File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed
src/test/run-make-fulldeps/arguments-non-c-like-enum Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change 1+ -include ../tools.mk
2+
3+ all :
4+ $(RUSTC ) --crate-type=staticlib nonclike.rs
5+ $(CC ) test.c $(call STATICLIB,nonclike) $(call OUT_EXE,test) \
6+ $(EXTRACFLAGS ) $(EXTRACXXFLAGS )
7+ $(call RUN,test)
Original file line number Diff line number Diff line change 1+ #![ crate_type = "lib" ]
2+ #![ crate_name = "nonclike" ]
3+
4+ #[ repr( C , u8 ) ]
5+ pub enum T {
6+ A ( u64 ) ,
7+ B ,
8+ }
9+
10+ #[ no_mangle]
11+ pub extern "C" fn t_add ( a : T , b : T ) -> u64 {
12+ match ( a, b) {
13+ ( T :: A ( a) , T :: A ( b) ) => a + b,
14+ ( T :: A ( a) , T :: B ) => a,
15+ ( T :: B , T :: A ( b) ) => b,
16+ _ => 0 ,
17+ }
18+ }
Original file line number Diff line number Diff line change 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 T` type
7+ * in nonclike.rs . */
8+ enum T_Tag {
9+ A ,
10+ B ,
11+ };
12+ typedef uint8_t T_Tag ;
13+
14+ typedef struct {
15+ uint64_t _0 ;
16+ } A_Body ;
17+
18+ typedef struct {
19+ T_Tag tag ;
20+ union {
21+ A_Body a ;
22+ };
23+ } T ;
24+
25+ /* This symbol is defined by the Rust staticlib built from
26+ * nonclike.rs. */
27+ extern uint64_t t_add (T a , T b );
28+
29+ int main (int argc , char * argv []) {
30+ (void )argc ; (void )argv ;
31+
32+ T x = { .tag = A , .a = { ._0 = 1 } };
33+ T y = { .tag = A , .a = { ._0 = 10 } };
34+
35+ uint64_t r = t_add (x , y );
36+
37+ assert (11 == r );
38+
39+ return 0 ;
40+ }
You can’t perform that action at this time.
0 commit comments