Suppress -Wcast-qual warnings in bsearch

Message ID YKUdWuzFbiAnWx+Y@redhat.com
State Superseded
Headers
Series Suppress -Wcast-qual warnings in bsearch |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Jonathan Wakely May 19, 2021, 2:14 p.m. UTC
  This fixes these GCC warnings when -Wsystem-headers is used:

/usr/include/bits/stdlib-bsearch.h: In function ‘bsearch’:
/usr/include/bits/stdlib-bsearch.h:32:13: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
    32 |       __p = (void *) (((const char *) __base) + (__idx * __size));
       |             ^
/usr/include/bits/stdlib-bsearch.h:39:16: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
    39 |         return (void *) __p;
       |                ^

OK to push?
commit 2e988862a07b75b433468cfd591a8acb1ab4f0af
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed May 19 14:58:50 2021 +0100

    Suppress -Wcast-qual warnings in bsearch
    
    The first cast to (void *) is redundant but should be (const void *)
    anyway, because that's the type of the lvalue being assigned to.
    
    The second cast is necessary and intentionally not const-correct, so
    tell the compiler not to warn about it.
  

Comments

Joseph Myers May 19, 2021, 3:37 p.m. UTC | #1
On Wed, 19 May 2021, Jonathan Wakely via Libc-alpha wrote:

> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wcast-qual"
>  	return (void *) __p;
> +#pragma GCC diagnostic pop

I think such pragma uses in installed headers should be conditional on 
__GNUC_PREREQ (4, 6) (either directly or via conditionally defining a 
macro in sys/cdefs.h).
  
Jonathan Wakely May 19, 2021, 3:50 p.m. UTC | #2
On 19/05/21 15:37 +0000, Joseph Myers wrote:
>On Wed, 19 May 2021, Jonathan Wakely via Libc-alpha wrote:
>
>> +#pragma GCC diagnostic push
>> +#pragma GCC diagnostic ignored "-Wcast-qual"
>>  	return (void *) __p;
>> +#pragma GCC diagnostic pop
>
>I think such pragma uses in installed headers should be conditional on
>__GNUC_PREREQ (4, 6) (either directly or via conditionally defining a
>macro in sys/cdefs.h).

Good point.

I spent about two minutes trying to do something with _Pragma in
sys/cdefs.h to allow:

__GLIBC_IGNORE_WARNING("-Wcast-qual")
   return (void *) __p;
__GLIBC_UNIGNORE_WARNING

but didn't get it working, so here's a patch that just tests
__GNUC_PREREQ directly.
commit ee7c2451a102b4cd3c87a31b3156ad4458729840
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed May 19 16:48:19 2021 +0100

    Suppress -Wcast-qual warnings in bsearch
    
    The first cast to (void *) is redundant but should be (const void *)
    anyway, because that's the type of the lvalue being assigned to.
    
    The second cast is necessary and intentionally not const-correct, so
    tell the compiler not to warn about it.

diff --git a/bits/stdlib-bsearch.h b/bits/stdlib-bsearch.h
index 4132dc6af0..d688ed2e15 100644
--- a/bits/stdlib-bsearch.h
+++ b/bits/stdlib-bsearch.h
@@ -29,14 +29,21 @@ bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size,
   while (__l < __u)
     {
       __idx = (__l + __u) / 2;
-      __p = (void *) (((const char *) __base) + (__idx * __size));
+      __p = (const void *) (((const char *) __base) + (__idx * __size));
       __comparison = (*__compar) (__key, __p);
       if (__comparison < 0)
 	__u = __idx;
       else if (__comparison > 0)
 	__l = __idx + 1;
       else
+#if __GNUC_PREREQ(4, 6)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wcast-qual"
+#endif
 	return (void *) __p;
+#if __GNUC_PREREQ(4, 6)
+# pragma GCC diagnostic pop
+#endif
     }
 
   return NULL;
  
Jonathan Wakely Sept. 30, 2021, 9:22 a.m. UTC | #3
Ping for patch originally sent in
https://sourceware.org/pipermail/libc-alpha/2021-May/126572.html

The patch still applies cleanly to current master.


On Wed, 19 May 2021 at 16:50, Jonathan Wakely wrote:
>
> On 19/05/21 15:37 +0000, Joseph Myers wrote:
> >On Wed, 19 May 2021, Jonathan Wakely via Libc-alpha wrote:
> >
> >> +#pragma GCC diagnostic push
> >> +#pragma GCC diagnostic ignored "-Wcast-qual"
> >>      return (void *) __p;
> >> +#pragma GCC diagnostic pop
> >
> >I think such pragma uses in installed headers should be conditional on
> >__GNUC_PREREQ (4, 6) (either directly or via conditionally defining a
> >macro in sys/cdefs.h).
>
> Good point.
>
> I spent about two minutes trying to do something with _Pragma in
> sys/cdefs.h to allow:
>
> __GLIBC_IGNORE_WARNING("-Wcast-qual")
>    return (void *) __p;
> __GLIBC_UNIGNORE_WARNING
>
> but didn't get it working, so here's a patch that just tests
> __GNUC_PREREQ directly.
>
>
  
Florian Weimer Sept. 30, 2021, 10:43 a.m. UTC | #4
* Jonathan Wakely via Libc-alpha:

> diff --git a/bits/stdlib-bsearch.h b/bits/stdlib-bsearch.h
> index 4132dc6af0..d688ed2e15 100644
> --- a/bits/stdlib-bsearch.h
> +++ b/bits/stdlib-bsearch.h
> @@ -29,14 +29,21 @@ bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size,
>    while (__l < __u)
>      {
>        __idx = (__l + __u) / 2;
> -      __p = (void *) (((const char *) __base) + (__idx * __size));
> +      __p = (const void *) (((const char *) __base) + (__idx * __size));
>        __comparison = (*__compar) (__key, __p);
>        if (__comparison < 0)
>  	__u = __idx;
>        else if (__comparison > 0)
>  	__l = __idx + 1;
>        else
> +#if __GNUC_PREREQ(4, 6)
> +# pragma GCC diagnostic push
> +# pragma GCC diagnostic ignored "-Wcast-qual"
> +#endif
>  	return (void *) __p;
> +#if __GNUC_PREREQ(4, 6)
> +# pragma GCC diagnostic pop
> +#endif
>      }
>  
>    return NULL;

Patch looks okay, thanks.

Reviewed-by: Florian Weimer <fweimer@redhat.com>

Florian
  
Adhemerval Zanella Netto Sept. 30, 2021, 2:49 p.m. UTC | #5
On 30/09/2021 07:43, Florian Weimer via Libc-alpha wrote:
> * Jonathan Wakely via Libc-alpha:
> 
>> diff --git a/bits/stdlib-bsearch.h b/bits/stdlib-bsearch.h
>> index 4132dc6af0..d688ed2e15 100644
>> --- a/bits/stdlib-bsearch.h
>> +++ b/bits/stdlib-bsearch.h
>> @@ -29,14 +29,21 @@ bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size,
>>    while (__l < __u)
>>      {
>>        __idx = (__l + __u) / 2;
>> -      __p = (void *) (((const char *) __base) + (__idx * __size));
>> +      __p = (const void *) (((const char *) __base) + (__idx * __size));
>>        __comparison = (*__compar) (__key, __p);
>>        if (__comparison < 0)
>>  	__u = __idx;
>>        else if (__comparison > 0)
>>  	__l = __idx + 1;
>>        else
>> +#if __GNUC_PREREQ(4, 6)
>> +# pragma GCC diagnostic push
>> +# pragma GCC diagnostic ignored "-Wcast-qual"
>> +#endif
>>  	return (void *) __p;
>> +#if __GNUC_PREREQ(4, 6)
>> +# pragma GCC diagnostic pop
>> +#endif
>>      }
>>  
>>    return NULL;
> 
> Patch looks okay, thanks.
> 
> Reviewed-by: Florian Weimer <fweimer@redhat.com>
> 
> Florian
> 

I am seeing a lot of failure on x86_64 with gcc 11.1 after this
patch landed:

x86_64-linux-gnu$ grep ^FAIL tests.sum
FAIL: catgets/de/libc.cat
FAIL: catgets/test-gencat
FAIL: catgets/test1.cat
FAIL: catgets/tst-catgets
FAIL: debug/tst-chk1
FAIL: debug/tst-chk2
FAIL: debug/tst-chk3
FAIL: debug/tst-chk4
FAIL: debug/tst-chk5
FAIL: debug/tst-chk6
FAIL: debug/tst-lfschk1
FAIL: debug/tst-lfschk2
FAIL: debug/tst-lfschk3
FAIL: debug/tst-lfschk4
FAIL: debug/tst-lfschk5
FAIL: debug/tst-lfschk6
[...]

For instance some math tests shows ulps failures that does not
make much sense:

$ ./testrun.sh math/test-double-cacos
testing double (without inline functions)
Failure: Test: Imaginary part of: cacos_downward (-0x1p-52 - 0x1.0000000000001p+0 i)
Result:
 is:          8.8137358701954271e-01   0x1.c34366179d424p-1
 should be:   8.8137358701954315e-01   0x1.c34366179d428p-1
 difference:  4.4408920985006261e-16   0x1.0000000000000p-51
 ulp       :  4.0000
 max.ulp   :  3.0000
Failure: Test: Imaginary part of: cacos_downward (-0x1p-52 - 0x1.000002p+0 i)
Result:
 is:          8.8137367131323707e-01   0x1.c34368ebb10d9p-1
 should be:   8.8137367131323751e-01   0x1.c34368ebb10ddp-1
 difference:  4.4408920985006261e-16   0x1.0000000000000p-51
 ulp       :  4.0000
 max.ulp   :  3.0000
[...]

Reverting fixes it.
  
Joseph Myers Sept. 30, 2021, 3:07 p.m. UTC | #6
On Thu, 30 Sep 2021, Adhemerval Zanella via Libc-alpha wrote:

> >>        else
> >> +#if __GNUC_PREREQ(4, 6)
> >> +# pragma GCC diagnostic push
> >> +# pragma GCC diagnostic ignored "-Wcast-qual"
> >> +#endif
> >>  	return (void *) __p;
> >> +#if __GNUC_PREREQ(4, 6)
> >> +# pragma GCC diagnostic pop
> >> +#endif
> >>      }

I think braces may need adding around those pragmas to avoid a pragma 
being considered the body of the else in some cases.

> For instance some math tests shows ulps failures that does not
> make much sense:

libm-test-support.c does use bsearch (in order to look up ulps by name in 
a table).
  
Adhemerval Zanella Netto Sept. 30, 2021, 3:19 p.m. UTC | #7
On 30/09/2021 12:07, Joseph Myers wrote:
> On Thu, 30 Sep 2021, Adhemerval Zanella via Libc-alpha wrote:
> 
>>>>        else
>>>> +#if __GNUC_PREREQ(4, 6)
>>>> +# pragma GCC diagnostic push
>>>> +# pragma GCC diagnostic ignored "-Wcast-qual"
>>>> +#endif
>>>>  	return (void *) __p;
>>>> +#if __GNUC_PREREQ(4, 6)
>>>> +# pragma GCC diagnostic pop
>>>> +#endif
>>>>      }
> 
> I think braces may need adding around those pragmas to avoid a pragma 
> being considered the body of the else in some cases.

But how exactly the pragma is changing the code semantic in this case?
Would it be safe for all supported gcc (since it is an installed header)?

I wonder if you would be better to follow what we did for inline string
micro-optimizations and just remove this header.

> 
>> For instance some math tests shows ulps failures that does not
>> make much sense:
> 
> libm-test-support.c does use bsearch (in order to look up ulps by name in 
> a table).
>
  
Andreas Schwab Sept. 30, 2021, 3:30 p.m. UTC | #8
On Sep 30 2021, Adhemerval Zanella via Libc-alpha wrote:

> I wonder if you would be better to follow what we did for inline string
> micro-optimizations and just remove this header.

See https://sourceware.org/pipermail/libc-alpha/2013-January/037308.html
for the motivation.

Andreas.
  
Florian Weimer Sept. 30, 2021, 4:41 p.m. UTC | #9
* Adhemerval Zanella via Libc-alpha:

> On 30/09/2021 12:07, Joseph Myers wrote:
>> On Thu, 30 Sep 2021, Adhemerval Zanella via Libc-alpha wrote:
>> 
>>>>>        else
>>>>> +#if __GNUC_PREREQ(4, 6)
>>>>> +# pragma GCC diagnostic push
>>>>> +# pragma GCC diagnostic ignored "-Wcast-qual"
>>>>> +#endif
>>>>>  	return (void *) __p;
>>>>> +#if __GNUC_PREREQ(4, 6)
>>>>> +# pragma GCC diagnostic pop
>>>>> +#endif
>>>>>      }
>> 
>> I think braces may need adding around those pragmas to avoid a pragma 
>> being considered the body of the else in some cases.
>
> But how exactly the pragma is changing the code semantic in this case?
> Would it be safe for all supported gcc (since it is an installed header)?

It's parsed as:

  while (__l < __u)
    {
      __idx = (__l + __u) / 2;
      __p = (const void *) (((const char *) __base) + (__idx * __size));
      __comparison = (*__compar) (__key, __p);
      if (__comparison < 0)
        __u = __idx;
      else if (__comparison > 0)
        __l = __idx + 1;
      else
#if __GNUC_PREREQ(4, 6)
          # pragma GCC diagnostic push
      # pragma GCC diagnostic ignored "-Wcast-qual"
#endif
      return (void *) __p;
#if __GNUC_PREREQ(4, 6)
      # pragma GCC diagnostic pop
#endif
    }

See

  (GCC-pragma) - whether a #pragma is a statement depends on the type of pra
  <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63326>

and:

  -Wmisleading-indentation should also detect missing indentation 
  <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66298#c3>

Sorry, I should have caught this during review (and actually tested the
patch).

Joseph is right, we need braces here.

Thanks,
Florian
  
Joseph Myers Sept. 30, 2021, 4:42 p.m. UTC | #10
On Thu, 30 Sep 2021, Adhemerval Zanella via Libc-alpha wrote:

> On 30/09/2021 12:07, Joseph Myers wrote:
> > On Thu, 30 Sep 2021, Adhemerval Zanella via Libc-alpha wrote:
> > 
> >>>>        else
> >>>> +#if __GNUC_PREREQ(4, 6)
> >>>> +# pragma GCC diagnostic push
> >>>> +# pragma GCC diagnostic ignored "-Wcast-qual"
> >>>> +#endif
> >>>>  	return (void *) __p;
> >>>> +#if __GNUC_PREREQ(4, 6)
> >>>> +# pragma GCC diagnostic pop
> >>>> +#endif
> >>>>      }
> > 
> > I think braces may need adding around those pragmas to avoid a pragma 
> > being considered the body of the else in some cases.
> 
> But how exactly the pragma is changing the code semantic in this case?

The effect, when the #pragma is treated as a statement by the C parser, is 
that the prior cases of the "if" fall through to the "return", which 
becomes unconditional, when otherwise they would not have returned.

> Would it be safe for all supported gcc (since it is an installed header)?

The #if conditionals are still needed.  It's just that braces should be 
added before the first #if and after the last #endif, to avoid a single 
#pragma being considered as the else body (see GCC bug 41517 and other 
bugs related to #pragma parsing).
  
Jonathan Wakely Sept. 30, 2021, 4:52 p.m. UTC | #11
On Thu, 30 Sept 2021 at 15:49, Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 30/09/2021 07:43, Florian Weimer via Libc-alpha wrote:
> > * Jonathan Wakely via Libc-alpha:
> >
> >> diff --git a/bits/stdlib-bsearch.h b/bits/stdlib-bsearch.h
> >> index 4132dc6af0..d688ed2e15 100644
> >> --- a/bits/stdlib-bsearch.h
> >> +++ b/bits/stdlib-bsearch.h
> >> @@ -29,14 +29,21 @@ bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size,
> >>    while (__l < __u)
> >>      {
> >>        __idx = (__l + __u) / 2;
> >> -      __p = (void *) (((const char *) __base) + (__idx * __size));
> >> +      __p = (const void *) (((const char *) __base) + (__idx * __size));
> >>        __comparison = (*__compar) (__key, __p);
> >>        if (__comparison < 0)
> >>      __u = __idx;
> >>        else if (__comparison > 0)
> >>      __l = __idx + 1;
> >>        else
> >> +#if __GNUC_PREREQ(4, 6)
> >> +# pragma GCC diagnostic push
> >> +# pragma GCC diagnostic ignored "-Wcast-qual"
> >> +#endif
> >>      return (void *) __p;
> >> +#if __GNUC_PREREQ(4, 6)
> >> +# pragma GCC diagnostic pop
> >> +#endif
> >>      }
> >>
> >>    return NULL;
> >
> > Patch looks okay, thanks.
> >
> > Reviewed-by: Florian Weimer <fweimer@redhat.com>
> >
> > Florian
> >
>
> I am seeing a lot of failure on x86_64 with gcc 11.1 after this
> patch landed:
>
> x86_64-linux-gnu$ grep ^FAIL tests.sum
> FAIL: catgets/de/libc.cat
> FAIL: catgets/test-gencat
> FAIL: catgets/test1.cat
> FAIL: catgets/tst-catgets
> FAIL: debug/tst-chk1
> FAIL: debug/tst-chk2
> FAIL: debug/tst-chk3
> FAIL: debug/tst-chk4
> FAIL: debug/tst-chk5
> FAIL: debug/tst-chk6
> FAIL: debug/tst-lfschk1
> FAIL: debug/tst-lfschk2
> FAIL: debug/tst-lfschk3
> FAIL: debug/tst-lfschk4
> FAIL: debug/tst-lfschk5
> FAIL: debug/tst-lfschk6
> [...]
>
> For instance some math tests shows ulps failures that does not
> make much sense:
>
> $ ./testrun.sh math/test-double-cacos
> testing double (without inline functions)
> Failure: Test: Imaginary part of: cacos_downward (-0x1p-52 - 0x1.0000000000001p+0 i)
> Result:
>  is:          8.8137358701954271e-01   0x1.c34366179d424p-1
>  should be:   8.8137358701954315e-01   0x1.c34366179d428p-1
>  difference:  4.4408920985006261e-16   0x1.0000000000000p-51
>  ulp       :  4.0000
>  max.ulp   :  3.0000
> Failure: Test: Imaginary part of: cacos_downward (-0x1p-52 - 0x1.000002p+0 i)
> Result:
>  is:          8.8137367131323707e-01   0x1.c34368ebb10d9p-1
>  should be:   8.8137367131323751e-01   0x1.c34368ebb10ddp-1
>  difference:  4.4408920985006261e-16   0x1.0000000000000p-51
>  ulp       :  4.0000
>  max.ulp   :  3.0000
> [...]
>
> Reverting fixes it.

Huh, I wonder why I didn't see these. Sorry. I'll see if Joseph's
suggestion helps (as attached) or I'll revert it.
commit f1763cd2d3b77582309288198e56de5d883b425a
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Sep 30 17:24:54 2021 +0100

    stdlib: Add braces around return statement in bsearch
    
    The diagnostic pragmas are apparently interpreted as the statement
    following the else, so add braces around them to create a block
    statement containing the pragmas and the return statement.
    
    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

diff --git a/bits/stdlib-bsearch.h b/bits/stdlib-bsearch.h
index d688ed2e15..c4b485edf8 100644
--- a/bits/stdlib-bsearch.h
+++ b/bits/stdlib-bsearch.h
@@ -36,14 +36,16 @@ bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size,
       else if (__comparison > 0)
 	__l = __idx + 1;
       else
+        {
 #if __GNUC_PREREQ(4, 6)
 # pragma GCC diagnostic push
 # pragma GCC diagnostic ignored "-Wcast-qual"
 #endif
-	return (void *) __p;
+          return (void *) __p;
 #if __GNUC_PREREQ(4, 6)
 # pragma GCC diagnostic pop
 #endif
+        }
     }
 
   return NULL;
  
H.J. Lu Sept. 30, 2021, 5:54 p.m. UTC | #12
On Thu, Sep 30, 2021 at 7:49 AM Adhemerval Zanella via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
>
>
> On 30/09/2021 07:43, Florian Weimer via Libc-alpha wrote:
> > * Jonathan Wakely via Libc-alpha:
> >
> >> diff --git a/bits/stdlib-bsearch.h b/bits/stdlib-bsearch.h
> >> index 4132dc6af0..d688ed2e15 100644
> >> --- a/bits/stdlib-bsearch.h
> >> +++ b/bits/stdlib-bsearch.h
> >> @@ -29,14 +29,21 @@ bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size,
> >>    while (__l < __u)
> >>      {
> >>        __idx = (__l + __u) / 2;
> >> -      __p = (void *) (((const char *) __base) + (__idx * __size));
> >> +      __p = (const void *) (((const char *) __base) + (__idx * __size));
> >>        __comparison = (*__compar) (__key, __p);
> >>        if (__comparison < 0)
> >>      __u = __idx;
> >>        else if (__comparison > 0)
> >>      __l = __idx + 1;
> >>        else
> >> +#if __GNUC_PREREQ(4, 6)
> >> +# pragma GCC diagnostic push
> >> +# pragma GCC diagnostic ignored "-Wcast-qual"
> >> +#endif
> >>      return (void *) __p;
> >> +#if __GNUC_PREREQ(4, 6)
> >> +# pragma GCC diagnostic pop
> >> +#endif
> >>      }
> >>
> >>    return NULL;
> >
> > Patch looks okay, thanks.
> >
> > Reviewed-by: Florian Weimer <fweimer@redhat.com>
> >
> > Florian
> >
>
> I am seeing a lot of failure on x86_64 with gcc 11.1 after this
> patch landed:
>
> x86_64-linux-gnu$ grep ^FAIL tests.sum
> FAIL: catgets/de/libc.cat
> FAIL: catgets/test-gencat
> FAIL: catgets/test1.cat
> FAIL: catgets/tst-catgets
> FAIL: debug/tst-chk1
> FAIL: debug/tst-chk2
> FAIL: debug/tst-chk3
> FAIL: debug/tst-chk4
> FAIL: debug/tst-chk5
> FAIL: debug/tst-chk6
> FAIL: debug/tst-lfschk1
> FAIL: debug/tst-lfschk2
> FAIL: debug/tst-lfschk3
> FAIL: debug/tst-lfschk4
> FAIL: debug/tst-lfschk5
> FAIL: debug/tst-lfschk6
> [...]
>
> For instance some math tests shows ulps failures that does not
> make much sense:
>
> $ ./testrun.sh math/test-double-cacos
> testing double (without inline functions)
> Failure: Test: Imaginary part of: cacos_downward (-0x1p-52 - 0x1.0000000000001p+0 i)
> Result:
>  is:          8.8137358701954271e-01   0x1.c34366179d424p-1
>  should be:   8.8137358701954315e-01   0x1.c34366179d428p-1
>  difference:  4.4408920985006261e-16   0x1.0000000000000p-51
>  ulp       :  4.0000
>  max.ulp   :  3.0000
> Failure: Test: Imaginary part of: cacos_downward (-0x1p-52 - 0x1.000002p+0 i)
> Result:
>  is:          8.8137367131323707e-01   0x1.c34368ebb10d9p-1
>  should be:   8.8137367131323751e-01   0x1.c34368ebb10ddp-1
>  difference:  4.4408920985006261e-16   0x1.0000000000000p-51
>  ulp       :  4.0000
>  max.ulp   :  3.0000
> [...]
>
> Reverting fixes it.

I opened:

https://sourceware.org/bugzilla/show_bug.cgi?id=28400

I think the patch should be reverted.
  
Florian Weimer Sept. 30, 2021, 6:04 p.m. UTC | #13
* H. J. Lu via Libc-alpha:

> I opened:
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=28400
>
> I think the patch should be reverted.

Both Jonathan and I have posted the same fix (with a tabs-vs-spaces)
difference.  One needs to be reviewed.  I can push my variant if someone
acks it.

Thanks,
Florian
  
H.J. Lu Sept. 30, 2021, 6:09 p.m. UTC | #14
On Thu, Sep 30, 2021 at 11:04 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu via Libc-alpha:
>
> > I opened:
> >
> > https://sourceware.org/bugzilla/show_bug.cgi?id=28400
> >
> > I think the patch should be reverted.
>
> Both Jonathan and I have posted the same fix (with a tabs-vs-spaces)
> difference.  One needs to be reviewed.  I can push my variant if someone
> acks it.
>

Please repost your patch with BZ #28400.

Thanks.
  

Patch

diff --git a/bits/stdlib-bsearch.h b/bits/stdlib-bsearch.h
index 4132dc6af0..a08ad34ed6 100644
--- a/bits/stdlib-bsearch.h
+++ b/bits/stdlib-bsearch.h
@@ -29,14 +29,17 @@  bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size,
   while (__l < __u)
     {
       __idx = (__l + __u) / 2;
-      __p = (void *) (((const char *) __base) + (__idx * __size));
+      __p = (const void *) (((const char *) __base) + (__idx * __size));
       __comparison = (*__compar) (__key, __p);
       if (__comparison < 0)
 	__u = __idx;
       else if (__comparison > 0)
 	__l = __idx + 1;
       else
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-qual"
 	return (void *) __p;
+#pragma GCC diagnostic pop
     }
 
   return NULL;