From 96c955e66b39f23eca553644aeb2ea5f41ff355a Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Tue, 2 Aug 2022 05:25:45 +0100 Subject: [PATCH] Properly reject the `may_unwind` option in `global_asm!` This was accidentally accepted even though it had no effect in `global_asm!`. The option only makes sense for `asm!` which runs within a function. --- compiler/rustc_builtin_macros/src/asm.rs | 4 ++-- src/test/ui/asm/aarch64/bad-options.stderr | 24 +++++++++++----------- src/test/ui/asm/aarch64/parse-error.stderr | 12 +++++------ src/test/ui/asm/x86_64/bad-options.stderr | 24 +++++++++++----------- src/test/ui/asm/x86_64/parse-error.stderr | 12 +++++------ 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index a2205c3613d92..fc310129b249e 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -410,12 +410,12 @@ fn parse_options<'a>( try_set_option(p, args, sym::noreturn, ast::InlineAsmOptions::NORETURN); } else if !is_global_asm && p.eat_keyword(sym::nostack) { try_set_option(p, args, sym::nostack, ast::InlineAsmOptions::NOSTACK); + } else if !is_global_asm && p.eat_keyword(sym::may_unwind) { + try_set_option(p, args, kw::Raw, ast::InlineAsmOptions::MAY_UNWIND); } else if p.eat_keyword(sym::att_syntax) { try_set_option(p, args, sym::att_syntax, ast::InlineAsmOptions::ATT_SYNTAX); } else if p.eat_keyword(kw::Raw) { try_set_option(p, args, kw::Raw, ast::InlineAsmOptions::RAW); - } else if p.eat_keyword(sym::may_unwind) { - try_set_option(p, args, kw::Raw, ast::InlineAsmOptions::MAY_UNWIND); } else { return p.unexpected(); } diff --git a/src/test/ui/asm/aarch64/bad-options.stderr b/src/test/ui/asm/aarch64/bad-options.stderr index 867e0433eae1b..21bcc4a9c7bad 100644 --- a/src/test/ui/asm/aarch64/bad-options.stderr +++ b/src/test/ui/asm/aarch64/bad-options.stderr @@ -36,41 +36,41 @@ LL | asm!("{}", out(reg) foo, clobber_abi("C")); | | | generic outputs -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nomem` +error: expected one of `)`, `att_syntax`, or `raw`, found `nomem` --> $DIR/bad-options.rs:28:25 | LL | global_asm!("", options(nomem)); - | ^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^^ expected one of `)`, `att_syntax`, or `raw` -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `readonly` +error: expected one of `)`, `att_syntax`, or `raw`, found `readonly` --> $DIR/bad-options.rs:30:25 | LL | global_asm!("", options(readonly)); - | ^^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^^^^^ expected one of `)`, `att_syntax`, or `raw` -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `noreturn` +error: expected one of `)`, `att_syntax`, or `raw`, found `noreturn` --> $DIR/bad-options.rs:32:25 | LL | global_asm!("", options(noreturn)); - | ^^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^^^^^ expected one of `)`, `att_syntax`, or `raw` -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `pure` +error: expected one of `)`, `att_syntax`, or `raw`, found `pure` --> $DIR/bad-options.rs:34:25 | LL | global_asm!("", options(pure)); - | ^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^ expected one of `)`, `att_syntax`, or `raw` -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nostack` +error: expected one of `)`, `att_syntax`, or `raw`, found `nostack` --> $DIR/bad-options.rs:36:25 | LL | global_asm!("", options(nostack)); - | ^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^^^^ expected one of `)`, `att_syntax`, or `raw` -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `preserves_flags` +error: expected one of `)`, `att_syntax`, or `raw`, found `preserves_flags` --> $DIR/bad-options.rs:38:25 | LL | global_asm!("", options(preserves_flags)); - | ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, or `raw` error: invalid ABI for `clobber_abi` --> $DIR/bad-options.rs:20:18 diff --git a/src/test/ui/asm/aarch64/parse-error.stderr b/src/test/ui/asm/aarch64/parse-error.stderr index f2013046cda42..804966b06ba7d 100644 --- a/src/test/ui/asm/aarch64/parse-error.stderr +++ b/src/test/ui/asm/aarch64/parse-error.stderr @@ -260,23 +260,23 @@ error: expected one of `,`, `.`, `?`, or an operator, found `FOO` LL | global_asm!("{}", const(reg) FOO); | ^^^ expected one of `,`, `.`, `?`, or an operator -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `FOO` +error: expected one of `)`, `att_syntax`, or `raw`, found `FOO` --> $DIR/parse-error.rs:102:25 | LL | global_asm!("", options(FOO)); - | ^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^ expected one of `)`, `att_syntax`, or `raw` -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nomem` +error: expected one of `)`, `att_syntax`, or `raw`, found `nomem` --> $DIR/parse-error.rs:104:25 | LL | global_asm!("", options(nomem FOO)); - | ^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^^ expected one of `)`, `att_syntax`, or `raw` -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nomem` +error: expected one of `)`, `att_syntax`, or `raw`, found `nomem` --> $DIR/parse-error.rs:106:25 | LL | global_asm!("", options(nomem, FOO)); - | ^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^^ expected one of `)`, `att_syntax`, or `raw` error: arguments are not allowed after options --> $DIR/parse-error.rs:108:30 diff --git a/src/test/ui/asm/x86_64/bad-options.stderr b/src/test/ui/asm/x86_64/bad-options.stderr index a63c42aac2737..e2351840eef21 100644 --- a/src/test/ui/asm/x86_64/bad-options.stderr +++ b/src/test/ui/asm/x86_64/bad-options.stderr @@ -45,41 +45,41 @@ LL | asm!("{}", out(reg) foo, clobber_abi("C"), clobber_abi("C")); | | clobber_abi | generic outputs -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nomem` +error: expected one of `)`, `att_syntax`, or `raw`, found `nomem` --> $DIR/bad-options.rs:31:25 | LL | global_asm!("", options(nomem)); - | ^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^^ expected one of `)`, `att_syntax`, or `raw` -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `readonly` +error: expected one of `)`, `att_syntax`, or `raw`, found `readonly` --> $DIR/bad-options.rs:33:25 | LL | global_asm!("", options(readonly)); - | ^^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^^^^^ expected one of `)`, `att_syntax`, or `raw` -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `noreturn` +error: expected one of `)`, `att_syntax`, or `raw`, found `noreturn` --> $DIR/bad-options.rs:35:25 | LL | global_asm!("", options(noreturn)); - | ^^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^^^^^ expected one of `)`, `att_syntax`, or `raw` -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `pure` +error: expected one of `)`, `att_syntax`, or `raw`, found `pure` --> $DIR/bad-options.rs:37:25 | LL | global_asm!("", options(pure)); - | ^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^ expected one of `)`, `att_syntax`, or `raw` -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nostack` +error: expected one of `)`, `att_syntax`, or `raw`, found `nostack` --> $DIR/bad-options.rs:39:25 | LL | global_asm!("", options(nostack)); - | ^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^^^^ expected one of `)`, `att_syntax`, or `raw` -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `preserves_flags` +error: expected one of `)`, `att_syntax`, or `raw`, found `preserves_flags` --> $DIR/bad-options.rs:41:25 | LL | global_asm!("", options(preserves_flags)); - | ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, or `raw` error: invalid ABI for `clobber_abi` --> $DIR/bad-options.rs:20:18 diff --git a/src/test/ui/asm/x86_64/parse-error.stderr b/src/test/ui/asm/x86_64/parse-error.stderr index 1fd317a96a8a6..57702c37b7ce2 100644 --- a/src/test/ui/asm/x86_64/parse-error.stderr +++ b/src/test/ui/asm/x86_64/parse-error.stderr @@ -266,23 +266,23 @@ error: expected one of `,`, `.`, `?`, or an operator, found `FOO` LL | global_asm!("{}", const(reg) FOO); | ^^^ expected one of `,`, `.`, `?`, or an operator -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `FOO` +error: expected one of `)`, `att_syntax`, or `raw`, found `FOO` --> $DIR/parse-error.rs:104:25 | LL | global_asm!("", options(FOO)); - | ^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^ expected one of `)`, `att_syntax`, or `raw` -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nomem` +error: expected one of `)`, `att_syntax`, or `raw`, found `nomem` --> $DIR/parse-error.rs:106:25 | LL | global_asm!("", options(nomem FOO)); - | ^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^^ expected one of `)`, `att_syntax`, or `raw` -error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nomem` +error: expected one of `)`, `att_syntax`, or `raw`, found `nomem` --> $DIR/parse-error.rs:108:25 | LL | global_asm!("", options(nomem, FOO)); - | ^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw` + | ^^^^^ expected one of `)`, `att_syntax`, or `raw` error: arguments are not allowed after options --> $DIR/parse-error.rs:110:30