]> git.lizzy.rs Git - rust.git/blob - tests/run-make-fulldeps/arguments-non-c-like-enum/test.c
add (currently ICEing) test
[rust.git] / tests / run-make-fulldeps / arguments-non-c-like-enum / test.c
1 #include <stdint.h>
2 #include <assert.h>
3
4 #include <stdio.h>
5
6 /* This is the code generated by cbindgen 0.12.1 for the `enum TT`
7  * type in nonclike.rs . */
8 enum TT_Tag {
9   AA,
10   BB,
11 };
12 typedef uint8_t TT_Tag;
13
14 typedef struct {
15   uint64_t _0;
16   uint64_t _1;
17 } AA_Body;
18
19 typedef struct {
20   TT_Tag tag;
21   union {
22     AA_Body aa;
23   };
24 } TT;
25
26 /* This is the code generated by cbindgen 0.12.1 for the `enum T` type
27  * in nonclike.rs . */
28 enum T_Tag {
29   A,
30   B,
31 };
32 typedef uint8_t T_Tag;
33
34 typedef struct {
35   uint64_t _0;
36 } A_Body;
37
38 typedef struct {
39   T_Tag tag;
40   union {
41     A_Body a;
42   };
43 } T;
44
45 /* These symbols are defined by the Rust staticlib built from
46  * nonclike.rs. */
47 extern uint64_t t_add(T a, T b);
48 extern uint64_t tt_add(TT a, TT b);
49
50 int main(int argc, char *argv[]) {
51   (void)argc; (void)argv;
52
53   /* This example works. */
54   TT xx = { .tag = AA, .aa = { ._0 = 1, ._1 = 2 } };
55   TT yy = { .tag = AA, .aa = { ._0 = 10, ._1 = 20 } };
56   uint64_t rr = tt_add(xx, yy);
57   assert(33 == rr);
58
59   /* This one used to return an incorrect result (see issue #68190). */
60   T x = { .tag = A, .a = { ._0 = 1 } };
61   T y = { .tag = A, .a = { ._0 = 10 } };
62   uint64_t r = t_add(x, y);
63   assert(11 == r);
64
65   return 0;
66 }