aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/CMakeLists.txt6
-rw-r--r--backend/cmake/modules/RCCBackendBuild.cmake12
-rw-r--r--backend/lib/CodeGen/MachineFunction.cpp17
3 files changed, 25 insertions, 10 deletions
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt
index 2d5cc82..0f983d0 100644
--- a/backend/CMakeLists.txt
+++ b/backend/CMakeLists.txt
@@ -44,6 +44,12 @@ include(RCCBackendDeveloperTools)
option(RCC_BACKEND_BUILD_TESTS "Build RCC Backend tests" "${BUILD_TESTING}")
option(RCC_BACKEND_WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF)
option(RCC_BACKEND_ENABLE_CLANG_TIDY "Run clang-tidy during each compilation" OFF)
+option(RCC_BACKEND_ENABLE_EH "Enable C++ exception handling" OFF)
+option(RCC_BACKEND_ENABLE_RTTI "Enable C++ run-time type information" OFF)
+
+if(RCC_BACKEND_ENABLE_EH AND NOT RCC_BACKEND_ENABLE_RTTI)
+ message(FATAL_ERROR "RCC Backend exception handling requires RTTI")
+endif()
rcc_backend_initialize_toolchain()
diff --git a/backend/cmake/modules/RCCBackendBuild.cmake b/backend/cmake/modules/RCCBackendBuild.cmake
index 79e7bb1..52e3a71 100644
--- a/backend/cmake/modules/RCCBackendBuild.cmake
+++ b/backend/cmake/modules/RCCBackendBuild.cmake
@@ -70,6 +70,18 @@ function(rcc_backend_configure_target Target)
-Wformat=2
)
+ if(RCC_BACKEND_ENABLE_EH)
+ target_compile_options("${Target}" PRIVATE -fexceptions)
+ else()
+ target_compile_options("${Target}" PRIVATE -fno-exceptions)
+ endif()
+
+ if(RCC_BACKEND_ENABLE_RTTI)
+ target_compile_options("${Target}" PRIVATE -frtti)
+ else()
+ target_compile_options("${Target}" PRIVATE -fno-rtti)
+ endif()
+
if(RCC_BACKEND_WARNINGS_AS_ERRORS)
target_compile_options("${Target}" PRIVATE -Werror)
endif()
diff --git a/backend/lib/CodeGen/MachineFunction.cpp b/backend/lib/CodeGen/MachineFunction.cpp
index e19c115..fc1508c 100644
--- a/backend/lib/CodeGen/MachineFunction.cpp
+++ b/backend/lib/CodeGen/MachineFunction.cpp
@@ -35,16 +35,13 @@ public:
[[nodiscard]] ObjectT *create(ArgumentTs &&...Arguments) {
void *Storage = Resource.allocate(sizeof(ObjectT), alignof(ObjectT));
ObjectT *Object = ::new (Storage) ObjectT(std::forward<ArgumentTs>(Arguments)...);
- try {
- Destructors.push_back(DestructorRecord{
- Object,
- [](void *RawObject) noexcept { std::destroy_at(static_cast<ObjectT *>(RawObject)); },
- });
- } catch (...) {
- std::destroy_at(Object);
- throw;
- }
- return Object;
+ auto DestroyObject = [](ObjectT *TypedObject) noexcept { std::destroy_at(TypedObject); };
+ std::unique_ptr<ObjectT, decltype(DestroyObject)> ConstructionGuard(Object, DestroyObject);
+ Destructors.push_back(DestructorRecord{
+ Object,
+ [](void *RawObject) noexcept { std::destroy_at(static_cast<ObjectT *>(RawObject)); },
+ });
+ return ConstructionGuard.release();
}
private: