From 2020a102e9e0ea2f39a0f2b2a75085c3607ce734 Mon Sep 17 00:00:00 2001 From: Gangzheng Tong Date: Wed, 10 Sep 2025 00:14:05 -0700 Subject: Check if debugVar for is debuggable types in the legalization pass (#8326) ## Problem When generic functions with debug variables were specialized with concrete types containing non-debuggable fields (e.g., `StructuredBuffer`), the IR cloning process would create invalid `DebugVar` instructions without checking if the substituted types remained debuggable. ## Solution This fix adds a defensive check in the legalization pass that removes the debugVar created for the non-debuggable types. --------- Co-authored-by: slangbot Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-ir-legalize-types.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/slang/slang-ir-legalize-types.cpp b/source/slang/slang-ir-legalize-types.cpp index 9363bc882..dd7107b18 100644 --- a/source/slang/slang-ir-legalize-types.cpp +++ b/source/slang/slang-ir-legalize-types.cpp @@ -13,6 +13,7 @@ #include "../compiler-core/slang-name.h" #include "../core/slang-performance-profiler.h" #include "slang-ir-clone.h" +#include "slang-ir-insert-debug-value-store.h" #include "slang-ir-insts.h" #include "slang-ir-util.h" #include "slang-ir.h" @@ -842,8 +843,17 @@ static LegalVal legalizeDebugVar( { case LegalType::Flavor::simple: { + auto pointedToType = tryGetPointedToType(context->builder, type.getSimple()); + + // Check if the type is debuggable before creating DebugVar + DebugValueStoreContext debugContext; + if (!debugContext.isDebuggableType(pointedToType)) + { + return LegalVal(); + } + auto legalVal = context->builder->emitDebugVar( - tryGetPointedToType(context->builder, type.getSimple()), + pointedToType, originalInst->getSource(), originalInst->getLine(), originalInst->getCol(), @@ -881,6 +891,9 @@ static LegalVal legalizeDebugValue( LegalVal debugValue, IRDebugValue* originalInst) { + if (debugVar.flavor == LegalVal::Flavor::none) + return LegalVal(); + // For now we just discard any special part and keep the ordinary part. switch (debugValue.flavor) { @@ -2114,6 +2127,10 @@ static LegalVal legalizeInst( break; case kIROp_DebugVar: result = legalizeDebugVar(context, type, (IRDebugVar*)inst); + if (result.flavor == LegalVal::Flavor::none) + { + return result; + } break; case kIROp_DebugValue: result = legalizeDebugValue(context, args[0], args[1], (IRDebugValue*)inst); -- cgit v1.2.3