<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 - Instruction selection error on asm-goto statement"
   href="https://bugs.llvm.org/show_bug.cgi?id=42489">42489</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Instruction selection error on asm-goto statement
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

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

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

        <tr>
          <th>Reporter</th>
          <td>glider@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following sample is a creduce-d piece of Android kernel:

$ cat rotator.i
d() {
  for (int e = 0; e < 3; e++)
    if (e) {
      _Bool branch = 0;
      int *f = 0;
      asm goto("1: nop\n\t.quad b, %l[l_yes], %c0\n\t"
               :
               : "i"(&f[branch])
               :
               : l_yes);
    l_yes:
      g();
    }
}

Compiling it with GCC works just fine:

$ gcc -g -w -o rotator.o rotator.i -fno-pie -c -O2
(note that neither GCC nor Clang can compile it with -O0 - this probably has
something to do with loop unrolling)

whereas Clang crashes on instruction selection:

$ clang  -no-integrated-as -g -w -o rotator.o rotator.i -c -fno-pie -O2
clang-9:
/usr/local/google/src/llvm-git-monorepo/llvm/include/llvm/Support/Casting.h:264:
typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X =
llvm::BlockAddress; Y = llvm::Value; typename llvm::cast_retty<X, Y*>::ret_type
= llvm::BlockAddress*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of
incompatible type!"' failed.
Stack dump:
0.      Program arguments:
/usr/local/google/src/llvm-git-monorepo/llvm_cmake_build/bin/clang-9 -cc1
-triple x86_64-unknown-linux-gnu -S -disable-free -main-file-name rotator.i
-mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose
-no-integrated-as -mconstructor-aliases -munwind-tables -fuse-init-array
-target-cpu x86-64 -dwarf-column-info -debug-info-kind=limited -dwarf-version=4
-debugger-tuning=gdb -momit-leaf-frame-pointer -coverage-notes-file
/usr/local/google/src/kernel-bonito-new/out/android-msm-pixel-4.9/private/msm-google/rotator.gcno
-resource-dir
/usr/local/google/src/llvm-git-monorepo/llvm_cmake_build/lib/clang/9.0.0 -O2 -w
-fno-dwarf-directory-asm -fdebug-compilation-dir
/usr/local/google/src/kernel-bonito-new/out/android-msm-pixel-4.9/private/msm-google
-ferror-limit 19 -fmessage-length 0 -fobjc-runtime=gcc
-fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp
-o /tmp/rotator-804c16.s -x cpp-output rotator.i 
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'rotator.i'.
4.      Running pass 'X86 DAG->DAG Instruction Selection' on function '@d'
 #0 0x000056287f64a17a llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/usr/local/google/src/llvm-git-monorepo/llvm_cmake_build/bin/clang-9+0x2b0e17a)
 #1 0x000056287f647fa4 llvm::sys::RunSignalHandlers()
(/usr/local/google/src/llvm-git-monorepo/llvm_cmake_build/bin/clang-9+0x2b0bfa4)
 #2 0x000056287f6480d2 SignalHandler(int)
(/usr/local/google/src/llvm-git-monorepo/llvm_cmake_build/bin/clang-9+0x2b0c0d2)
 #3 0x00007f52f79713a0 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x123a0)
 #4 0x00007f52f6462cfb raise (/lib/x86_64-linux-gnu/libc.so.6+0x36cfb)
 #5 0x00007f52f644d8ad abort (/lib/x86_64-linux-gnu/libc.so.6+0x218ad)
 #6 0x00007f52f644d77f (/lib/x86_64-linux-gnu/libc.so.6+0x2177f)
 #7 0x00007f52f645b542 (/lib/x86_64-linux-gnu/libc.so.6+0x2f542)
 #8 0x000056288011dcae
llvm::SelectionDAGBuilder::visitInlineAsm(llvm::ImmutableCallSite)
(/usr/local/google/src/llvm-git-monorepo/llvm_cmake_build/bin/clang-9+0x35e1cae)
 #9 0x000056288011e067 llvm::SelectionDAGBuilder::visitCallBr(llvm::CallBrInst
const&)
(/usr/local/google/src/llvm-git-monorepo/llvm_cmake_build/bin/clang-9+0x35e2067)
#10 0x0000562880131e5f llvm::SelectionDAGBuilder::visit(llvm::Instruction
const&)
(/usr/local/google/src/llvm-git-monorepo/llvm_cmake_build/bin/clang-9+0x35f5e5f)

Note that the same problem is reproducible with --target=aarch64-linux-gnu, so
it's not X86-specific</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>