Bug 60854 - [4.9 Regression] inline constructor of extern template
Summary: [4.9 Regression] inline constructor of extern template
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ipa (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 4.9.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-15 21:20 UTC by Joachim Schoeberl
Modified: 2014-06-26 13:01 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.10.0
Known to fail: 4.9.0
Last reconfirmed: 2014-04-16 00:00:00


Attachments
source file (138 bytes, text/x-c++src)
2014-04-15 21:20 UTC, Joachim Schoeberl
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Joachim Schoeberl 2014-04-15 21:20:58 UTC
Created attachment 32610 [details]
source file

this code was accepted by gcc-4.8 up to (at least) gcc-4.9-20140323, but g++ (GCC) 4.9.0 20140411 (prerelease) complains.

compiled with
g++ -c -O2 --std=c++11 test.cpp



error message of gcc-4.9.0 prerelease:

test.cpp: In function ‘void Func()’:
test.cpp:5:46: error: inlining failed in call to always_inline ‘MyClass<T>::MyClass() [with T = double]’: function body not available
   __attribute__ ((__always_inline__)) inline MyClass () { ; }
                                              ^
test.cpp:12:19: error: called from here
   MyClass<double> x;
                   ^
Comment 1 Richard Biener 2014-04-16 08:32:07 UTC
Not sure how the C++ 'extern template' explicit instantiation interacts with
the GCC always-inline extension.  But with always-inline it is an _error_
to have a function not inlined and thus we omit the body of the function.

Somehow early inlining doesn't see that MyClass::MyClass is always-inline,
this works in 4.8 and the constructor is always-inlined.

Honza?
Comment 2 Jan Hubicka 2014-04-16 20:56:03 UTC
There is cpp implicit alias, seems like unreachable node removal now gets confused about it.  I am looking into it.
Comment 3 Jan Hubicka 2014-04-16 21:06:35 UTC
OK, the problem is that we see the reference to alias and decide to keep the alias for future inlining. But when processing the refernce from alias to function itself, we throw it away. We need to keep the body, too ;)

(the existing node->alias check actually cares about oposite case where we want to keep weakrefs)

Index: ipa.c
===================================================================
--- ipa.c       (revision 209435)
+++ ipa.c       (working copy)
@@ -138,7 +138,7 @@ process_references (struct ipa_ref_list
       symtab_node *node = ref->referred;
 
       if (node->definition && !node->in_other_partition
-         && ((!DECL_EXTERNAL (node->decl) || node->alias)
+         && ((!DECL_EXTERNAL (node->decl) || node->alias || ref->use == IPA_REF_ALIAS)
              || (((before_inlining_p
                    && (cgraph_state < CGRAPH_STATE_IPA_SSA
                        || !lookup_attribute ("always_inline",
Comment 4 Jan Hubicka 2014-04-17 02:23:31 UTC
Author: hubicka
Date: Thu Apr 17 02:22:57 2014
New Revision: 209459

URL: http://gcc.gnu.org/viewcvs?rev=209459&root=gcc&view=rev
Log:

	PR ipa/60854
	* ipa.c (symtab_remove_unreachable_nodes): Mark targets of
	external aliases alive, too.
	* g++.dg/torture/pr60854.C: New testcase.

Added:
    trunk/gcc/testsuite/g++.dg/torture/pr60854.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/ipa.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Richard Biener 2014-04-17 08:10:45 UTC
Fixed on trunk sofar.
Comment 6 Jan Hubicka 2014-05-17 22:18:58 UTC
Author: hubicka
Date: Sat May 17 22:18:25 2014
New Revision: 210563

URL: http://gcc.gnu.org/viewcvs?rev=210563&root=gcc&view=rev
Log:

	PR ipa/60854
	* ipa.c (symtab_remove_unreachable_nodes): Mark targets of
	external aliases alive, too.
	* g++.dg/torture/pr60854.C: New testcase.

Added:
    branches/gcc-4_9-branch/gcc/testsuite/g++.dg/torture/pr60854.C
Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/ipa.c
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog
Comment 7 Richard Biener 2014-06-26 13:01:17 UTC
Fixed.