public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114631] New: Inconsistent behavior with infinite loops?
@ 2024-04-07 22:23 kubry at gmx dot com
  2024-04-07 22:26 ` [Bug c++/114631] " kubry at gmx dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: kubry at gmx dot com @ 2024-04-07 22:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114631

            Bug ID: 114631
           Summary: Inconsistent behavior with infinite loops?
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kubry at gmx dot com
  Target Milestone: ---

Dear GCC developers,

First of all, thanks for your work!

This programs works as it is expected (it never stops):

```
#include <iostream>

int main()
{
    double doub;

    // This line caused a «warning: comparing floating point with == or != is
unsafe [-Wfloat-equal]»
    for (doub = 1.1; doub != 1.5; doub = doub + 0.1)
    {
        std::cout << doub << " ";
    }

    // "doubles" are not good enough for this program, the program should not
arrive there
    std::cout << "double is ok." << std::endl;
}
```

however, if we remove the `std::cout << doub << " ";` line... the program stops
(!).

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/114631] Inconsistent behavior with infinite loops?
  2024-04-07 22:23 [Bug c++/114631] New: Inconsistent behavior with infinite loops? kubry at gmx dot com
@ 2024-04-07 22:26 ` kubry at gmx dot com
  2024-04-07 22:28 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: kubry at gmx dot com @ 2024-04-07 22:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114631

--- Comment #1 from Ganton <kubry at gmx dot com> ---
Maybe this can be useful: "if we remove the `std::cout << doub << " ";` line...
the program stops"... does that happen because an "aggressive"(?🤔) optimization
is made (without warning the user)? 

If we add a `for(;;);` after the `double doub;` line, then the program never
stops. If an "aggressive"(?🤔) optimization is made, why is made for one loop
but not for the other loop? Is that inconsistent?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/114631] Inconsistent behavior with infinite loops?
  2024-04-07 22:23 [Bug c++/114631] New: Inconsistent behavior with infinite loops? kubry at gmx dot com
  2024-04-07 22:26 ` [Bug c++/114631] " kubry at gmx dot com
@ 2024-04-07 22:28 ` pinskia at gcc dot gnu.org
  2024-04-07 22:31 ` kubry at gmx dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-07 22:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114631

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So the C++ standard requires forward progress, otherwise it is undefined
behavior (except if the condition is a constant expression which evaluates to
true [See https://wg21.link/P2809R3]) .

*** This bug has been marked as a duplicate of bug 93041 ***

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/114631] Inconsistent behavior with infinite loops?
  2024-04-07 22:23 [Bug c++/114631] New: Inconsistent behavior with infinite loops? kubry at gmx dot com
  2024-04-07 22:26 ` [Bug c++/114631] " kubry at gmx dot com
  2024-04-07 22:28 ` pinskia at gcc dot gnu.org
@ 2024-04-07 22:31 ` kubry at gmx dot com
  2024-04-07 22:39 ` pinskia at gcc dot gnu.org
  2024-04-08 20:08 ` kubry at gmx dot com
  4 siblings, 0 replies; 6+ messages in thread
From: kubry at gmx dot com @ 2024-04-07 22:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114631

--- Comment #3 from Ganton <kubry at gmx dot com> ---
Note: That code was initially aimed for `decimal32` testing
(https://bugreports.qt.io/browse/QTBUG-33026) because using `decimal32` instead
of `double`... the `for (doub = [...]` loop is not infinite. 

When that page (https://bugreports.qt.io/browse/QTBUG-33026) was written, the
behavior of GCC was not like the described in this bug report (because the `for
(doub = [...]` infinite loop was always taken into account). Do we have a
regression? 🤔

Keep up the good work! Thanks a lot for GCC!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/114631] Inconsistent behavior with infinite loops?
  2024-04-07 22:23 [Bug c++/114631] New: Inconsistent behavior with infinite loops? kubry at gmx dot com
                   ` (2 preceding siblings ...)
  2024-04-07 22:31 ` kubry at gmx dot com
@ 2024-04-07 22:39 ` pinskia at gcc dot gnu.org
  2024-04-08 20:08 ` kubry at gmx dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-07 22:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114631

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Ganton from comment #3)
> When that page (https://bugreports.qt.io/browse/QTBUG-33026) was written,
> the behavior of GCC was not like the described in this bug report (because
> the `for (doub = [...]` infinite loop was always taken into account). Do we
> have a regression? 🤔

No, the removal of loops which cannot prove being finite was added in GCC 10
(which was released in 2020) while the issue you pointed to was written up in
2013 which was GCC 4.8.x timeframe. In this case C++ standard has not changed,
just GCC started to optimize more based on what the standard says is allowed.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/114631] Inconsistent behavior with infinite loops?
  2024-04-07 22:23 [Bug c++/114631] New: Inconsistent behavior with infinite loops? kubry at gmx dot com
                   ` (3 preceding siblings ...)
  2024-04-07 22:39 ` pinskia at gcc dot gnu.org
@ 2024-04-08 20:08 ` kubry at gmx dot com
  4 siblings, 0 replies; 6+ messages in thread
From: kubry at gmx dot com @ 2024-04-08 20:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114631

--- Comment #5 from Ganton <kubry at gmx dot com> ---
Thanks for the detailed information, Andrew!

If anybody reads this bug report: The reported problems are seen using GCC
13.2.0 and `-O2`, but not using `-O1` nor `-O0`.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-04-08 20:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-07 22:23 [Bug c++/114631] New: Inconsistent behavior with infinite loops? kubry at gmx dot com
2024-04-07 22:26 ` [Bug c++/114631] " kubry at gmx dot com
2024-04-07 22:28 ` pinskia at gcc dot gnu.org
2024-04-07 22:31 ` kubry at gmx dot com
2024-04-07 22:39 ` pinskia at gcc dot gnu.org
2024-04-08 20:08 ` kubry at gmx dot com

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).