Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 15 pull requests #122338

Merged
merged 50 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a03d19e
Allow targets to override default codegen backend
WaffleLapkin Feb 14, 2024
5441523
Refactor out a repeating pattern with `get_or_default_sysroot`
WaffleLapkin Feb 15, 2024
9a77ec9
Rename `-Zno_parallel_llvm` -> `-Zno_parallel_backend`
WaffleLapkin Feb 15, 2024
f368922
Allow codegen backends to opt-out of parallel codegen
WaffleLapkin Feb 15, 2024
8bb49e2
Propagate the resolved type of assoc const bindings via query feeding
fmease Dec 31, 2023
6d115f5
Refactor out another repeating pattern
WaffleLapkin Feb 18, 2024
b94498a
Use existing query feeding workarounds
oli-obk Feb 21, 2024
3908a93
std support for wasm32 panic=unwind
coolreader18 Feb 21, 2024
861c7e7
Fix llvm hang
coolreader18 Feb 22, 2024
658a0a2
Unconditionally pass -wasm-enable-eh
coolreader18 Feb 22, 2024
125b26a
Use Itanium ABI for thrown exceptions
coolreader18 Feb 22, 2024
c7fcf43
Don't codegen wasm.throw unless with -Zbuild-std
coolreader18 Feb 26, 2024
858d336
Slightly simplify feeding of assoc const eq bounds
fmease Feb 23, 2024
d9a2886
add comment and test: we do not do value-based reasoning for promotio…
RalfJung Feb 29, 2024
30fa6a8
Rename `DropTreeBuilder::add_entry` to `link_entry_point`
Zalathar Mar 6, 2024
3bd8df9
Assert that `link_entry_point` sees the expected dummy terminator
Zalathar Mar 6, 2024
fbdac30
Rename `DropTree::add_entry` to `add_entry_point`
Zalathar Mar 6, 2024
5ba70bd
Replace tuples in `DropTree` with named structs
Zalathar Mar 6, 2024
d673fd8
Remove the unused `field_remapping` field from `TypeLowering`
beetrees Mar 8, 2024
bf47df8
interpret: do not call machine read hooks during validation
RalfJung Mar 9, 2024
58f6aaa
Improve diagnostics for parenthesized type arguments
wutchzone Mar 7, 2024
3830510
Ignore tests w/ current/next revisions from compare-mode=next-solver
compiler-errors Mar 11, 2024
a7cd803
use ptradd for vtable indexing
erikdesjardins Mar 11, 2024
73fc170
Store backtrace for must_produce_diag
compiler-errors Mar 10, 2024
01e6b43
Mark some next-solver-behavior tests explicitly with revisions
compiler-errors Mar 11, 2024
aea60b0
unix_sigpipe: Replace `inherit` with `sig_dfl` in syntax tests
Enselic Feb 9, 2024
816dc96
bootstrap readme: fix, improve, update
tshepang Mar 11, 2024
ed252e9
LLVM_TOOLS: Include llvm-link as a llvm tool
Oct 26, 2023
222ce4f
LLVM Bitcode Linker: Added crate
Feb 6, 2024
af42d2a
NVPTX: Enable self-contained for the nvptx target
Dec 1, 2023
43f2055
LLVM Bitcode Linker: Add as a linker known to the compiler
Feb 6, 2024
6a50d05
Bootstrap: Add argument for building llvm bitcode linker
Feb 6, 2024
843dd28
NVPTX: Enable previously disabled tests
Mar 4, 2024
279465b
const-checking: add some corner case tests, and fix some nits
RalfJung Mar 2, 2024
fb802f2
promote-not: add test that distinguishes promotion from outer scope rule
RalfJung Mar 11, 2024
88d387b
Rollup merge of #116791 - WaffleLapkin:unparallel-backends, r=oli-obk
workingjubilee Mar 11, 2024
86af4d2
Rollup merge of #116793 - WaffleLapkin:target_rules_the_backend, r=cj…
workingjubilee Mar 11, 2024
e1ceadc
Rollup merge of #117458 - kjetilkjeka:embedded-linker, r=petrochenkov
workingjubilee Mar 11, 2024
a450339
Rollup merge of #119385 - fmease:assoc-const-eq-fixes-2, r=oli-obk,cj…
workingjubilee Mar 11, 2024
1279830
Rollup merge of #121438 - coolreader18:wasm32-panic-unwind, r=cuviper
workingjubilee Mar 11, 2024
9300fbb
Rollup merge of #121893 - RalfJung:const-interior-mut-tests, r=oli-obk
workingjubilee Mar 11, 2024
e3f9b2f
Rollup merge of #122080 - Zalathar:drop-tree, r=oli-obk
workingjubilee Mar 11, 2024
05ff86c
Rollup merge of #122152 - wutchzone:120892, r=fmease
workingjubilee Mar 11, 2024
afa0581
Rollup merge of #122166 - beetrees:remove-field-remapping, r=davidtwco
workingjubilee Mar 11, 2024
f6ca425
Rollup merge of #122249 - RalfJung:machine-read-hook, r=oli-obk
workingjubilee Mar 11, 2024
671fc18
Rollup merge of #122299 - compiler-errors:bt-for-must-diag, r=nnether…
workingjubilee Mar 11, 2024
a11e6c3
Rollup merge of #122318 - compiler-errors:next-solver-tests, r=lcnr
workingjubilee Mar 11, 2024
028e260
Rollup merge of #122320 - erikdesjardins:vtable, r=nikic
workingjubilee Mar 11, 2024
9aca5c0
Rollup merge of #122328 - Enselic:sig_dfl-not-inherit, r=davidtwco
workingjubilee Mar 11, 2024
7fa6fa4
Rollup merge of #122330 - tshepang:patch-1, r=clubby789
workingjubilee Mar 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
interpret: do not call machine read hooks during validation
  • Loading branch information
RalfJung committed Mar 9, 2024
commit bf47df8b0be83dde623a1057e63fd728c0ae5dec
8 changes: 2 additions & 6 deletions compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,12 @@ pub fn eval_in_interpreter<'mir, 'tcx>(
}
Ok(mplace) => {
// Since evaluation had no errors, validate the resulting constant.

// Temporarily allow access to the static_root_alloc_id for the purpose of validation.
let static_root_alloc_id = ecx.machine.static_root_alloc_id.take();
let validation = const_validate_mplace(&ecx, &mplace, cid);
ecx.machine.static_root_alloc_id = static_root_alloc_id;
let res = const_validate_mplace(&ecx, &mplace, cid);

let alloc_id = mplace.ptr().provenance.unwrap().alloc_id();

// Validation failed, report an error.
if let Err(error) = validation {
if let Err(error) = res {
Err(const_report_error(&ecx, error, alloc_id))
} else {
// Convert to raw constant
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_const_eval/src/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {

/// Hook for performing extra checks on a memory read access.
///
/// This will *not* be called during validation!
///
/// Takes read-only access to the allocation so we can keep all the memory read
/// operations take `&self`. Use a `RefCell` in `AllocExtra` if you
/// need to mutate.
Expand All @@ -410,6 +412,8 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
/// Hook for performing extra checks on any memory read access,
/// that involves an allocation, even ZST reads.
///
/// This will *not* be called during validation!
///
/// Used to prevent statics from self-initializing by reading from their own memory
/// as it is being initialized.
fn before_alloc_read(
Expand Down
43 changes: 38 additions & 5 deletions compiler/rustc_const_eval/src/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use std::assert_matches::assert_matches;
use std::borrow::Cow;
use std::cell::Cell;
use std::collections::VecDeque;
use std::fmt;
use std::ptr;
Expand Down Expand Up @@ -111,6 +112,11 @@ pub struct Memory<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
/// that do not exist any more.
// FIXME: this should not be public, but interning currently needs access to it
pub(super) dead_alloc_map: FxIndexMap<AllocId, (Size, Align)>,

/// This stores whether we are currently doing reads purely for the purpose of validation.
/// Those reads do not trigger the machine's hooks for memory reads.
/// Needless to say, this must only be set with great care!
validation_in_progress: Cell<bool>,
}

/// A reference to some allocation that was already bounds-checked for the given region
Expand All @@ -137,6 +143,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
alloc_map: M::MemoryMap::default(),
extra_fn_ptr_map: FxIndexMap::default(),
dead_alloc_map: FxIndexMap::default(),
validation_in_progress: Cell::new(false),
}
}

Expand Down Expand Up @@ -624,18 +631,28 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
size,
CheckInAllocMsg::MemoryAccessTest,
|alloc_id, offset, prov| {
// We want to call the hook on *all* accesses that involve an AllocId,
// including zero-sized accesses. That means we have to do it here
// rather than below in the `Some` branch.
M::before_alloc_read(self, alloc_id)?;
if !self.memory.validation_in_progress.get() {
// We want to call the hook on *all* accesses that involve an AllocId,
// including zero-sized accesses. That means we have to do it here
// rather than below in the `Some` branch.
M::before_alloc_read(self, alloc_id)?;
}
let alloc = self.get_alloc_raw(alloc_id)?;
Ok((alloc.size(), alloc.align, (alloc_id, offset, prov, alloc)))
},
)?;

if let Some((alloc_id, offset, prov, alloc)) = ptr_and_alloc {
let range = alloc_range(offset, size);
M::before_memory_read(self.tcx, &self.machine, &alloc.extra, (alloc_id, prov), range)?;
if !self.memory.validation_in_progress.get() {
M::before_memory_read(
self.tcx,
&self.machine,
&alloc.extra,
(alloc_id, prov),
range,
)?;
}
Ok(Some(AllocRef { alloc, range, tcx: *self.tcx, alloc_id }))
} else {
Ok(None)
Expand Down Expand Up @@ -909,6 +926,21 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}
})
}

/// Runs the close in "validation" mode, which means the machine's memory read hooks will be
/// suppressed. Needless to say, this must only be set with great care! Cannot be nested.
pub(super) fn run_for_validation<R>(&self, f: impl FnOnce() -> R) -> R {
assert!(
self.memory.validation_in_progress.replace(true) == false,
"`validation_in_progress` was already set"
);
let res = f();
assert!(
self.memory.validation_in_progress.replace(false) == true,
"`validation_in_progress` was unset by someone else"
);
res
}
}

#[doc(hidden)]
Expand Down Expand Up @@ -1154,6 +1186,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
};
let src_alloc = self.get_alloc_raw(src_alloc_id)?;
let src_range = alloc_range(src_offset, size);
assert!(!self.memory.validation_in_progress.get(), "we can't be copying during validation");
M::before_memory_read(
tcx,
&self.machine,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let mut visitor = ValidityVisitor { path, ref_tracking, ctfe_mode, ecx: self };

// Run it.
match visitor.visit_value(op) {
match self.run_for_validation(|| visitor.visit_value(op)) {
Ok(()) => Ok(()),
// Pass through validation failures and "invalid program" issues.
Err(err)
Expand Down
25 changes: 25 additions & 0 deletions src/tools/miri/tests/pass/alloc-access-tracking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#![feature(start)]
#![no_std]
//@compile-flags: -Zmiri-track-alloc-id=17 -Zmiri-track-alloc-accesses -Cpanic=abort
//@only-target-linux: alloc IDs differ between OSes for some reason

extern "Rust" {
fn miri_alloc(size: usize, align: usize) -> *mut u8;
fn miri_dealloc(ptr: *mut u8, size: usize, align: usize);
}

#[start]
fn start(_: isize, _: *const *const u8) -> isize {
unsafe {
let ptr = miri_alloc(123, 1);
*ptr = 42; // Crucially, only a write is printed here, no read!
assert_eq!(*ptr, 42);
miri_dealloc(ptr, 123, 1);
}
0
}

#[panic_handler]
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
loop {}
}
37 changes: 37 additions & 0 deletions src/tools/miri/tests/pass/alloc-access-tracking.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
note: tracking was triggered
--> $DIR/alloc-access-tracking.rs:LL:CC
|
LL | let ptr = miri_alloc(123, 1);
| ^^^^^^^^^^^^^^^^^^ created Miri bare-metal heap allocation of 123 bytes (alignment ALIGN bytes) with id 17
|
= note: BACKTRACE:
= note: inside `start` at $DIR/alloc-access-tracking.rs:LL:CC

note: tracking was triggered
--> $DIR/alloc-access-tracking.rs:LL:CC
|
LL | *ptr = 42; // Crucially, only a write is printed here, no read!
| ^^^^^^^^^ write access to allocation with id 17
|
= note: BACKTRACE:
= note: inside `start` at $DIR/alloc-access-tracking.rs:LL:CC

note: tracking was triggered
--> $DIR/alloc-access-tracking.rs:LL:CC
|
LL | assert_eq!(*ptr, 42);
| ^^^^^^^^^^^^^^^^^^^^ read access to allocation with id 17
|
= note: BACKTRACE:
= note: inside `start` at RUSTLIB/core/src/macros/mod.rs:LL:CC
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

note: tracking was triggered
--> $DIR/alloc-access-tracking.rs:LL:CC
|
LL | miri_dealloc(ptr, 123, 1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^ freed allocation with id 17
|
= note: BACKTRACE:
= note: inside `start` at $DIR/alloc-access-tracking.rs:LL:CC

Loading