Skip to content

Commit 4f5355a

Browse files
committed
fix jobserver GLOBAL_CLIENT_CHECKED uninitialized before use
1 parent 85a4bd8 commit 4f5355a

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
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
@@ -382,6 +382,10 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
382382
// Set parallel mode before thread pool creation, which will create `Lock`s.
383383
rustc_data_structures::sync::set_dyn_thread_safe_mode(config.opts.unstable_opts.threads > 1);
384384

385+
// Check jobserver before run_in_thread_pool_with_globals, which call jobserver::acquire_thread
386+
let handler = EarlyErrorHandler::new(config.opts.error_format);
387+
handler.initialize_checked_jobserver();
388+
385389
util::run_in_thread_pool_with_globals(
386390
config.opts.edition,
387391
config.opts.unstable_opts.threads,

compiler/rustc_interface/src/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ fn mk_session(handler: &mut EarlyErrorHandler, matches: getopts::Matches) -> (Se
3636
output_file: None,
3737
temps_dir,
3838
};
39+
40+
handler.initialize_checked_jobserver();
41+
3942
let sess = build_session(
4043
handler,
4144
sessopts,

compiler/rustc_session/src/session.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1469,11 +1469,6 @@ pub fn build_session(
14691469
let asm_arch =
14701470
if target_cfg.allow_asm { InlineAsmArch::from_str(&target_cfg.arch).ok() } else { None };
14711471

1472-
// Check jobserver before getting `jobserver::client`.
1473-
jobserver::check(|err| {
1474-
handler.early_warn_with_note(err, "the build environment is likely misconfigured")
1475-
});
1476-
14771472
let sess = Session {
14781473
target: target_cfg,
14791474
host,
@@ -1791,6 +1786,13 @@ impl EarlyErrorHandler {
17911786
) {
17921787
self.handler.struct_warn(msg).note(note).emit()
17931788
}
1789+
1790+
pub fn initialize_checked_jobserver(&self) {
1791+
// initialize jobserver before getting `jobserver::client` and `build_session`.
1792+
jobserver::initialize_checked(|err| {
1793+
self.early_warn_with_note(err, "the build environment is likely misconfigured")
1794+
});
1795+
}
17941796
}
17951797

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

0 commit comments

Comments
 (0)