[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.
This commit is contained in:
Bill Currie 2024-11-18 03:42:26 +09:00
parent 28e8697ae6
commit 13f25af881
4 changed files with 62 additions and 0 deletions

View file

@ -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);

View file

@ -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 $<

23
tools/qfcc/test/calluse.r Normal file
View file

@ -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;
}

View file

@ -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);
}