https://github.com/Icohedron updated 
https://github.com/llvm/llvm-project/pull/192151

>From a27d5638c75890ad3431cb3139c7e26530f01515 Mon Sep 17 00:00:00 2001
From: Deric Cheung <[email protected]>
Date: Tue, 14 Apr 2026 14:46:44 -0700
Subject: [PATCH 1/2] Mark vector and matrix constructor-turned-InitListExprs
 as ListInitializations

Fixes a bug for HLSL where vector and matrix constructors that have been
turned into initializer lists were not marked as ListInitializations,
which causes template re-instantiation to fail because the
initialization with a InitListExpr was InitializationKind::IK_Direct
instead of a InitializationKind::IK_DirectList.

Assisted-by: Claude Opus 4.6
---
 clang/lib/Sema/SemaExprCXX.cpp                | 10 ++-
 .../HLSL/vector-constructors-template.hlsl    | 80 +++++++++++++++++++
 2 files changed, 89 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/HLSL/vector-constructors-template.hlsl

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 39c5e3b0671bb..e60d5d7748b44 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1674,7 +1674,15 @@ Sema::BuildCXXTypeConstructExpr(TypeSourceInfo *TInfo,
     // CXXTemporaryObjectExpr. It's also weird that the functional cast
     // is sometimes handled by initialization and sometimes not.
     QualType ResultType = Result.get()->getType();
-    SourceRange Locs = ListInitialization
+    // In HLSL, vector/matrix constructors have their arguments wrapped into an
+    // InitListExpr during initialization sequencing. Mark the resulting
+    // CXXFunctionalCastExpr as list-initialization so that during template
+    // re-instantiation, TreeTransform correctly passes the InitListExpr back
+    // through BuildCXXTypeConstructExpr with ListInitialization=true as 
opposed
+    // to false.
+    bool IsListInit = ListInitialization ||
+                      (getLangOpts().HLSL && isa<InitListExpr>(Result.get()));
+    SourceRange Locs = IsListInit
                            ? SourceRange()
                            : SourceRange(LParenOrBraceLoc, RParenOrBraceLoc);
     Result = CXXFunctionalCastExpr::Create(
diff --git a/clang/test/AST/HLSL/vector-constructors-template.hlsl 
b/clang/test/AST/HLSL/vector-constructors-template.hlsl
new file mode 100644
index 0000000000000..b9d700f3a091f
--- /dev/null
+++ b/clang/test/AST/HLSL/vector-constructors-template.hlsl
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -ast-dump -o 
- %s | FileCheck %s
+
+// Verify that HLSL vector/matrix paren-syntax constructors inside template
+// functions produce the correct AST after template instantiation. The key
+// property is that the CXXFunctionalCastExpr wrapping an InitListExpr survives
+// re-instantiation intact.
+
+typedef int int2 __attribute__((ext_vector_type(2)));
+typedef float float2 __attribute__((ext_vector_type(2)));
+typedef float float3 __attribute__((ext_vector_type(3)));
+typedef float float4 __attribute__((ext_vector_type(4)));
+typedef float float2x2 __attribute__((matrix_type(2, 2)));
+
+// Basic vector constructors in a template.
+template<typename T>
+void vector_constructors() {
+// CHECK-LABEL: FunctionDecl {{.*}} used vector_constructors 'void ()' 
implicit_instantiation
+// CHECK: VarDecl {{.*}} a 'int2':'vector<int, 2>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'int2':'vector<int, 2>' functional 
cast to int2 <NoOp>
+// CHECK-NEXT: InitListExpr {{.*}} 'int2':'vector<int, 2>'
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0
+// CHECK: VarDecl {{.*}} b 'float3':'vector<float, 3>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float3':'vector<float, 3>' 
functional cast to float3 <NoOp>
+// CHECK-NEXT: InitListExpr {{.*}} 'float3':'vector<float, 3>'
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 2.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 3.000000e+00
+  int2 a = int2(0, 0);
+  float3 b = float3(1.0f, 2.0f, 3.0f);
+}
+
+
+// Nested vector constructor: float4 built from a float2 + two scalars.
+template<typename T>
+void vector_constructors_nested() {
+// CHECK-LABEL: FunctionDecl {{.*}} used vector_constructors_nested 'void ()' 
implicit_instantiation
+// CHECK: VarDecl {{.*}} used v 'float2':'vector<float, 2>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float2':'vector<float, 2>' 
functional cast to float2 <NoOp>
+// CHECK-NEXT: InitListExpr {{.*}} 'float2':'vector<float, 2>'
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 2.000000e+00
+// CHECK: VarDecl {{.*}} w 'float4':'vector<float, 4>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float4':'vector<float, 4>' 
functional cast to float4 <NoOp>
+// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector<float, 4>'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' <LValueToRValue>
+// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float2':'vector<float, 2>' lvalue Var 
{{.*}} 'v' 'float2':'vector<float, 2>'
+// CHECK-NEXT: IntegerLiteral {{.*}} '__size_t':'unsigned long' 0
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' <LValueToRValue>
+// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float2':'vector<float, 2>' lvalue Var 
{{.*}} 'v' 'float2':'vector<float, 2>'
+// CHECK-NEXT: IntegerLiteral {{.*}} '__size_t':'unsigned long' 1
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 3.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 4.000000e+00
+  float2 v = float2(1.0f, 2.0f);
+  float4 w = float4(v, 3.0f, 4.0f);
+}
+
+// Matrix constructor in a template.
+template<typename T>
+void matrix_constructors() {
+// CHECK-LABEL: FunctionDecl {{.*}} used matrix_constructors 'void ()' 
implicit_instantiation
+// CHECK: VarDecl {{.*}} m 'float2x2':'matrix<float, 2, 2>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float2x2':'matrix<float, 2, 2>' 
functional cast to float2x2 <NoOp>
+// CHECK-NEXT: InitListExpr {{.*}} 'float2x2':'matrix<float, 2, 2>'
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 2.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 3.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 4.000000e+00
+  float2x2 m = float2x2(1.0f, 2.0f, 3.0f, 4.0f);
+}
+
+// Instantiate the templates from a compute shader entry point.
+[numthreads(1,1,1)]
+void main() {
+  vector_constructors<int>();
+  vector_constructors_nested<float>();
+  matrix_constructors<int>();
+}

>From 9ae80a810f89775057caf430ca754aa9a632064a Mon Sep 17 00:00:00 2001
From: Deric Cheung <[email protected]>
Date: Wed, 15 Apr 2026 09:56:09 -0700
Subject: [PATCH 2/2] Add more test cases. Rename file to be more generic

Assisted-by: Claude Opus 4.6
---
 .../AST/HLSL/hlsl-constructors-template.hlsl  | 169 ++++++++++++++++++
 .../HLSL/vector-constructors-template.hlsl    |  80 ---------
 2 files changed, 169 insertions(+), 80 deletions(-)
 create mode 100644 clang/test/AST/HLSL/hlsl-constructors-template.hlsl
 delete mode 100644 clang/test/AST/HLSL/vector-constructors-template.hlsl

diff --git a/clang/test/AST/HLSL/hlsl-constructors-template.hlsl 
b/clang/test/AST/HLSL/hlsl-constructors-template.hlsl
new file mode 100644
index 0000000000000..3dbbdb5e16a68
--- /dev/null
+++ b/clang/test/AST/HLSL/hlsl-constructors-template.hlsl
@@ -0,0 +1,169 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -ast-dump -o 
- %s | FileCheck %s
+
+// Verify that HLSL vector/matrix paren-syntax constructors inside template
+// functions produce the correct AST after template instantiation. The key
+// property is that the CXXFunctionalCastExpr wrapping an InitListExpr survives
+// re-instantiation intact.
+
+typedef int int2 __attribute__((ext_vector_type(2)));
+typedef float float2 __attribute__((ext_vector_type(2)));
+typedef float float3 __attribute__((ext_vector_type(3)));
+typedef float float4 __attribute__((ext_vector_type(4)));
+typedef float float2x2 __attribute__((matrix_type(2, 2)));
+typedef float float2x3 __attribute__((matrix_type(2, 3)));
+
+// Basic vector constructors in a template.
+template<typename T>
+void vector_constructors() {
+// CHECK-LABEL: FunctionDecl {{.*}} used vector_constructors 'void ()' 
implicit_instantiation
+// CHECK: VarDecl {{.*}} a 'int2':'vector<int, 2>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'int2':'vector<int, 2>' functional 
cast to int2 <NoOp>
+// CHECK-NEXT: InitListExpr {{.*}} 'int2':'vector<int, 2>'
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0
+// CHECK: VarDecl {{.*}} b 'float3':'vector<float, 3>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float3':'vector<float, 3>' 
functional cast to float3 <NoOp>
+// CHECK-NEXT: InitListExpr {{.*}} 'float3':'vector<float, 3>'
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 2.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 3.000000e+00
+  int2 a = int2(0, 0);
+  float3 b = float3(1.0f, 2.0f, 3.0f);
+}
+
+
+// Nested vector constructor: float4 built from a float2 + two scalars.
+template<typename T>
+void vector_constructors_nested() {
+// CHECK-LABEL: FunctionDecl {{.*}} used vector_constructors_nested 'void ()' 
implicit_instantiation
+// CHECK: VarDecl {{.*}} used v 'float2':'vector<float, 2>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float2':'vector<float, 2>' 
functional cast to float2 <NoOp>
+// CHECK-NEXT: InitListExpr {{.*}} 'float2':'vector<float, 2>'
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 2.000000e+00
+// CHECK: VarDecl {{.*}} w 'float4':'vector<float, 4>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float4':'vector<float, 4>' 
functional cast to float4 <NoOp>
+// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector<float, 4>'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' <LValueToRValue>
+// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float2':'vector<float, 2>' lvalue Var 
{{.*}} 'v' 'float2':'vector<float, 2>'
+// CHECK-NEXT: IntegerLiteral {{.*}} '__size_t':'unsigned long' 0
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' <LValueToRValue>
+// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float2':'vector<float, 2>' lvalue Var 
{{.*}} 'v' 'float2':'vector<float, 2>'
+// CHECK-NEXT: IntegerLiteral {{.*}} '__size_t':'unsigned long' 1
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 3.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 4.000000e+00
+  float2 v = float2(1.0f, 2.0f);
+  float4 w = float4(v, 3.0f, 4.0f);
+}
+
+// Matrix constructor in a template.
+template<typename T>
+void matrix_constructors() {
+// CHECK-LABEL: FunctionDecl {{.*}} used matrix_constructors 'void ()' 
implicit_instantiation
+// CHECK: VarDecl {{.*}} m 'float2x2':'matrix<float, 2, 2>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float2x2':'matrix<float, 2, 2>' 
functional cast to float2x2 <NoOp>
+// CHECK-NEXT: InitListExpr {{.*}} 'float2x2':'matrix<float, 2, 2>'
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 2.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 3.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 4.000000e+00
+  float2x2 m = float2x2(1.0f, 2.0f, 3.0f, 4.0f);
+}
+
+// Nested matrix constructor: float2x2 built from a float2 + two scalars.
+template<typename T>
+void matrix_constructors_nested() {
+// CHECK-LABEL: FunctionDecl {{.*}} used matrix_constructors_nested 'void ()' 
implicit_instantiation
+// CHECK: VarDecl {{.*}} used v 'float2':'vector<float, 2>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float2':'vector<float, 2>' 
functional cast to float2 <NoOp>
+// CHECK-NEXT: InitListExpr {{.*}} 'float2':'vector<float, 2>'
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 2.000000e+00
+// CHECK: VarDecl {{.*}} m 'float2x2':'matrix<float, 2, 2>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float2x2':'matrix<float, 2, 2>' 
functional cast to float2x2 <NoOp>
+// CHECK-NEXT: InitListExpr {{.*}} 'float2x2':'matrix<float, 2, 2>'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' <LValueToRValue>
+// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float2':'vector<float, 2>' lvalue Var 
{{.*}} 'v' 'float2':'vector<float, 2>'
+// CHECK-NEXT: IntegerLiteral {{.*}} '__size_t':'unsigned long' 0
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' <LValueToRValue>
+// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float2':'vector<float, 2>' lvalue Var 
{{.*}} 'v' 'float2':'vector<float, 2>'
+// CHECK-NEXT: IntegerLiteral {{.*}} '__size_t':'unsigned long' 1
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 3.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 4.000000e+00
+  float2 v = float2(1.0f, 2.0f);
+  float2x2 m = float2x2(v, 3.0f, 4.0f);
+}
+
+// Vector from matrix: float4 built from a float2x2 (elementwise cast).
+template<typename T>
+void vector_from_matrix() {
+// CHECK-LABEL: FunctionDecl {{.*}} used vector_from_matrix 'void ()' 
implicit_instantiation
+// CHECK: VarDecl {{.*}} used m 'float2x2':'matrix<float, 2, 2>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float2x2':'matrix<float, 2, 2>' 
functional cast to float2x2 <NoOp>
+// CHECK-NEXT: InitListExpr {{.*}} 'float2x2':'matrix<float, 2, 2>'
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 2.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 3.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 4.000000e+00
+// CHECK: VarDecl {{.*}} v 'float4':'vector<float, 4>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float4':'vector<float, 4>' 
functional cast to float4 <HLSLElementwiseCast>
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float2x2':'matrix<float, 2, 2>' 
<LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float2x2':'matrix<float, 2, 2>' lvalue Var 
{{.*}} 'm' 'float2x2':'matrix<float, 2, 2>'
+  float2x2 m = float2x2(1.0f, 2.0f, 3.0f, 4.0f);
+  float4 v = float4(m);
+}
+
+// Matrix from matrix: float2x3 built from a float2x2 + two scalars.
+template<typename T>
+void matrix_from_matrix() {
+// CHECK-LABEL: FunctionDecl {{.*}} used matrix_from_matrix 'void ()' 
implicit_instantiation
+// CHECK: VarDecl {{.*}} used m 'float2x2':'matrix<float, 2, 2>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float2x2':'matrix<float, 2, 2>' 
functional cast to float2x2 <NoOp>
+// CHECK-NEXT: InitListExpr {{.*}} 'float2x2':'matrix<float, 2, 2>'
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 2.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 3.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 4.000000e+00
+// CHECK: VarDecl {{.*}} n 'float2x3':'matrix<float, 2, 3>' cinit
+// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float2x3':'matrix<float, 2, 3>' 
functional cast to float2x3 <NoOp>
+// CHECK-NEXT: InitListExpr {{.*}} 'float2x3':'matrix<float, 2, 3>'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' <LValueToRValue>
+// CHECK-NEXT: MatrixSubscriptExpr {{.*}} 'float' lvalue matrixcomponent
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float2x2':'matrix<float, 2, 2>' lvalue Var 
{{.*}} 'm' 'float2x2':'matrix<float, 2, 2>'
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' <LValueToRValue>
+// CHECK-NEXT: MatrixSubscriptExpr {{.*}} 'float' lvalue matrixcomponent
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float2x2':'matrix<float, 2, 2>' lvalue Var 
{{.*}} 'm' 'float2x2':'matrix<float, 2, 2>'
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' <LValueToRValue>
+// CHECK-NEXT: MatrixSubscriptExpr {{.*}} 'float' lvalue matrixcomponent
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float2x2':'matrix<float, 2, 2>' lvalue Var 
{{.*}} 'm' 'float2x2':'matrix<float, 2, 2>'
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' <LValueToRValue>
+// CHECK-NEXT: MatrixSubscriptExpr {{.*}} 'float' lvalue matrixcomponent
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float2x2':'matrix<float, 2, 2>' lvalue Var 
{{.*}} 'm' 'float2x2':'matrix<float, 2, 2>'
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 5.000000e+00
+// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 6.000000e+00
+  float2x2 m = float2x2(1.0f, 2.0f, 3.0f, 4.0f);
+  float2x3 n = float2x3(m, 5.0f, 6.0f);
+}
+
+// Instantiate the templates from a compute shader entry point.
+[numthreads(1,1,1)]
+void main() {
+  vector_constructors<int>();
+  vector_constructors_nested<float>();
+  matrix_constructors<int>();
+  matrix_constructors_nested<int>();
+  vector_from_matrix<int>();
+  matrix_from_matrix<int>();
+}
diff --git a/clang/test/AST/HLSL/vector-constructors-template.hlsl 
b/clang/test/AST/HLSL/vector-constructors-template.hlsl
deleted file mode 100644
index b9d700f3a091f..0000000000000
--- a/clang/test/AST/HLSL/vector-constructors-template.hlsl
+++ /dev/null
@@ -1,80 +0,0 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -ast-dump -o 
- %s | FileCheck %s
-
-// Verify that HLSL vector/matrix paren-syntax constructors inside template
-// functions produce the correct AST after template instantiation. The key
-// property is that the CXXFunctionalCastExpr wrapping an InitListExpr survives
-// re-instantiation intact.
-
-typedef int int2 __attribute__((ext_vector_type(2)));
-typedef float float2 __attribute__((ext_vector_type(2)));
-typedef float float3 __attribute__((ext_vector_type(3)));
-typedef float float4 __attribute__((ext_vector_type(4)));
-typedef float float2x2 __attribute__((matrix_type(2, 2)));
-
-// Basic vector constructors in a template.
-template<typename T>
-void vector_constructors() {
-// CHECK-LABEL: FunctionDecl {{.*}} used vector_constructors 'void ()' 
implicit_instantiation
-// CHECK: VarDecl {{.*}} a 'int2':'vector<int, 2>' cinit
-// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'int2':'vector<int, 2>' functional 
cast to int2 <NoOp>
-// CHECK-NEXT: InitListExpr {{.*}} 'int2':'vector<int, 2>'
-// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0
-// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0
-// CHECK: VarDecl {{.*}} b 'float3':'vector<float, 3>' cinit
-// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float3':'vector<float, 3>' 
functional cast to float3 <NoOp>
-// CHECK-NEXT: InitListExpr {{.*}} 'float3':'vector<float, 3>'
-// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.000000e+00
-// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 2.000000e+00
-// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 3.000000e+00
-  int2 a = int2(0, 0);
-  float3 b = float3(1.0f, 2.0f, 3.0f);
-}
-
-
-// Nested vector constructor: float4 built from a float2 + two scalars.
-template<typename T>
-void vector_constructors_nested() {
-// CHECK-LABEL: FunctionDecl {{.*}} used vector_constructors_nested 'void ()' 
implicit_instantiation
-// CHECK: VarDecl {{.*}} used v 'float2':'vector<float, 2>' cinit
-// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float2':'vector<float, 2>' 
functional cast to float2 <NoOp>
-// CHECK-NEXT: InitListExpr {{.*}} 'float2':'vector<float, 2>'
-// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.000000e+00
-// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 2.000000e+00
-// CHECK: VarDecl {{.*}} w 'float4':'vector<float, 4>' cinit
-// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float4':'vector<float, 4>' 
functional cast to float4 <NoOp>
-// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector<float, 4>'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' <LValueToRValue>
-// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent
-// CHECK-NEXT: DeclRefExpr {{.*}} 'float2':'vector<float, 2>' lvalue Var 
{{.*}} 'v' 'float2':'vector<float, 2>'
-// CHECK-NEXT: IntegerLiteral {{.*}} '__size_t':'unsigned long' 0
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' <LValueToRValue>
-// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent
-// CHECK-NEXT: DeclRefExpr {{.*}} 'float2':'vector<float, 2>' lvalue Var 
{{.*}} 'v' 'float2':'vector<float, 2>'
-// CHECK-NEXT: IntegerLiteral {{.*}} '__size_t':'unsigned long' 1
-// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 3.000000e+00
-// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 4.000000e+00
-  float2 v = float2(1.0f, 2.0f);
-  float4 w = float4(v, 3.0f, 4.0f);
-}
-
-// Matrix constructor in a template.
-template<typename T>
-void matrix_constructors() {
-// CHECK-LABEL: FunctionDecl {{.*}} used matrix_constructors 'void ()' 
implicit_instantiation
-// CHECK: VarDecl {{.*}} m 'float2x2':'matrix<float, 2, 2>' cinit
-// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'float2x2':'matrix<float, 2, 2>' 
functional cast to float2x2 <NoOp>
-// CHECK-NEXT: InitListExpr {{.*}} 'float2x2':'matrix<float, 2, 2>'
-// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.000000e+00
-// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 2.000000e+00
-// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 3.000000e+00
-// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 4.000000e+00
-  float2x2 m = float2x2(1.0f, 2.0f, 3.0f, 4.0f);
-}
-
-// Instantiate the templates from a compute shader entry point.
-[numthreads(1,1,1)]
-void main() {
-  vector_constructors<int>();
-  vector_constructors_nested<float>();
-  matrix_constructors<int>();
-}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to