From 1205c935d00329ae5ae4f3f1e6373a74eaea8ce0 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 13 Jan 2021 16:47:49 +0900 Subject: [PATCH] [qfcc] Add failing test for static init The function local static init is being treated as a non-static init (ie, initialized each call). --- tools/qfcc/test/Makemodule.am | 11 +++++++++++ tools/qfcc/test/static-init.r | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tools/qfcc/test/static-init.r diff --git a/tools/qfcc/test/Makemodule.am b/tools/qfcc/test/Makemodule.am index 3eb33892b..f328fcb6e 100644 --- a/tools/qfcc/test/Makemodule.am +++ b/tools/qfcc/test/Makemodule.am @@ -36,6 +36,7 @@ test_progs_dat=\ tools/qfcc/test/return-ivar.dat \ tools/qfcc/test/sendv.dat \ tools/qfcc/test/state.dat \ + tools/qfcc/test/static-init.dat \ tools/qfcc/test/struct-init-param.dat \ tools/qfcc/test/struct-nil-init.dat \ tools/qfcc/test/structarray.dat \ @@ -411,6 +412,16 @@ tools/qfcc/test/state.run: $(qfcc_test_run_deps) include $(state_dep) # am--include-marker r_depfiles_remade += $(state_dep) +tools_qfcc_test_static_init_dat_SOURCES=tools/qfcc/test/static-init.r +static_init_obj=$(tools_qfcc_test_static_init_dat_SOURCES:.r=.o) +static_init_dep=$(call qcautodep,$(tools_qfcc_test_static_init_dat_SOURCES)) +tools/qfcc/test/static-init.dat$(EXEEXT): $(static_init_obj) $(QFCC_DEP) + $(V_QFCCLD)$(QLINK) -o $@ $(static_init_obj) +tools/qfcc/test/static-init.run: $(qfcc_test_run_deps) + @$(top_srcdir)/tools/qfcc/test/build-run $@ +include $(static_init_dep) # am--include-marker +r_depfiles_remade += $(static_init_dep) + tools_qfcc_test_struct_init_param_dat_SOURCES=tools/qfcc/test/struct-init-param.r struct_init_param_obj=$(tools_qfcc_test_struct_init_param_dat_SOURCES:.r=.o) struct_init_param_dep=$(call qcautodep,$(tools_qfcc_test_struct_init_param_dat_SOURCES)) diff --git a/tools/qfcc/test/static-init.r b/tools/qfcc/test/static-init.r new file mode 100644 index 000000000..bbbe3f9a7 --- /dev/null +++ b/tools/qfcc/test/static-init.r @@ -0,0 +1,19 @@ +#include "test-harness.h" + +int count_down () +{ + static int count = 2; + count--; + return count > 0; +} + +int main() +{ + int ret = 0; + count_down (); + if (count_down ()) { + printf ("did not reach 0\n"); + ret |= 1; + } + return ret; +}