From 4a2879e2142fbfb97c3dffc59c024924949ef01d Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Fri, 21 Nov 2014 00:20:58 +0000 Subject: [PATCH] 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) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222485 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 18 +++++++----------- test/CodeGenCXX/debug-info-static-member.cpp | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 9506cef31d..e91b6fdf29 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -3275,23 +3275,19 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, if (isa(VD->getDeclContext())) return; VD = cast(VD->getCanonicalDecl()); - llvm::DIDescriptor DContext = - getContextDescriptor(dyn_cast(VD->getDeclContext())); auto *VarD = cast(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(VarD->getDeclContext()); + getContextDescriptor(RD); // Ensure that the type is retained even though it's otherwise unreferenced. RetainedTypes.push_back( - CGM.getContext() - .getRecordType(cast(VD->getDeclContext())) - .getAsOpaquePtr()); + CGM.getContext().getRecordType(RD).getAsOpaquePtr()); return; } + llvm::DIDescriptor DContext = + getContextDescriptor(dyn_cast(VD->getDeclContext())); + auto pair = DeclCache.insert(std::make_pair(VD, llvm::WeakVH())); if (!pair.second) return; diff --git a/test/CodeGenCXX/debug-info-static-member.cpp b/test/CodeGenCXX/debug-info-static-member.cpp index 803d0dc1c7..d80f978b77 100644 --- a/test/CodeGenCXX/debug-info-static-member.cpp +++ b/test/CodeGenCXX/debug-info-static-member.cpp @@ -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] {{.*}} [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 +struct static_decl_templ { + static const int static_decl_templ_var = 7; +}; + +template +const int static_decl_templ::static_decl_templ_var; + +int static_decl_templ_ref() { + return static_decl_templ::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] -- 2.50.1