[MC] Report location information for MCDwarfCallFrameFragment diagnostics
authorFangrui Song <i@maskray.me>
Tue, 27 Jun 2023 01:02:22 +0000 (18:02 -0700)
committerFangrui Song <i@maskray.me>
Tue, 27 Jun 2023 01:02:22 +0000 (18:02 -0700)
llvm/include/llvm/MC/MCFragment.h
llvm/lib/MC/MCAssembler.cpp
llvm/lib/MC/MCDwarf.cpp
llvm/test/MC/MachO/cfi-advance-loc-err.s

index f040cea..0c7e973 100644 (file)
@@ -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;
index cde1d75..24172a4 100644 (file)
@@ -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;
   }
 
index 4d21098..177f957 100644 (file)
@@ -1476,7 +1476,7 @@ void FrameEmitterImpl::emitCFIInstructions(ArrayRef<MCCFIInstruction> Instrs,
     if (BaseLabel && Label) {
       MCSymbol *ThisSym = Label;
       if (ThisSym != BaseLabel) {
-        Streamer.emitDwarfAdvanceFrameAddr(BaseLabel, ThisSym, {});
+        Streamer.emitDwarfAdvanceFrameAddr(BaseLabel, ThisSym, Instr.getLoc());
         BaseLabel = ThisSym;
       }
     }
index a049c19..3143dd8 100644 (file)
@@ -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: <unknown>: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