scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 6d3d7af1e88c1e466579c95b6538d0f2c9bebd8a
parent 27f24349d56b76da526aa232dbb686ad792a055a
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 15 Mar 2022 15:26:55 +0100

cc2-qbe: Fix parameters handling

The fix in 688c9c87 that solved memory corruption problems
also modified the behaviour of the local symbol list.
It is simpler and it makes the target code independent
of the order in the list.

Diffstat:
Msrc/cmd/cc/cc2/target/qbe/cgen.c | 14++++++++++----
Msrc/cmd/cc/cc2/target/qbe/code.c | 6++++--
2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/cmd/cc/cc2/target/qbe/cgen.c b/src/cmd/cc/cc2/target/qbe/cgen.c @@ -432,19 +432,25 @@ function(void) Symbol *p; /* allocate stack space for parameters */ - for (p = locals; p && (p->type.flags & PARF) != 0; p = p->next) + for (p = locals; p; p = p->next) { + if ((p->type.flags & PARF) == 0) + continue; code(ASALLOC, label2node(&aux, p), NULL, NULL); + } /* allocate stack space for local variables) */ - for ( ; p && p->id != TMPSYM; p = p->next) { - if (p->kind != SAUTO) + for (p = locals; p; p = p->next) { + if ((p->type.flags & PARF) != 0) + continue; + if (p->kind != SAUTO || p->id == TMPSYM) continue; code(ASALLOC, label2node(&aux, p), NULL, NULL); } + /* store formal parameters in parameters */ for (p = locals; p; p = p->next) { if ((p->type.flags & PARF) == 0) - break; + continue; code(ASFORM, label2node(&aux, p), NULL, NULL); } return NULL; diff --git a/src/cmd/cc/cc2/target/qbe/code.c b/src/cmd/cc/cc2/target/qbe/code.c @@ -358,10 +358,12 @@ writeout(void) printf("function %s %s(", size2stack(&curfun->rtype), symname(curfun)); /* declare formal parameters */ - for (sep = "", p = locals; p; p = p->next, sep = ",") { + sep = ""; + for (p = locals; p; p = p->next) { if ((p->type.flags & PARF) == 0) - break; + continue; printf("%s%s %s.val", sep, size2stack(&p->type), symname(p)); + sep = ","; } printf("%s)\n{\n", (curfun->type.flags&ELLIPS) ? ", ..." : "");