Skip to content

Commit

Permalink
Rollup merge of #112683 - asquared31415:asm_clobber_ice, r=compiler-e…
Browse files Browse the repository at this point in the history
…rrors

fix ICE on specific malformed asm clobber_abi

fixes #112635
  • Loading branch information
matthiaskrgr authored Jun 17, 2023
2 parents ba3e535 + 3dc793e commit 7051c84
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 96 deletions.
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

0 comments on commit 7051c84

Please sign in to comment.