From be4c3a82a2e120859c0eee641c7309bf3b67b977 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 8 Jun 2019 19:25:25 +0900 Subject: [PATCH] Detect redefinitions of structs and unions While the redefinition was being detected, it was misreported as the tag being wrong, and on the wrong line, too. --- tools/qfcc/source/qc-parse.y | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index 3e05a55e5..15edcb0ee 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -584,8 +584,13 @@ struct_specifier { symbol_t *sym; sym = find_struct ($1, $2, 0); - if (!sym->table) + if (!sym->table) { symtab_addsymbol (current_symtab, sym); + } else { + error (0, "%s %s redefined", $1 == 's' ? "struct" : "union", + $2->name); + $1 = 0; + } current_symtab = new_symtab (current_symtab, stab_local); } struct_defs '}' @@ -594,10 +599,12 @@ struct_specifier symtab_t *symtab = current_symtab; current_symtab = symtab->parent; - sym = build_struct ($1, $2, symtab, 0); - $$ = make_spec (sym->type, 0, 0, 0); - if (!sym->table) - symtab_addsymbol (current_symtab, sym); + if ($1) { + sym = build_struct ($1, $2, symtab, 0); + $$ = make_spec (sym->type, 0, 0, 0); + if (!sym->table) + symtab_addsymbol (current_symtab, sym); + } } | STRUCT tag {