Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 May 1997 09:57:22 -0400 (EDT)
From:      Thomas David Rivers <ponds!rivers@dg-rtp.dg.com>
To:        ponds!zeta.org.au!bde, ponds!freebsd.org!hackers, ponds!uriah.heep.sas.de!j, ponds!lakes.water.net!rivers
Subject:   Re: Variable initialization
Message-ID:  <199705211357.JAA29635@lakes.water.net>

next in thread | raw e-mail | index | archive | help
> 
> >> Ones based on variable liftime analysis.  If the compiler would emit
> >> a spurious warning because it can't tell that a variable is initialized
> >> for all flows of control, then initializing the variable when it is
> >> declared (or just early) is a pessimization - the compiler must store
> >> the value to memory or uselessly extend a register lifetime to hold
> >> the (unused) initial value.  The correct fix for this is to rearrange
> 
> > Ahh... but forward flow operations would move the initialization to
> >the beginning of the basic block where it's used.
> >
> > i.e. If a variable has the same value in the IN and OUT sets,
> >and is unused  in the block - it is hoisted through it.
> >
> > Initializing a variable "early" actually doesn't affect too much
> >of a change... and can be viewed as initializing it at the start of the
> >first basic block where it's referenced.
> >
> > So - control flow really isn't too much of an issue here, the register
> >lifetime isn't extended and the variable is (presumable correctly)
> >initialized.  
> 
> Nope.  The compiler can't move the initialization significantly if the
> flow of control is too complicated.  E.g., in:
> 
> foo() {
> 	int i, j = 0;
> 	for (i = 0; i < 2000; ++i)
> 		if (i = 1000)
> 			j = 1;
> 	test(j);
> }
> 
> the first initialization of j is bogus, but this is not obvious, and at
> least gcc -O3 has to initialize j before the for loop since it can't
> tell where inside the for loop j is initialized.

 I believe I seen some ideas in the literature that could accomplish this.

 But - I have no idea what GCC is capable of...  certainly, one
can easily believe that most compilers don't spend the time to
consider situations as deeply as could be done...

 So, upon reflection,  - I agree - in general; you can't expect 
the compiler to move the initialization forward.

	- Dave R. -



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199705211357.JAA29635>