<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 - Mishandling of uselistorder when there is a user of type blockaddress"
   href="https://bugs.llvm.org/show_bug.cgi?id=48258">48258</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Mishandling of uselistorder when there is a user of type blockaddress
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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>LLVM assembly language parser
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>itay.bookstein@nextsilicon.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The issue appears to be caused by trying to sort a uselistorder immediately
after parsing it. This mis-interacts with the blockaddress forward-decl
machinery, because the function is a declaration at this point (i.e. the V that
is passed to LLParser::sortUseListOrder), but the directive contains more
indices than uses which have already been materialized due to the forward-decl
machinery.

Reproduction below:

// repro.ll
@__irsym_main = hidden constant i32 (i32, i8**)* @main
@__irbb_main_LBB1 = hidden constant i8* blockaddress(@main, %main_LBB1)

declare i32 @rand()
declare i32 @putchar(i32)

define internal i32 @main(i32, i8** nocapture readnone) {
  %3 = call i32 @rand()
  %4 = icmp eq i32 %3, 5
  br i1 %4, label %main_LBB1, label %main_LBB2

main_LBB1:
  %5 = call i32 @putchar(i32 104)
  br label %main_LBB2

main_LBB2:
  ret i32 0
}

// repro.sh
bin/verify-uselistorder /local/users/itay/tmp/uselist/my.ll

// OUTPUT:
*** verify-uselistorder ***
verify bitcode
verify assembly
reverse
verify bitcode
verify assembly
verify-uselistorder: /tmp/uselistorder-4df326.ll:8:1: error: value only has one
use
uselistorder i32 (i32, i8**)* @main, { 1, 0 }
^
LLVM ERROR: parsing failed
PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace.
Stack dump:
0.      Program arguments: bin/verify-uselistorder
/local/users/itay/tmp/uselist/my.ll
 #0 0x000000000101cf8a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
/local/users/itay/Projects/llvm-project/llvm/lib/Support/Unix/Signals.inc:563:11
 #1 0x000000000101d15b PrintStackTraceSignalHandler(void*)
/local/users/itay/Projects/llvm-project/llvm/lib/Support/Unix/Signals.inc:630:1
 #2 0x000000000101b74b llvm::sys::RunSignalHandlers()
/local/users/itay/Projects/llvm-project/llvm/lib/Support/Signals.cpp:70:5
 #3 0x000000000101d8ad SignalHandler(int)
/local/users/itay/Projects/llvm-project/llvm/lib/Support/Unix/Signals.inc:405:1
 #4 0x00007f1184672730 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12730)
 #5 0x00007f1183f587bb raise
/build/glibc-vjB4T1/glibc-2.28/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #6 0x00007f1183f43535 abort /build/glibc-vjB4T1/glibc-2.28/stdlib/abort.c:81:7
 #7 0x0000000000f54eb5 (bin/verify-uselistorder+0xf54eb5)
 #8 0x0000000000f54d22
/local/users/itay/Projects/llvm-project/llvm/lib/Support/ErrorHandling.cpp:83:3
 #9 0x00000000009c6104 verifyAfterRoundTrip(llvm::Module const&,
std::unique_ptr<llvm::Module, std::default_delete<llvm::Module> >)
/local/users/itay/Projects/llvm-project/llvm/tools/verify-uselistorder/verify-uselistorder.cpp:0:5
#10 0x00000000009c5c1b verifyAssemblyUseListOrder(llvm::Module const&)
/local/users/itay/Projects/llvm-project/llvm/tools/verify-uselistorder/verify-uselistorder.cpp:379:3
#11 0x00000000009c588e verifyUseListOrder(llvm::Module const&)
/local/users/itay/Projects/llvm-project/llvm/tools/verify-uselistorder/verify-uselistorder.cpp:387:1
#12 0x00000000009c568e main
/local/users/itay/Projects/llvm-project/llvm/tools/verify-uselistorder/verify-uselistorder.cpp:568:3
#13 0x00007f1183f4509b __libc_start_main
/build/glibc-vjB4T1/glibc-2.28/csu/../csu/libc-start.c:342:3
#14 0x00000000009c530a _start (bin/verify-uselistorder+0x9c530a)
fish: “bin/verify-uselistorder /local/…” terminated by signal SIGABRT (Abort)</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>