https://github.com/makslevental updated https://github.com/llvm/llvm-project/pull/69072
>From 737bef4f36139f0347e9ab58838e41aadbb45d16 Mon Sep 17 00:00:00 2001 From: max <maksim.leven...@gmail.com> Date: Sat, 14 Oct 2023 12:46:42 -0500 Subject: [PATCH] [clang][repl] fix `new` --- clang/lib/Interpreter/Interpreter.cpp | 24 ++++++++++++------- clang/test/Interpreter/execute.cpp | 2 ++ .../unittests/Interpreter/InterpreterTest.cpp | 5 +++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index 7968c62cbd3e7b3..57514f2d0cc424d 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -248,7 +248,6 @@ Interpreter::~Interpreter() { // can't find the precise resource directory in unittests so we have to hard // code them. const char *const Runtimes = R"( - void* operator new(__SIZE_TYPE__, void* __p) noexcept; void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*); @@ -257,14 +256,9 @@ const char *const Runtimes = R"( void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double); void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long long); template <class T, class = T (*)() /*disable for arrays*/> - void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned long Size) { - for (auto Idx = 0; Idx < Size; ++Idx) - new ((void*)(((T*)Placement) + Idx)) T(Src[Idx]); - } + void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned long Size); template <class T, unsigned long N> - void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* Placement, unsigned long Size) { - __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size); - } + void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* Placement, unsigned long Size); )"; llvm::Expected<std::unique_ptr<Interpreter>> @@ -762,6 +756,20 @@ __clang_Interpreter_SetValueNoAlloc(void *This, void *OutVal, VRef = Value(static_cast<Interpreter *>(This), OpaqueType); } +template <class T, class> +REPL_EXTERNAL_VISIBILITY void +__clang_Interpreter_SetValueCopyArr(T *Src, void *Placement, + unsigned long Size) { + for (unsigned long Idx = 0; Idx < Size; ++Idx) + new ((void *)(((T *)Placement) + Idx)) T(Src[Idx]); +} +template <class T, unsigned long N> +REPL_EXTERNAL_VISIBILITY void +__clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void *Placement, + unsigned long Size) { + __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size); +} + static void SetValueDataBasedOnQualType(Value &V, unsigned long long Data) { QualType QT = V.getType(); if (const auto *ET = QT->getAs<EnumType>()) diff --git a/clang/test/Interpreter/execute.cpp b/clang/test/Interpreter/execute.cpp index 6e73ed3927e8155..d54ab99749c1bac 100644 --- a/clang/test/Interpreter/execute.cpp +++ b/clang/test/Interpreter/execute.cpp @@ -20,4 +20,6 @@ auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast<unsigned long long inline int foo() { return 42; } int r3 = foo(); +#include <memory> + %quit diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp index 5f2911e9a7adad3..cc00d52d8d3bfa6 100644 --- a/clang/unittests/Interpreter/InterpreterTest.cpp +++ b/clang/unittests/Interpreter/InterpreterTest.cpp @@ -51,7 +51,10 @@ createInterpreter(const Args &ExtraArgs = {}, auto CI = cantFail(CB.CreateCpp()); if (Client) CI->getDiagnostics().setClient(Client, /*ShouldOwnClient=*/false); - return cantFail(clang::Interpreter::create(std::move(CI))); + auto interp = cantFail(clang::Interpreter::create(std::move(CI))); + (void)cantFail( + interp->Parse("void* operator new(__SIZE_TYPE__, void* __p) noexcept;")); + return interp; } static size_t DeclsSize(TranslationUnitDecl *PTUDecl) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits