about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorAndreas Jonson <andjo403@users.noreply.github.com>2021-09-29 22:58:33 +0200
committerAndreas Jonson <andjo403@users.noreply.github.com>2021-09-29 22:58:33 +0200
commitd90934ce87352e7478f8c872a5a65363206082a0 (patch)
treec75fea2291f11880f244d6e77a66c5d10bddb6a4 /compiler/rustc_codegen_llvm/src
parent50f9f7810c975234ce4730488d32661a76a00428 (diff)
downloadrust-d90934ce87352e7478f8c872a5a65363206082a0.tar.gz
rust-d90934ce87352e7478f8c872a5a65363206082a0.zip
Fix use after drop in self-profile with llvm events
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
-rw-r--r--compiler/rustc_codegen_llvm/src/back/write.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs
index 92199f611ba..985640fb60e 100644
--- a/compiler/rustc_codegen_llvm/src/back/write.rs
+++ b/compiler/rustc_codegen_llvm/src/back/write.rs
@@ -405,13 +405,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.