Skip to content

Commit

Permalink
Make TimingGuard a little safer
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Jan 7, 2025
1 parent a28b986 commit 0335dc1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ impl Drop for TimingGuard {

impl cranelift_codegen::timing::Profiler for MeasuremeProfiler {
fn start_pass(&self, pass: cranelift_codegen::timing::Pass) -> Box<dyn std::any::Any> {
let mut timing_guard =
TimingGuard { profiler: std::mem::ManuallyDrop::new(self.0.clone()), inner: None };
let mut timing_guard = Box::new(TimingGuard {
profiler: std::mem::ManuallyDrop::new(self.0.clone()),
inner: None,
});
timing_guard.inner = Some(
unsafe { &*(&*timing_guard.profiler as &SelfProfilerRef as *const SelfProfilerRef) }
.generic_activity(pass.description()),
);
Box::new(timing_guard)
timing_guard
}
}

0 comments on commit 0335dc1

Please sign in to comment.