xref: /llvm-project/clang/test/AST/HLSL/vector-alias.hlsl (revision b6fd6d4cc53d263c586264d1476265fbdcc0ba21)
1// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -ast-dump -o - %s | FileCheck %s
2
3// CHECK: NamespaceDecl 0x{{[0-9a-fA-F]+}} <<invalid sloc>> <invalid sloc> implicit hlsl
4// CHECK-NEXT: TypeAliasTemplateDecl 0x{{[0-9a-fA-F]+}} <<invalid sloc>> <invalid sloc> implicit vector
5// CHECK-NEXT: TemplateTypeParmDecl 0x{{[0-9a-fA-F]+}} <<invalid sloc>> <invalid sloc> class depth 0 index 0 element
6// CHECK-NEXT: TemplateArgument type 'float'
7// CHECK-NEXT: BuiltinType 0x{{[0-9a-fA-F]+}} 'float'
8// CHECK-NEXT: NonTypeTemplateParmDecl 0x{{[0-9a-fA-F]+}} <<invalid sloc>> <invalid sloc> 'int' depth 0 index 1 element_count
9// CHECK-NEXT: TemplateArgument expr
10// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-fA-F]+}} <<invalid sloc>> 'int' 4
11// CHECK-NEXT: TypeAliasDecl 0x{{[0-9a-fA-F]+}} <<invalid sloc>> <invalid sloc> implicit vector 'vector<element, element_count>'
12// CHECK-NEXT: DependentSizedExtVectorType 0x{{[0-9a-fA-F]+}} 'vector<element, element_count>' dependent <invalid sloc>
13// CHECK-NEXT: TemplateTypeParmType 0x{{[0-9a-fA-F]+}} 'element' dependent depth 0 index 0
14// CHECK-NEXT: TemplateTypeParm 0x{{[0-9a-fA-F]+}} 'element'
15// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-fA-F]+}} <<invalid sloc>> 'int' lvalue
16// NonTypeTemplateParm 0x{{[0-9a-fA-F]+}} 'element_count' 'int'
17
18// Make sure we got a using directive at the end.
19// CHECK: UsingDirectiveDecl 0x{{[0-9a-fA-F]+}} <<invalid sloc>> <invalid sloc> Namespace 0x{{[0-9a-fA-F]+}} 'hlsl'
20
21[numthreads(1,1,1)]
22int entry() {
23  // Verify that the alias is generated inside the hlsl namespace.
24  hlsl::vector<float, 2> Vec2 = {1.0, 2.0};
25
26  // CHECK: DeclStmt 0x{{[0-9a-fA-F]+}} <line:24:3, col:43>
27  // CHECK-NEXT: VarDecl 0x{{[0-9a-fA-F]+}} <col:3, col:42> col:26 Vec2 'hlsl::vector<float, 2>':'vector<float, 2>' cinit
28
29  // Verify that you don't need to specify the namespace.
30  vector<int, 2> Vec2a = {1, 2};
31
32  // CHECK: DeclStmt 0x{{[0-9a-fA-F]+}} <line:30:3, col:32>
33  // CHECK-NEXT: VarDecl 0x{{[0-9a-fA-F]+}} <col:3, col:31> col:18 Vec2a 'vector<int, 2>' cinit
34
35  // Build a bigger vector.
36  vector<double, 4> Vec4 = {1.0, 2.0, 3.0, 4.0};
37
38  // CHECK: DeclStmt 0x{{[0-9a-fA-F]+}} <line:36:3, col:48>
39  // CHECK-NEXT: VarDecl 0x{{[0-9a-fA-F]+}} <col:3, col:47> col:21 used Vec4 'vector<double, 4>' cinit
40
41  // Verify that swizzles still work.
42  vector<double, 3> Vec3 = Vec4.xyz;
43
44  // CHECK: DeclStmt 0x{{[0-9a-fA-F]+}} <line:42:3, col:36>
45  // CHECK-NEXT: VarDecl 0x{{[0-9a-fA-F]+}} <col:3, col:33> col:21 Vec3 'vector<double, 3>' cinit
46
47  // Verify that the implicit arguments generate the correct type.
48  vector<> ImpVec4 = {1.0, 2.0, 3.0, 4.0};
49
50  // CHECK: DeclStmt 0x{{[0-9a-fA-F]+}} <line:48:3, col:42>
51  // CHECK-NEXT: VarDecl 0x{{[0-9a-fA-F]+}} <col:3, col:41> col:12 ImpVec4 'vector<>':'vector<float, 4>' cinit
52  return 1;
53}
54