[PATCH] D136742: [llvm][LoongArch] Improve the "out of range" error information reported by `adjustFixupValue`, NFC
Xiaodong Liu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 27 18:48:29 PDT 2022
XiaodongLoong updated this revision to Diff 471359.
XiaodongLoong added a comment.
Update patch for review comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136742/new/
https://reviews.llvm.org/D136742
Files:
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
llvm/test/MC/LoongArch/Relocations/fixups-diagnostics.s
Index: llvm/test/MC/LoongArch/Relocations/fixups-diagnostics.s
===================================================================
--- llvm/test/MC/LoongArch/Relocations/fixups-diagnostics.s
+++ llvm/test/MC/LoongArch/Relocations/fixups-diagnostics.s
@@ -9,12 +9,12 @@
.byte 0
.byte 0
- beq $a0, $a1, out_of_range_b16 # CHECK: :[[#@LINE]]:3: error: fixup value out of range
+ beq $a0, $a1, out_of_range_b18 # CHECK: :[[#@LINE]]:3: error: fixup value out of range [-131072, 131071]
.space 1<<18
-out_of_range_b16:
- beqz $a0, out_of_range_b21 # CHECK: :[[#@LINE]]:3: error: fixup value out of range
+out_of_range_b18:
+ beqz $a0, out_of_range_b23 # CHECK: :[[#@LINE]]:3: error: fixup value out of range [-4194304, 4194303]
.space 1<<23
-out_of_range_b21:
- b out_of_range_b26 # CHECK: :[[#@LINE]]:3: error: fixup value out of range
+out_of_range_b23:
+ b out_of_range_b28 # CHECK: :[[#@LINE]]:3: error: fixup value out of range [-134217728, 134217727]
.space 1<<28
-out_of_range_b26:
+out_of_range_b28:
Index: llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
===================================================================
--- llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -77,6 +77,15 @@
return Infos[Kind - FirstTargetFixupKind];
}
+static void reportOutOfRangeError(const MCFixup &Fixup, unsigned N,
+ MCContext &Ctx) {
+ int64_t min = -(INT64_C(1) << (N - 1));
+ uint64_t max = (INT64_C(1) << (N - 1)) - 1;
+ Ctx.reportError(Fixup.getLoc(), "fixup value out of range [" +
+ Twine(min).str() + ", " +
+ Twine(max).str() + "]");
+}
+
static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
MCContext &Ctx) {
switch (Fixup.getTargetKind()) {
@@ -89,21 +98,21 @@
return Value;
case LoongArch::fixup_loongarch_b16: {
if (!isInt<18>(Value))
- Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
+ reportOutOfRangeError(Fixup, 18, Ctx);
if (Value % 4)
Ctx.reportError(Fixup.getLoc(), "fixup value must be 4-byte aligned");
return (Value >> 2) & 0xffff;
}
case LoongArch::fixup_loongarch_b21: {
if (!isInt<23>(Value))
- Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
+ reportOutOfRangeError(Fixup, 23, Ctx);
if (Value % 4)
Ctx.reportError(Fixup.getLoc(), "fixup value must be 4-byte aligned");
return ((Value & 0x3fffc) << 8) | ((Value >> 18) & 0x1f);
}
case LoongArch::fixup_loongarch_b26: {
if (!isInt<28>(Value))
- Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
+ reportOutOfRangeError(Fixup, 28, Ctx);
if (Value % 4)
Ctx.reportError(Fixup.getLoc(), "fixup value must be 4-byte aligned");
return ((Value & 0x3fffc) << 8) | ((Value >> 18) & 0x3ff);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136742.471359.patch
Type: text/x-patch
Size: 2997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221028/a70beae2/attachment.bin>
More information about the llvm-commits
mailing list