diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -3069,12 +3069,14 @@ OS.EmitBinaryData(SRef); OS.AddComment("Name"); - // Get fully qualified name if global is a static data member. - std::string Name = DIGV->getDisplayName(); + // Static data members have global scope, so get the scope from the + // declaration. + const DIScope *Scope = DIGV->getScope(); if (const auto *MemberDecl = dyn_cast_or_null( DIGV->getRawStaticDataMemberDeclaration())) - Name = getFullyQualifiedName(MemberDecl->getScope(), Name); - emitNullTerminatedSymbolName(OS, Name); + Scope = MemberDecl->getScope(); + emitNullTerminatedSymbolName(OS, + getFullyQualifiedName(Scope, DIGV->getName())); endSymbolRecord(SConstantEnd); } } diff --git a/llvm/test/DebugInfo/COFF/global-constants.ll b/llvm/test/DebugInfo/COFF/global-constants.ll --- a/llvm/test/DebugInfo/COFF/global-constants.ll +++ b/llvm/test/DebugInfo/COFF/global-constants.ll @@ -2,7 +2,9 @@ ; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s --check-prefix=OBJ ; C++ source to regenerate: +; namespace Test1 { ; const float TestConst1 = 3.14; +; } ; struct S { ; static const int TestConst2 = -10; ; } @@ -12,7 +14,7 @@ ; }; ; void useConst(int); ; void foo() { -; useConst(TestConst1); +; useConst(Test1::TestConst1); ; useConst(S::TestConst2); ; useConst(ENUM_B); ; } @@ -21,18 +23,18 @@ ; ASM-LABEL: .long 241 # Symbol subsection for globals ; ASM: .short {{.*-.*}} # Record length ; ASM: .short 4359 # Record kind: S_CONSTANT -; ASM-NEXT: .long 4099 # Type +; ASM-NEXT: .long 4102 # Type ; ASM-NEXT: .byte 0x04, 0x80, 0xc3, 0xf5 # Value ; ASM-NEXT: .byte 0x48, 0x40 -; ASM-NEXT: .asciz "TestConst1" # Name +; ASM-NEXT: .asciz "Test1::TestConst1" # Name ; ASM: .short {{.*-.*}} # Record length ; ASM: .short 4359 # Record kind: S_CONSTANT -; ASM-NEXT: .long 4100 # Type +; ASM-NEXT: .long 4103 # Type ; ASM-NEXT: .byte 0x61, 0x00 # Value ; ASM-NEXT: .asciz "S::TestConst2" # Name ; ASM: .short {{.*-.*}} # Record length ; ASM: .short 4359 # Record kind: S_CONSTANT -; ASM-NEXT: .long 4102 # Type +; ASM-NEXT: .long 4105 # Type ; ASM-NEXT: .byte 0x0a, 0x80, 0x40, 0x61 # Value ; ASM-NEXT: .byte 0x07, 0x80, 0xff, 0xff ; ASM-NEXT: .byte 0xff, 0xff @@ -45,77 +47,92 @@ ; OBJ: SubSectionType: Symbols (0xF1) ; OBJ: ConstantSym { ; OBJ-NEXT: Kind: S_CONSTANT (0x1107) -; OBJ-NEXT: Type: const float (0x1003) +; OBJ-NEXT: Type: const float (0x1006) ; OBJ-NEXT: Value: 1078523331 -; OBJ-NEXT: Name: TestConst1 +; OBJ-NEXT: Name: Test1::TestConst1 ; OBJ-NEXT: } ; OBJ-NEXT: ConstantSym { ; OBJ-NEXT: Kind: S_CONSTANT (0x1107) -; OBJ-NEXT: Type: const char (0x1004) +; OBJ-NEXT: Type: const char (0x1007) ; OBJ-NEXT: Value: 97 ; OBJ-NEXT: Name: S::TestConst2 ; OBJ-NEXT: } ; OBJ-NEXT: ConstantSym { ; OBJ-NEXT: Kind: S_CONSTANT (0x1107) -; OBJ-NEXT: Type: TestEnum (0x1006) +; OBJ-NEXT: Type: TestEnum (0x1009) ; OBJ-NEXT: Value: 18446744071562551616 ; OBJ-NEXT: Name: ENUM_B ; OBJ-NEXT: } - ; ModuleID = 't.cpp' source_filename = "t.cpp" target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" -target triple = "x86_64-w64-windows-gnu" +target triple = "x86_64-pc-windows-msvc19.16.27030" -; Function Attrs: noinline nounwind optnone -define dso_local void @_Z3foov() #0 !dbg !28 { +; Function Attrs: noinline nounwind optnone uwtable +define dso_local void @"?useConst@@YAXH@Z"(i32) #0 !dbg !29 { entry: - call void @_Z8useConsti(i32 3), !dbg !32 - call void @_Z8useConsti(i32 97), !dbg !33 - call void @_Z8useConsti(i32 -2147000000), !dbg !34 - ret void, !dbg !35 + %.addr = alloca i32, align 4 + store i32 %0, i32* %.addr, align 4 + call void @llvm.dbg.declare(metadata i32* %.addr, metadata !33, metadata !DIExpression()), !dbg !34 + ret void, !dbg !34 } -declare dso_local void @_Z8useConsti(i32) #1 +; Function Attrs: nounwind readnone speculatable +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local void @"?foo@@YAXXZ"() #0 !dbg !35 { +entry: + call void @"?useConst@@YAXH@Z"(i32 3), !dbg !38 + call void @"?useConst@@YAXH@Z"(i32 97), !dbg !39 + call void @"?useConst@@YAXH@Z"(i32 -2147000000), !dbg !40 + ret void, !dbg !41 +} !llvm.dbg.cu = !{!0} -!llvm.module.flags = !{!24, !25, !26} -!llvm.ident = !{!27} +!llvm.module.flags = !{!24, !25, !26, !27} +!llvm.ident = !{!28} -!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git dee1891507401f396290b5d9cb5717d6b0755337)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !9, globals: !15, nameTableKind: None) -!1 = !DIFile(filename: "", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d700c7d582557a012214ac1f1f8721b") +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git c0edb8f5cf2f19496e44f59dce33d3e5695f5bf6)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !8, globals: !14, nameTableKind: None) +!1 = !DIFile(filename: "t.cpp", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "7e3616d7fc8fe3023b8e01f000fdcf67") !2 = !{!3} -!3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "TestEnum", file: !4, line: 5, baseType: !5, size: 32, elements: !6, identifier: "_ZTS8TestEnum") -!4 = !DIFile(filename: "t.cpp", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d700c7d582557a012214ac1f1f8721b") -!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) -!6 = !{!7, !8} -!7 = !DIEnumerator(name: "ENUM_A", value: 2147000000) -!8 = !DIEnumerator(name: "ENUM_B", value: -2147000000) -!9 = !{!10} -!10 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !4, line: 2, size: 8, flags: DIFlagTypePassByValue, elements: !11, identifier: "_ZTS1S") -!11 = !{!12} -!12 = !DIDerivedType(tag: DW_TAG_member, name: "TestConst2", scope: !10, file: !4, line: 3, baseType: !13, flags: DIFlagStaticMember, extraData: i8 97) -!13 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !14) -!14 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) -!15 = !{!16, !20, !22} -!16 = !DIGlobalVariableExpression(var: !17, expr: !DIExpression(DW_OP_constu, 1078523331, DW_OP_stack_value)) -!17 = distinct !DIGlobalVariable(name: "TestConst1", scope: !0, file: !4, line: 1, type: !18, isLocal: true, isDefinition: true) +!3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "TestEnum", file: !1, line: 7, baseType: !4, size: 32, elements: !5, identifier: ".?AW4TestEnum@@") +!4 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!5 = !{!6, !7} +!6 = !DIEnumerator(name: "ENUM_A", value: 2147000000) +!7 = !DIEnumerator(name: "ENUM_B", value: -2147000000) +!8 = !{!9} +!9 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !1, line: 4, size: 8, flags: DIFlagTypePassByValue, elements: !10, identifier: ".?AUS@@") +!10 = !{!11} +!11 = !DIDerivedType(tag: DW_TAG_member, name: "TestConst2", scope: !9, file: !1, line: 5, baseType: !12, flags: DIFlagStaticMember, extraData: i8 97) +!12 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !13) +!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!14 = !{!15, !20, !22} +!15 = !DIGlobalVariableExpression(var: !16, expr: !DIExpression(DW_OP_constu, 1078523331, DW_OP_stack_value)) +!16 = distinct !DIGlobalVariable(name: "TestConst1", scope: !17, file: !1, line: 2, type: !18, isLocal: true, isDefinition: true) +!17 = !DINamespace(name: "Test1", scope: null) !18 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !19) !19 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float) !20 = !DIGlobalVariableExpression(var: !21, expr: !DIExpression(DW_OP_constu, 97, DW_OP_stack_value)) -!21 = distinct !DIGlobalVariable(name: "TestConst2", scope: !0, file: !4, line: 3, type: !13, isLocal: true, isDefinition: true, declaration: !12) +!21 = distinct !DIGlobalVariable(name: "TestConst2", scope: !0, file: !1, line: 5, type: !12, isLocal: true, isDefinition: true, declaration: !11) !22 = !DIGlobalVariableExpression(var: !23, expr: !DIExpression(DW_OP_constu, 18446744071562551616, DW_OP_stack_value)) -!23 = distinct !DIGlobalVariable(name: "ENUM_B", scope: !0, file: !4, line: 7, type: !3, isLocal: true, isDefinition: true) +!23 = distinct !DIGlobalVariable(name: "ENUM_B", scope: !0, file: !1, line: 9, type: !3, isLocal: true, isDefinition: true) !24 = !{i32 2, !"CodeView", i32 1} !25 = !{i32 2, !"Debug Info Version", i32 3} !26 = !{i32 1, !"wchar_size", i32 2} -!27 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git dee1891507401f396290b5d9cb5717d6b0755337)"} -!28 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !4, file: !4, line: 10, type: !29, scopeLine: 10, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !31) -!29 = !DISubroutineType(types: !30) -!30 = !{null} -!31 = !{} -!32 = !DILocation(line: 11, scope: !28) -!33 = !DILocation(line: 12, scope: !28) -!34 = !DILocation(line: 13, scope: !28) -!35 = !DILocation(line: 14, scope: !28) +!27 = !{i32 7, !"PIC Level", i32 2} +!28 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git c0edb8f5cf2f19496e44f59dce33d3e5695f5bf6)"} +!29 = distinct !DISubprogram(name: "useConst", linkageName: "?useConst@@YAXH@Z", scope: !1, file: !1, line: 11, type: !30, scopeLine: 11, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !32) +!30 = !DISubroutineType(types: !31) +!31 = !{null, !4} +!32 = !{} +!33 = !DILocalVariable(arg: 1, scope: !29, file: !1, line: 11, type: !4) +!34 = !DILocation(line: 11, scope: !29) +!35 = distinct !DISubprogram(name: "foo", linkageName: "?foo@@YAXXZ", scope: !1, file: !1, line: 12, type: !36, scopeLine: 12, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !32) +!36 = !DISubroutineType(types: !37) +!37 = !{null} +!38 = !DILocation(line: 13, scope: !35) +!39 = !DILocation(line: 14, scope: !35) +!40 = !DILocation(line: 15, scope: !35) +!41 = !DILocation(line: 16, scope: !35)