| 1 |
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -ast-dump -o - %s | FileCheck %s |
| 2 |
|
| 3 |
typedef float float2 __attribute__((ext_vector_type(2))); |
| 4 |
typedef float float3 __attribute__((ext_vector_type(3))); |
| 5 |
|
| 6 |
[numthreads(1,1,1)] |
| 7 |
void entry() { |
| 8 |
float2 Vec2 = float2(1.0, 2.0); |
| 9 |
float3 Vec3 = float3(Vec2, 3.0); |
| 10 |
float3 Vec3b = float3(1.0, 2.0, 3.0); |
| 11 |
|
| 12 |
// For the float2 vector, we just expect a conversion from constructor |
| 13 |
// parameters to an initialization list |
| 14 |
// CHECK-LABEL: VarDecl 0x{{[0-9a-fA-F]+}} {{.*}} used Vec2 'float2':'vector<float, 2>' cinit |
| 15 |
// CHECK-NEXT: CXXFunctionalCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float2':'vector<float, 2>' functional cast to float2 <NoOp> |
| 16 |
// CHECK-NEXT: InitListExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float2':'vector<float, 2>' |
| 17 |
// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} {{.*}} 'float' 1.000000e+00 |
| 18 |
// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} {{.*}} 'float' 2.000000e+00 |
| 19 |
|
| 20 |
|
| 21 |
// For the float 3 things get fun... |
| 22 |
// Here we expect accesses to the vec2 to provide the first and second |
| 23 |
// components using ArraySubscriptExpr |
| 24 |
// CHECK-LABEL: VarDecl 0x{{[0-9a-fA-F]+}} {{.*}} col:10 Vec3 'float3':'vector<float, 3>' cinit |
| 25 |
// CHECK-NEXT: CXXFunctionalCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float3':'vector<float, 3>' functional cast to float3 <NoOp> |
| 26 |
// CHECK-NEXT: InitListExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float3':'vector<float, 3>' |
| 27 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} <col:24, <invalid sloc>> 'float' <LValueToRValue> |
| 28 |
// CHECK-NEXT: ArraySubscriptExpr 0x{{[0-9a-fA-F]+}} <col:24, <invalid sloc>> 'float' lvalue |
| 29 |
// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float2':'vector<float, 2>' lvalue Var 0x{{[0-9a-fA-F]+}} 'Vec2' 'float2':'vector<float, 2>' |
| 30 |
// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-fA-F]+}} <<invalid sloc>> 'int' 0 |
| 31 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} <col:24, <invalid sloc>> 'float' <LValueToRValue> |
| 32 |
// CHECK-NEXT: ArraySubscriptExpr 0x{{[0-9a-fA-F]+}} <col:24, <invalid sloc>> 'float' lvalue |
| 33 |
// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float2':'vector<float, 2>' lvalue Var 0x{{[0-9a-fA-F]+}} 'Vec2' 'float2':'vector<float, 2>' |
| 34 |
// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-fA-F]+}} <<invalid sloc>> 'int' 1 |
| 35 |
// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} {{.*}} 'float' 3.000000e+00 |
| 36 |
|
| 37 |
// CHECK: VarDecl 0x{{[0-9a-fA-F]+}} {{.*}} col:10 Vec3b 'float3':'vector<float, 3>' cinit |
| 38 |
// CHECK-NEXT: CXXFunctionalCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float3':'vector<float, 3>' functional cast to float3 <NoOp> |
| 39 |
// CHECK-NEXT: InitListExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float3':'vector<float, 3>' |
| 40 |
|
| 41 |
// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} {{.*}} 'float' 1.000000e+00 |
| 42 |
// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} {{.*}} 'float' 2.000000e+00 |
| 43 |
// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} {{.*}} 'float' 3.000000e+00 |
| 44 |
|
| 45 |
// The tests above verify pretty explictily that the Initialization lists are |
| 46 |
// being constructed as expected. The next tests are bit sparser for brevity. |
| 47 |
|
| 48 |
float f = 1.0f, g = 2.0f; |
| 49 |
float2 foo0 = float2(f, g); // Non-literal |
| 50 |
|
| 51 |
// CHECK-LABEL: VarDecl 0x{{[0-9a-fA-F]+}} {{.*}} foo0 'float2' |
| 52 |
// CHECK-NEXT: CXXFunctionalCastExpr |
| 53 |
// CHECK-NEXT: InitListExpr |
| 54 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' <LValueToRValue> |
| 55 |
// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' lvalue Var 0x{{[0-9a-fA-F]+}} 'f' 'float' |
| 56 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' <LValueToRValue> |
| 57 |
// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' lvalue Var 0x{{[0-9a-fA-F]+}} 'g' 'float' |
| 58 |
|
| 59 |
int i = 1, j = 2; |
| 60 |
float2 foo1 = float2(1, 2); // Integer literals |
| 61 |
|
| 62 |
// CHECK-LABEL: VarDecl 0x{{[0-9a-fA-F]+}} {{.*}} foo1 'float2' |
| 63 |
// CHECK-NEXT: CXXFunctionalCastExpr |
| 64 |
// CHECK-NEXT: InitListExpr |
| 65 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' <IntegralToFloating> |
| 66 |
// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-fA-F]+}} {{.*}} 'int' 1 |
| 67 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' <IntegralToFloating> |
| 68 |
// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-fA-F]+}} {{.*}} 'int' 2 |
| 69 |
|
| 70 |
float2 foo2 = float2(i, j); // Integer non-literal |
| 71 |
|
| 72 |
// CHECK-LABEL: VarDecl 0x{{[0-9a-fA-F]+}} {{.*}} foo2 'float2' |
| 73 |
// CHECK-NEXT: CXXFunctionalCastExpr |
| 74 |
// CHECK-NEXT: InitListExpr |
| 75 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' <IntegralToFloating> |
| 76 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'int' <LValueToRValue> |
| 77 |
// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'int' lvalue Var 0x{{[0-9a-fA-F]+}} 'i' 'int' |
| 78 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' <IntegralToFloating> |
| 79 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'int' <LValueToRValue> |
| 80 |
// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'int' lvalue Var 0x{{[0-9a-fA-F]+}} 'j' 'int' |
| 81 |
|
| 82 |
struct S { float f; } s; |
| 83 |
float2 foo4 = float2(s.f, s.f); |
| 84 |
|
| 85 |
// CHECK-LABEL: VarDecl 0x{{[0-9a-fA-F]+}} {{.*}} foo4 'float2' |
| 86 |
// CHECK-NEXT: CXXFunctionalCastExpr |
| 87 |
// CHECK-NEXT: InitListExpr |
| 88 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' <LValueToRValue> |
| 89 |
// CHECK-NEXT: MemberExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' lvalue .f 0x{{[0-9a-fA-F]+}} |
| 90 |
// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'struct S':'S' lvalue Var 0x{{[0-9a-fA-F]+}} 's' 'struct S':'S' |
| 91 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' <LValueToRValue> |
| 92 |
// CHECK-NEXT: MemberExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' lvalue .f 0x{{[0-9a-fA-F]+}} |
| 93 |
// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'struct S':'S' lvalue Var 0x{{[0-9a-fA-F]+}} 's' 'struct S':'S' |
| 94 |
|
| 95 |
struct T { |
| 96 |
operator float() const { return 1.0f; } |
| 97 |
} t; |
| 98 |
float2 foo5 = float2(t, t); // user-defined cast operator |
| 99 |
|
| 100 |
// CHECK-LABEL: VarDecl 0x{{[0-9a-fA-F]+}} {{.*}} foo5 'float2' |
| 101 |
// CHECK-NEXT: CXXFunctionalCastExpr |
| 102 |
// CHECK-NEXT: InitListExpr |
| 103 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' <UserDefinedConversion> |
| 104 |
// CHECK-NEXT: CXXMemberCallExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' |
| 105 |
// CHECK-NEXT: MemberExpr 0x{{[0-9a-fA-F]+}} {{.*}} '<bound member function type>' .operator float 0x{{[0-9a-fA-F]+}} |
| 106 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'const T' lvalue <NoOp> |
| 107 |
// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'struct T':'T' lvalue Var 0x{{[0-9a-fA-F]+}} 't' 'struct T':'T' |
| 108 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' <UserDefinedConversion> |
| 109 |
// CHECK-NEXT: CXXMemberCallExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float' |
| 110 |
// CHECK-NEXT: MemberExpr 0x{{[0-9a-fA-F]+}} {{.*}} '<bound member function type>' .operator float 0x{{[0-9a-fA-F]+}} |
| 111 |
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'const T' lvalue <NoOp> |
| 112 |
// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'struct T':'T' lvalue Var 0x{{[0-9a-fA-F]+}} 't' 'struct T':'T' |
| 113 |
|
| 114 |
typedef float2 second_level_of_typedefs; |
| 115 |
second_level_of_typedefs foo6 = float2(1.0f, 2.0f); |
| 116 |
|
| 117 |
|
| 118 |
// CHECK-LABEL: VarDecl 0x{{[0-9a-fA-F]+}} {{.*}} foo6 'second_level_of_typedefs' |
| 119 |
// CHECK-NEXT: CXXFunctionalCastExpr |
| 120 |
// CHECK-NEXT: InitListExpr |
| 121 |
// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} {{.*}} 'float' 1.000000e+00 |
| 122 |
// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} {{.*}} 'float' 2.000000e+00 |
| 123 |
|
| 124 |
float2 foo7 = second_level_of_typedefs(1.0f, 2.0f); |
| 125 |
|
| 126 |
// CHECK-LABEL: VarDecl 0x{{[0-9a-fA-F]+}} {{.*}} foo7 'float2' |
| 127 |
// CHECK-NEXT: CXXFunctionalCastExpr |
| 128 |
// CHECK-NEXT: InitListExpr |
| 129 |
// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} {{.*}} 'float' 1.000000e+00 |
| 130 |
// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} {{.*}} 'float' 2.000000e+00 |
| 131 |
|
| 132 |
} |