]> granicus.if.org Git - clang/commitdiff
Try to make the output of PlistDiagnostics more deterministic by sorting PathDiagnost...
authorTed Kremenek <kremenek@apple.com>
Thu, 3 Dec 2009 19:35:02 +0000 (19:35 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 3 Dec 2009 19:35:02 +0000 (19:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90478 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/PlistDiagnostics.cpp

index 80ee2c2e8eba3bf2a323185f75cc5247b39d27f7..92cafe6d1cbe4215215b844d877e9ff74fe8574f 100644 (file)
@@ -29,6 +29,40 @@ namespace clang {
   class Preprocessor;
 }
 
+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;
@@ -314,6 +348,11 @@ void PlistDiagnostics::FlushDiagnostics(llvm::SmallVectorImpl<std::string>
     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.