Debian Codegraph @

gcc/testsuite/rust/compile/torture/intrinsics-5.rs

raw
1 #![feature(intrinsics)]
2
3 #[lang = "sized"]
4 pub trait Sized {}
5
6 #[lang = "clone"]
7 pub trait Clone: Sized {
8 fn clone(&self) -> Self;
9
10 fn clone_from(&mut self, source: &Self) {
11 *self = source.clone()
12 }
13 }
14
15 mod impls {
16 use super::Clone;
17
18 macro_rules! impl_clone {
19 ($($t:ty)*) => {
20 $(
21 impl Clone for $t {
22 fn clone(&self) -> Self {
23 *self
24 }
25 }
26 )*
27 }
28 }
29
30 impl_clone! {
31 usize u8 u16 u32 u64 // u128
32 isize i8 i16 i32 i64 // i128
33 f32 f64
34 bool char
35 }
36 }
37
38 #[lang = "copy"]
39 pub trait Copy: Clone {
40 // Empty.
41 }
42
43 mod copy_impls {
44 use super::Copy;
45
46 macro_rules! impl_copy {
47 ($($t:ty)*) => {
48 $(
49 impl Copy for $t {}
50 )*
51 }
52 }
53
54 impl_copy! {
55 usize u8 u16 u32 u64 // u128
56 isize i8 i16 i32 i64 // i128
57 f32 f64
58 bool char
59 }
60 }
61
62 extern "rust-intrinsic" {
63 pub fn atomic_store_seqcst<T: Copy>(dst: *mut T, value: T);
64 // { dg-error "atomic intrinsics can only be used with basic integer types .got .VeryLargeType.." "" { target *-*-* } .-1 }
65 // { dg-error "atomic intrinsics can only be used with basic integer types .got .bool.." "" { target *-*-* } .-2 }
66 }
67
68 struct VeryLargeType {
69 a0: i128,
70 a1: i128,
71 a2: i128,
72 a3: i128,
73 }
74
75 impl VeryLargeType {
76 pub fn new(value: i128) -> VeryLargeType {
77 VeryLargeType {
78 a0: value,
79 a1: 0,
80 a2: 0,
81 a3: 0,
82 }
83 }
84 }
85
86 impl Clone for VeryLargeType {
87 fn clone(&self) -> Self {
88 *self
89 }
90 }
91 impl Copy for VeryLargeType {}
92
93 fn main() {
94 let mut dst = VeryLargeType::new(0);
95 let mut b = false;
96
97 unsafe {
98 atomic_store_seqcst(&mut dst, VeryLargeType::new(1));
99 atomic_store_seqcst(&mut b, true);
100 }
101 }