Skip to content

Commit

Permalink
middle-end/110055 - avoid CLOBBERing static variables
Browse files Browse the repository at this point in the history
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.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	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.
  • Loading branch information
rguenth authored and ouuleilei-bot committed Jun 6, 2023
1 parent c2d62cd commit 17618e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gcc/gimplify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7173,8 +7173,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)
Expand Down
16 changes: 16 additions & 0 deletions gcc/testsuite/g++.dg/warn/Wdangling-pointer-pr110055.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// { dg-do compile }
// { dg-require-effective-target c++11 }
// { dg-options "-O3 -fno-exceptions -Wdangling-pointer" }

#include <cstdint>
#include <vector>

struct Data {
std::vector<uint16_t> v = {1, 1};
};

int main()
{
Data a;
Data b;
}

0 comments on commit 17618e7

Please sign in to comment.