-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't allow internal_error to pass an error test (#8458)
- Loading branch information
1 parent
72749c5
commit 2e73b3c
Showing
2 changed files
with
32 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,36 @@ | ||
#include <Halide.h> | ||
|
||
#include <csignal> | ||
#include <cstdlib> | ||
#include <exception> | ||
#include <iostream> | ||
|
||
// This is a hack to implement death tests in CTest. | ||
extern "C" void hl_error_test_handle_abort(int) { | ||
std::_Exit(EXIT_FAILURE); | ||
} | ||
std::atomic<bool> suppress_abort{true}; | ||
|
||
struct hl_override_abort { | ||
hl_override_abort() noexcept { | ||
std::signal(SIGABRT, hl_error_test_handle_abort); | ||
} | ||
}; | ||
auto handler = ([]() { | ||
#ifdef HALIDE_WITH_EXCEPTIONS | ||
std::set_terminate([]() { // | ||
try { | ||
if (const auto e = std::current_exception()) { | ||
std::rethrow_exception(e); | ||
} | ||
} catch (const Halide::InternalError &e) { | ||
std::cerr << e.what() << "\n" | ||
<< std::flush; | ||
suppress_abort = false; | ||
std::abort(); // We should never EXPECT an internal error | ||
} catch (const std::exception &e) { | ||
std::cerr << e.what() << "\n" | ||
<< std::flush; | ||
} catch (...) {} | ||
std::_Exit(EXIT_FAILURE); | ||
}); | ||
#endif | ||
|
||
hl_override_abort handler{}; | ||
// If exceptions are disabled, we just hope for the best. | ||
return std::signal(SIGABRT, [](int) { | ||
if (suppress_abort) { | ||
std::_Exit(EXIT_FAILURE); | ||
} | ||
}); | ||
})(); |