This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: "uninitialized variable" warning from compiler
- From: Andrew Haley <aph at redhat dot com>
- To: "Umashankar V.K." <shankar dot vk at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 26 Oct 2009 14:06:04 +0000
- Subject: Re: "uninitialized variable" warning from compiler
- References: <448a67a0910260655g2fe59e61g209bd1cb4122fd35@mail.gmail.com>
Umashankar V.K. wrote:
> I have few questions about inbuilt mechanism of gcc/g++ for
> warning about uninitialized variable.
>
> I am interested in cases where compiler is unable to warn. I am
> aware that all the known bugs about warning-failure are
> mentioned at bugzilla http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639
>
> a) The compiler activates the warning mechanism only if optimisation
> is enabled at compilation time with -O option.
> For all the bugs that I went through at bugzilla, the failure is not
> -O level dependent. The warning-failure occurs for all levels of
> optimisation.
> So, I believe this is the general case.
>
> But then I came across the following failure case. This one fails
> to warn when compiled with any level below 3.
> With -O3, gcc is able to warn. Can someone tell me which is the
> corresponding bug logged at bugzilla ?
I don't understand why you think this is a bug in gcc. Inlining will
always reveal more about the data flow of a program.
> Are there any more such bugs which disappear when compiled with
> specific -O level ?
>
> b) Are there any known "fail to do uninitialised-warning" gcc bugs
> which are language-dependent ?
If there is an uninitialized variable, and gcc fails to notice, that is
not necessarily a bug. For example,
extern void foo (int *p);
void bar
{
int a;
foo (&a);
printf("%d\n", a);
}
We could fix gcc so that in every case where we couldn't prove that a variable
is initialized, we warned. You'd have to put up with a lot of spurious "may
be used uninitialized" warnings.
Andrew.