With implicit modules, it is hard to debug issues that depend on state of the module cache before the clang invocation. The state of the module cache can be changed by other parallel clang invocations that share the module cache.
We build a module by spawning a child thread. Even when the parent thread already validated some modules and stored the FileEntries, the child thread can invalidate those modules, causing use-after-free for the parent thread.
Since this issue is time-sensitive, it is hard to reproduce with a release compiler. With an assert or an ASAN'ed compiler the chance of reproducing is even smaller. This patch tries to diagnose the use-after-free in the compiler, by passing up the list of invalidated modules from the child thread and emitting a hard error in the parent thread.
Another option is to pass down the list of validated modules from the parent thread, the child thread can emit a warning and not invalidate those modules.
I am open to other suggestions as well.