public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/96295] New: Wmaybe-uninitialized warning for range operator with empty range struct
@ 2020-07-23 7:56 vries at gcc dot gnu.org
2020-07-23 15:08 ` [Bug tree-optimization/96295] [11 Regression] -Wmaybe-uninitialized warning for range operator with reference to an empty struct msebor at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2020-07-23 7:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96295
Bug ID: 96295
Summary: Wmaybe-uninitialized warning for range operator with
empty range struct
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: vries at gcc dot gnu.org
Target Milestone: ---
Consider test-case tui-winsource.c (minimized from gdb sources, filed as gdb PR
https://sourceware.org/bugzilla/show_bug.cgi?id=26282):
...
struct tui_source_window_iterator
{
public:
typedef tui_source_window_iterator self_type;
typedef void *value_type;
explicit tui_source_window_iterator (void *it, void *end) {}
explicit tui_source_window_iterator (void *it) {}
bool operator!= (const self_type &other) const { return false; }
value_type operator* () const { return (value_type)0; }
self_type &operator++ () { return *this; }
};
struct tui_source_windows
{
tui_source_window_iterator begin () const
{
return tui_source_window_iterator ((void *)0, (void *)0);
}
tui_source_window_iterator end () const
{
return tui_source_window_iterator ((void*)0);
}
};
void
foo (void)
{
for (void *win : tui_source_windows ())
{
(void)win;
}
}
...
With gcc-10, we have:
...
$ g++-10 -x c++ -Wall -O0 -g -c tui-winsource.c
...
And with gcc-11 (g++-11 (SUSE Linux) 11.0.0 20200720 (experimental) [revision
8764e9a3fc43f1117db77d1f056b6c3f15a29db3]):
...
$ g++-11 -x c++ -Wall -O0 -g -c tui-winsource.c
tui-winsource.c: In function ‘void foo()’:
tui-winsource.c:34:40: warning: ‘<unknown>’ may be used uninitialized
[-Wmaybe-uninitialized]
34 | for (void *win : tui_source_windows ())
| ^
tui-winsource.c:20:30: note: by argument 1 of type ‘const tui_source_windows*’
to ‘tui_source_window_iterator tui_source_windows::begin() const’ declared here
20 | tui_source_window_iterator begin () const
| ^~~~~
tui-winsource.c:34:40: note: ‘<anonymous>’ declared here
34 | for (void *win : tui_source_windows ())
| ^
...
At gimple, we have:
...
struct tui_source_windows & __for_range;
struct tui_source_windows D.2465;
try
{
__for_range = &D.2465;
tui_source_windows::begin (__for_range);
tui_source_windows::end (__for_range);
...
So, strictly speaking the warning is correct, because &D.2465 is not
initialized, and consequently __for_range is not initialized when it is passed
as argument to tui_source_windows::begin.
But it shouldn't matter, because struct tui_source_windows is an empty struct.
Workaround is to add:
...
struct tui_source_windows
{
+ tui_source_windows () {}
tui_source_window_iterator begin () const
...
which gives us:
...
struct tui_source_windows & __for_range;
struct tui_source_windows D.2469;
try
{
tui_source_windows::tui_source_windows (&D.2469);
__for_range = &D.2469;
tui_source_windows::begin (__for_range);
tui_source_windows::end (__for_range);
...
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/96295] [11 Regression] -Wmaybe-uninitialized warning for range operator with reference to an empty struct
2020-07-23 7:56 [Bug tree-optimization/96295] New: Wmaybe-uninitialized warning for range operator with empty range struct vries at gcc dot gnu.org
@ 2020-07-23 15:08 ` msebor at gcc dot gnu.org
2020-09-15 19:01 ` msebor at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-07-23 15:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96295
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |11.0
Summary|Wmaybe-uninitialized |[11 Regression]
|warning for range operator |-Wmaybe-uninitialized
|with empty range struct |warning for range operator
| |with reference to an empty
| |struct
Status|UNCONFIRMED |ASSIGNED
Ever confirmed|0 |1
Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org
Last reconfirmed| |2020-07-23
CC| |msebor at gcc dot gnu.org
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed. The warning detects and avoids triggering for objects of empty
types but in the test case __for_range is a reference to such an object and the
logic doesn't consider those. The tweak below makes the warning go away. Let
me handle this.
diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c
index 2f0ff724cde..fa88cad841c 100644
--- a/gcc/tree-ssa-uninit.c
+++ b/gcc/tree-ssa-uninit.c
@@ -401,6 +401,8 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs,
tree rhs,
The first_field() test is important for C++ where the predicate
alone isn't always sufficient. */
tree rhstype = TREE_TYPE (rhs);
+ if (POINTER_TYPE_P (rhstype))
+ rhstype = TREE_TYPE (rhstype);
if (TYPE_EMPTY_P (rhstype)
|| (RECORD_OR_UNION_TYPE_P (rhstype)
&& (!first_field (rhstype)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/96295] [11 Regression] -Wmaybe-uninitialized warning for range operator with reference to an empty struct
2020-07-23 7:56 [Bug tree-optimization/96295] New: Wmaybe-uninitialized warning for range operator with empty range struct vries at gcc dot gnu.org
2020-07-23 15:08 ` [Bug tree-optimization/96295] [11 Regression] -Wmaybe-uninitialized warning for range operator with reference to an empty struct msebor at gcc dot gnu.org
@ 2020-09-15 19:01 ` msebor at gcc dot gnu.org
2020-09-16 19:24 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-09-15 19:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96295
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |11.0
Keywords| |patch
Known to work| |10.2.0
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2020-September/553996.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/96295] [11 Regression] -Wmaybe-uninitialized warning for range operator with reference to an empty struct
2020-07-23 7:56 [Bug tree-optimization/96295] New: Wmaybe-uninitialized warning for range operator with empty range struct vries at gcc dot gnu.org
2020-07-23 15:08 ` [Bug tree-optimization/96295] [11 Regression] -Wmaybe-uninitialized warning for range operator with reference to an empty struct msebor at gcc dot gnu.org
2020-09-15 19:01 ` msebor at gcc dot gnu.org
@ 2020-09-16 19:24 ` cvs-commit at gcc dot gnu.org
2020-09-16 19:25 ` msebor at gcc dot gnu.org
2020-09-17 16:24 ` msebor at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-16 19:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96295
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:
https://gcc.gnu.org/g:8b75204b27cb2a296ac329d48918992b4053c61e
commit r11-3237-g8b75204b27cb2a296ac329d48918992b4053c61e
Author: Martin Sebor <msebor@redhat.com>
Date: Wed Sep 16 13:23:31 2020 -0600
Work harder to avoid -Wuninitialized for objects of empty structs (PR
middle-end/96295).
Resolves:
PR middle-end/96295 - -Wmaybe-uninitialized warning for range operator with
reference to an empty struct
gcc/ChangeLog:
PR middle-end/96295
* tree-ssa-uninit.c (maybe_warn_operand): Work harder to avoid
warning for objects of empty structs
gcc/testsuite/ChangeLog:
PR middle-end/96295
* g++.dg/warn/Wuninitialized-11.C: New test.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/96295] [11 Regression] -Wmaybe-uninitialized warning for range operator with reference to an empty struct
2020-07-23 7:56 [Bug tree-optimization/96295] New: Wmaybe-uninitialized warning for range operator with empty range struct vries at gcc dot gnu.org
` (2 preceding siblings ...)
2020-09-16 19:24 ` cvs-commit at gcc dot gnu.org
@ 2020-09-16 19:25 ` msebor at gcc dot gnu.org
2020-09-17 16:24 ` msebor at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-09-16 19:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96295
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Fixed in r11-3237.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/96295] [11 Regression] -Wmaybe-uninitialized warning for range operator with reference to an empty struct
2020-07-23 7:56 [Bug tree-optimization/96295] New: Wmaybe-uninitialized warning for range operator with empty range struct vries at gcc dot gnu.org
` (3 preceding siblings ...)
2020-09-16 19:25 ` msebor at gcc dot gnu.org
@ 2020-09-17 16:24 ` msebor at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-09-17 16:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96295
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |vincent.lebourlot@starqube.
| |com
--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
*** Bug 97067 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-09-17 16:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-23 7:56 [Bug tree-optimization/96295] New: Wmaybe-uninitialized warning for range operator with empty range struct vries at gcc dot gnu.org
2020-07-23 15:08 ` [Bug tree-optimization/96295] [11 Regression] -Wmaybe-uninitialized warning for range operator with reference to an empty struct msebor at gcc dot gnu.org
2020-09-15 19:01 ` msebor at gcc dot gnu.org
2020-09-16 19:24 ` cvs-commit at gcc dot gnu.org
2020-09-16 19:25 ` msebor at gcc dot gnu.org
2020-09-17 16:24 ` msebor 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).