From 8d1b2ca3ec998fc8bdbfe03f5c8faf7cc138a9ed Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 14 Jun 2022 09:45:02 -0700 Subject: [PATCH 1/3] check that tag_alloc_base_pointer is not called on the wrong things --- src/machine.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/machine.rs b/src/machine.rs index 824f0e3fc87..955677df6f0 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -662,6 +662,19 @@ fn tag_alloc_base_pointer( ecx: &MiriEvalContext<'mir, 'tcx>, ptr: Pointer, ) -> Pointer { + if cfg!(debug_assertions) { + // The machine promises to never call us on thread-local or extern statics. + let alloc_id = ptr.provenance; + match ecx.tcx.get_global_alloc(alloc_id) { + Some(GlobalAlloc::Static(def_id)) if ecx.tcx.is_thread_local_static(def_id) => { + panic!("tag_alloc_base_pointer called on thread-local static") + } + Some(GlobalAlloc::Static(def_id)) if ecx.tcx.is_foreign_item(def_id) => { + panic!("tag_alloc_base_pointer called on extern static") + } + _ => {} + } + } let absolute_addr = intptrcast::GlobalStateInner::rel_ptr_to_addr(ecx, ptr); let sb_tag = if let Some(stacked_borrows) = &ecx.machine.stacked_borrows { stacked_borrows.borrow_mut().base_tag(ptr.provenance) From f992099820993005ec9ac9ddf6d6646b85c55311 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 19 Jun 2022 09:45:05 -0700 Subject: [PATCH 2/3] fix ICE when const refers to extern static --- src/machine.rs | 8 ++++---- src/thread.rs | 2 +- tests/fail/extern_static_in_const.rs | 11 +++++++++++ tests/fail/extern_static_in_const.stderr | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 tests/fail/extern_static_in_const.rs create mode 100644 tests/fail/extern_static_in_const.stderr diff --git a/src/machine.rs b/src/machine.rs index 955677df6f0..d14ddaa1a6b 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -618,7 +618,7 @@ fn init_allocation_extra<'b>( id: AllocId, alloc: Cow<'b, Allocation>, kind: Option>, - ) -> Cow<'b, Allocation> { + ) -> InterpResult<'tcx, Cow<'b, Allocation>> { if ecx.machine.tracked_alloc_ids.contains(&id) { register_diagnostic(NonHaltingDiagnostic::CreatedAlloc(id)); } @@ -653,9 +653,9 @@ fn init_allocation_extra<'b>( data_race: race_alloc, weak_memory: buffer_alloc, }, - |ptr| Evaluator::tag_alloc_base_pointer(ecx, ptr), - ); - Cow::Owned(alloc) + |ptr| ecx.global_base_pointer(ptr), + )?; + Ok(Cow::Owned(alloc)) } fn tag_alloc_base_pointer( diff --git a/src/thread.rs b/src/thread.rs index 9eabbd77419..2135806de3e 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -587,7 +587,7 @@ fn get_or_create_thread_local_alloc( // This allocation will be deallocated when the thread dies, so it is not in read-only memory. allocation.mutability = Mutability::Mut; // 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); Ok(new_alloc) } diff --git a/tests/fail/extern_static_in_const.rs b/tests/fail/extern_static_in_const.rs new file mode 100644 index 00000000000..4c1de6ace51 --- /dev/null +++ b/tests/fail/extern_static_in_const.rs @@ -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 +} diff --git a/tests/fail/extern_static_in_const.stderr b/tests/fail/extern_static_in_const.stderr new file mode 100644 index 00000000000..8524bb02c05 --- /dev/null +++ b/tests/fail/extern_static_in_const.stderr @@ -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 + From b29a706edd5e9b7d9f8bf0ba1beb2374326f8acf Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 21 Jun 2022 21:03:52 -0700 Subject: [PATCH 3/3] rustup --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index 9782fbe6cd4..45773390616 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -cdcc53b7dc002ea4a7a28105010c5a1126ee31b7 +a09c668c965f735f4cd59e7158662b9daa0b71ba