[clang] 6448c95 - Reapply "[clang-repl] Fix crashing on unusable top-level declarations" (#230054) (#230742)

via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 10 04:37:55 PDT 2026


Author: Ivy Xu
Date: 2026-10-10T14:37:49+03:00
New Revision: 6448c95cf38042b5e6a503689ba965087b01fa55

URL: https://github.com/llvm/llvm-project/commit/6448c95cf38042b5e6a503689ba965087b01fa55
DIFF: https://github.com/llvm/llvm-project/commit/6448c95cf38042b5e6a503689ba965087b01fa55.diff

LOG: Reapply "[clang-repl] Fix crashing on unusable top-level declarations" (#230054) (#230742)

Drop the previously failing test lines:
```c
printf("not crashed\n");
// CHECK-NEXT: not crashed
```
A bare `return;` is sufficient for detecting the regression.

Reverts #230734.

Added: 
    

Modified: 
    clang/lib/Parse/ParseDecl.cpp
    clang/test/Interpreter/execute.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 2f326451c3f13..a3567d618cfa5 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 82cd70a93980a..2cfcbda0b540f 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