Skip to content

Commit 3c5d0c4

Browse files
committed
Skip neg length while inferring initializes attr
1 parent e339f0a commit 3c5d0c4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,13 @@ 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) {
637+
if (ConstantLength->getSExtValue() < 0)
638+
return std::nullopt;
637639
return ConstantRange(
638640
APInt(64, *Offset, true),
639641
APInt(64, *Offset + ConstantLength->getSExtValue(), true));
642+
}
640643
return std::nullopt;
641644
};
642645
if (auto *SI = dyn_cast<StoreInst>(I)) {

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)