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 @@ -790,6 +790,9 @@ if (Tag == dwarf::DW_TAG_ptr_to_member_type) addDIEEntry(Buffer, dwarf::DW_AT_containing_type, *getOrCreateTypeDIE(cast(DTy)->getClassType())); + + addAccess(Buffer, DTy->getFlags()); + // Add source line info if available and TyDesc is not a forward declaration. if (!DTy->isForwardDecl()) addSourceLine(Buffer, DTy); diff --git a/llvm/test/DebugInfo/X86/debug-info-access.ll b/llvm/test/DebugInfo/X86/debug-info-access.ll --- a/llvm/test/DebugInfo/X86/debug-info-access.ll +++ b/llvm/test/DebugInfo/X86/debug-info-access.ll @@ -15,8 +15,14 @@ ; public: ; void pub(); ; static int public_static; +; ; protected: +; typedef int prot_typedef; +; using prot_using = prot_typedef; +; prot_using prot_member; +; ; void prot(); +; ; private: ; void priv_default(); ; }; @@ -28,9 +34,13 @@ ; protected: ; union E { ; }; +; private: +; struct J { +; }; ; public: ; D d; ; E e; +; J j; ; }; ; ; struct F { @@ -57,9 +67,9 @@ ; ; void free() {} ; +; U u; ; A a; ; B b; -; U u; ; C c; ; F f; ; H h; @@ -92,6 +102,14 @@ ; CHECK-NOT: DW_TAG ; CHECK: DW_AT_accessibility {{.*}}(DW_ACCESS_public) +; CHECK: DW_TAG_member +; CHECK: DW_AT_name {{.*}}"prot_member") + +; CHECK: DW_TAG_typedef +; CHECK: DW_AT_name {{.*}}"prot_using") +; CHECK-NOT: DW_TAG +; CHECK: DW_AT_accessibility {{.*}}(DW_ACCESS_protected) + ; CHECK: DW_TAG_subprogram ; CHECK: DW_AT_name {{.*}}"pub") ; CHECK-NOT: DW_TAG @@ -130,42 +148,43 @@ %union.U = type { i32 } %struct.A = type { i8 } -%class.B = type { i8 } -%class.C = type { %"struct.C::D", %"union.C::E" } +%class.B = type { i32 } +%class.C = type { %"struct.C::D", %"union.C::E", %"struct.C::J" } %"struct.C::D" = type { i8 } %"union.C::E" = type { i8 } +%"struct.C::J" = type { i8 } %struct.F = type { %"union.F::G" } %"union.F::G" = type { i8 } %union.H = type { %"class.H::I" } %"class.H::I" = type { i8 } -@u = global %union.U zeroinitializer, align 4, !dbg !0 -@a = global %struct.A zeroinitializer, align 1, !dbg !5 -@b = global %class.B zeroinitializer, align 1, !dbg !16 -@c = global %class.C zeroinitializer, align 1, !dbg !28 -@f = global %struct.F zeroinitializer, align 1, !dbg !37 -@h = global %union.H zeroinitializer, align 1, !dbg !43 +@u = dso_local global %union.U zeroinitializer, align 4, !dbg !0 +@a = dso_local global %struct.A zeroinitializer, align 1, !dbg !5 +@b = dso_local global %class.B zeroinitializer, align 4, !dbg !16 +@c = dso_local global %class.C zeroinitializer, align 1, !dbg !31 +@f = dso_local global %struct.F zeroinitializer, align 1, !dbg !42 +@h = dso_local global %union.H zeroinitializer, align 1, !dbg !48 -; Function Attrs: mustprogress noinline nounwind optnone -define dso_local void @_Z4freev() #0 !dbg !59 { +; Function Attrs: mustprogress noinline nounwind optnone uwtable +define dso_local void @_Z4freev() #0 !dbg !69 { entry: - ret void, !dbg !62 + ret void, !dbg !72 } -attributes #0 = { mustprogress noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" } +attributes #0 = { mustprogress noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } !llvm.dbg.cu = !{!2} -!llvm.module.flags = !{!56, !57} -!llvm.ident = !{!58} +!llvm.module.flags = !{!61, !62, !63, !64, !65, !66, !67} +!llvm.ident = !{!68} !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) -!1 = distinct !DIGlobalVariable(name: "u", scope: !2, file: !7, line: 73, type: !49, isLocal: false, isDefinition: true) -!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 14.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None) -!3 = !DIFile(filename: "clang/test/CodeGenCXX/", directory: "") -!4 = !{!0, !5, !16, !28, !37, !43} +!1 = distinct !DIGlobalVariable(name: "u", scope: !2, file: !7, line: 86, type: !54, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 16.0.0 (https://github.com/llvm/llvm-project.git 113a643a597b6a8f68099fedbeb7509449d4bd50)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None) +!3 = !DIFile(filename: "/home/jon/sources/llvm-project/clang/test/CodeGenCXX/debug-info-access.cpp", directory: "/home/jon/sources/llvm-project/build/testing", checksumkind: CSK_MD5, checksum: "98644ed3fc3955a9b5fefee27d5c16ef") +!4 = !{!0, !5, !16, !31, !42, !48} !5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression()) -!6 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !7, line: 74, type: !8, isLocal: false, isDefinition: true) -!7 = !DIFile(filename: "clang/test/CodeGenCXX/debug-info-access.cpp", directory: "") +!6 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !7, line: 87, type: !8, isLocal: false, isDefinition: true) +!7 = !DIFile(filename: "clang/test/CodeGenCXX/debug-info-access.cpp", directory: "/home/jon/sources/llvm-project", checksumkind: CSK_MD5, checksum: "98644ed3fc3955a9b5fefee27d5c16ef") !8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "A", file: !7, line: 3, size: 8, flags: DIFlagTypePassByValue, elements: !9, identifier: "_ZTS1A") !9 = !{!10, !12} !10 = !DIDerivedType(tag: DW_TAG_member, name: "pub_default_static", scope: !8, file: !7, line: 9, baseType: !11, flags: DIFlagStaticMember) @@ -175,49 +194,59 @@ !14 = !{null, !15} !15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) !16 = !DIGlobalVariableExpression(var: !17, expr: !DIExpression()) -!17 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !7, line: 75, type: !18, isLocal: false, isDefinition: true) -!18 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "B", file: !7, line: 14, size: 8, flags: DIFlagTypePassByValue, elements: !19, identifier: "_ZTS1B") -!19 = !{!20, !21, !22, !26, !27} +!17 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !7, line: 88, type: !18, isLocal: false, isDefinition: true) +!18 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "B", file: !7, line: 13, size: 32, flags: DIFlagTypePassByValue, elements: !19, identifier: "_ZTS1B") +!19 = !{!20, !21, !22, !25, !29, !30} !20 = !DIDerivedType(tag: DW_TAG_inheritance, scope: !18, baseType: !8, flags: DIFlagPublic, extraData: i32 0) -!21 = !DIDerivedType(tag: DW_TAG_member, name: "public_static", scope: !18, file: !7, line: 19, baseType: !11, flags: DIFlagPublic | DIFlagStaticMember) -!22 = !DISubprogram(name: "pub", linkageName: "_ZN1B3pubEv", scope: !18, file: !7, line: 17, type: !23, scopeLine: 17, flags: DIFlagPublic | DIFlagPrototyped, spFlags: 0) -!23 = !DISubroutineType(types: !24) -!24 = !{null, !25} -!25 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !18, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) -!26 = !DISubprogram(name: "prot", linkageName: "_ZN1B4protEv", scope: !18, file: !7, line: 22, type: !23, scopeLine: 22, flags: DIFlagProtected | DIFlagPrototyped, spFlags: 0) -!27 = !DISubprogram(name: "priv_default", linkageName: "_ZN1B12priv_defaultEv", scope: !18, file: !7, line: 25, type: !23, scopeLine: 25, flags: DIFlagPrototyped, spFlags: 0) -!28 = !DIGlobalVariableExpression(var: !29, expr: !DIExpression()) -!29 = distinct !DIGlobalVariable(name: "c", scope: !2, file: !7, line: 76, type: !30, isLocal: false, isDefinition: true) -!30 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "C", file: !7, line: 28, size: 16, flags: DIFlagTypePassByValue, elements: !31, identifier: "_ZTS1C") -!31 = !{!32, !35} -!32 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !30, file: !7, line: 38, baseType: !33, size: 8, flags: DIFlagPublic) -!33 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "D", scope: !30, file: !7, line: 31, size: 8, flags: DIFlagPublic | DIFlagTypePassByValue, elements: !34, identifier: "_ZTSN1C1DE") -!34 = !{} -!35 = !DIDerivedType(tag: DW_TAG_member, name: "e", scope: !30, file: !7, line: 39, baseType: !36, size: 8, offset: 8, flags: DIFlagPublic) -!36 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "E", scope: !30, file: !7, line: 35, size: 8, flags: DIFlagProtected | DIFlagTypePassByValue, elements: !34, identifier: "_ZTSN1C1EE") -!37 = !DIGlobalVariableExpression(var: !38, expr: !DIExpression()) -!38 = distinct !DIGlobalVariable(name: "f", scope: !2, file: !7, line: 77, type: !39, isLocal: false, isDefinition: true) -!39 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "F", file: !7, line: 42, size: 8, flags: DIFlagTypePassByValue, elements: !40, identifier: "_ZTS1F") -!40 = !{!41} -!41 = !DIDerivedType(tag: DW_TAG_member, name: "g", scope: !39, file: !7, line: 48, baseType: !42, size: 8) -!42 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "G", scope: !39, file: !7, line: 45, size: 8, flags: DIFlagPrivate | DIFlagTypePassByValue, elements: !34, identifier: "_ZTSN1F1GE") -!43 = !DIGlobalVariableExpression(var: !44, expr: !DIExpression()) -!44 = distinct !DIGlobalVariable(name: "h", scope: !2, file: !7, line: 78, type: !45, isLocal: false, isDefinition: true) -!45 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "H", file: !7, line: 51, size: 8, flags: DIFlagTypePassByValue, elements: !46, identifier: "_ZTS1H") -!46 = !{!47} -!47 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !45, file: !7, line: 57, baseType: !48, size: 8) -!48 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "I", scope: !45, file: !7, line: 54, size: 8, flags: DIFlagPrivate | DIFlagTypePassByValue, elements: !34, identifier: "_ZTSN1H1IE") -!49 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "U", file: !7, line: 60, size: 32, flags: DIFlagTypePassByValue, elements: !50, identifier: "_ZTS1U") -!50 = !{!51, !52} -!51 = !DIDerivedType(tag: DW_TAG_member, name: "union_priv", scope: !49, file: !7, line: 65, baseType: !11, size: 32, flags: DIFlagPrivate) -!52 = !DISubprogram(name: "union_pub_default", linkageName: "_ZN1U17union_pub_defaultEv", scope: !49, file: !7, line: 62, type: !53, scopeLine: 62, flags: DIFlagPrototyped, spFlags: 0) -!53 = !DISubroutineType(types: !54) -!54 = !{null, !55} -!55 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !49, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) -!56 = !{i32 2, !"Debug Info Version", i32 3} -!57 = !{i32 1, !"wchar_size", i32 4} -!58 = !{!"clang version 14.0.0"} -!59 = distinct !DISubprogram(name: "free", linkageName: "_Z4freev", scope: !7, file: !7, line: 71, type: !60, scopeLine: 71, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !34) -!60 = !DISubroutineType(types: !61) -!61 = !{null} -!62 = !DILocation(line: 71, column: 14, scope: !59) +!21 = !DIDerivedType(tag: DW_TAG_member, name: "public_static", scope: !18, file: !7, line: 18, baseType: !11, flags: DIFlagPublic | DIFlagStaticMember) +!22 = !DIDerivedType(tag: DW_TAG_member, name: "prot_member", scope: !18, file: !7, line: 25, baseType: !23, size: 32, flags: DIFlagProtected) +!23 = !DIDerivedType(tag: DW_TAG_typedef, name: "prot_using", scope: !18, file: !7, line: 24, baseType: !24, flags: DIFlagProtected) +!24 = !DIDerivedType(tag: DW_TAG_typedef, name: "prot_typedef", scope: !18, file: !7, line: 22, baseType: !11, flags: DIFlagProtected) +!25 = !DISubprogram(name: "pub", linkageName: "_ZN1B3pubEv", scope: !18, file: !7, line: 16, type: !26, scopeLine: 16, flags: DIFlagPublic | DIFlagPrototyped, spFlags: 0) +!26 = !DISubroutineType(types: !27) +!27 = !{null, !28} +!28 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !18, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!29 = !DISubprogram(name: "prot", linkageName: "_ZN1B4protEv", scope: !18, file: !7, line: 29, type: !26, scopeLine: 29, flags: DIFlagProtected | DIFlagPrototyped, spFlags: 0) +!30 = !DISubprogram(name: "priv_default", linkageName: "_ZN1B12priv_defaultEv", scope: !18, file: !7, line: 33, type: !26, scopeLine: 33, flags: DIFlagPrototyped, spFlags: 0) +!31 = !DIGlobalVariableExpression(var: !32, expr: !DIExpression()) +!32 = distinct !DIGlobalVariable(name: "c", scope: !2, file: !7, line: 89, type: !33, isLocal: false, isDefinition: true) +!33 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "C", file: !7, line: 36, size: 24, flags: DIFlagTypePassByValue, elements: !34, identifier: "_ZTS1C") +!34 = !{!35, !38, !40} +!35 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !33, file: !7, line: 50, baseType: !36, size: 8, flags: DIFlagPublic) +!36 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "D", scope: !33, file: !7, line: 39, size: 8, flags: DIFlagPublic | DIFlagTypePassByValue, elements: !37, identifier: "_ZTSN1C1DE") +!37 = !{} +!38 = !DIDerivedType(tag: DW_TAG_member, name: "e", scope: !33, file: !7, line: 51, baseType: !39, size: 8, offset: 8, flags: DIFlagPublic) +!39 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "E", scope: !33, file: !7, line: 43, size: 8, flags: DIFlagProtected | DIFlagTypePassByValue, elements: !37, identifier: "_ZTSN1C1EE") +!40 = !DIDerivedType(tag: DW_TAG_member, name: "j", scope: !33, file: !7, line: 52, baseType: !41, size: 8, offset: 16, flags: DIFlagPublic) +!41 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "J", scope: !33, file: !7, line: 47, size: 8, flags: DIFlagTypePassByValue, elements: !37, identifier: "_ZTSN1C1JE") +!42 = !DIGlobalVariableExpression(var: !43, expr: !DIExpression()) +!43 = distinct !DIGlobalVariable(name: "f", scope: !2, file: !7, line: 90, type: !44, isLocal: false, isDefinition: true) +!44 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "F", file: !7, line: 55, size: 8, flags: DIFlagTypePassByValue, elements: !45, identifier: "_ZTS1F") +!45 = !{!46} +!46 = !DIDerivedType(tag: DW_TAG_member, name: "g", scope: !44, file: !7, line: 61, baseType: !47, size: 8) +!47 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "G", scope: !44, file: !7, line: 58, size: 8, flags: DIFlagPrivate | DIFlagTypePassByValue, elements: !37, identifier: "_ZTSN1F1GE") +!48 = !DIGlobalVariableExpression(var: !49, expr: !DIExpression()) +!49 = distinct !DIGlobalVariable(name: "h", scope: !2, file: !7, line: 91, type: !50, isLocal: false, isDefinition: true) +!50 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "H", file: !7, line: 64, size: 8, flags: DIFlagTypePassByValue, elements: !51, identifier: "_ZTS1H") +!51 = !{!52} +!52 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !50, file: !7, line: 70, baseType: !53, size: 8) +!53 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "I", scope: !50, file: !7, line: 67, size: 8, flags: DIFlagPrivate | DIFlagTypePassByValue, elements: !37, identifier: "_ZTSN1H1IE") +!54 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "U", file: !7, line: 73, size: 32, flags: DIFlagTypePassByValue, elements: !55, identifier: "_ZTS1U") +!55 = !{!56, !57} +!56 = !DIDerivedType(tag: DW_TAG_member, name: "union_priv", scope: !54, file: !7, line: 78, baseType: !11, size: 32, flags: DIFlagPrivate) +!57 = !DISubprogram(name: "union_pub_default", linkageName: "_ZN1U17union_pub_defaultEv", scope: !54, file: !7, line: 75, type: !58, scopeLine: 75, flags: DIFlagPrototyped, spFlags: 0) +!58 = !DISubroutineType(types: !59) +!59 = !{null, !60} +!60 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !54, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!61 = !{i32 7, !"Dwarf Version", i32 5} +!62 = !{i32 2, !"Debug Info Version", i32 3} +!63 = !{i32 1, !"wchar_size", i32 4} +!64 = !{i32 8, !"PIC Level", i32 2} +!65 = !{i32 7, !"PIE Level", i32 2} +!66 = !{i32 7, !"uwtable", i32 2} +!67 = !{i32 7, !"frame-pointer", i32 2} +!68 = !{!"clang version 16.0.0 (https://github.com/llvm/llvm-project.git 113a643a597b6a8f68099fedbeb7509449d4bd50)"} +!69 = distinct !DISubprogram(name: "free", linkageName: "_Z4freev", scope: !7, file: !7, line: 84, type: !70, scopeLine: 84, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !37) +!70 = !DISubroutineType(types: !71) +!71 = !{null} +!72 = !DILocation(line: 84, column: 14, scope: !69)