don't access element zero of an array of size zero.
authorChris Lattner <sabre@nondot.org>
Thu, 3 Jan 2008 01:25:31 +0000 (01:25 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 3 Jan 2008 01:25:31 +0000 (01:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45526 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineRegisterInfo.h

index 81eb69414ad24a6575149b2dcaef00f0866b6bfe..8af42b7cf5f0ecde656245d3fab314f20a888dba 100644 (file)
@@ -108,10 +108,10 @@ public:
   unsigned createVirtualRegister(const TargetRegisterClass *RegClass) {
     assert(RegClass && "Cannot create register without RegClass!");
     // Add a reg, but keep track of whether the vector reallocated or not.
-    void *ArrayBase = &VRegInfo[0];
+    void *ArrayBase = VRegInfo.empty() ? 0 : &VRegInfo[0];
     VRegInfo.push_back(std::make_pair(RegClass, (MachineOperand*)0));
     
-    if (&VRegInfo[0] == ArrayBase)
+    if (&VRegInfo[0] == ArrayBase || VRegInfo.size() == 1)
       return getLastVirtReg();
 
     // Otherwise, the vector reallocated, handle this now.