Skip to content

Commit 5ce7050

Browse files
author
Balazs Benics
committed
[analyzer] Allow exploded graph dumps in release builds
Historically, exploded graph dumps were disabled in non-debug builds. It was done so probably because a regular user should not dump the internal representation of the analyzer anyway and the dump methods might introduce unnecessary binary size overhead. It turns out some of the users actually want to dump this. Note that e.g. `LiveExpressionsDumper`, `LiveVariablesDumper`, `ControlDependencyTreeDumper` etc. worked previously, and they are unaffected by this change. However, `CFGViewer` and `CFGDumper` still won't work for a similar reason. AFAIK only these two won't work after this change. Addresses #53873 --- **baseline** | binary | size | size after strip | | clang | 103M | 83M | | clang-tidy | 67M | 54M | **after this change** | binary | size | size after strip | | clang | 103M | 84M | | clang-tidy | 67M | 54M | CMake configuration: ``` cmake -S llvm -GNinja -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_USE_LINKER=lld -DLLVM_ENABLE_DUMP=OFF -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DLLVM_ENABLE_Z3_SOLVER=ON -DLLVM_TARGETS_TO_BUILD="X86" ``` Built by `clang-14.0.0`. Reviewed By: martong Differential Revision: https://reviews.llvm.org/D124442
1 parent 86bb7df commit 5ce7050

10 files changed

+16
-47
lines changed

clang/lib/StaticAnalyzer/Core/ExprEngine.cpp

+12-33
Original file line numberDiff line numberDiff line change
@@ -3119,7 +3119,6 @@ void ExprEngine::VisitMSAsmStmt(const MSAsmStmt *A, ExplodedNode *Pred,
31193119
// Visualization.
31203120
//===----------------------------------------------------------------------===//
31213121

3122-
#ifndef NDEBUG
31233122
namespace llvm {
31243123

31253124
template<>
@@ -3217,29 +3216,18 @@ struct DOTGraphTraits<ExplodedGraph*> : public DefaultDOTGraphTraits {
32173216
};
32183217

32193218
} // namespace llvm
3220-
#endif
32213219

32223220
void ExprEngine::ViewGraph(bool trim) {
3223-
#ifndef NDEBUG
32243221
std::string Filename = DumpGraph(trim);
32253222
llvm::DisplayGraph(Filename, false, llvm::GraphProgram::DOT);
3226-
#else
3227-
llvm::errs() << "Warning: viewing graph requires assertions" << "\n";
3228-
#endif
32293223
}
32303224

3231-
3232-
void ExprEngine::ViewGraph(ArrayRef<const ExplodedNode*> Nodes) {
3233-
#ifndef NDEBUG
3225+
void ExprEngine::ViewGraph(ArrayRef<const ExplodedNode *> Nodes) {
32343226
std::string Filename = DumpGraph(Nodes);
32353227
llvm::DisplayGraph(Filename, false, llvm::GraphProgram::DOT);
3236-
#else
3237-
llvm::errs() << "Warning: viewing graph requires assertions" << "\n";
3238-
#endif
32393228
}
32403229

32413230
std::string ExprEngine::DumpGraph(bool trim, StringRef Filename) {
3242-
#ifndef NDEBUG
32433231
if (trim) {
32443232
std::vector<const ExplodedNode *> Src;
32453233

@@ -3254,35 +3242,26 @@ std::string ExprEngine::DumpGraph(bool trim, StringRef Filename) {
32543242
Src.push_back(N);
32553243
}
32563244
return DumpGraph(Src, Filename);
3257-
} else {
3258-
return llvm::WriteGraph(&G, "ExprEngine", /*ShortNames=*/false,
3259-
/*Title=*/"Exploded Graph",
3260-
/*Filename=*/std::string(Filename));
32613245
}
3262-
#else
3263-
llvm::errs() << "Warning: dumping graph requires assertions" << "\n";
3264-
return "";
3265-
#endif
3246+
3247+
return llvm::WriteGraph(&G, "ExprEngine", /*ShortNames=*/false,
3248+
/*Title=*/"Exploded Graph",
3249+
/*Filename=*/std::string(Filename));
32663250
}
32673251

3268-
std::string ExprEngine::DumpGraph(ArrayRef<const ExplodedNode*> Nodes,
3252+
std::string ExprEngine::DumpGraph(ArrayRef<const ExplodedNode *> Nodes,
32693253
StringRef Filename) {
3270-
#ifndef NDEBUG
32713254
std::unique_ptr<ExplodedGraph> TrimmedG(G.trim(Nodes));
32723255

32733256
if (!TrimmedG.get()) {
32743257
llvm::errs() << "warning: Trimmed ExplodedGraph is empty.\n";
32753258
return "";
3276-
} else {
3277-
return llvm::WriteGraph(TrimmedG.get(), "TrimmedExprEngine",
3278-
/*ShortNames=*/false,
3279-
/*Title=*/"Trimmed Exploded Graph",
3280-
/*Filename=*/std::string(Filename));
3281-
}
3282-
#else
3283-
llvm::errs() << "Warning: dumping graph requires assertions" << "\n";
3284-
return "";
3285-
#endif
3259+
}
3260+
3261+
return llvm::WriteGraph(TrimmedG.get(), "TrimmedExprEngine",
3262+
/*ShortNames=*/false,
3263+
/*Title=*/"Trimmed Exploded Graph",
3264+
/*Filename=*/std::string(Filename));
32863265
}
32873266

32883267
void *ProgramStateTrait<ReplayWithoutInlining>::GDMIndex() {

clang/test/Analysis/dump_egraph.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
// RUN: -trim-egraph %s
88
// RUN: cat %t.dot | FileCheck %s
99

10-
// REQUIRES: asserts
11-
1210
int getJ(void);
1311

1412
int foo(void) {
@@ -29,21 +27,21 @@ int foo(void) {
2927
// CHECK-SAME: \{ \"kind\": \"Statement\", \"stmt_kind\": \"IntegerLiteral\",
3028
// CHECK-SAME: \"stmt_id\": {{[0-9]*}}, \"pointer\": \"0x{{[0-9a-f]*}}\",
3129
// CHECK-SAME: \"pretty\": \"0\", \"location\": \{
32-
// CHECK-SAME: \"line\": 15, \"column\": 12, \"file\":
30+
// CHECK-SAME: \"line\": 13, \"column\": 12, \"file\":
3331
// CHECK-SAME: \}, \"stmt_point_kind\": \"PreStmtPurgeDeadSymbols\",
3432
// CHECK-SAME: \"tag\": \"ExprEngine : Clean Node\", \"node_id\": 3,
3533
// CHECK-SAME: \"is_sink\": 0, \"has_report\": 0
3634
// CHECK-SAME: \},
3735
// CHECK-SAME: \{ \"kind\": \"Statement\", \"stmt_kind\": \"IntegerLiteral\",
3836
// CHECK-SAME: \"stmt_id\": {{[0-9]*}}, \"pointer\": \"0x{{[0-9a-f]*}}\",
3937
// CHECK-SAME: \"pretty\": \"0\", \"location\": \{
40-
// CHECK-SAME: \"line\": 15, \"column\": 12, \"file\":
38+
// CHECK-SAME: \"line\": 13, \"column\": 12, \"file\":
4139
// CHECK-SAME: \}, \"stmt_point_kind\": \"PostStmt\", \"tag\": null,
4240
// CHECK-SAME: \"node_id\": 4, \"is_sink\": 0, \"has_report\": 0
4341
// CHECK-SAME: \}
4442
// CHECK-SAME: ]
4543

46-
// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 18, \"column\": 10, \"file\": \"{{(.+)}}dump_egraph.c\" \}
44+
// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, \"file\": \"{{(.+)}}dump_egraph.c\" \}
4745

4846
// CHECK: \"pretty\": \"'\\\\x13'\"
4947

clang/test/Analysis/dump_egraph.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-dump-egraph=%t.dot %s
22
// RUN: cat %t.dot | FileCheck %s
3-
// REQUIRES: asserts
43

54
struct S {
65
~S();
@@ -20,7 +19,7 @@ void foo() {
2019

2120
// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", \"location\": null, \"items\": [\l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{ \"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", \"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"&t\"
2221

23-
// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"location\": \{ \"line\": 16, \"column\": 5, \"file\": \"{{.*}}dump_egraph.cpp\" \}, \"items\": [\l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{ \"init_id\": {{[0-9]+}}, \"kind\": \"construct into member variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"&t.s\"
22+
// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"location\": \{ \"line\": 15, \"column\": 5, \"file\": \"{{.*}}dump_egraph.cpp\" \}, \"items\": [\l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{ \"init_id\": {{[0-9]+}}, \"kind\": \"construct into member variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"&t.s\"
2423

2524
// CHECK: \"cluster\": \"t\", \"pointer\": \"{{0x[0-9a-f]+}}\", \"items\": [\l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{ \"kind\": \"Default\", \"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
2625

clang/test/Analysis/exploded-graph-rewriter/dynamic_types.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// RUN: -analyzer-checker=core \
44
// RUN: -analyzer-dump-egraph=%t.dot %s
55
// RUN: %exploded_graph_rewriter %t.dot | FileCheck %s
6-
// REQUIRES: asserts
76

87
struct S {};
98

clang/test/Analysis/exploded-graph-rewriter/escapes.c

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// RUN: -analyzer-checker=core \
44
// RUN: -analyzer-dump-egraph=%t.dot %s
55
// RUN: %exploded_graph_rewriter %t.dot | FileCheck %s
6-
// REQUIRES: asserts
76

87
void escapes(void) {
98
// CHECK: <td align="left"><b>Store: </b> <font color="gray">(0x{{[0-9a-f]*}})</font></td>

clang/test/Analysis/exploded-graph-rewriter/initializers_under_construction.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// RUN: -analyzer-checker=core \
44
// RUN: -analyzer-dump-egraph=%t.dot %s
55
// RUN: %exploded_graph_rewriter %t.dot | FileCheck %s
6-
// REQUIRES: asserts
76

87
struct A {
98
A() {}

clang/test/Analysis/exploded-graph-rewriter/l_name_starts_with_l.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// RUN: -analyzer-checker=core \
55
// RUN: -analyzer-dump-egraph=%t.dot %s
66
// RUN: %exploded_graph_rewriter %t.dot | FileCheck %s
7-
// REQUIRES: asserts
87

98
void test1() {
109
// Here __FILE__ macros produces a string with `\` delimiters on Windows

clang/test/Analysis/exploded-graph-rewriter/macros.c

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ void *foo(void) {
1111
// RUN: -analyzer-checker=core \
1212
// RUN: -analyzer-dump-egraph=%t.dot %s
1313
// RUN: %exploded_graph_rewriter %t.dot | FileCheck %s
14-
// REQUIRES: asserts
1514

1615
// CHECK: macros.c:<b>3</b>:<b>10</b>
1716
// CHECK-SAME: <font color="royalblue1">

clang/test/Analysis/exploded-graph-rewriter/objects_under_construction.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// RUN: -analyzer-checker=core \
55
// RUN: -analyzer-dump-egraph=%t.dot %s
66
// RUN: %exploded_graph_rewriter %t.dot | FileCheck %s
7-
// REQUIRES: asserts
87

98
struct S {
109
S() {}

clang/test/Analysis/exploded-graph-rewriter/win_path_forbidden_chars.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// RUN: -analyzer-checker=core \
44
// RUN: -analyzer-dump-egraph=%t.dot %s
55
// RUN: %exploded_graph_rewriter --verbose %t.dot 2>&1 | FileCheck %s
6-
// REQUIRES: asserts
76
// UNSUPPORTED: !windows
87

98
// Angle brackets shall not be presented in the field `file`,

0 commit comments

Comments
 (0)