Skip to content

Commit b50d167

Browse files
committed
[analyzer] exploded-graph-rewriter: Fix escaping StringRegions.
Quotes around StringRegions are now escaped and unescaped correctly, producing valid JSON. Additionally, add a forgotten escape for Store values. Differential Revision: https://reviews.llvm.org/D63519 llvm-svn: 363897
1 parent 064c8c6 commit b50d167

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

clang/lib/StaticAnalyzer/Core/RegionStore.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,17 @@ class RegionBindingsRef : public llvm::ImmutableMapRef<const MemRegion *,
210210
void printJson(raw_ostream &Out, const char *NL = "\n",
211211
unsigned int Space = 0, bool IsDot = false) const {
212212
for (iterator I = begin(); I != end(); ++I) {
213+
// TODO: We might need a .printJson for I.getKey() as well.
213214
Indent(Out, Space, IsDot)
214215
<< "{ \"cluster\": \"" << I.getKey() << "\", \"pointer\": \""
215216
<< (const void *)I.getKey() << "\", \"items\": [" << NL;
216217

217218
++Space;
218219
const ClusterBindings &CB = I.getData();
219220
for (ClusterBindings::iterator CI = CB.begin(); CI != CB.end(); ++CI) {
220-
Indent(Out, Space, IsDot) << "{ " << CI.getKey() << ", \"value\": \""
221-
<< CI.getData() << "\" }";
221+
Indent(Out, Space, IsDot) << "{ " << CI.getKey() << ", \"value\": ";
222+
CI.getData().printJson(Out, /*AddQuotes=*/true);
223+
Out << " }";
222224
if (std::next(CI) != CB.end())
223225
Out << ',';
224226
Out << NL;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// FIXME: Figure out how to use %clang_analyze_cc1 with our lit.local.cfg.
2+
// RUN: %clang_cc1 -analyze -triple x86_64-unknown-linux-gnu \
3+
// RUN: -analyzer-checker=core \
4+
// RUN: -analyzer-dump-egraph=%t.dot %s
5+
// RUN: %exploded_graph_rewriter %t.dot | FileCheck %s
6+
7+
// FIXME: Substitution doesn't seem to work on Windows.
8+
// UNSUPPORTED: system-windows
9+
10+
void string_region_escapes() {
11+
// CHECK: <td align="left"><b>Store: </b></td>
12+
// CHECK-SAME: <td align="left">foo</td><td align="left">0</td>
13+
// CHECK-SAME: <td align="left">&amp;Element\{"foo",0 S64b,char\}</td>
14+
// CHECK: <td align="left"><b>Environment: </b></td>
15+
// CHECK-SAME: <td align="left">"foo"</td>
16+
// CHECK-SAME: <td align="left">&amp;Element\{"foo",0 S64b,char\}</td>
17+
const char *const foo = "foo";
18+
}

clang/test/Analysis/exploded-graph-rewriter/lit.local.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ config.substitutions.append(('%exploded_graph_rewriter',
1515
config.clang_src_dir,
1616
'utils', 'analyzer')))))
1717

18-
config.suffixes = ['.dot']
18+
config.suffixes.add('.dot')

clang/utils/analyzer/exploded-graph-rewriter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def add_raw_line(self, raw_line):
199199
.replace('\\"', '"') \
200200
.replace('\\{', '{') \
201201
.replace('\\}', '}') \
202+
.replace('\\\\', '\\') \
202203
.replace('\\<', '\\\\<') \
203204
.replace('\\>', '\\\\>') \
204205
.rstrip(',')

0 commit comments

Comments
 (0)