public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/10844: Wrong computation on nan initialized vectors.
@ 2003-05-18 17:26 szegedy
  0 siblings, 0 replies; 5+ messages in thread
From: szegedy @ 2003-05-18 17:26 UTC (permalink / raw)
  To: gcc-gnats


>Number:         10844
>Category:       c
>Synopsis:       Wrong computation on nan initialized vectors.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Sun May 18 17:26:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Christian Szegedy
>Release:        gcc (GCC) 3.2.2
>Organization:
>Environment:
gentoo Linux
>Description:
The following program outputs nan istead of 0:

#include <math.h>

int main()
{
   int n = 10;
   int i;
   double *w= (double*)malloc(sizeof(double)*n);
   double x;

   for( i=0 ; i<n ; i++ ) { w[i] = nan(""); }

   w[0] = .0;
   w[0] += .0;

   printf("%lg\n",w[0]);
   
   return 0;
}
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: c/10844: Wrong computation on nan initialized vectors.
@ 2003-05-19 15:06 Christian Szegedy
  0 siblings, 0 replies; 5+ messages in thread
From: Christian Szegedy @ 2003-05-19 15:06 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c/10844; it has been noted by GNATS.

From: Christian Szegedy <szegedy@or.uni-bonn.de>
To: ehrhardt@mathematik.uni-ulm.de, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org,
   nobody@gcc.gnu.org, szegedy@or.uni-bonn.de, gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: c/10844: Wrong computation on nan initialized vectors.
Date: Mon, 19 May 2003 17:00:46 +0200

 ehrhardt@mathematik.uni-ulm.de wrote:
 
 > Hence gcc assumes that the return value of nan is int not double.
 >  
 >
 OK, thanks a lot.
 Stupid mistake on my side. 
 
 Best Regards, Christian
 
 
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: c/10844: Wrong computation on nan initialized vectors.
@ 2003-05-19 12:01 ehrhardt
  0 siblings, 0 replies; 5+ messages in thread
From: ehrhardt @ 2003-05-19 12:01 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, szegedy

Synopsis: Wrong computation on nan initialized vectors.

State-Changed-From-To: feedback->closed
State-Changed-By: cae
State-Changed-When: Mon May 19 12:01:16 2003
State-Changed-Why:
    Oh! I was about to believe you that this is a bug but it is not.
    The nan () function was introduced into math.h with the c99 standard
    but the default used by gcc is the c89 standard. With this standard the
    nan function is #ifdef'ed out intentionally. Hence there is no prototype
    for nan (as -Wall would have told you)! Hence gcc assumes that the
    return value of nan is int not double.
    
    Adding the prototype manually or using the -std=c99 option will make the
    problem go away.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10844


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: c/10844: Wrong computation on nan initialized vectors.
@ 2003-05-19 10:17 Christian Szegedy
  0 siblings, 0 replies; 5+ messages in thread
From: Christian Szegedy @ 2003-05-19 10:17 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c/10844; it has been noted by GNATS.

From: Christian Szegedy <szegedy@or.uni-bonn.de>
To: ehrhardt@mathematik.uni-ulm.de, gcc-bugs@gcc.gnu.org,
   gcc-gnats@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, szegedy@or.uni-bonn.de
Subject: Re: c/10844: Wrong computation on nan initialized vectors.
Date: Mon, 19 May 2003 12:05:19 +0200

 ehrhardt@mathematik.uni-ulm.de wrote:
 
 >Synopsis: Wrong computation on nan initialized vectors.
 >
 >State-Changed-From-To: open->feedback
 >State-Changed-By: cae
 >State-Changed-When: Sun May 18 17:49:33 2003
 >State-Changed-Why:
 >    I can't reproduce this. Could you tell us the compiler options used
 >    to compile the code, the output of gcc -v and the assemble code
 >    generated for the main function? Additionally your libc version might
 >    be of interest here.
 >    
 >        regards  Christian
 >    
 >
 >http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10844
 >
 >  
 >
 I just used "gcc -lm bug.c" to compile the code.
 I am at work, but I can reproduce the bug on my SuSe 8.0 box, with
 
 Reading specs from 
 /home/szegedy/extern/gcc-3.2-install/lib/gcc-lib/i686-pc-linux-gnu/3.2/specs
 Configured with: ../gcc-3.2/configure 
 --prefix=/home/szegedy/extern/gcc-3.2-install
 Thread model: posix
 gcc version 3.2
 
 How can I determine the glibc version?
 
 The bug also occurs with the old 2.95 compiler.
 
 The assembler output is:
 
         .file   "bug.c"
         .section        .rodata
 .LC0:
         .string ""
 .LC2:
         .string "%lg\n"
         .text
         .align 2
 .globl main
         .type   main,@function
 main:
         pushl   %ebp
         movl    %esp, %ebp
         pushl   %esi
         pushl   %ebx
         subl    $32, %esp
         andl    $-16, %esp
         movl    $0, %eax
         subl    %eax, %esp
         movl    $10, -16(%ebp)
         movl    -16(%ebp), %eax
         sall    $3, %eax
         movl    %eax, (%esp)
         call    malloc
         movl    %eax, -20(%ebp)
         movl    $0, -12(%ebp)
 .L2:
         movl    -12(%ebp), %eax
         cmpl    -16(%ebp), %eax
         jl      .L5
         jmp     .L3
 .L5:
         movl    -12(%ebp), %eax
         leal    0(,%eax,8), %esi
         movl    -20(%ebp), %ebx
         movl    $.LC0, (%esp)
         call    nan
         pushl   %eax
         fildl   (%esp)
         leal    4(%esp), %esp
         fstpl   (%ebx,%esi)
         leal    -12(%ebp), %eax
         incl    (%eax)
         jmp     .L2
 .L3:
         movl    -20(%ebp), %eax
         movl    $0, (%eax)
         movl    $0, 4(%eax)
         movl    -20(%ebp), %edx
         movl    -20(%ebp), %eax
         fldl    (%eax)
         fldz
         faddp   %st, %st(1)
         fstpl   (%edx)
         movl    $.LC2, (%esp)
         movl    -20(%ebp), %eax
         movl    4(%eax), %edx
         movl    (%eax), %eax
         movl    %eax, 4(%esp)
         movl    %edx, 8(%esp)
         call    printf
         movl    $0, %eax
         leal    -8(%ebp), %esp
         popl    %ebx
         popl    %esi
         popl    %ebp
         ret
 .Lfe1:
         .size   main,.Lfe1-main
         .ident  "GCC: (GNU) 3.2"
 
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: c/10844: Wrong computation on nan initialized vectors.
@ 2003-05-18 17:49 ehrhardt
  0 siblings, 0 replies; 5+ messages in thread
From: ehrhardt @ 2003-05-18 17:49 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, szegedy

Synopsis: Wrong computation on nan initialized vectors.

State-Changed-From-To: open->feedback
State-Changed-By: cae
State-Changed-When: Sun May 18 17:49:33 2003
State-Changed-Why:
    I can't reproduce this. Could you tell us the compiler options used
    to compile the code, the output of gcc -v and the assemble code
    generated for the main function? Additionally your libc version might
    be of interest here.
    
        regards  Christian
    

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10844


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-05-19 15:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-18 17:26 c/10844: Wrong computation on nan initialized vectors szegedy
2003-05-18 17:49 ehrhardt
2003-05-19 10:17 Christian Szegedy
2003-05-19 12:01 ehrhardt
2003-05-19 15:06 Christian Szegedy

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).