Fix memrchr

Andreas Jaeger aj@suse.de
Mon Jan 6 16:26:00 GMT 2003


Jakub Jelinek <jakub@redhat.com> writes:

> On Mon, Jan 06, 2003 at 04:33:21PM +0100, Andreas Jaeger wrote:
>> 
>> The first memrchr testcase in string/inl-tester failed for me with GCC
>> 3.4.  Looking closer into it, Honza noticed that it is not valid C,
>> the arithmetic is wrong.
>
> Not valid C, but a documented GCC extension (see extend.texi).
> If it doesn't work, it is a GCC bug.

I'm appending the two test programs that I have.  What do you think?
Shall I report this as a GCC bug?

Andreas

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: inl-tester.c
URL: <http://sourceware.org/pipermail/libc-hacker/attachments/20030106/6d179ef8/attachment.c>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fixed-inline.c
URL: <http://sourceware.org/pipermail/libc-hacker/attachments/20030106/6d179ef8/attachment-0001.c>
-------------- next part --------------


>> --- sysdeps/i386/i486/bits/string.h	4 Dec 2002 12:27:43 -0000	1.51
>> +++ sysdeps/i386/i486/bits/string.h	6 Jan 2003 15:10:00 -0000
>> @@ -1,5 +1,5 @@
>>  /* Optimized, inlined string functions.  i486 version.
>> -   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
>> +   Copyright (C) 1997,1998,1999,2000,2001,2002,2003 Free Software Foundation, Inc.
>>     This file is part of the GNU C Library.
>>  
>>     The GNU C Library is free software; you can redistribute it and/or
>> @@ -472,7 +472,7 @@ __memrchr (__const void *__s, int __c, s
>>  # ifdef __i686__
>>    register unsigned long int __d1;
>>  # endif
>> -  register void *__res;
>> +  register int __res;
>>    if (__n == 0)
>>      return NULL;
>>  # ifdef __i686__
>> @@ -497,7 +497,7 @@ __memrchr (__const void *__s, int __c, s
>>         "m" ( *(struct { __extension__ char __x[__n]; } *)__s)
>>       : "cc");
>>  # endif
>> -  return __res + 1;
>> +  return (void *)(__res + 1);
>>  }
>>  # ifdef __USE_GNU
>>  #  define memrchr(s, c, n) __memrchr (s, c, n)
>
> 	Jakub
>

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj


More information about the Libc-hacker mailing list