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,22 @@ } 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. + // TODO: the naively replacement may introduce duplicated tags. For example, + // before the replacement, we have DW_TAG_rvalue_reference_type with type + // int and DW_TAG_reference_type with type int, after the replacement, now + // we have two DW_TAG_reference_type with type int. We should fix this. + 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,67 @@ +; 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 +; CHECK-NEXT: DW_AT_type {{.*}} "int" +; CHECK: DW_TAG_base_type +; CHECK-NOT: DW_TAG +; CHECK: DW_AT_name {{.*}}"int" +; CHECK: DW_TAG_reference_type +; CHECK-NEXT: DW_AT_type {{.*}} "int" +; +; FIXME: remove the redundant tag DW_TAG_reference_type. We only need one tag +; DW_TAG_reference_type with base type int. +; +; STRICT-NOT: DW_TAG_rvalue_reference_type +; STRICT: DW_TAG_reference_type +; STRICT-NEXT: DW_AT_type {{.*}} "int" +; STRICT: DW_TAG_base_type +; STRICT-NOT: DW_TAG +; STRICT: DW_AT_name {{.}}"int" +; STRICT: DW_TAG_reference_type +; STRICT-NEXT: DW_AT_type {{.*}} "int" + +define void @_Z2f1OiRi(i32* dereferenceable(4) %0, i32* dereferenceable(4) %1) #0 !dbg !9 { + %3 = alloca i32*, align 8 + %4 = alloca i32*, align 8 + store i32* %0, i32** %3, align 8 + call void @llvm.dbg.declare(metadata i32** %3, metadata !15, metadata !DIExpression()), !dbg !16 + store i32* %1, i32** %4, align 8 + call void @llvm.dbg.declare(metadata i32** %4, metadata !17, metadata !DIExpression()), !dbg !18 + ret void, !dbg !19 +} + +; Function Attrs: nofree nosync nounwind readnone speculatable willreturn +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5, !6, !7} +!llvm.ident = !{!8} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 13.0.0", isOptimized: false, 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 = !{i32 7, !"frame-pointer", i32 2} +!8 = !{!"clang version 13.0.0"} +!9 = distinct !DISubprogram(name: "f1", linkageName: "_Z2f1OiRi", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!10 = !DISubroutineType(types: !11) +!11 = !{null, !12, !14} +!12 = !DIDerivedType(tag: DW_TAG_rvalue_reference_type, baseType: !13, size: 64) +!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!14 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !13, size: 64) +!15 = !DILocalVariable(name: "x", arg: 1, scope: !9, file: !1, line: 1, type: !12) +!16 = !DILocation(line: 1, column: 15, scope: !9) +!17 = !DILocalVariable(name: "y", arg: 2, scope: !9, file: !1, line: 1, type: !14) +!18 = !DILocation(line: 1, column: 23, scope: !9) +!19 = !DILocation(line: 2, column: 1, scope: !9)