<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58629>58629</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            uselistorder is broken for tools which load multiple files
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          arsenm
      </td>
    </tr>
</table>

<pre>
    Tools that load multiple files, such as llvm-diff, cannot handle 2 modules using uselistorder. On the parse of the second module, it sees the uses of constants in the first module, and errors when the indexes mismatch. The error is hard for text IR, and silently ignored for bitcode.

The error is failing on this check:
https://github.com/llvm/llvm-project/blob/7bc7f2da763ba7694bbdda3178d5638348a1bc11/llvm/lib/AsmParser/LLParser.cpp#L7845

The equivalent in the bitcode reader simply drops the uselistorder:
https://github.com/llvm/llvm-project/blob/7bc7f2da763ba7694bbdda3178d5638348a1bc11/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L3485

A simple test which tries to run llvm-diff on the same input shows the issue:

uselistorder.ll:10:1: error: wrong number of indexes, expected 4
uselistorder ptr addrspace(4) null, { 1, 0 }

```
; RUN: llvm-diff %s %s

define void @func() {
entry:
  %gep0 = getelementptr inbounds i8, ptr addrspace(4) null, i64 12
  %gep1 = getelementptr i8, ptr addrspace(4) null, i64 4
  ret void
}

uselistorder ptr addrspace(4) null, { 1, 0 }

```


I'm not sure what the right solution is. We could parse these into their own contexts, but llvm-diff needs the two modules to share the context to compare. Alternatively, the bitcode parsing could check if the users belong to the same parent module when counting and sorting
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFVU2PnDgQ_TVwsYLAQEMfOMzsKFKkUbIaZbVng4vGG2Oztpme-fdbhftTiVabQ7RStymbqueq8vOjt_K9-2qt9ixMIjBthWTzqoNaNLBRafAJ_435dZiY8Ezr1_mDVONIi4MwxgY2CSPRl7PZyhX92eqVOeAIW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