fn load_discr(bcx: Block, ity: IntType, ptr: ValueRef, min: Disr, max: Disr,
              range_assert: bool)
    -> ValueRef {
    let llty = ll_inttype(bcx.ccx(), ity);
    assert_eq!(val_ty(ptr), llty.ptr_to());
    let bits = machine::llbitsize_of_real(bcx.ccx(), llty);
    assert!(bits <= 64);
    let bits = bits as usize;
    let mask = Disr(!0u64 >> (64 - bits));
    // For a (max) discr of -1, max will be `-1 as usize`, which overflows.
    // However, that is fine here (it would still represent the full range),
    if max.wrapping_add(Disr(1)) & mask == min & mask || !range_assert {
        // i.e., if the range is everything.  The lo==hi case would be
        // rejected by the LLVM verifier (it would mean either an
        // empty set, which is impossible, or the entire range of the
        // type, which is pointless).
        Load(bcx, ptr)
    } else {
        // llvm::ConstantRange can deal with ranges that wrap around,
        // so an overflow on (max + 1) is fine.
        LoadRangeAssert(bcx, ptr, min.0, max.0.wrapping_add(1), /* signed: */ True)
    }
}
/// Helper for cases where the discriminant is simply loaded.
Helper for cases where the discriminant is simply loaded.
Helper for cases where the discriminant is simply loaded .
fn load_discr(bcx: Block, ity: IntType, ptr: ValueRef, min: Disr, max: Disr,
              range_assert: bool)
    -> ValueRef {
    let llty = ll_inttype(bcx.ccx(), ity);
    assert_eq!(val_ty(ptr), llty.ptr_to());
    let bits = machine::llbitsize_of_real(bcx.ccx(), llty);
    assert!(bits <= 64);
    let bits = bits as usize;
    let mask = Disr(!0u64 >> (64 - bits));
    // For a (max) discr of -1, max will be `-1 as usize`, which overflows.
    // However, that is fine here (it would still represent the full range),
    if max.wrapping_add(Disr(1)) & mask == min & mask || !range_assert {
        // i.e., if the range is everything.  The lo==hi case would be
        // rejected by the LLVM verifier (it would mean either an
        // empty set, which is impossible, or the entire range of the
        // type, which is pointless).
        Load(bcx, ptr)
    } else {
        // llvm::ConstantRange can deal with ranges that wrap around,
        // so an overflow on (max + 1) is fine.
        LoadRangeAssert(bcx, ptr, min.0, max.0.wrapping_add(1), /* signed: */ True)
    }
}
fn load_discr ( bcx : Block , ity : IntType , ptr : ValueRef , min : Disr , max : Disr , range_assert : bool ) -> ValueRef { let llty = ll_inttype ( bcx . ccx ( ) , ity ) ; assert_eq ! ( val_ty ( ptr ) llty ptr_to ( ) ) ; let bits = machine :: llbitsize_of_real ( bcx . ccx ( ) , llty ) ; assert ! ( bits 64 ) ; let bits = bits as usize ; let mask = Disr ( ! 0u64 >> ( 64 - bits ) ) ; // For a (max) discr of -1, max will be `-1 as usize`, which overflows. // However, that is fine here (it would still represent the full range), if max . wrapping_add ( Disr ( 1 ) ) & mask == min & mask || ! range_assert { // i.e., if the range is everything.  The lo==hi case would be // rejected by the LLVM verifier (it would mean either an // empty set, which is impossible, or the entire range of the // type, which is pointless). Load ( bcx , ptr ) } else { // llvm::ConstantRange can deal with ranges that wrap around, // so an overflow on (max + 1) is fine. LoadRangeAssert ( bcx , ptr , min . 0 , max . 0 . wrapping_add ( 1 ) , /* signed: */ True ) } }
Helper for cases where the discriminant is simply loaded.
Helper for cases where the discriminant is simply loaded .
bcx
Block
ity
IntType
ptr
ValueRef
min
Disr
max
Disr
range_assert
bool
bcx
Block
ity
IntType
ptr
ValueRef
min
Disr
max
Disr
range_assert
bool