[clang] [HLSL] Add empty struct test cases to `__builtin_hlsl_is_typed_resource_element_compatible` test file (PR #115045)
Chris B via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 8 13:12:01 PST 2024
================
@@ -2200,47 +2200,43 @@ static void BuildFlattenedTypeList(QualType BaseTy,
}
bool SemaHLSL::IsTypedResourceElementCompatible(clang::QualType QT) {
- if (QT.isNull())
+ // null and array types are not allowed.
+ if (QT.isNull() || QT->isArrayType())
return false;
- // check if the outer type was an array type
- if (QT->isArrayType())
+ // UDT types are not allowed
+ clang::QualType CanonicalType = QT.getCanonicalType();
+ if (CanonicalType->getAs<clang::RecordType>()) {
return false;
+ }
- llvm::SmallVector<QualType, 4> QTTypes;
- BuildFlattenedTypeList(QT, QTTypes);
+ // the only other valid builtin types are scalars or vectors
+ if (const BuiltinType *BT = CanonicalType->getAs<BuiltinType>()) {
+ if (BT->isBooleanType() || BT->isEnumeralType())
+ return false;
- assert(QTTypes.size() > 0 &&
- "expected at least one constituent type from non-null type");
- QualType FirstQT = SemaRef.Context.getCanonicalType(QTTypes[0]);
+ int TotalSizeInBytes = SemaRef.Context.getTypeSize(BT) / 8;
- // element count cannot exceed 4
- if (QTTypes.size() > 4)
- return false;
-
- for (QualType TempQT : QTTypes) {
- // ensure homogeneity
- if (!getASTContext().hasSameUnqualifiedType(FirstQT, TempQT))
+ if (TotalSizeInBytes > 16)
return false;
+ return true;
}
- if (const BuiltinType *BT = FirstQT->getAs<BuiltinType>()) {
- if (BT->isBooleanType() || BT->isEnumeralType())
+ if (const VectorType *VT = CanonicalType->getAs<VectorType>()) {
+ int ArraySize = VT->getNumElements();
+
+ if (ArraySize > 4)
return false;
- // Check if it is an array type.
- if (FirstQT->isArrayType())
+ QualType ElTy = VT->getElementType();
+ int TotalSizeInBytes = (SemaRef.Context.getTypeSize(ElTy) / 8) * ArraySize;
+
+ if (TotalSizeInBytes > 16)
----------------
llvm-beanz wrote:
Can this be simplified to:
```suggestion
if (SemaRef.Context.getTypeSize(QT) > 16)
```
https://github.com/llvm/llvm-project/pull/115045
More information about the cfe-commits
mailing list