[cfe-commits] r62928 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/Sema.h lib/Sema/SemaExpr.cpp test/Sema/exprs.c

Eli Friedman eli.friedman at gmail.com
Sat Jan 24 13:09:06 PST 2009


On Sat, Jan 24, 2009 at 12:53 PM, Chris Lattner <sabre at nondot.org> wrote:
>> Conceptually, it seems like a better fix for PR3386 would be adding
>> something like "if (!isSizeof && exprType->isIncompleteArrayType())
>> exprType = exprType->getAsArrayType()->getElementType();" at the
>> beginning of CheckSizeOfAlignOfOperand.
>
> unfortunately, that's not what GCC does.  GCC allows alignof on any decl
> (except bitfield), and takes the alignment of the decl.  This means that if
> you use attribute(align) it should affect alignof.

I'm not quite following why my solution doesn't work here?  This isn't
the evaluation code, just validity checking.  And it might be nice to
accept stuff like "__alignof__(int[])"; I'm not really sure why gcc
rejects it.

> I'm working on the ExprConstant code to better handle alignof.

Okay, cool.  As an extension to what I was mentioning before, if we're
going to accept it, you had better watch out for the following
testcase:
extern struct x a;
int b = __alignof(a);
struct x {int x;};

Oh, and on a related note, it appears we don't reject the following:
struct x {int x : 5;} z;
int b = sizeof(z.x);

-Eli



More information about the cfe-commits mailing list