r364989 - [analyzer] exploded-graph-rewriter: Implement checker messages.
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 2 18:26:33 PDT 2019
Author: dergachev
Date: Tue Jul 2 18:26:32 2019
New Revision: 364989
URL: http://llvm.org/viewvc/llvm-project?rev=364989&view=rev
Log:
[analyzer] exploded-graph-rewriter: Implement checker messages.
They are displayed as raw lines and diffed via difflib on a per-checker basis.
Differential Revision: https://reviews.llvm.org/D64100
Added:
cfe/trunk/test/Analysis/exploded-graph-rewriter/checker_messages.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/checker_messages_diff.dot
Modified:
cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints_diff.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/store_diff.dot
cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
Added: cfe/trunk/test/Analysis/exploded-graph-rewriter/checker_messages.dot
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/checker_messages.dot?rev=364989&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/checker_messages.dot (added)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/checker_messages.dot Tue Jul 2 18:26:32 2019
@@ -0,0 +1,30 @@
+// RUN: %exploded_graph_rewriter %s | FileCheck %s
+
+// FIXME: Substitution doesn't seem to work on Windows.
+// UNSUPPORTED: system-windows
+
+// CHECK: <b>Checker State: </b>
+// CHECK-SAME: <td align="left"><i>alpha.core.FooChecker</i>:</td>
+// CHECK-SAME: <td align="left">Foo stuff:</td>
+// CHECK-SAME: <td align="left">Foo: Bar</td>
+Node0x1 [shape=record,label=
+ "{
+ { "node_id": 1,
+ "pointer": "0x1",
+ "state_id": 2,
+ "program_points": [],
+ "program_state": {
+ "store": null,
+ "constraints": null,
+ "dynamic_types": null,
+ "constructing_objects": null,
+ "environment": null,
+ "checker_messages": [
+ { "checker": "alpha.core.FooChecker", "messages": [
+ "Foo stuff:",
+ "Foo: Bar"
+ ]}
+ ]
+ }
+ }
+\l}"];
Added: cfe/trunk/test/Analysis/exploded-graph-rewriter/checker_messages_diff.dot
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/checker_messages_diff.dot?rev=364989&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/checker_messages_diff.dot (added)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/checker_messages_diff.dot Tue Jul 2 18:26:32 2019
@@ -0,0 +1,93 @@
+// RUN: %exploded_graph_rewriter -d %s | FileCheck %s
+
+// FIXME: Substitution doesn't seem to work on Windows.
+// UNSUPPORTED: system-windows
+
+Node0x1 [shape=record,label=
+ "{
+ { "node_id": 1,
+ "pointer": "0x1",
+ "state_id": 2,
+ "program_points": [],
+ "program_state": {
+ "environment": null,
+ "store": null,
+ "constraints": null,
+ "dynamic_types": null,
+ "constructing_objects": null,
+ "checker_messages": [
+ { "checker": "FooChecker", "messages": [
+ "Foo: Bar"
+ ]},
+ { "checker": "BarChecker", "messages": [
+ "Bar: Foo"
+ ]}
+ ]
+ }
+ }
+\l}"];
+
+Node0x1 -> Node0x4;
+
+
+// CHECK: Node0x4 [
+// CHECK-SAME: <tr>
+// CHECK-SAME: <td><font color="red">-</font></td>
+// CHECK-SAME: <td align="left"><i>BarChecker</i>:</td>
+// CHECK-SAME: </tr>
+// CHECK-SAME: <tr>
+// CHECK-SAME: <td><font color="red">-</font></td>
+// CHECK-SAME: <td align="left">Bar: Foo</td>
+// CHECK-SAME: </tr>
+// CHECK-SAME: <tr>
+// CHECK-SAME: <td></td>
+// CHECK-SAME: <td align="left"><i>FooChecker</i>:</td>
+// CHECK-SAME: </tr>
+// CHECK-SAME: <tr>
+// CHECK-SAME: <td><font color="forestgreen">+</font></td>
+// CHECK-SAME: <td align="left"> Bar: Foo</td>
+// CHECK-SAME: </tr>
+// CHECK-SAME: <tr>
+// CHECK-SAME: <td><font color="forestgreen">+</font></td>
+// CHECK-SAME: <td align="left"><i>DunnoWhateverSomeOtherChecker</i>:</td>
+// CHECK-SAME: </tr>
+// CHECK-SAME: <tr>
+// CHECK-SAME: <td><font color="forestgreen">+</font></td>
+// CHECK-SAME: <td align="left">Dunno, some other message.</td>
+// CHECK-SAME: </tr>
+Node0x4 [shape=record,label=
+ "{
+ { "node_id": 4,
+ "pointer": "0x4",
+ "state_id": 5,
+ "program_points": [],
+ "program_state": {
+ "environment": null,
+ "store": null,
+ "constraints": null,
+ "dynamic_types": null,
+ "constructing_objects": null,
+ "checker_messages": [
+ { "checker": "FooChecker", "messages": [
+ "Foo: Bar",
+ "Bar: Foo"
+ ]},
+ { "checker": "DunnoWhateverSomeOtherChecker", "messages": [
+ "Dunno, some other message."
+ ]}
+ ]
+ }
+ }
+\l}"];
+
+Node0x4 -> Node0x6;
+
+Node0x6 [shape=record,label=
+ "{
+ { "node_id": 6,
+ "pointer": "0x6",
+ "state_id": 7,
+ "program_points": [],
+ "program_state": null
+ }
+\l}"];
Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints.dot
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints.dot?rev=364989&r1=364988&r2=364989&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints.dot (original)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints.dot Tue Jul 2 18:26:32 2019
@@ -21,6 +21,7 @@ Node0x1 [shape=record,label=
"environment": null,
"dynamic_types": null,
"constructing_objects": null,
+ "checker_messages": null,
"constraints": [
{ "symbol": "reg_$0<x>", "range": "{ [0, 0] }" }
]
Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints_diff.dot
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints_diff.dot?rev=364989&r1=364988&r2=364989&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints_diff.dot (original)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints_diff.dot Tue Jul 2 18:26:32 2019
@@ -14,6 +14,7 @@ Node0x1 [shape=record,label=
"environment": null,
"dynamic_types": null,
"constructing_objects": null,
+ "checker_messages": null,
"constraints": [
{ "symbol": "reg_$0<x>", "range": "{ [0, 10] }" }
]
@@ -45,6 +46,7 @@ Node0x3 [shape=record,label=
"environment": null,
"dynamic_types": null,
"constructing_objects": null,
+ "checker_messages": null,
"constraints": [
{ "symbol": "reg_$0<x>", "range": "{ [0, 5] }" }
]
@@ -65,7 +67,8 @@ Node0x5 [shape=record,label=
"environment": null,
"constraints": null,
"dynamic_types": null,
- "constructing_objects": null
+ "constructing_objects": null,
+ "checker_messages": null
}
}
\l}"];
Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot?rev=364989&r1=364988&r2=364989&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot (original)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot Tue Jul 2 18:26:32 2019
@@ -36,6 +36,7 @@ Node0x1 [shape=record,label=
"constraints": null,
"dynamic_types": null,
"constructing_objects": null,
+ "checker_messages": null,
"environment": {
"pointer": "0x2",
"items": [
Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot?rev=364989&r1=364988&r2=364989&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot (original)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot Tue Jul 2 18:26:32 2019
@@ -15,6 +15,7 @@ Node0x1 [shape=record,label=
"constraints": null,
"dynamic_types": null,
"constructing_objects": null,
+ "checker_messages": null,
"environment": {
"pointer": "0x2",
"items": [
@@ -63,6 +64,7 @@ Node0x6 [shape=record,label=
"constraints": null,
"dynamic_types": null,
"constructing_objects": null,
+ "checker_messages": null,
"environment": {
"pointer": "0x2",
"items": [
@@ -105,6 +107,7 @@ Node0x9 [shape=record,label=
"constraints": null,
"dynamic_types": null,
"constructing_objects": null,
+ "checker_messages": null,
"environment": {
"pointer": "0x2",
"items": [
Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot?rev=364989&r1=364988&r2=364989&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot (original)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot Tue Jul 2 18:26:32 2019
@@ -31,6 +31,7 @@ Node0x1 [shape=record,label=
"constraints": null,
"dynamic_types": null,
"constructing_objects": null,
+ "checker_messages": null,
"store": {
"pointer": "0x2",
"items": [
Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/store_diff.dot
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/store_diff.dot?rev=364989&r1=364988&r2=364989&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/store_diff.dot (original)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/store_diff.dot Tue Jul 2 18:26:32 2019
@@ -14,6 +14,7 @@ Node0x1 [shape=record,label=
"constraints": null,
"dynamic_types": null,
"constructing_objects": null,
+ "checker_messages": null,
"store": {
"pointer": "0x2",
"items": [
@@ -61,6 +62,7 @@ Node0x4 [shape=record,label=
"constraints": null,
"dynamic_types": null,
"constructing_objects": null,
+ "checker_messages": null,
"store": {
"pointer": "0x5",
"items": [
Modified: cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/analyzer/exploded-graph-rewriter.py?rev=364989&r1=364988&r2=364989&view=diff
==============================================================================
--- cfe/trunk/utils/analyzer/exploded-graph-rewriter.py (original)
+++ cfe/trunk/utils/analyzer/exploded-graph-rewriter.py Tue Jul 2 18:26:32 2019
@@ -13,6 +13,7 @@ from __future__ import print_function
import argparse
import collections
+import difflib
import json
import logging
import re
@@ -211,6 +212,41 @@ class Store(object):
return len(removed) != 0 or len(added) != 0 or len(updated) != 0
+# Deserialized messages from a single checker in a single program state.
+# Basically a list of raw strings.
+class CheckerLines(object):
+ def __init__(self, json_lines):
+ super(CheckerLines, self).__init__()
+ self.lines = json_lines
+
+ def diff_lines(self, prev):
+ lines = difflib.ndiff(prev.lines, self.lines)
+ return [l.strip() for l in lines
+ if l.startswith('+') or l.startswith('-')]
+
+ def is_different(self, prev):
+ return len(self.diff_lines(prev)) > 0
+
+
+# Deserialized messages of all checkers, separated by checker.
+class CheckerMessages(object):
+ def __init__(self, json_m):
+ super(CheckerMessages, self).__init__()
+ self.items = collections.OrderedDict(
+ [(m['checker'], CheckerLines(m['messages'])) for m in json_m])
+
+ def diff_messages(self, prev):
+ removed = [k for k in prev.items if k not in self.items]
+ added = [k for k in self.items if k not in prev.items]
+ updated = [k for k in prev.items if k in self.items
+ and prev.items[k].is_different(self.items[k])]
+ return (removed, added, updated)
+
+ def is_different(self, prev):
+ removed, added, updated = self.diff_messages(prev)
+ return len(removed) != 0 or len(added) != 0 or len(updated) != 0
+
+
# A deserialized program state.
class ProgramState(object):
def __init__(self, state_id, json_ps):
@@ -241,7 +277,8 @@ class ProgramState(object):
GenericEnvironment(json_ps['constructing_objects']) \
if json_ps['constructing_objects'] is not None else None
- # TODO: Checker messages.
+ self.checker_messages = CheckerMessages(json_ps['checker_messages']) \
+ if json_ps['checker_messages'] is not None else None
# A deserialized exploded graph node. Has a default constructor because it
@@ -595,16 +632,73 @@ class DotDumpVisitor(object):
if m is None:
self._dump('<i> Nothing!</i>')
else:
- if prev_s is not None:
- if prev_m is not None:
- if m.is_different(prev_m):
- self._dump('</td></tr><tr><td align="left">')
- self.visit_generic_map(m, prev_m)
- else:
- self._dump('<i> No changes!</i>')
- if prev_m is None:
+ if prev_m is not None:
+ if m.is_different(prev_m):
+ self._dump('</td></tr><tr><td align="left">')
+ self.visit_generic_map(m, prev_m)
+ else:
+ self._dump('<i> No changes!</i>')
+ else:
self._dump('</td></tr><tr><td align="left">')
self.visit_generic_map(m)
+
+ self._dump('</td></tr>')
+
+ def visit_checker_messages(self, m, prev_m=None):
+ self._dump('<table border="0">')
+
+ def dump_line(l, is_added=None):
+ self._dump('<tr><td>%s</td>'
+ '<td align="left">%s</td></tr>'
+ % (self._diff_plus_minus(is_added), l))
+
+ def dump_chk(chk, is_added=None):
+ dump_line('<i>%s</i>:' % chk, is_added)
+
+ if prev_m is not None:
+ removed, added, updated = m.diff_messages(prev_m)
+ for chk in removed:
+ dump_chk(chk, False)
+ for l in prev_m.items[chk].lines:
+ dump_line(l, False)
+ for chk in updated:
+ dump_chk(chk)
+ for l in m.items[chk].diff_lines(prev_m.items[chk]):
+ dump_line(l[1:], l.startswith('+'))
+ for chk in added:
+ dump_chk(chk, True)
+ for l in m.items[chk].lines:
+ dump_line(l, True)
+ else:
+ for chk in m.items:
+ dump_chk(chk)
+ for l in m.items[chk].lines:
+ dump_line(l)
+
+ self._dump('</table>')
+
+ def visit_checker_messages_in_state(self, s, prev_s=None):
+ m = s.checker_messages
+ prev_m = prev_s.checker_messages if prev_s is not None else None
+ if m is None and prev_m is None:
+ return
+
+ self._dump('<hr />')
+ self._dump('<tr><td align="left">'
+ '<b>Checker State: </b>')
+ if m is None:
+ self._dump('<i> Nothing!</i>')
+ else:
+ if prev_m is not None:
+ if m.is_different(prev_m):
+ self._dump('</td></tr><tr><td align="left">')
+ self.visit_checker_messages(m, prev_m)
+ else:
+ self._dump('<i> No changes!</i>')
+ else:
+ self._dump('</td></tr><tr><td align="left">')
+ self.visit_checker_messages(m)
+
self._dump('</td></tr>')
def visit_state(self, s, prev_s):
@@ -618,6 +712,7 @@ class DotDumpVisitor(object):
self.visit_environment_in_state('constructing_objects',
'Objects Under Construction',
s, prev_s)
+ self.visit_checker_messages_in_state(s, prev_s)
def visit_node(self, node):
self._dump('%s [shape=record,'
More information about the cfe-commits
mailing list