Index: clang/include/clang/Analysis/IssueHash.h =================================================================== --- clang/include/clang/Analysis/IssueHash.h +++ clang/include/clang/Analysis/IssueHash.h @@ -12,7 +12,6 @@ namespace clang { class Decl; -class SourceManager; class FullSourceLoc; class LangOptions; @@ -25,26 +24,31 @@ /// The hash contains the normalized text of the location associated with the /// diagnostic. Normalization means removing the whitespaces. The associated /// location is the either the last location of a diagnostic path or a uniqueing -/// location. The bugtype and the name of the checker is also part of the hash. +/// location. The warning message and the name of the checker (the entity that +/// was responsible for displaying the issue) is also part of the hash. /// The last component is the string representation of the enclosing declaration /// of the associated location. /// +/// If the warning message is flaky (e.g. contains line numbers), it makes sense +/// to put a simplified message text into the hash. +/// /// In case a new hash is introduced, the old one should still be maintained for /// a while. One should not introduce a new hash for every change, it is /// possible to introduce experimental hashes that may change in the future. /// Such hashes should be marked as experimental using a comment in the plist /// files. -llvm::SmallString<32> GetIssueHash(const SourceManager &SM, - FullSourceLoc &IssueLoc, - llvm::StringRef CheckerName, - llvm::StringRef BugType, const Decl *D, - const LangOptions &LangOpts); +llvm::SmallString<32> +GetIssueHash(FullSourceLoc &IssueLoc, + llvm::StringRef CheckerName, llvm::StringRef WarningMessage, + const Decl *IssueDecl, const LangOptions &LangOpts); /// 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 LangOptions &LangOpts); +std::string GetIssueString(FullSourceLoc &IssueLoc, + llvm::StringRef CheckerName, + llvm::StringRef WarningMessage, + const Decl *IssueDecl, + const LangOptions &LangOpts); } // namespace clang #endif Index: clang/lib/Analysis/CMakeLists.txt =================================================================== --- clang/lib/Analysis/CMakeLists.txt +++ clang/lib/Analysis/CMakeLists.txt @@ -16,6 +16,7 @@ CodeInjector.cpp Dominators.cpp ExprMutationAnalyzer.cpp + IssueHash.cpp LiveVariables.cpp ObjCNoReturn.cpp PathDiagnostic.cpp Index: clang/lib/Analysis/IssueHash.cpp =================================================================== --- clang/lib/Analysis/IssueHash.cpp +++ clang/lib/Analysis/IssueHash.cpp @@ -5,7 +5,8 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// -#include "clang/StaticAnalyzer/Core/IssueHash.h" + +#include "clang/Analysis/IssueHash.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" @@ -179,26 +180,27 @@ return Res; } -std::string clang::GetIssueString(const SourceManager &SM, - FullSourceLoc &IssueLoc, - StringRef CheckerName, StringRef BugType, - const Decl *D, +std::string clang::GetIssueString(FullSourceLoc &IssueLoc, + StringRef CheckerName, + StringRef WarningMessage, + const Decl *IssueDecl, const LangOptions &LangOpts) { static StringRef Delimiter = "$"; return (llvm::Twine(CheckerName) + Delimiter + - GetEnclosingDeclContextSignature(D) + Delimiter + + GetEnclosingDeclContextSignature(IssueDecl) + Delimiter + Twine(IssueLoc.getExpansionColumnNumber()) + Delimiter + - NormalizeLine(SM, IssueLoc, LangOpts) + Delimiter + BugType) + NormalizeLine(IssueLoc.getManager(), IssueLoc, LangOpts) + + Delimiter + WarningMessage) .str(); } -SmallString<32> clang::GetIssueHash(const SourceManager &SM, - FullSourceLoc &IssueLoc, - StringRef CheckerName, StringRef BugType, - const Decl *D, +SmallString<32> clang::GetIssueHash(FullSourceLoc &IssueLoc, + StringRef CheckerName, + StringRef WarningMessage, + const Decl *IssueDecl, const LangOptions &LangOpts) { - return GetHashOfContent( - GetIssueString(SM, IssueLoc, CheckerName, BugType, D, LangOpts)); + return GetHashOfContent(GetIssueString(IssueLoc, CheckerName, WarningMessage, + IssueDecl, LangOpts)); } Index: clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp @@ -6,11 +6,11 @@ // //===----------------------------------------------------------------------===// +#include "clang/Analysis/IssueHash.h" #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" #include "clang/StaticAnalyzer/Checkers/SValExplainer.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" #include "clang/StaticAnalyzer/Core/Checker.h" -#include "clang/StaticAnalyzer/Core/IssueHash.h" #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" #include "llvm/ADT/StringSwitch.h" @@ -305,7 +305,7 @@ const SourceManager &SM = C.getSourceManager(); FullSourceLoc FL(CE->getArg(0)->getBeginLoc(), SM); std::string HashContent = - GetIssueString(SM, FL, getCheckName().getName(), "Category", + GetIssueString(FL, getCheckName().getName(), "Category", C.getLocationContext()->getDecl(), Opts); reportBug(HashContent, C); Index: clang/lib/StaticAnalyzer/Core/CMakeLists.txt =================================================================== --- clang/lib/StaticAnalyzer/Core/CMakeLists.txt +++ clang/lib/StaticAnalyzer/Core/CMakeLists.txt @@ -26,7 +26,6 @@ ExprEngineObjC.cpp FunctionSummary.cpp HTMLDiagnostics.cpp - IssueHash.cpp LoopUnrolling.cpp LoopWidening.cpp MemRegion.cpp Index: clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp +++ clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp @@ -10,6 +10,7 @@ // //===----------------------------------------------------------------------===// +#include "clang/Analysis/IssueHash.h" #include "clang/Analysis/PathDiagnostic.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclBase.h" @@ -23,7 +24,6 @@ #include "clang/Lex/Token.h" #include "clang/Rewrite/Core/HTMLRewrite.h" #include "clang/Rewrite/Core/Rewriter.h" -#include "clang/StaticAnalyzer/Core/IssueHash.h" #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallString.h" @@ -554,7 +554,7 @@ os << "\n\n"; os << "\n\n"; os << "\n