analyzer: consolidate conditionals in paths
authorDavid Malcolm <dmalcolm@redhat.com>
Fri, 29 Jan 2021 20:12:24 +0000 (15:12 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Fri, 29 Jan 2021 20:12:24 +0000 (15:12 -0500)
commiteb06fdd424bf66e0245295b75f22316743d86251
tree3a06559e68cbf2a5ddd0e08cdeaaf5156fa9f20a
parent7f9f83ef300e8734dccb90a7c347997b2787e9e9
analyzer: consolidate conditionals in paths

This patch adds a simplification to analyzer paths for
repeated CFG edges generated from compound conditionals.
For example, it simplifies:

    |    5 |   if (a && b && c)
    |      |      ^~~~~~~~~~~~
    |      |      |  |    |
    |      |      |  |    (4) ...to here
    |      |      |  |    (5) following ‘true’ branch (when ‘c != 0’)...
    |      |      |  (2) ...to here
    |      |      |  (3) following ‘true’ branch (when ‘b != 0’)...
    |      |      (1) following ‘true’ branch (when ‘a != 0’)...
    |    6 |     __analyzer_dump_path ();
    |      |     ~~~~~~~~~~~~~~~~~~~~~~~
    |      |     |
    |      |     (6) ...to here

to:

    |    5 |   if (a && b && c)
    |      |      ^
    |      |      |
    |      |      (1) following ‘true’ branch...
    |    6 |     __analyzer_dump_path ();
    |      |     ~~~~~~~~~~~~~~~~~~~~~~~
    |      |     |
    |      |     (2) ...to here

gcc/analyzer/ChangeLog:
* checker-path.cc (event_kind_to_string): Handle
EK_START_CONSOLIDATED_CFG_EDGES and
EK_END_CONSOLIDATED_CFG_EDGES.
(start_consolidated_cfg_edges_event::get_desc): New.
(checker_path::cfg_edge_pair_at_p): New.
* checker-path.h (enum event_kind): Add
EK_START_CONSOLIDATED_CFG_EDGES and
EK_END_CONSOLIDATED_CFG_EDGES.
(class start_consolidated_cfg_edges_event): New class.
(class end_consolidated_cfg_edges_event): New class.
(checker_path::delete_events): New.
(checker_path::replace_event): New.
(checker_path::cfg_edge_pair_at_p): New decl.
* diagnostic-manager.cc (diagnostic_manager::prune_path): Call
consolidate_conditions.
(same_line_as_p): New.
(diagnostic_manager::consolidate_conditions): New.
* diagnostic-manager.h
(diagnostic_manager::consolidate_conditions): New decl.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/combined-conditionals-1.c: New test.
gcc/analyzer/checker-path.cc
gcc/analyzer/checker-path.h
gcc/analyzer/diagnostic-manager.cc
gcc/analyzer/diagnostic-manager.h
gcc/testsuite/gcc.dg/analyzer/combined-conditionals-1.c [new file with mode: 0644]