1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0 -Clink-dead-code
//@ edition: 2024
//@ ignore-wasm32 aligning functions is not currently supported on wasm (#143368)
#![crate_type = "lib"]
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
#![feature(rustc_attrs)]
#![feature(fn_align)]
// CHECK: align 16
#[unsafe(no_mangle)]
#[rustc_align(16)]
pub fn fn_align() {}
pub struct A;
impl A {
// CHECK: align 16
#[unsafe(no_mangle)]
#[rustc_align(16)]
pub fn method_align(self) {}
// CHECK: align 16
#[unsafe(no_mangle)]
#[rustc_align(16)]
pub fn associated_fn() {}
}
trait T: Sized {
fn trait_fn() {}
fn trait_method(self) {}
#[rustc_align(8)]
fn trait_method_inherit_low(self);
#[rustc_align(32)]
fn trait_method_inherit_high(self);
#[rustc_align(32)]
fn trait_method_inherit_default(self) {}
#[rustc_align(4)]
#[rustc_align(128)]
#[rustc_align(8)]
fn inherit_highest(self) {}
}
impl T for A {
// CHECK-LABEL: trait_fn
// CHECK-SAME: align 16
#[unsafe(no_mangle)]
#[rustc_align(16)]
fn trait_fn() {}
// CHECK-LABEL: trait_method
// CHECK-SAME: align 16
#[unsafe(no_mangle)]
#[rustc_align(16)]
fn trait_method(self) {}
// The prototype's align is ignored because the align here is higher.
// CHECK-LABEL: trait_method_inherit_low
// CHECK-SAME: align 16
#[unsafe(no_mangle)]
#[rustc_align(16)]
fn trait_method_inherit_low(self) {}
// The prototype's align is used because it is higher.
// CHECK-LABEL: trait_method_inherit_high
// CHECK-SAME: align 32
#[unsafe(no_mangle)]
#[rustc_align(16)]
fn trait_method_inherit_high(self) {}
// The prototype's align inherited.
// CHECK-LABEL: trait_method_inherit_default
// CHECK-SAME: align 32
#[unsafe(no_mangle)]
fn trait_method_inherit_default(self) {}
// The prototype's highest align inherited.
// CHECK-LABEL: inherit_highest
// CHECK-SAME: align 128
#[unsafe(no_mangle)]
#[rustc_align(32)]
#[rustc_align(64)]
fn inherit_highest(self) {}
}
trait HasDefaultImpl: Sized {
// CHECK-LABEL: inherit_from_default_method
// CHECK-LABEL: inherit_from_default_method
// CHECK-SAME: align 32
#[rustc_align(32)]
fn inherit_from_default_method(self) {}
}
pub struct InstantiateDefaultMethods;
impl HasDefaultImpl for InstantiateDefaultMethods {}
// CHECK-LABEL: align_specified_twice_1
// CHECK-SAME: align 64
#[unsafe(no_mangle)]
#[rustc_align(32)]
#[rustc_align(64)]
pub fn align_specified_twice_1() {}
// CHECK-LABEL: align_specified_twice_2
// CHECK-SAME: align 128
#[unsafe(no_mangle)]
#[rustc_align(128)]
#[rustc_align(32)]
pub fn align_specified_twice_2() {}
// CHECK-LABEL: align_specified_twice_3
// CHECK-SAME: align 256
#[unsafe(no_mangle)]
#[rustc_align(32)]
#[rustc_align(256)]
pub fn align_specified_twice_3() {}
const _: () = {
// CHECK-LABEL: align_unmangled
// CHECK-SAME: align 256
#[unsafe(no_mangle)]
#[rustc_align(32)]
#[rustc_align(256)]
extern "C" fn align_unmangled() {}
};
unsafe extern "C" {
#[rustc_align(256)]
fn align_unmangled();
}
// FIXME also check `gen` et al
// CHECK-LABEL: async_align
// CHECK-SAME: align 64
#[unsafe(no_mangle)]
#[rustc_align(64)]
pub async fn async_align() {}
|