Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,7 @@ fn fat_lto(
let data = bc_decoded.data();

unsafe {
if !llvm::LLVMRustLinkerAdd(
linker,
data.as_ptr() as *const libc::c_char,
data.len(),
) {
if !llvm::LLVMRustLinkerAdd(linker, data.as_ptr(), data.len()) {
llvm::LLVMRustLinkerFree(linker);
write::llvm_err(dcx, LlvmError::LoadBitcode { name })
}
Expand All @@ -327,10 +323,9 @@ fn fat_lto(

// Internalize everything below threshold to help strip out more modules and such.
unsafe {
let ptr = symbols_below_threshold.as_ptr();
llvm::LLVMRustRunRestrictionPass(
llmod,
ptr as *const *const libc::c_char,
symbols_below_threshold.as_ptr(),
symbols_below_threshold.len() as libc::size_t,
);
}
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_codegen_llvm/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,20 +470,14 @@ pub(crate) fn val_ty(v: &Value) -> &Type {
}

pub(crate) fn bytes_in_context<'ll>(llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
unsafe {
let ptr = bytes.as_ptr() as *const c_char;
llvm::LLVMConstStringInContext2(llcx, ptr, bytes.len(), TRUE)
}
unsafe { llvm::LLVMConstStringInContext2(llcx, bytes.as_ptr(), bytes.len(), TRUE) }
}

pub(crate) fn null_terminate_bytes_in_context<'ll>(
llcx: &'ll llvm::Context,
bytes: &[u8],
) -> &'ll Value {
unsafe {
let ptr = bytes.as_ptr() as *const c_char;
llvm::LLVMConstStringInContext2(llcx, ptr, bytes.len(), FALSE)
}
unsafe { llvm::LLVMConstStringInContext2(llcx, bytes.as_ptr(), bytes.len(), FALSE) }
}

pub(crate) fn named_struct<'ll>(ty: &'ll Type, elts: &[&'ll Value]) -> &'ll Value {
Expand Down
14 changes: 3 additions & 11 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::{Borrow, Cow};
use std::cell::{Cell, RefCell};
use std::ffi::{CStr, c_char, c_uint};
use std::ffi::{CStr, c_uint};
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
use std::str;
Expand Down Expand Up @@ -911,19 +911,11 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
}

pub(crate) fn get_md_kind_id(&self, name: &str) -> llvm::MetadataKindId {
unsafe {
llvm::LLVMGetMDKindIDInContext(
self.llcx(),
name.as_ptr() as *const c_char,
name.len() as c_uint,
)
}
unsafe { llvm::LLVMGetMDKindIDInContext(self.llcx(), name.as_ptr(), name.len() as c_uint) }
}

pub(crate) fn create_metadata(&self, name: &[u8]) -> &'ll Metadata {
unsafe {
llvm::LLVMMDStringInContext2(self.llcx(), name.as_ptr() as *const c_char, name.len())
}
unsafe { llvm::LLVMMDStringInContext2(self.llcx(), name.as_ptr(), name.len()) }
}

pub(crate) fn get_functions(&self) -> Vec<&'ll Value> {
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,7 @@ pub(crate) mod Enzyme_AD {
let c_fun_name = std::ffi::CString::new(fun_name)
.unwrap_or_else(|err| bug!("failed to set_print_type_fun: {err}"));
unsafe {
(self.EnzymeSetCLString)(
self.EnzymeFunctionToAnalyze,
c_fun_name.as_ptr() as *const c_char,
);
(self.EnzymeSetCLString)(self.EnzymeFunctionToAnalyze, c_fun_name.as_ptr());
}
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ unsafe extern "C" {
pub(crate) fn LLVMContextSetDiscardValueNames(C: &Context, Discard: Bool);
pub(crate) fn LLVMGetMDKindIDInContext(
C: &Context,
Name: *const c_char,
Name: *const c_uchar, // See "PTR_LEN_STR".
SLen: c_uint,
) -> MetadataKindId;

Expand Down Expand Up @@ -1009,7 +1009,7 @@ unsafe extern "C" {
// Operations on metadata
pub(crate) fn LLVMMDStringInContext2(
C: &Context,
Str: *const c_char,
Str: *const c_uchar, // See "PTR_LEN_STR".
SLen: size_t,
) -> &Metadata;
pub(crate) fn LLVMMDNodeInContext2<'a>(
Expand Down Expand Up @@ -1042,7 +1042,7 @@ unsafe extern "C" {
pub(crate) fn LLVMArrayType2(ElementType: &Type, ElementCount: u64) -> &Type;
pub(crate) fn LLVMConstStringInContext2(
C: &Context,
Str: *const c_char,
Str: *const c_uchar, // See "PTR_LEN_STR".
Length: size_t,
DontNullTerminate: Bool,
) -> &Value;
Expand Down Expand Up @@ -2561,7 +2561,7 @@ unsafe extern "C" {
pub(crate) fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>;
pub(crate) fn LLVMRustLinkerAdd(
linker: &Linker<'_>,
bytecode: *const c_char,
bytecode: *const c_uchar, // See "PTR_LEN_STR".
bytecode_len: usize,
) -> bool;
pub(crate) fn LLVMRustLinkerFree<'a>(linker: &'a mut Linker<'a>);
Expand Down
Loading