From: Mark Mitchell Date: Wed, 2 Mar 2005 20:57:53 +0000 (+0000) Subject: re PR c++/19916 (Segmentation fault in __static_initialization_and_destruction_0) X-Git-Tag: releases/gcc-3.4.4~182 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff75c584a12429f8014867785b8dd908654872f7;p=thirdparty%2Fgcc.git re PR c++/19916 (Segmentation fault in __static_initialization_and_destruction_0) PR c++/19916 * varasm.c (initializer_constant_valid_p): Allow conversions between OFFSET_TYPEs. Tidy. PR c++/19916 * g++.dg/init/ptrmem2.C: New test. From-SVN: r95809 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9aa82e790d69..15dc08ecf121 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2005-03-02 Mark Mitchell + + PR c++/19916 + * varasm.c (initializer_constant_valid_p): Allow conversions + between OFFSET_TYPEs. Tidy. + 2005-02-28 John David Anglin PR target/19819 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dca1f18ba350..8b6ee0dca2e9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-03-02 Mark Mitchell + + PR c++/19916 + * g++.dg/init/ptrmem2.C: New test. + 2005-03-02 Alexandre Oliva * g++.dg/overload/using2.C: New. diff --git a/gcc/varasm.c b/gcc/varasm.c index 19afc3db832d..33307e529a6b 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -3556,63 +3556,61 @@ initializer_constant_valid_p (tree value, tree endtype) case CONVERT_EXPR: case NOP_EXPR: - /* Allow conversions between pointer types. */ - if (POINTER_TYPE_P (TREE_TYPE (value)) - && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))) - return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); - - /* Allow conversions between real types. */ - if (FLOAT_TYPE_P (TREE_TYPE (value)) - && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))) - return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); - - /* Allow length-preserving conversions between integer types. */ - if (INTEGRAL_TYPE_P (TREE_TYPE (value)) - && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))) - && (TYPE_PRECISION (TREE_TYPE (value)) - == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))) - return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); - - /* Allow conversions between other integer types only if - explicit value. */ - if (INTEGRAL_TYPE_P (TREE_TYPE (value)) - && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))) - { - tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0), - endtype); - if (inner == null_pointer_node) - return null_pointer_node; - break; - } + { + tree src; + tree src_type; + tree dest_type; + + src = TREE_OPERAND (value, 0); + src_type = TREE_TYPE (src); + dest_type = TREE_TYPE (value); + + /* Allow conversions between pointer types, floating-point + types, and offset types. */ + if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)) + || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type)) + || (TREE_CODE (dest_type) == OFFSET_TYPE + && TREE_CODE (src_type) == OFFSET_TYPE)) + return initializer_constant_valid_p (src, endtype); + + /* Allow length-preserving conversions between integer types. */ + if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type) + && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type))) + return initializer_constant_valid_p (src, endtype); + + /* Allow conversions between other integer types only if + explicit value. */ + if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)) + { + tree inner = initializer_constant_valid_p (src, endtype); + if (inner == null_pointer_node) + return null_pointer_node; + break; + } - /* Allow (int) &foo provided int is as wide as a pointer. */ - if (INTEGRAL_TYPE_P (TREE_TYPE (value)) - && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))) - && (TYPE_PRECISION (TREE_TYPE (value)) - >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))) - return initializer_constant_valid_p (TREE_OPERAND (value, 0), - endtype); - - /* Likewise conversions from int to pointers, but also allow - conversions from 0. */ - if ((POINTER_TYPE_P (TREE_TYPE (value)) - || TREE_CODE (TREE_TYPE (value)) == OFFSET_TYPE) - && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))) - { - if (integer_zerop (TREE_OPERAND (value, 0))) - return null_pointer_node; - else if (TYPE_PRECISION (TREE_TYPE (value)) - <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))) - return initializer_constant_valid_p (TREE_OPERAND (value, 0), - endtype); - } + /* Allow (int) &foo provided int is as wide as a pointer. */ + if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type) + && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))) + return initializer_constant_valid_p (src, endtype); - /* Allow conversions to struct or union types if the value - inside is okay. */ - if (TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE - || TREE_CODE (TREE_TYPE (value)) == UNION_TYPE) - return initializer_constant_valid_p (TREE_OPERAND (value, 0), - endtype); + /* Likewise conversions from int to pointers, but also allow + conversions from 0. */ + if ((POINTER_TYPE_P (dest_type) + || TREE_CODE (dest_type) == OFFSET_TYPE) + && INTEGRAL_TYPE_P (src_type)) + { + if (integer_zerop (src)) + return null_pointer_node; + else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type)) + return initializer_constant_valid_p (src, endtype); + } + + /* Allow conversions to struct or union types if the value + inside is okay. */ + if (TREE_CODE (dest_type) == RECORD_TYPE + || TREE_CODE (dest_type) == UNION_TYPE) + return initializer_constant_valid_p (src, endtype); + } break; case PLUS_EXPR: