| 1 |
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -ast-dump -o - %s | FileCheck %s |
| 2 |
|
| 3 |
// CHECK: CXXRecordDecl {{.*}} struct EmptyStruct definition |
| 4 |
struct EmptyStruct { |
| 5 |
}; |
| 6 |
|
| 7 |
// CHECK: NamespaceDecl {{.*}} NS1 |
| 8 |
namespace NS1 { |
| 9 |
// CHECK: CXXRecordDecl {{.*}} struct Foo definition |
| 10 |
struct Foo { |
| 11 |
float a; |
| 12 |
EmptyStruct es; |
| 13 |
}; |
| 14 |
|
| 15 |
// CHECK: CXXRecordDecl {{.*}} struct Bar definition |
| 16 |
struct Bar { |
| 17 |
// CHECK: CXXRecordDecl {{.*}} struct Foo definition |
| 18 |
struct Foo { |
| 19 |
int b; |
| 20 |
EmptyStruct es; |
| 21 |
}; |
| 22 |
// CHECK: CXXRecordDecl {{.*}} implicit struct __cblayout_Foo definition |
| 23 |
// CHECK: FieldDecl {{.*}} b 'int' |
| 24 |
}; |
| 25 |
// CHECK: CXXRecordDecl {{.*}} implicit struct __cblayout_Foo definition |
| 26 |
// CHECK: FieldDecl {{.*}} a 'float' |
| 27 |
} |
| 28 |
|
| 29 |
struct Foo { |
| 30 |
double c; |
| 31 |
EmptyStruct es; |
| 32 |
}; |
| 33 |
|
| 34 |
// CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 2]]:9 cbuffer CB1 |
| 35 |
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer |
| 36 |
cbuffer CB1 { |
| 37 |
// CHECK: VarDecl {{.*}} foo1 'hlsl_constant Foo' |
| 38 |
Foo foo1; |
| 39 |
// CHECK: VarDecl {{.*}} foo2 'hlsl_constant NS1::Foo' |
| 40 |
NS1::Foo foo2; |
| 41 |
// CHECK: VarDecl {{.*}} foo3 'hlsl_constant NS1::Bar::Foo' |
| 42 |
NS1::Bar::Foo foo3; |
| 43 |
// CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_CB1 definition |
| 44 |
// CHECK: FieldDecl {{.*}} foo1 '__cblayout_Foo' |
| 45 |
// CHECK: FieldDecl {{.*}} foo2 'NS1::__cblayout_Foo' |
| 46 |
// CHECK: FieldDecl {{.*}} foo3 'NS1::Bar::__cblayout_Foo' |
| 47 |
} |
| 48 |
// CHECK: CXXRecordDecl {{.*}} implicit struct __cblayout_Foo definition |
| 49 |
// CHECK: FieldDecl {{.*}} c 'double' |
| 50 |
|
| 51 |
struct CB1ExpectedShape { |
| 52 |
double a1; |
| 53 |
float a2; |
| 54 |
int a; |
| 55 |
}; |
| 56 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(CB1ExpectedShape, __cblayout_CB1), ""); |
| 57 |
|
| 58 |
namespace NS2 { |
| 59 |
struct Foo { |
| 60 |
float d[4]; |
| 61 |
EmptyStruct es; |
| 62 |
}; |
| 63 |
// CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 2]]:11 cbuffer CB2 |
| 64 |
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer |
| 65 |
cbuffer CB2 { |
| 66 |
// CHECK: VarDecl {{.*}} foo0 'hlsl_constant ::Foo' |
| 67 |
::Foo foo0; |
| 68 |
// CHECK: VarDecl {{.*}} foo1 'hlsl_constant Foo' |
| 69 |
Foo foo1; |
| 70 |
// CHECK: VarDecl {{.*}} foo2 'hlsl_constant NS1::Foo' |
| 71 |
NS1::Foo foo2; |
| 72 |
// CHECK: VarDecl {{.*}} foo3 'hlsl_constant NS1::Bar::Foo' |
| 73 |
NS1::Bar::Foo foo3; |
| 74 |
// CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_CB2 definition |
| 75 |
// CHECK: FieldDecl {{.*}} foo0 '__cblayout_Foo' |
| 76 |
// CHECK: FieldDecl {{.*}} foo1 'NS2::__cblayout_Foo' |
| 77 |
// CHECK: FieldDecl {{.*}} foo2 'NS1::__cblayout_Foo' |
| 78 |
// CHECK: FieldDecl {{.*}} foo3 'NS1::Bar::__cblayout_Foo' |
| 79 |
} |
| 80 |
// CHECK: CXXRecordDecl {{.*}} implicit struct __cblayout_Foo definition |
| 81 |
// CHECK: FieldDecl {{.*}} d 'float[4]' |
| 82 |
} |
| 83 |
|
| 84 |
struct CB2ExpectedShape { |
| 85 |
double a1; |
| 86 |
float d[4]; |
| 87 |
float a2; |
| 88 |
int a; |
| 89 |
}; |
| 90 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(CB2ExpectedShape, NS2::__cblayout_CB2), ""); |
| 91 |
|
| 92 |
// Add uses for the constant buffer declarations so they are not optimized away |
| 93 |
// CHECK: ExportDecl |
| 94 |
export float f() { |
| 95 |
return foo2.a + NS2::foo2.a; |
| 96 |
} |