From 2dff8956e37c835db601f922cadc5b1229a0a6bd Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 24 Sep 2007 17:16:23 +0200 Subject: [PATCH] re PR c++/33506 (TYPE_RAISES_EXCEPTIONS dumped with attributes) PR c++/33506 * langhooks.h (struct lang_hooks_for_types): Add type_hash_eq field. * langhooks-def.h (LANG_HOOKS_TYPE_HASH_EQ): Define. (LANG_HOOKS_FOR_TYPES_INITIALIZER): Add LANG_HOOKS_TYPE_HASH_EQ. * tree.c (type_hash_eq): For FUNCTION_TYPE use lang_hooks.type.type_hash_eq in addition to generic tests. * cp-tree.h (cxx_type_hash_eq): New prototype. * cp-objcp-common.h (LANG_HOOKS_TYPE_HASH_EQ): Redefine. * tree.c (cxx_type_hash_eq): New function. * g++.dg/ext/attrib29.C: New test. From-SVN: r128718 --- gcc/ChangeLog | 10 ++++++++++ gcc/cp/ChangeLog | 7 +++++++ gcc/cp/cp-objcp-common.h | 2 ++ gcc/cp/cp-tree.h | 1 + gcc/cp/tree.c | 14 ++++++++++++++ gcc/langhooks-def.h | 2 ++ gcc/langhooks.h | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/ext/attrib29.C | 10 ++++++++++ gcc/tree.c | 21 ++++++++++++++------- 10 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/attrib29.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 81bdc4c8890..4ef90d38a7c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2007-09-24 Jakub Jelinek + + PR c++/33506 + * langhooks.h (struct lang_hooks_for_types): Add type_hash_eq + field. + * langhooks-def.h (LANG_HOOKS_TYPE_HASH_EQ): Define. + (LANG_HOOKS_FOR_TYPES_INITIALIZER): Add LANG_HOOKS_TYPE_HASH_EQ. + * tree.c (type_hash_eq): For FUNCTION_TYPE use + lang_hooks.type.type_hash_eq in addition to generic tests. + 2007-09-24 Pranav Bhandarkar Ramana Radhakrishnan diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f8a6875497c..5e9b1875b2e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2007-09-24 Jakub Jelinek + + PR c++/33506 + * cp-tree.h (cxx_type_hash_eq): New prototype. + * cp-objcp-common.h (LANG_HOOKS_TYPE_HASH_EQ): Redefine. + * tree.c (cxx_type_hash_eq): New function. + 2007-09-24 Douglas Gregor PR c++/33185 diff --git a/gcc/cp/cp-objcp-common.h b/gcc/cp/cp-objcp-common.h index dd236131f0a..7f8138c6e60 100644 --- a/gcc/cp/cp-objcp-common.h +++ b/gcc/cp/cp-objcp-common.h @@ -88,6 +88,8 @@ extern tree objcp_tsubst_copy_and_build (tree, tree, tsubst_flags_t, #define LANG_HOOKS_COMDAT_GROUP cxx_comdat_group #undef LANG_HOOKS_BUILTIN_FUNCTION #define LANG_HOOKS_BUILTIN_FUNCTION cxx_builtin_function +#undef LANG_HOOKS_TYPE_HASH_EQ +#define LANG_HOOKS_TYPE_HASH_EQ cxx_type_hash_eq #undef LANG_HOOKS_FUNCTION_INIT #define LANG_HOOKS_FUNCTION_INIT cxx_push_function_context diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index fbe1bcc0170..83f4d423231 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -4752,6 +4752,7 @@ extern tree rvalue (tree); extern tree convert_bitfield_to_declared_type (tree); extern tree cp_save_expr (tree); extern bool cast_valid_in_integral_constant_expression_p (tree); +extern bool cxx_type_hash_eq (const_tree, const_tree); /* in typeck.c */ extern int string_conv_p (const_tree, const_tree, int); diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 78ba4282b44..77aac702f20 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -2261,6 +2261,20 @@ cp_build_type_attribute_variant (tree type, tree attributes) return new_type; } +/* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes. + Called only after doing all language independent checks. Only + to check TYPE_RAISES_EXCEPTIONS for FUNCTION_TYPE, the rest is already + compared in type_hash_eq. */ + +bool +cxx_type_hash_eq (const_tree typea, const_tree typeb) +{ + gcc_assert (TREE_CODE (typea) == FUNCTION_TYPE); + + return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea), + TYPE_RAISES_EXCEPTIONS (typeb), 1); +} + /* Apply FUNC to all language-specific sub-trees of TP in a pre-order traversal. Called from walk_tree. */ diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h index 523fc0b4766..28efd6beb49 100644 --- a/gcc/langhooks-def.h +++ b/gcc/langhooks-def.h @@ -180,6 +180,7 @@ extern tree lhd_make_node (enum tree_code); #define LANG_HOOKS_TYPE_MAX_SIZE lhd_return_null_const_tree #define LANG_HOOKS_OMP_FIRSTPRIVATIZE_TYPE_SIZES \ lhd_omp_firstprivatize_type_sizes +#define LANG_HOOKS_TYPE_HASH_EQ NULL #define LANG_HOOKS_HASH_TYPES true #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \ @@ -192,6 +193,7 @@ extern tree lhd_make_node (enum tree_code); LANG_HOOKS_INCOMPLETE_TYPE_ERROR, \ LANG_HOOKS_TYPE_MAX_SIZE, \ LANG_HOOKS_OMP_FIRSTPRIVATIZE_TYPE_SIZES, \ + LANG_HOOKS_TYPE_HASH_EQ, \ LANG_HOOKS_HASH_TYPES \ } diff --git a/gcc/langhooks.h b/gcc/langhooks.h index ad925a84c3b..7efe7425eb8 100644 --- a/gcc/langhooks.h +++ b/gcc/langhooks.h @@ -129,6 +129,12 @@ struct lang_hooks_for_types firstprivate variables. */ void (*omp_firstprivatize_type_sizes) (struct gimplify_omp_ctx *, tree); + /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes. + Called only after doing all language independent checks. + At present, this function is only called when both TYPE1 and TYPE2 are + FUNCTION_TYPEs. */ + bool (*type_hash_eq) (const_tree, const_tree); + /* Nonzero if types that are identical are to be hashed so that only one copy is kept. If a language requires unique types for each user-specified type, such as Ada, this should be set to TRUE. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2e3b520d1a3..8e146d2917a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-09-24 Jakub Jelinek + + PR c++/33506 + * g++.dg/ext/attrib29.C: New test. + 2007-09-23 Ollie Wild * gcc.dg/fold-bitand-1.c: New test. diff --git a/gcc/testsuite/g++.dg/ext/attrib29.C b/gcc/testsuite/g++.dg/ext/attrib29.C new file mode 100644 index 00000000000..710a5ce2763 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attrib29.C @@ -0,0 +1,10 @@ +// PR c++/33506 +// { dg-do compile } + +extern int f1 (char *) __attribute__ ((warn_unused_result)); +extern int f2 (char *) throw () __attribute__ ((warn_unused_result)); +extern int f2 (char *) throw (); + +extern int f3 (char *) __attribute__ ((nonnull (1))); +extern int f4 (char *) throw () __attribute__ ((nonnull (1))); +extern int f4 (char *) throw (); diff --git a/gcc/tree.c b/gcc/tree.c index 2e5bf5c9337..88ec29e13e3 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -4608,17 +4608,24 @@ type_hash_eq (const void *va, const void *vb) TYPE_FIELDS (b->type)))); case FUNCTION_TYPE: - return (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type) - || (TYPE_ARG_TYPES (a->type) - && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST - && TYPE_ARG_TYPES (b->type) - && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST - && type_list_equal (TYPE_ARG_TYPES (a->type), - TYPE_ARG_TYPES (b->type)))); + if (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type) + || (TYPE_ARG_TYPES (a->type) + && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST + && TYPE_ARG_TYPES (b->type) + && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST + && type_list_equal (TYPE_ARG_TYPES (a->type), + TYPE_ARG_TYPES (b->type)))) + break; + return 0; default: return 0; } + + if (lang_hooks.types.type_hash_eq != NULL) + return lang_hooks.types.type_hash_eq (a->type, b->type); + + return 1; } /* Return the cached hash value. */ -- 2.30.2