From ba9166773929f6d5ec6bd89d46605b803bcde9c4 Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Mon, 18 Nov 2024 15:52:34 -0500 Subject: [PATCH] [SPIRV] Check if decl is identifier before getting name We hit an assert when trying to get the name of `operator()`. This is fixed by first checking if it function declatarion is an identifier. Fixes #6973 --- tools/clang/lib/SPIRV/SpirvEmitter.cpp | 3 +- .../test/CodeGenSPIRV/func.noidentifier.hlsl | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tools/clang/test/CodeGenSPIRV/func.noidentifier.hlsl diff --git a/tools/clang/lib/SPIRV/SpirvEmitter.cpp b/tools/clang/lib/SPIRV/SpirvEmitter.cpp index 92a4734187..07f51c1fe1 100644 --- a/tools/clang/lib/SPIRV/SpirvEmitter.cpp +++ b/tools/clang/lib/SPIRV/SpirvEmitter.cpp @@ -778,7 +778,8 @@ void SpirvEmitter::HandleTranslationUnit(ASTContext &context) { } } else { const bool isPrototype = !funcDecl->isThisDeclarationADefinition(); - if (funcDecl->getName() == hlslEntryFunctionName && !isPrototype) { + if (funcDecl->getIdentifier() && + funcDecl->getName() == hlslEntryFunctionName && !isPrototype) { addFunctionToWorkQueue(spvContext.getCurrentShaderModelKind(), funcDecl, /*isEntryFunction*/ true); numEntryPoints++; diff --git a/tools/clang/test/CodeGenSPIRV/func.noidentifier.hlsl b/tools/clang/test/CodeGenSPIRV/func.noidentifier.hlsl new file mode 100644 index 0000000000..dfb44c21e0 --- /dev/null +++ b/tools/clang/test/CodeGenSPIRV/func.noidentifier.hlsl @@ -0,0 +1,29 @@ +// RUN: %dxc -T cs_6_0 -E main -spirv -fcgl %s -spirv | FileCheck %s + + +// CHECK: %src_main = OpFunction %void +// CHECK: OpFunctionCall %void %S_operator_Call %s +// CHECK: OpFunctionEnd +// CHECK: %S_operator_Call = OpFunction %void None +// CHECK-NEXT: OpFunctionParameter +// CHECK-NEXT: OpLabel +// CHECK-NEXT: OpReturn +// CHECK-NEXT: OpFunctionEnd + + +struct S +{ + void operator()(); +}; + +void S::operator()() +{ +} + +[numthreads(8,8,1)] +void main(uint32_t3 gl_GlobalInvocationID : SV_DispatchThreadID) +{ + S s; + s(); +} +