[llvm-dev] llvm generates IR with syntax error for C++20 bit_cast

Haoran Xu via llvm-dev llvm-dev at lists.llvm.org
Sat Oct 3 16:31:17 PDT 2020


Hello,

I just hit a issue with syntax error in IR generated by LLVM involving
std::bit_cast. The following is a repro (https://godbolt.org/z/xTzx3r):

> #include <bits/stdc++.h>
> template<typename LiteralType>
> static LiteralType f() noexcept {
>    static_assert(sizeof(LiteralType) == 1);
>    constexpr LiteralType v = __builtin_bit_cast(LiteralType, static_cast
> <uint8_t>(0));
>    return v;
> }
> auto g = f<bool>;
>

The generated IR for 'g' is:

> define internal zeroext i1 @_ZL1fIbET_v() #3 !dbg !1631 {
>    call void @llvm.dbg.value(metadata i8 0, metadata !1633, metadata !
> DIExpression()), !dbg !1637
>    ret i8 0, !dbg !1638
> }
>
which contains a syntax error of mismatching return value, and fails when
passed to llc:

> llvm-as t.ll
> llvm-as: t.ll:17:7: error: value doesn't match function result type 'i1'
>   ret i8 0, !dbg !1639
>

The problem goes away if I remove the 'constexpr' assignment statement, and
return directly.
Is this a bug with LLVM?

Best,
Haoran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201003/d6fb06ac/attachment.html>


More information about the llvm-dev mailing list