]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add testcase to show matching of enum variants
authorPhilip Herron <herron.philip@googlemail.com>
Wed, 29 Mar 2023 21:27:38 +0000 (22:27 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:34:10 +0000 (18:34 +0100)
Fixes #852

gcc/testsuite/ChangeLog:

* rust/compile/issue-852.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/testsuite/rust/compile/issue-852.rs [new file with mode: 0644]

diff --git a/gcc/testsuite/rust/compile/issue-852.rs b/gcc/testsuite/rust/compile/issue-852.rs
new file mode 100644 (file)
index 0000000..763105d
--- /dev/null
@@ -0,0 +1,30 @@
+// { dg-options "-w" }
+extern "C" {
+    fn printf(s: *const i8, ...);
+}
+
+enum Foo {
+    A,
+    B(i32),
+}
+
+fn main() {
+    let result = Foo::B(123);
+
+    match result {
+        A => unsafe {
+            let a = "A\n\0";
+            let b = a as *const str;
+            let c = b as *const i8;
+
+            printf(c);
+        },
+        Foo::B(x) => unsafe {
+            let a = "Result: %i\n\0";
+            let b = a as *const str;
+            let c = b as *const i8;
+
+            printf(c, x);
+        },
+    }
+}