User account creation filtered due to spam.

Bug 59223 - -Wmaybe-uninitialized and -Wuninitialized relationships
Summary: -Wmaybe-uninitialized and -Wuninitialized relationships
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Marek Polacek
URL:
Keywords:
: 60294 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-11-21 02:42 UTC by Vincent Lefèvre
Modified: 2014-02-27 08:06 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-02-26 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vincent Lefèvre 2013-11-21 02:42:20 UTC
With:
* gcc-4.8 (Debian 4.8.2-5) 4.8.2
* gcc (Debian 20131021-1) 4.9.0 20131021 (experimental) [trunk revision 203899]

It seems that -Wmaybe-uninitialized works only if -Wuninitialized is enabled. Moreover -Wmaybe-uninitialized is enabled by -Wuninitialized. I wonder whether this is intended or something is missing in the man page (the gcc 4.8.2 one doesn't say anything about these relationships).

xvii:~> cat tst2.c
int foo (int x)
{
  int y;
  if (x == 0)
    y = 1;
  else if (x == 1)
    y = 2;
  return y;
}

First test:

xvii:~> gcc-snapshot -O2 -Wmaybe-uninitialized -c tst2.c

No warning here; -Wuninitialized is needed to trigger the [-Wmaybe-uninitialized] warning (see below).

Second test:

xvii:~> gcc-snapshot -O2 -Wuninitialized -c tst2.c
tst2.c: In function 'foo':
tst2.c:8:3: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   return y;
   ^

The use of -Wuninitialized alone has enabled -Wmaybe-uninitialized.
Comment 1 Manuel López-Ibáñez 2013-11-21 03:29:30 UTC
I am pretty sure that this is an oversight when the option got renamed. In particular, this seems appropriate:

Index: tree-ssa-uninit.c
===================================================================
--- tree-ssa-uninit.c	(revision 205089)
+++ tree-ssa-uninit.c	(working copy)
@@ -2175,7 +2175,7 @@
 static bool
 gate_warn_uninitialized (void)
 {
-  return warn_uninitialized != 0;
+  return warn_uninitialized || warn_maybe_uninitialized;
 }



since the pass can warn for both options and the warnings are already guarded by the appropriate OPT_W* code.
Comment 2 Marek Polacek 2014-02-26 17:55:06 UTC
*** Bug 60294 has been marked as a duplicate of this bug. ***
Comment 3 Marek Polacek 2014-02-26 17:56:30 UTC
I'll post a patch.
Comment 4 Marek Polacek 2014-02-27 08:05:52 UTC
Author: mpolacek
Date: Thu Feb 27 08:05:21 2014
New Revision: 208196

URL: http://gcc.gnu.org/viewcvs?rev=208196&root=gcc&view=rev
Log:
	PR middle-end/59223
	* tree-ssa-uninit.c (gate_warn_uninitialized): Run the pass even for
	-Wmaybe-uninitialized.
testsuite/
	* c-c++-common/pr59223.c: New test.


Added:
    trunk/gcc/testsuite/c-c++-common/pr59223.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-uninit.c
Comment 5 Marek Polacek 2014-02-27 08:06:58 UTC
Fixed.