Skip to content

Commit

Permalink
Rollup merge of rust-lang#112683 - asquared31415:asm_clobber_ice, r=c…
Browse files Browse the repository at this point in the history
…ompiler-errors

fix ICE on specific malformed asm clobber_abi

fixes rust-lang#112635
  • Loading branch information
Dylan-DPC authored Jun 16, 2023
2 parents 7f3557c + e8824d6 commit d2836a4
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 51 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
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 Down
Loading

0 comments on commit d2836a4

Please sign in to comment.