Skip to content

Commit 196c974

Browse files
committed
Forbid asm unwind to work with labels
1 parent 7d4d872 commit 196c974

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

compiler/rustc_builtin_macros/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ builtin_macros_asm_expected_other = expected operand, {$is_global_asm ->
1919
2020
builtin_macros_asm_explicit_register_name = explicit register arguments cannot have names
2121
22+
builtin_macros_asm_mayunwind = asm labels are not allowed with the `may_unwind` option
23+
2224
builtin_macros_asm_modifier_invalid = asm template modifier must be a single character
2325
2426
builtin_macros_asm_mutually_exclusive = the `{$opt1}` and `{$opt2}` options are mutually exclusive

compiler/rustc_builtin_macros/src/asm.rs

+7
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ pub fn parse_asm_args<'a>(
245245
let mut have_real_output = false;
246246
let mut outputs_sp = vec![];
247247
let mut regclass_outputs = vec![];
248+
let mut labels_sp = vec![];
248249
for (op, op_sp) in &args.operands {
249250
match op {
250251
ast::InlineAsmOperand::Out { reg, expr, .. }
@@ -262,6 +263,9 @@ pub fn parse_asm_args<'a>(
262263
regclass_outputs.push(*op_sp);
263264
}
264265
}
266+
ast::InlineAsmOperand::Label { .. } => {
267+
labels_sp.push(*op_sp);
268+
}
265269
_ => {}
266270
}
267271
}
@@ -273,6 +277,9 @@ pub fn parse_asm_args<'a>(
273277
// Bail out now since this is likely to confuse MIR
274278
return Err(err);
275279
}
280+
if args.options.contains(ast::InlineAsmOptions::MAY_UNWIND) && !labels_sp.is_empty() {
281+
dcx.emit_err(errors::AsmMayUnwind { labels_sp });
282+
}
276283

277284
if args.clobber_abis.len() > 0 {
278285
if is_global_asm {

compiler/rustc_builtin_macros/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,13 @@ pub(crate) struct AsmNoReturn {
789789
pub(crate) outputs_sp: Vec<Span>,
790790
}
791791

792+
#[derive(Diagnostic)]
793+
#[diag(builtin_macros_asm_mayunwind)]
794+
pub(crate) struct AsmMayUnwind {
795+
#[primary_span]
796+
pub(crate) labels_sp: Vec<Span>,
797+
}
798+
792799
#[derive(Diagnostic)]
793800
#[diag(builtin_macros_global_asm_clobber_abi)]
794801
pub(crate) struct GlobalAsmClobberAbi {

0 commit comments

Comments
 (0)