diff options
| author | Oliver Middleton <olliemail27@gmail.com> | 2018-09-08 12:50:19 +0100 |
|---|---|---|
| committer | Simonas Kazlauskas <git@kazlauskas.me> | 2018-10-27 13:47:11 +0300 |
| commit | 01674fbe06aa2d05f8dafbb8a27ba6bd23fa09e1 (patch) | |
| tree | 625649f40505a0bb90e034efb257f129b7980ec6 /src/test | |
| parent | 10f42cbde015c44a019e8b6dceca472a1532f36a (diff) | |
| download | rust-01674fbe06aa2d05f8dafbb8a27ba6bd23fa09e1.tar.gz rust-01674fbe06aa2d05f8dafbb8a27ba6bd23fa09e1.zip | |
Correct alignment of atomic types and (re)add Atomic{I,U}128
LLVM requires that atomic loads and stores be aligned to at least the size of the type.
Diffstat (limited to 'src/test')
4 files changed, 97 insertions, 7 deletions
diff --git a/src/test/run-make-fulldeps/atomic-lock-free/atomic_lock_free.rs b/src/test/run-make-fulldeps/atomic-lock-free/atomic_lock_free.rs index 54f888b3796..2c8128b1907 100644 --- a/src/test/run-make-fulldeps/atomic-lock-free/atomic_lock_free.rs +++ b/src/test/run-make-fulldeps/atomic-lock-free/atomic_lock_free.rs @@ -58,6 +58,14 @@ pub unsafe fn atomic_u64(x: *mut u64) { pub unsafe fn atomic_i64(x: *mut i64) { atomic_xadd(x, 1); } +#[cfg(target_has_atomic = "128")] +pub unsafe fn atomic_u128(x: *mut u128) { + atomic_xadd(x, 1); +} +#[cfg(target_has_atomic = "128")] +pub unsafe fn atomic_i128(x: *mut i128) { + atomic_xadd(x, 1); +} #[cfg(target_has_atomic = "ptr")] pub unsafe fn atomic_usize(x: *mut usize) { atomic_xadd(x, 1); diff --git a/src/test/run-pass/atomic-alignment.rs b/src/test/run-pass/atomic-alignment.rs new file mode 100644 index 00000000000..8771765de29 --- /dev/null +++ b/src/test/run-pass/atomic-alignment.rs @@ -0,0 +1,46 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(cfg_target_has_atomic)] +#![feature(integer_atomics)] + +use std::mem::{align_of, size_of}; +use std::sync::atomic::*; + +fn main() { + #[cfg(target_has_atomic = "8")] + assert_eq!(align_of::<AtomicBool>(), size_of::<AtomicBool>()); + #[cfg(target_has_atomic = "ptr")] + assert_eq!(align_of::<AtomicPtr<u8>>(), size_of::<AtomicPtr<u8>>()); + #[cfg(target_has_atomic = "8")] + assert_eq!(align_of::<AtomicU8>(), size_of::<AtomicU8>()); + #[cfg(target_has_atomic = "8")] + assert_eq!(align_of::<AtomicI8>(), size_of::<AtomicI8>()); + #[cfg(target_has_atomic = "16")] + assert_eq!(align_of::<AtomicU16>(), size_of::<AtomicU16>()); + #[cfg(target_has_atomic = "16")] + assert_eq!(align_of::<AtomicI16>(), size_of::<AtomicI16>()); + #[cfg(target_has_atomic = "32")] + assert_eq!(align_of::<AtomicU32>(), size_of::<AtomicU32>()); + #[cfg(target_has_atomic = "32")] + assert_eq!(align_of::<AtomicI32>(), size_of::<AtomicI32>()); + #[cfg(target_has_atomic = "64")] + assert_eq!(align_of::<AtomicU64>(), size_of::<AtomicU64>()); + #[cfg(target_has_atomic = "64")] + assert_eq!(align_of::<AtomicI64>(), size_of::<AtomicI64>()); + #[cfg(target_has_atomic = "128")] + assert_eq!(align_of::<AtomicU128>(), size_of::<AtomicU128>()); + #[cfg(target_has_atomic = "128")] + assert_eq!(align_of::<AtomicI128>(), size_of::<AtomicI128>()); + #[cfg(target_has_atomic = "ptr")] + assert_eq!(align_of::<AtomicUsize>(), size_of::<AtomicUsize>()); + #[cfg(target_has_atomic = "ptr")] + assert_eq!(align_of::<AtomicIsize>(), size_of::<AtomicIsize>()); +} diff --git a/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.rs b/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.rs index aa27f8922c0..6b70c1ea294 100644 --- a/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.rs +++ b/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.rs @@ -61,6 +61,16 @@ pub unsafe fn atomic_u64(x: *mut u64) { pub unsafe fn atomic_i64(x: *mut i64) { atomic_xadd(x, 1); } +#[cfg(target_has_atomic = "128")] +//~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) +pub unsafe fn atomic_u128(x: *mut u128) { + atomic_xadd(x, 1); +} +#[cfg(target_has_atomic = "128")] +//~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) +pub unsafe fn atomic_i128(x: *mut i128) { + atomic_xadd(x, 1); +} #[cfg(target_has_atomic = "ptr")] //~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) pub unsafe fn atomic_usize(x: *mut usize) { @@ -81,6 +91,8 @@ fn main() { //~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) cfg!(target_has_atomic = "64"); //~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) + cfg!(target_has_atomic = "128"); + //~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) cfg!(target_has_atomic = "ptr"); //~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) } diff --git a/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.stderr b/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.stderr index f3975b7ce8b..81f20112a12 100644 --- a/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.stderr +++ b/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.stderr @@ -65,7 +65,7 @@ LL | #[cfg(target_has_atomic = "64")] error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) --> $DIR/feature-gate-cfg-target-has-atomic.rs:64:7 | -LL | #[cfg(target_has_atomic = "ptr")] +LL | #[cfg(target_has_atomic = "128")] | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: add #![feature(cfg_target_has_atomic)] to the crate attributes to enable @@ -73,13 +73,29 @@ LL | #[cfg(target_has_atomic = "ptr")] error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) --> $DIR/feature-gate-cfg-target-has-atomic.rs:69:7 | +LL | #[cfg(target_has_atomic = "128")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(cfg_target_has_atomic)] to the crate attributes to enable + +error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) + --> $DIR/feature-gate-cfg-target-has-atomic.rs:74:7 + | +LL | #[cfg(target_has_atomic = "ptr")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(cfg_target_has_atomic)] to the crate attributes to enable + +error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) + --> $DIR/feature-gate-cfg-target-has-atomic.rs:79:7 + | LL | #[cfg(target_has_atomic = "ptr")] | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: add #![feature(cfg_target_has_atomic)] to the crate attributes to enable error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) - --> $DIR/feature-gate-cfg-target-has-atomic.rs:76:10 + --> $DIR/feature-gate-cfg-target-has-atomic.rs:86:10 | LL | cfg!(target_has_atomic = "8"); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -87,7 +103,7 @@ LL | cfg!(target_has_atomic = "8"); = help: add #![feature(cfg_target_has_atomic)] to the crate attributes to enable error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) - --> $DIR/feature-gate-cfg-target-has-atomic.rs:78:10 + --> $DIR/feature-gate-cfg-target-has-atomic.rs:88:10 | LL | cfg!(target_has_atomic = "16"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -95,7 +111,7 @@ LL | cfg!(target_has_atomic = "16"); = help: add #![feature(cfg_target_has_atomic)] to the crate attributes to enable error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) - --> $DIR/feature-gate-cfg-target-has-atomic.rs:80:10 + --> $DIR/feature-gate-cfg-target-has-atomic.rs:90:10 | LL | cfg!(target_has_atomic = "32"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -103,7 +119,7 @@ LL | cfg!(target_has_atomic = "32"); = help: add #![feature(cfg_target_has_atomic)] to the crate attributes to enable error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) - --> $DIR/feature-gate-cfg-target-has-atomic.rs:82:10 + --> $DIR/feature-gate-cfg-target-has-atomic.rs:92:10 | LL | cfg!(target_has_atomic = "64"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,13 +127,21 @@ LL | cfg!(target_has_atomic = "64"); = help: add #![feature(cfg_target_has_atomic)] to the crate attributes to enable error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) - --> $DIR/feature-gate-cfg-target-has-atomic.rs:84:10 + --> $DIR/feature-gate-cfg-target-has-atomic.rs:94:10 + | +LL | cfg!(target_has_atomic = "128"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(cfg_target_has_atomic)] to the crate attributes to enable + +error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change (see issue #32976) + --> $DIR/feature-gate-cfg-target-has-atomic.rs:96:10 | LL | cfg!(target_has_atomic = "ptr"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: add #![feature(cfg_target_has_atomic)] to the crate attributes to enable -error: aborting due to 15 previous errors +error: aborting due to 18 previous errors For more information about this error, try `rustc --explain E0658`. |
