[cfe-commits] r41425 - /cfe/trunk/CodeGen/CGExprScalar.cpp
Chris Lattner
sabre at nondot.org
Sat Aug 25 22:10:16 PDT 2007
Author: lattner
Date: Sun Aug 26 00:10:16 2007
New Revision: 41425
URL: http://llvm.org/viewvc/llvm-project?rev=41425&view=rev
Log:
fix codegen of pre/post inc/dec of a pointer.
Modified:
cfe/trunk/CodeGen/CGExprScalar.cpp
Modified: cfe/trunk/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprScalar.cpp?rev=41425&r1=41424&r2=41425&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/CodeGen/CGExprScalar.cpp Sun Aug 26 00:10:16 2007
@@ -314,19 +314,24 @@
bool isInc, bool isPre) {
LValue LV = EmitLValue(E->getSubExpr());
// FIXME: Handle volatile!
- Value *InVal = CGF.EmitLoadOfLValue(LV/* false*/,
- E->getSubExpr()->getType()).getVal();
+ Value *InVal = CGF.EmitLoadOfLValue(LV, // false
+ E->getSubExpr()->getType()).getVal();
int AmountVal = isInc ? 1 : -1;
Value *NextVal;
- if (isa<llvm::IntegerType>(InVal->getType()))
- NextVal = llvm::ConstantInt::get(InVal->getType(), AmountVal);
- else
- NextVal = llvm::ConstantFP::get(InVal->getType(), AmountVal);
-
- // Add the inc/dec to the real part.
- NextVal = Builder.CreateAdd(InVal, NextVal, isInc ? "inc" : "dec");
+ if (isa<llvm::PointerType>(InVal->getType())) {
+ // FIXME: This isn't right for VLAs.
+ NextVal = llvm::ConstantInt::get(llvm::Type::Int32Ty, AmountVal);
+ NextVal = Builder.CreateGEP(InVal, NextVal);
+ } else {
+ // Add the inc/dec to the real part.
+ if (isa<llvm::IntegerType>(InVal->getType()))
+ NextVal = llvm::ConstantInt::get(InVal->getType(), AmountVal);
+ else
+ NextVal = llvm::ConstantFP::get(InVal->getType(), AmountVal);
+ NextVal = Builder.CreateAdd(InVal, NextVal, isInc ? "inc" : "dec");
+ }
// Store the updated result through the lvalue.
CGF.EmitStoreThroughLValue(RValue::get(NextVal), LV,
More information about the cfe-commits
mailing list