Skip to content

codegen: on alignment incongruence, replace assert by jl_error #34245

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

Closed

Conversation

tkluck
Copy link
Contributor

@tkluck tkluck commented Jan 3, 2020

It is possible that LLVM and Julia disagree on the offsets of struct
fields. This has been observed in #32414 in cases like

Tuple{Float64, NTuple{8, VecElement{Float64}}}

where LLVM wants to align the vec on 64 bytes (adding 56 bytes
of padding after the first Float64) but Julia refusing to
align like that because it can't guarantee that on the heap:

if (al > JL_HEAP_ALIGNMENT)

There is no easy solution this I can see, but since this can be
triggered from pure Julia, the least we can do is not abort the program.

For this reason, this commit replaces the assert by jl_error.
To be able to give a sort-of meaningful error message, we return
a sentinel value from convert_struct_offset and generate
an error message in the caller.

It is possible that LLVM and Julia disagree on the offsets of struct
fields. This has been observed in JuliaLang#32414 in cases like

    Tuple{Float64, NTuple{8, VecElement{Float64}}}

where LLVM wants to align the `vec` on 64 bytes (adding 56 bytes
of padding after the first `Float64`) but Julia refusing to
align like that because it can't guarantee that on the heap:

https://github.com/JuliaLang/julia/blob/c7e9d9f8ade647582c6635c8c9a587f2360af404/src/datatype.c#L453

There is no easy solution this I can see, but since this can be
triggered from pure Julia, the least we can do is not abort the program.

For this reason, this commit replaces the assert by jl_error.
To be able to give a sort-of meaningful error message, we return
a sentinel value from `convert_struct_offset` and generate
an error message in the caller.
@ararslan ararslan added the needs tests Unit tests are required for this change label Jan 3, 2020
@ararslan ararslan requested a review from vtjnash January 3, 2020 22:20
@tkluck
Copy link
Contributor Author

tkluck commented Jan 4, 2020

@ararslan thanks for having a look and requesting a review. I just pushed a simple test per your request.

@ararslan ararslan removed the needs tests Unit tests are required for this change label Jan 6, 2020
@tkluck
Copy link
Contributor Author

tkluck commented Jan 31, 2020

Closing as there is now a complete fix in the form of #34473

@tkluck tkluck closed this Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants