Skip to content

Commit 4721490

Browse files
authored
[libc++abi][AIX] Use different function pointer types for destructors with 1 or 2 args (#89624)
The destructors generated by the legacy IBM `xlclang++` compiler can take 1 or 2 arguments and the differences were handled by type `cast` where it is needed. Clang now treats the `cast` here as an error after 999d4f8 landed with `-Xextra -Werror`. The issue had been worked around by using `#pragma GCC diagnostic push/pop`. This patch defines 2 separate destructor types for 1 argument and 2 arguments respectively so `cast` is not needed.
1 parent 6217abc commit 4721490

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

libcxxabi/src/aix_state_tab_eh.inc

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ static bool state_tab_dbg() {
102102

103103
namespace __state_table_eh {
104104

105-
using destruct_f = void (*)(void*);
106-
107105
// Definition of flags for the state table entry field 'action flag'.
108106
enum FSMEntryCount : intptr_t { beginCatch = -1, endCatch = -2, deleteObject = -3, cleanupLabel = -4, terminate = -5 };
109107

@@ -145,8 +143,10 @@ struct FSMEntry {
145143
intptr_t nextStatePtr;
146144
};
147145
union {
148-
// Address of the destructor function.
149-
void (*destructor)(void*, size_t);
146+
// Address of the destructor function with 1 argument.
147+
void (*destructor)(void*);
148+
// Address of the destructor function with 2 arguments.
149+
void (*xlCDestructor)(void*, size_t);
150150
// The address of the catch block or cleanup code.
151151
void* landingPad;
152152
};
@@ -191,17 +191,12 @@ static void invoke_destructor(FSMEntry* fsmEntry, void* addr) {
191191
try {
192192
if (fsmEntry->elementCount == 1) {
193193
_LIBCXXABI_TRACE_STATETAB0("calling scalar destructor\n");
194-
(*fsmEntry->destructor)(addr, dtorArgument);
194+
(*fsmEntry->xlCDestructor)(addr, dtorArgument);
195195
_LIBCXXABI_TRACE_STATETAB0("returned from scalar destructor\n");
196196
} else {
197197
_LIBCXXABI_TRACE_STATETAB0("calling vector destructor\n");
198-
// TODO: in the legacy ABI, destructors had a second argument. We don't expect to encounter
199-
// destructors of this type in the itanium-based ABI, so this should be safe, but this could use some cleanup.
200-
#pragma GCC diagnostic push
201-
#pragma GCC diagnostic ignored "-Wcast-function-type"
202198
__cxa_vec_cleanup(addr, reinterpret_cast<size_t>(fsmEntry->elementCount), fsmEntry->elemSize,
203-
reinterpret_cast<destruct_f>(fsmEntry->destructor));
204-
#pragma GCC diagnostic pop
199+
fsmEntry->destructor);
205200
_LIBCXXABI_TRACE_STATETAB0("returned from vector destructor\n");
206201
}
207202
} catch (...) {
@@ -218,7 +213,7 @@ static void invoke_delete(FSMEntry* fsmEntry, void* addr) {
218213
try {
219214
_LIBCXXABI_TRACE_STATETAB0("..calling delete()\n");
220215
// 'destructor' holds a function pointer to delete().
221-
(*fsmEntry->destructor)(objectAddress, fsmEntry->elemSize);
216+
(*fsmEntry->xlCDestructor)(objectAddress, fsmEntry->elemSize);
222217
_LIBCXXABI_TRACE_STATETAB0("..returned from delete()\n");
223218
} catch (...) {
224219
_LIBCXXABI_TRACE_STATETAB0("Uncaught exception in delete(), terminating\n");

0 commit comments

Comments
 (0)