public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/41952] New: False uninitialized variable warning
@ 2009-11-05 18:17 xinliangli at gmail dot com
2009-11-05 18:19 ` [Bug middle-end/41952] " xinliangli at gmail dot com
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: xinliangli at gmail dot com @ 2009-11-05 18:17 UTC (permalink / raw)
To: gcc-bugs
Compiling the following example with -Wuninitialized, 4.4 gcc will emit false
warning on uninitialized variable. In fact the definition is guarded by a
condition which is always true (coming from the assignment operator) for
locals. The solution is to fold the predicate (see proposed patch).
On 4.5, due to vsym related changes, the false positive warning issue is masked
(but false negative one occurs -- see a different PR). While this patch can be
used to fix the 4.4 issue, it is also applicable to 4.5 as a very safe
optimization. Is it ok to get it in at this stage?
#ifndef WORK_AROUND_GCC_4_4_0_BROKENNESS
#define WORK_AROUND_GCC_4_4_0_BROKENNESS 0
#endif
struct ExtentsBase {
ExtentsBase() : startx_(), endx_() { }
ExtentsBase(const ExtentsBase &b) {
*this = b;
}
const ExtentsBase & operator=(const ExtentsBase &b) {
if (this != &b || WORK_AROUND_GCC_4_4_0_BROKENNESS) {
startx_ = b.startx_;
}
return *this;
}
int startx_;
int endx_;
};
int f(const ExtentsBase &e1) {
ExtentsBase my_extents = e1;
return my_extents.startx_;
}
====================
self2.cc: In function 'int f(const ExtentsBase&)':
self2.cc:25: warning: 'my_extents' may be used uninitialized in this function
--
Summary: False uninitialized variable warning
Product: gcc
Version: 4.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: xinliangli at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41952
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/41952] False uninitialized variable warning
2009-11-05 18:17 [Bug middle-end/41952] New: False uninitialized variable warning xinliangli at gmail dot com
@ 2009-11-05 18:19 ` xinliangli at gmail dot com
2009-11-06 10:01 ` rguenth at gcc dot gnu dot org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: xinliangli at gmail dot com @ 2009-11-05 18:19 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from xinliangli at gmail dot com 2009-11-05 18:18 -------
Created an attachment (id=18975)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18975&action=view)
proposed patch
Bootstrapped and regression tested on x86-64 linux with gcc 4.5
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41952
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/41952] False uninitialized variable warning
2009-11-05 18:17 [Bug middle-end/41952] New: False uninitialized variable warning xinliangli at gmail dot com
2009-11-05 18:19 ` [Bug middle-end/41952] " xinliangli at gmail dot com
@ 2009-11-06 10:01 ` rguenth at gcc dot gnu dot org
2009-11-06 18:12 ` xinliangli at gmail dot com
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-11-06 10:01 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rguenth at gcc dot gnu dot org 2009-11-06 10:01 -------
Patches should go to gcc-patches, you need to add the testcase and you
should use auto_var_in_fn_p instead of !is_global_var.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |diagnostic, missed-
| |optimization
Last reconfirmed|0000-00-00 00:00:00 |2009-11-06 10:01:05
date| |
Summary|False uninitialized variable|False uninitialized variable
|warning |warning
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41952
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/41952] False uninitialized variable warning
2009-11-05 18:17 [Bug middle-end/41952] New: False uninitialized variable warning xinliangli at gmail dot com
2009-11-05 18:19 ` [Bug middle-end/41952] " xinliangli at gmail dot com
2009-11-06 10:01 ` rguenth at gcc dot gnu dot org
@ 2009-11-06 18:12 ` xinliangli at gmail dot com
2009-11-06 19:06 ` rguenth at gcc dot gnu dot org
2010-04-29 20:40 ` [Bug middle-end/41952] patch to improve Wuninitialized hjl dot tools at gmail dot com
4 siblings, 0 replies; 6+ messages in thread
From: xinliangli at gmail dot com @ 2009-11-06 18:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from xinliangli at gmail dot com 2009-11-06 18:11 -------
(In reply to comment #2)
> Patches should go to gcc-patches, you need to add the testcase and you
> should use auto_var_in_fn_p instead of !is_global_var.
>
auto_var_in_fn_p uses DECL_CONTEXT --- is it guaranteed to always point to the
enclosing functions even for inner block scoped locals (it seems so now).
David
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41952
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/41952] False uninitialized variable warning
2009-11-05 18:17 [Bug middle-end/41952] New: False uninitialized variable warning xinliangli at gmail dot com
` (2 preceding siblings ...)
2009-11-06 18:12 ` xinliangli at gmail dot com
@ 2009-11-06 19:06 ` rguenth at gcc dot gnu dot org
2010-04-29 20:40 ` [Bug middle-end/41952] patch to improve Wuninitialized hjl dot tools at gmail dot com
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-11-06 19:06 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from rguenth at gcc dot gnu dot org 2009-11-06 19:06 -------
Yes, the predicate is implemented correctly.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41952
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/41952] patch to improve Wuninitialized
2009-11-05 18:17 [Bug middle-end/41952] New: False uninitialized variable warning xinliangli at gmail dot com
` (3 preceding siblings ...)
2009-11-06 19:06 ` rguenth at gcc dot gnu dot org
@ 2010-04-29 20:40 ` hjl dot tools at gmail dot com
4 siblings, 0 replies; 6+ messages in thread
From: hjl dot tools at gmail dot com @ 2010-04-29 20:40 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from hjl dot tools at gmail dot com 2010-04-29 20:40 -------
Fixed by revision 158567:
http://gcc.gnu.org/ml/gcc-cvs/2010-04/msg00673.html
--
hjl dot tools at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.6.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41952
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-04-29 20:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-05 18:17 [Bug middle-end/41952] New: False uninitialized variable warning xinliangli at gmail dot com
2009-11-05 18:19 ` [Bug middle-end/41952] " xinliangli at gmail dot com
2009-11-06 10:01 ` rguenth at gcc dot gnu dot org
2009-11-06 18:12 ` xinliangli at gmail dot com
2009-11-06 19:06 ` rguenth at gcc dot gnu dot org
2010-04-29 20:40 ` [Bug middle-end/41952] patch to improve Wuninitialized hjl dot tools at gmail dot com
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).