[clang] [clang-repl] Remove invalid TopLevelStmtDecl from TU on parse failure (PR #153945)
Vassil Vassilev via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 16 23:58:44 PDT 2025
================
@@ -5696,8 +5696,11 @@ 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()) {
+ if (DeclContext *DC = TLSD->getDeclContext())
+ DC->removeDecl(TLSD); // unlink from TU
----------------
vgvassilev wrote:
Can we do this here https://github.com/llvm/llvm-project/blob/e44784fb44bd00acc0ecd25537a359c3a1df8f17/clang/lib/Interpreter/IncrementalParser.cpp#L155 ?
https://github.com/llvm/llvm-project/pull/153945
More information about the cfe-commits
mailing list