Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion llvm/lib/Transforms/IPO/FunctionAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,13 @@ 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include in the if condition?

Suggested change
if (ConstantLength && Offset) {
if (ConstantLength && Offset && ConstantLength->isNonNegative()) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

if (ConstantLength->getSExtValue() < 0)
return std::nullopt;
return ConstantRange(
APInt(64, *Offset, true),
APInt(64, *Offset + ConstantLength->getSExtValue(), true));
}
return std::nullopt;
};
if (auto *SI = dyn_cast<StoreInst>(I)) {
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
Loading