Skip to content

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

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
RalfJung:unwind-abi-compat
Oct 2, 2026
Merged

rust-bors[bot] merged 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
Comment thread library/core/src/primitive_docs.rs Outdated
@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 5, 2026
@rustbot

rustbot commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@traviscross traviscross added I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Sep 7, 2026
@RalfJung

RalfJung commented Sep 20, 2026 •

Copy link
Copy Markdown
Member Author

I guess we should FCP this? Not sure if lang wants to be involved. I'll start with opsem.
@nikic @bjorn3 if you have any concerns please let us know!

@rfcbot fcp merge

@RalfJung

Copy link
Copy Markdown
Member Author

@rfcbot fcp merge opsem

is what I meant...

@rust-rfcbot

rust-rfcbot commented Sep 20, 2026 •

Copy link
Copy Markdown
Collaborator

@RalfJung has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. and removed needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. labels Sep 20, 2026
@clarfonthey clarfonthey removed the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Sep 21, 2026
@bjorn3

bjorn3 commented Sep 21, 2026

Copy link
Copy Markdown
Member

I don't have any concerns with this either. For a long time extern "C" was effectively what we now call extern "C-unwind" and I don't recall anyone filling an issue about this causing ABI problems at all.

@rust-rfcbot rust-rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Sep 21, 2026
@rust-rfcbot

Copy link
Copy Markdown
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

@traviscross

Copy link
Copy Markdown
Contributor

We talked about this briefly in the lang meeting today, and all present agreed this made sense.

@traviscross traviscross removed the I-lang-nominated Nominated for discussion during a lang team meeting. label Sep 23, 2026
@traviscross traviscross removed the P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang label Sep 23, 2026
@rust-rfcbot rust-rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Oct 1, 2026
@rust-rfcbot rust-rfcbot added the to-announce Announce this issue on triage meeting label Oct 1, 2026
@rust-rfcbot

Copy link
Copy Markdown
Collaborator

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

@RalfJung RalfJung removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 1, 2026
@RalfJung

RalfJung commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

@Mark-Simulacrum (or anyone reading along) this now just needs a review. :)

@traviscross traviscross added the waived-reference-pr This language change does not need a Reference PR. label Oct 1, 2026
@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

📌 Commit aee14eb has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 1, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 2, 2026
Rollup of 8 pull requests

Successful merges:

 - #162556 (Refactor CodeGen Pipeline Setup into a Single Function)
 - #163254 (rustdoc: Fix where-clause placement of free const items & checked type aliases)
 - #163621 (core: Unstably constify `abort_immediate`)
 - #161904 (declare C and C-unwind as mutually ABI-compatible)
 - #163144 (Add Tier 3 targets for Hyperlight guests)
 - #163537 (remove unnecessary panic from opsem inhabitedness calculation)
 - #163570 (Add tests for `!` and `bool`'s size and alignment to `coretests`.)
 - #163606 (ignore hanging next-solver tests, remove unnecessary ignore test)

Failed merges:

 - #163572 (Update the minimum external LLVM to 22)
@rust-bors
rust-bors Bot merged commit e0a574e into rust-lang:main Oct 2, 2026
13 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 2, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 2, 2026
Rollup merge of #161904 - RalfJung:unwind-abi-compat, r=Mark-Simulacrum

declare C and C-unwind as mutually ABI-compatible

We left this conservative in #115476. That means the following code is currently UB:
```rust
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](https://rust-lang.zulipchat.com/#narrow/channel/136281-t-opsem/topic/ABI.20compatibility.20of.20.22C.22.20vs.20.22C-unwind.22) 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team T-opsem Relevant to the opsem team to-announce Announce this issue on triage meeting waived-reference-pr This language change does not need a Reference PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants