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

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 3 14:10:32 PST 2022


lebedev.ri updated this revision to Diff 479869.
lebedev.ri added a comment.
Herald added subscribers: kbarton, aheejin, nemanjai, dschuff.

@rjmccall thank you for taking a look!

1. Always add UB scope for `nounwind` functions
2. When popping the EH scopes, do that in backwards order :)
3. Ensure that check-clang actually passes (it wasn't in last patch)
4. Correctly annotate call's in UB scope as `nounwind`ing
5. Now, this point is uncomfortably overlapped with the D138958 <https://reviews.llvm.org/D138958>: i believe, the attribute that specifies that unwind is UB, takes priority over the exception specification / `noexcept`.
6. When looking into all this, an interesting question appeared: what about dynamic exception specification, `EHFilterScope`? If the outermost scope is UB, and exception is listed in `EHFilterScope`, then it will hit UB scope, and if it is not, then `the function std::unexpected is called. The default function calls std::terminate, but it may be replaced by a user-provided function`. Should we do something here?
7. I'm a bit lost about your 3'rd point in https://reviews.llvm.org/D137381#inline-1339891, about not overriding the src loc with something that is irrelevant. I think i need a C++ example in order to handle this. Right now it seems like those calls wouldn't actually go throught `CodeGenFunction::EmitCall()`, and thus wouldn't cause a proble.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137381

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UndefinedBehaviorSanitizer.rst
  clang/include/clang/Basic/Sanitizers.def
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGCleanup.cpp
  clang/lib/CodeGen/CGCleanup.h
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/EHScopeStack.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/windows-seh-EHa-CppCondiTemps.cpp
  clang/test/CodeGenCXX/catch-exception-escape.cpp
  clang/test/CodeGenCXX/exception-escape-as-ub-cleanups.cpp
  clang/test/Driver/fsanitize.c
  compiler-rt/lib/ubsan/ubsan_checks.inc
  compiler-rt/lib/ubsan/ubsan_handlers.cpp
  compiler-rt/lib/ubsan/ubsan_handlers.h
  compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
  compiler-rt/test/ubsan/TestCases/Misc/exception-escape.cpp
  compiler-rt/test/ubsan_minimal/TestCases/exception-escape.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137381.479869.patch
Type: text/x-patch
Size: 188349 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221203/ad700a14/attachment-0001.bin>


More information about the llvm-commits mailing list