public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98126] New: -Wsequence-point is non-linear for certain cases
@ 2020-12-03 17:47 mpolacek at gcc dot gnu.org
  2020-12-03 22:14 ` [Bug c++/98126] " mpolacek at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-12-03 17:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98126
           Summary: -Wsequence-point is non-linear for certain cases
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

This script generates C++ programs that show that -Wsequence-point exhibits
non-linear behavior:

#!/bin/bash
n=$1

printf "struct T { bool operator==(const T &ot) const; };
struct C {
  bool operator==(const C &ot) const {
    return\n"
for i in $(seq $n); do printf "      t$i == ot.t$i &&\n"; done
printf "      true; 
  }
"
for i in $(seq $n); do printf "  T t$i;\n"; done
printf "};\n"

$ ./gen.sh 100 > gen.cc && time -p ./cc1plus -quiet -fsyntax-only -Wall gen.cc
real 0.60
$ ./gen.sh 200 > gen.cc && time -p ./cc1plus -quiet -fsyntax-only -Wall gen.cc
real 4.50
$ ./gen.sh 300 > gen.cc && time -p ./cc1plus -quiet -fsyntax-only -Wall gen.cc
real 14.62
$ ./gen.sh 400 > gen.cc && time -p ./cc1plus -quiet -fsyntax-only -Wall gen.cc
real 34.46
$ ./gen.sh 500 > gen.cc && time -p ./cc1plus -quiet -fsyntax-only -Wall gen.cc
real 67.27
$ ./gen.sh 600 > gen.cc && time -p ./cc1plus -quiet -fsyntax-only -Wall gen.cc
real 117.33
$ ./gen.sh 700 > gen.cc && time -p ./cc1plus -quiet -fsyntax-only -Wall gen.cc
real 179.78
$ ./gen.sh 800 > gen.cc && time -p ./cc1plus -quiet -fsyntax-only -Wall gen.cc
real 278.54

Note that
$ ./gen.sh 800 > gen.cc && time -p ./cc1plus -quiet -fsyntax-only -Wall gen.cc
-Wno-sequence-point
real 0.14

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

* [Bug c++/98126] -Wsequence-point is non-linear for certain cases
  2020-12-03 17:47 [Bug c++/98126] New: -Wsequence-point is non-linear for certain cases mpolacek at gcc dot gnu.org
@ 2020-12-03 22:14 ` mpolacek at gcc dot gnu.org
  2020-12-07 16:56 ` cvs-commit at gcc dot gnu.org
  2020-12-07 17:00 ` mpolacek at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-12-03 22:14 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-12-03
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I have a (simple, stupid) patch.

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

* [Bug c++/98126] -Wsequence-point is non-linear for certain cases
  2020-12-03 17:47 [Bug c++/98126] New: -Wsequence-point is non-linear for certain cases mpolacek at gcc dot gnu.org
  2020-12-03 22:14 ` [Bug c++/98126] " mpolacek at gcc dot gnu.org
@ 2020-12-07 16:56 ` cvs-commit at gcc dot gnu.org
  2020-12-07 17:00 ` mpolacek at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-07 16:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:1cac89da2cb1f2a7c2d93f7f325484c2d1619ca8

commit r11-5826-g1cac89da2cb1f2a7c2d93f7f325484c2d1619ca8
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Dec 3 18:35:00 2020 -0500

    c-family: Fix hang with -Wsequence-point [PR98126]

    verify_sequence_points uses verify_tree to recursively walk the
    subexpressions of an expression, and while recursing, it also
    keeps lists of expressions found after/before a sequence point.
    For a large expression, the list can grow significantly.  And
    merge_tlist is at least N(n^2): for a list of length n it will
    iterate n(n -1) times, and call candidate_equal_p each time, and
    that can recurse further.  warn_for_collision also has to go
    through the whole list.  With a large-enough expression, the
    compilation can easily get stuck here for 24 hours.

    This patch is a simple kludge: if we see that the expression is
    overly complex, don't even try.

    gcc/c-family/ChangeLog:

            PR c++/98126
            * c-common.c (verify_tree_lim_r): New function.
            (verify_sequence_points): Use it.  Use nullptr instead of 0.

    gcc/testsuite/ChangeLog:

            PR c++/98126
            * g++.dg/warn/Wsequence-point-4.C: New test.

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

* [Bug c++/98126] -Wsequence-point is non-linear for certain cases
  2020-12-03 17:47 [Bug c++/98126] New: -Wsequence-point is non-linear for certain cases mpolacek at gcc dot gnu.org
  2020-12-03 22:14 ` [Bug c++/98126] " mpolacek at gcc dot gnu.org
  2020-12-07 16:56 ` cvs-commit at gcc dot gnu.org
@ 2020-12-07 17:00 ` mpolacek at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-12-07 17:00 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.  This *could* be backported to GCC 10, if someone wants to.

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

end of thread, other threads:[~2020-12-07 17:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-03 17:47 [Bug c++/98126] New: -Wsequence-point is non-linear for certain cases mpolacek at gcc dot gnu.org
2020-12-03 22:14 ` [Bug c++/98126] " mpolacek at gcc dot gnu.org
2020-12-07 16:56 ` cvs-commit at gcc dot gnu.org
2020-12-07 17:00 ` mpolacek 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).