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 @@ -36,6 +36,7 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Target/TargetLoweringObjectFile.h" +#include "llvm/Target/TargetMachine.h" #include #include #include @@ -218,6 +219,11 @@ } void DwarfUnit::addFlag(DIE &Die, dwarf::Attribute Attribute) { + // For strict DWARF mode, only generate attributes available to current DWARF + // version. + if (Asm->TM.Options.DebugStrictDwarf && + DD->getDwarfVersion() < dwarf::AttributeVersion(Attribute)) + return; if (DD->getDwarfVersion() >= 4) Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_flag_present, DIEInteger(1)); @@ -228,6 +234,11 @@ void DwarfUnit::addUInt(DIEValueList &Die, dwarf::Attribute Attribute, Optional Form, uint64_t Integer) { + // For strict DWARF mode, only generate attributes available to current DWARF + // version. + if (Asm->TM.Options.DebugStrictDwarf && + DD->getDwarfVersion() < dwarf::AttributeVersion(Attribute)) + return; if (!Form) Form = DIEInteger::BestForm(false, Integer); assert(Form != dwarf::DW_FORM_implicit_const && @@ -242,6 +253,11 @@ void DwarfUnit::addSInt(DIEValueList &Die, dwarf::Attribute Attribute, Optional Form, int64_t Integer) { + // For strict DWARF mode, only generate attributes available to current DWARF + // version. + if (Asm->TM.Options.DebugStrictDwarf && + DD->getDwarfVersion() < dwarf::AttributeVersion(Attribute)) + return; if (!Form) Form = DIEInteger::BestForm(true, Integer); Die.addValue(DIEValueAllocator, Attribute, *Form, DIEInteger(Integer)); @@ -257,6 +273,12 @@ if (CUNode->isDebugDirectivesOnly()) return; + // For strict DWARF mode, only generate attributes available to current DWARF + // version. + if (Asm->TM.Options.DebugStrictDwarf && + DD->getDwarfVersion() < dwarf::AttributeVersion(Attribute)) + return; + if (DD->useInlineStrings()) { Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_string, new (DIEValueAllocator) @@ -288,6 +310,11 @@ void DwarfUnit::addLabel(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form, const MCSymbol *Label) { + // For strict DWARF mode, only generate attributes available to current DWARF + // version. + if (Asm->TM.Options.DebugStrictDwarf && + DD->getDwarfVersion() < dwarf::AttributeVersion(Attribute)) + return; Die.addValue(DIEValueAllocator, Attribute, Form, DIELabel(Label)); } @@ -355,6 +382,11 @@ void DwarfUnit::addLabelDelta(DIEValueList &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo) { + // For strict DWARF mode, only generate attributes available to current DWARF + // version. + if (Asm->TM.Options.DebugStrictDwarf && + DD->getDwarfVersion() < dwarf::AttributeVersion(Attribute)) + return; Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_data4, new (DIEValueAllocator) DIEDelta(Hi, Lo)); } @@ -376,6 +408,11 @@ void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIEEntry Entry) { + // For strict DWARF mode, only generate attributes available to current DWARF + // version. + if (Asm->TM.Options.DebugStrictDwarf && + DD->getDwarfVersion() < dwarf::AttributeVersion(Attribute)) + return; const DIEUnit *CU = Die.getUnit(); const DIEUnit *EntryCU = Entry.getEntry().getUnit(); if (!CU) @@ -396,6 +433,11 @@ } void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc) { + // For strict DWARF mode, only generate attributes available to current DWARF + // version. + if (Asm->TM.Options.DebugStrictDwarf && + DD->getDwarfVersion() < dwarf::AttributeVersion(Attribute)) + return; Loc->ComputeSize(Asm); DIELocs.push_back(Loc); // Memoize so we can call the destructor later on. Die.addValue(DIEValueAllocator, Attribute, @@ -404,6 +446,11 @@ void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, dwarf::Form Form, DIEBlock *Block) { + // For strict DWARF mode, only generate attributes available to current DWARF + // version. + if (Asm->TM.Options.DebugStrictDwarf && + DD->getDwarfVersion() < dwarf::AttributeVersion(Attribute)) + return; Block->ComputeSize(Asm); DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on. Die.addValue(DIEValueAllocator, Attribute, Form, Block); @@ -649,6 +696,11 @@ void DwarfUnit::addType(DIE &Entity, const DIType *Ty, dwarf::Attribute Attribute) { + // For strict DWARF mode, only generate attributes available to current DWARF + // version. + if (Asm->TM.Options.DebugStrictDwarf && + DD->getDwarfVersion() < dwarf::AttributeVersion(Attribute)) + return; assert(Ty && "Trying to add a type that doesn't exist?"); addDIEEntry(Entity, Attribute, DIEEntry(*getOrCreateTypeDIE(Ty))); } @@ -1746,6 +1798,11 @@ void DwarfUnit::addSectionDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo) { + // For strict DWARF mode, only generate attributes available to current DWARF + // version. + if (Asm->TM.Options.DebugStrictDwarf && + DD->getDwarfVersion() < dwarf::AttributeVersion(Attribute)) + return; Die.addValue(DIEValueAllocator, Attribute, DD->getDwarfSectionOffsetForm(), new (DIEValueAllocator) DIEDelta(Hi, Lo)); } diff --git a/llvm/test/DebugInfo/PowerPC/alignment.ll b/llvm/test/DebugInfo/PowerPC/alignment.ll --- a/llvm/test/DebugInfo/PowerPC/alignment.ll +++ b/llvm/test/DebugInfo/PowerPC/alignment.ll @@ -2,10 +2,7 @@ ; 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 - -; FIXME: when -strict-dwarf=true is specified, we should check "STRICT" to tell -; that with DWARF 4, we should not generate DWARF 5 attribute DW_AT_alignment. +; RUN: FileCheck %s --check-prefix=STRICT ; CHECK: DW_AT_alignment ; STRICT-NOT: DW_AT_alignment diff --git a/llvm/test/DebugInfo/PowerPC/noreturn.ll b/llvm/test/DebugInfo/PowerPC/noreturn.ll --- a/llvm/test/DebugInfo/PowerPC/noreturn.ll +++ b/llvm/test/DebugInfo/PowerPC/noreturn.ll @@ -2,10 +2,7 @@ ; 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 - -; FIXME: when -strict-dwarf=true is specified, we should check "STRICT" to tell -; that with DWARF 4, we should not generate DWARF 5 attribute DW_AT_noreturn. +; RUN: FileCheck %s --check-prefix=STRICT ; CHECK: DW_AT_noreturn ; STRICT-NOT: DW_AT_noreturn