From 8b18659aef23fd63b713dff6109b710bd88242ed Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Fri, 21 Jun 2024 11:20:16 -0400 Subject: [PATCH] Avoid adding types to default namespace (#6700) Some of the types that have been added to the vk namespace were being added to the default namespace when compiling for DXIL. The if conditions were such that they would fall through to a default case. The solution is to explicitly add code that we should skip adding those builtin types when the vk namespace is not defined. Fixes #6646. --- tools/clang/lib/Sema/SemaHLSL.cpp | 26 +++++++++++++------ .../clang/test/SemaHLSL/vk.types.in.dxil.hlsl | 12 +++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 tools/clang/test/SemaHLSL/vk.types.in.dxil.hlsl diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 5159a5c28..4df32f9a6 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -3817,29 +3817,41 @@ private: recordDecl = m_ThreadNodeOutputRecordsTemplateDecl->getTemplatedDecl(); } #ifdef ENABLE_SPIRV_CODEGEN - else if (kind == AR_OBJECT_VK_SPIRV_TYPE && m_vkNSDecl) { + else if (kind == AR_OBJECT_VK_SPIRV_TYPE) { + if (!m_vkNSDecl) + continue; recordDecl = DeclareInlineSpirvType(*m_context, m_vkNSDecl, typeName, false); recordDecl->setImplicit(true); - } else if (kind == AR_OBJECT_VK_SPIRV_OPAQUE_TYPE && m_vkNSDecl) { + } else if (kind == AR_OBJECT_VK_SPIRV_OPAQUE_TYPE) { + if (!m_vkNSDecl) + continue; recordDecl = DeclareInlineSpirvType(*m_context, m_vkNSDecl, typeName, true); recordDecl->setImplicit(true); - } else if (kind == AR_OBJECT_VK_INTEGRAL_CONSTANT && m_vkNSDecl) { + } else if (kind == AR_OBJECT_VK_INTEGRAL_CONSTANT) { + if (!m_vkNSDecl) + continue; recordDecl = DeclareVkIntegralConstant(*m_context, m_vkNSDecl, typeName, &m_vkIntegralConstantTemplateDecl); recordDecl->setImplicit(true); - } else if (kind == AR_OBJECT_VK_LITERAL && m_vkNSDecl) { + } else if (kind == AR_OBJECT_VK_LITERAL) { + if (!m_vkNSDecl) + continue; recordDecl = DeclareTemplateTypeWithHandleInDeclContext( *m_context, m_vkNSDecl, typeName, 1, nullptr); recordDecl->setImplicit(true); m_vkLiteralTemplateDecl = recordDecl->getDescribedClassTemplate(); - } else if (kind == AR_OBJECT_VK_SPV_INTRINSIC_TYPE && m_vkNSDecl) { + } else if (kind == AR_OBJECT_VK_SPV_INTRINSIC_TYPE) { + if (!m_vkNSDecl) + continue; recordDecl = DeclareUIntTemplatedTypeWithHandleInDeclContext( *m_context, m_vkNSDecl, typeName, "id"); recordDecl->setImplicit(true); - } else if (kind == AR_OBJECT_VK_SPV_INTRINSIC_RESULT_ID && m_vkNSDecl) { + } else if (kind == AR_OBJECT_VK_SPV_INTRINSIC_RESULT_ID) { + if (!m_vkNSDecl) + continue; recordDecl = DeclareTemplateTypeWithHandleInDeclContext( *m_context, m_vkNSDecl, typeName, 1, nullptr); recordDecl->setImplicit(true); @@ -4505,8 +4517,6 @@ public: int startDepth = (templateArgCount == 0) ? 0 : 1; CXXRecordDecl *recordDecl = m_objectTypeDecls[i]; if (recordDecl == nullptr) { - DXASSERT(kind == AR_OBJECT_WAVE, - "else objects other than reserved not initialized"); continue; } diff --git a/tools/clang/test/SemaHLSL/vk.types.in.dxil.hlsl b/tools/clang/test/SemaHLSL/vk.types.in.dxil.hlsl new file mode 100644 index 000000000..41d9bd650 --- /dev/null +++ b/tools/clang/test/SemaHLSL/vk.types.in.dxil.hlsl @@ -0,0 +1,12 @@ +// RUN: %dxc -T ps_6_0 -E PSMain -fcgl %s -verify + +static const integral_constant MyVar; // expected-error{{unknown type name 'integral_constant'}} +static const SpirvType MyVar; // expected-error{{unknown type name 'SpirvType'}} +static const SpirvOpaqueType MyVar; // expected-error{{unknown type name 'SpirvOpaqueType'}} +static const Literal MyVar; // expected-error{{unknown type name 'Literal'}} + +float4 PSMain() : SV_TARGET +{ + return float4(1.0, 1.0, 1.0, 1.0); +} +