https://github.com/thurstond updated 
https://github.com/llvm/llvm-project/pull/229591

>From 7d4f429bfcf0ea053f8bd22b7e69a693ff7c9a15 Mon Sep 17 00:00:00 2001
From: Thurston Dang <[email protected]>
Date: Tue, 6 Oct 2026 22:32:01 +0000
Subject: [PATCH 1/2] [msan] Don't instrument llvm::fake_use

The fake_use intrinsic (used by -fextend-variable-liveness) was being strictly 
handled (i.e., check that the
parameter is fully initialized), which led to false positives
(https://github.com/llvm/llvm-project/issues/225425). This patch solves
the issue by silently not instrumenting fake_use, since they are, by
definition, not real uses.

Fixes: #225425
---
 clang/test/CodeGen/fake-use-sanitizer.cpp              |  8 +-------
 .../lib/Transforms/Instrumentation/MemorySanitizer.cpp | 10 ++++++++++
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/test/CodeGen/fake-use-sanitizer.cpp 
b/clang/test/CodeGen/fake-use-sanitizer.cpp
index 68a702b132663..3f6e4e10337e7 100644
--- a/clang/test/CodeGen/fake-use-sanitizer.cpp
+++ b/clang/test/CodeGen/fake-use-sanitizer.cpp
@@ -65,7 +65,7 @@ void foo()
 // MSan regression test from https://github.com/llvm/llvm-project/issues/225425
 // This test (not the tests above) was generated with update_cc_test_checks.py.
 //
-// A fake_use will be inserted for x. Currently, MSan erroneously checks it.
+// A fake_use will be inserted for x. MSan shouldn't check its parameter.
 //
 // MEMORY-LABEL: define dso_local noundef i32 @main(
 // MEMORY-SAME: ) #[[ATTR0:[0-9]+]] {
@@ -92,12 +92,6 @@ void foo()
 // MEMORY-NEXT:    [[TMP10:%.*]] = xor i64 [[TMP9]], 87960930222080
 // MEMORY-NEXT:    [[TMP11:%.*]] = inttoptr i64 [[TMP10]] to ptr
 // MEMORY-NEXT:    [[_MSLD:%.*]] = load i8, ptr [[TMP11]], align 1
-// MEMORY-NEXT:    [[_MSCMP:%.*]] = icmp ne i8 [[_MSLD]], 0
-// MEMORY-NEXT:    br i1 [[_MSCMP]], label %[[BB12:.*]], label %[[BB13:.*]], 
!prof [[PROF2:![0-9]+]]
-// MEMORY:       [[BB12]]:
-// MEMORY-NEXT:    call void @__msan_warning_noreturn() #[[ATTR7:[0-9]+]]
-// MEMORY-NEXT:    unreachable
-// MEMORY:       [[BB13]]:
 // MEMORY-NEXT:    notail call void (...) @llvm.fake.use(i8 [[FAKE_USE]]) 
#[[ATTR6]]
 // MEMORY-NEXT:    call void @llvm.lifetime.end.p0(ptr [[X]]) #[[ATTR6]]
 // MEMORY-NEXT:    ret i32 0
diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp 
b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index dfae300d56bef..921588d3d6a3c 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -6125,6 +6125,16 @@ struct MemorySanitizerVisitor : public 
InstVisitor<MemorySanitizerVisitor> {
       handleGenericVectorConvertIntrinsic(I, /*FixedPoint=*/false);
       break;
 
+    // e.g.,
+    //     notail call void (...) @llvm.fake.use(i64 %x)
+    //     notail call void (...) @llvm.fake.use(i32 %y)
+    //     notail call void (...) @llvm.fake.use(ptr %z)
+    case Intrinsic::fake_use:
+      assert(I.getType()->isVoidTy());
+      // fake_uses aren't real, they can't hurt you. Simply ignore them since
+      // the input isn't truly being used, and there is no output.
+      return true;
+
     default:
       return false;
     }

>From 24c49e937ad11c28c1fa1fdd3b05733a16e835c6 Mon Sep 17 00:00:00 2001
From: Thurston Dang <[email protected]>
Date: Tue, 6 Oct 2026 22:46:21 +0000
Subject: [PATCH 2/2] Reword comment

---
 llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp 
b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index 921588d3d6a3c..360c071bc95f1 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -6131,8 +6131,9 @@ struct MemorySanitizerVisitor : public 
InstVisitor<MemorySanitizerVisitor> {
     //     notail call void (...) @llvm.fake.use(ptr %z)
     case Intrinsic::fake_use:
       assert(I.getType()->isVoidTy());
-      // fake_uses aren't real, they can't hurt you. Simply ignore them since
-      // the input isn't truly being used, and there is no output.
+      // fake_uses aren't real, they can't hurt you. If the use isn't real, it
+      // can't be a real use-of-uninitialized memory. Silently skip over
+      // fake_use.
       return true;
 
     default:

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to