]> granicus.if.org Git - clang/commitdiff
fix codegen of pre/post inc/dec of a pointer.
authorChris Lattner <sabre@nondot.org>
Sun, 26 Aug 2007 05:10:16 +0000 (05:10 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 26 Aug 2007 05:10:16 +0000 (05:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41425 91177308-0d34-0410-b5e6-96231b3b80d8

CodeGen/CGExprScalar.cpp

index 889842e1c81828cb764f00d03d2a44d4a1d95e68..91e76aaf84f682871062ecd7972b10cf061a27e9 100644 (file)
@@ -314,19 +314,24 @@ Value *ScalarExprEmitter::VisitPrePostIncDec(const UnaryOperator *E,
                                              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,