[clang] [HLSL] add IsTypedResourceElementCompatible type trait (PR #114864)
Chris B via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 5 06:39:01 PST 2024
================
@@ -2163,6 +2163,50 @@ static void BuildFlattenedTypeList(QualType BaseTy,
}
}
+bool SemaHLSL::IsTypedResourceElementCompatible(clang::QualType QT) {
+ if (QT.isNull())
+ return false;
+
+ // check if the outer type was an array type
+ if (QT->isArrayType())
+ return false;
+
+ llvm::SmallVector<QualType, 4> QTTypes;
+ BuildFlattenedTypeList(QT, QTTypes);
+
+ assert(QTTypes.size() > 0 &&
----------------
llvm-beanz wrote:
That's an incomplete type, not an empty struct. What about something like:
```hlsl
struct EmptyStruct {};
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EmptyStruct), "");
struct EmptyDerived : EmptyStruct {};
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EmptyDerived), "");
struct EmptyBase : EmptyStruct {
int4 V;
};
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(EmptyBase), "");
```
We frequently find bugs in DXC with cases of empty structs, empty base classes, etc.
https://github.com/llvm/llvm-project/pull/114864
More information about the cfe-commits
mailing list