Rollup merge of #76254 - tmiasko:fold-len, r=wesleywiser

Fold length constant in Rvalue::Repeat

Fixes #76248.
This commit is contained in:
Dylan DPC 2020-09-05 16:28:30 +02:00 committed by GitHub
commit 79b8f59185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -175,7 +175,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
use crate::mir::Rvalue::*; use crate::mir::Rvalue::*;
match *self { match *self {
Use(ref op) => Use(op.fold_with(folder)), Use(ref op) => Use(op.fold_with(folder)),
Repeat(ref op, len) => Repeat(op.fold_with(folder), len), Repeat(ref op, len) => Repeat(op.fold_with(folder), len.fold_with(folder)),
ThreadLocalRef(did) => ThreadLocalRef(did.fold_with(folder)), ThreadLocalRef(did) => ThreadLocalRef(did.fold_with(folder)),
Ref(region, bk, ref place) => { Ref(region, bk, ref place) => {
Ref(region.fold_with(folder), bk, place.fold_with(folder)) Ref(region.fold_with(folder), bk, place.fold_with(folder))

View File

@ -0,0 +1,29 @@
// This used to ICE during codegen after MIR inlining of g into f.
// The root cause was a missing fold of length constant in Rvalue::Repeat.
// Regression test for #76248.
//
// build-pass
// compile-flags: -Zmir-opt-level=2
const N: usize = 1;
pub struct Elem<M> {
pub x: [usize; N],
pub m: M,
}
pub fn f() -> Elem<()> {
g(())
}
#[inline]
pub fn g<M>(m: M) -> Elem<M> {
Elem {
x: [0; N],
m,
}
}
pub fn main() {
f();
}