Skip to content

Commit e85ecbb

Browse files
authored
Rollup merge of rust-lang#110233 - nbdd0121:intrinsic, r=tmiasko
Make rust-intrinsic ABI unwindable Fix rust-lang#104451, fix rust-lang/miri#2839 r? `@RalfJung`
2 parents 232eb69 + b07a470 commit e85ecbb

14 files changed

+289
-13
lines changed

compiler/rustc_middle/src/ty/layout.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1226,10 +1226,11 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
12261226
| AvrNonBlockingInterrupt
12271227
| CCmseNonSecureCall
12281228
| Wasm
1229-
| RustIntrinsic
12301229
| PlatformIntrinsic
12311230
| Unadjusted => false,
1232-
Rust | RustCall | RustCold => tcx.sess.panic_strategy() == PanicStrategy::Unwind,
1231+
Rust | RustCall | RustCold | RustIntrinsic => {
1232+
tcx.sess.panic_strategy() == PanicStrategy::Unwind
1233+
}
12331234
}
12341235
}
12351236

library/core/src/ffi/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -615,12 +615,15 @@ impl<'f> Drop for VaListImpl<'f> {
615615
extern "rust-intrinsic" {
616616
/// Destroy the arglist `ap` after initialization with `va_start` or
617617
/// `va_copy`.
618+
#[rustc_nounwind]
618619
fn va_end(ap: &mut VaListImpl<'_>);
619620

620621
/// Copies the current location of arglist `src` to the arglist `dst`.
622+
#[rustc_nounwind]
621623
fn va_copy<'f>(dest: *mut VaListImpl<'f>, src: &VaListImpl<'f>);
622624

623625
/// Loads an argument of type `T` from the `va_list` `ap` and increment the
624626
/// argument `ap` points to.
627+
#[rustc_nounwind]
625628
fn va_arg<T: sealed_trait::VaArgSafe>(ap: &mut VaListImpl<'_>) -> T;
626629
}

library/core/src/intrinsics.rs

+231-1
Large diffs are not rendered by default.

library/core/src/ptr/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,7 @@ pub const unsafe fn write<T>(dst: *mut T, src: T) {
13711371
// as `intrinsics::copy_nonoverlapping` is a wrapper function.
13721372
extern "rust-intrinsic" {
13731373
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
1374+
#[rustc_nounwind]
13741375
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
13751376
}
13761377

library/std/src/panicking.rs

+1
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
498498
// This function cannot be marked as `unsafe` because `intrinsics::r#try`
499499
// expects normal function pointers.
500500
#[inline]
501+
#[rustc_nounwind] // `intrinsic::r#try` requires catch fn to be nounwind
501502
fn do_catch<F: FnOnce() -> R, R>(data: *mut u8, payload: *mut u8) {
502503
// SAFETY: this is the responsibility of the caller, see above.
503504
//
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// MIR for `main` after AbortUnwindingCalls
2+
3+
fn main() -> () {
4+
let mut _0: (); // return place in scope 0 at $DIR/issue_104451_unwindable_intrinsics.rs:+0:11: +0:11
5+
let mut _1: !; // in scope 0 at $DIR/issue_104451_unwindable_intrinsics.rs:+2:9: +2:62
6+
let mut _2: (); // in scope 0 at $DIR/issue_104451_unwindable_intrinsics.rs:+2:45: +2:47
7+
scope 1 {
8+
}
9+
10+
bb0: {
11+
StorageLive(_1); // scope 1 at $DIR/issue_104451_unwindable_intrinsics.rs:+2:9: +2:62
12+
StorageLive(_2); // scope 1 at $DIR/issue_104451_unwindable_intrinsics.rs:+2:45: +2:47
13+
_2 = (); // scope 1 at $DIR/issue_104451_unwindable_intrinsics.rs:+2:45: +2:47
14+
_1 = const_eval_select::<(), fn() -> ! {ow_ct}, fn() -> ! {ow_ct}, !>(move _2, ow_ct, ow_ct); // scope 1 at $DIR/issue_104451_unwindable_intrinsics.rs:+2:9: +2:62
15+
// mir::Constant
16+
// + span: $DIR/issue_104451_unwindable_intrinsics.rs:8:9: 8:44
17+
// + literal: Const { ty: unsafe extern "rust-intrinsic" fn((), fn() -> ! {ow_ct}, fn() -> ! {ow_ct}) -> ! {const_eval_select::<(), fn() -> ! {ow_ct}, fn() -> ! {ow_ct}, !>}, val: Value(<ZST>) }
18+
// mir::Constant
19+
// + span: $DIR/issue_104451_unwindable_intrinsics.rs:8:49: 8:54
20+
// + literal: Const { ty: fn() -> ! {ow_ct}, val: Value(<ZST>) }
21+
// mir::Constant
22+
// + span: $DIR/issue_104451_unwindable_intrinsics.rs:8:56: 8:61
23+
// + literal: Const { ty: fn() -> ! {ow_ct}, val: Value(<ZST>) }
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Check that `UnwindAction::Unreachable` is not generated for unwindable intrinsics.
2+
// ignore-wasm32 compiled with panic=abort by default
3+
#![feature(core_intrinsics)]
4+
5+
// EMIT_MIR issue_104451_unwindable_intrinsics.main.AbortUnwindingCalls.after.mir
6+
fn main() {
7+
unsafe {
8+
core::intrinsics::const_eval_select((), ow_ct, ow_ct)
9+
}
10+
}
11+
12+
const fn ow_ct() -> ! {
13+
panic!();
14+
}

tests/mir-opt/lower_intrinsics.assume.LowerIntrinsics.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
StorageLive(_1); // scope 1 at $DIR/lower_intrinsics.rs:+2:9: +2:38
1212
- _1 = std::intrinsics::assume(const true) -> [return: bb1, unwind unreachable]; // scope 1 at $DIR/lower_intrinsics.rs:+2:9: +2:38
1313
- // mir::Constant
14-
- // + span: $DIR/lower_intrinsics.rs:105:9: 105:32
14+
- // + span: $DIR/lower_intrinsics.rs:106:9: 106:32
1515
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(bool) {std::intrinsics::assume}, val: Value(<ZST>) }
1616
+ assume(const true); // scope 1 at $DIR/lower_intrinsics.rs:+2:9: +2:38
1717
+ goto -> bb1; // scope 1 at $DIR/lower_intrinsics.rs:+2:9: +2:38

tests/mir-opt/lower_intrinsics.f_copy_nonoverlapping.LowerIntrinsics.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
StorageDead(_9); // scope 3 at $DIR/lower_intrinsics.rs:+4:90: +4:91
5050
- _3 = copy_nonoverlapping::<i32>(move _4, move _8, const 0_usize) -> [return: bb1, unwind unreachable]; // scope 3 at $DIR/lower_intrinsics.rs:+4:9: +4:95
5151
- // mir::Constant
52-
- // + span: $DIR/lower_intrinsics.rs:98:9: 98:28
52+
- // + span: $DIR/lower_intrinsics.rs:99:9: 99:28
5353
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(*const i32, *mut i32, usize) {copy_nonoverlapping::<i32>}, val: Value(<ZST>) }
5454
+ copy_nonoverlapping(dst = move _8, src = move _4, count = const 0_usize); // scope 3 at $DIR/lower_intrinsics.rs:+4:9: +4:95
5555
+ goto -> bb1; // scope 3 at $DIR/lower_intrinsics.rs:+4:9: +4:95

tests/mir-opt/lower_intrinsics.option_payload.LowerIntrinsics.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
_4 = &raw const (*_1); // scope 1 at $DIR/lower_intrinsics.rs:+2:55: +2:56
2525
- _3 = option_payload_ptr::<usize>(move _4) -> [return: bb1, unwind unreachable]; // scope 1 at $DIR/lower_intrinsics.rs:+2:18: +2:57
2626
- // mir::Constant
27-
- // + span: $DIR/lower_intrinsics.rs:132:18: 132:54
27+
- // + span: $DIR/lower_intrinsics.rs:133:18: 133:54
2828
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(*const Option<usize>) -> *const usize {option_payload_ptr::<usize>}, val: Value(<ZST>) }
2929
+ _3 = &raw const (((*_4) as Some).0: usize); // scope 1 at $DIR/lower_intrinsics.rs:+2:18: +2:57
3030
+ goto -> bb1; // scope 1 at $DIR/lower_intrinsics.rs:+2:18: +2:57
@@ -37,7 +37,7 @@
3737
_6 = &raw const (*_2); // scope 2 at $DIR/lower_intrinsics.rs:+3:55: +3:56
3838
- _5 = option_payload_ptr::<String>(move _6) -> [return: bb2, unwind unreachable]; // scope 2 at $DIR/lower_intrinsics.rs:+3:18: +3:57
3939
- // mir::Constant
40-
- // + span: $DIR/lower_intrinsics.rs:133:18: 133:54
40+
- // + span: $DIR/lower_intrinsics.rs:134:18: 134:54
4141
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(*const Option<String>) -> *const String {option_payload_ptr::<String>}, val: Value(<ZST>) }
4242
+ _5 = &raw const (((*_6) as Some).0: std::string::String); // scope 2 at $DIR/lower_intrinsics.rs:+3:18: +3:57
4343
+ goto -> bb2; // scope 2 at $DIR/lower_intrinsics.rs:+3:18: +3:57

tests/mir-opt/lower_intrinsics.read_via_copy_primitive.LowerIntrinsics.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
_2 = &raw const (*_1); // scope 1 at $DIR/lower_intrinsics.rs:+1:46: +1:47
1414
- _0 = read_via_copy::<i32>(move _2) -> [return: bb1, unwind unreachable]; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:48
1515
- // mir::Constant
16-
- // + span: $DIR/lower_intrinsics.rs:118:14: 118:45
16+
- // + span: $DIR/lower_intrinsics.rs:119:14: 119:45
1717
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(*const i32) -> i32 {read_via_copy::<i32>}, val: Value(<ZST>) }
1818
+ _0 = (*_2); // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:48
1919
+ goto -> bb1; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:48

tests/mir-opt/lower_intrinsics.read_via_copy_uninhabited.LowerIntrinsics.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
_2 = &raw const (*_1); // scope 1 at $DIR/lower_intrinsics.rs:+1:46: +1:47
1414
- _0 = read_via_copy::<Never>(move _2) -> unwind unreachable; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:48
1515
- // mir::Constant
16-
- // + span: $DIR/lower_intrinsics.rs:123:14: 123:45
16+
- // + span: $DIR/lower_intrinsics.rs:124:14: 124:45
1717
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(*const Never) -> Never {read_via_copy::<Never>}, val: Value(<ZST>) }
1818
+ unreachable; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:48
1919
}

tests/mir-opt/lower_intrinsics.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// unit-test: LowerIntrinsics
22
// ignore-wasm32 compiled with panic=abort by default
33

4-
#![feature(core_intrinsics, intrinsics)]
4+
#![feature(core_intrinsics, intrinsics, rustc_attrs)]
55
#![crate_type = "lib"]
66

77
// EMIT_MIR lower_intrinsics.wrapping.LowerIntrinsics.diff
@@ -87,6 +87,7 @@ pub fn discriminant<T>(t: T) {
8787

8888
extern "rust-intrinsic" {
8989
// Cannot use `std::intrinsics::copy_nonoverlapping` as that is a wrapper function
90+
#[rustc_nounwind]
9091
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
9192
}
9293

tests/mir-opt/lower_intrinsics.with_overflow.LowerIntrinsics.diff

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
_5 = _2; // scope 0 at $DIR/lower_intrinsics.rs:+1:53: +1:54
3333
- _3 = add_with_overflow::<i32>(move _4, move _5) -> [return: bb1, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+1:14: +1:55
3434
- // mir::Constant
35-
- // + span: $DIR/lower_intrinsics.rs:111:14: 111:49
35+
- // + span: $DIR/lower_intrinsics.rs:112:14: 112:49
3636
- // + literal: Const { ty: extern "rust-intrinsic" fn(i32, i32) -> (i32, bool) {add_with_overflow::<i32>}, val: Value(<ZST>) }
3737
+ _3 = CheckedAdd(move _4, move _5); // scope 0 at $DIR/lower_intrinsics.rs:+1:14: +1:55
3838
+ goto -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:+1:14: +1:55
@@ -48,7 +48,7 @@
4848
_8 = _2; // scope 1 at $DIR/lower_intrinsics.rs:+2:53: +2:54
4949
- _6 = sub_with_overflow::<i32>(move _7, move _8) -> [return: bb2, unwind unreachable]; // scope 1 at $DIR/lower_intrinsics.rs:+2:14: +2:55
5050
- // mir::Constant
51-
- // + span: $DIR/lower_intrinsics.rs:112:14: 112:49
51+
- // + span: $DIR/lower_intrinsics.rs:113:14: 113:49
5252
- // + literal: Const { ty: extern "rust-intrinsic" fn(i32, i32) -> (i32, bool) {sub_with_overflow::<i32>}, val: Value(<ZST>) }
5353
+ _6 = CheckedSub(move _7, move _8); // scope 1 at $DIR/lower_intrinsics.rs:+2:14: +2:55
5454
+ goto -> bb2; // scope 1 at $DIR/lower_intrinsics.rs:+2:14: +2:55
@@ -64,7 +64,7 @@
6464
_11 = _2; // scope 2 at $DIR/lower_intrinsics.rs:+3:53: +3:54
6565
- _9 = mul_with_overflow::<i32>(move _10, move _11) -> [return: bb3, unwind unreachable]; // scope 2 at $DIR/lower_intrinsics.rs:+3:14: +3:55
6666
- // mir::Constant
67-
- // + span: $DIR/lower_intrinsics.rs:113:14: 113:49
67+
- // + span: $DIR/lower_intrinsics.rs:114:14: 114:49
6868
- // + literal: Const { ty: extern "rust-intrinsic" fn(i32, i32) -> (i32, bool) {mul_with_overflow::<i32>}, val: Value(<ZST>) }
6969
+ _9 = CheckedMul(move _10, move _11); // scope 2 at $DIR/lower_intrinsics.rs:+3:14: +3:55
7070
+ goto -> bb3; // scope 2 at $DIR/lower_intrinsics.rs:+3:14: +3:55

0 commit comments

Comments
 (0)