Debian Codegraph @

clang/test/SemaHLSL/Language/ElementwiseCasts.hlsl

raw
1 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type %s -ast-dump | FileCheck %s
2
3 // truncation
4 // CHECK-LABEL: call1
5 // CHECK: CStyleCastExpr {{.*}} 'int[1]' <HLSLElementwiseCast>
6 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'int[2]' <HLSLArrayRValue> part_of_explicit_cast
7 // CHECK-NEXT: DeclRefExpr {{.*}} 'int[2]' lvalue Var {{.*}} 'A' 'int[2]'
8 export void call1() {
9 int A[2] = {0,1};
10 int B[1] = {4};
11 B = (int[1])A;
12 }
13
14 // flat cast of equal size
15 // CHECK-LABEL: call2
16 // CHECK: CStyleCastExpr {{.*}} 'float[1]' <HLSLElementwiseCast>
17 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'int[1]' <HLSLArrayRValue> part_of_explicit_cast
18 // CHECK-NEXT: DeclRefExpr {{.*}} 'int[1]' lvalue Var {{.*}} 'A' 'int[1]'
19 export void call2() {
20 int A[1] = {0};
21 float B[1] = {1.0};
22 B = (float[1])A;
23 }
24
25 struct S {
26 int A;
27 float F;
28 };
29
30 // cast from a struct
31 // CHECK-LABEL: call3
32 // CHECK: CStyleCastExpr {{.*}} 'int[2]' <HLSLElementwiseCast>
33 // CHECK-NEXT: DeclRefExpr {{.*}} 'S' lvalue Var {{.*}} 'SS' 'S'
34 export void call3() {
35 S SS = {1,1.0};
36 int A[2] = (int[2])SS;
37 }
38
39 // cast from a vector
40 // CHECK-LABEL: call4
41 // CHECK: CStyleCastExpr {{.*}} 'float[3]' <HLSLElementwiseCast>
42 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'int3':'vector<int, 3>' <LValueToRValue> part_of_explicit_cast
43 // CHECK-NEXT: DeclRefExpr {{.*}} 'int3':'vector<int, 3>' lvalue Var {{.*}} 'A' 'int3'
44 export void call4() {
45 int3 A = {1,2,3};
46 float B[3] = (float[3])A;
47 }