]> granicus.if.org Git - clang/commitdiff
Fix isIntegerConstantExpr to compare against zero for casts to bool instead of
authorChris Lattner <sabre@nondot.org>
Wed, 9 Jan 2008 18:59:34 +0000 (18:59 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 9 Jan 2008 18:59:34 +0000 (18:59 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45779 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp

index 726e4939cc7ec6779f707f591569d0001883a3e4..159122156fba68d7f74f7668be7aca6d5a214356 100644 (file)
@@ -846,7 +846,11 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
       
       // 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 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
       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();