public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/96658] New: Unhelpful -Wstrict-overflow warning from std::push_heap
@ 2020-08-17 13:19 redi at gcc dot gnu.org
2021-12-08 22:27 ` [Bug tree-optimization/96658] " msebor at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-17 13:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96658
Bug ID: 96658
Summary: Unhelpful -Wstrict-overflow warning from
std::push_heap
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
Reduced from https://stackoverflow.com/q/63405519/981959
This code produces a warning that is of zero value to users:
#include <algorithm>
void f(unsigned long* v) { std::push_heap(v, v+3); }
$ g++ -c -O3 -Wstrict-overflow=3 p.C
p.C: In function 'void std::push_heap(_RAIter, _RAIter) [with _RAIter = long
unsigned int*]':
p.C:2:52: warning: assuming signed overflow does not occur when changing X +-
C1 cmp C2 to X cmp C2 -+ C1 [-Wstrict-overflow]
2 | void f(unsigned long* v) { std::push_heap(v, v+3); }
| ^
The user doesn't have any signed integers, and the C1 cmp C2 expression doesn't
appear in the user's code (it doesn't even appear in the libstdc++ headers).
This warning seems totally useless to users. The library code is correct, no
useful location is shown to the user, and the user can't change the library
anyway.
The code can be simplified to:
template<typename T>
inline void
push_heap(T* first, T* last)
{
T value = (*(last - 1));
long holeIndex = last - first - 1;
long topIndex = 0;
long parent = (holeIndex - 1) / 2;
while (holeIndex > topIndex && *(first + parent) < value)
{
*(first + holeIndex) = *(first + parent);
holeIndex = parent;
parent = (holeIndex - 1) / 2;
}
*(first + holeIndex) = value;
}
void f(unsigned long* v) { push_heap(v, v+3); }
Which still warns and still shows no useful information:
p.C: In function 'void push_heap(T*, T*) [with T = long unsigned int]':
p.C:18:47: warning: assuming signed overflow does not occur when changing X +-
C1 cmp C2 to X cmp C2 -+ C1 [-Wstrict-overflow]
18 | void f(unsigned long* v) { push_heap(v, v+3); }
| ^
I know the documentation says that -Wstrict-overflow=3 easily gives false
positives, but this case seems especially unhelpful.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug tree-optimization/96658] Unhelpful -Wstrict-overflow warning from std::push_heap
2020-08-17 13:19 [Bug tree-optimization/96658] New: Unhelpful -Wstrict-overflow warning from std::push_heap redi at gcc dot gnu.org
@ 2021-12-08 22:27 ` msebor at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-12-08 22:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96658
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
CC| |msebor at gcc dot gnu.org
Known to fail| |10.3.0, 11.2.0, 12.0, 9.3.0
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-12-08
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed on trunk plus GCC 9, 10, 11 but not 8, so strictly speaking it's a
regression:
pr96658.C: In function ‘void push_heap(T*, T*) [with T = long unsigned int]’:
pr96658.C:19:47: warning: assuming signed overflow does not occur when changing
X +- C1 cmp C2 to X cmp C2 -+ C1 [-Wstrict-overflow]
19 | void f(unsigned long* v) { push_heap(v, v+3); }
| ^
The warning first appeared with r263875.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-08 22:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-17 13:19 [Bug tree-optimization/96658] New: Unhelpful -Wstrict-overflow warning from std::push_heap redi at gcc dot gnu.org
2021-12-08 22:27 ` [Bug tree-optimization/96658] " 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).