Merge pull request #20210 from ChayimFriedman2/naked-asm-safe

fix: Inline asm fixes
This commit is contained in:
Shoyu Vanilla (Flint) 2025-07-10 06:28:49 +00:00 committed by GitHub
commit e9968fc555
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 303 additions and 84 deletions

View file

@ -4,7 +4,7 @@ use crate::grammar::attributes::ATTRIBUTE_FIRST;
use super::*;
pub(super) use atom::{EXPR_RECOVERY_SET, LITERAL_FIRST, literal};
pub(super) use atom::{EXPR_RECOVERY_SET, LITERAL_FIRST, literal, parse_asm_expr};
pub(crate) use atom::{block_expr, match_arm_list};
#[derive(PartialEq, Eq)]

View file

@ -253,8 +253,7 @@ fn builtin_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
let m = p.start();
p.bump_remap(T![builtin]);
p.bump(T![#]);
if p.at_contextual_kw(T![offset_of]) {
p.bump_remap(T![offset_of]);
if p.eat_contextual_kw(T![offset_of]) {
p.expect(T!['(']);
type_(p);
p.expect(T![,]);
@ -278,8 +277,7 @@ fn builtin_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
p.expect(T![')']);
}
Some(m.complete(p, OFFSET_OF_EXPR))
} else if p.at_contextual_kw(T![format_args]) {
p.bump_remap(T![format_args]);
} else if p.eat_contextual_kw(T![format_args]) {
p.expect(T!['(']);
expr(p);
if p.eat(T![,]) {
@ -302,7 +300,16 @@ fn builtin_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
}
p.expect(T![')']);
Some(m.complete(p, FORMAT_ARGS_EXPR))
} else if p.at_contextual_kw(T![asm]) {
} else if p.eat_contextual_kw(T![asm])
|| p.eat_contextual_kw(T![global_asm])
|| p.eat_contextual_kw(T![naked_asm])
{
// test asm_kinds
// fn foo() {
// builtin#asm("");
// builtin#global_asm("");
// builtin#naked_asm("");
// }
parse_asm_expr(p, m)
} else {
m.abandon(p);
@ -321,8 +328,7 @@ fn builtin_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
// tmp = out(reg) _,
// );
// }
fn parse_asm_expr(p: &mut Parser<'_>, m: Marker) -> Option<CompletedMarker> {
p.bump_remap(T![asm]);
pub(crate) fn parse_asm_expr(p: &mut Parser<'_>, m: Marker) -> Option<CompletedMarker> {
p.expect(T!['(']);
if expr(p).is_none() {
p.err_and_bump("expected asm template");

View file

@ -261,6 +261,19 @@ fn opt_item_without_modifiers(p: &mut Parser<'_>, m: Marker) -> Result<(), Marke
T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m),
T![static] if (la == IDENT || la == T![_] || la == T![mut]) => consts::static_(p, m),
IDENT
if p.at_contextual_kw(T![builtin])
&& p.nth_at(1, T![#])
&& p.nth_at_contextual_kw(2, T![global_asm]) =>
{
p.bump_remap(T![builtin]);
p.bump(T![#]);
p.bump_remap(T![global_asm]);
// test global_asm
// builtin#global_asm("")
expressions::parse_asm_expr(p, m);
}
_ => return Err(m),
};
Ok(())

File diff suppressed because one or more lines are too long