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

fix #29718, union field alignment #29722

Merged
merged 1 commit into from
Oct 23, 2018
Merged

fix #29718, union field alignment #29722

merged 1 commit into from
Oct 23, 2018

Conversation

JeffBezanson
Copy link
Sponsor Member

No description provided.

@JeffBezanson JeffBezanson added bugfix This change fixes an existing bug backport pending 1.0 labels Oct 19, 2018
@quinnj
Copy link
Member

quinnj commented Oct 19, 2018

So is the bug only hit in the case where there were enough fields to require alignment? Or with an unfortunate choice of fields prior to an isbits Union field to cause the misalignment?

@vtjnash
Copy link
Sponsor Member

vtjnash commented Oct 19, 2018

This looks correct, but is a bit more pessimistic than it necessarily needs to be. The only caller that needs the more pessimistic result is julia_struct_to_llvm, so we can instead just remove the first branch from julia_struct_to_llvm that calls this, and instead unconditionally uses the jl_islayout_inline computation—that's still slightly pessimistic for alignment in rare cases (we could use al = std::min(al, fsz)), but the jl_islayout_inline alignment computation result might be a better match for later usage (better for SROA) anyways.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Oct 19, 2018

@quinnj, the correct representation of the type was { [i16 * 1], i8 }, so this only hits when we are at a byte boundary where the actual alignment guarantee exceeds the minimum required (we had accidentally instead emitted { [i64 * 0], i8, i8, i8 }).

@JeffBezanson
Copy link
Sponsor Member Author

Better?

@vtjnash
Copy link
Sponsor Member

vtjnash commented Oct 19, 2018

Remove pessimization of jl_field_align?

MWE can be added to the existing UnionFieldN list of tests. The smallest type that should exhibit this mis-behavior is:

struct UnionField
    alignment::Int32
    padding::NTuple{3, UInt8}
    #= implicit-padding::UInt8 =#
    maybe_val::Union{UInt16, Nothing} # offset = 8, align = 8, size = 2
end

@JeffBezanson JeffBezanson merged commit 70be5f2 into master Oct 23, 2018
@JeffBezanson JeffBezanson deleted the jb/fix29718 branch October 23, 2018 02:38
KristofferC pushed a commit that referenced this pull request Oct 29, 2018
KristofferC pushed a commit that referenced this pull request Feb 11, 2019
KristofferC pushed a commit that referenced this pull request Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants