<div dir="ltr">Agreed that the new isa_or_null style is better. Just wanted mention the other style so we know we should migrate those to the new one.<div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 4, 2019 at 4:37 PM Don Hinton <<a href="mailto:hintonda@gmail.com">hintonda@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Thu, Apr 4, 2019 at 6:29 PM Craig Topper <<a href="mailto:craig.topper@gmail.com" target="_blank">craig.topper@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">There are a handful of places in LLVM that dosomething like if (dyn_cast_or_null<UndefValue>(P->hasConstantValue()))</div></div></blockquote><div><br></div><div>Yes, I've seen those, but while working on a new checker, I was advised that replacing `X && isa<Y>(X)` with `dyn_cast_or_null<Y>(X)` was suboptimal, and it was suggested something like a `isa_or_null` style operator would better express what was actually going on, i.e., we are expecting a bool, not a pointer.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br clear="all"><div><div dir="ltr" class="gmail-m_-476835357822391154gmail-m_-3852499570257309238gmail_signature">~Craig</div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 4, 2019 at 4:16 PM Don Hinton via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>I've added a patch, temporarily using the name Chris suggested. Please let me know what you think.<br></div><div><br></div><div><a href="https://reviews.llvm.org/D60291" target="_blank">https://reviews.llvm.org/D60291</a><br></div><div><br></div><div>thanks...</div><div>don</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 4, 2019 at 2:55 PM David Greene <<a href="mailto:dag@cray.com" target="_blank">dag@cray.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Don Hinton <<a href="mailto:hintonda@gmail.com" target="_blank">hintonda@gmail.com</a>> writes:<br>
<br>
> > if (isa_or_null<T>(var)) {<br>
> > ...<br>
> > }<br>
> ><br>
> > at least according to what "isa_or_null" conveys to me.<br>
><br>
> This is the same convention used by the existing "_or_null" varieties,<br>
> i.e., "cast_or_null" and "dyn_cast_or_null". They accept a null and<br>
> propagate it. In the "isa" case, it would accept a null and propagate<br>
> it as false.<br>
<br>
isa<> is very different from *cast<>. *cast<> gives you a pointer back,<br>
which may be null. isa<> is precondition check, so it "reads"<br>
differently to me. If I were to see:<br>
<br>
if (isa_or_null<T>(var)) {<br>
...<br>
}<br>
<br>
I would think, "Ok, the body is fine if var is null."<br>
<br>
Instead:<br>
<br>
if (exists_and_isa<T>(var)) {<br>
...<br>
}<br>
<br>
This tells me that the body expects a non-null value.<br>
<br>
> > That said, I'm not sure sure we need a special API for this. Are<br>
> > expensive calls used in the way you describe really common?<br>
><br>
> I've only been looking at the ones involving method calls, but it's<br>
> not too common. Perhaps a dozen in clang/lib -- haven't run it<br>
> against the rest of the code base.<br>
<br>
Thanks for checking. I don't have a strong opinion about the need<br>
either way, but I do care that the spelling is clear and intuitive.<br>
<br>
-David<br>
</blockquote></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>
</blockquote></div></div>
</blockquote></div>