From: Jakub Jelinek Date: Tue, 24 Apr 2012 06:14:37 +0000 (+0200) Subject: re PR middle-end/53084 (GCC cannot handle array initialization of string constant... X-Git-Tag: releases/gcc-4.6.4~574 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=714dd6237a87503c6c382e2a715e8f589e965f10;p=thirdparty%2Fgcc.git re PR middle-end/53084 (GCC cannot handle array initialization of string constant with point arithmetic properly) 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 90f8204c049c..268edbc3cba4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2012-04-24 Jakub Jelinek + + 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 struct siginfo vs. siginfo_t diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2819865ee750..c1c1ce9beadb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-04-24 Jakub Jelinek + + PR middle-end/53084 + * gcc.c-torture/execute/pr53084.c: New test. + 2012-04-13 Michael Meissner 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 index 000000000000..1afc016dfc41 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr53084.c @@ -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; +} diff --git a/gcc/varasm.c b/gcc/varasm.c index d9748887d893..977ca40a0882 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -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: