aboutsummaryrefslogtreecommitdiff
path: root/tccgen.c
diff options
context:
space:
mode:
authorThomas Preud'homme <robotux@celest.fr>2014-03-29 14:28:02 +0800
committerThomas Preud'homme <robotux@celest.fr>2014-03-29 14:46:26 +0800
commitb125743323f92b3492634cd875be820c890d5f29 (patch)
tree04a1ce3cdd3ce252b2aa22eabbd75d2c0cc0934a /tccgen.c
parent9a6ee577f6165dccfde424732bfc6f16f1e2811b (diff)
downloadtinycc-b125743323f92b3492634cd875be820c890d5f29.tar.gz
tinycc-b125743323f92b3492634cd875be820c890d5f29.tar.bz2
Create bcheck region for argv and arge argument
For program manipulating argv or arge as pointer with construct such as: (while *argv++) { do_something_with_argv; } it is necessary to have argv and arge inside a region. This patch create regions argv and arge) if main is declared with those parameters.
Diffstat (limited to 'tccgen.c')
-rw-r--r--tccgen.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/tccgen.c b/tccgen.c
index b4f97f4..fa03daf 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -5770,6 +5770,21 @@ static void gen_function(Sym *sym)
/* push a dummy symbol to enable local sym storage */
sym_push2(&local_stack, SYM_FIELD, 0, 0);
gfunc_prolog(&sym->type);
+#ifdef CONFIG_TCC_BCHECK
+ if (tcc_state->do_bound_check
+ && !strcmp(get_tok_str(sym->v, NULL), "main")) {
+ int i;
+
+ sym = local_stack;
+ for (i = 0, sym = local_stack; i < 2; i++, sym = sym->prev) {
+ if (sym->v & SYM_FIELD || sym->prev->v & SYM_FIELD)
+ break;
+ vpush_global_sym(&func_old_type, TOK___bound_main_arg);
+ vset(&sym->type, sym->r, sym->c);
+ gfunc_call(1);
+ }
+ }
+#endif
rsym = 0;
block(NULL, NULL, NULL, NULL, 0, 0);
gsym(rsym);