Skip to content

Commit ae8d576

Browse files
authored
Merge pull request #4063 from rust-lang/rustup-2024-11-28
Automatic Rustup
2 parents 3125c69 + 195b2b5 commit ae8d576

File tree

4 files changed

+67
-45
lines changed

4 files changed

+67
-45
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5d3c6ee9b34989595d2a72b79e61ca37e949d757
1+
eddb717281a9031f645d88dd3b8323a7e25632cc

src/bin/miri.rs

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
clippy::manual_range_contains,
44
clippy::useless_format,
55
clippy::field_reassign_with_default,
6+
clippy::needless_lifetimes,
67
rustc::diagnostic_outside_of_impl,
78
rustc::untranslatable_diagnostic
89
)]
@@ -73,51 +74,47 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
7374
fn after_analysis<'tcx>(
7475
&mut self,
7576
_: &rustc_interface::interface::Compiler,
76-
queries: &'tcx rustc_interface::Queries<'tcx>,
77+
tcx: TyCtxt<'tcx>,
7778
) -> Compilation {
78-
queries.global_ctxt().unwrap().enter(|tcx| {
79-
if tcx.sess.dcx().has_errors_or_delayed_bugs().is_some() {
80-
tcx.dcx().fatal("miri cannot be run on programs that fail compilation");
81-
}
79+
if tcx.sess.dcx().has_errors_or_delayed_bugs().is_some() {
80+
tcx.dcx().fatal("miri cannot be run on programs that fail compilation");
81+
}
8282

83-
let early_dcx = EarlyDiagCtxt::new(tcx.sess.opts.error_format);
84-
init_late_loggers(&early_dcx, tcx);
85-
if !tcx.crate_types().contains(&CrateType::Executable) {
86-
tcx.dcx().fatal("miri only makes sense on bin crates");
87-
}
83+
let early_dcx = EarlyDiagCtxt::new(tcx.sess.opts.error_format);
84+
init_late_loggers(&early_dcx, tcx);
85+
if !tcx.crate_types().contains(&CrateType::Executable) {
86+
tcx.dcx().fatal("miri only makes sense on bin crates");
87+
}
8888

89-
let (entry_def_id, entry_type) = entry_fn(tcx);
90-
let mut config = self.miri_config.clone();
89+
let (entry_def_id, entry_type) = entry_fn(tcx);
90+
let mut config = self.miri_config.clone();
9191

92-
// Add filename to `miri` arguments.
93-
config.args.insert(0, tcx.sess.io.input.filestem().to_string());
92+
// Add filename to `miri` arguments.
93+
config.args.insert(0, tcx.sess.io.input.filestem().to_string());
9494

95-
// Adjust working directory for interpretation.
96-
if let Some(cwd) = env::var_os("MIRI_CWD") {
97-
env::set_current_dir(cwd).unwrap();
98-
}
95+
// Adjust working directory for interpretation.
96+
if let Some(cwd) = env::var_os("MIRI_CWD") {
97+
env::set_current_dir(cwd).unwrap();
98+
}
9999

100-
if tcx.sess.opts.optimize != OptLevel::No {
101-
tcx.dcx().warn("Miri does not support optimizations: the opt-level is ignored. The only effect \
100+
if tcx.sess.opts.optimize != OptLevel::No {
101+
tcx.dcx().warn("Miri does not support optimizations: the opt-level is ignored. The only effect \
102102
of selecting a Cargo profile that enables optimizations (such as --release) is to apply \
103103
its remaining settings, such as whether debug assertions and overflow checks are enabled.");
104-
}
105-
if tcx.sess.mir_opt_level() > 0 {
106-
tcx.dcx().warn("You have explicitly enabled MIR optimizations, overriding Miri's default \
104+
}
105+
if tcx.sess.mir_opt_level() > 0 {
106+
tcx.dcx().warn("You have explicitly enabled MIR optimizations, overriding Miri's default \
107107
which is to completely disable them. Any optimizations may hide UB that Miri would \
108108
otherwise detect, and it is not necessarily possible to predict what kind of UB will \
109109
be missed. If you are enabling optimizations to make Miri run faster, we advise using \
110110
cfg(miri) to shrink your workload instead. The performance benefit of enabling MIR \
111111
optimizations is usually marginal at best.");
112-
}
112+
}
113113

114-
if let Some(return_code) = miri::eval_entry(tcx, entry_def_id, entry_type, config) {
115-
std::process::exit(
116-
i32::try_from(return_code).expect("Return value was too large!"),
117-
);
118-
}
119-
tcx.dcx().abort_if_errors();
120-
});
114+
if let Some(return_code) = miri::eval_entry(tcx, entry_def_id, entry_type, config) {
115+
std::process::exit(i32::try_from(return_code).expect("Return value was too large!"));
116+
}
117+
tcx.dcx().abort_if_errors();
121118

122119
Compilation::Stop
123120
}
@@ -193,20 +190,18 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
193190
fn after_analysis<'tcx>(
194191
&mut self,
195192
_: &rustc_interface::interface::Compiler,
196-
queries: &'tcx rustc_interface::Queries<'tcx>,
193+
tcx: TyCtxt<'tcx>,
197194
) -> Compilation {
198-
queries.global_ctxt().unwrap().enter(|tcx| {
199-
if self.target_crate {
200-
// cargo-miri has patched the compiler flags to make these into check-only builds,
201-
// but we are still emulating regular rustc builds, which would perform post-mono
202-
// const-eval during collection. So let's also do that here, even if we might be
203-
// running with `--emit=metadata`. In particular this is needed to make
204-
// `compile_fail` doc tests trigger post-mono errors.
205-
// In general `collect_and_partition_mono_items` is not safe to call in check-only
206-
// builds, but we are setting `-Zalways-encode-mir` which avoids those issues.
207-
let _ = tcx.collect_and_partition_mono_items(());
208-
}
209-
});
195+
if self.target_crate {
196+
// cargo-miri has patched the compiler flags to make these into check-only builds,
197+
// but we are still emulating regular rustc builds, which would perform post-mono
198+
// const-eval during collection. So let's also do that here, even if we might be
199+
// running with `--emit=metadata`. In particular this is needed to make
200+
// `compile_fail` doc tests trigger post-mono errors.
201+
// In general `collect_and_partition_mono_items` is not safe to call in check-only
202+
// builds, but we are setting `-Zalways-encode-mir` which avoids those issues.
203+
let _ = tcx.collect_and_partition_mono_items(());
204+
}
210205
Compilation::Continue
211206
}
212207
}

src/shims/windows/foreign_items.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
382382
// Return success (`1`).
383383
this.write_int(1, dest)?;
384384
}
385+
"TlsFree" => {
386+
let [key] =
387+
this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
388+
let key = u128::from(this.read_scalar(key)?.to_u32()?);
389+
this.machine.tls.delete_tls_key(key)?;
390+
391+
// Return success (`1`).
392+
this.write_int(1, dest)?;
393+
}
385394

386395
// Access to command-line arguments
387396
"GetCommandLineW" => {

tests/pass/tls/windows-tls.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@only-target: windows # this directly tests windows-only functions
2+
3+
use std::ffi::c_void;
4+
use std::ptr;
5+
6+
extern "system" {
7+
fn TlsAlloc() -> u32;
8+
fn TlsSetValue(key: u32, val: *mut c_void) -> bool;
9+
fn TlsGetValue(key: u32) -> *mut c_void;
10+
fn TlsFree(key: u32) -> bool;
11+
}
12+
13+
fn main() {
14+
let key = unsafe { TlsAlloc() };
15+
assert!(unsafe { TlsSetValue(key, ptr::without_provenance_mut(1)) });
16+
assert_eq!(unsafe { TlsGetValue(key).addr() }, 1);
17+
assert!(unsafe { TlsFree(key) });
18+
}

0 commit comments

Comments
 (0)