Re: Switch -Wunused-variable on?

Michael Eager
2012-04-23T18:39:17Z

On 04/23/2012 10:25 AM, Pedro Alves wrote:
> On 04/23/2012 04:49 PM, Sergio Durigan Junior wrote:
>
>> On Monday, April 23 2012, Tom Tromey wrote:
>>
>>> I'd say that the best approach would be to make the declarations
>>> conditional in the same way that the uses are.
>>>
>>> If there are a lot of problem cases with this approach, or if it makes
>>> the code too ugly, then maybe it would be better just not to use this
>>> flag.
>>
>> Ok, that makes sense to me. Since there are tons of places with unused
>> variables in the code, I will take some time to look and convert the
>> proper places to use this solution.
>
>
> I don't think there'll be that many such cases.
>
> In case it helps, here's how I peek at this sort of thing:
>
> $ .....configure --enable-targets=all
> $ make -j8
> $ cd gdb
> $ make clean
> $ make WERROR_CFLAGS="-Wunused-variable" -j8 2>&1 1>/dev/null | tee warnings.txt
> ...
>
> There aren't _that_ many warnings:
>
> $ grep warning warnings.txt | wc -l
> 512
>
> (This doesn't catch files only built on other hosts, of course.)
>
> And the worse offenders account for a lot of the instances:
>
> $ grep warning warnings.txt | sed 's/\.c.*/\.c/g' | sort | uniq -c | sort -nr
> 50 ../../src/gdb/arm-tdep.c
> 15 ../../src/gdb/cris-tdep.c
> 13 ../../src/gdb/ia64-tdep.c
> 12 ../../src/gdb/dwarf2read.c
> 12 ../../src/gdb/c-lang.c
> 12 ../../src/gdb/breakpoint.c
> 11 ../../src/gdb/mips-tdep.c
> 11 ../../src/gdb/m32c-tdep.c
> 10 ../../src/gdb/spu-tdep.c
> 10 ../../src/gdb/lm32-tdep.c
> 10 ../../src/gdb/hppa-tdep.c

> ../../src/gdb/microblaze-tdep.c: In function ‘microblaze_alloc_frame_cache’:
> ../../src/gdb/microblaze-tdep.c:176:7: warning: unused variable ‘i’ [-Wunused-variable]
> ../../src/gdb/microblaze-tdep.c: In function ‘microblaze_analyze_prologue’:
> ../../src/gdb/microblaze-tdep.c:234:7: warning: unused variable ‘rn’ [-Wunused-variable]
> ../../src/gdb/microblaze-tdep.c: In function ‘microblaze_frame_cache’:
> ../../src/gdb/microblaze-tdep.c:464:23: warning: unused variable ‘fp’ [-Wunused-variable]
> ../../src/gdb/microblaze-tdep.c:464:19: warning: unused variable ‘pc’ [-Wunused-variable]
> ../../src/gdb/microblaze-linux-tdep.c: In function ‘microblaze_linux_sigtramp_cache’:
> ../../src/gdb/microblaze-linux-tdep.c:76:24: warning: unused variable ‘tdep’ [-Wunused-variable]
> ../../src/gdb/microblaze-linux-tdep.c: In function ‘microblaze_linux_init_abi’:
> ../../src/gdb/microblaze-linux-tdep.c:124:24: warning: unused variable ‘tdep’ [-Wunused-variable]

I'll clean up the MicroBlaze target files when I have a moment.

--
Michael Eager eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077