diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -18,6 +18,7 @@ #include "llvm/ADT/Optional.h" #include "llvm/CodeGen/AsmPrinter.h" #include "llvm/CodeGen/DIE.h" +#include "llvm/Target/TargetMachine.h" #include namespace llvm { @@ -79,6 +80,12 @@ template void addAttribute(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form, T &&Value) { + // For strict DWARF mode, only generate attributes available to current + // DWARF version. + if (Attribute != 0 && Asm->TM.Options.DebugStrictDwarf && + DD->getDwarfVersion() < dwarf::AttributeVersion(Attribute)) + return; + Die.addValue(DIEValueAllocator, DIEValue(Attribute, Form, std::forward(Value))); } diff --git a/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll b/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll --- a/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll +++ b/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll @@ -2,11 +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 and -; DW_AT_alignment. +; RUN: FileCheck %s -check-prefix=STRICT ; CHECK: DW_AT_alignment ; CHECK: DW_AT_noreturn