]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gimplify: Don't optimize register const vars to static [PR93949]
authorJakub Jelinek <jakub@redhat.com>
Thu, 27 Feb 2020 09:45:30 +0000 (10:45 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 27 Feb 2020 10:23:32 +0000 (11:23 +0100)
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.

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr93949.c [new file with mode: 0644]

index c106e96c97883465b686d474b601eb2b1f582bac..9477068b051747f0273f9a87dba0ea831968373d 100644 (file)
@@ -1,3 +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.
+
 2020-02-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/93945
index f91ff3aca296404146589a6f8954dbee3c8e0eef..bd8bd6d7e064af225e7253250d3f676c3a610ad1 100644 (file)
@@ -4831,6 +4831,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
index 899b90d2e8c08edead0088216eef413b5cdcc283..934a50cfe4c53b7966aeed5685f46b1f26f3960f 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/93949
+       * gcc.c-torture/compile/pr93949.c: New test.
+
 2020-02-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/93945
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr93949.c b/gcc/testsuite/gcc.c-torture/compile/pr93949.c
new file mode 100644 (file)
index 0000000..bbda020
--- /dev/null
@@ -0,0 +1,7 @@
+/* PR c/93949 */
+
+void
+foo (void)
+{
+  register const double d[3] = { 0., 1., 2. };
+}