From 95466e9d55b2312c5ef793bda110814033522b25 Mon Sep 17 00:00:00 2001 From: Roland Schulz Date: Fri, 13 Jul 2018 15:51:36 -0700 Subject: [PATCH] MSVC: enable code analysis Change-Id: Iff67fd7640e9a4498525a72bb178b98335e43469 --- src/gromacs/CMakeLists.txt | 27 +++++++++++++++++++ src/gromacs/fft/fft5d.cpp | 2 +- src/gromacs/gmxana/gmx_chi.cpp | 2 +- src/gromacs/gmxana/gmx_hbond.cpp | 2 +- src/gromacs/listed-forces/listed-forces.cpp | 2 +- src/gromacs/mdlib/lincs.cpp | 2 +- src/gromacs/mdlib/vsite.cpp | 2 +- .../taskassignment/resourcedivision.cpp | 2 +- src/gromacs/utility/compare.cpp | 4 +-- src/gromacs/utility/gmxassert.h | 7 +++++ 10 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/gromacs/CMakeLists.txt b/src/gromacs/CMakeLists.txt index 870f3cadb0..3bff3a9bc5 100644 --- a/src/gromacs/CMakeLists.txt +++ b/src/gromacs/CMakeLists.txt @@ -300,6 +300,33 @@ string(REPLACE " " ";" IGNORED_CLANG_ALL_WARNINGS "${IGNORED_CLANG_ALL_WARNINGS} if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION MATCHES "^6\.0") target_compile_options(libgromacs PRIVATE $<$:-Weverything ${IGNORED_CLANG_ALL_WARNINGS}>) endif() +if (MSVC) + target_compile_options(libgromacs PRIVATE $<$:/analyze /analyze:stacksize 70000 + #Control flow warnings are disabled because the commond line output is insufficient. There is no tool + #to convert the xml report to e.g. HTML and even in Visual Studio the viewer doesn't work with cmake support. + /wd6001 #unitialized memory + /wd6011 #derefencing NULL + /wd6053 #prior call not zero-terminate + /wd6054 #might not be zero-terminated + /wd6385 #reading invalid data + /wd6386 #buffer overrun + /wd6387 #could be '0' + /wd28199 #uninitialized memory + # For compile time constant (e.g. templates) the following warnings have flase postives + /wd6239 #( && ) + /wd6294 #Ill-defined for-loop + /wd6326 #comparison of constant with other constant + /wd28020 #expression involving paramter is not true + # Misc + /wd6330 #incorrect type to function (warns for char (instead of unsigned) for isspace/isalpha/isdigit/..)) + /wd6993 #OpenMP ignored + #TODO + /wd6031 #return value ignored (important - mostly warnigns about sscanf) + /wd6244 #hides declaration (known issue - we ingore similar warnings for other compilers) + /wd6246 #hides declaration + > + ) +endif() if (GMX_CLANG_TIDY) set(CLANG_TIDY "clang-tidy" CACHE STRING "Name of clang-tidy executable") find_program(CLANG_TIDY_EXE NAMES "${CLANG_TIDY}" diff --git a/src/gromacs/fft/fft5d.cpp b/src/gromacs/fft/fft5d.cpp index 83a155ec81..a355672c13 100644 --- a/src/gromacs/fft/fft5d.cpp +++ b/src/gromacs/fft/fft5d.cpp @@ -197,7 +197,7 @@ fft5d_plan fft5d_plan_3d(int NG, int MG, int KG, MPI_Comm comm[2], int flags, t_ if (debug) { fprintf(debug, "FFT5D: N: %d, M: %d, K: %d, P: %dx%d, real2complex: %d, backward: %d, order yz: %d, debug %d\n", - NG, MG, KG, P[0], P[1], (flags&FFT5D_REALCOMPLEX) > 0, (flags&FFT5D_BACKWARD) > 0, (flags&FFT5D_ORDER_YZ) > 0, (flags&FFT5D_DEBUG) > 0); + NG, MG, KG, P[0], P[1], int((flags&FFT5D_REALCOMPLEX) > 0), int((flags&FFT5D_BACKWARD) > 0), int((flags&FFT5D_ORDER_YZ) > 0), int((flags&FFT5D_DEBUG) > 0)); } /* The check below is not correct, one prime factor 11 or 13 is ok. if (fft5d_fmax(fft5d_fmax(lpfactor(NG),lpfactor(MG)),lpfactor(KG))>7) { diff --git a/src/gromacs/gmxana/gmx_chi.cpp b/src/gromacs/gmxana/gmx_chi.cpp index 35e1f23c0d..c03f4757bc 100644 --- a/src/gromacs/gmxana/gmx_chi.cpp +++ b/src/gromacs/gmxana/gmx_chi.cpp @@ -927,7 +927,7 @@ static void do_rama(int nf, int nlist, t_dlist dlist[], real **dih, fprintf(fp, "%10g %10g\n", phi, psi); if (bViol) { - fprintf(gp, "%d\n", (bAllowed(dih[Phi][j], RAD2DEG*dih[Psi][j]) == FALSE) ); + fprintf(gp, "%d\n", int{(bAllowed(dih[Phi][j], RAD2DEG*dih[Psi][j]) == FALSE)} ); } if (bOm) { diff --git a/src/gromacs/gmxana/gmx_hbond.cpp b/src/gromacs/gmxana/gmx_hbond.cpp index 526cf7ed78..5329676f9a 100644 --- a/src/gromacs/gmxana/gmx_hbond.cpp +++ b/src/gromacs/gmxana/gmx_hbond.cpp @@ -220,7 +220,7 @@ static void mk_hbmap(t_hbdata *hb) { gmx_fatal(FARGS, "Could not allocate enough memory for hbmap"); } - for (j = 0; (j > hb->a.nra); j++) + for (j = 0; j < hb->a.nra; j++) { hb->hbmap[i][j] = nullptr; } diff --git a/src/gromacs/listed-forces/listed-forces.cpp b/src/gromacs/listed-forces/listed-forces.cpp index d1d2de44f0..33ee488b6c 100644 --- a/src/gromacs/listed-forces/listed-forces.cpp +++ b/src/gromacs/listed-forces/listed-forces.cpp @@ -97,7 +97,7 @@ zero_thread_output(bonded_threading_t *bt, int thread) } f_thread_t *f_t = &bt->f_t[thread]; - const int nelem_fa = sizeof(*f_t->f)/sizeof(real); + const int nelem_fa = sizeof(f_t->f[0])/sizeof(real); for (int i = 0; i < f_t->nblock_used; i++) { diff --git a/src/gromacs/mdlib/lincs.cpp b/src/gromacs/mdlib/lincs.cpp index 943327f6fb..40cbc8a321 100644 --- a/src/gromacs/mdlib/lincs.cpp +++ b/src/gromacs/mdlib/lincs.cpp @@ -1550,7 +1550,7 @@ Lincs *init_lincs(FILE *fplog, const gmx_mtop_t &mtop, if (debug && bPLINCS) { fprintf(debug, "PLINCS communication before each iteration: %d\n", - li->bCommIter); + int{li->bCommIter}); } /* LINCS can run on any number of threads. diff --git a/src/gromacs/mdlib/vsite.cpp b/src/gromacs/mdlib/vsite.cpp index aeac64e461..184f22dd92 100644 --- a/src/gromacs/mdlib/vsite.cpp +++ b/src/gromacs/mdlib/vsite.cpp @@ -2555,7 +2555,7 @@ void split_vsites_over_threads(const t_ilist *ilist, if (debug && vsite->nthreads > 1) { fprintf(debug, "virtual site useInterdependentTask %d, nuse:\n", - vsite->tData[0]->useInterdependentTask); + int{vsite->tData[0]->useInterdependentTask}); for (int th = 0; th < vsite->nthreads + 1; th++) { fprintf(debug, " %4d", vsite->tData[th]->idTask.nuse); diff --git a/src/gromacs/taskassignment/resourcedivision.cpp b/src/gromacs/taskassignment/resourcedivision.cpp index 309d054f49..a16deffb45 100644 --- a/src/gromacs/taskassignment/resourcedivision.cpp +++ b/src/gromacs/taskassignment/resourcedivision.cpp @@ -598,7 +598,7 @@ void check_resource_division_efficiency(const gmx_hw_info_t *hwinfo, nthreads_omp_mpi_ok_min = nthreads_omp_mpi_ok_min_gpu; } - if (DOMAINDECOMP(cr) && cr->nnodes > 1) + if (DOMAINDECOMP(cr)) { if (nth_omp_max < nthreads_omp_mpi_ok_min || nth_omp_max > nthreads_omp_mpi_ok_max) diff --git a/src/gromacs/utility/compare.cpp b/src/gromacs/utility/compare.cpp index 416d260158..d6f357d25e 100644 --- a/src/gromacs/utility/compare.cpp +++ b/src/gromacs/utility/compare.cpp @@ -94,11 +94,11 @@ void cmp_uc(FILE *fp, const char *s, int index, unsigned char i1, unsigned char { if (index != -1) { - fprintf(fp, "%s[%d] (%d - %d)\n", s, index, i1, i2); + fprintf(fp, "%s[%d] (%d - %d)\n", s, index, int{i1}, int{i2}); } else { - fprintf(fp, "%s (%d - %d)\n", s, i1, i2); + fprintf(fp, "%s (%d - %d)\n", s, int{i1}, int{i2}); } } } diff --git a/src/gromacs/utility/gmxassert.h b/src/gromacs/utility/gmxassert.h index 2a20d45340..43dab95941 100644 --- a/src/gromacs/utility/gmxassert.h +++ b/src/gromacs/utility/gmxassert.h @@ -63,6 +63,12 @@ #ifdef GMX_DISABLE_ASSERTS #define GMX_RELEASE_ASSERT(condition, msg) #else +#ifdef _MSC_VER +#define GMX_RELEASE_ASSERT(condition, msg) \ + ((void) ((condition) ? (void)0 : \ + ::gmx::internal::assertHandler(#condition, msg, \ + GMX_CURRENT_FUNCTION, __FILE__, __LINE__))) +#else // Use an "immediately invoked function expression" to allow being // used in constexpr context with older GCC versions // https://akrzemi1.wordpress.com/2017/05/18/asserts-in-constexpr-functions/ @@ -71,6 +77,7 @@ [&](){::gmx::internal::assertHandler(#condition, msg, \ GMX_CURRENT_FUNCTION, __FILE__, __LINE__); } ())) #endif +#endif /*! \def GMX_ASSERT * \brief * Macro for debug asserts. -- 2.22.0