Index: lib/CodeGen/AsmPrinter/DwarfUnit.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfUnit.cpp (revision 230313) +++ lib/CodeGen/AsmPrinter/DwarfUnit.cpp (working copy) @@ -1207,12 +1207,20 @@ DIE &NDie = createAndAddDIE(dwarf::DW_TAG_namespace, *ContextDIE, NS); StringRef Name = NS.getName(); - if (!Name.empty()) + bool Anonymous = Name.empty(); + if (!Anonymous) addString(NDie, dwarf::DW_AT_name, NS.getName()); else Name = "(anonymous namespace)"; DD->addAccelNamespace(Name, NDie); addGlobalName(Name, NDie, NS.getContext()); + if (Anonymous) { + // For anonymous namespaces, add a DW_TAG_imported_module tag + // containing an DW_AT_import attribute with the reference to this + // namespace entry. + DIE &IDie = createAndAddDIE(dwarf::DW_TAG_imported_module, *ContextDIE); + addDIEEntry(IDie, dwarf::DW_AT_import, NDie); + } addSourceLine(NDie, NS); return &NDie; } Index: test/DebugInfo/X86/gnu-public-names.ll =================================================================== --- test/DebugInfo/X86/gnu-public-names.ll (revision 230292) +++ test/DebugInfo/X86/gnu-public-names.ll (working copy) @@ -127,6 +127,8 @@ ; in clang. ; CHECK: DW_TAG_imported_module ; CHECK-NOT: {{DW_TAG|NULL}} +; CHECK: DW_TAG_imported_module +; CHECK-NOT: {{DW_TAG|NULL}} ; CHECK: NULL ; CHECK-NOT: {{DW_TAG|NULL}} @@ -147,6 +149,7 @@ ; CHECK: DW_AT_name {{.*}} "i" ; CHECK-NOT: {{DW_TAG|NULL}} ; CHECK: NULL +; CHECK: DW_TAG_imported_module ; CHECK-NOT: {{DW_TAG|NULL}} ; CHECK: [[MEM_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram Index: test/DebugInfo/anonymous-namespace.ll =================================================================== --- test/DebugInfo/anonymous-namespace.ll (revision 0) +++ test/DebugInfo/anonymous-namespace.ll (working copy) @@ -0,0 +1,61 @@ +; RUN: llc -O0 < %s | FileCheck %s +; If the namespace is anonymous, add a DW_TAG_imported_module tag +; containing DW_AT_import attribute with the reference to this namespace +; entry. + +; namespace +; { +; int a = 5; +; } +; +; ModuleID = 'anonymous-namespace.cpp' + +@_ZN12_GLOBAL__N_11aE = internal global i32 5, align 4 + +; Function Attrs: nounwind uwtable +define i32 @_Z3foov() #0 { +entry: + %0 = load i32* @_ZN12_GLOBAL__N_11aE, align 4, !dbg !15 + %add = add nsw i32 %0, 2, !dbg !16 + store i32 %add, i32* @_ZN12_GLOBAL__N_11aE, align 4, !dbg !17 + %1 = load i32* @_ZN12_GLOBAL__N_11aE, align 4, !dbg !18 + ret i32 %1, !dbg !19 +} + +attributes #0 = { nounwind 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" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!12, !13} +!llvm.ident = !{!14} + +!0 = !{!"0x11\004\00clang version 3.7.0 (trunk 230293) (llvm/trunk 230292:230313M)\000\00\000\00\001", !1, !2, !2, !3, !9, !2} ; [ DW_TAG_compile_unit ] [/home/kromanova/anonymous-namespace.cpp] [DW_LANG_C_plus_plus] +!1 = !{!"anonymous-namespace.cpp", !"/home/kromanova"} +!2 = !{} +!3 = !{!4} +!4 = !{!"0x2e\00foo\00foo\00_Z3foov\005\000\001\000\000\00256\000\006", !1, !5, !6, null, i32 ()* @_Z3foov, null, null, !2} ; [ DW_TAG_subprogram ] [line 5] [def] [scope 6] [foo] +!5 = !{!"0x29", !1} ; [ DW_TAG_file_type ] [/home/kromanova/anonymous-namespace.cpp] +!6 = !{!"0x15\00\000\000\000\000\000\000", null, null, null, !7, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ] +!7 = !{!8} +!8 = !{!"0x24\00int\000\0032\0032\000\000\005", null, null} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed] +!9 = !{!10} +!10 = !{!"0x34\00a\00a\00_ZN12_GLOBAL__N_11aE\003\001\001", !11, !5, !8, i32* @_ZN12_GLOBAL__N_11aE, null} ; [ DW_TAG_variable ] [a] [line 3] [local] [def] +!11 = !{!"0x39\00\002", !1, null} ; [ DW_TAG_namespace ] [line 2] +!12 = !{i32 2, !"Dwarf Version", i32 4} +!13 = !{i32 2, !"Debug Info Version", i32 2} +!14 = !{!"clang version 3.7.0 (trunk 230293) (llvm/trunk 230292:230313M)"} +!15 = !MDLocation(line: 7, column: 7, scope: !4) +!16 = !MDLocation(line: 7, column: 8, scope: !4) +!17 = !MDLocation(line: 7, column: 5, scope: !4) +!18 = !MDLocation(line: 8, column: 10, scope: !4) +!19 = !MDLocation(line: 8, column: 3, scope: !4) + +; int foo() +; { +; a = a+2; +; return a; +; } + +;CHECK: DW_TAG_imported_module +;CHECK-NEXT: DW_AT_import + +