@@ -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 {
@@ -1001,8 +1020,8 @@ bool isResourceDescriptorHeap(const Decl *D) {
10011020}
10021021
10031022bool isResourceDescriptorHeap (QualType T) {
1004- const RecordType *RT = T-> getAs <RecordType>( );
1005- return RT && RT-> getDecl ()-> getName () == " .Resource " ;
1023+ const HLSLDynamicResourceAttr *Attr = getAttr<HLSLDynamicResourceAttr>(T );
1024+ return Attr && !Attr-> getIsSampler () ;
10061025}
10071026
10081027bool isSamplerDescriptorHeap (const Decl *D) {
@@ -1011,8 +1030,8 @@ bool isSamplerDescriptorHeap(const Decl *D) {
10111030}
10121031
10131032bool isSamplerDescriptorHeap (QualType T) {
1014- const RecordType *RT = T-> getAs <RecordType>( );
1015- return RT && RT-> getDecl ()-> getName () == " .Sampler " ;
1033+ const HLSLDynamicResourceAttr *Attr = getAttr<HLSLDynamicResourceAttr>(T );
1034+ return Attr && Attr-> getIsSampler () ;
10161035}
10171036
10181037bool isAKindOfStructuredOrByteBuffer (QualType type) {
0 commit comments