Skip to content

Commit 1775b58

Browse files
Revert "[analyzer] Avoid creating LazyCompoundVal when possible (llvm#116840)"
This reverts commit 9b2ec87. Resolved conflicts in: clang/lib/StaticAnalyzer/Core/RegionStore.cpp clang/test/Analysis/ctor-trivial-copy.cpp clang/test/Analysis/explain-svals.cpp
1 parent 3793e75 commit 1775b58

File tree

7 files changed

+20
-50
lines changed

7 files changed

+20
-50
lines changed

clang/lib/StaticAnalyzer/Core/RegionStore.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,6 @@ class RegionStoreManager : public StoreManager {
714714
return getBinding(getRegionBindings(S), L, T);
715715
}
716716

717-
std::optional<SVal> getUniqueDefaultBinding(RegionBindingsConstRef B,
718-
const TypedValueRegion *R) const;
719717
std::optional<SVal>
720718
getUniqueDefaultBinding(nonloc::LazyCompoundVal LCV) const;
721719

@@ -2465,11 +2463,6 @@ SVal RegionStoreManager::getBindingForStruct(RegionBindingsConstRef B,
24652463
// behavior doesn't depend on the struct layout.
24662464
// This way even an empty struct can carry taint, no matter if creduce drops
24672465
// the last field member or not.
2468-
2469-
// Try to avoid creating a LCV if it would anyways just refer to a single
2470-
// default binding.
2471-
if (std::optional<SVal> Val = getUniqueDefaultBinding(B, R))
2472-
return *Val;
24732466
return createLazyBinding(B, R);
24742467
}
24752468

@@ -2758,25 +2751,21 @@ RegionStoreManager::bindVector(LimitedRegionBindingsConstRef B,
27582751
}
27592752

27602753
std::optional<SVal>
2761-
RegionStoreManager::getUniqueDefaultBinding(RegionBindingsConstRef B,
2762-
const TypedValueRegion *R) const {
2763-
if (R != R->getBaseRegion())
2754+
RegionStoreManager::getUniqueDefaultBinding(nonloc::LazyCompoundVal LCV) const {
2755+
const MemRegion *BaseR = LCV.getRegion();
2756+
2757+
// We only handle base regions.
2758+
if (BaseR != BaseR->getBaseRegion())
27642759
return std::nullopt;
27652760

2766-
const auto *Cluster = B.lookup(R);
2761+
const auto *Cluster = getRegionBindings(LCV.getStore()).lookup(BaseR);
27672762
if (!Cluster || !llvm::hasSingleElement(*Cluster))
27682763
return std::nullopt;
27692764

27702765
const auto [Key, Value] = *Cluster->begin();
27712766
return Key.isDirect() ? std::optional<SVal>{} : Value;
27722767
}
27732768

2774-
std::optional<SVal>
2775-
RegionStoreManager::getUniqueDefaultBinding(nonloc::LazyCompoundVal LCV) const {
2776-
auto B = getRegionBindings(LCV.getStore());
2777-
return getUniqueDefaultBinding(B, LCV.getRegion());
2778-
}
2779-
27802769
std::optional<LimitedRegionBindingsRef> RegionStoreManager::tryBindSmallStruct(
27812770
LimitedRegionBindingsConstRef B, const TypedValueRegion *R,
27822771
const RecordDecl *RD, nonloc::LazyCompoundVal LCV) {

clang/test/Analysis/ctor-trivial-copy.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
void clang_analyzer_printState();
66
template <typename T> void clang_analyzer_dump_lref(T& param);
77
template <typename T> void clang_analyzer_dump_val(T param);
8-
template <typename T> void clang_analyzer_denote(T param, const char *name);
9-
template <typename T> void clang_analyzer_express(T param);
108
template <typename T> T conjure();
119
template <typename... Ts> void nop(const Ts &... args) {}
1210

@@ -42,10 +40,16 @@ void test_assign_return() {
4240
namespace trivial_struct_copy {
4341

4442
void _01_empty_structs() {
45-
clang_analyzer_dump_val(conjure<empty>()); // expected-warning {{conj_$}}
43+
clang_analyzer_dump_val(conjure<empty>()); // expected-warning {{lazyCompoundVal}}
4644
empty Empty = conjure<empty>();
4745
empty Empty2 = Empty;
4846
empty Empty3 = Empty2;
47+
// All of these should refer to the exact same LCV, because all of
48+
// these trivial copies refer to the original conjured value.
49+
// There were Unknown before:
50+
clang_analyzer_dump_val(Empty); // expected-warning {{lazyCompoundVal}}
51+
clang_analyzer_dump_val(Empty2); // expected-warning {{lazyCompoundVal}}
52+
clang_analyzer_dump_val(Empty3); // expected-warning {{lazyCompoundVal}}
4953

5054
// We only have binding for the original Empty object, because copying empty
5155
// objects is a no-op in the performTrivialCopy. This is fine, because empty
@@ -67,16 +71,15 @@ void _01_empty_structs() {
6771
}
6872

6973
void _02_structs_with_members() {
70-
clang_analyzer_dump_val(conjure<aggr>()); // expected-warning {{conj_$}}
74+
clang_analyzer_dump_val(conjure<aggr>()); // expected-warning {{lazyCompoundVal}}
7175
aggr Aggr = conjure<aggr>();
7276
aggr Aggr2 = Aggr;
7377
aggr Aggr3 = Aggr2;
74-
// All of these should refer to the exact same symbol, because all of
78+
// All of these should refer to the exact same LCV, because all of
7579
// these trivial copies refer to the original conjured value.
76-
clang_analyzer_denote(Aggr, "$Aggr");
77-
clang_analyzer_express(Aggr); // expected-warning {{$Aggr}}
78-
clang_analyzer_express(Aggr2); // expected-warning {{$Aggr}}
79-
clang_analyzer_express(Aggr3); // expected-warning {{$Aggr}}
80+
clang_analyzer_dump_val(Aggr); // expected-warning {{lazyCompoundVal}}
81+
clang_analyzer_dump_val(Aggr2); // expected-warning {{lazyCompoundVal}}
82+
clang_analyzer_dump_val(Aggr3); // expected-warning {{lazyCompoundVal}}
8083

8184
// We should have the same Conjured symbol for "Aggr", "Aggr2" and "Aggr3".
8285
// We used to have Derived symbols for the individual fields that were

clang/test/Analysis/explain-svals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class C {
9999
} // end of anonymous namespace
100100

101101
void test_6() {
102-
clang_analyzer_explain(conjure_S()); // expected-warning-re{{{{^symbol of type 'int' conjured at CFG element 'conjure_S\(\) \(CXXRecordTypedCall, \+0\)'$}}}}
102+
clang_analyzer_explain(conjure_S()); // expected-warning-re{{{{^lazily frozen compound value of 1st parameter of function 'clang_analyzer_explain\(\)'$}}}}
103103
clang_analyzer_explain(conjure_S().z); // expected-warning-re{{{{^value derived from \(symbol of type 'int' conjured at CFG element 'conjure_S\(\) \(CXXRecordTypedCall, \)'\) for field 'z' of temporary object constructed at statement 'conjure_S\(\)'$}}}}
104104
}
105105

clang/test/Analysis/iterator-modeling.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,6 @@ void print_state(std::vector<int> &V) {
20352035
// CHECK: "checker_messages": [
20362036
// CHECK: { "checker": "alpha.cplusplus.IteratorModeling", "messages": [
20372037
// CHECK-NEXT: "Iterator Positions :",
2038-
// CHECK-NEXT: "conj_$[[#]]{int, LC[[#]], S[[#]], #[[#]]} : Valid ; Container == SymRegion{reg_$[[#]]<std::vector<int> & V>} ; Offset == conj_$[[#]]{long, LC[[#]], S[[#]], #[[#]]}",
20392038
// CHECK-NEXT: "i0 : Valid ; Container == SymRegion{reg_$[[#]]<std::vector<int> & V>} ; Offset == conj_$[[#]]{long, LC[[#]], S[[#]], #[[#]]}"
20402039
// CHECK-NEXT: ]}
20412040

@@ -2046,7 +2045,6 @@ void print_state(std::vector<int> &V) {
20462045
// CHECK: "checker_messages": [
20472046
// CHECK: { "checker": "alpha.cplusplus.IteratorModeling", "messages": [
20482047
// CHECK-NEXT: "Iterator Positions :",
2049-
// CHECK-NEXT: "conj_$[[#]]{int, LC[[#]], S[[#]], #[[#]]} : Valid ; Container == SymRegion{reg_$[[#]]<std::vector<int> & V>} ; Offset == conj_$[[#]]{long, LC[[#]], S[[#]], #[[#]]}",
20502048
// CHECK-NEXT: "i1 : Valid ; Container == SymRegion{reg_$[[#]]<std::vector<int> & V>} ; Offset == conj_$[[#]]{long, LC[[#]], S[[#]], #[[#]]}"
20512049
// CHECK-NEXT: ]}
20522050

clang/test/Analysis/stl-algorithm-modeling-aggressive-std-find-modeling.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@
44
// RUN: -analyzer-config alpha.cplusplus.STLAlgorithmModeling:AggressiveStdFindModeling=true\
55
// RUN: -verify
66

7-
// STLAlgorithmModeling and DebugIteratorModeling are probably bugged because
8-
// these tests started failing after we just directly copy the symbol
9-
// representing the value of a variable instead of creating a LazyCompoundVal
10-
// of that single conjured value.
11-
// In theory, it shouldn't matter if we eagerly copy the value that we would
12-
// "load" from the LCV once requested or just directly binding the backing symbol.
13-
// Yet, these tests fail, so there is likely messed up how/what the checker
14-
// metadata is associated with.
15-
// XFAIL: *
16-
177
#include "Inputs/system-header-simulator-cxx.h"
188

199
void clang_analyzer_eval(bool);

clang/test/Analysis/stl-algorithm-modeling.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@
33
// RUN: -analyzer-config aggressive-binary-operation-simplification=true\
44
// RUN: -verify
55

6-
// STLAlgorithmModeling and DebugIteratorModeling are probably bugged because
7-
// these tests started failing after we just directly copy the symbol
8-
// representing the value of a variable instead of creating a LazyCompoundVal
9-
// of that single conjured value.
10-
// In theory, it shouldn't matter if we eagerly copy the value that we would
11-
// "load" from the LCV once requested or just directly binding the backing symbol.
12-
// Yet, these tests fail, so there is likely messed up how/what the checker
13-
// metadata is associated with.
14-
// XFAIL: *
15-
166
#include "Inputs/system-header-simulator-cxx.h"
177

188
void clang_analyzer_eval(bool);

clang/test/Analysis/template-param-objects.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ bool operator ==(Box lhs, Box rhs) {
1111
return lhs.value == rhs.value;
1212
}
1313
template <Box V> void dumps() {
14-
clang_analyzer_dump(V); // expected-warning {{Unknown}}
14+
clang_analyzer_dump(V); // expected-warning {{lazyCompoundVal}}
1515
clang_analyzer_dump(&V); // expected-warning {{Unknown}}
1616
clang_analyzer_dump(V.value); // expected-warning {{Unknown}} FIXME: It should be '6 S32b'.
1717
clang_analyzer_dump(&V.value); // expected-warning {{Unknown}}

0 commit comments

Comments
 (0)