From 03dd9b87cb00a3f11231c2c96f41c4c1ce6abe48 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Sun, 17 Apr 2016 12:49:26 +0100 Subject: [PATCH] Add test to ensure that atomic types are lock-free --- src/test/run-make/atomic-lock-free/Makefile | 30 +++++++++ .../atomic-lock-free/atomic_lock_free.rs | 62 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 src/test/run-make/atomic-lock-free/Makefile create mode 100644 src/test/run-make/atomic-lock-free/atomic_lock_free.rs diff --git a/src/test/run-make/atomic-lock-free/Makefile b/src/test/run-make/atomic-lock-free/Makefile new file mode 100644 index 00000000000..78e7bb23137 --- /dev/null +++ b/src/test/run-make/atomic-lock-free/Makefile @@ -0,0 +1,30 @@ +-include ../tools.mk + +# This tests ensure that atomic types are never lowered into runtime library calls that are not +# guaranteed to be lock-free. + +all: +ifeq ($(UNAME),Linux) + $(RUSTC) --target=i686-unknown-linux-gnu atomic_lock_free.rs + nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add + $(RUSTC) --target=x86_64-unknown-linux-gnu atomic_lock_free.rs + nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add + $(RUSTC) --target=arm-unknown-linux-gnueabi atomic_lock_free.rs + nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add + $(RUSTC) --target=arm-unknown-linux-gnueabihf atomic_lock_free.rs + nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add + $(RUSTC) --target=armv7-unknown-linux-gnueabihf atomic_lock_free.rs + nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add + $(RUSTC) --target=aarch64-unknown-linux-gnu atomic_lock_free.rs + nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add + $(RUSTC) --target=mips-unknown-linux-gnu atomic_lock_free.rs + nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add + $(RUSTC) --target=mipsel-unknown-linux-gnu atomic_lock_free.rs + nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add + $(RUSTC) --target=powerpc-unknown-linux-gnu atomic_lock_free.rs + nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add + $(RUSTC) --target=powerpc64-unknown-linux-gnu atomic_lock_free.rs + nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add + $(RUSTC) --target=powerpc64le-unknown-linux-gnu atomic_lock_free.rs + nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add +endif diff --git a/src/test/run-make/atomic-lock-free/atomic_lock_free.rs b/src/test/run-make/atomic-lock-free/atomic_lock_free.rs new file mode 100644 index 00000000000..8731cd960f3 --- /dev/null +++ b/src/test/run-make/atomic-lock-free/atomic_lock_free.rs @@ -0,0 +1,62 @@ +// Copyright 2016 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(cfg_target_has_atomic, no_core, intrinsics, lang_items)] +#![crate_type="rlib"] +#![no_core] + +extern "rust-intrinsic" { + fn atomic_xadd(dst: *mut T, src: T) -> T; +} + +#[lang = "sized"] +trait Sized {} + +#[cfg(target_has_atomic = "8")] +pub unsafe fn atomic_u8(x: *mut u8) { + atomic_xadd(x, 1); + atomic_xadd(x, 1); +} +#[cfg(target_has_atomic = "8")] +pub unsafe fn atomic_i8(x: *mut i8) { + atomic_xadd(x, 1); +} +#[cfg(target_has_atomic = "16")] +pub unsafe fn atomic_u16(x: *mut u16) { + atomic_xadd(x, 1); +} +#[cfg(target_has_atomic = "16")] +pub unsafe fn atomic_i16(x: *mut i16) { + atomic_xadd(x, 1); +} +#[cfg(target_has_atomic = "32")] +pub unsafe fn atomic_u32(x: *mut u32) { + atomic_xadd(x, 1); +} +#[cfg(target_has_atomic = "32")] +pub unsafe fn atomic_i32(x: *mut i32) { + atomic_xadd(x, 1); +} +#[cfg(target_has_atomic = "64")] +pub unsafe fn atomic_u64(x: *mut u64) { + atomic_xadd(x, 1); +} +#[cfg(target_has_atomic = "64")] +pub unsafe fn atomic_i64(x: *mut i64) { + atomic_xadd(x, 1); +} +#[cfg(target_has_atomic = "ptr")] +pub unsafe fn atomic_usize(x: *mut usize) { + atomic_xadd(x, 1); +} +#[cfg(target_has_atomic = "ptr")] +pub unsafe fn atomic_isize(x: *mut isize) { + atomic_xadd(x, 1); +}