Skip to content

Commit

Permalink
Skip negative length while inferring initializes attr (llvm#120874)
Browse files Browse the repository at this point in the history
Bail out negative length while inferring initializes attr. Otherwise it
causes an assertion error:
`Attribute 'initializes' does not support unordered ranges`
  • Loading branch information
haopliu authored Dec 23, 2024
1 parent 34531cf commit 8daba2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/FunctionAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ ArgumentAccessInfo getArgmentAccessInfo(const Instruction *I,
[](Value *Length,
std::optional<int64_t> Offset) -> std::optional<ConstantRange> {
auto *ConstantLength = dyn_cast<ConstantInt>(Length);
if (ConstantLength && Offset)
if (ConstantLength && Offset && !ConstantLength->isNegative())
return ConstantRange(
APInt(64, *Offset, true),
APInt(64, *Offset + ConstantLength->getSExtValue(), true));
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/Transforms/FunctionAttrs/initializes.ll
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,17 @@ define void @memset_offset(ptr %p) {
ret void
}

define void @memset_neg(ptr %p) {
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
; CHECK-LABEL: define void @memset_neg(
; CHECK-SAME: ptr nocapture writeonly [[P:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr [[P]], i8 2, i64 -1, i1 false)
; CHECK-NEXT: ret void
;
call void @llvm.memset(ptr %p, i8 2, i64 -1, i1 false)
ret void
}

define void @memset_volatile(ptr %p) {
; CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(argmem: write)
; CHECK-LABEL: define void @memset_volatile(
Expand Down

0 comments on commit 8daba2c

Please sign in to comment.