[clang] 662ed9e - Revert "[analyzer] NFC: Move IssueHash to libAnalysis."

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 13 12:07:50 PDT 2020


Author: Artem Dergachev
Date: 2020-10-13T12:07:28-07:00
New Revision: 662ed9e67adace3d011f42478bc8bcb1773a2821

URL: https://github.com/llvm/llvm-project/commit/662ed9e67adace3d011f42478bc8bcb1773a2821
DIFF: https://github.com/llvm/llvm-project/commit/662ed9e67adace3d011f42478bc8bcb1773a2821.diff

LOG: Revert "[analyzer] NFC: Move IssueHash to libAnalysis."

This reverts commit b76dc111dd02672488df794570d82e3edbbfa5d8.

Added: 
    clang/include/clang/StaticAnalyzer/Core/IssueHash.h
    clang/lib/StaticAnalyzer/Core/IssueHash.cpp

Modified: 
    clang/lib/Analysis/CMakeLists.txt
    clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
    clang/lib/StaticAnalyzer/Core/CMakeLists.txt
    clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
    clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp

Removed: 
    clang/include/clang/Analysis/IssueHash.h
    clang/lib/Analysis/IssueHash.cpp


################################################################################
diff  --git a/clang/include/clang/Analysis/IssueHash.h b/clang/include/clang/Analysis/IssueHash.h
deleted file mode 100644
index 9c02b79f58f9..000000000000
--- a/clang/include/clang/Analysis/IssueHash.h
+++ /dev/null
@@ -1,49 +0,0 @@
-//===---------- IssueHash.h - Generate identification hashes ----*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_STATICANALYZER_CORE_ISSUE_HASH_H
-#define LLVM_CLANG_STATICANALYZER_CORE_ISSUE_HASH_H
-
-#include "llvm/ADT/SmallString.h"
-
-namespace clang {
-class Decl;
-class FullSourceLoc;
-class LangOptions;
-
-/// Returns an opaque identifier for a diagnostic.
-///
-/// This opaque identifier is intended to be stable even when the source code
-/// is changed. It allows to track diagnostics in the long term, for example,
-/// find which diagnostics are "new", maintain a database of suppressed
-/// diagnostics etc.
-///
-/// We may introduce more variants of issue hashes in the future
-/// but older variants will still be available for compatibility.
-///
-/// This hash is based on the following information:
-///   - Name of the checker that emitted the diagnostic.
-///   - Warning message.
-///   - Name of the enclosing declaration.
-///   - Contents of the line of code with the issue, excluding whitespace.
-///   - Column number (but not the line number! - which makes it stable).
-llvm::SmallString<32> getIssueHash(const FullSourceLoc &IssueLoc,
-                                   llvm::StringRef CheckerName,
-                                   llvm::StringRef WarningMessage,
-                                   const Decl *IssueDecl,
-                                   const LangOptions &LangOpts);
-
-/// Get the unhashed string representation of the V1 issue hash.
-/// When hashed, it becomes the actual issue hash. Useful for testing.
-/// See GetIssueHashV1() for more information.
-std::string getIssueString(const FullSourceLoc &IssueLoc,
-                           llvm::StringRef CheckerName,
-                           llvm::StringRef WarningMessage,
-                           const Decl *IssueDecl, const LangOptions &LangOpts);
-} // namespace clang
-
-#endif

diff  --git a/clang/include/clang/StaticAnalyzer/Core/IssueHash.h b/clang/include/clang/StaticAnalyzer/Core/IssueHash.h
new file mode 100644
index 000000000000..38d5f847fc29
--- /dev/null
+++ b/clang/include/clang/StaticAnalyzer/Core/IssueHash.h
@@ -0,0 +1,50 @@
+//===---------- IssueHash.h - Generate identification hashes ----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_STATICANALYZER_CORE_ISSUE_HASH_H
+#define LLVM_CLANG_STATICANALYZER_CORE_ISSUE_HASH_H
+
+#include "llvm/ADT/SmallString.h"
+
+namespace clang {
+class Decl;
+class SourceManager;
+class FullSourceLoc;
+class LangOptions;
+
+/// Get an MD5 hash to help identify bugs.
+///
+/// This function returns a hash that helps identify bugs within a source file.
+/// This identification can be utilized to 
diff  diagnostic results on 
diff erent
+/// snapshots of a projects, or maintain a database of suppressed diagnotics.
+///
+/// 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.
+/// The last component is the string representation of the enclosing declaration
+/// of the associated location.
+///
+/// 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);
+
+/// 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);
+} // namespace clang
+
+#endif

diff  --git a/clang/lib/Analysis/CMakeLists.txt b/clang/lib/Analysis/CMakeLists.txt
index 6cad671a8a4d..82cb00a8c3e0 100644
--- a/clang/lib/Analysis/CMakeLists.txt
+++ b/clang/lib/Analysis/CMakeLists.txt
@@ -17,7 +17,6 @@ add_clang_library(clangAnalysis
   CodeInjector.cpp
   Dominators.cpp
   ExprMutationAnalyzer.cpp
-  IssueHash.cpp
   LiveVariables.cpp
   ObjCNoReturn.cpp
   PathDiagnostic.cpp

diff  --git a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
index c0167b53ae26..4225d890c47a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "Taint.h"
-#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 "clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h"
@@ -326,7 +326,7 @@ void ExprInspectionChecker::analyzerHashDump(const CallExpr *CE,
   const SourceManager &SM = C.getSourceManager();
   FullSourceLoc FL(CE->getArg(0)->getBeginLoc(), SM);
   std::string HashContent =
-      getIssueString(FL, getCheckerName().getName(), "Category",
+      GetIssueString(SM, FL, getCheckerName().getName(), "Category",
                      C.getLocationContext()->getDecl(), Opts);
 
   reportBug(HashContent, C);

diff  --git a/clang/lib/StaticAnalyzer/Core/CMakeLists.txt b/clang/lib/StaticAnalyzer/Core/CMakeLists.txt
index d947d415ad6e..f2329ae6042e 100644
--- a/clang/lib/StaticAnalyzer/Core/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Core/CMakeLists.txt
@@ -31,6 +31,7 @@ add_clang_library(clangStaticAnalyzerCore
   ExprEngineObjC.cpp
   FunctionSummary.cpp
   HTMLDiagnostics.cpp
+  IssueHash.cpp
   LoopUnrolling.cpp
   LoopWidening.cpp
   MemRegion.cpp

diff  --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
index 35c590fe396b..20e1ad307bc3 100644
--- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -10,7 +10,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "clang/Analysis/IssueHash.h"
 #include "clang/Analysis/PathDiagnostic.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
@@ -24,6 +23,7 @@
 #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"
@@ -583,8 +583,8 @@ void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R,
     os  << "\n<!-- FUNCTIONNAME " <<  declName << " -->\n";
 
     os << "\n<!-- ISSUEHASHCONTENTOFLINEINCONTEXT "
-       << getIssueHash(L, D.getCheckerName(), D.getBugType(), DeclWithIssue,
-                       PP.getLangOpts())
+       << GetIssueHash(SMgr, L, D.getCheckerName(), D.getBugType(),
+                       DeclWithIssue, PP.getLangOpts())
        << " -->\n";
 
     os << "\n<!-- BUGLINE "

diff  --git a/clang/lib/Analysis/IssueHash.cpp b/clang/lib/StaticAnalyzer/Core/IssueHash.cpp
similarity index 84%
rename from clang/lib/Analysis/IssueHash.cpp
rename to clang/lib/StaticAnalyzer/Core/IssueHash.cpp
index 13005fe587e9..e7497f3fbdaa 100644
--- a/clang/lib/Analysis/IssueHash.cpp
+++ b/clang/lib/StaticAnalyzer/Core/IssueHash.cpp
@@ -5,8 +5,7 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
-
-#include "clang/Analysis/IssueHash.h"
+#include "clang/StaticAnalyzer/Core/IssueHash.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
@@ -132,7 +131,7 @@ static StringRef GetNthLineOfFile(const llvm::MemoryBuffer *Buffer, int Line) {
   return *LI;
 }
 
-static std::string NormalizeLine(const SourceManager &SM, const FullSourceLoc &L,
+static std::string NormalizeLine(const SourceManager &SM, FullSourceLoc &L,
                                  const LangOptions &LangOpts) {
   static StringRef Whitespaces = " \t\n";
 
@@ -168,7 +167,7 @@ static std::string NormalizeLine(const SourceManager &SM, const FullSourceLoc &L
   return LineBuff.str();
 }
 
-static llvm::SmallString<32> GetMD5HashOfContent(StringRef Content) {
+static llvm::SmallString<32> GetHashOfContent(StringRef Content) {
   llvm::MD5 Hash;
   llvm::MD5::MD5Result MD5Res;
   SmallString<32> Res;
@@ -180,27 +179,26 @@ static llvm::SmallString<32> GetMD5HashOfContent(StringRef Content) {
   return Res;
 }
 
-std::string clang::getIssueString(const FullSourceLoc &IssueLoc,
-                                  StringRef CheckerName,
-                                  StringRef WarningMessage,
-                                  const Decl *IssueDecl,
+std::string clang::GetIssueString(const SourceManager &SM,
+                                  FullSourceLoc &IssueLoc,
+                                  StringRef CheckerName, StringRef BugType,
+                                  const Decl *D,
                                   const LangOptions &LangOpts) {
   static StringRef Delimiter = "$";
 
   return (llvm::Twine(CheckerName) + Delimiter +
-          GetEnclosingDeclContextSignature(IssueDecl) + Delimiter +
+          GetEnclosingDeclContextSignature(D) + Delimiter +
           Twine(IssueLoc.getExpansionColumnNumber()) + Delimiter +
-          NormalizeLine(IssueLoc.getManager(), IssueLoc, LangOpts) +
-          Delimiter + WarningMessage)
+          NormalizeLine(SM, IssueLoc, LangOpts) + Delimiter + BugType)
       .str();
 }
 
-SmallString<32> clang::getIssueHash(const FullSourceLoc &IssueLoc,
-                                    StringRef CheckerName,
-                                    StringRef WarningMessage,
-                                    const Decl *IssueDecl,
+SmallString<32> clang::GetIssueHash(const SourceManager &SM,
+                                    FullSourceLoc &IssueLoc,
+                                    StringRef CheckerName, StringRef BugType,
+                                    const Decl *D,
                                     const LangOptions &LangOpts) {
 
-  return GetMD5HashOfContent(getIssueString(
-      IssueLoc, CheckerName, WarningMessage, IssueDecl, LangOpts));
+  return GetHashOfContent(
+      GetIssueString(SM, IssueLoc, CheckerName, BugType, D, LangOpts));
 }

diff  --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
index 18d83465eca6..c11fcc90efe1 100644
--- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -10,7 +10,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "clang/Analysis/IssueHash.h"
 #include "clang/Analysis/PathDiagnostic.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/PlistSupport.h"
@@ -21,6 +20,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/TokenConcatenation.h"
 #include "clang/Rewrite/Core/HTMLRewrite.h"
+#include "clang/StaticAnalyzer/Core/IssueHash.h"
 #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
@@ -697,7 +697,7 @@ void PlistDiagnostics::FlushDiagnosticsImpl(
                                             : D->getLocation().asLocation()),
                     SM);
     const Decl *DeclWithIssue = D->getDeclWithIssue();
-    EmitString(o, getIssueHash(L, D->getCheckerName(), D->getBugType(),
+    EmitString(o, GetIssueHash(SM, L, D->getCheckerName(), D->getBugType(),
                                DeclWithIssue, LangOpts))
         << '\n';
 


        


More information about the cfe-commits mailing list