diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -930,7 +930,7 @@ if (CTy->isAppleBlockExtension()) addFlag(Buffer, dwarf::DW_AT_APPLE_block); - if (CTy->getExportSymbols()) + if (CTy->getExportSymbols() && DD->getDwarfVersion() >= 5) addFlag(Buffer, dwarf::DW_AT_export_symbols); // This is outside the DWARF spec, but GDB expects a DW_AT_containing_type @@ -1064,7 +1064,7 @@ Name = "(anonymous namespace)"; DD->addAccelNamespace(*CUNode, Name, NDie); addGlobalName(Name, NDie, NS->getScope()); - if (NS->getExportSymbols()) + if (NS->getExportSymbols() && DD->getDwarfVersion() >= 5) addFlag(NDie, dwarf::DW_AT_export_symbols); return &NDie; } diff --git a/llvm/test/DebugInfo/Generic/export-symbol-anonymous-class.ll b/llvm/test/DebugInfo/Generic/export-symbol-anonymous-class.ll --- a/llvm/test/DebugInfo/Generic/export-symbol-anonymous-class.ll +++ b/llvm/test/DebugInfo/Generic/export-symbol-anonymous-class.ll @@ -38,6 +38,6 @@ !10 = !{!11} !11 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !9, file: !3, line: 3, baseType: !12, size: 32) !12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) -!14 = !{i32 2, !"Dwarf Version", i32 4} +!14 = !{i32 2, !"Dwarf Version", i32 5} !15 = !{i32 2, !"Debug Info Version", i32 3} !16 = !{!"clang version 10.0.0"}