From 213f700c75a176e9ca6c95da27f9c8cefe179872 Mon Sep 17 00:00:00 2001 From: Fabian Schiebel Date: Thu, 18 Dec 2025 19:02:09 +0100 Subject: [PATCH 1/3] LLVM 17 compatibility --- BUILD.md | 1 + CMakeLists.txt | 5 ++--- README.md | 4 +++- include/phasar/Utils/BitSet.h | 4 ++-- lib/PhasarLLVM/DB/LLVMProjectIRDB.cpp | 3 --- lib/PhasarLLVM/Pointer/FilteredAliasesUtils.h | 6 +++--- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/BUILD.md b/BUILD.md index d4e5b93e50..e8c026e721 100644 --- a/BUILD.md +++ b/BUILD.md @@ -80,6 +80,7 @@ When using CMake to compile PhASAR the following optional parameters can be used | **PHASAR_ENABLE_PIC** : BOOL | Build Position-Independed Code (default is ON) | | **PHASAR_ENABLE_WARNINGS** : BOOL | Enable compiler warnings (default is ON) | | **CMAKE_CXX_STANDARD** : INT|Adapt the used C++ standard (minimum required is 20)| +| **PHASAR_LLVM_VERSION** : INT|The LLVM major-version to use. Can be 16 or 17 (default is 16)| You can use these parameters either directly or modify the installer-script `bootstrap.sh` diff --git a/CMakeLists.txt b/CMakeLists.txt index 86c4fece2b..f929582f71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -334,9 +334,8 @@ endif() option(USE_LLVM_FAT_LIB "Link against libLLVM.so instead of the individual LLVM libraries if possible (default is OFF; always on if BUILD_SHARED_LIBS is ON)" OFF) # LLVM -if (NOT PHASAR_LLVM_VERSION) - set(PHASAR_LLVM_VERSION 16) -endif() +set(PHASAR_LLVM_VERSION 16 CACHE STRING "The LLVM major-version that PhASAR should use") + include(add_llvm) add_llvm() diff --git a/README.md b/README.md index c638e02141..db217e8d39 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,9 @@ PhASAR supports C++20 modules as an experimental feature. ## Currently Supported Version of LLVM -PhASAR is currently set up to support LLVM-16.0.* +**NEW**: PhASAR is currently set up to support **LLVM-16 and 17**, using LLVM 16 by default.
+Specify the `PHASAR_LLVM_VERSION` cmake-variable to change the LLVM version to use. + ## Breaking Changes diff --git a/include/phasar/Utils/BitSet.h b/include/phasar/Utils/BitSet.h index b49e1d647e..732ff7f6e8 100644 --- a/include/phasar/Utils/BitSet.h +++ b/include/phasar/Utils/BitSet.h @@ -12,8 +12,8 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallBitVector.h" -#include "llvm/Support/MathExtras.h" +#include #include #include #include @@ -189,7 +189,7 @@ template class BitSet { uint32_t Offset = 0; for (auto W : Words) { while (W) { - auto Curr = llvm::countTrailingZeros(W) + Offset; + auto Curr = std::countr_zero(W) + Offset; W &= W - 1; std::invoke(Handler, IdT(Curr)); } diff --git a/lib/PhasarLLVM/DB/LLVMProjectIRDB.cpp b/lib/PhasarLLVM/DB/LLVMProjectIRDB.cpp index 954d47ee36..af2dfe843f 100644 --- a/lib/PhasarLLVM/DB/LLVMProjectIRDB.cpp +++ b/lib/PhasarLLVM/DB/LLVMProjectIRDB.cpp @@ -34,9 +34,6 @@ static void setOpaquePointersForCtx(llvm::LLVMContext &Ctx, bool Enable) { if (Enable) { Ctx.enableOpaquePointers(); } -#else // LLVM_VERSION_MAJOR >= 17 -#error \ - "Non-opaque pointers are not supported anymore. Refactor PhASAR to remove typed pointer support." #endif } diff --git a/lib/PhasarLLVM/Pointer/FilteredAliasesUtils.h b/lib/PhasarLLVM/Pointer/FilteredAliasesUtils.h index 47e64f7cae..f227673121 100644 --- a/lib/PhasarLLVM/Pointer/FilteredAliasesUtils.h +++ b/lib/PhasarLLVM/Pointer/FilteredAliasesUtils.h @@ -6,7 +6,7 @@ #include "llvm/IR/Instructions.h" #include "llvm/Support/Compiler.h" -inline LLVM_LIBRARY_VISIBILITY const llvm::Function * +LLVM_LIBRARY_VISIBILITY inline const llvm::Function * getFunction(const llvm::Value *V) { if (const auto *Inst = llvm::dyn_cast(V)) { return Inst->getFunction(); @@ -17,7 +17,7 @@ getFunction(const llvm::Value *V) { return nullptr; } -[[nodiscard]] inline LLVM_LIBRARY_VISIBILITY bool +[[nodiscard]] LLVM_LIBRARY_VISIBILITY inline bool isConstantGlobalValue(const llvm::GlobalValue *GlobV) { if (const auto *Glob = llvm::dyn_cast(GlobV)) { return Glob->isConstant(); @@ -31,7 +31,7 @@ isConstantGlobalValue(const llvm::GlobalValue *GlobV) { return true; } -inline LLVM_LIBRARY_VISIBILITY bool mustNoalias(const llvm::Value *P1, +LLVM_LIBRARY_VISIBILITY inline bool mustNoalias(const llvm::Value *P1, const llvm::Value *P2) { if (P1 == P2) { return false; From b81dc715f412998710e28c67335ba8fb3bfcd39d Mon Sep 17 00:00:00 2001 From: Fabian Schiebel Date: Thu, 18 Dec 2025 19:27:52 +0100 Subject: [PATCH 2/3] Add CI-support for LLVM versions (16 + 17) --- .github/workflows/ci.yml | 4 ++- utils/InstallAptDependencies.sh | 52 +++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9e201cc17..228fa93d7c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,7 @@ jobs: os: [ubuntu-24.04, ubuntu-24.04-arm] compiler: [ [clang++-19, clang-19, "clang-19 libclang-rt-19-dev clang-tools-19"] ] build: [ Debug, Release, DebugLibdeps, DebugCov ] + llvm-version: [ 16, 17 ] include: - build: Debug cmake_build_type: Debug @@ -55,7 +56,7 @@ jobs: - name: Install Phasar Dependencies shell: bash run: | - ./utils/InstallAptDependencies.sh --noninteractive tzdata ccache ${{ matrix.compiler[2] }} ${{ matrix.extra_dependencies }} + ./utils/InstallAptDependencies.sh --llvm-version ${{ matrix.llvm-version }} --noninteractive tzdata ccache ${{ matrix.compiler[2] }} ${{ matrix.extra_dependencies }} - name: Building Phasar in ${{ matrix.build }} with ${{ matrix.compiler[0] }} env: @@ -69,6 +70,7 @@ jobs: -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DBUILD_PHASAR_CLANG=OFF \ -DPHASAR_USE_Z3=ON \ + -DPHASAR_LLVM_VERSION=${{ matrix.llvm-version }} \ ${{ matrix.flags }} \ -G Ninja ninja -C build diff --git a/utils/InstallAptDependencies.sh b/utils/InstallAptDependencies.sh index 1b5c7bf371..95134331b3 100755 --- a/utils/InstallAptDependencies.sh +++ b/utils/InstallAptDependencies.sh @@ -1,13 +1,53 @@ #!/bin/bash set -euo pipefail -if printf "%s\n" "$@" | grep -Eqe '^--noninteractive|-ni$'; then - readonly noninteractive="true" - shift -else - readonly noninteractive="false" +noninteractive="false" +LLVM_IR_VERSION=16 + +# Parsing command-line-parameters +# See "https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash" as a reference + +POSITIONAL=() +while [[ $# -gt 0 ]] +do +key="$1" + +case $key in + --noninteractive|-ni) + noninteractive="true" + shift # past argument + ;; + --llvm-version) + LLVM_IR_VERSION=$2 + shift # past argument + shift # past value + ;; + --llvm-version=*) + LLVM_IR_VERSION="${key#*=}" + shift # past argument=value + ;; + --help|-h) + echo "USAGE: ./InstallAptDependencies.sh [options] [additional deps]" + echo "" + echo "OPTIONS:" + echo -e "\t--noninteractive,-ni\t- Non-interactive mode for apt" + echo -e "\t--llvm-version=\t- The LLVM major-version to use (16 or 17, default is 16)" + exit 0 + ;; + *) # unknown option + POSITIONAL+=("$1") # save it in an array for later + shift # past argument + ;; +esac +done +set -- "${POSITIONAL[@]}" # restore positional parameters +# End - Parsing command-line-parameters + +if [ "$LLVM_IR_VERSION" -ne "16" ] && [ "$LLVM_IR_VERSION" -ne "17" ]; then + echo "Invalid LLVM version: $LLVM_IR_VERSION, expected 16 or 17" >&2 + exit 1 fi -readonly LLVM_IR_VERSION=16 + additional_dependencies=("$@") ( From d74adfb07f28bb476d4b117105aec621534bdace Mon Sep 17 00:00:00 2001 From: Fabian Schiebel Date: Thu, 18 Dec 2025 19:43:00 +0100 Subject: [PATCH 3/3] Make coverage-report name dependent on the llvm version, so that we can have both simultaneously --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 228fa93d7c..ad1da83e6f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,7 +103,7 @@ jobs: if: matrix.build == 'DebugCov' uses: actions/upload-artifact@v4 with: - name: CoverageReport + name: phasar-coverage-report-llvm-${{ matrix.llvm-version }} path: ./build/ccov/all-merged/ if-no-files-found: error retention-days: 7