<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">But: you can use ! Instead of ~ to avoid this issue.</div><div class=""><br class=""></div><div class="">– Steve</div><div><br class=""><blockquote type="cite" class=""><div class="">On Sep 13, 2019, at 4:52 PM, Stephen Canon <<a href="mailto:scanon@apple.com" class="">scanon@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">The C and C++ language standards fully specify this behavior. There’s no flexibility here to change it.<div class=""><br class=""></div><div class="">– Steve<br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Sep 13, 2019, at 4:49 PM, Alexandre Isoard via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Sorry for the typo:<div class=""><br class=""></div><div class=""><div class="">false → 0b0000 → <font color="#cc0000" class="">0b1111 </font>→ true</div><div class="">true → 0b0001 → 0b1110 → true</div></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 13, 2019 at 1:38 PM Alexandre Isoard <<a href="mailto:alexandre.isoard@gmail.com" class="">alexandre.isoard@gmail.com</a>> wrote:<br class=""></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" class=""><div style="background-color: rgb(255, 255, 254);" class="">Hello,</div><div style="background-color: rgb(255, 255, 254);" class=""><br class=""></div><div style="background-color: rgb(255, 255, 254);" class="">I encountered a really annoying issue, I am not sure it is Clang or C++ language issue.</div><div style="background-color: rgb(255, 255, 254);" class=""><br class=""></div><div style="background-color: rgb(255, 255, 254);" class="">But basically, the following code:</div><div style="background-color: rgb(255, 255, 254);" class=""><div class=""><div class=""><br class=""><div class=""><span style="color:rgb(0,0,255)" class="">bool</span> foo(<span style="color:rgb(0,0,255)" class="">bool</span> a) {</div><div class="">    <span style="color:rgb(0,0,255)" class="">return</span> ~a;</div><div class="">}</div></div></div></div><div class=""><br class=""></div><div class="">Collapse into:</div><div class=""><br class=""></div><div class=""><div style="background-color: rgb(255, 255, 254);" class=""><div class=""><span style="color:rgb(0,0,255)" class="">bool</span> foo(<span style="color:rgb(0,0,255)" class="">bool</span> a) {</div><div class="">    <span style="color:rgb(0,0,255)" class="">return</span> true;</div><div class="">}</div></div></div><div class=""><br class=""></div><div class="">The explanation is simple:</div><div class="">- a is implicitly converted to int using zext</div><div class="">- int operator~(int) has the unexpected behavior described below</div><div class="">- then icmp ne 0 is used to convert to bool and is always true</div><div class=""><br class=""></div><div class="">Here is the truth table of bool-to-int + operator~(int) + int-to-bool:</div><div class="">false → 0b0000 → 0b0000 → true</div><div class="">true → 0b0001 → 0b1110 → true</div><div class=""><br class=""></div><div class="">Note that we can solve the issue by using sext for bool-to-int conversions.</div><div class="">Should we? Is this a known problem?</div><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail-m_-557060104621179273gmail_signature"><div dir="ltr" class=""><b class="">Alexandre Isoard</b><br class=""></div></div></div>
</blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail_signature"><div dir="ltr" class=""><b class="">Alexandre Isoard</b><br class=""></div></div>
_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class=""><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class=""></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></body></html>