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 @@ -386,6 +386,18 @@ } DIE &DwarfUnit::createAndAddDIE(dwarf::Tag Tag, DIE &Parent, const DINode *N) { + // For strict DWARF mode, only generate tags available to current DWARF + // version. + if (Asm->TM.Options.DebugStrictDwarf && + DD->getDwarfVersion() < dwarf::TagVersion(Tag)) { + // See if there is any replacement for some tags. + if (Tag == dwarf::DW_TAG_rvalue_reference_type && + DD->getDwarfVersion() >= 3) + Tag = dwarf::DW_TAG_reference_type; + else + // Assertion for other cases. + assert(false && "Tag is generated not following strict DWARF!"); + } DIE &Die = Parent.addChild(DIE::get(DIEValueAllocator, Tag)); if (N) insertDIE(N, &Die); diff --git a/llvm/test/DebugInfo/PowerPC/strict-dwarf-tags.ll b/llvm/test/DebugInfo/PowerPC/strict-dwarf-tags.ll new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/PowerPC/strict-dwarf-tags.ll @@ -0,0 +1,43 @@ +; 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: -strict-dwarf=true < %s | llvm-dwarfdump -debug-info - | \ +; RUN: FileCheck %s -check-prefix=STRICT + +; If not strict DWARF mode, we expect DW_TAG_rvalue_reference_type at DWARF 3. +; If strict DWARF mode, we expect DW_TAG_reference_type at DWARF 3 as DW_TAG_rvalue_reference_type +; is a DWARF 4 tag. + +; CHECK: DW_TAG_rvalue_reference_type +; STRICT: DW_TAG_reference_type + +define void @_Z3fooOi(i32* dereferenceable(4) %i) !dbg !8 { +entry: + call void @llvm.dbg.value(metadata i32* %i, metadata !14, metadata !DIExpression()), !dbg !15 + ret void, !dbg !16 +} + +; Function Attrs: nofree nosync nounwind readnone speculatable willreturn +declare void @llvm.dbg.value(metadata, metadata, metadata) #1 + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5, !6} +!llvm.ident = !{!7} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 13.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "1.cpp", directory: "./") +!2 = !{} +!3 = !{i32 7, !"Dwarf Version", i32 3} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 4} +!6 = !{i32 7, !"uwtable", i32 1} +!7 = !{!"clang version 13.0.0"} +!8 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooOi", scope: !1, file: !1, line: 1, type: !9, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !13) +!9 = !DISubroutineType(types: !10) +!10 = !{null, !11} +!11 = !DIDerivedType(tag: DW_TAG_rvalue_reference_type, baseType: !12, size: 64) +!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!13 = !{!14} +!14 = !DILocalVariable(name: "i", arg: 1, scope: !8, file: !1, line: 1, type: !11) +!15 = !DILocation(line: 0, scope: !8) +!16 = !DILocation(line: 3, column: 1, scope: !8)