diff options
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
42 files changed, 472 insertions, 510 deletions
diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index d034f9b5256..b8f42031263 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -1,12 +1,6 @@ -use crate::attributes; -use crate::builder::Builder; -use crate::context::CodegenCx; -use crate::llvm::{self, Attribute, AttributePlace}; -use crate::llvm_util; -use crate::type_::Type; -use crate::type_of::LayoutLlvmExt; -use crate::value::Value; +use std::cmp; +use libc::c_uint; use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue}; use rustc_codegen_ssa::mir::place::{PlaceRef, PlaceValue}; use rustc_codegen_ssa::traits::*; @@ -20,11 +14,15 @@ pub use rustc_target::abi::call::*; use rustc_target::abi::{self, HasDataLayout, Int, Size}; pub use rustc_target::spec::abi::Abi; use rustc_target::spec::SanitizerSet; - -use libc::c_uint; use smallvec::SmallVec; -use std::cmp; +use crate::builder::Builder; +use crate::context::CodegenCx; +use crate::llvm::{self, Attribute, AttributePlace}; +use crate::type_::Type; +use crate::type_of::LayoutLlvmExt; +use crate::value::Value; +use crate::{attributes, llvm_util}; pub trait ArgAttributesExt { fn apply_attrs_to_llfn(&self, idx: AttributePlace, cx: &CodegenCx<'_, '_>, llfn: &Value); @@ -121,8 +119,10 @@ impl LlvmType for Reg { match self.kind { RegKind::Integer => cx.type_ix(self.size.bits()), RegKind::Float => match self.size.bits() { + 16 => cx.type_f16(), 32 => cx.type_f32(), 64 => cx.type_f64(), + 128 => cx.type_f128(), _ => bug!("unsupported float: {:?}", self), }, RegKind::Vector => cx.type_vector(cx.type_i8(), self.size.bytes()), diff --git a/compiler/rustc_codegen_llvm/src/allocator.rs b/compiler/rustc_codegen_llvm/src/allocator.rs index 5969d9b9144..8fb31082793 100644 --- a/compiler/rustc_codegen_llvm/src/allocator.rs +++ b/compiler/rustc_codegen_llvm/src/allocator.rs @@ -1,4 +1,3 @@ -use crate::attributes; use libc::c_uint; use rustc_ast::expand::allocator::{ alloc_error_handler_name, default_fn_name, global_fn_name, AllocatorKind, AllocatorTy, @@ -8,9 +7,8 @@ use rustc_middle::bug; use rustc_middle::ty::TyCtxt; use rustc_session::config::{DebugInfo, OomStrategy}; -use crate::debuginfo; use crate::llvm::{self, Context, False, Module, True, Type}; -use crate::ModuleLlvm; +use crate::{attributes, debuginfo, ModuleLlvm}; pub(crate) unsafe fn codegen( tcx: TyCtxt<'_>, diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index 597ebd97365..aea8395441a 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -1,25 +1,24 @@ -use crate::attributes; -use crate::builder::Builder; -use crate::common::Funclet; -use crate::context::CodegenCx; -use crate::llvm; -use crate::type_::Type; -use crate::type_of::LayoutLlvmExt; -use crate::value::Value; - +use libc::{c_char, c_uint}; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_codegen_ssa::mir::operand::OperandValue; use rustc_codegen_ssa::traits::*; use rustc_data_structures::fx::FxHashMap; use rustc_middle::ty::layout::TyAndLayout; -use rustc_middle::{bug, span_bug, ty::Instance}; +use rustc_middle::ty::Instance; +use rustc_middle::{bug, span_bug}; use rustc_span::{sym, Pos, Span, Symbol}; use rustc_target::abi::*; use rustc_target::asm::*; +use smallvec::SmallVec; use tracing::debug; -use libc::{c_char, c_uint}; -use smallvec::SmallVec; +use crate::builder::Builder; +use crate::common::Funclet; +use crate::context::CodegenCx; +use crate::type_::Type; +use crate::type_of::LayoutLlvmExt; +use crate::value::Value; +use crate::{attributes, llvm}; impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { fn codegen_inline_asm( diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 3877460fcdb..ad38814a68b 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -1,23 +1,21 @@ //! Set and unset common attributes on LLVM values. +pub use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr}; use rustc_codegen_ssa::traits::*; use rustc_hir::def_id::DefId; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, PatchableFunctionEntry}; use rustc_middle::ty::{self, TyCtxt}; -use rustc_session::config::{FunctionReturn, OptLevel}; +use rustc_session::config::{BranchProtection, FunctionReturn, OptLevel, PAuthKey, PacRet}; use rustc_span::symbol::sym; use rustc_target::spec::{FramePointer, SanitizerSet, StackProbeType, StackProtector}; use smallvec::SmallVec; -use crate::attributes; +use crate::context::CodegenCx; use crate::errors::{MissingFeatures, SanitizerMemtagRequiresMte, TargetFeatureDisableOrEnable}; use crate::llvm::AttributePlace::Function; use crate::llvm::{self, AllocKindFlags, Attribute, AttributeKind, AttributePlace, MemoryEffects}; -use crate::llvm_util; -pub use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr}; - -use crate::context::CodegenCx; use crate::value::Value; +use crate::{attributes, llvm_util}; pub fn apply_to_llfn(llfn: &Value, idx: AttributePlace, attrs: &[&Attribute]) { if !attrs.is_empty() { @@ -407,8 +405,33 @@ pub fn from_fn_attrs<'ll, 'tcx>( // And it is a module-level attribute, so the alternative is pulling naked functions into new LLVM modules. // Otherwise LLVM's "naked" functions come with endbr prefixes per https://github.com/rust-lang/rust/issues/98768 to_add.push(AttributeKind::NoCfCheck.create_attr(cx.llcx)); - // Need this for AArch64. - to_add.push(llvm::CreateAttrStringValue(cx.llcx, "branch-target-enforcement", "false")); + if llvm_util::get_version() < (19, 0, 0) { + // Prior to LLVM 19, branch-target-enforcement was disabled by setting the attribute to + // the string "false". Now it is disabled by absence of the attribute. + to_add.push(llvm::CreateAttrStringValue(cx.llcx, "branch-target-enforcement", "false")); + } + } else if llvm_util::get_version() >= (19, 0, 0) { + // For non-naked functions, set branch protection attributes on aarch64. + if let Some(BranchProtection { bti, pac_ret }) = + cx.sess().opts.unstable_opts.branch_protection + { + assert!(cx.sess().target.arch == "aarch64"); + if bti { + to_add.push(llvm::CreateAttrString(cx.llcx, "branch-target-enforcement")); + } + if let Some(PacRet { leaf, key }) = pac_ret { + to_add.push(llvm::CreateAttrStringValue( + cx.llcx, + "sign-return-address", + if leaf { "all" } else { "non-leaf" }, + )); + to_add.push(llvm::CreateAttrStringValue( + cx.llcx, + "sign-return-address-key", + if key == PAuthKey::A { "a_key" } else { "b_key" }, + )); + } + } } if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::ALLOCATOR) || codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::ALLOCATOR_ZEROED) diff --git a/compiler/rustc_codegen_llvm/src/back/archive.rs b/compiler/rustc_codegen_llvm/src/back/archive.rs index f46c6b1c498..9a28428cb62 100644 --- a/compiler/rustc_codegen_llvm/src/back/archive.rs +++ b/compiler/rustc_codegen_llvm/src/back/archive.rs @@ -1,27 +1,23 @@ //! A helper class for dealing with static archives -use std::env; use std::ffi::{c_char, c_void, CStr, CString, OsString}; -use std::io; -use std::mem; use std::path::{Path, PathBuf}; -use std::ptr; -use std::str; +use std::{env, io, mem, ptr, str}; -use crate::common; -use crate::errors::{ - DlltoolFailImportLibrary, ErrorCallingDllTool, ErrorCreatingImportLibrary, ErrorWritingDEFFile, -}; -use crate::llvm::archive_ro::{ArchiveRO, Child}; -use crate::llvm::{self, ArchiveKind, LLVMMachineType, LLVMRustCOFFShortExport}; use rustc_codegen_ssa::back::archive::{ try_extract_macho_fat_archive, ArArchiveBuilder, ArchiveBuildFailure, ArchiveBuilder, ArchiveBuilderBuilder, ObjectReader, UnknownArchiveKind, DEFAULT_OBJECT_READER, }; -use tracing::trace; - use rustc_session::cstore::DllImport; use rustc_session::Session; +use tracing::trace; + +use crate::common; +use crate::errors::{ + DlltoolFailImportLibrary, ErrorCallingDllTool, ErrorCreatingImportLibrary, ErrorWritingDEFFile, +}; +use crate::llvm::archive_ro::{ArchiveRO, Child}; +use crate::llvm::{self, ArchiveKind, LLVMMachineType, LLVMRustCOFFShortExport}; /// Helper for adding many files to an archive. #[must_use = "must call build() to finish building the archive"] diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index aef672631c8..f68155f523a 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -1,11 +1,11 @@ -use crate::back::write::{ - self, bitcode_section_name, save_temp_bitcode, CodegenDiagnosticsStage, DiagnosticHandlers, -}; -use crate::errors::{ - DynamicLinkingWithLTO, LlvmError, LtoBitcodeFromRlib, LtoDisallowed, LtoDylib, LtoProcMacro, -}; -use crate::llvm::{self, build_string}; -use crate::{LlvmCodegenBackend, ModuleLlvm}; +use std::collections::BTreeMap; +use std::ffi::{CStr, CString}; +use std::fs::File; +use std::mem::ManuallyDrop; +use std::path::Path; +use std::sync::Arc; +use std::{io, iter, slice}; + use object::read::archive::ArchiveFile; use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule, ThinShared}; use rustc_codegen_ssa::back::symbol_export; @@ -22,15 +22,14 @@ use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel use rustc_session::config::{self, CrateType, Lto}; use tracing::{debug, info}; -use std::collections::BTreeMap; -use std::ffi::{CStr, CString}; -use std::fs::File; -use std::io; -use std::iter; -use std::mem::ManuallyDrop; -use std::path::Path; -use std::slice; -use std::sync::Arc; +use crate::back::write::{ + self, bitcode_section_name, save_temp_bitcode, CodegenDiagnosticsStage, DiagnosticHandlers, +}; +use crate::errors::{ + DynamicLinkingWithLTO, LlvmError, LtoBitcodeFromRlib, LtoDisallowed, LtoDylib, LtoProcMacro, +}; +use crate::llvm::{self, build_string}; +use crate::{LlvmCodegenBackend, ModuleLlvm}; /// We keep track of the computed LTO cache keys from the previous /// session to determine which CGUs we can reuse. diff --git a/compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs b/compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs index b72636a6224..681ac75c877 100644 --- a/compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs +++ b/compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs @@ -1,13 +1,12 @@ -use std::{ - ffi::{c_char, CStr}, - marker::PhantomData, - ops::Deref, - ptr::NonNull, -}; +use std::ffi::{c_char, CStr}; +use std::marker::PhantomData; +use std::ops::Deref; +use std::ptr::NonNull; use rustc_data_structures::small_c_str::SmallCStr; -use crate::{errors::LlvmError, llvm}; +use crate::errors::LlvmError; +use crate::llvm; /// Responsible for safely creating and disposing llvm::TargetMachine via ffi functions. /// Not cloneable as there is no clone function for llvm::TargetMachine. diff --git a/compiler/rustc_codegen_llvm/src/back/profiling.rs b/compiler/rustc_codegen_llvm/src/back/profiling.rs index 2eee9f8c5a3..26fb4a96f84 100644 --- a/compiler/rustc_codegen_llvm/src/back/profiling.rs +++ b/compiler/rustc_codegen_llvm/src/back/profiling.rs @@ -1,9 +1,11 @@ -use measureme::{event_id::SEPARATOR_BYTE, EventId, StringComponent, StringId}; -use rustc_data_structures::profiling::{SelfProfiler, TimingGuard}; use std::ffi::{c_void, CStr}; use std::os::raw::c_char; use std::sync::Arc; +use measureme::event_id::SEPARATOR_BYTE; +use measureme::{EventId, StringComponent, StringId}; +use rustc_data_structures::profiling::{SelfProfiler, TimingGuard}; + fn llvm_args_to_string_id(profiler: &SelfProfiler, pass_name: &str, ir_name: &str) -> EventId { let pass_name = profiler.get_or_alloc_cached_string(pass_name); let mut components = vec![StringComponent::Ref(pass_name)]; diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index ddd52e80edf..5a7909d1511 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -1,19 +1,10 @@ -use crate::back::lto::ThinBuffer; -use crate::back::owned_target_machine::OwnedTargetMachine; -use crate::back::profiling::{ - selfprofile_after_pass_callback, selfprofile_before_pass_callback, LlvmSelfProfiler, -}; -use crate::base; -use crate::common; -use crate::errors::{ - CopyBitcode, FromLlvmDiag, FromLlvmOptimizationDiag, LlvmError, UnknownCompression, - WithLlvmError, WriteBytecode, -}; -use crate::llvm::{self, DiagnosticInfo, PassManager}; -use crate::llvm_util; -use crate::type_::Type; -use crate::LlvmCodegenBackend; -use crate::ModuleLlvm; +use std::ffi::CString; +use std::io::{self, Write}; +use std::path::{Path, PathBuf}; +use std::sync::Arc; +use std::{fs, slice, str}; + +use libc::{c_char, c_int, c_void, size_t}; use llvm::{ LLVMRustLLVMHasZlibCompressionForDebugSymbols, LLVMRustLLVMHasZstdCompressionForDebugSymbols, }; @@ -29,23 +20,28 @@ use rustc_data_structures::small_c_str::SmallCStr; use rustc_errors::{DiagCtxtHandle, FatalError, Level}; use rustc_fs_util::{link_or_copy, path_to_c_string}; use rustc_middle::ty::TyCtxt; -use rustc_session::config::{self, Lto, OutputType, Passes}; -use rustc_session::config::{RemapPathScopeComponents, SplitDwarfKind, SwitchWithOptPath}; +use rustc_session::config::{ + self, Lto, OutputType, Passes, RemapPathScopeComponents, SplitDwarfKind, SwitchWithOptPath, +}; use rustc_session::Session; use rustc_span::symbol::sym; use rustc_span::InnerSpan; use rustc_target::spec::{CodeModel, RelocModel, SanitizerSet, SplitDebuginfo, TlsModel}; use tracing::debug; +use crate::back::lto::ThinBuffer; +use crate::back::owned_target_machine::OwnedTargetMachine; +use crate::back::profiling::{ + selfprofile_after_pass_callback, selfprofile_before_pass_callback, LlvmSelfProfiler, +}; +use crate::errors::{ + CopyBitcode, FromLlvmDiag, FromLlvmOptimizationDiag, LlvmError, UnknownCompression, + WithLlvmError, WriteBytecode, +}; use crate::llvm::diagnostic::OptimizationDiagnosticKind; -use libc::{c_char, c_int, c_void, size_t}; -use std::ffi::CString; -use std::fs; -use std::io::{self, Write}; -use std::path::{Path, PathBuf}; -use std::slice; -use std::str; -use std::sync::Arc; +use crate::llvm::{self, DiagnosticInfo, PassManager}; +use crate::type_::Type; +use crate::{base, common, llvm_util, LlvmCodegenBackend, ModuleLlvm}; pub fn llvm_err<'a>(dcx: DiagCtxtHandle<'_>, err: LlvmError<'a>) -> FatalError { match llvm::last_error() { diff --git a/compiler/rustc_codegen_llvm/src/base.rs b/compiler/rustc_codegen_llvm/src/base.rs index 5dc271ccddb..e8236b45c89 100644 --- a/compiler/rustc_codegen_llvm/src/base.rs +++ b/compiler/rustc_codegen_llvm/src/base.rs @@ -11,13 +11,7 @@ //! [`Ty`]: rustc_middle::ty::Ty //! [`val_ty`]: crate::common::val_ty -use super::ModuleLlvm; - -use crate::attributes; -use crate::builder::Builder; -use crate::context::CodegenCx; -use crate::llvm; -use crate::value::Value; +use std::time::Instant; use rustc_codegen_ssa::base::maybe_create_entry_wrapper; use rustc_codegen_ssa::mono_item::MonoItemExt; @@ -32,7 +26,11 @@ use rustc_session::config::DebugInfo; use rustc_span::symbol::Symbol; use rustc_target::spec::SanitizerSet; -use std::time::Instant; +use super::ModuleLlvm; +use crate::builder::Builder; +use crate::context::CodegenCx; +use crate::value::Value; +use crate::{attributes, llvm}; pub struct ValueIter<'ll> { cur: Option<&'ll Value>, diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 72ff9ea118e..77e51f94150 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -1,12 +1,7 @@ -use crate::abi::FnAbiLlvmExt; -use crate::attributes; -use crate::common::Funclet; -use crate::context::CodegenCx; -use crate::llvm::{self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, False, True}; -use crate::llvm_util; -use crate::type_::Type; -use crate::type_of::LayoutLlvmExt; -use crate::value::Value; +use std::borrow::Cow; +use std::ops::Deref; +use std::{iter, ptr}; + use libc::{c_char, c_uint}; use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, SynchronizationScope, TypeKind}; use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue}; @@ -23,15 +18,21 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; use rustc_sanitizers::{cfi, kcfi}; use rustc_session::config::OptLevel; use rustc_span::Span; -use rustc_target::abi::{self, call::FnAbi, Align, Size, WrappingRange}; +use rustc_target::abi::call::FnAbi; +use rustc_target::abi::{self, Align, Size, WrappingRange}; use rustc_target::spec::{HasTargetSpec, SanitizerSet, Target}; use smallvec::SmallVec; -use std::borrow::Cow; -use std::iter; -use std::ops::Deref; -use std::ptr; use tracing::{debug, instrument}; +use crate::abi::FnAbiLlvmExt; +use crate::common::Funclet; +use crate::context::CodegenCx; +use crate::llvm::{self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, False, True}; +use crate::type_::Type; +use crate::type_of::LayoutLlvmExt; +use crate::value::Value; +use crate::{attributes, llvm_util}; + // All Builders must have an llfn associated with them #[must_use] pub struct Builder<'a, 'll, 'tcx> { @@ -390,8 +391,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { lhs: Self::Value, rhs: Self::Value, ) -> (Self::Value, Self::Value) { + use rustc_middle::ty::IntTy::*; + use rustc_middle::ty::UintTy::*; use rustc_middle::ty::{Int, Uint}; - use rustc_middle::ty::{IntTy::*, UintTy::*}; let new_kind = match ty.kind() { Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.pointer_width)), @@ -1353,6 +1355,16 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { } } + pub fn set_unpredictable(&mut self, inst: &'ll Value) { + unsafe { + llvm::LLVMSetMetadata( + inst, + llvm::MD_unpredictable as c_uint, + llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0), + ); + } + } + pub fn minnum(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value { unsafe { llvm::LLVMRustBuildMinNum(self.llbuilder, lhs, rhs) } } diff --git a/compiler/rustc_codegen_llvm/src/callee.rs b/compiler/rustc_codegen_llvm/src/callee.rs index 659c6ae0d86..c913bdebaaa 100644 --- a/compiler/rustc_codegen_llvm/src/callee.rs +++ b/compiler/rustc_codegen_llvm/src/callee.rs @@ -4,16 +4,14 @@ //! and methods are represented as just a fn ptr and not a full //! closure. -use crate::attributes; -use crate::common; -use crate::context::CodegenCx; -use crate::llvm; -use crate::value::Value; - use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt}; use rustc_middle::ty::{self, Instance, TypeVisitableExt}; use tracing::debug; +use crate::context::CodegenCx; +use crate::value::Value; +use crate::{attributes, common, llvm}; + /// Codegens a reference to a fn/method item, monomorphizing and /// inlining as it goes. /// diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index fe64649cf70..197bbb9ddbf 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -1,11 +1,8 @@ //! Code that is useful in various codegen modules. -use crate::consts::const_alloc_to_llvm; -pub use crate::context::CodegenCx; -use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, OperandBundleDef, True}; -use crate::type_::Type; -use crate::value::Value; +use std::fmt::Write; +use libc::{c_char, c_uint}; use rustc_ast::Mutability; use rustc_codegen_ssa::traits::*; use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableHasher}; @@ -16,11 +13,14 @@ use rustc_middle::ty::TyCtxt; use rustc_session::cstore::{DllCallingConvention, DllImport, PeImportNameType}; use rustc_target::abi::{self, AddressSpace, HasDataLayout, Pointer}; use rustc_target::spec::Target; - -use libc::{c_char, c_uint}; -use std::fmt::Write; use tracing::debug; +use crate::consts::const_alloc_to_llvm; +pub use crate::context::CodegenCx; +use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, OperandBundleDef, True}; +use crate::type_::Type; +use crate::value::Value; + /* * A note on nomenclature of linking: "extern", "foreign", and "upcall". * diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 164d1681a36..c3ea4a18a71 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -1,13 +1,5 @@ -use crate::base; -use crate::common::{self, CodegenCx}; -use crate::debuginfo; -use crate::errors::{ - InvalidMinimumAlignmentNotPowerOfTwo, InvalidMinimumAlignmentTooLarge, SymbolAlreadyDefined, -}; -use crate::llvm::{self, True}; -use crate::type_::Type; -use crate::type_of::LayoutLlvmExt; -use crate::value::Value; +use std::ops::Range; + use rustc_codegen_ssa::traits::*; use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; @@ -24,9 +16,18 @@ use rustc_session::config::Lto; use rustc_target::abi::{ Align, AlignFromBytesError, HasDataLayout, Primitive, Scalar, Size, WrappingRange, }; -use std::ops::Range; use tracing::{debug, instrument, trace}; +use crate::common::{self, CodegenCx}; +use crate::errors::{ + InvalidMinimumAlignmentNotPowerOfTwo, InvalidMinimumAlignmentTooLarge, SymbolAlreadyDefined, +}; +use crate::llvm::{self, True}; +use crate::type_::Type; +use crate::type_of::LayoutLlvmExt; +use crate::value::Value; +use crate::{base, debuginfo}; + pub fn const_alloc_to_llvm<'ll>( cx: &CodegenCx<'ll, '_>, alloc: ConstAllocation<'_>, @@ -330,7 +331,7 @@ impl<'ll> CodegenCx<'ll, '_> { // If this assertion triggers, there's something wrong with commandline // argument validation. - debug_assert!( + assert!( !(self.tcx.sess.opts.cg.linker_plugin_lto.enabled() && self.tcx.sess.target.is_like_windows && self.tcx.sess.opts.cg.prefer_dynamic) diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 49677dcf12f..ea930421b58 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -1,19 +1,13 @@ -use crate::attributes; -use crate::back::write::to_llvm_code_model; -use crate::callee::get_fn; -use crate::coverageinfo; -use crate::debuginfo; -use crate::debuginfo::metadata::apply_vcall_visibility_metadata; -use crate::llvm; -use crate::llvm_util; -use crate::type_::Type; -use crate::value::Value; +use std::borrow::Borrow; +use std::cell::{Cell, RefCell}; +use std::ffi::CStr; +use std::str; +use libc::c_uint; use rustc_codegen_ssa::base::{wants_msvc_seh, wants_wasm_eh}; use rustc_codegen_ssa::errors as ssa_errors; use rustc_codegen_ssa::traits::*; -use rustc_data_structures::base_n::ToBaseN; -use rustc_data_structures::base_n::ALPHANUMERIC_ONLY; +use rustc_data_structures::base_n::{ToBaseN, ALPHANUMERIC_ONLY}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::small_c_str::SmallCStr; use rustc_hir::def_id::DefId; @@ -24,20 +18,23 @@ use rustc_middle::ty::layout::{ }; use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; -use rustc_session::config::{BranchProtection, CFGuard, CFProtection}; -use rustc_session::config::{CrateType, DebugInfo, PAuthKey, PacRet}; +use rustc_session::config::{ + BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, PAuthKey, PacRet, +}; use rustc_session::Session; use rustc_span::source_map::Spanned; use rustc_span::{Span, DUMMY_SP}; -use rustc_target::abi::{call::FnAbi, HasDataLayout, TargetDataLayout, VariantIdx}; +use rustc_target::abi::call::FnAbi; +use rustc_target::abi::{HasDataLayout, TargetDataLayout, VariantIdx}; use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel}; use smallvec::SmallVec; -use libc::c_uint; -use std::borrow::Borrow; -use std::cell::{Cell, RefCell}; -use std::ffi::CStr; -use std::str; +use crate::back::write::to_llvm_code_model; +use crate::callee::get_fn; +use crate::debuginfo::metadata::apply_vcall_visibility_metadata; +use crate::type_::Type; +use crate::value::Value; +use crate::{attributes, coverageinfo, debuginfo, llvm, llvm_util}; /// There is one `CodegenCx` per compilation unit. Each one has its own LLVM /// `llvm::Context` so that several compilation units may be optimized in parallel. diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs index 14a94468587..9433385c23a 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs @@ -1,5 +1,3 @@ -use crate::coverageinfo::ffi::{Counter, CounterExpression, ExprKind}; - use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxIndexSet; use rustc_index::bit_set::BitSet; @@ -11,6 +9,8 @@ use rustc_middle::ty::Instance; use rustc_span::Symbol; use tracing::{debug, instrument}; +use crate::coverageinfo::ffi::{Counter, CounterExpression, ExprKind}; + /// Holds all of the coverage mapping data associated with a function instance, /// collected during traversal of `Coverage` statements in the function's MIR. #[derive(Debug)] diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs index d2c0f20c285..f8929a26011 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs @@ -1,21 +1,19 @@ -use crate::common::CodegenCx; -use crate::coverageinfo; -use crate::coverageinfo::ffi::CounterMappingRegion; -use crate::coverageinfo::map_data::{FunctionCoverage, FunctionCoverageCollector}; -use crate::llvm; - use itertools::Itertools as _; use rustc_codegen_ssa::traits::{BaseTypeMethods, ConstMethods}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_index::IndexVec; -use rustc_middle::bug; -use rustc_middle::mir; use rustc_middle::ty::{self, TyCtxt}; +use rustc_middle::{bug, mir}; use rustc_span::def_id::DefIdSet; use rustc_span::Symbol; use tracing::debug; +use crate::common::CodegenCx; +use crate::coverageinfo::ffi::CounterMappingRegion; +use crate::coverageinfo::map_data::{FunctionCoverage, FunctionCoverageCollector}; +use crate::{coverageinfo, llvm}; + /// Generates and exports the Coverage Map. /// /// Rust Coverage Map generation supports LLVM Coverage Mapping Format versions diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs index 7b7f8c885bb..20a713b8564 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs @@ -1,9 +1,4 @@ -use crate::llvm; - -use crate::builder::Builder; -use crate::common::CodegenCx; -use crate::coverageinfo::ffi::{CounterExpression, CounterMappingRegion}; -use crate::coverageinfo::map_data::FunctionCoverageCollector; +use std::cell::RefCell; use libc::c_uint; use rustc_codegen_ssa::traits::{ @@ -19,7 +14,11 @@ use rustc_middle::ty::Instance; use rustc_target::abi::{Align, Size}; use tracing::{debug, instrument}; -use std::cell::RefCell; +use crate::builder::Builder; +use crate::common::CodegenCx; +use crate::coverageinfo::ffi::{CounterExpression, CounterMappingRegion}; +use crate::coverageinfo::map_data::FunctionCoverageCollector; +use crate::llvm; pub(crate) mod ffi; pub(crate) mod map_data; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs index 6a63eda4b99..efe616838bf 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs @@ -1,18 +1,17 @@ -use super::metadata::file_metadata; -use super::utils::DIB; use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext}; use rustc_codegen_ssa::traits::*; - -use crate::common::CodegenCx; -use crate::llvm; -use crate::llvm::debuginfo::{DILocation, DIScope}; +use rustc_index::bit_set::BitSet; +use rustc_index::Idx; use rustc_middle::mir::{Body, SourceScope}; use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::{self, Instance}; use rustc_session::config::DebugInfo; -use rustc_index::bit_set::BitSet; -use rustc_index::Idx; +use super::metadata::file_metadata; +use super::utils::DIB; +use crate::common::CodegenCx; +use crate::llvm; +use crate::llvm::debuginfo::{DILocation, DIScope}; /// Produces DIScope DIEs for each MIR Scope which has variables defined in it. // FIXME(eddyb) almost all of this should be in `rustc_codegen_ssa::mir::debuginfo`. diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs index d82b1e1e721..5a08f2f00e5 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs @@ -1,18 +1,19 @@ // .debug_gdb_scripts binary section. -use crate::llvm; - -use crate::builder::Builder; -use crate::common::CodegenCx; -use crate::value::Value; use rustc_ast::attr; use rustc_codegen_ssa::base::collect_debugger_visualizers_transitive; use rustc_codegen_ssa::traits::*; use rustc_hir::def_id::LOCAL_CRATE; -use rustc_middle::{bug, middle::debugger_visualizer::DebuggerVisualizerType}; +use rustc_middle::bug; +use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerType; use rustc_session::config::{CrateType, DebugInfo}; use rustc_span::symbol::sym; +use crate::builder::Builder; +use crate::common::CodegenCx; +use crate::llvm; +use crate::value::Value; + /// Inserts a side-effect free instruction sequence that makes sure that the /// .debug_gdb_scripts global is referenced, so it isn't removed by the linker. pub fn insert_reference_to_gdb_debug_scripts_section_global(bx: &mut Builder<'_, '_, '_>) { diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 851a4c42e99..ad638588612 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1,32 +1,14 @@ -use self::type_map::DINodeCreationResult; -use self::type_map::Stub; -use self::type_map::UniqueTypeId; - -use super::namespace::mangled_name_of_instance; -use super::type_names::{compute_debuginfo_type_name, compute_debuginfo_vtable_name}; -use super::utils::{ - create_DIArray, debug_context, get_namespace_for_item, is_node_local_to_unit, DIB, -}; -use super::CodegenUnitDebugContext; - -use crate::abi; -use crate::common::CodegenCx; -use crate::debuginfo::metadata::type_map::build_type_with_children; -use crate::debuginfo::utils::fat_pointer_kind; -use crate::debuginfo::utils::FatPtrKind; -use crate::llvm; -use crate::llvm::debuginfo::{ - DIDescriptor, DIFile, DIFlags, DILexicalBlock, DIScope, DIType, DebugEmissionKind, - DebugNameTableKind, -}; -use crate::value::Value; +use std::borrow::Cow; +use std::fmt::{self, Write}; +use std::hash::{Hash, Hasher}; +use std::path::{Path, PathBuf}; +use std::{iter, ptr}; -use rustc_codegen_ssa::debuginfo::type_names::cpp_like_debuginfo; -use rustc_codegen_ssa::debuginfo::type_names::VTableNameKind; +use libc::{c_char, c_longlong, c_uint}; +use rustc_codegen_ssa::debuginfo::type_names::{cpp_like_debuginfo, VTableNameKind}; use rustc_codegen_ssa::traits::*; use rustc_fs_util::path_to_c_string; -use rustc_hir::def::CtorKind; -use rustc_hir::def::DefKind; +use rustc_hir::def::{CtorKind, DefKind}; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_middle::bug; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; @@ -36,21 +18,29 @@ use rustc_middle::ty::{ }; use rustc_session::config::{self, DebugInfo, Lto}; use rustc_span::symbol::Symbol; -use rustc_span::{hygiene, FileName, DUMMY_SP}; -use rustc_span::{FileNameDisplayPreference, SourceFile}; +use rustc_span::{hygiene, FileName, FileNameDisplayPreference, SourceFile, DUMMY_SP}; use rustc_symbol_mangling::typeid_for_trait_ref; use rustc_target::abi::{Align, Size}; use rustc_target::spec::DebuginfoKind; use smallvec::smallvec; use tracing::{debug, instrument}; -use libc::{c_char, c_longlong, c_uint}; -use std::borrow::Cow; -use std::fmt::{self, Write}; -use std::hash::{Hash, Hasher}; -use std::iter; -use std::path::{Path, PathBuf}; -use std::ptr; +use self::type_map::{DINodeCreationResult, Stub, UniqueTypeId}; +use super::namespace::mangled_name_of_instance; +use super::type_names::{compute_debuginfo_type_name, compute_debuginfo_vtable_name}; +use super::utils::{ + create_DIArray, debug_context, get_namespace_for_item, is_node_local_to_unit, DIB, +}; +use super::CodegenUnitDebugContext; +use crate::common::CodegenCx; +use crate::debuginfo::metadata::type_map::build_type_with_children; +use crate::debuginfo::utils::{fat_pointer_kind, FatPtrKind}; +use crate::llvm::debuginfo::{ + DIDescriptor, DIFile, DIFlags, DILexicalBlock, DIScope, DIType, DebugEmissionKind, + DebugNameTableKind, +}; +use crate::value::Value; +use crate::{abi, llvm}; impl PartialEq for llvm::Metadata { fn eq(&self, other: &Self) -> bool { @@ -170,7 +160,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>( ) -> DINodeCreationResult<'ll> { // The debuginfo generated by this function is only valid if `ptr_type` is really just // a (fat) pointer. Make sure it is not called for e.g. `Box<T, NonZSTAllocator>`. - debug_assert_eq!( + assert_eq!( cx.size_and_align_of(ptr_type), cx.size_and_align_of(Ty::new_mut_ptr(cx.tcx, pointee_type)) ); @@ -185,7 +175,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>( match fat_pointer_kind(cx, pointee_type) { None => { // This is a thin pointer. Create a regular pointer type and give it the correct name. - debug_assert_eq!( + assert_eq!( (data_layout.pointer_size, data_layout.pointer_align.abi), cx.size_and_align_of(ptr_type), "ptr_type={ptr_type}, pointee_type={pointee_type}", @@ -240,8 +230,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>( FatPtrKind::Slice => ("data_ptr", "length"), }; - debug_assert_eq!(abi::FAT_PTR_ADDR, 0); - debug_assert_eq!(abi::FAT_PTR_EXTRA, 1); + assert_eq!(abi::FAT_PTR_ADDR, 0); + assert_eq!(abi::FAT_PTR_EXTRA, 1); // The data pointer type is a regular, thin pointer, regardless of whether this // is a slice or a trait object. @@ -498,7 +488,7 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D } }; - debug_assert_eq!(di_node_for_uid as *const _, di_node as *const _); + assert_eq!(di_node_for_uid as *const _, di_node as *const _); } else { debug_context(cx).type_map.insert(unique_type_id, di_node); } @@ -874,7 +864,8 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>( codegen_unit_name: &str, debug_context: &CodegenUnitDebugContext<'ll, 'tcx>, ) -> &'ll DIDescriptor { - use rustc_session::{config::RemapPathScopeComponents, RemapFileNameExt}; + use rustc_session::config::RemapPathScopeComponents; + use rustc_session::RemapFileNameExt; let mut name_in_debuginfo = tcx .sess .local_crate_source_file() @@ -1060,7 +1051,7 @@ fn build_struct_type_di_node<'ll, 'tcx>( let ty::Adt(adt_def, _) = struct_type.kind() else { bug!("build_struct_type_di_node() called with non-struct-type: {:?}", struct_type); }; - debug_assert!(adt_def.is_struct()); + assert!(adt_def.is_struct()); let containing_scope = get_namespace_for_item(cx, adt_def.did()); let struct_type_and_layout = cx.layout_of(struct_type); let variant_def = adt_def.non_enum_variant(); @@ -1130,7 +1121,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>( } }; - debug_assert!( + assert!( up_var_tys.iter().all(|t| t == cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), t)) ); diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index 12f98eef97d..13006638bb3 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -1,41 +1,27 @@ use std::borrow::Cow; use libc::c_uint; -use rustc_codegen_ssa::{ - debuginfo::{type_names::compute_debuginfo_type_name, wants_c_like_enum_debuginfo}, - traits::ConstMethods, -}; - +use rustc_codegen_ssa::debuginfo::type_names::compute_debuginfo_type_name; +use rustc_codegen_ssa::debuginfo::wants_c_like_enum_debuginfo; +use rustc_codegen_ssa::traits::ConstMethods; use rustc_index::IndexVec; -use rustc_middle::{ - bug, - ty::{ - self, - layout::{LayoutOf, TyAndLayout}, - AdtDef, CoroutineArgs, CoroutineArgsExt, Ty, - }, -}; +use rustc_middle::bug; +use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; +use rustc_middle::ty::{self, AdtDef, CoroutineArgs, CoroutineArgsExt, Ty}; use rustc_target::abi::{Align, Endian, Size, TagEncoding, VariantIdx, Variants}; use smallvec::smallvec; -use crate::{ - common::CodegenCx, - debuginfo::{ - metadata::{ - build_field_di_node, - enums::{tag_base_type, DiscrResult}, - file_metadata, size_and_align_of, type_di_node, - type_map::{self, Stub, UniqueTypeId}, - unknown_file_metadata, visibility_di_flags, DINodeCreationResult, SmallVec, - NO_GENERICS, NO_SCOPE_METADATA, UNKNOWN_LINE_NUMBER, - }, - utils::DIB, - }, - llvm::{ - self, - debuginfo::{DIFile, DIFlags, DIType}, - }, +use crate::common::CodegenCx; +use crate::debuginfo::metadata::enums::{tag_base_type, DiscrResult}; +use crate::debuginfo::metadata::type_map::{self, Stub, UniqueTypeId}; +use crate::debuginfo::metadata::{ + build_field_di_node, file_metadata, size_and_align_of, type_di_node, unknown_file_metadata, + visibility_di_flags, DINodeCreationResult, SmallVec, NO_GENERICS, NO_SCOPE_METADATA, + UNKNOWN_LINE_NUMBER, }; +use crate::debuginfo::utils::DIB; +use crate::llvm::debuginfo::{DIFile, DIFlags, DIType}; +use crate::llvm::{self}; // The names of the associated constants in each variant wrapper struct. // These have to match up with the names being used in `intrinsic.natvis`. @@ -204,7 +190,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( let enum_type_and_layout = cx.layout_of(enum_type); let enum_type_name = compute_debuginfo_type_name(cx.tcx, enum_type, false); - debug_assert!(!wants_c_like_enum_debuginfo(enum_type_and_layout)); + assert!(!wants_c_like_enum_debuginfo(enum_type_and_layout)); type_map::build_type_with_children( cx, @@ -279,7 +265,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( let coroutine_type_and_layout = cx.layout_of(coroutine_type); let coroutine_type_name = compute_debuginfo_type_name(cx.tcx, coroutine_type, false); - debug_assert!(!wants_c_like_enum_debuginfo(coroutine_type_and_layout)); + assert!(!wants_c_like_enum_debuginfo(coroutine_type_and_layout)); type_map::build_type_with_children( cx, @@ -517,7 +503,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( if is_128_bits { DiscrKind::Exact128(discr_val) } else { - debug_assert_eq!(discr_val, discr_val as u64 as u128); + assert_eq!(discr_val, discr_val as u64 as u128); DiscrKind::Exact(discr_val as u64) } } @@ -526,8 +512,8 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( if is_128_bits { DiscrKind::Range128(min, max) } else { - debug_assert_eq!(min, min as u64 as u128); - debug_assert_eq!(max, max as u64 as u128); + assert_eq!(min, min as u64 as u128); + assert_eq!(max, max as u64 as u128); DiscrKind::Range(min as u64, max as u64) } } @@ -815,7 +801,7 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>( } })); - debug_assert_eq!( + assert_eq!( cx.size_and_align_of(enum_type_and_layout.field(cx, tag_field).ty), cx.size_and_align_of(super::tag_base_type(cx, enum_type_and_layout)) ); 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 2b00bb14593..fc3adaf0681 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -1,45 +1,29 @@ -use rustc_codegen_ssa::debuginfo::{ - type_names::{compute_debuginfo_type_name, cpp_like_debuginfo}, - wants_c_like_enum_debuginfo, -}; +use std::borrow::Cow; + +use rustc_codegen_ssa::debuginfo::type_names::{compute_debuginfo_type_name, cpp_like_debuginfo}; +use rustc_codegen_ssa::debuginfo::wants_c_like_enum_debuginfo; use rustc_hir::def::CtorKind; use rustc_index::IndexSlice; -use rustc_middle::{ - bug, - mir::CoroutineLayout, - ty::{ - self, - layout::{IntegerExt, LayoutOf, PrimitiveExt, TyAndLayout}, - AdtDef, CoroutineArgs, CoroutineArgsExt, Ty, VariantDef, - }, -}; +use rustc_middle::bug; +use rustc_middle::mir::CoroutineLayout; +use rustc_middle::ty::layout::{IntegerExt, LayoutOf, PrimitiveExt, TyAndLayout}; +use rustc_middle::ty::{self, AdtDef, CoroutineArgs, CoroutineArgsExt, Ty, VariantDef}; use rustc_span::Symbol; use rustc_target::abi::{ FieldIdx, HasDataLayout, Integer, Primitive, TagEncoding, VariantIdx, Variants, }; -use std::borrow::Cow; - -use crate::{ - common::CodegenCx, - debuginfo::{ - metadata::{ - build_field_di_node, build_generic_type_param_di_nodes, type_di_node, - type_map::{self, Stub}, - unknown_file_metadata, UNKNOWN_LINE_NUMBER, - }, - utils::{create_DIArray, get_namespace_for_item, DIB}, - }, - llvm::{ - self, - debuginfo::{DIFlags, DIType}, - }, -}; -use super::{ - size_and_align_of, - type_map::{DINodeCreationResult, UniqueTypeId}, - SmallVec, +use super::type_map::{DINodeCreationResult, UniqueTypeId}; +use super::{size_and_align_of, SmallVec}; +use crate::common::CodegenCx; +use crate::debuginfo::metadata::type_map::{self, Stub}; +use crate::debuginfo::metadata::{ + build_field_di_node, build_generic_type_param_di_nodes, type_di_node, unknown_file_metadata, + UNKNOWN_LINE_NUMBER, }; +use crate::debuginfo::utils::{create_DIArray, get_namespace_for_item, DIB}; +use crate::llvm::debuginfo::{DIFlags, DIType}; +use crate::llvm::{self}; mod cpp_like; mod native; @@ -106,7 +90,7 @@ fn tag_base_type<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, enum_type_and_layout: TyAndLayout<'tcx>, ) -> Ty<'tcx> { - debug_assert!(match enum_type_and_layout.ty.kind() { + assert!(match enum_type_and_layout.ty.kind() { ty::Coroutine(..) => true, ty::Adt(adt_def, _) => adt_def.is_enum(), _ => false, @@ -251,7 +235,7 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>( variant_layout: TyAndLayout<'tcx>, di_flags: DIFlags, ) -> &'ll DIType { - debug_assert_eq!(variant_layout.ty, enum_type_and_layout.ty); + assert_eq!(variant_layout.ty, enum_type_and_layout.ty); type_map::build_type_with_children( cx, 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 115d5187eaf..d7e3b47e0bd 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -1,37 +1,26 @@ use std::borrow::Cow; -use crate::{ - common::CodegenCx, - debuginfo::{ - metadata::{ - enums::tag_base_type, - file_metadata, size_and_align_of, type_di_node, - type_map::{self, Stub, StubInfo, UniqueTypeId}, - unknown_file_metadata, visibility_di_flags, DINodeCreationResult, SmallVec, - NO_GENERICS, UNKNOWN_LINE_NUMBER, - }, - utils::{create_DIArray, get_namespace_for_item, DIB}, - }, - llvm::{ - self, - debuginfo::{DIFile, DIFlags, DIType}, - }, -}; use libc::c_uint; -use rustc_codegen_ssa::{ - debuginfo::{type_names::compute_debuginfo_type_name, wants_c_like_enum_debuginfo}, - traits::ConstMethods, -}; -use rustc_middle::{ - bug, - ty::{ - self, - layout::{LayoutOf, TyAndLayout}, - }, -}; +use rustc_codegen_ssa::debuginfo::type_names::compute_debuginfo_type_name; +use rustc_codegen_ssa::debuginfo::wants_c_like_enum_debuginfo; +use rustc_codegen_ssa::traits::ConstMethods; +use rustc_middle::bug; +use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; +use rustc_middle::ty::{self}; use rustc_target::abi::{Size, TagEncoding, VariantIdx, Variants}; use smallvec::smallvec; +use crate::common::CodegenCx; +use crate::debuginfo::metadata::enums::tag_base_type; +use crate::debuginfo::metadata::type_map::{self, Stub, StubInfo, UniqueTypeId}; +use crate::debuginfo::metadata::{ + file_metadata, size_and_align_of, type_di_node, unknown_file_metadata, visibility_di_flags, + DINodeCreationResult, SmallVec, NO_GENERICS, UNKNOWN_LINE_NUMBER, +}; +use crate::debuginfo::utils::{create_DIArray, get_namespace_for_item, DIB}; +use crate::llvm::debuginfo::{DIFile, DIFlags, DIType}; +use crate::llvm::{self}; + /// Build the debuginfo node for an enum type. The listing below shows how such a /// type looks like at the LLVM IR/DWARF level. It is a `DW_TAG_structure_type` /// with a single `DW_TAG_variant_part` that in turn contains a `DW_TAG_variant` @@ -65,7 +54,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( let visibility_flags = visibility_di_flags(cx, enum_adt_def.did(), enum_adt_def.did()); - debug_assert!(!wants_c_like_enum_debuginfo(enum_type_and_layout)); + assert!(!wants_c_like_enum_debuginfo(enum_type_and_layout)); type_map::build_type_with_children( cx, @@ -142,7 +131,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( let containing_scope = get_namespace_for_item(cx, coroutine_def_id); let coroutine_type_and_layout = cx.layout_of(coroutine_type); - debug_assert!(!wants_c_like_enum_debuginfo(coroutine_type_and_layout)); + assert!(!wants_c_like_enum_debuginfo(coroutine_type_and_layout)); let coroutine_type_name = compute_debuginfo_type_name(cx.tcx, coroutine_type, false); diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs index e521d5e259c..25b2df9c52c 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs @@ -1,27 +1,18 @@ use std::cell::RefCell; -use rustc_data_structures::{ - fingerprint::Fingerprint, - fx::FxHashMap, - stable_hasher::{HashStable, StableHasher}, -}; +use rustc_data_structures::fingerprint::Fingerprint; +use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_macros::HashStable; -use rustc_middle::{ - bug, - ty::{ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt}, -}; +use rustc_middle::bug; +use rustc_middle::ty::{ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt}; use rustc_target::abi::{Align, Size, VariantIdx}; -use crate::{ - common::CodegenCx, - debuginfo::utils::{create_DIArray, debug_context, DIB}, - llvm::{ - self, - debuginfo::{DIFlags, DIScope, DIType}, - }, -}; - use super::{unknown_file_metadata, SmallVec, UNKNOWN_LINE_NUMBER}; +use crate::common::CodegenCx; +use crate::debuginfo::utils::{create_DIArray, debug_context, DIB}; +use crate::llvm::debuginfo::{DIFlags, DIScope, DIType}; +use crate::llvm::{self}; mod private { use rustc_macros::HashStable; @@ -36,7 +27,7 @@ mod private { /// A unique identifier for anything that we create a debuginfo node for. /// The types it contains are expected to already be normalized (which -/// is debug_asserted in the constructors). +/// is asserted in the constructors). /// /// Note that there are some things that only show up in debuginfo, like /// the separate type descriptions for each enum variant. These get an ID @@ -58,12 +49,12 @@ pub(super) enum UniqueTypeId<'tcx> { impl<'tcx> UniqueTypeId<'tcx> { pub fn for_ty(tcx: TyCtxt<'tcx>, t: Ty<'tcx>) -> Self { - debug_assert_eq!(t, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), t)); + assert_eq!(t, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), t)); UniqueTypeId::Ty(t, private::HiddenZst) } pub fn for_enum_variant_part(tcx: TyCtxt<'tcx>, enum_ty: Ty<'tcx>) -> Self { - debug_assert_eq!(enum_ty, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), enum_ty)); + assert_eq!(enum_ty, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), enum_ty)); UniqueTypeId::VariantPart(enum_ty, private::HiddenZst) } @@ -72,7 +63,7 @@ impl<'tcx> UniqueTypeId<'tcx> { enum_ty: Ty<'tcx>, variant_idx: VariantIdx, ) -> Self { - debug_assert_eq!(enum_ty, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), enum_ty)); + assert_eq!(enum_ty, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), enum_ty)); UniqueTypeId::VariantStructType(enum_ty, variant_idx, private::HiddenZst) } @@ -81,7 +72,7 @@ impl<'tcx> UniqueTypeId<'tcx> { enum_ty: Ty<'tcx>, variant_idx: VariantIdx, ) -> Self { - debug_assert_eq!(enum_ty, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), enum_ty)); + assert_eq!(enum_ty, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), enum_ty)); UniqueTypeId::VariantStructTypeCppLikeWrapper(enum_ty, variant_idx, private::HiddenZst) } @@ -90,11 +81,8 @@ impl<'tcx> UniqueTypeId<'tcx> { self_type: Ty<'tcx>, implemented_trait: Option<PolyExistentialTraitRef<'tcx>>, ) -> Self { - debug_assert_eq!( - self_type, - tcx.normalize_erasing_regions(ParamEnv::reveal_all(), self_type) - ); - debug_assert_eq!( + assert_eq!(self_type, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), self_type)); + assert_eq!( implemented_trait, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), implemented_trait) ); @@ -252,10 +240,7 @@ pub(super) fn build_type_with_children<'ll, 'tcx>( members: impl FnOnce(&CodegenCx<'ll, 'tcx>, &'ll DIType) -> SmallVec<&'ll DIType>, generics: impl FnOnce(&CodegenCx<'ll, 'tcx>) -> SmallVec<&'ll DIType>, ) -> DINodeCreationResult<'ll> { - debug_assert_eq!( - debug_context(cx).type_map.di_node_for_unique_id(stub_info.unique_type_id), - None - ); + assert_eq!(debug_context(cx).type_map.di_node_for_unique_id(stub_info.unique_type_id), None); debug_context(cx).type_map.insert(stub_info.unique_type_id, stub_info.metadata); diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 3486ce4becb..b23e05182ca 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -1,33 +1,21 @@ #![doc = include_str!("doc.md")] -use rustc_codegen_ssa::mir::debuginfo::VariableKind::*; -use rustc_data_structures::unord::UnordMap; - -use self::metadata::{file_metadata, type_di_node}; -use self::metadata::{UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER}; -use self::namespace::mangled_name_of_instance; -use self::utils::{create_DIArray, is_node_local_to_unit, DIB}; - -use crate::abi::FnAbi; -use crate::builder::Builder; -use crate::common::CodegenCx; -use crate::llvm; -use crate::llvm::debuginfo::{ - DIArray, DIBuilder, DIFile, DIFlags, DILexicalBlock, DILocation, DISPFlags, DIScope, DIType, - DIVariable, -}; -use crate::value::Value; +use std::cell::{OnceCell, RefCell}; +use std::iter; +use std::ops::Range; +use libc::c_uint; use rustc_codegen_ssa::debuginfo::type_names; +use rustc_codegen_ssa::mir::debuginfo::VariableKind::*; use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, VariableKind}; use rustc_codegen_ssa::traits::*; use rustc_data_structures::sync::Lrc; +use rustc_data_structures::unord::UnordMap; use rustc_hir::def_id::{DefId, DefIdMap}; use rustc_index::IndexVec; use rustc_middle::mir; use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::ty::GenericArgsRef; -use rustc_middle::ty::{self, Instance, ParamEnv, Ty, TypeVisitableExt}; +use rustc_middle::ty::{self, GenericArgsRef, Instance, ParamEnv, Ty, TypeVisitableExt}; use rustc_session::config::{self, DebugInfo}; use rustc_session::Session; use rustc_span::symbol::Symbol; @@ -35,15 +23,22 @@ use rustc_span::{ BytePos, Pos, SourceFile, SourceFileAndLine, SourceFileHash, Span, StableSourceFileId, }; use rustc_target::abi::Size; - -use libc::c_uint; use smallvec::SmallVec; -use std::cell::OnceCell; -use std::cell::RefCell; -use std::iter; -use std::ops::Range; use tracing::debug; +use self::metadata::{file_metadata, type_di_node, UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER}; +use self::namespace::mangled_name_of_instance; +use self::utils::{create_DIArray, is_node_local_to_unit, DIB}; +use crate::abi::FnAbi; +use crate::builder::Builder; +use crate::common::CodegenCx; +use crate::llvm; +use crate::llvm::debuginfo::{ + DIArray, DIBuilder, DIFile, DIFlags, DILexicalBlock, DILocation, DISPFlags, DIScope, DIType, + DIVariable, +}; +use crate::value::Value; + mod create_scope_map; pub mod gdb; pub mod metadata; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs b/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs index fa61c7dde18..5c4f8fe99e3 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs @@ -1,13 +1,13 @@ // Namespace Handling. -use super::utils::{debug_context, DIB}; use rustc_codegen_ssa::debuginfo::type_names; +use rustc_hir::def_id::DefId; use rustc_middle::ty::{self, Instance}; +use super::utils::{debug_context, DIB}; use crate::common::CodegenCx; use crate::llvm; use crate::llvm::debuginfo::DIScope; -use rustc_hir::def_id::DefId; pub fn mangled_name_of_instance<'a, 'tcx>( cx: &CodegenCx<'a, 'tcx>, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs b/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs index 155e7a89fd8..d51e15d12e2 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs @@ -1,13 +1,12 @@ // Utility Functions. -use super::namespace::item_namespace; -use super::CodegenUnitDebugContext; - use rustc_hir::def_id::DefId; use rustc_middle::ty::layout::{HasParamEnv, LayoutOf}; use rustc_middle::ty::{self, Ty}; use tracing::trace; +use super::namespace::item_namespace; +use super::CodegenUnitDebugContext; use crate::common::CodegenCx; use crate::llvm; use crate::llvm::debuginfo::{DIArray, DIBuilder, DIDescriptor, DIScope}; @@ -81,7 +80,7 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>( ty::Dynamic(..) => Some(FatPtrKind::Dyn), ty::Foreign(_) => { // Assert that pointers to foreign types really are thin: - debug_assert_eq!( + assert_eq!( cx.size_of(Ty::new_imm_ptr(cx.tcx, pointee_tail_ty)), cx.size_of(Ty::new_imm_ptr(cx.tcx, cx.tcx.types.u8)) ); diff --git a/compiler/rustc_codegen_llvm/src/declare.rs b/compiler/rustc_codegen_llvm/src/declare.rs index bf86d0e0569..c4887464e19 100644 --- a/compiler/rustc_codegen_llvm/src/declare.rs +++ b/compiler/rustc_codegen_llvm/src/declare.rs @@ -11,13 +11,6 @@ //! * Use define_* family of methods when you might be defining the Value. //! * When in doubt, define. -use crate::abi::{FnAbi, FnAbiLlvmExt}; -use crate::attributes; -use crate::context::CodegenCx; -use crate::llvm; -use crate::llvm::AttributePlace::Function; -use crate::type_::Type; -use crate::value::Value; use itertools::Itertools; use rustc_codegen_ssa::traits::TypeMembershipMethods; use rustc_data_structures::fx::FxIndexSet; @@ -26,6 +19,13 @@ use rustc_sanitizers::{cfi, kcfi}; use smallvec::SmallVec; use tracing::debug; +use crate::abi::{FnAbi, FnAbiLlvmExt}; +use crate::context::CodegenCx; +use crate::llvm::AttributePlace::Function; +use crate::type_::Type; +use crate::value::Value; +use crate::{attributes, llvm}; + /// Declare a function. /// /// If there’s a value with the same name already declared, the function will diff --git a/compiler/rustc_codegen_llvm/src/errors.rs b/compiler/rustc_codegen_llvm/src/errors.rs index 40ac2f9c8ba..a3957bc52a5 100644 --- a/compiler/rustc_codegen_llvm/src/errors.rs +++ b/compiler/rustc_codegen_llvm/src/errors.rs @@ -2,12 +2,13 @@ use std::borrow::Cow; use std::ffi::CString; use std::path::Path; -use crate::fluent_generated as fluent; use rustc_data_structures::small_c_str::SmallCStr; use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level}; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::Span; +use crate::fluent_generated as fluent; + #[derive(Diagnostic)] #[diag(codegen_llvm_unknown_ctarget_feature_prefix)] #[note] diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 68c3d47e826..040de1c7dd7 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -1,17 +1,10 @@ -use crate::abi::{Abi, FnAbi, FnAbiLlvmExt, LlvmType, PassMode}; -use crate::builder::Builder; -use crate::context::CodegenCx; -use crate::llvm; -use crate::type_::Type; -use crate::type_of::LayoutLlvmExt; -use crate::va_arg::emit_va_arg; -use crate::value::Value; +use std::cmp::Ordering; use rustc_codegen_ssa::base::{compare_simd_types, wants_msvc_seh, wants_wasm_eh}; use rustc_codegen_ssa::common::{IntPredicate, TypeKind}; use rustc_codegen_ssa::errors::{ExpectedPointerMutability, InvalidMonomorphization}; use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue}; -use rustc_codegen_ssa::mir::place::PlaceRef; +use rustc_codegen_ssa::mir::place::{PlaceRef, PlaceValue}; use rustc_codegen_ssa::traits::*; use rustc_hir as hir; use rustc_middle::mir::BinOp; @@ -23,7 +16,14 @@ use rustc_target::abi::{self, Align, Float, HasDataLayout, Primitive, Size}; use rustc_target::spec::{HasTargetSpec, PanicStrategy}; use tracing::debug; -use std::cmp::Ordering; +use crate::abi::{Abi, FnAbi, FnAbiLlvmExt, LlvmType, PassMode}; +use crate::builder::Builder; +use crate::context::CodegenCx; +use crate::llvm; +use crate::type_::Type; +use crate::type_of::LayoutLlvmExt; +use crate::va_arg::emit_va_arg; +use crate::value::Value; fn get_simple_intrinsic<'ll>( cx: &CodegenCx<'ll, '_>, @@ -203,6 +203,35 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> { } sym::unlikely => self .call_intrinsic("llvm.expect.i1", &[args[0].immediate(), self.const_bool(false)]), + sym::select_unpredictable => { + let cond = args[0].immediate(); + assert_eq!(args[1].layout, args[2].layout); + let select = |bx: &mut Self, true_val, false_val| { + let result = bx.select(cond, true_val, false_val); + bx.set_unpredictable(&result); + result + }; + match (args[1].val, args[2].val) { + (OperandValue::Ref(true_val), OperandValue::Ref(false_val)) => { + assert!(true_val.llextra.is_none()); + assert!(false_val.llextra.is_none()); + assert_eq!(true_val.align, false_val.align); + let ptr = select(self, true_val.llval, false_val.llval); + let selected = + OperandValue::Ref(PlaceValue::new_sized(ptr, true_val.align)); + selected.store(self, result); + return Ok(()); + } + (OperandValue::Immediate(_), OperandValue::Immediate(_)) + | (OperandValue::Pair(_, _), OperandValue::Pair(_, _)) => { + let true_val = args[1].immediate_or_packed_pair(self); + let false_val = args[2].immediate_or_packed_pair(self); + select(self, true_val, false_val) + } + (OperandValue::ZeroSized, OperandValue::ZeroSized) => return Ok(()), + _ => span_bug!(span, "Incompatible OperandValue for select_unpredictable"), + } + } sym::catch_unwind => { catch_unwind_intrinsic( self, diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index a96993b9aba..41e9cfd1066 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -17,9 +17,13 @@ #![feature(rustdoc_internals)] // tidy-alphabetical-end +use std::any::Any; +use std::ffi::CStr; +use std::io::Write; +use std::mem::ManuallyDrop; + use back::owned_target_machine::OwnedTargetMachine; use back::write::{create_informational_target_machine, create_target_machine}; - use errors::ParseTargetMachineConfig; pub use llvm_util::target_features; use rustc_ast::expand::allocator::AllocatorKind; @@ -28,8 +32,7 @@ use rustc_codegen_ssa::back::write::{ CodegenContext, FatLtoInput, ModuleConfig, TargetMachineFactoryConfig, TargetMachineFactoryFn, }; use rustc_codegen_ssa::traits::*; -use rustc_codegen_ssa::ModuleCodegen; -use rustc_codegen_ssa::{CodegenResults, CompiledModule}; +use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen}; use rustc_data_structures::fx::FxIndexMap; use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, FatalError}; use rustc_metadata::EncodedMetadata; @@ -40,11 +43,6 @@ use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest}; use rustc_session::Session; use rustc_span::symbol::Symbol; -use std::any::Any; -use std::ffi::CStr; -use std::io::Write; -use std::mem::ManuallyDrop; - mod back { pub mod archive; pub mod lto; @@ -394,9 +392,10 @@ impl CodegenBackend for LlvmCodegenBackend { codegen_results: CodegenResults, outputs: &OutputFilenames, ) -> Result<(), ErrorGuaranteed> { - use crate::back::archive::LlvmArchiveBuilderBuilder; use rustc_codegen_ssa::back::link::link_binary; + use crate::back::archive::LlvmArchiveBuilderBuilder; + // Run the linker on any artifacts that resulted from the LLVM run. // This should produce either a finished executable or library. link_binary(sess, &LlvmArchiveBuilderBuilder, &codegen_results, outputs) diff --git a/compiler/rustc_codegen_llvm/src/llvm/archive_ro.rs b/compiler/rustc_codegen_llvm/src/llvm/archive_ro.rs index 7d948970223..4dabde55e98 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/archive_ro.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/archive_ro.rs @@ -1,9 +1,9 @@ //! A wrapper around LLVM's archive (.a) code -use rustc_fs_util::path_to_c_string; use std::path::Path; -use std::slice; -use std::str; +use std::{slice, str}; + +use rustc_fs_util::path_to_c_string; pub struct ArchiveRO { pub raw: &'static mut super::Archive, diff --git a/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs b/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs index 73e1b08a3d7..a4cb5a25d1b 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs @@ -1,13 +1,12 @@ //! LLVM diagnostic reports. -pub use self::Diagnostic::*; -pub use self::OptimizationDiagnosticKind::*; - -use crate::value::Value; use libc::c_uint; +use rustc_span::InnerSpan; +pub use self::Diagnostic::*; +pub use self::OptimizationDiagnosticKind::*; use super::{DiagnosticInfo, SMDiagnostic}; -use rustc_span::InnerSpan; +use crate::value::Value; #[derive(Copy, Clone, Debug)] pub enum OptimizationDiagnosticKind { diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index ae46200d3f5..80b13c0e1d4 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -1,18 +1,16 @@ #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] +use std::marker::PhantomData; + +use libc::{c_char, c_int, c_uint, c_ulonglong, c_void, size_t}; + use super::debuginfo::{ DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DILocation, DINameSpace, DISPFlags, DIScope, DISubprogram, DISubrange, DITemplateTypeParameter, DIType, DIVariable, DebugEmissionKind, DebugNameTableKind, }; - -use libc::{c_char, c_int, c_uint, size_t}; -use libc::{c_ulonglong, c_void}; - -use std::marker::PhantomData; - use super::RustString; pub type Bool = c_uint; @@ -305,7 +303,6 @@ pub enum TypeKind { Pointer = 12, Vector = 13, Metadata = 14, - X86_MMX = 15, Token = 16, ScalableVector = 17, BFloat = 18, @@ -330,7 +327,6 @@ impl TypeKind { TypeKind::Pointer => rustc_codegen_ssa::common::TypeKind::Pointer, TypeKind::Vector => rustc_codegen_ssa::common::TypeKind::Vector, TypeKind::Metadata => rustc_codegen_ssa::common::TypeKind::Metadata, - TypeKind::X86_MMX => rustc_codegen_ssa::common::TypeKind::X86_MMX, TypeKind::Token => rustc_codegen_ssa::common::TypeKind::Token, TypeKind::ScalableVector => rustc_codegen_ssa::common::TypeKind::ScalableVector, TypeKind::BFloat => rustc_codegen_ssa::common::TypeKind::BFloat, @@ -430,6 +426,7 @@ pub enum MetadataType { MD_nontemporal = 9, MD_mem_parallel_loop_access = 10, MD_nonnull = 11, + MD_unpredictable = 15, MD_align = 17, MD_type = 19, MD_vcall_visibility = 28, @@ -699,9 +696,10 @@ pub type DiagnosticHandlerTy = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void pub type InlineAsmDiagHandlerTy = unsafe extern "C" fn(&SMDiagnostic, *const c_void, c_uint); pub mod debuginfo { - use super::{InvariantOpaque, Metadata}; use bitflags::bitflags; + use super::{InvariantOpaque, Metadata}; + #[repr(C)] pub struct DIBuilder<'a>(InvariantOpaque<'a>); diff --git a/compiler/rustc_codegen_llvm/src/llvm/mod.rs b/compiler/rustc_codegen_llvm/src/llvm/mod.rs index 6ab1eea9597..72691907c0d 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/mod.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/mod.rs @@ -1,5 +1,15 @@ #![allow(non_snake_case)] +use std::cell::RefCell; +use std::ffi::{CStr, CString}; +use std::str::FromStr; +use std::string::FromUtf8Error; + +use libc::c_uint; +use rustc_data_structures::small_c_str::SmallCStr; +use rustc_llvm::RustString; +use rustc_target::abi::Align; + pub use self::AtomicRmwBinOp::*; pub use self::CallConv::*; pub use self::CodeGenOptSize::*; @@ -8,15 +18,6 @@ pub use self::Linkage::*; pub use self::MetadataType::*; pub use self::RealPredicate::*; -use libc::c_uint; -use rustc_data_structures::small_c_str::SmallCStr; -use rustc_llvm::RustString; -use rustc_target::abi::Align; -use std::cell::RefCell; -use std::ffi::{CStr, CString}; -use std::str::FromStr; -use std::string::FromUtf8Error; - pub mod archive_ro; pub mod diagnostic; mod ffi; diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 4d56d1d3b1a..dc21b92a95f 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -1,9 +1,9 @@ -use crate::back::write::create_informational_target_machine; -use crate::errors::{ - FixedX18InvalidArch, InvalidTargetFeaturePrefix, PossibleFeature, TargetFeatureDisableOrEnable, - UnknownCTargetFeature, UnknownCTargetFeaturePrefix, UnstableCTargetFeature, -}; -use crate::llvm; +use std::ffi::{c_char, c_void, CStr, CString}; +use std::fmt::Write; +use std::path::Path; +use std::sync::Once; +use std::{ptr, slice, str}; + use libc::c_int; use rustc_codegen_ssa::base::wants_wasm_eh; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; @@ -16,13 +16,12 @@ use rustc_span::symbol::Symbol; use rustc_target::spec::{MergeFunctions, PanicStrategy}; use rustc_target::target_features::{RUSTC_SPECIAL_FEATURES, RUSTC_SPECIFIC_FEATURES}; -use std::ffi::{c_char, c_void, CStr, CString}; -use std::fmt::Write; -use std::path::Path; -use std::ptr; -use std::slice; -use std::str; -use std::sync::Once; +use crate::back::write::create_informational_target_machine; +use crate::errors::{ + FixedX18InvalidArch, InvalidTargetFeaturePrefix, PossibleFeature, TargetFeatureDisableOrEnable, + UnknownCTargetFeature, UnknownCTargetFeaturePrefix, UnstableCTargetFeature, +}; +use crate::llvm; static INIT: Once = Once::new(); diff --git a/compiler/rustc_codegen_llvm/src/mono_item.rs b/compiler/rustc_codegen_llvm/src/mono_item.rs index 282a186be99..d59eaae1ba9 100644 --- a/compiler/rustc_codegen_llvm/src/mono_item.rs +++ b/compiler/rustc_codegen_llvm/src/mono_item.rs @@ -1,9 +1,3 @@ -use crate::attributes; -use crate::base; -use crate::context::CodegenCx; -use crate::errors::SymbolAlreadyDefined; -use crate::llvm; -use crate::type_of::LayoutLlvmExt; use rustc_codegen_ssa::traits::*; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; @@ -15,6 +9,11 @@ use rustc_session::config::CrateType; use rustc_target::spec::RelocModel; use tracing::debug; +use crate::context::CodegenCx; +use crate::errors::SymbolAlreadyDefined; +use crate::type_of::LayoutLlvmExt; +use crate::{attributes, base, llvm}; + impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'_, 'tcx> { fn predefine_static( &self, diff --git a/compiler/rustc_codegen_llvm/src/type_.rs b/compiler/rustc_codegen_llvm/src/type_.rs index f1141c57ced..7e3ab19898d 100644 --- a/compiler/rustc_codegen_llvm/src/type_.rs +++ b/compiler/rustc_codegen_llvm/src/type_.rs @@ -1,12 +1,6 @@ -pub use crate::llvm::Type; +use std::{fmt, ptr}; -use crate::abi::{FnAbiLlvmExt, LlvmType}; -use crate::common; -use crate::context::CodegenCx; -use crate::llvm; -use crate::llvm::{Bool, False, True}; -use crate::type_of::LayoutLlvmExt; -use crate::value::Value; +use libc::{c_char, c_uint}; use rustc_codegen_ssa::common::TypeKind; use rustc_codegen_ssa::traits::*; use rustc_data_structures::small_c_str::SmallCStr; @@ -16,10 +10,13 @@ use rustc_middle::ty::{self, Ty}; use rustc_target::abi::call::{CastTarget, FnAbi, Reg}; use rustc_target::abi::{AddressSpace, Align, Integer, Size}; -use std::fmt; -use std::ptr; - -use libc::{c_char, c_uint}; +use crate::abi::{FnAbiLlvmExt, LlvmType}; +use crate::context::CodegenCx; +pub use crate::llvm::Type; +use crate::llvm::{Bool, False, True}; +use crate::type_of::LayoutLlvmExt; +use crate::value::Value; +use crate::{common, llvm}; impl PartialEq for Type { fn eq(&self, other: &Self) -> bool { diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs index 7be941ed749..4755fa08afb 100644 --- a/compiler/rustc_codegen_llvm/src/type_of.rs +++ b/compiler/rustc_codegen_llvm/src/type_of.rs @@ -1,16 +1,15 @@ -use crate::common::*; -use crate::type_::Type; +use std::fmt::Write; + use rustc_codegen_ssa::traits::*; use rustc_middle::bug; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths}; use rustc_middle::ty::{self, CoroutineArgsExt, Ty, TypeVisitableExt}; -use rustc_target::abi::{Abi, Align, FieldsShape}; -use rustc_target::abi::{Float, Int, Pointer}; -use rustc_target::abi::{Scalar, Size, Variants}; +use rustc_target::abi::{Abi, Align, FieldsShape, Float, Int, Pointer, Scalar, Size, Variants}; use tracing::debug; -use std::fmt::Write; +use crate::common::*; +use crate::type_::Type; fn uncached_llvm_type<'a, 'tcx>( cx: &CodegenCx<'a, 'tcx>, diff --git a/compiler/rustc_codegen_llvm/src/va_arg.rs b/compiler/rustc_codegen_llvm/src/va_arg.rs index 220bb77d3fd..94e77c5bd70 100644 --- a/compiler/rustc_codegen_llvm/src/va_arg.rs +++ b/compiler/rustc_codegen_llvm/src/va_arg.rs @@ -1,16 +1,15 @@ -use crate::builder::Builder; -use crate::type_::Type; -use crate::type_of::LayoutLlvmExt; -use crate::value::Value; +use rustc_codegen_ssa::common::IntPredicate; use rustc_codegen_ssa::mir::operand::OperandRef; -use rustc_codegen_ssa::{ - common::IntPredicate, - traits::{BaseTypeMethods, BuilderMethods, ConstMethods}, -}; +use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods, ConstMethods}; use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf}; use rustc_middle::ty::Ty; use rustc_target::abi::{Align, Endian, HasDataLayout, Size}; +use crate::builder::Builder; +use crate::type_::Type; +use crate::type_of::LayoutLlvmExt; +use crate::value::Value; + fn round_pointer_up_to_alignment<'ll>( bx: &mut Builder<'_, 'll, '_>, addr: &'ll Value, diff --git a/compiler/rustc_codegen_llvm/src/value.rs b/compiler/rustc_codegen_llvm/src/value.rs index 1338a229566..6295b0de356 100644 --- a/compiler/rustc_codegen_llvm/src/value.rs +++ b/compiler/rustc_codegen_llvm/src/value.rs @@ -1,10 +1,8 @@ -pub use crate::llvm::Value; +use std::hash::{Hash, Hasher}; +use std::{fmt, ptr}; use crate::llvm; - -use std::fmt; -use std::hash::{Hash, Hasher}; -use std::ptr; +pub use crate::llvm::Value; impl PartialEq for Value { fn eq(&self, other: &Self) -> bool { |
