This is an archive of the discontinued LLVM Phabricator instance.

[AST] Get aliased type info from an aliased TemplateSpecialization.
ClosedPublic

Authored by mattd on Nov 2 2018, 2:11 PM.

Details

Summary

Previously the TemplateSpecialization instance for 'template_alias', in the example below, returned the type info of the canonical type (int). This ignored the type alias if the template type happen to be aliased.

Before this patch, the assert would trigger with an alignment of 4:

typedef int __attribute__(( aligned( 16 ) )) aligned_int;
template < typename >
using template_alias = aligned_int;
static_assert( alignof( template_alias<void>) == 16, "" );

This patch checks if the TemplateSpecialization type has an alias, and if so will return the type information for the aliased type, else the canonical type's info is returned (original behavior). I believe that this is the desired behavior.

Diff Detail

Repository
rC Clang

Event Timeline

mattd created this revision.Nov 2 2018, 2:11 PM

Changing how TemplateSpecializationType is declared in TypeNodes.def has way more implications than you're giving it credit for.

FooType::desugar() should always perform a single-step desugar, but on TemplateSpecializationType it's calling getCanonicalTypeInternal(), which is clearly not a single-step desugar for a template alias. So I believe the fix here is as simple as just returning getAliasedType() from that method for template aliases.

mattd updated this revision to Diff 172503.Nov 3 2018, 2:03 PM

Thanks for the review @rjmccall. I have moved the type-alias check into TemplateSpecializationType's desugar method. I like this solution better.

That looks a lot better, thanks. Did you check whether any other tests needed adjustment? That's not uncommon from this kind of desugaring change.

If not, LGTM.

mattd added a comment.Nov 4 2018, 10:19 AM

That looks a lot better, thanks. Did you check whether any other tests needed adjustment? That's not uncommon from this kind of desugaring change.

If not, LGTM.

Thanks again. I ran the typical 'check-all' in my working tree which included clang, clang-extras, compiler-rt, lld. Everything passed as expected.

rjmccall accepted this revision.Nov 4 2018, 11:02 PM

Great!

This revision is now accepted and ready to land.Nov 4 2018, 11:02 PM
This revision was automatically updated to reflect the committed changes.