[Driver][Darwin] Pass -munwind-table when !UseSjLjExceptions.

This commit fixes a bug where clang/llvm doesn't emit an unwind table
for a function when it is marked noexcept. Without this patch, the
following code terminates with an uncaught exception on ARM64:

int foo1() noexcept {
  try {
    throw 0;
  } catch (int i) {
    return 0;
  }
  return 1;
}

int main() {
  return foo1();
}

rdar://problem/32411865

Differential Revision: https://reviews.llvm.org/D35693

llvm-svn: 310006
This commit is contained in:
Akira Hatanaka 2017-08-03 23:55:42 +00:00
parent 8482e56920
commit b72e35a4c4
15 changed files with 26 additions and 15 deletions

View File

@ -315,7 +315,7 @@ public:
/// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
/// by default.
virtual bool IsUnwindTablesDefault() const;
virtual bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const;
/// \brief Test whether this toolchain defaults to PIC.
virtual bool isPICDefault() const = 0;

View File

@ -217,7 +217,7 @@ StringRef ToolChain::getDefaultUniversalArchName() const {
}
}
bool ToolChain::IsUnwindTablesDefault() const {
bool ToolChain::IsUnwindTablesDefault(const ArgList &Args) const {
return false;
}

View File

@ -2599,7 +2599,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
bool AsynchronousUnwindTables =
Args.hasFlag(options::OPT_fasynchronous_unwind_tables,
options::OPT_fno_asynchronous_unwind_tables,
(getToolChain().IsUnwindTablesDefault() ||
(getToolChain().IsUnwindTablesDefault(Args) ||
getToolChain().getSanitizerArgs().needsUnwindTables()) &&
!KernelOrKext);
if (Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables,

View File

@ -213,7 +213,7 @@ CrossWindowsToolChain::CrossWindowsToolChain(const Driver &D,
}
}
bool CrossWindowsToolChain::IsUnwindTablesDefault() const {
bool CrossWindowsToolChain::IsUnwindTablesDefault(const ArgList &Args) const {
// FIXME: all non-x86 targets need unwind tables, however, LLVM currently does
// not know how to emit them.
return getArch() == llvm::Triple::x86_64;

View File

@ -56,7 +56,7 @@ public:
const llvm::opt::ArgList &Args);
bool IsIntegratedAssemblerDefault() const override { return true; }
bool IsUnwindTablesDefault() const override;
bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
bool isPICDefault() const override;
bool isPIEDefault() const override;
bool isPICDefaultForced() const override;

View File

@ -1844,8 +1844,8 @@ Darwin::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
return DAL;
}
bool MachO::IsUnwindTablesDefault() const {
return getArch() == llvm::Triple::x86_64;
bool MachO::IsUnwindTablesDefault(const ArgList &Args) const {
return !UseSjLjExceptions(Args);
}
bool MachO::UseDwarfDebugFlags() const {

View File

@ -216,7 +216,7 @@ public:
bool UseObjCMixedDispatch() const override { return true; }
bool IsUnwindTablesDefault() const override;
bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
RuntimeLibType GetDefaultRuntimeLibType() const override {
return ToolChain::RLT_CompilerRT;

View File

@ -2300,7 +2300,7 @@ void Generic_GCC::printVerboseInfo(raw_ostream &OS) const {
CudaInstallation.print(OS);
}
bool Generic_GCC::IsUnwindTablesDefault() const {
bool Generic_GCC::IsUnwindTablesDefault(const ArgList &Args) const {
return getArch() == llvm::Triple::x86_64;
}

View File

@ -284,7 +284,7 @@ public:
void printVerboseInfo(raw_ostream &OS) const override;
bool IsUnwindTablesDefault() const override;
bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
bool isPICDefault() const override;
bool isPIEDefault() const override;
bool isPICDefaultForced() const override;

View File

@ -699,7 +699,7 @@ bool MSVCToolChain::IsIntegratedAssemblerDefault() const {
return true;
}
bool MSVCToolChain::IsUnwindTablesDefault() const {
bool MSVCToolChain::IsUnwindTablesDefault(const ArgList &Args) const {
// Emit unwind tables by default on Win64. All non-x86_32 Windows platforms
// such as ARM and PPC actually require unwind tables, but LLVM doesn't know
// how to generate them yet.

View File

@ -73,7 +73,7 @@ public:
Action::OffloadKind DeviceOffloadKind) const override;
bool IsIntegratedAssemblerDefault() const override;
bool IsUnwindTablesDefault() const override;
bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
bool isPICDefault() const override;
bool isPIEDefault() const override;
bool isPICDefaultForced() const override;

View File

@ -346,7 +346,7 @@ Tool *toolchains::MinGW::buildLinker() const {
return new tools::MinGW::Linker(*this);
}
bool toolchains::MinGW::IsUnwindTablesDefault() const {
bool toolchains::MinGW::IsUnwindTablesDefault(const ArgList &Args) const {
return getArch() == llvm::Triple::x86_64;
}

View File

@ -60,7 +60,7 @@ public:
const llvm::opt::ArgList &Args);
bool IsIntegratedAssemblerDefault() const override;
bool IsUnwindTablesDefault() const override;
bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
bool isPICDefault() const override;
bool isPIEDefault() const override;
bool isPICDefaultForced() const override;

View File

@ -65,7 +65,10 @@ public:
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
bool IsUnwindTablesDefault() const override { return true; }
bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override {
return true;
}
SanitizerMask getSupportedSanitizers() const override;
protected:

View File

@ -69,6 +69,14 @@
// ARMV7_HARDFLOAT-NOT: "-msoft-float"
// ARMV7_HARDFLOAT: "-x" "c"
// RUN: %clang -target arm64-apple-ios10 -### -S %s -arch arm64 2>&1 | \
// RUN: FileCheck -check-prefix=ARM64-APPLE %s
// ARM64-APPLE: -munwind-table
// RUN: %clang -target armv7k-apple-watchos4.0 -### -S %s -arch armv7k 2>&1 | \
// RUN: FileCheck -check-prefix=ARMV7K-APPLE %s
// ARMV7K-APPLE: -munwind-table
// RUN: %clang -target arm-linux -### -S %s -march=armv5e 2>&1 | \
// RUN: FileCheck -check-prefix=ARMV5E %s
// ARMV5E: clang