]> granicus.if.org Git - clang/commitdiff
Evaluation of unary deref could call integer evaluator on non-integral
authorDaniel Dunbar <daniel@zuster.org>
Sat, 21 Feb 2009 18:14:20 +0000 (18:14 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 21 Feb 2009 18:14:20 +0000 (18:14 +0000)
expr; hilarity ensued.
 - PR3640.

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

lib/AST/ExprConstant.cpp
test/Sema/const-eval.c

index 64d3fdd8a7303de32d15448967ab4c6d26b88940..e3c48091b5e6d50c10ac97e9527372dae694d77f 100644 (file)
@@ -490,6 +490,7 @@ public:
   }
 
   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 @@ public:
   }
 
   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 @@ public:
   }
 
   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 @@ bool IntExprEvaluator::VisitUnaryOperator(const UnaryOperator *E) {
     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;
index 30075d5c77bd5ecc3f5a031aace3a9b8508c7f0c..aebcb6a3fd8ac6ad662bad4b3bbfa4d892d40ae6 100644 (file)
@@ -40,3 +40,5 @@ struct s {
 };
 
 EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1));
+
+EVAL_EXPR(20, __builtin_constant_p(*((int*) 10), -1, 1));