]> granicus.if.org Git - clang/commitdiff
Emit debug info for global constants whose address is taken exactly once.
authorAdrian Prantl <aprantl@apple.com>
Wed, 9 Nov 2016 00:42:03 +0000 (00:42 +0000)
committerAdrian Prantl <aprantl@apple.com>
Wed, 9 Nov 2016 00:42:03 +0000 (00:42 +0000)
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>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286322 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
test/CodeGen/debug-info-global-constant.c [new file with mode: 0644]

index b17d2482a784c244c7408b9f72819a1ed885d7d0..c4e7ffdd54e646fef11edc2b349cf5119500b253 100644 (file)
@@ -3675,6 +3675,13 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
   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;
diff --git a/test/CodeGen/debug-info-global-constant.c b/test/CodeGen/debug-info-global-constant.c
new file mode 100644 (file)
index 0000000..f214fdc
--- /dev/null
@@ -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);
+}