aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimplify.cc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2023-06-05 08:56:53 +0200
committerRichard Biener <rguenther@suse.de>2023-06-06 09:19:35 +0200
commit84eec2916fa68cd2e2b3a2cf764f2ba595cce843 (patch)
tree5df3af4b06ca42be81bf7c14eb90e488aa4cbd1f /gcc/gimplify.cc
parent21bf2b2fd99d7a94049610fc2f82db77f725d025 (diff)
downloadgcc-84eec2916fa68cd2e2b3a2cf764f2ba595cce843.zip
gcc-84eec2916fa68cd2e2b3a2cf764f2ba595cce843.tar.gz
gcc-84eec2916fa68cd2e2b3a2cf764f2ba595cce843.tar.bz2
middle-end/110055 - avoid CLOBBERing static variables
The gimplifier can elide initialized constant automatic variables to static storage in which case TARGET_EXPR gimplification needs to avoid emitting a CLOBBER for them since their lifetime is no longer limited. Failing to do so causes spurious dangling-pointer diagnostics on the added testcase for some targets. PR middle-end/110055 * gimplify.cc (gimplify_target_expr): Do not emit CLOBBERs for variables which have static storage duration after gimplifying their initializers. * g++.dg/warn/Wdangling-pointer-pr110055.C: New testcase.
Diffstat (limited to 'gcc/gimplify.cc')
-rw-r--r--gcc/gimplify.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index bd5d0bf..4aa6229 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -7174,8 +7174,10 @@ gimplify_target_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
gimplify_and_add (init, &init_pre_p);
/* Add a clobber for the temporary going out of scope, like
- gimplify_bind_expr. */
+ gimplify_bind_expr. But only if we did not promote the
+ temporary to static storage. */
if (gimplify_ctxp->in_cleanup_point_expr
+ && !TREE_STATIC (temp)
&& needs_to_live_in_memory (temp))
{
if (flag_stack_reuse == SR_ALL)