]> granicus.if.org Git - clang/commitdiff
[analyzer] print() JSONify: Create pointers
authorCsaba Dabis <dabis.csaba98@gmail.com>
Tue, 25 Jun 2019 03:17:55 +0000 (03:17 +0000)
committerCsaba Dabis <dabis.csaba98@gmail.com>
Tue, 25 Jun 2019 03:17:55 +0000 (03:17 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@364271 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/Environment.cpp
lib/StaticAnalyzer/Core/RegionStore.cpp
test/Analysis/exploded-graph-rewriter/environment.dot
test/Analysis/exploded-graph-rewriter/environment_diff.dot
test/Analysis/exploded-graph-rewriter/store.dot
test/Analysis/exploded-graph-rewriter/store_diff.dot
test/Analysis/expr-inspection.c
utils/analyzer/exploded-graph-rewriter.py

index 0ca3f778f1b9c1f2367b91c31c2955807a97e8ce..551c89b04db4b4315bca8fe7dc35c4a6b584ff72 100644 (file)
@@ -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;
 }
index 9bc0e62c27ff38f1557091358ff004bd84fa65fb..a389619f842607c9d68a8d6c61d1b02e112b21f9 100644 (file)
@@ -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;
 }
index e18cc7fc192d481bf18dd5016c117ca77d7226c7..052f35b28fc72f43333136d3001c9e96c3ec3889 100644 (file)
@@ -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}"];
index 33fe07d8789ffdfe93f797478becd230df104331..84f89dd469e4a667a9b740b72f732b5b1d5d6032 100644 (file)
@@ -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}"];
index 22f4eba623cd20cf9213301c9a23d01ac5552111..8f33b513b10e49fe5b20d7cc86745e2084fa9dd1 100644 (file)
@@ -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}"];
index d0a4e19817af9d0867a6e4a184fa7342f98a564b..af92c62163613b5afccb57573eadd00dfab34018 100644 (file)
@@ -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}"];
index 841b30a9b99d7ab8208133f8d6e08ade1d15f44d..5d07b70965f435e6b4665cf38d56c60d3863b478 100644 (file)
@@ -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:   ],
index 668b12110b4c3c9a477737aee3b1fe9e6ea8967f..7714e59656657eec02adfd4aedec9df2c7ec8db3 100755 (executable)
@@ -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]