]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/53084 (GCC cannot handle array initialization of string constant...
authorJakub Jelinek <jakub@redhat.com>
Tue, 24 Apr 2012 06:14:37 +0000 (08:14 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 24 Apr 2012 06:14:37 +0000 (08:14 +0200)
PR middle-end/53084
* varasm.c (compute_reloc_for_constant): Handle ADDR_EXPR
of MEM_REF.
(output_addressed_constants): Likewise.

* gcc.c-torture/execute/pr53084.c: New test.

From-SVN: r186746

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr53084.c [new file with mode: 0644]
gcc/varasm.c

index 90f8204c049c0a6a5f7376c6a30293113a5d6cd1..268edbc3cba4c138d308838d8de7bc00b161fb40 100644 (file)
@@ -1,3 +1,10 @@
+2012-04-24  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/53084
+       * varasm.c (compute_reloc_for_constant): Handle ADDR_EXPR
+       of MEM_REF.
+       (output_addressed_constants): Likewise.
+
 2012-04-20  Thomas Schwinge  <thomas@codesourcery.com>
 
        struct siginfo vs. siginfo_t
index 2819865ee750eefbc0539c0ebd590c143f6e6410..c1c1ce9beadbb18294997c78536d307045944e4a 100644 (file)
@@ -1,3 +1,8 @@
+2012-04-24  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/53084
+       * gcc.c-torture/execute/pr53084.c: New test.
+
 2012-04-13  Michael Meissner  <meissner@linux.vnet.ibm.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr53084.c b/gcc/testsuite/gcc.c-torture/execute/pr53084.c
new file mode 100644 (file)
index 0000000..1afc016
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR middle-end/53084 */
+
+extern void abort (void);
+
+__attribute__((noinline, noclone)) void
+bar (const char *p)
+{
+  if (p[0] != 'o' || p[1] != 'o' || p[2])
+    abort ();
+}
+
+int
+main ()
+{
+  static const char *const foo[] = {"foo" + 1};
+  bar (foo[0]);
+  return 0;
+}
index d9748887d893298ff7d79367d01675e7927ceeab..977ca40a088271ee4b7013461cdd80ef93c6af59 100644 (file)
@@ -1,7 +1,7 @@
 /* Output variables, constants and external declarations, for GNU compiler.
    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
    1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-   2010, 2011  Free Software Foundation, Inc.
+   2010, 2011, 2012  Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -3944,6 +3944,13 @@ compute_reloc_for_constant (tree exp)
           tem = TREE_OPERAND (tem, 0))
        ;
 
+      if (TREE_CODE (tem) == MEM_REF
+         && TREE_CODE (TREE_OPERAND (tem, 0)) == ADDR_EXPR)
+       {
+         reloc = compute_reloc_for_constant (TREE_OPERAND (tem, 0));
+         break;
+       }
+
       if (TREE_PUBLIC (tem))
        reloc |= 2;
       else
@@ -4012,6 +4019,9 @@ output_addressed_constants (tree exp)
 
       if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
        output_constant_def (tem, 0);
+
+      if (TREE_CODE (tem) == MEM_REF)
+       output_addressed_constants (TREE_OPERAND (tem, 0));
       break;
 
     case PLUS_EXPR: