From 98d8a84c508d743cb366db7a16b2b813f0c595d0 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Fri, 21 Feb 2025 17:47:12 -0600 Subject: [PATCH 1/2] [HLSL] Allow EmptyDecl in cbuffer/tbuffer 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 --- clang/lib/Parse/ParseHLSL.cpp | 2 +- clang/test/SemaHLSL/cb_error.hlsl | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp index 443bf2b9ec626..612e1ab0084ff 100644 --- a/clang/lib/Parse/ParseHLSL.cpp +++ b/clang/lib/Parse/ParseHLSL.cpp @@ -30,7 +30,7 @@ static bool validateDeclsInsideHLSLBuffer(Parser::DeclGroupPtrTy DG, // Only allow function, variable, record decls inside HLSLBuffer. for (DeclGroupRef::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) { Decl *D = *I; - if (isa(D)) + if (isa(D)) continue; // FIXME: support nested HLSLBuffer and namespace inside HLSLBuffer. diff --git a/clang/test/SemaHLSL/cb_error.hlsl b/clang/test/SemaHLSL/cb_error.hlsl index 133adeeb2068b..95c917a9bb9ee 100644 --- a/clang/test/SemaHLSL/cb_error.hlsl +++ b/clang/test/SemaHLSL/cb_error.hlsl @@ -47,3 +47,15 @@ tbuffer B { // expected-error@+1 {{unknown type name 'flaot'}} flaot f; } + +// None of these should produce an error! +cbuffer EmptyCBuffer {} + +cbuffer EmptyDeclCBuffer { + ; +} + +cbuffer EmptyDecl2CBuffer { + ; + int X; +} From 2494565de762e72181dba741eff7c49754df2de0 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Fri, 21 Feb 2025 18:11:47 -0600 Subject: [PATCH 2/2] Update comment --- clang/lib/Parse/ParseHLSL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp index 612e1ab0084ff..f4c109f9a81a2 100644 --- a/clang/lib/Parse/ParseHLSL.cpp +++ b/clang/lib/Parse/ParseHLSL.cpp @@ -27,7 +27,7 @@ static bool validateDeclsInsideHLSLBuffer(Parser::DeclGroupPtrTy DG, return false; DeclGroupRef Decls = DG.get(); bool IsValid = true; - // Only allow function, variable, record decls inside HLSLBuffer. + // Only allow function, variable, record, and empty decls inside HLSLBuffer. for (DeclGroupRef::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) { Decl *D = *I; if (isa(D))