Debian Codegraph @

gcc/testsuite/rust/execute/torture/builtin_macro_include_bytes.rs

raw
1 // { dg-output "1\r*\n1\r*\n1\r*\n" }
2
3 #![feature(rustc_attrs)]
4
5 #[rustc_builtin_macro]
6 macro_rules! include_bytes {
7 () => {{}};
8 }
9
10 macro_rules! my_file {
11 () => {"include.txt"};
12 }
13
14 extern "C" {
15 fn printf(s: *const i8, ...);
16 }
17
18 fn print_int(value: i32) {
19 let s = "%d\n\0" as *const str as *const i8;
20 unsafe {
21 printf(s, value);
22 }
23 }
24
25 fn check_bytes(bytes: &[u8; 16]) {
26 let the_bytes = b"hello, include!\n";
27
28 let mut x = true;
29 let mut i = 0;
30
31 // X is true iff bytes == the_bytes
32 while i < 16 {
33 x = x && (bytes[i] == the_bytes[i]);
34 i += 1;
35 }
36
37 print_int(x as i32);
38 }
39
40 fn main() -> i32 {
41 let bytes1: &'static [u8; 16] = include_bytes!("include.txt");
42 check_bytes(bytes1);
43
44 let bytes2: &'static [u8; 16] = include_bytes!(my_file!());
45 check_bytes(bytes2);
46
47 let bytes3 = include_bytes!(my_file!(),);
48 check_bytes(bytes3);
49
50 0
51 }