diff options
| author | Joe Soroka <gits@joesoroka.com> | 2011-04-06 09:17:03 -0700 |
|---|---|---|
| committer | Joe Soroka <gits@joesoroka.com> | 2011-04-06 09:17:03 -0700 |
| commit | ace0f7f2598f5e9d9d2ad8999e3140b8535d9459 (patch) | |
| tree | 0a763fdf00c10cedc7d968d4d99d2db92b0c2635 /tests | |
| parent | 17571298f30bf204fafe9cf1aca5258d2d087d63 (diff) | |
| download | tinycc-ace0f7f2598f5e9d9d2ad8999e3140b8535d9459.tar.gz tinycc-ace0f7f2598f5e9d9d2ad8999e3140b8535d9459.tar.bz2 | |
re-apply VLA by Thomas Preud'homme
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/tcctest.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/tcctest.c b/tests/tcctest.c index df0a0c6..8a6dd16 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -77,6 +77,7 @@ void whitespace_test(void); void relocation_test(void); void old_style_function(void); void alloca_test(void); +void c99_vla_test(int size1, int size2); void sizeof_test(void); void typeof_test(void); void local_label_test(void); @@ -569,6 +570,7 @@ int main(int argc, char **argv) relocation_test(); old_style_function(); alloca_test(); + c99_vla_test(5, 2); sizeof_test(); typeof_test(); statement_expr_test(); @@ -2068,6 +2070,26 @@ void alloca_test() #endif } +void c99_vla_test(int size1, int size2) +{ +#if defined __i386__ || defined __x86_64__ + int tab1[size1 * size2][2], tab2[10][2]; + void *tab1_ptr, *tab2_ptr; + + printf("Test C99 VLA 1 (sizeof): "); + printf("%s\n", (sizeof tab1 == size1 * size2 * 2 * sizeof(int)) ? "PASSED" : "FAILED"); + tab1_ptr = tab1; + tab2_ptr = tab2; + printf("Test C99 VLA 2 (ptrs substract): "); + printf("%s\n", (tab2 - tab1 == (tab2_ptr - tab1_ptr) / (sizeof(int) * 2)) ? "PASSED" : "FAILED"); + printf("Test C99 VLA 3 (ptr add): "); + printf("%s\n", &tab1[5][1] == (tab1_ptr + (5 * 2 + 1) * sizeof(int)) ? "PASSED" : "FAILED"); + printf("Test C99 VLA 4 (ptr access): "); + tab1[size1][1] = 42; + printf("%s\n", (*((int *) (tab1_ptr + (size1 * 2 + 1) * sizeof(int))) == 42) ? "PASSED" : "FAILED"); +#endif +} + void sizeof_test(void) { int a; |
