Author: Thurston Dang Date: 2026-10-06T23:49:27Z New Revision: 92dfb7a5b82c63895be374da73e24a9aabbd5309
URL: https://github.com/llvm/llvm-project/commit/92dfb7a5b82c63895be374da73e24a9aabbd5309 DIFF: https://github.com/llvm/llvm-project/commit/92dfb7a5b82c63895be374da73e24a9aabbd5309.diff LOG: [msan] Correctly handle llvm::fake_use (as a no-op) (#229591) 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 and therefore cannot lead to use-of-uninitialized-memory. Fixes: #225425 Added: Modified: clang/test/CodeGen/fake-use-sanitizer.cpp llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp Removed: ################################################################################ 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..360c071bc95f1 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -6125,6 +6125,17 @@ 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. If the use isn't real, it + // can't be a real use-of-uninitialized memory. Silently skip over + // fake_use. + return true; + default: return false; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
