From 4af01079ce2f2d2528d72b8ce5be018f68ea7d73 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Fri, 11 Aug 2017 01:47:32 +0000 Subject: Merging r310006: ------------------------------------------------------------------------ r310006 | ahatanak | 2017-08-03 16:55:42 -0700 (Thu, 03 Aug 2017) | 22 lines [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 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_50@310677 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/ToolChain.h | 2 +- lib/Driver/ToolChain.cpp | 2 +- lib/Driver/ToolChains/Clang.cpp | 2 +- lib/Driver/ToolChains/CrossWindows.cpp | 2 +- lib/Driver/ToolChains/CrossWindows.h | 2 +- lib/Driver/ToolChains/Darwin.cpp | 4 ++-- lib/Driver/ToolChains/Darwin.h | 2 +- lib/Driver/ToolChains/Gnu.cpp | 2 +- lib/Driver/ToolChains/Gnu.h | 2 +- lib/Driver/ToolChains/MSVC.cpp | 2 +- lib/Driver/ToolChains/MSVC.h | 2 +- lib/Driver/ToolChains/MinGW.cpp | 2 +- lib/Driver/ToolChains/MinGW.h | 2 +- lib/Driver/ToolChains/NetBSD.h | 5 ++++- test/Driver/clang-translation.c | 8 ++++++++ 15 files changed, 26 insertions(+), 15 deletions(-) diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h index eb42f1260d..6651491e5b 100644 --- a/include/clang/Driver/ToolChain.h +++ b/include/clang/Driver/ToolChain.h @@ -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; diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp index 2be7f0f690..9a858df8ab 100644 --- a/lib/Driver/ToolChain.cpp +++ b/lib/Driver/ToolChain.cpp @@ -217,7 +217,7 @@ StringRef ToolChain::getDefaultUniversalArchName() const { } } -bool ToolChain::IsUnwindTablesDefault() const { +bool ToolChain::IsUnwindTablesDefault(const ArgList &Args) const { return false; } diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index b82cc2d4fa..baf7a93d2d 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -2538,7 +2538,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, diff --git a/lib/Driver/ToolChains/CrossWindows.cpp b/lib/Driver/ToolChains/CrossWindows.cpp index 7d0c438b13..04b71c48cd 100644 --- a/lib/Driver/ToolChains/CrossWindows.cpp +++ b/lib/Driver/ToolChains/CrossWindows.cpp @@ -214,7 +214,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; diff --git a/lib/Driver/ToolChains/CrossWindows.h b/lib/Driver/ToolChains/CrossWindows.h index 5375a6324a..2f66446ec7 100644 --- a/lib/Driver/ToolChains/CrossWindows.h +++ b/lib/Driver/ToolChains/CrossWindows.h @@ -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; diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp index ad8e9eae79..6b7f0c71df 100644 --- a/lib/Driver/ToolChains/Darwin.cpp +++ b/lib/Driver/ToolChains/Darwin.cpp @@ -1836,8 +1836,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 { diff --git a/lib/Driver/ToolChains/Darwin.h b/lib/Driver/ToolChains/Darwin.h index 6cb1d04b78..77c569e8f8 100644 --- a/lib/Driver/ToolChains/Darwin.h +++ b/lib/Driver/ToolChains/Darwin.h @@ -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; diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp index bc26ee1de4..72a9f85ba3 100644 --- a/lib/Driver/ToolChains/Gnu.cpp +++ b/lib/Driver/ToolChains/Gnu.cpp @@ -2291,7 +2291,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; } diff --git a/lib/Driver/ToolChains/Gnu.h b/lib/Driver/ToolChains/Gnu.h index cdf6100544..f29342b95a 100644 --- a/lib/Driver/ToolChains/Gnu.h +++ b/lib/Driver/ToolChains/Gnu.h @@ -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; diff --git a/lib/Driver/ToolChains/MSVC.cpp b/lib/Driver/ToolChains/MSVC.cpp index 9e9d943610..b871c856d2 100644 --- a/lib/Driver/ToolChains/MSVC.cpp +++ b/lib/Driver/ToolChains/MSVC.cpp @@ -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. diff --git a/lib/Driver/ToolChains/MSVC.h b/lib/Driver/ToolChains/MSVC.h index 055830c52e..d153691a5c 100644 --- a/lib/Driver/ToolChains/MSVC.h +++ b/lib/Driver/ToolChains/MSVC.h @@ -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; diff --git a/lib/Driver/ToolChains/MinGW.cpp b/lib/Driver/ToolChains/MinGW.cpp index 7550bab486..632b76d92b 100644 --- a/lib/Driver/ToolChains/MinGW.cpp +++ b/lib/Driver/ToolChains/MinGW.cpp @@ -347,7 +347,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; } diff --git a/lib/Driver/ToolChains/MinGW.h b/lib/Driver/ToolChains/MinGW.h index cf1628a4cc..9b3d7c553f 100644 --- a/lib/Driver/ToolChains/MinGW.h +++ b/lib/Driver/ToolChains/MinGW.h @@ -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; diff --git a/lib/Driver/ToolChains/NetBSD.h b/lib/Driver/ToolChains/NetBSD.h index 412d0815e8..5163ff72d8 100644 --- a/lib/Driver/ToolChains/NetBSD.h +++ b/lib/Driver/ToolChains/NetBSD.h @@ -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: diff --git a/test/Driver/clang-translation.c b/test/Driver/clang-translation.c index 7c7b2f05f1..545951d5aa 100644 --- a/test/Driver/clang-translation.c +++ b/test/Driver/clang-translation.c @@ -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 -- cgit v1.2.3