Skip to content

Commit 02f91dd

Browse files
committedJul 1, 2019
[analyzer] exploded-graph-rewriter: Add support for dynamic types.
Slightly cleanup emission of horizontal lines and unhardcode the title for generic maps. Differential Revision: https://reviews.llvm.org/D64041 llvm-svn: 364865
1 parent 5a72338 commit 02f91dd

File tree

7 files changed

+37
-18
lines changed

7 files changed

+37
-18
lines changed
 

‎clang/test/Analysis/exploded-graph-rewriter/constraints.dot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Node0x1 [shape=record,label=
1919
"program_state": {
2020
"store": null,
2121
"environment": null,
22+
"dynamic_types": null,
2223
"constraints": [
2324
{ "symbol": "reg_$0<x>", "range": "{ [0, 0] }" }
2425
]

‎clang/test/Analysis/exploded-graph-rewriter/constraints_diff.dot

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Node0x1 [shape=record,label=
1212
"program_state": {
1313
"store": null,
1414
"environment": null,
15+
"dynamic_types": null,
1516
"constraints": [
1617
{ "symbol": "reg_$0<x>", "range": "{ [0, 10] }" }
1718
]
@@ -41,6 +42,7 @@ Node0x3 [shape=record,label=
4142
"program_state": {
4243
"store": null,
4344
"environment": null,
45+
"dynamic_types": null,
4446
"constraints": [
4547
{ "symbol": "reg_$0<x>", "range": "{ [0, 5] }" }
4648
]
@@ -59,7 +61,8 @@ Node0x5 [shape=record,label=
5961
"program_state": {
6062
"store": null,
6163
"environment": null,
62-
"constraints": null
64+
"constraints": null,
65+
"dynamic_types": null
6366
}
6467
}
6568
\l}"];

‎clang/test/Analysis/exploded-graph-rewriter/environment.dot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Node0x1 [shape=record,label=
3434
"program_state": {
3535
"store": null,
3636
"constraints": null,
37+
"dynamic_types": null,
3738
"environment": {
3839
"pointer": "0x2",
3940
"items": [

‎clang/test/Analysis/exploded-graph-rewriter/environment_diff.dot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Node0x1 [shape=record,label=
1313
"program_state": {
1414
"store": null,
1515
"constraints": null,
16+
"dynamic_types": null,
1617
"environment": {
1718
"pointer": "0x2",
1819
"items": [
@@ -59,6 +60,7 @@ Node0x6 [shape=record,label=
5960
"program_state": {
6061
"store": null,
6162
"constraints": null,
63+
"dynamic_types": null,
6264
"environment": {
6365
"pointer": "0x2",
6466
"items": [
@@ -99,6 +101,7 @@ Node0x9 [shape=record,label=
99101
"program_state": {
100102
"store": null,
101103
"constraints": null,
104+
"dynamic_types": null,
102105
"environment": {
103106
"pointer": "0x2",
104107
"items": [

‎clang/test/Analysis/exploded-graph-rewriter/store.dot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Node0x1 [shape=record,label=
2929
"program_state": {
3030
"environment": null,
3131
"constraints": null,
32+
"dynamic_types": null,
3233
"store": {
3334
"pointer": "0x2",
3435
"items": [

‎clang/test/Analysis/exploded-graph-rewriter/store_diff.dot

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Node0x1 [shape=record,label=
1212
"program_state": {
1313
"environment": null,
1414
"constraints": null,
15+
"dynamic_types": null,
1516
"store": {
1617
"pointer": "0x2",
1718
"items": [
@@ -57,6 +58,7 @@ Node0x4 [shape=record,label=
5758
"program_state": {
5859
"environment": null,
5960
"constraints": null,
61+
"dynamic_types": null,
6062
"store": {
6163
"pointer": "0x5",
6264
"items": [

‎clang/utils/analyzer/exploded-graph-rewriter.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def diff_dicts(curr, prev):
2727

2828
# Represents any program state trait that is a dictionary of key-value pairs.
2929
class GenericMap(object):
30-
def __init__(self, generic_map):
31-
self.generic_map = generic_map
30+
def __init__(self, items):
31+
self.generic_map = collections.OrderedDict(items)
3232

3333
def diff(self, prev):
3434
return diff_dicts(self.generic_map, prev.generic_map)
@@ -218,11 +218,17 @@ def __init__(self, state_id, json_ps):
218218
if json_ps['store'] is not None else None
219219
self.environment = Environment(json_ps['environment']) \
220220
if json_ps['environment'] is not None else None
221-
self.constraints = GenericMap(collections.OrderedDict([
221+
self.constraints = GenericMap([
222222
(c['symbol'], c['range']) for c in json_ps['constraints']
223-
])) if json_ps['constraints'] is not None else None
223+
]) if json_ps['constraints'] is not None else None
224+
self.dynamic_types = GenericMap([
225+
(t['region'], '%s%s' % (t['dyn_type'],
226+
' (or a sub-class)'
227+
if t['sub_classable'] else ''))
228+
for t in json_ps['dynamic_types']]) \
229+
if json_ps['dynamic_types'] is not None else None
230+
224231
# TODO: Objects under construction.
225-
# TODO: Dynamic types of objects.
226232
# TODO: Checker messages.
227233

228234

@@ -435,8 +441,7 @@ def dump_binding(f, b, is_added=None):
435441
self._dump('</table>')
436442

437443
def visit_environment_in_state(self, s, prev_s=None):
438-
self._dump('<tr><td align="left">'
439-
'<b>Environment: </b>')
444+
self._dump('<hr /><tr><td align="left"><b>Environment: </b>')
440445
if s.environment is None:
441446
self._dump('<i> Nothing!</i>')
442447
else:
@@ -491,7 +496,7 @@ def dump_binding(s, c, b, is_added=None):
491496
self._dump('</table>')
492497

493498
def visit_store_in_state(self, s, prev_s=None):
494-
self._dump('<tr><td align="left"><b>Store: </b>')
499+
self._dump('<hr /><tr><td align="left"><b>Store: </b>')
495500
if s.store is None:
496501
self._dump('<i> Nothing!</i>')
497502
else:
@@ -528,16 +533,19 @@ def dump_pair(m, k, is_added=None):
528533

529534
self._dump('</table>')
530535

531-
def visit_generic_map_in_state(self, selector, s, prev_s=None):
532-
self._dump('<tr><td align="left">'
533-
'<b>Ranges: </b>')
536+
def visit_generic_map_in_state(self, selector, title, s, prev_s=None):
534537
m = getattr(s, selector)
538+
prev_m = getattr(prev_s, selector) if prev_s is not None else None
539+
if m is None and prev_m is None:
540+
return
541+
542+
self._dump('<hr />')
543+
self._dump('<tr><td align="left">'
544+
'<b>%s: </b>' % title)
535545
if m is None:
536546
self._dump('<i> Nothing!</i>')
537547
else:
538-
prev_m = None
539548
if prev_s is not None:
540-
prev_m = getattr(prev_s, selector)
541549
if prev_m is not None:
542550
if m.is_different(prev_m):
543551
self._dump('</td></tr><tr><td align="left">')
@@ -551,10 +559,11 @@ def visit_generic_map_in_state(self, selector, s, prev_s=None):
551559

552560
def visit_state(self, s, prev_s):
553561
self.visit_store_in_state(s, prev_s)
554-
self._dump('<hr />')
555562
self.visit_environment_in_state(s, prev_s)
556-
self._dump('<hr />')
557-
self.visit_generic_map_in_state('constraints', s, prev_s)
563+
self.visit_generic_map_in_state('constraints', 'Ranges',
564+
s, prev_s)
565+
self.visit_generic_map_in_state('dynamic_types', 'Dynamic Types',
566+
s, prev_s)
558567

559568
def visit_node(self, node):
560569
self._dump('%s [shape=record,label=<<table border="0">'
@@ -576,7 +585,6 @@ def visit_node(self, node):
576585
self._dump('</table></td></tr>')
577586

578587
if node.state is not None:
579-
self._dump('<hr />')
580588
prev_s = None
581589
# Do diffs only when we have a unique predecessor.
582590
# Don't do diffs on the leaf nodes because they're

0 commit comments

Comments
 (0)
Please sign in to comment.