[llvm] [LoongArch] Don't left shift negative value (PR #106812)

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-loongarch

Author: Vitaly Buka (vitalybuka)

<details>
<summary>Changes</summary>

Fixed another UB from #<!-- -->106332.


---
Full diff: https://github.com/llvm/llvm-project/pull/106812.diff


1 Files Affected:

- (modified) llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMatInt.cpp (+2-2) 


``````````diff
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:

``````````

</details>


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


More information about the llvm-commits mailing list