[PATCH] D137381: [clang][compiler-rt] Exception escape out of an non-unwinding function is an undefined behaviour

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 3 21:15:05 PDT 2022


MaskRay added a comment.

In your example, `clang++ a.cc; ./a.out` gives a libstdc++ error:

  terminate called after throwing an instance of 'int'

libc++'s is similar.

footgun is nounwind (due to the GNU pure attribute), so Clang uses `call` instead of `invoke` and the function call does not get a call site entry in `.gcc_except_table`.
In `_Unwind_RaiseException` called by `__cxa_throw`, the missing exception handler causes `__terminate`.

`g++ a.cc; ./a.out` succeeds, likely because its `footgun` call is caught by `catch (...)`.

The patch doesn't implement the runtime correctly (I get a linker error) so I cannot try it out. How expensive if your instrumentation?
Does it work with `-fno-exceptions` intermediate functions? (Unwinding through such functions should fail as well). Note that this check can be done today,without any instrumentation: just use `-fno-asynchronous-unwind-tables` (for some targets which default to async unwind tables (aarch64,x86,etc)).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137381/new/

https://reviews.llvm.org/D137381



More information about the llvm-commits mailing list