[clang] Reapply "[clang-repl] Fix crashing on unusable top-level declarations" (#230054) (PR #230742)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 9 23:30:31 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Ivy Xu (IvyXu420)
<details>
<summary>Changes</summary>
Cc @<!-- -->dyung @<!-- -->vgvassilev
---
Full diff: https://github.com/llvm/llvm-project/pull/230742.diff
2 Files Affected:
- (modified) clang/lib/Parse/ParseDecl.cpp (+3-1)
- (modified) clang/test/Interpreter/execute.cpp (+2)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/230742
More information about the cfe-commits
mailing list