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]
Other format: [Raw text]

[Bug c/40757] gcc 4.4.0 miscompiles mpfr-2.4.1



------- Comment #23 from david dot kirkby at onetel dot net  2009-07-18 14:36 -------
(In reply to comment #22)
> (In reply to comment #20)
> >     buf[n] = 6;
> >     memset (buf+n, 0, i + j);
> >     if (buf[0] != 6)
> 
> It looks like you forgot to replace the second buf[0] by buf[n].
> 

Sorry, my mistake. This is the current code and it does show something
intersting. 

drkirkby@kestrel:[~] $ cat check2.c
#include <stdio.h>
typedef __SIZE_TYPE__ size_t;
extern void *memset (void *, const void *, size_t);
extern void abort (void);
volatile size_t i = 0x80000000U, j = 0x80000000U;
char buf[16];

int main (void)
{
  int n;

  for (n=0 ; n <=10;++n) {
    printf("n=%d\n",n);
    if (sizeof (size_t) != 4)
      return 0;
    buf[n] = 6;
    memset (buf+n, 0, i + j);
    if (buf[n] != 6)
      abort ();
  }
  return 0;
}

On the machine with the T2+ processor, which fails the mpfr tests:

kirkby@t2:[~] $ gcc -Wall check2.c
check2.c: In function 'main':
check2.c:17: warning: null argument where non-null required (argument 2)
kirkby@t2:[~] $ ./a.out
n=0
n=1
Abort (core dumped)

I tried with the Sun compiler too, but that refuses to compile the code. 

kirkby@t2:[~] $ /opt/SUNWspro/bin/cc check2.c
"check2.c", line 2: warning: no explicit type given
"check2.c", line 2: syntax error before or at: size_t
"check2.c", line 2: warning: useless declaration
cc: acomp failed for check2.c


However, when I went back and took away all the loop stuff and dropped it to
the bare minimum. 

kirkby@t2:[~] $ cat check3.c
typedef __SIZE_TYPE__ size_t;
extern void *memset (void *, const void *, size_t);
extern void abort (void);
volatile size_t i = 0x80000000U, j = 0x80000000U;
char buf[16];

int main (void)
{
  if (sizeof (size_t) != 4)
    return 0;
  buf[1] = 6;
  memset (buf+1, 0, i + j);
  if (buf[1] != 6)
    abort ();
  return 0;
}

then it does not dump core. 

kirkby@t2:[~] $ gcc check3.c
kirkby@t2:[~] $ ./a.out
kirkby@t2:[~] $

In fact, trying a few small values manually, without the loop, causes no
problem. 


I also tried it on my own personal machine, a Sun Blade 2000 with the sun4u
architecture (unlike the T5240 with it's T2+ processors, which is sun4v). 

drkirkby@kestrel:[~] $ ./a.out
n=0
n=1
n=2
n=3
n=4
n=5
n=6
n=7
n=8
n=9
n=10


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40757


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