Skip to content

Commit

Permalink
Revert "[analyzer] NFC: Move IssueHash to libAnalysis."
Browse files Browse the repository at this point in the history
This reverts commit b76dc11.
  • Loading branch information
haoNoQ committed Oct 13, 2020
1 parent 77bb3eb commit 662ed9e
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 74 deletions.
49 changes: 0 additions & 49 deletions clang/include/clang/Analysis/IssueHash.h

This file was deleted.

50 changes: 50 additions & 0 deletions clang/include/clang/StaticAnalyzer/Core/IssueHash.h
Original file line number Diff line number Diff line change
@@ -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 different
/// 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
1 change: 0 additions & 1 deletion clang/lib/Analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ add_clang_library(clangAnalysis
CodeInjector.cpp
Dominators.cpp
ExprMutationAnalyzer.cpp
IssueHash.cpp
LiveVariables.cpp
ObjCNoReturn.cpp
PathDiagnostic.cpp
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions clang/lib/StaticAnalyzer/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ add_clang_library(clangStaticAnalyzerCore
ExprEngineObjC.cpp
FunctionSummary.cpp
HTMLDiagnostics.cpp
IssueHash.cpp
LoopUnrolling.cpp
LoopWidening.cpp
MemRegion.cpp
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//

#include "clang/Analysis/IssueHash.h"
#include "clang/Analysis/PathDiagnostic.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
Expand All @@ -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"
Expand Down Expand Up @@ -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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -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;
Expand All @@ -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));
}
4 changes: 2 additions & 2 deletions clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//

#include "clang/Analysis/IssueHash.h"
#include "clang/Analysis/PathDiagnostic.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/PlistSupport.h"
Expand All @@ -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"
Expand Down Expand Up @@ -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';

Expand Down

0 comments on commit 662ed9e

Please sign in to comment.