<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Sep 18, 2018 at 9:33 AM David Blaikie via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Sep 18, 2018 at 1:08 AM Hans Wennborg 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, Sep 17, 2018 at 7:57 PM, Nico Weber via cfe-dev<br>
<<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br>
> Hi,<br>
><br>
> in <a href="https://reviews.llvm.org/D52143" rel="noreferrer" target="_blank">https://reviews.llvm.org/D52143</a> there's some uncertainty if LLVM code<br>
> prefers<br>
><br>
>   if (!Function())<br>
>     // Call to function failed, deal with it<br>
><br>
> or<br>
><br>
>   if (Function())<br>
>     // Call to function failed, deal with it<br>
><br>
> (Note that this is about functions returning bool, not int.)<br>
><br>
> Folks on that review feel that returning true on success is probably what we<br>
> want, but it's not documented anywhere and we do have both forms in the<br>
> codebase.<br>
><br>
> True on success seems more common:<br>
> <a href="http://llvm-cs.pcc.me.uk/?q=true+on+success" rel="noreferrer" target="_blank">http://llvm-cs.pcc.me.uk/?q=true+on+success</a><br>
> <a href="http://llvm-cs.pcc.me.uk/?q=true+on+error" rel="noreferrer" target="_blank">http://llvm-cs.pcc.me.uk/?q=true+on+error</a><br>
><br>
> Does anyone have a pointer to previous on-list discussion on this? If not,<br>
> this thread could be the place where we sort this out once and for all :-)<br>
<br>
I don't remember on-list discussions about this, but I'd be curious to<br>
learn about the background.<br>
<br>
In particular, true-on-error seems pervasive in our various parsers,<br>
both in Clang and LLVM. Is this some parser writing convention that's<br>
also used outside LLVM, or why do we do this?<br></blockquote><div><br></div></div></div><div dir="ltr"><div class="gmail_quote"><div>Nah, I believe it was an early LLVM convention (thought it was in the style guide at some point - but perhaps it was just an undocumented norm that was discussed from time to time) based on the idea that functions returning integers on failure in C APIs used zero-on-success, non-zero-on-failure - and the idea was that bool false-on-success, true-on-failure was consistent with that.<br></div></div></div></blockquote><div><br></div><div>It was an early LLVM and Clang convention, pushed much more commonly in Clang's parser for a while.</div><div><br></div><div>The theory was more about "returns whether there is an error" -> "returns true on error".</div><div><br></div><div>That said, there were several long email discussions about this many years ago (no idea how to find them now) and there was general consensus that new APIs should probably use "true on success" instead, but that code shouldn't *mix* the two conventions as that is much more confusing.</div><div><br></div><div>At some point, I think it would make a lot of sense to just systematically fix all of the cases we can find of "true on error".</div><div><br></div><div>-Chandler</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><br>- Dave</div></div></div><div dir="ltr"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Cheers,<br>
Hans<br>
_______________________________________________<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="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></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="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>