Skip to content

Commit f339eb1

Browse files
Ease debugging
1 parent 7711fe7 commit f339eb1

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

clang/unittests/StaticAnalyzer/BlockEntranceCallbackTest.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,6 @@ void addBranchConditionTester(AnalysisASTConsumer &AnalysisConsumer,
107107
});
108108
}
109109

110-
/// Add this to the \c runChecker template arguments to enable dumping the CFG
111-
/// and the ExplodedGraph for debugging a failing test case.
112-
[[maybe_unused]] void dumpCFGAndEgraph(AnalysisASTConsumer &AnalysisConsumer,
113-
AnalyzerOptions &AnOpts) {
114-
AnOpts.CheckersAndPackages.emplace_back("debug.DumpCFG", true);
115-
AnOpts.CheckersAndPackages.emplace_back("debug.ViewExplodedGraph", true);
116-
}
117-
118110
llvm::SmallVector<StringRef> parseEachDiag(StringRef Diags) {
119111
llvm::SmallVector<StringRef> Fragments;
120112
llvm::SplitString(Diags, Fragments, "\n");
@@ -137,6 +129,19 @@ bool runChecker(const std::string &Code, std::string &Diags) {
137129
return Res;
138130
}
139131

132+
[[maybe_unused]] void dumpCFGAndEgraph(AnalysisASTConsumer &AnalysisConsumer,
133+
AnalyzerOptions &AnOpts) {
134+
AnOpts.CheckersAndPackages.emplace_back("debug.DumpCFG", true);
135+
AnOpts.CheckersAndPackages.emplace_back("debug.ViewExplodedGraph", true);
136+
}
137+
138+
/// Use this instead of \c runChecker to enable the debugging a test case.
139+
template <AddCheckerFn... Fns>
140+
[[maybe_unused]] bool debugChecker(const std::string &Code,
141+
std::string &Diags) {
142+
return runChecker<dumpCFGAndEgraph, Fns...>(Code, Diags);
143+
}
144+
140145
std::string expected(SmallVector<StringRef> Diags) {
141146
llvm::sort(Diags);
142147
std::string Result;
@@ -152,6 +157,7 @@ TEST(BlockEntranceTester, FromEntryToExit) {
152157
})cpp";
153158

154159
std::string Diags;
160+
// Use "debugChecker" instead of "runChecker" for debugging.
155161
EXPECT_TRUE(runChecker(Code, Diags));
156162
EXPECT_EQ(expected({"Within 'top' B1 -> B0"}), Diags);
157163
}
@@ -170,6 +176,7 @@ TEST(BlockEntranceTester, SingleOpaqueIfCondition) {
170176
})cpp";
171177

172178
std::string Diags;
179+
// Use "debugChecker" instead of "runChecker" for debugging.
173180
EXPECT_TRUE(runChecker(Code, Diags));
174181
EXPECT_EQ(expected({
175182
"Within 'top' B1 -> B0",
@@ -203,6 +210,7 @@ TEST(BlockEntranceTester, TrivialIfCondition) {
203210
})cpp";
204211

205212
std::string Diags;
213+
// Use "debugChecker" instead of "runChecker" for debugging.
206214
EXPECT_TRUE(runChecker(Code, Diags));
207215
EXPECT_EQ(expected({
208216
"Within 'top' B1 -> B0",
@@ -227,6 +235,7 @@ TEST(BlockEntranceTester, AcrossFunctions) {
227235
})cpp";
228236

229237
std::string Diags;
238+
// Use "debugChecker" instead of "runChecker" for debugging.
230239
EXPECT_TRUE(runChecker(Code, Diags));
231240
EXPECT_EQ(
232241
expected({
@@ -273,6 +282,7 @@ TEST(BlockEntranceTester, ShortCircuitingLogicalOperator) {
273282
// (v = x): false
274283

275284
std::string Diags;
285+
// Use "debugChecker" instead of "runChecker" for debugging.
276286
EXPECT_TRUE(runChecker(Code, Diags));
277287
EXPECT_EQ(expected({
278288
"Within 'top' B1 -> B0",
@@ -313,6 +323,7 @@ TEST(BlockEntranceTester, Switch) {
313323
// +----+
314324

315325
std::string Diags;
326+
// Use "debugChecker" instead of "runChecker" for debugging.
316327
EXPECT_TRUE(runChecker(Code, Diags));
317328
EXPECT_EQ(expected({
318329
"Within 'top' B1 -> B0",
@@ -341,6 +352,7 @@ TEST(BlockEntranceTester, BlockEntranceVSBranchCondition) {
341352
return v;
342353
})cpp";
343354
std::string Diags;
355+
// Use "debugChecker" instead of "runChecker" for debugging.
344356
EXPECT_TRUE((runChecker<addBlockEntranceTester, addBranchConditionTester>(
345357
Code, Diags)));
346358
EXPECT_EQ(expected({

0 commit comments

Comments
 (0)