[llvm] 9f9e8ba - [MemoryLocation] Support memset_chk in getForArgument.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 2 05:46:22 PST 2021
Author: Florian Hahn
Date: 2021-12-02T13:45:58Z
New Revision: 9f9e8ba114ce091f375f7ea9316a65c7582d6882
URL: https://github.com/llvm/llvm-project/commit/9f9e8ba114ce091f375f7ea9316a65c7582d6882
DIFF: https://github.com/llvm/llvm-project/commit/9f9e8ba114ce091f375f7ea9316a65c7582d6882.diff
LOG: [MemoryLocation] Support memset_chk in getForArgument.
The size argument for memset_chk is an upper bound for the size of the
pointer argument. memset_chk may write less than the specified length,
if it exceeds the specified max size and aborts.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D114870
Added:
Modified:
llvm/lib/Analysis/MemoryLocation.cpp
llvm/test/Analysis/BasicAA/libfuncs.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/MemoryLocation.cpp b/llvm/lib/Analysis/MemoryLocation.cpp
index 7f2d04c495658..b4eb06dec03a2 100644
--- a/llvm/lib/Analysis/MemoryLocation.cpp
+++ b/llvm/lib/Analysis/MemoryLocation.cpp
@@ -213,6 +213,16 @@ MemoryLocation MemoryLocation::getForArgument(const CallBase *Call,
LibFunc F;
if (TLI && TLI->getLibFunc(*Call, F) && TLI->has(F)) {
switch (F) {
+ case LibFunc_memset_chk: {
+ assert(ArgIdx == 0 && "Invalid argument index for memset_chk");
+ LocationSize Size = LocationSize::afterPointer();
+ if (const auto *Len = dyn_cast<ConstantInt>(Call->getArgOperand(2))) {
+ // memset_chk writes at most Len bytes. It may write less, if Len
+ // exceeds the specified max size and aborts.
+ Size = LocationSize::upperBound(Len->getZExtValue());
+ }
+ return MemoryLocation(Arg, Size, AATags);
+ }
case LibFunc_memset_pattern16:
assert((ArgIdx == 0 || ArgIdx == 1) &&
"Invalid argument index for memset_pattern16");
diff --git a/llvm/test/Analysis/BasicAA/libfuncs.ll b/llvm/test/Analysis/BasicAA/libfuncs.ll
index 31c4367aef07b..476e77bb781d8 100644
--- a/llvm/test/Analysis/BasicAA/libfuncs.ll
+++ b/llvm/test/Analysis/BasicAA/libfuncs.ll
@@ -183,7 +183,7 @@ define i8* @test_memset_chk_const_size(i8* noalias %a, i64 %n) {
; CHECK: Just Mod (MustAlias): Ptr: i8* %a <-> %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
; CHECK-NEXT: Just Mod: Ptr: i8* %res <-> %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
; CHECK-NEXT: Just Mod: Ptr: i8* %a.gep.1 <-> %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
-; CHECK-NEXT: Just Mod: Ptr: i8* %a.gep.5 <-> %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
+; CHECK-NEXT: NoModRef: Ptr: i8* %a.gep.5 <-> %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
;
entry:
%res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
More information about the llvm-commits
mailing list