Author: Chen Zheng Date: 2021-04-24T21:34:42-04:00 New Revision: e91eb89cc97d077c8bbae2c28749304d005511cd
URL: https://github.com/llvm/llvm-project/commit/e91eb89cc97d077c8bbae2c28749304d005511cd DIFF: https://github.com/llvm/llvm-project/commit/e91eb89cc97d077c8bbae2c28749304d005511cd.diff LOG: [Debug-Info] guard attribute generating under strict dwarf. Conflicts: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h Added: Modified: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h llvm/test/DebugInfo/PowerPC/strict-dwarf.ll Removed: ################################################################################ diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h index aca831a535a19..3a961ab47f6df 100644 --- 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 <string> namespace llvm { @@ -79,6 +80,12 @@ class DwarfUnit : public DIEUnit { template <typename T> 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<T>(Value))); } diff --git a/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll b/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll index b64fd426e8eab..27fbfdbcedf42 100644 --- a/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll +++ b/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll @@ -2,16 +2,25 @@ ; 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 +; RUN: FileCheck %s -check-prefix=STRICT -; 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. +; We also check that with/without -strict-dwarf=true, the location attribute +; is not changed. The location attribute adding will call DwarfUnit::addUInt() +; which contains a attribute 0, we want to make sure the strict-dwarf handling +; is also right for attribute 0. +; For this case, the location attribute adding is for global variable @_ZL3var +; and the call chain to addUInt() is: +; 1: DwarfCompileUnit::addLocationAttribute() +; 2: DwarfUnit::addOpAddress() +; 3: DwarfUnit::addUInt() +; 4: addUInt(Block, (dwarf::Attribute)0, Form, Integer); ; CHECK: DW_AT_alignment +; CHECK: DW_AT_location (DW_OP_addr 0x0) ; CHECK: DW_AT_noreturn ; STRICT-NOT: DW_AT_noreturn ; STRICT-NOT: DW_AT_alignment +; STRICT: DW_AT_location (DW_OP_addr 0x0) @_ZL3var = internal global i32 0, align 16, !dbg !0 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits