[cfe-commits] r64296 - /cfe/trunk/lib/CodeGen/CGExprScalar.cpp
Chris Lattner
sabre at nondot.org
Tue Feb 10 23:40:06 PST 2009
Author: lattner
Date: Wed Feb 11 01:40:06 2009
New Revision: 64296
URL: http://llvm.org/viewvc/llvm-project?rev=64296&view=rev
Log:
Fix rdar://6518463, increment of a bool is always true, due to
subtle and non-obvious promotion rules. We already handle +=
and +1 correctly.
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=64296&r1=64295&r2=64296&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Wed Feb 11 01:40:06 2009
@@ -619,6 +619,13 @@
// 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()))
More information about the cfe-commits
mailing list