Skip to content

declare C and C-unwind as mutually ABI-compatible - #161904

Open
RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:unwind-abi-compat
Open

declare C and C-unwind as mutually ABI-compatible#161904
RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:unwind-abi-compat

Conversation

@RalfJung

@RalfJung RalfJung commented Aug 28, 2026

Copy link
Copy Markdown
Member

We left this conservative in #115476. That means the following code is currently UB:

extern "C-unwind" fn does_not_unwind_but_could() {}

fn main() {
    let f: extern "C-unwind" fn() = does_not_unwind_but_could;
    let f: extern "C" fn() = unsafe { std::mem::transmute(f) };
    f();
}

I think this code should be allowed. Zulip discussion also led to the conclusion that this should be fine in LLVM -- the nounwind attribute does not affect the ABI. This is widely relied upon in the C ecosystem when doing calls between C and C++.
Cc @nikic to confirm.

I am not sure why #115476 left this conservative. There was discussion about explicitly listing the ABIs rather than saying this holds universally for all *-unwind that we may add in the future, but there was no discussion I could find about allowing a mismatch both ways.

Cc @rust-lang/opsem @rust-lang/lang

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 28, 2026
@rustbot

rustbot commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from JohnTitor, Mark-Simulacrum, clarfonthey, nia-e

@RalfJung RalfJung added the needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. label Aug 28, 2026
@traviscross traviscross added T-lang Relevant to the language team T-opsem Relevant to the opsem team I-lang-radar Items that are on lang's radar and will need eventual work or consideration. labels Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

I-lang-radar Items that are on lang's radar and will need eventual work or consideration. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-lang Relevant to the language team T-libs Relevant to the library team, which will review and decide on the PR/issue. T-opsem Relevant to the opsem team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants