diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-08-05 19:23:29 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-08-05 19:23:29 +0000 |
commit | 6fa08aafcce77c519b19c605c6cb2853ca2a35ea (patch) | |
tree | 5d32e827fb711110209660a230fe71ef9d376bbe /llvm/lib/Analysis/ConstantFolding.cpp | |
parent | 344e25f13b89ab2907c666a5c76d425434d31747 (diff) | |
download | llvm-6fa08aafcce77c519b19c605c6cb2853ca2a35ea.zip llvm-6fa08aafcce77c519b19c605c6cb2853ca2a35ea.tar.gz llvm-6fa08aafcce77c519b19c605c6cb2853ca2a35ea.tar.bz2 |
[ConstantFolding] Don't create illegal (non-integral) inttoptrs
Reviewers: majnemer, arsenm
Subscribers: mcrosier, llvm-commits
Differential Revision: https://reviews.llvm.org/D23182
llvm-svn: 277854
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 39e422f..a7fb10b 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -828,7 +828,9 @@ Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP, } } - if (Ptr->isNullValue() || BasePtr != 0) { + auto *PTy = cast<PointerType>(Ptr->getType()); + if ((Ptr->isNullValue() || BasePtr != 0) && + !DL.isNonIntegralPointerType(PTy)) { Constant *C = ConstantInt::get(Ptr->getContext(), Offset + BasePtr); return ConstantExpr::getIntToPtr(C, ResTy); } @@ -837,8 +839,7 @@ Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP, // we eliminate over-indexing of the notional static type array bounds. // This makes it easy to determine if the getelementptr is "inbounds". // Also, this helps GlobalOpt do SROA on GlobalVariables. - Type *Ty = Ptr->getType(); - assert(Ty->isPointerTy() && "Forming regular GEP of non-pointer type"); + Type *Ty = PTy; SmallVector<Constant *, 32> NewIdxs; do { |