Информация об изменениях

Сообщение Re[8]: Приведение базового класса в конструкторе потомка от 04.09.2019 11:41

Изменено 04.09.2019 11:45 Mystic Artifact

Re[8]: Приведение базового класса в конструкторе потомка
Здравствуйте, Евгений Музыченко, Вы писали:

MA>> Как бы я не извращался — результат в rax. На clang тоже в rax.

ЕМ>А это уже странно. Они ж должны быть совместимы по ABI.
Что-то вчера был не мой день видимо.

В моём примере: msvc x64 v19.22 для method и virtual_method возвращается адрес на структуру, для static_method возвращается сама структура по значению.
А вот clang 8.0 — в обоих случаях возвращает структуру по значению (через регистр). С -O1 тела методов вообще идентичны.

Насчет должны быть совместимы по ABI — то, афаик, windows abi отличается от amd64 abi.

Вроде как похоже, что поведение вполне соответствует документации Calling Conventions: Return Values.

A scalar return value that can fit into 64 bits is returned through RAX; this includes __m64 types. Non-scalar types including floats, doubles, and vector types such as __m128, __m128i, __m128d are returned in XMM0. The state of unused bits in the value returned in RAX or XMM0 is undefined.

User-defined types can be returned by value from global functions and static member functions. To return a user-defined type by value in RAX, it must have a length of 1, 2, 4, 8, 16, 32, or 64 bits. It must also have no user-defined constructor, destructor, or copy assignment operator; no private or protected non-static data members; no non-static data members of reference type; no base classes; no virtual functions; and no data members that do not also meet these requirements. (This is essentially the definition of a C++03 POD type. Because the definition has changed in the C++11 standard, we don't recommend using std::is_pod for this test.) Otherwise, the caller assumes the responsibility of allocating memory and passing a pointer for the return value as the first argument. Subsequent arguments are then shifted one argument to the right. The same pointer must be returned by the callee in RAX.


Похоже на правду?
Re[8]: Приведение базового класса в конструкторе потомка
Здравствуйте, Евгений Музыченко, Вы писали:

MA>> Как бы я не извращался — результат в rax. На clang тоже в rax.

ЕМ>А это уже странно. Они ж должны быть совместимы по ABI.
Что-то вчера был не мой день видимо. Я и проект собирал, ошибся и пол дня он висел без дела, пока я не заметил.

В моём примере: msvc x64 v19.22 для method и virtual_method возвращается адрес на структуру, для static_method возвращается сама структура по значению.
А вот clang 8.0 — в обоих случаях возвращает структуру по значению (через регистр). С -O1 тела методов вообще идентичны.

Насчет должны быть совместимы по ABI — то, афаик, windows abi отличается от amd64 abi.

Вроде как похоже, что поведение вполне соответствует документации Calling Conventions: Return Values.

A scalar return value that can fit into 64 bits is returned through RAX; this includes __m64 types. Non-scalar types including floats, doubles, and vector types such as __m128, __m128i, __m128d are returned in XMM0. The state of unused bits in the value returned in RAX or XMM0 is undefined.

User-defined types can be returned by value from global functions and static member functions. To return a user-defined type by value in RAX, it must have a length of 1, 2, 4, 8, 16, 32, or 64 bits. It must also have no user-defined constructor, destructor, or copy assignment operator; no private or protected non-static data members; no non-static data members of reference type; no base classes; no virtual functions; and no data members that do not also meet these requirements. (This is essentially the definition of a C++03 POD type. Because the definition has changed in the C++11 standard, we don't recommend using std::is_pod for this test.) Otherwise, the caller assumes the responsibility of allocating memory and passing a pointer for the return value as the first argument. Subsequent arguments are then shifted one argument to the right. The same pointer must be returned by the callee in RAX.


Похоже на правду?