This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c/6898: gcc produces incorrect minimization code
- From: Matthias Klose <doko at klose dot in-berlin dot de>
- To: gcc-gnats at gcc dot gnu dot org, debian-gcc at lists dot debian dot org
- Date: Sat, 01 Jun 2002 22:43:49 +0200
- Subject: c/6898: gcc produces incorrect minimization code
- Reply-to: 40189 at bugs dot debian dot org
>Number: 6898
>Category: c
>Synopsis: gcc produces incorrect minimization code
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Sat Jun 01 13:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: camm@enhanced.com
>Release: 3.1 (Debian) (Debian unstable)
>Organization:
The Debian Project
>Environment:
System: Debian GNU/Linux (unstable)
Architecture: i686
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name Version Description
+++-==============-==============-============================================
ii gcc-3.1 3.1-2 The GNU C compiler.
ii binutils 2.12.90.0.7-1 The GNU assembler, linker and binary utiliti
ii libc6 2.2.5-6 GNU C Library: Shared libraries and Timezone
host: i386-linux
configured with: /mnt/data/gcc-3.1/gcc-3.1-3.1ds2/src/configure -v --enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr --mandir=$\(prefix\)/share/man --infodir=$\(prefix\)/share/info --with-gxx-include-dir=$\(prefix\)/include/g++-v3-3.1 --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --enable-clocale=gnu --enable-threads=posix --enable-java-gc=boehm --enable-objc-gc i386-linux
>Description:
[ Reported to the Debian BTS as report #40189.
Please CC 40189@bugs.debian.org on replies.
Log of report can be found at http://bugs.debian.org/40189 ]
The following program inconsistently chooses minimal
array elements in case of equal elements being present.
intech19:~$ gcc -g ttr.c -o ttr
intech19:~$ ./ttr
ir=0
ir=3
On all other optimization levels (-Os, -O1 and up) the "expected"
output is:
intech19:~$ ./ttr
ir=0
ir=0
Here is the code (ttr.c):
------------------------
#include <stdio.h>
#include <float.h>
#include <math.h>
int
main() {
double a[4]={0.006776,2.5,3.0,0.006776},
w[4]={0.000030,3.7,3.0,0.000030},
t,
amin;
int ir, i, nr = 4;
double tol = 9.31322574615479e-10 * 3.0;
for (i=0, ir=-1, amin = DBL_MAX; i < nr; i++)
if (a[i] > tol) {
t = w[i] / a[i];
if (t < amin || ir == -1) {
amin = t;
ir = i;
}
}
printf("ir=%d\n", ir);
for (i = 0, ir = -1, amin = DBL_MAX; i < nr; i++)
if (a[i] > tol && ((t = w[i] / a[i]) < amin || ir == -1)) {
amin = t;
ir = i;
}
printf("ir=%d\n", ir);
return 0;
}
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: