[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
vgvassilev wrote: Yes, you are right, I've put a fix here https://github.com/llvm/llvm-project/pull/78843. Can you take a look? https://github.com/llvm/llvm-project/pull/76218 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
vitalybuka wrote: Yes, it fixes the leak but on asan bot it's mismatch https://lab.llvm.org/buildbot/#/builders/168/builds/18159/steps/10/logs/stdio https://github.com/llvm/llvm-project/pull/76218 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
vitalybuka wrote: I suspect asan may complain on new/free mismatch https://github.com/llvm/llvm-project/pull/76218 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
vgvassilev wrote: @vitalybuka, thank you! I am trying to add a fix but I get `unsupported option '-fsanitize=hwaddress' for target 'x86_64-apple-darwin21.6.0'`. If you have a compatible platform, do you mind testing: ```diff diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp index d6eb0684ba49..406a4871dff5 100644 --- a/clang/unittests/Interpreter/InterpreterTest.cpp +++ b/clang/unittests/Interpreter/InterpreterTest.cpp @@ -34,12 +34,6 @@ using namespace clang; #define CLANG_INTERPRETER_NO_SUPPORT_EXEC #endif -#if LLVM_ADDRESS_SANITIZER_BUILD || LLVM_HWADDRESS_SANITIZER_BUILD -#include -#else -extern "C" void __lsan_ignore_object(const void *p) {} -#endif - int Global = 42; // JIT reports symbol not found on Windows without the visibility attribute. REPL_EXTERNAL_VISIBILITY int getGlobal() { return Global; } @@ -317,8 +311,9 @@ TEST(IncrementalProcessing, InstantiateTemplate) { auto fn = cantFail(Interp->getSymbolAddress(MangledName)).toPtr(); EXPECT_EQ(42, fn(NewA.getPtr())); - // FIXME: release the memory. - __lsan_ignore_object(NewA.getPtr()); + // FIXME: Consider providing an option in clang::Value to take ownership of + // the memory created from the interpreter. + free(NewA.getPtr()); } #ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC ``` I think that's going to work. https://github.com/llvm/llvm-project/pull/76218 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
vitalybuka wrote: @vgvassilev I end up with suppression, please check, when you have time, if this can be done better way, or just remove FIXME. https://github.com/llvm/llvm-project/pull/76218 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
vgvassilev wrote: If the fix is not trivial please revert it since I am not on my laptop (very late on my end) https://github.com/llvm/llvm-project/pull/76218 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
vitalybuka wrote: Looks like after this patch https://lab.llvm.org/buildbot/#/builders/236/builds/8819 https://github.com/llvm/llvm-project/pull/76218 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
https://github.com/vgvassilev closed https://github.com/llvm/llvm-project/pull/76218 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
https://github.com/vgvassilev updated https://github.com/llvm/llvm-project/pull/76218 >From 9d24f6d18450ba035279945bb8bb780c1a1f126f Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Fri, 22 Dec 2023 08:38:23 + Subject: [PATCH] [clang-repl] Add a interpreter-specific overload of operator new for C++. This patch brings back the basic support for C by inserting the required for value printing runtime only when we are in C++ mode. Additionally, it defines a new overload of operator placement new because we can't really forward declare it in a library-agnostic way. Fixes the issue described in llvm/llvm-project#69072. --- clang/include/clang/Interpreter/Interpreter.h | 4 +-- clang/lib/Interpreter/Interpreter.cpp | 33 +++ clang/test/Interpreter/incremental-mode.cpp | 3 +- .../unittests/Interpreter/InterpreterTest.cpp | 29 +++- 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h index 01858dfcc90ac5..292fa566ae7037 100644 --- a/clang/include/clang/Interpreter/Interpreter.h +++ b/clang/include/clang/Interpreter/Interpreter.h @@ -129,7 +129,7 @@ class Interpreter { llvm::Expected getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const; - enum InterfaceKind { NoAlloc, WithAlloc, CopyArray }; + enum InterfaceKind { NoAlloc, WithAlloc, CopyArray, NewTag }; const llvm::SmallVectorImpl () const { return ValuePrintingInfo; @@ -144,7 +144,7 @@ class Interpreter { llvm::DenseMap Dtors; - llvm::SmallVector ValuePrintingInfo; + llvm::SmallVector ValuePrintingInfo; }; } // namespace clang diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index 734fe90d0d89b4..d1764d07dfd240 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -249,7 +249,7 @@ 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; +#ifdef __cplusplus void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*); @@ -257,15 +257,18 @@ const char *const Runtimes = R"( void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double); void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long long); +struct __clang_Interpreter_NewTag{} __ci_newtag; +void* operator new(__SIZE_TYPE__, void* __p, __clang_Interpreter_NewTag) noexcept; template 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]); +new ((void*)(((T*)Placement) + Idx), __ci_newtag) T(Src[Idx]); } template void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* Placement, unsigned long Size) { __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size); } +#endif // __cplusplus )"; llvm::Expected> @@ -280,7 +283,7 @@ Interpreter::create(std::unique_ptr CI) { if (!PTU) return PTU.takeError(); - Interp->ValuePrintingInfo.resize(3); + Interp->ValuePrintingInfo.resize(4); // FIXME: This is a ugly hack. Undo command checks its availability by looking // at the size of the PTU list. However we have parsed something in the // beginning of the REPL so we have to mark them as 'Irrevocable'. @@ -501,7 +504,7 @@ Interpreter::CompileDtorCall(CXXRecordDecl *CXXRD) { static constexpr llvm::StringRef MagicRuntimeInterface[] = { "__clang_Interpreter_SetValueNoAlloc", "__clang_Interpreter_SetValueWithAlloc", -"__clang_Interpreter_SetValueCopyArr"}; +"__clang_Interpreter_SetValueCopyArr", "__ci_newtag"}; bool Interpreter::FindRuntimeInterface() { if (llvm::all_of(ValuePrintingInfo, [](Expr *E) { return E != nullptr; })) @@ -531,6 +534,9 @@ bool Interpreter::FindRuntimeInterface() { if (!LookupInterface(ValuePrintingInfo[CopyArray], MagicRuntimeInterface[CopyArray])) return false; + if (!LookupInterface(ValuePrintingInfo[NewTag], + MagicRuntimeInterface[NewTag])) +return false; return true; } @@ -608,7 +614,9 @@ class RuntimeInterfaceBuilder .getValuePrintingInfo()[Interpreter::InterfaceKind::CopyArray], SourceLocation(), Args, SourceLocation()); } - Expr *Args[] = {AllocCall.get()}; + Expr *Args[] = { + AllocCall.get(), + Interp.getValuePrintingInfo()[Interpreter::InterfaceKind::NewTag]}; ExprResult CXXNewCall = S.BuildCXXNew(
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
https://github.com/hahnjo approved this pull request. Looks good (sorry, this fell through) https://github.com/llvm/llvm-project/pull/76218 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
vgvassilev wrote: Ping. https://github.com/llvm/llvm-project/pull/76218 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
https://github.com/vgvassilev updated https://github.com/llvm/llvm-project/pull/76218 >From a3f213ef4a7e293152c272cce78ad5d10a3ede52 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Fri, 22 Dec 2023 08:38:23 + Subject: [PATCH] [clang-repl] Add a interpreter-specific overload of operator new for C++. This patch brings back the basic support for C by inserting the required for value printing runtime only when we are in C++ mode. Additionally, it defines a new overload of operator placement new because we can't really forward declare it in a library-agnostic way. Fixes the issue described in llvm/llvm-project#69072. --- clang/include/clang/Interpreter/Interpreter.h | 4 +-- clang/lib/Interpreter/Interpreter.cpp | 33 +++ clang/test/Interpreter/incremental-mode.cpp | 3 +- .../unittests/Interpreter/InterpreterTest.cpp | 29 +++- 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h index 01858dfcc90ac5..292fa566ae7037 100644 --- a/clang/include/clang/Interpreter/Interpreter.h +++ b/clang/include/clang/Interpreter/Interpreter.h @@ -129,7 +129,7 @@ class Interpreter { llvm::Expected getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const; - enum InterfaceKind { NoAlloc, WithAlloc, CopyArray }; + enum InterfaceKind { NoAlloc, WithAlloc, CopyArray, NewTag }; const llvm::SmallVectorImpl () const { return ValuePrintingInfo; @@ -144,7 +144,7 @@ class Interpreter { llvm::DenseMap Dtors; - llvm::SmallVector ValuePrintingInfo; + llvm::SmallVector ValuePrintingInfo; }; } // namespace clang diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index c9fcef5b5b5af1..9f97a3c6b0be9e 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -248,7 +248,7 @@ 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; +#ifdef __cplusplus void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*); @@ -256,15 +256,18 @@ const char *const Runtimes = R"( void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double); void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long long); +struct __clang_Interpreter_NewTag{} __ci_newtag; +void* operator new(__SIZE_TYPE__, void* __p, __clang_Interpreter_NewTag) noexcept; template 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]); +new ((void*)(((T*)Placement) + Idx), __ci_newtag) T(Src[Idx]); } template void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* Placement, unsigned long Size) { __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size); } +#endif // __cplusplus )"; llvm::Expected> @@ -279,7 +282,7 @@ Interpreter::create(std::unique_ptr CI) { if (!PTU) return PTU.takeError(); - Interp->ValuePrintingInfo.resize(3); + Interp->ValuePrintingInfo.resize(4); // FIXME: This is a ugly hack. Undo command checks its availability by looking // at the size of the PTU list. However we have parsed something in the // beginning of the REPL so we have to mark them as 'Irrevocable'. @@ -500,7 +503,7 @@ Interpreter::CompileDtorCall(CXXRecordDecl *CXXRD) { static constexpr llvm::StringRef MagicRuntimeInterface[] = { "__clang_Interpreter_SetValueNoAlloc", "__clang_Interpreter_SetValueWithAlloc", -"__clang_Interpreter_SetValueCopyArr"}; +"__clang_Interpreter_SetValueCopyArr", "__ci_newtag"}; bool Interpreter::FindRuntimeInterface() { if (llvm::all_of(ValuePrintingInfo, [](Expr *E) { return E != nullptr; })) @@ -530,6 +533,9 @@ bool Interpreter::FindRuntimeInterface() { if (!LookupInterface(ValuePrintingInfo[CopyArray], MagicRuntimeInterface[CopyArray])) return false; + if (!LookupInterface(ValuePrintingInfo[NewTag], + MagicRuntimeInterface[NewTag])) +return false; return true; } @@ -607,7 +613,9 @@ class RuntimeInterfaceBuilder .getValuePrintingInfo()[Interpreter::InterfaceKind::CopyArray], SourceLocation(), Args, SourceLocation()); } - Expr *Args[] = {AllocCall.get()}; + Expr *Args[] = { + AllocCall.get(), + Interp.getValuePrintingInfo()[Interpreter::InterfaceKind::NewTag]}; ExprResult CXXNewCall = S.BuildCXXNew(
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
https://github.com/vgvassilev updated https://github.com/llvm/llvm-project/pull/76218 >From 50a08a2a04c97b0ed5630c53f549a1331e18aee7 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Fri, 22 Dec 2023 08:38:23 + Subject: [PATCH] [clang-repl] Add a interpreter-specific overload of operator new for C++. This patch brings back the basic support for C by inserting the required for value printing runtime only when we are in C++ mode. Additionally, it defines a new overload of operator placement new because we can't really forward declare it in a library-agnostic way. Fixes the issue described in llvm/llvm-project#69072. --- clang/include/clang/Interpreter/Interpreter.h | 4 +-- clang/lib/Interpreter/Interpreter.cpp | 33 +++ clang/test/Interpreter/incremental-mode.cpp | 3 +- .../unittests/Interpreter/InterpreterTest.cpp | 29 +++- 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h index 01858dfcc90ac5..292fa566ae7037 100644 --- a/clang/include/clang/Interpreter/Interpreter.h +++ b/clang/include/clang/Interpreter/Interpreter.h @@ -129,7 +129,7 @@ class Interpreter { llvm::Expected getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const; - enum InterfaceKind { NoAlloc, WithAlloc, CopyArray }; + enum InterfaceKind { NoAlloc, WithAlloc, CopyArray, NewTag }; const llvm::SmallVectorImpl () const { return ValuePrintingInfo; @@ -144,7 +144,7 @@ class Interpreter { llvm::DenseMap Dtors; - llvm::SmallVector ValuePrintingInfo; + llvm::SmallVector ValuePrintingInfo; }; } // namespace clang diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index c9fcef5b5b5af1..82a4217ad37aa2 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -248,7 +248,7 @@ 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; +#ifdef __cplusplus void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*); @@ -256,15 +256,18 @@ const char *const Runtimes = R"( void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double); void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long long); +struct __clang_Interpreter_NewTag{} __ci_newtag; +void* operator new(__SIZE_TYPE__, void* __p, __clang_Interpreter_NewTag) noexcept; template 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]); +new ((void*)(((T*)Placement) + Idx), __ci_newtag) T(Src[Idx]); } template void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* Placement, unsigned long Size) { __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size); } +#endif // __cplusplus )"; llvm::Expected> @@ -279,7 +282,7 @@ Interpreter::create(std::unique_ptr CI) { if (!PTU) return PTU.takeError(); - Interp->ValuePrintingInfo.resize(3); + Interp->ValuePrintingInfo.resize(4); // FIXME: This is a ugly hack. Undo command checks its availability by looking // at the size of the PTU list. However we have parsed something in the // beginning of the REPL so we have to mark them as 'Irrevocable'. @@ -500,7 +503,7 @@ Interpreter::CompileDtorCall(CXXRecordDecl *CXXRD) { static constexpr llvm::StringRef MagicRuntimeInterface[] = { "__clang_Interpreter_SetValueNoAlloc", "__clang_Interpreter_SetValueWithAlloc", -"__clang_Interpreter_SetValueCopyArr"}; +"__clang_Interpreter_SetValueCopyArr", "__ci_newtag"}; bool Interpreter::FindRuntimeInterface() { if (llvm::all_of(ValuePrintingInfo, [](Expr *E) { return E != nullptr; })) @@ -530,6 +533,9 @@ bool Interpreter::FindRuntimeInterface() { if (!LookupInterface(ValuePrintingInfo[CopyArray], MagicRuntimeInterface[CopyArray])) return false; + if (!LookupInterface(ValuePrintingInfo[NewTag], + MagicRuntimeInterface[NewTag])) +return false; return true; } @@ -607,7 +613,9 @@ class RuntimeInterfaceBuilder .getValuePrintingInfo()[Interpreter::InterfaceKind::CopyArray], SourceLocation(), Args, SourceLocation()); } - Expr *Args[] = {AllocCall.get()}; + Expr *Args[] = { + AllocCall.get(), + Interp.getValuePrintingInfo()[Interpreter::InterfaceKind::NewTag]}; ExprResult CXXNewCall = S.BuildCXXNew(
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
https://github.com/vgvassilev updated https://github.com/llvm/llvm-project/pull/76218 >From c5f5ea4b38e7248a404c0e591d16145faeac388f Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Fri, 22 Dec 2023 08:38:23 + Subject: [PATCH] [clang-repl] Add a interpreter-specific overload of operator new for C++. This patch brings back the basic support for C by inserting the required for value printing runtime only when we are in C++ mode. Additionally, it defines a new overload of operator placement new because we can't really forward declare it in a library-agnostic way. Fixes the issue described in llvm/llvm-project#69072. --- clang/include/clang/Interpreter/Interpreter.h | 4 +-- clang/lib/Interpreter/Interpreter.cpp | 33 +++ clang/test/Interpreter/incremental-mode.cpp | 3 +- .../unittests/Interpreter/InterpreterTest.cpp | 29 +++- 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h index 01858dfcc90ac5..292fa566ae7037 100644 --- a/clang/include/clang/Interpreter/Interpreter.h +++ b/clang/include/clang/Interpreter/Interpreter.h @@ -129,7 +129,7 @@ class Interpreter { llvm::Expected getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const; - enum InterfaceKind { NoAlloc, WithAlloc, CopyArray }; + enum InterfaceKind { NoAlloc, WithAlloc, CopyArray, NewTag }; const llvm::SmallVectorImpl () const { return ValuePrintingInfo; @@ -144,7 +144,7 @@ class Interpreter { llvm::DenseMap Dtors; - llvm::SmallVector ValuePrintingInfo; + llvm::SmallVector ValuePrintingInfo; }; } // namespace clang diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index c9fcef5b5b5af1..83ca750e299792 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -248,7 +248,7 @@ 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; +#ifdef __cplusplus void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*); @@ -256,15 +256,18 @@ const char *const Runtimes = R"( void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double); void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long long); +struct __clang_Interpreter_NewTag{} __ci_newtag; +void* operator new(__SIZE_TYPE__, void* __p, __clang_Interpreter_NewTag) noexcept; template 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]); +new ((void*)(((T*)Placement) + Idx), __ci_newtag) T(Src[Idx]); } template void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* Placement, unsigned long Size) { __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size); } +#endif // __cplusplus )"; llvm::Expected> @@ -279,7 +282,7 @@ Interpreter::create(std::unique_ptr CI) { if (!PTU) return PTU.takeError(); - Interp->ValuePrintingInfo.resize(3); + Interp->ValuePrintingInfo.resize(4); // FIXME: This is a ugly hack. Undo command checks its availability by looking // at the size of the PTU list. However we have parsed something in the // beginning of the REPL so we have to mark them as 'Irrevocable'. @@ -500,7 +503,7 @@ Interpreter::CompileDtorCall(CXXRecordDecl *CXXRD) { static constexpr llvm::StringRef MagicRuntimeInterface[] = { "__clang_Interpreter_SetValueNoAlloc", "__clang_Interpreter_SetValueWithAlloc", -"__clang_Interpreter_SetValueCopyArr"}; +"__clang_Interpreter_SetValueCopyArr", "__ci_newtag"}; bool Interpreter::FindRuntimeInterface() { if (llvm::all_of(ValuePrintingInfo, [](Expr *E) { return E != nullptr; })) @@ -530,6 +533,9 @@ bool Interpreter::FindRuntimeInterface() { if (!LookupInterface(ValuePrintingInfo[CopyArray], MagicRuntimeInterface[CopyArray])) return false; + if (!LookupInterface(ValuePrintingInfo[NewTag], + MagicRuntimeInterface[NewTag])) +return false; return true; } @@ -607,7 +613,9 @@ class RuntimeInterfaceBuilder .getValuePrintingInfo()[Interpreter::InterfaceKind::CopyArray], SourceLocation(), Args, SourceLocation()); } - Expr *Args[] = {AllocCall.get()}; + Expr *Args[] = { + AllocCall.get(), + Interp.getValuePrintingInfo()[Interpreter::InterfaceKind::NewTag]}; ExprResult CXXNewCall = S.BuildCXXNew(
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
vgvassilev wrote: This PR should help compiler-research/CppInterOp#173 move forward. cc: @makslevental, @alexander-penev, @mcbarton https://github.com/llvm/llvm-project/pull/76218 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
https://github.com/vgvassilev updated https://github.com/llvm/llvm-project/pull/76218 >From 0578f4c1582abdc6d4695d5c3c460213d1f02f00 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Fri, 22 Dec 2023 08:38:23 + Subject: [PATCH] [clang-repl] Add a interpreter-specific overload of operator new for C++. This patch brings back the basic support for C by inserting the required for value printing runtime only when we are in C++ mode. Additionally, it defines a new overload of operator placement new because we can't really forward declare it in a library-agnostic way. Fixes the issue described in llvm/llvm-project#69072. --- clang/lib/Interpreter/Interpreter.cpp | 19 +-- clang/test/Interpreter/incremental-mode.cpp | 3 ++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index c9fcef5b5b5af1..b94493699f7fb9 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -248,7 +248,7 @@ 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; +#ifdef __cplusplus void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*); @@ -256,15 +256,18 @@ const char *const Runtimes = R"( void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double); void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long long); +struct __clang_Interpreter_NewTag{}; +void* operator new(__SIZE_TYPE__, void* __p, __clang_Interpreter_NewTag) noexcept; template 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]); +new ((void*)(((T*)Placement) + Idx), __clang_Interpreter_NewTag()) T(Src[Idx]); } template void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* Placement, unsigned long Size) { __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size); } +#endif // __cplusplus )"; llvm::Expected> @@ -814,3 +817,15 @@ __clang_Interpreter_SetValueNoAlloc(void *This, void *OutVal, void *OpaqueType, VRef = Value(static_cast(This), OpaqueType); VRef.setLongDouble(Val); } + +// A trampoline to work around the fact that operator placement new cannot +// really be forward declared due to libc++ and libstdc++ declaration mismatch. +// FIXME: __clang_Interpreter_NewTag is ODR violation because we get the same +// definition in the interpreter runtime. We should move it in a runtime header +// which gets included by the interpreter and here. +struct __clang_Interpreter_NewTag {}; +void *operator new(__SIZE_TYPE__ __sz, void *__p, + __clang_Interpreter_NewTag) noexcept { + // Just forward to the standard operator placement new. + return operator new(__sz, __p); +} diff --git a/clang/test/Interpreter/incremental-mode.cpp b/clang/test/Interpreter/incremental-mode.cpp index e6350d237ef578..d63cee0dd6d15f 100644 --- a/clang/test/Interpreter/incremental-mode.cpp +++ b/clang/test/Interpreter/incremental-mode.cpp @@ -1,3 +1,4 @@ // RUN: clang-repl -Xcc -E -// RUN: clang-repl -Xcc -emit-llvm +// RUN: clang-repl -Xcc -emit-llvm +// RUN: clang-repl -Xcc -xc // expected-no-diagnostics ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Vassil Vassilev (vgvassilev) Changes This patch brings back the basic support for C by inserting the required for value printing runtime only when we are in C++ mode. Additionally, it defines a new overload of operator placement new because we can't really forward declare it in a library-agnostic way. Fixes the issue described in llvm/llvm-project#69072. --- Full diff: https://github.com/llvm/llvm-project/pull/76218.diff 2 Files Affected: - (modified) clang/lib/Interpreter/Interpreter.cpp (+16-2) - (modified) clang/test/Interpreter/incremental-mode.cpp (+2-1) ``diff diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index c9fcef5b5b5af1..daceabafe4c938 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -248,7 +248,7 @@ 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; +#ifdef __cplusplus void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*); @@ -256,15 +256,18 @@ const char *const Runtimes = R"( void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double); void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long long); +struct __clang_Interpreter_NewTag{}; +void* operator new(__SIZE_TYPE__, void* __p, __clang_Interpreter_NewTag) noexcept; template 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]); +new ((void*)(((T*)Placement) + Idx), __clang_Interpreter_NewTag()) T(Src[Idx]); } template void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* Placement, unsigned long Size) { __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size); } +#endif // __cplusplus )"; llvm::Expected> @@ -814,3 +817,14 @@ __clang_Interpreter_SetValueNoAlloc(void *This, void *OutVal, void *OpaqueType, VRef = Value(static_cast(This), OpaqueType); VRef.setLongDouble(Val); } + +// A trampoline to work around the fact that operator placement new cannot +// really be forward declared due to libc++ and libstdc++ declaration mismatch. +// FIXME: __clang_Interpreter_NewTag is ODR violation because we get the same +// definition in the interpreter runtime. We should move it in a runtime header +// which gets included by the interpreter and here. +struct __clang_Interpreter_NewTag{}; +void* operator new(__SIZE_TYPE__ __sz, void* __p, __clang_Interpreter_NewTag) noexcept { + // Just forward to the standard operator placement new. + return operator new(__sz, __p); +} diff --git a/clang/test/Interpreter/incremental-mode.cpp b/clang/test/Interpreter/incremental-mode.cpp index e6350d237ef578..d63cee0dd6d15f 100644 --- a/clang/test/Interpreter/incremental-mode.cpp +++ b/clang/test/Interpreter/incremental-mode.cpp @@ -1,3 +1,4 @@ // RUN: clang-repl -Xcc -E -// RUN: clang-repl -Xcc -emit-llvm +// RUN: clang-repl -Xcc -emit-llvm +// RUN: clang-repl -Xcc -xc // expected-no-diagnostics `` https://github.com/llvm/llvm-project/pull/76218 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)
https://github.com/vgvassilev created https://github.com/llvm/llvm-project/pull/76218 This patch brings back the basic support for C by inserting the required for value printing runtime only when we are in C++ mode. Additionally, it defines a new overload of operator placement new because we can't really forward declare it in a library-agnostic way. Fixes the issue described in llvm/llvm-project#69072. >From 114b93d587509acde0f65b50e7abbf571c5d2613 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Fri, 22 Dec 2023 08:38:23 + Subject: [PATCH] [clang-repl] Add a interpreter-specific overload of operator new for C++. This patch brings back the basic support for C by inserting the required for value printing runtime only when we are in C++ mode. Additionally, it defines a new overload of operator placement new because we can't really forward declare it in a library-agnostic way. Fixes the issue described in llvm/llvm-project#69072. --- clang/lib/Interpreter/Interpreter.cpp | 18 -- clang/test/Interpreter/incremental-mode.cpp | 3 ++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index c9fcef5b5b5af1..daceabafe4c938 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -248,7 +248,7 @@ 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; +#ifdef __cplusplus void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*); @@ -256,15 +256,18 @@ const char *const Runtimes = R"( void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double); void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long long); +struct __clang_Interpreter_NewTag{}; +void* operator new(__SIZE_TYPE__, void* __p, __clang_Interpreter_NewTag) noexcept; template 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]); +new ((void*)(((T*)Placement) + Idx), __clang_Interpreter_NewTag()) T(Src[Idx]); } template void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* Placement, unsigned long Size) { __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size); } +#endif // __cplusplus )"; llvm::Expected> @@ -814,3 +817,14 @@ __clang_Interpreter_SetValueNoAlloc(void *This, void *OutVal, void *OpaqueType, VRef = Value(static_cast(This), OpaqueType); VRef.setLongDouble(Val); } + +// A trampoline to work around the fact that operator placement new cannot +// really be forward declared due to libc++ and libstdc++ declaration mismatch. +// FIXME: __clang_Interpreter_NewTag is ODR violation because we get the same +// definition in the interpreter runtime. We should move it in a runtime header +// which gets included by the interpreter and here. +struct __clang_Interpreter_NewTag{}; +void* operator new(__SIZE_TYPE__ __sz, void* __p, __clang_Interpreter_NewTag) noexcept { + // Just forward to the standard operator placement new. + return operator new(__sz, __p); +} diff --git a/clang/test/Interpreter/incremental-mode.cpp b/clang/test/Interpreter/incremental-mode.cpp index e6350d237ef578..d63cee0dd6d15f 100644 --- a/clang/test/Interpreter/incremental-mode.cpp +++ b/clang/test/Interpreter/incremental-mode.cpp @@ -1,3 +1,4 @@ // RUN: clang-repl -Xcc -E -// RUN: clang-repl -Xcc -emit-llvm +// RUN: clang-repl -Xcc -emit-llvm +// RUN: clang-repl -Xcc -xc // expected-no-diagnostics ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits