@@ -209,10 +209,6 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
209
209
if (Err)
210
210
return ;
211
211
CI->ExecuteAction (*Act);
212
-
213
- if (getCodeGen ())
214
- CachedInCodeGenModule = GenModule ();
215
-
216
212
std::unique_ptr<ASTConsumer> IncrConsumer =
217
213
std::make_unique<IncrementalASTConsumer>(Interp, CI->takeASTConsumer ());
218
214
CI->setASTConsumer (std::move (IncrConsumer));
@@ -228,8 +224,11 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
228
224
return ; // PTU.takeError();
229
225
}
230
226
231
- if (getCodeGen ()) {
232
- PTU->TheModule = GenModule ();
227
+ if (CodeGenerator *CG = getCodeGen ()) {
228
+ std::unique_ptr<llvm::Module> M (CG->ReleaseModule ());
229
+ CG->StartModule (" incr_module_" + std::to_string (PTUs.size ()),
230
+ M->getContext ());
231
+ PTU->TheModule = std::move (M);
233
232
assert (PTU->TheModule && " Failed to create initial PTU" );
234
233
}
235
234
}
@@ -365,20 +364,6 @@ IncrementalParser::Parse(llvm::StringRef input) {
365
364
std::unique_ptr<llvm::Module> IncrementalParser::GenModule () {
366
365
static unsigned ID = 0 ;
367
366
if (CodeGenerator *CG = getCodeGen ()) {
368
- // Clang's CodeGen is designed to work with a single llvm::Module. In many
369
- // cases for convenience various CodeGen parts have a reference to the
370
- // llvm::Module (TheModule or Module) which does not change when a new
371
- // module is pushed. However, the execution engine wants to take ownership
372
- // of the module which does not map well to CodeGen's design. To work this
373
- // around we created an empty module to make CodeGen happy. We should make
374
- // sure it always stays empty.
375
- assert ((!CachedInCodeGenModule ||
376
- (CachedInCodeGenModule->empty () &&
377
- CachedInCodeGenModule->global_empty () &&
378
- CachedInCodeGenModule->alias_empty () &&
379
- CachedInCodeGenModule->ifunc_empty () &&
380
- CachedInCodeGenModule->named_metadata_empty ())) &&
381
- " CodeGen wrote to a readonly module" );
382
367
std::unique_ptr<llvm::Module> M (CG->ReleaseModule ());
383
368
CG->StartModule (" incr_module_" + std::to_string (ID++), M->getContext ());
384
369
return M;
0 commit comments