[clang] [HLSL] Add empty struct test cases to `__builtin_hlsl_is_typed_resource_element_compatible` test file (PR #115045)
Joshua Batista via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 5 10:59:14 PST 2024
https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/115045
>From ef4a7eea3eacce4f77b628aebe7f2838733971d0 Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Tue, 5 Nov 2024 10:35:59 -0800
Subject: [PATCH 1/2] add empty struct test cases
---
.../SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl | 2 ++
1 file changed, 2 insertions(+)
diff --git a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
index acc1f281daddfc..08d75a0c23b228 100644
--- a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
+++ b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
@@ -107,3 +107,5 @@ struct TypeDefTest {
};
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(TypeDefTest), "");
+
+
>From 0ed4809a4bb12618e885914c09ba83e44c9c83c9 Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Tue, 5 Nov 2024 10:58:58 -0800
Subject: [PATCH 2/2] remove assert, return false instead
---
clang/lib/Sema/SemaHLSL.cpp | 6 ++++--
.../Types/Traits/IsTypedResourceElementCompatible.hlsl | 9 +++++++++
.../Traits/IsTypedResourceElementCompatibleErrors.hlsl | 1 -
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 298b7ad4f9e687..4b5b5aa96d5c20 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2210,8 +2210,10 @@ bool SemaHLSL::IsTypedResourceElementCompatible(clang::QualType QT) {
llvm::SmallVector<QualType, 4> QTTypes;
BuildFlattenedTypeList(QT, QTTypes);
- assert(QTTypes.size() > 0 &&
- "expected at least one constituent type from non-null type");
+ // empty structs are not typed resource element compatible
+ if (QTTypes.size() == 0)
+ return false;
+
QualType FirstQT = SemaRef.Context.getCanonicalType(QTTypes[0]);
// element count cannot exceed 4
diff --git a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
index 08d75a0c23b228..0a124be3e0aa60 100644
--- a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
+++ b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
@@ -108,4 +108,13 @@ struct TypeDefTest {
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(TypeDefTest), "");
+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), "");
diff --git a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl
index cb3e9ae7a61509..1cc9880e5b25f1 100644
--- a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl
+++ b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl
@@ -7,4 +7,3 @@ _Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(__hlsl_resour
struct notComplete;
// expected-error at +1{{incomplete type 'notComplete' where a complete type is required}}
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(notComplete), "");
-
More information about the cfe-commits
mailing list