Skip to content

vector_algorithms.cpp: __std_find_trivial_unsized_impl assumes N-byte elements are N-aligned #4454

@StephanTLavavej

Description

@StephanTLavavej

This initially appeared to be x86 /clr specific - but it wasn't, see below.

With #4450 and an MSVC-internal build:

C:\Temp>cl /clr /nologo /W4 /std:c++20 /MDd /Od D:\msvc\src\vctools\crt\github\tests\std\tests\VSO_0000000_vector_algorithms\test.cpp /I D:\msvc\src\vctools\crt\github\tests\std\include
test.cpp

C:\Temp>test
This is a randomized test.
DO NOT IGNORE/RERUN ANY FAILURES.
You must report them to the STL maintainers.

Seed vector: [...]

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at __std_find_trivial_unsized_8(Void* , UInt64 )
   at std.ranges._Find_unchecked<unsigned __int64 *,struct std::unreachable_sentinel_t,unsigned __int64,struct std::identity>(UInt64* _First, unreachable_sentinel_t _Last, UInt64* _Val, identity _Proj)
   at std.ranges._Find_fn.operator()<unsigned __int64 *,struct std::unreachable_sentinel_t,unsigned __int64,struct std::identity>(_Find_fn* , UInt64* _First, unreachable_sentinel_t _Last, UInt64* _Val, identity _Proj)
   at test_gh_4449<unsigned __int64>()
   at test_vector_algorithms(mersenne_twister_engine<unsigned __int64\,64\,312\,156\,31\,-5403634167711393303\,29\,6148914691236517205\,17\,8202884508482404352\,37\,-2270628950310912\,43\,6364136223846793005>* gen)
   at main()
   at _mainCRTStartup()

I can also repro this with plain VS 2022 17.10 Preview 1 x86, if I take #4450's test and alter it to disable the assert(where == arr + mid2), so this doesn't appear to be a regression caused by #4450.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!rangesC++20/23 ranges

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions