<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 17, 2016 at 5:24 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Thu, Mar 17, 2016 at 4:58 PM, Peter Collingbourne via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: pcc<br>
Date: Thu Mar 17 18:58:03 2016<br>
New Revision: 263765<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=263765&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=263765&view=rev</a><br>
Log:<br>
DebugInfo: Add ability to not emit DW_AT_vtable_elem_location for virtual functions.<br>
<br>
A virtual index of -1u indicates that the subprogram's virtual index is<br>
unrepresentable (for example, when using the relative vtable ABI), so do<br>
not emit a DW_AT_vtable_elem_location attribute for it.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D18236" rel="noreferrer" target="_blank">http://reviews.llvm.org/D18236</a><br>
<br>
Added:<br>
    llvm/trunk/test/DebugInfo/Generic/virtual-index.ll<br>
Modified:<br>
    llvm/trunk/include/llvm/IR/DIBuilder.h<br>
    llvm/trunk/lib/AsmParser/LLParser.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp<br>
    llvm/trunk/lib/IR/AsmWriter.cpp<br>
    llvm/trunk/test/Assembler/disubprogram.ll<br>
<br>
Modified: llvm/trunk/include/llvm/IR/DIBuilder.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DIBuilder.h?rev=263765&r1=263764&r2=263765&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DIBuilder.h?rev=263765&r1=263764&r2=263765&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/IR/DIBuilder.h (original)<br>
+++ llvm/trunk/include/llvm/IR/DIBuilder.h Thu Mar 17 18:58:03 2016<br>
@@ -558,7 +558,8 @@ namespace llvm {<br>
     /// \param isDefinition  True if this is a function definition.<br>
     /// \param Virtuality    Attributes describing virtualness. e.g. pure<br>
     ///                      virtual function.<br>
-    /// \param VTableIndex   Index no of this method in virtual table.<br>
+    /// \param VTableIndex   Index no of this method in virtual table, or -1u if<br>
+    ///                      unrepresentable.<br>
     /// \param VTableHolder  Type that holds vtable.<br>
     /// \param Flags         e.g. is this function prototyped or not.<br>
     ///                      This flags are used to emit dwarf attributes.<br>
<br>
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=263765&r1=263764&r2=263765&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=263765&r1=263764&r2=263765&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)<br>
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu Mar 17 18:58:03 2016<br>
@@ -3353,7 +3353,7 @@ bool LLParser::ParseMDField(LocTy Loc, S<br>
     return TokError("expected DWARF virtuality code");<br>
<br>
   unsigned Virtuality = dwarf::getVirtuality(Lex.getStrVal());<br>
-  if (!Virtuality)<br>
+  if (Virtuality == dwarf::DW_VIRTUALITY_invalid)<br>
     return TokError("invalid DWARF virtuality code" + Twine(" '") +<br>
                     Lex.getStrVal() + "'");<br>
   assert(Virtuality <= Result.Max && "Expected valid DWARF virtuality code");<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=263765&r1=263764&r2=263765&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=263765&r1=263764&r2=263765&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Thu Mar 17 18:58:03 2016<br>
@@ -1218,10 +1218,12 @@ void DwarfUnit::applySubprogramAttribute<br>
   unsigned VK = SP->getVirtuality();<br>
   if (VK) {<br>
     addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, VK);<br>
-    DIELoc *Block = getDIELoc();<br>
-    addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);<br>
-    addUInt(*Block, dwarf::DW_FORM_udata, SP->getVirtualIndex());<br>
-    addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block);<br>
+    if (SP->getVirtualIndex() != -1u) {<br>
+      DIELoc *Block = getDIELoc();<br>
+      addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);<br>
+      addUInt(*Block, dwarf::DW_FORM_udata, SP->getVirtualIndex());<br>
+      addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block);<br>
+    }<br>
     ContainingTypeMap.insert(<br>
         std::make_pair(&SPDie, resolve(SP->getContainingType())));<br>
   }<br>
<br>
Modified: llvm/trunk/lib/IR/AsmWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=263765&r1=263764&r2=263765&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=263765&r1=263764&r2=263765&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)<br>
+++ llvm/trunk/lib/IR/AsmWriter.cpp Thu Mar 17 18:58:03 2016<br>
@@ -1669,7 +1669,9 @@ static void writeDISubprogram(raw_ostrea<br>
   Printer.printMetadata("containingType", N->getRawContainingType());<br>
   Printer.printDwarfEnum("virtuality", N->getVirtuality(),<br>
                          dwarf::VirtualityString);<br>
-  Printer.printInt("virtualIndex", N->getVirtualIndex());<br>
+  if (N->getVirtuality() != dwarf::DW_VIRTUALITY_none ||<br>
+      N->getVirtualIndex() != 0)<br></blockquote><div><br></div></div></div><div>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.</div></div></div></div></blockquote><div><br></div><div>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.</div><div><br></div><div>Peter</div></div>
</div></div>