add unsafe tags into various points in the translation chains
and so forth
This commit is contained in:
parent
c1cefa52d0
commit
d4d7eb069b
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -256,7 +256,7 @@ fn unsafe_from_bytes() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn str_from_cstr() {
|
||||
unsafe fn str_from_cstr() {
|
||||
let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8];
|
||||
let b = vec::to_ptr(a);
|
||||
let c = str::str_from_cstr(b);
|
||||
@ -278,7 +278,7 @@ fn as_buf_small() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn as_buf2() {
|
||||
unsafe fn as_buf2() {
|
||||
let s = "hello";
|
||||
let sb = str::as_buf(s, {|b| b });
|
||||
let s_cstr = str::str_from_cstr(sb);
|
||||
|
@ -21,7 +21,7 @@ fn square_if_odd(&&n: uint) -> option::t<uint> {
|
||||
fn add(&&x: uint, &&y: uint) -> uint { ret x + y; }
|
||||
|
||||
#[test]
|
||||
fn test_unsafe_ptrs() {
|
||||
unsafe fn test_unsafe_ptrs() {
|
||||
// Test on-stack copy-from-buf.
|
||||
let a = [1, 2, 3];
|
||||
let ptr = vec::to_ptr(a);
|
||||
|
Loading…
x
Reference in New Issue
Block a user