This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Improve the implementation of std::unreachable
ClosedPublic

Authored by ldionne on Aug 10 2022, 2:27 PM.

Details

Reviewers
None
Group Reviewers
Restricted Project
Commits
rG678dd9a589d6: [libc++] Improve the implementation of std::unreachable
Summary

First, use __builtin_unreachable unconditionally. It is implemented by
all the compilers that we support. Clang started supporting it around
Clang 4, and GCC around GCC 4.10.

Also add _LIBCPP_ASSERT so that we will actually get a guaranteed crash
if we reached std::unreachable() and assertions have been enabled,
since that's UB that's extremely easy to catch.

Diff Detail

Event Timeline

ldionne created this revision.Aug 10 2022, 2:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2022, 2:27 PM
ldionne requested review of this revision.Aug 10 2022, 2:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2022, 2:27 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript

Do we want to abort when in debug mode? While it doesn't give the speed improvements in debug mode it would be really nice to get informed when std::unreachable is reached.

LGTM. I would leave approvals to others

ldionne updated this revision to Diff 487967.Jan 10 2023, 1:24 PM
ldionne retitled this revision from [libc++] Use __builtin_unreachable unconditionally to [libc++] Improve the implementation of std::unreachable.
ldionne edited the summary of this revision. (Show Details)

Rebase onto main and address comments

This revision was not accepted when it landed; it landed in state Needs Review.Jan 11 2023, 7:15 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.