junaire updated this revision to Diff 434714.
junaire added a comment.

Try to address @rjmccall 's comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126781/new/

https://reviews.llvm.org/D126781

Files:
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===================================================================
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast<unsigned long 
long>(s.m));
 // CHECK-NEXT: S[f=1.000000, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===================================================================
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ 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<CodeGenModule>(
+          *Ctx, HeaderSearchOpts, PreprocessorOpts, CodeGenOpts, *M, Diags,
+          CoverageInfo);
+      Builder->moveLazyEmissionState(NewBuilder.get());
       Initialize(*Ctx);
+      Builder = std::move(NewBuilder);
       return M.get();
     }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===================================================================
--- clang/lib/CodeGen/CodeGenModule.h
+++ 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,


Index: clang/test/Interpreter/execute.cpp
===================================================================
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast<unsigned long long>(s.m));
 // CHECK-NEXT: S[f=1.000000, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===================================================================
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ 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<CodeGenModule>(
+          *Ctx, HeaderSearchOpts, PreprocessorOpts, CodeGenOpts, *M, Diags,
+          CoverageInfo);
+      Builder->moveLazyEmissionState(NewBuilder.get());
       Initialize(*Ctx);
+      Builder = std::move(NewBuilder);
       return M.get();
     }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===================================================================
--- clang/lib/CodeGen/CodeGenModule.h
+++ 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,
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to