about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn VanEnk <jvanenk@fastly.com>2020-01-10 17:59:18 -0800
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2020-02-08 06:17:03 +0200
commit26bb0f15e7e97bc93385296c2932193fe6da6300 (patch)
tree0f0cc13e1d43f4579fe70da6c24e3a61228aa6b3
parentf1b52b34f201456d8a0e9da907e3e5619fa24ac7 (diff)
downloadrust-26bb0f15e7e97bc93385296c2932193fe6da6300.tar.gz
rust-26bb0f15e7e97bc93385296c2932193fe6da6300.zip
Add similar examples that work to each test.
-rw-r--r--src/test/run-make-fulldeps/arguments-non-c-like-enum/nonclike.rs20
-rw-r--r--src/test/run-make-fulldeps/arguments-non-c-like-enum/test.c32
-rw-r--r--src/test/run-make-fulldeps/return-non-c-like-enum/nonclike.rs11
-rw-r--r--src/test/run-make-fulldeps/return-non-c-like-enum/test.c30
4 files changed, 87 insertions, 6 deletions
diff --git a/src/test/run-make-fulldeps/arguments-non-c-like-enum/nonclike.rs b/src/test/run-make-fulldeps/arguments-non-c-like-enum/nonclike.rs
index 563f907608b..8f75076a30e 100644
--- a/src/test/run-make-fulldeps/arguments-non-c-like-enum/nonclike.rs
+++ b/src/test/run-make-fulldeps/arguments-non-c-like-enum/nonclike.rs
@@ -1,7 +1,23 @@
 #![crate_type = "lib"]
 #![crate_name = "nonclike"]
 
-#[repr(C,u8)]
+#[repr(C, u8)]
+pub enum TT {
+    AA(u64, u64),
+    BB,
+}
+
+#[no_mangle]
+pub extern "C" fn tt_add(a: TT, b: TT) -> u64 {
+    match (a, b) {
+        (TT::AA(a1, b1), TT::AA(a2, b2)) => a1 + a2 + b1 + b2,
+        (TT::AA(a1, b1), TT::BB) => a1 + b1,
+        (TT::BB, TT::AA(a1, b1)) => a1 + b1,
+        _ => 0,
+    }
+}
+
+#[repr(C, u8)]
 pub enum T {
     A(u64),
     B,
@@ -9,7 +25,7 @@ pub enum T {
 
 #[no_mangle]
 pub extern "C" fn t_add(a: T, b: T) -> u64 {
-    match (a,b) {
+    match (a, b) {
         (T::A(a), T::A(b)) => a + b,
         (T::A(a), T::B) => a,
         (T::B, T::A(b)) => b,
diff --git a/src/test/run-make-fulldeps/arguments-non-c-like-enum/test.c b/src/test/run-make-fulldeps/arguments-non-c-like-enum/test.c
index f622471e7d1..d34babcf3d3 100644
--- a/src/test/run-make-fulldeps/arguments-non-c-like-enum/test.c
+++ b/src/test/run-make-fulldeps/arguments-non-c-like-enum/test.c
@@ -3,6 +3,26 @@
 
 #include <stdio.h>
 
+/* This is the code generated by cbindgen 0.12.1 for the `enum TT`
+ * type in nonclike.rs . */
+enum TT_Tag {
+  AA,
+  BB,
+};
+typedef uint8_t TT_Tag;
+
+typedef struct {
+  uint64_t _0;
+  uint64_t _1;
+} AA_Body;
+
+typedef struct {
+  TT_Tag tag;
+  union {
+    AA_Body aa;
+  };
+} TT;
+
 /* This is the code generated by cbindgen 0.12.1 for the `enum T` type
  * in nonclike.rs . */
 enum T_Tag {
@@ -22,18 +42,24 @@ typedef struct {
   };
 } T;
 
-/* This symbol is defined by the Rust staticlib built from
+/* These symbols are defined by the Rust staticlib built from
  * nonclike.rs. */
 extern uint64_t t_add(T a, T b);
+extern uint64_t tt_add(TT a, TT b);
 
 int main(int argc, char *argv[]) {
   (void)argc; (void)argv;
 
+  /* This example works. */
+  TT xx = { .tag = AA, .aa = { ._0 = 1, ._1 = 2 } };
+  TT yy = { .tag = AA, .aa = { ._0 = 10, ._1 = 20 } };
+  uint64_t rr = tt_add(xx, yy);
+  assert(33 == rr);
+
+  /* This one returns an incorrect result. */
   T x = { .tag = A, .a = { ._0 = 1 } };
   T y = { .tag = A, .a = { ._0 = 10 } };
-
   uint64_t r = t_add(x, y);
-
   assert(11 == r);
 
   return 0;
diff --git a/src/test/run-make-fulldeps/return-non-c-like-enum/nonclike.rs b/src/test/run-make-fulldeps/return-non-c-like-enum/nonclike.rs
index 36f618b05e8..700d2df1f38 100644
--- a/src/test/run-make-fulldeps/return-non-c-like-enum/nonclike.rs
+++ b/src/test/run-make-fulldeps/return-non-c-like-enum/nonclike.rs
@@ -1,6 +1,17 @@
 #![crate_type = "lib"]
 #![crate_name = "nonclike"]
 
+#[repr(C, u8)]
+pub enum TT {
+    AA(u64, u64),
+    BB,
+}
+
+#[no_mangle]
+pub extern "C" fn tt_new(a: u64, b: u64) -> TT {
+    TT::AA(a, b)
+}
+
 #[repr(C,u8)]
 pub enum T {
     A(u64),
diff --git a/src/test/run-make-fulldeps/return-non-c-like-enum/test.c b/src/test/run-make-fulldeps/return-non-c-like-enum/test.c
index bcc17c0008d..3cbd8e6a20c 100644
--- a/src/test/run-make-fulldeps/return-non-c-like-enum/test.c
+++ b/src/test/run-make-fulldeps/return-non-c-like-enum/test.c
@@ -1,6 +1,26 @@
 #include <stdint.h>
 #include <assert.h>
 
+/* This is the code generated by cbindgen 0.12.1 for the `enum TT`
+ * type in nonclike.rs . */
+enum TT_Tag {
+  AA,
+  BB,
+};
+typedef uint8_t TT_Tag;
+
+typedef struct {
+  uint64_t _0;
+  uint64_t _1;
+} AA_Body;
+
+typedef struct {
+  TT_Tag tag;
+  union {
+    AA_Body aa;
+  };
+} TT;
+
 /* This is the code generated by cbindgen 0.12.1 for the `enum T` type
  * in nonclike.rs . */
 enum T_Tag {
@@ -20,13 +40,21 @@ typedef struct {
   };
 } T;
 
-/* This symbol is defined by the Rust staticlib built from
+/* These symbols are defined by the Rust staticlib built from
  * nonclike.rs. */
+extern TT tt_new(uint64_t a, uint64_t b);
 extern T t_new(uint64_t v);
 
 int main(int argc, char *argv[]) {
   (void)argc; (void)argv;
 
+  /* This example works. */
+  TT tt = tt_new(10, 20);
+  assert(AA == tt.tag);
+  assert(10 == tt.aa._0);
+  assert(20 == tt.aa._1);
+
+  /* This one segfaults. */
   T t = t_new(10);
   assert(A == t.tag);
   assert(10 == t.a._0);