Rollup merge of #145432 - Zalathar:target-machine, r=wesleywiser
cg_llvm: Small cleanups to `owned_target_machine` This PR contains a few tiny cleanups to the `owned_target_machine` code. Each individual commit should be fairly straightforward.
This commit is contained in:
5
compiler/rustc_codegen_llvm/src/back/mod.rs
Normal file
5
compiler/rustc_codegen_llvm/src/back/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
pub(crate) mod archive;
|
||||
pub(crate) mod lto;
|
||||
pub(crate) mod owned_target_machine;
|
||||
mod profiling;
|
||||
pub(crate) mod write;
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::ffi::{CStr, c_char};
|
||||
use std::assert_matches::assert_matches;
|
||||
use std::ffi::CStr;
|
||||
use std::marker::PhantomData;
|
||||
use std::ptr::NonNull;
|
||||
|
||||
@@ -41,11 +42,9 @@ impl OwnedTargetMachine {
|
||||
args_cstr_buff: &[u8],
|
||||
use_wasm_eh: bool,
|
||||
) -> Result<Self, LlvmError<'static>> {
|
||||
assert!(args_cstr_buff.len() > 0);
|
||||
assert!(
|
||||
*args_cstr_buff.last().unwrap() == 0,
|
||||
"The last character must be a null terminator."
|
||||
);
|
||||
// The argument list is passed as the concatenation of one or more C strings.
|
||||
// This implies that there must be a last byte, and it must be 0.
|
||||
assert_matches!(args_cstr_buff, [.., b'\0'], "the last byte must be a NUL terminator");
|
||||
|
||||
// SAFETY: llvm::LLVMRustCreateTargetMachine copies pointed to data
|
||||
let tm_ptr = unsafe {
|
||||
@@ -71,7 +70,7 @@ impl OwnedTargetMachine {
|
||||
output_obj_file.as_ptr(),
|
||||
debug_info_compression.as_ptr(),
|
||||
use_emulated_tls,
|
||||
args_cstr_buff.as_ptr() as *const c_char,
|
||||
args_cstr_buff.as_ptr(),
|
||||
args_cstr_buff.len(),
|
||||
use_wasm_eh,
|
||||
)
|
||||
@@ -99,7 +98,7 @@ impl Drop for OwnedTargetMachine {
|
||||
// llvm::LLVMRustCreateTargetMachine OwnedTargetMachine is not copyable so there is no
|
||||
// double free or use after free.
|
||||
unsafe {
|
||||
llvm::LLVMRustDisposeTargetMachine(self.tm_unique.as_mut());
|
||||
llvm::LLVMRustDisposeTargetMachine(self.tm_unique.as_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,18 +46,11 @@ use rustc_session::Session;
|
||||
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
|
||||
use rustc_span::Symbol;
|
||||
|
||||
mod back {
|
||||
pub(crate) mod archive;
|
||||
pub(crate) mod lto;
|
||||
pub(crate) mod owned_target_machine;
|
||||
mod profiling;
|
||||
pub(crate) mod write;
|
||||
}
|
||||
|
||||
mod abi;
|
||||
mod allocator;
|
||||
mod asm;
|
||||
mod attributes;
|
||||
mod back;
|
||||
mod base;
|
||||
mod builder;
|
||||
mod callee;
|
||||
|
||||
@@ -2443,7 +2443,7 @@ unsafe extern "C" {
|
||||
OutputObjFile: *const c_char,
|
||||
DebugInfoCompression: *const c_char,
|
||||
UseEmulatedTls: bool,
|
||||
ArgsCstrBuff: *const c_char,
|
||||
ArgsCstrBuff: *const c_uchar, // See "PTR_LEN_STR".
|
||||
ArgsCstrBuffLen: usize,
|
||||
UseWasmEH: bool,
|
||||
) -> *mut TargetMachine;
|
||||
|
||||
Reference in New Issue
Block a user