diff options
| author | John VanEnk <jvanenk@fastly.com> | 2020-01-10 17:16:04 -0800 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2020-02-08 06:17:02 +0200 |
| commit | cd5ad993d093f8ee5eedb63ed888a2ae2c35299f (patch) | |
| tree | d8f4fc78ea1109943a5b7c3c2b9b0aec7d84b758 | |
| parent | 8498c5f5b02dbb4ed58a1eb4901b0b733342c35f (diff) | |
| download | rust-cd5ad993d093f8ee5eedb63ed888a2ae2c35299f.tar.gz rust-cd5ad993d093f8ee5eedb63ed888a2ae2c35299f.zip | |
Add a test that demonstrates a segfault when calling into rust with non-c-like-enum.
3 files changed, 55 insertions, 0 deletions
diff --git a/src/test/run-make-fulldeps/return-non-c-like-enum/Makefile b/src/test/run-make-fulldeps/return-non-c-like-enum/Makefile new file mode 100644 index 00000000000..5b5d620efe6 --- /dev/null +++ b/src/test/run-make-fulldeps/return-non-c-like-enum/Makefile @@ -0,0 +1,7 @@ +-include ../tools.mk + +all: + $(RUSTC) --crate-type=staticlib nonclike.rs + $(CC) test.c $(call STATICLIB,nonclike) $(call OUT_EXE,test) \ + $(EXTRACFLAGS) $(EXTRACXXFLAGS) + $(call RUN,test) 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 new file mode 100644 index 00000000000..36f618b05e8 --- /dev/null +++ b/src/test/run-make-fulldeps/return-non-c-like-enum/nonclike.rs @@ -0,0 +1,13 @@ +#![crate_type = "lib"] +#![crate_name = "nonclike"] + +#[repr(C,u8)] +pub enum T { + A(u64), + B, +} + +#[no_mangle] +pub extern "C" fn t_new(a: u64) -> T { + T::A(a) +} 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 new file mode 100644 index 00000000000..bcc17c0008d --- /dev/null +++ b/src/test/run-make-fulldeps/return-non-c-like-enum/test.c @@ -0,0 +1,35 @@ +#include <stdint.h> +#include <assert.h> + +/* This is the code generated by cbindgen 0.12.1 for the `enum T` type + * in nonclike.rs . */ +enum T_Tag { + A, + B, +}; +typedef uint8_t T_Tag; + +typedef struct { + uint64_t _0; +} A_Body; + +typedef struct { + T_Tag tag; + union { + A_Body a; + }; +} T; + +/* This symbol is defined by the Rust staticlib built from + * nonclike.rs. */ +extern T t_new(uint64_t v); + +int main(int argc, char *argv[]) { + (void)argc; (void)argv; + + T t = t_new(10); + assert(A == t.tag); + assert(10 == t.a._0); + + return 0; +} |
