mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-05 04:40:06 +08:00
44c330d647
This patch disables the optimization of saving stack pointers lazily, which didn't fully take into account that control flow might not reach the stack-saving instructions. I've decided to leave in the extra calls to vla_sp_save() in case anyone wants to restore this optimization. Tests added and enabled. There are two remaining bugs: VLA variables can be modified, and jumping into the scope of a declared VLA will cause a segfault rather than a compiler error. Both of these do not affect correct C code, but should be fixed at some point. Once VLA variables have been made properly immutable, we can share them with the saved stack pointer and save stack and instructions.
117 lines
1.3 KiB
C
117 lines
1.3 KiB
C
#include <stdio.h>
|
|
|
|
int f(void)
|
|
{
|
|
return 5;
|
|
}
|
|
|
|
void test1()
|
|
{
|
|
int count = 10;
|
|
void *addr[10];
|
|
for(;count--;) {
|
|
int a[f()];
|
|
|
|
addr[count] = a;
|
|
|
|
continue;
|
|
}
|
|
|
|
if(addr[9] == addr[0]) {
|
|
printf("OK\n");
|
|
} else {
|
|
printf("NOT OK\n");
|
|
}
|
|
}
|
|
|
|
void test2()
|
|
{
|
|
int count = 10;
|
|
void *addr[count];
|
|
for(;count--;) {
|
|
int a[f()];
|
|
|
|
addr[count] = a;
|
|
|
|
continue;
|
|
}
|
|
|
|
if(addr[9] == addr[0]) {
|
|
printf("OK\n");
|
|
} else {
|
|
printf("NOT OK\n");
|
|
}
|
|
}
|
|
|
|
void test3()
|
|
{
|
|
int count = 10;
|
|
void *addr[count];
|
|
while(count--) {
|
|
int a[f()];
|
|
|
|
addr[count] = a;
|
|
|
|
continue;
|
|
}
|
|
|
|
if(addr[9] == addr[0]) {
|
|
printf("OK\n");
|
|
} else {
|
|
printf("NOT OK\n");
|
|
}
|
|
}
|
|
|
|
void test4()
|
|
{
|
|
int count = 10;
|
|
void *addr[count];
|
|
do {
|
|
int a[f()];
|
|
|
|
addr[count] = a;
|
|
|
|
continue;
|
|
} while(count--);
|
|
|
|
if(addr[9] == addr[0]) {
|
|
printf("OK\n");
|
|
} else {
|
|
printf("NOT OK\n");
|
|
}
|
|
}
|
|
|
|
void test5()
|
|
{
|
|
int count = 10;
|
|
int a[f()];
|
|
int c[f()];
|
|
|
|
c[0] = 42;
|
|
|
|
for(;count--;) {
|
|
int b[f()];
|
|
int i;
|
|
for (i=0; i<f(); i++) {
|
|
b[i] = count;
|
|
}
|
|
}
|
|
|
|
if (c[0] == 42) {
|
|
printf("OK\n");
|
|
} else {
|
|
printf("NOT OK\n");
|
|
}
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
test1();
|
|
test2();
|
|
test3();
|
|
test4();
|
|
test5();
|
|
|
|
return 0;
|
|
}
|