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

Generate data only array members if they are of fixed size #1388

Merged
merged 5 commits into from
Dec 30, 2022

Conversation

czgdp1807
Copy link
Collaborator

@czgdp1807 czgdp1807 commented Dec 28, 2022

cc: @certik

Closes #1387

@czgdp1807 czgdp1807 marked this pull request as ready for review December 28, 2022 09:58
@@ -351,7 +351,8 @@ RUN(NAME structs_11 LABELS cpython llvm c)
RUN(NAME structs_12 LABELS cpython llvm c)
RUN(NAME structs_13 LABELS llvm c
EXTRAFILES structs_13b.c)
RUN(NAME structs_14 LABELS cpython llvm c)
RUN(NAME structs_14 LABELS llvm c
EXTRAFILES structs_14b.c)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to do a separate test, since we lost CPython test here. We want to ideally test everything via CPython, but at least what we were testing before.

sum_buffer += data[i];
}
return sum_buffer;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not enough. I think we need to pass the whole structure into C, then in C recreate the same structure using char[64] style, and then access the members and check that everything works. That would be robust.

The current test could still pass even with our pointer setup (yes, the memory would not be initialized properly, but one could get "lucky").

Copy link
Collaborator Author

@czgdp1807 czgdp1807 Dec 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which one do you want to pass to C, buffer_struct (not decorated with @ccall/@ccallable) or buffer_struct_clink (decorated with @ccall/@ccallable)? I guess buffer_struct_clink should be passed to C for testing as its the one with BindC ABI, correct? If you want to pass both, then LLVM backend will also need to be updated to always (irrespective of the ABI) represent fixed sized array members as data only pointers

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added test as per my understanding of the requirement. Please let me know if they look good or if you want any change in it. Thanks.

Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good, although it's not immediately obvious to me from the test that it does the right thing. Let's add the C Struct test as I indicated in the comment, then I think it will be 100% clear that it works.

Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good to merge! Thanks for fixing this.

@czgdp1807 czgdp1807 merged commit 90ca0a6 into lcompilers:main Dec 30, 2022
@czgdp1807 czgdp1807 deleted the arr_struct_2 branch December 30, 2022 05:17
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.

buffer: i8[64]; in struct must generate char buffer[64], not struct i8* buffer
2 participants