[PATCH] D109675: [value-tracking] see through returned attribute.

Florian Mayer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 13 02:31:20 PDT 2021


fmayer created this revision.
Herald added a subscriber: hiraditya.
fmayer requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109675

Files:
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll
  llvm/unittests/Analysis/ValueTrackingTest.cpp


Index: llvm/unittests/Analysis/ValueTrackingTest.cpp
===================================================================
--- llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -2256,6 +2256,22 @@
         ret void
       })",
      false, false},
+    {R"(
+      declare i32* @retptr(i32* returned)
+      define void @test(i1 %cond) {
+        %a = alloca i32
+        %r = call i32* @retptr(i32* %a)
+        ret void
+      })",
+     true, true},
+    {R"(
+      declare i32* @fun(i32*)
+      define void @test(i1 %cond) {
+        %a = alloca i32
+        %r = call i32* @fun(i32* %a)
+        ret void
+      })",
+     false, false},
 };
 
 TEST_P(FindAllocaForValueTest, findAllocaForValue) {
Index: llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll
===================================================================
--- llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll
+++ llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll
@@ -164,8 +164,7 @@
   ; SAFETY: call {{.*}}__hwasan_generate_tag
   ; SAFETY-NOT: call {{.*}}__hwasan_store
   ; NOSTACK-NOT: call {{.*}}__hwasan_generate_tag
-  ; TODO: Do not emit this store.
-  ; NOSTACK: call {{.*}}__hwasan_store
+  ; NOSTACK-NOT: call {{.*}}__hwasan_store
   %buf.sroa.0 = alloca i8, align 4
   call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull %buf.sroa.0)
   %ptr = call i8* @retptr(i8* %buf.sroa.0)
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -4533,6 +4533,12 @@
       if (OffsetZero && !GEP->hasAllZeroIndices())
         return nullptr;
       AddWork(GEP->getPointerOperand());
+    } else if (CallBase *CB = dyn_cast<CallBase>(V)) {
+      Value *Returned = CB->getReturnedArgOperand();
+      if (Returned)
+        AddWork(Returned);
+      else
+        return nullptr;
     } else {
       return nullptr;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109675.372188.patch
Type: text/x-patch
Size: 2048 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210913/98b4e4df/attachment.bin>


More information about the llvm-commits mailing list