Skip to content

Empty landing pads aren't optimized away on x86_64-pc-windows-gnu #43151

Closed
@alexcrichton

Description

@alexcrichton

It looks like empty landing pads are not optimized away due to our usage of rust_eh_unwind_resume instead of the standard resumption function. For example:

// bar.rs
#![crate_type = "rlib"]
pub fn bar() {}
// foo.rs
#![crate_type = "rlib"]
extern crate bar;

struct A;

impl Drop for A {
    fn drop(&mut self) {
    }
}

pub fn foo() {
    let _a = A;
    bar::bar();
}
$ rustc bar.rs --target x86_64-pc-windows-gnu
$ rustc foo.rs --target x86_64-pc-windows-gnu -L . -O --emit llvm-ir
$ cat foo.ll

yields this IR, notably:

; foo::foo
; Function Attrs: uwtable
define void @_ZN3foo3foo17h6cb4f4601b3a0374E() unnamed_addr #1 personality i32 (%"panic_unwind::windows::EXCEPTION_RECORD"*, i8*, %"panic_unwind::windows::CONTEXT"*, %"panic_unwind::windows::DISPATCHER_CONTEXT"*)* @rust_eh_personality {
start:
; invoke bar::bar
  invoke void @_ZN3bar3bar17h21868f3a4452d05bE()
          to label %bb2 unwind label %cleanup

bb2:                                              ; preds = %start
  ret void

cleanup:                                          ; preds = %start
  %0 = landingpad { i8*, i32 }
          cleanup
  %.fca.0.extract = extractvalue { i8*, i32 } %0, 0
  tail call void @rust_eh_unwind_resume(i8* %.fca.0.extract)
  unreachable
}

On other targets such as x86_64-unknown-linux-gnu this is optimized away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationC-bugCategory: This is a bug.O-windows-gnuToolchain: GNU, Operating system: WindowsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions