Skip to content

Commit 6cbe47a

Browse files
authored
Unrolled build for #145432
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.
2 parents b96868f + 9e7d066 commit 6cbe47a

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub(crate) mod archive;
2+
pub(crate) mod lto;
3+
pub(crate) mod owned_target_machine;
4+
mod profiling;
5+
pub(crate) mod write;

compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use std::ffi::{CStr, c_char};
1+
use std::assert_matches::assert_matches;
2+
use std::ffi::CStr;
23
use std::marker::PhantomData;
34
use std::ptr::NonNull;
45

@@ -41,11 +42,9 @@ impl OwnedTargetMachine {
4142
args_cstr_buff: &[u8],
4243
use_wasm_eh: bool,
4344
) -> Result<Self, LlvmError<'static>> {
44-
assert!(args_cstr_buff.len() > 0);
45-
assert!(
46-
*args_cstr_buff.last().unwrap() == 0,
47-
"The last character must be a null terminator."
48-
);
45+
// The argument list is passed as the concatenation of one or more C strings.
46+
// This implies that there must be a last byte, and it must be 0.
47+
assert_matches!(args_cstr_buff, [.., b'\0'], "the last byte must be a NUL terminator");
4948

5049
// SAFETY: llvm::LLVMRustCreateTargetMachine copies pointed to data
5150
let tm_ptr = unsafe {
@@ -71,7 +70,7 @@ impl OwnedTargetMachine {
7170
output_obj_file.as_ptr(),
7271
debug_info_compression.as_ptr(),
7372
use_emulated_tls,
74-
args_cstr_buff.as_ptr() as *const c_char,
73+
args_cstr_buff.as_ptr(),
7574
args_cstr_buff.len(),
7675
use_wasm_eh,
7776
)
@@ -99,7 +98,7 @@ impl Drop for OwnedTargetMachine {
9998
// llvm::LLVMRustCreateTargetMachine OwnedTargetMachine is not copyable so there is no
10099
// double free or use after free.
101100
unsafe {
102-
llvm::LLVMRustDisposeTargetMachine(self.tm_unique.as_mut());
101+
llvm::LLVMRustDisposeTargetMachine(self.tm_unique.as_ptr());
103102
}
104103
}
105104
}

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,11 @@ use rustc_session::Session;
4646
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
4747
use rustc_span::Symbol;
4848

49-
mod back {
50-
pub(crate) mod archive;
51-
pub(crate) mod lto;
52-
pub(crate) mod owned_target_machine;
53-
mod profiling;
54-
pub(crate) mod write;
55-
}
56-
5749
mod abi;
5850
mod allocator;
5951
mod asm;
6052
mod attributes;
53+
mod back;
6154
mod base;
6255
mod builder;
6356
mod callee;

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2443,7 +2443,7 @@ unsafe extern "C" {
24432443
OutputObjFile: *const c_char,
24442444
DebugInfoCompression: *const c_char,
24452445
UseEmulatedTls: bool,
2446-
ArgsCstrBuff: *const c_char,
2446+
ArgsCstrBuff: *const c_uchar, // See "PTR_LEN_STR".
24472447
ArgsCstrBuffLen: usize,
24482448
UseWasmEH: bool,
24492449
) -> *mut TargetMachine;

0 commit comments

Comments
 (0)