[PATCH] D114871: [MemoryLocation] Support strncpy in getForArgument.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 2 06:18:43 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG639a78a4bf9d: [MemoryLocation] Support strncpy in getForArgument. (authored by fhahn).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114871/new/
https://reviews.llvm.org/D114871
Files:
llvm/lib/Analysis/MemoryLocation.cpp
llvm/test/Analysis/BasicAA/libfuncs.ll
Index: llvm/test/Analysis/BasicAA/libfuncs.ll
===================================================================
--- llvm/test/Analysis/BasicAA/libfuncs.ll
+++ llvm/test/Analysis/BasicAA/libfuncs.ll
@@ -136,9 +136,9 @@
; CHECK-NEXT: Just Ref: Ptr: i8* %b <-> %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
; CHECK-NEXT: Just Mod: Ptr: i8* %res <-> %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
; CHECK-NEXT: Just Mod: Ptr: i8* %a.gep.1 <-> %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
-; CHECK-NEXT: Just Mod: Ptr: i8* %a.gep.5 <-> %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
+; CHECK-NEXT: NoModRef: Ptr: i8* %a.gep.5 <-> %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
; CHECK-NEXT: Just Ref: Ptr: i8* %b.gep.1 <-> %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
-; CHECK-NEXT: Just Ref: Ptr: i8* %b.gep.5 <-> %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
+; CHECK-NEXT: NoModRef: Ptr: i8* %b.gep.5 <-> %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
;
entry:
%res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
Index: llvm/lib/Analysis/MemoryLocation.cpp
===================================================================
--- llvm/lib/Analysis/MemoryLocation.cpp
+++ llvm/lib/Analysis/MemoryLocation.cpp
@@ -223,6 +223,18 @@
}
return MemoryLocation(Arg, Size, AATags);
}
+ case LibFunc_strncpy: {
+ assert((ArgIdx == 0 || ArgIdx == 1) &&
+ "Invalid argument index for strncpy");
+ LocationSize Size = LocationSize::afterPointer();
+ if (const auto *Len = dyn_cast<ConstantInt>(Call->getArgOperand(2))) {
+ // strncpy is guaranteed to write Len bytes, but only reads up to Len
+ // bytes.
+ Size = ArgIdx == 0 ? LocationSize::precise(Len->getZExtValue())
+ : LocationSize::upperBound(Len->getZExtValue());
+ }
+ return MemoryLocation(Arg, Size, AATags);
+ }
case LibFunc_memset_pattern16:
assert((ArgIdx == 0 || ArgIdx == 1) &&
"Invalid argument index for memset_pattern16");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114871.391302.patch
Type: text/x-patch
Size: 2101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211202/32574174/attachment.bin>
More information about the llvm-commits
mailing list