* [Bug analyzer/98447] incorrect -Wanalyzer-shift-count-overflow warning
2020-12-26 0:51 [Bug analyzer/98447] New: incorrect -Wanalyzer-shift-count-overflow warning vincent-gcc at vinc17 dot net
@ 2020-12-26 16:35 ` vincent-gcc at vinc17 dot net
2020-12-26 18:17 ` vincent-gcc at vinc17 dot net
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2020-12-26 16:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98447
--- Comment #1 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
This is probably due to commit 5e00ad3ffbfb4df7242c313a0d836f5b538eb2fb (where
this warning was introduced, as requested by PR97424).
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug analyzer/98447] incorrect -Wanalyzer-shift-count-overflow warning
2020-12-26 0:51 [Bug analyzer/98447] New: incorrect -Wanalyzer-shift-count-overflow warning vincent-gcc at vinc17 dot net
2020-12-26 16:35 ` [Bug analyzer/98447] " vincent-gcc at vinc17 dot net
@ 2020-12-26 18:17 ` vincent-gcc at vinc17 dot net
2020-12-26 18:21 ` vincent-gcc at vinc17 dot net
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2020-12-26 18:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98447
--- Comment #2 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
Note: The warning occurs when the compiler knows that b < 63 in the "if" case
(it occurs up to "n = r % 64", but not with "n = r % 65") so that the condition
"b + 1 >= 64" is always false. I suppose that the p[i--] line has already been
simplified to something equivalent to
p[i--] = 1UL << (b + 1);
but the analyzer doesn't see that b has restricted values in the "if" case.
if (n > b)
{
p[i--] = 1UL << (b + 1);
b += 64;
}
triggers the warning, but not
if (63 > b)
{
p[i--] = 1UL << (b + 1);
b += 64;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug analyzer/98447] incorrect -Wanalyzer-shift-count-overflow warning
2020-12-26 0:51 [Bug analyzer/98447] New: incorrect -Wanalyzer-shift-count-overflow warning vincent-gcc at vinc17 dot net
2020-12-26 16:35 ` [Bug analyzer/98447] " vincent-gcc at vinc17 dot net
2020-12-26 18:17 ` vincent-gcc at vinc17 dot net
@ 2020-12-26 18:21 ` vincent-gcc at vinc17 dot net
2020-12-26 18:47 ` vincent-gcc at vinc17 dot net
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2020-12-26 18:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98447
--- Comment #3 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
And the warning is triggered with the initial "b = 63", but not "b = 62" and
smaller values.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug analyzer/98447] incorrect -Wanalyzer-shift-count-overflow warning
2020-12-26 0:51 [Bug analyzer/98447] New: incorrect -Wanalyzer-shift-count-overflow warning vincent-gcc at vinc17 dot net
` (2 preceding siblings ...)
2020-12-26 18:21 ` vincent-gcc at vinc17 dot net
@ 2020-12-26 18:47 ` vincent-gcc at vinc17 dot net
2021-01-29 13:50 ` vincent-gcc at vinc17 dot net
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2020-12-26 18:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98447
--- Comment #4 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
So this can be simplified to
void f (unsigned long *p, int r, int i)
{
int b = 64, n = r % 64;
while (i >= 0 && b >= 0)
{
if (b <= n)
p[i--] = 1UL << b;
b -= n;
}
}
Here, due to the "n = r % 64", one has n <= 63, so that "1UL << b" can be
executed only when b <= 63, and the shift is necessarily valid (no overflow).
This could be part of a more general bug: I also get the
-Wanalyzer-shift-count-overflow warning if I replace "n = r % 64" by "n = r".
While with the initial code, one is certain that the shift is valid, now this
depends on the value of r. But since the compiler doesn't know the condition
under which this function will be called, it should not assume that r may have
any value.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug analyzer/98447] incorrect -Wanalyzer-shift-count-overflow warning
2020-12-26 0:51 [Bug analyzer/98447] New: incorrect -Wanalyzer-shift-count-overflow warning vincent-gcc at vinc17 dot net
` (3 preceding siblings ...)
2020-12-26 18:47 ` vincent-gcc at vinc17 dot net
@ 2021-01-29 13:50 ` vincent-gcc at vinc17 dot net
2021-04-21 11:54 ` vincent-gcc at vinc17 dot net
2023-02-28 12:59 ` vincent-gcc at vinc17 dot net
6 siblings, 0 replies; 8+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2021-01-29 13:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98447
--- Comment #5 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
This is still failing (trunk). The test on godbolt:
https://godbolt.org/z/Yx7b1d
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug analyzer/98447] incorrect -Wanalyzer-shift-count-overflow warning
2020-12-26 0:51 [Bug analyzer/98447] New: incorrect -Wanalyzer-shift-count-overflow warning vincent-gcc at vinc17 dot net
` (4 preceding siblings ...)
2021-01-29 13:50 ` vincent-gcc at vinc17 dot net
@ 2021-04-21 11:54 ` vincent-gcc at vinc17 dot net
2023-02-28 12:59 ` vincent-gcc at vinc17 dot net
6 siblings, 0 replies; 8+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2021-04-21 11:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98447
--- Comment #6 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
On the test on godbolt, this is still failing with:
gcc (Compiler-Explorer-Build) 12.0.0 20210420 (experimental)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug analyzer/98447] incorrect -Wanalyzer-shift-count-overflow warning
2020-12-26 0:51 [Bug analyzer/98447] New: incorrect -Wanalyzer-shift-count-overflow warning vincent-gcc at vinc17 dot net
` (5 preceding siblings ...)
2021-04-21 11:54 ` vincent-gcc at vinc17 dot net
@ 2023-02-28 12:59 ` vincent-gcc at vinc17 dot net
6 siblings, 0 replies; 8+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2023-02-28 12:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98447
--- Comment #7 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
On https://godbolt.org/z/Yx7b1d this still fails with "x86-64 gcc (trunk)".
Moreover, several releases are affected: 11.1, 11.2, 11.3, 12.1, 12.2.
^ permalink raw reply [flat|nested] 8+ messages in thread