Skip to content

Commit 6e42a9a

Browse files
committed
clarified semantics of target machine wrapper
1 parent 153a920 commit 6e42a9a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

compiler/rustc_codegen_llvm/src/back/target_machine_wrapper.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use crate::{errors::LlvmError, llvm};
1111

1212
#[repr(transparent)]
1313
pub struct TargetMachineWrapper {
14-
tm: NonNull<llvm::TargetMachine>,
15-
phantom: PhantomData<&'static mut llvm::TargetMachine>,
14+
tm_unique: NonNull<llvm::TargetMachine>,
15+
phantom: PhantomData<llvm::TargetMachine>,
1616
}
1717

1818
impl TargetMachineWrapper {
@@ -74,7 +74,7 @@ impl TargetMachineWrapper {
7474
};
7575

7676
NonNull::new(tm_ptr)
77-
.map(|tm| Self { tm, phantom: PhantomData })
77+
.map(|tm_unique| Self { tm_unique, phantom: PhantomData })
7878
.ok_or_else(|| LlvmError::CreateTargetMachine { triple: SmallCStr::from(triple) })
7979
}
8080
}
@@ -84,7 +84,7 @@ impl Deref for TargetMachineWrapper {
8484

8585
fn deref(&self) -> &Self::Target {
8686
// SAFETY: constructing ensures we have a valid pointer created by llvm::LLVMRustCreateTargetMachine
87-
unsafe { self.tm.as_ref() }
87+
unsafe { self.tm_unique.as_ref() }
8888
}
8989
}
9090

@@ -93,7 +93,7 @@ impl Drop for TargetMachineWrapper {
9393
// SAFETY: constructing ensures we have a valid pointer created by llvm::LLVMRustCreateTargetMachine
9494
// TargetMachineWrapper is not copyable so there is no double free or use after free
9595
unsafe {
96-
llvm::LLVMRustDisposeTargetMachine(self.tm.as_mut());
96+
llvm::LLVMRustDisposeTargetMachine(self.tm_unique.as_mut());
9797
}
9898
}
9999
}

0 commit comments

Comments
 (0)