[clang] [analyzer] Commit the dead-region cleanup in UninitializedObjectChecker (PR #244849)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 21 00:45:08 PST 2026
https://github.com/Xazax-hun created https://github.com/llvm/llvm-project/pull/244849
checkDeadSymbols removed dead regions from the AnalyzedRegions set but never added a transition, so the updated state was thrown away. This has been the case since the callback was introduced. As a result the set only ever grew along a path, and a region that died and was later reused (e.g. a local in a loop body) stayed marked as already reported, suppressing legitimate warnings for objects constructed later that point to it.
Add the missing transition. The new test constructs, in two iterations of a loop, two different objects pointing to a fresh uninitialized local; previously the second warning was suppressed.
Assisted-by: Claude Opus 5.5
>From fa147d2a41b83af98819d36b9039047fb73f22f5 Mon Sep 17 00:00:00 2001
From: Gabor Horvath <gaborh at apple.com>
Date: Sat, 21 Nov 2026 04:54:10 +0000
Subject: [PATCH] [analyzer] Commit the dead-region cleanup in
UninitializedObjectChecker
checkDeadSymbols removed dead regions from the AnalyzedRegions set but
never added a transition, so the updated state was thrown away. This has
been the case since the callback was introduced. As a result the set only
ever grew along a path, and a region that died and was later reused (e.g.
a local in a loop body) stayed marked as already reported, suppressing
legitimate warnings for objects constructed later that point to it.
Add the missing transition. The new test constructs, in two iterations of
a loop, two different objects pointing to a fresh uninitialized local;
previously the second warning was suppressed.
Assisted-by: Claude Opus 5.5
---
.../UninitializedObjectChecker.cpp | 1 +
.../cxx-uninitialized-object-ptr-ref.cpp | 26 +++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index 2137b649f75410..7c59e2bab8292b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -235,6 +235,7 @@ void UninitializedObjectChecker::checkDeadSymbols(SymbolReaper &SR,
if (!SR.isLiveRegion(R))
State = State->remove<AnalyzedRegions>(R);
}
+ C.addTransition(State);
}
//===----------------------------------------------------------------------===//
diff --git a/clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp b/clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
index b5a02bbf59f95d..c8ba8169f173d6 100644
--- a/clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ b/clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -967,3 +967,29 @@ void fMultipleObjectsReferencingTheSameObjectTest() {
INIT(IntReferenceWrapper1, (a));
INIT(IntReferenceWrapper2, (a));
}
+
+// The pointee 'x' is dead at the end of the first iteration, so a later
+// object referencing the new 'x' in the next iteration must be reported too.
+struct IntPointerWrapper1 {
+ int *p; // expected-note{{uninitialized pointee 'this->p'}}
+ int dontGetFilteredByNonPedanticMode = 0;
+
+ IntPointerWrapper1(int *p) : p(p) {} // expected-warning{{1 uninitialized field}}
+};
+
+struct IntPointerWrapper2 {
+ int *p; // expected-note{{uninitialized pointee 'this->p'}}
+ int dontGetFilteredByNonPedanticMode = 0;
+
+ IntPointerWrapper2(int *p) : p(p) {} // expected-warning{{1 uninitialized field}}
+};
+
+void fDeadPointeeRegionIsForgottenTest() {
+ for (int i = 0; i < 2; ++i) {
+ int x;
+ if (i == 0)
+ IntPointerWrapper1 w1(&x);
+ else
+ IntPointerWrapper2 w2(&x);
+ }
+}
More information about the cfe-commits
mailing list