Skip to content

Commit 8daba2c

Browse files
authored
Skip negative length while inferring initializes attr (#120874)
Bail out negative length while inferring initializes attr. Otherwise it causes an assertion error: `Attribute 'initializes' does not support unordered ranges`
1 parent 34531cf commit 8daba2c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ ArgumentAccessInfo getArgmentAccessInfo(const Instruction *I,
633633
[](Value *Length,
634634
std::optional<int64_t> Offset) -> std::optional<ConstantRange> {
635635
auto *ConstantLength = dyn_cast<ConstantInt>(Length);
636-
if (ConstantLength && Offset)
636+
if (ConstantLength && Offset && !ConstantLength->isNegative())
637637
return ConstantRange(
638638
APInt(64, *Offset, true),
639639
APInt(64, *Offset + ConstantLength->getSExtValue(), true));

llvm/test/Transforms/FunctionAttrs/initializes.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,17 @@ define void @memset_offset(ptr %p) {
423423
ret void
424424
}
425425

426+
define void @memset_neg(ptr %p) {
427+
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
428+
; CHECK-LABEL: define void @memset_neg(
429+
; CHECK-SAME: ptr nocapture writeonly [[P:%.*]]) #[[ATTR0]] {
430+
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr [[P]], i8 2, i64 -1, i1 false)
431+
; CHECK-NEXT: ret void
432+
;
433+
call void @llvm.memset(ptr %p, i8 2, i64 -1, i1 false)
434+
ret void
435+
}
436+
426437
define void @memset_volatile(ptr %p) {
427438
; CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(argmem: write)
428439
; CHECK-LABEL: define void @memset_volatile(

0 commit comments

Comments
 (0)