about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorBjörn Steinbrink <bsteinbr@gmail.com>2014-01-14 18:01:24 +0100
committerBjörn Steinbrink <bsteinbr@gmail.com>2014-01-14 19:22:23 +0100
commit5902263d0af99fba3f286f589ac864ad9ccffc42 (patch)
tree930a5e0243edd9bc3cfebc595ee44ccd56a10e96 /src/libstd
parent77eeddaa481fa083dfa857e5d7dd7f5ab784a9f1 (diff)
downloadrust-5902263d0af99fba3f286f589ac864ad9ccffc42.tar.gz
rust-5902263d0af99fba3f286f589ac864ad9ccffc42.zip
Fix the representation of C void pointers in LLVM IR
Currently, we have c_void defined to be represented as an empty struct,
but LLVM expects C's void* to be represented as i8*. That means we
currently generate code in which LLVM doesn't recognize malloc() and
free() and can't apply certain optimization that would remove calls to
those functions.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/libc.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/libstd/libc.rs b/src/libstd/libc.rs
index ac4be8fec93..6b54a176e89 100644
--- a/src/libstd/libc.rs
+++ b/src/libstd/libc.rs
@@ -194,8 +194,19 @@ pub mod types {
             This type is only useful as a pointer target. Do not use it as a
             return type for FFI functions which have the `void` return type in
             C. Use the unit type `()` or omit the return type instead.
+
+            For LLVM to recognize the void pointer type and by extension
+            functions like malloc(), we need to have it represented as i8* in
+            LLVM bitcode. The enum used here ensures this and prevents misuse
+            of the "raw" type by only having private variants.. We need two
+            variants, because the compiler complains about the repr attribute
+            otherwise.
             */
-            pub enum c_void {}
+            #[repr(u8)]
+            pub enum c_void {
+                priv variant1,
+                priv variant2
+            }
             pub enum FILE {}
             pub enum fpos_t {}
         }