From 3e7a4ca2f1d576a4a23e8c541cb5c0c420b108de Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Mon, 17 Dec 2018 16:47:26 +0100 Subject: [PATCH 1/2] Remove a wrong multiplier on relocation offset computation --- src/librustc_mir/interpret/memory.rs | 8 ++++---- src/test/ui/consts/promoted_regression.rs | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/consts/promoted_regression.rs diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 420fe26426321..65347a02be0c7 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -707,10 +707,10 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> { new_relocations.extend( relocations .iter() - .map(|&(offset, reloc)| { - (offset + dest.offset - src.offset + (i * size * relocations.len() as u64), - reloc) - }) + .map(|&(offset, reloc)| ( + offset + dest.offset - src.offset + (i * size), + reloc, + )) ); } diff --git a/src/test/ui/consts/promoted_regression.rs b/src/test/ui/consts/promoted_regression.rs new file mode 100644 index 0000000000000..68b9a20ecf90b --- /dev/null +++ b/src/test/ui/consts/promoted_regression.rs @@ -0,0 +1,9 @@ +// compile-pass + +fn main() { + let _ = &[("", ""); 3]; +} + +const FOO: &[(&str, &str)] = &[("", ""); 3]; +const BAR: &[(&str, &str); 5] = &[("", ""); 5]; +const BAA: &[[&str; 12]; 11] = &[[""; 12]; 11]; From 50eb5f6137719a7e8fdd270e90af0d734d002c5d Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 18 Dec 2018 10:08:37 +0100 Subject: [PATCH 2/2] Explain the math --- src/librustc_mir/interpret/memory.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 65347a02be0c7..77a5f5d7b3a84 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -707,10 +707,15 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> { new_relocations.extend( relocations .iter() - .map(|&(offset, reloc)| ( - offset + dest.offset - src.offset + (i * size), - reloc, - )) + .map(|&(offset, reloc)| { + // compute offset for current repetition + let dest_offset = dest.offset + (i * size); + ( + // shift offsets from source allocation to destination allocation + offset + dest_offset - src.offset, + reloc, + ) + }) ); }