This patch is addressing a problem that occurs when we are combining debug-translation units with non-debug translation units (most notably with LTO).
In LexicalScopes::initialize() in lib/CodeGen/LexicalScopes.cpp we don't reset the LexicalScopes object when a function from a non-debug translation (or rather, compilation) unit is processed. This leaves some residual pointers around, most notably one pointing to the previous function's MachineFunction object. Subsequently, LiveDebugValues may get confused (and assert) later when it is processing the non-debug function and sees a seemingly valid LexicalScopes object, especially one pointing to a machine function object, whose memory may have been re-used for the current function.
The fix is 2-fold:
- Reset the LexicalScopes object in all cases, debug or no.
- Make LiveDebugvalues skip non-debug functions.
This patch is by Andrea DiBiagio.