From 93cd98dd143d45a31a7fd90ad8f0b3d3c4c7798f Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Fri, 3 Apr 2020 00:10:45 -0700 Subject: move tinyc to a separate repo and allow installing external dependencency (eg tinyc) from koch / library code (#13850) * remove tinyc * installDeps * update tinyc paths --- tinyc/tests/vla_test.c | 84 -------------------------------------------------- 1 file changed, 84 deletions(-) delete mode 100644 tinyc/tests/vla_test.c (limited to 'tinyc/tests/vla_test.c') diff --git a/tinyc/tests/vla_test.c b/tinyc/tests/vla_test.c deleted file mode 100644 index 3616c46d4..000000000 --- a/tinyc/tests/vla_test.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Test that allocating a variable length array in a loop - * does not use up a linear amount of memory - */ - -#include -#include -#include - -#define LOOP_COUNT 1000 -#define ARRAY_SIZE 100 - -/* Overwrite a VLA. This will overwrite the return address if SP is incorrect */ -void smash(char *p, int n) { - memset(p, 0, n); -} - -int test1(int n) { - int i; - char *array_ptrs[LOOP_COUNT]; - - for (i = 0; i < LOOP_COUNT; ++i) { - char test[n]; - smash(test, n); - array_ptrs[i] = test; - } - - return (array_ptrs[0]-array_ptrs[LOOP_COUNT-1] < n) ? 0 : 1; -} - -/* ensure goto does not circumvent array free */ -int test2(int n) { - char *array_ptrs[LOOP_COUNT]; - - int i = 0; -loop:; - char test[n]; - smash(test, n); - if (i >= LOOP_COUNT) - goto end; - array_ptrs[i] = test; - ++i; - goto loop; - -end: - smash(test, n); - char test2[n]; - smash(test2, n); - return (array_ptrs[0] - array_ptrs[LOOP_COUNT-1] < n) ? 0 : 1; -} - -int test3(int n) { - char test[n]; - smash(test, n); - goto label; -label: - smash(test, n); - char test2[n]; - smash(test2, n); - return (test-test2 >= n) ? 0 : 1; -} - -#define RUN_TEST(t) \ - if (!testname || (strcmp(#t, testname) == 0)) { \ - fputs(#t "... ", stdout); \ - fflush(stdout); \ - if (t(ARRAY_SIZE) == 0) { \ - fputs("success\n", stdout); \ - } else { \ - fputs("failure\n", stdout); \ - retval = EXIT_FAILURE; \ - } \ - } - -int main(int argc, char **argv) { - const char *testname = NULL; - int retval = EXIT_SUCCESS; - if (argc > 1) - testname = argv[1]; - RUN_TEST(test1) - RUN_TEST(test2) - RUN_TEST(test3) - return retval; -} -- cgit 1.4.1-2-gfad0