[PATCH] D106642: [Analyzer][solver][NFC] print constraints deterministically (ordered by their string representation)

Gabor Marton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 23 02:46:05 PDT 2021


martong created this revision.
martong added reviewers: NoQ, vsavchenko, steakhal, Szelethus.
Herald added subscribers: manas, ASDenysPetrov, gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, mgrang, rnkovacs, szepet, baloghadamsoftware, xazax.hun, whisperity.
martong requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change is an extension to D103967 <https://reviews.llvm.org/D103967> where I added dump methods for
(dis)equality classes of the State. There, the (dis)equality classes and their
contents are dumped in an ordered fashion, they are ordered based on their
string representation. This is very useful once we start to use FileCheck to
test the State dump in certain tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106642

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp


Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2618,6 +2618,13 @@
   printDisequalities(Out, State, NL, Space, IsDot);
 }
 
+static std::string toString(const SymbolRef &Sym) {
+  std::string S;
+  llvm::raw_string_ostream O(S);
+  Sym->dumpToStream(O);
+  return O.str();
+}
+
 void RangeConstraintManager::printConstraints(raw_ostream &Out,
                                               ProgramStateRef State,
                                               const char *NL,
@@ -2631,25 +2638,28 @@
     return;
   }
 
-  ++Space;
-  Out << '[' << NL;
-  bool First = true;
+  std::map<std::string, RangeSet> OrderedConstraints;
   for (std::pair<EquivalenceClass, RangeSet> P : Constraints) {
     SymbolSet ClassMembers = P.first.getClassMembers(State);
+    for (const SymbolRef &ClassMember : ClassMembers) {
+      OrderedConstraints.insert({toString(ClassMember), P.second});
+    }
+  }
 
-    // We can print the same constraint for every class member.
-    for (SymbolRef ClassMember : ClassMembers) {
-      if (First) {
-        First = false;
-      } else {
-        Out << ',';
-        Out << NL;
-      }
-      Indent(Out, Space, IsDot)
-          << "{ \"symbol\": \"" << ClassMember << "\", \"range\": \"";
-      P.second.dump(Out);
-      Out << "\" }";
+  ++Space;
+  Out << '[' << NL;
+  bool First = true;
+  for (std::pair<std::string, RangeSet> P : OrderedConstraints) {
+    if (First) {
+      First = false;
+    } else {
+      Out << ',';
+      Out << NL;
     }
+    Indent(Out, Space, IsDot)
+        << "{ \"symbol\": \"" << P.first << "\", \"range\": \"";
+    P.second.dump(Out);
+    Out << "\" }";
   }
   Out << NL;
 
@@ -2657,13 +2667,6 @@
   Indent(Out, Space, IsDot) << "]," << NL;
 }
 
-static std::string toString(const SymbolRef &Sym) {
-  std::string S;
-  llvm::raw_string_ostream O(S);
-  Sym->dumpToStream(O);
-  return O.str();
-}
-
 static std::string toString(ProgramStateRef State, EquivalenceClass Class) {
   SymbolSet ClassMembers = Class.getClassMembers(State);
   llvm::SmallVector<SymbolRef, 8> ClassMembersSorted(ClassMembers.begin(),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106642.361142.patch
Type: text/x-patch
Size: 2308 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210723/1f17ba62/attachment.bin>


More information about the cfe-commits mailing list