[llvm] r254094 - [WebAssembly] Fix WebAssembly register numbering for registers added late.

Dan Gohman via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 25 13:13:02 PST 2015


Author: djg
Date: Wed Nov 25 15:13:02 2015
New Revision: 254094

URL: http://llvm.org/viewvc/llvm-project?rev=254094&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h?rev=254094&r1=254093&r2=254094&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h Wed Nov 25 15:13:02 2015
@@ -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

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp?rev=254094&r1=254093&r2=254094&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp Wed Nov 25 15:13:02 2015
@@ -69,6 +69,7 @@ bool WebAssemblyPeephole::runOnMachineFu
           MO.setReg(NewReg);
           MO.setIsDead();
           MFI.stackifyVReg(NewReg);
+          MFI.addWAReg(NewReg, WebAssemblyFunctionInfo::UnusedReg);
         }
       }
       }




More information about the llvm-commits mailing list