diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1390,7 +1390,7 @@ virtual void setAuxTarget(const TargetInfo *Aux) {} /// Whether target allows debuginfo types for decl only variables. - virtual bool allowDebugInfoForExternalVar() const { return false; } + virtual bool allowDebugInfoForExternalVar() const { return true; } protected: /// Copy type and layout related info. diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -4594,6 +4594,8 @@ assert(DebugKind >= codegenoptions::LimitedDebugInfo); if (D->hasAttr()) return; + if (!(DebugKind == clang::codegenoptions::FullDebugInfo)) + return; auto Align = getDeclAlignIfRequired(D, CGM.getContext()); llvm::DIFile *Unit = getOrCreateFile(D->getLocation()); 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 @@ -171,7 +171,11 @@ if (!GV->isDefinition()) addFlag(*VariableDIE, dwarf::DW_AT_declaration); else + { + // Add location. + addLocationAttribute(VariableDIE, GV, GlobalExprs); addGlobalName(GV->getName(), *VariableDIE, DeclContext); + } if (uint32_t AlignInBytes = GV->getAlignInBytes()) addUInt(*VariableDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata, @@ -180,9 +184,6 @@ if (MDTuple *TP = GV->getTemplateParams()) addTemplateParams(*VariableDIE, DINodeArray(TP)); - // Add location. - addLocationAttribute(VariableDIE, GV, GlobalExprs); - return VariableDIE; }