diff options
author | Dan Gohman <dan433584@gmail.com> | 2015-11-25 21:13:02 +0000 |
---|---|---|
committer | Dan Gohman <dan433584@gmail.com> | 2015-11-25 21:13:02 +0000 |
commit | 80e34e0a189a297db76db86580e0716827f7fef2 (patch) | |
tree | 240bddd2af75ea66bad68c45231d676657ed044a | |
parent | dd04fee8a607abb6f9214aafbf5d83a21a40c5fa (diff) | |
download | bcm5719-llvm-80e34e0a189a297db76db86580e0716827f7fef2.tar.gz bcm5719-llvm-80e34e0a189a297db76db86580e0716827f7fef2.zip |
[WebAssembly] Fix WebAssembly register numbering for registers added late.
If virtual registers are created late, mappings to WebAssembly
registers need to be added explicitly. This patch adds a function
to do so and teaches WebAssemblyPeephole to use it. This fixes
an out-of-bounds access on the WARegs vector.
llvm-svn: 254094
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h | 8 | ||||
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyPeephole.cpp | 1 |
2 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h b/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h index 9c23412b3cc..4760f0d576e 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h +++ b/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h @@ -63,11 +63,19 @@ public: void initWARegs(); void setWAReg(unsigned VReg, unsigned WAReg) { assert(WAReg != UnusedReg); + assert(TargetRegisterInfo::virtReg2Index(VReg) < WARegs.size()); WARegs[TargetRegisterInfo::virtReg2Index(VReg)] = WAReg; } unsigned getWAReg(unsigned VReg) const { + assert(TargetRegisterInfo::virtReg2Index(VReg) < WARegs.size()); return WARegs[TargetRegisterInfo::virtReg2Index(VReg)]; } + // If new virtual registers are created after initWARegs has been called, + // this function can be used to add WebAssembly register mappings for them. + void addWAReg(unsigned VReg, unsigned WAReg) { + assert(VReg = WARegs.size()); + WARegs.push_back(WAReg); + } }; } // end namespace llvm diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyPeephole.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyPeephole.cpp index 139956225b9..e149d9cce71 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyPeephole.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyPeephole.cpp @@ -69,6 +69,7 @@ bool WebAssemblyPeephole::runOnMachineFunction(MachineFunction &MF) { MO.setReg(NewReg); MO.setIsDead(); MFI.stackifyVReg(NewReg); + MFI.addWAReg(NewReg, WebAssemblyFunctionInfo::UnusedReg); } } } |