[FIX] Make object construction exception-safe#650
Merged
Conversation
GCC 11.4 -O3 unsafe-vs-final A/B keeps the no-throw path at 22/22 executed instructions and a byte-identical 85-byte section, while throwing object and array paths remain 28/28 instructions through their first ret with no added guard branch, disarm store, destructor/free call, or memory operation. The throwing hot sections grow 112 to 130 bytes and 115 to 133 bytes: 6 bytes are accepted register/encoding changes and 12 bytes are an unreachable post-ret EH trampoline. free remains exclusive to the cold landing pads, whose sections grow from 5 to 21 bytes.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces exception safety to SimpleObjAllocator by implementing an AllocGuard RAII helper. This guard ensures that allocated memory is properly freed if an exception is thrown during the in-place construction of an object. Additionally, a unit test has been added to verify that constructor exceptions are correctly propagated. I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
6 tasks
spectrometerHBH
approved these changes
Jul 4, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change makes SimpleObjAllocator strongly exception-safe when placement construction throws.
It adds an allocator-local allocation guard to both ordinary object and variable-sized array creation. The guard frees the matching aligned allocation during exception unwinding and is disarmed after successful construction. A focused object test verifies constructor exceptions propagate through make_object.