[Bug fortran/84867] Wrong code generated, except at -O0, with inappropriate Warning: iteration 1 invokes undefined behavior [-Waggressive-loop-optimizations]
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Mar 14 16:16:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84867
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |RESOLVED
Last reconfirmed|2018-03-14 00:00:00 |
CC| |jakub at gcc dot gnu.org
Resolution|--- |INVALID
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
That is undefined behavior, so the warning correctly tells you your code will
not really work properly.
GCC has -funconstrained-commons option you can use to make that sort of
defined.
'-funconstrained-commons'
This option tells the compiler that variables declared in common
blocks (e.g. Fortran) may later be overridden with longer trailing
arrays. This prevents certain optimizations that depend on knowing
the array bounds.
Or you can use -fno-aggressive-loop-optimizations, though the hack is still UB
and it still might cause problems.
More information about the Gcc-bugs
mailing list