Skip to content

Commit 0cdd13c

Browse files
author
Csaba Dabis
committed
[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
1 parent c55170c commit 0cdd13c

File tree

8 files changed

+135
-111
lines changed

8 files changed

+135
-111
lines changed

clang/lib/StaticAnalyzer/Core/Environment.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,13 @@ void Environment::printJson(raw_ostream &Out, const ASTContext &Ctx,
204204
const LocationContext *LCtx, const char *NL,
205205
unsigned int Space, bool IsDot) const {
206206
Indent(Out, Space, IsDot) << "\"environment\": ";
207-
++Space;
208207

209208
if (ExprBindings.isEmpty()) {
210209
Out << "null," << NL;
211210
return;
212211
}
213212

213+
++Space;
214214
if (!LCtx) {
215215
// Find the freshest location context.
216216
llvm::SmallPtrSet<const LocationContext *, 16> FoundContexts;
@@ -227,7 +227,8 @@ void Environment::printJson(raw_ostream &Out, const ASTContext &Ctx,
227227

228228
assert(LCtx);
229229

230-
Out << '[' << NL; // Start of Environment.
230+
Out << "{ \"pointer\": \"" << (const void *)LCtx->getStackFrame()
231+
<< "\", \"items\": [" << NL;
231232
PrintingPolicy PP = Ctx.getPrintingPolicy();
232233

233234
LCtx->printJson(Out, NL, Space, IsDot, [&](const LocationContext *LC) {
@@ -280,5 +281,5 @@ void Environment::printJson(raw_ostream &Out, const ASTContext &Ctx,
280281
Out << "null ";
281282
});
282283

283-
Indent(Out, --Space, IsDot) << "]," << NL; // End of Environment.
284+
Indent(Out, --Space, IsDot) << "]}," << NL;
284285
}

clang/lib/StaticAnalyzer/Core/RegionStore.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2640,7 +2640,7 @@ void RegionStoreManager::printJson(raw_ostream &Out, Store S, const char *NL,
26402640
return;
26412641
}
26422642

2643-
Out << '[' << NL;
2644-
Bindings.printJson(Out, NL, ++Space, IsDot);
2645-
Indent(Out, --Space, IsDot) << "]," << NL;
2643+
Out << "{ \"pointer\": \"" << Bindings.asStore() << "\", \"items\": [" << NL;
2644+
Bindings.printJson(Out, NL, Space + 1, IsDot);
2645+
Indent(Out, Space, IsDot) << "]}," << NL;
26462646
}

clang/test/Analysis/exploded-graph-rewriter/environment.dot

+18-15
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,24 @@ Node0x1 [shape=record,label=
3434
"program_state": {
3535
"store": null,
3636
"constraints": null,
37-
"environment": [
38-
{
39-
"location_context": "#0 Call",
40-
"lctx_id": 3,
41-
"calling": "foo",
42-
"call_line": 4,
43-
"items": [
44-
{
45-
"stmt_id": 5,
46-
"pretty": "bar()",
47-
"value": "Unknown"
48-
}
49-
]
50-
}
51-
]
37+
"environment": {
38+
"pointer": "0x2",
39+
"items": [
40+
{
41+
"location_context": "#0 Call",
42+
"lctx_id": 3,
43+
"calling": "foo",
44+
"call_line": 4,
45+
"items": [
46+
{
47+
"stmt_id": 5,
48+
"pretty": "bar()",
49+
"value": "Unknown"
50+
}
51+
]
52+
}
53+
]
54+
}
5255
}
5356
}
5457
\l}"];

clang/test/Analysis/exploded-graph-rewriter/environment_diff.dot

+54-45
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@ Node0x1 [shape=record,label=
1313
"program_state": {
1414
"store": null,
1515
"constraints": null,
16-
"environment": [
17-
{
18-
"location_context": "#0 Call",
19-
"lctx_id": 3,
20-
"calling": "foo",
21-
"call_line": 4,
22-
"items": [
23-
{
24-
"stmt_id": 5,
25-
"pretty": "bar()",
26-
"value": "Unknown"
27-
}
28-
]
29-
}
30-
]
16+
"environment": {
17+
"pointer": "0x2",
18+
"items": [
19+
{
20+
"location_context": "#0 Call",
21+
"lctx_id": 3,
22+
"calling": "foo",
23+
"call_line": 4,
24+
"items": [
25+
{
26+
"stmt_id": 5,
27+
"pretty": "bar()",
28+
"value": "Unknown"
29+
}
30+
]
31+
}
32+
]
33+
}
3134
}
3235
}
3336
\l}"];
@@ -56,21 +59,24 @@ Node0x6 [shape=record,label=
5659
"program_state": {
5760
"store": null,
5861
"constraints": null,
59-
"environment": [
60-
{
61-
"location_context": "#0 Call",
62-
"lctx_id": 3,
63-
"calling": "foo",
64-
"call_line": 4,
65-
"items": [
66-
{
67-
"stmt_id": 9,
68-
"pretty": "baz()",
69-
"value": "Undefined"
70-
}
71-
]
72-
}
73-
]
62+
"environment": {
63+
"pointer": "0x2",
64+
"items": [
65+
{
66+
"location_context": "#0 Call",
67+
"lctx_id": 3,
68+
"calling": "foo",
69+
"call_line": 4,
70+
"items": [
71+
{
72+
"stmt_id": 9,
73+
"pretty": "baz()",
74+
"value": "Undefined"
75+
}
76+
]
77+
}
78+
]
79+
}
7480
}
7581
}
7682
\l}"];
@@ -93,21 +99,24 @@ Node0x9 [shape=record,label=
9399
"program_state": {
94100
"store": null,
95101
"constraints": null,
96-
"environment": [
97-
{
98-
"location_context": "#0 Call",
99-
"lctx_id": 3,
100-
"calling": "foo",
101-
"call_line": 4,
102-
"items": [
103-
{
104-
"stmt_id": 9,
105-
"pretty": "baz()",
106-
"value": "Undefined"
107-
}
108-
]
109-
}
110-
]
102+
"environment": {
103+
"pointer": "0x2",
104+
"items": [
105+
{
106+
"location_context": "#0 Call",
107+
"lctx_id": 3,
108+
"calling": "foo",
109+
"call_line": 4,
110+
"items": [
111+
{
112+
"stmt_id": 9,
113+
"pretty": "baz()",
114+
"value": "Undefined"
115+
}
116+
]
117+
}
118+
]
119+
}
111120
}
112121
}
113122
\l}"];

clang/test/Analysis/exploded-graph-rewriter/store.dot

+16-13
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,22 @@ Node0x1 [shape=record,label=
2929
"program_state": {
3030
"environment": null,
3131
"constraints": null,
32-
"store": [
33-
{
34-
"cluster": "x",
35-
"pointer": "0x3",
36-
"items": [
37-
{
38-
"kind": "Default",
39-
"offset": 0,
40-
"value": "Undefined"
41-
}
42-
]
43-
}
44-
]
32+
"store": {
33+
"pointer": "0x2",
34+
"items": [
35+
{
36+
"cluster": "x",
37+
"pointer": "0x3",
38+
"items": [
39+
{
40+
"kind": "Default",
41+
"offset": 0,
42+
"value": "Undefined"
43+
}
44+
]
45+
}
46+
]
47+
}
4548
}
4649
}
4750
\l}"];

clang/test/Analysis/exploded-graph-rewriter/store_diff.dot

+32-26
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@ Node0x1 [shape=record,label=
1212
"program_state": {
1313
"environment": null,
1414
"constraints": null,
15-
"store": [
16-
{
17-
"cluster": "x",
18-
"pointer": "0x3",
19-
"items": [
20-
{
21-
"kind": "Default",
22-
"offset": 0,
23-
"value": "Undefined"
24-
}
25-
]
26-
}
27-
]
15+
"store": {
16+
"pointer": "0x2",
17+
"items": [
18+
{
19+
"cluster": "x",
20+
"pointer": "0x3",
21+
"items": [
22+
{
23+
"kind": "Default",
24+
"offset": 0,
25+
"value": "Undefined"
26+
}
27+
]
28+
}
29+
]
30+
}
2831
}
2932
}
3033
\l}"];
@@ -54,19 +57,22 @@ Node0x4 [shape=record,label=
5457
"program_state": {
5558
"environment": null,
5659
"constraints": null,
57-
"store": [
58-
{
59-
"cluster": "x",
60-
"pointer": "0x3",
61-
"items": [
62-
{
63-
"kind": "Default",
64-
"offset": 0,
65-
"value": "Unknown"
66-
}
67-
]
68-
}
69-
]
60+
"store": {
61+
"pointer": "0x5",
62+
"items": [
63+
{
64+
"cluster": "x",
65+
"pointer": "0x3",
66+
"items": [
67+
{
68+
"kind": "Default",
69+
"offset": 0,
70+
"value": "Unknown"
71+
}
72+
]
73+
}
74+
]
75+
}
7076
}
7177
}
7278
\l}"];

clang/test/Analysis/expr-inspection.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ void foo(int x) {
2424
}
2525

2626
// CHECK: "program_state": {
27-
// CHECK-NEXT: "store": [
27+
// CHECK-NEXT: "store": { "pointer": "{{0x[0-9a-f]+}}", "items": [
2828
// CHECK-NEXT: { "cluster": "y", "pointer": "{{0x[0-9a-f]+}}", "items": [
2929
// CHECK-NEXT: { "kind": "Direct", "offset": 0, "value": "2 S32b" }
3030
// CHECK-NEXT: ]}
31-
// CHECK-NEXT: ],
32-
// CHECK-NEXT: "environment": [
31+
// CHECK-NEXT: ]},
32+
// CHECK-NEXT: "environment": { "pointer": "{{0x[0-9a-f]+}}", "items": [
3333
// CHECK-NEXT: { "lctx_id": 1, "location_context": "#0 Call", "calling": "foo", "call_line": null, "items": [
3434
// CHECK-NEXT: { "stmt_id": {{[0-9]+}}, "pretty": "clang_analyzer_printState", "value": "&code{clang_analyzer_printState}" }
3535
// CHECK-NEXT: ]}
36-
// CHECK-NEXT: ],
36+
// CHECK-NEXT: ]},
3737
// CHECK-NEXT: "constraints": [
3838
// CHECK-NEXT: { "symbol": "reg_$0<int x>", "range": "{ [-2147483648, 13] }" }
3939
// CHECK-NEXT: ],

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ def is_different(self, prev):
126126
class Environment(object):
127127
def __init__(self, json_e):
128128
super(Environment, self).__init__()
129-
self.frames = [EnvironmentFrame(f) for f in json_e]
129+
self.ptr = json_e['pointer']
130+
self.frames = [EnvironmentFrame(f) for f in json_e['items']]
130131

131132
def diff_frames(self, prev):
132133
# TODO: It's difficult to display a good diff when frame numbers shift.
@@ -190,8 +191,9 @@ def is_different(self, prev):
190191
class Store(object):
191192
def __init__(self, json_s):
192193
super(Store, self).__init__()
194+
self.ptr = json_s['pointer']
193195
self.clusters = collections.OrderedDict(
194-
[(c['pointer'], StoreCluster(c)) for c in json_s])
196+
[(c['pointer'], StoreCluster(c)) for c in json_s['items']])
195197

196198
def diff_clusters(self, prev):
197199
removed = [k for k in prev.clusters if k not in self.clusters]

0 commit comments

Comments
 (0)