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
8 changes: 6 additions & 2 deletions llvm/lib/Transforms/IPO/FunctionAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,12 @@ ArgumentAccessInfo getArgumentAccessInfo(const Instruction *I,
auto TypeSize = DL.getTypeStoreSize(Ty);
if (!TypeSize.isScalable() && Offset) {
int64_t Size = TypeSize.getFixedValue();
return ConstantRange(APInt(64, *Offset, true),
APInt(64, *Offset + Size, true));
APInt Low(64, *Offset, true);
APInt High(64, *Offset + Size, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

This will probably still make ubsan unhappy for your test case?

// Bail if the range overflows signed 64-bit int.
if (Low.sge(High))
return std::nullopt;
return ConstantRange(Low, High);
Copy link
Contributor

Choose a reason for hiding this comment

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

Check isSignWrappedSet() on the result instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't see this, thanks for pointing it out. Although I ended up just using APInt::sadd_ov

}
return std::nullopt;
};
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/Transforms/FunctionAttrs/initializes.ll
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,17 @@ define void @memset_offset_1_size_0(ptr %dst, ptr %src) {
call void @llvm.memmove.p0.p0.i64(ptr %dst.1, ptr %src, i64 0, i1 false)
ret void
}

; We should bail if the range overflows a singed 64-bit int.
define void @range_overflows_signed_64_bit_int(ptr %arg) {
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
; CHECK-LABEL: define void @range_overflows_signed_64_bit_int(
; CHECK-SAME: ptr writeonly captures(none) [[ARG:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[GETELEMENTPTR:%.*]] = getelementptr i8, ptr [[ARG]], i64 9223372036854775804
; CHECK-NEXT: store i32 0, ptr [[GETELEMENTPTR]], align 4
; CHECK-NEXT: ret void
;
%getelementptr = getelementptr i8, ptr %arg, i64 9223372036854775804
store i32 0, ptr %getelementptr
ret void
}
Loading