<div dir="ltr"><div dir="ltr">On Thu, Sep 9, 2021 at 11:02 AM Sanjay Patel <<a href="mailto:spatel@rotateright.com">spatel@rotateright.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>Not sure which way to go, but I agree that we need to improve the docs/user experience either way.</div><div>Let's try to iron this out with an example (this is based on <a href="https://llvm.org/PR51775" target="_blank">https://llvm.org/PR51775</a> ):<br></div><div><br></div><div>#include <math.h></div>#include <stdlib.h><br>int main() {<br>    const double d = strtod("1E+1000000", NULL);<br></div></blockquote><div><br></div><div>This should be covered by the "general function call" rule, is therefore unaffected by -ffinite-math-only, and may validly return inf.</div><div><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">    return d == HUGE_VAL;<br></div></blockquote><div><br></div><div>For this comparison, however, the compiler can assume its operands are always finite. Thus, this comparison results in a poison value (in LLVM IR terminology).</div><div><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">What should this program return when compiled with -ffinite-math-only? Should this trigger a clang warning?<br><div><a href="https://godbolt.org/z/MY73Tf3ee" target="_blank">https://godbolt.org/z/MY73Tf3ee</a></div><div></div></div></blockquote><div><br></div><div>We could indeed emit a diagnostic (when -ffinite-math-only is in effect) to let you know that you are doing something guaranteed to be incorrect, by using a manifest constant INF, where you promised that you would not.</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></div><div>The proposed documentation text isn't clear to me. Should clang apply "nnan ninf" to the IR call for "strtod"?</div></div></blockquote><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> "strtod" is not in the enumerated list of functions where we would block fast-math-flags, but it is a standard lib call, so "nnan ninf" would seem to apply...but we also don't want "-ffinite-math-only" to alter the ability to return an INF from a "general function call"?</div></div></blockquote><div><br></div><div><br class="gmail-Apple-interchange-newline">The strtod function should be allowed to return inf/nan. There's two ways we could accomplish that:</div><div>1. We could specify in LLVM that nnan/ninf are meaningless to most function calls. In this case, Clang may continue emitting it everywhere, as is done today, including on strtod, but it would have no impact.</div><div>2. We could specify that clang should not emit nnan/ninf except on certain calls. In this case, Clang would not emit it on strtod.</div><div><br></div><div>I haven't thought about which option would be better. I've been trying to discuss the desired C-facing semantics first.</div><div>  </div></div></div>