From 94b2f5705c62f16e0bbbd755e93049c831891a4c Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Mon, 17 Dec 2012 15:34:52 +0100 Subject: [PATCH] cleanup: Resolve warnings about shadowed variables. --- ast2firm.c | 23 ++++---- diagnostic.c | 6 +-- main.c | 71 ++++++++++--------------- parser.c | 142 ++++++++++++++++++++++++------------------------- preprocessor.c | 25 +++++---- 5 files changed, 123 insertions(+), 144 deletions(-) diff --git a/ast2firm.c b/ast2firm.c index 8a52156..c0018ba 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -136,11 +136,8 @@ static void enqueue_inner_function(entity_t *entity) static ir_node *uninitialized_local_var(ir_graph *irg, ir_mode *mode, int pos) { const entity_t *entity = get_irg_loc_description(irg, pos); - - if (entity != NULL) { - position_t const *const pos = &entity->base.pos; - warningf(WARN_UNINITIALIZED, pos, "'%N' might be used uninitialized", entity); - } + if (entity) + warningf(WARN_UNINITIALIZED, &entity->base.pos, "'%N' might be used uninitialized", entity); return new_r_Unknown(irg, mode); } @@ -604,15 +601,15 @@ static ir_type *create_compound_type(compound_type_t *const type, bool const inc symbol_t *symbol = entry->base.symbol; type_t *entry_type = entry->declaration.type; - ident *ident; + ident *member_id; if (symbol == NULL) { /* anonymous bitfield member, skip */ if (entry->compound_member.bitfield) continue; assert(is_type_compound(entry_type)); - ident = id_unique("anon.%u"); + member_id = id_unique("anon.%u"); } else { - ident = new_id_from_str(symbol->string); + member_id = new_id_from_str(symbol->string); } dbg_info *dbgi = get_dbg_info(&entry->base.pos); @@ -623,7 +620,7 @@ static ir_type *create_compound_type(compound_type_t *const type, bool const inc } else { entry_irtype = get_ir_type(entry_type); } - ir_entity *entity = new_d_entity(irtype, ident, entry_irtype, dbgi); + ir_entity *entity = new_d_entity(irtype, member_id, entry_irtype, dbgi); set_entity_offset(entity, entry->compound_member.offset); set_entity_offset_bits_remainder(entity, @@ -4723,12 +4720,12 @@ static void create_variable_initializer(entity_t *entity) && get_entity_owner(irentity) != get_tls_type()) { add_entity_linkage(irentity, IR_LINKAGE_CONSTANT); } - ir_initializer_t *initializer = create_initializer_compound(2); + ir_initializer_t *complex_init = create_initializer_compound(2); ir_initializer_t *reali = create_initializer_const(real); - set_initializer_compound_value(initializer, 0, reali); + set_initializer_compound_value(complex_init, 0, reali); ir_initializer_t *imagi = create_initializer_const(imag); - set_initializer_compound_value(initializer, 1, imagi); - set_entity_initializer(irentity, initializer); + set_initializer_compound_value(complex_init, 1, imagi); + set_entity_initializer(irentity, complex_init); } return; } else if (!is_type_scalar(init_type)) { diff --git a/diagnostic.c b/diagnostic.c index 182b085..6c9739c 100644 --- a/diagnostic.c +++ b/diagnostic.c @@ -126,9 +126,9 @@ done_flags:; } case 'X': { - unsigned int const val = va_arg(ap, unsigned int); - char const *const fmt = flag_zero ? "%0*X" : "%*X"; - fprintf(stderr, fmt, field_width, val); + unsigned int const val = va_arg(ap, unsigned int); + char const *const xfmt = flag_zero ? "%0*X" : "%*X"; + fprintf(stderr, xfmt, field_width, val); break; } diff --git a/main.c b/main.c index eb3ff51..9c8b0c3 100644 --- a/main.c +++ b/main.c @@ -976,19 +976,19 @@ static void init_types_and_adjust(void) atomic_type_properties_t *props = atomic_type_properties; /* adjust types as requested by target architecture */ - ir_type *type_long_double = be_params->type_long_double; - if (type_long_double != NULL) { - set_typeprops_type(&props[ATOMIC_TYPE_LONG_DOUBLE], type_long_double); - atomic_modes[ATOMIC_TYPE_LONG_DOUBLE] = get_type_mode(type_long_double); + ir_type *const type_ld = be_params->type_long_double; + if (type_ld) { + set_typeprops_type(&props[ATOMIC_TYPE_LONG_DOUBLE], type_ld); + atomic_modes[ATOMIC_TYPE_LONG_DOUBLE] = get_type_mode(type_ld); } - ir_type *type_long_long = be_params->type_long_long; - if (type_long_long != NULL) - set_typeprops_type(&props[ATOMIC_TYPE_LONGLONG], type_long_long); + ir_type *const type_ll = be_params->type_long_long; + if (type_ll) + set_typeprops_type(&props[ATOMIC_TYPE_LONGLONG], type_ll); - ir_type *type_unsigned_long_long = be_params->type_unsigned_long_long; - if (type_unsigned_long_long != NULL) - set_typeprops_type(&props[ATOMIC_TYPE_ULONGLONG], type_unsigned_long_long); + ir_type *const type_ull = be_params->type_unsigned_long_long; + if (type_ull) + set_typeprops_type(&props[ATOMIC_TYPE_ULONGLONG], type_ull); /* operating system ABI specifics */ if (firm_is_darwin_os(target_machine)) { @@ -1033,14 +1033,14 @@ static void init_types_and_adjust(void) props[ATOMIC_TYPE_WCHAR_T] = props[wchar_atomic_kind]; /* initialize defaults for unsupported types */ - if (type_long_long == NULL) { + if (!type_ll) { copy_typeprops(&props[ATOMIC_TYPE_LONGLONG], &props[ATOMIC_TYPE_LONG]); } - if (type_unsigned_long_long == NULL) { + if (!type_ull) { copy_typeprops(&props[ATOMIC_TYPE_ULONGLONG], &props[ATOMIC_TYPE_ULONG]); } - if (type_long_double == NULL) { + if (!type_ld) { copy_typeprops(&props[ATOMIC_TYPE_LONG_DOUBLE], &props[ATOMIC_TYPE_DOUBLE]); } @@ -1264,13 +1264,11 @@ static int compilation_loop(compile_mode_t mode, compilation_unit_t *units, again: switch (unit->type) { case COMPILATION_UNIT_IR: { - bool res = open_input(unit); - if (!res) { + if (!open_input(unit)) { result = EXIT_FAILURE; break; } - res = !ir_import_file(unit->input, unit->name); - if (!res) { + if (ir_import_file(unit->input, unit->name)) { position_t const pos = { inputname, 0, 0, 0 }; errorf(&pos, "import of firm graph failed"); result = EXIT_FAILURE; @@ -1283,8 +1281,7 @@ again: if (external_preprocessor == NULL) { panic("preprocessed assembler not possible with internal preprocessor yet"); } - bool res = run_external_preprocessor(unit); - if (!res) { + if (!run_external_preprocessor(unit)) { result = EXIT_FAILURE; break; } @@ -1306,8 +1303,7 @@ again: case COMPILATION_UNIT_C: case COMPILATION_UNIT_CXX: if (external_preprocessor != NULL) { - bool res = run_external_preprocessor(unit); - if (!res) { + if (!run_external_preprocessor(unit)) { result = EXIT_FAILURE; break; } @@ -1317,16 +1313,14 @@ again: case COMPILATION_UNIT_PREPROCESSED_C: case COMPILATION_UNIT_PREPROCESSED_CXX: { - bool res = open_input(unit); - if (!res) { + if (!open_input(unit)) { result = EXIT_FAILURE; break; } init_tokens(); if (mode == PreprocessOnly) { - bool res = output_preprocessor_tokens(unit, out); - if (!res) { + if (!output_preprocessor_tokens(unit, out)) { result = EXIT_FAILURE; break; } @@ -1780,8 +1774,7 @@ int main(int argc, char **argv) streq(opt, "stack-protector-all")) { fprintf(stderr, "ignoring gcc option '-f%s'\n", orig_opt); } else { - int res = firm_option(orig_opt); - if (res == 0) { + if (firm_option(orig_opt) == 0) { errorf(NULL, "unknown Firm option '-f%s'", orig_opt); argument_errors = true; continue; @@ -1796,8 +1789,7 @@ int main(int argc, char **argv) fprintf(stderr, "warning: -bhelp is deprecated (use --help-firm)\n"); help |= HELP_FIRM; } else { - int res = be_parse_arg(opt); - if (res == 0) { + if (be_parse_arg(opt) == 0) { errorf(NULL, "unknown Firm backend option '-b %s'", opt); argument_errors = true; } else if (strstart(opt, "isa=")) { @@ -1872,14 +1864,12 @@ int main(int argc, char **argv) } else if (strstart(opt, "tune=")) { GET_ARG_AFTER(opt, "-mtune="); snprintf(arch_opt, sizeof(arch_opt), "%s-opt=%s", cpu_arch, opt); - int res = be_parse_arg(arch_opt); - if (res == 0) + if (be_parse_arg(arch_opt) == 0) argument_errors = true; } else if (strstart(opt, "cpu=")) { GET_ARG_AFTER(opt, "-mcpu="); snprintf(arch_opt, sizeof(arch_opt), "%s-arch=%s", cpu_arch, opt); - int res = be_parse_arg(arch_opt); - if (res == 0) + if (be_parse_arg(arch_opt) == 0) argument_errors = true; } else if (strstart(opt, "fpmath=")) { GET_ARG_AFTER(opt, "-mfpmath="); @@ -1893,15 +1883,13 @@ int main(int argc, char **argv) } if (!argument_errors) { snprintf(arch_opt, sizeof(arch_opt), "%s-fpunit=%s", cpu_arch, opt); - int res = be_parse_arg(arch_opt); - if (res == 0) + if (be_parse_arg(arch_opt) == 0) argument_errors = true; } } else if (strstart(opt, "preferred-stack-boundary=")) { GET_ARG_AFTER(opt, "-mpreferred-stack-boundary="); snprintf(arch_opt, sizeof(arch_opt), "%s-stackalign=%s", cpu_arch, opt); - int res = be_parse_arg(arch_opt); - if (res == 0) + if (be_parse_arg(arch_opt) == 0) argument_errors = true; } else if (streq(opt, "rtd")) { default_calling_convention = CC_STDCALL; @@ -1911,8 +1899,7 @@ int main(int argc, char **argv) } else if (streq(opt, "soft-float")) { add_flag(&ldflags_obst, "-msoft-float"); snprintf(arch_opt, sizeof(arch_opt), "%s-fpunit=softfloat", cpu_arch); - int res = be_parse_arg(arch_opt); - if (res == 0) + if (be_parse_arg(arch_opt) == 0) argument_errors = true; } else if (streq(opt, "sse2")) { /* ignore for now, our x86 backend always uses sse when @@ -2274,11 +2261,11 @@ int main(int argc, char **argv) /* link program file */ if (mode == CompileAssembleLink) { - int result = link_program(units); - if (result != EXIT_SUCCESS) { + int const link_result = link_program(units); + if (link_result != EXIT_SUCCESS) { if (out != stdout) unlink(outname); - return result; + return link_result; } } diff --git a/parser.c b/parser.c index f742f33..95a204f 100644 --- a/parser.c +++ b/parser.c @@ -4145,13 +4145,13 @@ static void parser_error_multiple_definition(entity_t *entity, errorf(pos, "redefinition of '%N' (declared %P)", entity, &entity->base.pos); } -static bool is_declaration_specifier(const token_t *token) +static bool is_declaration_specifier(token_t const *const tk) { - switch (token->kind) { + switch (tk->kind) { DECLARATION_START return true; case T_IDENTIFIER: - return is_typedef_symbol(token->base.symbol); + return is_typedef_symbol(tk->base.symbol); default: return false; @@ -5213,42 +5213,42 @@ static void parse_external_declaration(void) return; } - assert(is_declaration(ndeclaration)); - type_t *const orig_type = ndeclaration->declaration.type; - type_t * type = skip_typeref(orig_type); + { + assert(is_declaration(ndeclaration)); + type_t *const orig_type = ndeclaration->declaration.type; + type_t *const type = skip_typeref(orig_type); - if (!is_type_function(type)) { - if (is_type_valid(type)) { - errorf(HERE, "declarator '%#N' has a body but is not a function type", ndeclaration); + if (!is_type_function(type)) { + if (is_type_valid(type)) { + errorf(HERE, "declarator '%#N' has a body but is not a function type", ndeclaration); + } + eat_block(); + return; } - eat_block(); - return; - } - position_t const *const pos = &ndeclaration->base.pos; - if (is_typeref(orig_type)) { - /* §6.9.1:2 */ - errorf(pos, "type of function definition '%#N' is a typedef", ndeclaration); - } - - if (is_type_compound(skip_typeref(type->function.return_type))) { - warningf(WARN_AGGREGATE_RETURN, pos, "'%N' returns an aggregate", ndeclaration); - } - if (type->function.unspecified_parameters) { - warningf(WARN_OLD_STYLE_DEFINITION, pos, "old-style definition of '%N'", ndeclaration); - } else { - warningf(WARN_TRADITIONAL, pos, "traditional C rejects ISO C style definition of '%N'", ndeclaration); - } + position_t const *const pos = &ndeclaration->base.pos; + if (is_typeref(orig_type)) { + /* §6.9.1:2 */ + errorf(pos, "type of function definition '%#N' is a typedef", ndeclaration); + } - /* §6.7.5.3:14 a function definition with () means no - * parameters (and not unspecified parameters) */ - if (type->function.unspecified_parameters && - type->function.parameters == NULL) { - type_t *copy = duplicate_type(type); - copy->function.unspecified_parameters = false; - type = identify_new_type(copy); + if (is_type_compound(skip_typeref(type->function.return_type))) { + warningf(WARN_AGGREGATE_RETURN, pos, "'%N' returns an aggregate", ndeclaration); + } + if (type->function.unspecified_parameters) { + warningf(WARN_OLD_STYLE_DEFINITION, pos, "old-style definition of '%N'", ndeclaration); + } else { + warningf(WARN_TRADITIONAL, pos, "traditional C rejects ISO C style definition of '%N'", ndeclaration); + } - ndeclaration->declaration.type = type; + /* §6.7.5.3:14 a function definition with () means no + * parameters (and not unspecified parameters) */ + if (type->function.unspecified_parameters && + type->function.parameters == NULL) { + type_t *copy = duplicate_type(type); + copy->function.unspecified_parameters = false; + ndeclaration->declaration.type = identify_new_type(copy); + } } entity_t *const entity = record_entity(ndeclaration, true); @@ -5307,8 +5307,7 @@ static void parse_external_declaration(void) walk_statements(body, check_unreachable, NULL); if (noreturn_candidate && !(function->base.modifiers & DM_NORETURN)) { - position_t const *const pos = &body->base.pos; - warningf(WARN_MISSING_NORETURN, pos, "function '%#N' is candidate for attribute 'noreturn'", entity); + warningf(WARN_MISSING_NORETURN, &body->base.pos, "function '%#N' is candidate for attribute 'noreturn'", entity); } } @@ -5500,11 +5499,10 @@ static void parse_compound_declarators(compound_t *compound, add_anchor_token(','); do { entity_t *entity; - if (token.kind == ':') { /* anonymous bitfield */ type_t *type = specifiers->type; - entity_t *const entity = allocate_entity_zero(ENTITY_COMPOUND_MEMBER, NAMESPACE_NORMAL, NULL, HERE); + entity = allocate_entity_zero(ENTITY_COMPOUND_MEMBER, NAMESPACE_NORMAL, NULL, HERE); entity->declaration.declared_storage_class = STORAGE_CLASS_NONE; entity->declaration.storage_class = STORAGE_CLASS_NONE; entity->declaration.type = type; @@ -5520,52 +5518,50 @@ static void parse_compound_declarators(compound_t *compound, handle_entity_attributes(attributes, entity); } entity->declaration.attributes = attributes; - - append_entity(&compound->members, entity); } else { - entity = parse_declarator(specifiers, - DECL_MAY_BE_ABSTRACT | DECL_CREATE_COMPOUND_MEMBER); + entity = parse_declarator(specifiers, DECL_MAY_BE_ABSTRACT | DECL_CREATE_COMPOUND_MEMBER); position_t const *const pos = &entity->base.pos; if (entity->kind == ENTITY_TYPEDEF) { errorf(pos, "typedef not allowed as compound member"); - } else { - assert(entity->kind == ENTITY_COMPOUND_MEMBER); - - /* make sure we don't define a symbol multiple times */ - symbol_t *symbol = entity->base.symbol; - if (symbol != NULL) { - entity_t *prev = find_compound_entry(compound, symbol); - if (prev != NULL) { - position_t const *const ppos = &prev->base.pos; - errorf(pos, "multiple declarations of '%N' (declared %P)", entity, ppos); - } + continue; + } + + assert(entity->kind == ENTITY_COMPOUND_MEMBER); + + /* make sure we don't define a symbol multiple times */ + symbol_t *symbol = entity->base.symbol; + if (symbol != NULL) { + entity_t *prev = find_compound_entry(compound, symbol); + if (prev != NULL) { + position_t const *const ppos = &prev->base.pos; + errorf(pos, "multiple declarations of '%N' (declared %P)", entity, ppos); } + } - if (token.kind == ':') { - parse_bitfield_member(entity); + if (token.kind == ':') { + parse_bitfield_member(entity); - attribute_t *attributes = parse_attributes(NULL); - handle_entity_attributes(attributes, entity); - } else { - type_t *orig_type = entity->declaration.type; - type_t *type = skip_typeref(orig_type); - if (is_type_function(type)) { - errorf(pos, "'%N' must not have function type '%T'", entity, orig_type); - } else if (is_type_incomplete(type)) { - /* §6.7.2.1:16 flexible array member */ - if (!is_type_array(type) || - token.kind != ';' || - look_ahead(1)->kind != '}') { - errorf(pos, "'%N' has incomplete type '%T'", entity, orig_type); - } else if (compound->members.entities == NULL) { - errorf(pos, "flexible array member in otherwise empty struct"); - } + attribute_t *attributes = parse_attributes(NULL); + handle_entity_attributes(attributes, entity); + } else { + type_t *orig_type = entity->declaration.type; + type_t *type = skip_typeref(orig_type); + if (is_type_function(type)) { + errorf(pos, "'%N' must not have function type '%T'", entity, orig_type); + } else if (is_type_incomplete(type)) { + /* §6.7.2.1:16 flexible array member */ + if (!is_type_array(type) || + token.kind != ';' || + look_ahead(1)->kind != '}') { + errorf(pos, "'%N' has incomplete type '%T'", entity, orig_type); + } else if (compound->members.entities == NULL) { + errorf(pos, "flexible array member in otherwise empty struct"); } } - - append_entity(&compound->members, entity); } } + + append_entity(&compound->members, entity); } while (accept(',')); rem_anchor_token(','); rem_anchor_token(';'); diff --git a/preprocessor.c b/preprocessor.c index 9fbf392..5d4213b 100644 --- a/preprocessor.c +++ b/preprocessor.c @@ -1855,18 +1855,18 @@ static void parse_define_directive(void) = size / sizeof(new_definition->parameters[0]); new_definition->parameters = obstack_finish(&pp_obstack); for (size_t i = 0; i < new_definition->n_parameters; ++i) { - pp_definition_t *param = &new_definition->parameters[i]; - symbol_t *symbol = param->symbol; - pp_definition_t *previous = symbol->pp_definition; + pp_definition_t *const param = &new_definition->parameters[i]; + symbol_t *const param_sym = param->symbol; + pp_definition_t *const previous = param_sym->pp_definition; if (previous != NULL && previous->function_definition == new_definition) { - errorf(¶m->pos, "duplicate macro parameter '%Y'", symbol); + errorf(¶m->pos, "duplicate macro parameter '%Y'", param_sym); param->symbol = sym_anonymous; continue; } param->parent_expansion = previous; param->function_definition = new_definition; - symbol->pp_definition = param; + param_sym->pp_definition = param; } } else { next_input_token(); @@ -1877,8 +1877,7 @@ static void parse_define_directive(void) bool next_must_be_param = false; while (!info.at_line_begin) { if (pp_token.kind == T_IDENTIFIER) { - const symbol_t *symbol = pp_token.base.symbol; - pp_definition_t *definition = symbol->pp_definition; + pp_definition_t *const definition = pp_token.base.symbol->pp_definition; if (definition != NULL && definition->function_definition == new_definition) { pp_token.kind = T_MACRO_PARAMETER; @@ -1905,14 +1904,14 @@ static void parse_define_directive(void) if (new_definition->has_parameters) { for (size_t i = 0; i < new_definition->n_parameters; ++i) { - pp_definition_t *param = &new_definition->parameters[i]; - symbol_t *symbol = param->symbol; - if (symbol == sym_anonymous) + pp_definition_t *const param = &new_definition->parameters[i]; + symbol_t *const param_sym = param->symbol; + if (param_sym == sym_anonymous) continue; - assert(symbol->pp_definition == param); + assert(param_sym->pp_definition == param); assert(param->function_definition == new_definition); - symbol->pp_definition = param->parent_expansion; - param->parent_expansion = NULL; + param_sym->pp_definition = param->parent_expansion; + param->parent_expansion = NULL; } } -- 2.20.1