Skip to content

Commit 5298203

Browse files
committed
---
yaml --- r: 43007 b: refs/heads/try c: cf6c3d9 h: refs/heads/master i: 43005: 51a549b 43003: 25c3f10 42999: a16062b 42991: 1003ff5 42975: 2e7b416 42943: cede17b 42879: 7970bfd 42751: cd44180 42495: 3be99a2 41983: 3f927ed 40959: a2875c3 v: v3
1 parent 9891fab commit 5298203

File tree

13 files changed

+122
-54
lines changed

13 files changed

+122
-54
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 19dfec2aaf746535de1521f68421f9980dbf25de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
5-
refs/heads/try: b081f594954385813fc3b3b0d26cfcc191f1ceeb
5+
refs/heads/try: cf6c3d96fb1a7230cbdd8ebc77af30ba35b9e35a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/src/librustc/lib/llvm.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,19 @@ pub extern mod llvm {
445445
Count: c_uint,
446446
Packed: Bool) -> ValueRef;
447447

448-
pub unsafe fn LLVMConstString(Str: *c_char, Length: c_uint,
449-
DontNullTerminate: Bool) -> ValueRef;
450-
pub unsafe fn LLVMConstArray(ElementTy: TypeRef, ConstantVals: *ValueRef,
451-
Length: c_uint) -> ValueRef;
448+
pub unsafe fn LLVMConstString(Str: *c_char,
449+
Length: c_uint,
450+
DontNullTerminate: Bool)
451+
-> ValueRef;
452+
pub unsafe fn LLVMConstArray(ElementTy: TypeRef,
453+
ConstantVals: *ValueRef,
454+
Length: c_uint)
455+
-> ValueRef;
452456
pub unsafe fn LLVMConstStruct(ConstantVals: *ValueRef,
453-
Count: c_uint, Packed: Bool) -> ValueRef;
457+
Count: c_uint,
458+
Packed: Bool) -> ValueRef;
454459
pub unsafe fn LLVMConstVector(ScalarConstantVals: *ValueRef,
455-
Size: c_uint) -> ValueRef;
460+
Size: c_uint) -> ValueRef;
456461

457462
/* Constant expressions */
458463
pub unsafe fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
@@ -463,8 +468,8 @@ pub extern mod llvm {
463468
pub unsafe fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
464469
pub unsafe fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
465470
pub unsafe fn LLVMConstAdd(LHSConstant: ValueRef,
466-
RHSConstant: ValueRef)
467-
-> ValueRef;
471+
RHSConstant: ValueRef)
472+
-> ValueRef;
468473
pub unsafe fn LLVMConstNSWAdd(LHSConstant: ValueRef,
469474
RHSConstant: ValueRef)
470475
-> ValueRef;
@@ -475,14 +480,14 @@ pub extern mod llvm {
475480
RHSConstant: ValueRef)
476481
-> ValueRef;
477482
pub unsafe fn LLVMConstSub(LHSConstant: ValueRef,
478-
RHSConstant: ValueRef)
479-
-> ValueRef;
483+
RHSConstant: ValueRef)
484+
-> ValueRef;
480485
pub unsafe fn LLVMConstNSWSub(LHSConstant: ValueRef,
481-
RHSConstant: ValueRef)
482-
-> ValueRef;
486+
RHSConstant: ValueRef)
487+
-> ValueRef;
483488
pub unsafe fn LLVMConstNUWSub(LHSConstant: ValueRef,
484-
RHSConstant: ValueRef)
485-
-> ValueRef;
489+
RHSConstant: ValueRef)
490+
-> ValueRef;
486491
pub unsafe fn LLVMConstFSub(LHSConstant: ValueRef,
487492
RHSConstant: ValueRef)
488493
-> ValueRef;

branches/try/src/librustc/middle/trans/_match.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,8 @@ pub fn pick_col(m: &[@Match]) -> uint {
10281028
pub enum branch_kind { no_branch, single, switch, compare, compare_vec_len, }
10291029
10301030
// Compiles a comparison between two things.
1031+
//
1032+
// NB: This must produce an i1, not a Rust bool (i8).
10311033
pub fn compare_values(cx: block,
10321034
lhs: ValueRef,
10331035
rhs: ValueRef,
@@ -1053,7 +1055,11 @@ pub fn compare_values(cx: block,
10531055
scratch_rhs],
10541056
expr::SaveIn(
10551057
scratch_result.val));
1056-
return scratch_result.to_result(bcx);
1058+
let result = scratch_result.to_result(bcx);
1059+
Result {
1060+
bcx: result.bcx,
1061+
val: bool_to_i1(result.bcx, result.val)
1062+
}
10571063
}
10581064
ty::ty_estr(_) => {
10591065
let scratch_result = scratch_datum(cx, ty::mk_bool(cx.tcx()),
@@ -1063,7 +1069,11 @@ pub fn compare_values(cx: block,
10631069
~[lhs, rhs],
10641070
expr::SaveIn(
10651071
scratch_result.val));
1066-
return scratch_result.to_result(bcx);
1072+
let result = scratch_result.to_result(bcx);
1073+
Result {
1074+
bcx: result.bcx,
1075+
val: bool_to_i1(result.bcx, result.val)
1076+
}
10671077
}
10681078
_ => {
10691079
cx.tcx().sess.bug(~"only scalars and strings supported in \
@@ -1176,6 +1186,7 @@ pub fn compile_guard(bcx: block,
11761186
expr::trans_to_datum(bcx, guard_expr).to_result()
11771187
}
11781188
});
1189+
let val = bool_to_i1(bcx, val);
11791190
11801191
// Revoke the temp cleanups now that the guard successfully executed.
11811192
for temp_cleanups.each |llval| {

branches/try/src/librustc/middle/trans/base.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,13 @@ pub fn maybe_name_value(cx: @crate_ctxt, v: ValueRef, s: ~str) {
494494
// Used only for creating scalar comparison glue.
495495
pub enum scalar_type { nil_type, signed_int, unsigned_int, floating_point, }
496496

497-
pub fn compare_scalar_types(cx: block, lhs: ValueRef, rhs: ValueRef,
498-
t: ty::t, op: ast::binop) -> Result {
497+
// NB: This produces an i1, not a Rust bool (i8).
498+
pub fn compare_scalar_types(cx: block,
499+
lhs: ValueRef,
500+
rhs: ValueRef,
501+
t: ty::t,
502+
op: ast::binop)
503+
-> Result {
499504
let f = |a| compare_scalar_values(cx, lhs, rhs, a, op);
500505

501506
match ty::get(t).sty {
@@ -521,8 +526,12 @@ pub fn compare_scalar_types(cx: block, lhs: ValueRef, rhs: ValueRef,
521526

522527

523528
// A helper function to do the actual comparison of scalar values.
524-
pub fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
525-
nt: scalar_type, op: ast::binop) -> ValueRef {
529+
pub fn compare_scalar_values(cx: block,
530+
lhs: ValueRef,
531+
rhs: ValueRef,
532+
nt: scalar_type,
533+
op: ast::binop)
534+
-> ValueRef {
526535
let _icx = cx.insn_ctxt("compare_scalar_values");
527536
fn die(cx: block) -> ! {
528537
cx.tcx().sess.bug(~"compare_scalar_values: must be a\
@@ -533,8 +542,8 @@ pub fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
533542
// We don't need to do actual comparisons for nil.
534543
// () == () holds but () < () does not.
535544
match op {
536-
ast::eq | ast::le | ast::ge => return C_bool(true),
537-
ast::ne | ast::lt | ast::gt => return C_bool(false),
545+
ast::eq | ast::le | ast::ge => return C_i1(true),
546+
ast::ne | ast::lt | ast::gt => return C_i1(false),
538547
// refinements would be nice
539548
_ => die(cx)
540549
}
@@ -1442,7 +1451,7 @@ pub fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef,
14421451
let dst_ptr = PointerCast(cx, dst, T_ptr(T_i8()));
14431452
let size = IntCast(cx, n_bytes, ccx.int_type);
14441453
let align = C_i32(1i32);
1445-
let volatile = C_bool(false);
1454+
let volatile = C_i1(false);
14461455
Call(cx, memcpy, ~[dst_ptr, src_ptr, size, align, volatile]);
14471456
}
14481457

@@ -1489,7 +1498,7 @@ pub fn memzero(cx: block, llptr: ValueRef, llty: TypeRef) {
14891498
let llzeroval = C_u8(0);
14901499
let size = IntCast(cx, machine::llsize_of(ccx, llty), ccx.int_type);
14911500
let align = C_i32(1i32);
1492-
let volatile = C_bool(false);
1501+
let volatile = C_i1(false);
14931502
Call(cx, llintrinsicfn, ~[llptr, llzeroval, size, align, volatile]);
14941503
}
14951504

branches/try/src/librustc/middle/trans/callee.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,9 @@ pub fn trans_call_inner(
438438
let flag = alloca(bcx, T_bool());
439439
Store(bcx, C_bool(false), flag);
440440
Some(flag)
441-
} else { None };
441+
} else {
442+
None
443+
};
442444

443445
let (llfn, llenv) = unsafe {
444446
match callee.data {
@@ -506,7 +508,8 @@ pub fn trans_call_inner(
506508
if ty::type_is_bot(ret_ty) {
507509
Unreachable(bcx);
508510
} else if ret_in_loop {
509-
bcx = do with_cond(bcx, Load(bcx, ret_flag.get())) |bcx| {
511+
let ret_flag_result = bool_to_i1(bcx, Load(bcx, ret_flag.get()));
512+
bcx = do with_cond(bcx, ret_flag_result) |bcx| {
510513
do option::iter(&copy bcx.fcx.loop_ret) |lret| {
511514
Store(bcx, C_bool(true), lret.flagptr);
512515
Store(bcx, C_bool(false), bcx.fcx.llretptr);

branches/try/src/librustc/middle/trans/common.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ pub fn T_f32() -> TypeRef { unsafe { return llvm::LLVMFloatType(); } }
759759

760760
pub fn T_f64() -> TypeRef { unsafe { return llvm::LLVMDoubleType(); } }
761761

762-
pub fn T_bool() -> TypeRef { return T_i1(); }
762+
pub fn T_bool() -> TypeRef { return T_i8(); }
763763

764764
pub fn T_int(targ_cfg: @session::config) -> TypeRef {
765765
return match targ_cfg.arch {
@@ -1109,6 +1109,10 @@ pub fn C_bool(b: bool) -> ValueRef {
11091109
C_integral(T_bool(), if b { 1u64 } else { 0u64 }, False)
11101110
}
11111111

1112+
pub fn C_i1(b: bool) -> ValueRef {
1113+
return C_integral(T_i1(), if b { 1 } else { 0 }, False);
1114+
}
1115+
11121116
pub fn C_i32(i: i32) -> ValueRef {
11131117
return C_integral(T_i32(), i as u64, True);
11141118
}
@@ -1435,6 +1439,11 @@ pub fn struct_dtor() -> [uint * 2] {
14351439
[0, 1]
14361440
}
14371441

1442+
// Casts a Rust bool value to an i1.
1443+
pub fn bool_to_i1(bcx: block, llval: ValueRef) -> ValueRef {
1444+
build::ICmp(bcx, lib::llvm::IntNE, llval, C_bool(false))
1445+
}
1446+
14381447
//
14391448
// Local Variables:
14401449
// mode: rust

branches/try/src/librustc/middle/trans/consts.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,18 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
204204
ast::box(_) |
205205
ast::uniq(_) |
206206
ast::deref => const_deref(cx, te),
207-
ast::not => llvm::LLVMConstNot(te),
207+
ast::not => {
208+
match ty::get(ty).sty {
209+
ty::ty_bool => {
210+
// Somewhat questionable, but I believe this is
211+
// correct.
212+
let te = llvm::LLVMConstTrunc(te, T_i1());
213+
let te = llvm::LLVMConstNot(te);
214+
llvm::LLVMConstZExt(te, T_bool())
215+
}
216+
_ => llvm::LLVMConstNot(te),
217+
}
218+
}
208219
ast::neg => {
209220
if is_float { llvm::LLVMConstFNeg(te) }
210221
else { llvm::LLVMConstNeg(te) }

branches/try/src/librustc/middle/trans/controlflow.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ pub fn trans_if(bcx: block,
6262

6363
let then_bcx_in = scope_block(bcx, thn.info(), ~"then");
6464
let else_bcx_in = scope_block(bcx, els.info(), ~"else");
65+
66+
let cond_val = bool_to_i1(bcx, cond_val);
6567
CondBr(bcx, cond_val, then_bcx_in.llbb, else_bcx_in.llbb);
6668

6769
debug!("then_bcx_in=%s, else_bcx_in=%s",
@@ -139,6 +141,7 @@ pub fn trans_while(bcx: block, cond: @ast::expr, body: ast::blk) -> block {
139141
// compile the condition
140142
let Result {bcx: cond_bcx_out, val: cond_val} =
141143
expr::trans_to_datum(cond_bcx_in, cond).to_result();
144+
let cond_val = bool_to_i1(cond_bcx_out, cond_val);
142145
let cond_bcx_out =
143146
trans_block_cleanups(cond_bcx_out, block_cleanups(cond_bcx_in));
144147
CondBr(cond_bcx_out, cond_val, body_bcx_in.llbb, next_bcx.llbb);
@@ -324,6 +327,7 @@ pub fn trans_check_expr(bcx: block,
324327
expr::trans_to_datum(bcx, pred_expr).to_result()
325328
}
326329
};
330+
let val = bool_to_i1(bcx, val);
327331
do with_cond(bcx, Not(bcx, val)) |bcx| {
328332
trans_fail(bcx, Some(pred_expr.span), /*bad*/copy expr_str)
329333
}

branches/try/src/librustc/middle/trans/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn lli64(val: int) -> ValueRef {
7777
C_i64(val as i64)
7878
}
7979
fn lli1(bval: bool) -> ValueRef {
80-
C_bool(bval)
80+
C_i1(bval)
8181
}
8282
fn llmdnode(elems: ~[ValueRef]) -> ValueRef {
8383
unsafe {

branches/try/src/librustc/middle/trans/expr.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,6 @@ fn trans_unary_datum(bcx: block,
12361236
un_expr: @ast::expr,
12371237
op: ast::unop,
12381238
sub_expr: @ast::expr) -> DatumBlock {
1239-
12401239
let _icx = bcx.insn_ctxt("trans_unary_datum");
12411240

12421241
// if deref, would be LvalueExpr
@@ -1251,7 +1250,21 @@ fn trans_unary_datum(bcx: block,
12511250
return match op {
12521251
ast::not => {
12531252
let Result {bcx, val} = trans_to_datum(bcx, sub_expr).to_result();
1254-
immediate_rvalue_bcx(bcx, Not(bcx, val), un_ty)
1253+
1254+
// If this is a boolean type, we must not use the LLVM Not
1255+
// instruction, as that is a *bitwise* not and we want *logical*
1256+
// not on our 8-bit boolean values.
1257+
let llresult = match ty::get(un_ty).sty {
1258+
ty::ty_bool => {
1259+
let llcond = ICmp(bcx,
1260+
lib::llvm::IntEQ,
1261+
val,
1262+
C_bool(false));
1263+
Select(bcx, llcond, C_bool(true), C_bool(false))
1264+
}
1265+
_ => Not(bcx, val)
1266+
};
1267+
immediate_rvalue_bcx(bcx, llresult, un_ty)
12551268
}
12561269
ast::neg => {
12571270
let Result {bcx, val} = trans_to_datum(bcx, sub_expr).to_result();
@@ -1308,8 +1321,8 @@ fn trans_eager_binop(bcx: block,
13081321
binop_ty: ty::t,
13091322
op: ast::binop,
13101323
lhs_datum: &Datum,
1311-
rhs_datum: &Datum) -> DatumBlock
1312-
{
1324+
rhs_datum: &Datum)
1325+
-> DatumBlock {
13131326
let mut bcx = bcx;
13141327
let _icx = bcx.insn_ctxt("trans_eager_binop");
13151328

@@ -1388,7 +1401,7 @@ fn trans_eager_binop(bcx: block,
13881401
}
13891402
let cmpr = base::compare_scalar_types(bcx, lhs, rhs, rhs_t, op);
13901403
bcx = cmpr.bcx;
1391-
cmpr.val
1404+
ZExt(bcx, cmpr.val, T_i8())
13921405
}
13931406
}
13941407
_ => {
@@ -1406,8 +1419,7 @@ fn trans_lazy_binop(bcx: block,
14061419
binop_expr: @ast::expr,
14071420
op: lazy_binop_ty,
14081421
a: @ast::expr,
1409-
b: @ast::expr) -> DatumBlock
1410-
{
1422+
b: @ast::expr) -> DatumBlock {
14111423
let _icx = bcx.insn_ctxt("trans_lazy_binop");
14121424
let binop_ty = expr_ty(bcx, binop_expr);
14131425
let mut bcx = bcx;
@@ -1425,10 +1437,12 @@ fn trans_lazy_binop(bcx: block,
14251437
let join = base::sub_block(bcx, ~"join");
14261438
let before_rhs = base::sub_block(bcx, ~"rhs");
14271439

1440+
let lhs_i1 = bool_to_i1(past_lhs, lhs);
14281441
match op {
1429-
lazy_and => CondBr(past_lhs, lhs, before_rhs.llbb, join.llbb),
1430-
lazy_or => CondBr(past_lhs, lhs, join.llbb, before_rhs.llbb)
1442+
lazy_and => CondBr(past_lhs, lhs_i1, before_rhs.llbb, join.llbb),
1443+
lazy_or => CondBr(past_lhs, lhs_i1, join.llbb, before_rhs.llbb)
14311444
}
1445+
14321446
let Result {bcx: past_rhs, val: rhs} = {
14331447
do base::with_scope_result(before_rhs, b.info(), ~"rhs") |bcx| {
14341448
trans_to_datum(bcx, b).to_result()

0 commit comments

Comments
 (0)