public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/66875] New: entire for loop got eliminated at cddce2 tree-opt stage
@ 2015-07-15  8:23 patricksung at gmail dot com
  2015-07-15 10:05 ` [Bug tree-optimization/66875] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: patricksung at gmail dot com @ 2015-07-15  8:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66875

            Bug ID: 66875
           Summary: entire for loop got eliminated at cddce2 tree-opt
                    stage
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patricksung at gmail dot com
  Target Milestone: ---

Created attachment 35985
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35985&action=edit
Intermediate of the C source

Hi the attached code in the parse_peppi_protocol() (which got inline into
parse()) with the for loop (and nearby code) from line 10821 to line 10995 got
eliminated.

We found out this problem starting with GCC version 4.9.2 and subsequently also
tested with GCC 4.9.3 and 5.1 also having this problem.

One of the following two ways will work around this problem,

1) -fno-aggressive-loop-optimizations (obvious?)
2) change the for loop code from "for (...; i++)" to "for (...; --i)", i.e. the
loop search backwards.

We also found that the code elimination was happening at the "cddce2" stage of
the tree optimization. Here is the command line used with the -v output (with
compiler warnings removed that I believe is irrelevant to this problem to make
the output a little bit cleaner here)

x86_64-peplink-linux-gnu-gcc -D_LARGEFILE_SOURCE=1 -D_LARGE_FILES
-D_FILE_OFFSET_BITS=64 -D_REENTRANT   -DXTABLES_LIBDIR=\"/usr/lib/xtables\"
-DXTABLES_INTERNAL -I../include -I.. -I../include
-I/home/psung/tmp/fw.63.ndpi-test/staging/usr/include
-I/home/psung/tmp/fw.63.ndpi-test/staging/usr/include
-Wp,-MMD,./.libxt_peppi.oo.d,-MT,libxt_peppi.oo -Wall -Waggregate-return
-Wmissing-declarations    -Wmissing-prototypes -Wredundant-decls -Wshadow
-Wstrict-prototypes     -Winline -pipe -D_INIT=libxt_peppi_init -DPIC -fPIC
-Wextra -g -O3 -o libxt_peppi.oo -c libxt_peppi.c -dp -save-temps
-fdump-tree-cddce2-details-stats -fno-strict-aliasing -fwrapv -v
x86_64-peplink-linux-gnu-gcc: warning: -pipe ignored because -save-temps
specified
Using built-in specs.
COLLECT_GCC=x86_64-peplink-linux-gnu-gcc
Target: x86_64-peplink-linux-gnu
Configured with:
/home/psung/toolchains-2015/x64-4.9.3/.build/src/gcc-4.9.3/configure
--build=x86_64-build_unknown-linux-gnu --host=x86_64-build_unknown-linux-gnu
--target=x86_64-peplink-linux-gnu
--prefix=/home/psung/x-tools-2015/x86_64-peplink-linux-gnu
--with-sysroot=/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot
--enable-languages=c,c++,go --with-pkgversion='crosstool-NG
crosstool-ng-1.21.0-50-g488f7a8' --enable-__cxa_atexit --disable-libmudflap
--disable-libgomp --disable-libssp --disable-libquadmath
--disable-libquadmath-support --disable-libsanitizer
--with-gmp=/home/psung/toolchains-2015/x64-4.9.3/.build/x86_64-peplink-linux-gnu/buildtools
--with-mpfr=/home/psung/toolchains-2015/x64-4.9.3/.build/x86_64-peplink-linux-gnu/buildtools
--with-mpc=/home/psung/toolchains-2015/x64-4.9.3/.build/x86_64-peplink-linux-gnu/buildtools
--with-ppl=no --with-isl=no --with-cloog=no
--with-libelf=/home/psung/toolchains-2015/x64-4.9.3/.build/x86_64-peplink-linux-gnu/buildtools
--with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm'
--enable-threads=posix --enable-gold --disable-nls --disable-multilib
--with-local-prefix=/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot
--enable-long-long
Thread model: posix
gcc version 4.9.3 (crosstool-NG crosstool-ng-1.21.0-50-g488f7a8)
COLLECT_GCC_OPTIONS='-D' '_LARGEFILE_SOURCE=1' '-D' '_LARGE_FILES' '-D'
'_FILE_OFFSET_BITS=64' '-D' '_REENTRANT' '-D'
'XTABLES_LIBDIR="/usr/lib/xtables"' '-D' 'XTABLES_INTERNAL' '-I' '../include'
'-I' '..' '-I' '../include' '-I'
'/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-I'
'/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-Wall'
'-Waggregate-return' '-Wmissing-declarations' '-Wmissing-prototypes'
'-Wredundant-decls' '-Wshadow' '-Wstrict-prototypes' '-Winline' '-pipe' '-D'
'_INIT=libxt_peppi_init' '-D' 'PIC' '-fPIC' '-Wextra' '-g' '-O3' '-o'
'libxt_peppi.oo' '-c' '-dp' '-save-temps' '-fdump-tree-cddce2-details-stats'
'-fno-strict-aliasing' '-fwrapv' '-v' '-mtune=generic' '-march=x86-64'

/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/libexec/gcc/x86_64-peplink-linux-gnu/4.9.3/cc1
-E -quiet -v -I ../include -I .. -I ../include -I
/home/psung/tmp/fw.63.ndpi-test/staging/usr/include -I
/home/psung/tmp/fw.63.ndpi-test/staging/usr/include -D _LARGEFILE_SOURCE=1 -D
_LARGE_FILES -D _FILE_OFFSET_BITS=64 -D _REENTRANT -D
XTABLES_LIBDIR="/usr/lib/xtables" -D XTABLES_INTERNAL -D _INIT=libxt_peppi_init
-D PIC -MMD ./.libxt_peppi.oo.d -MT libxt_peppi.oo libxt_peppi.c -mtune=generic
-march=x86-64 -Wall -Waggregate-return -Wmissing-declarations
-Wmissing-prototypes -Wredundant-decls -Wshadow -Wstrict-prototypes -Winline
-Wextra -fPIC -fdump-tree-cddce2-details-stats -fno-strict-aliasing -fwrapv -g
-fworking-directory -O3 -fpch-preprocess -o libxt_peppi.i
ignoring nonexistent directory
"/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot/include"
ignoring duplicate directory "../include"
ignoring duplicate directory
"/home/psung/tmp/fw.63.ndpi-test/staging/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 ../include
 ..
 /home/psung/tmp/fw.63.ndpi-test/staging/usr/include

/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/include

/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/include-fixed

/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/../../../../x86_64-peplink-linux-gnu/include

/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot/usr/include
End of search list.
COLLECT_GCC_OPTIONS='-D' '_LARGEFILE_SOURCE=1' '-D' '_LARGE_FILES' '-D'
'_FILE_OFFSET_BITS=64' '-D' '_REENTRANT' '-D'
'XTABLES_LIBDIR="/usr/lib/xtables"' '-D' 'XTABLES_INTERNAL' '-I' '../include'
'-I' '..' '-I' '../include' '-I'
'/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-I'
'/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-Wall'
'-Waggregate-return' '-Wmissing-declarations' '-Wmissing-prototypes'
'-Wredundant-decls' '-Wshadow' '-Wstrict-prototypes' '-Winline' '-pipe' '-D'
'_INIT=libxt_peppi_init' '-D' 'PIC' '-fPIC' '-Wextra' '-g' '-O3' '-o'
'libxt_peppi.oo' '-c' '-dp' '-save-temps' '-fdump-tree-cddce2-details-stats'
'-fno-strict-aliasing' '-fwrapv' '-v' '-mtune=generic' '-march=x86-64'

/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/libexec/gcc/x86_64-peplink-linux-gnu/4.9.3/cc1
-fpreprocessed libxt_peppi.i -quiet -dumpbase libxt_peppi.c -dp -mtune=generic
-march=x86-64 -auxbase-strip libxt_peppi.oo -g -O3 -Wall -Waggregate-return
-Wmissing-declarations -Wmissing-prototypes -Wredundant-decls -Wshadow
-Wstrict-prototypes -Winline -Wextra -version -fPIC
-fdump-tree-cddce2-details-stats -fno-strict-aliasing -fwrapv -o libxt_peppi.s
GNU C (crosstool-NG crosstool-ng-1.21.0-50-g488f7a8) version 4.9.3
(x86_64-peplink-linux-gnu)
        compiled by GNU C version 4.7.3, GMP version 6.0.0, MPFR version 3.1.2,
MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C (crosstool-NG crosstool-ng-1.21.0-50-g488f7a8) version 4.9.3
(x86_64-peplink-linux-gnu)
        compiled by GNU C version 4.7.3, GMP version 6.0.0, MPFR version 3.1.2,
MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: a9b782f9952f9abb8547d3239b6bb751
                              ^
COLLECT_GCC_OPTIONS='-D' '_LARGEFILE_SOURCE=1' '-D' '_LARGE_FILES' '-D'
'_FILE_OFFSET_BITS=64' '-D' '_REENTRANT' '-D'
'XTABLES_LIBDIR="/usr/lib/xtables"' '-D' 'XTABLES_INTERNAL' '-I' '../include'
'-I' '..' '-I' '../include' '-I'
'/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-I'
'/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-Wall'
'-Waggregate-return' '-Wmissing-declarations' '-Wmissing-prototypes'
'-Wredundant-decls' '-Wshadow' '-Wstrict-prototypes' '-Winline' '-pipe' '-D'
'_INIT=libxt_peppi_init' '-D' 'PIC' '-fPIC' '-Wextra' '-g' '-O3' '-o'
'libxt_peppi.oo' '-c' '-dp' '-save-temps' '-fdump-tree-cddce2-details-stats'
'-fno-strict-aliasing' '-fwrapv' '-v' '-mtune=generic' '-march=x86-64'

/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/../../../../x86_64-peplink-linux-gnu/bin/as
-v -I ../include -I .. -I ../include -I
/home/psung/tmp/fw.63.ndpi-test/staging/usr/include -I
/home/psung/tmp/fw.63.ndpi-test/staging/usr/include --64 -o libxt_peppi.oo
libxt_peppi.s
GNU assembler version 2.24 (x86_64-peplink-linux-gnu) using BFD version
(crosstool-NG crosstool-ng-1.21.0-50-g488f7a8) 2.24
COMPILER_PATH=/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/libexec/gcc/x86_64-peplink-linux-gnu/4.9.3/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/libexec/gcc/x86_64-peplink-linux-gnu/4.9.3/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/libexec/gcc/x86_64-peplink-linux-gnu/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/../../../../x86_64-peplink-linux-gnu/bin/
LIBRARY_PATH=/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/../../../../x86_64-peplink-linux-gnu/lib/../lib64/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot/lib/../lib64/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot/usr/lib/../lib64/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/../../../../x86_64-peplink-linux-gnu/lib/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot/lib/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot/usr/lib/
COLLECT_GCC_OPTIONS='-D' '_LARGEFILE_SOURCE=1' '-D' '_LARGE_FILES' '-D'
'_FILE_OFFSET_BITS=64' '-D' '_REENTRANT' '-D'
'XTABLES_LIBDIR="/usr/lib/xtables"' '-D' 'XTABLES_INTERNAL' '-I' '../include'
'-I' '..' '-I' '../include' '-I'
'/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-I'
'/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-Wall'
'-Waggregate-return' '-Wmissing-declarations' '-Wmissing-prototypes'
'-Wredundant-decls' '-Wshadow' '-Wstrict-prototypes' '-Winline' '-pipe' '-D'
'_INIT=libxt_peppi_init' '-D' 'PIC' '-fPIC' '-Wextra' '-g' '-O3' '-o'
'libxt_peppi.oo' '-c' '-dp' '-save-temps' '-fdump-tree-cddce2-details-stats'
'-fno-strict-aliasing' '-fwrapv' '-v' '-mtune=generic' '-march=x86-64'


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/66875] entire for loop got eliminated at cddce2 tree-opt stage
  2015-07-15  8:23 [Bug tree-optimization/66875] New: entire for loop got eliminated at cddce2 tree-opt stage patricksung at gmail dot com
@ 2015-07-15 10:05 ` rguenth at gcc dot gnu.org
  2015-07-15 10:10 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-07-15 10:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66875

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
I'm just guessing that

  for(i = 1; i <= (188 + 1); i++) {
    if (prot_short_str[i]) {

is accessing prot_short_str out of bounds.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/66875] entire for loop got eliminated at cddce2 tree-opt stage
  2015-07-15  8:23 [Bug tree-optimization/66875] New: entire for loop got eliminated at cddce2 tree-opt stage patricksung at gmail dot com
  2015-07-15 10:05 ` [Bug tree-optimization/66875] " rguenth at gcc dot gnu.org
@ 2015-07-15 10:10 ` mpolacek at gcc dot gnu.org
  2015-07-15 10:19 ` patricksung at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-07-15 10:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66875

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2015-07-15
                 CC|                            |mpolacek at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Yes, please try -fsanitize=undefined.  This looks like an invalid.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/66875] entire for loop got eliminated at cddce2 tree-opt stage
  2015-07-15  8:23 [Bug tree-optimization/66875] New: entire for loop got eliminated at cddce2 tree-opt stage patricksung at gmail dot com
  2015-07-15 10:05 ` [Bug tree-optimization/66875] " rguenth at gcc dot gnu.org
  2015-07-15 10:10 ` mpolacek at gcc dot gnu.org
@ 2015-07-15 10:19 ` patricksung at gmail dot com
  2015-07-15 10:20 ` patricksung at gmail dot com
  2015-07-15 10:23 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: patricksung at gmail dot com @ 2015-07-15 10:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66875

--- Comment #3 from Patrick S. <patricksung at gmail dot com> ---
argh...

my mistake to not check the termination condition is actually matching the size
of the prot_short_str[] array.  fixing that by properly calculating the array
size would fix the compilation now. Thanks!

But one more thing. Since the compiler can see the static size of the array,
wouldn't it be possible to have a warning for possible access of array size out
of bound?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/66875] entire for loop got eliminated at cddce2 tree-opt stage
  2015-07-15  8:23 [Bug tree-optimization/66875] New: entire for loop got eliminated at cddce2 tree-opt stage patricksung at gmail dot com
                   ` (2 preceding siblings ...)
  2015-07-15 10:19 ` patricksung at gmail dot com
@ 2015-07-15 10:20 ` patricksung at gmail dot com
  2015-07-15 10:23 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: patricksung at gmail dot com @ 2015-07-15 10:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66875

--- Comment #4 from Patrick S. <patricksung at gmail dot com> ---
(In reply to Marek Polacek from comment #2)
> Yes, please try -fsanitize=undefined.  This looks like an invalid.

I am guessing this would allow the compiler to detect the loop is undefined and
would generate warning? if in that case no new warning/error was generated.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/66875] entire for loop got eliminated at cddce2 tree-opt stage
  2015-07-15  8:23 [Bug tree-optimization/66875] New: entire for loop got eliminated at cddce2 tree-opt stage patricksung at gmail dot com
                   ` (3 preceding siblings ...)
  2015-07-15 10:20 ` patricksung at gmail dot com
@ 2015-07-15 10:23 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-07-15 10:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66875

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |INVALID

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
You can try -Warray-bounds, but it has its own quirks...

If you compile with -fsanitize=undefined you should get a run-time error when
doing an out-of-bounds access.

Closing.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-07-15 10:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-15  8:23 [Bug tree-optimization/66875] New: entire for loop got eliminated at cddce2 tree-opt stage patricksung at gmail dot com
2015-07-15 10:05 ` [Bug tree-optimization/66875] " rguenth at gcc dot gnu.org
2015-07-15 10:10 ` mpolacek at gcc dot gnu.org
2015-07-15 10:19 ` patricksung at gmail dot com
2015-07-15 10:20 ` patricksung at gmail dot com
2015-07-15 10:23 ` mpolacek at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).