[llvm] 18e35d8 - [LoongArch] Don't left shift negative value (#106812)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 30 17:17:54 PDT 2024


Author: Vitaly Buka
Date: 2024-08-30T17:17:50-07:00
New Revision: 18e35d8f665177a971d0f4ea93b2008dac5e7f33

URL: https://github.com/llvm/llvm-project/commit/18e35d8f665177a971d0f4ea93b2008dac5e7f33
DIFF: https://github.com/llvm/llvm-project/commit/18e35d8f665177a971d0f4ea93b2008dac5e7f33.diff

LOG: [LoongArch] Don't left shift negative value (#106812)

Fixed another UB from #106332.

Detected here https://lab.llvm.org/buildbot/#/builders/169/builds/2662

Added: 
    

Modified: 
    llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMatInt.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMatInt.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMatInt.cpp
index a7823470382756..08e5ccc7bc0be5 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMatInt.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMatInt.cpp
@@ -82,9 +82,9 @@ LoongArchMatInt::InstSeq LoongArchMatInt::generateInstSeq(int64_t Val) {
       TmpVal1 = Insts[1].Imm;
       if (N == 3)
         break;
-      TmpVal2 = Insts[3].Imm << 52 | TmpVal1;
+      TmpVal2 = static_cast<uint64_t>(Insts[3].Imm) << 52 | TmpVal1;
     }
-    TmpVal1 |= Insts[0].Imm << 12;
+    TmpVal1 |= static_cast<uint64_t>(Insts[0].Imm) << 12;
     break;
   case LoongArch::ORI:
   case LoongArch::ADDI_W:


        


More information about the llvm-commits mailing list