tinycc/tests/tests2/100_c99array-decls.c
Christopher Bazley f4d81ced3e tccgen: Minimal implementation of restrict
TCC currently recognises the restrict keyword but
discards it. Give the qualifier its own type bit and
diagnose misuse that violates constraints in ISO C.

There is (obviously) no new aliasing analysis.
2026-09-26 21:47:46 +01:00

55 lines
1.4 KiB
C

void foo(int [5]);
void fooc(int x[const 5]);
void foos(int x[static 5]);
void foov(int x[volatile 5]);
void foor(int x[restrict 5]);
void fooc(int [const 5]);
void foos(int [static 5]);
void foov(int [volatile 5]);
void foor(int [restrict 5]);
void fooc(int (* const x));
void foos(int *x);
void foov(int * volatile x);
void foor(int * restrict x);
void fooc(int x[volatile 5])
{
x[3] = 42;
#ifdef INVALID
x = 0;
#endif
}
void foovm(int x[const *]);
void foovm(int * const x);
typedef int *pointer_array[2];
typedef int *restrict restricted_pointer;
typedef restrict pointer_array restricted_pointer_array;
_Static_assert(!__builtin_types_compatible_p(int **,
restricted_pointer *),
"nested restrict qualifier is retained");
_Static_assert(__builtin_types_compatible_p(restricted_pointer_array,
restricted_pointer[2]),
"restrict can qualify an array of pointer types");
restricted_pointer *restricted_pp;
int **unrestricted_pp;
_Static_assert(__builtin_types_compatible_p(
__typeof__(1 ? restricted_pp : unrestricted_pp),
restricted_pointer *),
"conditional expression combines restrict qualifiers");
#ifdef INVALID
void wrongc(int x[3][const 4]);
void wrongvm(int x[static *]);
void foovm(int x[const *])
{
x[2] = 1;
}
#endif
int main()
{
return 0;
}