RFC https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544 Similar to imported declarations and types, the patch tracks function-local static variables (globals in terms of LLVM IR) in DISubprogram's 'retainedNodes'. DwarfDebug is adjusted in accordance with the aforementioned metadata change and provided a support of static locals scoped by a lexical block. CodeViewDebug is modified to collect global variables from DISubprogram's 'retainedNodes' too. The patch assumes that DICompileUnit's 'globals' no longer tracks static locals and DwarfDebug would assert if any locally-scoped variables get placed there. This change has already been reviewed in https://reviews.llvm.org/D144008, but I’m opening a new PR because it has been a while since it was approved. Additional logic was added to CloneFunction to deal with DISubprograms that have static locals: if such a subprogram is cloned, DIGlobalVariableExpressions are removed from retainedNodes of the clone. This is consistent with the current behavior, in which DIGlobalVariableExpressions are not cloned. Authored-by: Kristina Bessonova <kbessonova@accesssoftek.com> Co-authored-by: Tobias Gysi <tobias.gysi@nextsilicon.com>