Skip to content

Commit 6416365

Browse files
rguenthRichard Biener
authored andcommitted
tree-optimization/116850 - corrupt post-dom info
Path isolation computes post-dominators on demand but can end up splitting blocks after that, wrecking it. We can delay splitting of blocks until we no longer need the post-dom info which is what the following patch does to solve the issue. PR tree-optimization/116850 * gimple-ssa-isolate-paths.cc (bb_split_points): New global. (insert_trap): Delay BB splitting if post-doms are computed. (find_explicit_erroneous_behavior): Process delayed BB splitting after releasing post dominators. (gimple_ssa_isolate_erroneous_paths): Do not free post-dom info here. * gcc.dg/pr116850.c: New testcase.
1 parent 3f8b1b2 commit 6416365

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

gcc/gimple-ssa-isolate-paths.cc

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ check_loadstore (gimple *stmt, tree op, tree, void *data)
6262
return false;
6363
}
6464

65+
static vec<gimple *> *bb_split_points;
66+
6567
/* Insert a trap after SI and split the block after the trap. */
6668

6769
static void
@@ -104,14 +106,20 @@ insert_trap (gimple_stmt_iterator *si_p, tree op)
104106
gsi_insert_after (si_p, seq, GSI_NEW_STMT);
105107
if (stmt_ends_bb_p (stmt))
106108
{
107-
split_block (gimple_bb (stmt), stmt);
109+
if (dom_info_available_p (CDI_POST_DOMINATORS))
110+
bb_split_points->safe_push (stmt);
111+
else
112+
split_block (gimple_bb (stmt), stmt);
108113
return;
109114
}
110115
}
111116
else
112117
gsi_insert_before (si_p, seq, GSI_NEW_STMT);
113118

114-
split_block (gimple_bb (new_stmt), new_stmt);
119+
if (dom_info_available_p (CDI_POST_DOMINATORS))
120+
bb_split_points->safe_push (new_stmt);
121+
else
122+
split_block (gimple_bb (new_stmt), new_stmt);
115123
*si_p = gsi_for_stmt (stmt);
116124
}
117125

@@ -842,6 +850,8 @@ static void
842850
find_explicit_erroneous_behavior (void)
843851
{
844852
basic_block bb;
853+
auto_vec<gimple *> local_bb_split_points;
854+
bb_split_points = &local_bb_split_points;
845855

846856
FOR_EACH_BB_FN (bb, cfun)
847857
{
@@ -883,6 +893,14 @@ find_explicit_erroneous_behavior (void)
883893
warn_return_addr_local (bb, return_stmt);
884894
}
885895
}
896+
897+
free_dominance_info (CDI_POST_DOMINATORS);
898+
899+
/* Perform delayed splitting of blocks. */
900+
for (gimple *stmt : local_bb_split_points)
901+
split_block (gimple_bb (stmt), stmt);
902+
903+
bb_split_points = NULL;
886904
}
887905

888906
/* Search the function for statements which, if executed, would cause
@@ -939,7 +957,6 @@ gimple_ssa_isolate_erroneous_paths (void)
939957
/* We scramble the CFG and loop structures a bit, clean up
940958
appropriately. We really should incrementally update the
941959
loop structures, in theory it shouldn't be that hard. */
942-
free_dominance_info (CDI_POST_DOMINATORS);
943960
if (cfg_altered)
944961
{
945962
free_dominance_info (CDI_DOMINATORS);

gcc/testsuite/gcc.dg/pr116850.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-Os -w" } */
3+
4+
int a, b;
5+
int *c()
6+
{
7+
int d, *e = 0, *f = &d, *g = &a;
8+
if (b)
9+
g = 0;
10+
*e = *g;
11+
return f;
12+
}

0 commit comments

Comments
 (0)