Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755078AbbDTM2V (ORCPT ); Mon, 20 Apr 2015 08:28:21 -0400 Received: from smtprelay0168.hostedemail.com ([216.40.44.168]:38441 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755049AbbDTM2S (ORCPT ); Mon, 20 Apr 2015 08:28:18 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 10,1,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::,RULES_HIT:41:355:379:541:599:800:960:967:973:988:989:1260:1263:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2194:2199:2393:2525:2553:2561:2564:2682:2685:2828:2859:2902:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3354:3622:3770:3865:3866:3867:3868:3870:3871:3872:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4605:5007:6117:6119:6120:6261:7808:7901:7903:8599:8784:9025:9121:9388:10004:10400:10471:10848:11026:11232:11233:11473:11658:11914:12043:12262:12438:12517:12519:12555:12679:12698:12737:12740:12776:12933:13161:13225:13229:13255:13618:13898:14093:14097:14157:21063:21080,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: rings51_8235ae89ab04e X-Filterd-Recvd-Size: 3802 Message-ID: <1429532893.4216.36.camel@perches.com> Subject: Re: gcc doesn't warn about uninitialized variable use in switch/case with -O (was: Re: [PATCH] Staging: dgnc: Using temporary value for repeated dereferences) From: Joe Perches To: Dan Carpenter Cc: Yorick Rommers , devel@driverdev.osuosl.org, lidza.louina@gmail.com, driverdev-devel@linuxdriverproject.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org Date: Mon, 20 Apr 2015 05:28:13 -0700 In-Reply-To: <1429526541.4216.18.camel@perches.com> References: <1429475676.2947.43.camel@perches.com> <1429491259.27863.1.camel@perches.com> <20150420083310.GE16501@mwanda> <1429526541.4216.18.camel@perches.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.12.10-0ubuntu1~14.10.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2784 Lines: 72 On Mon, 2015-04-20 at 03:42 -0700, Joe Perches wrote: > On Mon, 2015-04-20 at 11:33 +0300, Dan Carpenter wrote: > > You would hope that GCC would warn about the uninitialized variable but > > it doesn't. > > That's odd. So I filed this new gcc bugzilla: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65812) > > gcc 4.9.1 doesn't warn about uninitialized variable use > declared in a switch/case statement when compiled with -O Hey Dan/Yorick A bit more investigation: It's true that gcc doesn't report the uninitialized variable for the code I showed, but that's probably not the reason the "may be used uninitialized" warning is not shown for the dgnc code as patched by Yorick. The example code doesn't show the "uninitialized" warning because gcc's dead code elimination is set by -O and the sample code foo_2 function switch/case is eliminated. Perhaps the warning is not shown for this dgnc patch because your .config has CONFIG_GCOV_PROFILE_ALL set. That enables the gcc -fprofile-arcs option which masks the warning, I don't know why. Maybe see: commit 2521f2c228ad750701ba4702484e31d876dbc386 Author: Peter Oberparleiter Date: Wed Jun 17 16:28:08 2009 -0700 gcov: add gcov profiling infrastructure Enable the use of GCC's coverage testing tool gcov [1] with the Linux kernel. gcov may be useful for: * debugging (has this code been reached at all?) * test improvement (how do I change my test to cover these lines?) * minimizing kernel configurations (do I need this option if the associated code is never run?) The profiling patch incorporates the following changes: * change kbuild to include profiling flags * provide functions needed by profiling code * present profiling data as files in debugfs Note that on some architectures, enabling gcc's profiling option "-fprofile-arcs" for the entire kernel may trigger compile/link/ run-time problems, some of which are caused by toolchain bugs and others which require adjustment of architecture code. For this reason profiling the entire kernel is initially restricted to those architectures for which it is known to work without changes. This restriction can be lifted once an architecture has been tested and found compatible with gcc's profiling. Profiling of single files or directories is still available on all platforms (see config help text). [1] http://gcc.gnu.org/onlinedocs/gcc/Gcov.html -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/