public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107163] New: Compile time regression when using templated base classes, virtual method, and Wall
@ 2022-10-05 19:35 cfsteefel at arista dot com
  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
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: cfsteefel at arista dot com @ 2022-10-05 19:35 UTC (permalink / raw)
  To: gcc-bugs

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.

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

end of thread, other threads:[~2023-07-07 10:44 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-05 19:35 [Bug c++/107163] New: Compile time regression when using templated base classes, virtual method, and Wall cfsteefel at arista dot com
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

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