Debug Info: static member DIE creation.
authorManman Ren <manman.ren@gmail.com>
Mon, 14 Oct 2013 20:33:57 +0000 (20:33 +0000)
committerManman Ren <manman.ren@gmail.com>
Mon, 14 Oct 2013 20:33:57 +0000 (20:33 +0000)
Clean up creation of static member DIEs. We can create static member DIEs from
two places, so we call getOrCreateStaticMemberDIE from the two places.

getOrCreateStaticMemberDIE will get or create the context DIE first, then it
will check if the DIE already exists, if not, we create the static member DIE
and add it to the context.

Creation of static member DIEs are handled in a similar way as subprogram DIEs.

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

lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
lib/CodeGen/AsmPrinter/DwarfCompileUnit.h

index b43b98820deb5e518e394bc6095fcc696c0764a7..732db20943edda2f5d310fa6122b03fe1b91a3d2 100644 (file)
@@ -1112,11 +1112,13 @@ void CompileUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
           ElemDie = new DIE(dwarf::DW_TAG_friend);
           addType(ElemDie, resolve(DDTy.getTypeDerivedFrom()),
                   dwarf::DW_AT_friend);
-        } else if (DDTy.isStaticMember())
-          ElemDie = createStaticMemberDIE(DDTy);
-        else
+          Buffer.addChild(ElemDie);
+        } else if (DDTy.isStaticMember()) {
+          ElemDie = getOrCreateStaticMemberDIE(DDTy);
+        } else {
           ElemDie = createMemberDIE(DDTy);
-        Buffer.addChild(ElemDie);
+          Buffer.addChild(ElemDie);
+        }
       } else if (Element.isObjCProperty()) {
         DIObjCProperty Property(Element);
         ElemDie = new DIE(Property.getTag());
@@ -1454,11 +1456,7 @@ void CompileUnit::createGlobalVariableDIE(const MDNode *N) {
   if (SDMDecl.Verify()) {
     assert(SDMDecl.isStaticMember() && "Expected static member decl");
     // We need the declaration DIE that is in the static member's class.
-    // But that class might not exist in the DWARF yet.
-    // Creating the class will create the static member decl DIE.
-    getOrCreateContextDIE(resolve(SDMDecl.getContext()));
-    VariableDIE = getDIE(SDMDecl);
-    assert(VariableDIE && "Static member decl has no context?");
+    VariableDIE = getOrCreateStaticMemberDIE(SDMDecl);
     IsStaticMember = true;
   }
 
@@ -1819,12 +1817,24 @@ DIE *CompileUnit::createMemberDIE(DIDerivedType DT) {
   return MemberDie;
 }
 
-/// createStaticMemberDIE - Create new DIE for C++ static member.
-DIE *CompileUnit::createStaticMemberDIE(const DIDerivedType DT) {
+/// getOrCreateStaticMemberDIE - Create new DIE for C++ static member.
+DIE *CompileUnit::getOrCreateStaticMemberDIE(const DIDerivedType DT) {
   if (!DT.Verify())
     return NULL;
 
-  DIE *StaticMemberDIE = new DIE(DT.getTag());
+  // Construct the context before querying for the existence of the DIE in case
+  // such construction creates the DIE.
+  DIE *ContextDIE = getOrCreateContextDIE(resolve(DT.getContext()));
+  assert(ContextDIE && "Static member should belong to a non-CU context.");
+
+  DIE *StaticMemberDIE = getDIE(DT);
+  if (StaticMemberDIE)
+    return StaticMemberDIE;
+
+  StaticMemberDIE = new DIE(DT.getTag());
+  // Add to context owner.
+  ContextDIE->addChild(StaticMemberDIE);
+
   DIType Ty = resolve(DT.getTypeDerivedFrom());
 
   addString(StaticMemberDIE, dwarf::DW_AT_name, DT.getName());
index 43b24f720eb0b1a8956225b8dcdef96e27270820..0364f38be9468c0edd4d661fcc3368f856f41408 100644 (file)
@@ -329,8 +329,8 @@ private:
   /// createMemberDIE - Create new member DIE.
   DIE *createMemberDIE(DIDerivedType DT);
 
-  /// createStaticMemberDIE - Create new static data member DIE.
-  DIE *createStaticMemberDIE(DIDerivedType DT);
+  /// getOrCreateStaticMemberDIE - Create new static data member DIE.
+  DIE *getOrCreateStaticMemberDIE(DIDerivedType DT);
 
   /// getLowerBoundDefault - Return the default lower bound for an array. If the
   /// DWARF version doesn't handle the language, return -1.