aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust/execute/torture/issue-2180.rs
blob: 6bd71720e48181429e662f7401511f8059da56cf (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
32
33
34
35
36
37
// { dg-output "123\r*\n" }
#[lang = "sized"]
pub trait Sized {}

trait A {
    fn get_int(&self) -> i32;
}

impl A for i32 {
    fn get_int(&self) -> i32 {
        *self
    }
}

fn get_dyn_a(x: &i32) -> &dyn A {
    x as &dyn A
}

fn clobber_stack() {
    let _z: [usize; 8] = [1, 2, 3, 4, 5, 6, 7, 8];
}

extern "C" {
    fn printf(s: *const i8, ...) -> i32;
}

fn main() -> i32 {
    let x = 123;
    let y = get_dyn_a(&x);
    clobber_stack();
    let value = y.get_int();
    let fmt_string = "%d\n\0" as *const str as *const i8;
    unsafe {
        printf(fmt_string, value);
    }
    return 0;
}