]> gcc.gnu.org Git - gcc.git/commitdiff
expand: Fix up LTO ICE with COMPOUND_LITERAL_EXPR [PR99849]
authorJakub Jelinek <jakub@redhat.com>
Sat, 10 Apr 2021 10:49:01 +0000 (12:49 +0200)
committerJakub Jelinek <jakub@redhat.com>
Sat, 10 Apr 2021 10:49:01 +0000 (12:49 +0200)
The gimplifier optimizes away COMPOUND_LITERAL_EXPRs, but they can remain
in the form of ADDR_EXPR of COMPOUND_LITERAL_EXPRs in static initializers.
By the TREE_STATIC check I meant to check that the underlying decl of
the compound literal is a global rather than automatic variable which
obviously can't be referenced in static initializers, but unfortunately
with LTO it might end up in another partition and thus be DECL_EXTERNAL
instead.

2021-04-10  Jakub Jelinek  <jakub@redhat.com>

PR lto/99849
* expr.c (expand_expr_addr_expr_1): Test is_global_var rather than
just TREE_STATIC on COMPOUND_LITERAL_EXPR_DECLs.

* gcc.dg/lto/pr99849_0.c: New test.

gcc/expr.c
gcc/testsuite/gcc.dg/lto/pr99849_0.c [new file with mode: 0644]

index 92035c7c3c1b5045bcb4e11654db49bcb6975b99..a0e194659659da378edc603b53d51128bfce9bd0 100644 (file)
@@ -8204,7 +8204,7 @@ expand_expr_addr_expr_1 (tree exp, rtx target, scalar_int_mode tmode,
         array with address of COMPOUND_LITERAL_EXPR in DECL_INITIAL;
         the initializers aren't gimplified.  */
       if (COMPOUND_LITERAL_EXPR_DECL (exp)
-         && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp)))
+         && is_global_var (COMPOUND_LITERAL_EXPR_DECL (exp)))
        return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp),
                                        target, tmode, modifier, as);
       /* FALLTHRU */
diff --git a/gcc/testsuite/gcc.dg/lto/pr99849_0.c b/gcc/testsuite/gcc.dg/lto/pr99849_0.c
new file mode 100644 (file)
index 0000000..d489cee
--- /dev/null
@@ -0,0 +1,23 @@
+/* PR lto/99849 */
+/* { dg-lto-do link } */
+/* { dg-require-effective-target fpic } */
+/* { dg-require-effective-target shared } */
+/* { dg-extra-ld-options { -shared } } */
+/* { dg-lto-options { { -flto -flto-partition=1to1 -O2 -Wno-incompatible-pointer-types -Wno-discarded-qualifiers -fPIC } } } */
+
+struct { struct A *a; } *b;
+struct B { int *b; };
+struct C { int *c; };
+const struct D { struct C d; } d;
+struct A { struct { struct C e; }; };
+struct E { void *e; } e = { &( &(const struct D) { (void *) &d })->d };
+struct C f = { &( &(const struct D) { (void *) &d })->d };
+struct A g[] = { &e, &f };
+void foo () { b->a = g; }
+struct E h = { foo };
+void bar ();
+int baz () { bar (h); }
+struct B i = { (int *) baz };
+void qux ();
+void corge () { qux (i); }
+void *j __attribute__((__used__)) = corge;
This page took 0.077929 seconds and 5 git commands to generate.