瀏覽代碼

[template] Support empty template arg list on TypeAliasTemplateDecl. (#5114)

* [template] Support empty template arg list on TypeAliasTemplateDecl.

This is to help add sperate type for row major and column major matrix.

The issue is only support ClassTemplateSpecializationDecl in getHLSLDefaultSpecialization.
It cause compile error on t22 in following shader.

  template<typename T=float, int i=0>
  struct test {
    T d;
  };

  template<typename T=float>
  using test2 = test<T, 1>;

  test2 t22;

The fix is using Sema::CheckTemplateIdType to generate the default specialization for all TemplateDecl.
Xiang Li 2 年之前
父節點
當前提交
02d4922aa5

+ 1 - 2
tools/clang/include/clang/Sema/Sema.h

@@ -9078,8 +9078,7 @@ public:
   // HLSL Change Begin - adjust this from T* to T&-like
   CXXThisExpr *genereateHLSLThis(SourceLocation Loc, QualType ThisType,
                                 bool isImplicit);
-  ClassTemplateSpecializationDecl *
-  getHLSLDefaultSpecialization(ClassTemplateDecl *Decl);
+  QualType getHLSLDefaultSpecialization(TemplateDecl *Decl);
   // HLSL Change End - adjust this from T* to T&-like
 };
 

+ 5 - 3
tools/clang/lib/Sema/SemaDecl.cpp

@@ -447,9 +447,11 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
     if (!HasTrailingDot)
       T = Context.getObjCInterfaceType(IDecl);
   } else if (getLangOpts().HLSL) { // HLSL - omit empty template argument lists
-    if (ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(IIDecl))
-      if (TypeDecl *DefaultSpec = getHLSLDefaultSpecialization(TD))
-        T = Context.getTypeDeclType(DefaultSpec); // HLSL Change end
+    if (TemplateDecl *TD = dyn_cast<TemplateDecl>(IIDecl)) {
+      QualType DefaultTy = getHLSLDefaultSpecialization(TD);
+      if (!DefaultTy.isNull())
+        T = DefaultTy;
+    } // HLSL Change end
   }
 
   if (T.isNull()) {

+ 6 - 21
tools/clang/lib/Sema/SemaHLSL.cpp

@@ -7834,6 +7834,7 @@ bool HLSLExternalSource::IsTypeNumeric(QualType type, UINT* count)
     *count = GetElementCount(type);
     return IsBasicKindNumeric(GetTypeElementKind(type));
   case AR_TOBJ_OBJECT:
+  case AR_TOBJ_DEPENDENT:
   case AR_TOBJ_STRING:
     return false;
   }
@@ -14072,29 +14073,13 @@ clang::QualType ApplyTypeSpecSignToParsedType(
     return HLSLExternalSource::FromSema(self)->ApplyTypeSpecSignToParsedType(type, TSS, Loc);
 }
 
-ClassTemplateSpecializationDecl *
-Sema::getHLSLDefaultSpecialization(ClassTemplateDecl *Decl) {
+QualType Sema::getHLSLDefaultSpecialization(TemplateDecl *Decl) {
   if (Decl->getTemplateParameters()->getMinRequiredArguments() == 0) {
-    void *InsertPos = nullptr;
     TemplateArgumentListInfo EmptyArgs;
     EmptyArgs.setLAngleLoc(Decl->getSourceRange().getEnd());
     EmptyArgs.setRAngleLoc(Decl->getSourceRange().getEnd());
-    SmallVector<TemplateArgument, 2> Converted;
-    if (!CheckTemplateArgumentList(Decl, Decl->getSourceRange().getEnd(), EmptyArgs,
-                                   false, Converted)) {
-      ClassTemplateSpecializationDecl *DefaultSpec =
-          Decl->findSpecialization(Converted, InsertPos);
-      if (!DefaultSpec) {
-        DefaultSpec = ClassTemplateSpecializationDecl::Create(
-            getASTContext(), TagDecl::TagKind::TTK_Class,
-            getASTContext().getTranslationUnitDecl(), SourceLocation(),
-            SourceLocation(), Decl, Converted.data(), Converted.size(),
-            DefaultSpec);
-        Decl->AddSpecialization(DefaultSpec, InsertPos);
-        DefaultSpec->setImplicit(true);
-      }
-      return DefaultSpec;
-    }
-  }
-  return nullptr;
+    return CheckTemplateIdType(TemplateName(Decl),
+                               Decl->getSourceRange().getEnd(), EmptyArgs);
+  }
+  return QualType();
 }

+ 3 - 6
tools/clang/lib/Sema/SemaTemplate.cpp

@@ -3056,12 +3056,9 @@ bool Sema::CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
     // HLSL allows omiting empty template argument lists
     TemplateDecl *Decl = Name.getAsTemplateDecl();
     if (getLangOpts().HLSL && Decl) {
-      if (ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(Decl)) {
-        if (TypeDecl *DefaultSpec = getHLSLDefaultSpecialization(TD)) {
-          SourceRange SR = Decl->getSourceRange();
-          TemplateArgumentListInfo TemplateArgs(SR.getEnd(), SR.getEnd());
-          ArgType = CheckTemplateIdType(TemplateName(Decl), SR.getBegin(),
-                                        TemplateArgs);
+      if (TemplateDecl *TD = dyn_cast<TemplateDecl>(Decl)) {
+        ArgType = getHLSLDefaultSpecialization(TD);
+        if (!ArgType.isNull()) {
           CXXScopeSpec SS;
           TypeLocBuilder TLB;
           TemplateSpecializationTypeLoc TL =

+ 2 - 2
tools/clang/test/CodeGenSPIRV/decoration.user-type.hlsl

@@ -47,9 +47,9 @@ RWBuffer<float> t;
 Texture2DMSArray<float4, 64> u;
 // CHECK: OpDecorateString %v UserTypeGOOGLE "texture2dmsarray:<float4,64>"
 const Texture2DMSArray<float4, 64> v;
-// CHECK: OpDecorateString %t1 UserTypeGOOGLE "texture1d:<vector<float,4> >"
+// CHECK: OpDecorateString %t1 UserTypeGOOGLE "texture1d"
 Texture1D t1;
-// CHECK: OpDecorateString %t2 UserTypeGOOGLE "texture2d:<vector<float,4> >"
+// CHECK: OpDecorateString %t2 UserTypeGOOGLE "texture2d"
 Texture2D t2;
 
 // CHECK: OpDecorateString %eArr UserTypeGOOGLE "texture1d:<float>"

+ 3 - 3
tools/clang/test/HLSL/conversions-non-numeric-aggregates.hlsl

@@ -7,13 +7,13 @@ struct ObjStruct { Buffer a; };
 
 void main()
 {
-  (Buffer[1])0; /* expected-error {{cannot convert from 'literal int' to 'Buffer<vector<float, 4> > [1]'}} fxc-error {{X3017: cannot convert from 'int' to 'Buffer<float4>[1]'}} */
+  (Buffer[1])0; /* expected-error {{cannot convert from 'literal int' to 'Buffer [1]'}} fxc-error {{X3017: cannot convert from 'int' to 'Buffer<float4>[1]'}} */
   (ObjStruct)0; /* expected-error {{cannot convert from 'literal int' to 'ObjStruct'}} fxc-error {{X3017: cannot convert from 'int' to 'struct ObjStruct'}} */
-  (Buffer[1])(int[1])0; /* expected-error {{cannot convert from 'int [1]' to 'Buffer<vector<float, 4> > [1]'}} fxc-error {{X3017: cannot convert from 'const int[1]' to 'Buffer<float4>[1]'}} */
+  (Buffer[1])(int[1])0; /* expected-error {{cannot convert from 'int [1]' to 'Buffer [1]'}} fxc-error {{X3017: cannot convert from 'const int[1]' to 'Buffer<float4>[1]'}} */
   (ObjStruct)(NumStruct)0; /* expected-error {{cannot convert from 'NumStruct' to 'ObjStruct'}} fxc-error {{X3017: cannot convert from 'const struct NumStruct' to 'struct ObjStruct'}} */
 
   Buffer oa1[1];
   ObjStruct os1;
-  (int)oa1; /* expected-error {{cannot convert from 'Buffer<vector<float, 4> > [1]' to 'int'}} fxc-error {{X3017: cannot convert from 'Buffer<float4>[1]' to 'int'}} */
+  (int)oa1; /* expected-error {{cannot convert from 'Buffer [1]' to 'int'}} fxc-error {{X3017: cannot convert from 'Buffer<float4>[1]' to 'int'}} */
   (int)os1; /* expected-error {{cannot convert from 'ObjStruct' to 'int'}} fxc-error {{X3017: cannot convert from 'struct ObjStruct' to 'int'}} */
 }

+ 18 - 18
tools/clang/test/HLSL/indexing-operator.hlsl

@@ -127,21 +127,21 @@ float4 test_scalar_indexing()
           `-IntegerLiteral <col:14> 'literal int' 0
   */
   // fxc error X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
-  f4 += g_t1da[0]; // expected-error {{no viable overloaded operator[] for type 'Texture1DArray<vector<float, 4> >'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'literal int' to 'vector<uint, 2>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
+  f4 += g_t1da[0]; // expected-error {{no viable overloaded operator[] for type 'Texture1DArray'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'literal int' to 'vector<uint, 2>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   // fxc error X3120 : invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
-  f4 += g_t2d[0]; // expected-error {{no viable overloaded operator[] for type 'Texture2D<vector<float, 4> >'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'literal int' to 'vector<uint, 2>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
+  f4 += g_t2d[0]; // expected-error {{no viable overloaded operator[] for type 'Texture2D'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'literal int' to 'vector<uint, 2>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   // fxc error X3120 : invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
-  f4 += g_t2da[0]; // expected-error {{no viable overloaded operator[] for type 'Texture2DArray<vector<float, 4> >'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'literal int' to 'vector<uint, 3>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
+  f4 += g_t2da[0]; // expected-error {{no viable overloaded operator[] for type 'Texture2DArray'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'literal int' to 'vector<uint, 3>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   // fxc error X3120 : invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
   f4 += g_t2dms[0]; // expected-error {{no viable overloaded operator[] for type 'Texture2DMS<float4, 8>'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'literal int' to 'vector<uint, 2>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   // fxc error X3120 : invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
   f4 += g_t2dmsa[0]; // expected-error {{no viable overloaded operator[] for type 'Texture2DMSArray<float4, 8>'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'literal int' to 'vector<uint, 3>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   // fxc error X3120 : invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
-  f4 += g_t3d[0]; // expected-error {{no viable overloaded operator[] for type 'Texture3D<vector<float, 4> >'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'literal int' to 'vector<uint, 3>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
+  f4 += g_t3d[0]; // expected-error {{no viable overloaded operator[] for type 'Texture3D'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'literal int' to 'vector<uint, 3>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   // fxc  error X3121: array, matrix, vector, or indexable object type expected in index expression
-  f4 += g_tc[0]; // expected-error {{type 'TextureCube<vector<float, 4> >' does not provide a subscript operator}} fxc-error {{X3121: array, matrix, vector, or indexable object type expected in index expression}}
+  f4 += g_tc[0]; // expected-error {{type 'TextureCube' does not provide a subscript operator}} fxc-error {{X3121: array, matrix, vector, or indexable object type expected in index expression}}
   // fxc  error X3121: array, matrix, vector, or indexable object type expected in index expression
-  f4 += g_tca[0]; // expected-error {{type 'TextureCubeArray<vector<float, 4> >' does not provide a subscript operator}} fxc-error {{X3121: array, matrix, vector, or indexable object type expected in index expression}}
+  f4 += g_tca[0]; // expected-error {{type 'TextureCubeArray' does not provide a subscript operator}} fxc-error {{X3121: array, matrix, vector, or indexable object type expected in index expression}}
 
   g_b[0] = f4;          /* expected-error {{cannot assign to return value because function 'operator[]<const vector<float, 4> &>' returns a const value}} fxc-error {{X3025: l-value specifies const object}} */
   g_t1d[0] = f4;        /* expected-error {{cannot assign to return value because function 'operator[]<const vector<float, 4> &>' returns a const value}} fxc-error {{X3025: l-value specifies const object}} */
@@ -199,9 +199,9 @@ float4 test_vector2_indexing()
   int2 offset = { 1, 2 };
   float4 f4 = 0;
   // fxc error X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
-  f4 += g_b[offset]; // expected-error {{no viable overloaded operator[] for type 'Buffer<vector<float, 4> >'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'int2' to 'unsigned int' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
+  f4 += g_b[offset]; // expected-error {{no viable overloaded operator[] for type 'Buffer'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'int2' to 'unsigned int' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   // fxc error X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
-  f4 += g_t1d[offset]; // expected-error {{no viable overloaded operator[] for type 'Texture1D<vector<float, 4> >'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'int2' to 'unsigned int' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
+  f4 += g_t1d[offset]; // expected-error {{no viable overloaded operator[] for type 'Texture1D'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'int2' to 'unsigned int' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   // fxc error X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
   f4 += g_sb[offset]; // expected-error {{no viable overloaded operator[] for type 'StructuredBuffer<float4>'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'int2' to 'unsigned int' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   f4 += g_t1da[offset];
@@ -233,16 +233,16 @@ float4 test_vector2_indexing()
             `-DeclRefExpr <col:15> 'int2':'vector<int, 2>' lvalue Var 'offset' 'int2':'vector<int, 2>'
   */
   // fxc error X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
-  f4 += g_t2da[offset]; // expected-error {{no viable overloaded operator[] for type 'Texture2DArray<vector<float, 4> >'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'vector<int, 2>' to 'vector<uint, 3>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
+  f4 += g_t2da[offset]; // expected-error {{no viable overloaded operator[] for type 'Texture2DArray'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'vector<int, 2>' to 'vector<uint, 3>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   f4 += g_t2dms[offset];
   // fxc error X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
   f4 += g_t2dmsa[offset]; // expected-error {{no viable overloaded operator[] for type 'Texture2DMSArray<float4, 8>'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'vector<int, 2>' to 'vector<uint, 3>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   // fxc error X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
-  f4 += g_t3d[offset]; // expected-error {{no viable overloaded operator[] for type 'Texture3D<vector<float, 4> >'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'vector<int, 2>' to 'vector<uint, 3>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
+  f4 += g_t3d[offset]; // expected-error {{no viable overloaded operator[] for type 'Texture3D'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'vector<int, 2>' to 'vector<uint, 3>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   // fxc error X3121: array, matrix, vector, or indexable object type expected in index expression
-  f4 += g_tc[offset]; // expected-error {{type 'TextureCube<vector<float, 4> >' does not provide a subscript operator}} fxc-error {{X3121: array, matrix, vector, or indexable object type expected in index expression}}
+  f4 += g_tc[offset]; // expected-error {{type 'TextureCube' does not provide a subscript operator}} fxc-error {{X3121: array, matrix, vector, or indexable object type expected in index expression}}
   // fxc error X3121: array, matrix, vector, or indexable object type expected in index expression
-  f4 += g_tca[offset]; // expected-error {{type 'TextureCubeArray<vector<float, 4> >' does not provide a subscript operator}} fxc-error {{X3121: array, matrix, vector, or indexable object type expected in index expression}}
+  f4 += g_tca[offset]; // expected-error {{type 'TextureCubeArray' does not provide a subscript operator}} fxc-error {{X3121: array, matrix, vector, or indexable object type expected in index expression}}
 
   g_t1da[offset] = f4;    /* expected-error {{cannot assign to return value because function 'operator[]<const vector<float, 4> &>' returns a const value}} fxc-error {{X3025: l-value specifies const object}} */
   g_t2d[offset] = f4;     /* expected-error {{cannot assign to return value because function 'operator[]<const vector<float, 4> &>' returns a const value}} fxc-error {{X3025: l-value specifies const object}} */
@@ -290,15 +290,15 @@ float4 test_vector3_indexing()
   int3 offset = { 1, 2, 3 };
   float4 f4 = 0;
   // fxc error X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
-  f4 += g_b[offset]; // expected-error {{no viable overloaded operator[] for type 'Buffer<vector<float, 4> >'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'int3' to 'unsigned int' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
+  f4 += g_b[offset]; // expected-error {{no viable overloaded operator[] for type 'Buffer'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'int3' to 'unsigned int' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   // fxc error X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
-  f4 += g_t1d[offset]; // expected-error {{no viable overloaded operator[] for type 'Texture1D<vector<float, 4> >'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'int3' to 'unsigned int' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
+  f4 += g_t1d[offset]; // expected-error {{no viable overloaded operator[] for type 'Texture1D'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'int3' to 'unsigned int' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   // fxc error X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
   f4 += g_sb[offset]; // expected-error {{no viable overloaded operator[] for type 'StructuredBuffer<float4>'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'int3' to 'unsigned int' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   // fxc error X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
-  f4 += g_t1da[offset]; // expected-error {{no viable overloaded operator[] for type 'Texture1DArray<vector<float, 4> >'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'vector<int, 3>' to 'vector<uint, 2>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
+  f4 += g_t1da[offset]; // expected-error {{no viable overloaded operator[] for type 'Texture1DArray'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'vector<int, 3>' to 'vector<uint, 2>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   // fxc error X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions
-  f4 += g_t2d[offset]; // expected-error {{no viable overloaded operator[] for type 'Texture2D<vector<float, 4> >'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'vector<int, 3>' to 'vector<uint, 2>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
+  f4 += g_t2d[offset]; // expected-error {{no viable overloaded operator[] for type 'Texture2D'}} expected-note {{candidate function [with element = const vector<float, 4> &] not viable: no known conversion from 'vector<int, 3>' to 'vector<uint, 2>' for 1st argument}} fxc-error {{X3120: invalid type for index - index must be a scalar, or a vector with the correct number of dimensions}}
   f4 += g_t2da[offset];
   /*verify-ast
     CompoundAssignOperator <col:3, col:22> 'float4':'vector<float, 4>' lvalue '+=' ComputeLHSTy='float4':'vector<float, 4>' ComputeResultTy='float4':'vector<float, 4>'
@@ -344,9 +344,9 @@ float4 test_vector3_indexing()
             `-DeclRefExpr <col:15> 'int3':'vector<int, 3>' lvalue Var 'offset' 'int3':'vector<int, 3>'
   */
   // fxc error X3121: array, matrix, vector, or indexable object type expected in index expression
-  f4 += g_tc[offset]; // expected-error {{type 'TextureCube<vector<float, 4> >' does not provide a subscript operator}} fxc-error {{X3121: array, matrix, vector, or indexable object type expected in index expression}}
+  f4 += g_tc[offset]; // expected-error {{type 'TextureCube' does not provide a subscript operator}} fxc-error {{X3121: array, matrix, vector, or indexable object type expected in index expression}}
   // fxc error X3121: array, matrix, vector, or indexable object type expected in index expression
-  f4 += g_tca[offset]; // expected-error {{type 'TextureCubeArray<vector<float, 4> >' does not provide a subscript operator}} fxc-error {{X3121: array, matrix, vector, or indexable object type expected in index expression}}
+  f4 += g_tca[offset]; // expected-error {{type 'TextureCubeArray' does not provide a subscript operator}} fxc-error {{X3121: array, matrix, vector, or indexable object type expected in index expression}}
 
   g_t2da[offset] = f4;      /* expected-error {{cannot assign to return value because function 'operator[]<const vector<float, 4> &>' returns a const value}} fxc-error {{X3025: l-value specifies const object}} */
   g_t2dmsa[offset] = f4;    /* expected-error {{cannot assign to return value because function 'operator[]<const vector<float, 4> &>' returns a const value}} fxc-error {{X3025: l-value specifies const object}} */

+ 1 - 1
tools/clang/test/HLSL/rewriter/correct_rewrites/matrix-syntax_gold.hlsl

@@ -1,5 +1,5 @@
 // Rewrite unchanged result:
-const matrix<float, 4, 4> m;
+const matrix m;
 void abs_without_using_result() {
   matrix<float, 4, 4> mymatrix;
   abs(mymatrix);

+ 1 - 1
tools/clang/test/HLSL/sizeof.hlsl

@@ -25,7 +25,7 @@ void main()
   sizeof 42; // expected-error {{invalid application of 'sizeof' to literal type 'literal int'}}
   sizeof 42.0; // expected-error {{invalid application of 'sizeof' to literal type 'literal float'}}
   sizeof ""; // expected-error {{invalid application of 'sizeof' to non-numeric type 'literal string'}}
-  sizeof(Buffer); // expected-error {{invalid application of 'sizeof' to non-numeric type 'Buffer<vector<float, 4> >'}}
+  sizeof(Buffer); // expected-error {{invalid application of 'sizeof' to non-numeric type 'Buffer'}}
   sizeof(StructWithResource); // expected-error {{invalid application of 'sizeof' to non-numeric type 'StructWithResource'}}
   sizeof(main); // expected-error {{invalid application of 'sizeof' to non-numeric type 'void ()'}}
 }

+ 5 - 1
tools/clang/test/HLSLFileCheck/hlsl/template/OmitDefaulted.hlsl

@@ -1,6 +1,10 @@
 // RUN: %dxc -E main -T ps_6_0 %s -ast-dump | FileCheck %s
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s -check-prefix=IR
 
-// CHECK: VarDecl {{0x[0-9a-fA-F]+}} {{<.*>}} col:14 used Tex 'Texture2D<vector<float, 4> >'
+// CHECK: VarDecl {{0x[0-9a-fA-F]+}} {{<.*>}} col:14 used Tex 'Texture2D':'Texture2D<vector<float, 4> >'
+
+// IR: !{i32 0, %"class.Texture2D<vector<float, 4> >"* undef, !"Tex", i32 0, i32 0, i32 1, i32 2, i32 0, ![[EXTRA:[0-9]+]]}
+// IR: ![[EXTRA]] = !{i32 0, i32 9}
 
 Texture2D    Tex;
 SamplerState Samp;

+ 13 - 4
tools/clang/test/HLSLFileCheck/hlsl/template/complete-array-parameter.hlsl

@@ -1,8 +1,17 @@
 // RUN: %dxc -T lib_6_3 -ast-dump %s | FileCheck %s
-
+// RUN: %dxc -T lib_6_3 %s | FileCheck %s -check-prefix=IR
 float4 Val(Texture2D f[2]) {
-  return float4(0,0,0,0);
+  return float4(0,0,0,0) + f[0].Load(0);
 }
 
-// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}, line:5:1> line:3:8 Val 'float4 (Texture2D<vector<float, 4> > [2])'
-// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <col:12, col:25> col:22 f 'Texture2D<vector<float, 4> > [2]'
+Texture2D a[2];
+
+export float foo() {
+  return Val(a);
+}
+
+// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}, line:5:1> line:3:8 used Val 'float4 (Texture2D [2])'
+// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <col:12, col:25> col:22 used f 'Texture2D [2]'
+
+// IR:!{i32 0, [2 x %"class.Texture2D<vector<float, 4> >"]* @"\01?a@@3PAV?$Texture2D@V?$vector@M$03@@@@A", !"a", i32 -1, i32 -1, i32 2, i32 2, i32 0, ![[EXTRA:[0-9]+]]}
+// IR:![[EXTRA]] = !{i32 0, i32 9}

+ 76 - 0
tools/clang/test/HLSLFileCheck/hlsl/template/template_alias_empty_arg.hlsl

@@ -0,0 +1,76 @@
+// RUN: %dxc  -T lib_6_3 %s -ast-dump -HV 2021 | FileCheck %s
+// RUN: %dxc  -T lib_6_3 %s  -HV 2021 | FileCheck %s -check-prefix=IR
+
+// CHECK: ClassTemplateDecl 0x{{.*}} test
+// CHECK-NEXT: TemplateTypeParmDecl 0x{{.*}} referenced typename T
+// CHECK-NEXT: -TemplateArgument type 'float'
+// CHECK-NEXT: NonTypeTemplateParmDecl 0x{{.*}} 'int' i
+// CHECK-NEXT: TemplateArgument expr
+// CHECK-NEXT: ImplicitCastExpr 0x{{.*}} 'int' <IntegralCast>
+// CHECK-NEXT: IntegerLiteral 0x{{.*}} 'literal int' 0
+// CHECK-NEXT: CXXRecordDecl 0x{{.*}} struct test definition
+// CHECK-NEXT: CXXRecordDecl 0x{{.*}} implicit struct test
+// CHECK-NEXT: FieldDecl 0x{{.*}} d 'T'
+// CHECK-NEXT: ClassTemplateSpecializationDecl 0x[[test_CTSD0:[0-9a-f]+]] {{.*}} struct test definition
+// CHECK-NEXT: TemplateArgument type 'float'
+// CHECK-NEXT: TemplateArgument integral 1
+// CHECK-NEXT: CXXRecordDecl 0x{{[0-9a-f]+}} prev 0x[[test_CTSD0]] {{.*}} implicit struct test
+// CHECK-NEXT: FieldDecl 0x[[field_d:[0-9a-f]+]] {{.*}} referenced d 'float':'float'
+
+template<typename T=float, int i=0>
+struct test {
+  T d;
+};
+
+// CHECK: TypeAliasTemplateDecl 0x{{.*}} test2
+// CHECK-NEXT: TemplateTypeParmDecl 0x{{.*}} referenced typename T
+// CHECK-NEXT: TemplateArgument type 'float'
+// CHECK-NEXT: TypeAliasDecl 0x{{.*}} test2 'test<T, 1>'
+template<typename T=float>
+using test2 = test<T, 1>;
+
+// CHECK: VarDecl 0x[[t22:[0-9a-f]+]] {{.*}} used t22 'test2':'test<float, 1>'
+test2 t22;
+
+// CHECK: ClassTemplateDecl 0x{{.*}} test3
+// CHECK-NEXT: TemplateTypeParmDecl 0x{{.*}} referenced typename T
+// CHECK-NEXT: CXXRecordDecl 0x{{.*}} struct test3 definition
+// CHECK-NEXT: CXXRecordDecl 0x{{.*}} implicit struct test3
+// CHECK-NEXT: FieldDecl 0x{{.*}} d 'T'
+// CHECK-NEXT: ClassTemplateSpecializationDecl 0x[[test3_CTSD0:[0-9a-f]+]] {{.*}} struct test3 definition
+// CHECK-NEXT: TemplateArgument type 'test<float, 1>'
+// CHECK-NEXT: CXXRecordDecl 0x{{.*}} prev 0x[[test3_CTSD0]] {{.*}} implicit struct test3
+// CHECK-NEXT: FieldDecl 0x[[test3_d:[0-9a-f]+]] {{.*}} referenced d 'test<float, 1>':'test<float, 1>'
+
+template<typename T>
+struct test3 {
+  T d;
+};
+
+// CHECK: VarDecl 0x[[tt:[0-9a-f]+]] {{.*}} used tt 'test3<test2>':'test3<test<float, 1> >'
+test3<test2>  tt;
+
+// CHECK: FunctionDecl 0x{{.*}} foo 'float ()'
+// CHECK-NEXT: CompoundStmt 0x{{.*}}
+// CHECK-NEXT: ReturnStmt 0x{{.*}}
+// CHECK-NEXT: BinaryOperator 0x{{.*}} 'float':'float' '+'
+// CHECK-NEXT: ImplicitCastExpr 0x{{.*}} 'float':'float' <LValueToRValue>
+// CHECK-NEXT: MemberExpr 0x{{.*}} 'float':'float' lvalue .d 0x[[field_d]]
+// CHECK-NEXT: MemberExpr 0x{{.*}} <col:10, col:13> 'test<float, 1>':'test<float, 1>' lvalue .d 0x[[test3_d]]
+// CHECK-NEXT: DeclRefExpr 0x{{.*}} <col:10> 'test3<test2>':'test3<test<float, 1> >' lvalue Var 0x[[tt]] 'tt' 'test3<test2>':'test3<test<float, 1> >'
+// CHECK-NEXT: ImplicitCastExpr 0x{{.*}} 'float':'float' <LValueToRValue>
+// CHECK-NEXT: MemberExpr 0x{{.*}} 'float':'float' lvalue .d 0x[[field_d]]
+// CHECK-NEXT: DeclRefExpr 0x{{.*}} 'test2':'test<float, 1>' lvalue Var 0x[[t22]] 't22' 'test2':'test<float, 1>'
+// CHECK-NEXT: HLSLExportAttr 0x{{.*}}
+export
+float foo() {
+  return tt.d.d + t22.d; 
+}
+
+// Make sure generate cb load from index 1 and 0 then add.
+// IR:%[[CB1:[0-9]+]] = call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %{{.+}}, i32 1)  ; CBufferLoadLegacy(handle,regIndex)
+// IR:%[[VAL1:[0-9]+]] = extractvalue %dx.types.CBufRet.f32 %[[CB1]], 0
+// IR:%[[CB0:[0-9]+]] = call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %{{.+}}, i32 0)  ; CBufferLoadLegacy(handle,regIndex)
+// IR:%[[VAL0:[0-9]+]] = extractvalue %dx.types.CBufRet.f32 %[[CB0]], 0
+// IR:%[[VAL:.+]] = fadd fast float %[[VAL0]], %[[VAL1]]
+// IR:ret float %[[VAL]]