From db3bd4b4eabc325781a6a407c3dcf68a8d6db0f9 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 11 Feb 2009 07:40:06 +0000 Subject: [PATCH] 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 --- lib/CodeGen/CGExprScalar.cpp | 7 +++++++ 1 file changed, 7 insertions(+) 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(InVal->getType())) -- 2.40.0