summaryrefslogtreecommitdiffstats
path: root/tests/run-make/issue-25581
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run-make/issue-25581')
-rw-r--r--tests/run-make/issue-25581/Makefile6
-rw-r--r--tests/run-make/issue-25581/test.c15
-rw-r--r--tests/run-make/issue-25581/test.rs18
3 files changed, 39 insertions, 0 deletions
diff --git a/tests/run-make/issue-25581/Makefile b/tests/run-make/issue-25581/Makefile
new file mode 100644
index 000000000..3cbbf3839
--- /dev/null
+++ b/tests/run-make/issue-25581/Makefile
@@ -0,0 +1,6 @@
+# ignore-cross-compile
+include ../tools.mk
+
+all: $(call NATIVE_STATICLIB,test)
+ $(RUSTC) test.rs
+ $(call RUN,test) || exit 1
diff --git a/tests/run-make/issue-25581/test.c b/tests/run-make/issue-25581/test.c
new file mode 100644
index 000000000..52fbf7851
--- /dev/null
+++ b/tests/run-make/issue-25581/test.c
@@ -0,0 +1,15 @@
+#include <stddef.h>
+#include <stdint.h>
+
+struct ByteSlice {
+ uint8_t *data;
+ size_t len;
+};
+
+size_t slice_len(struct ByteSlice bs) {
+ return bs.len;
+}
+
+uint8_t slice_elem(struct ByteSlice bs, size_t idx) {
+ return bs.data[idx];
+}
diff --git a/tests/run-make/issue-25581/test.rs b/tests/run-make/issue-25581/test.rs
new file mode 100644
index 000000000..ba6749c97
--- /dev/null
+++ b/tests/run-make/issue-25581/test.rs
@@ -0,0 +1,18 @@
+#[link(name = "test", kind = "static")]
+extern "C" {
+ fn slice_len(s: &[u8]) -> usize;
+ fn slice_elem(s: &[u8], idx: usize) -> u8;
+}
+
+fn main() {
+ let data = [1, 2, 3, 4, 5];
+
+ unsafe {
+ assert_eq!(data.len(), slice_len(&data) as usize);
+ assert_eq!(data[0], slice_elem(&data, 0));
+ assert_eq!(data[1], slice_elem(&data, 1));
+ assert_eq!(data[2], slice_elem(&data, 2));
+ assert_eq!(data[3], slice_elem(&data, 3));
+ assert_eq!(data[4], slice_elem(&data, 4));
+ }
+}