diff options
| author | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-05-18 18:43:52 +0300 |
|---|---|---|
| committer | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-05-28 10:43:24 +0300 |
| commit | 7b295eea4296eedf7858a001297eadfaace253d3 (patch) | |
| tree | fb4cbb9bbeac2d6aab802a283d4a9d301638ad2a /src/librustc_trans | |
| parent | 3bcd6fa5712520061fcc2504e1f0aae62c09e514 (diff) | |
| download | rust-7b295eea4296eedf7858a001297eadfaace253d3.tar.gz rust-7b295eea4296eedf7858a001297eadfaace253d3.zip | |
add NullOp::SizeOf and BinOp::Offset
Diffstat (limited to 'src/librustc_trans')
| -rw-r--r-- | src/librustc_trans/collector.rs | 2 | ||||
| -rw-r--r-- | src/librustc_trans/glue.rs | 1 | ||||
| -rw-r--r-- | src/librustc_trans/mir/constant.rs | 7 | ||||
| -rw-r--r-- | src/librustc_trans/mir/operand.rs | 2 | ||||
| -rw-r--r-- | src/librustc_trans/mir/rvalue.rs | 15 |
5 files changed, 23 insertions, 4 deletions
diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index 429e7b01610..dc4e947b0f6 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -502,7 +502,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { _ => bug!(), } } - mir::Rvalue::Box(..) => { + mir::Rvalue::NullaryOp(mir::NullOp::Box, _) => { let tcx = self.scx.tcx(); let exchange_malloc_fn_def_id = tcx .lang_items diff --git a/src/librustc_trans/glue.rs b/src/librustc_trans/glue.rs index 59876a7f2a2..fa400b54d27 100644 --- a/src/librustc_trans/glue.rs +++ b/src/librustc_trans/glue.rs @@ -76,6 +76,7 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf let align = C_uint(bcx.ccx, align); return (size, align); } + assert!(!info.is_null()); match t.sty { ty::TyAdt(def, substs) => { let ccx = bcx.ccx; diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs index cd27ddda1b1..4967ef2f790 100644 --- a/src/librustc_trans/mir/constant.rs +++ b/src/librustc_trans/mir/constant.rs @@ -796,6 +796,12 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> { Const::new(llval, operand.ty) } + mir::Rvalue::NullaryOp(mir::NullOp::SizeOf, ty) => { + assert!(self.ccx.shared().type_is_sized(ty)); + let llval = C_uint(self.ccx, self.ccx.size_of(ty)); + Const::new(llval, tcx.types.usize) + } + _ => span_bug!(span, "{:?} in constant", rvalue) }; @@ -870,6 +876,7 @@ pub fn const_scalar_binop(op: mir::BinOp, llvm::LLVMConstICmp(cmp, lhs, rhs) } } + mir::BinOp::Offset => unreachable!("BinOp::Offset in const-eval!") } } } diff --git a/src/librustc_trans/mir/operand.rs b/src/librustc_trans/mir/operand.rs index 8b7c7d9d372..a12d0fec1cd 100644 --- a/src/librustc_trans/mir/operand.rs +++ b/src/librustc_trans/mir/operand.rs @@ -114,7 +114,7 @@ impl<'a, 'tcx> OperandRef<'tcx> { pub fn deref(self) -> LvalueRef<'tcx> { let projected_ty = self.ty.builtin_deref(true, ty::NoPreference) - .unwrap().ty; + .unwrap_or_else(|| bug!("deref of non-pointer {:?}", self)).ty; let (llptr, llextra) = match self.val { OperandValue::Immediate(llptr) => (llptr, ptr::null_mut()), OperandValue::Pair(llptr, llextra) => (llptr, llextra), diff --git a/src/librustc_trans/mir/rvalue.rs b/src/librustc_trans/mir/rvalue.rs index 667075e6970..b2f44a5d89f 100644 --- a/src/librustc_trans/mir/rvalue.rs +++ b/src/librustc_trans/mir/rvalue.rs @@ -432,7 +432,17 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { }) } - mir::Rvalue::Box(content_ty) => { + mir::Rvalue::NullaryOp(mir::NullOp::SizeOf, ty) => { + assert!(bcx.ccx.shared().type_is_sized(ty)); + let val = C_uint(bcx.ccx, bcx.ccx.size_of(ty)); + let tcx = bcx.tcx(); + (bcx, OperandRef { + val: OperandValue::Immediate(val), + ty: tcx.types.usize, + }) + } + + mir::Rvalue::NullaryOp(mir::NullOp::Box, content_ty) => { let content_ty: Ty<'tcx> = self.monomorphize(&content_ty); let llty = type_of::type_of(bcx.ccx, content_ty); let llsize = machine::llsize_of(bcx.ccx, llty); @@ -515,6 +525,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { mir::BinOp::BitOr => bcx.or(lhs, rhs), mir::BinOp::BitAnd => bcx.and(lhs, rhs), mir::BinOp::BitXor => bcx.xor(lhs, rhs), + mir::BinOp::Offset => bcx.inbounds_gep(lhs, &[rhs]), mir::BinOp::Shl => common::build_unchecked_lshift(bcx, lhs, rhs), mir::BinOp::Shr => common::build_unchecked_rshift(bcx, input_ty, lhs, rhs), mir::BinOp::Ne | mir::BinOp::Lt | mir::BinOp::Gt | @@ -660,7 +671,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { mir::Rvalue::CheckedBinaryOp(..) | mir::Rvalue::UnaryOp(..) | mir::Rvalue::Discriminant(..) | - mir::Rvalue::Box(..) | + mir::Rvalue::NullaryOp(..) | mir::Rvalue::Use(..) => // (*) true, mir::Rvalue::Repeat(..) | |
