summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominic Chen <d.c.ddcc@gmail.com>2016-08-12 23:12:59 +0000
committerDominic Chen <d.c.ddcc@gmail.com>2016-08-12 23:12:59 +0000
commit2868fa171a35ebe9b8f4462004ed1bf359b86dba (patch)
tree46e543be0c805400d0c05e3341889d0e20642468
parentc9c0d2dcb5ff88916290deb5d413435ac1ac3bc6 (diff)
downloadbcm5719-llvm-2868fa171a35ebe9b8f4462004ed1bf359b86dba.tar.gz
bcm5719-llvm-2868fa171a35ebe9b8f4462004ed1bf359b86dba.zip
Avoid accessing LLVM/DWARF register mappings if undefined
Summary: If the backend does not define LLVM/DWARF register mappings, the associated variables are undefined since the map initializer is called by auto-generated TableGen routines. This patch initializes the pointers and sizes to nullptr and zero, respectively, and checks that they are valid before searching for a mapping. Reviewers: grosbach, dschuff Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D23458 llvm-svn: 278574
-rw-r--r--llvm/include/llvm/MC/MCRegisterInfo.h10
-rw-r--r--llvm/lib/MC/MCRegisterInfo.cpp4
2 files changed, 14 insertions, 0 deletions
diff --git a/llvm/include/llvm/MC/MCRegisterInfo.h b/llvm/include/llvm/MC/MCRegisterInfo.h
index 548280614e9..1d3c64a8ef5 100644
--- a/llvm/include/llvm/MC/MCRegisterInfo.h
+++ b/llvm/include/llvm/MC/MCRegisterInfo.h
@@ -271,6 +271,16 @@ public:
NumSubRegIndices = NumIndices;
SubRegIdxRanges = SubIdxRanges;
RegEncodingTable = RET;
+
+ // Initialize DWARF register mapping variables
+ EHL2DwarfRegs = nullptr;
+ EHL2DwarfRegsSize = 0;
+ L2DwarfRegs = nullptr;
+ L2DwarfRegsSize = 0;
+ EHDwarf2LRegs = nullptr;
+ EHDwarf2LRegsSize = 0;
+ Dwarf2LRegs = nullptr;
+ Dwarf2LRegsSize = 0;
}
/// \brief Used to initialize LLVM register to Dwarf
diff --git a/llvm/lib/MC/MCRegisterInfo.cpp b/llvm/lib/MC/MCRegisterInfo.cpp
index c76bb646c12..3d0f30d306c 100644
--- a/llvm/lib/MC/MCRegisterInfo.cpp
+++ b/llvm/lib/MC/MCRegisterInfo.cpp
@@ -62,6 +62,8 @@ int MCRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
const DwarfLLVMRegPair *M = isEH ? EHL2DwarfRegs : L2DwarfRegs;
unsigned Size = isEH ? EHL2DwarfRegsSize : L2DwarfRegsSize;
+ if (!M)
+ return -1;
DwarfLLVMRegPair Key = { RegNum, 0 };
const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
if (I == M+Size || I->FromReg != RegNum)
@@ -73,6 +75,8 @@ int MCRegisterInfo::getLLVMRegNum(unsigned RegNum, bool isEH) const {
const DwarfLLVMRegPair *M = isEH ? EHDwarf2LRegs : Dwarf2LRegs;
unsigned Size = isEH ? EHDwarf2LRegsSize : Dwarf2LRegsSize;
+ if (!M)
+ return -1;
DwarfLLVMRegPair Key = { RegNum, 0 };
const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
assert(I != M+Size && I->FromReg == RegNum && "Invalid RegNum");
OpenPOWER on IntegriCloud