Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 940b2ea

Browse files
Amanieucynecx
authored andcommitted
Add initial AST and MIR support for unwinding from inline assembly
1 parent 532d2b1 commit 940b2ea

File tree

39 files changed

+355
-212
lines changed

39 files changed

+355
-212
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,7 @@ pub enum InlineAsmRegOrRegClass {
19811981

19821982
bitflags::bitflags! {
19831983
#[derive(Encodable, Decodable, HashStable_Generic)]
1984-
pub struct InlineAsmOptions: u8 {
1984+
pub struct InlineAsmOptions: u16 {
19851985
const PURE = 1 << 0;
19861986
const NOMEM = 1 << 1;
19871987
const READONLY = 1 << 2;
@@ -1990,6 +1990,7 @@ bitflags::bitflags! {
19901990
const NOSTACK = 1 << 5;
19911991
const ATT_SYNTAX = 1 << 6;
19921992
const RAW = 1 << 7;
1993+
const MAY_UNWIND = 1 << 8;
19931994
}
19941995
}
19951996

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,6 +2338,9 @@ impl<'a> State<'a> {
23382338
if opts.contains(InlineAsmOptions::RAW) {
23392339
options.push("raw");
23402340
}
2341+
if opts.contains(InlineAsmOptions::MAY_UNWIND) {
2342+
options.push("may_unwind");
2343+
}
23412344
s.commasep(Inconsistent, &options, |s, &opt| {
23422345
s.word(opt);
23432346
});

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_middle::ty::RegionVid;
55
use rustc_middle::ty::TyCtxt;
66
use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces};
77
use rustc_mir_dataflow::ResultsVisitable;
8-
use rustc_mir_dataflow::{self, fmt::DebugWithContext, GenKill};
8+
use rustc_mir_dataflow::{self, fmt::DebugWithContext, CallReturnPlaces, GenKill};
99
use rustc_mir_dataflow::{Analysis, Direction, Results};
1010
use std::fmt;
1111
use std::iter;
@@ -434,9 +434,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
434434
&self,
435435
_trans: &mut impl GenKill<Self::Idx>,
436436
_block: mir::BasicBlock,
437-
_func: &mir::Operand<'tcx>,
438-
_args: &[mir::Operand<'tcx>],
439-
_dest_place: mir::Place<'tcx>,
437+
_return_places: CallReturnPlaces<'_, 'tcx>,
440438
) {
441439
}
442440
}

compiler/rustc_borrowck/src/def_use.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {
1717
PlaceContext::MutatingUse(MutatingUseContext::Store) |
1818

1919
// This is potentially both a def and a use...
20-
PlaceContext::MutatingUse(MutatingUseContext::AsmOutput) |
20+
PlaceContext::MutatingUse(MutatingUseContext::LlvmAsmOutput) |
2121

2222
// We let Call define the result in both the success and
2323
// unwind cases. This is not really correct, however it
@@ -26,6 +26,7 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {
2626
// the def in call only to the input from the success
2727
// path and not the unwind path. -nmatsakis
2828
PlaceContext::MutatingUse(MutatingUseContext::Call) |
29+
PlaceContext::MutatingUse(MutatingUseContext::AsmOutput) |
2930
PlaceContext::MutatingUse(MutatingUseContext::Yield) |
3031

3132
// Storage live and storage dead aren't proper defines, but we can ignore

compiler/rustc_borrowck/src/invalidation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
199199
options: _,
200200
line_spans: _,
201201
destination: _,
202+
cleanup: _,
202203
} => {
203204
for op in operands {
204205
match *op {

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
791791
options: _,
792792
line_spans: _,
793793
destination: _,
794+
cleanup: _,
794795
} => {
795796
for op in operands {
796797
match *op {

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1828,10 +1828,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18281828
self.assert_iscleanup(body, block_data, unwind, true);
18291829
}
18301830
}
1831-
TerminatorKind::InlineAsm { destination, .. } => {
1831+
TerminatorKind::InlineAsm { destination, cleanup, .. } => {
18321832
if let Some(target) = destination {
18331833
self.assert_iscleanup(body, block_data, target, is_cleanup);
18341834
}
1835+
if let Some(cleanup) = cleanup {
1836+
if is_cleanup {
1837+
span_mirbug!(self, block_data, "cleanup on cleanup block")
1838+
}
1839+
self.assert_iscleanup(body, block_data, cleanup, true);
1840+
}
18351841
}
18361842
}
18371843
}

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ fn parse_options<'a>(
420420
try_set_option(p, args, sym::att_syntax, ast::InlineAsmOptions::ATT_SYNTAX);
421421
} else if p.eat_keyword(kw::Raw) {
422422
try_set_option(p, args, kw::Raw, ast::InlineAsmOptions::RAW);
423+
} else if p.eat_keyword(sym::may_unwind) {
424+
try_set_option(p, args, kw::Raw, ast::InlineAsmOptions::MAY_UNWIND);
423425
} else {
424426
return p.unexpected();
425427
}

compiler/rustc_codegen_ssa/src/mir/analyze.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
211211

212212
PlaceContext::MutatingUse(
213213
MutatingUseContext::Store
214+
| MutatingUseContext::LlvmAsmOutput
214215
| MutatingUseContext::AsmOutput
215216
| MutatingUseContext::Borrow
216217
| MutatingUseContext::AddressOf

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10411041
options,
10421042
line_spans,
10431043
destination,
1044+
cleanup: _, // TODO
10441045
} => {
10451046
self.codegen_asm_terminator(
10461047
helper,

0 commit comments

Comments
 (0)