This is the mail archive of the 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: [PATCH] [4.5 regression] C++ ignores some aligned attributes

On 08/04/2010 08:19 AM, Ulrich Weigand wrote:
Paul Brook wrote:

I'm not so sure. Consider the following example:

struct JSString
   unsigned char mLength;
   static  JSString unitStringTable[];

int var1 =__alignof__ (JSString::unitStringTable);

JSString JSString::unitStringTable[] __attribute__ ((aligned (8))) = { 1 };
int var2 =__alignof__ (JSString::unitStringTable);

int main()
   assert(var1 == var2);

Note that var1 may be in a separate file, and never see the additional

Should we be rejecting this mismatch, rather than papering over what looks
like user error?  If the packed attribute can reduce alignment then this is
going to cause havoc on STRICT_ALIGN targets.

Well, the only thing my patch does is to revert behavior back to what it was in 4.4 and earlier, after having been (clearly inadvertently) changed by an unrelated patch. At least Firefox relies on that behavior; Firefox builds would certainly break if we add the error you suggest ...

That said, I have no strong opinion on what the behavior *should* be in
the case of differing aligned attributes between declaration and definition.
(However, I would suggest to keep the behavior the same between C and C++
whereever that makes sense.)

In C++ 0x, the (presumably equivalent) alignof operator had better yield the same result across all translation units to preserve the ODR. Consider:

struct S { static int i; };

template <int> struct X { };
template <> struct X<alignof S::i> { enum { e }; };

int S::i [[align(sizeof (int) * 2)]];

int main() {
    return X<alignof S::i>::e;


Bye, Ulrich

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