]> granicus.if.org Git - clang/commitdiff
[analyzer] Display cast kinds in program point dumps.
authorArtem Dergachev <artem.dergachev@gmail.com>
Thu, 17 Oct 2019 23:10:05 +0000 (23:10 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Thu, 17 Oct 2019 23:10:05 +0000 (23:10 +0000)
Because cast expressions have their own hierarchy, it's extremely useful
to have some information about what kind of casts are we dealing with.

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

lib/Analysis/ProgramPoint.cpp
test/Analysis/exploded-graph-rewriter/program_points.dot
utils/analyzer/exploded-graph-rewriter.py

index 97e90965d007a45ac93c428c655b8e6c880c5191..0783fbed53155453c60796c3c8956976c12b33bb 100644 (file)
@@ -188,7 +188,11 @@ void ProgramPoint::printJson(llvm::raw_ostream &Out, const char *NL) const {
 
     Out << "Statement\", \"stmt_kind\": \"" << S->getStmtClassName()
         << "\", \"stmt_id\": " << S->getID(Context)
-        << ", \"pointer\": \"" << (const void *)S << "\", \"pretty\": ";
+        << ", \"pointer\": \"" << (const void *)S << "\", ";
+    if (const auto *CS = dyn_cast<CastExpr>(S))
+      Out << "\"cast_kind\": \"" << CS->getCastKindName() << "\", ";
+
+    Out << "\"pretty\": ";
 
     S->printJson(Out, nullptr, PP, AddQuotes);
 
index 2f49d7f75ef01fee8f913d4c9292650d47d874df..c27c230ebfb370f84fae799ecc09c098c7c55910 100644 (file)
@@ -116,3 +116,51 @@ Node0x3 [shape=record,label=
       }
     ]}
 \l}"];
+
+// CHECK-NEXT: <b>Program point:</b>
+// CHECK-SAME: <table border="0" align="left" width="0">
+// CHECK-SAME:   <tr>
+// CHECK-SAME:     <td align="left" width="0">
+// CHECK-SAME:       main.cpp:<b>8</b>:<b>9</b>:
+// CHECK-SAME:     </td>
+// CHECK-SAME:     <td align="left" width="0">
+// CHECK-SAME:       <font color="cyan4">
+// CHECK-SAME:         ImplicitCastExpr (LValueToRValue)
+// CHECK-SAME:       </font>
+// CHECK-SAME:     </td>
+// CHECK-SAME:     <td align="left"><i>S5</i></td>
+// CHECK-SAME:     <td align="left">
+// CHECK-SAME:       <font color="cyan3">PreStmt</font>
+// CHECK-SAME:     </td>
+// CHECK-SAME:     <td align="left">y</td>
+// CHECK-SAME:   </tr>
+// CHECK-SAME:   <tr>
+// CHECK-SAME:     <td width="0">
+// CHECK-SAME:     </td>
+// CHECK-SAME:     <td colspan="3" align="left">
+// CHECK-SAME:       <b>Tag: </b>
+// CHECK-SAME:       <font color="crimson">ExprEngine : Clean Node</font>
+// CHECK-SAME:     </td>
+// CHECK-SAME:   </tr>
+// CHECK-SAME: </table>
+Node0x4 [shape=record,label=
+ "{
+    { "node_id": 4, "pointer": "0x4", "has_report": false, "is_sink": false,
+      "program_state": null, "program_points": [
+      {
+        "kind": "Statement",
+        "stmt_kind": "ImplicitCastExpr",
+        "cast_kind": "LValueToRValue",
+        "stmt_point_kind": "PreStmt",
+        "stmt_id": 5,
+        "pointer": "0x6",
+        "pretty": "y",
+        "location": {
+          "file": "main.cpp",
+          "line": 8,
+          "column": 9
+        },
+        "tag": "ExprEngine : Clean Node"
+      }
+    ]}
+\l}"];
index 05b01b3f9502cc9bf21751901200e6d70d6cd673..77da7392e36055351fc9633767622588fb9567a1 100755 (executable)
@@ -73,6 +73,8 @@ class ProgramPoint(object):
         elif self.kind == 'Statement':
             logging.debug(json_pp)
             self.stmt_kind = json_pp['stmt_kind']
+            self.cast_kind = json_pp['cast_kind'] \
+                if 'cast_kind' in json_pp else None
             self.stmt_point_kind = json_pp['stmt_point_kind']
             self.stmt_id = json_pp['stmt_id']
             self.pointer = json_pp['pointer']
@@ -497,7 +499,9 @@ class DotDumpVisitor(object):
                        '<td align="left"><i>S%s</i></td>'
                        '<td align="left"><font color="%s">%s</font></td>'
                        '<td align="left">%s</td></tr>'
-                       % (self._make_sloc(p.loc), color, p.stmt_kind,
+                       % (self._make_sloc(p.loc), color,
+                          '%s (%s)' % (p.stmt_kind, p.cast_kind)
+                          if p.cast_kind is not None else p.stmt_kind,
                           p.stmt_id, stmt_color, p.stmt_point_kind,
                           self._short_pretty(p.pretty)
                           if not skip_pretty else ''))