MSVC: enable code analysis
authorRoland Schulz <roland.schulz@intel.com>
Fri, 13 Jul 2018 22:51:36 +0000 (15:51 -0700)
committerRoland Schulz <roland.schulz@intel.com>
Sat, 14 Jul 2018 18:35:23 +0000 (11:35 -0700)
Change-Id: Iff67fd7640e9a4498525a72bb178b98335e43469

src/gromacs/CMakeLists.txt
src/gromacs/fft/fft5d.cpp
src/gromacs/gmxana/gmx_chi.cpp
src/gromacs/gmxana/gmx_hbond.cpp
src/gromacs/listed-forces/listed-forces.cpp
src/gromacs/mdlib/lincs.cpp
src/gromacs/mdlib/vsite.cpp
src/gromacs/taskassignment/resourcedivision.cpp
src/gromacs/utility/compare.cpp
src/gromacs/utility/gmxassert.h

index 870f3cadb023b113ce97d4c435673ec43343ecb9..3bff3a9bc53101630b28b25135366b0338bd5f76 100644 (file)
@@ -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 $<$<COMPILE_LANGUAGE:CXX>:-Weverything ${IGNORED_CLANG_ALL_WARNINGS}>)
 endif()
+if (MSVC)
+   target_compile_options(libgromacs PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/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  #(<non-zero> && <expr>)
+     /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}"
index 83a155ec813ef9c524a14cdd2c18197946ae13b1..a355672c1306b2857255786e217a409291d1dad2 100644 (file)
@@ -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) {
index 35e1f23c0d481e8e0716a1f34cd5313e80341233..c03f4757bcb4ad60ca952d4cb6636f795148b0fc 100644 (file)
@@ -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)
                 {
index 526cf7ed78b02e8d705e3659b0a46cb1722f8454..5329676f9a4e3b2c8a7e64f995d538e2aa3aae4f 100644 (file)
@@ -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;
         }
index d1d2de44f068a100730fe16d62903bbe7fbc7129..33ee488b6ca2dfb4207c88172e8e607672826928 100644 (file)
@@ -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++)
     {
index 943327f6fb8fad765f4d5f3ce400dbc10b0a8cc9..40cbc8a3211be5ff9bb3e9e8bbbfabc2e0f1d65c 100644 (file)
@@ -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.
index aeac64e4614309b89a04a53c6f314ee762002bcf..184f22dd9234e883d672b6631d71cffe5bfe5190 100644 (file)
@@ -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);
index 309d054f494f14e57332fe0316a116f0af366f73..a16deffb4520c0fa0803a92e17d3709de2a12413 100644 (file)
@@ -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)
index 416d260158f6dd9560dd5f3858a845d67bb05850..d6f357d25e56b21abbb52e554cf303df15fe34f8 100644 (file)
@@ -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});
         }
     }
 }
index 2a20d453402a8a8f67ac6a826da6ca09690300b0..43dab95941d9fe4765fe768ab3d43fd4ab4892f4 100644 (file)
 #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.