[clang] Reapply "[clang-repl] Fix crashing on unusable top-level declarations" (#230054) (PR #230742)
Ivy Xu via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 9 23:29:49 PDT 2026
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 <ivyxu1337 at gmail.com>
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;
More information about the cfe-commits
mailing list