[clang] [HLSL] Split out resource class data from resource attribute (PR #98419)

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 11 14:50:10 PDT 2024


================
@@ -437,6 +437,33 @@ void SemaHLSL::handleShaderAttr(Decl *D, const ParsedAttr &AL) {
     D->addAttr(NewAttr);
 }
 
+void SemaHLSL::handleResourceClassAttr(Decl *D, const ParsedAttr &AL) {
+  if (!AL.isArgIdent(0)) {
+    Diag(AL.getLoc(), diag::err_attribute_argument_type)
+        << AL << AANT_ArgumentIdentifier;
+    return;
+  }
+
+  IdentifierLoc *Loc = AL.getArgAsIdent(0);
+  StringRef ResourceClassTypeStrRef = Loc->Ident->getName();
+  SourceLocation ArgLoc = Loc->Loc;
+
+  // Validate.
+  llvm::dxil::ResourceClass RC;
+  bool succ = HLSLResourceClassAttr::ConvertStrToResourceClass(
+      ResourceClassTypeStrRef, RC);
+  if (!succ) {
+    Diag(ArgLoc, diag::warn_attribute_type_not_supported)
+        << "ResourceClass" << ResourceClassTypeStrRef;
+    return;
+  }
+
+  HLSLResourceClassAttr *NewAttr =
+      HLSLResourceClassAttr::Create(getASTContext(), RC, ArgLoc);
+  if (NewAttr)
----------------
bogner wrote:

Can `HLSLResourceClassAttr::Create(...)` fail? Does it actually make sense to check if `NewAttr` is null here?

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


More information about the cfe-commits mailing list