[llvm-dev] [RFC] Should we add isa_or_null<>?

Don Hinton via llvm-dev llvm-dev at lists.llvm.org
Sat Apr 6 08:00:05 PDT 2019

Hi David:

On Fri, Apr 5, 2019 at 7:50 AM David Chisnall via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> On 05/04/2019 09:13, via llvm-dev wrote:
> > I think "isa_nonnull" would read fine too. To me, the extra "and" makes
> > the ordering more of an issue.
> At the risk of bikeshedding:
> To me, isa_nonnull sounds as if the caller is guaranteeing that the
> argument is nonnull.  I don't think I've seen it in LLVM, but elsewhere
> I've come across a convention of adding nonnull variants of functions
> that skip null checks and pass the non-null restriction to the caller.
> I wonder if the better solution is to rename isa to isa_nonnull and
> introduce a new isa that can take a null argument.  If these have the
> correct nullability annotations then anyone building with clang should
> get a warning if they use the wrong one...

I like your logic, but not sure it's feasible to detect which one you
should use in all cases, e.g., if the user already knows `p` can't be null,
they just use `isa`.  However, if it could be null, they use `p &&
isa<X>(p)`, `cast_or_null` or `dyn_cast_or_null`.  So, we could switch all
the current uses of `isa` to the null variety when we make the change, but
wouldn't we have to trust the user from them on.

Also, wouldn't this be a pretty big change across llvm and all subprojects,
and be an issue for downstream projects.


> David
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190406/8daa3d4f/attachment.html>

More information about the llvm-dev mailing list