Mercurial > hg > qcc
changeset 435:f16b04be31b6
Force "static" variables to be in global memory (grischka-2005-09-25 bugfix 5).
This patch was originally posted in grischka's 2005-09-25 email as a
"required fix" 5 to compile gcc 2.95. It was tweaked by
David A. Wheeler to merge the test case into the standard tcc test suite.
The test case was enhanced to ensure that multiple different static variables
with the same local name were mapped to different memory locations
(if they originated from different scopes).
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 02 May 2007 18:05:36 -0400 |
parents | 98a68386c5a6 |
children | 91152e505b77 |
files | tcc.c tests/tcctest.c |
diffstat | 2 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/tcc.c Wed May 02 17:18:07 2007 -0400 +++ b/tcc.c Wed May 02 18:05:36 2007 -0400 @@ -8422,6 +8422,7 @@ extern */ external_sym(v, &type, r); } else { + type.t |= (btype.t & VT_STATIC); // Retain "static". if (type.t & VT_STATIC) r |= VT_CONST; else
--- a/tests/tcctest.c Wed May 02 17:18:07 2007 -0400 +++ b/tests/tcctest.c Wed May 02 18:05:36 2007 -0400 @@ -80,6 +80,7 @@ void statement_expr_test(void); void asm_test(void); void builtin_test(void); +void static_test(void); int fib(int n); void num(int n); @@ -532,6 +533,7 @@ local_label_test(); asm_test(); builtin_test(); + static_test(); return 0; } @@ -2025,6 +2027,43 @@ } +/* static_stub1 takes a pointer to a function, and returns a pointer to + * a function; that function must accept no parameters, and return nothing. */ +void ((*static_stub1(void ((*p)(void)))) (void)) +{ + static void (*pfn)(void); + void (*mytemp)(void); + mytemp = pfn; + pfn = p; + return mytemp; +} + +/* Another stub. The static "pfn" is in a different function, so it'd better + not be mapped to the same memory location. */ +void ((*static_stub2(void ((*p)(void)))) (void)) +{ + static void (*pfn)(void); + void (*mytemp)(void); + mytemp = pfn; + pfn = p; + return mytemp; +} + + +void static_test(void) +{ + void (*result)(void); + result = static_stub1(static_test); + printf("static_test Expect 1 -> %d\n", result == 0); + result = static_stub1(static_test); + printf("static_test Expect 1 -> %d\n", result == static_test); + result = static_stub2(static_test); + printf("static_test Expect 1 -> %d\n", result == 0); + result = static_stub2(static_test); + printf("static_test Expect 1 -> %d\n", result == static_test); +} + + void const_func(const int a) { }