[PATCH] D64611: [analyzer] exploded-graph-rewriter: Improve source location dumps.

2019-07-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ closed this revision.
NoQ added a comment.

Whoops, forgot the phabricator link.
Committed as rC365861 .


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64611/new/

https://reviews.llvm.org/D64611



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64611: [analyzer] exploded-graph-rewriter: Improve source location dumps.

2019-07-11 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso accepted this revision.
Charusso added a comment.
This revision is now accepted and ready to land.

Much better! Thanks!


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64611/new/

https://reviews.llvm.org/D64611



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64611: [analyzer] exploded-graph-rewriter: Improve source location dumps.

2019-07-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added a reviewer: Charusso.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: clang.

- Correctly display macro expansion and spelling locations.
- Use the same procedure to display location context call site locations.
- Display statement IDs for program points.

F9535526: Screen Shot 2019-07-11 at 5.07.05 PM.png 



Repository:
  rC Clang

https://reviews.llvm.org/D64611

Files:
  clang/include/clang/Basic/JsonSupport.h
  clang/lib/Analysis/AnalysisDeclContext.cpp
  clang/lib/Analysis/ProgramPoint.cpp
  clang/test/Analysis/dump_egraph.cpp
  clang/test/Analysis/exploded-graph-rewriter/environment.dot
  clang/test/Analysis/exploded-graph-rewriter/environment_diff.dot
  clang/test/Analysis/exploded-graph-rewriter/macros.c
  clang/test/Analysis/exploded-graph-rewriter/program_points.dot
  clang/test/Analysis/expr-inspection.c
  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
@@ -49,10 +49,16 @@
 class SourceLocation(object):
 def __init__(self, json_loc):
 super(SourceLocation, self).__init__()
+logging.debug('json: %s' % json_loc)
 self.line = json_loc['line']
 self.col = json_loc['column']
 self.filename = os.path.basename(json_loc['file']) \
 if 'file' in json_loc else '(main file)'
+self.spelling = SourceLocation(json_loc['spelling']) \
+if 'spelling' in json_loc else None
+
+def is_macro(self):
+return self.spelling is not None
 
 
 # A deserialized program point.
@@ -65,8 +71,10 @@
 self.src_id = json_pp['src_id']
 self.dst_id = json_pp['dst_id']
 elif self.kind == 'Statement':
+logging.debug(json_pp)
 self.stmt_kind = json_pp['stmt_kind']
 self.stmt_point_kind = json_pp['stmt_point_kind']
+self.stmt_id = json_pp['stmt_id']
 self.pointer = json_pp['pointer']
 self.pretty = json_pp['pretty']
 self.loc = SourceLocation(json_pp['location']) \
@@ -102,7 +110,8 @@
 self.lctx_id = json_frame['lctx_id']
 self.caption = json_frame['location_context']
 self.decl = json_frame['calling']
-self.line = json_frame['call_line']
+self.loc = SourceLocation(json_frame['location']) \
+if json_frame['location'] is not None else None
 
 def _key(self):
 return self.lctx_id
@@ -432,6 +441,22 @@
 return s
 return candidate
 
+@staticmethod
+def _make_sloc(loc):
+if loc is None:
+return 'Invalid Source Location'
+
+def make_plain_loc(loc):
+return '%s:%s:%s' \
+% (loc.filename, loc.line, loc.col)
+
+if loc.is_macro():
+return '%s ' \
+   '(spelling at  %s)' \
+% (make_plain_loc(loc), make_plain_loc(loc.spelling))
+
+return make_plain_loc(loc)
+
 def visit_begin_graph(self, graph):
 self._graph = graph
 self._dump_raw('digraph "ExplodedGraph" {\n')
@@ -457,29 +482,16 @@
 # Such statements show up only at [Pre|Post]StmtPurgeDeadSymbols
 skip_pretty = 'PurgeDeadSymbols' in p.stmt_point_kind
 stmt_color = 'cyan3'
-if p.loc is not None:
-self._dump(''
-   '%s:%s:%s:'
-   ''
-   '%s'
-   '%s'
-   '%s'
-   % (p.loc.filename, p.loc.line,
-  p.loc.col, color, p.stmt_kind,
-  stmt_color, p.stmt_point_kind,
-  self._short_pretty(p.pretty)
-  if not skip_pretty else ''))
-else:
-self._dump(''
-   'Invalid Source Location:'
-   ''
-   '%s'
-   '%s'
-   '%s'
-   % (color, p.stmt_kind,
-  stmt_color, p.stmt_point_kind,
-  self._short_pretty(p.pretty)
-  if not skip_pretty else ''))
+self._dump('%s:'
+   ''
+   '%s '
+   'S%s'
+   '%s'
+   '%s'
+   % (self._make_sloc(p.loc), color, p.stmt_kind,
+  p.stmt_id, stmt_color, p.stmt_point_kind,
+  self._short_pretty(p.pretty)
+