This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[c++ patch] packed fields
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org, mark at codesourcery dot com
- Date: Thu, 08 Aug 2002 16:02:00 +0100
- Subject: [c++ patch] packed fields
- Organization: Codesourcery LLC
Hi,
this fixes a code generation problem with accessing packed
fields. We lost information about the unalignedness of the
field, leading to bus errors on architectures where it is
important.
built & tested on sparc-sun-solaris2.8, ok?
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2002-08-07 Nathan Sidwell <nathan@codesourcery.com>
* typeck.c (build_component_addr): Remove.
(build_unary_op): Just check it's not a bitfield, and then build
an ADDR_EXPR.
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.413
diff -c -3 -p -r1.413 typeck.c
*** cp/typeck.c 26 Jul 2002 20:10:43 -0000 1.413
--- cp/typeck.c 1 Aug 2002 11:40:36 -0000
*************** static int comp_array_types PARAMS ((int
*** 57,63 ****
static tree common_base_type PARAMS ((tree, tree));
static tree lookup_anon_field PARAMS ((tree, tree));
static tree pointer_diff PARAMS ((tree, tree, tree));
- static tree build_component_addr PARAMS ((tree, tree));
static tree qualify_type_recursive PARAMS ((tree, tree));
static tree get_delta_difference PARAMS ((tree, tree, int));
static int comp_cv_target_types PARAMS ((tree, tree, int));
--- 57,62 ----
*************** pointer_diff (op0, op1, ptrtype)
*** 4019,4068 ****
return folded;
}
- /* Handle the case of taking the address of a COMPONENT_REF.
- Called by `build_unary_op'.
-
- ARG is the COMPONENT_REF whose address we want.
- ARGTYPE is the pointer type that this address should have. */
-
- static tree
- build_component_addr (arg, argtype)
- tree arg, argtype;
- {
- tree field = TREE_OPERAND (arg, 1);
- tree basetype = decl_type_context (field);
- tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
-
- my_friendly_assert (TREE_CODE (field) == FIELD_DECL, 981018);
-
- if (DECL_C_BIT_FIELD (field))
- {
- error ("attempt to take address of bit-field structure member `%D'",
- field);
- return error_mark_node;
- }
-
- if (TREE_CODE (field) == FIELD_DECL
- && TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (basetype))
- {
- /* Can't convert directly to ARGTYPE, since that
- may have the same pointer type as one of our
- baseclasses. */
- tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (rval)), basetype,
- ba_check, NULL);
-
- rval = build_base_path (PLUS_EXPR, rval, binfo, 1);
- rval = build1 (NOP_EXPR, argtype, rval);
- TREE_CONSTANT (rval) = TREE_CONSTANT (TREE_OPERAND (rval, 0));
- }
- else
- /* This conversion is harmless. */
- rval = convert_force (argtype, rval, 0);
-
- return fold (build (PLUS_EXPR, argtype, rval,
- cp_convert (argtype, byte_position (field))));
- }
-
/* Construct and perhaps optimize a tree representation
for a unary operation. CODE, a tree_code, specifies the operation
and XARG is the operand. */
--- 4018,4023 ----
*************** build_unary_op (code, xarg, noconvert)
*** 4549,4556 ****
{
tree addr;
! if (TREE_CODE (arg) == COMPONENT_REF)
! addr = build_component_addr (arg, argtype);
else
addr = build1 (ADDR_EXPR, argtype, arg);
--- 4504,4516 ----
{
tree addr;
! if (TREE_CODE (arg) == COMPONENT_REF
! && 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
addr = build1 (ADDR_EXPR, argtype, arg);
// { dg-do run }
// Copyright (C) 2002 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 8 Aug 2002 <nathan@codesourcery.com>
// WRS SPR 63496, lost packed attribute when accessing a packed
// field. This matters on aligned architectures like sh
struct thing { int m; };
struct pod {char a; thing m __attribute__ ((packed)); };
int main ()
{
thing t;
pod p;
p.m = t; /* runtime bus error here */
return 0;
};