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

Check argument size on static array parameters #742

Merged
merged 6 commits into from
Aug 5, 2024

Conversation

wrongnull
Copy link
Contributor

Closes #349

@@ -7683,6 +7684,18 @@ fn callExpr(p: *Parser, lhs: Result) Error!Result {
continue;
}
const p_ty = params[arg_count].ty;
if (p_ty.statically_sized_array) {
if (arg.ty.data == .array and arg.ty.data.array.*.len < p_ty.data.array.*.len) {
Copy link
Owner

Choose a reason for hiding this comment

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

This should use arrayLen instead of making the union tagged.

.expected = @intCast(arg.ty.data.array.*.len),
.actual = @intCast(p_ty.data.array.*.len),
} };
try p.errExtra(.array_argument_too_small, param_tok, extra);
Copy link
Owner

Choose a reason for hiding this comment

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

Clang also adds a callee declares array parameter as static here note. You should be able to do the same with params[arg_count].name_tok.

src/aro/Type.zig Outdated
@@ -425,6 +425,7 @@ data: union {
specifier: Specifier,
qual: Qualifiers = .{},
decayed: bool = false,
statically_sized_array: bool = false,
Copy link
Owner

Choose a reason for hiding this comment

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

static_array specifier exists but is seemingly unused currently. Could you try using that instead?

(Apparently it was only used for three days between c35d5c2 and 9b4daaa)

@wrongnull
Copy link
Contributor Author

@Vexu all the desired changes have been made

@Vexu Vexu merged commit 399ac84 into Vexu:master Aug 5, 2024
3 checks passed
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.

Check array bounds for array parameters with static keyword
2 participants