For the most part, a call to a destructor can be handled just like a regular function call.
A smaller part deals with EH. I noticed that MSC generates a combination of built-in calls of the destructor in the "regular" code and for x86-64 creates a separate cleaning code, which itself may or may not have a copy of the destructor logic in it.
IMO, the simplest solution would always be to call non-trivial destructors like regular functions.
If optimization seems possible on the horizon, consider the above challenges, like everything else: will it go into the cache with everything else? Will it take up too much space in the image? Etc ..
An interface can insert “calls” into non-trivial destructors at the end of each active block in its AST output.
A backend can relate to such things as ordinary function calls, bind them together, create the logic of the logic of a large block-o-destructor somewhere, and move on to this, etc.
Associating functions with the same logic seems pretty common. For example, MSC tends to associate all trivial functions with the same implementation, destructor, or otherwise, optimizing or not.
This is primarily an experience. As usual, YMMV.
One more thing:
EH cleanup logic tends to work like a transition table. For this function, you can simply go to one list of calls to the destructor, depending on where the exception was thrown (if applicable).
defube
source share