]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/issue-29663.rs
New upstream version 1.19.0+dfsg1
[rustc.git] / src / test / run-pass / issue-29663.rs
CommitLineData
54a0048b
SL
1// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11// write_volatile causes an LLVM assert with composite types
12
7cac9316
XL
13// ignore-emscripten See #41299: probably a bad optimization
14
54a0048b
SL
15#![feature(volatile)]
16use std::ptr::{read_volatile, write_volatile};
17
18#[derive(Debug, Eq, PartialEq)]
19struct A(u32);
20#[derive(Debug, Eq, PartialEq)]
21struct B(u64);
22#[derive(Debug, Eq, PartialEq)]
23struct C(u32, u32);
24#[derive(Debug, Eq, PartialEq)]
25struct D(u64, u64);
26#[derive(Debug, Eq, PartialEq)]
27struct E([u64; 32]);
28
29fn main() {
30 unsafe {
31 let mut x: u32 = 0;
32 write_volatile(&mut x, 1);
33 assert_eq!(read_volatile(&x), 1);
34 assert_eq!(x, 1);
35
36 let mut x: u64 = 0;
37 write_volatile(&mut x, 1);
38 assert_eq!(read_volatile(&x), 1);
39 assert_eq!(x, 1);
40
41 let mut x = A(0);
42 write_volatile(&mut x, A(1));
43 assert_eq!(read_volatile(&x), A(1));
44 assert_eq!(x, A(1));
45
46 let mut x = B(0);
47 write_volatile(&mut x, B(1));
48 assert_eq!(read_volatile(&x), B(1));
49 assert_eq!(x, B(1));
50
51 let mut x = C(0, 0);
52 write_volatile(&mut x, C(1, 1));
53 assert_eq!(read_volatile(&x), C(1, 1));
54 assert_eq!(x, C(1, 1));
55
56 let mut x = D(0, 0);
57 write_volatile(&mut x, D(1, 1));
58 assert_eq!(read_volatile(&x), D(1, 1));
59 assert_eq!(x, D(1, 1));
60
61 let mut x = E([0; 32]);
62 write_volatile(&mut x, E([1; 32]));
63 assert_eq!(read_volatile(&x), E([1; 32]));
64 assert_eq!(x, E([1; 32]));
65 }
66}