Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3917,15 +3917,20 @@ if (Freestanding) CmdArgs.push_back("-ffreestanding"); + Arg *ExceptionArg = Args.getLastArg(options::OPT_fsjlj_exceptions, + options::OPT_fseh_exceptions, + options::OPT_fdwarf_exceptions); // This is a coarse approximation of what llvm-gcc actually does, both // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more // complicated ways. - bool AsynchronousUnwindTables = - Args.hasFlag(options::OPT_fasynchronous_unwind_tables, - options::OPT_fno_asynchronous_unwind_tables, - (TC.IsUnwindTablesDefault(Args) || - TC.getSanitizerArgs().needsUnwindTables()) && - !Freestanding); + bool AsynchronousUnwindTables = Args.hasFlag( + options::OPT_fasynchronous_unwind_tables, + options::OPT_fno_asynchronous_unwind_tables, + (TC.IsUnwindTablesDefault(Args) || + (ExceptionArg && + ExceptionArg->getOption().matches(options::OPT_fseh_exceptions)) || + TC.getSanitizerArgs().needsUnwindTables()) && + !Freestanding); if (Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables, AsynchronousUnwindTables)) CmdArgs.push_back("-munwind-tables"); @@ -4704,11 +4709,8 @@ addExceptionArgs(Args, InputType, TC, KernelOrKext, Runtime, CmdArgs); // Handle exception personalities - Arg *A = Args.getLastArg(options::OPT_fsjlj_exceptions, - options::OPT_fseh_exceptions, - options::OPT_fdwarf_exceptions); - if (A) { - const Option &Opt = A->getOption(); + if (ExceptionArg) { + const Option &Opt = ExceptionArg->getOption(); if (Opt.matches(options::OPT_fsjlj_exceptions)) CmdArgs.push_back("-fsjlj-exceptions"); if (Opt.matches(options::OPT_fseh_exceptions)) Index: test/Driver/windows-exceptions.cpp =================================================================== --- test/Driver/windows-exceptions.cpp +++ test/Driver/windows-exceptions.cpp @@ -2,8 +2,11 @@ // RUN: %clang -target x86_64-windows-msvc -c %s -### 2>&1 | FileCheck -check-prefix=MSVC %s // RUN: %clang -target i686-windows-gnu -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-DWARF %s // RUN: %clang -target x86_64-windows-gnu -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-SEH %s +// RUN: %clang -target aarch64-windows-gnu -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-DWARF %s +// RUN: %clang -target aarch64-windows-gnu -fseh-exceptions -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-SEH %s MSVC-NOT: -fdwarf-exceptions MSVC-NOT: -fseh-exceptions MINGW-DWARF: -fdwarf-exceptions +MINGW-SEH: -munwind-tables MINGW-SEH: -fseh-exceptions