[cfe-commits] r59938 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/Sema/const-eval.c

Anders Carlsson andersca at mac.com
Sun Nov 23 20:21:44 PST 2008


Author: andersca
Date: Sun Nov 23 22:21:33 2008
New Revision: 59938

URL: http://llvm.org/viewvc/llvm-project?rev=59938&view=rev
Log:
Fix bug in the constant evaluator. Fixes PR3115.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/test/Sema/const-eval.c

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=59938&r1=59937&r2=59938&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sun Nov 23 22:21:33 2008
@@ -505,14 +505,12 @@
     Result = EvaluateBuiltinClassifyType(E);
     return true;
     
-  case Builtin::BI__builtin_constant_p: {
+  case Builtin::BI__builtin_constant_p:
     // __builtin_constant_p always has one operand: it returns true if that
     // operand can be folded, false otherwise.
-    APValue Res;
-    Result = E->getArg(0)->Evaluate(Res, Info.Ctx);
+    Result = E->getArg(0)->isEvaluatable(Info.Ctx);
     return true;
   }
-  }
 }
 
 bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
@@ -537,43 +535,45 @@
     // These need to be handled specially because the operands aren't
     // necessarily integral
     bool bres;
-    bool isEvaluated = true;
     
     if (HandleConversionToBool(E->getLHS(), bres, Info)) {
       // We were able to evaluate the LHS, see if we can get away with not
       // evaluating the RHS: 0 && X -> 0, 1 || X -> 1
-    } else {
-      // We can't evaluate the LHS; however, sometimes the result
-      // is determined by the RHS: X && 0 -> 0, X || 1 -> 1.
-      if (!HandleConversionToBool(E->getRHS(), bres, Info)) {
-        // We can't evaluate.
-        return false;
+      if (bres == (E->getOpcode() == BinaryOperator::LOr) || 
+          !bres == (E->getOpcode() == BinaryOperator::LAnd)) {
+        Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+        Result.setIsUnsigned(E->getType()->isUnsignedIntegerType());
+        Result = bres;
+        
+        return true;
       }
-      
-      // We did not evaluate the LHS
-      isEvaluated = false;
-    }
 
-    if (bres == (E->getOpcode() == BinaryOperator::LOr) ||
-        !bres == (E->getOpcode() == BinaryOperator::LAnd)) {
-      Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
-      Result.setIsUnsigned(E->getType()->isUnsignedIntegerType());
-      Result = bres;
-      Info.isEvaluated = isEvaluated;
-      
-      return true;
+      bool bres2;
+      if (HandleConversionToBool(E->getRHS(), bres2, Info)) {
+        Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+        Result.setIsUnsigned(E->getType()->isUnsignedIntegerType());
+        if (E->getOpcode() == BinaryOperator::LOr)
+          Result = bres || bres2;
+        else
+          Result = bres && bres2;
+        return true;
+      }
+    } else {
+      if (HandleConversionToBool(E->getRHS(), bres, Info)) {
+        // We can't evaluate the LHS; however, sometimes the result
+        // is determined by the RHS: X && 0 -> 0, X || 1 -> 1.
+        if (bres == (E->getOpcode() == BinaryOperator::LOr) || 
+            !bres == (E->getOpcode() == BinaryOperator::LAnd)) {
+          Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+          Result.setIsUnsigned(E->getType()->isUnsignedIntegerType());
+          Result = bres;
+          Info.isEvaluated = false;
+        
+          return true;
+        }
+      }
     }
 
-    bool bres2;
-    if (HandleConversionToBool(E->getRHS(), bres2, Info)) {
-      Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
-      Result.setIsUnsigned(E->getType()->isUnsignedIntegerType());
-      if (E->getOpcode() == BinaryOperator::LOr)
-        Result = bres || bres2;
-      else
-        Result = bres && bres2;
-      return true;
-    }
     return false;
   }
 

Modified: cfe/trunk/test/Sema/const-eval.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/const-eval.c?rev=59938&r1=59937&r2=59938&view=diff

==============================================================================
--- cfe/trunk/test/Sema/const-eval.c (original)
+++ cfe/trunk/test/Sema/const-eval.c Sun Nov 23 22:21:33 2008
@@ -17,3 +17,6 @@
 EVAL_EXPR(11, (g0(), 12)) // FIXME: This should give an error
 EVAL_EXPR(12, 1.0&&2.0)
 EVAL_EXPR(13, x || 3.0)
+
+unsigned int l_19 = 1;
+EVAL_EXPR(14, (1 ^ l_19) && 1); // expected-error {{fields must have a constant size}}





More information about the cfe-commits mailing list