Commit 8de9bb0e by Nathan Sidwell Committed by Nathan Sidwell

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
parent 0f0b91be
2003-04-21 Nathan Sidwell <nathan@codesourcery.com>
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 <nathan@codesourcery.com> 2003-04-20 Nathan Sidwell <nathan@codesourcery.com>
* cp/decl2.c (start_static_storage_duration_function): Take count * cp/decl2.c (start_static_storage_duration_function): Take count
......
...@@ -4504,19 +4504,19 @@ build_unary_op (code, xarg, noconvert) ...@@ -4504,19 +4504,19 @@ build_unary_op (code, xarg, noconvert)
&& TREE_CODE (TREE_OPERAND (arg, 1)) == BASELINK) && TREE_CODE (TREE_OPERAND (arg, 1)) == BASELINK)
arg = BASELINK_FUNCTIONS (TREE_OPERAND (arg, 1)); arg = BASELINK_FUNCTIONS (TREE_OPERAND (arg, 1));
if (TREE_CODE (arg) == COMPONENT_REF if (TREE_CODE (arg) != COMPONENT_REF)
&& DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1))) 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'", error ("attempt to take address of bit-field structure member `%D'",
TREE_OPERAND (arg, 1)); TREE_OPERAND (arg, 1));
return error_mark_node; return error_mark_node;
} }
else if (TREE_CODE (arg) == COMPONENT_REF else
&& TREE_CODE (TREE_OPERAND (arg, 0)) == INDIRECT_REF
&& (TREE_CODE (TREE_OPERAND (TREE_OPERAND (arg, 0), 0))
== INTEGER_CST))
{ {
/* 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 field = TREE_OPERAND (arg, 1);
tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0); tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (rval)), tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (rval)),
...@@ -4529,8 +4529,6 @@ build_unary_op (code, xarg, noconvert) ...@@ -4529,8 +4529,6 @@ build_unary_op (code, xarg, noconvert)
addr = fold (build (PLUS_EXPR, argtype, rval, addr = fold (build (PLUS_EXPR, argtype, rval,
cp_convert (argtype, byte_position (field)))); cp_convert (argtype, byte_position (field))));
} }
else
addr = build_address (arg);
if (TREE_CODE (argtype) == POINTER_TYPE if (TREE_CODE (argtype) == POINTER_TYPE
&& TREE_CODE (TREE_TYPE (argtype)) == METHOD_TYPE) && TREE_CODE (TREE_TYPE (argtype)) == METHOD_TYPE)
...@@ -6578,15 +6576,14 @@ comp_ptr_ttypes_real (to, from, constp) ...@@ -6578,15 +6576,14 @@ comp_ptr_ttypes_real (to, from, constp)
} }
if (TREE_CODE (to) != POINTER_TYPE) if (TREE_CODE (to) != POINTER_TYPE)
return return ((constp >= 0 || to_more_cv_qualified)
same_type_ignoring_top_level_qualifiers_p (to, from) && same_type_ignoring_top_level_qualifiers_p (to, from));
&& (constp >= 0 || to_more_cv_qualified);
} }
} }
/* When comparing, say, char ** to char const **, this function takes the /* When comparing, say, char ** to char const **, this function takes
'char *' and 'char const *'. Do not pass non-pointer types to this the 'char *' and 'char const *'. Do not pass non-pointer/reference
function. */ types to this function. */
int int
comp_ptr_ttypes (to, from) comp_ptr_ttypes (to, from)
......
2003-04-19 Nathan Sidwell <nathan@codesourcery.com> 2003-04-21 Nathan Sidwell <nathan@codesourcery.com>
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 <nathan@codesourcery.com>
PR c++/10405 PR c++/10405
* g++.dg/lookup/struct-hack1.C: New test. * g++.dg/lookup/struct-hack1.C: New test.
......
// { dg-do run }
// Copyright (C) 2003 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 19 Apr 2003 <nathan@codesourcery.com>
// 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;
}
// { 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. // Copyright (C) 2002 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 8 Aug 2002 <nathan@codesourcery.com> // Contributed by Nathan Sidwell 8 Aug 2002 <nathan@codesourcery.com>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment