[llvm] 097b702 - [Coverity] avoid array overflow when use -1 as index.
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 10 00:52:37 PDT 2023
Author: Luo, Yuanke
Date: 2023-04-10T15:40:59+08:00
New Revision: 097b70254678d947feaa108c73f11adec27473d9
URL: https://github.com/llvm/llvm-project/commit/097b70254678d947feaa108c73f11adec27473d9
DIFF: https://github.com/llvm/llvm-project/commit/097b70254678d947feaa108c73f11adec27473d9.diff
LOG: [Coverity] avoid array overflow when use -1 as index.
Added:
Modified:
llvm/lib/MC/MCRegisterInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCRegisterInfo.cpp b/llvm/lib/MC/MCRegisterInfo.cpp
index 9c88e3be97df0..9f5b08c5cd1cb 100644
--- a/llvm/lib/MC/MCRegisterInfo.cpp
+++ b/llvm/lib/MC/MCRegisterInfo.cpp
@@ -101,8 +101,13 @@ int MCRegisterInfo::getDwarfRegNumFromDwarfEHRegNum(unsigned RegNum) const {
// a corresponding LLVM register number at all. So if we can't map the
// EH register number to an LLVM register number, assume it's just a
// valid DWARF register number as is.
- if (std::optional<unsigned> LRegNum = getLLVMRegNum(RegNum, true))
- return getDwarfRegNum(*LRegNum, false);
+ if (std::optional<unsigned> LRegNum = getLLVMRegNum(RegNum, true)) {
+ int DwarfRegNum = getDwarfRegNum(*LRegNum, false);
+ if (DwarfRegNum == -1)
+ return RegNum;
+ else
+ return DwarfRegNum;
+ }
return RegNum;
}
More information about the llvm-commits
mailing list