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