[PATCH] D35693: [Driver][Darwin] Pass -munwind-table when !UseSjLjExceptions

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 20 11:43:32 PDT 2017


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35693.107563.patch
Type: text/x-patch
Size: 7846 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170720/dd2b1428/attachment-0001.bin>


More information about the cfe-commits mailing list