Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doh: fix undefined behaviour in swap #4350

Closed
wants to merge 1 commit into from

Conversation

@pauldreik
Copy link
Contributor

commented Sep 13, 2019

The undefined behaviour is annoying when running fuzzing with
sanitizers. The codegen is the same, but the meaning is now
not up for dispute. See https://cppinsights.io/s/516a2ff4

By incrementing the pointer first, both gcc and clang recognize this
as a bswap and optimizes it to a single instruction.
See https://godbolt.org/z/994Zpx

The undefined behaviour is annoying when running fuzzing with
sanitizers. The codegen is the same, but the meaning is now
not up for dispute. See https://cppinsights.io/s/516a2ff4

By incrementing the pointer first, both gcc and clang recognize this
as a bswap and optimizes it to a single instruction.
See https://godbolt.org/z/994Zpx
@bagder
bagder approved these changes Sep 13, 2019
Copy link
Member

left a comment

There are certainly several ways to fix the undefined behavior (even if most compilers seem to be fine with it), but if this has the benefit that it generates better code I'm all for it!

@pauldreik pauldreik changed the title adc: fix undefined behaviour in swap doh: fix undefined behaviour in swap Sep 14, 2019
@bagder

This comment has been minimized.

Copy link
Member

commented Sep 15, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.