STL icon indicating copy to clipboard operation
STL copied to clipboard

`<concepts>`: `std::swap` for arrays uses `memcpy`

Open AlexGuteniev opened this issue 6 months ago • 4 comments
trafficstars

After #4991 std::swap for arrays uses memcpy. Normally these calls are optimized to inline vectorized operations that don't call anything external (and don't even use stack), but under certain conditions they can be actual memcpy calls.

This contradicts Core Headers intention.

AlexGuteniev avatar May 08 '25 06:05 AlexGuteniev

Apparently, #pragma intrinsic(memcpy) forces the function call not to be inserted, even in /Od. However there's no push/pop and no query of the state.

AlexGuteniev avatar May 08 '25 07:05 AlexGuteniev

DevCom-10900610 may help resolving this.

AlexGuteniev avatar May 08 '25 07:05 AlexGuteniev

When using Clang, it seems that we can use __builtin_memcpy_inline. Not sure whether it's a good idea to request MSVC to add the same intrinsic.

frederick-vs-ja avatar May 08 '25 09:05 frederick-vs-ja

I would say that we're pretty confused about what "core headers" are supposed to be. Originally they were supposed to be free of runtime dependencies (e.g. the core of <type_traits> is compile-time-only and perfectly usable even in kernel mode, despite our general lack of support for exotic modes like that). Later we found it highly convenient to enforce the use of core headers only in the import lib, to keep things like basic_string out of it. But something like memcpy() is a middle ground - it's a runtime dependency, but not usually a problematic one.

StephanTLavavej avatar May 09 '25 08:05 StephanTLavavej