diff options
| author | Folkert de Vries <folkert@folkertdev.nl> | 2025-06-07 22:56:22 +0200 |
|---|---|---|
| committer | Folkert de Vries <folkert@folkertdev.nl> | 2025-09-09 21:54:54 +0200 |
| commit | cbacd00f106778830803ad2e2364518f06ff9078 (patch) | |
| tree | 4e17ddefcf9c27f5d7bacf37f7f5c57b81ce1679 /tests/ui/static/static-align.rs | |
| parent | c559c4a741836c4ffa8e4f60cb9fe7e92af5298e (diff) | |
| download | rust-cbacd00f106778830803ad2e2364518f06ff9078.tar.gz rust-cbacd00f106778830803ad2e2364518f06ff9078.zip | |
allow `#[rustc_align_static(N)]` on `static`s
We need a different attribute than `rustc_align` because unstable attributes are tied to their feature (we can't have two unstable features use the same unstable attribute). Otherwise this uses all of the same infrastructure as `#[rustc_align]`.
Diffstat (limited to 'tests/ui/static/static-align.rs')
| -rw-r--r-- | tests/ui/static/static-align.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/ui/static/static-align.rs b/tests/ui/static/static-align.rs new file mode 100644 index 00000000000..93241db09f9 --- /dev/null +++ b/tests/ui/static/static-align.rs @@ -0,0 +1,26 @@ +//@ run-pass +#![feature(static_align)] + +#[rustc_align_static(64)] +static A: u8 = 0; + +#[rustc_align_static(64)] +static B: u8 = 0; + +#[rustc_align_static(128)] +#[no_mangle] +static EXPORTED: u64 = 0; + +unsafe extern "C" { + #[rustc_align_static(128)] + #[link_name = "EXPORTED"] + static C: u64; +} + +fn main() { + assert!(core::ptr::from_ref(&A).addr().is_multiple_of(64)); + assert!(core::ptr::from_ref(&B).addr().is_multiple_of(64)); + + assert!(core::ptr::from_ref(&EXPORTED).addr().is_multiple_of(128)); + unsafe { assert!(core::ptr::from_ref(&C).addr().is_multiple_of(128)) }; +} |
