commit b3ac2d6c35ab05cde378a4f0b625123e9bc9306a
parent f124441bbf6a16824334f195bb5bec268a55eefa
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:
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) ? ", ..." : "");