[cfe-commits] r90478 - /cfe/trunk/lib/Frontend/PlistDiagnostics.cpp

Ted Kremenek kremenek at apple.com
Thu Dec 3 11:35:03 PST 2009


Author: kremenek
Date: Thu Dec  3 13:35:02 2009
New Revision: 90478

URL: http://llvm.org/viewvc/llvm-project?rev=90478&view=rev
Log:
Try to make the output of PlistDiagnostics more deterministic by sorting PathDiagnostics before they are emitted.  Fixes <rdar://problem/7439668>.

Modified:
    cfe/trunk/lib/Frontend/PlistDiagnostics.cpp

Modified: cfe/trunk/lib/Frontend/PlistDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PlistDiagnostics.cpp?rev=90478&r1=90477&r2=90478&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PlistDiagnostics.cpp (original)
+++ cfe/trunk/lib/Frontend/PlistDiagnostics.cpp Thu Dec  3 13:35:02 2009
@@ -30,6 +30,40 @@
 }
 
 namespace {
+struct CompareDiagnostics {
+  // Compare if 'X' is "<" than 'Y'.
+  bool operator()(const PathDiagnostic *X, const PathDiagnostic *Y) const {
+    // First compare by location
+    const FullSourceLoc &XLoc = X->getLocation().asLocation();
+    const FullSourceLoc &YLoc = Y->getLocation().asLocation();
+    if (XLoc < YLoc)
+      return true;
+    if (XLoc != YLoc)
+      return false;
+    
+    // Next, compare by bug type.
+    llvm::StringRef XBugType = X->getBugType();
+    llvm::StringRef YBugType = Y->getBugType();
+    if (XBugType < YBugType)
+      return true;
+    if (XBugType != YBugType)
+      return false;
+    
+    // Next, compare by bug description.
+    llvm::StringRef XDesc = X->getDescription();
+    llvm::StringRef YDesc = Y->getDescription();
+    if (XDesc < YDesc)
+      return true;
+    if (XDesc != YDesc)
+      return false;
+    
+    // FIXME: Further refine by comparing PathDiagnosticPieces?
+    return false;    
+  }  
+};  
+}
+
+namespace {
   class PlistDiagnostics : public PathDiagnosticClient {
     std::vector<const PathDiagnostic*> BatchedDiags;
     const std::string OutputFile;
@@ -314,6 +348,11 @@
     return;
   
   flushed = true;
+  
+  // Sort the diagnostics so that they are always emitted in a deterministic
+  // order.
+  if (!BatchedDiags.empty())
+    std::sort(BatchedDiags.begin(), BatchedDiags.end(), CompareDiagnostics()); 
 
   // Build up a set of FIDs that we use by scanning the locations and
   // ranges of the diagnostics.





More information about the cfe-commits mailing list