From f0ffc5233d7042aa426e2305a64e6a09ba4e6c8a Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 23 Mar 2017 23:35:00 +0000 Subject: [PATCH] Fix a bug when emitting debug info for partially constant global variables. While fixing a malformed testcase, I discovered that the code exercised by it was wrong, too. llvm-svn: 298664 --- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | 9 ++------- llvm/test/DebugInfo/X86/split-global.ll | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp index 60973f33af5a..40712463590b 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -142,12 +142,6 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE( bool addToAccelTable = false; DIELoc *Loc = nullptr; std::unique_ptr DwarfExpr; - bool AllConstant = std::all_of( - GlobalExprs.begin(), GlobalExprs.end(), - [&](const GlobalExpr GE) { - return GE.Expr && GE.Expr->isConstant(); - }); - for (const auto &GE : GlobalExprs) { const GlobalVariable *Global = GE.Var; const DIExpression *Expr = GE.Expr; @@ -158,7 +152,8 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE( addConstantValue(*VariableDIE, /*Unsigned=*/true, Expr->getElement(1)); // We cannot describe the location of dllimport'd variables: the // computation of their address requires loads from the IAT. - } else if ((Global && !Global->hasDLLImportStorageClass()) || AllConstant) { + } else if ((Global && !Global->hasDLLImportStorageClass()) || + (Expr && Expr->isConstant())) { if (!Loc) { Loc = new (DIEValueAllocator) DIELoc; DwarfExpr = llvm::make_unique(*Asm, *this, *Loc); diff --git a/llvm/test/DebugInfo/X86/split-global.ll b/llvm/test/DebugInfo/X86/split-global.ll index 536ed045b5d6..3cdecdafc8d4 100644 --- a/llvm/test/DebugInfo/X86/split-global.ll +++ b/llvm/test/DebugInfo/X86/split-global.ll @@ -30,7 +30,7 @@ target triple = "x86_64-apple-macosx10.12.0" @point.y = global i32 2, align 4, !dbg !13 @point.x = global i32 1, align 4, !dbg !12 -@part_const.x = global i32 1, align 4, !dbg !15 +@part_const.x = global i32 1, align 4, !dbg !14 !llvm.dbg.cu = !{!1} !llvm.module.flags = !{!10, !11}