[llvm] 5b13371 - [DebugInfo] Avoid triggering global location assert for 2-byte pointer sizes.
Jack Andersen via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 4 12:17:55 PST 2022
Author: Jack Andersen
Date: 2022-01-04T15:16:36-05:00
New Revision: 5b1337184bfb12dd0ec9141765d57677438005b7
URL: https://github.com/llvm/llvm-project/commit/5b1337184bfb12dd0ec9141765d57677438005b7
DIFF: https://github.com/llvm/llvm-project/commit/5b1337184bfb12dd0ec9141765d57677438005b7.diff
LOG: [DebugInfo] Avoid triggering global location assert for 2-byte pointer sizes.
D111404 moved a 4/8 byte check assert into a block taken by 2-byte platforms.
Since these platforms do not take the branches where the pointer size is used,
sink the assert accordingly.
Reviewed By: dblaikie
Differential Revision: https://reviews.llvm.org/D116480
Added:
llvm/test/DebugInfo/MSP430/global-var.ll
Modified:
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index 9b73f0ab2f05e..3ab73d128aed1 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -260,9 +260,20 @@ void DwarfCompileUnit::addLocationAttribute(
if (Global) {
const MCSymbol *Sym = Asm->getSymbol(Global);
- unsigned PointerSize = Asm->getDataLayout().getPointerSize();
- assert((PointerSize == 4 || PointerSize == 8) &&
- "Add support for other sizes if necessary");
+ // 16-bit platforms like MSP430 and AVR take this path, so sink this
+ // assert to platforms that use it.
+ auto GetPointerSizedFormAndOp = [this]() {
+ unsigned PointerSize = Asm->getDataLayout().getPointerSize();
+ assert((PointerSize == 4 || PointerSize == 8) &&
+ "Add support for other sizes if necessary");
+ struct FormAndOp {
+ dwarf::Form Form;
+ dwarf::LocationAtom Op;
+ };
+ return PointerSize == 4
+ ? FormAndOp{dwarf::DW_FORM_data4, dwarf::DW_OP_const4u}
+ : FormAndOp{dwarf::DW_FORM_data8, dwarf::DW_OP_const8u};
+ };
if (Global->isThreadLocal()) {
if (Asm->TM.useEmulatedTLS()) {
// TODO: add debug info for emulated thread local mode.
@@ -270,15 +281,12 @@ void DwarfCompileUnit::addLocationAttribute(
// FIXME: Make this work with -gsplit-dwarf.
// Based on GCC's support for TLS:
if (!DD->useSplitDwarf()) {
+ auto FormAndOp = GetPointerSizedFormAndOp();
// 1) Start with a constNu of the appropriate pointer size
- addUInt(*Loc, dwarf::DW_FORM_data1,
- PointerSize == 4 ? dwarf::DW_OP_const4u
- : dwarf::DW_OP_const8u);
+ addUInt(*Loc, dwarf::DW_FORM_data1, FormAndOp.Op);
// 2) containing the (relocated) offset of the TLS variable
// within the module's TLS block.
- addExpr(*Loc,
- PointerSize == 4 ? dwarf::DW_FORM_data4
- : dwarf::DW_FORM_data8,
+ addExpr(*Loc, FormAndOp.Form,
Asm->getObjFileLowering().getDebugThreadLocalSymbol(Sym));
} else {
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_const_index);
@@ -292,13 +300,11 @@ void DwarfCompileUnit::addLocationAttribute(
}
} else if (Asm->TM.getRelocationModel() == Reloc::RWPI ||
Asm->TM.getRelocationModel() == Reloc::ROPI_RWPI) {
+ auto FormAndOp = GetPointerSizedFormAndOp();
// Constant
- addUInt(*Loc, dwarf::DW_FORM_data1,
- PointerSize == 4 ? dwarf::DW_OP_const4u
- : dwarf::DW_OP_const8u);
+ addUInt(*Loc, dwarf::DW_FORM_data1, FormAndOp.Op);
// Relocation offset
- addExpr(*Loc, PointerSize == 4 ? dwarf::DW_FORM_data4
- : dwarf::DW_FORM_data8,
+ addExpr(*Loc, FormAndOp.Form,
Asm->getObjFileLowering().getIndirectSymViaRWPI(Sym));
// Base register
Register BaseReg = Asm->getObjFileLowering().getStaticBase();
diff --git a/llvm/test/DebugInfo/MSP430/global-var.ll b/llvm/test/DebugInfo/MSP430/global-var.ll
new file mode 100644
index 0000000000000..1941b33846dc1
--- /dev/null
+++ b/llvm/test/DebugInfo/MSP430/global-var.ll
@@ -0,0 +1,47 @@
+; RUN: llc --filetype=obj -o %t < %s
+; RUN: llvm-dwarfdump --debug-info %t | FileCheck %s
+; RUN: llvm-dwarfdump --verify %t
+
+; CHECK: DW_TAG_variable
+; CHECK-NEXT: DW_AT_name ("global_var")
+; CHECK-NEXT: DW_AT_type ({{0x[0-9]+}} "char")
+; CHECK-NEXT: DW_AT_external (true)
+; CHECK-NEXT: DW_AT_decl_file ("/tmp{{[/\\]}}global-var.c")
+; CHECK-NEXT: DW_AT_decl_line (1)
+; CHECK-NEXT: DW_AT_location (DW_OP_addr 0x0)
+
+; ModuleID = 'global-var.c'
+source_filename = "global-var.c"
+target datalayout = "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16"
+target triple = "msp430"
+
+ at global_var = dso_local global i8 42, align 1, !dbg !0
+
+; Function Attrs: noinline nounwind optnone
+define dso_local i16 @main() #0 !dbg !10 {
+entry:
+ ret i16 0, !dbg !15
+}
+
+attributes #0 = { noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!6, !7, !8}
+!llvm.ident = !{!9}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "global_var", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 14.0.0 (https://github.com/llvm/llvm-project ...)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "global-var.c", directory: "/tmp")
+!4 = !{!0}
+!5 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
+!6 = !{i32 7, !"Dwarf Version", i32 4}
+!7 = !{i32 2, !"Debug Info Version", i32 3}
+!8 = !{i32 1, !"wchar_size", i32 2}
+!9 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project ...)"}
+!10 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 2, type: !11, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !14)
+!11 = !DISubroutineType(types: !12)
+!12 = !{!13}
+!13 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_signed)
+!14 = !{}
+!15 = !DILocation(line: 2, column: 13, scope: !10)
More information about the llvm-commits
mailing list