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