From bbc092a11c9d1eef8dfc488add4a994a9616d449 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Sat, 2 Mar 2024 17:12:29 -0500 Subject: [PATCH] don't do set_new_handler() workaround for LLVM 9+ --- libraries/chain/controller.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index fecdf6c6cb..b79210526f 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -220,13 +220,18 @@ struct controller_impl { // Read-write tasks are not being executed. }; - // LLVM sets the new handler, we need to reset this to throw a bad_alloc exception so we can possibly exit cleanly - // and not just abort. +#if LLVM_VERSION_MAJOR < 9 + // LLVM versions prior to 9 do a set_new_handler() in a static global initializer. Reset LLVM's custom handler + // back to the default behavior of throwing bad_alloc so we can possibly exit cleanly and not just abort as LLVM's + // handler does. + // LLVM 9+ doesn't install this handler unless calling InitLLVM(), which we don't. + // See https://reviews.llvm.org/D64505 struct reset_new_handler { reset_new_handler() { std::set_new_handler([](){ throw std::bad_alloc(); }); } }; reset_new_handler rnh; // placed here to allow for this to be set before constructing the other fields +#endif controller& self; std::function shutdown; chainbase::database db;