[clang] [Clang][Windows] Preserve x86_fp80 and vector alignment under #pragma pack. (PR #208256)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 3 21:26:22 PDT 2026
================
@@ -2029,13 +2064,20 @@ void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
UnpackedFieldAlign = std::max(UnpackedFieldAlign, MaxAlignmentInChars);
// The maximum field alignment overrides the aligned attribute.
- if (!MaxFieldAlignment.isZero()) {
+ // However, do not reduce alignment for ABI-required alignments (e.g.,
+ // x86_fp80, vector types) which must be preserved for correctness.
+ // On Windows, check if the field type is a vector with standard SIMD
+ // alignment (16 or 32 bytes with size == alignment) - these need their
+ // alignment preserved under #pragma pack. However, honor explicit
+ // __attribute__((packed)) on the struct (Packed=true means the struct
+ // has the packed attribute, not the field).
+ if (!MaxFieldAlignment.isZero() &&
+ !ShouldPreserveFieldAlignment(Context, D, AlignRequirement, Packed)) {
----------------
efriedma-quic wrote:
I see you added some tests here; I'd like to also see coverage for nested fields.
https://github.com/llvm/llvm-project/pull/208256
More information about the cfe-commits
mailing list