r222485 - DebugInfo: Fix another case of r222377 when we do have a definition of the variable, but we might not be emitting it (such as templates)

David Blaikie dblaikie at gmail.com
Thu Nov 20 16:20:59 PST 2014


Author: dblaikie
Date: Thu Nov 20 18:20:58 2014
New Revision: 222485

URL: http://llvm.org/viewvc/llvm-project?rev=222485&view=rev
Log:
DebugInfo: Fix another case of r222377 when we do have a definition of the variable, but we might not be emitting it (such as templates)

Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/test/CodeGenCXX/debug-info-static-member.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=222485&r1=222484&r2=222485&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Nov 20 18:20:58 2014
@@ -3275,23 +3275,19 @@ void CGDebugInfo::EmitGlobalVariable(con
   if (isa<FunctionDecl>(VD->getDeclContext()))
     return;
   VD = cast<ValueDecl>(VD->getCanonicalDecl());
-  llvm::DIDescriptor DContext =
-      getContextDescriptor(dyn_cast<Decl>(VD->getDeclContext()));
   auto *VarD = cast<VarDecl>(VD);
-
-  // If this is only a declaration, it might be the declaration of a static
-  // variable with an initializer - we still want to ensure that's emitted, but
-  // merely calling getContextDescriptor above has already ensured that. Since
-  // there's no definition to emit, there's no further work to do.
-  if (!VarD->hasDefinition()) {
+  if (VarD->isStaticDataMember()) {
+    auto *RD = cast<RecordDecl>(VarD->getDeclContext());
+    getContextDescriptor(RD);
     // Ensure that the type is retained even though it's otherwise unreferenced.
     RetainedTypes.push_back(
-        CGM.getContext()
-            .getRecordType(cast<RecordDecl>(VD->getDeclContext()))
-            .getAsOpaquePtr());
+        CGM.getContext().getRecordType(RD).getAsOpaquePtr());
     return;
   }
 
+  llvm::DIDescriptor DContext =
+      getContextDescriptor(dyn_cast<Decl>(VD->getDeclContext()));
+
   auto pair = DeclCache.insert(std::make_pair(VD, llvm::WeakVH()));
   if (!pair.second)
     return;

Modified: cfe/trunk/test/CodeGenCXX/debug-info-static-member.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-static-member.cpp?rev=222485&r1=222484&r2=222485&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-static-member.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-static-member.cpp Thu Nov 20 18:20:58 2014
@@ -42,6 +42,10 @@ int main()
 // CHECK: ![[DECL_C:[0-9]+]] = metadata !{metadata !"0xd\00c\00{{.*}}", {{.*}} [ DW_TAG_member ] [c] [line {{.*}}, size 0, align 0, offset 0] [public] [static]
 // CHECK: metadata !"0xd\00const_c\00{{.*}}", {{.*}} [ DW_TAG_member ] [const_c] [line {{.*}}, size 0, align 0, offset 0] [public] [static]
 // CHECK: metadata !"0xd\00x_a\00{{.*}}", {{.*}} [ DW_TAG_member ] [x_a] {{.*}} [public] [static]
+
+// CHECK: ; [ DW_TAG_structure_type ] [static_decl_templ<int>] {{.*}} [def]
+// CHECK: ; [ DW_TAG_member ] [static_decl_templ_var]
+
 // CHECK: [[NS_X:![0-9]+]] = {{.*}} ; [ DW_TAG_namespace ] [x]
 
 // Test this in an anonymous namespace to ensure the type is retained even when
@@ -52,6 +56,7 @@ struct anon_static_decl_struct {
 };
 }
 
+
 // CHECK: ; [ DW_TAG_structure_type ] [anon_static_decl_struct] {{.*}} [def]
 // CHECK: ; [ DW_TAG_member ] [anon_static_decl_var]
 
@@ -59,6 +64,18 @@ int ref() {
   return anon_static_decl_struct::anon_static_decl_var;
 }
 
+template<typename T>
+struct static_decl_templ {
+  static const int static_decl_templ_var = 7;
+};
+
+template<typename T>
+const int static_decl_templ<T>::static_decl_templ_var;
+
+int static_decl_templ_ref() {
+  return static_decl_templ<int>::static_decl_templ_var;
+}
+
 // CHECK: metadata !{metadata !"0x34\00a\00{{.*}}", null, {{.*}} @_ZN1C1aE, metadata ![[DECL_A]]} ; [ DW_TAG_variable ] [a] {{.*}} [def]
 // CHECK: metadata !{metadata !"0x34\00b\00{{.*}}", null, {{.*}} @_ZN1C1bE, metadata ![[DECL_B]]} ; [ DW_TAG_variable ] [b] {{.*}} [def]
 // CHECK: metadata !{metadata !"0x34\00c\00{{.*}}", null, {{.*}} @_ZN1C1cE, metadata ![[DECL_C]]} ; [ DW_TAG_variable ] [c] {{.*}} [def]





More information about the cfe-commits mailing list