https://github.com/jeaye updated https://github.com/llvm/llvm-project/pull/217147
>From 70e981be85bdd64258434ee30054b05acb833de6 Mon Sep 17 00:00:00 2001 From: jeaye <[email protected]> Date: Tue, 18 Aug 2026 13:10:09 -0700 Subject: [PATCH] [clang-repl] Stop interpreter init on action failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `clang::Interpreter` previously ignored the result of its initial `CompilerInstance::ExecuteAction()` call and always constructed the `IncrementalParser`. When the initial action failed, the parser could be created from an invalid compiler state. In practice, this failure happens if the incremental PCH included has expired, due to system headers changing. This happens quite regularly, after system updates, and is affecting jank. To fix this, the `Interpreter` now returns an error immediately when the initial action fails or records a diagnostic error. --- clang/lib/Interpreter/Interpreter.cpp | 8 +++++++- clang/test/Interpreter/stale-pch.cpp | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 clang/test/Interpreter/stale-pch.cpp diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index 0536fdcd548a2..d612c8d878f32 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -349,7 +349,13 @@ Interpreter::Interpreter(std::unique_ptr<CompilerInstance> Instance, if (ErrOut) return; - CI->ExecuteAction(*Act); + if (!CI->ExecuteAction(*Act) || CI->getDiagnostics().hasErrorOccurred()) { + ErrOut = joinErrors( + std::move(ErrOut), + llvm::createStringError(llvm::errc::not_supported, + "Failed to execute incremental action")); + return; + } IncrParser = std::make_unique<IncrementalParser>(*CI, Act.get(), ErrOut, PTUs); diff --git a/clang/test/Interpreter/stale-pch.cpp b/clang/test/Interpreter/stale-pch.cpp new file mode 100644 index 0000000000000..410a91fe7d8f0 --- /dev/null +++ b/clang/test/Interpreter/stale-pch.cpp @@ -0,0 +1,23 @@ +// REQUIRES: host-supports-jit +// UNSUPPORTED: system-aix +// +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t +// +// RUN: %if system-windows %{ \ +// RUN: %clang -fmax-type-align=16 -Xclang -fdeprecated-macro -fno-stack-protector -Xclang -fwrapv -Xclang -fblocks -Xclang -fskip-odr-check-in-gmf -fexceptions -fcxx-exceptions -fgnuc-version=0 -target %host-jit-triple -Xclang -fblocks -Xclang -fmax-type-align=8 -Xclang -fincremental-extensions -Xclang -emit-pch -x c++-header -o %t/include.pch %t/include.hpp \ +// RUN: %} \ +// RUN: %else %{ \ +// RUN: %clang -fPIC -fmax-type-align=16 -Xclang -fdeprecated-macro -fno-stack-protector -Xclang -fwrapv -Xclang -fblocks -Xclang -fskip-odr-check-in-gmf -fexceptions -fcxx-exceptions -fgnuc-version=0 -target %host-jit-triple -Xclang -fblocks -Xclang -fmax-type-align=8 -Xclang -fincremental-extensions -Xclang -emit-pch -x c++-header -o %t/include.pch %t/include.hpp \ +// RUN: %} +// RUN: echo '// changed after PCH creation' >> %t/include.hpp +// +// RUN: not clang-repl -Xcc -fgnuc-version=0 -Xcc -fno-stack-protector -Xcc -fwrapv -Xcc -fblocks -Xcc -fskip-odr-check-in-gmf -Xcc -fmax-type-align=8 -Xcc -include-pch -Xcc %t/include.pch < /dev/null 2>&1 | FileCheck %s + +//--- include.hpp + +int f_pch() { return 5; } + +// CHECK: fatal error: file '{{.*}}include.hpp' has been modified since the precompiled header +// CHECK: clang-repl: Failed to execute incremental action _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
