This is an archive of the discontinued LLVM Phabricator instance.

[LLVM][Casting.h] Add ForwardToPointerCast trait
ClosedPublic

Authored by bzcheeseman on May 13 2022, 11:53 AM.

Details

Summary

Addresses use cases in Clang/MLIR that need pointer-to-pointer, reference-to-reference, and value-to-value casts from/to the same types. This should reduce boilerplate by allowing the user to simply specify the pointer cast and forward the reference cast directly to the pointer cast.

This cast trait DOES NOT implement castFailed and doCastIfPossible because in the general case doing so could result in a nullptr dereference. Users can use NullableValueCastFailed and DefaultDoCastIfPossible as desired for those cases where nullptr is acceptable.

Diff Detail

Event Timeline

bzcheeseman created this revision.May 13 2022, 11:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2022, 11:53 AM
bzcheeseman requested review of this revision.May 13 2022, 11:53 AM
rriddle accepted this revision.May 13 2022, 3:36 PM

Nice.

Was there somewhere in MLIR that could take advantage of this? Trying to recall from another patch.

This revision is now accepted and ready to land.May 13 2022, 3:36 PM

I think Operation casting probably could have used it IIRC

This revision was automatically updated to reflect the committed changes.