summaryrefslogtreecommitdiff
path: root/source/slang/slang-lower-to-ir.cpp
diff options
context:
space:
mode:
authorCopilot <198982749+Copilot@users.noreply.github.com>2025-07-18 11:24:06 -0700
committerGitHub <noreply@github.com>2025-07-18 18:24:06 +0000
commit70273599e2bb8a8e2b0f7b5e7ad47fe2f00b2b40 (patch)
tree29d18f4b20c00bfbe684978d35d02da77713a4ae /source/slang/slang-lower-to-ir.cpp
parentc901338e3b443be4c72308f4f473892404b73268 (diff)
Fix debug info generation for let variables in SPIR-V output (#7743)
* Initial plan * Fix debug info for let variables Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Fix parameter count for emitDebugVar function call Fixed regression where let variable debug info generation was missing the optional argIndex parameter in emitDebugVar call. Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Add location validity check for debug info generation Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Don't insert debug value for nondebuggable types. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
-rw-r--r--source/slang/slang-lower-to-ir.cpp43
1 files changed, 42 insertions, 1 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index ab9f85b21..526e2f952 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -535,6 +535,8 @@ struct SharedIRGenContext
// in the source code.
//
List<IRInst*> m_stringLiterals;
+
+ DebugValueStoreContext debugValueContext;
};
struct IRGenContext;
@@ -9155,6 +9157,45 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
{
auto initVal = lowerRValueExpr(context, initExpr);
initVal = LoweredValInfo::simple(getSimpleVal(context, initVal));
+
+ // For debug builds, still create debug information for let variables
+ // even though we're not creating an actual variable
+ if (context->includeDebugInfo && decl->loc.isValid() &&
+ context->shared->debugValueContext.isDebuggableType(initVal.val->getDataType()))
+ {
+ // Create a debug variable for this let declaration
+ auto builder = context->irBuilder;
+ auto humaneLoc = context->getLinkage()->getSourceManager()->getHumaneLoc(
+ decl->loc,
+ SourceLocType::Emit);
+
+ // Find the debug source for this file
+ auto sourceView =
+ context->getLinkage()->getSourceManager()->findSourceView(decl->loc);
+ if (sourceView)
+ {
+ auto source = sourceView->getSourceFile();
+ IRInst* debugSourceInst = nullptr;
+ if (context->shared->mapSourceFileToDebugSourceInst.tryGetValue(
+ source,
+ debugSourceInst))
+ {
+ auto debugVar = builder->emitDebugVar(
+ varType,
+ debugSourceInst,
+ builder->getIntValue(builder->getUIntType(), humaneLoc.line),
+ builder->getIntValue(builder->getUIntType(), humaneLoc.column),
+ nullptr);
+
+ // Copy name hint from the declaration
+ addNameHint(context, debugVar, decl);
+
+ // Emit debug value to associate the constant with the debug variable
+ builder->emitDebugValue(debugVar, initVal.val);
+ }
+ }
+ }
+
context->setGlobalValue(decl, initVal);
return initVal;
}
@@ -12152,7 +12193,7 @@ RefPtr<IRModule> generateIRForTranslationUnit(
// if debug symbols are enabled.
if (context->includeDebugInfo)
{
- insertDebugValueStore(module);
+ insertDebugValueStore(context->shared->debugValueContext, module);
}