Debian Codegraph @

gcc/testsuite/rust/execute/torture/issue-2180.rs

raw
1 // { dg-output "123\r*\n" }
2 #[lang = "sized"]
3 pub trait Sized {}
4
5 trait A {
6 fn get_int(&self) -> i32;
7 }
8
9 impl A for i32 {
10 fn get_int(&self) -> i32 {
11 *self
12 }
13 }
14
15 fn get_dyn_a(x: &i32) -> &dyn A {
16 x as &dyn A
17 }
18
19 fn clobber_stack() {
20 let _z: [usize; 8] = [1, 2, 3, 4, 5, 6, 7, 8];
21 }
22
23 extern "C" {
24 fn printf(s: *const i8, ...) -> i32;
25 }
26
27 fn main() -> i32 {
28 let x = 123;
29 let y = get_dyn_a(&x);
30 clobber_stack();
31 let value = y.get_int();
32 let fmt_string = "%d\n\0" as *const str as *const i8;
33 unsafe {
34 printf(fmt_string, value);
35 }
36 return 0;
37 }