[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) {
----------------
bogner wrote:

This reads more simply if you just test the result of the function in the if condition. Also, you probably don't need quite that verbose of a name for the identifier, so I'd probably write this like:
```c++
  if (!HLSLResourceClassAttr::ConvertStrToResourceClass(Identifier, RC)) {
```

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


More information about the cfe-commits mailing list