aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprScalar.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-11 07:40:06 +0000
committerChris Lattner <sabre@nondot.org>2009-02-11 07:40:06 +0000
commitdb3bd4b4eabc325781a6a407c3dcf68a8d6db0f9 (patch)
tree86d39f57f79fd7f166bb798c8ef6b15c41c5c686 /lib/CodeGen/CGExprScalar.cpp
parente5ed15195b71b8fa440e67d49db0168bb58e4e8a (diff)
Fix rdar://6518463, increment of a bool is always true, due to
subtle and non-obvious promotion rules. We already handle += and +1 correctly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64296 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprScalar.cpp')
-rw-r--r--lib/CodeGen/CGExprScalar.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index a94eef1151..285f0f425b 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -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()))