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]

Re: Fix 21166


Richard Henderson wrote:
On Fri, Apr 29, 2005 at 12:32:44PM +0100, Nathan Sidwell wrote:

So, it's a request to stor-layout to pack the field as close as
possible to its predecessor.  What should it mean after layout
is complete?  Should it mean
1) the user asked for this to be packed densely, or
2) this field is not necessarily aligned

Both 1 and 2, normally.
Damn, I didn't ask a specific enough question!  I was trying to
get mutually exclusive options :)

Now, if the structure is aligned for *other* reasons, e.g.

	template<typename T>
	struct S {
		int x __attribute__((packed));
		T y;
	};

This structure has alignment based on 'y'. We can, without changing
the meaning of the program, boost the alignment of 'x' back from 1 to that of 'y' (taking into account the offset of x, 0 in this case).

Agreed. We don't do that right now, do we? If we did, do you agree that DECL_PACKED (S::x) would then be cleared?

How does the case in 21166 differ from that case?  I don't think it
does. (Furthermore I think it more obviously broken, in that
packing the type is indistinguishable from not packing the type. Which
is in essence what the bug report was all about.)

Agreed.  I've always thought it completely unintuitive that plain
__attribute__((aligned(2))) is supposed to be ignored if the natural
alignment is greater than 2; you're supposed to use packed as well.
No argument here.  We have the funny situation where aligned(1) means
something different from packed.

Now, to get back to the actual patch, I think you're right, we should
look at TYPE_ALIGN, not DECL_ALIGN, because otherwise we'll go wrong
with
	int x __attribute__((packed,aligned(1)));
DECL_ALIGN will be 1 byte, but TYPE_ALIGN will be 4 bytes. And here
we do not want to clear DECL_PACKED.

ok with that change?  I'll figure out a test case to make sure
we DTRT with packed,aligned(1).

nathan

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


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