[Bug tree-optimization/44547] -Wuninitialized reports false warning in nested switch statements

anthony dot penniston at hotmail dot com gcc-bugzilla@gcc.gnu.org
Thu Jun 17 01:14:00 GMT 2010



------- Comment #2 from anthony dot penniston at hotmail dot com  2010-06-17 01:14 -------
(In reply to comment #1)
> Value range-propagation (VRP) does not work on disjoint ranges, so the compiler
> does not actually know that argc can only be 1, 2 or 4. I think there is
> already a PR about this but I cannot find it right now.
> 

I'm not sure VRP is the issue here (the values being range-like was merely a
coincidence). Consider the following two equivalent examples:

int main( int argc, char *argv[] )
{
 if( argc == 111 || argc == 999 )
 {
  int n;
  if( argc == 111 || argc == 999 )
   n = argc;
  return n;
 }
}

int main( int argc, char *argv[] )
{
 switch( argc )
 {
  case 111:
  case 999:
  {
   int n;
   switch( argc )
   {
    case 111:
    case 999:
     n = argc;
   }
   return n;
  }
 }
}

In both examples - as with the example in the original report -  the compiler
is given the exact same information, namely that after the first switch/if
statement, the values on argc are constrained to either 111 or 999 (and thus
the following switch/if must necessarily cover all values of argc and n is
always used initialized). The only difference is that, in the example using
switch statements, the compiler seems to "forget" these constraints on argc.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44547



More information about the Gcc-bugs mailing list