[PATCH] DebugInfo: Allow CastInst instructions to show up around GlobalValues

David Majnemer david.majnemer at gmail.com
Thu Aug 22 17:08:14 PDT 2013


On Thu, Aug 22, 2013 at 4:02 PM, David Blaikie <dblaikie at gmail.com> wrote:

>
> On Aug 22, 2013 3:02 PM, "David Majnemer" <david.majnemer at gmail.com>
> wrote:
> >
> > Hi dblaikie, echristo,
> >
> > We wouldn't emit DW_AT_location for DW_TAG_template_value_parameter if
> > the value the non-type template parameter had was casted.  This happens
> > even if there is no textual cast written.
> >
> > http://llvm-reviews.chandlerc.com/D1478
> >
> > Files:
> >   lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
> >   test/DebugInfo/non-type-template-arg-cast.ll
> >
> > Index: lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
> > ===================================================================
> > --- lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
> > +++ lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
> > @@ -1145,6 +1145,7 @@
> >    if (!VP.getName().empty())
> >      addString(ParamDIE, dwarf::DW_AT_name, VP.getName());
> >    if (Value *Val = VP.getValue()) {
> > +    Val = Val->stripPointerCasts();
>
> Should we strip the casts in the frontend instead? Perhaps there's some
> easy way to get the right/simple thing there?
>
If by the "frontend" you mean CGDebugInfo::CollectTemplateParams, then we
could but I don't know if it would be better. For example, we would need to
fix this for Expression and Declaration.

> >      if (ConstantInt *CI = dyn_cast<ConstantInt>(Val))
> >        addConstantValue(ParamDIE, CI, VP.getType().isUnsignedDIType());
> >      else if (GlobalValue *GV = dyn_cast<GlobalValue>(Val)) {
> > Index: test/DebugInfo/non-type-template-arg-cast.ll
> > ===================================================================
> > --- /dev/null
> > +++ test/DebugInfo/non-type-template-arg-cast.ll
> > @@ -0,0 +1,83 @@
> > +; REQUIRES: object-emission
> > +
> > +; RUN: llc -O0 -filetype=obj < %s > %t
> > +; RUN: llvm-dwarfdump %t | FileCheck %s
> > +
> > +; This was created from the following source:
> > +; struct Type {
> > +;   unsigned int Data1;
> > +;   unsigned short Data2, Data3;
> > +;   unsigned char Data4;
> > +; };
>
> Is this the simplest class that demonstrates the problem?
>
No, I've simplified it a bit.

> > +; template<const Type *G>
> > +; const Type *func() {
> > +;   return G;
> > +; }
> > +
> > +; extern const Type Y;
>
> Do you need the extern declaration?
>
If I don't declare it as extern, I get a warning about using a C++11
extension.  I guess we don't care about it here though. The patch is
updated to reflect this.

> > +; const Type Y = {};
> > +; int main() {
> > +;   func<&Y>();
> > +; }
> > +
> > +; CHECK: DW_TAG_template_value_parameter
> > +; CHECK-NEXT: DW_AT_type
> > +; CHECK-NEXT: DW_AT_name
> > +; CHECK-NEXT: DW_AT_location
> > +; CHECK: NULL
> > +
> > +%struct.Type = type { i32, i16, i16, i8 }
> > +
> > + at Y = constant { i32, i16, i16, i8, [3 x i8] } { i32 0, i16 0, i16 0, i8
> 0, [3 x i8] undef }, align 4
> > +
> > +; Function Attrs: uwtable
> > +define i32 @main() #0 {
> > +entry:
> > +  %call = call %struct.Type* @_Z4funcIXadL_Z1YEEEPK4Typev(), !dbg !28
> > +  ret i32 0, !dbg !29
> > +}
> > +
> > +; Function Attrs: nounwind uwtable
> > +define linkonce_odr %struct.Type* @_Z4funcIXadL_Z1YEEEPK4Typev() #1 {
> > +entry:
> > +  ret %struct.Type* bitcast ({ i32, i16, i16, i8, [3 x i8] }* @Y to
> %struct.Type*), !dbg !30
> > +}
> > +
> > +attributes #0 = { uwtable "less-precise-fpmad"="false"
> "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true"
> "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 uwtable "less-precise-fpmad"="false"
> "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true"
> "no-infs-fp-math"="false" "no-nans-fp-math"="false"
> "stack-protector-buffer-size"="8" "unsafe-fp-math"="false"
> "use-soft-float"="false" }
> > +
> > +!llvm.dbg.cu = !{!0}
> > +!llvm.module.flags = !{!27}
> > +
> > +!0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang
> version 3.4 ", i1 false, metadata !"", i32 0, metadata !2, metadata !2,
> metadata !3, metadata !25, metadata !2, metadata !""} ; [
> DW_TAG_compile_unit ]
> [/usr/local/google/home/majnemer/llvm/build//var/tmp/dlb.cpp]
> [DW_LANG_C_plus_plus]
> > +!1 = metadata !{metadata !"/var/tmp/dlb.cpp", metadata
> !"/usr/local/google/home/majnemer/llvm/build"}
> > +!2 = metadata !{i32 0}
> > +!3 = metadata !{metadata !4, metadata !9}
> > +!4 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"main",
> metadata !"main", metadata !"", i32 14, metadata !6, i1 false, i1 true, i32
> 0, i32 0, null, i32 256, i1 false, i32 ()* @main, null, null, metadata !2,
> i32 14} ; [ DW_TAG_subprogram ] [line 14] [def] [main]
> > +!5 = metadata !{i32 786473, metadata !1}          ; [ DW_TAG_file_type
> ] [/usr/local/google/home/majnemer/llvm/build//var/tmp/dlb.cpp]
> > +!6 = metadata !{i32 786453, i32 0, i32 0, metadata !"", i32 0, i64 0,
> i64 0, i64 0, i32 0, null, metadata !7, i32 0, i32 0} ; [
> DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
> > +!7 = metadata !{metadata !8}
> > +!8 = 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]
> > +!9 = metadata !{i32 786478, metadata !1, metadata !5, metadata
> !"func<&Y>", metadata !"func<&Y>", metadata !"_Z4funcIXadL_Z1YEEEPK4Typev",
> i32 8, metadata !10, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1
> false, %struct.Type* ()* @_Z4funcIXadL_Z1YEEEPK4Typev, metadata !23, null,
> metadata !2, i32 8} ; [ DW_TAG_subprogram ] [line 8] [def] [func<&Y>]
> > +!10 = metadata !{i32 786453, i32 0, i32 0, metadata !"", i32 0, i64 0,
> i64 0, i64 0, i32 0, null, metadata !11, i32 0, i32 0} ; [
> DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
> > +!11 = metadata !{metadata !12}
> > +!12 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64,
> i64 64, i64 0, i32 0, metadata !13} ; [ DW_TAG_pointer_type ] [line 0, size
> 64, align 64, offset 0] [from ]
> > +!13 = metadata !{i32 786470, null, null, metadata !"", i32 0, i64 0,
> i64 0, i64 0, i32 0, metadata !14} ; [ DW_TAG_const_type ] [line 0, size 0,
> align 0, offset 0] [from Type]
> > +!14 = metadata !{i32 786451, metadata !1, null, metadata !"Type", i32
> 1, i64 96, i64 32, i32 0, i32 0, null, metadata !15, i32 0, null, null} ; [
> DW_TAG_structure_type ] [Type] [line 1, size 96, align 32, offset 0] [def]
> [from ]
> > +!15 = metadata !{metadata !16, metadata !18, metadata !20, metadata !21}
> > +!16 = metadata !{i32 786445, metadata !1, metadata !14, metadata
> !"Data1", i32 2, i64 32, i64 32, i64 0, i32 0, metadata !17} ; [
> DW_TAG_member ] [Data1] [line 2, size 32, align 32, offset 0] [from
> unsigned int]
> > +!17 = metadata !{i32 786468, null, null, metadata !"unsigned int", i32
> 0, i64 32, i64 32, i64 0, i32 0, i32 7} ; [ DW_TAG_base_type ] [unsigned
> int] [line 0, size 32, align 32, offset 0, enc DW_ATE_unsigned]
> > +!18 = metadata !{i32 786445, metadata !1, metadata !14, metadata
> !"Data2", i32 3, i64 16, i64 16, i64 32, i32 0, metadata !19} ; [
> DW_TAG_member ] [Data2] [line 3, size 16, align 16, offset 32] [from
> unsigned short]
> > +!19 = metadata !{i32 786468, null, null, metadata !"unsigned short",
> i32 0, i64 16, i64 16, i64 0, i32 0, i32 7} ; [ DW_TAG_base_type ]
> [unsigned short] [line 0, size 16, align 16, offset 0, enc DW_ATE_unsigned]
> > +!20 = metadata !{i32 786445, metadata !1, metadata !14, metadata
> !"Data3", i32 3, i64 16, i64 16, i64 48, i32 0, metadata !19} ; [
> DW_TAG_member ] [Data3] [line 3, size 16, align 16, offset 48] [from
> unsigned short]
> > +!21 = metadata !{i32 786445, metadata !1, metadata !14, metadata
> !"Data4", i32 4, i64 8, i64 8, i64 64, i32 0, metadata !22} ; [
> DW_TAG_member ] [Data4] [line 4, size 8, align 8, offset 64] [from unsigned
> char]
> > +!22 = metadata !{i32 786468, null, null, metadata !"unsigned char", i32
> 0, i64 8, i64 8, i64 0, i32 0, i32 8} ; [ DW_TAG_base_type ] [unsigned
> char] [line 0, size 8, align 8, offset 0, enc DW_ATE_unsigned_char]
> > +!23 = metadata !{metadata !24}
> > +!24 = metadata !{i32 786480, null, metadata !"G", metadata !12,
> %struct.Type* bitcast ({ i32, i16, i16, i8, [3 x i8] }* @Y to
> %struct.Type*), null, i32 0, i32 0} ; [ DW_TAG_template_value_parameter ]
> > +!25 = metadata !{metadata !26}
> > +!26 = metadata !{i32 786484, i32 0, null, metadata !"Y", metadata !"Y",
> metadata !"", metadata !5, i32 13, metadata !13, i32 0, i32 1, { i32, i16,
> i16, i8, [3 x i8] }* @Y, null} ; [ DW_TAG_variable ] [Y] [line 13] [def]
> > +!27 = metadata !{i32 2, metadata !"Dwarf Version", i32 3}
> > +!28 = metadata !{i32 15, i32 0, metadata !4, null}
> > +!29 = metadata !{i32 16, i32 0, metadata !4, null}
> > +!30 = metadata !{i32 9, i32 0, metadata !9, null}
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130822/1b3a7c5a/attachment.html>


More information about the llvm-commits mailing list