Skip to content

Commit 7051c84

Browse files
authored
Rollup merge of #112683 - asquared31415:asm_clobber_ice, r=compiler-errors
fix ICE on specific malformed asm clobber_abi fixes #112635
2 parents ba3e535 + 3dc793e commit 7051c84

File tree

5 files changed

+184
-96
lines changed

5 files changed

+184
-96
lines changed

compiler/rustc_builtin_macros/src/asm.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -379,16 +379,12 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
379379
}
380380

381381
let mut new_abis = Vec::new();
382-
loop {
382+
while !p.eat(&token::CloseDelim(Delimiter::Parenthesis)) {
383383
match p.parse_str_lit() {
384384
Ok(str_lit) => {
385385
new_abis.push((str_lit.symbol_unescaped, str_lit.span));
386386
}
387387
Err(opt_lit) => {
388-
// If the non-string literal is a closing paren then it's the end of the list and is fine
389-
if p.eat(&token::CloseDelim(Delimiter::Parenthesis)) {
390-
break;
391-
}
392388
let span = opt_lit.map_or(p.token.span, |lit| lit.span);
393389
let mut err =
394390
p.sess.span_diagnostic.struct_span_err(span, "expected string literal");

tests/ui/asm/x86_64/parse-error.rs renamed to tests/ui/asm/parse-error.rs

+24-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// only-x86_64
1+
// needs-asm-support
22

33
#![feature(asm_const)]
44

@@ -38,6 +38,9 @@ fn main() {
3838
//~^ ERROR expected one of
3939
asm!("{}", options(), const foo);
4040
//~^ ERROR attempt to use a non-constant value in a constant
41+
42+
// test that asm!'s clobber_abi doesn't accept non-string literals
43+
// see also https://github.com/rust-lang/rust/issues/112635
4144
asm!("", clobber_abi());
4245
//~^ ERROR at least one abi must be provided
4346
asm!("", clobber_abi(foo));
@@ -46,6 +49,25 @@ fn main() {
4649
//~^ ERROR expected one of `)` or `,`, found `foo`
4750
asm!("", clobber_abi("C", foo));
4851
//~^ ERROR expected string literal
52+
asm!("", clobber_abi(1));
53+
//~^ ERROR expected string literal
54+
asm!("", clobber_abi(()));
55+
//~^ ERROR expected string literal
56+
asm!("", clobber_abi(uwu));
57+
//~^ ERROR expected string literal
58+
asm!("", clobber_abi({}));
59+
//~^ ERROR expected string literal
60+
asm!("", clobber_abi(loop {}));
61+
//~^ ERROR expected string literal
62+
asm!("", clobber_abi(if));
63+
//~^ ERROR expected string literal
64+
asm!("", clobber_abi(do));
65+
//~^ ERROR expected string literal
66+
asm!("", clobber_abi(<));
67+
//~^ ERROR expected string literal
68+
asm!("", clobber_abi(.));
69+
//~^ ERROR expected string literal
70+
4971
asm!("{}", clobber_abi("C"), const foo);
5072
//~^ ERROR attempt to use a non-constant value in a constant
5173
asm!("", options(), clobber_abi("C"));
@@ -56,15 +78,7 @@ fn main() {
5678
//~^^ ERROR argument never used
5779
//~^^^ ERROR attempt to use a non-constant value in a constant
5880
//~^^^^ ERROR attempt to use a non-constant value in a constant
59-
asm!("", a = in("eax") foo);
60-
//~^ ERROR explicit register arguments cannot have names
61-
asm!("{a}", in("eax") foo, a = const bar);
62-
//~^ ERROR attempt to use a non-constant value in a constant
63-
asm!("{a}", in("eax") foo, a = const bar);
64-
//~^ ERROR attempt to use a non-constant value in a constant
65-
asm!("{1}", in("eax") foo, const bar);
66-
//~^ ERROR positional arguments cannot follow named arguments or explicit register arguments
67-
//~^^ ERROR attempt to use a non-constant value in a constant
81+
6882
asm!("", options(), "");
6983
//~^ ERROR expected one of
7084
asm!("{}", in(reg) foo, "{}", out(reg) foo);

0 commit comments

Comments
 (0)