From owner-svn-src-all@FreeBSD.ORG Thu Jan 17 02:07:57 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 3D854FFD; Thu, 17 Jan 2013 02:07:57 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from fallbackmx07.syd.optusnet.com.au (fallbackmx07.syd.optusnet.com.au [211.29.132.9]) by mx1.freebsd.org (Postfix) with ESMTP id 5854A6B; Thu, 17 Jan 2013 02:07:56 +0000 (UTC) Received: from mail10.syd.optusnet.com.au (mail10.syd.optusnet.com.au [211.29.132.191]) by fallbackmx07.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id r0H27ndK004029; Thu, 17 Jan 2013 13:07:49 +1100 Received: from c211-30-173-106.carlnfd1.nsw.optusnet.com.au (c211-30-173-106.carlnfd1.nsw.optusnet.com.au [211.30.173.106]) by mail10.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id r0H27V75017594 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 17 Jan 2013 13:07:33 +1100 Date: Thu, 17 Jan 2013 13:07:31 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Eitan Adler Subject: Re: svn commit: r245494 - head/bin/pwait In-Reply-To: Message-ID: <20130117125124.T1066@besplex.bde.org> References: <201301160503.r0G53qie087155@svn.freebsd.org> <50F6ED68.50602@delphij.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.0 cv=Auu2R5BP c=1 sm=1 a=FCoFQeHV-_kA:10 a=kj9zAlcOel0A:10 a=PO7r1zJSAAAA:8 a=JzwRw_2MAAAA:8 a=0Iti9RnyFakA:10 a=SWg00rOMAAAA:8 a=9I5xiGouAAAA:8 a=d02al9D6jb9SjW1LqP8A:9 a=CjuIK1q_8ugA:10 a=0yGDDesplhsA:10 a=3_5TX_vZOqAA:10 a=TEtd8y5WR3g2ypngnwZWYw==:117 Cc: "svn-src-head@freebsd.org" , Xin LI , "svn-src-all@freebsd.org" , "src-committers@freebsd.org" , d@delphij.net X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jan 2013 02:07:57 -0000 On Wed, 16 Jan 2013, Eitan Adler wrote: > On 16 January 2013 13:11, Xin Li wrote: > >> Yes I did. Using exit(3) tells clang that this is the final exit and >> thus eliminates the warning. >> >> It sounds like a bug (or arguably a feature) that clang does not >> recognize return in main()s... > > It is not a bug: see Of course it is a bug. > http://clang-developers.42468.n3.nabble.com/Static-analyzer-possible-memory-leak-false-positive-td4026706.html Not much signal there. C99 requires main() to be handled specially in hosted environments. (In freestanding environments(), neither main() nor malloc() is special. Now the compiler could warn about main(), but it cannot know what malloc() does so it cannot warn about not freeing memory on return from main().) It requires that, if the return type of main() is compatible with int (and thus not void), then a return from the _initial_ call to main() is equivalent to calling exit() with an arg equal to the return value (and that if main() doesn't explicitly return or exit, but falls through to the closing brace, then this is equivalent to 'return (0);'. It seems to be permitted to call malloc() recursively (otherwise C99 w. The warning is useful if main() is called recursively. But few programs call main() recursively. pwait(1) obviously doesn't. The the bug is quality of implementation one. The static analyzer is too stupid to see that main() isn't called recursively. Bruce