diff --git a/tools/qfcc/source/statements.c b/tools/qfcc/source/statements.c index e569d0317..9251c97a1 100644 --- a/tools/qfcc/source/statements.c +++ b/tools/qfcc/source/statements.c @@ -1512,7 +1512,7 @@ remove_dead_blocks (sblock_t *blocks) static void check_final_block (sblock_t *sblock) { - statement_t *s; + statement_t *s = 0; symbol_t *return_symbol = 0; def_t *return_def = 0; operand_t *return_operand = 0; @@ -1531,6 +1531,12 @@ check_final_block (sblock_t *sblock) } if (current_func->sym->type->t.func.type != &type_void) warning (0, "control reaches end of non-void function"); + if (s && s->type >= st_func) { + // func and flow end blocks, so we need to add a new block to take the + // return + sblock->next = new_sblock (); + sblock = sblock->next; + } if (options.traditional || options.code.progsversion == PROG_ID_VERSION) { return_symbol = make_symbol (".return", &type_param, pr.symtab->space, sc_extern); diff --git a/tools/qfcc/test/Makefile.am b/tools/qfcc/test/Makefile.am index 1e2382d89..02fd98dbd 100644 --- a/tools/qfcc/test/Makefile.am +++ b/tools/qfcc/test/Makefile.am @@ -29,7 +29,8 @@ test_progs_dat=\ structlive.dat \ structptr.dat \ vecinit.dat \ - while.dat + while.dat \ + voidfor.dat fail_progs_dat=\ $E @@ -120,6 +121,13 @@ while.dat: $(while_obj) $(QFCC_DEP) while.run: Makefile build-run $(srcdir)/build-run $@ +voidfor_dat_SOURCES=voidfor.r +voidfor_obj=$(voidfor_dat_SOURCES:.r=.qfo) +voidfor.dat: $(voidfor_obj) $(QFCC_DEP) + $(QFCC) $(QCFLAGS) -o $@ $(voidfor_obj) +voidfor.run: Makefile build-run + $(srcdir)/build-run $@ + include ./$(DEPDIR)/*.Qo EXTRA_DIST= test-bi.h build-run diff --git a/tools/qfcc/test/voidfor.r b/tools/qfcc/test/voidfor.r new file mode 100644 index 000000000..1429bdbac --- /dev/null +++ b/tools/qfcc/test/voidfor.r @@ -0,0 +1,17 @@ +void bar () +{ +} + +void foo () +{ + int i; + + for (i = 0; i < 11; i++) + bar (); +} + +int main () +{ + foo (); + return 0; +}