Skip to content

Fix VLA with forward declaration#248

Merged
tyfkda merged 1 commit intomainfrom
feature/vla-forward-decl
Mar 30, 2026
Merged

Fix VLA with forward declaration#248
tyfkda merged 1 commit intomainfrom
feature/vla-forward-decl

Conversation

@tyfkda
Copy link
Copy Markdown
Owner

@tyfkda tyfkda commented Mar 30, 2026

@kyx0r Would you please check this change fix the bug?
Thanks.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the ensure_type_info function for structs, adds type information checks in mark_var_used_sub and parse_vardecl_cont, and includes a new test case for VLAs with forward declarations. The review feedback highlights that the return values of the newly added ensure_type_info calls are being ignored in both fe_misc.c and parser.c, which could lead to crashes or unexpected behavior when processing incomplete types. It is recommended to check these return values and handle errors appropriately to ensure the compiler does not proceed with invalid type information.

}

static void mark_var_used_sub(Expr *expr, bool for_func) {
ensure_type_info(expr->type, expr->token, curscope, true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The return value of ensure_type_info is ignored. If the type is incomplete, this function returns false after reporting an error. Continuing execution with an incomplete type might lead to unexpected behavior or crashes in later stages. You should check the return value and handle the error, for example by returning early from this function.

  if (!ensure_type_info(expr->type, expr->token, curscope, true))
    return;

Comment on lines +201 to +202
if (!(storage & (VS_EXTERN | VS_TYPEDEF)))
ensure_type_info(type, ident, curscope, true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The return value of ensure_type_info is ignored. This function returns false if the type is incomplete, after reporting an error. The parser then continues execution, which can lead to a crash later (e.g., in calc_vla_size) when operating on the incomplete type. You should check the return value and skip processing this invalid declarator.

    if (!(storage & (VS_EXTERN | VS_TYPEDEF))) {
      if (!ensure_type_info(type, ident, curscope, true))
        continue;
    }

@tyfkda tyfkda merged commit 0ad6275 into main Mar 30, 2026
1 check passed
@tyfkda tyfkda deleted the feature/vla-forward-decl branch March 30, 2026 23:47
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.

1 participant