WebAssembly: Correct an `index' global shadowing error for pre-4.8 GCC

Message ID alpine.DEB.2.00.1802030438180.3553@tp.orcam.me.uk
State New
Headers show
Series
  • WebAssembly: Correct an `index' global shadowing error for pre-4.8 GCC
Related show

Commit Message

Maciej W. Rozycki Feb. 3, 2018, 3:15 p.m.
Remove `-Wshadow' compilation errors:

cc1: warnings being treated as errors
.../bfd/wasm-module.c: In function 'wasm_scan_name_function_section':
.../bfd/wasm-module.c:312: error: declaration of 'index' shadows a global declaration
/usr/include/string.h:303: error: shadowed declaration is here
.../bfd/wasm-module.c: In function 'wasm_register_section':
.../bfd/wasm-module.c:494: error: declaration of 'index' shadows a global declaration
/usr/include/string.h:303: error: shadowed declaration is here
.../bfd/wasm-module.c: In function 'wasm_compute_custom_section_file_position':
.../bfd/wasm-module.c:523: error: declaration of 'index' shadows a global declaration
/usr/include/string.h:303: error: shadowed declaration is here

and:

cc1: warnings being treated as errors
.../opcodes/wasm32-dis.c: In function 'print_insn_wasm32':
.../opcodes/wasm32-dis.c:272: error: declaration of 'index' shadows a global declaration
/usr/include/string.h:303: error: shadowed declaration is here
make[4]: *** [wasm32-dis.lo] Error 1

which for versions of GCC before 4.8 prevent support for the WebAssembly 
target from being built.  See also GCC PR c/53066.

	bfd/
	* wasm-module.c (wasm_scan_name_function_section): Rename 
	`index' local variable to `idx'.

	opcodes/
	* wasm32-dis.c (print_insn_wasm32): Rename `index' local 
	variable to 
---
Hi,

 This has popped up in routine cross-target testing for an unrelated 
change and should be obvious.  OK to apply?

  Maciej
---
 bfd/wasm-module.c    |   18 +++++++++---------
 opcodes/wasm32-dis.c |    6 +++---
 2 files changed, 12 insertions(+), 12 deletions(-)

binutils-wasm32-index-shadow.diff

Comments

Pip Cet Feb. 4, 2018, 2:53 p.m. | #1
Hello Maciej,
again, thank you for looking at this code and testing it. The change
also looks obviously correct to me.

Pip

On Sat, Feb 3, 2018 at 3:15 PM, Maciej W. Rozycki <macro@mips.com> wrote:
> Remove `-Wshadow' compilation errors:

>

> cc1: warnings being treated as errors

> .../bfd/wasm-module.c: In function 'wasm_scan_name_function_section':

> .../bfd/wasm-module.c:312: error: declaration of 'index' shadows a global declaration

> /usr/include/string.h:303: error: shadowed declaration is here

> .../bfd/wasm-module.c: In function 'wasm_register_section':

> .../bfd/wasm-module.c:494: error: declaration of 'index' shadows a global declaration

> /usr/include/string.h:303: error: shadowed declaration is here

> .../bfd/wasm-module.c: In function 'wasm_compute_custom_section_file_position':

> .../bfd/wasm-module.c:523: error: declaration of 'index' shadows a global declaration

> /usr/include/string.h:303: error: shadowed declaration is here

>

> and:

>

> cc1: warnings being treated as errors

> .../opcodes/wasm32-dis.c: In function 'print_insn_wasm32':

> .../opcodes/wasm32-dis.c:272: error: declaration of 'index' shadows a global declaration

> /usr/include/string.h:303: error: shadowed declaration is here

> make[4]: *** [wasm32-dis.lo] Error 1

>

> which for versions of GCC before 4.8 prevent support for the WebAssembly

> target from being built.  See also GCC PR c/53066.

>

>         bfd/

>         * wasm-module.c (wasm_scan_name_function_section): Rename

>         `index' local variable to `idx'.

>

>         opcodes/

>         * wasm32-dis.c (print_insn_wasm32): Rename `index' local

>         variable to

> ---

> Hi,

>

>  This has popped up in routine cross-target testing for an unrelated

> change and should be obvious.  OK to apply?

>

>   Maciej

> ---

>  bfd/wasm-module.c    |   18 +++++++++---------

>  opcodes/wasm32-dis.c |    6 +++---

>  2 files changed, 12 insertions(+), 12 deletions(-)

>

> binutils-wasm32-index-shadow.diff

> Index: binutils/bfd/wasm-module.c

> ===================================================================

> --- binutils.orig/bfd/wasm-module.c     2018-02-02 05:34:05.217268819 +0000

> +++ binutils/bfd/wasm-module.c  2018-02-02 05:34:41.869388049 +0000

> @@ -309,12 +309,12 @@ wasm_scan_name_function_section (bfd *ab

>

>    for (symcount = 0; p < end && symcount < tdata->symcount; symcount++)

>      {

> -      bfd_vma index;

> +      bfd_vma idx;

>        bfd_vma len;

>        char *name;

>        asymbol *sym;

>

> -      READ_LEB128 (index, p, end);

> +      READ_LEB128 (idx, p, end);

>        READ_LEB128 (len, p, end);

>

>        if (p + len < p || p + len > end)

> @@ -330,7 +330,7 @@ wasm_scan_name_function_section (bfd *ab

>        sym = &symbols[symcount];

>        sym->the_bfd = abfd;

>        sym->name = name;

> -      sym->value = index;

> +      sym->value = idx;

>        sym->flags = BSF_GLOBAL | BSF_FUNCTION;

>        sym->section = space_function_index;

>        sym->udata.p = NULL;

> @@ -491,12 +491,12 @@ wasm_register_section (bfd *abfd ATTRIBU

>                        void *fsarg)

>  {

>    sec_ptr *numbered_sections = fsarg;

> -  int index = wasm_section_name_to_code (asect->name);

> +  int idx = wasm_section_name_to_code (asect->name);

>

> -  if (index == 0)

> +  if (idx == 0)

>      return;

>

> -  numbered_sections[index] = asect;

> +  numbered_sections[idx] = asect;

>  }

>

>  struct compute_section_arg

> @@ -520,14 +520,14 @@ wasm_compute_custom_section_file_positio

>                                            void *fsarg)

>  {

>    struct compute_section_arg *fs = fsarg;

> -  int index;

> +  int idx;

>

>    if (fs->failed)

>      return;

>

> -  index = wasm_section_name_to_code (asect->name);

> +  idx = wasm_section_name_to_code (asect->name);

>

> -  if (index != 0)

> +  if (idx != 0)

>      return;

>

>    if (CONST_STRNEQ (asect->name, WASM_SECTION_PREFIX))

> Index: binutils/opcodes/wasm32-dis.c

> ===================================================================

> --- binutils.orig/opcodes/wasm32-dis.c  2018-01-28 00:50:52.000000000 +0000

> +++ binutils/opcodes/wasm32-dis.c       2018-02-02 05:36:53.262294076 +0000

> @@ -269,7 +269,7 @@ print_insn_wasm32 (bfd_vma pc, struct di

>    long flags = 0;

>    long offset = 0;

>    long depth = 0;

> -  long index = 0;

> +  long function_index = 0;

>    long target_count = 0;

>    long block_type = 0;

>    int len = 1;

> @@ -416,14 +416,14 @@ print_insn_wasm32 (bfd_vma pc, struct di

>            break;

>

>          case wasm_call:

> -          index = wasm_read_leb128

> +          function_index = wasm_read_leb128

>              (pc + len, info, &error, &bytes_read, FALSE);

>            if (error)

>              return -1;

>            len += bytes_read;

>            prin (stream, " ");

>            private_data->section_prefix = ".space.function_index";

> -          (*info->print_address_func) ((bfd_vma) index, info);

> +          (*info->print_address_func) ((bfd_vma) function_index, info);

>            private_data->section_prefix = NULL;

>            break;

>
Maciej W. Rozycki Feb. 13, 2018, 1:05 p.m. | #2
On Sat, 3 Feb 2018, Maciej W. Rozycki wrote:

> 	bfd/

> 	* wasm-module.c (wasm_scan_name_function_section): Rename 

> 	`index' local variable to `idx'.

> 

> 	opcodes/

> 	* wasm32-dis.c (print_insn_wasm32): Rename `index' local 

> 	variable to 


 I have committed this change, with the opcodes ChangeLog entry corrected 
to read:

	* wasm32-dis.c (print_insn_wasm32): Rename `index' local 
	variable to `function_index'.

  Maciej

Patch

Index: binutils/bfd/wasm-module.c
===================================================================
--- binutils.orig/bfd/wasm-module.c	2018-02-02 05:34:05.217268819 +0000
+++ binutils/bfd/wasm-module.c	2018-02-02 05:34:41.869388049 +0000
@@ -309,12 +309,12 @@  wasm_scan_name_function_section (bfd *ab
 
   for (symcount = 0; p < end && symcount < tdata->symcount; symcount++)
     {
-      bfd_vma index;
+      bfd_vma idx;
       bfd_vma len;
       char *name;
       asymbol *sym;
 
-      READ_LEB128 (index, p, end);
+      READ_LEB128 (idx, p, end);
       READ_LEB128 (len, p, end);
 
       if (p + len < p || p + len > end)
@@ -330,7 +330,7 @@  wasm_scan_name_function_section (bfd *ab
       sym = &symbols[symcount];
       sym->the_bfd = abfd;
       sym->name = name;
-      sym->value = index;
+      sym->value = idx;
       sym->flags = BSF_GLOBAL | BSF_FUNCTION;
       sym->section = space_function_index;
       sym->udata.p = NULL;
@@ -491,12 +491,12 @@  wasm_register_section (bfd *abfd ATTRIBU
 		       void *fsarg)
 {
   sec_ptr *numbered_sections = fsarg;
-  int index = wasm_section_name_to_code (asect->name);
+  int idx = wasm_section_name_to_code (asect->name);
 
-  if (index == 0)
+  if (idx == 0)
     return;
 
-  numbered_sections[index] = asect;
+  numbered_sections[idx] = asect;
 }
 
 struct compute_section_arg
@@ -520,14 +520,14 @@  wasm_compute_custom_section_file_positio
 					   void *fsarg)
 {
   struct compute_section_arg *fs = fsarg;
-  int index;
+  int idx;
 
   if (fs->failed)
     return;
 
-  index = wasm_section_name_to_code (asect->name);
+  idx = wasm_section_name_to_code (asect->name);
 
-  if (index != 0)
+  if (idx != 0)
     return;
 
   if (CONST_STRNEQ (asect->name, WASM_SECTION_PREFIX))
Index: binutils/opcodes/wasm32-dis.c
===================================================================
--- binutils.orig/opcodes/wasm32-dis.c	2018-01-28 00:50:52.000000000 +0000
+++ binutils/opcodes/wasm32-dis.c	2018-02-02 05:36:53.262294076 +0000
@@ -269,7 +269,7 @@  print_insn_wasm32 (bfd_vma pc, struct di
   long flags = 0;
   long offset = 0;
   long depth = 0;
-  long index = 0;
+  long function_index = 0;
   long target_count = 0;
   long block_type = 0;
   int len = 1;
@@ -416,14 +416,14 @@  print_insn_wasm32 (bfd_vma pc, struct di
           break;
 
         case wasm_call:
-          index = wasm_read_leb128
+          function_index = wasm_read_leb128
             (pc + len, info, &error, &bytes_read, FALSE);
           if (error)
             return -1;
           len += bytes_read;
           prin (stream, " ");
           private_data->section_prefix = ".space.function_index";
-          (*info->print_address_func) ((bfd_vma) index, info);
+          (*info->print_address_func) ((bfd_vma) function_index, info);
           private_data->section_prefix = NULL;
           break;