Skip to content

Commit 3cc4450

Browse files
Simplify some handling of target_pointer_width
1 parent 2bc7197 commit 3cc4450

File tree

2 files changed

+6
-35
lines changed

2 files changed

+6
-35
lines changed

src/librustc_codegen_llvm/intrinsic.rs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,29 +1778,15 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
17781778
fn int_type_width_signed(ty: Ty, cx: &CodegenCx) -> Option<(u64, bool)> {
17791779
match ty.sty {
17801780
ty::TyInt(t) => Some((match t {
1781-
ast::IntTy::Isize => {
1782-
match &cx.tcx.sess.target.target.target_pointer_width[..] {
1783-
"16" => 16,
1784-
"32" => 32,
1785-
"64" => 64,
1786-
tws => bug!("Unsupported target word size for isize: {}", tws),
1787-
}
1788-
},
1781+
ast::IntTy::Isize => cx.tcx.sess.target.isize_ty.bit_width().unwrap() as u64,
17891782
ast::IntTy::I8 => 8,
17901783
ast::IntTy::I16 => 16,
17911784
ast::IntTy::I32 => 32,
17921785
ast::IntTy::I64 => 64,
17931786
ast::IntTy::I128 => 128,
17941787
}, true)),
17951788
ty::TyUint(t) => Some((match t {
1796-
ast::UintTy::Usize => {
1797-
match &cx.tcx.sess.target.target.target_pointer_width[..] {
1798-
"16" => 16,
1799-
"32" => 32,
1800-
"64" => 64,
1801-
tws => bug!("Unsupported target word size for usize: {}", tws),
1802-
}
1803-
},
1789+
ast::UintTy::Usize => cx.tcx.sess.target.usize_ty.bit_width().unwrap() as u64,
18041790
ast::UintTy::U8 => 8,
18051791
ast::UintTy::U16 => 16,
18061792
ast::UintTy::U32 => 32,
@@ -1813,14 +1799,9 @@ fn int_type_width_signed(ty: Ty, cx: &CodegenCx) -> Option<(u64, bool)> {
18131799

18141800
// Returns the width of a float TypeVariant
18151801
// Returns None if the type is not a float
1816-
fn float_type_width<'tcx>(sty: &ty::TypeVariants<'tcx>)
1817-
-> Option<u64> {
1818-
use rustc::ty::TyFloat;
1802+
fn float_type_width<'tcx>(sty: &ty::TypeVariants<'tcx>) -> Option<u64> {
18191803
match *sty {
1820-
TyFloat(t) => Some(match t {
1821-
ast::FloatTy::F32 => 32,
1822-
ast::FloatTy::F64 => 64,
1823-
}),
1804+
ty::TyFloat(t) => Some(t.bit_width() as u64),
18241805
_ => None,
18251806
}
18261807
}

src/librustc_codegen_llvm/mir/rvalue.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -733,18 +733,8 @@ fn get_overflow_intrinsic(oop: OverflowOp, bx: &Builder<'_, 'll, '_>, ty: Ty) ->
733733
let tcx = bx.tcx();
734734

735735
let new_sty = match ty.sty {
736-
TyInt(Isize) => match &tcx.sess.target.target.target_pointer_width[..] {
737-
"16" => TyInt(I16),
738-
"32" => TyInt(I32),
739-
"64" => TyInt(I64),
740-
_ => panic!("unsupported target word size")
741-
},
742-
TyUint(Usize) => match &tcx.sess.target.target.target_pointer_width[..] {
743-
"16" => TyUint(U16),
744-
"32" => TyUint(U32),
745-
"64" => TyUint(U64),
746-
_ => panic!("unsupported target word size")
747-
},
736+
TyInt(Isize) => TyInt(tcx.sess.target.isize_ty),
737+
TyUint(Usize) => TyUint(tcx.sess.target.usize_ty),
748738
ref t @ TyUint(_) | ref t @ TyInt(_) => t.clone(),
749739
_ => panic!("tried to get overflow intrinsic for op applied to non-int type")
750740
};

0 commit comments

Comments
 (0)