Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f992099

Browse files
committed
fix ICE when const refers to extern static
1 parent 8d1b2ca commit f992099

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

src/machine.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
618618
id: AllocId,
619619
alloc: Cow<'b, Allocation>,
620620
kind: Option<MemoryKind<Self::MemoryKind>>,
621-
) -> Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>> {
621+
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>> {
622622
if ecx.machine.tracked_alloc_ids.contains(&id) {
623623
register_diagnostic(NonHaltingDiagnostic::CreatedAlloc(id));
624624
}
@@ -653,9 +653,9 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
653653
data_race: race_alloc,
654654
weak_memory: buffer_alloc,
655655
},
656-
|ptr| Evaluator::tag_alloc_base_pointer(ecx, ptr),
657-
);
658-
Cow::Owned(alloc)
656+
|ptr| ecx.global_base_pointer(ptr),
657+
)?;
658+
Ok(Cow::Owned(alloc))
659659
}
660660

661661
fn tag_alloc_base_pointer(

src/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
587587
// This allocation will be deallocated when the thread dies, so it is not in read-only memory.
588588
allocation.mutability = Mutability::Mut;
589589
// Create a fresh allocation with this content.
590-
let new_alloc = this.allocate_raw_ptr(allocation, MiriMemoryKind::Tls.into());
590+
let new_alloc = this.allocate_raw_ptr(allocation, MiriMemoryKind::Tls.into())?;
591591
this.machine.threads.set_thread_local_alloc(def_id, new_alloc);
592592
Ok(new_alloc)
593593
}

tests/fail/extern_static_in_const.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! Even referencing an unknown `extern static` already triggers an error.
2+
3+
extern "C" {
4+
static E: [u8; 0];
5+
}
6+
7+
static X: &'static [u8; 0] = unsafe { &E };
8+
9+
fn main() {
10+
let _val = X; //~ ERROR is not supported by Miri
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unsupported operation: `extern` static `E` from crate `extern_static_in_const` is not supported by Miri
2+
--> $DIR/extern_static_in_const.rs:LL:CC
3+
|
4+
LL | let _val = X;
5+
| ^ `extern` static `E` from crate `extern_static_in_const` is not supported by Miri
6+
|
7+
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
8+
9+
= note: inside `main` at $DIR/extern_static_in_const.rs:LL:CC
10+
11+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)