about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorDan Robertson <dan@dlrobertson.com>2019-02-05 15:52:54 +0000
committerDan Robertson <dan@dlrobertson.com>2019-02-05 21:20:07 +0000
commit80c052bed76d7b7406e956747012bc8a929fe909 (patch)
tree77a17b1ae61363f1c0191da16bee3d4324b2956c /src/test
parentb2c6b8c29f13f8d1f242da89e587960b95337819 (diff)
downloadrust-80c052bed76d7b7406e956747012bc8a929fe909.tar.gz
rust-80c052bed76d7b7406e956747012bc8a929fe909.zip
Do not ICE in codegen given a extern_type static
The layout of a extern_type static is unsized, but may pass the
Well-Formed check in typeck. As a result, we cannot assume that
a static is sized when generating the `Place` for an r-value.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-make-fulldeps/static-extern-type/Makefile5
-rw-r--r--src/test/run-make-fulldeps/static-extern-type/define-foo.c11
-rw-r--r--src/test/run-make-fulldeps/static-extern-type/use-foo.rs14
3 files changed, 30 insertions, 0 deletions
diff --git a/src/test/run-make-fulldeps/static-extern-type/Makefile b/src/test/run-make-fulldeps/static-extern-type/Makefile
new file mode 100644
index 00000000000..5879fc0ce77
--- /dev/null
+++ b/src/test/run-make-fulldeps/static-extern-type/Makefile
@@ -0,0 +1,5 @@
+-include ../tools.mk
+
+all: $(call NATIVE_STATICLIB,define-foo)
+	$(RUSTC) -ldefine-foo use-foo.rs
+	$(call RUN,use-foo) || exit 1
diff --git a/src/test/run-make-fulldeps/static-extern-type/define-foo.c b/src/test/run-make-fulldeps/static-extern-type/define-foo.c
new file mode 100644
index 00000000000..39be5acfa11
--- /dev/null
+++ b/src/test/run-make-fulldeps/static-extern-type/define-foo.c
@@ -0,0 +1,11 @@
+#include <stdint.h>
+
+struct Foo {
+    uint8_t x;
+};
+
+struct Foo FOO = { 42 };
+
+uint8_t bar(const struct Foo* foo) {
+    return foo->x;
+}
diff --git a/src/test/run-make-fulldeps/static-extern-type/use-foo.rs b/src/test/run-make-fulldeps/static-extern-type/use-foo.rs
new file mode 100644
index 00000000000..932b5b5944b
--- /dev/null
+++ b/src/test/run-make-fulldeps/static-extern-type/use-foo.rs
@@ -0,0 +1,14 @@
+#![feature(extern_types)]
+
+extern "C" {
+    type Foo;
+    static FOO: Foo;
+    fn bar(foo: *const Foo) -> u8;
+}
+
+fn main() {
+    unsafe {
+        let foo = &FOO;
+        assert_eq!(bar(foo), 42);
+    }
+}