public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99101] New: optimization bug with -ffinite-loops
@ 2021-02-15  8:55 251078896 at qq dot com
  2021-02-15  9:43 ` [Bug tree-optimization/99101] " rguenth at gcc dot gnu.org
                   ` (23 more replies)
  0 siblings, 24 replies; 25+ messages in thread
From: 251078896 at qq dot com @ 2021-02-15  8:55 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99101
           Summary: optimization bug with -ffinite-loops
           Product: gcc
           Version: og10 (devel/omp/gcc-10)
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 251078896 at qq dot com
  Target Milestone: ---

we have a reduced code to show this bug:

#include <iostream>

class CompactMD {
 public:
  void operator()() {
    while (true) {
      auto num_job = jobs_;
      for (auto i = 0; i < jobs_; i++) SendNextMd();
      jobs_ -= num_job;
    }
  }
  void SendNextMd() {
    if (at_eof_) return;
    if (read_finish_) {
      at_eof_ = true;
      std::cout << 1 << std::endl;
    }
  }

  bool read_finish_ = true;
  int jobs_{1};
  bool at_eof_{false};
};

int main() {
  CompactMD comp_md_;
  comp_md_();
  return 0;
}

The expected output is only one line of "1", after that the program should be
in a "while true" loop forever.
With O2 optimization level, the output are infinite lines of "1"s.

We can reproduce this in RedHat's devtoolset-10, and Ubuntu 20.10's bundled
gcc10. After some tests, I find this bug is related to -ffinite-loops

This bug cannot be reproduced with gcc9 or lower version.

btw, I cannot further simplify this code for now, any change to it the bug is
likely to be gone.

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

end of thread, other threads:[~2021-03-03 19:52 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-15  8:55 [Bug c++/99101] New: optimization bug with -ffinite-loops 251078896 at qq dot com
2021-02-15  9:43 ` [Bug tree-optimization/99101] " rguenth at gcc dot gnu.org
2021-02-15 10:17 ` rguenth at gcc dot gnu.org
2021-02-15 10:25 ` 251078896 at qq dot com
2021-02-15 10:29 ` jakub at gcc dot gnu.org
2021-02-15 10:38 ` rguenth at gcc dot gnu.org
2021-02-15 10:46 ` rguenth at gcc dot gnu.org
2021-02-15 13:08 ` rguenth at gcc dot gnu.org
2021-02-24 14:00 ` rguenth at gcc dot gnu.org
2021-02-24 14:20 ` rguenth at gcc dot gnu.org
2021-02-24 14:41 ` rguenth at gcc dot gnu.org
2021-02-24 14:45 ` rguenth at gcc dot gnu.org
2021-02-24 15:09 ` rguenth at gcc dot gnu.org
2021-02-25 10:18 ` rguenth at gcc dot gnu.org
2021-02-25 11:34 ` rguenth at gcc dot gnu.org
2021-02-25 12:09 ` rguenth at gcc dot gnu.org
2021-02-25 12:40 ` rguenth at gcc dot gnu.org
2021-02-25 13:31 ` matz at gcc dot gnu.org
2021-02-25 18:29 ` matz at gcc dot gnu.org
2021-02-25 18:34 ` matz at gcc dot gnu.org
2021-02-26  9:38 ` rguenth at gcc dot gnu.org
2021-03-03 12:16 ` rguenth at gcc dot gnu.org
2021-03-03 14:00 ` matz at gcc dot gnu.org
2021-03-03 14:37 ` rguenth at gcc dot gnu.org
2021-03-03 19:52 ` hubicka 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).