[llvm-commits] [llvm] r78698 - /llvm/trunk/lib/VMCore/Constants.cpp

Daniel Dunbar daniel at zuster.org
Tue Aug 11 11:28:09 PDT 2009


Author: ddunbar
Date: Tue Aug 11 13:28:09 2009
New Revision: 78698

URL: http://llvm.org/viewvc/llvm-project?rev=78698&view=rev
Log:
Simplify ConstantExpr::getInBoundsGetElementPtr and fix a possible crash, if
constant folding eliminated the GEP instruction.
 - clang was hitting this on its test suite (for x86_64, at least).

Modified:
    llvm/trunk/lib/VMCore/Constants.cpp

Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=78698&r1=78697&r2=78698&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Tue Aug 11 13:28:09 2009
@@ -1442,14 +1442,11 @@
 Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C,
                                                  Value* const *Idxs,
                                                  unsigned NumIdx) {
-  // Get the result type of the getelementptr!
-  const Type *Ty =
-    GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx);
-  assert(Ty && "GEP indices invalid!");
-  unsigned As = cast<PointerType>(C->getType())->getAddressSpace();
-  Constant *Result = getGetElementPtrTy(PointerType::get(Ty, As), C,
-                                        Idxs, NumIdx);
-  cast<GEPOperator>(Result)->setIsInBounds(true);
+  Constant *Result = getGetElementPtr(C, Idxs, NumIdx);
+  // Set in bounds attribute, assuming constant folding didn't eliminate the
+  // GEP.
+  if (GEPOperator *GEP = dyn_cast<GEPOperator>(Result))
+    GEP->setIsInBounds(true);
   return Result;
 }
 





More information about the llvm-commits mailing list