From 6e0c63b723cc81efcc82c2af778b26e507c71825 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 22 Jul 2025 09:27:05 -0700 Subject: Fix segfault when using -separate-debug-info with unsupported targets (#7777) * Initial plan * Fix segfault when using -separate-debug-info with unsupported targets Add validation to emit a diagnostic error when -separate-debug-info is used with targets other than SPIR-V binary. Previously, this would cause a segfault because the separate debug info logic is only implemented for SPIR-V targets. Changes: - Added new diagnostic error (ID 18) for unsupported separate debug info usage - Added validation in OptionsParser::_parse() to check target compatibility - Created test cases for HLSL and GLSL targets to verify the fix - Updated error message to clarify only SPIR-V binary targets are supported The fix prevents segfaults and provides clear feedback to users about target limitations for the -separate-debug-info option. Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Address feedback: fix segfault properly instead of preventing it Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> --- source/slang/slang-options.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'source/slang/slang-options.cpp') diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 8fd9d0507..0ada33697 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -3948,6 +3948,40 @@ SlangResult OptionsParser::_parse(int argc, char const* const* argv) applySettingsToDiagnosticSink(m_requestImpl->getSink(), m_sink, linkage->m_optionSet); + // Warn about separate debug info being used with unsupported targets + if (linkage->m_optionSet.getBoolOption(CompilerOptionName::EmitSeparateDebug)) + { + // Check all targets to see if any use separate debug info with an unsupported target + for (const auto& rawTarget : m_rawTargets) + { + if (rawTarget.format != CodeGenTarget::SPIRV) + { + // Get the target name for the warning message + UnownedStringSlice targetName = + TypeTextUtil::getCompileTargetName(asExternal(rawTarget.format)); + m_sink->diagnose( + SourceLoc(), + Diagnostics::separateDebugInfoUnsupportedForTarget, + targetName); + } + } + + // Also check the default target if no explicit targets were specified + if (m_rawTargets.getCount() == 0) + { + if (m_defaultTarget.format != CodeGenTarget::SPIRV) + { + // Get the target name for the warning message + UnownedStringSlice targetName = + TypeTextUtil::getCompileTargetName(asExternal(m_defaultTarget.format)); + m_sink->diagnose( + SourceLoc(), + Diagnostics::separateDebugInfoUnsupportedForTarget, + targetName); + } + } + } + return (m_sink->getErrorCount() == 0) ? SLANG_OK : SLANG_FAIL; } -- cgit v1.2.3