[llvm] 977eeb0 - [WebAssembly] Fix some UB from ca541aa319cd

Thomas Lively via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 24 19:44:12 PDT 2021


Author: Thomas Lively
Date: 2021-08-24T19:44:03-07:00
New Revision: 977eeb0c38712294bdeec790ba5ac9f5d8849539

URL: https://github.com/llvm/llvm-project/commit/977eeb0c38712294bdeec790ba5ac9f5d8849539
DIFF: https://github.com/llvm/llvm-project/commit/977eeb0c38712294bdeec790ba5ac9f5d8849539.diff

LOG: [WebAssembly] Fix some UB from ca541aa319cd

Added: 
    

Modified: 
    llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index f0191c6f98df..75c7841fd655 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -2055,10 +2055,10 @@ SDValue WebAssemblyTargetLowering::LowerBUILD_VECTOR(SDValue Op,
         auto *Const = dyn_cast<ConstantSDNode>(Lane.getNode());
         int64_t Val = Const ? Const->getSExtValue() : 0;
         uint64_t LaneBits = 128 / Lanes;
-        assert((LaneT == MVT::i64 || Val >= -(1 << (LaneBits - 1))) &&
+        assert((LaneBits == 64 || Val >= -(1ll << (LaneBits - 1))) &&
                "Unexpected out of bounds negative value");
-        if (Const && LaneT != MVT::i64 && Val > (1 << (LaneBits - 1)) - 1) {
-          auto NewVal = ((uint64_t)Val % (1u << LaneBits)) - (1u << LaneBits);
+        if (Const && LaneBits != 64 && Val > (1ll << (LaneBits - 1)) - 1) {
+          auto NewVal = ((uint64_t)Val % (1ll << LaneBits)) - (1ll << LaneBits);
           ConstLanes.push_back(DAG.getConstant(NewVal, SDLoc(Lane), LaneT));
         } else {
           ConstLanes.push_back(Lane);


        


More information about the llvm-commits mailing list