Branch data Line data Source code
1 : : /* Breadth-first and depth-first routines for
2 : : searching multiple-inheritance lattice for GNU C++.
3 : : Copyright (C) 1987-2024 Free Software Foundation, Inc.
4 : : Contributed by Michael Tiemann (tiemann@cygnus.com)
5 : :
6 : : This file is part of GCC.
7 : :
8 : : GCC is free software; you can redistribute it and/or modify
9 : : it under the terms of the GNU General Public License as published by
10 : : the Free Software Foundation; either version 3, or (at your option)
11 : : any later version.
12 : :
13 : : GCC is distributed in the hope that it will be useful,
14 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
15 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 : : GNU General Public License for more details.
17 : :
18 : : You should have received a copy of the GNU General Public License
19 : : along with GCC; see the file COPYING3. If not see
20 : : <http://www.gnu.org/licenses/>. */
21 : :
22 : : /* High-level class interface. */
23 : :
24 : : #include "config.h"
25 : : #include "system.h"
26 : : #include "coretypes.h"
27 : : #include "cp-tree.h"
28 : : #include "intl.h"
29 : : #include "toplev.h"
30 : : #include "spellcheck-tree.h"
31 : : #include "stringpool.h"
32 : : #include "attribs.h"
33 : : #include "tree-inline.h"
34 : :
35 : : static int is_subobject_of_p (tree, tree);
36 : : static tree dfs_lookup_base (tree, void *);
37 : : static tree dfs_dcast_hint_pre (tree, void *);
38 : : static tree dfs_dcast_hint_post (tree, void *);
39 : : static tree dfs_debug_mark (tree, void *);
40 : : static int check_hidden_convs (tree, int, int, tree, tree, tree);
41 : : static tree split_conversions (tree, tree, tree, tree);
42 : : static int lookup_conversions_r (tree, int, int, tree, tree, tree *);
43 : : static int look_for_overrides_r (tree, tree);
44 : : static tree lookup_field_r (tree, void *);
45 : : static tree dfs_accessible_post (tree, void *);
46 : : static tree dfs_walk_once_accessible (tree, bool,
47 : : tree (*pre_fn) (tree, void *),
48 : : tree (*post_fn) (tree, void *),
49 : : void *data);
50 : : static tree dfs_access_in_type (tree, void *);
51 : : static access_kind access_in_type (tree, tree);
52 : : static tree dfs_get_pure_virtuals (tree, void *);
53 : :
54 : :
55 : : /* Data for lookup_base and its workers. */
56 : :
57 : : struct lookup_base_data_s
58 : : {
59 : : HOST_WIDE_INT offset; /* Offset we want, or -1 if any. */
60 : : tree t; /* type being searched. */
61 : : tree base; /* The base type we're looking for. */
62 : : tree binfo; /* Found binfo. */
63 : : bool via_virtual; /* Found via a virtual path. */
64 : : bool ambiguous; /* Found multiply ambiguous */
65 : : bool repeated_base; /* Whether there are repeated bases in the
66 : : hierarchy. */
67 : : bool want_any; /* Whether we want any matching binfo. */
68 : : };
69 : :
70 : : /* Worker function for lookup_base. See if we've found the desired
71 : : base and update DATA_ (a pointer to LOOKUP_BASE_DATA_S). */
72 : :
73 : : static tree
74 : 776312860 : dfs_lookup_base (tree binfo, void *data_)
75 : : {
76 : 776312860 : struct lookup_base_data_s *data = (struct lookup_base_data_s *) data_;
77 : :
78 : 776312860 : if (data->offset != -1)
79 : : {
80 : : /* We're looking for the type at a particular offset. */
81 : 5368855 : int comp = compare_tree_int (BINFO_OFFSET (binfo), data->offset);
82 : 5368855 : if (comp > 0)
83 : : /* Don't bother looking into bases laid out later; even if they
84 : : do virtually inherit from the base we want, we can get there
85 : : by another path. */
86 : : return dfs_skip_bases;
87 : 5368008 : else if (comp != 0
88 : 5368897 : && SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->base))
89 : : /* Right type, wrong offset. */
90 : : return dfs_skip_bases;
91 : : /* Fall through. */
92 : : }
93 : :
94 : 776312010 : if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->base))
95 : : {
96 : 357824972 : if (!data->binfo)
97 : : {
98 : 357823810 : data->binfo = binfo;
99 : 357823810 : data->via_virtual
100 : 357823810 : = binfo_via_virtual (data->binfo, data->t) != NULL_TREE;
101 : :
102 : 357823810 : if (!data->repeated_base)
103 : : /* If there are no repeated bases, we can stop now. */
104 : : return binfo;
105 : :
106 : 11379 : if (data->want_any && !data->via_virtual)
107 : : /* If this is a non-virtual base, then we can't do
108 : : better. */
109 : : return binfo;
110 : :
111 : : return dfs_skip_bases;
112 : : }
113 : : else
114 : : {
115 : 1162 : gcc_assert (binfo != data->binfo);
116 : :
117 : : /* We've found more than one matching binfo. */
118 : 1162 : if (!data->want_any)
119 : : {
120 : : /* This is immediately ambiguous. */
121 : 1066 : data->binfo = NULL_TREE;
122 : 1066 : data->ambiguous = true;
123 : 1066 : return error_mark_node;
124 : : }
125 : :
126 : : /* Prefer one via a non-virtual path. */
127 : 96 : if (!binfo_via_virtual (binfo, data->t))
128 : : {
129 : 27 : data->binfo = binfo;
130 : 27 : data->via_virtual = false;
131 : 27 : return binfo;
132 : : }
133 : :
134 : : /* There must be repeated bases, otherwise we'd have stopped
135 : : on the first base we found. */
136 : : return dfs_skip_bases;
137 : : }
138 : : }
139 : :
140 : : return NULL_TREE;
141 : : }
142 : :
143 : : /* This deals with bug PR17314.
144 : :
145 : : DECL is a declaration and BINFO represents a class that has attempted (but
146 : : failed) to access DECL.
147 : :
148 : : Examine the parent binfos of BINFO and determine whether any of them had
149 : : private access to DECL. If they did, return the parent binfo. This helps
150 : : in figuring out the correct error message to show (if the parents had
151 : : access, it's their fault for not giving sufficient access to BINFO).
152 : :
153 : : If no parents had access, return NULL_TREE. */
154 : :
155 : : tree
156 : 1105 : get_parent_with_private_access (tree decl, tree binfo)
157 : : {
158 : : /* Only BINFOs should come through here. */
159 : 1105 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
160 : :
161 : 1201 : tree base_binfo = NULL_TREE;
162 : :
163 : : /* Iterate through immediate parent classes. */
164 : 1201 : for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
165 : : {
166 : : /* This parent had private access. Therefore that's why BINFO can't
167 : : access DECL. */
168 : 275 : if (access_in_type (BINFO_TYPE (base_binfo), decl) == ak_private)
169 : 179 : return base_binfo;
170 : : }
171 : :
172 : : /* None of the parents had access. Note: it's impossible for one of the
173 : : parents to have had public or protected access to DECL, since then
174 : : BINFO would have been able to access DECL too. */
175 : : return NULL_TREE;
176 : : }
177 : :
178 : : /* Returns true if type BASE is accessible in T. (BASE is known to be
179 : : a (possibly non-proper) base class of T.) If CONSIDER_LOCAL_P is
180 : : true, consider any special access of the current scope, or access
181 : : bestowed by friendship. */
182 : :
183 : : bool
184 : 35815302 : accessible_base_p (tree t, tree base, bool consider_local_p)
185 : : {
186 : 35815302 : tree decl;
187 : :
188 : : /* [class.access.base]
189 : :
190 : : A base class is said to be accessible if an invented public
191 : : member of the base class is accessible.
192 : :
193 : : If BASE is a non-proper base, this condition is trivially
194 : : true. */
195 : 35815302 : if (same_type_p (t, base))
196 : : return true;
197 : : /* Rather than inventing a public member, we use the implicit
198 : : public typedef created in the scope of every class. */
199 : 8429733 : decl = TYPE_FIELDS (base);
200 : 565244177 : while (!DECL_SELF_REFERENCE_P (decl))
201 : 556814444 : decl = DECL_CHAIN (decl);
202 : 8429733 : while (ANON_AGGR_TYPE_P (t))
203 : 0 : t = TYPE_CONTEXT (t);
204 : 8429733 : return accessible_p (t, decl, consider_local_p);
205 : : }
206 : :
207 : : /* Lookup BASE in the hierarchy dominated by T. Do access checking as
208 : : ACCESS specifies. Return the binfo we discover. If KIND_PTR is
209 : : non-NULL, fill with information about what kind of base we
210 : : discovered. If OFFSET is other than -1, only match at that offset.
211 : :
212 : : If the base is inaccessible, or ambiguous, then error_mark_node is
213 : : returned. If the tf_error bit of COMPLAIN is not set, no error
214 : : is issued. */
215 : :
216 : : tree
217 : 600005860 : lookup_base (tree t, tree base, base_access access,
218 : : base_kind *kind_ptr, tsubst_flags_t complain,
219 : : HOST_WIDE_INT offset /* = -1 */)
220 : : {
221 : 600005860 : tree binfo;
222 : 600005860 : tree t_binfo;
223 : 600005860 : base_kind bk;
224 : :
225 : : /* "Nothing" is definitely not derived from Base. */
226 : 600005860 : if (t == NULL_TREE)
227 : : {
228 : 4729 : if (kind_ptr)
229 : 0 : *kind_ptr = bk_not_base;
230 : 4729 : return NULL_TREE;
231 : : }
232 : :
233 : 600001131 : if (t == error_mark_node || base == error_mark_node)
234 : : {
235 : 0 : if (kind_ptr)
236 : 0 : *kind_ptr = bk_not_base;
237 : 0 : return error_mark_node;
238 : : }
239 : 600001131 : gcc_assert (TYPE_P (base));
240 : :
241 : 600001131 : if (!TYPE_P (t))
242 : : {
243 : 2959065 : t_binfo = t;
244 : 2959065 : t = BINFO_TYPE (t);
245 : : }
246 : : else
247 : : {
248 : 597042066 : t = complete_type (TYPE_MAIN_VARIANT (t));
249 : 597042066 : if (dependent_type_p (t))
250 : 145472613 : if (tree open = currently_open_class (t))
251 : 597042066 : t = open;
252 : 597042066 : t_binfo = TYPE_BINFO (t);
253 : : }
254 : :
255 : 600001131 : base = TYPE_MAIN_VARIANT (base);
256 : :
257 : : /* If BASE is incomplete, it can't be a base of T--and instantiating it
258 : : might cause an error. */
259 : 600001131 : if (t_binfo && CLASS_TYPE_P (base) && COMPLETE_OR_OPEN_TYPE_P (base))
260 : : {
261 : 595193663 : struct lookup_base_data_s data;
262 : :
263 : 595193663 : data.t = t;
264 : 595193663 : data.base = base;
265 : 595193663 : data.binfo = NULL_TREE;
266 : 595193663 : data.ambiguous = data.via_virtual = false;
267 : 595193663 : data.repeated_base = (offset == -1) && CLASSTYPE_REPEATED_BASE_P (t);
268 : 595193663 : data.want_any = access == ba_any;
269 : 595193663 : data.offset = offset;
270 : :
271 : 595193663 : dfs_walk_once (t_binfo, dfs_lookup_base, NULL, &data);
272 : 595193663 : binfo = data.binfo;
273 : :
274 : 595193663 : if (!binfo)
275 : 237370919 : bk = data.ambiguous ? bk_ambig : bk_not_base;
276 : 357822744 : else if (binfo == t_binfo)
277 : : bk = bk_same_type;
278 : 68100877 : else if (data.via_virtual)
279 : : bk = bk_via_virtual;
280 : : else
281 : 67487730 : bk = bk_proper_base;
282 : : }
283 : : else
284 : : {
285 : : binfo = NULL_TREE;
286 : : bk = bk_not_base;
287 : : }
288 : :
289 : : /* Check that the base is unambiguous and accessible. */
290 : 600001131 : if (access != ba_any)
291 : 13588321 : switch (bk)
292 : : {
293 : : case bk_not_base:
294 : : break;
295 : :
296 : 1066 : case bk_ambig:
297 : 1066 : if (complain & tf_error)
298 : 84 : error ("%qT is an ambiguous base of %qT", base, t);
299 : 1066 : binfo = error_mark_node;
300 : 1066 : break;
301 : :
302 : 13575848 : default:
303 : 13575848 : if ((access & ba_check_bit)
304 : : /* If BASE is incomplete, then BASE and TYPE are probably
305 : : the same, in which case BASE is accessible. If they
306 : : are not the same, then TYPE is invalid. In that case,
307 : : there's no need to issue another error here, and
308 : : there's no implicit typedef to use in the code that
309 : : follows, so we skip the check. */
310 : 3551496 : && COMPLETE_TYPE_P (base)
311 : 17127338 : && !accessible_base_p (t, base, !(access & ba_ignore_scope)))
312 : : {
313 : 320 : if (complain & tf_error)
314 : 48 : error ("%qT is an inaccessible base of %qT", base, t);
315 : 320 : binfo = error_mark_node;
316 : 320 : bk = bk_inaccessible;
317 : : }
318 : : break;
319 : : }
320 : :
321 : 600001131 : if (kind_ptr)
322 : 3306184 : *kind_ptr = bk;
323 : :
324 : : return binfo;
325 : : }
326 : :
327 : : /* Data for dcast_base_hint walker. */
328 : :
329 : : struct dcast_data_s
330 : : {
331 : : tree subtype; /* The base type we're looking for. */
332 : : int virt_depth; /* Number of virtual bases encountered from most
333 : : derived. */
334 : : tree offset; /* Best hint offset discovered so far. */
335 : : bool repeated_base; /* Whether there are repeated bases in the
336 : : hierarchy. */
337 : : };
338 : :
339 : : /* Worker for dcast_base_hint. Search for the base type being cast
340 : : from. */
341 : :
342 : : static tree
343 : 15864 : dfs_dcast_hint_pre (tree binfo, void *data_)
344 : : {
345 : 15864 : struct dcast_data_s *data = (struct dcast_data_s *) data_;
346 : :
347 : 15864 : if (BINFO_VIRTUAL_P (binfo))
348 : 135 : data->virt_depth++;
349 : :
350 : 15864 : if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->subtype))
351 : : {
352 : 7312 : if (data->virt_depth)
353 : : {
354 : 120 : data->offset = ssize_int (-1);
355 : 120 : return data->offset;
356 : : }
357 : 7192 : if (data->offset)
358 : 12 : data->offset = ssize_int (-3);
359 : : else
360 : 7180 : data->offset = BINFO_OFFSET (binfo);
361 : :
362 : 7192 : return data->repeated_base ? dfs_skip_bases : data->offset;
363 : : }
364 : :
365 : : return NULL_TREE;
366 : : }
367 : :
368 : : /* Worker for dcast_base_hint. Track the virtual depth. */
369 : :
370 : : static tree
371 : 1015 : dfs_dcast_hint_post (tree binfo, void *data_)
372 : : {
373 : 1015 : struct dcast_data_s *data = (struct dcast_data_s *) data_;
374 : :
375 : 1015 : if (BINFO_VIRTUAL_P (binfo))
376 : 3 : data->virt_depth--;
377 : :
378 : 1015 : return NULL_TREE;
379 : : }
380 : :
381 : : /* The dynamic cast runtime needs a hint about how the static SUBTYPE type
382 : : started from is related to the required TARGET type, in order to optimize
383 : : the inheritance graph search. This information is independent of the
384 : : current context, and ignores private paths, hence get_base_distance is
385 : : inappropriate. Return a TREE specifying the base offset, BOFF.
386 : : BOFF >= 0, there is only one public non-virtual SUBTYPE base at offset BOFF,
387 : : and there are no public virtual SUBTYPE bases.
388 : : BOFF == -1, SUBTYPE occurs as multiple public virtual or non-virtual bases.
389 : : BOFF == -2, SUBTYPE is not a public base.
390 : : BOFF == -3, SUBTYPE occurs as multiple public non-virtual bases. */
391 : :
392 : : tree
393 : 7592 : dcast_base_hint (tree subtype, tree target)
394 : : {
395 : 7592 : struct dcast_data_s data;
396 : :
397 : 7592 : data.subtype = subtype;
398 : 7592 : data.virt_depth = 0;
399 : 7592 : data.offset = NULL_TREE;
400 : 7592 : data.repeated_base = CLASSTYPE_REPEATED_BASE_P (target);
401 : :
402 : 7592 : dfs_walk_once_accessible (TYPE_BINFO (target), /*friends=*/false,
403 : : dfs_dcast_hint_pre, dfs_dcast_hint_post, &data);
404 : 7592 : return data.offset ? data.offset : ssize_int (-2);
405 : : }
406 : :
407 : : /* Search for a member with name NAME in a multiple inheritance
408 : : lattice specified by TYPE. If it does not exist, return NULL_TREE.
409 : : If the member is ambiguously referenced, return `error_mark_node'.
410 : : Otherwise, return a DECL with the indicated name. If WANT_TYPE is
411 : : true, type declarations are preferred. */
412 : :
413 : : /* Return the FUNCTION_DECL, RECORD_TYPE, UNION_TYPE, or
414 : : NAMESPACE_DECL corresponding to the innermost non-block scope. */
415 : :
416 : : tree
417 : 1744936548 : current_scope (void)
418 : : {
419 : : /* There are a number of cases we need to be aware of here:
420 : : current_class_type current_function_decl
421 : : global NULL NULL
422 : : fn-local NULL SET
423 : : class-local SET NULL
424 : : class->fn SET SET
425 : : fn->class SET SET
426 : :
427 : : Those last two make life interesting. If we're in a function which is
428 : : itself inside a class, we need decls to go into the fn's decls (our
429 : : second case below). But if we're in a class and the class itself is
430 : : inside a function, we need decls to go into the decls for the class. To
431 : : achieve this last goal, we must see if, when both current_class_ptr and
432 : : current_function_decl are set, the class was declared inside that
433 : : function. If so, we know to put the decls into the class's scope. */
434 : 422415243 : if (current_function_decl && current_class_type
435 : 2019940291 : && ((DECL_FUNCTION_MEMBER_P (current_function_decl)
436 : 269382464 : && same_type_p (DECL_CONTEXT (current_function_decl),
437 : : current_class_type))
438 : 19573082 : || (DECL_FRIEND_CONTEXT (current_function_decl)
439 : 3636140 : && same_type_p (DECL_FRIEND_CONTEXT (current_function_decl),
440 : : current_class_type))))
441 : 268650019 : return current_function_decl;
442 : :
443 : 1476286529 : if (current_class_type)
444 : : return current_class_type;
445 : :
446 : 725163741 : if (current_function_decl)
447 : : return current_function_decl;
448 : :
449 : 577752241 : return current_namespace;
450 : : }
451 : :
452 : : /* Returns nonzero if we are currently in a function scope. Note
453 : : that this function returns zero if we are within a local class, but
454 : : not within a member function body of the local class. */
455 : :
456 : : int
457 : 407998107 : at_function_scope_p (void)
458 : : {
459 : 407998107 : tree cs = current_scope ();
460 : : /* Also check cfun to make sure that we're really compiling
461 : : this function (as opposed to having set current_function_decl
462 : : for access checking or some such). */
463 : 407998107 : return (cs && TREE_CODE (cs) == FUNCTION_DECL
464 : 544310909 : && cfun && cfun->decl == current_function_decl);
465 : : }
466 : :
467 : : /* Returns true if the innermost active scope is a class scope. */
468 : :
469 : : bool
470 : 590897256 : at_class_scope_p (void)
471 : : {
472 : 590897256 : tree cs = current_scope ();
473 : 590897256 : return cs && TYPE_P (cs);
474 : : }
475 : :
476 : : /* Returns true if the innermost active scope is a namespace scope. */
477 : :
478 : : bool
479 : 292042338 : at_namespace_scope_p (void)
480 : : {
481 : 292042338 : tree cs = current_scope ();
482 : 292042338 : return cs && TREE_CODE (cs) == NAMESPACE_DECL;
483 : : }
484 : :
485 : : /* Return the scope of DECL, as appropriate when doing name-lookup. */
486 : :
487 : : tree
488 : 4850136978 : context_for_name_lookup (tree decl)
489 : : {
490 : : /* [class.union]
491 : :
492 : : For the purposes of name lookup, after the anonymous union
493 : : definition, the members of the anonymous union are considered to
494 : : have been defined in the scope in which the anonymous union is
495 : : declared. */
496 : 4850136978 : tree context = DECL_CONTEXT (decl);
497 : :
498 : 9286538750 : while (context && TYPE_P (context)
499 : 6878617919 : && (ANON_AGGR_TYPE_P (context) || UNSCOPED_ENUM_P (context)))
500 : 53309629 : context = TYPE_CONTEXT (context);
501 : 4850136978 : if (!context)
502 : 467044835 : context = global_namespace;
503 : :
504 : 4850136978 : return context;
505 : : }
506 : :
507 : : /* Like the above, but always return a type, because it's simpler for member
508 : : handling to refer to the anonymous aggr rather than a function. */
509 : :
510 : : tree
511 : 972725 : type_context_for_name_lookup (tree decl)
512 : : {
513 : 972725 : tree context = DECL_P (decl) ? DECL_CONTEXT (decl) : decl;
514 : 972725 : gcc_checking_assert (CLASS_TYPE_P (context));
515 : :
516 : 974984 : while (context && TYPE_P (context) && ANON_AGGR_TYPE_P (context))
517 : : {
518 : 2271 : tree next = TYPE_CONTEXT (context);
519 : 2271 : if (!TYPE_P (next))
520 : : break;
521 : : context = next;
522 : : }
523 : 972725 : return context;
524 : : }
525 : :
526 : : /* Returns true iff DECL is declared in TYPE. */
527 : :
528 : : static bool
529 : 379598226 : member_declared_in_type (tree decl, tree type)
530 : : {
531 : : /* A normal declaration obviously counts. */
532 : 379598226 : if (context_for_name_lookup (decl) == type)
533 : : return true;
534 : : /* So does a using or access declaration. */
535 : 117291286 : if (DECL_LANG_SPECIFIC (decl) && !DECL_DISCRIMINATOR_P (decl)
536 : 117291286 : && purpose_member (type, DECL_ACCESS (decl)))
537 : : return true;
538 : : return false;
539 : : }
540 : :
541 : : /* The accessibility routines use BINFO_ACCESS for scratch space
542 : : during the computation of the accessibility of some declaration. */
543 : :
544 : : /* Avoid walking up past a declaration of the member. */
545 : :
546 : : static tree
547 : 336492207 : dfs_access_in_type_pre (tree binfo, void *data)
548 : : {
549 : 336492207 : tree decl = (tree) data;
550 : 336492207 : tree type = BINFO_TYPE (binfo);
551 : 336492207 : if (member_declared_in_type (decl, type))
552 : 279517802 : return dfs_skip_bases;
553 : : return NULL_TREE;
554 : : }
555 : :
556 : : #define BINFO_ACCESS(NODE) \
557 : : ((access_kind) ((TREE_PUBLIC (NODE) << 1) | TREE_PRIVATE (NODE)))
558 : :
559 : : /* Set the access associated with NODE to ACCESS. */
560 : :
561 : : #define SET_BINFO_ACCESS(NODE, ACCESS) \
562 : : ((TREE_PUBLIC (NODE) = ((ACCESS) & 2) != 0), \
563 : : (TREE_PRIVATE (NODE) = ((ACCESS) & 1) != 0))
564 : :
565 : : /* Called from access_in_type via dfs_walk. Calculate the access to
566 : : DATA (which is really a DECL) in BINFO. */
567 : :
568 : : static tree
569 : 336492207 : dfs_access_in_type (tree binfo, void *data)
570 : : {
571 : 336492207 : tree decl = (tree) data;
572 : 336492207 : tree type = BINFO_TYPE (binfo);
573 : 336492207 : access_kind access = ak_none;
574 : :
575 : 336492207 : if (context_for_name_lookup (decl) == type)
576 : : {
577 : : /* If we have descended to the scope of DECL, just note the
578 : : appropriate access. */
579 : 278955789 : if (TREE_PRIVATE (decl))
580 : : access = ak_private;
581 : 249579574 : else if (TREE_PROTECTED (decl))
582 : : access = ak_protected;
583 : : else
584 : 291659896 : access = ak_public;
585 : : }
586 : : else
587 : : {
588 : : /* First, check for an access-declaration that gives us more
589 : : access to the DECL. */
590 : 57536418 : if (DECL_LANG_SPECIFIC (decl) && !DECL_DISCRIMINATOR_P (decl))
591 : : {
592 : 80986303 : tree decl_access = purpose_member (type, DECL_ACCESS (decl));
593 : :
594 : 53043803 : if (decl_access)
595 : : {
596 : 562013 : decl_access = TREE_VALUE (decl_access);
597 : :
598 : 562013 : if (decl_access == access_public_node)
599 : : access = ak_public;
600 : 205083 : else if (decl_access == access_protected_node)
601 : : access = ak_protected;
602 : 33952 : else if (decl_access == access_private_node)
603 : : access = ak_private;
604 : : else
605 : 0 : gcc_unreachable ();
606 : : }
607 : : }
608 : :
609 : : if (!access)
610 : : {
611 : 56974405 : int i;
612 : 56974405 : tree base_binfo;
613 : 56974405 : vec<tree, va_gc> *accesses;
614 : :
615 : : /* Otherwise, scan our baseclasses, and pick the most favorable
616 : : access. */
617 : 56974405 : accesses = BINFO_BASE_ACCESSES (binfo);
618 : 63302184 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
619 : : {
620 : 56267153 : tree base_access = (*accesses)[i];
621 : 56267153 : access_kind base_access_now = BINFO_ACCESS (base_binfo);
622 : :
623 : 56267153 : if (base_access_now == ak_none || base_access_now == ak_private)
624 : : /* If it was not accessible in the base, or only
625 : : accessible as a private member, we can't access it
626 : : all. */
627 : : base_access_now = ak_none;
628 : 53356244 : else if (base_access == access_protected_node)
629 : : /* Public and protected members in the base become
630 : : protected here. */
631 : : base_access_now = ak_protected;
632 : 52915586 : else if (base_access == access_private_node)
633 : : /* Public and protected members in the base become
634 : : private here. */
635 : : base_access_now = ak_private;
636 : :
637 : : /* See if the new access, via this base, gives more
638 : : access than our previous best access. */
639 : 51759361 : if (base_access_now != ak_none
640 : 53356244 : && (access == ak_none || base_access_now < access))
641 : : {
642 : 53355907 : access = base_access_now;
643 : :
644 : : /* If the new access is public, we can't do better. */
645 : 53355907 : if (access == ak_public)
646 : : break;
647 : : }
648 : : }
649 : : }
650 : : }
651 : :
652 : : /* Note the access to DECL in TYPE. */
653 : 336492207 : SET_BINFO_ACCESS (binfo, access);
654 : :
655 : 336492207 : return NULL_TREE;
656 : : }
657 : :
658 : : /* Return the access to DECL in TYPE. */
659 : :
660 : : static access_kind
661 : 279517650 : access_in_type (tree type, tree decl)
662 : : {
663 : 279517650 : tree binfo = TYPE_BINFO (type);
664 : :
665 : : /* We must take into account
666 : :
667 : : [class.paths]
668 : :
669 : : If a name can be reached by several paths through a multiple
670 : : inheritance graph, the access is that of the path that gives
671 : : most access.
672 : :
673 : : The algorithm we use is to make a post-order depth-first traversal
674 : : of the base-class hierarchy. As we come up the tree, we annotate
675 : : each node with the most lenient access. */
676 : 279517650 : dfs_walk_once (binfo, dfs_access_in_type_pre, dfs_access_in_type, decl);
677 : :
678 : 279517650 : return BINFO_ACCESS (binfo);
679 : : }
680 : :
681 : : /* Returns nonzero if it is OK to access DECL named in TYPE through an object
682 : : of OTYPE in the context of DERIVED. */
683 : :
684 : : static int
685 : 8447918 : protected_accessible_p (tree decl, tree derived, tree type, tree otype)
686 : : {
687 : : /* We're checking this clause from [class.access.base]
688 : :
689 : : m as a member of N is protected, and the reference occurs in a
690 : : member or friend of class N, or in a member or friend of a
691 : : class P derived from N, where m as a member of P is public, private
692 : : or protected.
693 : :
694 : : Here DERIVED is a possible P, DECL is m and TYPE is N. */
695 : :
696 : : /* If DERIVED isn't derived from N, then it can't be a P. */
697 : 8447918 : if (!DERIVED_FROM_P (type, derived))
698 : : return 0;
699 : :
700 : : /* DECL_NONSTATIC_MEMBER_P won't work for USING_DECLs. */
701 : 8387456 : decl = strip_using_decl (decl);
702 : : /* We don't expect or support dependent decls. */
703 : 8387456 : gcc_assert (TREE_CODE (decl) != USING_DECL);
704 : :
705 : : /* [class.protected]
706 : :
707 : : When a friend or a member function of a derived class references
708 : : a protected non-static member of a base class, an access check
709 : : applies in addition to those described earlier in clause
710 : : _class.access_) Except when forming a pointer to member
711 : : (_expr.unary.op_), the access must be through a pointer to,
712 : : reference to, or object of the derived class itself (or any class
713 : : derived from that class) (_expr.ref_). If the access is to form
714 : : a pointer to member, the nested-name-specifier shall name the
715 : : derived class (or any class derived from that class). */
716 : 14181142 : if (DECL_NONSTATIC_MEMBER_P (decl)
717 : 12644729 : && !DERIVED_FROM_P (derived, otype))
718 : : return 0;
719 : :
720 : : return 1;
721 : : }
722 : :
723 : : /* Returns nonzero if SCOPE is a type or a friend of a type which would be able
724 : : to access DECL through TYPE. OTYPE is the type of the object. */
725 : :
726 : : static int
727 : 14771979 : friend_accessible_p (tree scope, tree decl, tree type, tree otype)
728 : : {
729 : : /* We're checking this clause from [class.access.base]
730 : :
731 : : m as a member of N is protected, and the reference occurs in a
732 : : member or friend of class N, or in a member or friend of a
733 : : class P derived from N, where m as a member of P is public, private
734 : : or protected.
735 : :
736 : : Here DECL is m and TYPE is N. SCOPE is the current context,
737 : : and we check all its possible Ps. */
738 : 14771979 : tree befriending_classes;
739 : 14771979 : tree t;
740 : :
741 : 14771979 : if (!scope)
742 : : return 0;
743 : :
744 : 14771979 : if (is_global_friend (scope))
745 : : return 1;
746 : :
747 : : /* Is SCOPE itself a suitable P? */
748 : 14771979 : if (TYPE_P (scope) && protected_accessible_p (decl, scope, type, otype))
749 : : return 1;
750 : :
751 : 6396586 : if (DECL_DECLARES_FUNCTION_P (scope))
752 : 6335757 : befriending_classes = DECL_BEFRIENDING_CLASSES (scope);
753 : 60829 : else if (TYPE_P (scope))
754 : 60011 : befriending_classes = CLASSTYPE_BEFRIENDING_CLASSES (scope);
755 : : else
756 : : return 0;
757 : :
758 : 6396302 : for (t = befriending_classes; t; t = TREE_CHAIN (t))
759 : 12514 : if (protected_accessible_p (decl, TREE_VALUE (t), type, otype))
760 : : return 1;
761 : :
762 : : /* Nested classes have the same access as their enclosing types, as
763 : : per DR 45 (this is a change from C++98). */
764 : 6383788 : if (TYPE_P (scope))
765 : 48528 : if (friend_accessible_p (TYPE_CONTEXT (scope), decl, type, otype))
766 : : return 1;
767 : :
768 : 6335859 : if (DECL_DECLARES_FUNCTION_P (scope))
769 : : {
770 : : /* Perhaps this SCOPE is a member of a class which is a
771 : : friend. */
772 : 12670520 : if (DECL_CLASS_SCOPE_P (scope)
773 : 12670172 : && friend_accessible_p (DECL_CONTEXT (scope), decl, type, otype))
774 : : return 1;
775 : : /* Perhaps SCOPE is a friend function defined inside a class from which
776 : : DECL is accessible. */
777 : 910 : if (tree fctx = DECL_FRIEND_CONTEXT (scope))
778 : 3 : if (friend_accessible_p (fctx, decl, type, otype))
779 : : return 1;
780 : : }
781 : :
782 : : /* Maybe scope's template is a friend. */
783 : 1051 : if (tree tinfo = get_template_info (scope))
784 : : {
785 : 802 : tree tmpl = TI_TEMPLATE (tinfo);
786 : 802 : if (DECL_CLASS_TEMPLATE_P (tmpl))
787 : 534 : tmpl = TREE_TYPE (tmpl);
788 : : else
789 : 268 : tmpl = DECL_TEMPLATE_RESULT (tmpl);
790 : 802 : if (tmpl != scope)
791 : : {
792 : : /* Increment processing_template_decl to make sure that
793 : : dependent_type_p works correctly. */
794 : 654 : ++processing_template_decl;
795 : 654 : int ret = friend_accessible_p (tmpl, decl, type, otype);
796 : 654 : --processing_template_decl;
797 : 654 : if (ret)
798 : : return 1;
799 : : }
800 : : }
801 : :
802 : : /* If is_friend is true, we should have found a befriending class. */
803 : 431 : gcc_checking_assert (!is_friend (type, scope));
804 : :
805 : : return 0;
806 : : }
807 : :
808 : : struct dfs_accessible_data
809 : : {
810 : : tree decl;
811 : : tree object_type;
812 : : };
813 : :
814 : : /* Avoid walking up past a declaration of the member. */
815 : :
816 : : static tree
817 : 43106019 : dfs_accessible_pre (tree binfo, void *data)
818 : : {
819 : 43106019 : dfs_accessible_data *d = (dfs_accessible_data *)data;
820 : 43106019 : tree type = BINFO_TYPE (binfo);
821 : 43106019 : if (member_declared_in_type (d->decl, type))
822 : 39027228 : return dfs_skip_bases;
823 : : return NULL_TREE;
824 : : }
825 : :
826 : : /* Called via dfs_walk_once_accessible from accessible_p */
827 : :
828 : : static tree
829 : 39608470 : dfs_accessible_post (tree binfo, void *data)
830 : : {
831 : : /* access_in_type already set BINFO_ACCESS for us. */
832 : 39608470 : access_kind access = BINFO_ACCESS (binfo);
833 : 39608470 : tree N = BINFO_TYPE (binfo);
834 : 39608470 : dfs_accessible_data *d = (dfs_accessible_data *)data;
835 : 39608470 : tree decl = d->decl;
836 : 39608470 : tree scope = current_nonlambda_scope ();
837 : :
838 : : /* A member m is accessible at the point R when named in class N if */
839 : 39608470 : switch (access)
840 : : {
841 : : case ak_none:
842 : : return NULL_TREE;
843 : :
844 : : case ak_public:
845 : : /* m as a member of N is public, or */
846 : : return binfo;
847 : :
848 : 29410085 : case ak_private:
849 : 29410085 : {
850 : : /* m as a member of N is private, and R occurs in a member or friend of
851 : : class N, or */
852 : 29410085 : if (scope && TREE_CODE (scope) != NAMESPACE_DECL
853 : 58819801 : && is_friend (N, scope))
854 : : return binfo;
855 : : return NULL_TREE;
856 : : }
857 : :
858 : 8387882 : case ak_protected:
859 : 8387882 : {
860 : : /* m as a member of N is protected, and R occurs in a member or friend
861 : : of class N, or in a member or friend of a class P derived from N,
862 : : where m as a member of P is public, private, or protected */
863 : 8387882 : if (friend_accessible_p (scope, decl, N, d->object_type))
864 : : return binfo;
865 : : return NULL_TREE;
866 : : }
867 : :
868 : : default:
869 : : gcc_unreachable ();
870 : : }
871 : : }
872 : :
873 : : /* Like accessible_p below, but within a template returns true iff DECL is
874 : : accessible in TYPE to all possible instantiations of the template. */
875 : :
876 : : int
877 : 5190783 : accessible_in_template_p (tree type, tree decl)
878 : : {
879 : 5190783 : int save_ptd = processing_template_decl;
880 : 5190783 : processing_template_decl = 0;
881 : 5190783 : int val = accessible_p (type, decl, false);
882 : 5190783 : processing_template_decl = save_ptd;
883 : 5190783 : return val;
884 : : }
885 : :
886 : : /* DECL is a declaration from a base class of TYPE, which was the
887 : : class used to name DECL. Return nonzero if, in the current
888 : : context, DECL is accessible. If TYPE is actually a BINFO node,
889 : : then we can tell in what context the access is occurring by looking
890 : : at the most derived class along the path indicated by BINFO. If
891 : : CONSIDER_LOCAL is true, do consider special access the current
892 : : scope or friendship thereof we might have. */
893 : :
894 : : int
895 : 279517426 : accessible_p (tree type, tree decl, bool consider_local_p)
896 : : {
897 : 279517426 : tree binfo;
898 : 279517426 : access_kind access;
899 : :
900 : : /* If this declaration is in a block or namespace scope, there's no
901 : : access control. */
902 : 279517426 : if (!TYPE_P (context_for_name_lookup (decl)))
903 : : return 1;
904 : :
905 : : /* There is no need to perform access checks inside a thunk. */
906 : 279517375 : if (current_function_decl && DECL_THUNK_P (current_function_decl))
907 : : return 1;
908 : :
909 : 279517375 : tree otype = NULL_TREE;
910 : 279517375 : if (!TYPE_P (type))
911 : : {
912 : : /* When accessing a non-static member, the most derived type in the
913 : : binfo chain is the type of the object; remember that type for
914 : : protected_accessible_p. */
915 : 548201540 : for (tree b = type; b; b = BINFO_INHERITANCE_CHAIN (b))
916 : 282340369 : otype = BINFO_TYPE (b);
917 : 265861171 : type = BINFO_TYPE (type);
918 : : }
919 : : else
920 : : otype = type;
921 : :
922 : : /* Anonymous unions don't have their own access. */
923 : 279517375 : if (ANON_AGGR_TYPE_P (type))
924 : 3 : type = type_context_for_name_lookup (type);
925 : :
926 : : /* [class.access.base]
927 : :
928 : : A member m is accessible when named in class N if
929 : :
930 : : --m as a member of N is public, or
931 : :
932 : : --m as a member of N is private, and the reference occurs in a
933 : : member or friend of class N, or
934 : :
935 : : --m as a member of N is protected, and the reference occurs in a
936 : : member or friend of class N, or in a member or friend of a
937 : : class P derived from N, where m as a member of P is public, private or
938 : : protected, or
939 : :
940 : : --there exists a base class B of N that is accessible at the point
941 : : of reference, and m is accessible when named in class B.
942 : :
943 : : We walk the base class hierarchy, checking these conditions. */
944 : :
945 : : /* We walk using TYPE_BINFO (type) because access_in_type will set
946 : : BINFO_ACCESS on it and its bases. */
947 : 279517375 : binfo = TYPE_BINFO (type);
948 : :
949 : : /* Compute the accessibility of DECL in the class hierarchy
950 : : dominated by type. */
951 : 279517375 : access = access_in_type (type, decl);
952 : 279517375 : if (access == ak_public)
953 : : return 1;
954 : :
955 : : /* If we aren't considering the point of reference, only the first bullet
956 : : applies. */
957 : 39028734 : if (!consider_local_p)
958 : : return 0;
959 : :
960 : 39028364 : dfs_accessible_data d = { decl, otype };
961 : :
962 : : /* Walk the hierarchy again, looking for a base class that allows
963 : : access. */
964 : 39028364 : return dfs_walk_once_accessible (binfo, /*friends=*/true,
965 : : dfs_accessible_pre,
966 : : dfs_accessible_post, &d)
967 : 39028364 : != NULL_TREE;
968 : : }
969 : :
970 : : struct lookup_field_info {
971 : : /* The type in which we're looking. */
972 : : tree type;
973 : : /* The name of the field for which we're looking. */
974 : : tree name;
975 : : /* If non-NULL, the current result of the lookup. */
976 : : tree rval;
977 : : /* The path to RVAL. */
978 : : tree rval_binfo;
979 : : /* If non-NULL, the lookup was ambiguous, and this is a list of the
980 : : candidates. */
981 : : tree ambiguous;
982 : : /* If nonzero, we are looking for types, not data members. */
983 : : int want_type;
984 : : };
985 : :
986 : : /* True for a class member means that it is shared between all objects
987 : : of that class.
988 : :
989 : : [class.member.lookup]:If the resulting set of declarations are not all
990 : : from sub-objects of the same type, or the set has a non-static member
991 : : and includes members from distinct sub-objects, there is an ambiguity
992 : : and the program is ill-formed.
993 : :
994 : : This function checks that T contains no non-static members. */
995 : :
996 : : bool
997 : 41274833 : shared_member_p (tree t)
998 : : {
999 : 41274833 : if (VAR_P (t) || TREE_CODE (t) == TYPE_DECL
1000 : 38376898 : || TREE_CODE (t) == CONST_DECL)
1001 : : return true;
1002 : 38373414 : if (is_overloaded_fn (t))
1003 : : {
1004 : 65594897 : for (ovl_iterator iter (get_fns (t)); iter; ++iter)
1005 : : {
1006 : 41799968 : tree decl = strip_using_decl (*iter);
1007 : 41799968 : if (TREE_CODE (decl) == USING_DECL)
1008 : : /* Conservatively assume a dependent using-declaration
1009 : : might resolve to a non-static member. */
1010 : 24109001 : return false;
1011 : 41799965 : if (DECL_OBJECT_MEMBER_FUNCTION_P (decl))
1012 : : return false;
1013 : : }
1014 : 14264115 : return true;
1015 : : }
1016 : : return false;
1017 : : }
1018 : :
1019 : : /* Routine to see if the sub-object denoted by the binfo PARENT can be
1020 : : found as a base class and sub-object of the object denoted by
1021 : : BINFO. */
1022 : :
1023 : : static int
1024 : 6848984 : is_subobject_of_p (tree parent, tree binfo)
1025 : : {
1026 : 6848984 : tree probe;
1027 : :
1028 : 18978257 : for (probe = parent; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
1029 : : {
1030 : 13860482 : if (probe == binfo)
1031 : : return 1;
1032 : 13820262 : if (BINFO_VIRTUAL_P (probe))
1033 : 1690989 : return (binfo_for_vbase (BINFO_TYPE (probe), BINFO_TYPE (binfo))
1034 : 1690989 : != NULL_TREE);
1035 : : }
1036 : : return 0;
1037 : : }
1038 : :
1039 : : /* DATA is really a struct lookup_field_info. Look for a field with
1040 : : the name indicated there in BINFO. If this function returns a
1041 : : non-NULL value it is the result of the lookup. Called from
1042 : : lookup_field via breadth_first_search. */
1043 : :
1044 : : static tree
1045 : 5685544060 : lookup_field_r (tree binfo, void *data)
1046 : : {
1047 : 5685544060 : struct lookup_field_info *lfi = (struct lookup_field_info *) data;
1048 : 5685544060 : tree type = BINFO_TYPE (binfo);
1049 : 5685544060 : tree nval = NULL_TREE;
1050 : :
1051 : : /* If this is a dependent base, don't look in it. */
1052 : 5685544060 : if (BINFO_DEPENDENT_BASE_P (binfo))
1053 : : return NULL_TREE;
1054 : :
1055 : : /* If this base class is hidden by the best-known value so far, we
1056 : : don't need to look. */
1057 : 79846930 : if (lfi->rval_binfo && BINFO_INHERITANCE_CHAIN (binfo) == lfi->rval_binfo
1058 : 4532618253 : && !BINFO_VIRTUAL_P (binfo))
1059 : : return dfs_skip_bases;
1060 : :
1061 : 4411997476 : nval = get_class_binding (type, lfi->name, lfi->want_type);
1062 : :
1063 : : /* If there is no declaration with the indicated name in this type,
1064 : : then there's nothing to do. */
1065 : 4411997476 : if (!nval)
1066 : 3894107815 : goto done;
1067 : :
1068 : : /* If the lookup already found a match, and the new value doesn't
1069 : : hide the old one, we might have an ambiguity. */
1070 : 517889661 : if (lfi->rval_binfo
1071 : 517889661 : && !is_subobject_of_p (lfi->rval_binfo, binfo))
1072 : :
1073 : : {
1074 : 3404470 : if (nval == lfi->rval && shared_member_p (nval))
1075 : : /* The two things are really the same. */
1076 : : ;
1077 : 3404260 : else if (is_subobject_of_p (binfo, lfi->rval_binfo))
1078 : : /* The previous value hides the new one. */
1079 : : ;
1080 : : else
1081 : : {
1082 : : /* We have a real ambiguity. We keep a chain of all the
1083 : : candidates. */
1084 : 1757422 : if (!lfi->ambiguous && lfi->rval)
1085 : : {
1086 : : /* This is the first time we noticed an ambiguity. Add
1087 : : what we previously thought was a reasonable candidate
1088 : : to the list. */
1089 : 911730 : lfi->ambiguous = tree_cons (NULL_TREE, lfi->rval, NULL_TREE);
1090 : 911730 : TREE_TYPE (lfi->ambiguous) = error_mark_node;
1091 : : }
1092 : :
1093 : : /* Add the new value. */
1094 : 1757422 : if (TREE_CODE (nval) == TREE_LIST)
1095 : 6 : lfi->ambiguous = chainon (nval, lfi->ambiguous);
1096 : : else
1097 : : {
1098 : 1757416 : lfi->ambiguous = tree_cons (NULL_TREE, nval, lfi->ambiguous);
1099 : 1757416 : TREE_TYPE (lfi->ambiguous) = error_mark_node;
1100 : : }
1101 : : }
1102 : : }
1103 : : else
1104 : : {
1105 : 514485191 : if (TREE_CODE (nval) == TREE_LIST)
1106 : : {
1107 : 97 : lfi->ambiguous = chainon (nval, lfi->ambiguous);
1108 : 97 : lfi->rval = TREE_VALUE (nval);
1109 : : }
1110 : : else
1111 : 514485094 : lfi->rval = nval;
1112 : 514485191 : lfi->rval_binfo = binfo;
1113 : : }
1114 : :
1115 : 4411997476 : done:
1116 : : /* Don't look for constructors or destructors in base classes. */
1117 : 4411997476 : if (IDENTIFIER_CDTOR_P (lfi->name))
1118 : : return dfs_skip_bases;
1119 : : return NULL_TREE;
1120 : : }
1121 : :
1122 : : /* Return a "baselink" with BASELINK_BINFO, BASELINK_ACCESS_BINFO,
1123 : : BASELINK_FUNCTIONS, and BASELINK_OPTYPE set to BINFO, ACCESS_BINFO,
1124 : : FUNCTIONS, and OPTYPE respectively. */
1125 : :
1126 : : tree
1127 : 169601239 : build_baselink (tree binfo, tree access_binfo, tree functions, tree optype)
1128 : : {
1129 : 169601239 : tree baselink;
1130 : :
1131 : 169601239 : gcc_assert (OVL_P (functions) || TREE_CODE (functions) == TEMPLATE_ID_EXPR);
1132 : 169601239 : gcc_assert (!optype || TYPE_P (optype));
1133 : 169601239 : gcc_assert (TREE_TYPE (functions));
1134 : :
1135 : 169601239 : baselink = make_node (BASELINK);
1136 : 169601239 : TREE_TYPE (baselink) = TREE_TYPE (functions);
1137 : 169601239 : BASELINK_BINFO (baselink) = binfo;
1138 : 169601239 : BASELINK_ACCESS_BINFO (baselink) = access_binfo;
1139 : 169601239 : BASELINK_FUNCTIONS (baselink) = functions;
1140 : 169601239 : BASELINK_OPTYPE (baselink) = optype;
1141 : :
1142 : 169601239 : if (binfo == access_binfo
1143 : 330011920 : && TYPE_BEING_DEFINED (BINFO_TYPE (access_binfo)))
1144 : 3670281 : BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P (baselink) = true;
1145 : :
1146 : 169601239 : return baselink;
1147 : : }
1148 : :
1149 : : /* Look for a member named NAME in an inheritance lattice dominated by
1150 : : XBASETYPE. If PROTECT is 0 or two, we do not check access. If it
1151 : : is 1, we enforce accessibility. If PROTECT is zero, then, for an
1152 : : ambiguous lookup, we return NULL. If PROTECT is 1, we issue error
1153 : : messages about inaccessible or ambiguous lookup. If PROTECT is 2,
1154 : : we return a TREE_LIST whose TREE_TYPE is error_mark_node and whose
1155 : : TREE_VALUEs are the list of ambiguous candidates.
1156 : :
1157 : : WANT_TYPE is 1 when we should only return TYPE_DECLs.
1158 : :
1159 : : If nothing can be found return NULL_TREE and do not issue an error.
1160 : :
1161 : : If non-NULL, failure information is written back to AFI. */
1162 : :
1163 : : tree
1164 : 3735364446 : lookup_member (tree xbasetype, tree name, int protect, bool want_type,
1165 : : tsubst_flags_t complain, access_failure_info *afi /* = NULL */)
1166 : : {
1167 : 3735364446 : tree rval, rval_binfo = NULL_TREE;
1168 : 3735364446 : tree type = NULL_TREE, basetype_path = NULL_TREE;
1169 : 3735364446 : struct lookup_field_info lfi;
1170 : :
1171 : : /* rval_binfo is the binfo associated with the found member, note,
1172 : : this can be set with useful information, even when rval is not
1173 : : set, because it must deal with ALL members, not just non-function
1174 : : members. It is used for ambiguity checking and the hidden
1175 : : checks. Whereas rval is only set if a proper (not hidden)
1176 : : non-function member is found. */
1177 : :
1178 : 3735364446 : if (name == error_mark_node
1179 : 3735364446 : || xbasetype == NULL_TREE
1180 : 3735364440 : || xbasetype == error_mark_node)
1181 : : return NULL_TREE;
1182 : :
1183 : 3735364440 : gcc_assert (identifier_p (name));
1184 : :
1185 : 3735364440 : if (TREE_CODE (xbasetype) == TREE_BINFO)
1186 : : {
1187 : 77025650 : type = BINFO_TYPE (xbasetype);
1188 : 77025650 : basetype_path = xbasetype;
1189 : : }
1190 : : else
1191 : : {
1192 : 3658338790 : if (!RECORD_OR_UNION_CODE_P (TREE_CODE (xbasetype)))
1193 : : return NULL_TREE;
1194 : : type = xbasetype;
1195 : 3735364416 : xbasetype = NULL_TREE;
1196 : : }
1197 : :
1198 : 3735364416 : type = complete_type (type);
1199 : :
1200 : : /* Make sure we're looking for a member of the current instantiation in the
1201 : : right partial specialization. */
1202 : 3735364362 : if (dependent_type_p (type))
1203 : 2561416491 : if (tree t = currently_open_class (type))
1204 : 3735364362 : type = t;
1205 : :
1206 : 3735364362 : if (!basetype_path)
1207 : 3658338712 : basetype_path = TYPE_BINFO (type);
1208 : :
1209 : 3658338712 : if (!basetype_path)
1210 : : return NULL_TREE;
1211 : :
1212 : 3659251808 : memset (&lfi, 0, sizeof (lfi));
1213 : 3659251808 : lfi.type = type;
1214 : 3659251808 : lfi.name = name;
1215 : 3659251808 : lfi.want_type = want_type;
1216 : 3659251808 : dfs_walk_all (basetype_path, &lookup_field_r, NULL, &lfi);
1217 : 3659251808 : rval = lfi.rval;
1218 : 3659251808 : rval_binfo = lfi.rval_binfo;
1219 : 3659251808 : if (rval_binfo)
1220 : 514444937 : type = BINFO_TYPE (rval_binfo);
1221 : :
1222 : 3659251808 : if (lfi.ambiguous)
1223 : : {
1224 : 911827 : if (protect == 0)
1225 : : return NULL_TREE;
1226 : 911809 : else if (protect == 1)
1227 : : {
1228 : 81 : if (complain & tf_error)
1229 : : {
1230 : 68 : auto_diagnostic_group d;
1231 : 68 : error ("request for member %qD is ambiguous", name);
1232 : 68 : print_candidates (lfi.ambiguous);
1233 : 68 : }
1234 : 81 : return error_mark_node;
1235 : : }
1236 : 911728 : else if (protect == 2)
1237 : : return lfi.ambiguous;
1238 : : }
1239 : :
1240 : 3658339981 : if (!rval)
1241 : : return NULL_TREE;
1242 : :
1243 : : /* [class.access]
1244 : :
1245 : : In the case of overloaded function names, access control is
1246 : : applied to the function selected by overloaded resolution.
1247 : :
1248 : : We cannot check here, even if RVAL is only a single non-static
1249 : : member function, since we do not know what the "this" pointer
1250 : : will be. For:
1251 : :
1252 : : class A { protected: void f(); };
1253 : : class B : public A {
1254 : : void g(A *p) {
1255 : : f(); // OK
1256 : : p->f(); // Not OK.
1257 : : }
1258 : : };
1259 : :
1260 : : only the first call to "f" is valid. However, if the function is
1261 : : static, we can check. */
1262 : 513533110 : if (protect == 1 && !really_overloaded_fn (rval))
1263 : : {
1264 : 82909483 : tree decl = is_overloaded_fn (rval) ? get_first_fn (rval) : rval;
1265 : 82909483 : decl = strip_using_decl (decl);
1266 : : /* A dependent USING_DECL will be checked after tsubsting. */
1267 : 82909483 : if (TREE_CODE (decl) != USING_DECL
1268 : 77705295 : && !DECL_IOBJ_MEMBER_FUNCTION_P (decl)
1269 : 120552428 : && !perform_or_defer_access_check (basetype_path, decl, decl,
1270 : : complain, afi))
1271 : 72 : return error_mark_node;
1272 : : }
1273 : :
1274 : 513533038 : if (is_overloaded_fn (rval)
1275 : : /* Don't use a BASELINK for class-scope deduction guides since
1276 : : they're not actually member functions. */
1277 : 513533038 : && !dguide_name_p (name))
1278 : 157838858 : rval = build_baselink (rval_binfo, basetype_path, rval,
1279 : 157838858 : (IDENTIFIER_CONV_OP_P (name)
1280 : 294313 : ? TREE_TYPE (name): NULL_TREE));
1281 : : return rval;
1282 : : }
1283 : :
1284 : : /* Helper class for lookup_member_fuzzy. */
1285 : :
1286 : 606 : class lookup_field_fuzzy_info
1287 : : {
1288 : : public:
1289 : 606 : lookup_field_fuzzy_info (bool want_type_p) :
1290 : 606 : m_want_type_p (want_type_p), m_candidates () {}
1291 : :
1292 : : void fuzzy_lookup_field (tree type);
1293 : :
1294 : : /* If true, we are looking for types, not data members. */
1295 : : bool m_want_type_p;
1296 : : /* The result: a vec of identifiers. */
1297 : : auto_vec<tree> m_candidates;
1298 : : };
1299 : :
1300 : : /* Locate all fields within TYPE, append them to m_candidates. */
1301 : :
1302 : : void
1303 : 686 : lookup_field_fuzzy_info::fuzzy_lookup_field (tree type)
1304 : : {
1305 : 686 : if (!CLASS_TYPE_P (type))
1306 : : return;
1307 : :
1308 : 3641 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
1309 : : {
1310 : 2961 : if (m_want_type_p && !DECL_DECLARES_TYPE_P (field))
1311 : 116 : continue;
1312 : :
1313 : 2845 : if (!DECL_NAME (field))
1314 : 72 : continue;
1315 : :
1316 : 2773 : if (is_lambda_ignored_entity (field))
1317 : 36 : continue;
1318 : :
1319 : : /* Ignore special identifiers with space at the end like cdtor or
1320 : : conversion op identifiers. */
1321 : 2737 : if (TREE_CODE (DECL_NAME (field)) == IDENTIFIER_NODE)
1322 : 2737 : if (unsigned int len = IDENTIFIER_LENGTH (DECL_NAME (field)))
1323 : 2737 : if (IDENTIFIER_POINTER (DECL_NAME (field))[len - 1] == ' ')
1324 : 1287 : continue;
1325 : :
1326 : 1450 : m_candidates.safe_push (DECL_NAME (field));
1327 : : }
1328 : : }
1329 : :
1330 : :
1331 : : /* Helper function for lookup_member_fuzzy, called via dfs_walk_all
1332 : : DATA is really a lookup_field_fuzzy_info. Look for a field with
1333 : : the name indicated there in BINFO. Gathers pertinent identifiers into
1334 : : m_candidates. */
1335 : :
1336 : : static tree
1337 : 686 : lookup_field_fuzzy_r (tree binfo, void *data)
1338 : : {
1339 : 686 : lookup_field_fuzzy_info *lffi = (lookup_field_fuzzy_info *) data;
1340 : 686 : tree type = BINFO_TYPE (binfo);
1341 : :
1342 : 686 : lffi->fuzzy_lookup_field (type);
1343 : :
1344 : 686 : return NULL_TREE;
1345 : : }
1346 : :
1347 : : /* Like lookup_member, but try to find the closest match for NAME,
1348 : : rather than an exact match, and return an identifier (or NULL_TREE).
1349 : : Do not complain. */
1350 : :
1351 : : tree
1352 : 606 : lookup_member_fuzzy (tree xbasetype, tree name, bool want_type_p)
1353 : : {
1354 : 606 : tree type = NULL_TREE, basetype_path = NULL_TREE;
1355 : 606 : class lookup_field_fuzzy_info lffi (want_type_p);
1356 : :
1357 : : /* rval_binfo is the binfo associated with the found member, note,
1358 : : this can be set with useful information, even when rval is not
1359 : : set, because it must deal with ALL members, not just non-function
1360 : : members. It is used for ambiguity checking and the hidden
1361 : : checks. Whereas rval is only set if a proper (not hidden)
1362 : : non-function member is found. */
1363 : :
1364 : 606 : if (name == error_mark_node
1365 : 606 : || xbasetype == NULL_TREE
1366 : 606 : || xbasetype == error_mark_node)
1367 : : return NULL_TREE;
1368 : :
1369 : 606 : gcc_assert (identifier_p (name));
1370 : :
1371 : 606 : if (TREE_CODE (xbasetype) == TREE_BINFO)
1372 : : {
1373 : 6 : type = BINFO_TYPE (xbasetype);
1374 : 6 : basetype_path = xbasetype;
1375 : : }
1376 : : else
1377 : : {
1378 : 600 : if (!RECORD_OR_UNION_CODE_P (TREE_CODE (xbasetype)))
1379 : : return NULL_TREE;
1380 : : type = xbasetype;
1381 : 606 : xbasetype = NULL_TREE;
1382 : : }
1383 : :
1384 : 606 : type = complete_type (type);
1385 : :
1386 : : /* Make sure we're looking for a member of the current instantiation in the
1387 : : right partial specialization. */
1388 : 606 : if (flag_concepts && dependent_type_p (type))
1389 : 50 : type = currently_open_class (type);
1390 : :
1391 : 606 : if (!basetype_path)
1392 : 600 : basetype_path = TYPE_BINFO (type);
1393 : :
1394 : 600 : if (!basetype_path)
1395 : : return NULL_TREE;
1396 : :
1397 : : /* Populate lffi.m_candidates. */
1398 : 600 : dfs_walk_all (basetype_path, &lookup_field_fuzzy_r, NULL, &lffi);
1399 : :
1400 : 600 : return find_closest_identifier (name, &lffi.m_candidates);
1401 : 606 : }
1402 : :
1403 : : /* Like lookup_member, except that if we find a function member we
1404 : : return NULL_TREE. */
1405 : :
1406 : : tree
1407 : 21919872 : lookup_field (tree xbasetype, tree name, int protect, bool want_type)
1408 : : {
1409 : 21919872 : tree rval = lookup_member (xbasetype, name, protect, want_type,
1410 : : tf_warning_or_error);
1411 : :
1412 : : /* Ignore functions, but propagate the ambiguity list. */
1413 : 21919872 : if (!error_operand_p (rval)
1414 : 21919872 : && (rval && BASELINK_P (rval)))
1415 : 0 : return NULL_TREE;
1416 : :
1417 : : return rval;
1418 : : }
1419 : :
1420 : : /* Like lookup_member, except that if we find a non-function member we
1421 : : return NULL_TREE. */
1422 : :
1423 : : tree
1424 : 95211336 : lookup_fnfields (tree xbasetype, tree name, int protect,
1425 : : tsubst_flags_t complain)
1426 : : {
1427 : 95211336 : tree rval = lookup_member (xbasetype, name, protect, /*want_type=*/false,
1428 : : complain);
1429 : :
1430 : : /* Ignore non-functions, but propagate the ambiguity list. */
1431 : 95211336 : if (!error_operand_p (rval)
1432 : 95211336 : && (rval && !BASELINK_P (rval)))
1433 : 0 : return NULL_TREE;
1434 : :
1435 : : return rval;
1436 : : }
1437 : :
1438 : : /* DECL is the result of a qualified name lookup. QUALIFYING_SCOPE is
1439 : : the class or namespace used to qualify the name. CONTEXT_CLASS is
1440 : : the class corresponding to the object in which DECL will be used.
1441 : : Return a possibly modified version of DECL that takes into account
1442 : : the CONTEXT_CLASS.
1443 : :
1444 : : In particular, consider an expression like `B::m' in the context of
1445 : : a derived class `D'. If `B::m' has been resolved to a BASELINK,
1446 : : then the most derived class indicated by the BASELINK_BINFO will be
1447 : : `B', not `D'. This function makes that adjustment. */
1448 : :
1449 : : tree
1450 : 123941803 : adjust_result_of_qualified_name_lookup (tree decl,
1451 : : tree qualifying_scope,
1452 : : tree context_class)
1453 : : {
1454 : 86897821 : if (context_class && context_class != error_mark_node
1455 : 86897812 : && CLASS_TYPE_P (context_class)
1456 : 86897806 : && CLASS_TYPE_P (qualifying_scope)
1457 : 50504524 : && DERIVED_FROM_P (qualifying_scope, context_class)
1458 : 126883271 : && BASELINK_P (decl))
1459 : : {
1460 : 2846560 : tree base;
1461 : :
1462 : : /* Look for the QUALIFYING_SCOPE as a base of the CONTEXT_CLASS.
1463 : : Because we do not yet know which function will be chosen by
1464 : : overload resolution, we cannot yet check either accessibility
1465 : : or ambiguity -- in either case, the choice of a static member
1466 : : function might make the usage valid. */
1467 : 2846560 : base = lookup_base (context_class, qualifying_scope,
1468 : : ba_unique, NULL, tf_none);
1469 : 2846560 : if (base && base != error_mark_node)
1470 : : {
1471 : 2846554 : BASELINK_ACCESS_BINFO (decl) = base;
1472 : 2846554 : tree decl_binfo
1473 : 2846554 : = lookup_base (base, BINFO_TYPE (BASELINK_BINFO (decl)),
1474 : : ba_unique, NULL, tf_none);
1475 : 2846554 : if (decl_binfo && decl_binfo != error_mark_node)
1476 : 2846548 : BASELINK_BINFO (decl) = decl_binfo;
1477 : : }
1478 : : }
1479 : :
1480 : 123941803 : if (BASELINK_P (decl))
1481 : 17134265 : BASELINK_QUALIFIED_P (decl) = true;
1482 : :
1483 : 123941803 : return decl;
1484 : : }
1485 : :
1486 : :
1487 : : /* Walk the class hierarchy within BINFO, in a depth-first traversal.
1488 : : PRE_FN is called in preorder, while POST_FN is called in postorder.
1489 : : If PRE_FN returns DFS_SKIP_BASES, child binfos will not be
1490 : : walked. If PRE_FN or POST_FN returns a different non-NULL value,
1491 : : that value is immediately returned and the walk is terminated. One
1492 : : of PRE_FN and POST_FN can be NULL. At each node, PRE_FN and
1493 : : POST_FN are passed the binfo to examine and the caller's DATA
1494 : : value. All paths are walked, thus virtual and morally virtual
1495 : : binfos can be multiply walked. */
1496 : :
1497 : : tree
1498 : 6882824422 : dfs_walk_all (tree binfo, tree (*pre_fn) (tree, void *),
1499 : : tree (*post_fn) (tree, void *), void *data)
1500 : : {
1501 : 6882824422 : tree rval;
1502 : 6882824422 : unsigned ix;
1503 : 6882824422 : tree base_binfo;
1504 : :
1505 : : /* Call the pre-order walking function. */
1506 : 6882824422 : if (pre_fn)
1507 : : {
1508 : 6878466415 : rval = pre_fn (binfo, data);
1509 : 6878466415 : if (rval)
1510 : : {
1511 : 895331251 : if (rval == dfs_skip_bases)
1512 : 537905284 : goto skip_bases;
1513 : : return rval;
1514 : : }
1515 : : }
1516 : :
1517 : : /* Find the next child binfo to walk. */
1518 : 8209847293 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
1519 : : {
1520 : 2296517010 : rval = dfs_walk_all (base_binfo, pre_fn, post_fn, data);
1521 : 2296517010 : if (rval)
1522 : 74162888 : return rval;
1523 : : }
1524 : :
1525 : 6451235567 : skip_bases:
1526 : : /* Call the post-order walking function. */
1527 : 6451235567 : if (post_fn)
1528 : : {
1529 : 369025569 : rval = post_fn (binfo, data);
1530 : 369025569 : gcc_assert (rval != dfs_skip_bases);
1531 : : return rval;
1532 : : }
1533 : :
1534 : : return NULL_TREE;
1535 : : }
1536 : :
1537 : : /* Worker for dfs_walk_once. This behaves as dfs_walk_all, except
1538 : : that binfos are walked at most once. */
1539 : :
1540 : : static tree
1541 : 2671890 : dfs_walk_once_r (tree binfo, tree (*pre_fn) (tree, void *),
1542 : : tree (*post_fn) (tree, void *), hash_set<tree> *pset,
1543 : : void *data)
1544 : : {
1545 : 2671890 : tree rval;
1546 : 2671890 : unsigned ix;
1547 : 2671890 : tree base_binfo;
1548 : :
1549 : : /* Call the pre-order walking function. */
1550 : 2671890 : if (pre_fn)
1551 : : {
1552 : 2328469 : rval = pre_fn (binfo, data);
1553 : 2328469 : if (rval)
1554 : : {
1555 : 530653 : if (rval == dfs_skip_bases)
1556 : 137571 : goto skip_bases;
1557 : :
1558 : : return rval;
1559 : : }
1560 : : }
1561 : :
1562 : : /* Find the next child binfo to walk. */
1563 : 3950822 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
1564 : : {
1565 : 2306053 : if (BINFO_VIRTUAL_P (base_binfo))
1566 : 903737 : if (pset->add (base_binfo))
1567 : 381684 : continue;
1568 : :
1569 : 1924369 : rval = dfs_walk_once_r (base_binfo, pre_fn, post_fn, pset, data);
1570 : 1924369 : if (rval)
1571 : 496468 : return rval;
1572 : : }
1573 : :
1574 : 1782340 : skip_bases:
1575 : : /* Call the post-order walking function. */
1576 : 1782340 : if (post_fn)
1577 : : {
1578 : 494737 : rval = post_fn (binfo, data);
1579 : 494737 : gcc_assert (rval != dfs_skip_bases);
1580 : : return rval;
1581 : : }
1582 : :
1583 : : return NULL_TREE;
1584 : : }
1585 : :
1586 : : /* Like dfs_walk_all, except that binfos are not multiply walked. For
1587 : : non-diamond shaped hierarchies this is the same as dfs_walk_all.
1588 : : For diamond shaped hierarchies we must mark the virtual bases, to
1589 : : avoid multiple walks. */
1590 : :
1591 : : tree
1592 : 918740816 : dfs_walk_once (tree binfo, tree (*pre_fn) (tree, void *),
1593 : : tree (*post_fn) (tree, void *), void *data)
1594 : : {
1595 : 918740816 : static int active = 0; /* We must not be called recursively. */
1596 : 918740816 : tree rval;
1597 : :
1598 : 918740816 : gcc_assert (pre_fn || post_fn);
1599 : 918740816 : gcc_assert (!active);
1600 : 918740816 : active++;
1601 : :
1602 : 918740816 : if (!CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)))
1603 : : /* We are not diamond shaped, and therefore cannot encounter the
1604 : : same binfo twice. */
1605 : 917993295 : rval = dfs_walk_all (binfo, pre_fn, post_fn, data);
1606 : : else
1607 : : {
1608 : 747521 : hash_set<tree> pset;
1609 : 747521 : rval = dfs_walk_once_r (binfo, pre_fn, post_fn, &pset, data);
1610 : 747521 : }
1611 : :
1612 : 918740816 : active--;
1613 : :
1614 : 918740816 : return rval;
1615 : : }
1616 : :
1617 : : /* Worker function for dfs_walk_once_accessible. Behaves like
1618 : : dfs_walk_once_r, except (a) FRIENDS_P is true if special
1619 : : access given by the current context should be considered, (b) ONCE
1620 : : indicates whether bases should be marked during traversal. */
1621 : :
1622 : : static tree
1623 : 43122331 : dfs_walk_once_accessible_r (tree binfo, bool friends_p, hash_set<tree> *pset,
1624 : : tree (*pre_fn) (tree, void *),
1625 : : tree (*post_fn) (tree, void *), void *data)
1626 : : {
1627 : 43122331 : tree rval = NULL_TREE;
1628 : 43122331 : unsigned ix;
1629 : 43122331 : tree base_binfo;
1630 : :
1631 : : /* Call the pre-order walking function. */
1632 : 43122331 : if (pre_fn)
1633 : : {
1634 : 43122331 : rval = pre_fn (binfo, data);
1635 : 43122331 : if (rval)
1636 : : {
1637 : 39034701 : if (rval == dfs_skip_bases)
1638 : 39027345 : goto skip_bases;
1639 : :
1640 : : return rval;
1641 : : }
1642 : : }
1643 : :
1644 : : /* Find the next child binfo to walk. */
1645 : 4695970 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
1646 : : {
1647 : 4113564 : bool mark = pset && BINFO_VIRTUAL_P (base_binfo);
1648 : :
1649 : 7741 : if (mark && pset->contains (base_binfo))
1650 : 0 : continue;
1651 : :
1652 : : /* If the base is inherited via private or protected
1653 : : inheritance, then we can't see it, unless we are a friend of
1654 : : the current binfo. */
1655 : 4113564 : if (BINFO_BASE_ACCESS (binfo, ix) != access_public_node)
1656 : : {
1657 : 1747184 : tree scope;
1658 : 1747184 : if (!friends_p)
1659 : 228 : continue;
1660 : 1746956 : scope = current_scope ();
1661 : 1774323 : if (!scope
1662 : 1746956 : || TREE_CODE (scope) == NAMESPACE_DECL
1663 : 3493763 : || !is_friend (BINFO_TYPE (binfo), scope))
1664 : 27367 : continue;
1665 : : }
1666 : :
1667 : 4085969 : if (mark)
1668 : 388 : pset->add (base_binfo);
1669 : :
1670 : 4085969 : rval = dfs_walk_once_accessible_r (base_binfo, friends_p, pset,
1671 : : pre_fn, post_fn, data);
1672 : 4085969 : if (rval)
1673 : 3505224 : return rval;
1674 : : }
1675 : :
1676 : 39609751 : skip_bases:
1677 : : /* Call the post-order walking function. */
1678 : 39609751 : if (post_fn)
1679 : : {
1680 : 39609485 : rval = post_fn (binfo, data);
1681 : 39609485 : gcc_assert (rval != dfs_skip_bases);
1682 : : return rval;
1683 : : }
1684 : :
1685 : : return NULL_TREE;
1686 : : }
1687 : :
1688 : : /* Like dfs_walk_once except that only accessible bases are walked.
1689 : : FRIENDS_P indicates whether friendship of the local context
1690 : : should be considered when determining accessibility. */
1691 : :
1692 : : static tree
1693 : 39036362 : dfs_walk_once_accessible (tree binfo, bool friends_p,
1694 : : tree (*pre_fn) (tree, void *),
1695 : : tree (*post_fn) (tree, void *), void *data)
1696 : : {
1697 : 39036362 : hash_set<tree> *pset = NULL;
1698 : 39036362 : if (CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)))
1699 : 1843 : pset = new hash_set<tree>;
1700 : 39036362 : tree rval = dfs_walk_once_accessible_r (binfo, friends_p, pset,
1701 : : pre_fn, post_fn, data);
1702 : :
1703 : 39036362 : if (pset)
1704 : 1843 : delete pset;
1705 : 39036362 : return rval;
1706 : : }
1707 : :
1708 : : /* Return true iff the code of T is CODE, and it has compatible
1709 : : type with TYPE. */
1710 : :
1711 : : static bool
1712 : 448 : matches_code_and_type_p (tree t, enum tree_code code, tree type)
1713 : : {
1714 : 448 : if (TREE_CODE (t) != code)
1715 : : return false;
1716 : 434 : if (!cxx_types_compatible_p (TREE_TYPE (t), type))
1717 : : return false;
1718 : : return true;
1719 : : }
1720 : :
1721 : : /* Subroutine of direct_accessor_p and reference_accessor_p.
1722 : : Determine if COMPONENT_REF is a simple field lookup of this->FIELD_DECL.
1723 : : We expect a tree of the form:
1724 : : <component_ref:
1725 : : <indirect_ref:S>
1726 : : <nop_expr:P*
1727 : : <parm_decl (this)>
1728 : : <field_decl (FIELD_DECL)>>>. */
1729 : :
1730 : : static bool
1731 : 203 : field_access_p (tree component_ref, tree field_decl, tree field_type)
1732 : : {
1733 : 203 : if (!matches_code_and_type_p (component_ref, COMPONENT_REF, field_type))
1734 : : return false;
1735 : :
1736 : 189 : tree indirect_ref = TREE_OPERAND (component_ref, 0);
1737 : 189 : if (!INDIRECT_REF_P (indirect_ref))
1738 : : return false;
1739 : :
1740 : 189 : tree ptr = STRIP_NOPS (TREE_OPERAND (indirect_ref, 0));
1741 : 189 : if (!is_object_parameter (ptr))
1742 : : return false;
1743 : :
1744 : : /* Must access the correct field. */
1745 : 189 : if (TREE_OPERAND (component_ref, 1) != field_decl)
1746 : : return false;
1747 : : return true;
1748 : : }
1749 : :
1750 : : /* Subroutine of field_accessor_p.
1751 : :
1752 : : Assuming that INIT_EXPR has already had its code and type checked,
1753 : : determine if it is a simple accessor for FIELD_DECL
1754 : : (of type FIELD_TYPE).
1755 : :
1756 : : Specifically, a simple accessor within struct S of the form:
1757 : : T get_field () { return m_field; }
1758 : : should have a constexpr_fn_retval (saved_tree) of the form:
1759 : : <init_expr:T
1760 : : <result_decl:T
1761 : : <nop_expr:T
1762 : : <component_ref:
1763 : : <indirect_ref:S>
1764 : : <nop_expr:P*
1765 : : <parm_decl (this)>
1766 : : <field_decl (FIELD_DECL)>>>>>. */
1767 : :
1768 : : static bool
1769 : 161 : direct_accessor_p (tree init_expr, tree field_decl, tree field_type)
1770 : : {
1771 : 161 : tree result_decl = TREE_OPERAND (init_expr, 0);
1772 : 161 : if (!matches_code_and_type_p (result_decl, RESULT_DECL, field_type))
1773 : : return false;
1774 : :
1775 : 161 : tree component_ref = STRIP_NOPS (TREE_OPERAND (init_expr, 1));
1776 : 161 : if (!field_access_p (component_ref, field_decl, field_type))
1777 : : return false;
1778 : :
1779 : : return true;
1780 : : }
1781 : :
1782 : : /* Subroutine of field_accessor_p.
1783 : :
1784 : : Assuming that INIT_EXPR has already had its code and type checked,
1785 : : determine if it is a "reference" accessor for FIELD_DECL
1786 : : (of type FIELD_REFERENCE_TYPE).
1787 : :
1788 : : Specifically, a simple accessor within struct S of the form:
1789 : : T& get_field () { return m_field; }
1790 : : should have a constexpr_fn_retval (saved_tree) of the form:
1791 : : <init_expr:T&
1792 : : <result_decl:T&
1793 : : <nop_expr: T&
1794 : : <addr_expr: T*
1795 : : <component_ref:T
1796 : : <indirect_ref:S
1797 : : <nop_expr
1798 : : <parm_decl (this)>>
1799 : : <field (FIELD_DECL)>>>>>>. */
1800 : : static bool
1801 : 42 : reference_accessor_p (tree init_expr, tree field_decl, tree field_type,
1802 : : tree field_reference_type)
1803 : : {
1804 : 42 : tree result_decl = TREE_OPERAND (init_expr, 0);
1805 : 42 : if (!matches_code_and_type_p (result_decl, RESULT_DECL, field_reference_type))
1806 : : return false;
1807 : :
1808 : 42 : tree field_pointer_type = build_pointer_type (field_type);
1809 : 42 : tree addr_expr = STRIP_NOPS (TREE_OPERAND (init_expr, 1));
1810 : 42 : if (!matches_code_and_type_p (addr_expr, ADDR_EXPR, field_pointer_type))
1811 : : return false;
1812 : :
1813 : 42 : tree component_ref = STRIP_NOPS (TREE_OPERAND (addr_expr, 0));
1814 : :
1815 : 42 : if (!field_access_p (component_ref, field_decl, field_type))
1816 : : return false;
1817 : :
1818 : : return true;
1819 : : }
1820 : :
1821 : : /* Return the class of the `this' or explicit object parameter of FN. */
1822 : :
1823 : : static tree
1824 : 61 : class_of_object_parm (const_tree fn)
1825 : : {
1826 : 61 : tree fntype = TREE_TYPE (fn);
1827 : 61 : if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
1828 : 0 : return non_reference (TREE_VALUE (TYPE_ARG_TYPES (fntype)));
1829 : 61 : return class_of_this_parm (fntype);
1830 : : }
1831 : :
1832 : : /* Return true if FN is an accessor method for FIELD_DECL.
1833 : : i.e. a method of the form { return FIELD; }, with no
1834 : : conversions.
1835 : :
1836 : : If CONST_P, then additionally require that FN be a const
1837 : : method. */
1838 : :
1839 : : static bool
1840 : 2363 : field_accessor_p (tree fn, tree field_decl, bool const_p)
1841 : : {
1842 : 2363 : if (TREE_CODE (fn) != FUNCTION_DECL)
1843 : : return false;
1844 : :
1845 : : /* We don't yet support looking up static data, just fields. */
1846 : 624 : if (TREE_CODE (field_decl) != FIELD_DECL)
1847 : : return false;
1848 : :
1849 : 615 : if (!DECL_OBJECT_MEMBER_FUNCTION_P (fn))
1850 : : return false;
1851 : :
1852 : : /* If the field is accessed via a const "this" argument, verify
1853 : : that the "this" parameter is const. */
1854 : 615 : if (const_p)
1855 : : {
1856 : 61 : tree this_class = class_of_object_parm (fn);
1857 : 61 : if (!TYPE_READONLY (this_class))
1858 : : return false;
1859 : : }
1860 : :
1861 : 577 : tree saved_tree = DECL_SAVED_TREE (fn);
1862 : :
1863 : 577 : if (saved_tree == NULL_TREE)
1864 : : return false;
1865 : :
1866 : : /* Attempt to extract a single return value from the function,
1867 : : if it has one. */
1868 : 229 : tree retval = constexpr_fn_retval (saved_tree);
1869 : 229 : if (retval == NULL_TREE || retval == error_mark_node)
1870 : : return false;
1871 : : /* Require an INIT_EXPR. */
1872 : 203 : if (TREE_CODE (retval) != INIT_EXPR)
1873 : : return false;
1874 : 203 : tree init_expr = retval;
1875 : :
1876 : : /* Determine if this is a simple accessor within struct S of the form:
1877 : : T get_field () { return m_field; }. */
1878 : 203 : tree field_type = TREE_TYPE (field_decl);
1879 : 203 : if (cxx_types_compatible_p (TREE_TYPE (init_expr), field_type))
1880 : 161 : return direct_accessor_p (init_expr, field_decl, field_type);
1881 : :
1882 : : /* Failing that, determine if it is an accessor of the form:
1883 : : T& get_field () { return m_field; }. */
1884 : 42 : tree field_reference_type = cp_build_reference_type (field_type, false);
1885 : 42 : if (cxx_types_compatible_p (TREE_TYPE (init_expr), field_reference_type))
1886 : 42 : return reference_accessor_p (init_expr, field_decl, field_type,
1887 : 42 : field_reference_type);
1888 : :
1889 : : return false;
1890 : : }
1891 : :
1892 : : /* Callback data for dfs_locate_field_accessor_pre. */
1893 : :
1894 : : class locate_field_data
1895 : : {
1896 : : public:
1897 : 406 : locate_field_data (tree field_decl_, bool const_p_)
1898 : 406 : : field_decl (field_decl_), const_p (const_p_) {}
1899 : :
1900 : : tree field_decl;
1901 : : bool const_p;
1902 : : };
1903 : :
1904 : : /* Return a FUNCTION_DECL that is an "accessor" method for DATA, a FIELD_DECL,
1905 : : callable via binfo, if one exists, otherwise return NULL_TREE.
1906 : :
1907 : : Callback for dfs_walk_once_accessible for use within
1908 : : locate_field_accessor. */
1909 : :
1910 : : static tree
1911 : 448 : dfs_locate_field_accessor_pre (tree binfo, void *data)
1912 : : {
1913 : 448 : locate_field_data *lfd = (locate_field_data *)data;
1914 : 448 : tree type = BINFO_TYPE (binfo);
1915 : :
1916 : 448 : vec<tree, va_gc> *member_vec;
1917 : 448 : tree fn;
1918 : 448 : size_t i;
1919 : :
1920 : 448 : if (!CLASS_TYPE_P (type))
1921 : : return NULL_TREE;
1922 : :
1923 : 448 : member_vec = CLASSTYPE_MEMBER_VEC (type);
1924 : 448 : if (!member_vec)
1925 : : return NULL_TREE;
1926 : :
1927 : 2534 : for (i = 0; vec_safe_iterate (member_vec, i, &fn); ++i)
1928 : 2363 : if (fn)
1929 : 2363 : if (field_accessor_p (fn, lfd->field_decl, lfd->const_p))
1930 : 161 : return fn;
1931 : :
1932 : : return NULL_TREE;
1933 : : }
1934 : :
1935 : : /* Return a FUNCTION_DECL that is an "accessor" method for FIELD_DECL,
1936 : : callable via BASETYPE_PATH, if one exists, otherwise return NULL_TREE. */
1937 : :
1938 : : tree
1939 : 406 : locate_field_accessor (tree basetype_path, tree field_decl, bool const_p)
1940 : : {
1941 : 406 : if (TREE_CODE (basetype_path) != TREE_BINFO)
1942 : : return NULL_TREE;
1943 : :
1944 : : /* Walk the hierarchy, looking for a method of some base class that allows
1945 : : access to the field. */
1946 : 406 : locate_field_data lfd (field_decl, const_p);
1947 : 406 : return dfs_walk_once_accessible (basetype_path, /*friends=*/true,
1948 : : dfs_locate_field_accessor_pre,
1949 : 406 : NULL, &lfd);
1950 : : }
1951 : :
1952 : : /* Check throw specifier of OVERRIDER is at least as strict as
1953 : : the one of BASEFN. This is due to [except.spec]: "If a virtual function
1954 : : has a non-throwing exception specification, all declarations, including
1955 : : the definition, of any function that overrides that virtual function in
1956 : : any derived class shall have a non-throwing exception specification,
1957 : : unless the overriding function is defined as deleted." */
1958 : :
1959 : : bool
1960 : 3330183 : maybe_check_overriding_exception_spec (tree overrider, tree basefn)
1961 : : {
1962 : 3330183 : maybe_instantiate_noexcept (basefn);
1963 : 3330183 : maybe_instantiate_noexcept (overrider);
1964 : 3330183 : tree base_throw = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (basefn));
1965 : 3330183 : tree over_throw = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (overrider));
1966 : :
1967 : 3330183 : if (DECL_INVALID_OVERRIDER_P (overrider)
1968 : : /* CWG 1351 added the "unless the overriding function is defined as
1969 : : deleted" wording. */
1970 : 3330183 : || DECL_DELETED_FN (overrider))
1971 : : return true;
1972 : :
1973 : : /* Can't check this yet. Pretend this is fine and let
1974 : : noexcept_override_late_checks check this later. */
1975 : 2179069 : if (UNPARSED_NOEXCEPT_SPEC_P (base_throw)
1976 : 7688409 : || UNPARSED_NOEXCEPT_SPEC_P (over_throw))
1977 : : return true;
1978 : :
1979 : : /* We also have to defer checking when we're in a template and couldn't
1980 : : instantiate & evaluate the noexcept to true/false. */
1981 : 3330168 : if (processing_template_decl)
1982 : 6 : if ((base_throw
1983 : 3 : && base_throw != noexcept_true_spec
1984 : 0 : && base_throw != noexcept_false_spec)
1985 : 6 : || (over_throw
1986 : 6 : && over_throw != noexcept_true_spec
1987 : 6 : && over_throw != noexcept_false_spec))
1988 : : return true;
1989 : :
1990 : 3330162 : if (!comp_except_specs (base_throw, over_throw, ce_derived))
1991 : : {
1992 : 42 : auto_diagnostic_group d;
1993 : 42 : error ("looser exception specification on overriding virtual function "
1994 : : "%q+#F", overrider);
1995 : 42 : inform (DECL_SOURCE_LOCATION (basefn),
1996 : : "overridden function is %q#F", basefn);
1997 : 42 : DECL_INVALID_OVERRIDER_P (overrider) = 1;
1998 : 42 : return false;
1999 : 42 : }
2000 : : return true;
2001 : : }
2002 : :
2003 : : /* Check that virtual overrider OVERRIDER is acceptable for base function
2004 : : BASEFN. Issue diagnostic, and return zero, if unacceptable. */
2005 : :
2006 : : static int
2007 : 3330228 : check_final_overrider (tree overrider, tree basefn)
2008 : : {
2009 : 3330228 : tree over_type = TREE_TYPE (overrider);
2010 : 3330228 : tree base_type = TREE_TYPE (basefn);
2011 : 3330228 : tree over_return = fndecl_declared_return_type (overrider);
2012 : 3330228 : tree base_return = fndecl_declared_return_type (basefn);
2013 : :
2014 : 3330228 : int fail = 0;
2015 : :
2016 : 3330228 : if (DECL_INVALID_OVERRIDER_P (overrider))
2017 : : return 0;
2018 : :
2019 : 3330222 : if (same_type_p (base_return, over_return))
2020 : : /* OK */;
2021 : 0 : else if ((CLASS_TYPE_P (over_return) && CLASS_TYPE_P (base_return))
2022 : 295 : || (TREE_CODE (base_return) == TREE_CODE (over_return)
2023 : 280 : && INDIRECT_TYPE_P (base_return)))
2024 : : {
2025 : : /* Potentially covariant. */
2026 : 280 : unsigned base_quals, over_quals;
2027 : :
2028 : 280 : fail = !INDIRECT_TYPE_P (base_return);
2029 : 280 : if (!fail)
2030 : : {
2031 : 280 : if (cp_type_quals (base_return) != cp_type_quals (over_return))
2032 : 0 : fail = 1;
2033 : :
2034 : 280 : if (TYPE_REF_P (base_return)
2035 : 280 : && (TYPE_REF_IS_RVALUE (base_return)
2036 : 60 : != TYPE_REF_IS_RVALUE (over_return)))
2037 : : fail = 1;
2038 : :
2039 : 280 : base_return = TREE_TYPE (base_return);
2040 : 280 : over_return = TREE_TYPE (over_return);
2041 : : }
2042 : 280 : base_quals = cp_type_quals (base_return);
2043 : 280 : over_quals = cp_type_quals (over_return);
2044 : :
2045 : 280 : if ((base_quals & over_quals) != over_quals)
2046 : 3 : fail = 1;
2047 : :
2048 : 280 : if (CLASS_TYPE_P (base_return) && CLASS_TYPE_P (over_return))
2049 : : {
2050 : : /* Strictly speaking, the standard requires the return type to be
2051 : : complete even if it only differs in cv-quals, but that seems
2052 : : like a bug in the wording. */
2053 : 271 : if (!same_type_ignoring_top_level_qualifiers_p (base_return,
2054 : : over_return))
2055 : : {
2056 : 261 : tree binfo = lookup_base (over_return, base_return,
2057 : : ba_check, NULL, tf_none);
2058 : :
2059 : 261 : if (!binfo || binfo == error_mark_node)
2060 : : fail = 1;
2061 : : }
2062 : : }
2063 : 9 : else if (can_convert_standard (TREE_TYPE (base_type),
2064 : 9 : TREE_TYPE (over_type),
2065 : : tf_warning_or_error))
2066 : : /* GNU extension, allow trivial pointer conversions such as
2067 : : converting to void *, or qualification conversion. */
2068 : : {
2069 : 0 : auto_diagnostic_group d;
2070 : 0 : if (pedwarn (DECL_SOURCE_LOCATION (overrider), 0,
2071 : : "invalid covariant return type for %q#D", overrider))
2072 : 0 : inform (DECL_SOURCE_LOCATION (basefn),
2073 : : "overridden function is %q#D", basefn);
2074 : 0 : }
2075 : : else
2076 : : fail = 2;
2077 : : }
2078 : : else
2079 : : fail = 2;
2080 : 256 : if (!fail)
2081 : : /* OK */;
2082 : : else
2083 : : {
2084 : 45 : auto_diagnostic_group d;
2085 : 45 : if (fail == 1)
2086 : 21 : error ("invalid covariant return type for %q+#D", overrider);
2087 : : else
2088 : 24 : error ("conflicting return type specified for %q+#D", overrider);
2089 : 45 : inform (DECL_SOURCE_LOCATION (basefn),
2090 : : "overridden function is %q#D", basefn);
2091 : 45 : DECL_INVALID_OVERRIDER_P (overrider) = 1;
2092 : 45 : return 0;
2093 : 45 : }
2094 : :
2095 : 3330177 : if (!maybe_check_overriding_exception_spec (overrider, basefn))
2096 : : return 0;
2097 : :
2098 : : /* Check for conflicting type attributes. But leave transaction_safe for
2099 : : set_one_vmethod_tm_attributes. */
2100 : 3330135 : if (!comp_type_attributes (over_type, base_type)
2101 : 63 : && !tx_safe_fn_type_p (base_type)
2102 : 3330142 : && !tx_safe_fn_type_p (over_type))
2103 : : {
2104 : 0 : auto_diagnostic_group d;
2105 : 0 : error ("conflicting type attributes specified for %q+#D", overrider);
2106 : 0 : inform (DECL_SOURCE_LOCATION (basefn),
2107 : : "overridden function is %q#D", basefn);
2108 : 0 : DECL_INVALID_OVERRIDER_P (overrider) = 1;
2109 : 0 : return 0;
2110 : 0 : }
2111 : :
2112 : : /* A consteval virtual function shall not override a virtual function that is
2113 : : not consteval. A consteval virtual function shall not be overridden by a
2114 : : virtual function that is not consteval. */
2115 : 9990405 : if (DECL_IMMEDIATE_FUNCTION_P (overrider)
2116 : 6660270 : != DECL_IMMEDIATE_FUNCTION_P (basefn))
2117 : : {
2118 : 6 : auto_diagnostic_group d;
2119 : 12 : if (DECL_IMMEDIATE_FUNCTION_P (overrider))
2120 : 3 : error ("%<consteval%> function %q+D overriding non-%<consteval%> "
2121 : : "function", overrider);
2122 : : else
2123 : 3 : error ("non-%<consteval%> function %q+D overriding %<consteval%> "
2124 : : "function", overrider);
2125 : 6 : inform (DECL_SOURCE_LOCATION (basefn),
2126 : : "overridden function is %qD", basefn);
2127 : 6 : DECL_INVALID_OVERRIDER_P (overrider) = 1;
2128 : 6 : return 0;
2129 : 6 : }
2130 : :
2131 : : /* A function declared transaction_safe_dynamic that overrides a function
2132 : : declared transaction_safe (but not transaction_safe_dynamic) is
2133 : : ill-formed. */
2134 : 3330129 : if (tx_safe_fn_type_p (base_type)
2135 : 72 : && lookup_attribute ("transaction_safe_dynamic",
2136 : 72 : DECL_ATTRIBUTES (overrider))
2137 : 3330142 : && !lookup_attribute ("transaction_safe_dynamic",
2138 : 13 : DECL_ATTRIBUTES (basefn)))
2139 : : {
2140 : 1 : auto_diagnostic_group d;
2141 : 1 : error_at (DECL_SOURCE_LOCATION (overrider),
2142 : : "%qD declared %<transaction_safe_dynamic%>", overrider);
2143 : 1 : inform (DECL_SOURCE_LOCATION (basefn),
2144 : : "overriding %qD declared %<transaction_safe%>", basefn);
2145 : 1 : }
2146 : :
2147 : 3330129 : if (DECL_DELETED_FN (basefn) != DECL_DELETED_FN (overrider))
2148 : : {
2149 : 15 : if (DECL_DELETED_FN (overrider))
2150 : : {
2151 : 12 : auto_diagnostic_group d;
2152 : 12 : error ("deleted function %q+D overriding non-deleted function",
2153 : : overrider);
2154 : 12 : inform (DECL_SOURCE_LOCATION (basefn),
2155 : : "overridden function is %qD", basefn);
2156 : 12 : maybe_explain_implicit_delete (overrider);
2157 : 12 : }
2158 : : else
2159 : : {
2160 : 3 : auto_diagnostic_group d;
2161 : 3 : error ("non-deleted function %q+D overriding deleted function",
2162 : : overrider);
2163 : 3 : inform (DECL_SOURCE_LOCATION (basefn),
2164 : : "overridden function is %qD", basefn);
2165 : 3 : }
2166 : 15 : return 0;
2167 : : }
2168 : :
2169 : 3330114 : if (!DECL_HAS_CONTRACTS_P (basefn) && DECL_HAS_CONTRACTS_P (overrider))
2170 : : {
2171 : 0 : auto_diagnostic_group d;
2172 : 0 : error ("function with contracts %q+D overriding contractless function",
2173 : : overrider);
2174 : 0 : inform (DECL_SOURCE_LOCATION (basefn),
2175 : : "overridden function is %qD", basefn);
2176 : 0 : return 0;
2177 : 0 : }
2178 : 3330114 : else if (DECL_HAS_CONTRACTS_P (basefn) && !DECL_HAS_CONTRACTS_P (overrider))
2179 : : {
2180 : : /* We're inheriting basefn's contracts; create a copy of them but
2181 : : replace references to their parms to our parms. */
2182 : 12 : inherit_base_contracts (overrider, basefn);
2183 : : }
2184 : 3330102 : else if (DECL_HAS_CONTRACTS_P (basefn) && DECL_HAS_CONTRACTS_P (overrider))
2185 : : {
2186 : : /* We're in the process of completing the overrider's class, which means
2187 : : our conditions definitely are not parsed so simply chain on the
2188 : : basefn for later checking.
2189 : :
2190 : : Note that OVERRIDER's contracts will have been fully parsed at the
2191 : : point the deferred match is run. */
2192 : 20 : defer_guarded_contract_match (overrider, basefn, DECL_CONTRACTS (basefn));
2193 : : }
2194 : :
2195 : 3330114 : if (DECL_FINAL_P (basefn))
2196 : : {
2197 : 6 : auto_diagnostic_group d;
2198 : 6 : error ("virtual function %q+D overriding final function", overrider);
2199 : 6 : inform (DECL_SOURCE_LOCATION (basefn),
2200 : : "overridden function is %qD", basefn);
2201 : 6 : return 0;
2202 : 6 : }
2203 : : return 1;
2204 : : }
2205 : :
2206 : : /* Given a class TYPE, and a function decl FNDECL, look for
2207 : : virtual functions in TYPE's hierarchy which FNDECL overrides.
2208 : : We do not look in TYPE itself, only its bases.
2209 : :
2210 : : Returns nonzero, if we find any. Set FNDECL's DECL_VIRTUAL_P, if we
2211 : : find that it overrides anything.
2212 : :
2213 : : We check that every function which is overridden, is correctly
2214 : : overridden. */
2215 : :
2216 : : int
2217 : 14267057 : look_for_overrides (tree type, tree fndecl)
2218 : : {
2219 : 14267057 : tree binfo = TYPE_BINFO (type);
2220 : 14267057 : tree base_binfo;
2221 : 14267057 : int ix;
2222 : 14267057 : int found = 0;
2223 : :
2224 : : /* A constructor for a class T does not override a function T
2225 : : in a base class. */
2226 : 28534114 : if (DECL_CONSTRUCTOR_P (fndecl))
2227 : : return 0;
2228 : :
2229 : 22379169 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
2230 : : {
2231 : 8112112 : tree basetype = BINFO_TYPE (base_binfo);
2232 : :
2233 : 8112112 : if (TYPE_POLYMORPHIC_P (basetype))
2234 : 4916922 : found += look_for_overrides_r (basetype, fndecl);
2235 : : }
2236 : : return found;
2237 : : }
2238 : :
2239 : : /* Look in TYPE for virtual functions with the same signature as
2240 : : FNDECL. */
2241 : :
2242 : : tree
2243 : 23575770 : look_for_overrides_here (tree type, tree fndecl)
2244 : : {
2245 : 23575770 : tree ovl = get_class_binding (type, DECL_NAME (fndecl));
2246 : :
2247 : 24387595 : for (ovl_iterator iter (ovl); iter; ++iter)
2248 : : {
2249 : 18428918 : tree fn = *iter;
2250 : :
2251 : 18428918 : if (!DECL_VIRTUAL_P (fn))
2252 : : /* Not a virtual. */;
2253 : 18379063 : else if (DECL_CONTEXT (fn) != type)
2254 : : /* Introduced with a using declaration. */;
2255 : 18378913 : else if (DECL_STATIC_FUNCTION_P (fndecl)
2256 : 18378913 : || DECL_XOBJ_MEMBER_FUNCTION_P (fndecl))
2257 : : {
2258 : 28 : tree btypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
2259 : 28 : tree dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
2260 : 28 : dtypes = DECL_XOBJ_MEMBER_FUNCTION_P (fndecl) ? TREE_CHAIN (dtypes)
2261 : : : dtypes;
2262 : 28 : if (compparms (TREE_CHAIN (btypes), dtypes))
2263 : 17997154 : return fn;
2264 : : }
2265 : 18378885 : else if (same_signature_p (fndecl, fn))
2266 : 17997132 : return fn;
2267 : : }
2268 : :
2269 : 5578616 : return NULL_TREE;
2270 : : }
2271 : :
2272 : : /* Look in TYPE for virtual functions overridden by FNDECL. Check both
2273 : : TYPE itself and its bases. */
2274 : :
2275 : : static int
2276 : 4916922 : look_for_overrides_r (tree type, tree fndecl)
2277 : : {
2278 : 4916922 : tree fn = look_for_overrides_here (type, fndecl);
2279 : 4916922 : if (fn)
2280 : : {
2281 : 3330250 : if (DECL_STATIC_FUNCTION_P (fndecl))
2282 : : {
2283 : : /* A static member function cannot match an inherited
2284 : : virtual member function. */
2285 : 6 : auto_diagnostic_group d;
2286 : 6 : error ("%q+#D cannot be declared", fndecl);
2287 : 6 : error (" since %q+#D declared in base class", fn);
2288 : 6 : }
2289 : 3330244 : else if (DECL_XOBJ_MEMBER_FUNCTION_P (fndecl))
2290 : : {
2291 : 16 : auto_diagnostic_group d;
2292 : 16 : error_at (DECL_SOURCE_LOCATION (fndecl),
2293 : : "explicit object member function "
2294 : : "overrides virtual function");
2295 : 16 : inform (DECL_SOURCE_LOCATION (fn),
2296 : : "virtual function declared here");
2297 : 16 : }
2298 : : else
2299 : : {
2300 : : /* It's definitely virtual, even if not explicitly set. */
2301 : 3330228 : DECL_VIRTUAL_P (fndecl) = 1;
2302 : 3330228 : check_final_overrider (fndecl, fn);
2303 : : }
2304 : 3330250 : return 1;
2305 : : }
2306 : :
2307 : : /* We failed to find one declared in this class. Look in its bases. */
2308 : 1586672 : return look_for_overrides (type, fndecl);
2309 : : }
2310 : :
2311 : : /* Called via dfs_walk from dfs_get_pure_virtuals. */
2312 : :
2313 : : static tree
2314 : 4701428 : dfs_get_pure_virtuals (tree binfo, void *data)
2315 : : {
2316 : 4701428 : tree type = (tree) data;
2317 : :
2318 : : /* We're not interested in primary base classes; the derived class
2319 : : of which they are a primary base will contain the information we
2320 : : need. */
2321 : 4701428 : if (!BINFO_PRIMARY_P (binfo))
2322 : : {
2323 : 2288363 : tree virtuals;
2324 : :
2325 : 2288363 : for (virtuals = BINFO_VIRTUALS (binfo);
2326 : 11354748 : virtuals;
2327 : 9066385 : virtuals = TREE_CHAIN (virtuals))
2328 : 9066385 : if (DECL_PURE_VIRTUAL_P (BV_FN (virtuals)))
2329 : 524440 : vec_safe_push (CLASSTYPE_PURE_VIRTUALS (type), BV_FN (virtuals));
2330 : : }
2331 : :
2332 : 4701428 : return NULL_TREE;
2333 : : }
2334 : :
2335 : : /* Set CLASSTYPE_PURE_VIRTUALS for TYPE. */
2336 : :
2337 : : void
2338 : 1462319 : get_pure_virtuals (tree type)
2339 : : {
2340 : : /* Clear the CLASSTYPE_PURE_VIRTUALS list; whatever is already there
2341 : : is going to be overridden. */
2342 : 1462319 : CLASSTYPE_PURE_VIRTUALS (type) = NULL;
2343 : : /* Now, run through all the bases which are not primary bases, and
2344 : : collect the pure virtual functions. We look at the vtable in
2345 : : each class to determine what pure virtual functions are present.
2346 : : (A primary base is not interesting because the derived class of
2347 : : which it is a primary base will contain vtable entries for the
2348 : : pure virtuals in the base class. */
2349 : 1462319 : dfs_walk_once (TYPE_BINFO (type), NULL, dfs_get_pure_virtuals, type);
2350 : 1462319 : }
2351 : :
2352 : : /* Debug info for C++ classes can get very large; try to avoid
2353 : : emitting it everywhere.
2354 : :
2355 : : Note that this optimization wins even when the target supports
2356 : : BINCL (if only slightly), and reduces the amount of work for the
2357 : : linker. */
2358 : :
2359 : : void
2360 : 36027736 : maybe_suppress_debug_info (tree t)
2361 : : {
2362 : 36027736 : if (write_symbols == NO_DEBUG)
2363 : : return;
2364 : :
2365 : : /* We might have set this earlier in cp_finish_decl. */
2366 : 34479851 : TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 0;
2367 : :
2368 : : /* Always emit the information for each class every time. */
2369 : 34479851 : if (flag_emit_class_debug_always)
2370 : : return;
2371 : :
2372 : : /* If we already know how we're handling this class, handle debug info
2373 : : the same way. */
2374 : 34479851 : if (CLASSTYPE_INTERFACE_KNOWN (t))
2375 : : {
2376 : 1 : if (CLASSTYPE_INTERFACE_ONLY (t))
2377 : 1 : TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
2378 : : /* else don't set it. */
2379 : : }
2380 : : /* If the class has a vtable, write out the debug info along with
2381 : : the vtable. */
2382 : 34479850 : else if (TYPE_CONTAINS_VPTR_P (t))
2383 : 1569309 : TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
2384 : :
2385 : : /* Otherwise, just emit the debug info normally. */
2386 : : }
2387 : :
2388 : : /* Note that we want debugging information for a base class of a class
2389 : : whose vtable is being emitted. Normally, this would happen because
2390 : : calling the constructor for a derived class implies calling the
2391 : : constructors for all bases, which involve initializing the
2392 : : appropriate vptr with the vtable for the base class; but in the
2393 : : presence of optimization, this initialization may be optimized
2394 : : away, so we tell finish_vtable_vardecl that we want the debugging
2395 : : information anyway. */
2396 : :
2397 : : static tree
2398 : 669283 : dfs_debug_mark (tree binfo, void * /*data*/)
2399 : : {
2400 : 669283 : tree t = BINFO_TYPE (binfo);
2401 : :
2402 : 669283 : if (CLASSTYPE_DEBUG_REQUESTED (t))
2403 : : return dfs_skip_bases;
2404 : :
2405 : 417527 : CLASSTYPE_DEBUG_REQUESTED (t) = 1;
2406 : :
2407 : 417527 : return NULL_TREE;
2408 : : }
2409 : :
2410 : : /* Write out the debugging information for TYPE, whose vtable is being
2411 : : emitted. Also walk through our bases and note that we want to
2412 : : write out information for them. This avoids the problem of not
2413 : : writing any debug info for intermediate basetypes whose
2414 : : constructors, and thus the references to their vtables, and thus
2415 : : the vtables themselves, were optimized away. */
2416 : :
2417 : : void
2418 : 308112 : note_debug_info_needed (tree type)
2419 : : {
2420 : 308112 : if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
2421 : : {
2422 : 265214 : TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)) = 0;
2423 : 265214 : rest_of_type_compilation (type, namespace_bindings_p ());
2424 : : }
2425 : :
2426 : 308112 : dfs_walk_all (TYPE_BINFO (type), dfs_debug_mark, NULL, 0);
2427 : 308112 : }
2428 : :
2429 : : /* Helper for lookup_conversions_r. TO_TYPE is the type converted to
2430 : : by a conversion op in base BINFO. VIRTUAL_DEPTH is nonzero if
2431 : : BINFO is morally virtual, and VIRTUALNESS is nonzero if virtual
2432 : : bases have been encountered already in the tree walk. PARENT_CONVS
2433 : : is the list of lists of conversion functions that could hide CONV
2434 : : and OTHER_CONVS is the list of lists of conversion functions that
2435 : : could hide or be hidden by CONV, should virtualness be involved in
2436 : : the hierarchy. Merely checking the conversion op's name is not
2437 : : enough because two conversion operators to the same type can have
2438 : : different names. Return nonzero if we are visible. */
2439 : :
2440 : : static int
2441 : 15724476 : check_hidden_convs (tree binfo, int virtual_depth, int virtualness,
2442 : : tree to_type, tree parent_convs, tree other_convs)
2443 : : {
2444 : 15724476 : tree level, probe;
2445 : :
2446 : : /* See if we are hidden by a parent conversion. */
2447 : 15726203 : for (level = parent_convs; level; level = TREE_CHAIN (level))
2448 : 7734 : for (probe = TREE_VALUE (level); probe; probe = TREE_CHAIN (probe))
2449 : 6007 : if (same_type_p (to_type, TREE_TYPE (probe)))
2450 : : return 0;
2451 : :
2452 : 15720262 : if (virtual_depth || virtualness)
2453 : : {
2454 : : /* In a virtual hierarchy, we could be hidden, or could hide a
2455 : : conversion function on the other_convs list. */
2456 : 88826 : for (level = other_convs; level; level = TREE_CHAIN (level))
2457 : : {
2458 : 1348 : int we_hide_them;
2459 : 1348 : int they_hide_us;
2460 : 1348 : tree *prev, other;
2461 : :
2462 : 1348 : if (!(virtual_depth || TREE_STATIC (level)))
2463 : : /* Neither is morally virtual, so cannot hide each other. */
2464 : 0 : continue;
2465 : :
2466 : 1348 : if (!TREE_VALUE (level))
2467 : : /* They evaporated away already. */
2468 : 0 : continue;
2469 : :
2470 : 2702 : they_hide_us = (virtual_depth
2471 : 1348 : && original_binfo (binfo, TREE_PURPOSE (level)));
2472 : 6 : we_hide_them = (!they_hide_us && TREE_STATIC (level)
2473 : 6 : && original_binfo (TREE_PURPOSE (level), binfo));
2474 : :
2475 : 1348 : if (!(we_hide_them || they_hide_us))
2476 : : /* Neither is within the other, so no hiding can occur. */
2477 : 0 : continue;
2478 : :
2479 : 1354 : for (prev = &TREE_VALUE (level), other = *prev; other;)
2480 : : {
2481 : 1348 : if (same_type_p (to_type, TREE_TYPE (other)))
2482 : : {
2483 : 1348 : if (they_hide_us)
2484 : : /* We are hidden. */
2485 : : return 0;
2486 : :
2487 : 6 : if (we_hide_them)
2488 : : {
2489 : : /* We hide the other one. */
2490 : 6 : other = TREE_CHAIN (other);
2491 : 6 : *prev = other;
2492 : 6 : continue;
2493 : : }
2494 : : }
2495 : 0 : prev = &TREE_CHAIN (other);
2496 : 0 : other = *prev;
2497 : : }
2498 : : }
2499 : : }
2500 : : return 1;
2501 : : }
2502 : :
2503 : : /* Helper for lookup_conversions_r. PARENT_CONVS is a list of lists
2504 : : of conversion functions, the first slot will be for the current
2505 : : binfo, if MY_CONVS is non-NULL. CHILD_CONVS is the list of lists
2506 : : of conversion functions from children of the current binfo,
2507 : : concatenated with conversions from elsewhere in the hierarchy --
2508 : : that list begins with OTHER_CONVS. Return a single list of lists
2509 : : containing only conversions from the current binfo and its
2510 : : children. */
2511 : :
2512 : : static tree
2513 : 14862396 : split_conversions (tree my_convs, tree parent_convs,
2514 : : tree child_convs, tree other_convs)
2515 : : {
2516 : 14862396 : tree t;
2517 : 14862396 : tree prev;
2518 : :
2519 : : /* Remove the original other_convs portion from child_convs. */
2520 : 14862396 : for (prev = NULL, t = child_convs;
2521 : 15698858 : t != other_convs; prev = t, t = TREE_CHAIN (t))
2522 : 836462 : continue;
2523 : :
2524 : 14862396 : if (prev)
2525 : 836369 : TREE_CHAIN (prev) = NULL_TREE;
2526 : : else
2527 : : child_convs = NULL_TREE;
2528 : :
2529 : : /* Attach the child convs to any we had at this level. */
2530 : 14862396 : if (my_convs)
2531 : : {
2532 : 14022139 : my_convs = parent_convs;
2533 : 14022139 : TREE_CHAIN (my_convs) = child_convs;
2534 : : }
2535 : : else
2536 : : my_convs = child_convs;
2537 : :
2538 : 14862396 : return my_convs;
2539 : 836462 : }
2540 : :
2541 : : /* Worker for lookup_conversions. Lookup conversion functions in
2542 : : BINFO and its children. VIRTUAL_DEPTH is nonzero, if BINFO is in a
2543 : : morally virtual base, and VIRTUALNESS is nonzero, if we've
2544 : : encountered virtual bases already in the tree walk. PARENT_CONVS
2545 : : is a list of conversions within parent binfos. OTHER_CONVS are
2546 : : conversions found elsewhere in the tree. Return the conversions
2547 : : found within this portion of the graph in CONVS. Return nonzero if
2548 : : we encountered virtualness. We keep template and non-template
2549 : : conversions separate, to avoid unnecessary type comparisons.
2550 : :
2551 : : The located conversion functions are held in lists of lists. The
2552 : : TREE_VALUE of the outer list is the list of conversion functions
2553 : : found in a particular binfo. The TREE_PURPOSE of both the outer
2554 : : and inner lists is the binfo at which those conversions were
2555 : : found. TREE_STATIC is set for those lists within of morally
2556 : : virtual binfos. The TREE_VALUE of the inner list is the conversion
2557 : : function or overload itself. The TREE_TYPE of each inner list node
2558 : : is the converted-to type. */
2559 : :
2560 : : static int
2561 : 39302498 : lookup_conversions_r (tree binfo, int virtual_depth, int virtualness,
2562 : : tree parent_convs, tree other_convs, tree *convs)
2563 : : {
2564 : 39302498 : int my_virtualness = 0;
2565 : 39302498 : tree my_convs = NULL_TREE;
2566 : 39302498 : tree child_convs = NULL_TREE;
2567 : :
2568 : : /* If we have no conversion operators, then don't look. */
2569 : 39302498 : if (!TYPE_HAS_CONVERSION (BINFO_TYPE (binfo)))
2570 : : {
2571 : 24440102 : *convs = NULL_TREE;
2572 : :
2573 : 24440102 : return 0;
2574 : : }
2575 : :
2576 : 14862396 : if (BINFO_VIRTUAL_P (binfo))
2577 : 88826 : virtual_depth++;
2578 : :
2579 : : /* First, locate the unhidden ones at this level. */
2580 : 14862396 : if (tree conv = get_class_binding (BINFO_TYPE (binfo), conv_op_identifier))
2581 : 32201920 : for (ovl_iterator iter (conv); iter; ++iter)
2582 : : {
2583 : 15724476 : tree fn = *iter;
2584 : 15724476 : tree type = DECL_CONV_FN_TYPE (fn);
2585 : :
2586 : 15724476 : if (TREE_CODE (fn) != TEMPLATE_DECL && type_uses_auto (type))
2587 : : {
2588 : 3 : mark_used (fn);
2589 : 3 : type = DECL_CONV_FN_TYPE (fn);
2590 : : }
2591 : :
2592 : 15724476 : if (check_hidden_convs (binfo, virtual_depth, virtualness,
2593 : : type, parent_convs, other_convs))
2594 : : {
2595 : 15718920 : my_convs = tree_cons (binfo, fn, my_convs);
2596 : 15718920 : TREE_TYPE (my_convs) = type;
2597 : 15718920 : if (virtual_depth)
2598 : : {
2599 : 87472 : TREE_STATIC (my_convs) = 1;
2600 : 87472 : my_virtualness = 1;
2601 : : }
2602 : : }
2603 : : }
2604 : :
2605 : 14025649 : if (my_convs)
2606 : : {
2607 : 14022139 : parent_convs = tree_cons (binfo, my_convs, parent_convs);
2608 : 14022139 : if (virtual_depth)
2609 : 87472 : TREE_STATIC (parent_convs) = 1;
2610 : : }
2611 : :
2612 : 14862396 : child_convs = other_convs;
2613 : :
2614 : : /* Now iterate over each base, looking for more conversions. */
2615 : 14862396 : unsigned i;
2616 : 14862396 : tree base_binfo;
2617 : 16362263 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
2618 : : {
2619 : 1499867 : tree base_convs;
2620 : 1499867 : unsigned base_virtualness;
2621 : :
2622 : 1499867 : base_virtualness = lookup_conversions_r (base_binfo,
2623 : : virtual_depth, virtualness,
2624 : : parent_convs, child_convs,
2625 : : &base_convs);
2626 : 1499867 : if (base_virtualness)
2627 : 106268 : my_virtualness = virtualness = 1;
2628 : 1499867 : child_convs = chainon (base_convs, child_convs);
2629 : : }
2630 : :
2631 : 14862396 : *convs = split_conversions (my_convs, parent_convs,
2632 : : child_convs, other_convs);
2633 : :
2634 : 14862396 : return my_virtualness;
2635 : : }
2636 : :
2637 : : /* Return a TREE_LIST containing all the non-hidden user-defined
2638 : : conversion functions for TYPE (and its base-classes). The
2639 : : TREE_VALUE of each node is the FUNCTION_DECL of the conversion
2640 : : function. The TREE_PURPOSE is the BINFO from which the conversion
2641 : : functions in this node were selected. This function is effectively
2642 : : performing a set of member lookups as lookup_fnfield does, but
2643 : : using the type being converted to as the unique key, rather than the
2644 : : field name. */
2645 : :
2646 : : tree
2647 : 37802785 : lookup_conversions (tree type)
2648 : : {
2649 : 37802785 : tree convs;
2650 : :
2651 : 37802785 : complete_type (type);
2652 : 37802785 : if (!CLASS_TYPE_P (type) || !TYPE_BINFO (type))
2653 : : return NULL_TREE;
2654 : :
2655 : 37802631 : lookup_conversions_r (TYPE_BINFO (type), 0, 0, NULL_TREE, NULL_TREE, &convs);
2656 : :
2657 : 37802631 : tree list = NULL_TREE;
2658 : :
2659 : : /* Flatten the list-of-lists */
2660 : 51824770 : for (; convs; convs = TREE_CHAIN (convs))
2661 : : {
2662 : 14022139 : tree probe, next;
2663 : :
2664 : 29741053 : for (probe = TREE_VALUE (convs); probe; probe = next)
2665 : : {
2666 : 15718914 : next = TREE_CHAIN (probe);
2667 : :
2668 : 15718914 : TREE_CHAIN (probe) = list;
2669 : 15718914 : list = probe;
2670 : : }
2671 : : }
2672 : :
2673 : : return list;
2674 : : }
2675 : :
2676 : : /* Returns the binfo of the first direct or indirect virtual base derived
2677 : : from BINFO, or NULL if binfo is not via virtual. */
2678 : :
2679 : : tree
2680 : 78 : binfo_from_vbase (tree binfo)
2681 : : {
2682 : 123 : for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
2683 : : {
2684 : 123 : if (BINFO_VIRTUAL_P (binfo))
2685 : 78 : return binfo;
2686 : : }
2687 : : return NULL_TREE;
2688 : : }
2689 : :
2690 : : /* Returns the binfo of the first direct or indirect virtual base derived
2691 : : from BINFO up to the TREE_TYPE, LIMIT, or NULL if binfo is not
2692 : : via virtual. */
2693 : :
2694 : : tree
2695 : 359145421 : binfo_via_virtual (tree binfo, tree limit)
2696 : : {
2697 : 359145421 : if (limit && !CLASSTYPE_VBASECLASSES (limit))
2698 : : /* LIMIT has no virtual bases, so BINFO cannot be via one. */
2699 : : return NULL_TREE;
2700 : :
2701 : 12967679 : for (; binfo && !SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), limit);
2702 : 1890800 : binfo = BINFO_INHERITANCE_CHAIN (binfo))
2703 : : {
2704 : 3825180 : if (BINFO_VIRTUAL_P (binfo))
2705 : 1934380 : return binfo;
2706 : : }
2707 : : return NULL_TREE;
2708 : : }
2709 : :
2710 : : /* BINFO is for a base class in some hierarchy. Return true iff it is a
2711 : : direct base. */
2712 : :
2713 : : bool
2714 : 50014 : binfo_direct_p (tree binfo)
2715 : : {
2716 : 50014 : tree d_binfo = BINFO_INHERITANCE_CHAIN (binfo);
2717 : 50014 : if (BINFO_INHERITANCE_CHAIN (d_binfo))
2718 : : /* A second inheritance chain means indirect. */
2719 : : return false;
2720 : 50008 : if (!BINFO_VIRTUAL_P (binfo))
2721 : : /* Non-virtual, so only one inheritance chain means direct. */
2722 : : return true;
2723 : : /* A virtual base looks like a direct base, so we need to look through the
2724 : : direct bases to see if it's there. */
2725 : : tree b_binfo;
2726 : 27 : for (int i = 0; BINFO_BASE_ITERATE (d_binfo, i, b_binfo); ++i)
2727 : 24 : if (b_binfo == binfo)
2728 : : return true;
2729 : : return false;
2730 : : }
2731 : :
2732 : : /* BINFO is a base binfo in the complete type BINFO_TYPE (HERE).
2733 : : Find the equivalent binfo within whatever graph HERE is located.
2734 : : This is the inverse of original_binfo. */
2735 : :
2736 : : tree
2737 : 26639193 : copied_binfo (tree binfo, tree here)
2738 : : {
2739 : 26639193 : tree result = NULL_TREE;
2740 : :
2741 : 26639193 : if (BINFO_VIRTUAL_P (binfo))
2742 : : {
2743 : : tree t;
2744 : :
2745 : 6594435 : for (t = here; BINFO_INHERITANCE_CHAIN (t);
2746 : 3425554 : t = BINFO_INHERITANCE_CHAIN (t))
2747 : 3425554 : continue;
2748 : :
2749 : 3168881 : result = binfo_for_vbase (BINFO_TYPE (binfo), BINFO_TYPE (t));
2750 : 3425554 : }
2751 : 23470312 : else if (BINFO_INHERITANCE_CHAIN (binfo))
2752 : : {
2753 : 11735156 : tree cbinfo;
2754 : 11735156 : tree base_binfo;
2755 : 11735156 : int ix;
2756 : :
2757 : 11735156 : cbinfo = copied_binfo (BINFO_INHERITANCE_CHAIN (binfo), here);
2758 : 23496143 : for (ix = 0; BINFO_BASE_ITERATE (cbinfo, ix, base_binfo); ix++)
2759 : 11760987 : if (SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo), BINFO_TYPE (binfo)))
2760 : : {
2761 : : result = base_binfo;
2762 : : break;
2763 : : }
2764 : : }
2765 : : else
2766 : : {
2767 : 11735156 : gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (here), BINFO_TYPE (binfo)));
2768 : : result = here;
2769 : : }
2770 : :
2771 : 26639193 : gcc_assert (result);
2772 : 26639193 : return result;
2773 : : }
2774 : :
2775 : : tree
2776 : 6243008 : binfo_for_vbase (tree base, tree t)
2777 : : {
2778 : 6243008 : unsigned ix;
2779 : 6243008 : tree binfo;
2780 : 6243008 : vec<tree, va_gc> *vbases;
2781 : :
2782 : 67508155 : for (vbases = CLASSTYPE_VBASECLASSES (t), ix = 0;
2783 : 67508155 : vec_safe_iterate (vbases, ix, &binfo); ix++)
2784 : 66216556 : if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), base))
2785 : 4951409 : return binfo;
2786 : : return NULL;
2787 : : }
2788 : :
2789 : : /* BINFO is some base binfo of HERE, within some other
2790 : : hierarchy. Return the equivalent binfo, but in the hierarchy
2791 : : dominated by HERE. This is the inverse of copied_binfo. If BINFO
2792 : : is not a base binfo of HERE, returns NULL_TREE. */
2793 : :
2794 : : tree
2795 : 1348 : original_binfo (tree binfo, tree here)
2796 : : {
2797 : 1348 : tree result = NULL;
2798 : :
2799 : 1348 : if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (here)))
2800 : : result = here;
2801 : 12 : else if (BINFO_VIRTUAL_P (binfo))
2802 : 12 : result = (CLASSTYPE_VBASECLASSES (BINFO_TYPE (here))
2803 : 12 : ? binfo_for_vbase (BINFO_TYPE (binfo), BINFO_TYPE (here))
2804 : : : NULL_TREE);
2805 : 0 : else if (BINFO_INHERITANCE_CHAIN (binfo))
2806 : : {
2807 : 0 : tree base_binfos;
2808 : :
2809 : 0 : base_binfos = original_binfo (BINFO_INHERITANCE_CHAIN (binfo), here);
2810 : 0 : if (base_binfos)
2811 : : {
2812 : : int ix;
2813 : : tree base_binfo;
2814 : :
2815 : 0 : for (ix = 0; (base_binfo = BINFO_BASE_BINFO (base_binfos, ix)); ix++)
2816 : 0 : if (SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo),
2817 : : BINFO_TYPE (binfo)))
2818 : : {
2819 : : result = base_binfo;
2820 : : break;
2821 : : }
2822 : : }
2823 : : }
2824 : :
2825 : 1348 : return result;
2826 : : }
2827 : :
2828 : : /* True iff TYPE has any dependent bases (and therefore we can't say
2829 : : definitively that another class is not a base of an instantiation of
2830 : : TYPE). */
2831 : :
2832 : : bool
2833 : 122908038 : any_dependent_bases_p (tree type)
2834 : : {
2835 : 122908038 : if (!type || !CLASS_TYPE_P (type) || !uses_template_parms (type))
2836 : 81916163 : return false;
2837 : :
2838 : : /* If we haven't set TYPE_BINFO yet, we don't know anything about the bases.
2839 : : Return false because in this situation we aren't actually looking up names
2840 : : in the scope of the class, so it doesn't matter whether it has dependent
2841 : : bases. */
2842 : 40991875 : if (!TYPE_BINFO (type))
2843 : : return false;
2844 : :
2845 : : unsigned i;
2846 : : tree base_binfo;
2847 : 43153404 : FOR_EACH_VEC_SAFE_ELT (BINFO_BASE_BINFOS (TYPE_BINFO (type)), i, base_binfo)
2848 : 28069509 : if (BINFO_DEPENDENT_BASE_P (base_binfo))
2849 : : return true;
2850 : :
2851 : : return false;
2852 : : }
|