public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/115267] New: Undue warning about undefined behavior in
@ 2024-05-29 3:51 tobi at gcc dot gnu.org
2024-05-29 7:45 ` [Bug tree-optimization/115267] [14./15 Regression] Undue warning about undefined behavior in loop with varying limits rguenth at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: tobi at gcc dot gnu.org @ 2024-05-29 3:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115267
Bug ID: 115267
Summary: Undue warning about undefined behavior in
Product: gcc
Version: 14.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: tobi at gcc dot gnu.org
Target Milestone: ---
This seems to be a simpler case of PR103724. I originally observed it with 4.9
but was able to reproduce it with gcc 14.
Godbolt: https://godbolt.org/z/6h8bEYsvP
=== Testcase ===================
#include <iostream>
#include <sstream>
double arr[4];
void read(std::istream& is) {
for (unsigned int i = 0; i < 2; ++i) {
for (unsigned int j = i; j < 2; ++j) {
is >> arr[2*i+j];
if (i != j) {
arr[2*j+i] = arr[2*i+j];
}
}
}
}
int main()
{
std::stringstream ss("1 2 3");
read(ss);
return int(arr[0] + arr[1]);
}
===
Gives with -O3 -Wall:
=========================
<source>:11:39: warning: iteration 4 invokes undefined behavior
[-Waggressive-loop-optimizations]
11 | arr[2*j+i] = arr[2*i+j];
| ~~~~~~~~~^
<source>:8:36: note: within this loop
8 | for (unsigned int j = i; j < 2; ++j) {
|
==========================
Try as I might, I don't see the undefined behavior, the matrix is also
correctly filled in, no infinite loop obtains. Signedness of the loop index
doesn't play a role. The original code used a Eigen::Matrix2d instead of
manually indexing the 2x2 matirx, and then the warning is about iteration 2.
The stringstream seems to be necessary to confuse the compiler enough, but
maybe there's a way of getting the same behavior with a less complex thing
inside the loop.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug tree-optimization/115267] [14./15 Regression] Undue warning about undefined behavior in loop with varying limits
2024-05-29 3:51 [Bug tree-optimization/115267] New: Undue warning about undefined behavior in tobi at gcc dot gnu.org
@ 2024-05-29 7:45 ` rguenth at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-05-29 7:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115267
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
CC| |rguenth at gcc dot gnu.org
Known to work| |13.3.0
Summary|Undue warning about |[14./15 Regression] Undue
|undefined behavior in loop |warning about undefined
|with varying limits |behavior in loop with
| |varying limits
Known to fail| |14.1.0, 15.0
Priority|P3 |P2
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Target Milestone|--- |14.2
Last reconfirmed| |2024-05-29
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. We're confusing ourselves with splitting the loop, I haven't digged
how we confuse ourselves yet. -fno-split-loops avoids the diagnostic.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-29 7:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-29 3:51 [Bug tree-optimization/115267] New: Undue warning about undefined behavior in tobi at gcc dot gnu.org
2024-05-29 7:45 ` [Bug tree-optimization/115267] [14./15 Regression] Undue warning about undefined behavior in loop with varying limits rguenth 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).