Skip to content

Commit

Permalink
[Xtensa] Improve fixup error messages in asm backend.
Browse files Browse the repository at this point in the history
Add different diagnotstics messages for different branch
relocations fixups.
  • Loading branch information
andreisfr committed Apr 1, 2023
1 parent 2989ff7 commit 1e28f73
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 9 deletions.
68 changes: 68 additions & 0 deletions 0001-Xtensa-Improve-fixup-error-messages-in-asm-backend.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
From c8f321e8f88802dd427bc9772da171d5c889a77d Mon Sep 17 00:00:00 2001
From: Andrei Safronov <safronov@espressif.com>
Date: Thu, 9 Mar 2023 10:30:04 +0300
Subject: [PATCH] [Xtensa] Improve fixup error messages in asm backend.

---
.../Xtensa/MCTargetDesc/XtensaAsmBackend.cpp | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaAsmBackend.cpp b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaAsmBackend.cpp
index 4039804b1b58..6981c82e768f 100644
--- a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaAsmBackend.cpp
+++ b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaAsmBackend.cpp
@@ -93,7 +93,7 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
case Xtensa::fixup_xtensa_branch_6: {
Value -= 4;
if (!isInt<6>(Value))
- Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
+ Ctx.reportError(Fixup.getLoc(), "branch 6-bit fixup value out is of range");
unsigned Hi2 = (Value >> 4) & 0x3;
unsigned Lo4 = Value & 0xf;
return (Hi2 << 4) | (Lo4 << 12);
@@ -101,36 +101,36 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
case Xtensa::fixup_xtensa_branch_8:
Value -= 4;
if (!isInt<8>(Value))
- Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
+ Ctx.reportError(Fixup.getLoc(), "branch 8-bit fixup value out of range");
return (Value & 0xff);
case Xtensa::fixup_xtensa_branch_12:
Value -= 4;
if (!isInt<12>(Value))
- Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
+ Ctx.reportError(Fixup.getLoc(), "branch 12-bit fixup value out of range");
return (Value & 0xfff);
case Xtensa::fixup_xtensa_jump_18:
Value -= 4;
if (!isInt<18>(Value))
- Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
+ Ctx.reportError(Fixup.getLoc(), "jump fixup value out of range");
return (Value & 0x3ffff);
case Xtensa::fixup_xtensa_call_18:
Value -= 4;
if (!isInt<20>(Value))
- Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
+ Ctx.reportError(Fixup.getLoc(), "call fixup value out of range");
if (Value & 0x3)
Ctx.reportError(Fixup.getLoc(), "fixup value must be 4-byte aligned");
return (Value & 0xffffc) >> 2;
case Xtensa::fixup_xtensa_loop_8:
Value -= 4;
if (!isUInt<8>(Value))
- Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
+ Ctx.reportError(Fixup.getLoc(), "loop fixup value out of range");
return (Value & 0xff);
case Xtensa::fixup_xtensa_l32r_16:
unsigned Offset = Fixup.getOffset();
if (Offset & 0x3)
Value -= 4;
if (!isInt<18>(Value) && (Value & 0x20000))
- Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
+ Ctx.reportError(Fixup.getLoc(), "l32r fixup value out of range");
if (Value & 0x3)
Ctx.reportError(Fixup.getLoc(), "fixup value must be 4-byte aligned");
return (Value & 0x3fffc) >> 2;
--
2.25.1

14 changes: 7 additions & 7 deletions llvm/lib/Target/Xtensa/MCTargetDesc/XtensaAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,44 +93,44 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
case Xtensa::fixup_xtensa_branch_6: {
Value -= 4;
if (!isInt<6>(Value))
Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
Ctx.reportError(Fixup.getLoc(), "branch 6-bit fixup value out is of range");
unsigned Hi2 = (Value >> 4) & 0x3;
unsigned Lo4 = Value & 0xf;
return (Hi2 << 4) | (Lo4 << 12);
}
case Xtensa::fixup_xtensa_branch_8:
Value -= 4;
if (!isInt<8>(Value))
Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
Ctx.reportError(Fixup.getLoc(), "branch 8-bit fixup value out of range");
return (Value & 0xff);
case Xtensa::fixup_xtensa_branch_12:
Value -= 4;
if (!isInt<12>(Value))
Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
Ctx.reportError(Fixup.getLoc(), "branch 12-bit fixup value out of range");
return (Value & 0xfff);
case Xtensa::fixup_xtensa_jump_18:
Value -= 4;
if (!isInt<18>(Value))
Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
Ctx.reportError(Fixup.getLoc(), "jump fixup value out of range");
return (Value & 0x3ffff);
case Xtensa::fixup_xtensa_call_18:
Value -= 4;
if (!isInt<20>(Value))
Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
Ctx.reportError(Fixup.getLoc(), "call fixup value out of range");
if (Value & 0x3)
Ctx.reportError(Fixup.getLoc(), "fixup value must be 4-byte aligned");
return (Value & 0xffffc) >> 2;
case Xtensa::fixup_xtensa_loop_8:
Value -= 4;
if (!isUInt<8>(Value))
Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
Ctx.reportError(Fixup.getLoc(), "loop fixup value out of range");
return (Value & 0xff);
case Xtensa::fixup_xtensa_l32r_16:
unsigned Offset = Fixup.getOffset();
if (Offset & 0x3)
Value -= 4;
if (!isInt<18>(Value) && (Value & 0x20000))
Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
Ctx.reportError(Fixup.getLoc(), "l32r fixup value out of range");
if (Value & 0x3)
Ctx.reportError(Fixup.getLoc(), "fixup value must be 4-byte aligned");
return (Value & 0x3fffc) >> 2;
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/MC/Xtensa/fixups-diagnostics.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

.align 4

beq a0, a1, LBL1 # CHECK: :[[@LINE]]:3: error: fixup value out of range
beq a0, a1, LBL1 # CHECK: :[[@LINE]]:3: error: branch 8-bit fixup value out of range
LBL0:
beqz a0, LBL2 # CHECK: :[[@LINE]]:3: error: fixup value out of range
beqz a0, LBL2 # CHECK: :[[@LINE]]:3: error: branch 12-bit fixup value out of range

call0 LBL0 # CHECK: :[[@LINE]]:3: error: fixup value must be 4-byte aligned

Expand Down

0 comments on commit 1e28f73

Please sign in to comment.