This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

spurious warnings when optimizing with exceptions


hi,
Recently egcs++ seems to have got better about not giving bogus
'<somevar> might be used uninitialized' warnings when optimizing code
involving exception specifications, throw and catch. However I've come
across the following example which is not only unneeded but mentions
variables which are from inside inlined functions.

This is the 08-16 snapshot

--begin uninit.ii
struct S
{
  int flag;
  int v1;
  int v2;
  
  inline S(int v1_, int v2_) throw()  
    :v1(v1_), v2(v2_){}
};

inline S Bink(int i) throw()  
{
  return S(1, i);
}

int Foo();

void Bar(S, S);

inline int Quux() throw(char)
{
  return Foo();
}

static void Finkle(int a1)
{
  int a2 = Quux();
  
  Bar(Bink(a1), Bink(a2));
  
}
--end uninit.ii
--begin session log
nathan@laie:422>egcs-0816-g++ -v -O2 -W -c uninit.ii  
Reading specs from
/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.54/specs
gcc version egcs-2.91.54 19980816 (gcc2 ss-980609 experimental)

/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.54/cc1plus
uninit.ii -quiet -O2 -W -version -o /var/tmp/ccyEseMJ.s
GNU C++ version egcs-2.91.54 19980816 (gcc2 ss-980609 experimental)
(sparc-sun-solaris2.5.1) compiled by GNU C version 2.8.1.
uninit.ii: In function `void Finkle(int)':
uninit.ii:27: warning: `int a2' might be used uninitialized in this
function
uninit.ii:29: warning: `int i' might be used uninitialized in this
function
uninit.ii:13: warning: `int v2_' might be used uninitialized in this
function
 /usr/ccs/bin/as -V -Qy -s -o uninit.o /var/tmp/ccyEseMJ.s
/usr/ccs/bin/as: SC4.2 dev 30 Nov 1995
--end session log

Both -W and -O2 are necessary.

The line in causing all the problem is the call
	Bar(Bink(v1), Bink(v2);
inside Finkle(). `a2' must be initialized at line 27 before it's used in
that call. `i' is Bink's parameter and must be initialized before use --
notice that i is declared at line 11 not line 29. Finally `v2_' is S's
ctor's second argument, and again must have been set before it's used.

The unused field S::flag is necessary to elucidate the warning, it
doesn't matter whether it's initialized in the ctor or not. inline Quux
is necessary too and so is a two parameter Bar() function.

nathan

-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
      You can up the bandwidth, but you can't up the speed of light      
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]