Skip to content

Commit

Permalink
Fix C++20 build (#705)
Browse files Browse the repository at this point in the history
* Fix C++20 build + minor

* Update readme
  • Loading branch information
fabianbs96 authored Apr 7, 2024
1 parent e02d90c commit 8bdd67c
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 49 deletions.
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ endif()

option(PHASAR_EXPERIMENTAL_CXX20 "Build phasar in C++20 mode. This is an experimental feature" OFF)

set(CMAKE_EXPORT_COMPILE_COMMANDS YES)
if(PHASAR_EXPERIMENTAL_CXX20)
message(STATUS "Selected experimental C++20 build")
set(CMAKE_CXX_STANDARD 20)
else()
set(CMAKE_CXX_STANDARD 17)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Lead developers of PhASAR are: Fabian Schiebel (@fabianbs96)(<fabian.schiebel@i

PhASAR requires C++-17.

However, building in C++20 mode is supported as an experimental feature. You may enable this by turning the cmake option `PHASAR_EXPERIMENTAL_CXX20` on.
Although phasar currently does not make use of C++20 features (except for some `concept`s behind an #ifdef border), your client application that just *uses* phasar as a library may want to use C++20 ealier.
However, building in C++20 mode is supported as an experimental feature. You may enable this setting the cmake variable `CMAKE_CXX_STANDARD` to `20`.
Although phasar currently does not make use of C++-20 features (except for some `concept`s behind an #ifdef border), your client application that just *uses* phasar as a library may want to use C++20 ealier.

## Currently Supported Version of LLVM

Expand Down Expand Up @@ -124,7 +124,7 @@ When using CMake to compile PhASAR the following optional parameters can be used
| **PHASAR_ENABLE_PAMM** : STRING | Enable the performance measurement mechanism ('Off', 'Core' or 'Full', default is Off) |
| **PHASAR_ENABLE_PIC** : BOOL | Build Position-Independed Code (default is ON) |
| **PHASAR_ENABLE_WARNINGS** : BOOL | Enable compiler warnings (default is ON) |
| **PHASAR_EXPERIMENTAL_CXX20** : BOOL|Build phasar in C++20 mode. This is an experimental feature (default is OFF)|
| **CMAKE_CXX_STANDARD** : INT|Build phasar in C++17 or C++20 mode (default is 17)|

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

Expand Down
2 changes: 2 additions & 0 deletions cmake/phasar_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ function(add_phasar_library name)
EXPORT_NAME ${component_name}
)

target_compile_features(${name} PUBLIC cxx_std_17)

if(LLVM_COMMON_DEPENDS)
add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
endif(LLVM_COMMON_DEPENDS)
Expand Down
2 changes: 1 addition & 1 deletion include/phasar/ControlFlow/CFGBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ template <typename Derived> class CFGBase {

template <typename ICF, typename Domain>
// NOLINTNEXTLINE(readability-identifier-naming)
constexpr bool is_cfg_v = is_crtp_base_of_v<CFGBase, ICF>
PSR_CONCEPT is_cfg_v = is_crtp_base_of_v<CFGBase, ICF>
&&std::is_same_v<typename ICF::n_t, typename Domain::n_t>
&&std::is_same_v<typename ICF::f_t, typename Domain::f_t>;

Expand Down
2 changes: 1 addition & 1 deletion include/phasar/ControlFlow/ICFGBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ template <typename Derived> class ICFGBase {
/// from the given analysis-Domain
template <typename ICF, typename Domain>
// NOLINTNEXTLINE(readability-identifier-naming)
constexpr bool is_icfg_v = is_crtp_base_of_v<ICFGBase, ICF>
PSR_CONCEPT is_icfg_v = is_crtp_base_of_v<ICFGBase, ICF>
&&std::is_same_v<typename ICF::n_t, typename Domain::n_t>
&&std::is_same_v<typename ICF::f_t, typename Domain::f_t>;

Expand Down
2 changes: 1 addition & 1 deletion include/phasar/DataFlow/IfdsIde/EdgeFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct IsEdgeFunction<

} // namespace detail
template <typename T>
static inline constexpr bool IsEdgeFunction = detail::IsEdgeFunction<T>::value;
static constexpr bool IsEdgeFunction = detail::IsEdgeFunction<T>::value;

#else
// clang-format off
Expand Down
2 changes: 1 addition & 1 deletion include/phasar/DataFlow/IfdsIde/FlowFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ template <typename FF> struct IsFlowFunction {
/// Helper template to check at compile-time whether a type implements the
/// FlowFunction interface, no matter which data-flow fact type it uses.
template <typename FF>
static constexpr bool is_flowfunction_v = IsFlowFunction<FF>::value; // NOLINT
PSR_CONCEPT is_flowfunction_v = IsFlowFunction<FF>::value; // NOLINT

/// Given a flow-function type FF, returns a (smart) pointer type pointing to FF
template <typename FF, typename = std::enable_if_t<is_flowfunction_v<FF>>>
Expand Down
4 changes: 2 additions & 2 deletions include/phasar/Pointer/AliasInfoBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define PHASAR_POINTER_ALIASINFOBASE_H

#include "phasar/Pointer/AliasInfoTraits.h"
#include "phasar/Utils/TypeTraits.h"

#include "llvm/ADT/DenseSet.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -74,8 +75,7 @@ struct IsAliasInfo<
};
} // namespace detail

template <typename T>
static constexpr bool IsAliasInfo = detail::IsAliasInfo<T>::value;
template <typename T> PSR_CONCEPT IsAliasInfo = detail::IsAliasInfo<T>::value;

} // namespace psr

Expand Down
4 changes: 2 additions & 2 deletions include/phasar/Pointer/PointsToInfoBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ struct is_PointsToTraits<
: std::true_type {};

template <typename T>
static constexpr bool is_PointsToTraits_v = // NOLINT
PSR_CONCEPT is_PointsToTraits_v = // NOLINT
is_PointsToTraits<T>::value;

// clang-format off
template <typename T1, typename T2>
static constexpr bool is_equivalent_PointsToTraits_v = // NOLINT
PSR_CONCEPT is_equivalent_PointsToTraits_v = // NOLINT
is_PointsToTraits_v<T1> && is_PointsToTraits_v<T2> &&
std::is_same_v<typename T1::n_t, typename T2::n_t> &&
std::is_same_v<typename T1::v_t, typename T2::v_t> &&
Expand Down
4 changes: 2 additions & 2 deletions include/phasar/Utils/AdjacencyList.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ struct GraphTraits<AdjacencyList<T, EdgeTy>> {
if constexpr (!std::is_same_v<value_type, llvm::NoneType>) {
assert(G.Adj.size() == G.Nodes.size());
}
return psr::iota(size_t(0), G.Adj.size());
return psr::iota(vertex_t(0), G.Adj.size());
}

/// Gets the node-tag for node Vtx in graph G. Vtx must be part of G
Expand Down Expand Up @@ -292,8 +292,8 @@ struct GraphTraits<AdjacencyList<T, EdgeTy>> {

#if __cplusplus >= 202002L
static_assert(is_graph<AdjacencyList<T>>);
static_assert(is_reservable_graph_trait<GraphTraits<AdjacencyList<T>>>);
#endif
static_assert(is_reservable_graph_trait_v<GraphTraits<AdjacencyList<T>>>);
};

} // namespace psr
Expand Down
4 changes: 3 additions & 1 deletion include/phasar/Utils/ByRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
#ifndef PHASAR_UTILS_BYREF_H
#define PHASAR_UTILS_BYREF_H

#include "phasar/Utils/TypeTraits.h"

#include <type_traits>

namespace psr {

template <typename T>
static constexpr bool CanEfficientlyPassByValue =
PSR_CONCEPT CanEfficientlyPassByValue =
sizeof(T) <= 2 * sizeof(void *) && std::is_trivially_copyable_v<T>;

template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion include/phasar/Utils/GraphTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ concept is_graph_trait = requires(typename GraphTrait::graph_type &graph,
} -> psr::is_iterable_over_v<typename GraphTrait::value_type>;
{
GraphTrait::vertices(cgraph)
} -> psr::is_iterable_over_v<typename GraphTrait::value_type>;
} -> psr::is_iterable_over_v<typename GraphTrait::vertex_t>;
{
GraphTrait::node(cgraph, vtx)
} -> std::convertible_to<typename GraphTrait::value_type>;
Expand Down
3 changes: 2 additions & 1 deletion include/phasar/Utils/IotaIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ template <typename T> class IotaIterator {

template <typename T>
using IotaRangeType = llvm::iterator_range<IotaIterator<T>>;
template <typename T> constexpr auto iota(T From, T To) noexcept {
template <typename T>
constexpr auto iota(T From, type_identity_t<T> To) noexcept {
static_assert(std::is_integral_v<T>, "Iota only works on integers");
using iterator_type = IotaIterator<std::decay_t<T>>;
auto Ret = llvm::make_range(iterator_type(From), iterator_type(To));
Expand Down
5 changes: 3 additions & 2 deletions include/phasar/Utils/JoinLattice.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef PHASAR_UTILS_JOINLATTICE_H
#define PHASAR_UTILS_JOINLATTICE_H

#include "phasar/Utils/TypeTraits.h"

#include <type_traits>
#include <utility>

Expand All @@ -41,8 +43,7 @@ struct HasJoinLatticeTraitsHelper<
L>>> : std::true_type {};
} // namespace detail
template <typename L>
static constexpr bool HasJoinLatticeTraits =
detail::HasJoinLatticeTraitsHelper<L>::value;
PSR_CONCEPT HasJoinLatticeTraits = detail::HasJoinLatticeTraitsHelper<L>::value;

template <typename AnalysisDomainTy, typename = void> class JoinLattice {
public:
Expand Down
2 changes: 1 addition & 1 deletion include/phasar/Utils/Printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Function;
namespace psr {
namespace detail {
template <typename T>
static constexpr bool IsSomehowPrintable =
PSR_CONCEPT IsSomehowPrintable =
has_str_v<T> || is_llvm_printable_v<T> || has_adl_to_string_v<T>;

template <typename T> decltype(auto) printSomehow(const T &Val) {
Expand Down
44 changes: 21 additions & 23 deletions include/phasar/Utils/TypeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
namespace psr {

#if __cplusplus < 202002L
#define PSR_CONCEPT static constexpr bool
template <typename T> struct type_identity { using type = T; };
#else
#define PSR_CONCEPT concept
template <typename T> using type_identity = std::type_identity<T>;
#endif

Expand Down Expand Up @@ -173,75 +175,71 @@ struct variant_idx<std::variant<Ts...>, T>
} // namespace detail

template <typename T>
constexpr bool is_iterable_v = detail::is_iterable<T>::value; // NOLINT
PSR_CONCEPT is_iterable_v = detail::is_iterable<T>::value; // NOLINT

template <typename T, typename Over>
constexpr bool is_iterable_over_v = // NOLINT
PSR_CONCEPT is_iterable_over_v = // NOLINT
detail::is_iterable_over<T, Over>::value;

template <typename T>
constexpr bool is_pair_v = detail::is_pair<T>::value; // NOLINT
PSR_CONCEPT is_pair_v = detail::is_pair<T>::value; // NOLINT

template <typename T>
constexpr bool is_tuple_v = detail::is_tuple<T>::value; // NOLINT
PSR_CONCEPT is_tuple_v = detail::is_tuple<T>::value; // NOLINT

template <typename T>
constexpr bool is_llvm_printable_v = // NOLINT
PSR_CONCEPT is_llvm_printable_v = // NOLINT
detail::is_llvm_printable<T>::value;

template <typename T>
constexpr bool is_std_printable_v = // NOLINT
PSR_CONCEPT is_std_printable_v = // NOLINT
detail::is_std_printable<T>::value;

template <typename T, typename OS>
constexpr bool is_printable_v = detail::is_printable<T, OS>::value; // NOLINT
PSR_CONCEPT is_printable_v = detail::is_printable<T, OS>::value; // NOLINT

template <typename T>
constexpr bool has_str_v = detail::has_str<T>::value; // NOLINT
PSR_CONCEPT has_str_v = detail::has_str<T>::value; // NOLINT

template <typename T>
constexpr bool has_adl_to_string_v = detail::has_adl_to_string<T>::value;
PSR_CONCEPT has_adl_to_string_v = detail::has_adl_to_string<T>::value;

template <typename T>
constexpr bool has_erase_iterator_v = // NOLINT
PSR_CONCEPT has_erase_iterator_v = // NOLINT
detail::has_erase_iterator<T>::value;

template <typename T>
constexpr bool is_std_hashable_v = detail::is_std_hashable<T>::value; // NOLINT
PSR_CONCEPT is_std_hashable_v = detail::is_std_hashable<T>::value; // NOLINT

template <typename T>
constexpr bool is_llvm_hashable_v = // NOLINT
PSR_CONCEPT is_llvm_hashable_v = // NOLINT
detail::is_llvm_hashable<T>::value;

template <typename T> struct is_variant : std::false_type {}; // NOLINT

template <typename... Args>
struct is_variant<std::variant<Args...>> : std::true_type {}; // NOLINT

template <typename T>
inline constexpr bool is_variant_v = is_variant<T>::value; // NOLINT
template <typename T> PSR_CONCEPT is_variant_v = is_variant<T>::value; // NOLINT

template <typename T>
// NOLINTNEXTLINE
constexpr bool is_string_like_v = std::is_convertible_v<T, std::string_view>;
PSR_CONCEPT is_string_like_v = std::is_convertible_v<T, std::string_view>;

template <template <typename> typename Base, typename Derived>
constexpr bool is_crtp_base_of_v = // NOLINT
PSR_CONCEPT is_crtp_base_of_v = // NOLINT
detail::is_crtp_base_of<Base, Derived>::value;

template <typename T>
static inline constexpr bool HasIsConstant = detail::HasIsConstant<T>::value;
PSR_CONCEPT HasIsConstant = detail::HasIsConstant<T>::value;

template <typename T>
static inline constexpr bool HasDepth = detail::HasDepth<T>::value;
template <typename T> PSR_CONCEPT HasDepth = detail::HasDepth<T>::value;

template <typename T>
static inline constexpr bool IsEqualityComparable =
detail::IsEqualityComparable<T>::value;
PSR_CONCEPT IsEqualityComparable = detail::IsEqualityComparable<T>::value;

template <typename T, typename U>
static inline constexpr bool AreEqualityComparable =
detail::AreEqualityComparable<T, U>::value;
PSR_CONCEPT AreEqualityComparable = detail::AreEqualityComparable<T, U>::value;

template <typename T> using type_identity_t = typename type_identity<T>::type;

Expand Down

0 comments on commit 8bdd67c

Please sign in to comment.