Skip to content

Commit 01762f6

Browse files
authored
Rollup merge of #89376 - andjo403:selfProfileUseAfterDropFix, r=Mark-Simulacrum
Fix use after drop in self-profile with llvm events self-profile with `-Z self-profile-events=llvm` have failed with a segmentation fault due to this use after drop. this type of events can be more useful now that the new passmanager is the default.
2 parents 5a09551 + d90934c commit 01762f6

File tree

1 file changed

+6
-4
lines changed
  • compiler/rustc_codegen_llvm/src/back

1 file changed

+6
-4
lines changed

Diff for: compiler/rustc_codegen_llvm/src/back/write.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,15 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
406406
None
407407
};
408408

409-
let llvm_selfprofiler = if cgcx.prof.llvm_recording_enabled() {
410-
let mut llvm_profiler = LlvmSelfProfiler::new(cgcx.prof.get_self_profiler().unwrap());
411-
&mut llvm_profiler as *mut _ as *mut c_void
409+
let mut llvm_profiler = if cgcx.prof.llvm_recording_enabled() {
410+
Some(LlvmSelfProfiler::new(cgcx.prof.get_self_profiler().unwrap()))
412411
} else {
413-
std::ptr::null_mut()
412+
None
414413
};
415414

415+
let llvm_selfprofiler =
416+
llvm_profiler.as_mut().map(|s| s as *mut _ as *mut c_void).unwrap_or(std::ptr::null_mut());
417+
416418
let extra_passes = config.passes.join(",");
417419

418420
// FIXME: NewPM doesn't provide a facility to pass custom InlineParams.

0 commit comments

Comments
 (0)