[llvm] r263765 - DebugInfo: Add ability to not emit DW_AT_vtable_elem_location for virtual functions.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 17 17:36:08 PDT 2016


On Thu, Mar 17, 2016 at 5:24 PM, David Blaikie <dblaikie at gmail.com> wrote:

>
>
> On Thu, Mar 17, 2016 at 4:58 PM, Peter Collingbourne via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: pcc
>> Date: Thu Mar 17 18:58:03 2016
>> New Revision: 263765
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=263765&view=rev
>> Log:
>> DebugInfo: Add ability to not emit DW_AT_vtable_elem_location for virtual
>> functions.
>>
>> A virtual index of -1u indicates that the subprogram's virtual index is
>> unrepresentable (for example, when using the relative vtable ABI), so do
>> not emit a DW_AT_vtable_elem_location attribute for it.
>>
>> Differential Revision: http://reviews.llvm.org/D18236
>>
>> Added:
>>     llvm/trunk/test/DebugInfo/Generic/virtual-index.ll
>> Modified:
>>     llvm/trunk/include/llvm/IR/DIBuilder.h
>>     llvm/trunk/lib/AsmParser/LLParser.cpp
>>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
>>     llvm/trunk/lib/IR/AsmWriter.cpp
>>     llvm/trunk/test/Assembler/disubprogram.ll
>>
>> Modified: llvm/trunk/include/llvm/IR/DIBuilder.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DIBuilder.h?rev=263765&r1=263764&r2=263765&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/IR/DIBuilder.h (original)
>> +++ llvm/trunk/include/llvm/IR/DIBuilder.h Thu Mar 17 18:58:03 2016
>> @@ -558,7 +558,8 @@ namespace llvm {
>>      /// \param isDefinition  True if this is a function definition.
>>      /// \param Virtuality    Attributes describing virtualness. e.g. pure
>>      ///                      virtual function.
>> -    /// \param VTableIndex   Index no of this method in virtual table.
>> +    /// \param VTableIndex   Index no of this method in virtual table,
>> or -1u if
>> +    ///                      unrepresentable.
>>      /// \param VTableHolder  Type that holds vtable.
>>      /// \param Flags         e.g. is this function prototyped or not.
>>      ///                      This flags are used to emit dwarf
>> attributes.
>>
>> Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=263765&r1=263764&r2=263765&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
>> +++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu Mar 17 18:58:03 2016
>> @@ -3353,7 +3353,7 @@ bool LLParser::ParseMDField(LocTy Loc, S
>>      return TokError("expected DWARF virtuality code");
>>
>>    unsigned Virtuality = dwarf::getVirtuality(Lex.getStrVal());
>> -  if (!Virtuality)
>> +  if (Virtuality == dwarf::DW_VIRTUALITY_invalid)
>>      return TokError("invalid DWARF virtuality code" + Twine(" '") +
>>                      Lex.getStrVal() + "'");
>>    assert(Virtuality <= Result.Max && "Expected valid DWARF virtuality
>> code");
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=263765&r1=263764&r2=263765&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Thu Mar 17 18:58:03
>> 2016
>> @@ -1218,10 +1218,12 @@ void DwarfUnit::applySubprogramAttribute
>>    unsigned VK = SP->getVirtuality();
>>    if (VK) {
>>      addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, VK);
>> -    DIELoc *Block = getDIELoc();
>> -    addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
>> -    addUInt(*Block, dwarf::DW_FORM_udata, SP->getVirtualIndex());
>> -    addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block);
>> +    if (SP->getVirtualIndex() != -1u) {
>> +      DIELoc *Block = getDIELoc();
>> +      addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
>> +      addUInt(*Block, dwarf::DW_FORM_udata, SP->getVirtualIndex());
>> +      addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block);
>> +    }
>>      ContainingTypeMap.insert(
>>          std::make_pair(&SPDie, resolve(SP->getContainingType())));
>>    }
>>
>> Modified: llvm/trunk/lib/IR/AsmWriter.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=263765&r1=263764&r2=263765&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/IR/AsmWriter.cpp (original)
>> +++ llvm/trunk/lib/IR/AsmWriter.cpp Thu Mar 17 18:58:03 2016
>> @@ -1669,7 +1669,9 @@ static void writeDISubprogram(raw_ostrea
>>    Printer.printMetadata("containingType", N->getRawContainingType());
>>    Printer.printDwarfEnum("virtuality", N->getVirtuality(),
>>                           dwarf::VirtualityString);
>> -  Printer.printInt("virtualIndex", N->getVirtualIndex());
>> +  if (N->getVirtuality() != dwarf::DW_VIRTUALITY_none ||
>> +      N->getVirtualIndex() != 0)
>>
>
> That condition seems a bit wrong - 0 is a valid value for the field & will
> be emitted into the result. So we shouldn't suppress printing it when it's
> 0, should we? I think this should be the same test as in DwarfUnit.
>

We will only suppress if the value is 0 and the subprogram is non-virtual.
The default value in the reader is still 0, so we don't lose information by
suppressing. I guess I could have just left this code the way it was
before, but it seemed confusing to me that this would print only for
non-zero virtualIndices.

Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160317/0c872ab6/attachment.html>


More information about the llvm-commits mailing list