[PATCH] D117616: GCC ABI Compatibility: Preserve alignment of non-pod members in packed structs

Reid Kleckner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 25 12:55:38 PST 2022


rnk added a comment.

In addition to the ABI compatibility concern, IMO, GCC's behavior here is better and more user friendly:

- C++ classes have methods
- calling a method on a field takes the address of a field
- if the field is in a packed struct, it may be misaligned
- misaligned loads and stores cause UB
- the UB is not trivial or hypothetical: it manifests as a crash, or load/store tearing or non-atomicity

GCC prevents users from getting into this situation by ignoring the packed attribute in the presence of non-C++98-POD fields and warning the user about it. Clang should do the same. Currently, Clang's stance seems to be, if the user asks permission to shoot themselves in the foot, they can go right ahead. That's less than ideal.

Between the usability concern and the ABI concern, it seems worth changing behavior here, even if it means leaving behind a flag or a new attribute such as `__attribute__((packed_nonpod))` to get the old behavior. I don't see a PS4 reviewer here, but every time I've asked them if we can tweak some ABI detail, they ask to be opted out.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117616/new/

https://reviews.llvm.org/D117616



More information about the cfe-commits mailing list