Skip to content

Commit 1b459c4

Browse files
committed
Auto merge of #116564 - oli-obk:evaluated_static_in_metadata, r=RalfJung,cjgillot
Store static initializers in metadata instead of the MIR of statics. This means that adding generic statics would be even more difficult, as we can't evaluate statics from other crates anymore, but the subtle issue I have encountered make me think that having this be an explicit problem is better. The issue is that ```rust static mut FOO: &mut u32 = &mut 42; static mut BAR = unsafe { FOO }; ``` gets different allocations, instead of referring to the same one. This is also true for non-static mut, but promotion makes `static FOO: &u32 = &42;` annoying to demo. Fixes rust-lang/rust#61345 ## Why is this being done? In order to ensure all crates see the same nested allocations (which is the last issue that needs fixing before we can stabilize [`const_mut_refs`](rust-lang/rust#57349)), I am working on creating anonymous (from the Rust side, to LLVM it's like a regular static item) static items for the nested allocations in a static. If we evaluate the static item in a downstream crate again, we will end up duplicating its nested allocations (and in some cases, like the `match` case, even duplicate the main allocation).
2 parents 4232e7f + fda1555 commit 1b459c4

File tree

5 files changed

+2
-9
lines changed

5 files changed

+2
-9
lines changed

src/shims/intrinsics/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
108108
"volatile_load" => {
109109
let [place] = check_arg_count(args)?;
110110
let place = this.deref_pointer(place)?;
111-
this.copy_op(&place, dest, /*allow_transmute*/ false)?;
111+
this.copy_op(&place, dest)?;
112112
}
113113
"volatile_store" => {
114114
let [place, dest] = check_arg_count(args)?;
115115
let place = this.deref_pointer(place)?;
116-
this.copy_op(dest, &place, /*allow_transmute*/ false)?;
116+
this.copy_op(dest, &place)?;
117117
}
118118

119119
"write_bytes" | "volatile_set_memory" => {

src/shims/x86/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ fn bin_op_simd_float_first<'tcx, F: rustc_apfloat::Float>(
299299
this.copy_op(
300300
&this.project_index(&left, i)?,
301301
&this.project_index(&dest, i)?,
302-
/*allow_transmute*/ false,
303302
)?;
304303
}
305304

@@ -424,7 +423,6 @@ fn unary_op_ss<'tcx>(
424423
this.copy_op(
425424
&this.project_index(&op, i)?,
426425
&this.project_index(&dest, i)?,
427-
/*allow_transmute*/ false,
428426
)?;
429427
}
430428

@@ -484,7 +482,6 @@ fn round_first<'tcx, F: rustc_apfloat::Float>(
484482
this.copy_op(
485483
&this.project_index(&left, i)?,
486484
&this.project_index(&dest, i)?,
487-
/*allow_transmute*/ false,
488485
)?;
489486
}
490487

src/shims/x86/sse.rs

-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
211211
this.copy_op(
212212
&this.project_index(&left, i)?,
213213
&this.project_index(&dest, i)?,
214-
/*allow_transmute*/ false,
215214
)?;
216215
}
217216
}

src/shims/x86/sse2.rs

-2
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
443443
this.copy_op(
444444
&this.project_index(&op, i)?,
445445
&this.project_index(&dest, i)?,
446-
/*allow_transmute*/ false,
447446
)?;
448447
}
449448
}
@@ -584,7 +583,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
584583
this.copy_op(
585584
&this.project_index(&left, i)?,
586585
&this.project_index(&dest, i)?,
587-
/*allow_transmute*/ false,
588586
)?;
589587
}
590588
}

src/shims/x86/sse41.rs

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
6060
this.copy_op(
6161
&this.project_index(&left, i)?,
6262
&dest,
63-
/*allow_transmute*/ false,
6463
)?;
6564
}
6665
}

0 commit comments

Comments
 (0)