[clang] Implement resource binding type prefix mismatch errors (PR #87578)

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 22 11:50:35 PDT 2024


================
@@ -7334,6 +7334,81 @@ static void handleHLSLShaderAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
     D->addAttr(NewAttr);
 }
 
+static void DiagnoseHLSLResourceRegType(Sema &S, SourceLocation &ArgLoc,
+                                        Decl *D, StringRef &Slot) {
+  // Samplers, UAVs, and SRVs are VarDecl types
+  VarDecl *SamplerUAVOrSRV = dyn_cast<VarDecl>(D);
+  // Cbuffers and Tbuffers are HLSLBufferDecl types
+  HLSLBufferDecl *CBufferOrTBuffer = dyn_cast<HLSLBufferDecl>(D);
+  if (!SamplerUAVOrSRV && !CBufferOrTBuffer)
+    return;
+
+  llvm::hlsl::ResourceClass DeclResourceClass;
+  StringRef varTy = "";
+  if (SamplerUAVOrSRV) {
+    const Type *Ty = SamplerUAVOrSRV->getType()->getPointeeOrArrayElementType();
+    if (!Ty)
+      llvm_unreachable("Resource class should have an element type.");
----------------
bogner wrote:

I probably just read too many RFCs, but it'd be better to use "must" rather than "should" in this message.

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


More information about the cfe-commits mailing list