Subject: Re: GCC Optimization flags -> errors
To: Gary Thorpe <gathorpe79@yahoo.com>
From: Chuck Swiger <cswiger@mac.com>
List: netbsd-help
Date: 06/19/2006 23:08:47
Gary Thorpe wrote:
> I have noticed that when I compiled NetBSD 2.0's kernel and now the 3.0
> kernel, errors crop up when using certain optimization flags (-Os in my
> case).
> 
> Specifically, the compiler produces warnings/errors about uninitialized
> variables when using the optimization flag and no errors when the flag
> is excluded.

The compiler cannot provide warnings about uninitialized variables without 
performing liveness analysis, which means that you have to turn on 
optimization for the compiler to be able to generate those messages.

Also, unless you are using -Werror, warnings and errors are not identical. :)

> On 3.0, I encountered this with pckbc_pnpbios.c: I ended up using the
> ISA attachment just for this device (the rest of pnpbios attachments
> had no problems).
> 
> Is this a general problem with GCC or a problem with the source code?

Um.  It's not clear that what's going on is a problem directly without seeing 
a particular error message or fragment of code, and GCC can be finicky and 
warn about stuff that is perfectly valid, but it's likely to be the case that 
use of uninit'ed variables is something which can and should be fixed in the 
source code.

> From working with another project, it seems that optimization can make
> the compiler think that code has problems such as uninitialized
> variables while it is fine without optimization (I cannot remember if a
> _different_ optimization level also eliminated the problem e.g. -O2
> instead of -Os).

The compiler cannot generate many warnings at all unless at least -O1 is 
enabled; that does not mean compiling without optimization avoids any genuine 
error in the code, but you can get lucky that many things default to being 
init'ed with all zeros and work as a coincidence.

-- 
-Chuck