diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-18 04:25:13 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-18 04:25:13 +0000 |
commit | 8cc9d08eb8b2652ca939d724ab64dec906e418a0 (patch) | |
tree | 20ff05402c728213d950b3f75417a9e5ea6aeec6 /lib/CodeGen | |
parent | c3953a61f7e2a9919ce18d418f8b26a8612e87f2 (diff) |
fix PR3809, codegen for inc/dec of function pointers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67165 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 1a64e3c905..80aa755e18 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -627,10 +627,18 @@ Value *ScalarExprEmitter::VisitPrePostIncDec(const UnaryOperator *E, int AmountVal = isInc ? 1 : -1; Value *NextVal; - if (isa<llvm::PointerType>(InVal->getType())) { + if (const llvm::PointerType *PT = + dyn_cast<llvm::PointerType>(InVal->getType())) { // FIXME: This isn't right for VLAs. - NextVal = llvm::ConstantInt::get(llvm::Type::Int32Ty, AmountVal); - NextVal = Builder.CreateGEP(InVal, NextVal, "ptrincdec"); + llvm::Constant *Inc =llvm::ConstantInt::get(llvm::Type::Int32Ty, AmountVal); + if (!isa<llvm::FunctionType>(PT->getElementType())) { + NextVal = Builder.CreateGEP(InVal, Inc, "ptrincdec"); + } else { + const llvm::Type *i8Ty = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); + NextVal = Builder.CreateBitCast(InVal, i8Ty, "tmp"); + NextVal = Builder.CreateGEP(NextVal, Inc, "ptrincdec"); + NextVal = Builder.CreateBitCast(NextVal, InVal->getType()); + } } else if (InVal->getType() == llvm::Type::Int1Ty && isInc) { // Bool++ is an interesting case, due to promotion rules, we get: // Bool++ -> Bool = Bool+1 -> Bool = (int)Bool+1 -> |