From 8bdd67ccc3c5db2a9bd0519dd014fe93acb88f4a Mon Sep 17 00:00:00 2001 From: Fabian Schiebel <52407375+fabianbs96@users.noreply.github.com> Date: Sun, 7 Apr 2024 14:05:36 +0200 Subject: [PATCH] Fix C++20 build (#705) * Fix C++20 build + minor * Update readme --- CMakeLists.txt | 8 +--- README.md | 6 +-- cmake/phasar_macros.cmake | 2 + include/phasar/ControlFlow/CFGBase.h | 2 +- include/phasar/ControlFlow/ICFGBase.h | 2 +- .../phasar/DataFlow/IfdsIde/EdgeFunction.h | 2 +- .../phasar/DataFlow/IfdsIde/FlowFunctions.h | 2 +- include/phasar/Pointer/AliasInfoBase.h | 4 +- include/phasar/Pointer/PointsToInfoBase.h | 4 +- include/phasar/Utils/AdjacencyList.h | 4 +- include/phasar/Utils/ByRef.h | 4 +- include/phasar/Utils/GraphTraits.h | 2 +- include/phasar/Utils/IotaIterator.h | 3 +- include/phasar/Utils/JoinLattice.h | 5 ++- include/phasar/Utils/Printer.h | 2 +- include/phasar/Utils/TypeTraits.h | 44 +++++++++---------- 16 files changed, 47 insertions(+), 49 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eaf415b14..b9b6bf810 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/README.md b/README.md index 2d213e6c5..d7ceb3cd9 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ Lead developers of PhASAR are: Fabian Schiebel (@fabianbs96)( class CFGBase { template // NOLINTNEXTLINE(readability-identifier-naming) -constexpr bool is_cfg_v = is_crtp_base_of_v +PSR_CONCEPT is_cfg_v = is_crtp_base_of_v &&std::is_same_v &&std::is_same_v; diff --git a/include/phasar/ControlFlow/ICFGBase.h b/include/phasar/ControlFlow/ICFGBase.h index fea37796c..4291faf20 100644 --- a/include/phasar/ControlFlow/ICFGBase.h +++ b/include/phasar/ControlFlow/ICFGBase.h @@ -121,7 +121,7 @@ template class ICFGBase { /// from the given analysis-Domain template // NOLINTNEXTLINE(readability-identifier-naming) -constexpr bool is_icfg_v = is_crtp_base_of_v +PSR_CONCEPT is_icfg_v = is_crtp_base_of_v &&std::is_same_v &&std::is_same_v; diff --git a/include/phasar/DataFlow/IfdsIde/EdgeFunction.h b/include/phasar/DataFlow/IfdsIde/EdgeFunction.h index 7f8e98df8..ee7ee4b92 100644 --- a/include/phasar/DataFlow/IfdsIde/EdgeFunction.h +++ b/include/phasar/DataFlow/IfdsIde/EdgeFunction.h @@ -53,7 +53,7 @@ struct IsEdgeFunction< } // namespace detail template -static inline constexpr bool IsEdgeFunction = detail::IsEdgeFunction::value; +static constexpr bool IsEdgeFunction = detail::IsEdgeFunction::value; #else // clang-format off diff --git a/include/phasar/DataFlow/IfdsIde/FlowFunctions.h b/include/phasar/DataFlow/IfdsIde/FlowFunctions.h index b4246db4f..ad41e1e10 100644 --- a/include/phasar/DataFlow/IfdsIde/FlowFunctions.h +++ b/include/phasar/DataFlow/IfdsIde/FlowFunctions.h @@ -83,7 +83,7 @@ template 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 -static constexpr bool is_flowfunction_v = IsFlowFunction::value; // NOLINT +PSR_CONCEPT is_flowfunction_v = IsFlowFunction::value; // NOLINT /// Given a flow-function type FF, returns a (smart) pointer type pointing to FF template >> diff --git a/include/phasar/Pointer/AliasInfoBase.h b/include/phasar/Pointer/AliasInfoBase.h index b3bb828c1..039a212ed 100644 --- a/include/phasar/Pointer/AliasInfoBase.h +++ b/include/phasar/Pointer/AliasInfoBase.h @@ -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" @@ -74,8 +75,7 @@ struct IsAliasInfo< }; } // namespace detail -template -static constexpr bool IsAliasInfo = detail::IsAliasInfo::value; +template PSR_CONCEPT IsAliasInfo = detail::IsAliasInfo::value; } // namespace psr diff --git a/include/phasar/Pointer/PointsToInfoBase.h b/include/phasar/Pointer/PointsToInfoBase.h index 696065646..9eef7cf3a 100644 --- a/include/phasar/Pointer/PointsToInfoBase.h +++ b/include/phasar/Pointer/PointsToInfoBase.h @@ -36,12 +36,12 @@ struct is_PointsToTraits< : std::true_type {}; template -static constexpr bool is_PointsToTraits_v = // NOLINT +PSR_CONCEPT is_PointsToTraits_v = // NOLINT is_PointsToTraits::value; // clang-format off template -static constexpr bool is_equivalent_PointsToTraits_v = // NOLINT +PSR_CONCEPT is_equivalent_PointsToTraits_v = // NOLINT is_PointsToTraits_v && is_PointsToTraits_v && std::is_same_v && std::is_same_v && diff --git a/include/phasar/Utils/AdjacencyList.h b/include/phasar/Utils/AdjacencyList.h index e09bb99fa..b69abe74c 100644 --- a/include/phasar/Utils/AdjacencyList.h +++ b/include/phasar/Utils/AdjacencyList.h @@ -163,7 +163,7 @@ struct GraphTraits> { if constexpr (!std::is_same_v) { 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 @@ -292,8 +292,8 @@ struct GraphTraits> { #if __cplusplus >= 202002L static_assert(is_graph>); - static_assert(is_reservable_graph_trait>>); #endif + static_assert(is_reservable_graph_trait_v>>); }; } // namespace psr diff --git a/include/phasar/Utils/ByRef.h b/include/phasar/Utils/ByRef.h index 4e0f21bed..f98bd9eaa 100644 --- a/include/phasar/Utils/ByRef.h +++ b/include/phasar/Utils/ByRef.h @@ -10,12 +10,14 @@ #ifndef PHASAR_UTILS_BYREF_H #define PHASAR_UTILS_BYREF_H +#include "phasar/Utils/TypeTraits.h" + #include namespace psr { template -static constexpr bool CanEfficientlyPassByValue = +PSR_CONCEPT CanEfficientlyPassByValue = sizeof(T) <= 2 * sizeof(void *) && std::is_trivially_copyable_v; template diff --git a/include/phasar/Utils/GraphTraits.h b/include/phasar/Utils/GraphTraits.h index be00b4b84..76915be0f 100644 --- a/include/phasar/Utils/GraphTraits.h +++ b/include/phasar/Utils/GraphTraits.h @@ -69,7 +69,7 @@ concept is_graph_trait = requires(typename GraphTrait::graph_type &graph, } -> psr::is_iterable_over_v; { GraphTrait::vertices(cgraph) - } -> psr::is_iterable_over_v; + } -> psr::is_iterable_over_v; { GraphTrait::node(cgraph, vtx) } -> std::convertible_to; diff --git a/include/phasar/Utils/IotaIterator.h b/include/phasar/Utils/IotaIterator.h index 9eab786b6..c45a8efd0 100644 --- a/include/phasar/Utils/IotaIterator.h +++ b/include/phasar/Utils/IotaIterator.h @@ -59,7 +59,8 @@ template class IotaIterator { template using IotaRangeType = llvm::iterator_range>; -template constexpr auto iota(T From, T To) noexcept { +template +constexpr auto iota(T From, type_identity_t To) noexcept { static_assert(std::is_integral_v, "Iota only works on integers"); using iterator_type = IotaIterator>; auto Ret = llvm::make_range(iterator_type(From), iterator_type(To)); diff --git a/include/phasar/Utils/JoinLattice.h b/include/phasar/Utils/JoinLattice.h index 8e748cf78..203027cf2 100644 --- a/include/phasar/Utils/JoinLattice.h +++ b/include/phasar/Utils/JoinLattice.h @@ -17,6 +17,8 @@ #ifndef PHASAR_UTILS_JOINLATTICE_H #define PHASAR_UTILS_JOINLATTICE_H +#include "phasar/Utils/TypeTraits.h" + #include #include @@ -41,8 +43,7 @@ struct HasJoinLatticeTraitsHelper< L>>> : std::true_type {}; } // namespace detail template -static constexpr bool HasJoinLatticeTraits = - detail::HasJoinLatticeTraitsHelper::value; +PSR_CONCEPT HasJoinLatticeTraits = detail::HasJoinLatticeTraitsHelper::value; template class JoinLattice { public: diff --git a/include/phasar/Utils/Printer.h b/include/phasar/Utils/Printer.h index 31a08cdb4..76cb2e5e5 100644 --- a/include/phasar/Utils/Printer.h +++ b/include/phasar/Utils/Printer.h @@ -27,7 +27,7 @@ class Function; namespace psr { namespace detail { template -static constexpr bool IsSomehowPrintable = +PSR_CONCEPT IsSomehowPrintable = has_str_v || is_llvm_printable_v || has_adl_to_string_v; template decltype(auto) printSomehow(const T &Val) { diff --git a/include/phasar/Utils/TypeTraits.h b/include/phasar/Utils/TypeTraits.h index f4c6736f2..2c6d771c7 100644 --- a/include/phasar/Utils/TypeTraits.h +++ b/include/phasar/Utils/TypeTraits.h @@ -23,8 +23,10 @@ namespace psr { #if __cplusplus < 202002L +#define PSR_CONCEPT static constexpr bool template struct type_identity { using type = T; }; #else +#define PSR_CONCEPT concept template using type_identity = std::type_identity; #endif @@ -173,44 +175,44 @@ struct variant_idx, T> } // namespace detail template -constexpr bool is_iterable_v = detail::is_iterable::value; // NOLINT +PSR_CONCEPT is_iterable_v = detail::is_iterable::value; // NOLINT template -constexpr bool is_iterable_over_v = // NOLINT +PSR_CONCEPT is_iterable_over_v = // NOLINT detail::is_iterable_over::value; template -constexpr bool is_pair_v = detail::is_pair::value; // NOLINT +PSR_CONCEPT is_pair_v = detail::is_pair::value; // NOLINT template -constexpr bool is_tuple_v = detail::is_tuple::value; // NOLINT +PSR_CONCEPT is_tuple_v = detail::is_tuple::value; // NOLINT template -constexpr bool is_llvm_printable_v = // NOLINT +PSR_CONCEPT is_llvm_printable_v = // NOLINT detail::is_llvm_printable::value; template -constexpr bool is_std_printable_v = // NOLINT +PSR_CONCEPT is_std_printable_v = // NOLINT detail::is_std_printable::value; template -constexpr bool is_printable_v = detail::is_printable::value; // NOLINT +PSR_CONCEPT is_printable_v = detail::is_printable::value; // NOLINT template -constexpr bool has_str_v = detail::has_str::value; // NOLINT +PSR_CONCEPT has_str_v = detail::has_str::value; // NOLINT template -constexpr bool has_adl_to_string_v = detail::has_adl_to_string::value; +PSR_CONCEPT has_adl_to_string_v = detail::has_adl_to_string::value; template -constexpr bool has_erase_iterator_v = // NOLINT +PSR_CONCEPT has_erase_iterator_v = // NOLINT detail::has_erase_iterator::value; template -constexpr bool is_std_hashable_v = detail::is_std_hashable::value; // NOLINT +PSR_CONCEPT is_std_hashable_v = detail::is_std_hashable::value; // NOLINT template -constexpr bool is_llvm_hashable_v = // NOLINT +PSR_CONCEPT is_llvm_hashable_v = // NOLINT detail::is_llvm_hashable::value; template struct is_variant : std::false_type {}; // NOLINT @@ -218,30 +220,26 @@ template struct is_variant : std::false_type {}; // NOLINT template struct is_variant> : std::true_type {}; // NOLINT -template -inline constexpr bool is_variant_v = is_variant::value; // NOLINT +template PSR_CONCEPT is_variant_v = is_variant::value; // NOLINT template // NOLINTNEXTLINE -constexpr bool is_string_like_v = std::is_convertible_v; +PSR_CONCEPT is_string_like_v = std::is_convertible_v; template