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

@pauldreik pauldreik 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

@bagder bagder 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
Copy link
Member

@bagder bagder commented Sep 15, 2019

Thanks!

@bagder bagder closed this in dda4182 Sep 15, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Dec 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.