aboutsummaryrefslogtreecommitdiff
path: root/llvm
diff options
context:
space:
mode:
authorXiaodong Liu <liuxiaodong@loongson.cn>2022-10-27 17:42:54 +0800
committerXiaodong Liu <liuxiaodong@loongson.cn>2022-10-29 17:48:08 +0800
commit53f9b95179f46d94f3032626465b0d0442e3839c (patch)
tree4b6935fc6fca31a5941d899ff23bae73c30b9a2d /llvm
parentefae1a7cf06bd71f7ec6e8dc9e5c2b085150a451 (diff)
downloadllvm-53f9b95179f46d94f3032626465b0d0442e3839c.zip
llvm-53f9b95179f46d94f3032626465b0d0442e3839c.tar.gz
llvm-53f9b95179f46d94f3032626465b0d0442e3839c.tar.bz2
[LoongArch] Improve the "out of range" error information reported by `adjustFixupValue`
There are three reduplicate error messages for different conditions. I add meaningful information to make them more informative. Differential Revision: https://reviews.llvm.org/D136742
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp11
-rw-r--r--llvm/test/MC/LoongArch/Relocations/fixups-diagnostics.s12
2 files changed, 14 insertions, 9 deletions
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
index 4a5edd8..33e84fe 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -77,6 +77,11 @@ LoongArchAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
return Infos[Kind - FirstTargetFixupKind];
}
+static void reportOutOfRangeError(MCContext &Ctx, SMLoc Loc, unsigned N) {
+ Ctx.reportError(Loc, "fixup value out of range [" + Twine(llvm::minIntN(N)) +
+ ", " + Twine(llvm::maxIntN(N)) + "]");
+}
+
static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
MCContext &Ctx) {
switch (Fixup.getTargetKind()) {
@@ -89,21 +94,21 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
return Value;
case LoongArch::fixup_loongarch_b16: {
if (!isInt<18>(Value))
- Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
+ reportOutOfRangeError(Ctx, Fixup.getLoc(), 18);
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(Ctx, Fixup.getLoc(), 23);
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(Ctx, Fixup.getLoc(), 28);
if (Value % 4)
Ctx.reportError(Fixup.getLoc(), "fixup value must be 4-byte aligned");
return ((Value & 0x3fffc) << 8) | ((Value >> 18) & 0x3ff);
diff --git a/llvm/test/MC/LoongArch/Relocations/fixups-diagnostics.s b/llvm/test/MC/LoongArch/Relocations/fixups-diagnostics.s
index 7c02789..c72eef7 100644
--- a/llvm/test/MC/LoongArch/Relocations/fixups-diagnostics.s
+++ b/llvm/test/MC/LoongArch/Relocations/fixups-diagnostics.s
@@ -9,12 +9,12 @@ unaligned:
.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: