Skip to content

Commit aa3aa3b

Browse files
committed
librustc: Fix type_use to not treat i1* arguments as interchangeable with i8* arguments. Closes #3917. rs=bugfix
1 parent 32ce61f commit aa3aa3b

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

src/librustc/middle/trans/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,8 +1003,8 @@ fn trans_index(bcx: block,
10031003
// Translate index expression and cast to a suitable LLVM integer.
10041004
// Rust is less strict than LLVM in this regard.
10051005
let Result {bcx, val: ix_val} = trans_to_datum(bcx, idx).to_result();
1006-
let ix_size = shape::llsize_of_real(bcx.ccx(), val_ty(ix_val));
1007-
let int_size = shape::llsize_of_real(bcx.ccx(), ccx.int_type);
1006+
let ix_size = machine::llbitsize_of_real(bcx.ccx(), val_ty(ix_val));
1007+
let int_size = machine::llbitsize_of_real(bcx.ccx(), ccx.int_type);
10081008
let ix_val = {
10091009
if ix_size < int_size {
10101010
if ty::type_is_signed(expr_ty(bcx, idx)) {

src/librustc/middle/trans/foreign.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,16 +961,17 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item,
961961
let tp_ty = substs.tys[0];
962962
let lltp_ty = type_of::type_of(ccx, tp_ty);
963963
let llout_ty = type_of::type_of(ccx, substs.tys[1]);
964-
let tp_sz = shape::llsize_of_real(ccx, lltp_ty),
965-
out_sz = shape::llsize_of_real(ccx, llout_ty);
964+
let tp_sz = machine::llbitsize_of_real(ccx, lltp_ty),
965+
out_sz = machine::llbitsize_of_real(ccx, llout_ty);
966966
if tp_sz != out_sz {
967967
let sp = match ccx.tcx.items.get(ref_id.get()) {
968968
ast_map::node_expr(e) => e.span,
969969
_ => fail ~"reinterpret_cast or forget has non-expr arg"
970970
};
971971
ccx.sess.span_fatal(
972972
sp, fmt!("reinterpret_cast called on types \
973-
with different size: %s (%u) to %s (%u)",
973+
with different size: %s (%u bit(s)) to %s \
974+
(%u bit(s))",
974975
ty_to_str(ccx.tcx, tp_ty), tp_sz,
975976
ty_to_str(ccx.tcx, substs.tys[1]), out_sz));
976977
}

src/librustc/middle/trans/machine.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ pub fn llsize_of_alloc(cx: @crate_ctxt, t: TypeRef) -> uint {
8787
// bits in this number of bytes actually carry data related to the datum
8888
// with the type. Not junk, padding, accidentally-damaged words, or
8989
// whatever. Rounds up to the nearest byte though, so if you have a 1-bit
90-
// value, we return 1 here, not 0. Most of rustc works in bytes.
90+
// value, we return 1 here, not 0. Most of rustc works in bytes. Be warned
91+
// that LLVM *does* distinguish between e.g. a 1-bit value and an 8-bit value
92+
// at the codegen level! In general you should prefer `llbitsize_of_real`
93+
// below.
9194
pub fn llsize_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
9295
let nbits = llvm::LLVMSizeOfTypeInBits(cx.td.lltd, t) as uint;
9396
if nbits & 7u != 0u {
@@ -98,6 +101,11 @@ pub fn llsize_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
98101
}
99102
}
100103

104+
/// Returns the "real" size of the type in bits.
105+
pub fn llbitsize_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
106+
llvm::LLVMSizeOfTypeInBits(cx.td.lltd, t) as uint
107+
}
108+
101109
// Returns the "default" size of t, which is calculated by casting null to a
102110
// *T and then doing gep(1) on it and measuring the result. Really, look in
103111
// the LLVM sources. It does that. So this is likely similar to the ABI size

src/librustc/middle/trans/monomorphize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t],
329329
!ty::type_needs_drop(ccx.tcx, subst)
330330
{
331331
let llty = type_of::type_of(ccx, subst);
332-
let size = shape::llsize_of_real(ccx, llty);
332+
let size = machine::llbitsize_of_real(ccx, llty);
333333
let align = shape::llalign_of_pref(ccx, llty);
334334
let mode = datum::appropriate_mode(subst);
335335

@@ -344,7 +344,7 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t],
344344

345345
// Special value for nil to prevent problems
346346
// with undef return pointers.
347-
if size == 1u && ty::type_is_nil(subst) {
347+
if size <= 8u && ty::type_is_nil(subst) {
348348
mono_repr(0u, 0u, is_float, mode)
349349
} else {
350350
mono_repr(size, align, is_float, mode)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use io::ReaderUtil;
2+
fn main() {
3+
let mut x: bool = false;
4+
// this line breaks it
5+
vec::rusti::move_val_init(&mut x, false);
6+
7+
let input = io::stdin();
8+
let line = input.read_line(); // use core's io again
9+
10+
io::println(fmt!("got %?", line));
11+
}

0 commit comments

Comments
 (0)