diff options
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/abi.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/attributes.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/back/archive.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/back/write.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/base.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/builder.rs | 24 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/consts.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/context.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs | 35 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/debuginfo/utils.rs | 38 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/intrinsic.rs | 122 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/type_of.rs | 19 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/va_arg.rs | 52 |
14 files changed, 173 insertions, 170 deletions
diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index 8a11e3e71bc..c3994cef14f 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -599,13 +599,11 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { if self.conv == Conv::CCmseNonSecureCall { // This will probably get ignored on all targets but those supporting the TrustZone-M // extension (thumbv8m targets). - unsafe { - llvm::AddCallSiteAttrString( - callsite, - llvm::AttributePlace::Function, - cstr::cstr!("cmse_nonsecure_call"), - ); - } + llvm::AddCallSiteAttrString( + callsite, + llvm::AttributePlace::Function, + cstr::cstr!("cmse_nonsecure_call"), + ); } } } diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 30a52d6bd67..f6d7221d4e9 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -55,6 +55,19 @@ pub fn sanitize<'ll>(cx: &CodegenCx<'ll, '_>, no_sanitize: SanitizerSet, llfn: & if enabled.contains(SanitizerSet::HWADDRESS) { llvm::Attribute::SanitizeHWAddress.apply_llfn(Function, llfn); } + if enabled.contains(SanitizerSet::MEMTAG) { + // Check to make sure the mte target feature is actually enabled. + let sess = cx.tcx.sess; + let features = llvm_util::llvm_global_features(sess).join(","); + let mte_feature_enabled = features.rfind("+mte"); + let mte_feature_disabled = features.rfind("-mte"); + + if mte_feature_enabled.is_none() || (mte_feature_disabled > mte_feature_enabled) { + sess.err("`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`"); + } + + llvm::Attribute::SanitizeMemTag.apply_llfn(Function, llfn); + } } /// Tell LLVM to emit or not emit the information necessary to unwind the stack for the function. diff --git a/compiler/rustc_codegen_llvm/src/back/archive.rs b/compiler/rustc_codegen_llvm/src/back/archive.rs index 21bd1dae7ac..1a2cec2a0d9 100644 --- a/compiler/rustc_codegen_llvm/src/back/archive.rs +++ b/compiler/rustc_codegen_llvm/src/back/archive.rs @@ -310,10 +310,7 @@ impl<'a> LlvmArchiveBuilder<'a> { if let Some(archive) = self.src_archive() { for child in archive.iter() { let child = child.map_err(string_to_io_error)?; - let child_name = match child.name() { - Some(s) => s, - None => continue, - }; + let Some(child_name) = child.name() else { continue }; if removals.iter().any(|r| r == child_name) { continue; } diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 384596dfff5..e60ad170434 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -826,20 +826,14 @@ pub(crate) unsafe fn codegen( let input = unsafe { slice::from_raw_parts(input_ptr as *const u8, input_len as usize) }; - let input = match str::from_utf8(input) { - Ok(s) => s, - Err(_) => return 0, - }; + let Ok(input) = str::from_utf8(input) else { return 0 }; let output = unsafe { slice::from_raw_parts_mut(output_ptr as *mut u8, output_len as usize) }; let mut cursor = io::Cursor::new(output); - let demangled = match rustc_demangle::try_demangle(input) { - Ok(d) => d, - Err(_) => return 0, - }; + let Ok(demangled) = rustc_demangle::try_demangle(input) else { return 0 }; if write!(cursor, "{:#}", demangled).is_err() { // Possible only if provided buffer is not big enough diff --git a/compiler/rustc_codegen_llvm/src/base.rs b/compiler/rustc_codegen_llvm/src/base.rs index 7b6ce5ea89b..e15b86aa84f 100644 --- a/compiler/rustc_codegen_llvm/src/base.rs +++ b/compiler/rustc_codegen_llvm/src/base.rs @@ -138,10 +138,7 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol) -> (ModuleCodegen } pub fn set_link_section(llval: &Value, attrs: &CodegenFnAttrs) { - let sect = match attrs.link_section { - Some(name) => name, - None => return, - }; + let Some(sect) = attrs.link_section else { return }; unsafe { let buf = SmallCStr::new(sect.as_str()); llvm::LLVMSetSection(llval, buf.as_ptr()); diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index c9a04e6280f..780af5bc2af 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -166,9 +166,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { Self::append_block(self.cx, self.llfn(), name) } - fn build_sibling_block(&mut self, name: &str) -> Self { - let llbb = self.append_sibling_block(name); - Self::build(self.cx, llbb) + fn switch_to_block(&mut self, llbb: Self::BasicBlock) { + *self = Self::build(self.cx, llbb) } fn ret_void(&mut self) { @@ -544,16 +543,19 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { let start = dest.project_index(&mut self, zero).llval; let end = dest.project_index(&mut self, count).llval; - let mut header_bx = self.build_sibling_block("repeat_loop_header"); - let mut body_bx = self.build_sibling_block("repeat_loop_body"); - let next_bx = self.build_sibling_block("repeat_loop_next"); + let header_bb = self.append_sibling_block("repeat_loop_header"); + let body_bb = self.append_sibling_block("repeat_loop_body"); + let next_bb = self.append_sibling_block("repeat_loop_next"); - self.br(header_bx.llbb()); + self.br(header_bb); + + let mut header_bx = Self::build(self.cx, header_bb); let current = header_bx.phi(self.val_ty(start), &[start], &[self.llbb()]); let keep_going = header_bx.icmp(IntPredicate::IntNE, current, end); - header_bx.cond_br(keep_going, body_bx.llbb(), next_bx.llbb()); + header_bx.cond_br(keep_going, body_bb, next_bb); + let mut body_bx = Self::build(self.cx, body_bb); let align = dest.align.restrict_for_offset(dest.layout.field(self.cx(), 0).size); cg_elem .val @@ -564,10 +566,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { current, &[self.const_usize(1)], ); - body_bx.br(header_bx.llbb()); - header_bx.add_incoming_to_phi(current, next, body_bx.llbb()); + body_bx.br(header_bb); + header_bx.add_incoming_to_phi(current, next, body_bb); - next_bx + Self::build(self.cx, next_bb) } fn range_metadata(&mut self, load: &'ll Value, range: WrappingRange) { diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 9ab822f01f1..c98720944c9 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -366,10 +366,9 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> { unsafe { let attrs = self.tcx.codegen_fn_attrs(def_id); - let (v, alloc) = match codegen_static_initializer(self, def_id) { - Ok(v) => v, + let Ok((v, alloc)) = codegen_static_initializer(self, def_id) else { // Error has already been reported - Err(_) => return, + return; }; let g = self.get_static(def_id); diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index ec68f6eb0f8..90ddf791450 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -292,7 +292,7 @@ pub unsafe fn create_module<'ll>( "sign-return-address-all\0".as_ptr().cast(), pac_opts.leaf.into(), ); - let is_bkey = if pac_opts.key == PAuthKey::A { false } else { true }; + let is_bkey: bool = pac_opts.key != PAuthKey::A; llvm::LLVMRustAddModuleFlag( llmod, llvm::LLVMModFlagBehavior::Error, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 1abc3fb523d..d515502d445 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -87,7 +87,7 @@ const DW_ATE_signed: c_uint = 0x05; #[allow(non_upper_case_globals)] const DW_ATE_unsigned: c_uint = 0x07; #[allow(non_upper_case_globals)] -const DW_ATE_unsigned_char: c_uint = 0x08; +const DW_ATE_UTF: c_uint = 0x10; pub const UNKNOWN_LINE_NUMBER: c_uint = 0; pub const UNKNOWN_COLUMN_NUMBER: c_uint = 0; @@ -449,7 +449,10 @@ fn pointer_or_reference_metadata<'ll, 'tcx>( // This is a thin pointer. Create a regular pointer type and give it the correct name. debug_assert_eq!( (thin_pointer_size, thin_pointer_align), - cx.size_and_align_of(ptr_type) + cx.size_and_align_of(ptr_type), + "ptr_type={}, pointee_type={}", + ptr_type, + pointee_type, ); unsafe { @@ -752,9 +755,8 @@ pub fn type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll prepare_enum_metadata(cx, t, def.did, unique_type_id, vec![]).finalize(cx) } }, - ty::Tuple(elements) => { - let tys: Vec<_> = elements.iter().map(|k| k.expect_ty()).collect(); - prepare_tuple_metadata(cx, t, &tys, unique_type_id, NO_SCOPE_METADATA).finalize(cx) + ty::Tuple(tys) => { + prepare_tuple_metadata(cx, t, tys, unique_type_id, NO_SCOPE_METADATA).finalize(cx) } // Type parameters from polymorphized functions. ty::Param(_) => MetadataCreationResult::new(param_type_metadata(cx, t), false), @@ -766,18 +768,15 @@ pub fn type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll if already_stored_in_typemap { // Also make sure that we already have a `TypeMap` entry for the unique type ID. - let metadata_for_uid = match type_map.find_metadata_for_unique_id(unique_type_id) { - Some(metadata) => metadata, - None => { - bug!( - "expected type metadata for unique \ - type ID '{}' to already be in \ - the `debuginfo::TypeMap` but it \ - was not. (Ty = {})", - type_map.get_unique_type_id_as_string(unique_type_id), - t - ); - } + let Some(metadata_for_uid) = type_map.find_metadata_for_unique_id(unique_type_id) else { + bug!( + "expected type metadata for unique \ + type ID '{}' to already be in \ + the `debuginfo::TypeMap` but it \ + was not. (Ty = {})", + type_map.get_unique_type_id_as_string(unique_type_id), + t + ); }; match type_map.find_metadata_for_type(t) { @@ -937,7 +936,7 @@ fn basic_type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'l ty::Never => ("!", DW_ATE_unsigned), ty::Tuple(elements) if elements.is_empty() => ("()", DW_ATE_unsigned), ty::Bool => ("bool", DW_ATE_boolean), - ty::Char => ("char", DW_ATE_unsigned_char), + ty::Char => ("char", DW_ATE_UTF), ty::Int(int_ty) if cpp_like_debuginfo => (int_ty.msvc_basic_name(), DW_ATE_signed), ty::Uint(uint_ty) if cpp_like_debuginfo => (uint_ty.msvc_basic_name(), DW_ATE_unsigned), ty::Float(float_ty) if cpp_like_debuginfo => (float_ty.msvc_basic_name(), DW_ATE_float), diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs b/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs index 6dd0d58efe3..fa75463067f 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs @@ -4,9 +4,9 @@ use super::namespace::item_namespace; use super::CrateDebugContext; use rustc_hir::def_id::DefId; -use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::layout::{HasParamEnv, LayoutOf}; use rustc_middle::ty::{self, DefIdTree, Ty}; -use rustc_target::abi::VariantIdx; +use tracing::trace; use crate::common::CodegenCx; use crate::llvm; @@ -63,35 +63,26 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, pointee_ty: Ty<'tcx>, ) -> Option<FatPtrKind> { - let layout = cx.layout_of(pointee_ty); + let pointee_tail_ty = cx.tcx.struct_tail_erasing_lifetimes(pointee_ty, cx.param_env()); + let layout = cx.layout_of(pointee_tail_ty); + trace!( + "fat_pointer_kind: {:?} has layout {:?} (is_unsized? {})", + pointee_tail_ty, + layout, + layout.is_unsized() + ); if !layout.is_unsized() { return None; } - match *pointee_ty.kind() { + match *pointee_tail_ty.kind() { ty::Str | ty::Slice(_) => Some(FatPtrKind::Slice), ty::Dynamic(..) => Some(FatPtrKind::Dyn), - ty::Adt(adt_def, _) => { - assert!(adt_def.is_struct()); - assert!(adt_def.variants.len() == 1); - let variant = &adt_def.variants[VariantIdx::from_usize(0)]; - assert!(!variant.fields.is_empty()); - let last_field_index = variant.fields.len() - 1; - - debug_assert!( - (0..last_field_index) - .all(|field_index| { !layout.field(cx, field_index).is_unsized() }) - ); - - let unsized_field = layout.field(cx, last_field_index); - assert!(unsized_field.is_unsized()); - fat_pointer_kind(cx, unsized_field.ty) - } ty::Foreign(_) => { // Assert that pointers to foreign types really are thin: debug_assert_eq!( - cx.size_of(cx.tcx.mk_imm_ptr(pointee_ty)), + cx.size_of(cx.tcx.mk_imm_ptr(pointee_tail_ty)), cx.size_of(cx.tcx.mk_imm_ptr(cx.tcx.types.u8)) ); None @@ -99,7 +90,10 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>( _ => { // For all other pointee types we should already have returned None // at the beginning of the function. - panic!("fat_pointer_kind() - Encountered unexpected `pointee_ty`: {:?}", pointee_ty) + panic!( + "fat_pointer_kind() - Encountered unexpected `pointee_tail_ty`: {:?}", + pointee_tail_ty + ) } } } diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index cfd23f5c24e..e7c13e793d9 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -88,9 +88,8 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> { let tcx = self.tcx; let callee_ty = instance.ty(tcx, ty::ParamEnv::reveal_all()); - let (def_id, substs) = match *callee_ty.kind() { - ty::FnDef(def_id, substs) => (def_id, substs), - _ => bug!("expected fn item type, found {}", callee_ty), + let ty::FnDef(def_id, substs) = *callee_ty.kind() else { + bug!("expected fn item type, found {}", callee_ty); }; let sig = callee_ty.fn_sig(tcx); @@ -453,11 +452,11 @@ fn codegen_msvc_try<'ll>( let (llty, llfn) = get_rust_try_fn(bx, &mut |mut bx| { bx.set_personality_fn(bx.eh_personality()); - let mut normal = bx.build_sibling_block("normal"); - let mut catchswitch = bx.build_sibling_block("catchswitch"); - let mut catchpad_rust = bx.build_sibling_block("catchpad_rust"); - let mut catchpad_foreign = bx.build_sibling_block("catchpad_foreign"); - let mut caught = bx.build_sibling_block("caught"); + let normal = bx.append_sibling_block("normal"); + let catchswitch = bx.append_sibling_block("catchswitch"); + let catchpad_rust = bx.append_sibling_block("catchpad_rust"); + let catchpad_foreign = bx.append_sibling_block("catchpad_foreign"); + let caught = bx.append_sibling_block("caught"); let try_func = llvm::get_param(bx.llfn(), 0); let data = llvm::get_param(bx.llfn(), 1); @@ -521,12 +520,13 @@ fn codegen_msvc_try<'ll>( let ptr_align = bx.tcx().data_layout.pointer_align.abi; let slot = bx.alloca(bx.type_i8p(), ptr_align); let try_func_ty = bx.type_func(&[bx.type_i8p()], bx.type_void()); - bx.invoke(try_func_ty, try_func, &[data], normal.llbb(), catchswitch.llbb(), None); + bx.invoke(try_func_ty, try_func, &[data], normal, catchswitch, None); - normal.ret(bx.const_i32(0)); + bx.switch_to_block(normal); + bx.ret(bx.const_i32(0)); - let cs = - catchswitch.catch_switch(None, None, &[catchpad_rust.llbb(), catchpad_foreign.llbb()]); + bx.switch_to_block(catchswitch); + let cs = bx.catch_switch(None, None, &[catchpad_rust, catchpad_foreign]); // We can't use the TypeDescriptor defined in libpanic_unwind because it // might be in another DLL and the SEH encoding only supports specifying @@ -559,21 +559,24 @@ fn codegen_msvc_try<'ll>( // since our exception object effectively contains a Box. // // Source: MicrosoftCXXABI::getAddrOfCXXCatchHandlerType in clang + bx.switch_to_block(catchpad_rust); let flags = bx.const_i32(8); - let funclet = catchpad_rust.catch_pad(cs, &[tydesc, flags, slot]); - let ptr = catchpad_rust.load(bx.type_i8p(), slot, ptr_align); + let funclet = bx.catch_pad(cs, &[tydesc, flags, slot]); + let ptr = bx.load(bx.type_i8p(), slot, ptr_align); let catch_ty = bx.type_func(&[bx.type_i8p(), bx.type_i8p()], bx.type_void()); - catchpad_rust.call(catch_ty, catch_func, &[data, ptr], Some(&funclet)); - catchpad_rust.catch_ret(&funclet, caught.llbb()); + bx.call(catch_ty, catch_func, &[data, ptr], Some(&funclet)); + bx.catch_ret(&funclet, caught); // The flag value of 64 indicates a "catch-all". + bx.switch_to_block(catchpad_foreign); let flags = bx.const_i32(64); let null = bx.const_null(bx.type_i8p()); - let funclet = catchpad_foreign.catch_pad(cs, &[null, flags, null]); - catchpad_foreign.call(catch_ty, catch_func, &[data, null], Some(&funclet)); - catchpad_foreign.catch_ret(&funclet, caught.llbb()); + let funclet = bx.catch_pad(cs, &[null, flags, null]); + bx.call(catch_ty, catch_func, &[data, null], Some(&funclet)); + bx.catch_ret(&funclet, caught); - caught.ret(bx.const_i32(1)); + bx.switch_to_block(caught); + bx.ret(bx.const_i32(1)); }); // Note that no invoke is used here because by definition this function @@ -614,15 +617,17 @@ fn codegen_gnu_try<'ll>( // (%ptr, _) = landingpad // call %catch_func(%data, %ptr) // ret 1 - let mut then = bx.build_sibling_block("then"); - let mut catch = bx.build_sibling_block("catch"); + let then = bx.append_sibling_block("then"); + let catch = bx.append_sibling_block("catch"); let try_func = llvm::get_param(bx.llfn(), 0); let data = llvm::get_param(bx.llfn(), 1); let catch_func = llvm::get_param(bx.llfn(), 2); let try_func_ty = bx.type_func(&[bx.type_i8p()], bx.type_void()); - bx.invoke(try_func_ty, try_func, &[data], then.llbb(), catch.llbb(), None); - then.ret(bx.const_i32(0)); + bx.invoke(try_func_ty, try_func, &[data], then, catch, None); + + bx.switch_to_block(then); + bx.ret(bx.const_i32(0)); // Type indicator for the exception being thrown. // @@ -630,14 +635,15 @@ fn codegen_gnu_try<'ll>( // being thrown. The second value is a "selector" indicating which of // the landing pad clauses the exception's type had been matched to. // rust_try ignores the selector. + bx.switch_to_block(catch); let lpad_ty = bx.type_struct(&[bx.type_i8p(), bx.type_i32()], false); - let vals = catch.landing_pad(lpad_ty, bx.eh_personality(), 1); + let vals = bx.landing_pad(lpad_ty, bx.eh_personality(), 1); let tydesc = bx.const_null(bx.type_i8p()); - catch.add_clause(vals, tydesc); - let ptr = catch.extract_value(vals, 0); + bx.add_clause(vals, tydesc); + let ptr = bx.extract_value(vals, 0); let catch_ty = bx.type_func(&[bx.type_i8p(), bx.type_i8p()], bx.type_void()); - catch.call(catch_ty, catch_func, &[data, ptr], None); - catch.ret(bx.const_i32(1)); + bx.call(catch_ty, catch_func, &[data, ptr], None); + bx.ret(bx.const_i32(1)); }); // Note that no invoke is used here because by definition this function @@ -675,57 +681,54 @@ fn codegen_emcc_try<'ll>( // %catch_data[1] = %is_rust_panic // call %catch_func(%data, %catch_data) // ret 1 - let mut then = bx.build_sibling_block("then"); - let mut catch = bx.build_sibling_block("catch"); + let then = bx.append_sibling_block("then"); + let catch = bx.append_sibling_block("catch"); let try_func = llvm::get_param(bx.llfn(), 0); let data = llvm::get_param(bx.llfn(), 1); let catch_func = llvm::get_param(bx.llfn(), 2); let try_func_ty = bx.type_func(&[bx.type_i8p()], bx.type_void()); - bx.invoke(try_func_ty, try_func, &[data], then.llbb(), catch.llbb(), None); - then.ret(bx.const_i32(0)); + bx.invoke(try_func_ty, try_func, &[data], then, catch, None); + + bx.switch_to_block(then); + bx.ret(bx.const_i32(0)); // Type indicator for the exception being thrown. // // The first value in this tuple is a pointer to the exception object // being thrown. The second value is a "selector" indicating which of // the landing pad clauses the exception's type had been matched to. + bx.switch_to_block(catch); let tydesc = bx.eh_catch_typeinfo(); let lpad_ty = bx.type_struct(&[bx.type_i8p(), bx.type_i32()], false); - let vals = catch.landing_pad(lpad_ty, bx.eh_personality(), 2); - catch.add_clause(vals, tydesc); - catch.add_clause(vals, bx.const_null(bx.type_i8p())); - let ptr = catch.extract_value(vals, 0); - let selector = catch.extract_value(vals, 1); + let vals = bx.landing_pad(lpad_ty, bx.eh_personality(), 2); + bx.add_clause(vals, tydesc); + bx.add_clause(vals, bx.const_null(bx.type_i8p())); + let ptr = bx.extract_value(vals, 0); + let selector = bx.extract_value(vals, 1); // Check if the typeid we got is the one for a Rust panic. - let rust_typeid = catch.call_intrinsic("llvm.eh.typeid.for", &[tydesc]); - let is_rust_panic = catch.icmp(IntPredicate::IntEQ, selector, rust_typeid); - let is_rust_panic = catch.zext(is_rust_panic, bx.type_bool()); + let rust_typeid = bx.call_intrinsic("llvm.eh.typeid.for", &[tydesc]); + let is_rust_panic = bx.icmp(IntPredicate::IntEQ, selector, rust_typeid); + let is_rust_panic = bx.zext(is_rust_panic, bx.type_bool()); // We need to pass two values to catch_func (ptr and is_rust_panic), so // create an alloca and pass a pointer to that. let ptr_align = bx.tcx().data_layout.pointer_align.abi; let i8_align = bx.tcx().data_layout.i8_align.abi; let catch_data_type = bx.type_struct(&[bx.type_i8p(), bx.type_bool()], false); - let catch_data = catch.alloca(catch_data_type, ptr_align); - let catch_data_0 = catch.inbounds_gep( - catch_data_type, - catch_data, - &[bx.const_usize(0), bx.const_usize(0)], - ); - catch.store(ptr, catch_data_0, ptr_align); - let catch_data_1 = catch.inbounds_gep( - catch_data_type, - catch_data, - &[bx.const_usize(0), bx.const_usize(1)], - ); - catch.store(is_rust_panic, catch_data_1, i8_align); - let catch_data = catch.bitcast(catch_data, bx.type_i8p()); + let catch_data = bx.alloca(catch_data_type, ptr_align); + let catch_data_0 = + bx.inbounds_gep(catch_data_type, catch_data, &[bx.const_usize(0), bx.const_usize(0)]); + bx.store(ptr, catch_data_0, ptr_align); + let catch_data_1 = + bx.inbounds_gep(catch_data_type, catch_data, &[bx.const_usize(0), bx.const_usize(1)]); + bx.store(is_rust_panic, catch_data_1, i8_align); + let catch_data = bx.bitcast(catch_data, bx.type_i8p()); let catch_ty = bx.type_func(&[bx.type_i8p(), bx.type_i8p()], bx.type_void()); - catch.call(catch_ty, catch_func, &[data, catch_data], None); - catch.ret(bx.const_i32(1)); + bx.call(catch_ty, catch_func, &[data, catch_data], None); + bx.ret(bx.const_i32(1)); }); // Note that no invoke is used here because by definition this function @@ -1000,9 +1003,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>( } }) .collect(); - let indices = match indices { - Some(i) => i, - None => return Ok(bx.const_null(llret_ty)), + let Some(indices) = indices else { + return Ok(bx.const_null(llret_ty)); }; return Ok(bx.shuffle_vector( diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 90d4367a280..657f1fcf31e 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -190,6 +190,7 @@ pub enum Attribute { StackProtectStrong = 31, StackProtect = 32, NoUndef = 33, + SanitizeMemTag = 34, } /// LLVMIntPredicate diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs index fafb9a6dbde..da378dc6493 100644 --- a/compiler/rustc_codegen_llvm/src/type_of.rs +++ b/compiler/rustc_codegen_llvm/src/type_of.rs @@ -1,5 +1,6 @@ use crate::common::*; use crate::context::TypeLowering; +use crate::llvm_util::get_version; use crate::type_::Type; use rustc_codegen_ssa::traits::*; use rustc_middle::bug; @@ -42,9 +43,13 @@ fn uncached_llvm_type<'a, 'tcx>( // FIXME(eddyb) producing readable type names for trait objects can result // in problematically distinct types due to HRTB and subtyping (see #47638). // ty::Dynamic(..) | - ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Generator(..) | ty::Str => { - let mut name = - with_no_visible_paths(|| with_no_trimmed_paths(|| layout.ty.to_string())); + ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Generator(..) | ty::Str + // For performance reasons we use names only when emitting LLVM IR. Unless we are on + // LLVM < 14, where the use of unnamed types resulted in various issues, e.g., #76213, + // #79564, and #79246. + if get_version() < (14, 0, 0) || !cx.sess().fewer_names() => + { + let mut name = with_no_visible_paths!(with_no_trimmed_paths!(layout.ty.to_string())); if let (&ty::Adt(def, _), &Variants::Single { index }) = (layout.ty.kind(), &layout.variants) { @@ -59,6 +64,9 @@ fn uncached_llvm_type<'a, 'tcx>( } Some(name) } + // Use identified structure types for ADT. Due to pointee types in LLVM IR their definition + // might be recursive. Other cases are non-recursive and we can use literal structure types. + ty::Adt(..) => Some(String::new()), _ => None, }; @@ -339,9 +347,8 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { _ => {} } - let (a, b) = match self.abi { - Abi::ScalarPair(a, b) => (a, b), - _ => bug!("TyAndLayout::scalar_pair_element_llty({:?}): not applicable", self), + let Abi::ScalarPair(a, b) = self.abi else { + bug!("TyAndLayout::scalar_pair_element_llty({:?}): not applicable", self); }; let scalar = [a, b][index]; diff --git a/compiler/rustc_codegen_llvm/src/va_arg.rs b/compiler/rustc_codegen_llvm/src/va_arg.rs index f090ae6ecb4..ceb3d5a84ab 100644 --- a/compiler/rustc_codegen_llvm/src/va_arg.rs +++ b/compiler/rustc_codegen_llvm/src/va_arg.rs @@ -102,10 +102,10 @@ fn emit_aapcs_va_arg<'ll, 'tcx>( let va_list_ty = va_list_layout.llvm_type(bx); let layout = bx.cx.layout_of(target_ty); - let mut maybe_reg = bx.build_sibling_block("va_arg.maybe_reg"); - let mut in_reg = bx.build_sibling_block("va_arg.in_reg"); - let mut on_stack = bx.build_sibling_block("va_arg.on_stack"); - let mut end = bx.build_sibling_block("va_arg.end"); + let maybe_reg = bx.append_sibling_block("va_arg.maybe_reg"); + let in_reg = bx.append_sibling_block("va_arg.in_reg"); + let on_stack = bx.append_sibling_block("va_arg.on_stack"); + let end = bx.append_sibling_block("va_arg.end"); let zero = bx.const_i32(0); let offset_align = Align::from_bytes(4).unwrap(); @@ -125,53 +125,53 @@ fn emit_aapcs_va_arg<'ll, 'tcx>( // if the offset >= 0 then the value will be on the stack let mut reg_off_v = bx.load(bx.type_i32(), reg_off, offset_align); let use_stack = bx.icmp(IntPredicate::IntSGE, reg_off_v, zero); - bx.cond_br(use_stack, on_stack.llbb(), maybe_reg.llbb()); + bx.cond_br(use_stack, on_stack, maybe_reg); // The value at this point might be in a register, but there is a chance that // it could be on the stack so we have to update the offset and then check // the offset again. + bx.switch_to_block(maybe_reg); if gr_type && layout.align.abi.bytes() > 8 { - reg_off_v = maybe_reg.add(reg_off_v, bx.const_i32(15)); - reg_off_v = maybe_reg.and(reg_off_v, bx.const_i32(-16)); + reg_off_v = bx.add(reg_off_v, bx.const_i32(15)); + reg_off_v = bx.and(reg_off_v, bx.const_i32(-16)); } - let new_reg_off_v = maybe_reg.add(reg_off_v, bx.const_i32(slot_size as i32)); + let new_reg_off_v = bx.add(reg_off_v, bx.const_i32(slot_size as i32)); - maybe_reg.store(new_reg_off_v, reg_off, offset_align); + bx.store(new_reg_off_v, reg_off, offset_align); // Check to see if we have overflowed the registers as a result of this. // If we have then we need to use the stack for this value - let use_stack = maybe_reg.icmp(IntPredicate::IntSGT, new_reg_off_v, zero); - maybe_reg.cond_br(use_stack, on_stack.llbb(), in_reg.llbb()); + let use_stack = bx.icmp(IntPredicate::IntSGT, new_reg_off_v, zero); + bx.cond_br(use_stack, on_stack, in_reg); + bx.switch_to_block(in_reg); let top_type = bx.type_i8p(); - let top = in_reg.struct_gep(va_list_ty, va_list_addr, reg_top_index); - let top = in_reg.load(top_type, top, bx.tcx().data_layout.pointer_align.abi); + let top = bx.struct_gep(va_list_ty, va_list_addr, reg_top_index); + let top = bx.load(top_type, top, bx.tcx().data_layout.pointer_align.abi); // reg_value = *(@top + reg_off_v); - let mut reg_addr = in_reg.gep(bx.type_i8(), top, &[reg_off_v]); + let mut reg_addr = bx.gep(bx.type_i8(), top, &[reg_off_v]); if bx.tcx().sess.target.endian == Endian::Big && layout.size.bytes() != slot_size { // On big-endian systems the value is right-aligned in its slot. let offset = bx.const_i32((slot_size - layout.size.bytes()) as i32); - reg_addr = in_reg.gep(bx.type_i8(), reg_addr, &[offset]); + reg_addr = bx.gep(bx.type_i8(), reg_addr, &[offset]); } let reg_type = layout.llvm_type(bx); - let reg_addr = in_reg.bitcast(reg_addr, bx.cx.type_ptr_to(reg_type)); - let reg_value = in_reg.load(reg_type, reg_addr, layout.align.abi); - in_reg.br(end.llbb()); + let reg_addr = bx.bitcast(reg_addr, bx.cx.type_ptr_to(reg_type)); + let reg_value = bx.load(reg_type, reg_addr, layout.align.abi); + bx.br(end); // On Stack block + bx.switch_to_block(on_stack); let stack_value = - emit_ptr_va_arg(&mut on_stack, list, target_ty, false, Align::from_bytes(8).unwrap(), true); - on_stack.br(end.llbb()); + emit_ptr_va_arg(bx, list, target_ty, false, Align::from_bytes(8).unwrap(), true); + bx.br(end); - let val = end.phi( - layout.immediate_llvm_type(bx), - &[reg_value, stack_value], - &[in_reg.llbb(), on_stack.llbb()], - ); + bx.switch_to_block(end); + let val = + bx.phi(layout.immediate_llvm_type(bx), &[reg_value, stack_value], &[in_reg, on_stack]); - *bx = end; val } |
