From 3d8ee5df438afb41b5a71739d5c8eb3cb4bf97a9 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 3 Feb 2022 16:33:42 +0900 Subject: [PATCH] [qfcc] Ensure ops on globals occur before return This fixes the return-postop test, and covers calls, too. --- tools/qfcc/source/dags.c | 14 +++++++++++++- tools/qfcc/test/Makemodule.am | 3 +-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/qfcc/source/dags.c b/tools/qfcc/source/dags.c index d2f746962..6c787fdc6 100644 --- a/tools/qfcc/source/dags.c +++ b/tools/qfcc/source/dags.c @@ -462,7 +462,8 @@ dagnode_set_edges (dag_t *dag, dagnode_t *n, statement_t *s) if (n->type == st_func) { const char *num_params = 0; int first_param = 0; - flowvar_t **flowvars = dag->flownode->graph->func->vars; + function_t *func = dag->flownode->graph->func; + flowvar_t **flowvars = func->vars; if (!strcmp (n->label->opcode, "call")) { // nothing to do @@ -482,6 +483,17 @@ dagnode_set_edges (dag_t *dag, dagnode_t *n, statement_t *s) } label->live = 1; } + // ensure all operantions on global variables are completed before + // the st_func statement executes + for (set_iter_t *g = set_first (func->global_vars); g; + g = set_next (g)) { + flowvar_t *var = flowvars[g->element]; + dagnode_t *gn = dag_node (var->op); + if (gn) { + set_add (n->edges, gn->number); + set_remove (gn->edges, n->number); + } + } if (num_params && isdigit (*num_params)) { for (i = first_param; i < *num_params - '0'; i++) { flowvar_t *var = flowvars[i + 1]; diff --git a/tools/qfcc/test/Makemodule.am b/tools/qfcc/test/Makemodule.am index c82d750c4..f5111177e 100644 --- a/tools/qfcc/test/Makemodule.am +++ b/tools/qfcc/test/Makemodule.am @@ -68,8 +68,7 @@ test_progs_dat=\ tools/qfcc/test/while.dat \ tools/qfcc/test/zerolinker.dat -fail_progs_dat=\ - tools/qfcc/test/return-postop.dat +fail_progs_dat= test_build_errors=\ tools/qfcc/test/classarray.r \