From ce6b27cfae76b48c42878101eccb030864af34d2 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 13 May 2023 17:17:50 +0900 Subject: [PATCH] [qfcc] Add failing test for array life It seems that the optimizer keeps array assignments live when passing the array as a pointer, but not when passing the address of an element. Found when testing the following code: BasisBlade *pga_blades[16] = { blades[1], blades[2], blades[3], blades[4], blades[7], blades[6], blades[5], blades[0], blades[8], blades[9], blades[10], blades[15], blades[14], blades[13], blades[12], blades[11], }; BasisGroup *pga_groups[4] = { [BasisGroup new:4 basis:&pga_blades[ 0]], [BasisGroup new:4 basis:&pga_blades[ 4]], [BasisGroup new:4 basis:&pga_blades[ 8]], [BasisGroup new:4 basis:&pga_blades[12]], }; Only the first element of pga_blades is being assigned in the optimized code, but everything is correct when not optimizing. --- tools/qfcc/test/Makemodule.am | 11 +++++++++++ tools/qfcc/test/arraylife.r | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tools/qfcc/test/arraylife.r diff --git a/tools/qfcc/test/Makemodule.am b/tools/qfcc/test/Makemodule.am index faf0eb9bb..078fa5bfa 100644 --- a/tools/qfcc/test/Makemodule.am +++ b/tools/qfcc/test/Makemodule.am @@ -10,6 +10,7 @@ fail_bins= test_progs_dat=\ tools/qfcc/test/address-cast.dat \ tools/qfcc/test/alignment.dat \ + tools/qfcc/test/arraylife.dat \ tools/qfcc/test/assignchain.dat \ tools/qfcc/test/anonstruct.dat \ tools/qfcc/test/chewed-alias.dat \ @@ -157,6 +158,16 @@ tools/qfcc/test/anonstruct.run: $(qfcc_test_run_deps) include $(anonstruct_dep) # am--include-marker r_depfiles_remade += $(anonstruct_dep) +tools_qfcc_test_arraylife_dat_SOURCES=tools/qfcc/test/arraylife.r +arraylife_obj=$(tools_qfcc_test_arraylife_dat_SOURCES:.r=.o) +arraylife_dep=$(call qcautodep,$(tools_qfcc_test_arraylife_dat_SOURCES)) +tools/qfcc/test/arraylife.dat$(EXEEXT): $(arraylife_obj) $(QFCC_DEP) + $(V_QFCCLD)$(QLINK) -o $@ $(arraylife_obj) +tools/qfcc/test/arraylife.run: $(qfcc_test_run_deps) + @$(top_srcdir)/tools/qfcc/test/build-run $@ +include $(arraylife_dep) # am--include-marker +r_depfiles_remade += $(arraylife_dep) + tools_qfcc_test_assignchain_dat_SOURCES=tools/qfcc/test/assignchain.r assignchain_obj=$(tools_qfcc_test_assignchain_dat_SOURCES:.r=.o) assignchain_dep=$(call qcautodep,$(tools_qfcc_test_assignchain_dat_SOURCES)) diff --git a/tools/qfcc/test/arraylife.r b/tools/qfcc/test/arraylife.r new file mode 100644 index 000000000..7df0ea8a8 --- /dev/null +++ b/tools/qfcc/test/arraylife.r @@ -0,0 +1,20 @@ +vector +bar (float *v) +{ + return [v[0], v[1], v[2]]; +} + +vector +foo (float x, float y, float z) +{ + float v[3] = { x, y, z }; + return bar (&v[0]); +} + +int +main () +{ + int ret = 0; + ret |= foo(1,2,3) != [1, 2, 3]; + return ret; +}