Use src size for memcpy in order to avoid fortify complaints (#65222)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/65222

When compiling against the Android SDK with `--D_FORTIFY_SOURCE=2`, the compiler will complain that the `dst` size is a larger size than the `src` size due to the function templating using two differently sized objects. There is a `TORCH_CHECK` to ensure we don't go through with these `memcpy`'s, but in the interest of making the compiler happy, lets switch the `memcpy` to take `sizeof(src)`.

Test Plan: CI

Reviewed By: bertmaher, lanza

Differential Revision: D30992678

fbshipit-source-id: b3e7aa992a3650e1051abad05be800b684e6332b
This commit is contained in:
Oskar Wirga 2021-10-06 09:03:24 -07:00 committed by Facebook GitHub Bot
parent bfaaac6392
commit c4ea447eb5

View File

@ -103,7 +103,7 @@ template <typename To, typename From>
To raw_bitcast(const From& src) {
TORCH_CHECK(sizeof(To) == sizeof(From), "Invalid bitcast invocation");
To storage;
std::memcpy(&storage, &src, sizeof(From));
std::memcpy(&storage, &src, sizeof(To));
return reinterpret_cast<To&>(storage);
}