[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
Fri Jul 31 13:56:02 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:

Is there any test coverage for this?  (typeRequiresPreserveAlignUnderPragmaPack will never be true, but guess the special handling for long double doesn't exist for windows-gnu triples, but the RequiredByABI should have some effect?)

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


More information about the cfe-commits mailing list