mirror of
git://repo.or.cz/tinycc.git
synced 2026-11-04 21:26:36 +08:00
tccgen: stop ignoring qualifiers in array-like parameters
To ensure that qualifiers within an array-style parameter declaration (e.g. int [const 2] are handled correctly, post_type() is modified to collect qualifiers and OR them into the t member of CType. The new test for restrict also passes, but only because the restrict keyword is ignored.
This commit is contained in:
parent
5f1425ef21
commit
1f214e1390
12
tccgen.c
12
tccgen.c
@ -5144,6 +5144,7 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td)
|
||||
|
||||
} else if (tok == '[') {
|
||||
int saved_nocode_wanted = nocode_wanted;
|
||||
int array_qualifiers = 0;
|
||||
/* array definition */
|
||||
next();
|
||||
n = -1;
|
||||
@ -5153,9 +5154,15 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td)
|
||||
in parameter decls. The '*' as well, and then even only
|
||||
in prototypes (not function defs). */
|
||||
switch (tok) {
|
||||
case TOK_CONST1: case TOK_CONST2: case TOK_CONST3:
|
||||
array_qualifiers |= VT_CONSTANT;
|
||||
next();
|
||||
continue;
|
||||
case TOK_VOLATILE1: case TOK_VOLATILE2: case TOK_VOLATILE3:
|
||||
array_qualifiers |= VT_VOLATILE;
|
||||
next();
|
||||
continue;
|
||||
case TOK_RESTRICT1: case TOK_RESTRICT2: case TOK_RESTRICT3:
|
||||
case TOK_CONST1:
|
||||
case TOK_VOLATILE1:
|
||||
case TOK_STATIC:
|
||||
case '*':
|
||||
next();
|
||||
@ -5240,6 +5247,7 @@ check:
|
||||
s = sym_push(SYM_FIELD, type, 0, n);
|
||||
type->t = (t1 ? VT_VLA : VT_ARRAY) | VT_PTR;
|
||||
type->ref = s;
|
||||
type->t |= array_qualifiers;
|
||||
|
||||
if (vla_array_str) {
|
||||
/* for function args, the top dimension is converted to pointer */
|
||||
|
||||
@ -8,6 +8,16 @@ void pointer_parameters(int *const cp, int *volatile vp, int *restrict rp)
|
||||
"restrict pointer parameter remains qualified");
|
||||
}
|
||||
|
||||
void array_parameters(int ca[const 2], int va[volatile 2], int ra[restrict 2])
|
||||
{
|
||||
_Static_assert(_Generic(&ca, int *const *: 1, default: 0),
|
||||
"const array parameter adjusts to qualified pointer");
|
||||
_Static_assert(_Generic(&va, int *volatile *: 1, default: 0),
|
||||
"volatile array parameter adjusts to qualified pointer");
|
||||
_Static_assert(_Generic(&ra, int *restrict *: 1, default: 0),
|
||||
"restrict array parameter adjusts to qualified pointer");
|
||||
}
|
||||
|
||||
void declared_const(int *const pointer);
|
||||
void declared_const(int *pointer)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user