Unwind-tables: move back to original logic outline for kind.

There are lots of options interacting in complex ways here, and when moving to
`getDefaultUnwindTableLevel` I had refactored this and changed behaviour in
some cases. So this reverts the basic structure of the logic back to the
original, while leaving the hook in the new style.
This commit is contained in:
Tim Northover 2022-09-26 13:26:36 +01:00
parent 8a8bacb973
commit e62b3a9375
2 changed files with 27 additions and 19 deletions

View File

@ -5470,27 +5470,24 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// -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;
bool IsAsyncUnwindTablesDefault =
TC.getDefaultUnwindTableLevel(Args) == ToolChain::UnwindTableLevel::Asynchronous;
bool IsSyncUnwindTablesDefault =
TC.getDefaultUnwindTableLevel(Args) == ToolChain::UnwindTableLevel::Synchronous;
if (UnwindTables == ToolChain::UnwindTableLevel::Synchronous)
CmdArgs.push_back("-funwind-tables=1");
else if (UnwindTables == ToolChain::UnwindTableLevel::Asynchronous)
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.
@ -7316,7 +7313,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
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");

View File

@ -99,6 +99,17 @@
//
// 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