[lld] [lld][ELF] Fix a corner case of elf::getLoongArchPageDelta (PR #71907)

WÁNG Xuěruì via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 10 01:30:13 PST 2023


================
@@ -159,6 +159,10 @@ uint64_t elf::getLoongArchPageDelta(uint64_t dest, uint64_t pc) {
   bool negativeA = lo12(dest) > 0x7ff;
   bool negativeB = (result & 0x8000'0000) != 0;
 
+  // A corner case; directly return the expected result.
+  if (result == 0xfffffffffffff000 && negativeA)
+    return result = 0xffffffff00000000;
----------------
xen0n wrote:

I can see the misbehavior is caused by an overflow in the `result += 0x1000` below; who expected that! Thanks for spotting it.

First of all, stylistically, the `result =` part could be dropped and some `'` could be added to help counting bits; other than that, I don't know if the other arithmetic could overflow too, in which case we might want to guard them too.

https://github.com/llvm/llvm-project/pull/71907


More information about the llvm-commits mailing list