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

Daniel Dunbar daniel at zuster.org
Sat Feb 21 10:14:21 PST 2009


Author: ddunbar
Date: Sat Feb 21 12:14:20 2009
New Revision: 65234

URL: http://llvm.org/viewvc/llvm-project?rev=65234&view=rev
Log:
Evaluation of unary deref could call integer evaluator on non-integral
expr; hilarity ensued.
 - PR3640.

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=65234&r1=65233&r2=65234&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sat Feb 21 12:14:20 2009
@@ -490,6 +490,7 @@
   }
 
   bool Success(const llvm::APSInt &SI, const Expr *E) {
+    assert(E->getType()->isIntegralType() && "Invalid evaluation result.");
     assert(SI.isSigned() == E->getType()->isSignedIntegerType() &&
            "Invalid evaluation result.");
     assert(SI.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) &&
@@ -499,6 +500,7 @@
   }
 
   bool Success(const llvm::APInt &I, const Expr *E) {
+    assert(E->getType()->isIntegralType() && "Invalid evaluation result.");
     assert(I.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) &&
            "Invalid evaluation result.");
     Result = APValue(APSInt(I));
@@ -507,6 +509,7 @@
   }
 
   bool Success(uint64_t Value, const Expr *E) {
+    assert(E->getType()->isIntegralType() && "Invalid evaluation result.");
     Result = APValue(Info.Ctx.MakeIntValue(Value, E->getType()));
     return true;
   }
@@ -1027,6 +1030,10 @@
     return Success(!bres, E);
   }
 
+  // Only handle integral operations...
+  if (!E->getSubExpr()->getType()->isIntegralType())
+    return false;
+
   // Get the operand value into 'Result'.
   if (!Visit(E->getSubExpr()))
     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=65234&r1=65233&r2=65234&view=diff

==============================================================================
--- cfe/trunk/test/Sema/const-eval.c (original)
+++ cfe/trunk/test/Sema/const-eval.c Sat Feb 21 12:14:20 2009
@@ -40,3 +40,5 @@
 };
 
 EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1));
+
+EVAL_EXPR(20, __builtin_constant_p(*((int*) 10), -1, 1));





More information about the cfe-commits mailing list