From: Anna Zaks Date: Tue, 8 Jan 2013 19:19:46 +0000 (+0000) Subject: [analyzer] Only include uniqueling location as issue_hash when available X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6dfb96045bebe00212d251da1dad4660cb8652ac;p=clang [analyzer] Only include uniqueling location as issue_hash when available This makes us more optimistic when matching reports in a changing code base. Addresses Jordan's feedback for r171825. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171884 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp index 4d0f1d8d44..2939f56027 100644 --- a/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp +++ b/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp @@ -495,25 +495,32 @@ void PlistDiagnostics::FlushDiagnosticsImpl( // Output the bug hash for issue unique-ing. Currently, it's just an // offset from the beginning of the function. if (const Stmt *Body = DeclWithIssue->getBody()) { - FullSourceLoc Loc(SM->getExpansionLoc(D->getLocation().asLocation()), - *SM); - FullSourceLoc FunLoc(SM->getExpansionLoc(Body->getLocStart()), *SM); - o << " issue_hash" - << Loc.getExpansionLineNumber() - FunLoc.getExpansionLineNumber(); - // Augment the hash with the bug uniqueing location. For example, - // this ensures that two leaks reported on the same line will have - // different issue_hashes. + // If the bug uniqueing location exists, use it for the hash. + // For example, this ensures that two leaks reported on the same line + // will have different issue_hashes and that the hash will identify + // the leak location even after code is added between the allocation + // site and the end of scope (leak report location). PathDiagnosticLocation UPDLoc = D->getUniqueingLoc(); if (UPDLoc.isValid()) { FullSourceLoc UL(SM->getExpansionLoc(UPDLoc.asLocation()), *SM); FullSourceLoc UFunL(SM->getExpansionLoc( D->getUniqueingDecl()->getBody()->getLocStart()), *SM); - o << "_" - << UL.getExpansionLineNumber() - UFunL.getExpansionLineNumber(); + o << " issue_hash" + << UL.getExpansionLineNumber() - UFunL.getExpansionLineNumber() + << "\n"; + + // Otherwise, use the location on which the bug is reported. + } else { + FullSourceLoc L(SM->getExpansionLoc(D->getLocation().asLocation()), + *SM); + FullSourceLoc FunL(SM->getExpansionLoc(Body->getLocStart()), *SM); + o << " issue_hash" + << L.getExpansionLineNumber() - FunL.getExpansionLineNumber() + << "\n"; } - o << "\n"; + } } } diff --git a/test/Analysis/malloc-plist.c b/test/Analysis/malloc-plist.c index a48b94d03d..ddd09db6ff 100644 --- a/test/Analysis/malloc-plist.c +++ b/test/Analysis/malloc-plist.c @@ -388,7 +388,7 @@ void use_function_with_leak7() { // CHECK-NEXT: typeMemory leak // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contextdiagnosticTest -// CHECK-NEXT: issue_hash5_2 +// CHECK-NEXT: issue_hash2 // CHECK-NEXT: location // CHECK-NEXT: // CHECK-NEXT: line15 @@ -550,7 +550,7 @@ void use_function_with_leak7() { // CHECK-NEXT: typeMemory leak // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contextmyArrayAllocation -// CHECK-NEXT: issue_hash4_2 +// CHECK-NEXT: issue_hash2 // CHECK-NEXT: location // CHECK-NEXT: // CHECK-NEXT: line22 @@ -935,7 +935,7 @@ void use_function_with_leak7() { // CHECK-NEXT: typeMemory leak // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contextreallocDiagnostics -// CHECK-NEXT: issue_hash5_1 +// CHECK-NEXT: issue_hash1 // CHECK-NEXT: location // CHECK-NEXT: // CHECK-NEXT: line29 @@ -1334,7 +1334,7 @@ void use_function_with_leak7() { // CHECK-NEXT: typeMemory leak // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contexttest_wrapper -// CHECK-NEXT: issue_hash3_1 +// CHECK-NEXT: issue_hash1 // CHECK-NEXT: location // CHECK-NEXT: // CHECK-NEXT: line46 @@ -2413,7 +2413,7 @@ void use_function_with_leak7() { // CHECK-NEXT: typeMemory leak // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contextreallocIntra -// CHECK-NEXT: issue_hash3_1 +// CHECK-NEXT: issue_hash1 // CHECK-NEXT: location // CHECK-NEXT: // CHECK-NEXT: line77 @@ -2681,7 +2681,7 @@ void use_function_with_leak7() { // CHECK-NEXT: typeMemory leak // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contextuse_ret -// CHECK-NEXT: issue_hash3_2 +// CHECK-NEXT: issue_hash2 // CHECK-NEXT: location // CHECK-NEXT: // CHECK-NEXT: line87 @@ -2843,7 +2843,7 @@ void use_function_with_leak7() { // CHECK-NEXT: typeMemory leak // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contextLeakedSymbol -// CHECK-NEXT: issue_hash8_3 +// CHECK-NEXT: issue_hash3 // CHECK-NEXT: location // CHECK-NEXT: // CHECK-NEXT: line98 @@ -3048,7 +3048,7 @@ void use_function_with_leak7() { // CHECK-NEXT: typeMemory leak // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contextfunction_with_leak1 -// CHECK-NEXT: issue_hash2_1 +// CHECK-NEXT: issue_hash1 // CHECK-NEXT: location // CHECK-NEXT: // CHECK-NEXT: line104 @@ -3253,7 +3253,7 @@ void use_function_with_leak7() { // CHECK-NEXT: typeMemory leak // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contextfunction_with_leak2 -// CHECK-NEXT: issue_hash2_1 +// CHECK-NEXT: issue_hash1 // CHECK-NEXT: location // CHECK-NEXT: // CHECK-NEXT: line112 @@ -3555,7 +3555,7 @@ void use_function_with_leak7() { // CHECK-NEXT: typeMemory leak // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contextfunction_with_leak3 -// CHECK-NEXT: issue_hash3_1 +// CHECK-NEXT: issue_hash1 // CHECK-NEXT: location // CHECK-NEXT: // CHECK-NEXT: line121 @@ -3857,7 +3857,7 @@ void use_function_with_leak7() { // CHECK-NEXT: typeMemory leak // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contextfunction_with_leak4 -// CHECK-NEXT: issue_hash5_1 +// CHECK-NEXT: issue_hash1 // CHECK-NEXT: location // CHECK-NEXT: // CHECK-NEXT: line132 @@ -4062,7 +4062,7 @@ void use_function_with_leak7() { // CHECK-NEXT: typeMemory leak // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contextfunction_with_leak5 -// CHECK-NEXT: issue_hash2_1 +// CHECK-NEXT: issue_hash1 // CHECK-NEXT: location // CHECK-NEXT: // CHECK-NEXT: line143 @@ -4267,7 +4267,7 @@ void use_function_with_leak7() { // CHECK-NEXT: typeMemory leak // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contextfunction_with_leak6 -// CHECK-NEXT: issue_hash2_1 +// CHECK-NEXT: issue_hash1 // CHECK-NEXT: location // CHECK-NEXT: // CHECK-NEXT: line154 @@ -4501,7 +4501,7 @@ void use_function_with_leak7() { // CHECK-NEXT: typeMemory leak // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contextuse_function_with_leak7 -// CHECK-NEXT: issue_hash2_1 +// CHECK-NEXT: issue_hash1 // CHECK-NEXT: location // CHECK-NEXT: // CHECK-NEXT: line170