This is an archive of the discontinued LLVM Phabricator instance.

ADT: add <bit> header, implement C++20 bit_cast, use
ClosedPublic

Authored by jfb on Sep 5 2018, 10:36 AM.

Details

Summary

I saw a few places that were punning through a union of FP and integer, and that made me sad. Luckily, C++20 adds bit_cast for exactly that purpose. Implement our own version in ADT (without constexpr, leaving us a bit sad), and use it in the few places my grep-fu found silly union punning.

Diff Detail

Repository
rL LLVM

Event Timeline

jfb created this revision.Sep 5 2018, 10:36 AM
steven_wu accepted this revision.Sep 7 2018, 11:11 AM
steven_wu added a subscriber: steven_wu.

LGTM!

This revision is now accepted and ready to land.Sep 7 2018, 11:11 AM
srhines accepted this revision.Sep 7 2018, 11:29 AM
srhines added a subscriber: srhines.

Union punning is one of my pet peeves, so I am glad to see this. bit_cast seems generally useful too, so thanks for adding it.

This revision was automatically updated to reflect the committed changes.
jfb added a comment.EditedSep 7 2018, 4:25 PM

Reverted by r341730. Looks like missing std::is_trivially_copyable, and a missing include in the ARM change (which is what I get for not building that target by default...).
@rsmith points out the workaround in llvm/Support/type_traits.h

jfb added a subscriber: rsmith.Sep 7 2018, 4:30 PM
jfb reopened this revision.Sep 7 2018, 8:54 PM
This revision is now accepted and ready to land.Sep 7 2018, 8:54 PM
jfb updated this revision to Diff 164562.Sep 7 2018, 8:54 PM
  • Fix is_trivially_copytable, and ARM build.
This revision was automatically updated to reflect the committed changes.