r273589 - Revert r273548, "Rearrange condition handling so that semantic checks on a condition variable"

2016-06-23 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Thu Jun 23 13:11:15 2016
New Revision: 273589

URL: http://llvm.org/viewvc/llvm-project?rev=273589&view=rev
Log:
Revert r273548, "Rearrange condition handling so that semantic checks on a 
condition variable"
as it caused a regression in -Wfor-loop-analysis.

Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/FixIt/fixit-vexing-parse.cpp
cfe/trunk/test/Parser/cxx0x-condition.cpp
cfe/trunk/test/SemaCXX/crashes.cpp
cfe/trunk/test/SemaCXX/for-range-examples.cpp
cfe/trunk/test/SemaObjCXX/foreach.mm

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=273589&r1=273588&r2=273589&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Jun 23 13:11:15 2016
@@ -1588,8 +1588,8 @@ private:
 
   
//======//
   // C++ if/switch/while condition expression.
-  Sema::ConditionResult ParseCXXCondition(SourceLocation Loc,
-  Sema::ConditionKind CK);
+  bool ParseCXXCondition(ExprResult &ExprResult, Decl *&DeclResult,
+ SourceLocation Loc, bool ConvertToBoolean);
 
   
//======//
   // C++ Coroutines
@@ -1680,9 +1680,10 @@ private:
 unsigned ScopeFlags);
   void ParseCompoundStatementLeadingPragmas();
   StmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
-  bool ParseParenExprOrCondition(Sema::ConditionResult &CondResult,
+  bool ParseParenExprOrCondition(ExprResult &ExprResult,
+ Decl *&DeclResult,
  SourceLocation Loc,
- Sema::ConditionKind CK);
+ bool ConvertToBoolean);
   StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc);
   StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc);
   StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc);

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=273589&r1=273588&r2=273589&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Jun 23 13:11:15 2016
@@ -3298,7 +3298,6 @@ public:
 public:
   class FullExprArg {
   public:
-FullExprArg() : E(nullptr) { }
 FullExprArg(Sema &actions) : E(nullptr) { }
 
 ExprResult release() {
@@ -3392,23 +3391,27 @@ public:
  ArrayRef Attrs,
  Stmt *SubStmt);
 
-  class ConditionResult;
-  StmtResult ActOnIfStmt(SourceLocation IfLoc, ConditionResult Cond,
- Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal);
+  StmtResult ActOnIfStmt(SourceLocation IfLoc,
+ FullExprArg CondVal, Decl *CondVar,
+ Stmt *ThenVal,
+ SourceLocation ElseLoc, Stmt *ElseVal);
   StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc,
-ConditionResult Cond);
+Expr *Cond,
+Decl *CondVar);
   StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
Stmt *Switch, Stmt *Body);
-  StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ConditionResult Cond,
-Stmt *Body);
+  StmtResult ActOnWhileStmt(SourceLocation WhileLoc,
+FullExprArg Cond,
+Decl *CondVar, Stmt *Body);
   StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
- SourceLocation WhileLoc, SourceLocation CondLParen,
- Expr *Cond, SourceLocation CondRParen);
+ SourceLocation WhileLoc,
+ SourceLocation CondLParen, Expr *Cond,
+ SourceLocation CondRParen);
 
   StmtResult ActOnForStmt(SourceLocation ForLoc,
   SourceLocation LParenLoc,
-  Stmt *First,
-  ConditionResult Seco

r273548 - Rearrange condition handling so that semantic checks on a condition variable

2016-06-23 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Jun 23 03:41:20 2016
New Revision: 273548

URL: http://llvm.org/viewvc/llvm-project?rev=273548&view=rev
Log:
Rearrange condition handling so that semantic checks on a condition variable
are performed before the other substatements of the construct are parsed,
rather than deferring them until the end. This allows better error recovery
from semantic errors in the condition, improves diagnostic order, and is a
prerequisite for C++17 constexpr if.

Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/FixIt/fixit-vexing-parse.cpp
cfe/trunk/test/Parser/cxx0x-condition.cpp
cfe/trunk/test/SemaCXX/crashes.cpp
cfe/trunk/test/SemaCXX/for-range-examples.cpp
cfe/trunk/test/SemaObjCXX/foreach.mm

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=273548&r1=273547&r2=273548&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Jun 23 03:41:20 2016
@@ -1588,8 +1588,8 @@ private:
 
   
//======//
   // C++ if/switch/while condition expression.
-  bool ParseCXXCondition(ExprResult &ExprResult, Decl *&DeclResult,
- SourceLocation Loc, bool ConvertToBoolean);
+  Sema::ConditionResult ParseCXXCondition(SourceLocation Loc,
+  Sema::ConditionKind CK);
 
   
//======//
   // C++ Coroutines
@@ -1680,10 +1680,9 @@ private:
 unsigned ScopeFlags);
   void ParseCompoundStatementLeadingPragmas();
   StmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
-  bool ParseParenExprOrCondition(ExprResult &ExprResult,
- Decl *&DeclResult,
+  bool ParseParenExprOrCondition(Sema::ConditionResult &CondResult,
  SourceLocation Loc,
- bool ConvertToBoolean);
+ Sema::ConditionKind CK);
   StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc);
   StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc);
   StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc);

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=273548&r1=273547&r2=273548&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Jun 23 03:41:20 2016
@@ -3298,6 +3298,7 @@ public:
 public:
   class FullExprArg {
   public:
+FullExprArg() : E(nullptr) { }
 FullExprArg(Sema &actions) : E(nullptr) { }
 
 ExprResult release() {
@@ -3391,27 +3392,23 @@ public:
  ArrayRef Attrs,
  Stmt *SubStmt);
 
-  StmtResult ActOnIfStmt(SourceLocation IfLoc,
- FullExprArg CondVal, Decl *CondVar,
- Stmt *ThenVal,
- SourceLocation ElseLoc, Stmt *ElseVal);
+  class ConditionResult;
+  StmtResult ActOnIfStmt(SourceLocation IfLoc, ConditionResult Cond,
+ Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal);
   StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc,
-Expr *Cond,
-Decl *CondVar);
+ConditionResult Cond);
   StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
Stmt *Switch, Stmt *Body);
-  StmtResult ActOnWhileStmt(SourceLocation WhileLoc,
-FullExprArg Cond,
-Decl *CondVar, Stmt *Body);
+  StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ConditionResult Cond,
+Stmt *Body);
   StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
- SourceLocation WhileLoc,
- SourceLocation CondLParen, Expr *Cond,
- SourceLocation CondRParen);
+ SourceLocation WhileLoc, SourceLocation CondLParen,
+ Expr *Cond, SourceLocation CondRParen);
 
   StmtResult ActOnForStmt(SourceLocation ForLoc,