This is an archive of the discontinued LLVM Phabricator instance.

WIP: [Clang] Emit 'unwindabort' when applicable.
Needs ReviewPublic

Authored by jyknight on Jan 17 2023, 3:53 AM.

Details

Reviewers
jdoerfert
Summary

Now that the core codegen support has been implemented in LLVM, we can
start using it in Clang.

This allows us to generate more efficient and smaller code for
'noexcept' functions.

For now, we only enable this for the Itanium EH handling,
_gxx_personality_v0 and _objc_personality_v0, as LLVM support is still
incomplete for other exception-handling schemes.

Depends on D141917

Diff Detail

Event Timeline

jyknight created this revision.Jan 17 2023, 3:53 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 17 2023, 3:53 AM
jyknight requested review of this revision.Jan 17 2023, 3:53 AM

I couldn't find an example of creating "resume unwindabort" in the patch series. Is it yet to be done?
Could you show a source code example where such an instruction should be generated? (By the frontend or an IR pass.) I couldn't get it from the RFC.

jroelofs added inline comments.
clang/lib/CodeGen/CodeGenFunction.h
2026

Other method docs in the file use ///-style doxygen comments.

clang/test/CodeGenCXX/exceptions.cpp
78

FWI(was)W, this radar points at: https://bugs.llvm.org/show_bug.cgi?id=11893

jroelofs added inline comments.Jul 28 2023, 10:45 AM
clang/lib/CodeGen/CGCall.cpp
5510–5516

Is there coverage for a nounwind callee + an unwindabort call?

jyknight updated this revision to Diff 546613.Aug 2 2023, 2:23 PM
jyknight edited the summary of this revision. (Show Details)

Rebase patch.

Thanks for the rebase!

We're eager to try this for Meta's Android apps, where size is a priority and better noexcept codegen would be really helpful. I ran into a crash with coroutines though, which blocks me from fully evaluating the size difference made by these changes. The reduced test case is in P8313, and you can repro the crash by running:

$ clang -std=c++20 -O2 -c crash.cpp
cannot use musttail with unwindabort
  musttail call unwindabort fastcc void %10(ptr %call57)
in function _Z5startv.resume
fatal error: error in backend: Broken function found, compilation aborted!

$ clang -std=c++20 -O2 -c crash.cpp
cannot use musttail with unwindabort

Thanks for the report. We were missing a check of CI.isUnwindAbort() in CoroSplit.cpp's shouldBeMustTail() function -- fixed for next version of the series. (It's not a regression in tail-callability for coroutines, since that call unwindabort would've previously been an invoke, which also cannot be musttail'd.)

$ clang -std=c++20 -O2 -c crash.cpp
cannot use musttail with unwindabort

Thanks for the report. We were missing a check of CI.isUnwindAbort() in CoroSplit.cpp's shouldBeMustTail() function -- fixed for next version of the series. (It's not a regression in tail-callability for coroutines, since that call unwindabort would've previously been an invoke, which also cannot be musttail'd.)

Just to confirm, this hasn't been uploaded yet, right? I wanted to try it out once it is.