diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -980,9 +980,7 @@ bool visitedAllDependencies = Item.getInt(); WorkList.pop_back(); - // Dependency is in a different lexical scope or a global. - if (!Var) - continue; + assert(Var); // Already handled. if (Visited.count(Var)) @@ -1006,8 +1004,10 @@ // visited again after all of its dependencies are handled. WorkList.push_back({Var, 1}); for (auto *Dependency : dependencies(Var)) { - auto Dep = dyn_cast_or_null(Dependency); - WorkList.push_back({DbgVar[Dep], 0}); + // Don't add dependency if it is in a different lexical scope or a global. + if (const auto *Dep = dyn_cast(Dependency)) + if (DbgVariable *Var = DbgVar[Dep]) + WorkList.push_back({Var, 0}); } } return Result;