clang-tidy: more misc+readability
authorRoland Schulz <roland.schulz@intel.com>
Sat, 30 Jun 2018 20:01:04 +0000 (13:01 -0700)
committerRoland Schulz <roland.schulz@intel.com>
Tue, 3 Jul 2018 07:55:21 +0000 (00:55 -0700)
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

28 files changed:
src/gromacs/CMakeLists.txt
src/gromacs/domdec/domdec_network.cpp
src/gromacs/ewald/pme-gather.cpp
src/gromacs/ewald/pme-gpu-program-impl.cpp
src/gromacs/ewald/pme-solve.cpp
src/gromacs/ewald/pme-spread.cpp
src/gromacs/fileio/libxdrf.cpp
src/gromacs/fileio/md5.cpp
src/gromacs/fileio/tpxio.cpp
src/gromacs/gmxana/gmx_chi.cpp
src/gromacs/gmxana/gmx_dipoles.cpp
src/gromacs/gmxana/gmx_enemat.cpp
src/gromacs/gmxana/gmx_hbond.cpp
src/gromacs/gmxana/princ.cpp
src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp
src/gromacs/gmxpreprocess/gen_vsite.cpp
src/gromacs/gmxpreprocess/hackblock.cpp
src/gromacs/gmxpreprocess/ter_db.cpp
src/gromacs/gpu_utils/gpu_utils.cpp
src/gromacs/mdlib/nbnxn_kernels/.clang-tidy [new file with mode: 0644]
src/gromacs/mdlib/nbnxn_search.cpp
src/gromacs/mdlib/nbnxn_tuning.cpp
src/gromacs/mdlib/ns.cpp
src/gromacs/pbcutil/mshift.cpp
src/gromacs/pulling/pull_rotation.cpp
src/gromacs/tools/check.cpp
src/gromacs/utility/exceptions.h
src/gromacs/utility/qsort_threadsafe.cpp

index eff1a0e93fff0d548fe49487eecdb7a7a0a501dc..6aa75f20410d8c029da410793f568560166b58cd 100644 (file)
@@ -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()
index 95609cfdf2aff98d4eed1c8297e8f9fce931f5ce..b093fc2fbc7dd1a611f6f2e05f7aaee57113926c 100644 (file)
@@ -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
index 000f24929b2a7d745e6e89f173a43ae7e6595956..b939468ab6abad20435cc0863a5a7ff6e7e36bd8 100644 (file)
@@ -137,7 +137,7 @@ struct do_fspline
  * This code does not assume any memory alignment for the grid.
  */
     RVec
-    operator()(std::integral_constant<int, 4>) const
+    operator()(std::integral_constant<int, 4> /*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<int order>
-    static inline void loadOrderU(const real* data, std::integral_constant<int, order>,
+    static inline void loadOrderU(const real* data, std::integral_constant<int, order> /*unused*/,
                                   int offset, Simd4Real* S0, Simd4Real* S1)
     {
 #ifdef PME_SIMD4_UNALIGNED
index 1fc76b58a2c99dd36b5a412b61ba38441e28b900..c98bf6bd924804edba41c9dbeb28a9dbfa9281a1 100644 (file)
@@ -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;
index f9cccf78d7a1d4e4e9713a7a50901b9e0d269ce5..856ffbb54c7cd9b37772c5badc1c7f30f9b60e6f 100644 (file)
@@ -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<const SimdReal> d_aligned, ArrayRef<const SimdReal> r_aligned, ArrayRef<SimdReal> e_aligned)
+inline static void calc_exponentials_q(int /*unused*/, int /*unused*/, real f, ArrayRef<const SimdReal> d_aligned, ArrayRef<const SimdReal> r_aligned, ArrayRef<SimdReal> e_aligned)
 {
     {
         SimdReal              f_simd(f);
@@ -265,7 +265,7 @@ inline static void calc_exponentials_q(int start, int end, real f, ArrayRef<real
 
 #if defined PME_SIMD_SOLVE
 /* Calculate exponentials through SIMD */
-inline static void calc_exponentials_lj(int, int, ArrayRef<SimdReal> r_aligned, ArrayRef<SimdReal> factor_aligned, ArrayRef<SimdReal> d_aligned)
+inline static void calc_exponentials_lj(int /*unused*/, int /*unused*/, ArrayRef<SimdReal> r_aligned, ArrayRef<SimdReal> factor_aligned, ArrayRef<SimdReal> d_aligned)
 {
     SimdReal              tmp_r, tmp_d, tmp_fac, d_inv, tmp_mk;
     const SimdReal        sqr_PI = sqrt(SimdReal(M_PI));
index e77c7910d939f7419f5cfc4725dc58e003ecb73e..ff71c7fd87ce13a34e634b2db13d2402300ebe97 100644 (file)
@@ -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];      \
index 8b8cc023615cd7238a21fb132b382be62ab53349..1aa2ed272060254cdc1f6e783711c0b5e821b0be 100644 (file)
@@ -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))
index bacff2887dcc4170dea63a168d0a5b48f62d4492..9b9e6e88ab1056d0fb1a914f189887bb2e49a84b 100644 (file)
@@ -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);
index d33fca80eaa43fe2b66d2278694f4d7c9baa412d..d59b34b429ec68c483fd36b303812d37fb793276 100644 (file)
@@ -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)
index 35adac367f932a87030e9022555b5a54e5377eda..35e1f23c0d481e8e0716a1f34cd5313e80341233 100644 (file)
@@ -130,7 +130,7 @@ static gmx_bool bAllowed(real phi, real psi)
 #define NPP asize(map)
     int                x, y;
 
-#define INDEX(ppp) (((static_cast<int> (360+ppp*RAD2DEG)) % 360)/6)
+#define INDEX(ppp) (((static_cast<int> (360+(ppp)*RAD2DEG)) % 360)/6)
     x = INDEX(phi);
     y = INDEX(psi);
 #undef INDEX
index 00333c9094b38ecb877bbbf0c3c25f7b8b926a28..94aea2f132b8462b7878f08e35f3b4d21533ac75 100644 (file)
@@ -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);
index f5dab5afbfe9440345bafffcecc8bee01c7dcc00..676b2608efbb657795ce2e73e8255ab51bd0ffff 100644 (file)
@@ -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)
             {
index 08a7a8cf7b0f9fc8cddf7c16f7b56d32cc8fc652..7ac24d5415c9f2ee898bd368853269c24a8287f4 100644 (file)
@@ -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);
index 4f8e9af8f2fffe2a98daed63c0940ba69e5115af..65987d9d406541735de4ae6cb7224a9318ef59b4 100644 (file)
@@ -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)
index 6192ca8b8579d2653726c50ba71b219c60b8b2f0..b42def31cc4ab06294ea72a6d5cf15aeb3c6f58c 100644 (file)
@@ -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);
index 69d78151626535ef814d5fbb767ddceb8b8bde99..404fbdbc8509c38f775dec88cd00a170656a0d1f 100644 (file)
@@ -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,
index cf81e0e10cbe4922bc27b22102cc2a073e998aef..606a02a3033a02b57223c1d07c30d075408803df 100644 (file)
@@ -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)
 {
index ab6e078edec7464397867b3b5462d66358e452f5..b60d3dd4d4f82c8ccfefcbc0c0588c6fc8bfafa4 100644 (file)
@@ -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"
index 3b943dabfb31f3fd29f1d5ab39c48e1e236e5a7f..07d2ad4de0cba95d0cc0648b12fcf55918da452a 100644 (file)
@@ -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 (file)
index 0000000..c05e99a
--- /dev/null
@@ -0,0 +1,3 @@
+CheckOptions:
+  - key:             readability-function-size.StatementThreshold
+    value:           2000
index a61d705bbdfe66d50455c26871a2f71e196700a5..5cd0a9bafa6a71eaa7aa8fab07bf53c8537f9d6c 100644 (file)
@@ -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 */
index e78d8ae594469913687cad26d5e0268c99d1204c..b63702e075144da108e6369cc7babd3d24ea777a 100644 (file)
@@ -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.
index f0c1e111bc42fa9e537ee83687b9309c17794d4b..2e0085a9588795149b93bb8937786267610d3eb7 100644 (file)
@@ -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
index f0ff01ab08fc90be11efb1ca9ccd3be497c38709..87f3396af5765998815be96fc0b189a2647cfb10 100644 (file)
@@ -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)
 {
index a3411b06a5460dd180e8af4efee4c414d86b1f47..fb6aebb349b19cb06b879f2d9e5d8117b070424b 100644 (file)
@@ -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 */
index 8bb686a9946c3cd88a51387bb886308a6e189345..33bff294a3f03d9320459868450ebb3581197a7a 100644 (file)
@@ -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);
index fd66bdb98870ca2fafa92a5fcd9ab49257cd6726..be82bc080874aaa58b69a55b86fc826a5706d1b4 100644 (file)
@@ -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 <class Exception, class Tag, class T>
 inline
-typename std::enable_if<std::is_base_of<GromacsException, Exception>::value, const Exception &>::type
-operator<<(const Exception &ex, const ExceptionInfo<Tag, T> &item)
+typename std::enable_if<std::is_base_of<GromacsException, Exception>::value, Exception>::type
+operator<<(Exception ex, const ExceptionInfo<Tag, T> &item)
 {
-    const_cast<Exception &>(ex).setInfo(item);
+    ex.setInfo(item);
     return ex;
 }
 
index aaae4d03e416a35ad3ffd2607f5634d027fc64c5..e5a6404b38e7b15c08db97502135639b376426a4 100644 (file)
@@ -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)