From 065cd64af3166da430bd03067514f9c9ac09e8e1 Mon Sep 17 00:00:00 2001 From: Jeaye Wilkerson Date: Tue, 30 Sep 2025 03:58:57 -0700 Subject: [clang-repl] Teach clang-repl how to load PCHs (reprise) (#157359) This is an updated version of @vgvassilev's PR from last year here: https://github.com/llvm/llvm-project/pull/94166 In short, it includes: 1. The fix for a blocking issue where `clang::Interpreter` (and thus `clang-repl`) cannot resolve symbols defined in a PCH 2. A test to prove this is working 3. A new hidden flag for `clang-repl` so that `llvm-lit` can match the host JIT triple between the PCH and `clang-repl`; previously, they may differ in some cases 4. Everything based on the latest LLVM main Shout out to @kylc for finding a logic issue which had us stumped for a while (and securing the [bounty](https://github.com/jank-lang/jank/issues/446)). --------- Co-authored-by: Vassil Vassilev Co-authored-by: Kyle Cesare --- clang/lib/CodeGen/ModuleBuilder.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'clang/lib/CodeGen/ModuleBuilder.cpp') diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp b/clang/lib/CodeGen/ModuleBuilder.cpp index 8c1fee8..96f3f62 100644 --- a/clang/lib/CodeGen/ModuleBuilder.cpp +++ b/clang/lib/CodeGen/ModuleBuilder.cpp @@ -138,6 +138,8 @@ namespace { assert(!M && "Replacing existing Module?"); M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C)); + IRGenFinished = false; + std::unique_ptr OldBuilder = std::move(Builder); Initialize(*Ctx); @@ -179,6 +181,10 @@ namespace { } bool HandleTopLevelDecl(DeclGroupRef DG) override { + // Ignore interesting decls from the AST reader after IRGen is finished. + if (IRGenFinished) + return true; // We can't CodeGen more but pass to other consumers. + // FIXME: Why not return false and abort parsing? if (Diags.hasUnrecoverableErrorOccurred()) return true; @@ -292,8 +298,9 @@ namespace { if (Builder) Builder->clear(); M.reset(); - return; } + + IRGenFinished = true; } void AssignInheritanceModel(CXXRecordDecl *RD) override { -- cgit v1.1