]> git.lizzy.rs Git - rust.git/blobdiff - src/test/auxiliary/rust_test_helpers.c
Merge commit 'd556c56f792756dd7cfec742b9f2e07612dc10f4' into sync_cg_clif-2021-02-01
[rust.git] / src / test / auxiliary / rust_test_helpers.c
index b95b0ca1a89c00b103dd9200537be8bff3441ec3..92b7dd4b7c516bc388bec727585953b6989944ba 100644 (file)
@@ -168,6 +168,18 @@ struct floats {
     double c;
 };
 
+struct char_char_double {
+    uint8_t a;
+    uint8_t b;
+    double c;
+};
+
+struct char_char_float {
+    uint8_t a;
+    uint8_t b;
+    float c;
+};
+
 struct quad
 rust_dbg_abi_1(struct quad q) {
     struct quad qq = { q.c + 1,
@@ -185,6 +197,23 @@ rust_dbg_abi_2(struct floats f) {
     return ff;
 }
 
+struct char_char_double
+rust_dbg_abi_3(struct char_char_double a) {
+    struct char_char_double ccd = { a.a + 1,
+                                    a.b - 1,
+                                    a.c + 1.0 };
+    return ccd;
+}
+
+struct char_char_float
+rust_dbg_abi_4(struct char_char_float a) {
+    struct char_char_float ccd = { a.a + 1,
+                                   a.b - 1,
+                                   a.c + 1.0 };
+    return ccd;
+}
+
+
 int
 rust_dbg_static_mut = 3;
 
@@ -300,3 +329,89 @@ __int128 sub(__int128 a, __int128 b) {
 }
 
 #endif
+
+#define OPTION_TAG_NONE (0)
+#define OPTION_TAG_SOME (1)
+
+struct U8TaggedEnumOptionU64 {
+    uint8_t tag;
+    union {
+        uint64_t some;
+    };
+};
+
+struct U8TaggedEnumOptionU64
+rust_dbg_new_some_u64(uint64_t some) {
+    struct U8TaggedEnumOptionU64 r = {
+        .tag = OPTION_TAG_SOME,
+        .some = some,
+    };
+    return r;
+}
+
+struct U8TaggedEnumOptionU64
+rust_dbg_new_none_u64(void) {
+    struct U8TaggedEnumOptionU64 r = {
+        .tag = OPTION_TAG_NONE,
+    };
+    return r;
+}
+
+int32_t
+rust_dbg_unpack_option_u64(struct U8TaggedEnumOptionU64 o, uint64_t *into) {
+    assert(into);
+    switch (o.tag) {
+    case OPTION_TAG_SOME:
+        *into = o.some;
+        return 1;
+    case OPTION_TAG_NONE:
+        return 0;
+    default:
+        assert(0 && "unexpected tag");
+        return 0;
+    }
+}
+
+struct U8TaggedEnumOptionU64U64 {
+    uint8_t tag;
+    union {
+        struct {
+            uint64_t a;
+            uint64_t b;
+        } some;
+    };
+};
+
+struct U8TaggedEnumOptionU64U64
+rust_dbg_new_some_u64u64(uint64_t a, uint64_t b) {
+    struct U8TaggedEnumOptionU64U64 r = {
+        .tag = OPTION_TAG_SOME,
+        .some = { .a = a, .b = b },
+    };
+    return r;
+}
+
+struct U8TaggedEnumOptionU64U64
+rust_dbg_new_none_u64u64(void) {
+    struct U8TaggedEnumOptionU64U64 r = {
+        .tag = OPTION_TAG_NONE,
+    };
+    return r;
+}
+
+int32_t
+rust_dbg_unpack_option_u64u64(struct U8TaggedEnumOptionU64U64 o, uint64_t *a, uint64_t *b) {
+    assert(a);
+    assert(b);
+    switch (o.tag) {
+    case OPTION_TAG_SOME:
+        *a = o.some.a;
+        *b = o.some.b;
+        return 1;
+    case OPTION_TAG_NONE:
+        return 0;
+    default:
+        assert(0 && "unexpected tag");
+        return 0;
+    }
+}