[llvm] 5cf138c - [llvm][JITLink][LoongArch] Fix bit extraction on 32 bit platforms

David Spickett via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 3 04:47:40 PST 2025


Author: David Spickett
Date: 2025-01-03T12:47:14Z
New Revision: 5cf138cfbaa8040100fed1d0d5e0a189759b24ab

URL: https://github.com/llvm/llvm-project/commit/5cf138cfbaa8040100fed1d0d5e0a189759b24ab
DIFF: https://github.com/llvm/llvm-project/commit/5cf138cfbaa8040100fed1d0d5e0a189759b24ab.diff

LOG: [llvm][JITLink][LoongArch] Fix bit extraction on 32 bit platforms

This shifted `1UL` to make the mask. On 32 bit Linux UL is 32 bit,
so if Hi+1 was >= 32 then you'd get the wrong result here.

The other version of this uses 1ULL, but using the uint64_t typename
here saves someone going to check what ULL means on different platforms.

This fixes test failures seen on Linaro's 32 bit bots:
https://lab.llvm.org/buildbot/#/builders/39/builds/3700
https://lab.llvm.org/buildbot/#/builders/122/builds/781

Though I cannot say exactly why this fixes them. Does not seem
like the new code was triggering this problem, but somehow it
must be.

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h b/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h
index d31c749bad1b1c..1db4b822181094 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h
@@ -233,7 +233,7 @@ const char *getEdgeKindName(Edge::Kind K);
 
 // Returns extract bits Val[Hi:Lo].
 inline uint32_t extractBits(uint64_t Val, unsigned Hi, unsigned Lo) {
-  return Hi == 63 ? Val >> Lo : (Val & (((1UL << (Hi + 1)) - 1))) >> Lo;
+  return Hi == 63 ? Val >> Lo : (Val & ((((uint64_t)1 << (Hi + 1)) - 1))) >> Lo;
 }
 
 /// Apply fixup expression for edge to block content.


        


More information about the llvm-commits mailing list