diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index a95f259545982..5bbe1c887a939 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -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, @@ -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; @@ -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), + extra_passes.as_ptr(), extra_passes.len(), - llvm_plugins.as_c_char_ptr(), + llvm_plugins.as_ptr(), llvm_plugins.len(), ) }; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index a3bcce34566cb..e14cdeb1505d0 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -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}; @@ -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()), ) } @@ -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, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs index 37f114fc5b09e..c2aa981582aaf 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -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, @@ -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, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs index c0ecb14d21926..c9cac61a8bbe1 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -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, @@ -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, @@ -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(), ) }, @@ -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, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 29448f147d103..99a54f1d74a62 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -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, @@ -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, @@ -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, @@ -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, ) diff --git a/compiler/rustc_codegen_llvm/src/declare.rs b/compiler/rustc_codegen_llvm/src/declare.rs index 23f9fc93a4ba4..78bc5aba450aa 100644 --- a/compiler/rustc_codegen_llvm/src/declare.rs +++ b/compiler/rustc_codegen_llvm/src/declare.rs @@ -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}; @@ -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); @@ -96,12 +94,7 @@ impl<'ll, CX: Borrow>> 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) } } @@ -119,7 +112,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { unsafe { llvm::LLVMRustGetOrInsertGlobalInAddrspace( (**self).borrow().llmod, - name.as_c_char_ptr(), + name.as_ptr(), name.len(), ty, addr_space.0, @@ -261,7 +254,7 @@ impl<'ll, CX: Borrow>> 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 diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 4c7d60a0cbf67..f9718834fb846 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -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; @@ -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>; @@ -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, @@ -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; @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -2315,7 +2315,7 @@ 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; @@ -2323,7 +2323,7 @@ unsafe extern "C" { 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; @@ -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(