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

Incorrect sizeof for typeof incomplete array #692

Closed
ehaas opened this issue Apr 24, 2024 · 1 comment
Closed

Incorrect sizeof for typeof incomplete array #692

ehaas opened this issue Apr 24, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ehaas
Copy link
Collaborator

ehaas commented Apr 24, 2024

typeof(const int[]) x = {1, 2};
_Static_assert(sizeof(x) == sizeof(int[2]), "");
test.c:2:16: error: invalid application of 'sizeof' to an incomplete type 'const int []'
_Static_assert(sizeof(x) == sizeof(int[2]), "");
               ^

We're incorrectly treating x as having type const int[] instead of const int[2]. I suspect we're not resolving incomplete array types correctly when indirected through typeof. const int x[] = {1, 2}; (with no typeof) works fine.

@ehaas ehaas added the bug Something isn't working label Apr 24, 2024
@ehaas
Copy link
Collaborator Author

ehaas commented Apr 24, 2024

This seems to be the culprit:

arocc/src/aro/Parser.zig

Lines 1821 to 1825 in aa52b23

if (init_d.d.ty.specifier == .incomplete_array) {
// Modifying .data is exceptionally allowed for .incomplete_array.
init_d.d.ty.data.array.len = init_list_expr.ty.arrayLen() orelse break :init;
init_d.d.ty.specifier = .array;
}

ehaas added a commit to ehaas/arocc that referenced this issue Apr 25, 2024
@Vexu Vexu closed this as completed in f012358 Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant