[PATCH] Make getPreferredTypeAlign respect alignments specified with an aligned attribute on a typedef

David Majnemer david.majnemer at gmail.com
Wed Feb 12 11:45:53 PST 2014


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 <st at quanttec.com> 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
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140212/b49a53bf/attachment.html>


More information about the cfe-commits mailing list