Skip to content

Commit 8848330

Browse files
committed
Rewrite isHLSLResrouceWrapper as suggested
1 parent ff84239 commit 8848330

File tree

3 files changed

+8
-27
lines changed

3 files changed

+8
-27
lines changed

clang/include/clang/AST/Type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2661,7 +2661,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
26612661
bool isHLSLSpecificType() const; // Any HLSL specific type
26622662
bool isHLSLBuiltinIntangibleType() const; // Any HLSL builtin intangible type
26632663
bool isHLSLAttributedResourceType() const;
2664-
bool isHLSLResourceWrapper() const;
2664+
bool isHLSLResourceClass() const;
26652665
bool isHLSLIntangibleType()
26662666
const; // Any HLSL intangible type (builtin, array, class)
26672667

clang/lib/AST/Type.cpp

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5114,31 +5114,8 @@ bool Type::hasSizedVLAType() const {
51145114
return false;
51155115
}
51165116

5117-
bool Type::isHLSLResourceWrapper() const {
5118-
const Type *Ty = getUnqualifiedDesugaredType();
5119-
5120-
// check if it's a builtin type first
5121-
if (Ty->isBuiltinType())
5122-
return Ty->isHLSLBuiltinIntangibleType();
5123-
5124-
// unwrap arrays
5125-
while (isa<ConstantArrayType>(Ty))
5126-
Ty = Ty->getArrayElementTypeNoTypeQual();
5127-
5128-
const RecordType *RT =
5129-
dyn_cast<RecordType>(Ty->getUnqualifiedDesugaredType());
5130-
if (!RT)
5131-
return false;
5132-
5133-
CXXRecordDecl *RD = RT->getAsCXXRecordDecl();
5134-
assert(RD != nullptr &&
5135-
"all HLSL structs and classes should be CXXRecordDecl");
5136-
assert(RD->isCompleteDefinition() && "expecting complete type");
5137-
if (RD->field_empty()) {
5138-
return false;
5139-
}
5140-
const FieldDecl *FirstField = *RD->field_begin();
5141-
return FirstField->getType()->isHLSLAttributedResourceType();
5117+
bool Type::isHLSLResourceClass() const {
5118+
return HLSLAttributedResourceType::findHandleTypeOnResource(this) != nullptr;
51425119
}
51435120

51445121
bool Type::isHLSLIntangibleType() const {

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3065,7 +3065,11 @@ void SemaHLSL::ActOnVariableDeclarator(VarDecl *VD) {
30653065
if (VD->getType()->isHLSLIntangibleType())
30663066
collectResourceBindingsOnVarDecl(VD);
30673067

3068-
if (VD->getType()->isHLSLResourceWrapper()) {
3068+
const Type *VarType = VD->getType().getTypePtr();
3069+
if (VarType->isArrayType()) {
3070+
VarType = VarType->getArrayElementTypeNoTypeQual();
3071+
}
3072+
if (VarType->isHLSLResourceClass()) {
30693073
// Make the variable for resources static. The global externally visible
30703074
// storage is accessed through the handle, which is a member. The variable
30713075
// itself is not externally visible.

0 commit comments

Comments
 (0)