<div dir="ltr">Sorry for the typo:<div><br></div><div><div>false → 0b0000 → <font color="#cc0000">0b1111 </font>→ true</div><div>true → 0b0001 → 0b1110 → true</div></div></div><br><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">alexandre.isoard@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 style="color:rgb(0,0,0);background-color:rgb(255,255,254)">Hello,</div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254)"><br></div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254)">I encountered a really annoying issue, I am not sure it is Clang or C++ language issue.</div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254)"><br></div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254)">But basically, the following code:</div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254)"><div><div><br><div><span style="color:rgb(0,0,255)">bool</span> foo(<span style="color:rgb(0,0,255)">bool</span> a) {</div><div>    <span style="color:rgb(0,0,255)">return</span> ~a;</div><div>}</div></div></div></div><div><br></div><div>Collapse into:</div><div><br></div><div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254)"><div><span style="color:rgb(0,0,255)">bool</span> foo(<span style="color:rgb(0,0,255)">bool</span> a) {</div><div>    <span style="color:rgb(0,0,255)">return</span> true;</div><div>}</div></div></div><div><br></div><div>The explanation is simple:</div><div>- a is implicitly converted to int using zext</div><div>- int operator~(int) has the unexpected behavior described below</div><div>- then icmp ne 0 is used to convert to bool and is always true</div><div><br></div><div>Here is the truth table of bool-to-int + operator~(int) + int-to-bool:</div><div>false → 0b0000 → 0b0000 → true</div><div>true → 0b0001 → 0b1110 → true</div><div><br></div><div>Note that we can solve the issue by using sext for bool-to-int conversions.</div><div>Should we? Is this a known problem?</div><div><br></div>-- <br><div dir="ltr" class="gmail-m_-557060104621179273gmail_signature"><div dir="ltr"><b>Alexandre Isoard</b><br></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><b>Alexandre Isoard</b><br></div></div>