[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 sabre at nondot.org
Sat Jan 24 12:53:09 PST 2009


On Jan 24, 2009, at 12:43 PM, Eli Friedman wrote:

> On Sat, Jan 24, 2009 at 12:17 PM, Chris Lattner <sabre at nondot.org>  
> wrote:
>> +  // alignof decl is always ok.
>> +  if (isa<DeclRefExpr>(E))
>> +    return false;
>
> That looks wrong... what about something like the following?
>
> extern struct x a;
> int b = __alignof(a);
>
> Wait, actually, it appears that gcc accepts this?!
>
> 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 working on the ExprConstant code to better handle alignof.

-Chris



More information about the cfe-commits mailing list