Skip to content

Commit 50237b3

Browse files
authored
Rollup merge of #149268 - davidtwco:v0-mangling-global-asm-namespace, r=Kivooeo
add implementation-internal namespace for globalasm Fixes #138261 Adds a namespace for `global_asm` with a lowercase letter which [is reserved for implementation-internal disambiguation](https://doc.rust-lang.org/rustc/symbol-mangling/v0.html#namespace:~:text=Lowercase%20letters%20are%20reserved%20for%20implementation%2Dinternal%20disambiguation%20categories%20(and%20demanglers%20should%20never%20show%20them)): > Lowercase letters are reserved for implementation-internal disambiguation categories (and demanglers should never show them) As a implementation-internal disambiguation category, the demangler implementations shouldn't need updated (i.e. if this were an uppercase letter, then our mangle-then-demangle checks would fail because the demangler would expect to have explicit handling). `'a'` is chosen arbitrarily, for **a**sm, but I can change it to something else if preferred. `#[rustc_symbol_name]` only looks at top-level items, and would need a bunch of changes to be able to check the symbol for `foo::{constant}::{closure}` in the `global_asm` in this test, so for now the test just checks this compiles. The alternative to this would be to prohibit declaration of items in the operand of a `global_asm`, which is a breaking change.
2 parents 2f566a8 + 8ed8f18 commit 50237b3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

compiler/rustc_symbol_mangling/src/v0.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,11 +882,11 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> {
882882
DefPathData::OpaqueTy => 'i',
883883
DefPathData::SyntheticCoroutineBody => 's',
884884
DefPathData::NestedStatic => 'n',
885+
DefPathData::GlobalAsm => 'a',
885886

886887
// These should never show up as `print_path_with_simple` arguments.
887888
DefPathData::CrateRoot
888889
| DefPathData::Use
889-
| DefPathData::GlobalAsm
890890
| DefPathData::Impl
891891
| DefPathData::MacroNs(_)
892892
| DefPathData::LifetimeNs(_)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ build-pass
2+
//@ compile-flags: -Clink-dead-code
3+
//@ needs-asm-support
4+
5+
#![allow(unused)]
6+
7+
// Test that a symbol in a `global_asm` namespace doesn't cause an ICE during v0 symbol mangling
8+
// due to a lack of missing namespace character for `global_asm`.
9+
//
10+
// FIXME: Can't use `#[rustc_symbol_name]` on the `foo` call to check its symbol, so just checking
11+
// the test compiles.
12+
13+
fn foo<const N: usize>() {}
14+
15+
core::arch::global_asm!("/* {} */", sym foo::<{
16+
|| {};
17+
0
18+
}>);
19+
20+
fn main() {}

0 commit comments

Comments
 (0)