diff options
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/abi.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/allocator.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/asm.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/attributes.rs | 30 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/back/write.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/builder.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/consts.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/context.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs | 27 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/debuginfo/mod.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/metadata.rs | 4 |
11 files changed, 56 insertions, 51 deletions
diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index a69241e456f..d714ff1fe9b 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -554,7 +554,7 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> { llvm::AddCallSiteAttrString( callsite, llvm::AttributePlace::Function, - rustc_data_structures::const_cstr!("cmse_nonsecure_call"), + cstr::cstr!("cmse_nonsecure_call"), ); } } diff --git a/compiler/rustc_codegen_llvm/src/allocator.rs b/compiler/rustc_codegen_llvm/src/allocator.rs index a5ea0b2a74c..068e5e99efe 100644 --- a/compiler/rustc_codegen_llvm/src/allocator.rs +++ b/compiler/rustc_codegen_llvm/src/allocator.rs @@ -93,7 +93,7 @@ pub(crate) unsafe fn codegen( let args = [usize, usize]; // size, align let ty = llvm::LLVMFunctionType(void, args.as_ptr(), args.len() as c_uint, False); - let name = "__rust_alloc_error_handler".to_string(); + let name = "__rust_alloc_error_handler"; let llfn = llvm::LLVMRustGetOrInsertFunction(llmod, name.as_ptr().cast(), name.len(), ty); // -> ! DIFlagNoReturn llvm::Attribute::NoReturn.apply_llfn(llvm::AttributePlace::Function, llfn); diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index 8801211d51b..26815de403f 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -61,9 +61,9 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> { // Default per-arch clobbers // Basically what clang does let arch_clobbers = match &self.sess().target.arch[..] { - "x86" | "x86_64" => vec!["~{dirflag}", "~{fpsr}", "~{flags}"], - "mips" | "mips64" => vec!["~{$1}"], - _ => Vec::new(), + "x86" | "x86_64" => &["~{dirflag}", "~{fpsr}", "~{flags}"][..], + "mips" | "mips64" => &["~{$1}"], + _ => &[], }; let all_constraints = ia @@ -487,6 +487,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'tcx>>) } else if reg == InlineAsmReg::AArch64(AArch64InlineAsmReg::x30) { // LLVM doesn't recognize x30 "{lr}".to_string() + } else if reg == InlineAsmReg::Arm(ArmInlineAsmReg::r14) { + // LLVM doesn't recognize r14 + "{lr}".to_string() } else { format!("{{{}}}", reg.name()) } diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 26111729ba5..09ece6164eb 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -2,8 +2,8 @@ use std::ffi::CString; +use cstr::cstr; use rustc_codegen_ssa::traits::*; -use rustc_data_structures::const_cstr; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::small_c_str::SmallCStr; use rustc_hir::def_id::DefId; @@ -75,8 +75,8 @@ pub fn set_frame_pointer_elimination(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("frame-pointer"), - const_cstr!("all"), + cstr!("frame-pointer"), + cstr!("all"), ); } } @@ -95,7 +95,7 @@ fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("instrument-function-entry-inlined"), + cstr!("instrument-function-entry-inlined"), &mcount_name, ); } @@ -129,16 +129,16 @@ fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { StackProbeType::None => None, // Request LLVM to generate the probes inline. If the given LLVM version does not support // this, no probe is generated at all (even if the attribute is specified). - StackProbeType::Inline => Some(const_cstr!("inline-asm")), + StackProbeType::Inline => Some(cstr!("inline-asm")), // Flag our internal `__rust_probestack` function as the stack probe symbol. // This is defined in the `compiler-builtins` crate for each architecture. - StackProbeType::Call => Some(const_cstr!("__rust_probestack")), + StackProbeType::Call => Some(cstr!("__rust_probestack")), // Pick from the two above based on the LLVM version. StackProbeType::InlineOrCall { min_llvm_version_for_inline } => { if llvm_util::get_version() < min_llvm_version_for_inline { - Some(const_cstr!("__rust_probestack")) + Some(cstr!("__rust_probestack")) } else { - Some(const_cstr!("inline-asm")) + Some(cstr!("inline-asm")) } } }; @@ -146,7 +146,7 @@ fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("probe-stack"), + cstr!("probe-stack"), attr_value, ); } @@ -169,7 +169,7 @@ pub fn apply_target_cpu_attr(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("target-cpu"), + cstr!("target-cpu"), target_cpu.as_c_str(), ); } @@ -180,7 +180,7 @@ pub fn apply_tune_cpu_attr(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("tune-cpu"), + cstr!("tune-cpu"), tune_cpu.as_c_str(), ); } @@ -289,7 +289,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty:: Attribute::NoAlias.apply_llfn(llvm::AttributePlace::ReturnValue, llfn); } if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::CMSE_NONSECURE_ENTRY) { - llvm::AddFunctionAttrString(llfn, Function, const_cstr!("cmse_nonsecure_entry")); + llvm::AddFunctionAttrString(llfn, Function, cstr!("cmse_nonsecure_entry")); } sanitize(cx, codegen_fn_attrs.no_sanitize, llfn); @@ -319,7 +319,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty:: llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("target-features"), + cstr!("target-features"), &val, ); } @@ -332,7 +332,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty:: llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("wasm-import-module"), + cstr!("wasm-import-module"), &module, ); @@ -342,7 +342,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty:: llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("wasm-import-name"), + cstr!("wasm-import-name"), &name, ); } diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 8b737c9a2e5..c224da7885b 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -11,6 +11,7 @@ use crate::llvm_util; use crate::type_::Type; use crate::LlvmCodegenBackend; use crate::ModuleLlvm; +use rustc_codegen_ssa::back::link::ensure_removed; use rustc_codegen_ssa::back::write::{ BitcodeSection, CodegenContext, EmitObj, ModuleConfig, TargetMachineFactoryConfig, TargetMachineFactoryFn, @@ -93,7 +94,7 @@ pub fn create_informational_target_machine(sess: &Session) -> &'static mut llvm: pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> &'static mut llvm::TargetMachine { let split_dwarf_file = if tcx.sess.target_can_use_split_dwarf() { tcx.output_filenames(LOCAL_CRATE) - .split_dwarf_filename(tcx.sess.split_debuginfo(), Some(mod_name)) + .split_dwarf_path(tcx.sess.split_debuginfo(), Some(mod_name)) } else { None }; @@ -879,9 +880,7 @@ pub(crate) unsafe fn codegen( if !config.emit_bc { debug!("removing_bitcode {:?}", bc_out); - if let Err(e) = fs::remove_file(&bc_out) { - diag_handler.err(&format!("failed to remove bitcode: {}", e)); - } + ensure_removed(diag_handler, &bc_out); } } diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index d2f4d3edc22..f4852c91e53 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -5,13 +5,13 @@ use crate::llvm::{AtomicOrdering, AtomicRmwBinOp, SynchronizationScope}; use crate::type_::Type; use crate::type_of::LayoutLlvmExt; use crate::value::Value; +use cstr::cstr; use libc::{c_char, c_uint}; use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, TypeKind}; use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue}; use rustc_codegen_ssa::mir::place::PlaceRef; use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::MemFlags; -use rustc_data_structures::const_cstr; use rustc_data_structures::small_c_str::SmallCStr; use rustc_hir::def_id::DefId; use rustc_middle::ty::layout::TyAndLayout; @@ -979,7 +979,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } fn cleanup_pad(&mut self, parent: Option<&'ll Value>, args: &[&'ll Value]) -> Funclet<'ll> { - let name = const_cstr!("cleanuppad"); + let name = cstr!("cleanuppad"); let ret = unsafe { llvm::LLVMRustBuildCleanupPad( self.llbuilder, @@ -1003,7 +1003,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } fn catch_pad(&mut self, parent: &'ll Value, args: &[&'ll Value]) -> Funclet<'ll> { - let name = const_cstr!("catchpad"); + let name = cstr!("catchpad"); let ret = unsafe { llvm::LLVMRustBuildCatchPad( self.llbuilder, @@ -1022,7 +1022,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { unwind: Option<&'ll BasicBlock>, num_handlers: usize, ) -> &'ll Value { - let name = const_cstr!("catchswitch"); + let name = cstr!("catchswitch"); let ret = unsafe { llvm::LLVMRustBuildCatchSwitch( self.llbuilder, diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 16e1a8a1242..99046839973 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -5,9 +5,9 @@ use crate::llvm::{self, True}; use crate::type_::Type; use crate::type_of::LayoutLlvmExt; use crate::value::Value; +use cstr::cstr; use libc::c_uint; use rustc_codegen_ssa::traits::*; -use rustc_data_structures::const_cstr; use rustc_hir::def_id::DefId; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_middle::mir::interpret::{ @@ -419,9 +419,9 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> { .all(|&byte| byte == 0); let sect_name = if all_bytes_are_zero { - const_cstr!("__DATA,__thread_bss") + cstr!("__DATA,__thread_bss") } else { - const_cstr!("__DATA,__thread_data") + cstr!("__DATA,__thread_data") }; llvm::LLVMSetSection(g, sect_name.as_ptr()); } diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index ee099f93258..3ddc7424202 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -7,10 +7,10 @@ use crate::llvm_util; use crate::type_::Type; use crate::value::Value; +use cstr::cstr; use rustc_codegen_ssa::base::wants_msvc_seh; use rustc_codegen_ssa::traits::*; use rustc_data_structures::base_n; -use rustc_data_structures::const_cstr; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::small_c_str::SmallCStr; use rustc_middle::bug; @@ -414,8 +414,8 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> { } fn create_used_variable(&self) { - let name = const_cstr!("llvm.used"); - let section = const_cstr!("llvm.metadata"); + let name = cstr!("llvm.used"); + let section = cstr!("llvm.metadata"); let array = self.const_array(&self.type_ptr_to(self.type_i8()), &*self.used_statics.borrow()); diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 6e7c0b3e347..85d1b702399 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -18,8 +18,8 @@ use crate::llvm::debuginfo::{ }; use crate::value::Value; +use cstr::cstr; use rustc_codegen_ssa::traits::*; -use rustc_data_structures::const_cstr; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; @@ -979,7 +979,7 @@ pub fn compile_unit_metadata( // The OSX linker has an idiosyncrasy where it will ignore some debuginfo // if multiple object files with the same `DW_AT_name` are linked together. // As a workaround we generate unique names for each object file. Those do - // not correspond to an actual source file but that should be harmless. + // not correspond to an actual source file but that is harmless. if tcx.sess.target.is_like_osx { name_in_debuginfo.push("@"); name_in_debuginfo.push(codegen_unit_name); @@ -992,17 +992,17 @@ pub fn compile_unit_metadata( let producer = format!("clang LLVM ({})", rustc_producer); let name_in_debuginfo = name_in_debuginfo.to_string_lossy(); + let work_dir = tcx.sess.working_dir.0.to_string_lossy(); let flags = "\0"; - let out_dir = &tcx.output_filenames(LOCAL_CRATE).out_directory; let split_name = if tcx.sess.target_can_use_split_dwarf() { tcx.output_filenames(LOCAL_CRATE) - .split_dwarf_filename(tcx.sess.split_debuginfo(), Some(codegen_unit_name)) + .split_dwarf_path(tcx.sess.split_debuginfo(), Some(codegen_unit_name)) + .map(|f| out_dir.join(f)) } else { None } .unwrap_or_default(); - let out_dir = out_dir.to_str().unwrap(); let split_name = split_name.to_str().unwrap(); // FIXME(#60020): @@ -1024,12 +1024,12 @@ pub fn compile_unit_metadata( assert!(tcx.sess.opts.debuginfo != DebugInfo::None); unsafe { - let file_metadata = llvm::LLVMRustDIBuilderCreateFile( + let compile_unit_file = llvm::LLVMRustDIBuilderCreateFile( debug_context.builder, name_in_debuginfo.as_ptr().cast(), name_in_debuginfo.len(), - out_dir.as_ptr().cast(), - out_dir.len(), + work_dir.as_ptr().cast(), + work_dir.len(), llvm::ChecksumKind::None, ptr::null(), 0, @@ -1038,12 +1038,15 @@ pub fn compile_unit_metadata( let unit_metadata = llvm::LLVMRustDIBuilderCreateCompileUnit( debug_context.builder, DW_LANG_RUST, - file_metadata, + compile_unit_file, producer.as_ptr().cast(), producer.len(), tcx.sess.opts.optimize != config::OptLevel::No, flags.as_ptr().cast(), 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_ptr().cast(), split_name.len(), kind, @@ -1072,7 +1075,7 @@ pub fn compile_unit_metadata( gcov_cu_info.len() as c_uint, ); - let llvm_gcov_ident = const_cstr!("llvm.gcov"); + let llvm_gcov_ident = cstr!("llvm.gcov"); llvm::LLVMAddNamedMetadataOperand( debug_context.llmod, llvm_gcov_ident.as_ptr(), @@ -1090,7 +1093,7 @@ pub fn compile_unit_metadata( ); llvm::LLVMAddNamedMetadataOperand( debug_context.llmod, - const_cstr!("llvm.ident").as_ptr(), + cstr!("llvm.ident").as_ptr(), llvm::LLVMMDNodeInContext(debug_context.llcontext, &name_metadata, 1), ); } @@ -2369,7 +2372,7 @@ fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> &'ll DIAr fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> { let mut names = generics .parent - .map_or(vec![], |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id))); + .map_or_else(Vec::new, |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id))); names.extend(generics.params.iter().map(|param| param.name)); names } diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 955e739b2c1..c28b0d64651 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -481,9 +481,9 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { } fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> { - let mut names = generics - .parent - .map_or(vec![], |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id))); + let mut names = generics.parent.map_or_else(Vec::new, |def_id| { + get_parameter_names(cx, cx.tcx.generics_of(def_id)) + }); names.extend(generics.params.iter().map(|param| param.name)); names } diff --git a/compiler/rustc_codegen_llvm/src/metadata.rs b/compiler/rustc_codegen_llvm/src/metadata.rs index 3912d6a3a48..b007df57306 100644 --- a/compiler/rustc_codegen_llvm/src/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/metadata.rs @@ -65,8 +65,8 @@ fn search_meta_section<'a>( while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False { let mut name_buf = None; let name_len = llvm::LLVMRustGetSectionName(si.llsi, &mut name_buf); - let name = name_buf.map_or( - String::new(), // We got a NULL ptr, ignore `name_len`. + let name = name_buf.map_or_else( + String::new, // We got a NULL ptr, ignore `name_len`. |buf| { String::from_utf8( slice::from_raw_parts(buf.as_ptr() as *const u8, name_len as usize) |
