commit
38c943f7ef
@ -785,7 +785,7 @@ pub fn load_ty<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
|
||||
if !global.is_null() && llvm::LLVMIsGlobalConstant(global) == llvm::True {
|
||||
let val = llvm::LLVMGetInitializer(global);
|
||||
if !val.is_null() {
|
||||
return from_arg_ty(cx, val, t);
|
||||
return to_arg_ty(cx, val, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -807,7 +807,7 @@ pub fn load_ty<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
|
||||
llvm::LLVMSetAlignment(val, align);
|
||||
}
|
||||
|
||||
from_arg_ty(cx, val, t)
|
||||
to_arg_ty(cx, val, t)
|
||||
}
|
||||
|
||||
/// Helper for storing values in memory. Does the necessary conversion if the in-memory type
|
||||
@ -817,13 +817,13 @@ pub fn store_ty<'blk, 'tcx>(cx: Block<'blk, 'tcx>, v: ValueRef, dst: ValueRef, t
|
||||
return;
|
||||
}
|
||||
|
||||
let store = Store(cx, to_arg_ty(cx, v, t), to_arg_ty_ptr(cx, dst, t));
|
||||
let store = Store(cx, from_arg_ty(cx, v, t), to_arg_ty_ptr(cx, dst, t));
|
||||
unsafe {
|
||||
llvm::LLVMSetAlignment(store, type_of::align_of(cx.ccx(), t));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_arg_ty(bcx: Block, val: ValueRef, ty: Ty) -> ValueRef {
|
||||
pub fn from_arg_ty(bcx: Block, val: ValueRef, ty: Ty) -> ValueRef {
|
||||
if ty::type_is_bool(ty) {
|
||||
ZExt(bcx, val, Type::i8(bcx.ccx()))
|
||||
} else {
|
||||
@ -831,7 +831,7 @@ pub fn to_arg_ty(bcx: Block, val: ValueRef, ty: Ty) -> ValueRef {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_arg_ty(bcx: Block, val: ValueRef, ty: Ty) -> ValueRef {
|
||||
pub fn to_arg_ty(bcx: Block, val: ValueRef, ty: Ty) -> ValueRef {
|
||||
if ty::type_is_bool(ty) {
|
||||
Trunc(bcx, val, Type::i1(bcx.ccx()))
|
||||
} else {
|
||||
|
@ -223,7 +223,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
|
||||
let val = if datum.kind.is_by_ref() {
|
||||
load_ty(bcx, datum.val, datum.ty)
|
||||
} else {
|
||||
datum.val
|
||||
from_arg_ty(bcx, datum.val, datum.ty)
|
||||
};
|
||||
|
||||
let cast_val = BitCast(bcx, val, llret_ty);
|
||||
@ -490,12 +490,12 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
|
||||
unsafe {
|
||||
llvm::LLVMSetAlignment(load, type_of::align_of(ccx, tp_ty));
|
||||
}
|
||||
from_arg_ty(bcx, load, tp_ty)
|
||||
to_arg_ty(bcx, load, tp_ty)
|
||||
},
|
||||
(_, "volatile_store") => {
|
||||
let tp_ty = *substs.types.get(FnSpace, 0);
|
||||
let ptr = to_arg_ty_ptr(bcx, llargs[0], tp_ty);
|
||||
let val = to_arg_ty(bcx, llargs[1], tp_ty);
|
||||
let val = from_arg_ty(bcx, llargs[1], tp_ty);
|
||||
let store = VolatileStore(bcx, val, ptr);
|
||||
unsafe {
|
||||
llvm::LLVMSetAlignment(store, type_of::align_of(ccx, tp_ty));
|
||||
@ -777,8 +777,8 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
|
||||
|
||||
let tp_ty = *substs.types.get(FnSpace, 0);
|
||||
let ptr = to_arg_ty_ptr(bcx, llargs[0], tp_ty);
|
||||
let cmp = to_arg_ty(bcx, llargs[1], tp_ty);
|
||||
let src = to_arg_ty(bcx, llargs[2], tp_ty);
|
||||
let cmp = from_arg_ty(bcx, llargs[1], tp_ty);
|
||||
let src = from_arg_ty(bcx, llargs[2], tp_ty);
|
||||
let res = AtomicCmpXchg(bcx, ptr, cmp, src, order,
|
||||
strongest_failure_ordering);
|
||||
ExtractValue(bcx, res, 0)
|
||||
@ -787,12 +787,12 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
|
||||
"load" => {
|
||||
let tp_ty = *substs.types.get(FnSpace, 0);
|
||||
let ptr = to_arg_ty_ptr(bcx, llargs[0], tp_ty);
|
||||
from_arg_ty(bcx, AtomicLoad(bcx, ptr, order), tp_ty)
|
||||
to_arg_ty(bcx, AtomicLoad(bcx, ptr, order), tp_ty)
|
||||
}
|
||||
"store" => {
|
||||
let tp_ty = *substs.types.get(FnSpace, 0);
|
||||
let ptr = to_arg_ty_ptr(bcx, llargs[0], tp_ty);
|
||||
let val = to_arg_ty(bcx, llargs[1], tp_ty);
|
||||
let val = from_arg_ty(bcx, llargs[1], tp_ty);
|
||||
AtomicStore(bcx, val, ptr, order);
|
||||
C_nil(ccx)
|
||||
}
|
||||
@ -826,7 +826,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
|
||||
|
||||
let tp_ty = *substs.types.get(FnSpace, 0);
|
||||
let ptr = to_arg_ty_ptr(bcx, llargs[0], tp_ty);
|
||||
let val = to_arg_ty(bcx, llargs[1], tp_ty);
|
||||
let val = from_arg_ty(bcx, llargs[1], tp_ty);
|
||||
AtomicRMW(bcx, atom_op, ptr, val, order)
|
||||
}
|
||||
}
|
||||
|
20
src/test/run-pass/issue-25746-bool-transmute.rs
Normal file
20
src/test/run-pass/issue-25746-bool-transmute.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::mem::transmute;
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
let _: i8 = transmute(false);
|
||||
let _: i8 = transmute(true);
|
||||
let _: bool = transmute(0u8);
|
||||
let _: bool = transmute(1u8);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user