diff options
| author | bors <bors@rust-lang.org> | 2025-04-30 17:15:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-04-30 17:15:51 +0000 |
| commit | 251cda5e1f0057eb04fd9fc1653f2f1e010e8f97 (patch) | |
| tree | a437ee3fb4d894188f3e7cb395d7c607935434a6 /compiler/rustc_codegen_ssa/src/codegen_attrs.rs | |
| parent | 7188f453111502962326022740e2657fce0a6939 (diff) | |
| parent | 1e440aecc84b7e208ad14667aac83c963e85cd32 (diff) | |
| download | rust-251cda5e1f0057eb04fd9fc1653f2f1e010e8f97.tar.gz rust-251cda5e1f0057eb04fd9fc1653f2f1e010e8f97.zip | |
Auto merge of #140520 - matthiaskrgr:rollup-7aoqcnp, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #134232 (Share the naked asm impl between cg_ssa and cg_clif) - #139624 (Don't allow flattened format_args in const.) - #140090 (Check bare function idents for non snake-case name) - #140203 (Issue an error when using `no_mangle` on language items) - #140450 (ast: Remove token visiting from AST visitor) - #140498 (Misc tweaks to HIR typeck (mostly w.r.t. checking calls)) - #140504 (transmutability: ensure_sufficient_stack when answering query) - #140506 (unstable-book: fix capitalization) - #140516 (Replace use of rustc_type_ir by rustc_middle) Failed merges: - #140374 (Resolve instance for SymFn in global/naked asm) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/codegen_attrs.rs')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/codegen_attrs.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index b0c53ec93ce..5d09e62f274 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -87,6 +87,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { let mut link_ordinal_span = None; let mut no_sanitize_span = None; let mut mixed_export_name_no_mangle_lint_state = MixedExportNameAndNoMangleState::default(); + let mut no_mangle_span = None; for attr in attrs.iter() { // In some cases, attribute are only valid on functions, but it's the `check_attr` @@ -139,6 +140,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { } sym::naked => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED, sym::no_mangle => { + no_mangle_span = Some(attr.span()); if tcx.opt_item_name(did.to_def_id()).is_some() { codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE; mixed_export_name_no_mangle_lint_state.track_no_mangle( @@ -621,6 +623,34 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { } check_link_name_xor_ordinal(tcx, &codegen_fn_attrs, link_ordinal_span); + if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) + && codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE) + { + let lang_item = + lang_items::extract(attrs).map_or(None, |(name, _span)| LangItem::from_name(name)); + let mut err = tcx + .dcx() + .struct_span_err( + no_mangle_span.unwrap_or_default(), + "`#[no_mangle]` cannot be used on internal language items", + ) + .with_note("Rustc requires this item to have a specific mangled name.") + .with_span_label(tcx.def_span(did), "should be the internal language item"); + if let Some(lang_item) = lang_item { + if let Some(link_name) = lang_item.link_name() { + err = err + .with_note("If you are trying to prevent mangling to ease debugging, many") + .with_note(format!( + "debuggers support a command such as `rbreak {link_name}` to" + )) + .with_note(format!( + "match `.*{link_name}.*` instead of `break {link_name}` on a specific name" + )) + } + } + err.emit(); + } + // Any linkage to LLVM intrinsics for now forcibly marks them all as never // unwinds since LLVM sometimes can't handle codegen which `invoke`s // intrinsic functions. |
