diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 71 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 2 |
2 files changed, 50 insertions, 23 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 57627be9e3..a46dda94f7 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -302,6 +302,11 @@ public: return EmitScalarPrePostIncDec(E, LV, true, true); } + llvm::Value *EmitAddConsiderOverflowBehavior(const UnaryOperator *E, + llvm::Value *InVal, + llvm::Value *NextVal, + bool IsInc); + llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre); @@ -1221,6 +1226,31 @@ Value *ScalarExprEmitter::VisitBlockDeclRefExpr(const BlockDeclRefExpr *E) { //===----------------------------------------------------------------------===// llvm::Value *ScalarExprEmitter:: +EmitAddConsiderOverflowBehavior(const UnaryOperator *E, + llvm::Value *InVal, + llvm::Value *NextVal, bool IsInc) { + switch (CGF.getContext().getLangOptions().getSignedOverflowBehavior()) { + case LangOptions::SOB_Undefined: + return Builder.CreateNSWAdd(InVal, NextVal, IsInc ? "inc" : "dec"); + break; + case LangOptions::SOB_Defined: + return Builder.CreateAdd(InVal, NextVal, IsInc ? "inc" : "dec"); + break; + case LangOptions::SOB_Trapping: + BinOpInfo BinOp; + BinOp.LHS = InVal; + BinOp.RHS = NextVal; + BinOp.Ty = E->getType(); + BinOp.Opcode = BO_Add; + BinOp.E = E; + return EmitOverflowCheckedBinOp(BinOp); + break; + } + assert(false && "Unknown SignedOverflowBehaviorTy"); + return 0; +} + +llvm::Value *ScalarExprEmitter:: EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre) { @@ -1269,31 +1299,26 @@ EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, // An interesting aspect of this is that increment is always true. // Decrement does not have this property. NextVal = llvm::ConstantInt::getTrue(VMContext); + } else if (ValTy->isVectorType()) { + if (ValTy->hasIntegerRepresentation()) { + NextVal = llvm::ConstantInt::get(InVal->getType(), AmountVal); + + NextVal = ValTy->hasSignedIntegerRepresentation() ? + EmitAddConsiderOverflowBehavior(E, InVal, NextVal, isInc) : + Builder.CreateAdd(InVal, NextVal, isInc ? "inc" : "dec"); + } else { + NextVal = Builder.CreateFAdd( + InVal, + llvm::ConstantFP::get(InVal->getType(), AmountVal), + isInc ? "inc" : "dec"); + } } else if (isa<llvm::IntegerType>(InVal->getType())) { NextVal = llvm::ConstantInt::get(InVal->getType(), AmountVal); - - if (!ValTy->isSignedIntegerType()) - // Unsigned integer inc is always two's complement. - NextVal = Builder.CreateAdd(InVal, NextVal, isInc ? "inc" : "dec"); - else { - switch (CGF.getContext().getLangOptions().getSignedOverflowBehavior()) { - case LangOptions::SOB_Undefined: - NextVal = Builder.CreateNSWAdd(InVal, NextVal, isInc ? "inc" : "dec"); - break; - case LangOptions::SOB_Defined: - NextVal = Builder.CreateAdd(InVal, NextVal, isInc ? "inc" : "dec"); - break; - case LangOptions::SOB_Trapping: - BinOpInfo BinOp; - BinOp.LHS = InVal; - BinOp.RHS = NextVal; - BinOp.Ty = E->getType(); - BinOp.Opcode = BO_Add; - BinOp.E = E; - NextVal = EmitOverflowCheckedBinOp(BinOp); - break; - } - } + + NextVal = ValTy->isSignedIntegerType() ? + EmitAddConsiderOverflowBehavior(E, InVal, NextVal, isInc) : + // Unsigned integer inc is always two's complement. + Builder.CreateAdd(InVal, NextVal, isInc ? "inc" : "dec"); } else { // Add the inc/dec to the real part. if (InVal->getType()->isFloatTy()) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index a464977779..77c1d29827 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -7183,6 +7183,8 @@ static QualType CheckIncrementDecrementOperand(Sema &S, Expr *Op, if (PR.isInvalid()) return QualType(); return CheckIncrementDecrementOperand(S, PR.take(), VK, OpLoc, isInc, isPrefix); + } else if (S.getLangOptions().AltiVec && ResType->isVectorType()) { + // OK! ( C/C++ Language Extensions for CBEA(Version 2.6) 10.3 ) } else { S.Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement) << ResType << int(isInc) << Op->getSourceRange(); |