Skip to content

Commit 89d5d37

Browse files
committed
Prevent compiler from optimizing away reference assignment
1 parent 1258959 commit 89d5d37

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

vhdl_lang/src/analysis/named_entity.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ impl<'a> AnyEnt<'a> {
410410

411411
#[allow(clippy::mut_from_ref)]
412412
unsafe fn unsafe_ref_mut(&self) -> &mut Self {
413-
let mut_self: *mut AnyEnt = self as *const AnyEnt as *mut AnyEnt;
413+
// NOTE: Use read_volatile to prevent compiler to optimization away assignment to the returned reference
414+
let mut_self: *mut AnyEnt = std::ptr::read_volatile(&self) as *const AnyEnt as *mut AnyEnt;
414415
&mut *mut_self
415416
}
416417

0 commit comments

Comments
 (0)