Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch __builtin_unreachable to std::unreachable() #156

Merged
merged 11 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 50 additions & 50 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
---
InheritParentConfig: true
Checks: >
*,
-*static-assert*,
-*avoid-c-arrays,
-cert-dcl03-c,
-abseil-*,
-android-*,
-altera-*,
-bugprone-casting-through-void,
-bugprone-easily-swappable-parameters,
-bugprone-exception-escape,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-multi-level-implicit-pointer-conversion,
-bugprone-narrowing-conversions,
-boost-use-ranges,
-llvmlibc-*,
-cert-dcl50-cpp,
-cert-err33-c,
-cert-err34-c,
-cert-err58-cpp,
-clang-analyzer-deadcode.DeadStores,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-no-malloc,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-cstyle-cast,
-cppcoreguidelines-pro-type-vararg,
-fuchsia-*,
-google-objc*,
-google-readability-todo,
-hicpp-vararg,
-hicpp-no-array-decay,
-hicpp-no-malloc,
-hicpp-signed-bitwise,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
-modernize-use-ranges,
-modernize-use-std-print, # replace printout macro with a function when we want to autofix to use std::format gcc >=13
-performance-enum-size,
-readability-identifier-length,
-readability-function-cognitive-complexity,
-readability-magic-numbers,
WarningsAsErrors: >
*,
Checks: [
'*',
-*static-assert*,
-*avoid-c-arrays,
-cert-dcl03-c,
-abseil-*,
-android-*,
-altera-*,
-bugprone-casting-through-void,
-bugprone-easily-swappable-parameters,
-bugprone-exception-escape,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-multi-level-implicit-pointer-conversion,
-bugprone-narrowing-conversions,
-boost-use-ranges,
-llvmlibc-*,
-cert-dcl50-cpp,
-cert-err33-c,
-cert-err34-c,
-cert-err58-cpp,
-clang-analyzer-deadcode.DeadStores,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-no-malloc,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-cstyle-cast,
-cppcoreguidelines-pro-type-vararg,
-fuchsia-*,
-google-objc*,
-google-readability-todo,
-hicpp-vararg,
-hicpp-no-array-decay,
-hicpp-no-malloc,
-hicpp-signed-bitwise,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
-modernize-use-ranges, # things like sort and for_each don't support parallel execution policies
-modernize-use-std-print, # replace printout macro with a function when we want to autofix to use std::format gcc >=13
-performance-enum-size,
-readability-identifier-length,
-readability-function-cognitive-complexity,
-readability-magic-numbers,
]
WarningsAsErrors: '*'
FormatStyle: file
ExtraArgs: [-std=c++23]
CheckOptions:
Expand All @@ -73,6 +73,6 @@ CheckOptions:
value: lower_case
- key: bugprone-reserved-identifier.AllowedIdentifiers
value: '__host__;__device__'
- key: misc-include-cleaner.IgnoreHeaders # std::ranges::upper_bound is triggering warning to include a private libc++ header __algorithm/ranges_upper_bound.h
# value: '.*(ranges).*'
- key: misc-include-cleaner.IgnoreHeaders # std::ranges::upper_bound is triggering warning to include a private libc++ header __algorithm/ranges_upper_bound.h
# value: '.*(ranges).*'
value: '.*(__algorithm).*'
2 changes: 0 additions & 2 deletions .clangd
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ CompileFlags:
Diagnostics:
ClangTidy:
FastCheckFilter: None
Remove:
performance-enum-size
UnusedIncludes: Strict
MissingIncludes: Strict
Includes:
Expand Down
3 changes: 2 additions & 1 deletion atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cmath>
#include <span>
#include <tuple>
#include <utility>

#include "artisoptions.h"
#include "constants.h"
Expand Down Expand Up @@ -431,7 +432,7 @@ inline void set_nuptrans(const int element, const int ion, const int level, cons
}
assert_testmodeonly(false);
if constexpr (!TESTMODE) {
__builtin_unreachable();
std::unreachable();
}
return -1;
}
Expand Down
3 changes: 2 additions & 1 deletion gammapkt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <numeric>
#include <span>
#include <string>
#include <utility>
#include <vector>

#include "artisoptions.h"
Expand Down Expand Up @@ -1067,7 +1068,7 @@ __host__ __device__ void do_gamma(Packet &pkt, const int nts, const double t2) {
} else if constexpr (GAMMA_THERMALISATION_SCHEME == ThermalisationScheme::GUTTMAN) {
guttman_thermalisation(pkt);
} else {
__builtin_unreachable();
std::unreachable();
}

if (pkt.type != TYPE_GAMMA && pkt.type != TYPE_ESCAPE) {
Expand Down
6 changes: 3 additions & 3 deletions grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ auto get_coordcellindexincrement(const int axis) -> int {
printout("invalid coordinate index %d", axis);
assert_testmodeonly(false);
} else {
__builtin_unreachable();
std::unreachable();
}
}
}
Expand All @@ -1439,7 +1439,7 @@ auto get_cellcoordpointnum(const int cellindex, const int axis) -> int {
printout("invalid coordinate index %d", axis);
assert_testmodeonly(false);
} else {
__builtin_unreachable();
std::unreachable();
}
}
}
Expand Down Expand Up @@ -2551,7 +2551,7 @@ auto get_totmassradionuclide(const int z, const int a) -> double {

assert_always(false);
} else {
__builtin_unreachable();
std::unreachable();
}
}

Expand Down
3 changes: 2 additions & 1 deletion kpkt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <utility>
#include <vector>

#include "artisoptions.h"
Expand Down Expand Up @@ -642,7 +643,7 @@ __host__ __device__ void do_kpkt(Packet &pkt, const double t2, const int nts) {
} else if constexpr (TESTMODE) {
assert_always(false);
} else {
__builtin_unreachable();
std::unreachable();
}
}

Expand Down
3 changes: 2 additions & 1 deletion macroatom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <utility>
#if defined(STDPAR_ON) || defined(_OPENMP_ON)
#include <mutex>
#endif
Expand Down Expand Up @@ -602,7 +603,7 @@ __host__ __device__ void do_macroatom(Packet &pkt, const MacroAtomState &pktmast
printout("ERROR: Unknown macroatom selected_action type %d\n", selected_action);
assert_testmodeonly(false);
} else {
__builtin_unreachable();
std::unreachable();
}
}
}
Expand Down
22 changes: 12 additions & 10 deletions sn3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,27 @@ __attribute__((__format__(__printf__, 1, 2))) inline auto printout(const char *f
#include <atomic>
#endif

template <typename T>
inline void atomicadd(T &var, const T &val) {
#ifdef _OPENMP
#pragma omp atomic update
var += val;
#define atomicadd(var, val) \
{ \
_Pragma("omp atomic update") var += val; \
}

#else
#ifdef STDPAR_ON

#ifdef __cpp_lib_atomic_ref
static_assert(std::atomic<T>::is_always_lock_free);
std::atomic_ref<T>(var).fetch_add(val, std::memory_order_relaxed);
#define atomicadd(var, val) \
std::atomic_ref<std::remove_reference<decltype(var)>::type>(var).fetch_add(val, std::memory_order_relaxed);
#else
// this works on clang but not gcc for doubles.
__atomic_fetch_add(&var, val, __ATOMIC_RELAXED);
// needed for Apple clang
#define atomicadd(var, val) __atomic_fetch_add(&var, val, __ATOMIC_RELAXED);
#endif

#else
var += val;
#define atomicadd(var, val) var += (val);
#endif
#endif
}

inline void gsl_error_handler_printout(const char *reason, const char *file, int line, int gsl_errno) {
if (gsl_errno != 18) // roundoff error
Expand Down
7 changes: 4 additions & 3 deletions update_packets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cstdlib>
#include <ctime>
#include <span>
#include <utility>

#include "artisoptions.h"
#include "constants.h"
Expand Down Expand Up @@ -178,7 +179,7 @@ void update_pellet(Packet &pkt, const int nts, const double t2) {
pkt.pellet_decaytype);
std::abort();
} else {
__builtin_unreachable();
std::unreachable();
}
pkt.em_time = pkt.prop_time;
pkt.absorptiontype = -10;
Expand All @@ -204,7 +205,7 @@ void update_pellet(Packet &pkt, const int nts, const double t2) {
printout("ERROR: Something wrong with decaying pellets. tdecay %g ts %g (ts + tw) %g\n", tdecay, ts, t2);
assert_testmodeonly(false);
} else {
__builtin_unreachable();
std::unreachable();
}
}

Expand Down Expand Up @@ -270,7 +271,7 @@ void do_packet(Packet &pkt, const double t2, const int nts)
printout("ERROR: Unknown packet type %d\n", pkt.type);
assert_testmodeonly(false);
} else {
__builtin_unreachable();
std::unreachable();
}
}
}
Expand Down
Loading