#define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
#undef TARGET_SEH
-#define TARGET_SEH (TARGET_64BIT_MS_ABI && flag_unwind_tables)
+/* Win64 uses SEH unwind metadata regardless of whether an individual
+ function is compiled with the default MS ABI or with sysv_abi. Keep
+ SEH enabled for all 64-bit Windows functions whenever unwind tables are
+ requested so .seh_proc state stays consistent with EH emission. */
+#define TARGET_SEH (TARGET_64BIT && flag_unwind_tables)
#undef PREFERRED_STACK_BOUNDARY_DEFAULT
#define PREFERRED_STACK_BOUNDARY_DEFAULT \
--- /dev/null
+/* Verify that x86_64 mingw can emit SEH metadata for a sysv_abi wrapper
+ trampoline that references a throwing callee. */
+/* { dg-do compile { target x86_64-*-mingw* } } */
+/* { dg-options "-std=gnu++17 -fexceptions" } */
+
+#define SYSV __attribute__ ((sysv_abi))
+#define NOINLINE __attribute__ ((noinline))
+
+template <auto F>
+struct wrapper;
+
+template <typename R, typename... Args, SYSV R (*Func) (Args...)>
+struct wrapper<Func>
+{
+ static R SYSV NOINLINE
+ call (Args... args) noexcept
+ {
+ return Func (args...);
+ }
+};
+
+using entry_fn = int SYSV (*) ();
+
+volatile int throw_flag;
+volatile unsigned long long sink;
+
+int SYSV NOINLINE
+stub0 ()
+{
+ try
+ {
+ if (throw_flag)
+ throw 0;
+ }
+ catch (...)
+ {
+ }
+
+ return 1;
+}
+
+static entry_fn wrapped[] = { wrapper<stub0>::call };
+
+int
+main ()
+{
+ entry_fn fn = wrapped[0];
+ sink += (unsigned long long) (void *) fn;
+ return fn () == 0;
+}