diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bf78a214..8b2df5b4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,13 +67,25 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) include(GNUInstallDirs) ## Define supported version of clang and llvm - set(CLANG_MIN_SUPPORTED 13.0) +if (CPPINTEROP_USE_CLING) + set(CLANG_MIN_SUPPORTED 18.0) +else() + set(CLANG_MIN_SUPPORTED 16.0) +endif(CPPINTEROP_USE_CLING) set(CLANG_MAX_SUPPORTED "20.1.x") set(CLANG_VERSION_UPPER_BOUND 21.0.0) - set(LLD_MIN_SUPPORTED 13.0) +if (CPPINTEROP_USE_CLING) + set(LLD_MIN_SUPPORTED 18.0) +else() + set(LLD_MIN_SUPPORTED 16.0) +endif(CPPINTEROP_USE_CLING) set(LLD_MAX_SUPPORTED "20.1.x") set(LLD_VERSION_UPPER_BOUND 21.0.0) - set(LLVM_MIN_SUPPORTED 13.0) +if (CPPINTEROP_USE_CLING) + set(LLVM_MIN_SUPPORTED 18.0) +else() + set(LLVM_MIN_SUPPORTED 16.0) +endif(CPPINTEROP_USE_CLING) set(LLVM_MAX_SUPPORTED "20.1.x") set(LLVM_VERSION_UPPER_BOUND 21.0.0) @@ -230,21 +242,12 @@ endif() message(STATUS "Found supported version: Clang ${CLANG_PACKAGE_VERSION}") message(STATUS "Using ClangConfig.cmake in: ${Clang_DIR}") - ## Clang 13 require c++14 or later, Clang 16 require c++17 or later. - if (CLANG_VERSION_MAJOR GREATER_EQUAL 16) - if (NOT CMAKE_CXX_STANDARD) - set (CMAKE_CXX_STANDARD 17) - endif() - if (CMAKE_CXX_STANDARD LESS 17) - message(fatal "LLVM/CppInterOp requires c++17 or later") - endif() - elseif (CLANG_VERSION_MAJOR GREATER_EQUAL 13) - if (NOT CMAKE_CXX_STANDARD) - set (CMAKE_CXX_STANDARD 14) - endif() - if (CMAKE_CXX_STANDARD LESS 14) - message(fatal "LLVM/CppInterOp requires c++14 or later") - endif() + ## Clang 16 require c++17 or later. + if (NOT CMAKE_CXX_STANDARD) + set (CMAKE_CXX_STANDARD 17) + endif() + if (CMAKE_CXX_STANDARD LESS 17) + message(fatal "LLVM/CppInterOp requires c++17 or later") endif() ## Find supported Cling diff --git a/README.md b/README.md index 8d3e9b45e..1db3d03ce 100644 --- a/README.md +++ b/README.md @@ -190,9 +190,10 @@ Use the following build instructions to build on Linux and MacOS ```bash git clone https://github.com/root-project/cling.git cd ./cling/ -git checkout tags/v1.0 +git checkout tags/v1.2 +git apply -v ../CppInterOp/patches/llvm/cling1.2-LookupHelper.patch cd .. -git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git +git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git mkdir llvm-project/build cd llvm-project/build cmake -DLLVM_ENABLE_PROJECTS=clang \ @@ -208,7 +209,6 @@ cmake -DLLVM_ENABLE_PROJECTS=clang \ ../llvm cmake --build . --target clang --parallel $(nproc --all) cmake --build . --target cling --parallel $(nproc --all) -cmake --build . --target gtest_main --parallel $(nproc --all) ``` Use the following build instructions to build on Windows @@ -216,9 +216,10 @@ Use the following build instructions to build on Windows ```powershell git clone https://github.com/root-project/cling.git cd .\cling\ -git checkout tags/v1.0 +git checkout tags/v1.2 +git apply -v ..\CppInterOp\patches\llvm\cling1.2-LookupHelper.patch cd .. -git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git +git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git $env:ncpus = %NUMBER_OF_PROCESSORS% $env:PWD_DIR= $PWD.Path $env:CLING_DIR="$env:PWD_DIR\cling" @@ -237,7 +238,6 @@ cmake -DLLVM_ENABLE_PROJECTS=clang ` ../llvm cmake --build . --target clang --parallel $env:ncpus cmake --build . --target cling --parallel $env:ncpus -cmake --build . --target gtest_main --parallel $env:ncpus ``` Note the 'llvm-project' directory location. On linux and MacOS you execute the following diff --git a/docs/DevelopersDocumentation.rst b/docs/DevelopersDocumentation.rst index 7ece53747..32d2e2fbb 100644 --- a/docs/DevelopersDocumentation.rst +++ b/docs/DevelopersDocumentation.rst @@ -129,9 +129,10 @@ build instructions to build on Linux and MacOS git clone https://github.com/root-project/cling.git cd ./cling/ - git checkout tags/v1.0 + git checkout tags/v1.2 + git apply -v ../CppInterOp/patches/llvm/cling1.2-LookupHelper.patch cd .. - git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git + git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git mkdir llvm-project/build cd llvm-project/build cmake -DLLVM_ENABLE_PROJECTS=clang \ @@ -147,7 +148,6 @@ build instructions to build on Linux and MacOS ../llvm cmake --build . --target clang --parallel $(nproc --all) cmake --build . --target cling --parallel $(nproc --all) - cmake --build . --target gtest_main --parallel $(nproc --all) Use the following build instructions to build on Windows @@ -155,9 +155,10 @@ Use the following build instructions to build on Windows git clone https://github.com/root-project/cling.git cd .\cling\ - git checkout tags/v1.0 + git checkout tags/v1.2 + git apply -v ..\CppInterOp\patches\llvm\cling1.2-LookupHelper.patch cd .. - git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git + git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git $env:ncpus = %NUMBER_OF_PROCESSORS% $env:PWD_DIR= $PWD.Path $env:CLING_DIR="$env:PWD_DIR\cling" @@ -176,7 +177,6 @@ Use the following build instructions to build on Windows ../llvm cmake --build . --target clang --parallel $env:ncpus cmake --build . --target cling --parallel $env:ncpus - cmake --build . --target gtest_main --parallel $env:ncpus Note the 'llvm-project' directory location. On linux and MacOS you execute the following diff --git a/docs/InstallationAndUsage.rst b/docs/InstallationAndUsage.rst index 72ddff1a6..df20c773e 100644 --- a/docs/InstallationAndUsage.rst +++ b/docs/InstallationAndUsage.rst @@ -129,9 +129,10 @@ build instructions to build on Linux and MacOS git clone https://github.com/root-project/cling.git cd ./cling/ - git checkout tags/v1.0 + git checkout tags/v1.2 + git apply -v ../CppInterOp/patches/llvm/cling1.2-LookupHelper.patch cd .. - git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git + git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git mkdir llvm-project/build cd llvm-project/build cmake -DLLVM_ENABLE_PROJECTS=clang \ @@ -147,7 +148,6 @@ build instructions to build on Linux and MacOS ../llvm cmake --build . --target clang --parallel $(nproc --all) cmake --build . --target cling --parallel $(nproc --all) - cmake --build . --target gtest_main --parallel $(nproc --all) Use the following build instructions to build on Windows @@ -155,9 +155,10 @@ Use the following build instructions to build on Windows git clone https://github.com/root-project/cling.git cd .\cling\ - git checkout tags/v1.0 + git checkout tags/v1.2 + git apply -v ..\CppInterOp\patches\llvm\cling1.2-LookupHelper.patch cd .. - git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git + git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git $env:ncpus = %NUMBER_OF_PROCESSORS% $env:PWD_DIR= $PWD.Path $env:CLING_DIR="$env:PWD_DIR\cling" @@ -176,7 +177,6 @@ Use the following build instructions to build on Windows ../llvm cmake --build . --target clang --parallel $env:ncpus cmake --build . --target cling --parallel $env:ncpus - cmake --build . --target gtest_main --parallel $env:ncpus Note the 'llvm-project' directory location. On linux and MacOS you execute the following diff --git a/lib/CppInterOp/CXCppInterOp.cpp b/lib/CppInterOp/CXCppInterOp.cpp index ddfd07513..a5e6eb07f 100644 --- a/lib/CppInterOp/CXCppInterOp.cpp +++ b/lib/CppInterOp/CXCppInterOp.cpp @@ -200,9 +200,7 @@ CXTypeKind cxtype_GetTypeKind(QualType T) { TKCASE(Elaborated); TKCASE(Pipe); TKCASE(Attributed); -#if CLANG_VERSION_MAJOR >= 16 TKCASE(BTFTagAttributed); -#endif TKCASE(Atomic); default: return CXType_Unexposed; diff --git a/lib/CppInterOp/Compatibility.h b/lib/CppInterOp/Compatibility.h index 45d778cee..977603ea0 100644 --- a/lib/CppInterOp/Compatibility.h +++ b/lib/CppInterOp/Compatibility.h @@ -122,12 +122,8 @@ getSymbolAddress(cling::Interpreter& I, llvm::StringRef IRName) { llvm::orc::SymbolNameVector Names; llvm::orc::ExecutionSession& ES = Jit.getExecutionSession(); Names.push_back(ES.intern(IRName)); -#if CLANG_VERSION_MAJOR < 16 - return llvm::make_error(Names); -#else return llvm::make_error(ES.getSymbolStringPool(), std::move(Names)); -#endif // CLANG_VERSION_MAJOR } inline void codeComplete(std::vector& Results, @@ -208,9 +204,6 @@ namespace compat { inline std::unique_ptr createClangInterpreter(std::vector& args) { -#if CLANG_VERSION_MAJOR < 16 - auto ciOrErr = clang::IncrementalCompilerBuilder::create(args); -#else auto has_arg = [](const char* x, llvm::StringRef match = "cuda") { llvm::StringRef Arg = x; Arg = Arg.trim().ltrim('-'); @@ -240,15 +233,11 @@ createClangInterpreter(std::vector& args) { DeviceCI = std::move(*devOrErr); } auto ciOrErr = CudaEnabled ? CB.CreateCudaHost() : CB.CreateCpp(); -#endif // CLANG_VERSION_MAJOR < 16 if (!ciOrErr) { llvm::logAllUnhandledErrors(ciOrErr.takeError(), llvm::errs(), "Failed to build Incremental compiler:"); return nullptr; } -#if CLANG_VERSION_MAJOR < 16 - auto innerOrErr = clang::Interpreter::create(std::move(*ciOrErr)); -#else (*ciOrErr)->LoadRequestedPlugins(); if (CudaEnabled) DeviceCI->LoadRequestedPlugins(); @@ -256,7 +245,6 @@ createClangInterpreter(std::vector& args) { CudaEnabled ? clang::Interpreter::createWithCUDA(std::move(*ciOrErr), std::move(DeviceCI)) : clang::Interpreter::create(std::move(*ciOrErr)); -#endif // CLANG_VERSION_MAJOR < 16 if (!innerOrErr) { llvm::logAllUnhandledErrors(innerOrErr.takeError(), llvm::errs(), @@ -303,29 +291,15 @@ inline void maybeMangleDeclName(const clang::GlobalDecl& GD, RawStr.flush(); } -// Clang 13 - Initial implementation of Interpreter and clang-repl -// Clang 14 - Add new Interpreter methods: getExecutionEngine, -// getSymbolAddress, getSymbolAddressFromLinkerName -// Clang 15 - Add new Interpreter methods: Undo // Clang 18 - Add new Interpreter methods: CodeComplete inline llvm::orc::LLJIT* getExecutionEngine(clang::Interpreter& I) { -#if CLANG_VERSION_MAJOR >= 14 auto* engine = &llvm::cantFail(I.getExecutionEngine()); return const_cast(engine); -#else - assert(0 && "Not implemented in Clang <14!"); - return nullptr; -#endif } inline llvm::Expected getSymbolAddress(clang::Interpreter& I, llvm::StringRef IRName) { -#if CLANG_VERSION_MAJOR < 14 - assert(0 && "Not implemented in Clang <14!"); - return llvm::createStringError(llvm::inconvertibleErrorCode(), - "Not implemented in Clang <14!"); -#endif // CLANG_VERSION_MAJOR < 14 auto AddrOrErr = I.getSymbolAddress(IRName); if (llvm::Error Err = AddrOrErr.takeError()) @@ -343,7 +317,6 @@ getSymbolAddress(clang::Interpreter& I, clang::GlobalDecl GD) { inline llvm::Expected getSymbolAddressFromLinkerName(clang::Interpreter& I, llvm::StringRef LinkerName) { -#if CLANG_VERSION_MAJOR >= 14 const auto& DL = getExecutionEngine(I)->getDataLayout(); char GlobalPrefix = DL.getGlobalPrefix(); std::string LinkerNameTmp(LinkerName); @@ -354,21 +327,10 @@ getSymbolAddressFromLinkerName(clang::Interpreter& I, if (llvm::Error Err = AddrOrErr.takeError()) return std::move(Err); return AddrOrErr->getValue(); -#else - assert(0 && "Not implemented in Clang <14!"); - return llvm::createStringError(llvm::inconvertibleErrorCode(), - "Not implemented in Clang <14!"); -#endif } inline llvm::Error Undo(clang::Interpreter& I, unsigned N = 1) { -#if CLANG_VERSION_MAJOR >= 15 return I.Undo(N); -#else - assert(0 && "Not implemented in Clang <15!"); - return llvm::createStringError(llvm::inconvertibleErrorCode(), - "Not implemented in Clang <15!"); -#endif } inline void codeComplete(std::vector& Results, @@ -421,35 +383,14 @@ using Interpreter = Cpp::Interpreter; namespace compat { // Clang >= 14 change type name to string (spaces formatting problem) -#if CLANG_VERSION_MAJOR >= 14 inline std::string FixTypeName(const std::string type_name) { return type_name; } -#else -inline std::string FixTypeName(const std::string type_name) { - std::string result = type_name; - size_t pos = 0; - while ((pos = result.find(" [", pos)) != std::string::npos) { - result.erase(pos, 1); - pos++; - } - return result; -} -#endif -// Clang >= 16 change CLANG_LIBDIR_SUFFIX to CLANG_INSTALL_LIBDIR_BASENAME -#if CLANG_VERSION_MAJOR < 16 -#define CLANG_INSTALL_LIBDIR_BASENAME (llvm::Twine("lib") + CLANG_LIBDIR_SUFFIX) -#endif inline std::string MakeResourceDir(llvm::StringRef Dir) { llvm::SmallString<128> P(Dir); llvm::sys::path::append(P, CLANG_INSTALL_LIBDIR_BASENAME, "clang", -#if CLANG_VERSION_MAJOR < 16 - CLANG_VERSION_STRING -#else - CLANG_VERSION_MAJOR_STRING -#endif - ); + CLANG_VERSION_MAJOR_STRING); return std::string(P.str()); } diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index e4fd6296a..78c95a307 100755 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -3071,12 +3071,7 @@ std::string DetectResourceDir(const char* ClangBinaryName /* = clang */) { std::string detected_resource_dir = outs.back(); - std::string version = -#if CLANG_VERSION_MAJOR < 16 - CLANG_VERSION_STRING; -#else - CLANG_VERSION_MAJOR_STRING; -#endif + std::string version = CLANG_VERSION_MAJOR_STRING; // We need to check if the detected resource directory is compatible. if (llvm::sys::path::filename(detected_resource_dir) != version) return ""; diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index cff329553..0ea65be87 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -11,7 +11,6 @@ if(EMSCRIPTEN) set(gtest_libs gtest gmock) else() set(gtest_libs gtest gtest_main) - # Clang prior than clang13 (I think) merges both gmock into gtest. if (TARGET gmock) list(APPEND gtest_libs gmock gmock_main) endif() diff --git a/unittests/CppInterOp/CUDATest.cpp b/unittests/CppInterOp/CUDATest.cpp index 522ec08ca..45b41c94d 100644 --- a/unittests/CppInterOp/CUDATest.cpp +++ b/unittests/CppInterOp/CUDATest.cpp @@ -10,10 +10,10 @@ using namespace TestUtils; static bool HasCudaSDK() { auto supportsCudaSDK = []() { -#if CLANG_VERSION_MAJOR < 16 +#ifdef CPPINTEROP_USE_CLING // FIXME: Enable this for cling. return false; -#endif // CLANG_VERSION_MAJOR < 16 +#endif if (!Cpp::CreateInterpreter({}, {"--cuda"})) return false; return Cpp::Declare("__global__ void test_func() {}" @@ -25,10 +25,10 @@ static bool HasCudaSDK() { static bool HasCudaRuntime() { auto supportsCuda = []() { -#if CLANG_VERSION_MAJOR < 16 +#ifdef CPPINTEROP_USE_CLING // FIXME: Enable this for cling. return false; -#endif //CLANG_VERSION_MAJOR < 16 +#endif if (!HasCudaSDK()) return false; @@ -44,11 +44,11 @@ static bool HasCudaRuntime() { return hasCuda; } -#if CLANG_VERSION_MAJOR < 16 +#ifdef CPPINTEROP_USE_CLING TEST(DISABLED_CUDATest, Sanity) { #else TEST(CUDATest, Sanity) { -#endif // CLANG_VERSION_MAJOR < 16 +#endif #ifdef _WIN32 GTEST_SKIP() << "Disabled on Windows. Needs fixing."; #endif diff --git a/unittests/CppInterOp/ScopeReflectionTest.cpp b/unittests/CppInterOp/ScopeReflectionTest.cpp index 5dd57706d..13b0096b2 100644 --- a/unittests/CppInterOp/ScopeReflectionTest.cpp +++ b/unittests/CppInterOp/ScopeReflectionTest.cpp @@ -859,14 +859,10 @@ template constexpr T pi = T(3.1415926535897932385L); auto* VD = cast((Decl*)Instance1); VarTemplateDecl* VDTD1 = VD->getSpecializedTemplate(); EXPECT_TRUE(VDTD1->isThisDeclarationADefinition()); -#if CLANG_VERSION_MAJOR > 13 #if CLANG_VERSION_MAJOR <= 18 TemplateArgument TA1 = (*VD->getTemplateArgsInfo())[0].getArgument(); #else TemplateArgument TA1 = (*VD->getTemplateArgsAsWritten())[0].getArgument(); -#endif // CLANG_VERSION_MAJOR -#else - TemplateArgument TA1 = VD->getTemplateArgsInfo()[0].getArgument(); #endif // CLANG_VERSION_MAJOR EXPECT_TRUE(TA1.getAsType()->isIntegerType()); }