From: Artem Dergachev Date: Thu, 17 Oct 2019 23:10:05 +0000 (+0000) Subject: [analyzer] Display cast kinds in program point dumps. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=40a1cfa0b13160d82f688daa7fbab9f249679617;p=clang [analyzer] Display cast kinds in program point dumps. 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 --- diff --git a/lib/Analysis/ProgramPoint.cpp b/lib/Analysis/ProgramPoint.cpp index 97e90965d0..0783fbed53 100644 --- a/lib/Analysis/ProgramPoint.cpp +++ b/lib/Analysis/ProgramPoint.cpp @@ -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(S)) + Out << "\"cast_kind\": \"" << CS->getCastKindName() << "\", "; + + Out << "\"pretty\": "; S->printJson(Out, nullptr, PP, AddQuotes); diff --git a/test/Analysis/exploded-graph-rewriter/program_points.dot b/test/Analysis/exploded-graph-rewriter/program_points.dot index 2f49d7f75e..c27c230ebf 100644 --- a/test/Analysis/exploded-graph-rewriter/program_points.dot +++ b/test/Analysis/exploded-graph-rewriter/program_points.dot @@ -116,3 +116,51 @@ Node0x3 [shape=record,label= } ]} \l}"]; + +// CHECK-NEXT: Program point: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME:
+// CHECK-SAME: main.cpp:8:9: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: ImplicitCastExpr (LValueToRValue) +// CHECK-SAME: +// CHECK-SAME: S5 +// CHECK-SAME: PreStmt +// CHECK-SAME: y
+// CHECK-SAME: +// CHECK-SAME: Tag: +// CHECK-SAME: ExprEngine : Clean Node +// CHECK-SAME:
+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}"]; diff --git a/utils/analyzer/exploded-graph-rewriter.py b/utils/analyzer/exploded-graph-rewriter.py index 05b01b3f95..77da7392e3 100755 --- a/utils/analyzer/exploded-graph-rewriter.py +++ b/utils/analyzer/exploded-graph-rewriter.py @@ -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): 'S%s' '%s' '%s' - % (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 ''))