CallableCustomMethodPointerBase: Make _setup strict-aliasing safe#104501
CallableCustomMethodPointerBase: Make _setup strict-aliasing safe#104501corngood wants to merge 2 commits intogodotengine:masterfrom
_setup strict-aliasing safe#104501Conversation
6a6e4b3 to
783fbdb
Compare
|
@rune-scape @akien-mga excuse the pings, you were involved in the last substantial PR in this area |
_setup strict-aliasing safe
There was a problem hiding this comment.
The fix looks sound; this should never have used uint32_t* in the first place for raw data.
hash_murmur3_buffer might be a good candidate if we don't mind changing the result.
I agree it would be better to just hash a buffer, but I'm not familiar with the code. So I don't know if this would break compatibility somehow.
However, it looks like it also uses invalid aliasing:
This should probably be fixed too.
I added a commit to fix this. It's not as thoroughly tested as the other one. I can pull it into another PR if you prefer. Edit: I ran a few tests to confirm the results are unchanged when it's called in practice, so I think it's probably solid. |
Ivorforce
left a comment
There was a problem hiding this comment.
The code looks good! I only have a few comment and one style request now :)
e661f9e to
9b021ea
Compare
Ivorforce
left a comment
There was a problem hiding this comment.
The code looks good to me, thanks!
It should probably be tested before merging.
I also can't comment on whether this has any implications on GDExtension semantics (though I don't think it does).
9b021ea to
8282327
Compare
Let me know if there's anything you're interesting in testing in particular. I did run a bit with some assertions that the new functions match the results of the old functions. I also ran the test suite locally. I've only tested on x86_64-linux with gcc 14. |
I found a bug when compiling a production build of godot 4 (template) for x86_64-linux using GCC 14:
I tracked this down to incorrect optimisation of
CallableCustomMethodPointerBase::_setup, caused by invalid pointer aliasing.There are various ways this could be fixed. I went with one that gives the same results as the current implementation. I chose to use
charsince the language spec references it, butuint8_twould probably also be okay in practice.I can provide a repro as a nix expression, but it's very sensitive to the compiler configuration, so it might be difficult to reproduce otherwise.
hash_murmur3_buffermight be a good candidate if we don't mind changing the result. However, it looks like it also uses invalid aliasing:I'm not sure if it's worth trying to proactively fix things like this, do a more exhaustive search, or just turn on
-fno-strict-aliasing.