Skip to content

Commit b48eb01

Browse files
committed
Address review comments: clarify documentation in code, add extra AIX check.
1 parent 1728e83 commit b48eb01

File tree

4 files changed

+31
-32
lines changed

4 files changed

+31
-32
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,6 @@ lint_unused_closure =
915915
}{$post} that must be used
916916
.note = closures are lazy and do nothing unless called
917917
918-
lint_uses_power_alignment = repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
919-
920918
lint_unused_comparisons = comparison is useless due to type limits
921919
922920
lint_unused_coroutine =
@@ -972,6 +970,8 @@ lint_unused_result = unused result of type `{$ty}`
972970
973971
lint_use_let_underscore_ignore_suggestion = use `let _ = ...` to ignore the expression or result
974972
973+
lint_uses_power_alignment = repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
974+
975975
lint_variant_size_differences =
976976
enum variant is more than three times larger ({$largest} bytes) than the next largest
977977

compiler/rustc_lint/src/types.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -729,23 +729,18 @@ declare_lint! {
729729
}
730730

731731
declare_lint! {
732-
/// In it's platform C ABI, the AIX target follows the power alignment rule
733-
/// for structs. This rule applies the natural alignment of the first struct
734-
/// field if it is a floating-point type that is greater than 4-bytes, or
735-
/// is an aggregate whose recursively "first" field is a floating-point
736-
/// type greater than 4-bytes.
737-
/// The alignment for subsequent fields of the associated structs use an
738-
/// alignment value where the floating-point type is aligned on a 4-byte
739-
/// boundary.
740-
/// In this case, "natural alignment" (detailed in
741-
/// https://www.ibm.com/docs/en/xl-c-and-cpp-aix/16.1?topic=data-using-alignment-modes#alignment)
742-
/// refers to the floating-point type being aligned to a multiple of its
743-
/// size (for example, the size of a double is 8-bytes, and so is 8-byte
744-
/// aligned).
745-
///
746-
/// The power alignment rule for structs need for C compatibility is
747-
/// currently unimplemented within repr(C) in the compiler, so a warning is
748-
/// produced in these situations.
732+
/// In it's platform C ABI, AIX uses the "power" (as in PowerPC) alignment
733+
/// rule (detailed in https://www.ibm.com/docs/en/xl-c-and-cpp-aix/16.1?topic=data-using-alignment-modes#alignment),
734+
/// which can also be set for XLC by `#pragma align(power)` or
735+
/// `-qalign=power`. Aggregates with a floating-point type as the
736+
/// recursively first field (as in "at offset 0") modify the layout of
737+
/// *subsequent* fields of the associated structs to use an alignment value
738+
/// where the floating-point type is aligned on a 4-byte boundary.
739+
///
740+
/// The power alignment rule for structs needed for C compatibility is
741+
/// unimplementable within `repr(C)` in the compiler without building in
742+
/// handling of references to packed fields and infectious nested layouts,
743+
/// so a warning is produced in these situations.
749744
///
750745
/// ### Example
751746
///
@@ -1593,6 +1588,9 @@ impl ImproperCTypesDefinitions {
15931588
// - the first field of the struct is an aggregate whose
15941589
// recursively first field is a floating-point type greater than
15951590
// 4 bytes.
1591+
if cx.tcx.sess.target.os != "aix" {
1592+
return false;
1593+
}
15961594
if ty.is_floating_point() && ty.primitive_size(cx.tcx).bytes() > 4 {
15971595
return true;
15981596
} else if let Adt(adt_def, _) = ty.kind()

tests/ui/layout/reprc-power-alignment.aix.stderr

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,79 +29,79 @@ LL | y: Floats,
2929
| ^^^^^^^^^
3030

3131
warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
32-
--> $DIR/reprc-power-alignment.rs:58:5
32+
--> $DIR/reprc-power-alignment.rs:59:5
3333
|
3434
LL | y: FloatAgg2,
3535
| ^^^^^^^^^^^^
3636

3737
warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
38-
--> $DIR/reprc-power-alignment.rs:59:5
38+
--> $DIR/reprc-power-alignment.rs:60:5
3939
|
4040
LL | z: FloatAgg2,
4141
| ^^^^^^^^^^^^
4242

4343
warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
44-
--> $DIR/reprc-power-alignment.rs:65:5
44+
--> $DIR/reprc-power-alignment.rs:66:5
4545
|
4646
LL | y: FloatAgg2,
4747
| ^^^^^^^^^^^^
4848

4949
warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
50-
--> $DIR/reprc-power-alignment.rs:71:5
50+
--> $DIR/reprc-power-alignment.rs:72:5
5151
|
5252
LL | y: FloatAgg2,
5353
| ^^^^^^^^^^^^
5454

5555
warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
56-
--> $DIR/reprc-power-alignment.rs:72:5
56+
--> $DIR/reprc-power-alignment.rs:73:5
5757
|
5858
LL | z: FloatAgg3,
5959
| ^^^^^^^^^^^^
6060

6161
warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
62-
--> $DIR/reprc-power-alignment.rs:78:5
62+
--> $DIR/reprc-power-alignment.rs:79:5
6363
|
6464
LL | y: Floats,
6565
| ^^^^^^^^^
6666

6767
warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
68-
--> $DIR/reprc-power-alignment.rs:85:5
68+
--> $DIR/reprc-power-alignment.rs:86:5
6969
|
7070
LL | y: Floats,
7171
| ^^^^^^^^^
7272

7373
warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
74-
--> $DIR/reprc-power-alignment.rs:98:3
74+
--> $DIR/reprc-power-alignment.rs:99:3
7575
|
7676
LL | d: f64,
7777
| ^^^^^^
7878

7979
warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
80-
--> $DIR/reprc-power-alignment.rs:103:3
80+
--> $DIR/reprc-power-alignment.rs:104:3
8181
|
8282
LL | b: B,
8383
| ^^^^
8484

8585
warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
86-
--> $DIR/reprc-power-alignment.rs:112:3
86+
--> $DIR/reprc-power-alignment.rs:113:3
8787
|
8888
LL | d: D,
8989
| ^^^^
9090

9191
warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
92-
--> $DIR/reprc-power-alignment.rs:117:3
92+
--> $DIR/reprc-power-alignment.rs:118:3
9393
|
9494
LL | b: f64,
9595
| ^^^^^^
9696

9797
warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
98-
--> $DIR/reprc-power-alignment.rs:123:5
98+
--> $DIR/reprc-power-alignment.rs:124:5
9999
|
100100
LL | c: f64,
101101
| ^^^^^^
102102

103103
warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
104-
--> $DIR/reprc-power-alignment.rs:125:5
104+
--> $DIR/reprc-power-alignment.rs:126:5
105105
|
106106
LL | e: f64,
107107
| ^^^^^^

tests/ui/layout/reprc-power-alignment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub struct FloatAgg2 {
5555
#[repr(C)]
5656
pub struct FloatAgg3 {
5757
x: FloatAgg1,
58+
// NOTE: the "power" alignment rule is infectious to nested struct fields.
5859
y: FloatAgg2, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
5960
z: FloatAgg2, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type
6061
}

0 commit comments

Comments
 (0)