Explicitly call LLVMContext::setOpaquePointers in CodeGenAction before loading any IR files. With this we use the mode specified on the command-line rather than lazily initializing it based on the contents of the IR.
This helps when using -fthinlto-index which may end up mixing files with typed and opaque pointer types which fails when the first file happened to use typed pointers since we cannot downgrade IR with opaque pointer types to typed pointer types.
I think it would be fine to always do this, not just for the ThinLTO case.