public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] expand: Fix up LTO ICE with COMPOUND_LITERAL_EXPR [PR99849]
@ 2021-04-10  6:16 Jakub Jelinek
  2021-04-10 10:40 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2021-04-10  6:16 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

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.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

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.jj	2021-02-26 16:59:18.934091503 +0100
+++ gcc/expr.c	2021-04-09 17:16:20.784966107 +0200
@@ -8204,7 +8204,7 @@ expand_expr_addr_expr_1 (tree exp, rtx t
 	 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 */
--- gcc/testsuite/gcc.dg/lto/pr99849_0.c.jj	2021-04-09 17:12:51.554287572 +0200
+++ gcc/testsuite/gcc.dg/lto/pr99849_0.c	2021-04-09 17:15:53.303271468 +0200
@@ -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;

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] expand: Fix up LTO ICE with COMPOUND_LITERAL_EXPR [PR99849]
  2021-04-10  6:16 [PATCH] expand: Fix up LTO ICE with COMPOUND_LITERAL_EXPR [PR99849] Jakub Jelinek
@ 2021-04-10 10:40 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2021-04-10 10:40 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On April 10, 2021 8:16:16 AM GMT+02:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>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.
>
>Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok
>for
>trunk?

Ok. 

Richard. 
>
>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.jj	2021-02-26 16:59:18.934091503 +0100
>+++ gcc/expr.c	2021-04-09 17:16:20.784966107 +0200
>@@ -8204,7 +8204,7 @@ expand_expr_addr_expr_1 (tree exp, rtx t
> 	 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 */
>--- gcc/testsuite/gcc.dg/lto/pr99849_0.c.jj	2021-04-09
>17:12:51.554287572 +0200
>+++ gcc/testsuite/gcc.dg/lto/pr99849_0.c	2021-04-09 17:15:53.303271468
>+0200
>@@ -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;
>
>	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-10 10:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-10  6:16 [PATCH] expand: Fix up LTO ICE with COMPOUND_LITERAL_EXPR [PR99849] Jakub Jelinek
2021-04-10 10:40 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).