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

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 17 17:24:06 PDT 2016


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.


> +    Printer.printInt("virtualIndex", N->getVirtualIndex(), false);
>    Printer.printDIFlags("flags", N->getFlags());
>    Printer.printBool("isOptimized", N->isOptimized());
>    Printer.printMetadata("templateParams", N->getRawTemplateParams());
>
> Modified: llvm/trunk/test/Assembler/disubprogram.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/disubprogram.ll?rev=263765&r1=263764&r2=263765&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Assembler/disubprogram.ll (original)
> +++ llvm/trunk/test/Assembler/disubprogram.ll Thu Mar 17 18:58:03 2016
> @@ -6,8 +6,8 @@ define void @_Z3foov() !dbg !9 {
>    ret void
>  }
>
> -; CHECK: !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}
> -!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}
> +; CHECK: !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11}
> +!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11}
>
>  !0 = !{null}
>  !1 = distinct !DICompositeType(tag: DW_TAG_structure_type)
> @@ -31,5 +31,23 @@ define void @_Z3foov() !dbg !9 {
>                              flags: DIFlagPrototyped, isOptimized: true,
>                              templateParams: !5, declaration: !8,
> variables: !6)
>
> -!10 = !{i32 1, !"Debug Info Version", i32 3}
> -!llvm.module.flags = !{!10}
> +; CHECK: !10 = distinct !DISubprogram
> +; CHECK-SAME: virtualIndex: 0,
> +!10 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope:
> !1,
> +                            file: !2, line: 7, type: !3, isLocal: true,
> +                            isDefinition: true, scopeLine: 8,
> containingType: !4,
> +                            virtuality: DW_VIRTUALITY_pure_virtual,
> virtualIndex: 0,
> +                            flags: DIFlagPrototyped, isOptimized: true,
> +                            templateParams: !5, declaration: !8,
> variables: !6)
> +
> +; CHECK: !11 = distinct !DISubprogram
> +; CHECK-NOT: virtualIndex
> +!11 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope:
> !1,
> +                            file: !2, line: 7, type: !3, isLocal: true,
> +                            isDefinition: true, scopeLine: 8,
> containingType: !4,
> +                            virtuality: DW_VIRTUALITY_none,
> +                            flags: DIFlagPrototyped, isOptimized: true,
> +                            templateParams: !5, declaration: !8,
> variables: !6)
> +
> +!12 = !{i32 1, !"Debug Info Version", i32 3}
> +!llvm.module.flags = !{!12}
>
> Added: llvm/trunk/test/DebugInfo/Generic/virtual-index.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/virtual-index.ll?rev=263765&view=auto
>
> ==============================================================================
> --- llvm/trunk/test/DebugInfo/Generic/virtual-index.ll (added)
> +++ llvm/trunk/test/DebugInfo/Generic/virtual-index.ll Thu Mar 17 18:58:03
> 2016
> @@ -0,0 +1,71 @@
> +; REQUIRES: object-emission
> +
> +; RUN: %llc_dwarf -O0 -filetype=obj < %s > %t
> +; RUN: llvm-dwarfdump %t | FileCheck %s
> +
> +; Generated from the following C++ source code:
> +;
> +; struct A {
> +;   virtual void f();
> +;   virtual void g();
> +; };
> +;
> +; void A::f() {}
> +; void A::g() {}
> +;
> +; and manually edited to set virtualIndex attribute on the A::g
> subprogram to
> +; 4294967295.
> +
> +; CHECK: DW_TAG_subprogram [
> +; CHECK: DW_AT_vtable_elem_location [DW_FORM_exprloc]  (<0x2> 10 00 )
> +
> +; CHECK: DW_TAG_subprogram [
> +; CHECK-NOT: DW_AT_vtable_elem_location
> +
> +%struct.A = type { i32 (...)** }
> +
> + at _ZTV1A = unnamed_addr constant [4 x i8*] [i8* null, i8* null, i8*
> bitcast (void (%struct.A*)* @_ZN1A1fEv to i8*), i8* bitcast (void
> (%struct.A*)* @_ZN1A1gEv to i8*)], align 8
> +
> +define void @_ZN1A1fEv(%struct.A* %this) unnamed_addr !dbg !18 {
> +  ret void
> +}
> +
> +define void @_ZN1A1gEv(%struct.A* %this) unnamed_addr !dbg !19 {
> +  ret void
> +}
> +
> +!llvm.dbg.cu = !{!0}
> +!llvm.module.flags = !{!20, !21}
> +!llvm.ident = !{!22}
> +
> +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1,
> producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: 1,
> enums: !2, retainedTypes: !3, subprograms: !17)
> +!1 = !DIFile(filename: "x", directory: "x")
> +!2 = !{}
> +!3 = !{!4}
> +!4 = !DICompositeType(tag: DW_TAG_structure_type, name: "A", file: !1,
> line: 1, size: 64, align: 64, elements: !5, vtableHolder: !"_ZTS1A",
> identifier: "_ZTS1A")
> +!5 = !{!6, !12, !16}
> +!6 = !DIDerivedType(tag: DW_TAG_member, name: "_vptr$A", scope: !1, file:
> !1, baseType: !7, size: 64, flags: DIFlagArtificial)
> +!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
> +!8 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "__vtbl_ptr_type",
> baseType: !9, size: 64)
> +!9 = !DISubroutineType(types: !10)
> +!10 = !{!11}
> +!11 = !DIBasicType(name: "int", size: 32, align: 32, encoding:
> DW_ATE_signed)
> +!12 = !DISubprogram(name: "f", linkageName: "_ZN1A1fEv", scope:
> !"_ZTS1A", file: !1, line: 2, type: !13, isLocal: false, isDefinition:
> false, scopeLine: 2, containingType: !"_ZTS1A", virtuality:
> DW_VIRTUALITY_virtual, virtualIndex: 0, flags: DIFlagPrototyped,
> isOptimized: false)
> +!13 = !DISubroutineType(types: !14)
> +!14 = !{null, !15}
> +!15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !"_ZTS1A", size:
> 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
> +!16 = !DISubprogram(name: "g", linkageName: "_ZN1A1gEv", scope:
> !"_ZTS1A", file: !1, line: 3, type: !13, isLocal: false, isDefinition:
> false, scopeLine: 3, containingType: !"_ZTS1A", virtuality:
> DW_VIRTUALITY_virtual, virtualIndex: 4294967295, flags: DIFlagPrototyped,
> isOptimized: false)
> +!17 = !{!18, !19}
> +!18 = distinct !DISubprogram(name: "f", linkageName: "_ZN1A1fEv", scope:
> !"_ZTS1A", file: !1, line: 6, type: !13, isLocal: false, isDefinition:
> true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: false,
> declaration: !12, variables: !2)
> +!19 = distinct !DISubprogram(name: "g", linkageName: "_ZN1A1gEv", scope:
> !"_ZTS1A", file: !1, line: 7, type: !13, isLocal: false, isDefinition:
> true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: false,
> declaration: !16, variables: !2)
> +!20 = !{i32 2, !"Dwarf Version", i32 4}
> +!21 = !{i32 2, !"Debug Info Version", i32 3}
> +!22 = !{!"clang version 3.9.0 (trunk 263469) (llvm/trunk 263156)"}
> +!23 = !DILocalVariable(name: "this", arg: 1, scope: !18, type: !24,
> flags: DIFlagArtificial | DIFlagObjectPointer)
> +!24 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !"_ZTS1A", size:
> 64, align: 64)
> +!25 = !DIExpression()
> +!26 = !DILocation(line: 0, scope: !18)
> +!27 = !DILocation(line: 6, column: 14, scope: !18)
> +!28 = !DILocalVariable(name: "this", arg: 1, scope: !19, type: !24,
> flags: DIFlagArtificial | DIFlagObjectPointer)
> +!29 = !DILocation(line: 0, scope: !19)
> +!30 = !DILocation(line: 7, column: 14, scope: !19)
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160317/6dbbba84/attachment.html>


More information about the llvm-commits mailing list