From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14752 invoked by alias); 16 Jan 2014 06:08:54 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 14377 invoked by uid 48); 16 Jan 2014 06:08:49 -0000 From: "su at cs dot ucdavis.edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/59801] GCC does not warn on unused global variable Date: Thu, 16 Jan 2014 06:08:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: su at cs dot ucdavis.edu X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-01/txt/msg01649.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59801 Zhendong Su changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |su at cs dot ucdavis.edu --- Comment #3 from Zhendong Su --- 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