]> granicus.if.org Git - clang/commitdiff
Fix crash in EmitDeclMetadata mode
authorKeno Fischer <kfischer@college.harvard.edu>
Thu, 5 Nov 2015 23:18:44 +0000 (23:18 +0000)
committerKeno Fischer <kfischer@college.harvard.edu>
Thu, 5 Nov 2015 23:18:44 +0000 (23:18 +0000)
Summary: This fixes a bug that's easily encountered in LLDB
(https://llvm.org/bugs/show_bug.cgi?id=22875). The problem here is that we
mangle a name during debug info emission, but never actually emit the actual
Decl, so we run into problems in EmitDeclMetadata (which assumes such a Decl
exists). Fix that by just skipping metadata emissions for mangled names that
don't have associated Decls.

Reviewers: rjmccall

Subscribers: labath, cfe-commits

Differential Revision: http://reviews.llvm.org/D13959

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

lib/CodeGen/CodeGenModule.cpp

index 85cdbc48ca4d62312a331136c0ecaa8add64e00e..911953437bd158ff7762c8edf0c27bf49c5791ae 100644 (file)
@@ -3707,10 +3707,12 @@ bool CodeGenModule::lookupRepresentativeDecl(StringRef MangledName,
 void CodeGenModule::EmitDeclMetadata() {
   llvm::NamedMDNode *GlobalMetadata = nullptr;
 
-  // StaticLocalDeclMap
   for (auto &I : MangledDeclNames) {
     llvm::GlobalValue *Addr = getModule().getNamedValue(I.second);
-    EmitGlobalDeclMetadata(*this, GlobalMetadata, I.first, Addr);
+    // Some mangled names don't necessarily have an associated GlobalValue
+    // in this module, e.g. if we mangled it for DebugInfo.
+    if (Addr)
+      EmitGlobalDeclMetadata(*this, GlobalMetadata, I.first, Addr);
   }
 }