Skip to content

[HLSL][NFC] Move IsIntangibleType from SemaHLSL to Type to make it accessible outside of Sema #113206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion clang/include/clang/Sema/SemaHLSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion clang/lib/AST/DeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,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());
}
}

Expand Down
23 changes: 23 additions & 0 deletions clang/lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
30 changes: 2 additions & 28 deletions clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading