[clang] 0f6240c - [HLSL] Allow EmptyDecl in cbuffer/tbuffer (#128250)

via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 26 06:29:28 PST 2025


Author: Chris B
Date: 2025-02-26T08:29:24-06:00
New Revision: 0f6240c4ddc815283f7bd42fe80847295de4a92c

URL: https://github.com/llvm/llvm-project/commit/0f6240c4ddc815283f7bd42fe80847295de4a92c
DIFF: https://github.com/llvm/llvm-project/commit/0f6240c4ddc815283f7bd42fe80847295de4a92c.diff

LOG: [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

Added: 
    

Modified: 
    clang/lib/Parse/ParseHLSL.cpp
    clang/test/SemaHLSL/cb_error.hlsl

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp
index 443bf2b9ec626..f4c109f9a81a2 100644
--- a/clang/lib/Parse/ParseHLSL.cpp
+++ b/clang/lib/Parse/ParseHLSL.cpp
@@ -27,10 +27,10 @@ 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<CXXRecordDecl, RecordDecl, FunctionDecl, VarDecl>(D))
+    if (isa<CXXRecordDecl, RecordDecl, FunctionDecl, VarDecl, EmptyDecl>(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 at +1 {{unknown type name 'flaot'}}
   flaot f;
 }
+
+// None of these should produce an error!
+cbuffer EmptyCBuffer {}
+
+cbuffer EmptyDeclCBuffer {
+  ;
+}
+
+cbuffer EmptyDecl2CBuffer {
+  ;
+  int X;
+}


        


More information about the cfe-commits mailing list