// -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
// complicated ways.
auto SanitizeArgs = TC.getSanitizerArgs(Args);
- auto UnwindTables = TC.getDefaultUnwindTableLevel(Args);
-
- const bool HasSyncUnwindTables = Args.hasFlag(
- options::OPT_funwind_tables, options::OPT_fno_unwind_tables, false);
- if (Args.hasFlag(options::OPT_fasynchronous_unwind_tables,
- options::OPT_fno_asynchronous_unwind_tables,
- SanitizeArgs.needsUnwindTables()) &&
- !Freestanding)
- UnwindTables = ToolChain::UnwindTableLevel::Asynchronous;
- else if (HasSyncUnwindTables)
- UnwindTables = ToolChain::UnwindTableLevel::Synchronous;
- else if (Args.hasFlag(options::OPT_fno_unwind_tables,
- options::OPT_fno_asynchronous_unwind_tables,
- options::OPT_funwind_tables, false) || Freestanding)
- UnwindTables = ToolChain::UnwindTableLevel::None;
-
-
- if (UnwindTables == ToolChain::UnwindTableLevel::Synchronous)
- CmdArgs.push_back("-funwind-tables=1");
- else if (UnwindTables == ToolChain::UnwindTableLevel::Asynchronous)
+
+ bool IsAsyncUnwindTablesDefault =
+ TC.getDefaultUnwindTableLevel(Args) == ToolChain::UnwindTableLevel::Asynchronous;
+ bool IsSyncUnwindTablesDefault =
+ TC.getDefaultUnwindTableLevel(Args) == ToolChain::UnwindTableLevel::Synchronous;
+
+ bool AsyncUnwindTables = Args.hasFlag(
+ options::OPT_fasynchronous_unwind_tables,
+ options::OPT_fno_asynchronous_unwind_tables,
+ (IsAsyncUnwindTablesDefault || SanitizeArgs.needsUnwindTables()) &&
+ !Freestanding);
+ bool UnwindTables =
+ Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables,
+ IsSyncUnwindTablesDefault && !Freestanding);
+ if (AsyncUnwindTables)
CmdArgs.push_back("-funwind-tables=2");
+ else if (UnwindTables)
+ CmdArgs.push_back("-funwind-tables=1");
// Prepare `-aux-target-cpu` and `-aux-target-feature` unless
// `--gpu-use-aux-triple-only` is specified.
CmdArgs.push_back("-faddrsig");
if ((Triple.isOSBinFormatELF() || Triple.isOSBinFormatMachO()) &&
- (EH || UnwindTables != ToolChain::UnwindTableLevel::None ||
+ (EH || UnwindTables || AsyncUnwindTables ||
DebugInfoKind != codegenoptions::NoDebugInfo))
CmdArgs.push_back("-D__GCC_HAVE_DWARF2_CFI_ASM=1");
//
// ARM64-EXPLICIT-UWTABLE-APPLE: -funwind-tables
+// RUN: %clang -target arm64-apple-macosx -### -ffreestanding -fasynchronous-unwind-tables %s 2>&1 | \
+// RUN: FileCheck --check-prefix=ASYNC-UNWIND-FREESTANDING %s
+//
+// ASYNC-UNWIND-FREESTANDING: -funwind-tables=2
+
+// Quite weird behaviour, but it's a long-standing default.
+// RUN: %clang -target x86_64-apple-macosx -### -fno-unwind-tables %s 2>&1 |\
+// RUN: FileCheck --check-prefix=NOUNWIND-IGNORED %s
+//
+// NOUNWIND-IGNORED: -funwind-tables=2
+
// RUN: %clang -target arm64-apple-ios10 -fno-exceptions -### -S %s -arch arm64 2>&1 | \
// RUN: FileCheck -check-prefix=ARM64-APPLE-EXCEP %s
// ARM64-APPLE-EXCEP-NOT: -funwind-tables