Add support for the Switch instruction by running the lowerSwitch pass first
[oota-llvm.git] / lib / Transforms / ExprTypeConvert.cpp
index 85f9bb0714cf09b8d657fbe17f80c73bcf329fb6..73db901889d33a8fef0269aba5ac35c63fa5e162 100644 (file)
@@ -274,6 +274,7 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
     //
     if (GEP->getNumOperands() == 2 && 
         GEP->getOperand(1)->getType() == Type::LongTy &&
+        PTy->getElementType()->isSized() &&
         TD.getTypeSize(PTy->getElementType()) == 
         TD.getTypeSize(GEP->getType()->getElementType())) {
       const PointerType *NewSrcTy = PointerType::get(PVTy);
@@ -511,6 +512,8 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) {
     const FunctionType *NewTy =
       FunctionType::get(Ty, ArgTys, FT->isVarArg());
     const PointerType *NewPTy = PointerType::get(NewTy);
+    if (Ty == Type::VoidTy)
+      Name = "";  // Make sure not to name calls that now return void!
 
     Res = new CallInst(Constant::getNullValue(NewPTy),
                        std::vector<Value*>(I->op_begin()+1, I->op_end()),
@@ -657,7 +660,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
     if (Ty->isSigned() != V->getType()->isSigned()) return false;
     // FALL THROUGH
   case Instruction::Shl:
-    assert(I->getOperand(0) == V);
+    if (I->getOperand(1) == V) return false;  // Cannot change shift amount type
     if (!Ty->isInteger()) return false;
     return ValueConvertableToType(I, Ty, CTMap);
 
@@ -1153,6 +1156,9 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
       const FunctionType *NewTy = cast<FunctionType>(NewPTy->getElementType());
       const FunctionType::ParamTypes &PTs = NewTy->getParamTypes();
 
+      if (NewTy->getReturnType() == Type::VoidTy)
+        Name = "";  // Make sure not to name a void call!
+
       // Get an iterator to the call instruction so that we can insert casts for
       // operands if needbe.  Note that we do not require operands to be
       // convertable, we can insert casts if they are convertible but not