Line data Source code
1 : // Copyright (C) 2020-2026 Free Software Foundation, Inc.
2 :
3 : // This file is part of GCC.
4 :
5 : // GCC is free software; you can redistribute it and/or modify it under
6 : // the terms of the GNU General Public License as published by the Free
7 : // Software Foundation; either version 3, or (at your option) any later
8 : // version.
9 :
10 : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : // for more details.
14 :
15 : // You should have received a copy of the GNU General Public License
16 : // along with GCC; see the file COPYING3. If not see
17 : // <http://www.gnu.org/licenses/>.
18 :
19 : #include "rust-tree.h"
20 : #include "fold-const.h"
21 : #include "stringpool.h"
22 : #include "attribs.h"
23 : #include "escaped_string.h"
24 : #include "libiberty.h"
25 : #include "stor-layout.h"
26 : #include "hash-map.h"
27 : #include "diagnostic.h"
28 : #include "timevar.h"
29 : #include "convert.h"
30 : #include "gimple-expr.h"
31 : #include "gimplify.h"
32 : #include "function.h"
33 : #include "gcc-rich-location.h"
34 : #include "target.h"
35 : #include "file-prefix-map.h"
36 : #include "cgraph.h"
37 : #include "output.h"
38 : #include "memmodel.h"
39 : #include "tm_p.h"
40 :
41 : // forked from gcc/c-family/c-common.cc c_global_trees
42 : tree c_global_trees[CTI_MAX];
43 : // forked from gcc/cp/decl.cc cp_global_trees
44 : tree cp_global_trees[CPTI_MAX];
45 :
46 : struct saved_scope *scope_chain;
47 :
48 : namespace Rust {
49 :
50 : void
51 1566 : mark_exp_read (tree exp)
52 : {
53 1566 : char tmp_name[32];
54 1566 : ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lsrc_loc", 1);
55 :
56 1566 : if (exp == NULL)
57 0 : return;
58 :
59 1566 : switch (TREE_CODE (exp))
60 : {
61 1546 : case VAR_DECL:
62 1546 : gcc_fallthrough ();
63 1546 : case PARM_DECL:
64 1546 : DECL_READ_P (exp) = 1;
65 1546 : break;
66 19 : case ARRAY_REF:
67 19 : case COMPONENT_REF:
68 19 : case MODIFY_EXPR:
69 19 : case REALPART_EXPR:
70 19 : case IMAGPART_EXPR:
71 19 : CASE_CONVERT:
72 19 : case ADDR_EXPR:
73 19 : case INDIRECT_REF:
74 19 : case FLOAT_EXPR:
75 19 : case VIEW_CONVERT_EXPR:
76 19 : mark_exp_read (TREE_OPERAND (exp, 0));
77 19 : break;
78 0 : case COMPOUND_EXPR:
79 0 : mark_exp_read (TREE_OPERAND (exp, 1));
80 0 : break;
81 0 : case COND_EXPR:
82 0 : if (TREE_OPERAND (exp, 1))
83 0 : mark_exp_read (TREE_OPERAND (exp, 1));
84 0 : if (TREE_OPERAND (exp, 2))
85 0 : mark_exp_read (TREE_OPERAND (exp, 2));
86 : break;
87 : default:
88 : break;
89 : }
90 : }
91 :
92 : tree
93 0 : convert_from_reference (tree val)
94 : {
95 0 : if (TREE_TYPE (val) && TYPE_REF_P (TREE_TYPE (val)))
96 : {
97 0 : tree t = TREE_TYPE (TREE_TYPE (val));
98 0 : tree ref = build1 (INDIRECT_REF, t, val);
99 :
100 0 : mark_exp_read (val);
101 :
102 0 : TREE_SIDE_EFFECTS (ref)
103 0 : = (TREE_THIS_VOLATILE (ref) || TREE_SIDE_EFFECTS (val));
104 0 : val = ref;
105 : }
106 :
107 0 : return val;
108 : }
109 :
110 : tree
111 1547 : mark_use (tree expr, bool rvalue_p, bool read_p,
112 : location_t loc /* = UNKNOWN_LOCATION */,
113 : bool reject_builtin /* = true */)
114 : {
115 : #define RECUR(t) mark_use ((t), rvalue_p, read_p, loc, reject_builtin)
116 :
117 1547 : if (expr == NULL_TREE || error_operand_p (expr))
118 : return expr;
119 :
120 1547 : if (reject_builtin)
121 0 : return error_mark_node;
122 :
123 1547 : if (read_p)
124 1547 : mark_exp_read (expr);
125 :
126 1547 : bool recurse_op[3] = {false, false, false};
127 1547 : switch (TREE_CODE (expr))
128 : {
129 16 : case COMPONENT_REF:
130 16 : recurse_op[0] = true;
131 16 : break;
132 0 : case COMPOUND_EXPR:
133 0 : recurse_op[1] = true;
134 0 : break;
135 0 : case COND_EXPR:
136 0 : recurse_op[2] = true;
137 0 : if (TREE_OPERAND (expr, 1))
138 0 : recurse_op[1] = true;
139 : break;
140 1 : case INDIRECT_REF:
141 1 : if (REFERENCE_REF_P (expr))
142 : {
143 : /* Try to look through the reference. */
144 1 : tree ref = TREE_OPERAND (expr, 0);
145 1 : tree r = mark_rvalue_use (ref, loc, reject_builtin);
146 1 : if (r != ref)
147 0 : expr = convert_from_reference (r);
148 : }
149 : break;
150 :
151 0 : case VIEW_CONVERT_EXPR:
152 0 : if (location_wrapper_p (expr))
153 : {
154 0 : loc = EXPR_LOCATION (expr);
155 0 : tree op = TREE_OPERAND (expr, 0);
156 0 : tree nop = RECUR (op);
157 0 : if (nop == error_mark_node)
158 : return error_mark_node;
159 0 : else if (op == nop)
160 : /* No change. */;
161 0 : else if (DECL_P (nop) || CONSTANT_CLASS_P (nop))
162 : {
163 : /* Reuse the location wrapper. */
164 0 : TREE_OPERAND (expr, 0) = nop;
165 : /* If we're replacing a DECL with a constant, we also need to
166 : change the TREE_CODE of the location wrapper. */
167 0 : if (rvalue_p)
168 0 : TREE_SET_CODE (expr, NON_LVALUE_EXPR);
169 : }
170 : else
171 : {
172 : /* Drop the location wrapper. */
173 0 : expr = nop;
174 0 : protected_set_expr_location (expr, loc);
175 : }
176 : return expr;
177 : }
178 0 : gcc_fallthrough ();
179 0 : CASE_CONVERT:
180 0 : recurse_op[0] = true;
181 0 : break;
182 :
183 : default:
184 : break;
185 : }
186 :
187 6188 : for (int i = 0; i < 3; ++i)
188 4641 : if (recurse_op[i])
189 : {
190 16 : tree op = TREE_OPERAND (expr, i);
191 16 : op = RECUR (op);
192 16 : if (op == error_mark_node)
193 : return error_mark_node;
194 16 : TREE_OPERAND (expr, i) = op;
195 : }
196 :
197 : return expr;
198 : #undef RECUR
199 : }
200 :
201 : tree
202 1 : mark_rvalue_use (tree e, location_t loc /* = UNKNOWN_LOCATION */,
203 : bool reject_builtin /* = true */)
204 : {
205 1 : return mark_use (e, true, true, loc, reject_builtin);
206 : }
207 :
208 : tree
209 0 : mark_lvalue_use (tree expr)
210 : {
211 0 : return mark_use (expr, false, true, input_location, false);
212 : }
213 :
214 : tree
215 0 : mark_lvalue_use_nonread (tree expr)
216 : {
217 0 : return mark_use (expr, false, false, input_location, false);
218 : }
219 :
220 : tree
221 13056 : mark_discarded_use (tree expr)
222 : {
223 13056 : if (expr == NULL_TREE)
224 : return expr;
225 :
226 13056 : STRIP_ANY_LOCATION_WRAPPER (expr);
227 :
228 13056 : switch (TREE_CODE (expr))
229 : {
230 0 : case COND_EXPR:
231 0 : TREE_OPERAND (expr, 2) = mark_discarded_use (TREE_OPERAND (expr, 2));
232 114 : gcc_fallthrough ();
233 114 : case COMPOUND_EXPR:
234 114 : TREE_OPERAND (expr, 1) = mark_discarded_use (TREE_OPERAND (expr, 1));
235 114 : return expr;
236 :
237 : case COMPONENT_REF:
238 : case ARRAY_REF:
239 : case INDIRECT_REF:
240 : case MEMBER_REF:
241 : break;
242 12925 : default:
243 12925 : if (DECL_P (expr))
244 : break;
245 : else
246 : return expr;
247 : }
248 :
249 1530 : return mark_use (expr, true, true, input_location, false);
250 : }
251 :
252 : tree
253 12974 : convert_to_void (tree expr, impl_conv_void implicit)
254 : {
255 12974 : location_t loc = expr_loc_or_input_loc (expr);
256 12974 : if (expr == error_mark_node || TREE_TYPE (expr) == error_mark_node)
257 : return error_mark_node;
258 :
259 12942 : expr = mark_discarded_use (expr);
260 12942 : if (implicit == ICV_CAST)
261 : /* An explicit cast to void avoids all -Wunused-but-set* warnings. */
262 0 : mark_exp_read (expr);
263 :
264 12942 : if (!TREE_TYPE (expr))
265 : return expr;
266 :
267 12942 : if (VOID_TYPE_P (TREE_TYPE (expr)))
268 : return expr;
269 9259 : switch (TREE_CODE (expr))
270 : {
271 0 : case COND_EXPR:
272 0 : {
273 : /* The two parts of a cond expr might be separate lvalues. */
274 0 : tree op1 = TREE_OPERAND (expr, 1);
275 0 : tree op2 = TREE_OPERAND (expr, 2);
276 0 : bool side_effects
277 0 : = ((op1 && TREE_SIDE_EFFECTS (op1)) || TREE_SIDE_EFFECTS (op2));
278 0 : tree new_op1, new_op2;
279 0 : new_op1 = NULL_TREE;
280 0 : if (implicit != ICV_CAST && !side_effects)
281 : {
282 0 : if (op1)
283 0 : new_op1 = convert_to_void (op1, ICV_SECOND_OF_COND);
284 0 : new_op2 = convert_to_void (op2, ICV_THIRD_OF_COND);
285 : }
286 : else
287 : {
288 0 : if (op1)
289 0 : new_op1 = convert_to_void (op1, ICV_CAST);
290 0 : new_op2 = convert_to_void (op2, ICV_CAST);
291 : }
292 :
293 0 : expr = build3_loc (loc, COND_EXPR, TREE_TYPE (new_op2),
294 0 : TREE_OPERAND (expr, 0), new_op1, new_op2);
295 0 : break;
296 : }
297 :
298 65 : case COMPOUND_EXPR:
299 65 : {
300 : /* The second part of a compound expr contains the value. */
301 65 : tree op1 = TREE_OPERAND (expr, 1);
302 65 : tree new_op1;
303 65 : if (implicit != ICV_CAST
304 65 : && !warning_suppressed_p (expr /* What warning? */))
305 65 : new_op1 = convert_to_void (op1, ICV_RIGHT_OF_COMMA);
306 : else
307 0 : new_op1 = convert_to_void (op1, ICV_CAST);
308 :
309 65 : if (new_op1 != op1)
310 : {
311 2 : tree t = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (new_op1),
312 2 : TREE_OPERAND (expr, 0), new_op1);
313 2 : expr = t;
314 : }
315 :
316 : break;
317 : }
318 :
319 : case NON_LVALUE_EXPR:
320 : case NOP_EXPR:
321 : /* These have already decayed to rvalue. */
322 : break;
323 :
324 2512 : case CALL_EXPR:
325 2512 : maybe_warn_nodiscard (expr, implicit);
326 2512 : break;
327 :
328 1 : case INDIRECT_REF:
329 1 : {
330 1 : tree type = TREE_TYPE (expr);
331 1 : int is_reference = TYPE_REF_P (TREE_TYPE (TREE_OPERAND (expr, 0)));
332 1 : int is_volatile = TYPE_VOLATILE (type);
333 1 : int is_complete = COMPLETE_TYPE_P (type);
334 :
335 : /* Can't load the value if we don't know the type. */
336 1 : if (is_volatile && !is_complete)
337 : {
338 0 : switch (implicit)
339 : {
340 0 : case ICV_CAST:
341 0 : warning_at (loc, 0,
342 : "conversion to void will not access "
343 : "object of incomplete type %qT",
344 : type);
345 0 : break;
346 0 : case ICV_SECOND_OF_COND:
347 0 : warning_at (loc, 0,
348 : "indirection will not access object of "
349 : "incomplete type %qT in second operand "
350 : "of conditional expression",
351 : type);
352 0 : break;
353 0 : case ICV_THIRD_OF_COND:
354 0 : warning_at (loc, 0,
355 : "indirection will not access object of "
356 : "incomplete type %qT in third operand "
357 : "of conditional expression",
358 : type);
359 0 : break;
360 0 : case ICV_RIGHT_OF_COMMA:
361 0 : warning_at (loc, 0,
362 : "indirection will not access object of "
363 : "incomplete type %qT in right operand of "
364 : "comma operator",
365 : type);
366 0 : break;
367 0 : case ICV_LEFT_OF_COMMA:
368 0 : warning_at (loc, 0,
369 : "indirection will not access object of "
370 : "incomplete type %qT in left operand of "
371 : "comma operator",
372 : type);
373 0 : break;
374 0 : case ICV_STATEMENT:
375 0 : warning_at (loc, 0,
376 : "indirection will not access object of "
377 : "incomplete type %qT in statement",
378 : type);
379 0 : break;
380 0 : case ICV_THIRD_IN_FOR:
381 0 : warning_at (loc, 0,
382 : "indirection will not access object of "
383 : "incomplete type %qT in for increment "
384 : "expression",
385 : type);
386 0 : break;
387 0 : default:
388 0 : rust_unreachable ();
389 : }
390 : }
391 : /* Don't load the value if this is an implicit dereference, or if
392 : the type needs to be handled by ctors/dtors. */
393 1 : else if (is_volatile && is_reference)
394 : {
395 0 : switch (implicit)
396 : {
397 0 : case ICV_CAST:
398 0 : warning_at (loc, 0,
399 : "conversion to void will not access "
400 : "object of type %qT",
401 : type);
402 0 : break;
403 0 : case ICV_SECOND_OF_COND:
404 0 : warning_at (loc, 0,
405 : "implicit dereference will not access "
406 : "object of type %qT in second operand of "
407 : "conditional expression",
408 : type);
409 0 : break;
410 0 : case ICV_THIRD_OF_COND:
411 0 : warning_at (loc, 0,
412 : "implicit dereference will not access "
413 : "object of type %qT in third operand of "
414 : "conditional expression",
415 : type);
416 0 : break;
417 0 : case ICV_RIGHT_OF_COMMA:
418 0 : warning_at (loc, 0,
419 : "implicit dereference will not access "
420 : "object of type %qT in right operand of "
421 : "comma operator",
422 : type);
423 0 : break;
424 0 : case ICV_LEFT_OF_COMMA:
425 0 : warning_at (loc, 0,
426 : "implicit dereference will not access "
427 : "object of type %qT in left operand of comma "
428 : "operator",
429 : type);
430 0 : break;
431 0 : case ICV_STATEMENT:
432 0 : warning_at (loc, 0,
433 : "implicit dereference will not access "
434 : "object of type %qT in statement",
435 : type);
436 0 : break;
437 0 : case ICV_THIRD_IN_FOR:
438 0 : warning_at (loc, 0,
439 : "implicit dereference will not access "
440 : "object of type %qT in for increment expression",
441 : type);
442 0 : break;
443 0 : default:
444 0 : rust_unreachable ();
445 : }
446 : }
447 1 : else if (is_volatile && TREE_ADDRESSABLE (type))
448 : {
449 0 : switch (implicit)
450 : {
451 0 : case ICV_CAST:
452 0 : warning_at (loc, 0,
453 : "conversion to void will not access "
454 : "object of non-trivially-copyable type %qT",
455 : type);
456 0 : break;
457 0 : case ICV_SECOND_OF_COND:
458 0 : warning_at (loc, 0,
459 : "indirection will not access object of "
460 : "non-trivially-copyable type %qT in second "
461 : "operand of conditional expression",
462 : type);
463 0 : break;
464 0 : case ICV_THIRD_OF_COND:
465 0 : warning_at (loc, 0,
466 : "indirection will not access object of "
467 : "non-trivially-copyable type %qT in third "
468 : "operand of conditional expression",
469 : type);
470 0 : break;
471 0 : case ICV_RIGHT_OF_COMMA:
472 0 : warning_at (loc, 0,
473 : "indirection will not access object of "
474 : "non-trivially-copyable type %qT in right "
475 : "operand of comma operator",
476 : type);
477 0 : break;
478 0 : case ICV_LEFT_OF_COMMA:
479 0 : warning_at (loc, 0,
480 : "indirection will not access object of "
481 : "non-trivially-copyable type %qT in left "
482 : "operand of comma operator",
483 : type);
484 0 : break;
485 0 : case ICV_STATEMENT:
486 0 : warning_at (loc, 0,
487 : "indirection will not access object of "
488 : "non-trivially-copyable type %qT in statement",
489 : type);
490 0 : break;
491 0 : case ICV_THIRD_IN_FOR:
492 0 : warning_at (loc, 0,
493 : "indirection will not access object of "
494 : "non-trivially-copyable type %qT in for "
495 : "increment expression",
496 : type);
497 0 : break;
498 0 : default:
499 0 : rust_unreachable ();
500 : }
501 : }
502 1 : if (is_reference || !is_volatile || !is_complete
503 0 : || TREE_ADDRESSABLE (type))
504 : {
505 : /* Emit a warning (if enabled) when the "effect-less" INDIRECT_REF
506 : operation is stripped off. Note that we don't warn about
507 : - an expression with TREE_NO_WARNING set. (For an example of
508 : such expressions, see build_over_call in call.cc.)
509 : - automatic dereferencing of references, since the user cannot
510 : control it. (See also warn_if_unused_value() in c-common.cc.)
511 : */
512 0 : if (warn_unused_value && implicit != ICV_CAST
513 0 : && !warning_suppressed_p (expr, OPT_Wunused_value)
514 1 : && !is_reference)
515 0 : warning_at (loc, OPT_Wunused_value, "value computed is not used");
516 1 : expr = TREE_OPERAND (expr, 0);
517 1 : if (TREE_CODE (expr) == CALL_EXPR)
518 0 : maybe_warn_nodiscard (expr, implicit);
519 : }
520 :
521 : break;
522 : }
523 :
524 1504 : case VAR_DECL:
525 1504 : {
526 : /* External variables might be incomplete. */
527 1504 : tree type = TREE_TYPE (expr);
528 1504 : int is_complete = COMPLETE_TYPE_P (type);
529 :
530 1504 : if (TYPE_VOLATILE (type) && !is_complete)
531 0 : switch (implicit)
532 : {
533 0 : case ICV_CAST:
534 0 : warning_at (loc, 0,
535 : "conversion to void will not access "
536 : "object %qE of incomplete type %qT",
537 : expr, type);
538 0 : break;
539 0 : case ICV_SECOND_OF_COND:
540 0 : warning_at (loc, 0,
541 : "variable %qE of incomplete type %qT will "
542 : "not be accessed in second operand of "
543 : "conditional expression",
544 : expr, type);
545 0 : break;
546 0 : case ICV_THIRD_OF_COND:
547 0 : warning_at (loc, 0,
548 : "variable %qE of incomplete type %qT will "
549 : "not be accessed in third operand of "
550 : "conditional expression",
551 : expr, type);
552 0 : break;
553 0 : case ICV_RIGHT_OF_COMMA:
554 0 : warning_at (loc, 0,
555 : "variable %qE of incomplete type %qT will "
556 : "not be accessed in right operand of comma operator",
557 : expr, type);
558 0 : break;
559 0 : case ICV_LEFT_OF_COMMA:
560 0 : warning_at (loc, 0,
561 : "variable %qE of incomplete type %qT will "
562 : "not be accessed in left operand of comma operator",
563 : expr, type);
564 0 : break;
565 0 : case ICV_STATEMENT:
566 0 : warning_at (loc, 0,
567 : "variable %qE of incomplete type %qT will "
568 : "not be accessed in statement",
569 : expr, type);
570 0 : break;
571 0 : case ICV_THIRD_IN_FOR:
572 0 : warning_at (loc, 0,
573 : "variable %qE of incomplete type %qT will "
574 : "not be accessed in for increment expression",
575 : expr, type);
576 0 : break;
577 0 : default:
578 0 : rust_unreachable ();
579 : }
580 :
581 : break;
582 : }
583 :
584 9259 : default:;
585 : }
586 :
587 9259 : if (!TREE_SIDE_EFFECTS (expr))
588 6694 : expr = void_node;
589 :
590 : return expr;
591 : }
592 :
593 : void
594 2512 : maybe_warn_nodiscard (tree expr, impl_conv_void implicit)
595 : {
596 2512 : tree call = expr;
597 2512 : if (TREE_CODE (expr) == TARGET_EXPR)
598 0 : call = TARGET_EXPR_INITIAL (expr);
599 :
600 2512 : location_t loc = expr_loc_or_input_loc (call);
601 2512 : tree callee = CALL_EXPR_FN (call);
602 2512 : if (!callee)
603 : return;
604 :
605 2512 : tree type = TREE_TYPE (callee);
606 2512 : if (INDIRECT_TYPE_P (type))
607 2512 : type = TREE_TYPE (type);
608 :
609 2512 : tree rettype = TREE_TYPE (type);
610 2512 : tree fn = get_fndecl_from_callee (callee);
611 2512 : tree attr;
612 2512 : if (implicit != ICV_CAST && fn
613 2512 : && (attr = lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn))))
614 : {
615 14 : escaped_string msg;
616 14 : tree args = TREE_VALUE (attr);
617 14 : if (args)
618 7 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
619 14 : const char *format
620 14 : = (msg ? G_ ("ignoring return value of %qD, that must be used: %qs")
621 7 : : G_ ("ignoring return value of %qD, that must be used"));
622 14 : const char *raw_msg = msg ? (const char *) msg : "";
623 14 : auto_diagnostic_group d;
624 14 : if (warning_at (loc, OPT_Wunused_result, format, fn, raw_msg))
625 14 : inform (DECL_SOURCE_LOCATION (fn), "declared here");
626 14 : }
627 2498 : else if (implicit != ICV_CAST
628 2498 : && (attr
629 2498 : = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype))))
630 : {
631 0 : escaped_string msg;
632 0 : tree args = TREE_VALUE (attr);
633 0 : if (args)
634 0 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
635 0 : const char *format
636 0 : = (msg ? G_ (
637 : "ignoring returned value of type %qT, that must be used: %qs")
638 0 : : G_ ("ignoring returned value of type %qT, that must be used"));
639 0 : const char *raw_msg = msg ? (const char *) msg : "";
640 0 : auto_diagnostic_group d;
641 0 : if (warning_at (loc, OPT_Wunused_result, format, rettype, raw_msg))
642 : {
643 0 : if (fn)
644 0 : inform (DECL_SOURCE_LOCATION (fn), "in call to %qD, declared here",
645 : fn);
646 0 : inform (DECL_SOURCE_LOCATION (TYPE_NAME (rettype)),
647 : "%qT declared here", rettype);
648 : }
649 0 : }
650 : }
651 :
652 : location_t
653 15486 : expr_loc_or_loc (const_tree t, location_t or_loc)
654 : {
655 15486 : location_t loc = EXPR_LOCATION (t);
656 8793 : if (loc == UNKNOWN_LOCATION)
657 6693 : loc = or_loc;
658 15486 : return loc;
659 : }
660 :
661 : location_t
662 15486 : expr_loc_or_input_loc (const_tree t)
663 : {
664 15486 : return expr_loc_or_loc (t, input_location);
665 : }
666 :
667 : // FN is the callee of a CALL_EXPR or AGGR_INIT_EXPR; return the FUNCTION_DECL
668 : // if we can.
669 : tree
670 2512 : get_fndecl_from_callee (tree fn)
671 : {
672 2512 : if (fn == NULL_TREE)
673 : return fn;
674 2512 : if (TREE_CODE (fn) == FUNCTION_DECL)
675 : return fn;
676 2512 : tree type = TREE_TYPE (fn);
677 2512 : if (type == NULL_TREE || !INDIRECT_TYPE_P (type))
678 : return NULL_TREE;
679 :
680 2512 : STRIP_NOPS (fn);
681 2512 : if (TREE_CODE (fn) == ADDR_EXPR || TREE_CODE (fn) == FDESC_EXPR)
682 2374 : fn = TREE_OPERAND (fn, 0);
683 2512 : if (TREE_CODE (fn) == FUNCTION_DECL)
684 2374 : return fn;
685 : return NULL_TREE;
686 : }
687 :
688 : tree
689 256 : pointer_offset_expression (tree base_tree, tree index_tree, location_t location)
690 : {
691 256 : tree base_type_tree = TREE_TYPE (base_tree);
692 256 : tree element_type_tree
693 256 : = TREE_TYPE (base_type_tree) ? TREE_TYPE (base_type_tree) : error_mark_node;
694 256 : if (base_tree == error_mark_node || TREE_TYPE (base_tree) == error_mark_node
695 512 : || index_tree == error_mark_node || element_type_tree == error_mark_node)
696 : {
697 1 : error_at (location, "unknown element size type for %qT", base_type_tree);
698 1 : return error_mark_node;
699 : }
700 :
701 255 : tree element_size = TYPE_SIZE_UNIT (element_type_tree);
702 255 : index_tree = fold_convert_loc (location, sizetype, index_tree);
703 255 : tree offset
704 255 : = fold_build2_loc (location, MULT_EXPR, sizetype, index_tree, element_size);
705 :
706 255 : return fold_build2_loc (location, POINTER_PLUS_EXPR, TREE_TYPE (base_tree),
707 255 : base_tree, offset);
708 : }
709 :
710 : // forked from gcc/cp/tree.cc cp_walk_subtrees
711 : /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
712 : traversal. Called from walk_tree. */
713 :
714 : tree
715 153261 : rs_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func, void *data,
716 : hash_set<tree> *pset)
717 : {
718 153261 : enum tree_code code = TREE_CODE (*tp);
719 153261 : tree result;
720 :
721 : #define WALK_SUBTREE(NODE) \
722 : do \
723 : { \
724 : result = rs_walk_tree (&(NODE), func, data, pset); \
725 : if (result) \
726 : goto out; \
727 : } \
728 : while (0)
729 :
730 153261 : if (TYPE_P (*tp))
731 : {
732 : /* If *WALK_SUBTREES_P is 1, we're interested in the syntactic form of
733 : the argument, so don't look through typedefs, but do walk into
734 : template arguments for alias templates (and non-typedefed classes).
735 :
736 : If *WALK_SUBTREES_P > 1, we're interested in type identity or
737 : equivalence, so look through typedefs, ignoring template arguments for
738 : alias templates, and walk into template args of classes.
739 :
740 : See find_abi_tags_r for an example of setting *WALK_SUBTREES_P to 2
741 : when that's the behavior the walk_tree_fn wants. */
742 0 : if (*walk_subtrees_p == 1 && typedef_variant_p (*tp))
743 : {
744 0 : *walk_subtrees_p = 0;
745 0 : return NULL_TREE;
746 : }
747 : }
748 :
749 : /* Not one of the easy cases. We must explicitly go through the
750 : children. */
751 153261 : result = NULL_TREE;
752 153261 : switch (code)
753 : {
754 0 : case TREE_LIST:
755 0 : WALK_SUBTREE (TREE_PURPOSE (*tp));
756 : break;
757 :
758 0 : case RECORD_TYPE:
759 0 : if (TYPE_PTRMEMFUNC_P (*tp))
760 0 : WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (*tp));
761 : break;
762 :
763 1 : case CONSTRUCTOR:
764 1 : if (COMPOUND_LITERAL_P (*tp))
765 0 : WALK_SUBTREE (TREE_TYPE (*tp));
766 : break;
767 :
768 0 : case DECL_EXPR:
769 : /* User variables should be mentioned in BIND_EXPR_VARS
770 : and their initializers and sizes walked when walking
771 : the containing BIND_EXPR. Compiler temporaries are
772 : handled here. And also normal variables in templates,
773 : since do_poplevel doesn't build a BIND_EXPR then. */
774 0 : if (VAR_P (TREE_OPERAND (*tp, 0))
775 0 : && (DECL_ARTIFICIAL (TREE_OPERAND (*tp, 0))
776 0 : && !TREE_STATIC (TREE_OPERAND (*tp, 0))))
777 : {
778 0 : tree decl = TREE_OPERAND (*tp, 0);
779 0 : WALK_SUBTREE (DECL_INITIAL (decl));
780 0 : WALK_SUBTREE (DECL_SIZE (decl));
781 0 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
782 : }
783 : break;
784 :
785 : default:
786 : return NULL_TREE;
787 : }
788 :
789 : /* We didn't find what we were looking for. */
790 153261 : out:
791 : return result;
792 :
793 : #undef WALK_SUBTREE
794 : }
795 :
796 : // forked from gcc/cp/tree.cc cp_expr_location
797 :
798 : /* Like EXPR_LOCATION, but also handle some tcc_exceptional that have
799 : locations. */
800 :
801 : location_t
802 11 : rs_expr_location (const_tree t_)
803 : {
804 11 : tree t = const_cast<tree> (t_);
805 11 : if (t == NULL_TREE)
806 : return UNKNOWN_LOCATION;
807 :
808 11 : return EXPR_LOCATION (t);
809 : }
810 :
811 : // forked from gcc/cp/class.cc is_really_empty_class
812 :
813 : /* Returns true if TYPE contains no actual data, just various
814 : possible combinations of empty classes. If IGNORE_VPTR is true,
815 : a vptr doesn't prevent the class from being considered empty. Typically
816 : we want to ignore the vptr on assignment, and not on initialization. */
817 :
818 : bool
819 1741 : is_really_empty_class (tree type, bool ignore_vptr)
820 : {
821 1741 : if (CLASS_TYPE_P (type))
822 : {
823 0 : tree field;
824 0 : tree binfo;
825 0 : tree base_binfo;
826 0 : int i;
827 :
828 : /* CLASSTYPE_EMPTY_P isn't set properly until the class is actually laid
829 : out, but we'd like to be able to check this before then. */
830 0 : if (COMPLETE_TYPE_P (type) && is_empty_class (type))
831 : return true;
832 :
833 0 : if (!ignore_vptr && TYPE_CONTAINS_VPTR_P (type))
834 : return false;
835 :
836 0 : for (binfo = TYPE_BINFO (type), i = 0;
837 0 : BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
838 0 : if (!is_really_empty_class (BINFO_TYPE (base_binfo), ignore_vptr))
839 : return false;
840 0 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
841 0 : if (TREE_CODE (field) == FIELD_DECL
842 0 : && !DECL_ARTIFICIAL (field)
843 : /* An unnamed bit-field is not a data member. */
844 0 : && !DECL_UNNAMED_BIT_FIELD (field)
845 0 : && !is_really_empty_class (TREE_TYPE (field), ignore_vptr))
846 : return false;
847 : return true;
848 : }
849 1741 : else if (TREE_CODE (type) == ARRAY_TYPE)
850 8 : return (integer_zerop (array_type_nelts_top (type))
851 8 : || is_really_empty_class (TREE_TYPE (type), ignore_vptr));
852 : return false;
853 : }
854 :
855 : // forked from gcc/cp/class.cc is_empty_class
856 :
857 : /* Returns 1 if TYPE contains only padding bytes. */
858 :
859 : int
860 5 : is_empty_class (tree type)
861 : {
862 5 : if (type == error_mark_node)
863 : return 0;
864 :
865 5 : if (!CLASS_TYPE_P (type))
866 : return 0;
867 :
868 0 : return CLASSTYPE_EMPTY_P (type);
869 : }
870 :
871 : // forked from gcc/cp/tree.cc builtin_valid_in_constant_expr_p
872 :
873 : /* Test whether DECL is a builtin that may appear in a
874 : constant-expression. */
875 :
876 : bool
877 0 : builtin_valid_in_constant_expr_p (const_tree decl)
878 : {
879 0 : STRIP_ANY_LOCATION_WRAPPER (decl);
880 0 : if (TREE_CODE (decl) != FUNCTION_DECL)
881 : /* Not a function. */
882 : return false;
883 0 : if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL)
884 : {
885 0 : if (fndecl_built_in_p (decl, BUILT_IN_FRONTEND))
886 0 : switch (DECL_FE_FUNCTION_CODE (decl))
887 : {
888 : case RS_BUILT_IN_IS_CONSTANT_EVALUATED:
889 : case RS_BUILT_IN_SOURCE_LOCATION:
890 : case RS_BUILT_IN_IS_CORRESPONDING_MEMBER:
891 : case RS_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS:
892 : return true;
893 : default:
894 : break;
895 : }
896 : /* Not a built-in. */
897 : return false;
898 : }
899 0 : switch (DECL_FUNCTION_CODE (decl))
900 : {
901 : /* These always have constant results like the corresponding
902 : macros/symbol. */
903 : case BUILT_IN_FILE:
904 : case BUILT_IN_FUNCTION:
905 : case BUILT_IN_LINE:
906 :
907 : /* The following built-ins are valid in constant expressions
908 : when their arguments are. */
909 : case BUILT_IN_ADD_OVERFLOW_P:
910 : case BUILT_IN_SUB_OVERFLOW_P:
911 : case BUILT_IN_MUL_OVERFLOW_P:
912 :
913 : /* These have constant results even if their operands are
914 : non-constant. */
915 : case BUILT_IN_CONSTANT_P:
916 : case BUILT_IN_ATOMIC_ALWAYS_LOCK_FREE:
917 : return true;
918 : default:
919 : return false;
920 : }
921 : }
922 :
923 : // forked from gcc/cp/decl2.cc decl_maybe_constant_var_p
924 :
925 : /* Returns true if DECL could be a symbolic constant variable, depending on
926 : its initializer. */
927 :
928 : bool
929 0 : decl_maybe_constant_var_p (tree decl)
930 : {
931 0 : tree type = TREE_TYPE (decl);
932 0 : if (!VAR_P (decl))
933 : return false;
934 0 : if (DECL_DECLARED_CONSTEXPR_P (decl))
935 : return true;
936 0 : if (DECL_HAS_VALUE_EXPR_P (decl))
937 : /* A proxy isn't constant. */
938 : return false;
939 0 : if (TYPE_REF_P (type))
940 : /* References can be constant. */;
941 0 : else if (RS_TYPE_CONST_NON_VOLATILE_P (type)
942 0 : && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
943 : /* And const integers. */;
944 : else
945 : return false;
946 :
947 0 : if (DECL_INITIAL (decl) && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
948 : /* We know the initializer, and it isn't constant. */
949 0 : return false;
950 : else
951 : return true;
952 : }
953 :
954 : // forked from gcc/cp/typeck.cc cp_type_quals
955 :
956 : /* Returns the type qualifiers for this type, including the qualifiers on the
957 : elements for an array type. */
958 :
959 : cv_qualifier
960 153416 : rs_type_quals (const_tree type)
961 : {
962 : /* This CONST_CAST is okay because strip_array_types returns its
963 : argument unmodified and we assign it to a const_tree. */
964 153416 : type = strip_array_types (const_cast<tree> (type));
965 153416 : if (type == error_mark_node
966 : /* Quals on a FUNCTION_TYPE are memfn quals. */
967 153416 : || TREE_CODE (type) == FUNCTION_TYPE)
968 : return TYPE_UNQUALIFIED;
969 :
970 153416 : addr_space_t addr_space;
971 153416 : cv_qualifier quals;
972 153416 : std::tie (quals, addr_space) = TYPE_QUALS (type).split ();
973 : /* METHOD and REFERENCE_TYPEs should never have quals. */
974 : // gcc_assert (
975 : // (TREE_CODE (type) != METHOD_TYPE && !TYPE_REF_P (type))
976 : // || ((quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)) ==
977 : // TYPE_UNQUALIFIED));
978 : /* At the moment, the Rust front-end does not do address spaces. */
979 153416 : gcc_assert (ADDR_SPACE_GENERIC_P (addr_space));
980 : return quals;
981 : }
982 :
983 : // forked from gcc/cp/decl.cc cp_global_trees
984 :
985 : /* The following symbols are subsumed in the cp_global_trees array, and
986 : listed here individually for documentation purposes.
987 :
988 : C++ extensions
989 : tree wchar_decl_node;
990 :
991 : tree vtable_entry_type;
992 : tree delta_type_node;
993 : tree __t_desc_type_node;
994 :
995 : tree class_type_node;
996 : tree unknown_type_node;
997 :
998 : Array type `vtable_entry_type[]'
999 :
1000 : tree vtbl_type_node;
1001 : tree vtbl_ptr_type_node;
1002 :
1003 : Namespaces,
1004 :
1005 : tree std_node;
1006 : tree abi_node;
1007 :
1008 : A FUNCTION_DECL which can call `abort'. Not necessarily the
1009 : one that the user will declare, but sufficient to be called
1010 : by routines that want to abort the program.
1011 :
1012 : tree abort_fndecl;
1013 :
1014 : Used by RTTI
1015 : tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
1016 : tree tinfo_var_id; */
1017 :
1018 : /* The following symbols are subsumed in the c_global_trees array, and
1019 : listed here individually for documentation purposes.
1020 :
1021 : INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
1022 :
1023 : tree short_integer_type_node;
1024 : tree long_integer_type_node;
1025 : tree long_long_integer_type_node;
1026 :
1027 : tree short_unsigned_type_node;
1028 : tree long_unsigned_type_node;
1029 : tree long_long_unsigned_type_node;
1030 :
1031 : tree truthvalue_type_node;
1032 : tree truthvalue_false_node;
1033 : tree truthvalue_true_node;
1034 :
1035 : tree ptrdiff_type_node;
1036 :
1037 : tree unsigned_char_type_node;
1038 : tree signed_char_type_node;
1039 : tree wchar_type_node;
1040 :
1041 : tree char8_type_node;
1042 : tree char16_type_node;
1043 : tree char32_type_node;
1044 :
1045 : tree float_type_node;
1046 : tree double_type_node;
1047 : tree long_double_type_node;
1048 :
1049 : tree complex_integer_type_node;
1050 : tree complex_float_type_node;
1051 : tree complex_double_type_node;
1052 : tree complex_long_double_type_node;
1053 :
1054 : tree dfloat32_type_node;
1055 : tree dfloat64_type_node;
1056 : tree_dfloat128_type_node;
1057 :
1058 : tree intQI_type_node;
1059 : tree intHI_type_node;
1060 : tree intSI_type_node;
1061 : tree intDI_type_node;
1062 : tree intTI_type_node;
1063 :
1064 : tree unsigned_intQI_type_node;
1065 : tree unsigned_intHI_type_node;
1066 : tree unsigned_intSI_type_node;
1067 : tree unsigned_intDI_type_node;
1068 : tree unsigned_intTI_type_node;
1069 :
1070 : tree widest_integer_literal_type_node;
1071 : tree widest_unsigned_literal_type_node;
1072 :
1073 : Nodes for types `void *' and `const void *'.
1074 :
1075 : tree ptr_type_node, const_ptr_type_node;
1076 :
1077 : Nodes for types `char *' and `const char *'.
1078 :
1079 : tree string_type_node, const_string_type_node;
1080 :
1081 : Type `char[SOMENUMBER]'.
1082 : Used when an array of char is needed and the size is irrelevant.
1083 :
1084 : tree char_array_type_node;
1085 :
1086 : Type `wchar_t[SOMENUMBER]' or something like it.
1087 : Used when a wide string literal is created.
1088 :
1089 : tree wchar_array_type_node;
1090 :
1091 : Type `char8_t[SOMENUMBER]' or something like it.
1092 : Used when a UTF-8 string literal is created.
1093 :
1094 : tree char8_array_type_node;
1095 :
1096 : Type `char16_t[SOMENUMBER]' or something like it.
1097 : Used when a UTF-16 string literal is created.
1098 :
1099 : tree char16_array_type_node;
1100 :
1101 : Type `char32_t[SOMENUMBER]' or something like it.
1102 : Used when a UTF-32 string literal is created.
1103 :
1104 : tree char32_array_type_node;
1105 :
1106 : Type `int ()' -- used for implicit declaration of functions.
1107 :
1108 : tree default_function_type;
1109 :
1110 : A VOID_TYPE node, packaged in a TREE_LIST.
1111 :
1112 : tree void_list_node;
1113 :
1114 : The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
1115 : and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
1116 : VAR_DECLS, but C++ does.)
1117 :
1118 : tree function_name_decl_node;
1119 : tree pretty_function_name_decl_node;
1120 : tree c99_function_name_decl_node;
1121 :
1122 : Stack of nested function name VAR_DECLs.
1123 :
1124 : tree saved_function_name_decls;
1125 :
1126 : */
1127 :
1128 : // forked from gcc/cp/module.cc fixed_trees
1129 :
1130 : static GTY (()) vec<tree, va_gc> *fixed_trees;
1131 :
1132 : // forked from gcc/cp/module.cc maybe_add_global
1133 :
1134 : /* VAL is a global tree, add it to the global vec if it is
1135 : interesting. Add some of its targets, if they too are
1136 : interesting. We do not add identifiers, as they can be re-found
1137 : via the identifier hash table. There is a cost to the number of
1138 : global trees. */
1139 :
1140 : static int
1141 0 : maybe_add_global (tree val, unsigned &crc)
1142 : {
1143 0 : int v = 0;
1144 :
1145 0 : if (val && !(TREE_CODE (val) == IDENTIFIER_NODE || TREE_VISITED (val)))
1146 : {
1147 0 : TREE_VISITED (val) = true;
1148 0 : crc = crc32_unsigned (crc, fixed_trees->length ());
1149 0 : vec_safe_push (fixed_trees, val);
1150 0 : v++;
1151 :
1152 0 : if (CODE_CONTAINS_STRUCT (TREE_CODE (val), TS_TYPED))
1153 0 : v += maybe_add_global (TREE_TYPE (val), crc);
1154 0 : if (CODE_CONTAINS_STRUCT (TREE_CODE (val), TS_TYPE_COMMON))
1155 0 : v += maybe_add_global (TYPE_NAME (val), crc);
1156 : }
1157 :
1158 0 : return v;
1159 : }
1160 :
1161 : // forked from gcc/cp/module.cc global_tree_arys
1162 :
1163 : /* Global trees. */
1164 : static const std::pair<tree *, unsigned> global_tree_arys[] = {
1165 : std::pair<tree *, unsigned> (cp_global_trees, CPTI_MODULE_HWM),
1166 : std::pair<tree *, unsigned> (c_global_trees, CTI_MODULE_HWM),
1167 : };
1168 :
1169 : // forked from gcc/cp/module.cc init_modules
1170 :
1171 : void
1172 0 : init_modules ()
1173 : {
1174 0 : unsigned crc = 0;
1175 0 : vec_alloc (fixed_trees, 200);
1176 :
1177 0 : const tree *ptr = global_tree_arys[0].first;
1178 0 : unsigned limit = global_tree_arys[0].second;
1179 0 : for (unsigned ix = 0; ix != limit; ix++, ptr++)
1180 : {
1181 0 : maybe_add_global (*ptr, crc);
1182 : }
1183 :
1184 : ptr = global_tree_arys[1].first;
1185 0 : limit = global_tree_arys[1].second;
1186 0 : for (unsigned ix = 0; ix != limit; ix++, ptr++)
1187 : {
1188 0 : maybe_add_global (*ptr, crc);
1189 : }
1190 0 : }
1191 :
1192 : // forked from gcc/cp/constexpr.cc var_in_constexpr_fn
1193 :
1194 : /* True if T was declared in a function declared to be constexpr, and
1195 : therefore potentially constant in C++14. */
1196 :
1197 : bool
1198 0 : var_in_constexpr_fn (tree t)
1199 : {
1200 0 : tree ctx = DECL_CONTEXT (t);
1201 0 : return (ctx && TREE_CODE (ctx) == FUNCTION_DECL
1202 0 : && DECL_DECLARED_CONSTEXPR_P (ctx));
1203 : }
1204 :
1205 : // forked from gcc/cp/name-lookup.cc member_vec_linear_search
1206 :
1207 : /* Linear search of (unordered) MEMBER_VEC for NAME. */
1208 :
1209 : static tree
1210 0 : member_vec_linear_search (vec<tree, va_gc> *member_vec, tree name)
1211 : {
1212 0 : for (int ix = member_vec->length (); ix--;)
1213 0 : if (tree binding = (*member_vec)[ix])
1214 0 : if (OVL_NAME (binding) == name)
1215 : return binding;
1216 :
1217 : return NULL_TREE;
1218 : }
1219 :
1220 : // forked from gcc/cp/name-lookup.cc member_vec_binary_search
1221 :
1222 : /* Binary search of (ordered) MEMBER_VEC for NAME. */
1223 :
1224 : static tree
1225 0 : member_vec_binary_search (vec<tree, va_gc> *member_vec, tree name)
1226 : {
1227 0 : for (unsigned lo = 0, hi = member_vec->length (); lo < hi;)
1228 : {
1229 0 : unsigned mid = (lo + hi) / 2;
1230 0 : tree binding = (*member_vec)[mid];
1231 0 : tree binding_name = OVL_NAME (binding);
1232 :
1233 0 : if (binding_name > name)
1234 : hi = mid;
1235 0 : else if (binding_name < name)
1236 0 : lo = mid + 1;
1237 : else
1238 : return binding;
1239 : }
1240 :
1241 : return NULL_TREE;
1242 : }
1243 :
1244 : // forked from gcc/cp/tree.cc is_overloaded_fn
1245 :
1246 : /* Returns nonzero if X is an expression for a (possibly overloaded)
1247 : function. If "f" is a function or function template, "f", "c->f",
1248 : "c.f", "C::f", and "f<int>" will all be considered possibly
1249 : overloaded functions. Returns 2 if the function is actually
1250 : overloaded, i.e., if it is impossible to know the type of the
1251 : function without performing overload resolution. */
1252 :
1253 : int
1254 11 : is_overloaded_fn (tree x)
1255 : {
1256 11 : STRIP_ANY_LOCATION_WRAPPER (x);
1257 :
1258 11 : if (TREE_CODE (x) == COMPONENT_REF)
1259 11 : x = TREE_OPERAND (x, 1);
1260 :
1261 11 : return OVL_P (x);
1262 : }
1263 :
1264 : // forked from gcc/cp/tree.cc ovl_make
1265 :
1266 : /* Make a raw overload node containing FN. */
1267 :
1268 : tree
1269 0 : ovl_make (tree fn, tree next)
1270 : {
1271 0 : tree result = make_node (OVERLOAD);
1272 :
1273 0 : if (TREE_CODE (fn) == OVERLOAD)
1274 0 : OVL_NESTED_P (result) = true;
1275 :
1276 0 : TREE_TYPE (result) = (next ? unknown_type_node : TREE_TYPE (fn));
1277 0 : if (next && TREE_CODE (next) == OVERLOAD && OVL_DEDUP_P (next))
1278 0 : OVL_DEDUP_P (result) = true;
1279 0 : OVL_FUNCTION (result) = fn;
1280 0 : OVL_CHAIN (result) = next;
1281 0 : return result;
1282 : }
1283 :
1284 : // forked from gcc/cp/name-lookup.cc lookup_add
1285 :
1286 : /* Add a set of new FNS into a lookup. */
1287 :
1288 : tree
1289 0 : lookup_add (tree fns, tree lookup)
1290 : {
1291 0 : if (fns == error_mark_node || lookup == error_mark_node)
1292 0 : return error_mark_node;
1293 :
1294 0 : lookup = fns;
1295 :
1296 : return lookup;
1297 : }
1298 :
1299 : // forked from gcc/cp/typeck.cc type_memfn_quals
1300 :
1301 : /* Returns the function-cv-quals for TYPE, which must be a FUNCTION_TYPE or
1302 : METHOD_TYPE. */
1303 :
1304 : cv_qualifier
1305 0 : type_memfn_quals (const_tree type)
1306 : {
1307 0 : qualifier_set quals;
1308 0 : if (TREE_CODE (type) == FUNCTION_TYPE)
1309 0 : quals = TYPE_QUALS (type);
1310 0 : else if (TREE_CODE (type) == METHOD_TYPE)
1311 0 : quals = rs_type_quals (class_of_this_parm (type));
1312 : else
1313 0 : rust_unreachable ();
1314 :
1315 0 : addr_space_t as;
1316 0 : cv_qualifier cv;
1317 0 : std::tie (cv, as) = quals.split ();
1318 : /* These should never include an address space, at least for the time
1319 : being. */
1320 0 : gcc_checking_assert (ADDR_SPACE_GENERIC_P (as));
1321 0 : return cv;
1322 : }
1323 :
1324 : // forked from gcc/cp/pt.cc find_parameter_pack_data
1325 :
1326 : /* Structure used to track the progress of find_parameter_packs_r. */
1327 : struct find_parameter_pack_data
1328 : {
1329 : /* TREE_LIST that will contain all of the parameter packs found by
1330 : the traversal. */
1331 : tree *parameter_packs;
1332 :
1333 : /* Set of AST nodes that have been visited by the traversal. */
1334 : hash_set<tree> *visited;
1335 :
1336 : /* True iff we're making a type pack expansion. */
1337 : bool type_pack_expansion_p;
1338 :
1339 : /* True iff we found a subtree that has the extra args mechanism. */
1340 : bool found_extra_args_tree_p = false;
1341 : };
1342 :
1343 : // forked from gcc/cp/lex.cc conv_type_hasher
1344 :
1345 : /* Hasher for the conversion operator name hash table. */
1346 : struct rust_conv_type_hasher : ggc_ptr_hash<tree_node>
1347 : {
1348 : /* Hash NODE, an identifier node in the table. TYPE_UID is
1349 : suitable, as we're not concerned about matching canonicalness
1350 : here. */
1351 0 : static hashval_t hash (tree node)
1352 : {
1353 0 : return (hashval_t) TYPE_UID (TREE_TYPE (node));
1354 : }
1355 :
1356 : /* Compare NODE, an identifier node in the table, against TYPE, an
1357 : incoming TYPE being looked up. */
1358 0 : static bool equal (tree node, tree type) { return TREE_TYPE (node) == type; }
1359 : };
1360 :
1361 : static GTY (()) hash_table<rust_conv_type_hasher> *conv_type_names;
1362 :
1363 : // forked from gcc/cp/lex.cc make_conv_op_name
1364 :
1365 : /* Return an identifier for a conversion operator to TYPE. We can get
1366 : from the returned identifier to the type. We store TYPE, which is
1367 : not necessarily the canonical type, which allows us to report the
1368 : form the user used in error messages. All these identifiers are
1369 : not in the identifier hash table, and have the same string name.
1370 : These IDENTIFIERS are not in the identifier hash table, and all
1371 : have the same IDENTIFIER_STRING. */
1372 :
1373 : tree
1374 0 : make_conv_op_name (tree type)
1375 : {
1376 0 : if (type == error_mark_node)
1377 : return error_mark_node;
1378 :
1379 0 : if (conv_type_names == NULL)
1380 0 : conv_type_names = hash_table<rust_conv_type_hasher>::create_ggc (31);
1381 :
1382 0 : tree *slot
1383 0 : = conv_type_names->find_slot_with_hash (type, (hashval_t) TYPE_UID (type),
1384 : INSERT);
1385 0 : tree identifier = *slot;
1386 0 : if (!identifier)
1387 : {
1388 : /* Create a raw IDENTIFIER outside of the identifier hash
1389 : table. */
1390 0 : identifier = copy_node (conv_op_identifier);
1391 :
1392 : /* Just in case something managed to bind. */
1393 0 : IDENTIFIER_BINDING (identifier) = NULL;
1394 :
1395 : /* Hang TYPE off the identifier so it can be found easily later
1396 : when performing conversions. */
1397 0 : TREE_TYPE (identifier) = type;
1398 :
1399 0 : *slot = identifier;
1400 : }
1401 :
1402 : return identifier;
1403 : }
1404 :
1405 : // forked from gcc/cp/pt.cc builtin_pack_fn_p
1406 :
1407 : /* True iff FN is a function representing a built-in variadic parameter
1408 : pack. */
1409 :
1410 : bool
1411 0 : builtin_pack_fn_p (tree fn)
1412 : {
1413 0 : if (!fn || TREE_CODE (fn) != FUNCTION_DECL
1414 0 : || !DECL_IS_UNDECLARED_BUILTIN (fn))
1415 : return false;
1416 :
1417 0 : if (id_equal (DECL_NAME (fn), "__integer_pack"))
1418 : return true;
1419 :
1420 : return false;
1421 : }
1422 :
1423 : // forked from gcc/cp/pt.cc builtin_pack_call_p
1424 :
1425 : /* True iff CALL is a call to a function representing a built-in variadic
1426 : parameter pack. */
1427 :
1428 : static bool
1429 0 : builtin_pack_call_p (tree call)
1430 : {
1431 0 : if (TREE_CODE (call) != CALL_EXPR)
1432 : return false;
1433 0 : return builtin_pack_fn_p (CALL_EXPR_FN (call));
1434 : }
1435 :
1436 : //// forked from gcc/cp/pt.cc has_extra_args_mechanism_p
1437 : //
1438 : ///* Return true if the tree T has the extra args mechanism for
1439 : // avoiding partial instantiation. */
1440 : //
1441 : // static bool
1442 : // has_extra_args_mechanism_p (const_tree t)
1443 : //{
1444 : // return false;
1445 : //}
1446 :
1447 : // forked from gcc/cp/pt.cc find_parameter_packs_r
1448 :
1449 : /* Identifies all of the argument packs that occur in a template
1450 : argument and appends them to the TREE_LIST inside DATA, which is a
1451 : find_parameter_pack_data structure. This is a subroutine of
1452 : make_pack_expansion and uses_parameter_packs. */
1453 : static tree
1454 0 : find_parameter_packs_r (tree *tp, int *walk_subtrees, void *data)
1455 : {
1456 0 : tree t = *tp;
1457 0 : struct find_parameter_pack_data *ppd
1458 : = (struct find_parameter_pack_data *) data;
1459 0 : bool parameter_pack_p = false;
1460 :
1461 : #define WALK_SUBTREE(NODE) \
1462 : rs_walk_tree (&(NODE), &find_parameter_packs_r, ppd, ppd->visited)
1463 :
1464 : /* Don't look through typedefs; we are interested in whether a
1465 : parameter pack is actually written in the expression/type we're
1466 : looking at, not the target type. */
1467 0 : if (TYPE_P (t) && typedef_variant_p (t))
1468 : {
1469 0 : *walk_subtrees = 0;
1470 0 : return NULL_TREE;
1471 : }
1472 :
1473 : /* Identify whether this is a parameter pack or not. */
1474 0 : switch (TREE_CODE (t))
1475 : {
1476 : case FIELD_DECL:
1477 : case PARM_DECL:
1478 : break;
1479 :
1480 : case VAR_DECL:
1481 : break;
1482 :
1483 0 : case CALL_EXPR:
1484 0 : if (builtin_pack_call_p (t))
1485 : parameter_pack_p = true;
1486 : break;
1487 :
1488 : case BASES:
1489 : parameter_pack_p = true;
1490 : break;
1491 : default:
1492 : /* Not a parameter pack. */
1493 : break;
1494 : }
1495 :
1496 : if (parameter_pack_p)
1497 : {
1498 : /* Add this parameter pack to the list. */
1499 0 : *ppd->parameter_packs = tree_cons (NULL_TREE, t, *ppd->parameter_packs);
1500 : }
1501 :
1502 0 : if (TYPE_P (t))
1503 0 : rs_walk_tree (&TYPE_CONTEXT (t), &find_parameter_packs_r, ppd,
1504 : ppd->visited);
1505 :
1506 : /* This switch statement will return immediately if we don't find a
1507 : parameter pack. ??? Should some of these be in cp_walk_subtrees? */
1508 0 : switch (TREE_CODE (t))
1509 : {
1510 0 : case DECL_EXPR:
1511 0 : {
1512 0 : tree decl = DECL_EXPR_DECL (t);
1513 0 : if (is_typedef_decl (decl))
1514 : /* Since we stop at typedefs above, we need to look through them at
1515 : the point of the DECL_EXPR. */
1516 0 : rs_walk_tree (&DECL_ORIGINAL_TYPE (decl), &find_parameter_packs_r,
1517 : ppd, ppd->visited);
1518 : return NULL_TREE;
1519 : }
1520 :
1521 0 : case INTEGER_TYPE:
1522 0 : rs_walk_tree (&TYPE_MAX_VALUE (t), &find_parameter_packs_r, ppd,
1523 : ppd->visited);
1524 0 : *walk_subtrees = 0;
1525 0 : return NULL_TREE;
1526 :
1527 0 : case IDENTIFIER_NODE:
1528 0 : rs_walk_tree (&TREE_TYPE (t), &find_parameter_packs_r, ppd, ppd->visited);
1529 0 : *walk_subtrees = 0;
1530 0 : return NULL_TREE;
1531 :
1532 0 : case DECLTYPE_TYPE:
1533 0 : {
1534 : /* When traversing a DECLTYPE_TYPE_EXPR, we need to set
1535 : type_pack_expansion_p to false so that any placeholders
1536 : within the expression don't get marked as parameter packs. */
1537 0 : bool type_pack_expansion_p = ppd->type_pack_expansion_p;
1538 0 : ppd->type_pack_expansion_p = false;
1539 0 : rs_walk_tree (&DECLTYPE_TYPE_EXPR (t), &find_parameter_packs_r, ppd,
1540 : ppd->visited);
1541 0 : ppd->type_pack_expansion_p = type_pack_expansion_p;
1542 0 : *walk_subtrees = 0;
1543 0 : return NULL_TREE;
1544 : }
1545 :
1546 0 : case IF_STMT:
1547 0 : rs_walk_tree (&IF_COND (t), &find_parameter_packs_r, ppd, ppd->visited);
1548 0 : rs_walk_tree (&THEN_CLAUSE (t), &find_parameter_packs_r, ppd,
1549 : ppd->visited);
1550 0 : rs_walk_tree (&ELSE_CLAUSE (t), &find_parameter_packs_r, ppd,
1551 : ppd->visited);
1552 : /* Don't walk into IF_STMT_EXTRA_ARGS. */
1553 0 : *walk_subtrees = 0;
1554 0 : return NULL_TREE;
1555 :
1556 0 : case FUNCTION_TYPE:
1557 0 : case METHOD_TYPE:
1558 0 : WALK_SUBTREE (TYPE_RAISES_EXCEPTIONS (t));
1559 0 : break;
1560 :
1561 : default:
1562 : return NULL_TREE;
1563 : }
1564 :
1565 : #undef WALK_SUBTREE
1566 :
1567 0 : return NULL_TREE;
1568 : }
1569 :
1570 : // forked from gcc/cp/typeck.cc type_memfn_rqual
1571 :
1572 : /* Returns the function-ref-qualifier for TYPE */
1573 :
1574 : rs_ref_qualifier
1575 0 : type_memfn_rqual (const_tree type)
1576 : {
1577 0 : gcc_assert (FUNC_OR_METHOD_TYPE_P (type));
1578 :
1579 0 : if (!FUNCTION_REF_QUALIFIED (type))
1580 : return REF_QUAL_NONE;
1581 0 : else if (FUNCTION_RVALUE_QUALIFIED (type))
1582 : return REF_QUAL_RVALUE;
1583 : else
1584 0 : return REF_QUAL_LVALUE;
1585 : }
1586 :
1587 : // forked from gcc/cp/lex.cc maybe_add_lang_type_raw
1588 :
1589 : /* Add a raw lang_type to T, a type, should it need one. */
1590 :
1591 : bool
1592 0 : maybe_add_lang_type_raw (tree t)
1593 : {
1594 0 : if (!RECORD_OR_UNION_CODE_P (TREE_CODE (t)))
1595 : return false;
1596 :
1597 0 : auto *lt = (struct lang_type *) (ggc_internal_cleared_alloc (
1598 : sizeof (struct lang_type)));
1599 0 : TYPE_LANG_SPECIFIC (t) = lt;
1600 :
1601 0 : if (GATHER_STATISTICS)
1602 : {
1603 : tree_node_counts[(int) lang_type] += 1;
1604 : tree_node_sizes[(int) lang_type] += sizeof (struct lang_type);
1605 : }
1606 :
1607 0 : return true;
1608 : }
1609 :
1610 : // forked from gcc/c-family/c-lex.cc get_fileinfo
1611 :
1612 : static splay_tree file_info_tree;
1613 :
1614 : struct c_fileinfo *
1615 0 : get_fileinfo (const char *name)
1616 : {
1617 0 : splay_tree_node n;
1618 0 : struct c_fileinfo *fi;
1619 :
1620 0 : if (!file_info_tree)
1621 0 : file_info_tree = splay_tree_new (splay_tree_compare_strings, 0,
1622 : splay_tree_delete_pointers);
1623 :
1624 0 : n = splay_tree_lookup (file_info_tree, (splay_tree_key) name);
1625 0 : if (n)
1626 0 : return (struct c_fileinfo *) n->value;
1627 :
1628 0 : fi = XNEW (struct c_fileinfo);
1629 0 : fi->time = 0;
1630 0 : fi->interface_only = 0;
1631 0 : fi->interface_unknown = 1;
1632 0 : splay_tree_insert (file_info_tree, (splay_tree_key) name,
1633 : (splay_tree_value) fi);
1634 0 : return fi;
1635 : }
1636 :
1637 : // forked from gcc/cp/lex.cc cxx_make_type
1638 :
1639 : tree
1640 0 : cxx_make_type (enum tree_code code MEM_STAT_DECL)
1641 : {
1642 0 : tree t = make_node (code PASS_MEM_STAT);
1643 :
1644 0 : if (maybe_add_lang_type_raw (t))
1645 : {
1646 : /* Set up some flags that give proper default behavior. */
1647 0 : struct c_fileinfo *finfo = get_fileinfo (LOCATION_FILE (input_location));
1648 0 : SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, finfo->interface_unknown);
1649 0 : CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
1650 : }
1651 :
1652 0 : if (code == RECORD_TYPE || code == UNION_TYPE)
1653 0 : TYPE_CXX_ODR_P (t) = 1;
1654 :
1655 0 : return t;
1656 : }
1657 :
1658 : // forked from gcc/cp/tree.cc build_min_array_type
1659 :
1660 : /* Build an ARRAY_TYPE without laying it out. */
1661 :
1662 : static tree
1663 0 : build_min_array_type (tree elt_type, tree index_type)
1664 : {
1665 0 : tree t = cxx_make_type (ARRAY_TYPE);
1666 0 : TREE_TYPE (t) = elt_type;
1667 0 : TYPE_DOMAIN (t) = index_type;
1668 0 : return t;
1669 : }
1670 :
1671 : // forked from gcc/cp/name-lookup.cc resort_data
1672 :
1673 : } // namespace Rust
1674 :
1675 : static struct
1676 : {
1677 : gt_pointer_operator new_value;
1678 : void *cookie;
1679 : } resort_data;
1680 :
1681 : // forked from gcc/cp/name-lookup.cc resort_member_name_cmp
1682 :
1683 : /* This routine compares two fields like member_name_cmp but using the
1684 : pointer operator in resort_field_decl_data. We don't have to deal
1685 : with duplicates here. */
1686 :
1687 : static int
1688 0 : resort_member_name_cmp (const void *a_p, const void *b_p)
1689 : {
1690 0 : tree a = *(const tree *) a_p;
1691 0 : tree b = *(const tree *) b_p;
1692 0 : tree name_a = OVL_NAME (a);
1693 0 : tree name_b = OVL_NAME (b);
1694 :
1695 0 : resort_data.new_value (&name_a, &name_a, resort_data.cookie);
1696 0 : resort_data.new_value (&name_b, &name_b, resort_data.cookie);
1697 :
1698 0 : gcc_checking_assert (name_a != name_b);
1699 :
1700 0 : return name_a < name_b ? -1 : +1;
1701 : }
1702 :
1703 : // forked from gcc/cp/name-lookup.cc resort_type_member_vec
1704 :
1705 : /* Resort CLASSTYPE_MEMBER_VEC because pointers have been reordered. */
1706 :
1707 : void
1708 0 : resort_type_member_vec (void *obj, void * /*orig_obj*/,
1709 : gt_pointer_operator new_value, void *cookie)
1710 : {
1711 0 : if (vec<tree, va_gc> *member_vec = (vec<tree, va_gc> *) obj)
1712 : {
1713 0 : resort_data.new_value = new_value;
1714 0 : resort_data.cookie = cookie;
1715 0 : member_vec->qsort (resort_member_name_cmp);
1716 : }
1717 0 : }
1718 :
1719 : namespace Rust {
1720 :
1721 : // forked from gcc/cp/name-lookup.cc fields_linear_search
1722 :
1723 : /* Linear search of (partially ordered) fields of KLASS for NAME. */
1724 :
1725 : static tree
1726 0 : fields_linear_search (tree klass, tree name, bool want_type)
1727 : {
1728 0 : for (tree fields = TYPE_FIELDS (klass); fields; fields = DECL_CHAIN (fields))
1729 : {
1730 0 : tree decl = fields;
1731 :
1732 0 : if (DECL_NAME (decl) != name)
1733 0 : continue;
1734 :
1735 0 : if (DECL_DECLARES_FUNCTION_P (decl))
1736 : /* Functions are found separately. */
1737 0 : continue;
1738 :
1739 0 : if (!want_type || DECL_DECLARES_TYPE_P (decl))
1740 : return decl;
1741 : }
1742 :
1743 : return NULL_TREE;
1744 : }
1745 :
1746 : // forked from gcc/cp/except.cc canonnothrow_spec_pical_eh_spec
1747 :
1748 : /* Return true iff SPEC is throw() or noexcept(true). */
1749 :
1750 : bool
1751 0 : nothrow_spec_p (const_tree spec)
1752 : {
1753 0 : if (spec == empty_except_spec || spec == noexcept_true_spec)
1754 : return true;
1755 :
1756 0 : gcc_assert (!spec || TREE_VALUE (spec) || spec == noexcept_false_spec
1757 : || TREE_PURPOSE (spec) == error_mark_node);
1758 :
1759 : return false;
1760 : }
1761 :
1762 : // forked from gcc/cp/tree.cc may_get_fns
1763 :
1764 : /* Get the overload set FROM refers to. Returns NULL if it's not an
1765 : overload set. */
1766 :
1767 : tree
1768 0 : maybe_get_fns (tree from)
1769 : {
1770 0 : STRIP_ANY_LOCATION_WRAPPER (from);
1771 :
1772 : /* A baselink is also considered an overloaded function. */
1773 0 : if (TREE_CODE (from) == COMPONENT_REF)
1774 0 : from = TREE_OPERAND (from, 1);
1775 :
1776 0 : if (OVL_P (from))
1777 0 : return from;
1778 :
1779 : return NULL;
1780 : }
1781 :
1782 : // forked from gcc/cp/tree.cc get_fns
1783 :
1784 : /* FROM refers to an overload set. Return that set (or die). */
1785 :
1786 : tree
1787 0 : get_fns (tree from)
1788 : {
1789 0 : tree res = maybe_get_fns (from);
1790 :
1791 0 : gcc_assert (res);
1792 0 : return res;
1793 : }
1794 :
1795 : // forked from gcc/cp/tree.cc get_first_fn
1796 :
1797 : /* Return the first function of the overload set FROM refers to. */
1798 :
1799 : tree
1800 0 : get_first_fn (tree from)
1801 : {
1802 0 : return OVL_FIRST (get_fns (from));
1803 : }
1804 :
1805 : // forked from gcc/cp/tree.cc dependent_name
1806 :
1807 : /* X is the CALL_EXPR_FN of a CALL_EXPR. If X represents a dependent name
1808 : (14.6.2), return the IDENTIFIER_NODE for that name. Otherwise, return
1809 : NULL_TREE. */
1810 :
1811 : tree
1812 0 : dependent_name (tree x)
1813 : {
1814 : /* FIXME a dependent name must be unqualified, but this function doesn't
1815 : distinguish between qualified and unqualified identifiers. */
1816 0 : if (identifier_p (x))
1817 : return x;
1818 :
1819 0 : if (OVL_P (x))
1820 0 : return OVL_NAME (x);
1821 : return NULL_TREE;
1822 : }
1823 :
1824 : // forked from gcc/cp/tree.cc called_fns_equal
1825 :
1826 : /* Subroutine of rs_tree_equal: t1 and t2 are the CALL_EXPR_FNs of two
1827 : CALL_EXPRS. Return whether they are equivalent. */
1828 :
1829 : static bool
1830 0 : called_fns_equal (tree t1, tree t2)
1831 : {
1832 : /* Core 1321: dependent names are equivalent even if the overload sets
1833 : are different. But do compare explicit template arguments. */
1834 0 : tree name1 = dependent_name (t1);
1835 0 : tree name2 = dependent_name (t2);
1836 0 : if (name1 || name2)
1837 : {
1838 0 : tree targs1 = NULL_TREE, targs2 = NULL_TREE;
1839 :
1840 0 : if (name1 != name2)
1841 : return false;
1842 :
1843 : /* FIXME dependent_name currently returns an unqualified name regardless
1844 : of whether the function was named with a qualified- or unqualified-id.
1845 : Until that's fixed, check that we aren't looking at overload sets from
1846 : different scopes. */
1847 0 : if (is_overloaded_fn (t1) && is_overloaded_fn (t2)
1848 0 : && (DECL_CONTEXT (get_first_fn (t1))
1849 0 : != DECL_CONTEXT (get_first_fn (t2))))
1850 : return false;
1851 :
1852 0 : return rs_tree_equal (targs1, targs2);
1853 : }
1854 : else
1855 0 : return rs_tree_equal (t1, t2);
1856 : }
1857 :
1858 : // forked from gcc/cp/tree.cc canonical_eh_spec
1859 :
1860 : /* Return the canonical version of exception-specification RAISES for a C++17
1861 : function type, for use in type comparison and building TYPE_CANONICAL. */
1862 :
1863 : tree
1864 0 : canonical_eh_spec (tree raises)
1865 : {
1866 0 : if (raises == NULL_TREE)
1867 : return raises;
1868 0 : else if (nothrow_spec_p (raises))
1869 : /* throw() -> noexcept. */
1870 0 : return noexcept_true_spec;
1871 : else
1872 : /* For C++17 type matching, anything else -> nothing. */
1873 : return NULL_TREE;
1874 : }
1875 :
1876 : /* Like cp_tree_operand_length, but takes a tree_code CODE. */
1877 :
1878 : int
1879 0 : rs_tree_code_length (enum tree_code code)
1880 : {
1881 0 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
1882 :
1883 0 : switch (code)
1884 : {
1885 : case PREINCREMENT_EXPR:
1886 : case PREDECREMENT_EXPR:
1887 : case POSTINCREMENT_EXPR:
1888 : case POSTDECREMENT_EXPR:
1889 : return 1;
1890 :
1891 0 : case ARRAY_REF:
1892 0 : return 2;
1893 :
1894 0 : default:
1895 0 : return TREE_CODE_LENGTH (code);
1896 : }
1897 : }
1898 :
1899 : // forked from gcc/cp/tree.cc rs_tree_operand_length
1900 :
1901 : /* Return the number of operands in T that we care about for things like
1902 : mangling. */
1903 :
1904 : int
1905 0 : rs_tree_operand_length (const_tree t)
1906 : {
1907 0 : enum tree_code code = TREE_CODE (t);
1908 :
1909 0 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
1910 0 : return VL_EXP_OPERAND_LENGTH (t);
1911 :
1912 0 : return rs_tree_code_length (code);
1913 : }
1914 :
1915 : // forked from gcc/cp/tree.cc cp_tree_equal
1916 :
1917 : /* Return truthvalue of whether T1 is the same tree structure as T2.
1918 : Return 1 if they are the same. Return 0 if they are different. */
1919 :
1920 : bool
1921 0 : rs_tree_equal (tree t1, tree t2)
1922 : {
1923 0 : enum tree_code code1, code2;
1924 :
1925 0 : if (t1 == t2)
1926 : return true;
1927 0 : if (!t1 || !t2)
1928 : return false;
1929 :
1930 0 : code1 = TREE_CODE (t1);
1931 0 : code2 = TREE_CODE (t2);
1932 :
1933 0 : if (code1 != code2)
1934 : return false;
1935 :
1936 0 : if (CONSTANT_CLASS_P (t1) && !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
1937 : return false;
1938 :
1939 0 : switch (code1)
1940 : {
1941 0 : case VOID_CST:
1942 : /* There's only a single VOID_CST node, so we should never reach
1943 : here. */
1944 0 : rust_unreachable ();
1945 :
1946 0 : case INTEGER_CST:
1947 0 : return tree_int_cst_equal (t1, t2);
1948 :
1949 0 : case REAL_CST:
1950 0 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
1951 :
1952 0 : case STRING_CST:
1953 0 : return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
1954 0 : && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
1955 0 : TREE_STRING_LENGTH (t1));
1956 :
1957 0 : case FIXED_CST:
1958 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
1959 :
1960 0 : case COMPLEX_CST:
1961 0 : return rs_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
1962 0 : && rs_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
1963 :
1964 0 : case VECTOR_CST:
1965 0 : return operand_equal_p (t1, t2, OEP_ONLY_CONST);
1966 :
1967 0 : case CONSTRUCTOR:
1968 : /* We need to do this when determining whether or not two
1969 : non-type pointer to member function template arguments
1970 : are the same. */
1971 0 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
1972 0 : || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
1973 : return false;
1974 : {
1975 : tree field, value;
1976 : unsigned int i;
1977 0 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
1978 : {
1979 0 : constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
1980 0 : if (!rs_tree_equal (field, elt2->index)
1981 0 : || !rs_tree_equal (value, elt2->value))
1982 : return false;
1983 : }
1984 : }
1985 : return true;
1986 :
1987 0 : case TREE_LIST:
1988 0 : if (!rs_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
1989 : return false;
1990 0 : if (!rs_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
1991 : return false;
1992 0 : return rs_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
1993 :
1994 0 : case SAVE_EXPR:
1995 0 : return rs_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1996 :
1997 0 : case CALL_EXPR:
1998 0 : {
1999 0 : if (KOENIG_LOOKUP_P (t1) != KOENIG_LOOKUP_P (t2))
2000 : return false;
2001 :
2002 0 : if (!called_fns_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
2003 : return false;
2004 :
2005 0 : call_expr_arg_iterator iter1, iter2;
2006 0 : init_call_expr_arg_iterator (t1, &iter1);
2007 0 : init_call_expr_arg_iterator (t2, &iter2);
2008 0 : if (iter1.n != iter2.n)
2009 : return false;
2010 :
2011 0 : while (more_call_expr_args_p (&iter1))
2012 : {
2013 0 : tree arg1 = next_call_expr_arg (&iter1);
2014 0 : tree arg2 = next_call_expr_arg (&iter2);
2015 :
2016 0 : gcc_checking_assert (arg1 && arg2);
2017 0 : if (!rs_tree_equal (arg1, arg2))
2018 : return false;
2019 : }
2020 :
2021 : return true;
2022 : }
2023 :
2024 0 : case TARGET_EXPR:
2025 0 : {
2026 0 : tree o1 = TREE_OPERAND (t1, 0);
2027 0 : tree o2 = TREE_OPERAND (t2, 0);
2028 :
2029 : /* Special case: if either target is an unallocated VAR_DECL,
2030 : it means that it's going to be unified with whatever the
2031 : TARGET_EXPR is really supposed to initialize, so treat it
2032 : as being equivalent to anything. */
2033 0 : if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE && !DECL_RTL_SET_P (o1))
2034 : /*Nop*/;
2035 0 : else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
2036 0 : && !DECL_RTL_SET_P (o2))
2037 : /*Nop*/;
2038 0 : else if (!rs_tree_equal (o1, o2))
2039 : return false;
2040 :
2041 0 : return rs_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
2042 : }
2043 :
2044 0 : case PARM_DECL:
2045 : /* For comparing uses of parameters in late-specified return types
2046 : with an out-of-class definition of the function, but can also come
2047 : up for expressions that involve 'this' in a member function
2048 : template. */
2049 :
2050 0 : if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
2051 : {
2052 0 : if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2))
2053 : return false;
2054 0 : if (CONSTRAINT_VAR_P (t1) ^ CONSTRAINT_VAR_P (t2))
2055 : return false;
2056 0 : if (DECL_ARTIFICIAL (t1)
2057 0 : || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2)
2058 0 : && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)))
2059 : return true;
2060 : }
2061 : return false;
2062 :
2063 : case VAR_DECL:
2064 : case CONST_DECL:
2065 : case FIELD_DECL:
2066 : case FUNCTION_DECL:
2067 : case IDENTIFIER_NODE:
2068 : case SSA_NAME:
2069 : return false;
2070 :
2071 : case TREE_VEC:
2072 : return true;
2073 :
2074 0 : case NON_LVALUE_EXPR:
2075 0 : case VIEW_CONVERT_EXPR:
2076 : /* Used for location wrappers with possibly NULL types. */
2077 0 : if (!TREE_TYPE (t1) || !TREE_TYPE (t2))
2078 : {
2079 0 : if (TREE_TYPE (t1) || TREE_TYPE (t2))
2080 : return false;
2081 : break;
2082 : }
2083 :
2084 : default:
2085 : break;
2086 : }
2087 :
2088 0 : switch (TREE_CODE_CLASS (code1))
2089 : {
2090 0 : case tcc_unary:
2091 0 : case tcc_binary:
2092 0 : case tcc_comparison:
2093 0 : case tcc_expression:
2094 0 : case tcc_vl_exp:
2095 0 : case tcc_reference:
2096 0 : case tcc_statement:
2097 0 : {
2098 0 : int n = rs_tree_operand_length (t1);
2099 0 : if (TREE_CODE_CLASS (code1) == tcc_vl_exp
2100 0 : && n != TREE_OPERAND_LENGTH (t2))
2101 : return false;
2102 :
2103 0 : for (int i = 0; i < n; ++i)
2104 0 : if (!rs_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
2105 : return false;
2106 :
2107 : return true;
2108 : }
2109 :
2110 0 : case tcc_type:
2111 0 : return same_type_p (t1, t2);
2112 :
2113 0 : default:
2114 0 : rust_unreachable ();
2115 : }
2116 :
2117 : /* We can get here with --disable-checking. */
2118 : return false;
2119 : }
2120 :
2121 : // forked from gcc/cp/class.cc publicly_uniquely_derived_p
2122 :
2123 : /* TRUE iff TYPE is publicly & uniquely derived from PARENT. */
2124 :
2125 : bool
2126 0 : publicly_uniquely_derived_p (tree, tree)
2127 : {
2128 0 : return false;
2129 : }
2130 :
2131 : // forked from gcc/cp/typeck.cc comp_except_types
2132 :
2133 : /* Compare two exception specifier types for exactness or subsetness, if
2134 : allowed. Returns false for mismatch, true for match (same, or
2135 : derived and !exact).
2136 :
2137 : [except.spec] "If a class X ... objects of class X or any class publicly
2138 : and unambiguously derived from X. Similarly, if a pointer type Y * ...
2139 : exceptions of type Y * or that are pointers to any type publicly and
2140 : unambiguously derived from Y. Otherwise a function only allows exceptions
2141 : that have the same type ..."
2142 : This does not mention cv qualifiers and is different to what throw
2143 : [except.throw] and catch [except.catch] will do. They will ignore the
2144 : top level cv qualifiers, and allow qualifiers in the pointer to class
2145 : example.
2146 :
2147 : We implement the letter of the standard. */
2148 :
2149 : static bool
2150 0 : comp_except_types (tree a, tree b, bool exact)
2151 : {
2152 0 : if (same_type_p (a, b))
2153 : return true;
2154 0 : else if (!exact)
2155 : {
2156 0 : if (rs_type_quals (a) || rs_type_quals (b))
2157 : return false;
2158 :
2159 0 : if (TYPE_PTR_P (a) && TYPE_PTR_P (b))
2160 : {
2161 0 : a = TREE_TYPE (a);
2162 0 : b = TREE_TYPE (b);
2163 0 : if (rs_type_quals (a) || rs_type_quals (b))
2164 : return false;
2165 : }
2166 :
2167 0 : if (TREE_CODE (a) != RECORD_TYPE || TREE_CODE (b) != RECORD_TYPE)
2168 : return false;
2169 :
2170 0 : if (publicly_uniquely_derived_p (a, b))
2171 : return true;
2172 : }
2173 : return false;
2174 : }
2175 :
2176 : // forked from gcc/cp/typeck.cc comp_except_specs
2177 :
2178 : /* Return true if TYPE1 and TYPE2 are equivalent exception specifiers.
2179 : If EXACT is ce_derived, T2 can be stricter than T1 (according to 15.4/5).
2180 : If EXACT is ce_type, the C++17 type compatibility rules apply.
2181 : If EXACT is ce_normal, the compatibility rules in 15.4/3 apply.
2182 : If EXACT is ce_exact, the specs must be exactly the same. Exception lists
2183 : are unordered, but we've already filtered out duplicates. Most lists will
2184 : be in order, we should try to make use of that. */
2185 :
2186 : bool
2187 0 : comp_except_specs (const_tree t1, const_tree t2, int exact)
2188 : {
2189 0 : const_tree probe;
2190 0 : const_tree base;
2191 0 : int length = 0;
2192 :
2193 0 : if (t1 == t2)
2194 : return true;
2195 :
2196 : /* First handle noexcept. */
2197 0 : if (exact < ce_exact)
2198 : {
2199 0 : if (exact == ce_type
2200 0 : && (canonical_eh_spec (const_cast<tree> (t1))
2201 0 : == canonical_eh_spec (const_cast<tree> (t2))))
2202 : return true;
2203 :
2204 : /* noexcept(false) is compatible with no exception-specification,
2205 : and less strict than any spec. */
2206 0 : if (t1 == noexcept_false_spec)
2207 0 : return t2 == NULL_TREE || exact == ce_derived;
2208 : /* Even a derived noexcept(false) is compatible with no
2209 : exception-specification. */
2210 0 : if (t2 == noexcept_false_spec)
2211 0 : return t1 == NULL_TREE;
2212 :
2213 : /* Otherwise, if we aren't looking for an exact match, noexcept is
2214 : equivalent to throw(). */
2215 0 : if (t1 == noexcept_true_spec)
2216 0 : t1 = empty_except_spec;
2217 0 : if (t2 == noexcept_true_spec)
2218 0 : t2 = empty_except_spec;
2219 : }
2220 :
2221 : /* If any noexcept is left, it is only comparable to itself;
2222 : either we're looking for an exact match or we're redeclaring a
2223 : template with dependent noexcept. */
2224 0 : if ((t1 && TREE_PURPOSE (t1)) || (t2 && TREE_PURPOSE (t2)))
2225 0 : return (t1 && t2 && rs_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)));
2226 :
2227 0 : if (t1 == NULL_TREE) /* T1 is ... */
2228 0 : return t2 == NULL_TREE || exact == ce_derived;
2229 0 : if (!TREE_VALUE (t1)) /* t1 is EMPTY */
2230 0 : return t2 != NULL_TREE && !TREE_VALUE (t2);
2231 0 : if (t2 == NULL_TREE) /* T2 is ... */
2232 : return false;
2233 0 : if (TREE_VALUE (t1) && !TREE_VALUE (t2)) /* T2 is EMPTY, T1 is not */
2234 0 : return exact == ce_derived;
2235 :
2236 : /* Neither set is ... or EMPTY, make sure each part of T2 is in T1.
2237 : Count how many we find, to determine exactness. For exact matching and
2238 : ordered T1, T2, this is an O(n) operation, otherwise its worst case is
2239 : O(nm). */
2240 0 : for (base = t1; t2 != NULL_TREE; t2 = TREE_CHAIN (t2))
2241 : {
2242 0 : for (probe = base; probe != NULL_TREE; probe = TREE_CHAIN (probe))
2243 : {
2244 0 : tree a = TREE_VALUE (probe);
2245 0 : tree b = TREE_VALUE (t2);
2246 :
2247 0 : if (comp_except_types (a, b, exact))
2248 : {
2249 0 : if (probe == base && exact > ce_derived)
2250 0 : base = TREE_CHAIN (probe);
2251 0 : length++;
2252 0 : break;
2253 : }
2254 : }
2255 0 : if (probe == NULL_TREE)
2256 : return false;
2257 : }
2258 0 : return exact == ce_derived || base == NULL_TREE || length == list_length (t1);
2259 : }
2260 :
2261 : // forked from gcc/cp/typeck.cc compparms
2262 :
2263 : /* Subroutines of `comptypes'. */
2264 :
2265 : /* Return true if two parameter type lists PARMS1 and PARMS2 are
2266 : equivalent in the sense that functions with those parameter types
2267 : can have equivalent types. The two lists must be equivalent,
2268 : element by element. */
2269 :
2270 : bool
2271 0 : compparms (const_tree parms1, const_tree parms2)
2272 : {
2273 0 : const_tree t1, t2;
2274 :
2275 : /* An unspecified parmlist matches any specified parmlist
2276 : whose argument types don't need default promotions. */
2277 :
2278 0 : for (t1 = parms1, t2 = parms2; t1 || t2;
2279 0 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
2280 : {
2281 : /* If one parmlist is shorter than the other,
2282 : they fail to match. */
2283 0 : if (!t1 || !t2)
2284 : return false;
2285 0 : if (!same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
2286 : return false;
2287 : }
2288 : return true;
2289 : }
2290 :
2291 : /* Set TYPE_CANONICAL like build_array_type_1, but using
2292 : build_cplus_array_type. */
2293 :
2294 : static void
2295 0 : set_array_type_canon (tree t, tree elt_type, tree index_type, bool dep)
2296 : {
2297 : /* Set the canonical type for this new node. */
2298 0 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
2299 0 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
2300 0 : SET_TYPE_STRUCTURAL_EQUALITY (t);
2301 0 : else if (TYPE_CANONICAL (elt_type) != elt_type
2302 0 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
2303 0 : TYPE_CANONICAL (t)
2304 0 : = build_cplus_array_type (TYPE_CANONICAL (elt_type),
2305 0 : index_type ? TYPE_CANONICAL (index_type)
2306 : : index_type,
2307 : dep);
2308 : else
2309 0 : TYPE_CANONICAL (t) = t;
2310 0 : }
2311 :
2312 : // forked from gcc/cp/tree.cc cplus_array_info
2313 :
2314 : struct cplus_array_info
2315 : {
2316 : tree type;
2317 : tree domain;
2318 : };
2319 :
2320 : // forked from gcc/cp/tree.cc cplus_array_hasher
2321 :
2322 : struct rust_cplus_array_hasher : ggc_ptr_hash<tree_node>
2323 : {
2324 : typedef cplus_array_info *compare_type;
2325 :
2326 : static hashval_t hash (tree t);
2327 : static bool equal (tree, cplus_array_info *);
2328 : };
2329 :
2330 : /* Hash an ARRAY_TYPE. K is really of type `tree'. */
2331 :
2332 : hashval_t
2333 0 : rust_cplus_array_hasher::hash (tree t)
2334 : {
2335 0 : hashval_t hash;
2336 :
2337 0 : hash = TYPE_UID (TREE_TYPE (t));
2338 0 : if (TYPE_DOMAIN (t))
2339 0 : hash ^= TYPE_UID (TYPE_DOMAIN (t));
2340 0 : return hash;
2341 : }
2342 :
2343 : /* Compare two ARRAY_TYPEs. K1 is really of type `tree', K2 is really
2344 : of type `cplus_array_info*'. */
2345 :
2346 : bool
2347 0 : rust_cplus_array_hasher::equal (tree t1, cplus_array_info *t2)
2348 : {
2349 0 : return (TREE_TYPE (t1) == t2->type && TYPE_DOMAIN (t1) == t2->domain);
2350 : }
2351 :
2352 : // forked from gcc/cp/tree.cc cplus_array_htab
2353 :
2354 : /* Hash table containing dependent array types, which are unsuitable for
2355 : the language-independent type hash table. */
2356 : static GTY (()) hash_table<rust_cplus_array_hasher> *cplus_array_htab;
2357 :
2358 : // forked from gcc/cp/tree.cc is_byte_access_type
2359 :
2360 : /* Returns true if TYPE is char, unsigned char, or std::byte. */
2361 :
2362 : bool
2363 0 : is_byte_access_type (tree type)
2364 : {
2365 0 : type = TYPE_MAIN_VARIANT (type);
2366 0 : if (type == char_type_node || type == unsigned_char_type_node)
2367 : return true;
2368 :
2369 0 : return (TREE_CODE (type) == ENUMERAL_TYPE && TYPE_CONTEXT (type) == std_node
2370 0 : && !strcmp ("byte", TYPE_NAME_STRING (type)));
2371 : }
2372 :
2373 : // forked from gcc/cp/tree.cc build_cplus_array_type
2374 :
2375 : /* Like build_array_type, but handle special C++ semantics: an array of a
2376 : variant element type is a variant of the array of the main variant of
2377 : the element type. IS_DEPENDENT is -ve if we should determine the
2378 : dependency. Otherwise its bool value indicates dependency. */
2379 :
2380 : tree
2381 0 : build_cplus_array_type (tree elt_type, tree index_type, int dependent)
2382 : {
2383 0 : tree t;
2384 :
2385 0 : if (elt_type == error_mark_node || index_type == error_mark_node)
2386 : return error_mark_node;
2387 :
2388 0 : if (dependent < 0)
2389 : dependent = 0;
2390 :
2391 0 : if (elt_type != TYPE_MAIN_VARIANT (elt_type))
2392 : /* Start with an array of the TYPE_MAIN_VARIANT. */
2393 0 : t = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type), index_type,
2394 : dependent);
2395 0 : else if (dependent)
2396 : {
2397 : /* Since type_hash_canon calls layout_type, we need to use our own
2398 : hash table. */
2399 0 : cplus_array_info cai;
2400 0 : hashval_t hash;
2401 :
2402 0 : if (cplus_array_htab == NULL)
2403 0 : cplus_array_htab = hash_table<rust_cplus_array_hasher>::create_ggc (61);
2404 :
2405 0 : hash = TYPE_UID (elt_type);
2406 0 : if (index_type)
2407 0 : hash ^= TYPE_UID (index_type);
2408 0 : cai.type = elt_type;
2409 0 : cai.domain = index_type;
2410 :
2411 0 : tree *e = cplus_array_htab->find_slot_with_hash (&cai, hash, INSERT);
2412 0 : if (*e)
2413 : /* We have found the type: we're done. */
2414 0 : return (tree) *e;
2415 : else
2416 : {
2417 : /* Build a new array type. */
2418 0 : t = build_min_array_type (elt_type, index_type);
2419 :
2420 : /* Store it in the hash table. */
2421 0 : *e = t;
2422 :
2423 : /* Set the canonical type for this new node. */
2424 0 : set_array_type_canon (t, elt_type, index_type, dependent);
2425 :
2426 : /* Mark it as dependent now, this saves time later. */
2427 0 : TYPE_DEPENDENT_P_VALID (t) = true;
2428 0 : TYPE_DEPENDENT_P (t) = true;
2429 : }
2430 : }
2431 : else
2432 : {
2433 0 : bool typeless_storage = is_byte_access_type (elt_type);
2434 0 : t = build_array_type (elt_type, index_type, typeless_storage);
2435 :
2436 : /* Mark as non-dependenty now, this will save time later. */
2437 0 : TYPE_DEPENDENT_P_VALID (t) = true;
2438 : }
2439 :
2440 : /* Now check whether we already have this array variant. */
2441 0 : if (elt_type != TYPE_MAIN_VARIANT (elt_type))
2442 : {
2443 : tree m = t;
2444 0 : for (t = m; t; t = TYPE_NEXT_VARIANT (t))
2445 0 : if (TREE_TYPE (t) == elt_type && TYPE_NAME (t) == NULL_TREE
2446 0 : && TYPE_ATTRIBUTES (t) == NULL_TREE)
2447 : break;
2448 0 : if (!t)
2449 : {
2450 0 : t = build_min_array_type (elt_type, index_type);
2451 : /* Mark dependency now, this saves time later. */
2452 0 : TYPE_DEPENDENT_P_VALID (t) = true;
2453 0 : TYPE_DEPENDENT_P (t) = dependent;
2454 0 : set_array_type_canon (t, elt_type, index_type, dependent);
2455 0 : if (!dependent)
2456 : {
2457 0 : layout_type (t);
2458 : /* Make sure sizes are shared with the main variant.
2459 : layout_type can't be called after setting TYPE_NEXT_VARIANT,
2460 : as it will overwrite alignment etc. of all variants. */
2461 0 : TYPE_SIZE (t) = TYPE_SIZE (m);
2462 0 : TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (m);
2463 0 : TYPE_TYPELESS_STORAGE (t) = TYPE_TYPELESS_STORAGE (m);
2464 : }
2465 :
2466 0 : TYPE_MAIN_VARIANT (t) = m;
2467 0 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
2468 0 : TYPE_NEXT_VARIANT (m) = t;
2469 : }
2470 : }
2471 :
2472 : /* Avoid spurious warnings with VLAs (c++/54583). */
2473 0 : if (TYPE_SIZE (t) && EXPR_P (TYPE_SIZE (t)))
2474 0 : suppress_warning (TYPE_SIZE (t), OPT_Wunused);
2475 :
2476 : /* Push these needs up to the ARRAY_TYPE so that initialization takes
2477 : place more easily. */
2478 0 : bool needs_ctor
2479 0 : = (TYPE_NEEDS_CONSTRUCTING (t) = TYPE_NEEDS_CONSTRUCTING (elt_type));
2480 0 : bool needs_dtor = (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
2481 0 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type));
2482 :
2483 0 : if (!dependent && t == TYPE_MAIN_VARIANT (t) && !COMPLETE_TYPE_P (t)
2484 0 : && COMPLETE_TYPE_P (elt_type))
2485 : {
2486 : /* The element type has been completed since the last time we saw
2487 : this array type; update the layout and 'tor flags for any variants
2488 : that need it. */
2489 0 : layout_type (t);
2490 0 : for (tree v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
2491 : {
2492 0 : TYPE_NEEDS_CONSTRUCTING (v) = needs_ctor;
2493 0 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (v) = needs_dtor;
2494 : }
2495 : }
2496 :
2497 : return t;
2498 : }
2499 :
2500 : // forked from gcc/cp/tree.cc cp_build_qualified_type_real
2501 :
2502 : /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
2503 : arrays correctly. In particular, if TYPE is an array of T's, and
2504 : TYPE_QUALS is non-empty, returns an array of qualified T's.
2505 :
2506 : FLAGS determines how to deal with ill-formed qualifications. If
2507 : tf_ignore_bad_quals is set, then bad qualifications are dropped
2508 : (this is permitted if TYPE was introduced via a typedef or template
2509 : type parameter). If bad qualifications are dropped and tf_warning
2510 : is set, then a warning is issued for non-const qualifications. If
2511 : tf_ignore_bad_quals is not set and tf_error is not set, we
2512 : return error_mark_node. Otherwise, we issue an error, and ignore
2513 : the qualifications.
2514 :
2515 : Qualification of a reference type is valid when the reference came
2516 : via a typedef or template type argument. [dcl.ref] No such
2517 : dispensation is provided for qualifying a function type. [dcl.fct]
2518 : DR 295 queries this and the proposed resolution brings it into line
2519 : with qualifying a reference. We implement the DR. We also behave
2520 : in a similar manner for restricting non-pointer types. */
2521 :
2522 : tree
2523 153349 : rs_build_qualified_type_real (tree type, cv_qualifier type_quals,
2524 : tsubst_flags_t complain)
2525 : {
2526 153349 : tree result;
2527 153349 : auto bad_quals = TYPE_UNQUALIFIED;
2528 :
2529 153349 : if (type == error_mark_node)
2530 : return type;
2531 :
2532 153349 : if (type_quals == rs_type_quals (type))
2533 : return type;
2534 :
2535 76678 : if (TREE_CODE (type) == ARRAY_TYPE)
2536 : {
2537 : /* In C++, the qualification really applies to the array element
2538 : type. Obtain the appropriately qualified element type. */
2539 0 : tree t;
2540 0 : tree element_type
2541 0 : = rs_build_qualified_type_real (TREE_TYPE (type), type_quals, complain);
2542 :
2543 0 : if (element_type == error_mark_node)
2544 : return error_mark_node;
2545 :
2546 : /* See if we already have an identically qualified type. Tests
2547 : should be equivalent to those in check_qualified_type. */
2548 0 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
2549 0 : if (TREE_TYPE (t) == element_type && TYPE_NAME (t) == TYPE_NAME (type)
2550 0 : && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
2551 0 : && attribute_list_equal (TYPE_ATTRIBUTES (t),
2552 0 : TYPE_ATTRIBUTES (type)))
2553 : break;
2554 :
2555 0 : if (!t)
2556 : {
2557 : /* If we already know the dependentness, tell the array type
2558 : constructor. This is important for module streaming, as we cannot
2559 : dynamically determine that on read in. */
2560 0 : t = build_cplus_array_type (element_type, TYPE_DOMAIN (type),
2561 0 : TYPE_DEPENDENT_P_VALID (type)
2562 0 : ? int (TYPE_DEPENDENT_P (type))
2563 : : -1);
2564 :
2565 : /* Keep the typedef name. */
2566 0 : if (TYPE_NAME (t) != TYPE_NAME (type))
2567 : {
2568 0 : t = build_variant_type_copy (t);
2569 0 : TYPE_NAME (t) = TYPE_NAME (type);
2570 0 : SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
2571 0 : TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
2572 : }
2573 : }
2574 :
2575 : /* Even if we already had this variant, we update
2576 : TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
2577 : they changed since the variant was originally created.
2578 :
2579 : This seems hokey; if there is some way to use a previous
2580 : variant *without* coming through here,
2581 : TYPE_NEEDS_CONSTRUCTING will never be updated. */
2582 0 : TYPE_NEEDS_CONSTRUCTING (t)
2583 0 : = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
2584 0 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
2585 0 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
2586 0 : return t;
2587 : }
2588 :
2589 : /* A reference or method type shall not be cv-qualified.
2590 : [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295
2591 : (in CD1) we always ignore extra cv-quals on functions. */
2592 :
2593 : /* [dcl.ref/1] Cv-qualified references are ill-formed except when
2594 : the cv-qualifiers are introduced through the use of a typedef-name
2595 : ([dcl.typedef], [temp.param]) or decltype-specifier
2596 : ([dcl.type.decltype]),in which case the cv-qualifiers are
2597 : ignored. */
2598 76678 : if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
2599 76678 : && (TYPE_REF_P (type) || FUNC_OR_METHOD_TYPE_P (type)))
2600 : {
2601 0 : if (TYPE_REF_P (type)
2602 0 : && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type)))
2603 : bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
2604 0 : type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
2605 : }
2606 :
2607 : /* But preserve any function-cv-quals on a FUNCTION_TYPE. */
2608 76678 : if (TREE_CODE (type) == FUNCTION_TYPE)
2609 0 : type_quals |= type_memfn_quals (type);
2610 :
2611 : /* A restrict-qualified type must be a pointer (or reference)
2612 : to object or incomplete type. */
2613 76678 : if ((type_quals & TYPE_QUAL_RESTRICT) && TREE_CODE (type) != TYPENAME_TYPE
2614 76678 : && !INDIRECT_TYPE_P (type))
2615 : {
2616 0 : bad_quals |= TYPE_QUAL_RESTRICT;
2617 0 : type_quals &= ~TYPE_QUAL_RESTRICT;
2618 : }
2619 :
2620 76678 : if (bad_quals == TYPE_UNQUALIFIED || (complain & tf_ignore_bad_quals))
2621 : /*OK*/;
2622 0 : else if (!(complain & tf_error))
2623 0 : return error_mark_node;
2624 : else
2625 : {
2626 0 : tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
2627 0 : error ("%qV qualifiers cannot be applied to %qT", bad_type, type);
2628 : }
2629 :
2630 : /* Retrieve (or create) the appropriately qualified variant. */
2631 76678 : result = build_qualified_type (type, type_quals);
2632 :
2633 76678 : return result;
2634 : }
2635 :
2636 : // forked from gcc/cp/c-common.cc vector_targets_convertible_p
2637 :
2638 : /* vector_targets_convertible_p is used for vector pointer types. The
2639 : callers perform various checks that the qualifiers are satisfactory,
2640 : while OTOH vector_targets_convertible_p ignores the number of elements
2641 : in the vectors. That's fine with vector pointers as we can consider,
2642 : say, a vector of 8 elements as two consecutive vectors of 4 elements,
2643 : and that does not require and conversion of the pointer values.
2644 : In contrast, vector_types_convertible_p and
2645 : vector_types_compatible_elements_p are used for vector value types. */
2646 : /* True if pointers to distinct types T1 and T2 can be converted to
2647 : each other without an explicit cast. Only returns true for opaque
2648 : vector types. */
2649 : bool
2650 0 : vector_targets_convertible_p (const_tree t1, const_tree t2)
2651 : {
2652 0 : if (VECTOR_TYPE_P (t1) && VECTOR_TYPE_P (t2)
2653 0 : && (TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2))
2654 0 : && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)))
2655 : return true;
2656 :
2657 : return false;
2658 : }
2659 :
2660 : // forked from gcc/cp/typeck.cc comp_array_types
2661 :
2662 : /* Compare the array types T1 and T2. CB says how we should behave when
2663 : comparing array bounds: bounds_none doesn't allow dimensionless arrays,
2664 : bounds_either says than any array can be [], bounds_first means that
2665 : onlt T1 can be an array with unknown bounds. STRICT is true if
2666 : qualifiers must match when comparing the types of the array elements. */
2667 :
2668 : static bool
2669 0 : comp_array_types (const_tree t1, const_tree t2, compare_bounds_t cb,
2670 : bool strict)
2671 : {
2672 0 : tree d1;
2673 0 : tree d2;
2674 0 : tree max1, max2;
2675 :
2676 0 : if (t1 == t2)
2677 : return true;
2678 :
2679 : /* The type of the array elements must be the same. */
2680 0 : if (strict ? !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
2681 0 : : !similar_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
2682 : return false;
2683 :
2684 0 : d1 = TYPE_DOMAIN (t1);
2685 0 : d2 = TYPE_DOMAIN (t2);
2686 :
2687 0 : if (d1 == d2)
2688 : return true;
2689 :
2690 : /* If one of the arrays is dimensionless, and the other has a
2691 : dimension, they are of different types. However, it is valid to
2692 : write:
2693 :
2694 : extern int a[];
2695 : int a[3];
2696 :
2697 : by [basic.link]:
2698 :
2699 : declarations for an array object can specify
2700 : array types that differ by the presence or absence of a major
2701 : array bound (_dcl.array_). */
2702 0 : if (!d1 && d2)
2703 0 : return cb >= bounds_either;
2704 0 : else if (d1 && !d2)
2705 0 : return cb == bounds_either;
2706 :
2707 : /* Check that the dimensions are the same. */
2708 :
2709 0 : if (!rs_tree_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2)))
2710 : return false;
2711 0 : max1 = TYPE_MAX_VALUE (d1);
2712 0 : max2 = TYPE_MAX_VALUE (d2);
2713 :
2714 0 : if (!rs_tree_equal (max1, max2))
2715 : return false;
2716 :
2717 : return true;
2718 : }
2719 :
2720 : // forked from gcc/cp/typeck.cc same_type_ignoring_top_level_qualifiers_p
2721 :
2722 : /* Returns nonzero iff TYPE1 and TYPE2 are the same type, ignoring
2723 : top-level qualifiers. */
2724 :
2725 : bool
2726 76680 : same_type_ignoring_top_level_qualifiers_p (tree type1, tree type2)
2727 : {
2728 76680 : if (type1 == error_mark_node || type2 == error_mark_node)
2729 : return false;
2730 76680 : if (type1 == type2)
2731 : return true;
2732 :
2733 76664 : type1 = rs_build_qualified_type (type1, TYPE_UNQUALIFIED);
2734 76664 : type2 = rs_build_qualified_type (type2, TYPE_UNQUALIFIED);
2735 76664 : return same_type_p (type1, type2);
2736 : }
2737 :
2738 : // forked from gcc/cp/typeck.cc comp_ptr_ttypes_const
2739 :
2740 : /* Return true if TO and FROM (both of which are POINTER_TYPEs or
2741 : pointer-to-member types) are the same, ignoring cv-qualification at
2742 : all levels. CB says how we should behave when comparing array bounds. */
2743 :
2744 : bool
2745 0 : comp_ptr_ttypes_const (tree to, tree from, compare_bounds_t cb)
2746 : {
2747 0 : bool is_opaque_pointer = false;
2748 :
2749 0 : for (;; to = TREE_TYPE (to), from = TREE_TYPE (from))
2750 : {
2751 0 : if (TREE_CODE (to) != TREE_CODE (from))
2752 : return false;
2753 :
2754 0 : if (TREE_CODE (from) == OFFSET_TYPE
2755 0 : && same_type_p (TYPE_OFFSET_BASETYPE (from),
2756 : TYPE_OFFSET_BASETYPE (to)))
2757 0 : continue;
2758 :
2759 0 : if (VECTOR_TYPE_P (to))
2760 0 : is_opaque_pointer = vector_targets_convertible_p (to, from);
2761 :
2762 0 : if (TREE_CODE (to) == ARRAY_TYPE
2763 : /* Ignore cv-qualification, but if we see e.g. int[3] and int[4],
2764 : we must fail. */
2765 0 : && !comp_array_types (to, from, cb, /*strict=*/false))
2766 : return false;
2767 :
2768 : /* CWG 330 says we need to look through arrays. */
2769 0 : if (!TYPE_PTR_P (to) && TREE_CODE (to) != ARRAY_TYPE)
2770 0 : return (is_opaque_pointer
2771 0 : || same_type_ignoring_top_level_qualifiers_p (to, from));
2772 : }
2773 : }
2774 :
2775 : // forked from gcc/cp/typeck.cc similar_type_p
2776 :
2777 : /* Returns nonzero iff TYPE1 and TYPE2 are similar, as per [conv.qual]. */
2778 :
2779 : bool
2780 3 : similar_type_p (tree type1, tree type2)
2781 : {
2782 3 : if (type1 == error_mark_node || type2 == error_mark_node)
2783 : return false;
2784 :
2785 : /* Informally, two types are similar if, ignoring top-level cv-qualification:
2786 : * they are the same type; or
2787 : * they are both pointers, and the pointed-to types are similar; or
2788 : * they are both pointers to member of the same class, and the types of
2789 : the pointed-to members are similar; or
2790 : * they are both arrays of the same size or both arrays of unknown bound,
2791 : and the array element types are similar. */
2792 :
2793 3 : if (same_type_ignoring_top_level_qualifiers_p (type1, type2))
2794 : return true;
2795 :
2796 0 : if ((TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
2797 0 : || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
2798 0 : || (TREE_CODE (type1) == ARRAY_TYPE && TREE_CODE (type2) == ARRAY_TYPE))
2799 0 : return comp_ptr_ttypes_const (type1, type2, bounds_either);
2800 :
2801 : return false;
2802 : }
2803 :
2804 : // forked from gcc/cp/typeck.cc structural_comptypes
2805 : // note: this fork only handles strict == COMPARE_STRICT
2806 : // if you pass in any other value for strict i.e. COMPARE_BASE,
2807 : // COMPARE_DERIVED, COMPARE_REDECLARATION or COMPARE_STRUCTURAL
2808 : // see the original function in gcc/cp/typeck.cc and port the required bits
2809 : // specifically under case UNION_TYPE.
2810 :
2811 : /* Subroutine in comptypes. */
2812 :
2813 : static bool
2814 23 : structural_comptypes (tree t1, tree t2, int strict)
2815 : {
2816 : /* Both should be types that are not obviously the same. */
2817 23 : gcc_checking_assert (t1 != t2 && TYPE_P (t1) && TYPE_P (t2));
2818 :
2819 23 : if (TYPE_PTRMEMFUNC_P (t1))
2820 0 : t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
2821 23 : if (TYPE_PTRMEMFUNC_P (t2))
2822 0 : t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
2823 :
2824 : /* Different classes of types can't be compatible. */
2825 23 : if (TREE_CODE (t1) != TREE_CODE (t2))
2826 : return false;
2827 :
2828 : /* Qualifiers must match. For array types, we will check when we
2829 : recur on the array element types. */
2830 23 : if (TREE_CODE (t1) != ARRAY_TYPE && rs_type_quals (t1) != rs_type_quals (t2))
2831 : return false;
2832 4 : if (TREE_CODE (t1) == FUNCTION_TYPE
2833 4 : && type_memfn_quals (t1) != type_memfn_quals (t2))
2834 : return false;
2835 : /* Need to check this before TYPE_MAIN_VARIANT.
2836 : FIXME function qualifiers should really change the main variant. */
2837 4 : if (FUNC_OR_METHOD_TYPE_P (t1))
2838 : {
2839 0 : if (type_memfn_rqual (t1) != type_memfn_rqual (t2))
2840 : return false;
2841 0 : if (/* cxx_dialect >= cxx17 && */
2842 0 : !comp_except_specs (TYPE_RAISES_EXCEPTIONS (t1),
2843 0 : TYPE_RAISES_EXCEPTIONS (t2), ce_type))
2844 : return false;
2845 : }
2846 :
2847 : /* Allow for two different type nodes which have essentially the same
2848 : definition. Note that we already checked for equality of the type
2849 : qualifiers (just above). */
2850 4 : if (TREE_CODE (t1) != ARRAY_TYPE
2851 4 : && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
2852 : return true;
2853 :
2854 : /* Compare the types. Return false on known not-same. Break on not
2855 : known. Never return true from this switch -- you'll break
2856 : specialization comparison. */
2857 1 : switch (TREE_CODE (t1))
2858 : {
2859 : case VOID_TYPE:
2860 : case BOOLEAN_TYPE:
2861 : /* All void and bool types are the same. */
2862 : break;
2863 :
2864 1 : case OPAQUE_TYPE:
2865 1 : case INTEGER_TYPE:
2866 1 : case FIXED_POINT_TYPE:
2867 1 : case REAL_TYPE:
2868 : /* With these nodes, we can't determine type equivalence by
2869 : looking at what is stored in the nodes themselves, because
2870 : two nodes might have different TYPE_MAIN_VARIANTs but still
2871 : represent the same type. For example, wchar_t and int could
2872 : have the same properties (TYPE_PRECISION, TYPE_MIN_VALUE,
2873 : TYPE_MAX_VALUE, etc.), but have different TYPE_MAIN_VARIANTs
2874 : and are distinct types. On the other hand, int and the
2875 : following typedef
2876 :
2877 : typedef int INT __attribute((may_alias));
2878 :
2879 : have identical properties, different TYPE_MAIN_VARIANTs, but
2880 : represent the same type. The canonical type system keeps
2881 : track of equivalence in this case, so we fall back on it. */
2882 1 : if (TYPE_CANONICAL (t1) != TYPE_CANONICAL (t2))
2883 1 : return false;
2884 :
2885 : /* We don't need or want the attribute comparison. */
2886 : return true;
2887 :
2888 : case RECORD_TYPE:
2889 : case UNION_TYPE:
2890 : return false;
2891 :
2892 0 : case OFFSET_TYPE:
2893 0 : if (!comptypes (TYPE_OFFSET_BASETYPE (t1), TYPE_OFFSET_BASETYPE (t2),
2894 : strict & ~COMPARE_REDECLARATION))
2895 : return false;
2896 0 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
2897 : return false;
2898 : break;
2899 :
2900 0 : case REFERENCE_TYPE:
2901 0 : if (TYPE_REF_IS_RVALUE (t1) != TYPE_REF_IS_RVALUE (t2))
2902 : return false;
2903 : /* fall through to checks for pointer types */
2904 0 : gcc_fallthrough ();
2905 :
2906 0 : case POINTER_TYPE:
2907 0 : if (TYPE_MODE (t1) != TYPE_MODE (t2)
2908 0 : || !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
2909 : return false;
2910 : break;
2911 :
2912 0 : case METHOD_TYPE:
2913 0 : case FUNCTION_TYPE:
2914 : /* Exception specs and memfn_rquals were checked above. */
2915 0 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
2916 : return false;
2917 0 : if (!compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2)))
2918 : return false;
2919 : break;
2920 :
2921 0 : case ARRAY_TYPE:
2922 : /* Target types must match incl. qualifiers. */
2923 0 : if (!comp_array_types (t1, t2,
2924 0 : ((strict & COMPARE_REDECLARATION) ? bounds_either
2925 : : bounds_none),
2926 : /*strict=*/true))
2927 : return false;
2928 : break;
2929 :
2930 0 : case COMPLEX_TYPE:
2931 0 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
2932 : return false;
2933 : break;
2934 :
2935 0 : case VECTOR_TYPE:
2936 0 : if (gnu_vector_type_p (t1) != gnu_vector_type_p (t2)
2937 0 : || maybe_ne (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
2938 0 : || !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
2939 : return false;
2940 : break;
2941 :
2942 : default:
2943 : return false;
2944 : }
2945 :
2946 : /* If we get here, we know that from a target independent POV the
2947 : types are the same. Make sure the target attributes are also
2948 : the same. */
2949 0 : if (!comp_type_attributes (t1, t2))
2950 0 : return false;
2951 :
2952 : return true;
2953 : }
2954 :
2955 : // forked from gcc/cp/typeck.cc comptypes
2956 :
2957 : /* Return true if T1 and T2 are related as allowed by STRICT. STRICT
2958 : is a bitwise-or of the COMPARE_* flags. */
2959 :
2960 : bool
2961 229915 : comptypes (tree t1, tree t2, int strict)
2962 : {
2963 229915 : gcc_checking_assert (t1 && t2);
2964 :
2965 : /* TYPE_ARGUMENT_PACKS are not really types. */
2966 229915 : gcc_checking_assert (TREE_CODE (t1) != TYPE_ARGUMENT_PACK
2967 : && TREE_CODE (t2) != TYPE_ARGUMENT_PACK);
2968 :
2969 229915 : if (t1 == t2)
2970 : return true;
2971 :
2972 : /* Suppress errors caused by previously reported errors. */
2973 23 : if (t1 == error_mark_node || t2 == error_mark_node)
2974 : return false;
2975 :
2976 23 : if (strict == COMPARE_STRICT)
2977 : {
2978 23 : if (TYPE_STRUCTURAL_EQUALITY_P (t1) || TYPE_STRUCTURAL_EQUALITY_P (t2))
2979 : /* At least one of the types requires structural equality, so
2980 : perform a deep check. */
2981 5 : return structural_comptypes (t1, t2, strict);
2982 :
2983 18 : if (!flag_checking)
2984 0 : return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
2985 : else
2986 18 : return structural_comptypes (t1, t2, strict);
2987 : }
2988 0 : else if (strict == COMPARE_STRUCTURAL)
2989 0 : return structural_comptypes (t1, t2, COMPARE_STRICT);
2990 : else
2991 0 : return structural_comptypes (t1, t2, strict);
2992 : }
2993 :
2994 : // forked from gcc/cp/decl.cc next_initializable_field
2995 :
2996 : /* FIELD is an element of TYPE_FIELDS or NULL. In the former case, the value
2997 : returned is the next FIELD_DECL (possibly FIELD itself) that can be
2998 : initialized. If there are no more such fields, the return value
2999 : will be NULL. */
3000 :
3001 : tree
3002 0 : next_initializable_field (tree field)
3003 : {
3004 0 : while (field
3005 0 : && (TREE_CODE (field) != FIELD_DECL || DECL_UNNAMED_BIT_FIELD (field)
3006 0 : || (DECL_ARTIFICIAL (field)
3007 : /* Don't skip vptr fields. We might see them when we're
3008 : called from reduced_constant_expression_p. */
3009 0 : && !DECL_VIRTUAL_P (field))))
3010 0 : field = DECL_CHAIN (field);
3011 :
3012 0 : return field;
3013 : }
3014 :
3015 : // forked from gcc/cp/call.cc sufficient_parms_p
3016 :
3017 : /* Returns nonzero if PARMLIST consists of only default parms,
3018 : ellipsis, and/or undeduced parameter packs. */
3019 :
3020 : bool
3021 0 : sufficient_parms_p (const_tree parmlist)
3022 : {
3023 0 : for (; parmlist && parmlist != void_list_node;
3024 0 : parmlist = TREE_CHAIN (parmlist))
3025 0 : if (!TREE_PURPOSE (parmlist))
3026 : return false;
3027 : return true;
3028 : }
3029 :
3030 : // forked from gcc/cp/class.cc default_ctor_p
3031 :
3032 : /* Returns true if FN is a default constructor. */
3033 :
3034 : bool
3035 0 : default_ctor_p (const_tree fn)
3036 : {
3037 0 : return (DECL_CONSTRUCTOR_P (fn)
3038 0 : && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
3039 : }
3040 :
3041 : // forked from gcc/cp/class.cc user_provided_p
3042 :
3043 : /* Returns true iff FN is a user-provided function, i.e. user-declared
3044 : and not defaulted at its first declaration. */
3045 :
3046 : bool
3047 0 : user_provided_p (tree fn)
3048 : {
3049 0 : return (!DECL_ARTIFICIAL (fn)
3050 0 : && !(DECL_INITIALIZED_IN_CLASS_P (fn)
3051 0 : && (DECL_DEFAULTED_FN (fn) || DECL_DELETED_FN (fn))));
3052 : }
3053 :
3054 : // forked from gcc/cp/class.cc type_has_non_user_provided_default_constructor
3055 :
3056 : /* Returns true iff class T has a non-user-provided (i.e. implicitly
3057 : declared or explicitly defaulted in the class body) default
3058 : constructor. */
3059 :
3060 : bool
3061 0 : type_has_non_user_provided_default_constructor (tree t)
3062 : {
3063 0 : if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (t))
3064 : return false;
3065 0 : if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
3066 : return true;
3067 :
3068 0 : for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
3069 : {
3070 0 : tree fn = *iter;
3071 0 : if (TREE_CODE (fn) == FUNCTION_DECL && default_ctor_p (fn)
3072 0 : && !user_provided_p (fn))
3073 0 : return true;
3074 : }
3075 :
3076 0 : return false;
3077 : }
3078 :
3079 : // forked from gcc/cp/class.cc default_init_uninitialized_part
3080 :
3081 : /* If default-initialization leaves part of TYPE uninitialized, returns
3082 : a DECL for the field or TYPE itself (DR 253). */
3083 :
3084 : tree
3085 0 : default_init_uninitialized_part (tree type)
3086 : {
3087 0 : tree t, r, binfo;
3088 0 : int i;
3089 :
3090 0 : type = strip_array_types (type);
3091 0 : if (!CLASS_TYPE_P (type))
3092 : return type;
3093 0 : if (!type_has_non_user_provided_default_constructor (type))
3094 : return NULL_TREE;
3095 0 : for (binfo = TYPE_BINFO (type), i = 0; BINFO_BASE_ITERATE (binfo, i, t); ++i)
3096 : {
3097 0 : r = default_init_uninitialized_part (BINFO_TYPE (t));
3098 0 : if (r)
3099 : return r;
3100 : }
3101 0 : for (t = next_initializable_field (TYPE_FIELDS (type)); t;
3102 0 : t = next_initializable_field (DECL_CHAIN (t)))
3103 0 : if (!DECL_INITIAL (t) && !DECL_ARTIFICIAL (t))
3104 : {
3105 0 : r = default_init_uninitialized_part (TREE_TYPE (t));
3106 0 : if (r)
3107 0 : return DECL_P (r) ? r : t;
3108 : }
3109 :
3110 : return NULL_TREE;
3111 : }
3112 :
3113 : // forked from gcc/cp/name-lookup.cc extract_conversion_operator
3114 :
3115 : /* FNS is an overload set of conversion functions. Return the
3116 : overloads converting to TYPE. */
3117 :
3118 : static tree
3119 0 : extract_conversion_operator (tree fns, tree type)
3120 : {
3121 0 : tree convs = NULL_TREE;
3122 0 : tree tpls = NULL_TREE;
3123 :
3124 0 : for (ovl_iterator iter (fns); iter; ++iter)
3125 : {
3126 0 : if (same_type_p (DECL_CONV_FN_TYPE (*iter), type))
3127 0 : convs = lookup_add (*iter, convs);
3128 : }
3129 :
3130 0 : if (!convs)
3131 0 : convs = tpls;
3132 :
3133 0 : return convs;
3134 : }
3135 :
3136 : // forked from gcc/cp/name-lookup.cc
3137 :
3138 : /* Look for NAME as an immediate member of KLASS (including
3139 : anon-members or unscoped enum member). TYPE_OR_FNS is zero for
3140 : regular search. >0 to get a type binding (if there is one) and <0
3141 : if you want (just) the member function binding.
3142 :
3143 : Use this if you do not want lazy member creation. */
3144 :
3145 : tree
3146 0 : get_class_binding_direct (tree klass, tree name, bool want_type)
3147 : {
3148 0 : gcc_checking_assert (RECORD_OR_UNION_TYPE_P (klass));
3149 :
3150 : /* Conversion operators can only be found by the marker conversion
3151 : operator name. */
3152 0 : bool conv_op = IDENTIFIER_CONV_OP_P (name);
3153 0 : tree lookup = conv_op ? conv_op_identifier : name;
3154 0 : tree val = NULL_TREE;
3155 0 : vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (klass);
3156 :
3157 0 : if (COMPLETE_TYPE_P (klass) && member_vec)
3158 : {
3159 0 : val = member_vec_binary_search (member_vec, lookup);
3160 0 : if (!val)
3161 : ;
3162 0 : else if (STAT_HACK_P (val))
3163 0 : val = want_type ? STAT_TYPE (val) : STAT_DECL (val);
3164 0 : else if (want_type && !DECL_DECLARES_TYPE_P (val))
3165 0 : val = NULL_TREE;
3166 : }
3167 : else
3168 : {
3169 0 : if (member_vec && !want_type)
3170 0 : val = member_vec_linear_search (member_vec, lookup);
3171 :
3172 0 : if (!val || (TREE_CODE (val) == OVERLOAD && OVL_DEDUP_P (val)))
3173 : /* Dependent using declarations are a 'field', make sure we
3174 : return that even if we saw an overload already. */
3175 0 : if (tree field_val = fields_linear_search (klass, lookup, want_type))
3176 : {
3177 0 : if (!val)
3178 : val = field_val;
3179 0 : else if (TREE_CODE (field_val) == USING_DECL)
3180 0 : val = ovl_make (field_val, val);
3181 : }
3182 : }
3183 :
3184 : /* Extract the conversion operators asked for, unless the general
3185 : conversion operator was requested. */
3186 0 : if (val && conv_op)
3187 : {
3188 0 : gcc_checking_assert (OVL_FUNCTION (val) == conv_op_marker);
3189 0 : val = OVL_CHAIN (val);
3190 0 : if (tree type = TREE_TYPE (name))
3191 0 : val = extract_conversion_operator (val, type);
3192 : }
3193 :
3194 0 : return val;
3195 : }
3196 :
3197 : #if defined ENABLE_TREE_CHECKING
3198 :
3199 : // forked from gcc/cp/tree.cc lang_check_failed
3200 :
3201 : /* Complain that some language-specific thing hanging off a tree
3202 : node has been accessed improperly. */
3203 :
3204 : void
3205 0 : lang_check_failed (const char *file, int line, const char *function)
3206 : {
3207 0 : internal_error ("%<lang_*%> check: failed in %s, at %s:%d", function,
3208 : trim_filename (file), line);
3209 : }
3210 : #endif /* ENABLE_TREE_CHECKING */
3211 :
3212 : // forked from gcc/cp/tree.cc skip_artificial_parms_for
3213 :
3214 : /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
3215 : as there are artificial parms in FN. */
3216 :
3217 : tree
3218 0 : skip_artificial_parms_for (const_tree fn, tree list)
3219 : {
3220 0 : if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
3221 0 : list = TREE_CHAIN (list);
3222 : else
3223 : return list;
3224 :
3225 0 : if (DECL_HAS_IN_CHARGE_PARM_P (fn))
3226 0 : list = TREE_CHAIN (list);
3227 0 : if (DECL_HAS_VTT_PARM_P (fn))
3228 0 : list = TREE_CHAIN (list);
3229 : return list;
3230 : }
3231 :
3232 : // forked from gcc/cp/class.cc in_class_defaulted_default_constructor
3233 :
3234 : /* Returns the defaulted constructor if T has one. Otherwise, returns
3235 : NULL_TREE. */
3236 :
3237 : tree
3238 0 : in_class_defaulted_default_constructor (tree t)
3239 : {
3240 0 : if (!TYPE_HAS_USER_CONSTRUCTOR (t))
3241 : return NULL_TREE;
3242 :
3243 0 : for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
3244 : {
3245 0 : tree fn = *iter;
3246 :
3247 0 : if (DECL_DEFAULTED_IN_CLASS_P (fn) && default_ctor_p (fn))
3248 0 : return fn;
3249 : }
3250 :
3251 0 : return NULL_TREE;
3252 : }
3253 :
3254 : // forked from gcc/cp/constexpr.cc
3255 :
3256 : /* Returns true iff FUN is an instantiation of a constexpr function
3257 : template or a defaulted constexpr function. */
3258 :
3259 : bool
3260 0 : is_instantiation_of_constexpr (tree fun)
3261 : {
3262 0 : return ((DECL_DEFAULTED_FN (fun) && DECL_DECLARED_CONSTEXPR_P (fun)));
3263 : }
3264 :
3265 : // forked from gcc/cp/decl.cc check_for_uninitialized_const_var
3266 :
3267 : /* Issue an error message if DECL is an uninitialized const variable.
3268 : CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
3269 : context from potential_constant_expression. Returns true if all is well,
3270 : false otherwise. */
3271 :
3272 : bool
3273 0 : check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
3274 : tsubst_flags_t complain)
3275 : {
3276 0 : tree type = strip_array_types (TREE_TYPE (decl));
3277 :
3278 : /* ``Unless explicitly declared extern, a const object does not have
3279 : external linkage and must be initialized. ($8.4; $12.1)'' ARM
3280 : 7.1.6 */
3281 0 : if (VAR_P (decl) && !TYPE_REF_P (type) && (RS_TYPE_CONST_P (type))
3282 0 : && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
3283 : {
3284 0 : tree field = default_init_uninitialized_part (type);
3285 0 : if (!field)
3286 : return true;
3287 :
3288 0 : bool show_notes = true;
3289 :
3290 0 : if (!constexpr_context_p)
3291 : {
3292 0 : if (RS_TYPE_CONST_P (type))
3293 : {
3294 0 : if (complain & tf_error)
3295 0 : show_notes = permerror (DECL_SOURCE_LOCATION (decl),
3296 : "uninitialized %<const %D%>", decl);
3297 : }
3298 : else
3299 : {
3300 0 : if (!is_instantiation_of_constexpr (current_function_decl)
3301 0 : && (complain & tf_error))
3302 0 : error_at (DECL_SOURCE_LOCATION (decl),
3303 : "uninitialized variable %qD in %<constexpr%> "
3304 : "function",
3305 : decl);
3306 : else
3307 : show_notes = false;
3308 : }
3309 : }
3310 0 : else if (complain & tf_error)
3311 0 : error_at (DECL_SOURCE_LOCATION (decl),
3312 : "uninitialized variable %qD in %<constexpr%> context", decl);
3313 :
3314 0 : if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
3315 : {
3316 : // tree defaulted_ctor;
3317 :
3318 : // inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
3319 : // "%q#T has no user-provided default constructor", type);
3320 : // defaulted_ctor = in_class_defaulted_default_constructor (type);
3321 : // if (defaulted_ctor)
3322 : // inform (DECL_SOURCE_LOCATION (defaulted_ctor),
3323 : // "constructor is not user-provided because it is "
3324 : // "explicitly defaulted in the class body");
3325 : // inform (DECL_SOURCE_LOCATION (field),
3326 : // "and the implicitly-defined constructor does not "
3327 : // "initialize %q#D",
3328 : // field);
3329 : }
3330 :
3331 : return false;
3332 : }
3333 :
3334 : return true;
3335 : }
3336 :
3337 : // forked from gcc/cp/tree.cc cv_unqualified
3338 :
3339 : /* Return TYPE with const and volatile removed. */
3340 :
3341 : tree
3342 21 : cv_unqualified (tree type)
3343 : {
3344 21 : if (type == error_mark_node)
3345 : return type;
3346 :
3347 21 : auto quals = rs_type_quals (type);
3348 21 : quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
3349 21 : return rs_build_qualified_type (type, quals);
3350 : }
3351 :
3352 : /* The C and C++ parsers both use vectors to hold function arguments.
3353 : For efficiency, we keep a cache of unused vectors. This is the
3354 : cache. */
3355 :
3356 : typedef vec<tree, va_gc> *tree_gc_vec;
3357 : static GTY ((deletable)) vec<tree_gc_vec, va_gc> *tree_vector_cache;
3358 :
3359 : // forked from gcc/c-family/c-common.c make_tree_vector
3360 :
3361 : /* Return a new vector from the cache. If the cache is empty,
3362 : allocate a new vector. These vectors are GC'ed, so it is OK if the
3363 : pointer is not released.. */
3364 :
3365 : vec<tree, va_gc> *
3366 1543971 : make_tree_vector (void)
3367 : {
3368 1543971 : if (tree_vector_cache && !tree_vector_cache->is_empty ())
3369 1540556 : return tree_vector_cache->pop ();
3370 : else
3371 : {
3372 : /* Passing 0 to vec::alloc returns NULL, and our callers require
3373 : that we always return a non-NULL value. The vector code uses
3374 : 4 when growing a NULL vector, so we do too. */
3375 3415 : vec<tree, va_gc> *v;
3376 3415 : vec_alloc (v, 4);
3377 3415 : return v;
3378 : }
3379 : }
3380 :
3381 : // forked from gcc/c-family/c-common.c release_tree_vector
3382 :
3383 : /* Release a vector of trees back to the cache. */
3384 :
3385 : void
3386 1543971 : release_tree_vector (vec<tree, va_gc> *vec)
3387 : {
3388 1543971 : if (vec != NULL)
3389 : {
3390 1543971 : if (vec->allocated () >= 16)
3391 : /* Don't cache vecs that have expanded more than once. On a p64
3392 : target, vecs double in alloc size with each power of 2 elements, e.g
3393 : at 16 elements the alloc increases from 128 to 256 bytes. */
3394 0 : vec_free (vec);
3395 : else
3396 : {
3397 1543971 : vec->truncate (0);
3398 1543971 : vec_safe_push (tree_vector_cache, vec);
3399 : }
3400 : }
3401 1543971 : }
3402 :
3403 : // forked from gcc/cp/cvt.cc instantiation_dependent_expression_p
3404 :
3405 : /* As above, but also check value-dependence of the expression as a whole. */
3406 :
3407 : bool
3408 0 : instantiation_dependent_expression_p (tree)
3409 : {
3410 0 : return false;
3411 : }
3412 :
3413 : // forked from gcc/cp/cvt.cc cp_get_callee
3414 :
3415 : /* If CALL is a call, return the callee; otherwise null. */
3416 :
3417 : tree
3418 0 : cp_get_callee (tree call)
3419 : {
3420 0 : if (call == NULL_TREE)
3421 : return call;
3422 0 : else if (TREE_CODE (call) == CALL_EXPR)
3423 0 : return CALL_EXPR_FN (call);
3424 : return NULL_TREE;
3425 : }
3426 :
3427 : // forked from gcc/cp/typeck.cc build_nop
3428 :
3429 : /* Return a NOP_EXPR converting EXPR to TYPE. */
3430 :
3431 : tree
3432 0 : build_nop (tree type, tree expr)
3433 : {
3434 0 : if (type == error_mark_node || error_operand_p (expr))
3435 : return expr;
3436 0 : return build1_loc (EXPR_LOCATION (expr), NOP_EXPR, type, expr);
3437 : }
3438 :
3439 : // forked from gcc/cp/tree.cc scalarish_type_p
3440 :
3441 : /* Returns 1 iff type T is something we want to treat as a scalar type for
3442 : the purpose of deciding whether it is trivial/POD/standard-layout. */
3443 :
3444 : bool
3445 18 : scalarish_type_p (const_tree t)
3446 : {
3447 18 : if (t == error_mark_node)
3448 : return 1;
3449 :
3450 18 : return (SCALAR_TYPE_P (t) || VECTOR_TYPE_P (t));
3451 : }
3452 :
3453 : // forked from gcc/cp/tree.cc type_has_nontrivial_copy_init
3454 :
3455 : /* Returns true iff copying an object of type T (including via move
3456 : constructor) is non-trivial. That is, T has no non-trivial copy
3457 : constructors and no non-trivial move constructors, and not all copy/move
3458 : constructors are deleted. This function implements the ABI notion of
3459 : non-trivial copy, which has diverged from the one in the standard. */
3460 :
3461 : bool
3462 0 : type_has_nontrivial_copy_init (const_tree)
3463 : {
3464 0 : return false;
3465 : }
3466 :
3467 : // forked from gcc/cp/tree.cc build_local_temp
3468 :
3469 : /* Return an undeclared local temporary of type TYPE for use in building a
3470 : TARGET_EXPR. */
3471 :
3472 : tree
3473 0 : build_local_temp (tree type)
3474 : {
3475 0 : tree slot = build_decl (input_location, VAR_DECL, NULL_TREE, type);
3476 0 : DECL_ARTIFICIAL (slot) = 1;
3477 0 : DECL_IGNORED_P (slot) = 1;
3478 0 : DECL_CONTEXT (slot) = current_function_decl;
3479 0 : layout_decl (slot, 0);
3480 0 : return slot;
3481 : }
3482 :
3483 : // forked from gcc/cp/lambda.cc is_normal_capture_proxy
3484 :
3485 : /* Returns true iff DECL is a capture proxy for a normal capture
3486 : (i.e. without explicit initializer). */
3487 :
3488 : bool
3489 0 : is_normal_capture_proxy (tree)
3490 : {
3491 0 : return false;
3492 : }
3493 :
3494 : // forked from gcc/cp/c-common.cc reject_gcc_builtin
3495 :
3496 : /* For an EXPR of a FUNCTION_TYPE that references a GCC built-in function
3497 : with no library fallback or for an ADDR_EXPR whose operand is such type
3498 : issues an error pointing to the location LOC.
3499 : Returns true when the expression has been diagnosed and false
3500 : otherwise. */
3501 :
3502 : bool
3503 0 : reject_gcc_builtin (const_tree expr, location_t loc /* = UNKNOWN_LOCATION */)
3504 : {
3505 0 : if (TREE_CODE (expr) == ADDR_EXPR)
3506 0 : expr = TREE_OPERAND (expr, 0);
3507 :
3508 0 : STRIP_ANY_LOCATION_WRAPPER (expr);
3509 :
3510 0 : if (TREE_TYPE (expr) && TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE
3511 0 : && TREE_CODE (expr) == FUNCTION_DECL
3512 : /* The intersection of DECL_BUILT_IN and DECL_IS_UNDECLARED_BUILTIN avoids
3513 : false positives for user-declared built-ins such as abs or
3514 : strlen, and for C++ operators new and delete.
3515 : The c_decl_implicit() test avoids false positives for implicitly
3516 : declared built-ins with library fallbacks (such as abs). */
3517 0 : && fndecl_built_in_p (expr) && DECL_IS_UNDECLARED_BUILTIN (expr)
3518 0 : && !DECL_ASSEMBLER_NAME_SET_P (expr))
3519 : {
3520 0 : if (loc == UNKNOWN_LOCATION)
3521 0 : loc = EXPR_LOC_OR_LOC (expr, input_location);
3522 :
3523 : /* Reject arguments that are built-in functions with
3524 : no library fallback. */
3525 0 : error_at (loc, "built-in function %qE must be directly called", expr);
3526 :
3527 0 : return true;
3528 : }
3529 :
3530 : return false;
3531 : }
3532 :
3533 : // forked from gcc/cp/typeck.cc is_bitfield_expr_with_lowered_type
3534 :
3535 : /* If EXP is a reference to a bit-field, and the type of EXP does not
3536 : match the declared type of the bit-field, return the declared type
3537 : of the bit-field. Otherwise, return NULL_TREE. */
3538 :
3539 : tree
3540 0 : is_bitfield_expr_with_lowered_type (const_tree exp)
3541 : {
3542 0 : switch (TREE_CODE (exp))
3543 : {
3544 0 : case COND_EXPR:
3545 0 : if (!is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1)
3546 0 : ? TREE_OPERAND (exp, 1)
3547 0 : : TREE_OPERAND (exp, 0)))
3548 : return NULL_TREE;
3549 0 : return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 2));
3550 :
3551 0 : case COMPOUND_EXPR:
3552 0 : return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1));
3553 :
3554 0 : case MODIFY_EXPR:
3555 0 : case SAVE_EXPR:
3556 0 : case UNARY_PLUS_EXPR:
3557 0 : case PREDECREMENT_EXPR:
3558 0 : case PREINCREMENT_EXPR:
3559 0 : case POSTDECREMENT_EXPR:
3560 0 : case POSTINCREMENT_EXPR:
3561 0 : case NEGATE_EXPR:
3562 0 : case NON_LVALUE_EXPR:
3563 0 : case BIT_NOT_EXPR:
3564 0 : return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0));
3565 :
3566 0 : case COMPONENT_REF:
3567 0 : {
3568 0 : tree field;
3569 :
3570 0 : field = TREE_OPERAND (exp, 1);
3571 0 : if (TREE_CODE (field) != FIELD_DECL || !DECL_BIT_FIELD_TYPE (field))
3572 : return NULL_TREE;
3573 0 : if (same_type_ignoring_top_level_qualifiers_p (
3574 0 : TREE_TYPE (exp), DECL_BIT_FIELD_TYPE (field)))
3575 : return NULL_TREE;
3576 0 : return DECL_BIT_FIELD_TYPE (field);
3577 : }
3578 :
3579 0 : case VAR_DECL:
3580 0 : if (DECL_HAS_VALUE_EXPR_P (exp))
3581 0 : return is_bitfield_expr_with_lowered_type (
3582 0 : DECL_VALUE_EXPR (const_cast<tree> (exp)));
3583 : return NULL_TREE;
3584 :
3585 0 : case VIEW_CONVERT_EXPR:
3586 0 : if (location_wrapper_p (exp))
3587 0 : return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0));
3588 : else
3589 : return NULL_TREE;
3590 :
3591 : default:
3592 : return NULL_TREE;
3593 : }
3594 : }
3595 :
3596 : // forked from gcc/cp/semantics.cc maybe_undo_parenthesized_ref
3597 :
3598 : /* If T is an id-expression obfuscated by force_paren_expr, undo the
3599 : obfuscation and return the underlying id-expression. Otherwise
3600 : return T. */
3601 :
3602 : tree
3603 0 : maybe_undo_parenthesized_ref (tree t)
3604 : {
3605 0 : if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
3606 0 : && REF_PARENTHESIZED_P (t))
3607 0 : t = TREE_OPERAND (t, 0);
3608 :
3609 0 : return t;
3610 : }
3611 :
3612 : // forked from gcc/c-family/c-common.cc fold_offsetof
3613 :
3614 : /* Fold an offsetof-like expression. EXPR is a nested sequence of component
3615 : references with an INDIRECT_REF of a constant at the bottom; much like the
3616 : traditional rendering of offsetof as a macro. TYPE is the desired type of
3617 : the whole expression. Return the folded result. */
3618 :
3619 : tree
3620 0 : fold_offsetof (tree expr, tree type, enum tree_code ctx)
3621 : {
3622 0 : tree base, off, t;
3623 0 : tree_code code = TREE_CODE (expr);
3624 0 : switch (code)
3625 : {
3626 : case ERROR_MARK:
3627 : return expr;
3628 :
3629 0 : case VAR_DECL:
3630 0 : error ("cannot apply %<offsetof%> to static data member %qD", expr);
3631 0 : return error_mark_node;
3632 :
3633 0 : case CALL_EXPR:
3634 0 : case TARGET_EXPR:
3635 0 : error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
3636 0 : return error_mark_node;
3637 :
3638 0 : case NOP_EXPR:
3639 0 : case INDIRECT_REF:
3640 0 : if (!TREE_CONSTANT (TREE_OPERAND (expr, 0)))
3641 : {
3642 0 : error ("cannot apply %<offsetof%> to a non constant address");
3643 0 : return error_mark_node;
3644 : }
3645 0 : return convert (type, TREE_OPERAND (expr, 0));
3646 :
3647 0 : case COMPONENT_REF:
3648 0 : base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
3649 0 : if (base == error_mark_node)
3650 : return base;
3651 :
3652 0 : t = TREE_OPERAND (expr, 1);
3653 0 : if (DECL_C_BIT_FIELD (t))
3654 : {
3655 0 : error ("attempt to take address of bit-field structure "
3656 : "member %qD",
3657 : t);
3658 0 : return error_mark_node;
3659 : }
3660 0 : off = size_binop_loc (input_location, PLUS_EXPR, DECL_FIELD_OFFSET (t),
3661 0 : size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t))
3662 : / BITS_PER_UNIT));
3663 0 : break;
3664 :
3665 0 : case ARRAY_REF:
3666 0 : base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
3667 0 : if (base == error_mark_node)
3668 : return base;
3669 :
3670 0 : t = TREE_OPERAND (expr, 1);
3671 0 : STRIP_ANY_LOCATION_WRAPPER (t);
3672 :
3673 : /* Check if the offset goes beyond the upper bound of the array. */
3674 0 : if (TREE_CODE (t) == INTEGER_CST && tree_int_cst_sgn (t) >= 0)
3675 : {
3676 0 : tree upbound = array_ref_up_bound (expr);
3677 0 : if (upbound != NULL_TREE && TREE_CODE (upbound) == INTEGER_CST
3678 0 : && !tree_int_cst_equal (upbound,
3679 0 : TYPE_MAX_VALUE (TREE_TYPE (upbound))))
3680 : {
3681 0 : if (ctx != ARRAY_REF && ctx != COMPONENT_REF)
3682 0 : upbound = size_binop (PLUS_EXPR, upbound,
3683 : build_int_cst (TREE_TYPE (upbound), 1));
3684 0 : if (tree_int_cst_lt (upbound, t))
3685 : {
3686 0 : tree v;
3687 :
3688 0 : for (v = TREE_OPERAND (expr, 0);
3689 0 : TREE_CODE (v) == COMPONENT_REF; v = TREE_OPERAND (v, 0))
3690 0 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
3691 : == RECORD_TYPE)
3692 : {
3693 0 : tree fld_chain = DECL_CHAIN (TREE_OPERAND (v, 1));
3694 0 : for (; fld_chain; fld_chain = DECL_CHAIN (fld_chain))
3695 0 : if (TREE_CODE (fld_chain) == FIELD_DECL)
3696 : break;
3697 :
3698 : if (fld_chain)
3699 : break;
3700 : }
3701 : /* Don't warn if the array might be considered a poor
3702 : man's flexible array member with a very permissive
3703 : definition thereof. */
3704 0 : if (TREE_CODE (v) == ARRAY_REF
3705 0 : || TREE_CODE (v) == COMPONENT_REF)
3706 0 : warning (OPT_Warray_bounds_,
3707 : "index %E denotes an offset "
3708 : "greater than size of %qT",
3709 0 : t, TREE_TYPE (TREE_OPERAND (expr, 0)));
3710 : }
3711 : }
3712 : }
3713 :
3714 0 : t = convert (sizetype, t);
3715 0 : off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t);
3716 0 : break;
3717 :
3718 0 : case COMPOUND_EXPR:
3719 : /* Handle static members of volatile structs. */
3720 0 : t = TREE_OPERAND (expr, 1);
3721 0 : gcc_checking_assert (VAR_P (get_base_address (t)));
3722 : return fold_offsetof (t, type);
3723 :
3724 0 : default:
3725 0 : rust_unreachable ();
3726 : }
3727 :
3728 0 : if (!POINTER_TYPE_P (type))
3729 0 : return size_binop (PLUS_EXPR, base, convert (type, off));
3730 0 : return fold_build_pointer_plus (base, off);
3731 : }
3732 :
3733 : // forked from gcc/cp/tree.cc char_type_p
3734 :
3735 : /* Returns nonzero if TYPE is a character type, including wchar_t. */
3736 :
3737 : int
3738 0 : char_type_p (tree type)
3739 : {
3740 0 : return (same_type_p (type, char_type_node)
3741 0 : || same_type_p (type, unsigned_char_type_node)
3742 0 : || same_type_p (type, signed_char_type_node)
3743 0 : || same_type_p (type, char8_type_node)
3744 0 : || same_type_p (type, char16_type_node)
3745 0 : || same_type_p (type, char32_type_node)
3746 0 : || same_type_p (type, wchar_type_node));
3747 : }
3748 :
3749 : // forked from gcc/cp/pt.cc resolve_nondeduced_context
3750 :
3751 : /* Core DR 115: In contexts where deduction is done and fails, or in
3752 : contexts where deduction is not done, if a template argument list is
3753 : specified and it, along with any default template arguments, identifies
3754 : a single function template specialization, then the template-id is an
3755 : lvalue for the function template specialization. */
3756 :
3757 : tree
3758 0 : resolve_nondeduced_context (tree orig_expr, tsubst_flags_t)
3759 : {
3760 0 : return orig_expr;
3761 : }
3762 :
3763 : // forked from gcc/cp/pt.cc instantiate_non_dependent_or_null
3764 :
3765 : /* Like instantiate_non_dependent_expr, but return NULL_TREE rather than
3766 : an uninstantiated expression. */
3767 :
3768 : tree
3769 0 : instantiate_non_dependent_or_null (tree expr)
3770 : {
3771 0 : if (expr == NULL_TREE)
3772 : return NULL_TREE;
3773 :
3774 : return expr;
3775 : }
3776 :
3777 : // forked from gcc/cp/pt.cc resolve_nondeduced_context_or_error
3778 :
3779 : /* As above, but error out if the expression remains overloaded. */
3780 :
3781 : tree
3782 0 : resolve_nondeduced_context_or_error (tree exp, tsubst_flags_t complain)
3783 : {
3784 0 : exp = resolve_nondeduced_context (exp, complain);
3785 0 : if (type_unknown_p (exp))
3786 : {
3787 0 : if (complain & tf_error)
3788 0 : cxx_incomplete_type_error (exp, TREE_TYPE (exp));
3789 0 : return error_mark_node;
3790 : }
3791 : return exp;
3792 : }
3793 :
3794 : // forked from gcc/cp/tree.cc really_overloaded_fn
3795 :
3796 : /* Returns true iff X is an expression for an overloaded function
3797 : whose type cannot be known without performing overload
3798 : resolution. */
3799 :
3800 : bool
3801 0 : really_overloaded_fn (tree x)
3802 : {
3803 0 : return is_overloaded_fn (x) == 2;
3804 : }
3805 :
3806 : // forked from gcc/cp/typeck..cc invalid_nonstatic_memfn_p
3807 :
3808 : /* EXPR is being used in a context that is not a function call.
3809 : Enforce:
3810 :
3811 : [expr.ref]
3812 :
3813 : The expression can be used only as the left-hand operand of a
3814 : member function call.
3815 :
3816 : [expr.mptr.operator]
3817 :
3818 : If the result of .* or ->* is a function, then that result can be
3819 : used only as the operand for the function call operator ().
3820 :
3821 : by issuing an error message if appropriate. Returns true iff EXPR
3822 : violates these rules. */
3823 :
3824 : bool
3825 0 : invalid_nonstatic_memfn_p (location_t loc, tree expr, tsubst_flags_t complain)
3826 : {
3827 0 : if (expr == NULL_TREE)
3828 : return false;
3829 : /* Don't enforce this in MS mode. */
3830 0 : if (flag_ms_extensions)
3831 : return false;
3832 0 : if (is_overloaded_fn (expr) && !really_overloaded_fn (expr))
3833 0 : expr = get_first_fn (expr);
3834 0 : if (DECL_NONSTATIC_MEMBER_FUNCTION_P (expr))
3835 : {
3836 0 : if (complain & tf_error)
3837 : {
3838 0 : if (DECL_P (expr))
3839 : {
3840 0 : error_at (loc, "invalid use of non-static member function %qD",
3841 : expr);
3842 0 : inform (DECL_SOURCE_LOCATION (expr), "declared here");
3843 : }
3844 : else
3845 0 : error_at (loc,
3846 : "invalid use of non-static member function of "
3847 : "type %qT",
3848 0 : TREE_TYPE (expr));
3849 : }
3850 : return true;
3851 : }
3852 : return false;
3853 : }
3854 :
3855 : // forked from gcc/cp/call.cc strip_top_quals
3856 :
3857 : tree
3858 0 : strip_top_quals (tree t)
3859 : {
3860 0 : if (TREE_CODE (t) == ARRAY_TYPE)
3861 : return t;
3862 0 : return rs_build_qualified_type (t, TYPE_UNQUALIFIED);
3863 : }
3864 :
3865 : // forked from gcc/cp/typeck2.cc cxx_incomplete_type_inform
3866 :
3867 : /* Print an inform about the declaration of the incomplete type TYPE. */
3868 :
3869 : // void
3870 : // cxx_incomplete_type_inform (const_tree type)
3871 : // {
3872 : // if (!TYPE_MAIN_DECL (type))
3873 : // return;
3874 :
3875 : // location_t loc = DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type));
3876 : // tree ptype = strip_top_quals (const_cast<tree> (type));
3877 :
3878 : // if (current_class_type && TYPE_BEING_DEFINED (current_class_type)
3879 : // && same_type_p (ptype, current_class_type))
3880 : // inform (loc,
3881 : // "definition of %q#T is not complete until "
3882 : // "the closing brace",
3883 : // ptype);
3884 : // else
3885 : // inform (loc, "forward declaration of %q#T", ptype);
3886 : // }
3887 :
3888 : // forked from gcc/cp/typeck2.cc cxx_incomplete_type_diagnostic
3889 :
3890 : /* Print an error message for invalid use of an incomplete type.
3891 : VALUE is the expression that was used (or 0 if that isn't known)
3892 : and TYPE is the type that was invalid. DIAG_KIND indicates the
3893 : type of diagnostic (see diagnostics/kinds.def). */
3894 :
3895 : void
3896 0 : cxx_incomplete_type_diagnostic (location_t loc, const_tree value,
3897 : const_tree type,
3898 : enum diagnostics::kind diag_kind)
3899 : {
3900 : // bool is_decl = false, complained = false;
3901 :
3902 0 : gcc_assert (diag_kind == diagnostics::kind::warning
3903 : || diag_kind == diagnostics::kind::pedwarn
3904 : || diag_kind == diagnostics::kind::error);
3905 :
3906 : /* Avoid duplicate error message. */
3907 0 : if (TREE_CODE (type) == ERROR_MARK)
3908 : return;
3909 :
3910 0 : if (value)
3911 : {
3912 0 : STRIP_ANY_LOCATION_WRAPPER (value);
3913 :
3914 0 : if (VAR_P (value) || TREE_CODE (value) == PARM_DECL
3915 : || TREE_CODE (value) == FIELD_DECL)
3916 : {
3917 : // complained = emit_diagnostic (diag_kind, DECL_SOURCE_LOCATION
3918 : // (value),
3919 : // 0, "%qD has incomplete type", value);
3920 : // is_decl = true;
3921 : }
3922 : }
3923 0 : retry:
3924 : /* We must print an error message. Be clever about what it says. */
3925 :
3926 0 : switch (TREE_CODE (type))
3927 : {
3928 : // case RECORD_TYPE:
3929 : // case UNION_TYPE:
3930 : // case ENUMERAL_TYPE:
3931 : // if (!is_decl)
3932 : // complained
3933 : // = emit_diagnostic (diag_kind, loc, 0,
3934 : // "invalid use of incomplete type %q#T", type);
3935 : // if (complained)
3936 : // cxx_incomplete_type_inform (type);
3937 : // break;
3938 :
3939 0 : case VOID_TYPE:
3940 0 : emit_diagnostic (diag_kind, loc, 0, "invalid use of %qT", type);
3941 0 : break;
3942 :
3943 0 : case ARRAY_TYPE:
3944 0 : if (TYPE_DOMAIN (type))
3945 : {
3946 0 : type = TREE_TYPE (type);
3947 0 : goto retry;
3948 : }
3949 0 : emit_diagnostic (diag_kind, loc, 0,
3950 : "invalid use of array with unspecified bounds");
3951 0 : break;
3952 :
3953 0 : case OFFSET_TYPE:
3954 0 : bad_member:
3955 0 : {
3956 0 : tree member = TREE_OPERAND (value, 1);
3957 0 : if (is_overloaded_fn (member))
3958 0 : member = get_first_fn (member);
3959 :
3960 0 : if (DECL_FUNCTION_MEMBER_P (member) && !flag_ms_extensions)
3961 : {
3962 0 : gcc_rich_location richloc (loc);
3963 : /* If "member" has no arguments (other than "this"), then
3964 : add a fix-it hint. */
3965 0 : if (type_num_arguments (TREE_TYPE (member)) == 1)
3966 0 : richloc.add_fixit_insert_after ("()");
3967 0 : emit_diagnostic (diag_kind, &richloc, 0,
3968 : "invalid use of member function %qD "
3969 : "(did you forget the %<()%> ?)",
3970 : member);
3971 0 : }
3972 : else
3973 0 : emit_diagnostic (diag_kind, loc, 0,
3974 : "invalid use of member %qD "
3975 : "(did you forget the %<&%> ?)",
3976 : member);
3977 : }
3978 : break;
3979 :
3980 0 : case LANG_TYPE:
3981 0 : if (type == init_list_type_node)
3982 : {
3983 0 : emit_diagnostic (diag_kind, loc, 0,
3984 : "invalid use of brace-enclosed initializer list");
3985 0 : break;
3986 : }
3987 0 : gcc_assert (type == unknown_type_node);
3988 0 : if (value && TREE_CODE (value) == COMPONENT_REF)
3989 0 : goto bad_member;
3990 0 : else if (value && TREE_CODE (value) == ADDR_EXPR)
3991 0 : emit_diagnostic (diag_kind, loc, 0,
3992 : "address of overloaded function with no contextual "
3993 : "type information");
3994 0 : else if (value && TREE_CODE (value) == OVERLOAD)
3995 0 : emit_diagnostic (
3996 0 : diag_kind, loc, 0,
3997 : "overloaded function with no contextual type information");
3998 : else
3999 0 : emit_diagnostic (
4000 0 : diag_kind, loc, 0,
4001 : "insufficient contextual information to determine type");
4002 : break;
4003 :
4004 0 : default:
4005 0 : rust_unreachable ();
4006 : }
4007 : }
4008 :
4009 : // forked from gcc/cp/decl2.cc decl_constant_var_p
4010 :
4011 : /* Nonzero for a VAR_DECL whose value can be used in a constant expression.
4012 :
4013 : [expr.const]
4014 :
4015 : An integral constant-expression can only involve ... const
4016 : variables of integral or enumeration types initialized with
4017 : constant expressions ...
4018 :
4019 : C++0x also allows constexpr variables and temporaries initialized
4020 : with constant expressions. We handle the former here, but the latter
4021 : are just folded away in cxx_eval_constant_expression.
4022 :
4023 : The standard does not require that the expression be non-volatile.
4024 : G++ implements the proposed correction in DR 457. */
4025 :
4026 : bool
4027 0 : decl_constant_var_p (tree decl)
4028 : {
4029 0 : if (!decl_maybe_constant_var_p (decl))
4030 : return false;
4031 :
4032 0 : return DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl);
4033 : }
4034 :
4035 : // forked from gcc/cp/decl.cc undeduced_auto_decl
4036 :
4037 : /* Returns true iff DECL is a variable or function declared with an auto type
4038 : that has not yet been deduced to a real type. */
4039 :
4040 : bool
4041 0 : undeduced_auto_decl (tree)
4042 : {
4043 0 : return false;
4044 : }
4045 :
4046 : // forked from gcc/cp/decl.cc require_deduced_type
4047 :
4048 : /* Complain if DECL has an undeduced return type. */
4049 :
4050 : bool
4051 0 : require_deduced_type (tree, tsubst_flags_t)
4052 : {
4053 0 : return true;
4054 : }
4055 :
4056 : /* Return the location of a tree passed to %+ formats. */
4057 :
4058 : location_t
4059 0 : location_of (tree t)
4060 : {
4061 0 : if (TYPE_P (t))
4062 : {
4063 0 : t = TYPE_MAIN_DECL (t);
4064 0 : if (t == NULL_TREE)
4065 0 : return input_location;
4066 : }
4067 0 : else if (TREE_CODE (t) == OVERLOAD)
4068 0 : t = OVL_FIRST (t);
4069 :
4070 0 : if (DECL_P (t))
4071 0 : return DECL_SOURCE_LOCATION (t);
4072 :
4073 0 : return EXPR_LOCATION (t);
4074 : }
4075 :
4076 : /* For element type ELT_TYPE, return the appropriate type of the heap object
4077 : containing such element(s). COOKIE_SIZE is NULL or the size of cookie
4078 : in bytes. FULL_SIZE is NULL if it is unknown how big the heap allocation
4079 : will be, otherwise size of the heap object. If COOKIE_SIZE is NULL,
4080 : return array type ELT_TYPE[FULL_SIZE / sizeof(ELT_TYPE)], otherwise return
4081 : struct { size_t[COOKIE_SIZE/sizeof(size_t)]; ELT_TYPE[N]; }
4082 : where N is nothing (flexible array member) if FULL_SIZE is NULL, otherwise
4083 : it is computed such that the size of the struct fits into FULL_SIZE. */
4084 :
4085 : tree
4086 0 : build_new_constexpr_heap_type (tree elt_type, tree cookie_size, tree full_size)
4087 : {
4088 0 : gcc_assert (cookie_size == NULL_TREE || tree_fits_uhwi_p (cookie_size));
4089 0 : gcc_assert (full_size == NULL_TREE || tree_fits_uhwi_p (full_size));
4090 0 : unsigned HOST_WIDE_INT csz = cookie_size ? tree_to_uhwi (cookie_size) : 0;
4091 0 : tree itype2 = NULL_TREE;
4092 0 : if (full_size)
4093 : {
4094 0 : unsigned HOST_WIDE_INT fsz = tree_to_uhwi (full_size);
4095 0 : gcc_assert (fsz >= csz);
4096 0 : fsz -= csz;
4097 0 : fsz /= int_size_in_bytes (elt_type);
4098 0 : itype2 = build_index_type (size_int (fsz - 1));
4099 0 : if (!cookie_size)
4100 0 : return build_cplus_array_type (elt_type, itype2);
4101 : }
4102 : else
4103 0 : gcc_assert (cookie_size);
4104 0 : csz /= int_size_in_bytes (sizetype);
4105 0 : tree itype1 = build_index_type (size_int (csz - 1));
4106 0 : tree atype1 = build_cplus_array_type (sizetype, itype1);
4107 0 : tree atype2 = build_cplus_array_type (elt_type, itype2);
4108 0 : tree rtype = cxx_make_type (RECORD_TYPE);
4109 0 : TYPE_NAME (rtype) = heap_identifier;
4110 0 : tree fld1 = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, atype1);
4111 0 : tree fld2 = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, atype2);
4112 0 : DECL_FIELD_CONTEXT (fld1) = rtype;
4113 0 : DECL_FIELD_CONTEXT (fld2) = rtype;
4114 0 : DECL_ARTIFICIAL (fld1) = true;
4115 0 : DECL_ARTIFICIAL (fld2) = true;
4116 0 : TYPE_FIELDS (rtype) = fld1;
4117 0 : DECL_CHAIN (fld1) = fld2;
4118 0 : layout_type (rtype);
4119 0 : return rtype;
4120 : }
4121 :
4122 : // forked from gcc/cp/class.cc field_poverlapping_p
4123 :
4124 : /* Return true iff FIELD_DECL DECL is potentially overlapping. */
4125 :
4126 : static bool
4127 0 : field_poverlapping_p (tree decl)
4128 : {
4129 0 : return lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (decl));
4130 : }
4131 :
4132 : // forked from gcc/cp/class.cc is_empty_field
4133 :
4134 : /* Return true iff DECL is an empty field, either for an empty base or a
4135 : [[no_unique_address]] data member. */
4136 :
4137 : bool
4138 2 : is_empty_field (tree decl)
4139 : {
4140 2 : if (!decl || TREE_CODE (decl) != FIELD_DECL)
4141 : return false;
4142 :
4143 2 : bool r = (is_empty_class (TREE_TYPE (decl)) && (field_poverlapping_p (decl)));
4144 :
4145 : /* Empty fields should have size zero. */
4146 0 : gcc_checking_assert (!r || integer_zerop (DECL_SIZE (decl)));
4147 :
4148 : return r;
4149 : }
4150 :
4151 : // forked from gcc/cp/call.cc in_immediate_context
4152 :
4153 : /* Return true if in an immediate function context, or an unevaluated operand,
4154 : or a subexpression of an immediate invocation. */
4155 :
4156 : bool
4157 0 : in_immediate_context ()
4158 : {
4159 0 : return false;
4160 : }
4161 :
4162 : // forked from gcc/cp/cvt.cc cp_get_fndecl_from_callee
4163 :
4164 : /* FN is the callee of a CALL_EXPR or AGGR_INIT_EXPR; return the FUNCTION_DECL
4165 : if we can. */
4166 :
4167 : tree
4168 0 : rs_get_fndecl_from_callee (tree fn, bool fold /* = true */)
4169 : {
4170 0 : if (fn == NULL_TREE)
4171 : return fn;
4172 0 : if (TREE_CODE (fn) == FUNCTION_DECL)
4173 : return fn;
4174 0 : tree type = TREE_TYPE (fn);
4175 0 : if (type == NULL_TREE || !INDIRECT_TYPE_P (type))
4176 : return NULL_TREE;
4177 0 : if (fold)
4178 0 : fn = Compile::maybe_constant_init (fn);
4179 0 : STRIP_NOPS (fn);
4180 0 : if (TREE_CODE (fn) == ADDR_EXPR || TREE_CODE (fn) == FDESC_EXPR)
4181 0 : fn = TREE_OPERAND (fn, 0);
4182 0 : if (TREE_CODE (fn) == FUNCTION_DECL)
4183 0 : return fn;
4184 : return NULL_TREE;
4185 : }
4186 :
4187 : // forked from gcc/cp/cvt.cc cp_get_callee_fndecl_nofold
4188 : tree
4189 0 : rs_get_callee_fndecl_nofold (tree call)
4190 : {
4191 0 : return rs_get_fndecl_from_callee (cp_get_callee (call), false);
4192 : }
4193 :
4194 : // forked from gcc/cp/init.cc is_class_type
4195 :
4196 : /* Report an error if TYPE is not a user-defined, class type. If
4197 : OR_ELSE is nonzero, give an error message. */
4198 :
4199 : int
4200 0 : is_class_type (tree type, int or_else)
4201 : {
4202 0 : if (type == error_mark_node)
4203 : return 0;
4204 :
4205 0 : if (!CLASS_TYPE_P (type))
4206 : {
4207 0 : if (or_else)
4208 0 : error ("%qT is not a class type", type);
4209 : return 0;
4210 : }
4211 : return 1;
4212 : }
4213 :
4214 : // forked from gcc/cp/decl.cc lookup_enumerator
4215 :
4216 : /* Look for an enumerator with the given NAME within the enumeration
4217 : type ENUMTYPE. This routine is used primarily for qualified name
4218 : lookup into an enumerator in C++0x, e.g.,
4219 :
4220 : enum class Color { Red, Green, Blue };
4221 :
4222 : Color color = Color::Red;
4223 :
4224 : Returns the value corresponding to the enumerator, or
4225 : NULL_TREE if no such enumerator was found. */
4226 : tree
4227 0 : lookup_enumerator (tree enumtype, tree name)
4228 : {
4229 0 : tree e;
4230 0 : gcc_assert (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE);
4231 :
4232 0 : e = purpose_member (name, TYPE_VALUES (enumtype));
4233 0 : return e ? TREE_VALUE (e) : NULL_TREE;
4234 : }
4235 :
4236 : // forked from gcc/cp/init.cc constant_value_1
4237 : // commented out mark_used
4238 :
4239 : /* If DECL is a scalar enumeration constant or variable with a
4240 : constant initializer, return the initializer (or, its initializers,
4241 : recursively); otherwise, return DECL. If STRICT_P, the
4242 : initializer is only returned if DECL is a
4243 : constant-expression. If RETURN_AGGREGATE_CST_OK_P, it is ok to
4244 : return an aggregate constant. If UNSHARE_P, return an unshared
4245 : copy of the initializer. */
4246 :
4247 : static tree
4248 0 : constant_value_1 (tree decl, bool strict_p, bool return_aggregate_cst_ok_p,
4249 : bool unshare_p)
4250 : {
4251 0 : while (TREE_CODE (decl) == CONST_DECL || decl_constant_var_p (decl)
4252 0 : || (!strict_p && VAR_P (decl)
4253 0 : && RS_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (decl))))
4254 : {
4255 0 : tree init;
4256 : /* If DECL is a static data member in a template
4257 : specialization, we must instantiate it here. The
4258 : initializer for the static data member is not processed
4259 : until needed; we need it now. */
4260 : // mark_used (decl, tf_none);
4261 0 : init = DECL_INITIAL (decl);
4262 0 : if (init == error_mark_node)
4263 : {
4264 0 : if (TREE_CODE (decl) == CONST_DECL
4265 0 : || DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
4266 : /* Treat the error as a constant to avoid cascading errors on
4267 : excessively recursive template instantiation (c++/9335). */
4268 0 : return init;
4269 : else
4270 : return decl;
4271 : }
4272 :
4273 : /* Instantiate a non-dependent initializer for user variables. We
4274 : mustn't do this for the temporary for an array compound literal;
4275 : trying to instatiate the initializer will keep creating new
4276 : temporaries until we crash. Probably it's not useful to do it for
4277 : other artificial variables, either. */
4278 0 : if (!DECL_ARTIFICIAL (decl))
4279 0 : init = instantiate_non_dependent_or_null (init);
4280 0 : if (!init || !TREE_TYPE (init) || !TREE_CONSTANT (init)
4281 0 : || (!return_aggregate_cst_ok_p
4282 : /* Unless RETURN_AGGREGATE_CST_OK_P is true, do not
4283 : return an aggregate constant (of which string
4284 : literals are a special case), as we do not want
4285 : to make inadvertent copies of such entities, and
4286 : we must be sure that their addresses are the
4287 : same everywhere. */
4288 0 : && (TREE_CODE (init) == CONSTRUCTOR
4289 0 : || TREE_CODE (init) == STRING_CST)))
4290 : break;
4291 : /* Don't return a CONSTRUCTOR for a variable with partial run-time
4292 : initialization, since it doesn't represent the entire value.
4293 : Similarly for VECTOR_CSTs created by cp_folding those
4294 : CONSTRUCTORs. */
4295 0 : if ((TREE_CODE (init) == CONSTRUCTOR || TREE_CODE (init) == VECTOR_CST)
4296 0 : && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
4297 : break;
4298 : /* If the variable has a dynamic initializer, don't use its
4299 : DECL_INITIAL which doesn't reflect the real value. */
4300 0 : if (VAR_P (decl) && TREE_STATIC (decl)
4301 0 : && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)
4302 0 : && DECL_NONTRIVIALLY_INITIALIZED_P (decl))
4303 : break;
4304 : decl = init;
4305 : }
4306 0 : return unshare_p ? unshare_expr (decl) : decl;
4307 : }
4308 :
4309 : // forked from gcc/cp/init.cc decl_constant_value
4310 :
4311 : /* A more relaxed version of decl_really_constant_value, used by the
4312 : common C/C++ code. */
4313 :
4314 : tree
4315 0 : decl_constant_value (tree decl, bool unshare_p)
4316 : {
4317 0 : return constant_value_1 (decl, /*strict_p=*/false,
4318 : /*return_aggregate_cst_ok_p=*/true,
4319 0 : /*unshare_p=*/unshare_p);
4320 : }
4321 :
4322 : // Below is forked from gcc/cp/init.cc decl_constant_value
4323 :
4324 : tree
4325 0 : decl_constant_value (tree decl)
4326 : {
4327 0 : return decl_constant_value (decl, /*unshare_p=*/true);
4328 : }
4329 :
4330 : // Below is forked from gcc/cp/cp-gimplify.cc
4331 :
4332 : /* Type for source_location_table hash_set. */
4333 : struct GTY ((for_user)) source_location_table_entry
4334 : {
4335 : location_t loc;
4336 : unsigned uid;
4337 : tree var;
4338 : };
4339 :
4340 : // exit/reenter namespace to declare some external functions
4341 :
4342 : } // namespace Rust
4343 :
4344 : extern void gt_pch_nx (Rust::source_location_table_entry &);
4345 : extern void gt_pch_nx (Rust::source_location_table_entry *, gt_pointer_operator,
4346 : void *);
4347 :
4348 : namespace Rust {
4349 :
4350 : /* Traits class for function start hash maps below. */
4351 :
4352 : struct rust_source_location_table_entry_hash
4353 : : ggc_remove<source_location_table_entry>
4354 : {
4355 : typedef source_location_table_entry value_type;
4356 : typedef source_location_table_entry compare_type;
4357 :
4358 0 : static hashval_t hash (const source_location_table_entry &ref)
4359 : {
4360 0 : inchash::hash hstate (0);
4361 0 : hstate.add_int (ref.loc);
4362 0 : hstate.add_int (ref.uid);
4363 0 : return hstate.end ();
4364 : }
4365 :
4366 0 : static bool equal (const source_location_table_entry &ref1,
4367 : const source_location_table_entry &ref2)
4368 : {
4369 0 : return ref1.loc == ref2.loc && ref1.uid == ref2.uid;
4370 : }
4371 :
4372 : static void mark_deleted (source_location_table_entry &ref)
4373 : {
4374 : ref.loc = UNKNOWN_LOCATION;
4375 : ref.uid = -1U;
4376 : ref.var = NULL_TREE;
4377 : }
4378 :
4379 : static const bool empty_zero_p = true;
4380 :
4381 0 : static void mark_empty (source_location_table_entry &ref)
4382 : {
4383 0 : ref.loc = UNKNOWN_LOCATION;
4384 0 : ref.uid = 0;
4385 0 : ref.var = NULL_TREE;
4386 : }
4387 :
4388 0 : static bool is_deleted (const source_location_table_entry &ref)
4389 : {
4390 0 : return (ref.loc == UNKNOWN_LOCATION && ref.uid == -1U
4391 0 : && ref.var == NULL_TREE);
4392 : }
4393 :
4394 0 : static bool is_empty (const source_location_table_entry &ref)
4395 : {
4396 0 : return (ref.loc == UNKNOWN_LOCATION && ref.uid == 0
4397 0 : && ref.var == NULL_TREE);
4398 : }
4399 :
4400 0 : static void pch_nx (source_location_table_entry &p) { gt_pch_nx (p); }
4401 :
4402 0 : static void pch_nx (source_location_table_entry &p, gt_pointer_operator op,
4403 : void *cookie)
4404 : {
4405 0 : gt_pch_nx (&p, op, cookie);
4406 : }
4407 : };
4408 :
4409 : static GTY (())
4410 : hash_table<rust_source_location_table_entry_hash> *source_location_table;
4411 : static GTY (()) unsigned int source_location_id;
4412 :
4413 : // Above is forked from gcc/cp/cp-gimplify.cc
4414 :
4415 : // forked from gcc/cp/tree.cc lvalue_kind
4416 :
4417 : /* If REF is an lvalue, returns the kind of lvalue that REF is.
4418 : Otherwise, returns clk_none. */
4419 :
4420 : cp_lvalue_kind
4421 0 : lvalue_kind (const_tree ref)
4422 : {
4423 0 : cp_lvalue_kind op1_lvalue_kind = clk_none;
4424 0 : cp_lvalue_kind op2_lvalue_kind = clk_none;
4425 :
4426 : /* Expressions of reference type are sometimes wrapped in
4427 : INDIRECT_REFs. INDIRECT_REFs are just internal compiler
4428 : representation, not part of the language, so we have to look
4429 : through them. */
4430 0 : if (REFERENCE_REF_P (ref))
4431 0 : return lvalue_kind (TREE_OPERAND (ref, 0));
4432 :
4433 0 : if (TREE_TYPE (ref) && TYPE_REF_P (TREE_TYPE (ref)))
4434 : {
4435 : /* unnamed rvalue references are rvalues */
4436 0 : if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref)) && TREE_CODE (ref) != PARM_DECL
4437 : && !VAR_P (ref)
4438 : && TREE_CODE (ref) != COMPONENT_REF
4439 : /* Functions are always lvalues. */
4440 0 : && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
4441 : {
4442 0 : op1_lvalue_kind = clk_rvalueref;
4443 0 : if (implicit_rvalue_p (ref))
4444 0 : op1_lvalue_kind |= clk_implicit_rval;
4445 : return op1_lvalue_kind;
4446 : }
4447 :
4448 : /* lvalue references and named rvalue references are lvalues. */
4449 : return clk_ordinary;
4450 : }
4451 :
4452 0 : if (ref == current_class_ptr)
4453 : return clk_none;
4454 :
4455 : /* Expressions with cv void type are prvalues. */
4456 0 : if (TREE_TYPE (ref) && VOID_TYPE_P (TREE_TYPE (ref)))
4457 : return clk_none;
4458 :
4459 0 : switch (TREE_CODE (ref))
4460 : {
4461 : case SAVE_EXPR:
4462 : return clk_none;
4463 :
4464 : /* preincrements and predecrements are valid lvals, provided
4465 : what they refer to are valid lvals. */
4466 0 : case PREINCREMENT_EXPR:
4467 0 : case PREDECREMENT_EXPR:
4468 0 : case TRY_CATCH_EXPR:
4469 0 : case REALPART_EXPR:
4470 0 : case IMAGPART_EXPR:
4471 0 : case VIEW_CONVERT_EXPR:
4472 0 : return lvalue_kind (TREE_OPERAND (ref, 0));
4473 :
4474 0 : case ARRAY_REF:
4475 0 : {
4476 0 : tree op1 = TREE_OPERAND (ref, 0);
4477 0 : if (TREE_CODE (TREE_TYPE (op1)) == ARRAY_TYPE)
4478 : {
4479 0 : op1_lvalue_kind = lvalue_kind (op1);
4480 0 : if (op1_lvalue_kind == clk_class)
4481 : /* in the case of an array operand, the result is an lvalue if
4482 : that operand is an lvalue and an xvalue otherwise */
4483 0 : op1_lvalue_kind = clk_rvalueref;
4484 : return op1_lvalue_kind;
4485 : }
4486 : else
4487 : return clk_ordinary;
4488 : }
4489 :
4490 0 : case MEMBER_REF:
4491 0 : case DOTSTAR_EXPR:
4492 0 : if (TREE_CODE (ref) == MEMBER_REF)
4493 : op1_lvalue_kind = clk_ordinary;
4494 : else
4495 0 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
4496 0 : if (TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (ref, 1))))
4497 : op1_lvalue_kind = clk_none;
4498 0 : else if (op1_lvalue_kind == clk_class)
4499 : /* The result of a .* expression whose second operand is a pointer to a
4500 : data member is an lvalue if the first operand is an lvalue and an
4501 : xvalue otherwise. */
4502 0 : op1_lvalue_kind = clk_rvalueref;
4503 : return op1_lvalue_kind;
4504 :
4505 0 : case COMPONENT_REF:
4506 0 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
4507 0 : if (op1_lvalue_kind == clk_class)
4508 : /* If E1 is an lvalue, then E1.E2 is an lvalue;
4509 : otherwise E1.E2 is an xvalue. */
4510 : op1_lvalue_kind = clk_rvalueref;
4511 :
4512 : /* Look at the member designator. */
4513 0 : if (!op1_lvalue_kind)
4514 : ;
4515 0 : else if (is_overloaded_fn (TREE_OPERAND (ref, 1)))
4516 : /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
4517 : situations. If we're seeing a COMPONENT_REF, it's a non-static
4518 : member, so it isn't an lvalue. */
4519 : op1_lvalue_kind = clk_none;
4520 0 : else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
4521 : /* This can be IDENTIFIER_NODE in a template. */;
4522 0 : else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
4523 : {
4524 : /* Clear the ordinary bit. If this object was a class
4525 : rvalue we want to preserve that information. */
4526 0 : op1_lvalue_kind &= ~clk_ordinary;
4527 : /* The lvalue is for a bitfield. */
4528 0 : op1_lvalue_kind |= clk_bitfield;
4529 : }
4530 0 : else if (DECL_PACKED (TREE_OPERAND (ref, 1)))
4531 0 : op1_lvalue_kind |= clk_packed;
4532 :
4533 : return op1_lvalue_kind;
4534 :
4535 : case STRING_CST:
4536 : case COMPOUND_LITERAL_EXPR:
4537 : return clk_ordinary;
4538 :
4539 0 : case CONST_DECL:
4540 : /* CONST_DECL without TREE_STATIC are enumeration values and
4541 : thus not lvalues. With TREE_STATIC they are used by ObjC++
4542 : in objc_build_string_object and need to be considered as
4543 : lvalues. */
4544 0 : if (!TREE_STATIC (ref))
4545 : return clk_none;
4546 : /* FALLTHRU */
4547 0 : case VAR_DECL:
4548 0 : if (VAR_P (ref) && DECL_HAS_VALUE_EXPR_P (ref))
4549 0 : return lvalue_kind (DECL_VALUE_EXPR (const_cast<tree> (ref)));
4550 :
4551 0 : if (TREE_READONLY (ref) && !TREE_STATIC (ref) && DECL_LANG_SPECIFIC (ref)
4552 0 : && DECL_IN_AGGR_P (ref))
4553 : return clk_none;
4554 : /* FALLTHRU */
4555 : case INDIRECT_REF:
4556 : case ARROW_EXPR:
4557 : case PARM_DECL:
4558 : case RESULT_DECL:
4559 : case PLACEHOLDER_EXPR:
4560 : return clk_ordinary;
4561 :
4562 0 : case MAX_EXPR:
4563 0 : case MIN_EXPR:
4564 : /* Disallow <? and >? as lvalues if either argument side-effects. */
4565 0 : if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 0))
4566 0 : || TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 1)))
4567 : return clk_none;
4568 0 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
4569 0 : op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1));
4570 0 : break;
4571 :
4572 0 : case COND_EXPR:
4573 0 : {
4574 0 : tree op1 = TREE_OPERAND (ref, 1);
4575 0 : if (!op1)
4576 0 : op1 = TREE_OPERAND (ref, 0);
4577 0 : tree op2 = TREE_OPERAND (ref, 2);
4578 0 : op1_lvalue_kind = lvalue_kind (op1);
4579 0 : op2_lvalue_kind = lvalue_kind (op2);
4580 0 : if (!op1_lvalue_kind != !op2_lvalue_kind)
4581 : {
4582 : /* The second or the third operand (but not both) is a
4583 : throw-expression; the result is of the type
4584 : and value category of the other. */
4585 0 : if (op1_lvalue_kind && TREE_CODE (op2) == THROW_EXPR)
4586 : op2_lvalue_kind = op1_lvalue_kind;
4587 0 : else if (op2_lvalue_kind && TREE_CODE (op1) == THROW_EXPR)
4588 0 : op1_lvalue_kind = op2_lvalue_kind;
4589 : }
4590 : }
4591 : break;
4592 :
4593 : case MODIFY_EXPR:
4594 : case TYPEID_EXPR:
4595 : return clk_ordinary;
4596 :
4597 0 : case COMPOUND_EXPR:
4598 0 : return lvalue_kind (TREE_OPERAND (ref, 1));
4599 :
4600 : case TARGET_EXPR:
4601 : return clk_class;
4602 :
4603 0 : case VA_ARG_EXPR:
4604 0 : return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none);
4605 :
4606 0 : case CALL_EXPR:
4607 : /* We can see calls outside of TARGET_EXPR in templates. */
4608 0 : if (CLASS_TYPE_P (TREE_TYPE (ref)))
4609 : return clk_class;
4610 : return clk_none;
4611 :
4612 0 : case FUNCTION_DECL:
4613 : /* All functions (except non-static-member functions) are
4614 : lvalues. */
4615 0 : return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref) ? clk_none : clk_ordinary);
4616 :
4617 0 : case PAREN_EXPR:
4618 0 : return lvalue_kind (TREE_OPERAND (ref, 0));
4619 :
4620 0 : case TEMPLATE_PARM_INDEX:
4621 0 : if (CLASS_TYPE_P (TREE_TYPE (ref)))
4622 : /* A template parameter object is an lvalue. */
4623 : return clk_ordinary;
4624 : return clk_none;
4625 :
4626 0 : default:
4627 0 : if (!TREE_TYPE (ref))
4628 : return clk_none;
4629 0 : if (CLASS_TYPE_P (TREE_TYPE (ref))
4630 0 : || TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE)
4631 : return clk_class;
4632 : return clk_none;
4633 : }
4634 :
4635 : /* If one operand is not an lvalue at all, then this expression is
4636 : not an lvalue. */
4637 0 : if (!op1_lvalue_kind || !op2_lvalue_kind)
4638 : return clk_none;
4639 :
4640 : /* Otherwise, it's an lvalue, and it has all the odd properties
4641 : contributed by either operand. */
4642 0 : op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
4643 : /* It's not an ordinary lvalue if it involves any other kind. */
4644 0 : if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
4645 0 : op1_lvalue_kind &= ~clk_ordinary;
4646 : /* It can't be both a pseudo-lvalue and a non-addressable lvalue.
4647 : A COND_EXPR of those should be wrapped in a TARGET_EXPR. */
4648 0 : if ((op1_lvalue_kind & (clk_rvalueref | clk_class))
4649 0 : && (op1_lvalue_kind & (clk_bitfield | clk_packed)))
4650 0 : op1_lvalue_kind = clk_none;
4651 : return op1_lvalue_kind;
4652 : }
4653 :
4654 : // forked from gcc/cp/tree.cc glvalue_p
4655 :
4656 : /* This differs from lvalue_p in that xvalues are included. */
4657 :
4658 : bool
4659 0 : glvalue_p (const_tree ref)
4660 : {
4661 0 : cp_lvalue_kind kind = lvalue_kind (ref);
4662 0 : if (kind & clk_class)
4663 : return false;
4664 : else
4665 0 : return (kind != clk_none);
4666 : }
4667 :
4668 : // forked from gcc/cp/init.cc cv_qualified_p
4669 :
4670 : /* Returns nonzero if TYPE is const or volatile. */
4671 :
4672 : bool
4673 0 : cv_qualified_p (const_tree type)
4674 : {
4675 0 : int quals = rs_type_quals (type);
4676 0 : return (quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)) != 0;
4677 : }
4678 :
4679 : // forked from gcc/cp/tree.cc rvalue
4680 :
4681 : /* EXPR is being used in an rvalue context. Return a version of EXPR
4682 : that is marked as an rvalue. */
4683 :
4684 : tree
4685 0 : rvalue (tree expr)
4686 : {
4687 0 : tree type;
4688 :
4689 0 : if (error_operand_p (expr))
4690 : return expr;
4691 :
4692 0 : expr = mark_rvalue_use (expr);
4693 :
4694 : /* [basic.lval]
4695 :
4696 : Non-class rvalues always have cv-unqualified types. */
4697 0 : type = TREE_TYPE (expr);
4698 0 : if (!CLASS_TYPE_P (type) && cv_qualified_p (type))
4699 0 : type = cv_unqualified (type);
4700 :
4701 : /* We need to do this for rvalue refs as well to get the right answer
4702 : from decltype; see c++/36628. */
4703 0 : if (glvalue_p (expr))
4704 : {
4705 : /* But don't use this function for class lvalues; use move (to treat an
4706 : lvalue as an xvalue) or force_rvalue (to make a prvalue copy). */
4707 0 : gcc_checking_assert (!CLASS_TYPE_P (type));
4708 0 : expr = build1 (NON_LVALUE_EXPR, type, expr);
4709 : }
4710 0 : else if (type != TREE_TYPE (expr))
4711 0 : expr = build_nop (type, expr);
4712 :
4713 : return expr;
4714 : }
4715 :
4716 : // forked from gcc/cp/tree.cc bitfield_p
4717 :
4718 : /* True if REF is a bit-field. */
4719 :
4720 : bool
4721 0 : bitfield_p (const_tree ref)
4722 : {
4723 0 : return (lvalue_kind (ref) & clk_bitfield);
4724 : }
4725 :
4726 : // forked from gcc/cp/typeck.cc cxx_mark_addressable
4727 :
4728 : /* Mark EXP saying that we need to be able to take the
4729 : address of it; it should not be allocated in a register.
4730 : Value is true if successful. ARRAY_REF_P is true if this
4731 : is for ARRAY_REF construction - in that case we don't want
4732 : to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
4733 : it is fine to use ARRAY_REFs for vector subscripts on vector
4734 : register variables.
4735 :
4736 : C++: we do not allow `current_class_ptr' to be addressable. */
4737 :
4738 : bool
4739 0 : cxx_mark_addressable (tree exp, bool array_ref_p)
4740 : {
4741 0 : tree x = exp;
4742 :
4743 0 : while (1)
4744 0 : switch (TREE_CODE (x))
4745 : {
4746 0 : case VIEW_CONVERT_EXPR:
4747 0 : if (array_ref_p && TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
4748 0 : && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))))
4749 : return true;
4750 0 : x = TREE_OPERAND (x, 0);
4751 0 : break;
4752 :
4753 0 : case COMPONENT_REF:
4754 0 : if (bitfield_p (x))
4755 0 : error ("attempt to take address of bit-field");
4756 : /* FALLTHRU */
4757 0 : case ADDR_EXPR:
4758 0 : case ARRAY_REF:
4759 0 : case REALPART_EXPR:
4760 0 : case IMAGPART_EXPR:
4761 0 : x = TREE_OPERAND (x, 0);
4762 0 : break;
4763 :
4764 0 : case PARM_DECL:
4765 0 : if (x == current_class_ptr)
4766 : {
4767 0 : error ("cannot take the address of %<this%>, which is an rvalue "
4768 : "expression");
4769 0 : TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later. */
4770 0 : return true;
4771 : }
4772 : /* Fall through. */
4773 :
4774 0 : case VAR_DECL:
4775 : /* Caller should not be trying to mark initialized
4776 : constant fields addressable. */
4777 0 : gcc_assert (DECL_LANG_SPECIFIC (x) == 0 || DECL_IN_AGGR_P (x) == 0
4778 : || TREE_STATIC (x) || DECL_EXTERNAL (x));
4779 : /* Fall through. */
4780 :
4781 0 : case RESULT_DECL:
4782 0 : if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x) && !DECL_ARTIFICIAL (x))
4783 : {
4784 0 : if (VAR_P (x) && DECL_HARD_REGISTER (x))
4785 : {
4786 0 : error ("address of explicit register variable %qD requested",
4787 : x);
4788 0 : return false;
4789 : }
4790 0 : else if (extra_warnings)
4791 0 : warning (
4792 0 : OPT_Wextra,
4793 : "address requested for %qD, which is declared %<register%>", x);
4794 : }
4795 0 : TREE_ADDRESSABLE (x) = 1;
4796 0 : return true;
4797 :
4798 0 : case CONST_DECL:
4799 0 : case FUNCTION_DECL:
4800 0 : TREE_ADDRESSABLE (x) = 1;
4801 0 : return true;
4802 :
4803 0 : case CONSTRUCTOR:
4804 0 : TREE_ADDRESSABLE (x) = 1;
4805 0 : return true;
4806 :
4807 0 : case TARGET_EXPR:
4808 0 : TREE_ADDRESSABLE (x) = 1;
4809 0 : cxx_mark_addressable (TREE_OPERAND (x, 0));
4810 0 : return true;
4811 :
4812 : default:
4813 : return true;
4814 : }
4815 : }
4816 :
4817 : // forked from gcc/cp/typeck.cc build_address
4818 :
4819 : /* Returns the address of T. This function will fold away
4820 : ADDR_EXPR of INDIRECT_REF. This is only for low-level usage;
4821 : most places should use cp_build_addr_expr instead. */
4822 :
4823 : tree
4824 0 : build_address (tree t)
4825 : {
4826 0 : if (error_operand_p (t) || !cxx_mark_addressable (t))
4827 0 : return error_mark_node;
4828 0 : gcc_checking_assert (TREE_CODE (t) != CONSTRUCTOR);
4829 0 : t = build_fold_addr_expr_loc (EXPR_LOCATION (t), t);
4830 0 : if (TREE_CODE (t) != ADDR_EXPR)
4831 0 : t = rvalue (t);
4832 : return t;
4833 : }
4834 :
4835 : // forked from gcc/cp/gp-gimplify.cc fold_builtin_source_location
4836 :
4837 : /* Fold __builtin_source_location () call. LOC is the location
4838 : of the call. */
4839 :
4840 : tree
4841 0 : fold_builtin_source_location (location_t loc)
4842 : {
4843 : // if (source_location_impl == NULL_TREE)
4844 : // {
4845 : // auto_diagnostic_group d;
4846 : // source_location_impl = get_source_location_impl_type (loc);
4847 : // if (source_location_impl == error_mark_node)
4848 : // inform (loc, "evaluating %qs", "__builtin_source_location");
4849 : // }
4850 0 : if (source_location_impl == error_mark_node)
4851 0 : return build_zero_cst (const_ptr_type_node);
4852 0 : if (source_location_table == NULL)
4853 0 : source_location_table
4854 0 : = hash_table<rust_source_location_table_entry_hash>::create_ggc (64);
4855 0 : const line_map_ordinary *map;
4856 0 : source_location_table_entry entry;
4857 0 : entry.loc = linemap_resolve_location (line_table, loc,
4858 : LRK_MACRO_EXPANSION_POINT, &map);
4859 0 : entry.uid = current_function_decl ? DECL_UID (current_function_decl) : -1;
4860 0 : entry.var = error_mark_node;
4861 0 : source_location_table_entry *entryp
4862 0 : = source_location_table->find_slot (entry, INSERT);
4863 0 : tree var;
4864 0 : if (entryp->var)
4865 : var = entryp->var;
4866 : else
4867 : {
4868 0 : char tmp_name[32];
4869 0 : ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lsrc_loc", source_location_id++);
4870 0 : var = build_decl (loc, VAR_DECL, get_identifier (tmp_name),
4871 : source_location_impl);
4872 0 : TREE_STATIC (var) = 1;
4873 0 : TREE_PUBLIC (var) = 0;
4874 0 : DECL_ARTIFICIAL (var) = 1;
4875 0 : DECL_IGNORED_P (var) = 1;
4876 0 : DECL_EXTERNAL (var) = 0;
4877 0 : DECL_DECLARED_CONSTEXPR_P (var) = 1;
4878 0 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var) = 1;
4879 0 : layout_decl (var, 0);
4880 :
4881 0 : vec<constructor_elt, va_gc> *v = NULL;
4882 0 : vec_alloc (v, 4);
4883 0 : for (tree field = TYPE_FIELDS (source_location_impl);
4884 0 : (field = next_initializable_field (field)) != NULL_TREE;
4885 0 : field = DECL_CHAIN (field))
4886 : {
4887 0 : const char *n = IDENTIFIER_POINTER (DECL_NAME (field));
4888 0 : tree val = NULL_TREE;
4889 0 : if (strcmp (n, "_M_file_name") == 0)
4890 : {
4891 0 : if (const char *fname = LOCATION_FILE (loc))
4892 : {
4893 0 : fname = remap_macro_filename (fname);
4894 0 : val = build_string_literal (strlen (fname) + 1, fname);
4895 : }
4896 : else
4897 0 : val = build_string_literal (1, "");
4898 : }
4899 0 : else if (strcmp (n, "_M_function_name") == 0)
4900 : {
4901 0 : const char *name = "todo: add function name here";
4902 :
4903 : // if (current_function_decl)
4904 : // name = cxx_printable_name (current_function_decl, 2);
4905 :
4906 0 : val = build_string_literal (strlen (name) + 1, name);
4907 : }
4908 0 : else if (strcmp (n, "_M_line") == 0)
4909 0 : val = build_int_cst (TREE_TYPE (field), LOCATION_LINE (loc));
4910 0 : else if (strcmp (n, "_M_column") == 0)
4911 0 : val = build_int_cst (TREE_TYPE (field), LOCATION_COLUMN (loc));
4912 : else
4913 0 : rust_unreachable ();
4914 0 : CONSTRUCTOR_APPEND_ELT (v, field, val);
4915 : }
4916 :
4917 0 : tree ctor = build_constructor (source_location_impl, v);
4918 0 : TREE_CONSTANT (ctor) = 1;
4919 0 : TREE_STATIC (ctor) = 1;
4920 0 : DECL_INITIAL (var) = ctor;
4921 0 : varpool_node::finalize_decl (var);
4922 0 : *entryp = entry;
4923 0 : entryp->var = var;
4924 : }
4925 :
4926 0 : return build_fold_addr_expr_with_type_loc (loc, var, const_ptr_type_node);
4927 : }
4928 :
4929 : // forked from gcc/c-family/c-common.cc braced_lists_to_strings
4930 :
4931 : /* Attempt to convert a braced array initializer list CTOR for array
4932 : TYPE into a STRING_CST for convenience and efficiency. Return
4933 : the converted string on success or the original ctor on failure. */
4934 :
4935 : static tree
4936 0 : braced_list_to_string (tree type, tree ctor, bool member)
4937 : {
4938 : /* Ignore non-members with unknown size like arrays with unspecified
4939 : bound. */
4940 0 : tree typesize = TYPE_SIZE_UNIT (type);
4941 0 : if (!member && !tree_fits_uhwi_p (typesize))
4942 : return ctor;
4943 :
4944 : /* If the target char size differes from the host char size, we'd risk
4945 : loosing data and getting object sizes wrong by converting to
4946 : host chars. */
4947 0 : if (TYPE_PRECISION (char_type_node) != CHAR_BIT)
4948 : return ctor;
4949 :
4950 : /* If the array has an explicit bound, use it to constrain the size
4951 : of the string. If it doesn't, be sure to create a string that's
4952 : as long as implied by the index of the last zero specified via
4953 : a designator, as in:
4954 : const char a[] = { [7] = 0 }; */
4955 0 : unsigned HOST_WIDE_INT maxelts;
4956 0 : if (typesize)
4957 : {
4958 0 : maxelts = tree_to_uhwi (typesize);
4959 0 : maxelts /= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type)));
4960 : }
4961 : else
4962 : maxelts = HOST_WIDE_INT_M1U;
4963 :
4964 : /* Avoid converting initializers for zero-length arrays (but do
4965 : create them for flexible array members). */
4966 0 : if (!maxelts)
4967 : return ctor;
4968 :
4969 0 : unsigned HOST_WIDE_INT nelts = CONSTRUCTOR_NELTS (ctor);
4970 :
4971 0 : auto_vec<char> str;
4972 0 : str.reserve (nelts + 1);
4973 :
4974 0 : unsigned HOST_WIDE_INT i;
4975 0 : tree index, value;
4976 :
4977 0 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, index, value)
4978 : {
4979 0 : unsigned HOST_WIDE_INT idx = i;
4980 0 : if (index)
4981 : {
4982 0 : if (!tree_fits_uhwi_p (index))
4983 : return ctor;
4984 0 : idx = tree_to_uhwi (index);
4985 : }
4986 :
4987 : /* auto_vec is limited to UINT_MAX elements. */
4988 0 : if (idx > UINT_MAX)
4989 : return ctor;
4990 :
4991 : /* Avoid non-constant initializers. */
4992 0 : if (!tree_fits_shwi_p (value))
4993 : return ctor;
4994 :
4995 : /* Skip over embedded nuls except the last one (initializer
4996 : elements are in ascending order of indices). */
4997 0 : HOST_WIDE_INT val = tree_to_shwi (value);
4998 0 : if (!val && i + 1 < nelts)
4999 0 : continue;
5000 :
5001 0 : if (idx < str.length ())
5002 : return ctor;
5003 :
5004 : /* Bail if the CTOR has a block of more than 256 embedded nuls
5005 : due to implicitly initialized elements. */
5006 0 : unsigned nchars = (idx - str.length ()) + 1;
5007 0 : if (nchars > 256)
5008 : return ctor;
5009 :
5010 0 : if (nchars > 1)
5011 : {
5012 0 : str.reserve (idx);
5013 0 : str.quick_grow_cleared (idx);
5014 : }
5015 :
5016 0 : if (idx >= maxelts)
5017 : return ctor;
5018 :
5019 0 : str.safe_insert (idx, val);
5020 : }
5021 :
5022 : /* Append a nul string termination. */
5023 0 : if (maxelts != HOST_WIDE_INT_M1U && str.length () < maxelts)
5024 0 : str.safe_push (0);
5025 :
5026 : /* Build a STRING_CST with the same type as the array. */
5027 0 : tree res = build_string (str.length (), str.begin ());
5028 0 : TREE_TYPE (res) = type;
5029 0 : return res;
5030 0 : }
5031 :
5032 : // forked from gcc/c-family/c-common.cc braced_lists_to_strings
5033 :
5034 : /* Implementation of the two-argument braced_lists_to_string withe
5035 : the same arguments plus MEMBER which is set for struct members
5036 : to allow initializers for flexible member arrays. */
5037 :
5038 : static tree
5039 0 : braced_lists_to_strings (tree type, tree ctor, bool member)
5040 : {
5041 0 : if (TREE_CODE (ctor) != CONSTRUCTOR)
5042 : return ctor;
5043 :
5044 0 : tree_code code = TREE_CODE (type);
5045 :
5046 0 : tree ttp;
5047 0 : if (code == ARRAY_TYPE)
5048 0 : ttp = TREE_TYPE (type);
5049 0 : else if (code == RECORD_TYPE)
5050 : {
5051 0 : ttp = TREE_TYPE (ctor);
5052 0 : if (TREE_CODE (ttp) == ARRAY_TYPE)
5053 : {
5054 0 : type = ttp;
5055 0 : ttp = TREE_TYPE (ttp);
5056 : }
5057 : }
5058 : else
5059 : return ctor;
5060 :
5061 0 : if ((TREE_CODE (ttp) == ARRAY_TYPE || TREE_CODE (ttp) == INTEGER_TYPE)
5062 0 : && TYPE_STRING_FLAG (ttp))
5063 0 : return braced_list_to_string (type, ctor, member);
5064 :
5065 0 : code = TREE_CODE (ttp);
5066 0 : if (code == ARRAY_TYPE || RECORD_OR_UNION_TYPE_P (ttp))
5067 : {
5068 0 : bool rec = RECORD_OR_UNION_TYPE_P (ttp);
5069 :
5070 : /* Handle array of arrays or struct member initializers. */
5071 0 : tree val;
5072 0 : unsigned HOST_WIDE_INT idx;
5073 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), idx, val)
5074 : {
5075 0 : val = braced_lists_to_strings (ttp, val, rec);
5076 0 : CONSTRUCTOR_ELT (ctor, idx)->value = val;
5077 : }
5078 : }
5079 :
5080 : return ctor;
5081 : }
5082 :
5083 : // forked from gcc/c-family/c-common.cc braced_lists_to_strings
5084 :
5085 : /* Attempt to convert a CTOR containing braced array initializer lists
5086 : for array TYPE into one containing STRING_CSTs, for convenience and
5087 : efficiency. Recurse for arrays of arrays and member initializers.
5088 : Return the converted CTOR or STRING_CST on success or the original
5089 : CTOR otherwise. */
5090 :
5091 : tree
5092 0 : braced_lists_to_strings (tree type, tree ctor)
5093 : {
5094 0 : return braced_lists_to_strings (type, ctor, false);
5095 : }
5096 :
5097 : /*---------------------------------------------------------------------------
5098 : Constraint satisfaction
5099 : ---------------------------------------------------------------------------*/
5100 :
5101 : // forked from gcc/cp/constraint.cc satisfying_constraint
5102 :
5103 : /* True if we are currently satisfying a failed_type_completions. */
5104 :
5105 : static bool satisfying_constraint;
5106 :
5107 : // forked from gcc/cp/constraint.cc satisfying_constraint
5108 :
5109 : /* A vector of incomplete types (and of declarations with undeduced return
5110 : type), appended to by note_failed_type_completion_for_satisfaction. The
5111 : satisfaction caches use this in order to keep track of "potentially unstable"
5112 : satisfaction results.
5113 :
5114 : Since references to entries in this vector are stored only in the
5115 : GC-deletable sat_cache, it's safe to make this deletable as well. */
5116 :
5117 : static GTY ((deletable)) vec<tree, va_gc> *failed_type_completions;
5118 :
5119 : // forked from gcc/cp/constraint.cc note_failed_type_completion_for_satisfaction
5120 :
5121 : /* Called whenever a type completion (or return type deduction) failure occurs
5122 : that definitely affects the meaning of the program, by e.g. inducing
5123 : substitution failure. */
5124 :
5125 : void
5126 0 : note_failed_type_completion_for_satisfaction (tree t)
5127 : {
5128 0 : if (satisfying_constraint)
5129 : {
5130 0 : gcc_checking_assert ((TYPE_P (t) && !COMPLETE_TYPE_P (t))
5131 : || (DECL_P (t) && undeduced_auto_decl (t)));
5132 0 : vec_safe_push (failed_type_completions, t);
5133 : }
5134 0 : }
5135 :
5136 : // forked from gcc/cp/typeck.cc complete_type
5137 :
5138 : /* Try to complete TYPE, if it is incomplete. For example, if TYPE is
5139 : a template instantiation, do the instantiation. Returns TYPE,
5140 : whether or not it could be completed, unless something goes
5141 : horribly wrong, in which case the error_mark_node is returned. */
5142 :
5143 : tree
5144 0 : complete_type (tree type)
5145 : {
5146 0 : if (type == NULL_TREE)
5147 : /* Rather than crash, we return something sure to cause an error
5148 : at some point. */
5149 0 : return error_mark_node;
5150 :
5151 0 : if (type == error_mark_node || COMPLETE_TYPE_P (type))
5152 : ;
5153 0 : else if (TREE_CODE (type) == ARRAY_TYPE)
5154 : {
5155 0 : tree t = complete_type (TREE_TYPE (type));
5156 0 : unsigned int needs_constructing, has_nontrivial_dtor;
5157 0 : if (COMPLETE_TYPE_P (t))
5158 0 : layout_type (type);
5159 0 : needs_constructing = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t));
5160 0 : has_nontrivial_dtor
5161 0 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (t));
5162 0 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
5163 : {
5164 0 : TYPE_NEEDS_CONSTRUCTING (t) = needs_constructing;
5165 0 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = has_nontrivial_dtor;
5166 : }
5167 : }
5168 :
5169 : return type;
5170 : }
5171 :
5172 : // forked from gcc/cp/typeck.cc complete_type_or_maybe_complain
5173 :
5174 : /* Like complete_type, but issue an error if the TYPE cannot be completed.
5175 : VALUE is used for informative diagnostics.
5176 : Returns NULL_TREE if the type cannot be made complete. */
5177 :
5178 : tree
5179 0 : complete_type_or_maybe_complain (tree type, tree value, tsubst_flags_t complain)
5180 : {
5181 0 : type = complete_type (type);
5182 0 : if (type == error_mark_node)
5183 : /* We already issued an error. */
5184 : return NULL_TREE;
5185 0 : else if (!COMPLETE_TYPE_P (type))
5186 : {
5187 0 : if (complain & tf_error)
5188 0 : cxx_incomplete_type_diagnostic (value, type, diagnostics::kind::error);
5189 0 : note_failed_type_completion_for_satisfaction (type);
5190 0 : return NULL_TREE;
5191 : }
5192 : else
5193 : return type;
5194 : }
5195 :
5196 : // forked from gcc/cp/typeck.cc complete_type_or_else
5197 :
5198 : tree
5199 0 : complete_type_or_else (tree type, tree value)
5200 : {
5201 0 : return complete_type_or_maybe_complain (type, value, tf_warning_or_error);
5202 : }
5203 :
5204 : // forked from gcc/cp/tree.cc std_layout_type_p
5205 :
5206 : /* Returns true iff T is a standard-layout type, as defined in
5207 : [basic.types]. */
5208 :
5209 : bool
5210 0 : std_layout_type_p (const_tree t)
5211 : {
5212 0 : t = strip_array_types (const_cast<tree> (t));
5213 :
5214 0 : if (CLASS_TYPE_P (t))
5215 0 : return !CLASSTYPE_NON_STD_LAYOUT (t);
5216 : else
5217 0 : return scalarish_type_p (t);
5218 : }
5219 :
5220 : // forked from /gcc/cp/semantics.cc first_nonstatic_data_member_p
5221 :
5222 : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
5223 : return true if MEMBERTYPE is the type of the first non-static data member
5224 : of TYPE or for unions of any members. */
5225 : static bool
5226 0 : first_nonstatic_data_member_p (tree type, tree membertype)
5227 : {
5228 0 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
5229 : {
5230 0 : if (TREE_CODE (field) != FIELD_DECL)
5231 0 : continue;
5232 0 : if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
5233 0 : continue;
5234 0 : if (DECL_FIELD_IS_BASE (field))
5235 0 : return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
5236 0 : if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
5237 : {
5238 0 : if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
5239 0 : || std_layout_type_p (TREE_TYPE (field)))
5240 0 : && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
5241 : return true;
5242 : }
5243 0 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
5244 : membertype))
5245 : return true;
5246 0 : if (TREE_CODE (type) != UNION_TYPE)
5247 : return false;
5248 : }
5249 : return false;
5250 : }
5251 :
5252 : // forked from gcc/cp/semantics.cc
5253 : // fold_builtin_is_pointer_inverconvertible_with_class
5254 :
5255 : /* Fold __builtin_is_pointer_interconvertible_with_class call. */
5256 :
5257 : tree
5258 0 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
5259 : tree *args)
5260 : {
5261 : /* Unless users call the builtin directly, the following 3 checks should be
5262 : ensured from std::is_pointer_interconvertible_with_class function
5263 : template. */
5264 0 : if (nargs != 1)
5265 : {
5266 0 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
5267 : "needs a single argument");
5268 0 : return boolean_false_node;
5269 : }
5270 0 : tree arg = args[0];
5271 0 : if (error_operand_p (arg))
5272 0 : return boolean_false_node;
5273 0 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
5274 : {
5275 0 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
5276 : "argument is not pointer to member");
5277 0 : return boolean_false_node;
5278 : }
5279 :
5280 0 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
5281 0 : return boolean_false_node;
5282 :
5283 0 : tree membertype = TREE_TYPE (TREE_TYPE (arg));
5284 0 : tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
5285 0 : if (!complete_type_or_else (basetype, NULL_TREE))
5286 0 : return boolean_false_node;
5287 :
5288 0 : if (TREE_CODE (basetype) != UNION_TYPE && !std_layout_type_p (basetype))
5289 0 : return boolean_false_node;
5290 :
5291 0 : if (!first_nonstatic_data_member_p (basetype, membertype))
5292 0 : return boolean_false_node;
5293 :
5294 0 : if (integer_nonzerop (arg))
5295 0 : return boolean_false_node;
5296 0 : if (integer_zerop (arg))
5297 0 : return boolean_true_node;
5298 :
5299 0 : return fold_build2 (EQ_EXPR, boolean_type_node, arg,
5300 : build_zero_cst (TREE_TYPE (arg)));
5301 : }
5302 :
5303 : // forked from gcc/c-family/c-common.cc registered_builtin_types
5304 :
5305 : /* Used for communication between c_common_type_for_mode and
5306 : c_register_builtin_type. */
5307 : tree registered_builtin_types;
5308 :
5309 : /* Return a data type that has machine mode MODE.
5310 : If the mode is an integer,
5311 : then UNSIGNEDP selects between signed and unsigned types.
5312 : If the mode is a fixed-point mode,
5313 : then UNSIGNEDP selects between saturating and nonsaturating types. */
5314 :
5315 : // forked from gcc/c-family/c-common.cc c_common_type_for_mode
5316 :
5317 : tree
5318 0 : c_common_type_for_mode (machine_mode mode, int unsignedp)
5319 : {
5320 0 : tree t;
5321 0 : int i;
5322 :
5323 0 : if (mode == TYPE_MODE (integer_type_node))
5324 0 : return unsignedp ? unsigned_type_node : integer_type_node;
5325 :
5326 0 : if (mode == TYPE_MODE (signed_char_type_node))
5327 0 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
5328 :
5329 0 : if (mode == TYPE_MODE (short_integer_type_node))
5330 0 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
5331 :
5332 0 : if (mode == TYPE_MODE (long_integer_type_node))
5333 0 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
5334 :
5335 0 : if (mode == TYPE_MODE (long_long_integer_type_node))
5336 0 : return unsignedp ? long_long_unsigned_type_node
5337 0 : : long_long_integer_type_node;
5338 :
5339 0 : for (i = 0; i < NUM_INT_N_ENTS; i++)
5340 0 : if (int_n_enabled_p[i] && mode == int_n_data[i].m)
5341 0 : return (unsignedp ? int_n_trees[i].unsigned_type
5342 0 : : int_n_trees[i].signed_type);
5343 :
5344 0 : if (mode == QImode)
5345 0 : return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
5346 :
5347 0 : if (mode == HImode)
5348 0 : return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
5349 :
5350 0 : if (mode == SImode)
5351 0 : return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
5352 :
5353 0 : if (mode == DImode)
5354 0 : return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
5355 :
5356 : #if HOST_BITS_PER_WIDE_INT >= 64
5357 0 : if (mode == TYPE_MODE (intTI_type_node))
5358 0 : return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
5359 : #endif
5360 :
5361 0 : if (mode == TYPE_MODE (float_type_node))
5362 0 : return float_type_node;
5363 :
5364 0 : if (mode == TYPE_MODE (double_type_node))
5365 0 : return double_type_node;
5366 :
5367 0 : if (mode == TYPE_MODE (long_double_type_node))
5368 0 : return long_double_type_node;
5369 :
5370 0 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
5371 0 : if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE
5372 0 : && mode == TYPE_MODE (FLOATN_NX_TYPE_NODE (i)))
5373 0 : return FLOATN_NX_TYPE_NODE (i);
5374 :
5375 0 : if (mode == TYPE_MODE (void_type_node))
5376 0 : return void_type_node;
5377 :
5378 0 : if (mode == TYPE_MODE (build_pointer_type (char_type_node))
5379 0 : || mode == TYPE_MODE (build_pointer_type (integer_type_node)))
5380 : {
5381 0 : unsigned int precision
5382 0 : = GET_MODE_PRECISION (as_a<scalar_int_mode> (mode));
5383 0 : return (unsignedp ? make_unsigned_type (precision)
5384 0 : : make_signed_type (precision));
5385 : }
5386 :
5387 0 : if (COMPLEX_MODE_P (mode))
5388 : {
5389 0 : machine_mode inner_mode;
5390 0 : tree inner_type;
5391 :
5392 0 : if (mode == TYPE_MODE (complex_float_type_node))
5393 0 : return complex_float_type_node;
5394 0 : if (mode == TYPE_MODE (complex_double_type_node))
5395 0 : return complex_double_type_node;
5396 0 : if (mode == TYPE_MODE (complex_long_double_type_node))
5397 0 : return complex_long_double_type_node;
5398 :
5399 0 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
5400 0 : if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE
5401 0 : && mode == TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i)))
5402 0 : return COMPLEX_FLOATN_NX_TYPE_NODE (i);
5403 :
5404 0 : if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
5405 0 : return complex_integer_type_node;
5406 :
5407 0 : inner_mode = GET_MODE_INNER (mode);
5408 0 : inner_type = c_common_type_for_mode (inner_mode, unsignedp);
5409 0 : if (inner_type != NULL_TREE)
5410 0 : return build_complex_type (inner_type);
5411 : }
5412 0 : else if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL
5413 0 : && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
5414 : {
5415 0 : unsigned int elem_bits = vector_element_size (GET_MODE_PRECISION (mode),
5416 : GET_MODE_NUNITS (mode));
5417 0 : tree bool_type = build_nonstandard_boolean_type (elem_bits);
5418 0 : return build_vector_type_for_mode (bool_type, mode);
5419 : }
5420 0 : else if (VECTOR_MODE_P (mode)
5421 0 : && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
5422 : {
5423 0 : machine_mode inner_mode = GET_MODE_INNER (mode);
5424 0 : tree inner_type = c_common_type_for_mode (inner_mode, unsignedp);
5425 0 : if (inner_type != NULL_TREE)
5426 0 : return build_vector_type_for_mode (inner_type, mode);
5427 : }
5428 :
5429 0 : if (dfloat32_type_node != NULL_TREE && mode == TYPE_MODE (dfloat32_type_node))
5430 0 : return dfloat32_type_node;
5431 0 : if (dfloat64_type_node != NULL_TREE && mode == TYPE_MODE (dfloat64_type_node))
5432 0 : return dfloat64_type_node;
5433 0 : if (dfloat128_type_node != NULL_TREE
5434 0 : && mode == TYPE_MODE (dfloat128_type_node))
5435 0 : return dfloat128_type_node;
5436 :
5437 0 : if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
5438 : {
5439 0 : if (mode == TYPE_MODE (short_fract_type_node))
5440 0 : return unsignedp ? sat_short_fract_type_node : short_fract_type_node;
5441 0 : if (mode == TYPE_MODE (fract_type_node))
5442 0 : return unsignedp ? sat_fract_type_node : fract_type_node;
5443 0 : if (mode == TYPE_MODE (long_fract_type_node))
5444 0 : return unsignedp ? sat_long_fract_type_node : long_fract_type_node;
5445 0 : if (mode == TYPE_MODE (long_long_fract_type_node))
5446 0 : return unsignedp ? sat_long_long_fract_type_node
5447 0 : : long_long_fract_type_node;
5448 :
5449 0 : if (mode == TYPE_MODE (unsigned_short_fract_type_node))
5450 0 : return unsignedp ? sat_unsigned_short_fract_type_node
5451 0 : : unsigned_short_fract_type_node;
5452 0 : if (mode == TYPE_MODE (unsigned_fract_type_node))
5453 0 : return unsignedp ? sat_unsigned_fract_type_node
5454 0 : : unsigned_fract_type_node;
5455 0 : if (mode == TYPE_MODE (unsigned_long_fract_type_node))
5456 0 : return unsignedp ? sat_unsigned_long_fract_type_node
5457 0 : : unsigned_long_fract_type_node;
5458 0 : if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
5459 0 : return unsignedp ? sat_unsigned_long_long_fract_type_node
5460 0 : : unsigned_long_long_fract_type_node;
5461 :
5462 0 : if (mode == TYPE_MODE (short_accum_type_node))
5463 0 : return unsignedp ? sat_short_accum_type_node : short_accum_type_node;
5464 0 : if (mode == TYPE_MODE (accum_type_node))
5465 0 : return unsignedp ? sat_accum_type_node : accum_type_node;
5466 0 : if (mode == TYPE_MODE (long_accum_type_node))
5467 0 : return unsignedp ? sat_long_accum_type_node : long_accum_type_node;
5468 0 : if (mode == TYPE_MODE (long_long_accum_type_node))
5469 0 : return unsignedp ? sat_long_long_accum_type_node
5470 0 : : long_long_accum_type_node;
5471 :
5472 0 : if (mode == TYPE_MODE (unsigned_short_accum_type_node))
5473 0 : return unsignedp ? sat_unsigned_short_accum_type_node
5474 0 : : unsigned_short_accum_type_node;
5475 0 : if (mode == TYPE_MODE (unsigned_accum_type_node))
5476 0 : return unsignedp ? sat_unsigned_accum_type_node
5477 0 : : unsigned_accum_type_node;
5478 0 : if (mode == TYPE_MODE (unsigned_long_accum_type_node))
5479 0 : return unsignedp ? sat_unsigned_long_accum_type_node
5480 0 : : unsigned_long_accum_type_node;
5481 0 : if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
5482 0 : return unsignedp ? sat_unsigned_long_long_accum_type_node
5483 0 : : unsigned_long_long_accum_type_node;
5484 :
5485 0 : if (mode == QQmode)
5486 0 : return unsignedp ? sat_qq_type_node : qq_type_node;
5487 : if (mode == HQmode)
5488 0 : return unsignedp ? sat_hq_type_node : hq_type_node;
5489 : if (mode == SQmode)
5490 0 : return unsignedp ? sat_sq_type_node : sq_type_node;
5491 : if (mode == DQmode)
5492 0 : return unsignedp ? sat_dq_type_node : dq_type_node;
5493 : if (mode == TQmode)
5494 0 : return unsignedp ? sat_tq_type_node : tq_type_node;
5495 :
5496 : if (mode == UQQmode)
5497 0 : return unsignedp ? sat_uqq_type_node : uqq_type_node;
5498 : if (mode == UHQmode)
5499 0 : return unsignedp ? sat_uhq_type_node : uhq_type_node;
5500 : if (mode == USQmode)
5501 0 : return unsignedp ? sat_usq_type_node : usq_type_node;
5502 : if (mode == UDQmode)
5503 0 : return unsignedp ? sat_udq_type_node : udq_type_node;
5504 : if (mode == UTQmode)
5505 0 : return unsignedp ? sat_utq_type_node : utq_type_node;
5506 :
5507 : if (mode == HAmode)
5508 0 : return unsignedp ? sat_ha_type_node : ha_type_node;
5509 : if (mode == SAmode)
5510 0 : return unsignedp ? sat_sa_type_node : sa_type_node;
5511 : if (mode == DAmode)
5512 0 : return unsignedp ? sat_da_type_node : da_type_node;
5513 : if (mode == TAmode)
5514 0 : return unsignedp ? sat_ta_type_node : ta_type_node;
5515 :
5516 : if (mode == UHAmode)
5517 0 : return unsignedp ? sat_uha_type_node : uha_type_node;
5518 : if (mode == USAmode)
5519 0 : return unsignedp ? sat_usa_type_node : usa_type_node;
5520 : if (mode == UDAmode)
5521 0 : return unsignedp ? sat_uda_type_node : uda_type_node;
5522 : if (mode == UTAmode)
5523 0 : return unsignedp ? sat_uta_type_node : uta_type_node;
5524 : }
5525 :
5526 0 : for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
5527 : {
5528 0 : tree type = TREE_VALUE (t);
5529 0 : if (TYPE_MODE (type) == mode
5530 0 : && VECTOR_TYPE_P (type) == VECTOR_MODE_P (mode)
5531 0 : && !!unsignedp == !!TYPE_UNSIGNED (type))
5532 : return type;
5533 : }
5534 : return NULL_TREE;
5535 : }
5536 :
5537 : // forked from gcc/cp/semantics.cc finish_underlying_type
5538 :
5539 : /* Implement the __underlying_type keyword: Return the underlying
5540 : type of TYPE, suitable for use as a type-specifier. */
5541 :
5542 : tree
5543 0 : finish_underlying_type (tree type)
5544 : {
5545 0 : tree underlying_type;
5546 :
5547 0 : if (!complete_type_or_else (type, NULL_TREE))
5548 0 : return error_mark_node;
5549 :
5550 0 : if (TREE_CODE (type) != ENUMERAL_TYPE)
5551 : {
5552 0 : error ("%qT is not an enumeration type", type);
5553 0 : return error_mark_node;
5554 : }
5555 :
5556 0 : underlying_type = ENUM_UNDERLYING_TYPE (type);
5557 :
5558 : /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
5559 : includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
5560 : See finish_enum_value_list for details. */
5561 0 : if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
5562 0 : underlying_type = c_common_type_for_mode (TYPE_MODE (underlying_type),
5563 0 : TYPE_UNSIGNED (underlying_type));
5564 :
5565 : return underlying_type;
5566 : }
5567 :
5568 : // forked from gcc/cp/typeck.cc layout_compatible_type_p
5569 :
5570 : /* Return true if TYPE1 and TYPE2 are layout-compatible types. */
5571 :
5572 : bool
5573 0 : layout_compatible_type_p (tree type1, tree type2)
5574 : {
5575 0 : if (type1 == error_mark_node || type2 == error_mark_node)
5576 : return false;
5577 0 : if (type1 == type2)
5578 : return true;
5579 0 : if (TREE_CODE (type1) != TREE_CODE (type2))
5580 : return false;
5581 :
5582 0 : type1 = rs_build_qualified_type (type1, TYPE_UNQUALIFIED);
5583 0 : type2 = rs_build_qualified_type (type2, TYPE_UNQUALIFIED);
5584 :
5585 0 : if (TREE_CODE (type1) == ENUMERAL_TYPE)
5586 0 : return (TYPE_ALIGN (type1) == TYPE_ALIGN (type2)
5587 0 : && tree_int_cst_equal (TYPE_SIZE (type1), TYPE_SIZE (type2))
5588 0 : && same_type_p (finish_underlying_type (type1),
5589 : finish_underlying_type (type2)));
5590 :
5591 0 : if (CLASS_TYPE_P (type1) && std_layout_type_p (type1)
5592 0 : && std_layout_type_p (type2) && TYPE_ALIGN (type1) == TYPE_ALIGN (type2)
5593 0 : && tree_int_cst_equal (TYPE_SIZE (type1), TYPE_SIZE (type2)))
5594 : {
5595 0 : tree field1 = TYPE_FIELDS (type1);
5596 0 : tree field2 = TYPE_FIELDS (type2);
5597 0 : if (TREE_CODE (type1) == RECORD_TYPE)
5598 : {
5599 0 : while (1)
5600 : {
5601 0 : if (!next_common_initial_seqence (field1, field2))
5602 : return false;
5603 0 : if (field1 == NULL_TREE)
5604 : return true;
5605 0 : field1 = DECL_CHAIN (field1);
5606 0 : field2 = DECL_CHAIN (field2);
5607 : }
5608 : }
5609 : /* Otherwise both types must be union types.
5610 : The standard says:
5611 : "Two standard-layout unions are layout-compatible if they have
5612 : the same number of non-static data members and corresponding
5613 : non-static data members (in any order) have layout-compatible
5614 : types."
5615 : but the code anticipates that bitfield vs. non-bitfield,
5616 : different bitfield widths or presence/absence of
5617 : [[no_unique_address]] should be checked as well. */
5618 0 : auto_vec<tree, 16> vec;
5619 0 : unsigned int count = 0;
5620 0 : for (; field1; field1 = DECL_CHAIN (field1))
5621 0 : if (TREE_CODE (field1) == FIELD_DECL)
5622 0 : count++;
5623 0 : for (; field2; field2 = DECL_CHAIN (field2))
5624 0 : if (TREE_CODE (field2) == FIELD_DECL)
5625 0 : vec.safe_push (field2);
5626 : /* Discussions on core lean towards treating multiple union fields
5627 : of the same type as the same field, so this might need changing
5628 : in the future. */
5629 0 : if (count != vec.length ())
5630 : return false;
5631 0 : for (field1 = TYPE_FIELDS (type1); field1; field1 = DECL_CHAIN (field1))
5632 : {
5633 0 : if (TREE_CODE (field1) != FIELD_DECL)
5634 0 : continue;
5635 0 : unsigned int j;
5636 0 : tree t1 = DECL_BIT_FIELD_TYPE (field1);
5637 0 : if (t1 == NULL_TREE)
5638 0 : t1 = TREE_TYPE (field1);
5639 0 : FOR_EACH_VEC_ELT (vec, j, field2)
5640 : {
5641 0 : tree t2 = DECL_BIT_FIELD_TYPE (field2);
5642 0 : if (t2 == NULL_TREE)
5643 0 : t2 = TREE_TYPE (field2);
5644 0 : if (DECL_BIT_FIELD_TYPE (field1))
5645 : {
5646 0 : if (!DECL_BIT_FIELD_TYPE (field2))
5647 0 : continue;
5648 0 : if (TYPE_PRECISION (TREE_TYPE (field1))
5649 0 : != TYPE_PRECISION (TREE_TYPE (field2)))
5650 0 : continue;
5651 : }
5652 0 : else if (DECL_BIT_FIELD_TYPE (field2))
5653 0 : continue;
5654 0 : if (!layout_compatible_type_p (t1, t2))
5655 0 : continue;
5656 0 : if ((!lookup_attribute ("no_unique_address",
5657 0 : DECL_ATTRIBUTES (field1)))
5658 0 : != !lookup_attribute ("no_unique_address",
5659 0 : DECL_ATTRIBUTES (field2)))
5660 0 : continue;
5661 : break;
5662 : }
5663 0 : if (j == vec.length ())
5664 : return false;
5665 0 : vec.unordered_remove (j);
5666 : }
5667 : return true;
5668 0 : }
5669 :
5670 0 : return same_type_p (type1, type2);
5671 : }
5672 :
5673 : // forked from gcc/cp/semnatics.cc is_corresponding_member_union
5674 :
5675 : /* Helper function for is_corresponding_member_aggr. Return true if
5676 : MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
5677 : union or structure BASETYPE. */
5678 :
5679 : static bool
5680 0 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
5681 : {
5682 0 : for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
5683 0 : if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
5684 0 : continue;
5685 0 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
5686 : membertype))
5687 : {
5688 0 : if (TREE_CODE (arg) != INTEGER_CST
5689 0 : || tree_int_cst_equal (arg, byte_position (field)))
5690 : return true;
5691 : }
5692 0 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
5693 : {
5694 0 : tree narg = arg;
5695 0 : if (TREE_CODE (basetype) != UNION_TYPE
5696 0 : && TREE_CODE (narg) == INTEGER_CST)
5697 0 : narg = size_binop (MINUS_EXPR, arg, byte_position (field));
5698 0 : if (is_corresponding_member_union (TREE_TYPE (field), membertype, narg))
5699 : return true;
5700 : }
5701 : return false;
5702 : }
5703 :
5704 : // forked from gcc/cp/typeck.cc next_common_initial_seqence
5705 :
5706 : /* Helper function for layout_compatible_type_p and
5707 : is_corresponding_member_aggr. Advance to next members (NULL if
5708 : no further ones) and return true if those members are still part of
5709 : the common initial sequence. */
5710 :
5711 : bool
5712 0 : next_common_initial_seqence (tree &memb1, tree &memb2)
5713 : {
5714 0 : while (memb1)
5715 : {
5716 0 : if (TREE_CODE (memb1) != FIELD_DECL
5717 0 : || (DECL_FIELD_IS_BASE (memb1) && is_empty_field (memb1)))
5718 : {
5719 0 : memb1 = DECL_CHAIN (memb1);
5720 0 : continue;
5721 : }
5722 0 : if (DECL_FIELD_IS_BASE (memb1))
5723 : {
5724 0 : memb1 = TYPE_FIELDS (TREE_TYPE (memb1));
5725 0 : continue;
5726 : }
5727 : break;
5728 : }
5729 0 : while (memb2)
5730 : {
5731 0 : if (TREE_CODE (memb2) != FIELD_DECL
5732 0 : || (DECL_FIELD_IS_BASE (memb2) && is_empty_field (memb2)))
5733 : {
5734 0 : memb2 = DECL_CHAIN (memb2);
5735 0 : continue;
5736 : }
5737 0 : if (DECL_FIELD_IS_BASE (memb2))
5738 : {
5739 0 : memb2 = TYPE_FIELDS (TREE_TYPE (memb2));
5740 0 : continue;
5741 : }
5742 : break;
5743 : }
5744 0 : if (memb1 == NULL_TREE && memb2 == NULL_TREE)
5745 : return true;
5746 0 : if (memb1 == NULL_TREE || memb2 == NULL_TREE)
5747 : return false;
5748 0 : if (DECL_BIT_FIELD_TYPE (memb1))
5749 : {
5750 0 : if (!DECL_BIT_FIELD_TYPE (memb2))
5751 : return false;
5752 0 : if (!layout_compatible_type_p (DECL_BIT_FIELD_TYPE (memb1),
5753 0 : DECL_BIT_FIELD_TYPE (memb2)))
5754 : return false;
5755 0 : if (TYPE_PRECISION (TREE_TYPE (memb1))
5756 0 : != TYPE_PRECISION (TREE_TYPE (memb2)))
5757 : return false;
5758 : }
5759 0 : else if (DECL_BIT_FIELD_TYPE (memb2))
5760 : return false;
5761 0 : else if (!layout_compatible_type_p (TREE_TYPE (memb1), TREE_TYPE (memb2)))
5762 : return false;
5763 0 : if ((!lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb1)))
5764 0 : != !lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb2)))
5765 : return false;
5766 0 : if (!tree_int_cst_equal (bit_position (memb1), bit_position (memb2)))
5767 : return false;
5768 : return true;
5769 : }
5770 :
5771 : // forked from gcc/cp/semantics.cc is_corresponding_member_aggr
5772 :
5773 : /* Helper function for fold_builtin_is_corresponding_member call.
5774 : Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
5775 : MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
5776 : boolean_true_node if they are corresponding members, or for
5777 : non-constant ARG2 the highest member offset for corresponding
5778 : members. */
5779 :
5780 : static tree
5781 0 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
5782 : tree arg1, tree basetype2, tree membertype2,
5783 : tree arg2)
5784 : {
5785 0 : tree field1 = TYPE_FIELDS (basetype1);
5786 0 : tree field2 = TYPE_FIELDS (basetype2);
5787 0 : tree ret = boolean_false_node;
5788 0 : while (1)
5789 : {
5790 0 : bool r = next_common_initial_seqence (field1, field2);
5791 0 : if (field1 == NULL_TREE || field2 == NULL_TREE)
5792 : break;
5793 0 : if (r
5794 0 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
5795 : membertype1)
5796 0 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
5797 : membertype2))
5798 : {
5799 0 : tree pos = byte_position (field1);
5800 0 : if (TREE_CODE (arg1) == INTEGER_CST && tree_int_cst_equal (arg1, pos))
5801 : {
5802 0 : if (TREE_CODE (arg2) == INTEGER_CST)
5803 0 : return boolean_true_node;
5804 : return pos;
5805 : }
5806 0 : else if (TREE_CODE (arg1) != INTEGER_CST)
5807 0 : ret = pos;
5808 : }
5809 0 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
5810 0 : && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
5811 : {
5812 0 : if ((!lookup_attribute ("no_unique_address",
5813 0 : DECL_ATTRIBUTES (field1)))
5814 0 : != !lookup_attribute ("no_unique_address",
5815 0 : DECL_ATTRIBUTES (field2)))
5816 : break;
5817 0 : if (!tree_int_cst_equal (bit_position (field1),
5818 0 : bit_position (field2)))
5819 : break;
5820 0 : bool overlap = true;
5821 0 : tree pos = byte_position (field1);
5822 0 : if (TREE_CODE (arg1) == INTEGER_CST)
5823 : {
5824 0 : tree off1 = fold_convert (sizetype, arg1);
5825 0 : tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
5826 0 : if (tree_int_cst_lt (off1, pos)
5827 0 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
5828 : overlap = false;
5829 : }
5830 0 : if (TREE_CODE (arg2) == INTEGER_CST)
5831 : {
5832 0 : tree off2 = fold_convert (sizetype, arg2);
5833 0 : tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
5834 0 : if (tree_int_cst_lt (off2, pos)
5835 0 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
5836 : overlap = false;
5837 : }
5838 0 : if (overlap && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
5839 0 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
5840 : {
5841 0 : tree narg1 = arg1;
5842 0 : if (TREE_CODE (arg1) == INTEGER_CST)
5843 0 : narg1
5844 0 : = size_binop (MINUS_EXPR, fold_convert (sizetype, arg1), pos);
5845 0 : tree narg2 = arg2;
5846 0 : if (TREE_CODE (arg2) == INTEGER_CST)
5847 0 : narg2
5848 0 : = size_binop (MINUS_EXPR, fold_convert (sizetype, arg2), pos);
5849 0 : tree t1 = TREE_TYPE (field1);
5850 0 : tree t2 = TREE_TYPE (field2);
5851 0 : tree nret
5852 0 : = is_corresponding_member_aggr (loc, t1, membertype1, narg1, t2,
5853 : membertype2, narg2);
5854 0 : if (nret != boolean_false_node)
5855 : {
5856 0 : if (nret == boolean_true_node)
5857 : return nret;
5858 0 : if (TREE_CODE (arg1) == INTEGER_CST)
5859 0 : return size_binop (PLUS_EXPR, nret, pos);
5860 0 : ret = size_binop (PLUS_EXPR, nret, pos);
5861 : }
5862 : }
5863 0 : else if (overlap && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
5864 0 : && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
5865 : {
5866 0 : tree narg1 = arg1;
5867 0 : if (TREE_CODE (arg1) == INTEGER_CST)
5868 0 : narg1
5869 0 : = size_binop (MINUS_EXPR, fold_convert (sizetype, arg1), pos);
5870 0 : tree narg2 = arg2;
5871 0 : if (TREE_CODE (arg2) == INTEGER_CST)
5872 0 : narg2
5873 0 : = size_binop (MINUS_EXPR, fold_convert (sizetype, arg2), pos);
5874 0 : if (is_corresponding_member_union (TREE_TYPE (field1),
5875 : membertype1, narg1)
5876 0 : && is_corresponding_member_union (TREE_TYPE (field2),
5877 : membertype2, narg2))
5878 : {
5879 0 : sorry_at (loc, "%<__builtin_is_corresponding_member%> "
5880 : "not well defined for anonymous unions");
5881 0 : return boolean_false_node;
5882 : }
5883 : }
5884 : }
5885 0 : if (!r)
5886 : break;
5887 0 : field1 = DECL_CHAIN (field1);
5888 0 : field2 = DECL_CHAIN (field2);
5889 0 : }
5890 : return ret;
5891 : }
5892 :
5893 : // forked from gcc/cp/call.cc null_member_pointer_value_p
5894 :
5895 : /* Returns true iff T is a null member pointer value (4.11). */
5896 :
5897 : bool
5898 0 : null_member_pointer_value_p (tree t)
5899 : {
5900 0 : tree type = TREE_TYPE (t);
5901 0 : if (!type)
5902 : return false;
5903 0 : else if (TYPE_PTRMEMFUNC_P (type))
5904 0 : return (TREE_CODE (t) == CONSTRUCTOR && CONSTRUCTOR_NELTS (t)
5905 0 : && integer_zerop (CONSTRUCTOR_ELT (t, 0)->value));
5906 0 : else if (TYPE_PTRDATAMEM_P (type))
5907 0 : return integer_all_onesp (t);
5908 : else
5909 : return false;
5910 : }
5911 :
5912 : // forked from gcc/cp/semantics.cc fold_builtin_is_corresponding_member
5913 :
5914 : /* Fold __builtin_is_corresponding_member call. */
5915 :
5916 : tree
5917 0 : fold_builtin_is_corresponding_member (location_t loc, int nargs, tree *args)
5918 : {
5919 : /* Unless users call the builtin directly, the following 3 checks should be
5920 : ensured from std::is_corresponding_member function template. */
5921 0 : if (nargs != 2)
5922 : {
5923 0 : error_at (loc, "%<__builtin_is_corresponding_member%> "
5924 : "needs two arguments");
5925 0 : return boolean_false_node;
5926 : }
5927 0 : tree arg1 = args[0];
5928 0 : tree arg2 = args[1];
5929 0 : if (error_operand_p (arg1) || error_operand_p (arg2))
5930 0 : return boolean_false_node;
5931 0 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg1)) || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
5932 : {
5933 0 : error_at (loc, "%<__builtin_is_corresponding_member%> "
5934 : "argument is not pointer to member");
5935 0 : return boolean_false_node;
5936 : }
5937 :
5938 0 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
5939 0 : || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
5940 0 : return boolean_false_node;
5941 :
5942 0 : tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
5943 0 : tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
5944 0 : if (!complete_type_or_else (basetype1, NULL_TREE))
5945 0 : return boolean_false_node;
5946 :
5947 0 : tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
5948 0 : tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
5949 0 : if (!complete_type_or_else (basetype2, NULL_TREE))
5950 0 : return boolean_false_node;
5951 :
5952 0 : if (!NON_UNION_CLASS_TYPE_P (basetype1) || !NON_UNION_CLASS_TYPE_P (basetype2)
5953 0 : || !std_layout_type_p (basetype1) || !std_layout_type_p (basetype2))
5954 0 : return boolean_false_node;
5955 :
5956 : /* If the member types aren't layout compatible, then they
5957 : can't be corresponding members. */
5958 0 : if (!layout_compatible_type_p (membertype1, membertype2))
5959 0 : return boolean_false_node;
5960 :
5961 0 : if (null_member_pointer_value_p (arg1) || null_member_pointer_value_p (arg2))
5962 0 : return boolean_false_node;
5963 :
5964 0 : if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg2) == INTEGER_CST
5965 0 : && !tree_int_cst_equal (arg1, arg2))
5966 0 : return boolean_false_node;
5967 :
5968 0 : if (TREE_CODE (arg2) == INTEGER_CST && TREE_CODE (arg1) != INTEGER_CST)
5969 : {
5970 : std::swap (arg1, arg2);
5971 : std::swap (membertype1, membertype2);
5972 : std::swap (basetype1, basetype2);
5973 : }
5974 :
5975 0 : tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
5976 : basetype2, membertype2, arg2);
5977 0 : if (TREE_TYPE (ret) == boolean_type_node)
5978 : return ret;
5979 : /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
5980 : already returns boolean_{true,false}_node whether those particular
5981 : members are corresponding members or not. Otherwise, if only
5982 : one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
5983 : above), it returns boolean_false_node if it is certainly not a
5984 : corresponding member and otherwise we need to do a runtime check that
5985 : those two OFFSET_TYPE offsets are equal.
5986 : If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
5987 : returns the largest offset at which the members would be corresponding
5988 : members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
5989 0 : gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
5990 0 : if (TREE_CODE (arg1) == INTEGER_CST)
5991 0 : return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
5992 : fold_convert (TREE_TYPE (arg1), arg2));
5993 0 : ret = fold_build2 (LE_EXPR, boolean_type_node,
5994 : fold_convert (pointer_sized_int_node, arg1),
5995 : fold_convert (pointer_sized_int_node, ret));
5996 0 : return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
5997 : fold_build2 (EQ_EXPR, boolean_type_node, arg1,
5998 : fold_convert (TREE_TYPE (arg1), arg2)));
5999 : }
6000 :
6001 : // forked from gcc/cp/tree.cc lvalue_type
6002 :
6003 : /* The type of ARG when used as an lvalue. */
6004 :
6005 : tree
6006 0 : lvalue_type (tree arg)
6007 : {
6008 0 : tree type = TREE_TYPE (arg);
6009 0 : return type;
6010 : }
6011 :
6012 : // forked from gcc/c-family/c-warn.cc lvalue_error
6013 :
6014 : /* Print an error message for an invalid lvalue. USE says
6015 : how the lvalue is being used and so selects the error message. LOC
6016 : is the location for the error. */
6017 :
6018 : void
6019 0 : lvalue_error (location_t loc, enum lvalue_use use)
6020 : {
6021 0 : switch (use)
6022 : {
6023 0 : case lv_assign:
6024 0 : error_at (loc, "lvalue required as left operand of assignment");
6025 0 : break;
6026 0 : case lv_increment:
6027 0 : error_at (loc, "lvalue required as increment operand");
6028 0 : break;
6029 0 : case lv_decrement:
6030 0 : error_at (loc, "lvalue required as decrement operand");
6031 0 : break;
6032 0 : case lv_addressof:
6033 0 : error_at (loc, "lvalue required as unary %<&%> operand");
6034 0 : break;
6035 0 : case lv_asm:
6036 0 : error_at (loc, "lvalue required in %<asm%> statement");
6037 0 : break;
6038 0 : default:
6039 0 : rust_unreachable ();
6040 : }
6041 0 : }
6042 :
6043 : // forked from gcc/cp/cp--gimplify.cc cp_fold_maybe_rvalue
6044 :
6045 : /* Fold expression X which is used as an rvalue if RVAL is true. */
6046 :
6047 : tree
6048 0 : cp_fold_maybe_rvalue (tree x, bool rval)
6049 : {
6050 0 : while (true)
6051 : {
6052 0 : x = fold (x);
6053 0 : if (rval)
6054 0 : x = mark_rvalue_use (x);
6055 0 : if (rval && DECL_P (x) && !TYPE_REF_P (TREE_TYPE (x)))
6056 : {
6057 0 : tree v = decl_constant_value (x);
6058 0 : if (v != x && v != error_mark_node)
6059 : {
6060 0 : x = v;
6061 0 : continue;
6062 : }
6063 : }
6064 0 : break;
6065 0 : }
6066 0 : return x;
6067 : }
6068 :
6069 : // forked from gcc/cp/cp--gimplify.cc cp_fold_rvalue
6070 :
6071 : /* Fold expression X which is used as an rvalue. */
6072 :
6073 : tree
6074 0 : cp_fold_rvalue (tree x)
6075 : {
6076 0 : return cp_fold_maybe_rvalue (x, true);
6077 : }
6078 :
6079 : /* Returns true iff class T has a constexpr destructor or has an
6080 : implicitly declared destructor that we can't tell if it's constexpr
6081 : without forcing a lazy declaration (which might cause undesired
6082 : instantiations). */
6083 :
6084 : static bool
6085 0 : type_maybe_constexpr_destructor (tree t)
6086 : {
6087 : /* Until C++20, only trivial destruction is constexpr. */
6088 0 : if (TYPE_HAS_TRIVIAL_DESTRUCTOR (t))
6089 : return true;
6090 :
6091 0 : if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DESTRUCTOR (t))
6092 : /* Assume it's constexpr. */
6093 : return true;
6094 0 : tree fn = CLASSTYPE_DESTRUCTOR (t);
6095 0 : return (fn && Compile::maybe_constexpr_fn (fn));
6096 : }
6097 :
6098 : /* T is a non-literal type used in a context which requires a constant
6099 : expression. Explain why it isn't literal. */
6100 :
6101 : void
6102 0 : explain_non_literal_class (tree t)
6103 : {
6104 0 : static hash_set<tree> *diagnosed;
6105 :
6106 0 : if (!CLASS_TYPE_P (t))
6107 0 : return;
6108 0 : t = TYPE_MAIN_VARIANT (t);
6109 :
6110 0 : if (diagnosed == NULL)
6111 0 : diagnosed = new hash_set<tree>;
6112 0 : if (diagnosed->add (t))
6113 : /* Already explained. */
6114 : return;
6115 :
6116 0 : auto_diagnostic_group d;
6117 0 : inform (UNKNOWN_LOCATION, "%q+T is not literal because:", t);
6118 0 : if (LAMBDA_TYPE_P (t))
6119 0 : inform (UNKNOWN_LOCATION,
6120 : " %qT is a closure type, which is only literal in "
6121 : "C++17 and later",
6122 : t);
6123 0 : else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
6124 0 : && !type_maybe_constexpr_destructor (t))
6125 0 : inform (UNKNOWN_LOCATION, " %q+T does not have %<constexpr%> destructor",
6126 : t);
6127 0 : else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
6128 0 : inform (UNKNOWN_LOCATION, " %q+T has a non-trivial destructor", t);
6129 0 : else if (CLASSTYPE_NON_AGGREGATE (t) && !TYPE_HAS_TRIVIAL_DFLT (t)
6130 0 : && !LAMBDA_TYPE_P (t) && !TYPE_HAS_CONSTEXPR_CTOR (t))
6131 : {
6132 0 : inform (UNKNOWN_LOCATION,
6133 : " %q+T is not an aggregate, does not have a trivial "
6134 : "default constructor, and has no %<constexpr%> constructor that "
6135 : "is not a copy or move constructor",
6136 : t);
6137 0 : if (type_has_non_user_provided_default_constructor (t))
6138 : /* Note that we can't simply call locate_ctor because when the
6139 : constructor is deleted it just returns NULL_TREE. */
6140 0 : for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
6141 : {
6142 0 : tree fn = *iter;
6143 0 : tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
6144 :
6145 0 : parms = skip_artificial_parms_for (fn, parms);
6146 :
6147 0 : if (sufficient_parms_p (parms))
6148 : {
6149 0 : Compile::explain_invalid_constexpr_fn (fn);
6150 0 : break;
6151 : }
6152 : }
6153 : }
6154 : else
6155 : {
6156 0 : tree binfo, base_binfo, field;
6157 0 : int i;
6158 0 : for (binfo = TYPE_BINFO (t), i = 0;
6159 0 : BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
6160 : {
6161 0 : tree basetype = TREE_TYPE (base_binfo);
6162 0 : if (!CLASSTYPE_LITERAL_P (basetype))
6163 : {
6164 0 : inform (UNKNOWN_LOCATION,
6165 : " base class %qT of %q+T is non-literal", basetype, t);
6166 0 : explain_non_literal_class (basetype);
6167 0 : return;
6168 : }
6169 : }
6170 0 : for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
6171 : {
6172 0 : tree ftype;
6173 0 : if (TREE_CODE (field) != FIELD_DECL)
6174 0 : continue;
6175 0 : ftype = TREE_TYPE (field);
6176 0 : if (!Compile::literal_type_p (ftype))
6177 : {
6178 0 : inform (DECL_SOURCE_LOCATION (field),
6179 : " non-static data member %qD has non-literal type",
6180 : field);
6181 0 : if (CLASS_TYPE_P (ftype))
6182 0 : explain_non_literal_class (ftype);
6183 : }
6184 0 : if (RS_TYPE_VOLATILE_P (ftype))
6185 0 : inform (DECL_SOURCE_LOCATION (field),
6186 : " non-static data member %qD has volatile type", field);
6187 : }
6188 : }
6189 0 : }
6190 :
6191 : // forked from gcc/cp/call.cc reference_related_p
6192 :
6193 : /* Returns nonzero if T1 is reference-related to T2. */
6194 :
6195 : bool
6196 0 : reference_related_p (tree t1, tree t2)
6197 : {
6198 0 : if (t1 == error_mark_node || t2 == error_mark_node)
6199 : return false;
6200 :
6201 0 : t1 = TYPE_MAIN_VARIANT (t1);
6202 0 : t2 = TYPE_MAIN_VARIANT (t2);
6203 :
6204 : /* [dcl.init.ref]
6205 :
6206 : Given types "cv1 T1" and "cv2 T2," "cv1 T1" is reference-related
6207 : to "cv2 T2" if T1 is similar to T2, or T1 is a base class of T2. */
6208 0 : return (similar_type_p (t1, t2)
6209 : /*|| (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
6210 0 : && DERIVED_FROM_P (t1, t2))*/);
6211 : }
6212 :
6213 : // forked from gcc/cp/typeck2.cc ordinary_char_type_p
6214 :
6215 : /* True iff TYPE is a C++20 "ordinary" character type. */
6216 :
6217 : bool
6218 0 : ordinary_char_type_p (tree type)
6219 : {
6220 0 : type = TYPE_MAIN_VARIANT (type);
6221 0 : return (type == char_type_node || type == signed_char_type_node
6222 0 : || type == unsigned_char_type_node);
6223 : }
6224 :
6225 : // forked from gcc/cp/typeck2.cc array_string_literal_compatible_p
6226 :
6227 : /* True iff the string literal INIT has a type suitable for initializing array
6228 : TYPE. */
6229 :
6230 : bool
6231 0 : array_string_literal_compatible_p (tree type, tree init)
6232 : {
6233 0 : tree to_char_type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
6234 0 : tree from_char_type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (init)));
6235 :
6236 0 : if (to_char_type == from_char_type)
6237 : return true;
6238 : /* The array element type does not match the initializing string
6239 : literal element type; this is only allowed when both types are
6240 : ordinary character type. There are no string literals of
6241 : signed or unsigned char type in the language, but we can get
6242 : them internally from converting braced-init-lists to
6243 : STRING_CST. */
6244 0 : if (ordinary_char_type_p (to_char_type)
6245 0 : && ordinary_char_type_p (from_char_type))
6246 : return true;
6247 : return false;
6248 : }
6249 :
6250 : } // namespace Rust
6251 :
6252 : using namespace Rust;
6253 :
6254 : #include "gt-rust-rust-tree.h"
|