From afcd862b2e0a561bf03b1e7b83e6eec8e7143098 Mon Sep 17 00:00:00 2001 From: Balazs Benics Date: Tue, 13 Sep 2022 08:58:46 +0200 Subject: [PATCH] [analyzer] LazyCompoundVals should be always bound as default bindings `LazyCompoundVals` should only appear as `default` bindings in the store. This fixes the second case in this patch-stack. Depends on: D132142 Reviewed By: xazax.hun Differential Revision: https://reviews.llvm.org/D132143 --- clang/lib/StaticAnalyzer/Core/RegionStore.cpp | 6 +++++- clang/test/Analysis/trivial-copy-struct.cpp | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp index 58f3b1c..eeadd15 100644 --- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp +++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp @@ -2400,7 +2400,11 @@ RegionStoreManager::bind(RegionBindingsConstRef B, Loc L, SVal V) { // Clear out bindings that may overlap with this binding. RegionBindingsRef NewB = removeSubRegionBindings(B, cast(R)); - return NewB.addBinding(BindingKey::Make(R, BindingKey::Direct), V); + + // LazyCompoundVals should be always bound as 'default' bindings. + auto KeyKind = isa(V) ? BindingKey::Default + : BindingKey::Direct; + return NewB.addBinding(BindingKey::Make(R, KeyKind), V); } RegionBindingsRef diff --git a/clang/test/Analysis/trivial-copy-struct.cpp b/clang/test/Analysis/trivial-copy-struct.cpp index 85efe85..b9a2b1d 100644 --- a/clang/test/Analysis/trivial-copy-struct.cpp +++ b/clang/test/Analysis/trivial-copy-struct.cpp @@ -27,10 +27,10 @@ void copy_on_heap(Node* n1) { clang_analyzer_dump(n2); // expected-warning-re {{&HeapSymRegion{conj_${{[0-9]+}}{Node *, LC{{[0-9]+}}, S{{[0-9]+}}, #{{[0-9]+}}}}}} clang_analyzer_dump(n1->ptr); // expected-warning-re {{&SymRegion{reg_${{[0-9]+}}},0 S64b,struct Node}.ptr>}}} - clang_analyzer_dump(n2->ptr); // expected-warning {{Unknown}} FIXME: This should be the same as above. + clang_analyzer_dump(n2->ptr); // expected-warning-re {{&SymRegion{reg_${{[0-9]+}}},0 S64b,struct Node}.ptr>}}} if (n1->ptr != n2->ptr) - clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}} FIXME: This should not be reachable. + clang_analyzer_warnIfReached(); // unreachable (void)(n1->ptr); (void)(n2->ptr); } -- 2.7.4