Skip to content

Conversation

@swolchok
Copy link
Contributor

@swolchok swolchok commented Nov 13, 2024

Accessing the inactive member of a union is undefined behavior. Fortunately, we have c10::bit_cast.

Differential Revision: [D65888680](https://our.internmc.facebook.com/intern/diff/D65888680/)

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Nov 13, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/140567

Note: Links to docs will display an error until the docs builds have been completed.

❗ 2 Active SEVs

There are 2 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit 656fca5 with merge base 891ba2e (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

swolchok added a commit that referenced this pull request Nov 13, 2024
Accessing the inactive member of a union is undefined behavior. Fortunately, we have c10::bit_cast.

Differential Revision: [D65888680](https://our.internmc.facebook.com/intern/diff/D65888680/)

ghstack-source-id: 253354216
Pull Request resolved: #140567
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D65888680

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 14, 2024
@swolchok swolchok added the topic: improvements topic category label Nov 14, 2024
Accessing the inactive member of a union is undefined behavior. Fortunately, we have c10::bit_cast.

Differential Revision: [D65888680](https://our.internmc.facebook.com/intern/diff/D65888680/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D65888680

Accessing the inactive member of a union is undefined behavior. Fortunately, we have c10::bit_cast.

Differential Revision: [D65888680](https://our.internmc.facebook.com/intern/diff/D65888680/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D65888680

Copy link
Contributor

@malfet malfet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but for my own education, why this is an undefined behavior? I though that union is a legit way of casting between types of the same size and https://stackoverflow.com/questions/6725809/trap-representation seems to confirm that

@swolchok
Copy link
Contributor Author

swolchok commented Nov 18, 2024

union is a legit way of casting between types of the same size and https://stackoverflow.com/questions/6725809/trap-representation seems to confirm that

It might be legal C (and that stack overflow question is about C), but it is not legal C++. This is one of the ways in which C++ is not a superset of C; instead they are two sets with overlapping and non-overlapping parts. Compare https://en.cppreference.com/w/cpp/language/union (search "undefined") to https://en.cppreference.com/w/c/language/union (search "unspecified" and "type punning"). FWIW I wrote an article about fun things to do with unions at https://dev-discuss.pytorch.org/t/unionizing-for-profit-how-to-exploit-the-power-of-unions-in-c/444

@swolchok
Copy link
Contributor Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D65888680

1 similar comment
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D65888680

pytorchmergebot pushed a commit that referenced this pull request Nov 19, 2024
cyyever pushed a commit to cyyever/pytorch that referenced this pull request Nov 20, 2024
Ryo-not-rio pushed a commit to Ryo-not-rio/pytorch that referenced this pull request Dec 2, 2024
pobin6 pushed a commit to pobin6/pytorch that referenced this pull request Dec 5, 2024
fmo-mt pushed a commit to fmo-mt/pytorch that referenced this pull request Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request fb-exported Merged release notes: cpp release notes category topic: improvements topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants