From: David Blaikie Date: Wed, 8 May 2013 06:01:41 +0000 (+0000) Subject: Debug Info: Support DW_TAG_imported_declaration X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=aa76a93cd35abd922b66825bb4e3e0b6e14ccfd5;p=oota-llvm.git Debug Info: Support DW_TAG_imported_declaration This provides basic functionality for imported declarations. For subprograms and types some amount of lazy construction is supported (so the definition of a function can proceed the using declaration), but it still doesn't handle declared-but-not-defined functions (since we don't generally emit function declarations). Variable support is really rudimentary at the moment - simply looking up the existing definition with no support for out of order (declaration, imported_module, then definition). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181392 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 4b2e86a3da5..d8de3ca859d 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -807,8 +807,10 @@ void DwarfDebug::constructImportedEntityDIE(CompileUnit *TheCU, EntityDie = TheCU->getOrCreateNameSpace(DINameSpace(Entity)); else if (Entity.isSubprogram()) EntityDie = TheCU->getOrCreateSubprogramDIE(DISubprogram(Entity)); + else if (Entity.isType()) + EntityDie = TheCU->getOrCreateTypeDIE(DIType(Entity)); else - return; + EntityDie = TheCU->getDIE(Entity); unsigned FileID = getOrCreateSourceID(Module.getContext().getFilename(), Module.getContext().getDirectory(), TheCU->getUniqueID()); diff --git a/test/DebugInfo/namespace.ll b/test/DebugInfo/namespace.ll index 3d2a6110185..7db57638d0c 100644 --- a/test/DebugInfo/namespace.ll +++ b/test/DebugInfo/namespace.ll @@ -13,15 +13,33 @@ ; CHECK-NEXT: DW_AT_decl_file{{.*}}(0x0[[F2:[0-9]]]) ; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x01) ; CHECK-NOT: NULL -; CHECK: DW_TAG_variable +; CHECK: [[I:0x[0-9a-f]*]]:{{ *}}DW_TAG_variable ; CHECK-NEXT: DW_AT_name{{.*}}= "i" +; CHECK-NOT: NULL +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT_MIPS_linkage_name +; CHECK-NEXT: DW_AT_name{{.*}}= "f1" +; CHECK: [[FUNC1:0x[0-9a-f]*]]:{{ *}}DW_TAG_subprogram +; CHECK-NEXT: DW_AT_MIPS_linkage_name +; CHECK-NEXT: DW_AT_name{{.*}}= "f1" +; CHECK: NULL +; CHECK-NOT: NULL +; CHECK: [[FOO:0x[0-9a-f]*]]:{{ *}}DW_TAG_structure_type +; CHECK-NEXT: DW_AT_name{{.*}}= "foo" +; CHECK-NEXT: DW_AT_declaration +; CHECK-NOT: NULL +; CHECK: [[BAR:0x[0-9a-f]*]]:{{ *}}DW_TAG_structure_type +; CHECK-NEXT: DW_AT_name{{.*}}= "bar" +; CHECK: NULL +; CHECK: NULL ; CHECK: NULL + ; CHECK-NOT: NULL ; CHECK: DW_TAG_imported_module ; This is a bug, it should be in F2 but it inherits the file from its ; enclosing scope ; CHECK-NEXT: DW_AT_decl_file{{.*}}(0x0[[F1]]) -; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x04) +; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x08) ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS2]]}) ; CHECK: NULL ; CHECK-NOT: NULL @@ -32,14 +50,34 @@ ; CHECK-NOT: NULL ; CHECK: DW_TAG_imported_module ; CHECK-NEXT: DW_AT_decl_file{{.*}}(0x0[[F2]]) -; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x0e) +; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x12) ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS1]]}) ; CHECK-NOT: NULL +; CHECK: DW_TAG_imported_declaration +; CHECK-NEXT: DW_AT_decl_file{{.*}}(0x0[[F2]]) +; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x13) +; CHECK-NEXT: DW_AT_import{{.*}}=> {[[FOO]]}) +; CHECK-NOT: NULL +; CHECK: DW_TAG_imported_declaration +; CHECK-NEXT: DW_AT_decl_file{{.*}}(0x0[[F2]]) +; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x14) +; CHECK-NEXT: DW_AT_import{{.*}}=> {[[BAR]]}) +; CHECK-NOT: NULL +; CHECK: DW_TAG_imported_declaration +; CHECK-NEXT: DW_AT_decl_file{{.*}}(0x0[[F2]]) +; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x15) +; CHECK-NEXT: DW_AT_import{{.*}}=> {[[FUNC1]]}) +; CHECK-NOT: NULL +; CHECK: DW_TAG_imported_declaration +; CHECK-NEXT: DW_AT_decl_file{{.*}}(0x0[[F2]]) +; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x16) +; CHECK-NEXT: DW_AT_import{{.*}}=> {[[I]]}) +; CHECK-NOT: NULL ; CHECK: DW_TAG_lexical_block ; CHECK-NOT: NULL ; CHECK: DW_TAG_imported_module ; CHECK-NEXT: DW_AT_decl_file{{.*}}(0x0[[F2]]) -; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x0b) +; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x0f) ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS2]]}) ; CHECK: NULL ; CHECK: NULL @@ -48,94 +86,145 @@ ; CHECK: DW_TAG_imported_module ; Same bug as above, this should be F2, not F1 ; CHECK-NEXT: DW_AT_decl_file{{.*}}(0x0[[F1]]) -; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x07) +; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x0b) ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS1]]}) ; CHECK: file_names[ [[F1]]]{{.*}}debug-info-namespace.cpp ; CHECK: file_names[ [[F2]]]{{.*}}foo.cpp ; IR generated from clang/test/CodeGenCXX/debug-info-namespace.cpp, file paths -; changed to protect the guilty. The C++ source code is simply: +; changed to protect the guilty. The C++ source code is: ; namespace A { ; #line 1 "foo.cpp" ; namespace B { ; int i; +; void f1() { } +; void f1(int) { } +; struct foo; +; struct bar { }; ; } ; using namespace B; ; } ; ; using namespace A; -; +; ; int func(bool b) { ; if (b) { ; using namespace A::B; ; return i; ; } ; using namespace A; -; return B::i; +; using B::foo; +; using B::bar; +; using B::f1; +; using B::i; +; bar x; +; return i; ; } +%"struct.A::B::bar" = type { i8 } + @_ZN1A1B1iE = global i32 0, align 4 +; Function Attrs: nounwind uwtable +define void @_ZN1A1B2f1Ev() #0 { +entry: + ret void, !dbg !39 +} + +; Function Attrs: nounwind uwtable +define void @_ZN1A1B2f1Ei(i32) #0 { +entry: + %.addr = alloca i32, align 4 + store i32 %0, i32* %.addr, align 4 + call void @llvm.dbg.declare(metadata !{i32* %.addr}, metadata !40), !dbg !41 + ret void, !dbg !41 +} + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.declare(metadata, metadata) #1 + ; Function Attrs: nounwind uwtable define i32 @_Z4funcb(i1 zeroext %b) #0 { entry: %retval = alloca i32, align 4 %b.addr = alloca i8, align 1 + %x = alloca %"struct.A::B::bar", align 1 %frombool = zext i1 %b to i8 store i8 %frombool, i8* %b.addr, align 1 - call void @llvm.dbg.declare(metadata !{i8* %b.addr}, metadata !21), !dbg !22 - %0 = load i8* %b.addr, align 1, !dbg !23 - %tobool = trunc i8 %0 to i1, !dbg !23 - br i1 %tobool, label %if.then, label %if.end, !dbg !23 + call void @llvm.dbg.declare(metadata !{i8* %b.addr}, metadata !42), !dbg !43 + %0 = load i8* %b.addr, align 1, !dbg !44 + %tobool = trunc i8 %0 to i1, !dbg !44 + br i1 %tobool, label %if.then, label %if.end, !dbg !44 if.then: ; preds = %entry - %1 = load i32* @_ZN1A1B1iE, align 4, !dbg !24 - store i32 %1, i32* %retval, !dbg !24 - br label %return, !dbg !24 + %1 = load i32* @_ZN1A1B1iE, align 4, !dbg !45 + store i32 %1, i32* %retval, !dbg !45 + br label %return, !dbg !45 if.end: ; preds = %entry - %2 = load i32* @_ZN1A1B1iE, align 4, !dbg !25 - store i32 %2, i32* %retval, !dbg !25 - br label %return, !dbg !25 + call void @llvm.dbg.declare(metadata !{%"struct.A::B::bar"* %x}, metadata !46), !dbg !47 + %2 = load i32* @_ZN1A1B1iE, align 4, !dbg !48 + store i32 %2, i32* %retval, !dbg !48 + br label %return, !dbg !48 return: ; preds = %if.end, %if.then - %3 = load i32* %retval, !dbg !26 - ret i32 %3, !dbg !26 + %3 = load i32* %retval, !dbg !49 + ret i32 %3, !dbg !49 } -; Function Attrs: nounwind readnone -declare void @llvm.dbg.declare(metadata, metadata) #1 - attributes #0 = { 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" "unsafe-fp-math"="false" "use-soft-float"="false" } attributes #1 = { nounwind readnone } !llvm.dbg.cu = !{!0} -!0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.3 ", i1 false, metadata !"", i32 0, metadata !2, metadata !2, metadata !3, metadata !11, metadata !15, metadata !""} ; [ DW_TAG_compile_unit ] [/usr/local/google/home/blaikie/dev/llvm/src/tools/clang//usr/local/google/home/blaikie/dev/llvm/src/tools/clang/test/CodeGenCXX/debug-info-namespace.cpp] [DW_LANG_C_plus_plus] -!1 = metadata !{metadata !"/usr/local/google/home/blaikie/dev/llvm/src/tools/clang/test/CodeGenCXX/debug-info-namespace.cpp", metadata !"/usr/local/google/home/blaikie/dev/llvm/src/tools/clang"} +!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 !19, metadata !21, metadata !""} ; [ DW_TAG_compile_unit ] [/usr/local/google/home/blaikie/dev/llvm/build/clang/debug//usr/local/google/home/blaikie/dev/llvm/src/tools/clang/test/CodeGenCXX/debug-info-namespace.cpp] [DW_LANG_C_plus_plus] +!1 = metadata !{metadata !"/usr/local/google/home/blaikie/dev/llvm/src/tools/clang/test/CodeGenCXX/debug-info-namespace.cpp", metadata !"/usr/local/google/home/blaikie/dev/llvm/build/clang/debug"} !2 = metadata !{i32 0} -!3 = metadata !{metadata !4} -!4 = metadata !{i32 786478, metadata !5, metadata !6, metadata !"func", metadata !"func", metadata !"_Z4funcb", i32 9, metadata !7, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 (i1)* @_Z4funcb, null, null, metadata !2, i32 9} ; [ DW_TAG_subprogram ] [line 9] [def] [func] -!5 = metadata !{metadata !"foo.cpp", metadata !"/usr/local/google/home/blaikie/dev/llvm/src/tools/clang"} -!6 = metadata !{i32 786473, metadata !5} ; [ DW_TAG_file_type ] [/usr/local/google/home/blaikie/dev/llvm/build/clang/debug/foo.cpp] -!7 = metadata !{i32 786453, i32 0, i32 0, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !8, i32 0, i32 0} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ] -!8 = metadata !{metadata !9, metadata !10} -!9 = 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] -!10 = metadata !{i32 786468, null, null, metadata !"bool", i32 0, i64 8, i64 8, i64 0, i32 0, i32 2} ; [ DW_TAG_base_type ] [bool] [line 0, size 8, align 8, offset 0, enc DW_ATE_boolean] -!11 = metadata !{metadata !12} -!12 = metadata !{i32 786484, i32 0, metadata !13, metadata !"i", metadata !"i", metadata !"_ZN1A1B1iE", metadata !6, i32 2, metadata !9, i32 0, i32 1, i32* @_ZN1A1B1iE, null} ; [ DW_TAG_variable ] [i] [line 2] [def] -!13 = metadata !{i32 786489, metadata !5, metadata !14, metadata !"B", i32 1} ; [ DW_TAG_namespace ] [B] [line 1] -!14 = metadata !{i32 786489, metadata !1, null, metadata !"A", i32 3} ; [ DW_TAG_namespace ] [A] [line 3] -!15 = metadata !{metadata !16, metadata !17, metadata !18, metadata !20} -!16 = metadata !{i32 786490, metadata !14, metadata !13, i32 4} ; [ DW_TAG_imported_module ] -!17 = metadata !{i32 786490, metadata !0, metadata !14, i32 7} ; [ DW_TAG_imported_module ] -!18 = metadata !{i32 786490, metadata !19, metadata !13, i32 11} ; [ DW_TAG_imported_module ] -!19 = metadata !{i32 786443, metadata !5, metadata !4, i32 10, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [/usr/local/google/home/blaikie/dev/llvm/build/clang/debug/foo.cpp] -!20 = metadata !{i32 786490, metadata !4, metadata !14, i32 14} ; [ DW_TAG_imported_module ] -!21 = metadata !{i32 786689, metadata !4, metadata !"b", metadata !6, i32 16777225, metadata !10, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [b] [line 9] -!22 = metadata !{i32 9, i32 0, metadata !4, null} -!23 = metadata !{i32 10, i32 0, metadata !4, null} -!24 = metadata !{i32 12, i32 0, metadata !19, null} -!25 = metadata !{i32 15, i32 0, metadata !4, null} -!26 = metadata !{i32 16, i32 0, metadata !4, null} +!3 = metadata !{metadata !4, metadata !10, metadata !14} +!4 = metadata !{i32 786478, metadata !5, metadata !6, metadata !"f1", metadata !"f1", metadata !"_ZN1A1B2f1Ev", i32 3, metadata !8, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, void ()* @_ZN1A1B2f1Ev, null, null, metadata !2, i32 3} ; [ DW_TAG_subprogram ] [line 3] [def] [f1] +!5 = metadata !{metadata !"foo.cpp", metadata !"/usr/local/google/home/blaikie/dev/llvm/build/clang/debug"} +!6 = metadata !{i32 786489, metadata !5, metadata !7, metadata !"B", i32 1} ; [ DW_TAG_namespace ] [B] [line 1] +!7 = metadata !{i32 786489, metadata !1, null, metadata !"A", i32 3} ; [ DW_TAG_namespace ] [A] [line 3] +!8 = metadata !{i32 786453, i32 0, i32 0, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !9, i32 0, i32 0} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ] +!9 = metadata !{null} +!10 = metadata !{i32 786478, metadata !5, metadata !6, metadata !"f1", metadata !"f1", metadata !"_ZN1A1B2f1Ei", i32 4, metadata !11, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, void (i32)* @_ZN1A1B2f1Ei, null, null, metadata !2, i32 4} ; [ DW_TAG_subprogram ] [line 4] [def] [f1] +!11 = metadata !{i32 786453, i32 0, i32 0, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !12, i32 0, i32 0} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ] +!12 = metadata !{null, metadata !13} +!13 = 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] +!14 = metadata !{i32 786478, metadata !5, metadata !15, metadata !"func", metadata !"func", metadata !"_Z4funcb", i32 13, metadata !16, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 (i1)* @_Z4funcb, null, null, metadata !2, i32 13} ; [ DW_TAG_subprogram ] [line 13] [def] [func] +!15 = metadata !{i32 786473, metadata !5} ; [ DW_TAG_file_type ] [/usr/local/google/home/blaikie/dev/llvm/build/clang/debug/foo.cpp] +!16 = metadata !{i32 786453, i32 0, i32 0, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !17, i32 0, i32 0} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ] +!17 = metadata !{metadata !13, metadata !18} +!18 = metadata !{i32 786468, null, null, metadata !"bool", i32 0, i64 8, i64 8, i64 0, i32 0, i32 2} ; [ DW_TAG_base_type ] [bool] [line 0, size 8, align 8, offset 0, enc DW_ATE_boolean] +!19 = metadata !{metadata !20} +!20 = metadata !{i32 786484, i32 0, metadata !6, metadata !"i", metadata !"i", metadata !"_ZN1A1B1iE", metadata !15, i32 2, metadata !13, i32 0, i32 1, i32* @_ZN1A1B1iE, null} ; [ DW_TAG_variable ] [i] [line 2] [def] +!21 = metadata !{metadata !22, metadata !23, metadata !24, metadata !26, metadata !27, metadata !29, metadata !37, metadata !38} +!22 = metadata !{i32 786490, metadata !7, metadata !6, i32 8} ; [ DW_TAG_imported_module ] +!23 = metadata !{i32 786490, metadata !0, metadata !7, i32 11} ; [ DW_TAG_imported_module ] +!24 = metadata !{i32 786490, metadata !25, metadata !6, i32 15} ; [ DW_TAG_imported_module ] +!25 = metadata !{i32 786443, metadata !5, metadata !14, i32 14, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [/usr/local/google/home/blaikie/dev/llvm/build/clang/debug/foo.cpp] +!26 = metadata !{i32 786490, metadata !14, metadata !7, i32 18} ; [ DW_TAG_imported_module ] +!27 = metadata !{i32 786440, metadata !14, metadata !28, i32 19} ; [ DW_TAG_imported_declaration ] +!28 = metadata !{i32 786451, metadata !5, metadata !6, metadata !"foo", i32 5, i64 0, i64 0, i32 0, i32 4, null, null, i32 0} ; [ DW_TAG_structure_type ] [foo] [line 5, size 0, align 0, offset 0] [fwd] [from ] +!29 = metadata !{i32 786440, metadata !14, metadata !30, i32 20} ; [ DW_TAG_imported_declaration ] +!30 = metadata !{i32 786451, metadata !5, metadata !6, metadata !"bar", i32 6, i64 8, i64 8, i32 0, i32 0, null, metadata !31, i32 0, null, null} ; [ DW_TAG_structure_type ] [bar] [line 6, size 8, align 8, offset 0] [from ] +!31 = metadata !{metadata !32} +!32 = metadata !{i32 786478, metadata !5, metadata !30, metadata !"bar", metadata !"bar", metadata !"", i32 6, metadata !33, i1 false, i1 false, i32 0, i32 0, null, i32 320, i1 false, null, null, i32 0, metadata !36, i32 6} ; [ DW_TAG_subprogram ] [line 6] [bar] +!33 = metadata !{i32 786453, i32 0, i32 0, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !34, i32 0, i32 0} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ] +!34 = metadata !{null, metadata !35} +!35 = metadata !{i32 786447, i32 0, i32 0, metadata !"", i32 0, i64 64, i64 64, i64 0, i32 1088, metadata !30} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [artificial] [from bar] +!36 = metadata !{i32 786468} +!37 = metadata !{i32 786440, metadata !14, metadata !10, i32 21} ; [ DW_TAG_imported_declaration ] +!38 = metadata !{i32 786440, metadata !14, metadata !20, i32 22} ; [ DW_TAG_imported_declaration ] +!39 = metadata !{i32 3, i32 0, metadata !4, null} +!40 = metadata !{i32 786689, metadata !10, metadata !"", metadata !15, i32 16777220, metadata !13, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [line 4] +!41 = metadata !{i32 4, i32 0, metadata !10, null} +!42 = metadata !{i32 786689, metadata !14, metadata !"b", metadata !15, i32 16777229, metadata !18, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [b] [line 13] +!43 = metadata !{i32 13, i32 0, metadata !14, null} +!44 = metadata !{i32 14, i32 0, metadata !14, null} +!45 = metadata !{i32 16, i32 0, metadata !25, null} +!46 = metadata !{i32 786688, metadata !14, metadata !"x", metadata !15, i32 23, metadata !30, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [x] [line 23] +!47 = metadata !{i32 23, i32 0, metadata !14, null} +!48 = metadata !{i32 24, i32 0, metadata !14, null} +!49 = metadata !{i32 25, i32 0, metadata !14, null}