This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/58454] Potentially wrong(or at least weird/inconsistent) code generation with -O2 -fno-strict-overflow
- From: "pinskia at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 18 Sep 2013 05:00:27 +0000
- Subject: [Bug c/58454] Potentially wrong(or at least weird/inconsistent) code generation with -O2 -fno-strict-overflow
- Auto-submitted: auto-generated
- References: <bug-58454-4 at http dot gcc dot gnu dot org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58454
--- Comment #1 from pinskia at gmail dot com <pinskia at gmail dot com> ---
All of these functions overflow the loop induction variable so only -fwrapv
will provide the behavior you want for all of the functions. The inconsistent
behavior is due to the overflows happening for induction variables. If it was
not an induction variable then -fno-strict-overflow would have
worked..-fno-strict-overflow is only defined to work for non loop variables.
Thanks,
Andrew
On Sep 17, 2013, at 6:28 PM, "mednafen at gmail dot com"
<gcc-bugzilla@gcc.gnu.org> wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58454
>
> Bug ID: 58454
> Summary: Potentially wrong(or at least weird/inconsistent) code
> generation with -O2 -fno-strict-overflow
> Product: gcc
> Version: 4.8.1
> Status: UNCONFIRMED
> Severity: normal
> Priority: P3
> Component: c
> Assignee: unassigned at gcc dot gnu.org
> Reporter: mednafen at gmail dot com
>
> Created attachment 30844
> --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30844&action=edit
> Testcase program.
>
> Working:
> XXX@willow:~/halt$ /usr/local/gcc-4.8.1/bin/gcc -Wall -O0 -o halt halt.c
> XXX@willow:~/halt$ ./halt
> IMm3: ****
> IMm2: ***
> IMm1: **
> IM: *
>
>
> ????:
> XXX@willow:~/halt$ /usr/local/gcc-4.8.1/bin/gcc -Wall -O2 -o halt halt.c
> XXX@willow:~/halt$ ./halt
> IMm3: ****IMm3: ****IMm3: ****IMm3: ****IMm3: ****IMm3: ****IMm3: ****IMm3:
> ****IMm3: ****IMm3: ****IMm3: ****IMm3: ****IMm3: ****IMm3: ****IMm3: ****IMm3:
> ****IMm3: ****IMm3: ****IMm3: ****IMm3: ****IMm3: ****IMm3: ****IMm3: ****IMm3:
> ****IMm3: ****Aborted
>
>
> Working:
> XXX@willow:~/halt$ /usr/local/gcc-4.8.1/bin/gcc -Wall -O2
> -fno-aggressive-loop-optimizations -o halt halt.c
> XXX@willow:~/halt$ ./halt
> IMm3:
> ****************************************************************************************************Aborted
>
>
> Broken:
> XXX@willow:~/halt$ /usr/local/gcc-4.8.1/bin/gcc -Wall -O2 -fno-strict-overflow
> -o halt halt.c
> XXX@willow:~/halt$ ./halt
> IMm3: ****
> IMm2: ***
> IMm1:
> *********************************************************************************************Aborted
>
>
> Broken:
> XXX@willow:~/halt$ /usr/local/gcc-4.8.1/bin/gcc -Wall -O2
> -fno-aggressive-loop-optimizations -fno-strict-overflow -o halt halt.c
> XXX@willow:~/halt$ ./halt
> IMm3: ****
> IMm2: ***
> IMm1:
> *********************************************************************************************Aborted
>
>
> Working:
> XXX@willow:~/halt$ /usr/local/gcc-4.8.1/bin/gcc -Wall -O2 -fno-strict-overflow
> -fno-tree-vrp -o halt halt.c
> XXX@willow:~/halt$ ./halt
> IMm3: ****
> IMm2: ***
> IMm1: **
> IM: *
>
>
> Working:
> XXX@willow:~/halt$ /usr/local/gcc-4.8.1/bin/gcc -Wall -O2 -fno-strict-overflow
> -fwrapv -o halt halt.c
> XXX@willow:~/halt$ ./halt
> IMm3: ****
> IMm2: ***
> IMm1: **
> IM: *
>
>
> XXX@willow:~/halt$ /usr/local/gcc-4.8.1/bin/gcc -v
> Using built-in specs.
> COLLECT_GCC=/usr/local/gcc-4.8.1/bin/gcc
> COLLECT_LTO_WRAPPER=/usr/local/gcc-4.8.1/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/lto-wrapper
> Target: x86_64-unknown-linux-gnu
> Configured with: ../gcc-4.8.1/configure --prefix=/usr/local/gcc-4.8.1
> Thread model: posix
> gcc version 4.8.1 (GCC)