From 1906d6b4dc4cf6bddb82e9dc3534438230030a8e Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 3 Nov 2016 15:52:58 -0400 Subject: [PATCH] Use type_hash_eq langhook in check_qualified_type. gcc/ * tree.c (check_lang_type): New. (check_qualified_type): Use it. (check_aligned_type): Use it. * tree.h: Declare it. gcc/cp/ * tree.c (cp_check_qualified_type): Call check_base_type instead of check_qualified_type. (cxx_type_hash_eq): Check ref-qualifiers. * typeck.c (apply_memfn_quals): No need to mess with TYPE_CANONICAL. From-SVN: r241831 --- gcc/ChangeLog | 7 +++++++ gcc/cp/ChangeLog | 7 +++++++ gcc/cp/tree.c | 9 +++++---- gcc/cp/typeck.c | 7 ------- gcc/langhooks.h | 2 +- gcc/tree.c | 21 +++++++++++++++++++-- gcc/tree.h | 5 +++++ 7 files changed, 44 insertions(+), 14 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3888d217ed2..dbbdba725ee 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2016-11-03 Jason Merrill + + * tree.c (check_lang_type): New. + (check_qualified_type): Use it. + (check_aligned_type): Use it. + * tree.h: Declare it. + 2016-11-03 Richard Earnshaw * config.gcc (arm-wrs-vxworks): Set target_cpu_cname. diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5eabdc2c886..c60c81de1f2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2016-11-03 Jason Merrill + + * tree.c (cp_check_qualified_type): Call check_base_type instead + of check_qualified_type. + (cxx_type_hash_eq): Check ref-qualifiers. + * typeck.c (apply_memfn_quals): No need to mess with TYPE_CANONICAL. + 2016-11-01 Jason Merrill Implement P0136R1, Rewording inheriting constructors. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index ac15d67eafb..4dc6e226851 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1980,7 +1980,8 @@ static bool cp_check_qualified_type (const_tree cand, const_tree base, int type_quals, cp_ref_qualifier rqual, tree raises) { - return (check_qualified_type (cand, base, type_quals) + return (TYPE_QUALS (cand) == type_quals + && check_base_type (cand, base) && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (cand), ce_exact) && type_memfn_rqual (cand) == rqual); @@ -4080,9 +4081,7 @@ cp_build_type_attribute_variant (tree type, tree attributes) } /* 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. */ + Called only after doing all language independent checks. */ bool cxx_type_hash_eq (const_tree typea, const_tree typeb) @@ -4090,6 +4089,8 @@ cxx_type_hash_eq (const_tree typea, const_tree typeb) gcc_assert (TREE_CODE (typea) == FUNCTION_TYPE || TREE_CODE (typea) == METHOD_TYPE); + if (type_memfn_rqual (typea) != type_memfn_rqual (typeb)) + return false; return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea), TYPE_RAISES_EXCEPTIONS (typeb), ce_exact); } diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 569442f38ac..45b7d264088 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -9227,13 +9227,6 @@ apply_memfn_quals (tree type, cp_cv_quals memfn_quals, cp_ref_qualifier rqual) /* This should really have a different TYPE_MAIN_VARIANT, but that gets complex. */ tree result = build_qualified_type (type, memfn_quals); - if (tree canon = TYPE_CANONICAL (result)) - if (canon != result) - /* check_qualified_type doesn't check the ref-qualifier, so make sure - TYPE_CANONICAL is correct. */ - TYPE_CANONICAL (result) - = build_ref_qualified_type (canon, type_memfn_rqual (result)); - result = build_exception_variant (result, TYPE_RAISES_EXCEPTIONS (type)); return build_ref_qualified_type (result, rqual); } diff --git a/gcc/langhooks.h b/gcc/langhooks.h index 8116b170f7b..6cd01a736e5 100644 --- a/gcc/langhooks.h +++ b/gcc/langhooks.h @@ -120,7 +120,7 @@ struct lang_hooks_for_types /* 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. */ + FUNCTION_TYPE or METHOD_TYPE. */ bool (*type_hash_eq) (const_tree, const_tree); /* Return TRUE if TYPE uses a hidden descriptor and fills in information diff --git a/gcc/tree.c b/gcc/tree.c index 56cc653c875..434aff1c4ee 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -6497,6 +6497,21 @@ set_type_quals (tree type, int type_quals) TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals); } +/* Returns true iff CAND and BASE have equivalent language-specific + qualifiers. */ + +bool +check_lang_type (const_tree cand, const_tree base) +{ + if (lang_hooks.types.type_hash_eq == NULL) + return true; + /* type_hash_eq currently only applies to these types. */ + if (TREE_CODE (cand) != FUNCTION_TYPE + && TREE_CODE (cand) != METHOD_TYPE) + return true; + return lang_hooks.types.type_hash_eq (cand, base); +} + /* Returns true iff unqualified CAND and BASE are equivalent. */ bool @@ -6517,7 +6532,8 @@ bool check_qualified_type (const_tree cand, const_tree base, int type_quals) { return (TYPE_QUALS (cand) == type_quals - && check_base_type (cand, base)); + && check_base_type (cand, base) + && check_lang_type (cand, base)); } /* Returns true iff CAND is equivalent to BASE with ALIGN. */ @@ -6532,7 +6548,8 @@ check_aligned_type (const_tree cand, const_tree base, unsigned int align) /* Check alignment. */ && TYPE_ALIGN (cand) == align && attribute_list_equal (TYPE_ATTRIBUTES (cand), - TYPE_ATTRIBUTES (base))); + TYPE_ATTRIBUTES (base)) + && check_lang_type (cand, base)); } /* This function checks to see if TYPE matches the size one of the built-in diff --git a/gcc/tree.h b/gcc/tree.h index 531bc5effb7..6a98b6ee0b6 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -4214,6 +4214,11 @@ extern tree merge_dllimport_decl_attributes (tree, tree); /* Handle a "dllimport" or "dllexport" attribute. */ extern tree handle_dll_attribute (tree *, tree, tree, int, bool *); +/* Returns true iff CAND and BASE have equivalent language-specific + qualifiers. */ + +extern bool check_lang_type (const_tree cand, const_tree base); + /* Returns true iff unqualified CAND and BASE are equivalent. */ extern bool check_base_type (const_tree cand, const_tree base); -- 2.30.2