xref: /llvm-project/clang/test/SemaHLSL/resource_binding_attr_error.hlsl (revision 905de9b0fe06d960e7f60175e6c96b955f334a66)
1// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
2
3template<typename T>
4struct MyTemplatedSRV {
5  __hlsl_resource_t [[hlsl::resource_class(SRV)]] x;
6};
7
8// valid, The register keyword in this statement isn't binding a resource, rather it is
9// specifying a constant register binding offset within the $Globals cbuffer, which is legacy behavior from DX9.
10float a : register(c0);
11
12// expected-error@+1 {{binding type 'i' ignored. The 'integer constant' binding type is no longer supported}}
13cbuffer b : register(i0) {
14
15}
16
17// expected-error@+1 {{register number should be an integer}}
18cbuffer c : register(bf, s2) {
19
20}
21
22// expected-error@+1 {{expected identifier}}
23cbuffer A : register() {}
24
25// expected-error@+1 {{register number should be an integer}}
26cbuffer B : register(space1) {}
27
28// expected-error@+1 {{wrong argument format for hlsl attribute, use b2 instead}}
29cbuffer C : register(b 2) {}
30
31// expected-error@+1 {{wrong argument format for hlsl attribute, use b2 instead}}
32cbuffer D : register(b 2, space3) {}
33
34// expected-error@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
35static MyTemplatedSRV<float> U : register(u5);
36
37// expected-error@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
38static float sa : register(c1);
39
40float x[2] : register(c2); // valid
41float y[2][2] : register(c3); // valid
42float z[2][2][3] : register(c4); // valid
43
44// expected-error@+1 {{binding type 'c' only applies to numeric variables in the global scope}}
45groupshared float fa[10] : register(c5);
46
47void foo() {
48  // expected-error@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
49  MyTemplatedSRV<float> U : register(u3);
50}
51void foo2() {
52  // expected-error@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
53  extern MyTemplatedSRV<float> U2 : register(u5);
54}
55
56// expected-error@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
57void bar(MyTemplatedSRV<float> U : register(u3)) {
58
59}
60
61struct S {
62  // expected-error@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
63  MyTemplatedSRV<float> U : register(u3);
64};
65
66// expected-error@+1 {{binding type 'z' is invalid}}
67MyTemplatedSRV<float> U3 : register(z5);
68