public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/112637] New: Bogus -Wmaybe-uninitialized warning
@ 2023-11-20 13:24 dangelog at gmail dot com
2023-11-21 0:40 ` [Bug tree-optimization/112637] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: dangelog at gmail dot com @ 2023-11-20 13:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112637
Bug ID: 112637
Summary: Bogus -Wmaybe-uninitialized warning
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: dangelog at gmail dot com
Target Milestone: ---
Testcase from Qt: https://gcc.godbolt.org/z/6brn9Knra
class QBenchmarkIterationController
{
public:
QBenchmarkIterationController() noexcept;
bool isDone() const noexcept;
void next() noexcept;
};
class QBenchmarkIterationControllerWrapper {
QBenchmarkIterationController controller;
bool first = true;
public:
QBenchmarkIterationControllerWrapper() = default;
bool isDone() const noexcept { return !first && controller.isDone(); }
void next() noexcept { first = false; controller.next(); }
};
int f() noexcept;
void check(bool);
void testcase()
{
int result;
for (QBenchmarkIterationControllerWrapper w; !w.isDone(); w.next())
result = f();
check(result == 42);
}
With warnings enabled and any level of optimization enabled, results in:
<source>: In function 'void testcase()':
<source>:31:10: warning: 'result' may be used uninitialized
[-Wmaybe-uninitialized]
31 | check(result == 42);
| ~~~~~^~~~~~~~~~~~~~
<source>:26:9: note: 'result' was declared here
26 | int result;
| ^~~~~~
But this is bogus, as the loop is always entered at least once.
Removing the declaration of QBenchmarkIterationController's constructor makes
the warning disappear.
Upstream Qt patch discussion:
https://codereview.qt-project.org/c/qt/qtbase/+/518574
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug tree-optimization/112637] Bogus -Wmaybe-uninitialized warning
2023-11-20 13:24 [Bug tree-optimization/112637] New: Bogus -Wmaybe-uninitialized warning dangelog at gmail dot com
@ 2023-11-21 0:40 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-21 0:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112637
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2023-11-21
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>and any level of optimization enabled,
No, it just at -O1, -Os and -Og. At -O2 and -O3 we are able to optimize the
first load of w.first out and end up with no uninitialized variable warning.
Basically it comes down to this:
```
QBenchmarkIterationController::QBenchmarkIterationController (&w.controller);
w.first = 1;
goto <bb 4>; [100.00%]
....
<bb 4> [local count: 1073741824]:
# result_4 = PHI <result_8(D)(2), result_13(3)>
_18 = w.first;
if (_18 != 0)
goto <bb 7>; [67.00%]
else
goto <bb 5>; [33.00%]
```
not being optimized ... I am not so sure if this is fixable, especially at -Og.
-Os might be. -O1 is in a similar situtation as -Os though. compile speed vs
runtime speed ...
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-21 0:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-20 13:24 [Bug tree-optimization/112637] New: Bogus -Wmaybe-uninitialized warning dangelog at gmail dot com
2023-11-21 0:40 ` [Bug tree-optimization/112637] " pinskia 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).