Skip to content

Commit adc4f62

Browse files
committed
Revert "[clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (llvm#89031)"
This reverts commit ca09045 and 1faf314 because it broke a darwin bot.
1 parent ca09045 commit adc4f62

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

clang/lib/Interpreter/IncrementalParser.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,6 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
209209
if (Err)
210210
return;
211211
CI->ExecuteAction(*Act);
212-
213-
if (getCodeGen())
214-
CachedInCodeGenModule = GenModule();
215-
216212
std::unique_ptr<ASTConsumer> IncrConsumer =
217213
std::make_unique<IncrementalASTConsumer>(Interp, CI->takeASTConsumer());
218214
CI->setASTConsumer(std::move(IncrConsumer));
@@ -228,8 +224,11 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
228224
return; // PTU.takeError();
229225
}
230226

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);
233232
assert(PTU->TheModule && "Failed to create initial PTU");
234233
}
235234
}
@@ -365,20 +364,6 @@ IncrementalParser::Parse(llvm::StringRef input) {
365364
std::unique_ptr<llvm::Module> IncrementalParser::GenModule() {
366365
static unsigned ID = 0;
367366
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");
382367
std::unique_ptr<llvm::Module> M(CG->ReleaseModule());
383368
CG->StartModule("incr_module_" + std::to_string(ID++), M->getContext());
384369
return M;

clang/lib/Interpreter/IncrementalParser.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <memory>
2525
namespace llvm {
2626
class LLVMContext;
27-
class Module;
2827
} // namespace llvm
2928

3029
namespace clang {
@@ -58,10 +57,6 @@ class IncrementalParser {
5857
/// of code.
5958
std::list<PartialTranslationUnit> PTUs;
6059

61-
/// When CodeGen is created the first llvm::Module gets cached in many places
62-
/// and we must keep it alive.
63-
std::unique_ptr<llvm::Module> CachedInCodeGenModule;
64-
6560
IncrementalParser();
6661

6762
public:

0 commit comments

Comments
 (0)