[llvm] r298664 - Fix a bug when emitting debug info for partially constant global variables.

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 23 16:35:01 PDT 2017


Author: adrian
Date: Thu Mar 23 18:35:00 2017
New Revision: 298664

URL: http://llvm.org/viewvc/llvm-project?rev=298664&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
    llvm/trunk/test/DebugInfo/X86/split-global.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=298664&r1=298663&r2=298664&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Thu Mar 23 18:35:00 2017
@@ -142,12 +142,6 @@ DIE *DwarfCompileUnit::getOrCreateGlobal
   bool addToAccelTable = false;
   DIELoc *Loc = nullptr;
   std::unique_ptr<DIEDwarfExpression> 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::getOrCreateGlobal
       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<DIEDwarfExpression>(*Asm, *this, *Loc);

Modified: llvm/trunk/test/DebugInfo/X86/split-global.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/split-global.ll?rev=298664&r1=298663&r2=298664&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/split-global.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/split-global.ll Thu Mar 23 18:35:00 2017
@@ -30,7 +30,7 @@ target triple = "x86_64-apple-macosx10.1
 @point.y = global i32 2, align 4, !dbg !13
 @point.x = global i32 1, align 4, !dbg !12
 
- at part_const.x = global i32 1, align 4, !dbg !15
+ at part_const.x = global i32 1, align 4, !dbg !14
 
 !llvm.dbg.cu = !{!1}
 !llvm.module.flags = !{!10, !11}




More information about the llvm-commits mailing list