From 13f25af881efef43a8e5faaa873037a90a9c5f5b Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 18 Nov 2024 03:42:26 +0900 Subject: [PATCH] [qfcc] Use the called function for ruamoko progs This was a nasty one to find as it was the unary expression rewrite that triggered the bug (by causing tighter if tests to be generated, which surprised me: I wasn't even trying for better if tests). I'm actually not sure why things worked at all, but this fixes the crashes and other weird behavior resulting from calls to performSelector. Two tests are included because I found a separate bug (not fixed yet, tested by calluse2) while getting the calluse test working. --- tools/qfcc/source/flow.c | 1 + tools/qfcc/test/Makemodule.am | 15 +++++++++++++++ tools/qfcc/test/calluse.r | 23 +++++++++++++++++++++++ tools/qfcc/test/calluse2.r | 23 +++++++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 tools/qfcc/test/calluse.r create mode 100644 tools/qfcc/test/calluse2.r diff --git a/tools/qfcc/source/flow.c b/tools/qfcc/source/flow.c index 1e34d2ceb..b8f6ee885 100644 --- a/tools/qfcc/source/flow.c +++ b/tools/qfcc/source/flow.c @@ -1745,6 +1745,7 @@ flow_analyze_statement (statement_t *s, set_t *use, set_t *def, set_t *kill, if (operands && s->opc->op_type != op_value) { operands[0] = s->opc; } + flow_add_op_var (use, s->opa, 1); } else if (strncmp (s->opcode, "call", 4) == 0) { calln = s->opcode[4] - '0'; flow_add_op_var (use, s->opa, 1); diff --git a/tools/qfcc/test/Makemodule.am b/tools/qfcc/test/Makemodule.am index 4c57e56a4..bc997def1 100644 --- a/tools/qfcc/test/Makemodule.am +++ b/tools/qfcc/test/Makemodule.am @@ -16,6 +16,7 @@ test_progs_dat=\ tools/qfcc/test/arraytypedef.dat \ tools/qfcc/test/assignchain.dat \ tools/qfcc/test/anonstruct.dat \ + tools/qfcc/test/calluse.dat \ tools/qfcc/test/chewed-alias.dat \ tools/qfcc/test/chewed-return.dat \ tools/qfcc/test/comma-expr.dat \ @@ -91,6 +92,7 @@ test_progs_dat=\ fail_progs_dat= test_build_passes=\ + tools/qfcc/test/calluse2.r \ tools/qfcc/test/motor.r \ tools/qfcc/test/typeredef1.r \ tools/qfcc/test/typeredef2.r @@ -231,6 +233,16 @@ tools/qfcc/test/assignchain.run: $(qfcc_test_run_deps) include $(assignchain_dep) # am--include-marker r_depfiles_remade += $(assignchain_dep) +tools_qfcc_test_calluse_dat_SOURCES=tools/qfcc/test/calluse.r +calluse_obj=$(tools_qfcc_test_calluse_dat_SOURCES:.r=.o) +calluse_dep=$(call qcautodep,$(tools_qfcc_test_calluse_dat_SOURCES)) +tools/qfcc/test/calluse.dat$(EXEEXT): $(calluse_obj) $(QFCC_DEP) + $(V_QFCCLD)$(QLINK) -o $@ $(calluse_obj) +tools/qfcc/test/calluse.run: $(qfcc_test_run_deps) + @$(top_srcdir)/tools/qfcc/test/build-run $@ +include $(calluse_dep) # am--include-marker +r_depfiles_remade += $(calluse_dep) + tools_qfcc_test_chewed_alias_dat_SOURCES=tools/qfcc/test/chewed-alias.r chewed_alias_obj=$(tools_qfcc_test_chewed_alias_dat_SOURCES:.r=.o) chewed_alias_dep=$(call qcautodep,$(tools_qfcc_test_chewed_alias_dat_SOURCES)) @@ -389,6 +401,9 @@ tools/qfcc/test/double-float-compare.run$(EXEEXT): tools/qfcc/test/double-float- tools/qfcc/test/shadow-param.run$(EXEEXT): tools/qfcc/test/shadow-param.r $(qfcc_fail_run_deps) @$(top_srcdir)/tools/qfcc/test/build-compile-fail-run $@ $(QFCC) $(QCFLAGS) $< +tools/qfcc/test/calluse2.run$(EXEEXT): tools/qfcc/test/calluse2.r $(qfcc_comp_run_deps) + @$(top_srcdir)/tools/qfcc/test/build-compile-pass-run $@ $(QFCC) $(QCFLAGS) -c $< + tools/qfcc/test/motor.run$(EXEEXT): tools/qfcc/test/motor.r $(qfcc_comp_run_deps) @$(top_srcdir)/tools/qfcc/test/build-compile-pass-run $@ $(QFCC) $(QCFLAGS) -c $< diff --git a/tools/qfcc/test/calluse.r b/tools/qfcc/test/calluse.r new file mode 100644 index 000000000..50b457da4 --- /dev/null +++ b/tools/qfcc/test/calluse.r @@ -0,0 +1,23 @@ +id func (id self, SEL bar, ...) +{ + return (id)1; +} + +IMP get_func () +{ + return func; +} + +id foo (IMP msg) +{ + if (!(msg = get_func ())) { + return nil; + } + return msg(nil, nil); +} + +int +main() +{ + return foo (nil) == nil; +} diff --git a/tools/qfcc/test/calluse2.r b/tools/qfcc/test/calluse2.r new file mode 100644 index 000000000..b517f3f94 --- /dev/null +++ b/tools/qfcc/test/calluse2.r @@ -0,0 +1,23 @@ +id func (id self, SEL bar, ...) +{ + return (id)1; +} + +IMP get_func () +{ + return func; +} + +id foo (IMP msg) +{ + if (!(msg = get_func ())) { + return nil; + } + return msg(nil, nil); +} + +int +main() +{ + return !foo (nil); +}