librustc: Fix type_use to not treat i1* arguments as interchangeable with i8* arguments. Closes #3917. rs=bugfix
This commit is contained in:
parent
32ce61f947
commit
aa3aa3b1b2
@ -1003,8 +1003,8 @@ fn trans_index(bcx: block,
|
||||
// Translate index expression and cast to a suitable LLVM integer.
|
||||
// Rust is less strict than LLVM in this regard.
|
||||
let Result {bcx, val: ix_val} = trans_to_datum(bcx, idx).to_result();
|
||||
let ix_size = shape::llsize_of_real(bcx.ccx(), val_ty(ix_val));
|
||||
let int_size = shape::llsize_of_real(bcx.ccx(), ccx.int_type);
|
||||
let ix_size = machine::llbitsize_of_real(bcx.ccx(), val_ty(ix_val));
|
||||
let int_size = machine::llbitsize_of_real(bcx.ccx(), ccx.int_type);
|
||||
let ix_val = {
|
||||
if ix_size < int_size {
|
||||
if ty::type_is_signed(expr_ty(bcx, idx)) {
|
||||
|
@ -961,8 +961,8 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item,
|
||||
let tp_ty = substs.tys[0];
|
||||
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
||||
let llout_ty = type_of::type_of(ccx, substs.tys[1]);
|
||||
let tp_sz = shape::llsize_of_real(ccx, lltp_ty),
|
||||
out_sz = shape::llsize_of_real(ccx, llout_ty);
|
||||
let tp_sz = machine::llbitsize_of_real(ccx, lltp_ty),
|
||||
out_sz = machine::llbitsize_of_real(ccx, llout_ty);
|
||||
if tp_sz != out_sz {
|
||||
let sp = match ccx.tcx.items.get(ref_id.get()) {
|
||||
ast_map::node_expr(e) => e.span,
|
||||
@ -970,7 +970,8 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item,
|
||||
};
|
||||
ccx.sess.span_fatal(
|
||||
sp, fmt!("reinterpret_cast called on types \
|
||||
with different size: %s (%u) to %s (%u)",
|
||||
with different size: %s (%u bit(s)) to %s \
|
||||
(%u bit(s))",
|
||||
ty_to_str(ccx.tcx, tp_ty), tp_sz,
|
||||
ty_to_str(ccx.tcx, substs.tys[1]), out_sz));
|
||||
}
|
||||
|
@ -87,7 +87,10 @@ pub fn llsize_of_alloc(cx: @crate_ctxt, t: TypeRef) -> uint {
|
||||
// bits in this number of bytes actually carry data related to the datum
|
||||
// with the type. Not junk, padding, accidentally-damaged words, or
|
||||
// whatever. Rounds up to the nearest byte though, so if you have a 1-bit
|
||||
// value, we return 1 here, not 0. Most of rustc works in bytes.
|
||||
// value, we return 1 here, not 0. Most of rustc works in bytes. Be warned
|
||||
// that LLVM *does* distinguish between e.g. a 1-bit value and an 8-bit value
|
||||
// at the codegen level! In general you should prefer `llbitsize_of_real`
|
||||
// below.
|
||||
pub fn llsize_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
|
||||
let nbits = llvm::LLVMSizeOfTypeInBits(cx.td.lltd, t) as uint;
|
||||
if nbits & 7u != 0u {
|
||||
@ -98,6 +101,11 @@ pub fn llsize_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the "real" size of the type in bits.
|
||||
pub fn llbitsize_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
|
||||
llvm::LLVMSizeOfTypeInBits(cx.td.lltd, t) as uint
|
||||
}
|
||||
|
||||
// Returns the "default" size of t, which is calculated by casting null to a
|
||||
// *T and then doing gep(1) on it and measuring the result. Really, look in
|
||||
// the LLVM sources. It does that. So this is likely similar to the ABI size
|
||||
|
@ -329,7 +329,7 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t],
|
||||
!ty::type_needs_drop(ccx.tcx, subst)
|
||||
{
|
||||
let llty = type_of::type_of(ccx, subst);
|
||||
let size = shape::llsize_of_real(ccx, llty);
|
||||
let size = machine::llbitsize_of_real(ccx, llty);
|
||||
let align = shape::llalign_of_pref(ccx, llty);
|
||||
let mode = datum::appropriate_mode(subst);
|
||||
|
||||
@ -344,7 +344,7 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t],
|
||||
|
||||
// Special value for nil to prevent problems
|
||||
// with undef return pointers.
|
||||
if size == 1u && ty::type_is_nil(subst) {
|
||||
if size <= 8u && ty::type_is_nil(subst) {
|
||||
mono_repr(0u, 0u, is_float, mode)
|
||||
} else {
|
||||
mono_repr(size, align, is_float, mode)
|
||||
|
11
src/test/run-pass/type-use-i1-versus-i8.rs
Normal file
11
src/test/run-pass/type-use-i1-versus-i8.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use io::ReaderUtil;
|
||||
fn main() {
|
||||
let mut x: bool = false;
|
||||
// this line breaks it
|
||||
vec::rusti::move_val_init(&mut x, false);
|
||||
|
||||
let input = io::stdin();
|
||||
let line = input.read_line(); // use core's io again
|
||||
|
||||
io::println(fmt!("got %?", line));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user