fix ICE when const refers to extern static
This commit is contained in:
parent
8d1b2ca3ec
commit
f992099820
@ -618,7 +618,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
|
|||||||
id: AllocId,
|
id: AllocId,
|
||||||
alloc: Cow<'b, Allocation>,
|
alloc: Cow<'b, Allocation>,
|
||||||
kind: Option<MemoryKind<Self::MemoryKind>>,
|
kind: Option<MemoryKind<Self::MemoryKind>>,
|
||||||
) -> Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>> {
|
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>> {
|
||||||
if ecx.machine.tracked_alloc_ids.contains(&id) {
|
if ecx.machine.tracked_alloc_ids.contains(&id) {
|
||||||
register_diagnostic(NonHaltingDiagnostic::CreatedAlloc(id));
|
register_diagnostic(NonHaltingDiagnostic::CreatedAlloc(id));
|
||||||
}
|
}
|
||||||
@ -653,9 +653,9 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
|
|||||||
data_race: race_alloc,
|
data_race: race_alloc,
|
||||||
weak_memory: buffer_alloc,
|
weak_memory: buffer_alloc,
|
||||||
},
|
},
|
||||||
|ptr| Evaluator::tag_alloc_base_pointer(ecx, ptr),
|
|ptr| ecx.global_base_pointer(ptr),
|
||||||
);
|
)?;
|
||||||
Cow::Owned(alloc)
|
Ok(Cow::Owned(alloc))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tag_alloc_base_pointer(
|
fn tag_alloc_base_pointer(
|
||||||
|
@ -587,7 +587,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||||||
// This allocation will be deallocated when the thread dies, so it is not in read-only memory.
|
// This allocation will be deallocated when the thread dies, so it is not in read-only memory.
|
||||||
allocation.mutability = Mutability::Mut;
|
allocation.mutability = Mutability::Mut;
|
||||||
// Create a fresh allocation with this content.
|
// Create a fresh allocation with this content.
|
||||||
let new_alloc = this.allocate_raw_ptr(allocation, MiriMemoryKind::Tls.into());
|
let new_alloc = this.allocate_raw_ptr(allocation, MiriMemoryKind::Tls.into())?;
|
||||||
this.machine.threads.set_thread_local_alloc(def_id, new_alloc);
|
this.machine.threads.set_thread_local_alloc(def_id, new_alloc);
|
||||||
Ok(new_alloc)
|
Ok(new_alloc)
|
||||||
}
|
}
|
||||||
|
11
tests/fail/extern_static_in_const.rs
Normal file
11
tests/fail/extern_static_in_const.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//! Even referencing an unknown `extern static` already triggers an error.
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
static E: [u8; 0];
|
||||||
|
}
|
||||||
|
|
||||||
|
static X: &'static [u8; 0] = unsafe { &E };
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _val = X; //~ ERROR is not supported by Miri
|
||||||
|
}
|
14
tests/fail/extern_static_in_const.stderr
Normal file
14
tests/fail/extern_static_in_const.stderr
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
error: unsupported operation: `extern` static `E` from crate `extern_static_in_const` is not supported by Miri
|
||||||
|
--> $DIR/extern_static_in_const.rs:LL:CC
|
||||||
|
|
|
||||||
|
LL | let _val = X;
|
||||||
|
| ^ `extern` static `E` from crate `extern_static_in_const` is not supported by Miri
|
||||||
|
|
|
||||||
|
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
|
||||||
|
|
||||||
|
= note: inside `main` at $DIR/extern_static_in_const.rs:LL:CC
|
||||||
|
|
||||||
|
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user