ahatanak created this revision. Herald added subscribers: kristof.beyls, aemerson.
When I compile the following code targeting arm64 and execute it, it terminates with an uncaught exception: "libc++abi.dylib: terminating with uncaught exception of type int": int foo1() noexcept { try { throw 0; } catch (int i) { return 0; } return 1; } int main() { return foo1(); } This happens because function foo1 has attribute nounwind but doesn't have attribute uwtable on it, in which case Funcion::needsUnwindTableEntry, which is the function that determines whether an unwind table is needed, returns false. bool needsUnwindTableEntry() const { return hasUWTable() || !doesNotThrow(); } This patch changes MachO::IsUnwindTablesDefault to return true when !UseSjLjExceptions. When the function returns true, -munwind-table is passed to the frontend, which causes IRGen to annotate functions with attribute uwtable. One question: instead of adding uwtable in SetLLVMFunctionAttributesForDefinition whenever CodeGenOpts.UnwindTables is true, is it possible to limit it to functions that actually need unwind tables (for example, in TryMarkNoThrow in CodeGenFunction.cpp)? rdar://problem/32411865 https://reviews.llvm.org/D35693 Files: include/clang/Driver/ToolChain.h lib/Driver/ToolChain.cpp lib/Driver/ToolChains/Clang.cpp lib/Driver/ToolChains/CrossWindows.cpp lib/Driver/ToolChains/CrossWindows.h lib/Driver/ToolChains/Darwin.cpp lib/Driver/ToolChains/Darwin.h lib/Driver/ToolChains/Gnu.cpp lib/Driver/ToolChains/Gnu.h lib/Driver/ToolChains/MSVC.cpp lib/Driver/ToolChains/MSVC.h lib/Driver/ToolChains/MinGW.cpp lib/Driver/ToolChains/MinGW.h lib/Driver/ToolChains/NetBSD.h test/Driver/clang-translation.c
Index: test/Driver/clang-translation.c =================================================================== --- test/Driver/clang-translation.c +++ 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 Index: lib/Driver/ToolChains/NetBSD.h =================================================================== --- lib/Driver/ToolChains/NetBSD.h +++ lib/Driver/ToolChains/NetBSD.h @@ -65,7 +65,10 @@ 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: Index: lib/Driver/ToolChains/MinGW.h =================================================================== --- lib/Driver/ToolChains/MinGW.h +++ lib/Driver/ToolChains/MinGW.h @@ -60,7 +60,7 @@ 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; Index: lib/Driver/ToolChains/MinGW.cpp =================================================================== --- lib/Driver/ToolChains/MinGW.cpp +++ lib/Driver/ToolChains/MinGW.cpp @@ -347,7 +347,7 @@ 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; } Index: lib/Driver/ToolChains/MSVC.h =================================================================== --- lib/Driver/ToolChains/MSVC.h +++ lib/Driver/ToolChains/MSVC.h @@ -73,7 +73,7 @@ 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; Index: lib/Driver/ToolChains/MSVC.cpp =================================================================== --- lib/Driver/ToolChains/MSVC.cpp +++ lib/Driver/ToolChains/MSVC.cpp @@ -699,7 +699,7 @@ 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. Index: lib/Driver/ToolChains/Gnu.h =================================================================== --- lib/Driver/ToolChains/Gnu.h +++ lib/Driver/ToolChains/Gnu.h @@ -284,7 +284,7 @@ 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; Index: lib/Driver/ToolChains/Gnu.cpp =================================================================== --- lib/Driver/ToolChains/Gnu.cpp +++ lib/Driver/ToolChains/Gnu.cpp @@ -2291,7 +2291,7 @@ CudaInstallation.print(OS); } -bool Generic_GCC::IsUnwindTablesDefault() const { +bool Generic_GCC::IsUnwindTablesDefault(const ArgList &Args) const { return getArch() == llvm::Triple::x86_64; } Index: lib/Driver/ToolChains/Darwin.h =================================================================== --- lib/Driver/ToolChains/Darwin.h +++ lib/Driver/ToolChains/Darwin.h @@ -216,7 +216,7 @@ 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; Index: lib/Driver/ToolChains/Darwin.cpp =================================================================== --- lib/Driver/ToolChains/Darwin.cpp +++ lib/Driver/ToolChains/Darwin.cpp @@ -1843,8 +1843,8 @@ 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 { Index: lib/Driver/ToolChains/CrossWindows.h =================================================================== --- lib/Driver/ToolChains/CrossWindows.h +++ lib/Driver/ToolChains/CrossWindows.h @@ -56,7 +56,7 @@ 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; Index: lib/Driver/ToolChains/CrossWindows.cpp =================================================================== --- lib/Driver/ToolChains/CrossWindows.cpp +++ lib/Driver/ToolChains/CrossWindows.cpp @@ -214,7 +214,7 @@ } } -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; Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -2538,7 +2538,7 @@ 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, Index: lib/Driver/ToolChain.cpp =================================================================== --- lib/Driver/ToolChain.cpp +++ lib/Driver/ToolChain.cpp @@ -217,7 +217,7 @@ } } -bool ToolChain::IsUnwindTablesDefault() const { +bool ToolChain::IsUnwindTablesDefault(const ArgList &Args) const { return false; } Index: include/clang/Driver/ToolChain.h =================================================================== --- include/clang/Driver/ToolChain.h +++ include/clang/Driver/ToolChain.h @@ -315,7 +315,7 @@ /// 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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits