From: Roland Schulz Date: Sat, 30 Jun 2018 20:01:04 +0000 (-0700) Subject: clang-tidy: more misc+readability X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=e121674e25cc95f06ffc7e3d7621841a8641c5b8;p=alexxy%2Fgromacs.git clang-tidy: more misc+readability Auto fixes: misc-macro-parentheses readability-named-parameter Enabled with few violations disabled by configuration: misc-throw-by-value-catch-by-reference readability-function-size Set clang-tidy checks as list to allow comments. Refactored the operator <<< used by GMX_THROW to take the exception by value and return a copy, which is easier for tools to see is a proper throw-by-value (of a temporary). Performance on the throwing path is not important, but is anyway not affected because the inlining of the operator allows the compiler to elide multiple copies. This also avoids casting away the constness. Change-Id: I85c3e3c8a494119ef906c0492680c0d0b177a38d --- diff --git a/src/gromacs/CMakeLists.txt b/src/gromacs/CMakeLists.txt index eff1a0e93f..6aa75f2041 100644 --- a/src/gromacs/CMakeLists.txt +++ b/src/gromacs/CMakeLists.txt @@ -277,15 +277,20 @@ if (GMX_CLANG_TIDY) if(CMAKE_VERSION VERSION_LESS "3.6") message(ERROR "clang-tidy support requires cmake 3.6.") endif() - set_target_properties(libgromacs PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXE};--checks=\ - -clang-analyzer-security.insecureAPI.strcpy,\ - bugprone-*,misc-*,readability-*,performance-*,mpi-*,\ - -misc-misplaced-widening-cast,-readability-named-parameter,\ - -misc-misplaced-const,\ - -misc-incorrect-roundings,-misc-macro-parentheses,-readability-function-size,-readability-else-after-return,\ - -readability-inconsistent-declaration-parameter-name,-misc-throw-by-value-catch-by-reference,\ - -readability-implicit-bool-conversion,\ - modernize-use-nullptr,modernize-use-emplace;-warnings-as-errors=*;-fix") + set(CLANG_TIDY_CHECKS + "-clang-analyzer-security.insecureAPI.strcpy" + "bugprone-*" "misc-*" "readability-*" "performance-*" "mpi-*" + "-misc-misplaced-widening-cast" + "-misc-misplaced-const" + "-misc-incorrect-roundings" #TODO: #2562 + "-readability-else-after-return" + "-readability-inconsistent-declaration-parameter-name" + "-readability-implicit-bool-conversion" #TODO: Remove gmx_bool + "modernize-use-nullptr" "modernize-use-emplace" + ) + string(REPLACE ";" "," CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS}") + set_target_properties(libgromacs PROPERTIES CXX_CLANG_TIDY + "${CLANG_TIDY_EXE};--checks=${CLANG_TIDY_CHECKS};-warnings-as-errors=*;-fix") endif() gmx_write_installed_header_list() diff --git a/src/gromacs/domdec/domdec_network.cpp b/src/gromacs/domdec/domdec_network.cpp index 95609cfdf2..b093fc2fbc 100644 --- a/src/gromacs/domdec/domdec_network.cpp +++ b/src/gromacs/domdec/domdec_network.cpp @@ -55,7 +55,7 @@ /*! \brief Returns the MPI rank of the domain decomposition master rank */ -#define DDMASTERRANK(dd) (dd->masterrank) +#define DDMASTERRANK(dd) ((dd)->masterrank) /*! \brief Move data of type \p T in the communication region one cell along diff --git a/src/gromacs/ewald/pme-gather.cpp b/src/gromacs/ewald/pme-gather.cpp index 000f24929b..b939468ab6 100644 --- a/src/gromacs/ewald/pme-gather.cpp +++ b/src/gromacs/ewald/pme-gather.cpp @@ -137,7 +137,7 @@ struct do_fspline * This code does not assume any memory alignment for the grid. */ RVec - operator()(std::integral_constant) const + operator()(std::integral_constant /*unused*/) const { const int norder = nn*4; /* Pointer arithmetic alert, next six statements */ @@ -190,7 +190,7 @@ struct do_fspline #ifdef PME_SIMD4_SPREAD_GATHER /* Load order elements from unaligned memory into two 4-wide SIMD */ template - static inline void loadOrderU(const real* data, std::integral_constant, + static inline void loadOrderU(const real* data, std::integral_constant /*unused*/, int offset, Simd4Real* S0, Simd4Real* S1) { #ifdef PME_SIMD4_UNALIGNED diff --git a/src/gromacs/ewald/pme-gpu-program-impl.cpp b/src/gromacs/ewald/pme-gpu-program-impl.cpp index 1fc76b58a2..c98bf6bd92 100644 --- a/src/gromacs/ewald/pme-gpu-program-impl.cpp +++ b/src/gromacs/ewald/pme-gpu-program-impl.cpp @@ -45,6 +45,6 @@ #include "pme-gpu-program-impl.h" -PmeGpuProgramImpl::PmeGpuProgramImpl(const gmx_device_info_t *) {}; +PmeGpuProgramImpl::PmeGpuProgramImpl(const gmx_device_info_t * /*unused*/) {}; PmeGpuProgramImpl::~PmeGpuProgramImpl() = default; diff --git a/src/gromacs/ewald/pme-solve.cpp b/src/gromacs/ewald/pme-solve.cpp index f9cccf78d7..856ffbb54c 100644 --- a/src/gromacs/ewald/pme-solve.cpp +++ b/src/gromacs/ewald/pme-solve.cpp @@ -220,7 +220,7 @@ void get_pme_ener_vir_lj(struct pme_solve_work_t *work, int nthread, #if defined PME_SIMD_SOLVE /* Calculate exponentials through SIMD */ -inline static void calc_exponentials_q(int, int, real f, ArrayRef d_aligned, ArrayRef r_aligned, ArrayRef e_aligned) +inline static void calc_exponentials_q(int /*unused*/, int /*unused*/, real f, ArrayRef d_aligned, ArrayRef r_aligned, ArrayRef e_aligned) { { SimdReal f_simd(f); @@ -265,7 +265,7 @@ inline static void calc_exponentials_q(int start, int end, real f, ArrayRef r_aligned, ArrayRef factor_aligned, ArrayRef d_aligned) +inline static void calc_exponentials_lj(int /*unused*/, int /*unused*/, ArrayRef r_aligned, ArrayRef factor_aligned, ArrayRef d_aligned) { SimdReal tmp_r, tmp_d, tmp_fac, d_inv, tmp_mk; const SimdReal sqr_PI = sqrt(SimdReal(M_PI)); diff --git a/src/gromacs/ewald/pme-spread.cpp b/src/gromacs/ewald/pme-spread.cpp index e77c7910d9..ff71c7fd87 100644 --- a/src/gromacs/ewald/pme-spread.cpp +++ b/src/gromacs/ewald/pme-spread.cpp @@ -224,11 +224,11 @@ static void make_thread_local_ind(const pme_atomcomm_t *atc, dr = xptr[j]; \ \ /* dr is relative offset from lower cell limit */ \ - data[order-1] = 0; \ - data[1] = dr; \ - data[0] = 1 - dr; \ + data[(order)-1] = 0; \ + data[1] = dr; \ + data[0] = 1 - dr; \ \ - for (int k = 3; (k < order); k++) \ + for (int k = 3; (k < (order)); k++) \ { \ div = 1.0/(k - 1.0); \ data[k-1] = div*dr*data[k-2]; \ @@ -240,24 +240,24 @@ static void make_thread_local_ind(const pme_atomcomm_t *atc, data[0] = div*(1-dr)*data[0]; \ } \ /* differentiate */ \ - dtheta[j][i*order+0] = -data[0]; \ - for (int k = 1; (k < order); k++) \ + dtheta[j][i*(order)+0] = -data[0]; \ + for (int k = 1; (k < (order)); k++) \ { \ - dtheta[j][i*order+k] = data[k-1] - data[k]; \ + dtheta[j][i*(order)+k] = data[k-1] - data[k]; \ } \ \ - div = 1.0/(order - 1); \ - data[order-1] = div*dr*data[order-2]; \ - for (int l = 1; (l < (order-1)); l++) \ + div = 1.0/((order) - 1); \ + data[(order)-1] = div*dr*data[(order)-2]; \ + for (int l = 1; (l < ((order)-1)); l++) \ { \ - data[order-l-1] = div*((dr+l)*data[order-l-2]+ \ - (order-l-dr)*data[order-l-1]); \ + data[(order)-l-1] = div*((dr+l)*data[(order)-l-2]+ \ + ((order)-l-dr)*data[(order)-l-1]); \ } \ data[0] = div*(1 - dr)*data[0]; \ \ - for (int k = 0; k < order; k++) \ + for (int k = 0; k < (order); k++) \ { \ - theta[j][i*order+k] = data[k]; \ + theta[j][i*(order)+k] = data[k]; \ } \ } \ } @@ -293,17 +293,17 @@ static void make_bsplines(splinevec theta, splinevec dtheta, int order, /* This has to be a macro to enable full compiler optimization with xlC (and probably others too) */ #define DO_BSPLINE(order) \ - for (ithx = 0; (ithx < order); ithx++) \ + for (ithx = 0; (ithx < (order)); ithx++) \ { \ index_x = (i0+ithx)*pny*pnz; \ valx = coefficient*thx[ithx]; \ \ - for (ithy = 0; (ithy < order); ithy++) \ + for (ithy = 0; (ithy < (order)); ithy++) \ { \ valxy = valx*thy[ithy]; \ index_xy = index_x+(j0+ithy)*pnz; \ \ - for (ithz = 0; (ithz < order); ithz++) \ + for (ithz = 0; (ithz < (order)); ithz++) \ { \ index_xyz = index_xy+(k0+ithz); \ grid[index_xyz] += valxy*thz[ithz]; \ diff --git a/src/gromacs/fileio/libxdrf.cpp b/src/gromacs/fileio/libxdrf.cpp index 8b8cc02361..1aa2ed2720 100644 --- a/src/gromacs/fileio/libxdrf.cpp +++ b/src/gromacs/fileio/libxdrf.cpp @@ -69,7 +69,7 @@ const char *xdr_datatype_names[] = | with some routines to assist in this task (those are marked | static and cannot be called from user programs) */ -#define MAXABS INT_MAX-2 +#define MAXABS (INT_MAX-2) #ifndef SQR #define SQR(x) ((x)*(x)) diff --git a/src/gromacs/fileio/md5.cpp b/src/gromacs/fileio/md5.cpp index bacff2887d..9b9e6e88ab 100644 --- a/src/gromacs/fileio/md5.cpp +++ b/src/gromacs/fileio/md5.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2009,2010,2011,2012,2014,2015, by the GROMACS development team, led by + * Copyright (c) 2009,2010,2011,2012,2014,2015,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -254,8 +254,8 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ #define F(x, y, z) (((x) & (y)) | (~(x) & (z))) #define SET(a, b, c, d, k, s, Ti) \ - t = a + F(b, c, d) + X[k] + Ti; \ - a = ROTATE_LEFT(t, s) + b + t = (a) + F(b, c, d) + X[k] + (Ti); \ + (a) = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 0, 7, T1); SET(d, a, b, c, 1, 12, T2); @@ -280,8 +280,8 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ #define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) #define SET(a, b, c, d, k, s, Ti) \ - t = a + G(b, c, d) + X[k] + Ti; \ - a = ROTATE_LEFT(t, s) + b + t = (a) + G(b, c, d) + X[k] + (Ti); \ + (a) = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 1, 5, T17); SET(d, a, b, c, 6, 9, T18); @@ -306,8 +306,8 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ #define H(x, y, z) ((x) ^ (y) ^ (z)) #define SET(a, b, c, d, k, s, Ti) \ - t = a + H(b, c, d) + X[k] + Ti; \ - a = ROTATE_LEFT(t, s) + b + t = (a) + H(b, c, d) + X[k] + (Ti); \ + (a) = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 5, 4, T33); SET(d, a, b, c, 8, 11, T34); @@ -332,8 +332,8 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ #define I(x, y, z) ((y) ^ ((x) | ~(z))) #define SET(a, b, c, d, k, s, Ti) \ - t = a + I(b, c, d) + X[k] + Ti; \ - a = ROTATE_LEFT(t, s) + b + t = (a) + I(b, c, d) + X[k] + (Ti); \ + (a) = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 0, 6, T49); SET(d, a, b, c, 7, 10, T50); diff --git a/src/gromacs/fileio/tpxio.cpp b/src/gromacs/fileio/tpxio.cpp index d33fca80ea..d59b34b429 100644 --- a/src/gromacs/fileio/tpxio.cpp +++ b/src/gromacs/fileio/tpxio.cpp @@ -2771,7 +2771,7 @@ static int do_tpx(t_fileio *fio, gmx_bool bRead, v = as_rvec_array(state->v.data()); } -#define do_test(fio, b, p) if (bRead && (p != NULL) && !b) gmx_fatal(FARGS, "No %s in %s",#p, gmx_fio_getname(fio)) +#define do_test(fio, b, p) if (bRead && ((p) != NULL) && !(b)) gmx_fatal(FARGS, "No %s in %s",#p, gmx_fio_getname(fio)) do_test(fio, tpx.bBox, state->box); if (tpx.bBox) diff --git a/src/gromacs/gmxana/gmx_chi.cpp b/src/gromacs/gmxana/gmx_chi.cpp index 35adac367f..35e1f23c0d 100644 --- a/src/gromacs/gmxana/gmx_chi.cpp +++ b/src/gromacs/gmxana/gmx_chi.cpp @@ -130,7 +130,7 @@ static gmx_bool bAllowed(real phi, real psi) #define NPP asize(map) int x, y; -#define INDEX(ppp) (((static_cast (360+ppp*RAD2DEG)) % 360)/6) +#define INDEX(ppp) (((static_cast (360+(ppp)*RAD2DEG)) % 360)/6) x = INDEX(phi); y = INDEX(psi); #undef INDEX diff --git a/src/gromacs/gmxana/gmx_dipoles.cpp b/src/gromacs/gmxana/gmx_dipoles.cpp index 00333c9094..94aea2f132 100644 --- a/src/gromacs/gmxana/gmx_dipoles.cpp +++ b/src/gromacs/gmxana/gmx_dipoles.cpp @@ -73,8 +73,8 @@ #include "gromacs/utility/smalloc.h" #define e2d(x) ENM2DEBYE*(x) -#define EANG2CM E_CHARGE*1.0e-10 /* e Angstrom to Coulomb meter */ -#define CM2D SPEED_OF_LIGHT*1.0e+24 /* Coulomb meter to Debye */ +#define EANG2CM (E_CHARGE*1.0e-10) /* e Angstrom to Coulomb meter */ +#define CM2D (SPEED_OF_LIGHT*1.0e+24) /* Coulomb meter to Debye */ typedef struct { int nelem; @@ -532,7 +532,7 @@ static void mol_quad(int k0, int k1, rvec x[], const t_atom atom[], rvec quad) * the individual components on the diagonal. */ -#define delta(a, b) (( a == b ) ? 1.0 : 0.0) +#define delta(a, b) (( (a) == (b) ) ? 1.0 : 0.0) for (m = 0; (m < DIM); m++) { @@ -587,10 +587,10 @@ static void mol_quad(int k0, int k1, rvec x[], const t_atom atom[], rvec quad) */ #define SWAP(i) \ - if (dd[i+1] > dd[i]) { \ - tmp = dd[i]; \ - dd[i] = dd[i+1]; \ - dd[i+1] = tmp; \ + if (dd[(i)+1] > dd[i]) { \ + tmp = dd[i]; \ + dd[i] = dd[(i)+1]; \ + dd[(i)+1] = tmp; \ } SWAP(0); SWAP(1); diff --git a/src/gromacs/gmxana/gmx_enemat.cpp b/src/gromacs/gmxana/gmx_enemat.cpp index f5dab5afbf..676b2608ef 100644 --- a/src/gromacs/gmxana/gmx_enemat.cpp +++ b/src/gromacs/gmxana/gmx_enemat.cpp @@ -279,7 +279,7 @@ int gmx_enemat(int argc, char *argv[]) if (timecheck == 0) { -#define DONTSKIP(cnt) (skip) ? ((cnt % skip) == 0) : TRUE +#define DONTSKIP(cnt) (skip) ? (((cnt) % skip) == 0) : TRUE if (bCont) { diff --git a/src/gromacs/gmxana/gmx_hbond.cpp b/src/gromacs/gmxana/gmx_hbond.cpp index 08a7a8cf7b..7ac24d5415 100644 --- a/src/gromacs/gmxana/gmx_hbond.cpp +++ b/src/gromacs/gmxana/gmx_hbond.cpp @@ -104,7 +104,7 @@ static gmx_bool bDebug = FALSE; #define HB_NO 0 #define HB_YES 1<<0 #define HB_INS 1<<1 -#define HB_YESINS HB_YES|HB_INS +#define HB_YESINS (HB_YES|HB_INS) #define HB_NR (1<<2) #define MAXHYDRO 4 @@ -245,8 +245,8 @@ static void add_frames(t_hbdata *hb, int nframes) hb->nframes = nframes; } -#define OFFSET(frame) (frame / 32) -#define MASK(frame) (1 << (frame % 32)) +#define OFFSET(frame) ((frame) / 32) +#define MASK(frame) (1 << ((frame) % 32)) static void _set_hb(unsigned int hbexist[], unsigned int frame, gmx_bool bValue) { @@ -3399,7 +3399,7 @@ int gmx_hbond(int argc, char *argv[]) char **legnames; char buf[STRLEN]; -#define USE_THIS_GROUP(j) ( (j == gr0) || (bTwo && (j == gr1)) ) +#define USE_THIS_GROUP(j) ( ((j) == gr0) || (bTwo && ((j) == gr1)) ) fp = xvgropen(opt2fn("-dan", NFILE, fnm), "Donors and Acceptors", output_env_get_xvgr_tlabel(oenv), "Count", oenv); diff --git a/src/gromacs/gmxana/princ.cpp b/src/gromacs/gmxana/princ.cpp index 4f8e9af8f2..65987d9d40 100644 --- a/src/gromacs/gmxana/princ.cpp +++ b/src/gromacs/gmxana/princ.cpp @@ -163,13 +163,13 @@ void principal_comp(int n, const int index[], t_atom atom[], rvec x[], /* Sort eigenvalues in ascending order */ #define SWAPPER(i) \ - if (std::abs(dd[i+1]) < std::abs(dd[i])) { \ + if (std::abs(dd[(i)+1]) < std::abs(dd[i])) { \ temp = dd[i]; \ for (j = 0; (j < NDIM); j++) { tvec[j] = ev[j][i]; } \ - dd[i] = dd[i+1]; \ - for (j = 0; (j < NDIM); j++) { ev[j][i] = ev[j][i+1]; } \ - dd[i+1] = temp; \ - for (j = 0; (j < NDIM); j++) { ev[j][i+1] = tvec[j]; } \ + dd[i] = dd[(i)+1]; \ + for (j = 0; (j < NDIM); j++) { ev[j][i] = ev[j][(i)+1]; } \ + dd[(i)+1] = temp; \ + for (j = 0; (j < NDIM); j++) { ev[j][(i)+1] = tvec[j]; } \ } SWAPPER(0) SWAPPER(1) diff --git a/src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp b/src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp index 6192ca8b85..b42def31cc 100644 --- a/src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp +++ b/src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp @@ -148,7 +148,7 @@ static real calc_cm(int natoms, const real mass[], rvec x[], rvec v[], #define PVEC(str, v) fprintf(log, \ "%s[X]: %10.5e %s[Y]: %10.5e %s[Z]: %10.5e\n", \ - str, v[0], str, v[1], str, v[2]) + str, (v)[0], str, (v)[1], str, (v)[2]) #ifdef DEBUG PVEC("xcm", xcm); PVEC("acm", acm); diff --git a/src/gromacs/gmxpreprocess/gen_vsite.cpp b/src/gromacs/gmxpreprocess/gen_vsite.cpp index 69d7815162..404fbdbc85 100644 --- a/src/gromacs/gmxpreprocess/gen_vsite.cpp +++ b/src/gromacs/gmxpreprocess/gen_vsite.cpp @@ -688,9 +688,9 @@ static void add_vsites(t_params plist[], int vsite_type[], /* cosine rule: a^2 = b^2 + c^2 - 2 b c cos(alpha) */ /* get a^2 when a, b and alpha are given: */ -#define cosrule(b, c, alpha) ( gmx::square(b) + gmx::square(c) - 2*b*c*std::cos(alpha) ) +#define cosrule(b, c, alpha) ( gmx::square(b) + gmx::square(c) - 2*(b)*(c)*std::cos(alpha) ) /* get cos(alpha) when a, b and c are given: */ -#define acosrule(a, b, c) ( (gmx::square(b)+gmx::square(c)-gmx::square(a))/(2*b*c) ) +#define acosrule(a, b, c) ( (gmx::square(b)+gmx::square(c)-gmx::square(a))/(2*(b)*(c)) ) static int gen_vsites_6ring(t_atoms *at, int *vsite_type[], t_params plist[], int nrfound, int *ats, real bond_cc, real bond_ch, diff --git a/src/gromacs/gmxpreprocess/hackblock.cpp b/src/gromacs/gmxpreprocess/hackblock.cpp index cf81e0e10c..606a02a303 100644 --- a/src/gromacs/gmxpreprocess/hackblock.cpp +++ b/src/gromacs/gmxpreprocess/hackblock.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2011,2014,2015,2017, by the GROMACS development team, led by + * Copyright (c) 2011,2014,2015,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -169,7 +169,7 @@ void clear_t_hack(t_hack *hack) } } -#define safe_strdup(str) ((str != NULL) ? gmx_strdup(str) : NULL) +#define safe_strdup(str) (((str) != NULL) ? gmx_strdup(str) : NULL) static void copy_t_rbonded(t_rbonded *s, t_rbonded *d) { diff --git a/src/gromacs/gmxpreprocess/ter_db.cpp b/src/gromacs/gmxpreprocess/ter_db.cpp index ab6e078ede..b60d3dd4d4 100644 --- a/src/gromacs/gmxpreprocess/ter_db.cpp +++ b/src/gromacs/gmxpreprocess/ter_db.cpp @@ -54,9 +54,9 @@ #include "gromacs/utility/strdb.h" /* use bonded types definitions in hackblock.h */ -#define ekwRepl ebtsNR+1 -#define ekwAdd ebtsNR+2 -#define ekwDel ebtsNR+3 +#define ekwRepl (ebtsNR+1) +#define ekwAdd (ebtsNR+2) +#define ekwDel (ebtsNR+3) #define ekwNR 3 const char *kw_names[ekwNR] = { "replace", "add", "delete" diff --git a/src/gromacs/gpu_utils/gpu_utils.cpp b/src/gromacs/gpu_utils/gpu_utils.cpp index 3b943dabfb..07d2ad4de0 100644 --- a/src/gromacs/gpu_utils/gpu_utils.cpp +++ b/src/gromacs/gpu_utils/gpu_utils.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014,2015,2017, by the GROMACS development team, led by + * Copyright (c) 2014,2015,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -47,7 +47,7 @@ * * Since GPU support is not configured, there is no host memory to * allocate. */ -void gpu_set_host_malloc_and_free(bool, +void gpu_set_host_malloc_and_free(bool /*unused*/, gmx_host_alloc_t **nb_alloc, gmx_host_free_t **nb_free) { diff --git a/src/gromacs/mdlib/nbnxn_kernels/.clang-tidy b/src/gromacs/mdlib/nbnxn_kernels/.clang-tidy new file mode 100644 index 0000000000..c05e99a967 --- /dev/null +++ b/src/gromacs/mdlib/nbnxn_kernels/.clang-tidy @@ -0,0 +1,3 @@ +CheckOptions: + - key: readability-function-size.StatementThreshold + value: 2000 diff --git a/src/gromacs/mdlib/nbnxn_search.cpp b/src/gromacs/mdlib/nbnxn_search.cpp index a61d705bbd..5cd0a9bafa 100644 --- a/src/gromacs/mdlib/nbnxn_search.cpp +++ b/src/gromacs/mdlib/nbnxn_search.cpp @@ -495,14 +495,14 @@ static float subc_bb_dist2_simd4(int si, Simd4Float d2x, d2y, d2z; \ Simd4Float d2s, d2t; \ \ - shi = si*NNBSBB_D*DIM; \ + shi = (si)*NNBSBB_D*DIM; \ \ - xi_l = load4(bb_i+shi+0*STRIDE_PBB); \ - yi_l = load4(bb_i+shi+1*STRIDE_PBB); \ - zi_l = load4(bb_i+shi+2*STRIDE_PBB); \ - xi_h = load4(bb_i+shi+3*STRIDE_PBB); \ - yi_h = load4(bb_i+shi+4*STRIDE_PBB); \ - zi_h = load4(bb_i+shi+5*STRIDE_PBB); \ + xi_l = load4((bb_i)+shi+0*STRIDE_PBB); \ + yi_l = load4((bb_i)+shi+1*STRIDE_PBB); \ + zi_l = load4((bb_i)+shi+2*STRIDE_PBB); \ + xi_h = load4((bb_i)+shi+3*STRIDE_PBB); \ + yi_h = load4((bb_i)+shi+4*STRIDE_PBB); \ + zi_h = load4((bb_i)+shi+5*STRIDE_PBB); \ \ dx_0 = xi_l - xj_h; \ dy_0 = yi_l - yj_h; \ @@ -527,7 +527,7 @@ static float subc_bb_dist2_simd4(int si, d2s = d2x + d2y; \ d2t = d2s + d2z; \ \ - store4(d2+si, d2t); \ + store4((d2)+(si), d2t); \ } /* 4-wide SIMD code for nsi bb distances for bb format xxxxyyyyzzzz */ diff --git a/src/gromacs/mdlib/nbnxn_tuning.cpp b/src/gromacs/mdlib/nbnxn_tuning.cpp index e78d8ae594..b63702e075 100644 --- a/src/gromacs/mdlib/nbnxn_tuning.cpp +++ b/src/gromacs/mdlib/nbnxn_tuning.cpp @@ -93,7 +93,7 @@ static const int nbnxnReferenceNstlist = 10; //! The values to try when switching const int nstlist_try[] = { 20, 25, 40, 50, 80, 100 }; //! Number of elements in the neighborsearch list trials. -#define NNSTL sizeof(nstlist_try)/sizeof(nstlist_try[0]) +#define NNSTL (sizeof(nstlist_try)/sizeof(nstlist_try[0])) /* Increase nstlist until the size of the pair-list increased by * \p c_nbnxnListSizeFactor??? or more, but never more than * \p c_nbnxnListSizeFactor??? + \p c_nbnxnListSizeFactorMargin. diff --git a/src/gromacs/mdlib/ns.cpp b/src/gromacs/mdlib/ns.cpp index f0c1e111bc..2e0085a958 100644 --- a/src/gromacs/mdlib/ns.cpp +++ b/src/gromacs/mdlib/ns.cpp @@ -1659,8 +1659,8 @@ static inline void get_dx_dd(int Nx, real gridx, real rc2, int xgi, real x, } -#define calc_dx2(XI, YI, ZI, y) (gmx::square(XI-y[XX]) + gmx::square(YI-y[YY]) + gmx::square(ZI-y[ZZ])) -#define calc_cyl_dx2(XI, YI, y) (gmx::square(XI-y[XX]) + gmx::square(YI-y[YY])) +#define calc_dx2(XI, YI, ZI, y) (gmx::square((XI)-(y)[XX]) + gmx::square((YI)-(y)[YY]) + gmx::square((ZI)-(y)[ZZ])) +#define calc_cyl_dx2(XI, YI, y) (gmx::square((XI)-(y)[XX]) + gmx::square((YI)-(y)[YY])) /**************************************************** * * F A S T N E I G H B O R S E A R C H I N G diff --git a/src/gromacs/pbcutil/mshift.cpp b/src/gromacs/pbcutil/mshift.cpp index f0ff01ab08..87f3396af5 100644 --- a/src/gromacs/pbcutil/mshift.cpp +++ b/src/gromacs/pbcutil/mshift.cpp @@ -150,7 +150,7 @@ gmx_noreturn static void g_error(int line, const char *file) gmx_fatal(FARGS, "Trying to print nonexistent graph (file %s, line %d)", file, line); } -#define GCHECK(g) if (g == NULL) g_error(__LINE__, __FILE__) +#define GCHECK(g) if ((g) == NULL) g_error(__LINE__, __FILE__) void p_graph(FILE *log, const char *title, t_graph *g) { diff --git a/src/gromacs/pulling/pull_rotation.cpp b/src/gromacs/pulling/pull_rotation.cpp index a3411b06a5..fb6aebb349 100644 --- a/src/gromacs/pulling/pull_rotation.cpp +++ b/src/gromacs/pulling/pull_rotation.cpp @@ -221,8 +221,8 @@ typedef struct gmx_enfrotgrp #endif /* Shortcuts for often used queries */ -#define ISFLEX(rg) ( (rg->eType == erotgFLEX) || (rg->eType == erotgFLEXT) || (rg->eType == erotgFLEX2) || (rg->eType == erotgFLEX2T) ) -#define ISCOLL(rg) ( (rg->eType == erotgFLEX) || (rg->eType == erotgFLEXT) || (rg->eType == erotgFLEX2) || (rg->eType == erotgFLEX2T) || (rg->eType == erotgRMPF) || (rg->eType == erotgRM2PF) ) +#define ISFLEX(rg) ( ((rg)->eType == erotgFLEX) || ((rg)->eType == erotgFLEXT) || ((rg)->eType == erotgFLEX2) || ((rg)->eType == erotgFLEX2T) ) +#define ISCOLL(rg) ( ((rg)->eType == erotgFLEX) || ((rg)->eType == erotgFLEXT) || ((rg)->eType == erotgFLEX2) || ((rg)->eType == erotgFLEX2T) || ((rg)->eType == erotgRMPF) || ((rg)->eType == erotgRM2PF) ) /* Does any of the rotation groups use slab decomposition? */ @@ -1639,7 +1639,7 @@ static inline void shift_single_coord(const matrix box, rvec x, const ivec is) /* Determine the 'home' slab of this atom which is the * slab with the highest Gaussian weight of all */ -#define round(a) (int)(a+0.5) +#define round(a) (int)((a)+0.5) static inline int get_homeslab( rvec curr_x, /* The position for which the home slab shall be determined */ rvec rotvec, /* The rotation vector */ diff --git a/src/gromacs/tools/check.cpp b/src/gromacs/tools/check.cpp index 8bb686a994..33bff294a3 100644 --- a/src/gromacs/tools/check.cpp +++ b/src/gromacs/tools/check.cpp @@ -482,7 +482,7 @@ static void chk_trj(const gmx_output_env_t *oenv, const char *fn, const char *tp old_t1 = fr.time; j++; new_natoms = fr.natoms; -#define INC(s, n, f, l, item) if (s.item != 0) { if (n.item == 0) { first.item = fr.time; } last.item = fr.time; n.item++; \ +#define INC(s, n, f, l, item) if ((s).item != 0) { if ((n).item == 0) { first.item = fr.time; } last.item = fr.time; (n).item++; \ } INC(fr, count, first, last, bStep); INC(fr, count, first, last, bTime); diff --git a/src/gromacs/utility/exceptions.h b/src/gromacs/utility/exceptions.h index fd66bdb988..be82bc0808 100644 --- a/src/gromacs/utility/exceptions.h +++ b/src/gromacs/utility/exceptions.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2011,2012,2013,2014,2015,2016, by the GROMACS development team, led by + * Copyright (c) 2011,2012,2013,2014,2015,2016,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -369,12 +369,16 @@ class GromacsException : public std::exception * form to make the simple syntax of GMX_THROW() possible. To support this, * this operation needs to: * - Allow setting information in a temporary to support - * `GMX_THROW(InvalidInputError(ex))`. This is the reason for taking a - * const reference and the `const_cast`. - * - Return the same reference it takes in, instead of a base class. - * The compiler needs this information to throw the correct type of - * exception. This would be tedious to achieve with a member function - * (without a lot of code duplication). + * `GMX_THROW(InvalidInputError(ex))`. + * - Return a copy of the same class it takes in. The compiler needs + * this information to throw the correct type of exception. This + * would be tedious to achieve with a member function (without a + * lot of code duplication). Generally, \c ex will be a temporary, + * copied twice and returned by value, which the compiler will + * typically elide away (and anyway performance is not important + * when throwing). We are not using the typical + * return-by-const-reference idiom for this operator so that + * tooling can reliably see that we are throwing by value. * - Provide convenient syntax for adding multiple items. A non-member * function that would require nested calls would look ugly for such cases. * @@ -385,10 +389,10 @@ class GromacsException : public std::exception */ template inline -typename std::enable_if::value, const Exception &>::type -operator<<(const Exception &ex, const ExceptionInfo &item) +typename std::enable_if::value, Exception>::type +operator<<(Exception ex, const ExceptionInfo &item) { - const_cast(ex).setInfo(item); + ex.setInfo(item); return ex; } diff --git a/src/gromacs/utility/qsort_threadsafe.cpp b/src/gromacs/utility/qsort_threadsafe.cpp index aaae4d03e4..e5a6404b38 100644 --- a/src/gromacs/utility/qsort_threadsafe.cpp +++ b/src/gromacs/utility/qsort_threadsafe.cpp @@ -122,7 +122,7 @@ gmx_qsort(void * base, size_t size, int (*compar)(const void *, const void *)) { -#define QSORT_EXCH(a, b, t) (t = a, a = b, b = t) +#define QSORT_EXCH(a, b, t) ((t) = (a), (a) = (b), (b) = (t)) #define QSORT_SWAP(a, b) swaptype != 0 ? qsort_swapfunc(a, b, size, swaptype) : \ (void)QSORT_EXCH(*(int *)(a), *(int *)(b), t)