@@ -1703,15 +1703,32 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1703
1703
let mut cs_bx = Bx :: build ( self . cx , llbb) ;
1704
1704
let cs = cs_bx. catch_switch ( None , None , & [ cp_llbb] ) ;
1705
1705
1706
- // The "null" here is actually a RTTI type descriptor for the
1707
- // C++ personality function, but `catch (...)` has no type so
1708
- // it's null. The 64 here is actually a bitfield which
1709
- // represents that this is a catch-all block.
1710
1706
bx = Bx :: build ( self . cx , cp_llbb) ;
1711
1707
let null =
1712
1708
bx. const_null ( bx. type_ptr_ext ( bx. cx ( ) . data_layout ( ) . instruction_address_space ) ) ;
1713
- let sixty_four = bx. const_i32 ( 64 ) ;
1714
- funclet = Some ( bx. catch_pad ( cs, & [ null, sixty_four, null] ) ) ;
1709
+
1710
+ // The `null` in first argument here is actually a RTTI type
1711
+ // descriptor for the C++ personality function, but `catch (...)`
1712
+ // has no type so it's null.
1713
+ let args = if base:: wants_msvc_seh ( self . cx . sess ( ) ) {
1714
+ // This bitmask is a single `HT_IsStdDotDot` flag, which
1715
+ // represents that this is a C++-style `catch (...)` block that
1716
+ // only captures programmatic exceptions, not all SEH
1717
+ // exceptions. The second `null` points to a non-existent
1718
+ // `alloca` instruction, which an LLVM pass would inline into
1719
+ // the initial SEH frame allocation.
1720
+ let adjectives = bx. const_i32 ( 0x40 ) ;
1721
+ & [ null, adjectives, null] as & [ _ ]
1722
+ } else {
1723
+ // Specifying more arguments than necessary usually doesn't
1724
+ // hurt, but the `WasmEHPrepare` LLVM pass does not recognize
1725
+ // anything other than a single `null` as a `catch (...)` block,
1726
+ // leading to problems down the line during instruction
1727
+ // selection.
1728
+ & [ null] as & [ _ ]
1729
+ } ;
1730
+
1731
+ funclet = Some ( bx. catch_pad ( cs, args) ) ;
1715
1732
} else {
1716
1733
llbb = Bx :: append_block ( self . cx , self . llfn , "terminate" ) ;
1717
1734
bx = Bx :: build ( self . cx , llbb) ;
0 commit comments