Bug 11371 - bogus warning and/or mis-optimization on ia64
Summary: bogus warning and/or mis-optimization on ia64
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.3
: P2 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-06-29 11:01 UTC by Debian GCC Maintainers
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: ia64-linux
Target: ia64-linux
Build: ia64-linux
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Debian GCC Maintainers 2003-06-29 11:01:32 UTC
[forwarded from http://bugs.debian.org/195834]

| troup@merulo:~/gdbm-1.8.3$ gcc -O2 -Wall -c gdbmopen.c
| gdbmopen.c: In function `gdbm_open':
| gdbmopen.c:15: warning: `lock_val' might be used uninitialized in this function

|   fstat (dbf->desc, &file_stat);
|
|   if ((flags & GDBM_OPENMASK) == GDBM_READER)
|   {
|       if (dbf->file_locking)
|         {
|           struct flock flock;
|           flock.l_type = F_RDLCK;
|           flock.l_whence = SEEK_SET;
|           flock.l_start = flock.l_len = 0L;
|           lock_val = fcntl (dbf->desc, F_SETLK, &flock);
|         }
|     }
|   else if (dbf->file_locking)
|     {
|       struct flock flock;
|       flock.l_type = F_WRLCK;
|       flock.l_whence = SEEK_SET;
|       flock.l_start = flock.l_len = 0L;
|       lock_val = fcntl (dbf->desc, F_SETLK, &flock);
|     }
|   if (dbf->file_locking && (lock_val != 0))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|     {
|       return NULL;
|     }

I think this warning is bogus because a) it only happens on ia64
(AFAICT, it doesn't happen on arm, i386 or hppa, at least), b) it only
happens with optimization turned on (disappears with -O0) and
c) if the (entirely unrelated) fstat call is commented out, the
warning disappears.  I also think that it's clear from the code above
that lock_val couldn't be used uninitialized unless I'm missing
something embarrassingly obvious.  Unfortunately I haven't been able
to determine if it's just a bogus warning or if the code's actually
being mis-compiled.

This isn't a regression, all previous versions of gcc (2.96, 3.0 and
3.2) for ia64 have the same problem and gcc-snapshot (20030531-2)
doesn't fix it.

http://people.debian.org/~troup/gcc/gdbm/ contains gdbmopen.{c,i},
fixed-gdbmopen.{c,i} (i.e. with the fstat commented out) and
orig-gdbmopen.{c,i} (the unreduced original file from gdbm 1.8.3).
Comment 1 Andrew Pinski 2003-06-29 13:47:12 UTC
This is a know documented defect of gcc's warning about uninitialized variables. In fact 
gcc should warn about it on all platforms but it does not.
Here is the sample from the documenation:
{
  int save_y;
  if (change_y) save_y = y, y = new_y;
  ...
  if (change_y) y = save_y;
} 

which is almost like your code but slightly different so this is not a bug.