<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - LLVM error when using bitshift operators (>> and <<) on 64-bit integers"
   href="https://bugs.llvm.org/show_bug.cgi?id=52119">52119</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLVM error when using bitshift operators (>> and <<) on 64-bit integers
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: M68k
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>annika0uwu@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>glaubitz@physik.fu-berlin.de, llvm-bugs@lists.llvm.org, minyihh@uci.edu
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=25344" name="attach_25344" title="Diagnostic report when attempting to compile the generated LLVM-IR with llc.">attachment 25344</a> <a href="attachment.cgi?id=25344&action=edit" title="Diagnostic report when attempting to compile the generated LLVM-IR with llc.">[details]</a></span>
Diagnostic report when attempting to compile the generated LLVM-IR with llc.

LLVM's new m68k target can't handle left-shifts and right-shifts of two 64-bit
integers. This bug isn't specific to C or Clang (it can be reproduced with Rust
as well), but the following C program is an easy way to reproduce it:

void llvm_bug() {
        unsigned long long x = 2;
        unsigned long long y = 2;
        unsigned long long result = x >> y;
}

It builds fine under an m68k GCC cross-compiler, but under Clang, throws the
following error: Cannot select: 0x7fc3c1017300: i32,i32 = srl_parts
0x7fc3c10171c8, 0x7fc3c1017160, 0x7fc3c1017090.

This is the output when building the above program (saved as shift.c) with
`bin/clang -target m68k-unknown-linux-gnu shift.c -nostdlib`:
fatal error: error in backend: Cannot select: 0x7f9644092b00: i32,i32 =
srl_parts 0x7f96440929c8, 0x7f9644092960, 0x7f9644092890
  0x7f96440929c8: i32,ch = load<(dereferenceable load (s32) from %ir.1 + 4,
basealign 8)> 0x7f96440927c0, 0x7f96440926f0, undef:i32
    0x7f96440926f0: i32 = or FrameIndex:i32<0>, Constant:i32<4>
      0x7f9644091e68: i32 = FrameIndex<0>
      0x7f96440924e8: i32 = Constant<4>
    0x7f9644091f38: i32 = undef
  0x7f9644092960: i32,ch = load<(dereferenceable load (s32) from %ir.1, align
8)> 0x7f96440927c0, FrameIndex:i32<0>, undef:i32
    0x7f9644091e68: i32 = FrameIndex<0>
    0x7f9644091f38: i32 = undef
  0x7f9644092890: i32,ch = load<(dereferenceable load (s32) from %ir.2 + 4,
basealign 8)> 0x7f96440927c0, 0x7f96440928f8, undef:i32
    0x7f96440928f8: i32 = or FrameIndex:i32<1>, Constant:i32<4>
      0x7f9644092008: i32 = FrameIndex<1>
      0x7f96440924e8: i32 = Constant<4>
    0x7f9644091f38: i32 = undef
In function: llvm_bug
clang-14: error: clang frontend command failed with exit code 70 (use -v to see
invocation)
clang version 14.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
9697f93587f46300814f1c6c68af347441d6e05d)
Target: m68k-unknown-linux-gnu
Thread model: posix
InstalledDir: /Users/annika/llvm-project/build/bin
clang-14: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-14: note: diagnostic msg:
/var/folders/cn/qwypwgqn3vn7wwn5ksn9lr5w0000gn/T/shift-5ddeee.c
clang-14: note: diagnostic msg:
/var/folders/cn/qwypwgqn3vn7wwn5ksn9lr5w0000gn/T/shift-5ddeee.sh
clang-14: note: diagnostic msg: Crash backtrace is located in
clang-14: note: diagnostic msg:
/Users/annika/Library/Logs/DiagnosticReports/clang-14_<YYYY-MM-DD-HHMMSS>_<hostname>.crash
clang-14: note: diagnostic msg: (choose the .crash file that corresponds to
your crash)
clang-14: note: diagnostic msg:

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

For some reason, clang didn't generate the `.crash` file it was talking about,
but compiling to LLVM-IR and then using llc made the proper diagnostic report,
which I have attached.

I understand that m68k support is experimental, but I would still like to
report this bug in hopes that it will either eventually be fixed, or someone
can help me to fix it myself.

Thanks!</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>