summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/PlistDiagnostics.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-12-03 19:35:02 +0000
committerTed Kremenek <kremenek@apple.com>2009-12-03 19:35:02 +0000
commita3536e23c8b13be76dea4ef0e2d6805b37261740 (patch)
tree18feed4eb3589602ffa35caeebc75a4b86107923 /clang/lib/Frontend/PlistDiagnostics.cpp
parent4313a9c56a509025e960afc1d1d832dbc98bd192 (diff)
downloadbcm5719-llvm-a3536e23c8b13be76dea4ef0e2d6805b37261740.tar.gz
bcm5719-llvm-a3536e23c8b13be76dea4ef0e2d6805b37261740.zip
Try to make the output of PlistDiagnostics more deterministic by sorting PathDiagnostics before they are emitted. Fixes <rdar://problem/7439668>.
llvm-svn: 90478
Diffstat (limited to 'clang/lib/Frontend/PlistDiagnostics.cpp')
-rw-r--r--clang/lib/Frontend/PlistDiagnostics.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/clang/lib/Frontend/PlistDiagnostics.cpp b/clang/lib/Frontend/PlistDiagnostics.cpp
index 80ee2c2e8eb..92cafe6d1cb 100644
--- a/clang/lib/Frontend/PlistDiagnostics.cpp
+++ b/clang/lib/Frontend/PlistDiagnostics.cpp
@@ -30,6 +30,40 @@ namespace clang {
}
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 @@ 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.
OpenPOWER on IntegriCloud