NoQ created this revision. NoQ added reviewers: dcoughlin, xazax.hun, a_sidorin, rnkovacs, Szelethus, baloghadamsoftware, Charusso. Herald added subscribers: cfe-commits, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, szepet. Herald added a project: clang. NoQ added a parent revision: D63684: [analyzer] exploded-graph-rewriter: NFC: Extract some code into functions..
Range constraints are now rendered as well. Diff support included. I'm using a cheap solution that treats range constraints as "some sort of key-value map", so it's going to be trivial to add support for other such maps later - such as dynamic type info. F9352100: Screen Shot 2019-06-21 at 8.17.43 PM.png <https://reviews.llvm.org/F9352100> Repository: rC Clang https://reviews.llvm.org/D63685 Files: clang/test/Analysis/exploded-graph-rewriter/constraints.dot clang/test/Analysis/exploded-graph-rewriter/constraints_diff.dot clang/test/Analysis/exploded-graph-rewriter/environment.dot clang/test/Analysis/exploded-graph-rewriter/environment_diff.dot clang/test/Analysis/exploded-graph-rewriter/store.dot clang/test/Analysis/exploded-graph-rewriter/store_diff.dot clang/utils/analyzer/exploded-graph-rewriter.py
Index: clang/utils/analyzer/exploded-graph-rewriter.py =================================================================== --- clang/utils/analyzer/exploded-graph-rewriter.py +++ clang/utils/analyzer/exploded-graph-rewriter.py @@ -25,6 +25,19 @@ return (removed, added) +# Represents any program state trait that is a dictionary of key-value pairs. +class GenericMap(object): + def __init__(self, generic_map): + self.generic_map = generic_map + + def diff(self, prev): + return diff_dicts(self.generic_map, prev.generic_map) + + def is_different(self, prev): + removed, added = self.diff(prev) + return len(removed) != 0 or len(added) != 0 + + # A deserialized source location. class SourceLocation(object): def __init__(self, json_loc): @@ -203,8 +216,10 @@ if json_ps['store'] is not None else None self.environment = Environment(json_ps['environment']) \ if json_ps['environment'] is not None else None + self.constraints = GenericMap(collections.OrderedDict([ + (c['symbol'], c['range']) for c in json_ps['constraints'] + ])) if json_ps['constraints'] is not None else None # TODO: Objects under construction. - # TODO: Constraint ranges. # TODO: Dynamic types of objects. # TODO: Checker messages. @@ -480,11 +495,57 @@ else: self._dump('</td></tr><tr><td align="left">') self.visit_store(s.store) - self._dump('</td></tr><hr />') + self._dump('</td></tr>') + + def visit_generic_map(self, m, prev_m=None): + self._dump('<table border="0">') + + def dump_pair(m, k, is_added=None): + self._dump('<tr><td>%s</td>' + '<td align="left">%s</td>' + '<td align="left">%s</td></tr>' + % (self._diff_plus_minus(is_added), + k, m.generic_map[k])) + + if prev_m is not None: + removed, added = m.diff(prev_m) + for k in removed: + dump_pair(prev_m, k, False) + for k in added: + dump_pair(m, k, True) + else: + for k in m.generic_map: + dump_pair(m, k, None) + + self._dump('</table>') + + def visit_generic_map_in_state(self, selector, s, prev_s=None): + self._dump('<tr><td align="left">' + '<b>Ranges: </b>') + m = getattr(s, selector) + if m is None: + self._dump('<i> Nothing!</i>') + else: + prev_m = None + if prev_s is not None: + prev_m = getattr(prev_s, selector) + 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: + self._dump('</td></tr><tr><td align="left">') + self.visit_generic_map(m) + self._dump('</td></tr>') def visit_state(self, s, prev_s): self.visit_store_in_state(s, prev_s) + self._dump('<hr />') self.visit_environment_in_state(s, prev_s) + self._dump('<hr />') + self.visit_generic_map_in_state('constraints', s, prev_s) def visit_node(self, node): self._dump('%s [shape=record,label=<<table border="0">' Index: clang/test/Analysis/exploded-graph-rewriter/store_diff.dot =================================================================== --- clang/test/Analysis/exploded-graph-rewriter/store_diff.dot +++ clang/test/Analysis/exploded-graph-rewriter/store_diff.dot @@ -11,6 +11,7 @@ "program_points": [], "program_state": { "environment": null, + "constraints": null, "store": [ { "cluster": "x", @@ -52,6 +53,7 @@ "program_points": [], "program_state": { "environment": null, + "constraints": null, "store": [ { "cluster": "x", Index: clang/test/Analysis/exploded-graph-rewriter/store.dot =================================================================== --- clang/test/Analysis/exploded-graph-rewriter/store.dot +++ clang/test/Analysis/exploded-graph-rewriter/store.dot @@ -28,6 +28,7 @@ "program_points": [], "program_state": { "environment": null, + "constraints": null, "store": [ { "cluster": "x", Index: clang/test/Analysis/exploded-graph-rewriter/environment_diff.dot =================================================================== --- clang/test/Analysis/exploded-graph-rewriter/environment_diff.dot +++ clang/test/Analysis/exploded-graph-rewriter/environment_diff.dot @@ -12,6 +12,7 @@ "program_points": [], "program_state": { "store": null, + "constraints": null, "environment": [ { "location_context": "#0 Call", @@ -54,6 +55,7 @@ "program_points": [], "program_state": { "store": null, + "constraints": null, "environment": [ { "location_context": "#0 Call", @@ -90,6 +92,7 @@ "program_points": [], "program_state": { "store": null, + "constraints": null, "environment": [ { "location_context": "#0 Call", Index: clang/test/Analysis/exploded-graph-rewriter/environment.dot =================================================================== --- clang/test/Analysis/exploded-graph-rewriter/environment.dot +++ clang/test/Analysis/exploded-graph-rewriter/environment.dot @@ -33,6 +33,7 @@ "program_points": [], "program_state": { "store": null, + "constraints": null, "environment": [ { "location_context": "#0 Call", Index: clang/test/Analysis/exploded-graph-rewriter/constraints_diff.dot =================================================================== --- /dev/null +++ clang/test/Analysis/exploded-graph-rewriter/constraints_diff.dot @@ -0,0 +1,65 @@ +// 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": { + "store": null, + "environment": null, + "constraints": [ + { "symbol": "reg_$0<x>", "range": "{ [0, 10] }" } + ] + } + } +\l}"]; + +Node0x1 -> Node0x3; + +// CHECK: Node0x3 [ +// CHECK-SAME: <tr> +// CHECK-SAME: <td><font color="red">-</font></td> +// CHECK-SAME: <td align="left">reg_$0<x></td> +// CHECK-SAME: <td align="left">\{ [0, 10] \}</td> +// CHECK-SAME: </tr> +// CHECK-SAME: <tr> +// CHECK-SAME: <td><font color="forestgreen">+</font></td> +// CHECK-SAME: <td align="left">reg_$0<x></td> +// CHECK-SAME: <td align="left">\{ [0, 5] \}</td> +// CHECK-SAME: </tr> +Node0x3 [shape=record,label= + "{ + { "node_id": 3, + "pointer": "0x3", + "state_id": 4, + "program_points": [], + "program_state": { + "store": null, + "environment": null, + "constraints": [ + { "symbol": "reg_$0<x>", "range": "{ [0, 5] }" } + ] + } + } +\l}"]; + +Node0x3 -> Node0x5; + +Node0x5 [shape=record,label= + "{ + { "node_id": 5, + "pointer": "0x5", + "state_id": 6, + "program_points": [], + "program_state": { + "store": null, + "environment": null, + "constraints": null + } + } +\l}"]; Index: clang/test/Analysis/exploded-graph-rewriter/constraints.dot =================================================================== --- /dev/null +++ clang/test/Analysis/exploded-graph-rewriter/constraints.dot @@ -0,0 +1,27 @@ +// RUN: %exploded_graph_rewriter %s | FileCheck %s + +// FIXME: Substitution doesn't seem to work on Windows. +// UNSUPPORTED: system-windows + +// CHECK: <tr><td align="left"><b>Ranges: </b></td></tr> +// CHECK-SAME: <tr><td align="left"><table border="0"> +// CHECK-SAME: <tr> +// CHECK-SAME: <td align="left">reg_$0<x></td> +// CHECK-SAME: <td align="left">\{ [0, 0] \}</td> +// CHECK-SAME: </tr> +// CHECK-SAME: </table></td></tr> +Node0x1 [shape=record,label= + "{ + { "node_id": 1, + "pointer": "0x1", + "state_id": 2, + "program_points": [], + "program_state": { + "store": null, + "environment": null, + "constraints": [ + { "symbol": "reg_$0<x>", "range": "{ [0, 0] }" } + ] + } + } +\l}"];
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits