From owner-freebsd-current Sat Feb 8 17:50:58 2003 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 028A337B401 for ; Sat, 8 Feb 2003 17:50:57 -0800 (PST) Received: from HAL9000.homeunix.com (12-233-57-224.client.attbi.com [12.233.57.224]) by mx1.FreeBSD.org (Postfix) with ESMTP id 531D843F93 for ; Sat, 8 Feb 2003 17:50:56 -0800 (PST) (envelope-from dschultz@uclink.berkeley.edu) Received: from HAL9000.homeunix.com (localhost [127.0.0.1]) by HAL9000.homeunix.com (8.12.6/8.12.5) with ESMTP id h191osYP021335; Sat, 8 Feb 2003 17:50:54 -0800 (PST) (envelope-from dschultz@uclink.berkeley.edu) Received: (from das@localhost) by HAL9000.homeunix.com (8.12.6/8.12.5/Submit) id h191orJm021334; Sat, 8 Feb 2003 17:50:53 -0800 (PST) (envelope-from dschultz@uclink.berkeley.edu) Date: Sat, 8 Feb 2003 17:50:53 -0800 From: David Schultz To: Terry Lambert Cc: Ray Kohler , freebsd-current@FreeBSD.ORG Subject: Re: Compiling with high optimization? Message-ID: <20030209015053.GB21191@HAL9000.homeunix.com> Mail-Followup-To: Terry Lambert , Ray Kohler , freebsd-current@FreeBSD.ORG References: <20030208173756.GA56030@arkadia.nv.cox.net> <20030208232724.GA20435@HAL9000.homeunix.com> <3E459BF3.BB3FC381@mindspring.com> <20030209002542.GA20812@HAL9000.homeunix.com> <3E45AD75.47C80368@mindspring.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3E45AD75.47C80368@mindspring.com> Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Thus spake Terry Lambert : > David Schultz wrote: > > Thus spake Terry Lambert : > > > Actually, failure to use optimization suppresses some compilation > > > warnings, particularly those which normally print from using some > > > variables without initializing them. > > > > I think you're thinking of dataflow analysis, which I believe gcc > > does with -O and higher optimization levels. So unless you're > > using -O0, I would expect that you'd get all the warnings you > > want. > > See the thread "Re: tmpfile breakage on setuid executables". > > Kris accidently introduced a bug that had to do with whether or > not a variable was used before it was initialized. The compiler > didn't complain when he checked it before committing it because > optimization was off by default; it should have complained, e.g.: > > "x.c:9:warning: `foo' might be used uninitialized in this function" Thanks, I saw that. I'm just pointing out that all you need is -O to get that warning: das@bloody-mary:~> cat foo.c int main() { int foo; return foo; } das@bloody-mary:~> gcc -o foo foo.c -Wall -O foo.c: In function `main': foo.c:2: warning: `foo' might be used uninitialized in this function This is one of those things that gcc3 does pretty well, but Sun's javac does very badly. First of all, in Java, the above warning is considered an error (except *maybe* in JDK 1.4, which is broken and slow on IA64 so I can't use it). Second, the dataflow analysis in javac is braindead, so the compiler is almost always wrong. When I get the same warning from gcc, it's usually right unless interprocedural analysis would be required. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message