Author: asudarsa-qti Date: 2026-09-26T09:14:23+03:00 New Revision: 6a37cee09997b28c6cc708dd36b283bbd5bd7147
URL: https://github.com/llvm/llvm-project/commit/6a37cee09997b28c6cc708dd36b283bbd5bd7147 DIFF: https://github.com/llvm/llvm-project/commit/6a37cee09997b28c6cc708dd36b283bbd5bd7147.diff LOG: Fix for a clang-repl crash when passing non-existent file to --Xcc (#225861) Problem: When clang-repl fails to initialize because an --Xcc file does not exist, Interpreter::create() destroys the partially initialized Interpreter. Its destructor unconditionally calls FinalizeAction(), which invokes FrontendAction::EndSourceFile() without a registered CompilerInstance and triggers an assertion. Fix: Track whether interpreter initialization completed successfully and only finalize the frontend action for successfully initialized interpreters. Test: Add a regression test covering a nonexistent --Xcc file. This change resolves https://github.com/llvm/llvm-project/issues/225429 Assisted by gpt-5.6-luna --------- Co-authored-by: Anutosh Bhat <[email protected]> Added: clang/test/Interpreter/nonexistent-xcc-file.cpp Modified: clang/lib/Interpreter/IncrementalAction.cpp Removed: ################################################################################ diff --git a/clang/lib/Interpreter/IncrementalAction.cpp b/clang/lib/Interpreter/IncrementalAction.cpp index 85f00c36dd5aa..2c1ad404a3e7d 100644 --- a/clang/lib/Interpreter/IncrementalAction.cpp +++ b/clang/lib/Interpreter/IncrementalAction.cpp @@ -85,7 +85,8 @@ void IncrementalAction::EndSourceFile() { void IncrementalAction::FinalizeAction() { assert(!IsTerminating && "Already finalized!"); IsTerminating = true; - EndSourceFile(); + if (!getCurrentInput().isEmpty()) + EndSourceFile(); } void IncrementalAction::CacheCodeGenModule() { diff --git a/clang/test/Interpreter/nonexistent-xcc-file.cpp b/clang/test/Interpreter/nonexistent-xcc-file.cpp new file mode 100644 index 0000000000000..7b1bb8abd94ce --- /dev/null +++ b/clang/test/Interpreter/nonexistent-xcc-file.cpp @@ -0,0 +1,7 @@ +// RUN: not clang-repl --Xcc=%t/nonexistent.cpp 2>&1 | FileCheck --ignore-case %s + +// CHECK: error: error reading '{{.*}}nonexistent.cpp': No such file or directory +// CHECK-NOT: Compiler instance not registered +// CHECK-NOT: Assertion +// CHECK-NOT: segmentation fault +// CHECK-NOT: core dumped _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
