Skip to content

Commit fa00657

Browse files
committed
Add GlobalAsm as a valid ItemKind to StableMIR
This fixes StableMIR crash when iterating over the items of a crate that contains global assembly.
1 parent f9e0239 commit fa00657

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind {
140140
| DefKind::OpaqueTy
141141
| DefKind::Field
142142
| DefKind::LifetimeParam
143-
| DefKind::Impl { .. }
144-
| DefKind::GlobalAsm => {
143+
| DefKind::Impl { .. } => {
145144
unreachable!("Not a valid item kind: {kind:?}");
146145
}
147146
DefKind::Closure | DefKind::AssocFn | DefKind::Fn | DefKind::SyntheticCoroutineBody => {
@@ -150,6 +149,7 @@ pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind {
150149
DefKind::Const | DefKind::InlineConst | DefKind::AssocConst | DefKind::AnonConst => {
151150
ItemKind::Const
152151
}
152+
DefKind::GlobalAsm => ItemKind::GlobalAsm,
153153
DefKind::Static { .. } => ItemKind::Static,
154154
DefKind::Ctor(_, rustc_hir::def::CtorKind::Const) => ItemKind::Ctor(CtorKind::Const),
155155
DefKind::Ctor(_, rustc_hir::def::CtorKind::Fn) => ItemKind::Ctor(CtorKind::Fn),

compiler/stable_mir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ pub enum ItemKind {
112112
Static,
113113
Const,
114114
Ctor(CtorKind),
115+
GlobalAsm,
115116
}
116117

117118
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Serialize)]

tests/ui-fulldeps/stable-mir/check_item_kind.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ const CRATE_NAME: &str = "input";
2626
/// This function uses the Stable MIR APIs to get information about the test crate.
2727
fn test_item_kind() -> ControlFlow<()> {
2828
let items = stable_mir::all_local_items();
29-
assert_eq!(items.len(), 4);
29+
assert_eq!(items.len(), 5);
3030
// Constructor item.
3131
for item in items {
3232
let expected_kind = match item.name().as_str() {
3333
"Dummy" => ItemKind::Ctor(CtorKind::Fn),
3434
"dummy" => ItemKind::Fn,
3535
"unit" => ItemKind::Fn,
3636
"DUMMY_CONST" => ItemKind::Const,
37+
name if name.contains("global_asm") => ItemKind::GlobalAsm,
3738
name => unreachable!("Unexpected item {name}"),
3839
};
3940
assert_eq!(item.kind(), expected_kind, "Mismatched type for {}", item.name());
@@ -75,6 +76,13 @@ fn generate_input(path: &str) -> std::io::Result<()> {
7576
pub fn unit() -> DummyUnit {{
7677
DummyUnit
7778
}}
79+
80+
std::arch::global_asm!(".global my_noop",
81+
".text",
82+
"my_noop:",
83+
"ret"
84+
);
85+
7886
"#
7987
)?;
8088
Ok(())

0 commit comments

Comments
 (0)