]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_gcc/tests/run/static.rs
Rollup merge of #99192 - Amanieu:fix-asm-srcloc, r=petrochenkov
[rust.git] / compiler / rustc_codegen_gcc / tests / run / static.rs
1 // Compiler:
2 //
3 // Run-time:
4 //   status: 0
5 //   stdout: 10
6 //      14
7 //      1
8 //      12
9 //      12
10 //      1
11
12 #![feature(auto_traits, lang_items, no_core, start, intrinsics)]
13
14 #![no_std]
15 #![no_core]
16
17 /*
18  * Core
19  */
20
21 // Because we don't have core yet.
22 #[lang = "sized"]
23 pub trait Sized {}
24
25 #[lang = "destruct"]
26 pub trait Destruct {}
27
28 #[lang = "drop"]
29 pub trait Drop {}
30
31 #[lang = "copy"]
32 trait Copy {
33 }
34
35 impl Copy for isize {}
36
37 #[lang = "receiver"]
38 trait Receiver {
39 }
40
41 #[lang = "freeze"]
42 pub(crate) unsafe auto trait Freeze {}
43
44 mod intrinsics {
45     use super::Sized;
46
47     extern "rust-intrinsic" {
48         pub fn abort() -> !;
49     }
50 }
51
52 mod libc {
53     #[link(name = "c")]
54     extern "C" {
55         pub fn printf(format: *const i8, ...) -> i32;
56     }
57 }
58
59 #[lang = "structural_peq"]
60 pub trait StructuralPartialEq {}
61
62 #[lang = "structural_teq"]
63 pub trait StructuralEq {}
64
65 #[lang = "drop_in_place"]
66 #[allow(unconditional_recursion)]
67 pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
68     // Code here does not matter - this is replaced by the
69     // real drop glue by the compiler.
70     drop_in_place(to_drop);
71 }
72
73 /*
74  * Code
75  */
76
77 struct Test {
78     field: isize,
79 }
80
81 struct WithRef {
82     refe: &'static Test,
83 }
84
85 static mut CONSTANT: isize = 10;
86
87 static mut TEST: Test = Test {
88     field: 12,
89 };
90
91 static mut TEST2: Test = Test {
92     field: 14,
93 };
94
95 static mut WITH_REF: WithRef = WithRef {
96     refe: unsafe { &TEST },
97 };
98
99 #[start]
100 fn main(mut argc: isize, _argv: *const *const u8) -> isize {
101     unsafe {
102         libc::printf(b"%ld\n\0" as *const u8 as *const i8, CONSTANT);
103         libc::printf(b"%ld\n\0" as *const u8 as *const i8, TEST2.field);
104         TEST2.field = argc;
105         libc::printf(b"%ld\n\0" as *const u8 as *const i8, TEST2.field);
106         libc::printf(b"%ld\n\0" as *const u8 as *const i8, WITH_REF.refe.field);
107         WITH_REF.refe = &TEST2;
108         libc::printf(b"%ld\n\0" as *const u8 as *const i8, TEST.field);
109         libc::printf(b"%ld\n\0" as *const u8 as *const i8, WITH_REF.refe.field);
110     }
111     0
112 }