Skip to content

Commit 04882d7

Browse files
committed
rustc: Use integer from ctypes consistently
1 parent dde4186 commit 04882d7

File tree

7 files changed

+60
-49
lines changed

7 files changed

+60
-49
lines changed

src/comp/back/link.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -170,27 +170,27 @@ mod write {
170170
llvm::LLVMAddTargetData(td.lltd, fpm.llpm);
171171

172172
let FPMB = llvm::LLVMPassManagerBuilderCreate();
173-
llvm::LLVMPassManagerBuilderSetOptLevel(FPMB, 2u32);
173+
llvm::LLVMPassManagerBuilderSetOptLevel(FPMB, 2u as c_uint);
174174
llvm::LLVMPassManagerBuilderPopulateFunctionPassManager(FPMB,
175175
fpm.llpm);
176176
llvm::LLVMPassManagerBuilderDispose(FPMB);
177177

178178
llvm::LLVMRunPassManager(fpm.llpm, llmod);
179-
let threshold = 225u as c_uint;
180-
if opts.optimize == 3u { threshold = 275u as c_uint; }
179+
let threshold = 225u;
180+
if opts.optimize == 3u { threshold = 275u; }
181181

182182
let MPMB = llvm::LLVMPassManagerBuilderCreate();
183183
llvm::LLVMPassManagerBuilderSetOptLevel(MPMB,
184-
opts.optimize as u32);
184+
opts.optimize as c_uint);
185185
llvm::LLVMPassManagerBuilderSetSizeLevel(MPMB, 0);
186186
llvm::LLVMPassManagerBuilderSetDisableUnitAtATime(MPMB, False);
187187
llvm::LLVMPassManagerBuilderSetDisableUnrollLoops(MPMB, False);
188188
llvm::LLVMPassManagerBuilderSetDisableSimplifyLibCalls(MPMB,
189189
False);
190190

191-
if threshold != 0u32 {
191+
if threshold != 0u {
192192
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold
193-
(MPMB, threshold);
193+
(MPMB, threshold as c_uint);
194194
}
195195
llvm::LLVMPassManagerBuilderPopulateModulePassManager(MPMB,
196196
pm.llpm);

src/comp/middle/debuginfo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const DW_ATE_unsigned_char: int = 0x08;
4646

4747
fn llstr(s: str) -> ValueRef {
4848
str::as_buf(s, {|sbuf|
49-
llvm::LLVMMDString(sbuf, str::byte_len(s) as u32)
49+
llvm::LLVMMDString(sbuf, str::byte_len(s) as ctypes::c_uint)
5050
})
5151
}
5252
fn lltag(lltag: int) -> ValueRef {
@@ -63,7 +63,7 @@ fn lli1(bval: bool) -> ValueRef {
6363
}
6464
fn llmdnode(elems: [ValueRef]) -> ValueRef unsafe {
6565
llvm::LLVMMDNode(vec::unsafe::to_ptr(elems),
66-
vec::len(elems) as u32)
66+
vec::len(elems) as ctypes::c_uint)
6767
}
6868
fn llunused() -> ValueRef {
6969
lli32(0x0)

src/comp/middle/trans.rs

+24-22
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ fn set_no_inline(f: ValueRef) {
10731073
llvm::LLVMAddFunctionAttr(f,
10741074
lib::llvm::LLVMNoInlineAttribute as
10751075
lib::llvm::llvm::Attribute,
1076-
0u32);
1076+
0u as c_uint);
10771077
}
10781078

10791079
// Tell LLVM to emit the information necessary to unwind the stack for the
@@ -1082,19 +1082,20 @@ fn set_uwtable(f: ValueRef) {
10821082
llvm::LLVMAddFunctionAttr(f,
10831083
lib::llvm::LLVMUWTableAttribute as
10841084
lib::llvm::llvm::Attribute,
1085-
0u32);
1085+
0u as c_uint);
10861086
}
10871087

10881088
fn set_always_inline(f: ValueRef) {
10891089
llvm::LLVMAddFunctionAttr(f,
10901090
lib::llvm::LLVMAlwaysInlineAttribute as
10911091
lib::llvm::llvm::Attribute,
1092-
0u32);
1092+
0u as c_uint);
10931093
}
10941094

10951095
fn set_custom_stack_growth_fn(f: ValueRef) {
10961096
// TODO: Remove this hack to work around the lack of u64 in the FFI.
1097-
llvm::LLVMAddFunctionAttr(f, 0 as lib::llvm::llvm::Attribute, 1u32);
1097+
llvm::LLVMAddFunctionAttr(f, 0 as lib::llvm::llvm::Attribute,
1098+
1u as c_uint);
10981099
}
10991100

11001101
fn set_glue_inlining(cx: @local_ctxt, f: ValueRef, t: ty::t) {
@@ -1181,7 +1182,7 @@ fn make_generic_glue_inner(cx: @local_ctxt, sp: span, t: ty::t,
11811182
} else { T_ptr(T_i8()) };
11821183

11831184
let ty_param_count = vec::len::<uint>(ty_params);
1184-
let lltyparams = llvm::LLVMGetParam(llfn, 2u32);
1185+
let lltyparams = llvm::LLVMGetParam(llfn, 2u as c_uint);
11851186
let load_env_bcx = new_raw_block_ctxt(fcx, fcx.llloadenv);
11861187
let lltydescs = [mutable];
11871188
let p = 0u;
@@ -1196,7 +1197,7 @@ fn make_generic_glue_inner(cx: @local_ctxt, sp: span, t: ty::t,
11961197

11971198
let bcx = new_top_block_ctxt(fcx);
11981199
let lltop = bcx.llbb;
1199-
let llrawptr0 = llvm::LLVMGetParam(llfn, 3u32);
1200+
let llrawptr0 = llvm::LLVMGetParam(llfn, 3u as c_uint);
12001201
let llval0 = BitCast(bcx, llrawptr0, llty);
12011202
helper(bcx, llval0, t);
12021203
finish_fn(fcx, lltop);
@@ -4303,8 +4304,8 @@ fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: span, llfndecl: ValueRef,
43034304
-> @fn_ctxt {
43044305
let llbbs = mk_standard_basic_blocks(llfndecl);
43054306
ret @{llfn: llfndecl,
4306-
llenv: llvm::LLVMGetParam(llfndecl, 1u32),
4307-
llretptr: llvm::LLVMGetParam(llfndecl, 0u32),
4307+
llenv: llvm::LLVMGetParam(llfndecl, 1u as c_uint),
4308+
llretptr: llvm::LLVMGetParam(llfndecl, 0u as c_uint),
43084309
mutable llstaticallocas: llbbs.sa,
43094310
mutable llloadenv: llbbs.ca,
43104311
mutable llderivedtydescs_first: llbbs.dt,
@@ -4347,21 +4348,22 @@ fn create_llargs_for_fn_args(cx: @fn_ctxt, ty_self: self_arg,
43474348
// Skip the implicit arguments 0, and 1. TODO: Pull out 2u and define
43484349
// it as a constant, since we're using it in several places in trans this
43494350
// way.
4350-
let arg_n = 2u32;
4351+
let arg_n = 2u;
43514352
alt ty_self {
43524353
impl_self(tt) {
43534354
cx.llself = some({v: cx.llenv, t: tt});
43544355
}
43554356
no_self. {}
43564357
}
43574358
for tp in ty_params {
4358-
let lltydesc = llvm::LLVMGetParam(cx.llfn, arg_n), dicts = none;
4359-
arg_n += 1u32;
4359+
let lltydesc = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);
4360+
let dicts = none;
4361+
arg_n += 1u;
43604362
for bound in *fcx_tcx(cx).ty_param_bounds.get(tp.id) {
43614363
alt bound {
43624364
ty::bound_iface(_) {
4363-
let dict = llvm::LLVMGetParam(cx.llfn, arg_n);
4364-
arg_n += 1u32;
4365+
let dict = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);
4366+
arg_n += 1u;
43654367
dicts = some(alt dicts {
43664368
none. { [dict] }
43674369
some(ds) { ds + [dict] }
@@ -4376,13 +4378,13 @@ fn create_llargs_for_fn_args(cx: @fn_ctxt, ty_self: self_arg,
43764378
// Populate the llargs field of the function context with the ValueRefs
43774379
// that we get from llvm::LLVMGetParam for each argument.
43784380
for arg: ast::arg in args {
4379-
let llarg = llvm::LLVMGetParam(cx.llfn, arg_n);
4381+
let llarg = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);
43804382
assert (llarg as int != 0);
43814383
// Note that this uses local_mem even for things passed by value.
43824384
// copy_args_to_allocas will overwrite the table entry with local_imm
43834385
// before it's actually used.
43844386
cx.llargs.insert(arg.id, local_mem(llarg));
4385-
arg_n += 1u32;
4387+
arg_n += 1u;
43864388
}
43874389
}
43884390

@@ -4801,7 +4803,7 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
48014803
let fcx = new_fn_ctxt(lcx, span, llshimfn);
48024804
let bcx = new_top_block_ctxt(fcx);
48034805
let lltop = bcx.llbb;
4804-
let llargbundle = llvm::LLVMGetParam(llshimfn, 0u32);
4806+
let llargbundle = llvm::LLVMGetParam(llshimfn, 0 as c_uint);
48054807
let i = 0u, n = vec::len(tys.arg_tys);
48064808
let llargvals = [];
48074809
while i < n {
@@ -4851,7 +4853,7 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
48514853
store_inbounds(bcx, llargval, llargbundle, [0, i as int]);
48524854
i += 1u;
48534855
}
4854-
let llretptr = llvm::LLVMGetParam(llwrapfn, 0u32);
4856+
let llretptr = llvm::LLVMGetParam(llwrapfn, 0 as c_uint);
48554857
store_inbounds(bcx, llretptr, llargbundle, [0, n as int]);
48564858

48574859
// Create call itself.
@@ -5036,10 +5038,10 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
50365038
let bcx = new_top_block_ctxt(fcx);
50375039
let lltop = bcx.llbb;
50385040

5039-
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0u32);
5040-
let llenvarg = llvm::LLVMGetParam(llfdecl, 1u32);
5041+
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0 as c_uint);
5042+
let llenvarg = llvm::LLVMGetParam(llfdecl, 1 as c_uint);
50415043
let args = [lloutputarg, llenvarg];
5042-
if takes_argv { args += [llvm::LLVMGetParam(llfdecl, 2u32)]; }
5044+
if takes_argv { args += [llvm::LLVMGetParam(llfdecl, 2 as c_uint)]; }
50435045
Call(bcx, main_llfn, args);
50445046
build_return(bcx);
50455047

@@ -5070,8 +5072,8 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
50705072
let start = str::as_buf("rust_start", {|buf|
50715073
llvm::LLVMAddGlobal(ccx.llmod, start_ty, buf)
50725074
});
5073-
let args = [rust_main, llvm::LLVMGetParam(llfn, 0u32),
5074-
llvm::LLVMGetParam(llfn, 1u32), crate_map];
5075+
let args = [rust_main, llvm::LLVMGetParam(llfn, 0 as c_uint),
5076+
llvm::LLVMGetParam(llfn, 1 as c_uint), crate_map];
50755077
let result = unsafe {
50765078
llvm::LLVMBuildCall(bld, start, vec::to_ptr(args),
50775079
vec::len(args) as c_uint, noname())

src/comp/middle/trans_build.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import core::{vec, str};
2-
import core::ctypes::c_uint;
2+
import core::ctypes::{c_uint, c_int};
33
import str::sbuf;
44
import lib::llvm::llvm;
55
import syntax::codemap;
@@ -311,7 +311,7 @@ fn Load(cx: @block_ctxt, PointerVal: ValueRef) -> ValueRef {
311311
let ccx = cx.fcx.lcx.ccx;
312312
if cx.unreachable {
313313
let ty = val_ty(PointerVal);
314-
let eltty = if llvm::LLVMGetTypeKind(ty) == 11i32 {
314+
let eltty = if llvm::LLVMGetTypeKind(ty) == 11 as c_int {
315315
llvm::LLVMGetElementType(ty) } else { ccx.int_type };
316316
ret llvm::LLVMGetUndef(eltty);
317317
}
@@ -500,14 +500,14 @@ fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) {
500500
unsafe {
501501
let valptr = unsafe::reinterpret_cast(ptr::addr_of(val));
502502
let bbptr = unsafe::reinterpret_cast(ptr::addr_of(bb));
503-
llvm::LLVMAddIncoming(phi, valptr, bbptr, 1u32);
503+
llvm::LLVMAddIncoming(phi, valptr, bbptr, 1 as c_uint);
504504
}
505505
}
506506

507507
fn _UndefReturn(cx: @block_ctxt, Fn: ValueRef) -> ValueRef {
508508
let ccx = cx.fcx.lcx.ccx;
509509
let ty = val_ty(Fn);
510-
let retty = if llvm::LLVMGetTypeKind(ty) == 8i32 {
510+
let retty = if llvm::LLVMGetTypeKind(ty) == 8 as c_int {
511511
llvm::LLVMGetReturnType(ty) } else { ccx.int_type };
512512
ret llvm::LLVMGetUndef(retty);
513513
}

src/comp/middle/trans_closure.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import core::ctypes::c_uint;
12
import syntax::ast;
23
import syntax::ast_util;
34
import lib::llvm::llvm;
@@ -918,7 +919,7 @@ fn trans_bind_thunk(cx: @local_ctxt,
918919
fcx.lltyparams += [{desc: dsc, dicts: dicts}];
919920
}
920921

921-
let a: u32 = 2u32; // retptr, env come first
922+
let a: uint = 2u; // retptr, env come first
922923
let b: int = starting_idx;
923924
let outgoing_arg_index: uint = 0u;
924925
let llout_arg_tys: [TypeRef] =
@@ -955,12 +956,12 @@ fn trans_bind_thunk(cx: @local_ctxt,
955956

956957
// Arg will be provided when the thunk is invoked.
957958
none. {
958-
let arg: ValueRef = llvm::LLVMGetParam(llthunk, a);
959+
let arg: ValueRef = llvm::LLVMGetParam(llthunk, a as c_uint);
959960
if ty::type_contains_params(cx.ccx.tcx, out_arg.ty) {
960961
arg = PointerCast(bcx, arg, llout_arg_ty);
961962
}
962963
llargs += [arg];
963-
a += 1u32;
964+
a += 1u;
964965
}
965966
}
966967
outgoing_arg_index += 1u;

src/comp/middle/trans_impl.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import core::ctypes::c_uint;
12
import trans::*;
23
import trans_common::*;
34
import trans_build::*;
@@ -191,20 +192,22 @@ fn trans_impl_wrapper(ccx: @crate_ctxt, pt: [ast::ident],
191192
vec::slice(real_args, 2u + vec::len(extra_ptrs), vec::len(real_args));
192193
let llfn_ty = T_fn(wrap_args, real_ret);
193194
trans_wrapper(ccx, pt, llfn_ty, {|llfn, bcx|
194-
let dict = PointerCast(bcx, LLVMGetParam(llfn, 0u32), env_ty);
195+
let dict = PointerCast(bcx, LLVMGetParam(llfn, 0 as c_uint), env_ty);
195196
// retptr, self
196-
let args = [LLVMGetParam(llfn, 1u32), LLVMGetParam(llfn, 2u32)];
197+
let args = [LLVMGetParam(llfn, 1 as c_uint),
198+
LLVMGetParam(llfn, 2 as c_uint)];
197199
let i = 0u;
198200
// saved tydescs/dicts
199201
while i < n_extra_ptrs {
200202
i += 1u;
201203
args += [load_inbounds(bcx, dict, [0, i as int])];
202204
}
203205
// the rest of the parameters
204-
let i = 3u32, params_total = llvm::LLVMCountParamTypes(llfn_ty);
205-
while i < params_total {
206-
args += [LLVMGetParam(llfn, i)];
207-
i += 1u32;
206+
let j = 3u as c_uint;
207+
let params_total = llvm::LLVMCountParamTypes(llfn_ty);
208+
while j < params_total {
209+
args += [LLVMGetParam(llfn, j)];
210+
j += 1u as c_uint;
208211
}
209212
Call(bcx, real_fn, args);
210213
bcx
@@ -232,7 +235,8 @@ fn trans_iface_wrapper(ccx: @crate_ctxt, pt: [ast::ident], m: ty::method,
232235
n: uint) -> ValueRef {
233236
let {llty: llfty, _} = wrapper_fn_ty(ccx, T_ptr(T_i8()), m);
234237
trans_wrapper(ccx, pt, llfty, {|llfn, bcx|
235-
let self = Load(bcx, PointerCast(bcx, LLVMGetParam(llfn, 2u32),
238+
let self = Load(bcx, PointerCast(bcx,
239+
LLVMGetParam(llfn, 2u as c_uint),
236240
T_ptr(T_opaque_iface_ptr(ccx))));
237241
let boxed = GEPi(bcx, self, [0, abi::box_rc_field_body]);
238242
let dict = Load(bcx, PointerCast(bcx, GEPi(bcx, boxed, [0, 1]),
@@ -243,12 +247,12 @@ fn trans_iface_wrapper(ccx: @crate_ctxt, pt: [ast::ident], m: ty::method,
243247
// FIXME[impl] This doesn't account for more-than-ptr-sized alignment
244248
let inner_self = GEPi(bcx, boxed, [0, 2]);
245249
let args = [PointerCast(bcx, dict, T_ptr(T_i8())),
246-
LLVMGetParam(llfn, 1u32),
250+
LLVMGetParam(llfn, 1u as c_uint),
247251
PointerCast(bcx, inner_self, T_opaque_cbox_ptr(ccx))];
248-
let i = 3u32, total = llvm::LLVMCountParamTypes(llfty);
252+
let i = 3u as c_uint, total = llvm::LLVMCountParamTypes(llfty);
249253
while i < total {
250254
args += [LLVMGetParam(llfn, i)];
251-
i += 1u32;
255+
i += 1u as c_uint;
252256
}
253257
Call(bcx, mptr, args);
254258
bcx

src/libstd/fs.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ Function: path_is_dir
120120
Indicates whether a path represents a directory.
121121
*/
122122
fn path_is_dir(p: path) -> bool {
123-
ret str::as_buf(p, {|buf| rustrt::rust_path_is_dir(buf) != 0i32 });
123+
ret str::as_buf(p, {|buf|
124+
rustrt::rust_path_is_dir(buf) != 0 as ctypes::c_int
125+
});
124126
}
125127

126128
/*
@@ -129,7 +131,9 @@ Function: path_exists
129131
Indicates whether a path exists.
130132
*/
131133
fn path_exists(p: path) -> bool {
132-
ret str::as_buf(p, {|buf| rustrt::rust_path_exists(buf) != 0i32 });
134+
ret str::as_buf(p, {|buf|
135+
rustrt::rust_path_exists(buf) != 0 as ctypes::c_int
136+
});
133137
}
134138

135139
/*

0 commit comments

Comments
 (0)