See https://godbolt.org/z/Ka9foTov4, the following simple example would make the compiler crash:
export struct Unit { bool operator<(const Unit&); };
The problem here is that we would set module ownership for the export decl even if we know it is invalid. And for decls who owns a module ownership, the Sema would assume there is a module for it. So here is the crash.
Another straight forward fix would be https://reviews.llvm.org/D117094. But I prefer the current revision. Since it didn't add new branch and it is more easy to read. I guess people reading D117094 without a background might be confusing. "Why is here a branch?". But this patch is more simple. We meet an error so we exit directly. So I prefer this one.
Am I understanding properly that this moved up here so that the for loop on line 553 can traverse the new context?
If so, can it be moved down to immediately before the for loop?