mirror of https://github.com/rui314/chibicc
Support sizeof(typename) where typename is a VLA
This commit is contained in:
parent
07f901057f
commit
2fa8f489f3
12
parse.c
12
parse.c
|
@ -2841,8 +2841,16 @@ static Node *primary(Token **rest, Token *tok) {
|
|||
if (equal(tok, "sizeof") && equal(tok->next, "(") && is_typename(tok->next->next)) {
|
||||
Type *ty = typename(&tok, tok->next->next);
|
||||
*rest = skip(tok, ")");
|
||||
if (ty->kind == TY_VLA)
|
||||
return new_var_node(ty->vla_size, tok);
|
||||
|
||||
if (ty->kind == TY_VLA) {
|
||||
if (ty->vla_size)
|
||||
return new_var_node(ty->vla_size, tok);
|
||||
|
||||
Node *lhs = compute_vla_size(ty, tok);
|
||||
Node *rhs = new_var_node(ty->vla_size, tok);
|
||||
return new_binary(ND_COMMA, lhs, rhs, tok);
|
||||
}
|
||||
|
||||
return new_ulong(ty->size, start);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ int main() {
|
|||
ASSERT(5, ({ int n=10; int x[n+1][n+6]; int *p=x; for (int i = 0; i<sizeof(x)/4; i++) p[i]=i; x[0][5]; }));
|
||||
ASSERT(5*16+2, ({ int n=10; int x[n+1][n+6]; int *p=x; for (int i = 0; i<sizeof(x)/4; i++) p[i]=i; x[5][2]; }));
|
||||
|
||||
ASSERT(10, ({ int n=5; sizeof(char[2][n]); }));
|
||||
|
||||
printf("OK\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue