Fix rdar://6518463, increment of a bool is always true, due to

subtle and non-obvious promotion rules.  We already handle += 
and +1 correctly.

llvm-svn: 64296
This commit is contained in:
Chris Lattner 2009-02-11 07:40:06 +00:00
parent 60dcdc7062
commit 746b21361f
1 changed files with 7 additions and 0 deletions

View File

@ -619,6 +619,13 @@ Value *ScalarExprEmitter::VisitPrePostIncDec(const UnaryOperator *E,
// FIXME: This isn't right for VLAs.
NextVal = llvm::ConstantInt::get(llvm::Type::Int32Ty, AmountVal);
NextVal = Builder.CreateGEP(InVal, NextVal, "ptrincdec");
} 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 ->
// Bool = ((int)Bool+1) != 0
// An interesting aspect of this is that increment is always true.
// Decrement does not have this property.
NextVal = llvm::ConstantInt::getTrue();
} else {
// Add the inc/dec to the real part.
if (isa<llvm::IntegerType>(InVal->getType()))