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
13 changes: 5 additions & 8 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use crate::back::profiling::{
};
use crate::builder::SBuilder;
use crate::builder::gpu_offload::scalar_width;
use crate::common::AsCCharPtr;
use crate::context::SimpleCx;
use crate::diagnostics::{
CopyBitcode, FromLlvmDiag, FromLlvmOptimizationDiag, LlvmError, ParseTargetMachineConfig,
Expand Down Expand Up @@ -548,9 +547,7 @@ pub(crate) unsafe fn llvm_optimize(
} else {
None
};
let passes_after_enzyme_ptr =
passes_after_enzyme.map_or(std::ptr::null(), |s| s.as_c_char_ptr());
let passes_after_enzyme_len = passes_after_enzyme.map_or(0, |s| s.len());

let merge_functions;
let unroll_loops;
let vectorize_slp;
Expand Down Expand Up @@ -788,11 +785,11 @@ pub(crate) unsafe fn llvm_optimize(
llvm_selfprofiler,
selfprofile_before_pass_callback,
selfprofile_after_pass_callback,
passes_after_enzyme_ptr,
passes_after_enzyme_len,
extra_passes.as_c_char_ptr(),
passes_after_enzyme.map(|s| s.as_ptr()).unwrap_or(std::ptr::null()),
passes_after_enzyme.map(|s| s.len()).unwrap_or(0),
Comment on lines +788 to +789

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for changing from map_or to map().unwrap_or()? I don't care strongly one way or another, but this code used map_or before and the debug info changes in the earlier commit preserved map_or, so this change stood out to me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the other cases I was just updating the call to as_c_char_ptr, so I didn’t even think about whether to change the enclosing map_or or not; I just left it as-is.

For this one I wanted to move the call site, so (after some intermediate edits) I rewrote the calls in the style that comes naturally to me, since I find map_or needlessly confusing.

extra_passes.as_ptr(),
extra_passes.len(),
llvm_plugins.as_c_char_ptr(),
llvm_plugins.as_ptr(),
llvm_plugins.len(),
)
};
Expand Down
17 changes: 9 additions & 8 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use super::CodegenUnitDebugContext;
use super::namespace::mangled_name_of_instance;
use super::type_names::{compute_debuginfo_type_name, compute_debuginfo_vtable_name};
use super::utils::{DIB, debug_context, get_namespace_for_item, is_node_local_to_unit};
use crate::common::{AsCCharPtr, CodegenCx};
use crate::common::CodegenCx;
use crate::debuginfo::metadata::type_map::build_type_with_children;
use crate::debuginfo::utils::{WidePtrKind, create_DIArray, wide_pointer_kind};
use crate::debuginfo::{DIBuilderExt, dwarf_const};
Expand Down Expand Up @@ -651,14 +651,14 @@ fn create_file<'ll>(
unsafe {
llvm::LLVMRustDIBuilderCreateFile(
builder,
file_name.as_c_char_ptr(),
file_name.as_ptr(),
file_name.len(),
directory.as_c_char_ptr(),
directory.as_ptr(),
directory.len(),
hash_kind,
hash_value.as_c_char_ptr(),
hash_value.as_ptr(),
hash_value.len(),
source.map_or(ptr::null(), |x| x.as_c_char_ptr()),
source.map_or(ptr::null(), |x| x.as_ptr()),
source.map_or(0, |x| x.len()),
)
}
Expand Down Expand Up @@ -949,20 +949,21 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
llvm::ChecksumKind::None,
None,
);
let flags = c"";

let unit_metadata = llvm::LLVMRustDIBuilderCreateCompileUnit(
debug_context.builder.as_ref(),
dwarf_const::DW_LANG_Rust,
compile_unit_file,
producer.as_c_char_ptr(),
producer.as_ptr(),
producer.len(),
tcx.sess.opts.optimize != config::OptLevel::No,
c"".as_ptr(),
flags.as_ptr(),
0,
// NB: this doesn't actually have any perceptible effect, it seems. LLVM will instead
// put the path supplied to `MCSplitDwarfFile` into the debug info of the final
// output(s).
split_name.as_c_char_ptr(),
split_name.as_ptr(),
split_name.len(),
kind,
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_span::{Span, Symbol, bug};

use super::type_map::{DINodeCreationResult, UniqueTypeId};
use super::{SmallVec, size_and_align_of};
use crate::common::{AsCCharPtr, CodegenCx};
use crate::common::CodegenCx;
use crate::debuginfo::metadata::type_map::{self, Stub};
use crate::debuginfo::metadata::{
UNKNOWN_LINE_NUMBER, build_field_di_node, build_generic_type_param_di_nodes,
Expand Down Expand Up @@ -141,7 +141,7 @@ fn build_enumeration_type_di_node<'ll, 'tcx>(
llvm::LLVMRustDIBuilderCreateEnumerationType(
DIB(cx),
containing_scope,
type_name.as_c_char_ptr(),
type_name.as_ptr(),
type_name.len(),
file_metadata,
line_number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
use rustc_span::bug;
use smallvec::smallvec;

use crate::common::{AsCCharPtr, CodegenCx};
use crate::common::CodegenCx;
use crate::debuginfo::metadata::type_map::{self, Stub, StubInfo, UniqueTypeId};
use crate::debuginfo::metadata::{
DINodeCreationResult, NO_GENERICS, SmallVec, UNKNOWN_LINE_NUMBER, create_member_type,
Expand Down Expand Up @@ -284,7 +284,7 @@ fn build_enum_variant_part_di_node<'ll, 'tcx>(
llvm::LLVMRustDIBuilderCreateVariantPart(
DIB(cx),
enum_type_di_node,
variant_part_name.as_c_char_ptr(),
variant_part_name.as_ptr(),
variant_part_name.len(),
file_metadata,
line_number,
Expand All @@ -293,7 +293,7 @@ fn build_enum_variant_part_di_node<'ll, 'tcx>(
DIFlags::FlagZero,
tag_member_di_node,
create_DIArray(DIB(cx), &[]),
variant_part_unique_type_id_str.as_c_char_ptr(),
variant_part_unique_type_id_str.as_ptr(),
variant_part_unique_type_id_str.len(),
)
},
Expand Down Expand Up @@ -444,7 +444,7 @@ fn build_enum_variant_member_di_node<'ll, 'tcx>(
llvm::LLVMRustDIBuilderCreateVariantMemberType(
DIB(cx),
variant_part_di_node,
variant_member_info.variant_name.as_c_char_ptr(),
variant_member_info.variant_name.as_ptr(),
variant_member_info.variant_name.len(),
file_di_node,
line_number,
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use self::metadata::{
use self::namespace::mangled_name_of_instance;
use self::utils::{DIB, create_DIArray, is_node_local_to_unit};
use crate::builder::Builder;
use crate::common::{AsCCharPtr, CodegenCx};
use crate::common::CodegenCx;
use crate::debuginfo::di_builder::DIBuilderBox;
use crate::llvm::debuginfo::{
DIArray, DIFile, DIFlags, DILexicalBlock, DILocation, DISPFlags, DIScope,
Expand Down Expand Up @@ -197,9 +197,9 @@ impl<'ll, 'tcx> DebugInfoBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
llvm::LLVMRustDIBuilderCreateMethod(
DIB(self),
containing_scope,
name.as_c_char_ptr(),
name.as_ptr(),
name.len(),
linkage_name.as_c_char_ptr(),
linkage_name.as_ptr(),
linkage_name.len(),
file_metadata,
loc.line,
Expand All @@ -214,9 +214,9 @@ impl<'ll, 'tcx> DebugInfoBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
llvm::LLVMRustDIBuilderCreateFunction(
DIB(self),
containing_scope,
name.as_c_char_ptr(),
name.as_ptr(),
name.len(),
linkage_name.as_c_char_ptr(),
linkage_name.as_ptr(),
linkage_name.len(),
file_metadata,
loc.line,
Expand Down Expand Up @@ -716,7 +716,7 @@ impl<'ll> CodegenCx<'ll, '_> {
llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
DIB(self),
None,
name.as_c_char_ptr(),
name.as_ptr(),
name.len(),
actual_type_metadata,
)
Expand Down
15 changes: 4 additions & 11 deletions compiler/rustc_codegen_llvm/src/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use tracing::debug;

use crate::abi::FnAbiLlvmExt;
use crate::attributes;
use crate::common::AsCCharPtr;
use crate::context::{CodegenCx, GenericCx, SCx, SimpleCx};
use crate::llvm::AttributePlace::Function;
use crate::llvm::{self, FromGeneric, Type, Value, Visibility};
Expand All @@ -43,8 +42,7 @@ pub(crate) fn declare_simple_fn<'ll>(
ty: &'ll Type,
) -> &'ll Value {
debug!("declare_simple_fn(name={:?}, ty={:?})", name, ty);
let llfn =
unsafe { llvm::LLVMGetOrInsertFunction(cx.llmod, name.as_c_char_ptr(), name.len(), ty) };
let llfn = unsafe { llvm::LLVMGetOrInsertFunction(cx.llmod, name.as_ptr(), name.len(), ty) };

llvm::SetFunctionCallConv(llfn, callconv);
llvm::set_unnamed_address(llfn, unnamed);
Expand Down Expand Up @@ -96,12 +94,7 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
pub(crate) fn declare_global(&self, name: &str, ty: &'ll Type) -> &'ll Value {
debug!("declare_global(name={:?})", name);
unsafe {
llvm::LLVMRustGetOrInsertGlobal(
(**self).borrow().llmod,
name.as_c_char_ptr(),
name.len(),
ty,
)
llvm::LLVMRustGetOrInsertGlobal((**self).borrow().llmod, name.as_ptr(), name.len(), ty)
}
}

Expand All @@ -119,7 +112,7 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
unsafe {
llvm::LLVMRustGetOrInsertGlobalInAddrspace(
(**self).borrow().llmod,
name.as_c_char_ptr(),
name.as_ptr(),
name.len(),
ty,
addr_space.0,
Expand Down Expand Up @@ -261,7 +254,7 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
/// Gets declared value by name.
pub(crate) fn get_declared_value(&self, name: &str) -> Option<&'ll Value> {
debug!("get_declared_value(name={:?})", name);
unsafe { llvm::LLVMRustGetNamedValue(self.llmod(), name.as_c_char_ptr(), name.len()) }
unsafe { llvm::LLVMRustGetNamedValue(self.llmod(), name.as_ptr(), name.len()) }
}

/// Gets defined or externally defined (AvailableExternally linkage) value by
Expand Down
44 changes: 22 additions & 22 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ unsafe extern "C" {
pub(crate) fn LLVMDeleteFunction(Fn: &Value);
pub(crate) fn LLVMGetOrInsertFunction<'a>(
M: &'a Module,
Name: *const c_char,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
FunctionTy: &'a Type,
) -> &'a Value;
Expand Down Expand Up @@ -1992,20 +1992,20 @@ unsafe extern "C" {
// Operations on global variables
pub(crate) fn LLVMRustGetOrInsertGlobal<'a>(
M: &'a Module,
Name: *const c_char,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
T: &'a Type,
) -> &'a Value;
pub(crate) fn LLVMRustGetOrInsertGlobalInAddrspace<'a>(
M: &'a Module,
Name: *const c_char,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
T: &'a Type,
AddressSpace: c_uint,
) -> &'a Value;
pub(crate) fn LLVMRustGetNamedValue(
M: &Module,
Name: *const c_char,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
) -> Option<&Value>;

Expand Down Expand Up @@ -2207,12 +2207,12 @@ unsafe extern "C" {
Builder: &DIBuilder<'a>,
Lang: c_uint,
File: &'a DIFile,
Producer: *const c_char,
Producer: *const c_uchar, // See "PTR_LEN_STR".
ProducerLen: size_t,
isOptimized: bool,
Flags: *const c_char,
RuntimeVer: c_uint,
SplitName: *const c_char,
SplitName: *const c_uchar, // See "PTR_LEN_STR".
SplitNameLen: size_t,
kind: DebugEmissionKind,
DWOId: u64,
Expand All @@ -2224,14 +2224,14 @@ unsafe extern "C" {
/// _requires_ a checksum, but we sometimes don't provide one.
pub(crate) fn LLVMRustDIBuilderCreateFile<'a>(
Builder: &DIBuilder<'a>,
Filename: *const c_char,
Filename: *const c_uchar, // See "PTR_LEN_STR".
FilenameLen: size_t,
Directory: *const c_char,
Directory: *const c_uchar, // See "PTR_LEN_STR".
DirectoryLen: size_t,
CSKind: ChecksumKind,
Checksum: *const c_char,
Checksum: *const c_uchar, // See "PTR_LEN_STR".
ChecksumLen: size_t,
Source: *const c_char,
Source: *const c_uchar, // See "PTR_LEN_STR".
SourceLen: size_t,
) -> &'a DIFile;

Expand All @@ -2240,9 +2240,9 @@ unsafe extern "C" {
pub(crate) fn LLVMRustDIBuilderCreateFunction<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIDescriptor,
Name: *const c_char,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
LinkageName: *const c_char,
LinkageName: *const c_uchar, // See "PTR_LEN_STR".
LinkageNameLen: size_t,
File: &'a DIFile,
LineNo: c_uint,
Expand All @@ -2259,9 +2259,9 @@ unsafe extern "C" {
pub(crate) fn LLVMRustDIBuilderCreateMethod<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIDescriptor,
Name: *const c_char,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
LinkageName: *const c_char,
LinkageName: *const c_uchar, // See "PTR_LEN_STR".
LinkageNameLen: size_t,
File: &'a DIFile,
LineNo: c_uint,
Expand All @@ -2275,7 +2275,7 @@ unsafe extern "C" {
pub(crate) fn LLVMRustDIBuilderCreateVariantMemberType<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIScope,
Name: *const c_char,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
File: &'a DIFile,
LineNumber: c_uint,
Expand All @@ -2291,7 +2291,7 @@ unsafe extern "C" {
pub(crate) fn LLVMRustDIBuilderCreateEnumerationType<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIScope,
Name: *const c_char,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
File: &'a DIFile,
LineNumber: c_uint,
Expand All @@ -2306,7 +2306,7 @@ unsafe extern "C" {
pub(crate) fn LLVMRustDIBuilderCreateVariantPart<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIScope,
Name: *const c_char,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
File: &'a DIFile,
LineNo: c_uint,
Expand All @@ -2315,15 +2315,15 @@ unsafe extern "C" {
Flags: DIFlags,
Discriminator: Option<&'a DIDerivedType>,
Elements: &'a DIArray,
UniqueId: *const c_char,
UniqueId: *const c_uchar, // See "PTR_LEN_STR".
UniqueIdLen: size_t,
) -> &'a DIDerivedType;

/// As of LLVM 22 there is no corresponding LLVM-C function.
pub(crate) fn LLVMRustDIBuilderCreateTemplateTypeParameter<'a>(
Builder: &DIBuilder<'a>,
Scope: Option<&'a DIScope>,
Name: *const c_char,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
Ty: &'a DIType,
) -> &'a DITemplateTypeParameter;
Expand Down Expand Up @@ -2462,11 +2462,11 @@ unsafe extern "C" {
llvm_selfprofiler: *mut c_void,
begin_callback: SelfProfileBeforePassCallback,
end_callback: SelfProfileAfterPassCallback,
PostEnzymePasses: *const c_char,
PostEnzymePasses: *const c_uchar, // See "PTR_LEN_STR".
PostEnzymePassesLen: size_t,
ExtraPasses: *const c_char,
ExtraPasses: *const c_uchar, // See "PTR_LEN_STR".
ExtraPassesLen: size_t,
LLVMPlugins: *const c_char,
LLVMPlugins: *const c_uchar, // See "PTR_LEN_STR".
LLVMPluginsLen: size_t,
) -> LLVMRustResult;
pub(crate) fn LLVMRustPrintModule(
Expand Down
Loading