[clang] Attach resource attributes to handle within record, instead of record (PR #101433)

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 2 13:02:44 PDT 2024


================
@@ -112,17 +116,13 @@ struct BuiltinTypeDeclBuilder {
         Ty = Record->getASTContext().getPointerType(
             QualType(TTD->getTypeForDecl(), 0));
     }
-    return addMemberVariable("h", Ty, Access);
-  }
-
-  BuiltinTypeDeclBuilder &annotateHLSLResource(ResourceClass RC,
-                                               ResourceKind RK, bool IsROV) {
-    if (Record->isCompleteDefinition())
-      return *this;
-    Record->addAttr(
+    // add handle member
+    llvm::SmallVector<Attr *, 2> Attrs;
+    Attrs.push_back(
         HLSLResourceClassAttr::CreateImplicit(Record->getASTContext(), RC));
-    Record->addAttr(
+    Attrs.push_back(
         HLSLResourceAttr::CreateImplicit(Record->getASTContext(), RK, IsROV));
+    addMemberVariable("h", Ty, Attrs, Access);
----------------
bogner wrote:

With the change to use `ArrayRef` above, I find constructing the array as part of the call slightly more readable:
```c++
    Attr *ResourceClassAttr =
        HLSLResourceClassAttr::CreateImplicit(Record->getASTContext(), RC);
    Attr *ResourceAttr =
        HLSLResourceClassAttr::CreateImplicit(Record->getASTContext(), RC);
    addMemberVariable("h", Ty, {ResourceClassAttr, ResourceAttr}, Access);
```

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


More information about the cfe-commits mailing list