public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/41649] New: Optimizer makes wrong integer arithmetic assumption
@ 2009-10-09 20:54 enrico dot kravina at gmail dot com
2009-10-09 20:55 ` [Bug c/41649] " pinskia at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: enrico dot kravina at gmail dot com @ 2009-10-09 20:54 UTC (permalink / raw)
To: gcc-bugs
Consider this simple program
int main(){
int a=0;
while (a>=0) a+=1;
}
compiled with this version of gcc: (The bug also manifested in later versions)
:~$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang
--prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext
--enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2
--program-suffix=-4.2
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr
--enable-targets=all
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu4)
Compiling without optimization and with -O2 gives two completely different
results
:~/work/sysprog/perf$ g++ cnt.c -o cnt; time ./cnt
real 0m1.199s
user 0m1.200s
sys 0m0.000s
:~/work/sysprog/perf$ g++ -O2 cnt.c -o cnt && time ./cnt
<DOES NOT HALT!>
Examining the assembly code it is clear why:
Without optimization we get
movl $0, %eax
.L2:
addl $1, %eax
jns .L2
And with O2 we get:
.L2:
jmp .L2
As I understand, a C program working with integers should not change its
semantics depending on the optimization switch. It would have been fine
to remove the loop completely but not to turn it into an infinite loop.
--
Summary: Optimizer makes wrong integer arithmetic assumption
Product: gcc
Version: 4.2.4
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: enrico dot kravina at gmail dot com
GCC build triplet: IA32, Linux, gcc 4.2 (and later)
GCC host triplet: IA32, Linux
GCC target triplet: IA32, Linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41649
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c/41649] Optimizer makes wrong integer arithmetic assumption
2009-10-09 20:54 [Bug c/41649] New: Optimizer makes wrong integer arithmetic assumption enrico dot kravina at gmail dot com
@ 2009-10-09 20:55 ` pinskia at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-10-09 20:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2009-10-09 20:55 -------
Nope, overflow on signed integers is undefined.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
Summary|Optimizer makes wrong |Optimizer makes wrong
|integer arithmetic |integer arithmetic
|assumption |assumption
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41649
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-10-09 20:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-09 20:54 [Bug c/41649] New: Optimizer makes wrong integer arithmetic assumption enrico dot kravina at gmail dot com
2009-10-09 20:55 ` [Bug c/41649] " pinskia at gcc dot gnu dot 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).