public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] macros: Add test cases for repetitions
@ 2022-06-08 12:09 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:09 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:af789a7079408782f76dc29efa7a8368740dc2ee

commit af789a7079408782f76dc29efa7a8368740dc2ee
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Thu Feb 17 15:08:28 2022 +0100

    macros: Add test cases for repetitions

Diff:
---
 gcc/testsuite/rust/compile/macro6.rs       | 11 +++++++++++
 gcc/testsuite/rust/compile/macro7.rs       | 13 +++++++++++++
 gcc/testsuite/rust/compile/macro8.rs       | 12 ++++++++++++
 gcc/testsuite/rust/execute/xfail/macro4.rs | 24 ++++++++++++++++++++++++
 gcc/testsuite/rust/execute/xfail/macro5.rs | 23 +++++++++++++++++++++++
 gcc/testsuite/rust/execute/xfail/macro6.rs | 23 +++++++++++++++++++++++
 6 files changed, 106 insertions(+)

diff --git a/gcc/testsuite/rust/compile/macro6.rs b/gcc/testsuite/rust/compile/macro6.rs
new file mode 100644
index 00000000000..e59155cf76f
--- /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 00000000000..b57c5cbd473
--- /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 00000000000..756d5b05491
--- /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 00000000000..8005cafe5b7
--- /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 00000000000..b8130d8b28d
--- /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 00000000000..77107ef5976
--- /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());
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:09 [gcc/devel/rust/master] macros: Add test cases for repetitions Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).