This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [LTO merge][4/15][RFA] C++ front end


On Tue, Sep 29, 2009 at 23:42, Mark Mitchell <mark@codesourcery.com> wrote:
> Jason Merrill wrote:
>> On 09/29/2009 05:58 PM, Mark Mitchell wrote:
>>> There should be
>>> some semantic way to explain what class of entities you're trying to
>>> exclude.
>>
>> He wants to exclude uninstantiated templates, since only full
>> instantiations get mangled names. ÂDo you have a better idea for how to
>> do that?
>
> Why are we running into VAR_DECLs and FUNCTION_DECLs instead of
> TEMPLATE_DECLs, then? ÂIt sounds like Diego is seeing the "exemplar" we
> create, instead of the template. ÂAre we putting the exemplars, instead
> of the templates, onto scope lists and such?

We never see TEMPLATE_DECLs.  The root of the problem was that I
was causing ICEs in the name mangler whenever I tried to create
assembler names for certain VAR_DECLs and FUNCTION_DECLs.

What they all have in common is that they either depend on
template arguments or they are a template specialization.  For
instance,

g++.dg/template/friend37.C
	friend void foo<class X>(A<X>*);

g++.dg/abi/mangle30.C
	template <class T>
	void f (T t, typename T::template B<C>::myT u, typename T::template
B<int>::myT v);

g++.dg/ext/tmplattr9.C
	void bar(B<b>) __attribute((weak));

For the last one, the check for uses_template_parms() helped
ignore it.

There were cases, though, were we would find a decl with template
information and refuse to mangle it, but it was needed.  For
instance,

g++.dg/compat/eh/template1_y.C
	template<class T> void C<T>::f (void) throw (E)

I *think* this means that I should only refuse to mangle decls
that are DECL_TEMPLATE_SPECIALIZATION.  But a
DECL_TEMPLATE_INSTANTIATION should be mangled.  I am currently
handling this case by recognizing that the FUNCTION_DECL has a
cgraph node attached to it, so it really does need to be mangled.

I have bootstrapped and tested the attached patch with no new
regressions.

Could I just remove the check for DECL_TEMPLATE_INSTANTIATION?


Thanks.  Diego.


Index: cp/tree.c
===================================================================
--- cp/tree.c   (revision 152279)
+++ cp/tree.c   (working copy)
@@ -3104,6 +3104,33 @@ cp_free_lang_data (tree t)
     }
 }

+
+/* Return true if DECL may need an assembler name to be set.  Note
+   that this should only check language-specific attributes and return true if
+   it is not completely sure.  It is used as a last resort in
+   tree.c:need_assembler_name_p.  */
+
+bool
+cxx_may_need_assembler_name_p (tree decl)
+{
+  /* We should never see anything other than variables and functions here.  */
+  gcc_assert (TREE_CODE (decl) == FUNCTION_DECL
+             || TREE_CODE (decl) == VAR_DECL);
+
+  /* Functions that depend on template parameters do not need
+     an assembler name.  */
+  if (TREE_CODE (decl) == FUNCTION_DECL && uses_template_parms (decl))
+    return false;
+
+  /* Templates do not need assembler names.  */
+  if (DECL_LANG_SPECIFIC (decl)
+      && (DECL_TEMPLATE_INSTANTIATION (decl)
+         || DECL_TEMPLATE_SPECIALIZATION (decl)))
+    return false;
+
+  return true;
+}
+

 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
 /* Complain that some language-specific thing hanging off a tree
Index: cp/cp-objcp-common.h
===================================================================
--- cp/cp-objcp-common.h        (revision 152279)
+++ cp/cp-objcp-common.h        (working copy)
@@ -141,6 +141,8 @@ extern bool cp_function_decl_explicit_p
 #define LANG_HOOKS_OMP_FINISH_CLAUSE cxx_omp_finish_clause
 #undef LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE
 #define LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE cxx_omp_privatize_by_reference
+#undef LANG_HOOKS_MAY_NEED_ASSEMBLER_NAME_P
+#define LANG_HOOKS_MAY_NEED_ASSEMBLER_NAME_P cxx_may_need_assembler_name_p

 #undef LANG_HOOKS_EH_USE_CXA_END_CLEANUP
 #define LANG_HOOKS_EH_USE_CXA_END_CLEANUP true
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h        (revision 152279)
+++ cp/cp-tree.h        (working copy)
@@ -4899,7 +4899,8 @@ extern tree finish_decltype_type
 extern tree finish_trait_expr                  (enum cp_trait_kind,
tree, tree);

 /* in tree.c */
-void cp_free_lang_data                                 (tree t);
+extern void cp_free_lang_data                  (tree t);
+extern bool cxx_may_need_assembler_name_p      (tree t);
 extern tree force_target_expr                  (tree, tree);
 extern tree build_target_expr_with_type                (tree, tree);
 extern void lang_check_failed                  (const char *, int,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]