This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fix 21166
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 10 May 2005 15:27:57 +0100
- Subject: Re: Fix 21166
- References: <4270A58A.3010704@codesourcery.com> <20050428224019.GC6294@redhat.com> <42721B5C.3000502@codesourcery.com> <20050429191025.GB9936@redhat.com> <4273AF72.6060500@codesourcery.com> <20050501035432.GB27933@redhat.com>
Richard Henderson wrote:
Gimme a new patch with exactly what you have in mind and I'll
try to poke holes in it.
ok, here's a new version. It takes advantage of your observation that
alignment might be constrained by something else in the struct.
I'm slightly uncomfortable, from a language abstractness POV, that the
packedness of one field can depend on the alignment constraints of another
field. But then, specifying packing puts us squarely in implementation
defined land.
booted & tested on i686-pc-linux-gnu.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2005-05-10 Nathan Sidwell <nathan@codesourcery.com>
* stor-layout.c (finalize_type_size): Undo DECL_PACKED when possible.
Index: stor-layout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stor-layout.c,v
retrieving revision 1.230
diff -c -3 -p -r1.230 stor-layout.c
*** stor-layout.c 27 Apr 2005 16:02:43 -0000 1.230
--- stor-layout.c 9 May 2005 13:16:34 -0000
*************** finalize_type_size (tree type)
*** 1404,1409 ****
--- 1404,1411 ----
void
finish_record_layout (record_layout_info rli, int free_p)
{
+ tree field;
+
/* Compute the final size. */
finalize_record_size (rli);
*************** finish_record_layout (record_layout_info
*** 1413,1418 ****
--- 1415,1429 ----
/* Perform any last tweaks to the TYPE_SIZE, etc. */
finalize_type_size (rli->t);
+ /* We might be able to clear DECL_PACKED on any members that happen
+ to be suitably aligned (not forgetting the alignment of the type
+ itself). */
+ for (field = TYPE_FIELDS (rli->t); field; field = TREE_CHAIN (field))
+ if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field)
+ && DECL_OFFSET_ALIGN (field) >= TYPE_ALIGN (TREE_TYPE (field))
+ && TYPE_ALIGN (rli->t) >= TYPE_ALIGN (TREE_TYPE (field)))
+ DECL_PACKED (field) = 0;
+
/* Lay out any static members. This is done now because their type
may use the record's type. */
while (rli->pending_statics)
// 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;
}