Author: Gabor Marton
Date: 2021-07-26T16:27:23+02:00
New Revision: 4761321d49db01dce1e308f900add033cc26fb47

URL: 
https://github.com/llvm/llvm-project/commit/4761321d49db01dce1e308f900add033cc26fb47
DIFF: 
https://github.com/llvm/llvm-project/commit/4761321d49db01dce1e308f900add033cc26fb47.diff

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

This change is an extension to 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.

Differential Revision: https://reviews.llvm.org/D106642

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index de86fc685b075..69554576bdb2e 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2630,6 +2630,13 @@ void RangeConstraintManager::printJson(raw_ostream &Out, 
ProgramStateRef State,
   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,
@@ -2643,25 +2650,32 @@ void 
RangeConstraintManager::printConstraints(raw_ostream &Out,
     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) {
+      bool insertion_took_place;
+      std::tie(std::ignore, insertion_took_place) =
+          OrderedConstraints.insert({toString(ClassMember), P.second});
+      assert(insertion_took_place &&
+             "two symbols should not have the same dump");
+    }
+  }
 
-    // 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;
 
@@ -2669,13 +2683,6 @@ void 
RangeConstraintManager::printConstraints(raw_ostream &Out,
   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(),


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to