mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add a flag to make CHECK failures non-fatal for debugging. (#4835)
`toolchain/autoupdate_testdata.py --allow-check-fail` can now be used to perform an autoupdate even if some `CARBON_CHECK`s are failing. What this does will depend on how the toolchain behaves after the `CHECK` failure, and of course there's no guarantees there, but this can be useful if it's easier to debug the `CHECK` failure by looking at the produced SemIR. Internally, this uses `bazel build --config=non-fatal-checks`, which in turn specifies a `--per_file_copt` for `check_internal.cpp`. The intent here is that the rebuild required to enable or disable this mode is as small as reasonably possible. This mode is not compatible with `-c opt`, as it's important that check failure calls are `[[noreturn]]` in `-c opt` mode. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
parent
1670baf180
commit
58fba078ee
@@ -9,11 +9,6 @@
|
||||
|
||||
namespace Carbon::Internal {
|
||||
|
||||
// Prints the buffered message.
|
||||
static auto PrintAfterStackTrace(void* str) -> void {
|
||||
llvm::errs() << reinterpret_cast<char*>(str);
|
||||
}
|
||||
|
||||
auto CheckFailImpl(const char* kind, const char* file, int line,
|
||||
const char* condition_str, llvm::StringRef extra_message)
|
||||
-> void {
|
||||
@@ -23,15 +18,29 @@ auto CheckFailImpl(const char* kind, const char* file, int line,
|
||||
llvm::StringRef(condition_str).empty() ? "" : ": ", condition_str,
|
||||
extra_message.empty() ? "" : ": ", extra_message);
|
||||
|
||||
// This macro is defined by `--config=non-fatal-checks`.
|
||||
#ifdef CARBON_NON_FATAL_CHECKS
|
||||
#ifdef NDEBUG
|
||||
#error "--config=non-fatal-checks is incompatible with -c opt"
|
||||
#endif
|
||||
// TODO: It'd be nice to print the LLVM PrettyStackTrace, but LLVM doesn't
|
||||
// expose functionality to do so.
|
||||
llvm::sys::PrintStackTrace(llvm::errs());
|
||||
|
||||
llvm::errs() << message;
|
||||
#else
|
||||
// Register another signal handler to print the message. This is because we
|
||||
// want it at the bottom of output, after LLVM's builtin stack output, rather
|
||||
// than the top.
|
||||
llvm::sys::AddSignalHandler(PrintAfterStackTrace,
|
||||
const_cast<char*>(message.c_str()));
|
||||
llvm::sys::AddSignalHandler(
|
||||
[](void* str) { llvm::errs() << reinterpret_cast<char*>(str); },
|
||||
const_cast<char*>(message.c_str()));
|
||||
|
||||
// It's useful to exit the program with `std::abort()` for integration with
|
||||
// debuggers and other tools. We also assume LLVM's exit handling is
|
||||
// installed, which will stack trace on `std::abort()`.
|
||||
std::abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace Carbon::Internal
|
||||
|
||||
Reference in New Issue
Block a user