-
-
Notifications
You must be signed in to change notification settings - Fork 186
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
flex_vector does not respect type alignment requirements #234
Comments
Thanks a lot! Yes had issues with Eigen before which made me suspect for some time that this was the case. I somehow thought that I fixed this in the past but it is clearly still there. Thanks for the nice words and for finding a small repro case! |
So I did a bit of digging on this. First, the current state. It looks like you've definitely thought about this before, since in I can see a couple solutions here:
If you want I can take a pass at either of these options, or something else that you have in mind. Or I can leave it be; I have a workaround I can use at the call site (turning off alignment optimizations for eigen types I store in |
Hi @sissow2! Your assesment seems very much on point. Thanks a lot for looking into this. Either of the two approaches sounds good. Maybe the latter could be better as to keep the data-structure code simpler, but happy to take the other route if you feel like it's actually not much effort. I don't have much time to look into this over the next few days, so if you wanna start the work it would be he greatly appreciated. Also: can you reproduce this issue with some of the other data-structures? |
Re other data structures: I updated the repro case to check all the data structures, as well as different alignments: master...sissow2:immer:sissow2-alignment-flex-vector-bug. Here's what I found:
The natural alignment of the compiler in Re the allocator solution: Writing an allocator that is guaranteed to return aligned pointers seems to be quite the exercise, but fortunately c++17 added overloads to
|
I do no think we need the C++17 alignment API since we use our own allocator API? Memory allocated with |
Hey, it just hit me I forgot to communicate back here- Again, sorry for leaving this in limbo for so long. |
No worries, I wasn't waiting for you. Thanks for checking in! |
Essentially, flex_vector can (always?) allocates objects at addresses that do not align with the type's alignment requirements. I uncovered this while using Eigen with
immer
, which causes some nasty segfaults when there are alignment violations on vectorized types.I added a repro case here: sissow2@9d295b8 . The sanity check with
std::vector
passes always, while theimmer::flex_vector
variant always fails :This might be related to #228, but the reporter's repro case is for a non-vectorized type so I'm not sure it's the same issue.
I might be able to create a PR with a fix, but wondering if you have any ideas before I dive into it.
Also: I'm really liking this library! This and
lager
have been making my life so much easier. Also thanks for providing anix-shell
environment, it made creating this repro case a breeze.The text was updated successfully, but these errors were encountered: