From: Mark Mitchell Date: Sun, 7 Sep 2003 23:48:33 +0000 (+0000) Subject: re PR c++/11852 (ICE: g++ with bad struct initializer.) X-Git-Tag: releases/gcc-3.4.0~3839 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cf9ad9a773d6b804843fa11a55da91112cdd7c05;p=thirdparty%2Fgcc.git re PR c++/11852 (ICE: g++ with bad struct initializer.) PR c++/11852 * varasm.c (initializer_constant_valid_p): Correct logic for CONSTRUCTORs. PR c++/11852 * g++.dg/init/struct1.C: New test. From-SVN: r71187 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 33083458f24e..edd91eb9af1c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2003-09-07 Mark Mitchell + + PR c++/11852 + * varasm.c (initializer_constant_valid_p): Correct logic for + CONSTRUCTORs. + 2003-09-07 Roger Sayle * expr.c (expand_operands): New function to expand an operand pair. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 51a01940bdf1..a88421b332ea 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2003-09-07 Mark Mitchell + + PR c++/11852 + * g++.dg/init/struct1.C: New test. + 2003-09-07 Mark Mitchell PR c++/12181 diff --git a/gcc/testsuite/g++.dg/init/struct1.C b/gcc/testsuite/g++.dg/init/struct1.C new file mode 100644 index 000000000000..4cabc99e0e23 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/struct1.C @@ -0,0 +1,6 @@ +struct bug { + const char *name; + unsigned long type; +}; + +struct bug s = { 0, (unsigned long) &s | 1 }; diff --git a/gcc/varasm.c b/gcc/varasm.c index d327cb2d8c23..84fbf259baf7 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -3476,11 +3476,27 @@ initializer_constant_valid_p (tree value, tree endtype) || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE) && TREE_CONSTANT (value) && CONSTRUCTOR_ELTS (value)) - return - initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)), - endtype); + { + tree elt; + bool absolute = true; + + for (elt = CONSTRUCTOR_ELTS (value); elt; elt = TREE_CHAIN (elt)) + { + tree reloc; + value = TREE_VALUE (elt); + reloc = initializer_constant_valid_p (value, TREE_TYPE (value)); + if (!reloc) + return NULL_TREE; + if (reloc != null_pointer_node) + absolute = false; + } + /* For a non-absolute relocation, there is no single + variable that can be "the variable that determines the + relocation." */ + return absolute ? null_pointer_node : error_mark_node; + } - return TREE_STATIC (value) ? null_pointer_node : 0; + return TREE_STATIC (value) ? null_pointer_node : NULL_TREE; case INTEGER_CST: case VECTOR_CST: