aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/CodeGen/MachineFunction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backend/lib/CodeGen/MachineFunction.cpp')
-rw-r--r--backend/lib/CodeGen/MachineFunction.cpp17
1 files changed, 7 insertions, 10 deletions
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: