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-compiler.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'source/slang/slang-compiler.cpp') diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index e31918d58..b13624aac 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -2289,14 +2289,20 @@ SlangResult EndToEndCompileRequest::_maybeWriteDebugArtifact( if (targetProgram->getOptionSet().getBoolOption(CompilerOptionName::EmitSeparateDebug)) { const auto dbgArtifact = _getSeparateDbgArtifact(artifact); - // The artifact's name may have been set to the debug build id hash, use - // it as the filename if it exists. - String dbgPath = dbgArtifact->getName(); - if (dbgPath.getLength() == 0) - dbgPath = _getDebugSpvPath(path); - else - dbgPath.append(".dbg.spv"); - return _maybeWriteArtifact(dbgPath, dbgArtifact); + // Check if a debug artifact was actually created (only for SPIR-V targets) + if (dbgArtifact) + { + // The artifact's name may have been set to the debug build id hash, use + // it as the filename if it exists. + String dbgPath = dbgArtifact->getName(); + if (dbgPath.getLength() == 0) + dbgPath = _getDebugSpvPath(path); + else + dbgPath.append(".dbg.spv"); + return _maybeWriteArtifact(dbgPath, dbgArtifact); + } + // If no debug artifact exists (e.g., for non-SPIR-V targets), just silently succeed + // The warning about unsupported targets is already issued during option parsing } return SLANG_OK; -- cgit v1.2.3