When we run into an error parsing or type-checking the left-hand side
of a binary expression, continue on and parse the right-hand side of
the binary expression anyway, but don't call the semantic actions to
type-check. Previously, we would see the error and then, effectively,
skip tokens until the end of the statement. 

The result should be more useful recovery, both in the normal case
(we'll actually see errors beyond the first one in a statement), but
it also helps code completion do a much better job, because we do
"real" code completion on the right-hand side of an invalid binary
expression rather than completing with the recovery completion. For
example, given

  x = p->y

if there is no variable named "x", we can still complete after the p->
as a member expression. Along the recovery path, we would have
completed after the "->" as if we were in an expression context, which
is mostly useless.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114225 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index 15c3e6e..c3c4b41 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -177,8 +177,6 @@
 ///
 ExprResult Parser::ParseExpression() {
   ExprResult LHS(ParseAssignmentExpression());
-  if (LHS.isInvalid()) return move(LHS);
-
   return ParseRHSOfBinaryExpression(move(LHS), prec::Comma);
 }
 
@@ -190,8 +188,6 @@
 ExprResult
 Parser::ParseExpressionWithLeadingAt(SourceLocation AtLoc) {
   ExprResult LHS(ParseObjCAtExpression(AtLoc));
-  if (LHS.isInvalid()) return move(LHS);
-
   return ParseRHSOfBinaryExpression(move(LHS), prec::Comma);
 }
 
@@ -206,14 +202,13 @@
     ExtensionRAIIObject O(Diags);
 
     LHS = ParseCastExpression(false);
-    if (LHS.isInvalid()) return move(LHS);
   }
 
-  LHS = Actions.ActOnUnaryOp(getCurScope(), ExtLoc, tok::kw___extension__,
-                             LHS.take());
-  if (LHS.isInvalid()) return move(LHS);
+  if (!LHS.isInvalid())
+    LHS = Actions.ActOnUnaryOp(getCurScope(), ExtLoc, tok::kw___extension__,
+                               LHS.take());
 
-  return ParseRHSOfBinaryExpression(LHS.take(), prec::Comma);
+  return ParseRHSOfBinaryExpression(move(LHS), prec::Comma);
 }
 
 /// ParseAssignmentExpression - Parse an expr that doesn't include commas.
@@ -228,9 +223,7 @@
     return ParseThrowExpression();
 
   ExprResult LHS(ParseCastExpression(false));
-  if (LHS.isInvalid()) return move(LHS);
-
-  return ParseRHSOfBinaryExpression(LHS.take(), prec::Assignment);
+  return ParseRHSOfBinaryExpression(move(LHS), prec::Assignment);
 }
 
 /// ParseAssignmentExprWithObjCMessageExprStart - Parse an assignment expression
@@ -251,8 +244,7 @@
                                      ReceiverType, ReceiverExpr);
   if (R.isInvalid()) return move(R);
   R = ParsePostfixExpressionSuffix(R.take());
-  if (R.isInvalid()) return move(R);
-  return ParseRHSOfBinaryExpression(R.take(), prec::Assignment);
+  return ParseRHSOfBinaryExpression(R, prec::Assignment);
 }
 
 
@@ -264,9 +256,7 @@
                                                Sema::Unevaluated);
 
   ExprResult LHS(ParseCastExpression(false));
-  if (LHS.isInvalid()) return move(LHS);
-
-  return ParseRHSOfBinaryExpression(LHS.take(), prec::Conditional);
+  return ParseRHSOfBinaryExpression(LHS, prec::Conditional);
 }
 
 /// ParseRHSOfBinaryExpression - Parse a binary expression that starts with
@@ -362,9 +352,10 @@
       RHS = ParseAssignmentExpression();
     else
       RHS = ParseCastExpression(false);
-    if (RHS.isInvalid())
-      return move(RHS);
 
+    if (RHS.isInvalid())
+      LHS = ExprError();
+    
     // Remember the precedence of this operator and get the precedence of the
     // operator immediately to the right of the RHS.
     prec::Level ThisPrec = NextTokPrec;
@@ -384,10 +375,11 @@
       // is okay, to bind exactly as tightly.  For example, compile A=B=C=D as
       // A=(B=(C=D)), where each paren is a level of recursion here.
       // The function takes ownership of the RHS.
-      RHS = ParseRHSOfBinaryExpression(RHS.get(), 
+      RHS = ParseRHSOfBinaryExpression(RHS, 
                             static_cast<prec::Level>(ThisPrec + !isRightAssoc));
+
       if (RHS.isInvalid())
-        return move(RHS);
+        LHS = ExprError();
 
       NextTokPrec = getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator,
                                        getLang().CPlusPlus0x);
@@ -426,9 +418,9 @@
                                                      ParsedType TypeOfCast) {
   bool NotCastExpr;
   ExprResult Res = ParseCastExpression(isUnaryExpression,
-                                             isAddressOfOperand,
-                                             NotCastExpr,
-                                             TypeOfCast);
+                                       isAddressOfOperand,
+                                       NotCastExpr,
+                                       TypeOfCast);
   if (NotCastExpr)
     Diag(Tok, diag::err_expected_expression);
   return move(Res);