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

Chris Lattner clattner at apple.com
Sat Jan 24 13:14:34 PST 2009


On Jan 24, 2009, at 1:09 PM, Eli Friedman wrote:

> 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.

The basic issue is that you could have attribute align on the field  
decl (to get the actual value, which the constant folder needs but  
sema doesn't for validation).  You have to do some special processing  
in the expr case before looking at types.

>> 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);

I'll look into it, thanks Eli!

-Chris



More information about the cfe-commits mailing list