[cfe-commits] r60334 - /cfe/trunk/lib/AST/ExprConstant.cpp

Anders Carlsson andersca at mac.com
Sun Nov 30 22:44:06 PST 2008


Author: andersca
Date: Mon Dec  1 00:44:05 2008
New Revision: 60334

URL: http://llvm.org/viewvc/llvm-project?rev=60334&view=rev
Log:
Generate the correct results for the comma expression. Fixes PR3123.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp

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

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Dec  1 00:44:05 2008
@@ -513,14 +513,17 @@
 
 bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
   if (E->getOpcode() == BinaryOperator::Comma) {
-    // Evaluate the side that actually matters; this needs to be
-    // handled specially because calling Visit() on the LHS can
-    // have strange results when it doesn't have an integral type.
     if (!Visit(E->getRHS()))
       return false;
-    
-    if (Info.ShortCircuit)
+
+    if (!Info.ShortCircuit) {
+      // If we can't evaluate the LHS, it must be because it has 
+      // side effects.
+      if (!E->getLHS()->isEvaluatable(Info.Ctx))
+        Info.EvalResult.HasSideEffects = true;
+      
       return Extension(E->getOperatorLoc(), diag::note_comma_in_ice, E);
+    }
 
     return true;
   }
@@ -1202,8 +1205,8 @@
 /// isEvaluatable - Call Evaluate to see if this expression can be constant
 /// folded, but discard the result.
 bool Expr::isEvaluatable(ASTContext &Ctx) const {
-  APValue V;
-  return Evaluate(V, Ctx);
+  EvalResult Result;
+  return Evaluate(Result, Ctx) && !Result.HasSideEffects;
 }
 
 APSInt Expr::EvaluateAsInt(ASTContext &Ctx) const {





More information about the cfe-commits mailing list