From: Anna Zaks Date: Thu, 2 Aug 2012 23:41:05 +0000 (+0000) Subject: [analyzer] Solve another source of non-determinism in the diagnostic X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d015f4febe85d3e3340172d70042840c51bbd836;p=clang [analyzer] Solve another source of non-determinism in the diagnostic engine. The code that was supposed to split the tie in a deterministic way is not deterministic. Most likely one of the profile methods uses a pointer. After this change we do finally get the consistent diagnostic output. Testing this requires running the analyzer on large code bases and diffing the results. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161224 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/BugReporter.cpp b/lib/StaticAnalyzer/Core/BugReporter.cpp index 1eaf1f9f76..7ba2fa7fdd 100644 --- a/lib/StaticAnalyzer/Core/BugReporter.cpp +++ b/lib/StaticAnalyzer/Core/BugReporter.cpp @@ -1536,6 +1536,8 @@ void BugReporter::FlushReports() { I = bugTypes.begin(), E = bugTypes.end(); I != E; ++I) const_cast(*I)->FlushReports(*this); + // We need to flush reports in deterministic order to ensure the order + // of the reports is consistent between runs. typedef std::vector ContVecTy; for (ContVecTy::iterator EI=EQClassesVector.begin(), EE=EQClassesVector.end(); EI != EE; ++EI){ diff --git a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp index 394e975d4e..b4c9068784 100644 --- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp +++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp @@ -148,23 +148,14 @@ void PathDiagnosticConsumer::HandlePathDiagnostic(PathDiagnostic *D) { if (PathDiagnostic *orig = Diags.FindNodeOrInsertPos(profile, InsertPos)) { // Keep the PathDiagnostic with the shorter path. + // Note, the enclosing rutine is called in deterministic order, so the + // results will be consistent between runs (no reason to break ties if the + // size is the same). const unsigned orig_size = orig->full_size(); const unsigned new_size = D->full_size(); - - if (orig_size <= new_size) { - bool shouldKeepOriginal = true; - if (orig_size == new_size) { - // Here we break ties in a fairly arbitrary, but deterministic, way. - llvm::FoldingSetNodeID fullProfile, fullProfileOrig; - D->FullProfile(fullProfile); - orig->FullProfile(fullProfileOrig); - if (fullProfile.ComputeHash() < fullProfileOrig.ComputeHash()) - shouldKeepOriginal = false; - } + if (orig_size <= new_size) + return; - if (shouldKeepOriginal) - return; - } Diags.RemoveNode(orig); delete orig; } diff --git a/test/Analysis/inline-unique-reports.c b/test/Analysis/inline-unique-reports.c index 6ae77e257e..9248ad2632 100644 --- a/test/Analysis/inline-unique-reports.c +++ b/test/Analysis/inline-unique-reports.c @@ -34,12 +34,12 @@ void test_bug_2() { // CHECK: start // CHECK: // CHECK: -// CHECK: line9 +// CHECK: line14 // CHECK: col3 // CHECK: file0 // CHECK: // CHECK: -// CHECK: line9 +// CHECK: line14 // CHECK: col5 // CHECK: file0 // CHECK: @@ -47,12 +47,12 @@ void test_bug_2() { // CHECK: end // CHECK: // CHECK: -// CHECK: line10 +// CHECK: line15 // CHECK: col3 // CHECK: file0 // CHECK: // CHECK: -// CHECK: line10 +// CHECK: line15 // CHECK: col5 // CHECK: file0 // CHECK: @@ -64,7 +64,7 @@ void test_bug_2() { // CHECK: kindevent // CHECK: location // CHECK: -// CHECK: line10 +// CHECK: line15 // CHECK: col3 // CHECK: file0 // CHECK: @@ -72,12 +72,12 @@ void test_bug_2() { // CHECK: // CHECK: // CHECK: -// CHECK: line10 +// CHECK: line15 // CHECK: col3 // CHECK: file0 // CHECK: // CHECK: -// CHECK: line10 +// CHECK: line15 // CHECK: col8 // CHECK: file0 // CHECK: @@ -99,9 +99,9 @@ void test_bug_2() { // CHECK: // CHECK: depth1 // CHECK: extended_message -// CHECK: Entered call from 'test_bug_1' +// CHECK: Entered call from 'test_bug_2' // CHECK: message -// CHECK: Entered call from 'test_bug_1' +// CHECK: Entered call from 'test_bug_2' // CHECK: // CHECK: // CHECK: kindcontrol @@ -172,6 +172,7 @@ void test_bug_2() { // CHECK: typeDereference of null pointer // CHECK: issue_context_kindfunction // CHECK: issue_contextbug +// CHECK: issue_hash1 // CHECK: location // CHECK: // CHECK: line5