Skip to content

Commit 469520e

Browse files
authored
Revert "[analyzer][NFC] Make RegionStore dumps deterministic" (#115881)
Reverts #115615 There are two problems with this PR: 1) If any of the dumps contains a store with a symbolic binding, we crash. 2) The memory space clusters come last among the clusters, which is not what I intended. I'm reverting because of the crash.
1 parent 9a9af0a commit 469520e

File tree

1 file changed

+13
-61
lines changed

1 file changed

+13
-61
lines changed

clang/lib/StaticAnalyzer/Core/RegionStore.cpp

Lines changed: 13 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class BindingKey {
6767
isa<ObjCIvarRegion, CXXDerivedObjectRegion>(r)) &&
6868
"Not a base");
6969
}
70-
7170
public:
71+
7272
bool isDirect() const { return P.getInt() & Direct; }
7373
bool hasSymbolicOffset() const { return P.getInt() & Symbolic; }
7474

@@ -232,75 +232,27 @@ class RegionBindingsRef : public llvm::ImmutableMapRef<const MemRegion *,
232232

233233
void printJson(raw_ostream &Out, const char *NL = "\n",
234234
unsigned int Space = 0, bool IsDot = false) const {
235-
using namespace llvm;
236-
DenseMap<const MemRegion *, std::string> StringifyCache;
237-
auto ToString = [&StringifyCache](const MemRegion *R) {
238-
auto [Place, Inserted] = StringifyCache.try_emplace(R);
239-
if (!Inserted)
240-
return Place->second;
241-
std::string Res;
242-
raw_string_ostream OS(Res);
243-
OS << R;
244-
Place->second = Res;
245-
return Res;
246-
};
247-
248-
using Cluster =
249-
std::pair<const MemRegion *, ImmutableMap<BindingKey, SVal>>;
250-
using Binding = std::pair<BindingKey, SVal>;
251-
252-
const auto ClusterSortKey = [&ToString](const Cluster *C) {
253-
const MemRegion *Key = C->first;
254-
return std::tuple{isa<MemSpaceRegion>(Key), ToString(Key)};
255-
};
256-
257-
const auto MemSpaceBeforeRegionName = [&ClusterSortKey](const Cluster *L,
258-
const Cluster *R) {
259-
return ClusterSortKey(L) < ClusterSortKey(R);
260-
};
261-
262-
const auto BindingSortKey = [&ToString](const Binding *BPtr) {
263-
const BindingKey &Key = BPtr->first;
264-
return std::tuple{Key.isDirect(), !Key.hasSymbolicOffset(),
265-
ToString(Key.getRegion()), Key.getOffset()};
266-
};
267-
268-
const auto DefaultBindingBeforeDirectBindings =
269-
[&BindingSortKey](const Binding *LPtr, const Binding *RPtr) {
270-
return BindingSortKey(LPtr) < BindingSortKey(RPtr);
271-
};
272-
273-
const auto AddrOf = [](const auto &Item) { return &Item; };
274-
275-
std::vector<const Cluster *> SortedClusters;
276-
SortedClusters.reserve(std::distance(begin(), end()));
277-
append_range(SortedClusters, map_range(*this, AddrOf));
278-
llvm::sort(SortedClusters, MemSpaceBeforeRegionName);
279-
280-
for (auto [Idx, C] : llvm::enumerate(SortedClusters)) {
281-
const auto &[BaseRegion, Bindings] = *C;
235+
for (iterator I = begin(), E = end(); I != E; ++I) {
236+
// TODO: We might need a .printJson for I.getKey() as well.
282237
Indent(Out, Space, IsDot)
283-
<< "{ \"cluster\": \"" << BaseRegion << "\", \"pointer\": \""
284-
<< (const void *)BaseRegion << "\", \"items\": [" << NL;
285-
286-
std::vector<const Binding *> SortedBindings;
287-
SortedBindings.reserve(std::distance(Bindings.begin(), Bindings.end()));
288-
append_range(SortedBindings, map_range(Bindings, AddrOf));
289-
llvm::sort(SortedBindings, DefaultBindingBeforeDirectBindings);
238+
<< "{ \"cluster\": \"" << I.getKey() << "\", \"pointer\": \""
239+
<< (const void *)I.getKey() << "\", \"items\": [" << NL;
290240

291241
++Space;
292-
for (auto [Idx, B] : llvm::enumerate(SortedBindings)) {
293-
const auto &[Key, Value] = *B;
294-
Indent(Out, Space, IsDot) << "{ " << Key << ", \"value\": ";
295-
Value.printJson(Out, /*AddQuotes=*/true);
242+
const ClusterBindings &CB = I.getData();
243+
for (ClusterBindings::iterator CI = CB.begin(), CE = CB.end(); CI != CE;
244+
++CI) {
245+
Indent(Out, Space, IsDot) << "{ " << CI.getKey() << ", \"value\": ";
246+
CI.getData().printJson(Out, /*AddQuotes=*/true);
296247
Out << " }";
297-
if (Idx != SortedBindings.size() - 1)
248+
if (std::next(CI) != CE)
298249
Out << ',';
299250
Out << NL;
300251
}
252+
301253
--Space;
302254
Indent(Out, Space, IsDot) << "]}";
303-
if (Idx != SortedClusters.size() - 1)
255+
if (std::next(I) != E)
304256
Out << ',';
305257
Out << NL;
306258
}

0 commit comments

Comments
 (0)