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

clang-tidy fixes #475

Merged
merged 3 commits into from
Mar 2, 2025
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
3 changes: 1 addition & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,*,-hicpp-uppercase-literal-suffix,-readability-uppercase-literal-suffix,-modernize-use-trailing-return-type,-readability-named-parameter,-hicpp-named-parameter,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-hicpp-no-array-decay,-llvm-header-guard,-cppcoreguidelines-macro-usage,-google-runtime-references,-readability-isolate-declaration,-fuchsia-default-arguments-calls,-fuchsia-overloaded-operator,-fuchsia-default-arguments-declarations,-readability-else-after-return,-google-runtime-int,-hicpp-signed-bitwise,-cert-dcl21-cpp,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-avoid-c-arrays,-hicpp-avoid-c-arrays,-modernize-avoid-c-arrays,-modernize-use-transparent-functors,-cert-dcl16-c,-cppcoreguidelines-pro-type-union-access,-bugprone-branch-clone,-fuchsia-statically-constructed-objects,-cppcoreguidelines-pro-bounds-constant-array-index,-readability-static-accessed-through-instance,-cppcoreguidelines-pro-type-vararg,-hicpp-vararg,-llvmlibc-restrict-system-libc-headers,-llvmlibc-callee-namespace,-llvmlibc-implementation-in-namespace,-llvm-else-after-return,-fuchsia-trailing-return,-readability-identifier-length,-altera-unroll-loops,-altera-id-dependent-backward-branch,-altera-struct-pack-align,-performance-no-int-to-ptr,-readability-function-cognitive-complexity,-misc-include-cleaner,-llvmlibc-inline-function-decl'
Checks: 'clang-diagnostic-*,clang-analyzer-*,*,-hicpp-uppercase-literal-suffix,-readability-uppercase-literal-suffix,-modernize-use-trailing-return-type,-readability-named-parameter,-hicpp-named-parameter,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-hicpp-no-array-decay,-llvm-header-guard,-cppcoreguidelines-macro-usage,-google-runtime-references,-readability-isolate-declaration,-fuchsia-default-arguments-calls,-fuchsia-overloaded-operator,-fuchsia-default-arguments-declarations,-readability-else-after-return,-google-runtime-int,-hicpp-signed-bitwise,-cert-dcl21-cpp,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-avoid-c-arrays,-hicpp-avoid-c-arrays,-modernize-avoid-c-arrays,-modernize-use-transparent-functors,-cert-dcl16-c,-cppcoreguidelines-pro-type-union-access,-bugprone-branch-clone,-fuchsia-statically-constructed-objects,-cppcoreguidelines-pro-bounds-constant-array-index,-readability-static-accessed-through-instance,-cppcoreguidelines-pro-type-vararg,-hicpp-vararg,-llvmlibc-restrict-system-libc-headers,-llvmlibc-callee-namespace,-llvmlibc-implementation-in-namespace,-llvm-else-after-return,-fuchsia-trailing-return,-readability-identifier-length,-altera-unroll-loops,-altera-id-dependent-backward-branch,-altera-struct-pack-align,-performance-no-int-to-ptr,-readability-function-cognitive-complexity,-misc-include-cleaner,-llvmlibc-inline-function-decl,-boost-use-ranges,-modernize-use-constraints,-modernize-use-std-numbers'
WarningsAsErrors: '*'
AnalyzeTemporaryDtors: false
FormatStyle: none
User: yardbird
CheckOptions:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if(NOT CMAKE_BUILD_TYPE)
FORCE)
endif()

project(heyoka VERSION 7.2.1 LANGUAGES CXX C)
project(heyoka VERSION 7.2.2 LANGUAGES CXX C)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/yacma")

Expand Down
5 changes: 3 additions & 2 deletions src/detail/cm_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ std::function<llvm::Value *(llvm::Value *)> cm_make_arg_gen_vidx(llvm_state &s,
// Iterate over the blocks of repetitions.
for (decltype(ind.size()) rep_idx = 1; rep_idx < ind.size() / n_reps; ++rep_idx) {
for (decltype(ind.size()) i = 1; i < n_reps; ++i) {
const auto cur_idx = rep_idx * n_reps + i;
const auto cur_idx = (rep_idx * n_reps) + i;

if (ind[cur_idx] != ind[cur_idx - 1u]) {
rep_flag = false;
Expand All @@ -231,8 +231,9 @@ std::function<llvm::Value *(llvm::Value *)> cm_make_arg_gen_vidx(llvm_state &s,
#if !defined(NDEBUG)
// Double-check the result in debug mode.
std::vector<std::uint32_t> checker;
checker.reserve(ind.size());
for (decltype(ind.size()) i = 0; i < ind.size(); ++i) {
checker.push_back(boost::numeric_cast<std::uint32_t>(ind[0] + (i / n_reps) * stride));
checker.push_back(boost::numeric_cast<std::uint32_t>(ind[0] + ((i / n_reps) * stride)));
}
assert(checker == ind); // LCOV_EXCL_LINE
#endif
Expand Down
1 change: 1 addition & 0 deletions src/detail/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace
// Global flag to signal whether or not to enable
// expensive debug checks. This is just used to avoid
// excessive runtime in certain unit tests.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
bool edb_is_enabled = true;

} // namespace
Expand Down
3 changes: 3 additions & 0 deletions src/detail/erfa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ add_library(heyoka_erfa STATIC "${HEYOKA_ERFA_SRC_FILES}")
target_compile_features(heyoka_erfa PRIVATE c_std_99)
# Enforce vanilla C.
set_property(TARGET heyoka_erfa PROPERTY C_EXTENSIONS NO)
# NOTE: force clang-tidy OFF as there's too much warnings in the
# erfa source code.
set_property(TARGET heyoka_erfa PROPERTY C_CLANG_TIDY "")

# IPO setup.
if(HEYOKA_ENABLE_IPO)
Expand Down
5 changes: 3 additions & 2 deletions src/detail/event_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ int sign(const mppp::real &z)

const auto ret = z.sgn();

// NOLINTNEXTLINE(readability-avoid-nested-conditional-operator)
return ret == 0 ? 0 : (ret < 0 ? -1 : 1);
}

Expand Down Expand Up @@ -190,7 +191,7 @@ int sgn(const mppp::real &val)
// Evaluate the first derivative of a polynomial.
// Requires random-access iterator.
template <typename InputIt, typename T>
auto poly_eval_1(InputIt a, T x, std::uint32_t n)
auto poly_eval_1(InputIt a, const T &x, std::uint32_t n)
{
assert(n >= 2u); // LCOV_EXCL_LINE

Expand All @@ -209,7 +210,7 @@ auto poly_eval_1(InputIt a, T x, std::uint32_t n)
// Evaluate polynomial.
// Requires random-access iterator.
template <typename InputIt, typename T>
auto poly_eval(InputIt a, T x, std::uint32_t n)
auto poly_eval(InputIt a, const T &x, std::uint32_t n)
{
auto ret = a[n];

Expand Down
3 changes: 3 additions & 0 deletions src/detail/get_dl_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ std::string make_dl_path_dlfcn()
// LCOV_EXCL_START
} catch (const std::exception &e) {
std::cerr << "WARNING - exception raised while trying to determine the path of the heyoka library: "
// NOLINTNEXTLINE(performance-avoid-endl)
<< e.what() << std::endl;
} catch (...) {
std::cerr << "WARNING - exception raised while trying to determine the path of the heyoka library"
// NOLINTNEXTLINE(performance-avoid-endl)
<< std::endl;
}
}
Expand All @@ -78,6 +80,7 @@ std::string make_dl_path()
}

// The path to the heyoka shared library.
// NOLINTNEXTLINE(cert-err58-cpp)
const std::string dl_path = make_dl_path();

} // namespace
Expand Down
5 changes: 5 additions & 0 deletions src/detail/i_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace boost::serialization
{

template <typename Archive, typename... Args>
// NOLINTNEXTLINE(misc-use-internal-linkage)
void save(Archive &ar, const std::tuple<heyoka::taylor_outcome, Args...> &tup, unsigned)
{
auto tf = [&ar](const auto &x) {
Expand All @@ -68,6 +69,7 @@ void save(Archive &ar, const std::tuple<heyoka::taylor_outcome, Args...> &tup, u
}

template <typename Archive, typename... Args>
// NOLINTNEXTLINE(misc-use-internal-linkage)
void load(Archive &ar, std::tuple<heyoka::taylor_outcome, Args...> &tup, unsigned)
{
auto tf = [&ar](auto &x) {
Expand All @@ -85,6 +87,7 @@ void load(Archive &ar, std::tuple<heyoka::taylor_outcome, Args...> &tup, unsigne
}

template <typename Archive, typename... Args>
// NOLINTNEXTLINE(misc-use-internal-linkage)
void serialize(Archive &ar, std::tuple<heyoka::taylor_outcome, Args...> &tup, unsigned v)
{
split_free(ar, tup, v);
Expand Down Expand Up @@ -190,6 +193,7 @@ taylor_adaptive<T>::i_data::i_data(const i_data &other)
// NOTE: here we are recovering only the dense output function pointer because recovering
// the correct stepper requires information which is available only from the integrator
// class (hence, we do it from there).
// NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
m_d_out_f = std::visit([](auto &s) { return reinterpret_cast<d_out_f_t>(s.jit_lookup("d_out_f")); }, m_llvm_state);

// Init the compact mode tape, if necessary.
Expand Down Expand Up @@ -361,6 +365,7 @@ taylor_adaptive_batch<T>::i_data::i_data(const i_data &other)
// NOTE: here we are recovering only the dense output function pointer because recovering
// the correct stepper requires information which is available only from the integrator
// class (hence, we do it from there).
// NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
m_d_out_f = std::visit([](auto &s) { return reinterpret_cast<d_out_f_t>(s.jit_lookup("d_out_f")); }, m_llvm_state);

// Init the compact mode tape, if necessary.
Expand Down
18 changes: 11 additions & 7 deletions src/detail/llvm_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ void llvm_append_used(llvm_state &s, llvm::Constant *ptr)
} else {
// The llvm.used variable does not exist yet, create it.
auto *used_array_type = llvm::ArrayType::get(ptr_type, 1);
std::vector<llvm::Constant *> arr_values{ptr};
const std::vector<llvm::Constant *> arr_values{ptr};
auto *used_arr = llvm::ConstantArray::get(used_array_type, arr_values);
auto *g_used_arr = new llvm::GlobalVariable(md, used_arr->getType(), true,
llvm::GlobalVariable::AppendingLinkage, used_arr, "llvm.used");
Expand Down Expand Up @@ -471,8 +471,8 @@ llvm_scalarise_vector_call(llvm_state &s, const std::vector<llvm::Value *> &args
assert(std::all_of(args.begin() + 1, args.end(),
[&args](const auto &arg) { return arg->getType() == args[0]->getType(); }));
// Make sure all arguments are either vectors or scalars.
assert(std::all_of(args.begin(), args.end(), [](const auto &arg) { return arg->getType()->isVectorTy(); })
|| std::all_of(args.begin(), args.end(), [](const auto &arg) { return !arg->getType()->isVectorTy(); }));
assert(std::ranges::all_of(args, [](const auto &arg) { return arg->getType()->isVectorTy(); })
|| std::ranges::all_of(args, [](const auto &arg) { return !arg->getType()->isVectorTy(); }));

auto &builder = s.builder();

Expand Down Expand Up @@ -715,14 +715,15 @@ llvm::Value *llvm_invoke_vector_impl(llvm_state &s, const auto &vfi, const auto
// real128/real implementations (if these cannot be implemented
// on top of the LLVM intrinsics).
template <typename... Args>
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
llvm::Value *llvm_math_intr(llvm_state &s, const std::string &intr_name,
#if defined(HEYOKA_HAVE_REAL128)
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
const std::string f128_name,
const std::string &f128_name,
#endif
#if defined(HEYOKA_HAVE_REAL)
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
const std::string real_name,
const std::string &real_name,
#endif

Args *...args)
Expand Down Expand Up @@ -3194,6 +3195,7 @@ llvm::Value *llvm_dl_lt(llvm_state &state, llvm::Value *x_hi, llvm::Value *x_lo,
auto *cond1 = llvm_fcmp_olt(state, x_hi, y_hi);
auto *cond2 = llvm_fcmp_oeq(state, x_hi, y_hi);
auto *cond3 = llvm_fcmp_olt(state, x_lo, y_lo);
// NOLINTNEXTLINE(readability-suspicious-call-argument)
auto *cond4 = builder.CreateLogicalAnd(cond2, cond3);
auto *cond = builder.CreateLogicalOr(cond1, cond4);

Expand All @@ -3212,6 +3214,7 @@ llvm::Value *llvm_dl_gt(llvm_state &state, llvm::Value *x_hi, llvm::Value *x_lo,
auto *cond1 = llvm_fcmp_ogt(state, x_hi, y_hi);
auto *cond2 = llvm_fcmp_oeq(state, x_hi, y_hi);
auto *cond3 = llvm_fcmp_ogt(state, x_lo, y_lo);
// NOLINTNEXTLINE(readability-suspicious-call-argument)
auto *cond4 = builder.CreateLogicalAnd(cond2, cond3);
auto *cond = builder.CreateLogicalOr(cond1, cond4);

Expand Down Expand Up @@ -3398,6 +3401,7 @@ llvm::Type *to_internal_llvm_type(llvm_state &s, [[maybe_unused]] long long prec
if constexpr (std::same_as<T, mppp::real>) {
// Checks on prec.
// LCOV_EXCL_START
// NOLINTNEXTLINE(misc-redundant-expression)
if (prec == 0 || prec < mppp::real_prec_min() || prec > mppp::real_prec_max()) [[unlikely]] {
throw std::invalid_argument(
fmt::format("An invalid precision value of {} was passed to to_internal_llvm_type()", prec));
Expand All @@ -3413,8 +3417,8 @@ llvm::Type *to_internal_llvm_type(llvm_state &s, [[maybe_unused]] long long prec
// Compute the required number of limbs.
// NOTE: this is a computation done in the implementation of mppp::real and
// reproduced here. We should consider exposing this functionality in mp++.
const auto nlimbs
= boost::numeric_cast<std::uint64_t>(prec / GMP_NUMB_BITS + static_cast<int>((prec % GMP_NUMB_BITS) != 0));
const auto nlimbs = boost::numeric_cast<std::uint64_t>((prec / GMP_NUMB_BITS)
+ static_cast<int>((prec % GMP_NUMB_BITS) != 0));

// Fetch the limb array type.
auto *limb_arr_t = llvm::ArrayType::get(to_external_llvm_type<mp_limb_t>(c), nlimbs);
Expand Down
3 changes: 2 additions & 1 deletion src/detail/tm_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ mppp::real128 factorial<mppp::real128>(std::uint32_t n, long long)
#if defined(HEYOKA_HAVE_REAL)

template <>
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
mppp::real factorial<mppp::real>(std::uint32_t n, long long prec)
{
mppp::real ret{mppp::real_kind::zero, boost::numeric_cast<mpfr_prec_t>(prec)};
Expand Down Expand Up @@ -145,7 +146,7 @@ void add_tm_func_nc_mode(llvm_state &st, const std::vector<T> &state, const var_
// - the pointer to the state vector (read-only).
// All pointers are external. There might be overlap between input,
// output and state vector pointers.
std::vector<llvm::Type *> fargs(3u, ext_ptr_t);
const std::vector<llvm::Type *> fargs(3u, ext_ptr_t);

// The function does not return anything.
auto *ft = llvm::FunctionType::get(builder.getVoidTy(), fargs, false);
Expand Down
3 changes: 3 additions & 0 deletions src/detail/validate_ode_sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ void validate_ode_sys_impl(const std::vector<std::pair<expression, expression>>
}
} else {
throw std::invalid_argument(
// NOTE: I think this is another false positive. clang-tidy complains that we are
// printing an uninited value but I cannot see how this is the case.
// NOLINTNEXTLINE(clang-analyzer-core.CallAndMessage)
fmt::format("Invalid system of differential equations detected: the "
"left-hand side contains the expression '{}', which is not a variable",
lhs));
Expand Down
12 changes: 8 additions & 4 deletions src/detail/vector_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ auto make_vfinfo(const char *s_name, std::string v_name, std::string lp_v_name,
{
assert(nargs == 1u || nargs == 2u);

auto ret = vf_info{std::move(v_name), {}, std::move(lp_v_name), {}, width, nargs};
auto ret = vf_info{.name = std::move(v_name),
.vf_abi_attr = {},
.lp_name = std::move(lp_v_name),
.lp_vf_abi_attr = {},
.width = width,
.nargs = nargs};
ret.vf_abi_attr = fmt::format("_ZGV_LLVM_N{}{}_{}({})", width, nargs == 1u ? "v" : "vv", s_name, ret.name);
ret.lp_vf_abi_attr = fmt::format("_ZGV_LLVM_N{}{}_{}({})", width, nargs == 1u ? "v" : "vv", s_name, ret.lp_name);
return ret;
Expand Down Expand Up @@ -173,11 +178,10 @@ auto make_vf_map()
// Checks in debug mode.
for (const auto &[key, value] : retval) {
assert(!value.empty());
assert(std::none_of(value.begin(), value.end(), [](const auto &v) {
assert(std::ranges::none_of(value, [](const auto &v) {
return v.width == 0u || v.nargs == 0u || v.name.empty() || v.vf_abi_attr.empty();
}));
assert(std::is_sorted(value.begin(), value.end(),
[](const auto &v1, const auto &v2) { return v1.width < v2.width; }));
assert(std::ranges::is_sorted(value, [](const auto &v1, const auto &v2) { return v1.width < v2.width; }));
}

#endif
Expand Down
6 changes: 3 additions & 3 deletions src/dtens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ std::vector<expression> dtens::get_gradient() const
const auto sr = get_derivatives(0, 1);
std::vector<expression> retval;
retval.reserve(get_nargs());
std::transform(sr.begin(), sr.end(), std::back_inserter(retval), [](const auto &p) { return p.second; });
std::ranges::transform(sr, std::back_inserter(retval), [](const auto &p) { return p.second; });

assert(retval.size() == get_nargs());

Expand All @@ -575,7 +575,7 @@ std::vector<expression> dtens::get_jacobian() const
const auto sr = get_derivatives(1);
std::vector<expression> retval;
retval.reserve(boost::safe_numerics::safe<decltype(retval.size())>(get_nargs()) * get_nouts());
std::transform(sr.begin(), sr.end(), std::back_inserter(retval), [](const auto &p) { return p.second; });
std::ranges::transform(sr, std::back_inserter(retval), [](const auto &p) { return p.second; });

assert(retval.size() == boost::safe_numerics::safe<decltype(retval.size())>(get_nargs()) * get_nouts());

Expand All @@ -601,7 +601,7 @@ std::vector<expression> dtens::get_hessian(std::uint32_t component) const
std::vector<expression> retval;
retval.reserve(static_cast<decltype(retval.size())>(std::ranges::size(sr)));

std::transform(sr.begin(), sr.end(), std::back_inserter(retval), [](const auto &p) { return p.second; });
std::ranges::transform(sr, std::back_inserter(retval), [](const auto &p) { return p.second; });

return retval;
}
Expand Down
12 changes: 6 additions & 6 deletions src/expression_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ std::vector<std::string> get_variables(const expression &e)

// Turn the set into an ordered vector.
std::vector retval(s_set.begin(), s_set.end());
std::sort(retval.begin(), retval.end());
std::ranges::sort(retval);

return retval;
}
Expand All @@ -386,7 +386,7 @@ std::vector<std::string> get_variables(const std::vector<expression> &v_ex)

// Turn the set into an ordered vector.
std::vector retval(s_set.begin(), s_set.end());
std::sort(retval.begin(), retval.end());
std::ranges::sort(retval);

return retval;
}
Expand Down Expand Up @@ -1035,13 +1035,13 @@ std::vector<expression> get_params(const expression &ex)

// Transform idx_set into a sorted vector.
std::vector<std::uint32_t> idx_vec(idx_set.begin(), idx_set.end());
std::sort(idx_vec.begin(), idx_vec.end());
std::ranges::sort(idx_vec);

// Transform the sorted indices into a vector of
// sorted parameter expressions.
std::vector<expression> retval;
retval.reserve(static_cast<decltype(retval.size())>(idx_vec.size()));
std::transform(idx_vec.begin(), idx_vec.end(), std::back_inserter(retval), [](auto idx) { return par[idx]; });
std::ranges::transform(idx_vec, std::back_inserter(retval), [](auto idx) { return par[idx]; });

return retval;
}
Expand All @@ -1059,13 +1059,13 @@ std::vector<expression> get_params(const std::vector<expression> &v_ex)

// Transform idx_set into a sorted vector.
std::vector<std::uint32_t> idx_vec(idx_set.begin(), idx_set.end());
std::sort(idx_vec.begin(), idx_vec.end());
std::ranges::sort(idx_vec);

// Transform the sorted indices into a vector of
// sorted parameter expressions.
std::vector<expression> retval;
retval.reserve(static_cast<decltype(retval.size())>(idx_vec.size()));
std::transform(idx_vec.begin(), idx_vec.end(), std::back_inserter(retval), [](auto idx) { return par[idx]; });
std::ranges::transform(idx_vec, std::back_inserter(retval), [](auto idx) { return par[idx]; });

return retval;
}
Expand Down
Loading
Loading