]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-14936.rs
ace1f00b023b58a8847ab40dae2cf496d1c98cd7
[rust.git] / src / test / run-pass / issue-14936.rs
1 // Copyright 2012-2014 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 #![feature(asm)]
12
13 type History = Vec<&'static str>;
14
15 fn wrap<A>(x:A, which: &'static str, history: &mut History) -> A {
16     history.push(which);
17     x
18 }
19
20 macro_rules! demo {
21     ( $output_constraint:tt ) => {
22         {
23             let mut x: int = 0;
24             let y: int = 1;
25
26             let mut history: History = vec!();
27             unsafe {
28                 asm!("mov ($1), $0"
29                      : $output_constraint (*wrap(&mut x, "out", &mut history))
30                      : "r"(&wrap(y, "in", &mut history)));
31             }
32             assert_eq!((x,y), (1,1));
33             let b: &[_] = &["out", "in"];
34             assert_eq!(history, b);
35         }
36     }
37 }
38
39 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
40 fn main() {
41     fn out_write_only_expr_then_in_expr() {
42         demo!("=r")
43     }
44
45     fn out_read_write_expr_then_in_expr() {
46         demo!("+r")
47     }
48
49     out_write_only_expr_then_in_expr();
50     out_read_write_expr_then_in_expr();
51 }
52
53 #[cfg(all(not(target_arch = "x86"), not(target_arch = "x86_64")))]
54 pub fn main() {}