From 42a6dd2da0462f4abfd6cdebedeed7c67a415439 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 3 Jun 2025 18:31:15 -0700 Subject: [PATCH 1/3] compiler: Remove power alignment lint The "power alignment" lint was based on a false premise: rustc assumed LLVM's built-in AIX datalayout was correct for given types. Unfortunately, C compilers, like clang, implemented a different layout. As LLVM's wrong layout was taken as gospel, a fix seemed impossible. This resulted in the creation of the "power alignment" lint as a compromise, as it did not require invasively changing layout algorithms. Eventually in llvm-project's @b7c0452a9a3d895b14ec7c5735e4e4ddc311edb3 LLVM's AIX layout was fixed. Now rustc will have mostly-correct layouts on AIX since rust's dea8b8b3c0a4292c4f2bc344766952d7fd592763 We may need a new lint that captures the remaining C layout problems for AIX and other targets as well, but that is a larger conversation. For now, remove the incorrect lint. --- compiler/rustc_lint/messages.ftl | 2 - compiler/rustc_lint/src/lints.rs | 4 - .../rustc_lint/src/types/improper_ctypes.rs | 159 +----------------- 3 files changed, 3 insertions(+), 162 deletions(-) diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 867b937d4090d..78b9ca10741e8 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -1063,7 +1063,5 @@ lint_useless_ptr_null_checks_fn_ret = returned pointer of `{$fn_name}` call is n lint_useless_ptr_null_checks_ref = references are not nullable, so checking them for null will always return false .label = expression has type `{$orig_ty}` -lint_uses_power_alignment = repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - lint_variant_size_differences = enum variant is more than three times larger ({$largest} bytes) than the next largest diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index a20d90e1227e9..dac057764501a 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1775,10 +1775,6 @@ pub(crate) struct TooLargeCharCast { pub literal: u128, } -#[derive(LintDiagnostic)] -#[diag(lint_uses_power_alignment)] -pub(crate) struct UsesPowerAlignment; - #[derive(LintDiagnostic)] #[diag(lint_unused_comparisons)] pub(crate) struct UnusedComparisons; diff --git a/compiler/rustc_lint/src/types/improper_ctypes.rs b/compiler/rustc_lint/src/types/improper_ctypes.rs index 38094c67c34a0..67bd3de8c578e 100644 --- a/compiler/rustc_lint/src/types/improper_ctypes.rs +++ b/compiler/rustc_lint/src/types/improper_ctypes.rs @@ -2,7 +2,6 @@ use std::iter; use std::ops::ControlFlow; use bitflags::bitflags; -use rustc_abi::VariantIdx; use rustc_data_structures::fx::FxHashSet; use rustc_errors::DiagMessage; use rustc_hir::def::CtorKind; @@ -10,17 +9,15 @@ use rustc_hir::intravisit::VisitorExt; use rustc_hir::{self as hir, AmbigArg}; use rustc_middle::bug; use rustc_middle::ty::{ - self, Adt, AdtDef, AdtKind, GenericArgsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, - TypeVisitableExt, + self, AdtKind, GenericArgsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, }; use rustc_session::{declare_lint, declare_lint_pass}; use rustc_span::def_id::LocalDefId; use rustc_span::{Span, sym}; -use rustc_target::spec::Os; use tracing::debug; use super::repr_nullable_ptr; -use crate::lints::{ImproperCTypes, UsesPowerAlignment}; +use crate::lints::ImproperCTypes; use crate::{LateContext, LateLintPass, LintContext, fluent_generated as fluent}; declare_lint! { @@ -77,65 +74,9 @@ declare_lint! { "proper use of libc types in foreign item definitions" } -declare_lint! { - /// The `uses_power_alignment` lint detects specific `repr(C)` - /// aggregates on AIX. - /// In its platform C ABI, AIX uses the "power" (as in PowerPC) alignment - /// rule (detailed in https://www.ibm.com/docs/en/xl-c-and-cpp-aix/16.1?topic=data-using-alignment-modes#alignment), - /// which can also be set for XLC by `#pragma align(power)` or - /// `-qalign=power`. Aggregates with a floating-point type as the - /// recursively first field (as in "at offset 0") modify the layout of - /// *subsequent* fields of the associated structs to use an alignment value - /// where the floating-point type is aligned on a 4-byte boundary. - /// - /// Effectively, subsequent floating-point fields act as-if they are `repr(packed(4))`. This - /// would be unsound to do in a `repr(C)` type without all the restrictions that come with - /// `repr(packed)`. Rust instead chooses a layout that maintains soundness of Rust code, at the - /// expense of incompatibility with C code. - /// - /// ### Example - /// - /// ```rust,ignore (fails on non-powerpc64-ibm-aix) - /// #[repr(C)] - /// pub struct Floats { - /// a: f64, - /// b: u8, - /// c: f64, - /// } - /// ``` - /// - /// This will produce: - /// - /// ```text - /// warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - /// --> :5:3 - /// | - /// 5 | c: f64, - /// | ^^^^^^ - /// | - /// = note: `#[warn(uses_power_alignment)]` on by default - /// ``` - /// - /// ### Explanation - /// - /// The power alignment rule specifies that the above struct has the - /// following alignment: - /// - offset_of!(Floats, a) == 0 - /// - offset_of!(Floats, b) == 8 - /// - offset_of!(Floats, c) == 12 - /// - /// However, Rust currently aligns `c` at `offset_of!(Floats, c) == 16`. - /// Using offset 12 would be unsound since `f64` generally must be 8-aligned on this target. - /// Thus, a warning is produced for the above struct. - USES_POWER_ALIGNMENT, - Warn, - "Structs do not follow the power alignment rule under repr(C)" -} - declare_lint_pass!(ImproperCTypesLint => [ IMPROPER_CTYPES, IMPROPER_CTYPES_DEFINITIONS, - USES_POWER_ALIGNMENT ]); /// Check a variant of a non-exhaustive enum for improper ctypes @@ -174,75 +115,6 @@ fn variant_has_complex_ctor(variant: &ty::VariantDef) -> bool { !matches!(variant.ctor_kind(), Some(CtorKind::Const)) } -/// Per-struct-field function that checks if a struct definition follows -/// the Power alignment Rule (see the `check_struct_for_power_alignment` function). -fn check_arg_for_power_alignment<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { - let tcx = cx.tcx; - assert!(tcx.sess.target.os == Os::Aix); - // Structs (under repr(C)) follow the power alignment rule if: - // - the first field of the struct is a floating-point type that - // is greater than 4-bytes, or - // - the first field of the struct is an aggregate whose - // recursively first field is a floating-point type greater than - // 4 bytes. - if ty.is_floating_point() && ty.primitive_size(tcx).bytes() > 4 { - return true; - } else if let Adt(adt_def, _) = ty.kind() - && adt_def.is_struct() - && adt_def.repr().c() - && !adt_def.repr().packed() - && adt_def.repr().align.is_none() - { - let struct_variant = adt_def.variant(VariantIdx::ZERO); - // Within a nested struct, all fields are examined to correctly - // report if any fields after the nested struct within the - // original struct are misaligned. - for struct_field in &struct_variant.fields { - let field_ty = tcx.type_of(struct_field.did).instantiate_identity(); - if check_arg_for_power_alignment(cx, field_ty) { - return true; - } - } - } - return false; -} - -/// Check a struct definition for respect of the Power alignment Rule (as in PowerPC), -/// which should be respected in the "aix" target OS. -/// To do so, we must follow one of the two following conditions: -/// - The first field of the struct must be floating-point type that -/// is greater than 4-bytes. -/// - The first field of the struct must be an aggregate whose -/// recursively first field is a floating-point type greater than -/// 4 bytes. -fn check_struct_for_power_alignment<'tcx>( - cx: &LateContext<'tcx>, - item: &'tcx hir::Item<'tcx>, - adt_def: AdtDef<'tcx>, -) { - let tcx = cx.tcx; - - // Only consider structs (not enums or unions) on AIX. - if tcx.sess.target.os != Os::Aix || !adt_def.is_struct() { - return; - } - - // The struct must be repr(C), but ignore it if it explicitly specifies its alignment with - // either `align(N)` or `packed(N)`. - if adt_def.repr().c() && !adt_def.repr().packed() && adt_def.repr().align.is_none() { - let struct_variant_data = item.expect_struct().2; - for field_def in struct_variant_data.fields().iter().skip(1) { - // Struct fields (after the first field) are checked for the - // power alignment rule, as fields after the first are likely - // to be the fields that are misaligned. - let ty = tcx.type_of(field_def.def_id).instantiate_identity(); - if check_arg_for_power_alignment(cx, ty) { - cx.emit_span_lint(USES_POWER_ALIGNMENT, field_def.span, UsesPowerAlignment); - } - } - } -} - #[derive(Clone, Copy)] enum CItemKind { Declaration, @@ -844,23 +716,6 @@ impl<'tcx> ImproperCTypesLint { } } - /// For a local definition of a #[repr(C)] struct/enum/union, check that it is indeed FFI-safe. - fn check_reprc_adt( - &mut self, - cx: &LateContext<'tcx>, - item: &'tcx hir::Item<'tcx>, - adt_def: AdtDef<'tcx>, - ) { - debug_assert!( - adt_def.repr().c() && !adt_def.repr().packed() && adt_def.repr().align.is_none() - ); - - // FIXME(ctypes): this following call is awkward. - // is there a way to perform its logic in MIR space rather than HIR space? - // (so that its logic can be absorbed into visitor.visit_struct_or_union) - check_struct_for_power_alignment(cx, item, adt_def); - } - fn check_foreign_static(&mut self, cx: &LateContext<'tcx>, id: hir::OwnerId, span: Span) { let ty = cx.tcx.type_of(id).instantiate_identity(); let mut visitor = ImproperCTypesVisitor::new(cx, ty, CItemKind::Declaration); @@ -996,15 +851,7 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesLint { } // See `check_fn` for declarations, `check_foreign_items` for definitions in extern blocks hir::ItemKind::Fn { .. } => {} - hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) | hir::ItemKind::Enum(..) => { - // looking for extern FnPtr:s is delegated to `check_field_def`. - let adt_def: AdtDef<'tcx> = cx.tcx.adt_def(item.owner_id.to_def_id()); - - if adt_def.repr().c() && !adt_def.repr().packed() && adt_def.repr().align.is_none() - { - self.check_reprc_adt(cx, item, adt_def); - } - } + hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) | hir::ItemKind::Enum(..) => {} // Doesn't define something that can contain a external type to be checked. hir::ItemKind::Impl(..) From 950ad7e063d6ae546aa27087d2b0cac567a67322 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 10 Jun 2025 12:30:05 -0700 Subject: [PATCH 2/3] tests: Test for newly corrected alignments on AIX --- tests/ui/layout/reprc-power-alignment.rs | 138 ++++++++----- tests/ui/layout/reprc-power-alignment.stderr | 200 ++++++++++++------- 2 files changed, 212 insertions(+), 126 deletions(-) diff --git a/tests/ui/layout/reprc-power-alignment.rs b/tests/ui/layout/reprc-power-alignment.rs index 639e217823513..32e3db4756f52 100644 --- a/tests/ui/layout/reprc-power-alignment.rs +++ b/tests/ui/layout/reprc-power-alignment.rs @@ -1,9 +1,8 @@ -//@ check-pass //@ compile-flags: --target powerpc64-ibm-aix //@ needs-llvm-components: powerpc //@ add-minicore //@ ignore-backends: gcc -#![feature(no_core)] +#![feature(no_core, rustc_attrs)] #![no_core] #![no_std] #![crate_type = "lib"] @@ -11,182 +10,217 @@ extern crate minicore; use minicore::*; -#[warn(uses_power_alignment)] +#[rustc_layout(align)] #[repr(C)] -pub struct Floats { +pub struct Floats { //~ ERROR: align: AbiAlign { abi: Align(4 bytes) } a: f64, b: u8, - c: f64, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type + c: f64, d: f32, } -pub struct Floats2 { +#[rustc_layout(align)] +pub struct Floats2 { //~ ERROR: align: AbiAlign { abi: Align(4 bytes) } a: f64, b: u32, c: f64, } +#[rustc_layout(align)] #[repr(C)] -pub struct Floats3 { +pub struct Floats3 { //~ ERROR: align: AbiAlign { abi: Align(8 bytes) } a: f32, b: f32, c: i64, } +#[rustc_layout(align)] #[repr(C)] -pub struct Floats4 { +pub struct Floats4 { //~ ERROR: align: AbiAlign { abi: Align(8 bytes) } a: u64, b: u32, c: f32, } +#[rustc_layout(align)] #[repr(C)] -pub struct Floats5 { +pub struct Floats5 { //~ ERROR: align: AbiAlign { abi: Align(4 bytes) } a: f32, - b: f64, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type + b: f64, c: f32, } +#[rustc_layout(align)] #[repr(C)] -pub struct FloatAgg1 { +pub struct FloatAgg1 { //~ ERROR: align: AbiAlign { abi: Align(4 bytes) } x: Floats, - y: f64, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type + y: f64, } +#[rustc_layout(align)] #[repr(C)] -pub struct FloatAgg2 { +pub struct FloatAgg2 { //~ ERROR: align: AbiAlign { abi: Align(8 bytes) } x: i64, - y: Floats, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type + y: Floats, } +#[rustc_layout(align)] #[repr(C)] -pub struct FloatAgg3 { +pub struct FloatAgg3 { //~ ERROR: align: AbiAlign { abi: Align(8 bytes) } x: FloatAgg1, - // NOTE: the "power" alignment rule is infectious to nested struct fields. - y: FloatAgg2, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - z: FloatAgg2, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type + y: FloatAgg2, + z: FloatAgg2, } +#[rustc_layout(align)] #[repr(C)] -pub struct FloatAgg4 { +pub struct FloatAgg4 { //~ ERROR: align: AbiAlign { abi: Align(8 bytes) } x: FloatAgg1, - y: FloatAgg2, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type + y: FloatAgg2, } +#[rustc_layout(align)] #[repr(C)] -pub struct FloatAgg5 { +pub struct FloatAgg5 { //~ ERROR: align: AbiAlign { abi: Align(8 bytes) } x: FloatAgg1, - y: FloatAgg2, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - z: FloatAgg3, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type + y: FloatAgg2, + z: FloatAgg3, } +#[rustc_layout(align)] #[repr(C)] -pub struct FloatAgg6 { +pub struct FloatAgg6 { //~ ERROR: align: AbiAlign { abi: Align(8 bytes) } x: i64, - y: Floats, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type + y: Floats, z: u8, } +#[rustc_layout(align)] #[repr(C)] -pub struct FloatAgg7 { +pub struct FloatAgg7 { //~ ERROR: align: AbiAlign { abi: Align(8 bytes) } x: i64, - y: Floats, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type + y: Floats, z: u8, zz: f32, } +#[rustc_layout(align)] #[repr(C)] -pub struct A { +pub struct A { //~ ERROR: align: AbiAlign { abi: Align(4 bytes) } d: f64, } + +#[rustc_layout(align)] #[repr(C)] -pub struct B { +pub struct B { //~ ERROR: align: AbiAlign { abi: Align(4 bytes) } a: A, f: f32, - d: f64, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type + d: f64, } + +#[rustc_layout(align)] #[repr(C)] -pub struct C { +pub struct C { //~ ERROR: align: AbiAlign { abi: Align(4 bytes) } c: u8, - b: B, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type + b: B, } + +#[rustc_layout(align)] #[repr(C)] -pub struct D { +pub struct D { //~ ERROR: align: AbiAlign { abi: Align(4 bytes) } x: f64, } + +#[rustc_layout(align)] #[repr(C)] -pub struct E { +pub struct E { //~ ERROR: align: AbiAlign { abi: Align(4 bytes) } x: i32, - d: D, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type + d: D, } + +#[rustc_layout(align)] #[repr(C)] -pub struct F { +pub struct F { //~ ERROR: align: AbiAlign { abi: Align(4 bytes) } a: u8, - b: f64, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type + b: f64, } + +#[rustc_layout(align)] #[repr(C)] -pub struct G { +pub struct G { //~ ERROR: align: AbiAlign { abi: Align(4 bytes) } a: u8, b: u8, - c: f64, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type + c: f64, d: f32, - e: f64, //~ WARNING repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type + e: f64, } -// Should not warn on #[repr(packed)]. + +#[rustc_layout(align)] #[repr(packed)] -pub struct H { +pub struct H { //~ ERROR: align: AbiAlign { abi: Align(1 bytes) } a: u8, b: u8, c: f64, d: f32, e: f64, } + +#[rustc_layout(align)] #[repr(C, packed)] -pub struct I { +pub struct I { //~ ERROR: align: AbiAlign { abi: Align(1 bytes) } a: u8, b: u8, c: f64, d: f32, e: f64, } + + +#[rustc_layout(align)] #[repr(C)] -pub struct J { +pub struct J { //~ ERROR: align: AbiAlign { abi: Align(1 bytes) } a: u8, b: I, } -// The lint also ignores diagnosing #[repr(align(n))]. + +#[rustc_layout(align)] #[repr(C, align(8))] -pub struct K { +pub struct K { //~ ERROR: align: AbiAlign { abi: Align(8 bytes) } a: u8, b: u8, c: f64, d: f32, e: f64, } + +#[rustc_layout(align)] #[repr(C)] -pub struct L { +pub struct L { //~ ERROR: align: AbiAlign { abi: Align(8 bytes) } a: u8, b: K, } + +#[rustc_layout(align)] #[repr(C, align(8))] -pub struct M { +pub struct M { //~ ERROR: align: AbiAlign { abi: Align(8 bytes) } a: u8, b: K, c: L, } -// The lint ignores unions +#[rustc_layout(align)] #[repr(C)] -pub union Union { +pub union Union { //~ ERROR: align: AbiAlign { abi: Align(4 bytes) } a: f64, b: u8, c: f64, d: f32, } -// The lint ignores enums + +#[rustc_layout(align)] #[repr(C)] -pub enum Enum { +pub enum Enum { //~ ERROR: align: AbiAlign { abi: Align(4 bytes) } A { a: f64, b: u8, c: f64, d: f32 }, B, } diff --git a/tests/ui/layout/reprc-power-alignment.stderr b/tests/ui/layout/reprc-power-alignment.stderr index 5398c7d4871f5..57c55387db802 100644 --- a/tests/ui/layout/reprc-power-alignment.stderr +++ b/tests/ui/layout/reprc-power-alignment.stderr @@ -1,112 +1,164 @@ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:19:5 +error: align: AbiAlign { abi: Align(4 bytes) } + --> $DIR/reprc-power-alignment.rs:15:1 | -LL | c: f64, - | ^^^^^^ +LL | pub struct Floats { + | ^^^^^^^^^^^^^^^^^ + +error: align: AbiAlign { abi: Align(4 bytes) } + --> $DIR/reprc-power-alignment.rs:23:1 | -note: the lint level is defined here - --> $DIR/reprc-power-alignment.rs:14:8 +LL | pub struct Floats2 { + | ^^^^^^^^^^^^^^^^^^ + +error: align: AbiAlign { abi: Align(8 bytes) } + --> $DIR/reprc-power-alignment.rs:31:1 | -LL | #[warn(uses_power_alignment)] - | ^^^^^^^^^^^^^^^^^^^^ +LL | pub struct Floats3 { + | ^^^^^^^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:46:5 +error: align: AbiAlign { abi: Align(8 bytes) } + --> $DIR/reprc-power-alignment.rs:39:1 | -LL | b: f64, - | ^^^^^^ +LL | pub struct Floats4 { + | ^^^^^^^^^^^^^^^^^^ + +error: align: AbiAlign { abi: Align(4 bytes) } + --> $DIR/reprc-power-alignment.rs:47:1 + | +LL | pub struct Floats5 { + | ^^^^^^^^^^^^^^^^^^ + +error: align: AbiAlign { abi: Align(4 bytes) } + --> $DIR/reprc-power-alignment.rs:55:1 + | +LL | pub struct FloatAgg1 { + | ^^^^^^^^^^^^^^^^^^^^ + +error: align: AbiAlign { abi: Align(8 bytes) } + --> $DIR/reprc-power-alignment.rs:62:1 + | +LL | pub struct FloatAgg2 { + | ^^^^^^^^^^^^^^^^^^^^ + +error: align: AbiAlign { abi: Align(8 bytes) } + --> $DIR/reprc-power-alignment.rs:69:1 + | +LL | pub struct FloatAgg3 { + | ^^^^^^^^^^^^^^^^^^^^ + +error: align: AbiAlign { abi: Align(8 bytes) } + --> $DIR/reprc-power-alignment.rs:77:1 + | +LL | pub struct FloatAgg4 { + | ^^^^^^^^^^^^^^^^^^^^ + +error: align: AbiAlign { abi: Align(8 bytes) } + --> $DIR/reprc-power-alignment.rs:84:1 + | +LL | pub struct FloatAgg5 { + | ^^^^^^^^^^^^^^^^^^^^ + +error: align: AbiAlign { abi: Align(8 bytes) } + --> $DIR/reprc-power-alignment.rs:92:1 + | +LL | pub struct FloatAgg6 { + | ^^^^^^^^^^^^^^^^^^^^ + +error: align: AbiAlign { abi: Align(8 bytes) } + --> $DIR/reprc-power-alignment.rs:100:1 | - = note: `#[warn(uses_power_alignment)]` on by default +LL | pub struct FloatAgg7 { + | ^^^^^^^^^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:53:5 +error: align: AbiAlign { abi: Align(4 bytes) } + --> $DIR/reprc-power-alignment.rs:109:1 | -LL | y: f64, - | ^^^^^^ +LL | pub struct A { + | ^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:59:5 +error: align: AbiAlign { abi: Align(4 bytes) } + --> $DIR/reprc-power-alignment.rs:115:1 | -LL | y: Floats, - | ^^^^^^^^^ +LL | pub struct B { + | ^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:66:5 +error: align: AbiAlign { abi: Align(4 bytes) } + --> $DIR/reprc-power-alignment.rs:123:1 | -LL | y: FloatAgg2, - | ^^^^^^^^^^^^ +LL | pub struct C { + | ^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:67:5 +error: align: AbiAlign { abi: Align(4 bytes) } + --> $DIR/reprc-power-alignment.rs:130:1 | -LL | z: FloatAgg2, - | ^^^^^^^^^^^^ +LL | pub struct D { + | ^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:73:5 +error: align: AbiAlign { abi: Align(4 bytes) } + --> $DIR/reprc-power-alignment.rs:136:1 | -LL | y: FloatAgg2, - | ^^^^^^^^^^^^ +LL | pub struct E { + | ^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:79:5 +error: align: AbiAlign { abi: Align(4 bytes) } + --> $DIR/reprc-power-alignment.rs:143:1 | -LL | y: FloatAgg2, - | ^^^^^^^^^^^^ +LL | pub struct F { + | ^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:80:5 +error: align: AbiAlign { abi: Align(4 bytes) } + --> $DIR/reprc-power-alignment.rs:150:1 | -LL | z: FloatAgg3, - | ^^^^^^^^^^^^ +LL | pub struct G { + | ^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:86:5 +error: align: AbiAlign { abi: Align(1 bytes) } + --> $DIR/reprc-power-alignment.rs:160:1 | -LL | y: Floats, - | ^^^^^^^^^ +LL | pub struct H { + | ^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:93:5 +error: align: AbiAlign { abi: Align(1 bytes) } + --> $DIR/reprc-power-alignment.rs:170:1 | -LL | y: Floats, - | ^^^^^^^^^ +LL | pub struct I { + | ^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:106:5 +error: align: AbiAlign { abi: Align(1 bytes) } + --> $DIR/reprc-power-alignment.rs:181:1 | -LL | d: f64, - | ^^^^^^ +LL | pub struct J { + | ^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:111:5 +error: align: AbiAlign { abi: Align(8 bytes) } + --> $DIR/reprc-power-alignment.rs:188:1 | -LL | b: B, - | ^^^^ +LL | pub struct K { + | ^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:120:5 +error: align: AbiAlign { abi: Align(8 bytes) } + --> $DIR/reprc-power-alignment.rs:198:1 | -LL | d: D, - | ^^^^ +LL | pub struct L { + | ^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:125:5 +error: align: AbiAlign { abi: Align(8 bytes) } + --> $DIR/reprc-power-alignment.rs:205:1 | -LL | b: f64, - | ^^^^^^ +LL | pub struct M { + | ^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:131:5 +error: align: AbiAlign { abi: Align(4 bytes) } + --> $DIR/reprc-power-alignment.rs:213:1 | -LL | c: f64, - | ^^^^^^ +LL | pub union Union { + | ^^^^^^^^^^^^^^^ -warning: repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type - --> $DIR/reprc-power-alignment.rs:133:5 +error: align: AbiAlign { abi: Align(4 bytes) } + --> $DIR/reprc-power-alignment.rs:223:1 | -LL | e: f64, - | ^^^^^^ +LL | pub enum Enum { + | ^^^^^^^^^^^^^ -warning: 17 warnings emitted +error: aborting due to 27 previous errors From 6f5f162d49709c4f6fe35663d34a9aaa5d8a836d Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 10 Jun 2025 14:21:04 -0700 Subject: [PATCH 3/3] tests: Fixup clashing-extern-fn for absence of power-alignment lint --- tests/ui/lint/clashing-extern-fn.rs | 1 - tests/ui/lint/clashing-extern-fn.stderr | 26 ++++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/ui/lint/clashing-extern-fn.rs b/tests/ui/lint/clashing-extern-fn.rs index e4477c9620221..cdf0768e304bc 100644 --- a/tests/ui/lint/clashing-extern-fn.rs +++ b/tests/ui/lint/clashing-extern-fn.rs @@ -248,7 +248,6 @@ mod sameish_members { mod same_sized_members_clash { mod a { - #[allow(uses_power_alignment)] #[repr(C)] struct Point3 { x: f32, diff --git a/tests/ui/lint/clashing-extern-fn.stderr b/tests/ui/lint/clashing-extern-fn.stderr index 0c27547a6ed8f..a4531bcbc634a 100644 --- a/tests/ui/lint/clashing-extern-fn.stderr +++ b/tests/ui/lint/clashing-extern-fn.stderr @@ -1,5 +1,5 @@ warning: `extern` block uses type `Option`, which is not FFI-safe - --> $DIR/clashing-extern-fn.rs:483:55 + --> $DIR/clashing-extern-fn.rs:482:55 | LL | fn hidden_niche_transparent_no_niche() -> Option; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -9,7 +9,7 @@ LL | fn hidden_niche_transparent_no_niche() -> Option>>`, which is not FFI-safe - --> $DIR/clashing-extern-fn.rs:487:46 + --> $DIR/clashing-extern-fn.rs:486:46 | LL | fn hidden_niche_unsafe_cell() -> Option>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -18,7 +18,7 @@ LL | fn hidden_niche_unsafe_cell() -> Option`, which is not FFI-safe - --> $DIR/clashing-extern-fn.rs:502:54 + --> $DIR/clashing-extern-fn.rs:501:54 | LL | fn pt_non_zero_usize_opt_full_range() -> Option; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -160,7 +160,7 @@ LL | fn draw_point(p: Point); found `unsafe extern "C" fn(sameish_members::b::Point)` warning: `origin` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:270:13 + --> $DIR/clashing-extern-fn.rs:269:13 | LL | fn origin() -> Point3; | ---------------------- `origin` previously declared here @@ -172,7 +172,7 @@ LL | fn origin() -> Point3; found `unsafe extern "C" fn() -> same_sized_members_clash::b::Point3` warning: `transparent_incorrect` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:293:13 + --> $DIR/clashing-extern-fn.rs:292:13 | LL | fn transparent_incorrect() -> T; | -------------------------------- `transparent_incorrect` previously declared here @@ -184,7 +184,7 @@ LL | fn transparent_incorrect() -> isize; found `unsafe extern "C" fn() -> isize` warning: `missing_return_type` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:311:13 + --> $DIR/clashing-extern-fn.rs:310:13 | LL | fn missing_return_type() -> usize; | ---------------------------------- `missing_return_type` previously declared here @@ -196,7 +196,7 @@ LL | fn missing_return_type(); found `unsafe extern "C" fn()` warning: `non_zero_usize` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:329:13 + --> $DIR/clashing-extern-fn.rs:328:13 | LL | fn non_zero_usize() -> core::num::NonZero; | ------------------------------------------------- `non_zero_usize` previously declared here @@ -208,7 +208,7 @@ LL | fn non_zero_usize() -> usize; found `unsafe extern "C" fn() -> usize` warning: `non_null_ptr` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:331:13 + --> $DIR/clashing-extern-fn.rs:330:13 | LL | fn non_null_ptr() -> core::ptr::NonNull; | ----------------------------------------------- `non_null_ptr` previously declared here @@ -220,7 +220,7 @@ LL | fn non_null_ptr() -> *const usize; found `unsafe extern "C" fn() -> *const usize` warning: `option_non_zero_usize_incorrect` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:425:13 + --> $DIR/clashing-extern-fn.rs:424:13 | LL | fn option_non_zero_usize_incorrect() -> usize; | ---------------------------------------------- `option_non_zero_usize_incorrect` previously declared here @@ -232,7 +232,7 @@ LL | fn option_non_zero_usize_incorrect() -> isize; found `unsafe extern "C" fn() -> isize` warning: `option_non_null_ptr_incorrect` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:427:13 + --> $DIR/clashing-extern-fn.rs:426:13 | LL | fn option_non_null_ptr_incorrect() -> *const usize; | --------------------------------------------------- `option_non_null_ptr_incorrect` previously declared here @@ -244,7 +244,7 @@ LL | fn option_non_null_ptr_incorrect() -> *const isize; found `unsafe extern "C" fn() -> *const isize` warning: `hidden_niche_transparent_no_niche` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:483:13 + --> $DIR/clashing-extern-fn.rs:482:13 | LL | fn hidden_niche_transparent_no_niche() -> usize; | ------------------------------------------------ `hidden_niche_transparent_no_niche` previously declared here @@ -256,7 +256,7 @@ LL | fn hidden_niche_transparent_no_niche() -> Option Option` warning: `hidden_niche_unsafe_cell` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:487:13 + --> $DIR/clashing-extern-fn.rs:486:13 | LL | fn hidden_niche_unsafe_cell() -> usize; | --------------------------------------- `hidden_niche_unsafe_cell` previously declared here @@ -268,7 +268,7 @@ LL | fn hidden_niche_unsafe_cell() -> Option Option>>` warning: `pt_non_null_ptr` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:516:13 + --> $DIR/clashing-extern-fn.rs:515:13 | LL | fn pt_non_null_ptr() -> pattern_type!(usize is 1..); | ---------------------------------------------------- `pt_non_null_ptr` previously declared here