summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCsaba Dabis <dabis.csaba98@gmail.com>2019-06-25 03:17:55 +0000
committerCsaba Dabis <dabis.csaba98@gmail.com>2019-06-25 03:17:55 +0000
commit0cdd13c05a16c90aa4dde56e1e46ca7e0a7261d6 (patch)
tree816823d2e1591fc2e58f4ff6ee573cc14f4d08ff
parentc55170c0310961b64a7fe89824114ebb78315c72 (diff)
downloadbcm5719-llvm-0cdd13c05a16c90aa4dde56e1e46ca7e0a7261d6.tar.gz
bcm5719-llvm-0cdd13c05a16c90aa4dde56e1e46ca7e0a7261d6.zip
[analyzer] print() JSONify: Create pointers
Summary: - Reviewers: NoQ Reviewed By: NoQ Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63726 llvm-svn: 364271
-rw-r--r--clang/lib/StaticAnalyzer/Core/Environment.cpp7
-rw-r--r--clang/lib/StaticAnalyzer/Core/RegionStore.cpp6
-rw-r--r--clang/test/Analysis/exploded-graph-rewriter/environment.dot33
-rw-r--r--clang/test/Analysis/exploded-graph-rewriter/environment_diff.dot99
-rw-r--r--clang/test/Analysis/exploded-graph-rewriter/store.dot29
-rw-r--r--clang/test/Analysis/exploded-graph-rewriter/store_diff.dot58
-rw-r--r--clang/test/Analysis/expr-inspection.c8
-rwxr-xr-xclang/utils/analyzer/exploded-graph-rewriter.py6
8 files changed, 135 insertions, 111 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/Environment.cpp b/clang/lib/StaticAnalyzer/Core/Environment.cpp
index 0ca3f778f1b..551c89b04db 100644
--- a/clang/lib/StaticAnalyzer/Core/Environment.cpp
+++ b/clang/lib/StaticAnalyzer/Core/Environment.cpp
@@ -204,13 +204,13 @@ void Environment::printJson(raw_ostream &Out, const ASTContext &Ctx,
const LocationContext *LCtx, const char *NL,
unsigned int Space, bool IsDot) const {
Indent(Out, Space, IsDot) << "\"environment\": ";
- ++Space;
if (ExprBindings.isEmpty()) {
Out << "null," << NL;
return;
}
+ ++Space;
if (!LCtx) {
// Find the freshest location context.
llvm::SmallPtrSet<const LocationContext *, 16> FoundContexts;
@@ -227,7 +227,8 @@ void Environment::printJson(raw_ostream &Out, const ASTContext &Ctx,
assert(LCtx);
- Out << '[' << NL; // Start of Environment.
+ Out << "{ \"pointer\": \"" << (const void *)LCtx->getStackFrame()
+ << "\", \"items\": [" << NL;
PrintingPolicy PP = Ctx.getPrintingPolicy();
LCtx->printJson(Out, NL, Space, IsDot, [&](const LocationContext *LC) {
@@ -280,5 +281,5 @@ void Environment::printJson(raw_ostream &Out, const ASTContext &Ctx,
Out << "null ";
});
- Indent(Out, --Space, IsDot) << "]," << NL; // End of Environment.
+ Indent(Out, --Space, IsDot) << "]}," << NL;
}
diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index 9bc0e62c27f..a389619f842 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2640,7 +2640,7 @@ void RegionStoreManager::printJson(raw_ostream &Out, Store S, const char *NL,
return;
}
- Out << '[' << NL;
- Bindings.printJson(Out, NL, ++Space, IsDot);
- Indent(Out, --Space, IsDot) << "]," << NL;
+ Out << "{ \"pointer\": \"" << Bindings.asStore() << "\", \"items\": [" << NL;
+ Bindings.printJson(Out, NL, Space + 1, IsDot);
+ Indent(Out, Space, IsDot) << "]}," << NL;
}
diff --git a/clang/test/Analysis/exploded-graph-rewriter/environment.dot b/clang/test/Analysis/exploded-graph-rewriter/environment.dot
index e18cc7fc192..052f35b28fc 100644
--- a/clang/test/Analysis/exploded-graph-rewriter/environment.dot
+++ b/clang/test/Analysis/exploded-graph-rewriter/environment.dot
@@ -34,21 +34,24 @@ Node0x1 [shape=record,label=
"program_state": {
"store": null,
"constraints": null,
- "environment": [
- {
- "location_context": "#0 Call",
- "lctx_id": 3,
- "calling": "foo",
- "call_line": 4,
- "items": [
- {
- "stmt_id": 5,
- "pretty": "bar()",
- "value": "Unknown"
- }
- ]
- }
- ]
+ "environment": {
+ "pointer": "0x2",
+ "items": [
+ {
+ "location_context": "#0 Call",
+ "lctx_id": 3,
+ "calling": "foo",
+ "call_line": 4,
+ "items": [
+ {
+ "stmt_id": 5,
+ "pretty": "bar()",
+ "value": "Unknown"
+ }
+ ]
+ }
+ ]
+ }
}
}
\l}"];
diff --git a/clang/test/Analysis/exploded-graph-rewriter/environment_diff.dot b/clang/test/Analysis/exploded-graph-rewriter/environment_diff.dot
index 33fe07d8789..84f89dd469e 100644
--- a/clang/test/Analysis/exploded-graph-rewriter/environment_diff.dot
+++ b/clang/test/Analysis/exploded-graph-rewriter/environment_diff.dot
@@ -13,21 +13,24 @@ Node0x1 [shape=record,label=
"program_state": {
"store": null,
"constraints": null,
- "environment": [
- {
- "location_context": "#0 Call",
- "lctx_id": 3,
- "calling": "foo",
- "call_line": 4,
- "items": [
- {
- "stmt_id": 5,
- "pretty": "bar()",
- "value": "Unknown"
- }
- ]
- }
- ]
+ "environment": {
+ "pointer": "0x2",
+ "items": [
+ {
+ "location_context": "#0 Call",
+ "lctx_id": 3,
+ "calling": "foo",
+ "call_line": 4,
+ "items": [
+ {
+ "stmt_id": 5,
+ "pretty": "bar()",
+ "value": "Unknown"
+ }
+ ]
+ }
+ ]
+ }
}
}
\l}"];
@@ -56,21 +59,24 @@ Node0x6 [shape=record,label=
"program_state": {
"store": null,
"constraints": null,
- "environment": [
- {
- "location_context": "#0 Call",
- "lctx_id": 3,
- "calling": "foo",
- "call_line": 4,
- "items": [
- {
- "stmt_id": 9,
- "pretty": "baz()",
- "value": "Undefined"
- }
- ]
- }
- ]
+ "environment": {
+ "pointer": "0x2",
+ "items": [
+ {
+ "location_context": "#0 Call",
+ "lctx_id": 3,
+ "calling": "foo",
+ "call_line": 4,
+ "items": [
+ {
+ "stmt_id": 9,
+ "pretty": "baz()",
+ "value": "Undefined"
+ }
+ ]
+ }
+ ]
+ }
}
}
\l}"];
@@ -93,21 +99,24 @@ Node0x9 [shape=record,label=
"program_state": {
"store": null,
"constraints": null,
- "environment": [
- {
- "location_context": "#0 Call",
- "lctx_id": 3,
- "calling": "foo",
- "call_line": 4,
- "items": [
- {
- "stmt_id": 9,
- "pretty": "baz()",
- "value": "Undefined"
- }
- ]
- }
- ]
+ "environment": {
+ "pointer": "0x2",
+ "items": [
+ {
+ "location_context": "#0 Call",
+ "lctx_id": 3,
+ "calling": "foo",
+ "call_line": 4,
+ "items": [
+ {
+ "stmt_id": 9,
+ "pretty": "baz()",
+ "value": "Undefined"
+ }
+ ]
+ }
+ ]
+ }
}
}
\l}"];
diff --git a/clang/test/Analysis/exploded-graph-rewriter/store.dot b/clang/test/Analysis/exploded-graph-rewriter/store.dot
index 22f4eba623c..8f33b513b10 100644
--- a/clang/test/Analysis/exploded-graph-rewriter/store.dot
+++ b/clang/test/Analysis/exploded-graph-rewriter/store.dot
@@ -29,19 +29,22 @@ Node0x1 [shape=record,label=
"program_state": {
"environment": null,
"constraints": null,
- "store": [
- {
- "cluster": "x",
- "pointer": "0x3",
- "items": [
- {
- "kind": "Default",
- "offset": 0,
- "value": "Undefined"
- }
- ]
- }
- ]
+ "store": {
+ "pointer": "0x2",
+ "items": [
+ {
+ "cluster": "x",
+ "pointer": "0x3",
+ "items": [
+ {
+ "kind": "Default",
+ "offset": 0,
+ "value": "Undefined"
+ }
+ ]
+ }
+ ]
+ }
}
}
\l}"];
diff --git a/clang/test/Analysis/exploded-graph-rewriter/store_diff.dot b/clang/test/Analysis/exploded-graph-rewriter/store_diff.dot
index d0a4e19817a..af92c621636 100644
--- a/clang/test/Analysis/exploded-graph-rewriter/store_diff.dot
+++ b/clang/test/Analysis/exploded-graph-rewriter/store_diff.dot
@@ -12,19 +12,22 @@ Node0x1 [shape=record,label=
"program_state": {
"environment": null,
"constraints": null,
- "store": [
- {
- "cluster": "x",
- "pointer": "0x3",
- "items": [
- {
- "kind": "Default",
- "offset": 0,
- "value": "Undefined"
- }
- ]
- }
- ]
+ "store": {
+ "pointer": "0x2",
+ "items": [
+ {
+ "cluster": "x",
+ "pointer": "0x3",
+ "items": [
+ {
+ "kind": "Default",
+ "offset": 0,
+ "value": "Undefined"
+ }
+ ]
+ }
+ ]
+ }
}
}
\l}"];
@@ -54,19 +57,22 @@ Node0x4 [shape=record,label=
"program_state": {
"environment": null,
"constraints": null,
- "store": [
- {
- "cluster": "x",
- "pointer": "0x3",
- "items": [
- {
- "kind": "Default",
- "offset": 0,
- "value": "Unknown"
- }
- ]
- }
- ]
+ "store": {
+ "pointer": "0x5",
+ "items": [
+ {
+ "cluster": "x",
+ "pointer": "0x3",
+ "items": [
+ {
+ "kind": "Default",
+ "offset": 0,
+ "value": "Unknown"
+ }
+ ]
+ }
+ ]
+ }
}
}
\l}"];
diff --git a/clang/test/Analysis/expr-inspection.c b/clang/test/Analysis/expr-inspection.c
index 841b30a9b99..5d07b70965f 100644
--- a/clang/test/Analysis/expr-inspection.c
+++ b/clang/test/Analysis/expr-inspection.c
@@ -24,16 +24,16 @@ void foo(int x) {
}
// CHECK: "program_state": {
-// CHECK-NEXT: "store": [
+// CHECK-NEXT: "store": { "pointer": "{{0x[0-9a-f]+}}", "items": [
// CHECK-NEXT: { "cluster": "y", "pointer": "{{0x[0-9a-f]+}}", "items": [
// CHECK-NEXT: { "kind": "Direct", "offset": 0, "value": "2 S32b" }
// CHECK-NEXT: ]}
-// CHECK-NEXT: ],
-// CHECK-NEXT: "environment": [
+// CHECK-NEXT: ]},
+// CHECK-NEXT: "environment": { "pointer": "{{0x[0-9a-f]+}}", "items": [
// CHECK-NEXT: { "lctx_id": 1, "location_context": "#0 Call", "calling": "foo", "call_line": null, "items": [
// CHECK-NEXT: { "stmt_id": {{[0-9]+}}, "pretty": "clang_analyzer_printState", "value": "&code{clang_analyzer_printState}" }
// CHECK-NEXT: ]}
-// CHECK-NEXT: ],
+// CHECK-NEXT: ]},
// CHECK-NEXT: "constraints": [
// CHECK-NEXT: { "symbol": "reg_$0<int x>", "range": "{ [-2147483648, 13] }" }
// CHECK-NEXT: ],
diff --git a/clang/utils/analyzer/exploded-graph-rewriter.py b/clang/utils/analyzer/exploded-graph-rewriter.py
index 668b12110b4..7714e596566 100755
--- a/clang/utils/analyzer/exploded-graph-rewriter.py
+++ b/clang/utils/analyzer/exploded-graph-rewriter.py
@@ -126,7 +126,8 @@ class EnvironmentFrame(object):
class Environment(object):
def __init__(self, json_e):
super(Environment, self).__init__()
- self.frames = [EnvironmentFrame(f) for f in json_e]
+ self.ptr = json_e['pointer']
+ self.frames = [EnvironmentFrame(f) for f in json_e['items']]
def diff_frames(self, prev):
# TODO: It's difficult to display a good diff when frame numbers shift.
@@ -190,8 +191,9 @@ class StoreCluster(object):
class Store(object):
def __init__(self, json_s):
super(Store, self).__init__()
+ self.ptr = json_s['pointer']
self.clusters = collections.OrderedDict(
- [(c['pointer'], StoreCluster(c)) for c in json_s])
+ [(c['pointer'], StoreCluster(c)) for c in json_s['items']])
def diff_clusters(self, prev):
removed = [k for k in prev.clusters if k not in self.clusters]
OpenPOWER on IntegriCloud