Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aarch64]std::is_permutation function Incorrect input parameter of the same value. #74164

Closed
dongjianqiang2 opened this issue Dec 2, 2023 · 1 comment
Labels
invalid Resolved as invalid, i.e. not a bug libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@dongjianqiang2
Copy link
Contributor

dongjianqiang2 commented Dec 2, 2023

demo.cpp

#include <algorithm>
#include <iostream>


int main (void) {
    bool rv=true;
    {
        std::initializer_list<int> a{1,2,3,4,5},b{5,4,3,2,1}, c{1,2,3,4};
        rv&=std::is_permutation(a.begin(), a.end(), b.begin());
        return std::is_permutation(a.begin(), a.end(), c.begin() );  //supposed to return 0;
    }
}

clang++ demo.cpp -O2
./a.out
echo $?
1

gdb ./a.out

0x0000aaaaaaaaa930 <+76>: ldr q0, [x10, #3520]
0x0000aaaaaaaaa934 <+80>: mov x1, x19
0x0000aaaaaaaaa938 <+84>: str w8, [sp, #32]
0x0000aaaaaaaaa93c <+88>: stp q0, q1, [sp]
0x0000aaaaaaaaa940 <+92>: bl 0xaaaaaaaaa968 <ZSt16__is_permutationIPKiS1_N9__gnu_cxx5__ops19_Iter_equal_to_iterEEbT_S5_T0_T1>
0x0000aaaaaaaaa944 <+96>: sub x0, x29, #0x20
0x0000aaaaaaaaa948 <+100>: mov x2, sp
0x0000aaaaaaaaa94c <+104>: mov x1, x19
=> 0x0000aaaaaaaaa950 <+108>: bl 0xaaaaaaaaa968 <ZSt16__is_permutationIPKiS1_N9__gnu_cxx5__ops19_Iter_equal_to_iterEEbT_S5_T0_T1>
0x0000aaaaaaaaa954 <+112>: and w0, w0, #0x1
0x0000aaaaaaaaa958 <+116>: ldp x29, x30, [sp, #80]
0x0000aaaaaaaaa95c <+120>: ldr x19, [sp, #96]
0x0000aaaaaaaaa960 <+124>: add sp, sp, #0x70
0x0000aaaaaaaaa964 <+128>: ret
End of assembler dump.
(gdb) x /5wx $x0
0xffffffffe940: 0x00000001 0x00000002 0x00000003 0x00000004
0xffffffffe950: 0x00000005
(gdb) x /5wx $x2
0xffffffffe910: 0x00000001 0x00000002 0x00000003 0x00000004
0xffffffffe920: 0x00000005

The same value is saved in the input space (x0 and x2)。
I look into the assemble and find that they may have used the same rodata.

@EugeneZelenko EugeneZelenko added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. and removed new issue labels Dec 2, 2023
@philnik777
Copy link
Contributor

philnik777 commented Dec 2, 2023

Your example has UB because the c range is smaller than the a range. If you want to check for ranges of different lenghts you can use std::is_permutation(a.begin(), a.end(), c.begin(), c.end()).

@philnik777 philnik777 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2023
@philnik777 philnik777 added the invalid Resolved as invalid, i.e. not a bug label Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Resolved as invalid, i.e. not a bug libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

3 participants