[clang] [LifetimeSafety][test] Fix UUM of fields added in #221610 and #205764 (PR #221843)

via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 7 14:59:15 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Thurston Dang (thurstond)

<details>
<summary>Changes</summary>

New LifetimeSafetyOpts fields were added in https://github.com/llvm/llvm-project/pull/221610 but they are not initialized in clang/unittests/Analysis/LifetimeSafetyTest.cpp, leading to use-of-uninitialized-memory (https://lab.llvm.org/buildbot/#/builders/164/builds/25165):
```
Uninitialized value was stored to memory at
    #<!-- -->0 0x55555bcd06c7 in __msan_memcpy /home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/compiler-rt/lib/msan/msan_interceptors.cpp:1760:3
    #<!-- -->1 0x5555715238ed in clang::lifetimes::internal::LifetimeSafetyAnalysis::LifetimeSafetyAnalysis(clang::AnalysisDeclContext&, clang::lifetimes::LifetimeSafetySemaHelper*, clang::lifetimes::LifetimeSafetyOpts const&) /home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Analysis/LifetimeSafety/LifetimeSafety.cpp:54:39
```

This patch fixes the issue by initializing the fields in the test to true, which maintains the behavior prior to the new fields being added.

Additionally, this patch does a similar drive-by fix to the SuggestAnnotations field (added in https://github.com/llvm/llvm-project/pull/205764). Although there has been no MSan report, that's likely due to either an MSan false positive or insufficient test coverage.

---
Full diff: https://github.com/llvm/llvm-project/pull/221843.diff


1 Files Affected:

- (modified) clang/unittests/Analysis/LifetimeSafetyTest.cpp (+5) 


``````````diff
diff --git a/clang/unittests/Analysis/LifetimeSafetyTest.cpp b/clang/unittests/Analysis/LifetimeSafetyTest.cpp
index 1686e88e740c5..759e2d3ba01b7 100644
--- a/clang/unittests/Analysis/LifetimeSafetyTest.cpp
+++ b/clang/unittests/Analysis/LifetimeSafetyTest.cpp
@@ -66,6 +66,11 @@ class LifetimeTestRunner {
     // Run the main analysis.
     LifetimeSafetyOpts LSOpts;
     LSOpts.MaxCFGBlocks = 0;
+    LSOpts.SuggestAnnotations = true;
+    LSOpts.CheckNoescapeViolations = true;
+    LSOpts.CheckLifetimeboundViolations = true;
+    LSOpts.CheckMisplacedLifetimebound = true;
+    LSOpts.CheckInapplicableLifetimebound = true;
     Analysis =
         std::make_unique<LifetimeSafetyAnalysis>(*AnalysisCtx, nullptr, LSOpts);
     Analysis->run();

``````````

</details>


https://github.com/llvm/llvm-project/pull/221843


More information about the cfe-commits mailing list