diff options
author | Liam Naddell <liam.naddell@mail.utoronto.ca> | 2024-07-27 00:28:13 -0400 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-19 15:32:03 +0100 |
commit | ad3fc42abd84b7fc40e78c3a83b883c9b83af22d (patch) | |
tree | 784787bf6a0b18a86499203c61dbdb93ee32aa06 /gcc/testsuite/rust/execute | |
parent | 86970cc56e6d3521a815ce7e3bf14071ce61ff98 (diff) | |
download | gcc-ad3fc42abd84b7fc40e78c3a83b883c9b83af22d.zip gcc-ad3fc42abd84b7fc40e78c3a83b883c9b83af22d.tar.gz gcc-ad3fc42abd84b7fc40e78c3a83b883c9b83af22d.tar.bz2 |
gccrs: Eager expansion for include* gccrs#1805 gccrs#1865
gcc/rust/ChangeLog:
* expand/rust-expand-visitor.h:
remove auto keyword
* expand/rust-macro-builtins-helpers.cc:
allow for changing macro invoc types on eager expansions to
semicoloned macros
* expand/rust-macro-builtins-helpers.h:
add default semicoloned argument
* expand/rust-macro-builtins-include.cc:
allow for eager expansion for include and include_bytes
allow for parsing include invocations as items instead of
expressions, which allows invocations at global scope
* expand/rust-macro-expand.cc:
push Expr type for eager invocations
gcc/testsuite/ChangeLog:
* rust/compile/macros/builtin/include1.rs:
add basic include test at global scope
* rust/compile/macros/builtin/include2.rs:
add basic include test at local scope with expression
* rust/compile/macros/builtin/include3.rs:
add eager expansion test at global scope
* rust/compile/macros/builtin/include4.rs:
add eager expansion test at local scope with expression
* rust/compile/macros/builtin/include_bytes.rs:
add eager expansion test at global scope
* rust/compile/macros/builtin/include_rs:
supporting test file with dummy function
* rust/compile/macros/builtin/include_rs2:
supporting test file with dummy string
* rust/compile/macros/builtin/include_str.rs:
add eager expansion test at global scope
* rust/execute/torture/builtin_macro_include_bytes.rs:
clean up old test logic, add permutations for eager expansion
* rust/execute/torture/builtin_macro_include_str.rs:
add eager expansion permutations
Diffstat (limited to 'gcc/testsuite/rust/execute')
-rw-r--r-- | gcc/testsuite/rust/execute/torture/builtin_macro_include_bytes.rs | 49 | ||||
-rw-r--r-- | gcc/testsuite/rust/execute/torture/builtin_macro_include_str.rs | 11 |
2 files changed, 35 insertions, 25 deletions
diff --git a/gcc/testsuite/rust/execute/torture/builtin_macro_include_bytes.rs b/gcc/testsuite/rust/execute/torture/builtin_macro_include_bytes.rs index 19a1faf..6aec417 100644 --- a/gcc/testsuite/rust/execute/torture/builtin_macro_include_bytes.rs +++ b/gcc/testsuite/rust/execute/torture/builtin_macro_include_bytes.rs @@ -1,4 +1,5 @@ -// { dg-output "104\r*\n33\r*\n1\r*\n" } +// { dg-output "1\r*\n1\r*\n1\r*\n" } + #![feature(rustc_attrs)] #[rustc_builtin_macro] @@ -6,6 +7,10 @@ macro_rules! include_bytes { () => {{}}; } +macro_rules! my_file { + () => {"include.txt"}; +} + extern "C" { fn printf(s: *const i8, ...); } @@ -17,32 +22,30 @@ fn print_int(value: i32) { } } -fn main() -> i32 { - let bytes = include_bytes!("include.txt"); - - print_int(bytes[0] as i32); - print_int(bytes[14] as i32); - +fn check_bytes(bytes: &[u8; 16]) { let the_bytes = b"hello, include!\n"; - let x = bytes[0] == the_bytes[0] - && bytes[1] == the_bytes[1] - && bytes[2] == the_bytes[2] - && bytes[3] == the_bytes[3] - && bytes[4] == the_bytes[4] - && bytes[5] == the_bytes[5] - && bytes[6] == the_bytes[6] - && bytes[7] == the_bytes[7] - && bytes[8] == the_bytes[8] - && bytes[9] == the_bytes[9] - && bytes[10] == the_bytes[10] - && bytes[11] == the_bytes[11] - && bytes[12] == the_bytes[12] - && bytes[13] == the_bytes[13] - && bytes[14] == the_bytes[14] - && bytes[15] == the_bytes[15]; + let x = true; + let mut i = 0; + + // X is true iff bytes == the_bytes + while i < 16 { + x = x && (bytes[i] == the_bytes[i]); + i += 1; + } print_int(x as i32); +} + +fn main() -> i32 { + let bytes1: &'static [u8; 16] = include_bytes!("include.txt"); + check_bytes(bytes1); + + let bytes2: &'static [u8; 16] = include_bytes!(my_file!()); + check_bytes(bytes2); + + let bytes3 = include_bytes!(my_file!(),); + check_bytes(bytes3); 0 } diff --git a/gcc/testsuite/rust/execute/torture/builtin_macro_include_str.rs b/gcc/testsuite/rust/execute/torture/builtin_macro_include_str.rs index a65639d..b5454db 100644 --- a/gcc/testsuite/rust/execute/torture/builtin_macro_include_str.rs +++ b/gcc/testsuite/rust/execute/torture/builtin_macro_include_str.rs @@ -1,4 +1,4 @@ -// { dg-output "hello, include!\r*\n" } +// { dg-output "hello, include!\r*\nhello, include!\r*\nhello, include!\r*\n" } #![feature(rustc_attrs)] #[rustc_builtin_macro] @@ -6,6 +6,10 @@ macro_rules! include_str { () => {{}}; } +macro_rules! my_file { + () => {"include.txt"}; +} + extern "C" { fn printf(fmt: *const i8, ...); } @@ -22,7 +26,10 @@ fn print(s: &str) { fn main() -> i32 { // include_str! (and include_bytes!) allow for an optional trailing comma. let my_str = include_str!("include.txt",); - + print(my_str); + let my_str = include_str!(my_file!()); + print(my_str); + let my_str = include_str!(my_file!(),); print(my_str); 0 |