mirror of https://github.com/microsoft/clang.git
[analyzer] Make issue hash related tests more concise
Extend ExprInspection checker to make it possible to dump the issue hash of arbitrary expressions. This change makes it possible to make issue hash related tests more concise and also makes debugging issue hash related problems easier. Differential Revision: https://reviews.llvm.org/D38844 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316899 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a855bcfaf2
commit
a154e5b192
|
@ -749,10 +749,6 @@ def ExplodedGraphViewer : Checker<"ViewExplodedGraph">,
|
|||
HelpText<"View Exploded Graphs using GraphViz">,
|
||||
DescFile<"DebugCheckers.cpp">;
|
||||
|
||||
def BugHashDumper : Checker<"DumpBugHash">,
|
||||
HelpText<"Dump the bug hash for all statements.">,
|
||||
DescFile<"DebugCheckers.cpp">;
|
||||
|
||||
} // end "debug"
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#include "clang/Analysis/Analyses/LiveVariables.h"
|
||||
#include "clang/Analysis/CallGraph.h"
|
||||
#include "clang/StaticAnalyzer/Core/Checker.h"
|
||||
#include "clang/StaticAnalyzer/Core/IssueHash.h"
|
||||
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
|
||||
|
@ -213,35 +212,3 @@ void ento::registerExplodedGraphViewer(CheckerManager &mgr) {
|
|||
mgr.registerChecker<ExplodedGraphViewer>();
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// DumpBugHash
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
namespace {
|
||||
class BugHashDumper : public Checker<check::PostStmt<Stmt>> {
|
||||
public:
|
||||
mutable std::unique_ptr<BugType> BT;
|
||||
|
||||
void checkPostStmt(const Stmt *S, CheckerContext &C) const {
|
||||
if (!BT)
|
||||
BT.reset(new BugType(this, "Dump hash components", "debug"));
|
||||
|
||||
ExplodedNode *N = C.generateNonFatalErrorNode();
|
||||
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(), Opts);
|
||||
|
||||
C.emitReport(llvm::make_unique<BugReport>(*BT, HashContent, N));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void ento::registerBugHashDumper(CheckerManager &mgr) {
|
||||
mgr.registerChecker<BugHashDumper>();
|
||||
}
|
||||
|
|
|
@ -8,10 +8,11 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "ClangSACheckers.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/CheckerContext.h"
|
||||
#include "clang/StaticAnalyzer/Checkers/SValExplainer.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/Support/ScopedPrinter.h"
|
||||
|
||||
|
@ -41,6 +42,7 @@ class ExprInspectionChecker : public Checker<eval::Call, check::DeadSymbols,
|
|||
void analyzerExplain(const CallExpr *CE, CheckerContext &C) const;
|
||||
void analyzerPrintState(const CallExpr *CE, CheckerContext &C) const;
|
||||
void analyzerGetExtent(const CallExpr *CE, CheckerContext &C) const;
|
||||
void analyzerHashDump(const CallExpr *CE, CheckerContext &C) const;
|
||||
|
||||
typedef void (ExprInspectionChecker::*FnCheck)(const CallExpr *,
|
||||
CheckerContext &C) const;
|
||||
|
@ -79,6 +81,7 @@ bool ExprInspectionChecker::evalCall(const CallExpr *CE,
|
|||
&ExprInspectionChecker::analyzerPrintState)
|
||||
.Case("clang_analyzer_numTimesReached",
|
||||
&ExprInspectionChecker::analyzerNumTimesReached)
|
||||
.Case("clang_analyzer_hashDump", &ExprInspectionChecker::analyzerHashDump)
|
||||
.Default(nullptr);
|
||||
|
||||
if (!Handler)
|
||||
|
@ -280,7 +283,18 @@ void ExprInspectionChecker::analyzerCrash(const CallExpr *CE,
|
|||
LLVM_BUILTIN_TRAP;
|
||||
}
|
||||
|
||||
void ExprInspectionChecker::analyzerHashDump(const CallExpr *CE,
|
||||
CheckerContext &C) const {
|
||||
const LangOptions &Opts = C.getLangOpts();
|
||||
const SourceManager &SM = C.getSourceManager();
|
||||
FullSourceLoc FL(CE->getArg(0)->getLocStart(), SM);
|
||||
std::string HashContent =
|
||||
GetIssueString(SM, FL, getCheckName().getName(), "Category",
|
||||
C.getLocationContext()->getDecl(), Opts);
|
||||
|
||||
reportBug(HashContent, C);
|
||||
}
|
||||
|
||||
void ento::registerExprInspectionChecker(CheckerManager &Mgr) {
|
||||
Mgr.registerChecker<ExprInspectionChecker>();
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue