@@ -23,6 +23,25 @@ clang::DiagnosticBuilder emitError(const clang::ASTContext &astContext,
2323 clang::DiagnosticsEngine::Error, message);
2424 return astContext.getDiagnostics ().Report (srcLoc, diagId);
2525}
26+
27+ // Returns the attribute of the given type attached to the record declaration
28+ // behind \p type, or nullptr if there is none. Attributes live on the
29+ // declaration, so they cannot be retrieved with QualType::getAs (which only
30+ // navigates the clang::Type hierarchy).
31+ template <typename AttrType> AttrType *getAttr (clang::QualType type) {
32+ type = type.getCanonicalType ();
33+ if (const clang::RecordType *RT = type->getAs <clang::RecordType>()) {
34+ if (const auto *Spec =
35+ clang::dyn_cast<clang::ClassTemplateSpecializationDecl>(
36+ RT ->getDecl ()))
37+ if (const auto *Template = clang::dyn_cast<clang::ClassTemplateDecl>(
38+ Spec->getSpecializedTemplate ()))
39+ return Template->getTemplatedDecl ()->getAttr <AttrType>();
40+ if (const auto *Decl = clang::dyn_cast<clang::CXXRecordDecl>(RT ->getDecl ()))
41+ return Decl->getAttr <AttrType>();
42+ }
43+ return nullptr ;
44+ }
2645} // namespace
2746
2847namespace clang {
@@ -1021,8 +1040,8 @@ bool isResourceDescriptorHeap(const Decl *D) {
10211040}
10221041
10231042bool isResourceDescriptorHeap (QualType T) {
1024- const RecordType * RT = T-> getAs <RecordType>( );
1025- return RT && RT -> getDecl ()-> getName () == " .Resource " ;
1043+ const HLSLDynamicResourceAttr *Attr = getAttr<HLSLDynamicResourceAttr>(T );
1044+ return Attr && !Attr-> getIsSampler () ;
10261045}
10271046
10281047bool isSamplerDescriptorHeap (const Decl *D) {
@@ -1031,8 +1050,8 @@ bool isSamplerDescriptorHeap(const Decl *D) {
10311050}
10321051
10331052bool isSamplerDescriptorHeap (QualType T) {
1034- const RecordType * RT = T-> getAs <RecordType>( );
1035- return RT && RT -> getDecl ()-> getName () == " .Sampler " ;
1053+ const HLSLDynamicResourceAttr *Attr = getAttr<HLSLDynamicResourceAttr>(T );
1054+ return Attr && Attr-> getIsSampler () ;
10361055}
10371056
10381057bool isAKindOfStructuredOrByteBuffer (QualType type) {
0 commit comments