public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/46684] New: GCC throws incorrect "may be used uninitialized" warnings
@ 2010-11-27 15:53 william@witt-family.net
2010-11-27 18:19 ` [Bug c/46684] " rguenth at gcc dot gnu.org
2012-10-24 23:52 ` manu at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: william@witt-family.net @ 2010-11-27 15:53 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46684
Summary: GCC throws incorrect "may be used uninitialized"
warnings
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: william@witt-family.net
Originally reported: https://bugzilla.novell.com/238855
% cat x2.c
enum BLA {A, C};
int f (enum BLA a, int i)
{
int ret, ret2;
switch (a) {
case A:
//ret2=42;
if (i) ret=1; else ret=3;
break;
case C:
ret = 2;
ret2=1;
break;
}
if (ret2 || ret)
return 42;
return 43;
}
(note the missing initialization of ret2 in the A arm). Now it doesn't
warn at all:
% gcc -c -W -Wall -O2 x2.c
%
Now, we can change it a bit more, and get "may be" warnings:
% cat x3.c
enum BLA {A, B, C};
int f (enum BLA a, int i)
{
int ret, ret2;
switch (a) {
case A: case B:
//if (i) ret=1; else ret=3;
ret = 1;
ret2=42;
break;
case C:
ret = 2;
ret2=1;
break;
}
if (i || ret || ret2)
return 42;
return 43;
}
Note the missing 'if' and the changed second if condition. It's now:
% gcc -c -W -Wall -O2 x3.c
x.c: In function ‘f’:
x.c:5: warning: ‘ret2’ may be used uninitialized in this function
x.c:5: warning: ‘ret’ may be used uninitialized in this function
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/46684] GCC throws incorrect "may be used uninitialized" warnings
2010-11-27 15:53 [Bug c/46684] New: GCC throws incorrect "may be used uninitialized" warnings william@witt-family.net
@ 2010-11-27 18:19 ` rguenth at gcc dot gnu.org
2012-10-24 23:52 ` manu at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2010-11-27 18:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46684
--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2010-11-27 18:14:45 UTC ---
As only constant initializers are involved CCP optimizes based on undefinedness
of uninitialized variables.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/46684] GCC throws incorrect "may be used uninitialized" warnings
2010-11-27 15:53 [Bug c/46684] New: GCC throws incorrect "may be used uninitialized" warnings william@witt-family.net
2010-11-27 18:19 ` [Bug c/46684] " rguenth at gcc dot gnu.org
@ 2012-10-24 23:52 ` manu at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: manu at gcc dot gnu.org @ 2012-10-24 23:52 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46684
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
CC| |manu at gcc dot gnu.org
Resolution| |DUPLICATE
--- Comment #2 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-10-24 23:52:06 UTC ---
(In reply to comment #1)
> As only constant initializers are involved CCP optimizes based on undefinedness
> of uninitialized variables.
Ergo, bug 18501.
*** This bug has been marked as a duplicate of bug 18501 ***
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-10-24 23:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-27 15:53 [Bug c/46684] New: GCC throws incorrect "may be used uninitialized" warnings william@witt-family.net
2010-11-27 18:19 ` [Bug c/46684] " rguenth at gcc dot gnu.org
2012-10-24 23:52 ` manu at gcc dot gnu.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).