diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -185,9 +185,11 @@ else addGlobalName(GV->getName(), *VariableDIE, DeclContext); - if (uint32_t AlignInBytes = GV->getAlignInBytes()) - addUInt(*VariableDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata, - AlignInBytes); + // For DBX, we generate DWARF 5 attribute at DWARF version no less than 5. + if (!DD->tuneForDBX() || DD->getDwarfVersion() >= 5) + if (uint32_t AlignInBytes = GV->getAlignInBytes()) + addUInt(*VariableDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata, + AlignInBytes); if (MDTuple *TP = GV->getTemplateParams()) addTemplateParams(*VariableDIE, DINodeArray(TP)); @@ -1481,7 +1483,8 @@ if (!Name.empty()) addString(VariableDie, dwarf::DW_AT_name, Name); const auto *DIVar = Var.getVariable(); - if (DIVar) + // For DBX, we generate DWARF 5 attribute at DWARF version no less than 5. + if (DIVar && (!DD->tuneForDBX() || DD->getDwarfVersion() >= 5)) if (uint32_t AlignInBytes = DIVar->getAlignInBytes()) addUInt(VariableDie, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata, AlignInBytes); 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 @@ -991,9 +991,11 @@ RLang); // Add align info if available. - if (uint32_t AlignInBytes = CTy->getAlignInBytes()) - addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata, - AlignInBytes); + // For DBX, we generate DWARF 5 attribute at DWARF version no less than 5. + if (!DD->tuneForDBX() || DD->getDwarfVersion() >= 5) + if (uint32_t AlignInBytes = CTy->getAlignInBytes()) + addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata, + AlignInBytes); } } @@ -1611,7 +1613,8 @@ } else { // This is not a bitfield. OffsetInBytes = DT->getOffsetInBits() / 8; - if (AlignInBytes) + // For DBX, we generate DWARF 5 attribute at DWARF version no less than 5. + if (AlignInBytes && (!DD->tuneForDBX() || DD->getDwarfVersion() >= 5)) addUInt(MemberDie, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata, AlignInBytes); } @@ -1692,9 +1695,11 @@ if (const ConstantFP *CFP = dyn_cast_or_null(DT->getConstant())) addConstantFPValue(StaticMemberDIE, CFP); - if (uint32_t AlignInBytes = DT->getAlignInBytes()) - addUInt(StaticMemberDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata, - AlignInBytes); + // For DBX, we generate DWARF 5 attribute at DWARF version no less than 5. + if (!DD->tuneForDBX() || DD->getDwarfVersion() >= 5) + if (uint32_t AlignInBytes = DT->getAlignInBytes()) + addUInt(StaticMemberDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata, + AlignInBytes); return &StaticMemberDIE; } diff --git a/llvm/test/DebugInfo/PowerPC/align.ll b/llvm/test/DebugInfo/PowerPC/align.ll new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/PowerPC/align.ll @@ -0,0 +1,37 @@ +; RUN: llc -filetype=obj -mtriple=powerpc64le-unknown-linux-gnu < %s | \ +; RUN: llvm-dwarfdump -debug-info - | FileCheck %s +; RUN: llc -filetype=obj -mtriple=powerpc64le-unknown-linux-gnu \ +; RUN: -debugger-tune=dbx < %s | llvm-dwarfdump -debug-info - | \ +; RUN: FileCheck %s --check-prefix=DBX + +; CHECK: DW_AT_alignment +; DBX-NOT: DW_AT_alignment + +@_ZL3var = internal global i32 0, align 16, !dbg !0 + +define dso_local signext i32 @_Z3foov() #0 !dbg !11 { + %1 = load i32, i32* @_ZL3var, align 16, !dbg !15 + ret i32 %1, !dbg !16 +} + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!7, !8, !9} +!llvm.ident = !{!10} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "var", linkageName: "_ZL3var", scope: !2, file: !3, line: 1, type: !6, isLocal: true, isDefinition: true, align: 128) +!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 13.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None) +!3 = !DIFile(filename: "align.cpp", directory: "./") +!4 = !{} +!5 = !{!0} +!6 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned) +!7 = !{i32 7, !"Dwarf Version", i32 4} +!8 = !{i32 2, !"Debug Info Version", i32 3} +!9 = !{i32 1, !"wchar_size", i32 4} +!10 = !{!"clang version 13.0.0"} +!11 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !3, file: !3, line: 3, type: !12, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4) +!12 = !DISubroutineType(types: !13) +!13 = !{!14} +!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!15 = !DILocation(line: 5, column: 18, scope: !11) +!16 = !DILocation(line: 5, column: 11, scope: !11)