llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Gábor Horváth (Xazax-hun) <details> <summary>Changes</summary> 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 --- Full diff: https://github.com/llvm/llvm-project/pull/244849.diff 2 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp (+1) - (modified) clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp (+26) ``````````diff 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); + } +} `````````` </details> https://github.com/llvm/llvm-project/pull/244849 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
