From: David Blaikie Date: Sun, 31 Aug 2014 18:04:28 +0000 (+0000) Subject: DebugInfo: Move argument creation up into the caller that's unambiguously handling... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=363d0d273896d5e0ae595547b99fefadc5790819;p=oota-llvm.git DebugInfo: Move argument creation up into the caller that's unambiguously handling the subprogram scope (replacing a conditional with an assertion in the process) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216845 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index cfffef7e747..defae5d920b 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -458,26 +458,6 @@ DIE *DwarfDebug::createScopeChildrenDIE( SmallVectorImpl> &Children) { DIE *ObjectPointer = nullptr; - // Collect arguments for current function. - if (LScopes.isCurrentFunctionScope(Scope)) { - for (DbgVariable *ArgDV : CurrentFnArguments) - if (ArgDV) - Children.push_back( - constructVariableDIE(TheCU, *ArgDV, *Scope, ObjectPointer)); - - // If this is a variadic function, add an unspecified parameter. - DISubprogram SP(Scope->getScopeNode()); - DITypeArray FnArgs = SP.getType().getTypeArray(); - // If we have a single element of null, it is a function that returns void. - // If we have more than one elements and the last one is null, it is a - // variadic function. - if (FnArgs.getNumElements() > 1 && - !FnArgs.getElement(FnArgs.getNumElements() - 1)) - Children.push_back( - make_unique(dwarf::DW_TAG_unspecified_parameters)); - } - - // Collect lexical scope children first. for (DbgVariable *DV : ScopeVariables.lookup(Scope)) Children.push_back(constructVariableDIE(TheCU, *DV, *Scope, ObjectPointer)); @@ -487,16 +467,17 @@ DIE *DwarfDebug::createScopeChildrenDIE( return ObjectPointer; } -void DwarfDebug::createAndAddScopeChildren(DwarfCompileUnit &TheCU, +DIE *DwarfDebug::createAndAddScopeChildren(DwarfCompileUnit &TheCU, LexicalScope *Scope, DIE &ScopeDIE) { // We create children when the scope DIE is not null. SmallVector, 8> Children; - if (DIE *ObjectPointer = createScopeChildrenDIE(TheCU, Scope, Children)) - TheCU.addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, *ObjectPointer); + DIE *ObjectPointer = createScopeChildrenDIE(TheCU, Scope, Children); // Add children for (auto &I : Children) ScopeDIE.addChild(std::move(I)); + + return ObjectPointer; } void DwarfDebug::constructAbstractSubprogramScopeDIE(DwarfCompileUnit &TheCU, @@ -535,7 +516,8 @@ void DwarfDebug::constructAbstractSubprogramScopeDIE(DwarfCompileUnit &TheCU, SPCU.applySubprogramAttributesToDefinition(SP, *AbsDef); SPCU.addUInt(*AbsDef, dwarf::DW_AT_inline, None, dwarf::DW_INL_inlined); - createAndAddScopeChildren(SPCU, Scope, *AbsDef); + if (DIE *ObjectPointer = createAndAddScopeChildren(SPCU, Scope, *AbsDef)) + SPCU.addDIEEntry(*AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer); } DIE &DwarfDebug::constructSubprogramScopeDIE(DwarfCompileUnit &TheCU, @@ -551,7 +533,33 @@ DIE &DwarfDebug::constructSubprogramScopeDIE(DwarfCompileUnit &TheCU, DIE &ScopeDIE = updateSubprogramScopeDIE(TheCU, Sub); - createAndAddScopeChildren(TheCU, Scope, ScopeDIE); + // Collect arguments for current function. + assert(LScopes.isCurrentFunctionScope(Scope)); + DIE *ObjectPointer = nullptr; + for (DbgVariable *ArgDV : CurrentFnArguments) + if (ArgDV) + ScopeDIE.addChild( + constructVariableDIE(TheCU, *ArgDV, *Scope, ObjectPointer)); + + // If this is a variadic function, add an unspecified parameter. + DITypeArray FnArgs = Sub.getType().getTypeArray(); + // If we have a single element of null, it is a function that returns void. + // If we have more than one elements and the last one is null, it is a + // variadic function. + if (FnArgs.getNumElements() > 1 && + !FnArgs.getElement(FnArgs.getNumElements() - 1)) + ScopeDIE.addChild(make_unique(dwarf::DW_TAG_unspecified_parameters)); + + // Collect lexical scope children first. + // ObjectPointer might be a local (non-argument) local variable if it's a + // block's synthetic this pointer. + if (DIE *BlockObjPtr = createAndAddScopeChildren(TheCU, Scope, ScopeDIE)) { + assert(!ObjectPointer && "multiple object pointers can't be described"); + ObjectPointer = BlockObjPtr; + } + + if (ObjectPointer) + TheCU.addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, *ObjectPointer); return ScopeDIE; } diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index b5a20b2b907..40385cf0b2c 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -379,7 +379,7 @@ class DwarfDebug : public AsmPrinterHandler { /// \brief Construct a DIE for this scope. std::unique_ptr constructScopeDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope); - void createAndAddScopeChildren(DwarfCompileUnit &TheCU, LexicalScope *Scope, + DIE *createAndAddScopeChildren(DwarfCompileUnit &TheCU, LexicalScope *Scope, DIE &ScopeDIE); /// \brief Construct a DIE for this abstract scope. void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &TheCU,