Stop debug tslang --emit=exe/dll ending in a breakpoint at exit - #326
Merged
Merged
Conversation
A debug tslang turns on the CRT leak report at exit (_CRTDBG_LEAK_CHECK_DF), which is emitted as a _CRT_WARN report. Building an exe or dll constructs llvm::InitLLVM (exe.cpp), whose PrintStackTraceOnErrorSignal installs LLVM's AvoidMessageBoxHook with _CrtSetReportHook. That hook answers every CRT report with "retry", and the report macro turns a retry into _CrtDbgBreak - so every debug --emit=exe and --emit=dll ended with an unhandled breakpoint (0x80000003, exit code 3) after the output had been written. The heap was not corrupted: periodic _CrtCheckMemory during the build stayed clean. The JIT installs the same hook but exits through TerminateProcess, and --emit=obj never installs it. Install a _CrtSetReportHook2 hook for _CRT_WARN that writes the message to the debugger output (where it went before) and does not ask to break. Report hooks from _CrtSetReportHook2 run before the _CrtSetReportHook one (ucrt dbgrptt.cpp), so asserts and errors still reach LLVM's hook. Fixes test-compile-gc-shared-auto and test-jit-gc-defaultlib-collector on debug builds (CI builds Release, where the leak check does not exist). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In a Debug build, every
tslang --emit=exe/--emit=dllrun ended in a breakpoint exception (0x80000003) at process exit. This failedtest-compile-gc-shared-autoandtest-jit-gc-defaultlib-collector, and was half oftest-compile-gc-defaultlib-collector. CI builds Release only, so it never showed there.Root cause
tslang.cppenables_CRTDBG_LEAK_CHECK_DF, so the debug CRT emits a_CRT_WARNleak report at exit.buildExeconstructsllvm::InitLLVM, which (viaDisableSystemDialogsOnCrash) installs LLVM'sAvoidMessageBoxHookwith_CrtSetReportHook. That hook answers every report with "retry"._CrtDbgBreak, so the harmless leak report became an int3.JIT exits via
TerminateProcessand never reports;--emit=objnever installs LLVM's hook.Fix
Install a
_CrtSetReportHook2hook inmain(Debug MSVC only) that handles_CRT_WARNitself: it forwards the text toOutputDebugStringAand returns without asking for a break. v2 hooks run before the v1 hook (ucrtdbgrptt.cpp), so LLVM's hook never sees warnings. Errors and asserts are untouched.Verification (windows-msbuild-2026-debug)
--emit=dll/--emit=exeexit 0.test-compile-gc-shared-autoandtest-jit-gc-defaultlib-collectorpass.test-compile-gc-defaultlib-collectorpasses together with TypeScriptCompilerDefaultLib#7 (debug wrappers built with/MTd) and a rebuilt debug default lib.ctest -R "^test-", 2727 tests): onlytest-jit-rc-owned-array-opsandtest-compile-rc-corpus-00owned-array-opsfail, both fixed by Fix memmove sizes in array shift, unshift and splice #325 which is not in this branch.🤖 Generated with Claude Code