This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix 21166


Hi,
this patch fixes a C++ (and C) problem with packed structures.  A field
with a natural alignement of one byte, can't really be packed.  The problem
manifests in C++ in that it requires a copy constructor when taking a
reference to the packed field, and that's unnecessary in this case.

booted & tested on i686-pc-linux-gnu, ok?

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2005-04-28  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/21166
	* stor-layout.c (do_type_align): Undo packing, if the alignment is
	one unit.

Index: stor-layout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stor-layout.c,v
retrieving revision 1.229
diff -c -3 -p -r1.229 stor-layout.c
*** stor-layout.c	23 Apr 2005 21:27:51 -0000	1.229
--- stor-layout.c	28 Apr 2005 08:37:39 -0000
*************** do_type_align (tree type, tree decl)
*** 272,277 ****
--- 272,280 ----
        if (TREE_CODE (decl) == FIELD_DECL)
  	DECL_USER_ALIGN (decl) = TYPE_USER_ALIGN (type);
      }
+   /* If the alignment is one unit, then we're not really packed.  */
+   if (TREE_CODE (decl) == FIELD_DECL && DECL_ALIGN (decl) == BITS_PER_UNIT)
+     DECL_PACKED (decl) = 0;
  }
  
  /* Set the size, mode and alignment of a ..._DECL node.
// Copyright (C) 2005 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 26 Apr 2005 <nathan@codesourcery.com>

// DR21166. unnecessary error on packed char

struct s1 {
        char    c1;
} __attribute__((packed));

char&
f(struct s1 *s)
{
        return s->c1;
}

char *
g(struct s1 *s)
{
        return &s->c1;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]