Files
clang-p2996/clang/test/SemaHLSL/cb_error.hlsl
Xiang Li 782ac2182c [HLSL] Support cbuffer/tbuffer for hlsl.
This is first part for support cbuffer/tbuffer.

The format for cbuffer/tbuffer is
BufferType [Name] [: register(b#)] { VariableDeclaration [: packoffset(c#.xyzw)]; ... };

More details at https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-constants

New keyword 'cbuffer' and 'tbuffer' are added.
New AST node HLSLBufferDecl is added.
Build AST for simple cbuffer/tbuffer without attribute support.

The special thing is variables declared inside cbuffer is exposed into global scope.
So isTransparentContext should return true for HLSLBuffer.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D129883
2022-09-21 10:07:43 -07:00

50 lines
1.1 KiB
HLSL

// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
// expected-note@+1 {{declared here}}
cbuffer a {
int x;
};
int foo() {
// expected-error@+1 {{'a' does not refer to a value}}
return sizeof(a);
}
// expected-error@+1 {{expected unqualified-id}}
template <typename Ty> cbuffer a { Ty f; };
// For back-compat reason, it is OK for multiple cbuffer/tbuffer use same name in hlsl.
// And these cbuffer name only used for reflection, cannot be removed.
cbuffer A {
float A;
}
cbuffer A {
float b;
}
tbuffer A {
float a;
}
float bar() {
// cbuffer/tbuffer name will not conflict with other variables.
return A;
}
cbuffer a {
// expected-error@+2 {{unknown type name 'oh'}}
// expected-error@+1 {{expected ';' after top level declarator}}
oh no!
// expected-warning@+1 {{missing terminating ' character}}
this isn't even valid HLSL code
despite seeming totally reasonable
once you understand that HLSL
is so flaming weird.
}
tbuffer B {
// expected-error@+1 {{unknown type name 'flaot'}}
flaot f;
}