Conversation
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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;| if (!(storage & (VS_EXTERN | VS_TYPEDEF))) | ||
| ensure_type_info(type, ident, curscope, true); |
There was a problem hiding this comment.
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;
}
@kyx0r Would you please check this change fix the bug?
Thanks.