[clang] Implement resource binding type prefix mismatch flag setting logic (PR #97103)

Chris B via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 8 18:05:05 PDT 2024


================
@@ -38,6 +38,22 @@ Decl *SemaHLSL::ActOnStartBuffer(Scope *BufferScope, bool CBuffer,
   HLSLBufferDecl *Result = HLSLBufferDecl::Create(
       getASTContext(), LexicalParent, CBuffer, KwLoc, Ident, IdentLoc, LBrace);
 
+  HLSLResourceAttr *NewAttr;
+  if (CBuffer) {
+    NewAttr = HLSLResourceAttr::CreateImplicit(
+        getASTContext(), llvm::hlsl::ResourceClass::CBuffer,
+        llvm::hlsl::ResourceKind::CBuffer,
+        /*IsROV=*/false);
+  }
+  // tbuffer case
+  else {
+    NewAttr = HLSLResourceAttr::CreateImplicit(
+        getASTContext(), llvm::hlsl::ResourceClass::SRV,
+        llvm::hlsl::ResourceKind::TBuffer,
+        /*IsROV=*/false);
+  }
+  Result->addAttr(NewAttr);
----------------
llvm-beanz wrote:

```suggestion
  auto RC = CBuffer ? llvm::hlsl::ResourceClass::CBuffer : llvm::hlsl::ResourceClass::SRV;
  auto RK = CBuffer ? llvm::hlsl::ResourceKind::CBuffer : llvm::hlsl::ResourceKind::TBuffer
  D->addAttr(HLSLResourceAttr::CreateImplicit(getASTContext(),RC, RK, /*IsROV=*/false));
```

nit: the formatting for this is off, but I think this is a simpler way to write it.

https://github.com/llvm/llvm-project/pull/97103


More information about the cfe-commits mailing list