Index: lib/CodeGen/AsmPrinter/DwarfUnit.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -1231,6 +1231,14 @@ Name = "(anonymous namespace)"; DD->addAccelNamespace(Name, NDie); addGlobalName(Name, NDie, NS.getContext()); + if (Triple(Asm->getTargetTriple()).isPS4() && !Name.empty()) { + // For anonymous namespaces, add a DW_TAG_imported_module tag + // containing a 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); + addFlag(IDie, dwarf::DW_AT_artificial); + } addSourceLine(NDie, NS); return &NDie; } Index: test/DebugInfo/anonymous-namespace.ll =================================================================== --- test/DebugInfo/anonymous-namespace.ll +++ test/DebugInfo/anonymous-namespace.ll @@ -0,0 +1,36 @@ +; RUN: %llc_dwarf -mtriple=x86_64-scei-ps4 -O0 -filetype=obj %s -o - | llvm-dwarfdump -debug-dump=info - | 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; +; } +; int *b = &a; + +; ModuleID = 'anon.cpp' + +@_ZN12_GLOBAL__N_11aE = internal global i32 5, align 4 +@b = global i32* @_ZN12_GLOBAL__N_11aE, align 8 + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!9, !10} +!llvm.ident = !{!11} + +!0 = !MDCompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.7.0 (trunk 232565)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !2, subprograms: !2, globals: !3, imports: !2) +!1 = !MDFile(filename: "test.cpp", directory: "/home/test/DebugInfo") +!2 = !{} +!3 = !{!4, !7} +!4 = !MDGlobalVariable(name: "b", scope: !0, file: !1, line: 5, type: !5, isLocal: false, isDefinition: true, variable: i32** @b) +!5 = !MDDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, align: 64) +!6 = !MDBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!7 = !MDGlobalVariable(name: "a", linkageName: "_ZN12_GLOBAL__N_11aE", scope: !8, file: !1, line: 3, type: !6, isLocal: true, isDefinition: true, variable: i32* @_ZN12_GLOBAL__N_11aE) +!8 = !MDNamespace(scope: null, file: !1, line: 2) +!9 = !{i32 2, !"Dwarf Version", i32 4} +!10 = !{i32 2, !"Debug Info Version", i32 3} +!11 = !{!"clang version 3.7.0 (trunk 232565)"} + +;CHECK: DW_TAG_imported_module +;CHECK: DW_AT_import +;CHECK-NEXT: DW_AT_artificial