Skip to content

Commit 98bce85

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents a8566bf + f9b80b1 commit 98bce85

File tree

3 files changed

+64
-44
lines changed

3 files changed

+64
-44
lines changed

src/bin/miri.rs

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -73,51 +73,47 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
7373
fn after_analysis<'tcx>(
7474
&mut self,
7575
_: &rustc_interface::interface::Compiler,
76-
queries: &'tcx rustc_interface::Queries<'tcx>,
76+
tcx: TyCtxt<'tcx>,
7777
) -> 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-
}
78+
if tcx.sess.dcx().has_errors_or_delayed_bugs().is_some() {
79+
tcx.dcx().fatal("miri cannot be run on programs that fail compilation");
80+
}
8281

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-
}
82+
let early_dcx = EarlyDiagCtxt::new(tcx.sess.opts.error_format);
83+
init_late_loggers(&early_dcx, tcx);
84+
if !tcx.crate_types().contains(&CrateType::Executable) {
85+
tcx.dcx().fatal("miri only makes sense on bin crates");
86+
}
8887

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

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

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

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 \
99+
if tcx.sess.opts.optimize != OptLevel::No {
100+
tcx.dcx().warn("Miri does not support optimizations: the opt-level is ignored. The only effect \
102101
of selecting a Cargo profile that enables optimizations (such as --release) is to apply \
103102
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 \
103+
}
104+
if tcx.sess.mir_opt_level() > 0 {
105+
tcx.dcx().warn("You have explicitly enabled MIR optimizations, overriding Miri's default \
107106
which is to completely disable them. Any optimizations may hide UB that Miri would \
108107
otherwise detect, and it is not necessarily possible to predict what kind of UB will \
109108
be missed. If you are enabling optimizations to make Miri run faster, we advise using \
110109
cfg(miri) to shrink your workload instead. The performance benefit of enabling MIR \
111110
optimizations is usually marginal at best.");
112-
}
111+
}
113112

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-
});
113+
if let Some(return_code) = miri::eval_entry(tcx, entry_def_id, entry_type, config) {
114+
std::process::exit(i32::try_from(return_code).expect("Return value was too large!"));
115+
}
116+
tcx.dcx().abort_if_errors();
121117

122118
Compilation::Stop
123119
}
@@ -193,20 +189,18 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
193189
fn after_analysis<'tcx>(
194190
&mut self,
195191
_: &rustc_interface::interface::Compiler,
196-
queries: &'tcx rustc_interface::Queries<'tcx>,
192+
tcx: TyCtxt<'tcx>,
197193
) -> 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-
});
194+
if self.target_crate {
195+
// cargo-miri has patched the compiler flags to make these into check-only builds,
196+
// but we are still emulating regular rustc builds, which would perform post-mono
197+
// const-eval during collection. So let's also do that here, even if we might be
198+
// running with `--emit=metadata`. In particular this is needed to make
199+
// `compile_fail` doc tests trigger post-mono errors.
200+
// In general `collect_and_partition_mono_items` is not safe to call in check-only
201+
// builds, but we are setting `-Zalways-encode-mir` which avoids those issues.
202+
let _ = tcx.collect_and_partition_mono_items(());
203+
}
210204
Compilation::Continue
211205
}
212206
}

src/shims/windows/foreign_items.rs

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

386394
// Access to command-line arguments
387395
"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)