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)

llvm-svn: 222485
This commit is contained in:
David Blaikie 2014-11-21 00:20:58 +00:00
parent c57059059d
commit af08085c86
2 changed files with 24 additions and 11 deletions

View File

@ -3275,23 +3275,19 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD,
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;

View File

@ -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]