[clang] [HLSL] Implement TransformHLSLAttributedResourceType (PR #106673)
Helena Kotas via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 29 23:55:20 PDT 2024
https://github.com/hekota created https://github.com/llvm/llvm-project/pull/106673
Implements `TreeTransform<Derived>::TransformHLSLAttributedResourceType` which will enable use of attributed resource types inside templates.
Follow up from llvm/llvm-project#106181
Related to llvm/llvm-project#104861
>From f060654648707f3bf7ecf68b01db8d7c0a8b2bf6 Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Thu, 29 Aug 2024 23:51:54 -0700
Subject: [PATCH] [HLSL] Implement TransformHLSLAttributedResourceType to
enable attributed resource types inside templates
Follow up from #106181
Related to #104861
---
clang/include/clang/AST/TypeLoc.h | 6 ++++++
clang/lib/Sema/TreeTransform.h | 23 +++++++++++++++++++++--
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/clang/include/clang/AST/TypeLoc.h b/clang/include/clang/AST/TypeLoc.h
index 5db39eb3aefa74..2826bedd122d12 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -951,12 +951,18 @@ class HLSLAttributedResourceTypeLoc
HLSLAttributedResourceLocInfo> {
public:
TypeLoc getWrappedLoc() const { return getInnerTypeLoc(); }
+
+ TypeLoc getContainedLoc() const {
+ return TypeLoc(getTypePtr()->getContainedType(), getNonLocalData());
+ }
+
void setSourceRange(const SourceRange &R) { getLocalData()->Range = R; }
SourceRange getLocalSourceRange() const { return getLocalData()->Range; }
void initializeLocal(ASTContext &Context, SourceLocation loc) {
setSourceRange(SourceRange());
}
QualType getInnerType() const { return getTypePtr()->getWrappedType(); }
+ unsigned getLocalDataSize() const { return sizeof(HLSLAttributedResourceLocInfo); }
};
struct ObjCObjectTypeLocInfo {
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a4d5d71bd11274..feb0481ccd265a 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -7462,8 +7462,27 @@ QualType TreeTransform<Derived>::TransformBTFTagAttributedType(
template <typename Derived>
QualType TreeTransform<Derived>::TransformHLSLAttributedResourceType(
TypeLocBuilder &TLB, HLSLAttributedResourceTypeLoc TL) {
- llvm_unreachable(
- "Unexpected TreeTransform for HLSLAttributedResourceTypeLoc");
+
+ const HLSLAttributedResourceType *oldType = TL.getTypePtr();
+
+ QualType WrappedTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
+ if (WrappedTy.isNull())
+ return QualType();
+
+ QualType ContainedTy = QualType();
+ if (!oldType->getContainedType().isNull())
+ ContainedTy = getDerived().TransformType(TLB, TL.getContainedLoc());
+
+ QualType Result = TL.getType();
+ if (getDerived().AlwaysRebuild() ||
+ WrappedTy != oldType->getWrappedType() ||
+ ContainedTy != oldType->getContainedType()) {
+ Result = SemaRef.Context.getHLSLAttributedResourceType(
+ WrappedTy, ContainedTy, oldType->getAttrs());
+ }
+
+ TLB.push<HLSLAttributedResourceTypeLoc>(Result);
+ return Result;
}
template<typename Derived>
More information about the cfe-commits
mailing list