PR 1603 test case.
[oota-llvm.git] / tools / llvm-upgrade / UpgradeParser.y.cvs
index dfc86c615d8ca2da49a48b509f4ac26e1f6f4165..211934f368a0978a3d9c2bc770413af58da904fd 100644 (file)
@@ -62,6 +62,7 @@ static bool ObsoleteVarArgs;
 static bool NewVarArgs;
 static BasicBlock *CurBB;
 static GlobalVariable *CurGV;
+static unsigned lastCallingConv;
 
 // This contains info used when building the body of a function.  It is
 // destroyed when the function is completed.
@@ -380,19 +381,18 @@ static bool FuncTysDifferOnlyBySRet(const FunctionType *F1,
   if (F1->getReturnType() != F2->getReturnType() ||
       F1->getNumParams() != F2->getNumParams())
     return false;
-  ParamAttrsList PAL1;
-  if (F1->getParamAttrs())
-    PAL1 = *F1->getParamAttrs();
-  ParamAttrsList PAL2;
-  if (F2->getParamAttrs())
-    PAL2 = *F2->getParamAttrs();
-  if (PAL1.getParamAttrs(0) != PAL2.getParamAttrs(0))
+  const ParamAttrsList *PAL1 = F1->getParamAttrs();
+  const ParamAttrsList *PAL2 = F2->getParamAttrs();
+  if (PAL1 && !PAL2 || PAL2 && !PAL1)
     return false;
-  unsigned SRetMask = ~unsigned(StructRetAttribute);
+  if (PAL1 && PAL2 && ((PAL1->size() != PAL2->size()) ||
+      (PAL1->getParamAttrs(0) != PAL2->getParamAttrs(0)))) 
+    return false;
+  unsigned SRetMask = ~unsigned(ParamAttr::StructRet);
   for (unsigned i = 0; i < F1->getNumParams(); ++i) {
-    if (F1->getParamType(i) != F2->getParamType(i) ||
-        unsigned(PAL1.getParamAttrs(i+1)) & SRetMask !=
-        unsigned(PAL2.getParamAttrs(i+1)) & SRetMask)
+    if (F1->getParamType(i) != F2->getParamType(i) || (PAL1 && PAL2 &&
+        (unsigned(PAL1->getParamAttrs(i+1)) & SRetMask !=
+         unsigned(PAL2->getParamAttrs(i+1)) & SRetMask)))
       return false;
   }
   return true;
@@ -433,7 +433,7 @@ static Value* handleSRetFuncTypeMerge(Value *V, const Type* Ty) {
     const FunctionType *FT2 = dyn_cast<FunctionType>(PF2->getElementType());
     if (FT1 && FT2 && FuncTysDifferOnlyBySRet(FT1, FT2)) {
       const ParamAttrsList *PAL2 = FT2->getParamAttrs();
-      if (PAL2 && PAL2->paramHasAttr(1, StructRetAttribute))
+      if (PAL2 && PAL2->paramHasAttr(1, ParamAttr::StructRet))
         return V;
       else if (Constant *C = dyn_cast<Constant>(V))
         return ConstantExpr::getBitCast(C, PF1);
@@ -533,9 +533,13 @@ static Value *getExistingValue(const Type *Ty, const ValID &D) {
       return ConstantInt::get(Ty, D.UConstPool64);
 
   case ValID::ConstFPVal:        // Is it a floating point const pool reference?
-    if (!ConstantFP::isValueValidForType(Ty, D.ConstPoolFP))
+    if (!ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP))
       error("FP constant invalid for type");
-    return ConstantFP::get(Ty, D.ConstPoolFP);
+    // Lexer has no type info, so builds all FP constants as double.
+    // Fix this here.
+    if (Ty==Type::FloatTy)
+      D.ConstPoolFP->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
+    return ConstantFP::get(Ty, *D.ConstPoolFP);
 
   case ValID::ConstNullVal:      // Is it a null value?
     if (!isa<PointerType>(Ty))
@@ -774,7 +778,8 @@ static void ResolveTypeTo(char *Name, const Type *ToTy, const Signedness& Sign){
     D = ValID::create((int)CurModule.Types.size());
   D.S.copy(Sign);
 
-  CurModule.NamedTypeSigns[Name] = Sign;
+  if (Name)
+    CurModule.NamedTypeSigns[Name] = Sign;
 
   std::map<ValID, PATypeHolder>::iterator I =
     CurModule.LateResolveTypes.find(D);
@@ -933,8 +938,9 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
   // of this global in the module and emit warnings if there are conflicts.
   if (!Name.empty()) {
     // The global has a name. See if there's an existing one of the same name.
-    if (CurModule.CurrentModule->getNamedGlobal(Name)) {
-      // We found an existing global ov the same name. This isn't allowed 
+    if (CurModule.CurrentModule->getNamedGlobal(Name) ||
+        CurModule.CurrentModule->getFunction(Name)) {
+      // We found an existing global of the same name. This isn't allowed 
       // in LLVM 2.0. Consequently, we must alter the name of the global so it
       // can at least compile. This can happen because of type planes 
       // There is alread a global of the same name which means there is a
@@ -1458,6 +1464,10 @@ upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
                      std::vector<Value*>& Args) {
 
   std::string Name = ID.Type == ValID::NameVal ? ID.Name : "";
+  if (Name.length() <= 5 || Name[0] != 'l' || Name[1] != 'l' || 
+      Name[2] != 'v' || Name[3] != 'm' || Name[4] != '.')
+    return 0;
+
   switch (Name[5]) {
     case 'i':
       if (Name == "llvm.isunordered.f32" || Name == "llvm.isunordered.f64") {
@@ -1466,34 +1476,6 @@ upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
         return new FCmpInst(FCmpInst::FCMP_UNO, Args[0], Args[1]);
       }
       break;
-    case 'b':
-      if (Name.length() == 14 && !memcmp(&Name[5], "bswap.i", 7)) {
-        const Type* ArgTy = Args[0]->getType();
-        Name += ".i" + utostr(cast<IntegerType>(ArgTy)->getBitWidth());
-        Function *F = cast<Function>(
-          CurModule.CurrentModule->getOrInsertFunction(Name, RetTy, ArgTy, 
-                                                       (void*)0));
-        return new CallInst(F, Args[0]);
-      }
-      break;
-    case 'c':
-      if ((Name.length() <= 14 && !memcmp(&Name[5], "ctpop.i", 7)) ||
-          (Name.length() <= 13 && !memcmp(&Name[5], "ctlz.i", 6)) ||
-          (Name.length() <= 13 && !memcmp(&Name[5], "cttz.i", 6))) {
-        // These intrinsics changed their result type.
-        const Type* ArgTy = Args[0]->getType();
-        Function *OldF = CurModule.CurrentModule->getFunction(Name);
-        if (OldF)
-          OldF->setName("upgrd.rm." + Name);
-
-        Function *NewF = cast<Function>(
-          CurModule.CurrentModule->getOrInsertFunction(Name, Type::Int32Ty, 
-                                                       ArgTy, (void*)0));
-
-        Instruction *Call = new CallInst(NewF, Args[0], "", CurBB);
-        return CastInst::createIntegerCast(Call, RetTy, false);
-      }
-      break;
 
     case 'v' : {
       const Type* PtrTy = PointerType::get(Type::Int8Ty);
@@ -1507,7 +1489,7 @@ upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
         const PointerType *PFTy = PointerType::get(FTy);
         Value* Func = getVal(PFTy, ID);
         Args[0] = new BitCastInst(Args[0], PtrTy, makeNameUnique("va"), CurBB);
-        return new CallInst(Func, &Args[0], Args.size());
+        return new CallInst(Func, Args.begin(), Args.end());
       } else if (Name == "llvm.va_copy") {
         if (Args.size() != 2)
           error("Invalid prototype for " + Name + " prototype");
@@ -1521,63 +1503,92 @@ upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
         std::string InstName1(makeNameUnique("va1"));
         Args[0] = new BitCastInst(Args[0], PtrTy, InstName0, CurBB);
         Args[1] = new BitCastInst(Args[1], PtrTy, InstName1, CurBB);
-        return new CallInst(Func, &Args[0], Args.size());
+        return new CallInst(Func, Args.begin(), Args.end());
       }
     }
   }
   return 0;
 }
 
-const Type* upgradeGEPIndices(const Type* PTy, 
-                       std::vector<ValueInfo> *Indices, 
-                       std::vector<Value*>    &VIndices, 
-                       std::vector<Constant*> *CIndices = 0) {
-  // Traverse the indices with a gep_type_iterator so we can build the list
-  // of constant and value indices for use later. Also perform upgrades
-  VIndices.clear();
-  if (CIndices) CIndices->clear();
-  for (unsigned i = 0, e = Indices->size(); i != e; ++i)
-    VIndices.push_back((*Indices)[i].V);
-  generic_gep_type_iterator<std::vector<Value*>::iterator>
-    GTI = gep_type_begin(PTy, VIndices.begin(),  VIndices.end()),
-    GTE = gep_type_end(PTy,  VIndices.begin(),  VIndices.end());
-  for (unsigned i = 0, e = Indices->size(); i != e && GTI != GTE; ++i, ++GTI) {
-    Value *Index = VIndices[i];
-    if (CIndices && !isa<Constant>(Index))
-      error("Indices to constant getelementptr must be constants");
-    // LLVM 1.2 and earlier used ubyte struct indices.  Convert any ubyte 
-    // struct indices to i32 struct indices with ZExt for compatibility.
-    else if (isa<StructType>(*GTI)) {        // Only change struct indices
-      if (ConstantInt *CUI = dyn_cast<ConstantInt>(Index))
-        if (CUI->getType()->getBitWidth() == 8)
-          Index = 
-            ConstantExpr::getCast(Instruction::ZExt, CUI, Type::Int32Ty);
+const Type* upgradeGEPCEIndices(const Type* PTy, 
+                                std::vector<ValueInfo> *Indices, 
+                                std::vector<Constant*> &Result) {
+  const Type *Ty = PTy;
+  Result.clear();
+  for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
+    Constant *Index = cast<Constant>((*Indices)[i].V);
+
+    if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
+      // LLVM 1.2 and earlier used ubyte struct indices.  Convert any ubyte 
+      // struct indices to i32 struct indices with ZExt for compatibility.
+      if (CI->getBitWidth() < 32)
+        Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
+    }
+    
+    if (isa<SequentialType>(Ty)) {
+      // Make sure that unsigned SequentialType indices are zext'd to 
+      // 64-bits if they were smaller than that because LLVM 2.0 will sext 
+      // all indices for SequentialType elements. We must retain the same 
+      // semantic (zext) for unsigned types.
+      if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
+        if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
+          Index = ConstantExpr::getCast(Instruction::ZExt, Index,Type::Int64Ty);
+        }
+      }
+    }
+    Result.push_back(Index);
+    Ty = GetElementPtrInst::getIndexedType(PTy, Result.begin(), 
+                                           Result.end(),true);
+    if (!Ty)
+      error("Index list invalid for constant getelementptr");
+  }
+  return Ty;
+}
+
+const Type* upgradeGEPInstIndices(const Type* PTy, 
+                                  std::vector<ValueInfo> *Indices, 
+                                  std::vector<Value*>    &Result) {
+  const Type *Ty = PTy;
+  Result.clear();
+  for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
+    Value *Index = (*Indices)[i].V;
+
+    if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
+      // LLVM 1.2 and earlier used ubyte struct indices.  Convert any ubyte 
+      // struct indices to i32 struct indices with ZExt for compatibility.
+      if (CI->getBitWidth() < 32)
+        Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
+    }
+    
+
+    if (isa<StructType>(Ty)) {        // Only change struct indices
+      if (!isa<Constant>(Index)) {
+        error("Invalid non-constant structure index");
+        return 0;
+      }
     } else {
       // Make sure that unsigned SequentialType indices are zext'd to 
       // 64-bits if they were smaller than that because LLVM 2.0 will sext 
       // all indices for SequentialType elements. We must retain the same 
       // semantic (zext) for unsigned types.
-      if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType()))
+      if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
         if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
-          if (CIndices)
+          if (isa<Constant>(Index))
             Index = ConstantExpr::getCast(Instruction::ZExt, 
               cast<Constant>(Index), Type::Int64Ty);
           else
             Index = CastInst::create(Instruction::ZExt, Index, Type::Int64Ty,
               makeNameUnique("gep"), CurBB);
-          VIndices[i] = Index;
         }
+      }
     }
-    // Add to the CIndices list, if requested.
-    if (CIndices)
-      CIndices->push_back(cast<Constant>(Index));
-  }
-
-  const Type *IdxTy =
-    GetElementPtrInst::getIndexedType(PTy, &VIndices[0], VIndices.size(), true);
-    if (!IdxTy)
+    Result.push_back(Index);
+    Ty = GetElementPtrInst::getIndexedType(PTy, Result.begin(),
+                                           Result.end(),true);
+    if (!Ty)
       error("Index list invalid for constant getelementptr");
-  return IdxTy;
+  }
+  return Ty;
 }
 
 unsigned upgradeCallingConv(unsigned CC) {
@@ -1717,11 +1728,13 @@ Module* UpgradeAssembly(const std::string &infile, std::istream& in,
 
       while (!F->use_empty()) {
         CallInst* CI = cast<CallInst>(F->use_back());
-        AllocaInst* a = new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI);
-        AllocaInst* b = new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI);
-        new StoreInst(CI->getOperand(1), b, CI);
-        new CallInst(NF, a, b, "", CI);
-        Value* foo = new LoadInst(a, "vacopy.fix.3", CI);
+        Value *Args[2] = {
+          new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI),
+          new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI)         
+        };
+        new StoreInst(CI->getOperand(1), Args[1], CI);
+        new CallInst(NF, Args, Args + 2, "", CI);
+        Value* foo = new LoadInst(Args[0], "vacopy.fix.3", CI);
         CI->replaceAllUsesWith(foo);
         CI->getParent()->getInstList().erase(CI);
       }
@@ -1764,7 +1777,7 @@ using namespace llvm;
   uint64_t                          UInt64Val;
   int                               SIntVal;
   unsigned                          UIntVal;
-  double                            FPVal;
+  llvm::APFloat                    *FPVal;
   bool                              BoolVal;
 
   char                             *StrVal;   // This memory is strdup'd!
@@ -1976,17 +1989,17 @@ OptLinkage
   ;
 
 OptCallingConv 
-  : /*empty*/          { $$ = OldCallingConv::C; } 
-  | CCC_TOK            { $$ = OldCallingConv::C; } 
-  | CSRETCC_TOK        { $$ = OldCallingConv::CSRet; } 
-  | FASTCC_TOK         { $$ = OldCallingConv::Fast; } 
-  | COLDCC_TOK         { $$ = OldCallingConv::Cold; } 
-  | X86_STDCALLCC_TOK  { $$ = OldCallingConv::X86_StdCall; } 
-  | X86_FASTCALLCC_TOK { $$ = OldCallingConv::X86_FastCall; } 
+  : /*empty*/          { $$ = lastCallingConv = OldCallingConv::C; } 
+  | CCC_TOK            { $$ = lastCallingConv = OldCallingConv::C; } 
+  | CSRETCC_TOK        { $$ = lastCallingConv = OldCallingConv::CSRet; } 
+  | FASTCC_TOK         { $$ = lastCallingConv = OldCallingConv::Fast; } 
+  | COLDCC_TOK         { $$ = lastCallingConv = OldCallingConv::Cold; } 
+  | X86_STDCALLCC_TOK  { $$ = lastCallingConv = OldCallingConv::X86_StdCall; } 
+  | X86_FASTCALLCC_TOK { $$ = lastCallingConv = OldCallingConv::X86_FastCall; } 
   | CC_TOK EUINT64VAL  {
     if ((unsigned)$2 != $2)
       error("Calling conv too large");
-    $$ = $2;
+    $$ = lastCallingConv = $2;
   }
   ;
 
@@ -2116,8 +2129,17 @@ UpRTypes
     bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
     if (isVarArg) Params.pop_back();
 
+    ParamAttrsList *PAL = 0;
+    if (lastCallingConv == OldCallingConv::CSRet) {
+      ParamAttrsVector Attrs;
+      ParamAttrsWithIndex PAWI;
+      PAWI.index = 1;  PAWI.attrs = ParamAttr::StructRet; // first arg
+      Attrs.push_back(PAWI);
+      PAL = ParamAttrsList::get(Attrs);
+    }
+
     const FunctionType *FTy =
-      FunctionType::get($1.PAT->get(), Params, isVarArg, 0);
+      FunctionType::get($1.PAT->get(), Params, isVarArg, PAL);
 
     $$.PAT = new PATypeHolder( HandleUpRefs(FTy, $$.S) );
     delete $1.PAT;  // Delete the return type handle
@@ -2496,9 +2518,14 @@ ConstVal
     $$.S.makeUnsigned();
   }
   | FPType FPVAL {                   // Float & Double constants
-    if (!ConstantFP::isValueValidForType($1.T, $2))
+    if (!ConstantFP::isValueValidForType($1.T, *$2))
       error("Floating point constant invalid for type");
-    $$.C = ConstantFP::get($1.T, $2);
+    // Lexer has no type info, so builds all FP constants as double.
+    // Fix this here.
+    if ($1.T==Type::FloatTy)
+      $2->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
+    $$.C = ConstantFP::get($1.T, *$2);
+    delete $2;
     $$.S.makeSignless();
   }
   ;
@@ -2524,9 +2551,8 @@ ConstExpr
     if (!isa<PointerType>(Ty))
       error("GetElementPtr requires a pointer operand");
 
-    std::vector<Value*> VIndices;
     std::vector<Constant*> CIndices;
-    upgradeGEPIndices($3.C->getType(), $4, VIndices, &CIndices);
+    upgradeGEPCEIndices($3.C->getType(), $4, CIndices);
 
     delete $4;
     $$.C = ConstantExpr::getGetElementPtr($3.C, &CIndices[0], CIndices.size());
@@ -2901,15 +2927,17 @@ FunctionHeaderH
 
     // Convert the CSRet calling convention into the corresponding parameter
     // attribute.
-    ParamAttrsList *ParamAttrs = 0;
+    ParamAttrsList *PAL = 0;
     if ($1 == OldCallingConv::CSRet) {
-      ParamAttrs = new ParamAttrsList();
-      ParamAttrs->addAttributes(0, NoAttributeSet);     // result
-      ParamAttrs->addAttributes(1, StructRetAttribute); // first arg
+      ParamAttrsVector Attrs;
+      ParamAttrsWithIndex PAWI;
+      PAWI.index = 1;  PAWI.attrs = ParamAttr::StructRet; // first arg
+      Attrs.push_back(PAWI);
+      PAL = ParamAttrsList::get(Attrs);
     }
 
     const FunctionType *FT = 
-      FunctionType::get(RetTy, ParamTyList, isVarArg, ParamAttrs);
+      FunctionType::get(RetTy, ParamTyList, isVarArg, PAL);
     const PointerType *PFT = PointerType::get(FT);
     delete $2.PAT;
 
@@ -2971,7 +2999,7 @@ FunctionHeaderH
               AI->setName("");
         }
       } else if (Conflict) {
-        // We have two globals with the same name and  different types. 
+        // We have two globals with the same name and different types. 
         // Previously, this was permitted because the symbol table had 
         // "type planes" and names only needed to be distinct within a 
         // type plane. After PR411 was fixed, this is no loner the case. 
@@ -3005,8 +3033,13 @@ FunctionHeaderH
         Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
         InsertValue(Fn, CurModule.Values);
       }
+    } else {
+      // There's no conflict, just define the function
+      Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
+      InsertValue(Fn, CurModule.Values);
     }
 
+
     CurFun.FunctionStart(Fn);
 
     if (CurFun.isDeclare) {
@@ -3042,6 +3075,7 @@ FunctionHeaderH
       }
       delete $5;                     // We're now done with the argument list
     }
+    lastCallingConv = OldCallingConv::C;
   }
   ;
 
@@ -3290,15 +3324,17 @@ BBTerminatorInst
           FTySign.add(I->S);
         }
       }
-      ParamAttrsList *ParamAttrs = 0;
+      ParamAttrsList *PAL = 0;
       if ($2 == OldCallingConv::CSRet) {
-        ParamAttrs = new ParamAttrsList();
-        ParamAttrs->addAttributes(0, NoAttributeSet);      // Function result
-        ParamAttrs->addAttributes(1, StructRetAttribute);  // first param
+        ParamAttrsVector Attrs;
+        ParamAttrsWithIndex PAWI;
+        PAWI.index = 1;  PAWI.attrs = ParamAttr::StructRet; // first arg
+        Attrs.push_back(PAWI);
+        PAL = ParamAttrsList::get(Attrs);
       }
       bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
       if (isVarArg) ParamTypes.pop_back();
-      Ty = FunctionType::get($3.PAT->get(), ParamTypes, isVarArg, ParamAttrs);
+      Ty = FunctionType::get($3.PAT->get(), ParamTypes, isVarArg, PAL);
       PFTy = PointerType::get(Ty);
       $$.S.copy($3.S);
     } else {
@@ -3316,7 +3352,8 @@ BBTerminatorInst
 
     // Create the call node...
     if (!$6) {                                   // Has no arguments?
-      $$.TI = new InvokeInst(V, Normal, Except, 0, 0);
+      std::vector<Value*> Args;
+      $$.TI = new InvokeInst(V, Normal, Except, Args.begin(), Args.end());
     } else {                                     // Has arguments?
       // Loop through FunctionType's arguments and ensure they are specified
       // correctly!
@@ -3336,11 +3373,12 @@ BBTerminatorInst
       if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
         error("Invalid number of parameters detected");
 
-      $$.TI = new InvokeInst(V, Normal, Except, &Args[0], Args.size());
+      $$.TI = new InvokeInst(V, Normal, Except, Args.begin(), Args.end());
     }
     cast<InvokeInst>($$.TI)->setCallingConv(upgradeCallingConv($2));
     delete $3.PAT;
     delete $6;
+    lastCallingConv = OldCallingConv::C;
   }
   | Unwind {
     $$.TI = new UnwindInst();
@@ -3695,14 +3733,16 @@ InstVal
         error("Functions cannot return aggregate types");
 
       // Deal with CSRetCC
-      ParamAttrsList *ParamAttrs = 0;
+      ParamAttrsList *PAL = 0;
       if ($2 == OldCallingConv::CSRet) {
-        ParamAttrs = new ParamAttrsList();
-        ParamAttrs->addAttributes(0, NoAttributeSet);     // function result
-        ParamAttrs->addAttributes(1, StructRetAttribute); // first parameter
+        ParamAttrsVector Attrs;
+        ParamAttrsWithIndex PAWI;
+        PAWI.index = 1;  PAWI.attrs = ParamAttr::StructRet; // first arg
+        Attrs.push_back(PAWI);
+        PAL = ParamAttrsList::get(Attrs);
       }
 
-      FTy = FunctionType::get(RetTy, ParamTypes, isVarArg, ParamAttrs);
+      FTy = FunctionType::get(RetTy, ParamTypes, isVarArg, PAL);
       PFTy = PointerType::get(FTy);
       $$.S.copy($3.S);
     } else {
@@ -3751,13 +3791,14 @@ InstVal
       }
 
       // Create the call instruction
-      CallInst *CI = new CallInst(V, &Args[0], Args.size());
+      CallInst *CI = new CallInst(V, Args.begin(), Args.end());
       CI->setTailCall($1);
       CI->setCallingConv(upgradeCallingConv($2));
       $$.I = CI;
     }
     delete $3.PAT;
     delete $6;
+    lastCallingConv = OldCallingConv::C;
   }
   | MemoryInst {
     $$ = $1;
@@ -3856,10 +3897,10 @@ MemoryInst
       error("getelementptr insn requires pointer operand");
 
     std::vector<Value*> VIndices;
-    upgradeGEPIndices(Ty, $4, VIndices);
+    upgradeGEPInstIndices(Ty, $4, VIndices);
 
     Value* tmpVal = getVal(Ty, $3);
-    $$.I = new GetElementPtrInst(tmpVal, &VIndices[0], VIndices.size());
+    $$.I = new GetElementPtrInst(tmpVal, VIndices.begin(), VIndices.end());
     ValueInfo VI; VI.V = tmpVal; VI.S.copy($2.S);
     $$.S.copy(getElementSign(VI, VIndices));
     delete $2.PAT;