[qfcc] Add failing test for lost var use

Storing a variable into a dereference pointer (*p = x) is not marking
the variable as used (due to a mistake while converting to Ruamoko
statement format) resulting in assignments to that variable being
dropped due to it being a dead assignment as the assignment to the
variable and the storing need to be in separate basic blocks (thus the
call in the test, though an if would have worked, I think) for the bug
to trigger.
This commit is contained in:
Bill Currie 2022-01-23 01:31:50 +09:00
parent ec5830f70b
commit b6093e0728
2 changed files with 40 additions and 0 deletions

View file

@ -31,6 +31,7 @@ test_progs_dat=\
tools/qfcc/test/infloop.dat \
tools/qfcc/test/ivar-struct-return.dat \
tools/qfcc/test/link_order.dat \
tools/qfcc/test/lost-use.dat \
tools/qfcc/test/methodparams.dat \
tools/qfcc/test/modulo.dat \
tools/qfcc/test/nilparamret.dat \
@ -386,6 +387,16 @@ tools/qfcc/test/link_order.run: $(qfcc_test_run_deps)
include $(link_order_dep) # am--include-marker
r_depfiles_remade += $(link_order_dep)
tools_qfcc_test_lost_use_dat_SOURCES=tools/qfcc/test/lost-use.r
lost_use_obj=$(tools_qfcc_test_lost_use_dat_SOURCES:.r=.o)
lost_use_dep=$(call qcautodep,$(tools_qfcc_test_lost_use_dat_SOURCES))
tools/qfcc/test/lost-use.dat$(EXEEXT): $(lost_use_obj) $(QFCC_DEP)
$(V_QFCCLD)$(QLINK) -o $@ $(lost_use_obj)
tools/qfcc/test/lost-use.run: $(qfcc_test_run_deps)
@$(top_srcdir)/tools/qfcc/test/build-run $@
include $(lost_use_dep) # am--include-marker
r_depfiles_remade += $(lost_use_dep)
tools_qfcc_test_methodparams_dat_SOURCES=tools/qfcc/test/methodparams.r
methodparams_obj=$(tools_qfcc_test_methodparams_dat_SOURCES:.r=.o)
methodparams_dep=$(call qcautodep,$(tools_qfcc_test_methodparams_dat_SOURCES))

View file

@ -0,0 +1,29 @@
void printf (string fmt, ...) = #0;
int getval(void)
{
return 42;
}
void magic (void)
{
}
void storeval (int *p)
{
int x = getval ();
magic ();
*p = x;
}
int val;
int
main(void)
{
storeval (&val);
if (val != 42) {
printf ("val is dead: %d\n", val);
return 1;
}
return 0;
}