r286322 - Emit debug info for global constants whose address is taken exactly once.

Adrian Prantl via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 8 16:42:03 PST 2016


Author: adrian
Date: Tue Nov  8 18:42:03 2016
New Revision: 286322

URL: http://llvm.org/viewvc/llvm-project?rev=286322&view=rev
Log:
Emit debug info for global constants whose address is taken exactly once.

Add a check to the DeclCache before emitting debug info for a
GlobalVariable a second time and just attach the previsously created one to it.

<rdar://problem/26721101>

Added:
    cfe/trunk/test/CodeGen/debug-info-global-constant.c
Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=286322&r1=286321&r2=286322&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Nov  8 18:42:03 2016
@@ -3675,6 +3675,13 @@ void CGDebugInfo::EmitGlobalVariable(llv
   assert(DebugKind >= codegenoptions::LimitedDebugInfo);
   if (D->hasAttr<NoDebugAttr>())
     return;
+
+  // If we already created a DIGlobalVariable for this declaration, just attach
+  // it to the llvm::GlobalVariable.
+  auto Cached = DeclCache.find(D->getCanonicalDecl());
+  if (Cached != DeclCache.end())
+    return Var->addDebugInfo(cast<llvm::DIGlobalVariable>(Cached->second));
+
   // Create global variable debug descriptor.
   llvm::DIFile *Unit = nullptr;
   llvm::DIScope *DContext = nullptr;

Added: cfe/trunk/test/CodeGen/debug-info-global-constant.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-global-constant.c?rev=286322&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/debug-info-global-constant.c (added)
+++ cfe/trunk/test/CodeGen/debug-info-global-constant.c Tue Nov  8 18:42:03 2016
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone \
+// RUN:      -triple %itanium_abi_triple %s -o - | FileCheck %s
+
+// Debug info for a global constant whose address is taken should be emitted
+// exactly once.
+
+// CHECK: @i = internal constant i32 1, align 4, !dbg ![[I:[0-9]+]]
+// CHECK: ![[I]] = distinct !DIGlobalVariable(name: "i",
+// CHECK-SAME:                                expr: ![[EXPR:[0-9]+]]
+// CHECK: !DICompileUnit({{.*}}globals: ![[GLOBALS:[0-9]+]])
+// CHECK: ![[GLOBALS]] = !{![[I]]}
+// CHECK: ![[EXPR]] = !DIExpression(DW_OP_constu, 1, DW_OP_stack_value)
+static const int i = 1;
+
+void g(const int *, int);
+void f() {
+  g(&i, i);
+}




More information about the cfe-commits mailing list