2002-07-30 Jakub Jelinek * expr.c (expand_expr) [ADDR_EXPR]: Force addresses of thread-local variables into pseudo. * gcc.dg/tls/opt-1.c: New test. --- 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); +} --- 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