This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Minor cleanup of usage of FloatModeKind with bitmask enums
ClosedPublic

Authored by jolanta.jensen on Jul 8 2022, 7:40 AM.

Diff Detail

Event Timeline

jolanta.jensen created this revision.Jul 8 2022, 7:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 8 2022, 7:40 AM
jolanta.jensen requested review of this revision.Jul 8 2022, 7:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 8 2022, 7:40 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Removing a tab.

tahonermann added a subscriber: tahonermann.
shafik added a subscriber: shafik.Jul 8 2022, 3:31 PM
shafik added inline comments.
clang/include/clang/Basic/TargetInfo.h
894

Why not just cast directly to bool?

tahonermann accepted this revision.Jul 11 2022, 9:30 AM

Looks good, thank you for following up @jolanta.jensen!

This revision is now accepted and ready to land.Jul 11 2022, 9:30 AM
jolanta.jensen added inline comments.Jul 12 2022, 8:57 AM
clang/include/clang/Basic/TargetInfo.h
894

Yes, it will work. But as int is the underlying type I find this way a bit clearer. I hope to be forgiven if I keep it.

tahonermann added inline comments.Jul 12 2022, 11:27 AM
clang/include/clang/Basic/TargetInfo.h
894

I'm ok in either case. It wasn't clear to me what the rationale was for casting to int; your explanation was helpful. Since the underlying type of an enumeration tends to not be well understood (I had to go look up the rules again), it would be nice if we could use C++23 std::to_underlying():

return std::to_underlying((FloatModeKind)RealTypeUsesObjCFPRetMask & T);

LLVM's BitmaskEnum.h has Underlying(), but only exposed in the detail namespace and I don't think it is worth changing just for this. We could do:

return static_cast<std::underlying_type_t<FloatModeKind>>((FloatModeKind)RealTypeUsesObjCFPRetMask & T);

But I personally don't find that to be an improvement in this case. I think the code is fine as is.