[llvm-bugs] [Bug 45646] New: __builtin_bit_cast hits unreachable when casting a cast pointer

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Apr 23 05:40:04 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=45646

            Bug ID: 45646
           Summary: __builtin_bit_cast hits unreachable when casting a
                    cast pointer
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: john.brawn at arm.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

If I compile

  long fn() {
    return __builtin_bit_cast(long, (long)&fn);
  }

I get

  LValue subobject in bit_cast?
  UNREACHABLE executed at
/home/jb/work/llvm-project/clang/lib/AST/ExprConstant.cpp:6331!

With a backtrace that shows this happened when trying to evaluate the
__builtin_bit_cast as a constant expression during CodeGen.

This rather odd use of __builtin_bit_cast came originally from
cmse_nsfptr_create which is a macro defined in arm_cmse.h (in
clang/lib/Headers) as

  #define cmse_nsfptr_create(p)                                                
 \
    __builtin_bit_cast(__typeof__(p),                                          
 \
                       (__builtin_bit_cast(uintptr_t, p) & ~(uintptr_t)1))

so you get this failure if you do (compiling with clang --target=arm-none-eabi
-mcpu=cortex-m33 -mcmse)

  #include <arm_cmse.h>
  unsigned fn() {
    cmse_nsfptr_create((unsigned)&fn);
  }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200423/3bbb8d68/attachment.html>


More information about the llvm-bugs mailing list