Bug 179 - -Wuninitialized missing warning with &var
Summary: -Wuninitialized missing warning with &var
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 2.95
: P3 enhancement
Target Milestone: 4.4.0
Assignee: Not yet assigned to anyone
Keywords: diagnostic, xfail
: 17172 17191 (view as bug list)
Depends on:
Blocks: 19430 Wuninitialized
  Show dependency treegraph
Reported: 2000-04-22 00:16 UTC by martin
Modified: 2018-11-05 02:14 UTC (History)
5 users (show)

See Also:
Known to work: tree-ssa
Known to fail:
Last reconfirmed: 2007-08-16 10:19:12


Note You need to log in before you can comment on or make changes to this bug.
Description martin 2000-04-22 00:16:00 UTC
 Original-Message-Id: <m12ilS7-000QqwC@whopper.256.com>
 Date: Fri, 21 Apr 2000 17:59:07 -0400 (EDT)

 System and gcc version:

     Linux squirrel 2.2.14 #6 Mon Jan 31 14:32:43 EST 2000 i686 unknown
     gcc version 2.95.2 19991024 (release)

 The following program will not generate an error:

     #include <stdio.h>
     void foo(int *i_p) {}
     int main()
       int i;
       if (i) (void)printf("%d?\n", i);
       /* ^^^ use of unitialized variable */
       /*  ^^ the reason why it isn't reported */
       return 0;

 If you remove the foo(&i) or substitute a i = 1 then it will see that
 the if (i) line accesses a unitialized variable.

 I'd call it a bug although it might be a by-product of block processing
 in function.c.


[ Reported to the Debian BTS as report #117765.
  Please CC 117765@bugs.debian.org on replies.
  Log of report can be found at http://bugs.debian.org/117765 ]
 <precise description of the problem (multiple lines)>

[ rechecked with gcc-3_3-branch 20021227 ]

(Wall includes Wunitialized, but I included both as "belt and braces".)

chiark:~/gcc-problem:12$ gcc -c -g -O3 -Wall -Wuninitialized warning-test.c -o warning-test -DMHP_TEST_WARNING

Doesn't give any warning about the timeout not being initialised. (I've
tried with varying -O options, and with and without -c, none help.)

If I remove the never used sscanf it does.  (Note ptr is set to NULL and
never changed.)

chiark:~/gcc-problem:11$ gcc -c -g -O3 -Wall -Wuninitialized warning-test.c -o warning-test
warning-test.c: In function `main':
warning-test.c:8: warning: unused variable `ptr'
warning-test.c:6: warning: `timeout' might be used uninitialized in this function

This may be related to a bug reported in gcc 2.95 on the gcc Gnatsweb
(PR 179) at http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=179.  As I
am unsure I thought I'd report it anyway.

warning-test.c follows:
#include <stdio.h>
#include <stdlib.h>

int main (int argc, char ** argv)
  int timeout, timeout_offset;
  int rv;
  char * ptr = NULL;

  timeout_offset = 100;

  if (ptr) {
    sscanf(ptr+timeout_offset, "%d", &timeout);
    printf("Found timeout\n");

  rv = timeout;

  return rv;

2.95.x 3.x
Comment 1 Joseph S. Myers 2001-01-14 11:58:58 UTC
From: "Joseph S. Myers" <jsm28@cam.ac.uk>
To: gcc-gnats@gcc.gnu.org
Subject: c/179
Date: Sun, 14 Jan 2001 11:58:58 +0000 (GMT)

 I've entered a testcase for this bug as gcc.dg/uninit-B.c (XFAIL, as with
 many of the -Wuninitialized testcases).
 Joseph S. Myers

Comment 2 Nathanael C. Nerode 2002-10-30 16:57:03 UTC
From: Nathanael Nerode <neroden@twcny.rr.com>
To: martin@loewis.home.cs.tu-berlin.de, gcc-gnats@gcc.gnu.org,
   gcc-prs@gcc.gnu.org, jsm28@cam.ac.uk, gcc-bugs@gcc.gnu.org,
   nobody@gcc.gnu.org, gray.reply@256.com
Subject: Re: middle-end/179: gcc -O2 -Wuninitialized bug with &var under 2.95.2
Date: Wed, 30 Oct 2002 16:57:03 -0500

 Is this bug still valid against 3.x series gcc?

Comment 3 Nathanael C. Nerode 2003-03-12 16:03:44 UTC
From: Nathanael Nerode <neroden@twcny.rr.com>
To: gcc-gnats@gcc.gnu.org, martin@v.loewis.de, gray.reply@256.com,
   gcc-bugs@gcc.gnu.org, 117765@bugs.debian.org, jsm28@cam.ac.uk,
   nobody@gcc.gnu.org, gcc-prs@gcc.gnu.org
Subject: Re: middle-end/179: gcc -O2 -Wuninitialized bug ...
Date: Wed, 12 Mar 2003 16:03:44 -0500

 Confirmed still present in mainline (thanks to the XFAILed testcase).
Comment 4 Andrew Pinski 2003-11-16 00:09:35 UTC
Suspending as it is fixed on the tree-ssa branch.
Comment 5 Andrew Pinski 2003-12-17 00:40:24 UTC
Leaving as suspending as someone needs to update the testcase.
Comment 6 Andrew Pinski 2004-05-13 11:31:48 UTC
Fixed for 3.5.0 by the merge of the tree-ssa.
Comment 7 Andrew Pinski 2004-08-25 21:16:19 UTC
*** Bug 17191 has been marked as a duplicate of this bug. ***
Comment 8 Andrew Pinski 2004-08-25 21:16:54 UTC
*** Bug 17172 has been marked as a duplicate of this bug. ***
Comment 9 Manuel López-Ibáñez 2007-08-15 14:22:58 UTC
(In reply to comment #8)
> *** Bug 17172 has been marked as a duplicate of this bug. ***
I see that the xfail is still there, so how can this be fixed ?
Comment 10 Manuel López-Ibáñez 2007-08-16 10:19:12 UTC
Some analysis http://gcc.gnu.org/ml/gcc/2007-08/msg00271.html

Comment 11 Richard Biener 2008-01-13 15:40:59 UTC
Non-regressions should not have a target milestone set.
Comment 12 Manuel López-Ibáñez 2008-08-11 13:18:55 UTC


Comments welcome!
Comment 13 Manuel López-Ibáñez 2008-08-20 22:25:10 UTC
Subject: Bug 179

Author: manu
Date: Wed Aug 20 22:23:45 2008
New Revision: 139347

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139347
2008-08-21  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR middle-end/179
	* tree-ssa.c (warn_uninit): Do not warn for variables that can be
	initialized outside the current module.
	(warn_uninitialized_var): Ignore left-hand side when walking the
	trees. Ignore address expressions. Examine VUSE operands in gimple
	statements with a variable declaration on the right-hand side.
	* gcc.dg/uninit-6.c (make_something): Remove XFAIL.
	* gcc.dg/uninit-6-O0.c (make_something): Remove XFAIL.
	* gcc.dg/uninit-B.c (baz): Remove XFAIL.
	* gcc.dg/uninit-B-2.c: New.
	* gcc.dg/uninit-B-O0-2.c: New.
	* gcc.dg/uninit-pr19430-O0.c: New.
	* gcc.dg/uninit-pr19430.c: New.
	* gcc.dg/uninit-pr19430-2.c: New.


Comment 14 Manuel López-Ibáñez 2008-08-20 22:27:35 UTC
This is FIXED in GCC 4.4