commit: ab0bf9f6ffce10948bc5d0a9a90da24c85f9e00d Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Sun Jul 20 16:48:17 2025 +0000 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> CommitDate: Sun Jul 20 16:48:54 2025 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ab0bf9f6
sci-libs/symengine: Backport upstream LLVM fixes Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> .../symengine/files/symengine-0.14.0-llvm.patch | 108 ++++++++++++++++++++ sci-libs/symengine/symengine-0.14.0-r2.ebuild | 111 +++++++++++++++++++++ 2 files changed, 219 insertions(+) diff --git a/sci-libs/symengine/files/symengine-0.14.0-llvm.patch b/sci-libs/symengine/files/symengine-0.14.0-llvm.patch new file mode 100644 index 000000000000..3697088f9f9a --- /dev/null +++ b/sci-libs/symengine/files/symengine-0.14.0-llvm.patch @@ -0,0 +1,108 @@ +From de7305e5e2fee97d80c25164a8f8c9f7ecfc9953 Mon Sep 17 00:00:00 2001 +From: Liam Keegan <[email protected]> +Date: Thu, 26 Jun 2025 14:51:50 +0200 +Subject: [PATCH] Fix issues when compiled against LLVM 20 built with + assertions enabled + +- `Assertion `Level != OptimizationLevel::O0 && "Must request optimizations!"'` + - skip simplification pipeline for O0 + - copied from https://github.com/symengine/symengine/issues/2076#issue-2764070679 +- `Assertion `GV->hasName() && "Global must have name."'` + - give the function a name +- `getDeclaration` is deprecated in llvm 20 and will be removed in next version + - use replacement `getOrInsertDeclaration` for llvm >= 20 +- resolves #2076 +--- + symengine/llvm_double.cpp | 34 +++++++++++++++++++++------------- + 1 file changed, 21 insertions(+), 13 deletions(-) + +diff --git a/symengine/llvm_double.cpp b/symengine/llvm_double.cpp +index fe06ebcc7..8ae3b4adf 100644 +--- a/symengine/llvm_double.cpp ++++ b/symengine/llvm_double.cpp +@@ -52,6 +52,12 @@ using CodeGenOptLevel = llvm::CodeGenOpt::Level; + using CodeGenOptLevel = llvm::CodeGenOptLevel; + #endif + ++#if (LLVM_VERSION_MAJOR < 20) ++const auto &GetDeclaration = llvm::Intrinsic::getDeclaration; ++#else ++const auto &GetDeclaration = llvm::Intrinsic::getOrInsertDeclaration; ++#endif ++ + #if (LLVM_VERSION_MAJOR >= 21) + #define AddNoCapture(A) A.addCapturesAttr(llvm::CaptureInfo::none()) + #else +@@ -85,8 +91,8 @@ llvm::Function *LLVMVisitor::get_function_type(llvm::LLVMContext *context) + } + llvm::FunctionType *function_type = llvm::FunctionType::get( + llvm::Type::getVoidTy(*context), inp, /*isVarArgs=*/false); +- auto F = llvm::Function::Create(function_type, +- llvm::Function::InternalLinkage, "", mod); ++ auto F = llvm::Function::Create( ++ function_type, llvm::Function::InternalLinkage, "symengine_func", mod); + F->setCallingConv(llvm::CallingConv::C); + #if (LLVM_VERSION_MAJOR < 5) + { +@@ -265,16 +271,19 @@ void LLVMVisitor::init(const vec_basic &inputs, const vec_basic &outputs, + } else if (opt_level == 2) { + pb_opt_level = OptimizationLevel::O2; + } ++ ++ if (opt_level != 0) { + #if (LLVM_VERSION_MAJOR < 6) +- FPM = PB.buildFunctionSimplificationPipeline(pb_opt_level); ++ FPM = PB.buildFunctionSimplificationPipeline(pb_opt_level); + #elif (LLVM_VERSION_MAJOR < 12) +- FPM = PB.buildFunctionSimplificationPipeline( +- pb_opt_level, llvm::PassBuilder::ThinLTOPhase::None); ++ FPM = PB.buildFunctionSimplificationPipeline( ++ pb_opt_level, llvm::PassBuilder::ThinLTOPhase::None); + #else +- FPM = PB.buildFunctionSimplificationPipeline( +- pb_opt_level, llvm::ThinOrFullLTOPhase::None); ++ FPM = PB.buildFunctionSimplificationPipeline( ++ pb_opt_level, llvm::ThinOrFullLTOPhase::None); + #endif +- FPM.run(*F, FAM); ++ FPM.run(*F, FAM); ++ } + + // std::cout << "Optimized LLVM IR" << std::endl; + // module->print(llvm::errs(), nullptr); +@@ -293,7 +302,7 @@ void LLVMVisitor::init(const vec_basic &inputs, const vec_basic &outputs, + { + public: + std::string &ss_; +- MemoryBufferRefCallback(std::string &ss) : ss_(ss) {} ++ explicit MemoryBufferRefCallback(std::string &ss) : ss_(ss) {} + + void notifyObjectCompiled(const llvm::Module *M, + llvm::MemoryBufferRef obj) override +@@ -306,7 +315,7 @@ void LLVMVisitor::init(const vec_basic &inputs, const vec_basic &outputs, + std::unique_ptr<llvm::MemoryBuffer> + getObject(const llvm::Module *M) override + { +- return NULL; ++ return nullptr; + } + }; + +@@ -492,15 +501,14 @@ llvm::Function *LLVMVisitor::get_powi() + #if (LLVM_VERSION_MAJOR > 12) + arg_type.push_back(llvm::Type::getInt32Ty(mod->getContext())); + #endif +- return llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::powi, +- arg_type); ++ return GetDeclaration(mod, llvm::Intrinsic::powi, arg_type); + } + + llvm::Function *get_float_intrinsic(llvm::Type *type, llvm::Intrinsic::ID id, + unsigned n, llvm::Module *mod) + { + std::vector<llvm::Type *> arg_type(n, type); +- return llvm::Intrinsic::getDeclaration(mod, id, arg_type); ++ return GetDeclaration(mod, id, arg_type); + } + + void LLVMVisitor::bvisit(const Pow &x) diff --git a/sci-libs/symengine/symengine-0.14.0-r2.ebuild b/sci-libs/symengine/symengine-0.14.0-r2.ebuild new file mode 100644 index 000000000000..0b194f2965d3 --- /dev/null +++ b/sci-libs/symengine/symengine-0.14.0-r2.ebuild @@ -0,0 +1,111 @@ +# Copyright 1999-2025 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +LLVM_COMPAT=( {18..20} ) +LLVM_OPTIONAL=1 + +inherit cmake llvm-r2 toolchain-funcs + +DESCRIPTION="Fast symbolic manipulation library, written in C++" +HOMEPAGE="https://github.com/symengine/symengine/" +SRC_URI=" + https://github.com/symengine/${PN}/archive/v${PV}.tar.gz + -> ${P}.gh.tar.gz +" + +LICENSE="MIT" +SLOT="0/$(ver_cut 1-2)" +KEYWORDS="~amd64 ~arm ~arm64 ~loong ~ppc64 ~riscv ~x86" +IUSE=" + boost debug ecm +flint llvm +mpc +mpfr openmp primesieve tcmalloc + test +" +REQUIRED_USE=" + boost? ( !flint !mpc !mpfr ) + llvm? ( ${LLVM_REQUIRED_USE} ) + mpc? ( mpfr ) +" +RESTRICT="!test? ( test )" + +RDEPEND=" + boost? ( dev-libs/boost:= ) + !boost? ( dev-libs/gmp:= ) + debug? ( sys-libs/binutils-libs:= ) + ecm? ( sci-mathematics/gmp-ecm:= ) + flint? ( sci-mathematics/flint:= ) + mpc? ( dev-libs/mpc:= ) + mpfr? ( dev-libs/mpfr:= ) + llvm? ( $(llvm_gen_dep 'llvm-core/llvm:${LLVM_SLOT}=') ) + primesieve? ( sci-mathematics/primesieve:= ) + tcmalloc? ( dev-util/google-perftools ) +" +DEPEND=" + ${RDEPEND} + dev-libs/cereal +" + +PATCHES=( + # bug 957803, in git master + "${FILESDIR}/${P}-cmake4.patch" + # https://github.com/symengine/symengine/pull/2103 + "${FILESDIR}/${P}-llvm.patch" +) + +pkg_pretend() { + [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp +} + +pkg_setup() { + [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp +} + +src_configure() { + local int_class + + if use flint; then + int_class=flint + elif use mpfr; then + int_class=gmpxx + elif use boost; then + int_class=boostmp + else + int_class=gmp + fi + + einfo "Building with integer class: ${int_class}" + + local mycmakeargs=( + -DINSTALL_CMAKE_DIR="${EPREFIX}/usr/$(get_libdir)/cmake/symengine" + -DINTEGER_CLASS=${int_class} + # not installed + -DBUILD_BENCHMARKS=OFF + # broken with out-of-tree builds + -DBUILD_DOXYGEN=OFF + -DBUILD_TESTS=$(usex test) + # -DWITH_ARB provided by flint >= 2 + -DWITH_BFD=$(usex debug) + -DWITH_ECM=$(usex ecm) + -DWITH_FLINT=$(usex flint) + -DWITH_LLVM=$(usex llvm) + -DWITH_MPC=$(usex mpc) + -DWITH_MPFR=$(usex mpfr) + -DWITH_OPENMP=$(usex openmp) + -DWITH_PRIMESIEVE=$(usex primesieve) + -DWITH_PTHREAD=ON + -DWITH_SYMENGINE_ASSERT=$(usex debug) + -DWITH_SYMENGINE_THREAD_SAFE=ON + -DWITH_SYSTEM_CEREAL=ON + # TODO: package it + # -DWITH_SYSTEM_FASTFLOAT=ON + -DWITH_TCMALLOC=$(usex tcmalloc) + ) + if use llvm; then + mycmakeargs+=( + -DLLVM_ROOT="$(get_llvm_prefix -d)" + ) + fi + + cmake_src_configure +}
