public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable
@ 2005-05-13 14:46 schwab at suse dot de
  2005-05-13 14:53 ` [Bug c/21548] " pinskia at gcc dot gnu dot org
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: schwab at suse dot de @ 2005-05-13 14:46 UTC (permalink / raw)
  To: gcc-bugs

$ cat uninit.c 
static int blocksize = 4096; 
 
int bar (int); 
 
void foo (void) 
{ 
  int toread; 
  int bytes; 
  static char eof_reached = 0; 
 
  toread = blocksize; 
 
  while (toread != 0) 
    { 
      bytes = bar (toread); 
      if (bytes <= 0) 
	{ 
	  if (bytes < 0) 
	    continue; 
	  break; 
	} 
      toread -= bytes; 
    } 
 
  if (bytes == 0) 
    eof_reached = 1; 
} 
$ gcc -O2 -Wall -c uninit.c  
uninit.c: In function &#8216;foo&#8217;:  
uninit.c:25: warning: &#8216;bytes&#8217; is used uninitialized in this function  
  
This warning is wrong, since bytes is never used uninitialized as long as  
blocksize is non-zero.

-- 
           Summary: [4.0 regression] Wrong warning about uninitialized
                    variable
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: schwab at suse dot de
                CC: gcc-bugs at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
@ 2005-05-13 14:53 ` pinskia at gcc dot gnu dot org
  2005-05-13 14:55 ` schwab at suse dot de
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-13 14:53 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-13 14:53 -------
hmm, what happens if blocksize is zero when foo is entered.

-- 


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
  2005-05-13 14:53 ` [Bug c/21548] " pinskia at gcc dot gnu dot org
@ 2005-05-13 14:55 ` schwab at suse dot de
  2005-05-13 14:57 ` rearnsha at gcc dot gnu dot org
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: schwab at suse dot de @ 2005-05-13 14:55 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schwab at suse dot de  2005-05-13 14:54 -------
The program logic guarantees that blocksize is never zero. 

-- 


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
  2005-05-13 14:53 ` [Bug c/21548] " pinskia at gcc dot gnu dot org
  2005-05-13 14:55 ` schwab at suse dot de
@ 2005-05-13 14:57 ` rearnsha at gcc dot gnu dot org
  2005-05-13 14:59 ` schwab at suse dot de
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2005-05-13 14:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rearnsha at gcc dot gnu dot org  2005-05-13 14:57 -------
The compiler can't be expected to follow that logic.  If blocksize is set to
zero by some magic daemon, then the bytes would be undefined.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
                   ` (2 preceding siblings ...)
  2005-05-13 14:57 ` rearnsha at gcc dot gnu dot org
@ 2005-05-13 14:59 ` schwab at suse dot de
  2005-05-13 15:01 ` pinskia at gcc dot gnu dot org
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: schwab at suse dot de @ 2005-05-13 14:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schwab at suse dot de  2005-05-13 14:59 -------
To clarify, the problem is the "is used" part.  This should be "might be used" 
instead. 

-- 


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
                   ` (3 preceding siblings ...)
  2005-05-13 14:59 ` schwab at suse dot de
@ 2005-05-13 15:01 ` pinskia at gcc dot gnu dot org
  2005-05-13 15:01 ` schwab at suse dot de
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-13 15:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-13 15:01 -------
I also get the warning in 3.4.0 and 3.3.3 with your example, did you reduce it too far?

-- 


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
                   ` (4 preceding siblings ...)
  2005-05-13 15:01 ` pinskia at gcc dot gnu dot org
@ 2005-05-13 15:01 ` schwab at suse dot de
  2005-05-13 15:05 ` rearnsha at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: schwab at suse dot de @ 2005-05-13 15:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schwab at suse dot de  2005-05-13 15:00 -------
It is not _always_ uninitialized. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
                   ` (5 preceding siblings ...)
  2005-05-13 15:01 ` schwab at suse dot de
@ 2005-05-13 15:05 ` rearnsha at gcc dot gnu dot org
  2005-05-13 15:06 ` schwab at suse dot de
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2005-05-13 15:05 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rearnsha at gcc dot gnu dot org  2005-05-13 15:05 -------
It's nothing to do with ALWAYS.  It's to do with COULD BE.

There are values that blocksize COULD take that would lead to bytes being
uninitialized.  That's all the warning is telling you.

The compiler is correct to warn.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
                   ` (6 preceding siblings ...)
  2005-05-13 15:05 ` rearnsha at gcc dot gnu dot org
@ 2005-05-13 15:06 ` schwab at suse dot de
  2005-05-13 21:54 ` [Bug tree-optimization/21548] " pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: schwab at suse dot de @ 2005-05-13 15:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schwab at suse dot de  2005-05-13 15:06 -------
That's why it should say "might be used".  

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
                   ` (7 preceding siblings ...)
  2005-05-13 15:06 ` schwab at suse dot de
@ 2005-05-13 21:54 ` pinskia at gcc dot gnu dot org
  2005-05-13 22:14 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-13 21:54 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 907 bytes --]


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-13 21:54 -------
In 4.1.0, we give:
t.c:8: warning: ‘bytes’ may be used uninitialized in this function


So this is only a 4.0.0 bug, let me see how it is considered as "is used".

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
          Component|c                           |tree-optimization
     Ever Confirmed|                            |1
      Known to fail|                            |4.0.0
      Known to work|                            |4.1.0 3.4.0
   Last reconfirmed|0000-00-00 00:00:00         |2005-05-13 21:54:06
               date|                            |
   Target Milestone|---                         |4.0.1


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
                   ` (8 preceding siblings ...)
  2005-05-13 21:54 ` [Bug tree-optimization/21548] " pinskia at gcc dot gnu dot org
@ 2005-05-13 22:14 ` pinskia at gcc dot gnu dot org
  2005-05-13 22:16 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-13 22:14 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-13 22:14 -------
Actually rethinking the problem, the only time we could execute the "if(bytes == 0)" is not going 
through the loop.  Maybe the order in execute_late_warn_uninitialized should be switched around but 
that will not fix this case as we already found that is the only time we can get there.  Hmm, I think we 
are now missing a jump thread opportunity on the mainline then.

-- 


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
                   ` (9 preceding siblings ...)
  2005-05-13 22:14 ` pinskia at gcc dot gnu dot org
@ 2005-05-13 22:16 ` pinskia at gcc dot gnu dot org
  2005-05-13 22:23 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-13 22:16 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-13 22:16 -------
Maybe not.  Hmm, there might be a wrong code bug here on the 4.0 branch.

-- 


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
                   ` (10 preceding siblings ...)
  2005-05-13 22:16 ` pinskia at gcc dot gnu dot org
@ 2005-05-13 22:23 ` pinskia at gcc dot gnu dot org
  2005-05-13 22:44 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-13 22:23 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-13 22:23 -------
thinking again out loud:
The function could be changed to (which we seem to be missing on the mainline):
static int blocksize = 4096; 
 
int bar (int); 
 
void foo (void) 
{ 
  int toread; 
  int bytes; 
  static char eof_reached = 0;
 
  toread = blocksize; 
  while (1) 
    { 
      bytes = bar (toread); 
      if (bytes <= 0) 
        { 
          if (bytes < 0) 
            continue; 
          goto temp; 
        } 
      toread -= bytes; 
     if (toread == 0)
       goto temp1;
    } 
   
 
  if (bytes == 0) 
temp:
    eof_reached = 1; 
temp1:
} 

So comming out of the loop bytes will be zero if we break out of it but otherwise cannot, so we can skip 
if statement.  This is a missing optimization on the mainline (someone should look into it) but now my 
comment #10 becomes true and we see that it is always used as uninitized.


-- 


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
                   ` (11 preceding siblings ...)
  2005-05-13 22:23 ` pinskia at gcc dot gnu dot org
@ 2005-05-13 22:44 ` pinskia at gcc dot gnu dot org
  2005-07-08  1:37 ` mmitchel at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-13 22:44 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-13 22:44 -------
Note after fixing PR 21559, we will be back to "is used" warning instead of "may be used".

-- 


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
                   ` (12 preceding siblings ...)
  2005-05-13 22:44 ` pinskia at gcc dot gnu dot org
@ 2005-07-08  1:37 ` mmitchel at gcc dot gnu dot org
  2005-08-22 12:35 ` pinskia at gcc dot gnu dot org
  2005-09-27 16:23 ` mmitchel at gcc dot gnu dot org
  15 siblings, 0 replies; 17+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-07-08  1:37 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.0.1                       |4.0.2


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
                   ` (13 preceding siblings ...)
  2005-07-08  1:37 ` mmitchel at gcc dot gnu dot org
@ 2005-08-22 12:35 ` pinskia at gcc dot gnu dot org
  2005-09-27 16:23 ` mmitchel at gcc dot gnu dot org
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-22 12:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-22 12:25 -------
As I mentioned, this will be come a regression again once fixing PR 21559.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |21559


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/21548] [4.0 regression] Wrong warning about uninitialized variable
  2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
                   ` (14 preceding siblings ...)
  2005-08-22 12:35 ` pinskia at gcc dot gnu dot org
@ 2005-09-27 16:23 ` mmitchel at gcc dot gnu dot org
  15 siblings, 0 replies; 17+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-09-27 16:23 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.0.2                       |4.0.3


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


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2005-09-27 16:19 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-13 14:46 [Bug c/21548] New: [4.0 regression] Wrong warning about uninitialized variable schwab at suse dot de
2005-05-13 14:53 ` [Bug c/21548] " pinskia at gcc dot gnu dot org
2005-05-13 14:55 ` schwab at suse dot de
2005-05-13 14:57 ` rearnsha at gcc dot gnu dot org
2005-05-13 14:59 ` schwab at suse dot de
2005-05-13 15:01 ` pinskia at gcc dot gnu dot org
2005-05-13 15:01 ` schwab at suse dot de
2005-05-13 15:05 ` rearnsha at gcc dot gnu dot org
2005-05-13 15:06 ` schwab at suse dot de
2005-05-13 21:54 ` [Bug tree-optimization/21548] " pinskia at gcc dot gnu dot org
2005-05-13 22:14 ` pinskia at gcc dot gnu dot org
2005-05-13 22:16 ` pinskia at gcc dot gnu dot org
2005-05-13 22:23 ` pinskia at gcc dot gnu dot org
2005-05-13 22:44 ` pinskia at gcc dot gnu dot org
2005-07-08  1:37 ` mmitchel at gcc dot gnu dot org
2005-08-22 12:35 ` pinskia at gcc dot gnu dot org
2005-09-27 16:23 ` mmitchel at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).