Skip to content

Commit 7fd3478

Browse files
author
Jan Hubicka
committed
Fix stmt_kills_ref_p WRT external throws
Add missing check to stmt_kills_ref_p for case that function is terminated by EH before call return value kills the ref. In the PR I tried to construct testcase but I don't know how to do that until I annotate EH code with fnspec attributes which I will do in separate patch and add a testcase. PR ipa/106057 * tree-ssa-alias.cc (stmt_kills_ref_p): Check for external throw.
1 parent 268b5c8 commit 7fd3478

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

gcc/tree-ssa-alias.cc

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ along with GCC; see the file COPYING3. If not see
8787
8888
This function tries to disambiguate two reference trees.
8989
90-
bool ptr_deref_may_alias_global_p (tree)
90+
bool ptr_deref_may_alias_global_p (tree, bool)
9191
9292
This function queries if dereferencing a pointer variable may
93-
alias global memory.
93+
alias global memory. If bool argument is true, global memory
94+
is considered to also include function local memory that escaped.
9495
9596
More low-level disambiguators are available and documented in
9697
this file. Low-level disambiguators dealing with points-to
@@ -3333,11 +3334,18 @@ stmt_kills_ref_p (gimple *stmt, ao_ref *ref)
33333334
&& TREE_CODE (gimple_get_lhs (stmt)) != SSA_NAME
33343335
/* The assignment is not necessarily carried out if it can throw
33353336
and we can catch it in the current function where we could inspect
3336-
the previous value.
3337+
the previous value. Similarly if the function can throw externally
3338+
and the ref does not die on the function return.
33373339
??? We only need to care about the RHS throwing. For aggregate
33383340
assignments or similar calls and non-call exceptions the LHS
3339-
might throw as well. */
3340-
&& !stmt_can_throw_internal (cfun, stmt))
3341+
might throw as well.
3342+
??? We also should care about possible longjmp, but since we
3343+
do not understand that longjmp is not using global memory we will
3344+
not consider a kill here since the function call will be considered
3345+
as possibly using REF. */
3346+
&& !stmt_can_throw_internal (cfun, stmt)
3347+
&& (!stmt_can_throw_external (cfun, stmt)
3348+
|| !ref_may_alias_global_p (ref, false)))
33413349
{
33423350
tree lhs = gimple_get_lhs (stmt);
33433351
/* If LHS is literally a base of the access we are done. */
@@ -3434,8 +3442,12 @@ stmt_kills_ref_p (gimple *stmt, ao_ref *ref)
34343442
&& node->binds_to_current_def_p ()
34353443
&& (summary = get_modref_function_summary (node)) != NULL
34363444
&& summary->kills.length ()
3445+
/* Check that we can not trap while evaulating function
3446+
parameters. This check is overly conservative. */
34373447
&& (!cfun->can_throw_non_call_exceptions
3438-
|| !stmt_can_throw_internal (cfun, stmt)))
3448+
|| (!stmt_can_throw_internal (cfun, stmt)
3449+
&& (!stmt_can_throw_external (cfun, stmt)
3450+
|| !ref_may_alias_global_p (ref, false)))))
34393451
{
34403452
for (auto kill : summary->kills)
34413453
{

0 commit comments

Comments
 (0)