@@ -264,7 +264,7 @@ class InProcessPrintingASTConsumer final : public MultiplexConsumer {
264264 if (auto *TLSD = llvm::dyn_cast<TopLevelStmtDecl>(D))
265265 if (TLSD && TLSD->isSemiMissing ()) {
266266 auto ExprOrErr =
267- Interp.ExtractValueFromExpr (cast<Expr>(TLSD->getStmt ()));
267+ Interp.convertExprToValue (cast<Expr>(TLSD->getStmt ()));
268268 if (llvm::Error E = ExprOrErr.takeError ()) {
269269 llvm::logAllUnhandledErrors (std::move (E), llvm::errs (),
270270 " Value printing failed: " );
@@ -440,11 +440,10 @@ const char *const Runtimes = R"(
440440 #define __CLANG_REPL__ 1
441441#ifdef __cplusplus
442442 #define EXTERN_C extern "C"
443- void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
444443 struct __clang_Interpreter_NewTag{} __ci_newtag;
445444 void* operator new(__SIZE_TYPE__, void* __p, __clang_Interpreter_NewTag) noexcept;
446445 template <class T, class = T (*)() /*disable for arrays*/>
447- void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned long Size) {
446+ void __clang_Interpreter_SetValueCopyArr(const T* Src, void* Placement, unsigned long Size) {
448447 for (auto Idx = 0; Idx < Size; ++Idx)
449448 new ((void*)(((T*)Placement) + Idx), __ci_newtag) T(Src[Idx]);
450449 }
@@ -454,8 +453,12 @@ const char *const Runtimes = R"(
454453 }
455454#else
456455 #define EXTERN_C extern
456+ EXTERN_C void *memcpy(void *restrict dst, const void *restrict src, __SIZE_TYPE__ n);
457+ EXTERN_C inline void __clang_Interpreter_SetValueCopyArr(const void* Src, void* Placement, unsigned long Size) {
458+ memcpy(Placement, Src, Size);
459+ }
457460#endif // __cplusplus
458-
461+ EXTERN_C void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
459462 EXTERN_C void __clang_Interpreter_SetValueNoAlloc(void *This, void *OutVal, void *OpaqueType, ...);
460463)" ;
461464
@@ -470,12 +473,12 @@ Interpreter::create(std::unique_ptr<CompilerInstance> CI,
470473
471474 // Add runtime code and set a marker to hide it from user code. Undo will not
472475 // go through that.
473- auto PTU = Interp->Parse (Runtimes);
474- if (!PTU)
475- return PTU.takeError ();
476+ Err = Interp->ParseAndExecute (Runtimes);
477+ if (Err)
478+ return std::move (Err);
479+
476480 Interp->markUserCodeStart ();
477481
478- Interp->ValuePrintingInfo .resize (4 );
479482 return std::move (Interp);
480483}
481484
@@ -524,12 +527,11 @@ Interpreter::createWithCUDA(std::unique_ptr<CompilerInstance> CI,
524527 return std::move (Interp);
525528}
526529
530+ CompilerInstance *Interpreter::getCompilerInstance () { return CI.get (); }
527531const CompilerInstance *Interpreter::getCompilerInstance () const {
528- return CI. get ();
532+ return const_cast <Interpreter *>( this )-> getCompilerInstance ();
529533}
530534
531- CompilerInstance *Interpreter::getCompilerInstance () { return CI.get (); }
532-
533535llvm::Expected<llvm::orc::LLJIT &> Interpreter::getExecutionEngine () {
534536 if (!IncrExecutor) {
535537 if (auto Err = CreateExecutor ())
@@ -610,7 +612,14 @@ Interpreter::Parse(llvm::StringRef Code) {
610612 if (!TuOrErr)
611613 return TuOrErr.takeError ();
612614
613- return RegisterPTU (*TuOrErr);
615+ PTUs.emplace_back (PartialTranslationUnit ());
616+ PartialTranslationUnit &LastPTU = PTUs.back ();
617+ LastPTU.TUPart = *TuOrErr;
618+
619+ if (std::unique_ptr<llvm::Module> M = GenModule ())
620+ LastPTU.TheModule = std::move (M);
621+
622+ return LastPTU;
614623}
615624
616625static llvm::Expected<llvm::orc::JITTargetMachineBuilder>
@@ -808,10 +817,10 @@ Interpreter::GenModule(IncrementalAction *Action) {
808817 // sure it always stays empty.
809818 assert (((!CachedInCodeGenModule ||
810819 !getCompilerInstance ()->getPreprocessorOpts ().Includes .empty ()) ||
811- (CachedInCodeGenModule->empty () &&
812- CachedInCodeGenModule->global_empty () &&
813- CachedInCodeGenModule->alias_empty () &&
814- CachedInCodeGenModule->ifunc_empty ())) &&
820+ (( CachedInCodeGenModule->empty () &&
821+ CachedInCodeGenModule->global_empty () &&
822+ CachedInCodeGenModule->alias_empty () &&
823+ CachedInCodeGenModule->ifunc_empty () ))) &&
815824 " CodeGen wrote to a readonly module" );
816825 std::unique_ptr<llvm::Module> M (CG->ReleaseModule ());
817826 CG->StartModule (" incr_module_" + std::to_string (ID++), M->getContext ());
@@ -828,4 +837,4 @@ CodeGenerator *Interpreter::getCodeGen(IncrementalAction *Action) const {
828837 return nullptr ;
829838 return static_cast <CodeGenAction *>(WrappedAct)->getCodeGenerator ();
830839}
831- } // namespace clang
840+ } // end namespace clang
0 commit comments