Skip to content

Commit 8b18659

Browse files
authored
Avoid adding types to default namespace (microsoft#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 microsoft#6646.
1 parent 1f8f796 commit 8b18659

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3817,29 +3817,41 @@ class HLSLExternalSource : public ExternalSemaSource {
38173817
recordDecl = m_ThreadNodeOutputRecordsTemplateDecl->getTemplatedDecl();
38183818
}
38193819
#ifdef ENABLE_SPIRV_CODEGEN
3820-
else if (kind == AR_OBJECT_VK_SPIRV_TYPE && m_vkNSDecl) {
3820+
else if (kind == AR_OBJECT_VK_SPIRV_TYPE) {
3821+
if (!m_vkNSDecl)
3822+
continue;
38213823
recordDecl =
38223824
DeclareInlineSpirvType(*m_context, m_vkNSDecl, typeName, false);
38233825
recordDecl->setImplicit(true);
3824-
} else if (kind == AR_OBJECT_VK_SPIRV_OPAQUE_TYPE && m_vkNSDecl) {
3826+
} else if (kind == AR_OBJECT_VK_SPIRV_OPAQUE_TYPE) {
3827+
if (!m_vkNSDecl)
3828+
continue;
38253829
recordDecl =
38263830
DeclareInlineSpirvType(*m_context, m_vkNSDecl, typeName, true);
38273831
recordDecl->setImplicit(true);
3828-
} else if (kind == AR_OBJECT_VK_INTEGRAL_CONSTANT && m_vkNSDecl) {
3832+
} else if (kind == AR_OBJECT_VK_INTEGRAL_CONSTANT) {
3833+
if (!m_vkNSDecl)
3834+
continue;
38293835
recordDecl =
38303836
DeclareVkIntegralConstant(*m_context, m_vkNSDecl, typeName,
38313837
&m_vkIntegralConstantTemplateDecl);
38323838
recordDecl->setImplicit(true);
3833-
} else if (kind == AR_OBJECT_VK_LITERAL && m_vkNSDecl) {
3839+
} else if (kind == AR_OBJECT_VK_LITERAL) {
3840+
if (!m_vkNSDecl)
3841+
continue;
38343842
recordDecl = DeclareTemplateTypeWithHandleInDeclContext(
38353843
*m_context, m_vkNSDecl, typeName, 1, nullptr);
38363844
recordDecl->setImplicit(true);
38373845
m_vkLiteralTemplateDecl = recordDecl->getDescribedClassTemplate();
3838-
} else if (kind == AR_OBJECT_VK_SPV_INTRINSIC_TYPE && m_vkNSDecl) {
3846+
} else if (kind == AR_OBJECT_VK_SPV_INTRINSIC_TYPE) {
3847+
if (!m_vkNSDecl)
3848+
continue;
38393849
recordDecl = DeclareUIntTemplatedTypeWithHandleInDeclContext(
38403850
*m_context, m_vkNSDecl, typeName, "id");
38413851
recordDecl->setImplicit(true);
3842-
} else if (kind == AR_OBJECT_VK_SPV_INTRINSIC_RESULT_ID && m_vkNSDecl) {
3852+
} else if (kind == AR_OBJECT_VK_SPV_INTRINSIC_RESULT_ID) {
3853+
if (!m_vkNSDecl)
3854+
continue;
38433855
recordDecl = DeclareTemplateTypeWithHandleInDeclContext(
38443856
*m_context, m_vkNSDecl, typeName, 1, nullptr);
38453857
recordDecl->setImplicit(true);
@@ -4505,8 +4517,6 @@ class HLSLExternalSource : public ExternalSemaSource {
45054517
int startDepth = (templateArgCount == 0) ? 0 : 1;
45064518
CXXRecordDecl *recordDecl = m_objectTypeDecls[i];
45074519
if (recordDecl == nullptr) {
4508-
DXASSERT(kind == AR_OBJECT_WAVE,
4509-
"else objects other than reserved not initialized");
45104520
continue;
45114521
}
45124522

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %dxc -T ps_6_0 -E PSMain -fcgl %s -verify
2+
3+
static const integral_constant MyVar; // expected-error{{unknown type name 'integral_constant'}}
4+
static const SpirvType MyVar; // expected-error{{unknown type name 'SpirvType'}}
5+
static const SpirvOpaqueType MyVar; // expected-error{{unknown type name 'SpirvOpaqueType'}}
6+
static const Literal MyVar; // expected-error{{unknown type name 'Literal'}}
7+
8+
float4 PSMain() : SV_TARGET
9+
{
10+
return float4(1.0, 1.0, 1.0, 1.0);
11+
}
12+

0 commit comments

Comments
 (0)