This looks like the right place to fix the bug.

Three comments:
- The '*' for pointer types should be on the right side.
- AlignedAttr::getMaxAlignment() isn't always super fast but I guess such
typedefs are rare.  An argument could be made that getTypeInfoImpl should
return a struct containing the size, alignment and whether or not the type
has an explicit alignment.  Then, getPreferredTypeAlign() could take
advantage of it.
- Both of your tests in CodeGen/alignment.c already pass without your patch.

-- 
David Majnemer


On Tue Feb 11 2014 at 8:31:12 AM, Stephan Tolksdorf <[email protected]> wrote:

> On 14-02-11 00:32, Stephan Tolksdorf wrote:
> > The result of alignof(T) is computed using 
> > ASTContext::getPreferredTypeAlign,
> which for certain types may return an alignment that is greater than the
> one computed by getTypeAlign. This patch teaches getPreferredTypeAlign not
> to change alignments specified with an aligned attribute on a typedef and
> thus allows the following test to compile:
> >
> > typedef long long T __attribute__((aligned(1));
> > static_assert(alignof(T) == 1, "");
> >
> > This patch does not affect the new test in CodeGen/alignment.c, but
> given the special handling of long long in getPreferredTypeAlign I thought
> it might be prudent to add a check for long long typedefs with an aligned
> attribute to the existing test for int typedefs.
>
> I've updated the patch to use getAs<> for the cast, as discussed on IRC.
>
> - Stephan
>
> _______________________________________________
> cfe-commits mailing list
> [email protected]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to