From: Gabor Horvath Date: Tue, 1 Dec 2015 09:00:41 +0000 (+0000) Subject: [analyzer] Fix IssueHash generation. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d69b791aec6da09f35c5c852e65d6cf14151bed5;p=clang [analyzer] Fix IssueHash generation. Differential Revision: http://reviews.llvm.org/D14919 Original patch by: Gyorgy Orban! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254394 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/StaticAnalyzer/Core/IssueHash.h b/include/clang/StaticAnalyzer/Core/IssueHash.h index 913ab7964f..b3c4f14655 100644 --- a/include/clang/StaticAnalyzer/Core/IssueHash.h +++ b/include/clang/StaticAnalyzer/Core/IssueHash.h @@ -15,6 +15,7 @@ namespace clang { class Decl; class SourceManager; class FullSourceLoc; +class LangOptions; /// \brief Get an MD5 hash to help identify bugs. /// @@ -37,13 +38,14 @@ class FullSourceLoc; llvm::SmallString<32> GetIssueHash(const SourceManager &SM, FullSourceLoc &IssueLoc, llvm::StringRef CheckerName, - llvm::StringRef BugType, const Decl *D); + llvm::StringRef BugType, const Decl *D, + const LangOptions &LangOpts); /// \brief Get the string representation of issue hash. See GetIssueHash() for /// more information. std::string GetIssueString(const SourceManager &SM, FullSourceLoc &IssueLoc, llvm::StringRef CheckerName, llvm::StringRef BugType, - const Decl *D); + const Decl *D, const LangOptions &LangOpts); } // namespace clang #endif diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 80a003fc93..4c501616a3 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -1717,7 +1717,7 @@ SourceLocation SourceManager::translateLineCol(FileID FID, unsigned Col) const { // Lines are used as a one-based index into a zero-based array. This assert // checks for possible buffer underruns. - assert(Line != 0 && "Passed a zero-based line"); + assert(Line && Col && "Line and column should start from 1!"); if (FID.isInvalid()) return SourceLocation(); diff --git a/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp b/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp index acf0004136..2eef1688d4 100644 --- a/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp +++ b/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp @@ -230,11 +230,12 @@ public: if (!N) return; + const LangOptions &Opts = C.getLangOpts(); const SourceManager &SM = C.getSourceManager(); FullSourceLoc FL(S->getLocStart(), SM); std::string HashContent = GetIssueString(SM, FL, getCheckName().getName(), BT->getCategory(), - C.getLocationContext()->getDecl()); + C.getLocationContext()->getDecl(), Opts); C.emitReport(llvm::make_unique(*BT, HashContent, N)); } diff --git a/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp index 86eab41a4c..183acbe1d9 100644 --- a/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp +++ b/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp @@ -255,8 +255,8 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D, os << "\n\n"; os << "\n\n"; + << GetIssueHash(SMgr, L, D.getCheckName(), D.getBugType(), DeclWithIssue, + PP.getLangOpts()) << " -->\n"; os << "\n -// CHECK-NEXT: issue_hash_content_of_line_in_contextf8ee38da3de42e209c4afa886b5531ab +// CHECK-NEXT: issue_hash_content_of_line_in_contextf5471f52854dc14167fe96db50c4ba5f // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contextf // CHECK-NEXT: issue_hash_function_offset0 diff --git a/test/Analysis/diagnostics/report-issues-within-main-file.cpp b/test/Analysis/diagnostics/report-issues-within-main-file.cpp index cb998965f7..5fd7abd03c 100644 --- a/test/Analysis/diagnostics/report-issues-within-main-file.cpp +++ b/test/Analysis/diagnostics/report-issues-within-main-file.cpp @@ -949,7 +949,7 @@ void callInMacroArg() { // CHECK-NEXT: typeBad deallocator // CHECK-NEXT: check_nameunix.MismatchedDeallocator // CHECK-NEXT: -// CHECK-NEXT: issue_hash_content_of_line_in_contextf21ac032efaa3d1459a5ed31f0ad44f0 +// CHECK-NEXT: issue_hash_content_of_line_in_contextf689fbd54138491e228f0f89bb02bfb2 // CHECK-NEXT: issue_context_kindfunction // CHECK-NEXT: issue_contextmainPlusHeader // CHECK-NEXT: issue_hash_function_offset2