re PR target/29198 (Incorrect reference to __thread array with -fPIC -O2 on x86)
authorJakub Jelinek <jakub@redhat.com>
Fri, 6 Oct 2006 07:25:02 +0000 (09:25 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 6 Oct 2006 07:25:02 +0000 (09:25 +0200)
PR target/29198
* config/i386/i386.c (legitimize_pic_address): Reject TLS symbols.
* config/i386/predicates.md (local_symbolic_operand): Likewise.

* gcc.dg/tls/opt-12.c: New test.

From-SVN: r117483

gcc/ChangeLog
gcc/config/i386/i386.c
gcc/config/i386/predicates.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tls/opt-12.c [new file with mode: 0644]

index 3eaecfedff3bf89163899479e714c4cd49f4d0a7..59bafdec7ffcdf1724235c6dca318d9bd1ab4031 100644 (file)
@@ -1,5 +1,9 @@
 2006-10-06  Jakub Jelinek  <jakub@redhat.com>
 
+       PR target/29198
+       * config/i386/i386.c (legitimize_pic_address): Reject TLS symbols.
+       * config/i386/predicates.md (local_symbolic_operand): Likewise.
+
        PR c/29091
        * varasm.c (output_constant): If TREE_VECTOR_CST_ELTS chain is shorter than
        the number of vector elements fill the rest with zeros.
index cdbd0c658c5812787f8a554757a6fb26036c2dd0..287163e8e0efef36e079988a4790b8809e702dc1 100644 (file)
@@ -6623,7 +6623,7 @@ legitimize_pic_address (rtx orig, rtx reg)
          new = reg;
        }
     }
-  else if (GET_CODE (addr) == SYMBOL_REF)
+  else if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
     {
       if (TARGET_64BIT)
        {
index 457f5563a7b0e9e6cdcc3dfe2edd92794f4e6ab8..52011918100deef097d5f76ceaa7f1354bdc8196 100644 (file)
   if (GET_CODE (op) != SYMBOL_REF)
     return 0;
 
+  if (SYMBOL_REF_TLS_MODEL (op) != 0)
+    return 0;
+
   if (SYMBOL_REF_LOCAL_P (op))
     return 1;
 
index ce15a0f56e585a2e96d66620d04a97dcfdfe33b5..5027cb4f5716836566b62fe88a0da62c126580f7 100644 (file)
@@ -1,5 +1,8 @@
 2006-10-06  Jakub Jelinek  <jakub@redhat.com>
 
+       PR target/29198
+       * gcc.dg/tls/opt-12.c: New test.
+
        PR fortran/28415
        * gfortran.dg/save_2.f90: New test.
 
diff --git a/gcc/testsuite/gcc.dg/tls/opt-12.c b/gcc/testsuite/gcc.dg/tls/opt-12.c
new file mode 100644 (file)
index 0000000..7c6e734
--- /dev/null
@@ -0,0 +1,50 @@
+/* PR target/29198 */
+/* { dg-do run } */
+/* { dg-options "-O2 -fpic" } */
+/* { dg-require-effective-target tls_runtime } */
+/* { dg-require-effective-target fpic } */
+
+extern void abort (void);
+
+int f2 (int, int, int, int);
+struct s { char b[4]; };
+__thread struct s thra[2];
+
+void
+__attribute__((noinline))
+f1 (int a1, int a2)
+{
+  int i, j;
+  for (i = 0; i < 4; i++)
+    {
+      int tot = 0;
+      for (j = 0; j < 4; j++)
+       tot += f2 (a1, a2, i, j);
+      *(&thra[0].b[0] + i) = tot;
+    }
+}
+
+int
+__attribute__((noinline))
+f2 (int a, int b, int c, int d)
+{
+  return a + b + c + d;
+}
+
+int
+main (void)
+{
+  f1 (0, 0);
+  if (thra[0].b[0] != 6
+      || thra[0].b[1] != 10
+      || thra[0].b[2] != 14
+      || thra[0].b[3] != 18)
+    abort ();
+  f1 (2, 3);
+  if (thra[0].b[0] != 26
+      || thra[0].b[1] != 30
+      || thra[0].b[2] != 34
+      || thra[0].b[3] != 38)
+    abort ();
+  return 0;
+}