Skip to content

Comments

Fix: On wasm targets, call panic_in_cleanup if panic occurs in cleanup#151771

Open
hoodmane wants to merge 1 commit intorust-lang:mainfrom
hoodmane:wasm-double-panic
Open

Fix: On wasm targets, call panic_in_cleanup if panic occurs in cleanup#151771
hoodmane wants to merge 1 commit intorust-lang:mainfrom
hoodmane:wasm-double-panic

Conversation

@hoodmane
Copy link
Contributor

@hoodmane hoodmane commented Jan 28, 2026

Previously this was not correctly implemented. Each funclet may need its own terminate block, so this changes the terminate_block into a terminate_blocks IndexVec which can have a terminate_block for each funclet. We key on the first basic block of the funclet -- in particular, this is the start block for the old case of the top level terminate function.

I also fixed the terminate handler to not be invoked when a foreign exception is raised, mimicking the behavior from msvc. On wasm, in order to avoid generating a catch_all we need to call llvm.wasm.get.exception and llvm.wasm.get.ehselector.

@rustbot
Copy link
Collaborator

rustbot commented Jan 28, 2026

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 28, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 28, 2026

r? @saethlin

rustbot has assigned @saethlin.
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

@hoodmane hoodmane force-pushed the wasm-double-panic branch 2 times, most recently from 947c55e to 08e5fd4 Compare January 28, 2026 03:52
@hoodmane
Copy link
Contributor Author

cc @bjorn3

@saethlin
Copy link
Member

saethlin commented Feb 1, 2026

r? bjorn3

You can roll it back to me, but I think you're a better reviewer for this

@rustbot rustbot assigned bjorn3 and unassigned saethlin Feb 1, 2026
@hoodmane
Copy link
Contributor Author

hoodmane commented Feb 9, 2026

@bjorn3 would appreciate review on this when you have a chance.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Previously this was not correctly implemented. Each funclet may need its own terminate
block, so this changes the `terminate_block` into a `terminate_blocks` `IndexVec` which
can have a terminate_block for each funclet. We key on the first basic block of the
funclet -- in particular, this is the start block for the old case of the top level
terminate function.

Rather than using a catchswitch/catchpad pair, I used a cleanuppad. The reason for the
pair is to avoid catching foreign exceptions on MSVC. On wasm, it seems that the
catchswitch/catchpad pair is optimized back into a single cleanuppad and a catch_all
instruction is emitted which will catch foreign exceptions. Because the new logic is
only used on wasm, it seemed better to take the simpler approach seeing as they do the
same thing.
@hoodmane
Copy link
Contributor Author

Okay @bjorn3 I updated this so it's waiting on review again.

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-gcc failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

=> Removing the following docker images:
WARNING: This output is designed for human readability. For machine-readable output, please use --format.
IMAGE                                               ID             DISK USAGE   CONTENT SIZE   EXTRA
ghcr.io/dependabot/dependabot-updater-core:latest   9a6a20114926       1.18GB          310MB        
=> Removing docker images...
Deleted Images:
untagged: ghcr.io/dependabot/dependabot-updater-core:latest
deleted: sha256:9a6a20114926442eeadab0732ddd7264ecafc907389c47974b1825d779571319

Total reclaimed space: 309.7MB

********************************************************************************
---
   Compiling rustc_codegen_gcc v0.1.0 (/checkout/compiler/rustc_codegen_gcc)
error[E0261]: use of undeclared lifetime name `'ll`
    --> compiler/rustc_codegen_gcc/src/builder.rs:1658:51
     |
1658 |     fn funclet_pad_value(&self, funclet: &Funclet<'ll>) -> &'ll Value {
     |                                                   ^^^ undeclared lifetime
     |
help: consider introducing lifetime `'ll` here
     |
1658 |     fn funclet_pad_value<'ll>(&self, funclet: &Funclet<'ll>) -> &'ll Value {
     |                         +++++
help: consider introducing lifetime `'ll` here
     |
 511 | impl<'ll, 'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
     |      ++++

error[E0261]: use of undeclared lifetime name `'ll`
    --> compiler/rustc_codegen_gcc/src/builder.rs:1658:61
     |
1658 |     fn funclet_pad_value(&self, funclet: &Funclet<'ll>) -> &'ll Value {
     |                                                             ^^^ undeclared lifetime
     |
help: consider introducing lifetime `'ll` here
     |
1658 |     fn funclet_pad_value<'ll>(&self, funclet: &Funclet<'ll>) -> &'ll Value {
     |                         +++++
help: consider introducing lifetime `'ll` here
     |
 511 | impl<'ll, 'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
     |      ++++

error[E0425]: cannot find type `Value` in this scope
    --> compiler/rustc_codegen_gcc/src/builder.rs:1658:65
     |
1658 |     fn funclet_pad_value(&self, funclet: &Funclet<'ll>) -> &'ll Value {
     |                                                                 ^^^^^
     |
    ::: /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/gccjit-3.3.0/src/lvalue.rs:99:1
     |
  99 | pub struct LValue<'ctx> {
     | ----------------------- similarly named struct `LValue` defined here
     |
help: a struct with a similar name exists
     |
1658 |     fn funclet_pad_value(&self, funclet: &Funclet<'ll>) -> &'ll LValue {
     |                                                                 +
help: consider importing one of these items
     |
   1 + use crate::builder::ty::Value;
     |
   1 + use rustc_middle::queries::adt_async_destructor::Value;
     |
   1 + use rustc_middle::queries::adt_async_drop_tys::Value;
     |
   1 + use rustc_middle::queries::adt_def::Value;
     |
     = and 317 other candidates

error[E0107]: type alias takes 0 lifetime arguments but 1 lifetime argument was supplied
    --> compiler/rustc_codegen_gcc/src/builder.rs:1658:43
     |
1658 |     fn funclet_pad_value(&self, funclet: &Funclet<'ll>) -> &'ll Value {
     |                                           ^^^^^^^----- help: remove the unnecessary generics
     |                                           |
     |                                           expected 0 lifetime arguments
     |
note: type alias defined here, with 0 lifetime parameters

For more information how to resolve CI failures of this job, visit this link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants