Skip to content

[libc++abi][AIX] Use different function pointer types for destructors with 1 or 2 args #89624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions libcxxabi/src/aix_state_tab_eh.inc
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ static bool state_tab_dbg() {

namespace __state_table_eh {

using destruct_f = void (*)(void*);

// Definition of flags for the state table entry field 'action flag'.
enum FSMEntryCount : intptr_t { beginCatch = -1, endCatch = -2, deleteObject = -3, cleanupLabel = -4, terminate = -5 };

Expand Down Expand Up @@ -145,8 +143,10 @@ struct FSMEntry {
intptr_t nextStatePtr;
};
union {
// Address of the destructor function.
void (*destructor)(void*, size_t);
// Address of the destructor function with 1 argument.
void (*destructor)(void*);
// Address of the destructor function with 2 arguments.
void (*xlCDestructor)(void*, size_t);
// The address of the catch block or cleanup code.
void* landingPad;
};
Expand Down Expand Up @@ -191,17 +191,12 @@ static void invoke_destructor(FSMEntry* fsmEntry, void* addr) {
try {
if (fsmEntry->elementCount == 1) {
_LIBCXXABI_TRACE_STATETAB0("calling scalar destructor\n");
(*fsmEntry->destructor)(addr, dtorArgument);
(*fsmEntry->xlCDestructor)(addr, dtorArgument);
_LIBCXXABI_TRACE_STATETAB0("returned from scalar destructor\n");
} else {
_LIBCXXABI_TRACE_STATETAB0("calling vector destructor\n");
// TODO: in the legacy ABI, destructors had a second argument. We don't expect to encounter
// destructors of this type in the itanium-based ABI, so this should be safe, but this could use some cleanup.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
__cxa_vec_cleanup(addr, reinterpret_cast<size_t>(fsmEntry->elementCount), fsmEntry->elemSize,
reinterpret_cast<destruct_f>(fsmEntry->destructor));
#pragma GCC diagnostic pop
fsmEntry->destructor);
_LIBCXXABI_TRACE_STATETAB0("returned from vector destructor\n");
}
} catch (...) {
Expand All @@ -218,7 +213,7 @@ static void invoke_delete(FSMEntry* fsmEntry, void* addr) {
try {
_LIBCXXABI_TRACE_STATETAB0("..calling delete()\n");
// 'destructor' holds a function pointer to delete().
(*fsmEntry->destructor)(objectAddress, fsmEntry->elemSize);
(*fsmEntry->xlCDestructor)(objectAddress, fsmEntry->elemSize);
_LIBCXXABI_TRACE_STATETAB0("..returned from delete()\n");
} catch (...) {
_LIBCXXABI_TRACE_STATETAB0("Uncaught exception in delete(), terminating\n");
Expand Down