[cfe-commits] r45779 - /cfe/trunk/AST/Expr.cpp
Chris Lattner
sabre at nondot.org
Wed Jan 9 10:59:34 PST 2008
Author: lattner
Date: Wed Jan 9 12:59:34 2008
New Revision: 45779
URL: http://llvm.org/viewvc/llvm-project?rev=45779&view=rev
Log:
Fix isIntegerConstantExpr to compare against zero for casts to bool instead of
truncating. This allows us to compile:
void foo() {
static _Bool foo = 4;
}
into:
@foo1 = internal global i8 1
instead of:
@foo1 = internal global i8 4
Modified:
cfe/trunk/AST/Expr.cpp
Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=45779&r1=45778&r2=45779&view=diff
==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Wed Jan 9 12:59:34 2008
@@ -846,7 +846,11 @@
// Figure out if this is a truncate, extend or noop cast.
// If the input is signed, do a sign extend, noop, or truncate.
- if (SubExpr->getType()->isSignedIntegerType())
+ if (getType()->isBooleanType()) {
+ // Conversion to bool compares against zero.
+ Result = Result != 0;
+ Result.zextOrTrunc(DestWidth);
+ } else if (SubExpr->getType()->isSignedIntegerType())
Result.sextOrTrunc(DestWidth);
else // If the input is unsigned, do a zero extend, noop, or truncate.
Result.zextOrTrunc(DestWidth);
@@ -865,6 +869,13 @@
if (Loc) *Loc = Operand->getLocStart();
return false;
}
+
+ // If the destination is boolean, compare against zero.
+ if (getType()->isBooleanType()) {
+ Result = !FL->getValue().isZero();
+ Result.zextOrTrunc(DestWidth);
+ break;
+ }
// Determine whether we are converting to unsigned or signed.
bool DestSigned = getType()->isSignedIntegerType();
More information about the cfe-commits
mailing list