This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix TLS related ICE
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Henderson <rth at redhat dot com>, roland at redhat dot com, gcc-patches at gcc dot gnu dot org
- Date: Tue, 30 Jul 2002 14:12:27 -0400
- Subject: Re: [PATCH] Fix TLS related ICE
- References: <20020730154715.H20867@sunsite.ms.mff.cuni.cz> <20020730094559.E1375@redhat.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Jul 30, 2002 at 09:45:59AM -0700, Richard Henderson wrote:
> On Tue, Jul 30, 2002 at 03:47:15PM +0200, Jakub Jelinek wrote:
> > + /* Addresses of thread local variables might result in
> > + function calls. */
> > + if (TREE_CODE (args[i].tree_value) == ADDR_EXPR
> > + && TREE_CODE (TREE_OPERAND (args[i].tree_value, 0)) == VAR_DECL
> > + && DECL_THREAD_LOCAL (TREE_OPERAND (args[i].tree_value, 0))
> > + && GET_CODE (args[i].value) == SYMBOL_REF)
> > + args[i].value
> > + = memory_address (TYPE_MODE (TREE_TYPE (args[i].tree_value)),
> > + args[i].value);
>
> I don't like this. Someone (expand_expr or here) should notice that
> the constant isn't valid and use that to force it into a register.
Like this?
If memory_address_p was tested unconditionally there, I'm afraid it would
cause -fforce-addr by default on most arches (where a SYMBOL_REF
is not valid memory address).
2002-07-30 Jakub Jelinek <jakub@redhat.com>
* expr.c (expand_expr) [ADDR_EXPR]: Force addresses of thread-local
variables into pseudo.
* gcc.dg/tls/opt-1.c: New test.
--- gcc/expr.c.jj 2002-07-30 12:49:43.000000000 +0200
+++ gcc/expr.c 2002-07-30 20:18:36.000000000 +0200
@@ -8833,7 +8833,12 @@ expand_expr (exp, target, tmode, modifie
op0 = force_operand (XEXP (op0, 0), target);
}
- if (flag_force_addr
+ if ((flag_force_addr
+ || (TREE_CODE (TREE_OPERAND (exp, 0)) == VAR_DECL
+ && DECL_THREAD_LOCAL (TREE_OPERAND (exp, 0))
+ && ! memory_address_p (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp,
+ 0))),
+ op0)))
&& GET_CODE (op0) != REG
&& modifier != EXPAND_CONST_ADDRESS
&& modifier != EXPAND_INITIALIZER
--- gcc/testsuite/gcc.dg/tls/opt-1.c.jj 2002-07-30 13:57:33.000000000 +0200
+++ gcc/testsuite/gcc.dg/tls/opt-1.c 2002-07-30 13:56:40.000000000 +0200
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fPIC" } */
+/* { dg-options "-O2 -fPIC -mcpu=i686" { target i?86-*-* } } */
+
+extern __thread int thr;
+
+static int x;
+
+static void
+bar (void)
+{
+ x = 1;
+}
+
+static void
+#ifdef __i386__
+__attribute__ ((regparm (3)))
+#endif
+foo (const char *x, void *y, int *z)
+{
+ bar ();
+}
+
+void
+test (const char *x, void *y)
+{
+ foo (x, y, &thr);
+}
Jakub