diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -1477,6 +1477,13 @@ void printPostfixForExternalizedDecl(llvm::raw_ostream &OS, const Decl *D) const; + void moveLazyEmissionState(CodeGenModule *NewBuilder) { + std::swap(NewBuilder->DeferredDecls, DeferredDecls); + std::swap(NewBuilder->DeferredVTables, DeferredVTables); + std::swap(NewBuilder->Manglings, Manglings); + std::swap(NewBuilder->TBAA, TBAA); + } + private: llvm::Constant *GetOrCreateLLVMFunction( StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable, diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp b/clang/lib/CodeGen/ModuleBuilder.cpp --- a/clang/lib/CodeGen/ModuleBuilder.cpp +++ b/clang/lib/CodeGen/ModuleBuilder.cpp @@ -134,7 +134,12 @@ llvm::LLVMContext &C) { assert(!M && "Replacing existing Module?"); M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C)); + auto NewBuilder = std::make_unique( + *Ctx, HeaderSearchOpts, PreprocessorOpts, CodeGenOpts, *M, Diags, + CoverageInfo); + Builder->moveLazyEmissionState(NewBuilder.get()); Initialize(*Ctx); + Builder = std::move(NewBuilder); return M.get(); } diff --git a/clang/test/Interpreter/execute.cpp b/clang/test/Interpreter/execute.cpp --- a/clang/test/Interpreter/execute.cpp +++ b/clang/test/Interpreter/execute.cpp @@ -13,4 +13,8 @@ auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m)); // CHECK-NEXT: S[f=1.000000, m=0x0] + +inline int foo() { return 42; } +int r3 = foo(); + quit