This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gcc 2.95.2 -O0 bug (double/long double)



System:
uname -a: 
Linux astik 2.2.14-SMP #1 SMP Fri Aug 11 15:01:51 CEST 2000 i686 unknown

/etc/SuSE-release:
SuSE Linux 6.4 (i386)
VERSION = 6.4

/proc/cpuinfo:
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 8
model name      : Pentium III (Coppermine)
stepping        : 3
cpu MHz         : 733.098085
cache size      : 256 KB
fdiv_bug        : no
hlt_bug         : no
sep_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 2
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 mmx fxsr xmm
bogomips        : 1461.45

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 8
model name      : Pentium III (Coppermine)
stepping        : 3
cpu MHz         : 733.098085
cache size      : 256 KB
fdiv_bug        : no
hlt_bug         : no
sep_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 2
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 mmx fxsr xmm
bogomips        : 1464.73

gcc -v:
Reading specs from /usr/lib/gcc-lib/i486-suse-linux/2.95.2/specs
gcc version 2.95.2 19991024 (release)

**********************************************************************

Program "dbl_if_test":
#include <stdio.h>

int main()
{
  double x1=1.0,x2=7.0,
    max=x1/x2;

  if (x1/x2<=max) {
    printf("if-cond = 1\n");
  }
  else {
    printf("if-cond = 0\n");
  }

  return 0;
}

I considere this as a bug:

Compilation with -O0: 
> gcc -O0 -o dbl_if_test dbl_if_test.c
> dbl_if_test
if-cond = 0

Compilation with -O1 (or -O2, -O3, ...):
> gcc -O1 -o dbl_if_test dbl_if_test.c
> dbl_if_test
if-cond = 1

> ldd dbl_if_test
        libc.so.6 => /lib/libc.so.6 (0x4001d000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)


I suppose there is problem with double/long double conversion 
(x1/x2 is long double, max is double) since

i)   gcc on a Solaris machine always produces "if-cond = 1"
ii)  gcc version 2.7.2.3 (SuSE 6.1) works fine (always "if-cond = 1")     
iii) if we replace double by long double then we have "if-cond = 1"
iv)  if we use a temporary variable, i.e.   
     .
     .    
     double temp=x1/x2;
     if (temp<=max) {
     .
     .

     then the program returns "if-cond = 1"

with options -O0, -O1, ...

Ciao,

G. Schreib

-- 
Monday is an awful way to spend one seventh of your life.

Gernot Schreib
schreib@fmi.uni-passau.de  http://www.stochastik.uni-passau.de/~schreib

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]