Skip to content

Commit

Permalink
Rollup merge of #89376 - andjo403:selfProfileUseAfterDropFix, r=Mark-…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
fee1-dead authored Oct 1, 2021
2 parents 5a09551 + d90934c commit 01762f6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,15 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
None
};

let llvm_selfprofiler = if cgcx.prof.llvm_recording_enabled() {
let mut llvm_profiler = LlvmSelfProfiler::new(cgcx.prof.get_self_profiler().unwrap());
&mut llvm_profiler as *mut _ as *mut c_void
let mut llvm_profiler = if cgcx.prof.llvm_recording_enabled() {
Some(LlvmSelfProfiler::new(cgcx.prof.get_self_profiler().unwrap()))
} else {
std::ptr::null_mut()
None
};

let llvm_selfprofiler =
llvm_profiler.as_mut().map(|s| s as *mut _ as *mut c_void).unwrap_or(std::ptr::null_mut());

let extra_passes = config.passes.join(",");

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

0 comments on commit 01762f6

Please sign in to comment.