Skip to content

Commit

Permalink
Validate #[unwind] syntax regardless of platform-specific panic str…
Browse files Browse the repository at this point in the history
…ategy
  • Loading branch information
petrochenkov committed Feb 27, 2019
1 parent b11502f commit dc00a8a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/librustc_mir/build/mod.rs
Expand Up @@ -581,6 +581,10 @@ fn should_abort_on_panic<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
// Not callable from C, so we can safely unwind through these // Not callable from C, so we can safely unwind through these
if abi == Abi::Rust || abi == Abi::RustCall { return false; } if abi == Abi::Rust || abi == Abi::RustCall { return false; }


// Validate `#[unwind]` syntax regardless of platform-specific panic strategy
let attrs = &tcx.get_attrs(fn_def_id);
let unwind_attr = attr::find_unwind_attr(Some(tcx.sess.diagnostic()), attrs);

// We never unwind, so it's not relevant to stop an unwind // We never unwind, so it's not relevant to stop an unwind
if tcx.sess.panic_strategy() != PanicStrategy::Unwind { return false; } if tcx.sess.panic_strategy() != PanicStrategy::Unwind { return false; }


Expand All @@ -589,8 +593,7 @@ fn should_abort_on_panic<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,


// This is a special case: some functions have a C abi but are meant to // This is a special case: some functions have a C abi but are meant to
// unwind anyway. Don't stop them. // unwind anyway. Don't stop them.
let attrs = &tcx.get_attrs(fn_def_id); match unwind_attr {
match attr::find_unwind_attr(Some(tcx.sess.diagnostic()), attrs) {
None => true, None => true,
Some(UnwindAttr::Allowed) => false, Some(UnwindAttr::Allowed) => false,
Some(UnwindAttr::Aborts) => true, Some(UnwindAttr::Aborts) => true,
Expand Down

0 comments on commit dc00a8a

Please sign in to comment.