Rewrite CompactValue to avoid undefined behavior from the use of a union for type-punning #1154
Reference in New Issue
Block a user
No description provided.
Delete Branch "htpiv/use-bit-cast"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
C++ does not, pedantically, allow the use of unions for type-punning in the way that C does. Most compilers, in practice, do support it; however, recent versions of MSVC appear to have a bug that cause bad code to be generated due to this U.B. (see: https://developercommunity.visualstudio.com/t/Bad-code-generated-for-std::isnan-compil/10082631). This led to a series of issues in the react-native-windows project, see:
In C++20, the
<bit>
header andbit_cast
function provide a pleasant API for type-punning. Since C++20 is not universally available, if the feature-test macro forbit_cast
is not defined, memcpy is used instead.Hi @htpiv!
Thank you for your pull request and welcome to our community.
Action Required
In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.
Process
In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.
Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with
CLA signed
. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!
@rozele has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@@ -12,0 +13,4 @@
#include <bit>
#else
#include <cstring>
#endif
Looks like internal builds are failing because std::memcpy requires
#include <cstring>
Should this be:
Pull request closed