diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-01 13:01:07 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-01 13:01:07 +0800 |
| commit | b4d1ddb99e1305f6ea6217e7570dda2a94b16e51 (patch) | |
| tree | fb4501033e8d03f06511bff638e0929c4114f465 | |
| parent | fd8770b01a7a3ae85ba85fb43b21803c88593ad7 (diff) | |
| download | rcc-project-b4d1ddb99e1305f6ea6217e7570dda2a94b16e51.tar.gz rcc-project-b4d1ddb99e1305f6ea6217e7570dda2a94b16e51.tar.xz | |
[CMake] Match LLVM EH and RTTI defaults
Disable C++ exceptions and RTTI by default while retaining explicit, validated opt-in switches. Replace the arena's exception syntax with an RAII construction guard so both configurations share one implementation.
| -rw-r--r-- | backend/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | backend/cmake/modules/RCCBackendBuild.cmake | 12 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineFunction.cpp | 17 |
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: |
