Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 25b7648

Browse files
committedAug 4, 2021
Auto merge of #86155 - alexcrichton:abort-on-unwind, r=nikomatsakis
rustc: Fill out remaining parts of C-unwind ABI This commit intends to fill out some of the remaining pieces of the C-unwind ABI. This has a number of other changes with it though to move this design space forward a bit. Notably contained within here is: * On `panic=unwind`, the `extern "C"` ABI is now considered as "may unwind". This fixes a longstanding soundness issue where if you `panic!()` in an `extern "C"` function defined in Rust that's actually UB because the LLVM representation for the function has the `nounwind` attribute, but then you unwind. * Whether or not a function unwinds now mainly considers the ABI of the function instead of first checking the panic strategy. This fixes a miscompile of `extern "C-unwind"` with `panic=abort` because that ABI can still unwind. * The aborting stub for non-unwinding ABIs with `panic=unwind` has been reimplemented. Previously this was done as a small tweak during MIR generation, but this has been moved to a separate and dedicated MIR pass. This new pass will, for appropriate functions and function calls, insert a `cleanup` landing pad for any function call that may unwind within a function that is itself not allowed to unwind. Note that this subtly changes some behavior from before where previously on an unwind which was caught-to-abort it would run active destructors in the function, and now it simply immediately aborts the process. * The `#[unwind]` attribute has been removed and all users in tests and such are now using `C-unwind` and `#![feature(c_unwind)]`. I think this is largely the last piece of the RFC to implement. Unfortunately I believe this is still not stabilizable as-is because activating the feature gate changes the behavior of the existing `extern "C"` ABI in a way that has no replacement. My thinking for how to enable this is that we add support for the `C-unwind` ABI on stable Rust first, and then after it hits stable we change the behavior of the `C` ABI. That way anyone straddling stable/beta/nightly can switch to `C-unwind` safely.
2 parents d54fbb9 + bb68c66 commit 25b7648

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+560
-593
lines changed
 

‎compiler/rustc_attr/src/builtin.rs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -87,50 +87,6 @@ pub enum OptimizeAttr {
8787
Size,
8888
}
8989

90-
#[derive(Copy, Clone, PartialEq)]
91-
pub enum UnwindAttr {
92-
Allowed,
93-
Aborts,
94-
}
95-
96-
/// Determine what `#[unwind]` attribute is present in `attrs`, if any.
97-
pub fn find_unwind_attr(sess: &Session, attrs: &[Attribute]) -> Option<UnwindAttr> {
98-
attrs.iter().fold(None, |ia, attr| {
99-
if sess.check_name(attr, sym::unwind) {
100-
if let Some(meta) = attr.meta() {
101-
if let MetaItemKind::List(items) = meta.kind {
102-
if items.len() == 1 {
103-
if items[0].has_name(sym::allowed) {
104-
return Some(UnwindAttr::Allowed);
105-
} else if items[0].has_name(sym::aborts) {
106-
return Some(UnwindAttr::Aborts);
107-
}
108-
}
109-
110-
struct_span_err!(
111-
sess.diagnostic(),
112-
attr.span,
113-
E0633,
114-
"malformed `unwind` attribute input"
115-
)
116-
.span_label(attr.span, "invalid argument")
117-
.span_suggestions(
118-
attr.span,
119-
"the allowed arguments are `allowed` and `aborts`",
120-
(vec!["allowed", "aborts"])
121-
.into_iter()
122-
.map(|s| format!("#[unwind({})]", s)),
123-
Applicability::MachineApplicable,
124-
)
125-
.emit();
126-
}
127-
}
128-
}
129-
130-
ia
131-
})
132-
}
133-
13490
/// Represents the following attributes:
13591
///
13692
/// - `#[stable]`

‎compiler/rustc_error_codes/src/error_codes/E0633.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
The `unwind` attribute was malformed.
24

35
Erroneous code example:
46

5-
```compile_fail,E0633
7+
```compile_fail
68
#![feature(unwind_attributes)]
79
810
#[unwind()] // error: expected one argument

0 commit comments

Comments
 (0)
Please sign in to comment.