This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/59801] GCC does not warn on unused global variable
- From: "su at cs dot ucdavis.edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 16 Jan 2014 06:08:48 +0000
- Subject: [Bug c/59801] GCC does not warn on unused global variable
- Auto-submitted: auto-generated
- References: <bug-59801-4 at http dot gcc dot gnu dot org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59801
Zhendong Su <su at cs dot ucdavis.edu> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |su at cs dot ucdavis.edu
--- Comment #3 from Zhendong Su <su at cs dot ucdavis.edu> ---
For the given code, it does seem make sense to issue a warning (whether or not
"volatile" is used) because this is likely a bug in the code.
$ gcc-trunk -Wunused-variable small.c
$ clang-trunk -Wunused-variable small.c
small.c:1:21: warning: unused variable 'a' [-Wunused-variable]
static volatile int a;
^
1 warning generated.
$ cat small.c
static volatile int a;
int
main ()
{
return 0;
}
----------------------
This also seems to be a missed optimization opportunity:
$ gcc-trunk -O3 -S small.c
$ cat small.s
.file "small.c"
.section .text.unlikely,"ax",@progbits
.LCOLDB0:
.section .text.startup,"ax",@progbits
.LHOTB0:
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
xorl %eax, %eax
ret
.cfi_endproc
.LFE0:
.size main, .-main
.section .text.unlikely
.LCOLDE0:
.section .text.startup
.LHOTE0:
.local a
.comm a,4,4
.ident "GCC: (GNU) 4.9.0 20140115 (experimental) [trunk revision
206638]"
.section .note.GNU-stack,"",@progbits