This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[RFC] Another fix for PR c++/41183
- From: Jie Zhang <jie at codesourcery dot com>
- To: jakub at redhat dot com, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 20 Mar 2010 00:46:01 +0800
- Subject: [RFC] Another fix for PR c++/41183
Hi Jakub,
I just found another way to fix this PR. Why not copy cfun->language
when we create function clones as the attached patch does. I encountered
another similar issue, that means I need to add cp_function_chain
checking in another place. This patch could fix both cases. This patch
has been bootstrapped and regtested with
--enable-languages=c,c++,objc,fortran on gcc-4.4 branch. Testing on
trunk with an adapted patch looks OK, too. How would you like this fix?
Regards,
--
Jie Zhang
CodeSourcery
(650) 331-3385 x735
gcc/cp/
* cp-lang.c (cp_copy_cfun_language): New.
(LANG_HOOKS_COPY_CFUN_LANGUAGE): Define.
* cp-tree.h (current_class_ptr): Don't check
cp_function_chain.
gcc/
* langhooks.c (lhd_do_nothing_ff): New.
* langhooks.h (struct lang_hooks): Add copy_cfun_language.
* tree-inline.c (initialize_cfun): Call
lang_hooks.copy_cfun_language.
* langhooks-def.h (lhd_do_nothing_ff): Declare.
(LANG_HOOKS_COPY_CFUN_LANGUAGE): Define.
(LANG_HOOKS_INITIALIZER): Add LANG_HOOKS_COPY_CFUN_LANGUAGE.
Index: cp/cp-lang.c
===================================================================
--- cp/cp-lang.c (revision 157556)
+++ cp/cp-lang.c (working copy)
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.
enum c_language_kind c_language = clk_cxx;
static void cp_init_ts (void);
+static void cp_copy_cfun_language (struct function *, struct function *);
static const char * cxx_dwarf_name (tree t, int verbosity);
static enum classify_record cp_classify_record (tree type);
@@ -57,6 +58,8 @@ static enum classify_record cp_classify_
#define LANG_HOOKS_FOLD_OBJ_TYPE_REF cp_fold_obj_type_ref
#undef LANG_HOOKS_INIT_TS
#define LANG_HOOKS_INIT_TS cp_init_ts
+#undef LANG_HOOKS_COPY_CFUN_LANGUAGE
+#define LANG_HOOKS_COPY_CFUN_LANGUAGE cp_copy_cfun_language
/* Each front end provides its own lang hook initializer. */
const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
@@ -104,6 +107,18 @@ cp_init_ts (void)
}
+static void
+cp_copy_cfun_language (struct function *dst, struct function *src)
+{
+ if (src->language)
+ {
+ if (dst->language == NULL)
+ dst->language = GGC_NEW (struct language_function);
+ memcpy (dst->language, src->language,
+ sizeof (struct language_function));
+ }
+}
+
static const char *
cxx_dwarf_name (tree t, int verbosity)
{
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h (revision 157556)
+++ cp/cp-tree.h (working copy)
@@ -883,8 +883,7 @@ struct language_function GTY(())
expression for `*this'. */
#define current_class_ptr \
- (cfun && cp_function_chain \
- ? cp_function_chain->x_current_class_ptr : NULL_TREE)
+ (cfun ? cp_function_chain->x_current_class_ptr : NULL_TREE)
#define current_class_ref \
(cfun ? cp_function_chain->x_current_class_ref : NULL_TREE)
Index: langhooks.c
===================================================================
--- langhooks.c (revision 157556)
+++ langhooks.c (working copy)
@@ -76,6 +76,14 @@ lhd_do_nothing_f (struct function * ARG_
{
}
+/* Do nothing (function). */
+
+void
+lhd_do_nothing_ff (struct function * ARG_UNUSED (f),
+ struct function * ARG_UNUSED (g))
+{
+}
+
/* Do nothing (return NULL_TREE). */
tree
Index: langhooks.h
===================================================================
--- langhooks.h (revision 157556)
+++ langhooks.h (working copy)
@@ -414,6 +414,9 @@ struct lang_hooks
if in the process TREE_CONSTANT or TREE_SIDE_EFFECTS need updating. */
tree (*expr_to_decl) (tree expr, bool *tc, bool *se);
+ /* Copy the lanuage-specific data. */
+ void (*copy_cfun_language) (struct function *, struct function *);
+
/* Whenever you add entries here, make sure you adjust langhooks-def.h
and langhooks.c accordingly. */
};
Index: tree-inline.c
===================================================================
--- tree-inline.c (revision 157556)
+++ tree-inline.c (working copy)
@@ -1822,8 +1822,10 @@ initialize_cfun (tree new_fndecl, tree c
gcc_assert (cfun->local_decls == NULL);
gcc_assert (cfun->cfg == NULL);
gcc_assert (cfun->decl == new_fndecl);
+ gcc_assert (cfun->language == NULL);
/* Copy items we preserve during clonning. */
+ lang_hooks.copy_cfun_language (cfun, src_cfun);
cfun->static_chain_decl = src_cfun->static_chain_decl;
cfun->nonlocal_goto_save_area = src_cfun->nonlocal_goto_save_area;
cfun->function_end_locus = src_cfun->function_end_locus;
Index: langhooks-def.h
===================================================================
--- langhooks-def.h (revision 157556)
+++ langhooks-def.h (working copy)
@@ -40,6 +40,7 @@ extern void lhd_do_nothing (void);
extern void lhd_do_nothing_t (tree);
extern void lhd_do_nothing_i (int);
extern void lhd_do_nothing_f (struct function *);
+extern void lhd_do_nothing_ff (struct function *, struct function *);
extern bool lhd_post_options (const char **);
extern alias_set_type lhd_get_alias_set (tree);
extern tree lhd_return_null_tree_v (void);
@@ -113,6 +114,7 @@ extern void lhd_omp_firstprivatize_type_
#define LANG_HOOKS_EXPR_TO_DECL lhd_expr_to_decl
#define LANG_HOOKS_TO_TARGET_CHARSET lhd_to_target_charset
#define LANG_HOOKS_INIT_TS lhd_do_nothing
+#define LANG_HOOKS_COPY_CFUN_LANGUAGE lhd_do_nothing_ff
/* Attribute hooks. */
#define LANG_HOOKS_ATTRIBUTE_TABLE NULL
@@ -270,6 +272,7 @@ extern tree lhd_make_node (enum tree_cod
LANG_HOOKS_BUILTIN_FUNCTION_EXT_SCOPE, \
LANG_HOOKS_INIT_TS, \
LANG_HOOKS_EXPR_TO_DECL, \
+ LANG_HOOKS_COPY_CFUN_LANGUAGE, \
}
#endif /* GCC_LANG_HOOKS_DEF_H */