Update GEP constructors to use an iterator interface to fix
GLIBCXX_DEBUG issues.

llvm-svn: 41697
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp
index c950e8d..fb2e65f 100644
--- a/llvm/lib/VMCore/ConstantFold.cpp
+++ b/llvm/lib/VMCore/ConstantFold.cpp
@@ -1350,7 +1350,7 @@
 }
 
 Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
-                                          Constant* const *Idxs, 
+                                          Constant* const *Idxs,
                                           unsigned NumIdx) {
   if (NumIdx == 0 ||
       (NumIdx == 1 && Idxs[0]->isNullValue()))
@@ -1358,7 +1358,8 @@
 
   if (isa<UndefValue>(C)) {
     const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(),
-                                                       (Value**)Idxs, NumIdx,
+                                                       (Value **)Idxs,
+                                                       (Value **)Idxs+NumIdx,
                                                        true);
     assert(Ty != 0 && "Invalid indices for GEP!");
     return UndefValue::get(PointerType::get(Ty));
@@ -1374,7 +1375,8 @@
       }
     if (isNull) {
       const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(),
-                                                         (Value**)Idxs, NumIdx,
+                                                         (Value**)Idxs,
+                                                         (Value**)Idxs+NumIdx,
                                                          true);
       assert(Ty != 0 && "Invalid indices for GEP!");
       return ConstantPointerNull::get(PointerType::get(Ty));
diff --git a/llvm/lib/VMCore/ConstantFold.h b/llvm/lib/VMCore/ConstantFold.h
index e01fa77..ffb7b10 100644
--- a/llvm/lib/VMCore/ConstantFold.h
+++ b/llvm/lib/VMCore/ConstantFold.h
@@ -19,6 +19,8 @@
 #ifndef CONSTANTFOLDING_H
 #define CONSTANTFOLDING_H
 
+#include <iterator>
+
 namespace llvm {
   class Value;
   class Constant;
@@ -46,6 +48,7 @@
   Constant *ConstantFoldCompareInstruction(unsigned short predicate, 
                                            const Constant *C1, 
                                            const Constant *C2);
+
   Constant *ConstantFoldGetElementPtr(const Constant *C,
                                       Constant* const *Idxs, unsigned NumIdx);
 } // End llvm namespace
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index 8e3d946..f7cbe82 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -1799,7 +1799,7 @@
 Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C,
                                            Value* const *Idxs,
                                            unsigned NumIdx) {
-  assert(GetElementPtrInst::getIndexedType(C->getType(), Idxs, NumIdx, true) &&
+  assert(GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx, true) &&
          "GEP indices invalid!");
 
   if (Constant *FC = ConstantFoldGetElementPtr(C, (Constant**)Idxs, NumIdx))
@@ -1821,7 +1821,7 @@
                                          unsigned NumIdx) {
   // Get the result type of the getelementptr!
   const Type *Ty = 
-    GetElementPtrInst::getIndexedType(C->getType(), Idxs, NumIdx, true);
+    GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx, true);
   assert(Ty && "GEP indices invalid!");
   return getGetElementPtrTy(PointerType::get(Ty), C, Idxs, NumIdx);
 }
diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp
index bb11a4b..369e98a 100644
--- a/llvm/lib/VMCore/Instructions.cpp
+++ b/llvm/lib/VMCore/Instructions.cpp
@@ -864,14 +864,6 @@
 //                       GetElementPtrInst Implementation
 //===----------------------------------------------------------------------===//
 
-// checkType - Simple wrapper function to give a better assertion failure
-// message on bad indexes for a gep instruction.
-//
-static inline const Type *checkType(const Type *Ty) {
-  assert(Ty && "Invalid GetElementPtrInst indices for type!");
-  return Ty;
-}
-
 void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx) {
   NumOperands = 1+NumIdx;
   Use *OL = OperandList = new Use[NumOperands];
@@ -881,14 +873,6 @@
     OL[i+1].init(Idx[i], this);
 }
 
-void GetElementPtrInst::init(Value *Ptr, Value *Idx0, Value *Idx1) {
-  NumOperands = 3;
-  Use *OL = OperandList = new Use[3];
-  OL[0].init(Ptr, this);
-  OL[1].init(Idx0, this);
-  OL[2].init(Idx1, this);
-}
-
 void GetElementPtrInst::init(Value *Ptr, Value *Idx) {
   NumOperands = 2;
   Use *OL = OperandList = new Use[2];
@@ -896,27 +880,6 @@
   OL[1].init(Idx, this);
 }
 
-
-GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value* const *Idx,
-                                     unsigned NumIdx,
-                                     const std::string &Name, Instruction *InBe)
-: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
-                                                        Idx, NumIdx, true))),
-              GetElementPtr, 0, 0, InBe) {
-  init(Ptr, Idx, NumIdx);
-  setName(Name);
-}
-
-GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value* const *Idx, 
-                                     unsigned NumIdx,
-                                     const std::string &Name, BasicBlock *IAE)
-: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
-                                                        Idx, NumIdx, true))),
-              GetElementPtr, 0, 0, IAE) {
-  init(Ptr, Idx, NumIdx);
-  setName(Name);
-}
-
 GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
                                      const std::string &Name, Instruction *InBe)
   : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),Idx))),
@@ -933,24 +896,6 @@
   setName(Name);
 }
 
-GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
-                                     const std::string &Name, Instruction *InBe)
-  : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
-                                                          Idx0, Idx1, true))),
-                GetElementPtr, 0, 0, InBe) {
-  init(Ptr, Idx0, Idx1);
-  setName(Name);
-}
-
-GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
-                                     const std::string &Name, BasicBlock *IAE)
-  : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
-                                                          Idx0, Idx1, true))),
-                GetElementPtr, 0, 0, IAE) {
-  init(Ptr, Idx0, Idx1);
-  setName(Name);
-}
-
 GetElementPtrInst::~GetElementPtrInst() {
   delete[] OperandList;
 }
@@ -999,24 +944,6 @@
   return CurIdx == NumIdx ? Ptr : 0;
 }
 
-const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
-                                              Value *Idx0, Value *Idx1,
-                                              bool AllowCompositeLeaf) {
-  const PointerType *PTy = dyn_cast<PointerType>(Ptr);
-  if (!PTy) return 0;   // Type isn't a pointer type!
-
-  // Check the pointer index.
-  if (!PTy->indexValid(Idx0)) return 0;
-
-  const CompositeType *CT = dyn_cast<CompositeType>(PTy->getElementType());
-  if (!CT || !CT->indexValid(Idx1)) return 0;
-
-  const Type *ElTy = CT->getTypeAtIndex(Idx1);
-  if (AllowCompositeLeaf || ElTy->isFirstClassType())
-    return ElTy;
-  return 0;
-}
-
 const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) {
   const PointerType *PTy = dyn_cast<PointerType>(Ptr);
   if (!PTy) return 0;   // Type isn't a pointer type!
diff --git a/llvm/lib/VMCore/Verifier.cpp b/llvm/lib/VMCore/Verifier.cpp
index 49f6abd..58bf485 100644
--- a/llvm/lib/VMCore/Verifier.cpp
+++ b/llvm/lib/VMCore/Verifier.cpp
@@ -913,7 +913,7 @@
   SmallVector<Value*, 16> Idxs(GEP.idx_begin(), GEP.idx_end());
   const Type *ElTy =
     GetElementPtrInst::getIndexedType(GEP.getOperand(0)->getType(),
-                                      &Idxs[0], Idxs.size(), true);
+                                      Idxs.begin(), Idxs.end(), true);
   Assert1(ElTy, "Invalid indices for GEP pointer type!", &GEP);
   Assert2(isa<PointerType>(GEP.getType()) &&
           cast<PointerType>(GEP.getType())->getElementType() == ElTy,