Skip to content

Commit 3bd24f9

Browse files
committedOct 30, 2017
[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 llvm-svn: 316899
1 parent f94da59 commit 3bd24f9

File tree

5 files changed

+125
-2531
lines changed

5 files changed

+125
-2531
lines changed
 

‎clang/include/clang/StaticAnalyzer/Checkers/Checkers.td

-4
Original file line numberDiff line numberDiff line change
@@ -749,10 +749,6 @@ def ExplodedGraphViewer : Checker<"ViewExplodedGraph">,
749749
HelpText<"View Exploded Graphs using GraphViz">,
750750
DescFile<"DebugCheckers.cpp">;
751751

752-
def BugHashDumper : Checker<"DumpBugHash">,
753-
HelpText<"Dump the bug hash for all statements.">,
754-
DescFile<"DebugCheckers.cpp">;
755-
756752
} // end "debug"
757753

758754

‎clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp

-33
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "clang/Analysis/Analyses/LiveVariables.h"
1717
#include "clang/Analysis/CallGraph.h"
1818
#include "clang/StaticAnalyzer/Core/Checker.h"
19-
#include "clang/StaticAnalyzer/Core/IssueHash.h"
2019
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
2120
#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
2221
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
@@ -213,35 +212,3 @@ void ento::registerExplodedGraphViewer(CheckerManager &mgr) {
213212
mgr.registerChecker<ExplodedGraphViewer>();
214213
}
215214

216-
//===----------------------------------------------------------------------===//
217-
// DumpBugHash
218-
//===----------------------------------------------------------------------===//
219-
220-
namespace {
221-
class BugHashDumper : public Checker<check::PostStmt<Stmt>> {
222-
public:
223-
mutable std::unique_ptr<BugType> BT;
224-
225-
void checkPostStmt(const Stmt *S, CheckerContext &C) const {
226-
if (!BT)
227-
BT.reset(new BugType(this, "Dump hash components", "debug"));
228-
229-
ExplodedNode *N = C.generateNonFatalErrorNode();
230-
if (!N)
231-
return;
232-
233-
const LangOptions &Opts = C.getLangOpts();
234-
const SourceManager &SM = C.getSourceManager();
235-
FullSourceLoc FL(S->getLocStart(), SM);
236-
std::string HashContent =
237-
GetIssueString(SM, FL, getCheckName().getName(), BT->getCategory(),
238-
C.getLocationContext()->getDecl(), Opts);
239-
240-
C.emitReport(llvm::make_unique<BugReport>(*BT, HashContent, N));
241-
}
242-
};
243-
}
244-
245-
void ento::registerBugHashDumper(CheckerManager &mgr) {
246-
mgr.registerChecker<BugHashDumper>();
247-
}

‎clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
//===----------------------------------------------------------------------===//
99

1010
#include "ClangSACheckers.h"
11+
#include "clang/StaticAnalyzer/Checkers/SValExplainer.h"
1112
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
1213
#include "clang/StaticAnalyzer/Core/Checker.h"
14+
#include "clang/StaticAnalyzer/Core/IssueHash.h"
1315
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
14-
#include "clang/StaticAnalyzer/Checkers/SValExplainer.h"
1516
#include "llvm/ADT/StringSwitch.h"
1617
#include "llvm/Support/ScopedPrinter.h"
1718

@@ -41,6 +42,7 @@ class ExprInspectionChecker : public Checker<eval::Call, check::DeadSymbols,
4142
void analyzerExplain(const CallExpr *CE, CheckerContext &C) const;
4243
void analyzerPrintState(const CallExpr *CE, CheckerContext &C) const;
4344
void analyzerGetExtent(const CallExpr *CE, CheckerContext &C) const;
45+
void analyzerHashDump(const CallExpr *CE, CheckerContext &C) const;
4446

4547
typedef void (ExprInspectionChecker::*FnCheck)(const CallExpr *,
4648
CheckerContext &C) const;
@@ -79,6 +81,7 @@ bool ExprInspectionChecker::evalCall(const CallExpr *CE,
7981
&ExprInspectionChecker::analyzerPrintState)
8082
.Case("clang_analyzer_numTimesReached",
8183
&ExprInspectionChecker::analyzerNumTimesReached)
84+
.Case("clang_analyzer_hashDump", &ExprInspectionChecker::analyzerHashDump)
8285
.Default(nullptr);
8386

8487
if (!Handler)
@@ -280,7 +283,18 @@ void ExprInspectionChecker::analyzerCrash(const CallExpr *CE,
280283
LLVM_BUILTIN_TRAP;
281284
}
282285

286+
void ExprInspectionChecker::analyzerHashDump(const CallExpr *CE,
287+
CheckerContext &C) const {
288+
const LangOptions &Opts = C.getLangOpts();
289+
const SourceManager &SM = C.getSourceManager();
290+
FullSourceLoc FL(CE->getArg(0)->getLocStart(), SM);
291+
std::string HashContent =
292+
GetIssueString(SM, FL, getCheckName().getName(), "Category",
293+
C.getLocationContext()->getDecl(), Opts);
294+
295+
reportBug(HashContent, C);
296+
}
297+
283298
void ento::registerExprInspectionChecker(CheckerManager &Mgr) {
284299
Mgr.registerChecker<ExprInspectionChecker>();
285300
}
286-

‎clang/test/Analysis/bug_hash_test.cpp

+96-1,323
Large diffs are not rendered by default.

‎clang/test/Analysis/bug_hash_test.m

+13-1,169
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.