Page MenuHomePhabricator

[llvm] Add isa_and_nonnull
ClosedPublic

Authored by hintonda on Apr 4 2019, 4:14 PM.

Details

Summary

Add new `isa_and_nonnull<>` operator that works just like
the `isa<>` operator, except that it allows for a null pointer as an
argument (which it then returns false).

The final name has not yet been determined, but a discussion can be
seen here: http://lists.llvm.org/pipermail/llvm-dev/2019-April/131555.html

Event Timeline

hintonda created this revision.Apr 4 2019, 4:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2019, 4:14 PM
hubert.reinterpretcast added inline comments.
llvm/docs/ProgrammersManual.rst
167

The name seems backwards. What does it mean to check "isa" on null? That question would not arise if the name was nonnull_and_isa.

hintonda marked an inline comment as done.Apr 4 2019, 4:44 PM
hintonda added inline comments.
llvm/docs/ProgrammersManual.rst
167

Btw, there's been 4 naming comments so far, and each one is different. So, I hope we can come to a consensus soon. I originally thought isa_or_null was a good idea because it matches (cast|dyn_cast)_or_null, but since we're returning a bool and not a pointer, I no longer think that's a good name either.

So, I'm open to whatever is decided.

lattner accepted this revision.Apr 4 2019, 10:51 PM

Patch LGTM. I think that the isa_and_nonnull name is the least bad of the options that I've heard, and if someone comes up with a better name, we can always rename it in the future. Thank you for updating the docs as well!

This revision is now accepted and ready to land.Apr 4 2019, 10:51 PM
This revision was automatically updated to reflect the committed changes.