Skip to content

Commit cf1cecc

Browse files
committed
fix jobserver GLOBAL_CLIENT_CHECKED uninitialized before use
1 parent 7df0c21 commit cf1cecc

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

compiler/rustc_data_structures/src/jobserver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn default_client() -> Client {
5252

5353
static GLOBAL_CLIENT_CHECKED: OnceLock<Client> = OnceLock::new();
5454

55-
pub fn check(report_warning: impl FnOnce(&'static str)) {
55+
pub fn initialize_checked(report_warning: impl FnOnce(&'static str)) {
5656
let client_checked = match &*GLOBAL_CLIENT {
5757
Ok(client) => client.clone(),
5858
Err(e) => {

compiler/rustc_interface/src/interface.rs

+4
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
316316
// Set parallel mode before thread pool creation, which will create `Lock`s.
317317
rustc_data_structures::sync::set_dyn_thread_safe_mode(config.opts.unstable_opts.threads > 1);
318318

319+
// Check jobserver before run_in_thread_pool_with_globals, which call jobserver::acquire_thread
320+
let early_handler = EarlyErrorHandler::new(config.opts.error_format);
321+
early_handler.initialize_checked_jobserver();
322+
319323
util::run_in_thread_pool_with_globals(
320324
config.opts.edition,
321325
config.opts.unstable_opts.threads,

compiler/rustc_interface/src/tests.rs

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ use std::sync::Arc;
2727

2828
fn mk_session(matches: getopts::Matches) -> (Session, Cfg) {
2929
let mut early_handler = EarlyErrorHandler::new(ErrorOutputType::default());
30+
early_handler.initialize_checked_jobserver();
31+
3032
let registry = registry::Registry::new(&[]);
3133
let sessopts = build_session_options(&mut early_handler, &matches);
3234
let temps_dir = sessopts.unstable_opts.temps_dir.as_deref().map(PathBuf::from);

compiler/rustc_session/src/session.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -1474,17 +1474,6 @@ pub fn build_session(
14741474
let asm_arch =
14751475
if target_cfg.allow_asm { InlineAsmArch::from_str(&target_cfg.arch).ok() } else { None };
14761476

1477-
// Check jobserver before getting `jobserver::client`.
1478-
jobserver::check(|err| {
1479-
#[allow(rustc::untranslatable_diagnostic)]
1480-
#[allow(rustc::diagnostic_outside_of_impl)]
1481-
parse_sess
1482-
.span_diagnostic
1483-
.struct_warn(err)
1484-
.note("the build environment is likely misconfigured")
1485-
.emit()
1486-
});
1487-
14881477
let sess = Session {
14891478
target: target_cfg,
14901479
host,
@@ -1792,6 +1781,18 @@ impl EarlyErrorHandler {
17921781
pub fn early_warn(&self, msg: impl Into<DiagnosticMessage>) {
17931782
self.handler.struct_warn(msg).emit()
17941783
}
1784+
1785+
pub fn initialize_checked_jobserver(&self) {
1786+
// initialize jobserver before getting `jobserver::client` and `build_session`.
1787+
jobserver::initialize_checked(|err| {
1788+
#[allow(rustc::untranslatable_diagnostic)]
1789+
#[allow(rustc::diagnostic_outside_of_impl)]
1790+
self.handler
1791+
.struct_warn(err)
1792+
.note("the build environment is likely misconfigured")
1793+
.emit()
1794+
});
1795+
}
17951796
}
17961797

17971798
fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {

0 commit comments

Comments
 (0)