aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimplify.cc
diff options
context:
space:
mode:
authorAndrew Pinski <apinski@marvell.com>2021-12-20 20:27:33 -0800
committerAndrew Pinski <apinski@marvell.com>2022-08-08 08:14:25 -0700
commit21c7aab09805d0c8c7695c8a69c8715d673a739a (patch)
treea382ed19535fe9b35a9268a7460f9680369803c8 /gcc/gimplify.cc
parent5471f55f001af412e1125b04972ebaab9d4f7337 (diff)
downloadgcc-21c7aab09805d0c8c7695c8a69c8715d673a739a.zip
gcc-21c7aab09805d0c8c7695c8a69c8715d673a739a.tar.gz
gcc-21c7aab09805d0c8c7695c8a69c8715d673a739a.tar.bz2
Fix middle-end/103645: empty struct store not removed when using compound literal
For compound literals empty struct stores are not removed as they go down a different path of the gimplifier; trying to optimize the init constructor. This fixes the problem by not adding the gimple assignment at the end of gimplify_init_constructor if it was an empty type. Note this updates gcc.dg/pr87052.c where we had: const char d[0] = { }; And was expecting a store to d but after this, there is no store as the decl's type is zero in size. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: PR middle-end/103645 * gimplify.cc (gimplify_init_constructor): Don't build/add gimple assignment of an empty type. gcc/testsuite/ChangeLog: * gcc.dg/pr87052.c: Update d var to expect nothing.
Diffstat (limited to 'gcc/gimplify.cc')
-rw-r--r--gcc/gimplify.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 2ac7ca0..f0fbdb4 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -5488,8 +5488,11 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
if (ret == GS_ERROR)
return GS_ERROR;
/* If we have gimplified both sides of the initializer but have
- not emitted an assignment, do so now. */
- if (*expr_p)
+ not emitted an assignment, do so now. */
+ if (*expr_p
+ /* If the type is an empty type, we don't need to emit the
+ assignment. */
+ && !is_empty_type (TREE_TYPE (TREE_OPERAND (*expr_p, 0))))
{
tree lhs = TREE_OPERAND (*expr_p, 0);
tree rhs = TREE_OPERAND (*expr_p, 1);