Sometimes when a function is inlined into a different CU, llvm-dwarfdump --verify would find an inlined subroutine with an invalid abstract origin. This is because DwarfUnit::addDIEEntry() will incorrectly assume the inlined subroutine and the abstract origin are from the same CU if it can't find the CU for the inlined subroutine.
In the added test, the inlined subroutine for bar() is created before the CU for B.swift is created, so it tries to point to goo() in the wrong CU. Interestingly, if we swap the order of the two functions then we don't see a crash since the module for goo() is created first.
The fix is to give a parent DIE to ScopeDIE before calling addDIEEntry() so that its CU can be found. Luckily, constructInlinedScopeDIE() is only called once so we can pass it the DIE of the scope's parent and give it a child just after it's created.
constructInlinedScopeDIE() should always return a DIE, so assert that it is not null.
Can you add CHECKs that actually verify that the dwarfdump output is as expected? RIght now this test will also succeed if llc decides to strip out the debug info entirely ;-)