<div dir="ltr"><div>Hello,</div><div><br></div><div>I just hit a issue with syntax error in IR generated by LLVM involving std::bit_cast. The following is a repro (<a href="https://godbolt.org/z/xTzx3r">https://godbolt.org/z/xTzx3r</a>):<br></div><div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254);font-family:"Consolas, ""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><span style="color:rgb(0,0,255)">#include</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,255)"><</span><span style="color:rgb(163,21,21)">bits/stdc++.h</span><span style="color:rgb(0,0,255)">></span></div><div><span style="color:rgb(0,0,255)">template</span><span style="color:rgb(0,0,0)"><</span><span style="color:rgb(0,0,255)">typename</span><span style="color:rgb(0,0,0)"> LiteralType></span></div><div><span style="color:rgb(0,0,255)">static</span><span style="color:rgb(0,0,0)"> LiteralType f() </span><span style="color:rgb(0,0,255)">noexcept</span><span style="color:rgb(0,0,0)"> {</span></div><div><span style="color:rgb(0,0,0)">   </span><span style="color:rgb(0,0,255)">static_assert</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,255)">sizeof</span><span style="color:rgb(0,0,0)">(LiteralType) == </span><span style="color:rgb(9,134,88)">1</span><span style="color:rgb(0,0,0)">);</span></div><div><span style="color:rgb(0,0,0)">   </span><span style="color:rgb(0,0,255)">constexpr</span><span style="color:rgb(0,0,0)"> LiteralType v = __builtin_bit_cast(LiteralType, </span><span style="color:rgb(0,0,255)">static_cast</span><span style="color:rgb(0,0,0)"><uint8_t>(</span><span style="color:rgb(9,134,88)">0</span><span style="color:rgb(0,0,0)">));</span></div><div><span style="color:rgb(0,0,0)">   </span><span style="color:rgb(0,0,255)">return</span><span style="color:rgb(0,0,0)"> v;</span></div><div><span style="color:rgb(0,0,0)">}</span></div><div><span style="color:rgb(0,0,255)">auto</span><span style="color:rgb(0,0,0)"> g = f<</span><span style="color:rgb(0,0,255)">bool</span><span style="color:rgb(0,0,0)">>;</span></div></blockquote><div><span style="color:rgb(0,0,0)"><br></span></div><div><span style="color:rgb(0,0,0)">The generated IR for 'g' is:</span></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 style="color:rgb(0,0,0);background-color:rgb(255,255,254);font-family:"Consolas, ""><div><span style="color:rgb(0,0,255)">define</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,128,128)">internal</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,128,128)">zeroext</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,128,128)">i1</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,128,128)">@_ZL1fIbET_v</span><span style="color:rgb(0,0,0)">() </span><span style="color:rgb(9,134,88)">#3</span><span style="color:rgb(0,0,0)"> !</span><span style="color:rgb(0,128,128)">dbg</span><span style="color:rgb(0,0,0)"> !</span><span style="color:rgb(9,134,88)">1631</span><span style="color:rgb(0,0,0)"> {</span></div><div><span style="color:rgb(0,0,0)">   </span><span style="color:rgb(0,0,255)">call</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,128,128)">void</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,128,128)">@llvm.dbg.value</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,128,128)">metadata</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,128,128)">i8</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(9,134,88)">0</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(0,128,128)">metadata</span><span style="color:rgb(0,0,0)"> !</span><span style="color:rgb(9,134,88)">1633</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(0,128,128)">metadata</span><span style="color:rgb(0,0,0)"> !</span><span style="color:rgb(0,128,128)">DIExpression</span><span style="color:rgb(0,0,0)">()), !</span><span style="color:rgb(0,128,128)">dbg</span><span style="color:rgb(0,0,0)"> !</span><span style="color:rgb(9,134,88)">1637</span></div><div><span style="color:rgb(0,0,0)">   </span><span style="color:rgb(0,0,255)">ret</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,128,128)">i8</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(9,134,88)">0</span><span style="color:rgb(0,0,0)">, !</span><span style="color:rgb(0,128,128)">dbg</span><span style="color:rgb(0,0,0)"> !</span><span style="color:rgb(9,134,88)">1638</span></div><div><span style="color:rgb(0,0,0)">}</span></div></div></blockquote><div>which contains a syntax error of mismatching return value, and fails when passed to llc:</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div> llvm-as t.ll<br>llvm-as: t.ll:17:7: error: value doesn't match function result type 'i1'<br>  ret i8 0, !dbg !1639<br></div></blockquote><div><br></div><div>The problem goes away if I remove the 'constexpr' assignment statement, and return directly. <br></div>Is this a bug with LLVM?<br><div><br></div><div>Best,<br></div></div><div><div>Haoran<br></div><div> </div><span style="color:rgb(0,0,0)"></span></div></div></div></div>