[opaque pointer type] Constant Folding: Use GEPOperator to access the pointee source...
authorDavid Blaikie <dblaikie@gmail.com>
Wed, 13 May 2015 18:35:29 +0000 (18:35 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Wed, 13 May 2015 18:35:29 +0000 (18:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237274 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/ConstantFold.cpp

index 8afb3e489de266927bfbc355eb817dc6787574e6..ec3414d25308b12e9b505cba77defcdc55e71250 100644 (file)
@@ -632,8 +632,8 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
     if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
       if (CE->getOpcode() == Instruction::GetElementPtr &&
           CE->getOperand(0)->isNullValue()) {
-        Type *Ty =
-          cast<PointerType>(CE->getOperand(0)->getType())->getElementType();
+        GEPOperator *GEPO = cast<GEPOperator>(CE);
+        Type *Ty = GEPO->getSourceElementType();
         if (CE->getNumOperands() == 2) {
           // Handle a sizeof-like expression.
           Constant *Idx = CE->getOperand(1);