[clang] 9b98455 - [HLSL][NFC] Move IsIntangibleType from SemaHLSL to Type to make it accessible outside of Sema (#113206)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 22 16:32:14 PDT 2024
Author: Helena Kotas
Date: 2024-10-22T16:32:09-07:00
New Revision: 9b984554d769f1f81adb654345aa9ef37d5e5b44
URL: https://github.com/llvm/llvm-project/commit/9b984554d769f1f81adb654345aa9ef37d5e5b44
DIFF: https://github.com/llvm/llvm-project/commit/9b984554d769f1f81adb654345aa9ef37d5e5b44.diff
LOG: [HLSL][NFC] Move IsIntangibleType from SemaHLSL to Type to make it accessible outside of Sema (#113206)
Moves `IsIntangibleType` from SemaHLSL to Type class and renames it to
`isHLSLIntangibleType`. The existing `isHLSLIntangibleType` is renamed
to `isHLSLBuiltinIntangibleType` and updated to return true only for the
builtin `__hlsl_resource_t` type.
This change makes `isHLSLIntangibleType` functionality accessible
outside of Sema, for example from clang CodeGen.
Added:
Modified:
clang/include/clang/AST/Type.h
clang/include/clang/Sema/SemaHLSL.h
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaHLSL.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 40e617bf8f3b8d..ba3161c366f4d9 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2661,8 +2661,10 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) bool is##Id##Type() const;
#include "clang/Basic/HLSLIntangibleTypes.def"
bool isHLSLSpecificType() const; // Any HLSL specific type
- bool isHLSLIntangibleType() const; // Any HLSL intangible type
+ bool isHLSLBuiltinIntangibleType() const; // Any HLSL builtin intangible type
bool isHLSLAttributedResourceType() const;
+ bool isHLSLIntangibleType()
+ const; // Any HLSL intangible type (builtin, array, class)
/// Determines if this type, which must satisfy
/// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
@@ -8450,15 +8452,15 @@ inline bool Type::isOpenCLSpecificType() const {
}
#include "clang/Basic/HLSLIntangibleTypes.def"
-inline bool Type::isHLSLIntangibleType() const {
+inline bool Type::isHLSLBuiltinIntangibleType() const {
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) is##Id##Type() ||
return
#include "clang/Basic/HLSLIntangibleTypes.def"
- isHLSLAttributedResourceType();
+ false;
}
inline bool Type::isHLSLSpecificType() const {
- return isHLSLIntangibleType() || isa<HLSLAttributedResourceType>(this);
+ return isHLSLBuiltinIntangibleType() || isHLSLAttributedResourceType();
}
inline bool Type::isHLSLAttributedResourceType() const {
diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h
index 4f1fc9a31404c6..e30acd87f77218 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -132,7 +132,6 @@ class SemaHLSL : public SemaBase {
// HLSL Type trait implementations
bool IsScalarizedLayoutCompatible(QualType T1, QualType T2) const;
- bool IsIntangibleType(QualType T1);
bool CheckCompatibleParameterABI(FunctionDecl *New, FunctionDecl *Old);
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 34bb200e43360c..17ebee0d6b22fa 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1420,7 +1420,8 @@ void CXXRecordDecl::addedMember(Decl *D) {
if (const RecordType *RT = dyn_cast<RecordType>(Ty))
data().IsHLSLIntangible |= RT->getAsCXXRecordDecl()->isHLSLIntangible();
else
- data().IsHLSLIntangible |= Ty->isHLSLIntangibleType();
+ data().IsHLSLIntangible |= (Ty->isHLSLAttributedResourceType() ||
+ Ty->isHLSLBuiltinIntangibleType());
}
}
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 5232efae4e3630..0afba0a1c92aff 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -5030,6 +5030,29 @@ bool Type::hasSizedVLAType() const {
return false;
}
+bool Type::isHLSLIntangibleType() const {
+ const Type *Ty = getUnqualifiedDesugaredType();
+
+ // check if it's a builtin type first
+ if (Ty->isBuiltinType())
+ return Ty->isHLSLBuiltinIntangibleType();
+
+ // unwrap arrays
+ while (isa<ConstantArrayType>(Ty))
+ Ty = Ty->getArrayElementTypeNoTypeQual();
+
+ const RecordType *RT =
+ dyn_cast<RecordType>(Ty->getUnqualifiedDesugaredType());
+ if (!RT)
+ return false;
+
+ CXXRecordDecl *RD = RT->getAsCXXRecordDecl();
+ assert(RD != nullptr &&
+ "all HLSL struct and classes should be CXXRecordDecl");
+ assert(RD->isCompleteDefinition() && "expecting complete type");
+ return RD->isHLSLIntangible();
+}
+
QualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) {
switch (type.getObjCLifetime()) {
case Qualifiers::OCL_None:
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index e19016ab23abe7..50c1b24fce6da7 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5713,7 +5713,7 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
if (DiagnoseVLAInCXXTypeTrait(Self, TInfo,
tok::kw___builtin_hlsl_is_intangible))
return false;
- return Self.HLSL().IsIntangibleType(T);
+ return T->isHLSLIntangibleType();
}
}
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index c6627b0e993226..1f6c5b8d4561bc 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2104,32 +2104,6 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
return false;
}
-bool SemaHLSL::IsIntangibleType(clang::QualType QT) {
- if (QT.isNull())
- return false;
-
- const Type *Ty = QT->getUnqualifiedDesugaredType();
-
- // check if it's a builtin type first (simple check, no need to cache it)
- if (Ty->isBuiltinType())
- return Ty->isHLSLIntangibleType();
-
- // unwrap arrays
- while (isa<ConstantArrayType>(Ty))
- Ty = Ty->getArrayElementTypeNoTypeQual();
-
- const RecordType *RT =
- dyn_cast<RecordType>(Ty->getUnqualifiedDesugaredType());
- if (!RT)
- return false;
-
- CXXRecordDecl *RD = RT->getAsCXXRecordDecl();
- assert(RD != nullptr &&
- "all HLSL struct and classes should be CXXRecordDecl");
- assert(RD->isCompleteDefinition() && "expecting complete type");
- return RD->isHLSLIntangible();
-}
-
static void BuildFlattenedTypeList(QualType BaseTy,
llvm::SmallVectorImpl<QualType> &List) {
llvm::SmallVector<QualType, 16> WorkList;
@@ -2325,7 +2299,7 @@ void SemaHLSL::ActOnVariableDeclarator(VarDecl *VD) {
}
// find all resources on decl
- if (IsIntangibleType(VD->getType()))
+ if (VD->getType()->isHLSLIntangibleType())
collectResourcesOnVarDecl(VD);
// process explicit bindings
@@ -2336,7 +2310,7 @@ void SemaHLSL::ActOnVariableDeclarator(VarDecl *VD) {
// Walks though the global variable declaration, collects all resource binding
// requirements and adds them to Bindings
void SemaHLSL::collectResourcesOnVarDecl(VarDecl *VD) {
- assert(VD->hasGlobalStorage() && IsIntangibleType(VD->getType()) &&
+ assert(VD->hasGlobalStorage() && VD->getType()->isHLSLIntangibleType() &&
"expected global variable that contains HLSL resource");
// Cbuffers and Tbuffers are HLSLBufferDecl types
More information about the cfe-commits
mailing list