From 3d7ff7286de5a44da1b843ace99262c777079714 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 29 May 2017 19:45:42 +0000 Subject: [PATCH] PR c++/80891 (#1,#5) PR c++/80891 (#1,#5) * cp-tree.h (lookup_maybe_add): Add DEDUPING argument. * name-lookup.c (name_lookup): Add deduping field. (name_lookup::preserve_state, name_lookup::restore_state): Deal with deduping. (name_lookup::add_overload): New. (name_lookup::add_value, name_lookup::add_fns): Call add_overload. (name_lookup::search_adl): Set deduping. Don't unmark here. * pt.c (most_specialized_instantiation): Revert previous change, Assert not given duplicates. * tree.c (lookup_mark): Just mark the underlying decls. (lookup_maybe_add): Dedup using marked decls. PR c++/80891 (#5) * g++.dg/lookup/pr80891-5.C: New. From-SVN: r248578 --- gcc/cp/ChangeLog | 13 ++++ gcc/cp/cp-tree.h | 3 +- gcc/cp/name-lookup.c | 68 ++++++++++++++++---- gcc/cp/pt.c | 42 ++++++------- gcc/cp/tree.c | 106 +++++++++++--------------------- gcc/testsuite/ChangeLog | 5 ++ gcc/testsuite/g++.dg/lookup/pr80891-5.C | 68 ++++++++++++++++++++ 7 files changed, 200 insertions(+), 105 deletions(-) create mode 100644 gcc/testsuite/g++.dg/lookup/pr80891-5.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index faae715..d471f37 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,18 @@ 2017-05-29 Nathan Sidwell + PR c++/80891 (#1,#5) + * cp-tree.h (lookup_maybe_add): Add DEDUPING argument. + * name-lookup.c (name_lookup): Add deduping field. + (name_lookup::preserve_state, name_lookup::restore_state): Deal + with deduping. + (name_lookup::add_overload): New. + (name_lookup::add_value, name_lookup::add_fns): Call add_overload. + (name_lookup::search_adl): Set deduping. Don't unmark here. + * pt.c (most_specialized_instantiation): Revert previous change, + Assert not given duplicates. + * tree.c (lookup_mark): Just mark the underlying decls. + (lookup_maybe_add): Dedup using marked decls. + PR c++/80891 (#4) * ptree.c (cxx_print_xnode): Show internal OVERLOAD structure. * tree.c (ovl_insert, ovl_iterator_remove_node): Fix copying assert. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index f1df0bd..b9c1b13 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6916,7 +6916,8 @@ extern tree ovl_insert (tree fn, tree maybe_ovl, extern tree ovl_skip_hidden (tree) ATTRIBUTE_PURE; extern void lookup_mark (tree lookup, bool val); extern tree lookup_add (tree fns, tree lookup); -extern tree lookup_maybe_add (tree fns, tree lookup); +extern tree lookup_maybe_add (tree fns, tree lookup, + bool deduping); extern void lookup_keep (tree lookup, bool keep); extern int is_overloaded_fn (tree) ATTRIBUTE_PURE; extern bool really_overloaded_fn (tree) ATTRIBUTE_PURE; diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index f0dc10f..861580f 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -48,7 +48,11 @@ static void set_identifier_type_value_with_scope (tree id, tree decl, #define MAYBE_STAT_DECL(N) (STAT_HACK_P (N) ? STAT_DECL (N) : N) #define MAYBE_STAT_TYPE(N) (STAT_HACK_P (N) ? STAT_TYPE (N) : NULL_TREE) -static tree stat_hack (tree decl = NULL_TREE, tree type = NULL_TREE) +/* Create a STAT_HACK node with DECL as the value binding and TYPE as + the type binding. */ + +static tree +stat_hack (tree decl = NULL_TREE, tree type = NULL_TREE) { tree result = make_node (OVERLOAD); @@ -179,6 +183,8 @@ public: tree value; /* A (possibly ambiguous) set of things found. */ tree type; /* A type that has been found. */ int flags; /* Lookup flags. */ + bool deduping; /* Full deduping is needed because using declarations + are in play. */ vec *scopes; name_lookup *previous; /* Previously active lookup. */ @@ -191,7 +197,7 @@ protected: public: name_lookup (tree n, int f = 0) : name (n), value (NULL_TREE), type (NULL_TREE), flags (f), - scopes (NULL), previous (NULL) + deduping (false), scopes (NULL), previous (NULL) { preserve_state (); } @@ -235,6 +241,7 @@ private: private: static tree ambiguous (tree thing, tree current); + void add_overload (tree fns); void add_value (tree new_val); void add_type (tree new_type); bool process_binding (tree val_bind, tree type_bind); @@ -321,7 +328,8 @@ name_lookup::preserve_state () } /* Unmark the outer partial lookup. */ - lookup_mark (previous->value, false); + if (previous->deduping) + lookup_mark (previous->value, false); } else scopes = shared_scopes; @@ -333,6 +341,9 @@ name_lookup::preserve_state () void name_lookup::restore_state () { + if (deduping) + lookup_mark (value, false); + /* Unmark and empty this lookup's scope stack. */ for (unsigned ix = vec_safe_length (scopes); ix--;) { @@ -371,7 +382,8 @@ name_lookup::restore_state () } /* Remark the outer partial lookup. */ - lookup_mark (previous->value, true); + if (previous->deduping) + lookup_mark (previous->value, true); } else shared_scopes = scopes; @@ -415,12 +427,36 @@ name_lookup::ambiguous (tree thing, tree current) return current; } +/* FNS is a new overload set to add to the exising set. */ + +void +name_lookup::add_overload (tree fns) +{ + if (!deduping && TREE_CODE (fns) == OVERLOAD) + { + tree probe = fns; + if (flags & LOOKUP_HIDDEN) + probe = ovl_skip_hidden (probe); + if (probe && TREE_CODE (probe) == OVERLOAD && OVL_USING_P (probe)) + { + /* We're about to add something found by a using + declaration, so need to engage deduping mode. */ + lookup_mark (value, true); + deduping = true; + } + } + + value = lookup_maybe_add (fns, value, deduping); +} + /* Add a NEW_VAL, a found value binding into the current value binding. */ void name_lookup::add_value (tree new_val) { - if (!value) + if (OVL_P (new_val) && (!value || OVL_P (value))) + add_overload (new_val); + else if (!value) value = new_val; else if (value == new_val) ; @@ -428,10 +464,16 @@ name_lookup::add_value (tree new_val) && TREE_CODE (new_val) == TYPE_DECL && same_type_p (TREE_TYPE (value), TREE_TYPE (new_val)))) ; - else if (OVL_P (value) && OVL_P (new_val)) - value = lookup_add (new_val, value); else - value = ambiguous (new_val, value); + { + if (deduping) + { + /* Disengage deduping mode. */ + lookup_mark (value, false); + deduping = false; + } + value = ambiguous (new_val, value); + } } /* Add a NEW_TYPE, a found type binding into the current type binding. */ @@ -703,8 +745,7 @@ name_lookup::add_fns (tree fns) else if (!DECL_DECLARES_FUNCTION_P (fns)) return; - /* Only add those that aren't already there. */ - value = lookup_maybe_add (fns, value); + add_overload (fns); } /* Add functions of a namespace to the lookup structure. */ @@ -1004,7 +1045,11 @@ name_lookup::adl_template_arg (tree arg) tree name_lookup::search_adl (tree fns, vec *args) { - lookup_mark (fns, true); + if (fns) + { + deduping = true; + lookup_mark (fns, true); + } value = fns; unsigned ix; @@ -1019,7 +1064,6 @@ name_lookup::search_adl (tree fns, vec *args) adl_expr (arg); fns = value; - lookup_mark (fns, false); return fns; } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index d3a0d7a..3602166 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -21728,32 +21728,32 @@ most_specialized_instantiation (tree templates) champ = templates; for (fn = TREE_CHAIN (templates); fn; fn = TREE_CHAIN (fn)) - if (TREE_VALUE (champ) != TREE_VALUE (fn)) - { - int fate = more_specialized_inst (TREE_VALUE (champ), TREE_VALUE (fn)); - if (fate == -1) + { + gcc_assert (TREE_VALUE (champ) != TREE_VALUE (fn)); + int fate = more_specialized_inst (TREE_VALUE (champ), TREE_VALUE (fn)); + if (fate == -1) + champ = fn; + else if (!fate) + { + /* Equally specialized, move to next function. If there + is no next function, nothing's most specialized. */ + fn = TREE_CHAIN (fn); champ = fn; - else if (!fate) - { - /* Equally specialized, move to next function. If there - is no next function, nothing's most specialized. */ - fn = TREE_CHAIN (fn); - champ = fn; - if (!fn) - break; - } - } + if (!fn) + break; + } + } if (champ) /* Now verify that champ is better than everything earlier in the instantiation list. */ - for (fn = templates; fn != champ; fn = TREE_CHAIN (fn)) - if (TREE_VALUE (champ) != TREE_VALUE (fn) - && more_specialized_inst (TREE_VALUE (champ), TREE_VALUE (fn)) != 1) - { - champ = NULL_TREE; - break; - } + for (fn = templates; fn != champ; fn = TREE_CHAIN (fn)) { + if (more_specialized_inst (TREE_VALUE (champ), TREE_VALUE (fn)) != 1) + { + champ = NULL_TREE; + break; + } + } processing_template_decl--; diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 411c9f3..bb17278 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -2293,21 +2293,10 @@ ovl_iterator::remove_node (tree overload, tree node) void lookup_mark (tree ovl, bool val) { - /* For every node that is a lookup, mark the thing it points to. */ - for (; ovl && TREE_CODE (ovl) == OVERLOAD && OVL_LOOKUP_P (ovl); - ovl = OVL_CHAIN (ovl)) - { - tree targ = OVL_FUNCTION (ovl); - gcc_checking_assert (LOOKUP_SEEN_P (targ) != val); - LOOKUP_SEEN_P (targ) = val; - } - - if (ovl && (TREE_CODE (ovl) == OVERLOAD || - TREE_CODE (ovl) == FUNCTION_DECL)) + for (lkp_iterator iter (ovl); iter; ++iter) { - /* Mark the overload itsef. */ - gcc_checking_assert (LOOKUP_SEEN_P (ovl) != val); - LOOKUP_SEEN_P (ovl) = val; + gcc_checking_assert (LOOKUP_SEEN_P (*iter) != val); + LOOKUP_SEEN_P (*iter) = val; } } @@ -2327,73 +2316,48 @@ lookup_add (tree fns, tree lookup) return lookup; } -/* FNS is a new overload set, add it to LOOKUP, if it is not already - present there. */ +/* FNS is a new overload set, add them to LOOKUP, if they are not + already present there. */ tree -lookup_maybe_add (tree fns, tree lookup) +lookup_maybe_add (tree fns, tree lookup, bool deduping) { - if (LOOKUP_SEEN_P (fns)) - return lookup; - - if (lookup && TREE_CODE (fns) == OVERLOAD) - { - /* Determine if we already have some part of this overload in - the overload set. If so fix things up so we only have the - overload set once. */ - tree marked = NULL_TREE; + if (deduping) + for (tree next, probe = fns; probe; probe = next) + { + tree fn = probe; + next = NULL_TREE; - for (tree probe = fns; probe; probe = OVL_CHAIN (probe)) - if (LOOKUP_SEEN_P (probe)) + if (TREE_CODE (probe) == OVERLOAD) { - marked = probe; - break; + fn = OVL_FUNCTION (probe); + next = OVL_CHAIN (probe); } - else if (TREE_CODE (probe) != OVERLOAD) - break; - if (marked) - { - /* The tail of this overload is already in the lookup - set. Stitch out the tail case, which might involve - copying. */ - bool rewrite = false; - - LOOKUP_SEEN_P (marked) = false; - for (tree *prev = &lookup, probe = *prev; - ; prev = &OVL_CHAIN (probe), probe = *prev) - { - if (probe == marked) - { - *prev = NULL_TREE; - break; - } - gcc_checking_assert (OVL_LOOKUP_P (probe)); - if (marked == OVL_FUNCTION (probe)) - { - *prev = OVL_CHAIN (probe); - break; - } + if (!LOOKUP_SEEN_P (fn)) + LOOKUP_SEEN_P (fn) = true; + else + { + /* This function was already seen. Insert all the + predecessors onto the lookup. */ + for (; fns != probe; fns = OVL_CHAIN (fns)) + { + lookup = lookup_add (OVL_FUNCTION (fns), lookup); + /* Propagate OVL_USING, but OVL_HIDDEN doesn't matter. */ + if (OVL_USING_P (fns)) + OVL_USING_P (lookup) = true; + } - /* If we're in a used part of the lookup set, copy the - node, so as to not disturb stored uses. */ - gcc_checking_assert (!rewrite || OVL_USED_P (probe)); - if (OVL_USED_P (probe)) - { - rewrite = true; - probe = ovl_copy (probe); - OVL_LOOKUP_P (probe) = true; - *prev = probe; - } - } - } - } + /* And now skip this function. */ + fns = next; + } + } - /* Finally mark the new overload and prepend it to the current - lookup. */ - LOOKUP_SEEN_P (fns) = true; + if (fns) + /* We ended in a set of new functions. Add them all in one go. */ + lookup = lookup_add (fns, lookup); - return lookup_add (fns, lookup); + return lookup; } /* Regular overload OVL is part of a kept lookup. Mark the nodes on diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 58dd05b..1b7ef97 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-05-29 Nathan Sidwell + + PR c++/80891 (#5) + * g++.dg/lookup/pr80891-5.C: New. + 2017-05-29 Jerry DeLisle PR libgfortran/53029 diff --git a/gcc/testsuite/g++.dg/lookup/pr80891-5.C b/gcc/testsuite/g++.dg/lookup/pr80891-5.C new file mode 100644 index 0000000..ebf64f8 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/pr80891-5.C @@ -0,0 +1,68 @@ +// PR c++/80891 part 4 + +// ICE copying an augmented lookup during ADL + +struct __normal_iterator get(); // { dg-message "candidate: .__normal_iterator get\\(\\)." } +namespace boost { +template void get(); // { dg-message "candidate: .template void boost::get\\(\\)." } +struct A { + A(int); +}; +enum problem_selector { subgraph_iso }; +template +struct B { + B(A, A, int, int, int, int); + void m_fn1(SubGraphIsoMapCallback p1) { + __normal_iterator __trans_tmp_1(); + p1(__trans_tmp_1, 0); + } +}; +template +void match( + Graph1, Graph2, SubGraphIsoMapCallback p3, VertexOrder1, + B + p5) { + p5.m_fn1(p3); +} +template +void vf2_subgraph_morphism(GraphSmall, GraphLarge, SubGraphIsoMapCallback p3, + IndexMapSmall, IndexMapLarge, VertexOrderSmall, + EdgeEquivalencePredicate, + VertexEquivalencePredicate) { + B + s(0, 0, 0, 0, 0, 0); + match(0, 0, p3, 0, s); +} +template +int vf2_subgraph_iso(GraphSmall, GraphLarge, SubGraphIsoMapCallback p3, + IndexMapSmall, IndexMapLarge, VertexOrderSmall, + EdgeEquivalencePredicate, VertexEquivalencePredicate) { + vf2_subgraph_morphism(0, 0, p3, 0, 0, 0, 0, 0); +} +} +using namespace boost; +struct C { + C(int) : graph1_(0), graph2_(0) {} + template + void operator()(CorrespondenceMap1To2 p1, CorrespondenceMap2To1) { + get(p1); // { dg-error "no matching function" } + } + A graph1_; + A graph2_; +}; +template void get(); // { dg-message "candidate: .template void get\\(\\)." } +void test_vf2_sub_graph_iso() { C a(vf2_subgraph_iso(0, 0, a, 0, 0, 0, 0, 0)); +} -- 2.7.4