Avoid crashing on Arguments, just silently miscompile
[oota-llvm.git] / lib / Target / X86 / X86ISelSimple.cpp
index 10fdf0f911da386b387dde19d424278d37784615..27c5d061c266e7c5593a25fabe34c6e5d775f1ea 100644 (file)
@@ -133,8 +133,16 @@ namespace {
       // If this operand is a constant, emit the code to copy the constant into
       // the register here...
       //
-      if (Constant *C = dyn_cast<Constant>(V))
+      if (Constant *C = dyn_cast<Constant>(V)) {
         copyConstantToRegister(C, Reg);
+      } else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
+        // Move the address of the global into the register
+        BuildMI(BB, X86::MOVir32, 1, Reg).addReg(GV);
+      } else if (Argument *A = dyn_cast<Argument>(V)) {
+        std::cerr << "ERROR: Arguments not implemented in SimpleInstSel\n";
+      } else {
+        assert(0 && "Don't know how to handle a value of this type!");
+      }
 
       return Reg;
     }
@@ -389,10 +397,9 @@ ISel::visitCallInst (CallInst & CI)
 {
   // Push the arguments on the stack in reverse order, as specified by
   // the ABI.
-  for (unsigned i = CI.getNumOperands (); i >= 1; --i)
+  for (unsigned i = CI.getNumOperands()-1; i >= 1; --i)
     {
       Value *v = CI.getOperand (i);
-      unsigned argReg = getReg (v);
       switch (getClass (v->getType ()))
        {
        case cByte:
@@ -403,9 +410,11 @@ ISel::visitCallInst (CallInst & CI)
          BuildMI (BB, X86::PUSHr32, 1).addReg (X86::EAX);
          break;
        case cInt:
-       case cFloat:
-         BuildMI (BB, X86::PUSHr32, 1).addReg (argReg);
+       case cFloat: {
+          unsigned Reg = getReg(v);
+          BuildMI (BB, X86::PUSHr32, 1).addReg(Reg);
          break;
+        }
        default:
          // FIXME: long/ulong/double args not handled.
          visitInstruction (CI);