Skip to content

Commit 96c955e

Browse files
committed
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.
1 parent 9d5cd21 commit 96c955e

File tree

5 files changed

+38
-38
lines changed

5 files changed

+38
-38
lines changed

Diff for: compiler/rustc_builtin_macros/src/asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,12 @@ fn parse_options<'a>(
410410
try_set_option(p, args, sym::noreturn, ast::InlineAsmOptions::NORETURN);
411411
} else if !is_global_asm && p.eat_keyword(sym::nostack) {
412412
try_set_option(p, args, sym::nostack, ast::InlineAsmOptions::NOSTACK);
413+
} else if !is_global_asm && p.eat_keyword(sym::may_unwind) {
414+
try_set_option(p, args, kw::Raw, ast::InlineAsmOptions::MAY_UNWIND);
413415
} else if p.eat_keyword(sym::att_syntax) {
414416
try_set_option(p, args, sym::att_syntax, ast::InlineAsmOptions::ATT_SYNTAX);
415417
} else if p.eat_keyword(kw::Raw) {
416418
try_set_option(p, args, kw::Raw, ast::InlineAsmOptions::RAW);
417-
} else if p.eat_keyword(sym::may_unwind) {
418-
try_set_option(p, args, kw::Raw, ast::InlineAsmOptions::MAY_UNWIND);
419419
} else {
420420
return p.unexpected();
421421
}

Diff for: src/test/ui/asm/aarch64/bad-options.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -36,41 +36,41 @@ LL | asm!("{}", out(reg) foo, clobber_abi("C"));
3636
| |
3737
| generic outputs
3838

39-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nomem`
39+
error: expected one of `)`, `att_syntax`, or `raw`, found `nomem`
4040
--> $DIR/bad-options.rs:28:25
4141
|
4242
LL | global_asm!("", options(nomem));
43-
| ^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
43+
| ^^^^^ expected one of `)`, `att_syntax`, or `raw`
4444

45-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `readonly`
45+
error: expected one of `)`, `att_syntax`, or `raw`, found `readonly`
4646
--> $DIR/bad-options.rs:30:25
4747
|
4848
LL | global_asm!("", options(readonly));
49-
| ^^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
49+
| ^^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
5050

51-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `noreturn`
51+
error: expected one of `)`, `att_syntax`, or `raw`, found `noreturn`
5252
--> $DIR/bad-options.rs:32:25
5353
|
5454
LL | global_asm!("", options(noreturn));
55-
| ^^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
55+
| ^^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
5656

57-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `pure`
57+
error: expected one of `)`, `att_syntax`, or `raw`, found `pure`
5858
--> $DIR/bad-options.rs:34:25
5959
|
6060
LL | global_asm!("", options(pure));
61-
| ^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
61+
| ^^^^ expected one of `)`, `att_syntax`, or `raw`
6262

63-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nostack`
63+
error: expected one of `)`, `att_syntax`, or `raw`, found `nostack`
6464
--> $DIR/bad-options.rs:36:25
6565
|
6666
LL | global_asm!("", options(nostack));
67-
| ^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
67+
| ^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
6868

69-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `preserves_flags`
69+
error: expected one of `)`, `att_syntax`, or `raw`, found `preserves_flags`
7070
--> $DIR/bad-options.rs:38:25
7171
|
7272
LL | global_asm!("", options(preserves_flags));
73-
| ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
73+
| ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
7474

7575
error: invalid ABI for `clobber_abi`
7676
--> $DIR/bad-options.rs:20:18

Diff for: src/test/ui/asm/aarch64/parse-error.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -260,23 +260,23 @@ error: expected one of `,`, `.`, `?`, or an operator, found `FOO`
260260
LL | global_asm!("{}", const(reg) FOO);
261261
| ^^^ expected one of `,`, `.`, `?`, or an operator
262262

263-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `FOO`
263+
error: expected one of `)`, `att_syntax`, or `raw`, found `FOO`
264264
--> $DIR/parse-error.rs:102:25
265265
|
266266
LL | global_asm!("", options(FOO));
267-
| ^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
267+
| ^^^ expected one of `)`, `att_syntax`, or `raw`
268268

269-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nomem`
269+
error: expected one of `)`, `att_syntax`, or `raw`, found `nomem`
270270
--> $DIR/parse-error.rs:104:25
271271
|
272272
LL | global_asm!("", options(nomem FOO));
273-
| ^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
273+
| ^^^^^ expected one of `)`, `att_syntax`, or `raw`
274274

275-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nomem`
275+
error: expected one of `)`, `att_syntax`, or `raw`, found `nomem`
276276
--> $DIR/parse-error.rs:106:25
277277
|
278278
LL | global_asm!("", options(nomem, FOO));
279-
| ^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
279+
| ^^^^^ expected one of `)`, `att_syntax`, or `raw`
280280

281281
error: arguments are not allowed after options
282282
--> $DIR/parse-error.rs:108:30

Diff for: src/test/ui/asm/x86_64/bad-options.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -45,41 +45,41 @@ LL | asm!("{}", out(reg) foo, clobber_abi("C"), clobber_abi("C"));
4545
| | clobber_abi
4646
| generic outputs
4747

48-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nomem`
48+
error: expected one of `)`, `att_syntax`, or `raw`, found `nomem`
4949
--> $DIR/bad-options.rs:31:25
5050
|
5151
LL | global_asm!("", options(nomem));
52-
| ^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
52+
| ^^^^^ expected one of `)`, `att_syntax`, or `raw`
5353

54-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `readonly`
54+
error: expected one of `)`, `att_syntax`, or `raw`, found `readonly`
5555
--> $DIR/bad-options.rs:33:25
5656
|
5757
LL | global_asm!("", options(readonly));
58-
| ^^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
58+
| ^^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
5959

60-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `noreturn`
60+
error: expected one of `)`, `att_syntax`, or `raw`, found `noreturn`
6161
--> $DIR/bad-options.rs:35:25
6262
|
6363
LL | global_asm!("", options(noreturn));
64-
| ^^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
64+
| ^^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
6565

66-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `pure`
66+
error: expected one of `)`, `att_syntax`, or `raw`, found `pure`
6767
--> $DIR/bad-options.rs:37:25
6868
|
6969
LL | global_asm!("", options(pure));
70-
| ^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
70+
| ^^^^ expected one of `)`, `att_syntax`, or `raw`
7171

72-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nostack`
72+
error: expected one of `)`, `att_syntax`, or `raw`, found `nostack`
7373
--> $DIR/bad-options.rs:39:25
7474
|
7575
LL | global_asm!("", options(nostack));
76-
| ^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
76+
| ^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
7777

78-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `preserves_flags`
78+
error: expected one of `)`, `att_syntax`, or `raw`, found `preserves_flags`
7979
--> $DIR/bad-options.rs:41:25
8080
|
8181
LL | global_asm!("", options(preserves_flags));
82-
| ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
82+
| ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
8383

8484
error: invalid ABI for `clobber_abi`
8585
--> $DIR/bad-options.rs:20:18

Diff for: src/test/ui/asm/x86_64/parse-error.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -266,23 +266,23 @@ error: expected one of `,`, `.`, `?`, or an operator, found `FOO`
266266
LL | global_asm!("{}", const(reg) FOO);
267267
| ^^^ expected one of `,`, `.`, `?`, or an operator
268268

269-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `FOO`
269+
error: expected one of `)`, `att_syntax`, or `raw`, found `FOO`
270270
--> $DIR/parse-error.rs:104:25
271271
|
272272
LL | global_asm!("", options(FOO));
273-
| ^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
273+
| ^^^ expected one of `)`, `att_syntax`, or `raw`
274274

275-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nomem`
275+
error: expected one of `)`, `att_syntax`, or `raw`, found `nomem`
276276
--> $DIR/parse-error.rs:106:25
277277
|
278278
LL | global_asm!("", options(nomem FOO));
279-
| ^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
279+
| ^^^^^ expected one of `)`, `att_syntax`, or `raw`
280280

281-
error: expected one of `)`, `att_syntax`, `may_unwind`, or `raw`, found `nomem`
281+
error: expected one of `)`, `att_syntax`, or `raw`, found `nomem`
282282
--> $DIR/parse-error.rs:108:25
283283
|
284284
LL | global_asm!("", options(nomem, FOO));
285-
| ^^^^^ expected one of `)`, `att_syntax`, `may_unwind`, or `raw`
285+
| ^^^^^ expected one of `)`, `att_syntax`, or `raw`
286286

287287
error: arguments are not allowed after options
288288
--> $DIR/parse-error.rs:110:30

0 commit comments

Comments
 (0)