Skip to content

Commit b9457ed

Browse files
rguenthRichard Biener
authored andcommitted
Fix unsafe stmt modifications in FOR_EACH_IMM_USE_STMT
The following fixes path isolation changing the immediate use list of an SSA name that is currently iterated over via FOR_EACH_IMM_USE_STMT. This happens when it duplicates a BB within this and creates/modifies stmts that contain SSA uses of the name and calls update_stmt which re-builds SSA operands, including removal of SSA uses and re-inserting them. This is not safe as that might cause missed iterated uses but more importantly could cause the 'next' use to be removed. For the case in question the fix is to collect interesting uses in a vec and do the processing outside of the FOR_EACH_IMM_USE_STMT iteration. * gimple-ssa-isolate-paths.cc (check_loadstore): Set the volatile flag on the stmt manually. (find_implicit_erroneous_behavior): Move code transform outside of FOR_EACH_IMM_USE_STMT iteration.
1 parent e5b355e commit b9457ed

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

gcc/gimple-ssa-isolate-paths.cc

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ check_loadstore (gimple *stmt, tree op, tree, void *data)
5656
{
5757
TREE_THIS_VOLATILE (op) = 1;
5858
TREE_SIDE_EFFECTS (op) = 1;
59-
update_stmt (stmt);
59+
gimple_set_has_volatile_ops (stmt, true);
6060
return true;
6161
}
6262
return false;
@@ -762,6 +762,7 @@ find_implicit_erroneous_behavior (void)
762762

763763
/* We've got a NULL PHI argument. Now see if the
764764
PHI's result is dereferenced within BB. */
765+
auto_vec <gimple *, 4> uses_in_bb;
765766
FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs)
766767
{
767768
/* We only care about uses in BB. Catching cases in
@@ -774,18 +775,23 @@ find_implicit_erroneous_behavior (void)
774775
? gimple_location (use_stmt)
775776
: phi_arg_loc;
776777

777-
if (stmt_uses_name_in_undefined_way (use_stmt, lhs, loc)
778-
&& (duplicate || can_duplicate_block_p (bb)))
778+
if (stmt_uses_name_in_undefined_way (use_stmt, lhs, loc))
779779
{
780-
duplicate = isolate_path (bb, duplicate, e,
781-
use_stmt, lhs, false);
782-
783-
/* When we remove an incoming edge, we need to
784-
reprocess the Ith element. */
785-
next_i = i;
786-
cfg_altered = true;
780+
if (!can_duplicate_block_p (bb))
781+
break;
782+
uses_in_bb.safe_push (use_stmt);
787783
}
788784
}
785+
for (gimple *use_stmt : uses_in_bb)
786+
{
787+
duplicate = isolate_path (bb, duplicate, e,
788+
use_stmt, lhs, false);
789+
790+
/* When we remove an incoming edge, we need to
791+
reprocess the Ith element. */
792+
next_i = i;
793+
cfg_altered = true;
794+
}
789795
}
790796
}
791797
}

0 commit comments

Comments
 (0)