On 02/03/20 13:22 +0100, Christophe Lyon wrote:
On Fri, 28 Feb 2020 at 22:53, Jonathan Wakely <jwak...@redhat.com> wrote:
On 28/02/20 14:59 -0500, Patrick Palka wrote:
>We were enabling the memcmp optimization in ranges::lexicographical_compare for
>signed integral types and for integral types larger than a byte. But memcmp
>gives the wrong answer for arrays of such types. This patch fixes this issue
by
>refining the condition that enables the memcmp optimization. It's now
>consistent with the corresponding condition used in
>std::lexicographical_compare.
>
>libstdc++-v3/ChangeLog:
>
> PR libstdc++/93972
> * include/bits/ranges_algo.h (__lexicographical_compare_fn::operator()):
> Fix condition for when to use memcmp, making it consistent with the
> corresponding condition used in std::lexicographical_compare.
> * testsuite/25_algorithms/lexicographical_compare/93972.cc: New test.
Hi,
The new test fails on aarch64 and arm, and other targets according to
gcc-testresults.
On aarch64, my log says:
FAIL: 25_algorithms/lexicographical_compare/93972.cc (test for excess errors)
Excess errors:
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64-none-linux-gnu/gcc3/aarch64-none-linux-gnu/libstdc++-v3/include/bits/ranges_algo.h:3490:
error: no matching function for call to '__memcmp(char*&, unsigned
char*&, const long int&)'
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64-none-linux-gnu/gcc3/aarch64-none-linux-gnu/libstdc++-v3/include/bits/ranges_algo.h:3490:
error: no matching function for call to '__memcmp(char*&, unsigned
char*&, const long int&)'
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64-none-linux-gnu/gcc3/aarch64-none-linux-gnu/libstdc++-v3/include/bits/ranges_algo.h:3490:
error: no matching function for call to '__memcmp(unsigned char*&,
char*&, const long int&)'
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64-none-linux-gnu/gcc3/aarch64-none-linux-gnu/libstdc++-v3/include/bits/ranges_algo.h:3490:
error: no matching function for call to '__memcmp(unsigned char*&,
char*&, const long int&)'
UNRESOLVED: 25_algorithms/lexicographical_compare/93972.cc compilation
failed to produce executable
Hmm, I think this was already broken in std::lexicographical_compare,
we just didn't have a test for it. I think the following will also
fail to compile on aarch64 and ARM (and any target where char is
unsigned):
#include <algorithm>
#include <assert.h>
int main()
{
unsigned char a[] = {1, 2, 3, 4};
char b[] = {1, 2, 3, 5};
assert( std::lexicographical_compare(a, a+4, b, b+4) );
}
So Patrick's ranges::lexicographical_compare didn't introduce the bug,
it just found it by having better tests.
The std::__memcmp function is broken in a similar way to the
std::__memmove function that I removed last week. I'll fix that
today...