[clang] [PowerPC] make `_Complex` ABI GCC-compatible (PR #208917)

Matt Turner via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 29 08:49:37 PST 2026


https://github.com/mattst88 commented:

Thanks for keeping at this. As the csqrtf example shows, calls to libm's complex
functions don't work at all today.

I've been working on the same change for 32-bit SVR4 and tested it against
powerpc-unknown-linux-gnu-gcc 16. The test was generated: every `_Complex` type
at every GPR position, mixed with ints, long longs and doubles, as arguments,
returns and variadic arguments, in all four gcc/clang caller/callee
combinations at -O0, -O1 and -O2. The three problems above came from running
the IR this patch emits for the same kinds of calls through llc and comparing
with GCC.

The sret and vector problems both come from counting GPRs in clang. The count
has to match the backend's register assignment exactly, and anything it gets
wrong moves every `_Complex` argument after it. I put the rule in the backend
instead: the 32-bit SVR4 calling convention assigns the elements of an
`[N x i32]` argument to consecutive GPRs, or to the stack after using up the
remaining GPRs, which is what GCC does with a `_Complex double` or a
`_Complex long double`. Clang then only picks the type, `iN` up to 64 bits and
`[N x i32]` above that. That removes the GPR count, the padding argument and
the new `classifyArgumentType` parameter. rustc would get the same behavior
from the same IR without having to count registers either.

If that sounds reasonable, I'll post the backend change as its own PR for this
one to build on. I also have va_arg for `_Complex` ready to go on top of this
PR. Separately, va_arg had bugs of its own on 32-bit SVR4, even between
clang-built callers and callees: #246994 and #246995 (long double), #246993
(vectors) and #246992 (structs passed by reference). #246991 fixes the stack
alignment of a soft-float long double argument.

For the version gate, #223481 shipped an ELFv1 union ABI change behind
`-fclang-abi-compat=23` in the same way.

https://github.com/llvm/llvm-project/pull/208917


More information about the cfe-commits mailing list