summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGDebugInfo.cpp
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-11-19 19:42:40 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-11-19 19:42:40 +0000
commit423eb5a6a5a60a67bc5e1030a233e7977fc15b3f (patch)
treead3d84278b26f5112f7175ea86f7ddec1fb37f07 /clang/lib/CodeGen/CGDebugInfo.cpp
parent3563938ee46c0d3f33436ec65a870c082e855f98 (diff)
downloadbcm5719-llvm-423eb5a6a5a60a67bc5e1030a233e7977fc15b3f.tar.gz
bcm5719-llvm-423eb5a6a5a60a67bc5e1030a233e7977fc15b3f.zip
DebugInfo: Don't emit a 'global variable' when a static member declaration is referenced without a definition, just ensure the enclosing class (with the static member declaration) is emitted.
Addresses PR21511 by emitting appropriate metadata rather than faux-global definitions for a variable that doesn't have a definition. llvm-svn: 222377
Diffstat (limited to 'clang/lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r--clang/lib/CodeGen/CGDebugInfo.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 71ccb0d9f90..03a0cd92c25 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3275,15 +3275,29 @@ 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()) {
+ // Ensure that the type is retained even though it's otherwise unreferenced.
+ RetainedTypes.push_back(
+ CGM.getContext()
+ .getRecordType(cast<RecordDecl>(VD->getDeclContext()))
+ .getAsOpaquePtr());
+ return;
+ }
+
auto pair = DeclCache.insert(std::make_pair(VD, llvm::WeakVH()));
if (!pair.second)
return;
- llvm::DIDescriptor DContext =
- getContextDescriptor(dyn_cast<Decl>(VD->getDeclContext()));
llvm::DIGlobalVariable GV = DBuilder.createGlobalVariable(
DContext, Name, StringRef(), Unit, getLineNumber(VD->getLocation()), Ty,
- true, Init,
- getOrCreateStaticDataMemberDeclarationOrNull(cast<VarDecl>(VD)));
+ true, Init, getOrCreateStaticDataMemberDeclarationOrNull(VarD));
pair.first->second = llvm::WeakVH(GV);
}
OpenPOWER on IntegriCloud