Unwind-tables: move back to original logic outline for kind.
authorTim Northover <tnorthover@apple.com>
Mon, 26 Sep 2022 12:26:36 +0000 (13:26 +0100)
committerTim Northover <tnorthover@apple.com>
Thu, 29 Sep 2022 12:39:06 +0000 (13:39 +0100)
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.

clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/clang-translation.c

index c93a727..5ea9e80 100644 (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;
-
-
-  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.
@@ -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");
 
index 715b0b3..ca98ca5 100644 (file)
 //
 // 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