about summary refs log tree commit diff
path: root/src/test/ui/llvm-asm/llvm-asm-in-moved.rs
blob: 35f4d92c8ffbcf6ff9b22721c679f00831395a68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// run-pass

#![feature(llvm_asm)]
#![allow(dead_code)]

use std::cell::Cell;

#[repr(C)]
struct NoisyDrop<'a>(&'a Cell<&'static str>);
impl<'a> Drop for NoisyDrop<'a> {
    fn drop(&mut self) {
        self.0.set("destroyed");
    }
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn main() {
    let status = Cell::new("alive");
    {
        let _y: Box<NoisyDrop>;
        let x = Box::new(NoisyDrop(&status));
        unsafe {
            llvm_asm!("mov $1, $0" : "=r"(_y) : "r"(x));
        }
        assert_eq!(status.get(), "alive");
    }
    assert_eq!(status.get(), "destroyed");
}

#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
fn main() {}