[clang] fix: compatible C++ empty record with align UB with gcc (PR #72197)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 16 11:11:48 PST 2023


efriedma-quic wrote:

The proper fix here is probably to just delete the `return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext()));` from the empty struct codepath on aarch64.

Alignment shouldn't affect whether a class is empty.  The issue here is just that according to aarch64 AAPCS rules, there isn't supposed to be a special case for empty classes; they're supposed to be passed exactly the same way as non-empty classes.  If there's no alignment involved, that's the same as an i8; if there's alignment, though, that increases the size of the struct, and therefore the calling convention.  It looks like whoever wrote it wasn't considering that an empty struct can have size greater than one byte if alignment is involved.

The code you noted is supposed to handle two cases, neither of which are relevant to your testcase:

- Darwin-specific calling convention rules.
- GNU extensions for zero-size structs (which aren't allowed according to either C or C++ standards, but GNU invented a bunch of non-standard rules for them)

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


More information about the cfe-commits mailing list