[PATCH] D54048: [AST] Get aliased type info from an aliased TemplateSpecialization.

Matt Davis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 2 14:11:48 PDT 2018


mattd created this revision.
mattd added reviewers: aaron.ballman, rjmccall.

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.


https://reviews.llvm.org/D54048

Files:
  include/clang/AST/TypeNodes.def
  lib/AST/ASTContext.cpp
  lib/AST/Type.cpp
  test/SemaCXX/alignof.cpp


Index: test/SemaCXX/alignof.cpp
===================================================================
--- test/SemaCXX/alignof.cpp
+++ test/SemaCXX/alignof.cpp
@@ -97,3 +97,8 @@
   typedef __attribute__((aligned(N))) int Field[sizeof(N)]; // expected-error {{requested alignment is dependent but declaration is not dependent}}
 };
 }
+
+typedef int __attribute__(( aligned( 16 ) )) aligned_int;
+template < typename >
+using template_alias = aligned_int;
+static_assert( alignof( template_alias<void>) == 16, "alignof(template_alias<>) is incorrect" );
Index: lib/AST/Type.cpp
===================================================================
--- lib/AST/Type.cpp
+++ lib/AST/Type.cpp
@@ -3481,6 +3481,7 @@
 
   case Type::Auto:
   case Type::DeducedTemplateSpecialization:
+  case Type::TemplateSpecialization:
     // Give non-deduced 'auto' types external linkage. We should only see them
     // here in error recovery.
     return CachedProperties(ExternalLinkage, false);
@@ -3587,6 +3588,7 @@
 
   case Type::Auto:
   case Type::DeducedTemplateSpecialization:
+  case Type::TemplateSpecialization:
     return LinkageInfo::external();
 
   case Type::Record:
Index: lib/AST/ASTContext.cpp
===================================================================
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -1990,6 +1990,12 @@
     return getTypeInfo(A->getDeducedType().getTypePtr());
   }
 
+  case Type::TemplateSpecialization: {
+    const auto *TS = cast<TemplateSpecializationType>(T);
+    return TS->isTypeAlias() ? getTypeInfo(TS->getAliasedType().getTypePtr())
+                             : getTypeInfo(TS->desugar().getTypePtr());
+  }
+
   case Type::Paren:
     return getTypeInfo(cast<ParenType>(T)->getInnerType().getTypePtr());
 
@@ -6926,6 +6932,7 @@
   // We could see an undeduced auto type here during error recovery.
   // Just ignore it.
   case Type::Auto:
+  case Type::TemplateSpecialization:
   case Type::DeducedTemplateSpecialization:
     return;
 
@@ -8738,6 +8745,7 @@
     llvm_unreachable("Non-canonical and dependent types shouldn't get here");
 
   case Type::Auto:
+  case Type::TemplateSpecialization:
   case Type::DeducedTemplateSpecialization:
   case Type::LValueReference:
   case Type::RValueReference:
Index: include/clang/AST/TypeNodes.def
===================================================================
--- include/clang/AST/TypeNodes.def
+++ include/clang/AST/TypeNodes.def
@@ -97,7 +97,7 @@
 DEPENDENT_TYPE(TemplateTypeParm, Type)
 NON_CANONICAL_TYPE(SubstTemplateTypeParm, Type)
 DEPENDENT_TYPE(SubstTemplateTypeParmPack, Type)
-NON_CANONICAL_UNLESS_DEPENDENT_TYPE(TemplateSpecialization, Type)
+TYPE(TemplateSpecialization, Type)
 ABSTRACT_TYPE(Deduced, Type)
 TYPE(Auto, DeducedType)
 TYPE(DeducedTemplateSpecialization, DeducedType)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54048.172427.patch
Type: text/x-patch
Size: 2805 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181102/3292e2fb/attachment.bin>


More information about the cfe-commits mailing list