]> granicus.if.org Git - clang/commitdiff
Fix rdar://6518463, increment of a bool is always true, due to
authorChris Lattner <sabre@nondot.org>
Wed, 11 Feb 2009 07:40:06 +0000 (07:40 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 11 Feb 2009 07:40:06 +0000 (07:40 +0000)
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

lib/CodeGen/CGExprScalar.cpp

index a94eef115117a689ea3a03c4d99e257f7694cc9a..285f0f425b143d4519105b676c578b6c7a54cba2 100644 (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()))