aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-02-27 10:45:30 +0100
committerJakub Jelinek <jakub@redhat.com>2020-02-27 10:45:30 +0100
commit1956773cc655dfcba8d310066d3f6585dd4b8972 (patch)
tree97912090e49accaad698355da78281533048d1a0
parent5f9cd512c4278621435cce486dd00248ea2e821c (diff)
downloadgcc-1956773cc655dfcba8d310066d3f6585dd4b8972.zip
gcc-1956773cc655dfcba8d310066d3f6585dd4b8972.tar.gz
gcc-1956773cc655dfcba8d310066d3f6585dd4b8972.tar.bz2
gimplify: Don't optimize register const vars to static [PR93949]
The following testcase is rejected, while it was accepted in 3.4 and earlier (before tree-ssa merge). The problem is that we decide to promote the const variable to TREE_STATIC, but TREE_STATIC DECL_REGISTER VAR_DECLs may only be the global register vars and so assemble_variable/make_decl_rtl diagnoses it. Either we do what the following patch does, where we could consider register as a hint the user doesn't want such optimization, because if something is forced static, it is not "register" anymore and register static is not valid in C either, or we could clear DECL_REGISTER instead, but would still need to punt at least on DECL_HARD_REGISTER cases. 2020-02-27 Jakub Jelinek <jakub@redhat.com> PR c/93949 * gimplify.c (gimplify_init_constructor): Don't promote readonly DECL_REGISTER variables to TREE_STATIC. * gcc.c-torture/compile/pr93949.c: New test.
-rw-r--r--gcc/ChangeLog4
-rw-r--r--gcc/gimplify.c1
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/gcc.c-torture/compile/pr93949.c7
4 files changed, 15 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 38bfbb9..d8cfd09 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,9 @@
2020-02-27 Jakub Jelinek <jakub@redhat.com>
+ PR c/93949
+ * gimplify.c (gimplify_init_constructor): Don't promote readonly
+ DECL_REGISTER variables to TREE_STATIC.
+
PR tree-optimization/93582
PR tree-optimization/93945
* tree-ssa-sccvn.c (vn_reference_lookup_3): Handle memset with
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index a6205d6..ef531f3 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -4923,6 +4923,7 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
&& num_nonzero_elements > 1
&& TREE_READONLY (object)
&& VAR_P (object)
+ && !DECL_REGISTER (object)
&& (flag_merge_constants >= 2 || !TREE_ADDRESSABLE (object))
/* For ctors that have many repeated nonzero elements
represented through RANGE_EXPRs, prefer initializing
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 70897c5..3cc13f9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
2020-02-27 Jakub Jelinek <jakub@redhat.com>
+ PR c/93949
+ * gcc.c-torture/compile/pr93949.c: New test.
+
PR tree-optimization/93582
PR tree-optimization/93945
* gcc.dg/tree-ssa/pr93582-9.c: New test.
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr93949.c b/gcc/testsuite/gcc.c-torture/compile/pr93949.c
new file mode 100644
index 0000000..bbda020
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr93949.c
@@ -0,0 +1,7 @@
+/* PR c/93949 */
+
+void
+foo (void)
+{
+ register const double d[3] = { 0., 1., 2. };
+}