-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
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
Fix union order to simplify empty initializers. #101344
Conversation
Thanks! |
Today I got bitten by this issue too (I was on an older master branch), Valgrind reports how these uninitialized variables propagate throughout the codebase. I strongly recommend this patch to be backported to earlier versions. It may be more serious than we think. |
The structs in the patch don't exist before 4.4. |
Then we missed some unions. I see them now. I'll make another PR. |
This is a followup to PR godotengine#101344 (commit 0e06eb8). Some of them were not an issue because Godot was initializing all members, but they were "fixed" just in case since it could become a problem in the future. Valgrind was specifically complaining about HashMapData & GlobalPipelineData.
Done. |
This is a followup to PR godotengine#101344 (commit 0e06eb8). Some of them were not an issue because Godot was initializing all members, but they were "fixed" just in case since it could become a problem in the future. Valgrind was specifically complaining about HashMapData & GlobalPipelineData.
This is a followup to PR godotengine#101344 (commit 0e06eb8). Some of them were not an issue because Godot was initializing all members, but they were "fixed" just in case since it could become a problem in the future. Valgrind was specifically complaining about HashMapData & GlobalPipelineData.
This is a followup to PR godotengine#101344 (commit 0e06eb8). Some of them were not an issue because Godot was initializing all members, but they were "fixed" just in case since it could become a problem in the future. Valgrind was specifically complaining about HashMapData & GlobalPipelineData.
This one's more of a general codebase issue but the particular structures I fixed were rendering related.
There's a bit of not so common knowledge regarding union initialization where only the very first element of the union is picked when using empty initializers such as
{}
if no other element in the union has an explicit initializer.This leads to a very significant difference when it comes to code generation when bitfields are involved, as can be verified here:
https://gcc.godbolt.org/z/6vzYnz4ae
The code difference generation can actually introduce subtle bugs where unused bits on the union were left uninitialized, causing more pipeline generation than what is necessary.
We should make sure to follow the rule of always placing first the element that covers the entire union and has the most trivial initialization to ensure subtle bugs like this can't be introduced.