[GRASS-dev] [GRASS GIS] #2787: grass-7.0.1: compiling on Gentoo shows warnings when built with -Wagressive-loop-optimizations

#2787: grass-7.0.1: compiling on Gentoo shows warnings when built with
-Wagressive-loop-optimizations
-------------------------+-------------------------
Reporter: wraeth | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone:
Component: Compiling | Version: 7.0.1
Keywords: | CPU: x86-64
Platform: Linux |
-------------------------+-------------------------
* QA Notice: Package triggers severe warnings which indicate that it
  * may exhibit random runtime failures.
  * main.c:312:2: warning: iteration 14u invokes undefined behavior
[-Waggressive-loop-optimizations]
  * main.c:308:6: warning: iteration 14u invokes undefined behavior
[-Waggressive-loop-optimizations]
  * main.c:278:6: warning: iteration 14u invokes undefined behavior
[-Waggressive-loop-optimizations]
  * aerosolmodel.cpp:619:59: warning: iteration 82u invokes undefined
behavior [-Waggressive-loop-optimizations]

This appears to be coming from the files:
   imagery/i.aster.toar/main.c
   imagery/i.atcorr/aerosolmodel.cpp

Compile log to follow.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2787&gt;
GRASS GIS <https://grass.osgeo.org>

#2787: grass-7.0.1: compiling on Gentoo shows warnings when built with
-Wagressive-loop-optimizations
--------------------------+-------------------------
  Reporter: wraeth | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone:
Component: Compiling | Version: 7.0.1
Resolution: | Keywords:
       CPU: x86-64 | Platform: Linux
--------------------------+-------------------------
Changes (by wraeth):

* Attachment "grass-7.0.1:201510300002.log.gz" added.

Compressed build output

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2787&gt;
GRASS GIS <https://grass.osgeo.org>

#2787: grass-7.0.1: compiling on Gentoo shows warnings when built with
-Wagressive-loop-optimizations
--------------------------+-------------------------
  Reporter: wraeth | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone:
Component: Compiling | Version: 7.0.1
Resolution: | Keywords:
       CPU: x86-64 | Platform: Linux
--------------------------+-------------------------

Comment (by wraeth):

Formatting messed the lines. The errors are produced when compiling the
files `imagery/i.aster.toar/main.c` and
`imagery/i.atcorr/aerosolmodel.cpp`

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2787#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#2787: grass-7.0.1: compiling on Gentoo shows warnings when built with
-Wagressive-loop-optimizations
--------------------------+-------------------------
  Reporter: wraeth | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone:
Component: Compiling | Version: 7.0.1
Resolution: | Keywords:
       CPU: x86-64 | Platform: Linux
--------------------------+-------------------------

Comment (by glynn):

Replying to [ticket:2787 wraeth]:

> * main.c:312:2: warning: iteration 14u invokes undefined behavior
[-Waggressive-loop-optimizations]
> * main.c:308:6: warning: iteration 14u invokes undefined behavior
[-Waggressive-loop-optimizations]
> * main.c:278:6: warning: iteration 14u invokes undefined behavior
[-Waggressive-loop-optimizations]

imagery/i.aster.toar/main.c

{{{
77 /*File Descriptors */
78 int infd[MAXFILES];
79 int outfd[MAXFILES];
}}}

{{{
277 for (i = 1; i <= MAXFILES; i++)
278 Rast_get_row(infd[i], inrast[i-1], row, in_data_type[i-1]);
}}}

{{{
307 for (i = 1; i <= MAXFILES; i++)
308 Rast_put_row(outfd[i], outrast[i-1], out_data_type);
}}}

{{{
310 for (i = 1; i <= MAXFILES; i++) {
311 G_free(inrast[i-1]);
312 Rast_close(infd[i]);
313 G_free(outrast[i-1]);
314 Rast_close(outfd[i]);
315 }
}}}

i can be equal to MAXFILES, which is the side of infd and outfd, so
accessing infd[i] and outfd[i] is undefined behaviour.

> * aerosolmodel.cpp:619:59: warning: iteration 82u invokes undefined
behavior [-Waggressive-loop-optimizations]

imagery/i.atcorr/common.h

{{{
51 float phasel[10][83];
}}}

imagery/i.atcorr/aerosolmodel.cpp

{{{
619 for (int k = 1; k <= 83; ++k) sixs_sos.phasel[i][k] = 0.f;
}}}

Similar issue.

Was this converted from Fortran?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2787#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>

#2787: grass-7.0.1: compiling on Gentoo shows warnings when built with
-Wagressive-loop-optimizations
--------------------------+-------------------------
  Reporter: wraeth | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.0.1
Component: Compiling | Version: 7.0.1
Resolution: | Keywords:
       CPU: x86-64 | Platform: Linux
--------------------------+-------------------------
Changes (by neteler):

* milestone: => 7.0.1

Comment:

Replying to [comment:2 glynn]:
> Was this converted from Fortran?

Yes, long time back.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2787#comment:3&gt;
GRASS GIS <https://grass.osgeo.org>

#2787: grass-7.0.1: compiling on Gentoo shows warnings when built with
-Wagressive-loop-optimizations
--------------------------+--------------------------
  Reporter: wraeth | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.0.3
Component: Compiling | Version: 7.0.1
Resolution: | Keywords: i.aster.toar
       CPU: x86-64 | Platform: Linux
--------------------------+--------------------------
Changes (by neteler):

* keywords: => i.aster.toar
* milestone: 7.0.1 => 7.0.3

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2787#comment:4&gt;
GRASS GIS <https://grass.osgeo.org>

#2787: grass-7.0.1: compiling on Gentoo shows warnings when built with
-Wagressive-loop-optimizations
--------------------------+--------------------------
  Reporter: wraeth | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.4.1
Component: Compiling | Version: 7.0.1
Resolution: | Keywords: i.aster.toar
       CPU: x86-64 | Platform: Linux
--------------------------+--------------------------

Comment (by martinl):

What is status of this issue?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2787#comment:11&gt;
GRASS GIS <https://grass.osgeo.org>

#2787: grass-7.0.1: compiling on Gentoo shows warnings when built with
-Wagressive-loop-optimizations
------------------------+--------------------------
  Reporter: wraeth | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.4.0
Component: Compiling | Version: 7.0.1
Resolution: fixed | Keywords: i.aster.toar
       CPU: x86-64 | Platform: Linux
------------------------+--------------------------
Changes (by neteler):

* status: new => closed
* type: enhancement => defect
* resolution: => fixed
* milestone: 7.4.1 => 7.4.0

Comment:

I have now compiled relbranch74 (a.k.a. 7.4.0) with -Waggressive-loop-
optimizations and the above reported i.atcorr compilation issues are fixed
after Markus Metz's latest improvements.

Closing, feel free to reopen if needed.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2787#comment:12&gt;
GRASS GIS <https://grass.osgeo.org>