Disable clang-analyzer because we run analyzer as seperate job.
Disable cppcoreguidelines-avoid-goto because it is easy to spot
in code-review and has very rare good uses.
Change-Id: Ibfeb8ba6b14012b0079e7eef15282e0e2b6538fc
# Test newest cmake at time of release
# Test with clang-tidy (without OpenMP, cmake>=3.6)
-clang-6 no-openmp cmake-3.12.1 tidy
+clang-7 no-openmp cmake-3.12.1 tidy
# Test oldest supported MSVC on Windows
# Test newest supported MSVC on Windows
regression tests
clang-tidy
- `clang-tidy <http://releases.llvm.org/6.0.0/tools/clang/tools/extra/docs/clang-tidy/index.html>`_
+ `clang-tidy <http://releases.llvm.org/7.0.0/tools/clang/tools/extra/docs/clang-tidy/index.html>`_
is used for static code analysis. clang-tidy is easy to install. It is contained in
the llvm binary `package <http://releases.llvm.org/download.html#6.0.0>`_. Only
- version 6.0.* with libstdc++<7 or libc++ is supported. Others might miss tests or give false positives.
+ version 7.0.* with libstdc++<7 or libc++ is supported. Others might miss tests or give false positives.
It is run automatically on Jenkins for each commit. Many checks have fixes which can automatically be
applied. To run it, the build has to be configured with
``cmake -DGMX_CLANG_TIDY=ON -DGMX_OPENMP=no -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=on``.
-Checks: clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-security.insecureAPI.strcpy,
+Checks: clang-diagnostic-*,-clang-analyzer-*,-clang-analyzer-security.insecureAPI.strcpy,
bugprone-*,misc-*,readability-*,performance-*,mpi-*,
-readability-inconsistent-declaration-parameter-name,
-readability-function-size,-readability-else-after-return,
modernize-redundant-void-arg,modernize-use-bool-literals,
cppcoreguidelines-*,-cppcoreguidelines-pro-*,-cppcoreguidelines-owning-memory,
-cppcoreguidelines-no-malloc,-cppcoreguidelines-special-member-functions,
+ -cppcoreguidelines-avoid-goto,
google-*,-google-build-using-namespace,-google-explicit-constructor,
-google-readability-function-size,-google-readability-todo,-google-runtime-int
HeaderFilterRegex: .*
-Checks: clang-diagnostic-*,clang-analyzer-*,
+Checks: clang-diagnostic-*,-clang-analyzer-*,
bugprone-*,misc-*,readability-*,performance-*,mpi-*,-misc-incorrect-roundings,
-readability-else-after-return,
modernize-use-nullptr,modernize-use-emplace,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
+ -cppcoreguidelines-avoid-goto,
google-*,-google-build-using-namespace,-google-explicit-constructor,
-google-readability-todo,
-google-runtime-int
else
{
time_unit_t time_unit
- = static_cast<time_unit_t>(impl_->settings_.timeUnit() + 1); // NOLINT(misc-misplaced-widening-cast)
+ = static_cast<time_unit_t>(impl_->settings_.timeUnit() + 1); // NOLINT(bugprone-misplaced-widening-cast)
xvg_format_t xvg_format
= (impl_->settings_.plotFormat() > 0
? static_cast<xvg_format_t>(impl_->settings_.plotFormat())
int stride = 1;
/* Workaround for bug in clang */
-#ifndef __clang_analyzer__
for (int k = d + 1; k < numDimensions; k++)
{
stride *= numPointsDim[k];
}
-#endif
indexMulti[d] = indexLinear/stride;
indexLinear -= indexMulti[d]*stride;
* In taking this deviation we lose a lot of precision, so we should
* compare against k*max(coord) instead of the instantaneous force.
*/
- const double kCoordMax = bias.dimParams()[0].k*coordMaxValue;
+ const double kCoordMax = bias.dimParams()[0].k*coordMaxValue;
- const double ulpTol = 10;
+ constexpr int ulpTol = 10;
checker.checkSequence(props.begin(), props.end(), "Properties");
checker.setDefaultTolerance(absoluteTolerance(kCoordMax*GMX_DOUBLE_EPS*ulpTol));
/* set program name, command line, and default values for output options */
output_env_init(oenv, gmx::getProgramContext(),
- static_cast<time_unit_t>(timeUnit + 1), bView, // NOLINT(misc-misplaced-widening-cast)
+ static_cast<time_unit_t>(timeUnit + 1), bView, // NOLINT(bugprone-misplaced-widening-cast)
static_cast<xvg_format_t>(xvgFormat + 1), 0);
/* Extract Time info from arguments */
atoms_global.nr = mtop->natoms;
atoms_global.atom = nullptr; /* Only used with virtual sites */
- GMX_RELEASE_ASSERT(mtop->intermolecular_ilist.get(), "We should have an ilist when intermolecular interactions are on");
+ GMX_RELEASE_ASSERT(mtop->intermolecular_ilist, "We should have an ilist when intermolecular interactions are on");
*nint +=
make_reverse_ilist(*mtop->intermolecular_ilist,
atoms.nr = mtop->natoms;
atoms.atom = nullptr;
- GMX_RELEASE_ASSERT(mtop->intermolecular_ilist.get(), "We should have an ilist when intermolecular interactions are on");
+ GMX_RELEASE_ASSERT(mtop->intermolecular_ilist, "We should have an ilist when intermolecular interactions are on");
make_reverse_ilist(*mtop->intermolecular_ilist,
&atoms,
gmx_fatal(FARGS, "The combination of intermolecular interactions, charge groups and domain decomposition is not supported. Use cutoff-scheme=Verlet (which removes the charge groups) or run without domain decomposition.");
}
- GMX_RELEASE_ASSERT(mtop->intermolecular_ilist.get(), "We should have an ilist when intermolecular interactions are on");
+ GMX_RELEASE_ASSERT(mtop->intermolecular_ilist, "We should have an ilist when intermolecular interactions are on");
bonded_distance_intermol(*mtop->intermolecular_ilist,
bBCheck,
#include <string>
#include "gromacs/fileio/gmxfio.h"
+#include "gromacs/math/functions.h"
#include "gromacs/math/utilities.h"
#include "gromacs/utility/binaryinformation.h"
#include "gromacs/utility/cstringutil.h"
fprintf(out, "\"");
for (i = 0; (i < n_x); i++)
{
- c = std::round((mat[i][j]-lo)*invlevel);
+ c = gmx::roundToInt((mat[i][j]-lo)*invlevel);
if (c < 0)
{
c = 0;
{
if (mat[i][j] >= mid)
{
- c = nmid+std::round((mat[i][j]-mid)*invlev_hi);
+ c = nmid+gmx::roundToInt((mat[i][j]-mid)*invlev_hi);
}
else if (mat[i][j] >= lo)
{
- c = std::round((mat[i][j]-lo)*invlev_lo);
+ c = gmx::roundToInt((mat[i][j]-lo)*invlev_lo);
}
else
{
{
if (i < j)
{
- c = nlevel_bot+std::round((mat[i][j]-lo_top)*invlev_top);
+ c = nlevel_bot+gmx::roundToInt((mat[i][j]-lo_top)*invlev_top);
if ((c < nlevel_bot) || (c >= nlevel_bot+nlevel_top))
{
gmx_fatal(FARGS, "Range checking i = %d, j = %d, c = %d, bot = %d, top = %d matrix[i,j] = %f", i, j, c, nlevel_bot, nlevel_top, mat[i][j]);
}
else if (i > j)
{
- c = std::round((mat[i][j]-lo_bot)*invlev_bot);
+ c = gmx::roundToInt((mat[i][j]-lo_bot)*invlev_bot);
if ((c < 0) || (c >= nlevel_bot+nlevel_bot))
{
gmx_fatal(FARGS, "Range checking i = %d, j = %d, c = %d, bot = %d, top = %d matrix[i,j] = %f", i, j, c, nlevel_bot, nlevel_top, mat[i][j]);
anm_copy[2] = nc;
if (gmx_atomprop_query(aps, epropElement, "???", anm_copy, &eval))
{
- atomnumber = std::round(eval);
+ atomnumber = gmx::roundToInt(eval);
atomNumberSet = true;
}
else
anm_copy[1] = nc;
if (gmx_atomprop_query(aps, epropElement, "???", anm_copy, &eval))
{
- atomnumber = std::round(eval);
+ atomnumber = gmx::roundToInt(eval);
atomNumberSet = true;
}
}
anm_copy[1] = nc;
if (gmx_atomprop_query(aps, epropElement, "???", anm_copy, &eval))
{
- atomnumber = std::round(eval);
+ atomnumber = gmx::roundToInt(eval);
atomNumberSet = true;
}
}
static void add2gkr(t_gkrbin *gb, real r, real cosa, real phi)
{
- int cy, index = std::round(r/gb->spacing);
+ int cy, index = gmx::roundToInt(r/gb->spacing);
real alpha;
if (index < gb->nelem)
{
qtot += atoms.atom[i].q;
}
- iqtot = std::round(qtot);
+ iqtot = gmx::roundToInt(qtot);
if (conc > 0)
{
/* Compute number of ions to be added */
vol = det(box);
- nsalt = std::round(conc*vol*AVOGADRO/1e24);
+ nsalt = gmx::roundToInt(conc*vol*AVOGADRO/1e24);
p_num = abs(nsalt*n_q);
n_num = abs(nsalt*p_q);
}
char **grpname;
int i, i0, i1, j, N, nat_trx;
real *DD, *SigmaD, a, a2, b, r, chi2;
- rvec *x;
+ rvec *x = nullptr;
matrix box;
int *gnx_com = nullptr; /* the COM removal group size */
int **index_com = nullptr; /* the COM removal group atom indices */
}
for (gmx::index i = 0; i < inFiles.size(); i++)
{
- int j = std::round(value[i][k]);
+ int j = gmx::roundToInt(value[i][k]);
range_check(j, 0, inFiles.size());
if (bSet[j])
{
{
gmx_fatal(FARGS, "Error reading from file %s", fn);
}
-
+ GMX_ASSERT(nx > 0, "");
sd->nx = nx;
sd->ny = ny;
sd->dx = nx/(2*M_PI);
-Checks: -*
+Checks: -modernize-*
{
x = -x;
}
- ix = std::round(x);
+ ix = gmx::roundToInt(x);
return (fabs(x-ix) < tol);
}
bool
checkDualAvx512FmaUnits()
{
- uint64_t timeFmaAndShuf = 1e9; // Large value
+ uint64_t timeFmaAndShuf = static_cast<uint64_t>(1e9); // Large value
// Make sure the CPU is in AVX512 mode by executing a fairly long loop.
// Use the return value to make sure it is not optimized away. Later invocations
ntab = static_cast<int>(rtab);
eps = rtab-ntab;
eps2 = eps*eps;
- ntab = tableStride*ntab;
+ ntab = static_cast<int>(tableStride*ntab);
/* Electrostatics */
Y = vftab[ntab];
F = vftab[ntab+1];
ntab = static_cast<int>(rtab);
eps = rtab-ntab;
eps2 = eps*eps;
- ntab = tableStride*ntab;
+ ntab = static_cast<int>(tableStride*ntab);
/* Electrostatics */
Y = vftab[ntab];
F = vftab[ntab+1];
gmx_bool bInvert;
npbcdim = ePBC2npbcdim(ePBC);
-
+ GMX_ASSERT((ePBC == epbcNONE) == (npbcdim == 0), "");
if (refcoord_scaling == erscCOM)
{
clear_rvec(com_sc);
rvec comA_sc, comB_sc, rdist, dpdl, dx;
npbcdim = ePBC2npbcdim(ePBC);
-
+ GMX_ASSERT((ePBC == epbcNONE) == (npbcdim == 0), "");
if (refcoord_scaling == erscCOM)
{
clear_rvec(comA_sc);
*/
static inline int roundToInt(float x)
{
- return rintf(x);
+ return static_cast<int>(rintf(x));
}
//! Round double to int
static inline int roundToInt(double x)
{
- return rint(x);
+ return static_cast<int>(rint(x));
}
//! Round float to int64_t
static inline int64_t roundToInt64(float x)
{
- return rintf(x);
+ return static_cast<int>(rintf(x));
}
//! Round double to int64_t
static inline int64_t roundToInt64(double x)
{
- return rint(x);
+ return static_cast<int>(rint(x));
}
} // namespace gmx
const double *ivxi = &state->nosehoover_vxi[i*nh];
const double *iQinv = &(MassQ->Qinv[i*nh]);
- int nd = ir->opts.nrdf[i];
+ int nd = static_cast<int>(ir->opts.nrdf[i]);
real reft = std::max<real>(ir->opts.ref_t[i], 0);
real kT = BOLTZ * reft;
}
else
{
- ndj = 1.0;
+ ndj = 1;
}
energy += ndj*ixi[j]*kT;
}
{
r = rsq*rinv;
rt = r*iconst->tabq_scale;
- n0 = rt;
+ n0 = static_cast<int>(rt);
eps = rt - n0;
fexcl = (1 - eps)*Ftab[n0] + eps*Ftab[n0+1];
}
pullAllReduce(cr, comm, pull->group.size()*3*DIM,
- static_cast<double *>(comm->comBuffer.data()[0]));
+ static_cast<double *>(comm->comBuffer[0]));
for (size_t g = 0; g < pull->group.size(); g++)
{
/* Store the values */
if (param->flags & SPAR_VARNUM)
{
- dataGuard.release();
+ (void)dataGuard.release();
param->val.nr = n;
if (param->val.type == INT_VALUE)
{
#include "gromacs/selection/position.h"
#include "gromacs/selection/selectionenums.h"
#include "gromacs/utility/exceptions.h"
+#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
break;
default:
- GMX_THROW(gmx::InternalError("Memory pooling not implemented for requested type"));
+ gmx_incons("Memory pooling not implemented for requested type");
}
}
break;
default:
- GMX_THROW(gmx::InternalError("Memory pooling not implemented for requested type"));
+ gmx_incons("Memory pooling not implemented for requested type");
}
}
static inline std::int32_t
cvtR2I(float a)
{
- return std::round(a);
+ return static_cast<std::int32_t>(std::round(a));
};
/*! \brief Truncate single precision floating point to integer.
static inline std::int32_t
cvttR2I(float a)
{
- return std::trunc(a);
+ return static_cast<std::int32_t>(std::trunc(a));
};
/*! \brief Return integer.
static inline std::int32_t
cvtR2I(double a)
{
- return std::round(a);
+ return static_cast<std::int32_t>(std::round(a));
};
/*! \brief Truncate single precision doubleing point to integer.
static inline std::int32_t
cvttR2I(double a)
{
- return std::trunc(a);
+ return static_cast<std::int32_t>(std::trunc(a));
};
// We do not have a separate cvtI2R for double, since that would require
double spacing,
std::vector<real> *yfghTableData)
{
- int endIndex = range.second / spacing + 2;
+ int endIndex = static_cast<int>(range.second / spacing + 2);
yfghTableData->resize(4*endIndex);
double spacing,
std::vector<real> *yfghTableData)
{
- int endIndex = range.second / spacing + 2;
+ int endIndex = static_cast<int>(range.second / spacing + 2);
std::vector<double> tmpFunction(endIndex);
std::vector<double> tmpDerivative(endIndex);
{
double x = i * spacing;
double xtab = x / inputSpacing;
- int index = xtab;
+ int index = static_cast<int>(xtab);
double eps = xtab - index;
if (range.first > 0 && i == 0)
double minQuotient = GMX_REAL_MAX;
// loop over all functions to find smallest spacing
- for (auto thisFuncInput : analyticalInputList)
+ for (const auto &thisFuncInput : analyticalInputList)
{
try
{
// combine them into a multiplexed table function.
std::size_t funcIndex = 0;
- for (auto thisFuncInput : analyticalInputList)
+ for (const auto &thisFuncInput : analyticalInputList)
{
try
{
std::vector<real> *functionTableData,
std::vector<real> *derivativeTableData)
{
- std::size_t endIndex = range.second / spacing + 2;
+ std::size_t endIndex = static_cast<std::size_t>(range.second / spacing + 2);
functionTableData->resize(endIndex);
derivativeTableData->resize(endIndex);
std::vector<real> *functionTableData,
std::vector<real> *derivativeTableData)
{
- std::size_t endIndex = range.second / spacing + 2;
+ std::size_t endIndex = static_cast<std::size_t>(range.second / spacing + 2);
functionTableData->resize(endIndex);
derivativeTableData->resize(endIndex);
{
// Step 1: Interpolate the function value at x from input table.
double inputXTab = x / inputSpacing;
- int inputIndex = inputXTab;
+ int inputIndex = static_cast<std::size_t>(inputXTab);
double inputEps = inputXTab - inputIndex;
// Linear interpolation of input derivative and third derivative
double minQuotient = GMX_REAL_MAX;
// loop over all functions to find smallest spacing
- for (auto thisFuncInput : analyticalInputList)
+ for (const auto &thisFuncInput : analyticalInputList)
{
try
{
// combine them into a multiplexed table function.
std::size_t funcIndex = 0;
- for (auto thisFuncInput : analyticalInputList)
+ for (const auto &thisFuncInput : analyticalInputList)
{
try
{
double inputSpacing,
const std::pair<real, real> &range)
{
- std::size_t firstIndex = range.first / inputSpacing;
- std::size_t lastIndex = range.second / inputSpacing;
+ std::size_t firstIndex = static_cast<std::size_t>(range.first / inputSpacing);
+ std::size_t lastIndex = static_cast<std::size_t>(range.second / inputSpacing);
bool isConsistent = true;
std::size_t minFail = lastIndex;
std::size_t maxFail = firstIndex;
const std::pair<real, real> &range)
{
- std::size_t firstIndex = range.first / inputSpacing;
- std::size_t lastIndex = range.second / inputSpacing;
+ std::size_t firstIndex = static_cast<std::size_t>(range.first / inputSpacing);
+ std::size_t lastIndex = static_cast<std::size_t>(range.second / inputSpacing);
double minQuotient = GMX_REAL_MAX;
for (std::size_t i = firstIndex + 1; (i + 1) < lastIndex; i++)
const std::pair<real, real> &range)
{
- std::size_t firstIndex = range.first / inputSpacing;
- std::size_t lastIndex = range.second / inputSpacing;
+ std::size_t firstIndex = static_cast<std::size_t>(range.first / inputSpacing);
+ std::size_t lastIndex = static_cast<std::size_t>(range.second / inputSpacing);
double minQuotient = GMX_REAL_MAX;
for (std::size_t i = firstIndex + 2; (i + 2) < lastIndex; i++)
#include <cstdio>
#include <cstring>
+#include "gromacs/math/functions.h"
#include "gromacs/math/utilities.h"
#include "gromacs/topology/residuetypes.h"
#include "gromacs/utility/cstringutil.h"
{
if (gmx_strcasecmp(ap->prop[epropElement].atomnm[i], elem) == 0)
{
- return std::round(ap->prop[epropElement].value[i]);
+ return gmx::roundToInt(ap->prop[epropElement].value[i]);
}
}
return -1;
return;
}
time_unit_t time_unit
- = static_cast<time_unit_t>(settings_.timeUnit() + 1); // NOLINT(misc-misplaced-widening-cast)
+ = static_cast<time_unit_t>(settings_.timeUnit() + 1); // NOLINT(bugprone-misplaced-widening-cast)
output_env_init(&oenv_, getProgramContext(), time_unit, FALSE, exvgNONE, 0);
int frflags = settings_.frflags();
{
memset(m->data(), 255, b/64*8);
(*m)[b/64] = (static_cast<uint64_t>(1) << (b%64)) - 1;
- memset(&(m->data())[b/64+1], 0, (BITMASK_ALEN-b/64-1)*8);
+ memset(&(*m)[b/64+1], 0, (BITMASK_ALEN-b/64-1)*8);
}
inline static bool bitmask_is_set(gmx_bitmask_t m, int b)
int gmx_file_copy(const char *oldname, const char *newname, gmx_bool copy_if_empty)
{
-/* the full copy buffer size: */
-#define FILECOPY_BUFSIZE (1<<16)
- FILE *in = nullptr;
- FILE *out = nullptr;
- char *buf;
-
- snew(buf, FILECOPY_BUFSIZE);
-
- in = fopen(oldname, "rb");
+ gmx::FilePtr in(fopen(oldname, "rb"));
if (!in)
{
- goto error;
+ return 1;
}
/* If we don't copy when empty, we postpone opening the file
until we're actually ready to write. */
+ gmx::FilePtr out;
if (copy_if_empty)
{
- out = fopen(newname, "wb");
+ out.reset(fopen(newname, "wb"));
if (!out)
{
- goto error;
+ return 1;
}
}
- while (!feof(in))
+ /* the full copy buffer size: */
+ constexpr int FILECOPY_BUFSIZE = 1<<16;
+ std::vector<char> buf(FILECOPY_BUFSIZE);
+
+ while (!feof(in.get()))
{
size_t nread;
- nread = fread(buf, sizeof(char), FILECOPY_BUFSIZE, in);
+ nread = fread(buf.data(), sizeof(char), FILECOPY_BUFSIZE, in.get());
if (nread > 0)
{
size_t ret;
{
/* so this is where we open when copy_if_empty is false:
here we know we read something. */
- out = fopen(newname, "wb");
+ out.reset(fopen(newname, "wb"));
if (!out)
{
- goto error;
+ return 1;
}
}
- ret = fwrite(buf, sizeof(char), nread, out);
+ ret = fwrite(buf.data(), sizeof(char), nread, out.get());
if (ret != nread)
{
- goto error;
+ return 1;
}
}
- if (ferror(in))
+ if (ferror(in.get()))
{
- goto error;
+ return 1;
}
}
- sfree(buf);
- fclose(in);
- fclose(out);
return 0;
-error:
- sfree(buf);
- if (in)
- {
- fclose(in);
- }
- if (out)
- {
- fclose(out);
- }
- return 1;
-#undef FILECOPY_BUFSIZE
}
{
++start;
}
- while (start != end && std::isspace(*(end - 1)))
+ while (start != end && (std::isspace(*(end - 1)) != 0))
{
--end;
}
"no", "no");
// bd is much less reproducible in a rerun than the other integrators
- double toleranceScaleFactor = (integrator == "bd") ? 2 : 1;
+ const int toleranceScaleFactor = (integrator == "bd") ? 2 : 1;
EnergyTolerances energiesToMatch
{{
{
static inline FloatingPointTolerance defaultFloatTolerance()
{
return relativeToleranceAsPrecisionDependentUlp
- (1.0, detail::g_defaultUlpTolerance, detail::g_defaultUlpTolerance * (GMX_FLOAT_EPS / GMX_DOUBLE_EPS));
+ (1.0, detail::g_defaultUlpTolerance,
+ static_cast<uint64_t>(detail::g_defaultUlpTolerance * (GMX_FLOAT_EPS / GMX_DOUBLE_EPS)));
}
/*! \name Assertions for floating-point comparison