/// Set the discriminant for a new value of the given case of the given
/// representation.
Set the discriminant for a new value of the given case of the given
representation.
Set the discriminant for a new value of the given case of the given representation .
pub fn codegen_set_discr(&self, bx: &Builder<'a, 'll, 'tcx>, variant_index: usize) {
        if self.layout.for_variant(bx.cx, variant_index).abi == layout::Abi::Uninhabited {
            return;
        }
        match self.layout.variants {
            layout::Variants::Single { index } => {
                assert_eq!(index, variant_index);
            }
            layout::Variants::Tagged { .. } => {
                let ptr = self.project_field(bx, 0);
                let to = self.layout.ty.ty_adt_def().unwrap()
                    .discriminant_for_variant(bx.tcx(), variant_index)
                    .val;
                bx.store(
                    C_uint_big(ptr.layout.llvm_type(bx.cx), to),
                    ptr.llval,
                    ptr.align);
            }
            layout::Variants::NicheFilling {
                dataful_variant,
                ref niche_variants,
                niche_start,
                ..
            } => {
                if variant_index != dataful_variant {
                    if bx.sess().target.target.arch == "arm" ||
                       bx.sess().target.target.arch == "aarch64" {
                        // Issue #34427: As workaround for LLVM bug on ARM,
                        // use memset of 0 before assigning niche value.
                        let llptr = bx.pointercast(self.llval, Type::i8(bx.cx).ptr_to());
                        let fill_byte = C_u8(bx.cx, 0);
                        let (size, align) = self.layout.size_and_align();
                        let size = C_usize(bx.cx, size.bytes());
                        let align = C_u32(bx.cx, align.abi() as u32);
                        base::call_memset(bx, llptr, fill_byte, size, align, false);
                    }
                    let niche = self.project_field(bx, 0);
                    let niche_llty = niche.layout.immediate_llvm_type(bx.cx);
                    let niche_value = ((variant_index - *niche_variants.start()) as u128)
                        .wrapping_add(niche_start);
                    // FIXME(eddyb) Check the actual primitive type here.
                    let niche_llval = if niche_value == 0 {
                        // HACK(eddyb) Using `C_null` as it works on all types.
                        C_null(niche_llty)
                    } else {
                        C_uint_big(niche_llty, niche_value)
                    };
                    OperandValue::Immediate(niche_llval).store(bx, niche);
                }
            }
        }
    }
pub fn codegen_set_discr ( & self , bx : & Builder < ' a , ' ll , ' tcx > , variant_index : usize ) { if self . layout . for_variant ( bx . cx , variant_index ) . abi == layout :: Abi :: Uninhabited { return ; } match self . layout . variants { layout :: Variants :: Single { index } => { assert_eq ! ( index variant_index ) ; } layout :: Variants :: Tagged { .. } => { let ptr = self . project_field ( bx , 0 ) ; let to = self . layout . ty . ty_adt_def ( ) . unwrap ( ) . discriminant_for_variant ( bx . tcx ( ) , variant_index ) . val ; bx . store ( C_uint_big ( ptr . layout . llvm_type ( bx . cx ) , to ) , ptr . llval , ptr . align ) ; } layout :: Variants :: NicheFilling { dataful_variant , ref niche_variants , niche_start , .. } => { if variant_index != dataful_variant { if bx . sess ( ) . target . target . arch == " " || bx . sess ( ) . target . target . arch == " " { // Issue #34427: As workaround for LLVM bug on ARM, // use memset of 0 before assigning niche value. let llptr = bx . pointercast ( self . llval , Type :: i8 ( bx . cx ) . ptr_to ( ) ) ; let fill_byte = C_u8 ( bx . cx , 0 ) ; let ( size , align ) = self . layout . size_and_align ( ) ; let size = C_usize ( bx . cx , size . bytes ( ) ) ; let align = C_u32 ( bx . cx , align . abi ( ) as u32 ) ; base :: call_memset ( bx , llptr , fill_byte , size , align , false ) ; } let niche = self . project_field ( bx , 0 ) ; let niche_llty = niche . layout . immediate_llvm_type ( bx . cx ) ; let niche_value = ( ( variant_index - * niche_variants . start ( ) ) as u128 ) . wrapping_add ( niche_start ) ; // FIXME(eddyb) Check the actual primitive type here. let niche_llval = if niche_value == 0 { // HACK(eddyb) Using `C_null` as it works on all types. C_null ( niche_llty ) } else { C_uint_big ( niche_llty , niche_value ) } ; OperandValue :: Immediate ( niche_llval ) . store ( bx , niche ) ; } } } }
Set the discriminant for a new value of the given case of the given
representation.
Set the discriminant for a new value of the given case of the given representation .
&self
bx
&Builder<'a, 'll, 'tcx>
variant_index
usize