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

Eli Friedman eli.friedman at gmail.com
Sun Nov 15 20:25:39 PST 2009


Author: efriedma
Date: Sun Nov 15 22:25:37 2009
New Revision: 88885

URL: http://llvm.org/viewvc/llvm-project?rev=88885&view=rev
Log:
Add constant evaluation for comma operator with floating-point operand.  Fixes
PR5449.


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=88885&r1=88884&r2=88885&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sun Nov 15 22:25:37 2009
@@ -1488,7 +1488,7 @@
 
   // FIXME: Missing: __real__/__imag__, array subscript of vector,
   //                 member of vector, ImplicitValueInitExpr,
-  //                 conditional ?:, comma
+  //                 conditional ?:
 };
 } // end anonymous namespace
 
@@ -1577,6 +1577,18 @@
 }
 
 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);

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

==============================================================================
--- cfe/trunk/test/Sema/const-eval.c (original)
+++ cfe/trunk/test/Sema/const-eval.c Sun Nov 15 22:25:37 2009
@@ -73,3 +73,5 @@
 const _Bool constbool = 0;
 EVAL_EXPR(35, constbool)
 EVAL_EXPR(36, constbool)
+
+EVAL_EXPR(37, (1,2.0) == 2.0)





More information about the cfe-commits mailing list