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

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 3 15:35:27 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 18cf14efe3e82b2343817fd174bcac48244c8f50 337a9ed1d5e7c71fb5be5741afe7726f5b76af7b --extensions h,cpp -- clang/include/clang/AST/TypeLoc.h clang/include/clang/Sema/SemaHLSL.h clang/lib/AST/TypePrinter.cpp clang/lib/CodeGen/CGHLSLRuntime.cpp clang/lib/Sema/HLSLExternalSemaSource.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaHLSL.cpp clang/lib/Sema/TreeTransform.h
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h
index 5131458863..29480d8f3e 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -89,9 +89,10 @@ public:
 private:
   // HLSL resource type attributes need to be processed all at once.
   // This is a list to collect them.
-  llvm::SmallVector<const Attr*> HLSLResourcesTypeAttrs;
+  llvm::SmallVector<const Attr *> HLSLResourcesTypeAttrs;
 
-  /// SourceRanges corresponding to HLSLAttributedResourceTypeLocs that we have not yet populated.
+  /// SourceRanges corresponding to HLSLAttributedResourceTypeLocs that we have
+  /// not yet populated.
   llvm::DenseMap<const HLSLAttributedResourceType *, SourceLocation>
       LocsForHLSLAttributedResources;
 };
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 0716406933..37d24eefb5 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -124,13 +124,13 @@ struct BuiltinTypeDeclBuilder {
 
     // add handle member with resource type attributes
     QualType AttributedResTy = QualType();
-    SmallVector<const Attr*> Attrs = {
-      HLSLResourceClassAttr::CreateImplicit(Record->getASTContext(), RC),
-      IsROV ? HLSLROVAttr::CreateImplicit(Record->getASTContext()) : nullptr
-    };
+    SmallVector<const Attr *> Attrs = {
+        HLSLResourceClassAttr::CreateImplicit(Record->getASTContext(), RC),
+        IsROV ? HLSLROVAttr::CreateImplicit(Record->getASTContext()) : nullptr};
     Attr *ResourceAttr =
         HLSLResourceAttr::CreateImplicit(Record->getASTContext(), RK);
-    if (SemaHLSL::CreateHLSLAttributedResourceType(S, Ty, Attrs, AttributedResTy)) {
+    if (SemaHLSL::CreateHLSLAttributedResourceType(S, Ty, Attrs,
+                                                   AttributedResTy)) {
       addMemberVariable("h", AttributedResTy, {ResourceAttr}, Access);
     }
     return *this;
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 69f4382e46..e2ec89ef6e 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -562,7 +562,9 @@ void SemaHLSL::handleShaderAttr(Decl *D, const ParsedAttr &AL) {
     D->addAttr(NewAttr);
 }
 
-bool SemaHLSL::CreateHLSLAttributedResourceType(Sema &S, QualType Wrapped, llvm::SmallVector<const Attr *> &AttrList, QualType &ResType) {
+bool SemaHLSL::CreateHLSLAttributedResourceType(
+    Sema &S, QualType Wrapped, llvm::SmallVector<const Attr *> &AttrList,
+    QualType &ResType) {
   assert(AttrList.size() && "expected list of resource attributes");
 
   QualType Contained = QualType();
@@ -574,7 +576,8 @@ bool SemaHLSL::CreateHLSLAttributedResourceType(Sema &S, QualType Wrapped, llvm:
       continue;
     switch (Attr->getKind()) {
     case attr::HLSLResourceClass: {
-      llvm::dxil::ResourceClass RC = dyn_cast<HLSLResourceClassAttr>(Attr)->getResourceClass();
+      llvm::dxil::ResourceClass RC =
+          dyn_cast<HLSLResourceClassAttr>(Attr)->getResourceClass();
       if (!hasResourceClass) {
         ResAttrs.ResourceClass = RC;
         hasResourceClass = true;
@@ -593,11 +596,13 @@ bool SemaHLSL::CreateHLSLAttributedResourceType(Sema &S, QualType Wrapped, llvm:
   }
 
   if (!hasResourceClass) {
-    S.Diag(AttrList.back()->getRange().getEnd(), diag::err_missing_resource_class);
+    S.Diag(AttrList.back()->getRange().getEnd(),
+           diag::err_missing_resource_class);
     return false;
   }
 
-  ResType = S.getASTContext().getHLSLAttributedResourceType(Wrapped, Contained, ResAttrs);
+  ResType = S.getASTContext().getHLSLAttributedResourceType(Wrapped, Contained,
+                                                            ResAttrs);
   return true;
 }
 
@@ -651,8 +656,10 @@ QualType SemaHLSL::ProcessResourceTypeAttributes(QualType CurrentType) {
     return CurrentType;
 
   QualType QT = CurrentType;
-  if (CreateHLSLAttributedResourceType(SemaRef, CurrentType, HLSLResourcesTypeAttrs, QT)) {
-    const HLSLAttributedResourceType *RT = dyn_cast<HLSLAttributedResourceType>(QT.getTypePtr());
+  if (CreateHLSLAttributedResourceType(SemaRef, CurrentType,
+                                       HLSLResourcesTypeAttrs, QT)) {
+    const HLSLAttributedResourceType *RT =
+        dyn_cast<HLSLAttributedResourceType>(QT.getTypePtr());
     SourceLocation Loc = HLSLResourcesTypeAttrs[0]->getLoc();
     LocsForHLSLAttributedResources.insert(std::pair(RT, Loc));
   }
@@ -726,7 +733,8 @@ static void updateResourceClassFlagsFromDeclResourceClass(
   }
 }
 
-const HLSLAttributedResourceType *findAttributedResourceTypeOnField(VarDecl *VD) {
+const HLSLAttributedResourceType *
+findAttributedResourceTypeOnField(VarDecl *VD) {
   assert(VD != nullptr && "expected VarDecl");
   if (RecordDecl *RD = getRecordDeclFromVarDecl(VD)) {
     for (auto *FD : RD->fields()) {
@@ -760,7 +768,8 @@ static void updateResourceClassFlagsFromRecordType(RegisterBindingFlags &Flags,
       const Type *FieldTy = FD->getType().getTypePtr();
       if (const HLSLAttributedResourceType *AttrResType =
               dyn_cast<HLSLAttributedResourceType>(FieldTy)) {
-        updateResourceClassFlagsFromDeclResourceClass(Flags, AttrResType->getAttrs().ResourceClass);
+        updateResourceClassFlagsFromDeclResourceClass(
+            Flags, AttrResType->getAttrs().ResourceClass);
         continue;
       }
       TypesToScan.emplace_back(FD->getType().getTypePtr());

``````````

</details>


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


More information about the cfe-commits mailing list