diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-02-17 15:08:28 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-02-18 16:46:10 +0100 |
commit | af789a7079408782f76dc29efa7a8368740dc2ee (patch) | |
tree | 4c52557a56fa1ccfa38e9689696e3768230d549d /gcc | |
parent | ad7e4bb6f8e19efbae93332f25f3a4897fedbb74 (diff) | |
download | gcc-af789a7079408782f76dc29efa7a8368740dc2ee.zip gcc-af789a7079408782f76dc29efa7a8368740dc2ee.tar.gz gcc-af789a7079408782f76dc29efa7a8368740dc2ee.tar.bz2 |
macros: Add test cases for repetitions
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/rust/compile/macro6.rs | 11 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/macro7.rs | 13 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/macro8.rs | 12 | ||||
-rw-r--r-- | gcc/testsuite/rust/execute/xfail/macro4.rs | 24 | ||||
-rw-r--r-- | gcc/testsuite/rust/execute/xfail/macro5.rs | 23 | ||||
-rw-r--r-- | gcc/testsuite/rust/execute/xfail/macro6.rs | 23 |
6 files changed, 106 insertions, 0 deletions
diff --git a/gcc/testsuite/rust/compile/macro6.rs b/gcc/testsuite/rust/compile/macro6.rs new file mode 100644 index 0000000..e59155c --- /dev/null +++ b/gcc/testsuite/rust/compile/macro6.rs @@ -0,0 +1,11 @@ +macro_rules! zero_or_one { + ($($a:literal)?) => { // { dg-error "invalid amount of matches for macro invocation. Expected between 0 and 1, got 2" } + f() + } +} + +fn main() { + zero_or_one!(); + zero_or_one!(14); + zero_or_one!(125 12 "gcc"); // { dg-error "Failed to match any rule within macro" } +} diff --git a/gcc/testsuite/rust/compile/macro7.rs b/gcc/testsuite/rust/compile/macro7.rs new file mode 100644 index 0000000..b57c5cb --- /dev/null +++ b/gcc/testsuite/rust/compile/macro7.rs @@ -0,0 +1,13 @@ +fn f() {} + +macro_rules! one_or_more { + ($($a:literal)+) => { // { dg-error "invalid amount of matches for macro invocation" } + f() + } +} + +fn main() { + one_or_more!(1 1 1 1 1 1 1 1 1 1 1 "rust" 'c'); + one_or_more!(1); + one_or_more!(); // { dg-error "Failed to match any rule within macro" } +} diff --git a/gcc/testsuite/rust/compile/macro8.rs b/gcc/testsuite/rust/compile/macro8.rs new file mode 100644 index 0000000..756d5b0 --- /dev/null +++ b/gcc/testsuite/rust/compile/macro8.rs @@ -0,0 +1,12 @@ +fn f() {} + +macro_rules! expr { + ($($a:expr)?) => { + f() + } +} + +fn main() { + expr!(); + expr!(14); +} diff --git a/gcc/testsuite/rust/execute/xfail/macro4.rs b/gcc/testsuite/rust/execute/xfail/macro4.rs new file mode 100644 index 0000000..8005caf --- /dev/null +++ b/gcc/testsuite/rust/execute/xfail/macro4.rs @@ -0,0 +1,24 @@ +// { dg-output "any\nany\nany\nany\nany\n" } +extern "C" { + fn printf(s: *const i8, ...); +} + +fn f() { + let r_s = "any\n\0"; + let s_p = r_s as *const str; + let c_p = s_p as *const i8; + + printf(c_p); +} + +macro_rules! any { + ($($a:expr)*) => { + $($a;)* + } +} + +fn main() { + any!(); // valid, but does not print anything + any!(f() f()); + any!(f() f() f()); +} diff --git a/gcc/testsuite/rust/execute/xfail/macro5.rs b/gcc/testsuite/rust/execute/xfail/macro5.rs new file mode 100644 index 0000000..b8130d8 --- /dev/null +++ b/gcc/testsuite/rust/execute/xfail/macro5.rs @@ -0,0 +1,23 @@ +// { dg-output "zo1\nzo1\n" } +extern "C" { + fn printf(s: *const i8, ...); +} + +fn f() { + let r_s = "zo1\n\0"; + let s_p = r_s as *const str; + let c_p = s_p as *const i8; + + unsafe { printf(c_p); } +} + +macro_rules! zero_or_one { + ($($a:expr)?) => { + f() + } +} + +fn main() { + zero_or_one!(); + zero_or_one!(f()); +} diff --git a/gcc/testsuite/rust/execute/xfail/macro6.rs b/gcc/testsuite/rust/execute/xfail/macro6.rs new file mode 100644 index 0000000..77107ef --- /dev/null +++ b/gcc/testsuite/rust/execute/xfail/macro6.rs @@ -0,0 +1,23 @@ +// { dg-output "oom\noom\noom\n" } +extern "C" { + fn printf(s: *const i8, ...); +} + +fn f() { + let r_s = "oom\n\0"; + let s_p = r_s as *const str; + let c_p = s_p as *const i8; + + unsafe { printf(c_p); } +} + +macro_rules! one_or_more { + ($($a:expr)+) => { + $($a;)+ + } +} + +fn main() { + one_or_more!(f()); + one_or_more!(f() f()); +} |