From 291898b46f46dd032ffbc07f36a701577d56da87 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 30 Aug 2024 21:45:37 +0900 Subject: [PATCH] [qfcc] Properly dup symbol for declaration The unification of qc and c function symbol handling made it important that the new symbol was a proper duplicate (minus being in a table) of the old symbol. This fixes redeclared prototypes (especially for qc-style functions, not encountered for c-style). Complete with unit test :) --- tools/qfcc/source/symtab.c | 2 ++ tools/qfcc/test/Makemodule.am | 11 +++++++++++ tools/qfcc/test/reproto.r | 8 ++++++++ 3 files changed, 21 insertions(+) create mode 100644 tools/qfcc/test/reproto.r diff --git a/tools/qfcc/source/symtab.c b/tools/qfcc/source/symtab.c index d50d9696f..5e6310ec2 100644 --- a/tools/qfcc/source/symtab.c +++ b/tools/qfcc/source/symtab.c @@ -260,6 +260,8 @@ declare_symbol (specifier_t spec, const expr_t *init, symtab_t *symtab) // due to the way declarations work, we need a new symbol at all times. // redelcarations will be checked later s = new_symbol (s->name); + *s = *spec.sym; + s->table = nullptr; } if (!spec.type_expr && !spec.is_function) { diff --git a/tools/qfcc/test/Makemodule.am b/tools/qfcc/test/Makemodule.am index 590c2f96c..216d66c30 100644 --- a/tools/qfcc/test/Makemodule.am +++ b/tools/qfcc/test/Makemodule.am @@ -57,6 +57,7 @@ test_progs_dat=\ tools/qfcc/test/motor-point.dat \ tools/qfcc/test/motor-xform.dat \ tools/qfcc/test/quaternion.dat \ + tools/qfcc/test/reproto.dat \ tools/qfcc/test/return-ivar.dat \ tools/qfcc/test/return-postop.dat \ tools/qfcc/test/sendv.dat \ @@ -692,6 +693,16 @@ tools/qfcc/test/quaternion.run: $(qfcc_test_run_deps) include $(quaternion_dep) # am--include-marker r_depfiles_remade += $(quaternion_dep) +tools_qfcc_test_reproto_dat_SOURCES=tools/qfcc/test/reproto.r +reproto_obj=$(tools_qfcc_test_reproto_dat_SOURCES:.r=.o) +reproto_dep=$(call qcautodep,$(tools_qfcc_test_reproto_dat_SOURCES)) +tools/qfcc/test/reproto.dat$(EXEEXT): $(reproto_obj) $(QFCC_DEP) + $(V_QFCCLD)$(QLINK) -o $@ $(reproto_obj) +tools/qfcc/test/reproto.run: $(qfcc_test_run_deps) + @$(top_srcdir)/tools/qfcc/test/build-run $@ +include $(reproto_dep) # am--include-marker +r_depfiles_remade += $(reproto_dep) + tools_qfcc_test_return_ivar_dat_SOURCES=tools/qfcc/test/return-ivar.r return_ivar_obj=$(tools_qfcc_test_return_ivar_dat_SOURCES:.r=.o) return_ivar_dep=$(call qcautodep,$(tools_qfcc_test_return_ivar_dat_SOURCES)) diff --git a/tools/qfcc/test/reproto.r b/tools/qfcc/test/reproto.r new file mode 100644 index 000000000..9384adaf0 --- /dev/null +++ b/tools/qfcc/test/reproto.r @@ -0,0 +1,8 @@ +float (entity targ) visible; +float (entity targ) visible; + +int +main (void) +{ + return 0; // to survive and prevail :) +}