[PATCH] D139798: [clang-repl] Support compound statement as a top-level statement.
Vassil Vassilev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 11 13:12:17 PST 2022
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139798.481945.patch
Type: text/x-patch
Size: 918 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221211/604ca19b/attachment-0001.bin>
More information about the cfe-commits
mailing list