Skip to content

Unwinding intrinsics use non-unwinding ABI #104451

Closed
@tmiasko

Description

@tmiasko

There are intrinsics like assert_inhabited, which can unwind, but use rust-intrinsic ABI that never unwinds:

| RustIntrinsic
| PlatformIntrinsic
| Unadjusted => false,

An example demonstrating the issue. The argument passed to function f is never dropped, when assert_inhabited unwinds:

#![feature(core_intrinsics)]
#![feature(never_type)]

struct NoisyDrop(&'static str);

impl Drop for NoisyDrop {
    fn drop(&mut self) {
        println!("{}", self.0);
    }
}

pub fn f<A, B>(_: A) {
    core::intrinsics::assert_inhabited::<B>()
}

fn main() {
    let _a = NoisyDrop("1");
    f::<NoisyDrop, !>(NoisyDrop("2"));
}

$ rustc a.rs && ./a
thread 'main' panicked at 'attempted to instantiate uninhabited type `!`', a.rs:13:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1

Metadata

Metadata

Assignees

Labels

A-intrinsicsArea: IntrinsicsA-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions