compiler: adjust code to avoid shadowing local variables
authorIan Lance Taylor <ian@gcc.gnu.org>
Fri, 4 Oct 2019 13:50:07 +0000 (13:50 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Fri, 4 Oct 2019 13:50:07 +0000 (13:50 +0000)
    Also add a couple of missing calls to free after mpz_get_str.

    This should make the code clean with respect to -Wshadow=local.

    Based on patch by Bernd Edlinger.

    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/198837

From-SVN: r276579

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/ast-dump.cc
gcc/go/gofrontend/escape.cc
gcc/go/gofrontend/expressions.cc
gcc/go/gofrontend/gogo.cc
gcc/go/gofrontend/parse.cc
gcc/go/gofrontend/statements.cc
gcc/go/gofrontend/types.cc

index 54c682a8b78cb301cc1b987c3cc63bcb70dec4ae..bb509943d6e0d8e523fb65728fd5b790e191f179 100644 (file)
@@ -1,4 +1,4 @@
-a3aef6b6df932ea6c7094d074695bc0b033a3d17
+441f3f1f350b532707c48273d7f454cf1c4e959f
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index b20f7e4e725e282f99a25427d66e4dbcfc51e826..a3cbda9debc55b0a63c598a5820ad50b63a81719 100644 (file)
@@ -135,11 +135,11 @@ Ast_dump_traverse_blocks_and_functions::function(Named_object* no)
         {
           if (it != res->begin())
             this->ast_dump_context_->ostream() << ",";
-          Named_object* no = (*it);
+          Named_object* rno = (*it);
 
-          this->ast_dump_context_->ostream() << no->name() << " ";
-          go_assert(no->is_result_variable());
-          Result_variable* resvar = no->result_var_value();
+          this->ast_dump_context_->ostream() << rno->name() << " ";
+          go_assert(rno->is_result_variable());
+          Result_variable* resvar = rno->result_var_value();
 
           this->ast_dump_context_->dump_type(resvar->type());
 
index bfd1a39d7e4e4a122637b27ecac52f65fa60ed2e..f8e07f73cd2d7d3048167140fe14e59331f643a7 100644 (file)
@@ -1541,7 +1541,6 @@ Escape_analysis_assign::expression(Expression** pexpr)
 
   if (debug_level > 1)
     {
-      Node* n = Node::make_node(*pexpr);
       std::string fn_name = this->context_->current_function_name();
       go_debug((*pexpr)->location(), "[%d] %s esc: %s",
               this->context_->loop_depth(), fn_name.c_str(),
index a72ba243f376ff79d5a6fce0585869a6148a2710..9babc3485951ee8452d2352a828e995b9e55ca44 100644 (file)
@@ -4104,9 +4104,11 @@ Type_conversion_expression::do_get_backend(Translate_context* context)
             x = mpz_get_ui(intval);
           else
             {
-              char* s = mpz_get_str(NULL, 16, intval);
+              char* ms = mpz_get_str(NULL, 16, intval);
               go_warning_at(loc, 0,
-                            "unicode code point 0x%s out of range in string", s);
+                            "unicode code point 0x%s out of range in string",
+                            ms);
+              free(ms);
               x = 0xfffd;
             }
          Lex::append_char(x, true, &s, loc);
@@ -8016,14 +8018,14 @@ Bound_method_expression::do_flatten(Gogo* gogo, Named_object*,
   Expression* ret = Expression::make_struct_composite_literal(st, vals, loc);
   ret = Expression::make_heap_expression(ret, loc);
 
-  Node* n = Node::make_node(this);
-  if ((n->encoding() & ESCAPE_MASK) == Node::ESCAPE_NONE)
+  Node* node = Node::make_node(this);
+  if ((node->encoding() & ESCAPE_MASK) == Node::ESCAPE_NONE)
     ret->heap_expression()->set_allocate_on_stack();
   else if (gogo->compiling_runtime()
           && gogo->package_name() == "runtime"
           && !saw_errors())
     go_error_at(loc, "%s escapes to heap, not allowed in runtime",
-                n->ast_format(gogo).c_str());
+                node->ast_format(gogo).c_str());
 
   // If necessary, check whether the expression or any embedded
   // pointers are nil.
@@ -8741,8 +8743,6 @@ Builtin_call_expression::lower_make(Statement_inserter* inserter)
                                  Expression::make_nil(loc));
       else
        {
-         Numeric_constant nclen;
-         unsigned long vlen;
          if (len_arg->numeric_constant_value(&nclen)
              && nclen.to_unsigned_long(&vlen) == Numeric_constant::NC_UL_VALID
              && vlen <= Map_type::bucket_size)
@@ -9053,8 +9053,7 @@ Builtin_call_expression::flatten_append(Gogo* gogo, Named_object* function,
           else
             {
               Type* int32_type = Type::lookup_integer_type("int32");
-              Expression* zero =
-                Expression::make_integer_ul(0, int32_type, loc);
+              zero = Expression::make_integer_ul(0, int32_type, loc);
               call = Runtime::make_call(Runtime::BUILTIN_MEMSET, loc, 3, a1,
                                         zero, a2);
             }
@@ -9064,15 +9063,12 @@ Builtin_call_expression::flatten_append(Gogo* gogo, Named_object* function,
               // For a slice containing pointers, growslice already zeroed
               // the memory. We only need to zero in non-growing case.
               // Note: growslice does not zero the memory in non-pointer case.
-              Expression* left =
-                Expression::make_temporary_reference(ntmp, loc);
-              left = Expression::make_cast(uint_type, left, loc);
-              Expression* right =
-                Expression::make_temporary_reference(c1tmp, loc);
-              right = Expression::make_cast(uint_type, right, loc);
-              Expression* cond =
-                Expression::make_binary(OPERATOR_GT, left, right, loc);
-              Expression* zero = Expression::make_integer_ul(0, int_type, loc);
+              ref = Expression::make_temporary_reference(ntmp, loc);
+              ref = Expression::make_cast(uint_type, ref, loc);
+              ref2 = Expression::make_temporary_reference(c1tmp, loc);
+              ref2 = Expression::make_cast(uint_type, ref2, loc);
+              cond = Expression::make_binary(OPERATOR_GT, ref, ref2, loc);
+              zero = Expression::make_integer_ul(0, int_type, loc);
               call = Expression::make_conditional(cond, call, zero, loc);
             }
         }
@@ -10877,9 +10873,7 @@ Call_expression::do_lower(Gogo* gogo, Named_object* function,
   if (this->result_count() > 1 && this->call_temp_ == NULL)
     {
       Struct_field_list* sfl = new Struct_field_list();
-      Function_type* fntype = this->get_function_type();
       const Typed_identifier_list* results = fntype->results();
-      Location loc = this->location();
 
       int i = 0;
       char buf[20];
@@ -12295,10 +12289,10 @@ Call_expression::do_get_backend(Translate_context* context)
     }
   else
     {
-      Expression* first_arg;
-      fn = this->interface_method_function(interface_method, &first_arg,
+      Expression* arg0;
+      fn = this->interface_method_function(interface_method, &arg0,
                                            location);
-      fn_args[0] = first_arg->get_backend(context);
+      fn_args[0] = arg0->get_backend(context);
     }
 
   Bexpression* bclosure = NULL;
@@ -16453,11 +16447,11 @@ Composite_literal_expression::lower_array(Type* type)
       traverse_order = new std::vector<unsigned long>();
       traverse_order->reserve(v.size());
 
-      for (V::const_iterator p = v.begin(); p != v.end(); ++p)
+      for (V::const_iterator pv = v.begin(); pv != v.end(); ++pv)
        {
-         indexes->push_back(p->index);
-         vals->push_back(p->expr);
-         traverse_order->push_back(p->traversal_order);
+         indexes->push_back(pv->index);
+         vals->push_back(pv->expr);
+         traverse_order->push_back(pv->traversal_order);
        }
     }
 
@@ -17771,9 +17765,9 @@ Interface_info_expression::do_type()
 
         Interface_type* itype = this->iface_->type()->interface_type();
 
-        Hashtable::const_iterator p = result_types.find(itype);
-        if (p != result_types.end())
-          return p->second;
+        Hashtable::const_iterator pr = result_types.find(itype);
+        if (pr != result_types.end())
+          return pr->second;
 
         Type* pdt = Type::make_type_descriptor_ptr_type();
         if (itype->is_empty())
index e7af673c8df8d0293f24baa189791c9d184578bb..a79cfc3a9a76e9d8487dc629fedfb26b8fd867ef 100644 (file)
@@ -518,11 +518,11 @@ Gogo::import_package(const std::string& filename,
       else if (ln == ".")
        {
          Bindings* bindings = package->bindings();
-         for (Bindings::const_declarations_iterator p =
+         for (Bindings::const_declarations_iterator pd =
                 bindings->begin_declarations();
-              p != bindings->end_declarations();
-              ++p)
-           this->add_dot_import_object(p->second);
+              pd != bindings->end_declarations();
+              ++pd)
+           this->add_dot_import_object(pd->second);
           std::string dot_alias = "." + package->package_name();
           package->add_alias(dot_alias, location);
        }
@@ -678,8 +678,8 @@ Gogo::recompute_init_priorities()
            pci != ii->precursors().end();
            ++pci)
         {
-          Import_init* ii = this->lookup_init(*pci);
-          nonroots.insert(ii);
+          Import_init* ii_init = this->lookup_init(*pci);
+          nonroots.insert(ii_init);
         }
     }
 
@@ -2613,11 +2613,11 @@ Gogo::define_global_names()
            {
              if (no->type_declaration_value()->has_methods())
                {
-                 for (std::vector<Named_object*>::const_iterator p =
+                 for (std::vector<Named_object*>::const_iterator pm =
                         no->type_declaration_value()->methods()->begin();
-                      p != no->type_declaration_value()->methods()->end();
-                      p++)
-                   go_error_at((*p)->location(),
+                      pm != no->type_declaration_value()->methods()->end();
+                      pm++)
+                   go_error_at((*pm)->location(),
                                "may not define methods on non-local type");
                }
              no->set_type_value(global_no->type_value());
@@ -6550,8 +6550,8 @@ Function::build(Gogo* gogo, Named_object* named_function)
 
       // Build the backend representation for all the statements in the
       // function.
-      Translate_context context(gogo, named_function, NULL, NULL);
-      Bblock* code_block = this->block_->get_backend(&context);
+      Translate_context bcontext(gogo, named_function, NULL, NULL);
+      Bblock* code_block = this->block_->get_backend(&bcontext);
 
       // Initialize variables if necessary.
       Translate_context icontext(gogo, named_function, this->block_,
@@ -6608,8 +6608,8 @@ Function::build(Gogo* gogo, Named_object* named_function)
   // If we created a descriptor for the function, make sure we emit it.
   if (this->descriptor_ != NULL)
     {
-      Translate_context context(gogo, NULL, NULL, NULL);
-      this->descriptor_->get_backend(&context);
+      Translate_context dcontext(gogo, NULL, NULL, NULL);
+      this->descriptor_->get_backend(&dcontext);
     }
 }
 
index 52371b2b032797b148e20078cbfc8f48b9a4c5b8..e50af616421fcfb4f6c6422ca21cef20cebe101e 100644 (file)
@@ -836,7 +836,7 @@ Parse::parameter_list(bool* is_varargs)
     {
       std::string name = token->identifier();
       bool is_exported = token->is_identifier_exported();
-      Location location = token->location();
+      Location id_location = token->location();
       token = this->advance_token();
       if (!token->is_op(OPERATOR_COMMA))
        {
@@ -861,7 +861,7 @@ Parse::parameter_list(bool* is_varargs)
            }
 
          this->unget_token(Token::make_identifier_token(name, is_exported,
-                                                        location));
+                                                        id_location));
        }
       else
        {
@@ -872,15 +872,15 @@ Parse::parameter_list(bool* is_varargs)
          // commas as we can.
          std::string id_name = this->gogo_->pack_hidden_name(name,
                                                              is_exported);
-         ret->push_back(Typed_identifier(id_name, NULL, location));
+         ret->push_back(Typed_identifier(id_name, NULL, id_location));
          bool just_saw_comma = true;
          while (this->advance_token()->is_identifier())
            {
              name = this->peek_token()->identifier();
              is_exported = this->peek_token()->is_identifier_exported();
-             location = this->peek_token()->location();
+             id_location = this->peek_token()->location();
              id_name = this->gogo_->pack_hidden_name(name, is_exported);
-             ret->push_back(Typed_identifier(id_name, NULL, location));
+             ret->push_back(Typed_identifier(id_name, NULL, id_location));
              if (!this->advance_token()->is_op(OPERATOR_COMMA))
                {
                  just_saw_comma = false;
@@ -909,7 +909,7 @@ Parse::parameter_list(bool* is_varargs)
              // names.
              parameters_have_names = false;
              this->unget_token(Token::make_identifier_token(name, is_exported,
-                                                            location));
+                                                            id_location));
              ret->pop_back();
              just_saw_comma = true;
            }
@@ -2808,7 +2808,7 @@ Parse::composite_lit(Type* type, int depth, Location location)
        {
          std::string identifier = token->identifier();
          bool is_exported = token->is_identifier_exported();
-         Location location = token->location();
+         Location id_location = token->location();
 
          if (this->advance_token()->is_op(OPERATOR_COLON))
            {
@@ -2820,14 +2820,14 @@ Parse::composite_lit(Type* type, int depth, Location location)
              Gogo* gogo = this->gogo_;
              val = this->id_to_expression(gogo->pack_hidden_name(identifier,
                                                                  is_exported),
-                                          location, false);
+                                          id_location, false);
              is_name = true;
            }
          else
            {
              this->unget_token(Token::make_identifier_token(identifier,
                                                             is_exported,
-                                                            location));
+                                                            id_location));
              val = this->expression(PRECEDENCE_NORMAL, false, true, NULL,
                                     NULL);
            }
@@ -2923,14 +2923,14 @@ Parse::composite_lit(Type* type, int depth, Location location)
            go_error_at(this->location(), "expected %<,%> or %<}%>");
 
          this->gogo_->mark_locals_used();
-         int depth = 0;
+         int edepth = 0;
          while (!token->is_eof()
-                && (depth > 0 || !token->is_op(OPERATOR_RCURLY)))
+                && (edepth > 0 || !token->is_op(OPERATOR_RCURLY)))
            {
              if (token->is_op(OPERATOR_LCURLY))
-               ++depth;
+               ++edepth;
              else if (token->is_op(OPERATOR_RCURLY))
-               --depth;
+               --edepth;
              token = this->advance_token();
            }
          if (token->is_op(OPERATOR_RCURLY))
index 3dc394ab32b1af94cae2ec65919a943270192562..f52b33d665cfb2376be179e5faa1241731c79bb6 100644 (file)
@@ -2938,7 +2938,7 @@ Thunk_statement::build_thunk(Gogo* gogo, const std::string& thunk_name)
       go_assert(call_statement->classification() == STATEMENT_EXPRESSION);
       Expression_statement* es =
        static_cast<Expression_statement*>(call_statement);
-      Call_expression* ce = es->expr()->call_expression();
+      ce = es->expr()->call_expression();
       if (ce == NULL)
        go_assert(saw_errors());
       else
@@ -5972,10 +5972,11 @@ Select_statement::lower_two_case(Block* b)
           // if selectnbrecv2(&lhs, &ok, chan) { body } else { default body }
 
           Type* booltype = Type::make_boolean_type();
-          Temporary_statement* ts = Statement::make_temporary(booltype, NULL, loc);
-          b->add_statement(ts);
+          Temporary_statement* okts = Statement::make_temporary(booltype, NULL,
+                                                                loc);
+          b->add_statement(okts);
 
-          okref = Expression::make_temporary_reference(ts, loc);
+          okref = Expression::make_temporary_reference(okts, loc);
           Expression* okaddr = Expression::make_unary(OPERATOR_AND, okref, loc);
           call = Runtime::make_call(Runtime::SELECTNBRECV2, loc, 3, addr, okaddr,
                                     chanref);
@@ -6595,7 +6596,7 @@ For_range_statement::lower_range_array(Gogo* gogo,
       iter_init = new Block(body_block, loc);
 
       ref = Expression::make_temporary_reference(range_temp, loc);
-      Expression* ref2 = Expression::make_temporary_reference(index_temp, loc);
+      ref2 = Expression::make_temporary_reference(index_temp, loc);
       Expression* index = Expression::make_index(ref, ref2, NULL, NULL, loc);
 
       tref = Expression::make_temporary_reference(value_temp, loc);
@@ -6693,7 +6694,7 @@ For_range_statement::lower_range_slice(Gogo* gogo,
       iter_init = new Block(body_block, loc);
 
       ref = Expression::make_temporary_reference(for_temp, loc);
-      Expression* ref2 = Expression::make_temporary_reference(index_temp, loc);
+      ref2 = Expression::make_temporary_reference(index_temp, loc);
       Expression* index = Expression::make_index(ref, ref2, NULL, NULL, loc);
 
       tref = Expression::make_temporary_reference(value_temp, loc);
@@ -7179,9 +7180,9 @@ For_range_statement::lower_array_range_clear(Gogo* gogo,
   else
     {
       Type* int32_type = Type::lookup_integer_type("int32");
-      Expression* zero = Expression::make_integer_ul(0, int32_type, loc);
+      Expression* zero32 = Expression::make_integer_ul(0, int32_type, loc);
       call = Runtime::make_call(Runtime::BUILTIN_MEMSET, loc, 3, ptr_arg,
-                                zero, sz_arg);
+                                zero32, sz_arg);
     }
   Statement* cs3 = Statement::make_statement(call, true);
   b->add_statement(cs3);
index eeae9fa4c0e924eef4a6056b652b58594b45a9cb..e02b832df149d08ff1427e307f2ff206d34df6dc 100644 (file)
@@ -6410,12 +6410,11 @@ Struct_type::do_type_descriptor(Gogo* gogo, Named_type* name)
         fvals->push_back(Expression::make_nil(bloc));
       else
        {
-         std::string n;
           if (is_embedded_builtin)
             n = gogo->package_name();
           else
             n = Gogo::hidden_name_pkgpath(pf->field_name());
-         Expression* s = Expression::make_string(n, bloc);
+         s = Expression::make_string(n, bloc);
          fvals->push_back(Expression::make_unary(OPERATOR_AND, s, bloc));
        }
 
@@ -6429,7 +6428,7 @@ Struct_type::do_type_descriptor(Gogo* gogo, Named_type* name)
        fvals->push_back(Expression::make_nil(bloc));
       else
        {
-         Expression* s = Expression::make_string(pf->tag(), bloc);
+         s = Expression::make_string(pf->tag(), bloc);
          fvals->push_back(Expression::make_unary(OPERATOR_AND, s, bloc));
        }
 
@@ -6635,22 +6634,22 @@ Struct_type::do_reflection(Gogo* gogo, std::string* ret) const
        {
          const std::string& tag(p->tag());
          ret->append(" \"");
-         for (std::string::const_iterator p = tag.begin();
-              p != tag.end();
-              ++p)
+         for (std::string::const_iterator pt = tag.begin();
+              pt != tag.end();
+              ++pt)
            {
-             if (*p == '\0')
+             if (*pt == '\0')
                ret->append("\\x00");
-             else if (*p == '\n')
+             else if (*pt == '\n')
                ret->append("\\n");
-             else if (*p == '\t')
+             else if (*pt == '\t')
                ret->append("\\t");
-             else if (*p == '"')
+             else if (*pt == '"')
                ret->append("\\\"");
-             else if (*p == '\\')
+             else if (*pt == '\\')
                ret->append("\\\\");
              else
-               ret->push_back(*p);
+               ret->push_back(*pt);
            }
          ret->push_back('"');
        }
@@ -7197,11 +7196,11 @@ Array_type::verify_length()
       return false;
     case Numeric_constant::NC_UL_BIG:
       {
-       mpz_t val;
-       if (!nc.to_int(&val))
+       mpz_t mval;
+       if (!nc.to_int(&mval))
          go_unreachable();
-       unsigned int bits = mpz_sizeinbase(val, 2);
-       mpz_clear(val);
+       unsigned int bits = mpz_sizeinbase(mval, 2);
+       mpz_clear(mval);
        if (bits >= tbits)
          {
            go_error_at(this->length_->location(), "array bound overflows");
@@ -7704,6 +7703,7 @@ Array_type::do_export(Export* exp) const
         }
       char* s = mpz_get_str(NULL, 10, val);
       exp->write_string(s);
+      free(s);
       exp->write_string(" ");
       mpz_clear(val);
     }
@@ -9752,7 +9752,7 @@ Interface_type::do_import(Import* imp)
          parameters = new Typed_identifier_list;
          while (true)
            {
-             std::string name = imp->read_name();
+             std::string pname = imp->read_name();
              imp->require_c_string(" ");
 
              if (imp->match_c_string("..."))
@@ -9764,7 +9764,7 @@ Interface_type::do_import(Import* imp)
              Type* ptype = imp->read_type();
              if (is_varargs)
                ptype = Type::make_array_type(ptype, NULL);
-             parameters->push_back(Typed_identifier(name, ptype,
+             parameters->push_back(Typed_identifier(pname, ptype,
                                                     imp->location()));
              if (imp->peek_char() != ',')
                break;
@@ -9791,10 +9791,10 @@ Interface_type::do_import(Import* imp)
              imp->advance(1);
              while (true)
                {
-                 std::string name = imp->read_name();
+                 std::string rname = imp->read_name();
                  imp->require_c_string(" ");
                  Type* rtype = imp->read_type();
-                 results->push_back(Typed_identifier(name, rtype,
+                 results->push_back(Typed_identifier(rname, rtype,
                                                      imp->location()));
                  if (imp->peek_char() != ',')
                    break;