[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 4 12:42:38 PDT 2024


================
@@ -556,46 +562,120 @@ 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;
-  }
+bool clang::CreateHLSLAttributedResourceType(
+    Sema &S, QualType Wrapped, llvm::SmallVector<const Attr *> &AttrList,
+    QualType &ResType) {
+  assert(AttrList.size() && "expected list of resource attributes");
 
-  IdentifierLoc *Loc = AL.getArgAsIdent(0);
-  StringRef Identifier = Loc->Ident->getName();
-  SourceLocation ArgLoc = Loc->Loc;
+  QualType Contained = QualType();
+  HLSLAttributedResourceType::Attributes ResAttrs = {};
 
-  // Validate.
-  llvm::dxil::ResourceClass RC;
-  if (!HLSLResourceClassAttr::ConvertStrToResourceClass(Identifier, RC)) {
-    Diag(ArgLoc, diag::warn_attribute_type_not_supported)
-        << "ResourceClass" << Identifier;
-    return;
+  bool hasResourceClass = false;
+  for (auto *Attr : AttrList) {
+    if (!Attr)
+      continue;
+    switch (Attr->getKind()) {
+    case attr::HLSLResourceClass: {
+      llvm::dxil::ResourceClass RC =
+          dyn_cast<HLSLResourceClassAttr>(Attr)->getResourceClass();
+      if (!hasResourceClass) {
+        ResAttrs.ResourceClass = RC;
+        hasResourceClass = true;
+      } else if (RC != ResAttrs.ResourceClass) {
+        S.Diag(Attr->getLocation(), diag::warn_duplicate_attribute) << Attr;
+        return false;
+      }
----------------
bogner wrote:

Do we really want `__hlsl_resource_t [[hlsl::resource_class(SRV)]][[hlsl::resource_class(SRV)]] H` to be valid? Maybe we should warn even if the RC does match.

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


More information about the cfe-commits mailing list