[qfcc] Add a test for use/write dependencies

I ran into this with frikbot causing an infinite loop due to incorrectly
linked objects.
This commit is contained in:
Bill Currie 2021-12-27 14:17:12 +09:00
parent 44dd183d55
commit 4ad84b3786
2 changed files with 55 additions and 0 deletions

View file

@ -30,6 +30,7 @@ test_progs_dat=\
tools/qfcc/test/gcd.dat \
tools/qfcc/test/infloop.dat \
tools/qfcc/test/ivar-struct-return.dat \
tools/qfcc/test/link_order.dat \
tools/qfcc/test/methodparams.dat \
tools/qfcc/test/modulo.dat \
tools/qfcc/test/nilparamret.dat \
@ -370,6 +371,16 @@ tools/qfcc/test/ivar-struct-return.run: $(qfcc_test_run_deps)
include $(ivar_struct_return_dep) # am--include-marker
r_depfiles_remade += $(ivar_struct_return_dep)
tools_qfcc_test_link_order_dat_SOURCES=tools/qfcc/test/link_order.r
link_order_obj=$(tools_qfcc_test_link_order_dat_SOURCES:.r=.o)
link_order_dep=$(call qcautodep,$(tools_qfcc_test_link_order_dat_SOURCES))
tools/qfcc/test/link_order.dat$(EXEEXT): $(link_order_obj) $(QFCC_DEP)
$(V_QFCCLD)$(QLINK) -o $@ $(link_order_obj)
tools/qfcc/test/link_order.run: $(qfcc_test_run_deps)
@$(top_srcdir)/tools/qfcc/test/build-run $@
include $(link_order_dep) # am--include-marker
r_depfiles_remade += $(link_order_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,44 @@
#pragma bug die
#include "test-harness.h"
typedef struct link_s {
int something;
struct link_s *next;
} link_t;
link_t *
link_objs(link_t **array, int count)
{
link_t *obj = nil, *o;
while (count-- > 0) {
o = array[count];
o.next = obj;
obj = o;
}
return obj;
}
link_t link_a;
link_t link_b;
link_t *links[2];
int
main ()
{
links[0] = &link_a;
links[1] = &link_b;
link_t *chain = link_objs (links, 2);
if (chain != &link_a) {
printf ("chain doesn't point to link_a\n");
return 1;
}
if (chain.next != &link_b) {
printf ("chain.next doesn't point to link_b\n");
return 1;
}
if (chain.next.next != nil) {
printf ("chain.next.next isn't nil\n");
return 1;
}
return 0;
}