[clang] [HLSL] Implement TransformHLSLAttributedResourceType (PR #106673)
Helena Kotas via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 30 12:32:36 PDT 2024
https://github.com/hekota updated https://github.com/llvm/llvm-project/pull/106673
>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 1/2] [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>
>From 3088b923668bb6a1b47ef269af17552711b74ead Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Fri, 30 Aug 2024 12:32:17 -0700
Subject: [PATCH 2/2] clang-format
---
clang/include/clang/AST/TypeLoc.h | 6 ++++--
clang/lib/Sema/TreeTransform.h | 3 +--
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/clang/include/clang/AST/TypeLoc.h b/clang/include/clang/AST/TypeLoc.h
index 2826bedd122d12..03fbdcf60140df 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -952,7 +952,7 @@ class HLSLAttributedResourceTypeLoc
public:
TypeLoc getWrappedLoc() const { return getInnerTypeLoc(); }
- TypeLoc getContainedLoc() const {
+ TypeLoc getContainedLoc() const {
return TypeLoc(getTypePtr()->getContainedType(), getNonLocalData());
}
@@ -962,7 +962,9 @@ class HLSLAttributedResourceTypeLoc
setSourceRange(SourceRange());
}
QualType getInnerType() const { return getTypePtr()->getWrappedType(); }
- unsigned getLocalDataSize() const { return sizeof(HLSLAttributedResourceLocInfo); }
+ unsigned getLocalDataSize() const {
+ return sizeof(HLSLAttributedResourceLocInfo);
+ }
};
struct ObjCObjectTypeLocInfo {
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index feb0481ccd265a..0513e7b13bc778 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -7474,8 +7474,7 @@ QualType TreeTransform<Derived>::TransformHLSLAttributedResourceType(
ContainedTy = getDerived().TransformType(TLB, TL.getContainedLoc());
QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- WrappedTy != oldType->getWrappedType() ||
+ if (getDerived().AlwaysRebuild() || WrappedTy != oldType->getWrappedType() ||
ContainedTy != oldType->getContainedType()) {
Result = SemaRef.Context.getHLSLAttributedResourceType(
WrappedTy, ContainedTy, oldType->getAttrs());
More information about the cfe-commits
mailing list