Skip to content

Commit

Permalink
[SPIRV] Check if decl is identifier before getting name (#7012)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
s-perron authored Nov 20, 2024
1 parent 9b9442c commit e824ae3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tools/clang/lib/SPIRV/SpirvEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
29 changes: 29 additions & 0 deletions tools/clang/test/CodeGenSPIRV/func.noidentifier.hlsl
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit e824ae3

Please sign in to comment.