[LLVMbugs] [Bug 16622] New: clang crashes when doing 128 bit division

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Jul 13 14:42:21 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=16622

            Bug ID: 16622
           Summary: clang crashes when doing 128 bit division
           Product: clang
           Version: 3.3
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Driver
          Assignee: unassignedclangbugs at nondot.org
          Reporter: nruslan_devel at yahoo.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 10878
  --> http://llvm.org/bugs/attachment.cgi?id=10878&action=edit
10-xfXqYg.c file

I have encountered a problem with clang when dividing 128-bit integer by 64-bit
integer to obtain 64-bit result. Platform is x86-64. (GCC seems to work fine
with this code.)

The following example first multiplies two 64-bit integers to obtain 128-bit
result (using clang capabilities) and then using an inline assembly divides it
by 64-bit integer to obtain 64-bit result:

("A" constraint is used for [RDX:RAX] in case of x86-64. It is [EDX:EAX] only
for x86; the crash message mentions 32-bit registers for some reason.)

#include <inttypes.h>

static inline uint64_t divide(__uint128_t a, uint64_t b)
{
    asm (
        "divq %1"
        : "+A" (a)
        : "rm" (b)
        : "cc"
    );
    return (uint64_t) a; /* Just leave the quotient. */
}

uint64_t check_divide(uint64_t a, uint64_t c, uint64_t d)
{
    return divide((__uint128_t) a * c, d);
}

Crash message:

fatal error: error in backend: Cannot select: 0x36567e0: i64 = build_pair
      0x36565e0, 0x36566e0 [ORD=21] [ID=46]
  0x36565e0: i32,ch,glue = CopyFromReg 0x36564e0, 0x3651cd0, 0x36564e0:1
[ORD=21] [ID=44]
    0x3651cd0: i32 = Register %EAX [ORD=21] [ID=14]
    0x36564e0: ch,glue = inlineasm 0x36560e0, 0x3653e50, 0x36520d0, 0x36526d0,
0x36522d0, 0x3651cd0, 0x3653d50, 0x36525d0, 0x36528d0, 0x36561e0, 0x36523d0,
0x3655fe0, 0x36562e0, 0x36563e0, 0x36560e0:1 [ORD=21] [ID=43]
      0x3653e50: i64 = TargetExternalSymbol'divq $1' [ORD=21] [ID=10]
      0x36526d0: i64 = TargetConstant<8> [ORD=21] [ID=12]
      0x36522d0: i32 = TargetConstant<18> [ORD=21] [ID=13]
      0x3651cd0: i32 = Register %EAX [ORD=21] [ID=14]
      0x3653d50: i32 = Register %EDX [ORD=21] [ID=15]
      0x36525d0: i64 = TargetConstant<14> [ORD=21] [ID=16]
      0x36528d0: i64 = FrameIndex<3> [ORD=21] [ID=9]
      0x36561e0: i32 = TargetConstant<-2147483631> [ORD=21] [ID=19]
      0x36523d0: i32 = Register %vreg7 [ORD=21] [ID=17]
      0x3655fe0: i32 = Register %vreg8 [ORD=21] [ID=18]
      0x36562e0: i32 = TargetConstant<12> [ORD=21] [ID=20]
      0x36563e0: i32 = Register %EFLAGS [ORD=21] [ID=21]
      0x36560e0: ch,glue = CopyToReg 0x36524d0, 0x3655fe0, 0x3654050,
0x36527d0:1 [ORD=21] [ID=42]
        0x3655fe0: i32 = Register %vreg8 [ORD=21] [ID=18]
        0x3654050: i32 = truncate 0x3651fd0 [ID=40]
          0x3651fd0: i64 = srl 0x365e8f0, 0x3655ce0 [ID=37]
            0x365e8f0: i64,ch = load 0x3654650, 0x3653c50,
0x3655be0<LD8[%2](align=16)> [ID=36]
              0x3653c50: i64 = FrameIndex<1> [ORD=17] [ID=6]
              0x3655be0: i64 = undef [ORD=13] [ID=3]
            0x3655ce0: i8 = Constant<32> [ID=23]
        0x36527d0: ch,glue = CopyToReg 0x36524d0, 0x36523d0, 0x36521d0 [ORD=21]
[ID=41]
          0x36523d0: i32 = Register %vreg7 [ORD=21] [ID=17]
          0x36521d0: i32 = truncate 0x365e8f0 [ID=38]
            0x365e8f0: i64,ch = load 0x3654650, 0x3653c50,
0x3655be0<LD8[%2](align=16)> [ID=36]
              0x3653c50: i64 = FrameIndex<1> [ORD=17] [ID=6]
              0x3655be0: i64 = undef [ORD=13] [ID=3]
  0x36566e0: i32,ch,glue = CopyFromReg 0x36565e0:1, 0x3653d50, 0x36565e0:2
[ORD=21] [ID=45]
    0x3653d50: i32 = Register %EDX [ORD=21] [ID=15]
    0x36565e0: i32,ch,glue = CopyFromReg 0x36564e0, 0x3651cd0, 0x36564e0:1
[ORD=21] [ID=44]
      0x3651cd0: i32 = Register %EAX [ORD=21] [ID=14]
      0x36564e0: ch,glue = inlineasm 0x36560e0, 0x3653e50, 0x36520d0,
0x36526d0, 0x36522d0, 0x3651cd0, 0x3653d50, 0x36525d0, 0x36528d0, 0x36561e0,
0x36523d0, 0x3655fe0, 0x36562e0, 0x36563e0, 0x36560e0:1 [ORD=21] [ID=43]
        0x3653e50: i64 = TargetExternalSymbol'divq $1' [ORD=21] [ID=10]
        0x36526d0: i64 = TargetConstant<8> [ORD=21] [ID=12]
        0x36522d0: i32 = TargetConstant<18> [ORD=21] [ID=13]
        0x3651cd0: i32 = Register %EAX [ORD=21] [ID=14]
        0x3653d50: i32 = Register %EDX [ORD=21] [ID=15]
        0x36525d0: i64 = TargetConstant<14> [ORD=21] [ID=16]
        0x36528d0: i64 = FrameIndex<3> [ORD=21] [ID=9]
        0x36561e0: i32 = TargetConstant<-2147483631> [ORD=21] [ID=19]
        0x36523d0: i32 = Register %vreg7 [ORD=21] [ID=17]
        0x3655fe0: i32 = Register %vreg8 [ORD=21] [ID=18]
        0x36562e0: i32 = TargetConstant<12> [ORD=21] [ID=20]
        0x36563e0: i32 = Register %EFLAGS [ORD=21] [ID=21]
        0x36560e0: ch,glue = CopyToReg 0x36524d0, 0x3655fe0, 0x3654050,
0x36527d0:1 [ORD=21] [ID=42]
          0x3655fe0: i32 = Register %vreg8 [ORD=21] [ID=18]
          0x3654050: i32 = truncate 0x3651fd0 [ID=40]
            0x3651fd0: i64 = srl 0x365e8f0, 0x3655ce0 [ID=37]
              0x365e8f0: i64,ch = load 0x3654650, 0x3653c50,
0x3655be0<LD8[%2](align=16)> [ID=36]
                0x3653c50: i64 = FrameIndex<1> [ORD=17] [ID=6]
                0x3655be0: i64 = undef [ORD=13] [ID=3]
              0x3655ce0: i8 = Constant<32> [ID=23]
          0x36527d0: ch,glue = CopyToReg 0x36524d0, 0x36523d0, 0x36521d0
[ORD=21] [ID=41]
            0x36523d0: i32 = Register %vreg7 [ORD=21] [ID=17]
            0x36521d0: i32 = truncate 0x365e8f0 [ID=38]
              0x365e8f0: i64,ch = load 0x3654650, 0x3653c50,
0x3655be0<LD8[%2](align=16)> [ID=36]
                0x3653c50: i64 = FrameIndex<1> [ORD=17] [ID=6]
                0x3655be0: i64 = undef [ORD=13] [ID=3]
In function: divide
clang: error: clang frontend command failed with exit code 70 (use -v to see
invocation)
clang version 3.3 (tags/RELEASE_33/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
clang: note: diagnostic msg: PLEASE submit a bug report to
http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and
associated run script.
clang: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/10-xfXqYg.c
clang: note: diagnostic msg: /tmp/10-xfXqYg.sh
clang: note: diagnostic msg: 

********************

-- 
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/20130713/093123c6/attachment.html>


More information about the llvm-bugs mailing list