From c659c42920d9c95373fa569615a62bac4db873c6 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Thu, 17 Aug 2023 15:55:06 +0200 Subject: [PATCH 1/2] [cling] Cast to base element type pointer before calling copyArray (For context, this is important for multi-dimensional constant arrays as described in ROOT-7016 and tested in Cling's Interfaces/evaluate.C test. But for reasons unknown to me, the ROOT prompt now seems to have a different way of handling this case because just reverting commit d97e4dca363 still works there...) Instead of using relying on recursive templated calls, perform the type cast in the ValueExtractionSynthesizer. This has the advantage of avoiding an ODR violation warning in MultipleInterpreters.C with LLVM 16 (while unclear if that one is correct or not). --- .../cling/include/cling/Interpreter/RuntimeUniverse.h | 8 +------- .../cling/lib/Interpreter/ValueExtractionSynthesizer.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/interpreter/cling/include/cling/Interpreter/RuntimeUniverse.h b/interpreter/cling/include/cling/Interpreter/RuntimeUniverse.h index 446a37e69f3a6..c6f0f2eab0972 100644 --- a/interpreter/cling/include/cling/Interpreter/RuntimeUniverse.h +++ b/interpreter/cling/include/cling/Interpreter/RuntimeUniverse.h @@ -171,17 +171,11 @@ namespace cling { ///\param[in] placement - where to copy ///\param[in] size - size of the array. /// - template + template void copyArray(T* src, void* placement, std::size_t size) { for (std::size_t i = 0; i < size; ++i) new ((void*)(((T*)placement) + i)) T(src[i]); } - - // "size" is the number of elements even for subarrays; flatten the type: - template - void copyArray(const T (*src)[N], void* placement, std::size_t size) { - copyArray(src[0], placement, size); - } } // end namespace internal } // end namespace runtime } // end namespace cling diff --git a/interpreter/cling/lib/Interpreter/ValueExtractionSynthesizer.cpp b/interpreter/cling/lib/Interpreter/ValueExtractionSynthesizer.cpp index 830d50ace2583..cf6d6cdf2979a 100644 --- a/interpreter/cling/lib/Interpreter/ValueExtractionSynthesizer.cpp +++ b/interpreter/cling/lib/Interpreter/ValueExtractionSynthesizer.cpp @@ -295,7 +295,14 @@ namespace { if (const ConstantArrayType* constArray = dyn_cast(desugaredTy.getTypePtr())) { CallArgs.clear(); - CallArgs.push_back(E); + // Get a pointer to the base element type so the instantiated copyArray + // template can do placement new. + QualType baseElementType = m_Context->getBaseElementType(desugaredTy); + TypeSourceInfo* TSI = m_Context->getTrivialTypeSourceInfo( + m_Context->getPointerType(baseElementType), noLoc); + Expr* srcPointer = + m_Sema->BuildCStyleCastExpr(noLoc, TSI, noLoc, E).get(); + CallArgs.push_back(srcPointer); CallArgs.push_back(placement); size_t arrSize = m_Context->getConstantArrayElementCount(constArray); From a2b74c58d6d804f291f4cf4b56eede6099c0d199 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Thu, 17 Aug 2023 15:59:40 +0200 Subject: [PATCH 2/2] [cling] Fix assertion in ExternalInterpreterSource As far as I can understand the intent, this wants to check that the diagnostic is *not* because it's an unsupported AST node. --- interpreter/cling/lib/Interpreter/ExternalInterpreterSource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interpreter/cling/lib/Interpreter/ExternalInterpreterSource.cpp b/interpreter/cling/lib/Interpreter/ExternalInterpreterSource.cpp index 42d2a2dcf1422..1c83a4e0ecb3f 100644 --- a/interpreter/cling/lib/Interpreter/ExternalInterpreterSource.cpp +++ b/interpreter/cling/lib/Interpreter/ExternalInterpreterSource.cpp @@ -111,7 +111,7 @@ namespace cling { const Decl* To = llvm::cantFail(m_Importer->Import(declToImport)); assert(To && "Import did not work!"); assert((DS.empty() || - DS[0].getID() == clang::diag::err_unsupported_ast_node) && + DS[0].getID() != clang::diag::err_unsupported_ast_node) && "Import not supported!"); #endif return;