public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cfsteefel at arista dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/107163] New: Compile time regression when using templated base classes, virtual method, and Wall
Date: Wed, 05 Oct 2022 19:35:24 +0000	[thread overview]
Message-ID: <bug-107163-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 107163
           Summary: Compile time regression when using templated base
                    classes, virtual method, and Wall
           Product: gcc
           Version: 11.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cfsteefel at arista dot com
  Target Milestone: ---

When using templates to create a recursive base class structure, if the base
class uses a virtual method and -Wall is enabled, g++-11 shows much worse
compile time compared to g++-8.

Consider the following code:
# 0 "test.cpp"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "test.cpp"


class BaseType  {
   virtual int doSomething() {
      return 1;
   }
};

template< int Seq >
class DerivedType : public DerivedType< Seq - 1 > {
};

template<>
class DerivedType< -1 > : public BaseType {
};

int main() {
   auto * d = new DerivedType< COUNT >();
   delete d;
   return 0;
}

Compiled as:
g++-11 test.cpp -Wall -DCOUNT=200
g++-8 test.cpp -Wall -DCOUNT=200

In g++-11, with COUNT=100, the time to compile is around 2 seconds, while with
COUNT=200, the time is around 1 minute, and COUNT=400 took around 28 minutes.

For comparison, compiling the same code with g++-8 took around .3 seconds, 1.6
seconds, and 22 seconds, respectively.

Removing the virtual will lead to the compile time being near instant again, as
will removing the Wall flag (with g++-11).

Other details:
Compiler versions:
g++ (GCC) 11.3.1 20220421 (Red Hat 11.3.1-2)
g++ (GCC) 8.4.0 20200304 (Red Hat 8.4.0-4)
System:
Centos7 based linux
Compiler output:
test.cpp: In function 'int main()':
test.cpp:20:4: warning: deleting object of polymorphic class type
'DerivedType<100>' which has non-virtual destructor might cause undefined
behavior [-Wdelete-non-virtual-dtor]
   20 |    delete d;
      |    ^~~~~~~~
(fixing the warning changes nothing, and seemed to double the compile time).

extra g++-11/8 configuration options:
%{O*:%{!fomit-frame-pointer:-fno-omit-frame-pointer}} \
%{O*:%{!fno-wrapv:-fwrapv}} \
%{O*:%{!freorder-blocks-and-partition:-fno-reorder-blocks-and-partition}} \
%{mfpmath=sse:-msse2} \
%{!fsemantic-interposition:-fno-semantic-interposition} \
%{g:%{!g0:-gdwarf-4}} \


Using godbolt, I can see similar timing for g++-10 and g++-8, so this seems to
be a g++-11 specific regression.

             reply	other threads:[~2022-10-05 19:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-05 19:35 cfsteefel at arista dot com [this message]
2022-10-05 19:49 ` [Bug c++/107163] Compile time regression when using templated base classes, virtual method, and Wall since r10-2823-g6a07489267e55084 marxin at gcc dot gnu.org
2022-10-05 19:53 ` [Bug c++/107163] [10/11/12/13 Regression] huge Compile time " pinskia at gcc dot gnu.org
2022-10-05 20:39 ` [Bug c++/107163] [10/11/12/13 Regression] huge Compile time increase " redi at gcc dot gnu.org
2022-10-18  8:36 ` rguenth at gcc dot gnu.org
2023-03-23 19:59 ` jason at gcc dot gnu.org
2023-03-28 15:27 ` cvs-commit at gcc dot gnu.org
2023-04-18 20:46 ` [Bug c++/107163] [10/11/12 " cvs-commit at gcc dot gnu.org
2023-04-21 20:28 ` [Bug c++/107163] [10/11 " cvs-commit at gcc dot gnu.org
2023-04-22  0:23 ` cvs-commit at gcc dot gnu.org
2023-07-07 10:44 ` [Bug c++/107163] [11 " rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-107163-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).