13081 – [3.3 regression] forward template declarations in let inlining fail (original) (raw)
Description Debian GCC Maintainers 2003-11-17 00:06:03 UTC
[ forwarded from http://bugs.debian.org/195264 ]
the bug submitter noticed, that std::conj() doesn't get inlined, as one'd expect it to be, when compiling the following with -O2
template T foo(T);
template inline T foo(T t) { return t; } // __attribute((always_inline))
long bar (long);
inline long bar (long l) { return l; }
void doo (long &l) { l = foo (l); l = bar (l); }
Disassembly of section .text:
00000000 <doo(long&)>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 53 push %ebx
4: 83 ec 10 sub $0x10,%esp
7: 8b 5d 08 mov 0x8(%ebp),%ebx
a: ff 33 pushl (%ebx)
c: e8 fc ff ff ff call d <doo(long&)+0xd>
d: R_386_PC32 long foo(long)
11: 89 03 mov %eax,(%ebx)
13: 83 c4 10 add $0x10,%esp
16: 8b 5d fc mov 0xfffffffc(%ebp),%ebx
19: c9 leave
1a: c3 ret
Disassembly of section .gnu.linkonce.t.Z3fooIlET_S0:
00000000 <long foo(long)>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 8b 45 08 mov 0x8(%ebp),%eax
6: c9 leave
7: c3 ret
i.e. bar get's inlined, but foo does not... why? btw, gcc-2.95 would optimize it into a NOP:
00000000 <doo(long &)>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: c9 leave
4: c3 ret
-- I'd say that's a regression...
Comment 1 Drea Pinski 2003-11-17 00:52:07 UTC
The problem is somehow related to having this line: template T foo(T);
Confirmed on the mainline and 3.3.2.
Comment 2 Drea Pinski 2003-12-16 20:31:48 UTC
Some how the template is being marked as not inlinable (it does not inline even at -O3).
Comment 3 Drea Pinski 2003-12-25 00:27:41 UTC
Too much changes for 3.3.3 to fix this one.
Comment 4 Drea Pinski 2003-12-25 16:46:11 UTC
Maybe I was wrong, this might be fixable for 3.3.3.
Comment 5 Drea Pinski 2003-12-25 17:24:04 UTC
The problem is that the followard template declaration: template T foo(T); Causes all template functions not be defined as inline.
Comment 7 Mark Mitchell 2003-12-29 02:44:11 UTC
Fixed in GCC 3.4.
Comment 8 Matthias Klose 2003-12-29 17:00:07 UTC
Subject: Re: [3.3/3.4 regression] forward template declarations in let inlining fail
Module name: gcc Changes by: mmitchel@gcc.gnu.org 2003-12-29 02:42:17
Modified files: gcc/cp : ChangeLog decl.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/opt: inline6.C gcc/testsuite/g++.dg/parse: error9.C
Log message: PR c++/13081 * decl.c (duplicate_decls): Preserve inline-ness when redeclaring a function template.
[PR c++/13081](show%5Fbug.cgi?id=13081 "RESOLVED FIXED - [3.3 regression] forward template declarations in <complex> let inlining fail") * g++.dg/opt/inline6.C: New test.
backported to the gcc-3_3-branch, no regressions on an i486-linux bootstrap. Ok for the branch?
2003-12-28 Mark Mitchell <mark@codesourcery.com>
[PR c++/13081](show%5Fbug.cgi?id=13081 "RESOLVED FIXED - [3.3 regression] forward template declarations in <complex> let inlining fail")
* decl.c (duplicate_decls): Preserve inline-ness when redeclaring
a function template.
[PR c++/13081](show%5Fbug.cgi?id=13081 "RESOLVED FIXED - [3.3 regression] forward template declarations in <complex> let inlining fail")
* g++.dg/opt/inline6.C: New test.--- gcc/testsuite/g++.dg/opt/inline6.C +++ gcc/testsuite/g++.dg/opt/inline6.C 2003-12-29 09:12:36.000000000 +0000 @@ -0,0 +1,14 @@ +// PR c++/13081 +// { dg-options "-O2" } +// { dg-final { scan-assembler-not "foo" } } + +template T foo(T);
+ +template inline T foo(T t) +{
- return t; +}
- +void bar (long& l) {
- l = foo(l); +}
--- gcc/cp/decl.c~ 2003-12-29 10🔞13.000000000 +0100 +++ gcc/cp/decl.c 2003-12-29 10:25:57.000000000 +0100 @@ -3737,6 +3737,14 @@ = DECL_SOURCE_LOCATION (newdecl); }
if (DECL_FUNCTION_TEMPLATE_P (newdecl))- {
DECL_INLINE (DECL_TEMPLATE_RESULT (olddecl))|= DECL_INLINE (DECL_TEMPLATE_RESULT (newdecl));DECL_DECLARED_INLINE_P (DECL_TEMPLATE_RESULT (olddecl))|= DECL_DECLARED_INLINE_P (DECL_TEMPLATE_RESULT (newdecl));- }
return 1; }
Comment 9 Gabriel Dos Reis 2004-01-01 00:22:26 UTC
Subject: Re: [3.3/3.4 regression] forward template declarations in let inlining fail
Matthias Klose <doko@cs.tu-berlin.de> writes:
| > Module name: gcc | > Changes by: mmitchel@gcc.gnu.org 2003-12-29 02:42:17 | > | > Modified files: | > gcc/cp : ChangeLog decl.c | > gcc/testsuite : ChangeLog | > Added files: | > gcc/testsuite/g++.dg/opt: inline6.C | > gcc/testsuite/g++.dg/parse: error9.C | > | > Log message: | > PR c++/13081 | > * decl.c (duplicate_decls): Preserve inline-ness when redeclaring | > a function template. | > | > PR c++/13081 | > * g++.dg/opt/inline6.C: New test. | | backported to the gcc-3_3-branch, no regressions on an i486-linux | bootstrap. Ok for the branch?
Yes, thanks.
-- Gaby
Comment 11 Debian GCC Maintainers 2004-01-02 11:42:58 UTC
Fixed on the 3.3 branch as well.