public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/7857: Different behaviour if compiled with optimization!
@ 2002-09-08 7:46 jcas
0 siblings, 0 replies; 2+ messages in thread
From: jcas @ 2002-09-08 7:46 UTC (permalink / raw)
To: gcc-gnats
>Number: 7857
>Category: c
>Synopsis: Different behaviour if compiled with optimization!
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Sep 08 07:46:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Jose Santos
>Release: 3.10
>Organization:
>Environment:
Windows XP
>Description:
If code is compiled with any optimization (-O1 to -O3) it has a different behaviour than with compiled with no optimizations.
The code is related with precision errors.With optimizations there are no precision errors, without optimization there's a precision error!
>How-To-Repeat:
Just run the file with -O3 and without -O3 and see that in first case it runs fine(requires a couple of seconds, eg: 15s), in second case it enters an infinite loop(and just ends after looping all integers back to 0)
>Fix:
Don't known...perhaps don't use the sqrt function ?
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="bug.c"
Content-Disposition: inline; filename="bug.c"
#include <stdio.h>
#include <math.h>
/*
Compile with -O3 and runs fine
without there's a precision error.
SQ's value has the correct value with -O3 (+1 than without -O3 for n==46611179)
E-mail me at jcas@netcabo.pt
*/
#define NUMPAIRS 10
int main(){
long long n=2, count = 0;
for(n=2; count<NUMPAIRS; n++){
long long n2 =n*n;
//double sq = sqrt(1+8.0*n2);
long long sq = sqrt(1+8*n2);
long long k = -(1 - sq)/2;
long long k2 = k*k;
if(n==46611179)
printf("%lld, %lld\n", sq, k);
if(2*n2==k2+k){
printf("%10lld %10lld\n", n, k);
count++;
}
}
return 0;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: c/7857: Different behaviour if compiled with optimization!
@ 2002-10-09 10:16 Pop Sébastian
0 siblings, 0 replies; 2+ messages in thread
From: Pop Sébastian @ 2002-10-09 10:16 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c/7857; it has been noted by GNATS.
From: =?iso-8859-1?Q?Pop_S=E9bastian?= <pop@gauvain.u-strasbg.fr>
To: jcas@netcabo.pt
Cc: gcc-gnats@gcc.gnu.org, austern@apple.com
Subject: Re: c/7857: Different behaviour if compiled with optimization!
Date: Wed, 9 Oct 2002 19:15:06 +0200
On Sun, Sep 08, 2002 at 02:36:46PM -0000, jcas@netcabo.pt wrote:
> /*
> Compile with -O3 and runs fine
> without there's a precision error.
> SQ's value has the correct value with -O3 (+1 than without -O3 for n==46611179)
>
Reproduced with
gcc version 2.95.4 20011002 (Debian prerelease)
version gcc 3.3 20021007 (experimental)
Compiling the bug report without -O3 gives an error: "Undefined reference to 'sqrt'".
For completing the link we have to specify the -lm.
Thus with no optimization, the 'sqrt' function is the one defined in the math library,
whereas with -O3 the 'sqrt' function is the one defined by GCC... (I think)
I hope that this helps,
Sebastian.
pop@gauvain:~/gcc/main/test$ ../usr/bin/gcc -o pr7857 ./pr7857.c -O3
pop@gauvain:~/gcc/main/test$ ../usr/bin/gcc -o pr7857 ./pr7857.c
/tmp/emacs-09607/cc4vzVim.o: dans la fonction `main':
/tmp/emacs-09607/cc4vzVim.o(.text+0xaf): r\351f\351rence ind\351finie vers `sqrt'
collect2: ld a retourn\351 1 code d'\351tat d'ex\351cution
pop@gauvain:~/gcc/main/test$ ../usr/bin/gcc -o pr7857 ./pr7857.c -lm
pop@gauvain:~/gcc/main/test$
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-10-09 17:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-08 7:46 c/7857: Different behaviour if compiled with optimization! jcas
2002-10-09 10:16 Pop Sébastian
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).