<div dir="ltr">Hello LLVM,<div><br></div><div>I have found and filed PR22750, and I've looked into fixing it.</div><div><br></div><div>Basically, it's an assertion failure during debug info generation, and its cause is the interaction of two factors:</div><div>1) When generating a DW_TAG_imported_declaration DIE which imports another imported declaration, the code in lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp asserts that the second imported declaration must already have a DIE (line 661).<br></div><div>2) There is a non-determinism in the order in which imported declarations within the same scope are processed.</div><div><br></div><div>Because of the non-determinism (2), it is possible that an imported declaration is processed before another one it depends on, breaking the assumption in (1).</div><div><br></div><div>I have tracked down the source of the non-determinism.</div><div>The imported declaration DIDescriptors are sorted by scope in DwarfDebug::beginModule(), in lib/CodeGen/AsmPrinter/DwarfDebug.cpp:480; however that sort is not a stable_sort, therefore the order of the declarations within the same scope is not preserved.</div><div><br></div><div>The attached patch changes the std::sort to a std::stable_sort and it fixes the problem.</div><div><br></div><div>I'm not 100% sure this is the right solution, even if it works. My question is: would it be better to relax the assumption in (1), e.g. by making the code create the dependency DIE on demand?</div><div><br></div><div>Cheers,</div><div>    Dario Domizioli</div><div>    SN Systems - Sony Computer Entertainment Group</div><div><br></div><div><br></div></div>