Skip to content

Commit 0f6240c

Browse files
authored
[HLSL] Allow EmptyDecl in cbuffer/tbuffer (#128250)
We do handle EmptyDecls in codegen already as of #124886, but we were blocking them in Sema. EmptyDecls tend to be caused by extra semicolons which are not illegal. Fixes #128238
1 parent 8634635 commit 0f6240c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

clang/lib/Parse/ParseHLSL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ static bool validateDeclsInsideHLSLBuffer(Parser::DeclGroupPtrTy DG,
2727
return false;
2828
DeclGroupRef Decls = DG.get();
2929
bool IsValid = true;
30-
// Only allow function, variable, record decls inside HLSLBuffer.
30+
// Only allow function, variable, record, and empty decls inside HLSLBuffer.
3131
for (DeclGroupRef::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) {
3232
Decl *D = *I;
33-
if (isa<CXXRecordDecl, RecordDecl, FunctionDecl, VarDecl>(D))
33+
if (isa<CXXRecordDecl, RecordDecl, FunctionDecl, VarDecl, EmptyDecl>(D))
3434
continue;
3535

3636
// FIXME: support nested HLSLBuffer and namespace inside HLSLBuffer.

clang/test/SemaHLSL/cb_error.hlsl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ tbuffer B {
4747
// expected-error@+1 {{unknown type name 'flaot'}}
4848
flaot f;
4949
}
50+
51+
// None of these should produce an error!
52+
cbuffer EmptyCBuffer {}
53+
54+
cbuffer EmptyDeclCBuffer {
55+
;
56+
}
57+
58+
cbuffer EmptyDecl2CBuffer {
59+
;
60+
int X;
61+
}

0 commit comments

Comments
 (0)