cosmopolitan/third_party/chibicc/test/vla_test.c
Justine Tunney 8da931a7f6 Add chibicc
This program popped up on Hacker News recently. It's the only modern
compiler I've ever seen that doesn't have dependencies and is easily
modified. So I added all of the missing GNU extensions I like to use
which means it might be possible soon to build on non-Linux and have
third party not vendor gcc binaries.
2020-12-06 16:20:21 -08:00

86 lines
1.7 KiB
C

#include "third_party/chibicc/test/test.h"
int main() {
ASSERT(20, ({
int n = 5;
int x[n];
sizeof(x);
}));
ASSERT((5 + 1) * (8 * 2) * 4, ({
int m = 5, n = 8;
int x[m + 1][n * 2];
sizeof(x);
}));
ASSERT(8, ({
char n = 10;
int(*x)[n][n + 2];
sizeof(x);
}));
ASSERT(480, ({
char n = 10;
int(*x)[n][n + 2];
sizeof(*x);
}));
ASSERT(48, ({
char n = 10;
int(*x)[n][n + 2];
sizeof(**x);
}));
ASSERT(4, ({
char n = 10;
int(*x)[n][n + 2];
sizeof(***x);
}));
ASSERT(60, ({
char n = 3;
int x[5][n];
sizeof(x);
}));
ASSERT(12, ({
char n = 3;
int x[5][n];
sizeof(*x);
}));
ASSERT(60, ({
char n = 3;
int x[n][5];
sizeof(x);
}));
ASSERT(20, ({
char n = 3;
int x[n][5];
sizeof(*x);
}));
ASSERT(0, ({
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][0];
}));
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]);
}));
return 0;
}