Skip to content

Commit 0ed4809

Browse files
committed
remove assert, return false instead
1 parent ef4a7ee commit 0ed4809

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,8 +2210,10 @@ bool SemaHLSL::IsTypedResourceElementCompatible(clang::QualType QT) {
22102210
llvm::SmallVector<QualType, 4> QTTypes;
22112211
BuildFlattenedTypeList(QT, QTTypes);
22122212

2213-
assert(QTTypes.size() > 0 &&
2214-
"expected at least one constituent type from non-null type");
2213+
// empty structs are not typed resource element compatible
2214+
if (QTTypes.size() == 0)
2215+
return false;
2216+
22152217
QualType FirstQT = SemaRef.Context.getCanonicalType(QTTypes[0]);
22162218

22172219
// element count cannot exceed 4

clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,13 @@ struct TypeDefTest {
108108

109109
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(TypeDefTest), "");
110110

111+
struct EmptyStruct {};
112+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EmptyStruct), "");
111113

114+
struct EmptyDerived : EmptyStruct {};
115+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EmptyDerived), "");
116+
117+
struct EmptyBase : EmptyStruct {
118+
int4 V;
119+
};
120+
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(EmptyBase), "");

clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ _Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(__hlsl_resour
77
struct notComplete;
88
// expected-error@+1{{incomplete type 'notComplete' where a complete type is required}}
99
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(notComplete), "");
10-

0 commit comments

Comments
 (0)