]> granicus.if.org Git - clang/commitdiff
[analyzer] exploded-graph-rewriter: Fix escaping StringRegions.
authorArtem Dergachev <artem.dergachev@gmail.com>
Wed, 19 Jun 2019 23:33:55 +0000 (23:33 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Wed, 19 Jun 2019 23:33:55 +0000 (23:33 +0000)
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

lib/StaticAnalyzer/Core/RegionStore.cpp
test/Analysis/exploded-graph-rewriter/escapes.c [new file with mode: 0644]
test/Analysis/exploded-graph-rewriter/lit.local.cfg
utils/analyzer/exploded-graph-rewriter.py

index fa9f751c3f74f1dca4ea9b7f337496fce214affa..9bc0e62c27ff38f1557091358ff004bd84fa65fb 100644 (file)
@@ -210,6 +210,7 @@ public:
   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;
@@ -217,8 +218,9 @@ public:
       ++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;
diff --git a/test/Analysis/exploded-graph-rewriter/escapes.c b/test/Analysis/exploded-graph-rewriter/escapes.c
new file mode 100644 (file)
index 0000000..2fd564c
--- /dev/null
@@ -0,0 +1,18 @@
+// 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">&amp;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">&amp;Element\{"foo",0 S64b,char\}</td>
+  const char *const foo = "foo";
+}
index 7bc2e107f6423d2c6657aea20da7c06f85b0d5aa..dfeb0a86c4f3c1357c81ce39201d4c35c0616d5b 100644 (file)
@@ -15,4 +15,4 @@ config.substitutions.append(('%exploded_graph_rewriter',
                                                     config.clang_src_dir,
                                                     'utils', 'analyzer')))))
 
-config.suffixes = ['.dot']
+config.suffixes.add('.dot')
index dbfd086215385e24fbba5c08a4569d88cf28638f..7f83f801aea1ea607f25c6cf72fbef0f0dc32765 100755 (executable)
@@ -199,6 +199,7 @@ class ExplodedGraph(object):
                                         .replace('\\"', '"') \
                                         .replace('\\{', '{') \
                                         .replace('\\}', '}') \
+                                        .replace('\\\\', '\\') \
                                         .replace('\\<', '\\\\<') \
                                         .replace('\\>', '\\\\>') \
                                         .rstrip(',')