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: Add more checks #3466

Merged
merged 1 commit into from
Aug 7, 2023
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
12 changes: 8 additions & 4 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Checks: >
clang-diagnostic-*,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-avoid-goto,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-init-variables,
Expand All @@ -20,16 +19,21 @@ Checks: >
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-pro-*,
misc-misplaced-const,
google-build-explicit-make-pair,
google-build-namespaces,
google-global-names-in-headers,
misc-*,
-misc-const-correctness,
-misc-non-private-member-variables-in-classes,
-misc-no-recursion,
modernize-*,
-modernize-avoid-c-arrays,
-modernize-macro-to-enum,
-modernize-return-braced-init-list,
-modernize-use-trailing-return-type,
performance-*,
portability-*,
readability-*,
-readability-braces-around-statements,
-readability-container-data-pointer,
-readability-else-after-return,
-readability-function-cognitive-complexity,
-readability-function-size,
Expand Down
6 changes: 3 additions & 3 deletions Src/Base/AMReX.H
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace amrex
#if defined(NDEBUG)
amrex::ignore_unused(msg);
#else
if (msg) AMREX_DEVICE_PRINTF("Error %s\n", msg);
if (msg) { AMREX_DEVICE_PRINTF("Error %s\n", msg); }
AMREX_DEVICE_ASSERT(0);
#endif
#else
Expand All @@ -136,7 +136,7 @@ namespace amrex
#if defined(NDEBUG)
amrex::ignore_unused(msg);
#else
if (msg) AMREX_DEVICE_PRINTF("Warning %s\n", msg);
if (msg) { AMREX_DEVICE_PRINTF("Warning %s\n", msg); }
#endif
#else
Warning_host(msg);
Expand All @@ -152,7 +152,7 @@ namespace amrex
#if defined(NDEBUG)
amrex::ignore_unused(msg);
#else
if (msg) AMREX_DEVICE_PRINTF("Abort %s\n", msg);
if (msg) { AMREX_DEVICE_PRINTF("Abort %s\n", msg); }
AMREX_DEVICE_ASSERT(0);
#endif
#else
Expand Down
36 changes: 18 additions & 18 deletions Src/Base/AMReX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ amrex::Initialize (int& argc, char**& argv, bool build_parm_parse,
system::exename += argv[0];

for (int i = 0; i < argc; ++i) {
if (i != 0) command_line.append(" ");
if (i != 0) { command_line.append(" "); }
command_line.append(argv[i]);
command_arguments.emplace_back(argv[i]);
}
Expand Down Expand Up @@ -412,7 +412,7 @@ amrex::Initialize (int& argc, char**& argv, bool build_parm_parse,
// the rest get ingored.
int ppargc = 1;
for (; ppargc < argc; ++ppargc) {
if (std::strcmp(argv[ppargc], "--") == 0) break;
if (std::strcmp(argv[ppargc], "--") == 0) { break; }
}
if (ppargc > 1)
{
Expand Down Expand Up @@ -549,9 +549,9 @@ amrex::Initialize (int& argc, char**& argv, bool build_parm_parse,

#if defined(__linux__)
curr_fpe_excepts = 0;
if (invalid) curr_fpe_excepts |= FE_INVALID;
if (divbyzero) curr_fpe_excepts |= FE_DIVBYZERO;
if (overflow) curr_fpe_excepts |= FE_OVERFLOW;
if (invalid) { curr_fpe_excepts |= FE_INVALID; }
if (divbyzero) { curr_fpe_excepts |= FE_DIVBYZERO; }
if (overflow) { curr_fpe_excepts |= FE_OVERFLOW; }
prev_fpe_excepts = fegetexcept();
if (curr_fpe_excepts != 0) {
feenableexcept(curr_fpe_excepts); // trap floating point exceptions
Expand All @@ -561,9 +561,9 @@ amrex::Initialize (int& argc, char**& argv, bool build_parm_parse,
#elif defined(__APPLE__) && defined(__x86_64__)
prev_fpe_mask = _MM_GET_EXCEPTION_MASK();
curr_fpe_excepts = 0u;
if (invalid) curr_fpe_excepts |= _MM_MASK_INVALID;
if (divbyzero) curr_fpe_excepts |= _MM_MASK_DIV_ZERO;
if (overflow) curr_fpe_excepts |= _MM_MASK_OVERFLOW;
if (invalid) { curr_fpe_excepts |= _MM_MASK_INVALID; }
if (divbyzero) { curr_fpe_excepts |= _MM_MASK_DIV_ZERO; }
if (overflow) { curr_fpe_excepts |= _MM_MASK_OVERFLOW; }
if (curr_fpe_excepts != 0u) {
_MM_SET_EXCEPTION_MASK(prev_fpe_mask & ~curr_fpe_excepts);
prev_handler_sigfpe = std::signal(SIGFPE, BLBackTrace::handler);
Expand All @@ -582,9 +582,9 @@ amrex::Initialize (int& argc, char**& argv, bool build_parm_parse,

fenv_t env;
fegetenv(&env);
if (invalid) env.__fpcr |= __fpcr_trap_invalid;
if (divbyzero) env.__fpcr |= __fpcr_trap_divbyzero;
if (overflow) env.__fpcr |= __fpcr_trap_overflow;
if (invalid) { env.__fpcr |= __fpcr_trap_invalid; }
if (divbyzero) { env.__fpcr |= __fpcr_trap_divbyzero; }
if (overflow) { env.__fpcr |= __fpcr_trap_overflow; }
fesetenv(&env);
// SIGILL ref: https://developer.apple.com/forums/thread/689159
#endif
Expand Down Expand Up @@ -708,7 +708,7 @@ amrex::Finalize (amrex::AMReX* pamrex)
AMReX::erase(pamrex);

#ifdef AMREX_USE_HYPRE
if (init_hypre) HYPRE_Finalize();
if (init_hypre) { HYPRE_Finalize(); }
#endif

BL_TINY_PROFILE_FINALIZE();
Expand Down Expand Up @@ -781,12 +781,12 @@ amrex::Finalize (amrex::AMReX* pamrex)
#ifndef BL_AMRPROF
if (system::signal_handling)
{
if (prev_handler_sigsegv != SIG_ERR) std::signal(SIGSEGV, prev_handler_sigsegv); // NOLINT(performance-no-int-to-ptr)
if (prev_handler_sigterm != SIG_ERR) std::signal(SIGTERM, prev_handler_sigterm); // NOLINT(performance-no-int-to-ptr)
if (prev_handler_sigint != SIG_ERR) std::signal(SIGINT , prev_handler_sigint); // NOLINT(performance-no-int-to-ptr)
if (prev_handler_sigabrt != SIG_ERR) std::signal(SIGABRT, prev_handler_sigabrt); // NOLINT(performance-no-int-to-ptr)
if (prev_handler_sigfpe != SIG_ERR) std::signal(SIGFPE , prev_handler_sigfpe); // NOLINT(performance-no-int-to-ptr)
if (prev_handler_sigill != SIG_ERR) std::signal(SIGILL , prev_handler_sigill); // NOLINT(performance-no-int-to-ptr)
if (prev_handler_sigsegv != SIG_ERR) { std::signal(SIGSEGV, prev_handler_sigsegv); } // NOLINT(performance-no-int-to-ptr)
if (prev_handler_sigterm != SIG_ERR) { std::signal(SIGTERM, prev_handler_sigterm); } // NOLINT(performance-no-int-to-ptr)
if (prev_handler_sigint != SIG_ERR) { std::signal(SIGINT , prev_handler_sigint); } // NOLINT(performance-no-int-to-ptr)
if (prev_handler_sigabrt != SIG_ERR) { std::signal(SIGABRT, prev_handler_sigabrt); } // NOLINT(performance-no-int-to-ptr)
if (prev_handler_sigfpe != SIG_ERR) { std::signal(SIGFPE , prev_handler_sigfpe); } // NOLINT(performance-no-int-to-ptr)
if (prev_handler_sigill != SIG_ERR) { std::signal(SIGILL , prev_handler_sigill); } // NOLINT(performance-no-int-to-ptr)
#if defined(__linux__)
#if !defined(__PGI) || (__PGIC__ >= 16)
if (curr_fpe_excepts != 0) {
Expand Down
8 changes: 4 additions & 4 deletions Src/Base/AMReX_Algorithm.H
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ namespace amrex
T flo = f(lo);
T fhi = f(hi);

if (flo == T(0)) return flo;
if (fhi == T(0)) return fhi;
if (flo == T(0)) { return flo; }
if (fhi == T(0)) { return fhi; }

AMREX_ASSERT_WITH_MESSAGE(flo * fhi <= T(0),
"Error - calling bisect but lo and hi don't bracket a root.");
Expand All @@ -121,10 +121,10 @@ namespace amrex
int n = 1;
while (n <= max_iter)
{
if (hi - lo < tol || almostEqual(lo,hi)) break;
if (hi - lo < tol || almostEqual(lo,hi)) { break; }
mi = (lo + hi) / T(2);
fmi = f(mi);
if (fmi == T(0)) break;
if (fmi == T(0)) { break; }
fmi*flo < T(0) ? hi = mi : lo = mi;
flo = f(lo);
fhi = f(hi);
Expand Down
12 changes: 6 additions & 6 deletions Src/Base/AMReX_Arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Arena::allocate_system (std::size_t nbytes) // NOLINT(readability-make-member-fu
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
if (p && (nbytes > 0) && arena_info.device_use_hostalloc) mlock(p, nbytes);
if (p && (nbytes > 0) && arena_info.device_use_hostalloc) { mlock(p, nbytes); }
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
Expand Down Expand Up @@ -201,13 +201,13 @@ Arena::allocate_system (std::size_t nbytes) // NOLINT(readability-make-member-fu
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
if (p && (nbytes > 0) && arena_info.device_use_hostalloc) mlock(p, nbytes);
if (p && (nbytes > 0) && arena_info.device_use_hostalloc) { mlock(p, nbytes); }
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
#endif
#endif
if (p == nullptr) amrex::Abort("Sorry, malloc failed");
if (p == nullptr) { amrex::Abort("Sorry, malloc failed"); }
return p;
}

Expand All @@ -217,7 +217,7 @@ Arena::deallocate_system (void* p, std::size_t nbytes) // NOLINT(readability-mak
#ifdef AMREX_USE_GPU
if (arena_info.use_cpu_memory)
{
if (p && arena_info.device_use_hostalloc) AMREX_MUNLOCK(p, nbytes);
if (p && arena_info.device_use_hostalloc) { AMREX_MUNLOCK(p, nbytes); }
std::free(p);
}
else if (arena_info.device_use_hostalloc)
Expand All @@ -235,7 +235,7 @@ Arena::deallocate_system (void* p, std::size_t nbytes) // NOLINT(readability-mak
sycl::free(p,Gpu::Device::syclContext()));
}
#else
if (p && arena_info.device_use_hostalloc) AMREX_MUNLOCK(p, nbytes);
if (p && arena_info.device_use_hostalloc) { AMREX_MUNLOCK(p, nbytes); }
std::free(p);
#endif
}
Expand Down Expand Up @@ -265,7 +265,7 @@ namespace {
void
Arena::Initialize ()
{
if (initialized) return;
if (initialized) { return; }
initialized = true;

// see reason on allowed reuse of the default CPU BArena in Arena::Finalize
Expand Down
9 changes: 4 additions & 5 deletions Src/Base/AMReX_Array.H
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace amrex {
*/
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void fill ( const T& value ) noexcept
{ for (unsigned int i = 0; i < N; ++i) arr[i] = value; }
{ for (unsigned int i = 0; i < N; ++i) { arr[i] = value; } }

/**
* Returns the sum of all elements in the GpuArray object.
Expand Down Expand Up @@ -853,7 +853,7 @@ namespace amrex
template <class T, typename = typename T::FABType>
std::array<T*,AMREX_SPACEDIM> GetArrOfPtrs (std::array<T,AMREX_SPACEDIM>& a) noexcept
{
return {{AMREX_D_DECL(&a[0], &a[1], &a[2])}};
return {{AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
}

template <class T>
Expand All @@ -865,13 +865,13 @@ namespace amrex
template <class T>
std::array<T const*,AMREX_SPACEDIM> GetArrOfConstPtrs (const std::array<T,AMREX_SPACEDIM>& a) noexcept
{
return {{AMREX_D_DECL(&a[0], &a[1], &a[2])}};
return {{AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
}

template <class T>
std::array<T const*,AMREX_SPACEDIM> GetArrOfConstPtrs (const std::array<T*,AMREX_SPACEDIM>& a) noexcept
{
return {{AMREX_D_DECL(a[0], a[1], a[2])}};
return {{AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
}

template <class T>
Expand All @@ -897,4 +897,3 @@ namespace amrex
}

#endif

2 changes: 1 addition & 1 deletion Src/Base/AMReX_AsyncOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void Finalize ()
}

#ifdef AMREX_USE_MPI
if (s_comm != MPI_COMM_NULL) MPI_Comm_free(&s_comm);
if (s_comm != MPI_COMM_NULL) { MPI_Comm_free(&s_comm); }
s_comm = MPI_COMM_NULL;
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions Src/Base/AMReX_BCUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ struct dummy_gpu_fill_extdir

void FillDomainBoundary (MultiFab& phi, const Geometry& geom, const Vector<BCRec>& bc)
{
if (geom.isAllPeriodic()) return;
if (phi.nGrow() == 0) return;
if (geom.isAllPeriodic()) { return; }
if (phi.nGrow() == 0) { return; }

AMREX_ALWAYS_ASSERT(phi.ixType().cellCentered());

Expand Down
15 changes: 9 additions & 6 deletions Src/Base/AMReX_BaseFab.H
Original file line number Diff line number Diff line change
Expand Up @@ -1769,8 +1769,9 @@ BaseFab<T>::getVal (T* data,
AMREX_ASSERT(!(this->dptr == nullptr));
AMREX_ASSERT(n >= 0 && n + numcomp <= this->nvar);

for (int k = 0; k < numcomp; k++)
for (int k = 0; k < numcomp; k++) {
data[k] = this->dptr[loc+(n+k)*sz];
}
}

template <class T>
Expand Down Expand Up @@ -1895,7 +1896,7 @@ BaseFab<T>::define ()
AMREX_ASSERT(this->dptr == nullptr);
AMREX_ASSERT(this->domain.numPts() > 0);
AMREX_ASSERT(this->nvar >= 0);
if (this->nvar == 0) return;
if (this->nvar == 0) { return; }
AMREX_ASSERT(std::numeric_limits<Long>::max()/this->nvar > this->domain.numPts());

this->truesize = this->nvar*this->domain.numPts();
Expand Down Expand Up @@ -1923,7 +1924,7 @@ template <class T>
BaseFab<T>::BaseFab (const Box& bx, int n, bool alloc, bool shared, Arena* ar)
: DataAllocator{ar}, domain(bx), nvar(n), shared_memory(shared)
{
if (!this->shared_memory && alloc) define();
if (!this->shared_memory && alloc) { define(); }
}

template <class T>
Expand Down Expand Up @@ -2054,16 +2055,18 @@ BaseFab<T>::resize (const Box& b, int n, Arena* ar)
}
else if (this->dptr == nullptr || !this->ptr_owner)
{
if (this->shared_memory)
if (this->shared_memory) {
amrex::Abort("BaseFab::resize: BaseFab in shared memory cannot increase size");
}

this->dptr = nullptr;
define();
}
else if (this->nvar*this->domain.numPts() > this->truesize)
{
if (this->shared_memory)
if (this->shared_memory) {
amrex::Abort("BaseFab::resize: BaseFab in shared memory cannot increase size");
}

clear();

Expand Down Expand Up @@ -2590,7 +2593,7 @@ BaseFab<T>::indexFromValue (Box const& subbox, int comp, T const& value) const n
{
AMREX_LOOP_3D(subbox, i, j, k,
{
if (a(i,j,k) == value) return IntVect(AMREX_D_DECL(i,j,k));
if (a(i,j,k) == value) { return IntVect(AMREX_D_DECL(i,j,k)); }
});
return IntVect::TheMinVector();
}
Expand Down
2 changes: 1 addition & 1 deletion Src/Base/AMReX_BlockMutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void BlockMutex::init_states (state_t* state, int N) noexcept {
[=] AMREX_GPU_DEVICE () noexcept
{
int i = threadIdx.x + blockIdx.x*blockDim.x;
if (i < N) state[i] = FreeState();
if (i < N) { state[i] = FreeState(); }
});
#endif
}
Expand Down
11 changes: 7 additions & 4 deletions Src/Base/AMReX_Box.H
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,11 @@ public:
AMREX_GPU_HOST_DEVICE
Box& grow (Orientation face, int n_cell = 1) noexcept {
int idir = face.coordDir();
if (face.isLow())
if (face.isLow()) {
smallend.shift(idir, -n_cell);
else
} else {
bigend.shift(idir,n_cell);
}
return *this;
}

Expand Down Expand Up @@ -800,9 +801,11 @@ Box::coarsen (const IntVect& ref_ratio) noexcept
IntVect off(0);
for (int dir = 0; dir < AMREX_SPACEDIM; dir++)
{
if (btype[dir])
if (bigend[dir]%ref_ratio[dir])
if (btype[dir]) {
if (bigend[dir]%ref_ratio[dir]) {
off.setVal(dir,1);
}
}
}
bigend.coarsen(ref_ratio);
bigend += off;
Expand Down
Loading
Loading