[PATCH] D138613: [MemoryLocation] Support memcpy_chk in getForArgument.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 23 14:36:38 PST 2022


fhahn created this revision.
fhahn added reviewers: ab, xbolva00, efriedma, jdoerfert, nikic.
Herald added a subscriber: hiraditya.
Herald added a project: All.
fhahn requested review of this revision.
Herald added a project: LLVM.

Similar to 9f9e8ba114ce <https://reviews.llvm.org/rG9f9e8ba114ce091f375f7ea9316a65c7582d6882>, add support for memcyp_chk to
MemoryLocation::getForArgument.

The size argument for memcpy_chk is an upper bound for the size of the
pointer argument. memcpy_chk may read/write less than the specified length,
if it exceeds the specified max size and aborts.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138613

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
@@ -323,9 +323,9 @@
 ; CHECK:       Just Mod:  Ptr: i8* %a	<->  %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n)
 ; CHECK-NEXT:  Just Mod:  Ptr: i8* %res	<->  %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n)
 ; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.1	<->  %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n)
-; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.5	<->  %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n)
+; CHECK-NEXT:  NoModRef:  Ptr: i8* %a.gep.5	<->  %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n)
 ; CHECK-NEXT:  Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n)
-; CHECK-NEXT:  Just Ref:  Ptr: i8* %b.gep.5	<->  %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n)
+; CHECK-NEXT:  NoModRef:  Ptr: i8* %b.gep.5	<->  %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n)
 ;
 entry:
   load i8, i8* %a
Index: llvm/lib/Analysis/MemoryLocation.cpp
===================================================================
--- llvm/lib/Analysis/MemoryLocation.cpp
+++ llvm/lib/Analysis/MemoryLocation.cpp
@@ -253,8 +253,12 @@
       assert((ArgIdx == 0 || ArgIdx == 1) && "Invalid argument index for str function");
       return MemoryLocation::getAfter(Arg, AATags);
 
-    case LibFunc_memset_chk: {
+    case LibFunc_memset_chk:
       assert(ArgIdx == 0 && "Invalid argument index for memset_chk");
+      LLVM_FALLTHROUGH;
+    case LibFunc_memcpy_chk: {
+      assert((ArgIdx == 0 || ArgIdx == 1) &&
+             "Invalid argument index for memcpy_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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138613.477609.patch
Type: text/x-patch
Size: 2030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221123/f520b03b/attachment.bin>


More information about the llvm-commits mailing list