Repository navigation
Add repr(align) to over-aligned empty structs - #3555
Open
samiarif02 wants to merge 1 commit into
Open
samiarif02 wants to merge 1 commit into
samiarif02 wants to merge 1 commit into
Conversation
An empty struct with __attribute__((aligned(N))) went through the zero-sized path in codegen, which never set an explicit alignment, so the generated struct had alignment 1 and its own layout test failed, as did the layout of any struct containing it. Fixes rust-lang#3549.
Author
|
The clippy failure is in |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3549.
An empty struct marked
__attribute__((aligned(N)))goes through the zero-sized branch inCompInfo::codegen, and that branch never setsexplicit_align. So the struct came out as plain#[repr(C)]with alignment 1, its own layout test failed, and so did the layout of any struct that contains it (thetaskexample in the issue).The fix sets
explicit_alignfor zero-sized, non-union, non-forward-declared structs when the layout asks for more than 1-byte alignment. Ordinary empty structs (align 1) are unchanged.Tests: added
empty-struct-aligned.h(C, size 0) andempty-struct-aligned-cpp.hpp(C++, size 64 with the_addressbyte). Both expectations differ from main only by the new#[repr(align(64))]. Without the fix the generated layout tests don't compile (align_of1 vs 64); with it they do.cargo test -p bindgen-testsgives the same results as main apart from the two new tests. Three tests (issue-544-stylo-creduce-2,nsbasehashtable,objc_template) fail locally on main too with Apple's libclang. Changelog entry added under Unreleased/Fixed.