]> granicus.if.org Git - clang/commitdiff
Add constant evaluation for comma operator with floating-point operand. Fixes
authorEli Friedman <eli.friedman@gmail.com>
Mon, 16 Nov 2009 04:25:37 +0000 (04:25 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Mon, 16 Nov 2009 04:25:37 +0000 (04:25 +0000)
PR5449.

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

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

index c036640b71121a2852beb03275ebdfbcd7243a3b..2689859e8e4aa79b29cf815cead029aa55dfde14 100644 (file)
@@ -1488,7 +1488,7 @@ public:
 
   // FIXME: Missing: __real__/__imag__, array subscript of vector,
   //                 member of vector, ImplicitValueInitExpr,
-  //                 conditional ?:, comma
+  //                 conditional ?:
 };
 } // end anonymous namespace
 
@@ -1577,6 +1577,18 @@ bool FloatExprEvaluator::VisitUnaryOperator(const UnaryOperator *E) {
 }
 
 bool FloatExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
+  if (E->getOpcode() == BinaryOperator::Comma) {
+    if (!EvaluateFloat(E->getRHS(), Result, Info))
+      return false;
+
+    // If we can't evaluate the LHS, it might have side effects;
+    // conservatively mark it.
+    if (!E->getLHS()->isEvaluatable(Info.Ctx))
+      Info.EvalResult.HasSideEffects = true;
+
+    return true;
+  }
+
   // FIXME: Diagnostics?  I really don't understand how the warnings
   // and errors are supposed to work.
   APFloat RHS(0.0);
index 87d1f155ebaf2253b6d4edd38748e129bbcbbb2e..39a24b3269912cc3900165675bacf80f8300f734 100644 (file)
@@ -73,3 +73,5 @@ EVAL_EXPR(34, (foo == (void *)0) ? -1 : 1)
 const _Bool constbool = 0;
 EVAL_EXPR(35, constbool)
 EVAL_EXPR(36, constbool)
+
+EVAL_EXPR(37, (1,2.0) == 2.0)