Mercurial > hg > tinycc
diff tests/tcctest.c @ 450:cd7e1ce83b92
Implement alloca for x86 (grischka case_8).
This implements alloca() on x86, at least for non-Windows.
Unlike the grischka version, this patch handles both the bounded and
non-bounded cases (when bounded, the alloca'd memory is covered), and
when asked to allocate with 0 size, it returns 0 without any allocation.
Modify the assembly files to adjust the amount of padding (the unused space
after an allocation); this must be at least 1 for bounds-checking. It's
recommended that the padding be identical for unchecked and bounded cases,
because otherwise turning on bound-checking might change errors to non-errors.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 12 May 2007 00:20:07 -0400 |
parents | eff8bc296c57 |
children | 43ba14a107b0 |
line wrap: on
line diff
--- a/tests/tcctest.c Sat May 12 00:15:39 2007 -0400 +++ b/tests/tcctest.c Sat May 12 00:20:07 2007 -0400 @@ -2,6 +2,8 @@ * TCC auto test program */ #include "config.h" +#include <alloca.h> + #if GCC_MAJOR >= 3 @@ -74,6 +76,7 @@ void whitespace_test(void); void relocation_test(void); void old_style_function(void); +void alloca_test(void); void sizeof_test(void); void typeof_test(void); void local_label_test(void); @@ -537,6 +540,7 @@ whitespace_test(); relocation_test(); old_style_function(); + alloca_test(); sizeof_test(); typeof_test(); statement_expr_test(); @@ -1889,6 +1893,37 @@ decl_func2(NULL); } + +void alloca_test1() +{ + char *p = alloca(1); + *p = 0; +} + +void alloca_test2() +{ + char *p = alloca(2000); + p += 2000; + p--; + *p = 0; +} + +void alloca_test() +{ + char *p = alloca(16); + strcpy(p,"123456789012345"); + printf("p is %s\n", p); + + char *demo = "This is a test. This is only a test.\n"; + + /* Test alloca embedded in a larger expression */ + printf("Test: %s\n", strcpy(alloca(strlen(demo)+1),demo) ); + + alloca_test2(); + alloca_test1(); +} + + void sizeof_test(void) { int a;