]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_gcc/tests/run/static.rs
Auto merge of #92419 - erikdesjardins:coldland, r=nagisa
[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 = "copy"]
26 trait Copy {
27 }
28
29 impl Copy for isize {}
30
31 #[lang = "receiver"]
32 trait Receiver {
33 }
34
35 #[lang = "freeze"]
36 pub(crate) unsafe auto trait Freeze {}
37
38 mod intrinsics {
39     use super::Sized;
40
41     extern "rust-intrinsic" {
42         pub fn abort() -> !;
43     }
44 }
45
46 mod libc {
47     #[link(name = "c")]
48     extern "C" {
49         pub fn printf(format: *const i8, ...) -> i32;
50     }
51 }
52
53 #[lang = "structural_peq"]
54 pub trait StructuralPartialEq {}
55
56 #[lang = "structural_teq"]
57 pub trait StructuralEq {}
58
59 #[lang = "drop_in_place"]
60 #[allow(unconditional_recursion)]
61 pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
62     // Code here does not matter - this is replaced by the
63     // real drop glue by the compiler.
64     drop_in_place(to_drop);
65 }
66
67 /*
68  * Code
69  */
70
71 struct Test {
72     field: isize,
73 }
74
75 struct WithRef {
76     refe: &'static Test,
77 }
78
79 static mut CONSTANT: isize = 10;
80
81 static mut TEST: Test = Test {
82     field: 12,
83 };
84
85 static mut TEST2: Test = Test {
86     field: 14,
87 };
88
89 static mut WITH_REF: WithRef = WithRef {
90     refe: unsafe { &TEST },
91 };
92
93 #[start]
94 fn main(mut argc: isize, _argv: *const *const u8) -> isize {
95     unsafe {
96         libc::printf(b"%ld\n\0" as *const u8 as *const i8, CONSTANT);
97         libc::printf(b"%ld\n\0" as *const u8 as *const i8, TEST2.field);
98         TEST2.field = argc;
99         libc::printf(b"%ld\n\0" as *const u8 as *const i8, TEST2.field);
100         libc::printf(b"%ld\n\0" as *const u8 as *const i8, WITH_REF.refe.field);
101         WITH_REF.refe = &TEST2;
102         libc::printf(b"%ld\n\0" as *const u8 as *const i8, TEST.field);
103         libc::printf(b"%ld\n\0" as *const u8 as *const i8, WITH_REF.refe.field);
104     }
105     0
106 }