Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions tslang/test/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2546,17 +2546,14 @@ set_tests_properties(test-compile-specialization-cast-pair-error
FAIL_REGULAR_EXPRESSION "Stack dump|Assertion failed")

# A failing assert shows a message known only at run time, after the output printed before it.
# Windows only: that is where the JIT reports a failed assert; on Linux abort() reaches LLVM's
# crash handler.
if (WIN32)
add_test(NAME test-jit-assert-message-failing
COMMAND $<TARGET_FILE:tslang> --emit=jit --no-default-lib
--shared-libs=$<TARGET_FILE:TypeScriptRuntime>
"${PROJECT_SOURCE_DIR}/test/tester/assert-message/failing.ts")
set_tests_properties(test-jit-assert-message-failing
PROPERTIES PASS_REGULAR_EXPRESSION "printed before.*assertion failed: n is 7"
FAIL_REGULAR_EXPRESSION "Stack dump|unlinked")
endif()
# The JIT reports it itself on every platform, so on Linux abort() never reaches the crash handler.
add_test(NAME test-jit-assert-message-failing
COMMAND $<TARGET_FILE:tslang> --emit=jit --no-default-lib
--shared-libs=$<TARGET_FILE:TypeScriptRuntime>
"${PROJECT_SOURCE_DIR}/test/tester/assert-message/failing.ts")
set_tests_properties(test-jit-assert-message-failing
PROPERTIES PASS_REGULAR_EXPRESSION "printed before.*assertion failed: n is 7"
FAIL_REGULAR_EXPRESSION "Stack dump|unlinked")

# --export=all exports the module's variables, not the locals of its functions.
add_test(NAME test-compile-export-all-no-locals
Expand Down
24 changes: 24 additions & 0 deletions tslang/tslang/jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,16 @@ static void jitAssertFailed(const char *message, const char *file, unsigned line
_exit(3);
}

#ifndef _WIN32
// glibc's `__assert_fail`, which the lowering calls off Windows, ends in abort(). tslang's own
// crash handler takes that SIGABRT for a compiler crash and prints a "Stack dump" after the
// message. Report it as on Windows instead.
static void jitGlibcAssertFail(const char *assertion, const char *file, unsigned line, const char * /*function*/)
{
jitAssertFailed(assertion, file, line);
}
#endif

#ifdef _WIN64
// MSVC x64 C++ EH encodes throw-site type information as image-relative offsets.
// vcruntime's _CxxThrowException recovers the base with RtlPcToFileHeader on the
Expand Down Expand Up @@ -904,6 +914,20 @@ int runJit(int argc, char **argv, mlir::ModuleOp module, CompileOptions &compile
return -1;
}
}
#else
// see jitGlibcAssertFail above
{
llvm::orc::MangleAndInterner interner(jit->getExecutionSession(), jit->getDataLayout());
llvm::orc::SymbolMap assertOverrides;
assertOverrides[interner("__assert_fail")] = {
llvm::orc::ExecutorAddr::fromPtr(&jitGlibcAssertFail), llvm::JITSymbolFlags::Exported};
if (auto err = jit->getMainJITDylib().define(llvm::orc::absoluteSymbols(std::move(assertOverrides))))
{
llvm::WithColor::error(llvm::errs(), "tslang") << "failed to define the assert handler, error: " << err << "\n";
llvm::consumeError(std::move(err));
return -1;
}
}
#endif

if (auto err = jit->addIRModule(llvm::orc::ThreadSafeModule(std::move(llvmModule), std::move(llvmContext))))
Expand Down
Loading