From dc00a8adee77f04a450e2f02be97b4e308af863e Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 27 Feb 2019 09:36:49 +0300 Subject: [PATCH] Validate `#[unwind]` syntax regardless of platform-specific panic strategy --- src/librustc_mir/build/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 19507c900da64..39c84b95f8f5d 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -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 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 if tcx.sess.panic_strategy() != PanicStrategy::Unwind { return false; } @@ -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 // unwind anyway. Don't stop them. - let attrs = &tcx.get_attrs(fn_def_id); - match attr::find_unwind_attr(Some(tcx.sess.diagnostic()), attrs) { + match unwind_attr { None => true, Some(UnwindAttr::Allowed) => false, Some(UnwindAttr::Aborts) => true,