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

Thurston Dang via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 7 14:58:42 PDT 2026


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

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.

>From 0b298c6af96f5e418a8928973cd2da3c3e62772d Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Mon, 7 Sep 2026 21:56:34 +0000
Subject: [PATCH] [LifetimeSafety][test] Fix UUM of fields added in #221610 and
 #205764

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.
---
 clang/unittests/Analysis/LifetimeSafetyTest.cpp | 5 +++++
 1 file changed, 5 insertions(+)

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();



More information about the cfe-commits mailing list