https://github.com/IvyXu420 created https://github.com/llvm/llvm-project/pull/230742
Cc @dyung @vgvassilev >From 001a883141b5f563157343c46fa3349a9440d79b Mon Sep 17 00:00:00 2001 From: Ivy Xu <[email protected]> Date: Sat, 10 Oct 2026 14:04:19 +0800 Subject: [PATCH] Reapply "[clang-repl] Fix crashing on unusable top-level declarations" #230054 --- clang/lib/Parse/ParseDecl.cpp | 4 +++- clang/test/Interpreter/execute.cpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 2f326451c3f13d..a3567d618cfa52 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -5873,8 +5873,10 @@ Parser::DeclGroupPtrTy Parser::ParseTopLevelStmtDecl() { TopLevelStmtDecl *TLSD = Actions.ActOnStartTopLevelStmtDecl(getCurScope()); StmtResult R = ParseStatementOrDeclaration(Stmts, SubStmtCtx); Actions.ActOnFinishTopLevelStmtDecl(TLSD, R.get()); - if (!R.isUsable()) + if (!R.isUsable()) { R = Actions.ActOnNullStmt(Tok.getLocation()); + TLSD->setStmt(R.get()); + } if (Tok.is(tok::annot_repl_input_end) && Tok.getAnnotationValue() != nullptr) { diff --git a/clang/test/Interpreter/execute.cpp b/clang/test/Interpreter/execute.cpp index 82cd70a93980a7..2cfcbda0b540fa 100644 --- a/clang/test/Interpreter/execute.cpp +++ b/clang/test/Interpreter/execute.cpp @@ -19,3 +19,5 @@ auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast<unsigned long long inline int foo() { return 42; } int r3 = foo(); + +return; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
