uselistorder is broken for tools which load multiple files
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
Pushed xfailed test as 7c0362b1a1b59a5b7d164debcea7b3c6c6948542
In case anybody else encounters this issue while trying to use llvm-reduce: you can work around this issue by using --write-tmp-files-as-bitcode.
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.
If there's a way to detect that the LLVMContext isn't "fresh" (maybe by passing in a flag), then it would be reasonable to silently ignore this error for pure constants. There simply isn't a way to replicate the use-list-order in that situation. (But for a fresh context, I think it's useful to have the error...)
The correct solution is to restrict access to use-lists of pure constants so that they don't affect program output. Then we wouldn't need to serialize or replicate them in any situation. At one point a number of years ago, I was only a few patches away from landing this...
The correct solution is to restrict access to use-lists of pure constants so that they don't affect program output. Then we wouldn't need to serialize or replicate them in any situation. At one point a number of years ago, I was only a few patches away from landing this...
Found it:
https://discourse.llvm.org/t/rfc-constantdata-should-not-have-use-lists/42606