[clang] [clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (PR #89031)

Vassil Vassilev via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 19 11:58:34 PDT 2024


================
@@ -364,6 +365,19 @@ IncrementalParser::Parse(llvm::StringRef input) {
 std::unique_ptr<llvm::Module> IncrementalParser::GenModule() {
   static unsigned ID = 0;
   if (CodeGenerator *CG = getCodeGen()) {
+    // Clang's CodeGen is designed to work with a single llvm::Module. In many
+    // cases for convenience various CodeGen parts have a reference to the
+    // llvm::Module (TheModule or Module) which does not change when a new
+    // module is pushed. However, the execution engine wants to take ownership
+    // of the module which does not map well to CodeGen's design. To work this
+    // around we clone the module and pass it down.
----------------
vgvassilev wrote:

Fixed.

https://github.com/llvm/llvm-project/pull/89031


More information about the cfe-commits mailing list