241 lines
9.2 KiB
Diff
241 lines
9.2 KiB
Diff
diff -rupN a/gcc/cp/decl.c b/gcc/cp/decl.c
|
|
--- a/gcc/cp/decl.c 2014-06-09 19:29:17.000000000 +0000
|
|
+++ b/gcc/cp/decl.c 2015-03-12 03:53:10.876000000 +0000
|
|
@@ -2185,6 +2185,7 @@ duplicate_decls (tree newdecl, tree oldd
|
|
olddecl);
|
|
|
|
SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
|
|
+ DECL_COMDAT (newdecl) = DECL_DECLARED_INLINE_P (newdecl);
|
|
|
|
/* Don't propagate visibility from the template to the
|
|
specialization here. We'll do that in determine_visibility if
|
|
@@ -4638,6 +4639,8 @@ start_decl (const cp_declarator *declara
|
|
if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
|
|
{
|
|
SET_DECL_TEMPLATE_SPECIALIZATION (decl);
|
|
+ if (TREE_CODE (decl) == FUNCTION_DECL)
|
|
+ DECL_COMDAT (decl) = DECL_DECLARED_INLINE_P (decl);
|
|
|
|
/* [temp.expl.spec] An explicit specialization of a static data
|
|
member of a template is a definition if the declaration
|
|
@@ -7602,7 +7605,10 @@ grokfndecl (tree ctype,
|
|
|
|
/* If the declaration was declared inline, mark it as such. */
|
|
if (inlinep)
|
|
- DECL_DECLARED_INLINE_P (decl) = 1;
|
|
+ {
|
|
+ DECL_DECLARED_INLINE_P (decl) = 1;
|
|
+ DECL_COMDAT (decl) = 1;
|
|
+ }
|
|
if (inlinep & 2)
|
|
DECL_DECLARED_CONSTEXPR_P (decl) = true;
|
|
|
|
@@ -14147,6 +14153,7 @@ grokmethod (cp_decl_specifier_seq *decls
|
|
|
|
check_template_shadow (fndecl);
|
|
|
|
+ DECL_COMDAT (fndecl) = 1;
|
|
DECL_DECLARED_INLINE_P (fndecl) = 1;
|
|
DECL_NO_INLINE_WARNING_P (fndecl) = 1;
|
|
|
|
diff -rupN a/gcc/cp/decl2.c b/gcc/cp/decl2.c
|
|
--- a/gcc/cp/decl2.c 2014-04-01 17:49:38.000000000 +0000
|
|
+++ b/gcc/cp/decl2.c 2015-03-12 03:53:10.876000000 +0000
|
|
@@ -1896,6 +1896,12 @@ mark_needed (tree decl)
|
|
definition. */
|
|
struct cgraph_node *node = cgraph_get_create_node (decl);
|
|
node->forced_by_abi = true;
|
|
+
|
|
+ /* #pragma interface and -frepo code can call mark_needed for
|
|
+ maybe-in-charge 'tors; mark the clones as well. */
|
|
+ tree clone;
|
|
+ FOR_EACH_CLONE (clone, decl)
|
|
+ mark_needed (clone);
|
|
}
|
|
else if (TREE_CODE (decl) == VAR_DECL)
|
|
{
|
|
@@ -2678,17 +2684,7 @@ import_export_decl (tree decl)
|
|
{
|
|
/* The repository indicates that this entity should be defined
|
|
here. Make sure the back end honors that request. */
|
|
- if (VAR_P (decl))
|
|
- mark_needed (decl);
|
|
- else if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl)
|
|
- || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
|
|
- {
|
|
- tree clone;
|
|
- FOR_EACH_CLONE (clone, decl)
|
|
- mark_needed (clone);
|
|
- }
|
|
- else
|
|
- mark_needed (decl);
|
|
+ mark_needed (decl);
|
|
/* Output the definition as an ordinary strong definition. */
|
|
DECL_EXTERNAL (decl) = 0;
|
|
DECL_INTERFACE_KNOWN (decl) = 1;
|
|
diff -rupN a/gcc/cp/method.c b/gcc/cp/method.c
|
|
--- a/gcc/cp/method.c 2014-03-26 21:33:28.000000000 +0000
|
|
+++ b/gcc/cp/method.c 2015-03-12 03:53:10.876000000 +0000
|
|
@@ -1760,8 +1760,6 @@ implicitly_declare_fn (special_function_
|
|
DECL_ARGUMENTS (fn) = this_parm;
|
|
|
|
grokclassfn (type, fn, kind == sfk_destructor ? DTOR_FLAG : NO_SPECIAL);
|
|
- set_linkage_according_to_type (type, fn);
|
|
- rest_of_decl_compilation (fn, toplevel_bindings_p (), at_eof);
|
|
DECL_IN_AGGR_P (fn) = 1;
|
|
DECL_ARTIFICIAL (fn) = 1;
|
|
DECL_DEFAULTED_FN (fn) = 1;
|
|
@@ -1773,6 +1771,9 @@ implicitly_declare_fn (special_function_
|
|
DECL_EXTERNAL (fn) = true;
|
|
DECL_NOT_REALLY_EXTERN (fn) = 1;
|
|
DECL_DECLARED_INLINE_P (fn) = 1;
|
|
+ DECL_COMDAT (fn) = 1;
|
|
+ set_linkage_according_to_type (type, fn);
|
|
+ rest_of_decl_compilation (fn, toplevel_bindings_p (), at_eof);
|
|
gcc_assert (!TREE_USED (fn));
|
|
|
|
/* Restore PROCESSING_TEMPLATE_DECL. */
|
|
diff -rupN a/gcc/cp/pt.c b/gcc/cp/pt.c
|
|
--- a/gcc/cp/pt.c 2014-06-30 18:52:45.000000000 +0000
|
|
+++ b/gcc/cp/pt.c 2015-03-12 03:53:10.880000000 +0000
|
|
@@ -2783,6 +2783,9 @@ check_explicit_specialization (tree decl
|
|
It's just the name of an instantiation. But, it's not
|
|
a request for an instantiation, either. */
|
|
SET_DECL_IMPLICIT_INSTANTIATION (decl);
|
|
+ else
|
|
+ /* A specialization is not necessarily COMDAT. */
|
|
+ DECL_COMDAT (decl) = DECL_DECLARED_INLINE_P (decl);
|
|
|
|
/* Register this specialization so that we can find it
|
|
again. */
|
|
@@ -5022,6 +5025,14 @@ template arguments to %qD do not match o
|
|
DECL_TEMPLATE_INFO (decl) = info;
|
|
}
|
|
|
|
+ if (flag_implicit_templates
|
|
+ && !is_friend
|
|
+ && TREE_CODE (decl) == FUNCTION_DECL)
|
|
+ /* Set DECL_COMDAT on template instantiations; if we force
|
|
+ them to be emitted by explicit instantiation or -frepo,
|
|
+ mark_needed will tell cgraph to do the right thing. */
|
|
+ DECL_COMDAT (decl) = true;
|
|
+
|
|
return DECL_TEMPLATE_RESULT (tmpl);
|
|
}
|
|
|
|
diff -rupN a/gcc/cp/tree.c b/gcc/cp/tree.c
|
|
--- a/gcc/cp/tree.c 2014-06-30 14:25:21.000000000 +0000
|
|
+++ b/gcc/cp/tree.c 2015-03-12 03:53:10.880000000 +0000
|
|
@@ -3716,23 +3716,15 @@ decl_linkage (tree decl)
|
|
if (TREE_CODE (decl) == CONST_DECL)
|
|
return decl_linkage (TYPE_NAME (DECL_CONTEXT (decl)));
|
|
|
|
- /* Some things that are not TREE_PUBLIC have external linkage, too.
|
|
- For example, on targets that don't have weak symbols, we make all
|
|
- template instantiations have internal linkage (in the object
|
|
- file), but the symbols should still be treated as having external
|
|
- linkage from the point of view of the language. */
|
|
- if (VAR_OR_FUNCTION_DECL_P (decl)
|
|
- && DECL_COMDAT (decl))
|
|
- return lk_external;
|
|
-
|
|
/* Things in local scope do not have linkage, if they don't have
|
|
TREE_PUBLIC set. */
|
|
if (decl_function_context (decl))
|
|
return lk_none;
|
|
|
|
/* Members of the anonymous namespace also have TREE_PUBLIC unset, but
|
|
- are considered to have external linkage for language purposes. DECLs
|
|
- really meant to have internal linkage have DECL_THIS_STATIC set. */
|
|
+ are considered to have external linkage for language purposes, as do
|
|
+ template instantiations on targets without weak symbols. DECLs really
|
|
+ meant to have internal linkage have DECL_THIS_STATIC set. */
|
|
if (TREE_CODE (decl) == TYPE_DECL)
|
|
return lk_external;
|
|
if (VAR_OR_FUNCTION_DECL_P (decl))
|
|
diff -rupN a/gcc/sched-deps.c b/gcc/sched-deps.c
|
|
--- a/gcc/sched-deps.c 2014-02-05 18:42:19.000000000 +0000
|
|
+++ b/gcc/sched-deps.c 2015-03-12 03:51:08.500000000 +0000
|
|
@@ -2750,7 +2750,7 @@ sched_analyze_2 (struct deps_desc *deps,
|
|
Consider for instance a volatile asm that changes the fpu rounding
|
|
mode. An insn should not be moved across this even if it only uses
|
|
pseudo-regs because it might give an incorrectly rounded result. */
|
|
- if (code != ASM_OPERANDS || MEM_VOLATILE_P (x))
|
|
+ if ((code != ASM_OPERANDS || MEM_VOLATILE_P (x)) && !DEBUG_INSN_P (insn))
|
|
reg_pending_barrier = TRUE_BARRIER;
|
|
|
|
/* For all ASM_OPERANDS, we must traverse the vector of input operands.
|
|
diff -rupN a/gcc/testsuite/g++.dg/abi/spec1.C b/gcc/testsuite/g++.dg/abi/spec1.C
|
|
--- a/gcc/testsuite/g++.dg/abi/spec1.C 1970-01-01 00:00:00.000000000 +0000
|
|
+++ b/gcc/testsuite/g++.dg/abi/spec1.C 2015-03-12 03:53:10.880000000 +0000
|
|
@@ -0,0 +1,4 @@
|
|
+// { dg-final { scan-assembler-not "weak" } }
|
|
+
|
|
+template <class T> struct A { static int i; };
|
|
+template<> int A<int>::i = 42;
|
|
diff -rupN a/gcc/testsuite/g++.dg/opt/devirt4.C b/gcc/testsuite/g++.dg/opt/devirt4.C
|
|
--- a/gcc/testsuite/g++.dg/opt/devirt4.C 2014-02-25 18:54:48.000000000 +0000
|
|
+++ b/gcc/testsuite/g++.dg/opt/devirt4.C 2015-03-12 03:53:10.880000000 +0000
|
|
@@ -1,8 +1,7 @@
|
|
// PR lto/53808
|
|
-// Devirtualization + inlining should produce a non-virtual
|
|
-// call to ~foo.
|
|
-// { dg-options "-O -fdevirtualize" }
|
|
-// { dg-final { scan-assembler "_ZN3fooD2Ev" } }
|
|
+// Devirtualization should not produce an external ref to ~bar.
|
|
+// { dg-options "-O2" }
|
|
+// { dg-final { scan-assembler-not "_ZN3barD0Ev" } }
|
|
|
|
struct foo {
|
|
virtual ~foo();
|
|
diff -rupN a/gcc/testsuite/g++.dg/opt/devirt5.C b/gcc/testsuite/g++.dg/opt/devirt5.C
|
|
--- a/gcc/testsuite/g++.dg/opt/devirt5.C 1970-01-01 00:00:00.000000000 +0000
|
|
+++ b/gcc/testsuite/g++.dg/opt/devirt5.C 2015-03-12 03:53:10.880000000 +0000
|
|
@@ -0,0 +1,19 @@
|
|
+// PR c++/61659
|
|
+// { dg-options "-O3" }
|
|
+// { dg-final { scan-assembler-not "_ZN6parserIiE9getOptionEv" } }
|
|
+
|
|
+struct generic_parser_base {
|
|
+ virtual void getOption();
|
|
+ void getExtraOptionNames() { getOption(); }
|
|
+};
|
|
+template <class DataType> struct parser : public generic_parser_base {
|
|
+ virtual void getOption() {}
|
|
+};
|
|
+struct PassNameParser : public parser<int> {
|
|
+ PassNameParser();
|
|
+};
|
|
+struct list {
|
|
+ PassNameParser Parser;
|
|
+ virtual void getExtraOptionNames() { return Parser.getExtraOptionNames(); }
|
|
+};
|
|
+list PassList;
|
|
diff -rupN a/gcc/testsuite/g++.dg/template/friend56.C b/gcc/testsuite/g++.dg/template/friend56.C
|
|
--- a/gcc/testsuite/g++.dg/template/friend56.C 1970-01-01 00:00:00.000000000 +0000
|
|
+++ b/gcc/testsuite/g++.dg/template/friend56.C 2015-03-12 03:53:10.880000000 +0000
|
|
@@ -0,0 +1,13 @@
|
|
+// Make sure we don't mistakenly mark f as DECL_COMDAT.
|
|
+// { dg-final { scan-assembler "_Z1fv" } }
|
|
+
|
|
+void f();
|
|
+
|
|
+template <class T> struct A
|
|
+{
|
|
+ friend void f();
|
|
+};
|
|
+
|
|
+A<int> a;
|
|
+
|
|
+void f() { }
|
|
diff -rupN a/gcc/testsuite/g++.dg/template/spec38.C b/gcc/testsuite/g++.dg/template/spec38.C
|
|
--- a/gcc/testsuite/g++.dg/template/spec38.C 1970-01-01 00:00:00.000000000 +0000
|
|
+++ b/gcc/testsuite/g++.dg/template/spec38.C 2015-03-12 03:53:10.880000000 +0000
|
|
@@ -0,0 +1,6 @@
|
|
+// PR ipa/61659
|
|
+
|
|
+// { dg-final { scan-assembler "_Z1fIiEvPT_" } }
|
|
+
|
|
+template <typename T> inline void f (T *);
|
|
+template <> void f (int *) { }
|