This is an issue both with regular and Thin LTO. When we link together
a DICompileUnit that is marked NoDebug (e.g when compiling with -g0
but applying an AutoFDO profile, which requires location tracking
in the compiler) and a DICompileUnit with debug emission enabled,
we can have failures during dwarf debug generation. Specifically,
when we have inlined from the NoDebug compile unit into the debug
compile unit, we can fail during construction of the abstract and
inlined scope DIEs. This is because the SPMap does not include NoDebug
CUs (they are skipped in the debug_compile_units_iterator).
This patch fixes the failures by skipping SPs from NoDebug CUs when
generating these DIEs. I am not sure if this is the right fix from
the debug generation standpoint, however. I don't know if we should
instead either upgrade NoDebug CU on link with a debug CU, or enable
adding these NoDebug CUs into the SPMap.
This probably won't catch all cases - if the location was in a subscope within the function (eg: try adding a {} to the function which should add an extra scope). Walking the scope chain until a DISubprogram is probably needed here - I forget if we have a nice wrapped up utility for that. Don't see one at a glance.
It should be an invariant/guaranteed that a DISubprogram is reached (& is the end of the scope chain), so something like:
oh, wait, no, here it is: http://llvm.org/docs/doxygen/html/classllvm_1_1DILocalScope.html#a747dd1690fc477a8d9638fa37a30ced8
so, I think, maybe: