Skip to content

Commit 29dff0d

Browse files
author
Balazs Benics
committed
[analyzer] Allow CFG dumps in release builds
This is a similar commit to D124442, but for CFG dumps. The binary size diff remained the same demonstrated in that patch. This time I'm adding tests for demonstrating that all the dump debug checkers work - even in regular builds without asserts. Reviewed By: martong Differential Revision: https://reviews.llvm.org/D124443
1 parent 5ce7050 commit 29dff0d

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

clang/lib/Analysis/CFG.cpp

+2-10
Original file line numberDiff line numberDiff line change
@@ -6127,17 +6127,13 @@ Stmt *CFGBlock::getTerminatorCondition(bool StripParens) {
61276127
// CFG Graphviz Visualization
61286128
//===----------------------------------------------------------------------===//
61296129

6130-
#ifndef NDEBUG
6131-
static StmtPrinterHelper* GraphHelper;
6132-
#endif
6130+
static StmtPrinterHelper *GraphHelper;
61336131

61346132
void CFG::viewCFG(const LangOptions &LO) const {
6135-
#ifndef NDEBUG
61366133
StmtPrinterHelper H(this, LO);
61376134
GraphHelper = &H;
61386135
llvm::ViewGraph(this,"CFG");
61396136
GraphHelper = nullptr;
6140-
#endif
61416137
}
61426138

61436139
namespace llvm {
@@ -6146,8 +6142,7 @@ template<>
61466142
struct DOTGraphTraits<const CFG*> : public DefaultDOTGraphTraits {
61476143
DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {}
61486144

6149-
static std::string getNodeLabel(const CFGBlock *Node, const CFG* Graph) {
6150-
#ifndef NDEBUG
6145+
static std::string getNodeLabel(const CFGBlock *Node, const CFG *Graph) {
61516146
std::string OutSStr;
61526147
llvm::raw_string_ostream Out(OutSStr);
61536148
print_block(Out,Graph, *Node, *GraphHelper, false, false);
@@ -6163,9 +6158,6 @@ struct DOTGraphTraits<const CFG*> : public DefaultDOTGraphTraits {
61636158
}
61646159

61656160
return OutStr;
6166-
#else
6167-
return {};
6168-
#endif
61696161
}
61706162
};
61716163

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpDominators %s > %t 2>&1
2+
// RUN: FileCheck --input-file=%t %s -check-prefix=DOM-CHECK
3+
// DOM-CHECK: Immediate dominance tree (Node#,IDom#)
4+
5+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpPostDominators %s > %t 2>&1
6+
// RUN: FileCheck --input-file=%t %s -check-prefix=POSTDOM-CHECK
7+
// POSTDOM-CHECK: Immediate post dominance tree (Node#,IDom#)
8+
9+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpControlDependencies %s > %t 2>&1
10+
// RUN: FileCheck --input-file=%t %s -check-prefix=CTRLDEPS-CHECK
11+
// CTRLDEPS-CHECK: Control dependencies (Node#,Dependency#)
12+
13+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpLiveVars %s > %t 2>&1
14+
// RUN: FileCheck --input-file=%t %s -check-prefix=LIVE-VARS-CHECK
15+
// LIVE-VARS-CHECK: live variables at block exit
16+
17+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpLiveExprs %s > %t 2>&1
18+
// RUN: FileCheck --input-file=%t %s -check-prefix=LIVE-EXPRS-CHECK
19+
// LIVE-EXPRS-CHECK: live expressions at block exit
20+
21+
// Skip testing CFGViewer.
22+
23+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpCFG %s > %t 2>&1
24+
// RUN: FileCheck --input-file=%t %s -check-prefix=CFG-CHECK
25+
// CFG-CHECK: ENTRY
26+
27+
// Skip testing CallGraphViewer.
28+
29+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpCallGraph %s > %t 2>&1
30+
// RUN: FileCheck --input-file=%t %s -check-prefix=CALL-GRAPH-CHECK
31+
// CALL-GRAPH-CHECK: --- Call graph Dump ---
32+
33+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ConfigDumper %s > %t 2>&1
34+
// RUN: FileCheck --input-file=%t %s -check-prefix=CONFIG-CHECK
35+
// CONFIG-CHECK: [config]
36+
37+
// Skip testing ExplodedGraphViewer.
38+
39+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ReportStmts %s > %t 2>&1
40+
// RUN: FileCheck --input-file=%t %s -check-prefix=REPORT-STMTS-CHECK
41+
// REPORT-STMTS-CHECK: warning: Statement
42+
43+
void foo(int *p) {
44+
*p = 3;
45+
}
46+
47+
int bar() {
48+
int x;
49+
foo(&x);
50+
return x;
51+
}

0 commit comments

Comments
 (0)