[llvm] r190190 - Debug Info: Use identifier to reference DIType in containing type field of

David Blaikie dblaikie at gmail.com
Fri Sep 6 12:54:31 PDT 2013


On Fri, Sep 6, 2013 at 12:02 PM, Manman Ren <manman.ren at gmail.com> wrote:

>
>
>
> On Fri, Sep 6, 2013 at 11:53 AM, David Blaikie <dblaikie at gmail.com> wrote:
>
>>
>>
>>
>> On Fri, Sep 6, 2013 at 11:46 AM, Manman Ren <manman.ren at gmail.com> wrote:
>>
>>> Author: mren
>>> Date: Fri Sep  6 13:46:00 2013
>>> New Revision: 190190
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=190190&view=rev
>>> Log:
>>> Debug Info: Use identifier to reference DIType in containing type field
>>> of
>>> a DICompositeType.
>>>
>>> Verifier is updated accordingly.
>>>
>>> Added:
>>>     llvm/trunk/test/DebugInfo/tu-composite.ll
>>> Modified:
>>>     llvm/trunk/include/llvm/DebugInfo.h
>>>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
>>>     llvm/trunk/lib/IR/DIBuilder.cpp
>>>     llvm/trunk/lib/IR/DebugInfo.cpp
>>>
>>> Modified: llvm/trunk/include/llvm/DebugInfo.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo.h?rev=190190&r1=190189&r2=190190&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/include/llvm/DebugInfo.h (original)
>>> +++ llvm/trunk/include/llvm/DebugInfo.h Fri Sep  6 13:46:00 2013
>>> @@ -358,8 +358,8 @@ namespace llvm {
>>>      void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
>>>      void addMember(DIDescriptor D);
>>>      unsigned getRunTimeLang() const { return getUnsignedField(11); }
>>> -    DICompositeType getContainingType() const {
>>> -      return getFieldAs<DICompositeType>(12);
>>> +    DITypeRef getContainingType() const {
>>> +      return getFieldAs<DITypeRef>(12);
>>>      }
>>>      void setContainingType(DICompositeType ContainingType);
>>>      DIArray getTemplateParams() const { return getFieldAs<DIArray>(13);
>>> }
>>>
>>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=190190&r1=190189&r2=190190&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)
>>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Fri Sep  6
>>> 13:46:00 2013
>>> @@ -1083,7 +1083,7 @@ void CompileUnit::constructTypeDIE(DIE &
>>>      if (CTy.isAppleBlockExtension())
>>>        addFlag(&Buffer, dwarf::DW_AT_APPLE_block);
>>>
>>> -    DICompositeType ContainingType = CTy.getContainingType();
>>> +    DICompositeType
>>> ContainingType(DD->resolve(CTy.getContainingType()));
>>>      if (DIDescriptor(ContainingType).isCompositeType())
>>>        addDIEEntry(&Buffer, dwarf::DW_AT_containing_type,
>>> dwarf::DW_FORM_ref4,
>>>                    getOrCreateTypeDIE(DIType(ContainingType)));
>>>
>>> Modified: llvm/trunk/lib/IR/DIBuilder.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=190190&r1=190189&r2=190190&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/lib/IR/DIBuilder.cpp (original)
>>> +++ llvm/trunk/lib/IR/DIBuilder.cpp Fri Sep  6 13:46:00 2013
>>> @@ -626,7 +626,7 @@ DICompositeType DIBuilder::createClassTy
>>>      DerivedFrom,
>>>      Elements,
>>>      ConstantInt::get(Type::getInt32Ty(VMContext), 0),
>>> -    VTableHolder,
>>> +    DIType(VTableHolder).generateRef(),
>>>
>>
>> Could we make the VTableHolder parameter a DIType so we don't need to
>> cast here (& improve the type-correctness of this function)?
>>
> I will try.
>
>>
>>
>>>      TemplateParams,
>>>      UniqueIdentifier.empty() ? NULL : MDString::get(VMContext,
>>> UniqueIdentifier)
>>>    };
>>> @@ -663,7 +663,7 @@ DICompositeType DIBuilder::createStructT
>>>      DerivedFrom,
>>>      Elements,
>>>      ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
>>> -    VTableHolder,
>>> +    DIType(VTableHolder).generateRef(),
>>>
>>
>> and here.
>>
>>
>>>      NULL,
>>>      UniqueIdentifier.empty() ? NULL : MDString::get(VMContext,
>>> UniqueIdentifier)
>>>    };
>>>
>>> Modified: llvm/trunk/lib/IR/DebugInfo.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=190190&r1=190189&r2=190190&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/lib/IR/DebugInfo.cpp (original)
>>> +++ llvm/trunk/lib/IR/DebugInfo.cpp Fri Sep  6 13:46:00 2013
>>> @@ -497,7 +497,7 @@ bool DICompositeType::Verify() const {
>>>    // Make sure DerivedFrom @ field 9 and ContainingType @ field 12 are
>>> MDNodes.
>>>    if (!fieldIsMDNode(DbgNode, 9))
>>>      return false;
>>> -  if (!fieldIsMDNode(DbgNode, 12))
>>> +  if (!fieldIsTypeRef(DbgNode, 12))
>>>      return false;
>>>
>>>    // Make sure the type identifier at field 14 is MDString, it can be
>>> null.
>>> @@ -721,7 +721,7 @@ DITypeRef DIType::generateRef() {
>>>  /// \brief Set the containing type.
>>>  void DICompositeType::setContainingType(DICompositeType ContainingType)
>>> {
>>>    TrackingVH<MDNode> N(*this);
>>> -  N->replaceOperandWith(12, ContainingType);
>>> +  N->replaceOperandWith(12, ContainingType.generateRef());
>>>    DbgNode = N;
>>>  }
>>>
>>>
>>> Added: llvm/trunk/test/DebugInfo/tu-composite.ll
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/tu-composite.ll?rev=190190&view=auto
>>>
>>> ==============================================================================
>>> --- llvm/trunk/test/DebugInfo/tu-composite.ll (added)
>>> +++ llvm/trunk/test/DebugInfo/tu-composite.ll Fri Sep  6 13:46:00 2013
>>>
>>
>> Did we not have any tests already covering this functionality? or that
>> could be extended to do so? We generally try not to add new test cases if
>> there's a good home to cover the functionality already.
>>
> The problem is that we have testing cases that refer to a DIType via
> MDNode, but we don't have testing cases that refer to a DIType via the
> identifier (MDString).
> Right now, we support both type references.
>
> To verify that MDString works as a type reference, I added these new
> testing cases.
>
> Let me know if we can avoid that.
>

We could beef up the verifier to /require/ that any type referenced that
has an identifier should be referenced with that identifier (& do this on a
per-TypeRef-enabled field, of course - essentially is the "isTypeRef"
check, check if the target has an identifier & in that case fail if it's
not using that identifier as the typeref). Then we'd find all the test
cases that should be exercising this functionality & aren't - update those
to use the identifier & now the're actually covering the real production
codepath rather than a valid, but less useful one.

Short of that, temporarily implement that verifier check, pick a test case
& update at least one to use the new typeref field as test coverage.

I'd ideally like the first case, of course - but appreciate that it might
be painful.

- David


>
> Manman
>
>>
>>
>>> @@ -0,0 +1,64 @@
>>> +; REQUIRES: object-emission
>>> +
>>> +; RUN: llc -filetype=obj -O0 < %s > %t
>>> +; RUN: llvm-dwarfdump -debug-dump=info %t | FileCheck %s
>>> +; CHECK: [[TYPE:.*]]: DW_TAG_structure_type
>>> +; CHECK-NEXT: DW_AT_containing_type [DW_FORM_ref4]       (cu + {{.*}}
>>> => {[[TYPE]]})
>>> +; IR generated from clang -g with the following source:
>>> +; struct C {
>>> +;   virtual void foo();
>>> +; };
>>> +; void C::foo() {
>>> +; }
>>> +
>>> +%struct.C = type { i32 (...)** }
>>> +
>>> + at _ZTV1C = unnamed_addr constant [3 x i8*] [i8* null, i8* bitcast ({
>>> i8*, i8* }* @_ZTI1C to i8*), i8* bitcast (void (%struct.C*)* @_ZN1C3fooEv
>>> to i8*)]
>>> + at _ZTVN10__cxxabiv117__class_type_infoE = external global i8*
>>> + at _ZTS1C = constant [3 x i8] c"1C\00"
>>> + at _ZTI1C = unnamed_addr constant { i8*, i8* } { i8* bitcast (i8**
>>> getelementptr inbounds (i8** @_ZTVN10__cxxabiv117__class_type_infoE, i64 2)
>>> to i8*), i8* getelementptr inbounds ([3 x i8]* @_ZTS1C, i32 0, i32 0) }
>>> +
>>> +; Function Attrs: nounwind ssp uwtable
>>> +define void @_ZN1C3fooEv(%struct.C* %this) unnamed_addr #0 align 2 {
>>> +entry:
>>> +  %this.addr = alloca %struct.C*, align 8
>>> +  store %struct.C* %this, %struct.C** %this.addr, align 8
>>> +  call void @llvm.dbg.declare(metadata !{%struct.C** %this.addr},
>>> metadata !21), !dbg !23
>>> +  %this1 = load %struct.C** %this.addr
>>> +  ret void, !dbg !24
>>> +}
>>> +
>>> +; Function Attrs: nounwind readnone
>>> +declare void @llvm.dbg.declare(metadata, metadata) #1
>>> +
>>> +attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false"
>>> "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
>>> "no-infs-fp-math"="false" "no-nans-fp-math"="false"
>>> "stack-protector-buffer-size"="8" "unsafe-fp-math"="false"
>>> "use-soft-float"="false" }
>>> +attributes #1 = { nounwind readnone }
>>> +
>>> +!llvm.dbg.cu = !{!0}
>>> +!llvm.module.flags = !{!20}
>>> +
>>> +!0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang
>>> version 3.4 (trunk 190115)", i1 false, metadata !"", i32 0, metadata !2,
>>> metadata !3, metadata !18, metadata !2, metadata !2, metadata !""} ; [
>>> DW_TAG_compile_unit ] [tmp.cpp] [DW_LANG_C_plus_plus]
>>> +!1 = metadata !{metadata !"tmp.cpp", metadata !"."}
>>> +!2 = metadata !{i32 0}
>>> +!3 = metadata !{metadata !4}
>>> +!4 = metadata !{i32 786451, metadata !1, null, metadata !"C", i32 1,
>>> i64 64, i64 64, i32 0, i32 0, null, metadata !5, i32 0, metadata !"_ZTS1C",
>>> null, metadata !"_ZTS1C"} ; [ DW_TAG_structure_type ] [C] [line 1, size 64,
>>> align 64, offset 0] [def] [from ]
>>> +!5 = metadata !{metadata !6, metadata !13}
>>> +!6 = metadata !{i32 786445, metadata !1, metadata !7, metadata
>>> !"_vptr$C", i32 0, i64 64, i64 0, i64 0, i32 64, metadata !8} ; [
>>> DW_TAG_member ] [_vptr$C] [line 0, size 64, align 0, offset 0] [artificial]
>>> [from ]
>>> +!7 = metadata !{i32 786473, metadata !1}          ; [ DW_TAG_file_type
>>> ] [tmp.cpp]
>>> +!8 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64,
>>> i64 0, i64 0, i32 0, metadata !9} ; [ DW_TAG_pointer_type ] [line 0, size
>>> 64, align 0, offset 0] [from __vtbl_ptr_type]
>>> +!9 = metadata !{i32 786447, null, null, metadata !"__vtbl_ptr_type",
>>> i32 0, i64 64, i64 0, i64 0, i32 0, metadata !10} ; [ DW_TAG_pointer_type ]
>>> [__vtbl_ptr_type] [line 0, size 64, align 0, offset 0] [from ]
>>> +!10 = metadata !{i32 786453, i32 0, i32 0, metadata !"", i32 0, i64 0,
>>> i64 0, i64 0, i32 0, null, metadata !11, i32 0, null, null, null} ; [
>>> DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
>>> +!11 = metadata !{metadata !12}
>>> +!12 = metadata !{i32 786468, null, null, metadata !"int", i32 0, i64
>>> 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size
>>> 32, align 32, offset 0, enc DW_ATE_signed]
>>> +!13 = metadata !{i32 786478, metadata !1, metadata !4, metadata !"foo",
>>> metadata !"foo", metadata !"_ZN1C3fooEv", i32 2, metadata !14, i1 false, i1
>>> false, i32 1, i32 0, metadata !4, i32 256, i1 false, null, null, i32 0,
>>> metadata !17, i32 2} ; [ DW_TAG_subprogram ] [line 2] [foo]
>>> +!14 = metadata !{i32 786453, i32 0, i32 0, metadata !"", i32 0, i64 0,
>>> i64 0, i64 0, i32 0, null, metadata !15, i32 0, null, null, null} ; [
>>> DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
>>> +!15 = metadata !{null, metadata !16}
>>> +!16 = metadata !{i32 786447, i32 0, i32 0, metadata !"", i32 0, i64 64,
>>> i64 64, i64 0, i32 1088, metadata !4} ; [ DW_TAG_pointer_type ] [line 0,
>>> size 64, align 64, offset 0] [artificial] [from C]
>>> +!17 = metadata !{i32 786468}
>>> +!18 = metadata !{metadata !19}
>>> +!19 = metadata !{i32 786478, metadata !1, null, metadata !"foo",
>>> metadata !"foo", metadata !"_ZN1C3fooEv", i32 4, metadata !14, i1 false, i1
>>> true, i32 0, i32 0, null, i32 256, i1 false, void (%struct.C*)*
>>> @_ZN1C3fooEv, null, metadata !13, metadata !2, i32 4} ; [ DW_TAG_subprogram
>>> ] [line 4] [def] [foo]
>>> +!20 = metadata !{i32 2, metadata !"Dwarf Version", i32 2}
>>> +!21 = metadata !{i32 786689, metadata !19, metadata !"this", null, i32
>>> 16777216, metadata !22, i32 1088, i32 0} ; [ DW_TAG_arg_variable ] [this]
>>> [line 0]
>>> +!22 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64,
>>> i64 64, i64 0, i32 0, metadata !4} ; [ DW_TAG_pointer_type ] [line 0, size
>>> 64, align 64, offset 0] [from C]
>>> +!23 = metadata !{i32 0, i32 0, metadata !19, null}
>>> +!24 = metadata !{i32 5, i32 0, metadata !19, null}
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130906/7169b5d2/attachment.html>


More information about the llvm-commits mailing list