Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1403: Warn if int or uint is used in native fn declarations #1539

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/comp/back/link.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

import core::ctypes::{c_int, c_uint};
import driver::session;
import session::session;
import lib::llvm::llvm;
Expand Down Expand Up @@ -170,17 +170,18 @@ mod write {
llvm::LLVMAddTargetData(td.lltd, fpm.llpm);

let FPMB = llvm::LLVMPassManagerBuilderCreate();
llvm::LLVMPassManagerBuilderSetOptLevel(FPMB, 2u);
llvm::LLVMPassManagerBuilderSetOptLevel(FPMB, 2u as c_uint);
llvm::LLVMPassManagerBuilderPopulateFunctionPassManager(FPMB,
fpm.llpm);
llvm::LLVMPassManagerBuilderDispose(FPMB);

llvm::LLVMRunPassManager(fpm.llpm, llmod);
let threshold: uint = 225u;
let threshold = 225u;
if opts.optimize == 3u { threshold = 275u; }

let MPMB = llvm::LLVMPassManagerBuilderCreate();
llvm::LLVMPassManagerBuilderSetOptLevel(MPMB, opts.optimize);
llvm::LLVMPassManagerBuilderSetOptLevel(MPMB,
opts.optimize as c_uint);
llvm::LLVMPassManagerBuilderSetSizeLevel(MPMB, 0);
llvm::LLVMPassManagerBuilderSetDisableUnitAtATime(MPMB, False);
llvm::LLVMPassManagerBuilderSetDisableUnrollLoops(MPMB, False);
Expand All @@ -189,7 +190,7 @@ mod write {

if threshold != 0u {
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold
(MPMB, threshold);
(MPMB, threshold as c_uint);
}
llvm::LLVMPassManagerBuilderPopulateModulePassManager(MPMB,
pm.llpm);
Expand All @@ -198,12 +199,12 @@ mod write {
}
if opts.verify { llvm::LLVMAddVerifierPass(pm.llpm); }
if is_object_or_assembly_or_exe(opts.output_type) {
let LLVMAssemblyFile: int = 0;
let LLVMObjectFile: int = 1;
let LLVMOptNone: int = 0; // -O0
let LLVMOptLess: int = 1; // -O1
let LLVMOptDefault: int = 2; // -O2, -Os
let LLVMOptAggressive: int = 3; // -O3
let LLVMAssemblyFile = 0 as c_int;
let LLVMObjectFile = 1 as c_int;
let LLVMOptNone = 0 as c_int; // -O0
let LLVMOptLess = 1 as c_int; // -O1
let LLVMOptDefault = 2 as c_int; // -O2, -Os
let LLVMOptAggressive = 3 as c_int; // -O3

let CodeGenOptLevel;
alt opts.optimize {
Expand Down
219 changes: 114 additions & 105 deletions src/comp/lib/llvm.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/comp/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ fn get_metadata_section(sess: session::session,
let name = unsafe { str::from_cstr(name_buf) };
if str::eq(name, sess.targ_cfg.target_strs.meta_sect_name) {
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
let csz = llvm::LLVMGetSectionSize(si.llsi);
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
unsafe {
let cvbuf: *u8 = unsafe::reinterpret_cast(cbuf);
ret option::some::<@[u8]>(@vec::unsafe::from_buf(cvbuf, csz));
Expand Down
4 changes: 2 additions & 2 deletions src/comp/middle/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const DW_ATE_unsigned_char: int = 0x08;

fn llstr(s: str) -> ValueRef {
str::as_buf(s, {|sbuf|
llvm::LLVMMDString(sbuf, str::byte_len(s))
llvm::LLVMMDString(sbuf, str::byte_len(s) as ctypes::c_uint)
})
}
fn lltag(lltag: int) -> ValueRef {
Expand All @@ -62,7 +62,7 @@ fn lli1(bval: bool) -> ValueRef {
}
fn llmdnode(elems: [ValueRef]) -> ValueRef unsafe {
llvm::LLVMMDNode(vec::unsafe::to_ptr(elems),
vec::len(elems))
vec::len(elems) as ctypes::c_uint)
}
fn llunused() -> ValueRef {
lli32(0x0)
Expand Down
61 changes: 34 additions & 27 deletions src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// but many TypeRefs correspond to one ty::t; for instance, tup(int, int,
// int) and rec(x=int, y=int, z=int) will have the same TypeRef.

import core::ctypes::c_uint;
import std::{map, time};
import std::map::hashmap;
import std::map::{new_int_hash, new_str_hash};
Expand Down Expand Up @@ -291,11 +292,12 @@ fn log_fn_time(ccx: @crate_ctxt, name: str, start: time::timeval,
}


fn decl_fn(llmod: ModuleRef, name: str, cc: uint, llty: TypeRef) -> ValueRef {
fn decl_fn(llmod: ModuleRef, name: str, cc: uint, llty: TypeRef) ->
ValueRef {
let llfn: ValueRef =
str::as_buf(name, {|buf|
llvm::LLVMGetOrInsertFunction(llmod, buf, llty) });
llvm::LLVMSetFunctionCallConv(llfn, cc);
llvm::LLVMSetFunctionCallConv(llfn, cc as c_uint);
ret llfn;
}

Expand Down Expand Up @@ -338,7 +340,8 @@ fn get_simple_extern_fn(cx: @block_ctxt,
let inputs = vec::init_elt::<TypeRef>(ccx.int_type, n_args as uint);
let output = ccx.int_type;
let t = T_fn(inputs, output);
ret get_extern_fn(externs, llmod, name, lib::llvm::LLVMCCallConv, t);
ret get_extern_fn(externs, llmod, name,
lib::llvm::LLVMCCallConv, t);
}

fn trans_native_call(cx: @block_ctxt, externs: hashmap<str, ValueRef>,
Expand Down Expand Up @@ -389,12 +392,12 @@ fn align_to(cx: @block_ctxt, off: ValueRef, align: ValueRef) -> ValueRef {

// Returns the real size of the given type for the current target.
fn llsize_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
ret llvm::LLVMStoreSizeOfType(cx.td.lltd, t);
ret llvm::LLVMStoreSizeOfType(cx.td.lltd, t) as uint;
}

// Returns the real alignment of the given type for the current target.
fn llalign_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
ret llvm::LLVMPreferredAlignmentOfType(cx.td.lltd, t);
ret llvm::LLVMPreferredAlignmentOfType(cx.td.lltd, t) as uint;
}

fn llsize_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef {
Expand Down Expand Up @@ -1067,7 +1070,7 @@ fn set_no_inline(f: ValueRef) {
llvm::LLVMAddFunctionAttr(f,
lib::llvm::LLVMNoInlineAttribute as
lib::llvm::llvm::Attribute,
0u);
0u as c_uint);
}

// Tell LLVM to emit the information necessary to unwind the stack for the
Expand All @@ -1076,19 +1079,20 @@ fn set_uwtable(f: ValueRef) {
llvm::LLVMAddFunctionAttr(f,
lib::llvm::LLVMUWTableAttribute as
lib::llvm::llvm::Attribute,
0u);
0u as c_uint);
}

fn set_always_inline(f: ValueRef) {
llvm::LLVMAddFunctionAttr(f,
lib::llvm::LLVMAlwaysInlineAttribute as
lib::llvm::llvm::Attribute,
0u);
0u as c_uint);
}

fn set_custom_stack_growth_fn(f: ValueRef) {
// TODO: Remove this hack to work around the lack of u64 in the FFI.
llvm::LLVMAddFunctionAttr(f, 0 as lib::llvm::llvm::Attribute, 1u);
llvm::LLVMAddFunctionAttr(f, 0 as lib::llvm::llvm::Attribute,
1u as c_uint);
}

fn set_glue_inlining(cx: @local_ctxt, f: ValueRef, t: ty::t) {
Expand Down Expand Up @@ -1175,7 +1179,7 @@ fn make_generic_glue_inner(cx: @local_ctxt, sp: span, t: ty::t,
} else { T_ptr(T_i8()) };

let ty_param_count = vec::len::<uint>(ty_params);
let lltyparams = llvm::LLVMGetParam(llfn, 2u);
let lltyparams = llvm::LLVMGetParam(llfn, 2u as c_uint);
let load_env_bcx = new_raw_block_ctxt(fcx, fcx.llloadenv);
let lltydescs = [mutable];
let p = 0u;
Expand All @@ -1190,7 +1194,7 @@ fn make_generic_glue_inner(cx: @local_ctxt, sp: span, t: ty::t,

let bcx = new_top_block_ctxt(fcx);
let lltop = bcx.llbb;
let llrawptr0 = llvm::LLVMGetParam(llfn, 3u);
let llrawptr0 = llvm::LLVMGetParam(llfn, 3u as c_uint);
let llval0 = BitCast(bcx, llrawptr0, llty);
helper(bcx, llval0, t);
finish_fn(fcx, lltop);
Expand Down Expand Up @@ -4302,8 +4306,8 @@ fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: span, llfndecl: ValueRef,
-> @fn_ctxt {
let llbbs = mk_standard_basic_blocks(llfndecl);
ret @{llfn: llfndecl,
llenv: llvm::LLVMGetParam(llfndecl, 1u),
llretptr: llvm::LLVMGetParam(llfndecl, 0u),
llenv: llvm::LLVMGetParam(llfndecl, 1u as c_uint),
llretptr: llvm::LLVMGetParam(llfndecl, 0u as c_uint),
mutable llstaticallocas: llbbs.sa,
mutable llloadenv: llbbs.ca,
mutable llderivedtydescs_first: llbbs.dt,
Expand Down Expand Up @@ -4354,12 +4358,13 @@ fn create_llargs_for_fn_args(cx: @fn_ctxt, ty_self: self_arg,
no_self. {}
}
for tp in ty_params {
let lltydesc = llvm::LLVMGetParam(cx.llfn, arg_n), dicts = none;
let lltydesc = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);
let dicts = none;
arg_n += 1u;
for bound in *fcx_tcx(cx).ty_param_bounds.get(tp.id) {
alt bound {
ty::bound_iface(_) {
let dict = llvm::LLVMGetParam(cx.llfn, arg_n);
let dict = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);
arg_n += 1u;
dicts = some(alt dicts {
none. { [dict] }
Expand All @@ -4375,7 +4380,7 @@ fn create_llargs_for_fn_args(cx: @fn_ctxt, ty_self: self_arg,
// Populate the llargs field of the function context with the ValueRefs
// that we get from llvm::LLVMGetParam for each argument.
for arg: ast::arg in args {
let llarg = llvm::LLVMGetParam(cx.llfn, arg_n);
let llarg = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);
assert (llarg as int != 0);
// Note that this uses local_mem even for things passed by value.
// copy_args_to_allocas will overwrite the table entry with local_imm
Expand Down Expand Up @@ -4804,7 +4809,7 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
let fcx = new_fn_ctxt(lcx, span, llshimfn);
let bcx = new_top_block_ctxt(fcx);
let lltop = bcx.llbb;
let llargbundle = llvm::LLVMGetParam(llshimfn, 0u);
let llargbundle = llvm::LLVMGetParam(llshimfn, 0 as c_uint);
let i = 0u, n = vec::len(tys.arg_tys);
let llargvals = [];
while i < n {
Expand All @@ -4814,7 +4819,8 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
}

// Create the call itself and store the return value:
let llretval = CallWithConv(bcx, llbasefn, llargvals, cc); // r
let llretval = CallWithConv(bcx, llbasefn,
llargvals, cc as c_uint); // r
if tys.ret_def {
// R** llretptr = &args->r;
let llretptr = GEPi(bcx, llargbundle, [0, n as int]);
Expand Down Expand Up @@ -4848,11 +4854,12 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
let i = 0u, n = vec::len(tys.arg_tys);
let implicit_args = 2u + num_tps; // ret + env
while i < n {
let llargval = llvm::LLVMGetParam(llwrapfn, i + implicit_args);
let llargval = llvm::LLVMGetParam(llwrapfn,
(i + implicit_args) as c_uint);
store_inbounds(bcx, llargval, llargbundle, [0, i as int]);
i += 1u;
}
let llretptr = llvm::LLVMGetParam(llwrapfn, 0u);
let llretptr = llvm::LLVMGetParam(llwrapfn, 0 as c_uint);
store_inbounds(bcx, llretptr, llargbundle, [0, n as int]);

// Create call itself.
Expand All @@ -4865,7 +4872,7 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
}

let ccx = lcx_ccx(lcx);
let cc: uint = lib::llvm::LLVMCCallConv;
let cc = lib::llvm::LLVMCCallConv;
alt abi {
ast::native_abi_rust_intrinsic. { ret; }
ast::native_abi_cdecl. { cc = lib::llvm::LLVMCCallConv; }
Expand Down Expand Up @@ -5037,10 +5044,10 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
let bcx = new_top_block_ctxt(fcx);
let lltop = bcx.llbb;

let lloutputarg = llvm::LLVMGetParam(llfdecl, 0u);
let llenvarg = llvm::LLVMGetParam(llfdecl, 1u);
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0 as c_uint);
let llenvarg = llvm::LLVMGetParam(llfdecl, 1 as c_uint);
let args = [lloutputarg, llenvarg];
if takes_argv { args += [llvm::LLVMGetParam(llfdecl, 2u)]; }
if takes_argv { args += [llvm::LLVMGetParam(llfdecl, 2 as c_uint)]; }
Call(bcx, main_llfn, args);
build_return(bcx);

Expand Down Expand Up @@ -5071,11 +5078,11 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
let start = str::as_buf("rust_start", {|buf|
llvm::LLVMAddGlobal(ccx.llmod, start_ty, buf)
});
let args = [rust_main, llvm::LLVMGetParam(llfn, 0u),
llvm::LLVMGetParam(llfn, 1u), crate_map];
let args = [rust_main, llvm::LLVMGetParam(llfn, 0 as c_uint),
llvm::LLVMGetParam(llfn, 1 as c_uint), crate_map];
let result = unsafe {
llvm::LLVMBuildCall(bld, start, vec::to_ptr(args),
vec::len(args), noname())
vec::len(args) as c_uint, noname())
};
llvm::LLVMBuildRet(bld, result);
}
Expand Down
Loading