Currently, LLParser will create a Function/GlobalVariable forward reference based on the desired pointer type and then modify it when it is declared. With opaque pointers, we generally do not know the correct type to use until we see the declaration.
Solve this by creating the forward reference with a dummy type, and then performing a RAUW with the correct Function/GlobalVariable when it is declared. The approach is shamelessly stolen from https://github.com/TNorthover/llvm-project/commit/b5b55963f62038319fa7a8b1b232226ba1d8ef3c.
This results in a change to the use list order, which is why we see test changes on some module passes that are not stable under reordering.
Seems like we could probably keep this behaviour somehow -- getting the global to the "correct" spot in the module might avoid some of the testcase churn as well. See the example I call out below.