You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of #135552 - amy-kwan:amy-kwan/reprc-struct-diagnostic-power-alignment, r=workingjubilee
[AIX] Lint on structs that have a different alignment in AIX's C ABI
This PR adds a linting diagnostic on AIX for repr(C) structs that are required to follow
the power alignment rule. A repr(C) struct needs to follow the power alignment rule if
the struct:
- Has a floating-point data type (greater than 4-bytes) as its first member, or
- The first member of the struct is an aggregate, whose recursively first member is a
floating-point data type (greater than 4-bytes).
The power alignment rule for eligible structs is currently unimplemented, so a linting
diagnostic is produced when such a struct is encountered.
/// The `uses_power_alignment` lint detects specific `repr(C)`
733
+
/// aggregates on AIX.
734
+
/// In its platform C ABI, AIX uses the "power" (as in PowerPC) alignment
735
+
/// rule (detailed in https://www.ibm.com/docs/en/xl-c-and-cpp-aix/16.1?topic=data-using-alignment-modes#alignment),
736
+
/// which can also be set for XLC by `#pragma align(power)` or
737
+
/// `-qalign=power`. Aggregates with a floating-point type as the
738
+
/// recursively first field (as in "at offset 0") modify the layout of
739
+
/// *subsequent* fields of the associated structs to use an alignment value
740
+
/// where the floating-point type is aligned on a 4-byte boundary.
741
+
///
742
+
/// The power alignment rule for structs needed for C compatibility is
743
+
/// unimplementable within `repr(C)` in the compiler without building in
744
+
/// handling of references to packed fields and infectious nested layouts,
745
+
/// so a warning is produced in these situations.
746
+
///
747
+
/// ### Example
748
+
///
749
+
/// ```rust,ignore (fails on non-powerpc64-ibm-aix)
750
+
/// #[repr(C)]
751
+
/// pub struct Floats {
752
+
/// a: f64,
753
+
/// b: u8,
754
+
/// c: f64,
755
+
/// }
756
+
/// ```
757
+
///
758
+
/// This will produce:
759
+
///
760
+
/// ```text
761
+
/// warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
762
+
/// --> <source>:5:3
763
+
/// |
764
+
/// 5 | c: f64,
765
+
/// | ^^^^^^
766
+
/// |
767
+
/// = note: `#[warn(uses_power_alignment)]` on by default
768
+
/// ```
769
+
///
770
+
/// ### Explanation
771
+
///
772
+
/// The power alignment rule specifies that the above struct has the
773
+
/// following alignment:
774
+
/// - offset_of!(Floats, a) == 0
775
+
/// - offset_of!(Floats, b) == 8
776
+
/// - offset_of!(Floats, c) == 12
777
+
/// However, rust currently aligns `c` at offset_of!(Floats, c) == 16.
778
+
/// Thus, a warning should be produced for the above struct in this case.
779
+
USES_POWER_ALIGNMENT,
780
+
Warn,
781
+
"Structs do not follow the power alignment rule under repr(C)"
0 commit comments