diff options
| author | Chris Lattner <sabre@nondot.org> | 2010-06-26 22:18:28 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2010-06-26 22:18:28 +0000 |
| commit | 431bef44098ad37188c0f692b28e683d37a79e0f (patch) | |
| tree | d3423f1c0ff16758aadcdc46734bc35458aae19f /clang/lib/CodeGen/CGExprScalar.cpp | |
| parent | 05dc78c0965caae4c19ad318a1690c70a51156d7 (diff) | |
| download | bcm5719-llvm-431bef44098ad37188c0f692b28e683d37a79e0f.tar.gz bcm5719-llvm-431bef44098ad37188c0f692b28e683d37a79e0f.zip | |
fix inc/dec to honor -fwrapv and -ftrapv, implementing PR7426.
llvm-svn: 106962
Diffstat (limited to 'clang/lib/CodeGen/CGExprScalar.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CGExprScalar.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 63d14f0e53b..208e1a6c896 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -1179,11 +1179,27 @@ EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, } else if (isa<llvm::IntegerType>(InVal->getType())) { NextVal = llvm::ConstantInt::get(InVal->getType(), AmountVal); - // Signed integer overflow is undefined behavior. - if (ValTy->isSignedIntegerType()) - NextVal = Builder.CreateNSWAdd(InVal, NextVal, isInc ? "inc" : "dec"); - else + 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 = BinaryOperator::Add; + BinOp.E = E; + return EmitOverflowCheckedBinOp(BinOp); + } + } } else { // Add the inc/dec to the real part. if (InVal->getType()->isFloatTy()) |

