Branch data Line data Source code
1 : : // Copyright (C) 2020-2025 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 : 1166 : mark_exp_read (tree exp)
52 : : {
53 : 1166 : char tmp_name[32];
54 : 1166 : ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lsrc_loc", 1);
55 : :
56 : 1166 : if (exp == NULL)
57 : 0 : return;
58 : :
59 : 1166 : switch (TREE_CODE (exp))
60 : : {
61 : 1149 : case VAR_DECL:
62 : 1149 : gcc_fallthrough ();
63 : 1149 : case PARM_DECL:
64 : 1149 : DECL_READ_P (exp) = 1;
65 : 1149 : 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 : 1150 : 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 : 1150 : if (expr == NULL_TREE || error_operand_p (expr))
118 : : return expr;
119 : :
120 : 1150 : if (reject_builtin)
121 : 0 : return error_mark_node;
122 : :
123 : 1150 : if (read_p)
124 : 1150 : mark_exp_read (expr);
125 : :
126 : 1150 : bool recurse_op[3] = {false, false, false};
127 : 1150 : 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 : 4600 : for (int i = 0; i < 3; ++i)
188 : 3450 : 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 : : 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 : 5603 : mark_discarded_use (tree expr)
222 : : {
223 : 5603 : if (expr == NULL_TREE)
224 : : return expr;
225 : :
226 : 5603 : STRIP_ANY_LOCATION_WRAPPER (expr);
227 : :
228 : 5603 : 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 : 5587 : default:
243 : 5587 : if (DECL_P (expr))
244 : : break;
245 : : else
246 : : return expr;
247 : : }
248 : :
249 : 1135 : return mark_use (expr, true, true, input_location, false);
250 : : }
251 : :
252 : : tree
253 : 8927 : convert_to_void (tree expr, impl_conv_void implicit)
254 : : {
255 : 8927 : location_t loc = expr_loc_or_input_loc (expr);
256 : 8927 : if (expr == error_mark_node || TREE_TYPE (expr) == error_mark_node)
257 : : return error_mark_node;
258 : :
259 : 5603 : expr = mark_discarded_use (expr);
260 : 5603 : if (implicit == ICV_CAST)
261 : : /* An explicit cast to void avoids all -Wunused-but-set* warnings. */
262 : 0 : mark_exp_read (expr);
263 : :
264 : 5603 : if (!TREE_TYPE (expr))
265 : : return expr;
266 : :
267 : 5603 : if (VOID_TYPE_P (TREE_TYPE (expr)))
268 : : return expr;
269 : 3402 : switch (TREE_CODE (expr))
270 : : {
271 : 0 : case COND_EXPR:
272 : 0 : {
273 : : /* The two parts of a cond expr might be separate lvalues. */
274 : 0 : tree op1 = TREE_OPERAND (expr, 1);
275 : 0 : tree op2 = TREE_OPERAND (expr, 2);
276 : 0 : bool side_effects
277 : 0 : = ((op1 && TREE_SIDE_EFFECTS (op1)) || TREE_SIDE_EFFECTS (op2));
278 : 0 : tree new_op1, new_op2;
279 : 0 : new_op1 = NULL_TREE;
280 : 0 : if (implicit != ICV_CAST && !side_effects)
281 : : {
282 : 0 : if (op1)
283 : 0 : new_op1 = convert_to_void (op1, ICV_SECOND_OF_COND);
284 : 0 : new_op2 = convert_to_void (op2, ICV_THIRD_OF_COND);
285 : : }
286 : : else
287 : : {
288 : 0 : if (op1)
289 : 0 : new_op1 = convert_to_void (op1, ICV_CAST);
290 : 0 : new_op2 = convert_to_void (op2, ICV_CAST);
291 : : }
292 : :
293 : 0 : expr = build3_loc (loc, COND_EXPR, TREE_TYPE (new_op2),
294 : 0 : TREE_OPERAND (expr, 0), new_op1, new_op2);
295 : 0 : break;
296 : : }
297 : :
298 : 0 : case COMPOUND_EXPR:
299 : 0 : {
300 : : /* The second part of a compound expr contains the value. */
301 : 0 : tree op1 = TREE_OPERAND (expr, 1);
302 : 0 : tree new_op1;
303 : 0 : if (implicit != ICV_CAST
304 : 0 : && !warning_suppressed_p (expr /* What warning? */))
305 : 0 : new_op1 = convert_to_void (op1, ICV_RIGHT_OF_COMMA);
306 : : else
307 : 0 : new_op1 = convert_to_void (op1, ICV_CAST);
308 : :
309 : 0 : if (new_op1 != op1)
310 : : {
311 : 0 : tree t = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (new_op1),
312 : 0 : TREE_OPERAND (expr, 0), new_op1);
313 : 0 : expr = t;
314 : : }
315 : :
316 : : break;
317 : : }
318 : :
319 : : case NON_LVALUE_EXPR:
320 : : case NOP_EXPR:
321 : : /* These have already decayed to rvalue. */
322 : : break;
323 : :
324 : 2183 : case CALL_EXPR:
325 : 2183 : maybe_warn_nodiscard (expr, implicit);
326 : 2183 : break;
327 : :
328 : 0 : case INDIRECT_REF:
329 : 0 : {
330 : 0 : tree type = TREE_TYPE (expr);
331 : 0 : int is_reference = TYPE_REF_P (TREE_TYPE (TREE_OPERAND (expr, 0)));
332 : 0 : int is_volatile = TYPE_VOLATILE (type);
333 : 0 : int is_complete = COMPLETE_TYPE_P (type);
334 : :
335 : : /* Can't load the value if we don't know the type. */
336 : 0 : if (is_volatile && !is_complete)
337 : : {
338 : 0 : switch (implicit)
339 : : {
340 : 0 : case ICV_CAST:
341 : 0 : warning_at (loc, 0,
342 : : "conversion to void will not access "
343 : : "object of incomplete type %qT",
344 : : type);
345 : 0 : break;
346 : 0 : case ICV_SECOND_OF_COND:
347 : 0 : warning_at (loc, 0,
348 : : "indirection will not access object of "
349 : : "incomplete type %qT in second operand "
350 : : "of conditional expression",
351 : : type);
352 : 0 : break;
353 : 0 : case ICV_THIRD_OF_COND:
354 : 0 : warning_at (loc, 0,
355 : : "indirection will not access object of "
356 : : "incomplete type %qT in third operand "
357 : : "of conditional expression",
358 : : type);
359 : 0 : break;
360 : 0 : case ICV_RIGHT_OF_COMMA:
361 : 0 : warning_at (loc, 0,
362 : : "indirection will not access object of "
363 : : "incomplete type %qT in right operand of "
364 : : "comma operator",
365 : : type);
366 : 0 : break;
367 : 0 : case ICV_LEFT_OF_COMMA:
368 : 0 : warning_at (loc, 0,
369 : : "indirection will not access object of "
370 : : "incomplete type %qT in left operand of "
371 : : "comma operator",
372 : : type);
373 : 0 : break;
374 : 0 : case ICV_STATEMENT:
375 : 0 : warning_at (loc, 0,
376 : : "indirection will not access object of "
377 : : "incomplete type %qT in statement",
378 : : type);
379 : 0 : break;
380 : 0 : case ICV_THIRD_IN_FOR:
381 : 0 : warning_at (loc, 0,
382 : : "indirection will not access object of "
383 : : "incomplete type %qT in for increment "
384 : : "expression",
385 : : type);
386 : 0 : break;
387 : 0 : default:
388 : 0 : rust_unreachable ();
389 : : }
390 : : }
391 : : /* Don't load the value if this is an implicit dereference, or if
392 : : the type needs to be handled by ctors/dtors. */
393 : 0 : else if (is_volatile && is_reference)
394 : : {
395 : 0 : switch (implicit)
396 : : {
397 : 0 : case ICV_CAST:
398 : 0 : warning_at (loc, 0,
399 : : "conversion to void will not access "
400 : : "object of type %qT",
401 : : type);
402 : 0 : break;
403 : 0 : case ICV_SECOND_OF_COND:
404 : 0 : warning_at (loc, 0,
405 : : "implicit dereference will not access "
406 : : "object of type %qT in second operand of "
407 : : "conditional expression",
408 : : type);
409 : 0 : break;
410 : 0 : case ICV_THIRD_OF_COND:
411 : 0 : warning_at (loc, 0,
412 : : "implicit dereference will not access "
413 : : "object of type %qT in third operand of "
414 : : "conditional expression",
415 : : type);
416 : 0 : break;
417 : 0 : case ICV_RIGHT_OF_COMMA:
418 : 0 : warning_at (loc, 0,
419 : : "implicit dereference will not access "
420 : : "object of type %qT in right operand of "
421 : : "comma operator",
422 : : type);
423 : 0 : break;
424 : 0 : case ICV_LEFT_OF_COMMA:
425 : 0 : warning_at (loc, 0,
426 : : "implicit dereference will not access "
427 : : "object of type %qT in left operand of comma "
428 : : "operator",
429 : : type);
430 : 0 : break;
431 : 0 : case ICV_STATEMENT:
432 : 0 : warning_at (loc, 0,
433 : : "implicit dereference will not access "
434 : : "object of type %qT in statement",
435 : : type);
436 : 0 : break;
437 : 0 : case ICV_THIRD_IN_FOR:
438 : 0 : warning_at (loc, 0,
439 : : "implicit dereference will not access "
440 : : "object of type %qT in for increment expression",
441 : : type);
442 : 0 : break;
443 : 0 : default:
444 : 0 : rust_unreachable ();
445 : : }
446 : : }
447 : 0 : else if (is_volatile && TREE_ADDRESSABLE (type))
448 : : {
449 : 0 : switch (implicit)
450 : : {
451 : 0 : case ICV_CAST:
452 : 0 : warning_at (loc, 0,
453 : : "conversion to void will not access "
454 : : "object of non-trivially-copyable type %qT",
455 : : type);
456 : 0 : break;
457 : 0 : case ICV_SECOND_OF_COND:
458 : 0 : warning_at (loc, 0,
459 : : "indirection will not access object of "
460 : : "non-trivially-copyable type %qT in second "
461 : : "operand of conditional expression",
462 : : type);
463 : 0 : break;
464 : 0 : case ICV_THIRD_OF_COND:
465 : 0 : warning_at (loc, 0,
466 : : "indirection will not access object of "
467 : : "non-trivially-copyable type %qT in third "
468 : : "operand of conditional expression",
469 : : type);
470 : 0 : break;
471 : 0 : case ICV_RIGHT_OF_COMMA:
472 : 0 : warning_at (loc, 0,
473 : : "indirection will not access object of "
474 : : "non-trivially-copyable type %qT in right "
475 : : "operand of comma operator",
476 : : type);
477 : 0 : break;
478 : 0 : case ICV_LEFT_OF_COMMA:
479 : 0 : warning_at (loc, 0,
480 : : "indirection will not access object of "
481 : : "non-trivially-copyable type %qT in left "
482 : : "operand of comma operator",
483 : : type);
484 : 0 : break;
485 : 0 : case ICV_STATEMENT:
486 : 0 : warning_at (loc, 0,
487 : : "indirection will not access object of "
488 : : "non-trivially-copyable type %qT in statement",
489 : : type);
490 : 0 : break;
491 : 0 : case ICV_THIRD_IN_FOR:
492 : 0 : warning_at (loc, 0,
493 : : "indirection will not access object of "
494 : : "non-trivially-copyable type %qT in for "
495 : : "increment expression",
496 : : type);
497 : 0 : break;
498 : 0 : default:
499 : 0 : rust_unreachable ();
500 : : }
501 : : }
502 : 0 : if (is_reference || !is_volatile || !is_complete
503 : 0 : || TREE_ADDRESSABLE (type))
504 : : {
505 : : /* Emit a warning (if enabled) when the "effect-less" INDIRECT_REF
506 : : operation is stripped off. Note that we don't warn about
507 : : - an expression with TREE_NO_WARNING set. (For an example of
508 : : such expressions, see build_over_call in call.cc.)
509 : : - automatic dereferencing of references, since the user cannot
510 : : control it. (See also warn_if_unused_value() in c-common.cc.)
511 : : */
512 : 0 : if (warn_unused_value && implicit != ICV_CAST
513 : 0 : && !warning_suppressed_p (expr, OPT_Wunused_value)
514 : 0 : && !is_reference)
515 : 0 : warning_at (loc, OPT_Wunused_value, "value computed is not used");
516 : 0 : expr = TREE_OPERAND (expr, 0);
517 : 0 : if (TREE_CODE (expr) == CALL_EXPR)
518 : 0 : maybe_warn_nodiscard (expr, implicit);
519 : : }
520 : :
521 : : break;
522 : : }
523 : :
524 : 1112 : case VAR_DECL:
525 : 1112 : {
526 : : /* External variables might be incomplete. */
527 : 1112 : tree type = TREE_TYPE (expr);
528 : 1112 : int is_complete = COMPLETE_TYPE_P (type);
529 : :
530 : 1112 : if (TYPE_VOLATILE (type) && !is_complete)
531 : 0 : switch (implicit)
532 : : {
533 : 0 : case ICV_CAST:
534 : 0 : warning_at (loc, 0,
535 : : "conversion to void will not access "
536 : : "object %qE of incomplete type %qT",
537 : : expr, type);
538 : 0 : break;
539 : 0 : case ICV_SECOND_OF_COND:
540 : 0 : warning_at (loc, 0,
541 : : "variable %qE of incomplete type %qT will "
542 : : "not be accessed in second operand of "
543 : : "conditional expression",
544 : : expr, type);
545 : 0 : break;
546 : 0 : case ICV_THIRD_OF_COND:
547 : 0 : warning_at (loc, 0,
548 : : "variable %qE of incomplete type %qT will "
549 : : "not be accessed in third operand of "
550 : : "conditional expression",
551 : : expr, type);
552 : 0 : break;
553 : 0 : case ICV_RIGHT_OF_COMMA:
554 : 0 : warning_at (loc, 0,
555 : : "variable %qE of incomplete type %qT will "
556 : : "not be accessed in right operand of comma operator",
557 : : expr, type);
558 : 0 : break;
559 : 0 : case ICV_LEFT_OF_COMMA:
560 : 0 : warning_at (loc, 0,
561 : : "variable %qE of incomplete type %qT will "
562 : : "not be accessed in left operand of comma operator",
563 : : expr, type);
564 : 0 : break;
565 : 0 : case ICV_STATEMENT:
566 : 0 : warning_at (loc, 0,
567 : : "variable %qE of incomplete type %qT will "
568 : : "not be accessed in statement",
569 : : expr, type);
570 : 0 : break;
571 : 0 : case ICV_THIRD_IN_FOR:
572 : 0 : warning_at (loc, 0,
573 : : "variable %qE of incomplete type %qT will "
574 : : "not be accessed in for increment expression",
575 : : expr, type);
576 : 0 : break;
577 : 0 : default:
578 : 0 : rust_unreachable ();
579 : : }
580 : :
581 : : break;
582 : : }
583 : :
584 : 3402 : default:;
585 : : }
586 : :
587 : 3402 : if (!TREE_SIDE_EFFECTS (expr))
588 : 1220 : expr = void_node;
589 : :
590 : : return expr;
591 : : }
592 : :
593 : : void
594 : 2183 : maybe_warn_nodiscard (tree expr, impl_conv_void implicit)
595 : : {
596 : 2183 : tree call = expr;
597 : 2183 : if (TREE_CODE (expr) == TARGET_EXPR)
598 : 0 : call = TARGET_EXPR_INITIAL (expr);
599 : :
600 : 2183 : location_t loc = expr_loc_or_input_loc (call);
601 : 2183 : tree callee = CALL_EXPR_FN (call);
602 : 2183 : if (!callee)
603 : : return;
604 : :
605 : 2183 : tree type = TREE_TYPE (callee);
606 : 2183 : if (INDIRECT_TYPE_P (type))
607 : 2183 : type = TREE_TYPE (type);
608 : :
609 : 2183 : tree rettype = TREE_TYPE (type);
610 : 2183 : tree fn = get_fndecl_from_callee (callee);
611 : 2183 : tree attr;
612 : 2183 : if (implicit != ICV_CAST && fn
613 : 2183 : && (attr = lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn))))
614 : : {
615 : 14 : escaped_string msg;
616 : 14 : tree args = TREE_VALUE (attr);
617 : 14 : if (args)
618 : 7 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
619 : 14 : const char *format
620 : 14 : = (msg ? G_ ("ignoring return value of %qD, that must be used: %qs")
621 : 7 : : G_ ("ignoring return value of %qD, that must be used"));
622 : 14 : const char *raw_msg = msg ? (const char *) msg : "";
623 : 14 : auto_diagnostic_group d;
624 : 14 : if (warning_at (loc, OPT_Wunused_result, format, fn, raw_msg))
625 : 14 : inform (DECL_SOURCE_LOCATION (fn), "declared here");
626 : 14 : }
627 : 2169 : else if (implicit != ICV_CAST
628 : 2169 : && (attr
629 : 2169 : = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype))))
630 : : {
631 : 0 : escaped_string msg;
632 : 0 : tree args = TREE_VALUE (attr);
633 : 0 : if (args)
634 : 0 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
635 : 0 : const char *format
636 : 0 : = (msg ? G_ (
637 : : "ignoring returned value of type %qT, that must be used: %qs")
638 : 0 : : G_ ("ignoring returned value of type %qT, that must be used"));
639 : 0 : const char *raw_msg = msg ? (const char *) msg : "";
640 : 0 : auto_diagnostic_group d;
641 : 0 : if (warning_at (loc, OPT_Wunused_result, format, rettype, raw_msg))
642 : : {
643 : 0 : if (fn)
644 : 0 : inform (DECL_SOURCE_LOCATION (fn), "in call to %qD, declared here",
645 : : fn);
646 : 0 : inform (DECL_SOURCE_LOCATION (TYPE_NAME (rettype)),
647 : : "%qT declared here", rettype);
648 : : }
649 : 0 : }
650 : : }
651 : :
652 : : location_t
653 : 11110 : expr_loc_or_loc (const_tree t, location_t or_loc)
654 : : {
655 : 11110 : location_t loc = EXPR_LOCATION (t);
656 : 6587 : if (loc == UNKNOWN_LOCATION)
657 : 4525 : loc = or_loc;
658 : 11110 : return loc;
659 : : }
660 : :
661 : : location_t
662 : 11110 : expr_loc_or_input_loc (const_tree t)
663 : : {
664 : 11110 : return expr_loc_or_loc (t, input_location);
665 : : }
666 : :
667 : : // FN is the callee of a CALL_EXPR or AGGR_INIT_EXPR; return the FUNCTION_DECL
668 : : // if we can.
669 : : tree
670 : 2183 : get_fndecl_from_callee (tree fn)
671 : : {
672 : 2183 : if (fn == NULL_TREE)
673 : : return fn;
674 : 2183 : if (TREE_CODE (fn) == FUNCTION_DECL)
675 : : return fn;
676 : 2183 : tree type = TREE_TYPE (fn);
677 : 2183 : if (type == NULL_TREE || !INDIRECT_TYPE_P (type))
678 : : return NULL_TREE;
679 : :
680 : 2183 : STRIP_NOPS (fn);
681 : 2183 : if (TREE_CODE (fn) == ADDR_EXPR || TREE_CODE (fn) == FDESC_EXPR)
682 : 2045 : fn = TREE_OPERAND (fn, 0);
683 : 2183 : if (TREE_CODE (fn) == FUNCTION_DECL)
684 : : return fn;
685 : : return NULL_TREE;
686 : : }
687 : :
688 : : tree
689 : 134 : pointer_offset_expression (tree base_tree, tree index_tree, location_t location)
690 : : {
691 : 134 : tree element_type_tree = TREE_TYPE (TREE_TYPE (base_tree));
692 : 134 : if (base_tree == error_mark_node || TREE_TYPE (base_tree) == error_mark_node
693 : 268 : || index_tree == error_mark_node || element_type_tree == error_mark_node)
694 : : return error_mark_node;
695 : :
696 : 134 : tree element_size = TYPE_SIZE_UNIT (element_type_tree);
697 : 134 : index_tree = fold_convert_loc (location, sizetype, index_tree);
698 : 134 : tree offset
699 : 134 : = fold_build2_loc (location, MULT_EXPR, sizetype, index_tree, element_size);
700 : :
701 : 134 : return fold_build2_loc (location, POINTER_PLUS_EXPR, TREE_TYPE (base_tree),
702 : 134 : base_tree, offset);
703 : : }
704 : :
705 : : // forked from gcc/cp/tree.cc cp_walk_subtrees
706 : : /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
707 : : traversal. Called from walk_tree. */
708 : :
709 : : tree
710 : 3 : rs_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func, void *data,
711 : : hash_set<tree> *pset)
712 : : {
713 : 3 : enum tree_code code = TREE_CODE (*tp);
714 : 3 : tree result;
715 : :
716 : : #define WALK_SUBTREE(NODE) \
717 : : do \
718 : : { \
719 : : result = rs_walk_tree (&(NODE), func, data, pset); \
720 : : if (result) \
721 : : goto out; \
722 : : } \
723 : : while (0)
724 : :
725 : 3 : if (TYPE_P (*tp))
726 : : {
727 : : /* If *WALK_SUBTREES_P is 1, we're interested in the syntactic form of
728 : : the argument, so don't look through typedefs, but do walk into
729 : : template arguments for alias templates (and non-typedefed classes).
730 : :
731 : : If *WALK_SUBTREES_P > 1, we're interested in type identity or
732 : : equivalence, so look through typedefs, ignoring template arguments for
733 : : alias templates, and walk into template args of classes.
734 : :
735 : : See find_abi_tags_r for an example of setting *WALK_SUBTREES_P to 2
736 : : when that's the behavior the walk_tree_fn wants. */
737 : 0 : if (*walk_subtrees_p == 1 && typedef_variant_p (*tp))
738 : : {
739 : 0 : *walk_subtrees_p = 0;
740 : 0 : return NULL_TREE;
741 : : }
742 : : }
743 : :
744 : : /* Not one of the easy cases. We must explicitly go through the
745 : : children. */
746 : 3 : result = NULL_TREE;
747 : 3 : switch (code)
748 : : {
749 : 0 : case TREE_LIST:
750 : 0 : WALK_SUBTREE (TREE_PURPOSE (*tp));
751 : : break;
752 : :
753 : 0 : case RECORD_TYPE:
754 : 0 : if (TYPE_PTRMEMFUNC_P (*tp))
755 : 0 : WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (*tp));
756 : : break;
757 : :
758 : 0 : case CONSTRUCTOR:
759 : 0 : if (COMPOUND_LITERAL_P (*tp))
760 : 0 : WALK_SUBTREE (TREE_TYPE (*tp));
761 : : break;
762 : :
763 : 0 : case DECL_EXPR:
764 : : /* User variables should be mentioned in BIND_EXPR_VARS
765 : : and their initializers and sizes walked when walking
766 : : the containing BIND_EXPR. Compiler temporaries are
767 : : handled here. And also normal variables in templates,
768 : : since do_poplevel doesn't build a BIND_EXPR then. */
769 : 0 : if (VAR_P (TREE_OPERAND (*tp, 0))
770 : 0 : && (DECL_ARTIFICIAL (TREE_OPERAND (*tp, 0))
771 : 0 : && !TREE_STATIC (TREE_OPERAND (*tp, 0))))
772 : : {
773 : 0 : tree decl = TREE_OPERAND (*tp, 0);
774 : 0 : WALK_SUBTREE (DECL_INITIAL (decl));
775 : 0 : WALK_SUBTREE (DECL_SIZE (decl));
776 : 0 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
777 : : }
778 : : break;
779 : :
780 : : default:
781 : : return NULL_TREE;
782 : : }
783 : :
784 : : /* We didn't find what we were looking for. */
785 : : out:
786 : : return result;
787 : :
788 : : #undef WALK_SUBTREE
789 : : }
790 : :
791 : : // forked from gcc/cp/tree.cc cp_expr_location
792 : :
793 : : /* Like EXPR_LOCATION, but also handle some tcc_exceptional that have
794 : : locations. */
795 : :
796 : : location_t
797 : 10 : rs_expr_location (const_tree t_)
798 : : {
799 : 10 : tree t = CONST_CAST_TREE (t_);
800 : 10 : if (t == NULL_TREE)
801 : : return UNKNOWN_LOCATION;
802 : :
803 : 10 : return EXPR_LOCATION (t);
804 : : }
805 : :
806 : : // forked from gcc/cp/class.cc is_really_empty_class
807 : :
808 : : /* Returns true if TYPE contains no actual data, just various
809 : : possible combinations of empty classes. If IGNORE_VPTR is true,
810 : : a vptr doesn't prevent the class from being considered empty. Typically
811 : : we want to ignore the vptr on assignment, and not on initialization. */
812 : :
813 : : bool
814 : 0 : is_really_empty_class (tree type, bool ignore_vptr)
815 : : {
816 : 0 : if (CLASS_TYPE_P (type))
817 : : {
818 : 0 : tree field;
819 : 0 : tree binfo;
820 : 0 : tree base_binfo;
821 : 0 : int i;
822 : :
823 : : /* CLASSTYPE_EMPTY_P isn't set properly until the class is actually laid
824 : : out, but we'd like to be able to check this before then. */
825 : 0 : if (COMPLETE_TYPE_P (type) && is_empty_class (type))
826 : : return true;
827 : :
828 : 0 : if (!ignore_vptr && TYPE_CONTAINS_VPTR_P (type))
829 : : return false;
830 : :
831 : 0 : for (binfo = TYPE_BINFO (type), i = 0;
832 : 0 : BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
833 : 0 : if (!is_really_empty_class (BINFO_TYPE (base_binfo), ignore_vptr))
834 : : return false;
835 : 0 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
836 : 0 : if (TREE_CODE (field) == FIELD_DECL
837 : 0 : && !DECL_ARTIFICIAL (field)
838 : : /* An unnamed bit-field is not a data member. */
839 : 0 : && !DECL_UNNAMED_BIT_FIELD (field)
840 : 0 : && !is_really_empty_class (TREE_TYPE (field), ignore_vptr))
841 : : return false;
842 : : return true;
843 : : }
844 : 0 : else if (TREE_CODE (type) == ARRAY_TYPE)
845 : 0 : return (integer_zerop (array_type_nelts_top (type))
846 : 0 : || is_really_empty_class (TREE_TYPE (type), ignore_vptr));
847 : : return false;
848 : : }
849 : :
850 : : // forked from gcc/cp/class.cc is_empty_class
851 : :
852 : : /* Returns 1 if TYPE contains only padding bytes. */
853 : :
854 : : int
855 : 1 : is_empty_class (tree type)
856 : : {
857 : 1 : if (type == error_mark_node)
858 : : return 0;
859 : :
860 : 1 : if (!CLASS_TYPE_P (type))
861 : : return 0;
862 : :
863 : 0 : return CLASSTYPE_EMPTY_P (type);
864 : : }
865 : :
866 : : // forked from gcc/cp/tree.cc builtin_valid_in_constant_expr_p
867 : :
868 : : /* Test whether DECL is a builtin that may appear in a
869 : : constant-expression. */
870 : :
871 : : bool
872 : 0 : builtin_valid_in_constant_expr_p (const_tree decl)
873 : : {
874 : 0 : STRIP_ANY_LOCATION_WRAPPER (decl);
875 : 0 : if (TREE_CODE (decl) != FUNCTION_DECL)
876 : : /* Not a function. */
877 : : return false;
878 : 0 : if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL)
879 : : {
880 : 0 : if (fndecl_built_in_p (decl, BUILT_IN_FRONTEND))
881 : 0 : switch (DECL_FE_FUNCTION_CODE (decl))
882 : : {
883 : : case RS_BUILT_IN_IS_CONSTANT_EVALUATED:
884 : : case RS_BUILT_IN_SOURCE_LOCATION:
885 : : case RS_BUILT_IN_IS_CORRESPONDING_MEMBER:
886 : : case RS_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS:
887 : : return true;
888 : : default:
889 : : break;
890 : : }
891 : : /* Not a built-in. */
892 : : return false;
893 : : }
894 : 0 : switch (DECL_FUNCTION_CODE (decl))
895 : : {
896 : : /* These always have constant results like the corresponding
897 : : macros/symbol. */
898 : : case BUILT_IN_FILE:
899 : : case BUILT_IN_FUNCTION:
900 : : case BUILT_IN_LINE:
901 : :
902 : : /* The following built-ins are valid in constant expressions
903 : : when their arguments are. */
904 : : case BUILT_IN_ADD_OVERFLOW_P:
905 : : case BUILT_IN_SUB_OVERFLOW_P:
906 : : case BUILT_IN_MUL_OVERFLOW_P:
907 : :
908 : : /* These have constant results even if their operands are
909 : : non-constant. */
910 : : case BUILT_IN_CONSTANT_P:
911 : : case BUILT_IN_ATOMIC_ALWAYS_LOCK_FREE:
912 : : return true;
913 : : default:
914 : : return false;
915 : : }
916 : : }
917 : :
918 : : // forked from gcc/cp/decl2.cc decl_maybe_constant_var_p
919 : :
920 : : /* Returns true if DECL could be a symbolic constant variable, depending on
921 : : its initializer. */
922 : :
923 : : bool
924 : 0 : decl_maybe_constant_var_p (tree decl)
925 : : {
926 : 0 : tree type = TREE_TYPE (decl);
927 : 0 : if (!VAR_P (decl))
928 : : return false;
929 : 0 : if (DECL_DECLARED_CONSTEXPR_P (decl))
930 : : return true;
931 : 0 : if (DECL_HAS_VALUE_EXPR_P (decl))
932 : : /* A proxy isn't constant. */
933 : : return false;
934 : 0 : if (TYPE_REF_P (type))
935 : : /* References can be constant. */;
936 : 0 : else if (RS_TYPE_CONST_NON_VOLATILE_P (type)
937 : 0 : && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
938 : : /* And const integers. */;
939 : : else
940 : : return false;
941 : :
942 : 0 : if (DECL_INITIAL (decl) && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
943 : : /* We know the initializer, and it isn't constant. */
944 : : return false;
945 : : else
946 : : return true;
947 : : }
948 : :
949 : : // forked from gcc/cp/typeck.cc cp_type_quals
950 : :
951 : : /* Returns the type qualifiers for this type, including the qualifiers on the
952 : : elements for an array type. */
953 : :
954 : : int
955 : 26 : rs_type_quals (const_tree type)
956 : : {
957 : 26 : int quals;
958 : : /* This CONST_CAST is okay because strip_array_types returns its
959 : : argument unmodified and we assign it to a const_tree. */
960 : 26 : type = strip_array_types (CONST_CAST_TREE (type));
961 : 26 : if (type == error_mark_node
962 : : /* Quals on a FUNCTION_TYPE are memfn quals. */
963 : 26 : || TREE_CODE (type) == FUNCTION_TYPE)
964 : : return TYPE_UNQUALIFIED;
965 : 26 : quals = TYPE_QUALS (type);
966 : : /* METHOD and REFERENCE_TYPEs should never have quals. */
967 : : // gcc_assert (
968 : : // (TREE_CODE (type) != METHOD_TYPE && !TYPE_REF_P (type))
969 : : // || ((quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)) ==
970 : : // TYPE_UNQUALIFIED));
971 : 26 : return quals;
972 : : }
973 : :
974 : : // forked from gcc/cp/decl.cc cp_global_trees
975 : :
976 : : /* The following symbols are subsumed in the cp_global_trees array, and
977 : : listed here individually for documentation purposes.
978 : :
979 : : C++ extensions
980 : : tree wchar_decl_node;
981 : :
982 : : tree vtable_entry_type;
983 : : tree delta_type_node;
984 : : tree __t_desc_type_node;
985 : :
986 : : tree class_type_node;
987 : : tree unknown_type_node;
988 : :
989 : : Array type `vtable_entry_type[]'
990 : :
991 : : tree vtbl_type_node;
992 : : tree vtbl_ptr_type_node;
993 : :
994 : : Namespaces,
995 : :
996 : : tree std_node;
997 : : tree abi_node;
998 : :
999 : : A FUNCTION_DECL which can call `abort'. Not necessarily the
1000 : : one that the user will declare, but sufficient to be called
1001 : : by routines that want to abort the program.
1002 : :
1003 : : tree abort_fndecl;
1004 : :
1005 : : Used by RTTI
1006 : : tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
1007 : : tree tinfo_var_id; */
1008 : :
1009 : : /* The following symbols are subsumed in the c_global_trees array, and
1010 : : listed here individually for documentation purposes.
1011 : :
1012 : : INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
1013 : :
1014 : : tree short_integer_type_node;
1015 : : tree long_integer_type_node;
1016 : : tree long_long_integer_type_node;
1017 : :
1018 : : tree short_unsigned_type_node;
1019 : : tree long_unsigned_type_node;
1020 : : tree long_long_unsigned_type_node;
1021 : :
1022 : : tree truthvalue_type_node;
1023 : : tree truthvalue_false_node;
1024 : : tree truthvalue_true_node;
1025 : :
1026 : : tree ptrdiff_type_node;
1027 : :
1028 : : tree unsigned_char_type_node;
1029 : : tree signed_char_type_node;
1030 : : tree wchar_type_node;
1031 : :
1032 : : tree char8_type_node;
1033 : : tree char16_type_node;
1034 : : tree char32_type_node;
1035 : :
1036 : : tree float_type_node;
1037 : : tree double_type_node;
1038 : : tree long_double_type_node;
1039 : :
1040 : : tree complex_integer_type_node;
1041 : : tree complex_float_type_node;
1042 : : tree complex_double_type_node;
1043 : : tree complex_long_double_type_node;
1044 : :
1045 : : tree dfloat32_type_node;
1046 : : tree dfloat64_type_node;
1047 : : tree_dfloat128_type_node;
1048 : :
1049 : : tree intQI_type_node;
1050 : : tree intHI_type_node;
1051 : : tree intSI_type_node;
1052 : : tree intDI_type_node;
1053 : : tree intTI_type_node;
1054 : :
1055 : : tree unsigned_intQI_type_node;
1056 : : tree unsigned_intHI_type_node;
1057 : : tree unsigned_intSI_type_node;
1058 : : tree unsigned_intDI_type_node;
1059 : : tree unsigned_intTI_type_node;
1060 : :
1061 : : tree widest_integer_literal_type_node;
1062 : : tree widest_unsigned_literal_type_node;
1063 : :
1064 : : Nodes for types `void *' and `const void *'.
1065 : :
1066 : : tree ptr_type_node, const_ptr_type_node;
1067 : :
1068 : : Nodes for types `char *' and `const char *'.
1069 : :
1070 : : tree string_type_node, const_string_type_node;
1071 : :
1072 : : Type `char[SOMENUMBER]'.
1073 : : Used when an array of char is needed and the size is irrelevant.
1074 : :
1075 : : tree char_array_type_node;
1076 : :
1077 : : Type `wchar_t[SOMENUMBER]' or something like it.
1078 : : Used when a wide string literal is created.
1079 : :
1080 : : tree wchar_array_type_node;
1081 : :
1082 : : Type `char8_t[SOMENUMBER]' or something like it.
1083 : : Used when a UTF-8 string literal is created.
1084 : :
1085 : : tree char8_array_type_node;
1086 : :
1087 : : Type `char16_t[SOMENUMBER]' or something like it.
1088 : : Used when a UTF-16 string literal is created.
1089 : :
1090 : : tree char16_array_type_node;
1091 : :
1092 : : Type `char32_t[SOMENUMBER]' or something like it.
1093 : : Used when a UTF-32 string literal is created.
1094 : :
1095 : : tree char32_array_type_node;
1096 : :
1097 : : Type `int ()' -- used for implicit declaration of functions.
1098 : :
1099 : : tree default_function_type;
1100 : :
1101 : : A VOID_TYPE node, packaged in a TREE_LIST.
1102 : :
1103 : : tree void_list_node;
1104 : :
1105 : : The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
1106 : : and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
1107 : : VAR_DECLS, but C++ does.)
1108 : :
1109 : : tree function_name_decl_node;
1110 : : tree pretty_function_name_decl_node;
1111 : : tree c99_function_name_decl_node;
1112 : :
1113 : : Stack of nested function name VAR_DECLs.
1114 : :
1115 : : tree saved_function_name_decls;
1116 : :
1117 : : */
1118 : :
1119 : : // forked from gcc/cp/module.cc fixed_trees
1120 : :
1121 : : static GTY (()) vec<tree, va_gc> *fixed_trees;
1122 : :
1123 : : // forked from gcc/cp/module.cc maybe_add_global
1124 : :
1125 : : /* VAL is a global tree, add it to the global vec if it is
1126 : : interesting. Add some of its targets, if they too are
1127 : : interesting. We do not add identifiers, as they can be re-found
1128 : : via the identifier hash table. There is a cost to the number of
1129 : : global trees. */
1130 : :
1131 : : static int
1132 : 0 : maybe_add_global (tree val, unsigned &crc)
1133 : : {
1134 : 0 : int v = 0;
1135 : :
1136 : 0 : if (val && !(TREE_CODE (val) == IDENTIFIER_NODE || TREE_VISITED (val)))
1137 : : {
1138 : 0 : TREE_VISITED (val) = true;
1139 : 0 : crc = crc32_unsigned (crc, fixed_trees->length ());
1140 : 0 : vec_safe_push (fixed_trees, val);
1141 : 0 : v++;
1142 : :
1143 : 0 : if (CODE_CONTAINS_STRUCT (TREE_CODE (val), TS_TYPED))
1144 : 0 : v += maybe_add_global (TREE_TYPE (val), crc);
1145 : 0 : if (CODE_CONTAINS_STRUCT (TREE_CODE (val), TS_TYPE_COMMON))
1146 : 0 : v += maybe_add_global (TYPE_NAME (val), crc);
1147 : : }
1148 : :
1149 : 0 : return v;
1150 : : }
1151 : :
1152 : : // forked from gcc/cp/module.cc global_tree_arys
1153 : :
1154 : : /* Global trees. */
1155 : : static const std::pair<tree *, unsigned> global_tree_arys[] = {
1156 : : std::pair<tree *, unsigned> (cp_global_trees, CPTI_MODULE_HWM),
1157 : : std::pair<tree *, unsigned> (c_global_trees, CTI_MODULE_HWM),
1158 : : };
1159 : :
1160 : : // forked from gcc/cp/module.cc init_modules
1161 : :
1162 : : void
1163 : 0 : init_modules ()
1164 : : {
1165 : 0 : unsigned crc = 0;
1166 : 0 : vec_alloc (fixed_trees, 200);
1167 : :
1168 : 0 : const tree *ptr = global_tree_arys[0].first;
1169 : 0 : unsigned limit = global_tree_arys[0].second;
1170 : 0 : for (unsigned ix = 0; ix != limit; ix++, ptr++)
1171 : : {
1172 : 0 : maybe_add_global (*ptr, crc);
1173 : : }
1174 : :
1175 : : ptr = global_tree_arys[1].first;
1176 : 0 : limit = global_tree_arys[1].second;
1177 : 0 : for (unsigned ix = 0; ix != limit; ix++, ptr++)
1178 : : {
1179 : 0 : maybe_add_global (*ptr, crc);
1180 : : }
1181 : 0 : }
1182 : :
1183 : : // forked from gcc/cp/constexpr.cc var_in_constexpr_fn
1184 : :
1185 : : /* True if T was declared in a function declared to be constexpr, and
1186 : : therefore potentially constant in C++14. */
1187 : :
1188 : : bool
1189 : 0 : var_in_constexpr_fn (tree t)
1190 : : {
1191 : 0 : tree ctx = DECL_CONTEXT (t);
1192 : 0 : return (ctx && TREE_CODE (ctx) == FUNCTION_DECL
1193 : 0 : && DECL_DECLARED_CONSTEXPR_P (ctx));
1194 : : }
1195 : :
1196 : : // forked from gcc/cp/name-lookup.cc member_vec_linear_search
1197 : :
1198 : : /* Linear search of (unordered) MEMBER_VEC for NAME. */
1199 : :
1200 : : static tree
1201 : 0 : member_vec_linear_search (vec<tree, va_gc> *member_vec, tree name)
1202 : : {
1203 : 0 : for (int ix = member_vec->length (); ix--;)
1204 : 0 : if (tree binding = (*member_vec)[ix])
1205 : 0 : if (OVL_NAME (binding) == name)
1206 : : return binding;
1207 : :
1208 : : return NULL_TREE;
1209 : : }
1210 : :
1211 : : // forked from gcc/cp/name-lookup.cc member_vec_binary_search
1212 : :
1213 : : /* Binary search of (ordered) MEMBER_VEC for NAME. */
1214 : :
1215 : : static tree
1216 : 0 : member_vec_binary_search (vec<tree, va_gc> *member_vec, tree name)
1217 : : {
1218 : 0 : for (unsigned lo = 0, hi = member_vec->length (); lo < hi;)
1219 : : {
1220 : 0 : unsigned mid = (lo + hi) / 2;
1221 : 0 : tree binding = (*member_vec)[mid];
1222 : 0 : tree binding_name = OVL_NAME (binding);
1223 : :
1224 : 0 : if (binding_name > name)
1225 : : hi = mid;
1226 : 0 : else if (binding_name < name)
1227 : 0 : lo = mid + 1;
1228 : : else
1229 : : return binding;
1230 : : }
1231 : :
1232 : : return NULL_TREE;
1233 : : }
1234 : :
1235 : : // forked from gcc/cp/tree.cc is_overloaded_fn
1236 : :
1237 : : /* Returns nonzero if X is an expression for a (possibly overloaded)
1238 : : function. If "f" is a function or function template, "f", "c->f",
1239 : : "c.f", "C::f", and "f<int>" will all be considered possibly
1240 : : overloaded functions. Returns 2 if the function is actually
1241 : : overloaded, i.e., if it is impossible to know the type of the
1242 : : function without performing overload resolution. */
1243 : :
1244 : : int
1245 : 5 : is_overloaded_fn (tree x)
1246 : : {
1247 : 5 : STRIP_ANY_LOCATION_WRAPPER (x);
1248 : :
1249 : 5 : if (TREE_CODE (x) == COMPONENT_REF)
1250 : 5 : x = TREE_OPERAND (x, 1);
1251 : :
1252 : 5 : return OVL_P (x);
1253 : : }
1254 : :
1255 : : // forked from gcc/cp/tree.cc ovl_make
1256 : :
1257 : : /* Make a raw overload node containing FN. */
1258 : :
1259 : : tree
1260 : 0 : ovl_make (tree fn, tree next)
1261 : : {
1262 : 0 : tree result = make_node (OVERLOAD);
1263 : :
1264 : 0 : if (TREE_CODE (fn) == OVERLOAD)
1265 : 0 : OVL_NESTED_P (result) = true;
1266 : :
1267 : 0 : TREE_TYPE (result) = (next ? unknown_type_node : TREE_TYPE (fn));
1268 : 0 : if (next && TREE_CODE (next) == OVERLOAD && OVL_DEDUP_P (next))
1269 : 0 : OVL_DEDUP_P (result) = true;
1270 : 0 : OVL_FUNCTION (result) = fn;
1271 : 0 : OVL_CHAIN (result) = next;
1272 : 0 : return result;
1273 : : }
1274 : :
1275 : : // forked from gcc/cp/name-lookup.cc lookup_add
1276 : :
1277 : : /* Add a set of new FNS into a lookup. */
1278 : :
1279 : : tree
1280 : 0 : lookup_add (tree fns, tree lookup)
1281 : : {
1282 : 0 : if (fns == error_mark_node || lookup == error_mark_node)
1283 : 0 : return error_mark_node;
1284 : :
1285 : 0 : lookup = fns;
1286 : :
1287 : : return lookup;
1288 : : }
1289 : :
1290 : : // forked from gcc/cp/typeck.cc type_memfn_quals
1291 : :
1292 : : /* Returns the function-cv-quals for TYPE, which must be a FUNCTION_TYPE or
1293 : : METHOD_TYPE. */
1294 : :
1295 : : int
1296 : 0 : type_memfn_quals (const_tree type)
1297 : : {
1298 : 0 : if (TREE_CODE (type) == FUNCTION_TYPE)
1299 : 0 : return TYPE_QUALS (type);
1300 : 0 : else if (TREE_CODE (type) == METHOD_TYPE)
1301 : 0 : return rs_type_quals (class_of_this_parm (type));
1302 : : else
1303 : 0 : rust_unreachable ();
1304 : : }
1305 : :
1306 : : // forked from gcc/cp/pt.cc find_parameter_pack_data
1307 : :
1308 : : /* Structure used to track the progress of find_parameter_packs_r. */
1309 : : struct find_parameter_pack_data
1310 : : {
1311 : : /* TREE_LIST that will contain all of the parameter packs found by
1312 : : the traversal. */
1313 : : tree *parameter_packs;
1314 : :
1315 : : /* Set of AST nodes that have been visited by the traversal. */
1316 : : hash_set<tree> *visited;
1317 : :
1318 : : /* True iff we're making a type pack expansion. */
1319 : : bool type_pack_expansion_p;
1320 : :
1321 : : /* True iff we found a subtree that has the extra args mechanism. */
1322 : : bool found_extra_args_tree_p = false;
1323 : : };
1324 : :
1325 : : // forked from gcc/cp/lex.cc conv_type_hasher
1326 : :
1327 : : /* Hasher for the conversion operator name hash table. */
1328 : : struct rust_conv_type_hasher : ggc_ptr_hash<tree_node>
1329 : : {
1330 : : /* Hash NODE, an identifier node in the table. TYPE_UID is
1331 : : suitable, as we're not concerned about matching canonicalness
1332 : : here. */
1333 : 0 : static hashval_t hash (tree node)
1334 : : {
1335 : 0 : return (hashval_t) TYPE_UID (TREE_TYPE (node));
1336 : : }
1337 : :
1338 : : /* Compare NODE, an identifier node in the table, against TYPE, an
1339 : : incoming TYPE being looked up. */
1340 : 0 : static bool equal (tree node, tree type) { return TREE_TYPE (node) == type; }
1341 : : };
1342 : :
1343 : : static GTY (()) hash_table<rust_conv_type_hasher> *conv_type_names;
1344 : :
1345 : : // forked from gcc/cp/lex.cc make_conv_op_name
1346 : :
1347 : : /* Return an identifier for a conversion operator to TYPE. We can get
1348 : : from the returned identifier to the type. We store TYPE, which is
1349 : : not necessarily the canonical type, which allows us to report the
1350 : : form the user used in error messages. All these identifiers are
1351 : : not in the identifier hash table, and have the same string name.
1352 : : These IDENTIFIERS are not in the identifier hash table, and all
1353 : : have the same IDENTIFIER_STRING. */
1354 : :
1355 : : tree
1356 : 0 : make_conv_op_name (tree type)
1357 : : {
1358 : 0 : if (type == error_mark_node)
1359 : : return error_mark_node;
1360 : :
1361 : 0 : if (conv_type_names == NULL)
1362 : 0 : conv_type_names = hash_table<rust_conv_type_hasher>::create_ggc (31);
1363 : :
1364 : 0 : tree *slot
1365 : 0 : = conv_type_names->find_slot_with_hash (type, (hashval_t) TYPE_UID (type),
1366 : : INSERT);
1367 : 0 : tree identifier = *slot;
1368 : 0 : if (!identifier)
1369 : : {
1370 : : /* Create a raw IDENTIFIER outside of the identifier hash
1371 : : table. */
1372 : 0 : identifier = copy_node (conv_op_identifier);
1373 : :
1374 : : /* Just in case something managed to bind. */
1375 : 0 : IDENTIFIER_BINDING (identifier) = NULL;
1376 : :
1377 : : /* Hang TYPE off the identifier so it can be found easily later
1378 : : when performing conversions. */
1379 : 0 : TREE_TYPE (identifier) = type;
1380 : :
1381 : 0 : *slot = identifier;
1382 : : }
1383 : :
1384 : : return identifier;
1385 : : }
1386 : :
1387 : : // forked from gcc/cp/pt.cc builtin_pack_fn_p
1388 : :
1389 : : /* True iff FN is a function representing a built-in variadic parameter
1390 : : pack. */
1391 : :
1392 : : bool
1393 : 0 : builtin_pack_fn_p (tree fn)
1394 : : {
1395 : 0 : if (!fn || TREE_CODE (fn) != FUNCTION_DECL
1396 : 0 : || !DECL_IS_UNDECLARED_BUILTIN (fn))
1397 : : return false;
1398 : :
1399 : 0 : if (id_equal (DECL_NAME (fn), "__integer_pack"))
1400 : : return true;
1401 : :
1402 : : return false;
1403 : : }
1404 : :
1405 : : // forked from gcc/cp/pt.cc builtin_pack_call_p
1406 : :
1407 : : /* True iff CALL is a call to a function representing a built-in variadic
1408 : : parameter pack. */
1409 : :
1410 : : static bool
1411 : 0 : builtin_pack_call_p (tree call)
1412 : : {
1413 : 0 : if (TREE_CODE (call) != CALL_EXPR)
1414 : : return false;
1415 : 0 : return builtin_pack_fn_p (CALL_EXPR_FN (call));
1416 : : }
1417 : :
1418 : : //// forked from gcc/cp/pt.cc has_extra_args_mechanism_p
1419 : : //
1420 : : ///* Return true if the tree T has the extra args mechanism for
1421 : : // avoiding partial instantiation. */
1422 : : //
1423 : : // static bool
1424 : : // has_extra_args_mechanism_p (const_tree t)
1425 : : //{
1426 : : // return false;
1427 : : //}
1428 : :
1429 : : // forked from gcc/cp/pt.cc find_parameter_packs_r
1430 : :
1431 : : /* Identifies all of the argument packs that occur in a template
1432 : : argument and appends them to the TREE_LIST inside DATA, which is a
1433 : : find_parameter_pack_data structure. This is a subroutine of
1434 : : make_pack_expansion and uses_parameter_packs. */
1435 : : static tree
1436 : 0 : find_parameter_packs_r (tree *tp, int *walk_subtrees, void *data)
1437 : : {
1438 : 0 : tree t = *tp;
1439 : 0 : struct find_parameter_pack_data *ppd
1440 : : = (struct find_parameter_pack_data *) data;
1441 : 0 : bool parameter_pack_p = false;
1442 : :
1443 : : #define WALK_SUBTREE(NODE) \
1444 : : rs_walk_tree (&(NODE), &find_parameter_packs_r, ppd, ppd->visited)
1445 : :
1446 : : /* Don't look through typedefs; we are interested in whether a
1447 : : parameter pack is actually written in the expression/type we're
1448 : : looking at, not the target type. */
1449 : 0 : if (TYPE_P (t) && typedef_variant_p (t))
1450 : : {
1451 : 0 : *walk_subtrees = 0;
1452 : 0 : return NULL_TREE;
1453 : : }
1454 : :
1455 : : /* Identify whether this is a parameter pack or not. */
1456 : 0 : switch (TREE_CODE (t))
1457 : : {
1458 : : case FIELD_DECL:
1459 : : case PARM_DECL:
1460 : : break;
1461 : :
1462 : : case VAR_DECL:
1463 : : break;
1464 : :
1465 : 0 : case CALL_EXPR:
1466 : 0 : if (builtin_pack_call_p (t))
1467 : : parameter_pack_p = true;
1468 : : break;
1469 : :
1470 : : case BASES:
1471 : : parameter_pack_p = true;
1472 : : break;
1473 : : default:
1474 : : /* Not a parameter pack. */
1475 : : break;
1476 : : }
1477 : :
1478 : : if (parameter_pack_p)
1479 : : {
1480 : : /* Add this parameter pack to the list. */
1481 : 0 : *ppd->parameter_packs = tree_cons (NULL_TREE, t, *ppd->parameter_packs);
1482 : : }
1483 : :
1484 : 0 : if (TYPE_P (t))
1485 : 0 : rs_walk_tree (&TYPE_CONTEXT (t), &find_parameter_packs_r, ppd,
1486 : : ppd->visited);
1487 : :
1488 : : /* This switch statement will return immediately if we don't find a
1489 : : parameter pack. ??? Should some of these be in cp_walk_subtrees? */
1490 : 0 : switch (TREE_CODE (t))
1491 : : {
1492 : 0 : case DECL_EXPR:
1493 : 0 : {
1494 : 0 : tree decl = DECL_EXPR_DECL (t);
1495 : 0 : if (is_typedef_decl (decl))
1496 : : /* Since we stop at typedefs above, we need to look through them at
1497 : : the point of the DECL_EXPR. */
1498 : 0 : rs_walk_tree (&DECL_ORIGINAL_TYPE (decl), &find_parameter_packs_r,
1499 : : ppd, ppd->visited);
1500 : : return NULL_TREE;
1501 : : }
1502 : :
1503 : 0 : case INTEGER_TYPE:
1504 : 0 : rs_walk_tree (&TYPE_MAX_VALUE (t), &find_parameter_packs_r, ppd,
1505 : : ppd->visited);
1506 : 0 : *walk_subtrees = 0;
1507 : 0 : return NULL_TREE;
1508 : :
1509 : 0 : case IDENTIFIER_NODE:
1510 : 0 : rs_walk_tree (&TREE_TYPE (t), &find_parameter_packs_r, ppd, ppd->visited);
1511 : 0 : *walk_subtrees = 0;
1512 : 0 : return NULL_TREE;
1513 : :
1514 : 0 : case DECLTYPE_TYPE:
1515 : 0 : {
1516 : : /* When traversing a DECLTYPE_TYPE_EXPR, we need to set
1517 : : type_pack_expansion_p to false so that any placeholders
1518 : : within the expression don't get marked as parameter packs. */
1519 : 0 : bool type_pack_expansion_p = ppd->type_pack_expansion_p;
1520 : 0 : ppd->type_pack_expansion_p = false;
1521 : 0 : rs_walk_tree (&DECLTYPE_TYPE_EXPR (t), &find_parameter_packs_r, ppd,
1522 : : ppd->visited);
1523 : 0 : ppd->type_pack_expansion_p = type_pack_expansion_p;
1524 : 0 : *walk_subtrees = 0;
1525 : 0 : return NULL_TREE;
1526 : : }
1527 : :
1528 : 0 : case IF_STMT:
1529 : 0 : rs_walk_tree (&IF_COND (t), &find_parameter_packs_r, ppd, ppd->visited);
1530 : 0 : rs_walk_tree (&THEN_CLAUSE (t), &find_parameter_packs_r, ppd,
1531 : : ppd->visited);
1532 : 0 : rs_walk_tree (&ELSE_CLAUSE (t), &find_parameter_packs_r, ppd,
1533 : : ppd->visited);
1534 : : /* Don't walk into IF_STMT_EXTRA_ARGS. */
1535 : 0 : *walk_subtrees = 0;
1536 : 0 : return NULL_TREE;
1537 : :
1538 : 0 : case FUNCTION_TYPE:
1539 : 0 : case METHOD_TYPE:
1540 : 0 : WALK_SUBTREE (TYPE_RAISES_EXCEPTIONS (t));
1541 : 0 : break;
1542 : :
1543 : : default:
1544 : : return NULL_TREE;
1545 : : }
1546 : :
1547 : : #undef WALK_SUBTREE
1548 : :
1549 : 0 : return NULL_TREE;
1550 : : }
1551 : :
1552 : : // forked from gcc/cp/typeck.cc type_memfn_rqual
1553 : :
1554 : : /* Returns the function-ref-qualifier for TYPE */
1555 : :
1556 : : rs_ref_qualifier
1557 : 0 : type_memfn_rqual (const_tree type)
1558 : : {
1559 : 0 : gcc_assert (FUNC_OR_METHOD_TYPE_P (type));
1560 : :
1561 : 0 : if (!FUNCTION_REF_QUALIFIED (type))
1562 : : return REF_QUAL_NONE;
1563 : 0 : else if (FUNCTION_RVALUE_QUALIFIED (type))
1564 : : return REF_QUAL_RVALUE;
1565 : : else
1566 : 0 : return REF_QUAL_LVALUE;
1567 : : }
1568 : :
1569 : : // forked from gcc/cp/lex.cc maybe_add_lang_type_raw
1570 : :
1571 : : /* Add a raw lang_type to T, a type, should it need one. */
1572 : :
1573 : : bool
1574 : 0 : maybe_add_lang_type_raw (tree t)
1575 : : {
1576 : 0 : if (!RECORD_OR_UNION_CODE_P (TREE_CODE (t)))
1577 : : return false;
1578 : :
1579 : 0 : auto *lt = (struct lang_type *) (ggc_internal_cleared_alloc (
1580 : : sizeof (struct lang_type)));
1581 : 0 : TYPE_LANG_SPECIFIC (t) = lt;
1582 : :
1583 : 0 : if (GATHER_STATISTICS)
1584 : : {
1585 : : tree_node_counts[(int) lang_type] += 1;
1586 : : tree_node_sizes[(int) lang_type] += sizeof (struct lang_type);
1587 : : }
1588 : :
1589 : 0 : return true;
1590 : : }
1591 : :
1592 : : // forked from gcc/c-family/c-lex.cc get_fileinfo
1593 : :
1594 : : static splay_tree file_info_tree;
1595 : :
1596 : : struct c_fileinfo *
1597 : 0 : get_fileinfo (const char *name)
1598 : : {
1599 : 0 : splay_tree_node n;
1600 : 0 : struct c_fileinfo *fi;
1601 : :
1602 : 0 : if (!file_info_tree)
1603 : 0 : file_info_tree = splay_tree_new (splay_tree_compare_strings, 0,
1604 : : splay_tree_delete_pointers);
1605 : :
1606 : 0 : n = splay_tree_lookup (file_info_tree, (splay_tree_key) name);
1607 : 0 : if (n)
1608 : 0 : return (struct c_fileinfo *) n->value;
1609 : :
1610 : 0 : fi = XNEW (struct c_fileinfo);
1611 : 0 : fi->time = 0;
1612 : 0 : fi->interface_only = 0;
1613 : 0 : fi->interface_unknown = 1;
1614 : 0 : splay_tree_insert (file_info_tree, (splay_tree_key) name,
1615 : : (splay_tree_value) fi);
1616 : 0 : return fi;
1617 : : }
1618 : :
1619 : : // forked from gcc/cp/lex.cc cxx_make_type
1620 : :
1621 : : tree
1622 : 0 : cxx_make_type (enum tree_code code MEM_STAT_DECL)
1623 : : {
1624 : 0 : tree t = make_node (code PASS_MEM_STAT);
1625 : :
1626 : 0 : if (maybe_add_lang_type_raw (t))
1627 : : {
1628 : : /* Set up some flags that give proper default behavior. */
1629 : 0 : struct c_fileinfo *finfo = get_fileinfo (LOCATION_FILE (input_location));
1630 : 0 : SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, finfo->interface_unknown);
1631 : 0 : CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
1632 : : }
1633 : :
1634 : 0 : if (code == RECORD_TYPE || code == UNION_TYPE)
1635 : 0 : TYPE_CXX_ODR_P (t) = 1;
1636 : :
1637 : 0 : return t;
1638 : : }
1639 : :
1640 : : // forked from gcc/cp/tree.cc build_min_array_type
1641 : :
1642 : : /* Build an ARRAY_TYPE without laying it out. */
1643 : :
1644 : : static tree
1645 : 0 : build_min_array_type (tree elt_type, tree index_type)
1646 : : {
1647 : 0 : tree t = cxx_make_type (ARRAY_TYPE);
1648 : 0 : TREE_TYPE (t) = elt_type;
1649 : 0 : TYPE_DOMAIN (t) = index_type;
1650 : 0 : return t;
1651 : : }
1652 : :
1653 : : // forked from gcc/cp/name-lookup.cc resort_data
1654 : :
1655 : : } // namespace Rust
1656 : :
1657 : : static struct
1658 : : {
1659 : : gt_pointer_operator new_value;
1660 : : void *cookie;
1661 : : } resort_data;
1662 : :
1663 : : // forked from gcc/cp/name-lookup.cc resort_member_name_cmp
1664 : :
1665 : : /* This routine compares two fields like member_name_cmp but using the
1666 : : pointer operator in resort_field_decl_data. We don't have to deal
1667 : : with duplicates here. */
1668 : :
1669 : : static int
1670 : 0 : resort_member_name_cmp (const void *a_p, const void *b_p)
1671 : : {
1672 : 0 : tree a = *(const tree *) a_p;
1673 : 0 : tree b = *(const tree *) b_p;
1674 : 0 : tree name_a = OVL_NAME (a);
1675 : 0 : tree name_b = OVL_NAME (b);
1676 : :
1677 : 0 : resort_data.new_value (&name_a, &name_a, resort_data.cookie);
1678 : 0 : resort_data.new_value (&name_b, &name_b, resort_data.cookie);
1679 : :
1680 : 0 : gcc_checking_assert (name_a != name_b);
1681 : :
1682 : 0 : return name_a < name_b ? -1 : +1;
1683 : : }
1684 : :
1685 : : // forked from gcc/cp/name-lookup.cc resort_type_member_vec
1686 : :
1687 : : /* Resort CLASSTYPE_MEMBER_VEC because pointers have been reordered. */
1688 : :
1689 : : void
1690 : 0 : resort_type_member_vec (void *obj, void * /*orig_obj*/,
1691 : : gt_pointer_operator new_value, void *cookie)
1692 : : {
1693 : 0 : if (vec<tree, va_gc> *member_vec = (vec<tree, va_gc> *) obj)
1694 : : {
1695 : 0 : resort_data.new_value = new_value;
1696 : 0 : resort_data.cookie = cookie;
1697 : 0 : member_vec->qsort (resort_member_name_cmp);
1698 : : }
1699 : 0 : }
1700 : :
1701 : : namespace Rust {
1702 : :
1703 : : // forked from gcc/cp/name-lookup.cc fields_linear_search
1704 : :
1705 : : /* Linear search of (partially ordered) fields of KLASS for NAME. */
1706 : :
1707 : : static tree
1708 : 0 : fields_linear_search (tree klass, tree name, bool want_type)
1709 : : {
1710 : 0 : for (tree fields = TYPE_FIELDS (klass); fields; fields = DECL_CHAIN (fields))
1711 : : {
1712 : 0 : tree decl = fields;
1713 : :
1714 : 0 : if (DECL_NAME (decl) != name)
1715 : 0 : continue;
1716 : :
1717 : 0 : if (DECL_DECLARES_FUNCTION_P (decl))
1718 : : /* Functions are found separately. */
1719 : 0 : continue;
1720 : :
1721 : 0 : if (!want_type || DECL_DECLARES_TYPE_P (decl))
1722 : : return decl;
1723 : : }
1724 : :
1725 : : return NULL_TREE;
1726 : : }
1727 : :
1728 : : // forked from gcc/cp/except.cc canonnothrow_spec_pical_eh_spec
1729 : :
1730 : : /* Return true iff SPEC is throw() or noexcept(true). */
1731 : :
1732 : : bool
1733 : 0 : nothrow_spec_p (const_tree spec)
1734 : : {
1735 : 0 : if (spec == empty_except_spec || spec == noexcept_true_spec)
1736 : : return true;
1737 : :
1738 : 0 : gcc_assert (!spec || TREE_VALUE (spec) || spec == noexcept_false_spec
1739 : : || TREE_PURPOSE (spec) == error_mark_node);
1740 : :
1741 : : return false;
1742 : : }
1743 : :
1744 : : // forked from gcc/cp/tree.cc may_get_fns
1745 : :
1746 : : /* Get the overload set FROM refers to. Returns NULL if it's not an
1747 : : overload set. */
1748 : :
1749 : : tree
1750 : 0 : maybe_get_fns (tree from)
1751 : : {
1752 : 0 : STRIP_ANY_LOCATION_WRAPPER (from);
1753 : :
1754 : : /* A baselink is also considered an overloaded function. */
1755 : 0 : if (TREE_CODE (from) == COMPONENT_REF)
1756 : 0 : from = TREE_OPERAND (from, 1);
1757 : :
1758 : 0 : if (OVL_P (from))
1759 : 0 : return from;
1760 : :
1761 : : return NULL;
1762 : : }
1763 : :
1764 : : // forked from gcc/cp/tree.cc get_fns
1765 : :
1766 : : /* FROM refers to an overload set. Return that set (or die). */
1767 : :
1768 : : tree
1769 : 0 : get_fns (tree from)
1770 : : {
1771 : 0 : tree res = maybe_get_fns (from);
1772 : :
1773 : 0 : gcc_assert (res);
1774 : 0 : return res;
1775 : : }
1776 : :
1777 : : // forked from gcc/cp/tree.cc get_first_fn
1778 : :
1779 : : /* Return the first function of the overload set FROM refers to. */
1780 : :
1781 : : tree
1782 : 0 : get_first_fn (tree from)
1783 : : {
1784 : 0 : return OVL_FIRST (get_fns (from));
1785 : : }
1786 : :
1787 : : // forked from gcc/cp/tree.cc dependent_name
1788 : :
1789 : : /* X is the CALL_EXPR_FN of a CALL_EXPR. If X represents a dependent name
1790 : : (14.6.2), return the IDENTIFIER_NODE for that name. Otherwise, return
1791 : : NULL_TREE. */
1792 : :
1793 : : tree
1794 : 0 : dependent_name (tree x)
1795 : : {
1796 : : /* FIXME a dependent name must be unqualified, but this function doesn't
1797 : : distinguish between qualified and unqualified identifiers. */
1798 : 0 : if (identifier_p (x))
1799 : : return x;
1800 : :
1801 : 0 : if (OVL_P (x))
1802 : 0 : return OVL_NAME (x);
1803 : : return NULL_TREE;
1804 : : }
1805 : :
1806 : : // forked from gcc/cp/tree.cc called_fns_equal
1807 : :
1808 : : /* Subroutine of rs_tree_equal: t1 and t2 are the CALL_EXPR_FNs of two
1809 : : CALL_EXPRS. Return whether they are equivalent. */
1810 : :
1811 : : static bool
1812 : 0 : called_fns_equal (tree t1, tree t2)
1813 : : {
1814 : : /* Core 1321: dependent names are equivalent even if the overload sets
1815 : : are different. But do compare explicit template arguments. */
1816 : 0 : tree name1 = dependent_name (t1);
1817 : 0 : tree name2 = dependent_name (t2);
1818 : 0 : if (name1 || name2)
1819 : : {
1820 : 0 : tree targs1 = NULL_TREE, targs2 = NULL_TREE;
1821 : :
1822 : 0 : if (name1 != name2)
1823 : : return false;
1824 : :
1825 : : /* FIXME dependent_name currently returns an unqualified name regardless
1826 : : of whether the function was named with a qualified- or unqualified-id.
1827 : : Until that's fixed, check that we aren't looking at overload sets from
1828 : : different scopes. */
1829 : 0 : if (is_overloaded_fn (t1) && is_overloaded_fn (t2)
1830 : 0 : && (DECL_CONTEXT (get_first_fn (t1))
1831 : 0 : != DECL_CONTEXT (get_first_fn (t2))))
1832 : : return false;
1833 : :
1834 : 0 : return rs_tree_equal (targs1, targs2);
1835 : : }
1836 : : else
1837 : 0 : return rs_tree_equal (t1, t2);
1838 : : }
1839 : :
1840 : : // forked from gcc/cp/tree.cc canonical_eh_spec
1841 : :
1842 : : /* Return the canonical version of exception-specification RAISES for a C++17
1843 : : function type, for use in type comparison and building TYPE_CANONICAL. */
1844 : :
1845 : : tree
1846 : 0 : canonical_eh_spec (tree raises)
1847 : : {
1848 : 0 : if (raises == NULL_TREE)
1849 : : return raises;
1850 : 0 : else if (nothrow_spec_p (raises))
1851 : : /* throw() -> noexcept. */
1852 : 0 : return noexcept_true_spec;
1853 : : else
1854 : : /* For C++17 type matching, anything else -> nothing. */
1855 : : return NULL_TREE;
1856 : : }
1857 : :
1858 : : /* Like cp_tree_operand_length, but takes a tree_code CODE. */
1859 : :
1860 : : int
1861 : 0 : rs_tree_code_length (enum tree_code code)
1862 : : {
1863 : 0 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
1864 : :
1865 : 0 : switch (code)
1866 : : {
1867 : : case PREINCREMENT_EXPR:
1868 : : case PREDECREMENT_EXPR:
1869 : : case POSTINCREMENT_EXPR:
1870 : : case POSTDECREMENT_EXPR:
1871 : : return 1;
1872 : :
1873 : 0 : case ARRAY_REF:
1874 : 0 : return 2;
1875 : :
1876 : 0 : default:
1877 : 0 : return TREE_CODE_LENGTH (code);
1878 : : }
1879 : : }
1880 : :
1881 : : // forked from gcc/cp/tree.cc rs_tree_operand_length
1882 : :
1883 : : /* Return the number of operands in T that we care about for things like
1884 : : mangling. */
1885 : :
1886 : : int
1887 : 0 : rs_tree_operand_length (const_tree t)
1888 : : {
1889 : 0 : enum tree_code code = TREE_CODE (t);
1890 : :
1891 : 0 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
1892 : 0 : return VL_EXP_OPERAND_LENGTH (t);
1893 : :
1894 : 0 : return rs_tree_code_length (code);
1895 : : }
1896 : :
1897 : : // forked from gcc/cp/tree.cc cp_tree_equal
1898 : :
1899 : : /* Return truthvalue of whether T1 is the same tree structure as T2.
1900 : : Return 1 if they are the same. Return 0 if they are different. */
1901 : :
1902 : : bool
1903 : 0 : rs_tree_equal (tree t1, tree t2)
1904 : : {
1905 : 0 : enum tree_code code1, code2;
1906 : :
1907 : 0 : if (t1 == t2)
1908 : : return true;
1909 : 0 : if (!t1 || !t2)
1910 : : return false;
1911 : :
1912 : 0 : code1 = TREE_CODE (t1);
1913 : 0 : code2 = TREE_CODE (t2);
1914 : :
1915 : 0 : if (code1 != code2)
1916 : : return false;
1917 : :
1918 : 0 : if (CONSTANT_CLASS_P (t1) && !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
1919 : : return false;
1920 : :
1921 : 0 : switch (code1)
1922 : : {
1923 : 0 : case VOID_CST:
1924 : : /* There's only a single VOID_CST node, so we should never reach
1925 : : here. */
1926 : 0 : rust_unreachable ();
1927 : :
1928 : 0 : case INTEGER_CST:
1929 : 0 : return tree_int_cst_equal (t1, t2);
1930 : :
1931 : 0 : case REAL_CST:
1932 : 0 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
1933 : :
1934 : 0 : case STRING_CST:
1935 : 0 : return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
1936 : 0 : && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
1937 : 0 : TREE_STRING_LENGTH (t1));
1938 : :
1939 : 0 : case FIXED_CST:
1940 : 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
1941 : :
1942 : 0 : case COMPLEX_CST:
1943 : 0 : return rs_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
1944 : 0 : && rs_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
1945 : :
1946 : 0 : case VECTOR_CST:
1947 : 0 : return operand_equal_p (t1, t2, OEP_ONLY_CONST);
1948 : :
1949 : 0 : case CONSTRUCTOR:
1950 : : /* We need to do this when determining whether or not two
1951 : : non-type pointer to member function template arguments
1952 : : are the same. */
1953 : 0 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
1954 : 0 : || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
1955 : : return false;
1956 : : {
1957 : : tree field, value;
1958 : : unsigned int i;
1959 : 0 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
1960 : : {
1961 : 0 : constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
1962 : 0 : if (!rs_tree_equal (field, elt2->index)
1963 : 0 : || !rs_tree_equal (value, elt2->value))
1964 : 0 : return false;
1965 : : }
1966 : : }
1967 : : return true;
1968 : :
1969 : 0 : case TREE_LIST:
1970 : 0 : if (!rs_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
1971 : : return false;
1972 : 0 : if (!rs_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
1973 : : return false;
1974 : 0 : return rs_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
1975 : :
1976 : 0 : case SAVE_EXPR:
1977 : 0 : return rs_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1978 : :
1979 : 0 : case CALL_EXPR:
1980 : 0 : {
1981 : 0 : if (KOENIG_LOOKUP_P (t1) != KOENIG_LOOKUP_P (t2))
1982 : : return false;
1983 : :
1984 : 0 : if (!called_fns_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
1985 : : return false;
1986 : :
1987 : 0 : call_expr_arg_iterator iter1, iter2;
1988 : 0 : init_call_expr_arg_iterator (t1, &iter1);
1989 : 0 : init_call_expr_arg_iterator (t2, &iter2);
1990 : 0 : if (iter1.n != iter2.n)
1991 : : return false;
1992 : :
1993 : 0 : while (more_call_expr_args_p (&iter1))
1994 : : {
1995 : 0 : tree arg1 = next_call_expr_arg (&iter1);
1996 : 0 : tree arg2 = next_call_expr_arg (&iter2);
1997 : :
1998 : 0 : gcc_checking_assert (arg1 && arg2);
1999 : 0 : if (!rs_tree_equal (arg1, arg2))
2000 : : return false;
2001 : : }
2002 : :
2003 : : return true;
2004 : : }
2005 : :
2006 : 0 : case TARGET_EXPR:
2007 : 0 : {
2008 : 0 : tree o1 = TREE_OPERAND (t1, 0);
2009 : 0 : tree o2 = TREE_OPERAND (t2, 0);
2010 : :
2011 : : /* Special case: if either target is an unallocated VAR_DECL,
2012 : : it means that it's going to be unified with whatever the
2013 : : TARGET_EXPR is really supposed to initialize, so treat it
2014 : : as being equivalent to anything. */
2015 : 0 : if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE && !DECL_RTL_SET_P (o1))
2016 : : /*Nop*/;
2017 : 0 : else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
2018 : 0 : && !DECL_RTL_SET_P (o2))
2019 : : /*Nop*/;
2020 : 0 : else if (!rs_tree_equal (o1, o2))
2021 : : return false;
2022 : :
2023 : 0 : return rs_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
2024 : : }
2025 : :
2026 : 0 : case PARM_DECL:
2027 : : /* For comparing uses of parameters in late-specified return types
2028 : : with an out-of-class definition of the function, but can also come
2029 : : up for expressions that involve 'this' in a member function
2030 : : template. */
2031 : :
2032 : 0 : if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
2033 : : {
2034 : 0 : if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2))
2035 : : return false;
2036 : 0 : if (CONSTRAINT_VAR_P (t1) ^ CONSTRAINT_VAR_P (t2))
2037 : : return false;
2038 : 0 : if (DECL_ARTIFICIAL (t1)
2039 : 0 : || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2)
2040 : 0 : && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)))
2041 : : return true;
2042 : : }
2043 : : return false;
2044 : :
2045 : : case VAR_DECL:
2046 : : case CONST_DECL:
2047 : : case FIELD_DECL:
2048 : : case FUNCTION_DECL:
2049 : : case IDENTIFIER_NODE:
2050 : : case SSA_NAME:
2051 : : return false;
2052 : :
2053 : : case TREE_VEC:
2054 : : return true;
2055 : :
2056 : 0 : case NON_LVALUE_EXPR:
2057 : 0 : case VIEW_CONVERT_EXPR:
2058 : : /* Used for location wrappers with possibly NULL types. */
2059 : 0 : if (!TREE_TYPE (t1) || !TREE_TYPE (t2))
2060 : : {
2061 : 0 : if (TREE_TYPE (t1) || TREE_TYPE (t2))
2062 : : return false;
2063 : : break;
2064 : : }
2065 : :
2066 : : default:
2067 : : break;
2068 : : }
2069 : :
2070 : 0 : switch (TREE_CODE_CLASS (code1))
2071 : : {
2072 : 0 : case tcc_unary:
2073 : 0 : case tcc_binary:
2074 : 0 : case tcc_comparison:
2075 : 0 : case tcc_expression:
2076 : 0 : case tcc_vl_exp:
2077 : 0 : case tcc_reference:
2078 : 0 : case tcc_statement:
2079 : 0 : {
2080 : 0 : int n = rs_tree_operand_length (t1);
2081 : 0 : if (TREE_CODE_CLASS (code1) == tcc_vl_exp
2082 : 0 : && n != TREE_OPERAND_LENGTH (t2))
2083 : : return false;
2084 : :
2085 : 0 : for (int i = 0; i < n; ++i)
2086 : 0 : if (!rs_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
2087 : : return false;
2088 : :
2089 : : return true;
2090 : : }
2091 : :
2092 : 0 : case tcc_type:
2093 : 0 : return same_type_p (t1, t2);
2094 : :
2095 : 0 : default:
2096 : 0 : rust_unreachable ();
2097 : : }
2098 : :
2099 : : /* We can get here with --disable-checking. */
2100 : : return false;
2101 : : }
2102 : :
2103 : : // forked from gcc/cp/class.cc publicly_uniquely_derived_p
2104 : :
2105 : : /* TRUE iff TYPE is publicly & uniquely derived from PARENT. */
2106 : :
2107 : : bool
2108 : 0 : publicly_uniquely_derived_p (tree, tree)
2109 : : {
2110 : 0 : return false;
2111 : : }
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 : 18 : rs_build_qualified_type_real (tree type, int type_quals,
2506 : : tsubst_flags_t complain)
2507 : : {
2508 : 18 : tree result;
2509 : 18 : int bad_quals = TYPE_UNQUALIFIED;
2510 : :
2511 : 18 : if (type == error_mark_node)
2512 : : return type;
2513 : :
2514 : 18 : if (type_quals == rs_type_quals (type))
2515 : : return type;
2516 : :
2517 : 9 : 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 : 9 : 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 : 9 : 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 : 9 : 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 : 9 : 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 : 9 : result = build_qualified_type (type, type_quals);
2614 : :
2615 : 9 : 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 : 9 : same_type_ignoring_top_level_qualifiers_p (tree type1, tree type2)
2709 : : {
2710 : 9 : if (type1 == error_mark_node || type2 == error_mark_node)
2711 : : return false;
2712 : 9 : if (type1 == type2)
2713 : : return true;
2714 : :
2715 : 8 : type1 = rs_build_qualified_type (type1, TYPE_UNQUALIFIED);
2716 : 8 : type2 = rs_build_qualified_type (type2, TYPE_UNQUALIFIED);
2717 : 8 : 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 : 3 : structural_comptypes (tree t1, tree t2, int strict)
2797 : : {
2798 : : /* Both should be types that are not obviously the same. */
2799 : 3 : gcc_checking_assert (t1 != t2 && TYPE_P (t1) && TYPE_P (t2));
2800 : :
2801 : 3 : if (TYPE_PTRMEMFUNC_P (t1))
2802 : 0 : t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
2803 : 3 : if (TYPE_PTRMEMFUNC_P (t2))
2804 : 0 : t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
2805 : :
2806 : : /* Different classes of types can't be compatible. */
2807 : 3 : 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 : 3 : if (TREE_CODE (t1) != ARRAY_TYPE && rs_type_quals (t1) != rs_type_quals (t2))
2813 : : return false;
2814 : 1 : if (TREE_CODE (t1) == FUNCTION_TYPE
2815 : 1 : && 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 : 1 : 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 : 1 : if (TREE_CODE (t1) != ARRAY_TYPE
2833 : 1 : && 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 : 11 : comptypes (tree t1, tree t2, int strict)
2944 : : {
2945 : 11 : gcc_checking_assert (t1 && t2);
2946 : :
2947 : : /* TYPE_ARGUMENT_PACKS are not really types. */
2948 : 11 : gcc_checking_assert (TREE_CODE (t1) != TYPE_ARGUMENT_PACK
2949 : : && TREE_CODE (t2) != TYPE_ARGUMENT_PACK);
2950 : :
2951 : 11 : if (t1 == t2)
2952 : : return true;
2953 : :
2954 : : /* Suppress errors caused by previously reported errors. */
2955 : 3 : if (t1 == error_mark_node || t2 == error_mark_node)
2956 : : return false;
2957 : :
2958 : 3 : if (strict == COMPARE_STRICT)
2959 : : {
2960 : 3 : 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 : 1 : 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 : : 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 : 7794 : make_tree_vector (void)
3351 : : {
3352 : 7794 : if (tree_vector_cache && !tree_vector_cache->is_empty ())
3353 : 5678 : 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 : 2116 : vec<tree, va_gc> *v;
3360 : 2116 : vec_alloc (v, 4);
3361 : 2116 : 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 : 7794 : release_tree_vector (vec<tree, va_gc> *vec)
3371 : : {
3372 : 7794 : if (vec != NULL)
3373 : : {
3374 : 7794 : 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 : 7794 : vec->truncate (0);
3382 : 7794 : vec_safe_push (tree_vector_cache, vec);
3383 : : }
3384 : : }
3385 : 7794 : }
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 : : bool
3392 : 0 : instantiation_dependent_expression_p (tree)
3393 : : {
3394 : 0 : return false;
3395 : : }
3396 : :
3397 : : // forked from gcc/cp/cvt.cc cp_get_callee
3398 : :
3399 : : /* If CALL is a call, return the callee; otherwise null. */
3400 : :
3401 : : tree
3402 : 0 : cp_get_callee (tree call)
3403 : : {
3404 : 0 : if (call == NULL_TREE)
3405 : : return call;
3406 : 0 : else if (TREE_CODE (call) == CALL_EXPR)
3407 : 0 : return CALL_EXPR_FN (call);
3408 : : return NULL_TREE;
3409 : : }
3410 : :
3411 : : // forked from gcc/cp/typeck.cc build_nop
3412 : :
3413 : : /* Return a NOP_EXPR converting EXPR to TYPE. */
3414 : :
3415 : : tree
3416 : 0 : build_nop (tree type, tree expr)
3417 : : {
3418 : 0 : if (type == error_mark_node || error_operand_p (expr))
3419 : : return expr;
3420 : 0 : return build1_loc (EXPR_LOCATION (expr), NOP_EXPR, type, expr);
3421 : : }
3422 : :
3423 : : // forked from gcc/cp/tree.cc scalarish_type_p
3424 : :
3425 : : /* Returns 1 iff type T is something we want to treat as a scalar type for
3426 : : the purpose of deciding whether it is trivial/POD/standard-layout. */
3427 : :
3428 : : bool
3429 : 2 : scalarish_type_p (const_tree t)
3430 : : {
3431 : 2 : if (t == error_mark_node)
3432 : : return 1;
3433 : :
3434 : 2 : return (SCALAR_TYPE_P (t) || VECTOR_TYPE_P (t));
3435 : : }
3436 : :
3437 : : // forked from gcc/cp/tree.cc type_has_nontrivial_copy_init
3438 : :
3439 : : /* Returns true iff copying an object of type T (including via move
3440 : : constructor) is non-trivial. That is, T has no non-trivial copy
3441 : : constructors and no non-trivial move constructors, and not all copy/move
3442 : : constructors are deleted. This function implements the ABI notion of
3443 : : non-trivial copy, which has diverged from the one in the standard. */
3444 : :
3445 : : bool
3446 : 0 : type_has_nontrivial_copy_init (const_tree)
3447 : : {
3448 : 0 : return false;
3449 : : }
3450 : :
3451 : : // forked from gcc/cp/tree.cc build_local_temp
3452 : :
3453 : : /* Return an undeclared local temporary of type TYPE for use in building a
3454 : : TARGET_EXPR. */
3455 : :
3456 : : tree
3457 : 0 : build_local_temp (tree type)
3458 : : {
3459 : 0 : tree slot = build_decl (input_location, VAR_DECL, NULL_TREE, type);
3460 : 0 : DECL_ARTIFICIAL (slot) = 1;
3461 : 0 : DECL_IGNORED_P (slot) = 1;
3462 : 0 : DECL_CONTEXT (slot) = current_function_decl;
3463 : 0 : layout_decl (slot, 0);
3464 : 0 : return slot;
3465 : : }
3466 : :
3467 : : // forked from gcc/cp/lambda.cc is_normal_capture_proxy
3468 : :
3469 : : /* Returns true iff DECL is a capture proxy for a normal capture
3470 : : (i.e. without explicit initializer). */
3471 : :
3472 : : bool
3473 : 0 : is_normal_capture_proxy (tree)
3474 : : {
3475 : 0 : return false;
3476 : : }
3477 : :
3478 : : // forked from gcc/cp/c-common.cc reject_gcc_builtin
3479 : :
3480 : : /* For an EXPR of a FUNCTION_TYPE that references a GCC built-in function
3481 : : with no library fallback or for an ADDR_EXPR whose operand is such type
3482 : : issues an error pointing to the location LOC.
3483 : : Returns true when the expression has been diagnosed and false
3484 : : otherwise. */
3485 : :
3486 : : bool
3487 : 0 : reject_gcc_builtin (const_tree expr, location_t loc /* = UNKNOWN_LOCATION */)
3488 : : {
3489 : 0 : if (TREE_CODE (expr) == ADDR_EXPR)
3490 : 0 : expr = TREE_OPERAND (expr, 0);
3491 : :
3492 : 0 : STRIP_ANY_LOCATION_WRAPPER (expr);
3493 : :
3494 : 0 : if (TREE_TYPE (expr) && TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE
3495 : 0 : && TREE_CODE (expr) == FUNCTION_DECL
3496 : : /* The intersection of DECL_BUILT_IN and DECL_IS_UNDECLARED_BUILTIN avoids
3497 : : false positives for user-declared built-ins such as abs or
3498 : : strlen, and for C++ operators new and delete.
3499 : : The c_decl_implicit() test avoids false positives for implicitly
3500 : : declared built-ins with library fallbacks (such as abs). */
3501 : 0 : && fndecl_built_in_p (expr) && DECL_IS_UNDECLARED_BUILTIN (expr)
3502 : 0 : && !DECL_ASSEMBLER_NAME_SET_P (expr))
3503 : : {
3504 : 0 : if (loc == UNKNOWN_LOCATION)
3505 : 0 : loc = EXPR_LOC_OR_LOC (expr, input_location);
3506 : :
3507 : : /* Reject arguments that are built-in functions with
3508 : : no library fallback. */
3509 : 0 : error_at (loc, "built-in function %qE must be directly called", expr);
3510 : :
3511 : 0 : return true;
3512 : : }
3513 : :
3514 : : return false;
3515 : : }
3516 : :
3517 : : // forked from gcc/cp/typeck.cc is_bitfield_expr_with_lowered_type
3518 : :
3519 : : /* If EXP is a reference to a bit-field, and the type of EXP does not
3520 : : match the declared type of the bit-field, return the declared type
3521 : : of the bit-field. Otherwise, return NULL_TREE. */
3522 : :
3523 : : tree
3524 : 0 : is_bitfield_expr_with_lowered_type (const_tree exp)
3525 : : {
3526 : 0 : switch (TREE_CODE (exp))
3527 : : {
3528 : 0 : case COND_EXPR:
3529 : 0 : if (!is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1)
3530 : 0 : ? TREE_OPERAND (exp, 1)
3531 : 0 : : TREE_OPERAND (exp, 0)))
3532 : : return NULL_TREE;
3533 : 0 : return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 2));
3534 : :
3535 : 0 : case COMPOUND_EXPR:
3536 : 0 : return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1));
3537 : :
3538 : 0 : case MODIFY_EXPR:
3539 : 0 : case SAVE_EXPR:
3540 : 0 : case UNARY_PLUS_EXPR:
3541 : 0 : case PREDECREMENT_EXPR:
3542 : 0 : case PREINCREMENT_EXPR:
3543 : 0 : case POSTDECREMENT_EXPR:
3544 : 0 : case POSTINCREMENT_EXPR:
3545 : 0 : case NEGATE_EXPR:
3546 : 0 : case NON_LVALUE_EXPR:
3547 : 0 : case BIT_NOT_EXPR:
3548 : 0 : return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0));
3549 : :
3550 : 0 : case COMPONENT_REF:
3551 : 0 : {
3552 : 0 : tree field;
3553 : :
3554 : 0 : field = TREE_OPERAND (exp, 1);
3555 : 0 : if (TREE_CODE (field) != FIELD_DECL || !DECL_BIT_FIELD_TYPE (field))
3556 : : return NULL_TREE;
3557 : 0 : if (same_type_ignoring_top_level_qualifiers_p (
3558 : 0 : TREE_TYPE (exp), DECL_BIT_FIELD_TYPE (field)))
3559 : : return NULL_TREE;
3560 : 0 : return DECL_BIT_FIELD_TYPE (field);
3561 : : }
3562 : :
3563 : 0 : case VAR_DECL:
3564 : 0 : if (DECL_HAS_VALUE_EXPR_P (exp))
3565 : 0 : return is_bitfield_expr_with_lowered_type (
3566 : 0 : DECL_VALUE_EXPR (CONST_CAST_TREE (exp)));
3567 : : return NULL_TREE;
3568 : :
3569 : 0 : case VIEW_CONVERT_EXPR:
3570 : 0 : if (location_wrapper_p (exp))
3571 : 0 : return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0));
3572 : : else
3573 : : return NULL_TREE;
3574 : :
3575 : : default:
3576 : : return NULL_TREE;
3577 : : }
3578 : : }
3579 : :
3580 : : // forked from gcc/cp/semantics.cc maybe_undo_parenthesized_ref
3581 : :
3582 : : /* If T is an id-expression obfuscated by force_paren_expr, undo the
3583 : : obfuscation and return the underlying id-expression. Otherwise
3584 : : return T. */
3585 : :
3586 : : tree
3587 : 0 : maybe_undo_parenthesized_ref (tree t)
3588 : : {
3589 : 0 : if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
3590 : 0 : && REF_PARENTHESIZED_P (t))
3591 : 0 : t = TREE_OPERAND (t, 0);
3592 : :
3593 : 0 : return t;
3594 : : }
3595 : :
3596 : : // forked from gcc/c-family/c-common.cc fold_offsetof
3597 : :
3598 : : /* Fold an offsetof-like expression. EXPR is a nested sequence of component
3599 : : references with an INDIRECT_REF of a constant at the bottom; much like the
3600 : : traditional rendering of offsetof as a macro. TYPE is the desired type of
3601 : : the whole expression. Return the folded result. */
3602 : :
3603 : : tree
3604 : 0 : fold_offsetof (tree expr, tree type, enum tree_code ctx)
3605 : : {
3606 : 0 : tree base, off, t;
3607 : 0 : tree_code code = TREE_CODE (expr);
3608 : 0 : switch (code)
3609 : : {
3610 : : case ERROR_MARK:
3611 : : return expr;
3612 : :
3613 : 0 : case VAR_DECL:
3614 : 0 : error ("cannot apply %<offsetof%> to static data member %qD", expr);
3615 : 0 : return error_mark_node;
3616 : :
3617 : 0 : case CALL_EXPR:
3618 : 0 : case TARGET_EXPR:
3619 : 0 : error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
3620 : 0 : return error_mark_node;
3621 : :
3622 : 0 : case NOP_EXPR:
3623 : 0 : case INDIRECT_REF:
3624 : 0 : if (!TREE_CONSTANT (TREE_OPERAND (expr, 0)))
3625 : : {
3626 : 0 : error ("cannot apply %<offsetof%> to a non constant address");
3627 : 0 : return error_mark_node;
3628 : : }
3629 : 0 : return convert (type, TREE_OPERAND (expr, 0));
3630 : :
3631 : 0 : case COMPONENT_REF:
3632 : 0 : base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
3633 : 0 : if (base == error_mark_node)
3634 : : return base;
3635 : :
3636 : 0 : t = TREE_OPERAND (expr, 1);
3637 : 0 : if (DECL_C_BIT_FIELD (t))
3638 : : {
3639 : 0 : error ("attempt to take address of bit-field structure "
3640 : : "member %qD",
3641 : : t);
3642 : 0 : return error_mark_node;
3643 : : }
3644 : 0 : off = size_binop_loc (input_location, PLUS_EXPR, DECL_FIELD_OFFSET (t),
3645 : 0 : size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t))
3646 : : / BITS_PER_UNIT));
3647 : 0 : break;
3648 : :
3649 : 0 : case ARRAY_REF:
3650 : 0 : base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
3651 : 0 : if (base == error_mark_node)
3652 : : return base;
3653 : :
3654 : 0 : t = TREE_OPERAND (expr, 1);
3655 : 0 : STRIP_ANY_LOCATION_WRAPPER (t);
3656 : :
3657 : : /* Check if the offset goes beyond the upper bound of the array. */
3658 : 0 : if (TREE_CODE (t) == INTEGER_CST && tree_int_cst_sgn (t) >= 0)
3659 : : {
3660 : 0 : tree upbound = array_ref_up_bound (expr);
3661 : 0 : if (upbound != NULL_TREE && TREE_CODE (upbound) == INTEGER_CST
3662 : 0 : && !tree_int_cst_equal (upbound,
3663 : 0 : TYPE_MAX_VALUE (TREE_TYPE (upbound))))
3664 : : {
3665 : 0 : if (ctx != ARRAY_REF && ctx != COMPONENT_REF)
3666 : 0 : upbound = size_binop (PLUS_EXPR, upbound,
3667 : : build_int_cst (TREE_TYPE (upbound), 1));
3668 : 0 : if (tree_int_cst_lt (upbound, t))
3669 : : {
3670 : 0 : tree v;
3671 : :
3672 : 0 : for (v = TREE_OPERAND (expr, 0);
3673 : 0 : TREE_CODE (v) == COMPONENT_REF; v = TREE_OPERAND (v, 0))
3674 : 0 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
3675 : : == RECORD_TYPE)
3676 : : {
3677 : 0 : tree fld_chain = DECL_CHAIN (TREE_OPERAND (v, 1));
3678 : 0 : for (; fld_chain; fld_chain = DECL_CHAIN (fld_chain))
3679 : 0 : if (TREE_CODE (fld_chain) == FIELD_DECL)
3680 : : break;
3681 : :
3682 : : if (fld_chain)
3683 : : break;
3684 : : }
3685 : : /* Don't warn if the array might be considered a poor
3686 : : man's flexible array member with a very permissive
3687 : : definition thereof. */
3688 : 0 : if (TREE_CODE (v) == ARRAY_REF
3689 : 0 : || TREE_CODE (v) == COMPONENT_REF)
3690 : 0 : warning (OPT_Warray_bounds_,
3691 : : "index %E denotes an offset "
3692 : : "greater than size of %qT",
3693 : 0 : t, TREE_TYPE (TREE_OPERAND (expr, 0)));
3694 : : }
3695 : : }
3696 : : }
3697 : :
3698 : 0 : t = convert (sizetype, t);
3699 : 0 : off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t);
3700 : 0 : break;
3701 : :
3702 : 0 : case COMPOUND_EXPR:
3703 : : /* Handle static members of volatile structs. */
3704 : 0 : t = TREE_OPERAND (expr, 1);
3705 : 0 : gcc_checking_assert (VAR_P (get_base_address (t)));
3706 : : return fold_offsetof (t, type);
3707 : :
3708 : 0 : default:
3709 : 0 : rust_unreachable ();
3710 : : }
3711 : :
3712 : 0 : if (!POINTER_TYPE_P (type))
3713 : 0 : return size_binop (PLUS_EXPR, base, convert (type, off));
3714 : 0 : return fold_build_pointer_plus (base, off);
3715 : : }
3716 : :
3717 : : // forked from gcc/cp/tree.cc char_type_p
3718 : :
3719 : : /* Returns nonzero if TYPE is a character type, including wchar_t. */
3720 : :
3721 : : int
3722 : 0 : char_type_p (tree type)
3723 : : {
3724 : 0 : return (same_type_p (type, char_type_node)
3725 : 0 : || same_type_p (type, unsigned_char_type_node)
3726 : 0 : || same_type_p (type, signed_char_type_node)
3727 : 0 : || same_type_p (type, char8_type_node)
3728 : 0 : || same_type_p (type, char16_type_node)
3729 : 0 : || same_type_p (type, char32_type_node)
3730 : 0 : || same_type_p (type, wchar_type_node));
3731 : : }
3732 : :
3733 : : // forked from gcc/cp/pt.cc resolve_nondeduced_context
3734 : :
3735 : : /* Core DR 115: In contexts where deduction is done and fails, or in
3736 : : contexts where deduction is not done, if a template argument list is
3737 : : specified and it, along with any default template arguments, identifies
3738 : : a single function template specialization, then the template-id is an
3739 : : lvalue for the function template specialization. */
3740 : :
3741 : : tree
3742 : 0 : resolve_nondeduced_context (tree orig_expr, tsubst_flags_t)
3743 : : {
3744 : 0 : return orig_expr;
3745 : : }
3746 : :
3747 : : // forked from gcc/cp/pt.cc instantiate_non_dependent_or_null
3748 : :
3749 : : /* Like instantiate_non_dependent_expr, but return NULL_TREE rather than
3750 : : an uninstantiated expression. */
3751 : :
3752 : : tree
3753 : 0 : instantiate_non_dependent_or_null (tree expr)
3754 : : {
3755 : 0 : if (expr == NULL_TREE)
3756 : : return NULL_TREE;
3757 : :
3758 : : return expr;
3759 : : }
3760 : :
3761 : : // forked from gcc/cp/pt.cc resolve_nondeduced_context_or_error
3762 : :
3763 : : /* As above, but error out if the expression remains overloaded. */
3764 : :
3765 : : tree
3766 : 0 : resolve_nondeduced_context_or_error (tree exp, tsubst_flags_t complain)
3767 : : {
3768 : 0 : exp = resolve_nondeduced_context (exp, complain);
3769 : 0 : if (type_unknown_p (exp))
3770 : : {
3771 : 0 : if (complain & tf_error)
3772 : 0 : cxx_incomplete_type_error (exp, TREE_TYPE (exp));
3773 : 0 : return error_mark_node;
3774 : : }
3775 : : return exp;
3776 : : }
3777 : :
3778 : : // forked from gcc/cp/tree.cc really_overloaded_fn
3779 : :
3780 : : /* Returns true iff X is an expression for an overloaded function
3781 : : whose type cannot be known without performing overload
3782 : : resolution. */
3783 : :
3784 : : bool
3785 : 0 : really_overloaded_fn (tree x)
3786 : : {
3787 : 0 : return is_overloaded_fn (x) == 2;
3788 : : }
3789 : :
3790 : : // forked from gcc/cp/typeck..cc invalid_nonstatic_memfn_p
3791 : :
3792 : : /* EXPR is being used in a context that is not a function call.
3793 : : Enforce:
3794 : :
3795 : : [expr.ref]
3796 : :
3797 : : The expression can be used only as the left-hand operand of a
3798 : : member function call.
3799 : :
3800 : : [expr.mptr.operator]
3801 : :
3802 : : If the result of .* or ->* is a function, then that result can be
3803 : : used only as the operand for the function call operator ().
3804 : :
3805 : : by issuing an error message if appropriate. Returns true iff EXPR
3806 : : violates these rules. */
3807 : :
3808 : : bool
3809 : 0 : invalid_nonstatic_memfn_p (location_t loc, tree expr, tsubst_flags_t complain)
3810 : : {
3811 : 0 : if (expr == NULL_TREE)
3812 : : return false;
3813 : : /* Don't enforce this in MS mode. */
3814 : 0 : if (flag_ms_extensions)
3815 : : return false;
3816 : 0 : if (is_overloaded_fn (expr) && !really_overloaded_fn (expr))
3817 : 0 : expr = get_first_fn (expr);
3818 : 0 : if (DECL_NONSTATIC_MEMBER_FUNCTION_P (expr))
3819 : : {
3820 : 0 : if (complain & tf_error)
3821 : : {
3822 : 0 : if (DECL_P (expr))
3823 : : {
3824 : 0 : error_at (loc, "invalid use of non-static member function %qD",
3825 : : expr);
3826 : 0 : inform (DECL_SOURCE_LOCATION (expr), "declared here");
3827 : : }
3828 : : else
3829 : 0 : error_at (loc,
3830 : : "invalid use of non-static member function of "
3831 : : "type %qT",
3832 : 0 : TREE_TYPE (expr));
3833 : : }
3834 : 0 : return true;
3835 : : }
3836 : : return false;
3837 : : }
3838 : :
3839 : : // forked from gcc/cp/call.cc strip_top_quals
3840 : :
3841 : : tree
3842 : 0 : strip_top_quals (tree t)
3843 : : {
3844 : 0 : if (TREE_CODE (t) == ARRAY_TYPE)
3845 : : return t;
3846 : 0 : return rs_build_qualified_type (t, 0);
3847 : : }
3848 : :
3849 : : // forked from gcc/cp/typeck2.cc cxx_incomplete_type_inform
3850 : :
3851 : : /* Print an inform about the declaration of the incomplete type TYPE. */
3852 : :
3853 : : // void
3854 : : // cxx_incomplete_type_inform (const_tree type)
3855 : : // {
3856 : : // if (!TYPE_MAIN_DECL (type))
3857 : : // return;
3858 : :
3859 : : // location_t loc = DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type));
3860 : : // tree ptype = strip_top_quals (CONST_CAST_TREE (type));
3861 : :
3862 : : // if (current_class_type && TYPE_BEING_DEFINED (current_class_type)
3863 : : // && same_type_p (ptype, current_class_type))
3864 : : // inform (loc,
3865 : : // "definition of %q#T is not complete until "
3866 : : // "the closing brace",
3867 : : // ptype);
3868 : : // else
3869 : : // inform (loc, "forward declaration of %q#T", ptype);
3870 : : // }
3871 : :
3872 : : // forked from gcc/cp/typeck2.cc cxx_incomplete_type_diagnostic
3873 : :
3874 : : /* Print an error message for invalid use of an incomplete type.
3875 : : VALUE is the expression that was used (or 0 if that isn't known)
3876 : : and TYPE is the type that was invalid. DIAG_KIND indicates the
3877 : : type of diagnostic (see diagnostics/kinds.def). */
3878 : :
3879 : : void
3880 : 0 : cxx_incomplete_type_diagnostic (location_t loc, const_tree value,
3881 : : const_tree type,
3882 : : enum diagnostics::kind diag_kind)
3883 : : {
3884 : : // bool is_decl = false, complained = false;
3885 : :
3886 : 0 : gcc_assert (diag_kind == diagnostics::kind::warning
3887 : : || diag_kind == diagnostics::kind::pedwarn
3888 : : || diag_kind == diagnostics::kind::error);
3889 : :
3890 : : /* Avoid duplicate error message. */
3891 : 0 : if (TREE_CODE (type) == ERROR_MARK)
3892 : : return;
3893 : :
3894 : 0 : if (value)
3895 : : {
3896 : 0 : STRIP_ANY_LOCATION_WRAPPER (value);
3897 : :
3898 : 0 : if (VAR_P (value) || TREE_CODE (value) == PARM_DECL
3899 : : || TREE_CODE (value) == FIELD_DECL)
3900 : : {
3901 : : // complained = emit_diagnostic (diag_kind, DECL_SOURCE_LOCATION
3902 : : // (value),
3903 : : // 0, "%qD has incomplete type", value);
3904 : : // is_decl = true;
3905 : : }
3906 : : }
3907 : 0 : retry:
3908 : : /* We must print an error message. Be clever about what it says. */
3909 : :
3910 : 0 : switch (TREE_CODE (type))
3911 : : {
3912 : : // case RECORD_TYPE:
3913 : : // case UNION_TYPE:
3914 : : // case ENUMERAL_TYPE:
3915 : : // if (!is_decl)
3916 : : // complained
3917 : : // = emit_diagnostic (diag_kind, loc, 0,
3918 : : // "invalid use of incomplete type %q#T", type);
3919 : : // if (complained)
3920 : : // cxx_incomplete_type_inform (type);
3921 : : // break;
3922 : :
3923 : 0 : case VOID_TYPE:
3924 : 0 : emit_diagnostic (diag_kind, loc, 0, "invalid use of %qT", type);
3925 : 0 : break;
3926 : :
3927 : 0 : case ARRAY_TYPE:
3928 : 0 : if (TYPE_DOMAIN (type))
3929 : : {
3930 : 0 : type = TREE_TYPE (type);
3931 : 0 : goto retry;
3932 : : }
3933 : 0 : emit_diagnostic (diag_kind, loc, 0,
3934 : : "invalid use of array with unspecified bounds");
3935 : 0 : break;
3936 : :
3937 : 0 : case OFFSET_TYPE:
3938 : 0 : bad_member:
3939 : 0 : {
3940 : 0 : tree member = TREE_OPERAND (value, 1);
3941 : 0 : if (is_overloaded_fn (member))
3942 : 0 : member = get_first_fn (member);
3943 : :
3944 : 0 : if (DECL_FUNCTION_MEMBER_P (member) && !flag_ms_extensions)
3945 : : {
3946 : 0 : gcc_rich_location richloc (loc);
3947 : : /* If "member" has no arguments (other than "this"), then
3948 : : add a fix-it hint. */
3949 : 0 : if (type_num_arguments (TREE_TYPE (member)) == 1)
3950 : 0 : richloc.add_fixit_insert_after ("()");
3951 : 0 : emit_diagnostic (diag_kind, &richloc, 0,
3952 : : "invalid use of member function %qD "
3953 : : "(did you forget the %<()%> ?)",
3954 : : member);
3955 : 0 : }
3956 : : else
3957 : 0 : emit_diagnostic (diag_kind, loc, 0,
3958 : : "invalid use of member %qD "
3959 : : "(did you forget the %<&%> ?)",
3960 : : member);
3961 : : }
3962 : : break;
3963 : :
3964 : 0 : case LANG_TYPE:
3965 : 0 : if (type == init_list_type_node)
3966 : : {
3967 : 0 : emit_diagnostic (diag_kind, loc, 0,
3968 : : "invalid use of brace-enclosed initializer list");
3969 : 0 : break;
3970 : : }
3971 : 0 : gcc_assert (type == unknown_type_node);
3972 : 0 : if (value && TREE_CODE (value) == COMPONENT_REF)
3973 : 0 : goto bad_member;
3974 : 0 : else if (value && TREE_CODE (value) == ADDR_EXPR)
3975 : 0 : emit_diagnostic (diag_kind, loc, 0,
3976 : : "address of overloaded function with no contextual "
3977 : : "type information");
3978 : 0 : else if (value && TREE_CODE (value) == OVERLOAD)
3979 : 0 : emit_diagnostic (
3980 : 0 : diag_kind, loc, 0,
3981 : : "overloaded function with no contextual type information");
3982 : : else
3983 : 0 : emit_diagnostic (
3984 : 0 : diag_kind, loc, 0,
3985 : : "insufficient contextual information to determine type");
3986 : : break;
3987 : :
3988 : 0 : default:
3989 : 0 : rust_unreachable ();
3990 : : }
3991 : : }
3992 : :
3993 : : // forked from gcc/cp/decl2.cc decl_constant_var_p
3994 : :
3995 : : /* Nonzero for a VAR_DECL whose value can be used in a constant expression.
3996 : :
3997 : : [expr.const]
3998 : :
3999 : : An integral constant-expression can only involve ... const
4000 : : variables of integral or enumeration types initialized with
4001 : : constant expressions ...
4002 : :
4003 : : C++0x also allows constexpr variables and temporaries initialized
4004 : : with constant expressions. We handle the former here, but the latter
4005 : : are just folded away in cxx_eval_constant_expression.
4006 : :
4007 : : The standard does not require that the expression be non-volatile.
4008 : : G++ implements the proposed correction in DR 457. */
4009 : :
4010 : : bool
4011 : 0 : decl_constant_var_p (tree decl)
4012 : : {
4013 : 0 : if (!decl_maybe_constant_var_p (decl))
4014 : : return false;
4015 : :
4016 : 0 : return DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl);
4017 : : }
4018 : :
4019 : : // forked from gcc/cp/decl.cc undeduced_auto_decl
4020 : :
4021 : : /* Returns true iff DECL is a variable or function declared with an auto type
4022 : : that has not yet been deduced to a real type. */
4023 : :
4024 : : bool
4025 : 0 : undeduced_auto_decl (tree)
4026 : : {
4027 : 0 : return false;
4028 : : }
4029 : :
4030 : : // forked from gcc/cp/decl.cc require_deduced_type
4031 : :
4032 : : /* Complain if DECL has an undeduced return type. */
4033 : :
4034 : : bool
4035 : 0 : require_deduced_type (tree, tsubst_flags_t)
4036 : : {
4037 : 0 : return true;
4038 : : }
4039 : :
4040 : : /* Return the location of a tree passed to %+ formats. */
4041 : :
4042 : : location_t
4043 : 0 : location_of (tree t)
4044 : : {
4045 : 0 : if (TYPE_P (t))
4046 : : {
4047 : 0 : t = TYPE_MAIN_DECL (t);
4048 : 0 : if (t == NULL_TREE)
4049 : 0 : return input_location;
4050 : : }
4051 : 0 : else if (TREE_CODE (t) == OVERLOAD)
4052 : 0 : t = OVL_FIRST (t);
4053 : :
4054 : 0 : if (DECL_P (t))
4055 : 0 : return DECL_SOURCE_LOCATION (t);
4056 : :
4057 : 0 : return EXPR_LOCATION (t);
4058 : : }
4059 : :
4060 : : /* For element type ELT_TYPE, return the appropriate type of the heap object
4061 : : containing such element(s). COOKIE_SIZE is NULL or the size of cookie
4062 : : in bytes. FULL_SIZE is NULL if it is unknown how big the heap allocation
4063 : : will be, otherwise size of the heap object. If COOKIE_SIZE is NULL,
4064 : : return array type ELT_TYPE[FULL_SIZE / sizeof(ELT_TYPE)], otherwise return
4065 : : struct { size_t[COOKIE_SIZE/sizeof(size_t)]; ELT_TYPE[N]; }
4066 : : where N is nothing (flexible array member) if FULL_SIZE is NULL, otherwise
4067 : : it is computed such that the size of the struct fits into FULL_SIZE. */
4068 : :
4069 : : tree
4070 : 0 : build_new_constexpr_heap_type (tree elt_type, tree cookie_size, tree full_size)
4071 : : {
4072 : 0 : gcc_assert (cookie_size == NULL_TREE || tree_fits_uhwi_p (cookie_size));
4073 : 0 : gcc_assert (full_size == NULL_TREE || tree_fits_uhwi_p (full_size));
4074 : 0 : unsigned HOST_WIDE_INT csz = cookie_size ? tree_to_uhwi (cookie_size) : 0;
4075 : 0 : tree itype2 = NULL_TREE;
4076 : 0 : if (full_size)
4077 : : {
4078 : 0 : unsigned HOST_WIDE_INT fsz = tree_to_uhwi (full_size);
4079 : 0 : gcc_assert (fsz >= csz);
4080 : 0 : fsz -= csz;
4081 : 0 : fsz /= int_size_in_bytes (elt_type);
4082 : 0 : itype2 = build_index_type (size_int (fsz - 1));
4083 : 0 : if (!cookie_size)
4084 : 0 : return build_cplus_array_type (elt_type, itype2);
4085 : : }
4086 : : else
4087 : 0 : gcc_assert (cookie_size);
4088 : 0 : csz /= int_size_in_bytes (sizetype);
4089 : 0 : tree itype1 = build_index_type (size_int (csz - 1));
4090 : 0 : tree atype1 = build_cplus_array_type (sizetype, itype1);
4091 : 0 : tree atype2 = build_cplus_array_type (elt_type, itype2);
4092 : 0 : tree rtype = cxx_make_type (RECORD_TYPE);
4093 : 0 : TYPE_NAME (rtype) = heap_identifier;
4094 : 0 : tree fld1 = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, atype1);
4095 : 0 : tree fld2 = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, atype2);
4096 : 0 : DECL_FIELD_CONTEXT (fld1) = rtype;
4097 : 0 : DECL_FIELD_CONTEXT (fld2) = rtype;
4098 : 0 : DECL_ARTIFICIAL (fld1) = true;
4099 : 0 : DECL_ARTIFICIAL (fld2) = true;
4100 : 0 : TYPE_FIELDS (rtype) = fld1;
4101 : 0 : DECL_CHAIN (fld1) = fld2;
4102 : 0 : layout_type (rtype);
4103 : 0 : return rtype;
4104 : : }
4105 : :
4106 : : // forked from gcc/cp/class.cc field_poverlapping_p
4107 : :
4108 : : /* Return true iff FIELD_DECL DECL is potentially overlapping. */
4109 : :
4110 : : static bool
4111 : 0 : field_poverlapping_p (tree decl)
4112 : : {
4113 : 0 : return lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (decl));
4114 : : }
4115 : :
4116 : : // forked from gcc/cp/class.cc is_empty_field
4117 : :
4118 : : /* Return true iff DECL is an empty field, either for an empty base or a
4119 : : [[no_unique_address]] data member. */
4120 : :
4121 : : bool
4122 : 0 : is_empty_field (tree decl)
4123 : : {
4124 : 0 : if (!decl || TREE_CODE (decl) != FIELD_DECL)
4125 : : return false;
4126 : :
4127 : 0 : bool r = (is_empty_class (TREE_TYPE (decl)) && (field_poverlapping_p (decl)));
4128 : :
4129 : : /* Empty fields should have size zero. */
4130 : 0 : gcc_checking_assert (!r || integer_zerop (DECL_SIZE (decl)));
4131 : :
4132 : : return r;
4133 : : }
4134 : :
4135 : : // forked from gcc/cp/call.cc in_immediate_context
4136 : :
4137 : : /* Return true if in an immediate function context, or an unevaluated operand,
4138 : : or a subexpression of an immediate invocation. */
4139 : :
4140 : : bool
4141 : 0 : in_immediate_context ()
4142 : : {
4143 : 0 : return false;
4144 : : }
4145 : :
4146 : : // forked from gcc/cp/cvt.cc cp_get_fndecl_from_callee
4147 : :
4148 : : /* FN is the callee of a CALL_EXPR or AGGR_INIT_EXPR; return the FUNCTION_DECL
4149 : : if we can. */
4150 : :
4151 : : tree
4152 : 0 : rs_get_fndecl_from_callee (tree fn, bool fold /* = true */)
4153 : : {
4154 : 0 : if (fn == NULL_TREE)
4155 : : return fn;
4156 : 0 : if (TREE_CODE (fn) == FUNCTION_DECL)
4157 : : return fn;
4158 : 0 : tree type = TREE_TYPE (fn);
4159 : 0 : if (type == NULL_TREE || !INDIRECT_TYPE_P (type))
4160 : : return NULL_TREE;
4161 : 0 : if (fold)
4162 : 0 : fn = Compile::maybe_constant_init (fn);
4163 : 0 : STRIP_NOPS (fn);
4164 : 0 : if (TREE_CODE (fn) == ADDR_EXPR || TREE_CODE (fn) == FDESC_EXPR)
4165 : 0 : fn = TREE_OPERAND (fn, 0);
4166 : 0 : if (TREE_CODE (fn) == FUNCTION_DECL)
4167 : : return fn;
4168 : : return NULL_TREE;
4169 : : }
4170 : :
4171 : : // forked from gcc/cp/cvt.cc cp_get_callee_fndecl_nofold
4172 : : tree
4173 : 0 : rs_get_callee_fndecl_nofold (tree call)
4174 : : {
4175 : 0 : return rs_get_fndecl_from_callee (cp_get_callee (call), false);
4176 : : }
4177 : :
4178 : : // forked from gcc/cp/init.cc is_class_type
4179 : :
4180 : : /* Report an error if TYPE is not a user-defined, class type. If
4181 : : OR_ELSE is nonzero, give an error message. */
4182 : :
4183 : : int
4184 : 0 : is_class_type (tree type, int or_else)
4185 : : {
4186 : 0 : if (type == error_mark_node)
4187 : : return 0;
4188 : :
4189 : 0 : if (!CLASS_TYPE_P (type))
4190 : : {
4191 : 0 : if (or_else)
4192 : 0 : error ("%qT is not a class type", type);
4193 : 0 : return 0;
4194 : : }
4195 : : return 1;
4196 : : }
4197 : :
4198 : : // forked from gcc/cp/decl.cc lookup_enumerator
4199 : :
4200 : : /* Look for an enumerator with the given NAME within the enumeration
4201 : : type ENUMTYPE. This routine is used primarily for qualified name
4202 : : lookup into an enumerator in C++0x, e.g.,
4203 : :
4204 : : enum class Color { Red, Green, Blue };
4205 : :
4206 : : Color color = Color::Red;
4207 : :
4208 : : Returns the value corresponding to the enumerator, or
4209 : : NULL_TREE if no such enumerator was found. */
4210 : : tree
4211 : 0 : lookup_enumerator (tree enumtype, tree name)
4212 : : {
4213 : 0 : tree e;
4214 : 0 : gcc_assert (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE);
4215 : :
4216 : 0 : e = purpose_member (name, TYPE_VALUES (enumtype));
4217 : 0 : return e ? TREE_VALUE (e) : NULL_TREE;
4218 : : }
4219 : :
4220 : : // forked from gcc/cp/init.cc constant_value_1
4221 : : // commented out mark_used
4222 : :
4223 : : /* If DECL is a scalar enumeration constant or variable with a
4224 : : constant initializer, return the initializer (or, its initializers,
4225 : : recursively); otherwise, return DECL. If STRICT_P, the
4226 : : initializer is only returned if DECL is a
4227 : : constant-expression. If RETURN_AGGREGATE_CST_OK_P, it is ok to
4228 : : return an aggregate constant. If UNSHARE_P, return an unshared
4229 : : copy of the initializer. */
4230 : :
4231 : : static tree
4232 : 0 : constant_value_1 (tree decl, bool strict_p, bool return_aggregate_cst_ok_p,
4233 : : bool unshare_p)
4234 : : {
4235 : 0 : while (TREE_CODE (decl) == CONST_DECL || decl_constant_var_p (decl)
4236 : 0 : || (!strict_p && VAR_P (decl)
4237 : 0 : && RS_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (decl))))
4238 : : {
4239 : 0 : tree init;
4240 : : /* If DECL is a static data member in a template
4241 : : specialization, we must instantiate it here. The
4242 : : initializer for the static data member is not processed
4243 : : until needed; we need it now. */
4244 : : // mark_used (decl, tf_none);
4245 : 0 : init = DECL_INITIAL (decl);
4246 : 0 : if (init == error_mark_node)
4247 : : {
4248 : 0 : if (TREE_CODE (decl) == CONST_DECL
4249 : 0 : || DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
4250 : : /* Treat the error as a constant to avoid cascading errors on
4251 : : excessively recursive template instantiation (c++/9335). */
4252 : : return init;
4253 : : else
4254 : 0 : return decl;
4255 : : }
4256 : :
4257 : : /* Instantiate a non-dependent initializer for user variables. We
4258 : : mustn't do this for the temporary for an array compound literal;
4259 : : trying to instatiate the initializer will keep creating new
4260 : : temporaries until we crash. Probably it's not useful to do it for
4261 : : other artificial variables, either. */
4262 : 0 : if (!DECL_ARTIFICIAL (decl))
4263 : 0 : init = instantiate_non_dependent_or_null (init);
4264 : 0 : if (!init || !TREE_TYPE (init) || !TREE_CONSTANT (init)
4265 : 0 : || (!return_aggregate_cst_ok_p
4266 : : /* Unless RETURN_AGGREGATE_CST_OK_P is true, do not
4267 : : return an aggregate constant (of which string
4268 : : literals are a special case), as we do not want
4269 : : to make inadvertent copies of such entities, and
4270 : : we must be sure that their addresses are the
4271 : : same everywhere. */
4272 : 0 : && (TREE_CODE (init) == CONSTRUCTOR
4273 : 0 : || TREE_CODE (init) == STRING_CST)))
4274 : : break;
4275 : : /* Don't return a CONSTRUCTOR for a variable with partial run-time
4276 : : initialization, since it doesn't represent the entire value.
4277 : : Similarly for VECTOR_CSTs created by cp_folding those
4278 : : CONSTRUCTORs. */
4279 : 0 : if ((TREE_CODE (init) == CONSTRUCTOR || TREE_CODE (init) == VECTOR_CST)
4280 : 0 : && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
4281 : : break;
4282 : : /* If the variable has a dynamic initializer, don't use its
4283 : : DECL_INITIAL which doesn't reflect the real value. */
4284 : 0 : if (VAR_P (decl) && TREE_STATIC (decl)
4285 : 0 : && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)
4286 : 0 : && DECL_NONTRIVIALLY_INITIALIZED_P (decl))
4287 : : break;
4288 : : decl = init;
4289 : : }
4290 : 0 : return unshare_p ? unshare_expr (decl) : decl;
4291 : : }
4292 : :
4293 : : // forked from gcc/cp/init.cc decl_constant_value
4294 : :
4295 : : /* A more relaxed version of decl_really_constant_value, used by the
4296 : : common C/C++ code. */
4297 : :
4298 : : tree
4299 : 0 : decl_constant_value (tree decl, bool unshare_p)
4300 : : {
4301 : 0 : return constant_value_1 (decl, /*strict_p=*/false,
4302 : : /*return_aggregate_cst_ok_p=*/true,
4303 : 0 : /*unshare_p=*/unshare_p);
4304 : : }
4305 : :
4306 : : // Below is forked from gcc/cp/init.cc decl_constant_value
4307 : :
4308 : : tree
4309 : 0 : decl_constant_value (tree decl)
4310 : : {
4311 : 0 : return decl_constant_value (decl, /*unshare_p=*/true);
4312 : : }
4313 : :
4314 : : // Below is forked from gcc/cp/cp-gimplify.cc
4315 : :
4316 : : /* Type for source_location_table hash_set. */
4317 : : struct GTY ((for_user)) source_location_table_entry
4318 : : {
4319 : : location_t loc;
4320 : : unsigned uid;
4321 : : tree var;
4322 : : };
4323 : :
4324 : : // exit/reenter namespace to declare some external functions
4325 : :
4326 : : } // namespace Rust
4327 : :
4328 : : extern void gt_pch_nx (Rust::source_location_table_entry &);
4329 : : extern void gt_pch_nx (Rust::source_location_table_entry *, gt_pointer_operator,
4330 : : void *);
4331 : :
4332 : : namespace Rust {
4333 : :
4334 : : /* Traits class for function start hash maps below. */
4335 : :
4336 : : struct rust_source_location_table_entry_hash
4337 : : : ggc_remove<source_location_table_entry>
4338 : : {
4339 : : typedef source_location_table_entry value_type;
4340 : : typedef source_location_table_entry compare_type;
4341 : :
4342 : 0 : static hashval_t hash (const source_location_table_entry &ref)
4343 : : {
4344 : 0 : inchash::hash hstate (0);
4345 : 0 : hstate.add_int (ref.loc);
4346 : 0 : hstate.add_int (ref.uid);
4347 : 0 : return hstate.end ();
4348 : : }
4349 : :
4350 : 0 : static bool equal (const source_location_table_entry &ref1,
4351 : : const source_location_table_entry &ref2)
4352 : : {
4353 : 0 : return ref1.loc == ref2.loc && ref1.uid == ref2.uid;
4354 : : }
4355 : :
4356 : : static void mark_deleted (source_location_table_entry &ref)
4357 : : {
4358 : : ref.loc = UNKNOWN_LOCATION;
4359 : : ref.uid = -1U;
4360 : : ref.var = NULL_TREE;
4361 : : }
4362 : :
4363 : : static const bool empty_zero_p = true;
4364 : :
4365 : 0 : static void mark_empty (source_location_table_entry &ref)
4366 : : {
4367 : 0 : ref.loc = UNKNOWN_LOCATION;
4368 : 0 : ref.uid = 0;
4369 : 0 : ref.var = NULL_TREE;
4370 : : }
4371 : :
4372 : 0 : static bool is_deleted (const source_location_table_entry &ref)
4373 : : {
4374 : 0 : return (ref.loc == UNKNOWN_LOCATION && ref.uid == -1U
4375 : 0 : && ref.var == NULL_TREE);
4376 : : }
4377 : :
4378 : 0 : static bool is_empty (const source_location_table_entry &ref)
4379 : : {
4380 : 0 : return (ref.loc == UNKNOWN_LOCATION && ref.uid == 0
4381 : 0 : && ref.var == NULL_TREE);
4382 : : }
4383 : :
4384 : 0 : static void pch_nx (source_location_table_entry &p) { gt_pch_nx (p); }
4385 : :
4386 : 0 : static void pch_nx (source_location_table_entry &p, gt_pointer_operator op,
4387 : : void *cookie)
4388 : : {
4389 : 0 : gt_pch_nx (&p, op, cookie);
4390 : 0 : }
4391 : : };
4392 : :
4393 : : static GTY (())
4394 : : hash_table<rust_source_location_table_entry_hash> *source_location_table;
4395 : : static GTY (()) unsigned int source_location_id;
4396 : :
4397 : : // Above is forked from gcc/cp/cp-gimplify.cc
4398 : :
4399 : : // forked from gcc/cp/tree.cc lvalue_kind
4400 : :
4401 : : /* If REF is an lvalue, returns the kind of lvalue that REF is.
4402 : : Otherwise, returns clk_none. */
4403 : :
4404 : : cp_lvalue_kind
4405 : 0 : lvalue_kind (const_tree ref)
4406 : : {
4407 : 0 : cp_lvalue_kind op1_lvalue_kind = clk_none;
4408 : 0 : cp_lvalue_kind op2_lvalue_kind = clk_none;
4409 : :
4410 : : /* Expressions of reference type are sometimes wrapped in
4411 : : INDIRECT_REFs. INDIRECT_REFs are just internal compiler
4412 : : representation, not part of the language, so we have to look
4413 : : through them. */
4414 : 0 : if (REFERENCE_REF_P (ref))
4415 : 0 : return lvalue_kind (TREE_OPERAND (ref, 0));
4416 : :
4417 : 0 : if (TREE_TYPE (ref) && TYPE_REF_P (TREE_TYPE (ref)))
4418 : : {
4419 : : /* unnamed rvalue references are rvalues */
4420 : 0 : if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref)) && TREE_CODE (ref) != PARM_DECL
4421 : : && !VAR_P (ref)
4422 : : && TREE_CODE (ref) != COMPONENT_REF
4423 : : /* Functions are always lvalues. */
4424 : 0 : && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
4425 : : {
4426 : 0 : op1_lvalue_kind = clk_rvalueref;
4427 : 0 : if (implicit_rvalue_p (ref))
4428 : 0 : op1_lvalue_kind |= clk_implicit_rval;
4429 : 0 : return op1_lvalue_kind;
4430 : : }
4431 : :
4432 : : /* lvalue references and named rvalue references are lvalues. */
4433 : : return clk_ordinary;
4434 : : }
4435 : :
4436 : 0 : if (ref == current_class_ptr)
4437 : : return clk_none;
4438 : :
4439 : : /* Expressions with cv void type are prvalues. */
4440 : 0 : if (TREE_TYPE (ref) && VOID_TYPE_P (TREE_TYPE (ref)))
4441 : : return clk_none;
4442 : :
4443 : 0 : switch (TREE_CODE (ref))
4444 : : {
4445 : : case SAVE_EXPR:
4446 : : return clk_none;
4447 : :
4448 : : /* preincrements and predecrements are valid lvals, provided
4449 : : what they refer to are valid lvals. */
4450 : 0 : case PREINCREMENT_EXPR:
4451 : 0 : case PREDECREMENT_EXPR:
4452 : 0 : case TRY_CATCH_EXPR:
4453 : 0 : case REALPART_EXPR:
4454 : 0 : case IMAGPART_EXPR:
4455 : 0 : case VIEW_CONVERT_EXPR:
4456 : 0 : return lvalue_kind (TREE_OPERAND (ref, 0));
4457 : :
4458 : 0 : case ARRAY_REF:
4459 : 0 : {
4460 : 0 : tree op1 = TREE_OPERAND (ref, 0);
4461 : 0 : if (TREE_CODE (TREE_TYPE (op1)) == ARRAY_TYPE)
4462 : : {
4463 : 0 : op1_lvalue_kind = lvalue_kind (op1);
4464 : 0 : if (op1_lvalue_kind == clk_class)
4465 : : /* in the case of an array operand, the result is an lvalue if
4466 : : that operand is an lvalue and an xvalue otherwise */
4467 : 0 : op1_lvalue_kind = clk_rvalueref;
4468 : 0 : return op1_lvalue_kind;
4469 : : }
4470 : : else
4471 : : return clk_ordinary;
4472 : : }
4473 : :
4474 : 0 : case MEMBER_REF:
4475 : 0 : case DOTSTAR_EXPR:
4476 : 0 : if (TREE_CODE (ref) == MEMBER_REF)
4477 : : op1_lvalue_kind = clk_ordinary;
4478 : : else
4479 : 0 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
4480 : 0 : if (TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (ref, 1))))
4481 : : op1_lvalue_kind = clk_none;
4482 : 0 : else if (op1_lvalue_kind == clk_class)
4483 : : /* The result of a .* expression whose second operand is a pointer to a
4484 : : data member is an lvalue if the first operand is an lvalue and an
4485 : : xvalue otherwise. */
4486 : 0 : op1_lvalue_kind = clk_rvalueref;
4487 : : return op1_lvalue_kind;
4488 : :
4489 : 0 : case COMPONENT_REF:
4490 : 0 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
4491 : 0 : if (op1_lvalue_kind == clk_class)
4492 : : /* If E1 is an lvalue, then E1.E2 is an lvalue;
4493 : : otherwise E1.E2 is an xvalue. */
4494 : : op1_lvalue_kind = clk_rvalueref;
4495 : :
4496 : : /* Look at the member designator. */
4497 : 0 : if (!op1_lvalue_kind)
4498 : : ;
4499 : 0 : else if (is_overloaded_fn (TREE_OPERAND (ref, 1)))
4500 : : /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
4501 : : situations. If we're seeing a COMPONENT_REF, it's a non-static
4502 : : member, so it isn't an lvalue. */
4503 : : op1_lvalue_kind = clk_none;
4504 : 0 : else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
4505 : : /* This can be IDENTIFIER_NODE in a template. */;
4506 : 0 : else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
4507 : : {
4508 : : /* Clear the ordinary bit. If this object was a class
4509 : : rvalue we want to preserve that information. */
4510 : 0 : op1_lvalue_kind &= ~clk_ordinary;
4511 : : /* The lvalue is for a bitfield. */
4512 : 0 : op1_lvalue_kind |= clk_bitfield;
4513 : : }
4514 : 0 : else if (DECL_PACKED (TREE_OPERAND (ref, 1)))
4515 : 0 : op1_lvalue_kind |= clk_packed;
4516 : :
4517 : : return op1_lvalue_kind;
4518 : :
4519 : : case STRING_CST:
4520 : : case COMPOUND_LITERAL_EXPR:
4521 : : return clk_ordinary;
4522 : :
4523 : 0 : case CONST_DECL:
4524 : : /* CONST_DECL without TREE_STATIC are enumeration values and
4525 : : thus not lvalues. With TREE_STATIC they are used by ObjC++
4526 : : in objc_build_string_object and need to be considered as
4527 : : lvalues. */
4528 : 0 : if (!TREE_STATIC (ref))
4529 : : return clk_none;
4530 : : /* FALLTHRU */
4531 : 0 : case VAR_DECL:
4532 : 0 : if (VAR_P (ref) && DECL_HAS_VALUE_EXPR_P (ref))
4533 : 0 : return lvalue_kind (DECL_VALUE_EXPR (CONST_CAST_TREE (ref)));
4534 : :
4535 : 0 : if (TREE_READONLY (ref) && !TREE_STATIC (ref) && DECL_LANG_SPECIFIC (ref)
4536 : 0 : && DECL_IN_AGGR_P (ref))
4537 : : return clk_none;
4538 : : /* FALLTHRU */
4539 : : case INDIRECT_REF:
4540 : : case ARROW_EXPR:
4541 : : case PARM_DECL:
4542 : : case RESULT_DECL:
4543 : : case PLACEHOLDER_EXPR:
4544 : : return clk_ordinary;
4545 : :
4546 : 0 : case MAX_EXPR:
4547 : 0 : case MIN_EXPR:
4548 : : /* Disallow <? and >? as lvalues if either argument side-effects. */
4549 : 0 : if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 0))
4550 : 0 : || TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 1)))
4551 : : return clk_none;
4552 : 0 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
4553 : 0 : op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1));
4554 : 0 : break;
4555 : :
4556 : 0 : case COND_EXPR:
4557 : 0 : {
4558 : 0 : tree op1 = TREE_OPERAND (ref, 1);
4559 : 0 : if (!op1)
4560 : 0 : op1 = TREE_OPERAND (ref, 0);
4561 : 0 : tree op2 = TREE_OPERAND (ref, 2);
4562 : 0 : op1_lvalue_kind = lvalue_kind (op1);
4563 : 0 : op2_lvalue_kind = lvalue_kind (op2);
4564 : 0 : if (!op1_lvalue_kind != !op2_lvalue_kind)
4565 : : {
4566 : : /* The second or the third operand (but not both) is a
4567 : : throw-expression; the result is of the type
4568 : : and value category of the other. */
4569 : 0 : if (op1_lvalue_kind && TREE_CODE (op2) == THROW_EXPR)
4570 : : op2_lvalue_kind = op1_lvalue_kind;
4571 : 0 : else if (op2_lvalue_kind && TREE_CODE (op1) == THROW_EXPR)
4572 : 0 : op1_lvalue_kind = op2_lvalue_kind;
4573 : : }
4574 : : }
4575 : : break;
4576 : :
4577 : : case MODIFY_EXPR:
4578 : : case TYPEID_EXPR:
4579 : : return clk_ordinary;
4580 : :
4581 : 0 : case COMPOUND_EXPR:
4582 : 0 : return lvalue_kind (TREE_OPERAND (ref, 1));
4583 : :
4584 : : case TARGET_EXPR:
4585 : : return clk_class;
4586 : :
4587 : 0 : case VA_ARG_EXPR:
4588 : 0 : return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none);
4589 : :
4590 : 0 : case CALL_EXPR:
4591 : : /* We can see calls outside of TARGET_EXPR in templates. */
4592 : 0 : if (CLASS_TYPE_P (TREE_TYPE (ref)))
4593 : : return clk_class;
4594 : : return clk_none;
4595 : :
4596 : 0 : case FUNCTION_DECL:
4597 : : /* All functions (except non-static-member functions) are
4598 : : lvalues. */
4599 : 0 : return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref) ? clk_none : clk_ordinary);
4600 : :
4601 : 0 : case PAREN_EXPR:
4602 : 0 : return lvalue_kind (TREE_OPERAND (ref, 0));
4603 : :
4604 : 0 : case TEMPLATE_PARM_INDEX:
4605 : 0 : if (CLASS_TYPE_P (TREE_TYPE (ref)))
4606 : : /* A template parameter object is an lvalue. */
4607 : : return clk_ordinary;
4608 : : return clk_none;
4609 : :
4610 : 0 : default:
4611 : 0 : if (!TREE_TYPE (ref))
4612 : : return clk_none;
4613 : 0 : if (CLASS_TYPE_P (TREE_TYPE (ref))
4614 : 0 : || TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE)
4615 : : return clk_class;
4616 : : return clk_none;
4617 : : }
4618 : :
4619 : : /* If one operand is not an lvalue at all, then this expression is
4620 : : not an lvalue. */
4621 : 0 : if (!op1_lvalue_kind || !op2_lvalue_kind)
4622 : : return clk_none;
4623 : :
4624 : : /* Otherwise, it's an lvalue, and it has all the odd properties
4625 : : contributed by either operand. */
4626 : 0 : op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
4627 : : /* It's not an ordinary lvalue if it involves any other kind. */
4628 : 0 : if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
4629 : 0 : op1_lvalue_kind &= ~clk_ordinary;
4630 : : /* It can't be both a pseudo-lvalue and a non-addressable lvalue.
4631 : : A COND_EXPR of those should be wrapped in a TARGET_EXPR. */
4632 : 0 : if ((op1_lvalue_kind & (clk_rvalueref | clk_class))
4633 : 0 : && (op1_lvalue_kind & (clk_bitfield | clk_packed)))
4634 : 0 : op1_lvalue_kind = clk_none;
4635 : : return op1_lvalue_kind;
4636 : : }
4637 : :
4638 : : // forked from gcc/cp/tree.cc glvalue_p
4639 : :
4640 : : /* This differs from lvalue_p in that xvalues are included. */
4641 : :
4642 : : bool
4643 : 0 : glvalue_p (const_tree ref)
4644 : : {
4645 : 0 : cp_lvalue_kind kind = lvalue_kind (ref);
4646 : 0 : if (kind & clk_class)
4647 : : return false;
4648 : : else
4649 : 0 : return (kind != clk_none);
4650 : : }
4651 : :
4652 : : // forked from gcc/cp/init.cc cv_qualified_p
4653 : :
4654 : : /* Returns nonzero if TYPE is const or volatile. */
4655 : :
4656 : : bool
4657 : 0 : cv_qualified_p (const_tree type)
4658 : : {
4659 : 0 : int quals = rs_type_quals (type);
4660 : 0 : return (quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)) != 0;
4661 : : }
4662 : :
4663 : : // forked from gcc/cp/tree.cc rvalue
4664 : :
4665 : : /* EXPR is being used in an rvalue context. Return a version of EXPR
4666 : : that is marked as an rvalue. */
4667 : :
4668 : : tree
4669 : 0 : rvalue (tree expr)
4670 : : {
4671 : 0 : tree type;
4672 : :
4673 : 0 : if (error_operand_p (expr))
4674 : : return expr;
4675 : :
4676 : 0 : expr = mark_rvalue_use (expr);
4677 : :
4678 : : /* [basic.lval]
4679 : :
4680 : : Non-class rvalues always have cv-unqualified types. */
4681 : 0 : type = TREE_TYPE (expr);
4682 : 0 : if (!CLASS_TYPE_P (type) && cv_qualified_p (type))
4683 : 0 : type = cv_unqualified (type);
4684 : :
4685 : : /* We need to do this for rvalue refs as well to get the right answer
4686 : : from decltype; see c++/36628. */
4687 : 0 : if (glvalue_p (expr))
4688 : : {
4689 : : /* But don't use this function for class lvalues; use move (to treat an
4690 : : lvalue as an xvalue) or force_rvalue (to make a prvalue copy). */
4691 : 0 : gcc_checking_assert (!CLASS_TYPE_P (type));
4692 : 0 : expr = build1 (NON_LVALUE_EXPR, type, expr);
4693 : : }
4694 : 0 : else if (type != TREE_TYPE (expr))
4695 : 0 : expr = build_nop (type, expr);
4696 : :
4697 : : return expr;
4698 : : }
4699 : :
4700 : : // forked from gcc/cp/tree.cc bitfield_p
4701 : :
4702 : : /* True if REF is a bit-field. */
4703 : :
4704 : : bool
4705 : 0 : bitfield_p (const_tree ref)
4706 : : {
4707 : 0 : return (lvalue_kind (ref) & clk_bitfield);
4708 : : }
4709 : :
4710 : : // forked from gcc/cp/typeck.cc cxx_mark_addressable
4711 : :
4712 : : /* Mark EXP saying that we need to be able to take the
4713 : : address of it; it should not be allocated in a register.
4714 : : Value is true if successful. ARRAY_REF_P is true if this
4715 : : is for ARRAY_REF construction - in that case we don't want
4716 : : to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
4717 : : it is fine to use ARRAY_REFs for vector subscripts on vector
4718 : : register variables.
4719 : :
4720 : : C++: we do not allow `current_class_ptr' to be addressable. */
4721 : :
4722 : : bool
4723 : 0 : cxx_mark_addressable (tree exp, bool array_ref_p)
4724 : : {
4725 : 0 : tree x = exp;
4726 : :
4727 : 0 : while (1)
4728 : 0 : switch (TREE_CODE (x))
4729 : : {
4730 : 0 : case VIEW_CONVERT_EXPR:
4731 : 0 : if (array_ref_p && TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
4732 : 0 : && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))))
4733 : : return true;
4734 : 0 : x = TREE_OPERAND (x, 0);
4735 : 0 : break;
4736 : :
4737 : 0 : case COMPONENT_REF:
4738 : 0 : if (bitfield_p (x))
4739 : 0 : error ("attempt to take address of bit-field");
4740 : : /* FALLTHRU */
4741 : 0 : case ADDR_EXPR:
4742 : 0 : case ARRAY_REF:
4743 : 0 : case REALPART_EXPR:
4744 : 0 : case IMAGPART_EXPR:
4745 : 0 : x = TREE_OPERAND (x, 0);
4746 : 0 : break;
4747 : :
4748 : 0 : case PARM_DECL:
4749 : 0 : if (x == current_class_ptr)
4750 : : {
4751 : 0 : error ("cannot take the address of %<this%>, which is an rvalue "
4752 : : "expression");
4753 : 0 : TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later. */
4754 : 0 : return true;
4755 : : }
4756 : : /* Fall through. */
4757 : :
4758 : 0 : case VAR_DECL:
4759 : : /* Caller should not be trying to mark initialized
4760 : : constant fields addressable. */
4761 : 0 : gcc_assert (DECL_LANG_SPECIFIC (x) == 0 || DECL_IN_AGGR_P (x) == 0
4762 : : || TREE_STATIC (x) || DECL_EXTERNAL (x));
4763 : : /* Fall through. */
4764 : :
4765 : 0 : case RESULT_DECL:
4766 : 0 : if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x) && !DECL_ARTIFICIAL (x))
4767 : : {
4768 : 0 : if (VAR_P (x) && DECL_HARD_REGISTER (x))
4769 : : {
4770 : 0 : error ("address of explicit register variable %qD requested",
4771 : : x);
4772 : 0 : return false;
4773 : : }
4774 : 0 : else if (extra_warnings)
4775 : 0 : warning (
4776 : 0 : OPT_Wextra,
4777 : : "address requested for %qD, which is declared %<register%>", x);
4778 : : }
4779 : 0 : TREE_ADDRESSABLE (x) = 1;
4780 : 0 : return true;
4781 : :
4782 : 0 : case CONST_DECL:
4783 : 0 : case FUNCTION_DECL:
4784 : 0 : TREE_ADDRESSABLE (x) = 1;
4785 : 0 : return true;
4786 : :
4787 : 0 : case CONSTRUCTOR:
4788 : 0 : TREE_ADDRESSABLE (x) = 1;
4789 : 0 : return true;
4790 : :
4791 : 0 : case TARGET_EXPR:
4792 : 0 : TREE_ADDRESSABLE (x) = 1;
4793 : 0 : cxx_mark_addressable (TREE_OPERAND (x, 0));
4794 : 0 : return true;
4795 : :
4796 : : default:
4797 : : return true;
4798 : : }
4799 : : }
4800 : :
4801 : : // forked from gcc/cp/typeck.cc build_address
4802 : :
4803 : : /* Returns the address of T. This function will fold away
4804 : : ADDR_EXPR of INDIRECT_REF. This is only for low-level usage;
4805 : : most places should use cp_build_addr_expr instead. */
4806 : :
4807 : : tree
4808 : 0 : build_address (tree t)
4809 : : {
4810 : 0 : if (error_operand_p (t) || !cxx_mark_addressable (t))
4811 : 0 : return error_mark_node;
4812 : 0 : gcc_checking_assert (TREE_CODE (t) != CONSTRUCTOR);
4813 : 0 : t = build_fold_addr_expr_loc (EXPR_LOCATION (t), t);
4814 : 0 : if (TREE_CODE (t) != ADDR_EXPR)
4815 : 0 : t = rvalue (t);
4816 : : return t;
4817 : : }
4818 : :
4819 : : // forked from gcc/cp/gp-gimplify.cc fold_builtin_source_location
4820 : :
4821 : : /* Fold __builtin_source_location () call. LOC is the location
4822 : : of the call. */
4823 : :
4824 : : tree
4825 : 0 : fold_builtin_source_location (location_t loc)
4826 : : {
4827 : : // if (source_location_impl == NULL_TREE)
4828 : : // {
4829 : : // auto_diagnostic_group d;
4830 : : // source_location_impl = get_source_location_impl_type (loc);
4831 : : // if (source_location_impl == error_mark_node)
4832 : : // inform (loc, "evaluating %qs", "__builtin_source_location");
4833 : : // }
4834 : 0 : if (source_location_impl == error_mark_node)
4835 : 0 : return build_zero_cst (const_ptr_type_node);
4836 : 0 : if (source_location_table == NULL)
4837 : 0 : source_location_table
4838 : 0 : = hash_table<rust_source_location_table_entry_hash>::create_ggc (64);
4839 : 0 : const line_map_ordinary *map;
4840 : 0 : source_location_table_entry entry;
4841 : 0 : entry.loc = linemap_resolve_location (line_table, loc,
4842 : : LRK_MACRO_EXPANSION_POINT, &map);
4843 : 0 : entry.uid = current_function_decl ? DECL_UID (current_function_decl) : -1;
4844 : 0 : entry.var = error_mark_node;
4845 : 0 : source_location_table_entry *entryp
4846 : 0 : = source_location_table->find_slot (entry, INSERT);
4847 : 0 : tree var;
4848 : 0 : if (entryp->var)
4849 : : var = entryp->var;
4850 : : else
4851 : : {
4852 : 0 : char tmp_name[32];
4853 : 0 : ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lsrc_loc", source_location_id++);
4854 : 0 : var = build_decl (loc, VAR_DECL, get_identifier (tmp_name),
4855 : : source_location_impl);
4856 : 0 : TREE_STATIC (var) = 1;
4857 : 0 : TREE_PUBLIC (var) = 0;
4858 : 0 : DECL_ARTIFICIAL (var) = 1;
4859 : 0 : DECL_IGNORED_P (var) = 1;
4860 : 0 : DECL_EXTERNAL (var) = 0;
4861 : 0 : DECL_DECLARED_CONSTEXPR_P (var) = 1;
4862 : 0 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var) = 1;
4863 : 0 : layout_decl (var, 0);
4864 : :
4865 : 0 : vec<constructor_elt, va_gc> *v = NULL;
4866 : 0 : vec_alloc (v, 4);
4867 : 0 : for (tree field = TYPE_FIELDS (source_location_impl);
4868 : 0 : (field = next_initializable_field (field)) != NULL_TREE;
4869 : 0 : field = DECL_CHAIN (field))
4870 : : {
4871 : 0 : const char *n = IDENTIFIER_POINTER (DECL_NAME (field));
4872 : 0 : tree val = NULL_TREE;
4873 : 0 : if (strcmp (n, "_M_file_name") == 0)
4874 : : {
4875 : 0 : if (const char *fname = LOCATION_FILE (loc))
4876 : : {
4877 : 0 : fname = remap_macro_filename (fname);
4878 : 0 : val = build_string_literal (strlen (fname) + 1, fname);
4879 : : }
4880 : : else
4881 : 0 : val = build_string_literal (1, "");
4882 : : }
4883 : 0 : else if (strcmp (n, "_M_function_name") == 0)
4884 : : {
4885 : 0 : const char *name = "todo: add funciton name here";
4886 : :
4887 : : // if (current_function_decl)
4888 : : // name = cxx_printable_name (current_function_decl, 2);
4889 : :
4890 : 0 : val = build_string_literal (strlen (name) + 1, name);
4891 : : }
4892 : 0 : else if (strcmp (n, "_M_line") == 0)
4893 : 0 : val = build_int_cst (TREE_TYPE (field), LOCATION_LINE (loc));
4894 : 0 : else if (strcmp (n, "_M_column") == 0)
4895 : 0 : val = build_int_cst (TREE_TYPE (field), LOCATION_COLUMN (loc));
4896 : : else
4897 : 0 : rust_unreachable ();
4898 : 0 : CONSTRUCTOR_APPEND_ELT (v, field, val);
4899 : : }
4900 : :
4901 : 0 : tree ctor = build_constructor (source_location_impl, v);
4902 : 0 : TREE_CONSTANT (ctor) = 1;
4903 : 0 : TREE_STATIC (ctor) = 1;
4904 : 0 : DECL_INITIAL (var) = ctor;
4905 : 0 : varpool_node::finalize_decl (var);
4906 : 0 : *entryp = entry;
4907 : 0 : entryp->var = var;
4908 : : }
4909 : :
4910 : 0 : return build_fold_addr_expr_with_type_loc (loc, var, const_ptr_type_node);
4911 : : }
4912 : :
4913 : : // forked from gcc/c-family/c-common.cc braced_lists_to_strings
4914 : :
4915 : : /* Attempt to convert a braced array initializer list CTOR for array
4916 : : TYPE into a STRING_CST for convenience and efficiency. Return
4917 : : the converted string on success or the original ctor on failure. */
4918 : :
4919 : : static tree
4920 : 0 : braced_list_to_string (tree type, tree ctor, bool member)
4921 : : {
4922 : : /* Ignore non-members with unknown size like arrays with unspecified
4923 : : bound. */
4924 : 0 : tree typesize = TYPE_SIZE_UNIT (type);
4925 : 0 : if (!member && !tree_fits_uhwi_p (typesize))
4926 : : return ctor;
4927 : :
4928 : : /* If the target char size differes from the host char size, we'd risk
4929 : : loosing data and getting object sizes wrong by converting to
4930 : : host chars. */
4931 : 0 : if (TYPE_PRECISION (char_type_node) != CHAR_BIT)
4932 : : return ctor;
4933 : :
4934 : : /* If the array has an explicit bound, use it to constrain the size
4935 : : of the string. If it doesn't, be sure to create a string that's
4936 : : as long as implied by the index of the last zero specified via
4937 : : a designator, as in:
4938 : : const char a[] = { [7] = 0 }; */
4939 : 0 : unsigned HOST_WIDE_INT maxelts;
4940 : 0 : if (typesize)
4941 : : {
4942 : 0 : maxelts = tree_to_uhwi (typesize);
4943 : 0 : maxelts /= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type)));
4944 : : }
4945 : : else
4946 : : maxelts = HOST_WIDE_INT_M1U;
4947 : :
4948 : : /* Avoid converting initializers for zero-length arrays (but do
4949 : : create them for flexible array members). */
4950 : 0 : if (!maxelts)
4951 : : return ctor;
4952 : :
4953 : 0 : unsigned HOST_WIDE_INT nelts = CONSTRUCTOR_NELTS (ctor);
4954 : :
4955 : 0 : auto_vec<char> str;
4956 : 0 : str.reserve (nelts + 1);
4957 : :
4958 : 0 : unsigned HOST_WIDE_INT i;
4959 : 0 : tree index, value;
4960 : :
4961 : 0 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, index, value)
4962 : : {
4963 : 0 : unsigned HOST_WIDE_INT idx = i;
4964 : 0 : if (index)
4965 : : {
4966 : 0 : if (!tree_fits_uhwi_p (index))
4967 : : return ctor;
4968 : 0 : idx = tree_to_uhwi (index);
4969 : : }
4970 : :
4971 : : /* auto_vec is limited to UINT_MAX elements. */
4972 : 0 : if (idx > UINT_MAX)
4973 : : return ctor;
4974 : :
4975 : : /* Avoid non-constant initializers. */
4976 : 0 : if (!tree_fits_shwi_p (value))
4977 : : return ctor;
4978 : :
4979 : : /* Skip over embedded nuls except the last one (initializer
4980 : : elements are in ascending order of indices). */
4981 : 0 : HOST_WIDE_INT val = tree_to_shwi (value);
4982 : 0 : if (!val && i + 1 < nelts)
4983 : 0 : continue;
4984 : :
4985 : 0 : if (idx < str.length ())
4986 : : return ctor;
4987 : :
4988 : : /* Bail if the CTOR has a block of more than 256 embedded nuls
4989 : : due to implicitly initialized elements. */
4990 : 0 : unsigned nchars = (idx - str.length ()) + 1;
4991 : 0 : if (nchars > 256)
4992 : : return ctor;
4993 : :
4994 : 0 : if (nchars > 1)
4995 : : {
4996 : 0 : str.reserve (idx);
4997 : 0 : str.quick_grow_cleared (idx);
4998 : : }
4999 : :
5000 : 0 : if (idx >= maxelts)
5001 : : return ctor;
5002 : :
5003 : 0 : str.safe_insert (idx, val);
5004 : : }
5005 : :
5006 : : /* Append a nul string termination. */
5007 : 0 : if (maxelts != HOST_WIDE_INT_M1U && str.length () < maxelts)
5008 : 0 : str.safe_push (0);
5009 : :
5010 : : /* Build a STRING_CST with the same type as the array. */
5011 : 0 : tree res = build_string (str.length (), str.begin ());
5012 : 0 : TREE_TYPE (res) = type;
5013 : 0 : return res;
5014 : 0 : }
5015 : :
5016 : : // forked from gcc/c-family/c-common.cc braced_lists_to_strings
5017 : :
5018 : : /* Implementation of the two-argument braced_lists_to_string withe
5019 : : the same arguments plus MEMBER which is set for struct members
5020 : : to allow initializers for flexible member arrays. */
5021 : :
5022 : : static tree
5023 : 0 : braced_lists_to_strings (tree type, tree ctor, bool member)
5024 : : {
5025 : 0 : if (TREE_CODE (ctor) != CONSTRUCTOR)
5026 : : return ctor;
5027 : :
5028 : 0 : tree_code code = TREE_CODE (type);
5029 : :
5030 : 0 : tree ttp;
5031 : 0 : if (code == ARRAY_TYPE)
5032 : 0 : ttp = TREE_TYPE (type);
5033 : 0 : else if (code == RECORD_TYPE)
5034 : : {
5035 : 0 : ttp = TREE_TYPE (ctor);
5036 : 0 : if (TREE_CODE (ttp) == ARRAY_TYPE)
5037 : : {
5038 : 0 : type = ttp;
5039 : 0 : ttp = TREE_TYPE (ttp);
5040 : : }
5041 : : }
5042 : : else
5043 : : return ctor;
5044 : :
5045 : 0 : if ((TREE_CODE (ttp) == ARRAY_TYPE || TREE_CODE (ttp) == INTEGER_TYPE)
5046 : 0 : && TYPE_STRING_FLAG (ttp))
5047 : 0 : return braced_list_to_string (type, ctor, member);
5048 : :
5049 : 0 : code = TREE_CODE (ttp);
5050 : 0 : if (code == ARRAY_TYPE || RECORD_OR_UNION_TYPE_P (ttp))
5051 : : {
5052 : 0 : bool rec = RECORD_OR_UNION_TYPE_P (ttp);
5053 : :
5054 : : /* Handle array of arrays or struct member initializers. */
5055 : 0 : tree val;
5056 : 0 : unsigned HOST_WIDE_INT idx;
5057 : 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), idx, val)
5058 : : {
5059 : 0 : val = braced_lists_to_strings (ttp, val, rec);
5060 : 0 : CONSTRUCTOR_ELT (ctor, idx)->value = val;
5061 : : }
5062 : : }
5063 : :
5064 : : return ctor;
5065 : : }
5066 : :
5067 : : // forked from gcc/c-family/c-common.cc braced_lists_to_strings
5068 : :
5069 : : /* Attempt to convert a CTOR containing braced array initializer lists
5070 : : for array TYPE into one containing STRING_CSTs, for convenience and
5071 : : efficiency. Recurse for arrays of arrays and member initializers.
5072 : : Return the converted CTOR or STRING_CST on success or the original
5073 : : CTOR otherwise. */
5074 : :
5075 : : tree
5076 : 0 : braced_lists_to_strings (tree type, tree ctor)
5077 : : {
5078 : 0 : return braced_lists_to_strings (type, ctor, false);
5079 : : }
5080 : :
5081 : : /*---------------------------------------------------------------------------
5082 : : Constraint satisfaction
5083 : : ---------------------------------------------------------------------------*/
5084 : :
5085 : : // forked from gcc/cp/constraint.cc satisfying_constraint
5086 : :
5087 : : /* True if we are currently satisfying a failed_type_completions. */
5088 : :
5089 : : static bool satisfying_constraint;
5090 : :
5091 : : // forked from gcc/cp/constraint.cc satisfying_constraint
5092 : :
5093 : : /* A vector of incomplete types (and of declarations with undeduced return
5094 : : type), appended to by note_failed_type_completion_for_satisfaction. The
5095 : : satisfaction caches use this in order to keep track of "potentially unstable"
5096 : : satisfaction results.
5097 : :
5098 : : Since references to entries in this vector are stored only in the
5099 : : GC-deletable sat_cache, it's safe to make this deletable as well. */
5100 : :
5101 : : static GTY ((deletable)) vec<tree, va_gc> *failed_type_completions;
5102 : :
5103 : : // forked from gcc/cp/constraint.cc note_failed_type_completion_for_satisfaction
5104 : :
5105 : : /* Called whenever a type completion (or return type deduction) failure occurs
5106 : : that definitely affects the meaning of the program, by e.g. inducing
5107 : : substitution failure. */
5108 : :
5109 : : void
5110 : 0 : note_failed_type_completion_for_satisfaction (tree t)
5111 : : {
5112 : 0 : if (satisfying_constraint)
5113 : : {
5114 : 0 : gcc_checking_assert ((TYPE_P (t) && !COMPLETE_TYPE_P (t))
5115 : : || (DECL_P (t) && undeduced_auto_decl (t)));
5116 : 0 : vec_safe_push (failed_type_completions, t);
5117 : : }
5118 : 0 : }
5119 : :
5120 : : // forked from gcc/cp/typeck.cc complete_type
5121 : :
5122 : : /* Try to complete TYPE, if it is incomplete. For example, if TYPE is
5123 : : a template instantiation, do the instantiation. Returns TYPE,
5124 : : whether or not it could be completed, unless something goes
5125 : : horribly wrong, in which case the error_mark_node is returned. */
5126 : :
5127 : : tree
5128 : 0 : complete_type (tree type)
5129 : : {
5130 : 0 : if (type == NULL_TREE)
5131 : : /* Rather than crash, we return something sure to cause an error
5132 : : at some point. */
5133 : 0 : return error_mark_node;
5134 : :
5135 : 0 : if (type == error_mark_node || COMPLETE_TYPE_P (type))
5136 : : ;
5137 : 0 : else if (TREE_CODE (type) == ARRAY_TYPE)
5138 : : {
5139 : 0 : tree t = complete_type (TREE_TYPE (type));
5140 : 0 : unsigned int needs_constructing, has_nontrivial_dtor;
5141 : 0 : if (COMPLETE_TYPE_P (t))
5142 : 0 : layout_type (type);
5143 : 0 : needs_constructing = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t));
5144 : 0 : has_nontrivial_dtor
5145 : 0 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (t));
5146 : 0 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
5147 : : {
5148 : 0 : TYPE_NEEDS_CONSTRUCTING (t) = needs_constructing;
5149 : 0 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = has_nontrivial_dtor;
5150 : : }
5151 : : }
5152 : :
5153 : : return type;
5154 : : }
5155 : :
5156 : : // forked from gcc/cp/typeck.cc complete_type_or_maybe_complain
5157 : :
5158 : : /* Like complete_type, but issue an error if the TYPE cannot be completed.
5159 : : VALUE is used for informative diagnostics.
5160 : : Returns NULL_TREE if the type cannot be made complete. */
5161 : :
5162 : : tree
5163 : 0 : complete_type_or_maybe_complain (tree type, tree value, tsubst_flags_t complain)
5164 : : {
5165 : 0 : type = complete_type (type);
5166 : 0 : if (type == error_mark_node)
5167 : : /* We already issued an error. */
5168 : : return NULL_TREE;
5169 : 0 : else if (!COMPLETE_TYPE_P (type))
5170 : : {
5171 : 0 : if (complain & tf_error)
5172 : 0 : cxx_incomplete_type_diagnostic (value, type, diagnostics::kind::error);
5173 : 0 : note_failed_type_completion_for_satisfaction (type);
5174 : 0 : return NULL_TREE;
5175 : : }
5176 : : else
5177 : : return type;
5178 : : }
5179 : :
5180 : : // forked from gcc/cp/typeck.cc complete_type_or_else
5181 : :
5182 : : tree
5183 : 0 : complete_type_or_else (tree type, tree value)
5184 : : {
5185 : 0 : return complete_type_or_maybe_complain (type, value, tf_warning_or_error);
5186 : : }
5187 : :
5188 : : // forked from gcc/cp/tree.cc std_layout_type_p
5189 : :
5190 : : /* Returns true iff T is a standard-layout type, as defined in
5191 : : [basic.types]. */
5192 : :
5193 : : bool
5194 : 0 : std_layout_type_p (const_tree t)
5195 : : {
5196 : 0 : t = strip_array_types (CONST_CAST_TREE (t));
5197 : :
5198 : 0 : if (CLASS_TYPE_P (t))
5199 : 0 : return !CLASSTYPE_NON_STD_LAYOUT (t);
5200 : : else
5201 : 0 : return scalarish_type_p (t);
5202 : : }
5203 : :
5204 : : // forked from /gcc/cp/semantics.cc first_nonstatic_data_member_p
5205 : :
5206 : : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
5207 : : return true if MEMBERTYPE is the type of the first non-static data member
5208 : : of TYPE or for unions of any members. */
5209 : : static bool
5210 : 0 : first_nonstatic_data_member_p (tree type, tree membertype)
5211 : : {
5212 : 0 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
5213 : : {
5214 : 0 : if (TREE_CODE (field) != FIELD_DECL)
5215 : 0 : continue;
5216 : 0 : if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
5217 : 0 : continue;
5218 : 0 : if (DECL_FIELD_IS_BASE (field))
5219 : 0 : return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
5220 : 0 : if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
5221 : : {
5222 : 0 : if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
5223 : 0 : || std_layout_type_p (TREE_TYPE (field)))
5224 : 0 : && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
5225 : : return true;
5226 : : }
5227 : 0 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
5228 : : membertype))
5229 : : return true;
5230 : 0 : if (TREE_CODE (type) != UNION_TYPE)
5231 : : return false;
5232 : : }
5233 : : return false;
5234 : : }
5235 : :
5236 : : // forked from gcc/cp/semantics.cc
5237 : : // fold_builtin_is_pointer_inverconvertible_with_class
5238 : :
5239 : : /* Fold __builtin_is_pointer_interconvertible_with_class call. */
5240 : :
5241 : : tree
5242 : 0 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
5243 : : tree *args)
5244 : : {
5245 : : /* Unless users call the builtin directly, the following 3 checks should be
5246 : : ensured from std::is_pointer_interconvertible_with_class function
5247 : : template. */
5248 : 0 : if (nargs != 1)
5249 : : {
5250 : 0 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
5251 : : "needs a single argument");
5252 : 0 : return boolean_false_node;
5253 : : }
5254 : 0 : tree arg = args[0];
5255 : 0 : if (error_operand_p (arg))
5256 : 0 : return boolean_false_node;
5257 : 0 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
5258 : : {
5259 : 0 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
5260 : : "argument is not pointer to member");
5261 : 0 : return boolean_false_node;
5262 : : }
5263 : :
5264 : 0 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
5265 : 0 : return boolean_false_node;
5266 : :
5267 : 0 : tree membertype = TREE_TYPE (TREE_TYPE (arg));
5268 : 0 : tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
5269 : 0 : if (!complete_type_or_else (basetype, NULL_TREE))
5270 : 0 : return boolean_false_node;
5271 : :
5272 : 0 : if (TREE_CODE (basetype) != UNION_TYPE && !std_layout_type_p (basetype))
5273 : 0 : return boolean_false_node;
5274 : :
5275 : 0 : if (!first_nonstatic_data_member_p (basetype, membertype))
5276 : 0 : return boolean_false_node;
5277 : :
5278 : 0 : if (integer_nonzerop (arg))
5279 : 0 : return boolean_false_node;
5280 : 0 : if (integer_zerop (arg))
5281 : 0 : return boolean_true_node;
5282 : :
5283 : 0 : return fold_build2 (EQ_EXPR, boolean_type_node, arg,
5284 : : build_zero_cst (TREE_TYPE (arg)));
5285 : : }
5286 : :
5287 : : // forked from gcc/c-family/c-common.cc registered_builtin_types
5288 : :
5289 : : /* Used for communication between c_common_type_for_mode and
5290 : : c_register_builtin_type. */
5291 : : tree registered_builtin_types;
5292 : :
5293 : : /* Return a data type that has machine mode MODE.
5294 : : If the mode is an integer,
5295 : : then UNSIGNEDP selects between signed and unsigned types.
5296 : : If the mode is a fixed-point mode,
5297 : : then UNSIGNEDP selects between saturating and nonsaturating types. */
5298 : :
5299 : : // forked from gcc/c-family/c-common.cc c_common_type_for_mode
5300 : :
5301 : : tree
5302 : 0 : c_common_type_for_mode (machine_mode mode, int unsignedp)
5303 : : {
5304 : 0 : tree t;
5305 : 0 : int i;
5306 : :
5307 : 0 : if (mode == TYPE_MODE (integer_type_node))
5308 : 0 : return unsignedp ? unsigned_type_node : integer_type_node;
5309 : :
5310 : 0 : if (mode == TYPE_MODE (signed_char_type_node))
5311 : 0 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
5312 : :
5313 : 0 : if (mode == TYPE_MODE (short_integer_type_node))
5314 : 0 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
5315 : :
5316 : 0 : if (mode == TYPE_MODE (long_integer_type_node))
5317 : 0 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
5318 : :
5319 : 0 : if (mode == TYPE_MODE (long_long_integer_type_node))
5320 : 0 : return unsignedp ? long_long_unsigned_type_node
5321 : 0 : : long_long_integer_type_node;
5322 : :
5323 : 0 : for (i = 0; i < NUM_INT_N_ENTS; i++)
5324 : 0 : if (int_n_enabled_p[i] && mode == int_n_data[i].m)
5325 : 0 : return (unsignedp ? int_n_trees[i].unsigned_type
5326 : 0 : : int_n_trees[i].signed_type);
5327 : :
5328 : 0 : if (mode == QImode)
5329 : 0 : return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
5330 : :
5331 : 0 : if (mode == HImode)
5332 : 0 : return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
5333 : :
5334 : 0 : if (mode == SImode)
5335 : 0 : return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
5336 : :
5337 : 0 : if (mode == DImode)
5338 : 0 : return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
5339 : :
5340 : : #if HOST_BITS_PER_WIDE_INT >= 64
5341 : 0 : if (mode == TYPE_MODE (intTI_type_node))
5342 : 0 : return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
5343 : : #endif
5344 : :
5345 : 0 : if (mode == TYPE_MODE (float_type_node))
5346 : 0 : return float_type_node;
5347 : :
5348 : 0 : if (mode == TYPE_MODE (double_type_node))
5349 : 0 : return double_type_node;
5350 : :
5351 : 0 : if (mode == TYPE_MODE (long_double_type_node))
5352 : 0 : return long_double_type_node;
5353 : :
5354 : 0 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
5355 : 0 : if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE
5356 : 0 : && mode == TYPE_MODE (FLOATN_NX_TYPE_NODE (i)))
5357 : 0 : return FLOATN_NX_TYPE_NODE (i);
5358 : :
5359 : 0 : if (mode == TYPE_MODE (void_type_node))
5360 : 0 : return void_type_node;
5361 : :
5362 : 0 : if (mode == TYPE_MODE (build_pointer_type (char_type_node))
5363 : 0 : || mode == TYPE_MODE (build_pointer_type (integer_type_node)))
5364 : : {
5365 : 0 : unsigned int precision
5366 : 0 : = GET_MODE_PRECISION (as_a<scalar_int_mode> (mode));
5367 : 0 : return (unsignedp ? make_unsigned_type (precision)
5368 : 0 : : make_signed_type (precision));
5369 : : }
5370 : :
5371 : 0 : if (COMPLEX_MODE_P (mode))
5372 : : {
5373 : 0 : machine_mode inner_mode;
5374 : 0 : tree inner_type;
5375 : :
5376 : 0 : if (mode == TYPE_MODE (complex_float_type_node))
5377 : 0 : return complex_float_type_node;
5378 : 0 : if (mode == TYPE_MODE (complex_double_type_node))
5379 : 0 : return complex_double_type_node;
5380 : 0 : if (mode == TYPE_MODE (complex_long_double_type_node))
5381 : 0 : return complex_long_double_type_node;
5382 : :
5383 : 0 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
5384 : 0 : if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE
5385 : 0 : && mode == TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i)))
5386 : 0 : return COMPLEX_FLOATN_NX_TYPE_NODE (i);
5387 : :
5388 : 0 : if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
5389 : 0 : return complex_integer_type_node;
5390 : :
5391 : 0 : inner_mode = GET_MODE_INNER (mode);
5392 : 0 : inner_type = c_common_type_for_mode (inner_mode, unsignedp);
5393 : 0 : if (inner_type != NULL_TREE)
5394 : 0 : return build_complex_type (inner_type);
5395 : : }
5396 : 0 : else if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL
5397 : 0 : && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
5398 : : {
5399 : 0 : unsigned int elem_bits = vector_element_size (GET_MODE_PRECISION (mode),
5400 : : GET_MODE_NUNITS (mode));
5401 : 0 : tree bool_type = build_nonstandard_boolean_type (elem_bits);
5402 : 0 : return build_vector_type_for_mode (bool_type, mode);
5403 : : }
5404 : 0 : else if (VECTOR_MODE_P (mode)
5405 : 0 : && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
5406 : : {
5407 : 0 : machine_mode inner_mode = GET_MODE_INNER (mode);
5408 : 0 : tree inner_type = c_common_type_for_mode (inner_mode, unsignedp);
5409 : 0 : if (inner_type != NULL_TREE)
5410 : 0 : return build_vector_type_for_mode (inner_type, mode);
5411 : : }
5412 : :
5413 : 0 : if (dfloat32_type_node != NULL_TREE && mode == TYPE_MODE (dfloat32_type_node))
5414 : 0 : return dfloat32_type_node;
5415 : 0 : if (dfloat64_type_node != NULL_TREE && mode == TYPE_MODE (dfloat64_type_node))
5416 : 0 : return dfloat64_type_node;
5417 : 0 : if (dfloat128_type_node != NULL_TREE
5418 : 0 : && mode == TYPE_MODE (dfloat128_type_node))
5419 : 0 : return dfloat128_type_node;
5420 : :
5421 : 0 : if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
5422 : : {
5423 : 0 : if (mode == TYPE_MODE (short_fract_type_node))
5424 : 0 : return unsignedp ? sat_short_fract_type_node : short_fract_type_node;
5425 : 0 : if (mode == TYPE_MODE (fract_type_node))
5426 : 0 : return unsignedp ? sat_fract_type_node : fract_type_node;
5427 : 0 : if (mode == TYPE_MODE (long_fract_type_node))
5428 : 0 : return unsignedp ? sat_long_fract_type_node : long_fract_type_node;
5429 : 0 : if (mode == TYPE_MODE (long_long_fract_type_node))
5430 : 0 : return unsignedp ? sat_long_long_fract_type_node
5431 : 0 : : long_long_fract_type_node;
5432 : :
5433 : 0 : if (mode == TYPE_MODE (unsigned_short_fract_type_node))
5434 : 0 : return unsignedp ? sat_unsigned_short_fract_type_node
5435 : 0 : : unsigned_short_fract_type_node;
5436 : 0 : if (mode == TYPE_MODE (unsigned_fract_type_node))
5437 : 0 : return unsignedp ? sat_unsigned_fract_type_node
5438 : 0 : : unsigned_fract_type_node;
5439 : 0 : if (mode == TYPE_MODE (unsigned_long_fract_type_node))
5440 : 0 : return unsignedp ? sat_unsigned_long_fract_type_node
5441 : 0 : : unsigned_long_fract_type_node;
5442 : 0 : if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
5443 : 0 : return unsignedp ? sat_unsigned_long_long_fract_type_node
5444 : 0 : : unsigned_long_long_fract_type_node;
5445 : :
5446 : 0 : if (mode == TYPE_MODE (short_accum_type_node))
5447 : 0 : return unsignedp ? sat_short_accum_type_node : short_accum_type_node;
5448 : 0 : if (mode == TYPE_MODE (accum_type_node))
5449 : 0 : return unsignedp ? sat_accum_type_node : accum_type_node;
5450 : 0 : if (mode == TYPE_MODE (long_accum_type_node))
5451 : 0 : return unsignedp ? sat_long_accum_type_node : long_accum_type_node;
5452 : 0 : if (mode == TYPE_MODE (long_long_accum_type_node))
5453 : 0 : return unsignedp ? sat_long_long_accum_type_node
5454 : 0 : : long_long_accum_type_node;
5455 : :
5456 : 0 : if (mode == TYPE_MODE (unsigned_short_accum_type_node))
5457 : 0 : return unsignedp ? sat_unsigned_short_accum_type_node
5458 : 0 : : unsigned_short_accum_type_node;
5459 : 0 : if (mode == TYPE_MODE (unsigned_accum_type_node))
5460 : 0 : return unsignedp ? sat_unsigned_accum_type_node
5461 : 0 : : unsigned_accum_type_node;
5462 : 0 : if (mode == TYPE_MODE (unsigned_long_accum_type_node))
5463 : 0 : return unsignedp ? sat_unsigned_long_accum_type_node
5464 : 0 : : unsigned_long_accum_type_node;
5465 : 0 : if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
5466 : 0 : return unsignedp ? sat_unsigned_long_long_accum_type_node
5467 : 0 : : unsigned_long_long_accum_type_node;
5468 : :
5469 : 0 : if (mode == QQmode)
5470 : 0 : return unsignedp ? sat_qq_type_node : qq_type_node;
5471 : : if (mode == HQmode)
5472 : 0 : return unsignedp ? sat_hq_type_node : hq_type_node;
5473 : : if (mode == SQmode)
5474 : 0 : return unsignedp ? sat_sq_type_node : sq_type_node;
5475 : : if (mode == DQmode)
5476 : 0 : return unsignedp ? sat_dq_type_node : dq_type_node;
5477 : : if (mode == TQmode)
5478 : 0 : return unsignedp ? sat_tq_type_node : tq_type_node;
5479 : :
5480 : : if (mode == UQQmode)
5481 : 0 : return unsignedp ? sat_uqq_type_node : uqq_type_node;
5482 : : if (mode == UHQmode)
5483 : 0 : return unsignedp ? sat_uhq_type_node : uhq_type_node;
5484 : : if (mode == USQmode)
5485 : 0 : return unsignedp ? sat_usq_type_node : usq_type_node;
5486 : : if (mode == UDQmode)
5487 : 0 : return unsignedp ? sat_udq_type_node : udq_type_node;
5488 : : if (mode == UTQmode)
5489 : 0 : return unsignedp ? sat_utq_type_node : utq_type_node;
5490 : :
5491 : : if (mode == HAmode)
5492 : 0 : return unsignedp ? sat_ha_type_node : ha_type_node;
5493 : : if (mode == SAmode)
5494 : 0 : return unsignedp ? sat_sa_type_node : sa_type_node;
5495 : : if (mode == DAmode)
5496 : 0 : return unsignedp ? sat_da_type_node : da_type_node;
5497 : : if (mode == TAmode)
5498 : 0 : return unsignedp ? sat_ta_type_node : ta_type_node;
5499 : :
5500 : : if (mode == UHAmode)
5501 : 0 : return unsignedp ? sat_uha_type_node : uha_type_node;
5502 : : if (mode == USAmode)
5503 : 0 : return unsignedp ? sat_usa_type_node : usa_type_node;
5504 : : if (mode == UDAmode)
5505 : 0 : return unsignedp ? sat_uda_type_node : uda_type_node;
5506 : : if (mode == UTAmode)
5507 : 0 : return unsignedp ? sat_uta_type_node : uta_type_node;
5508 : : }
5509 : :
5510 : 0 : for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
5511 : : {
5512 : 0 : tree type = TREE_VALUE (t);
5513 : 0 : if (TYPE_MODE (type) == mode
5514 : 0 : && VECTOR_TYPE_P (type) == VECTOR_MODE_P (mode)
5515 : 0 : && !!unsignedp == !!TYPE_UNSIGNED (type))
5516 : : return type;
5517 : : }
5518 : : return NULL_TREE;
5519 : : }
5520 : :
5521 : : // forked from gcc/cp/semantics.cc finish_underlying_type
5522 : :
5523 : : /* Implement the __underlying_type keyword: Return the underlying
5524 : : type of TYPE, suitable for use as a type-specifier. */
5525 : :
5526 : : tree
5527 : 0 : finish_underlying_type (tree type)
5528 : : {
5529 : 0 : tree underlying_type;
5530 : :
5531 : 0 : if (!complete_type_or_else (type, NULL_TREE))
5532 : 0 : return error_mark_node;
5533 : :
5534 : 0 : if (TREE_CODE (type) != ENUMERAL_TYPE)
5535 : : {
5536 : 0 : error ("%qT is not an enumeration type", type);
5537 : 0 : return error_mark_node;
5538 : : }
5539 : :
5540 : 0 : underlying_type = ENUM_UNDERLYING_TYPE (type);
5541 : :
5542 : : /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
5543 : : includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
5544 : : See finish_enum_value_list for details. */
5545 : 0 : if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
5546 : 0 : underlying_type = c_common_type_for_mode (TYPE_MODE (underlying_type),
5547 : 0 : TYPE_UNSIGNED (underlying_type));
5548 : :
5549 : : return underlying_type;
5550 : : }
5551 : :
5552 : : // forked from gcc/cp/typeck.cc layout_compatible_type_p
5553 : :
5554 : : /* Return true if TYPE1 and TYPE2 are layout-compatible types. */
5555 : :
5556 : : bool
5557 : 0 : layout_compatible_type_p (tree type1, tree type2)
5558 : : {
5559 : 0 : if (type1 == error_mark_node || type2 == error_mark_node)
5560 : : return false;
5561 : 0 : if (type1 == type2)
5562 : : return true;
5563 : 0 : if (TREE_CODE (type1) != TREE_CODE (type2))
5564 : : return false;
5565 : :
5566 : 0 : type1 = rs_build_qualified_type (type1, TYPE_UNQUALIFIED);
5567 : 0 : type2 = rs_build_qualified_type (type2, TYPE_UNQUALIFIED);
5568 : :
5569 : 0 : if (TREE_CODE (type1) == ENUMERAL_TYPE)
5570 : 0 : return (TYPE_ALIGN (type1) == TYPE_ALIGN (type2)
5571 : 0 : && tree_int_cst_equal (TYPE_SIZE (type1), TYPE_SIZE (type2))
5572 : 0 : && same_type_p (finish_underlying_type (type1),
5573 : : finish_underlying_type (type2)));
5574 : :
5575 : 0 : if (CLASS_TYPE_P (type1) && std_layout_type_p (type1)
5576 : 0 : && std_layout_type_p (type2) && TYPE_ALIGN (type1) == TYPE_ALIGN (type2)
5577 : 0 : && tree_int_cst_equal (TYPE_SIZE (type1), TYPE_SIZE (type2)))
5578 : : {
5579 : 0 : tree field1 = TYPE_FIELDS (type1);
5580 : 0 : tree field2 = TYPE_FIELDS (type2);
5581 : 0 : if (TREE_CODE (type1) == RECORD_TYPE)
5582 : : {
5583 : 0 : while (1)
5584 : : {
5585 : 0 : if (!next_common_initial_seqence (field1, field2))
5586 : : return false;
5587 : 0 : if (field1 == NULL_TREE)
5588 : : return true;
5589 : 0 : field1 = DECL_CHAIN (field1);
5590 : 0 : field2 = DECL_CHAIN (field2);
5591 : : }
5592 : : }
5593 : : /* Otherwise both types must be union types.
5594 : : The standard says:
5595 : : "Two standard-layout unions are layout-compatible if they have
5596 : : the same number of non-static data members and corresponding
5597 : : non-static data members (in any order) have layout-compatible
5598 : : types."
5599 : : but the code anticipates that bitfield vs. non-bitfield,
5600 : : different bitfield widths or presence/absence of
5601 : : [[no_unique_address]] should be checked as well. */
5602 : 0 : auto_vec<tree, 16> vec;
5603 : 0 : unsigned int count = 0;
5604 : 0 : for (; field1; field1 = DECL_CHAIN (field1))
5605 : 0 : if (TREE_CODE (field1) == FIELD_DECL)
5606 : 0 : count++;
5607 : 0 : for (; field2; field2 = DECL_CHAIN (field2))
5608 : 0 : if (TREE_CODE (field2) == FIELD_DECL)
5609 : 0 : vec.safe_push (field2);
5610 : : /* Discussions on core lean towards treating multiple union fields
5611 : : of the same type as the same field, so this might need changing
5612 : : in the future. */
5613 : 0 : if (count != vec.length ())
5614 : : return false;
5615 : 0 : for (field1 = TYPE_FIELDS (type1); field1; field1 = DECL_CHAIN (field1))
5616 : : {
5617 : 0 : if (TREE_CODE (field1) != FIELD_DECL)
5618 : 0 : continue;
5619 : 0 : unsigned int j;
5620 : 0 : tree t1 = DECL_BIT_FIELD_TYPE (field1);
5621 : 0 : if (t1 == NULL_TREE)
5622 : 0 : t1 = TREE_TYPE (field1);
5623 : 0 : FOR_EACH_VEC_ELT (vec, j, field2)
5624 : : {
5625 : 0 : tree t2 = DECL_BIT_FIELD_TYPE (field2);
5626 : 0 : if (t2 == NULL_TREE)
5627 : 0 : t2 = TREE_TYPE (field2);
5628 : 0 : if (DECL_BIT_FIELD_TYPE (field1))
5629 : : {
5630 : 0 : if (!DECL_BIT_FIELD_TYPE (field2))
5631 : 0 : continue;
5632 : 0 : if (TYPE_PRECISION (TREE_TYPE (field1))
5633 : 0 : != TYPE_PRECISION (TREE_TYPE (field2)))
5634 : 0 : continue;
5635 : : }
5636 : 0 : else if (DECL_BIT_FIELD_TYPE (field2))
5637 : 0 : continue;
5638 : 0 : if (!layout_compatible_type_p (t1, t2))
5639 : 0 : continue;
5640 : 0 : if ((!lookup_attribute ("no_unique_address",
5641 : 0 : DECL_ATTRIBUTES (field1)))
5642 : 0 : != !lookup_attribute ("no_unique_address",
5643 : 0 : DECL_ATTRIBUTES (field2)))
5644 : 0 : continue;
5645 : : break;
5646 : : }
5647 : 0 : if (j == vec.length ())
5648 : : return false;
5649 : 0 : vec.unordered_remove (j);
5650 : : }
5651 : : return true;
5652 : 0 : }
5653 : :
5654 : 0 : return same_type_p (type1, type2);
5655 : : }
5656 : :
5657 : : // forked from gcc/cp/semnatics.cc is_corresponding_member_union
5658 : :
5659 : : /* Helper function for is_corresponding_member_aggr. Return true if
5660 : : MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
5661 : : union or structure BASETYPE. */
5662 : :
5663 : : static bool
5664 : 0 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
5665 : : {
5666 : 0 : for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
5667 : 0 : if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
5668 : 0 : continue;
5669 : 0 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
5670 : : membertype))
5671 : : {
5672 : 0 : if (TREE_CODE (arg) != INTEGER_CST
5673 : 0 : || tree_int_cst_equal (arg, byte_position (field)))
5674 : 0 : return true;
5675 : : }
5676 : 0 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
5677 : : {
5678 : 0 : tree narg = arg;
5679 : 0 : if (TREE_CODE (basetype) != UNION_TYPE
5680 : 0 : && TREE_CODE (narg) == INTEGER_CST)
5681 : 0 : narg = size_binop (MINUS_EXPR, arg, byte_position (field));
5682 : 0 : if (is_corresponding_member_union (TREE_TYPE (field), membertype, narg))
5683 : : return true;
5684 : : }
5685 : : return false;
5686 : : }
5687 : :
5688 : : // forked from gcc/cp/typeck.cc next_common_initial_seqence
5689 : :
5690 : : /* Helper function for layout_compatible_type_p and
5691 : : is_corresponding_member_aggr. Advance to next members (NULL if
5692 : : no further ones) and return true if those members are still part of
5693 : : the common initial sequence. */
5694 : :
5695 : : bool
5696 : 0 : next_common_initial_seqence (tree &memb1, tree &memb2)
5697 : : {
5698 : 0 : while (memb1)
5699 : : {
5700 : 0 : if (TREE_CODE (memb1) != FIELD_DECL
5701 : 0 : || (DECL_FIELD_IS_BASE (memb1) && is_empty_field (memb1)))
5702 : : {
5703 : 0 : memb1 = DECL_CHAIN (memb1);
5704 : 0 : continue;
5705 : : }
5706 : 0 : if (DECL_FIELD_IS_BASE (memb1))
5707 : : {
5708 : 0 : memb1 = TYPE_FIELDS (TREE_TYPE (memb1));
5709 : 0 : continue;
5710 : : }
5711 : : break;
5712 : : }
5713 : 0 : while (memb2)
5714 : : {
5715 : 0 : if (TREE_CODE (memb2) != FIELD_DECL
5716 : 0 : || (DECL_FIELD_IS_BASE (memb2) && is_empty_field (memb2)))
5717 : : {
5718 : 0 : memb2 = DECL_CHAIN (memb2);
5719 : 0 : continue;
5720 : : }
5721 : 0 : if (DECL_FIELD_IS_BASE (memb2))
5722 : : {
5723 : 0 : memb2 = TYPE_FIELDS (TREE_TYPE (memb2));
5724 : 0 : continue;
5725 : : }
5726 : : break;
5727 : : }
5728 : 0 : if (memb1 == NULL_TREE && memb2 == NULL_TREE)
5729 : : return true;
5730 : 0 : if (memb1 == NULL_TREE || memb2 == NULL_TREE)
5731 : : return false;
5732 : 0 : if (DECL_BIT_FIELD_TYPE (memb1))
5733 : : {
5734 : 0 : if (!DECL_BIT_FIELD_TYPE (memb2))
5735 : : return false;
5736 : 0 : if (!layout_compatible_type_p (DECL_BIT_FIELD_TYPE (memb1),
5737 : 0 : DECL_BIT_FIELD_TYPE (memb2)))
5738 : : return false;
5739 : 0 : if (TYPE_PRECISION (TREE_TYPE (memb1))
5740 : 0 : != TYPE_PRECISION (TREE_TYPE (memb2)))
5741 : : return false;
5742 : : }
5743 : 0 : else if (DECL_BIT_FIELD_TYPE (memb2))
5744 : : return false;
5745 : 0 : else if (!layout_compatible_type_p (TREE_TYPE (memb1), TREE_TYPE (memb2)))
5746 : : return false;
5747 : 0 : if ((!lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb1)))
5748 : 0 : != !lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb2)))
5749 : : return false;
5750 : 0 : if (!tree_int_cst_equal (bit_position (memb1), bit_position (memb2)))
5751 : : return false;
5752 : : return true;
5753 : : }
5754 : :
5755 : : // forked from gcc/cp/semantics.cc is_corresponding_member_aggr
5756 : :
5757 : : /* Helper function for fold_builtin_is_corresponding_member call.
5758 : : Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
5759 : : MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
5760 : : boolean_true_node if they are corresponding members, or for
5761 : : non-constant ARG2 the highest member offset for corresponding
5762 : : members. */
5763 : :
5764 : : static tree
5765 : 0 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
5766 : : tree arg1, tree basetype2, tree membertype2,
5767 : : tree arg2)
5768 : : {
5769 : 0 : tree field1 = TYPE_FIELDS (basetype1);
5770 : 0 : tree field2 = TYPE_FIELDS (basetype2);
5771 : 0 : tree ret = boolean_false_node;
5772 : 0 : while (1)
5773 : : {
5774 : 0 : bool r = next_common_initial_seqence (field1, field2);
5775 : 0 : if (field1 == NULL_TREE || field2 == NULL_TREE)
5776 : : break;
5777 : 0 : if (r
5778 : 0 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
5779 : : membertype1)
5780 : 0 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
5781 : : membertype2))
5782 : : {
5783 : 0 : tree pos = byte_position (field1);
5784 : 0 : if (TREE_CODE (arg1) == INTEGER_CST && tree_int_cst_equal (arg1, pos))
5785 : : {
5786 : 0 : if (TREE_CODE (arg2) == INTEGER_CST)
5787 : 0 : return boolean_true_node;
5788 : : return pos;
5789 : : }
5790 : 0 : else if (TREE_CODE (arg1) != INTEGER_CST)
5791 : 0 : ret = pos;
5792 : : }
5793 : 0 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
5794 : 0 : && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
5795 : : {
5796 : 0 : if ((!lookup_attribute ("no_unique_address",
5797 : 0 : DECL_ATTRIBUTES (field1)))
5798 : 0 : != !lookup_attribute ("no_unique_address",
5799 : 0 : DECL_ATTRIBUTES (field2)))
5800 : : break;
5801 : 0 : if (!tree_int_cst_equal (bit_position (field1),
5802 : 0 : bit_position (field2)))
5803 : : break;
5804 : 0 : bool overlap = true;
5805 : 0 : tree pos = byte_position (field1);
5806 : 0 : if (TREE_CODE (arg1) == INTEGER_CST)
5807 : : {
5808 : 0 : tree off1 = fold_convert (sizetype, arg1);
5809 : 0 : tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
5810 : 0 : if (tree_int_cst_lt (off1, pos)
5811 : 0 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
5812 : : overlap = false;
5813 : : }
5814 : 0 : if (TREE_CODE (arg2) == INTEGER_CST)
5815 : : {
5816 : 0 : tree off2 = fold_convert (sizetype, arg2);
5817 : 0 : tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
5818 : 0 : if (tree_int_cst_lt (off2, pos)
5819 : 0 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
5820 : : overlap = false;
5821 : : }
5822 : 0 : if (overlap && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
5823 : 0 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
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 : tree t1 = TREE_TYPE (field1);
5834 : 0 : tree t2 = TREE_TYPE (field2);
5835 : 0 : tree nret
5836 : 0 : = is_corresponding_member_aggr (loc, t1, membertype1, narg1, t2,
5837 : : membertype2, narg2);
5838 : 0 : if (nret != boolean_false_node)
5839 : : {
5840 : 0 : if (nret == boolean_true_node)
5841 : : return nret;
5842 : 0 : if (TREE_CODE (arg1) == INTEGER_CST)
5843 : 0 : return size_binop (PLUS_EXPR, nret, pos);
5844 : 0 : ret = size_binop (PLUS_EXPR, nret, pos);
5845 : : }
5846 : : }
5847 : 0 : else if (overlap && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
5848 : 0 : && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
5849 : : {
5850 : 0 : tree narg1 = arg1;
5851 : 0 : if (TREE_CODE (arg1) == INTEGER_CST)
5852 : 0 : narg1
5853 : 0 : = size_binop (MINUS_EXPR, fold_convert (sizetype, arg1), pos);
5854 : 0 : tree narg2 = arg2;
5855 : 0 : if (TREE_CODE (arg2) == INTEGER_CST)
5856 : 0 : narg2
5857 : 0 : = size_binop (MINUS_EXPR, fold_convert (sizetype, arg2), pos);
5858 : 0 : if (is_corresponding_member_union (TREE_TYPE (field1),
5859 : : membertype1, narg1)
5860 : 0 : && is_corresponding_member_union (TREE_TYPE (field2),
5861 : : membertype2, narg2))
5862 : : {
5863 : 0 : sorry_at (loc, "%<__builtin_is_corresponding_member%> "
5864 : : "not well defined for anonymous unions");
5865 : 0 : return boolean_false_node;
5866 : : }
5867 : : }
5868 : : }
5869 : 0 : if (!r)
5870 : : break;
5871 : 0 : field1 = DECL_CHAIN (field1);
5872 : 0 : field2 = DECL_CHAIN (field2);
5873 : 0 : }
5874 : : return ret;
5875 : : }
5876 : :
5877 : : // forked from gcc/cp/call.cc null_member_pointer_value_p
5878 : :
5879 : : /* Returns true iff T is a null member pointer value (4.11). */
5880 : :
5881 : : bool
5882 : 0 : null_member_pointer_value_p (tree t)
5883 : : {
5884 : 0 : tree type = TREE_TYPE (t);
5885 : 0 : if (!type)
5886 : : return false;
5887 : 0 : else if (TYPE_PTRMEMFUNC_P (type))
5888 : 0 : return (TREE_CODE (t) == CONSTRUCTOR && CONSTRUCTOR_NELTS (t)
5889 : 0 : && integer_zerop (CONSTRUCTOR_ELT (t, 0)->value));
5890 : 0 : else if (TYPE_PTRDATAMEM_P (type))
5891 : 0 : return integer_all_onesp (t);
5892 : : else
5893 : : return false;
5894 : : }
5895 : :
5896 : : // forked from gcc/cp/semantics.cc fold_builtin_is_corresponding_member
5897 : :
5898 : : /* Fold __builtin_is_corresponding_member call. */
5899 : :
5900 : : tree
5901 : 0 : fold_builtin_is_corresponding_member (location_t loc, int nargs, tree *args)
5902 : : {
5903 : : /* Unless users call the builtin directly, the following 3 checks should be
5904 : : ensured from std::is_corresponding_member function template. */
5905 : 0 : if (nargs != 2)
5906 : : {
5907 : 0 : error_at (loc, "%<__builtin_is_corresponding_member%> "
5908 : : "needs two arguments");
5909 : 0 : return boolean_false_node;
5910 : : }
5911 : 0 : tree arg1 = args[0];
5912 : 0 : tree arg2 = args[1];
5913 : 0 : if (error_operand_p (arg1) || error_operand_p (arg2))
5914 : 0 : return boolean_false_node;
5915 : 0 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg1)) || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
5916 : : {
5917 : 0 : error_at (loc, "%<__builtin_is_corresponding_member%> "
5918 : : "argument is not pointer to member");
5919 : 0 : return boolean_false_node;
5920 : : }
5921 : :
5922 : 0 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
5923 : 0 : || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
5924 : 0 : return boolean_false_node;
5925 : :
5926 : 0 : tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
5927 : 0 : tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
5928 : 0 : if (!complete_type_or_else (basetype1, NULL_TREE))
5929 : 0 : return boolean_false_node;
5930 : :
5931 : 0 : tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
5932 : 0 : tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
5933 : 0 : if (!complete_type_or_else (basetype2, NULL_TREE))
5934 : 0 : return boolean_false_node;
5935 : :
5936 : 0 : if (!NON_UNION_CLASS_TYPE_P (basetype1) || !NON_UNION_CLASS_TYPE_P (basetype2)
5937 : 0 : || !std_layout_type_p (basetype1) || !std_layout_type_p (basetype2))
5938 : 0 : return boolean_false_node;
5939 : :
5940 : : /* If the member types aren't layout compatible, then they
5941 : : can't be corresponding members. */
5942 : 0 : if (!layout_compatible_type_p (membertype1, membertype2))
5943 : 0 : return boolean_false_node;
5944 : :
5945 : 0 : if (null_member_pointer_value_p (arg1) || null_member_pointer_value_p (arg2))
5946 : 0 : return boolean_false_node;
5947 : :
5948 : 0 : if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg2) == INTEGER_CST
5949 : 0 : && !tree_int_cst_equal (arg1, arg2))
5950 : 0 : return boolean_false_node;
5951 : :
5952 : 0 : if (TREE_CODE (arg2) == INTEGER_CST && TREE_CODE (arg1) != INTEGER_CST)
5953 : : {
5954 : : std::swap (arg1, arg2);
5955 : : std::swap (membertype1, membertype2);
5956 : : std::swap (basetype1, basetype2);
5957 : : }
5958 : :
5959 : 0 : tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
5960 : : basetype2, membertype2, arg2);
5961 : 0 : if (TREE_TYPE (ret) == boolean_type_node)
5962 : : return ret;
5963 : : /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
5964 : : already returns boolean_{true,false}_node whether those particular
5965 : : members are corresponding members or not. Otherwise, if only
5966 : : one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
5967 : : above), it returns boolean_false_node if it is certainly not a
5968 : : corresponding member and otherwise we need to do a runtime check that
5969 : : those two OFFSET_TYPE offsets are equal.
5970 : : If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
5971 : : returns the largest offset at which the members would be corresponding
5972 : : members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
5973 : 0 : gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
5974 : 0 : if (TREE_CODE (arg1) == INTEGER_CST)
5975 : 0 : return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
5976 : : fold_convert (TREE_TYPE (arg1), arg2));
5977 : 0 : ret = fold_build2 (LE_EXPR, boolean_type_node,
5978 : : fold_convert (pointer_sized_int_node, arg1),
5979 : : fold_convert (pointer_sized_int_node, ret));
5980 : 0 : return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
5981 : : fold_build2 (EQ_EXPR, boolean_type_node, arg1,
5982 : : fold_convert (TREE_TYPE (arg1), arg2)));
5983 : : }
5984 : :
5985 : : // forked from gcc/cp/tree.cc lvalue_type
5986 : :
5987 : : /* The type of ARG when used as an lvalue. */
5988 : :
5989 : : tree
5990 : 0 : lvalue_type (tree arg)
5991 : : {
5992 : 0 : tree type = TREE_TYPE (arg);
5993 : 0 : return type;
5994 : : }
5995 : :
5996 : : // forked from gcc/c-family/c-warn.cc lvalue_error
5997 : :
5998 : : /* Print an error message for an invalid lvalue. USE says
5999 : : how the lvalue is being used and so selects the error message. LOC
6000 : : is the location for the error. */
6001 : :
6002 : : void
6003 : 0 : lvalue_error (location_t loc, enum lvalue_use use)
6004 : : {
6005 : 0 : switch (use)
6006 : : {
6007 : 0 : case lv_assign:
6008 : 0 : error_at (loc, "lvalue required as left operand of assignment");
6009 : 0 : break;
6010 : 0 : case lv_increment:
6011 : 0 : error_at (loc, "lvalue required as increment operand");
6012 : 0 : break;
6013 : 0 : case lv_decrement:
6014 : 0 : error_at (loc, "lvalue required as decrement operand");
6015 : 0 : break;
6016 : 0 : case lv_addressof:
6017 : 0 : error_at (loc, "lvalue required as unary %<&%> operand");
6018 : 0 : break;
6019 : 0 : case lv_asm:
6020 : 0 : error_at (loc, "lvalue required in %<asm%> statement");
6021 : 0 : break;
6022 : 0 : default:
6023 : 0 : rust_unreachable ();
6024 : : }
6025 : 0 : }
6026 : :
6027 : : // forked from gcc/cp/cp--gimplify.cc cp_fold_maybe_rvalue
6028 : :
6029 : : /* Fold expression X which is used as an rvalue if RVAL is true. */
6030 : :
6031 : : tree
6032 : 0 : cp_fold_maybe_rvalue (tree x, bool rval)
6033 : : {
6034 : 0 : while (true)
6035 : : {
6036 : 0 : x = fold (x);
6037 : 0 : if (rval)
6038 : 0 : x = mark_rvalue_use (x);
6039 : 0 : if (rval && DECL_P (x) && !TYPE_REF_P (TREE_TYPE (x)))
6040 : : {
6041 : 0 : tree v = decl_constant_value (x);
6042 : 0 : if (v != x && v != error_mark_node)
6043 : : {
6044 : 0 : x = v;
6045 : 0 : continue;
6046 : : }
6047 : : }
6048 : 0 : break;
6049 : 0 : }
6050 : 0 : return x;
6051 : : }
6052 : :
6053 : : // forked from gcc/cp/cp--gimplify.cc cp_fold_rvalue
6054 : :
6055 : : /* Fold expression X which is used as an rvalue. */
6056 : :
6057 : : tree
6058 : 0 : cp_fold_rvalue (tree x)
6059 : : {
6060 : 0 : return cp_fold_maybe_rvalue (x, true);
6061 : : }
6062 : :
6063 : : /* Returns true iff class T has a constexpr destructor or has an
6064 : : implicitly declared destructor that we can't tell if it's constexpr
6065 : : without forcing a lazy declaration (which might cause undesired
6066 : : instantiations). */
6067 : :
6068 : : static bool
6069 : 0 : type_maybe_constexpr_destructor (tree t)
6070 : : {
6071 : : /* Until C++20, only trivial destruction is constexpr. */
6072 : 0 : if (TYPE_HAS_TRIVIAL_DESTRUCTOR (t))
6073 : : return true;
6074 : :
6075 : 0 : if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DESTRUCTOR (t))
6076 : : /* Assume it's constexpr. */
6077 : : return true;
6078 : 0 : tree fn = CLASSTYPE_DESTRUCTOR (t);
6079 : 0 : return (fn && Compile::maybe_constexpr_fn (fn));
6080 : : }
6081 : :
6082 : : /* T is a non-literal type used in a context which requires a constant
6083 : : expression. Explain why it isn't literal. */
6084 : :
6085 : : void
6086 : 0 : explain_non_literal_class (tree t)
6087 : : {
6088 : 0 : static hash_set<tree> *diagnosed;
6089 : :
6090 : 0 : if (!CLASS_TYPE_P (t))
6091 : 0 : return;
6092 : 0 : t = TYPE_MAIN_VARIANT (t);
6093 : :
6094 : 0 : if (diagnosed == NULL)
6095 : 0 : diagnosed = new hash_set<tree>;
6096 : 0 : if (diagnosed->add (t))
6097 : : /* Already explained. */
6098 : : return;
6099 : :
6100 : 0 : auto_diagnostic_group d;
6101 : 0 : inform (UNKNOWN_LOCATION, "%q+T is not literal because:", t);
6102 : 0 : if (LAMBDA_TYPE_P (t))
6103 : 0 : inform (UNKNOWN_LOCATION,
6104 : : " %qT is a closure type, which is only literal in "
6105 : : "C++17 and later",
6106 : : t);
6107 : 0 : else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
6108 : 0 : && !type_maybe_constexpr_destructor (t))
6109 : 0 : inform (UNKNOWN_LOCATION, " %q+T does not have %<constexpr%> destructor",
6110 : : t);
6111 : 0 : else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
6112 : 0 : inform (UNKNOWN_LOCATION, " %q+T has a non-trivial destructor", t);
6113 : 0 : else if (CLASSTYPE_NON_AGGREGATE (t) && !TYPE_HAS_TRIVIAL_DFLT (t)
6114 : 0 : && !LAMBDA_TYPE_P (t) && !TYPE_HAS_CONSTEXPR_CTOR (t))
6115 : : {
6116 : 0 : inform (UNKNOWN_LOCATION,
6117 : : " %q+T is not an aggregate, does not have a trivial "
6118 : : "default constructor, and has no %<constexpr%> constructor that "
6119 : : "is not a copy or move constructor",
6120 : : t);
6121 : 0 : if (type_has_non_user_provided_default_constructor (t))
6122 : : /* Note that we can't simply call locate_ctor because when the
6123 : : constructor is deleted it just returns NULL_TREE. */
6124 : 0 : for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
6125 : : {
6126 : 0 : tree fn = *iter;
6127 : 0 : tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
6128 : :
6129 : 0 : parms = skip_artificial_parms_for (fn, parms);
6130 : :
6131 : 0 : if (sufficient_parms_p (parms))
6132 : : {
6133 : 0 : Compile::explain_invalid_constexpr_fn (fn);
6134 : 0 : break;
6135 : : }
6136 : : }
6137 : : }
6138 : : else
6139 : : {
6140 : 0 : tree binfo, base_binfo, field;
6141 : 0 : int i;
6142 : 0 : for (binfo = TYPE_BINFO (t), i = 0;
6143 : 0 : BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
6144 : : {
6145 : 0 : tree basetype = TREE_TYPE (base_binfo);
6146 : 0 : if (!CLASSTYPE_LITERAL_P (basetype))
6147 : : {
6148 : 0 : inform (UNKNOWN_LOCATION,
6149 : : " base class %qT of %q+T is non-literal", basetype, t);
6150 : 0 : explain_non_literal_class (basetype);
6151 : 0 : return;
6152 : : }
6153 : : }
6154 : 0 : for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
6155 : : {
6156 : 0 : tree ftype;
6157 : 0 : if (TREE_CODE (field) != FIELD_DECL)
6158 : 0 : continue;
6159 : 0 : ftype = TREE_TYPE (field);
6160 : 0 : if (!Compile::literal_type_p (ftype))
6161 : : {
6162 : 0 : inform (DECL_SOURCE_LOCATION (field),
6163 : : " non-static data member %qD has non-literal type",
6164 : : field);
6165 : 0 : if (CLASS_TYPE_P (ftype))
6166 : 0 : explain_non_literal_class (ftype);
6167 : : }
6168 : 0 : if (RS_TYPE_VOLATILE_P (ftype))
6169 : 0 : inform (DECL_SOURCE_LOCATION (field),
6170 : : " non-static data member %qD has volatile type", field);
6171 : : }
6172 : : }
6173 : 0 : }
6174 : :
6175 : : // forked from gcc/cp/call.cc reference_related_p
6176 : :
6177 : : /* Returns nonzero if T1 is reference-related to T2. */
6178 : :
6179 : : bool
6180 : 0 : reference_related_p (tree t1, tree t2)
6181 : : {
6182 : 0 : if (t1 == error_mark_node || t2 == error_mark_node)
6183 : : return false;
6184 : :
6185 : 0 : t1 = TYPE_MAIN_VARIANT (t1);
6186 : 0 : t2 = TYPE_MAIN_VARIANT (t2);
6187 : :
6188 : : /* [dcl.init.ref]
6189 : :
6190 : : Given types "cv1 T1" and "cv2 T2," "cv1 T1" is reference-related
6191 : : to "cv2 T2" if T1 is similar to T2, or T1 is a base class of T2. */
6192 : 0 : return (similar_type_p (t1, t2)
6193 : : /*|| (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
6194 : 0 : && DERIVED_FROM_P (t1, t2))*/);
6195 : : }
6196 : :
6197 : : // forked from gcc/cp/typeck2.cc ordinary_char_type_p
6198 : :
6199 : : /* True iff TYPE is a C++20 "ordinary" character type. */
6200 : :
6201 : : bool
6202 : 0 : ordinary_char_type_p (tree type)
6203 : : {
6204 : 0 : type = TYPE_MAIN_VARIANT (type);
6205 : 0 : return (type == char_type_node || type == signed_char_type_node
6206 : 0 : || type == unsigned_char_type_node);
6207 : : }
6208 : :
6209 : : // forked from gcc/cp/typeck2.cc array_string_literal_compatible_p
6210 : :
6211 : : /* True iff the string literal INIT has a type suitable for initializing array
6212 : : TYPE. */
6213 : :
6214 : : bool
6215 : 0 : array_string_literal_compatible_p (tree type, tree init)
6216 : : {
6217 : 0 : tree to_char_type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
6218 : 0 : tree from_char_type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (init)));
6219 : :
6220 : 0 : if (to_char_type == from_char_type)
6221 : : return true;
6222 : : /* The array element type does not match the initializing string
6223 : : literal element type; this is only allowed when both types are
6224 : : ordinary character type. There are no string literals of
6225 : : signed or unsigned char type in the language, but we can get
6226 : : them internally from converting braced-init-lists to
6227 : : STRING_CST. */
6228 : 0 : if (ordinary_char_type_p (to_char_type)
6229 : 0 : && ordinary_char_type_p (from_char_type))
6230 : : return true;
6231 : : return false;
6232 : : }
6233 : :
6234 : : } // namespace Rust
6235 : :
6236 : : using namespace Rust;
6237 : :
6238 : : #include "gt-rust-rust-tree.h"
|