Skip to content

fix ICE on specific malformed asm clobber_abi #112683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,12 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
}

let mut new_abis = Vec::new();
loop {
while !p.eat(&token::CloseDelim(Delimiter::Parenthesis)) {
match p.parse_str_lit() {
Ok(str_lit) => {
new_abis.push((str_lit.symbol_unescaped, str_lit.span));
}
Err(opt_lit) => {
// If the non-string literal is a closing paren then it's the end of the list and is fine
if p.eat(&token::CloseDelim(Delimiter::Parenthesis)) {
break;
}
let span = opt_lit.map_or(p.token.span, |lit| lit.span);
let mut err =
p.sess.span_diagnostic.struct_span_err(span, "expected string literal");
Expand Down
34 changes: 24 additions & 10 deletions tests/ui/asm/x86_64/parse-error.rs → tests/ui/asm/parse-error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// only-x86_64
// needs-asm-support

#![feature(asm_const)]

Expand Down Expand Up @@ -38,6 +38,9 @@ fn main() {
//~^ ERROR expected one of
asm!("{}", options(), const foo);
//~^ ERROR attempt to use a non-constant value in a constant

// test that asm!'s clobber_abi doesn't accept non-string literals
// see also https://github.com/rust-lang/rust/issues/112635
asm!("", clobber_abi());
//~^ ERROR at least one abi must be provided
asm!("", clobber_abi(foo));
Expand All @@ -46,6 +49,25 @@ fn main() {
//~^ ERROR expected one of `)` or `,`, found `foo`
asm!("", clobber_abi("C", foo));
//~^ ERROR expected string literal
asm!("", clobber_abi(1));
//~^ ERROR expected string literal
asm!("", clobber_abi(()));
//~^ ERROR expected string literal
asm!("", clobber_abi(uwu));
//~^ ERROR expected string literal
asm!("", clobber_abi({}));
//~^ ERROR expected string literal
asm!("", clobber_abi(loop {}));
//~^ ERROR expected string literal
asm!("", clobber_abi(if));
//~^ ERROR expected string literal
asm!("", clobber_abi(do));
//~^ ERROR expected string literal
asm!("", clobber_abi(<));
//~^ ERROR expected string literal
asm!("", clobber_abi(.));
//~^ ERROR expected string literal

asm!("{}", clobber_abi("C"), const foo);
//~^ ERROR attempt to use a non-constant value in a constant
asm!("", options(), clobber_abi("C"));
Expand All @@ -56,15 +78,7 @@ fn main() {
//~^^ ERROR argument never used
//~^^^ ERROR attempt to use a non-constant value in a constant
//~^^^^ ERROR attempt to use a non-constant value in a constant
asm!("", a = in("eax") foo);
//~^ ERROR explicit register arguments cannot have names
asm!("{a}", in("eax") foo, a = const bar);
//~^ ERROR attempt to use a non-constant value in a constant
asm!("{a}", in("eax") foo, a = const bar);
//~^ ERROR attempt to use a non-constant value in a constant
asm!("{1}", in("eax") foo, const bar);
//~^ ERROR positional arguments cannot follow named arguments or explicit register arguments
//~^^ ERROR attempt to use a non-constant value in a constant

asm!("", options(), "");
//~^ ERROR expected one of
asm!("{}", in(reg) foo, "{}", out(reg) foo);
Expand Down
Loading