Implement casting between TyRef and TyRawPtr

This commit is contained in:
bjorn3 2018-07-18 14:21:13 +02:00
parent 9e45cc490f
commit fdc625e18a
2 changed files with 18 additions and 2 deletions

View File

@ -85,3 +85,7 @@ fn return_str() -> &'static str {
fn promoted_val() -> &'static u8 {
&(1 * 2)
}
fn cast_ref_to_raw_ptr(abc: &u8) -> *const u8 {
abc as *const u8
}

View File

@ -371,7 +371,19 @@ fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, stmt: &Statement<'tcx
let layout = fx.layout_of(ty);
lval.write_cvalue(fx, operand.unchecked_cast_to(layout));
}
Rvalue::Cast(CastKind::Misc, operand, ty) => unimplemented!("rval misc {:?} {:?}", operand, ty),
Rvalue::Cast(CastKind::Misc, operand, ty) => {
let operand = trans_operand(fx, operand);
match (&operand.layout().ty.sty, &ty.sty) {
(TypeVariants::TyRef(..), TypeVariants::TyRef(..)) |
(TypeVariants::TyRef(..), TypeVariants::TyRawPtr(..)) |
(TypeVariants::TyRawPtr(..), TypeVariants::TyRef(..)) |
(TypeVariants::TyRawPtr(..), TypeVariants::TyRawPtr(..)) => {
let layout = fx.layout_of(ty);
lval.write_cvalue(fx, operand.unchecked_cast_to(layout));
}
_ => unimplemented!("rval misc {:?} {:?}", operand, ty),
}
},
Rvalue::Cast(CastKind::ClosureFnPointer, operand, ty) => unimplemented!("rval closure_fn_ptr {:?} {:?}", operand, ty),
Rvalue::Cast(CastKind::Unsize, operand, ty) => unimplemented!("rval unsize {:?} {:?}", operand, ty),
Rvalue::Discriminant(place) => {
@ -436,7 +448,7 @@ fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, stmt: &Statement<'tcx
}
}
Rvalue::Repeat(operand, times) => unimplemented!("rval repeat {:?} {:?}", operand, times),
Rvalue::Len(lval) => unimplemented!("rval len {:?}", lval),
Rvalue::Len(lval) => return Err(format!("rval len {:?}", lval)),
Rvalue::NullaryOp(NullOp::Box, ty) => unimplemented!("rval box {:?}", ty),
Rvalue::NullaryOp(NullOp::SizeOf, ty) => unimplemented!("rval size_of {:?}", ty),
Rvalue::Aggregate(_, _) => bug!("shouldn't exist at trans {:?}", rval),