From 781ee538da1855876b085989a37ec959e3f2ecd1 Mon Sep 17 00:00:00 2001 From: Jun Zhang Date: Tue, 14 Jun 2022 17:36:41 +0800 Subject: Reland "[CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder" This reverts commits: d3ddc251acae631bf5ab4da13878f7e8b5b5a451 d90eecff5c9e7e9f8263de6cd72d70322400829f This relands below commit with asan fix: The intent of this patch is to selectively carry some states over to the Builder so we won't lose the information of the previous symbols. This used to be several downstream patches of Cling, it aims to fix errors in Clang Interpreter when trying to use inline functions. Before this patch: clang-repl> inline int foo() { return 42;} clang-repl> int x = foo(); JIT session error: Symbols not found: [ _Z3foov ] error: Failed to materialize symbols: { (main, { x, $.incr_module_1.__inits.0, __orc_init_func.incr_module_1 }) } Co-authored-by: Axel Naumann Signed-off-by: Jun Zhang Differential Revision: https://reviews.llvm.org/D127730 --- clang/lib/CodeGen/ModuleBuilder.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'clang/lib/CodeGen/ModuleBuilder.cpp') diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp b/clang/lib/CodeGen/ModuleBuilder.cpp index 50b7fd8..8e97a29 100644 --- a/clang/lib/CodeGen/ModuleBuilder.cpp +++ b/clang/lib/CodeGen/ModuleBuilder.cpp @@ -134,7 +134,14 @@ namespace { llvm::LLVMContext &C) { assert(!M && "Replacing existing Module?"); M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C)); + + std::unique_ptr OldBuilder = std::move(Builder); + Initialize(*Ctx); + + if (OldBuilder) + OldBuilder->moveLazyEmissionStates(Builder.get()); + return M.get(); } -- cgit v1.1