v.g.vassilev created this revision.
v.g.vassilev added reviewers: aaron.ballman, rsmith.
Herald added a project: All.
v.g.vassilev requested review of this revision.

This patch teaches our incremental compilation infrastructure to push and pop a 
fake function scope making the Parser happy when parsing compound statements as 
part of a top-leve statement declaration.


Repository:
  rC Clang

https://reviews.llvm.org/D139798

Files:
  clang/lib/Parse/ParseDecl.cpp
  clang/test/Interpreter/execute-stmts.cpp


Index: clang/test/Interpreter/execute-stmts.cpp
===================================================================
--- clang/test/Interpreter/execute-stmts.cpp
+++ clang/test/Interpreter/execute-stmts.cpp
@@ -34,5 +34,10 @@
 for (; i > 4; --i) printf("i = %d\n", i);
 // CHECK-NEXT: i = 5
 
+{++i;}
+
+for (; i > 4; --i) { printf("i = %d\n", i); };
+// CHECK-NEXT: i = 5
+
 int j = i; printf("j = %d\n", j);
 // CHECK-NEXT: j = 4
Index: clang/lib/Parse/ParseDecl.cpp
===================================================================
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -5387,7 +5387,9 @@
   // Parse a top-level-stmt.
   Parser::StmtVector Stmts;
   ParsedStmtContext SubStmtCtx = ParsedStmtContext();
+  Actions.PushFunctionScope();
   StmtResult R = ParseStatementOrDeclaration(Stmts, SubStmtCtx);
+  Actions.PopFunctionScopeInfo();
   if (!R.isUsable())
     return nullptr;
 


Index: clang/test/Interpreter/execute-stmts.cpp
===================================================================
--- clang/test/Interpreter/execute-stmts.cpp
+++ clang/test/Interpreter/execute-stmts.cpp
@@ -34,5 +34,10 @@
 for (; i > 4; --i) printf("i = %d\n", i);
 // CHECK-NEXT: i = 5
 
+{++i;}
+
+for (; i > 4; --i) { printf("i = %d\n", i); };
+// CHECK-NEXT: i = 5
+
 int j = i; printf("j = %d\n", j);
 // CHECK-NEXT: j = 4
Index: clang/lib/Parse/ParseDecl.cpp
===================================================================
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -5387,7 +5387,9 @@
   // Parse a top-level-stmt.
   Parser::StmtVector Stmts;
   ParsedStmtContext SubStmtCtx = ParsedStmtContext();
+  Actions.PushFunctionScope();
   StmtResult R = ParseStatementOrDeclaration(Stmts, SubStmtCtx);
+  Actions.PopFunctionScopeInfo();
   if (!R.isUsable())
     return nullptr;
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to