Avoid array-bounds warnings with gcc 4.8.2
authorMark Abraham <mark.j.abraham@gmail.com>
Wed, 26 Feb 2014 14:58:50 +0000 (15:58 +0100)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 11 Mar 2014 12:07:41 +0000 (13:07 +0100)
The asserts fix RelWithAssert build and for Relase
build the warning is suppressed.

Change-Id: I0a7e6576014bd32648a1e2f08d88e1f2eef3335e

cmake/gmxCFlags.cmake
src/gromacs/gmxlib/bondfree.c
src/gromacs/gmxlib/pbc.c
src/gromacs/gmxpreprocess/grompp.c
src/gromacs/gmxpreprocess/toppush.c
src/gromacs/gmxpreprocess/x2top.c
src/gromacs/mdlib/domdec.c

index 02c87bf178c1f3698ce3e5475085428102967c9b..1f373d64379baab6f410602f9b338de0ffe88b1d 100644 (file)
@@ -107,6 +107,9 @@ MACRO(gmx_c_flags)
         endif()
         GMX_TEST_CFLAG(CFLAGS_WARN "-Wall -Wno-unused -Wunused-value -Wunused-parameter" GMXC_CFLAGS)
         GMX_TEST_CFLAG(CFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers -Wno-sign-compare -Wpointer-arith" GMXC_CFLAGS)
+        # Since 4.8 on by default. For previous version disabling is a no-op. Only disabling for Release because with assert
+        # the warnings are OK.
+        GMX_TEST_CFLAG(CFLAGS_WARN_REL "-Wno-array-bounds" GMXC_CFLAGS_RELEASE_ONLY)
         # new in gcc 4.5
         GMX_TEST_CFLAG(CFLAGS_EXCESS_PREC "-fexcess-precision=fast" GMXC_CFLAGS_RELEASE)
         GMX_TEST_CFLAG(CFLAGS_COPT "-fomit-frame-pointer -funroll-all-loops"
@@ -122,6 +125,7 @@ MACRO(gmx_c_flags)
         # Problematic with CUDA
         # GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EFFCXX "-Wnon-virtual-dtor" GMXC_CXXFLAGS)
         GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers -Wpointer-arith" GMXC_CXXFLAGS)
+        GMX_TEST_CFLAG(CXXFLAGS_WARN_REL "-Wno-array-bounds" GMXC_CXXFLAGS_RELEASE_ONLY)
         # new in gcc 4.5
         GMX_TEST_CXXFLAG(CXXFLAGS_EXCESS_PREC "-fexcess-precision=fast" GMXC_CXXFLAGS_RELEASE)
         GMX_TEST_CXXFLAG(CXXFLAGS_COPT "-fomit-frame-pointer -funroll-all-loops"
index dfc6bf2fc57b00328b0a2744cad01262078b8a03..ca0110552e2309426f289c650eea3c0bf2d9e6b6 100644 (file)
@@ -2200,6 +2200,7 @@ static void posres_dx(const rvec x, const rvec pos0A, const rvec pos0B,
                     /* Box relative coordinates are stored for dimensions with pbc */
                     posA *= pbc->box[m][m];
                     posB *= pbc->box[m][m];
+                    assert(npbcdim <= DIM);
                     for (d = m+1; d < npbcdim; d++)
                     {
                         posA += pos0A[d]*pbc->box[d][m];
@@ -2264,6 +2265,7 @@ real fbposres(int nbonds,
         clear_rvec(com_sc);
         for (m = 0; m < npbcdim; m++)
         {
+            assert(npbcdim <= DIM);
             for (d = m; d < npbcdim; d++)
             {
                 com_sc[m] += com[d]*pbc->box[d][m];
@@ -2389,6 +2391,7 @@ real posres(int nbonds,
         clear_rvec(comB_sc);
         for (m = 0; m < npbcdim; m++)
         {
+            assert(npbcdim <= DIM);
             for (d = m; d < npbcdim; d++)
             {
                 comA_sc[m] += comA[d]*pbc->box[d][m];
index b9e48a236f525387c747e9c806da3c663b61f903..c2ceaef80d67c6ba9f39281e2b3024c1f2ee56e5 100644 (file)
@@ -39,6 +39,8 @@
 #endif
 
 #include <math.h>
+#include <assert.h>
+
 #include "sysstuff.h"
 #include "typedefs.h"
 #include "vec.h"
@@ -395,6 +397,7 @@ static void low_set_pbc(t_pbc *pbc, int ePBC, ivec *dd_nc, matrix box)
                         pbc->dim = i;
                     }
                 }
+                assert(pbc->dim < DIM);
                 for (i = 0; i < pbc->dim; i++)
                 {
                     if (pbc->box[pbc->dim][i] != 0)
index 49529521e263205c29cf3d32495d8b2ba306c62b..b337cd6b612d6aeb19e6fe5979d0fea7a458a6f0 100644 (file)
@@ -45,6 +45,7 @@
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
+#include <assert.h>
 
 #include "sysstuff.h"
 #include "smalloc.h"
@@ -887,6 +888,8 @@ static void read_posres(gmx_mtop_t *mtop, t_molinfo *molinfo, gmx_bool bTopB,
 
     if (rc_scaling != erscNO)
     {
+        assert(npbcdim <= DIM);
+
         for (mb = 0; mb < mtop->nmolblock; mb++)
         {
             molb     = &mtop->molblock[mb];
index 6f2badc2e5b09b0b57d034b9ad314663639a1f88..841c446731a3fce093d73457a4600470156e7cfe 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) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, 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.
@@ -40,6 +40,7 @@
 
 #include <ctype.h>
 #include <math.h>
+#include <assert.h>
 
 #include "sysstuff.h"
 #include "smalloc.h"
@@ -951,6 +952,7 @@ void push_nbt(directive d, t_nbparam **nbt, gpp_atomtype_t atype,
         /* When the B topology parameters are not set,
          * copy them from topology A
          */
+        assert(nrfp <= 4);
         for (i = n; i < nrfp; i++)
         {
             c[i] = c[i-2];
@@ -1822,7 +1824,8 @@ void push_bond(directive d, t_params bondtype[], t_params bond[],
         bFoundA = default_params(ftype, bondtype, at, atype, &param, FALSE, &param_defA, &nparam_defA);
         if (bFoundA)
         {
-            /* Copy the A-state and B-state default parameters */
+            /* Copy the A-state and B-state default parameters. */
+            assert(NRFPA(ftype)+NRFPB(ftype) <= MAXFORCEPARAM);
             for (j = 0; (j < NRFPA(ftype)+NRFPB(ftype)); j++)
             {
                 param.c[j] = param_defA->c[j];
index 4246eb7ee74bab66cf94c3bb136af0b60318e675..b3d051cb1273a3edb81f271b3907dcb5f6662943 100644 (file)
@@ -40,6 +40,8 @@
 #include <config.h>
 #endif
 
+#include <assert.h>
+
 #include "copyrite.h"
 #include "gromacs/math/utilities.h"
 #include "macros.h"
@@ -265,6 +267,7 @@ void lo_set_force_const(t_params *plist, real c[], int nrfp, gmx_bool bRound,
                 c[0] += 180;
             }
         }
+        assert(nrfp <= MAXFORCEPARAM/2);
         for (j = 0; (j < nrfp); j++)
         {
             plist->param[i].c[j]      = c[j];
index a344ba5bd732cb584c24f59f05800936484cc933..dc9132a70e3ea11064d33de8462b39de43a20331 100644 (file)
@@ -42,6 +42,8 @@
 #include <math.h>
 #include <string.h>
 #include <stdlib.h>
+#include <assert.h>
+
 #include "typedefs.h"
 #include "smalloc.h"
 #include "gmx_fatal.h"
@@ -8684,6 +8686,7 @@ static void set_zones_size(gmx_domdec_t *dd,
                 corner[YY] -= corner[ZZ]*box[ZZ][YY]/box[ZZ][ZZ];
             }
             /* Apply the triclinic couplings */
+            assert(ddbox->npbcdim <= DIM);
             for (i = YY; i < ddbox->npbcdim; i++)
             {
                 for (j = XX; j < i; j++)