From d166fe8333c7dfc61c32fda5017461858eb4c3fa Mon Sep 17 00:00:00 2001 From: Lujin Wang <143145775+lujinwangnv@users.noreply.github.com> Date: Thu, 26 Jun 2025 09:29:32 -0700 Subject: Correct the scope for DebugLocalVariable (#7516) * Correct the scope for DebugLocalVariable All of the DebugLocalVariable instructions have their scope set to DebugCompilationUnit. The scope should instead be set to a DebugFunction, or a DebugLexicalBlock which is recursively inside a DebugFunction. Register the debug info for the function instructions, which helps findDebugScope() to find the right DebugFunction scope for DebugLocalVariable. * Add a test for DebugLocalVariable To check the scope, which should be a DebugFunction. --- source/slang/slang-emit-spirv.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 018f833aa..3f3b5e707 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -3468,7 +3468,8 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex spvBlock, spvFunc, irDebugFunc, - irFunc->getDataType()); + irFunc->getDataType(), + irFunc); } if (funcDebugScope) { @@ -7964,7 +7965,8 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex SpvInst* firstBlock, SpvInst* spvFunc, IRDebugFunction* debugFunc, - IRFuncType* debugType) + IRFuncType* debugType, + IRFunc* irFunc = nullptr) { SpvInst* debugFuncInfo = nullptr; if (debugFunc && m_mapIRInstToSpvInst.tryGetValue(debugFunc, debugFuncInfo)) @@ -8002,6 +8004,11 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex builder.getIntValue(builder.getUIntType(), 0), debugFunc->getLine()); + if (irFunc) + { + registerDebugInst(irFunc, debugFuncInfo); + } + if (firstBlock && spvFunc) { emitOpDebugFunctionDefinition( -- cgit v1.2.3