]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #107756 - RalfJung:miri-out-of-addresses, r=oli-obk
authorMatthias Krüger <matthias.krueger@famsik.de>
Tue, 7 Feb 2023 16:57:18 +0000 (17:57 +0100)
committerGitHub <noreply@github.com>
Tue, 7 Feb 2023 16:57:18 +0000 (17:57 +0100)
miri: fix ICE when running out of address space

Fixes https://github.com/rust-lang/miri/issues/2769
r? `@oli-obk`

I didn't add a test since that requires https://github.com/oli-obk/ui_test/issues/38 (host must be 64bit and target 32bit). Also the test takes ~30s, so I am not sure if we want to have it in the test suite?

1  2 
compiler/rustc_const_eval/src/interpret/place.rs

index f82a41078d153a4485c9585ef1b85257568e3c63,86786d812667f915927a04d142058b9e10393ce9..038282e2161e6637891d2cde59fe2e766e40b189
@@@ -764,11 -764,90 +764,11 @@@ wher
              ty::TypeAndMut { ty: self.tcx.types.str_, mutbl },
          );
          let layout = self.layout_of(ty).unwrap();
-         MPlaceTy { mplace, layout, align: layout.align.abi }
+         Ok(MPlaceTy { mplace, layout, align: layout.align.abi })
      }
  
 -    /// Writes the discriminant of the given variant.
 -    #[instrument(skip(self), level = "debug")]
 -    pub fn write_discriminant(
 -        &mut self,
 -        variant_index: VariantIdx,
 -        dest: &PlaceTy<'tcx, M::Provenance>,
 -    ) -> InterpResult<'tcx> {
 -        // Layout computation excludes uninhabited variants from consideration
 -        // therefore there's no way to represent those variants in the given layout.
 -        // Essentially, uninhabited variants do not have a tag that corresponds to their
 -        // discriminant, so we cannot do anything here.
 -        // When evaluating we will always error before even getting here, but ConstProp 'executes'
 -        // dead code, so we cannot ICE here.
 -        if dest.layout.for_variant(self, variant_index).abi.is_uninhabited() {
 -            throw_ub!(UninhabitedEnumVariantWritten)
 -        }
 -
 -        match dest.layout.variants {
 -            abi::Variants::Single { index } => {
 -                assert_eq!(index, variant_index);
 -            }
 -            abi::Variants::Multiple {
 -                tag_encoding: TagEncoding::Direct,
 -                tag: tag_layout,
 -                tag_field,
 -                ..
 -            } => {
 -                // No need to validate that the discriminant here because the
 -                // `TyAndLayout::for_variant()` call earlier already checks the variant is valid.
 -
 -                let discr_val =
 -                    dest.layout.ty.discriminant_for_variant(*self.tcx, variant_index).unwrap().val;
 -
 -                // raw discriminants for enums are isize or bigger during
 -                // their computation, but the in-memory tag is the smallest possible
 -                // representation
 -                let size = tag_layout.size(self);
 -                let tag_val = size.truncate(discr_val);
 -
 -                let tag_dest = self.place_field(dest, tag_field)?;
 -                self.write_scalar(Scalar::from_uint(tag_val, size), &tag_dest)?;
 -            }
 -            abi::Variants::Multiple {
 -                tag_encoding:
 -                    TagEncoding::Niche { untagged_variant, ref niche_variants, niche_start },
 -                tag: tag_layout,
 -                tag_field,
 -                ..
 -            } => {
 -                // No need to validate that the discriminant here because the
 -                // `TyAndLayout::for_variant()` call earlier already checks the variant is valid.
 -
 -                if variant_index != untagged_variant {
 -                    let variants_start = niche_variants.start().as_u32();
 -                    let variant_index_relative = variant_index
 -                        .as_u32()
 -                        .checked_sub(variants_start)
 -                        .expect("overflow computing relative variant idx");
 -                    // We need to use machine arithmetic when taking into account `niche_start`:
 -                    // tag_val = variant_index_relative + niche_start_val
 -                    let tag_layout = self.layout_of(tag_layout.primitive().to_int_ty(*self.tcx))?;
 -                    let niche_start_val = ImmTy::from_uint(niche_start, tag_layout);
 -                    let variant_index_relative_val =
 -                        ImmTy::from_uint(variant_index_relative, tag_layout);
 -                    let tag_val = self.binary_op(
 -                        mir::BinOp::Add,
 -                        &variant_index_relative_val,
 -                        &niche_start_val,
 -                    )?;
 -                    // Write result.
 -                    let niche_dest = self.place_field(dest, tag_field)?;
 -                    self.write_immediate(*tag_val, &niche_dest)?;
 -                }
 -            }
 -        }
 -
 -        Ok(())
 -    }
 -
 -    /// Writes the discriminant of the given variant.
 -    #[instrument(skip(self), level = "debug")]
 +    /// Writes the aggregate to the destination.
 +    #[instrument(skip(self), level = "trace")]
      pub fn write_aggregate(
          &mut self,
          kind: &mir::AggregateKind<'tcx>,