[PATCH 1/1] bfd, binutils, gas: Mark unused variables

Jan Beulich jbeulich@suse.com
Thu Sep 15 07:29:27 GMT 2022


On 15.09.2022 06:17, Tsukasa OI via Binutils wrote:
> Clang generates a warning on unused (technically, written but not read
> thereafter) variables.  By the default configuration (with "-Werror"), it
> causes a build failure (unless "--disable-werror" is specified).
> 
> This commit, instead of just removing those variables, adds
> ATTRIBUTE_UNUSED attribute to them, which means they are *possibly* unused
> (can be used but no warnings occur when unused).

May I ask why you chose to do so? I can see such a variable being consumed
inside an #ifdef, but being declared unconditionally as a reason, but
(looking just at code I'm a little familiar with) ...

> --- a/gas/config/tc-riscv.c
> +++ b/gas/config/tc-riscv.c
> @@ -2303,7 +2303,7 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
>    char save_c = 0;
>    struct riscv_opcode *insn;
>    unsigned int regno;
> -  int argnum;
> +  int argnum ATTRIBUTE_UNUSED;
>    const struct percent_op_match *p;
>    struct riscv_ip_error error;
>    error.msg = "unrecognized opcode";
> --- a/ld/pe-dll.c
> +++ b/ld/pe-dll.c
> @@ -1510,8 +1510,9 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info)
>    int total_relocs = 0;
>    int i;
>    bfd_vma sec_page = (bfd_vma) -1;
> -  bfd_vma page_ptr, page_count;
> -  int bi;
> +  bfd_vma page_ptr;
> +  bfd_vma page_count ATTRIBUTE_UNUSED;
> +  int bi ATTRIBUTE_UNUSED;
>    bfd *b;
>    struct bfd_section *s;
>  

... in both of these cases there's truly no reading of the values,
so I don't see why they would need maintaining.

Jan


More information about the Binutils mailing list