From 8de9bb0eb6b5c48572d87fd616e8b21c702b38ad Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 21 Apr 2003 11:16:57 +0000 Subject: re PR c++/9881 (What is an address constant expression?) cp: PR c++/9881 * typeck.c (build_unary_op): Fold all COMPONENT_REF addr expressions. Reverts my 2002-08-08 patch. * typeck.c (comp_ptr_ttypes_real): Swap final && operands for cheaper early exit. testsuite: PR c++/9881 * g++.dg/init/addr-const1.C: New test. * g++.dg/other/packed1.C: XFAIL on aligned architectures. From-SVN: r65882 --- gcc/cp/ChangeLog | 9 ++++++++ gcc/cp/typeck.c | 27 +++++++++++------------ gcc/testsuite/ChangeLog | 8 ++++++- gcc/testsuite/g++.dg/init/addr-const1.C | 38 +++++++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/other/packed1.C | 5 ++++- 5 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/g++.dg/init/addr-const1.C (limited to 'gcc') diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8ea634f..cbe913e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2003-04-21 Nathan Sidwell + + PR c++/9881 + * typeck.c (build_unary_op): Fold all COMPONENT_REF addr + expressions. Reverts my 2002-08-08 patch. + + * typeck.c (comp_ptr_ttypes_real): Swap final && operands for + cheaper early exit. + 2003-04-20 Nathan Sidwell * cp/decl2.c (start_static_storage_duration_function): Take count diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 8e2682f..e60eb10 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4504,19 +4504,19 @@ build_unary_op (code, xarg, noconvert) && TREE_CODE (TREE_OPERAND (arg, 1)) == BASELINK) arg = BASELINK_FUNCTIONS (TREE_OPERAND (arg, 1)); - if (TREE_CODE (arg) == COMPONENT_REF - && DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1))) + if (TREE_CODE (arg) != COMPONENT_REF) + addr = build_address (arg); + else if (DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1))) { error ("attempt to take address of bit-field structure member `%D'", TREE_OPERAND (arg, 1)); return error_mark_node; } - else if (TREE_CODE (arg) == COMPONENT_REF - && TREE_CODE (TREE_OPERAND (arg, 0)) == INDIRECT_REF - && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (arg, 0), 0)) - == INTEGER_CST)) + else { - /* offsetof idiom, fold it. */ + /* Unfortunately we cannot just build an address + expression here, because we would not handle + address-constant-expressions or offsetof correctly. */ tree field = TREE_OPERAND (arg, 1); tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0); tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (rval)), @@ -4529,8 +4529,6 @@ build_unary_op (code, xarg, noconvert) addr = fold (build (PLUS_EXPR, argtype, rval, cp_convert (argtype, byte_position (field)))); } - else - addr = build_address (arg); if (TREE_CODE (argtype) == POINTER_TYPE && TREE_CODE (TREE_TYPE (argtype)) == METHOD_TYPE) @@ -6578,15 +6576,14 @@ comp_ptr_ttypes_real (to, from, constp) } if (TREE_CODE (to) != POINTER_TYPE) - return - same_type_ignoring_top_level_qualifiers_p (to, from) - && (constp >= 0 || to_more_cv_qualified); + return ((constp >= 0 || to_more_cv_qualified) + && same_type_ignoring_top_level_qualifiers_p (to, from)); } } -/* When comparing, say, char ** to char const **, this function takes the - 'char *' and 'char const *'. Do not pass non-pointer types to this - function. */ +/* When comparing, say, char ** to char const **, this function takes + the 'char *' and 'char const *'. Do not pass non-pointer/reference + types to this function. */ int comp_ptr_ttypes (to, from) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 408d817..fe9eb5c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,4 +1,10 @@ -2003-04-19 Nathan Sidwell +2003-04-21 Nathan Sidwell + + PR c++/9881 + * g++.dg/init/addr-const1.C: New test. + * g++.dg/other/packed1.C: XFAIL on aligned architectures. + +2003-04-20 Nathan Sidwell PR c++/10405 * g++.dg/lookup/struct-hack1.C: New test. diff --git a/gcc/testsuite/g++.dg/init/addr-const1.C b/gcc/testsuite/g++.dg/init/addr-const1.C new file mode 100644 index 0000000..3b4637a --- /dev/null +++ b/gcc/testsuite/g++.dg/init/addr-const1.C @@ -0,0 +1,38 @@ +// { dg-do run } + +// Copyright (C) 2003 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 19 Apr 2003 + +// PR 9881. address-constant-expression not static initialized + +struct bar { + double p; +}; // bar + +bar v; +static bool error = false; + +struct foo { + static double *a; + static double *b; + static double storage; +}; + +struct baz { + baz () { + if (foo::a != &v.p) + error = true; + if (foo::b != &foo::storage) + error = true; + } +}; + +baz f; // Get constructor to run before any other non-static initializers + +double *foo::a = &(((bar *)(&v))->p); +double *foo::b = &(((bar *)(&foo::storage))->p); +double foo::storage = 0.0; + +int main() { + return error; +} diff --git a/gcc/testsuite/g++.dg/other/packed1.C b/gcc/testsuite/g++.dg/other/packed1.C index 4fb7194..d19bb00 100644 --- a/gcc/testsuite/g++.dg/other/packed1.C +++ b/gcc/testsuite/g++.dg/other/packed1.C @@ -1,4 +1,7 @@ -// { dg-do run } +// { dg-do run { xfail arm-*-* } { xfail mips-*-* } { xfail powerpc-*-* } { xfail sh-*-* } { xfail sparc-*-* } + +// NMS:2003-04-21 this fails on strict aligned architectures again, +// the patch was reverted because it broke something more important. // Copyright (C) 2002 Free Software Foundation, Inc. // Contributed by Nathan Sidwell 8 Aug 2002 -- cgit v1.1