Line data Source code
1 : /* Language-independent node constructors for parse phase of GNU compiler.
2 : Copyright (C) 1987-2026 Free Software Foundation, Inc.
3 :
4 : This file is part of GCC.
5 :
6 : GCC is free software; you can redistribute it and/or modify it under
7 : the terms of the GNU General Public License as published by the Free
8 : Software Foundation; either version 3, or (at your option) any later
9 : version.
10 :
11 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : for more details.
15 :
16 : You should have received a copy of the GNU General Public License
17 : along with GCC; see the file COPYING3. If not see
18 : <http://www.gnu.org/licenses/>. */
19 :
20 : /* This file contains the low level primitives for operating on tree nodes,
21 : including allocation, list operations, interning of identifiers,
22 : construction of data type nodes and statement nodes,
23 : and construction of type conversion nodes. It also contains
24 : tables index by tree code that describe how to take apart
25 : nodes of that code.
26 :
27 : It is intended to be language-independent but can occasionally
28 : calls language-dependent routines. */
29 :
30 : #include "config.h"
31 : #include "system.h"
32 : #include "coretypes.h"
33 : #include "backend.h"
34 : #include "target.h"
35 : #include "memmodel.h"
36 : #include "tm_p.h"
37 : #include "tree.h"
38 : #include "gimple.h"
39 : #include "tree-pass.h"
40 : #include "ssa.h"
41 : #include "cgraph.h"
42 : #include "diagnostic.h"
43 : #include "flags.h"
44 : #include "alias.h"
45 : #include "fold-const.h"
46 : #include "stor-layout.h"
47 : #include "calls.h"
48 : #include "attribs.h"
49 : #include "toplev.h" /* get_random_seed */
50 : #include "output.h"
51 : #include "common/common-target.h"
52 : #include "langhooks.h"
53 : #include "tree-inline.h"
54 : #include "tree-iterator.h"
55 : #include "internal-fn.h"
56 : #include "gimple-iterator.h"
57 : #include "gimplify.h"
58 : #include "tree-dfa.h"
59 : #include "langhooks-def.h"
60 : #include "tree-diagnostic.h"
61 : #include "except.h"
62 : #include "builtins.h"
63 : #include "print-tree.h"
64 : #include "ipa-utils.h"
65 : #include "selftest.h"
66 : #include "stringpool.h"
67 : #include "attribs.h"
68 : #include "rtl.h"
69 : #include "regs.h"
70 : #include "tree-vector-builder.h"
71 : #include "gimple-fold.h"
72 : #include "escaped_string.h"
73 : #include "gimple-range.h"
74 : #include "gomp-constants.h"
75 : #include "dfp.h"
76 : #include "asan.h"
77 : #include "ubsan.h"
78 : #include "attr-callback.h"
79 :
80 : /* Names of tree components.
81 : Used for printing out the tree and error messages. */
82 : #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
83 : #define END_OF_BASE_TREE_CODES "@dummy",
84 :
85 : static const char *const tree_code_name[] = {
86 : #include "all-tree.def"
87 : };
88 :
89 : #undef DEFTREECODE
90 : #undef END_OF_BASE_TREE_CODES
91 :
92 : /* Each tree code class has an associated string representation.
93 : These must correspond to the tree_code_class entries. */
94 :
95 : const char *const tree_code_class_strings[] =
96 : {
97 : "exceptional",
98 : "constant",
99 : "type",
100 : "declaration",
101 : "reference",
102 : "comparison",
103 : "unary",
104 : "binary",
105 : "statement",
106 : "vl_exp",
107 : "expression"
108 : };
109 :
110 : /* obstack.[ch] explicitly declined to prototype this. */
111 : extern int _obstack_allocated_p (struct obstack *h, void *obj);
112 :
113 : /* Statistics-gathering stuff. */
114 :
115 : static uint64_t tree_code_counts[MAX_TREE_CODES];
116 : uint64_t tree_node_counts[(int) all_kinds];
117 : uint64_t tree_node_sizes[(int) all_kinds];
118 :
119 : /* Keep in sync with tree.h:enum tree_node_kind. */
120 : static const char * const tree_node_kind_names[] = {
121 : "decls",
122 : "types",
123 : "blocks",
124 : "stmts",
125 : "refs",
126 : "exprs",
127 : "constants",
128 : "identifiers",
129 : "vecs",
130 : "binfos",
131 : "ssa names",
132 : "constructors",
133 : "random kinds",
134 : "lang_decl kinds",
135 : "lang_type kinds",
136 : "omp clauses",
137 : };
138 :
139 : /* Unique id for next decl created. */
140 : static GTY(()) int next_decl_uid;
141 : /* Unique id for next type created. */
142 : static GTY(()) unsigned next_type_uid = 1;
143 : /* Unique id for next debug decl created. Use negative numbers,
144 : to catch erroneous uses. */
145 : static GTY(()) int next_debug_decl_uid;
146 :
147 : /* Since we cannot rehash a type after it is in the table, we have to
148 : keep the hash code. */
149 :
150 : struct GTY((for_user)) type_hash {
151 : unsigned long hash;
152 : tree type;
153 : };
154 :
155 : /* Initial size of the hash table (rounded to next prime). */
156 : #define TYPE_HASH_INITIAL_SIZE 1000
157 :
158 : struct type_cache_hasher : ggc_cache_ptr_hash<type_hash>
159 : {
160 8519919989 : static hashval_t hash (type_hash *t) { return t->hash; }
161 : static bool equal (type_hash *a, type_hash *b);
162 :
163 : static int
164 2032668617 : keep_cache_entry (type_hash *&t)
165 : {
166 2032668617 : return ggc_marked_p (t->type);
167 : }
168 : };
169 :
170 : /* Now here is the hash table. When recording a type, it is added to
171 : the slot whose index is the hash code. Note that the hash table is
172 : used for several kinds of types (function types, array types and
173 : array index range types, for now). While all these live in the
174 : same table, they are completely independent, and the hash code is
175 : computed differently for each of these. */
176 :
177 : static GTY ((cache)) hash_table<type_cache_hasher> *type_hash_table;
178 :
179 : /* Hash table and temporary node for larger integer const values. */
180 : static GTY (()) tree int_cst_node;
181 :
182 : struct int_cst_hasher : ggc_cache_ptr_hash<tree_node>
183 : {
184 : static hashval_t hash (tree t);
185 : static bool equal (tree x, tree y);
186 : };
187 :
188 : static GTY ((cache)) hash_table<int_cst_hasher> *int_cst_hash_table;
189 :
190 : /* Class and variable for making sure that there is a single POLY_INT_CST
191 : for a given value. */
192 : struct poly_int_cst_hasher : ggc_cache_ptr_hash<tree_node>
193 : {
194 : typedef std::pair<tree, const poly_wide_int *> compare_type;
195 : static hashval_t hash (tree t);
196 : static bool equal (tree x, const compare_type &y);
197 : };
198 :
199 : static GTY ((cache)) hash_table<poly_int_cst_hasher> *poly_int_cst_hash_table;
200 :
201 : /* Hash table for optimization flags and target option flags. Use the same
202 : hash table for both sets of options. Nodes for building the current
203 : optimization and target option nodes. The assumption is most of the time
204 : the options created will already be in the hash table, so we avoid
205 : allocating and freeing up a node repeatably. */
206 : static GTY (()) tree cl_optimization_node;
207 : static GTY (()) tree cl_target_option_node;
208 :
209 : struct cl_option_hasher : ggc_cache_ptr_hash<tree_node>
210 : {
211 : static hashval_t hash (tree t);
212 : static bool equal (tree x, tree y);
213 : };
214 :
215 : static GTY ((cache)) hash_table<cl_option_hasher> *cl_option_hash_table;
216 :
217 870738 : struct gt_value_expr_mark_data {
218 : hash_set<tree> pset;
219 : auto_vec<tree, 16> to_mark;
220 : };
221 :
222 : /* Callback called through walk_tree_1 to discover DECL_HAS_VALUE_EXPR_P
223 : VAR_DECLs which weren't marked yet, in that case marks them and
224 : walks their DECL_VALUE_EXPR expressions. */
225 :
226 : static tree
227 22447052 : gt_value_expr_mark_2 (tree *tp, int *, void *data)
228 : {
229 22447052 : tree t = *tp;
230 22447052 : if (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t) && !ggc_marked_p (t))
231 : {
232 1095 : tree dve = DECL_VALUE_EXPR (t);
233 1095 : gt_value_expr_mark_data *d = (gt_value_expr_mark_data *) data;
234 1095 : walk_tree_1 (&dve, gt_value_expr_mark_2, data, &d->pset, NULL);
235 1095 : d->to_mark.safe_push (t);
236 : }
237 22447052 : return NULL_TREE;
238 : }
239 :
240 : /* Callback called through traverse_noresize on the
241 : value_expr_for_decl hash table. */
242 :
243 : int
244 9617947 : gt_value_expr_mark_1 (tree_decl_map **e, gt_value_expr_mark_data *data)
245 : {
246 9617947 : if (ggc_marked_p ((*e)->base.from))
247 8411261 : walk_tree_1 (&(*e)->to, gt_value_expr_mark_2, data, &data->pset, NULL);
248 9617947 : return 1;
249 : }
250 :
251 : /* The value_expr_for_decl hash table can have mappings for trees
252 : which are only referenced from mappings of other trees in the
253 : same table, see PR118790. Without this routine, gt_cleare_cache
254 : could clear hash table slot of a tree which isn't marked but
255 : will be marked when processing later hash table slot of another
256 : tree which is marked. This function marks with the above
257 : helpers marks all the not yet marked DECL_HAS_VALUE_EXPR_P
258 : VAR_DECLs mentioned in DECL_VALUE_EXPR expressions of marked
259 : trees and in that case also recurses on their DECL_VALUE_EXPR. */
260 :
261 : void
262 870738 : gt_value_expr_mark (hash_table<tree_decl_map_cache_hasher> *h)
263 : {
264 870738 : if (!h)
265 0 : return;
266 :
267 870738 : gt_value_expr_mark_data data;
268 870738 : h->traverse_noresize<gt_value_expr_mark_data *,
269 10488685 : gt_value_expr_mark_1> (&data);
270 2613309 : for (auto v : data.to_mark)
271 1095 : gt_ggc_mx (v);
272 870738 : }
273 :
274 : /* General tree->tree mapping structure for use in hash tables. */
275 :
276 :
277 : static GTY ((cache))
278 : hash_table<tree_decl_map_cache_hasher> *debug_expr_for_decl;
279 :
280 : static GTY ((cache ("gt_value_expr_mark")))
281 : hash_table<tree_decl_map_cache_hasher> *value_expr_for_decl;
282 :
283 : static GTY ((cache))
284 : hash_table<tree_vec_map_cache_hasher> *debug_args_for_decl;
285 :
286 : static void set_type_quals (tree, int);
287 : static void print_type_hash_statistics (void);
288 : static void print_debug_expr_statistics (void);
289 : static void print_value_expr_statistics (void);
290 :
291 : tree global_trees[TI_MAX];
292 : tree integer_types[itk_none];
293 :
294 : bool int_n_enabled_p[NUM_INT_N_ENTS];
295 : struct int_n_trees_t int_n_trees [NUM_INT_N_ENTS];
296 :
297 : bool tree_contains_struct[MAX_TREE_CODES][64];
298 :
299 : /* Number of operands for each OMP clause. */
300 : unsigned const char omp_clause_num_ops[] =
301 : {
302 : 0, /* OMP_CLAUSE_ERROR */
303 : 1, /* OMP_CLAUSE_PRIVATE */
304 : 1, /* OMP_CLAUSE_SHARED */
305 : 1, /* OMP_CLAUSE_FIRSTPRIVATE */
306 : 2, /* OMP_CLAUSE_LASTPRIVATE */
307 : 5, /* OMP_CLAUSE_REDUCTION */
308 : 5, /* OMP_CLAUSE_TASK_REDUCTION */
309 : 5, /* OMP_CLAUSE_IN_REDUCTION */
310 : 1, /* OMP_CLAUSE_COPYIN */
311 : 1, /* OMP_CLAUSE_COPYPRIVATE */
312 : 3, /* OMP_CLAUSE_LINEAR */
313 : 1, /* OMP_CLAUSE_AFFINITY */
314 : 2, /* OMP_CLAUSE_ALIGNED */
315 : 3, /* OMP_CLAUSE_ALLOCATE */
316 : 1, /* OMP_CLAUSE_DEPEND */
317 : 1, /* OMP_CLAUSE_NONTEMPORAL */
318 : 1, /* OMP_CLAUSE_UNIFORM */
319 : 1, /* OMP_CLAUSE_ENTER */
320 : 1, /* OMP_CLAUSE_LINK */
321 : 1, /* OMP_CLAUSE_DETACH */
322 : 1, /* OMP_CLAUSE_USE_DEVICE_PTR */
323 : 1, /* OMP_CLAUSE_USE_DEVICE_ADDR */
324 : 1, /* OMP_CLAUSE_IS_DEVICE_PTR */
325 : 1, /* OMP_CLAUSE_INCLUSIVE */
326 : 1, /* OMP_CLAUSE_EXCLUSIVE */
327 : 3, /* OMP_CLAUSE_FROM */
328 : 3, /* OMP_CLAUSE_TO */
329 : 3, /* OMP_CLAUSE_MAP (update walk_tree_1 if this is changed) */
330 : 1, /* OMP_CLAUSE_HAS_DEVICE_ADDR */
331 : 1, /* OMP_CLAUSE_DOACROSS */
332 : 3, /* OMP_CLAUSE__MAPPER_BINDING_ */
333 : 2, /* OMP_CLAUSE__CACHE_ */
334 : 1, /* OMP_CLAUSE_DESTROY */
335 : 2, /* OMP_CLAUSE_INIT */
336 : 1, /* OMP_CLAUSE_USE */
337 : 1, /* OMP_CLAUSE_INTEROP */
338 : 2, /* OMP_CLAUSE_GANG */
339 : 1, /* OMP_CLAUSE_ASYNC */
340 : 1, /* OMP_CLAUSE_WAIT */
341 : 0, /* OMP_CLAUSE_AUTO */
342 : 0, /* OMP_CLAUSE_SEQ */
343 : 1, /* OMP_CLAUSE__LOOPTEMP_ */
344 : 1, /* OMP_CLAUSE__REDUCTEMP_ */
345 : 1, /* OMP_CLAUSE__CONDTEMP_ */
346 : 1, /* OMP_CLAUSE__SCANTEMP_ */
347 : 1, /* OMP_CLAUSE_IF */
348 : 1, /* OMP_CLAUSE_SELF */
349 : 1, /* OMP_CLAUSE_NUM_THREADS */
350 : 1, /* OMP_CLAUSE_SCHEDULE */
351 : 0, /* OMP_CLAUSE_NOWAIT */
352 : 1, /* OMP_CLAUSE_ORDERED */
353 : 0, /* OMP_CLAUSE_DEFAULT */
354 : 3, /* OMP_CLAUSE_COLLAPSE */
355 : 0, /* OMP_CLAUSE_UNTIED */
356 : 1, /* OMP_CLAUSE_FINAL */
357 : 0, /* OMP_CLAUSE_MERGEABLE */
358 : 1, /* OMP_CLAUSE_DEVICE */
359 : 1, /* OMP_CLAUSE_DIST_SCHEDULE */
360 : 0, /* OMP_CLAUSE_INBRANCH */
361 : 0, /* OMP_CLAUSE_NOTINBRANCH */
362 : 2, /* OMP_CLAUSE_NUM_TEAMS */
363 : 1, /* OMP_CLAUSE_THREAD_LIMIT */
364 : 0, /* OMP_CLAUSE_PROC_BIND */
365 : 1, /* OMP_CLAUSE_SAFELEN */
366 : 1, /* OMP_CLAUSE_SIMDLEN */
367 : 0, /* OMP_CLAUSE_DEVICE_TYPE */
368 : 0, /* OMP_CLAUSE_FOR */
369 : 0, /* OMP_CLAUSE_PARALLEL */
370 : 0, /* OMP_CLAUSE_SECTIONS */
371 : 0, /* OMP_CLAUSE_TASKGROUP */
372 : 1, /* OMP_CLAUSE_PRIORITY */
373 : 1, /* OMP_CLAUSE_GRAINSIZE */
374 : 1, /* OMP_CLAUSE_NUM_TASKS */
375 : 0, /* OMP_CLAUSE_NOGROUP */
376 : 0, /* OMP_CLAUSE_THREADS */
377 : 0, /* OMP_CLAUSE_SIMD */
378 : 1, /* OMP_CLAUSE_HINT */
379 : 0, /* OMP_CLAUSE_DEFAULTMAP */
380 : 0, /* OMP_CLAUSE_ORDER */
381 : 0, /* OMP_CLAUSE_BIND */
382 : 1, /* OMP_CLAUSE_FILTER */
383 : 1, /* OMP_CLAUSE_INDIRECT */
384 : 1, /* OMP_CLAUSE_PARTIAL */
385 : 0, /* OMP_CLAUSE_FULL */
386 : 1, /* OMP_CLAUSE_SIZES */
387 : 1, /* OMP_CLAUSE__SIMDUID_ */
388 : 0, /* OMP_CLAUSE__SIMT_ */
389 : 0, /* OMP_CLAUSE_INDEPENDENT */
390 : 1, /* OMP_CLAUSE_WORKER */
391 : 1, /* OMP_CLAUSE_VECTOR */
392 : 1, /* OMP_CLAUSE_NUM_GANGS */
393 : 1, /* OMP_CLAUSE_NUM_WORKERS */
394 : 1, /* OMP_CLAUSE_VECTOR_LENGTH */
395 : 3, /* OMP_CLAUSE_TILE */
396 : 0, /* OMP_CLAUSE_IF_PRESENT */
397 : 0, /* OMP_CLAUSE_FINALIZE */
398 : 0, /* OMP_CLAUSE_NOHOST */
399 : 1, /* OMP_CLAUSE_NOVARIANTS */
400 : 1, /* OMP_CLAUSE_NOCONTEXT */
401 : 1, /* OMP_CLAUSE_DYN_GROUPPRIVATE */
402 : 3, /* OMP_CLAUSE_USES_ALLOCATORS */
403 : };
404 :
405 : const char * const omp_clause_code_name[] =
406 : {
407 : "error_clause",
408 : "private",
409 : "shared",
410 : "firstprivate",
411 : "lastprivate",
412 : "reduction",
413 : "task_reduction",
414 : "in_reduction",
415 : "copyin",
416 : "copyprivate",
417 : "linear",
418 : "affinity",
419 : "aligned",
420 : "allocate",
421 : "depend",
422 : "nontemporal",
423 : "uniform",
424 : "enter",
425 : "link",
426 : "detach",
427 : "use_device_ptr",
428 : "use_device_addr",
429 : "is_device_ptr",
430 : "inclusive",
431 : "exclusive",
432 : "from",
433 : "to",
434 : "map",
435 : "has_device_addr",
436 : "doacross",
437 : "_mapper_binding_",
438 : "_cache_",
439 : "destroy",
440 : "init",
441 : "use",
442 : "interop",
443 : "gang",
444 : "async",
445 : "wait",
446 : "auto",
447 : "seq",
448 : "_looptemp_",
449 : "_reductemp_",
450 : "_condtemp_",
451 : "_scantemp_",
452 : "if",
453 : "self",
454 : "num_threads",
455 : "schedule",
456 : "nowait",
457 : "ordered",
458 : "default",
459 : "collapse",
460 : "untied",
461 : "final",
462 : "mergeable",
463 : "device",
464 : "dist_schedule",
465 : "inbranch",
466 : "notinbranch",
467 : "num_teams",
468 : "thread_limit",
469 : "proc_bind",
470 : "safelen",
471 : "simdlen",
472 : "device_type",
473 : "for",
474 : "parallel",
475 : "sections",
476 : "taskgroup",
477 : "priority",
478 : "grainsize",
479 : "num_tasks",
480 : "nogroup",
481 : "threads",
482 : "simd",
483 : "hint",
484 : "defaultmap",
485 : "order",
486 : "bind",
487 : "filter",
488 : "indirect",
489 : "partial",
490 : "full",
491 : "sizes",
492 : "_simduid_",
493 : "_simt_",
494 : "independent",
495 : "worker",
496 : "vector",
497 : "num_gangs",
498 : "num_workers",
499 : "vector_length",
500 : "tile",
501 : "if_present",
502 : "finalize",
503 : "nohost",
504 : "novariants",
505 : "nocontext",
506 : "dyn_groupprivate",
507 : "uses_allocators",
508 : };
509 :
510 : /* Unless specific to OpenACC, we tend to internally maintain OpenMP-centric
511 : clause names, but for use in diagnostics etc. would like to use the "user"
512 : clause names. */
513 :
514 : const char *
515 445 : user_omp_clause_code_name (tree clause, bool oacc)
516 : {
517 : /* For OpenACC, the 'OMP_CLAUSE_MAP_KIND' of an 'OMP_CLAUSE_MAP' is used to
518 : distinguish clauses as seen by the user. See also where front ends do
519 : 'build_omp_clause' with 'OMP_CLAUSE_MAP'. */
520 890 : if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP)
521 445 : switch (OMP_CLAUSE_MAP_KIND (clause))
522 : {
523 : case GOMP_MAP_FORCE_ALLOC:
524 : case GOMP_MAP_ALLOC: return "create";
525 0 : case GOMP_MAP_FORCE_TO:
526 0 : case GOMP_MAP_TO: return "copyin";
527 0 : case GOMP_MAP_FORCE_FROM:
528 0 : case GOMP_MAP_FROM: return "copyout";
529 361 : case GOMP_MAP_FORCE_TOFROM:
530 361 : case GOMP_MAP_TOFROM: return "copy";
531 0 : case GOMP_MAP_RELEASE: return "delete";
532 0 : case GOMP_MAP_FORCE_PRESENT: return "present";
533 42 : case GOMP_MAP_ATTACH: return "attach";
534 42 : case GOMP_MAP_FORCE_DETACH:
535 42 : case GOMP_MAP_DETACH: return "detach";
536 0 : case GOMP_MAP_DEVICE_RESIDENT: return "device_resident";
537 0 : case GOMP_MAP_LINK: return "link";
538 0 : case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr";
539 : default: break;
540 : }
541 :
542 0 : return omp_clause_code_name[OMP_CLAUSE_CODE (clause)];
543 : }
544 :
545 :
546 : /* Return the tree node structure used by tree code CODE. */
547 :
548 : static inline enum tree_node_structure_enum
549 44222361020 : tree_node_structure_for_code (enum tree_code code)
550 : {
551 44222361020 : switch (TREE_CODE_CLASS (code))
552 : {
553 10915320682 : case tcc_declaration:
554 10915320682 : switch (code)
555 : {
556 : case CONST_DECL: return TS_CONST_DECL;
557 : case DEBUG_EXPR_DECL: return TS_DECL_WRTL;
558 : case FIELD_DECL: return TS_FIELD_DECL;
559 : case FUNCTION_DECL: return TS_FUNCTION_DECL;
560 : case LABEL_DECL: return TS_LABEL_DECL;
561 : case PARM_DECL: return TS_PARM_DECL;
562 : case RESULT_DECL: return TS_RESULT_DECL;
563 : case TRANSLATION_UNIT_DECL: return TS_TRANSLATION_UNIT_DECL;
564 : case TYPE_DECL: return TS_TYPE_DECL;
565 : case VAR_DECL: return TS_VAR_DECL;
566 : default: return TS_DECL_NON_COMMON;
567 : }
568 :
569 : case tcc_type: return TS_TYPE_NON_COMMON;
570 :
571 11533865073 : case tcc_binary:
572 11533865073 : case tcc_comparison:
573 11533865073 : case tcc_expression:
574 11533865073 : case tcc_reference:
575 11533865073 : case tcc_statement:
576 11533865073 : case tcc_unary:
577 11533865073 : case tcc_vl_exp: return TS_EXP;
578 :
579 15765374826 : default: /* tcc_constant and tcc_exceptional */
580 15765374826 : break;
581 : }
582 :
583 15765374826 : switch (code)
584 : {
585 : /* tcc_constant cases. */
586 : case COMPLEX_CST: return TS_COMPLEX;
587 292371 : case FIXED_CST: return TS_FIXED_CST;
588 770956173 : case INTEGER_CST: return TS_INT_CST;
589 292371 : case POLY_INT_CST: return TS_POLY_INT_CST;
590 49571271 : case REAL_CST: return TS_REAL_CST;
591 260250879 : case STRING_CST: return TS_STRING;
592 13803179 : case VECTOR_CST: return TS_VECTOR;
593 1163963 : case VOID_CST: return TS_TYPED;
594 292629 : case RAW_DATA_CST: return TS_RAW_DATA_CST;
595 :
596 : /* tcc_exceptional cases. */
597 729054496 : case BLOCK: return TS_BLOCK;
598 141706139 : case CONSTRUCTOR: return TS_CONSTRUCTOR;
599 : case ERROR_MARK: return TS_COMMON;
600 8831231 : case IDENTIFIER_NODE: return TS_IDENTIFIER;
601 857667 : case OMP_CLAUSE: return TS_OMP_CLAUSE;
602 2047950 : case OPTIMIZATION_NODE: return TS_OPTIMIZATION;
603 : case PLACEHOLDER_EXPR: return TS_COMMON;
604 333739830 : case SSA_NAME: return TS_SSA_NAME;
605 802567576 : case STATEMENT_LIST: return TS_STATEMENT_LIST;
606 3984609 : case TARGET_OPTION_NODE: return TS_TARGET_OPTION;
607 272915416 : case TREE_BINFO: return TS_BINFO;
608 10172162514 : case TREE_LIST: return TS_LIST;
609 2198929070 : case TREE_VEC: return TS_VEC;
610 :
611 0 : default:
612 0 : gcc_unreachable ();
613 : }
614 : }
615 :
616 :
617 : /* Initialize tree_contains_struct to describe the hierarchy of tree
618 : nodes. */
619 :
620 : static void
621 292371 : initialize_tree_contains_struct (void)
622 : {
623 292371 : unsigned i;
624 :
625 71923266 : for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++)
626 : {
627 71630895 : enum tree_code code;
628 71630895 : enum tree_node_structure_enum ts_code;
629 :
630 71630895 : code = (enum tree_code) i;
631 71630895 : ts_code = tree_node_structure_for_code (code);
632 :
633 : /* Mark the TS structure itself. */
634 71630895 : tree_contains_struct[code][ts_code] = 1;
635 :
636 : /* Mark all the structures that TS is derived from. */
637 71630895 : switch (ts_code)
638 : {
639 1169484 : case TS_TYPED:
640 1169484 : case TS_BLOCK:
641 1169484 : case TS_OPTIMIZATION:
642 1169484 : case TS_TARGET_OPTION:
643 1169484 : MARK_TS_BASE (code);
644 1169484 : break;
645 :
646 59058942 : case TS_COMMON:
647 59058942 : case TS_INT_CST:
648 59058942 : case TS_POLY_INT_CST:
649 59058942 : case TS_REAL_CST:
650 59058942 : case TS_FIXED_CST:
651 59058942 : case TS_VECTOR:
652 59058942 : case TS_STRING:
653 59058942 : case TS_RAW_DATA_CST:
654 59058942 : case TS_COMPLEX:
655 59058942 : case TS_SSA_NAME:
656 59058942 : case TS_CONSTRUCTOR:
657 59058942 : case TS_EXP:
658 59058942 : case TS_STATEMENT_LIST:
659 59058942 : MARK_TS_TYPED (code);
660 59058942 : break;
661 :
662 1461855 : case TS_IDENTIFIER:
663 1461855 : case TS_DECL_MINIMAL:
664 1461855 : case TS_TYPE_COMMON:
665 1461855 : case TS_LIST:
666 1461855 : case TS_VEC:
667 1461855 : case TS_BINFO:
668 1461855 : case TS_OMP_CLAUSE:
669 1461855 : MARK_TS_COMMON (code);
670 1461855 : break;
671 :
672 0 : case TS_TYPE_WITH_LANG_SPECIFIC:
673 0 : MARK_TS_TYPE_COMMON (code);
674 0 : break;
675 :
676 6139791 : case TS_TYPE_NON_COMMON:
677 6139791 : MARK_TS_TYPE_WITH_LANG_SPECIFIC (code);
678 6139791 : break;
679 :
680 0 : case TS_DECL_COMMON:
681 0 : MARK_TS_DECL_MINIMAL (code);
682 0 : break;
683 :
684 584742 : case TS_DECL_WRTL:
685 584742 : case TS_CONST_DECL:
686 584742 : MARK_TS_DECL_COMMON (code);
687 584742 : break;
688 :
689 877113 : case TS_DECL_NON_COMMON:
690 877113 : MARK_TS_DECL_WITH_VIS (code);
691 877113 : break;
692 :
693 877113 : case TS_DECL_WITH_VIS:
694 877113 : case TS_PARM_DECL:
695 877113 : case TS_LABEL_DECL:
696 877113 : case TS_RESULT_DECL:
697 877113 : MARK_TS_DECL_WRTL (code);
698 877113 : break;
699 :
700 292371 : case TS_FIELD_DECL:
701 292371 : MARK_TS_DECL_COMMON (code);
702 292371 : break;
703 :
704 292371 : case TS_VAR_DECL:
705 292371 : MARK_TS_DECL_WITH_VIS (code);
706 292371 : break;
707 :
708 584742 : case TS_TYPE_DECL:
709 584742 : case TS_FUNCTION_DECL:
710 584742 : MARK_TS_DECL_NON_COMMON (code);
711 584742 : break;
712 :
713 292371 : case TS_TRANSLATION_UNIT_DECL:
714 292371 : MARK_TS_DECL_COMMON (code);
715 292371 : break;
716 :
717 : default:
718 : gcc_unreachable ();
719 : }
720 : }
721 :
722 : /* Basic consistency checks for attributes used in fold. */
723 292371 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]);
724 292371 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]);
725 292371 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]);
726 292371 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]);
727 292371 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]);
728 292371 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]);
729 292371 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]);
730 292371 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]);
731 292371 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]);
732 292371 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]);
733 292371 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]);
734 292371 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]);
735 292371 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]);
736 292371 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]);
737 292371 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]);
738 292371 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]);
739 292371 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]);
740 292371 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]);
741 292371 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]);
742 292371 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]);
743 292371 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]);
744 292371 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]);
745 292371 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]);
746 292371 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]);
747 292371 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]);
748 292371 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]);
749 292371 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]);
750 292371 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]);
751 292371 : gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]);
752 292371 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]);
753 292371 : gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]);
754 292371 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]);
755 292371 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]);
756 292371 : gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]);
757 292371 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]);
758 292371 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]);
759 292371 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]);
760 292371 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]);
761 292371 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_MINIMAL]);
762 292371 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_COMMON]);
763 292371 : }
764 :
765 :
766 : /* Init tree.cc. */
767 :
768 : void
769 292371 : init_ttree (void)
770 : {
771 : /* Initialize the hash table of types. */
772 292371 : type_hash_table
773 292371 : = hash_table<type_cache_hasher>::create_ggc (TYPE_HASH_INITIAL_SIZE);
774 :
775 292371 : debug_expr_for_decl
776 292371 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
777 :
778 292371 : value_expr_for_decl
779 292371 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
780 :
781 292371 : int_cst_hash_table = hash_table<int_cst_hasher>::create_ggc (1024);
782 :
783 292371 : poly_int_cst_hash_table = hash_table<poly_int_cst_hasher>::create_ggc (64);
784 :
785 292371 : int_cst_node = make_int_cst (1, 1);
786 :
787 292371 : cl_option_hash_table = hash_table<cl_option_hasher>::create_ggc (64);
788 :
789 292371 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
790 292371 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
791 :
792 : /* Initialize the tree_contains_struct array. */
793 292371 : initialize_tree_contains_struct ();
794 292371 : lang_hooks.init_ts ();
795 292371 : }
796 :
797 :
798 : /* Mapping from prefix to label number. */
799 :
800 : struct identifier_hash : ggc_ptr_hash <tree_node>
801 : {
802 55160 : static inline hashval_t hash (tree t)
803 : {
804 55160 : return IDENTIFIER_HASH_VALUE (t);
805 : }
806 : };
807 : struct identifier_count_traits
808 : : simple_hashmap_traits<identifier_hash, long> {};
809 : typedef hash_map<tree, long, identifier_count_traits> internal_label_map;
810 : static GTY(()) internal_label_map *internal_label_nums;
811 :
812 : /* Generates an identifier intended to be used internally with the
813 : given PREFIX. This is intended to be used by the frontend so that
814 : C++ modules can regenerate appropriate (non-clashing) identifiers on
815 : stream-in. */
816 :
817 : tree
818 44139 : generate_internal_label (const char *prefix)
819 : {
820 44139 : tree prefix_id = get_identifier (prefix);
821 44139 : if (!internal_label_nums)
822 3049 : internal_label_nums = internal_label_map::create_ggc();
823 44139 : long &num = internal_label_nums->get_or_insert (prefix_id);
824 :
825 44139 : char tmp[32];
826 44139 : ASM_GENERATE_INTERNAL_LABEL (tmp, prefix, num++);
827 :
828 44139 : tree id = get_identifier (tmp);
829 44139 : IDENTIFIER_INTERNAL_P (id) = true;
830 :
831 : /* Cache the prefix on the identifier so we can retrieve it later. */
832 44139 : TREE_CHAIN (id) = prefix_id;
833 :
834 44139 : return id;
835 : }
836 :
837 : /* Get the PREFIX we created the internal identifier LABEL with. */
838 :
839 : const char *
840 7 : prefix_for_internal_label (tree label)
841 : {
842 7 : gcc_assert (IDENTIFIER_INTERNAL_P (label)
843 : && !IDENTIFIER_TRANSPARENT_ALIAS (label)
844 : && TREE_CHAIN (label)
845 : && TREE_CODE (TREE_CHAIN (label)) == IDENTIFIER_NODE);
846 7 : return IDENTIFIER_POINTER (TREE_CHAIN (label));
847 : }
848 :
849 : /* The name of the object as the assembler will see it (but before any
850 : translations made by ASM_OUTPUT_LABELREF). Often this is the same
851 : as DECL_NAME. It is an IDENTIFIER_NODE. */
852 : tree
853 1753912892 : decl_assembler_name (tree decl)
854 : {
855 1753912892 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
856 172778095 : lang_hooks.set_decl_assembler_name (decl);
857 1753912892 : return DECL_ASSEMBLER_NAME_RAW (decl);
858 : }
859 :
860 : /* The DECL_ASSEMBLER_NAME_RAW of DECL is being explicitly set to NAME
861 : (either of which may be NULL). Inform the FE, if this changes the
862 : name. */
863 :
864 : void
865 918277700 : overwrite_decl_assembler_name (tree decl, tree name)
866 : {
867 918277700 : if (DECL_ASSEMBLER_NAME_RAW (decl) != name)
868 451761236 : lang_hooks.overwrite_decl_assembler_name (decl, name);
869 918277700 : }
870 :
871 : /* Return true if DECL may need an assembler name to be set. */
872 :
873 : static inline bool
874 5150557 : need_assembler_name_p (tree decl)
875 : {
876 : /* We use DECL_ASSEMBLER_NAME to hold mangled type names for One Definition
877 : Rule merging. This makes type_odr_p to return true on those types during
878 : LTO and by comparing the mangled name, we can say what types are intended
879 : to be equivalent across compilation unit.
880 :
881 : We do not store names of type_in_anonymous_namespace_p.
882 :
883 : Record, union and enumeration type have linkage that allows use
884 : to check type_in_anonymous_namespace_p. We do not mangle compound types
885 : that always can be compared structurally.
886 :
887 : Similarly for builtin types, we compare properties of their main variant.
888 : A special case are integer types where mangling do make differences
889 : between char/signed char/unsigned char etc. Storing name for these makes
890 : e.g. -fno-signed-char/-fsigned-char mismatches to be handled well.
891 : See cp/mangle.cc:write_builtin_type for details. */
892 :
893 5150557 : if (TREE_CODE (decl) == TYPE_DECL)
894 : {
895 157052 : if (DECL_NAME (decl)
896 127662 : && decl == TYPE_NAME (TREE_TYPE (decl))
897 127507 : && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TREE_TYPE (decl)
898 108256 : && !TYPE_ARTIFICIAL (TREE_TYPE (decl))
899 105236 : && ((TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
900 87385 : && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE)
901 18109 : || TYPE_CXX_ODR_P (TREE_TYPE (decl)))
902 103837 : && (type_with_linkage_p (TREE_TYPE (decl))
903 88995 : || TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE)
904 226192 : && !variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
905 69140 : return !DECL_ASSEMBLER_NAME_SET_P (decl);
906 87912 : return false;
907 : }
908 : /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
909 4993505 : if (!VAR_OR_FUNCTION_DECL_P (decl))
910 : return false;
911 :
912 : /* If DECL already has its assembler name set, it does not need a
913 : new one. */
914 4301863 : if (!HAS_DECL_ASSEMBLER_NAME_P (decl)
915 4301863 : || DECL_ASSEMBLER_NAME_SET_P (decl))
916 : return false;
917 :
918 : /* Abstract decls do not need an assembler name, except they
919 : can be looked up by autofdo. */
920 1726373 : if (DECL_ABSTRACT_P (decl) && !flag_auto_profile)
921 : return false;
922 :
923 : /* For VAR_DECLs, only static, public and external symbols need an
924 : assembler name. */
925 1724995 : if (VAR_P (decl)
926 542710 : && !TREE_STATIC (decl)
927 542385 : && !TREE_PUBLIC (decl)
928 2267380 : && !DECL_EXTERNAL (decl))
929 : return false;
930 :
931 1182610 : if (TREE_CODE (decl) == FUNCTION_DECL)
932 : {
933 : /* Do not set assembler name on builtins. Allow RTL expansion to
934 : decide whether to expand inline or via a regular call. */
935 1182285 : if (fndecl_built_in_p (decl)
936 1182285 : && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND)
937 : return false;
938 :
939 : /* Functions represented in the callgraph need an assembler name. */
940 1177571 : if (cgraph_node::get (decl) != NULL)
941 : return true;
942 :
943 : /* Unused and not public functions don't need an assembler name. */
944 3372 : if (!TREE_USED (decl) && !TREE_PUBLIC (decl))
945 : return false;
946 : }
947 :
948 : return true;
949 : }
950 :
951 : /* If T needs an assembler name, have one created for it. */
952 :
953 : void
954 5150557 : assign_assembler_name_if_needed (tree t)
955 : {
956 5150557 : if (need_assembler_name_p (t))
957 : {
958 : /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
959 : diagnostics that use input_location to show locus
960 : information. The problem here is that, at this point,
961 : input_location is generally anchored to the end of the file
962 : (since the parser is long gone), so we don't have a good
963 : position to pin it to.
964 :
965 : To alleviate this problem, this uses the location of T's
966 : declaration. Examples of this are
967 : testsuite/g++.dg/template/cond2.C and
968 : testsuite/g++.dg/template/pr35240.C. */
969 1247010 : location_t saved_location = input_location;
970 1247010 : input_location = DECL_SOURCE_LOCATION (t);
971 :
972 1247010 : decl_assembler_name (t);
973 :
974 1247010 : input_location = saved_location;
975 : }
976 5150557 : }
977 :
978 : /* When the target supports COMDAT groups, this indicates which group the
979 : DECL is associated with. This can be either an IDENTIFIER_NODE or a
980 : decl, in which case its DECL_ASSEMBLER_NAME identifies the group. */
981 : tree
982 393889378 : decl_comdat_group (const_tree node)
983 : {
984 393889378 : struct symtab_node *snode = symtab_node::get (node);
985 393889378 : if (!snode)
986 : return NULL;
987 376561602 : return snode->get_comdat_group ();
988 : }
989 :
990 : /* Likewise, but make sure it's been reduced to an IDENTIFIER_NODE. */
991 : tree
992 11912 : decl_comdat_group_id (const_tree node)
993 : {
994 11912 : struct symtab_node *snode = symtab_node::get (node);
995 11912 : if (!snode)
996 : return NULL;
997 11912 : return snode->get_comdat_group_id ();
998 : }
999 :
1000 : /* When the target supports named section, return its name as IDENTIFIER_NODE
1001 : or NULL if it is in no section. */
1002 : const char *
1003 752449482 : decl_section_name (const_tree node)
1004 : {
1005 752449482 : struct symtab_node *snode = symtab_node::get (node);
1006 752449482 : if (!snode)
1007 : return NULL;
1008 565703421 : return snode->get_section ();
1009 : }
1010 :
1011 : /* Set section name of NODE to VALUE (that is expected to be
1012 : identifier node) */
1013 : void
1014 1824096 : set_decl_section_name (tree node, const char *value)
1015 : {
1016 1824096 : struct symtab_node *snode;
1017 :
1018 1824096 : if (value == NULL)
1019 : {
1020 210 : snode = symtab_node::get (node);
1021 210 : if (!snode)
1022 : return;
1023 : }
1024 1823886 : else if (VAR_P (node))
1025 1565642 : snode = varpool_node::get_create (node);
1026 : else
1027 258244 : snode = cgraph_node::get_create (node);
1028 1824096 : snode->set_section (value);
1029 : }
1030 :
1031 : /* Set section name of NODE to match the section name of OTHER.
1032 :
1033 : set_decl_section_name (decl, other) is equivalent to
1034 : set_decl_section_name (decl, DECL_SECTION_NAME (other)), but possibly more
1035 : efficient. */
1036 : void
1037 16618171 : set_decl_section_name (tree decl, const_tree other)
1038 : {
1039 16618171 : struct symtab_node *other_node = symtab_node::get (other);
1040 16618171 : if (other_node)
1041 : {
1042 16602511 : struct symtab_node *decl_node;
1043 16602511 : if (VAR_P (decl))
1044 23 : decl_node = varpool_node::get_create (decl);
1045 : else
1046 16602488 : decl_node = cgraph_node::get_create (decl);
1047 16602511 : decl_node->set_section (*other_node);
1048 : }
1049 : else
1050 : {
1051 15660 : struct symtab_node *decl_node = symtab_node::get (decl);
1052 15660 : if (!decl_node)
1053 : return;
1054 0 : decl_node->set_section (NULL);
1055 : }
1056 : }
1057 :
1058 : /* Return TLS model of a variable NODE. */
1059 : enum tls_model
1060 279980219 : decl_tls_model (const_tree node)
1061 : {
1062 279980219 : struct varpool_node *snode = varpool_node::get (node);
1063 279980219 : if (!snode)
1064 : return TLS_MODEL_NONE;
1065 230705748 : return snode->tls_model;
1066 : }
1067 :
1068 : /* Set TLS model of variable NODE to MODEL. */
1069 : void
1070 57488 : set_decl_tls_model (tree node, enum tls_model model)
1071 : {
1072 57488 : struct varpool_node *vnode;
1073 :
1074 57488 : if (model == TLS_MODEL_NONE)
1075 : {
1076 6107 : vnode = varpool_node::get (node);
1077 6107 : if (!vnode)
1078 : return;
1079 : }
1080 : else
1081 51381 : vnode = varpool_node::get_create (node);
1082 51381 : vnode->tls_model = model;
1083 : }
1084 :
1085 : /* Compute the number of bytes occupied by a tree with code CODE.
1086 : This function cannot be used for nodes that have variable sizes,
1087 : including TREE_VEC, INTEGER_CST, STRING_CST, and CALL_EXPR. */
1088 : size_t
1089 19106366354 : tree_code_size (enum tree_code code)
1090 : {
1091 19106366354 : switch (TREE_CODE_CLASS (code))
1092 : {
1093 4590773771 : case tcc_declaration: /* A decl node */
1094 4590773771 : switch (code)
1095 : {
1096 : case FIELD_DECL: return sizeof (tree_field_decl);
1097 : case PARM_DECL: return sizeof (tree_parm_decl);
1098 282303844 : case VAR_DECL: return sizeof (tree_var_decl);
1099 : case LABEL_DECL: return sizeof (tree_label_decl);
1100 : case RESULT_DECL: return sizeof (tree_result_decl);
1101 31224571 : case CONST_DECL: return sizeof (tree_const_decl);
1102 : case TYPE_DECL: return sizeof (tree_type_decl);
1103 1455149202 : case FUNCTION_DECL: return sizeof (tree_function_decl);
1104 : case DEBUG_EXPR_DECL: return sizeof (tree_decl_with_rtl);
1105 : case TRANSLATION_UNIT_DECL: return sizeof (tree_translation_unit_decl);
1106 : case NAMESPACE_DECL:
1107 : case IMPORTED_DECL:
1108 : case NAMELIST_DECL: return sizeof (tree_decl_non_common);
1109 299456995 : default:
1110 299456995 : gcc_checking_assert (code >= NUM_TREE_CODES);
1111 299456995 : return lang_hooks.tree_size (code);
1112 : }
1113 :
1114 3186954139 : case tcc_type: /* a type node */
1115 3186954139 : switch (code)
1116 : {
1117 : case OFFSET_TYPE:
1118 : case ENUMERAL_TYPE:
1119 : case BOOLEAN_TYPE:
1120 : case INTEGER_TYPE:
1121 : case REAL_TYPE:
1122 : case OPAQUE_TYPE:
1123 : case POINTER_TYPE:
1124 : case REFERENCE_TYPE:
1125 : case NULLPTR_TYPE:
1126 : case FIXED_POINT_TYPE:
1127 : case COMPLEX_TYPE:
1128 : case VECTOR_TYPE:
1129 : case ARRAY_TYPE:
1130 : case RECORD_TYPE:
1131 : case UNION_TYPE:
1132 : case QUAL_UNION_TYPE:
1133 : case VOID_TYPE:
1134 : case FUNCTION_TYPE:
1135 : case METHOD_TYPE:
1136 : case BITINT_TYPE:
1137 : case LANG_TYPE: return sizeof (tree_type_non_common);
1138 763523472 : default:
1139 763523472 : gcc_checking_assert (code >= NUM_TREE_CODES);
1140 763523472 : return lang_hooks.tree_size (code);
1141 : }
1142 :
1143 5259863236 : case tcc_reference: /* a reference */
1144 5259863236 : case tcc_expression: /* an expression */
1145 5259863236 : case tcc_statement: /* an expression with side effects */
1146 5259863236 : case tcc_comparison: /* a comparison expression */
1147 5259863236 : case tcc_unary: /* a unary arithmetic expression */
1148 5259863236 : case tcc_binary: /* a binary arithmetic expression */
1149 5259863236 : return (sizeof (struct tree_exp)
1150 5259863236 : + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
1151 :
1152 43938384 : case tcc_constant: /* a constant */
1153 43938384 : switch (code)
1154 : {
1155 : case VOID_CST: return sizeof (tree_typed);
1156 0 : case INTEGER_CST: gcc_unreachable ();
1157 : case POLY_INT_CST: return sizeof (tree_poly_int_cst);
1158 43085404 : case REAL_CST: return sizeof (tree_real_cst);
1159 : case FIXED_CST: return sizeof (tree_fixed_cst);
1160 : case COMPLEX_CST: return sizeof (tree_complex);
1161 : case RAW_DATA_CST: return sizeof (tree_raw_data);
1162 0 : case VECTOR_CST: gcc_unreachable ();
1163 0 : case STRING_CST: gcc_unreachable ();
1164 64296 : default:
1165 64296 : gcc_checking_assert (code >= NUM_TREE_CODES);
1166 64296 : return lang_hooks.tree_size (code);
1167 : }
1168 :
1169 6024836824 : case tcc_exceptional: /* something random, like an identifier. */
1170 6024836824 : switch (code)
1171 : {
1172 1732525909 : case IDENTIFIER_NODE: return lang_hooks.identifier_size;
1173 : case TREE_LIST: return sizeof (tree_list);
1174 :
1175 : case ERROR_MARK:
1176 : case PLACEHOLDER_EXPR: return sizeof (tree_common);
1177 :
1178 0 : case TREE_VEC: gcc_unreachable ();
1179 0 : case OMP_CLAUSE: gcc_unreachable ();
1180 :
1181 : case SSA_NAME: return sizeof (tree_ssa_name);
1182 :
1183 : case STATEMENT_LIST: return sizeof (tree_statement_list);
1184 316177455 : case BLOCK: return sizeof (struct tree_block);
1185 : case CONSTRUCTOR: return sizeof (tree_constructor);
1186 : case OPTIMIZATION_NODE: return sizeof (tree_optimization_option);
1187 : case TARGET_OPTION_NODE: return sizeof (tree_target_option);
1188 :
1189 1675763927 : default:
1190 1675763927 : gcc_checking_assert (code >= NUM_TREE_CODES);
1191 1675763927 : return lang_hooks.tree_size (code);
1192 : }
1193 :
1194 0 : default:
1195 0 : gcc_unreachable ();
1196 : }
1197 : }
1198 :
1199 : /* Compute the number of bytes occupied by NODE. This routine only
1200 : looks at TREE_CODE, except for those nodes that have variable sizes. */
1201 : size_t
1202 4641448639 : tree_size (const_tree node)
1203 : {
1204 4641448639 : const enum tree_code code = TREE_CODE (node);
1205 4641448639 : switch (code)
1206 : {
1207 541399 : case INTEGER_CST:
1208 541399 : return (sizeof (struct tree_int_cst)
1209 541399 : + (TREE_INT_CST_EXT_NUNITS (node) - 1) * sizeof (HOST_WIDE_INT));
1210 :
1211 0 : case TREE_BINFO:
1212 0 : return (offsetof (struct tree_binfo, base_binfos)
1213 : + vec<tree, va_gc>
1214 0 : ::embedded_size (BINFO_N_BASE_BINFOS (node)));
1215 :
1216 425038650 : case TREE_VEC:
1217 425038650 : return (sizeof (struct tree_vec)
1218 425038650 : + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
1219 :
1220 0 : case VECTOR_CST:
1221 0 : return (sizeof (struct tree_vector)
1222 0 : + (vector_cst_encoded_nelts (node) - 1) * sizeof (tree));
1223 :
1224 23632 : case STRING_CST:
1225 23632 : return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
1226 :
1227 33587 : case OMP_CLAUSE:
1228 33587 : return (sizeof (struct tree_omp_clause)
1229 33587 : + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
1230 33587 : * sizeof (tree));
1231 :
1232 4215811371 : default:
1233 4215811371 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
1234 195277299 : return (sizeof (struct tree_exp)
1235 195277299 : + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
1236 : else
1237 4020534072 : return tree_code_size (code);
1238 : }
1239 : }
1240 :
1241 : /* Return tree node kind based on tree CODE. */
1242 :
1243 : static tree_node_kind
1244 0 : get_stats_node_kind (enum tree_code code)
1245 : {
1246 0 : enum tree_code_class type = TREE_CODE_CLASS (code);
1247 :
1248 0 : switch (type)
1249 : {
1250 : case tcc_declaration: /* A decl node */
1251 : return d_kind;
1252 0 : case tcc_type: /* a type node */
1253 0 : return t_kind;
1254 0 : case tcc_statement: /* an expression with side effects */
1255 0 : return s_kind;
1256 0 : case tcc_reference: /* a reference */
1257 0 : return r_kind;
1258 : case tcc_expression: /* an expression */
1259 : case tcc_comparison: /* a comparison expression */
1260 : case tcc_unary: /* a unary arithmetic expression */
1261 : case tcc_binary: /* a binary arithmetic expression */
1262 : return e_kind;
1263 0 : case tcc_constant: /* a constant */
1264 0 : return c_kind;
1265 0 : case tcc_exceptional: /* something random, like an identifier. */
1266 0 : switch (code)
1267 : {
1268 : case IDENTIFIER_NODE:
1269 : return id_kind;
1270 0 : case TREE_VEC:
1271 0 : return vec_kind;
1272 0 : case TREE_BINFO:
1273 0 : return binfo_kind;
1274 0 : case SSA_NAME:
1275 0 : return ssa_name_kind;
1276 0 : case BLOCK:
1277 0 : return b_kind;
1278 0 : case CONSTRUCTOR:
1279 0 : return constr_kind;
1280 0 : case OMP_CLAUSE:
1281 0 : return omp_clause_kind;
1282 0 : default:
1283 0 : return x_kind;
1284 : }
1285 : break;
1286 : case tcc_vl_exp:
1287 : return e_kind;
1288 0 : default:
1289 0 : gcc_unreachable ();
1290 : }
1291 : }
1292 :
1293 : /* Record interesting allocation statistics for a tree node with CODE
1294 : and LENGTH. */
1295 :
1296 : static void
1297 0 : record_node_allocation_statistics (enum tree_code code, size_t length)
1298 : {
1299 0 : if (!GATHER_STATISTICS)
1300 0 : return;
1301 :
1302 : tree_node_kind kind = get_stats_node_kind (code);
1303 :
1304 : tree_code_counts[(int) code]++;
1305 : tree_node_counts[(int) kind]++;
1306 : tree_node_sizes[(int) kind] += length;
1307 : }
1308 :
1309 : /* Allocate and return a new UID from the DECL_UID namespace. */
1310 :
1311 : int
1312 4584144678 : allocate_decl_uid (void)
1313 : {
1314 4584144678 : return next_decl_uid++;
1315 : }
1316 :
1317 : /* Return a newly allocated node of code CODE. For decl and type
1318 : nodes, some other fields are initialized. The rest of the node is
1319 : initialized to zero. This function cannot be used for TREE_VEC,
1320 : INTEGER_CST or OMP_CLAUSE nodes, which is enforced by asserts in
1321 : tree_code_size.
1322 :
1323 : Achoo! I got a code in the node. */
1324 :
1325 : tree
1326 15080147915 : make_node (enum tree_code code MEM_STAT_DECL)
1327 : {
1328 15080147915 : tree t;
1329 15080147915 : enum tree_code_class type = TREE_CODE_CLASS (code);
1330 15080147915 : size_t length = tree_code_size (code);
1331 :
1332 15080147915 : record_node_allocation_statistics (code, length);
1333 :
1334 15080147915 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1335 15080147915 : TREE_SET_CODE (t, code);
1336 :
1337 15080147915 : switch (type)
1338 : {
1339 786816753 : case tcc_statement:
1340 786816753 : if (code != DEBUG_BEGIN_STMT)
1341 412275316 : TREE_SIDE_EFFECTS (t) = 1;
1342 : break;
1343 :
1344 3261469998 : case tcc_declaration:
1345 3261469998 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1346 : {
1347 3261469998 : if (code == FUNCTION_DECL)
1348 : {
1349 1130196604 : SET_DECL_ALIGN (t, FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY));
1350 1130196604 : SET_DECL_MODE (t, FUNCTION_MODE);
1351 : }
1352 : else
1353 2131273394 : SET_DECL_ALIGN (t, 1);
1354 : }
1355 3261469998 : DECL_SOURCE_LOCATION (t) = input_location;
1356 3261469998 : if (TREE_CODE (t) == DEBUG_EXPR_DECL)
1357 2021521 : DECL_UID (t) = --next_debug_decl_uid;
1358 : else
1359 : {
1360 3259448477 : DECL_UID (t) = allocate_decl_uid ();
1361 3259448477 : SET_DECL_PT_UID (t, -1);
1362 : }
1363 3261469998 : if (TREE_CODE (t) == LABEL_DECL)
1364 37751090 : LABEL_DECL_UID (t) = -1;
1365 :
1366 : break;
1367 :
1368 2363165715 : case tcc_type:
1369 2363165715 : TYPE_UID (t) = next_type_uid++;
1370 2363165715 : SET_TYPE_ALIGN (t, BITS_PER_UNIT);
1371 2363165715 : TYPE_USER_ALIGN (t) = 0;
1372 2363165715 : TYPE_MAIN_VARIANT (t) = t;
1373 2363165715 : TYPE_CANONICAL (t) = t;
1374 :
1375 : /* Default to no attributes for type, but let target change that. */
1376 2363165715 : TYPE_ATTRIBUTES (t) = NULL_TREE;
1377 2363165715 : targetm.set_default_type_attributes (t);
1378 :
1379 : /* We have not yet computed the alias set for this type. */
1380 2363165715 : TYPE_ALIAS_SET (t) = -1;
1381 2363165715 : break;
1382 :
1383 43936606 : case tcc_constant:
1384 43936606 : TREE_CONSTANT (t) = 1;
1385 43936606 : break;
1386 :
1387 1371040502 : case tcc_expression:
1388 1371040502 : switch (code)
1389 : {
1390 294268522 : case INIT_EXPR:
1391 294268522 : case MODIFY_EXPR:
1392 294268522 : case VA_ARG_EXPR:
1393 294268522 : case PREDECREMENT_EXPR:
1394 294268522 : case PREINCREMENT_EXPR:
1395 294268522 : case POSTDECREMENT_EXPR:
1396 294268522 : case POSTINCREMENT_EXPR:
1397 : /* All of these have side-effects, no matter what their
1398 : operands are. */
1399 294268522 : TREE_SIDE_EFFECTS (t) = 1;
1400 294268522 : break;
1401 :
1402 : default:
1403 : break;
1404 : }
1405 : break;
1406 :
1407 5801193021 : case tcc_exceptional:
1408 5801193021 : switch (code)
1409 : {
1410 1087591 : case TARGET_OPTION_NODE:
1411 2175182 : TREE_TARGET_OPTION(t)
1412 1087591 : = ggc_cleared_alloc<struct cl_target_option> ();
1413 1087591 : break;
1414 :
1415 608655 : case OPTIMIZATION_NODE:
1416 1217310 : TREE_OPTIMIZATION (t)
1417 608655 : = ggc_cleared_alloc<struct cl_optimization> ();
1418 608655 : break;
1419 :
1420 : default:
1421 : break;
1422 : }
1423 : break;
1424 :
1425 : default:
1426 : /* Other classes need no special treatment. */
1427 : break;
1428 : }
1429 :
1430 15080147915 : return t;
1431 : }
1432 :
1433 : /* Free tree node. */
1434 :
1435 : void
1436 680533475 : free_node (tree node)
1437 : {
1438 680533475 : enum tree_code code = TREE_CODE (node);
1439 680533475 : if (GATHER_STATISTICS)
1440 : {
1441 : enum tree_node_kind kind = get_stats_node_kind (code);
1442 :
1443 : gcc_checking_assert (tree_code_counts[(int) TREE_CODE (node)] != 0);
1444 : gcc_checking_assert (tree_node_counts[(int) kind] != 0);
1445 : gcc_checking_assert (tree_node_sizes[(int) kind] >= tree_size (node));
1446 :
1447 : tree_code_counts[(int) TREE_CODE (node)]--;
1448 : tree_node_counts[(int) kind]--;
1449 : tree_node_sizes[(int) kind] -= tree_size (node);
1450 : }
1451 680533475 : if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1452 349 : vec_free (CONSTRUCTOR_ELTS (node));
1453 680533282 : else if (code == BLOCK)
1454 0 : vec_free (BLOCK_NONLOCALIZED_VARS (node));
1455 680533282 : else if (code == TREE_BINFO)
1456 369 : vec_free (BINFO_BASE_ACCESSES (node));
1457 680532913 : else if (code == OPTIMIZATION_NODE)
1458 836 : cl_optimization_option_free (TREE_OPTIMIZATION (node));
1459 680532077 : else if (code == TARGET_OPTION_NODE)
1460 901 : cl_target_option_free (TREE_TARGET_OPTION (node));
1461 680533475 : ggc_free (node);
1462 680533475 : }
1463 :
1464 : /* Return a new node with the same contents as NODE except that its
1465 : TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
1466 :
1467 : tree
1468 4556261775 : copy_node (tree node MEM_STAT_DECL)
1469 : {
1470 4556261775 : tree t;
1471 4556261775 : enum tree_code code = TREE_CODE (node);
1472 4556261775 : size_t length;
1473 :
1474 4556261775 : gcc_assert (code != STATEMENT_LIST);
1475 :
1476 4556261775 : length = tree_size (node);
1477 4556261775 : record_node_allocation_statistics (code, length);
1478 4556261775 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
1479 4556261775 : memcpy (t, node, length);
1480 :
1481 4556261775 : if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
1482 2622313434 : TREE_CHAIN (t) = 0;
1483 4556261775 : TREE_ASM_WRITTEN (t) = 0;
1484 4556261775 : TREE_VISITED (t) = 0;
1485 :
1486 4556261775 : if (TREE_CODE_CLASS (code) == tcc_declaration)
1487 : {
1488 1323619406 : if (code == DEBUG_EXPR_DECL)
1489 0 : DECL_UID (t) = --next_debug_decl_uid;
1490 : else
1491 : {
1492 1323619406 : DECL_UID (t) = allocate_decl_uid ();
1493 1323619406 : if (DECL_PT_UID_SET_P (node))
1494 3524 : SET_DECL_PT_UID (t, DECL_PT_UID (node));
1495 : }
1496 659232152 : if ((TREE_CODE (node) == PARM_DECL || VAR_P (node))
1497 1411617079 : && DECL_HAS_VALUE_EXPR_P (node))
1498 : {
1499 1246422 : SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
1500 1246422 : DECL_HAS_VALUE_EXPR_P (t) = 1;
1501 : }
1502 : /* DECL_DEBUG_EXPR is copied explicitly by callers. */
1503 1323619406 : if (VAR_P (node))
1504 : {
1505 87997673 : DECL_HAS_DEBUG_EXPR_P (t) = 0;
1506 87997673 : t->decl_with_vis.symtab_node = NULL;
1507 : }
1508 1323619406 : if (VAR_P (node) && DECL_HAS_INIT_PRIORITY_P (node))
1509 : {
1510 0 : SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
1511 0 : DECL_HAS_INIT_PRIORITY_P (t) = 1;
1512 : }
1513 1323619406 : if (TREE_CODE (node) == FUNCTION_DECL)
1514 : {
1515 319904794 : DECL_STRUCT_FUNCTION (t) = NULL;
1516 319904794 : t->decl_with_vis.symtab_node = NULL;
1517 : }
1518 : }
1519 3232642369 : else if (TREE_CODE_CLASS (code) == tcc_type)
1520 : {
1521 823788424 : TYPE_UID (t) = next_type_uid++;
1522 : /* The following is so that the debug code for
1523 : the copy is different from the original type.
1524 : The two statements usually duplicate each other
1525 : (because they clear fields of the same union),
1526 : but the optimizer should catch that. */
1527 823788424 : TYPE_SYMTAB_ADDRESS (t) = 0;
1528 823788424 : TYPE_SYMTAB_DIE (t) = 0;
1529 :
1530 : /* Do not copy the values cache. */
1531 823788424 : if (TYPE_CACHED_VALUES_P (t))
1532 : {
1533 20031787 : TYPE_CACHED_VALUES_P (t) = 0;
1534 20031787 : TYPE_CACHED_VALUES (t) = NULL_TREE;
1535 : }
1536 : }
1537 2408853945 : else if (code == TARGET_OPTION_NODE)
1538 : {
1539 0 : TREE_TARGET_OPTION (t) = ggc_alloc<struct cl_target_option>();
1540 0 : memcpy (TREE_TARGET_OPTION (t), TREE_TARGET_OPTION (node),
1541 : sizeof (struct cl_target_option));
1542 : }
1543 2408853945 : else if (code == OPTIMIZATION_NODE)
1544 : {
1545 0 : TREE_OPTIMIZATION (t) = ggc_alloc<struct cl_optimization>();
1546 0 : memcpy (TREE_OPTIMIZATION (t), TREE_OPTIMIZATION (node),
1547 : sizeof (struct cl_optimization));
1548 : }
1549 :
1550 4556261775 : return t;
1551 : }
1552 :
1553 : /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1554 : For example, this can copy a list made of TREE_LIST nodes. */
1555 :
1556 : tree
1557 167907539 : copy_list (tree list)
1558 : {
1559 167907539 : tree head;
1560 167907539 : tree prev, next;
1561 :
1562 167907539 : if (list == 0)
1563 : return 0;
1564 :
1565 162703353 : head = prev = copy_node (list);
1566 162703353 : next = TREE_CHAIN (list);
1567 320403731 : while (next)
1568 : {
1569 157700378 : TREE_CHAIN (prev) = copy_node (next);
1570 157700378 : prev = TREE_CHAIN (prev);
1571 157700378 : next = TREE_CHAIN (next);
1572 : }
1573 : return head;
1574 : }
1575 :
1576 :
1577 : /* Return the value that TREE_INT_CST_EXT_NUNITS should have for an
1578 : INTEGER_CST with value CST and type TYPE. */
1579 :
1580 : static unsigned int
1581 11100722230 : get_int_cst_ext_nunits (tree type, const wide_int &cst)
1582 : {
1583 11100722230 : gcc_checking_assert (cst.get_precision () == TYPE_PRECISION (type));
1584 : /* We need extra HWIs if CST is an unsigned integer with its
1585 : upper bit set. */
1586 11100722230 : if (TYPE_UNSIGNED (type) && wi::neg_p (cst))
1587 185234758 : return cst.get_precision () / HOST_BITS_PER_WIDE_INT + 1;
1588 10915487472 : return cst.get_len ();
1589 : }
1590 :
1591 : /* Return a new INTEGER_CST with value CST and type TYPE. */
1592 :
1593 : static tree
1594 134450518 : build_new_int_cst (tree type, const wide_int &cst)
1595 : {
1596 134450518 : unsigned int len = cst.get_len ();
1597 134450518 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1598 134450518 : tree nt = make_int_cst (len, ext_len);
1599 :
1600 134450518 : if (len < ext_len)
1601 : {
1602 68794500 : --ext_len;
1603 137589000 : TREE_INT_CST_ELT (nt, ext_len)
1604 68794500 : = zext_hwi (-1, cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1605 92016712 : for (unsigned int i = len; i < ext_len; ++i)
1606 23222212 : TREE_INT_CST_ELT (nt, i) = -1;
1607 : }
1608 65656018 : else if (TYPE_UNSIGNED (type)
1609 65656018 : && cst.get_precision () < len * HOST_BITS_PER_WIDE_INT)
1610 : {
1611 14286783 : len--;
1612 28573566 : TREE_INT_CST_ELT (nt, len)
1613 14286783 : = zext_hwi (cst.elt (len),
1614 14286783 : cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1615 : }
1616 :
1617 258037237 : for (unsigned int i = 0; i < len; i++)
1618 123586719 : TREE_INT_CST_ELT (nt, i) = cst.elt (i);
1619 134450518 : TREE_TYPE (nt) = type;
1620 134450518 : return nt;
1621 : }
1622 :
1623 : /* Return a new POLY_INT_CST with coefficients COEFFS and type TYPE. */
1624 :
1625 : static tree
1626 0 : build_new_poly_int_cst (tree type, tree (&coeffs)[NUM_POLY_INT_COEFFS]
1627 : CXX_MEM_STAT_INFO)
1628 : {
1629 0 : size_t length = sizeof (struct tree_poly_int_cst);
1630 0 : record_node_allocation_statistics (POLY_INT_CST, length);
1631 :
1632 0 : tree t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1633 :
1634 0 : TREE_SET_CODE (t, POLY_INT_CST);
1635 0 : TREE_CONSTANT (t) = 1;
1636 0 : TREE_TYPE (t) = type;
1637 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1638 0 : POLY_INT_CST_COEFF (t, i) = coeffs[i];
1639 0 : return t;
1640 : }
1641 :
1642 : /* Create a constant tree that contains CST sign-extended to TYPE. */
1643 :
1644 : tree
1645 7309034381 : build_int_cst (tree type, poly_int64 cst)
1646 : {
1647 : /* Support legacy code. */
1648 7309034381 : if (!type)
1649 2560671069 : type = integer_type_node;
1650 :
1651 7309034381 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1652 : }
1653 :
1654 : /* Create a constant tree that contains CST zero-extended to TYPE. */
1655 :
1656 : tree
1657 9875230 : build_int_cstu (tree type, poly_uint64 cst)
1658 : {
1659 9875230 : return wide_int_to_tree (type, wi::uhwi (cst, TYPE_PRECISION (type)));
1660 : }
1661 :
1662 : /* Create a constant tree that contains CST sign-extended to TYPE. */
1663 :
1664 : tree
1665 28258955 : build_int_cst_type (tree type, poly_int64 cst)
1666 : {
1667 28258955 : gcc_assert (type);
1668 28258955 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1669 : }
1670 :
1671 : /* Constructs tree in type TYPE from with value given by CST. Signedness
1672 : of CST is assumed to be the same as the signedness of TYPE. */
1673 :
1674 : tree
1675 7297653 : double_int_to_tree (tree type, double_int cst)
1676 : {
1677 7297653 : return wide_int_to_tree (type, widest_int::from (cst, TYPE_SIGN (type)));
1678 : }
1679 :
1680 : /* We force the wide_int CST to the range of the type TYPE by sign or
1681 : zero extending it. OVERFLOWABLE indicates if we are interested in
1682 : overflow of the value, when >0 we are only interested in signed
1683 : overflow, for <0 we are interested in any overflow. OVERFLOWED
1684 : indicates whether overflow has already occurred. CONST_OVERFLOWED
1685 : indicates whether constant overflow has already occurred. We force
1686 : T's value to be within range of T's type (by setting to 0 or 1 all
1687 : the bits outside the type's range). We set TREE_OVERFLOWED if,
1688 : OVERFLOWED is nonzero,
1689 : or OVERFLOWABLE is >0 and signed overflow occurs
1690 : or OVERFLOWABLE is <0 and any overflow occurs
1691 : We return a new tree node for the extended wide_int. The node
1692 : is shared if no overflow flags are set. */
1693 :
1694 :
1695 : tree
1696 3029741895 : force_fit_type (tree type, const poly_wide_int_ref &cst,
1697 : int overflowable, bool overflowed)
1698 : {
1699 3029741895 : signop sign = TYPE_SIGN (type);
1700 :
1701 : /* If we need to set overflow flags, return a new unshared node. */
1702 3029741895 : if (overflowed || !wi::fits_to_tree_p (cst, type))
1703 : {
1704 6919168 : if (overflowed
1705 6919168 : || overflowable < 0
1706 5704181 : || (overflowable > 0 && sign == SIGNED))
1707 : {
1708 1293468 : poly_wide_int tmp = poly_wide_int::from (cst, TYPE_PRECISION (type),
1709 1293468 : sign);
1710 1293468 : tree t;
1711 1293468 : if (tmp.is_constant ())
1712 1293468 : t = build_new_int_cst (type, tmp.coeffs[0]);
1713 : else
1714 : {
1715 : tree coeffs[NUM_POLY_INT_COEFFS];
1716 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1717 : {
1718 : coeffs[i] = build_new_int_cst (type, tmp.coeffs[i]);
1719 : TREE_OVERFLOW (coeffs[i]) = 1;
1720 : }
1721 : t = build_new_poly_int_cst (type, coeffs);
1722 : }
1723 1293468 : TREE_OVERFLOW (t) = 1;
1724 1293468 : return t;
1725 1293468 : }
1726 : }
1727 :
1728 : /* Else build a shared node. */
1729 3028448427 : return wide_int_to_tree (type, cst);
1730 : }
1731 :
1732 : /* These are the hash table functions for the hash table of INTEGER_CST
1733 : nodes of a sizetype. */
1734 :
1735 : /* Return the hash code X, an INTEGER_CST. */
1736 :
1737 : hashval_t
1738 3283157911 : int_cst_hasher::hash (tree x)
1739 : {
1740 3283157911 : const_tree const t = x;
1741 3283157911 : hashval_t code = TYPE_UID (TREE_TYPE (t));
1742 3283157911 : int i;
1743 :
1744 6572085745 : for (i = 0; i < TREE_INT_CST_NUNITS (t); i++)
1745 3288927834 : code = iterative_hash_host_wide_int (TREE_INT_CST_ELT(t, i), code);
1746 :
1747 3283157911 : return code;
1748 : }
1749 :
1750 : /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1751 : is the same as that given by *Y, which is the same. */
1752 :
1753 : bool
1754 3233513069 : int_cst_hasher::equal (tree x, tree y)
1755 : {
1756 3233513069 : const_tree const xt = x;
1757 3233513069 : const_tree const yt = y;
1758 :
1759 3233513069 : if (TREE_TYPE (xt) != TREE_TYPE (yt)
1760 1015845917 : || TREE_INT_CST_NUNITS (xt) != TREE_INT_CST_NUNITS (yt)
1761 4249296588 : || TREE_INT_CST_EXT_NUNITS (xt) != TREE_INT_CST_EXT_NUNITS (yt))
1762 : return false;
1763 :
1764 1368448456 : for (int i = 0; i < TREE_INT_CST_NUNITS (xt); i++)
1765 980340029 : if (TREE_INT_CST_ELT (xt, i) != TREE_INT_CST_ELT (yt, i))
1766 : return false;
1767 :
1768 : return true;
1769 : }
1770 :
1771 : /* Cache wide_int CST into the TYPE_CACHED_VALUES cache for TYPE.
1772 : SLOT is the slot entry to store it in, and MAX_SLOTS is the maximum
1773 : number of slots that can be cached for the type. */
1774 :
1775 : static inline tree
1776 10411288146 : cache_wide_int_in_type_cache (tree type, const wide_int &cst,
1777 : int slot, int max_slots)
1778 : {
1779 10411288146 : gcc_checking_assert (slot >= 0);
1780 : /* Initialize cache. */
1781 10411288146 : if (!TYPE_CACHED_VALUES_P (type))
1782 : {
1783 20063780 : TYPE_CACHED_VALUES_P (type) = 1;
1784 20063780 : TYPE_CACHED_VALUES (type) = make_tree_vec (max_slots);
1785 : }
1786 10411288146 : tree t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot);
1787 10411288146 : if (!t)
1788 : {
1789 : /* Create a new shared int. */
1790 62089392 : t = build_new_int_cst (type, cst);
1791 62089392 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot) = t;
1792 : }
1793 10411288146 : return t;
1794 : }
1795 :
1796 : /* Create an INT_CST node of TYPE and value CST.
1797 : The returned node is always shared. For small integers we use a
1798 : per-type vector cache, for larger ones we use a single hash table.
1799 : The value is extended from its precision according to the sign of
1800 : the type to be a multiple of HOST_BITS_PER_WIDE_INT. This defines
1801 : the upper bits and ensures that hashing and value equality based
1802 : upon the underlying HOST_WIDE_INTs works without masking. */
1803 :
1804 : static tree
1805 10966271712 : wide_int_to_tree_1 (tree type, const wide_int_ref &pcst)
1806 : {
1807 10966271712 : tree t;
1808 10966271712 : int ix = -1;
1809 10966271712 : int limit = 0;
1810 :
1811 10966271712 : gcc_assert (type);
1812 10966271712 : unsigned int prec = TYPE_PRECISION (type);
1813 10966271712 : signop sgn = TYPE_SIGN (type);
1814 :
1815 : /* Verify that everything is canonical. */
1816 10966271712 : int l = pcst.get_len ();
1817 10966271712 : if (l > 1)
1818 : {
1819 3963844 : if (pcst.elt (l - 1) == 0)
1820 1140889 : gcc_checking_assert (pcst.elt (l - 2) < 0);
1821 3963844 : if (pcst.elt (l - 1) == HOST_WIDE_INT_M1)
1822 8545 : gcc_checking_assert (pcst.elt (l - 2) >= 0);
1823 : }
1824 :
1825 10966271712 : wide_int cst = wide_int::from (pcst, prec, sgn);
1826 10966271712 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1827 :
1828 10966271712 : enum tree_code code = TREE_CODE (type);
1829 10966271712 : if (code == POINTER_TYPE || code == REFERENCE_TYPE)
1830 : {
1831 : /* Cache NULL pointer and zero bounds. */
1832 191814171 : if (cst == 0)
1833 : ix = 0;
1834 : /* Cache upper bounds of pointers. */
1835 50334891 : else if (cst == wi::max_value (prec, sgn))
1836 : ix = 1;
1837 : /* Cache 1 which is used for a non-zero range. */
1838 48224184 : else if (cst == 1)
1839 : ix = 2;
1840 :
1841 : if (ix >= 0)
1842 : {
1843 149362476 : t = cache_wide_int_in_type_cache (type, cst, ix, 3);
1844 : /* Make sure no one is clobbering the shared constant. */
1845 149362476 : gcc_checking_assert (TREE_TYPE (t) == type
1846 : && cst == wi::to_wide (t));
1847 149362476 : return t;
1848 : }
1849 : }
1850 10816909236 : if (ext_len == 1)
1851 : {
1852 : /* We just need to store a single HOST_WIDE_INT. */
1853 10745841578 : HOST_WIDE_INT hwi;
1854 10745841578 : if (TYPE_UNSIGNED (type))
1855 7223561318 : hwi = cst.to_uhwi ();
1856 : else
1857 3522280790 : hwi = cst.to_shwi ();
1858 :
1859 10745841578 : switch (code)
1860 : {
1861 225374 : case NULLPTR_TYPE:
1862 225374 : gcc_assert (hwi == 0);
1863 : /* Fallthru. */
1864 :
1865 : case POINTER_TYPE:
1866 : case REFERENCE_TYPE:
1867 : /* Ignore pointers, as they were already handled above. */
1868 : break;
1869 :
1870 112933851 : case BOOLEAN_TYPE:
1871 : /* Cache false or true. */
1872 112933851 : limit = 2;
1873 112933851 : if (IN_RANGE (hwi, 0, 1))
1874 112731006 : ix = hwi;
1875 : break;
1876 :
1877 10575291954 : case INTEGER_TYPE:
1878 10575291954 : case OFFSET_TYPE:
1879 10575291954 : case BITINT_TYPE:
1880 10575291954 : if (TYPE_SIGN (type) == UNSIGNED)
1881 : {
1882 : /* Cache [0, N). */
1883 7059219476 : limit = param_integer_share_limit;
1884 7059219476 : if (IN_RANGE (hwi, 0, param_integer_share_limit - 1))
1885 6781822281 : ix = hwi;
1886 : }
1887 : else
1888 : {
1889 : /* Cache [-1, N). */
1890 3516072478 : limit = param_integer_share_limit + 1;
1891 3516072478 : if (IN_RANGE (hwi, -1, param_integer_share_limit - 1))
1892 3367372383 : ix = hwi + 1;
1893 : }
1894 : break;
1895 :
1896 : case ENUMERAL_TYPE:
1897 : break;
1898 :
1899 0 : default:
1900 0 : gcc_unreachable ();
1901 : }
1902 :
1903 10745841578 : if (ix >= 0)
1904 : {
1905 10261925670 : t = cache_wide_int_in_type_cache (type, cst, ix, limit);
1906 : /* Make sure no one is clobbering the shared constant. */
1907 20523851340 : gcc_checking_assert (TREE_TYPE (t) == type
1908 : && TREE_INT_CST_NUNITS (t) == 1
1909 : && TREE_INT_CST_EXT_NUNITS (t) == 1
1910 : && TREE_INT_CST_ELT (t, 0) == hwi);
1911 : return t;
1912 : }
1913 : else
1914 : {
1915 : /* Use the cache of larger shared ints, using int_cst_node as
1916 : a temporary. */
1917 :
1918 483915908 : TREE_INT_CST_ELT (int_cst_node, 0) = hwi;
1919 483915908 : TREE_TYPE (int_cst_node) = type;
1920 :
1921 483915908 : tree *slot = int_cst_hash_table->find_slot (int_cst_node, INSERT);
1922 483915908 : t = *slot;
1923 483915908 : if (!t)
1924 : {
1925 : /* Insert this one into the hash table. */
1926 155293551 : t = int_cst_node;
1927 155293551 : *slot = t;
1928 : /* Make a new node for next time round. */
1929 155293551 : int_cst_node = make_int_cst (1, 1);
1930 : }
1931 : }
1932 : }
1933 : else
1934 : {
1935 : /* The value either hashes properly or we drop it on the floor
1936 : for the gc to take care of. There will not be enough of them
1937 : to worry about. */
1938 :
1939 71067658 : tree nt = build_new_int_cst (type, cst);
1940 71067658 : tree *slot = int_cst_hash_table->find_slot (nt, INSERT);
1941 71067658 : t = *slot;
1942 71067658 : if (!t)
1943 : {
1944 : /* Insert this one into the hash table. */
1945 12302288 : t = nt;
1946 12302288 : *slot = t;
1947 : }
1948 : else
1949 58765370 : ggc_free (nt);
1950 : }
1951 :
1952 : return t;
1953 10966271712 : }
1954 :
1955 : hashval_t
1956 0 : poly_int_cst_hasher::hash (tree t)
1957 : {
1958 0 : inchash::hash hstate;
1959 :
1960 0 : hstate.add_int (TYPE_UID (TREE_TYPE (t)));
1961 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1962 0 : hstate.add_wide_int (wi::to_wide (POLY_INT_CST_COEFF (t, i)));
1963 :
1964 0 : return hstate.end ();
1965 : }
1966 :
1967 : bool
1968 0 : poly_int_cst_hasher::equal (tree x, const compare_type &y)
1969 : {
1970 0 : if (TREE_TYPE (x) != y.first)
1971 : return false;
1972 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1973 0 : if (wi::to_wide (POLY_INT_CST_COEFF (x, i)) != y.second->coeffs[i])
1974 : return false;
1975 : return true;
1976 : }
1977 :
1978 : /* Build a POLY_INT_CST node with type TYPE and with the elements in VALUES.
1979 : The elements must also have type TYPE. */
1980 :
1981 : tree
1982 0 : build_poly_int_cst (tree type, const poly_wide_int_ref &values)
1983 : {
1984 0 : unsigned int prec = TYPE_PRECISION (type);
1985 0 : gcc_assert (prec <= values.coeffs[0].get_precision ());
1986 0 : poly_wide_int c = poly_wide_int::from (values, prec, SIGNED);
1987 :
1988 0 : inchash::hash h;
1989 0 : h.add_int (TYPE_UID (type));
1990 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1991 0 : h.add_wide_int (c.coeffs[i]);
1992 0 : poly_int_cst_hasher::compare_type comp (type, &c);
1993 0 : tree *slot = poly_int_cst_hash_table->find_slot_with_hash (comp, h.end (),
1994 : INSERT);
1995 0 : if (*slot == NULL_TREE)
1996 : {
1997 : tree coeffs[NUM_POLY_INT_COEFFS];
1998 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1999 0 : coeffs[i] = wide_int_to_tree_1 (type, c.coeffs[i]);
2000 0 : *slot = build_new_poly_int_cst (type, coeffs);
2001 : }
2002 0 : return *slot;
2003 0 : }
2004 :
2005 : /* Create a constant tree with value VALUE in type TYPE. */
2006 :
2007 : tree
2008 10966271712 : wide_int_to_tree (tree type, const poly_wide_int_ref &value)
2009 : {
2010 10966271712 : if (value.is_constant ())
2011 10966271712 : return wide_int_to_tree_1 (type, value.coeffs[0]);
2012 : return build_poly_int_cst (type, value);
2013 : }
2014 :
2015 : /* Insert INTEGER_CST T into a cache of integer constants. And return
2016 : the cached constant (which may or may not be T). If MIGHT_DUPLICATE
2017 : is false, and T falls into the type's 'smaller values' range, there
2018 : cannot be an existing entry. Otherwise, if MIGHT_DUPLICATE is true,
2019 : or the value is large, should an existing entry exist, it is
2020 : returned (rather than inserting T). */
2021 :
2022 : tree
2023 637154 : cache_integer_cst (tree t, bool might_duplicate ATTRIBUTE_UNUSED)
2024 : {
2025 637154 : tree type = TREE_TYPE (t);
2026 637154 : int ix = -1;
2027 637154 : int limit = 0;
2028 637154 : int prec = TYPE_PRECISION (type);
2029 :
2030 637154 : gcc_assert (!TREE_OVERFLOW (t));
2031 :
2032 : /* The caching indices here must match those in
2033 : wide_int_to_type_1. */
2034 637154 : switch (TREE_CODE (type))
2035 : {
2036 0 : case NULLPTR_TYPE:
2037 0 : gcc_checking_assert (integer_zerop (t));
2038 : /* Fallthru. */
2039 :
2040 4879 : case POINTER_TYPE:
2041 4879 : case REFERENCE_TYPE:
2042 4879 : {
2043 4879 : if (integer_zerop (t))
2044 : ix = 0;
2045 1878 : else if (integer_onep (t))
2046 : ix = 2;
2047 :
2048 : if (ix >= 0)
2049 : limit = 3;
2050 : }
2051 : break;
2052 :
2053 10666 : case BOOLEAN_TYPE:
2054 : /* Cache false or true. */
2055 10666 : limit = 2;
2056 10666 : if (wi::ltu_p (wi::to_wide (t), 2))
2057 0 : ix = TREE_INT_CST_ELT (t, 0);
2058 : break;
2059 :
2060 606127 : case INTEGER_TYPE:
2061 606127 : case OFFSET_TYPE:
2062 606127 : case BITINT_TYPE:
2063 606127 : if (TYPE_UNSIGNED (type))
2064 : {
2065 : /* Cache 0..N */
2066 452723 : limit = param_integer_share_limit;
2067 :
2068 : /* This is a little hokie, but if the prec is smaller than
2069 : what is necessary to hold param_integer_share_limit, then the
2070 : obvious test will not get the correct answer. */
2071 452723 : if (prec < HOST_BITS_PER_WIDE_INT)
2072 : {
2073 96299 : if (tree_to_uhwi (t)
2074 96299 : < (unsigned HOST_WIDE_INT) param_integer_share_limit)
2075 15798 : ix = tree_to_uhwi (t);
2076 : }
2077 356424 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2078 276497 : ix = tree_to_uhwi (t);
2079 : }
2080 : else
2081 : {
2082 : /* Cache -1..N */
2083 153404 : limit = param_integer_share_limit + 1;
2084 :
2085 153404 : if (integer_minus_onep (t))
2086 : ix = 0;
2087 152934 : else if (!wi::neg_p (wi::to_wide (t)))
2088 : {
2089 135883 : if (prec < HOST_BITS_PER_WIDE_INT)
2090 : {
2091 129189 : if (tree_to_shwi (t) < param_integer_share_limit)
2092 120077 : ix = tree_to_shwi (t) + 1;
2093 : }
2094 6694 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2095 5419 : ix = tree_to_shwi (t) + 1;
2096 : }
2097 : }
2098 : break;
2099 :
2100 : case ENUMERAL_TYPE:
2101 : /* The slot used by TYPE_CACHED_VALUES is used for the enum
2102 : members. */
2103 : break;
2104 :
2105 0 : default:
2106 0 : gcc_unreachable ();
2107 : }
2108 :
2109 420792 : if (ix >= 0)
2110 : {
2111 : /* Look for it in the type's vector of small shared ints. */
2112 421710 : if (!TYPE_CACHED_VALUES_P (type))
2113 : {
2114 14221 : TYPE_CACHED_VALUES_P (type) = 1;
2115 14221 : TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
2116 : }
2117 :
2118 421710 : if (tree r = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix))
2119 : {
2120 395259 : gcc_checking_assert (might_duplicate);
2121 395259 : t = r;
2122 : }
2123 : else
2124 26451 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
2125 : }
2126 : else
2127 : {
2128 : /* Use the cache of larger shared ints. */
2129 215444 : tree *slot = int_cst_hash_table->find_slot (t, INSERT);
2130 215444 : if (tree r = *slot)
2131 : {
2132 : /* If there is already an entry for the number verify it's the
2133 : same value. */
2134 125656 : gcc_checking_assert (wi::to_wide (tree (r)) == wi::to_wide (t));
2135 : /* And return the cached value. */
2136 125656 : t = r;
2137 : }
2138 : else
2139 : /* Otherwise insert this one into the hash table. */
2140 89788 : *slot = t;
2141 : }
2142 :
2143 637154 : return t;
2144 : }
2145 :
2146 :
2147 : /* Builds an integer constant in TYPE such that lowest BITS bits are ones
2148 : and the rest are zeros. */
2149 :
2150 : tree
2151 9631766 : build_low_bits_mask (tree type, unsigned bits)
2152 : {
2153 9631766 : gcc_assert (bits <= TYPE_PRECISION (type));
2154 :
2155 9631766 : return wide_int_to_tree (type, wi::mask (bits, false,
2156 9631766 : TYPE_PRECISION (type)));
2157 : }
2158 :
2159 : /* Checks that X is integer constant that can be expressed in (unsigned)
2160 : HOST_WIDE_INT without loss of precision. */
2161 :
2162 : bool
2163 789556055 : cst_and_fits_in_hwi (const_tree x)
2164 : {
2165 789556055 : return (TREE_CODE (x) == INTEGER_CST
2166 789556055 : && (tree_fits_shwi_p (x) || tree_fits_uhwi_p (x)));
2167 : }
2168 :
2169 : /* Build a newly constructed VECTOR_CST with the given values of
2170 : (VECTOR_CST_)LOG2_NPATTERNS and (VECTOR_CST_)NELTS_PER_PATTERN. */
2171 :
2172 : tree
2173 3447064 : make_vector (unsigned log2_npatterns,
2174 : unsigned int nelts_per_pattern MEM_STAT_DECL)
2175 : {
2176 3447064 : gcc_assert (IN_RANGE (nelts_per_pattern, 1, 3));
2177 3447064 : tree t;
2178 3447064 : unsigned npatterns = 1 << log2_npatterns;
2179 3447064 : unsigned encoded_nelts = npatterns * nelts_per_pattern;
2180 3447064 : unsigned length = (sizeof (struct tree_vector)
2181 : + (encoded_nelts - 1) * sizeof (tree));
2182 :
2183 3447064 : record_node_allocation_statistics (VECTOR_CST, length);
2184 :
2185 3447064 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2186 :
2187 3447064 : TREE_SET_CODE (t, VECTOR_CST);
2188 3447064 : TREE_CONSTANT (t) = 1;
2189 3447064 : VECTOR_CST_LOG2_NPATTERNS (t) = log2_npatterns;
2190 3447064 : VECTOR_CST_NELTS_PER_PATTERN (t) = nelts_per_pattern;
2191 :
2192 3447064 : return t;
2193 : }
2194 :
2195 : /* Return a new VECTOR_CST node whose type is TYPE and whose values
2196 : are extracted from V, a vector of CONSTRUCTOR_ELT. */
2197 :
2198 : tree
2199 686763 : build_vector_from_ctor (tree type, const vec<constructor_elt, va_gc> *v)
2200 : {
2201 686763 : if (vec_safe_length (v) == 0)
2202 2031 : return build_zero_cst (type);
2203 :
2204 684732 : unsigned HOST_WIDE_INT idx, npatterns, nelts_per_pattern;
2205 684732 : tree value;
2206 :
2207 : /* If the vector is a VLA, build a VLA constant vector. */
2208 684732 : npatterns = constant_lower_bound (TYPE_VECTOR_SUBPARTS (type));
2209 684732 : nelts_per_pattern = TYPE_VECTOR_SUBPARTS (type).is_constant () ? 1 : 2;
2210 684732 : gcc_assert (vec_safe_length (v) <= npatterns);
2211 :
2212 684732 : tree_vector_builder vec (type, npatterns, nelts_per_pattern);
2213 4537745 : FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
2214 : {
2215 3853013 : if (TREE_CODE (value) == VECTOR_CST)
2216 : {
2217 : /* If NPATTERNS is constant then this must be too. */
2218 4908 : unsigned int sub_nelts = VECTOR_CST_NELTS (value).to_constant ();
2219 19972 : for (unsigned i = 0; i < sub_nelts; ++i)
2220 15064 : vec.quick_push (VECTOR_CST_ELT (value, i));
2221 : }
2222 : else
2223 3848105 : vec.quick_push (value);
2224 : }
2225 1934906 : while (vec.length () < npatterns * nelts_per_pattern)
2226 282721 : vec.quick_push (build_zero_cst (TREE_TYPE (type)));
2227 :
2228 684732 : return vec.build ();
2229 684732 : }
2230 :
2231 : /* Build a vector of type VECTYPE where all the elements are SCs. */
2232 : tree
2233 660146 : build_vector_from_val (tree vectype, tree sc)
2234 : {
2235 660146 : unsigned HOST_WIDE_INT i, nunits;
2236 :
2237 660146 : if (sc == error_mark_node)
2238 : return sc;
2239 :
2240 : /* Verify that the vector type is suitable for SC. Note that there
2241 : is some inconsistency in the type-system with respect to restrict
2242 : qualifications of pointers. Vector types always have a main-variant
2243 : element type and the qualification is applied to the vector-type.
2244 : So TREE_TYPE (vector-type) does not return a properly qualified
2245 : vector element-type. */
2246 660146 : gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
2247 : TREE_TYPE (vectype)));
2248 :
2249 660146 : if (CONSTANT_CLASS_P (sc))
2250 : {
2251 629105 : tree_vector_builder v (vectype, 1, 1);
2252 629105 : v.quick_push (sc);
2253 629105 : return v.build ();
2254 629105 : }
2255 31041 : else if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
2256 : return fold_build1 (VEC_DUPLICATE_EXPR, vectype, sc);
2257 : else
2258 : {
2259 31041 : vec<constructor_elt, va_gc> *v;
2260 31041 : vec_alloc (v, nunits);
2261 149306 : for (i = 0; i < nunits; ++i)
2262 118265 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
2263 31041 : return build_constructor (vectype, v);
2264 : }
2265 : }
2266 :
2267 : /* If TYPE is not a vector type, just return SC, otherwise return
2268 : build_vector_from_val (TYPE, SC). */
2269 :
2270 : tree
2271 5449723 : build_uniform_cst (tree type, tree sc)
2272 : {
2273 5449723 : if (!VECTOR_TYPE_P (type))
2274 : return sc;
2275 :
2276 367 : return build_vector_from_val (type, sc);
2277 : }
2278 :
2279 : /* Build a vector series of type TYPE in which element I has the value
2280 : BASE + I * STEP. The result is a constant if BASE and STEP are constant
2281 : and a VEC_SERIES_EXPR otherwise. */
2282 :
2283 : tree
2284 18 : build_vec_series (tree type, tree base, tree step)
2285 : {
2286 18 : if (integer_zerop (step))
2287 0 : return build_vector_from_val (type, base);
2288 18 : if (TREE_CODE (base) == INTEGER_CST && TREE_CODE (step) == INTEGER_CST)
2289 : {
2290 18 : tree_vector_builder builder (type, 1, 3);
2291 18 : tree elt1 = wide_int_to_tree (TREE_TYPE (base),
2292 36 : wi::to_wide (base) + wi::to_wide (step));
2293 18 : tree elt2 = wide_int_to_tree (TREE_TYPE (base),
2294 36 : wi::to_wide (elt1) + wi::to_wide (step));
2295 18 : builder.quick_push (base);
2296 18 : builder.quick_push (elt1);
2297 18 : builder.quick_push (elt2);
2298 18 : return builder.build ();
2299 18 : }
2300 0 : return build2 (VEC_SERIES_EXPR, type, base, step);
2301 : }
2302 :
2303 : /* Return a vector with the same number of units and number of bits
2304 : as VEC_TYPE, but in which the elements are a linear series of unsigned
2305 : integers { BASE, BASE + STEP, BASE + STEP * 2, ... }. */
2306 :
2307 : tree
2308 1795 : build_index_vector (tree vec_type, poly_uint64 base, poly_uint64 step)
2309 : {
2310 1795 : tree index_vec_type = vec_type;
2311 1795 : tree index_elt_type = TREE_TYPE (vec_type);
2312 1795 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vec_type);
2313 1795 : if (!INTEGRAL_TYPE_P (index_elt_type) || !TYPE_UNSIGNED (index_elt_type))
2314 : {
2315 4 : index_elt_type = build_nonstandard_integer_type
2316 8 : (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (index_elt_type)), true);
2317 4 : index_vec_type = build_vector_type (index_elt_type, nunits);
2318 : }
2319 :
2320 1795 : tree_vector_builder v (index_vec_type, 1, 3);
2321 7180 : for (unsigned int i = 0; i < 3; ++i)
2322 5385 : v.quick_push (build_int_cstu (index_elt_type, base + i * step));
2323 1795 : return v.build ();
2324 1795 : }
2325 :
2326 : /* Return a VECTOR_CST of type VEC_TYPE in which the first NUM_A
2327 : elements are A and the rest are B. */
2328 :
2329 : tree
2330 0 : build_vector_a_then_b (tree vec_type, unsigned int num_a, tree a, tree b)
2331 : {
2332 0 : gcc_assert (known_le (num_a, TYPE_VECTOR_SUBPARTS (vec_type)));
2333 0 : unsigned int count = constant_lower_bound (TYPE_VECTOR_SUBPARTS (vec_type));
2334 : /* Optimize the constant case. */
2335 0 : if ((count & 1) == 0 && TYPE_VECTOR_SUBPARTS (vec_type).is_constant ())
2336 0 : count /= 2;
2337 0 : tree_vector_builder builder (vec_type, count, 2);
2338 0 : for (unsigned int i = 0; i < count * 2; ++i)
2339 0 : builder.quick_push (i < num_a ? a : b);
2340 0 : return builder.build ();
2341 0 : }
2342 :
2343 : /* Something has messed with the elements of CONSTRUCTOR C after it was built;
2344 : calculate TREE_CONSTANT and TREE_SIDE_EFFECTS. */
2345 :
2346 : void
2347 153378799 : recompute_constructor_flags (tree c)
2348 : {
2349 153378799 : unsigned int i;
2350 153378799 : tree val;
2351 153378799 : bool constant_p = true;
2352 153378799 : bool side_effects_p = false;
2353 153378799 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2354 :
2355 334015839 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2356 : {
2357 : /* Mostly ctors will have elts that don't have side-effects, so
2358 : the usual case is to scan all the elements. Hence a single
2359 : loop for both const and side effects, rather than one loop
2360 : each (with early outs). */
2361 180637040 : if (!TREE_CONSTANT (val))
2362 22431445 : constant_p = false;
2363 180637040 : if (TREE_SIDE_EFFECTS (val))
2364 4667203 : side_effects_p = true;
2365 : }
2366 :
2367 153378799 : TREE_SIDE_EFFECTS (c) = side_effects_p;
2368 153378799 : TREE_CONSTANT (c) = constant_p;
2369 153378799 : }
2370 :
2371 : /* Make sure that TREE_CONSTANT and TREE_SIDE_EFFECTS are correct for
2372 : CONSTRUCTOR C. */
2373 :
2374 : void
2375 19024348 : verify_constructor_flags (tree c)
2376 : {
2377 19024348 : unsigned int i;
2378 19024348 : tree val;
2379 19024348 : bool constant_p = TREE_CONSTANT (c);
2380 19024348 : bool side_effects_p = TREE_SIDE_EFFECTS (c);
2381 19024348 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2382 :
2383 171923601 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2384 : {
2385 152899253 : if (constant_p && !TREE_CONSTANT (val))
2386 0 : internal_error ("non-constant element in constant CONSTRUCTOR");
2387 152899253 : if (!side_effects_p && TREE_SIDE_EFFECTS (val))
2388 0 : internal_error ("side-effects element in no-side-effects CONSTRUCTOR");
2389 : }
2390 19024348 : }
2391 :
2392 : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2393 : are in the vec pointed to by VALS. */
2394 : tree
2395 128852363 : build_constructor (tree type, vec<constructor_elt, va_gc> *vals MEM_STAT_DECL)
2396 : {
2397 128852363 : tree c = make_node (CONSTRUCTOR PASS_MEM_STAT);
2398 :
2399 128852363 : TREE_TYPE (c) = type;
2400 128852363 : CONSTRUCTOR_ELTS (c) = vals;
2401 :
2402 128852363 : recompute_constructor_flags (c);
2403 :
2404 128852363 : return c;
2405 : }
2406 :
2407 : /* Build a CONSTRUCTOR node made of a single initializer, with the specified
2408 : INDEX and VALUE. */
2409 : tree
2410 6967 : build_constructor_single (tree type, tree index, tree value)
2411 : {
2412 6967 : vec<constructor_elt, va_gc> *v;
2413 6967 : constructor_elt elt = {index, value};
2414 :
2415 6967 : vec_alloc (v, 1);
2416 6967 : v->quick_push (elt);
2417 :
2418 6967 : return build_constructor (type, v);
2419 : }
2420 :
2421 :
2422 : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2423 : are in a list pointed to by VALS. */
2424 : tree
2425 1013 : build_constructor_from_list (tree type, tree vals)
2426 : {
2427 1013 : tree t;
2428 1013 : vec<constructor_elt, va_gc> *v = NULL;
2429 :
2430 1013 : if (vals)
2431 : {
2432 1013 : vec_alloc (v, list_length (vals));
2433 20836 : for (t = vals; t; t = TREE_CHAIN (t))
2434 19823 : CONSTRUCTOR_APPEND_ELT (v, TREE_PURPOSE (t), TREE_VALUE (t));
2435 : }
2436 :
2437 1013 : return build_constructor (type, v);
2438 : }
2439 :
2440 : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2441 : are in a vector pointed to by VALS. Note that the TREE_PURPOSE
2442 : fields in the constructor remain null. */
2443 :
2444 : tree
2445 1610 : build_constructor_from_vec (tree type, const vec<tree, va_gc> *vals)
2446 : {
2447 1610 : vec<constructor_elt, va_gc> *v = NULL;
2448 :
2449 73721 : for (tree t : vals)
2450 72111 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t);
2451 :
2452 1610 : return build_constructor (type, v);
2453 : }
2454 :
2455 : /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
2456 : of elements, provided as index/value pairs. */
2457 :
2458 : tree
2459 39710 : build_constructor_va (tree type, int nelts, ...)
2460 : {
2461 39710 : vec<constructor_elt, va_gc> *v = NULL;
2462 39710 : va_list p;
2463 :
2464 39710 : va_start (p, nelts);
2465 39710 : vec_alloc (v, nelts);
2466 39710 : while (nelts--)
2467 : {
2468 120386 : tree index = va_arg (p, tree);
2469 120386 : tree value = va_arg (p, tree);
2470 280482 : CONSTRUCTOR_APPEND_ELT (v, index, value);
2471 : }
2472 39710 : va_end (p);
2473 39710 : return build_constructor (type, v);
2474 : }
2475 :
2476 : /* Return a node of type TYPE for which TREE_CLOBBER_P is true. */
2477 :
2478 : tree
2479 10060116 : build_clobber (tree type, enum clobber_kind kind)
2480 : {
2481 10060116 : tree clobber = build_constructor (type, NULL);
2482 10060116 : TREE_THIS_VOLATILE (clobber) = true;
2483 10060116 : CLOBBER_KIND (clobber) = kind;
2484 10060116 : return clobber;
2485 : }
2486 :
2487 : /* Return a new FIXED_CST node whose type is TYPE and value is F. */
2488 :
2489 : tree
2490 54 : build_fixed (tree type, FIXED_VALUE_TYPE f)
2491 : {
2492 54 : tree v;
2493 54 : FIXED_VALUE_TYPE *fp;
2494 :
2495 54 : v = make_node (FIXED_CST);
2496 54 : fp = ggc_alloc<fixed_value> ();
2497 54 : memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
2498 :
2499 54 : TREE_TYPE (v) = type;
2500 54 : TREE_FIXED_CST_PTR (v) = fp;
2501 54 : return v;
2502 : }
2503 :
2504 : /* Return a new REAL_CST node whose type is TYPE and value is D. */
2505 :
2506 : tree
2507 42964074 : build_real (tree type, REAL_VALUE_TYPE d)
2508 : {
2509 42964074 : tree v;
2510 42964074 : int overflow = 0;
2511 :
2512 : /* dconst{0,1,2,m1,half} are used in various places in
2513 : the middle-end and optimizers, allow them here
2514 : even for decimal floating point types as an exception
2515 : by converting them to decimal. */
2516 42964074 : if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type))
2517 610441 : && (d.cl == rvc_normal || d.cl == rvc_zero)
2518 43572317 : && !d.decimal)
2519 : {
2520 610 : if (memcmp (&d, &dconst1, sizeof (d)) == 0)
2521 0 : decimal_real_from_string (&d, "1");
2522 610 : else if (memcmp (&d, &dconst2, sizeof (d)) == 0)
2523 22 : decimal_real_from_string (&d, "2");
2524 588 : else if (memcmp (&d, &dconstm1, sizeof (d)) == 0)
2525 90 : decimal_real_from_string (&d, "-1");
2526 498 : else if (memcmp (&d, &dconsthalf, sizeof (d)) == 0)
2527 0 : decimal_real_from_string (&d, "0.5");
2528 498 : else if (memcmp (&d, &dconst0, sizeof (d)) == 0)
2529 : {
2530 : /* Make sure to give zero the minimum quantum exponent for
2531 : the type (which corresponds to all bits zero). */
2532 498 : const struct real_format *fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
2533 498 : char buf[16];
2534 498 : sprintf (buf, "0e%d", fmt->emin - fmt->p);
2535 498 : decimal_real_from_string (&d, buf);
2536 : }
2537 : else
2538 0 : gcc_unreachable ();
2539 : }
2540 :
2541 : /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
2542 : Consider doing it via real_convert now. */
2543 :
2544 42964074 : v = make_node (REAL_CST);
2545 42964074 : TREE_TYPE (v) = type;
2546 42964074 : memcpy (TREE_REAL_CST_PTR (v), &d, sizeof (REAL_VALUE_TYPE));
2547 42964074 : TREE_OVERFLOW (v) = overflow;
2548 42964074 : return v;
2549 : }
2550 :
2551 : /* Like build_real, but first truncate D to the type. */
2552 :
2553 : tree
2554 175893 : build_real_truncate (tree type, REAL_VALUE_TYPE d)
2555 : {
2556 175893 : return build_real (type, real_value_truncate (TYPE_MODE (type), d));
2557 : }
2558 :
2559 : /* Return a new REAL_CST node whose type is TYPE
2560 : and whose value is the integer value of the INTEGER_CST node I. */
2561 :
2562 : REAL_VALUE_TYPE
2563 24623978 : real_value_from_int_cst (const_tree type, const_tree i)
2564 : {
2565 24623978 : REAL_VALUE_TYPE d;
2566 :
2567 : /* Clear all bits of the real value type so that we can later do
2568 : bitwise comparisons to see if two values are the same. */
2569 24623978 : memset (&d, 0, sizeof d);
2570 :
2571 24623978 : real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, wi::to_wide (i),
2572 24623978 : TYPE_SIGN (TREE_TYPE (i)));
2573 24623978 : return d;
2574 : }
2575 :
2576 : /* Given a tree representing an integer constant I, return a tree
2577 : representing the same value as a floating-point constant of type TYPE. */
2578 :
2579 : tree
2580 24041141 : build_real_from_int_cst (tree type, const_tree i)
2581 : {
2582 24041141 : tree v;
2583 24041141 : int overflow = TREE_OVERFLOW (i);
2584 :
2585 24041141 : v = build_real (type, real_value_from_int_cst (type, i));
2586 :
2587 24041141 : TREE_OVERFLOW (v) |= overflow;
2588 24041141 : return v;
2589 : }
2590 :
2591 : /* Return a new REAL_CST node whose type is TYPE
2592 : and whose value is the integer value I which has sign SGN. */
2593 :
2594 : tree
2595 138 : build_real_from_wide (tree type, const wide_int_ref &i, signop sgn)
2596 : {
2597 138 : REAL_VALUE_TYPE d;
2598 :
2599 : /* Clear all bits of the real value type so that we can later do
2600 : bitwise comparisons to see if two values are the same. */
2601 138 : memset (&d, 0, sizeof d);
2602 :
2603 138 : real_from_integer (&d, TYPE_MODE (type), i, sgn);
2604 138 : return build_real (type, d);
2605 : }
2606 :
2607 : /* Return a newly constructed STRING_CST node whose value is the LEN
2608 : characters at STR when STR is nonnull, or all zeros otherwise.
2609 : Note that for a C string literal, LEN should include the trailing NUL.
2610 : The TREE_TYPE is not initialized. */
2611 :
2612 : tree
2613 101235940 : build_string (unsigned len, const char *str /*= NULL */)
2614 : {
2615 : /* Do not waste bytes provided by padding of struct tree_string. */
2616 101235940 : unsigned size = len + offsetof (struct tree_string, str) + 1;
2617 :
2618 101235940 : record_node_allocation_statistics (STRING_CST, size);
2619 :
2620 101235940 : tree s = (tree) ggc_internal_alloc (size);
2621 :
2622 101235940 : memset (s, 0, sizeof (struct tree_typed));
2623 101235940 : TREE_SET_CODE (s, STRING_CST);
2624 101235940 : TREE_CONSTANT (s) = 1;
2625 101235940 : TREE_STRING_LENGTH (s) = len;
2626 101235940 : if (str)
2627 101226773 : memcpy (s->string.str, str, len);
2628 : else
2629 9167 : memset (s->string.str, 0, len);
2630 101235940 : s->string.str[len] = '\0';
2631 :
2632 101235940 : return s;
2633 : }
2634 :
2635 : /* Return a newly constructed COMPLEX_CST node whose value is
2636 : specified by the real and imaginary parts REAL and IMAG.
2637 : Both REAL and IMAG should be constant nodes. TYPE, if specified,
2638 : will be the type of the COMPLEX_CST; otherwise a new type will be made. */
2639 :
2640 : tree
2641 487635 : build_complex (tree type, tree real, tree imag)
2642 : {
2643 487635 : gcc_assert (CONSTANT_CLASS_P (real));
2644 487635 : gcc_assert (CONSTANT_CLASS_P (imag));
2645 :
2646 487635 : tree t = make_node (COMPLEX_CST);
2647 :
2648 487635 : TREE_REALPART (t) = real;
2649 487635 : TREE_IMAGPART (t) = imag;
2650 487635 : TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
2651 487635 : TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
2652 487635 : return t;
2653 : }
2654 :
2655 : /* Build a complex (inf +- 0i), such as for the result of cproj.
2656 : TYPE is the complex tree type of the result. If NEG is true, the
2657 : imaginary zero is negative. */
2658 :
2659 : tree
2660 840 : build_complex_inf (tree type, bool neg)
2661 : {
2662 840 : REAL_VALUE_TYPE rzero = dconst0;
2663 :
2664 840 : rzero.sign = neg;
2665 840 : return build_complex (type, build_real (TREE_TYPE (type), dconstinf),
2666 840 : build_real (TREE_TYPE (type), rzero));
2667 : }
2668 :
2669 : /* Return the constant 1 in type TYPE. If TYPE has several elements, each
2670 : element is set to 1. In particular, this is 1 + i for complex types. */
2671 :
2672 : tree
2673 3874 : build_each_one_cst (tree type)
2674 : {
2675 3874 : if (TREE_CODE (type) == COMPLEX_TYPE)
2676 : {
2677 0 : tree scalar = build_one_cst (TREE_TYPE (type));
2678 0 : return build_complex (type, scalar, scalar);
2679 : }
2680 : else
2681 3874 : return build_one_cst (type);
2682 : }
2683 :
2684 : /* Return a constant of arithmetic type TYPE which is the
2685 : multiplicative identity of the set TYPE. */
2686 :
2687 : tree
2688 10241704 : build_one_cst (tree type)
2689 : {
2690 10241704 : switch (TREE_CODE (type))
2691 : {
2692 10227473 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2693 10227473 : case POINTER_TYPE: case REFERENCE_TYPE:
2694 10227473 : case OFFSET_TYPE: case BITINT_TYPE:
2695 10227473 : return build_int_cst (type, 1);
2696 :
2697 10623 : case REAL_TYPE:
2698 10623 : return build_real (type, dconst1);
2699 :
2700 0 : case FIXED_POINT_TYPE:
2701 : /* We can only generate 1 for accum types. */
2702 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2703 0 : return build_fixed (type, FCONST1 (TYPE_MODE (type)));
2704 :
2705 589 : case VECTOR_TYPE:
2706 589 : {
2707 589 : tree scalar = build_one_cst (TREE_TYPE (type));
2708 :
2709 589 : return build_vector_from_val (type, scalar);
2710 : }
2711 :
2712 3019 : case COMPLEX_TYPE:
2713 6038 : return build_complex (type,
2714 3019 : build_one_cst (TREE_TYPE (type)),
2715 6038 : build_zero_cst (TREE_TYPE (type)));
2716 :
2717 0 : default:
2718 0 : gcc_unreachable ();
2719 : }
2720 : }
2721 :
2722 : /* Return an integer of type TYPE containing all 1's in as much precision as
2723 : it contains, or a complex or vector whose subparts are such integers. */
2724 :
2725 : tree
2726 1719798 : build_all_ones_cst (tree type)
2727 : {
2728 1719798 : if (TREE_CODE (type) == COMPLEX_TYPE)
2729 : {
2730 0 : tree scalar = build_all_ones_cst (TREE_TYPE (type));
2731 0 : return build_complex (type, scalar, scalar);
2732 : }
2733 : else
2734 1719798 : return build_minus_one_cst (type);
2735 : }
2736 :
2737 : /* Return a constant of arithmetic type TYPE which is the
2738 : opposite of the multiplicative identity of the set TYPE. */
2739 :
2740 : tree
2741 2323633 : build_minus_one_cst (tree type)
2742 : {
2743 2323633 : switch (TREE_CODE (type))
2744 : {
2745 2204146 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2746 2204146 : case POINTER_TYPE: case REFERENCE_TYPE:
2747 2204146 : case OFFSET_TYPE: case BITINT_TYPE:
2748 2204146 : return build_int_cst (type, -1);
2749 :
2750 9793 : case REAL_TYPE:
2751 9793 : return build_real (type, dconstm1);
2752 :
2753 0 : case FIXED_POINT_TYPE:
2754 : /* We can only generate 1 for accum types. */
2755 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2756 0 : return build_fixed (type,
2757 : fixed_from_double_int (double_int_minus_one,
2758 0 : SCALAR_TYPE_MODE (type)));
2759 :
2760 109694 : case VECTOR_TYPE:
2761 109694 : {
2762 109694 : tree scalar = build_minus_one_cst (TREE_TYPE (type));
2763 :
2764 109694 : return build_vector_from_val (type, scalar);
2765 : }
2766 :
2767 0 : case COMPLEX_TYPE:
2768 0 : return build_complex (type,
2769 0 : build_minus_one_cst (TREE_TYPE (type)),
2770 0 : build_zero_cst (TREE_TYPE (type)));
2771 :
2772 0 : default:
2773 0 : gcc_unreachable ();
2774 : }
2775 : }
2776 :
2777 : /* Build 0 constant of type TYPE. This is used by constructor folding
2778 : and thus the constant should be represented in memory by
2779 : zero(es). */
2780 :
2781 : tree
2782 86672597 : build_zero_cst (tree type)
2783 : {
2784 86672597 : switch (TREE_CODE (type))
2785 : {
2786 86085419 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2787 86085419 : case POINTER_TYPE: case REFERENCE_TYPE:
2788 86085419 : case OFFSET_TYPE: case NULLPTR_TYPE: case BITINT_TYPE:
2789 86085419 : return build_int_cst (type, 0);
2790 :
2791 222027 : case REAL_TYPE:
2792 222027 : return build_real (type, dconst0);
2793 :
2794 0 : case FIXED_POINT_TYPE:
2795 0 : return build_fixed (type, FCONST0 (TYPE_MODE (type)));
2796 :
2797 176862 : case VECTOR_TYPE:
2798 176862 : {
2799 176862 : tree scalar = build_zero_cst (TREE_TYPE (type));
2800 :
2801 176862 : return build_vector_from_val (type, scalar);
2802 : }
2803 :
2804 2082 : case COMPLEX_TYPE:
2805 2082 : {
2806 2082 : tree zero = build_zero_cst (TREE_TYPE (type));
2807 :
2808 2082 : return build_complex (type, zero, zero);
2809 : }
2810 :
2811 186207 : default:
2812 186207 : if (!AGGREGATE_TYPE_P (type))
2813 1 : return fold_convert (type, integer_zero_node);
2814 186206 : return build_constructor (type, NULL);
2815 : }
2816 : }
2817 :
2818 : /* Build a constant of integer type TYPE, made of VALUE's bits replicated
2819 : every WIDTH bits to fit TYPE's precision. */
2820 :
2821 : tree
2822 14 : build_replicated_int_cst (tree type, unsigned int width, HOST_WIDE_INT value)
2823 : {
2824 14 : int n = ((TYPE_PRECISION (type) + HOST_BITS_PER_WIDE_INT - 1)
2825 14 : / HOST_BITS_PER_WIDE_INT);
2826 14 : unsigned HOST_WIDE_INT low, mask;
2827 14 : HOST_WIDE_INT a[WIDE_INT_MAX_INL_ELTS];
2828 14 : int i;
2829 :
2830 14 : gcc_assert (n && n <= WIDE_INT_MAX_INL_ELTS);
2831 :
2832 14 : if (width == HOST_BITS_PER_WIDE_INT)
2833 0 : low = value;
2834 : else
2835 : {
2836 14 : mask = (HOST_WIDE_INT_1U << width) - 1;
2837 14 : low = (unsigned HOST_WIDE_INT) ~0 / mask * (value & mask);
2838 : }
2839 :
2840 28 : for (i = 0; i < n; i++)
2841 14 : a[i] = low;
2842 :
2843 14 : gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
2844 14 : return wide_int_to_tree (type, wide_int::from_array (a, n,
2845 14 : TYPE_PRECISION (type)));
2846 : }
2847 :
2848 : /* If floating-point type TYPE has an IEEE-style sign bit, return an
2849 : unsigned constant in which only the sign bit is set. Return null
2850 : otherwise. */
2851 :
2852 : tree
2853 0 : sign_mask_for (tree type)
2854 : {
2855 : /* Avoid having to choose between a real-only sign and a pair of signs.
2856 : This could be relaxed if the choice becomes obvious later. */
2857 0 : if (TREE_CODE (type) == COMPLEX_TYPE)
2858 : return NULL_TREE;
2859 :
2860 0 : auto eltmode = as_a<scalar_float_mode> (element_mode (type));
2861 0 : auto bits = REAL_MODE_FORMAT (eltmode)->ieee_bits;
2862 0 : if (!bits || !pow2p_hwi (bits))
2863 : return NULL_TREE;
2864 :
2865 0 : tree inttype = unsigned_type_for (type);
2866 0 : if (!inttype)
2867 : return NULL_TREE;
2868 :
2869 0 : auto mask = wi::set_bit_in_zero (bits - 1, bits);
2870 0 : if (VECTOR_TYPE_P (inttype))
2871 : {
2872 0 : tree elt = wide_int_to_tree (TREE_TYPE (inttype), mask);
2873 0 : return build_vector_from_val (inttype, elt);
2874 : }
2875 0 : return wide_int_to_tree (inttype, mask);
2876 0 : }
2877 :
2878 : /* Build a BINFO with LEN language slots. */
2879 :
2880 : tree
2881 111536182 : make_tree_binfo (unsigned base_binfos MEM_STAT_DECL)
2882 : {
2883 111536182 : tree t;
2884 111536182 : size_t length = (offsetof (struct tree_binfo, base_binfos)
2885 111536182 : + vec<tree, va_gc>::embedded_size (base_binfos));
2886 :
2887 111536182 : record_node_allocation_statistics (TREE_BINFO, length);
2888 :
2889 111536182 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
2890 :
2891 111536182 : memset (t, 0, offsetof (struct tree_binfo, base_binfos));
2892 :
2893 111536182 : TREE_SET_CODE (t, TREE_BINFO);
2894 :
2895 111536182 : BINFO_BASE_BINFOS (t)->embedded_init (base_binfos);
2896 :
2897 111536182 : return t;
2898 : }
2899 :
2900 : /* Create a CASE_LABEL_EXPR tree node and return it. */
2901 :
2902 : tree
2903 6939972 : build_case_label (tree low_value, tree high_value, tree label_decl)
2904 : {
2905 6939972 : tree t = make_node (CASE_LABEL_EXPR);
2906 :
2907 6939972 : TREE_TYPE (t) = void_type_node;
2908 6939972 : SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (label_decl));
2909 :
2910 6939972 : CASE_LOW (t) = low_value;
2911 6939972 : CASE_HIGH (t) = high_value;
2912 6939972 : CASE_LABEL (t) = label_decl;
2913 6939972 : CASE_CHAIN (t) = NULL_TREE;
2914 :
2915 6939972 : return t;
2916 : }
2917 :
2918 : /* Build a newly constructed INTEGER_CST node. LEN and EXT_LEN are the
2919 : values of TREE_INT_CST_NUNITS and TREE_INT_CST_EXT_NUNITS respectively.
2920 : The latter determines the length of the HOST_WIDE_INT vector. */
2921 :
2922 : tree
2923 290886331 : make_int_cst (int len, int ext_len MEM_STAT_DECL)
2924 : {
2925 290886331 : tree t;
2926 290886331 : int length = ((ext_len - 1) * sizeof (HOST_WIDE_INT)
2927 290886331 : + sizeof (struct tree_int_cst));
2928 :
2929 290886331 : gcc_assert (len);
2930 290886331 : record_node_allocation_statistics (INTEGER_CST, length);
2931 :
2932 290886331 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2933 :
2934 290886331 : TREE_SET_CODE (t, INTEGER_CST);
2935 290886331 : TREE_INT_CST_NUNITS (t) = len;
2936 290886331 : TREE_INT_CST_EXT_NUNITS (t) = ext_len;
2937 290886331 : TREE_CONSTANT (t) = 1;
2938 :
2939 290886331 : return t;
2940 : }
2941 :
2942 : /* Build a newly constructed TREE_VEC node of length LEN. */
2943 :
2944 : tree
2945 3324473980 : make_tree_vec (int len MEM_STAT_DECL)
2946 : {
2947 3324473980 : tree t;
2948 3324473980 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2949 :
2950 3324473980 : record_node_allocation_statistics (TREE_VEC, length);
2951 :
2952 3324473980 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2953 :
2954 3324473980 : TREE_SET_CODE (t, TREE_VEC);
2955 3324473980 : TREE_VEC_LENGTH (t) = len;
2956 :
2957 3324473980 : return t;
2958 : }
2959 :
2960 : /* Grow a TREE_VEC node to new length LEN. */
2961 :
2962 : tree
2963 490556 : grow_tree_vec (tree v, int len MEM_STAT_DECL)
2964 : {
2965 490556 : gcc_assert (TREE_CODE (v) == TREE_VEC);
2966 :
2967 490556 : int oldlen = TREE_VEC_LENGTH (v);
2968 490556 : gcc_assert (len > oldlen);
2969 :
2970 490556 : size_t oldlength = (oldlen - 1) * sizeof (tree) + sizeof (struct tree_vec);
2971 490556 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2972 :
2973 490556 : record_node_allocation_statistics (TREE_VEC, length - oldlength);
2974 :
2975 490556 : v = (tree) ggc_realloc (v, length PASS_MEM_STAT);
2976 :
2977 490556 : TREE_VEC_LENGTH (v) = len;
2978 :
2979 490556 : return v;
2980 : }
2981 :
2982 : /* Return true if EXPR is the constant zero, whether it is integral, float or
2983 : fixed, and scalar, complex or vector. */
2984 :
2985 : bool
2986 17841862 : zerop (const_tree expr)
2987 : {
2988 17841862 : return (integer_zerop (expr)
2989 12403279 : || real_zerop (expr)
2990 29850593 : || fixed_zerop (expr));
2991 : }
2992 :
2993 : /* Return true if EXPR is the integer constant zero or a complex constant
2994 : of zero, or a location wrapper for such a constant. */
2995 :
2996 : bool
2997 6615336894 : integer_zerop (const_tree expr)
2998 : {
2999 6615336894 : STRIP_ANY_LOCATION_WRAPPER (expr);
3000 :
3001 6615336894 : switch (TREE_CODE (expr))
3002 : {
3003 5399779729 : case INTEGER_CST:
3004 5399779729 : return wi::to_wide (expr) == 0;
3005 1200236 : case COMPLEX_CST:
3006 1200236 : return (integer_zerop (TREE_REALPART (expr))
3007 1222776 : && integer_zerop (TREE_IMAGPART (expr)));
3008 3048121 : case VECTOR_CST:
3009 3048121 : return (VECTOR_CST_NPATTERNS (expr) == 1
3010 2878169 : && VECTOR_CST_DUPLICATE_P (expr)
3011 5477512 : && integer_zerop (VECTOR_CST_ENCODED_ELT (expr, 0)));
3012 : default:
3013 : return false;
3014 : }
3015 : }
3016 :
3017 : /* Return true if EXPR is the integer constant one or the corresponding
3018 : complex constant, or a location wrapper for such a constant. */
3019 :
3020 : bool
3021 1087078744 : integer_onep (const_tree expr)
3022 : {
3023 1087078744 : STRIP_ANY_LOCATION_WRAPPER (expr);
3024 :
3025 1087078744 : switch (TREE_CODE (expr))
3026 : {
3027 941873235 : case INTEGER_CST:
3028 941873235 : return wi::eq_p (wi::to_widest (expr), 1);
3029 21899 : case COMPLEX_CST:
3030 21899 : return (integer_onep (TREE_REALPART (expr))
3031 21923 : && integer_zerop (TREE_IMAGPART (expr)));
3032 188169 : case VECTOR_CST:
3033 188169 : return (VECTOR_CST_NPATTERNS (expr) == 1
3034 166800 : && VECTOR_CST_DUPLICATE_P (expr)
3035 331700 : && integer_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3036 : default:
3037 : return false;
3038 : }
3039 : }
3040 :
3041 : /* Return true if EXPR is the integer constant one. For complex and vector,
3042 : return true if every piece is the integer constant one.
3043 : Also return true for location wrappers for such a constant. */
3044 :
3045 : bool
3046 742173 : integer_each_onep (const_tree expr)
3047 : {
3048 742173 : STRIP_ANY_LOCATION_WRAPPER (expr);
3049 :
3050 742173 : if (TREE_CODE (expr) == COMPLEX_CST)
3051 34 : return (integer_onep (TREE_REALPART (expr))
3052 48 : && integer_onep (TREE_IMAGPART (expr)));
3053 : else
3054 742139 : return integer_onep (expr);
3055 : }
3056 :
3057 : /* Return true if EXPR is an integer containing all 1's in as much precision
3058 : as it contains, or a complex or vector whose subparts are such integers,
3059 : or a location wrapper for such a constant. */
3060 :
3061 : bool
3062 298514426 : integer_all_onesp (const_tree expr)
3063 : {
3064 298514426 : STRIP_ANY_LOCATION_WRAPPER (expr);
3065 :
3066 298514426 : if (TREE_CODE (expr) == COMPLEX_CST
3067 950 : && integer_all_onesp (TREE_REALPART (expr))
3068 298514466 : && integer_all_onesp (TREE_IMAGPART (expr)))
3069 : return true;
3070 :
3071 298514390 : else if (TREE_CODE (expr) == VECTOR_CST)
3072 625042 : return (VECTOR_CST_NPATTERNS (expr) == 1
3073 571332 : && VECTOR_CST_DUPLICATE_P (expr)
3074 1172207 : && integer_all_onesp (VECTOR_CST_ENCODED_ELT (expr, 0)));
3075 :
3076 297889348 : else if (TREE_CODE (expr) != INTEGER_CST)
3077 : return false;
3078 :
3079 197601492 : return (wi::max_value (TYPE_PRECISION (TREE_TYPE (expr)), UNSIGNED)
3080 395203497 : == wi::to_wide (expr));
3081 : }
3082 :
3083 : /* Return true if EXPR is the integer constant minus one, or a location
3084 : wrapper for such a constant. */
3085 :
3086 : bool
3087 218346374 : integer_minus_onep (const_tree expr)
3088 : {
3089 218346374 : STRIP_ANY_LOCATION_WRAPPER (expr);
3090 :
3091 218346374 : if (TREE_CODE (expr) == COMPLEX_CST)
3092 9421 : return (integer_all_onesp (TREE_REALPART (expr))
3093 9425 : && integer_zerop (TREE_IMAGPART (expr)));
3094 : else
3095 218336953 : return integer_all_onesp (expr);
3096 : }
3097 :
3098 : /* Return true if EXPR is an integer constant that is a power of 2 (i.e., has
3099 : only one bit on), or a location wrapper for such a constant. */
3100 :
3101 : bool
3102 20740906 : integer_pow2p (const_tree expr)
3103 : {
3104 20740906 : STRIP_ANY_LOCATION_WRAPPER (expr);
3105 :
3106 20740906 : if (TREE_CODE (expr) == COMPLEX_CST
3107 553 : && integer_pow2p (TREE_REALPART (expr))
3108 20741133 : && integer_zerop (TREE_IMAGPART (expr)))
3109 : return true;
3110 :
3111 20740753 : if (TREE_CODE (expr) != INTEGER_CST)
3112 : return false;
3113 :
3114 13761907 : return wi::popcount (wi::to_wide (expr)) == 1;
3115 : }
3116 :
3117 : /* Return true if EXPR is an integer constant other than zero or a
3118 : complex constant other than zero, or a location wrapper for such a
3119 : constant. */
3120 :
3121 : bool
3122 153335784 : integer_nonzerop (const_tree expr)
3123 : {
3124 153335784 : STRIP_ANY_LOCATION_WRAPPER (expr);
3125 :
3126 153335784 : return ((TREE_CODE (expr) == INTEGER_CST
3127 75948073 : && wi::to_wide (expr) != 0)
3128 173255470 : || (TREE_CODE (expr) == COMPLEX_CST
3129 244 : && (integer_nonzerop (TREE_REALPART (expr))
3130 184 : || integer_nonzerop (TREE_IMAGPART (expr)))));
3131 : }
3132 :
3133 : /* Return true if EXPR is the integer constant one. For vector,
3134 : return true if every piece is the integer constant minus one
3135 : (representing the value TRUE).
3136 : Also return true for location wrappers for such a constant. */
3137 :
3138 : bool
3139 1187191 : integer_truep (const_tree expr)
3140 : {
3141 1187191 : STRIP_ANY_LOCATION_WRAPPER (expr);
3142 :
3143 1187191 : if (TREE_CODE (expr) == VECTOR_CST)
3144 14701 : return integer_all_onesp (expr);
3145 1172490 : return integer_onep (expr);
3146 : }
3147 :
3148 : /* Return true if EXPR is the fixed-point constant zero, or a location wrapper
3149 : for such a constant. */
3150 :
3151 : bool
3152 29311080 : fixed_zerop (const_tree expr)
3153 : {
3154 29311080 : STRIP_ANY_LOCATION_WRAPPER (expr);
3155 :
3156 29311080 : return (TREE_CODE (expr) == FIXED_CST
3157 29311080 : && TREE_FIXED_CST (expr).data.is_zero ());
3158 : }
3159 :
3160 : /* Return the power of two represented by a tree node known to be a
3161 : power of two. */
3162 :
3163 : int
3164 789129 : tree_log2 (const_tree expr)
3165 : {
3166 789129 : if (TREE_CODE (expr) == COMPLEX_CST)
3167 0 : return tree_log2 (TREE_REALPART (expr));
3168 :
3169 789129 : return wi::exact_log2 (wi::to_wide (expr));
3170 : }
3171 :
3172 : /* Similar, but return the largest integer Y such that 2 ** Y is less
3173 : than or equal to EXPR. */
3174 :
3175 : int
3176 2964933 : tree_floor_log2 (const_tree expr)
3177 : {
3178 2964933 : if (TREE_CODE (expr) == COMPLEX_CST)
3179 0 : return tree_log2 (TREE_REALPART (expr));
3180 :
3181 2964933 : return wi::floor_log2 (wi::to_wide (expr));
3182 : }
3183 :
3184 : /* Return number of known trailing zero bits in EXPR, or, if the value of
3185 : EXPR is known to be zero, the precision of it's type. */
3186 :
3187 : unsigned int
3188 84123503 : tree_ctz (const_tree expr)
3189 : {
3190 168245284 : if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
3191 84131456 : && !POINTER_TYPE_P (TREE_TYPE (expr)))
3192 : return 0;
3193 :
3194 84123442 : unsigned int ret1, ret2, prec = TYPE_PRECISION (TREE_TYPE (expr));
3195 84123442 : switch (TREE_CODE (expr))
3196 : {
3197 44652806 : case INTEGER_CST:
3198 44652806 : ret1 = wi::ctz (wi::to_wide (expr));
3199 44652806 : return MIN (ret1, prec);
3200 12873641 : case SSA_NAME:
3201 12873641 : ret1 = wi::ctz (get_nonzero_bits (expr));
3202 12873641 : return MIN (ret1, prec);
3203 2083865 : case PLUS_EXPR:
3204 2083865 : case MINUS_EXPR:
3205 2083865 : case BIT_IOR_EXPR:
3206 2083865 : case BIT_XOR_EXPR:
3207 2083865 : case MIN_EXPR:
3208 2083865 : case MAX_EXPR:
3209 2083865 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3210 2083865 : if (ret1 == 0)
3211 : return ret1;
3212 958315 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3213 958315 : return MIN (ret1, ret2);
3214 0 : case POINTER_PLUS_EXPR:
3215 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3216 0 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3217 : /* Second operand is sizetype, which could be in theory
3218 : wider than pointer's precision. Make sure we never
3219 : return more than prec. */
3220 0 : ret2 = MIN (ret2, prec);
3221 0 : return MIN (ret1, ret2);
3222 234 : case BIT_AND_EXPR:
3223 234 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3224 234 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3225 234 : return MAX (ret1, ret2);
3226 11948779 : case MULT_EXPR:
3227 11948779 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3228 11948779 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3229 11948779 : return MIN (ret1 + ret2, prec);
3230 0 : case LSHIFT_EXPR:
3231 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3232 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3233 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3234 : {
3235 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3236 0 : return MIN (ret1 + ret2, prec);
3237 : }
3238 : return ret1;
3239 0 : case RSHIFT_EXPR:
3240 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3241 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3242 : {
3243 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3244 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3245 0 : if (ret1 > ret2)
3246 0 : return ret1 - ret2;
3247 : }
3248 : return 0;
3249 6017 : case TRUNC_DIV_EXPR:
3250 6017 : case CEIL_DIV_EXPR:
3251 6017 : case FLOOR_DIV_EXPR:
3252 6017 : case ROUND_DIV_EXPR:
3253 6017 : case EXACT_DIV_EXPR:
3254 6017 : if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
3255 6017 : && tree_int_cst_sgn (TREE_OPERAND (expr, 1)) == 1)
3256 : {
3257 6017 : int l = tree_log2 (TREE_OPERAND (expr, 1));
3258 6017 : if (l >= 0)
3259 : {
3260 4941 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3261 4941 : ret2 = l;
3262 4941 : if (ret1 > ret2)
3263 0 : return ret1 - ret2;
3264 : }
3265 : }
3266 : return 0;
3267 12533432 : CASE_CONVERT:
3268 12533432 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3269 12533432 : if (ret1 && ret1 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
3270 : ret1 = prec;
3271 12533432 : return MIN (ret1, prec);
3272 0 : case SAVE_EXPR:
3273 0 : return tree_ctz (TREE_OPERAND (expr, 0));
3274 12573 : case COND_EXPR:
3275 12573 : ret1 = tree_ctz (TREE_OPERAND (expr, 1));
3276 12573 : if (ret1 == 0)
3277 : return 0;
3278 205 : ret2 = tree_ctz (TREE_OPERAND (expr, 2));
3279 205 : return MIN (ret1, ret2);
3280 0 : case COMPOUND_EXPR:
3281 0 : return tree_ctz (TREE_OPERAND (expr, 1));
3282 204 : case ADDR_EXPR:
3283 204 : ret1 = get_pointer_alignment (const_cast<tree> (expr));
3284 204 : if (ret1 > BITS_PER_UNIT)
3285 : {
3286 204 : ret1 = ctz_hwi (ret1 / BITS_PER_UNIT);
3287 204 : return MIN (ret1, prec);
3288 : }
3289 : return 0;
3290 : default:
3291 : return 0;
3292 : }
3293 : }
3294 :
3295 : /* Return true if EXPR is the real constant zero. Trailing zeroes matter for
3296 : decimal float constants, so don't return true for them.
3297 : Also return true for location wrappers around such a constant. */
3298 :
3299 : bool
3300 589235585 : real_zerop (const_tree expr)
3301 : {
3302 589235585 : STRIP_ANY_LOCATION_WRAPPER (expr);
3303 :
3304 589235585 : switch (TREE_CODE (expr))
3305 : {
3306 19310906 : case REAL_CST:
3307 19310906 : return real_equal (&TREE_REAL_CST (expr), &dconst0)
3308 19310906 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3309 45268 : case COMPLEX_CST:
3310 45268 : return real_zerop (TREE_REALPART (expr))
3311 58205 : && real_zerop (TREE_IMAGPART (expr));
3312 469501 : case VECTOR_CST:
3313 469501 : {
3314 : /* Don't simply check for a duplicate because the predicate
3315 : accepts both +0.0 and -0.0. */
3316 469501 : unsigned count = vector_cst_encoded_nelts (expr);
3317 504327 : for (unsigned int i = 0; i < count; ++i)
3318 480527 : if (!real_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3319 : return false;
3320 : return true;
3321 : }
3322 : default:
3323 : return false;
3324 : }
3325 : }
3326 :
3327 : /* Return true if EXPR is the real constant one in real or complex form.
3328 : Trailing zeroes matter for decimal float constants, so don't return
3329 : true for them.
3330 : Also return true for location wrappers around such a constant. */
3331 :
3332 : bool
3333 122077594 : real_onep (const_tree expr)
3334 : {
3335 122077594 : STRIP_ANY_LOCATION_WRAPPER (expr);
3336 :
3337 122077594 : switch (TREE_CODE (expr))
3338 : {
3339 7189204 : case REAL_CST:
3340 7189204 : return real_equal (&TREE_REAL_CST (expr), &dconst1)
3341 7189204 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3342 12972 : case COMPLEX_CST:
3343 12972 : return real_onep (TREE_REALPART (expr))
3344 16581 : && real_zerop (TREE_IMAGPART (expr));
3345 59972 : case VECTOR_CST:
3346 59972 : return (VECTOR_CST_NPATTERNS (expr) == 1
3347 50786 : && VECTOR_CST_DUPLICATE_P (expr)
3348 100673 : && real_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3349 : default:
3350 : return false;
3351 : }
3352 : }
3353 :
3354 : /* Return true if EXPR is the real constant minus one. Trailing zeroes
3355 : matter for decimal float constants, so don't return true for them.
3356 : Also return true for location wrappers around such a constant. */
3357 :
3358 : bool
3359 123108981 : real_minus_onep (const_tree expr)
3360 : {
3361 123108981 : STRIP_ANY_LOCATION_WRAPPER (expr);
3362 :
3363 123108981 : switch (TREE_CODE (expr))
3364 : {
3365 7123570 : case REAL_CST:
3366 7123570 : return real_equal (&TREE_REAL_CST (expr), &dconstm1)
3367 7123570 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3368 12952 : case COMPLEX_CST:
3369 12952 : return real_minus_onep (TREE_REALPART (expr))
3370 15324 : && real_zerop (TREE_IMAGPART (expr));
3371 61593 : case VECTOR_CST:
3372 61593 : return (VECTOR_CST_NPATTERNS (expr) == 1
3373 51807 : && VECTOR_CST_DUPLICATE_P (expr)
3374 103134 : && real_minus_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3375 : default:
3376 : return false;
3377 : }
3378 : }
3379 :
3380 : /* Return true if T could be a floating point zero. */
3381 :
3382 : bool
3383 700343 : real_maybe_zerop (const_tree expr)
3384 : {
3385 700343 : switch (TREE_CODE (expr))
3386 : {
3387 479136 : case REAL_CST:
3388 : /* Can't use real_zerop here, as it always returns false for decimal
3389 : floats. And can't use TREE_REAL_CST (expr).cl == rvc_zero
3390 : either, as decimal zeros are rvc_normal. */
3391 479136 : return real_equal (&TREE_REAL_CST (expr), &dconst0);
3392 0 : case COMPLEX_CST:
3393 0 : return (real_maybe_zerop (TREE_REALPART (expr))
3394 0 : || real_maybe_zerop (TREE_IMAGPART (expr)));
3395 0 : case VECTOR_CST:
3396 0 : {
3397 0 : unsigned count = vector_cst_encoded_nelts (expr);
3398 0 : for (unsigned int i = 0; i < count; ++i)
3399 0 : if (real_maybe_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3400 : return true;
3401 : return false;
3402 : }
3403 : default:
3404 : /* Perhaps for SSA_NAMEs we could query frange. */
3405 : return true;
3406 : }
3407 : }
3408 :
3409 : /* True if EXP is a constant or a cast of a constant. */
3410 :
3411 : bool
3412 6072 : really_constant_p (const_tree exp)
3413 : {
3414 : /* This is not quite the same as STRIP_NOPS. It does more. */
3415 12152 : while (CONVERT_EXPR_P (exp)
3416 12204 : || TREE_CODE (exp) == NON_LVALUE_EXPR)
3417 60 : exp = TREE_OPERAND (exp, 0);
3418 6072 : return TREE_CONSTANT (exp);
3419 : }
3420 :
3421 : /* Return true if T holds a polynomial pointer difference, storing it in
3422 : *VALUE if so. A true return means that T's precision is no greater
3423 : than 64 bits, which is the largest address space we support, so *VALUE
3424 : never loses precision. However, the signedness of the result does
3425 : not necessarily match the signedness of T: sometimes an unsigned type
3426 : like sizetype is used to encode a value that is actually negative. */
3427 :
3428 : bool
3429 11356748 : ptrdiff_tree_p (const_tree t, poly_int64 *value)
3430 : {
3431 11356748 : if (!t)
3432 : return false;
3433 11356748 : if (TREE_CODE (t) == INTEGER_CST)
3434 : {
3435 3266631 : if (!cst_and_fits_in_hwi (t))
3436 : return false;
3437 3266059 : *value = int_cst_value (t);
3438 3266059 : return true;
3439 : }
3440 : if (POLY_INT_CST_P (t))
3441 : {
3442 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3443 : if (!cst_and_fits_in_hwi (POLY_INT_CST_COEFF (t, i)))
3444 : return false;
3445 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3446 : value->coeffs[i] = int_cst_value (POLY_INT_CST_COEFF (t, i));
3447 : return true;
3448 : }
3449 : return false;
3450 : }
3451 :
3452 : poly_int64
3453 478605866 : tree_to_poly_int64 (const_tree t)
3454 : {
3455 478605866 : gcc_assert (tree_fits_poly_int64_p (t));
3456 478605866 : if (POLY_INT_CST_P (t))
3457 : return poly_int_cst_value (t).force_shwi ();
3458 478605866 : return TREE_INT_CST_LOW (t);
3459 : }
3460 :
3461 : poly_uint64
3462 542537441 : tree_to_poly_uint64 (const_tree t)
3463 : {
3464 542537441 : gcc_assert (tree_fits_poly_uint64_p (t));
3465 542537441 : if (POLY_INT_CST_P (t))
3466 : return poly_int_cst_value (t).force_uhwi ();
3467 542537441 : return TREE_INT_CST_LOW (t);
3468 : }
3469 :
3470 : /* Return first list element whose TREE_VALUE is ELEM.
3471 : Return 0 if ELEM is not in LIST. */
3472 :
3473 : tree
3474 8203560 : value_member (tree elem, tree list)
3475 : {
3476 23880819 : while (list)
3477 : {
3478 20740063 : if (elem == TREE_VALUE (list))
3479 : return list;
3480 15677259 : list = TREE_CHAIN (list);
3481 : }
3482 : return NULL_TREE;
3483 : }
3484 :
3485 : /* Return first list element whose TREE_PURPOSE is ELEM.
3486 : Return 0 if ELEM is not in LIST. */
3487 :
3488 : tree
3489 205137273 : purpose_member (const_tree elem, tree list)
3490 : {
3491 541175740 : while (list)
3492 : {
3493 368001287 : if (elem == TREE_PURPOSE (list))
3494 : return list;
3495 336038467 : list = TREE_CHAIN (list);
3496 : }
3497 : return NULL_TREE;
3498 : }
3499 :
3500 : /* Return true if ELEM is in V. */
3501 :
3502 : bool
3503 5341797 : vec_member (const_tree elem, vec<tree, va_gc> *v)
3504 : {
3505 5341797 : unsigned ix;
3506 5341797 : tree t;
3507 8072192 : FOR_EACH_VEC_SAFE_ELT (v, ix, t)
3508 2738647 : if (elem == t)
3509 : return true;
3510 : return false;
3511 : }
3512 :
3513 : /* Returns element number IDX (zero-origin) of chain CHAIN, or
3514 : NULL_TREE. */
3515 :
3516 : tree
3517 22717267 : chain_index (int idx, tree chain)
3518 : {
3519 29085036 : for (; chain && idx > 0; --idx)
3520 6367769 : chain = TREE_CHAIN (chain);
3521 22717267 : return chain;
3522 : }
3523 :
3524 : /* Return true if ELEM is part of the chain CHAIN. */
3525 :
3526 : bool
3527 233462 : chain_member (const_tree elem, const_tree chain)
3528 : {
3529 431514 : while (chain)
3530 : {
3531 430017 : if (elem == chain)
3532 : return true;
3533 198052 : chain = DECL_CHAIN (chain);
3534 : }
3535 :
3536 : return false;
3537 : }
3538 :
3539 : /* Return the length of a chain of nodes chained through TREE_CHAIN.
3540 : We expect a null pointer to mark the end of the chain.
3541 : This is the Lisp primitive `length'. */
3542 :
3543 : int
3544 2112377646 : list_length (const_tree t)
3545 : {
3546 2112377646 : const_tree p = t;
3547 : #ifdef ENABLE_TREE_CHECKING
3548 2112377646 : const_tree q = t;
3549 : #endif
3550 2112377646 : int len = 0;
3551 :
3552 3516580440 : while (p)
3553 : {
3554 1404202794 : p = TREE_CHAIN (p);
3555 : #ifdef ENABLE_TREE_CHECKING
3556 1404202794 : if (len % 2)
3557 458481393 : q = TREE_CHAIN (q);
3558 1404202794 : gcc_assert (p != q);
3559 : #endif
3560 1404202794 : len++;
3561 : }
3562 :
3563 2112377646 : return len;
3564 : }
3565 :
3566 : /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3567 : UNION_TYPE TYPE, or NULL_TREE if none. */
3568 :
3569 : tree
3570 160337 : first_field (const_tree type)
3571 : {
3572 160337 : tree t = TYPE_FIELDS (type);
3573 4349267 : while (t && TREE_CODE (t) != FIELD_DECL)
3574 4188930 : t = TREE_CHAIN (t);
3575 160337 : return t;
3576 : }
3577 :
3578 : /* Returns the last FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3579 : UNION_TYPE TYPE, or NULL_TREE if none. */
3580 :
3581 : tree
3582 2839489 : last_field (const_tree type)
3583 : {
3584 2839489 : tree last = NULL_TREE;
3585 :
3586 65087718 : for (tree fld = TYPE_FIELDS (type); fld; fld = TREE_CHAIN (fld))
3587 : {
3588 62248229 : if (TREE_CODE (fld) != FIELD_DECL)
3589 53714134 : continue;
3590 :
3591 : last = fld;
3592 : }
3593 :
3594 2839489 : return last;
3595 : }
3596 :
3597 : /* Concatenate two chains of nodes (chained through TREE_CHAIN)
3598 : by modifying the last node in chain 1 to point to chain 2.
3599 : This is the Lisp primitive `nconc'. */
3600 :
3601 : tree
3602 4176484803 : chainon (tree op1, tree op2)
3603 : {
3604 4176484803 : tree t1;
3605 :
3606 4176484803 : if (!op1)
3607 : return op2;
3608 775845187 : if (!op2)
3609 : return op1;
3610 :
3611 1601465499 : for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
3612 903576111 : continue;
3613 697889388 : TREE_CHAIN (t1) = op2;
3614 :
3615 : #ifdef ENABLE_TREE_CHECKING
3616 697889388 : {
3617 697889388 : tree t2;
3618 1781653782 : for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
3619 1083764394 : gcc_assert (t2 != t1);
3620 : }
3621 : #endif
3622 :
3623 : return op1;
3624 903576111 : }
3625 :
3626 : /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
3627 :
3628 : tree
3629 105648796 : tree_last (tree chain)
3630 : {
3631 105648796 : tree next;
3632 105648796 : if (chain)
3633 193448714 : while ((next = TREE_CHAIN (chain)))
3634 : chain = next;
3635 105648796 : return chain;
3636 : }
3637 :
3638 : /* Reverse the order of elements in the chain T,
3639 : and return the new head of the chain (old last element). */
3640 :
3641 : tree
3642 1586147239 : nreverse (tree t)
3643 : {
3644 1586147239 : tree prev = 0, decl, next;
3645 4003421283 : for (decl = t; decl; decl = next)
3646 : {
3647 : /* We shouldn't be using this function to reverse BLOCK chains; we
3648 : have blocks_nreverse for that. */
3649 2417274044 : gcc_checking_assert (TREE_CODE (decl) != BLOCK);
3650 2417274044 : next = TREE_CHAIN (decl);
3651 2417274044 : TREE_CHAIN (decl) = prev;
3652 2417274044 : prev = decl;
3653 : }
3654 1586147239 : return prev;
3655 : }
3656 :
3657 : /* Return a newly created TREE_LIST node whose
3658 : purpose and value fields are PARM and VALUE. */
3659 :
3660 : tree
3661 1469049125 : build_tree_list (tree parm, tree value MEM_STAT_DECL)
3662 : {
3663 1469049125 : tree t = make_node (TREE_LIST PASS_MEM_STAT);
3664 1469049125 : TREE_PURPOSE (t) = parm;
3665 1469049125 : TREE_VALUE (t) = value;
3666 1469049125 : return t;
3667 : }
3668 :
3669 : /* Build a chain of TREE_LIST nodes from a vector. */
3670 :
3671 : tree
3672 92294315 : build_tree_list_vec (const vec<tree, va_gc> *vec MEM_STAT_DECL)
3673 : {
3674 92294315 : tree ret = NULL_TREE;
3675 92294315 : tree *pp = &ret;
3676 92294315 : unsigned int i;
3677 92294315 : tree t;
3678 193645061 : FOR_EACH_VEC_SAFE_ELT (vec, i, t)
3679 : {
3680 101350746 : *pp = build_tree_list (NULL, t PASS_MEM_STAT);
3681 101350746 : pp = &TREE_CHAIN (*pp);
3682 : }
3683 92294315 : return ret;
3684 : }
3685 :
3686 : /* Return a newly created TREE_LIST node whose
3687 : purpose and value fields are PURPOSE and VALUE
3688 : and whose TREE_CHAIN is CHAIN. */
3689 :
3690 : tree
3691 5601302794 : tree_cons (tree purpose, tree value, tree chain MEM_STAT_DECL)
3692 : {
3693 5601302794 : tree node;
3694 :
3695 5601302794 : node = ggc_alloc_tree_node_stat (sizeof (struct tree_list) PASS_MEM_STAT);
3696 5601302794 : memset (node, 0, sizeof (struct tree_common));
3697 :
3698 5601302794 : record_node_allocation_statistics (TREE_LIST, sizeof (struct tree_list));
3699 :
3700 5601302794 : TREE_SET_CODE (node, TREE_LIST);
3701 5601302794 : TREE_CHAIN (node) = chain;
3702 5601302794 : TREE_PURPOSE (node) = purpose;
3703 5601302794 : TREE_VALUE (node) = value;
3704 5601302794 : return node;
3705 : }
3706 :
3707 : /* Return the values of the elements of a CONSTRUCTOR as a vector of
3708 : trees. */
3709 :
3710 : vec<tree, va_gc> *
3711 0 : ctor_to_vec (tree ctor)
3712 : {
3713 0 : vec<tree, va_gc> *vec;
3714 0 : vec_alloc (vec, CONSTRUCTOR_NELTS (ctor));
3715 0 : unsigned int ix;
3716 0 : tree val;
3717 :
3718 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val)
3719 0 : vec->quick_push (val);
3720 :
3721 0 : return vec;
3722 : }
3723 :
3724 : /* Return the size nominally occupied by an object of type TYPE
3725 : when it resides in memory. The value is measured in units of bytes,
3726 : and its data type is that normally used for type sizes
3727 : (which is the first type created by make_signed_type or
3728 : make_unsigned_type). */
3729 :
3730 : tree
3731 28828667 : size_in_bytes_loc (location_t loc, const_tree type)
3732 : {
3733 28828667 : tree t;
3734 :
3735 28828667 : if (type == error_mark_node)
3736 0 : return integer_zero_node;
3737 :
3738 28828667 : type = TYPE_MAIN_VARIANT (type);
3739 28828667 : t = TYPE_SIZE_UNIT (type);
3740 :
3741 28828667 : if (t == 0)
3742 : {
3743 65 : lang_hooks.types.incomplete_type_error (loc, NULL_TREE, type);
3744 65 : return size_zero_node;
3745 : }
3746 :
3747 : return t;
3748 : }
3749 :
3750 : /* Return the size of TYPE (in bytes) as a wide integer
3751 : or return -1 if the size can vary or is larger than an integer. */
3752 :
3753 : HOST_WIDE_INT
3754 522416417 : int_size_in_bytes (const_tree type)
3755 : {
3756 522416417 : tree t;
3757 :
3758 522416417 : if (type == error_mark_node)
3759 : return 0;
3760 :
3761 522416417 : type = TYPE_MAIN_VARIANT (type);
3762 522416417 : t = TYPE_SIZE_UNIT (type);
3763 :
3764 522416417 : if (t && tree_fits_uhwi_p (t))
3765 522363191 : return TREE_INT_CST_LOW (t);
3766 : else
3767 : return -1;
3768 : }
3769 :
3770 : /* Return the maximum size of TYPE (in bytes) as a wide integer
3771 : or return -1 if the size can vary or is larger than an integer. */
3772 :
3773 : HOST_WIDE_INT
3774 9220 : max_int_size_in_bytes (const_tree type)
3775 : {
3776 9220 : HOST_WIDE_INT size = -1;
3777 9220 : tree size_tree;
3778 :
3779 : /* If this is an array type, check for a possible MAX_SIZE attached. */
3780 :
3781 9220 : if (TREE_CODE (type) == ARRAY_TYPE)
3782 : {
3783 8487 : size_tree = TYPE_ARRAY_MAX_SIZE (type);
3784 :
3785 8487 : if (size_tree && tree_fits_uhwi_p (size_tree))
3786 0 : size = tree_to_uhwi (size_tree);
3787 : }
3788 :
3789 : /* If we still haven't been able to get a size, see if the language
3790 : can compute a maximum size. */
3791 :
3792 0 : if (size == -1)
3793 : {
3794 9220 : size_tree = lang_hooks.types.max_size (type);
3795 :
3796 9220 : if (size_tree && tree_fits_uhwi_p (size_tree))
3797 0 : size = tree_to_uhwi (size_tree);
3798 : }
3799 :
3800 9220 : return size;
3801 : }
3802 :
3803 : /* Return the bit position of FIELD, in bits from the start of the record.
3804 : This is a tree of type bitsizetype. */
3805 :
3806 : tree
3807 145299657 : bit_position (const_tree field)
3808 : {
3809 145299657 : return bit_from_pos (DECL_FIELD_OFFSET (field),
3810 145299657 : DECL_FIELD_BIT_OFFSET (field));
3811 : }
3812 :
3813 : /* Return the byte position of FIELD, in bytes from the start of the record.
3814 : This is a tree of type sizetype. */
3815 :
3816 : tree
3817 119585892 : byte_position (const_tree field)
3818 : {
3819 119585892 : return byte_from_pos (DECL_FIELD_OFFSET (field),
3820 119585892 : DECL_FIELD_BIT_OFFSET (field));
3821 : }
3822 :
3823 : /* Likewise, but return as an integer. It must be representable in
3824 : that way (since it could be a signed value, we don't have the
3825 : option of returning -1 like int_size_in_byte can. */
3826 :
3827 : HOST_WIDE_INT
3828 10110795 : int_byte_position (const_tree field)
3829 : {
3830 10110795 : return tree_to_shwi (byte_position (field));
3831 : }
3832 :
3833 : /* Return, as a tree node, the number of elements for TYPE (which is an
3834 : ARRAY_TYPE) minus one. This counts only elements of the top array. */
3835 :
3836 : tree
3837 113915275 : array_type_nelts_minus_one (const_tree type)
3838 : {
3839 113915275 : tree index_type, min, max;
3840 :
3841 : /* If they did it with unspecified bounds, then we should have already
3842 : given an error about it before we got here. */
3843 113915275 : if (! TYPE_DOMAIN (type))
3844 10148554 : return error_mark_node;
3845 :
3846 103766721 : index_type = TYPE_DOMAIN (type);
3847 103766721 : min = TYPE_MIN_VALUE (index_type);
3848 103766721 : max = TYPE_MAX_VALUE (index_type);
3849 :
3850 : /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
3851 103766721 : if (!max)
3852 : {
3853 : /* zero sized arrays are represented from C FE as complete types with
3854 : NULL TYPE_MAX_VALUE and zero TYPE_SIZE, while C++ FE represents
3855 : them as min 0, max -1. */
3856 1277334 : if (COMPLETE_TYPE_P (type)
3857 3145 : && integer_zerop (TYPE_SIZE (type))
3858 1280479 : && integer_zerop (min))
3859 3145 : return build_int_cst (TREE_TYPE (min), -1);
3860 :
3861 1274189 : return error_mark_node;
3862 : }
3863 :
3864 102489387 : return (integer_zerop (min)
3865 102489387 : ? max
3866 1152261 : : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
3867 : }
3868 :
3869 : /* Return, as an INTEGER_CST node, the number of elements for TYPE
3870 : (which is an ARRAY_TYPE). This counts only elements of the top
3871 : array. */
3872 :
3873 : tree
3874 24301720 : array_type_nelts_top (tree type)
3875 : {
3876 24301720 : return fold_build2_loc (input_location,
3877 : PLUS_EXPR, sizetype,
3878 : array_type_nelts_minus_one (type),
3879 24301720 : size_one_node);
3880 : }
3881 :
3882 : /* If arg is static -- a reference to an object in static storage -- then
3883 : return the object. This is not the same as the C meaning of `static'.
3884 : If arg isn't static, return NULL. */
3885 :
3886 : tree
3887 1209264411 : staticp (tree arg)
3888 : {
3889 1210251994 : switch (TREE_CODE (arg))
3890 : {
3891 : case FUNCTION_DECL:
3892 : /* Nested functions are static, even though taking their address will
3893 : involve a trampoline as we unnest the nested function and create
3894 : the trampoline on the tree level. */
3895 : return arg;
3896 :
3897 728497919 : case VAR_DECL:
3898 575252345 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3899 198757758 : && ! DECL_THREAD_LOCAL_P (arg)
3900 196897176 : && ! DECL_DLLIMPORT_P (arg)
3901 728497919 : ? arg : NULL);
3902 :
3903 699743 : case CONST_DECL:
3904 70 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3905 699743 : ? arg : NULL);
3906 :
3907 0 : case CONSTRUCTOR:
3908 0 : return TREE_STATIC (arg) ? arg : NULL;
3909 :
3910 : case LABEL_DECL:
3911 : case STRING_CST:
3912 : return arg;
3913 :
3914 735307 : case COMPONENT_REF:
3915 : /* If the thing being referenced is not a field, then it is
3916 : something language specific. */
3917 735307 : gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL);
3918 :
3919 : /* If we are referencing a bitfield, we can't evaluate an
3920 : ADDR_EXPR at compile time and so it isn't a constant. */
3921 735307 : if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
3922 : return NULL;
3923 :
3924 735307 : return staticp (TREE_OPERAND (arg, 0));
3925 :
3926 : case BIT_FIELD_REF:
3927 : return NULL;
3928 :
3929 35031 : case INDIRECT_REF:
3930 35031 : return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
3931 :
3932 252188 : case ARRAY_REF:
3933 252188 : case ARRAY_RANGE_REF:
3934 252188 : if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
3935 252188 : && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
3936 251844 : return staticp (TREE_OPERAND (arg, 0));
3937 : else
3938 : return NULL;
3939 :
3940 432 : case REALPART_EXPR:
3941 432 : case IMAGPART_EXPR:
3942 432 : return staticp (TREE_OPERAND (arg, 0));
3943 :
3944 934 : case COMPOUND_LITERAL_EXPR:
3945 934 : return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;
3946 :
3947 : default:
3948 : return NULL;
3949 : }
3950 : }
3951 :
3952 :
3953 :
3954 :
3955 : /* Return whether OP is a DECL whose address is function-invariant. */
3956 :
3957 : bool
3958 5321895560 : decl_address_invariant_p (const_tree op)
3959 : {
3960 : /* The conditions below are slightly less strict than the one in
3961 : staticp. */
3962 :
3963 5321895560 : switch (TREE_CODE (op))
3964 : {
3965 : case PARM_DECL:
3966 : case RESULT_DECL:
3967 : case LABEL_DECL:
3968 : case FUNCTION_DECL:
3969 : return true;
3970 :
3971 2930935719 : case VAR_DECL:
3972 2227633594 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3973 2091665835 : || DECL_THREAD_LOCAL_P (op)
3974 2091665835 : || DECL_CONTEXT (op) == current_function_decl
3975 2938791388 : || decl_function_context (op) == current_function_decl)
3976 2923080050 : return true;
3977 : break;
3978 :
3979 25738704 : case CONST_DECL:
3980 0 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3981 25738704 : || decl_function_context (op) == current_function_decl)
3982 25738704 : return true;
3983 : break;
3984 :
3985 : default:
3986 : break;
3987 : }
3988 :
3989 : return false;
3990 : }
3991 :
3992 : /* Return whether OP is a DECL whose address is interprocedural-invariant. */
3993 :
3994 : bool
3995 1837418 : decl_address_ip_invariant_p (const_tree op)
3996 : {
3997 : /* The conditions below are slightly less strict than the one in
3998 : staticp. */
3999 :
4000 1837418 : symtab_node* node;
4001 1837418 : switch (TREE_CODE (op))
4002 : {
4003 : case LABEL_DECL:
4004 : case STRING_CST:
4005 : return true;
4006 :
4007 90797 : case FUNCTION_DECL:
4008 : /* Disable const propagation of symbols defined in assembly. */
4009 90797 : node = symtab_node::get (op);
4010 90797 : return !node || !node->must_remain_in_tu_name;
4011 :
4012 1642192 : case VAR_DECL:
4013 1642192 : if (TREE_STATIC (op) || DECL_EXTERNAL (op))
4014 : {
4015 : /* Disable const propagation of symbols defined in assembly. */
4016 479943 : node = symtab_node::get (op);
4017 479943 : if (node && node->must_remain_in_tu_name)
4018 : return false;
4019 : }
4020 1202143 : if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
4021 479941 : && !DECL_DLLIMPORT_P (op))
4022 2804439 : || DECL_THREAD_LOCAL_P (op))
4023 479941 : return true;
4024 : break;
4025 :
4026 52952 : case CONST_DECL:
4027 52952 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
4028 : return true;
4029 : break;
4030 :
4031 : default:
4032 : break;
4033 : }
4034 :
4035 : return false;
4036 : }
4037 :
4038 : /* Return true if T is an object with invariant address. */
4039 :
4040 : bool
4041 44900 : address_invariant_p (tree t)
4042 : {
4043 52830 : while (handled_component_p (t))
4044 : {
4045 8922 : switch (TREE_CODE (t))
4046 : {
4047 1472 : case ARRAY_REF:
4048 1472 : case ARRAY_RANGE_REF:
4049 1472 : if (!tree_invariant_p (TREE_OPERAND (t, 1))
4050 480 : || TREE_OPERAND (t, 2) != NULL_TREE
4051 1952 : || TREE_OPERAND (t, 3) != NULL_TREE)
4052 : return false;
4053 : break;
4054 :
4055 7291 : case COMPONENT_REF:
4056 7291 : if (TREE_OPERAND (t, 2) != NULL_TREE)
4057 : return false;
4058 : break;
4059 :
4060 : default:
4061 : break;
4062 : }
4063 7930 : t = TREE_OPERAND (t, 0);
4064 : }
4065 :
4066 43908 : STRIP_ANY_LOCATION_WRAPPER (t);
4067 43908 : return CONSTANT_CLASS_P (t) || decl_address_invariant_p (t);
4068 : }
4069 :
4070 :
4071 : /* Return true if T is function-invariant (internal function, does
4072 : not handle arithmetic; that's handled in skip_simple_arithmetic and
4073 : tree_invariant_p). */
4074 :
4075 : static bool
4076 16036307 : tree_invariant_p_1 (tree t)
4077 : {
4078 16036307 : if (TREE_CONSTANT (t) || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
4079 : return true;
4080 :
4081 13438712 : switch (TREE_CODE (t))
4082 : {
4083 : case SAVE_EXPR:
4084 : case TARGET_EXPR:
4085 : return true;
4086 :
4087 44848 : case ADDR_EXPR:
4088 44848 : return address_invariant_p (TREE_OPERAND (t, 0));
4089 :
4090 : default:
4091 : break;
4092 : }
4093 :
4094 : return false;
4095 : }
4096 :
4097 : /* Return true if T is function-invariant. */
4098 :
4099 : bool
4100 12581377 : tree_invariant_p (tree t)
4101 : {
4102 12581377 : tree inner = skip_simple_arithmetic (t);
4103 12581377 : return tree_invariant_p_1 (inner);
4104 : }
4105 :
4106 : /* Wrap a SAVE_EXPR around EXPR, if appropriate.
4107 : Do this to any expression which may be used in more than one place,
4108 : but must be evaluated only once.
4109 :
4110 : Normally, expand_expr would reevaluate the expression each time.
4111 : Calling save_expr produces something that is evaluated and recorded
4112 : the first time expand_expr is called on it. Subsequent calls to
4113 : expand_expr just reuse the recorded value.
4114 :
4115 : The call to expand_expr that generates code that actually computes
4116 : the value is the first call *at compile time*. Subsequent calls
4117 : *at compile time* generate code to use the saved value.
4118 : This produces correct result provided that *at run time* control
4119 : always flows through the insns made by the first expand_expr
4120 : before reaching the other places where the save_expr was evaluated.
4121 : You, the caller of save_expr, must make sure this is so.
4122 :
4123 : Constants, and certain read-only nodes, are returned with no
4124 : SAVE_EXPR because that is safe. Expressions containing placeholders
4125 : are not touched; see tree.def for an explanation of what these
4126 : are used for. */
4127 :
4128 : tree
4129 3454941 : save_expr (tree expr)
4130 : {
4131 3454941 : tree inner;
4132 :
4133 : /* If the tree evaluates to a constant, then we don't want to hide that
4134 : fact (i.e. this allows further folding, and direct checks for constants).
4135 : However, a read-only object that has side effects cannot be bypassed.
4136 : Since it is no problem to reevaluate literals, we just return the
4137 : literal node. */
4138 3454941 : inner = skip_simple_arithmetic (expr);
4139 3454941 : if (TREE_CODE (inner) == ERROR_MARK)
4140 : return inner;
4141 :
4142 3454930 : if (tree_invariant_p_1 (inner))
4143 : return expr;
4144 :
4145 : /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
4146 : it means that the size or offset of some field of an object depends on
4147 : the value within another field.
4148 :
4149 : Note that it must not be the case that EXPR contains both a PLACEHOLDER_EXPR
4150 : and some variable since it would then need to be both evaluated once and
4151 : evaluated more than once. Front-ends must assure this case cannot
4152 : happen by surrounding any such subexpressions in their own SAVE_EXPR
4153 : and forcing evaluation at the proper time. */
4154 2410039 : if (contains_placeholder_p (inner))
4155 : return expr;
4156 :
4157 2410039 : expr = build1_loc (EXPR_LOCATION (expr), SAVE_EXPR, TREE_TYPE (expr), expr);
4158 :
4159 : /* This expression might be placed ahead of a jump to ensure that the
4160 : value was computed on both sides of the jump. So make sure it isn't
4161 : eliminated as dead. */
4162 2410039 : TREE_SIDE_EFFECTS (expr) = 1;
4163 2410039 : return expr;
4164 : }
4165 :
4166 : /* Look inside EXPR into any simple arithmetic operations. Return the
4167 : outermost non-arithmetic or non-invariant node. */
4168 :
4169 : tree
4170 16036318 : skip_simple_arithmetic (tree expr)
4171 : {
4172 : /* We don't care about whether this can be used as an lvalue in this
4173 : context. */
4174 16052017 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4175 15699 : expr = TREE_OPERAND (expr, 0);
4176 :
4177 : /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
4178 : a constant, it will be more efficient to not make another SAVE_EXPR since
4179 : it will allow better simplification and GCSE will be able to merge the
4180 : computations if they actually occur. */
4181 40476341 : while (true)
4182 : {
4183 40476341 : if (UNARY_CLASS_P (expr))
4184 15276203 : expr = TREE_OPERAND (expr, 0);
4185 25200138 : else if (BINARY_CLASS_P (expr))
4186 : {
4187 : /* Before commutative binary operands are canonicalized,
4188 : it is quite common to have constants in the first operand.
4189 : Check for that common case first so that we don't walk
4190 : large expressions with tree_invariant_p unnecessarily.
4191 : This can still have terrible compile time complexity,
4192 : we should limit the depth of the tree_invariant_p and
4193 : skip_simple_arithmetic recursion. */
4194 9217334 : if ((TREE_CONSTANT (TREE_OPERAND (expr, 0))
4195 9206990 : || (TREE_READONLY (TREE_OPERAND (expr, 0))
4196 10121 : && !TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0))))
4197 9227419 : && tree_invariant_p (TREE_OPERAND (expr, 0)))
4198 20429 : expr = TREE_OPERAND (expr, 1);
4199 9196905 : else if (tree_invariant_p (TREE_OPERAND (expr, 1)))
4200 9133659 : expr = TREE_OPERAND (expr, 0);
4201 63246 : else if (tree_invariant_p (TREE_OPERAND (expr, 0)))
4202 9732 : expr = TREE_OPERAND (expr, 1);
4203 : else
4204 : break;
4205 : }
4206 : else
4207 : break;
4208 : }
4209 :
4210 16036318 : return expr;
4211 : }
4212 :
4213 : /* Look inside EXPR into simple arithmetic operations involving constants.
4214 : Return the outermost non-arithmetic or non-constant node. */
4215 :
4216 : tree
4217 0 : skip_simple_constant_arithmetic (tree expr)
4218 : {
4219 0 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4220 0 : expr = TREE_OPERAND (expr, 0);
4221 :
4222 0 : while (true)
4223 : {
4224 0 : if (UNARY_CLASS_P (expr))
4225 0 : expr = TREE_OPERAND (expr, 0);
4226 0 : else if (BINARY_CLASS_P (expr))
4227 : {
4228 0 : if (TREE_CONSTANT (TREE_OPERAND (expr, 1)))
4229 0 : expr = TREE_OPERAND (expr, 0);
4230 0 : else if (TREE_CONSTANT (TREE_OPERAND (expr, 0)))
4231 0 : expr = TREE_OPERAND (expr, 1);
4232 : else
4233 : break;
4234 : }
4235 : else
4236 : break;
4237 : }
4238 :
4239 0 : return expr;
4240 : }
4241 :
4242 : /* Return which tree structure is used by T. */
4243 :
4244 : enum tree_node_structure_enum
4245 44150730125 : tree_node_structure (const_tree t)
4246 : {
4247 44150730125 : const enum tree_code code = TREE_CODE (t);
4248 44150730125 : return tree_node_structure_for_code (code);
4249 : }
4250 :
4251 : /* Set various status flags when building a CALL_EXPR object T. */
4252 :
4253 : static void
4254 292153357 : process_call_operands (tree t)
4255 : {
4256 292153357 : bool side_effects = TREE_SIDE_EFFECTS (t);
4257 292153357 : bool read_only = false;
4258 292153357 : int i = call_expr_flags (t);
4259 :
4260 : /* Calls have side-effects, except those to const or pure functions. */
4261 292153357 : if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
4262 : side_effects = true;
4263 : /* Propagate TREE_READONLY of arguments for const functions. */
4264 60252028 : if (i & ECF_CONST)
4265 58639596 : read_only = true;
4266 :
4267 292153357 : if (!side_effects || read_only)
4268 300398702 : for (i = 1; i < TREE_OPERAND_LENGTH (t); i++)
4269 : {
4270 240147178 : tree op = TREE_OPERAND (t, i);
4271 240147178 : if (op && TREE_SIDE_EFFECTS (op))
4272 : side_effects = true;
4273 240147178 : if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op))
4274 : read_only = false;
4275 : }
4276 :
4277 292153357 : TREE_SIDE_EFFECTS (t) = side_effects;
4278 292153357 : TREE_READONLY (t) = read_only;
4279 292153357 : }
4280 :
4281 : /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
4282 : size or offset that depends on a field within a record. */
4283 :
4284 : bool
4285 38865186 : contains_placeholder_p (const_tree exp)
4286 : {
4287 38865186 : enum tree_code code;
4288 :
4289 38865186 : if (!exp)
4290 : return false;
4291 :
4292 38865186 : code = TREE_CODE (exp);
4293 38865186 : if (code == PLACEHOLDER_EXPR)
4294 : return true;
4295 :
4296 38865186 : switch (TREE_CODE_CLASS (code))
4297 : {
4298 1166449 : case tcc_reference:
4299 : /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
4300 : position computations since they will be converted into a
4301 : WITH_RECORD_EXPR involving the reference, which will assume
4302 : here will be valid. */
4303 1166449 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4304 :
4305 581264 : case tcc_exceptional:
4306 581264 : if (code == TREE_LIST)
4307 0 : return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
4308 0 : || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
4309 : break;
4310 :
4311 33747515 : case tcc_unary:
4312 33747515 : case tcc_binary:
4313 33747515 : case tcc_comparison:
4314 33747515 : case tcc_expression:
4315 33747515 : switch (code)
4316 : {
4317 7297 : case COMPOUND_EXPR:
4318 : /* Ignoring the first operand isn't quite right, but works best. */
4319 7297 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
4320 :
4321 4530 : case COND_EXPR:
4322 9060 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4323 4530 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
4324 9060 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
4325 :
4326 : case SAVE_EXPR:
4327 : /* The save_expr function never wraps anything containing
4328 : a PLACEHOLDER_EXPR. */
4329 : return false;
4330 :
4331 24565665 : default:
4332 24565665 : break;
4333 : }
4334 :
4335 24565665 : switch (TREE_CODE_LENGTH (code))
4336 : {
4337 14965471 : case 1:
4338 14965471 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4339 9502736 : case 2:
4340 19003933 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4341 19003933 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
4342 : default:
4343 : return false;
4344 : }
4345 :
4346 811834 : case tcc_vl_exp:
4347 811834 : switch (code)
4348 : {
4349 811834 : case CALL_EXPR:
4350 811834 : {
4351 811834 : const_tree arg;
4352 811834 : const_call_expr_arg_iterator iter;
4353 2825205 : FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
4354 1201537 : if (CONTAINS_PLACEHOLDER_P (arg))
4355 : return true;
4356 : return false;
4357 : }
4358 : default:
4359 : return false;
4360 : }
4361 :
4362 : default:
4363 : return false;
4364 : }
4365 : return false;
4366 : }
4367 :
4368 : /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
4369 : directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
4370 : field positions. */
4371 :
4372 : static bool
4373 807155 : type_contains_placeholder_1 (const_tree type)
4374 : {
4375 : /* If the size contains a placeholder or the parent type (component type in
4376 : the case of arrays) type involves a placeholder, this type does. */
4377 1593201 : if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
4378 807155 : || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
4379 1614310 : || (!POINTER_TYPE_P (type)
4380 669022 : && TREE_TYPE (type)
4381 116043 : && type_contains_placeholder_p (TREE_TYPE (type))))
4382 0 : return true;
4383 :
4384 : /* Now do type-specific checks. Note that the last part of the check above
4385 : greatly limits what we have to do below. */
4386 807155 : switch (TREE_CODE (type))
4387 : {
4388 : case VOID_TYPE:
4389 : case OPAQUE_TYPE:
4390 : case COMPLEX_TYPE:
4391 : case ENUMERAL_TYPE:
4392 : case BOOLEAN_TYPE:
4393 : case POINTER_TYPE:
4394 : case OFFSET_TYPE:
4395 : case REFERENCE_TYPE:
4396 : case METHOD_TYPE:
4397 : case FUNCTION_TYPE:
4398 : case VECTOR_TYPE:
4399 : case NULLPTR_TYPE:
4400 : return false;
4401 :
4402 181171 : case INTEGER_TYPE:
4403 181171 : case BITINT_TYPE:
4404 181171 : case REAL_TYPE:
4405 181171 : case FIXED_POINT_TYPE:
4406 : /* Here we just check the bounds. */
4407 352599 : return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
4408 352599 : || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
4409 :
4410 57819 : case ARRAY_TYPE:
4411 : /* We have already checked the component type above, so just check
4412 : the domain type. Flexible array members have a null domain. */
4413 115626 : return TYPE_DOMAIN (type) ?
4414 57807 : type_contains_placeholder_p (TYPE_DOMAIN (type)) : false;
4415 :
4416 405680 : case RECORD_TYPE:
4417 405680 : case UNION_TYPE:
4418 405680 : case QUAL_UNION_TYPE:
4419 405680 : {
4420 405680 : tree field;
4421 :
4422 11930302 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
4423 11524622 : if (TREE_CODE (field) == FIELD_DECL
4424 11524622 : && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
4425 943560 : || (TREE_CODE (type) == QUAL_UNION_TYPE
4426 0 : && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
4427 943560 : || type_contains_placeholder_p (TREE_TYPE (field))))
4428 0 : return true;
4429 :
4430 : return false;
4431 : }
4432 :
4433 0 : default:
4434 0 : gcc_unreachable ();
4435 : }
4436 : }
4437 :
4438 : /* Wrapper around above function used to cache its result. */
4439 :
4440 : bool
4441 3004745 : type_contains_placeholder_p (tree type)
4442 : {
4443 3004745 : bool result;
4444 :
4445 : /* If the contains_placeholder_bits field has been initialized,
4446 : then we know the answer. */
4447 3004745 : if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
4448 2197590 : return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
4449 :
4450 : /* Indicate that we've seen this type node, and the answer is false.
4451 : This is what we want to return if we run into recursion via fields. */
4452 807155 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
4453 :
4454 : /* Compute the real value. */
4455 807155 : result = type_contains_placeholder_1 (type);
4456 :
4457 : /* Store the real value. */
4458 807155 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
4459 :
4460 807155 : return result;
4461 : }
4462 :
4463 : /* Push tree EXP onto vector QUEUE if it is not already present. */
4464 :
4465 : static void
4466 0 : push_without_duplicates (tree exp, vec<tree> *queue)
4467 : {
4468 0 : unsigned int i;
4469 0 : tree iter;
4470 :
4471 0 : FOR_EACH_VEC_ELT (*queue, i, iter)
4472 0 : if (simple_cst_equal (iter, exp) == 1)
4473 : break;
4474 :
4475 0 : if (!iter)
4476 0 : queue->safe_push (exp);
4477 0 : }
4478 :
4479 : /* Given a tree EXP, find all occurrences of references to fields
4480 : in a PLACEHOLDER_EXPR and place them in vector REFS without
4481 : duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
4482 : we assume here that EXP contains only arithmetic expressions
4483 : or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
4484 : argument list. */
4485 :
4486 : void
4487 0 : find_placeholder_in_expr (tree exp, vec<tree> *refs)
4488 : {
4489 0 : enum tree_code code = TREE_CODE (exp);
4490 0 : tree inner;
4491 0 : int i;
4492 :
4493 : /* We handle TREE_LIST and COMPONENT_REF separately. */
4494 0 : if (code == TREE_LIST)
4495 : {
4496 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs);
4497 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs);
4498 : }
4499 0 : else if (code == COMPONENT_REF)
4500 : {
4501 0 : for (inner = TREE_OPERAND (exp, 0);
4502 0 : REFERENCE_CLASS_P (inner);
4503 0 : inner = TREE_OPERAND (inner, 0))
4504 : ;
4505 :
4506 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
4507 0 : push_without_duplicates (exp, refs);
4508 : else
4509 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs);
4510 : }
4511 : else
4512 0 : switch (TREE_CODE_CLASS (code))
4513 : {
4514 : case tcc_constant:
4515 : break;
4516 :
4517 0 : case tcc_declaration:
4518 : /* Variables allocated to static storage can stay. */
4519 0 : if (!TREE_STATIC (exp))
4520 0 : push_without_duplicates (exp, refs);
4521 : break;
4522 :
4523 0 : case tcc_expression:
4524 : /* This is the pattern built in ada/make_aligning_type. */
4525 0 : if (code == ADDR_EXPR
4526 0 : && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR)
4527 : {
4528 0 : push_without_duplicates (exp, refs);
4529 0 : break;
4530 : }
4531 :
4532 : /* Fall through. */
4533 :
4534 : case tcc_exceptional:
4535 : case tcc_unary:
4536 : case tcc_binary:
4537 : case tcc_comparison:
4538 : case tcc_reference:
4539 0 : for (i = 0; i < TREE_CODE_LENGTH (code); i++)
4540 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4541 : break;
4542 :
4543 : case tcc_vl_exp:
4544 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4545 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4546 : break;
4547 :
4548 0 : default:
4549 0 : gcc_unreachable ();
4550 : }
4551 0 : }
4552 :
4553 : /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
4554 : return a tree with all occurrences of references to F in a
4555 : PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
4556 : CONST_DECLs. Note that we assume here that EXP contains only
4557 : arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
4558 : occurring only in their argument list. */
4559 :
4560 : tree
4561 0 : substitute_in_expr (tree exp, tree f, tree r)
4562 : {
4563 0 : enum tree_code code = TREE_CODE (exp);
4564 0 : tree op0, op1, op2, op3;
4565 0 : tree new_tree;
4566 :
4567 : /* We handle TREE_LIST and COMPONENT_REF separately. */
4568 0 : if (code == TREE_LIST)
4569 : {
4570 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
4571 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
4572 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4573 : return exp;
4574 :
4575 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4576 : }
4577 0 : else if (code == COMPONENT_REF)
4578 : {
4579 0 : tree inner;
4580 :
4581 : /* If this expression is getting a value from a PLACEHOLDER_EXPR
4582 : and it is the right field, replace it with R. */
4583 0 : for (inner = TREE_OPERAND (exp, 0);
4584 0 : REFERENCE_CLASS_P (inner);
4585 0 : inner = TREE_OPERAND (inner, 0))
4586 : ;
4587 :
4588 : /* The field. */
4589 0 : op1 = TREE_OPERAND (exp, 1);
4590 :
4591 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f)
4592 : return r;
4593 :
4594 : /* If this expression hasn't been completed let, leave it alone. */
4595 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner))
4596 : return exp;
4597 :
4598 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4599 0 : if (op0 == TREE_OPERAND (exp, 0))
4600 : return exp;
4601 :
4602 0 : new_tree
4603 0 : = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE);
4604 : }
4605 : else
4606 0 : switch (TREE_CODE_CLASS (code))
4607 : {
4608 : case tcc_constant:
4609 : return exp;
4610 :
4611 0 : case tcc_declaration:
4612 0 : if (exp == f)
4613 : return r;
4614 : else
4615 : return exp;
4616 :
4617 0 : case tcc_expression:
4618 0 : if (exp == f)
4619 : return r;
4620 :
4621 : /* Fall through. */
4622 :
4623 0 : case tcc_exceptional:
4624 0 : case tcc_unary:
4625 0 : case tcc_binary:
4626 0 : case tcc_comparison:
4627 0 : case tcc_reference:
4628 0 : switch (TREE_CODE_LENGTH (code))
4629 : {
4630 : case 0:
4631 : return exp;
4632 :
4633 0 : case 1:
4634 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4635 0 : if (op0 == TREE_OPERAND (exp, 0))
4636 : return exp;
4637 :
4638 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4639 0 : break;
4640 :
4641 0 : case 2:
4642 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4643 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4644 :
4645 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4646 : return exp;
4647 :
4648 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4649 0 : break;
4650 :
4651 0 : case 3:
4652 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4653 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4654 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4655 :
4656 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4657 0 : && op2 == TREE_OPERAND (exp, 2))
4658 : return exp;
4659 :
4660 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4661 0 : break;
4662 :
4663 0 : case 4:
4664 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4665 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4666 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4667 0 : op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
4668 :
4669 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4670 0 : && op2 == TREE_OPERAND (exp, 2)
4671 0 : && op3 == TREE_OPERAND (exp, 3))
4672 : return exp;
4673 :
4674 0 : new_tree
4675 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4676 0 : break;
4677 :
4678 0 : default:
4679 0 : gcc_unreachable ();
4680 : }
4681 : break;
4682 :
4683 0 : case tcc_vl_exp:
4684 0 : {
4685 0 : int i;
4686 :
4687 0 : new_tree = NULL_TREE;
4688 :
4689 : /* If we are trying to replace F with a constant or with another
4690 : instance of one of the arguments of the call, inline back
4691 : functions which do nothing else than computing a value from
4692 : the arguments they are passed. This makes it possible to
4693 : fold partially or entirely the replacement expression. */
4694 0 : if (code == CALL_EXPR)
4695 : {
4696 0 : bool maybe_inline = false;
4697 0 : if (CONSTANT_CLASS_P (r))
4698 : maybe_inline = true;
4699 : else
4700 0 : for (i = 3; i < TREE_OPERAND_LENGTH (exp); i++)
4701 0 : if (operand_equal_p (TREE_OPERAND (exp, i), r, 0))
4702 : {
4703 : maybe_inline = true;
4704 : break;
4705 : }
4706 0 : if (maybe_inline)
4707 : {
4708 0 : tree t = maybe_inline_call_in_expr (exp);
4709 0 : if (t)
4710 0 : return SUBSTITUTE_IN_EXPR (t, f, r);
4711 : }
4712 : }
4713 :
4714 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4715 : {
4716 0 : tree op = TREE_OPERAND (exp, i);
4717 0 : tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
4718 0 : if (new_op != op)
4719 : {
4720 0 : if (!new_tree)
4721 0 : new_tree = copy_node (exp);
4722 0 : TREE_OPERAND (new_tree, i) = new_op;
4723 : }
4724 : }
4725 :
4726 0 : if (new_tree)
4727 : {
4728 0 : new_tree = fold (new_tree);
4729 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4730 0 : process_call_operands (new_tree);
4731 : }
4732 : else
4733 : return exp;
4734 : }
4735 : break;
4736 :
4737 0 : default:
4738 0 : gcc_unreachable ();
4739 : }
4740 :
4741 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4742 :
4743 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4744 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4745 :
4746 : return new_tree;
4747 : }
4748 :
4749 : /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
4750 : for it within OBJ, a tree that is an object or a chain of references. */
4751 :
4752 : tree
4753 243556 : substitute_placeholder_in_expr (tree exp, tree obj)
4754 : {
4755 243556 : enum tree_code code = TREE_CODE (exp);
4756 243556 : tree op0, op1, op2, op3;
4757 243556 : tree new_tree;
4758 :
4759 : /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
4760 : in the chain of OBJ. */
4761 243556 : if (code == PLACEHOLDER_EXPR)
4762 : {
4763 0 : tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
4764 0 : tree elt;
4765 :
4766 0 : for (elt = obj; elt != 0;
4767 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4768 0 : || TREE_CODE (elt) == COND_EXPR)
4769 0 : ? TREE_OPERAND (elt, 1)
4770 0 : : (REFERENCE_CLASS_P (elt)
4771 : || UNARY_CLASS_P (elt)
4772 : || BINARY_CLASS_P (elt)
4773 : || VL_EXP_CLASS_P (elt)
4774 : || EXPRESSION_CLASS_P (elt))
4775 0 : ? TREE_OPERAND (elt, 0) : 0))
4776 0 : if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
4777 : return elt;
4778 :
4779 0 : for (elt = obj; elt != 0;
4780 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4781 0 : || TREE_CODE (elt) == COND_EXPR)
4782 0 : ? TREE_OPERAND (elt, 1)
4783 0 : : (REFERENCE_CLASS_P (elt)
4784 : || UNARY_CLASS_P (elt)
4785 : || BINARY_CLASS_P (elt)
4786 : || VL_EXP_CLASS_P (elt)
4787 : || EXPRESSION_CLASS_P (elt))
4788 0 : ? TREE_OPERAND (elt, 0) : 0))
4789 0 : if (POINTER_TYPE_P (TREE_TYPE (elt))
4790 0 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
4791 : == need_type))
4792 0 : return fold_build1 (INDIRECT_REF, need_type, elt);
4793 :
4794 : /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
4795 : survives until RTL generation, there will be an error. */
4796 : return exp;
4797 : }
4798 :
4799 : /* TREE_LIST is special because we need to look at TREE_VALUE
4800 : and TREE_CHAIN, not TREE_OPERANDS. */
4801 243556 : else if (code == TREE_LIST)
4802 : {
4803 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
4804 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
4805 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4806 : return exp;
4807 :
4808 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4809 : }
4810 : else
4811 243556 : switch (TREE_CODE_CLASS (code))
4812 : {
4813 : case tcc_constant:
4814 : case tcc_declaration:
4815 : return exp;
4816 :
4817 9742 : case tcc_exceptional:
4818 9742 : case tcc_unary:
4819 9742 : case tcc_binary:
4820 9742 : case tcc_comparison:
4821 9742 : case tcc_expression:
4822 9742 : case tcc_reference:
4823 9742 : case tcc_statement:
4824 9742 : switch (TREE_CODE_LENGTH (code))
4825 : {
4826 : case 0:
4827 : return exp;
4828 :
4829 7419 : case 1:
4830 7419 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4831 7419 : if (op0 == TREE_OPERAND (exp, 0))
4832 : return exp;
4833 :
4834 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4835 0 : break;
4836 :
4837 2311 : case 2:
4838 2311 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4839 2311 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4840 :
4841 2311 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4842 : return exp;
4843 :
4844 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4845 0 : break;
4846 :
4847 12 : case 3:
4848 12 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4849 12 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4850 12 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4851 :
4852 24 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4853 24 : && op2 == TREE_OPERAND (exp, 2))
4854 : return exp;
4855 :
4856 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4857 0 : break;
4858 :
4859 0 : case 4:
4860 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4861 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4862 0 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4863 0 : op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
4864 :
4865 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4866 0 : && op2 == TREE_OPERAND (exp, 2)
4867 0 : && op3 == TREE_OPERAND (exp, 3))
4868 : return exp;
4869 :
4870 0 : new_tree
4871 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4872 0 : break;
4873 :
4874 0 : default:
4875 0 : gcc_unreachable ();
4876 : }
4877 : break;
4878 :
4879 : case tcc_vl_exp:
4880 : {
4881 : int i;
4882 :
4883 : new_tree = NULL_TREE;
4884 :
4885 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4886 : {
4887 0 : tree op = TREE_OPERAND (exp, i);
4888 0 : tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
4889 0 : if (new_op != op)
4890 : {
4891 0 : if (!new_tree)
4892 0 : new_tree = copy_node (exp);
4893 0 : TREE_OPERAND (new_tree, i) = new_op;
4894 : }
4895 : }
4896 :
4897 0 : if (new_tree)
4898 : {
4899 0 : new_tree = fold (new_tree);
4900 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4901 0 : process_call_operands (new_tree);
4902 : }
4903 : else
4904 : return exp;
4905 : }
4906 : break;
4907 :
4908 0 : default:
4909 0 : gcc_unreachable ();
4910 : }
4911 :
4912 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4913 :
4914 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4915 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4916 :
4917 : return new_tree;
4918 : }
4919 :
4920 :
4921 : /* Subroutine of stabilize_reference; this is called for subtrees of
4922 : references. Any expression with side-effects must be put in a SAVE_EXPR
4923 : to ensure that it is only evaluated once.
4924 :
4925 : We don't put SAVE_EXPR nodes around everything, because assigning very
4926 : simple expressions to temporaries causes us to miss good opportunities
4927 : for optimizations. Among other things, the opportunity to fold in the
4928 : addition of a constant into an addressing mode often gets lost, e.g.
4929 : "y[i+1] += x;". In general, we take the approach that we should not make
4930 : an assignment unless we are forced into it - i.e., that any non-side effect
4931 : operator should be allowed, and that cse should take care of coalescing
4932 : multiple utterances of the same expression should that prove fruitful. */
4933 :
4934 : static tree
4935 904927 : stabilize_reference_1 (tree e)
4936 : {
4937 904927 : tree result;
4938 904927 : enum tree_code code = TREE_CODE (e);
4939 :
4940 : /* We cannot ignore const expressions because it might be a reference
4941 : to a const array but whose index contains side-effects. But we can
4942 : ignore things that are actual constant or that already have been
4943 : handled by this function. */
4944 :
4945 904927 : if (tree_invariant_p (e))
4946 : return e;
4947 :
4948 134125 : switch (TREE_CODE_CLASS (code))
4949 : {
4950 0 : case tcc_exceptional:
4951 : /* Always wrap STATEMENT_LIST into SAVE_EXPR, even if it doesn't
4952 : have side-effects. */
4953 0 : if (code == STATEMENT_LIST)
4954 0 : return save_expr (e);
4955 : /* FALLTHRU */
4956 104462 : case tcc_type:
4957 104462 : case tcc_declaration:
4958 104462 : case tcc_comparison:
4959 104462 : case tcc_statement:
4960 104462 : case tcc_expression:
4961 104462 : case tcc_reference:
4962 104462 : case tcc_vl_exp:
4963 : /* If the expression has side-effects, then encase it in a SAVE_EXPR
4964 : so that it will only be evaluated once. */
4965 : /* The reference (r) and comparison (<) classes could be handled as
4966 : below, but it is generally faster to only evaluate them once. */
4967 104462 : if (TREE_SIDE_EFFECTS (e))
4968 1014 : return save_expr (e);
4969 : return e;
4970 :
4971 : case tcc_constant:
4972 : /* Constants need no processing. In fact, we should never reach
4973 : here. */
4974 : return e;
4975 :
4976 21941 : case tcc_binary:
4977 : /* Division is slow and tends to be compiled with jumps,
4978 : especially the division by powers of 2 that is often
4979 : found inside of an array reference. So do it just once. */
4980 21941 : if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
4981 19901 : || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
4982 19901 : || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
4983 19901 : || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
4984 2040 : return save_expr (e);
4985 : /* Recursively stabilize each operand. */
4986 19901 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
4987 19901 : stabilize_reference_1 (TREE_OPERAND (e, 1)));
4988 19901 : break;
4989 :
4990 7722 : case tcc_unary:
4991 : /* Recursively stabilize each operand. */
4992 7722 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
4993 7722 : break;
4994 :
4995 0 : default:
4996 0 : gcc_unreachable ();
4997 : }
4998 :
4999 27623 : TREE_TYPE (result) = TREE_TYPE (e);
5000 27623 : TREE_READONLY (result) = TREE_READONLY (e);
5001 27623 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
5002 27623 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
5003 :
5004 27623 : return result;
5005 : }
5006 :
5007 : /* Stabilize a reference so that we can use it any number of times
5008 : without causing its operands to be evaluated more than once.
5009 : Returns the stabilized reference. This works by means of save_expr,
5010 : so see the caveats in the comments about save_expr.
5011 :
5012 : Also allows conversion expressions whose operands are references.
5013 : Any other kind of expression is returned unchanged. */
5014 :
5015 : tree
5016 4878867 : stabilize_reference (tree ref)
5017 : {
5018 4878867 : tree result;
5019 4878867 : enum tree_code code = TREE_CODE (ref);
5020 :
5021 4878867 : switch (code)
5022 : {
5023 : case VAR_DECL:
5024 : case PARM_DECL:
5025 : case RESULT_DECL:
5026 : /* No action is needed in this case. */
5027 : return ref;
5028 :
5029 0 : CASE_CONVERT:
5030 0 : case FLOAT_EXPR:
5031 0 : case FIX_TRUNC_EXPR:
5032 0 : result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
5033 0 : break;
5034 :
5035 810479 : case INDIRECT_REF:
5036 810479 : result = build_nt (INDIRECT_REF,
5037 810479 : stabilize_reference_1 (TREE_OPERAND (ref, 0)));
5038 810479 : break;
5039 :
5040 469804 : case COMPONENT_REF:
5041 469804 : result = build_nt (COMPONENT_REF,
5042 469804 : stabilize_reference (TREE_OPERAND (ref, 0)),
5043 469804 : TREE_OPERAND (ref, 1), NULL_TREE);
5044 469804 : break;
5045 :
5046 0 : case BIT_FIELD_REF:
5047 0 : result = build_nt (BIT_FIELD_REF,
5048 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5049 0 : TREE_OPERAND (ref, 1), TREE_OPERAND (ref, 2));
5050 0 : REF_REVERSE_STORAGE_ORDER (result) = REF_REVERSE_STORAGE_ORDER (ref);
5051 0 : break;
5052 :
5053 46924 : case ARRAY_REF:
5054 93848 : result = build_nt (ARRAY_REF,
5055 46924 : stabilize_reference (TREE_OPERAND (ref, 0)),
5056 46924 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5057 46924 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5058 46924 : break;
5059 :
5060 0 : case ARRAY_RANGE_REF:
5061 0 : result = build_nt (ARRAY_RANGE_REF,
5062 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5063 0 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5064 0 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5065 0 : break;
5066 :
5067 0 : case COMPOUND_EXPR:
5068 : /* We cannot wrap the first expression in a SAVE_EXPR, as then
5069 : it wouldn't be ignored. This matters when dealing with
5070 : volatiles. */
5071 0 : return stabilize_reference_1 (ref);
5072 :
5073 : /* If arg isn't a kind of lvalue we recognize, make no change.
5074 : Caller should recognize the error for an invalid lvalue. */
5075 : default:
5076 : return ref;
5077 :
5078 0 : case ERROR_MARK:
5079 0 : return error_mark_node;
5080 : }
5081 :
5082 1327207 : TREE_TYPE (result) = TREE_TYPE (ref);
5083 1327207 : TREE_READONLY (result) = TREE_READONLY (ref);
5084 1327207 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
5085 1327207 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
5086 1327207 : protected_set_expr_location (result, EXPR_LOCATION (ref));
5087 :
5088 1327207 : return result;
5089 : }
5090 :
5091 : /* Low-level constructors for expressions. */
5092 :
5093 : /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
5094 : and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
5095 :
5096 : void
5097 1427766961 : recompute_tree_invariant_for_addr_expr (tree t)
5098 : {
5099 1427766961 : tree node;
5100 1427766961 : bool tc = true, se = false;
5101 :
5102 1427766961 : gcc_assert (TREE_CODE (t) == ADDR_EXPR);
5103 :
5104 : /* We started out assuming this address is both invariant and constant, but
5105 : does not have side effects. Now go down any handled components and see if
5106 : any of them involve offsets that are either non-constant or non-invariant.
5107 : Also check for side-effects.
5108 :
5109 : ??? Note that this code makes no attempt to deal with the case where
5110 : taking the address of something causes a copy due to misalignment. */
5111 :
5112 : #define UPDATE_FLAGS(NODE) \
5113 : do { tree _node = (NODE); \
5114 : if (_node && !TREE_CONSTANT (_node)) tc = false; \
5115 : if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
5116 :
5117 1673723742 : for (node = TREE_OPERAND (t, 0); handled_component_p (node);
5118 245956781 : node = TREE_OPERAND (node, 0))
5119 : {
5120 : /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
5121 : array reference (probably made temporarily by the G++ front end),
5122 : so ignore all the operands. */
5123 245956781 : if ((TREE_CODE (node) == ARRAY_REF
5124 245956781 : || TREE_CODE (node) == ARRAY_RANGE_REF)
5125 245956781 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
5126 : {
5127 34451255 : UPDATE_FLAGS (TREE_OPERAND (node, 1));
5128 34451255 : if (TREE_OPERAND (node, 2))
5129 2353555 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5130 34451255 : if (TREE_OPERAND (node, 3))
5131 274118 : UPDATE_FLAGS (TREE_OPERAND (node, 3));
5132 : }
5133 : /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
5134 : FIELD_DECL, apparently. The G++ front end can put something else
5135 : there, at least temporarily. */
5136 211505526 : else if (TREE_CODE (node) == COMPONENT_REF
5137 211505526 : && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
5138 : {
5139 210287697 : if (TREE_OPERAND (node, 2))
5140 17035 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5141 : }
5142 : }
5143 :
5144 1427766961 : node = lang_hooks.expr_to_decl (node, &tc, &se);
5145 :
5146 : /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
5147 : the address, since &(*a)->b is a form of addition. If it's a constant, the
5148 : address is constant too. If it's a decl, its address is constant if the
5149 : decl is static. Everything else is not constant and, furthermore,
5150 : taking the address of a volatile variable is not volatile. */
5151 1427766961 : if (INDIRECT_REF_P (node)
5152 1388199481 : || TREE_CODE (node) == MEM_REF)
5153 164245758 : UPDATE_FLAGS (TREE_OPERAND (node, 0));
5154 1263521203 : else if (CONSTANT_CLASS_P (node))
5155 : ;
5156 1181723240 : else if (DECL_P (node))
5157 1157207149 : tc &= (staticp (node) != NULL_TREE);
5158 : else
5159 : {
5160 24516091 : tc = false;
5161 24516091 : se |= TREE_SIDE_EFFECTS (node);
5162 : }
5163 :
5164 :
5165 1427766961 : TREE_CONSTANT (t) = tc;
5166 1427766961 : TREE_SIDE_EFFECTS (t) = se;
5167 : #undef UPDATE_FLAGS
5168 1427766961 : }
5169 :
5170 : /* Build an expression of code CODE, data type TYPE, and operands as
5171 : specified. Expressions and reference nodes can be created this way.
5172 : Constants, decls, types and misc nodes cannot be.
5173 :
5174 : We define 5 non-variadic functions, from 0 to 4 arguments. This is
5175 : enough for all extant tree codes. */
5176 :
5177 : tree
5178 401691473 : build0 (enum tree_code code, tree tt MEM_STAT_DECL)
5179 : {
5180 401691473 : tree t;
5181 :
5182 401691473 : gcc_assert (TREE_CODE_LENGTH (code) == 0);
5183 :
5184 401691473 : t = make_node (code PASS_MEM_STAT);
5185 401691473 : TREE_TYPE (t) = tt;
5186 :
5187 401691473 : return t;
5188 : }
5189 :
5190 : tree
5191 4086668222 : build1 (enum tree_code code, tree type, tree node MEM_STAT_DECL)
5192 : {
5193 4086668222 : int length = sizeof (struct tree_exp);
5194 4086668222 : tree t;
5195 :
5196 4086668222 : record_node_allocation_statistics (code, length);
5197 :
5198 4086668222 : gcc_assert (TREE_CODE_LENGTH (code) == 1);
5199 :
5200 4086668222 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
5201 :
5202 4086668222 : memset (t, 0, sizeof (struct tree_common));
5203 :
5204 4086668222 : TREE_SET_CODE (t, code);
5205 :
5206 4086668222 : TREE_TYPE (t) = type;
5207 4086668222 : SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
5208 4086668222 : TREE_OPERAND (t, 0) = node;
5209 4086668222 : if (node && !TYPE_P (node))
5210 : {
5211 4086604007 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
5212 4086604007 : TREE_READONLY (t) = TREE_READONLY (node);
5213 : }
5214 :
5215 4086668222 : if (TREE_CODE_CLASS (code) == tcc_statement)
5216 : {
5217 24322216 : if (code != DEBUG_BEGIN_STMT)
5218 24322216 : TREE_SIDE_EFFECTS (t) = 1;
5219 : }
5220 4062346006 : else switch (code)
5221 : {
5222 51146 : case VA_ARG_EXPR:
5223 : /* All of these have side-effects, no matter what their
5224 : operands are. */
5225 51146 : TREE_SIDE_EFFECTS (t) = 1;
5226 51146 : TREE_READONLY (t) = 0;
5227 51146 : break;
5228 :
5229 642301855 : case INDIRECT_REF:
5230 : /* Whether a dereference is readonly has nothing to do with whether
5231 : its operand is readonly. */
5232 642301855 : TREE_READONLY (t) = 0;
5233 642301855 : break;
5234 :
5235 673636638 : case ADDR_EXPR:
5236 673636638 : if (node)
5237 673636638 : recompute_tree_invariant_for_addr_expr (t);
5238 : break;
5239 :
5240 2746356367 : default:
5241 1018037178 : if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
5242 2597556014 : && node && !TYPE_P (node)
5243 5343912381 : && TREE_CONSTANT (node))
5244 721166341 : TREE_CONSTANT (t) = 1;
5245 2746356367 : if (TREE_CODE_CLASS (code) == tcc_reference
5246 871997954 : && node && TREE_THIS_VOLATILE (node))
5247 2999297 : TREE_THIS_VOLATILE (t) = 1;
5248 : break;
5249 : }
5250 :
5251 4086668222 : return t;
5252 : }
5253 :
5254 : #define PROCESS_ARG(N) \
5255 : do { \
5256 : TREE_OPERAND (t, N) = arg##N; \
5257 : if (arg##N &&!TYPE_P (arg##N)) \
5258 : { \
5259 : if (TREE_SIDE_EFFECTS (arg##N)) \
5260 : side_effects = 1; \
5261 : if (!TREE_READONLY (arg##N) \
5262 : && !CONSTANT_CLASS_P (arg##N)) \
5263 : (void) (read_only = 0); \
5264 : if (!TREE_CONSTANT (arg##N)) \
5265 : (void) (constant = 0); \
5266 : } \
5267 : } while (0)
5268 :
5269 : tree
5270 1311321916 : build2 (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
5271 : {
5272 1311321916 : bool constant, read_only, side_effects, div_by_zero;
5273 1311321916 : tree t;
5274 :
5275 1311321916 : gcc_assert (TREE_CODE_LENGTH (code) == 2);
5276 :
5277 1311321916 : if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
5278 195178036 : && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
5279 : /* When sizetype precision doesn't match that of pointers
5280 : we need to be able to build explicit extensions or truncations
5281 : of the offset argument. */
5282 1311321916 : && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
5283 0 : gcc_assert (TREE_CODE (arg0) == INTEGER_CST
5284 : && TREE_CODE (arg1) == INTEGER_CST);
5285 :
5286 1311321916 : if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
5287 60433262 : gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
5288 : && ptrofftype_p (TREE_TYPE (arg1)));
5289 :
5290 1311321916 : t = make_node (code PASS_MEM_STAT);
5291 1311321916 : TREE_TYPE (t) = tt;
5292 :
5293 : /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
5294 : result based on those same flags for the arguments. But if the
5295 : arguments aren't really even `tree' expressions, we shouldn't be trying
5296 : to do this. */
5297 :
5298 : /* Expressions without side effects may be constant if their
5299 : arguments are as well. */
5300 2622643832 : constant = (TREE_CODE_CLASS (code) == tcc_comparison
5301 1311321916 : || TREE_CODE_CLASS (code) == tcc_binary);
5302 1311321916 : read_only = 1;
5303 1311321916 : side_effects = TREE_SIDE_EFFECTS (t);
5304 :
5305 1311321916 : switch (code)
5306 : {
5307 14605474 : case TRUNC_DIV_EXPR:
5308 14605474 : case CEIL_DIV_EXPR:
5309 14605474 : case FLOOR_DIV_EXPR:
5310 14605474 : case ROUND_DIV_EXPR:
5311 14605474 : case EXACT_DIV_EXPR:
5312 14605474 : case CEIL_MOD_EXPR:
5313 14605474 : case FLOOR_MOD_EXPR:
5314 14605474 : case ROUND_MOD_EXPR:
5315 14605474 : case TRUNC_MOD_EXPR:
5316 14605474 : div_by_zero = integer_zerop (arg1);
5317 14605474 : break;
5318 : default:
5319 : div_by_zero = false;
5320 : }
5321 :
5322 1450144678 : PROCESS_ARG (0);
5323 1846582020 : PROCESS_ARG (1);
5324 :
5325 1311321916 : TREE_SIDE_EFFECTS (t) = side_effects;
5326 1311321916 : if (code == MEM_REF)
5327 : {
5328 81726610 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5329 : {
5330 22874407 : tree o = TREE_OPERAND (arg0, 0);
5331 22874407 : TREE_READONLY (t) = TREE_READONLY (o);
5332 22874407 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5333 : }
5334 : }
5335 : else
5336 : {
5337 1229595306 : TREE_READONLY (t) = read_only;
5338 : /* Don't mark X / 0 as constant. */
5339 1229595306 : TREE_CONSTANT (t) = constant && !div_by_zero;
5340 1229595306 : TREE_THIS_VOLATILE (t)
5341 1229595306 : = (TREE_CODE_CLASS (code) == tcc_reference
5342 1229595306 : && arg0 && TREE_THIS_VOLATILE (arg0));
5343 : }
5344 :
5345 1311321916 : return t;
5346 : }
5347 :
5348 :
5349 : tree
5350 482361233 : build3 (enum tree_code code, tree tt, tree arg0, tree arg1,
5351 : tree arg2 MEM_STAT_DECL)
5352 : {
5353 482361233 : bool constant, read_only, side_effects;
5354 482361233 : tree t;
5355 :
5356 482361233 : gcc_assert (TREE_CODE_LENGTH (code) == 3);
5357 482361233 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5358 :
5359 482361233 : t = make_node (code PASS_MEM_STAT);
5360 482361233 : TREE_TYPE (t) = tt;
5361 :
5362 482361233 : read_only = 1;
5363 :
5364 : /* As a special exception, if COND_EXPR has NULL branches, we
5365 : assume that it is a gimple statement and always consider
5366 : it to have side effects. */
5367 482361233 : if (code == COND_EXPR
5368 40735629 : && tt == void_type_node
5369 25429608 : && arg1 == NULL_TREE
5370 25429608 : && arg2 == NULL_TREE)
5371 : side_effects = true;
5372 : else
5373 482361233 : side_effects = TREE_SIDE_EFFECTS (t);
5374 :
5375 528188902 : PROCESS_ARG (0);
5376 496693269 : PROCESS_ARG (1);
5377 496608674 : PROCESS_ARG (2);
5378 :
5379 482361233 : if (code == COND_EXPR)
5380 40735629 : TREE_READONLY (t) = read_only;
5381 :
5382 482361233 : TREE_SIDE_EFFECTS (t) = side_effects;
5383 482361233 : TREE_THIS_VOLATILE (t)
5384 482361233 : = (TREE_CODE_CLASS (code) == tcc_reference
5385 482361233 : && arg0 && TREE_THIS_VOLATILE (arg0));
5386 :
5387 482361233 : return t;
5388 : }
5389 :
5390 : tree
5391 58506176 : build4 (enum tree_code code, tree tt, tree arg0, tree arg1,
5392 : tree arg2, tree arg3 MEM_STAT_DECL)
5393 : {
5394 58506176 : bool constant, read_only, side_effects;
5395 58506176 : tree t;
5396 :
5397 58506176 : gcc_assert (TREE_CODE_LENGTH (code) == 4);
5398 :
5399 58506176 : t = make_node (code PASS_MEM_STAT);
5400 58506176 : TREE_TYPE (t) = tt;
5401 :
5402 58506176 : side_effects = TREE_SIDE_EFFECTS (t);
5403 :
5404 58506176 : PROCESS_ARG (0);
5405 58506176 : PROCESS_ARG (1);
5406 58506176 : PROCESS_ARG (2);
5407 58506176 : PROCESS_ARG (3);
5408 :
5409 58506176 : TREE_SIDE_EFFECTS (t) = side_effects;
5410 58506176 : TREE_THIS_VOLATILE (t)
5411 117012352 : = (TREE_CODE_CLASS (code) == tcc_reference
5412 58506176 : && arg0 && TREE_THIS_VOLATILE (arg0));
5413 :
5414 58506176 : return t;
5415 : }
5416 :
5417 : tree
5418 1182007 : build5 (enum tree_code code, tree tt, tree arg0, tree arg1,
5419 : tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
5420 : {
5421 1182007 : bool constant, read_only, side_effects;
5422 1182007 : tree t;
5423 :
5424 1182007 : gcc_assert (TREE_CODE_LENGTH (code) == 5);
5425 :
5426 1182007 : t = make_node (code PASS_MEM_STAT);
5427 1182007 : TREE_TYPE (t) = tt;
5428 :
5429 1182007 : side_effects = TREE_SIDE_EFFECTS (t);
5430 :
5431 1182007 : PROCESS_ARG (0);
5432 1182007 : PROCESS_ARG (1);
5433 1182007 : PROCESS_ARG (2);
5434 1182007 : PROCESS_ARG (3);
5435 1182007 : PROCESS_ARG (4);
5436 :
5437 1182007 : TREE_SIDE_EFFECTS (t) = side_effects;
5438 1182007 : if (code == TARGET_MEM_REF)
5439 : {
5440 1173425 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5441 : {
5442 190913 : tree o = TREE_OPERAND (arg0, 0);
5443 190913 : TREE_READONLY (t) = TREE_READONLY (o);
5444 190913 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5445 : }
5446 : }
5447 : else
5448 8582 : TREE_THIS_VOLATILE (t)
5449 8582 : = (TREE_CODE_CLASS (code) == tcc_reference
5450 8582 : && arg0 && TREE_THIS_VOLATILE (arg0));
5451 :
5452 1182007 : return t;
5453 : }
5454 :
5455 : /* Build a simple MEM_REF tree with the semantics of a plain INDIRECT_REF
5456 : on the pointer PTR. */
5457 :
5458 : tree
5459 481928 : build_simple_mem_ref_loc (location_t loc, tree ptr)
5460 : {
5461 481928 : poly_int64 offset = 0;
5462 481928 : tree ptype = TREE_TYPE (ptr);
5463 481928 : tree tem;
5464 : /* For convenience allow addresses that collapse to a simple base
5465 : and offset. */
5466 481928 : if (TREE_CODE (ptr) == ADDR_EXPR
5467 481928 : && (handled_component_p (TREE_OPERAND (ptr, 0))
5468 15618 : || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF))
5469 : {
5470 147 : ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset);
5471 147 : gcc_assert (ptr);
5472 147 : if (TREE_CODE (ptr) == MEM_REF)
5473 : {
5474 37 : offset += mem_ref_offset (ptr).force_shwi ();
5475 37 : ptr = TREE_OPERAND (ptr, 0);
5476 : }
5477 : else
5478 110 : ptr = build_fold_addr_expr (ptr);
5479 147 : gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr));
5480 : }
5481 481928 : tem = build2 (MEM_REF, TREE_TYPE (ptype),
5482 : ptr, build_int_cst (ptype, offset));
5483 481928 : SET_EXPR_LOCATION (tem, loc);
5484 481928 : return tem;
5485 : }
5486 :
5487 : /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
5488 :
5489 : poly_offset_int
5490 1227142787 : mem_ref_offset (const_tree t)
5491 : {
5492 1227142787 : return poly_offset_int::from (wi::to_poly_wide (TREE_OPERAND (t, 1)),
5493 1227142787 : SIGNED);
5494 : }
5495 :
5496 : /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
5497 : offsetted by OFFSET units. */
5498 :
5499 : tree
5500 199093 : build_invariant_address (tree type, tree base, poly_int64 offset)
5501 : {
5502 199093 : tree ref = fold_build2 (MEM_REF, TREE_TYPE (type),
5503 : build_fold_addr_expr (base),
5504 : build_int_cst (ptr_type_node, offset));
5505 199093 : tree addr = build1 (ADDR_EXPR, type, ref);
5506 199093 : recompute_tree_invariant_for_addr_expr (addr);
5507 199093 : return addr;
5508 : }
5509 :
5510 : /* Similar except don't specify the TREE_TYPE
5511 : and leave the TREE_SIDE_EFFECTS as 0.
5512 : It is permissible for arguments to be null,
5513 : or even garbage if their values do not matter. */
5514 :
5515 : tree
5516 5832223 : build_nt (enum tree_code code, ...)
5517 : {
5518 5832223 : tree t;
5519 5832223 : int length;
5520 5832223 : int i;
5521 5832223 : va_list p;
5522 :
5523 5832223 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5524 :
5525 5832223 : va_start (p, code);
5526 :
5527 5832223 : t = make_node (code);
5528 5832223 : length = TREE_CODE_LENGTH (code);
5529 :
5530 15740429 : for (i = 0; i < length; i++)
5531 9908206 : TREE_OPERAND (t, i) = va_arg (p, tree);
5532 :
5533 5832223 : va_end (p);
5534 5832223 : return t;
5535 : }
5536 :
5537 : /* Similar to build_nt, but for creating a CALL_EXPR object with a
5538 : tree vec. */
5539 :
5540 : tree
5541 0 : build_nt_call_vec (tree fn, vec<tree, va_gc> *args)
5542 : {
5543 0 : tree ret, t;
5544 0 : unsigned int ix;
5545 :
5546 0 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
5547 0 : CALL_EXPR_FN (ret) = fn;
5548 0 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
5549 0 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
5550 0 : CALL_EXPR_ARG (ret, ix) = t;
5551 0 : return ret;
5552 : }
5553 :
5554 : /* Create a DECL_... node of code CODE, name NAME (if non-null)
5555 : and data type TYPE.
5556 : We do NOT enter this node in any sort of symbol table.
5557 :
5558 : LOC is the location of the decl.
5559 :
5560 : layout_decl is used to set up the decl's storage layout.
5561 : Other slots are initialized to 0 or null pointers. */
5562 :
5563 : tree
5564 3255167533 : build_decl (location_t loc, enum tree_code code, tree name,
5565 : tree type MEM_STAT_DECL)
5566 : {
5567 3255167533 : tree t;
5568 :
5569 3255167533 : t = make_node (code PASS_MEM_STAT);
5570 3255167533 : DECL_SOURCE_LOCATION (t) = loc;
5571 :
5572 : /* if (type == error_mark_node)
5573 : type = integer_type_node; */
5574 : /* That is not done, deliberately, so that having error_mark_node
5575 : as the type can suppress useless errors in the use of this variable. */
5576 :
5577 3255167533 : DECL_NAME (t) = name;
5578 3255167533 : TREE_TYPE (t) = type;
5579 :
5580 3255167533 : if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
5581 1164119026 : layout_decl (t, 0);
5582 :
5583 3255167533 : return t;
5584 : }
5585 :
5586 : /* Create and return a DEBUG_EXPR_DECL node of the given TYPE. */
5587 :
5588 : tree
5589 1718685 : build_debug_expr_decl (tree type)
5590 : {
5591 1718685 : tree vexpr = make_node (DEBUG_EXPR_DECL);
5592 1718685 : DECL_ARTIFICIAL (vexpr) = 1;
5593 1718685 : TREE_TYPE (vexpr) = type;
5594 1718685 : SET_DECL_MODE (vexpr, TYPE_MODE (type));
5595 1718685 : return vexpr;
5596 : }
5597 :
5598 : /* Builds and returns function declaration with NAME and TYPE. */
5599 :
5600 : tree
5601 21317 : build_fn_decl (const char *name, tree type)
5602 : {
5603 21317 : tree id = get_identifier (name);
5604 21317 : tree decl = build_decl (input_location, FUNCTION_DECL, id, type);
5605 :
5606 21317 : DECL_EXTERNAL (decl) = 1;
5607 21317 : TREE_PUBLIC (decl) = 1;
5608 21317 : DECL_ARTIFICIAL (decl) = 1;
5609 21317 : TREE_NOTHROW (decl) = 1;
5610 :
5611 21317 : return decl;
5612 : }
5613 :
5614 : vec<tree, va_gc> *all_translation_units;
5615 :
5616 : /* Builds a new translation-unit decl with name NAME, queues it in the
5617 : global list of translation-unit decls and returns it. */
5618 :
5619 : tree
5620 255551 : build_translation_unit_decl (tree name)
5621 : {
5622 255551 : tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL,
5623 255551 : name, NULL_TREE);
5624 255551 : TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
5625 255551 : vec_safe_push (all_translation_units, tu);
5626 255551 : return tu;
5627 : }
5628 :
5629 :
5630 : /* BLOCK nodes are used to represent the structure of binding contours
5631 : and declarations, once those contours have been exited and their contents
5632 : compiled. This information is used for outputting debugging info. */
5633 :
5634 : tree
5635 727768 : build_block (tree vars, tree subblocks, tree supercontext, tree chain)
5636 : {
5637 727768 : tree block = make_node (BLOCK);
5638 :
5639 727768 : BLOCK_VARS (block) = vars;
5640 727768 : BLOCK_SUBBLOCKS (block) = subblocks;
5641 727768 : BLOCK_SUPERCONTEXT (block) = supercontext;
5642 727768 : BLOCK_CHAIN (block) = chain;
5643 727768 : return block;
5644 : }
5645 :
5646 :
5647 : /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
5648 :
5649 : LOC is the location to use in tree T. */
5650 :
5651 : void
5652 14956278665 : protected_set_expr_location (tree t, location_t loc)
5653 : {
5654 14956278665 : if (CAN_HAVE_LOCATION_P (t))
5655 2368566854 : SET_EXPR_LOCATION (t, loc);
5656 12497827177 : else if (t && TREE_CODE (t) == STATEMENT_LIST)
5657 : {
5658 22243 : t = expr_single (t);
5659 22243 : if (t && CAN_HAVE_LOCATION_P (t))
5660 18 : SET_EXPR_LOCATION (t, loc);
5661 : }
5662 14956278665 : }
5663 :
5664 : /* Like PROTECTED_SET_EXPR_LOCATION, but only do that if T has
5665 : UNKNOWN_LOCATION. */
5666 :
5667 : void
5668 26073756 : protected_set_expr_location_if_unset (tree t, location_t loc)
5669 : {
5670 26073756 : t = expr_single (t);
5671 26073756 : if (t && !EXPR_HAS_LOCATION (t))
5672 18581368 : protected_set_expr_location (t, loc);
5673 26073756 : }
5674 :
5675 : /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5676 : of the various TYPE_QUAL values. */
5677 :
5678 : static void
5679 113705037 : set_type_quals (tree type, int type_quals)
5680 : {
5681 113705037 : TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
5682 113705037 : TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
5683 113705037 : TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
5684 113705037 : TYPE_ATOMIC (type) = (type_quals & TYPE_QUAL_ATOMIC) != 0;
5685 113705037 : TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals);
5686 113705037 : }
5687 :
5688 : /* Returns true iff CAND and BASE have equivalent language-specific
5689 : qualifiers. */
5690 :
5691 : bool
5692 3230402829 : check_lang_type (const_tree cand, const_tree base)
5693 : {
5694 3230402829 : if (lang_hooks.types.type_hash_eq == NULL)
5695 : return true;
5696 : /* type_hash_eq currently only applies to these types. */
5697 3174111643 : if (TREE_CODE (cand) != FUNCTION_TYPE
5698 3174111643 : && TREE_CODE (cand) != METHOD_TYPE)
5699 : return true;
5700 1160813 : return lang_hooks.types.type_hash_eq (cand, base);
5701 : }
5702 :
5703 : /* This function checks to see if TYPE matches the size one of the built-in
5704 : atomic types, and returns that core atomic type. */
5705 :
5706 : static tree
5707 8880 : find_atomic_core_type (const_tree type)
5708 : {
5709 8880 : tree base_atomic_type;
5710 :
5711 : /* Only handle complete types. */
5712 8880 : if (!tree_fits_uhwi_p (TYPE_SIZE (type)))
5713 : return NULL_TREE;
5714 :
5715 8868 : switch (tree_to_uhwi (TYPE_SIZE (type)))
5716 : {
5717 2710 : case 8:
5718 2710 : base_atomic_type = atomicQI_type_node;
5719 2710 : break;
5720 :
5721 862 : case 16:
5722 862 : base_atomic_type = atomicHI_type_node;
5723 862 : break;
5724 :
5725 1117 : case 32:
5726 1117 : base_atomic_type = atomicSI_type_node;
5727 1117 : break;
5728 :
5729 2749 : case 64:
5730 2749 : base_atomic_type = atomicDI_type_node;
5731 2749 : break;
5732 :
5733 1310 : case 128:
5734 1310 : base_atomic_type = atomicTI_type_node;
5735 1310 : break;
5736 :
5737 : default:
5738 : base_atomic_type = NULL_TREE;
5739 : }
5740 :
5741 : return base_atomic_type;
5742 : }
5743 :
5744 : /* Returns true iff unqualified CAND and BASE are equivalent. */
5745 :
5746 : bool
5747 5150666472 : check_base_type (const_tree cand, const_tree base)
5748 : {
5749 5150666472 : if (TYPE_NAME (cand) != TYPE_NAME (base)
5750 : /* Apparently this is needed for Objective-C. */
5751 4539764349 : || TYPE_CONTEXT (cand) != TYPE_CONTEXT (base)
5752 9690430820 : || !attribute_list_equal (TYPE_ATTRIBUTES (cand),
5753 4539764348 : TYPE_ATTRIBUTES (base)))
5754 610902124 : return false;
5755 : /* Check alignment. */
5756 4539764348 : if (TYPE_ALIGN (cand) == TYPE_ALIGN (base)
5757 4539764348 : && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base))
5758 : return true;
5759 : /* Atomic types increase minimal alignment. We must to do so as well
5760 : or we get duplicated canonical types. See PR88686. */
5761 11262 : if ((TYPE_QUALS (cand) & TYPE_QUAL_ATOMIC))
5762 : {
5763 : /* See if this object can map to a basic atomic type. */
5764 1775 : tree atomic_type = find_atomic_core_type (cand);
5765 1775 : if (atomic_type && TYPE_ALIGN (atomic_type) == TYPE_ALIGN (cand))
5766 : return true;
5767 : }
5768 : return false;
5769 : }
5770 :
5771 : /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
5772 :
5773 : bool
5774 5512026360 : check_qualified_type (const_tree cand, const_tree base, int type_quals)
5775 : {
5776 5512026360 : return (TYPE_QUALS (cand) == type_quals
5777 3839110588 : && check_base_type (cand, base)
5778 8740587145 : && check_lang_type (cand, base));
5779 : }
5780 :
5781 : /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5782 :
5783 : static bool
5784 3846764 : check_aligned_type (const_tree cand, const_tree base, unsigned int align)
5785 : {
5786 3846764 : return (TYPE_QUALS (cand) == TYPE_QUALS (base)
5787 3113569 : && TYPE_NAME (cand) == TYPE_NAME (base)
5788 : /* Apparently this is needed for Objective-C. */
5789 2213454 : && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
5790 : /* Check alignment. */
5791 2213454 : && TYPE_ALIGN (cand) == align
5792 : /* Check this is a user-aligned type as build_aligned_type
5793 : would create. */
5794 1044589 : && TYPE_USER_ALIGN (cand)
5795 1041726 : && attribute_list_equal (TYPE_ATTRIBUTES (cand),
5796 1041726 : TYPE_ATTRIBUTES (base))
5797 4888490 : && check_lang_type (cand, base));
5798 : }
5799 :
5800 : /* Return a version of the TYPE, qualified as indicated by the
5801 : TYPE_QUALS, if one exists. If no qualified version exists yet,
5802 : return NULL_TREE. */
5803 :
5804 : tree
5805 4722886644 : get_qualified_type (tree type, int type_quals)
5806 : {
5807 4722886644 : if (TYPE_QUALS (type) == type_quals)
5808 : return type;
5809 :
5810 3342419601 : tree mv = TYPE_MAIN_VARIANT (type);
5811 3342419601 : if (check_qualified_type (mv, type, type_quals))
5812 : return mv;
5813 :
5814 : /* Search the chain of variants to see if there is already one there just
5815 : like the one we need to have. If so, use that existing one. We must
5816 : preserve the TYPE_NAME, since there is code that depends on this. */
5817 2283475888 : for (tree *tp = &TYPE_NEXT_VARIANT (mv); *tp; tp = &TYPE_NEXT_VARIANT (*tp))
5818 2169543230 : if (check_qualified_type (*tp, type, type_quals))
5819 : {
5820 : /* Put the found variant at the head of the variant list so
5821 : frequently searched variants get found faster. The C++ FE
5822 : benefits greatly from this. */
5823 1364643349 : tree t = *tp;
5824 1364643349 : *tp = TYPE_NEXT_VARIANT (t);
5825 1364643349 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
5826 1364643349 : TYPE_NEXT_VARIANT (mv) = t;
5827 1364643349 : return t;
5828 : }
5829 :
5830 : return NULL_TREE;
5831 : }
5832 :
5833 : /* Like get_qualified_type, but creates the type if it does not
5834 : exist. This function never returns NULL_TREE. */
5835 :
5836 : tree
5837 4221372573 : build_qualified_type (tree type, int type_quals MEM_STAT_DECL)
5838 : {
5839 4221372573 : tree t;
5840 :
5841 : /* See if we already have the appropriate qualified variant. */
5842 4221372573 : t = get_qualified_type (type, type_quals);
5843 :
5844 : /* If not, build it. */
5845 4221372573 : if (!t)
5846 : {
5847 112244697 : t = build_variant_type_copy (type PASS_MEM_STAT);
5848 112244697 : set_type_quals (t, type_quals);
5849 :
5850 112244697 : if (((type_quals & TYPE_QUAL_ATOMIC) == TYPE_QUAL_ATOMIC))
5851 : {
5852 : /* See if this object can map to a basic atomic type. */
5853 7105 : tree atomic_type = find_atomic_core_type (type);
5854 7105 : if (atomic_type)
5855 : {
5856 : /* Ensure the alignment of this type is compatible with
5857 : the required alignment of the atomic type. */
5858 6973 : if (TYPE_ALIGN (atomic_type) > TYPE_ALIGN (t))
5859 94 : SET_TYPE_ALIGN (t, TYPE_ALIGN (atomic_type));
5860 : }
5861 : }
5862 :
5863 112244697 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5864 : /* Propagate structural equality. */
5865 5632480 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5866 106612217 : else if (TYPE_CANONICAL (type) != type)
5867 : /* Build the underlying canonical type, since it is different
5868 : from TYPE. */
5869 : {
5870 34935045 : tree c = build_qualified_type (TYPE_CANONICAL (type), type_quals);
5871 34935045 : TYPE_CANONICAL (t) = TYPE_CANONICAL (c);
5872 : }
5873 : else
5874 : /* T is its own canonical type. */
5875 71677172 : TYPE_CANONICAL (t) = t;
5876 :
5877 : }
5878 :
5879 4221372573 : return t;
5880 : }
5881 :
5882 : /* Create a variant of type T with alignment ALIGN which
5883 : is measured in bits. */
5884 :
5885 : tree
5886 1331366 : build_aligned_type (tree type, unsigned int align)
5887 : {
5888 1331366 : tree t;
5889 :
5890 1331366 : if (TYPE_PACKED (type)
5891 1331366 : || TYPE_ALIGN (type) == align)
5892 : return type;
5893 :
5894 3954936 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
5895 3846764 : if (check_aligned_type (t, type, align))
5896 : return t;
5897 :
5898 108172 : t = build_variant_type_copy (type);
5899 108172 : SET_TYPE_ALIGN (t, align);
5900 108172 : TYPE_USER_ALIGN (t) = 1;
5901 :
5902 108172 : return t;
5903 : }
5904 :
5905 : /* Create a new distinct copy of TYPE. The new type is made its own
5906 : MAIN_VARIANT. If TYPE requires structural equality checks, the
5907 : resulting type requires structural equality checks; otherwise, its
5908 : TYPE_CANONICAL points to itself. */
5909 :
5910 : tree
5911 808568416 : build_distinct_type_copy (tree type MEM_STAT_DECL)
5912 : {
5913 808568416 : tree t = copy_node (type PASS_MEM_STAT);
5914 :
5915 808568416 : TYPE_POINTER_TO (t) = 0;
5916 808568416 : TYPE_REFERENCE_TO (t) = 0;
5917 :
5918 : /* Set the canonical type either to a new equivalence class, or
5919 : propagate the need for structural equality checks. */
5920 808568416 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5921 68064711 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5922 : else
5923 740503705 : TYPE_CANONICAL (t) = t;
5924 :
5925 : /* Make it its own variant. */
5926 808568416 : TYPE_MAIN_VARIANT (t) = t;
5927 808568416 : TYPE_NEXT_VARIANT (t) = 0;
5928 :
5929 : /* Note that it is now possible for TYPE_MIN_VALUE to be a value
5930 : whose TREE_TYPE is not t. This can also happen in the Ada
5931 : frontend when using subtypes. */
5932 :
5933 808568416 : return t;
5934 : }
5935 :
5936 : /* Create a new variant of TYPE, equivalent but distinct. This is so
5937 : the caller can modify it. TYPE_CANONICAL for the return type will
5938 : be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
5939 : are considered equal by the language itself (or that both types
5940 : require structural equality checks). */
5941 :
5942 : tree
5943 523214941 : build_variant_type_copy (tree type MEM_STAT_DECL)
5944 : {
5945 523214941 : tree t, m = TYPE_MAIN_VARIANT (type);
5946 :
5947 523214941 : t = build_distinct_type_copy (type PASS_MEM_STAT);
5948 :
5949 : /* Since we're building a variant, assume that it is a non-semantic
5950 : variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
5951 523214941 : TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
5952 : /* Type variants have no alias set defined. */
5953 523214941 : TYPE_ALIAS_SET (t) = -1;
5954 :
5955 : /* Add the new type to the chain of variants of TYPE. */
5956 523214941 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
5957 523214941 : TYPE_NEXT_VARIANT (m) = t;
5958 523214941 : TYPE_MAIN_VARIANT (t) = m;
5959 :
5960 523214941 : return t;
5961 : }
5962 :
5963 : /* Return true if the from tree in both tree maps are equal. */
5964 :
5965 : int
5966 1869368839 : tree_map_base_eq (const void *va, const void *vb)
5967 : {
5968 1869368839 : const struct tree_map_base *const a = (const struct tree_map_base *) va,
5969 1869368839 : *const b = (const struct tree_map_base *) vb;
5970 1869368839 : return (a->from == b->from);
5971 : }
5972 :
5973 : /* Hash a from tree in a tree_base_map. */
5974 :
5975 : unsigned int
5976 0 : tree_map_base_hash (const void *item)
5977 : {
5978 0 : return htab_hash_pointer (((const struct tree_map_base *)item)->from);
5979 : }
5980 :
5981 : /* Return true if this tree map structure is marked for garbage collection
5982 : purposes. We simply return true if the from tree is marked, so that this
5983 : structure goes away when the from tree goes away. */
5984 :
5985 : bool
5986 0 : tree_map_base_marked_p (const void *p)
5987 : {
5988 0 : return ggc_marked_p (((const struct tree_map_base *) p)->from);
5989 : }
5990 :
5991 : /* Hash a from tree in a tree_map. */
5992 :
5993 : unsigned int
5994 199 : tree_map_hash (const void *item)
5995 : {
5996 199 : return (((const struct tree_map *) item)->hash);
5997 : }
5998 :
5999 : /* Hash a from tree in a tree_decl_map. */
6000 :
6001 : unsigned int
6002 1274938838 : tree_decl_map_hash (const void *item)
6003 : {
6004 1274938838 : return DECL_UID (((const struct tree_decl_map *) item)->base.from);
6005 : }
6006 :
6007 : /* Return the initialization priority for DECL. */
6008 :
6009 : priority_type
6010 24397 : decl_init_priority_lookup (tree decl)
6011 : {
6012 24397 : symtab_node *snode = symtab_node::get (decl);
6013 :
6014 24397 : if (!snode)
6015 : return DEFAULT_INIT_PRIORITY;
6016 24397 : return
6017 24397 : snode->get_init_priority ();
6018 : }
6019 :
6020 : /* Return the finalization priority for DECL. */
6021 :
6022 : priority_type
6023 1851 : decl_fini_priority_lookup (tree decl)
6024 : {
6025 1851 : cgraph_node *node = cgraph_node::get (decl);
6026 :
6027 1851 : if (!node)
6028 : return DEFAULT_INIT_PRIORITY;
6029 1851 : return
6030 1851 : node->get_fini_priority ();
6031 : }
6032 :
6033 : /* Set the initialization priority for DECL to PRIORITY. */
6034 :
6035 : void
6036 25972 : decl_init_priority_insert (tree decl, priority_type priority)
6037 : {
6038 25972 : struct symtab_node *snode;
6039 :
6040 25972 : if (priority == DEFAULT_INIT_PRIORITY)
6041 : {
6042 22484 : snode = symtab_node::get (decl);
6043 22484 : if (!snode)
6044 : return;
6045 : }
6046 3488 : else if (VAR_P (decl))
6047 45 : snode = varpool_node::get_create (decl);
6048 : else
6049 3443 : snode = cgraph_node::get_create (decl);
6050 25149 : snode->set_init_priority (priority);
6051 : }
6052 :
6053 : /* Set the finalization priority for DECL to PRIORITY. */
6054 :
6055 : void
6056 1712 : decl_fini_priority_insert (tree decl, priority_type priority)
6057 : {
6058 1712 : struct cgraph_node *node;
6059 :
6060 1712 : if (priority == DEFAULT_INIT_PRIORITY)
6061 : {
6062 105 : node = cgraph_node::get (decl);
6063 105 : if (!node)
6064 : return;
6065 : }
6066 : else
6067 1607 : node = cgraph_node::get_create (decl);
6068 1617 : node->set_fini_priority (priority);
6069 : }
6070 :
6071 : /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
6072 :
6073 : static void
6074 0 : print_debug_expr_statistics (void)
6075 : {
6076 0 : fprintf (stderr, "DECL_DEBUG_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6077 : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6078 0 : (fmt_size_t) debug_expr_for_decl->size (),
6079 0 : (fmt_size_t) debug_expr_for_decl->elements (),
6080 : debug_expr_for_decl->collisions ());
6081 0 : }
6082 :
6083 : /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6084 :
6085 : static void
6086 0 : print_value_expr_statistics (void)
6087 : {
6088 0 : fprintf (stderr, "DECL_VALUE_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6089 : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6090 0 : (fmt_size_t) value_expr_for_decl->size (),
6091 0 : (fmt_size_t) value_expr_for_decl->elements (),
6092 : value_expr_for_decl->collisions ());
6093 0 : }
6094 :
6095 : /* Lookup a debug expression for FROM, and return it if we find one. */
6096 :
6097 : tree
6098 442671939 : decl_debug_expr_lookup (tree from)
6099 : {
6100 442671939 : struct tree_decl_map *h, in;
6101 442671939 : in.base.from = from;
6102 :
6103 442671939 : h = debug_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6104 442671939 : if (h)
6105 442671939 : return h->to;
6106 : return NULL_TREE;
6107 : }
6108 :
6109 : /* Insert a mapping FROM->TO in the debug expression hashtable. */
6110 :
6111 : void
6112 1411543 : decl_debug_expr_insert (tree from, tree to)
6113 : {
6114 1411543 : struct tree_decl_map *h;
6115 :
6116 1411543 : h = ggc_alloc<tree_decl_map> ();
6117 1411543 : h->base.from = from;
6118 1411543 : h->to = to;
6119 1411543 : *debug_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6120 1411543 : }
6121 :
6122 : /* Lookup a value expression for FROM, and return it if we find one. */
6123 :
6124 : tree
6125 23164594 : decl_value_expr_lookup (tree from)
6126 : {
6127 23164594 : struct tree_decl_map *h, in;
6128 23164594 : in.base.from = from;
6129 :
6130 23164594 : h = value_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6131 23164594 : if (h)
6132 23164594 : return h->to;
6133 : return NULL_TREE;
6134 : }
6135 :
6136 : /* Insert a mapping FROM->TO in the value expression hashtable. */
6137 :
6138 : void
6139 8572585 : decl_value_expr_insert (tree from, tree to)
6140 : {
6141 8572585 : struct tree_decl_map *h;
6142 :
6143 : /* Uses of FROM shouldn't look like they happen at the location of TO. */
6144 8572585 : to = protected_set_expr_location_unshare (to, UNKNOWN_LOCATION);
6145 :
6146 8572585 : h = ggc_alloc<tree_decl_map> ();
6147 8572585 : h->base.from = from;
6148 8572585 : h->to = to;
6149 8572585 : *value_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6150 8572585 : }
6151 :
6152 : /* Lookup a vector of debug arguments for FROM, and return it if we
6153 : find one. */
6154 :
6155 : vec<tree, va_gc> **
6156 950895 : decl_debug_args_lookup (tree from)
6157 : {
6158 950895 : struct tree_vec_map *h, in;
6159 :
6160 950895 : if (!DECL_HAS_DEBUG_ARGS_P (from))
6161 : return NULL;
6162 809721 : gcc_checking_assert (debug_args_for_decl != NULL);
6163 809721 : in.base.from = from;
6164 809721 : h = debug_args_for_decl->find_with_hash (&in, DECL_UID (from));
6165 809721 : if (h)
6166 805755 : return &h->to;
6167 : return NULL;
6168 : }
6169 :
6170 : /* Insert a mapping FROM->empty vector of debug arguments in the value
6171 : expression hashtable. */
6172 :
6173 : vec<tree, va_gc> **
6174 302553 : decl_debug_args_insert (tree from)
6175 : {
6176 302553 : struct tree_vec_map *h;
6177 302553 : tree_vec_map **loc;
6178 :
6179 302553 : if (DECL_HAS_DEBUG_ARGS_P (from))
6180 208864 : return decl_debug_args_lookup (from);
6181 93689 : if (debug_args_for_decl == NULL)
6182 8471 : debug_args_for_decl = hash_table<tree_vec_map_cache_hasher>::create_ggc (64);
6183 93689 : h = ggc_alloc<tree_vec_map> ();
6184 93689 : h->base.from = from;
6185 93689 : h->to = NULL;
6186 93689 : loc = debug_args_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT);
6187 93689 : *loc = h;
6188 93689 : DECL_HAS_DEBUG_ARGS_P (from) = 1;
6189 93689 : return &h->to;
6190 : }
6191 :
6192 : /* Hashing of types so that we don't make duplicates.
6193 : The entry point is `type_hash_canon'. */
6194 :
6195 : /* Generate the default hash code for TYPE. This is designed for
6196 : speed, rather than maximum entropy. */
6197 :
6198 : hashval_t
6199 1454018011 : type_hash_canon_hash (tree type)
6200 : {
6201 1454018011 : inchash::hash hstate;
6202 :
6203 1454018011 : hstate.add_int (TREE_CODE (type));
6204 :
6205 1454018011 : hstate.add_flag (TYPE_STRUCTURAL_EQUALITY_P (type));
6206 :
6207 1454018011 : if (TREE_TYPE (type))
6208 1453935108 : hstate.add_object (TYPE_HASH (TREE_TYPE (type)));
6209 :
6210 1734155918 : for (tree t = TYPE_ATTRIBUTES (type); t; t = TREE_CHAIN (t))
6211 : /* Just the identifier is adequate to distinguish. */
6212 280137907 : hstate.add_object (IDENTIFIER_HASH_VALUE (get_attribute_name (t)));
6213 :
6214 1454018011 : switch (TREE_CODE (type))
6215 : {
6216 344941070 : case METHOD_TYPE:
6217 344941070 : hstate.add_object (TYPE_HASH (TYPE_METHOD_BASETYPE (type)));
6218 : /* FALLTHROUGH. */
6219 1254800371 : case FUNCTION_TYPE:
6220 4944629797 : for (tree t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
6221 3689829426 : if (TREE_VALUE (t) != error_mark_node)
6222 3689817011 : hstate.add_object (TYPE_HASH (TREE_VALUE (t)));
6223 : break;
6224 :
6225 991199 : case OFFSET_TYPE:
6226 991199 : hstate.add_object (TYPE_HASH (TYPE_OFFSET_BASETYPE (type)));
6227 991199 : break;
6228 :
6229 74017905 : case ARRAY_TYPE:
6230 74017905 : {
6231 74017905 : if (TYPE_DOMAIN (type))
6232 71013105 : hstate.add_object (TYPE_HASH (TYPE_DOMAIN (type)));
6233 74017905 : if (!AGGREGATE_TYPE_P (TREE_TYPE (type)))
6234 : {
6235 71524984 : unsigned typeless = TYPE_TYPELESS_STORAGE (type);
6236 71524984 : hstate.add_object (typeless);
6237 : }
6238 : }
6239 : break;
6240 :
6241 44014339 : case INTEGER_TYPE:
6242 44014339 : {
6243 44014339 : tree t = TYPE_MAX_VALUE (type);
6244 44014339 : if (!t)
6245 554848 : t = TYPE_MIN_VALUE (type);
6246 88028679 : for (int i = 0; i < TREE_INT_CST_NUNITS (t); i++)
6247 44014340 : hstate.add_object (TREE_INT_CST_ELT (t, i));
6248 : break;
6249 : }
6250 :
6251 60482 : case BITINT_TYPE:
6252 60482 : {
6253 60482 : unsigned prec = TYPE_PRECISION (type);
6254 60482 : unsigned uns = TYPE_UNSIGNED (type);
6255 60482 : hstate.add_object (prec);
6256 60482 : hstate.add_int (uns);
6257 60482 : break;
6258 : }
6259 :
6260 12034 : case REAL_TYPE:
6261 12034 : case FIXED_POINT_TYPE:
6262 12034 : {
6263 12034 : unsigned prec = TYPE_PRECISION (type);
6264 12034 : hstate.add_object (prec);
6265 12034 : break;
6266 : }
6267 :
6268 74441285 : case VECTOR_TYPE:
6269 74441285 : hstate.add_poly_int (TYPE_VECTOR_SUBPARTS (type));
6270 74441285 : break;
6271 :
6272 : case REFERENCE_TYPE:
6273 1454018011 : hstate.add_flag (TYPE_REF_IS_RVALUE (type));
6274 : break;
6275 :
6276 : default:
6277 : break;
6278 : }
6279 :
6280 1454018011 : return hstate.end ();
6281 : }
6282 :
6283 : /* These are the Hashtable callback functions. */
6284 :
6285 : /* Returns true iff the types are equivalent. */
6286 :
6287 : bool
6288 9954175136 : type_cache_hasher::equal (type_hash *a, type_hash *b)
6289 : {
6290 : /* First test the things that are the same for all types. */
6291 9954175136 : if (a->hash != b->hash
6292 717499314 : || TREE_CODE (a->type) != TREE_CODE (b->type)
6293 717498850 : || TREE_TYPE (a->type) != TREE_TYPE (b->type)
6294 717489850 : || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
6295 717489850 : TYPE_ATTRIBUTES (b->type))
6296 10664512149 : || (TREE_CODE (a->type) != COMPLEX_TYPE
6297 708126284 : && TYPE_NAME (a->type) != TYPE_NAME (b->type)))
6298 9244731100 : return false;
6299 :
6300 : /* Be careful about comparing arrays before and after the element type
6301 : has been completed; don't compare TYPE_ALIGN unless both types are
6302 : complete. */
6303 1415675275 : if (COMPLETE_TYPE_P (a->type) && COMPLETE_TYPE_P (b->type)
6304 1415675275 : && (TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
6305 706230694 : || TYPE_MODE (a->type) != TYPE_MODE (b->type)))
6306 600 : return false;
6307 :
6308 709443436 : if (TYPE_STRUCTURAL_EQUALITY_P (a->type)
6309 709443436 : != TYPE_STRUCTURAL_EQUALITY_P (b->type))
6310 : return false;
6311 :
6312 709439664 : switch (TREE_CODE (a->type))
6313 : {
6314 : case VOID_TYPE:
6315 : case OPAQUE_TYPE:
6316 : case COMPLEX_TYPE:
6317 : case POINTER_TYPE:
6318 : case NULLPTR_TYPE:
6319 : return true;
6320 :
6321 67991115 : case VECTOR_TYPE:
6322 67991115 : return known_eq (TYPE_VECTOR_SUBPARTS (a->type),
6323 : TYPE_VECTOR_SUBPARTS (b->type));
6324 :
6325 0 : case ENUMERAL_TYPE:
6326 0 : if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
6327 0 : && !(TYPE_VALUES (a->type)
6328 0 : && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
6329 0 : && TYPE_VALUES (b->type)
6330 0 : && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
6331 0 : && type_list_equal (TYPE_VALUES (a->type),
6332 0 : TYPE_VALUES (b->type))))
6333 0 : return false;
6334 :
6335 : /* fall through */
6336 :
6337 41024892 : case INTEGER_TYPE:
6338 41024892 : case REAL_TYPE:
6339 41024892 : case BOOLEAN_TYPE:
6340 41024892 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6341 : return false;
6342 41011076 : return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
6343 731033 : || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
6344 731033 : TYPE_MAX_VALUE (b->type)))
6345 41336336 : && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
6346 495985 : || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
6347 495985 : TYPE_MIN_VALUE (b->type))));
6348 :
6349 54248 : case BITINT_TYPE:
6350 54248 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6351 : return false;
6352 54248 : return TYPE_UNSIGNED (a->type) == TYPE_UNSIGNED (b->type);
6353 :
6354 0 : case FIXED_POINT_TYPE:
6355 0 : return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
6356 :
6357 751108 : case OFFSET_TYPE:
6358 751108 : return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
6359 :
6360 95950849 : case METHOD_TYPE:
6361 95950849 : if (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
6362 95950849 : && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6363 95799984 : || (TYPE_ARG_TYPES (a->type)
6364 95799984 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6365 95799984 : && TYPE_ARG_TYPES (b->type)
6366 95799984 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6367 95799984 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6368 95799984 : TYPE_ARG_TYPES (b->type)))))
6369 : break;
6370 : return false;
6371 62625376 : case ARRAY_TYPE:
6372 : /* Don't compare TYPE_TYPELESS_STORAGE flag on aggregates,
6373 : where the flag should be inherited from the element type
6374 : and can change after ARRAY_TYPEs are created; on non-aggregates
6375 : compare it and hash it, scalars will never have that flag set
6376 : and we need to differentiate between arrays created by different
6377 : front-ends or middle-end created arrays. */
6378 62625376 : return (TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type)
6379 62625376 : && (AGGREGATE_TYPE_P (TREE_TYPE (a->type))
6380 60773087 : || (TYPE_TYPELESS_STORAGE (a->type)
6381 60773087 : == TYPE_TYPELESS_STORAGE (b->type))));
6382 :
6383 0 : case RECORD_TYPE:
6384 0 : case UNION_TYPE:
6385 0 : case QUAL_UNION_TYPE:
6386 0 : return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
6387 0 : || (TYPE_FIELDS (a->type)
6388 0 : && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
6389 0 : && TYPE_FIELDS (b->type)
6390 0 : && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
6391 0 : && type_list_equal (TYPE_FIELDS (a->type),
6392 0 : TYPE_FIELDS (b->type))));
6393 :
6394 438830889 : case FUNCTION_TYPE:
6395 438830889 : if ((TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6396 276798255 : && (TYPE_NO_NAMED_ARGS_STDARG_P (a->type)
6397 276798255 : == TYPE_NO_NAMED_ARGS_STDARG_P (b->type)))
6398 439129958 : || (TYPE_ARG_TYPES (a->type)
6399 162032634 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6400 162032634 : && TYPE_ARG_TYPES (b->type)
6401 162032619 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6402 162032619 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6403 162032619 : TYPE_ARG_TYPES (b->type))))
6404 : break;
6405 : return false;
6406 :
6407 9 : case REFERENCE_TYPE:
6408 9 : return TYPE_REF_IS_RVALUE (a->type) == TYPE_REF_IS_RVALUE (b->type);
6409 :
6410 : default:
6411 : return false;
6412 : }
6413 :
6414 506317669 : if (lang_hooks.types.type_hash_eq != NULL)
6415 324772983 : return lang_hooks.types.type_hash_eq (a->type, b->type);
6416 :
6417 : return true;
6418 : }
6419 :
6420 : /* Given TYPE, and HASHCODE its hash code, return the canonical
6421 : object for an identical type if one already exists.
6422 : Otherwise, return TYPE, and record it as the canonical object.
6423 :
6424 : To use this function, first create a type of the sort you want.
6425 : Then compute its hash code from the fields of the type that
6426 : make it different from other similar types.
6427 : Then call this function and use the value. */
6428 :
6429 : tree
6430 1455096901 : type_hash_canon (unsigned int hashcode, tree type)
6431 : {
6432 1455096901 : type_hash in;
6433 1455096901 : type_hash **loc;
6434 :
6435 : /* The hash table only contains main variants, so ensure that's what we're
6436 : being passed. */
6437 1455096901 : gcc_assert (TYPE_MAIN_VARIANT (type) == type);
6438 :
6439 : /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6440 : must call that routine before comparing TYPE_ALIGNs. */
6441 1455096901 : layout_type (type);
6442 :
6443 1455096901 : in.hash = hashcode;
6444 1455096901 : in.type = type;
6445 :
6446 1455096901 : loc = type_hash_table->find_slot_with_hash (&in, hashcode, INSERT);
6447 1455096901 : if (*loc)
6448 : {
6449 680379000 : tree t1 = ((type_hash *) *loc)->type;
6450 680379000 : gcc_assert (TYPE_MAIN_VARIANT (t1) == t1
6451 : && t1 != type);
6452 680379000 : if (TYPE_UID (type) + 1 == next_type_uid)
6453 675079807 : --next_type_uid;
6454 : /* Free also min/max values and the cache for integer
6455 : types. This can't be done in free_node, as LTO frees
6456 : those on its own. */
6457 680379000 : if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == BITINT_TYPE)
6458 : {
6459 40482542 : if (TYPE_MIN_VALUE (type)
6460 40482542 : && TREE_TYPE (TYPE_MIN_VALUE (type)) == type)
6461 : {
6462 : /* Zero is always in TYPE_CACHED_VALUES. */
6463 372572 : if (! TYPE_UNSIGNED (type))
6464 222472 : int_cst_hash_table->remove_elt (TYPE_MIN_VALUE (type));
6465 372572 : ggc_free (TYPE_MIN_VALUE (type));
6466 : }
6467 40482542 : if (TYPE_MAX_VALUE (type)
6468 40482542 : && TREE_TYPE (TYPE_MAX_VALUE (type)) == type)
6469 : {
6470 372572 : int_cst_hash_table->remove_elt (TYPE_MAX_VALUE (type));
6471 372572 : ggc_free (TYPE_MAX_VALUE (type));
6472 : }
6473 40482542 : if (TYPE_CACHED_VALUES_P (type))
6474 150100 : ggc_free (TYPE_CACHED_VALUES (type));
6475 : }
6476 680379000 : free_node (type);
6477 680379000 : return t1;
6478 : }
6479 : else
6480 : {
6481 774717901 : struct type_hash *h;
6482 :
6483 774717901 : h = ggc_alloc<type_hash> ();
6484 774717901 : h->hash = hashcode;
6485 774717901 : h->type = type;
6486 774717901 : *loc = h;
6487 :
6488 774717901 : return type;
6489 : }
6490 : }
6491 :
6492 : static void
6493 0 : print_type_hash_statistics (void)
6494 : {
6495 0 : fprintf (stderr, "Type hash: size " HOST_SIZE_T_PRINT_DEC ", "
6496 : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6497 0 : (fmt_size_t) type_hash_table->size (),
6498 0 : (fmt_size_t) type_hash_table->elements (),
6499 : type_hash_table->collisions ());
6500 0 : }
6501 :
6502 : /* Given two lists of types
6503 : (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6504 : return 1 if the lists contain the same types in the same order.
6505 : Also, the TREE_PURPOSEs must match. */
6506 :
6507 : bool
6508 257833127 : type_list_equal (const_tree l1, const_tree l2)
6509 : {
6510 257833127 : const_tree t1, t2;
6511 :
6512 968556425 : for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
6513 738888240 : if (TREE_VALUE (t1) != TREE_VALUE (t2)
6514 738888240 : || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
6515 28166792 : && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
6516 1887 : && (TREE_TYPE (TREE_PURPOSE (t1))
6517 1887 : == TREE_TYPE (TREE_PURPOSE (t2))))))
6518 28164942 : return false;
6519 :
6520 229668185 : return t1 == t2;
6521 : }
6522 :
6523 : /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6524 : given by TYPE. If the argument list accepts variable arguments,
6525 : then this function counts only the ordinary arguments. */
6526 :
6527 : int
6528 80987555 : type_num_arguments (const_tree fntype)
6529 : {
6530 80987555 : int i = 0;
6531 :
6532 314488656 : for (tree t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
6533 : /* If the function does not take a variable number of arguments,
6534 : the last element in the list will have type `void'. */
6535 295505535 : if (VOID_TYPE_P (TREE_VALUE (t)))
6536 : break;
6537 : else
6538 233501101 : ++i;
6539 :
6540 80987555 : return i;
6541 : }
6542 :
6543 : /* Return the type of the function TYPE's argument ARGNO if known.
6544 : For vararg function's where ARGNO refers to one of the variadic
6545 : arguments return null. Otherwise, return a void_type_node for
6546 : out-of-bounds ARGNO. */
6547 :
6548 : tree
6549 79915304 : type_argument_type (const_tree fntype, unsigned argno)
6550 : {
6551 : /* Treat zero the same as an out-of-bounds argument number. */
6552 79915304 : if (!argno)
6553 0 : return void_type_node;
6554 :
6555 79915304 : function_args_iterator iter;
6556 :
6557 79915304 : tree argtype;
6558 79915304 : unsigned i = 1;
6559 172199942 : FOREACH_FUNCTION_ARGS (fntype, argtype, iter)
6560 : {
6561 : /* A vararg function's argument list ends in a null. Otherwise,
6562 : an ordinary function's argument list ends with void. Return
6563 : null if ARGNO refers to a vararg argument, void_type_node if
6564 : it's out of bounds, and the formal argument type otherwise. */
6565 166502913 : if (!argtype)
6566 : break;
6567 :
6568 166502913 : if (i == argno || VOID_TYPE_P (argtype))
6569 : return argtype;
6570 :
6571 92284638 : ++i;
6572 : }
6573 :
6574 : return NULL_TREE;
6575 : }
6576 :
6577 : /* True if integer constants T1 and T2
6578 : represent the same constant value. */
6579 :
6580 : bool
6581 1324550209 : tree_int_cst_equal (const_tree t1, const_tree t2)
6582 : {
6583 1324550209 : if (t1 == t2)
6584 : return true;
6585 :
6586 671765379 : if (t1 == 0 || t2 == 0)
6587 : return false;
6588 :
6589 671357912 : STRIP_ANY_LOCATION_WRAPPER (t1);
6590 671357912 : STRIP_ANY_LOCATION_WRAPPER (t2);
6591 :
6592 671357912 : if (TREE_CODE (t1) == INTEGER_CST
6593 667291395 : && TREE_CODE (t2) == INTEGER_CST
6594 1338649307 : && wi::to_widest (t1) == wi::to_widest (t2))
6595 20297327 : return true;
6596 :
6597 : return false;
6598 : }
6599 :
6600 : /* Return true if T is an INTEGER_CST whose numerical value (extended
6601 : according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. */
6602 :
6603 : bool
6604 2381182607 : tree_fits_shwi_p (const_tree t)
6605 : {
6606 2381182607 : return (t != NULL_TREE
6607 2381182516 : && TREE_CODE (t) == INTEGER_CST
6608 4759705405 : && wi::fits_shwi_p (wi::to_widest (t)));
6609 : }
6610 :
6611 : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6612 : value (extended according to TYPE_UNSIGNED) fits in a poly_int64. */
6613 :
6614 : bool
6615 999092230 : tree_fits_poly_int64_p (const_tree t)
6616 : {
6617 999092230 : if (t == NULL_TREE)
6618 : return false;
6619 961670892 : if (POLY_INT_CST_P (t))
6620 : {
6621 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6622 : if (!wi::fits_shwi_p (wi::to_wide (POLY_INT_CST_COEFF (t, i))))
6623 : return false;
6624 : return true;
6625 : }
6626 961670892 : return (TREE_CODE (t) == INTEGER_CST
6627 1923447507 : && wi::fits_shwi_p (wi::to_widest (t)));
6628 : }
6629 :
6630 : /* Return true if T is an INTEGER_CST whose numerical value (extended
6631 : according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
6632 :
6633 : bool
6634 4141522615 : tree_fits_uhwi_p (const_tree t)
6635 : {
6636 4141522615 : return (t != NULL_TREE
6637 4140914457 : && TREE_CODE (t) == INTEGER_CST
6638 8277201890 : && wi::fits_uhwi_p (wi::to_widest (t)));
6639 : }
6640 :
6641 : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6642 : value (extended according to TYPE_UNSIGNED) fits in a poly_uint64. */
6643 :
6644 : bool
6645 1082503705 : tree_fits_poly_uint64_p (const_tree t)
6646 : {
6647 1082503705 : if (t == NULL_TREE)
6648 : return false;
6649 1082144804 : if (POLY_INT_CST_P (t))
6650 : {
6651 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6652 : if (!wi::fits_uhwi_p (wi::to_widest (POLY_INT_CST_COEFF (t, i))))
6653 : return false;
6654 : return true;
6655 : }
6656 1082144804 : return (TREE_CODE (t) == INTEGER_CST
6657 2164291002 : && wi::fits_uhwi_p (wi::to_widest (t)));
6658 : }
6659 :
6660 : /* Return true if T is an INTEGER_CST whose numerical value (extended according
6661 : to TYPE_UNSIGNED) fits in a sanitize_code_type (uint64_t). */
6662 :
6663 : bool
6664 90 : tree_fits_sanitize_code_type_p (const_tree t)
6665 : {
6666 90 : if (t == NULL_TREE)
6667 : return false;
6668 90 : return (TREE_CODE (t) == INTEGER_CST
6669 180 : && wi::fits_uhwi_p (wi::to_widest (t)));
6670 : }
6671 :
6672 : /* T is an INTEGER_CST whose numerical value (extended according to
6673 : TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that
6674 : HOST_WIDE_INT. */
6675 :
6676 : HOST_WIDE_INT
6677 1408550742 : tree_to_shwi (const_tree t)
6678 : {
6679 1408550742 : gcc_assert (tree_fits_shwi_p (t));
6680 1408550742 : return TREE_INT_CST_LOW (t);
6681 : }
6682 :
6683 : /* T is an INTEGER_CST whose numerical value (extended according to
6684 : TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. Return that
6685 : HOST_WIDE_INT. */
6686 :
6687 : unsigned HOST_WIDE_INT
6688 1012347566 : tree_to_uhwi (const_tree t)
6689 : {
6690 1012347566 : gcc_assert (tree_fits_uhwi_p (t));
6691 1012347566 : return TREE_INT_CST_LOW (t);
6692 : }
6693 :
6694 : /* T is an INTEGER_CST whose numerical value (extended according to
6695 : TYPE_UNSIGNED) fits in a sanitize_code_type. Return that
6696 : sanitize_code_type. */
6697 :
6698 : sanitize_code_type
6699 90 : tree_to_sanitize_code_type (const_tree t)
6700 : {
6701 90 : gcc_assert (tree_fits_sanitize_code_type_p (t));
6702 90 : return TREE_INT_CST_LOW (t);
6703 : }
6704 :
6705 : /* Return the most significant (sign) bit of T. */
6706 :
6707 : int
6708 44291389 : tree_int_cst_sign_bit (const_tree t)
6709 : {
6710 44291389 : unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1;
6711 :
6712 44291389 : return wi::extract_uhwi (wi::to_wide (t), bitno, 1);
6713 : }
6714 :
6715 : /* Return an indication of the sign of the integer constant T.
6716 : The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6717 : Note that -1 will never be returned if T's type is unsigned. */
6718 :
6719 : int
6720 1896857593 : tree_int_cst_sgn (const_tree t)
6721 : {
6722 1896857593 : if (wi::to_wide (t) == 0)
6723 : return 0;
6724 1763847535 : else if (TYPE_UNSIGNED (TREE_TYPE (t)))
6725 : return 1;
6726 84609261 : else if (wi::neg_p (wi::to_wide (t)))
6727 : return -1;
6728 : else
6729 : return 1;
6730 : }
6731 :
6732 : /* Return the minimum number of bits needed to represent VALUE in a
6733 : signed or unsigned type, UNSIGNEDP says which. */
6734 :
6735 : unsigned int
6736 3733224 : tree_int_cst_min_precision (tree value, signop sgn)
6737 : {
6738 : /* If the value is negative, compute its negative minus 1. The latter
6739 : adjustment is because the absolute value of the largest negative value
6740 : is one larger than the largest positive value. This is equivalent to
6741 : a bit-wise negation, so use that operation instead. */
6742 :
6743 3733224 : if (tree_int_cst_sgn (value) < 0)
6744 106684 : value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value);
6745 :
6746 : /* Return the number of bits needed, taking into account the fact
6747 : that we need one more bit for a signed than unsigned type.
6748 : If value is 0 or -1, the minimum precision is 1 no matter
6749 : whether unsignedp is true or false. */
6750 :
6751 3733224 : if (integer_zerop (value))
6752 : return 1;
6753 : else
6754 5363356 : return tree_floor_log2 (value) + 1 + (sgn == SIGNED ? 1 : 0) ;
6755 : }
6756 :
6757 : /* Return truthvalue of whether T1 is the same tree structure as T2.
6758 : Return 1 if they are the same.
6759 : Return 0 if they are understandably different.
6760 : Return -1 if either contains tree structure not understood by
6761 : this function. */
6762 :
6763 : int
6764 208129224 : simple_cst_equal (const_tree t1, const_tree t2)
6765 : {
6766 211915794 : enum tree_code code1, code2;
6767 211915794 : int cmp;
6768 211915794 : int i;
6769 :
6770 211915794 : if (t1 == t2)
6771 : return 1;
6772 135999016 : if (t1 == 0 || t2 == 0)
6773 : return 0;
6774 :
6775 : /* For location wrappers to be the same, they must be at the same
6776 : source location (and wrap the same thing). */
6777 127102412 : if (location_wrapper_p (t1) && location_wrapper_p (t2))
6778 : {
6779 13371427 : if (EXPR_LOCATION (t1) != EXPR_LOCATION (t2))
6780 : return 0;
6781 738 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6782 : }
6783 :
6784 113730985 : code1 = TREE_CODE (t1);
6785 113730985 : code2 = TREE_CODE (t2);
6786 :
6787 113730985 : if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR)
6788 : {
6789 3773894 : if (CONVERT_EXPR_CODE_P (code2)
6790 3773180 : || code2 == NON_LVALUE_EXPR)
6791 714 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6792 : else
6793 3773180 : return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
6794 : }
6795 :
6796 109957091 : else if (CONVERT_EXPR_CODE_P (code2)
6797 109957076 : || code2 == NON_LVALUE_EXPR)
6798 113 : return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
6799 :
6800 109956978 : if (code1 != code2)
6801 : return 0;
6802 :
6803 105480885 : switch (code1)
6804 : {
6805 95651609 : case INTEGER_CST:
6806 95651609 : return wi::to_widest (t1) == wi::to_widest (t2);
6807 :
6808 93 : case REAL_CST:
6809 93 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
6810 :
6811 0 : case FIXED_CST:
6812 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
6813 :
6814 3210056 : case STRING_CST:
6815 3210056 : return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
6816 3210056 : && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
6817 3680584 : TREE_STRING_LENGTH (t1)));
6818 :
6819 479 : case CONSTRUCTOR:
6820 479 : {
6821 479 : unsigned HOST_WIDE_INT idx;
6822 479 : vec<constructor_elt, va_gc> *v1 = CONSTRUCTOR_ELTS (t1);
6823 479 : vec<constructor_elt, va_gc> *v2 = CONSTRUCTOR_ELTS (t2);
6824 :
6825 503 : if (vec_safe_length (v1) != vec_safe_length (v2))
6826 : return 0;
6827 :
6828 485 : for (idx = 0; idx < vec_safe_length (v1); ++idx)
6829 : {
6830 12 : if ((*v1)[idx].index
6831 12 : && TREE_CODE ((*v1)[idx].index) == FIELD_DECL)
6832 : {
6833 9 : if ((*v1)[idx].index != (*v2)[idx].index)
6834 : return 0;
6835 : }
6836 : else
6837 : {
6838 3 : cmp = simple_cst_equal ((*v1)[idx].index, (*v2)[idx].index);
6839 3 : if (cmp <= 0)
6840 : return cmp;
6841 : }
6842 12 : cmp = simple_cst_equal ((*v1)[idx].value, (*v2)[idx].value);
6843 12 : if (cmp <= 0)
6844 : return cmp;
6845 : }
6846 : return 1;
6847 : }
6848 :
6849 0 : case SAVE_EXPR:
6850 0 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6851 :
6852 207206 : case CALL_EXPR:
6853 207206 : cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2));
6854 207206 : if (cmp <= 0)
6855 : return cmp;
6856 85559 : if (call_expr_nargs (t1) != call_expr_nargs (t2))
6857 : return 0;
6858 85559 : {
6859 85559 : const_tree arg1, arg2;
6860 85559 : const_call_expr_arg_iterator iter1, iter2;
6861 171118 : for (arg1 = first_const_call_expr_arg (t1, &iter1),
6862 85559 : arg2 = first_const_call_expr_arg (t2, &iter2);
6863 85593 : arg1 && arg2;
6864 34 : arg1 = next_const_call_expr_arg (&iter1),
6865 34 : arg2 = next_const_call_expr_arg (&iter2))
6866 : {
6867 85533 : cmp = simple_cst_equal (arg1, arg2);
6868 85533 : if (cmp <= 0)
6869 : return cmp;
6870 : }
6871 60 : return arg1 == arg2;
6872 : }
6873 :
6874 11617 : case TARGET_EXPR:
6875 : /* Special case: if either target is an unallocated VAR_DECL,
6876 : it means that it's going to be unified with whatever the
6877 : TARGET_EXPR is really supposed to initialize, so treat it
6878 : as being equivalent to anything. */
6879 11617 : if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
6880 11617 : && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
6881 11617 : && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
6882 11617 : || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
6883 0 : && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
6884 0 : && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
6885 : cmp = 1;
6886 : else
6887 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6888 :
6889 0 : if (cmp <= 0)
6890 : return cmp;
6891 :
6892 11617 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
6893 :
6894 0 : case WITH_CLEANUP_EXPR:
6895 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6896 0 : if (cmp <= 0)
6897 : return cmp;
6898 :
6899 0 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
6900 :
6901 208 : case COMPONENT_REF:
6902 208 : if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
6903 208 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6904 :
6905 : return 0;
6906 :
6907 : case VAR_DECL:
6908 : case PARM_DECL:
6909 : case CONST_DECL:
6910 : case FUNCTION_DECL:
6911 : return 0;
6912 :
6913 6335247 : default:
6914 6335247 : if (POLY_INT_CST_P (t1))
6915 : /* A false return means maybe_ne rather than known_ne. */
6916 : return known_eq (poly_widest_int::from (poly_int_cst_value (t1),
6917 : TYPE_SIGN (TREE_TYPE (t1))),
6918 : poly_widest_int::from (poly_int_cst_value (t2),
6919 : TYPE_SIGN (TREE_TYPE (t2))));
6920 6335247 : break;
6921 : }
6922 :
6923 : /* This general rule works for most tree codes. All exceptions should be
6924 : handled above. If this is a language-specific tree code, we can't
6925 : trust what might be in the operand, so say we don't know
6926 : the situation. */
6927 6335247 : if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
6928 : return -1;
6929 :
6930 874761 : switch (TREE_CODE_CLASS (code1))
6931 : {
6932 : case tcc_unary:
6933 : case tcc_binary:
6934 : case tcc_comparison:
6935 : case tcc_expression:
6936 : case tcc_reference:
6937 : case tcc_statement:
6938 : cmp = 1;
6939 1172 : for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
6940 : {
6941 903 : cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
6942 903 : if (cmp <= 0)
6943 : return cmp;
6944 : }
6945 :
6946 : return cmp;
6947 :
6948 : default:
6949 : return -1;
6950 : }
6951 : }
6952 :
6953 : /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
6954 : Return -1, 0, or 1 if the value of T is less than, equal to, or greater
6955 : than U, respectively. */
6956 :
6957 : int
6958 1546221397 : compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u)
6959 : {
6960 1546221397 : if (tree_int_cst_sgn (t) < 0)
6961 : return -1;
6962 1546221119 : else if (!tree_fits_uhwi_p (t))
6963 : return 1;
6964 1546221094 : else if (TREE_INT_CST_LOW (t) == u)
6965 : return 0;
6966 1377883833 : else if (TREE_INT_CST_LOW (t) < u)
6967 : return -1;
6968 : else
6969 13877569 : return 1;
6970 : }
6971 :
6972 : /* Return true if SIZE represents a constant size that is in bounds of
6973 : what the middle-end and the backend accepts (covering not more than
6974 : half of the address-space).
6975 : When PERR is non-null, set *PERR on failure to the description of
6976 : why SIZE is not valid. */
6977 :
6978 : bool
6979 69060059 : valid_constant_size_p (const_tree size, cst_size_error *perr /* = NULL */)
6980 : {
6981 69060059 : if (POLY_INT_CST_P (size))
6982 : {
6983 : if (TREE_OVERFLOW (size))
6984 : return false;
6985 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
6986 : if (!valid_constant_size_p (POLY_INT_CST_COEFF (size, i)))
6987 : return false;
6988 : return true;
6989 : }
6990 :
6991 69060059 : cst_size_error error;
6992 69060059 : if (!perr)
6993 63318558 : perr = &error;
6994 :
6995 69060059 : if (TREE_CODE (size) != INTEGER_CST)
6996 : {
6997 3 : *perr = cst_size_not_constant;
6998 3 : return false;
6999 : }
7000 :
7001 69060056 : if (TREE_OVERFLOW_P (size))
7002 : {
7003 60 : *perr = cst_size_overflow;
7004 60 : return false;
7005 : }
7006 :
7007 69059996 : if (tree_int_cst_sgn (size) < 0)
7008 : {
7009 410 : *perr = cst_size_negative;
7010 410 : return false;
7011 : }
7012 138119172 : if (!tree_fits_uhwi_p (size)
7013 207178758 : || (wi::to_widest (TYPE_MAX_VALUE (sizetype))
7014 207178758 : < wi::to_widest (size) * 2))
7015 : {
7016 624 : *perr = cst_size_too_big;
7017 624 : return false;
7018 : }
7019 :
7020 : return true;
7021 : }
7022 :
7023 : /* Return the precision of the type, or for a complex or vector type the
7024 : precision of the type of its elements. */
7025 :
7026 : unsigned int
7027 7594539452 : element_precision (const_tree type)
7028 : {
7029 7594539452 : if (!TYPE_P (type))
7030 6206474 : type = TREE_TYPE (type);
7031 7594539452 : enum tree_code code = TREE_CODE (type);
7032 7594539452 : if (code == COMPLEX_TYPE || code == VECTOR_TYPE)
7033 57098046 : type = TREE_TYPE (type);
7034 :
7035 7594539452 : return TYPE_PRECISION (type);
7036 : }
7037 :
7038 : /* Return true if CODE represents an associative tree code. Otherwise
7039 : return false. */
7040 : bool
7041 36034196 : associative_tree_code (enum tree_code code)
7042 : {
7043 36034196 : switch (code)
7044 : {
7045 : case BIT_IOR_EXPR:
7046 : case BIT_AND_EXPR:
7047 : case BIT_XOR_EXPR:
7048 : case PLUS_EXPR:
7049 : case MULT_EXPR:
7050 : case MIN_EXPR:
7051 : case MAX_EXPR:
7052 : return true;
7053 :
7054 25299593 : default:
7055 25299593 : break;
7056 : }
7057 25299593 : return false;
7058 : }
7059 :
7060 : /* Return true if CODE represents a commutative tree code. Otherwise
7061 : return false. */
7062 : bool
7063 1788889698 : commutative_tree_code (enum tree_code code)
7064 : {
7065 1788889698 : switch (code)
7066 : {
7067 : case PLUS_EXPR:
7068 : case MULT_EXPR:
7069 : case MULT_HIGHPART_EXPR:
7070 : case MIN_EXPR:
7071 : case MAX_EXPR:
7072 : case BIT_IOR_EXPR:
7073 : case BIT_XOR_EXPR:
7074 : case BIT_AND_EXPR:
7075 : case NE_EXPR:
7076 : case EQ_EXPR:
7077 : case UNORDERED_EXPR:
7078 : case ORDERED_EXPR:
7079 : case UNEQ_EXPR:
7080 : case LTGT_EXPR:
7081 : case TRUTH_AND_EXPR:
7082 : case TRUTH_XOR_EXPR:
7083 : case TRUTH_OR_EXPR:
7084 : case WIDEN_MULT_EXPR:
7085 : case VEC_WIDEN_MULT_HI_EXPR:
7086 : case VEC_WIDEN_MULT_LO_EXPR:
7087 : case VEC_WIDEN_MULT_EVEN_EXPR:
7088 : case VEC_WIDEN_MULT_ODD_EXPR:
7089 : return true;
7090 :
7091 956220709 : default:
7092 956220709 : break;
7093 : }
7094 956220709 : return false;
7095 : }
7096 :
7097 : /* Return true if CODE represents a ternary tree code for which the
7098 : first two operands are commutative. Otherwise return false. */
7099 : bool
7100 96258124 : commutative_ternary_tree_code (enum tree_code code)
7101 : {
7102 96258124 : switch (code)
7103 : {
7104 : case WIDEN_MULT_PLUS_EXPR:
7105 : case WIDEN_MULT_MINUS_EXPR:
7106 : case DOT_PROD_EXPR:
7107 : return true;
7108 :
7109 96248576 : default:
7110 96248576 : break;
7111 : }
7112 96248576 : return false;
7113 : }
7114 :
7115 : /* Returns true if CODE can overflow. */
7116 :
7117 : bool
7118 2810 : operation_can_overflow (enum tree_code code)
7119 : {
7120 2810 : switch (code)
7121 : {
7122 : case PLUS_EXPR:
7123 : case MINUS_EXPR:
7124 : case MULT_EXPR:
7125 : case LSHIFT_EXPR:
7126 : /* Can overflow in various ways. */
7127 : return true;
7128 : case TRUNC_DIV_EXPR:
7129 : case EXACT_DIV_EXPR:
7130 : case FLOOR_DIV_EXPR:
7131 : case CEIL_DIV_EXPR:
7132 : /* For INT_MIN / -1. */
7133 : return true;
7134 : case NEGATE_EXPR:
7135 : case ABS_EXPR:
7136 : /* For -INT_MIN. */
7137 : return true;
7138 163 : default:
7139 : /* These operators cannot overflow. */
7140 163 : return false;
7141 : }
7142 : }
7143 :
7144 : /* Returns true if CODE operating on operands of type TYPE doesn't overflow, or
7145 : ftrapv doesn't generate trapping insns for CODE. */
7146 :
7147 : bool
7148 6170249 : operation_no_trapping_overflow (tree type, enum tree_code code)
7149 : {
7150 6170249 : gcc_checking_assert (ANY_INTEGRAL_TYPE_P (type));
7151 :
7152 : /* We don't generate instructions that trap on overflow for complex or vector
7153 : types. */
7154 6170249 : if (!INTEGRAL_TYPE_P (type))
7155 : return true;
7156 :
7157 6170249 : if (!TYPE_OVERFLOW_TRAPS (type))
7158 : return true;
7159 :
7160 1345 : switch (code)
7161 : {
7162 : case PLUS_EXPR:
7163 : case MINUS_EXPR:
7164 : case MULT_EXPR:
7165 : case NEGATE_EXPR:
7166 : case ABS_EXPR:
7167 : /* These operators can overflow, and -ftrapv generates trapping code for
7168 : these. */
7169 : return false;
7170 : case TRUNC_DIV_EXPR:
7171 : case EXACT_DIV_EXPR:
7172 : case FLOOR_DIV_EXPR:
7173 : case CEIL_DIV_EXPR:
7174 : case LSHIFT_EXPR:
7175 : /* These operators can overflow, but -ftrapv does not generate trapping
7176 : code for these. */
7177 : return true;
7178 : default:
7179 : /* These operators cannot overflow. */
7180 : return true;
7181 : }
7182 : }
7183 :
7184 : /* Constructors for pointer, array and function types.
7185 : (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7186 : constructed by language-dependent code, not here.) */
7187 :
7188 : /* Construct, lay out and return the type of pointers to TO_TYPE with
7189 : mode MODE. If MODE is VOIDmode, a pointer mode for the address
7190 : space of TO_TYPE will be picked. If CAN_ALIAS_ALL is TRUE,
7191 : indicate this type can reference all of memory. If such a type has
7192 : already been constructed, reuse it. */
7193 :
7194 : tree
7195 2635718594 : build_pointer_type_for_mode (tree to_type, machine_mode mode,
7196 : bool can_alias_all)
7197 : {
7198 2635718594 : tree t;
7199 2635718594 : bool could_alias = can_alias_all;
7200 :
7201 2635718594 : if (to_type == error_mark_node)
7202 : return error_mark_node;
7203 :
7204 2635718588 : if (mode == VOIDmode)
7205 : {
7206 2507110386 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7207 2507110386 : mode = targetm.addr_space.pointer_mode (as);
7208 : }
7209 :
7210 : /* If the pointed-to type has the may_alias attribute set, force
7211 : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7212 2635718588 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7213 4486676 : can_alias_all = true;
7214 :
7215 : /* In some cases, languages will have things that aren't a POINTER_TYPE
7216 : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7217 : In that case, return that type without regard to the rest of our
7218 : operands.
7219 :
7220 : ??? This is a kludge, but consistent with the way this function has
7221 : always operated and there doesn't seem to be a good way to avoid this
7222 : at the moment. */
7223 2635718588 : if (TYPE_POINTER_TO (to_type) != 0
7224 2635718588 : && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
7225 49945 : return TYPE_POINTER_TO (to_type);
7226 :
7227 : /* First, if we already have a type for pointers to TO_TYPE and it's
7228 : the proper mode, use it. */
7229 2636390395 : for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
7230 2482785419 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7231 : return t;
7232 :
7233 153604976 : t = make_node (POINTER_TYPE);
7234 :
7235 153604976 : TREE_TYPE (t) = to_type;
7236 153604976 : SET_TYPE_MODE (t, mode);
7237 153604976 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7238 153604976 : TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
7239 153604976 : TYPE_POINTER_TO (to_type) = t;
7240 :
7241 : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7242 153604976 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7243 5325782 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7244 148279194 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7245 44448000 : TYPE_CANONICAL (t)
7246 88896000 : = build_pointer_type_for_mode (TYPE_CANONICAL (to_type),
7247 : mode, false);
7248 :
7249 : /* Lay out the type. This function has many callers that are concerned
7250 : with expression-construction, and this simplifies them all. */
7251 153604976 : layout_type (t);
7252 :
7253 153604976 : return t;
7254 : }
7255 :
7256 : /* By default build pointers in ptr_mode. */
7257 :
7258 : tree
7259 2506397499 : build_pointer_type (tree to_type)
7260 : {
7261 2506397499 : return build_pointer_type_for_mode (to_type, VOIDmode, false);
7262 : }
7263 :
7264 : /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7265 :
7266 : tree
7267 735552736 : build_reference_type_for_mode (tree to_type, machine_mode mode,
7268 : bool can_alias_all)
7269 : {
7270 735552736 : tree t;
7271 735552736 : bool could_alias = can_alias_all;
7272 :
7273 735552736 : if (to_type == error_mark_node)
7274 : return error_mark_node;
7275 :
7276 735552736 : if (mode == VOIDmode)
7277 : {
7278 581700262 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7279 581700262 : mode = targetm.addr_space.pointer_mode (as);
7280 : }
7281 :
7282 : /* If the pointed-to type has the may_alias attribute set, force
7283 : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7284 735552736 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7285 753017 : can_alias_all = true;
7286 :
7287 : /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7288 : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7289 : In that case, return that type without regard to the rest of our
7290 : operands.
7291 :
7292 : ??? This is a kludge, but consistent with the way this function has
7293 : always operated and there doesn't seem to be a good way to avoid this
7294 : at the moment. */
7295 735552736 : if (TYPE_REFERENCE_TO (to_type) != 0
7296 735552736 : && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
7297 0 : return TYPE_REFERENCE_TO (to_type);
7298 :
7299 : /* First, if we already have a type for pointers to TO_TYPE and it's
7300 : the proper mode, use it. */
7301 735552736 : for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
7302 642196456 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7303 : return t;
7304 :
7305 93356280 : t = make_node (REFERENCE_TYPE);
7306 :
7307 93356280 : TREE_TYPE (t) = to_type;
7308 93356280 : SET_TYPE_MODE (t, mode);
7309 93356280 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7310 93356280 : TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
7311 93356280 : TYPE_REFERENCE_TO (to_type) = t;
7312 :
7313 : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7314 93356280 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7315 5070225 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7316 88286055 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7317 52270455 : TYPE_CANONICAL (t)
7318 104540910 : = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
7319 : mode, false);
7320 :
7321 93356280 : layout_type (t);
7322 :
7323 93356280 : return t;
7324 : }
7325 :
7326 :
7327 : /* Build the node for the type of references-to-TO_TYPE by default
7328 : in ptr_mode. */
7329 :
7330 : tree
7331 27956629 : build_reference_type (tree to_type)
7332 : {
7333 27956629 : return build_reference_type_for_mode (to_type, VOIDmode, false);
7334 : }
7335 :
7336 : #define MAX_INT_CACHED_PREC \
7337 : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7338 : static GTY(()) tree nonstandard_integer_type_cache[2 * MAX_INT_CACHED_PREC + 2];
7339 :
7340 : static void
7341 262609 : clear_nonstandard_integer_type_cache (void)
7342 : {
7343 34401779 : for (size_t i = 0 ; i < 2 * MAX_INT_CACHED_PREC + 2 ; i++)
7344 : {
7345 34139170 : nonstandard_integer_type_cache[i] = NULL;
7346 : }
7347 0 : }
7348 :
7349 : /* Builds a signed or unsigned integer type of precision PRECISION.
7350 : Used for C bitfields whose precision does not match that of
7351 : built-in target types. */
7352 : tree
7353 63779747 : build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
7354 : int unsignedp)
7355 : {
7356 63779747 : tree itype, ret;
7357 :
7358 63779747 : if (unsignedp)
7359 54886153 : unsignedp = MAX_INT_CACHED_PREC + 1;
7360 :
7361 63779747 : if (precision <= MAX_INT_CACHED_PREC)
7362 : {
7363 63419743 : itype = nonstandard_integer_type_cache[precision + unsignedp];
7364 63419743 : if (itype)
7365 : return itype;
7366 : }
7367 :
7368 1078890 : itype = make_node (INTEGER_TYPE);
7369 1078890 : TYPE_PRECISION (itype) = precision;
7370 :
7371 1078890 : if (unsignedp)
7372 706829 : fixup_unsigned_type (itype);
7373 : else
7374 372061 : fixup_signed_type (itype);
7375 :
7376 1078890 : inchash::hash hstate;
7377 1078890 : inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7378 1078890 : ret = type_hash_canon (hstate.end (), itype);
7379 1078890 : if (precision <= MAX_INT_CACHED_PREC)
7380 718886 : nonstandard_integer_type_cache[precision + unsignedp] = ret;
7381 :
7382 : return ret;
7383 : }
7384 :
7385 : #define MAX_BOOL_CACHED_PREC \
7386 : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7387 : static GTY(()) tree nonstandard_boolean_type_cache[MAX_BOOL_CACHED_PREC + 1];
7388 :
7389 : /* Builds a boolean type of precision PRECISION.
7390 : Used for boolean vectors to choose proper vector element size. */
7391 : tree
7392 2758207 : build_nonstandard_boolean_type (unsigned HOST_WIDE_INT precision)
7393 : {
7394 2758207 : tree type;
7395 :
7396 2758207 : if (precision <= MAX_BOOL_CACHED_PREC)
7397 : {
7398 2754159 : type = nonstandard_boolean_type_cache[precision];
7399 2754159 : if (type)
7400 : return type;
7401 : }
7402 :
7403 83589 : type = make_node (BOOLEAN_TYPE);
7404 83589 : TYPE_PRECISION (type) = precision;
7405 83589 : fixup_signed_type (type);
7406 :
7407 83589 : if (precision <= MAX_INT_CACHED_PREC)
7408 79541 : nonstandard_boolean_type_cache[precision] = type;
7409 :
7410 : return type;
7411 : }
7412 :
7413 : static GTY(()) vec<tree, va_gc> *bitint_type_cache;
7414 :
7415 : /* Builds a signed or unsigned _BitInt(PRECISION) type. */
7416 : tree
7417 75257 : build_bitint_type (unsigned HOST_WIDE_INT precision, int unsignedp)
7418 : {
7419 75257 : tree itype, ret;
7420 :
7421 75257 : gcc_checking_assert (precision >= 1);
7422 :
7423 75257 : if (unsignedp)
7424 37076 : unsignedp = MAX_INT_CACHED_PREC + 1;
7425 :
7426 75257 : if (bitint_type_cache == NULL)
7427 590 : vec_safe_grow_cleared (bitint_type_cache, 2 * MAX_INT_CACHED_PREC + 2);
7428 :
7429 75257 : if (precision <= MAX_INT_CACHED_PREC)
7430 : {
7431 16501 : itype = (*bitint_type_cache)[precision + unsignedp];
7432 16501 : if (itype)
7433 : return itype;
7434 : }
7435 :
7436 60481 : itype = make_node (BITINT_TYPE);
7437 60481 : TYPE_PRECISION (itype) = precision;
7438 :
7439 60481 : if (unsignedp)
7440 30249 : fixup_unsigned_type (itype);
7441 : else
7442 30232 : fixup_signed_type (itype);
7443 :
7444 60481 : hashval_t hash = type_hash_canon_hash (itype);
7445 60481 : ret = type_hash_canon (hash, itype);
7446 60481 : if (precision <= MAX_INT_CACHED_PREC)
7447 1725 : (*bitint_type_cache)[precision + unsignedp] = ret;
7448 :
7449 : return ret;
7450 : }
7451 :
7452 : /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7453 : or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7454 : is true, reuse such a type that has already been constructed. */
7455 :
7456 : static tree
7457 45200145 : build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
7458 : {
7459 45200145 : tree itype = make_node (INTEGER_TYPE);
7460 :
7461 45200145 : TREE_TYPE (itype) = type;
7462 :
7463 45200145 : TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
7464 45200145 : TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
7465 :
7466 45200145 : TYPE_PRECISION (itype) = TYPE_PRECISION (type);
7467 45200145 : SET_TYPE_MODE (itype, TYPE_MODE (type));
7468 45200145 : TYPE_SIZE (itype) = TYPE_SIZE (type);
7469 45200145 : TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
7470 45200145 : SET_TYPE_ALIGN (itype, TYPE_ALIGN (type));
7471 45200145 : TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
7472 45200145 : SET_TYPE_WARN_IF_NOT_ALIGN (itype, TYPE_WARN_IF_NOT_ALIGN (type));
7473 :
7474 45200145 : if (!shared)
7475 : return itype;
7476 :
7477 45200145 : if ((TYPE_MIN_VALUE (itype)
7478 45200145 : && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST)
7479 90399453 : || (TYPE_MAX_VALUE (itype)
7480 44644460 : && TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST))
7481 : {
7482 : /* Since we cannot reliably merge this type, we need to compare it using
7483 : structural equality checks. */
7484 1196292 : SET_TYPE_STRUCTURAL_EQUALITY (itype);
7485 1196292 : return itype;
7486 : }
7487 :
7488 44003853 : hashval_t hash = type_hash_canon_hash (itype);
7489 44003853 : itype = type_hash_canon (hash, itype);
7490 :
7491 44003853 : return itype;
7492 : }
7493 :
7494 : /* Wrapper around build_range_type_1 with SHARED set to true. */
7495 :
7496 : tree
7497 45200145 : build_range_type (tree type, tree lowval, tree highval)
7498 : {
7499 45200145 : return build_range_type_1 (type, lowval, highval, true);
7500 : }
7501 :
7502 : /* Wrapper around build_range_type_1 with SHARED set to false. */
7503 :
7504 : tree
7505 0 : build_nonshared_range_type (tree type, tree lowval, tree highval)
7506 : {
7507 0 : return build_range_type_1 (type, lowval, highval, false);
7508 : }
7509 :
7510 : /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7511 : MAXVAL should be the maximum value in the domain
7512 : (one less than the length of the array).
7513 :
7514 : The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7515 : We don't enforce this limit, that is up to caller (e.g. language front end).
7516 : The limit exists because the result is a signed type and we don't handle
7517 : sizes that use more than one HOST_WIDE_INT. */
7518 :
7519 : tree
7520 42252354 : build_index_type (tree maxval)
7521 : {
7522 42252354 : return build_range_type (sizetype, size_zero_node, maxval);
7523 : }
7524 :
7525 : /* Return true if the debug information for TYPE, a subtype, should be emitted
7526 : as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7527 : high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7528 : debug info and doesn't reflect the source code. */
7529 :
7530 : bool
7531 18 : subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval)
7532 : {
7533 18 : tree base_type = TREE_TYPE (type), low, high;
7534 :
7535 : /* Subrange types have a base type which is an integral type. */
7536 18 : if (!INTEGRAL_TYPE_P (base_type))
7537 : return false;
7538 :
7539 : /* Get the real bounds of the subtype. */
7540 18 : if (lang_hooks.types.get_subrange_bounds)
7541 0 : lang_hooks.types.get_subrange_bounds (type, &low, &high);
7542 : else
7543 : {
7544 18 : low = TYPE_MIN_VALUE (type);
7545 18 : high = TYPE_MAX_VALUE (type);
7546 : }
7547 :
7548 : /* If the type and its base type have the same representation and the same
7549 : name, then the type is not a subrange but a copy of the base type. */
7550 18 : if ((TREE_CODE (base_type) == INTEGER_TYPE
7551 18 : || TREE_CODE (base_type) == BOOLEAN_TYPE)
7552 18 : && int_size_in_bytes (type) == int_size_in_bytes (base_type)
7553 18 : && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type))
7554 0 : && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type))
7555 18 : && TYPE_IDENTIFIER (type) == TYPE_IDENTIFIER (base_type))
7556 : return false;
7557 :
7558 18 : if (lowval)
7559 18 : *lowval = low;
7560 18 : if (highval)
7561 18 : *highval = high;
7562 : return true;
7563 : }
7564 :
7565 : /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7566 : and number of elements specified by the range of values of INDEX_TYPE.
7567 : If TYPELESS_STORAGE is true, TYPE_TYPELESS_STORAGE flag is set on the type.
7568 : If SHARED is true, reuse such a type that has already been constructed.
7569 : If SET_CANONICAL is true, compute TYPE_CANONICAL from the element type. */
7570 :
7571 : tree
7572 73377581 : build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
7573 : bool shared, bool set_canonical)
7574 : {
7575 73377581 : tree t;
7576 :
7577 73377581 : if (TREE_CODE (elt_type) == FUNCTION_TYPE)
7578 : {
7579 0 : error ("arrays of functions are not meaningful");
7580 0 : elt_type = integer_type_node;
7581 : }
7582 :
7583 73377581 : t = make_node (ARRAY_TYPE);
7584 73377581 : TREE_TYPE (t) = elt_type;
7585 73377581 : TYPE_DOMAIN (t) = index_type;
7586 73377581 : TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type);
7587 73377581 : TYPE_TYPELESS_STORAGE (t) = typeless_storage;
7588 :
7589 : /* Set TYPE_STRUCTURAL_EQUALITY_P. */
7590 73377581 : if (set_canonical
7591 73377581 : && (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7592 73338381 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7593 73059038 : || in_lto_p))
7594 390873 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7595 :
7596 73377581 : layout_type (t);
7597 :
7598 73377581 : if (shared)
7599 : {
7600 73377552 : hashval_t hash = type_hash_canon_hash (t);
7601 73377552 : tree probe_type = t;
7602 73377552 : t = type_hash_canon (hash, t);
7603 73377552 : if (t != probe_type)
7604 : return t;
7605 : }
7606 :
7607 11257783 : if (TYPE_CANONICAL (t) == t && set_canonical)
7608 : {
7609 10916065 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7610 10916065 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7611 21832130 : || in_lto_p)
7612 0 : gcc_unreachable ();
7613 10916065 : else if (TYPE_CANONICAL (elt_type) != elt_type
7614 10916065 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
7615 106135 : TYPE_CANONICAL (t)
7616 307980 : = build_array_type_1 (TYPE_CANONICAL (elt_type),
7617 : index_type
7618 95710 : ? TYPE_CANONICAL (index_type) : NULL_TREE,
7619 : typeless_storage, shared, set_canonical);
7620 : }
7621 :
7622 : return t;
7623 : }
7624 :
7625 : /* Wrapper around build_array_type_1 with SHARED set to true. */
7626 :
7627 : tree
7628 73271417 : build_array_type (tree elt_type, tree index_type, bool typeless_storage)
7629 : {
7630 73271417 : return
7631 73271417 : build_array_type_1 (elt_type, index_type, typeless_storage, true, true);
7632 : }
7633 :
7634 : /* Wrapper around build_array_type_1 with SHARED set to false. */
7635 :
7636 : tree
7637 0 : build_nonshared_array_type (tree elt_type, tree index_type)
7638 : {
7639 0 : return build_array_type_1 (elt_type, index_type, false, false, true);
7640 : }
7641 :
7642 : /* Return a representation of ELT_TYPE[NELTS], using indices of type
7643 : sizetype. */
7644 :
7645 : tree
7646 1687803 : build_array_type_nelts (tree elt_type, poly_uint64 nelts)
7647 : {
7648 1687803 : return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
7649 : }
7650 :
7651 : /* Computes the canonical argument types from the argument type list
7652 : ARGTYPES.
7653 :
7654 : Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7655 : on entry to this function, or if any of the ARGTYPES are
7656 : structural.
7657 :
7658 : Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7659 : true on entry to this function, or if any of the ARGTYPES are
7660 : non-canonical.
7661 :
7662 : Returns a canonical argument list, which may be ARGTYPES when the
7663 : canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7664 : true) or would not differ from ARGTYPES. */
7665 :
7666 : static tree
7667 1003644627 : maybe_canonicalize_argtypes (tree argtypes,
7668 : bool *any_structural_p,
7669 : bool *any_noncanonical_p)
7670 : {
7671 1003644627 : tree arg;
7672 1003644627 : bool any_noncanonical_argtypes_p = false;
7673 :
7674 3457587563 : for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
7675 : {
7676 2453942936 : if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
7677 : /* Fail gracefully by stating that the type is structural. */
7678 4770 : *any_structural_p = true;
7679 2453938166 : else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg)))
7680 34558308 : *any_structural_p = true;
7681 2419379858 : else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg)
7682 2419379858 : || TREE_PURPOSE (arg))
7683 : /* If the argument has a default argument, we consider it
7684 : non-canonical even though the type itself is canonical.
7685 : That way, different variants of function and method types
7686 : with default arguments will all point to the variant with
7687 : no defaults as their canonical type. */
7688 : any_noncanonical_argtypes_p = true;
7689 : }
7690 :
7691 1003644627 : if (*any_structural_p)
7692 : return argtypes;
7693 :
7694 908521290 : if (any_noncanonical_argtypes_p)
7695 : {
7696 : /* Build the canonical list of argument types. */
7697 : tree canon_argtypes = NULL_TREE;
7698 : bool is_void = false;
7699 :
7700 893265944 : for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
7701 : {
7702 685737684 : if (arg == void_list_node)
7703 : is_void = true;
7704 : else
7705 958426336 : canon_argtypes = tree_cons (NULL_TREE,
7706 479213168 : TYPE_CANONICAL (TREE_VALUE (arg)),
7707 : canon_argtypes);
7708 : }
7709 :
7710 207528260 : canon_argtypes = nreverse (canon_argtypes);
7711 207528260 : if (is_void)
7712 206524516 : canon_argtypes = chainon (canon_argtypes, void_list_node);
7713 :
7714 : /* There is a non-canonical type. */
7715 207528260 : *any_noncanonical_p = true;
7716 207528260 : return canon_argtypes;
7717 : }
7718 :
7719 : /* The canonical argument types are the same as ARGTYPES. */
7720 : return argtypes;
7721 : }
7722 :
7723 : /* Construct, lay out and return
7724 : the type of functions returning type VALUE_TYPE
7725 : given arguments of types ARG_TYPES.
7726 : ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7727 : are data type nodes for the arguments of the function.
7728 : NO_NAMED_ARGS_STDARG_P is true if this is a prototyped
7729 : variable-arguments function with (...) prototype (no named arguments).
7730 : If such a type has already been constructed, reuse it. */
7731 :
7732 : tree
7733 659772889 : build_function_type (tree value_type, tree arg_types,
7734 : bool no_named_args_stdarg_p)
7735 : {
7736 659772889 : tree t;
7737 659772889 : inchash::hash hstate;
7738 659772889 : bool any_structural_p, any_noncanonical_p;
7739 659772889 : tree canon_argtypes;
7740 :
7741 659772889 : gcc_assert (arg_types != error_mark_node);
7742 :
7743 659772889 : if (TREE_CODE (value_type) == FUNCTION_TYPE)
7744 : {
7745 0 : error ("function return type cannot be function");
7746 0 : value_type = integer_type_node;
7747 : }
7748 :
7749 : /* Make a node of the sort we want. */
7750 659772889 : t = make_node (FUNCTION_TYPE);
7751 659772889 : TREE_TYPE (t) = value_type;
7752 659772889 : TYPE_ARG_TYPES (t) = arg_types;
7753 659772889 : if (no_named_args_stdarg_p)
7754 : {
7755 1037079 : gcc_assert (arg_types == NULL_TREE);
7756 1037079 : TYPE_NO_NAMED_ARGS_STDARG_P (t) = 1;
7757 : }
7758 :
7759 : /* Set up the canonical type. */
7760 659772889 : any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type);
7761 659772889 : any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
7762 659772889 : canon_argtypes = maybe_canonicalize_argtypes (arg_types,
7763 : &any_structural_p,
7764 : &any_noncanonical_p);
7765 : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7766 659772889 : if (any_structural_p)
7767 68518779 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7768 :
7769 : /* If we already have such a type, use the old one. */
7770 659772889 : hashval_t hash = type_hash_canon_hash (t);
7771 659772889 : tree probe_type = t;
7772 659772889 : t = type_hash_canon (hash, t);
7773 659772889 : if (t != probe_type)
7774 : return t;
7775 :
7776 423256133 : if (any_structural_p)
7777 54941816 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7778 368314317 : else if (any_noncanonical_p)
7779 88822361 : TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
7780 : canon_argtypes,
7781 : no_named_args_stdarg_p);
7782 :
7783 423256133 : if (!COMPLETE_TYPE_P (t))
7784 0 : layout_type (t);
7785 : return t;
7786 : }
7787 :
7788 : /* Build a function type. The RETURN_TYPE is the type returned by the
7789 : function. If VAARGS is set, no void_type_node is appended to the
7790 : list. ARGP must be always be terminated be a NULL_TREE. */
7791 :
7792 : static tree
7793 15330098 : build_function_type_list_1 (bool vaargs, tree return_type, va_list argp)
7794 : {
7795 15330098 : tree t, args, last;
7796 :
7797 15330098 : t = va_arg (argp, tree);
7798 64680756 : for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree))
7799 34020560 : args = tree_cons (NULL_TREE, t, args);
7800 :
7801 15330098 : if (vaargs)
7802 : {
7803 948276 : last = args;
7804 948276 : if (args != NULL_TREE)
7805 815579 : args = nreverse (args);
7806 948276 : gcc_assert (last != void_list_node);
7807 : }
7808 14381822 : else if (args == NULL_TREE)
7809 1233762 : args = void_list_node;
7810 : else
7811 : {
7812 13148060 : last = args;
7813 13148060 : args = nreverse (args);
7814 13148060 : TREE_CHAIN (last) = void_list_node;
7815 : }
7816 15330098 : args = build_function_type (return_type, args, vaargs && args == NULL_TREE);
7817 :
7818 15330098 : return args;
7819 : }
7820 :
7821 : /* Build a function type. The RETURN_TYPE is the type returned by the
7822 : function. If additional arguments are provided, they are
7823 : additional argument types. The list of argument types must always
7824 : be terminated by NULL_TREE. */
7825 :
7826 : tree
7827 14381822 : build_function_type_list (tree return_type, ...)
7828 : {
7829 14381822 : tree args;
7830 14381822 : va_list p;
7831 :
7832 14381822 : va_start (p, return_type);
7833 14381822 : args = build_function_type_list_1 (false, return_type, p);
7834 14381822 : va_end (p);
7835 14381822 : return args;
7836 : }
7837 :
7838 : /* Build a variable argument function type. The RETURN_TYPE is the
7839 : type returned by the function. If additional arguments are provided,
7840 : they are additional argument types. The list of argument types must
7841 : always be terminated by NULL_TREE. */
7842 :
7843 : tree
7844 948276 : build_varargs_function_type_list (tree return_type, ...)
7845 : {
7846 948276 : tree args;
7847 948276 : va_list p;
7848 :
7849 948276 : va_start (p, return_type);
7850 948276 : args = build_function_type_list_1 (true, return_type, p);
7851 948276 : va_end (p);
7852 :
7853 948276 : return args;
7854 : }
7855 :
7856 : /* Build a function type. RETURN_TYPE is the type returned by the
7857 : function; VAARGS indicates whether the function takes varargs. The
7858 : function takes N named arguments, the types of which are provided in
7859 : ARG_TYPES. */
7860 :
7861 : static tree
7862 118880683 : build_function_type_array_1 (bool vaargs, tree return_type, int n,
7863 : tree *arg_types)
7864 : {
7865 118880683 : int i;
7866 118880683 : tree t = vaargs ? NULL_TREE : void_list_node;
7867 :
7868 389101910 : for (i = n - 1; i >= 0; i--)
7869 270221227 : t = tree_cons (NULL_TREE, arg_types[i], t);
7870 :
7871 118880683 : return build_function_type (return_type, t, vaargs && n == 0);
7872 : }
7873 :
7874 : /* Build a function type. RETURN_TYPE is the type returned by the
7875 : function. The function takes N named arguments, the types of which
7876 : are provided in ARG_TYPES. */
7877 :
7878 : tree
7879 112524070 : build_function_type_array (tree return_type, int n, tree *arg_types)
7880 : {
7881 112524070 : return build_function_type_array_1 (false, return_type, n, arg_types);
7882 : }
7883 :
7884 : /* Build a variable argument function type. RETURN_TYPE is the type
7885 : returned by the function. The function takes N named arguments, the
7886 : types of which are provided in ARG_TYPES. */
7887 :
7888 : tree
7889 6356613 : build_varargs_function_type_array (tree return_type, int n, tree *arg_types)
7890 : {
7891 6356613 : return build_function_type_array_1 (true, return_type, n, arg_types);
7892 : }
7893 :
7894 : /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
7895 : and ARGTYPES (a TREE_LIST) are the return type and arguments types
7896 : for the method. An implicit additional parameter (of type
7897 : pointer-to-BASETYPE) is added to the ARGTYPES. */
7898 :
7899 : tree
7900 343871738 : build_method_type_directly (tree basetype,
7901 : tree rettype,
7902 : tree argtypes)
7903 : {
7904 343871738 : tree t;
7905 343871738 : tree ptype;
7906 343871738 : bool any_structural_p, any_noncanonical_p;
7907 343871738 : tree canon_argtypes;
7908 :
7909 : /* Make a node of the sort we want. */
7910 343871738 : t = make_node (METHOD_TYPE);
7911 :
7912 343871738 : TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7913 343871738 : TREE_TYPE (t) = rettype;
7914 343871738 : ptype = build_pointer_type (basetype);
7915 :
7916 : /* The actual arglist for this function includes a "hidden" argument
7917 : which is "this". Put it into the list of argument types. */
7918 343871738 : argtypes = tree_cons (NULL_TREE, ptype, argtypes);
7919 343871738 : TYPE_ARG_TYPES (t) = argtypes;
7920 :
7921 : /* Set up the canonical type. */
7922 343871738 : any_structural_p
7923 343871738 : = (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7924 343871738 : || TYPE_STRUCTURAL_EQUALITY_P (rettype));
7925 343871738 : any_noncanonical_p
7926 343871738 : = (TYPE_CANONICAL (basetype) != basetype
7927 343871738 : || TYPE_CANONICAL (rettype) != rettype);
7928 343871738 : canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes),
7929 : &any_structural_p,
7930 : &any_noncanonical_p);
7931 :
7932 : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7933 343871738 : if (any_structural_p)
7934 26604558 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7935 :
7936 : /* If we already have such a type, use the old one. */
7937 343871738 : hashval_t hash = type_hash_canon_hash (t);
7938 343871738 : tree probe_type = t;
7939 343871738 : t = type_hash_canon (hash, t);
7940 343871738 : if (t != probe_type)
7941 : return t;
7942 :
7943 265054352 : if (any_structural_p)
7944 22451014 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7945 242603338 : else if (any_noncanonical_p)
7946 89260824 : TYPE_CANONICAL (t)
7947 178521648 : = build_method_type_directly (TYPE_CANONICAL (basetype),
7948 89260824 : TYPE_CANONICAL (rettype),
7949 : canon_argtypes);
7950 265054352 : if (!COMPLETE_TYPE_P (t))
7951 0 : layout_type (t);
7952 :
7953 : return t;
7954 : }
7955 :
7956 : /* Construct, lay out and return the type of methods belonging to class
7957 : BASETYPE and whose arguments and values are described by TYPE.
7958 : If that type exists already, reuse it.
7959 : TYPE must be a FUNCTION_TYPE node. */
7960 :
7961 : tree
7962 0 : build_method_type (tree basetype, tree type)
7963 : {
7964 0 : gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
7965 :
7966 0 : return build_method_type_directly (basetype,
7967 0 : TREE_TYPE (type),
7968 0 : TYPE_ARG_TYPES (type));
7969 : }
7970 :
7971 : /* Construct, lay out and return the type of offsets to a value
7972 : of type TYPE, within an object of type BASETYPE.
7973 : If a suitable offset type exists already, reuse it. */
7974 :
7975 : tree
7976 991193 : build_offset_type (tree basetype, tree type)
7977 : {
7978 991193 : tree t;
7979 :
7980 : /* Make a node of the sort we want. */
7981 991193 : t = make_node (OFFSET_TYPE);
7982 :
7983 991193 : TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7984 991193 : TREE_TYPE (t) = type;
7985 991193 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7986 991193 : || TYPE_STRUCTURAL_EQUALITY_P (type))
7987 4 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7988 :
7989 : /* If we already have such a type, use the old one. */
7990 991193 : hashval_t hash = type_hash_canon_hash (t);
7991 991193 : tree probe_type = t;
7992 991193 : t = type_hash_canon (hash, t);
7993 991193 : if (t != probe_type)
7994 : return t;
7995 :
7996 240085 : if (!COMPLETE_TYPE_P (t))
7997 0 : layout_type (t);
7998 :
7999 240085 : if (TYPE_CANONICAL (t) == t)
8000 : {
8001 240081 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
8002 240081 : || TYPE_STRUCTURAL_EQUALITY_P (type))
8003 0 : gcc_unreachable ();
8004 240081 : else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
8005 240081 : || TYPE_CANONICAL (type) != type)
8006 137630 : TYPE_CANONICAL (t)
8007 275260 : = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
8008 137630 : TYPE_CANONICAL (type));
8009 : }
8010 :
8011 : return t;
8012 : }
8013 :
8014 : /* Create a complex type whose components are COMPONENT_TYPE.
8015 :
8016 : If NAMED is true, the type is given a TYPE_NAME. We do not always
8017 : do so because this creates a DECL node and thus make the DECL_UIDs
8018 : dependent on the type canonicalization hashtable, which is GC-ed,
8019 : so the DECL_UIDs would not be stable wrt garbage collection. */
8020 :
8021 : tree
8022 5394365 : build_complex_type (tree component_type, bool named)
8023 : {
8024 5394365 : gcc_assert (INTEGRAL_TYPE_P (component_type)
8025 : || SCALAR_FLOAT_TYPE_P (component_type)
8026 : || FIXED_POINT_TYPE_P (component_type));
8027 :
8028 : /* Make a node of the sort we want. */
8029 5394365 : tree probe = make_node (COMPLEX_TYPE);
8030 :
8031 5394365 : TREE_TYPE (probe) = TYPE_MAIN_VARIANT (component_type);
8032 5394365 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (probe)))
8033 0 : SET_TYPE_STRUCTURAL_EQUALITY (probe);
8034 :
8035 : /* If we already have such a type, use the old one. */
8036 5394365 : hashval_t hash = type_hash_canon_hash (probe);
8037 5394365 : tree t = type_hash_canon (hash, probe);
8038 :
8039 5394365 : if (t == probe)
8040 : {
8041 : /* We created a new type. The hash insertion will have laid
8042 : out the type. We need to check the canonicalization and
8043 : maybe set the name. */
8044 3183636 : gcc_checking_assert (COMPLETE_TYPE_P (t)
8045 : && !TYPE_NAME (t));
8046 :
8047 3183636 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t)))
8048 : ;
8049 3183636 : else if (TYPE_CANONICAL (TREE_TYPE (t)) != TREE_TYPE (t))
8050 101 : TYPE_CANONICAL (t)
8051 202 : = build_complex_type (TYPE_CANONICAL (TREE_TYPE (t)), named);
8052 :
8053 : /* We need to create a name, since complex is a fundamental type. */
8054 3183636 : if (named)
8055 : {
8056 1168272 : const char *name = NULL;
8057 :
8058 1168272 : if (TREE_TYPE (t) == char_type_node)
8059 : name = "complex char";
8060 1168272 : else if (TREE_TYPE (t) == signed_char_type_node)
8061 : name = "complex signed char";
8062 1168272 : else if (TREE_TYPE (t) == unsigned_char_type_node)
8063 : name = "complex unsigned char";
8064 1168272 : else if (TREE_TYPE (t) == short_integer_type_node)
8065 : name = "complex short int";
8066 1168272 : else if (TREE_TYPE (t) == short_unsigned_type_node)
8067 : name = "complex short unsigned int";
8068 1168272 : else if (TREE_TYPE (t) == integer_type_node)
8069 : name = "complex int";
8070 876204 : else if (TREE_TYPE (t) == unsigned_type_node)
8071 : name = "complex unsigned int";
8072 876204 : else if (TREE_TYPE (t) == long_integer_type_node)
8073 : name = "complex long int";
8074 876204 : else if (TREE_TYPE (t) == long_unsigned_type_node)
8075 : name = "complex long unsigned int";
8076 876204 : else if (TREE_TYPE (t) == long_long_integer_type_node)
8077 : name = "complex long long int";
8078 876204 : else if (TREE_TYPE (t) == long_long_unsigned_type_node)
8079 : name = "complex long long unsigned int";
8080 :
8081 : if (name != NULL)
8082 292068 : TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
8083 : get_identifier (name), t);
8084 : }
8085 : }
8086 :
8087 5394365 : return build_qualified_type (t, TYPE_QUALS (component_type));
8088 : }
8089 :
8090 : /* If TYPE is a real or complex floating-point type and the target
8091 : does not directly support arithmetic on TYPE then return the wider
8092 : type to be used for arithmetic on TYPE. Otherwise, return
8093 : NULL_TREE. */
8094 :
8095 : tree
8096 90897625 : excess_precision_type (tree type)
8097 : {
8098 : /* The target can give two different responses to the question of
8099 : which excess precision mode it would like depending on whether we
8100 : are in -fexcess-precision=standard or -fexcess-precision=fast. */
8101 :
8102 3515375 : enum excess_precision_type requested_type
8103 90897625 : = (flag_excess_precision == EXCESS_PRECISION_FAST
8104 90897625 : ? EXCESS_PRECISION_TYPE_FAST
8105 : : (flag_excess_precision == EXCESS_PRECISION_FLOAT16
8106 3516101 : ? EXCESS_PRECISION_TYPE_FLOAT16 : EXCESS_PRECISION_TYPE_STANDARD));
8107 :
8108 90897625 : enum flt_eval_method target_flt_eval_method
8109 90897625 : = targetm.c.excess_precision (requested_type);
8110 :
8111 : /* The target should not ask for unpredictable float evaluation (though
8112 : it might advertise that implicitly the evaluation is unpredictable,
8113 : but we don't care about that here, it will have been reported
8114 : elsewhere). If it does ask for unpredictable evaluation, we have
8115 : nothing to do here. */
8116 90897625 : gcc_assert (target_flt_eval_method != FLT_EVAL_METHOD_UNPREDICTABLE);
8117 :
8118 : /* Nothing to do. The target has asked for all types we know about
8119 : to be computed with their native precision and range. */
8120 90897625 : if (target_flt_eval_method == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
8121 : return NULL_TREE;
8122 :
8123 : /* The target will promote this type in a target-dependent way, so excess
8124 : precision ought to leave it alone. */
8125 89283504 : if (targetm.promoted_type (type) != NULL_TREE)
8126 : return NULL_TREE;
8127 :
8128 89283504 : machine_mode float16_type_mode = (float16_type_node
8129 89283504 : ? TYPE_MODE (float16_type_node)
8130 89283504 : : VOIDmode);
8131 89283504 : machine_mode bfloat16_type_mode = (bfloat16_type_node
8132 89283504 : ? TYPE_MODE (bfloat16_type_node)
8133 89283504 : : VOIDmode);
8134 89283504 : machine_mode float_type_mode = TYPE_MODE (float_type_node);
8135 89283504 : machine_mode double_type_mode = TYPE_MODE (double_type_node);
8136 :
8137 89283504 : switch (TREE_CODE (type))
8138 : {
8139 60928766 : case REAL_TYPE:
8140 60928766 : {
8141 60928766 : machine_mode type_mode = TYPE_MODE (type);
8142 60928766 : switch (target_flt_eval_method)
8143 : {
8144 60915933 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8145 60915933 : if (type_mode == float16_type_mode
8146 60915933 : || type_mode == bfloat16_type_mode)
8147 246047 : return float_type_node;
8148 : break;
8149 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8150 0 : if (type_mode == float16_type_mode
8151 0 : || type_mode == bfloat16_type_mode
8152 0 : || type_mode == float_type_mode)
8153 0 : return double_type_node;
8154 : break;
8155 12833 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8156 12833 : if (type_mode == float16_type_mode
8157 12833 : || type_mode == bfloat16_type_mode
8158 12828 : || type_mode == float_type_mode
8159 12828 : || type_mode == double_type_mode)
8160 12384 : return long_double_type_node;
8161 : break;
8162 0 : default:
8163 0 : gcc_unreachable ();
8164 : }
8165 : break;
8166 : }
8167 379420 : case COMPLEX_TYPE:
8168 379420 : {
8169 379420 : if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
8170 : return NULL_TREE;
8171 369904 : machine_mode type_mode = TYPE_MODE (TREE_TYPE (type));
8172 369904 : switch (target_flt_eval_method)
8173 : {
8174 369571 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8175 369571 : if (type_mode == float16_type_mode
8176 369571 : || type_mode == bfloat16_type_mode)
8177 281 : return complex_float_type_node;
8178 : break;
8179 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8180 0 : if (type_mode == float16_type_mode
8181 0 : || type_mode == bfloat16_type_mode
8182 0 : || type_mode == float_type_mode)
8183 0 : return complex_double_type_node;
8184 : break;
8185 333 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8186 333 : if (type_mode == float16_type_mode
8187 333 : || type_mode == bfloat16_type_mode
8188 333 : || type_mode == float_type_mode
8189 333 : || type_mode == double_type_mode)
8190 281 : return complex_long_double_type_node;
8191 : break;
8192 0 : default:
8193 0 : gcc_unreachable ();
8194 : }
8195 : break;
8196 : }
8197 : default:
8198 : break;
8199 : }
8200 :
8201 : return NULL_TREE;
8202 : }
8203 :
8204 : /* Return OP, stripped of any conversions to wider types as much as is safe.
8205 : Converting the value back to OP's type makes a value equivalent to OP.
8206 :
8207 : If FOR_TYPE is nonzero, we return a value which, if converted to
8208 : type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8209 :
8210 : OP must have integer, real or enumeral type. Pointers are not allowed!
8211 :
8212 : There are some cases where the obvious value we could return
8213 : would regenerate to OP if converted to OP's type,
8214 : but would not extend like OP to wider types.
8215 : If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8216 : For example, if OP is (unsigned short)(signed char)-1,
8217 : we avoid returning (signed char)-1 if FOR_TYPE is int,
8218 : even though extending that to an unsigned short would regenerate OP,
8219 : since the result of extending (signed char)-1 to (int)
8220 : is different from (int) OP. */
8221 :
8222 : tree
8223 11431152 : get_unwidened (tree op, tree for_type)
8224 : {
8225 : /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8226 11431152 : tree type = TREE_TYPE (op);
8227 11431152 : unsigned final_prec
8228 19241460 : = TYPE_PRECISION (for_type != 0 ? for_type : type);
8229 11431152 : int uns
8230 11431152 : = (for_type != 0 && for_type != type
8231 3281613 : && final_prec > TYPE_PRECISION (type)
8232 11679738 : && TYPE_UNSIGNED (type));
8233 11431152 : tree win = op;
8234 :
8235 11764467 : while (CONVERT_EXPR_P (op))
8236 : {
8237 333408 : int bitschange;
8238 :
8239 : /* TYPE_PRECISION on vector types has different meaning
8240 : (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8241 : so avoid them here. */
8242 333408 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
8243 : break;
8244 :
8245 333408 : bitschange = TYPE_PRECISION (TREE_TYPE (op))
8246 333408 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
8247 :
8248 : /* Truncations are many-one so cannot be removed.
8249 : Unless we are later going to truncate down even farther. */
8250 333408 : if (bitschange < 0
8251 333408 : && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
8252 : break;
8253 :
8254 : /* See what's inside this conversion. If we decide to strip it,
8255 : we will set WIN. */
8256 333315 : op = TREE_OPERAND (op, 0);
8257 :
8258 : /* If we have not stripped any zero-extensions (uns is 0),
8259 : we can strip any kind of extension.
8260 : If we have previously stripped a zero-extension,
8261 : only zero-extensions can safely be stripped.
8262 : Any extension can be stripped if the bits it would produce
8263 : are all going to be discarded later by truncating to FOR_TYPE. */
8264 :
8265 333315 : if (bitschange > 0)
8266 : {
8267 199664 : if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
8268 : win = op;
8269 : /* TYPE_UNSIGNED says whether this is a zero-extension.
8270 : Let's avoid computing it if it does not affect WIN
8271 : and if UNS will not be needed again. */
8272 199664 : if ((uns
8273 199633 : || CONVERT_EXPR_P (op))
8274 200335 : && TYPE_UNSIGNED (TREE_TYPE (op)))
8275 : {
8276 : uns = 1;
8277 : win = op;
8278 : }
8279 : }
8280 : }
8281 :
8282 : /* If we finally reach a constant see if it fits in sth smaller and
8283 : in that case convert it. */
8284 11431152 : if (TREE_CODE (win) == INTEGER_CST)
8285 : {
8286 540585 : tree wtype = TREE_TYPE (win);
8287 540585 : unsigned prec = wi::min_precision (wi::to_wide (win), TYPE_SIGN (wtype));
8288 540585 : if (for_type)
8289 528817 : prec = MAX (prec, final_prec);
8290 540585 : if (prec < TYPE_PRECISION (wtype))
8291 : {
8292 536139 : tree t = lang_hooks.types.type_for_size (prec, TYPE_UNSIGNED (wtype));
8293 536139 : if (t && TYPE_PRECISION (t) < TYPE_PRECISION (wtype))
8294 524410 : win = fold_convert (t, win);
8295 : }
8296 : }
8297 :
8298 11431152 : return win;
8299 : }
8300 :
8301 : /* Return OP or a simpler expression for a narrower value
8302 : which can be sign-extended or zero-extended to give back OP.
8303 : Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8304 : or 0 if the value should be sign-extended. */
8305 :
8306 : tree
8307 84919410 : get_narrower (tree op, int *unsignedp_ptr)
8308 : {
8309 84919410 : int uns = 0;
8310 84919410 : bool first = true;
8311 84919410 : tree win = op;
8312 84919410 : bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
8313 :
8314 84919410 : if (TREE_CODE (op) == COMPOUND_EXPR)
8315 : {
8316 90867 : do
8317 90867 : op = TREE_OPERAND (op, 1);
8318 90867 : while (TREE_CODE (op) == COMPOUND_EXPR);
8319 90852 : tree ret = get_narrower (op, unsignedp_ptr);
8320 90852 : if (ret == op)
8321 : return win;
8322 4262 : auto_vec <tree, 16> v;
8323 4262 : unsigned int i;
8324 8531 : for (op = win; TREE_CODE (op) == COMPOUND_EXPR;
8325 4269 : op = TREE_OPERAND (op, 1))
8326 4269 : v.safe_push (op);
8327 12793 : FOR_EACH_VEC_ELT_REVERSE (v, i, op)
8328 4269 : ret = build2_loc (EXPR_LOCATION (op), COMPOUND_EXPR,
8329 4269 : TREE_TYPE (ret), TREE_OPERAND (op, 0),
8330 : ret);
8331 4262 : return ret;
8332 4262 : }
8333 101242860 : while (TREE_CODE (op) == NOP_EXPR)
8334 : {
8335 16447158 : int bitschange
8336 16447158 : = (TYPE_PRECISION (TREE_TYPE (op))
8337 16447158 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
8338 :
8339 : /* Truncations are many-one so cannot be removed. */
8340 16447158 : if (bitschange < 0)
8341 : break;
8342 :
8343 : /* See what's inside this conversion. If we decide to strip it,
8344 : we will set WIN. */
8345 :
8346 16414398 : if (bitschange > 0)
8347 : {
8348 3890860 : op = TREE_OPERAND (op, 0);
8349 : /* An extension: the outermost one can be stripped,
8350 : but remember whether it is zero or sign extension. */
8351 3890860 : if (first)
8352 3879950 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8353 : /* Otherwise, if a sign extension has been stripped,
8354 : only sign extensions can now be stripped;
8355 : if a zero extension has been stripped, only zero-extensions. */
8356 10910 : else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
8357 : break;
8358 : first = false;
8359 : }
8360 : else /* bitschange == 0 */
8361 : {
8362 : /* A change in nominal type can always be stripped, but we must
8363 : preserve the unsignedness. */
8364 12523538 : if (first)
8365 11924688 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8366 12523538 : first = false;
8367 12523538 : op = TREE_OPERAND (op, 0);
8368 : /* Keep trying to narrow, but don't assign op to win if it
8369 : would turn an integral type into something else. */
8370 23283867 : if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
8371 99330 : continue;
8372 : }
8373 :
8374 16314972 : win = op;
8375 : }
8376 :
8377 84828558 : if (TREE_CODE (op) == COMPONENT_REF
8378 : /* Since type_for_size always gives an integer type. */
8379 2984999 : && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
8380 2882677 : && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE
8381 : /* Ensure field is laid out already. */
8382 2882677 : && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
8383 87711232 : && tree_fits_uhwi_p (DECL_SIZE (TREE_OPERAND (op, 1))))
8384 : {
8385 2882674 : unsigned HOST_WIDE_INT innerprec
8386 2882674 : = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (op, 1)));
8387 2882674 : int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
8388 2882674 : || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
8389 2882674 : tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
8390 :
8391 : /* We can get this structure field in a narrower type that fits it,
8392 : but the resulting extension to its nominal type (a fullword type)
8393 : must satisfy the same conditions as for other extensions.
8394 :
8395 : Do this only for fields that are aligned (not bit-fields),
8396 : because when bit-field insns will be used there is no
8397 : advantage in doing this. */
8398 :
8399 2882674 : if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
8400 0 : && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
8401 0 : && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
8402 2882674 : && type != 0)
8403 : {
8404 0 : if (first)
8405 0 : uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
8406 0 : win = fold_convert (type, op);
8407 : }
8408 : }
8409 :
8410 84828558 : *unsignedp_ptr = uns;
8411 84828558 : return win;
8412 : }
8413 :
8414 : /* Return true if integer constant C has a value that is permissible
8415 : for TYPE, an integral type. */
8416 :
8417 : bool
8418 197478456 : int_fits_type_p (const_tree c, const_tree type)
8419 : {
8420 197478456 : tree type_low_bound, type_high_bound;
8421 197478456 : bool ok_for_low_bound, ok_for_high_bound;
8422 197478456 : signop sgn_c = TYPE_SIGN (TREE_TYPE (c));
8423 :
8424 : /* Non-standard boolean types can have arbitrary precision but various
8425 : transformations assume that they can only take values 0 and +/-1. */
8426 197478456 : if (TREE_CODE (type) == BOOLEAN_TYPE)
8427 1280933 : return wi::fits_to_boolean_p (wi::to_wide (c), type);
8428 :
8429 196197523 : retry:
8430 196209370 : type_low_bound = TYPE_MIN_VALUE (type);
8431 196209370 : type_high_bound = TYPE_MAX_VALUE (type);
8432 :
8433 : /* If at least one bound of the type is a constant integer, we can check
8434 : ourselves and maybe make a decision. If no such decision is possible, but
8435 : this type is a subtype, try checking against that. Otherwise, use
8436 : fits_to_tree_p, which checks against the precision.
8437 :
8438 : Compute the status for each possibly constant bound, and return if we see
8439 : one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8440 : for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8441 : for "constant known to fit". */
8442 :
8443 : /* Check if c >= type_low_bound. */
8444 196209370 : if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
8445 : {
8446 196209370 : if (tree_int_cst_lt (c, type_low_bound))
8447 : return false;
8448 : ok_for_low_bound = true;
8449 : }
8450 : else
8451 : ok_for_low_bound = false;
8452 :
8453 : /* Check if c <= type_high_bound. */
8454 195955291 : if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
8455 : {
8456 195923719 : if (tree_int_cst_lt (type_high_bound, c))
8457 : return false;
8458 : ok_for_high_bound = true;
8459 : }
8460 : else
8461 : ok_for_high_bound = false;
8462 :
8463 : /* If the constant fits both bounds, the result is known. */
8464 194006233 : if (ok_for_low_bound && ok_for_high_bound)
8465 : return true;
8466 :
8467 : /* Perform some generic filtering which may allow making a decision
8468 : even if the bounds are not constant. First, negative integers
8469 : never fit in unsigned types, */
8470 31572 : if (TYPE_UNSIGNED (type) && sgn_c == SIGNED && wi::neg_p (wi::to_wide (c)))
8471 0 : return false;
8472 :
8473 : /* Second, narrower types always fit in wider ones. */
8474 31572 : if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
8475 : return true;
8476 :
8477 : /* Third, unsigned integers with top bit set never fit signed types. */
8478 11856 : if (!TYPE_UNSIGNED (type) && sgn_c == UNSIGNED)
8479 : {
8480 14 : int prec = GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (c))) - 1;
8481 14 : if (prec < TYPE_PRECISION (TREE_TYPE (c)))
8482 : {
8483 : /* When a tree_cst is converted to a wide-int, the precision
8484 : is taken from the type. However, if the precision of the
8485 : mode underneath the type is smaller than that, it is
8486 : possible that the value will not fit. The test below
8487 : fails if any bit is set between the sign bit of the
8488 : underlying mode and the top bit of the type. */
8489 14 : if (wi::zext (wi::to_wide (c), prec - 1) != wi::to_wide (c))
8490 : return false;
8491 : }
8492 0 : else if (wi::neg_p (wi::to_wide (c)))
8493 : return false;
8494 : }
8495 :
8496 : /* If we haven't been able to decide at this point, there nothing more we
8497 : can check ourselves here. Look at the base type if we have one and it
8498 : has the same precision. */
8499 11847 : if (TREE_CODE (type) == INTEGER_TYPE
8500 11847 : && TREE_TYPE (type) != 0
8501 23694 : && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
8502 : {
8503 11847 : type = TREE_TYPE (type);
8504 11847 : goto retry;
8505 : }
8506 :
8507 : /* Or to fits_to_tree_p, if nothing else. */
8508 0 : return wi::fits_to_tree_p (wi::to_wide (c), type);
8509 : }
8510 :
8511 : /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8512 : bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8513 : represented (assuming two's-complement arithmetic) within the bit
8514 : precision of the type are returned instead. */
8515 :
8516 : void
8517 23108083 : get_type_static_bounds (const_tree type, mpz_t min, mpz_t max)
8518 : {
8519 21612019 : if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type)
8520 44720102 : && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
8521 21612019 : wi::to_mpz (wi::to_wide (TYPE_MIN_VALUE (type)), min, TYPE_SIGN (type));
8522 : else
8523 : {
8524 1496064 : if (TYPE_UNSIGNED (type))
8525 1496064 : mpz_set_ui (min, 0);
8526 : else
8527 : {
8528 0 : wide_int mn = wi::min_value (TYPE_PRECISION (type), SIGNED);
8529 0 : wi::to_mpz (mn, min, SIGNED);
8530 0 : }
8531 : }
8532 :
8533 21612019 : if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
8534 44720102 : && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
8535 21612019 : wi::to_mpz (wi::to_wide (TYPE_MAX_VALUE (type)), max, TYPE_SIGN (type));
8536 : else
8537 : {
8538 1496064 : wide_int mn = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
8539 1496064 : wi::to_mpz (mn, max, TYPE_SIGN (type));
8540 1496064 : }
8541 23108083 : }
8542 :
8543 : /* Return true if VAR is an automatic variable. */
8544 :
8545 : bool
8546 532770137 : auto_var_p (const_tree var)
8547 : {
8548 316810692 : return ((((VAR_P (var) && ! DECL_EXTERNAL (var))
8549 219335657 : || TREE_CODE (var) == PARM_DECL)
8550 413104702 : && ! TREE_STATIC (var))
8551 662686610 : || TREE_CODE (var) == RESULT_DECL);
8552 : }
8553 :
8554 : /* Return true if VAR is an automatic variable defined in function FN. */
8555 :
8556 : bool
8557 1849425468 : auto_var_in_fn_p (const_tree var, const_tree fn)
8558 : {
8559 627395715 : return (DECL_P (var) && DECL_CONTEXT (var) == fn
8560 2253369562 : && (auto_var_p (var)
8561 6277372 : || TREE_CODE (var) == LABEL_DECL));
8562 : }
8563 :
8564 : /* Subprogram of following function. Called by walk_tree.
8565 :
8566 : Return *TP if it is an automatic variable or parameter of the
8567 : function passed in as DATA. */
8568 :
8569 : static tree
8570 127370 : find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
8571 : {
8572 127370 : tree fn = (tree) data;
8573 :
8574 127370 : if (TYPE_P (*tp))
8575 0 : *walk_subtrees = 0;
8576 :
8577 127370 : else if (DECL_P (*tp)
8578 127370 : && auto_var_in_fn_p (*tp, fn))
8579 118994 : return *tp;
8580 :
8581 : return NULL_TREE;
8582 : }
8583 :
8584 : /* Returns true if T is, contains, or refers to a type with variable
8585 : size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8586 : arguments, but not the return type. If FN is nonzero, only return
8587 : true if a modifier of the type or position of FN is a variable or
8588 : parameter inside FN.
8589 :
8590 : This concept is more general than that of C99 'variably modified types':
8591 : in C99, a struct type is never variably modified because a VLA may not
8592 : appear as a structure member. However, in GNU C code like:
8593 :
8594 : struct S { int i[f()]; };
8595 :
8596 : is valid, and other languages may define similar constructs. */
8597 :
8598 : bool
8599 2449477003 : variably_modified_type_p (tree type, tree fn)
8600 : {
8601 2449477003 : tree t;
8602 :
8603 : /* Test if T is either variable (if FN is zero) or an expression containing
8604 : a variable in FN. If TYPE isn't gimplified, return true also if
8605 : gimplify_one_sizepos would gimplify the expression into a local
8606 : variable. */
8607 : #define RETURN_TRUE_IF_VAR(T) \
8608 : do { tree _t = (T); \
8609 : if (_t != NULL_TREE \
8610 : && _t != error_mark_node \
8611 : && !CONSTANT_CLASS_P (_t) \
8612 : && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8613 : && (!fn \
8614 : || (!TYPE_SIZES_GIMPLIFIED (type) \
8615 : && (TREE_CODE (_t) != VAR_DECL \
8616 : && !CONTAINS_PLACEHOLDER_P (_t))) \
8617 : || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8618 : return true; } while (0)
8619 :
8620 2449477003 : if (type == error_mark_node)
8621 : return false;
8622 :
8623 : /* If TYPE itself has variable size, it is variably modified. */
8624 2449476635 : RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
8625 2449336464 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
8626 :
8627 2449335840 : switch (TREE_CODE (type))
8628 : {
8629 657195303 : case POINTER_TYPE:
8630 657195303 : case REFERENCE_TYPE:
8631 657195303 : case VECTOR_TYPE:
8632 : /* Ada can have pointer types referring to themselves indirectly. */
8633 657195303 : if (TREE_VISITED (type))
8634 : return false;
8635 657195303 : TREE_VISITED (type) = true;
8636 657195303 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8637 : {
8638 81151 : TREE_VISITED (type) = false;
8639 81151 : return true;
8640 : }
8641 657114152 : TREE_VISITED (type) = false;
8642 657114152 : break;
8643 :
8644 139424337 : case FUNCTION_TYPE:
8645 139424337 : case METHOD_TYPE:
8646 : /* If TYPE is a function type, it is variably modified if the
8647 : return type is variably modified. */
8648 139424337 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8649 : return true;
8650 : break;
8651 :
8652 603127289 : case INTEGER_TYPE:
8653 603127289 : case REAL_TYPE:
8654 603127289 : case FIXED_POINT_TYPE:
8655 603127289 : case ENUMERAL_TYPE:
8656 603127289 : case BOOLEAN_TYPE:
8657 : /* Scalar types are variably modified if their end points
8658 : aren't constant. */
8659 603127289 : RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
8660 603127289 : RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
8661 603091849 : break;
8662 :
8663 852218629 : case RECORD_TYPE:
8664 852218629 : case UNION_TYPE:
8665 852218629 : case QUAL_UNION_TYPE:
8666 : /* We can't see if any of the fields are variably-modified by the
8667 : definition we normally use, since that would produce infinite
8668 : recursion via pointers. */
8669 : /* This is variably modified if some field's type is. */
8670 39585327580 : for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
8671 38733108951 : if (TREE_CODE (t) == FIELD_DECL)
8672 : {
8673 1245052736 : RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
8674 1245052736 : RETURN_TRUE_IF_VAR (DECL_SIZE (t));
8675 1245052736 : RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
8676 :
8677 : /* If the type is a qualified union, then the DECL_QUALIFIER
8678 : of fields can also be an expression containing a variable. */
8679 1245052736 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
8680 0 : RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
8681 :
8682 : /* If the field is a qualified union, then it's only a container
8683 : for what's inside so we look into it. That's necessary in LTO
8684 : mode because the sizes of the field tested above have been set
8685 : to PLACEHOLDER_EXPRs by free_lang_data. */
8686 1245052736 : if (TREE_CODE (TREE_TYPE (t)) == QUAL_UNION_TYPE
8687 1245052736 : && variably_modified_type_p (TREE_TYPE (t), fn))
8688 : return true;
8689 : }
8690 : break;
8691 :
8692 14578717 : case ARRAY_TYPE:
8693 : /* Do not call ourselves to avoid infinite recursion. This is
8694 : variably modified if the element type is. */
8695 14578717 : RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
8696 14575204 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
8697 14575178 : break;
8698 :
8699 : default:
8700 : break;
8701 : }
8702 :
8703 : /* The current language may have other cases to check, but in general,
8704 : all other types are not variably modified. */
8705 2449215480 : return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
8706 :
8707 : #undef RETURN_TRUE_IF_VAR
8708 : }
8709 :
8710 : /* Given a DECL or TYPE, return the scope in which it was declared, or
8711 : NULL_TREE if there is no containing scope. */
8712 :
8713 : tree
8714 3067970102 : get_containing_scope (const_tree t)
8715 : {
8716 3067970102 : return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
8717 : }
8718 :
8719 : /* Returns the ultimate TRANSLATION_UNIT_DECL context of DECL or NULL. */
8720 :
8721 : const_tree
8722 14269 : get_ultimate_context (const_tree decl)
8723 : {
8724 38959 : while (decl && TREE_CODE (decl) != TRANSLATION_UNIT_DECL)
8725 : {
8726 24690 : if (TREE_CODE (decl) == BLOCK)
8727 0 : decl = BLOCK_SUPERCONTEXT (decl);
8728 : else
8729 24690 : decl = get_containing_scope (decl);
8730 : }
8731 14269 : return decl;
8732 : }
8733 :
8734 : /* Return the innermost context enclosing DECL that is
8735 : a FUNCTION_DECL, or zero if none. */
8736 :
8737 : tree
8738 1534969688 : decl_function_context (const_tree decl)
8739 : {
8740 1534969688 : tree context;
8741 :
8742 1534969688 : if (TREE_CODE (decl) == ERROR_MARK)
8743 : return 0;
8744 :
8745 : /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8746 : where we look up the function at runtime. Such functions always take
8747 : a first argument of type 'pointer to real context'.
8748 :
8749 : C++ should really be fixed to use DECL_CONTEXT for the real context,
8750 : and use something else for the "virtual context". */
8751 1534969688 : else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
8752 4868803 : context
8753 4868803 : = TYPE_MAIN_VARIANT
8754 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
8755 : else
8756 1530100885 : context = DECL_CONTEXT (decl);
8757 :
8758 3758987737 : while (context && TREE_CODE (context) != FUNCTION_DECL)
8759 : {
8760 2224018049 : if (TREE_CODE (context) == BLOCK)
8761 0 : context = BLOCK_SUPERCONTEXT (context);
8762 : else
8763 2224018049 : context = get_containing_scope (context);
8764 : }
8765 :
8766 : return context;
8767 : }
8768 :
8769 : /* Return the innermost context enclosing DECL that is
8770 : a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8771 : TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8772 :
8773 : tree
8774 98194172 : decl_type_context (const_tree decl)
8775 : {
8776 98194172 : tree context = DECL_CONTEXT (decl);
8777 :
8778 101244338 : while (context)
8779 95525792 : switch (TREE_CODE (context))
8780 : {
8781 : case NAMESPACE_DECL:
8782 : case TRANSLATION_UNIT_DECL:
8783 : return NULL_TREE;
8784 :
8785 : case RECORD_TYPE:
8786 : case UNION_TYPE:
8787 : case QUAL_UNION_TYPE:
8788 : return context;
8789 :
8790 3050166 : case TYPE_DECL:
8791 3050166 : case FUNCTION_DECL:
8792 3050166 : context = DECL_CONTEXT (context);
8793 3050166 : break;
8794 :
8795 0 : case BLOCK:
8796 0 : context = BLOCK_SUPERCONTEXT (context);
8797 0 : break;
8798 :
8799 0 : default:
8800 0 : gcc_unreachable ();
8801 : }
8802 :
8803 : return NULL_TREE;
8804 : }
8805 :
8806 : /* CALL is a CALL_EXPR. Return the declaration for the function
8807 : called, or NULL_TREE if the called function cannot be
8808 : determined. */
8809 :
8810 : tree
8811 1246810192 : get_callee_fndecl (const_tree call)
8812 : {
8813 1246810192 : tree addr;
8814 :
8815 1246810192 : if (call == error_mark_node)
8816 : return error_mark_node;
8817 :
8818 : /* It's invalid to call this function with anything but a
8819 : CALL_EXPR. */
8820 1246810192 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8821 :
8822 : /* The first operand to the CALL is the address of the function
8823 : called. */
8824 1246810192 : addr = CALL_EXPR_FN (call);
8825 :
8826 : /* If there is no function, return early. */
8827 1246810192 : if (addr == NULL_TREE)
8828 : return NULL_TREE;
8829 :
8830 1244164943 : STRIP_NOPS (addr);
8831 :
8832 : /* If this is a readonly function pointer, extract its initial value. */
8833 21136756 : if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
8834 2515770 : && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
8835 1244829890 : && DECL_INITIAL (addr))
8836 664892 : addr = DECL_INITIAL (addr);
8837 :
8838 : /* If the address is just `&f' for some function `f', then we know
8839 : that `f' is being called. */
8840 1244164943 : if (TREE_CODE (addr) == ADDR_EXPR
8841 1244164943 : && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
8842 1188930372 : return TREE_OPERAND (addr, 0);
8843 :
8844 : /* We couldn't figure out what was being called. */
8845 : return NULL_TREE;
8846 : }
8847 :
8848 : /* Return true when STMTs arguments and return value match those of FNDECL,
8849 : a decl of a builtin function. */
8850 :
8851 : static bool
8852 6365910 : tree_builtin_call_types_compatible_p (const_tree call, tree fndecl)
8853 : {
8854 6365910 : gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN);
8855 :
8856 6365910 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
8857 6365910 : if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
8858 6365910 : fndecl = decl;
8859 :
8860 6365910 : bool gimple_form = (cfun && (cfun->curr_properties & PROP_gimple)) != 0;
8861 6365910 : if (gimple_form
8862 15104 : ? !useless_type_conversion_p (TREE_TYPE (call),
8863 15104 : TREE_TYPE (TREE_TYPE (fndecl)))
8864 6350806 : : (TYPE_MAIN_VARIANT (TREE_TYPE (call))
8865 6350806 : != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))))
8866 : return false;
8867 :
8868 6365694 : tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
8869 6365694 : unsigned nargs = call_expr_nargs (call);
8870 16098487 : for (unsigned i = 0; i < nargs; ++i, targs = TREE_CHAIN (targs))
8871 : {
8872 : /* Variadic args follow. */
8873 11254219 : if (!targs)
8874 : return true;
8875 9733450 : tree arg = CALL_EXPR_ARG (call, i);
8876 9733450 : tree type = TREE_VALUE (targs);
8877 9733450 : if (gimple_form
8878 9733450 : ? !useless_type_conversion_p (type, TREE_TYPE (arg))
8879 9718346 : : TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (TREE_TYPE (arg)))
8880 : {
8881 : /* For pointer arguments be more forgiving, e.g. due to
8882 : FILE * vs. fileptr_type_node, or say char * vs. const char *
8883 : differences etc. */
8884 1128629 : if (!gimple_form
8885 564643 : && POINTER_TYPE_P (type)
8886 564091 : && POINTER_TYPE_P (TREE_TYPE (arg))
8887 1128629 : && tree_nop_conversion_p (type, TREE_TYPE (arg)))
8888 563986 : continue;
8889 657 : return false;
8890 : }
8891 : }
8892 9687889 : if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
8893 : return false;
8894 : return true;
8895 : }
8896 :
8897 : /* If CALL_EXPR CALL calls a normal built-in function or an internal function,
8898 : return the associated function code, otherwise return CFN_LAST. */
8899 :
8900 : combined_fn
8901 41910582 : get_call_combined_fn (const_tree call)
8902 : {
8903 : /* It's invalid to call this function with anything but a CALL_EXPR. */
8904 41910582 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8905 :
8906 41910582 : if (!CALL_EXPR_FN (call))
8907 66275 : return as_combined_fn (CALL_EXPR_IFN (call));
8908 :
8909 41844307 : tree fndecl = get_callee_fndecl (call);
8910 41844307 : if (fndecl
8911 41822150 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
8912 48210217 : && tree_builtin_call_types_compatible_p (call, fndecl))
8913 6365032 : return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
8914 :
8915 : return CFN_LAST;
8916 : }
8917 :
8918 : /* Comparator of indices based on tree_node_counts. */
8919 :
8920 : static int
8921 0 : tree_nodes_cmp (const void *p1, const void *p2)
8922 : {
8923 0 : const unsigned *n1 = (const unsigned *)p1;
8924 0 : const unsigned *n2 = (const unsigned *)p2;
8925 :
8926 0 : return tree_node_counts[*n1] - tree_node_counts[*n2];
8927 : }
8928 :
8929 : /* Comparator of indices based on tree_code_counts. */
8930 :
8931 : static int
8932 0 : tree_codes_cmp (const void *p1, const void *p2)
8933 : {
8934 0 : const unsigned *n1 = (const unsigned *)p1;
8935 0 : const unsigned *n2 = (const unsigned *)p2;
8936 :
8937 0 : return tree_code_counts[*n1] - tree_code_counts[*n2];
8938 : }
8939 :
8940 : #define TREE_MEM_USAGE_SPACES 40
8941 :
8942 : /* Print debugging information about tree nodes generated during the compile,
8943 : and any language-specific information. */
8944 :
8945 : void
8946 0 : dump_tree_statistics (void)
8947 : {
8948 0 : if (GATHER_STATISTICS)
8949 : {
8950 : uint64_t total_nodes, total_bytes;
8951 : fprintf (stderr, "\nKind Nodes Bytes\n");
8952 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8953 : total_nodes = total_bytes = 0;
8954 :
8955 : {
8956 : auto_vec<unsigned> indices (all_kinds);
8957 : for (unsigned i = 0; i < all_kinds; i++)
8958 : indices.quick_push (i);
8959 : indices.qsort (tree_nodes_cmp);
8960 :
8961 : for (unsigned i = 0; i < (int) all_kinds; i++)
8962 : {
8963 : unsigned j = indices[i];
8964 : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n",
8965 : tree_node_kind_names[j], SIZE_AMOUNT (tree_node_counts[j]),
8966 : SIZE_AMOUNT (tree_node_sizes[j]));
8967 : total_nodes += tree_node_counts[j];
8968 : total_bytes += tree_node_sizes[j];
8969 : }
8970 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8971 : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n", "Total",
8972 : SIZE_AMOUNT (total_nodes), SIZE_AMOUNT (total_bytes));
8973 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8974 : }
8975 :
8976 : {
8977 : fprintf (stderr, "Code Nodes\n");
8978 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8979 :
8980 : auto_vec<unsigned> indices (MAX_TREE_CODES);
8981 : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8982 : indices.quick_push (i);
8983 : indices.qsort (tree_codes_cmp);
8984 :
8985 : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8986 : {
8987 : unsigned j = indices[i];
8988 : fprintf (stderr, "%-32s %6" PRIu64 "%c\n",
8989 : get_tree_code_name ((enum tree_code) j),
8990 : SIZE_AMOUNT (tree_code_counts[j]));
8991 : }
8992 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8993 : fprintf (stderr, "\n");
8994 : ssanames_print_statistics ();
8995 : fprintf (stderr, "\n");
8996 : phinodes_print_statistics ();
8997 : fprintf (stderr, "\n");
8998 : }
8999 : }
9000 : else
9001 0 : fprintf (stderr, "(No per-node statistics)\n");
9002 :
9003 0 : print_type_hash_statistics ();
9004 0 : print_debug_expr_statistics ();
9005 0 : print_value_expr_statistics ();
9006 0 : lang_hooks.print_statistics ();
9007 0 : }
9008 :
9009 : #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
9010 :
9011 : /* Generate a crc32 of the low BYTES bytes of VALUE. */
9012 :
9013 : unsigned
9014 17155671 : crc32_unsigned_n (unsigned chksum, unsigned value, unsigned bytes)
9015 : {
9016 : /* This relies on the raw feedback's top 4 bits being zero. */
9017 : #define FEEDBACK(X) ((X) * 0x04c11db7)
9018 : #define SYNDROME(X) (FEEDBACK ((X) & 1) ^ FEEDBACK ((X) & 2) \
9019 : ^ FEEDBACK ((X) & 4) ^ FEEDBACK ((X) & 8))
9020 17155671 : static const unsigned syndromes[16] =
9021 : {
9022 : SYNDROME(0x0), SYNDROME(0x1), SYNDROME(0x2), SYNDROME(0x3),
9023 : SYNDROME(0x4), SYNDROME(0x5), SYNDROME(0x6), SYNDROME(0x7),
9024 : SYNDROME(0x8), SYNDROME(0x9), SYNDROME(0xa), SYNDROME(0xb),
9025 : SYNDROME(0xc), SYNDROME(0xd), SYNDROME(0xe), SYNDROME(0xf),
9026 : };
9027 : #undef FEEDBACK
9028 : #undef SYNDROME
9029 :
9030 17155671 : value <<= (32 - bytes * 8);
9031 57182607 : for (unsigned ix = bytes * 2; ix--; value <<= 4)
9032 : {
9033 40026936 : unsigned feedback = syndromes[((value ^ chksum) >> 28) & 0xf];
9034 :
9035 40026936 : chksum = (chksum << 4) ^ feedback;
9036 : }
9037 :
9038 17155671 : return chksum;
9039 : }
9040 :
9041 : /* Generate a crc32 of a string. */
9042 :
9043 : unsigned
9044 8784 : crc32_string (unsigned chksum, const char *string)
9045 : {
9046 350980 : do
9047 350980 : chksum = crc32_byte (chksum, *string);
9048 350980 : while (*string++);
9049 8784 : return chksum;
9050 : }
9051 :
9052 : /* P is a string that will be used in a symbol. Mask out any characters
9053 : that are not valid in that context. */
9054 :
9055 : void
9056 7506 : clean_symbol_name (char *p)
9057 : {
9058 86262 : for (; *p; p++)
9059 78756 : if (! (ISALNUM (*p)
9060 : #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
9061 : || *p == '$'
9062 : #endif
9063 : #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
9064 : || *p == '.'
9065 : #endif
9066 : ))
9067 7304 : *p = '_';
9068 7506 : }
9069 :
9070 : static GTY(()) unsigned anon_cnt = 0; /* Saved for PCH. */
9071 :
9072 : /* Create a unique anonymous identifier. The identifier is still a
9073 : valid assembly label. */
9074 :
9075 : tree
9076 3558331 : make_anon_name ()
9077 : {
9078 3558331 : const char *fmt =
9079 : #if !defined (NO_DOT_IN_LABEL)
9080 : "."
9081 : #elif !defined (NO_DOLLAR_IN_LABEL)
9082 : "$"
9083 : #else
9084 : "_"
9085 : #endif
9086 : "_anon_%d";
9087 :
9088 3558331 : char buf[24];
9089 3558331 : int len = snprintf (buf, sizeof (buf), fmt, anon_cnt++);
9090 3558331 : gcc_checking_assert (len < int (sizeof (buf)));
9091 :
9092 3558331 : tree id = get_identifier_with_length (buf, len);
9093 3558331 : IDENTIFIER_ANON_P (id) = true;
9094 :
9095 3558331 : return id;
9096 : }
9097 :
9098 : /* Generate a name for a special-purpose function.
9099 : The generated name may need to be unique across the whole link.
9100 : Changes to this function may also require corresponding changes to
9101 : xstrdup_mask_random.
9102 : TYPE is some string to identify the purpose of this function to the
9103 : linker or collect2; it must start with an uppercase letter,
9104 : one of:
9105 : I - for constructors
9106 : D - for destructors
9107 : N - for C++ anonymous namespaces
9108 : F - for DWARF unwind frame information. */
9109 :
9110 : tree
9111 5603 : get_file_function_name (const char *type)
9112 : {
9113 5603 : char *buf;
9114 5603 : const char *p;
9115 5603 : char *q;
9116 :
9117 : /* If we already have a name we know to be unique, just use that. */
9118 5603 : if (first_global_object_name)
9119 5304 : p = q = ASTRDUP (first_global_object_name);
9120 : /* If the target is handling the constructors/destructors, they
9121 : will be local to this file and the name is only necessary for
9122 : debugging purposes.
9123 : We also assign sub_I and sub_D suffixes to constructors called from
9124 : the global static constructors. These are always local.
9125 : OpenMP "declare target" offloaded constructors/destructors use "off_I" and
9126 : "off_D" for the same purpose. */
9127 299 : else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
9128 598 : || ((startswith (type, "sub_") || startswith (type, "off_"))
9129 299 : && (type[4] == 'I' || type[4] == 'D')))
9130 : {
9131 299 : const char *file = main_input_filename;
9132 299 : if (! file)
9133 0 : file = LOCATION_FILE (input_location);
9134 : /* Just use the file's basename, because the full pathname
9135 : might be quite long. */
9136 299 : p = q = ASTRDUP (lbasename (file));
9137 : }
9138 : else
9139 : {
9140 : /* Otherwise, the name must be unique across the entire link.
9141 : We don't have anything that we know to be unique to this translation
9142 : unit, so use what we do have and throw in some randomness. */
9143 0 : unsigned len;
9144 0 : const char *name = weak_global_object_name;
9145 0 : const char *file = main_input_filename;
9146 :
9147 0 : if (! name)
9148 0 : name = "";
9149 0 : if (! file)
9150 0 : file = LOCATION_FILE (input_location);
9151 :
9152 0 : len = strlen (file);
9153 0 : q = (char *) alloca (9 + 19 + len + 1);
9154 0 : memcpy (q, file, len + 1);
9155 :
9156 0 : snprintf (q + len, 9 + 19 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX,
9157 : crc32_string (0, name), get_random_seed (false));
9158 :
9159 0 : p = q;
9160 : }
9161 :
9162 5603 : clean_symbol_name (q);
9163 5603 : buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
9164 : + strlen (type));
9165 :
9166 : /* Set up the name of the file-level functions we may need.
9167 : Use a global object (which is already required to be unique over
9168 : the program) rather than the file name (which imposes extra
9169 : constraints). */
9170 5603 : sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
9171 :
9172 5603 : return get_identifier (buf);
9173 : }
9174 :
9175 : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9176 :
9177 : /* Complain that the tree code of NODE does not match the expected 0
9178 : terminated list of trailing codes. The trailing code list can be
9179 : empty, for a more vague error message. FILE, LINE, and FUNCTION
9180 : are of the caller. */
9181 :
9182 : void
9183 0 : tree_check_failed (const_tree node, const char *file,
9184 : int line, const char *function, ...)
9185 : {
9186 0 : va_list args;
9187 0 : const char *buffer;
9188 0 : unsigned length = 0;
9189 0 : enum tree_code code;
9190 :
9191 0 : va_start (args, function);
9192 0 : while ((code = (enum tree_code) va_arg (args, int)))
9193 0 : length += 4 + strlen (get_tree_code_name (code));
9194 0 : va_end (args);
9195 0 : if (length)
9196 : {
9197 0 : char *tmp;
9198 0 : va_start (args, function);
9199 0 : length += strlen ("expected ");
9200 0 : buffer = tmp = (char *) alloca (length);
9201 0 : length = 0;
9202 0 : while ((code = (enum tree_code) va_arg (args, int)))
9203 : {
9204 0 : const char *prefix = length ? " or " : "expected ";
9205 :
9206 0 : strcpy (tmp + length, prefix);
9207 0 : length += strlen (prefix);
9208 0 : strcpy (tmp + length, get_tree_code_name (code));
9209 0 : length += strlen (get_tree_code_name (code));
9210 : }
9211 0 : va_end (args);
9212 : }
9213 : else
9214 : buffer = "unexpected node";
9215 :
9216 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9217 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9218 : function, trim_filename (file), line);
9219 : }
9220 :
9221 : /* Complain that the tree code of NODE does match the expected 0
9222 : terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9223 : the caller. */
9224 :
9225 : void
9226 0 : tree_not_check_failed (const_tree node, const char *file,
9227 : int line, const char *function, ...)
9228 : {
9229 0 : va_list args;
9230 0 : char *buffer;
9231 0 : unsigned length = 0;
9232 0 : enum tree_code code;
9233 :
9234 0 : va_start (args, function);
9235 0 : while ((code = (enum tree_code) va_arg (args, int)))
9236 0 : length += 4 + strlen (get_tree_code_name (code));
9237 0 : va_end (args);
9238 0 : va_start (args, function);
9239 0 : buffer = (char *) alloca (length);
9240 0 : length = 0;
9241 0 : while ((code = (enum tree_code) va_arg (args, int)))
9242 : {
9243 0 : if (length)
9244 : {
9245 0 : strcpy (buffer + length, " or ");
9246 0 : length += 4;
9247 : }
9248 0 : strcpy (buffer + length, get_tree_code_name (code));
9249 0 : length += strlen (get_tree_code_name (code));
9250 : }
9251 0 : va_end (args);
9252 :
9253 0 : internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9254 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9255 : function, trim_filename (file), line);
9256 : }
9257 :
9258 : /* Similar to tree_check_failed, except that we check for a class of tree
9259 : code, given in CL. */
9260 :
9261 : void
9262 0 : tree_class_check_failed (const_tree node, const enum tree_code_class cl,
9263 : const char *file, int line, const char *function)
9264 : {
9265 0 : internal_error
9266 0 : ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9267 0 : TREE_CODE_CLASS_STRING (cl),
9268 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9269 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9270 : }
9271 :
9272 : /* Similar to tree_check_failed, except that instead of specifying a
9273 : dozen codes, use the knowledge that they're all sequential. */
9274 :
9275 : void
9276 0 : tree_range_check_failed (const_tree node, const char *file, int line,
9277 : const char *function, enum tree_code c1,
9278 : enum tree_code c2)
9279 : {
9280 0 : char *buffer;
9281 0 : unsigned length = 0;
9282 0 : unsigned int c;
9283 :
9284 0 : for (c = c1; c <= c2; ++c)
9285 0 : length += 4 + strlen (get_tree_code_name ((enum tree_code) c));
9286 :
9287 0 : length += strlen ("expected ");
9288 0 : buffer = (char *) alloca (length);
9289 0 : length = 0;
9290 :
9291 0 : for (c = c1; c <= c2; ++c)
9292 : {
9293 0 : const char *prefix = length ? " or " : "expected ";
9294 :
9295 0 : strcpy (buffer + length, prefix);
9296 0 : length += strlen (prefix);
9297 0 : strcpy (buffer + length, get_tree_code_name ((enum tree_code) c));
9298 0 : length += strlen (get_tree_code_name ((enum tree_code) c));
9299 : }
9300 :
9301 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9302 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9303 : function, trim_filename (file), line);
9304 : }
9305 :
9306 :
9307 : /* Similar to tree_check_failed, except that we check that a tree does
9308 : not have the specified code, given in CL. */
9309 :
9310 : void
9311 0 : tree_not_class_check_failed (const_tree node, const enum tree_code_class cl,
9312 : const char *file, int line, const char *function)
9313 : {
9314 0 : internal_error
9315 0 : ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9316 0 : TREE_CODE_CLASS_STRING (cl),
9317 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9318 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9319 : }
9320 :
9321 :
9322 : /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9323 :
9324 : void
9325 0 : omp_clause_check_failed (const_tree node, const char *file, int line,
9326 : const char *function, enum omp_clause_code code)
9327 : {
9328 0 : internal_error ("tree check: expected %<omp_clause %s%>, have %qs "
9329 : "in %s, at %s:%d",
9330 0 : omp_clause_code_name[code],
9331 0 : get_tree_code_name (TREE_CODE (node)),
9332 : function, trim_filename (file), line);
9333 : }
9334 :
9335 :
9336 : /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9337 :
9338 : void
9339 0 : omp_clause_range_check_failed (const_tree node, const char *file, int line,
9340 : const char *function, enum omp_clause_code c1,
9341 : enum omp_clause_code c2)
9342 : {
9343 0 : char *buffer;
9344 0 : unsigned length = 0;
9345 0 : unsigned int c;
9346 :
9347 0 : for (c = c1; c <= c2; ++c)
9348 0 : length += 4 + strlen (omp_clause_code_name[c]);
9349 :
9350 0 : length += strlen ("expected ");
9351 0 : buffer = (char *) alloca (length);
9352 0 : length = 0;
9353 :
9354 0 : for (c = c1; c <= c2; ++c)
9355 : {
9356 0 : const char *prefix = length ? " or " : "expected ";
9357 :
9358 0 : strcpy (buffer + length, prefix);
9359 0 : length += strlen (prefix);
9360 0 : strcpy (buffer + length, omp_clause_code_name[c]);
9361 0 : length += strlen (omp_clause_code_name[c]);
9362 : }
9363 :
9364 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9365 0 : buffer, omp_clause_code_name[TREE_CODE (node)],
9366 : function, trim_filename (file), line);
9367 : }
9368 :
9369 :
9370 : #undef DEFTREESTRUCT
9371 : #define DEFTREESTRUCT(VAL, NAME) NAME,
9372 :
9373 : static const char *ts_enum_names[] = {
9374 : #include "treestruct.def"
9375 : };
9376 : #undef DEFTREESTRUCT
9377 :
9378 : #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9379 :
9380 : /* Similar to tree_class_check_failed, except that we check for
9381 : whether CODE contains the tree structure identified by EN. */
9382 :
9383 : void
9384 0 : tree_contains_struct_check_failed (const_tree node,
9385 : const enum tree_node_structure_enum en,
9386 : const char *file, int line,
9387 : const char *function)
9388 : {
9389 0 : internal_error
9390 0 : ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9391 0 : TS_ENUM_NAME (en),
9392 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9393 : }
9394 :
9395 :
9396 : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9397 : (dynamically sized) vector. */
9398 :
9399 : void
9400 0 : tree_int_cst_elt_check_failed (int idx, int len, const char *file, int line,
9401 : const char *function)
9402 : {
9403 0 : internal_error
9404 0 : ("tree check: accessed elt %d of %<tree_int_cst%> with %d elts in %s, "
9405 : "at %s:%d",
9406 : idx + 1, len, function, trim_filename (file), line);
9407 : }
9408 :
9409 : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9410 : (dynamically sized) vector. */
9411 :
9412 : void
9413 0 : tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
9414 : const char *function)
9415 : {
9416 0 : internal_error
9417 0 : ("tree check: accessed elt %d of %<tree_vec%> with %d elts in %s, at %s:%d",
9418 : idx + 1, len, function, trim_filename (file), line);
9419 : }
9420 :
9421 : /* Similar to above, except that the check is for the bounds of the operand
9422 : vector of an expression node EXP. */
9423 :
9424 : void
9425 0 : tree_operand_check_failed (int idx, const_tree exp, const char *file,
9426 : int line, const char *function)
9427 : {
9428 0 : enum tree_code code = TREE_CODE (exp);
9429 0 : internal_error
9430 0 : ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9431 : idx + 1, get_tree_code_name (code), TREE_OPERAND_LENGTH (exp),
9432 : function, trim_filename (file), line);
9433 : }
9434 :
9435 : /* Similar to above, except that the check is for the number of
9436 : operands of an OMP_CLAUSE node. */
9437 :
9438 : void
9439 0 : omp_clause_operand_check_failed (int idx, const_tree t, const char *file,
9440 : int line, const char *function)
9441 : {
9442 0 : internal_error
9443 0 : ("tree check: accessed operand %d of %<omp_clause %s%> with %d operands "
9444 0 : "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
9445 0 : omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
9446 : trim_filename (file), line);
9447 : }
9448 : #endif /* ENABLE_TREE_CHECKING */
9449 :
9450 : /* Create a new vector type node holding NUNITS units of type INNERTYPE,
9451 : and mapped to the machine mode MODE. Initialize its fields and build
9452 : the information necessary for debugging output. */
9453 :
9454 : static tree
9455 73831681 : make_vector_type (tree innertype, poly_int64 nunits, machine_mode mode)
9456 : {
9457 73831681 : tree t;
9458 73831681 : tree mv_innertype = TYPE_MAIN_VARIANT (innertype);
9459 :
9460 73831681 : t = make_node (VECTOR_TYPE);
9461 73831681 : TREE_TYPE (t) = mv_innertype;
9462 73831681 : SET_TYPE_VECTOR_SUBPARTS (t, nunits);
9463 73831681 : SET_TYPE_MODE (t, mode);
9464 :
9465 73831681 : if (TYPE_STRUCTURAL_EQUALITY_P (mv_innertype) || in_lto_p)
9466 1193349 : SET_TYPE_STRUCTURAL_EQUALITY (t);
9467 72638332 : else if ((TYPE_CANONICAL (mv_innertype) != innertype
9468 68960060 : || mode != VOIDmode)
9469 105111270 : && !VECTOR_BOOLEAN_TYPE_P (t))
9470 33469914 : TYPE_CANONICAL (t)
9471 66939828 : = make_vector_type (TYPE_CANONICAL (mv_innertype), nunits, VOIDmode);
9472 :
9473 73831681 : layout_type (t);
9474 :
9475 73831681 : hashval_t hash = type_hash_canon_hash (t);
9476 73831681 : t = type_hash_canon (hash, t);
9477 :
9478 : /* We have built a main variant, based on the main variant of the
9479 : inner type. Use it to build the variant we return. */
9480 147657644 : if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
9481 74666277 : && TREE_TYPE (t) != innertype)
9482 838989 : return build_type_attribute_qual_variant (t,
9483 838989 : TYPE_ATTRIBUTES (innertype),
9484 1677978 : TYPE_QUALS (innertype));
9485 :
9486 : return t;
9487 : }
9488 :
9489 : static tree
9490 4081792 : make_or_reuse_type (unsigned size, int unsignedp)
9491 : {
9492 4081792 : int i;
9493 :
9494 4081792 : if (size == INT_TYPE_SIZE)
9495 876204 : return unsignedp ? unsigned_type_node : integer_type_node;
9496 3205588 : if (size == CHAR_TYPE_SIZE)
9497 584136 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
9498 2621452 : if (size == SHORT_TYPE_SIZE)
9499 876204 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
9500 1781624 : if (size == LONG_TYPE_SIZE)
9501 854436 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
9502 890812 : if (size == LONG_LONG_TYPE_SIZE)
9503 21768 : return (unsignedp ? long_long_unsigned_type_node
9504 21768 : : long_long_integer_type_node);
9505 :
9506 883364 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9507 869044 : if (size == int_n_data[i].bitsize
9508 869044 : && int_n_enabled_p[i])
9509 854724 : return (unsignedp ? int_n_trees[i].unsigned_type
9510 854724 : : int_n_trees[i].signed_type);
9511 :
9512 14320 : if (unsignedp)
9513 7160 : return make_unsigned_type (size);
9514 : else
9515 7160 : return make_signed_type (size);
9516 : }
9517 :
9518 : /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9519 :
9520 : static tree
9521 5841360 : make_or_reuse_fract_type (unsigned size, int unsignedp, int satp)
9522 : {
9523 5841360 : if (satp)
9524 : {
9525 2920680 : if (size == SHORT_FRACT_TYPE_SIZE)
9526 584136 : return unsignedp ? sat_unsigned_short_fract_type_node
9527 584136 : : sat_short_fract_type_node;
9528 2336544 : if (size == FRACT_TYPE_SIZE)
9529 584136 : return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node;
9530 1752408 : if (size == LONG_FRACT_TYPE_SIZE)
9531 584136 : return unsignedp ? sat_unsigned_long_fract_type_node
9532 584136 : : sat_long_fract_type_node;
9533 1168272 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9534 584136 : return unsignedp ? sat_unsigned_long_long_fract_type_node
9535 584136 : : sat_long_long_fract_type_node;
9536 : }
9537 : else
9538 : {
9539 2920680 : if (size == SHORT_FRACT_TYPE_SIZE)
9540 584136 : return unsignedp ? unsigned_short_fract_type_node
9541 584136 : : short_fract_type_node;
9542 2336544 : if (size == FRACT_TYPE_SIZE)
9543 584136 : return unsignedp ? unsigned_fract_type_node : fract_type_node;
9544 1752408 : if (size == LONG_FRACT_TYPE_SIZE)
9545 584136 : return unsignedp ? unsigned_long_fract_type_node
9546 584136 : : long_fract_type_node;
9547 1168272 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9548 584136 : return unsignedp ? unsigned_long_long_fract_type_node
9549 584136 : : long_long_fract_type_node;
9550 : }
9551 :
9552 1168272 : return make_fract_type (size, unsignedp, satp);
9553 : }
9554 :
9555 : /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9556 :
9557 : static tree
9558 4673088 : make_or_reuse_accum_type (unsigned size, int unsignedp, int satp)
9559 : {
9560 4673088 : if (satp)
9561 : {
9562 2336544 : if (size == SHORT_ACCUM_TYPE_SIZE)
9563 584136 : return unsignedp ? sat_unsigned_short_accum_type_node
9564 584136 : : sat_short_accum_type_node;
9565 1752408 : if (size == ACCUM_TYPE_SIZE)
9566 584136 : return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node;
9567 1168272 : if (size == LONG_ACCUM_TYPE_SIZE)
9568 584136 : return unsignedp ? sat_unsigned_long_accum_type_node
9569 584136 : : sat_long_accum_type_node;
9570 584136 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9571 584136 : return unsignedp ? sat_unsigned_long_long_accum_type_node
9572 584136 : : sat_long_long_accum_type_node;
9573 : }
9574 : else
9575 : {
9576 2336544 : if (size == SHORT_ACCUM_TYPE_SIZE)
9577 584136 : return unsignedp ? unsigned_short_accum_type_node
9578 584136 : : short_accum_type_node;
9579 1752408 : if (size == ACCUM_TYPE_SIZE)
9580 584136 : return unsignedp ? unsigned_accum_type_node : accum_type_node;
9581 1168272 : if (size == LONG_ACCUM_TYPE_SIZE)
9582 584136 : return unsignedp ? unsigned_long_accum_type_node
9583 584136 : : long_accum_type_node;
9584 584136 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9585 584136 : return unsignedp ? unsigned_long_long_accum_type_node
9586 584136 : : long_long_accum_type_node;
9587 : }
9588 :
9589 0 : return make_accum_type (size, unsignedp, satp);
9590 : }
9591 :
9592 :
9593 : /* Create an atomic variant node for TYPE. This routine is called
9594 : during initialization of data types to create the 5 basic atomic
9595 : types. The generic build_variant_type function requires these to
9596 : already be set up in order to function properly, so cannot be
9597 : called from there. If ALIGN is non-zero, then ensure alignment is
9598 : overridden to this value. */
9599 :
9600 : static tree
9601 1460340 : build_atomic_base (tree type, unsigned int align)
9602 : {
9603 1460340 : tree t;
9604 :
9605 : /* Make sure its not already registered. */
9606 1460340 : if ((t = get_qualified_type (type, TYPE_QUAL_ATOMIC)))
9607 : return t;
9608 :
9609 1460340 : t = build_variant_type_copy (type);
9610 1460340 : set_type_quals (t, TYPE_QUAL_ATOMIC);
9611 :
9612 1460340 : if (align)
9613 0 : SET_TYPE_ALIGN (t, align);
9614 :
9615 : return t;
9616 : }
9617 :
9618 : /* Return unsigned integer tree node for TYPE. */
9619 :
9620 : tree
9621 292108 : unsigned_integer_tree_node_for_type (const char *type)
9622 : {
9623 292108 : tree type_node;
9624 :
9625 292108 : if (strcmp (type, "unsigned int") == 0)
9626 7256 : type_node = unsigned_type_node;
9627 284852 : else if (strcmp (type, "long unsigned int") == 0)
9628 284852 : type_node = long_unsigned_type_node;
9629 0 : else if (strcmp (type, "long long unsigned int") == 0)
9630 0 : type_node = long_long_unsigned_type_node;
9631 0 : else if (strcmp (type, "short unsigned int") == 0)
9632 0 : type_node = short_unsigned_type_node;
9633 : else
9634 : {
9635 : int i;
9636 :
9637 : type_node = nullptr;
9638 0 : for (i = 0; i < NUM_INT_N_ENTS; i++)
9639 0 : if (int_n_enabled_p[i])
9640 : {
9641 0 : char name[50], altname[50];
9642 0 : sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
9643 0 : sprintf (altname, "__int%d__ unsigned", int_n_data[i].bitsize);
9644 :
9645 0 : if (strcmp (name, type) == 0
9646 0 : || strcmp (altname, type) == 0)
9647 : {
9648 0 : type_node = int_n_trees[i].unsigned_type;
9649 : }
9650 : }
9651 0 : if (type_node == nullptr)
9652 0 : gcc_unreachable ();
9653 : }
9654 :
9655 292108 : return type_node;
9656 : }
9657 :
9658 : /* Information about the _FloatN and _FloatNx types. This must be in
9659 : the same order as the corresponding TI_* enum values. */
9660 : const floatn_type_info floatn_nx_types[NUM_FLOATN_NX_TYPES] =
9661 : {
9662 : { 16, false },
9663 : { 32, false },
9664 : { 64, false },
9665 : { 128, false },
9666 : { 32, true },
9667 : { 64, true },
9668 : { 128, true },
9669 : };
9670 :
9671 :
9672 : /* Create nodes for all integer types (and error_mark_node) using the sizes
9673 : of C datatypes. SIGNED_CHAR specifies whether char is signed. */
9674 :
9675 : void
9676 292068 : build_common_tree_nodes (bool signed_char)
9677 : {
9678 292068 : int i;
9679 :
9680 292068 : error_mark_node = make_node (ERROR_MARK);
9681 292068 : TREE_TYPE (error_mark_node) = error_mark_node;
9682 :
9683 292068 : initialize_sizetypes ();
9684 :
9685 : /* Define both `signed char' and `unsigned char'. */
9686 292068 : signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
9687 292068 : TYPE_STRING_FLAG (signed_char_type_node) = 1;
9688 292068 : unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
9689 292068 : TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
9690 :
9691 : /* Define `char', which is like either `signed char' or `unsigned char'
9692 : but not the same as either. */
9693 292068 : char_type_node
9694 292068 : = (signed_char
9695 292068 : ? make_signed_type (CHAR_TYPE_SIZE)
9696 58343 : : make_unsigned_type (CHAR_TYPE_SIZE));
9697 292068 : TYPE_STRING_FLAG (char_type_node) = 1;
9698 :
9699 292068 : short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
9700 292068 : short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
9701 292068 : integer_type_node = make_signed_type (INT_TYPE_SIZE);
9702 292068 : unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
9703 299324 : long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
9704 299324 : long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
9705 292068 : long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
9706 292068 : long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
9707 :
9708 876204 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9709 : {
9710 292068 : int_n_trees[i].signed_type = make_signed_type (int_n_data[i].bitsize);
9711 292068 : int_n_trees[i].unsigned_type = make_unsigned_type (int_n_data[i].bitsize);
9712 :
9713 292068 : if (int_n_enabled_p[i])
9714 : {
9715 284908 : integer_types[itk_intN_0 + i * 2] = int_n_trees[i].signed_type;
9716 284908 : integer_types[itk_unsigned_intN_0 + i * 2] = int_n_trees[i].unsigned_type;
9717 : }
9718 : }
9719 :
9720 : /* Define a boolean type. This type only represents boolean values but
9721 : may be larger than char depending on the value of BOOL_TYPE_SIZE. */
9722 292068 : boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
9723 292068 : TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
9724 292068 : TYPE_PRECISION (boolean_type_node) = 1;
9725 292068 : TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
9726 :
9727 : /* Define what type to use for size_t. */
9728 299324 : size_type_node = unsigned_integer_tree_node_for_type (SIZE_TYPE);
9729 :
9730 : /* Define what type to use for ptrdiff_t. */
9731 299324 : if (strcmp (PTRDIFF_TYPE, "int") == 0)
9732 7256 : ptrdiff_type_node = integer_type_node;
9733 284812 : else if (strcmp (PTRDIFF_TYPE, "long int") == 0)
9734 284812 : ptrdiff_type_node = long_integer_type_node;
9735 0 : else if (strcmp (PTRDIFF_TYPE, "long long int") == 0)
9736 0 : ptrdiff_type_node = long_long_integer_type_node;
9737 0 : else if (strcmp (PTRDIFF_TYPE, "short int") == 0)
9738 0 : ptrdiff_type_node = short_integer_type_node;
9739 : else
9740 : {
9741 0 : ptrdiff_type_node = NULL_TREE;
9742 0 : for (int i = 0; i < NUM_INT_N_ENTS; i++)
9743 0 : if (int_n_enabled_p[i])
9744 : {
9745 0 : char name[50], altname[50];
9746 0 : sprintf (name, "__int%d", int_n_data[i].bitsize);
9747 0 : sprintf (altname, "__int%d__", int_n_data[i].bitsize);
9748 :
9749 0 : if (strcmp (name, PTRDIFF_TYPE) == 0
9750 0 : || strcmp (altname, PTRDIFF_TYPE) == 0)
9751 0 : ptrdiff_type_node = int_n_trees[i].signed_type;
9752 : }
9753 0 : if (ptrdiff_type_node == NULL_TREE)
9754 0 : gcc_unreachable ();
9755 : }
9756 :
9757 : /* Fill in the rest of the sized types. Reuse existing type nodes
9758 : when possible. */
9759 292068 : intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
9760 292068 : intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
9761 292068 : intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
9762 292068 : intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
9763 292068 : intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
9764 :
9765 292068 : unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
9766 292068 : unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
9767 292068 : unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
9768 292068 : unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
9769 292068 : unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
9770 :
9771 : /* Don't call build_qualified type for atomics. That routine does
9772 : special processing for atomics, and until they are initialized
9773 : it's better not to make that call.
9774 :
9775 : Check to see if there is a target override for atomic types. */
9776 :
9777 292068 : atomicQI_type_node = build_atomic_base (unsigned_intQI_type_node,
9778 292068 : targetm.atomic_align_for_mode (QImode));
9779 292068 : atomicHI_type_node = build_atomic_base (unsigned_intHI_type_node,
9780 292068 : targetm.atomic_align_for_mode (HImode));
9781 292068 : atomicSI_type_node = build_atomic_base (unsigned_intSI_type_node,
9782 292068 : targetm.atomic_align_for_mode (SImode));
9783 292068 : atomicDI_type_node = build_atomic_base (unsigned_intDI_type_node,
9784 292068 : targetm.atomic_align_for_mode (DImode));
9785 292068 : atomicTI_type_node = build_atomic_base (unsigned_intTI_type_node,
9786 292068 : targetm.atomic_align_for_mode (TImode));
9787 :
9788 292068 : access_public_node = get_identifier ("public");
9789 292068 : access_protected_node = get_identifier ("protected");
9790 292068 : access_private_node = get_identifier ("private");
9791 :
9792 : /* Define these next since types below may used them. */
9793 292068 : integer_zero_node = build_int_cst (integer_type_node, 0);
9794 292068 : integer_one_node = build_int_cst (integer_type_node, 1);
9795 292068 : integer_minus_one_node = build_int_cst (integer_type_node, -1);
9796 :
9797 292068 : size_zero_node = size_int (0);
9798 292068 : size_one_node = size_int (1);
9799 292068 : bitsize_zero_node = bitsize_int (0);
9800 292068 : bitsize_one_node = bitsize_int (1);
9801 292068 : bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
9802 :
9803 292068 : boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
9804 292068 : boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
9805 :
9806 292068 : void_type_node = make_node (VOID_TYPE);
9807 292068 : layout_type (void_type_node);
9808 :
9809 : /* We are not going to have real types in C with less than byte alignment,
9810 : so we might as well not have any types that claim to have it. */
9811 292068 : SET_TYPE_ALIGN (void_type_node, BITS_PER_UNIT);
9812 292068 : TYPE_USER_ALIGN (void_type_node) = 0;
9813 :
9814 292068 : void_node = make_node (VOID_CST);
9815 292068 : TREE_TYPE (void_node) = void_type_node;
9816 :
9817 292068 : void_list_node = build_tree_list (NULL_TREE, void_type_node);
9818 :
9819 292068 : null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
9820 292068 : layout_type (TREE_TYPE (null_pointer_node));
9821 :
9822 292068 : ptr_type_node = build_pointer_type (void_type_node);
9823 292068 : const_ptr_type_node
9824 292068 : = build_pointer_type (build_type_variant (void_type_node, 1, 0));
9825 2044476 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
9826 1752408 : builtin_structptr_types[i].node = builtin_structptr_types[i].base;
9827 :
9828 299324 : pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
9829 :
9830 292068 : float_type_node = make_node (REAL_TYPE);
9831 292068 : machine_mode float_type_mode
9832 292068 : = targetm.c.mode_for_floating_type (TI_FLOAT_TYPE);
9833 292068 : SET_TYPE_MODE (float_type_node, float_type_mode);
9834 292068 : TYPE_PRECISION (float_type_node)
9835 292068 : = GET_MODE_PRECISION (float_type_mode).to_constant ();
9836 292068 : layout_type (float_type_node);
9837 :
9838 292068 : double_type_node = make_node (REAL_TYPE);
9839 292068 : machine_mode double_type_mode
9840 292068 : = targetm.c.mode_for_floating_type (TI_DOUBLE_TYPE);
9841 292068 : SET_TYPE_MODE (double_type_node, double_type_mode);
9842 292068 : TYPE_PRECISION (double_type_node)
9843 292068 : = GET_MODE_PRECISION (double_type_mode).to_constant ();
9844 292068 : layout_type (double_type_node);
9845 :
9846 292068 : long_double_type_node = make_node (REAL_TYPE);
9847 292068 : machine_mode long_double_type_mode
9848 292068 : = targetm.c.mode_for_floating_type (TI_LONG_DOUBLE_TYPE);
9849 292068 : SET_TYPE_MODE (long_double_type_node, long_double_type_mode);
9850 292068 : TYPE_PRECISION (long_double_type_node)
9851 292068 : = GET_MODE_PRECISION (long_double_type_mode).to_constant ();
9852 292068 : layout_type (long_double_type_node);
9853 :
9854 2336544 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9855 : {
9856 2044476 : int n = floatn_nx_types[i].n;
9857 2044476 : bool extended = floatn_nx_types[i].extended;
9858 2044476 : scalar_float_mode mode;
9859 2044476 : if (!targetm.floatn_mode (n, extended).exists (&mode))
9860 292068 : continue;
9861 1752408 : int precision = GET_MODE_PRECISION (mode);
9862 1752408 : FLOATN_NX_TYPE_NODE (i) = make_node (REAL_TYPE);
9863 1752408 : TYPE_PRECISION (FLOATN_NX_TYPE_NODE (i)) = precision;
9864 1752408 : layout_type (FLOATN_NX_TYPE_NODE (i));
9865 1752408 : SET_TYPE_MODE (FLOATN_NX_TYPE_NODE (i), mode);
9866 : }
9867 292068 : float128t_type_node = float128_type_node;
9868 : #ifdef HAVE_BFmode
9869 292068 : if (REAL_MODE_FORMAT (BFmode) == &arm_bfloat_half_format
9870 292068 : && targetm.scalar_mode_supported_p (BFmode)
9871 584136 : && targetm.libgcc_floating_mode_supported_p (BFmode))
9872 : {
9873 292068 : bfloat16_type_node = make_node (REAL_TYPE);
9874 292068 : TYPE_PRECISION (bfloat16_type_node) = GET_MODE_PRECISION (BFmode);
9875 292068 : layout_type (bfloat16_type_node);
9876 292068 : SET_TYPE_MODE (bfloat16_type_node, BFmode);
9877 : }
9878 : #endif
9879 :
9880 292068 : float_ptr_type_node = build_pointer_type (float_type_node);
9881 292068 : double_ptr_type_node = build_pointer_type (double_type_node);
9882 292068 : long_double_ptr_type_node = build_pointer_type (long_double_type_node);
9883 292068 : integer_ptr_type_node = build_pointer_type (integer_type_node);
9884 :
9885 : /* Fixed size integer types. */
9886 292068 : uint16_type_node = make_or_reuse_type (16, 1);
9887 292068 : uint32_type_node = make_or_reuse_type (32, 1);
9888 292068 : uint64_type_node = make_or_reuse_type (64, 1);
9889 292068 : if (targetm.scalar_mode_supported_p (TImode))
9890 284908 : uint128_type_node = make_or_reuse_type (128, 1);
9891 :
9892 : /* Decimal float types. */
9893 292068 : if (targetm.decimal_float_supported_p ())
9894 : {
9895 292068 : dfloat32_type_node = make_node (REAL_TYPE);
9896 292068 : TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
9897 292068 : SET_TYPE_MODE (dfloat32_type_node, SDmode);
9898 292068 : layout_type (dfloat32_type_node);
9899 :
9900 292068 : dfloat64_type_node = make_node (REAL_TYPE);
9901 292068 : TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
9902 292068 : SET_TYPE_MODE (dfloat64_type_node, DDmode);
9903 292068 : layout_type (dfloat64_type_node);
9904 :
9905 292068 : dfloat128_type_node = make_node (REAL_TYPE);
9906 292068 : TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
9907 292068 : SET_TYPE_MODE (dfloat128_type_node, TDmode);
9908 292068 : layout_type (dfloat128_type_node);
9909 :
9910 292068 : dfloat64x_type_node = make_node (REAL_TYPE);
9911 292068 : TYPE_PRECISION (dfloat64x_type_node) = DECIMAL128_TYPE_SIZE;
9912 292068 : SET_TYPE_MODE (dfloat64x_type_node, TDmode);
9913 292068 : layout_type (dfloat64x_type_node);
9914 : }
9915 :
9916 292068 : complex_integer_type_node = build_complex_type (integer_type_node, true);
9917 292068 : complex_float_type_node = build_complex_type (float_type_node, true);
9918 292068 : complex_double_type_node = build_complex_type (double_type_node, true);
9919 292068 : complex_long_double_type_node = build_complex_type (long_double_type_node,
9920 : true);
9921 :
9922 2336544 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9923 : {
9924 2044476 : if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
9925 1752408 : COMPLEX_FLOATN_NX_TYPE_NODE (i)
9926 1752408 : = build_complex_type (FLOATN_NX_TYPE_NODE (i));
9927 : }
9928 :
9929 : /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9930 : #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9931 : sat_ ## KIND ## _type_node = \
9932 : make_sat_signed_ ## KIND ## _type (SIZE); \
9933 : sat_unsigned_ ## KIND ## _type_node = \
9934 : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9935 : KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9936 : unsigned_ ## KIND ## _type_node = \
9937 : make_unsigned_ ## KIND ## _type (SIZE);
9938 :
9939 : #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9940 : sat_ ## WIDTH ## KIND ## _type_node = \
9941 : make_sat_signed_ ## KIND ## _type (SIZE); \
9942 : sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9943 : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9944 : WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9945 : unsigned_ ## WIDTH ## KIND ## _type_node = \
9946 : make_unsigned_ ## KIND ## _type (SIZE);
9947 :
9948 : /* Make fixed-point type nodes based on four different widths. */
9949 : #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9950 : MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9951 : MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9952 : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9953 : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9954 :
9955 : /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9956 : #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9957 : NAME ## _type_node = \
9958 : make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9959 : u ## NAME ## _type_node = \
9960 : make_or_reuse_unsigned_ ## KIND ## _type \
9961 : (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9962 : sat_ ## NAME ## _type_node = \
9963 : make_or_reuse_sat_signed_ ## KIND ## _type \
9964 : (GET_MODE_BITSIZE (MODE ## mode)); \
9965 : sat_u ## NAME ## _type_node = \
9966 : make_or_reuse_sat_unsigned_ ## KIND ## _type \
9967 : (GET_MODE_BITSIZE (U ## MODE ## mode));
9968 :
9969 : /* Fixed-point type and mode nodes. */
9970 292068 : MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT)
9971 292068 : MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM)
9972 292068 : MAKE_FIXED_MODE_NODE (fract, qq, QQ)
9973 292068 : MAKE_FIXED_MODE_NODE (fract, hq, HQ)
9974 292068 : MAKE_FIXED_MODE_NODE (fract, sq, SQ)
9975 292068 : MAKE_FIXED_MODE_NODE (fract, dq, DQ)
9976 292068 : MAKE_FIXED_MODE_NODE (fract, tq, TQ)
9977 292068 : MAKE_FIXED_MODE_NODE (accum, ha, HA)
9978 292068 : MAKE_FIXED_MODE_NODE (accum, sa, SA)
9979 292068 : MAKE_FIXED_MODE_NODE (accum, da, DA)
9980 292068 : MAKE_FIXED_MODE_NODE (accum, ta, TA)
9981 :
9982 292068 : {
9983 292068 : tree t = targetm.build_builtin_va_list ();
9984 :
9985 : /* Many back-ends define record types without setting TYPE_NAME.
9986 : If we copied the record type here, we'd keep the original
9987 : record type without a name. This breaks name mangling. So,
9988 : don't copy record types and let c_common_nodes_and_builtins()
9989 : declare the type to be __builtin_va_list. */
9990 292068 : if (TREE_CODE (t) != RECORD_TYPE)
9991 292068 : t = build_variant_type_copy (t);
9992 :
9993 292068 : va_list_type_node = t;
9994 : }
9995 :
9996 : /* SCEV analyzer global shared trees. */
9997 292068 : chrec_dont_know = make_node (SCEV_NOT_KNOWN);
9998 292068 : TREE_TYPE (chrec_dont_know) = void_type_node;
9999 292068 : chrec_known = make_node (SCEV_KNOWN);
10000 292068 : TREE_TYPE (chrec_known) = void_type_node;
10001 292068 : }
10002 :
10003 : /* Modify DECL for given flags.
10004 : TM_PURE attribute is set only on types, so the function will modify
10005 : DECL's type when ECF_TM_PURE is used. */
10006 :
10007 : void
10008 32531189 : set_call_expr_flags (tree decl, int flags)
10009 : {
10010 32531189 : if (flags & ECF_NOTHROW)
10011 28194680 : TREE_NOTHROW (decl) = 1;
10012 32531189 : if (flags & ECF_CONST)
10013 13442786 : TREE_READONLY (decl) = 1;
10014 32531189 : if (flags & ECF_PURE)
10015 1583061 : DECL_PURE_P (decl) = 1;
10016 32531189 : if (flags & ECF_LOOPING_CONST_OR_PURE)
10017 59644 : DECL_LOOPING_CONST_OR_PURE_P (decl) = 1;
10018 32531189 : if (flags & ECF_NOVOPS)
10019 0 : DECL_IS_NOVOPS (decl) = 1;
10020 32531189 : if (flags & ECF_NORETURN)
10021 1259981 : TREE_THIS_VOLATILE (decl) = 1;
10022 32531189 : if (flags & ECF_MALLOC)
10023 753075 : DECL_IS_MALLOC (decl) = 1;
10024 32531189 : if (flags & ECF_RETURNS_TWICE)
10025 0 : DECL_IS_RETURNS_TWICE (decl) = 1;
10026 32531189 : if (flags & ECF_LEAF)
10027 28010288 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("leaf"),
10028 28010288 : NULL, DECL_ATTRIBUTES (decl));
10029 32531189 : if (flags & ECF_COLD)
10030 670221 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("cold"),
10031 670221 : NULL, DECL_ATTRIBUTES (decl));
10032 32531189 : if (flags & ECF_RET1)
10033 0 : DECL_ATTRIBUTES (decl)
10034 0 : = tree_cons (get_identifier ("fn spec"),
10035 : build_tree_list (NULL_TREE, build_string (2, "1 ")),
10036 0 : DECL_ATTRIBUTES (decl));
10037 32531189 : if ((flags & ECF_TM_PURE) && flag_tm)
10038 535 : apply_tm_attr (decl, get_identifier ("transaction_pure"));
10039 32531189 : if ((flags & ECF_XTHROW))
10040 420775 : DECL_ATTRIBUTES (decl)
10041 841550 : = tree_cons (get_identifier ("expected_throw"),
10042 420775 : NULL, DECL_ATTRIBUTES (decl));
10043 :
10044 32531189 : if (flags & ECF_CB_1_2)
10045 : {
10046 382356 : tree attr = callback_build_attr (1, 1, 2);
10047 382356 : TREE_CHAIN (attr) = DECL_ATTRIBUTES (decl);
10048 382356 : DECL_ATTRIBUTES (decl) = attr;
10049 : }
10050 :
10051 : /* Looping const or pure is implied by noreturn.
10052 : There is currently no way to declare looping const or looping pure alone. */
10053 32531189 : gcc_assert (!(flags & ECF_LOOPING_CONST_OR_PURE)
10054 : || (flags & (ECF_CONST | ECF_PURE)));
10055 32531189 : }
10056 :
10057 :
10058 : /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
10059 :
10060 : static void
10061 9747372 : local_define_builtin (const char *name, tree type, enum built_in_function code,
10062 : const char *library_name, int ecf_flags)
10063 : {
10064 9747372 : tree decl;
10065 :
10066 9747372 : decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
10067 : library_name, NULL_TREE);
10068 9747372 : set_call_expr_flags (decl, ecf_flags);
10069 :
10070 9747372 : set_builtin_decl (code, decl, true);
10071 9747372 : }
10072 :
10073 : /* Call this function after instantiating all builtins that the language
10074 : front end cares about. This will build the rest of the builtins
10075 : and internal functions that are relied upon by the tree optimizers and
10076 : the middle-end. */
10077 :
10078 : void
10079 292051 : build_common_builtin_nodes (void)
10080 : {
10081 292051 : tree tmp, ftype;
10082 292051 : int ecf_flags;
10083 :
10084 292051 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_PADDING))
10085 : {
10086 59644 : ftype = build_function_type_list (void_type_node,
10087 : ptr_type_node,
10088 : ptr_type_node,
10089 : NULL_TREE);
10090 59644 : local_define_builtin ("__builtin_clear_padding", ftype,
10091 : BUILT_IN_CLEAR_PADDING,
10092 : "__builtin_clear_padding",
10093 : ECF_LEAF | ECF_NOTHROW);
10094 : }
10095 :
10096 292051 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE)
10097 237053 : || !builtin_decl_explicit_p (BUILT_IN_TRAP)
10098 237053 : || !builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP)
10099 232407 : || !builtin_decl_explicit_p (BUILT_IN_OBSERVABLE_CHKPT)
10100 524458 : || !builtin_decl_explicit_p (BUILT_IN_ABORT))
10101 : {
10102 59644 : ftype = build_function_type (void_type_node, void_list_node);
10103 59644 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE))
10104 54998 : local_define_builtin ("__builtin_unreachable", ftype,
10105 : BUILT_IN_UNREACHABLE,
10106 : "__builtin_unreachable",
10107 : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10108 : | ECF_CONST | ECF_COLD);
10109 59644 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP))
10110 59644 : local_define_builtin ("__builtin_unreachable trap", ftype,
10111 : BUILT_IN_UNREACHABLE_TRAP,
10112 : "__builtin_unreachable trap",
10113 : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10114 : | ECF_CONST | ECF_COLD);
10115 59644 : if (!builtin_decl_explicit_p (BUILT_IN_ABORT))
10116 59644 : local_define_builtin ("__builtin_abort", ftype, BUILT_IN_ABORT,
10117 : "abort",
10118 : ECF_LEAF | ECF_NORETURN | ECF_CONST | ECF_COLD);
10119 59644 : if (!builtin_decl_explicit_p (BUILT_IN_TRAP))
10120 23135 : local_define_builtin ("__builtin_trap", ftype, BUILT_IN_TRAP,
10121 : "__builtin_trap",
10122 : ECF_NORETURN | ECF_NOTHROW | ECF_LEAF | ECF_COLD);
10123 59644 : if (!builtin_decl_explicit_p (BUILT_IN_OBSERVABLE_CHKPT))
10124 59644 : local_define_builtin ("__builtin_observable_checkpoint", ftype,
10125 : BUILT_IN_OBSERVABLE_CHKPT,
10126 : "__builtin_observable_checkpoint",
10127 : ECF_NOTHROW | ECF_LEAF | ECF_CONST
10128 : | ECF_LOOPING_CONST_OR_PURE);
10129 : }
10130 :
10131 292051 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY)
10132 292051 : || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10133 : {
10134 59644 : ftype = build_function_type_list (ptr_type_node,
10135 : ptr_type_node, const_ptr_type_node,
10136 : size_type_node, NULL_TREE);
10137 :
10138 59644 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY))
10139 59644 : local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
10140 : "memcpy", ECF_NOTHROW | ECF_LEAF);
10141 59644 : if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10142 54998 : local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
10143 : "memmove", ECF_NOTHROW | ECF_LEAF);
10144 : }
10145 :
10146 292051 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP))
10147 : {
10148 54998 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10149 : const_ptr_type_node, size_type_node,
10150 : NULL_TREE);
10151 54998 : local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
10152 : "memcmp", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10153 : }
10154 :
10155 292051 : if (!builtin_decl_explicit_p (BUILT_IN_MEMSET))
10156 : {
10157 54998 : ftype = build_function_type_list (ptr_type_node,
10158 : ptr_type_node, integer_type_node,
10159 : size_type_node, NULL_TREE);
10160 54998 : local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
10161 : "memset", ECF_NOTHROW | ECF_LEAF);
10162 : }
10163 :
10164 : /* If we're checking the stack, `alloca' can throw. */
10165 291983 : const int alloca_flags
10166 292051 : = ECF_MALLOC | ECF_LEAF | (flag_stack_check ? 0 : ECF_NOTHROW);
10167 :
10168 292051 : if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA))
10169 : {
10170 59644 : ftype = build_function_type_list (ptr_type_node,
10171 : size_type_node, NULL_TREE);
10172 59644 : local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
10173 : "alloca", alloca_flags);
10174 : }
10175 :
10176 292051 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10177 : size_type_node, NULL_TREE);
10178 292051 : local_define_builtin ("__builtin_alloca_with_align", ftype,
10179 : BUILT_IN_ALLOCA_WITH_ALIGN,
10180 : "__builtin_alloca_with_align",
10181 : alloca_flags);
10182 :
10183 292051 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10184 : size_type_node, size_type_node, NULL_TREE);
10185 292051 : local_define_builtin ("__builtin_alloca_with_align_and_max", ftype,
10186 : BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX,
10187 : "__builtin_alloca_with_align_and_max",
10188 : alloca_flags);
10189 :
10190 292051 : ftype = build_function_type_list (void_type_node,
10191 : ptr_type_node, ptr_type_node,
10192 : ptr_type_node, NULL_TREE);
10193 292051 : local_define_builtin ("__builtin_init_trampoline", ftype,
10194 : BUILT_IN_INIT_TRAMPOLINE,
10195 : "__builtin_init_trampoline", ECF_NOTHROW | ECF_LEAF);
10196 292051 : local_define_builtin ("__builtin_init_heap_trampoline", ftype,
10197 : BUILT_IN_INIT_HEAP_TRAMPOLINE,
10198 : "__builtin_init_heap_trampoline",
10199 : ECF_NOTHROW | ECF_LEAF);
10200 292051 : local_define_builtin ("__builtin_init_descriptor", ftype,
10201 : BUILT_IN_INIT_DESCRIPTOR,
10202 : "__builtin_init_descriptor", ECF_NOTHROW | ECF_LEAF);
10203 :
10204 292051 : ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
10205 292051 : local_define_builtin ("__builtin_adjust_trampoline", ftype,
10206 : BUILT_IN_ADJUST_TRAMPOLINE,
10207 : "__builtin_adjust_trampoline",
10208 : ECF_CONST | ECF_NOTHROW);
10209 292051 : local_define_builtin ("__builtin_adjust_descriptor", ftype,
10210 : BUILT_IN_ADJUST_DESCRIPTOR,
10211 : "__builtin_adjust_descriptor",
10212 : ECF_CONST | ECF_NOTHROW);
10213 :
10214 292051 : ftype = build_function_type_list (void_type_node,
10215 : ptr_type_node, ptr_type_node, NULL_TREE);
10216 292051 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_CACHE))
10217 59644 : local_define_builtin ("__builtin___clear_cache", ftype,
10218 : BUILT_IN_CLEAR_CACHE,
10219 : "__clear_cache",
10220 : ECF_NOTHROW);
10221 :
10222 292051 : local_define_builtin ("__builtin_nonlocal_goto", ftype,
10223 : BUILT_IN_NONLOCAL_GOTO,
10224 : "__builtin_nonlocal_goto",
10225 : ECF_NORETURN | ECF_NOTHROW);
10226 :
10227 292051 : tree ptr_ptr_type_node = build_pointer_type (ptr_type_node);
10228 :
10229 292051 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_CREATED))
10230 : {
10231 59644 : ftype = build_function_type_list (void_type_node,
10232 : ptr_type_node, // void *chain
10233 : ptr_type_node, // void *func
10234 : ptr_ptr_type_node, // void **dst
10235 : NULL_TREE);
10236 59644 : local_define_builtin ("__builtin___gcc_nested_func_ptr_created", ftype,
10237 : BUILT_IN_GCC_NESTED_PTR_CREATED,
10238 : "__gcc_nested_func_ptr_created", ECF_NOTHROW);
10239 : }
10240 :
10241 292051 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_DELETED))
10242 : {
10243 59644 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10244 59644 : local_define_builtin ("__builtin___gcc_nested_func_ptr_deleted", ftype,
10245 : BUILT_IN_GCC_NESTED_PTR_DELETED,
10246 : "__gcc_nested_func_ptr_deleted", ECF_NOTHROW);
10247 : }
10248 :
10249 292051 : ftype = build_function_type_list (void_type_node,
10250 : ptr_type_node, ptr_type_node, NULL_TREE);
10251 292051 : local_define_builtin ("__builtin_setjmp_setup", ftype,
10252 : BUILT_IN_SETJMP_SETUP,
10253 : "__builtin_setjmp_setup", ECF_NOTHROW);
10254 :
10255 292051 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10256 292051 : local_define_builtin ("__builtin_setjmp_receiver", ftype,
10257 : BUILT_IN_SETJMP_RECEIVER,
10258 : "__builtin_setjmp_receiver", ECF_NOTHROW | ECF_LEAF);
10259 :
10260 292051 : ftype = build_function_type_list (ptr_type_node, NULL_TREE);
10261 292051 : local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
10262 : "__builtin_stack_save", ECF_NOTHROW | ECF_LEAF);
10263 :
10264 292051 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10265 292051 : local_define_builtin ("__builtin_stack_restore", ftype,
10266 : BUILT_IN_STACK_RESTORE,
10267 : "__builtin_stack_restore", ECF_NOTHROW | ECF_LEAF);
10268 :
10269 292051 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10270 : const_ptr_type_node, size_type_node,
10271 : NULL_TREE);
10272 292051 : local_define_builtin ("__builtin_memcmp_eq", ftype, BUILT_IN_MEMCMP_EQ,
10273 : "__builtin_memcmp_eq",
10274 : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10275 :
10276 292051 : local_define_builtin ("__builtin_strncmp_eq", ftype, BUILT_IN_STRNCMP_EQ,
10277 : "__builtin_strncmp_eq",
10278 : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10279 :
10280 292051 : local_define_builtin ("__builtin_strcmp_eq", ftype, BUILT_IN_STRCMP_EQ,
10281 : "__builtin_strcmp_eq",
10282 : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10283 :
10284 : /* If there's a possibility that we might use the ARM EABI, build the
10285 : alternate __cxa_end_cleanup node used to resume from C++. */
10286 292051 : if (targetm.arm_eabi_unwinder)
10287 : {
10288 0 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10289 0 : local_define_builtin ("__builtin_cxa_end_cleanup", ftype,
10290 : BUILT_IN_CXA_END_CLEANUP,
10291 : "__cxa_end_cleanup",
10292 : ECF_NORETURN | ECF_XTHROW | ECF_LEAF);
10293 : }
10294 :
10295 292051 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10296 584102 : local_define_builtin ("__builtin_unwind_resume", ftype,
10297 : BUILT_IN_UNWIND_RESUME,
10298 292051 : ((targetm_common.except_unwind_info (&global_options)
10299 : == UI_SJLJ)
10300 : ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
10301 : ECF_NORETURN | ECF_XTHROW);
10302 :
10303 292051 : if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS) == NULL_TREE)
10304 : {
10305 54998 : ftype = build_function_type_list (ptr_type_node, integer_type_node,
10306 : NULL_TREE);
10307 54998 : local_define_builtin ("__builtin_return_address", ftype,
10308 : BUILT_IN_RETURN_ADDRESS,
10309 : "__builtin_return_address",
10310 : ECF_NOTHROW);
10311 : }
10312 :
10313 292051 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER)
10314 292051 : || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10315 : {
10316 59644 : ftype = build_function_type_list (void_type_node, ptr_type_node,
10317 : ptr_type_node, NULL_TREE);
10318 59644 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER))
10319 59644 : local_define_builtin ("__cyg_profile_func_enter", ftype,
10320 : BUILT_IN_PROFILE_FUNC_ENTER,
10321 : "__cyg_profile_func_enter", 0);
10322 59644 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10323 59644 : local_define_builtin ("__cyg_profile_func_exit", ftype,
10324 : BUILT_IN_PROFILE_FUNC_EXIT,
10325 : "__cyg_profile_func_exit", 0);
10326 : }
10327 :
10328 : /* The exception object and filter values from the runtime. The argument
10329 : must be zero before exception lowering, i.e. from the front end. After
10330 : exception lowering, it will be the region number for the exception
10331 : landing pad. These functions are PURE instead of CONST to prevent
10332 : them from being hoisted past the exception edge that will initialize
10333 : its value in the landing pad. */
10334 292051 : ftype = build_function_type_list (ptr_type_node,
10335 : integer_type_node, NULL_TREE);
10336 292051 : ecf_flags = ECF_PURE | ECF_NOTHROW | ECF_LEAF;
10337 : /* Only use TM_PURE if we have TM language support. */
10338 292051 : if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1))
10339 471 : ecf_flags |= ECF_TM_PURE;
10340 292051 : local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER,
10341 : "__builtin_eh_pointer", ecf_flags);
10342 :
10343 292051 : tmp = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0);
10344 292051 : ftype = build_function_type_list (tmp, integer_type_node, NULL_TREE);
10345 292051 : local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER,
10346 : "__builtin_eh_filter", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10347 :
10348 292051 : ftype = build_function_type_list (void_type_node,
10349 : integer_type_node, integer_type_node,
10350 : NULL_TREE);
10351 292051 : local_define_builtin ("__builtin_eh_copy_values", ftype,
10352 : BUILT_IN_EH_COPY_VALUES,
10353 : "__builtin_eh_copy_values", ECF_NOTHROW);
10354 :
10355 : /* Complex multiplication and division. These are handled as builtins
10356 : rather than optabs because emit_library_call_value doesn't support
10357 : complex. Further, we can do slightly better with folding these
10358 : beasties if the real and complex parts of the arguments are separate. */
10359 292051 : {
10360 292051 : int mode;
10361 :
10362 2044357 : for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
10363 : {
10364 1752306 : char mode_name_buf[4], *q;
10365 1752306 : const char *p;
10366 1752306 : enum built_in_function mcode, dcode;
10367 1752306 : tree type, inner_type;
10368 1752306 : const char *prefix = "__";
10369 :
10370 1752306 : if (targetm.libfunc_gnu_prefix)
10371 0 : prefix = "__gnu_";
10372 :
10373 1752306 : type = lang_hooks.types.type_for_mode ((machine_mode) mode, 0);
10374 1752306 : if (type == NULL)
10375 130209 : continue;
10376 1622097 : inner_type = TREE_TYPE (type);
10377 :
10378 1622097 : ftype = build_function_type_list (type, inner_type, inner_type,
10379 : inner_type, inner_type, NULL_TREE);
10380 :
10381 1622097 : mcode = ((enum built_in_function)
10382 1622097 : (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10383 1622097 : dcode = ((enum built_in_function)
10384 1622097 : (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10385 :
10386 4866291 : for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
10387 3244194 : *q = TOLOWER (*p);
10388 1622097 : *q = '\0';
10389 :
10390 : /* For -ftrapping-math these should throw from a former
10391 : -fnon-call-exception stmt. */
10392 1622097 : built_in_names[mcode] = concat (prefix, "mul", mode_name_buf, "3",
10393 : NULL);
10394 1622097 : local_define_builtin (built_in_names[mcode], ftype, mcode,
10395 : built_in_names[mcode],
10396 : ECF_CONST | ECF_LEAF);
10397 :
10398 1622097 : built_in_names[dcode] = concat (prefix, "div", mode_name_buf, "3",
10399 : NULL);
10400 1622097 : local_define_builtin (built_in_names[dcode], ftype, dcode,
10401 : built_in_names[dcode],
10402 : ECF_CONST | ECF_LEAF);
10403 : }
10404 : }
10405 :
10406 292051 : init_internal_fns ();
10407 292051 : }
10408 :
10409 : /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10410 : better way.
10411 :
10412 : If we requested a pointer to a vector, build up the pointers that
10413 : we stripped off while looking for the inner type. Similarly for
10414 : return values from functions.
10415 :
10416 : The argument TYPE is the top of the chain, and BOTTOM is the
10417 : new type which we will point to. */
10418 :
10419 : tree
10420 0 : reconstruct_complex_type (tree type, tree bottom)
10421 : {
10422 0 : tree inner, outer;
10423 :
10424 0 : if (TREE_CODE (type) == POINTER_TYPE)
10425 : {
10426 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10427 0 : outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
10428 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10429 : }
10430 : else if (TREE_CODE (type) == REFERENCE_TYPE)
10431 : {
10432 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10433 0 : outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
10434 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10435 : }
10436 : else if (TREE_CODE (type) == ARRAY_TYPE)
10437 : {
10438 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10439 0 : outer = build_array_type (inner, TYPE_DOMAIN (type));
10440 : }
10441 : else if (TREE_CODE (type) == FUNCTION_TYPE)
10442 : {
10443 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10444 0 : outer = build_function_type (inner, TYPE_ARG_TYPES (type),
10445 0 : TYPE_NO_NAMED_ARGS_STDARG_P (type));
10446 : }
10447 : else if (TREE_CODE (type) == METHOD_TYPE)
10448 : {
10449 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10450 : /* The build_method_type_directly() routine prepends 'this' to argument list,
10451 : so we must compensate by getting rid of it. */
10452 0 : outer
10453 : = build_method_type_directly
10454 0 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
10455 : inner,
10456 0 : TREE_CHAIN (TYPE_ARG_TYPES (type)));
10457 : }
10458 : else if (TREE_CODE (type) == OFFSET_TYPE)
10459 : {
10460 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10461 0 : outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
10462 : }
10463 : else
10464 : return bottom;
10465 :
10466 0 : return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
10467 0 : TYPE_QUALS (type));
10468 : }
10469 :
10470 : /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10471 : the inner type. */
10472 : tree
10473 34575782 : build_vector_type_for_mode (tree innertype, machine_mode mode)
10474 : {
10475 34575782 : poly_int64 nunits;
10476 34575782 : unsigned int bitsize;
10477 :
10478 34575782 : switch (GET_MODE_CLASS (mode))
10479 : {
10480 34574462 : case MODE_VECTOR_BOOL:
10481 34574462 : case MODE_VECTOR_INT:
10482 34574462 : case MODE_VECTOR_FLOAT:
10483 34574462 : case MODE_VECTOR_FRACT:
10484 34574462 : case MODE_VECTOR_UFRACT:
10485 34574462 : case MODE_VECTOR_ACCUM:
10486 34574462 : case MODE_VECTOR_UACCUM:
10487 69148924 : nunits = GET_MODE_NUNITS (mode);
10488 34574462 : break;
10489 :
10490 1320 : case MODE_INT:
10491 : /* Check that there are no leftover bits. */
10492 1320 : bitsize = GET_MODE_BITSIZE (as_a <scalar_int_mode> (mode));
10493 1320 : gcc_assert (bitsize % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
10494 1320 : nunits = bitsize / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
10495 1320 : break;
10496 :
10497 0 : default:
10498 0 : gcc_unreachable ();
10499 : }
10500 :
10501 34575782 : return make_vector_type (innertype, nunits, mode);
10502 : }
10503 :
10504 : /* Similarly, but takes the inner type and number of units, which must be
10505 : a power of two. */
10506 :
10507 : tree
10508 2917932 : build_vector_type (tree innertype, poly_int64 nunits)
10509 : {
10510 2917932 : return make_vector_type (innertype, nunits, VOIDmode);
10511 : }
10512 :
10513 : /* Build a truth vector with NUNITS units, giving it mode MASK_MODE. */
10514 :
10515 : tree
10516 2757576 : build_truth_vector_type_for_mode (poly_uint64 nunits, machine_mode mask_mode)
10517 : {
10518 2757576 : gcc_assert (mask_mode != BLKmode);
10519 :
10520 2757576 : unsigned HOST_WIDE_INT esize;
10521 2757576 : if (VECTOR_MODE_P (mask_mode))
10522 : {
10523 2619723 : poly_uint64 vsize = GET_MODE_PRECISION (mask_mode);
10524 2619723 : esize = vector_element_size (vsize, nunits);
10525 2619723 : }
10526 : else
10527 : esize = 1;
10528 :
10529 2757576 : tree bool_type = build_nonstandard_boolean_type (esize);
10530 :
10531 2757576 : return make_vector_type (bool_type, nunits, mask_mode);
10532 : }
10533 :
10534 : /* Build a vector type that holds one boolean result for each element of
10535 : vector type VECTYPE. The public interface for this operation is
10536 : truth_type_for. */
10537 :
10538 : static tree
10539 2746514 : build_truth_vector_type_for (tree vectype)
10540 : {
10541 2746514 : machine_mode vector_mode = TYPE_MODE (vectype);
10542 2746514 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
10543 :
10544 2746514 : machine_mode mask_mode;
10545 102883 : if (VECTOR_MODE_P (vector_mode)
10546 2848777 : && targetm.vectorize.get_mask_mode (vector_mode).exists (&mask_mode))
10547 2745894 : return build_truth_vector_type_for_mode (nunits, mask_mode);
10548 :
10549 620 : poly_uint64 vsize = tree_to_poly_uint64 (TYPE_SIZE (vectype));
10550 620 : unsigned HOST_WIDE_INT esize = vector_element_size (vsize, nunits);
10551 620 : tree bool_type = build_nonstandard_boolean_type (esize);
10552 :
10553 620 : return make_vector_type (bool_type, nunits, VOIDmode);
10554 : }
10555 :
10556 : /* Like build_vector_type, but builds a variant type with TYPE_VECTOR_OPAQUE
10557 : set. */
10558 :
10559 : tree
10560 109857 : build_opaque_vector_type (tree innertype, poly_int64 nunits)
10561 : {
10562 109857 : tree t = make_vector_type (innertype, nunits, VOIDmode);
10563 109857 : tree cand;
10564 : /* We always build the non-opaque variant before the opaque one,
10565 : so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10566 109857 : cand = TYPE_NEXT_VARIANT (t);
10567 109857 : if (cand
10568 98191 : && TYPE_VECTOR_OPAQUE (cand)
10569 173386 : && check_qualified_type (cand, t, TYPE_QUALS (t)))
10570 : return cand;
10571 : /* Otherwise build a variant type and make sure to queue it after
10572 : the non-opaque type. */
10573 46329 : cand = build_distinct_type_copy (t);
10574 46329 : TYPE_VECTOR_OPAQUE (cand) = true;
10575 46329 : TYPE_CANONICAL (cand) = TYPE_CANONICAL (t);
10576 46329 : TYPE_NEXT_VARIANT (cand) = TYPE_NEXT_VARIANT (t);
10577 46329 : TYPE_NEXT_VARIANT (t) = cand;
10578 46329 : TYPE_MAIN_VARIANT (cand) = TYPE_MAIN_VARIANT (t);
10579 : /* Type variants have no alias set defined. */
10580 46329 : TYPE_ALIAS_SET (cand) = -1;
10581 46329 : return cand;
10582 : }
10583 :
10584 : /* Return the value of element I of VECTOR_CST T as a wide_int. */
10585 :
10586 : static poly_wide_int
10587 542680 : vector_cst_int_elt (const_tree t, unsigned int i)
10588 : {
10589 : /* First handle elements that are directly encoded. */
10590 542680 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10591 542680 : if (i < encoded_nelts)
10592 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, i));
10593 :
10594 : /* Identify the pattern that contains element I and work out the index of
10595 : the last encoded element for that pattern. */
10596 542680 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10597 542680 : unsigned int pattern = i % npatterns;
10598 542680 : unsigned int count = i / npatterns;
10599 542680 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10600 :
10601 : /* If there are no steps, the final encoded value is the right one. */
10602 542680 : if (!VECTOR_CST_STEPPED_P (t))
10603 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, final_i));
10604 :
10605 : /* Otherwise work out the value from the last two encoded elements. */
10606 542680 : tree v1 = VECTOR_CST_ENCODED_ELT (t, final_i - npatterns);
10607 542680 : tree v2 = VECTOR_CST_ENCODED_ELT (t, final_i);
10608 542680 : poly_wide_int diff = wi::to_poly_wide (v2) - wi::to_poly_wide (v1);
10609 542680 : return wi::to_poly_wide (v2) + (count - 2) * diff;
10610 542680 : }
10611 :
10612 : /* Return the value of element I of VECTOR_CST T. */
10613 :
10614 : tree
10615 8149407 : vector_cst_elt (const_tree t, unsigned int i)
10616 : {
10617 : /* First handle elements that are directly encoded. */
10618 8149407 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10619 8149407 : if (i < encoded_nelts)
10620 5237715 : return VECTOR_CST_ENCODED_ELT (t, i);
10621 :
10622 : /* If there are no steps, the final encoded value is the right one. */
10623 2911692 : if (!VECTOR_CST_STEPPED_P (t))
10624 : {
10625 : /* Identify the pattern that contains element I and work out the index of
10626 : the last encoded element for that pattern. */
10627 2369012 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10628 2369012 : unsigned int pattern = i % npatterns;
10629 2369012 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10630 2369012 : return VECTOR_CST_ENCODED_ELT (t, final_i);
10631 : }
10632 :
10633 : /* Otherwise work out the value from the last two encoded elements. */
10634 542680 : return wide_int_to_tree (TREE_TYPE (TREE_TYPE (t)),
10635 1085360 : vector_cst_int_elt (t, i));
10636 : }
10637 :
10638 : /* Given an initializer INIT, return TRUE if INIT is zero or some
10639 : aggregate of zeros. Otherwise return FALSE. If NONZERO is not
10640 : null, set *NONZERO if and only if INIT is known not to be all
10641 : zeros. The combination of return value of false and *NONZERO
10642 : false implies that INIT may but need not be all zeros. Other
10643 : combinations indicate definitive answers. */
10644 :
10645 : bool
10646 44651874 : initializer_zerop (const_tree init, bool *nonzero /* = NULL */)
10647 : {
10648 44651874 : bool dummy;
10649 44651874 : if (!nonzero)
10650 41877190 : nonzero = &dummy;
10651 :
10652 : /* Conservatively clear NONZERO and set it only if INIT is definitely
10653 : not all zero. */
10654 44651874 : *nonzero = false;
10655 :
10656 44651874 : STRIP_NOPS (init);
10657 :
10658 44651874 : unsigned HOST_WIDE_INT off = 0;
10659 :
10660 44651874 : switch (TREE_CODE (init))
10661 : {
10662 17201135 : case INTEGER_CST:
10663 17201135 : if (integer_zerop (init))
10664 : return true;
10665 :
10666 10902648 : *nonzero = true;
10667 10902648 : return false;
10668 :
10669 571601 : case REAL_CST:
10670 : /* ??? Note that this is not correct for C4X float formats. There,
10671 : a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10672 : negative exponent. */
10673 571601 : if (real_zerop (init)
10674 667560 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init)))
10675 : return true;
10676 :
10677 478818 : *nonzero = true;
10678 478818 : return false;
10679 :
10680 0 : case FIXED_CST:
10681 0 : if (fixed_zerop (init))
10682 : return true;
10683 :
10684 0 : *nonzero = true;
10685 0 : return false;
10686 :
10687 18300 : case COMPLEX_CST:
10688 18300 : if (integer_zerop (init)
10689 18300 : || (real_zerop (init)
10690 3249 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
10691 3169 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init)))))
10692 3347 : return true;
10693 :
10694 14953 : *nonzero = true;
10695 14953 : return false;
10696 :
10697 1174214 : case VECTOR_CST:
10698 1174214 : if (VECTOR_CST_NPATTERNS (init) == 1
10699 1079546 : && VECTOR_CST_DUPLICATE_P (init)
10700 1850110 : && initializer_zerop (VECTOR_CST_ENCODED_ELT (init, 0)))
10701 : return true;
10702 :
10703 818807 : *nonzero = true;
10704 818807 : return false;
10705 :
10706 : case RAW_DATA_CST:
10707 1969 : for (unsigned int i = 0; i < (unsigned int) RAW_DATA_LENGTH (init); ++i)
10708 1969 : if (RAW_DATA_POINTER (init)[i])
10709 : {
10710 1919 : *nonzero = true;
10711 1919 : return false;
10712 : }
10713 : return true;
10714 :
10715 4334795 : case CONSTRUCTOR:
10716 4334795 : {
10717 4334795 : if (TREE_CLOBBER_P (init))
10718 : return false;
10719 :
10720 : unsigned HOST_WIDE_INT idx;
10721 : tree elt;
10722 :
10723 3647979 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
10724 2774684 : if (!initializer_zerop (elt, nonzero))
10725 : return false;
10726 :
10727 : return true;
10728 : }
10729 :
10730 369775 : case MEM_REF:
10731 369775 : {
10732 369775 : tree arg = TREE_OPERAND (init, 0);
10733 369775 : if (TREE_CODE (arg) != ADDR_EXPR)
10734 : return false;
10735 92283 : tree offset = TREE_OPERAND (init, 1);
10736 92283 : if (TREE_CODE (offset) != INTEGER_CST
10737 92283 : || !tree_fits_uhwi_p (offset))
10738 : return false;
10739 92283 : off = tree_to_uhwi (offset);
10740 92283 : if (INT_MAX < off)
10741 : return false;
10742 92279 : arg = TREE_OPERAND (arg, 0);
10743 92279 : if (TREE_CODE (arg) != STRING_CST)
10744 : return false;
10745 : init = arg;
10746 : }
10747 : /* Fall through. */
10748 :
10749 : case STRING_CST:
10750 : {
10751 : gcc_assert (off <= INT_MAX);
10752 :
10753 155368 : int i = off;
10754 155368 : int n = TREE_STRING_LENGTH (init);
10755 155368 : if (n <= i)
10756 : return false;
10757 :
10758 : /* We need to loop through all elements to handle cases like
10759 : "\0" and "\0foobar". */
10760 167495 : for (i = 0; i < n; ++i)
10761 161998 : if (TREE_STRING_POINTER (init)[i] != '\0')
10762 : {
10763 149838 : *nonzero = true;
10764 149838 : return false;
10765 : }
10766 :
10767 : return true;
10768 : }
10769 :
10770 : default:
10771 : return false;
10772 : }
10773 : }
10774 :
10775 : /* Return true if EXPR is an initializer expression in which every element
10776 : is a constant that is numerically equal to 0 or 1. The elements do not
10777 : need to be equal to each other. */
10778 :
10779 : bool
10780 130637 : initializer_each_zero_or_onep (const_tree expr)
10781 : {
10782 130637 : STRIP_ANY_LOCATION_WRAPPER (expr);
10783 :
10784 130637 : switch (TREE_CODE (expr))
10785 : {
10786 46550 : case INTEGER_CST:
10787 46550 : return integer_zerop (expr) || integer_onep (expr);
10788 :
10789 24408 : case REAL_CST:
10790 24408 : return real_zerop (expr) || real_onep (expr);
10791 :
10792 59679 : case VECTOR_CST:
10793 59679 : {
10794 59679 : unsigned HOST_WIDE_INT nelts = vector_cst_encoded_nelts (expr);
10795 59679 : if (VECTOR_CST_STEPPED_P (expr)
10796 59679 : && !TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)).is_constant (&nelts))
10797 : return false;
10798 :
10799 73310 : for (unsigned int i = 0; i < nelts; ++i)
10800 : {
10801 70958 : tree elt = vector_cst_elt (expr, i);
10802 70958 : if (!initializer_each_zero_or_onep (elt))
10803 : return false;
10804 : }
10805 :
10806 : return true;
10807 : }
10808 :
10809 : default:
10810 : return false;
10811 : }
10812 : }
10813 :
10814 : /* Check if vector VEC consists of all the equal elements and
10815 : that the number of elements corresponds to the type of VEC.
10816 : The function returns first element of the vector
10817 : or NULL_TREE if the vector is not uniform. */
10818 : tree
10819 3277569 : uniform_vector_p (const_tree vec)
10820 : {
10821 3277569 : tree first, t;
10822 3277569 : unsigned HOST_WIDE_INT i, nelts;
10823 :
10824 3277569 : if (vec == NULL_TREE)
10825 : return NULL_TREE;
10826 :
10827 3277569 : gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec)));
10828 :
10829 3277569 : if (TREE_CODE (vec) == VEC_DUPLICATE_EXPR)
10830 0 : return TREE_OPERAND (vec, 0);
10831 :
10832 3277569 : else if (TREE_CODE (vec) == VECTOR_CST)
10833 : {
10834 401683 : if (VECTOR_CST_NPATTERNS (vec) == 1 && VECTOR_CST_DUPLICATE_P (vec))
10835 335877 : return VECTOR_CST_ENCODED_ELT (vec, 0);
10836 : return NULL_TREE;
10837 : }
10838 :
10839 2875886 : else if (TREE_CODE (vec) == CONSTRUCTOR
10840 2875886 : && TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec)).is_constant (&nelts))
10841 : {
10842 176182 : first = error_mark_node;
10843 :
10844 578695 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t)
10845 : {
10846 516132 : if (i == 0)
10847 : {
10848 176182 : first = t;
10849 176182 : continue;
10850 : }
10851 339950 : if (!operand_equal_p (first, t, 0))
10852 : return NULL_TREE;
10853 : }
10854 62563 : if (i != nelts)
10855 : return NULL_TREE;
10856 :
10857 62268 : if (TREE_CODE (first) == CONSTRUCTOR || TREE_CODE (first) == VECTOR_CST)
10858 : return uniform_vector_p (first);
10859 : return first;
10860 : }
10861 :
10862 : return NULL_TREE;
10863 : }
10864 :
10865 : /* If OP is a uniform vector return the element it is a splat from. */
10866 :
10867 : tree
10868 284975 : ssa_uniform_vector_p (tree op)
10869 : {
10870 284975 : if (TREE_CODE (op) == VECTOR_CST
10871 : || TREE_CODE (op) == VEC_DUPLICATE_EXPR
10872 : || TREE_CODE (op) == CONSTRUCTOR)
10873 11887 : return uniform_vector_p (op);
10874 : if (TREE_CODE (op) == SSA_NAME)
10875 : {
10876 273088 : gimple *def_stmt = SSA_NAME_DEF_STMT (op);
10877 273088 : if (gimple_assign_single_p (def_stmt))
10878 115733 : return uniform_vector_p (gimple_assign_rhs1 (def_stmt));
10879 : }
10880 : return NULL_TREE;
10881 : }
10882 :
10883 : /* If the argument is INTEGER_CST, return it. If the argument is vector
10884 : with all elements the same INTEGER_CST, return that INTEGER_CST. Otherwise
10885 : return NULL_TREE.
10886 : Look through location wrappers. */
10887 :
10888 : tree
10889 888882461 : uniform_integer_cst_p (tree t)
10890 : {
10891 888882461 : STRIP_ANY_LOCATION_WRAPPER (t);
10892 :
10893 888882461 : if (TREE_CODE (t) == INTEGER_CST)
10894 : return t;
10895 :
10896 357985412 : if (VECTOR_TYPE_P (TREE_TYPE (t)))
10897 : {
10898 1396130 : t = uniform_vector_p (t);
10899 1396130 : if (t && TREE_CODE (t) == INTEGER_CST)
10900 : return t;
10901 : }
10902 :
10903 : return NULL_TREE;
10904 : }
10905 :
10906 : /* Checks to see if T is a constant or a constant vector and if each element E
10907 : adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE. */
10908 :
10909 : tree
10910 2906292 : bitmask_inv_cst_vector_p (tree t)
10911 : {
10912 :
10913 2906292 : tree_code code = TREE_CODE (t);
10914 2906292 : tree type = TREE_TYPE (t);
10915 :
10916 2906292 : if (!INTEGRAL_TYPE_P (type)
10917 2906292 : && !VECTOR_INTEGER_TYPE_P (type))
10918 : return NULL_TREE;
10919 :
10920 2906292 : unsigned HOST_WIDE_INT nelts = 1;
10921 2906292 : tree cst;
10922 2906292 : unsigned int idx = 0;
10923 2906292 : bool uniform = uniform_integer_cst_p (t);
10924 2906292 : tree newtype = unsigned_type_for (type);
10925 2906292 : tree_vector_builder builder;
10926 2906292 : if (code == INTEGER_CST)
10927 : cst = t;
10928 : else
10929 : {
10930 17579 : if (!VECTOR_CST_NELTS (t).is_constant (&nelts))
10931 : return NULL_TREE;
10932 :
10933 17579 : cst = vector_cst_elt (t, 0);
10934 17579 : builder.new_vector (newtype, nelts, 1);
10935 : }
10936 :
10937 2906292 : tree ty = unsigned_type_for (TREE_TYPE (cst));
10938 :
10939 2906304 : do
10940 : {
10941 2906304 : if (idx > 0)
10942 12 : cst = vector_cst_elt (t, idx);
10943 2906304 : wide_int icst = wi::to_wide (cst);
10944 2906304 : wide_int inv = wi::bit_not (icst);
10945 2906304 : icst = wi::add (1, inv);
10946 2906304 : if (wi::popcount (icst) != 1)
10947 : return NULL_TREE;
10948 :
10949 8097 : tree newcst = wide_int_to_tree (ty, inv);
10950 :
10951 8097 : if (uniform)
10952 8081 : return build_uniform_cst (newtype, newcst);
10953 :
10954 16 : builder.quick_push (newcst);
10955 2906304 : }
10956 16 : while (++idx < nelts);
10957 :
10958 4 : return builder.build ();
10959 2906292 : }
10960 :
10961 : /* If VECTOR_CST T has a single nonzero element, return the index of that
10962 : element, otherwise return -1. */
10963 :
10964 : int
10965 180 : single_nonzero_element (const_tree t)
10966 : {
10967 180 : unsigned HOST_WIDE_INT nelts;
10968 180 : unsigned int repeat_nelts;
10969 180 : if (VECTOR_CST_NELTS (t).is_constant (&nelts))
10970 180 : repeat_nelts = nelts;
10971 : else if (VECTOR_CST_NELTS_PER_PATTERN (t) == 2)
10972 : {
10973 : nelts = vector_cst_encoded_nelts (t);
10974 : repeat_nelts = VECTOR_CST_NPATTERNS (t);
10975 : }
10976 : else
10977 : return -1;
10978 :
10979 180 : int res = -1;
10980 567 : for (unsigned int i = 0; i < nelts; ++i)
10981 : {
10982 531 : tree elt = vector_cst_elt (t, i);
10983 531 : if (!integer_zerop (elt) && !real_zerop (elt))
10984 : {
10985 324 : if (res >= 0 || i >= repeat_nelts)
10986 : return -1;
10987 180 : res = i;
10988 : }
10989 : }
10990 : return res;
10991 : }
10992 :
10993 : /* Build an empty statement at location LOC. */
10994 :
10995 : tree
10996 15945592 : build_empty_stmt (location_t loc)
10997 : {
10998 15945592 : tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
10999 15945592 : SET_EXPR_LOCATION (t, loc);
11000 15945592 : return t;
11001 : }
11002 :
11003 :
11004 : /* Build an OMP clause with code CODE. LOC is the location of the
11005 : clause. */
11006 :
11007 : tree
11008 1756530 : build_omp_clause (location_t loc, enum omp_clause_code code)
11009 : {
11010 1756530 : tree t;
11011 1756530 : int size, length;
11012 :
11013 1756530 : length = omp_clause_num_ops[code];
11014 1756530 : size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
11015 :
11016 1756530 : record_node_allocation_statistics (OMP_CLAUSE, size);
11017 :
11018 1756530 : t = (tree) ggc_internal_alloc (size);
11019 1756530 : memset (t, 0, size);
11020 1756530 : TREE_SET_CODE (t, OMP_CLAUSE);
11021 1756530 : OMP_CLAUSE_SET_CODE (t, code);
11022 1756530 : OMP_CLAUSE_LOCATION (t) = loc;
11023 :
11024 1756530 : return t;
11025 : }
11026 :
11027 : /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
11028 : includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
11029 : Except for the CODE and operand count field, other storage for the
11030 : object is initialized to zeros. */
11031 :
11032 : tree
11033 545733755 : build_vl_exp (enum tree_code code, int len MEM_STAT_DECL)
11034 : {
11035 545733755 : tree t;
11036 545733755 : int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
11037 :
11038 545733755 : gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp);
11039 545733755 : gcc_assert (len >= 1);
11040 :
11041 545733755 : record_node_allocation_statistics (code, length);
11042 :
11043 545733755 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
11044 :
11045 545733755 : TREE_SET_CODE (t, code);
11046 :
11047 : /* Can't use TREE_OPERAND to store the length because if checking is
11048 : enabled, it will try to check the length before we store it. :-P */
11049 545733755 : t->exp.operands[0] = build_int_cst (sizetype, len);
11050 :
11051 545733755 : return t;
11052 : }
11053 :
11054 : /* Helper function for build_call_* functions; build a CALL_EXPR with
11055 : indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
11056 : the argument slots. */
11057 :
11058 : static tree
11059 292153357 : build_call_1 (tree return_type, tree fn, int nargs)
11060 : {
11061 292153357 : tree t;
11062 :
11063 292153357 : t = build_vl_exp (CALL_EXPR, nargs + 3);
11064 292153357 : TREE_TYPE (t) = return_type;
11065 292153357 : CALL_EXPR_FN (t) = fn;
11066 292153357 : CALL_EXPR_STATIC_CHAIN (t) = NULL;
11067 :
11068 292153357 : return t;
11069 : }
11070 :
11071 : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11072 : FN and a null static chain slot. NARGS is the number of call arguments
11073 : which are specified as a va_list ARGS. */
11074 :
11075 : tree
11076 135900 : build_call_valist (tree return_type, tree fn, int nargs, va_list args)
11077 : {
11078 135900 : tree t;
11079 135900 : int i;
11080 :
11081 135900 : t = build_call_1 (return_type, fn, nargs);
11082 551187 : for (i = 0; i < nargs; i++)
11083 279387 : CALL_EXPR_ARG (t, i) = va_arg (args, tree);
11084 135900 : process_call_operands (t);
11085 135900 : return t;
11086 : }
11087 :
11088 : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11089 : FN and a null static chain slot. ARGS specifies the call arguments. */
11090 :
11091 : tree
11092 266 : build_call (tree return_type, tree fn, std::initializer_list<tree> args)
11093 : {
11094 266 : tree t;
11095 266 : int i;
11096 266 : int nargs = args.size();
11097 :
11098 266 : t = build_call_1 (return_type, fn, nargs);
11099 1024 : for (i = 0; i < nargs; i++)
11100 492 : CALL_EXPR_ARG (t, i) = args.begin()[i];
11101 266 : process_call_operands (t);
11102 266 : return t;
11103 : }
11104 :
11105 : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11106 : FN and a null static chain slot. NARGS is the number of call arguments
11107 : which are specified as a tree array ARGS. */
11108 :
11109 : tree
11110 243627006 : build_call_array_loc (location_t loc, tree return_type, tree fn,
11111 : int nargs, const tree *args)
11112 : {
11113 243627006 : tree t;
11114 243627006 : int i;
11115 :
11116 243627006 : t = build_call_1 (return_type, fn, nargs);
11117 814440500 : for (i = 0; i < nargs; i++)
11118 327186488 : CALL_EXPR_ARG (t, i) = args[i];
11119 243627006 : process_call_operands (t);
11120 243627006 : SET_EXPR_LOCATION (t, loc);
11121 243627006 : return t;
11122 : }
11123 :
11124 : /* Like build_call_array, but takes a vec. */
11125 :
11126 : tree
11127 47580961 : build_call_vec (tree return_type, tree fn, const vec<tree, va_gc> *args)
11128 : {
11129 47580961 : tree ret, t;
11130 47580961 : unsigned int ix;
11131 :
11132 47580961 : ret = build_call_1 (return_type, fn, vec_safe_length (args));
11133 131173039 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
11134 36011117 : CALL_EXPR_ARG (ret, ix) = t;
11135 47580961 : process_call_operands (ret);
11136 47580961 : return ret;
11137 : }
11138 :
11139 : /* Conveniently construct a function call expression. FNDECL names the
11140 : function to be called and N arguments are passed in the array
11141 : ARGARRAY. */
11142 :
11143 : tree
11144 23599849 : build_call_expr_loc_array (location_t loc, tree fndecl, int n, tree *argarray)
11145 : {
11146 23599849 : tree fntype = TREE_TYPE (fndecl);
11147 23599849 : tree fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fndecl);
11148 :
11149 23599849 : return fold_build_call_array_loc (loc, TREE_TYPE (fntype), fn, n, argarray);
11150 : }
11151 :
11152 : /* Conveniently construct a function call expression. FNDECL names the
11153 : function to be called and the arguments are passed in the vector
11154 : VEC. */
11155 :
11156 : tree
11157 20734 : build_call_expr_loc_vec (location_t loc, tree fndecl, vec<tree, va_gc> *vec)
11158 : {
11159 20734 : return build_call_expr_loc_array (loc, fndecl, vec_safe_length (vec),
11160 20734 : vec_safe_address (vec));
11161 : }
11162 :
11163 :
11164 : /* Conveniently construct a function call expression. FNDECL names the
11165 : function to be called, N is the number of arguments, and the "..."
11166 : parameters are the argument expressions. */
11167 :
11168 : tree
11169 21935894 : build_call_expr_loc (location_t loc, tree fndecl, int n, ...)
11170 : {
11171 21935894 : va_list ap;
11172 21935894 : tree *argarray = XALLOCAVEC (tree, n);
11173 21935894 : int i;
11174 :
11175 21935894 : va_start (ap, n);
11176 24812352 : for (i = 0; i < n; i++)
11177 2876458 : argarray[i] = va_arg (ap, tree);
11178 21935894 : va_end (ap);
11179 21935894 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11180 : }
11181 :
11182 : /* Like build_call_expr_loc (UNKNOWN_LOCATION, ...). Duplicated because
11183 : varargs macros aren't supported by all bootstrap compilers. */
11184 :
11185 : tree
11186 1638733 : build_call_expr (tree fndecl, int n, ...)
11187 : {
11188 1638733 : va_list ap;
11189 1638733 : tree *argarray = XALLOCAVEC (tree, n);
11190 1638733 : int i;
11191 :
11192 1638733 : va_start (ap, n);
11193 4910409 : for (i = 0; i < n; i++)
11194 3271676 : argarray[i] = va_arg (ap, tree);
11195 1638733 : va_end (ap);
11196 1638733 : return build_call_expr_loc_array (UNKNOWN_LOCATION, fndecl, n, argarray);
11197 : }
11198 :
11199 : /* Build an internal call to IFN, with arguments ARGS[0:N-1] and with return
11200 : type TYPE. This is just like CALL_EXPR, except its CALL_EXPR_FN is NULL.
11201 : It will get gimplified later into an ordinary internal function. */
11202 :
11203 : tree
11204 809224 : build_call_expr_internal_loc_array (location_t loc, internal_fn ifn,
11205 : tree type, int n, const tree *args)
11206 : {
11207 809224 : tree t = build_call_1 (type, NULL_TREE, n);
11208 2557370 : for (int i = 0; i < n; ++i)
11209 1748146 : CALL_EXPR_ARG (t, i) = args[i];
11210 809224 : SET_EXPR_LOCATION (t, loc);
11211 809224 : CALL_EXPR_IFN (t) = ifn;
11212 809224 : process_call_operands (t);
11213 809224 : return t;
11214 : }
11215 :
11216 : /* Build internal call expression. This is just like CALL_EXPR, except
11217 : its CALL_EXPR_FN is NULL. It will get gimplified later into ordinary
11218 : internal function. */
11219 :
11220 : tree
11221 808094 : build_call_expr_internal_loc (location_t loc, enum internal_fn ifn,
11222 : tree type, int n, ...)
11223 : {
11224 808094 : va_list ap;
11225 808094 : tree *argarray = XALLOCAVEC (tree, n);
11226 808094 : int i;
11227 :
11228 808094 : va_start (ap, n);
11229 2553968 : for (i = 0; i < n; i++)
11230 1745874 : argarray[i] = va_arg (ap, tree);
11231 808094 : va_end (ap);
11232 808094 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11233 : }
11234 :
11235 : /* Return a function call to FN, if the target is guaranteed to support it,
11236 : or null otherwise.
11237 :
11238 : N is the number of arguments, passed in the "...", and TYPE is the
11239 : type of the return value. */
11240 :
11241 : tree
11242 1924 : maybe_build_call_expr_loc (location_t loc, combined_fn fn, tree type,
11243 : int n, ...)
11244 : {
11245 1924 : va_list ap;
11246 1924 : tree *argarray = XALLOCAVEC (tree, n);
11247 1924 : int i;
11248 :
11249 1924 : va_start (ap, n);
11250 5035 : for (i = 0; i < n; i++)
11251 3111 : argarray[i] = va_arg (ap, tree);
11252 1924 : va_end (ap);
11253 1924 : if (internal_fn_p (fn))
11254 : {
11255 1118 : internal_fn ifn = as_internal_fn (fn);
11256 1118 : if (direct_internal_fn_p (ifn))
11257 : {
11258 1 : tree_pair types = direct_internal_fn_types (ifn, type, argarray);
11259 1 : if (!direct_internal_fn_supported_p (ifn, types,
11260 : OPTIMIZE_FOR_BOTH))
11261 1 : return NULL_TREE;
11262 : }
11263 1117 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11264 : }
11265 : else
11266 : {
11267 806 : tree fndecl = builtin_decl_implicit (as_builtin_fn (fn));
11268 806 : if (!fndecl)
11269 : return NULL_TREE;
11270 698 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11271 : }
11272 : }
11273 :
11274 : /* Return a function call to the appropriate builtin alloca variant.
11275 :
11276 : SIZE is the size to be allocated. ALIGN, if non-zero, is the requested
11277 : alignment of the allocated area. MAX_SIZE, if non-negative, is an upper
11278 : bound for SIZE in case it is not a fixed value. */
11279 :
11280 : tree
11281 8963 : build_alloca_call_expr (tree size, unsigned int align, HOST_WIDE_INT max_size)
11282 : {
11283 8963 : if (max_size >= 0)
11284 : {
11285 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX);
11286 0 : return
11287 0 : build_call_expr (t, 3, size, size_int (align), size_int (max_size));
11288 : }
11289 8963 : else if (align > 0)
11290 : {
11291 8963 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
11292 8963 : return build_call_expr (t, 2, size, size_int (align));
11293 : }
11294 : else
11295 : {
11296 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA);
11297 0 : return build_call_expr (t, 1, size);
11298 : }
11299 : }
11300 :
11301 : /* The built-in decl to use to mark code points believed to be unreachable.
11302 : Typically __builtin_unreachable, but __builtin_trap if
11303 : -fsanitize=unreachable -fsanitize-trap=unreachable. If only
11304 : -fsanitize=unreachable, we rely on sanopt to replace calls with the
11305 : appropriate ubsan function. When building a call directly, use
11306 : {gimple_},build_builtin_unreachable instead. */
11307 :
11308 : tree
11309 350388 : builtin_decl_unreachable ()
11310 : {
11311 350388 : enum built_in_function fncode = BUILT_IN_UNREACHABLE;
11312 :
11313 700776 : if (sanitize_flags_p (SANITIZE_UNREACHABLE)
11314 350388 : ? (flag_sanitize_trap & SANITIZE_UNREACHABLE)
11315 349792 : : flag_unreachable_traps)
11316 22 : fncode = BUILT_IN_UNREACHABLE_TRAP;
11317 : /* For non-trapping sanitize, we will rewrite __builtin_unreachable () later,
11318 : in the sanopt pass. */
11319 :
11320 350388 : return builtin_decl_explicit (fncode);
11321 : }
11322 :
11323 : /* Build a call to __builtin_unreachable, possibly rewritten by
11324 : -fsanitize=unreachable. Use this rather than the above when practical. */
11325 :
11326 : tree
11327 20440637 : build_builtin_unreachable (location_t loc)
11328 : {
11329 20440637 : tree data = NULL_TREE;
11330 20440637 : tree fn = sanitize_unreachable_fn (&data, loc);
11331 20440637 : return build_call_expr_loc (loc, fn, data != NULL_TREE, data);
11332 : }
11333 :
11334 : /* Create a new constant string literal of type ELTYPE[SIZE] (or LEN
11335 : if SIZE == -1) and return a tree node representing char* pointer to
11336 : it as an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)). When STR is nonnull
11337 : the STRING_CST value is the LEN bytes at STR (the representation
11338 : of the string, which may be wide). Otherwise it's all zeros. */
11339 :
11340 : tree
11341 265064 : build_string_literal (unsigned len, const char *str /* = NULL */,
11342 : tree eltype /* = char_type_node */,
11343 : unsigned HOST_WIDE_INT size /* = -1 */)
11344 : {
11345 265064 : tree t = build_string (len, str);
11346 : /* Set the maximum valid index based on the string length or SIZE. */
11347 530128 : unsigned HOST_WIDE_INT maxidx
11348 265064 : = (size == HOST_WIDE_INT_M1U ? len : size) - 1;
11349 :
11350 265064 : tree index = build_index_type (size_int (maxidx));
11351 265064 : eltype = build_type_variant (eltype, 1, 0);
11352 265064 : tree type = build_array_type (eltype, index);
11353 265064 : TREE_TYPE (t) = type;
11354 265064 : TREE_CONSTANT (t) = 1;
11355 265064 : TREE_READONLY (t) = 1;
11356 265064 : TREE_STATIC (t) = 1;
11357 :
11358 265064 : type = build_pointer_type (eltype);
11359 265064 : t = build1 (ADDR_EXPR, type,
11360 : build4 (ARRAY_REF, eltype,
11361 : t, integer_zero_node, NULL_TREE, NULL_TREE));
11362 265064 : return t;
11363 : }
11364 :
11365 :
11366 :
11367 : /* Return true if T (assumed to be a DECL) must be assigned a memory
11368 : location. */
11369 :
11370 : bool
11371 2010298926 : needs_to_live_in_memory (const_tree t)
11372 : {
11373 2010298926 : return (TREE_ADDRESSABLE (t)
11374 1632480798 : || is_global_var (t)
11375 3191465411 : || (TREE_CODE (t) == RESULT_DECL
11376 8351708 : && !DECL_BY_REFERENCE (t)
11377 5831010 : && aggregate_value_p (t, current_function_decl)));
11378 : }
11379 :
11380 : /* Return value of a constant X and sign-extend it. */
11381 :
11382 : HOST_WIDE_INT
11383 771446997 : int_cst_value (const_tree x)
11384 : {
11385 771446997 : unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
11386 771446997 : unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
11387 :
11388 : /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
11389 771446997 : gcc_assert (cst_and_fits_in_hwi (x));
11390 :
11391 771446997 : if (bits < HOST_BITS_PER_WIDE_INT)
11392 : {
11393 756624374 : bool negative = ((val >> (bits - 1)) & 1) != 0;
11394 756624374 : if (negative)
11395 221709 : val |= HOST_WIDE_INT_M1U << (bits - 1) << 1;
11396 : else
11397 756402665 : val &= ~(HOST_WIDE_INT_M1U << (bits - 1) << 1);
11398 : }
11399 :
11400 771446997 : return val;
11401 : }
11402 :
11403 : /* If TYPE is an integral or pointer type, return an integer type with
11404 : the same precision which is unsigned iff UNSIGNEDP is true, or itself
11405 : if TYPE is already an integer type of signedness UNSIGNEDP.
11406 : If TYPE is a floating-point type, return an integer type with the same
11407 : bitsize and with the signedness given by UNSIGNEDP; this is useful
11408 : when doing bit-level operations on a floating-point value. */
11409 :
11410 : tree
11411 87806505 : signed_or_unsigned_type_for (int unsignedp, tree type)
11412 : {
11413 87806505 : if (ANY_INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) == unsignedp)
11414 : return type;
11415 :
11416 56948091 : if (TREE_CODE (type) == VECTOR_TYPE)
11417 : {
11418 28177 : tree inner = TREE_TYPE (type);
11419 28177 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11420 28177 : if (!inner2)
11421 : return NULL_TREE;
11422 28177 : if (inner == inner2)
11423 : return type;
11424 28177 : machine_mode new_mode;
11425 56354 : if (VECTOR_MODE_P (TYPE_MODE (type))
11426 56270 : && related_int_vector_mode (TYPE_MODE (type)).exists (&new_mode))
11427 28093 : return build_vector_type_for_mode (inner2, new_mode);
11428 84 : return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type));
11429 : }
11430 :
11431 : if (TREE_CODE (type) == COMPLEX_TYPE)
11432 : {
11433 24 : tree inner = TREE_TYPE (type);
11434 24 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11435 24 : if (!inner2)
11436 : return NULL_TREE;
11437 24 : if (inner == inner2)
11438 : return type;
11439 24 : return build_complex_type (inner2);
11440 : }
11441 :
11442 : unsigned int bits;
11443 : if (INTEGRAL_TYPE_P (type)
11444 : || POINTER_TYPE_P (type)
11445 : || TREE_CODE (type) == OFFSET_TYPE)
11446 56919796 : bits = TYPE_PRECISION (type);
11447 : else if (TREE_CODE (type) == REAL_TYPE)
11448 188 : bits = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (type));
11449 : else
11450 : return NULL_TREE;
11451 :
11452 56919890 : if (TREE_CODE (type) == BITINT_TYPE)
11453 1862 : return build_bitint_type (bits, unsignedp);
11454 56918028 : return build_nonstandard_integer_type (bits, unsignedp);
11455 : }
11456 :
11457 : /* If TYPE is an integral or pointer type, return an integer type with
11458 : the same precision which is unsigned, or itself if TYPE is already an
11459 : unsigned integer type. If TYPE is a floating-point type, return an
11460 : unsigned integer type with the same bitsize as TYPE. */
11461 :
11462 : tree
11463 78202337 : unsigned_type_for (tree type)
11464 : {
11465 78202337 : return signed_or_unsigned_type_for (1, type);
11466 : }
11467 :
11468 : /* If TYPE is an integral or pointer type, return an integer type with
11469 : the same precision which is signed, or itself if TYPE is already a
11470 : signed integer type. If TYPE is a floating-point type, return a
11471 : signed integer type with the same bitsize as TYPE. */
11472 :
11473 : tree
11474 9570616 : signed_type_for (tree type)
11475 : {
11476 9570616 : return signed_or_unsigned_type_for (0, type);
11477 : }
11478 :
11479 : /* - For VECTOR_TYPEs:
11480 : - The truth type must be a VECTOR_BOOLEAN_TYPE.
11481 : - The number of elements must match (known_eq).
11482 : - targetm.vectorize.get_mask_mode exists, and exactly
11483 : the same mode as the truth type.
11484 : - Otherwise, the truth type must be a BOOLEAN_TYPE
11485 : or useless_type_conversion_p to BOOLEAN_TYPE. */
11486 : bool
11487 1422 : is_truth_type_for (tree type, tree truth_type)
11488 : {
11489 1422 : machine_mode mask_mode = TYPE_MODE (truth_type);
11490 1422 : machine_mode vmode = TYPE_MODE (type);
11491 1422 : machine_mode tmask_mode;
11492 :
11493 1422 : if (TREE_CODE (type) == VECTOR_TYPE)
11494 : {
11495 1422 : if (VECTOR_BOOLEAN_TYPE_P (truth_type)
11496 1422 : && known_eq (TYPE_VECTOR_SUBPARTS (type),
11497 : TYPE_VECTOR_SUBPARTS (truth_type))
11498 1422 : && targetm.vectorize.get_mask_mode (vmode).exists (&tmask_mode)
11499 2844 : && tmask_mode == mask_mode)
11500 1403 : return true;
11501 :
11502 19 : return false;
11503 : }
11504 :
11505 0 : return useless_type_conversion_p (boolean_type_node, truth_type);
11506 : }
11507 :
11508 : /* If TYPE is a vector type, return a signed integer vector type with the
11509 : same width and number of subparts. Otherwise return boolean_type_node. */
11510 :
11511 : tree
11512 5252897 : truth_type_for (tree type)
11513 : {
11514 5252897 : if (TREE_CODE (type) == VECTOR_TYPE)
11515 : {
11516 2838231 : if (VECTOR_BOOLEAN_TYPE_P (type))
11517 : return type;
11518 2746514 : return build_truth_vector_type_for (type);
11519 : }
11520 : else
11521 2414666 : return boolean_type_node;
11522 : }
11523 :
11524 : /* Returns the largest value obtainable by casting something in INNER type to
11525 : OUTER type. */
11526 :
11527 : tree
11528 10823255 : upper_bound_in_type (tree outer, tree inner)
11529 : {
11530 10823255 : unsigned int det = 0;
11531 10823255 : unsigned oprec = TYPE_PRECISION (outer);
11532 10823255 : unsigned iprec = TYPE_PRECISION (inner);
11533 10823255 : unsigned prec;
11534 :
11535 : /* Compute a unique number for every combination. */
11536 10823255 : det |= (oprec > iprec) ? 4 : 0;
11537 10823255 : det |= TYPE_UNSIGNED (outer) ? 2 : 0;
11538 10823255 : det |= TYPE_UNSIGNED (inner) ? 1 : 0;
11539 :
11540 : /* Determine the exponent to use. */
11541 10823255 : switch (det)
11542 : {
11543 7317756 : case 0:
11544 7317756 : case 1:
11545 : /* oprec <= iprec, outer: signed, inner: don't care. */
11546 7317756 : prec = oprec - 1;
11547 7317756 : break;
11548 : case 2:
11549 : case 3:
11550 : /* oprec <= iprec, outer: unsigned, inner: don't care. */
11551 : prec = oprec;
11552 : break;
11553 23176 : case 4:
11554 : /* oprec > iprec, outer: signed, inner: signed. */
11555 23176 : prec = iprec - 1;
11556 23176 : break;
11557 : case 5:
11558 : /* oprec > iprec, outer: signed, inner: unsigned. */
11559 9756 : prec = iprec;
11560 : break;
11561 : case 6:
11562 : /* oprec > iprec, outer: unsigned, inner: signed. */
11563 : prec = oprec;
11564 : break;
11565 : case 7:
11566 : /* oprec > iprec, outer: unsigned, inner: unsigned. */
11567 9756 : prec = iprec;
11568 : break;
11569 : default:
11570 : gcc_unreachable ();
11571 : }
11572 :
11573 10823255 : return wide_int_to_tree (outer,
11574 10823255 : wi::mask (prec, false, TYPE_PRECISION (outer)));
11575 : }
11576 :
11577 : /* Returns the smallest value obtainable by casting something in INNER type to
11578 : OUTER type. */
11579 :
11580 : tree
11581 8404411 : lower_bound_in_type (tree outer, tree inner)
11582 : {
11583 8404411 : unsigned oprec = TYPE_PRECISION (outer);
11584 8404411 : unsigned iprec = TYPE_PRECISION (inner);
11585 :
11586 : /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
11587 : and obtain 0. */
11588 8404411 : if (TYPE_UNSIGNED (outer)
11589 : /* If we are widening something of an unsigned type, OUTER type
11590 : contains all values of INNER type. In particular, both INNER
11591 : and OUTER types have zero in common. */
11592 8404411 : || (oprec > iprec && TYPE_UNSIGNED (inner)))
11593 2223187 : return build_int_cst (outer, 0);
11594 : else
11595 : {
11596 : /* If we are widening a signed type to another signed type, we
11597 : want to obtain -2^^(iprec-1). If we are keeping the
11598 : precision or narrowing to a signed type, we want to obtain
11599 : -2^(oprec-1). */
11600 6181224 : unsigned prec = oprec > iprec ? iprec : oprec;
11601 6181224 : return wide_int_to_tree (outer,
11602 12362448 : wi::mask (prec - 1, true,
11603 6181224 : TYPE_PRECISION (outer)));
11604 : }
11605 : }
11606 :
11607 : /* Return true if two operands that are suitable for PHI nodes are
11608 : necessarily equal. Specifically, both ARG0 and ARG1 must be either
11609 : SSA_NAME or invariant. Note that this is strictly an optimization.
11610 : That is, callers of this function can directly call operand_equal_p
11611 : and get the same result, only slower. */
11612 :
11613 : bool
11614 21843116 : operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1)
11615 : {
11616 21843116 : if (arg0 == arg1)
11617 : return true;
11618 20154344 : if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
11619 : return false;
11620 4294845 : return operand_equal_p (arg0, arg1, 0);
11621 : }
11622 :
11623 : /* Returns number of zeros at the end of binary representation of X. */
11624 :
11625 : tree
11626 9232652 : num_ending_zeros (const_tree x)
11627 : {
11628 9232652 : return build_int_cst (TREE_TYPE (x), wi::ctz (wi::to_wide (x)));
11629 : }
11630 :
11631 :
11632 : #define WALK_SUBTREE(NODE) \
11633 : do \
11634 : { \
11635 : result = walk_tree_1 (&(NODE), func, data, pset, lh); \
11636 : if (result) \
11637 : return result; \
11638 : } \
11639 : while (0)
11640 :
11641 : /* This is a subroutine of walk_tree that walks field of TYPE that are to
11642 : be walked whenever a type is seen in the tree. Rest of operands and return
11643 : value are as for walk_tree. */
11644 :
11645 : static tree
11646 5218700611 : walk_type_fields (tree type, walk_tree_fn func, void *data,
11647 : hash_set<tree> *pset, walk_tree_lh lh)
11648 : {
11649 5218700611 : tree result = NULL_TREE;
11650 :
11651 5218700611 : switch (TREE_CODE (type))
11652 : {
11653 1518240910 : case POINTER_TYPE:
11654 1518240910 : case REFERENCE_TYPE:
11655 1518240910 : case VECTOR_TYPE:
11656 : /* We have to worry about mutually recursive pointers. These can't
11657 : be written in C. They can in Ada. It's pathological, but
11658 : there's an ACATS test (c38102a) that checks it. Deal with this
11659 : by checking if we're pointing to another pointer, that one
11660 : points to another pointer, that one does too, and we have no htab.
11661 : If so, get a hash table. We check three levels deep to avoid
11662 : the cost of the hash table if we don't need one. */
11663 2986546971 : if (POINTER_TYPE_P (TREE_TYPE (type))
11664 49934916 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
11665 7326793 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
11666 1525469192 : && !pset)
11667 : {
11668 0 : result = walk_tree_without_duplicates (&TREE_TYPE (type),
11669 : func, data);
11670 0 : if (result)
11671 : return result;
11672 :
11673 : break;
11674 : }
11675 :
11676 : /* fall through */
11677 :
11678 1521191386 : case COMPLEX_TYPE:
11679 1521191386 : WALK_SUBTREE (TREE_TYPE (type));
11680 : break;
11681 :
11682 265887955 : case METHOD_TYPE:
11683 265887955 : WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
11684 :
11685 : /* Fall through. */
11686 :
11687 434120934 : case FUNCTION_TYPE:
11688 434120934 : WALK_SUBTREE (TREE_TYPE (type));
11689 434120892 : {
11690 434120892 : tree arg;
11691 :
11692 : /* We never want to walk into default arguments. */
11693 1664397629 : for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
11694 1230305381 : WALK_SUBTREE (TREE_VALUE (arg));
11695 : }
11696 : break;
11697 :
11698 16992233 : case ARRAY_TYPE:
11699 : /* Don't follow this nodes's type if a pointer for fear that
11700 : we'll have infinite recursion. If we have a PSET, then we
11701 : need not fear. */
11702 16992233 : if (pset
11703 16992233 : || (!POINTER_TYPE_P (TREE_TYPE (type))
11704 162613 : && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
11705 16971445 : WALK_SUBTREE (TREE_TYPE (type));
11706 16989610 : WALK_SUBTREE (TYPE_DOMAIN (type));
11707 : break;
11708 :
11709 1132274 : case OFFSET_TYPE:
11710 1132274 : WALK_SUBTREE (TREE_TYPE (type));
11711 1131410 : WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
11712 : break;
11713 :
11714 : default:
11715 : break;
11716 : }
11717 :
11718 : return NULL_TREE;
11719 : }
11720 :
11721 : /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
11722 : called with the DATA and the address of each sub-tree. If FUNC returns a
11723 : non-NULL value, the traversal is stopped, and the value returned by FUNC
11724 : is returned. If PSET is non-NULL it is used to record the nodes visited,
11725 : and to avoid visiting a node more than once. */
11726 :
11727 : tree
11728 >10998*10^7 : walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
11729 : hash_set<tree> *pset, walk_tree_lh lh)
11730 : {
11731 : #define WALK_SUBTREE_TAIL(NODE) \
11732 : do \
11733 : { \
11734 : tp = & (NODE); \
11735 : goto tail_recurse; \
11736 : } \
11737 : while (0)
11738 :
11739 >13580*10^7 : tail_recurse:
11740 : /* Skip empty subtrees. */
11741 >13580*10^7 : if (!*tp)
11742 : return NULL_TREE;
11743 :
11744 : /* Don't walk the same tree twice, if the user has requested
11745 : that we avoid doing so. */
11746 >11227*10^7 : if (pset && pset->add (*tp))
11747 : return NULL_TREE;
11748 :
11749 : /* Call the function. */
11750 >11051*10^7 : int walk_subtrees = 1;
11751 >11051*10^7 : tree result = (*func) (tp, &walk_subtrees, data);
11752 :
11753 : /* If we found something, return it. */
11754 >11051*10^7 : if (result)
11755 : return result;
11756 :
11757 >11043*10^7 : tree t = *tp;
11758 >11043*10^7 : tree_code code = TREE_CODE (t);
11759 :
11760 : /* Even if we didn't, FUNC may have decided that there was nothing
11761 : interesting below this point in the tree. */
11762 >11043*10^7 : if (!walk_subtrees)
11763 : {
11764 : /* But we still need to check our siblings. */
11765 67574478051 : if (code == TREE_LIST)
11766 107234 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11767 67574370817 : else if (code == OMP_CLAUSE)
11768 886315 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11769 : else
11770 : return NULL_TREE;
11771 : }
11772 :
11773 42863374595 : if (lh)
11774 : {
11775 25289974740 : result = (*lh) (tp, &walk_subtrees, func, data, pset);
11776 25289974740 : if (result || !walk_subtrees)
11777 2924261263 : return result;
11778 : }
11779 :
11780 39939113332 : switch (code)
11781 : {
11782 : case ERROR_MARK:
11783 : case IDENTIFIER_NODE:
11784 : case INTEGER_CST:
11785 : case REAL_CST:
11786 : case FIXED_CST:
11787 : case STRING_CST:
11788 : case BLOCK:
11789 : case PLACEHOLDER_EXPR:
11790 : case SSA_NAME:
11791 : case FIELD_DECL:
11792 : case RESULT_DECL:
11793 : /* None of these have subtrees other than those already walked
11794 : above. */
11795 : break;
11796 :
11797 283188877 : case TREE_LIST:
11798 283188877 : WALK_SUBTREE (TREE_VALUE (t));
11799 282700346 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11800 :
11801 1338747770 : case TREE_VEC:
11802 1338747770 : {
11803 1338747770 : int len = TREE_VEC_LENGTH (t);
11804 :
11805 1338747770 : if (len == 0)
11806 : break;
11807 :
11808 : /* Walk all elements but the last. */
11809 2458927280 : for (int i = 0; i < len - 1; ++i)
11810 1129902102 : WALK_SUBTREE (TREE_VEC_ELT (t, i));
11811 :
11812 : /* Now walk the last one as a tail call. */
11813 1329025178 : WALK_SUBTREE_TAIL (TREE_VEC_ELT (t, len - 1));
11814 : }
11815 :
11816 5560055 : case VECTOR_CST:
11817 5560055 : {
11818 5560055 : unsigned len = vector_cst_encoded_nelts (t);
11819 5560055 : if (len == 0)
11820 : break;
11821 : /* Walk all elements but the last. */
11822 18352827 : for (unsigned i = 0; i < len - 1; ++i)
11823 12792916 : WALK_SUBTREE (VECTOR_CST_ENCODED_ELT (t, i));
11824 : /* Now walk the last one as a tail call. */
11825 5559911 : WALK_SUBTREE_TAIL (VECTOR_CST_ENCODED_ELT (t, len - 1));
11826 : }
11827 :
11828 640990 : case COMPLEX_CST:
11829 640990 : WALK_SUBTREE (TREE_REALPART (t));
11830 639424 : WALK_SUBTREE_TAIL (TREE_IMAGPART (t));
11831 :
11832 : case CONSTRUCTOR:
11833 : {
11834 : unsigned HOST_WIDE_INT idx;
11835 : constructor_elt *ce;
11836 :
11837 954294967 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce);
11838 : idx++)
11839 490630333 : WALK_SUBTREE (ce->value);
11840 : }
11841 : break;
11842 :
11843 4805566 : case SAVE_EXPR:
11844 4805566 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, 0));
11845 :
11846 268881791 : case BIND_EXPR:
11847 268881791 : {
11848 268881791 : tree decl;
11849 434663029 : for (decl = BIND_EXPR_VARS (t); decl; decl = DECL_CHAIN (decl))
11850 : {
11851 : /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
11852 : into declarations that are just mentioned, rather than
11853 : declared; they don't really belong to this part of the tree.
11854 : And, we can see cycles: the initializer for a declaration
11855 : can refer to the declaration itself. */
11856 165781262 : WALK_SUBTREE (DECL_INITIAL (decl));
11857 165781238 : WALK_SUBTREE (DECL_SIZE (decl));
11858 165781238 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
11859 : }
11860 268881767 : WALK_SUBTREE_TAIL (BIND_EXPR_BODY (t));
11861 : }
11862 :
11863 363582816 : case STATEMENT_LIST:
11864 363582816 : {
11865 363582816 : tree_stmt_iterator i;
11866 1304282088 : for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
11867 940891332 : WALK_SUBTREE (*tsi_stmt_ptr (i));
11868 : }
11869 363390756 : break;
11870 :
11871 1834527 : case OMP_CLAUSE:
11872 1834527 : {
11873 1834527 : int len = omp_clause_num_ops[OMP_CLAUSE_CODE (t)];
11874 : /* Do not walk the iterator operand of OpenMP MAP clauses. */
11875 1834527 : if (OMP_CLAUSE_HAS_ITERATORS (t))
11876 1578 : len--;
11877 5224917 : for (int i = 0; i < len; i++)
11878 3390390 : WALK_SUBTREE (OMP_CLAUSE_OPERAND (t, i));
11879 1834527 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11880 : }
11881 :
11882 82947322 : case TARGET_EXPR:
11883 82947322 : {
11884 82947322 : int i, len;
11885 :
11886 : /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
11887 : But, we only want to walk once. */
11888 82947322 : len = (TREE_OPERAND (t, 3) == TREE_OPERAND (t, 1)) ? 2 : 3;
11889 331754615 : for (i = 0; i < len; ++i)
11890 248824579 : WALK_SUBTREE (TREE_OPERAND (t, i));
11891 82930036 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len));
11892 : }
11893 :
11894 161857898 : case DECL_EXPR:
11895 : /* If this is a TYPE_DECL, walk into the fields of the type that it's
11896 : defining. We only want to walk into these fields of a type in this
11897 : case and not in the general case of a mere reference to the type.
11898 :
11899 : The criterion is as follows: if the field can be an expression, it
11900 : must be walked only here. This should be in keeping with the fields
11901 : that are directly gimplified in gimplify_type_sizes in order for the
11902 : mark/copy-if-shared/unmark machinery of the gimplifier to work with
11903 : variable-sized types.
11904 :
11905 : Note that DECLs get walked as part of processing the BIND_EXPR. */
11906 161857898 : if (TREE_CODE (DECL_EXPR_DECL (t)) == TYPE_DECL)
11907 : {
11908 : /* Call the function for the decl so e.g. copy_tree_body_r can
11909 : replace it with the remapped one. */
11910 1674120 : result = (*func) (&DECL_EXPR_DECL (t), &walk_subtrees, data);
11911 1674120 : if (result || !walk_subtrees)
11912 45325 : return result;
11913 :
11914 1628795 : tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (t));
11915 1628795 : if (TREE_CODE (*type_p) == ERROR_MARK)
11916 : return NULL_TREE;
11917 :
11918 : /* Call the function for the type. See if it returns anything or
11919 : doesn't want us to continue. If we are to continue, walk both
11920 : the normal fields and those for the declaration case. */
11921 1628795 : result = (*func) (type_p, &walk_subtrees, data);
11922 1628795 : if (result || !walk_subtrees)
11923 93998 : return result;
11924 :
11925 1534797 : tree type = *type_p;
11926 :
11927 : /* But do not walk a pointed-to type since it may itself need to
11928 : be walked in the declaration case if it isn't anonymous. */
11929 1534797 : if (!POINTER_TYPE_P (type))
11930 : {
11931 1519091 : result = walk_type_fields (type, func, data, pset, lh);
11932 1519091 : if (result)
11933 : return result;
11934 : }
11935 :
11936 : /* If this is a record type, also walk the fields. */
11937 1534797 : if (RECORD_OR_UNION_TYPE_P (type))
11938 : {
11939 459651 : tree field;
11940 :
11941 2124114 : for (field = TYPE_FIELDS (type); field;
11942 1664463 : field = DECL_CHAIN (field))
11943 : {
11944 : /* We'd like to look at the type of the field, but we can
11945 : easily get infinite recursion. So assume it's pointed
11946 : to elsewhere in the tree. Also, ignore things that
11947 : aren't fields. */
11948 1664463 : if (TREE_CODE (field) != FIELD_DECL)
11949 1267437 : continue;
11950 :
11951 397026 : WALK_SUBTREE (DECL_FIELD_OFFSET (field));
11952 397026 : WALK_SUBTREE (DECL_SIZE (field));
11953 397026 : WALK_SUBTREE (DECL_SIZE_UNIT (field));
11954 397026 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
11955 0 : WALK_SUBTREE (DECL_QUALIFIER (field));
11956 : }
11957 : }
11958 :
11959 : /* Same for scalar types. */
11960 1075146 : else if (TREE_CODE (type) == BOOLEAN_TYPE
11961 : || TREE_CODE (type) == ENUMERAL_TYPE
11962 1075146 : || TREE_CODE (type) == INTEGER_TYPE
11963 1074728 : || TREE_CODE (type) == FIXED_POINT_TYPE
11964 1074728 : || TREE_CODE (type) == REAL_TYPE)
11965 : {
11966 419 : WALK_SUBTREE (TYPE_MIN_VALUE (type));
11967 419 : WALK_SUBTREE (TYPE_MAX_VALUE (type));
11968 : }
11969 :
11970 1534797 : WALK_SUBTREE (TYPE_SIZE (type));
11971 1534797 : WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (type));
11972 : }
11973 : /* FALLTHRU */
11974 :
11975 32515093392 : default:
11976 32515093392 : if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
11977 : {
11978 24114303714 : int i, len;
11979 :
11980 : /* Walk over all the sub-trees of this operand. */
11981 24114303714 : len = TREE_OPERAND_LENGTH (t);
11982 :
11983 : /* Go through the subtrees. We need to do this in forward order so
11984 : that the scope of a FOR_EXPR is handled properly. */
11985 24114303714 : if (len)
11986 : {
11987 48307905579 : for (i = 0; i < len - 1; ++i)
11988 24465100117 : WALK_SUBTREE (TREE_OPERAND (t, i));
11989 23842805462 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len - 1));
11990 : }
11991 : }
11992 : /* If this is a type, walk the needed fields in the type. */
11993 8400789678 : else if (TYPE_P (t))
11994 5217181520 : return walk_type_fields (t, func, data, pset, lh);
11995 : break;
11996 : }
11997 :
11998 : /* We didn't find what we were looking for. */
11999 : return NULL_TREE;
12000 :
12001 : #undef WALK_SUBTREE_TAIL
12002 : }
12003 : #undef WALK_SUBTREE
12004 :
12005 : /* Like walk_tree, but does not walk duplicate nodes more than once. */
12006 :
12007 : tree
12008 3883759877 : walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data,
12009 : walk_tree_lh lh)
12010 : {
12011 3883759877 : tree result;
12012 :
12013 3883759877 : hash_set<tree> pset;
12014 3883759877 : result = walk_tree_1 (tp, func, data, &pset, lh);
12015 3883759877 : return result;
12016 3883759877 : }
12017 :
12018 :
12019 : tree
12020 1190162462 : tree_block (tree t)
12021 : {
12022 1190162462 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
12023 :
12024 1190162462 : if (IS_EXPR_CODE_CLASS (c))
12025 1190162462 : return LOCATION_BLOCK (t->exp.locus);
12026 0 : gcc_unreachable ();
12027 : return NULL;
12028 : }
12029 :
12030 : void
12031 748630862 : tree_set_block (tree t, tree b)
12032 : {
12033 748630862 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
12034 :
12035 748630862 : if (IS_EXPR_CODE_CLASS (c))
12036 : {
12037 748630862 : t->exp.locus = set_block (t->exp.locus, b);
12038 : }
12039 : else
12040 0 : gcc_unreachable ();
12041 748630862 : }
12042 :
12043 : /* Create a nameless artificial label and put it in the current
12044 : function context. The label has a location of LOC. Returns the
12045 : newly created label. */
12046 :
12047 : tree
12048 32857084 : create_artificial_label (location_t loc)
12049 : {
12050 32857084 : tree lab = build_decl (loc,
12051 : LABEL_DECL, NULL_TREE, void_type_node);
12052 :
12053 32857084 : DECL_ARTIFICIAL (lab) = 1;
12054 32857084 : DECL_IGNORED_P (lab) = 1;
12055 32857084 : DECL_CONTEXT (lab) = current_function_decl;
12056 32857084 : return lab;
12057 : }
12058 :
12059 : /* Given a tree, try to return a useful variable name that we can use
12060 : to prefix a temporary that is being assigned the value of the tree.
12061 : I.E. given <temp> = &A, return A. */
12062 :
12063 : const char *
12064 25312647 : get_name (tree t)
12065 : {
12066 27208826 : tree stripped_decl;
12067 :
12068 27208826 : stripped_decl = t;
12069 27208826 : STRIP_NOPS (stripped_decl);
12070 27208826 : if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl))
12071 4079803 : return IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
12072 23129023 : else if (TREE_CODE (stripped_decl) == SSA_NAME)
12073 : {
12074 1381328 : tree name = SSA_NAME_IDENTIFIER (stripped_decl);
12075 339050 : if (!name)
12076 : return NULL;
12077 337509 : return IDENTIFIER_POINTER (name);
12078 : }
12079 : else
12080 : {
12081 21747695 : switch (TREE_CODE (stripped_decl))
12082 : {
12083 1896179 : case ADDR_EXPR:
12084 1896179 : return get_name (TREE_OPERAND (stripped_decl, 0));
12085 : default:
12086 : return NULL;
12087 : }
12088 : }
12089 : }
12090 :
12091 : /* Return true if TYPE has a variable argument list. */
12092 :
12093 : bool
12094 235804827 : stdarg_p (const_tree fntype)
12095 : {
12096 235804827 : function_args_iterator args_iter;
12097 235804827 : tree n = NULL_TREE, t;
12098 :
12099 235804827 : if (!fntype)
12100 : return false;
12101 :
12102 235670074 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
12103 : return true;
12104 :
12105 954957847 : FOREACH_FUNCTION_ARGS (fntype, t, args_iter)
12106 : {
12107 719942379 : n = t;
12108 : }
12109 :
12110 235015468 : return n != NULL_TREE && n != void_type_node;
12111 : }
12112 :
12113 : /* Return true if TYPE has a prototype. */
12114 :
12115 : bool
12116 723381325 : prototype_p (const_tree fntype)
12117 : {
12118 723381325 : tree t;
12119 :
12120 723381325 : gcc_assert (fntype != NULL_TREE);
12121 :
12122 723381325 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
12123 : return true;
12124 :
12125 722640488 : t = TYPE_ARG_TYPES (fntype);
12126 722640488 : return (t != NULL_TREE);
12127 : }
12128 :
12129 : /* If BLOCK is inlined from an __attribute__((__artificial__))
12130 : routine, return pointer to location from where it has been
12131 : called. */
12132 : location_t *
12133 173063 : block_nonartificial_location (tree block)
12134 : {
12135 173063 : location_t *ret = NULL;
12136 :
12137 443142 : while (block && TREE_CODE (block) == BLOCK
12138 534922 : && BLOCK_ABSTRACT_ORIGIN (block))
12139 : {
12140 167263 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12141 167263 : if (TREE_CODE (ao) == FUNCTION_DECL)
12142 : {
12143 : /* If AO is an artificial inline, point RET to the
12144 : call site locus at which it has been inlined and continue
12145 : the loop, in case AO's caller is also an artificial
12146 : inline. */
12147 72002 : if (DECL_DECLARED_INLINE_P (ao)
12148 72002 : && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
12149 1813 : ret = &BLOCK_SOURCE_LOCATION (block);
12150 : else
12151 : break;
12152 : }
12153 95261 : else if (TREE_CODE (ao) != BLOCK)
12154 : break;
12155 :
12156 97074 : block = BLOCK_SUPERCONTEXT (block);
12157 : }
12158 173063 : return ret;
12159 : }
12160 :
12161 :
12162 : /* If EXP is inlined from an __attribute__((__artificial__))
12163 : function, return the location of the original call expression. */
12164 :
12165 : location_t
12166 58 : tree_nonartificial_location (tree exp)
12167 : {
12168 58 : location_t *loc = block_nonartificial_location (TREE_BLOCK (exp));
12169 :
12170 58 : if (loc)
12171 0 : return *loc;
12172 : else
12173 58 : return EXPR_LOCATION (exp);
12174 : }
12175 :
12176 : /* Return the location into which EXP has been inlined. Analogous
12177 : to tree_nonartificial_location() above but not limited to artificial
12178 : functions declared inline. If SYSTEM_HEADER is true, return
12179 : the macro expansion point of the location if it's in a system header */
12180 :
12181 : location_t
12182 0 : tree_inlined_location (tree exp, bool system_header /* = true */)
12183 : {
12184 0 : location_t loc = UNKNOWN_LOCATION;
12185 :
12186 0 : tree block = TREE_BLOCK (exp);
12187 :
12188 0 : while (block && TREE_CODE (block) == BLOCK
12189 0 : && BLOCK_ABSTRACT_ORIGIN (block))
12190 : {
12191 0 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12192 0 : if (TREE_CODE (ao) == FUNCTION_DECL)
12193 0 : loc = BLOCK_SOURCE_LOCATION (block);
12194 0 : else if (TREE_CODE (ao) != BLOCK)
12195 : break;
12196 :
12197 0 : block = BLOCK_SUPERCONTEXT (block);
12198 : }
12199 :
12200 0 : if (loc == UNKNOWN_LOCATION)
12201 : {
12202 0 : loc = EXPR_LOCATION (exp);
12203 0 : if (system_header)
12204 : /* Only consider macro expansion when the block traversal failed
12205 : to find a location. Otherwise it's not relevant. */
12206 0 : return expansion_point_location_if_in_system_header (loc);
12207 : }
12208 :
12209 : return loc;
12210 : }
12211 :
12212 : /* These are the hash table functions for the hash table of OPTIMIZATION_NODE
12213 : nodes. */
12214 :
12215 : /* Return the hash code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
12216 :
12217 : hashval_t
12218 857356946 : cl_option_hasher::hash (tree x)
12219 : {
12220 857356946 : const_tree const t = x;
12221 :
12222 857356946 : if (TREE_CODE (t) == OPTIMIZATION_NODE)
12223 107416315 : return cl_optimization_hash (TREE_OPTIMIZATION (t));
12224 749940631 : else if (TREE_CODE (t) == TARGET_OPTION_NODE)
12225 749940631 : return cl_target_option_hash (TREE_TARGET_OPTION (t));
12226 : else
12227 0 : gcc_unreachable ();
12228 : }
12229 :
12230 : /* Return nonzero if the value represented by *X (an OPTIMIZATION or
12231 : TARGET_OPTION tree node) is the same as that given by *Y, which is the
12232 : same. */
12233 :
12234 : bool
12235 898548767 : cl_option_hasher::equal (tree x, tree y)
12236 : {
12237 898548767 : const_tree const xt = x;
12238 898548767 : const_tree const yt = y;
12239 :
12240 898548767 : if (TREE_CODE (xt) != TREE_CODE (yt))
12241 : return false;
12242 :
12243 507828286 : if (TREE_CODE (xt) == OPTIMIZATION_NODE)
12244 97024354 : return cl_optimization_option_eq (TREE_OPTIMIZATION (xt),
12245 97024354 : TREE_OPTIMIZATION (yt));
12246 410803932 : else if (TREE_CODE (xt) == TARGET_OPTION_NODE)
12247 410803932 : return cl_target_option_eq (TREE_TARGET_OPTION (xt),
12248 410803932 : TREE_TARGET_OPTION (yt));
12249 : else
12250 0 : gcc_unreachable ();
12251 : }
12252 :
12253 : /* Build an OPTIMIZATION_NODE based on the options in OPTS and OPTS_SET. */
12254 :
12255 : tree
12256 97318560 : build_optimization_node (struct gcc_options *opts,
12257 : struct gcc_options *opts_set)
12258 : {
12259 97318560 : tree t;
12260 :
12261 : /* Use the cache of optimization nodes. */
12262 :
12263 97318560 : cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node),
12264 : opts, opts_set);
12265 :
12266 97318560 : tree *slot = cl_option_hash_table->find_slot (cl_optimization_node, INSERT);
12267 97318560 : t = *slot;
12268 97318560 : if (!t)
12269 : {
12270 : /* Insert this one into the hash table. */
12271 294625 : t = cl_optimization_node;
12272 294625 : *slot = t;
12273 :
12274 : /* Make a new node for next time round. */
12275 294625 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
12276 : }
12277 :
12278 97318560 : return t;
12279 : }
12280 :
12281 : /* Build a TARGET_OPTION_NODE based on the options in OPTS and OPTS_SET. */
12282 :
12283 : tree
12284 75398630 : build_target_option_node (struct gcc_options *opts,
12285 : struct gcc_options *opts_set)
12286 : {
12287 75398630 : tree t;
12288 :
12289 : /* Use the cache of optimization nodes. */
12290 :
12291 75398630 : cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node),
12292 : opts, opts_set);
12293 :
12294 75398630 : tree *slot = cl_option_hash_table->find_slot (cl_target_option_node, INSERT);
12295 75398630 : t = *slot;
12296 75398630 : if (!t)
12297 : {
12298 : /* Insert this one into the hash table. */
12299 774001 : t = cl_target_option_node;
12300 774001 : *slot = t;
12301 :
12302 : /* Make a new node for next time round. */
12303 774001 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
12304 : }
12305 :
12306 75398630 : return t;
12307 : }
12308 :
12309 : /* Clear TREE_TARGET_GLOBALS of all TARGET_OPTION_NODE trees,
12310 : so that they aren't saved during PCH writing. */
12311 :
12312 : void
12313 427 : prepare_target_option_nodes_for_pch (void)
12314 : {
12315 427 : hash_table<cl_option_hasher>::iterator iter = cl_option_hash_table->begin ();
12316 2562 : for (; iter != cl_option_hash_table->end (); ++iter)
12317 854 : if (TREE_CODE (*iter) == TARGET_OPTION_NODE)
12318 427 : TREE_TARGET_GLOBALS (*iter) = NULL;
12319 427 : }
12320 :
12321 : /* Determine the "ultimate origin" of a block. */
12322 :
12323 : tree
12324 226600946 : block_ultimate_origin (const_tree block)
12325 : {
12326 226600946 : tree origin = BLOCK_ABSTRACT_ORIGIN (block);
12327 :
12328 226600946 : if (origin == NULL_TREE)
12329 : return NULL_TREE;
12330 : else
12331 : {
12332 279685300 : gcc_checking_assert ((DECL_P (origin)
12333 : && DECL_ORIGIN (origin) == origin)
12334 : || BLOCK_ORIGIN (origin) == origin);
12335 : return origin;
12336 : }
12337 : }
12338 :
12339 : /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates
12340 : no instruction. */
12341 :
12342 : bool
12343 1714549045 : tree_nop_conversion_p (const_tree outer_type, const_tree inner_type)
12344 : {
12345 1714549045 : if (!inner_type || inner_type == error_mark_node)
12346 : return false;
12347 :
12348 : /* Do not strip casts into or out of differing address spaces. */
12349 1714511133 : if (POINTER_TYPE_P (outer_type)
12350 1714511133 : && TYPE_ADDR_SPACE (TREE_TYPE (outer_type)) != ADDR_SPACE_GENERIC)
12351 : {
12352 570 : if (!POINTER_TYPE_P (inner_type)
12353 570 : || (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
12354 547 : != TYPE_ADDR_SPACE (TREE_TYPE (inner_type))))
12355 : return false;
12356 : }
12357 1714510563 : else if (POINTER_TYPE_P (inner_type)
12358 1714510563 : && TYPE_ADDR_SPACE (TREE_TYPE (inner_type)) != ADDR_SPACE_GENERIC)
12359 : {
12360 : /* We already know that outer_type is not a pointer with
12361 : a non-generic address space. */
12362 : return false;
12363 : }
12364 :
12365 : /* Use precision rather then machine mode when we can, which gives
12366 : the correct answer even for submode (bit-field) types. */
12367 1714508282 : if ((INTEGRAL_TYPE_P (outer_type)
12368 737425949 : || POINTER_TYPE_P (outer_type)
12369 73459477 : || TREE_CODE (outer_type) == OFFSET_TYPE)
12370 1641060428 : && (INTEGRAL_TYPE_P (inner_type)
12371 749203045 : || POINTER_TYPE_P (inner_type)
12372 1927904 : || TREE_CODE (inner_type) == OFFSET_TYPE))
12373 1639156360 : return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type);
12374 :
12375 : /* Otherwise fall back on comparing machine modes (e.g. for
12376 : aggregate types, floats). */
12377 75351922 : return TYPE_MODE (outer_type) == TYPE_MODE (inner_type);
12378 : }
12379 :
12380 : /* Return true iff conversion in EXP generates no instruction. Mark
12381 : it inline so that we fully inline into the stripping functions even
12382 : though we have two uses of this function. */
12383 :
12384 : static inline bool
12385 20558787652 : tree_nop_conversion (const_tree exp)
12386 : {
12387 20558787652 : tree outer_type, inner_type;
12388 :
12389 20558787652 : if (location_wrapper_p (exp))
12390 : return true;
12391 20491996695 : if (!CONVERT_EXPR_P (exp)
12392 19413820810 : && TREE_CODE (exp) != NON_LVALUE_EXPR)
12393 : return false;
12394 :
12395 1094105813 : outer_type = TREE_TYPE (exp);
12396 1094105813 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12397 :
12398 1094105813 : return tree_nop_conversion_p (outer_type, inner_type);
12399 : }
12400 :
12401 : /* Return true iff conversion in EXP generates no instruction. Don't
12402 : consider conversions changing the signedness. */
12403 :
12404 : static bool
12405 2346964013 : tree_sign_nop_conversion (const_tree exp)
12406 : {
12407 2346964013 : tree outer_type, inner_type;
12408 :
12409 2346964013 : if (!tree_nop_conversion (exp))
12410 : return false;
12411 :
12412 230045591 : outer_type = TREE_TYPE (exp);
12413 230045591 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12414 :
12415 230045591 : return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type)
12416 230045591 : && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
12417 : }
12418 :
12419 : /* Strip conversions from EXP according to tree_nop_conversion and
12420 : return the resulting expression. */
12421 :
12422 : tree
12423 17440594401 : tree_strip_nop_conversions (tree exp)
12424 : {
12425 18211823639 : while (tree_nop_conversion (exp))
12426 771229238 : exp = TREE_OPERAND (exp, 0);
12427 17440594401 : return exp;
12428 : }
12429 :
12430 : /* Strip conversions from EXP according to tree_sign_nop_conversion
12431 : and return the resulting expression. */
12432 :
12433 : tree
12434 2143404608 : tree_strip_sign_nop_conversions (tree exp)
12435 : {
12436 2346964013 : while (tree_sign_nop_conversion (exp))
12437 203559405 : exp = TREE_OPERAND (exp, 0);
12438 2143404608 : return exp;
12439 : }
12440 :
12441 : /* Avoid any floating point extensions from EXP. */
12442 : tree
12443 98600852 : strip_float_extensions (tree exp)
12444 : {
12445 98718979 : tree sub, expt, subt;
12446 :
12447 : /* For floating point constant look up the narrowest type that can hold
12448 : it properly and handle it like (type)(narrowest_type)constant.
12449 : This way we can optimize for instance a=a*2.0 where "a" is float
12450 : but 2.0 is double constant. */
12451 98718979 : if (TREE_CODE (exp) == REAL_CST && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp)))
12452 : {
12453 2565202 : REAL_VALUE_TYPE orig;
12454 2565202 : tree type = NULL;
12455 :
12456 2565202 : orig = TREE_REAL_CST (exp);
12457 2565202 : if (TYPE_PRECISION (TREE_TYPE (exp)) > TYPE_PRECISION (float_type_node)
12458 2565202 : && exact_real_truncate (TYPE_MODE (float_type_node), &orig))
12459 140775 : type = float_type_node;
12460 2424427 : else if (TYPE_PRECISION (TREE_TYPE (exp))
12461 2424427 : > TYPE_PRECISION (double_type_node)
12462 2424427 : && exact_real_truncate (TYPE_MODE (double_type_node), &orig))
12463 34591 : type = double_type_node;
12464 2565202 : if (type)
12465 175366 : return build_real_truncate (type, orig);
12466 : }
12467 :
12468 98543613 : if (!CONVERT_EXPR_P (exp))
12469 : return exp;
12470 :
12471 5559958 : sub = TREE_OPERAND (exp, 0);
12472 5559958 : subt = TREE_TYPE (sub);
12473 5559958 : expt = TREE_TYPE (exp);
12474 :
12475 5559958 : if (!FLOAT_TYPE_P (subt))
12476 : return exp;
12477 :
12478 426343 : if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_FLOAT_TYPE_P (subt))
12479 : return exp;
12480 :
12481 142479 : if (element_precision (subt) > element_precision (expt))
12482 : return exp;
12483 :
12484 : return strip_float_extensions (sub);
12485 : }
12486 :
12487 : /* Strip out all handled components that produce invariant
12488 : offsets. */
12489 :
12490 : const_tree
12491 6009622770 : strip_invariant_refs (const_tree op)
12492 : {
12493 7010344664 : while (handled_component_p (op))
12494 : {
12495 1013103455 : switch (TREE_CODE (op))
12496 : {
12497 196620946 : case ARRAY_REF:
12498 196620946 : case ARRAY_RANGE_REF:
12499 196620946 : if (!is_gimple_constant (TREE_OPERAND (op, 1))
12500 185945120 : || TREE_OPERAND (op, 2) != NULL_TREE
12501 184371976 : || TREE_OPERAND (op, 3) != NULL_TREE)
12502 : return NULL;
12503 : break;
12504 :
12505 815066507 : case COMPONENT_REF:
12506 815066507 : if (TREE_OPERAND (op, 2) != NULL_TREE)
12507 : return NULL;
12508 : break;
12509 :
12510 1000721894 : default:;
12511 : }
12512 1000721894 : op = TREE_OPERAND (op, 0);
12513 : }
12514 :
12515 : return op;
12516 : }
12517 :
12518 : /* Strip handled components with zero offset from OP. */
12519 :
12520 : tree
12521 576733 : strip_zero_offset_components (tree op)
12522 : {
12523 576733 : while (TREE_CODE (op) == COMPONENT_REF
12524 435194 : && integer_zerop (DECL_FIELD_OFFSET (TREE_OPERAND (op, 1)))
12525 1124684 : && integer_zerop (DECL_FIELD_BIT_OFFSET (TREE_OPERAND (op, 1))))
12526 180301 : op = TREE_OPERAND (op, 0);
12527 576733 : return op;
12528 : }
12529 :
12530 : static GTY(()) tree gcc_eh_personality_decl;
12531 :
12532 : /* Return the GCC personality function decl. */
12533 :
12534 : tree
12535 406 : lhd_gcc_personality (void)
12536 : {
12537 406 : if (!gcc_eh_personality_decl)
12538 160 : gcc_eh_personality_decl = build_personality_function ("gcc");
12539 406 : return gcc_eh_personality_decl;
12540 : }
12541 :
12542 : /* TARGET is a call target of GIMPLE call statement
12543 : (obtained by gimple_call_fn). Return true if it is
12544 : OBJ_TYPE_REF representing an virtual call of C++ method.
12545 : (As opposed to OBJ_TYPE_REF representing objc calls
12546 : through a cast where middle-end devirtualization machinery
12547 : can't apply.) FOR_DUMP_P is true when being called from
12548 : the dump routines. */
12549 :
12550 : bool
12551 28488210 : virtual_method_call_p (const_tree target, bool for_dump_p)
12552 : {
12553 28488210 : if (TREE_CODE (target) != OBJ_TYPE_REF)
12554 : return false;
12555 1295754 : tree t = TREE_TYPE (target);
12556 1295754 : gcc_checking_assert (TREE_CODE (t) == POINTER_TYPE);
12557 1295754 : t = TREE_TYPE (t);
12558 1295754 : if (TREE_CODE (t) == FUNCTION_TYPE)
12559 : return false;
12560 1294482 : gcc_checking_assert (TREE_CODE (t) == METHOD_TYPE);
12561 : /* If we do not have BINFO associated, it means that type was built
12562 : without devirtualization enabled. Do not consider this a virtual
12563 : call. */
12564 1294482 : if (!TYPE_BINFO (obj_type_ref_class (target, for_dump_p)))
12565 : return false;
12566 : return true;
12567 : }
12568 :
12569 : /* Lookup sub-BINFO of BINFO of TYPE at offset POS. */
12570 :
12571 : static tree
12572 108 : lookup_binfo_at_offset (tree binfo, tree type, HOST_WIDE_INT pos)
12573 : {
12574 108 : unsigned int i;
12575 108 : tree base_binfo, b;
12576 :
12577 124 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12578 108 : if (pos == tree_to_shwi (BINFO_OFFSET (base_binfo))
12579 108 : && types_same_for_odr (TREE_TYPE (base_binfo), type))
12580 : return base_binfo;
12581 70 : else if ((b = lookup_binfo_at_offset (base_binfo, type, pos)) != NULL)
12582 : return b;
12583 : return NULL;
12584 : }
12585 :
12586 : /* Try to find a base info of BINFO that would have its field decl at offset
12587 : OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
12588 : found, return, otherwise return NULL_TREE. */
12589 :
12590 : tree
12591 274094 : get_binfo_at_offset (tree binfo, poly_int64 offset, tree expected_type)
12592 : {
12593 274094 : tree type = BINFO_TYPE (binfo);
12594 :
12595 731570 : while (true)
12596 : {
12597 502832 : HOST_WIDE_INT pos, size;
12598 502832 : tree fld;
12599 502832 : int i;
12600 :
12601 502832 : if (types_same_for_odr (type, expected_type))
12602 274094 : return binfo;
12603 228738 : if (maybe_lt (offset, 0))
12604 : return NULL_TREE;
12605 :
12606 1147286 : for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
12607 : {
12608 1147286 : if (TREE_CODE (fld) != FIELD_DECL || !DECL_ARTIFICIAL (fld))
12609 918351 : continue;
12610 :
12611 228935 : pos = int_bit_position (fld);
12612 228935 : size = tree_to_uhwi (DECL_SIZE (fld));
12613 1147483 : if (known_in_range_p (offset, pos, size))
12614 : break;
12615 : }
12616 228738 : if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE)
12617 : return NULL_TREE;
12618 :
12619 : /* Offset 0 indicates the primary base, whose vtable contents are
12620 : represented in the binfo for the derived class. */
12621 228738 : else if (maybe_ne (offset, 0))
12622 : {
12623 197 : tree found_binfo = NULL, base_binfo;
12624 : /* Offsets in BINFO are in bytes relative to the whole structure
12625 : while POS is in bits relative to the containing field. */
12626 197 : int binfo_offset = (tree_to_shwi (BINFO_OFFSET (binfo)) + pos
12627 197 : / BITS_PER_UNIT);
12628 :
12629 377 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12630 339 : if (tree_to_shwi (BINFO_OFFSET (base_binfo)) == binfo_offset
12631 339 : && types_same_for_odr (TREE_TYPE (base_binfo), TREE_TYPE (fld)))
12632 : {
12633 : found_binfo = base_binfo;
12634 : break;
12635 : }
12636 197 : if (found_binfo)
12637 : binfo = found_binfo;
12638 : else
12639 38 : binfo = lookup_binfo_at_offset (binfo, TREE_TYPE (fld),
12640 : binfo_offset);
12641 : }
12642 :
12643 228738 : type = TREE_TYPE (fld);
12644 228738 : offset -= pos;
12645 228738 : }
12646 : }
12647 :
12648 : /* PR 84195: Replace control characters in "unescaped" with their
12649 : escaped equivalents. Allow newlines if -fmessage-length has
12650 : been set to a non-zero value. This is done here, rather than
12651 : where the attribute is recorded as the message length can
12652 : change between these two locations. */
12653 :
12654 : void
12655 135158 : escaped_string::escape (const char *unescaped)
12656 : {
12657 135158 : char *escaped;
12658 135158 : size_t i, new_i, len;
12659 :
12660 135158 : if (m_owned)
12661 8 : free (m_str);
12662 :
12663 135158 : m_str = const_cast<char *> (unescaped);
12664 135158 : m_owned = false;
12665 :
12666 135158 : if (unescaped == NULL || *unescaped == 0)
12667 : return;
12668 :
12669 135150 : len = strlen (unescaped);
12670 135150 : escaped = NULL;
12671 135150 : new_i = 0;
12672 :
12673 3922715 : for (i = 0; i < len; i++)
12674 : {
12675 3787565 : char c = unescaped[i];
12676 :
12677 3787565 : if (!ISCNTRL (c))
12678 : {
12679 3787480 : if (escaped)
12680 33 : escaped[new_i++] = c;
12681 3787480 : continue;
12682 : }
12683 :
12684 85 : if (c != '\n' || !pp_is_wrapping_line (global_dc->get_reference_printer ()))
12685 : {
12686 77 : if (escaped == NULL)
12687 : {
12688 : /* We only allocate space for a new string if we
12689 : actually encounter a control character that
12690 : needs replacing. */
12691 19 : escaped = (char *) xmalloc (len * 2 + 1);
12692 19 : strncpy (escaped, unescaped, i);
12693 19 : new_i = i;
12694 : }
12695 :
12696 77 : escaped[new_i++] = '\\';
12697 :
12698 77 : switch (c)
12699 : {
12700 8 : case '\a': escaped[new_i++] = 'a'; break;
12701 8 : case '\b': escaped[new_i++] = 'b'; break;
12702 8 : case '\f': escaped[new_i++] = 'f'; break;
12703 15 : case '\n': escaped[new_i++] = 'n'; break;
12704 15 : case '\r': escaped[new_i++] = 'r'; break;
12705 15 : case '\t': escaped[new_i++] = 't'; break;
12706 8 : case '\v': escaped[new_i++] = 'v'; break;
12707 0 : default: escaped[new_i++] = '?'; break;
12708 : }
12709 : }
12710 8 : else if (escaped)
12711 4 : escaped[new_i++] = c;
12712 : }
12713 :
12714 135150 : if (escaped)
12715 : {
12716 19 : escaped[new_i] = 0;
12717 19 : m_str = escaped;
12718 19 : m_owned = true;
12719 : }
12720 : }
12721 :
12722 : /* Warn about a use of an identifier which was marked deprecated. Returns
12723 : whether a warning was given. */
12724 :
12725 : bool
12726 1404155 : warn_deprecated_use (tree node, tree attr)
12727 : {
12728 1404155 : escaped_string msg;
12729 :
12730 1404155 : if (node == 0 || !warn_deprecated_decl)
12731 : return false;
12732 :
12733 1396916 : if (!attr)
12734 : {
12735 1282492 : if (DECL_P (node))
12736 1282328 : attr = DECL_ATTRIBUTES (node);
12737 164 : else if (TYPE_P (node))
12738 : {
12739 164 : tree decl = TYPE_STUB_DECL (node);
12740 164 : if (decl)
12741 140 : attr = TYPE_ATTRIBUTES (TREE_TYPE (decl));
12742 24 : else if ((decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (node)))
12743 : != NULL_TREE)
12744 : {
12745 6 : node = TREE_TYPE (decl);
12746 6 : attr = TYPE_ATTRIBUTES (node);
12747 : }
12748 : }
12749 : }
12750 :
12751 1282492 : if (attr)
12752 134828 : attr = lookup_attribute ("deprecated", attr);
12753 :
12754 134828 : if (attr)
12755 134817 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12756 :
12757 1396916 : bool w = false;
12758 1396916 : if (DECL_P (node))
12759 : {
12760 1396742 : auto_diagnostic_group d;
12761 1396742 : if (msg)
12762 134732 : w = warning (OPT_Wdeprecated_declarations,
12763 : "%qD is deprecated: %s", node, (const char *) msg);
12764 : else
12765 1262010 : w = warning (OPT_Wdeprecated_declarations,
12766 : "%qD is deprecated", node);
12767 1396742 : if (w)
12768 800 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12769 1396742 : }
12770 174 : else if (TYPE_P (node))
12771 : {
12772 174 : tree what = NULL_TREE;
12773 174 : tree decl = TYPE_STUB_DECL (node);
12774 :
12775 174 : if (TYPE_NAME (node))
12776 : {
12777 169 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12778 10 : what = TYPE_NAME (node);
12779 159 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12780 159 : && DECL_NAME (TYPE_NAME (node)))
12781 159 : what = DECL_NAME (TYPE_NAME (node));
12782 : }
12783 :
12784 174 : auto_diagnostic_group d;
12785 174 : if (what)
12786 : {
12787 169 : if (msg)
12788 83 : w = warning (OPT_Wdeprecated_declarations,
12789 : "%qE is deprecated: %s", what, (const char *) msg);
12790 : else
12791 86 : w = warning (OPT_Wdeprecated_declarations,
12792 : "%qE is deprecated", what);
12793 : }
12794 : else
12795 : {
12796 5 : if (msg)
12797 2 : w = warning (OPT_Wdeprecated_declarations,
12798 : "type is deprecated: %s", (const char *) msg);
12799 : else
12800 3 : w = warning (OPT_Wdeprecated_declarations,
12801 : "type is deprecated");
12802 : }
12803 :
12804 174 : if (w && decl)
12805 111 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12806 174 : }
12807 :
12808 : return w;
12809 1404155 : }
12810 :
12811 : /* Error out with an identifier which was marked 'unavailable'. */
12812 : void
12813 376 : error_unavailable_use (tree node, tree attr)
12814 : {
12815 376 : escaped_string msg;
12816 :
12817 376 : if (node == 0)
12818 0 : return;
12819 :
12820 376 : if (!attr)
12821 : {
12822 366 : if (DECL_P (node))
12823 306 : attr = DECL_ATTRIBUTES (node);
12824 60 : else if (TYPE_P (node))
12825 : {
12826 60 : tree decl = TYPE_STUB_DECL (node);
12827 60 : if (decl)
12828 51 : attr = lookup_attribute ("unavailable",
12829 51 : TYPE_ATTRIBUTES (TREE_TYPE (decl)));
12830 : }
12831 : }
12832 :
12833 366 : if (attr)
12834 164 : attr = lookup_attribute ("unavailable", attr);
12835 :
12836 164 : if (attr)
12837 164 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12838 :
12839 376 : if (DECL_P (node))
12840 : {
12841 306 : auto_diagnostic_group d;
12842 306 : if (msg)
12843 129 : error ("%qD is unavailable: %s", node, (const char *) msg);
12844 : else
12845 177 : error ("%qD is unavailable", node);
12846 306 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12847 306 : }
12848 70 : else if (TYPE_P (node))
12849 : {
12850 70 : tree what = NULL_TREE;
12851 70 : tree decl = TYPE_STUB_DECL (node);
12852 :
12853 70 : if (TYPE_NAME (node))
12854 : {
12855 66 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12856 4 : what = TYPE_NAME (node);
12857 62 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12858 62 : && DECL_NAME (TYPE_NAME (node)))
12859 62 : what = DECL_NAME (TYPE_NAME (node));
12860 : }
12861 :
12862 70 : auto_diagnostic_group d;
12863 70 : if (what)
12864 : {
12865 66 : if (msg)
12866 33 : error ("%qE is unavailable: %s", what, (const char *) msg);
12867 : else
12868 33 : error ("%qE is unavailable", what);
12869 : }
12870 : else
12871 : {
12872 4 : if (msg)
12873 2 : error ("type is unavailable: %s", (const char *) msg);
12874 : else
12875 2 : error ("type is unavailable");
12876 : }
12877 :
12878 70 : if (decl)
12879 52 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12880 70 : }
12881 376 : }
12882 :
12883 : /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
12884 : somewhere in it. */
12885 :
12886 : bool
12887 5818324 : contains_bitfld_component_ref_p (const_tree ref)
12888 : {
12889 11890527 : while (handled_component_p (ref))
12890 : {
12891 6088749 : if (TREE_CODE (ref) == COMPONENT_REF
12892 6088749 : && DECL_BIT_FIELD (TREE_OPERAND (ref, 1)))
12893 : return true;
12894 6072203 : ref = TREE_OPERAND (ref, 0);
12895 : }
12896 :
12897 : return false;
12898 : }
12899 :
12900 : /* Try to determine whether a TRY_CATCH expression can fall through.
12901 : This is a subroutine of block_may_fallthru. */
12902 :
12903 : static bool
12904 1 : try_catch_may_fallthru (const_tree stmt)
12905 : {
12906 1 : tree_stmt_iterator i;
12907 :
12908 : /* If the TRY block can fall through, the whole TRY_CATCH can
12909 : fall through. */
12910 1 : if (block_may_fallthru (TREE_OPERAND (stmt, 0)))
12911 : return true;
12912 :
12913 1 : switch (TREE_CODE (TREE_OPERAND (stmt, 1)))
12914 : {
12915 0 : case CATCH_EXPR:
12916 : /* See below. */
12917 0 : return block_may_fallthru (CATCH_BODY (TREE_OPERAND (stmt, 1)));
12918 :
12919 0 : case EH_FILTER_EXPR:
12920 : /* See below. */
12921 0 : return block_may_fallthru (EH_FILTER_FAILURE (TREE_OPERAND (stmt, 1)));
12922 :
12923 0 : case STATEMENT_LIST:
12924 0 : break;
12925 :
12926 : default:
12927 : /* See below. */
12928 : return false;
12929 : }
12930 :
12931 0 : i = tsi_start (TREE_OPERAND (stmt, 1));
12932 0 : switch (TREE_CODE (tsi_stmt (i)))
12933 : {
12934 : case CATCH_EXPR:
12935 : /* We expect to see a sequence of CATCH_EXPR trees, each with a
12936 : catch expression and a body. The whole TRY_CATCH may fall
12937 : through iff any of the catch bodies falls through. */
12938 0 : for (; !tsi_end_p (i); tsi_next (&i))
12939 : {
12940 0 : if (block_may_fallthru (CATCH_BODY (tsi_stmt (i))))
12941 : return true;
12942 : }
12943 : return false;
12944 :
12945 0 : case EH_FILTER_EXPR:
12946 : /* The exception filter expression only matters if there is an
12947 : exception. If the exception does not match EH_FILTER_TYPES,
12948 : we will execute EH_FILTER_FAILURE, and we will fall through
12949 : if that falls through. If the exception does match
12950 : EH_FILTER_TYPES, the stack unwinder will continue up the
12951 : stack, so we will not fall through. We don't know whether we
12952 : will throw an exception which matches EH_FILTER_TYPES or not,
12953 : so we just ignore EH_FILTER_TYPES and assume that we might
12954 : throw an exception which doesn't match. */
12955 0 : return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i)));
12956 :
12957 : default:
12958 : /* This case represents statements to be executed when an
12959 : exception occurs. Those statements are implicitly followed
12960 : by a RESX statement to resume execution after the exception.
12961 : So in this case the TRY_CATCH never falls through. */
12962 : return false;
12963 : }
12964 : }
12965 :
12966 : /* Try to determine if we can fall out of the bottom of BLOCK. This guess
12967 : need not be 100% accurate; simply be conservative and return true if we
12968 : don't know. This is used only to avoid stupidly generating extra code.
12969 : If we're wrong, we'll just delete the extra code later. */
12970 :
12971 : bool
12972 9271652 : block_may_fallthru (const_tree block)
12973 : {
12974 : /* This CONST_CAST is okay because expr_last returns its argument
12975 : unmodified and we assign it to a const_tree. */
12976 10707896 : const_tree stmt = expr_last (const_cast<tree> (block));
12977 :
12978 10707896 : switch (stmt ? TREE_CODE (stmt) : ERROR_MARK)
12979 : {
12980 : case GOTO_EXPR:
12981 : case RETURN_EXPR:
12982 : /* Easy cases. If the last statement of the block implies
12983 : control transfer, then we can't fall through. */
12984 : return false;
12985 :
12986 12 : case SWITCH_EXPR:
12987 : /* If there is a default: label or case labels cover all possible
12988 : SWITCH_COND values, then the SWITCH_EXPR will transfer control
12989 : to some case label in all cases and all we care is whether the
12990 : SWITCH_BODY falls through. */
12991 12 : if (SWITCH_ALL_CASES_P (stmt))
12992 11 : return block_may_fallthru (SWITCH_BODY (stmt));
12993 : return true;
12994 :
12995 21697 : case COND_EXPR:
12996 21697 : if (block_may_fallthru (COND_EXPR_THEN (stmt)))
12997 : return true;
12998 2821 : return block_may_fallthru (COND_EXPR_ELSE (stmt));
12999 :
13000 919307 : case BIND_EXPR:
13001 919307 : return block_may_fallthru (BIND_EXPR_BODY (stmt));
13002 :
13003 1 : case TRY_CATCH_EXPR:
13004 1 : return try_catch_may_fallthru (stmt);
13005 :
13006 2043 : case TRY_FINALLY_EXPR:
13007 : /* The finally clause is always executed after the try clause,
13008 : so if it does not fall through, then the try-finally will not
13009 : fall through. Otherwise, if the try clause does not fall
13010 : through, then when the finally clause falls through it will
13011 : resume execution wherever the try clause was going. So the
13012 : whole try-finally will only fall through if both the try
13013 : clause and the finally clause fall through. */
13014 2043 : return (block_may_fallthru (TREE_OPERAND (stmt, 0))
13015 2043 : && block_may_fallthru (TREE_OPERAND (stmt, 1)));
13016 :
13017 0 : case EH_ELSE_EXPR:
13018 0 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
13019 :
13020 91681 : case MODIFY_EXPR:
13021 91681 : if (TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR)
13022 1584 : stmt = TREE_OPERAND (stmt, 1);
13023 : else
13024 : return true;
13025 : /* FALLTHRU */
13026 :
13027 444117 : case CALL_EXPR:
13028 : /* Functions that do not return do not fall through. */
13029 444117 : return (call_expr_flags (stmt) & ECF_NORETURN) == 0;
13030 :
13031 514095 : case CLEANUP_POINT_EXPR:
13032 514095 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
13033 :
13034 10 : case TARGET_EXPR:
13035 10 : return block_may_fallthru (TREE_OPERAND (stmt, 1));
13036 :
13037 : case ERROR_MARK:
13038 : return true;
13039 :
13040 6472851 : default:
13041 6472851 : return lang_hooks.block_may_fallthru (stmt);
13042 : }
13043 : }
13044 :
13045 : /* True if we are using EH to handle cleanups. */
13046 : static bool using_eh_for_cleanups_flag = false;
13047 :
13048 : /* This routine is called from front ends to indicate eh should be used for
13049 : cleanups. */
13050 : void
13051 125920 : using_eh_for_cleanups (void)
13052 : {
13053 125920 : using_eh_for_cleanups_flag = true;
13054 125920 : }
13055 :
13056 : /* Query whether EH is used for cleanups. */
13057 : bool
13058 1729680 : using_eh_for_cleanups_p (void)
13059 : {
13060 1729680 : return using_eh_for_cleanups_flag;
13061 : }
13062 :
13063 : /* Wrapper for tree_code_name to ensure that tree code is valid */
13064 : const char *
13065 14582663494 : get_tree_code_name (enum tree_code code)
13066 : {
13067 14582663494 : const char *invalid = "<invalid tree code>";
13068 :
13069 : /* The tree_code enum promotes to signed, but we could be getting
13070 : invalid values, so force an unsigned comparison. */
13071 14582663494 : if (unsigned (code) >= MAX_TREE_CODES)
13072 : {
13073 0 : if ((unsigned)code == 0xa5a5)
13074 : return "ggc_freed";
13075 0 : return invalid;
13076 : }
13077 :
13078 14582663494 : return tree_code_name[code];
13079 : }
13080 :
13081 : /* Drops the TREE_OVERFLOW flag from T. */
13082 :
13083 : tree
13084 35085 : drop_tree_overflow (tree t)
13085 : {
13086 35085 : gcc_checking_assert (TREE_OVERFLOW (t));
13087 :
13088 : /* For tree codes with a sharing machinery re-build the result. */
13089 35085 : if (poly_int_tree_p (t))
13090 35073 : return wide_int_to_tree (TREE_TYPE (t), wi::to_poly_wide (t));
13091 :
13092 : /* For VECTOR_CST, remove the overflow bits from the encoded elements
13093 : and canonicalize the result. */
13094 12 : if (TREE_CODE (t) == VECTOR_CST)
13095 : {
13096 0 : tree_vector_builder builder;
13097 0 : builder.new_unary_operation (TREE_TYPE (t), t, true);
13098 0 : unsigned int count = builder.encoded_nelts ();
13099 0 : for (unsigned int i = 0; i < count; ++i)
13100 : {
13101 0 : tree elt = VECTOR_CST_ELT (t, i);
13102 0 : if (TREE_OVERFLOW (elt))
13103 0 : elt = drop_tree_overflow (elt);
13104 0 : builder.quick_push (elt);
13105 : }
13106 0 : return builder.build ();
13107 0 : }
13108 :
13109 : /* Otherwise, as all tcc_constants are possibly shared, copy the node
13110 : and drop the flag. */
13111 12 : t = copy_node (t);
13112 12 : TREE_OVERFLOW (t) = 0;
13113 :
13114 : /* For constants that contain nested constants, drop the flag
13115 : from those as well. */
13116 12 : if (TREE_CODE (t) == COMPLEX_CST)
13117 : {
13118 12 : if (TREE_OVERFLOW (TREE_REALPART (t)))
13119 12 : TREE_REALPART (t) = drop_tree_overflow (TREE_REALPART (t));
13120 12 : if (TREE_OVERFLOW (TREE_IMAGPART (t)))
13121 0 : TREE_IMAGPART (t) = drop_tree_overflow (TREE_IMAGPART (t));
13122 : }
13123 :
13124 : return t;
13125 : }
13126 :
13127 : /* Given a memory reference expression T, return its base address.
13128 : The base address of a memory reference expression is the main
13129 : object being referenced. For instance, the base address for
13130 : 'array[i].fld[j]' is 'array'. You can think of this as stripping
13131 : away the offset part from a memory address.
13132 :
13133 : This function calls handled_component_p to strip away all the inner
13134 : parts of the memory reference until it reaches the base object. */
13135 :
13136 : tree
13137 3234590048 : get_base_address (tree t)
13138 : {
13139 3234590048 : if (TREE_CODE (t) == WITH_SIZE_EXPR)
13140 899 : t = TREE_OPERAND (t, 0);
13141 4024890853 : while (handled_component_p (t))
13142 790300805 : t = TREE_OPERAND (t, 0);
13143 :
13144 3234590048 : if ((TREE_CODE (t) == MEM_REF
13145 3234590048 : || TREE_CODE (t) == TARGET_MEM_REF)
13146 3234590048 : && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
13147 145846810 : t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
13148 :
13149 3234590048 : return t;
13150 : }
13151 :
13152 : /* Return a tree of sizetype representing the size, in bytes, of the element
13153 : of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13154 :
13155 : tree
13156 796758253 : array_ref_element_size (tree exp)
13157 : {
13158 796758253 : tree aligned_size = TREE_OPERAND (exp, 3);
13159 796758253 : tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
13160 796758253 : location_t loc = EXPR_LOCATION (exp);
13161 :
13162 : /* If a size was specified in the ARRAY_REF, it's the size measured
13163 : in alignment units of the element type. So multiply by that value. */
13164 796758253 : if (aligned_size)
13165 : {
13166 : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13167 : sizetype from another type of the same width and signedness. */
13168 389466 : if (TREE_TYPE (aligned_size) != sizetype)
13169 3060 : aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
13170 389466 : return size_binop_loc (loc, MULT_EXPR, aligned_size,
13171 389466 : size_int (TYPE_ALIGN_UNIT (elmt_type)));
13172 : }
13173 :
13174 : /* Otherwise, take the size from that of the element type. Substitute
13175 : any PLACEHOLDER_EXPR that we have. */
13176 : else
13177 796368787 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
13178 : }
13179 :
13180 : /* Return a tree representing the lower bound of the array mentioned in
13181 : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13182 :
13183 : tree
13184 1098590131 : array_ref_low_bound (tree exp)
13185 : {
13186 1098590131 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13187 :
13188 : /* If a lower bound is specified in EXP, use it. */
13189 1098590131 : if (TREE_OPERAND (exp, 2))
13190 1974090 : return TREE_OPERAND (exp, 2);
13191 :
13192 : /* Otherwise, if there is a domain type and it has a lower bound, use it,
13193 : substituting for a PLACEHOLDER_EXPR as needed. */
13194 1096616041 : if (domain_type && TYPE_MIN_VALUE (domain_type))
13195 1095690597 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
13196 :
13197 : /* Otherwise, return a zero of the appropriate type. */
13198 925444 : tree idxtype = TREE_TYPE (TREE_OPERAND (exp, 1));
13199 925444 : return (idxtype == error_mark_node
13200 925444 : ? integer_zero_node : build_int_cst (idxtype, 0));
13201 : }
13202 :
13203 : /* Return a tree representing the upper bound of the array mentioned in
13204 : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13205 :
13206 : tree
13207 251789942 : array_ref_up_bound (tree exp)
13208 : {
13209 251789942 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13210 :
13211 : /* If there is a domain type and it has an upper bound, use it, substituting
13212 : for a PLACEHOLDER_EXPR as needed. */
13213 251789942 : if (domain_type && TYPE_MAX_VALUE (domain_type))
13214 250973509 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
13215 :
13216 : /* Otherwise fail. */
13217 : return NULL_TREE;
13218 : }
13219 :
13220 : /* Returns true if REF is an array reference, a component reference,
13221 : or a memory reference to an array whose actual size might be larger
13222 : than its upper bound implies, there are multiple cases:
13223 : A. a ref to a flexible array member at the end of a structure;
13224 : B. a ref to an array with a different type against the original decl;
13225 : for example:
13226 :
13227 : short a[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
13228 : (*((char(*)[16])&a[0]))[i+8]
13229 :
13230 : C. a ref to an array that was passed as a parameter;
13231 : for example:
13232 :
13233 : int test (uint8_t *p, uint32_t t[1][1], int n) {
13234 : for (int i = 0; i < 4; i++, p++)
13235 : t[i][0] = ...;
13236 :
13237 : If non-null, set IS_TRAILING_ARRAY to true if the ref is the above case A.
13238 : */
13239 :
13240 : bool
13241 75474736 : array_ref_flexible_size_p (tree ref, bool *is_trailing_array /* = NULL */)
13242 : {
13243 : /* The TYPE for this array reference. */
13244 75474736 : tree atype = NULL_TREE;
13245 : /* The FIELD_DECL for the array field in the containing structure. */
13246 75474736 : tree afield_decl = NULL_TREE;
13247 : /* Whether this array is the trailing array of a structure. */
13248 75474736 : bool is_trailing_array_tmp = false;
13249 75474736 : if (!is_trailing_array)
13250 75391912 : is_trailing_array = &is_trailing_array_tmp;
13251 :
13252 75474736 : if (TREE_CODE (ref) == ARRAY_REF
13253 75474736 : || TREE_CODE (ref) == ARRAY_RANGE_REF)
13254 : {
13255 75232487 : atype = TREE_TYPE (TREE_OPERAND (ref, 0));
13256 75232487 : ref = TREE_OPERAND (ref, 0);
13257 : }
13258 242249 : else if (TREE_CODE (ref) == COMPONENT_REF
13259 242249 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 1))) == ARRAY_TYPE)
13260 : {
13261 171371 : atype = TREE_TYPE (TREE_OPERAND (ref, 1));
13262 171371 : afield_decl = TREE_OPERAND (ref, 1);
13263 : }
13264 70878 : else if (TREE_CODE (ref) == MEM_REF)
13265 : {
13266 7570 : tree arg = TREE_OPERAND (ref, 0);
13267 7570 : if (TREE_CODE (arg) == ADDR_EXPR)
13268 7570 : arg = TREE_OPERAND (arg, 0);
13269 7570 : tree argtype = TREE_TYPE (arg);
13270 7570 : if (TREE_CODE (argtype) == RECORD_TYPE)
13271 : {
13272 157 : if (tree fld = last_field (argtype))
13273 : {
13274 157 : atype = TREE_TYPE (fld);
13275 157 : afield_decl = fld;
13276 157 : if (TREE_CODE (atype) != ARRAY_TYPE)
13277 : return false;
13278 157 : if (VAR_P (arg) && DECL_SIZE (fld))
13279 : return false;
13280 : }
13281 : else
13282 : return false;
13283 : }
13284 : else
13285 : return false;
13286 : }
13287 : else
13288 : return false;
13289 :
13290 75403971 : if (TREE_CODE (ref) == STRING_CST)
13291 : return false;
13292 :
13293 : tree ref_to_array = ref;
13294 92661645 : while (handled_component_p (ref))
13295 : {
13296 : /* If the reference chain contains a component reference to a
13297 : non-union type and there follows another field the reference
13298 : is not at the end of a structure. */
13299 20402494 : if (TREE_CODE (ref) == COMPONENT_REF)
13300 : {
13301 19258980 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
13302 : {
13303 18003678 : tree nextf = DECL_CHAIN (TREE_OPERAND (ref, 1));
13304 43719032 : while (nextf && TREE_CODE (nextf) != FIELD_DECL)
13305 25715354 : nextf = DECL_CHAIN (nextf);
13306 : if (nextf)
13307 : return false;
13308 : }
13309 : }
13310 : /* If we have a multi-dimensional array we do not consider
13311 : a non-innermost dimension as flex array if the whole
13312 : multi-dimensional array is at struct end.
13313 : Same for an array of aggregates with a trailing array
13314 : member. */
13315 1143514 : else if (TREE_CODE (ref) == ARRAY_REF)
13316 : return false;
13317 197144 : else if (TREE_CODE (ref) == ARRAY_RANGE_REF)
13318 : ;
13319 : /* If we view an underlying object as sth else then what we
13320 : gathered up to now is what we have to rely on. */
13321 197128 : else if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
13322 : break;
13323 : else
13324 0 : gcc_unreachable ();
13325 :
13326 17258882 : ref = TREE_OPERAND (ref, 0);
13327 : }
13328 :
13329 72456279 : gcc_assert (!afield_decl
13330 : || (afield_decl && TREE_CODE (afield_decl) == FIELD_DECL));
13331 :
13332 : /* The array now is at struct end. Treat flexible array member as
13333 : always subject to extend, even into just padding constrained by
13334 : an underlying decl. */
13335 72456279 : if (! TYPE_SIZE (atype)
13336 69894918 : || ! TYPE_DOMAIN (atype)
13337 142351197 : || ! TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13338 : {
13339 2566797 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13340 2651688 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13341 : }
13342 :
13343 : /* If the reference is based on a declared entity, the size of the array
13344 : is constrained by its given domain. (Do not trust commons PR/69368). */
13345 69889482 : ref = get_base_address (ref);
13346 69889482 : if (ref
13347 69889482 : && DECL_P (ref)
13348 59553630 : && !(flag_unconstrained_commons
13349 14 : && VAR_P (ref) && DECL_COMMON (ref))
13350 59553616 : && DECL_SIZE_UNIT (ref)
13351 129442721 : && TREE_CODE (DECL_SIZE_UNIT (ref)) == INTEGER_CST)
13352 : {
13353 : /* If the object itself is the array it is not at struct end. */
13354 59553211 : if (DECL_P (ref_to_array))
13355 : return false;
13356 :
13357 : /* Check whether the array domain covers all of the available
13358 : padding. */
13359 15688625 : poly_int64 offset;
13360 15688625 : if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
13361 15687265 : || TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST
13362 31353570 : || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST)
13363 : {
13364 23680 : *is_trailing_array
13365 23680 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13366 23723 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13367 : }
13368 15664945 : if (! get_addr_base_and_unit_offset (ref_to_array, &offset))
13369 : {
13370 2821 : *is_trailing_array
13371 2821 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13372 2821 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13373 : }
13374 :
13375 : /* If at least one extra element fits it is a flexarray. */
13376 15662124 : if (known_le ((wi::to_offset (TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13377 : - wi::to_offset (TYPE_MIN_VALUE (TYPE_DOMAIN (atype)))
13378 : + 2)
13379 : * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (atype))),
13380 : wi::to_offset (DECL_SIZE_UNIT (ref)) - offset))
13381 : {
13382 394506 : *is_trailing_array
13383 394506 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13384 404284 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13385 : }
13386 :
13387 : return false;
13388 : }
13389 :
13390 10336271 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13391 10351154 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13392 : }
13393 :
13394 :
13395 : /* Return a tree representing the offset, in bytes, of the field referenced
13396 : by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
13397 :
13398 : tree
13399 2765202287 : component_ref_field_offset (tree exp)
13400 : {
13401 2765202287 : tree aligned_offset = TREE_OPERAND (exp, 2);
13402 2765202287 : tree field = TREE_OPERAND (exp, 1);
13403 2765202287 : location_t loc = EXPR_LOCATION (exp);
13404 :
13405 : /* If an offset was specified in the COMPONENT_REF, it's the offset measured
13406 : in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
13407 : value. */
13408 2765202287 : if (aligned_offset)
13409 : {
13410 : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13411 : sizetype from another type of the same width and signedness. */
13412 11911 : if (TREE_TYPE (aligned_offset) != sizetype)
13413 133 : aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
13414 11911 : return size_binop_loc (loc, MULT_EXPR, aligned_offset,
13415 11911 : size_int (DECL_OFFSET_ALIGN (field)
13416 : / BITS_PER_UNIT));
13417 : }
13418 :
13419 : /* Otherwise, take the offset from that of the field. Substitute
13420 : any PLACEHOLDER_EXPR that we have. */
13421 : else
13422 2765190376 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
13423 : }
13424 :
13425 : /* Given the initializer INIT, return the initializer for the field
13426 : DECL if it exists, otherwise null. Used to obtain the initializer
13427 : for a flexible array member and determine its size. */
13428 :
13429 : static tree
13430 1267 : get_initializer_for (tree init, tree decl)
13431 : {
13432 1267 : STRIP_NOPS (init);
13433 :
13434 1267 : tree fld, fld_init;
13435 1267 : unsigned HOST_WIDE_INT i;
13436 3571 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), i, fld, fld_init)
13437 : {
13438 1926 : if (decl == fld)
13439 : return fld_init;
13440 :
13441 1037 : if (TREE_CODE (fld) == CONSTRUCTOR)
13442 : {
13443 0 : fld_init = get_initializer_for (fld_init, decl);
13444 0 : if (fld_init)
13445 : return fld_init;
13446 : }
13447 : }
13448 :
13449 : return NULL_TREE;
13450 : }
13451 :
13452 : /* Determines the special array member type for the array reference REF. */
13453 : special_array_member
13454 255776 : component_ref_sam_type (tree ref)
13455 : {
13456 255776 : special_array_member sam_type = special_array_member::none;
13457 :
13458 255776 : tree member = TREE_OPERAND (ref, 1);
13459 255776 : tree memsize = DECL_SIZE_UNIT (member);
13460 255776 : if (memsize)
13461 : {
13462 123702 : tree memtype = TREE_TYPE (member);
13463 123702 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13464 123580 : return sam_type;
13465 :
13466 82824 : bool trailing = false;
13467 82824 : (void) array_ref_flexible_size_p (ref, &trailing);
13468 82824 : bool zero_elts = integer_zerop (memsize);
13469 82824 : if (zero_elts && integer_zerop (TYPE_SIZE_UNIT (TREE_TYPE (memtype))))
13470 : {
13471 : /* If array element has zero size, verify if it is a flexible
13472 : array member or zero length array. Clear zero_elts if
13473 : it has one or more members or is a VLA member. */
13474 6 : if (tree dom = TYPE_DOMAIN (memtype))
13475 6 : if (tree min = TYPE_MIN_VALUE (dom))
13476 6 : if (tree max = TYPE_MAX_VALUE (dom))
13477 4 : if (TREE_CODE (min) != INTEGER_CST
13478 4 : || TREE_CODE (max) != INTEGER_CST
13479 12 : || !((integer_zerop (min) && integer_all_onesp (max))
13480 4 : || tree_int_cst_lt (max, min)))
13481 : zero_elts = false;
13482 : }
13483 82824 : if (!trailing && !zero_elts)
13484 : /* MEMBER is an interior array with more than one element. */
13485 : return special_array_member::int_n;
13486 :
13487 23140 : if (zero_elts)
13488 : {
13489 1074 : if (trailing)
13490 : return special_array_member::trail_0;
13491 : else
13492 463 : return special_array_member::int_0;
13493 : }
13494 :
13495 22529 : if (!zero_elts)
13496 22529 : if (tree dom = TYPE_DOMAIN (memtype))
13497 22529 : if (tree min = TYPE_MIN_VALUE (dom))
13498 22529 : if (tree max = TYPE_MAX_VALUE (dom))
13499 22529 : if (TREE_CODE (min) == INTEGER_CST
13500 22529 : && TREE_CODE (max) == INTEGER_CST)
13501 : {
13502 22407 : offset_int minidx = wi::to_offset (min);
13503 22407 : offset_int maxidx = wi::to_offset (max);
13504 22407 : offset_int neltsm1 = maxidx - minidx;
13505 22407 : if (neltsm1 > 0)
13506 : /* MEMBER is a trailing array with more than
13507 : one elements. */
13508 22407 : return special_array_member::trail_n;
13509 :
13510 2182 : if (neltsm1 == 0)
13511 : return special_array_member::trail_1;
13512 : }
13513 : }
13514 :
13515 : return sam_type;
13516 : }
13517 :
13518 : /* Determines the size of the member referenced by the COMPONENT_REF
13519 : REF, using its initializer expression if necessary in order to
13520 : determine the size of an initialized flexible array member.
13521 : If non-null, set *SAM to the type of special array member.
13522 : Returns the size as sizetype (which might be zero for an object
13523 : with an uninitialized flexible array member) or null if the size
13524 : cannot be determined. */
13525 :
13526 : tree
13527 156426 : component_ref_size (tree ref, special_array_member *sam /* = NULL */)
13528 : {
13529 156426 : gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
13530 :
13531 156426 : special_array_member sambuf;
13532 156426 : if (!sam)
13533 100755 : sam = &sambuf;
13534 156426 : *sam = component_ref_sam_type (ref);
13535 :
13536 : /* The object/argument referenced by the COMPONENT_REF and its type. */
13537 156426 : tree arg = TREE_OPERAND (ref, 0);
13538 156426 : tree argtype = TREE_TYPE (arg);
13539 : /* The referenced member. */
13540 156426 : tree member = TREE_OPERAND (ref, 1);
13541 :
13542 156426 : tree memsize = DECL_SIZE_UNIT (member);
13543 156426 : if (memsize)
13544 : {
13545 88849 : tree memtype = TREE_TYPE (member);
13546 88849 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13547 : /* DECL_SIZE may be less than TYPE_SIZE in C++ when referring
13548 : to the type of a class with a virtual base which doesn't
13549 : reflect the size of the virtual's members (see pr97595).
13550 : If that's the case fail for now and implement something
13551 : more robust in the future. */
13552 40878 : return (tree_int_cst_equal (memsize, TYPE_SIZE_UNIT (memtype))
13553 40878 : ? memsize : NULL_TREE);
13554 :
13555 : /* 2-or-more elements arrays are treated as normal arrays by default. */
13556 47971 : if (*sam == special_array_member::int_n
13557 47971 : || *sam == special_array_member::trail_n)
13558 : return memsize;
13559 :
13560 1849 : tree afield_decl = TREE_OPERAND (ref, 1);
13561 1849 : gcc_assert (TREE_CODE (afield_decl) == FIELD_DECL);
13562 : /* If the trailing array is a not a flexible array member, treat it as
13563 : a normal array. */
13564 1849 : if (DECL_NOT_FLEXARRAY (afield_decl)
13565 1849 : && *sam != special_array_member::int_0)
13566 : return memsize;
13567 :
13568 1840 : if (*sam == special_array_member::int_0)
13569 270 : memsize = NULL_TREE;
13570 :
13571 : /* For a reference to a flexible array member of a union
13572 : use the size of the union instead of the size of the member. */
13573 1840 : if (TREE_CODE (argtype) == UNION_TYPE)
13574 277 : memsize = TYPE_SIZE_UNIT (argtype);
13575 : }
13576 :
13577 : /* MEMBER is either a bona fide flexible array member, or a zero-elements
13578 : array member, or an array of length one treated as such. */
13579 :
13580 : /* If the reference is to a declared object and the member a true
13581 : flexible array, try to determine its size from its initializer. */
13582 69417 : poly_int64 baseoff = 0;
13583 69417 : tree base = get_addr_base_and_unit_offset (ref, &baseoff);
13584 69417 : if (!base || !VAR_P (base))
13585 : {
13586 66069 : if (*sam != special_array_member::int_0)
13587 : return NULL_TREE;
13588 :
13589 52 : if (TREE_CODE (arg) != COMPONENT_REF)
13590 : return NULL_TREE;
13591 :
13592 : base = arg;
13593 6 : while (TREE_CODE (base) == COMPONENT_REF)
13594 3 : base = TREE_OPERAND (base, 0);
13595 3 : baseoff = tree_to_poly_int64 (byte_position (TREE_OPERAND (ref, 1)));
13596 : }
13597 :
13598 : /* BASE is the declared object of which MEMBER is either a member
13599 : or that is cast to ARGTYPE (e.g., a char buffer used to store
13600 : an ARGTYPE object). */
13601 3351 : tree basetype = TREE_TYPE (base);
13602 :
13603 : /* Determine the base type of the referenced object. If it's
13604 : the same as ARGTYPE and MEMBER has a known size, return it. */
13605 3351 : tree bt = basetype;
13606 3351 : if (*sam != special_array_member::int_0)
13607 3352 : while (TREE_CODE (bt) == ARRAY_TYPE)
13608 222 : bt = TREE_TYPE (bt);
13609 3351 : bool typematch = useless_type_conversion_p (argtype, bt);
13610 3351 : if (memsize && typematch)
13611 : return memsize;
13612 :
13613 3261 : memsize = NULL_TREE;
13614 :
13615 3261 : if (typematch)
13616 : /* MEMBER is a true flexible array member. Compute its size from
13617 : the initializer of the BASE object if it has one. */
13618 2697 : if (tree init = DECL_P (base) ? DECL_INITIAL (base) : NULL_TREE)
13619 1300 : if (init != error_mark_node)
13620 : {
13621 1267 : init = get_initializer_for (init, member);
13622 1267 : if (init)
13623 : {
13624 889 : memsize = TYPE_SIZE_UNIT (TREE_TYPE (init));
13625 889 : if (tree refsize = TYPE_SIZE_UNIT (argtype))
13626 : {
13627 : /* Use the larger of the initializer size and the tail
13628 : padding in the enclosing struct. */
13629 889 : poly_int64 rsz = tree_to_poly_int64 (refsize);
13630 889 : rsz -= baseoff;
13631 889 : if (known_lt (tree_to_poly_int64 (memsize), rsz))
13632 56 : memsize = wide_int_to_tree (TREE_TYPE (memsize), rsz);
13633 : }
13634 :
13635 889 : baseoff = 0;
13636 : }
13637 : }
13638 :
13639 889 : if (!memsize)
13640 : {
13641 2372 : if (typematch)
13642 : {
13643 1808 : if (DECL_P (base)
13644 1808 : && DECL_EXTERNAL (base)
13645 454 : && bt == basetype
13646 2256 : && *sam != special_array_member::int_0)
13647 : /* The size of a flexible array member of an extern struct
13648 : with no initializer cannot be determined (it's defined
13649 : in another translation unit and can have an initializer
13650 : with an arbitrary number of elements). */
13651 : return NULL_TREE;
13652 :
13653 : /* Use the size of the base struct or, for interior zero-length
13654 : arrays, the size of the enclosing type. */
13655 1383 : memsize = TYPE_SIZE_UNIT (bt);
13656 : }
13657 564 : else if (DECL_P (base))
13658 : /* Use the size of the BASE object (possibly an array of some
13659 : other type such as char used to store the struct). */
13660 561 : memsize = DECL_SIZE_UNIT (base);
13661 : else
13662 : return NULL_TREE;
13663 : }
13664 :
13665 : /* If the flexible array member has a known size use the greater
13666 : of it and the tail padding in the enclosing struct.
13667 : Otherwise, when the size of the flexible array member is unknown
13668 : and the referenced object is not a struct, use the size of its
13669 : type when known. This detects sizes of array buffers when cast
13670 : to struct types with flexible array members. */
13671 1944 : if (memsize)
13672 : {
13673 2808 : if (!tree_fits_poly_int64_p (memsize))
13674 : return NULL_TREE;
13675 2808 : poly_int64 memsz64 = memsize ? tree_to_poly_int64 (memsize) : 0;
13676 2808 : if (known_lt (baseoff, memsz64))
13677 : {
13678 1341 : memsz64 -= baseoff;
13679 1341 : return wide_int_to_tree (TREE_TYPE (memsize), memsz64);
13680 : }
13681 1467 : return size_zero_node;
13682 : }
13683 :
13684 : /* Return "don't know" for an external non-array object since its
13685 : flexible array member can be initialized to have any number of
13686 : elements. Otherwise, return zero because the flexible array
13687 : member has no elements. */
13688 25 : return (DECL_P (base)
13689 25 : && DECL_EXTERNAL (base)
13690 25 : && (!typematch
13691 0 : || TREE_CODE (basetype) != ARRAY_TYPE)
13692 25 : ? NULL_TREE : size_zero_node);
13693 : }
13694 :
13695 : /* Return true if the given node CALL is a call to a .ACCESS_WITH_SIZE
13696 : function. */
13697 : bool
13698 162981770 : is_access_with_size_p (const_tree call)
13699 : {
13700 162981770 : if (TREE_CODE (call) != CALL_EXPR)
13701 : return false;
13702 42087047 : if (CALL_EXPR_IFN (call) == IFN_ACCESS_WITH_SIZE)
13703 1073 : return true;
13704 : return false;
13705 : }
13706 :
13707 : /* Get the corresponding reference from the call to a .ACCESS_WITH_SIZE.
13708 : * i.e the first argument of this call. Return NULL_TREE otherwise. */
13709 : tree
13710 3 : get_ref_from_access_with_size (tree call)
13711 : {
13712 3 : if (is_access_with_size_p (call))
13713 3 : return CALL_EXPR_ARG (call, 0);
13714 : return NULL_TREE;
13715 : }
13716 :
13717 : /* Return the machine mode of T. For vectors, returns the mode of the
13718 : inner type. The main use case is to feed the result to HONOR_NANS,
13719 : avoiding the BLKmode that a direct TYPE_MODE (T) might return. */
13720 :
13721 : machine_mode
13722 5836111721 : element_mode (const_tree t)
13723 : {
13724 5836111721 : if (!TYPE_P (t))
13725 205605566 : t = TREE_TYPE (t);
13726 5836111721 : if (VECTOR_TYPE_P (t) || TREE_CODE (t) == COMPLEX_TYPE)
13727 1518558549 : t = TREE_TYPE (t);
13728 5836111721 : return TYPE_MODE (t);
13729 : }
13730 :
13731 : /* Vector types need to re-check the target flags each time we report
13732 : the machine mode. We need to do this because attribute target can
13733 : change the result of vector_mode_supported_p and have_regs_of_mode
13734 : on a per-function basis. Thus the TYPE_MODE of a VECTOR_TYPE can
13735 : change on a per-function basis. */
13736 : /* ??? Possibly a better solution is to run through all the types
13737 : referenced by a function and re-compute the TYPE_MODE once, rather
13738 : than make the TYPE_MODE macro call a function. */
13739 :
13740 : machine_mode
13741 1377637788 : vector_type_mode (const_tree t)
13742 : {
13743 1377637788 : machine_mode mode;
13744 :
13745 1377637788 : gcc_assert (TREE_CODE (t) == VECTOR_TYPE);
13746 :
13747 1377637788 : mode = t->type_common.mode;
13748 312331956 : if (VECTOR_MODE_P (mode)
13749 1650821880 : && (!targetm.vector_mode_supported_p (mode)
13750 1315907734 : || !have_regs_of_mode[mode]))
13751 : {
13752 23541822 : scalar_int_mode innermode;
13753 :
13754 : /* For integers, try mapping it to a same-sized scalar mode. */
13755 23541822 : if (is_int_mode (TREE_TYPE (t)->type_common.mode, &innermode))
13756 : {
13757 35135798 : poly_int64 size = (TYPE_VECTOR_SUBPARTS (t)
13758 17567899 : * GET_MODE_BITSIZE (innermode));
13759 17567899 : scalar_int_mode mode;
13760 31803502 : if (int_mode_for_size (size, 0).exists (&mode)
13761 14290237 : && have_regs_of_mode[mode])
13762 54634 : return mode;
13763 : }
13764 :
13765 23487188 : return BLKmode;
13766 : }
13767 :
13768 : return mode;
13769 : }
13770 :
13771 : /* Return the size in bits of each element of vector type TYPE. */
13772 :
13773 : unsigned int
13774 249512 : vector_element_bits (const_tree type)
13775 : {
13776 249512 : gcc_checking_assert (VECTOR_TYPE_P (type));
13777 249512 : if (VECTOR_BOOLEAN_TYPE_P (type))
13778 1265 : return TYPE_PRECISION (TREE_TYPE (type));
13779 248247 : return tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)));
13780 : }
13781 :
13782 : /* Calculate the size in bits of each element of vector type TYPE
13783 : and return the result as a tree of type bitsizetype. */
13784 :
13785 : tree
13786 115741 : vector_element_bits_tree (const_tree type)
13787 : {
13788 115741 : gcc_checking_assert (VECTOR_TYPE_P (type));
13789 115741 : if (VECTOR_BOOLEAN_TYPE_P (type))
13790 630 : return bitsize_int (vector_element_bits (type));
13791 115111 : return TYPE_SIZE (TREE_TYPE (type));
13792 : }
13793 :
13794 : /* Verify that basic properties of T match TV and thus T can be a variant of
13795 : TV. TV should be the more specified variant (i.e. the main variant). */
13796 :
13797 : static bool
13798 198236981 : verify_type_variant (const_tree t, tree tv)
13799 : {
13800 : /* Type variant can differ by:
13801 :
13802 : - TYPE_QUALS: TYPE_READONLY, TYPE_VOLATILE, TYPE_ATOMIC, TYPE_RESTRICT,
13803 : ENCODE_QUAL_ADDR_SPACE.
13804 : - main variant may be TYPE_COMPLETE_P and variant types !TYPE_COMPLETE_P
13805 : in this case some values may not be set in the variant types
13806 : (see TYPE_COMPLETE_P checks).
13807 : - it is possible to have TYPE_ARTIFICIAL variant of non-artificial type
13808 : - by TYPE_NAME and attributes (i.e. when variant originate by typedef)
13809 : - TYPE_CANONICAL (TYPE_ALIAS_SET is the same among variants)
13810 : - by the alignment: TYPE_ALIGN and TYPE_USER_ALIGN
13811 : - during LTO by TYPE_CONTEXT if type is TYPE_FILE_SCOPE_P
13812 : this is necessary to make it possible to merge types form different TUs
13813 : - arrays, pointers and references may have TREE_TYPE that is a variant
13814 : of TREE_TYPE of their main variants.
13815 : - aggregates may have new TYPE_FIELDS list that list variants of
13816 : the main variant TYPE_FIELDS.
13817 : - vector types may differ by TYPE_VECTOR_OPAQUE
13818 : */
13819 :
13820 : /* Convenience macro for matching individual fields. */
13821 : #define verify_variant_match(flag) \
13822 : do { \
13823 : if (flag (tv) != flag (t)) \
13824 : { \
13825 : error ("type variant differs by %s", #flag); \
13826 : debug_tree (tv); \
13827 : return false; \
13828 : } \
13829 : } while (false)
13830 :
13831 : /* tree_base checks. */
13832 :
13833 198236981 : verify_variant_match (TREE_CODE);
13834 : /* FIXME: Ada builds non-artificial variants of artificial types. */
13835 : #if 0
13836 : if (TYPE_ARTIFICIAL (tv))
13837 : verify_variant_match (TYPE_ARTIFICIAL);
13838 : #endif
13839 198236981 : if (POINTER_TYPE_P (tv))
13840 12940890 : verify_variant_match (TYPE_REF_CAN_ALIAS_ALL);
13841 : /* FIXME: TYPE_SIZES_GIMPLIFIED may differs for Ada build. */
13842 198236981 : verify_variant_match (TYPE_UNSIGNED);
13843 198236981 : verify_variant_match (TYPE_PACKED);
13844 198236981 : if (TREE_CODE (t) == REFERENCE_TYPE)
13845 3151748 : verify_variant_match (TYPE_REF_IS_RVALUE);
13846 198236981 : if (AGGREGATE_TYPE_P (t))
13847 81569542 : verify_variant_match (TYPE_REVERSE_STORAGE_ORDER);
13848 : else
13849 116667439 : verify_variant_match (TYPE_SATURATING);
13850 : /* FIXME: This check trigger during libstdc++ build. */
13851 : #if 0
13852 : if (RECORD_OR_UNION_TYPE_P (t) && COMPLETE_TYPE_P (t))
13853 : verify_variant_match (TYPE_FINAL_P);
13854 : #endif
13855 :
13856 : /* tree_type_common checks. */
13857 :
13858 198236981 : if (COMPLETE_TYPE_P (t))
13859 : {
13860 186359513 : verify_variant_match (TYPE_MODE);
13861 186359513 : if (TREE_CODE (TYPE_SIZE (t)) != PLACEHOLDER_EXPR
13862 186359513 : && TREE_CODE (TYPE_SIZE (tv)) != PLACEHOLDER_EXPR)
13863 186359513 : verify_variant_match (TYPE_SIZE);
13864 186359513 : if (TREE_CODE (TYPE_SIZE_UNIT (t)) != PLACEHOLDER_EXPR
13865 186359513 : && TREE_CODE (TYPE_SIZE_UNIT (tv)) != PLACEHOLDER_EXPR
13866 372719026 : && TYPE_SIZE_UNIT (t) != TYPE_SIZE_UNIT (tv))
13867 : {
13868 0 : gcc_assert (!operand_equal_p (TYPE_SIZE_UNIT (t),
13869 : TYPE_SIZE_UNIT (tv), 0));
13870 0 : error ("type variant has different %<TYPE_SIZE_UNIT%>");
13871 0 : debug_tree (tv);
13872 0 : error ("type variant%'s %<TYPE_SIZE_UNIT%>");
13873 0 : debug_tree (TYPE_SIZE_UNIT (tv));
13874 0 : error ("type%'s %<TYPE_SIZE_UNIT%>");
13875 0 : debug_tree (TYPE_SIZE_UNIT (t));
13876 0 : return false;
13877 : }
13878 186359513 : verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
13879 : }
13880 198236981 : verify_variant_match (TYPE_PRECISION_RAW);
13881 198236981 : if (RECORD_OR_UNION_TYPE_P (t))
13882 80949607 : verify_variant_match (TYPE_TRANSPARENT_AGGR);
13883 117287374 : else if (TREE_CODE (t) == ARRAY_TYPE)
13884 619935 : verify_variant_match (TYPE_NONALIASED_COMPONENT);
13885 : /* During LTO we merge variant lists from different translation units
13886 : that may differ BY TYPE_CONTEXT that in turn may point
13887 : to TRANSLATION_UNIT_DECL.
13888 : Ada also builds variants of types with different TYPE_CONTEXT. */
13889 : #if 0
13890 : if (!in_lto_p || !TYPE_FILE_SCOPE_P (t))
13891 : verify_variant_match (TYPE_CONTEXT);
13892 : #endif
13893 198236981 : if (TREE_CODE (t) == ARRAY_TYPE || TREE_CODE (t) == INTEGER_TYPE)
13894 63454981 : verify_variant_match (TYPE_STRING_FLAG);
13895 198236981 : if (TREE_CODE (t) == RECORD_TYPE || TREE_CODE (t) == UNION_TYPE)
13896 80949607 : verify_variant_match (TYPE_CXX_ODR_P);
13897 198236981 : if (TYPE_ALIAS_SET_KNOWN_P (t))
13898 : {
13899 0 : error ("type variant with %<TYPE_ALIAS_SET_KNOWN_P%>");
13900 0 : debug_tree (tv);
13901 0 : return false;
13902 : }
13903 :
13904 : /* tree_type_non_common checks. */
13905 :
13906 : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
13907 : and dangle the pointer from time to time. */
13908 80949607 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_VFIELD (t) != TYPE_VFIELD (tv)
13909 198236981 : && (in_lto_p || !TYPE_VFIELD (tv)
13910 0 : || TREE_CODE (TYPE_VFIELD (tv)) != TREE_LIST))
13911 : {
13912 0 : error ("type variant has different %<TYPE_VFIELD%>");
13913 0 : debug_tree (tv);
13914 0 : return false;
13915 : }
13916 3539217 : if ((TREE_CODE (t) == ENUMERAL_TYPE && COMPLETE_TYPE_P (t))
13917 194697821 : || TREE_CODE (t) == INTEGER_TYPE
13918 131862775 : || TREE_CODE (t) == BOOLEAN_TYPE
13919 97194948 : || TREE_CODE (t) == BITINT_TYPE
13920 97194784 : || SCALAR_FLOAT_TYPE_P (t)
13921 293496411 : || FIXED_POINT_TYPE_P (t))
13922 : {
13923 102977551 : verify_variant_match (TYPE_MAX_VALUE);
13924 102977551 : verify_variant_match (TYPE_MIN_VALUE);
13925 : }
13926 198236981 : if (TREE_CODE (t) == METHOD_TYPE)
13927 11701 : verify_variant_match (TYPE_METHOD_BASETYPE);
13928 198236981 : if (TREE_CODE (t) == OFFSET_TYPE)
13929 1607 : verify_variant_match (TYPE_OFFSET_BASETYPE);
13930 198236981 : if (TREE_CODE (t) == ARRAY_TYPE)
13931 619935 : verify_variant_match (TYPE_ARRAY_MAX_SIZE);
13932 : /* FIXME: Be lax and allow TYPE_BINFO to be missing in variant types
13933 : or even type's main variant. This is needed to make bootstrap pass
13934 : and the bug seems new in GCC 5.
13935 : C++ FE should be updated to make this consistent and we should check
13936 : that TYPE_BINFO is always NULL for !COMPLETE_TYPE_P and otherwise there
13937 : is a match with main variant.
13938 :
13939 : Also disable the check for Java for now because of parser hack that builds
13940 : first an dummy BINFO and then sometimes replace it by real BINFO in some
13941 : of the copies. */
13942 80949607 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t) && TYPE_BINFO (tv)
13943 68900026 : && TYPE_BINFO (t) != TYPE_BINFO (tv)
13944 : /* FIXME: Java sometimes keep dump TYPE_BINFOs on variant types.
13945 : Since there is no cheap way to tell C++/Java type w/o LTO, do checking
13946 : at LTO time only. */
13947 198236981 : && (in_lto_p && odr_type_p (t)))
13948 : {
13949 0 : error ("type variant has different %<TYPE_BINFO%>");
13950 0 : debug_tree (tv);
13951 0 : error ("type variant%'s %<TYPE_BINFO%>");
13952 0 : debug_tree (TYPE_BINFO (tv));
13953 0 : error ("type%'s %<TYPE_BINFO%>");
13954 0 : debug_tree (TYPE_BINFO (t));
13955 0 : return false;
13956 : }
13957 :
13958 : /* Check various uses of TYPE_VALUES_RAW. */
13959 198236981 : if (TREE_CODE (t) == ENUMERAL_TYPE
13960 198236981 : && TYPE_VALUES (t))
13961 3369618 : verify_variant_match (TYPE_VALUES);
13962 194867363 : else if (TREE_CODE (t) == ARRAY_TYPE)
13963 619935 : verify_variant_match (TYPE_DOMAIN);
13964 : /* Permit incomplete variants of complete type. While FEs may complete
13965 : all variants, this does not happen for C++ templates in all cases. */
13966 194247428 : else if (RECORD_OR_UNION_TYPE_P (t)
13967 80949607 : && COMPLETE_TYPE_P (t)
13968 263526735 : && TYPE_FIELDS (t) != TYPE_FIELDS (tv))
13969 : {
13970 4051 : tree f1, f2;
13971 :
13972 : /* Fortran builds qualified variants as new records with items of
13973 : qualified type. Verify that they looks same. */
13974 4051 : for (f1 = TYPE_FIELDS (t), f2 = TYPE_FIELDS (tv);
13975 12962 : f1 && f2;
13976 8911 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
13977 8911 : if (TREE_CODE (f1) != FIELD_DECL || TREE_CODE (f2) != FIELD_DECL
13978 8911 : || (TYPE_MAIN_VARIANT (TREE_TYPE (f1))
13979 8911 : != TYPE_MAIN_VARIANT (TREE_TYPE (f2))
13980 : /* FIXME: gfc_nonrestricted_type builds all types as variants
13981 : with exception of pointer types. It deeply copies the type
13982 : which means that we may end up with a variant type
13983 : referring non-variant pointer. We may change it to
13984 : produce types as variants, too, like
13985 : objc_get_protocol_qualified_type does. */
13986 29 : && !POINTER_TYPE_P (TREE_TYPE (f1)))
13987 8911 : || DECL_FIELD_OFFSET (f1) != DECL_FIELD_OFFSET (f2)
13988 17822 : || DECL_FIELD_BIT_OFFSET (f1) != DECL_FIELD_BIT_OFFSET (f2))
13989 : break;
13990 4051 : if (f1 || f2)
13991 : {
13992 0 : error ("type variant has different %<TYPE_FIELDS%>");
13993 0 : debug_tree (tv);
13994 0 : error ("first mismatch is field");
13995 0 : debug_tree (f1);
13996 0 : error ("and field");
13997 0 : debug_tree (f2);
13998 0 : return false;
13999 : }
14000 : }
14001 194243377 : else if (FUNC_OR_METHOD_TYPE_P (t))
14002 151225 : verify_variant_match (TYPE_ARG_TYPES);
14003 : /* For C++ the qualified variant of array type is really an array type
14004 : of qualified TREE_TYPE.
14005 : objc builds variants of pointer where pointer to type is a variant, too
14006 : in objc_get_protocol_qualified_type. */
14007 198236981 : if (TREE_TYPE (t) != TREE_TYPE (tv)
14008 198236981 : && ((TREE_CODE (t) != ARRAY_TYPE
14009 0 : && !POINTER_TYPE_P (t))
14010 534745 : || TYPE_MAIN_VARIANT (TREE_TYPE (t))
14011 534745 : != TYPE_MAIN_VARIANT (TREE_TYPE (tv))))
14012 : {
14013 0 : error ("type variant has different %<TREE_TYPE%>");
14014 0 : debug_tree (tv);
14015 0 : error ("type variant%'s %<TREE_TYPE%>");
14016 0 : debug_tree (TREE_TYPE (tv));
14017 0 : error ("type%'s %<TREE_TYPE%>");
14018 0 : debug_tree (TREE_TYPE (t));
14019 0 : return false;
14020 : }
14021 198236981 : if (type_with_alias_set_p (t)
14022 198236981 : && !gimple_canonical_types_compatible_p (t, tv, false))
14023 : {
14024 0 : error ("type is not compatible with its variant");
14025 0 : debug_tree (tv);
14026 0 : error ("type variant%'s %<TREE_TYPE%>");
14027 0 : debug_tree (TREE_TYPE (tv));
14028 0 : error ("type%'s %<TREE_TYPE%>");
14029 0 : debug_tree (TREE_TYPE (t));
14030 0 : return false;
14031 : }
14032 : return true;
14033 : #undef verify_variant_match
14034 : }
14035 :
14036 :
14037 : /* The TYPE_CANONICAL merging machinery. It should closely resemble
14038 : the middle-end types_compatible_p function. It needs to avoid
14039 : claiming types are different for types that should be treated
14040 : the same with respect to TBAA. Canonical types are also used
14041 : for IL consistency checks via the useless_type_conversion_p
14042 : predicate which does not handle all type kinds itself but falls
14043 : back to pointer-comparison of TYPE_CANONICAL for aggregates
14044 : for example. */
14045 :
14046 : /* Return true if TYPE_UNSIGNED of TYPE should be ignored for canonical
14047 : type calculation because we need to allow inter-operability between signed
14048 : and unsigned variants. */
14049 :
14050 : bool
14051 1652332 : type_with_interoperable_signedness (const_tree type)
14052 : {
14053 : /* Fortran standard require C_SIGNED_CHAR to be interoperable with both
14054 : signed char and unsigned char. Similarly fortran FE builds
14055 : C_SIZE_T as signed type, while C defines it unsigned. */
14056 :
14057 1652332 : return tree_code_for_canonical_type_merging (TREE_CODE (type))
14058 : == INTEGER_TYPE
14059 1652128 : && (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node)
14060 446928 : || TYPE_PRECISION (type) == TYPE_PRECISION (size_type_node));
14061 : }
14062 :
14063 : /* Return true iff T1 and T2 are structurally identical for what
14064 : TBAA is concerned.
14065 : This function is used both by lto.cc canonical type merging and by the
14066 : verifier. If TRUST_TYPE_CANONICAL we do not look into structure of types
14067 : that have TYPE_CANONICAL defined and assume them equivalent. This is useful
14068 : only for LTO because only in these cases TYPE_CANONICAL equivalence
14069 : correspond to one defined by gimple_canonical_types_compatible_p. */
14070 :
14071 : bool
14072 405957668 : gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
14073 : bool trust_type_canonical)
14074 : {
14075 : /* Type variants should be same as the main variant. When not doing sanity
14076 : checking to verify this fact, go to main variants and save some work. */
14077 405957668 : if (trust_type_canonical)
14078 : {
14079 884383 : t1 = TYPE_MAIN_VARIANT (t1);
14080 884383 : t2 = TYPE_MAIN_VARIANT (t2);
14081 : }
14082 :
14083 : /* Check first for the obvious case of pointer identity. */
14084 405957668 : if (t1 == t2)
14085 : return true;
14086 :
14087 : /* Check that we have two types to compare. */
14088 343411572 : if (t1 == NULL_TREE || t2 == NULL_TREE)
14089 : return false;
14090 :
14091 : /* We consider complete types always compatible with incomplete type.
14092 : This does not make sense for canonical type calculation and thus we
14093 : need to ensure that we are never called on it.
14094 :
14095 : FIXME: For more correctness the function probably should have three modes
14096 : 1) mode assuming that types are complete matching their structure
14097 : 2) mode allowing incomplete types but producing equivalence classes
14098 : and thus ignoring all info from complete types
14099 : 3) mode allowing incomplete types to match complete but checking
14100 : compatibility between complete types.
14101 :
14102 : 1 and 2 can be used for canonical type calculation. 3 is the real
14103 : definition of type compatibility that can be used i.e. for warnings during
14104 : declaration merging. */
14105 :
14106 343411572 : gcc_assert (!trust_type_canonical
14107 : || (type_with_alias_set_p (t1) && type_with_alias_set_p (t2)));
14108 :
14109 : /* If the types have been previously registered and found equal
14110 : they still are. */
14111 :
14112 686527145 : if (TYPE_CANONICAL (t1) && TYPE_CANONICAL (t2)
14113 685591224 : && trust_type_canonical)
14114 : {
14115 : /* Do not use TYPE_CANONICAL of pointer types. For LTO streamed types
14116 : they are always NULL, but they are set to non-NULL for types
14117 : constructed by build_pointer_type and variants. In this case the
14118 : TYPE_CANONICAL is more fine grained than the equivalnce we test (where
14119 : all pointers are considered equal. Be sure to not return false
14120 : negatives. */
14121 163064 : gcc_checking_assert (canonical_type_used_p (t1)
14122 : && canonical_type_used_p (t2));
14123 81532 : return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
14124 : }
14125 :
14126 : /* For types where we do ODR based TBAA the canonical type is always
14127 : set correctly, so we know that types are different if their
14128 : canonical types does not match. */
14129 343330040 : if (trust_type_canonical
14130 344129856 : && (odr_type_p (t1) && odr_based_tbaa_p (t1))
14131 799816 : != (odr_type_p (t2) && odr_based_tbaa_p (t2)))
14132 : return false;
14133 :
14134 : /* Can't be the same type if the types don't have the same code. */
14135 343330040 : enum tree_code code = tree_code_for_canonical_type_merging (TREE_CODE (t1));
14136 682421560 : if (code != tree_code_for_canonical_type_merging (TREE_CODE (t2)))
14137 : return false;
14138 :
14139 : /* Qualifiers do not matter for canonical type comparison purposes. */
14140 :
14141 : /* Void types and nullptr types are always the same. */
14142 343330005 : if (VOID_TYPE_P (t1)
14143 343281643 : || TREE_CODE (t1) == NULLPTR_TYPE)
14144 : return true;
14145 :
14146 : /* Can't be compatible types if they have different mode. Because of
14147 : flexible array members, we allow mismatching modes for structures or
14148 : unions. */
14149 342621998 : if (!RECORD_OR_UNION_TYPE_P (t1)
14150 342621998 : && TREE_CODE (t1) != ARRAY_TYPE
14151 342621998 : && TYPE_MODE (t1) != TYPE_MODE (t2))
14152 : return false;
14153 :
14154 : /* Non-aggregate types can be handled cheaply. */
14155 342621998 : if (INTEGRAL_TYPE_P (t1)
14156 342621998 : || SCALAR_FLOAT_TYPE_P (t1)
14157 181426027 : || FIXED_POINT_TYPE_P (t1)
14158 181059619 : || VECTOR_TYPE_P (t1)
14159 181009480 : || TREE_CODE (t1) == COMPLEX_TYPE
14160 180664350 : || TREE_CODE (t1) == OFFSET_TYPE
14161 180661114 : || POINTER_TYPE_P (t1))
14162 : {
14163 : /* Can't be the same type if they have different precision. */
14164 205125583 : if (TYPE_PRECISION_RAW (t1) != TYPE_PRECISION_RAW (t2))
14165 : return false;
14166 :
14167 : /* In some cases the signed and unsigned types are required to be
14168 : inter-operable. */
14169 205125583 : if (TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)
14170 205125583 : && !type_with_interoperable_signedness (t1))
14171 : return false;
14172 :
14173 : /* Fortran's C_SIGNED_CHAR is !TYPE_STRING_FLAG but needs to be
14174 : interoperable with "signed char". Unless all frontends are revisited
14175 : to agree on these types, we must ignore the flag completely. */
14176 :
14177 : /* Fortran standard define C_PTR type that is compatible with every
14178 : C pointer. For this reason we need to glob all pointers into one.
14179 : Still pointers in different address spaces are not compatible. */
14180 205125583 : if (POINTER_TYPE_P (t1))
14181 : {
14182 43164699 : if (TYPE_ADDR_SPACE (TREE_TYPE (t1))
14183 43164699 : != TYPE_ADDR_SPACE (TREE_TYPE (t2)))
14184 : return false;
14185 : }
14186 :
14187 : /* Tail-recurse to components. */
14188 205125583 : if (VECTOR_TYPE_P (t1)
14189 205125583 : || TREE_CODE (t1) == COMPLEX_TYPE)
14190 395269 : return gimple_canonical_types_compatible_p (TREE_TYPE (t1),
14191 395269 : TREE_TYPE (t2),
14192 395269 : trust_type_canonical);
14193 :
14194 : return true;
14195 : }
14196 :
14197 : /* Do type-specific comparisons. */
14198 137496415 : switch (TREE_CODE (t1))
14199 : {
14200 1117862 : case ARRAY_TYPE:
14201 : /* Array types are the same if the element types are the same and
14202 : minimum and maximum index are the same. */
14203 1117862 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14204 : trust_type_canonical)
14205 1117823 : || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
14206 1117823 : || TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2)
14207 2235685 : || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
14208 : return false;
14209 : else
14210 : {
14211 1117823 : tree i1 = TYPE_DOMAIN (t1);
14212 1117823 : tree i2 = TYPE_DOMAIN (t2);
14213 :
14214 : /* For an incomplete external array, the type domain can be
14215 : NULL_TREE. Check this condition also. */
14216 1117823 : if (i1 == NULL_TREE && i2 == NULL_TREE)
14217 : return true;
14218 1018388 : else if (i1 == NULL_TREE || i2 == NULL_TREE)
14219 : return false;
14220 : else
14221 : {
14222 1018388 : tree min1 = TYPE_MIN_VALUE (i1);
14223 1018388 : tree min2 = TYPE_MIN_VALUE (i2);
14224 1018388 : tree max1 = TYPE_MAX_VALUE (i1);
14225 1018388 : tree max2 = TYPE_MAX_VALUE (i2);
14226 :
14227 : /* The minimum/maximum values have to be the same. */
14228 1018388 : if ((min1 == min2
14229 0 : || (min1 && min2
14230 0 : && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
14231 0 : && TREE_CODE (min2) == PLACEHOLDER_EXPR)
14232 0 : || operand_equal_p (min1, min2, 0))))
14233 1018388 : && (max1 == max2
14234 0 : || (max1 && max2
14235 0 : && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
14236 0 : && TREE_CODE (max2) == PLACEHOLDER_EXPR)
14237 0 : || operand_equal_p (max1, max2, 0)))))
14238 1018388 : return true;
14239 : else
14240 0 : return false;
14241 : }
14242 : }
14243 :
14244 7039 : case METHOD_TYPE:
14245 7039 : case FUNCTION_TYPE:
14246 : /* Function types are the same if the return type and arguments types
14247 : are the same. */
14248 7039 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14249 : trust_type_canonical))
14250 : return false;
14251 :
14252 7039 : if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2)
14253 7039 : && (TYPE_NO_NAMED_ARGS_STDARG_P (t1)
14254 322 : == TYPE_NO_NAMED_ARGS_STDARG_P (t2)))
14255 : return true;
14256 : else
14257 : {
14258 6717 : tree parms1, parms2;
14259 :
14260 6717 : for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
14261 29927 : parms1 && parms2;
14262 23210 : parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
14263 : {
14264 23210 : if (!gimple_canonical_types_compatible_p
14265 23210 : (TREE_VALUE (parms1), TREE_VALUE (parms2),
14266 : trust_type_canonical))
14267 : return false;
14268 : }
14269 :
14270 6717 : if (parms1 || parms2)
14271 : return false;
14272 :
14273 : return true;
14274 : }
14275 :
14276 136028988 : case RECORD_TYPE:
14277 136028988 : case UNION_TYPE:
14278 136028988 : case QUAL_UNION_TYPE:
14279 136028988 : {
14280 136028988 : tree f1, f2;
14281 :
14282 : /* Don't try to compare variants of an incomplete type, before
14283 : TYPE_FIELDS has been copied around. */
14284 136028988 : if (!COMPLETE_TYPE_P (t1) && !COMPLETE_TYPE_P (t2))
14285 : return true;
14286 :
14287 :
14288 125054484 : if (TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2))
14289 : return false;
14290 :
14291 : /* For aggregate types, all the fields must be the same. */
14292 125054484 : for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
14293 187312845 : f1 || f2;
14294 62258361 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
14295 : {
14296 : /* Skip non-fields and zero-sized fields, except zero-sized
14297 : arrays at the end. */
14298 1884172272 : while (f1 && (TREE_CODE (f1) != FIELD_DECL
14299 114254002 : || (DECL_SIZE (f1)
14300 114236664 : && integer_zerop (DECL_SIZE (f1))
14301 51995618 : && (TREE_CHAIN (f1)
14302 3509 : || TREE_CODE (TREE_TYPE (f1))
14303 : != ARRAY_TYPE))))
14304 1697984878 : f1 = TREE_CHAIN (f1);
14305 1884173834 : while (f2 && (TREE_CODE (f2) != FIELD_DECL
14306 114269075 : || (DECL_SIZE (f2)
14307 114251629 : && integer_zerop (DECL_SIZE (f2))
14308 51997187 : && (TREE_CHAIN (f2)
14309 4570 : || TREE_CODE (TREE_TYPE (f2))
14310 : != ARRAY_TYPE))))
14311 1697986440 : f2 = TREE_CHAIN (f2);
14312 186187394 : if (!f1 || !f2)
14313 : break;
14314 :
14315 62259156 : tree t1 = TREE_TYPE (f1);
14316 62259156 : tree t2 = TREE_TYPE (f2);
14317 :
14318 : /* If the last element are arrays, we only compare the element
14319 : types. */
14320 63375092 : if (TREE_CHAIN (f1) == NULL_TREE && TREE_CODE (t1) == ARRAY_TYPE
14321 62346183 : && TREE_CHAIN (f2) == NULL_TREE && TREE_CODE (t2) == ARRAY_TYPE)
14322 : {
14323 : /* If both arrays have zero size, this is a match. */
14324 157124 : if (DECL_SIZE (f1) && integer_zerop (DECL_SIZE (f1))
14325 87794 : && DECL_SIZE (f2) && integer_zerop (DECL_SIZE (f2)))
14326 : return true;
14327 :
14328 86251 : t1 = TREE_TYPE (t1);
14329 86251 : t2 = TREE_TYPE (t2);
14330 : }
14331 :
14332 62258385 : if (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
14333 62258380 : || !gimple_compare_field_offset (f1, f2)
14334 124516765 : || !gimple_canonical_types_compatible_p
14335 62258380 : (t1, t2, trust_type_canonical))
14336 24 : return false;
14337 : }
14338 :
14339 : /* If one aggregate has more fields than the other, they
14340 : are not the same. */
14341 125053689 : if (f1 || f2)
14342 : return false;
14343 :
14344 : return true;
14345 : }
14346 :
14347 342526 : default:
14348 : /* Consider all types with language specific trees in them mutually
14349 : compatible. This is executed only from verify_type and false
14350 : positives can be tolerated. */
14351 342526 : gcc_assert (!in_lto_p);
14352 : return true;
14353 : }
14354 : }
14355 :
14356 : /* For OPAQUE_TYPE T, it should have only size and alignment information
14357 : and its mode should be of class MODE_OPAQUE. This function verifies
14358 : these properties of T match TV which is the main variant of T and TC
14359 : which is the canonical of T. */
14360 :
14361 : static void
14362 0 : verify_opaque_type (const_tree t, tree tv, tree tc)
14363 : {
14364 0 : gcc_assert (OPAQUE_TYPE_P (t));
14365 0 : gcc_assert (tv && tv == TYPE_MAIN_VARIANT (tv));
14366 0 : gcc_assert (tc && tc == TYPE_CANONICAL (tc));
14367 :
14368 : /* For an opaque type T1, check if some of its properties match
14369 : the corresponding ones of the other opaque type T2, emit some
14370 : error messages for those inconsistent ones. */
14371 0 : auto check_properties_for_opaque_type = [](const_tree t1, tree t2,
14372 : const char *kind_msg)
14373 : {
14374 0 : if (!OPAQUE_TYPE_P (t2))
14375 : {
14376 0 : error ("type %s is not an opaque type", kind_msg);
14377 0 : debug_tree (t2);
14378 0 : return;
14379 : }
14380 0 : if (!OPAQUE_MODE_P (TYPE_MODE (t2)))
14381 : {
14382 0 : error ("type %s is not with opaque mode", kind_msg);
14383 0 : debug_tree (t2);
14384 0 : return;
14385 : }
14386 0 : if (TYPE_MODE (t1) != TYPE_MODE (t2))
14387 : {
14388 0 : error ("type %s differs by %<TYPE_MODE%>", kind_msg);
14389 0 : debug_tree (t2);
14390 0 : return;
14391 : }
14392 0 : poly_uint64 t1_size = tree_to_poly_uint64 (TYPE_SIZE (t1));
14393 0 : poly_uint64 t2_size = tree_to_poly_uint64 (TYPE_SIZE (t2));
14394 0 : if (maybe_ne (t1_size, t2_size))
14395 : {
14396 0 : error ("type %s differs by %<TYPE_SIZE%>", kind_msg);
14397 0 : debug_tree (t2);
14398 0 : return;
14399 : }
14400 0 : if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2))
14401 : {
14402 0 : error ("type %s differs by %<TYPE_ALIGN%>", kind_msg);
14403 0 : debug_tree (t2);
14404 0 : return;
14405 : }
14406 0 : if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
14407 : {
14408 0 : error ("type %s differs by %<TYPE_USER_ALIGN%>", kind_msg);
14409 0 : debug_tree (t2);
14410 0 : return;
14411 : }
14412 : };
14413 :
14414 0 : if (t != tv)
14415 0 : check_properties_for_opaque_type (t, tv, "variant");
14416 :
14417 0 : if (t != tc)
14418 0 : check_properties_for_opaque_type (t, tc, "canonical");
14419 0 : }
14420 :
14421 : /* Verify type T. */
14422 :
14423 : void
14424 916754716 : verify_type (const_tree t)
14425 : {
14426 916754716 : bool error_found = false;
14427 916754716 : tree mv = TYPE_MAIN_VARIANT (t);
14428 916754716 : tree ct = TYPE_CANONICAL (t);
14429 :
14430 916754716 : if (OPAQUE_TYPE_P (t))
14431 : {
14432 0 : verify_opaque_type (t, mv, ct);
14433 0 : return;
14434 : }
14435 :
14436 916754716 : if (!mv)
14437 : {
14438 0 : error ("main variant is not defined");
14439 0 : error_found = true;
14440 : }
14441 916754716 : else if (mv != TYPE_MAIN_VARIANT (mv))
14442 : {
14443 0 : error ("%<TYPE_MAIN_VARIANT%> has different %<TYPE_MAIN_VARIANT%>");
14444 0 : debug_tree (mv);
14445 0 : error_found = true;
14446 : }
14447 916754716 : else if (t != mv && !verify_type_variant (t, mv))
14448 : error_found = true;
14449 :
14450 916754716 : if (!ct)
14451 : ;
14452 914724224 : else if (TYPE_CANONICAL (ct) != ct)
14453 : {
14454 0 : error ("%<TYPE_CANONICAL%> has different %<TYPE_CANONICAL%>");
14455 0 : debug_tree (ct);
14456 0 : error_found = true;
14457 : }
14458 : /* Method and function types cannot be used to address memory and thus
14459 : TYPE_CANONICAL really matters only for determining useless conversions.
14460 :
14461 : FIXME: C++ FE produce declarations of builtin functions that are not
14462 : compatible with main variants. */
14463 914724224 : else if (TREE_CODE (t) == FUNCTION_TYPE)
14464 : ;
14465 914090857 : else if (t != ct
14466 : /* FIXME: gimple_canonical_types_compatible_p cannot compare types
14467 : with variably sized arrays because their sizes possibly
14468 : gimplified to different variables. */
14469 155057144 : && !variably_modified_type_p (ct, NULL)
14470 155052632 : && !gimple_canonical_types_compatible_p (t, ct, false)
14471 914104368 : && COMPLETE_TYPE_P (t))
14472 : {
14473 0 : error ("%<TYPE_CANONICAL%> is not compatible");
14474 0 : debug_tree (ct);
14475 0 : error_found = true;
14476 : }
14477 1657236924 : if (COMPLETE_TYPE_P (t) && TYPE_CANONICAL (t)
14478 : /* We allow a mismatch for structure or union because of
14479 : flexible array members. */
14480 738522502 : && !RECORD_OR_UNION_TYPE_P (t)
14481 304719710 : && !RECORD_OR_UNION_TYPE_P (TYPE_CANONICAL (t))
14482 304719710 : && TREE_CODE (t) != ARRAY_TYPE
14483 1219970021 : && TYPE_MODE (t) != TYPE_MODE (TYPE_CANONICAL (t)))
14484 : {
14485 0 : error ("%<TYPE_MODE%> of %<TYPE_CANONICAL%> is not compatible");
14486 0 : debug_tree (ct);
14487 0 : error_found = true;
14488 : }
14489 916754716 : if (TYPE_MAIN_VARIANT (t) == t && ct && TYPE_MAIN_VARIANT (ct) != ct)
14490 : {
14491 : /* This can happen when build_type_attribute_variant is called on
14492 : C/C++ arrays of qualified types. volatile int[2] is unqualified
14493 : ARRAY_TYPE with volatile int element type.
14494 : TYPE_CANONICAL (volatile int) is itself and so is
14495 : TYPE_CANONICAL (volatile int[2]). build_type_attribute_qual_variant
14496 : creates a distinct type copy (so TYPE_MAIN_VARIANT is itself) and sets
14497 : its TYPE_CANONICAL to the unqualified ARRAY_TYPE (so volatile int[2]).
14498 : But this is not the TYPE_MAIN_VARIANT, which is int[2]. So, just
14499 : verify that TYPE_MAIN_VARIANT (ct) is already the final type we
14500 : need. */
14501 2 : tree mvc = TYPE_MAIN_VARIANT (ct);
14502 2 : if (TYPE_CANONICAL (mvc) != mvc)
14503 : {
14504 0 : error ("main variant of %<TYPE_CANONICAL%> of main variant is not"
14505 : " its own %<TYPE_CANONICAL%>");
14506 0 : debug_tree (ct);
14507 0 : debug_tree (TYPE_MAIN_VARIANT (ct));
14508 0 : error_found = true;
14509 : }
14510 : }
14511 :
14512 :
14513 : /* Check various uses of TYPE_MIN_VALUE_RAW. */
14514 916754716 : if (RECORD_OR_UNION_TYPE_P (t))
14515 : {
14516 : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
14517 : and danagle the pointer from time to time. */
14518 482045256 : if (TYPE_VFIELD (t)
14519 12324624 : && TREE_CODE (TYPE_VFIELD (t)) != FIELD_DECL
14520 482045256 : && TREE_CODE (TYPE_VFIELD (t)) != TREE_LIST)
14521 : {
14522 0 : error ("%<TYPE_VFIELD%> is not %<FIELD_DECL%> nor %<TREE_LIST%>");
14523 0 : debug_tree (TYPE_VFIELD (t));
14524 0 : error_found = true;
14525 : }
14526 : }
14527 434709460 : else if (TREE_CODE (t) == POINTER_TYPE)
14528 : {
14529 111700583 : if (TYPE_NEXT_PTR_TO (t)
14530 111700583 : && TREE_CODE (TYPE_NEXT_PTR_TO (t)) != POINTER_TYPE)
14531 : {
14532 0 : error ("%<TYPE_NEXT_PTR_TO%> is not %<POINTER_TYPE%>");
14533 0 : debug_tree (TYPE_NEXT_PTR_TO (t));
14534 0 : error_found = true;
14535 : }
14536 : }
14537 323008877 : else if (TREE_CODE (t) == REFERENCE_TYPE)
14538 : {
14539 50948760 : if (TYPE_NEXT_REF_TO (t)
14540 50948760 : && TREE_CODE (TYPE_NEXT_REF_TO (t)) != REFERENCE_TYPE)
14541 : {
14542 0 : error ("%<TYPE_NEXT_REF_TO%> is not %<REFERENCE_TYPE%>");
14543 0 : debug_tree (TYPE_NEXT_REF_TO (t));
14544 0 : error_found = true;
14545 : }
14546 : }
14547 : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14548 : || FIXED_POINT_TYPE_P (t))
14549 : {
14550 : /* FIXME: The following check should pass:
14551 : useless_type_conversion_p (const_cast <tree> (t),
14552 : TREE_TYPE (TYPE_MIN_VALUE (t))
14553 : but does not for C sizetypes in LTO. */
14554 : }
14555 :
14556 : /* Check various uses of TYPE_MAXVAL_RAW. */
14557 916754716 : if (RECORD_OR_UNION_TYPE_P (t))
14558 : {
14559 482045256 : if (!TYPE_BINFO (t))
14560 : ;
14561 453352107 : else if (TREE_CODE (TYPE_BINFO (t)) != TREE_BINFO)
14562 : {
14563 0 : error ("%<TYPE_BINFO%> is not %<TREE_BINFO%>");
14564 0 : debug_tree (TYPE_BINFO (t));
14565 0 : error_found = true;
14566 : }
14567 453352107 : else if (TREE_TYPE (TYPE_BINFO (t)) != TYPE_MAIN_VARIANT (t))
14568 : {
14569 0 : error ("%<TYPE_BINFO%> type is not %<TYPE_MAIN_VARIANT%>");
14570 0 : debug_tree (TREE_TYPE (TYPE_BINFO (t)));
14571 0 : error_found = true;
14572 : }
14573 : }
14574 : else if (FUNC_OR_METHOD_TYPE_P (t))
14575 : {
14576 854865 : if (TYPE_METHOD_BASETYPE (t)
14577 69530 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != RECORD_TYPE
14578 855063 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != UNION_TYPE)
14579 : {
14580 0 : error ("%<TYPE_METHOD_BASETYPE%> is not record nor union");
14581 0 : debug_tree (TYPE_METHOD_BASETYPE (t));
14582 0 : error_found = true;
14583 : }
14584 : }
14585 : else if (TREE_CODE (t) == OFFSET_TYPE)
14586 : {
14587 35262 : if (TYPE_OFFSET_BASETYPE (t)
14588 35262 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != RECORD_TYPE
14589 35270 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != UNION_TYPE)
14590 : {
14591 0 : error ("%<TYPE_OFFSET_BASETYPE%> is not record nor union");
14592 0 : debug_tree (TYPE_OFFSET_BASETYPE (t));
14593 0 : error_found = true;
14594 : }
14595 : }
14596 : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14597 : || FIXED_POINT_TYPE_P (t))
14598 : {
14599 : /* FIXME: The following check should pass:
14600 : useless_type_conversion_p (const_cast <tree> (t),
14601 : TREE_TYPE (TYPE_MAX_VALUE (t))
14602 : but does not for C sizetypes in LTO. */
14603 : }
14604 : else if (TREE_CODE (t) == ARRAY_TYPE)
14605 : {
14606 1777816 : if (TYPE_ARRAY_MAX_SIZE (t)
14607 1777816 : && TREE_CODE (TYPE_ARRAY_MAX_SIZE (t)) != INTEGER_CST)
14608 : {
14609 0 : error ("%<TYPE_ARRAY_MAX_SIZE%> not %<INTEGER_CST%>");
14610 0 : debug_tree (TYPE_ARRAY_MAX_SIZE (t));
14611 0 : error_found = true;
14612 : }
14613 : }
14614 291937781 : else if (TYPE_MAX_VALUE_RAW (t))
14615 : {
14616 0 : error ("%<TYPE_MAX_VALUE_RAW%> non-NULL");
14617 0 : debug_tree (TYPE_MAX_VALUE_RAW (t));
14618 0 : error_found = true;
14619 : }
14620 :
14621 916754716 : if (TYPE_LANG_SLOT_1 (t) && in_lto_p)
14622 : {
14623 0 : error ("%<TYPE_LANG_SLOT_1 (binfo)%> field is non-NULL");
14624 0 : debug_tree (TYPE_LANG_SLOT_1 (t));
14625 0 : error_found = true;
14626 : }
14627 :
14628 : /* Check various uses of TYPE_VALUES_RAW. */
14629 916754716 : if (TREE_CODE (t) == ENUMERAL_TYPE)
14630 103020282 : for (tree l = TYPE_VALUES (t); l; l = TREE_CHAIN (l))
14631 : {
14632 89529493 : tree value = TREE_VALUE (l);
14633 89529493 : tree name = TREE_PURPOSE (l);
14634 :
14635 : /* C FE porduce INTEGER_CST of INTEGER_TYPE, while C++ FE uses
14636 : CONST_DECL of ENUMERAL TYPE. */
14637 89529493 : if (TREE_CODE (value) != INTEGER_CST && TREE_CODE (value) != CONST_DECL)
14638 : {
14639 0 : error ("enum value is not %<CONST_DECL%> or %<INTEGER_CST%>");
14640 0 : debug_tree (value);
14641 0 : debug_tree (name);
14642 0 : error_found = true;
14643 : }
14644 89529493 : if (TREE_CODE (TREE_TYPE (value)) != INTEGER_TYPE
14645 89511813 : && TREE_CODE (TREE_TYPE (value)) != BOOLEAN_TYPE
14646 179041303 : && !useless_type_conversion_p (const_cast <tree> (t), TREE_TYPE (value)))
14647 : {
14648 0 : error ("enum value type is not %<INTEGER_TYPE%> nor convertible "
14649 : "to the enum");
14650 0 : debug_tree (value);
14651 0 : debug_tree (name);
14652 0 : error_found = true;
14653 : }
14654 89529493 : if (TREE_CODE (name) != IDENTIFIER_NODE)
14655 : {
14656 0 : error ("enum value name is not %<IDENTIFIER_NODE%>");
14657 0 : debug_tree (value);
14658 0 : debug_tree (name);
14659 0 : error_found = true;
14660 : }
14661 : }
14662 903263927 : else if (TREE_CODE (t) == ARRAY_TYPE)
14663 : {
14664 1777816 : if (TYPE_DOMAIN (t) && TREE_CODE (TYPE_DOMAIN (t)) != INTEGER_TYPE)
14665 : {
14666 0 : error ("array %<TYPE_DOMAIN%> is not integer type");
14667 0 : debug_tree (TYPE_DOMAIN (t));
14668 0 : error_found = true;
14669 : }
14670 : }
14671 901486111 : else if (RECORD_OR_UNION_TYPE_P (t))
14672 : {
14673 482045256 : if (TYPE_FIELDS (t) && !COMPLETE_TYPE_P (t) && in_lto_p)
14674 : {
14675 0 : error ("%<TYPE_FIELDS%> defined in incomplete type");
14676 0 : error_found = true;
14677 : }
14678 20855565424 : for (tree fld = TYPE_FIELDS (t); fld; fld = TREE_CHAIN (fld))
14679 : {
14680 : /* TODO: verify properties of decls. */
14681 20373520168 : if (TREE_CODE (fld) == FIELD_DECL)
14682 : ;
14683 : else if (TREE_CODE (fld) == TYPE_DECL)
14684 : ;
14685 : else if (TREE_CODE (fld) == CONST_DECL)
14686 : ;
14687 : else if (VAR_P (fld))
14688 : ;
14689 : else if (TREE_CODE (fld) == TEMPLATE_DECL)
14690 : ;
14691 : else if (TREE_CODE (fld) == USING_DECL)
14692 : ;
14693 : else if (TREE_CODE (fld) == FUNCTION_DECL)
14694 : ;
14695 : else
14696 : {
14697 0 : error ("wrong tree in %<TYPE_FIELDS%> list");
14698 0 : debug_tree (fld);
14699 0 : error_found = true;
14700 : }
14701 : }
14702 : }
14703 419440855 : else if (TREE_CODE (t) == INTEGER_TYPE
14704 : || TREE_CODE (t) == BOOLEAN_TYPE
14705 419440855 : || TREE_CODE (t) == BITINT_TYPE
14706 298124295 : || TREE_CODE (t) == OFFSET_TYPE
14707 298089033 : || TREE_CODE (t) == REFERENCE_TYPE
14708 247140273 : || TREE_CODE (t) == NULLPTR_TYPE
14709 246794591 : || TREE_CODE (t) == POINTER_TYPE)
14710 : {
14711 284346847 : if (TYPE_CACHED_VALUES_P (t) != (TYPE_CACHED_VALUES (t) != NULL))
14712 : {
14713 0 : error ("%<TYPE_CACHED_VALUES_P%> is %i while %<TYPE_CACHED_VALUES%> "
14714 : "is %p",
14715 0 : TYPE_CACHED_VALUES_P (t), (void *)TYPE_CACHED_VALUES (t));
14716 0 : error_found = true;
14717 : }
14718 284346847 : else if (TYPE_CACHED_VALUES_P (t) && TREE_CODE (TYPE_CACHED_VALUES (t)) != TREE_VEC)
14719 : {
14720 0 : error ("%<TYPE_CACHED_VALUES%> is not %<TREE_VEC%>");
14721 0 : debug_tree (TYPE_CACHED_VALUES (t));
14722 0 : error_found = true;
14723 : }
14724 : /* Verify just enough of cache to ensure that no one copied it to new type.
14725 : All copying should go by copy_node that should clear it. */
14726 284346847 : else if (TYPE_CACHED_VALUES_P (t))
14727 : {
14728 : int i;
14729 8478591971 : for (i = 0; i < TREE_VEC_LENGTH (TYPE_CACHED_VALUES (t)); i++)
14730 8412594173 : if (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)
14731 8412594173 : && TREE_TYPE (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)) != t)
14732 : {
14733 0 : error ("wrong %<TYPE_CACHED_VALUES%> entry");
14734 0 : debug_tree (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i));
14735 0 : error_found = true;
14736 0 : break;
14737 : }
14738 : }
14739 : }
14740 135094008 : else if (FUNC_OR_METHOD_TYPE_P (t))
14741 3232803 : for (tree l = TYPE_ARG_TYPES (t); l; l = TREE_CHAIN (l))
14742 : {
14743 : /* C++ FE uses TREE_PURPOSE to store initial values. */
14744 2377938 : if (TREE_PURPOSE (l) && in_lto_p)
14745 : {
14746 0 : error ("%<TREE_PURPOSE%> is non-NULL in %<TYPE_ARG_TYPES%> list");
14747 0 : debug_tree (l);
14748 0 : error_found = true;
14749 : }
14750 2377938 : if (!TYPE_P (TREE_VALUE (l)))
14751 : {
14752 0 : error ("wrong entry in %<TYPE_ARG_TYPES%> list");
14753 0 : debug_tree (l);
14754 0 : error_found = true;
14755 : }
14756 : }
14757 268105830 : else if (!is_lang_specific (t) && TYPE_VALUES_RAW (t))
14758 : {
14759 0 : error ("%<TYPE_VALUES_RAW%> field is non-NULL");
14760 0 : debug_tree (TYPE_VALUES_RAW (t));
14761 0 : error_found = true;
14762 : }
14763 916754716 : if (TREE_CODE (t) != INTEGER_TYPE
14764 : && TREE_CODE (t) != BOOLEAN_TYPE
14765 916754716 : && TREE_CODE (t) != BITINT_TYPE
14766 : && TREE_CODE (t) != OFFSET_TYPE
14767 : && TREE_CODE (t) != REFERENCE_TYPE
14768 : && TREE_CODE (t) != NULLPTR_TYPE
14769 : && TREE_CODE (t) != POINTER_TYPE
14770 632407869 : && TYPE_CACHED_VALUES_P (t))
14771 : {
14772 0 : error ("%<TYPE_CACHED_VALUES_P%> is set while it should not be");
14773 0 : error_found = true;
14774 : }
14775 :
14776 : /* ipa-devirt makes an assumption that TYPE_METHOD_BASETYPE is always
14777 : TYPE_MAIN_VARIANT and it would be odd to add methods only to variatns
14778 : of a type. */
14779 916754716 : if (TREE_CODE (t) == METHOD_TYPE
14780 916754716 : && TYPE_MAIN_VARIANT (TYPE_METHOD_BASETYPE (t)) != TYPE_METHOD_BASETYPE (t))
14781 : {
14782 0 : error ("%<TYPE_METHOD_BASETYPE%> is not main variant");
14783 0 : error_found = true;
14784 : }
14785 :
14786 916754716 : if (error_found)
14787 : {
14788 0 : debug_tree (const_cast <tree> (t));
14789 0 : internal_error ("%qs failed", __func__);
14790 : }
14791 : }
14792 :
14793 :
14794 : /* Return 1 if ARG interpreted as signed in its precision is known to be
14795 : always non-negative or 2 if ARG is known to be always negative, or 3 if
14796 : ARG may be non-negative or negative. STMT if specified is the statement
14797 : on which it is being tested. */
14798 :
14799 : int
14800 874970 : get_range_pos_neg (tree arg, gimple *stmt)
14801 : {
14802 874970 : if (arg == error_mark_node || !INTEGRAL_TYPE_P (TREE_TYPE (arg)))
14803 : return 3;
14804 :
14805 874970 : int prec = TYPE_PRECISION (TREE_TYPE (arg));
14806 874970 : int cnt = 0;
14807 874970 : if (TREE_CODE (arg) == INTEGER_CST)
14808 : {
14809 74146 : wide_int w = wi::sext (wi::to_wide (arg), prec);
14810 74146 : if (wi::neg_p (w))
14811 : return 2;
14812 : else
14813 59682 : return 1;
14814 74146 : }
14815 799559 : while (CONVERT_EXPR_P (arg)
14816 14692 : && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
14817 828943 : && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg, 0))) <= prec)
14818 : {
14819 14048 : arg = TREE_OPERAND (arg, 0);
14820 : /* Narrower value zero extended into wider type
14821 : will always result in positive values. */
14822 14048 : if (TYPE_UNSIGNED (TREE_TYPE (arg))
14823 14048 : && TYPE_PRECISION (TREE_TYPE (arg)) < prec)
14824 : return 1;
14825 13427 : prec = TYPE_PRECISION (TREE_TYPE (arg));
14826 13427 : if (++cnt > 30)
14827 : return 3;
14828 : }
14829 :
14830 800203 : if (TREE_CODE (arg) != SSA_NAME)
14831 : return 3;
14832 793727 : int_range_max r;
14833 1604889 : while (!get_range_query (cfun)->range_of_expr (r, arg, stmt)
14834 1622324 : || r.undefined_p () || r.varying_p ())
14835 : {
14836 529992 : gimple *g = SSA_NAME_DEF_STMT (arg);
14837 529992 : if (is_gimple_assign (g)
14838 529992 : && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (g)))
14839 : {
14840 29429 : tree t = gimple_assign_rhs1 (g);
14841 58531 : if (INTEGRAL_TYPE_P (TREE_TYPE (t))
14842 55846 : && TYPE_PRECISION (TREE_TYPE (t)) <= prec)
14843 : {
14844 19832 : if (TYPE_UNSIGNED (TREE_TYPE (t))
14845 19832 : && TYPE_PRECISION (TREE_TYPE (t)) < prec)
14846 : return 1;
14847 17435 : prec = TYPE_PRECISION (TREE_TYPE (t));
14848 17435 : arg = t;
14849 17435 : if (++cnt > 30)
14850 : return 3;
14851 17435 : continue;
14852 : }
14853 : }
14854 : return 3;
14855 : }
14856 281170 : if (TYPE_UNSIGNED (TREE_TYPE (arg)))
14857 : {
14858 : /* For unsigned values, the "positive" range comes
14859 : below the "negative" range. */
14860 113824 : if (!wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14861 : return 1;
14862 32448 : if (wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14863 : return 2;
14864 : }
14865 : else
14866 : {
14867 167346 : if (!wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14868 : return 1;
14869 64937 : if (wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14870 : return 2;
14871 : }
14872 : return 3;
14873 793727 : }
14874 :
14875 :
14876 :
14877 :
14878 : /* Return true if ARG is marked with the nonnull attribute in the
14879 : current function signature. */
14880 :
14881 : bool
14882 27254348 : nonnull_arg_p (const_tree arg)
14883 : {
14884 27254348 : tree t, attrs, fntype;
14885 27254348 : unsigned HOST_WIDE_INT arg_num;
14886 :
14887 27254348 : gcc_assert (TREE_CODE (arg) == PARM_DECL
14888 : && (POINTER_TYPE_P (TREE_TYPE (arg))
14889 : || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE));
14890 :
14891 : /* The static chain decl is always non null. */
14892 27254348 : if (arg == cfun->static_chain_decl)
14893 : return true;
14894 :
14895 : /* THIS argument of method is always non-NULL. */
14896 26985287 : if (TREE_CODE (TREE_TYPE (cfun->decl)) == METHOD_TYPE
14897 10383619 : && arg == DECL_ARGUMENTS (cfun->decl)
14898 33513410 : && flag_delete_null_pointer_checks)
14899 : return true;
14900 :
14901 : /* Values passed by reference are always non-NULL. */
14902 20459242 : if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE
14903 20459242 : && flag_delete_null_pointer_checks)
14904 : return true;
14905 :
14906 13971660 : fntype = TREE_TYPE (cfun->decl);
14907 13994635 : for (attrs = TYPE_ATTRIBUTES (fntype); attrs; attrs = TREE_CHAIN (attrs))
14908 : {
14909 550074 : attrs = lookup_attribute ("nonnull", attrs);
14910 :
14911 : /* If "nonnull" wasn't specified, we know nothing about the argument. */
14912 550074 : if (attrs == NULL_TREE)
14913 : return false;
14914 :
14915 : /* If "nonnull" applies to all the arguments, then ARG is non-null. */
14916 114930 : if (TREE_VALUE (attrs) == NULL_TREE)
14917 : return true;
14918 :
14919 : /* Get the position number for ARG in the function signature. */
14920 56465 : for (arg_num = 1, t = DECL_ARGUMENTS (cfun->decl);
14921 131066 : t;
14922 74601 : t = DECL_CHAIN (t), arg_num++)
14923 : {
14924 131066 : if (t == arg)
14925 : break;
14926 : }
14927 :
14928 56465 : gcc_assert (t == arg);
14929 :
14930 : /* Now see if ARG_NUM is mentioned in the nonnull list. */
14931 89267 : for (t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
14932 : {
14933 66292 : if (compare_tree_int (TREE_VALUE (t), arg_num) == 0)
14934 : return true;
14935 : }
14936 : }
14937 :
14938 : return false;
14939 : }
14940 :
14941 : /* Combine LOC and BLOCK to a combined adhoc loc, retaining any range
14942 : information. */
14943 :
14944 : location_t
14945 950103228 : set_block (location_t loc, tree block)
14946 : {
14947 950103228 : location_t pure_loc = get_pure_location (loc);
14948 950103228 : source_range src_range = get_range_from_loc (line_table, loc);
14949 950103228 : unsigned discriminator = get_discriminator_from_loc (line_table, loc);
14950 950103228 : return line_table->get_or_create_combined_loc (pure_loc, src_range, block,
14951 950103228 : discriminator);
14952 : }
14953 :
14954 : location_t
14955 222155950 : set_source_range (tree expr, location_t start, location_t finish)
14956 : {
14957 222155950 : source_range src_range;
14958 222155950 : src_range.m_start = start;
14959 222155950 : src_range.m_finish = finish;
14960 222155950 : return set_source_range (expr, src_range);
14961 : }
14962 :
14963 : location_t
14964 453764479 : set_source_range (tree expr, source_range src_range)
14965 : {
14966 453764479 : if (!EXPR_P (expr))
14967 : return UNKNOWN_LOCATION;
14968 :
14969 199769984 : location_t expr_location = EXPR_LOCATION (expr);
14970 199769984 : location_t pure_loc = get_pure_location (expr_location);
14971 199769984 : unsigned discriminator = get_discriminator_from_loc (expr_location);
14972 199769984 : location_t adhoc = line_table->get_or_create_combined_loc (pure_loc,
14973 : src_range,
14974 : nullptr,
14975 : discriminator);
14976 199769984 : SET_EXPR_LOCATION (expr, adhoc);
14977 199769984 : return adhoc;
14978 : }
14979 :
14980 : /* Return EXPR, potentially wrapped with a node expression LOC,
14981 : if !CAN_HAVE_LOCATION_P (expr).
14982 :
14983 : NON_LVALUE_EXPR is used for wrapping constants, apart from STRING_CST.
14984 : VIEW_CONVERT_EXPR is used for wrapping non-constants and STRING_CST.
14985 :
14986 : Wrapper nodes can be identified using location_wrapper_p. */
14987 :
14988 : tree
14989 1600436241 : maybe_wrap_with_location (tree expr, location_t loc)
14990 : {
14991 1600436241 : if (expr == NULL)
14992 : return NULL;
14993 1600436237 : if (loc == UNKNOWN_LOCATION)
14994 : return expr;
14995 1546161285 : if (CAN_HAVE_LOCATION_P (expr))
14996 : return expr;
14997 : /* We should only be adding wrappers for constants and for decls,
14998 : or for some exceptional tree nodes (e.g. BASELINK in the C++ FE). */
14999 942803853 : gcc_assert (CONSTANT_CLASS_P (expr)
15000 : || DECL_P (expr)
15001 : || EXCEPTIONAL_CLASS_P (expr));
15002 :
15003 : /* For now, don't add wrappers to exceptional tree nodes, to minimize
15004 : any impact of the wrapper nodes. */
15005 942803853 : if (EXCEPTIONAL_CLASS_P (expr) || error_operand_p (expr))
15006 : return expr;
15007 :
15008 : /* Compiler-generated temporary variables don't need a wrapper. */
15009 870417371 : if (DECL_P (expr) && DECL_ARTIFICIAL (expr) && DECL_IGNORED_P (expr))
15010 : return expr;
15011 :
15012 : /* If any auto_suppress_location_wrappers are active, don't create
15013 : wrappers. */
15014 870414885 : if (suppress_location_wrappers > 0)
15015 : return expr;
15016 :
15017 1627574124 : tree_code code
15018 214515190 : = (((CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST)
15019 608493958 : || (TREE_CODE (expr) == CONST_DECL && !TREE_STATIC (expr)))
15020 813787062 : ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR);
15021 813787062 : tree wrapper = build1_loc (loc, code, TREE_TYPE (expr), expr);
15022 : /* Mark this node as being a wrapper. */
15023 813787062 : EXPR_LOCATION_WRAPPER_P (wrapper) = 1;
15024 813787062 : return wrapper;
15025 : }
15026 :
15027 : int suppress_location_wrappers;
15028 :
15029 : /* Return the name of combined function FN, for debugging purposes. */
15030 :
15031 : const char *
15032 0 : combined_fn_name (combined_fn fn)
15033 : {
15034 0 : if (builtin_fn_p (fn))
15035 : {
15036 0 : tree fndecl = builtin_decl_explicit (as_builtin_fn (fn));
15037 0 : return IDENTIFIER_POINTER (DECL_NAME (fndecl));
15038 : }
15039 : else
15040 0 : return internal_fn_name (as_internal_fn (fn));
15041 : }
15042 :
15043 : /* Return a bitmap with a bit set corresponding to each argument in
15044 : a function call type FNTYPE declared with attribute nonnull,
15045 : or null if none of the function's argument are nonnull. The caller
15046 : must free the bitmap. */
15047 :
15048 : bitmap
15049 22146865 : get_nonnull_args (const_tree fntype)
15050 : {
15051 22146865 : if (fntype == NULL_TREE)
15052 : return NULL;
15053 :
15054 21491630 : bitmap argmap = NULL;
15055 21491630 : if (TREE_CODE (fntype) == METHOD_TYPE)
15056 : {
15057 : /* The this pointer in C++ non-static member functions is
15058 : implicitly nonnull whether or not it's declared as such. */
15059 2849591 : argmap = BITMAP_ALLOC (NULL);
15060 2849591 : bitmap_set_bit (argmap, 0);
15061 : }
15062 :
15063 21491630 : tree attrs = TYPE_ATTRIBUTES (fntype);
15064 21491630 : if (!attrs)
15065 : return argmap;
15066 :
15067 : /* A function declaration can specify multiple attribute nonnull,
15068 : each with zero or more arguments. The loop below creates a bitmap
15069 : representing a union of all the arguments. An empty (but non-null)
15070 : bitmap means that all arguments have been declared nonnull. */
15071 6186120 : for ( ; attrs; attrs = TREE_CHAIN (attrs))
15072 : {
15073 6075976 : attrs = lookup_attribute ("nonnull", attrs);
15074 6075976 : if (!attrs)
15075 : break;
15076 :
15077 1646498 : if (!argmap)
15078 1606530 : argmap = BITMAP_ALLOC (NULL);
15079 :
15080 1646498 : if (!TREE_VALUE (attrs))
15081 : {
15082 : /* Clear the bitmap in case a previous attribute nonnull
15083 : set it and this one overrides it for all arguments. */
15084 999900 : bitmap_clear (argmap);
15085 999900 : return argmap;
15086 : }
15087 :
15088 : /* Iterate over the indices of the format arguments declared nonnull
15089 : and set a bit for each. */
15090 1694296 : for (tree idx = TREE_VALUE (attrs); idx; idx = TREE_CHAIN (idx))
15091 : {
15092 1047698 : unsigned int val = TREE_INT_CST_LOW (TREE_VALUE (idx)) - 1;
15093 1047698 : bitmap_set_bit (argmap, val);
15094 : }
15095 : }
15096 :
15097 : return argmap;
15098 : }
15099 :
15100 : /* Returns true if TYPE is a type where it and all of its subobjects
15101 : (recursively) are of structure, union, or array type. */
15102 :
15103 : bool
15104 2008866609 : is_empty_type (const_tree type)
15105 : {
15106 2008866609 : if (RECORD_OR_UNION_TYPE_P (type))
15107 : {
15108 888669136 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
15109 816127422 : if (TREE_CODE (field) == FIELD_DECL
15110 405235513 : && !DECL_PADDING_P (field)
15111 1221361614 : && !is_empty_type (TREE_TYPE (field)))
15112 : return false;
15113 : return true;
15114 : }
15115 1559382857 : else if (TREE_CODE (type) == ARRAY_TYPE)
15116 88611800 : return (integer_minus_onep (array_type_nelts_minus_one (type))
15117 88567910 : || TYPE_DOMAIN (type) == NULL_TREE
15118 167031278 : || is_empty_type (TREE_TYPE (type)));
15119 : return false;
15120 : }
15121 :
15122 : /* Implement TARGET_EMPTY_RECORD_P. Return true if TYPE is an empty type
15123 : that shouldn't be passed via stack. */
15124 :
15125 : bool
15126 1473184642 : default_is_empty_record (const_tree type)
15127 : {
15128 1473184642 : if (!abi_version_at_least (12))
15129 : return false;
15130 :
15131 1472136377 : if (type == error_mark_node)
15132 : return false;
15133 :
15134 1472136377 : if (TREE_ADDRESSABLE (type))
15135 : return false;
15136 :
15137 1472136377 : return is_empty_type (TYPE_MAIN_VARIANT (type));
15138 : }
15139 :
15140 :
15141 : /* Determine whether TYPE is an ISO C99 flexible array member type "[]". */
15142 :
15143 : bool
15144 11811524 : flexible_array_member_type_p (const_tree type)
15145 : {
15146 11811524 : if (TREE_CODE (type) == ARRAY_TYPE
15147 4935160 : && TYPE_SIZE (type) == NULL_TREE
15148 649035 : && TYPE_DOMAIN (type) != NULL_TREE
15149 12370649 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)
15150 559125 : return true;
15151 :
15152 : return false;
15153 : }
15154 :
15155 :
15156 : /* Determine whether TYPE is a structure with a flexible array member,
15157 : or a union containing such a structure (possibly recursively). */
15158 :
15159 : bool
15160 72211 : flexible_array_type_p (const_tree type)
15161 : {
15162 72211 : tree x, last;
15163 72211 : switch (TREE_CODE (type))
15164 : {
15165 37955 : case RECORD_TYPE:
15166 37955 : last = NULL_TREE;
15167 173016 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15168 135061 : if (TREE_CODE (x) == FIELD_DECL)
15169 135061 : last = x;
15170 37955 : if (last == NULL_TREE)
15171 : return false;
15172 37947 : return flexible_array_member_type_p (TREE_TYPE (last));
15173 579 : case UNION_TYPE:
15174 1668 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15175 : {
15176 1131 : if (TREE_CODE (x) == FIELD_DECL
15177 1131 : && flexible_array_type_p (TREE_TYPE (x)))
15178 : return true;
15179 : }
15180 : return false;
15181 : default:
15182 : return false;
15183 : }
15184 : }
15185 :
15186 : /* Like int_size_in_bytes, but handle empty records specially. */
15187 :
15188 : HOST_WIDE_INT
15189 463300 : arg_int_size_in_bytes (const_tree type)
15190 : {
15191 463300 : return TYPE_EMPTY_P (type) ? 0 : int_size_in_bytes (type);
15192 : }
15193 :
15194 : /* Like size_in_bytes, but handle empty records specially. */
15195 :
15196 : tree
15197 5712487 : arg_size_in_bytes (const_tree type)
15198 : {
15199 5712487 : return TYPE_EMPTY_P (type) ? size_zero_node : size_in_bytes (type);
15200 : }
15201 :
15202 : /* Return true if an expression with CODE has to have the same result type as
15203 : its first operand. */
15204 :
15205 : bool
15206 0 : expr_type_first_operand_type_p (tree_code code)
15207 : {
15208 0 : switch (code)
15209 : {
15210 : case NEGATE_EXPR:
15211 : case ABS_EXPR:
15212 : case BIT_NOT_EXPR:
15213 : case PAREN_EXPR:
15214 : case CONJ_EXPR:
15215 :
15216 : case PLUS_EXPR:
15217 : case MINUS_EXPR:
15218 : case MULT_EXPR:
15219 : case TRUNC_DIV_EXPR:
15220 : case CEIL_DIV_EXPR:
15221 : case FLOOR_DIV_EXPR:
15222 : case ROUND_DIV_EXPR:
15223 : case TRUNC_MOD_EXPR:
15224 : case CEIL_MOD_EXPR:
15225 : case FLOOR_MOD_EXPR:
15226 : case ROUND_MOD_EXPR:
15227 : case RDIV_EXPR:
15228 : case EXACT_DIV_EXPR:
15229 : case MIN_EXPR:
15230 : case MAX_EXPR:
15231 : case BIT_IOR_EXPR:
15232 : case BIT_XOR_EXPR:
15233 : case BIT_AND_EXPR:
15234 :
15235 : case LSHIFT_EXPR:
15236 : case RSHIFT_EXPR:
15237 : case LROTATE_EXPR:
15238 : case RROTATE_EXPR:
15239 : return true;
15240 :
15241 0 : default:
15242 0 : return false;
15243 : }
15244 : }
15245 :
15246 : /* Return a typenode for the "standard" C type with a given name. */
15247 : tree
15248 926337 : get_typenode_from_name (const char *name)
15249 : {
15250 926337 : if (name == NULL || *name == '\0')
15251 : return NULL_TREE;
15252 :
15253 926337 : if (strcmp (name, "char") == 0)
15254 0 : return char_type_node;
15255 926337 : if (strcmp (name, "unsigned char") == 0)
15256 95640 : return unsigned_char_type_node;
15257 830697 : if (strcmp (name, "signed char") == 0)
15258 95640 : return signed_char_type_node;
15259 :
15260 735057 : if (strcmp (name, "short int") == 0)
15261 65277 : return short_integer_type_node;
15262 669780 : if (strcmp (name, "short unsigned int") == 0)
15263 63760 : return short_unsigned_type_node;
15264 :
15265 606020 : if (strcmp (name, "int") == 0)
15266 66105 : return integer_type_node;
15267 539915 : if (strcmp (name, "unsigned int") == 0)
15268 64578 : return unsigned_type_node;
15269 :
15270 475337 : if (strcmp (name, "long int") == 0)
15271 283239 : return long_integer_type_node;
15272 192098 : if (strcmp (name, "long unsigned int") == 0)
15273 188826 : return long_unsigned_type_node;
15274 :
15275 3272 : if (strcmp (name, "long long int") == 0)
15276 1636 : return long_long_integer_type_node;
15277 1636 : if (strcmp (name, "long long unsigned int") == 0)
15278 1636 : return long_long_unsigned_type_node;
15279 :
15280 0 : gcc_unreachable ();
15281 : }
15282 :
15283 : /* List of pointer types used to declare builtins before we have seen their
15284 : real declaration.
15285 :
15286 : Keep the size up to date in tree.h ! */
15287 : const builtin_structptr_type builtin_structptr_types[6] =
15288 : {
15289 : { fileptr_type_node, ptr_type_node, "FILE" },
15290 : { const_tm_ptr_type_node, const_ptr_type_node, "tm" },
15291 : { fenv_t_ptr_type_node, ptr_type_node, "fenv_t" },
15292 : { const_fenv_t_ptr_type_node, const_ptr_type_node, "fenv_t" },
15293 : { fexcept_t_ptr_type_node, ptr_type_node, "fexcept_t" },
15294 : { const_fexcept_t_ptr_type_node, const_ptr_type_node, "fexcept_t" }
15295 : };
15296 :
15297 : /* Return the maximum object size. */
15298 :
15299 : tree
15300 7571388 : max_object_size (void)
15301 : {
15302 : /* To do: Make this a configurable parameter. */
15303 7571388 : return TYPE_MAX_VALUE (ptrdiff_type_node);
15304 : }
15305 :
15306 : /* A wrapper around TARGET_VERIFY_TYPE_CONTEXT that makes the silent_p
15307 : parameter default to false and that weeds out error_mark_node. */
15308 :
15309 : bool
15310 155248761 : verify_type_context (location_t loc, type_context_kind context,
15311 : const_tree type, bool silent_p)
15312 : {
15313 155248761 : if (type == error_mark_node)
15314 : return true;
15315 :
15316 155248665 : gcc_assert (TYPE_P (type));
15317 155248665 : return (!targetm.verify_type_context
15318 155248665 : || targetm.verify_type_context (loc, context, type, silent_p));
15319 : }
15320 :
15321 : /* Callback of walk_tree telling whether the current tree pointed by TP is the
15322 : one provided as DATA. */
15323 :
15324 : static tree
15325 4739 : find_tree_1 (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED, void *data)
15326 : {
15327 4739 : if (*tp == data)
15328 : return (tree) data;
15329 : else
15330 4667 : return NULL;
15331 : }
15332 :
15333 : /* Return whether SEARCH is a subtree of TOP. */
15334 :
15335 : bool
15336 3695 : find_tree (tree top, tree search)
15337 : {
15338 3695 : return walk_tree_without_duplicates (&top, find_tree_1, search) != 0;
15339 : }
15340 :
15341 : /* Return true if NEW_ASM and DELETE_ASM name a valid pair of new and
15342 : delete operators. Return false if they may or may not name such
15343 : a pair and, when nonnull, set *PCERTAIN to true if they certainly
15344 : do not. */
15345 :
15346 : bool
15347 64952 : valid_new_delete_pair_p (tree new_asm, tree delete_asm,
15348 : bool *pcertain /* = NULL */)
15349 : {
15350 64952 : bool certain;
15351 64952 : if (!pcertain)
15352 52863 : pcertain = &certain;
15353 :
15354 64952 : const char *new_name = IDENTIFIER_POINTER (new_asm);
15355 64952 : const char *delete_name = IDENTIFIER_POINTER (delete_asm);
15356 64952 : unsigned int new_len = IDENTIFIER_LENGTH (new_asm);
15357 64952 : unsigned int delete_len = IDENTIFIER_LENGTH (delete_asm);
15358 :
15359 : /* The following failures are due to invalid names so they're not
15360 : considered certain mismatches. */
15361 64952 : *pcertain = false;
15362 :
15363 64952 : if (new_len < 5 || delete_len < 6)
15364 : return false;
15365 64952 : if (new_name[0] == '_')
15366 64880 : ++new_name, --new_len;
15367 64952 : if (new_name[0] == '_')
15368 0 : ++new_name, --new_len;
15369 64952 : if (delete_name[0] == '_')
15370 64952 : ++delete_name, --delete_len;
15371 64952 : if (delete_name[0] == '_')
15372 0 : ++delete_name, --delete_len;
15373 64952 : if (new_len < 4 || delete_len < 5)
15374 : return false;
15375 :
15376 : /* The following failures are due to names of user-defined operators
15377 : so they're also not considered certain mismatches. */
15378 :
15379 : /* *_len is now just the length after initial underscores. */
15380 64952 : if (new_name[0] != 'Z' || new_name[1] != 'n')
15381 : return false;
15382 64279 : if (delete_name[0] != 'Z' || delete_name[1] != 'd')
15383 : return false;
15384 :
15385 : /* The following failures are certain mismatches. */
15386 64203 : *pcertain = true;
15387 :
15388 : /* _Znw must match _Zdl, _Zna must match _Zda. */
15389 64203 : if ((new_name[2] != 'w' || delete_name[2] != 'l')
15390 5115 : && (new_name[2] != 'a' || delete_name[2] != 'a'))
15391 : return false;
15392 64107 : if (new_name[3] == 'I' || delete_name[3] == 'I')
15393 : {
15394 : /* When ::operator new or ::operator delete are function templates,
15395 : return uncertain mismatch, we need demangler in that case. */
15396 6 : *pcertain = false;
15397 6 : return false;
15398 : }
15399 : /* 'j', 'm' and 'y' correspond to size_t. */
15400 64101 : if (new_name[3] != 'j' && new_name[3] != 'm' && new_name[3] != 'y')
15401 : return false;
15402 64101 : if (delete_name[3] != 'P' || delete_name[4] != 'v')
15403 : return false;
15404 64101 : if (new_len == 4
15405 370 : || (new_len == 18 && !memcmp (new_name + 4, "RKSt9nothrow_t", 14)))
15406 : {
15407 : /* _ZnXY or _ZnXYRKSt9nothrow_t matches
15408 : _ZdXPv, _ZdXPvY and _ZdXPvRKSt9nothrow_t. */
15409 63899 : if (delete_len == 5)
15410 : return true;
15411 57259 : if (delete_len == 6 && delete_name[5] == new_name[3])
15412 : return true;
15413 39 : if (delete_len == 19 && !memcmp (delete_name + 5, "RKSt9nothrow_t", 14))
15414 : return true;
15415 : }
15416 202 : else if ((new_len == 19 && !memcmp (new_name + 4, "St11align_val_t", 15))
15417 42 : || (new_len == 33
15418 10 : && !memcmp (new_name + 4, "St11align_val_tRKSt9nothrow_t", 29)))
15419 : {
15420 : /* _ZnXYSt11align_val_t or _ZnXYSt11align_val_tRKSt9nothrow_t matches
15421 : _ZdXPvSt11align_val_t or _ZdXPvYSt11align_val_t or
15422 : _ZdXPvSt11align_val_tRKSt9nothrow_t. */
15423 170 : if (delete_len == 20 && !memcmp (delete_name + 5, "St11align_val_t", 15))
15424 : return true;
15425 54 : if (delete_len == 21
15426 39 : && delete_name[5] == new_name[3]
15427 39 : && !memcmp (delete_name + 6, "St11align_val_t", 15))
15428 : return true;
15429 15 : if (delete_len == 34
15430 9 : && !memcmp (delete_name + 5, "St11align_val_tRKSt9nothrow_t", 29))
15431 : return true;
15432 : }
15433 :
15434 : /* The negative result is conservative. */
15435 38 : *pcertain = false;
15436 38 : return false;
15437 : }
15438 :
15439 : /* Return the zero-based number corresponding to the argument being
15440 : deallocated if FNDECL is a deallocation function or an out-of-bounds
15441 : value if it isn't. */
15442 :
15443 : unsigned
15444 23258244 : fndecl_dealloc_argno (tree fndecl)
15445 : {
15446 : /* A call to operator delete isn't recognized as one to a built-in. */
15447 23258244 : if (DECL_IS_OPERATOR_DELETE_P (fndecl))
15448 : {
15449 353091 : if (DECL_IS_REPLACEABLE_OPERATOR (fndecl))
15450 : return 0;
15451 :
15452 : /* Avoid placement delete that's not been inlined. */
15453 26589 : tree fname = DECL_ASSEMBLER_NAME (fndecl);
15454 26589 : if (id_equal (fname, "_ZdlPvS_") // ordinary form
15455 26589 : || id_equal (fname, "_ZdaPvS_")) // array form
15456 : return UINT_MAX;
15457 : return 0;
15458 : }
15459 :
15460 : /* TODO: Handle user-defined functions with attribute malloc? Handle
15461 : known non-built-ins like fopen? */
15462 22905153 : if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
15463 : {
15464 5602000 : switch (DECL_FUNCTION_CODE (fndecl))
15465 : {
15466 : case BUILT_IN_FREE:
15467 : case BUILT_IN_REALLOC:
15468 : case BUILT_IN_GOMP_FREE:
15469 : case BUILT_IN_GOMP_REALLOC:
15470 : return 0;
15471 : default:
15472 : break;
15473 : }
15474 : return UINT_MAX;
15475 : }
15476 :
15477 17303153 : tree attrs = DECL_ATTRIBUTES (fndecl);
15478 17303153 : if (!attrs)
15479 : return UINT_MAX;
15480 :
15481 0 : for (tree atfree = attrs;
15482 3982456 : (atfree = lookup_attribute ("*dealloc", atfree));
15483 0 : atfree = TREE_CHAIN (atfree))
15484 : {
15485 4926 : tree alloc = TREE_VALUE (atfree);
15486 4926 : if (!alloc)
15487 0 : continue;
15488 :
15489 4926 : tree pos = TREE_CHAIN (alloc);
15490 4926 : if (!pos)
15491 : return 0;
15492 :
15493 2739 : pos = TREE_VALUE (pos);
15494 2739 : return TREE_INT_CST_LOW (pos) - 1;
15495 : }
15496 :
15497 : return UINT_MAX;
15498 : }
15499 :
15500 : /* If EXPR refers to a character array or pointer declared attribute
15501 : nonstring, return a decl for that array or pointer and set *REF
15502 : to the referenced enclosing object or pointer. Otherwise return
15503 : null. */
15504 :
15505 : tree
15506 1400647 : get_attr_nonstring_decl (tree expr, tree *ref)
15507 : {
15508 1406317 : tree decl = expr;
15509 1406317 : tree var = NULL_TREE;
15510 1406317 : if (TREE_CODE (decl) == SSA_NAME)
15511 : {
15512 836726 : gimple *def = SSA_NAME_DEF_STMT (decl);
15513 :
15514 836726 : if (is_gimple_assign (def))
15515 : {
15516 44356 : tree_code code = gimple_assign_rhs_code (def);
15517 44356 : if (code == ADDR_EXPR
15518 44356 : || code == COMPONENT_REF
15519 29474 : || code == VAR_DECL)
15520 19361 : decl = gimple_assign_rhs1 (def);
15521 : }
15522 : else
15523 792370 : var = SSA_NAME_VAR (decl);
15524 : }
15525 :
15526 1406317 : if (TREE_CODE (decl) == ADDR_EXPR)
15527 26009 : decl = TREE_OPERAND (decl, 0);
15528 :
15529 : /* To simplify calling code, store the referenced DECL regardless of
15530 : the attribute determined below, but avoid storing the SSA_NAME_VAR
15531 : obtained above (it's not useful for dataflow purposes). */
15532 1406317 : if (ref)
15533 5463 : *ref = decl;
15534 :
15535 : /* Use the SSA_NAME_VAR that was determined above to see if it's
15536 : declared nonstring. Otherwise drill down into the referenced
15537 : DECL. */
15538 1406317 : if (var)
15539 : decl = var;
15540 : else
15541 : {
15542 639193 : while (TREE_CODE (decl) == ARRAY_REF)
15543 18639 : decl = TREE_OPERAND (decl, 0);
15544 620554 : if (TREE_CODE (decl) == COMPONENT_REF)
15545 16743 : decl = TREE_OPERAND (decl, 1);
15546 603811 : else if (TREE_CODE (decl) == MEM_REF)
15547 5670 : return get_attr_nonstring_decl (TREE_OPERAND (decl, 0), ref);
15548 : }
15549 :
15550 1400647 : if (DECL_P (decl) && lookup_attribute ("nonstring", DECL_ATTRIBUTES (decl)))
15551 : return decl;
15552 :
15553 : return NULL_TREE;
15554 : }
15555 :
15556 : /* Returns an auto_vec of string_slices containing the version strings from
15557 : ARGLIST. DEFAULT_COUNT is incremented for each default version found.
15558 : If FILTER is true then any invalid versions strings are not included. */
15559 :
15560 : auto_vec<string_slice>
15561 208 : get_clone_attr_versions (const tree arglist,
15562 : int *default_count,
15563 : bool filter)
15564 : {
15565 208 : gcc_assert (TREE_CODE (arglist) == TREE_LIST);
15566 208 : auto_vec<string_slice> versions;
15567 :
15568 208 : static const char separator_str[] = {TARGET_CLONES_ATTR_SEPARATOR, 0};
15569 208 : string_slice separators = string_slice (separator_str);
15570 :
15571 764 : for (tree arg = arglist; arg; arg = TREE_CHAIN (arg))
15572 : {
15573 556 : string_slice str = string_slice (TREE_STRING_POINTER (TREE_VALUE (arg)));
15574 1696 : while (str.is_valid ())
15575 : {
15576 584 : string_slice attr = string_slice::tokenize (&str, separators);
15577 584 : attr = attr.strip ();
15578 :
15579 584 : if (filter && !targetm.check_target_clone_version (attr, NULL))
15580 0 : continue;
15581 :
15582 584 : if (attr == "default" && default_count)
15583 206 : (*default_count)++;
15584 584 : versions.safe_push (attr);
15585 : }
15586 : }
15587 208 : return versions;
15588 : }
15589 :
15590 : /* Returns an auto_vec of string_slices containing the version strings from
15591 : the target_clone attribute from DECL. DEFAULT_COUNT is incremented for each
15592 : default version found. If FILTER is true then any invalid versions strings
15593 : are not included. */
15594 : auto_vec<string_slice>
15595 97 : get_clone_versions (const tree decl, int *default_count, bool filter)
15596 : {
15597 97 : tree attr = lookup_attribute ("target_clones", DECL_ATTRIBUTES (decl));
15598 97 : if (!attr)
15599 0 : return auto_vec<string_slice> ();
15600 97 : tree arglist = TREE_VALUE (attr);
15601 97 : return get_clone_attr_versions (arglist, default_count, filter);
15602 : }
15603 :
15604 : /* If DECL has a target_version attribute, returns a string_slice containing the
15605 : attribute value. Otherwise, returns string_slice::invalid.
15606 : Only works for target_version due to target attributes allowing multiple
15607 : string arguments to specify one target. */
15608 : string_slice
15609 0 : get_target_version (const tree decl)
15610 : {
15611 0 : gcc_assert (!TARGET_HAS_FMV_TARGET_ATTRIBUTE);
15612 :
15613 : tree attr = lookup_attribute ("target_version", DECL_ATTRIBUTES (decl));
15614 :
15615 : if (!attr)
15616 : return string_slice::invalid ();
15617 :
15618 : return string_slice (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))))
15619 : .strip ();
15620 : }
15621 :
15622 : /* Returns true if FN1 and FN2 define disjoint function versions in an FMV
15623 : function set. That is, the two declarations are completely non-overlapping.
15624 : For target_version semantics, that means if one is a target clone and one is
15625 : a target version, the target_version must not be defined by the target_clone,
15626 : and for two target_clones, they must not define any of the same version.
15627 :
15628 : FN1 and FN2 should be function decls. */
15629 :
15630 : bool
15631 31036165 : disjoint_version_decls (tree fn1, tree fn2)
15632 : {
15633 31036165 : if (TREE_CODE (fn1) != FUNCTION_DECL
15634 31034941 : || TREE_CODE (fn2) != FUNCTION_DECL)
15635 : return false;
15636 :
15637 28797228 : if (TARGET_HAS_FMV_TARGET_ATTRIBUTE)
15638 : {
15639 28797228 : tree attr1 = lookup_attribute ("target", DECL_ATTRIBUTES (fn1));
15640 28797228 : tree attr2 = lookup_attribute ("target", DECL_ATTRIBUTES (fn2));
15641 :
15642 : /* At least one function decl should have the target attribute
15643 : specified. */
15644 28797228 : if (attr1 == NULL_TREE && attr2 == NULL_TREE)
15645 : return false;
15646 :
15647 : /* Diagnose missing target attribute if one of the decls is already
15648 : multi-versioned. */
15649 18867 : if (attr1 == NULL_TREE || attr2 == NULL_TREE)
15650 : {
15651 363 : if (DECL_FUNCTION_VERSIONED (fn1) || DECL_FUNCTION_VERSIONED (fn2))
15652 : {
15653 114 : if (attr2 != NULL_TREE)
15654 : {
15655 114 : std::swap (fn1, fn2);
15656 114 : attr1 = attr2;
15657 : }
15658 114 : auto_diagnostic_group d;
15659 114 : error_at (DECL_SOURCE_LOCATION (fn2),
15660 : "missing %<target%> attribute for multi-versioned %qD",
15661 : fn2);
15662 114 : inform (DECL_SOURCE_LOCATION (fn1),
15663 : "previous declaration of %qD", fn1);
15664 : /* Prevent diagnosing of the same error multiple times. */
15665 114 : DECL_ATTRIBUTES (fn2)
15666 228 : = tree_cons (get_identifier ("target"),
15667 114 : copy_node (TREE_VALUE (attr1)),
15668 114 : DECL_ATTRIBUTES (fn2));
15669 114 : }
15670 363 : return false;
15671 : }
15672 :
15673 18504 : char *target1 = sorted_attr_string (TREE_VALUE (attr1));
15674 18504 : char *target2 = sorted_attr_string (TREE_VALUE (attr2));
15675 :
15676 : /* The sorted target strings must be different for fn1 and fn2
15677 : to be versions. */
15678 18504 : bool result = strcmp (target1, target2) != 0;
15679 :
15680 18504 : XDELETEVEC (target1);
15681 18504 : XDELETEVEC (target2);
15682 :
15683 18504 : return result;
15684 : }
15685 : else
15686 : {
15687 : /* As this is symmetric, can remove the case where fn2 is target clone
15688 : and fn1 is target version by swapping here. */
15689 : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn2)))
15690 : std::swap (fn1, fn2);
15691 :
15692 : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn1)))
15693 : {
15694 : auto_vec<string_slice> fn1_versions = get_clone_versions (fn1);
15695 : /* fn1 is target_clone. */
15696 : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn2)))
15697 : {
15698 : /* Both are target_clone. */
15699 : auto_vec<string_slice> fn2_versions = get_clone_versions (fn2);
15700 : for (string_slice v1 : fn1_versions)
15701 : {
15702 : for (string_slice v2 : fn2_versions)
15703 : if (targetm.target_option.same_function_versions
15704 : (v1, NULL_TREE, v2, NULL_TREE))
15705 : return false;
15706 : }
15707 : return true;
15708 : }
15709 : else
15710 : {
15711 : string_slice v2 = get_target_version (fn2);
15712 :
15713 : /* target and target_clones is always conflicting for target
15714 : semantics. */
15715 : if (TARGET_HAS_FMV_TARGET_ATTRIBUTE)
15716 : return false;
15717 :
15718 : /* Only fn1 is target clone. */
15719 : if (!v2.is_valid ())
15720 : v2 = "default";
15721 : for (string_slice v1 : fn1_versions)
15722 : if (targetm.target_option.same_function_versions
15723 : (v1, NULL_TREE, v2, NULL_TREE))
15724 : return false;
15725 : return true;
15726 : }
15727 : }
15728 : else
15729 : {
15730 : /* Both are target_version. */
15731 : string_slice v1 = get_target_version (fn1);
15732 : string_slice v2 = get_target_version (fn2);
15733 :
15734 : if (!v1.is_valid () && !v2.is_valid ())
15735 : return false;
15736 :
15737 : if (!v1.is_valid ())
15738 : v1 = "default";
15739 : if (!v2.is_valid ())
15740 : v2 = "default";
15741 :
15742 : if (targetm.target_option.same_function_versions (v1, NULL_TREE,
15743 : v2, NULL_TREE))
15744 : return false;
15745 :
15746 : return true;
15747 : }
15748 : }
15749 : }
15750 :
15751 : /* Check if the target_version/target_clones attributes are mergeable
15752 : for two decls, and if so returns false.
15753 : If they aren't mergeable, diagnose this and return true.
15754 : Only works for target_version semantics. */
15755 : bool
15756 0 : diagnose_versioned_decls (tree old_decl, tree new_decl)
15757 : {
15758 0 : gcc_assert (!TARGET_HAS_FMV_TARGET_ATTRIBUTE);
15759 :
15760 : string_slice old_target_attr = get_target_version (old_decl);
15761 : string_slice new_target_attr = get_target_version (new_decl);
15762 :
15763 : tree old_target_clones_attr = lookup_attribute ("target_clones",
15764 : DECL_ATTRIBUTES (old_decl));
15765 : tree new_target_clones_attr = lookup_attribute ("target_clones",
15766 : DECL_ATTRIBUTES (new_decl));
15767 :
15768 : /* If none of these are annotated, then it is mergeable. */
15769 : if (!old_target_attr.is_valid ()
15770 : && !old_target_attr.is_valid ()
15771 : && !old_target_clones_attr
15772 : && !new_target_clones_attr)
15773 : return false;
15774 :
15775 : /* If fn1 is unnanotated and fn2 contains default, then is mergeable. */
15776 : if (!old_target_attr.is_valid ()
15777 : && !old_target_clones_attr
15778 : && is_function_default_version (new_decl))
15779 : return false;
15780 :
15781 : /* If fn2 is unnanotated and fn1 contains default, then is mergeable. */
15782 : if (!new_target_attr.is_valid ()
15783 : && !new_target_clones_attr
15784 : && is_function_default_version (old_decl))
15785 : return false;
15786 :
15787 : /* In the case where both are annotated with target_clones, only mergeable if
15788 : the two sets of target_clones imply the same set of versions. */
15789 : if (old_target_clones_attr && new_target_clones_attr)
15790 : {
15791 : auto_vec<string_slice> old_versions = get_clone_versions (old_decl);
15792 : auto_vec<string_slice> new_versions = get_clone_versions (new_decl);
15793 :
15794 : bool mergeable = true;
15795 :
15796 : if (old_versions.length () != new_versions.length ())
15797 : mergeable = false;
15798 :
15799 : /* Check both inclusion directions. */
15800 : for (auto oldv: old_versions)
15801 : {
15802 : bool matched = false;
15803 : for (auto newv: new_versions)
15804 : if (targetm.target_option.same_function_versions (oldv, old_decl,
15805 : newv, new_decl))
15806 : matched = true;
15807 : if (!matched)
15808 : mergeable = false;
15809 : }
15810 :
15811 : for (auto newv: new_versions)
15812 : {
15813 : bool matched = false;
15814 : for (auto oldv: old_versions)
15815 : if (targetm.target_option.same_function_versions (oldv, old_decl,
15816 : newv, new_decl))
15817 : matched = true;
15818 : if (!matched)
15819 : mergeable = false;
15820 : }
15821 :
15822 : if (!mergeable)
15823 : {
15824 : error_at (DECL_SOURCE_LOCATION (new_decl),
15825 : "%qD conflicts with overlapping %<target_clone%> "
15826 : "declaration",
15827 : new_decl);
15828 : inform (DECL_SOURCE_LOCATION (old_decl),
15829 : "previous declaration of %qD", old_decl);
15830 : return true;
15831 : }
15832 :
15833 : return false;
15834 : }
15835 :
15836 : /* If olddecl is target clones and newdecl is a target_version.
15837 : As they are not distinct this implies newdecl redefines a version of
15838 : olddecl. Not mergeable. */
15839 : if (new_target_clones_attr)
15840 : {
15841 : gcc_assert (old_target_attr.is_valid ());
15842 :
15843 : error_at (DECL_SOURCE_LOCATION (new_decl),
15844 : "%qD conflicts for version %qB",
15845 : new_decl, &old_target_attr);
15846 : inform (DECL_SOURCE_LOCATION (old_decl),
15847 : "previous declaration of %qD",
15848 : old_decl);
15849 : return true;
15850 : }
15851 :
15852 : if (old_target_clones_attr)
15853 : {
15854 : gcc_assert (new_target_attr.is_valid ());
15855 :
15856 : error_at (DECL_SOURCE_LOCATION (new_decl),
15857 : "%qD conflicts with a previous declaration for version %qB",
15858 : new_decl, &new_target_attr);
15859 : inform (DECL_SOURCE_LOCATION (old_decl),
15860 : "previous declaration of %qD",
15861 : old_decl);
15862 : return true;
15863 : }
15864 :
15865 : /* The only remaining case is two target_version annotated decls. */
15866 : return !targetm.target_option.same_function_versions
15867 : (old_target_attr, old_decl, new_target_attr, new_decl);
15868 : }
15869 :
15870 :
15871 : /* This page contains routines to unshare tree nodes, i.e. to duplicate tree
15872 : nodes that are referenced more than once in GENERIC functions. This is
15873 : necessary because gimplification (translation into GIMPLE) is performed
15874 : by modifying tree nodes in-place, so gimplification of a shared node in a
15875 : first context could generate an invalid GIMPLE form in a second context.
15876 :
15877 : This is achieved with a simple mark/copy/unmark algorithm that walks the
15878 : GENERIC representation top-down, marks nodes with TREE_VISITED the first
15879 : time it encounters them, duplicates them if they already have TREE_VISITED
15880 : set, and finally removes the TREE_VISITED marks it has set.
15881 :
15882 : The algorithm works only at the function level, i.e. it generates a GENERIC
15883 : representation of a function with no nodes shared within the function when
15884 : passed a GENERIC function (except for nodes that are allowed to be shared).
15885 :
15886 : At the global level, it is also necessary to unshare tree nodes that are
15887 : referenced in more than one function, for the same aforementioned reason.
15888 : This requires some cooperation from the front-end. There are 2 strategies:
15889 :
15890 : 1. Manual unsharing. The front-end needs to call unshare_expr on every
15891 : expression that might end up being shared across functions.
15892 :
15893 : 2. Deep unsharing. This is an extension of regular unsharing. Instead
15894 : of calling unshare_expr on expressions that might be shared across
15895 : functions, the front-end pre-marks them with TREE_VISITED. This will
15896 : ensure that they are unshared on the first reference within functions
15897 : when the regular unsharing algorithm runs. The counterpart is that
15898 : this algorithm must look deeper than for manual unsharing, which is
15899 : specified by LANG_HOOKS_DEEP_UNSHARING.
15900 :
15901 : If there are only few specific cases of node sharing across functions, it is
15902 : probably easier for a front-end to unshare the expressions manually. On the
15903 : contrary, if the expressions generated at the global level are as widespread
15904 : as expressions generated within functions, deep unsharing is very likely the
15905 : way to go. */
15906 :
15907 : /* Similar to copy_tree_r but do not copy SAVE_EXPR or TARGET_EXPR nodes.
15908 : These nodes model computations that must be done once. If we were to
15909 : unshare something like SAVE_EXPR(i++), the gimplification process would
15910 : create wrong code. However, if DATA is non-null, it must hold a pointer
15911 : set that is used to unshare the subtrees of these nodes. */
15912 :
15913 : static tree
15914 2798621036 : mostly_copy_tree_r (tree *tp, int *walk_subtrees, void *data)
15915 : {
15916 2798621036 : tree t = *tp;
15917 2798621036 : enum tree_code code = TREE_CODE (t);
15918 :
15919 : /* Do not copy SAVE_EXPR, TARGET_EXPR or BIND_EXPR nodes themselves, but
15920 : copy their subtrees if we can make sure to do it only once. */
15921 2798621036 : if (code == SAVE_EXPR || code == TARGET_EXPR || code == BIND_EXPR)
15922 : {
15923 11574858 : if (data && !((hash_set<tree> *)data)->add (t))
15924 : ;
15925 : else
15926 11574858 : *walk_subtrees = 0;
15927 : }
15928 :
15929 : /* Stop at types, decls, constants like copy_tree_r. */
15930 2787046178 : else if (TREE_CODE_CLASS (code) == tcc_type
15931 : || TREE_CODE_CLASS (code) == tcc_declaration
15932 2787046178 : || TREE_CODE_CLASS (code) == tcc_constant)
15933 1726239336 : *walk_subtrees = 0;
15934 :
15935 : /* Cope with the statement expression extension. */
15936 1060806842 : else if (code == STATEMENT_LIST)
15937 : ;
15938 :
15939 : /* Leave the bulk of the work to copy_tree_r itself. */
15940 : else
15941 1060757198 : copy_tree_r (tp, walk_subtrees, NULL);
15942 :
15943 2798621036 : return NULL_TREE;
15944 : }
15945 :
15946 : /* Callback for walk_tree to unshare most of the shared trees rooted at *TP.
15947 : If *TP has been visited already, then *TP is deeply copied by calling
15948 : mostly_copy_tree_r. DATA is passed to mostly_copy_tree_r unmodified. */
15949 :
15950 : static tree
15951 285379459 : copy_if_shared_r (tree *tp, int *walk_subtrees, void *data)
15952 : {
15953 285379459 : tree t = *tp;
15954 285379459 : enum tree_code code = TREE_CODE (t);
15955 :
15956 : /* Skip types, decls, and constants. But we do want to look at their
15957 : types and the bounds of types. Mark them as visited so we properly
15958 : unmark their subtrees on the unmark pass. If we've already seen them,
15959 : don't look down further. */
15960 285379459 : if (TREE_CODE_CLASS (code) == tcc_type
15961 : || TREE_CODE_CLASS (code) == tcc_declaration
15962 285379459 : || TREE_CODE_CLASS (code) == tcc_constant)
15963 : {
15964 135638736 : if (TREE_VISITED (t))
15965 82971043 : *walk_subtrees = 0;
15966 : else
15967 52667693 : TREE_VISITED (t) = 1;
15968 : }
15969 :
15970 : /* If this node has been visited already, unshare it and don't look
15971 : any deeper. */
15972 149740723 : else if (TREE_VISITED (t))
15973 : {
15974 1753638 : walk_tree (tp, mostly_copy_tree_r, data, NULL);
15975 1753638 : *walk_subtrees = 0;
15976 : }
15977 :
15978 : /* Otherwise, mark the node as visited and keep looking. */
15979 : else
15980 147987085 : TREE_VISITED (t) = 1;
15981 :
15982 285379459 : return NULL_TREE;
15983 : }
15984 :
15985 : /* Unshare most of the shared trees rooted at *TP. DATA is passed to the
15986 : copy_if_shared_r callback unmodified. */
15987 :
15988 : void
15989 9106008 : copy_if_shared (tree *tp, void *data)
15990 : {
15991 9106008 : walk_tree (tp, copy_if_shared_r, data, NULL);
15992 9106008 : }
15993 :
15994 : /* Unconditionally make an unshared copy of EXPR. This is used when using
15995 : stored expressions which span multiple functions, such as BINFO_VTABLE,
15996 : as the normal unsharing process can't tell that they're shared. */
15997 :
15998 : tree
15999 1563582748 : unshare_expr (tree expr)
16000 : {
16001 1563582748 : walk_tree (&expr, mostly_copy_tree_r, NULL, NULL);
16002 1563582748 : return expr;
16003 : }
16004 :
16005 : /* Worker for unshare_expr_without_location. */
16006 :
16007 : static tree
16008 15409255 : prune_expr_location (tree *tp, int *walk_subtrees, void *)
16009 : {
16010 15409255 : if (EXPR_P (*tp))
16011 7728080 : SET_EXPR_LOCATION (*tp, UNKNOWN_LOCATION);
16012 : else
16013 7681175 : *walk_subtrees = 0;
16014 15409255 : return NULL_TREE;
16015 : }
16016 :
16017 : /* Similar to unshare_expr but also prune all expression locations
16018 : from EXPR. */
16019 :
16020 : tree
16021 24495326 : unshare_expr_without_location (tree expr)
16022 : {
16023 24495326 : walk_tree (&expr, mostly_copy_tree_r, NULL, NULL);
16024 24495326 : if (EXPR_P (expr))
16025 5273012 : walk_tree (&expr, prune_expr_location, NULL, NULL);
16026 24495326 : return expr;
16027 : }
16028 :
16029 : void
16030 262609 : tree_cc_finalize (void)
16031 : {
16032 262609 : clear_nonstandard_integer_type_cache ();
16033 262609 : vec_free (bitint_type_cache);
16034 262609 : }
16035 :
16036 : void
16037 234 : gt_ggc_mx (tree_raw_data *x)
16038 : {
16039 234 : gt_ggc_m_9tree_node (x->typed.type);
16040 234 : gt_ggc_m_9tree_node (x->owner);
16041 234 : }
16042 :
16043 : void
16044 12 : gt_pch_nx (tree_raw_data *x)
16045 : {
16046 12 : gt_pch_n_9tree_node (x->typed.type);
16047 12 : gt_pch_n_9tree_node (x->owner);
16048 12 : }
16049 :
16050 : /* For PCH we guarantee that RAW_DATA_CST's RAW_DATA_OWNER is a STRING_CST and
16051 : RAW_DATA_POINTER points into it. We don't want to save/restore
16052 : RAW_DATA_POINTER on its own but want to restore it pointing at the same
16053 : offset of the STRING_CST as before. */
16054 :
16055 : void
16056 12 : gt_pch_nx (tree_raw_data *x, gt_pointer_operator op, void *cookie)
16057 : {
16058 12 : op (&x->typed.type, NULL, cookie);
16059 12 : gcc_checking_assert (x->owner
16060 : && TREE_CODE (x->owner) == STRING_CST
16061 : && x->str >= TREE_STRING_POINTER (x->owner)
16062 : && (x->str + x->length
16063 : <= (TREE_STRING_POINTER (x->owner)
16064 : + TREE_STRING_LENGTH (x->owner))));
16065 12 : ptrdiff_t off = x->str - (const char *) (x->owner);
16066 12 : tree owner = x->owner;
16067 12 : op (&x->owner, NULL, cookie);
16068 12 : x->owner = owner;
16069 : /* The above op call relocates x->owner and remembers the address
16070 : for relocation e.g. if the compiler is position independent.
16071 : We then restore x->owner back to its previous value and call
16072 : op again, for x->owner itself this just repeats (uselessly) what
16073 : the first call did, but as the second argument is now non-NULL
16074 : and different, it also arranges for &x->str to be noted for the
16075 : PIE relocation. */
16076 12 : op (&x->owner, &x->str, cookie);
16077 12 : x->str = (const char *) (x->owner) + off;
16078 12 : }
16079 :
16080 : #if CHECKING_P
16081 :
16082 : namespace selftest {
16083 :
16084 : /* Selftests for tree. */
16085 :
16086 : /* Verify that integer constants are sane. */
16087 :
16088 : static void
16089 4 : test_integer_constants ()
16090 : {
16091 4 : ASSERT_TRUE (integer_type_node != NULL);
16092 4 : ASSERT_TRUE (build_int_cst (integer_type_node, 0) != NULL);
16093 :
16094 4 : tree type = integer_type_node;
16095 :
16096 4 : tree zero = build_zero_cst (type);
16097 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (zero));
16098 4 : ASSERT_EQ (type, TREE_TYPE (zero));
16099 :
16100 4 : tree one = build_int_cst (type, 1);
16101 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (one));
16102 4 : ASSERT_EQ (type, TREE_TYPE (zero));
16103 4 : }
16104 :
16105 : /* Verify identifiers. */
16106 :
16107 : static void
16108 4 : test_identifiers ()
16109 : {
16110 4 : tree identifier = get_identifier ("foo");
16111 4 : ASSERT_EQ (3, IDENTIFIER_LENGTH (identifier));
16112 4 : ASSERT_STREQ ("foo", IDENTIFIER_POINTER (identifier));
16113 4 : }
16114 :
16115 : /* Verify LABEL_DECL. */
16116 :
16117 : static void
16118 4 : test_labels ()
16119 : {
16120 4 : tree identifier = get_identifier ("err");
16121 4 : tree label_decl = build_decl (UNKNOWN_LOCATION, LABEL_DECL,
16122 : identifier, void_type_node);
16123 4 : ASSERT_EQ (-1, LABEL_DECL_UID (label_decl));
16124 4 : ASSERT_FALSE (FORCED_LABEL (label_decl));
16125 4 : }
16126 :
16127 : /* Return a new VECTOR_CST node whose type is TYPE and whose values
16128 : are given by VALS. */
16129 :
16130 : static tree
16131 40 : build_vector (tree type, const vec<tree> &vals MEM_STAT_DECL)
16132 : {
16133 80 : gcc_assert (known_eq (vals.length (), TYPE_VECTOR_SUBPARTS (type)));
16134 40 : tree_vector_builder builder (type, vals.length (), 1);
16135 40 : builder.splice (vals);
16136 40 : return builder.build ();
16137 40 : }
16138 :
16139 : /* Check that VECTOR_CST ACTUAL contains the elements in EXPECTED. */
16140 :
16141 : static void
16142 40 : check_vector_cst (const vec<tree> &expected, tree actual)
16143 : {
16144 80 : ASSERT_KNOWN_EQ (expected.length (),
16145 : TYPE_VECTOR_SUBPARTS (TREE_TYPE (actual)));
16146 360 : for (unsigned int i = 0; i < expected.length (); ++i)
16147 320 : ASSERT_EQ (wi::to_wide (expected[i]),
16148 : wi::to_wide (vector_cst_elt (actual, i)));
16149 40 : }
16150 :
16151 : /* Check that VECTOR_CST ACTUAL contains NPATTERNS duplicated elements,
16152 : and that its elements match EXPECTED. */
16153 :
16154 : static void
16155 8 : check_vector_cst_duplicate (const vec<tree> &expected, tree actual,
16156 : unsigned int npatterns)
16157 : {
16158 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
16159 8 : ASSERT_EQ (1, VECTOR_CST_NELTS_PER_PATTERN (actual));
16160 8 : ASSERT_EQ (npatterns, vector_cst_encoded_nelts (actual));
16161 8 : ASSERT_TRUE (VECTOR_CST_DUPLICATE_P (actual));
16162 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
16163 8 : check_vector_cst (expected, actual);
16164 8 : }
16165 :
16166 : /* Check that VECTOR_CST ACTUAL contains NPATTERNS foreground elements
16167 : and NPATTERNS background elements, and that its elements match
16168 : EXPECTED. */
16169 :
16170 : static void
16171 8 : check_vector_cst_fill (const vec<tree> &expected, tree actual,
16172 : unsigned int npatterns)
16173 : {
16174 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
16175 8 : ASSERT_EQ (2, VECTOR_CST_NELTS_PER_PATTERN (actual));
16176 8 : ASSERT_EQ (2 * npatterns, vector_cst_encoded_nelts (actual));
16177 8 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
16178 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
16179 8 : check_vector_cst (expected, actual);
16180 8 : }
16181 :
16182 : /* Check that VECTOR_CST ACTUAL contains NPATTERNS stepped patterns,
16183 : and that its elements match EXPECTED. */
16184 :
16185 : static void
16186 24 : check_vector_cst_stepped (const vec<tree> &expected, tree actual,
16187 : unsigned int npatterns)
16188 : {
16189 24 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
16190 24 : ASSERT_EQ (3, VECTOR_CST_NELTS_PER_PATTERN (actual));
16191 24 : ASSERT_EQ (3 * npatterns, vector_cst_encoded_nelts (actual));
16192 24 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
16193 24 : ASSERT_TRUE (VECTOR_CST_STEPPED_P (actual));
16194 24 : check_vector_cst (expected, actual);
16195 24 : }
16196 :
16197 : /* Test the creation of VECTOR_CSTs. */
16198 :
16199 : static void
16200 4 : test_vector_cst_patterns (ALONE_CXX_MEM_STAT_INFO)
16201 : {
16202 4 : auto_vec<tree, 8> elements (8);
16203 4 : elements.quick_grow (8);
16204 4 : tree element_type = build_nonstandard_integer_type (16, true);
16205 4 : tree vector_type = build_vector_type (element_type, 8);
16206 :
16207 : /* Test a simple linear series with a base of 0 and a step of 1:
16208 : { 0, 1, 2, 3, 4, 5, 6, 7 }. */
16209 36 : for (unsigned int i = 0; i < 8; ++i)
16210 32 : elements[i] = build_int_cst (element_type, i);
16211 4 : tree vector = build_vector (vector_type, elements PASS_MEM_STAT);
16212 4 : check_vector_cst_stepped (elements, vector, 1);
16213 :
16214 : /* Try the same with the first element replaced by 100:
16215 : { 100, 1, 2, 3, 4, 5, 6, 7 }. */
16216 4 : elements[0] = build_int_cst (element_type, 100);
16217 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16218 4 : check_vector_cst_stepped (elements, vector, 1);
16219 :
16220 : /* Try a series that wraps around.
16221 : { 100, 65531, 65532, 65533, 65534, 65535, 0, 1 }. */
16222 32 : for (unsigned int i = 1; i < 8; ++i)
16223 28 : elements[i] = build_int_cst (element_type, (65530 + i) & 0xffff);
16224 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16225 4 : check_vector_cst_stepped (elements, vector, 1);
16226 :
16227 : /* Try a downward series:
16228 : { 100, 79, 78, 77, 76, 75, 75, 73 }. */
16229 32 : for (unsigned int i = 1; i < 8; ++i)
16230 28 : elements[i] = build_int_cst (element_type, 80 - i);
16231 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16232 4 : check_vector_cst_stepped (elements, vector, 1);
16233 :
16234 : /* Try two interleaved series with different bases and steps:
16235 : { 100, 53, 66, 206, 62, 212, 58, 218 }. */
16236 4 : elements[1] = build_int_cst (element_type, 53);
16237 16 : for (unsigned int i = 2; i < 8; i += 2)
16238 : {
16239 12 : elements[i] = build_int_cst (element_type, 70 - i * 2);
16240 12 : elements[i + 1] = build_int_cst (element_type, 200 + i * 3);
16241 : }
16242 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16243 4 : check_vector_cst_stepped (elements, vector, 2);
16244 :
16245 : /* Try a duplicated value:
16246 : { 100, 100, 100, 100, 100, 100, 100, 100 }. */
16247 32 : for (unsigned int i = 1; i < 8; ++i)
16248 28 : elements[i] = elements[0];
16249 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16250 4 : check_vector_cst_duplicate (elements, vector, 1);
16251 :
16252 : /* Try an interleaved duplicated value:
16253 : { 100, 55, 100, 55, 100, 55, 100, 55 }. */
16254 4 : elements[1] = build_int_cst (element_type, 55);
16255 28 : for (unsigned int i = 2; i < 8; ++i)
16256 24 : elements[i] = elements[i - 2];
16257 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16258 4 : check_vector_cst_duplicate (elements, vector, 2);
16259 :
16260 : /* Try a duplicated value with 2 exceptions
16261 : { 41, 97, 100, 55, 100, 55, 100, 55 }. */
16262 4 : elements[0] = build_int_cst (element_type, 41);
16263 4 : elements[1] = build_int_cst (element_type, 97);
16264 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16265 4 : check_vector_cst_fill (elements, vector, 2);
16266 :
16267 : /* Try with and without a step
16268 : { 41, 97, 100, 21, 100, 35, 100, 49 }. */
16269 16 : for (unsigned int i = 3; i < 8; i += 2)
16270 12 : elements[i] = build_int_cst (element_type, i * 7);
16271 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16272 4 : check_vector_cst_stepped (elements, vector, 2);
16273 :
16274 : /* Try a fully-general constant:
16275 : { 41, 97, 100, 21, 100, 9990, 100, 49 }. */
16276 4 : elements[5] = build_int_cst (element_type, 9990);
16277 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16278 4 : check_vector_cst_fill (elements, vector, 4);
16279 4 : }
16280 :
16281 : /* Verify that STRIP_NOPS (NODE) is EXPECTED.
16282 : Helper function for test_location_wrappers, to deal with STRIP_NOPS
16283 : modifying its argument in-place. */
16284 :
16285 : static void
16286 12 : check_strip_nops (tree node, tree expected)
16287 : {
16288 12 : STRIP_NOPS (node);
16289 12 : ASSERT_EQ (expected, node);
16290 12 : }
16291 :
16292 : /* Verify location wrappers. */
16293 :
16294 : static void
16295 4 : test_location_wrappers ()
16296 : {
16297 4 : location_t loc = BUILTINS_LOCATION;
16298 :
16299 4 : ASSERT_EQ (NULL_TREE, maybe_wrap_with_location (NULL_TREE, loc));
16300 :
16301 : /* Wrapping a constant. */
16302 4 : tree int_cst = build_int_cst (integer_type_node, 42);
16303 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_cst));
16304 4 : ASSERT_FALSE (location_wrapper_p (int_cst));
16305 :
16306 4 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
16307 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
16308 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_cst));
16309 4 : ASSERT_EQ (int_cst, tree_strip_any_location_wrapper (wrapped_int_cst));
16310 :
16311 : /* We shouldn't add wrapper nodes for UNKNOWN_LOCATION. */
16312 4 : ASSERT_EQ (int_cst, maybe_wrap_with_location (int_cst, UNKNOWN_LOCATION));
16313 :
16314 : /* We shouldn't add wrapper nodes for nodes that CAN_HAVE_LOCATION_P. */
16315 4 : tree cast = build1 (NOP_EXPR, char_type_node, int_cst);
16316 4 : ASSERT_TRUE (CAN_HAVE_LOCATION_P (cast));
16317 4 : ASSERT_EQ (cast, maybe_wrap_with_location (cast, loc));
16318 :
16319 : /* Wrapping a STRING_CST. */
16320 4 : tree string_cst = build_string (4, "foo");
16321 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (string_cst));
16322 4 : ASSERT_FALSE (location_wrapper_p (string_cst));
16323 :
16324 4 : tree wrapped_string_cst = maybe_wrap_with_location (string_cst, loc);
16325 4 : ASSERT_TRUE (location_wrapper_p (wrapped_string_cst));
16326 4 : ASSERT_EQ (VIEW_CONVERT_EXPR, TREE_CODE (wrapped_string_cst));
16327 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_string_cst));
16328 4 : ASSERT_EQ (string_cst, tree_strip_any_location_wrapper (wrapped_string_cst));
16329 :
16330 :
16331 : /* Wrapping a variable. */
16332 4 : tree int_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
16333 : get_identifier ("some_int_var"),
16334 : integer_type_node);
16335 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_var));
16336 4 : ASSERT_FALSE (location_wrapper_p (int_var));
16337 :
16338 4 : tree wrapped_int_var = maybe_wrap_with_location (int_var, loc);
16339 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_var));
16340 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_var));
16341 4 : ASSERT_EQ (int_var, tree_strip_any_location_wrapper (wrapped_int_var));
16342 :
16343 : /* Verify that "reinterpret_cast<int>(some_int_var)" is not a location
16344 : wrapper. */
16345 4 : tree r_cast = build1 (NON_LVALUE_EXPR, integer_type_node, int_var);
16346 4 : ASSERT_FALSE (location_wrapper_p (r_cast));
16347 4 : ASSERT_EQ (r_cast, tree_strip_any_location_wrapper (r_cast));
16348 :
16349 : /* Verify that STRIP_NOPS removes wrappers. */
16350 4 : check_strip_nops (wrapped_int_cst, int_cst);
16351 4 : check_strip_nops (wrapped_string_cst, string_cst);
16352 4 : check_strip_nops (wrapped_int_var, int_var);
16353 4 : }
16354 :
16355 : /* Test various tree predicates. Verify that location wrappers don't
16356 : affect the results. */
16357 :
16358 : static void
16359 4 : test_predicates ()
16360 : {
16361 : /* Build various constants and wrappers around them. */
16362 :
16363 4 : location_t loc = BUILTINS_LOCATION;
16364 :
16365 4 : tree i_0 = build_int_cst (integer_type_node, 0);
16366 4 : tree wr_i_0 = maybe_wrap_with_location (i_0, loc);
16367 :
16368 4 : tree i_1 = build_int_cst (integer_type_node, 1);
16369 4 : tree wr_i_1 = maybe_wrap_with_location (i_1, loc);
16370 :
16371 4 : tree i_m1 = build_int_cst (integer_type_node, -1);
16372 4 : tree wr_i_m1 = maybe_wrap_with_location (i_m1, loc);
16373 :
16374 4 : tree f_0 = build_real_from_int_cst (float_type_node, i_0);
16375 4 : tree wr_f_0 = maybe_wrap_with_location (f_0, loc);
16376 4 : tree f_1 = build_real_from_int_cst (float_type_node, i_1);
16377 4 : tree wr_f_1 = maybe_wrap_with_location (f_1, loc);
16378 4 : tree f_m1 = build_real_from_int_cst (float_type_node, i_m1);
16379 4 : tree wr_f_m1 = maybe_wrap_with_location (f_m1, loc);
16380 :
16381 4 : tree c_i_0 = build_complex (NULL_TREE, i_0, i_0);
16382 4 : tree c_i_1 = build_complex (NULL_TREE, i_1, i_0);
16383 4 : tree c_i_m1 = build_complex (NULL_TREE, i_m1, i_0);
16384 :
16385 4 : tree c_f_0 = build_complex (NULL_TREE, f_0, f_0);
16386 4 : tree c_f_1 = build_complex (NULL_TREE, f_1, f_0);
16387 4 : tree c_f_m1 = build_complex (NULL_TREE, f_m1, f_0);
16388 :
16389 : /* TODO: vector constants. */
16390 :
16391 : /* Test integer_onep. */
16392 4 : ASSERT_FALSE (integer_onep (i_0));
16393 4 : ASSERT_FALSE (integer_onep (wr_i_0));
16394 4 : ASSERT_TRUE (integer_onep (i_1));
16395 4 : ASSERT_TRUE (integer_onep (wr_i_1));
16396 4 : ASSERT_FALSE (integer_onep (i_m1));
16397 4 : ASSERT_FALSE (integer_onep (wr_i_m1));
16398 4 : ASSERT_FALSE (integer_onep (f_0));
16399 4 : ASSERT_FALSE (integer_onep (wr_f_0));
16400 4 : ASSERT_FALSE (integer_onep (f_1));
16401 4 : ASSERT_FALSE (integer_onep (wr_f_1));
16402 4 : ASSERT_FALSE (integer_onep (f_m1));
16403 4 : ASSERT_FALSE (integer_onep (wr_f_m1));
16404 4 : ASSERT_FALSE (integer_onep (c_i_0));
16405 4 : ASSERT_TRUE (integer_onep (c_i_1));
16406 4 : ASSERT_FALSE (integer_onep (c_i_m1));
16407 4 : ASSERT_FALSE (integer_onep (c_f_0));
16408 4 : ASSERT_FALSE (integer_onep (c_f_1));
16409 4 : ASSERT_FALSE (integer_onep (c_f_m1));
16410 :
16411 : /* Test integer_zerop. */
16412 4 : ASSERT_TRUE (integer_zerop (i_0));
16413 4 : ASSERT_TRUE (integer_zerop (wr_i_0));
16414 4 : ASSERT_FALSE (integer_zerop (i_1));
16415 4 : ASSERT_FALSE (integer_zerop (wr_i_1));
16416 4 : ASSERT_FALSE (integer_zerop (i_m1));
16417 4 : ASSERT_FALSE (integer_zerop (wr_i_m1));
16418 4 : ASSERT_FALSE (integer_zerop (f_0));
16419 4 : ASSERT_FALSE (integer_zerop (wr_f_0));
16420 4 : ASSERT_FALSE (integer_zerop (f_1));
16421 4 : ASSERT_FALSE (integer_zerop (wr_f_1));
16422 4 : ASSERT_FALSE (integer_zerop (f_m1));
16423 4 : ASSERT_FALSE (integer_zerop (wr_f_m1));
16424 4 : ASSERT_TRUE (integer_zerop (c_i_0));
16425 4 : ASSERT_FALSE (integer_zerop (c_i_1));
16426 4 : ASSERT_FALSE (integer_zerop (c_i_m1));
16427 4 : ASSERT_FALSE (integer_zerop (c_f_0));
16428 4 : ASSERT_FALSE (integer_zerop (c_f_1));
16429 4 : ASSERT_FALSE (integer_zerop (c_f_m1));
16430 :
16431 : /* Test integer_all_onesp. */
16432 4 : ASSERT_FALSE (integer_all_onesp (i_0));
16433 4 : ASSERT_FALSE (integer_all_onesp (wr_i_0));
16434 4 : ASSERT_FALSE (integer_all_onesp (i_1));
16435 4 : ASSERT_FALSE (integer_all_onesp (wr_i_1));
16436 4 : ASSERT_TRUE (integer_all_onesp (i_m1));
16437 4 : ASSERT_TRUE (integer_all_onesp (wr_i_m1));
16438 4 : ASSERT_FALSE (integer_all_onesp (f_0));
16439 4 : ASSERT_FALSE (integer_all_onesp (wr_f_0));
16440 4 : ASSERT_FALSE (integer_all_onesp (f_1));
16441 4 : ASSERT_FALSE (integer_all_onesp (wr_f_1));
16442 4 : ASSERT_FALSE (integer_all_onesp (f_m1));
16443 4 : ASSERT_FALSE (integer_all_onesp (wr_f_m1));
16444 4 : ASSERT_FALSE (integer_all_onesp (c_i_0));
16445 4 : ASSERT_FALSE (integer_all_onesp (c_i_1));
16446 4 : ASSERT_FALSE (integer_all_onesp (c_i_m1));
16447 4 : ASSERT_FALSE (integer_all_onesp (c_f_0));
16448 4 : ASSERT_FALSE (integer_all_onesp (c_f_1));
16449 4 : ASSERT_FALSE (integer_all_onesp (c_f_m1));
16450 :
16451 : /* Test integer_minus_onep. */
16452 4 : ASSERT_FALSE (integer_minus_onep (i_0));
16453 4 : ASSERT_FALSE (integer_minus_onep (wr_i_0));
16454 4 : ASSERT_FALSE (integer_minus_onep (i_1));
16455 4 : ASSERT_FALSE (integer_minus_onep (wr_i_1));
16456 4 : ASSERT_TRUE (integer_minus_onep (i_m1));
16457 4 : ASSERT_TRUE (integer_minus_onep (wr_i_m1));
16458 4 : ASSERT_FALSE (integer_minus_onep (f_0));
16459 4 : ASSERT_FALSE (integer_minus_onep (wr_f_0));
16460 4 : ASSERT_FALSE (integer_minus_onep (f_1));
16461 4 : ASSERT_FALSE (integer_minus_onep (wr_f_1));
16462 4 : ASSERT_FALSE (integer_minus_onep (f_m1));
16463 4 : ASSERT_FALSE (integer_minus_onep (wr_f_m1));
16464 4 : ASSERT_FALSE (integer_minus_onep (c_i_0));
16465 4 : ASSERT_FALSE (integer_minus_onep (c_i_1));
16466 4 : ASSERT_TRUE (integer_minus_onep (c_i_m1));
16467 4 : ASSERT_FALSE (integer_minus_onep (c_f_0));
16468 4 : ASSERT_FALSE (integer_minus_onep (c_f_1));
16469 4 : ASSERT_FALSE (integer_minus_onep (c_f_m1));
16470 :
16471 : /* Test integer_each_onep. */
16472 4 : ASSERT_FALSE (integer_each_onep (i_0));
16473 4 : ASSERT_FALSE (integer_each_onep (wr_i_0));
16474 4 : ASSERT_TRUE (integer_each_onep (i_1));
16475 4 : ASSERT_TRUE (integer_each_onep (wr_i_1));
16476 4 : ASSERT_FALSE (integer_each_onep (i_m1));
16477 4 : ASSERT_FALSE (integer_each_onep (wr_i_m1));
16478 4 : ASSERT_FALSE (integer_each_onep (f_0));
16479 4 : ASSERT_FALSE (integer_each_onep (wr_f_0));
16480 4 : ASSERT_FALSE (integer_each_onep (f_1));
16481 4 : ASSERT_FALSE (integer_each_onep (wr_f_1));
16482 4 : ASSERT_FALSE (integer_each_onep (f_m1));
16483 4 : ASSERT_FALSE (integer_each_onep (wr_f_m1));
16484 4 : ASSERT_FALSE (integer_each_onep (c_i_0));
16485 4 : ASSERT_FALSE (integer_each_onep (c_i_1));
16486 4 : ASSERT_FALSE (integer_each_onep (c_i_m1));
16487 4 : ASSERT_FALSE (integer_each_onep (c_f_0));
16488 4 : ASSERT_FALSE (integer_each_onep (c_f_1));
16489 4 : ASSERT_FALSE (integer_each_onep (c_f_m1));
16490 :
16491 : /* Test integer_truep. */
16492 4 : ASSERT_FALSE (integer_truep (i_0));
16493 4 : ASSERT_FALSE (integer_truep (wr_i_0));
16494 4 : ASSERT_TRUE (integer_truep (i_1));
16495 4 : ASSERT_TRUE (integer_truep (wr_i_1));
16496 4 : ASSERT_FALSE (integer_truep (i_m1));
16497 4 : ASSERT_FALSE (integer_truep (wr_i_m1));
16498 4 : ASSERT_FALSE (integer_truep (f_0));
16499 4 : ASSERT_FALSE (integer_truep (wr_f_0));
16500 4 : ASSERT_FALSE (integer_truep (f_1));
16501 4 : ASSERT_FALSE (integer_truep (wr_f_1));
16502 4 : ASSERT_FALSE (integer_truep (f_m1));
16503 4 : ASSERT_FALSE (integer_truep (wr_f_m1));
16504 4 : ASSERT_FALSE (integer_truep (c_i_0));
16505 4 : ASSERT_TRUE (integer_truep (c_i_1));
16506 4 : ASSERT_FALSE (integer_truep (c_i_m1));
16507 4 : ASSERT_FALSE (integer_truep (c_f_0));
16508 4 : ASSERT_FALSE (integer_truep (c_f_1));
16509 4 : ASSERT_FALSE (integer_truep (c_f_m1));
16510 :
16511 : /* Test integer_nonzerop. */
16512 4 : ASSERT_FALSE (integer_nonzerop (i_0));
16513 4 : ASSERT_FALSE (integer_nonzerop (wr_i_0));
16514 4 : ASSERT_TRUE (integer_nonzerop (i_1));
16515 4 : ASSERT_TRUE (integer_nonzerop (wr_i_1));
16516 4 : ASSERT_TRUE (integer_nonzerop (i_m1));
16517 4 : ASSERT_TRUE (integer_nonzerop (wr_i_m1));
16518 4 : ASSERT_FALSE (integer_nonzerop (f_0));
16519 4 : ASSERT_FALSE (integer_nonzerop (wr_f_0));
16520 4 : ASSERT_FALSE (integer_nonzerop (f_1));
16521 4 : ASSERT_FALSE (integer_nonzerop (wr_f_1));
16522 4 : ASSERT_FALSE (integer_nonzerop (f_m1));
16523 4 : ASSERT_FALSE (integer_nonzerop (wr_f_m1));
16524 4 : ASSERT_FALSE (integer_nonzerop (c_i_0));
16525 4 : ASSERT_TRUE (integer_nonzerop (c_i_1));
16526 4 : ASSERT_TRUE (integer_nonzerop (c_i_m1));
16527 4 : ASSERT_FALSE (integer_nonzerop (c_f_0));
16528 4 : ASSERT_FALSE (integer_nonzerop (c_f_1));
16529 4 : ASSERT_FALSE (integer_nonzerop (c_f_m1));
16530 :
16531 : /* Test real_zerop. */
16532 4 : ASSERT_FALSE (real_zerop (i_0));
16533 4 : ASSERT_FALSE (real_zerop (wr_i_0));
16534 4 : ASSERT_FALSE (real_zerop (i_1));
16535 4 : ASSERT_FALSE (real_zerop (wr_i_1));
16536 4 : ASSERT_FALSE (real_zerop (i_m1));
16537 4 : ASSERT_FALSE (real_zerop (wr_i_m1));
16538 4 : ASSERT_TRUE (real_zerop (f_0));
16539 4 : ASSERT_TRUE (real_zerop (wr_f_0));
16540 4 : ASSERT_FALSE (real_zerop (f_1));
16541 4 : ASSERT_FALSE (real_zerop (wr_f_1));
16542 4 : ASSERT_FALSE (real_zerop (f_m1));
16543 4 : ASSERT_FALSE (real_zerop (wr_f_m1));
16544 4 : ASSERT_FALSE (real_zerop (c_i_0));
16545 4 : ASSERT_FALSE (real_zerop (c_i_1));
16546 4 : ASSERT_FALSE (real_zerop (c_i_m1));
16547 4 : ASSERT_TRUE (real_zerop (c_f_0));
16548 4 : ASSERT_FALSE (real_zerop (c_f_1));
16549 4 : ASSERT_FALSE (real_zerop (c_f_m1));
16550 :
16551 : /* Test real_onep. */
16552 4 : ASSERT_FALSE (real_onep (i_0));
16553 4 : ASSERT_FALSE (real_onep (wr_i_0));
16554 4 : ASSERT_FALSE (real_onep (i_1));
16555 4 : ASSERT_FALSE (real_onep (wr_i_1));
16556 4 : ASSERT_FALSE (real_onep (i_m1));
16557 4 : ASSERT_FALSE (real_onep (wr_i_m1));
16558 4 : ASSERT_FALSE (real_onep (f_0));
16559 4 : ASSERT_FALSE (real_onep (wr_f_0));
16560 4 : ASSERT_TRUE (real_onep (f_1));
16561 4 : ASSERT_TRUE (real_onep (wr_f_1));
16562 4 : ASSERT_FALSE (real_onep (f_m1));
16563 4 : ASSERT_FALSE (real_onep (wr_f_m1));
16564 4 : ASSERT_FALSE (real_onep (c_i_0));
16565 4 : ASSERT_FALSE (real_onep (c_i_1));
16566 4 : ASSERT_FALSE (real_onep (c_i_m1));
16567 4 : ASSERT_FALSE (real_onep (c_f_0));
16568 4 : ASSERT_TRUE (real_onep (c_f_1));
16569 4 : ASSERT_FALSE (real_onep (c_f_m1));
16570 :
16571 : /* Test real_minus_onep. */
16572 4 : ASSERT_FALSE (real_minus_onep (i_0));
16573 4 : ASSERT_FALSE (real_minus_onep (wr_i_0));
16574 4 : ASSERT_FALSE (real_minus_onep (i_1));
16575 4 : ASSERT_FALSE (real_minus_onep (wr_i_1));
16576 4 : ASSERT_FALSE (real_minus_onep (i_m1));
16577 4 : ASSERT_FALSE (real_minus_onep (wr_i_m1));
16578 4 : ASSERT_FALSE (real_minus_onep (f_0));
16579 4 : ASSERT_FALSE (real_minus_onep (wr_f_0));
16580 4 : ASSERT_FALSE (real_minus_onep (f_1));
16581 4 : ASSERT_FALSE (real_minus_onep (wr_f_1));
16582 4 : ASSERT_TRUE (real_minus_onep (f_m1));
16583 4 : ASSERT_TRUE (real_minus_onep (wr_f_m1));
16584 4 : ASSERT_FALSE (real_minus_onep (c_i_0));
16585 4 : ASSERT_FALSE (real_minus_onep (c_i_1));
16586 4 : ASSERT_FALSE (real_minus_onep (c_i_m1));
16587 4 : ASSERT_FALSE (real_minus_onep (c_f_0));
16588 4 : ASSERT_FALSE (real_minus_onep (c_f_1));
16589 4 : ASSERT_TRUE (real_minus_onep (c_f_m1));
16590 :
16591 : /* Test zerop. */
16592 4 : ASSERT_TRUE (zerop (i_0));
16593 4 : ASSERT_TRUE (zerop (wr_i_0));
16594 4 : ASSERT_FALSE (zerop (i_1));
16595 4 : ASSERT_FALSE (zerop (wr_i_1));
16596 4 : ASSERT_FALSE (zerop (i_m1));
16597 4 : ASSERT_FALSE (zerop (wr_i_m1));
16598 4 : ASSERT_TRUE (zerop (f_0));
16599 4 : ASSERT_TRUE (zerop (wr_f_0));
16600 4 : ASSERT_FALSE (zerop (f_1));
16601 4 : ASSERT_FALSE (zerop (wr_f_1));
16602 4 : ASSERT_FALSE (zerop (f_m1));
16603 4 : ASSERT_FALSE (zerop (wr_f_m1));
16604 4 : ASSERT_TRUE (zerop (c_i_0));
16605 4 : ASSERT_FALSE (zerop (c_i_1));
16606 4 : ASSERT_FALSE (zerop (c_i_m1));
16607 4 : ASSERT_TRUE (zerop (c_f_0));
16608 4 : ASSERT_FALSE (zerop (c_f_1));
16609 4 : ASSERT_FALSE (zerop (c_f_m1));
16610 :
16611 : /* Test tree_expr_nonnegative_p. */
16612 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_0));
16613 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_0));
16614 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_1));
16615 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_1));
16616 4 : ASSERT_FALSE (tree_expr_nonnegative_p (i_m1));
16617 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_i_m1));
16618 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_0));
16619 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_0));
16620 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_1));
16621 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_1));
16622 4 : ASSERT_FALSE (tree_expr_nonnegative_p (f_m1));
16623 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_f_m1));
16624 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_0));
16625 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_1));
16626 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_m1));
16627 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_0));
16628 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_1));
16629 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_m1));
16630 :
16631 : /* Test tree_expr_nonzero_p. */
16632 4 : ASSERT_FALSE (tree_expr_nonzero_p (i_0));
16633 4 : ASSERT_FALSE (tree_expr_nonzero_p (wr_i_0));
16634 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_1));
16635 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_1));
16636 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_m1));
16637 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_m1));
16638 :
16639 : /* Test integer_valued_real_p. */
16640 4 : ASSERT_FALSE (integer_valued_real_p (i_0));
16641 4 : ASSERT_TRUE (integer_valued_real_p (f_0));
16642 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_0));
16643 4 : ASSERT_TRUE (integer_valued_real_p (f_1));
16644 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_1));
16645 :
16646 : /* Test integer_pow2p. */
16647 4 : ASSERT_FALSE (integer_pow2p (i_0));
16648 4 : ASSERT_TRUE (integer_pow2p (i_1));
16649 4 : ASSERT_TRUE (integer_pow2p (wr_i_1));
16650 :
16651 : /* Test uniform_integer_cst_p. */
16652 4 : ASSERT_TRUE (uniform_integer_cst_p (i_0));
16653 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_0));
16654 4 : ASSERT_TRUE (uniform_integer_cst_p (i_1));
16655 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_1));
16656 4 : ASSERT_TRUE (uniform_integer_cst_p (i_m1));
16657 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_m1));
16658 4 : ASSERT_FALSE (uniform_integer_cst_p (f_0));
16659 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_0));
16660 4 : ASSERT_FALSE (uniform_integer_cst_p (f_1));
16661 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_1));
16662 4 : ASSERT_FALSE (uniform_integer_cst_p (f_m1));
16663 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_m1));
16664 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_0));
16665 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_1));
16666 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_m1));
16667 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_0));
16668 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_1));
16669 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_m1));
16670 4 : }
16671 :
16672 : /* Check that string escaping works correctly. */
16673 :
16674 : static void
16675 4 : test_escaped_strings (void)
16676 : {
16677 4 : int saved_cutoff;
16678 4 : escaped_string msg;
16679 :
16680 4 : msg.escape (NULL);
16681 : /* ASSERT_STREQ does not accept NULL as a valid test
16682 : result, so we have to use ASSERT_EQ instead. */
16683 4 : ASSERT_EQ (NULL, (const char *) msg);
16684 :
16685 4 : msg.escape ("");
16686 4 : ASSERT_STREQ ("", (const char *) msg);
16687 :
16688 4 : msg.escape ("foobar");
16689 4 : ASSERT_STREQ ("foobar", (const char *) msg);
16690 :
16691 : /* Ensure that we have -fmessage-length set to 0. */
16692 4 : pretty_printer *pp = global_dc->get_reference_printer ();
16693 4 : saved_cutoff = pp_line_cutoff (pp);
16694 4 : pp_line_cutoff (pp) = 0;
16695 :
16696 4 : msg.escape ("foo\nbar");
16697 4 : ASSERT_STREQ ("foo\\nbar", (const char *) msg);
16698 :
16699 4 : msg.escape ("\a\b\f\n\r\t\v");
16700 4 : ASSERT_STREQ ("\\a\\b\\f\\n\\r\\t\\v", (const char *) msg);
16701 :
16702 : /* Now repeat the tests with -fmessage-length set to 5. */
16703 4 : pp_line_cutoff (pp) = 5;
16704 :
16705 : /* Note that the newline is not translated into an escape. */
16706 4 : msg.escape ("foo\nbar");
16707 4 : ASSERT_STREQ ("foo\nbar", (const char *) msg);
16708 :
16709 4 : msg.escape ("\a\b\f\n\r\t\v");
16710 4 : ASSERT_STREQ ("\\a\\b\\f\n\\r\\t\\v", (const char *) msg);
16711 :
16712 : /* Restore the original message length setting. */
16713 4 : pp_line_cutoff (pp) = saved_cutoff;
16714 4 : }
16715 :
16716 : /* Run all of the selftests within this file. */
16717 :
16718 : void
16719 4 : tree_cc_tests ()
16720 : {
16721 4 : test_integer_constants ();
16722 4 : test_identifiers ();
16723 4 : test_labels ();
16724 4 : test_vector_cst_patterns ();
16725 4 : test_location_wrappers ();
16726 4 : test_predicates ();
16727 4 : test_escaped_strings ();
16728 4 : }
16729 :
16730 : } // namespace selftest
16731 :
16732 : #endif /* CHECKING_P */
16733 :
16734 : #include "gt-tree.h"
|