Skip to content

Commit 70f1394

Browse files
authored
LLVM 17 Compatibility (#808)
* LLVM 17 compatibility * Add CI-support for LLVM versions (16 + 17) * Make coverage-report name dependent on the llvm version, so that we can have both simultaneously
1 parent 055babd commit 70f1394

8 files changed

Lines changed: 61 additions & 20 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
os: [ubuntu-24.04, ubuntu-24.04-arm]
1818
compiler: [ [clang++-19, clang-19, "clang-19 libclang-rt-19-dev clang-tools-19"] ]
1919
build: [ Debug, Release, DebugLibdeps, DebugCov ]
20+
llvm-version: [ 16, 17 ]
2021
include:
2122
- build: Debug
2223
cmake_build_type: Debug
@@ -55,7 +56,7 @@ jobs:
5556
- name: Install Phasar Dependencies
5657
shell: bash
5758
run: |
58-
./utils/InstallAptDependencies.sh --noninteractive tzdata ccache ${{ matrix.compiler[2] }} ${{ matrix.extra_dependencies }}
59+
./utils/InstallAptDependencies.sh --llvm-version ${{ matrix.llvm-version }} --noninteractive tzdata ccache ${{ matrix.compiler[2] }} ${{ matrix.extra_dependencies }}
5960
6061
- name: Building Phasar in ${{ matrix.build }} with ${{ matrix.compiler[0] }}
6162
env:
@@ -69,6 +70,7 @@ jobs:
6970
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
7071
-DBUILD_PHASAR_CLANG=OFF \
7172
-DPHASAR_USE_Z3=ON \
73+
-DPHASAR_LLVM_VERSION=${{ matrix.llvm-version }} \
7274
${{ matrix.flags }} \
7375
-G Ninja
7476
ninja -C build
@@ -101,7 +103,7 @@ jobs:
101103
if: matrix.build == 'DebugCov'
102104
uses: actions/upload-artifact@v4
103105
with:
104-
name: CoverageReport
106+
name: phasar-coverage-report-llvm-${{ matrix.llvm-version }}
105107
path: ./build/ccov/all-merged/
106108
if-no-files-found: error
107109
retention-days: 7

BUILD.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ When using CMake to compile PhASAR the following optional parameters can be used
8080
| **PHASAR_ENABLE_PIC** : BOOL | Build Position-Independed Code (default is ON) |
8181
| **PHASAR_ENABLE_WARNINGS** : BOOL | Enable compiler warnings (default is ON) |
8282
| **CMAKE_CXX_STANDARD** : INT|Adapt the used C++ standard (minimum required is 20)|
83+
| **PHASAR_LLVM_VERSION** : INT|The LLVM major-version to use. Can be 16 or 17 (default is 16)|
8384

8485
You can use these parameters either directly or modify the installer-script `bootstrap.sh`
8586

CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,8 @@ endif()
334334
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)
335335

336336
# LLVM
337-
if (NOT PHASAR_LLVM_VERSION)
338-
set(PHASAR_LLVM_VERSION 16)
339-
endif()
337+
set(PHASAR_LLVM_VERSION 16 CACHE STRING "The LLVM major-version that PhASAR should use")
338+
340339
include(add_llvm)
341340
add_llvm()
342341

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ PhASAR supports C++20 modules as an experimental feature.
4848

4949
## Currently Supported Version of LLVM
5050

51-
PhASAR is currently set up to support LLVM-16.0.*
51+
**NEW**: PhASAR is currently set up to support **LLVM-16 and 17**, using LLVM 16 by default.<br>
52+
Specify the `PHASAR_LLVM_VERSION` cmake-variable to change the LLVM version to use.
53+
5254

5355
## Breaking Changes
5456

include/phasar/Utils/BitSet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
#include "llvm/ADT/STLExtras.h"
1414
#include "llvm/ADT/SmallBitVector.h"
15-
#include "llvm/Support/MathExtras.h"
1615

16+
#include <bit>
1717
#include <climits>
1818
#include <concepts>
1919
#include <cstddef>
@@ -189,7 +189,7 @@ template <typename IdT, typename BitVectorTy = llvm::BitVector> class BitSet {
189189
uint32_t Offset = 0;
190190
for (auto W : Words) {
191191
while (W) {
192-
auto Curr = llvm::countTrailingZeros(W) + Offset;
192+
auto Curr = std::countr_zero(W) + Offset;
193193
W &= W - 1;
194194
std::invoke(Handler, IdT(Curr));
195195
}

lib/PhasarLLVM/DB/LLVMProjectIRDB.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ static void setOpaquePointersForCtx(llvm::LLVMContext &Ctx, bool Enable) {
3434
if (Enable) {
3535
Ctx.enableOpaquePointers();
3636
}
37-
#else // LLVM_VERSION_MAJOR >= 17
38-
#error \
39-
"Non-opaque pointers are not supported anymore. Refactor PhASAR to remove typed pointer support."
4037
#endif
4138
}
4239

lib/PhasarLLVM/Pointer/FilteredAliasesUtils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "llvm/IR/Instructions.h"
77
#include "llvm/Support/Compiler.h"
88

9-
inline LLVM_LIBRARY_VISIBILITY const llvm::Function *
9+
LLVM_LIBRARY_VISIBILITY inline const llvm::Function *
1010
getFunction(const llvm::Value *V) {
1111
if (const auto *Inst = llvm::dyn_cast<llvm::Instruction>(V)) {
1212
return Inst->getFunction();
@@ -17,7 +17,7 @@ getFunction(const llvm::Value *V) {
1717
return nullptr;
1818
}
1919

20-
[[nodiscard]] inline LLVM_LIBRARY_VISIBILITY bool
20+
[[nodiscard]] LLVM_LIBRARY_VISIBILITY inline bool
2121
isConstantGlobalValue(const llvm::GlobalValue *GlobV) {
2222
if (const auto *Glob = llvm::dyn_cast<llvm::GlobalVariable>(GlobV)) {
2323
return Glob->isConstant();
@@ -31,7 +31,7 @@ isConstantGlobalValue(const llvm::GlobalValue *GlobV) {
3131
return true;
3232
}
3333

34-
inline LLVM_LIBRARY_VISIBILITY bool mustNoalias(const llvm::Value *P1,
34+
LLVM_LIBRARY_VISIBILITY inline bool mustNoalias(const llvm::Value *P1,
3535
const llvm::Value *P2) {
3636
if (P1 == P2) {
3737
return false;

utils/InstallAptDependencies.sh

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,53 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
if printf "%s\n" "$@" | grep -Eqe '^--noninteractive|-ni$'; then
5-
readonly noninteractive="true"
6-
shift
7-
else
8-
readonly noninteractive="false"
4+
noninteractive="false"
5+
LLVM_IR_VERSION=16
6+
7+
# Parsing command-line-parameters
8+
# See "https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash" as a reference
9+
10+
POSITIONAL=()
11+
while [[ $# -gt 0 ]]
12+
do
13+
key="$1"
14+
15+
case $key in
16+
--noninteractive|-ni)
17+
noninteractive="true"
18+
shift # past argument
19+
;;
20+
--llvm-version)
21+
LLVM_IR_VERSION=$2
22+
shift # past argument
23+
shift # past value
24+
;;
25+
--llvm-version=*)
26+
LLVM_IR_VERSION="${key#*=}"
27+
shift # past argument=value
28+
;;
29+
--help|-h)
30+
echo "USAGE: ./InstallAptDependencies.sh [options] [additional deps]"
31+
echo ""
32+
echo "OPTIONS:"
33+
echo -e "\t--noninteractive,-ni\t- Non-interactive mode for apt"
34+
echo -e "\t--llvm-version=<value>\t- The LLVM major-version to use (16 or 17, default is 16)"
35+
exit 0
36+
;;
37+
*) # unknown option
38+
POSITIONAL+=("$1") # save it in an array for later
39+
shift # past argument
40+
;;
41+
esac
42+
done
43+
set -- "${POSITIONAL[@]}" # restore positional parameters
44+
# End - Parsing command-line-parameters
45+
46+
if [ "$LLVM_IR_VERSION" -ne "16" ] && [ "$LLVM_IR_VERSION" -ne "17" ]; then
47+
echo "Invalid LLVM version: $LLVM_IR_VERSION, expected 16 or 17" >&2
48+
exit 1
949
fi
10-
readonly LLVM_IR_VERSION=16
50+
1151
additional_dependencies=("$@")
1252

1353
(

0 commit comments

Comments
 (0)