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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363897
91177308-0d34-0410-b5e6-
96231b3b80d8
void printJson(raw_ostream &Out, const char *NL = "\n",
unsigned int Space = 0, bool IsDot = false) const {
for (iterator I = begin(); I != end(); ++I) {
+ // TODO: We might need a .printJson for I.getKey() as well.
Indent(Out, Space, IsDot)
<< "{ \"cluster\": \"" << I.getKey() << "\", \"pointer\": \""
<< (const void *)I.getKey() << "\", \"items\": [" << NL;
++Space;
const ClusterBindings &CB = I.getData();
for (ClusterBindings::iterator CI = CB.begin(); CI != CB.end(); ++CI) {
- Indent(Out, Space, IsDot) << "{ " << CI.getKey() << ", \"value\": \""
- << CI.getData() << "\" }";
+ Indent(Out, Space, IsDot) << "{ " << CI.getKey() << ", \"value\": ";
+ CI.getData().printJson(Out, /*AddQuotes=*/true);
+ Out << " }";
if (std::next(CI) != CB.end())
Out << ',';
Out << NL;
--- /dev/null
+// FIXME: Figure out how to use %clang_analyze_cc1 with our lit.local.cfg.
+// RUN: %clang_cc1 -analyze -triple x86_64-unknown-linux-gnu \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-dump-egraph=%t.dot %s
+// RUN: %exploded_graph_rewriter %t.dot | FileCheck %s
+
+// FIXME: Substitution doesn't seem to work on Windows.
+// UNSUPPORTED: system-windows
+
+void string_region_escapes() {
+ // CHECK: <td align="left"><b>Store: </b></td>
+ // CHECK-SAME: <td align="left">foo</td><td align="left">0</td>
+ // CHECK-SAME: <td align="left">&Element\{"foo",0 S64b,char\}</td>
+ // CHECK: <td align="left"><b>Environment: </b></td>
+ // CHECK-SAME: <td align="left">"foo"</td>
+ // CHECK-SAME: <td align="left">&Element\{"foo",0 S64b,char\}</td>
+ const char *const foo = "foo";
+}
config.clang_src_dir,
'utils', 'analyzer')))))
-config.suffixes = ['.dot']
+config.suffixes.add('.dot')
.replace('\\"', '"') \
.replace('\\{', '{') \
.replace('\\}', '}') \
+ .replace('\\\\', '\\') \
.replace('\\<', '\\\\<') \
.replace('\\>', '\\\\>') \
.rstrip(',')