From f9b14f0b7cddd4c10d3fa6316ebb52fce2ad0e5b Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 26 Jun 2023 18:02:22 -0700 Subject: [PATCH] [MC] Report location information for MCDwarfCallFrameFragment diagnostics --- llvm/include/llvm/MC/MCFragment.h | 1 + llvm/lib/MC/MCAssembler.cpp | 1 + llvm/lib/MC/MCDwarf.cpp | 2 +- llvm/test/MC/MachO/cfi-advance-loc-err.s | 4 ++-- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/MC/MCFragment.h b/llvm/include/llvm/MC/MCFragment.h index f040cea..0c7e973 100644 --- a/llvm/include/llvm/MC/MCFragment.h +++ b/llvm/include/llvm/MC/MCFragment.h @@ -488,6 +488,7 @@ public: AddrDelta(&AddrDelta) {} const MCExpr &getAddrDelta() const { return *AddrDelta; } + void setAddrDelta(const MCExpr *E) { AddrDelta = E; } static bool classof(const MCFragment *F) { return F->getKind() == MCFragment::FT_DwarfFrame; diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index cde1d75..24172a4 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -1115,6 +1115,7 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout, if (!Abs) { getContext().reportError(DF.getAddrDelta().getLoc(), "invalid CFI advance_loc expression"); + DF.setAddrDelta(MCConstantExpr::create(0, Context)); return false; } diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp index 4d21098..177f957 100644 --- a/llvm/lib/MC/MCDwarf.cpp +++ b/llvm/lib/MC/MCDwarf.cpp @@ -1476,7 +1476,7 @@ void FrameEmitterImpl::emitCFIInstructions(ArrayRef Instrs, if (BaseLabel && Label) { MCSymbol *ThisSym = Label; if (ThisSym != BaseLabel) { - Streamer.emitDwarfAdvanceFrameAddr(BaseLabel, ThisSym, {}); + Streamer.emitDwarfAdvanceFrameAddr(BaseLabel, ThisSym, Instr.getLoc()); BaseLabel = ThisSym; } } diff --git a/llvm/test/MC/MachO/cfi-advance-loc-err.s b/llvm/test/MC/MachO/cfi-advance-loc-err.s index a049c19..3143dd8 100644 --- a/llvm/test/MC/MachO/cfi-advance-loc-err.s +++ b/llvm/test/MC/MachO/cfi-advance-loc-err.s @@ -1,7 +1,5 @@ # RUN: not llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=error: -# CHECK-COUNT-4: :0: error: invalid CFI advance_loc expression - .section __TEXT,__text .globl _foo _foo: @@ -13,9 +11,11 @@ _foo: tmp0: # non-private label cannot appear here addq $8, %rsp +# CHECK: :[[#@LINE+1]]:3: error: invalid CFI advance_loc expression .cfi_adjust_cfa_offset -8 .tmp1: # non-private label cannot appear here addq $8, %rsp +# CHECK: :[[#@LINE+1]]:3: error: invalid CFI advance_loc expression .cfi_adjust_cfa_offset -8 retq .cfi_endproc -- 2.7.4