about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2011-10-07 12:05:38 -0700
committerBrian Anderson <banderson@mozilla.com>2011-10-12 16:33:06 -0700
commitd4d7eb069b1a9299605bdfd513917fa9a0981702 (patch)
treeb72307b5b65c57a4b0d3090de2a76ac73c757aaf /src/comp
parentc1cefa52d01bb9a1ff55e76da8320641040d79cc (diff)
downloadrust-d4d7eb069b1a9299605bdfd513917fa9a0981702.tar.gz
rust-d4d7eb069b1a9299605bdfd513917fa9a0981702.zip
add unsafe tags into various points in the translation chains
and so forth
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/back/link.rs10
-rw-r--r--src/comp/lib/llvm.rs12
-rw-r--r--src/comp/metadata/creader.rs34
-rw-r--r--src/comp/middle/trans_build.rs77
-rw-r--r--src/comp/middle/trans_common.rs65
5 files changed, 125 insertions, 73 deletions
diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs
index 52024d6f5b7..01f44cd2edb 100644
--- a/src/comp/back/link.rs
+++ b/src/comp/back/link.rs
@@ -35,10 +35,12 @@ tag output_type {
 }
 
 fn llvm_err(sess: session::session, msg: str) {
-    let buf = llvm::LLVMRustGetLastError();
-    if buf == std::ptr::null() {
-        sess.fatal(msg);
-    } else { sess.fatal(msg + ": " + str::str_from_cstr(buf)); }
+    unsafe {
+        let buf = llvm::LLVMRustGetLastError();
+        if buf == std::ptr::null() {
+            sess.fatal(msg);
+        } else { sess.fatal(msg + ": " + str::str_from_cstr(buf)); }
+    }
 }
 
 fn link_intrinsics(sess: session::session, llmod: ModuleRef) {
diff --git a/src/comp/lib/llvm.rs b/src/comp/lib/llvm.rs
index c47f75135d7..2cf85bcd218 100644
--- a/src/comp/lib/llvm.rs
+++ b/src/comp/lib/llvm.rs
@@ -961,7 +961,9 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
         let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
         let n_args: uint = llvm::LLVMCountParamTypes(ty);
         let args: [TypeRef] = vec::init_elt::<TypeRef>(0 as TypeRef, n_args);
-        llvm::LLVMGetParamTypes(ty, vec::to_ptr(args));
+        unsafe {
+            llvm::LLVMGetParamTypes(ty, vec::to_ptr(args));
+        }
         s += tys_str(names, outer, args);
         s += ") -> ";
         s += type_to_str_inner(names, outer, out_ty);
@@ -971,7 +973,9 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
         let s: str = "{";
         let n_elts: uint = llvm::LLVMCountStructElementTypes(ty);
         let elts: [TypeRef] = vec::init_elt::<TypeRef>(0 as TypeRef, n_elts);
-        llvm::LLVMGetStructElementTypes(ty, vec::to_ptr(elts));
+        unsafe {
+            llvm::LLVMGetStructElementTypes(ty, vec::to_ptr(elts));
+        }
         s += tys_str(names, outer, elts);
         s += "}";
         ret s;
@@ -1011,7 +1015,9 @@ fn float_width(llt: TypeRef) -> uint {
 
 fn fn_ty_param_tys(fn_ty: TypeRef) -> [TypeRef] {
     let args = vec::init_elt(0 as TypeRef, llvm::LLVMCountParamTypes(fn_ty));
-    llvm::LLVMGetParamTypes(fn_ty, vec::to_ptr(args));
+    unsafe {
+        llvm::LLVMGetParamTypes(fn_ty, vec::to_ptr(args));
+    }
     ret args;
 }
 
diff --git a/src/comp/metadata/creader.rs b/src/comp/metadata/creader.rs
index 90da54f36b3..1dd51a8b680 100644
--- a/src/comp/metadata/creader.rs
+++ b/src/comp/metadata/creader.rs
@@ -170,24 +170,26 @@ fn find_library_crate_aux(nn: {prefix: str, suffix: str}, crate_name: str,
 }
 
 fn get_metadata_section(filename: str) -> option::t<@[u8]> {
-    let mb = str::as_buf(filename, {|buf|
-        llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
-    });
-    if mb as int == 0 { ret option::none::<@[u8]>; }
-    let of = mk_object_file(mb);
-    let si = mk_section_iter(of.llof);
-    while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
-        let name_buf = llvm::LLVMGetSectionName(si.llsi);
-        let name = str::str_from_cstr(name_buf);
-        if str::eq(name, x86::get_meta_sect_name()) {
-            let cbuf = llvm::LLVMGetSectionContents(si.llsi);
-            let csz = llvm::LLVMGetSectionSize(si.llsi);
-            let cvbuf: *u8 = std::unsafe::reinterpret_cast(cbuf);
-            ret option::some::<@[u8]>(@vec::unsafe::from_buf(cvbuf, csz));
+    unsafe {
+        let mb = str::as_buf(filename, {|buf|
+            llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
+                                       });
+        if mb as int == 0 { ret option::none::<@[u8]>; }
+        let of = mk_object_file(mb);
+        let si = mk_section_iter(of.llof);
+        while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
+            let name_buf = llvm::LLVMGetSectionName(si.llsi);
+            let name = str::str_from_cstr(name_buf);
+            if str::eq(name, x86::get_meta_sect_name()) {
+                let cbuf = llvm::LLVMGetSectionContents(si.llsi);
+                let csz = llvm::LLVMGetSectionSize(si.llsi);
+                let cvbuf: *u8 = std::unsafe::reinterpret_cast(cbuf);
+                ret option::some::<@[u8]>(@vec::unsafe::from_buf(cvbuf, csz));
+            }
+            llvm::LLVMMoveToNextSection(si.llsi);
         }
-        llvm::LLVMMoveToNextSection(si.llsi);
+        ret option::none::<@[u8]>;
     }
-    ret option::none::<@[u8]>;
 }
 
 fn load_library_crate(sess: session::session, span: span, ident: ast::ident,
diff --git a/src/comp/middle/trans_build.rs b/src/comp/middle/trans_build.rs
index 384cbb49ff9..7cf9a9c27b3 100644
--- a/src/comp/middle/trans_build.rs
+++ b/src/comp/middle/trans_build.rs
@@ -37,8 +37,10 @@ fn AggregateRet(cx: @block_ctxt, RetVals: [ValueRef]) {
     if cx.unreachable { ret; }
     assert (!cx.terminated);
     cx.terminated = true;
-    llvm::LLVMBuildAggregateRet(B(cx), vec::to_ptr(RetVals),
-                                vec::len(RetVals));
+    unsafe {
+        llvm::LLVMBuildAggregateRet(B(cx), vec::to_ptr(RetVals),
+                                    vec::len(RetVals));
+    }
 }
 
 fn Br(cx: @block_ctxt, Dest: BasicBlockRef) {
@@ -88,8 +90,10 @@ fn Invoke(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef],
     if cx.unreachable { ret; }
     assert (!cx.terminated);
     cx.terminated = true;
-    llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args),
-                          vec::len(Args), Then, Catch, noname());
+    unsafe {
+        llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args),
+                              vec::len(Args), Then, Catch, noname());
+    }
 }
 
 fn FastInvoke(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef],
@@ -97,9 +101,11 @@ fn FastInvoke(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef],
     if cx.unreachable { ret; }
     assert (!cx.terminated);
     cx.terminated = true;
-    let v = llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args),
-                                  vec::len(Args), Then, Catch, noname());
-    llvm::LLVMSetInstructionCallConv(v, lib::llvm::LLVMFastCallConv);
+    unsafe {
+        let v = llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args),
+                                      vec::len(Args), Then, Catch, noname());
+        llvm::LLVMSetInstructionCallConv(v, lib::llvm::LLVMFastCallConv);
+    }
 }
 
 fn Unreachable(cx: @block_ctxt) {
@@ -311,15 +317,19 @@ fn Store(cx: @block_ctxt, Val: ValueRef, Ptr: ValueRef) {
 
 fn GEP(cx: @block_ctxt, Pointer: ValueRef, Indices: [ValueRef]) -> ValueRef {
     if cx.unreachable { ret llvm::LLVMGetUndef(T_ptr(T_nil())); }
-    ret llvm::LLVMBuildGEP(B(cx), Pointer, vec::to_ptr(Indices),
-                           vec::len(Indices), noname());
+    unsafe {
+        ret llvm::LLVMBuildGEP(B(cx), Pointer, vec::to_ptr(Indices),
+                               vec::len(Indices), noname());
+    }
 }
 
 fn InBoundsGEP(cx: @block_ctxt, Pointer: ValueRef, Indices: [ValueRef]) ->
    ValueRef {
     if cx.unreachable { ret llvm::LLVMGetUndef(T_ptr(T_nil())); }
-    ret llvm::LLVMBuildInBoundsGEP(B(cx), Pointer, vec::to_ptr(Indices),
-                                   vec::len(Indices), noname());
+    unsafe {
+        ret llvm::LLVMBuildInBoundsGEP(B(cx), Pointer, vec::to_ptr(Indices),
+                                       vec::len(Indices), noname());
+    }
 }
 
 fn StructGEP(cx: @block_ctxt, Pointer: ValueRef, Idx: uint) -> ValueRef {
@@ -460,9 +470,11 @@ fn Phi(cx: @block_ctxt, Ty: TypeRef, vals: [ValueRef], bbs: [BasicBlockRef])
     if cx.unreachable { ret llvm::LLVMGetUndef(Ty); }
     assert (vec::len::<ValueRef>(vals) == vec::len::<BasicBlockRef>(bbs));
     let phi = EmptyPhi(cx, Ty);
-    llvm::LLVMAddIncoming(phi, vec::to_ptr(vals), vec::to_ptr(bbs),
-                          vec::len(vals));
-    ret phi;
+    unsafe {
+        llvm::LLVMAddIncoming(phi, vec::to_ptr(vals), vec::to_ptr(bbs),
+                              vec::len(vals));
+        ret phi;
+    }
 }
 
 fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) {
@@ -480,26 +492,32 @@ fn _UndefReturn(Fn: ValueRef) -> ValueRef {
 }
 
 fn Call(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef {
-    if cx.unreachable { ret _UndefReturn(Fn); }
-    ret llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
-                            vec::len(Args), noname());
+    unsafe {
+        if cx.unreachable { ret _UndefReturn(Fn); }
+        ret llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
+                                vec::len(Args), noname());
+    }
 }
 
 fn FastCall(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef {
-    if cx.unreachable { ret _UndefReturn(Fn); }
-    let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
-                                vec::len(Args), noname());
-    llvm::LLVMSetInstructionCallConv(v, lib::llvm::LLVMFastCallConv);
-    ret v;
+    unsafe {
+        if cx.unreachable { ret _UndefReturn(Fn); }
+        let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
+                                    vec::len(Args), noname());
+        llvm::LLVMSetInstructionCallConv(v, lib::llvm::LLVMFastCallConv);
+        ret v;
+    }
 }
 
 fn CallWithConv(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef], Conv: uint)
    -> ValueRef {
-    if cx.unreachable { ret _UndefReturn(Fn); }
-    let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
-                                vec::len(Args), noname());
-    llvm::LLVMSetInstructionCallConv(v, Conv);
-    ret v;
+    unsafe {
+        if cx.unreachable { ret _UndefReturn(Fn); }
+        let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
+                                    vec::len(Args), noname());
+        llvm::LLVMSetInstructionCallConv(v, Conv);
+        ret v;
+    }
 }
 
 fn Select(cx: @block_ctxt, If: ValueRef, Then: ValueRef, Else: ValueRef) ->
@@ -568,7 +586,10 @@ fn Trap(cx: @block_ctxt) {
     });
     assert (T as int != 0);
     let Args: [ValueRef] = [];
-    llvm::LLVMBuildCall(b, T, vec::to_ptr(Args), vec::len(Args), noname());
+    unsafe {
+        llvm::LLVMBuildCall(b, T, vec::to_ptr(Args),
+                            vec::len(Args), noname());
+    }
 }
 
 fn LandingPad(cx: @block_ctxt, Ty: TypeRef, PersFn: ValueRef,
diff --git a/src/comp/middle/trans_common.rs b/src/comp/middle/trans_common.rs
index 9e0f99685a5..945530d87d2 100644
--- a/src/comp/middle/trans_common.rs
+++ b/src/comp/middle/trans_common.rs
@@ -518,8 +518,10 @@ fn T_size_t() -> TypeRef {
 }
 
 fn T_fn(inputs: [TypeRef], output: TypeRef) -> TypeRef {
-    ret llvm::LLVMFunctionType(output, to_ptr(inputs),
-                               std::vec::len::<TypeRef>(inputs), False);
+    unsafe {
+        ret llvm::LLVMFunctionType(output, to_ptr(inputs),
+                                   std::vec::len::<TypeRef>(inputs), False);
+    }
 }
 
 fn T_fn_pair(cx: crate_ctxt, tfn: TypeRef) -> TypeRef {
@@ -529,7 +531,9 @@ fn T_fn_pair(cx: crate_ctxt, tfn: TypeRef) -> TypeRef {
 fn T_ptr(t: TypeRef) -> TypeRef { ret llvm::LLVMPointerType(t, 0u); }
 
 fn T_struct(elts: [TypeRef]) -> TypeRef {
-    ret llvm::LLVMStructType(to_ptr(elts), std::vec::len(elts), False);
+    unsafe {
+        ret llvm::LLVMStructType(to_ptr(elts), std::vec::len(elts), False);
+    }
 }
 
 fn T_named_struct(name: str) -> TypeRef {
@@ -538,7 +542,9 @@ fn T_named_struct(name: str) -> TypeRef {
 }
 
 fn set_struct_body(t: TypeRef, elts: [TypeRef]) {
-    llvm::LLVMStructSetBody(t, to_ptr(elts), std::vec::len(elts), False);
+    unsafe {
+        llvm::LLVMStructSetBody(t, to_ptr(elts), std::vec::len(elts), False);
+    }
 }
 
 fn T_empty_struct() -> TypeRef { ret T_struct([]); }
@@ -578,12 +584,15 @@ fn T_task() -> TypeRef {
 fn T_tydesc_field(cx: crate_ctxt, field: int) -> TypeRef {
     // Bit of a kludge: pick the fn typeref out of the tydesc..
 
-    let tydesc_elts: [TypeRef] =
-        std::vec::init_elt::<TypeRef>(T_nil(), abi::n_tydesc_fields as uint);
-    llvm::LLVMGetStructElementTypes(cx.tydesc_type,
-                                    to_ptr::<TypeRef>(tydesc_elts));
-    let t = llvm::LLVMGetElementType(tydesc_elts[field]);
-    ret t;
+    unsafe {
+        let tydesc_elts: [TypeRef] =
+            std::vec::init_elt::<TypeRef>(T_nil(),
+                                          abi::n_tydesc_fields as uint);
+        llvm::LLVMGetStructElementTypes(cx.tydesc_type,
+                                        to_ptr::<TypeRef>(tydesc_elts));
+        let t = llvm::LLVMGetElementType(tydesc_elts[field]);
+        ret t;
+    }
 }
 
 fn T_glue_fn(cx: crate_ctxt) -> TypeRef {
@@ -790,30 +799,42 @@ fn C_postr(s: str) -> ValueRef {
 }
 
 fn C_zero_byte_arr(size: uint) -> ValueRef {
-    let i = 0u;
-    let elts: [ValueRef] = [];
-    while i < size { elts += [C_u8(0u)]; i += 1u; }
-    ret llvm::LLVMConstArray(T_i8(), std::vec::to_ptr(elts),
-                             std::vec::len(elts));
+    unsafe {
+        let i = 0u;
+        let elts: [ValueRef] = [];
+        while i < size { elts += [C_u8(0u)]; i += 1u; }
+        ret llvm::LLVMConstArray(T_i8(), std::vec::to_ptr(elts),
+                                 std::vec::len(elts));
+    }
 }
 
 fn C_struct(elts: [ValueRef]) -> ValueRef {
-    ret llvm::LLVMConstStruct(std::vec::to_ptr(elts), std::vec::len(elts),
-                              False);
+    unsafe {
+        ret llvm::LLVMConstStruct(std::vec::to_ptr(elts), std::vec::len(elts),
+                                  False);
+    }
 }
 
 fn C_named_struct(T: TypeRef, elts: [ValueRef]) -> ValueRef {
-    ret llvm::LLVMConstNamedStruct(T, std::vec::to_ptr(elts),
-                                   std::vec::len(elts));
+    unsafe {
+        ret llvm::LLVMConstNamedStruct(T, std::vec::to_ptr(elts),
+                                       std::vec::len(elts));
+    }
 }
 
 fn C_array(ty: TypeRef, elts: [ValueRef]) -> ValueRef {
-    ret llvm::LLVMConstArray(ty, std::vec::to_ptr(elts), std::vec::len(elts));
+    unsafe {
+        ret llvm::LLVMConstArray(ty, std::vec::to_ptr(elts),
+                                 std::vec::len(elts));
+    }
 }
 
 fn C_bytes(bytes: [u8]) -> ValueRef {
-    ret llvm::LLVMConstString(unsafe::reinterpret_cast(vec::to_ptr(bytes)),
-                              vec::len(bytes), False);
+    unsafe {
+        ret llvm::LLVMConstString(
+            unsafe::reinterpret_cast(vec::to_ptr(bytes)),
+            vec::len(bytes), False);
+    }
 }
 
 fn C_shape(ccx: @crate_ctxt, bytes: [u8]) -> ValueRef {