Branch data Line data Source code
1 : : /* Language-independent node constructors for parse phase of GNU compiler.
2 : : Copyright (C) 1987-2025 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 "tree.h"
36 : : #include "gimple.h"
37 : : #include "tree-pass.h"
38 : : #include "ssa.h"
39 : : #include "cgraph.h"
40 : : #include "diagnostic.h"
41 : : #include "flags.h"
42 : : #include "alias.h"
43 : : #include "fold-const.h"
44 : : #include "stor-layout.h"
45 : : #include "calls.h"
46 : : #include "attribs.h"
47 : : #include "toplev.h" /* get_random_seed */
48 : : #include "output.h"
49 : : #include "common/common-target.h"
50 : : #include "langhooks.h"
51 : : #include "tree-inline.h"
52 : : #include "tree-iterator.h"
53 : : #include "internal-fn.h"
54 : : #include "gimple-iterator.h"
55 : : #include "gimplify.h"
56 : : #include "tree-dfa.h"
57 : : #include "langhooks-def.h"
58 : : #include "tree-diagnostic.h"
59 : : #include "except.h"
60 : : #include "builtins.h"
61 : : #include "print-tree.h"
62 : : #include "ipa-utils.h"
63 : : #include "selftest.h"
64 : : #include "stringpool.h"
65 : : #include "attribs.h"
66 : : #include "rtl.h"
67 : : #include "regs.h"
68 : : #include "tree-vector-builder.h"
69 : : #include "gimple-fold.h"
70 : : #include "escaped_string.h"
71 : : #include "gimple-range.h"
72 : : #include "gomp-constants.h"
73 : : #include "dfp.h"
74 : : #include "asan.h"
75 : : #include "ubsan.h"
76 : :
77 : : /* Names of tree components.
78 : : Used for printing out the tree and error messages. */
79 : : #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
80 : : #define END_OF_BASE_TREE_CODES "@dummy",
81 : :
82 : : static const char *const tree_code_name[] = {
83 : : #include "all-tree.def"
84 : : };
85 : :
86 : : #undef DEFTREECODE
87 : : #undef END_OF_BASE_TREE_CODES
88 : :
89 : : /* Each tree code class has an associated string representation.
90 : : These must correspond to the tree_code_class entries. */
91 : :
92 : : const char *const tree_code_class_strings[] =
93 : : {
94 : : "exceptional",
95 : : "constant",
96 : : "type",
97 : : "declaration",
98 : : "reference",
99 : : "comparison",
100 : : "unary",
101 : : "binary",
102 : : "statement",
103 : : "vl_exp",
104 : : "expression"
105 : : };
106 : :
107 : : /* obstack.[ch] explicitly declined to prototype this. */
108 : : extern int _obstack_allocated_p (struct obstack *h, void *obj);
109 : :
110 : : /* Statistics-gathering stuff. */
111 : :
112 : : static uint64_t tree_code_counts[MAX_TREE_CODES];
113 : : uint64_t tree_node_counts[(int) all_kinds];
114 : : uint64_t tree_node_sizes[(int) all_kinds];
115 : :
116 : : /* Keep in sync with tree.h:enum tree_node_kind. */
117 : : static const char * const tree_node_kind_names[] = {
118 : : "decls",
119 : : "types",
120 : : "blocks",
121 : : "stmts",
122 : : "refs",
123 : : "exprs",
124 : : "constants",
125 : : "identifiers",
126 : : "vecs",
127 : : "binfos",
128 : : "ssa names",
129 : : "constructors",
130 : : "random kinds",
131 : : "lang_decl kinds",
132 : : "lang_type kinds",
133 : : "omp clauses",
134 : : };
135 : :
136 : : /* Unique id for next decl created. */
137 : : static GTY(()) int next_decl_uid;
138 : : /* Unique id for next type created. */
139 : : static GTY(()) unsigned next_type_uid = 1;
140 : : /* Unique id for next debug decl created. Use negative numbers,
141 : : to catch erroneous uses. */
142 : : static GTY(()) int next_debug_decl_uid;
143 : :
144 : : /* Since we cannot rehash a type after it is in the table, we have to
145 : : keep the hash code. */
146 : :
147 : : struct GTY((for_user)) type_hash {
148 : : unsigned long hash;
149 : : tree type;
150 : : };
151 : :
152 : : /* Initial size of the hash table (rounded to next prime). */
153 : : #define TYPE_HASH_INITIAL_SIZE 1000
154 : :
155 : : struct type_cache_hasher : ggc_cache_ptr_hash<type_hash>
156 : : {
157 : 6826482706 : static hashval_t hash (type_hash *t) { return t->hash; }
158 : : static bool equal (type_hash *a, type_hash *b);
159 : :
160 : : static int
161 : 1643163978 : keep_cache_entry (type_hash *&t)
162 : : {
163 : 1643163978 : return ggc_marked_p (t->type);
164 : : }
165 : : };
166 : :
167 : : /* Now here is the hash table. When recording a type, it is added to
168 : : the slot whose index is the hash code. Note that the hash table is
169 : : used for several kinds of types (function types, array types and
170 : : array index range types, for now). While all these live in the
171 : : same table, they are completely independent, and the hash code is
172 : : computed differently for each of these. */
173 : :
174 : : static GTY ((cache)) hash_table<type_cache_hasher> *type_hash_table;
175 : :
176 : : /* Hash table and temporary node for larger integer const values. */
177 : : static GTY (()) tree int_cst_node;
178 : :
179 : : struct int_cst_hasher : ggc_cache_ptr_hash<tree_node>
180 : : {
181 : : static hashval_t hash (tree t);
182 : : static bool equal (tree x, tree y);
183 : : };
184 : :
185 : : static GTY ((cache)) hash_table<int_cst_hasher> *int_cst_hash_table;
186 : :
187 : : /* Class and variable for making sure that there is a single POLY_INT_CST
188 : : for a given value. */
189 : : struct poly_int_cst_hasher : ggc_cache_ptr_hash<tree_node>
190 : : {
191 : : typedef std::pair<tree, const poly_wide_int *> compare_type;
192 : : static hashval_t hash (tree t);
193 : : static bool equal (tree x, const compare_type &y);
194 : : };
195 : :
196 : : static GTY ((cache)) hash_table<poly_int_cst_hasher> *poly_int_cst_hash_table;
197 : :
198 : : /* Hash table for optimization flags and target option flags. Use the same
199 : : hash table for both sets of options. Nodes for building the current
200 : : optimization and target option nodes. The assumption is most of the time
201 : : the options created will already be in the hash table, so we avoid
202 : : allocating and freeing up a node repeatably. */
203 : : static GTY (()) tree cl_optimization_node;
204 : : static GTY (()) tree cl_target_option_node;
205 : :
206 : : struct cl_option_hasher : ggc_cache_ptr_hash<tree_node>
207 : : {
208 : : static hashval_t hash (tree t);
209 : : static bool equal (tree x, tree y);
210 : : };
211 : :
212 : : static GTY ((cache)) hash_table<cl_option_hasher> *cl_option_hash_table;
213 : :
214 : 696229 : struct gt_value_expr_mark_data {
215 : : hash_set<tree> pset;
216 : : auto_vec<tree, 16> to_mark;
217 : : };
218 : :
219 : : /* Callback called through walk_tree_1 to discover DECL_HAS_VALUE_EXPR_P
220 : : VAR_DECLs which weren't marked yet, in that case marks them and
221 : : walks their DECL_VALUE_EXPR expressions. */
222 : :
223 : : static tree
224 : 11975380 : gt_value_expr_mark_2 (tree *tp, int *, void *data)
225 : : {
226 : 11975380 : tree t = *tp;
227 : 11975380 : if (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t) && !ggc_marked_p (t))
228 : : {
229 : 1006 : tree dve = DECL_VALUE_EXPR (t);
230 : 1006 : gt_value_expr_mark_data *d = (gt_value_expr_mark_data *) data;
231 : 1006 : walk_tree_1 (&dve, gt_value_expr_mark_2, data, &d->pset, NULL);
232 : 1006 : d->to_mark.safe_push (t);
233 : : }
234 : 11975380 : return NULL_TREE;
235 : : }
236 : :
237 : : /* Callback called through traverse_noresize on the
238 : : value_expr_for_decl hash table. */
239 : :
240 : : int
241 : 4513641 : gt_value_expr_mark_1 (tree_decl_map **e, gt_value_expr_mark_data *data)
242 : : {
243 : 4513641 : if (ggc_marked_p ((*e)->base.from))
244 : 4278604 : walk_tree_1 (&(*e)->to, gt_value_expr_mark_2, data, &data->pset, NULL);
245 : 4513641 : return 1;
246 : : }
247 : :
248 : : /* The value_expr_for_decl hash table can have mappings for trees
249 : : which are only referenced from mappings of other trees in the
250 : : same table, see PR118790. Without this routine, gt_cleare_cache
251 : : could clear hash table slot of a tree which isn't marked but
252 : : will be marked when processing later hash table slot of another
253 : : tree which is marked. This function marks with the above
254 : : helpers marks all the not yet marked DECL_HAS_VALUE_EXPR_P
255 : : VAR_DECLs mentioned in DECL_VALUE_EXPR expressions of marked
256 : : trees and in that case also recurses on their DECL_VALUE_EXPR. */
257 : :
258 : : void
259 : 696229 : gt_value_expr_mark (hash_table<tree_decl_map_cache_hasher> *h)
260 : : {
261 : 696229 : if (!h)
262 : 0 : return;
263 : :
264 : 696229 : gt_value_expr_mark_data data;
265 : 696229 : h->traverse_noresize<gt_value_expr_mark_data *,
266 : 5209870 : gt_value_expr_mark_1> (&data);
267 : 2089693 : for (auto v : data.to_mark)
268 : 1006 : gt_ggc_mx (v);
269 : 696229 : }
270 : :
271 : : /* General tree->tree mapping structure for use in hash tables. */
272 : :
273 : :
274 : : static GTY ((cache))
275 : : hash_table<tree_decl_map_cache_hasher> *debug_expr_for_decl;
276 : :
277 : : static GTY ((cache ("gt_value_expr_mark")))
278 : : hash_table<tree_decl_map_cache_hasher> *value_expr_for_decl;
279 : :
280 : : static GTY ((cache))
281 : : hash_table<tree_vec_map_cache_hasher> *debug_args_for_decl;
282 : :
283 : : static void set_type_quals (tree, int);
284 : : static void print_type_hash_statistics (void);
285 : : static void print_debug_expr_statistics (void);
286 : : static void print_value_expr_statistics (void);
287 : :
288 : : tree global_trees[TI_MAX];
289 : : tree integer_types[itk_none];
290 : :
291 : : bool int_n_enabled_p[NUM_INT_N_ENTS];
292 : : struct int_n_trees_t int_n_trees [NUM_INT_N_ENTS];
293 : :
294 : : bool tree_contains_struct[MAX_TREE_CODES][64];
295 : :
296 : : /* Number of operands for each OMP clause. */
297 : : unsigned const char omp_clause_num_ops[] =
298 : : {
299 : : 0, /* OMP_CLAUSE_ERROR */
300 : : 1, /* OMP_CLAUSE_PRIVATE */
301 : : 1, /* OMP_CLAUSE_SHARED */
302 : : 1, /* OMP_CLAUSE_FIRSTPRIVATE */
303 : : 2, /* OMP_CLAUSE_LASTPRIVATE */
304 : : 5, /* OMP_CLAUSE_REDUCTION */
305 : : 5, /* OMP_CLAUSE_TASK_REDUCTION */
306 : : 5, /* OMP_CLAUSE_IN_REDUCTION */
307 : : 1, /* OMP_CLAUSE_COPYIN */
308 : : 1, /* OMP_CLAUSE_COPYPRIVATE */
309 : : 3, /* OMP_CLAUSE_LINEAR */
310 : : 1, /* OMP_CLAUSE_AFFINITY */
311 : : 2, /* OMP_CLAUSE_ALIGNED */
312 : : 3, /* OMP_CLAUSE_ALLOCATE */
313 : : 1, /* OMP_CLAUSE_DEPEND */
314 : : 1, /* OMP_CLAUSE_NONTEMPORAL */
315 : : 1, /* OMP_CLAUSE_UNIFORM */
316 : : 1, /* OMP_CLAUSE_ENTER */
317 : : 1, /* OMP_CLAUSE_LINK */
318 : : 1, /* OMP_CLAUSE_DETACH */
319 : : 1, /* OMP_CLAUSE_USE_DEVICE_PTR */
320 : : 1, /* OMP_CLAUSE_USE_DEVICE_ADDR */
321 : : 1, /* OMP_CLAUSE_IS_DEVICE_PTR */
322 : : 1, /* OMP_CLAUSE_INCLUSIVE */
323 : : 1, /* OMP_CLAUSE_EXCLUSIVE */
324 : : 2, /* OMP_CLAUSE_FROM */
325 : : 2, /* OMP_CLAUSE_TO */
326 : : 2, /* OMP_CLAUSE_MAP */
327 : : 1, /* OMP_CLAUSE_HAS_DEVICE_ADDR */
328 : : 1, /* OMP_CLAUSE_DOACROSS */
329 : : 2, /* OMP_CLAUSE__CACHE_ */
330 : : 1, /* OMP_CLAUSE_DESTROY */
331 : : 2, /* OMP_CLAUSE_INIT */
332 : : 1, /* OMP_CLAUSE_USE */
333 : : 1, /* OMP_CLAUSE_INTEROP */
334 : : 2, /* OMP_CLAUSE_GANG */
335 : : 1, /* OMP_CLAUSE_ASYNC */
336 : : 1, /* OMP_CLAUSE_WAIT */
337 : : 0, /* OMP_CLAUSE_AUTO */
338 : : 0, /* OMP_CLAUSE_SEQ */
339 : : 1, /* OMP_CLAUSE__LOOPTEMP_ */
340 : : 1, /* OMP_CLAUSE__REDUCTEMP_ */
341 : : 1, /* OMP_CLAUSE__CONDTEMP_ */
342 : : 1, /* OMP_CLAUSE__SCANTEMP_ */
343 : : 1, /* OMP_CLAUSE_IF */
344 : : 1, /* OMP_CLAUSE_SELF */
345 : : 1, /* OMP_CLAUSE_NUM_THREADS */
346 : : 1, /* OMP_CLAUSE_SCHEDULE */
347 : : 0, /* OMP_CLAUSE_NOWAIT */
348 : : 1, /* OMP_CLAUSE_ORDERED */
349 : : 0, /* OMP_CLAUSE_DEFAULT */
350 : : 3, /* OMP_CLAUSE_COLLAPSE */
351 : : 0, /* OMP_CLAUSE_UNTIED */
352 : : 1, /* OMP_CLAUSE_FINAL */
353 : : 0, /* OMP_CLAUSE_MERGEABLE */
354 : : 1, /* OMP_CLAUSE_DEVICE */
355 : : 1, /* OMP_CLAUSE_DIST_SCHEDULE */
356 : : 0, /* OMP_CLAUSE_INBRANCH */
357 : : 0, /* OMP_CLAUSE_NOTINBRANCH */
358 : : 2, /* OMP_CLAUSE_NUM_TEAMS */
359 : : 1, /* OMP_CLAUSE_THREAD_LIMIT */
360 : : 0, /* OMP_CLAUSE_PROC_BIND */
361 : : 1, /* OMP_CLAUSE_SAFELEN */
362 : : 1, /* OMP_CLAUSE_SIMDLEN */
363 : : 0, /* OMP_CLAUSE_DEVICE_TYPE */
364 : : 0, /* OMP_CLAUSE_FOR */
365 : : 0, /* OMP_CLAUSE_PARALLEL */
366 : : 0, /* OMP_CLAUSE_SECTIONS */
367 : : 0, /* OMP_CLAUSE_TASKGROUP */
368 : : 1, /* OMP_CLAUSE_PRIORITY */
369 : : 1, /* OMP_CLAUSE_GRAINSIZE */
370 : : 1, /* OMP_CLAUSE_NUM_TASKS */
371 : : 0, /* OMP_CLAUSE_NOGROUP */
372 : : 0, /* OMP_CLAUSE_THREADS */
373 : : 0, /* OMP_CLAUSE_SIMD */
374 : : 1, /* OMP_CLAUSE_HINT */
375 : : 0, /* OMP_CLAUSE_DEFAULTMAP */
376 : : 0, /* OMP_CLAUSE_ORDER */
377 : : 0, /* OMP_CLAUSE_BIND */
378 : : 1, /* OMP_CLAUSE_FILTER */
379 : : 1, /* OMP_CLAUSE_INDIRECT */
380 : : 1, /* OMP_CLAUSE_PARTIAL */
381 : : 0, /* OMP_CLAUSE_FULL */
382 : : 1, /* OMP_CLAUSE_SIZES */
383 : : 1, /* OMP_CLAUSE__SIMDUID_ */
384 : : 0, /* OMP_CLAUSE__SIMT_ */
385 : : 0, /* OMP_CLAUSE_INDEPENDENT */
386 : : 1, /* OMP_CLAUSE_WORKER */
387 : : 1, /* OMP_CLAUSE_VECTOR */
388 : : 1, /* OMP_CLAUSE_NUM_GANGS */
389 : : 1, /* OMP_CLAUSE_NUM_WORKERS */
390 : : 1, /* OMP_CLAUSE_VECTOR_LENGTH */
391 : : 3, /* OMP_CLAUSE_TILE */
392 : : 0, /* OMP_CLAUSE_IF_PRESENT */
393 : : 0, /* OMP_CLAUSE_FINALIZE */
394 : : 0, /* OMP_CLAUSE_NOHOST */
395 : : 1, /* OMP_CLAUSE_NOVARIANTS */
396 : : 1, /* OMP_CLAUSE_NOCONTEXT */
397 : : };
398 : :
399 : : const char * const omp_clause_code_name[] =
400 : : {
401 : : "error_clause",
402 : : "private",
403 : : "shared",
404 : : "firstprivate",
405 : : "lastprivate",
406 : : "reduction",
407 : : "task_reduction",
408 : : "in_reduction",
409 : : "copyin",
410 : : "copyprivate",
411 : : "linear",
412 : : "affinity",
413 : : "aligned",
414 : : "allocate",
415 : : "depend",
416 : : "nontemporal",
417 : : "uniform",
418 : : "enter",
419 : : "link",
420 : : "detach",
421 : : "use_device_ptr",
422 : : "use_device_addr",
423 : : "is_device_ptr",
424 : : "inclusive",
425 : : "exclusive",
426 : : "from",
427 : : "to",
428 : : "map",
429 : : "has_device_addr",
430 : : "doacross",
431 : : "_cache_",
432 : : "destroy",
433 : : "init",
434 : : "use",
435 : : "interop",
436 : : "gang",
437 : : "async",
438 : : "wait",
439 : : "auto",
440 : : "seq",
441 : : "_looptemp_",
442 : : "_reductemp_",
443 : : "_condtemp_",
444 : : "_scantemp_",
445 : : "if",
446 : : "self",
447 : : "num_threads",
448 : : "schedule",
449 : : "nowait",
450 : : "ordered",
451 : : "default",
452 : : "collapse",
453 : : "untied",
454 : : "final",
455 : : "mergeable",
456 : : "device",
457 : : "dist_schedule",
458 : : "inbranch",
459 : : "notinbranch",
460 : : "num_teams",
461 : : "thread_limit",
462 : : "proc_bind",
463 : : "safelen",
464 : : "simdlen",
465 : : "device_type",
466 : : "for",
467 : : "parallel",
468 : : "sections",
469 : : "taskgroup",
470 : : "priority",
471 : : "grainsize",
472 : : "num_tasks",
473 : : "nogroup",
474 : : "threads",
475 : : "simd",
476 : : "hint",
477 : : "defaultmap",
478 : : "order",
479 : : "bind",
480 : : "filter",
481 : : "indirect",
482 : : "partial",
483 : : "full",
484 : : "sizes",
485 : : "_simduid_",
486 : : "_simt_",
487 : : "independent",
488 : : "worker",
489 : : "vector",
490 : : "num_gangs",
491 : : "num_workers",
492 : : "vector_length",
493 : : "tile",
494 : : "if_present",
495 : : "finalize",
496 : : "nohost",
497 : : "novariants",
498 : : "nocontext",
499 : : };
500 : :
501 : : /* Unless specific to OpenACC, we tend to internally maintain OpenMP-centric
502 : : clause names, but for use in diagnostics etc. would like to use the "user"
503 : : clause names. */
504 : :
505 : : const char *
506 : 465 : user_omp_clause_code_name (tree clause, bool oacc)
507 : : {
508 : : /* For OpenACC, the 'OMP_CLAUSE_MAP_KIND' of an 'OMP_CLAUSE_MAP' is used to
509 : : distinguish clauses as seen by the user. See also where front ends do
510 : : 'build_omp_clause' with 'OMP_CLAUSE_MAP'. */
511 : 930 : if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP)
512 : 465 : switch (OMP_CLAUSE_MAP_KIND (clause))
513 : : {
514 : : case GOMP_MAP_FORCE_ALLOC:
515 : : case GOMP_MAP_ALLOC: return "create";
516 : 0 : case GOMP_MAP_FORCE_TO:
517 : 0 : case GOMP_MAP_TO: return "copyin";
518 : 0 : case GOMP_MAP_FORCE_FROM:
519 : 0 : case GOMP_MAP_FROM: return "copyout";
520 : 381 : case GOMP_MAP_FORCE_TOFROM:
521 : 381 : case GOMP_MAP_TOFROM: return "copy";
522 : 0 : case GOMP_MAP_RELEASE: return "delete";
523 : 0 : case GOMP_MAP_FORCE_PRESENT: return "present";
524 : 42 : case GOMP_MAP_ATTACH: return "attach";
525 : 42 : case GOMP_MAP_FORCE_DETACH:
526 : 42 : case GOMP_MAP_DETACH: return "detach";
527 : 0 : case GOMP_MAP_DEVICE_RESIDENT: return "device_resident";
528 : 0 : case GOMP_MAP_LINK: return "link";
529 : 0 : case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr";
530 : : default: break;
531 : : }
532 : :
533 : 0 : return omp_clause_code_name[OMP_CLAUSE_CODE (clause)];
534 : : }
535 : :
536 : :
537 : : /* Return the tree node structure used by tree code CODE. */
538 : :
539 : : static inline enum tree_node_structure_enum
540 : 34189898351 : tree_node_structure_for_code (enum tree_code code)
541 : : {
542 : 34189898351 : switch (TREE_CODE_CLASS (code))
543 : : {
544 : 8643177523 : case tcc_declaration:
545 : 8643177523 : switch (code)
546 : : {
547 : : case CONST_DECL: return TS_CONST_DECL;
548 : : case DEBUG_EXPR_DECL: return TS_DECL_WRTL;
549 : : case FIELD_DECL: return TS_FIELD_DECL;
550 : : case FUNCTION_DECL: return TS_FUNCTION_DECL;
551 : : case LABEL_DECL: return TS_LABEL_DECL;
552 : : case PARM_DECL: return TS_PARM_DECL;
553 : : case RESULT_DECL: return TS_RESULT_DECL;
554 : : case TRANSLATION_UNIT_DECL: return TS_TRANSLATION_UNIT_DECL;
555 : : case TYPE_DECL: return TS_TYPE_DECL;
556 : : case VAR_DECL: return TS_VAR_DECL;
557 : : default: return TS_DECL_NON_COMMON;
558 : : }
559 : :
560 : : case tcc_type: return TS_TYPE_NON_COMMON;
561 : :
562 : 8574107247 : case tcc_binary:
563 : 8574107247 : case tcc_comparison:
564 : 8574107247 : case tcc_expression:
565 : 8574107247 : case tcc_reference:
566 : 8574107247 : case tcc_statement:
567 : 8574107247 : case tcc_unary:
568 : 8574107247 : case tcc_vl_exp: return TS_EXP;
569 : :
570 : 12258024578 : default: /* tcc_constant and tcc_exceptional */
571 : 12258024578 : break;
572 : : }
573 : :
574 : 12258024578 : switch (code)
575 : : {
576 : : /* tcc_constant cases. */
577 : : case COMPLEX_CST: return TS_COMPLEX;
578 : 282866 : case FIXED_CST: return TS_FIXED_CST;
579 : 343889261 : case INTEGER_CST: return TS_INT_CST;
580 : 282866 : case POLY_INT_CST: return TS_POLY_INT_CST;
581 : 38507003 : case REAL_CST: return TS_REAL_CST;
582 : 203980196 : case STRING_CST: return TS_STRING;
583 : 11521557 : case VECTOR_CST: return TS_VECTOR;
584 : 980035 : case VOID_CST: return TS_TYPED;
585 : 283019 : case RAW_DATA_CST: return TS_RAW_DATA_CST;
586 : :
587 : : /* tcc_exceptional cases. */
588 : 570808623 : case BLOCK: return TS_BLOCK;
589 : 108654632 : case CONSTRUCTOR: return TS_CONSTRUCTOR;
590 : : case ERROR_MARK: return TS_COMMON;
591 : 8738280 : case IDENTIFIER_NODE: return TS_IDENTIFIER;
592 : 803856 : case OMP_CLAUSE: return TS_OMP_CLAUSE;
593 : 1689479 : case OPTIMIZATION_NODE: return TS_OPTIMIZATION;
594 : : case PLACEHOLDER_EXPR: return TS_COMMON;
595 : 237965382 : case SSA_NAME: return TS_SSA_NAME;
596 : 577674707 : case STATEMENT_LIST: return TS_STATEMENT_LIST;
597 : 3667030 : case TARGET_OPTION_NODE: return TS_TARGET_OPTION;
598 : 220054292 : case TREE_BINFO: return TS_BINFO;
599 : 8331590577 : case TREE_LIST: return TS_LIST;
600 : 1594900206 : case TREE_VEC: return TS_VEC;
601 : :
602 : 0 : default:
603 : 0 : gcc_unreachable ();
604 : : }
605 : : }
606 : :
607 : :
608 : : /* Initialize tree_contains_struct to describe the hierarchy of tree
609 : : nodes. */
610 : :
611 : : static void
612 : 282866 : initialize_tree_contains_struct (void)
613 : : {
614 : 282866 : unsigned i;
615 : :
616 : 69302170 : for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++)
617 : : {
618 : 69019304 : enum tree_code code;
619 : 69019304 : enum tree_node_structure_enum ts_code;
620 : :
621 : 69019304 : code = (enum tree_code) i;
622 : 69019304 : ts_code = tree_node_structure_for_code (code);
623 : :
624 : : /* Mark the TS structure itself. */
625 : 69019304 : tree_contains_struct[code][ts_code] = 1;
626 : :
627 : : /* Mark all the structures that TS is derived from. */
628 : 69019304 : switch (ts_code)
629 : : {
630 : 1131464 : case TS_TYPED:
631 : 1131464 : case TS_BLOCK:
632 : 1131464 : case TS_OPTIMIZATION:
633 : 1131464 : case TS_TARGET_OPTION:
634 : 1131464 : MARK_TS_BASE (code);
635 : 1131464 : break;
636 : :
637 : 56856066 : case TS_COMMON:
638 : 56856066 : case TS_INT_CST:
639 : 56856066 : case TS_POLY_INT_CST:
640 : 56856066 : case TS_REAL_CST:
641 : 56856066 : case TS_FIXED_CST:
642 : 56856066 : case TS_VECTOR:
643 : 56856066 : case TS_STRING:
644 : 56856066 : case TS_RAW_DATA_CST:
645 : 56856066 : case TS_COMPLEX:
646 : 56856066 : case TS_SSA_NAME:
647 : 56856066 : case TS_CONSTRUCTOR:
648 : 56856066 : case TS_EXP:
649 : 56856066 : case TS_STATEMENT_LIST:
650 : 56856066 : MARK_TS_TYPED (code);
651 : 56856066 : break;
652 : :
653 : 1414330 : case TS_IDENTIFIER:
654 : 1414330 : case TS_DECL_MINIMAL:
655 : 1414330 : case TS_TYPE_COMMON:
656 : 1414330 : case TS_LIST:
657 : 1414330 : case TS_VEC:
658 : 1414330 : case TS_BINFO:
659 : 1414330 : case TS_OMP_CLAUSE:
660 : 1414330 : MARK_TS_COMMON (code);
661 : 1414330 : break;
662 : :
663 : 0 : case TS_TYPE_WITH_LANG_SPECIFIC:
664 : 0 : MARK_TS_TYPE_COMMON (code);
665 : 0 : break;
666 : :
667 : 5940186 : case TS_TYPE_NON_COMMON:
668 : 5940186 : MARK_TS_TYPE_WITH_LANG_SPECIFIC (code);
669 : 5940186 : break;
670 : :
671 : 0 : case TS_DECL_COMMON:
672 : 0 : MARK_TS_DECL_MINIMAL (code);
673 : 0 : break;
674 : :
675 : 565732 : case TS_DECL_WRTL:
676 : 565732 : case TS_CONST_DECL:
677 : 565732 : MARK_TS_DECL_COMMON (code);
678 : 565732 : break;
679 : :
680 : 848598 : case TS_DECL_NON_COMMON:
681 : 848598 : MARK_TS_DECL_WITH_VIS (code);
682 : 848598 : break;
683 : :
684 : 848598 : case TS_DECL_WITH_VIS:
685 : 848598 : case TS_PARM_DECL:
686 : 848598 : case TS_LABEL_DECL:
687 : 848598 : case TS_RESULT_DECL:
688 : 848598 : MARK_TS_DECL_WRTL (code);
689 : 848598 : break;
690 : :
691 : 282866 : case TS_FIELD_DECL:
692 : 282866 : MARK_TS_DECL_COMMON (code);
693 : 282866 : break;
694 : :
695 : 282866 : case TS_VAR_DECL:
696 : 282866 : MARK_TS_DECL_WITH_VIS (code);
697 : 282866 : break;
698 : :
699 : 565732 : case TS_TYPE_DECL:
700 : 565732 : case TS_FUNCTION_DECL:
701 : 565732 : MARK_TS_DECL_NON_COMMON (code);
702 : 565732 : break;
703 : :
704 : 282866 : case TS_TRANSLATION_UNIT_DECL:
705 : 282866 : MARK_TS_DECL_COMMON (code);
706 : 282866 : break;
707 : :
708 : : default:
709 : : gcc_unreachable ();
710 : : }
711 : : }
712 : :
713 : : /* Basic consistency checks for attributes used in fold. */
714 : 282866 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]);
715 : 282866 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]);
716 : 282866 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]);
717 : 282866 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]);
718 : 282866 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]);
719 : 282866 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]);
720 : 282866 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]);
721 : 282866 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]);
722 : 282866 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]);
723 : 282866 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]);
724 : 282866 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]);
725 : 282866 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]);
726 : 282866 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]);
727 : 282866 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]);
728 : 282866 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]);
729 : 282866 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]);
730 : 282866 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]);
731 : 282866 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]);
732 : 282866 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]);
733 : 282866 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]);
734 : 282866 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]);
735 : 282866 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]);
736 : 282866 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]);
737 : 282866 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]);
738 : 282866 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]);
739 : 282866 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]);
740 : 282866 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]);
741 : 282866 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]);
742 : 282866 : gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]);
743 : 282866 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]);
744 : 282866 : gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]);
745 : 282866 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]);
746 : 282866 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]);
747 : 282866 : gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]);
748 : 282866 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]);
749 : 282866 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]);
750 : 282866 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]);
751 : 282866 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]);
752 : 282866 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_MINIMAL]);
753 : 282866 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_COMMON]);
754 : 282866 : }
755 : :
756 : :
757 : : /* Init tree.cc. */
758 : :
759 : : void
760 : 282866 : init_ttree (void)
761 : : {
762 : : /* Initialize the hash table of types. */
763 : 282866 : type_hash_table
764 : 282866 : = hash_table<type_cache_hasher>::create_ggc (TYPE_HASH_INITIAL_SIZE);
765 : :
766 : 282866 : debug_expr_for_decl
767 : 282866 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
768 : :
769 : 282866 : value_expr_for_decl
770 : 282866 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
771 : :
772 : 282866 : int_cst_hash_table = hash_table<int_cst_hasher>::create_ggc (1024);
773 : :
774 : 282866 : poly_int_cst_hash_table = hash_table<poly_int_cst_hasher>::create_ggc (64);
775 : :
776 : 282866 : int_cst_node = make_int_cst (1, 1);
777 : :
778 : 282866 : cl_option_hash_table = hash_table<cl_option_hasher>::create_ggc (64);
779 : :
780 : 282866 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
781 : 282866 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
782 : :
783 : : /* Initialize the tree_contains_struct array. */
784 : 282866 : initialize_tree_contains_struct ();
785 : 282866 : lang_hooks.init_ts ();
786 : 282866 : }
787 : :
788 : :
789 : : /* The name of the object as the assembler will see it (but before any
790 : : translations made by ASM_OUTPUT_LABELREF). Often this is the same
791 : : as DECL_NAME. It is an IDENTIFIER_NODE. */
792 : : tree
793 : 1514416734 : decl_assembler_name (tree decl)
794 : : {
795 : 1514416734 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
796 : 125642890 : lang_hooks.set_decl_assembler_name (decl);
797 : 1514416734 : return DECL_ASSEMBLER_NAME_RAW (decl);
798 : : }
799 : :
800 : : /* The DECL_ASSEMBLER_NAME_RAW of DECL is being explicitly set to NAME
801 : : (either of which may be NULL). Inform the FE, if this changes the
802 : : name. */
803 : :
804 : : void
805 : 715410575 : overwrite_decl_assembler_name (tree decl, tree name)
806 : : {
807 : 715410575 : if (DECL_ASSEMBLER_NAME_RAW (decl) != name)
808 : 380302582 : lang_hooks.overwrite_decl_assembler_name (decl, name);
809 : 715410575 : }
810 : :
811 : : /* Return true if DECL may need an assembler name to be set. */
812 : :
813 : : static inline bool
814 : 12490813 : need_assembler_name_p (tree decl)
815 : : {
816 : : /* We use DECL_ASSEMBLER_NAME to hold mangled type names for One Definition
817 : : Rule merging. This makes type_odr_p to return true on those types during
818 : : LTO and by comparing the mangled name, we can say what types are intended
819 : : to be equivalent across compilation unit.
820 : :
821 : : We do not store names of type_in_anonymous_namespace_p.
822 : :
823 : : Record, union and enumeration type have linkage that allows use
824 : : to check type_in_anonymous_namespace_p. We do not mangle compound types
825 : : that always can be compared structurally.
826 : :
827 : : Similarly for builtin types, we compare properties of their main variant.
828 : : A special case are integer types where mangling do make differences
829 : : between char/signed char/unsigned char etc. Storing name for these makes
830 : : e.g. -fno-signed-char/-fsigned-char mismatches to be handled well.
831 : : See cp/mangle.cc:write_builtin_type for details. */
832 : :
833 : 12490813 : if (TREE_CODE (decl) == TYPE_DECL)
834 : : {
835 : 387516 : if (DECL_NAME (decl)
836 : 331074 : && decl == TYPE_NAME (TREE_TYPE (decl))
837 : 322287 : && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TREE_TYPE (decl)
838 : 274161 : && !TYPE_ARTIFICIAL (TREE_TYPE (decl))
839 : 271141 : && ((TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
840 : 242825 : && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE)
841 : 28656 : || TYPE_CXX_ODR_P (TREE_TYPE (decl)))
842 : 261770 : && (type_with_linkage_p (TREE_TYPE (decl))
843 : 243569 : || TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE)
844 : 528623 : && !variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
845 : 141107 : return !DECL_ASSEMBLER_NAME_SET_P (decl);
846 : 246409 : return false;
847 : : }
848 : : /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
849 : 12103297 : if (!VAR_OR_FUNCTION_DECL_P (decl))
850 : : return false;
851 : :
852 : : /* If DECL already has its assembler name set, it does not need a
853 : : new one. */
854 : 10910419 : if (!HAS_DECL_ASSEMBLER_NAME_P (decl)
855 : 10910419 : || DECL_ASSEMBLER_NAME_SET_P (decl))
856 : : return false;
857 : :
858 : : /* Abstract decls do not need an assembler name, except they
859 : : can be looked up by autofdo. */
860 : 6413614 : if (DECL_ABSTRACT_P (decl) && !flag_auto_profile)
861 : : return false;
862 : :
863 : : /* For VAR_DECLs, only static, public and external symbols need an
864 : : assembler name. */
865 : 6409982 : if (VAR_P (decl)
866 : : && !TREE_STATIC (decl)
867 : 6409982 : && !TREE_PUBLIC (decl)
868 : 6409982 : && !DECL_EXTERNAL (decl))
869 : : return false;
870 : :
871 : 5886501 : if (TREE_CODE (decl) == FUNCTION_DECL)
872 : : {
873 : : /* Do not set assembler name on builtins. Allow RTL expansion to
874 : : decide whether to expand inline or via a regular call. */
875 : 5885244 : if (fndecl_built_in_p (decl)
876 : 5885244 : && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND)
877 : : return false;
878 : :
879 : : /* Functions represented in the callgraph need an assembler name. */
880 : 1348580 : if (cgraph_node::get (decl) != NULL)
881 : : return true;
882 : :
883 : : /* Unused and not public functions don't need an assembler name. */
884 : 243506 : if (!TREE_USED (decl) && !TREE_PUBLIC (decl))
885 : : return false;
886 : : }
887 : :
888 : : return true;
889 : : }
890 : :
891 : : /* If T needs an assembler name, have one created for it. */
892 : :
893 : : void
894 : 12490813 : assign_assembler_name_if_needed (tree t)
895 : : {
896 : 12490813 : if (need_assembler_name_p (t))
897 : : {
898 : : /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
899 : : diagnostics that use input_location to show locus
900 : : information. The problem here is that, at this point,
901 : : input_location is generally anchored to the end of the file
902 : : (since the parser is long gone), so we don't have a good
903 : : position to pin it to.
904 : :
905 : : To alleviate this problem, this uses the location of T's
906 : : declaration. Examples of this are
907 : : testsuite/g++.dg/template/cond2.C and
908 : : testsuite/g++.dg/template/pr35240.C. */
909 : 1488744 : location_t saved_location = input_location;
910 : 1488744 : input_location = DECL_SOURCE_LOCATION (t);
911 : :
912 : 1488744 : decl_assembler_name (t);
913 : :
914 : 1488744 : input_location = saved_location;
915 : : }
916 : 12490813 : }
917 : :
918 : : /* When the target supports COMDAT groups, this indicates which group the
919 : : DECL is associated with. This can be either an IDENTIFIER_NODE or a
920 : : decl, in which case its DECL_ASSEMBLER_NAME identifies the group. */
921 : : tree
922 : 343637606 : decl_comdat_group (const_tree node)
923 : : {
924 : 343637606 : struct symtab_node *snode = symtab_node::get (node);
925 : 343637606 : if (!snode)
926 : : return NULL;
927 : 328499281 : return snode->get_comdat_group ();
928 : : }
929 : :
930 : : /* Likewise, but make sure it's been reduced to an IDENTIFIER_NODE. */
931 : : tree
932 : 11658 : decl_comdat_group_id (const_tree node)
933 : : {
934 : 11658 : struct symtab_node *snode = symtab_node::get (node);
935 : 11658 : if (!snode)
936 : : return NULL;
937 : 11658 : return snode->get_comdat_group_id ();
938 : : }
939 : :
940 : : /* When the target supports named section, return its name as IDENTIFIER_NODE
941 : : or NULL if it is in no section. */
942 : : const char *
943 : 632982582 : decl_section_name (const_tree node)
944 : : {
945 : 632982582 : struct symtab_node *snode = symtab_node::get (node);
946 : 632982582 : if (!snode)
947 : : return NULL;
948 : 497409240 : return snode->get_section ();
949 : : }
950 : :
951 : : /* Set section name of NODE to VALUE (that is expected to be
952 : : identifier node) */
953 : : void
954 : 1773540 : set_decl_section_name (tree node, const char *value)
955 : : {
956 : 1773540 : struct symtab_node *snode;
957 : :
958 : 1773540 : if (value == NULL)
959 : : {
960 : 38 : snode = symtab_node::get (node);
961 : 38 : if (!snode)
962 : : return;
963 : : }
964 : 1773502 : else if (VAR_P (node))
965 : 1546116 : snode = varpool_node::get_create (node);
966 : : else
967 : 227386 : snode = cgraph_node::get_create (node);
968 : 1773540 : snode->set_section (value);
969 : : }
970 : :
971 : : /* Set section name of NODE to match the section name of OTHER.
972 : :
973 : : set_decl_section_name (decl, other) is equivalent to
974 : : set_decl_section_name (decl, DECL_SECTION_NAME (other)), but possibly more
975 : : efficient. */
976 : : void
977 : 13024031 : set_decl_section_name (tree decl, const_tree other)
978 : : {
979 : 13024031 : struct symtab_node *other_node = symtab_node::get (other);
980 : 13024031 : if (other_node)
981 : : {
982 : 13023897 : struct symtab_node *decl_node;
983 : 13023897 : if (VAR_P (decl))
984 : 23 : decl_node = varpool_node::get_create (decl);
985 : : else
986 : 13023874 : decl_node = cgraph_node::get_create (decl);
987 : 13023897 : decl_node->set_section (*other_node);
988 : : }
989 : : else
990 : : {
991 : 134 : struct symtab_node *decl_node = symtab_node::get (decl);
992 : 134 : if (!decl_node)
993 : : return;
994 : 0 : decl_node->set_section (NULL);
995 : : }
996 : : }
997 : :
998 : : /* Return TLS model of a variable NODE. */
999 : : enum tls_model
1000 : 228326236 : decl_tls_model (const_tree node)
1001 : : {
1002 : 228326236 : struct varpool_node *snode = varpool_node::get (node);
1003 : 228326236 : if (!snode)
1004 : : return TLS_MODEL_NONE;
1005 : 192280162 : return snode->tls_model;
1006 : : }
1007 : :
1008 : : /* Set TLS model of variable NODE to MODEL. */
1009 : : void
1010 : 34324 : set_decl_tls_model (tree node, enum tls_model model)
1011 : : {
1012 : 34324 : struct varpool_node *vnode;
1013 : :
1014 : 34324 : if (model == TLS_MODEL_NONE)
1015 : : {
1016 : 5274 : vnode = varpool_node::get (node);
1017 : 5274 : if (!vnode)
1018 : : return;
1019 : : }
1020 : : else
1021 : 29050 : vnode = varpool_node::get_create (node);
1022 : 29050 : vnode->tls_model = model;
1023 : : }
1024 : :
1025 : : /* Compute the number of bytes occupied by a tree with code CODE.
1026 : : This function cannot be used for nodes that have variable sizes,
1027 : : including TREE_VEC, INTEGER_CST, STRING_CST, and CALL_EXPR. */
1028 : : size_t
1029 : 14971126722 : tree_code_size (enum tree_code code)
1030 : : {
1031 : 14971126722 : switch (TREE_CODE_CLASS (code))
1032 : : {
1033 : 3724458047 : case tcc_declaration: /* A decl node */
1034 : 3724458047 : switch (code)
1035 : : {
1036 : : case FIELD_DECL: return sizeof (tree_field_decl);
1037 : : case PARM_DECL: return sizeof (tree_parm_decl);
1038 : 199556079 : case VAR_DECL: return sizeof (tree_var_decl);
1039 : : case LABEL_DECL: return sizeof (tree_label_decl);
1040 : : case RESULT_DECL: return sizeof (tree_result_decl);
1041 : 30487867 : case CONST_DECL: return sizeof (tree_const_decl);
1042 : : case TYPE_DECL: return sizeof (tree_type_decl);
1043 : 1297877863 : case FUNCTION_DECL: return sizeof (tree_function_decl);
1044 : : case DEBUG_EXPR_DECL: return sizeof (tree_decl_with_rtl);
1045 : : case TRANSLATION_UNIT_DECL: return sizeof (tree_translation_unit_decl);
1046 : : case NAMESPACE_DECL:
1047 : : case IMPORTED_DECL:
1048 : : case NAMELIST_DECL: return sizeof (tree_decl_non_common);
1049 : 216624030 : default:
1050 : 216624030 : gcc_checking_assert (code >= NUM_TREE_CODES);
1051 : 216624030 : return lang_hooks.tree_size (code);
1052 : : }
1053 : :
1054 : 2545663345 : case tcc_type: /* a type node */
1055 : 2545663345 : switch (code)
1056 : : {
1057 : : case OFFSET_TYPE:
1058 : : case ENUMERAL_TYPE:
1059 : : case BOOLEAN_TYPE:
1060 : : case INTEGER_TYPE:
1061 : : case REAL_TYPE:
1062 : : case OPAQUE_TYPE:
1063 : : case POINTER_TYPE:
1064 : : case REFERENCE_TYPE:
1065 : : case NULLPTR_TYPE:
1066 : : case FIXED_POINT_TYPE:
1067 : : case COMPLEX_TYPE:
1068 : : case VECTOR_TYPE:
1069 : : case ARRAY_TYPE:
1070 : : case RECORD_TYPE:
1071 : : case UNION_TYPE:
1072 : : case QUAL_UNION_TYPE:
1073 : : case VOID_TYPE:
1074 : : case FUNCTION_TYPE:
1075 : : case METHOD_TYPE:
1076 : : case BITINT_TYPE:
1077 : : case LANG_TYPE: return sizeof (tree_type_non_common);
1078 : 585750499 : default:
1079 : 585750499 : gcc_checking_assert (code >= NUM_TREE_CODES);
1080 : 585750499 : return lang_hooks.tree_size (code);
1081 : : }
1082 : :
1083 : 3794104435 : case tcc_reference: /* a reference */
1084 : 3794104435 : case tcc_expression: /* an expression */
1085 : 3794104435 : case tcc_statement: /* an expression with side effects */
1086 : 3794104435 : case tcc_comparison: /* a comparison expression */
1087 : 3794104435 : case tcc_unary: /* a unary arithmetic expression */
1088 : 3794104435 : case tcc_binary: /* a binary arithmetic expression */
1089 : 3794104435 : return (sizeof (struct tree_exp)
1090 : 3794104435 : + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
1091 : :
1092 : 42613266 : case tcc_constant: /* a constant */
1093 : 42613266 : switch (code)
1094 : : {
1095 : : case VOID_CST: return sizeof (tree_typed);
1096 : 0 : case INTEGER_CST: gcc_unreachable ();
1097 : : case POLY_INT_CST: return sizeof (tree_poly_int_cst);
1098 : 41757920 : case REAL_CST: return sizeof (tree_real_cst);
1099 : : case FIXED_CST: return sizeof (tree_fixed_cst);
1100 : : case COMPLEX_CST: return sizeof (tree_complex);
1101 : : case RAW_DATA_CST: return sizeof (tree_raw_data);
1102 : 0 : case VECTOR_CST: gcc_unreachable ();
1103 : 0 : case STRING_CST: gcc_unreachable ();
1104 : 64310 : default:
1105 : 64310 : gcc_checking_assert (code >= NUM_TREE_CODES);
1106 : 64310 : return lang_hooks.tree_size (code);
1107 : : }
1108 : :
1109 : 4864287629 : case tcc_exceptional: /* something random, like an identifier. */
1110 : 4864287629 : switch (code)
1111 : : {
1112 : 1579129706 : case IDENTIFIER_NODE: return lang_hooks.identifier_size;
1113 : : case TREE_LIST: return sizeof (tree_list);
1114 : :
1115 : : case ERROR_MARK:
1116 : : case PLACEHOLDER_EXPR: return sizeof (tree_common);
1117 : :
1118 : 0 : case TREE_VEC: gcc_unreachable ();
1119 : 0 : case OMP_CLAUSE: gcc_unreachable ();
1120 : :
1121 : : case SSA_NAME: return sizeof (tree_ssa_name);
1122 : :
1123 : : case STATEMENT_LIST: return sizeof (tree_statement_list);
1124 : 251528532 : case BLOCK: return sizeof (struct tree_block);
1125 : : case CONSTRUCTOR: return sizeof (tree_constructor);
1126 : : case OPTIMIZATION_NODE: return sizeof (tree_optimization_option);
1127 : : case TARGET_OPTION_NODE: return sizeof (tree_target_option);
1128 : :
1129 : 1237888437 : default:
1130 : 1237888437 : gcc_checking_assert (code >= NUM_TREE_CODES);
1131 : 1237888437 : return lang_hooks.tree_size (code);
1132 : : }
1133 : :
1134 : 0 : default:
1135 : 0 : gcc_unreachable ();
1136 : : }
1137 : : }
1138 : :
1139 : : /* Compute the number of bytes occupied by NODE. This routine only
1140 : : looks at TREE_CODE, except for those nodes that have variable sizes. */
1141 : : size_t
1142 : 3305685949 : tree_size (const_tree node)
1143 : : {
1144 : 3305685949 : const enum tree_code code = TREE_CODE (node);
1145 : 3305685949 : switch (code)
1146 : : {
1147 : 10599213 : case INTEGER_CST:
1148 : 10599213 : return (sizeof (struct tree_int_cst)
1149 : 10599213 : + (TREE_INT_CST_EXT_NUNITS (node) - 1) * sizeof (HOST_WIDE_INT));
1150 : :
1151 : 0 : case TREE_BINFO:
1152 : 0 : return (offsetof (struct tree_binfo, base_binfos)
1153 : : + vec<tree, va_gc>
1154 : 0 : ::embedded_size (BINFO_N_BASE_BINFOS (node)));
1155 : :
1156 : 336657437 : case TREE_VEC:
1157 : 336657437 : return (sizeof (struct tree_vec)
1158 : 336657437 : + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
1159 : :
1160 : 0 : case VECTOR_CST:
1161 : 0 : return (sizeof (struct tree_vector)
1162 : 0 : + (vector_cst_encoded_nelts (node) - 1) * sizeof (tree));
1163 : :
1164 : 21525 : case STRING_CST:
1165 : 21525 : return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
1166 : :
1167 : 32075 : case OMP_CLAUSE:
1168 : 32075 : return (sizeof (struct tree_omp_clause)
1169 : 32075 : + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
1170 : 32075 : * sizeof (tree));
1171 : :
1172 : 2958375699 : default:
1173 : 2958375699 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
1174 : 128574189 : return (sizeof (struct tree_exp)
1175 : 128574189 : + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
1176 : : else
1177 : 2829801510 : return tree_code_size (code);
1178 : : }
1179 : : }
1180 : :
1181 : : /* Return tree node kind based on tree CODE. */
1182 : :
1183 : : static tree_node_kind
1184 : 0 : get_stats_node_kind (enum tree_code code)
1185 : : {
1186 : 0 : enum tree_code_class type = TREE_CODE_CLASS (code);
1187 : :
1188 : 0 : switch (type)
1189 : : {
1190 : : case tcc_declaration: /* A decl node */
1191 : : return d_kind;
1192 : 0 : case tcc_type: /* a type node */
1193 : 0 : return t_kind;
1194 : 0 : case tcc_statement: /* an expression with side effects */
1195 : 0 : return s_kind;
1196 : 0 : case tcc_reference: /* a reference */
1197 : 0 : return r_kind;
1198 : : case tcc_expression: /* an expression */
1199 : : case tcc_comparison: /* a comparison expression */
1200 : : case tcc_unary: /* a unary arithmetic expression */
1201 : : case tcc_binary: /* a binary arithmetic expression */
1202 : : return e_kind;
1203 : 0 : case tcc_constant: /* a constant */
1204 : 0 : return c_kind;
1205 : 0 : case tcc_exceptional: /* something random, like an identifier. */
1206 : 0 : switch (code)
1207 : : {
1208 : : case IDENTIFIER_NODE:
1209 : : return id_kind;
1210 : 0 : case TREE_VEC:
1211 : 0 : return vec_kind;
1212 : 0 : case TREE_BINFO:
1213 : 0 : return binfo_kind;
1214 : 0 : case SSA_NAME:
1215 : 0 : return ssa_name_kind;
1216 : 0 : case BLOCK:
1217 : 0 : return b_kind;
1218 : 0 : case CONSTRUCTOR:
1219 : 0 : return constr_kind;
1220 : 0 : case OMP_CLAUSE:
1221 : 0 : return omp_clause_kind;
1222 : 0 : default:
1223 : 0 : return x_kind;
1224 : : }
1225 : : break;
1226 : : case tcc_vl_exp:
1227 : : return e_kind;
1228 : 0 : default:
1229 : 0 : gcc_unreachable ();
1230 : : }
1231 : : }
1232 : :
1233 : : /* Record interesting allocation statistics for a tree node with CODE
1234 : : and LENGTH. */
1235 : :
1236 : : static void
1237 : 0 : record_node_allocation_statistics (enum tree_code code, size_t length)
1238 : : {
1239 : 0 : if (!GATHER_STATISTICS)
1240 : 0 : return;
1241 : :
1242 : : tree_node_kind kind = get_stats_node_kind (code);
1243 : :
1244 : : tree_code_counts[(int) code]++;
1245 : : tree_node_counts[(int) kind]++;
1246 : : tree_node_sizes[(int) kind] += length;
1247 : : }
1248 : :
1249 : : /* Allocate and return a new UID from the DECL_UID namespace. */
1250 : :
1251 : : int
1252 : 3718824081 : allocate_decl_uid (void)
1253 : : {
1254 : 3718824081 : return next_decl_uid++;
1255 : : }
1256 : :
1257 : : /* Return a newly allocated node of code CODE. For decl and type
1258 : : nodes, some other fields are initialized. The rest of the node is
1259 : : initialized to zero. This function cannot be used for TREE_VEC,
1260 : : INTEGER_CST or OMP_CLAUSE nodes, which is enforced by asserts in
1261 : : tree_code_size.
1262 : :
1263 : : Achoo! I got a code in the node. */
1264 : :
1265 : : tree
1266 : 12136515779 : make_node (enum tree_code code MEM_STAT_DECL)
1267 : : {
1268 : 12136515779 : tree t;
1269 : 12136515779 : enum tree_code_class type = TREE_CODE_CLASS (code);
1270 : 12136515779 : size_t length = tree_code_size (code);
1271 : :
1272 : 12136515779 : record_node_allocation_statistics (code, length);
1273 : :
1274 : 12136515779 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1275 : 12136515779 : TREE_SET_CODE (t, code);
1276 : :
1277 : 12136515779 : switch (type)
1278 : : {
1279 : 596304340 : case tcc_statement:
1280 : 596304340 : if (code != DEBUG_BEGIN_STMT)
1281 : 310733563 : TREE_SIDE_EFFECTS (t) = 1;
1282 : : break;
1283 : :
1284 : 2769423157 : case tcc_declaration:
1285 : 2769423157 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1286 : : {
1287 : 2769423157 : if (code == FUNCTION_DECL)
1288 : : {
1289 : 1051272689 : SET_DECL_ALIGN (t, FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY));
1290 : 1051272689 : SET_DECL_MODE (t, FUNCTION_MODE);
1291 : : }
1292 : : else
1293 : 1718150468 : SET_DECL_ALIGN (t, 1);
1294 : : }
1295 : 2769423157 : DECL_SOURCE_LOCATION (t) = input_location;
1296 : 2769423157 : if (TREE_CODE (t) == DEBUG_EXPR_DECL)
1297 : 1737884 : DECL_UID (t) = --next_debug_decl_uid;
1298 : : else
1299 : : {
1300 : 2767685273 : DECL_UID (t) = allocate_decl_uid ();
1301 : 2767685273 : SET_DECL_PT_UID (t, -1);
1302 : : }
1303 : 2769423157 : if (TREE_CODE (t) == LABEL_DECL)
1304 : 31490174 : LABEL_DECL_UID (t) = -1;
1305 : :
1306 : : break;
1307 : :
1308 : 1899661913 : case tcc_type:
1309 : 1899661913 : TYPE_UID (t) = next_type_uid++;
1310 : 1899661913 : SET_TYPE_ALIGN (t, BITS_PER_UNIT);
1311 : 1899661913 : TYPE_USER_ALIGN (t) = 0;
1312 : 1899661913 : TYPE_MAIN_VARIANT (t) = t;
1313 : 1899661913 : TYPE_CANONICAL (t) = t;
1314 : :
1315 : : /* Default to no attributes for type, but let target change that. */
1316 : 1899661913 : TYPE_ATTRIBUTES (t) = NULL_TREE;
1317 : 1899661913 : targetm.set_default_type_attributes (t);
1318 : :
1319 : : /* We have not yet computed the alias set for this type. */
1320 : 1899661913 : TYPE_ALIAS_SET (t) = -1;
1321 : 1899661913 : break;
1322 : :
1323 : 42612090 : case tcc_constant:
1324 : 42612090 : TREE_CONSTANT (t) = 1;
1325 : 42612090 : break;
1326 : :
1327 : 1008014944 : case tcc_expression:
1328 : 1008014944 : switch (code)
1329 : : {
1330 : 243107106 : case INIT_EXPR:
1331 : 243107106 : case MODIFY_EXPR:
1332 : 243107106 : case VA_ARG_EXPR:
1333 : 243107106 : case PREDECREMENT_EXPR:
1334 : 243107106 : case PREINCREMENT_EXPR:
1335 : 243107106 : case POSTDECREMENT_EXPR:
1336 : 243107106 : case POSTINCREMENT_EXPR:
1337 : : /* All of these have side-effects, no matter what their
1338 : : operands are. */
1339 : 243107106 : TREE_SIDE_EFFECTS (t) = 1;
1340 : 243107106 : break;
1341 : :
1342 : : default:
1343 : : break;
1344 : : }
1345 : : break;
1346 : :
1347 : 4676595734 : case tcc_exceptional:
1348 : 4676595734 : switch (code)
1349 : : {
1350 : 1132864 : case TARGET_OPTION_NODE:
1351 : 1132864 : TREE_TARGET_OPTION(t)
1352 : 1132864 : = ggc_cleared_alloc<struct cl_target_option> ();
1353 : 1132864 : break;
1354 : :
1355 : 591231 : case OPTIMIZATION_NODE:
1356 : 591231 : TREE_OPTIMIZATION (t)
1357 : 591231 : = ggc_cleared_alloc<struct cl_optimization> ();
1358 : 591231 : break;
1359 : :
1360 : : default:
1361 : : break;
1362 : : }
1363 : : break;
1364 : :
1365 : : default:
1366 : : /* Other classes need no special treatment. */
1367 : : break;
1368 : : }
1369 : :
1370 : 12136515779 : return t;
1371 : : }
1372 : :
1373 : : /* Free tree node. */
1374 : :
1375 : : void
1376 : 572518679 : free_node (tree node)
1377 : : {
1378 : 572518679 : enum tree_code code = TREE_CODE (node);
1379 : 572518679 : if (GATHER_STATISTICS)
1380 : : {
1381 : : enum tree_node_kind kind = get_stats_node_kind (code);
1382 : :
1383 : : gcc_checking_assert (tree_code_counts[(int) TREE_CODE (node)] != 0);
1384 : : gcc_checking_assert (tree_node_counts[(int) kind] != 0);
1385 : : gcc_checking_assert (tree_node_sizes[(int) kind] >= tree_size (node));
1386 : :
1387 : : tree_code_counts[(int) TREE_CODE (node)]--;
1388 : : tree_node_counts[(int) kind]--;
1389 : : tree_node_sizes[(int) kind] -= tree_size (node);
1390 : : }
1391 : 572518679 : if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1392 : 349 : vec_free (CONSTRUCTOR_ELTS (node));
1393 : 572518486 : else if (code == BLOCK)
1394 : 0 : vec_free (BLOCK_NONLOCALIZED_VARS (node));
1395 : 572518486 : else if (code == TREE_BINFO)
1396 : 363 : vec_free (BINFO_BASE_ACCESSES (node));
1397 : 572518123 : else if (code == OPTIMIZATION_NODE)
1398 : 801 : cl_optimization_option_free (TREE_OPTIMIZATION (node));
1399 : 572517322 : else if (code == TARGET_OPTION_NODE)
1400 : 865 : cl_target_option_free (TREE_TARGET_OPTION (node));
1401 : 572518679 : ggc_free (node);
1402 : 572518679 : }
1403 : :
1404 : : /* Return a new node with the same contents as NODE except that its
1405 : : TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
1406 : :
1407 : : tree
1408 : 3230242652 : copy_node (tree node MEM_STAT_DECL)
1409 : : {
1410 : 3230242652 : tree t;
1411 : 3230242652 : enum tree_code code = TREE_CODE (node);
1412 : 3230242652 : size_t length;
1413 : :
1414 : 3230242652 : gcc_assert (code != STATEMENT_LIST);
1415 : :
1416 : 3230242652 : length = tree_size (node);
1417 : 3230242652 : record_node_allocation_statistics (code, length);
1418 : 3230242652 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
1419 : 3230242652 : memcpy (t, node, length);
1420 : :
1421 : 3230242652 : if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
1422 : 1989323088 : TREE_CHAIN (t) = 0;
1423 : 3230242652 : TREE_ASM_WRITTEN (t) = 0;
1424 : 3230242652 : TREE_VISITED (t) = 0;
1425 : :
1426 : 3230242652 : if (TREE_CODE_CLASS (code) == tcc_declaration)
1427 : : {
1428 : 950225457 : if (code == DEBUG_EXPR_DECL)
1429 : 0 : DECL_UID (t) = --next_debug_decl_uid;
1430 : : else
1431 : : {
1432 : 950225457 : DECL_UID (t) = allocate_decl_uid ();
1433 : 950225457 : if (DECL_PT_UID_SET_P (node))
1434 : 3180 : SET_DECL_PT_UID (t, DECL_PT_UID (node));
1435 : : }
1436 : 464962668 : if ((TREE_CODE (node) == PARM_DECL || VAR_P (node))
1437 : 1001595428 : && DECL_HAS_VALUE_EXPR_P (node))
1438 : : {
1439 : 617688 : SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
1440 : 617688 : DECL_HAS_VALUE_EXPR_P (t) = 1;
1441 : : }
1442 : : /* DECL_DEBUG_EXPR is copied explicitly by callers. */
1443 : 950225457 : if (VAR_P (node))
1444 : : {
1445 : 51369971 : DECL_HAS_DEBUG_EXPR_P (t) = 0;
1446 : 51369971 : t->decl_with_vis.symtab_node = NULL;
1447 : : }
1448 : 950225457 : if (VAR_P (node) && DECL_HAS_INIT_PRIORITY_P (node))
1449 : : {
1450 : 0 : SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
1451 : 0 : DECL_HAS_INIT_PRIORITY_P (t) = 1;
1452 : : }
1453 : 950225457 : if (TREE_CODE (node) == FUNCTION_DECL)
1454 : : {
1455 : 242253227 : DECL_STRUCT_FUNCTION (t) = NULL;
1456 : 242253227 : t->decl_with_vis.symtab_node = NULL;
1457 : : }
1458 : : }
1459 : 2280017195 : else if (TREE_CODE_CLASS (code) == tcc_type)
1460 : : {
1461 : 646001432 : TYPE_UID (t) = next_type_uid++;
1462 : : /* The following is so that the debug code for
1463 : : the copy is different from the original type.
1464 : : The two statements usually duplicate each other
1465 : : (because they clear fields of the same union),
1466 : : but the optimizer should catch that. */
1467 : 646001432 : TYPE_SYMTAB_ADDRESS (t) = 0;
1468 : 646001432 : TYPE_SYMTAB_DIE (t) = 0;
1469 : :
1470 : : /* Do not copy the values cache. */
1471 : 646001432 : if (TYPE_CACHED_VALUES_P (t))
1472 : : {
1473 : 16508370 : TYPE_CACHED_VALUES_P (t) = 0;
1474 : 16508370 : TYPE_CACHED_VALUES (t) = NULL_TREE;
1475 : : }
1476 : : }
1477 : 1634015763 : else if (code == TARGET_OPTION_NODE)
1478 : : {
1479 : 0 : TREE_TARGET_OPTION (t) = ggc_alloc<struct cl_target_option>();
1480 : 0 : memcpy (TREE_TARGET_OPTION (t), TREE_TARGET_OPTION (node),
1481 : : sizeof (struct cl_target_option));
1482 : : }
1483 : 1634015763 : else if (code == OPTIMIZATION_NODE)
1484 : : {
1485 : 0 : TREE_OPTIMIZATION (t) = ggc_alloc<struct cl_optimization>();
1486 : 0 : memcpy (TREE_OPTIMIZATION (t), TREE_OPTIMIZATION (node),
1487 : : sizeof (struct cl_optimization));
1488 : : }
1489 : :
1490 : 3230242652 : return t;
1491 : : }
1492 : :
1493 : : /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1494 : : For example, this can copy a list made of TREE_LIST nodes. */
1495 : :
1496 : : tree
1497 : 134324073 : copy_list (tree list)
1498 : : {
1499 : 134324073 : tree head;
1500 : 134324073 : tree prev, next;
1501 : :
1502 : 134324073 : if (list == 0)
1503 : : return 0;
1504 : :
1505 : 129392994 : head = prev = copy_node (list);
1506 : 129392994 : next = TREE_CHAIN (list);
1507 : 249403348 : while (next)
1508 : : {
1509 : 120010354 : TREE_CHAIN (prev) = copy_node (next);
1510 : 120010354 : prev = TREE_CHAIN (prev);
1511 : 120010354 : next = TREE_CHAIN (next);
1512 : : }
1513 : : return head;
1514 : : }
1515 : :
1516 : :
1517 : : /* Return the value that TREE_INT_CST_EXT_NUNITS should have for an
1518 : : INTEGER_CST with value CST and type TYPE. */
1519 : :
1520 : : static unsigned int
1521 : 8634498142 : get_int_cst_ext_nunits (tree type, const wide_int &cst)
1522 : : {
1523 : 8634498142 : gcc_checking_assert (cst.get_precision () == TYPE_PRECISION (type));
1524 : : /* We need extra HWIs if CST is an unsigned integer with its
1525 : : upper bit set. */
1526 : 8634498142 : if (TYPE_UNSIGNED (type) && wi::neg_p (cst))
1527 : 155283262 : return cst.get_precision () / HOST_BITS_PER_WIDE_INT + 1;
1528 : 8479214880 : return cst.get_len ();
1529 : : }
1530 : :
1531 : : /* Return a new INTEGER_CST with value CST and type TYPE. */
1532 : :
1533 : : static tree
1534 : 117734404 : build_new_int_cst (tree type, const wide_int &cst)
1535 : : {
1536 : 117734404 : unsigned int len = cst.get_len ();
1537 : 117734404 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1538 : 117734404 : tree nt = make_int_cst (len, ext_len);
1539 : :
1540 : 117734404 : if (len < ext_len)
1541 : : {
1542 : 55666473 : --ext_len;
1543 : 55666473 : TREE_INT_CST_ELT (nt, ext_len)
1544 : 55666473 : = zext_hwi (-1, cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1545 : 72841570 : for (unsigned int i = len; i < ext_len; ++i)
1546 : 17175097 : TREE_INT_CST_ELT (nt, i) = -1;
1547 : : }
1548 : 62067931 : else if (TYPE_UNSIGNED (type)
1549 : 62067931 : && cst.get_precision () < len * HOST_BITS_PER_WIDE_INT)
1550 : : {
1551 : 12351542 : len--;
1552 : 12351542 : TREE_INT_CST_ELT (nt, len)
1553 : 24703084 : = zext_hwi (cst.elt (len),
1554 : 12351542 : cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1555 : : }
1556 : :
1557 : 247873132 : for (unsigned int i = 0; i < len; i++)
1558 : 130138728 : TREE_INT_CST_ELT (nt, i) = cst.elt (i);
1559 : 117734404 : TREE_TYPE (nt) = type;
1560 : 117734404 : return nt;
1561 : : }
1562 : :
1563 : : /* Return a new POLY_INT_CST with coefficients COEFFS and type TYPE. */
1564 : :
1565 : : static tree
1566 : 0 : build_new_poly_int_cst (tree type, tree (&coeffs)[NUM_POLY_INT_COEFFS]
1567 : : CXX_MEM_STAT_INFO)
1568 : : {
1569 : 0 : size_t length = sizeof (struct tree_poly_int_cst);
1570 : 0 : record_node_allocation_statistics (POLY_INT_CST, length);
1571 : :
1572 : 0 : tree t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1573 : :
1574 : 0 : TREE_SET_CODE (t, POLY_INT_CST);
1575 : 0 : TREE_CONSTANT (t) = 1;
1576 : 0 : TREE_TYPE (t) = type;
1577 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1578 : 0 : POLY_INT_CST_COEFF (t, i) = coeffs[i];
1579 : 0 : return t;
1580 : : }
1581 : :
1582 : : /* Create a constant tree that contains CST sign-extended to TYPE. */
1583 : :
1584 : : tree
1585 : 5590995028 : build_int_cst (tree type, poly_int64 cst)
1586 : : {
1587 : : /* Support legacy code. */
1588 : 5590995028 : if (!type)
1589 : 1711426757 : type = integer_type_node;
1590 : :
1591 : 5590995028 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1592 : : }
1593 : :
1594 : : /* Create a constant tree that contains CST zero-extended to TYPE. */
1595 : :
1596 : : tree
1597 : 8690290 : build_int_cstu (tree type, poly_uint64 cst)
1598 : : {
1599 : 8690290 : return wide_int_to_tree (type, wi::uhwi (cst, TYPE_PRECISION (type)));
1600 : : }
1601 : :
1602 : : /* Create a constant tree that contains CST sign-extended to TYPE. */
1603 : :
1604 : : tree
1605 : 23645819 : build_int_cst_type (tree type, poly_int64 cst)
1606 : : {
1607 : 23645819 : gcc_assert (type);
1608 : 23645819 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1609 : : }
1610 : :
1611 : : /* Constructs tree in type TYPE from with value given by CST. Signedness
1612 : : of CST is assumed to be the same as the signedness of TYPE. */
1613 : :
1614 : : tree
1615 : 7284993 : double_int_to_tree (tree type, double_int cst)
1616 : : {
1617 : 7284993 : return wide_int_to_tree (type, widest_int::from (cst, TYPE_SIGN (type)));
1618 : : }
1619 : :
1620 : : /* We force the wide_int CST to the range of the type TYPE by sign or
1621 : : zero extending it. OVERFLOWABLE indicates if we are interested in
1622 : : overflow of the value, when >0 we are only interested in signed
1623 : : overflow, for <0 we are interested in any overflow. OVERFLOWED
1624 : : indicates whether overflow has already occurred. CONST_OVERFLOWED
1625 : : indicates whether constant overflow has already occurred. We force
1626 : : T's value to be within range of T's type (by setting to 0 or 1 all
1627 : : the bits outside the type's range). We set TREE_OVERFLOWED if,
1628 : : OVERFLOWED is nonzero,
1629 : : or OVERFLOWABLE is >0 and signed overflow occurs
1630 : : or OVERFLOWABLE is <0 and any overflow occurs
1631 : : We return a new tree node for the extended wide_int. The node
1632 : : is shared if no overflow flags are set. */
1633 : :
1634 : :
1635 : : tree
1636 : 2404802566 : force_fit_type (tree type, const poly_wide_int_ref &cst,
1637 : : int overflowable, bool overflowed)
1638 : : {
1639 : 2404802566 : signop sign = TYPE_SIGN (type);
1640 : :
1641 : : /* If we need to set overflow flags, return a new unshared node. */
1642 : 2404802566 : if (overflowed || !wi::fits_to_tree_p (cst, type))
1643 : : {
1644 : 7026376 : if (overflowed
1645 : 7026376 : || overflowable < 0
1646 : 5797154 : || (overflowable > 0 && sign == SIGNED))
1647 : : {
1648 : 1276284 : poly_wide_int tmp = poly_wide_int::from (cst, TYPE_PRECISION (type),
1649 : 1276284 : sign);
1650 : 1276284 : tree t;
1651 : 1276284 : if (tmp.is_constant ())
1652 : 1276284 : t = build_new_int_cst (type, tmp.coeffs[0]);
1653 : : else
1654 : : {
1655 : : tree coeffs[NUM_POLY_INT_COEFFS];
1656 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1657 : : {
1658 : : coeffs[i] = build_new_int_cst (type, tmp.coeffs[i]);
1659 : : TREE_OVERFLOW (coeffs[i]) = 1;
1660 : : }
1661 : : t = build_new_poly_int_cst (type, coeffs);
1662 : : }
1663 : 1276284 : TREE_OVERFLOW (t) = 1;
1664 : 1276284 : return t;
1665 : 1276284 : }
1666 : : }
1667 : :
1668 : : /* Else build a shared node. */
1669 : 2403526282 : return wide_int_to_tree (type, cst);
1670 : : }
1671 : :
1672 : : /* These are the hash table functions for the hash table of INTEGER_CST
1673 : : nodes of a sizetype. */
1674 : :
1675 : : /* Return the hash code X, an INTEGER_CST. */
1676 : :
1677 : : hashval_t
1678 : 1269264511 : int_cst_hasher::hash (tree x)
1679 : : {
1680 : 1269264511 : const_tree const t = x;
1681 : 1269264511 : hashval_t code = TYPE_UID (TREE_TYPE (t));
1682 : 1269264511 : int i;
1683 : :
1684 : 2603901654 : for (i = 0; i < TREE_INT_CST_NUNITS (t); i++)
1685 : 1334637143 : code = iterative_hash_host_wide_int (TREE_INT_CST_ELT(t, i), code);
1686 : :
1687 : 1269264511 : return code;
1688 : : }
1689 : :
1690 : : /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1691 : : is the same as that given by *Y, which is the same. */
1692 : :
1693 : : bool
1694 : 1259010941 : int_cst_hasher::equal (tree x, tree y)
1695 : : {
1696 : 1259010941 : const_tree const xt = x;
1697 : 1259010941 : const_tree const yt = y;
1698 : :
1699 : 1259010941 : if (TREE_TYPE (xt) != TREE_TYPE (yt)
1700 : 507407179 : || TREE_INT_CST_NUNITS (xt) != TREE_INT_CST_NUNITS (yt)
1701 : 1766369256 : || TREE_INT_CST_EXT_NUNITS (xt) != TREE_INT_CST_EXT_NUNITS (yt))
1702 : : return false;
1703 : :
1704 : 780440944 : for (int i = 0; i < TREE_INT_CST_NUNITS (xt); i++)
1705 : 483246041 : if (TREE_INT_CST_ELT (xt, i) != TREE_INT_CST_ELT (yt, i))
1706 : : return false;
1707 : :
1708 : : return true;
1709 : : }
1710 : :
1711 : : /* Cache wide_int CST into the TYPE_CACHED_VALUES cache for TYPE.
1712 : : SLOT is the slot entry to store it in, and MAX_SLOTS is the maximum
1713 : : number of slots that can be cached for the type. */
1714 : :
1715 : : static inline tree
1716 : 8158302311 : cache_wide_int_in_type_cache (tree type, const wide_int &cst,
1717 : : int slot, int max_slots)
1718 : : {
1719 : 8158302311 : gcc_checking_assert (slot >= 0);
1720 : : /* Initialize cache. */
1721 : 8158302311 : if (!TYPE_CACHED_VALUES_P (type))
1722 : : {
1723 : 16303457 : TYPE_CACHED_VALUES_P (type) = 1;
1724 : 16303457 : TYPE_CACHED_VALUES (type) = make_tree_vec (max_slots);
1725 : : }
1726 : 8158302311 : tree t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot);
1727 : 8158302311 : if (!t)
1728 : : {
1729 : : /* Create a new shared int. */
1730 : 53178355 : t = build_new_int_cst (type, cst);
1731 : 53178355 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot) = t;
1732 : : }
1733 : 8158302311 : return t;
1734 : : }
1735 : :
1736 : : /* Create an INT_CST node of TYPE and value CST.
1737 : : The returned node is always shared. For small integers we use a
1738 : : per-type vector cache, for larger ones we use a single hash table.
1739 : : The value is extended from its precision according to the sign of
1740 : : the type to be a multiple of HOST_BITS_PER_WIDE_INT. This defines
1741 : : the upper bits and ensures that hashing and value equality based
1742 : : upon the underlying HOST_WIDE_INTs works without masking. */
1743 : :
1744 : : static tree
1745 : 8516763738 : wide_int_to_tree_1 (tree type, const wide_int_ref &pcst)
1746 : : {
1747 : 8516763738 : tree t;
1748 : 8516763738 : int ix = -1;
1749 : 8516763738 : int limit = 0;
1750 : :
1751 : 8516763738 : gcc_assert (type);
1752 : 8516763738 : unsigned int prec = TYPE_PRECISION (type);
1753 : 8516763738 : signop sgn = TYPE_SIGN (type);
1754 : :
1755 : : /* Verify that everything is canonical. */
1756 : 8516763738 : int l = pcst.get_len ();
1757 : 8516763738 : if (l > 1)
1758 : : {
1759 : 9114745 : if (pcst.elt (l - 1) == 0)
1760 : 941176 : gcc_checking_assert (pcst.elt (l - 2) < 0);
1761 : 9114745 : if (pcst.elt (l - 1) == HOST_WIDE_INT_M1)
1762 : 9074 : gcc_checking_assert (pcst.elt (l - 2) >= 0);
1763 : : }
1764 : :
1765 : 8516763738 : wide_int cst = wide_int::from (pcst, prec, sgn);
1766 : 8516763738 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1767 : :
1768 : 8516763738 : enum tree_code code = TREE_CODE (type);
1769 : 8516763738 : if (code == POINTER_TYPE || code == REFERENCE_TYPE)
1770 : : {
1771 : : /* Cache NULL pointer and zero bounds. */
1772 : 161947321 : if (cst == 0)
1773 : : ix = 0;
1774 : : /* Cache upper bounds of pointers. */
1775 : 28924301 : else if (cst == wi::max_value (prec, sgn))
1776 : : ix = 1;
1777 : : /* Cache 1 which is used for a non-zero range. */
1778 : 26977839 : else if (cst == 1)
1779 : : ix = 2;
1780 : :
1781 : : if (ix >= 0)
1782 : : {
1783 : 138461189 : t = cache_wide_int_in_type_cache (type, cst, ix, 3);
1784 : : /* Make sure no one is clobbering the shared constant. */
1785 : 138461189 : gcc_checking_assert (TREE_TYPE (t) == type
1786 : : && cst == wi::to_wide (t));
1787 : 138461189 : return t;
1788 : : }
1789 : : }
1790 : 8378302549 : if (ext_len == 1)
1791 : : {
1792 : : /* We just need to store a single HOST_WIDE_INT. */
1793 : 8315022784 : HOST_WIDE_INT hwi;
1794 : 8315022784 : if (TYPE_UNSIGNED (type))
1795 : 5816381536 : hwi = cst.to_uhwi ();
1796 : : else
1797 : 2498641611 : hwi = cst.to_shwi ();
1798 : :
1799 : 8315022784 : switch (code)
1800 : : {
1801 : 204260 : case NULLPTR_TYPE:
1802 : 204260 : gcc_assert (hwi == 0);
1803 : : /* Fallthru. */
1804 : :
1805 : : case POINTER_TYPE:
1806 : : case REFERENCE_TYPE:
1807 : : /* Ignore pointers, as they were already handled above. */
1808 : : break;
1809 : :
1810 : 98557209 : case BOOLEAN_TYPE:
1811 : : /* Cache false or true. */
1812 : 98557209 : limit = 2;
1813 : 98557209 : if (IN_RANGE (hwi, 0, 1))
1814 : 98401112 : ix = hwi;
1815 : : break;
1816 : :
1817 : 8189237108 : case INTEGER_TYPE:
1818 : 8189237108 : case OFFSET_TYPE:
1819 : 8189237108 : case BITINT_TYPE:
1820 : 8189237108 : if (TYPE_SIGN (type) == UNSIGNED)
1821 : : {
1822 : : /* Cache [0, N). */
1823 : 5693754069 : limit = param_integer_share_limit;
1824 : 5693754069 : if (IN_RANGE (hwi, 0, param_integer_share_limit - 1))
1825 : 5527853137 : ix = hwi;
1826 : : }
1827 : : else
1828 : : {
1829 : : /* Cache [-1, N). */
1830 : 2495483039 : limit = param_integer_share_limit + 1;
1831 : 2495483039 : if (IN_RANGE (hwi, -1, param_integer_share_limit - 1))
1832 : 2393586873 : ix = hwi + 1;
1833 : : }
1834 : : break;
1835 : :
1836 : : case ENUMERAL_TYPE:
1837 : : break;
1838 : :
1839 : 0 : default:
1840 : 0 : gcc_unreachable ();
1841 : : }
1842 : :
1843 : 8315022784 : if (ix >= 0)
1844 : : {
1845 : 8019841122 : t = cache_wide_int_in_type_cache (type, cst, ix, limit);
1846 : : /* Make sure no one is clobbering the shared constant. */
1847 : 16039682244 : gcc_checking_assert (TREE_TYPE (t) == type
1848 : : && TREE_INT_CST_NUNITS (t) == 1
1849 : : && TREE_INT_CST_EXT_NUNITS (t) == 1
1850 : : && TREE_INT_CST_ELT (t, 0) == hwi);
1851 : : return t;
1852 : : }
1853 : : else
1854 : : {
1855 : : /* Use the cache of larger shared ints, using int_cst_node as
1856 : : a temporary. */
1857 : :
1858 : 295181662 : TREE_INT_CST_ELT (int_cst_node, 0) = hwi;
1859 : 295181662 : TREE_TYPE (int_cst_node) = type;
1860 : :
1861 : 295181662 : tree *slot = int_cst_hash_table->find_slot (int_cst_node, INSERT);
1862 : 295181662 : t = *slot;
1863 : 295181662 : if (!t)
1864 : : {
1865 : : /* Insert this one into the hash table. */
1866 : 52140502 : t = int_cst_node;
1867 : 52140502 : *slot = t;
1868 : : /* Make a new node for next time round. */
1869 : 52140502 : int_cst_node = make_int_cst (1, 1);
1870 : : }
1871 : : }
1872 : : }
1873 : : else
1874 : : {
1875 : : /* The value either hashes properly or we drop it on the floor
1876 : : for the gc to take care of. There will not be enough of them
1877 : : to worry about. */
1878 : :
1879 : 63279765 : tree nt = build_new_int_cst (type, cst);
1880 : 63279765 : tree *slot = int_cst_hash_table->find_slot (nt, INSERT);
1881 : 63279765 : t = *slot;
1882 : 63279765 : if (!t)
1883 : : {
1884 : : /* Insert this one into the hash table. */
1885 : 15257134 : t = nt;
1886 : 15257134 : *slot = t;
1887 : : }
1888 : : else
1889 : 48022631 : ggc_free (nt);
1890 : : }
1891 : :
1892 : : return t;
1893 : 8516763738 : }
1894 : :
1895 : : hashval_t
1896 : 0 : poly_int_cst_hasher::hash (tree t)
1897 : : {
1898 : 0 : inchash::hash hstate;
1899 : :
1900 : 0 : hstate.add_int (TYPE_UID (TREE_TYPE (t)));
1901 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1902 : 0 : hstate.add_wide_int (wi::to_wide (POLY_INT_CST_COEFF (t, i)));
1903 : :
1904 : 0 : return hstate.end ();
1905 : : }
1906 : :
1907 : : bool
1908 : 0 : poly_int_cst_hasher::equal (tree x, const compare_type &y)
1909 : : {
1910 : 0 : if (TREE_TYPE (x) != y.first)
1911 : : return false;
1912 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1913 : 0 : if (wi::to_wide (POLY_INT_CST_COEFF (x, i)) != y.second->coeffs[i])
1914 : : return false;
1915 : : return true;
1916 : : }
1917 : :
1918 : : /* Build a POLY_INT_CST node with type TYPE and with the elements in VALUES.
1919 : : The elements must also have type TYPE. */
1920 : :
1921 : : tree
1922 : 0 : build_poly_int_cst (tree type, const poly_wide_int_ref &values)
1923 : : {
1924 : 0 : unsigned int prec = TYPE_PRECISION (type);
1925 : 0 : gcc_assert (prec <= values.coeffs[0].get_precision ());
1926 : 0 : poly_wide_int c = poly_wide_int::from (values, prec, SIGNED);
1927 : :
1928 : 0 : inchash::hash h;
1929 : 0 : h.add_int (TYPE_UID (type));
1930 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1931 : 0 : h.add_wide_int (c.coeffs[i]);
1932 : 0 : poly_int_cst_hasher::compare_type comp (type, &c);
1933 : 0 : tree *slot = poly_int_cst_hash_table->find_slot_with_hash (comp, h.end (),
1934 : : INSERT);
1935 : 0 : if (*slot == NULL_TREE)
1936 : : {
1937 : : tree coeffs[NUM_POLY_INT_COEFFS];
1938 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1939 : 0 : coeffs[i] = wide_int_to_tree_1 (type, c.coeffs[i]);
1940 : 0 : *slot = build_new_poly_int_cst (type, coeffs);
1941 : : }
1942 : 0 : return *slot;
1943 : 0 : }
1944 : :
1945 : : /* Create a constant tree with value VALUE in type TYPE. */
1946 : :
1947 : : tree
1948 : 8516763738 : wide_int_to_tree (tree type, const poly_wide_int_ref &value)
1949 : : {
1950 : 8516763738 : if (value.is_constant ())
1951 : 8516763738 : return wide_int_to_tree_1 (type, value.coeffs[0]);
1952 : : return build_poly_int_cst (type, value);
1953 : : }
1954 : :
1955 : : /* Insert INTEGER_CST T into a cache of integer constants. And return
1956 : : the cached constant (which may or may not be T). If MIGHT_DUPLICATE
1957 : : is false, and T falls into the type's 'smaller values' range, there
1958 : : cannot be an existing entry. Otherwise, if MIGHT_DUPLICATE is true,
1959 : : or the value is large, should an existing entry exist, it is
1960 : : returned (rather than inserting T). */
1961 : :
1962 : : tree
1963 : 418419 : cache_integer_cst (tree t, bool might_duplicate ATTRIBUTE_UNUSED)
1964 : : {
1965 : 418419 : tree type = TREE_TYPE (t);
1966 : 418419 : int ix = -1;
1967 : 418419 : int limit = 0;
1968 : 418419 : int prec = TYPE_PRECISION (type);
1969 : :
1970 : 418419 : gcc_assert (!TREE_OVERFLOW (t));
1971 : :
1972 : : /* The caching indices here must match those in
1973 : : wide_int_to_type_1. */
1974 : 418419 : switch (TREE_CODE (type))
1975 : : {
1976 : 0 : case NULLPTR_TYPE:
1977 : 0 : gcc_checking_assert (integer_zerop (t));
1978 : : /* Fallthru. */
1979 : :
1980 : 2964 : case POINTER_TYPE:
1981 : 2964 : case REFERENCE_TYPE:
1982 : 2964 : {
1983 : 2964 : if (integer_zerop (t))
1984 : : ix = 0;
1985 : 1236 : else if (integer_onep (t))
1986 : : ix = 2;
1987 : :
1988 : : if (ix >= 0)
1989 : : limit = 3;
1990 : : }
1991 : : break;
1992 : :
1993 : 9759 : case BOOLEAN_TYPE:
1994 : : /* Cache false or true. */
1995 : 9759 : limit = 2;
1996 : 9759 : if (wi::ltu_p (wi::to_wide (t), 2))
1997 : 0 : ix = TREE_INT_CST_ELT (t, 0);
1998 : : break;
1999 : :
2000 : 395921 : case INTEGER_TYPE:
2001 : 395921 : case OFFSET_TYPE:
2002 : 395921 : case BITINT_TYPE:
2003 : 395921 : if (TYPE_UNSIGNED (type))
2004 : : {
2005 : : /* Cache 0..N */
2006 : 285005 : limit = param_integer_share_limit;
2007 : :
2008 : : /* This is a little hokie, but if the prec is smaller than
2009 : : what is necessary to hold param_integer_share_limit, then the
2010 : : obvious test will not get the correct answer. */
2011 : 285005 : if (prec < HOST_BITS_PER_WIDE_INT)
2012 : : {
2013 : 46288 : if (tree_to_uhwi (t)
2014 : 46288 : < (unsigned HOST_WIDE_INT) param_integer_share_limit)
2015 : 9844 : ix = tree_to_uhwi (t);
2016 : : }
2017 : 238717 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2018 : 206783 : ix = tree_to_uhwi (t);
2019 : : }
2020 : : else
2021 : : {
2022 : : /* Cache -1..N */
2023 : 110916 : limit = param_integer_share_limit + 1;
2024 : :
2025 : 110916 : if (integer_minus_onep (t))
2026 : : ix = 0;
2027 : 110630 : else if (!wi::neg_p (wi::to_wide (t)))
2028 : : {
2029 : 96715 : if (prec < HOST_BITS_PER_WIDE_INT)
2030 : : {
2031 : 92527 : if (tree_to_shwi (t) < param_integer_share_limit)
2032 : 87819 : ix = tree_to_shwi (t) + 1;
2033 : : }
2034 : 4188 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2035 : 3294 : ix = tree_to_shwi (t) + 1;
2036 : : }
2037 : : }
2038 : : break;
2039 : :
2040 : : case ENUMERAL_TYPE:
2041 : : /* The slot used by TYPE_CACHED_VALUES is used for the enum
2042 : : members. */
2043 : : break;
2044 : :
2045 : 0 : default:
2046 : 0 : gcc_unreachable ();
2047 : : }
2048 : :
2049 : 309468 : if (ix >= 0)
2050 : : {
2051 : : /* Look for it in the type's vector of small shared ints. */
2052 : 310003 : if (!TYPE_CACHED_VALUES_P (type))
2053 : : {
2054 : 11828 : TYPE_CACHED_VALUES_P (type) = 1;
2055 : 11828 : TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
2056 : : }
2057 : :
2058 : 310003 : if (tree r = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix))
2059 : : {
2060 : 290822 : gcc_checking_assert (might_duplicate);
2061 : 290822 : t = r;
2062 : : }
2063 : : else
2064 : 19181 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
2065 : : }
2066 : : else
2067 : : {
2068 : : /* Use the cache of larger shared ints. */
2069 : 108416 : tree *slot = int_cst_hash_table->find_slot (t, INSERT);
2070 : 108416 : if (tree r = *slot)
2071 : : {
2072 : : /* If there is already an entry for the number verify it's the
2073 : : same value. */
2074 : 57018 : gcc_checking_assert (wi::to_wide (tree (r)) == wi::to_wide (t));
2075 : : /* And return the cached value. */
2076 : 57018 : t = r;
2077 : : }
2078 : : else
2079 : : /* Otherwise insert this one into the hash table. */
2080 : 51398 : *slot = t;
2081 : : }
2082 : :
2083 : 418419 : return t;
2084 : : }
2085 : :
2086 : :
2087 : : /* Builds an integer constant in TYPE such that lowest BITS bits are ones
2088 : : and the rest are zeros. */
2089 : :
2090 : : tree
2091 : 8594246 : build_low_bits_mask (tree type, unsigned bits)
2092 : : {
2093 : 8594246 : gcc_assert (bits <= TYPE_PRECISION (type));
2094 : :
2095 : 8594246 : return wide_int_to_tree (type, wi::mask (bits, false,
2096 : 8594246 : TYPE_PRECISION (type)));
2097 : : }
2098 : :
2099 : : /* Checks that X is integer constant that can be expressed in (unsigned)
2100 : : HOST_WIDE_INT without loss of precision. */
2101 : :
2102 : : bool
2103 : 503474173 : cst_and_fits_in_hwi (const_tree x)
2104 : : {
2105 : 503474173 : return (TREE_CODE (x) == INTEGER_CST
2106 : 503474173 : && (tree_fits_shwi_p (x) || tree_fits_uhwi_p (x)));
2107 : : }
2108 : :
2109 : : /* Build a newly constructed VECTOR_CST with the given values of
2110 : : (VECTOR_CST_)LOG2_NPATTERNS and (VECTOR_CST_)NELTS_PER_PATTERN. */
2111 : :
2112 : : tree
2113 : 3180862 : make_vector (unsigned log2_npatterns,
2114 : : unsigned int nelts_per_pattern MEM_STAT_DECL)
2115 : : {
2116 : 3180862 : gcc_assert (IN_RANGE (nelts_per_pattern, 1, 3));
2117 : 3180862 : tree t;
2118 : 3180862 : unsigned npatterns = 1 << log2_npatterns;
2119 : 3180862 : unsigned encoded_nelts = npatterns * nelts_per_pattern;
2120 : 3180862 : unsigned length = (sizeof (struct tree_vector)
2121 : : + (encoded_nelts - 1) * sizeof (tree));
2122 : :
2123 : 3180862 : record_node_allocation_statistics (VECTOR_CST, length);
2124 : :
2125 : 3180862 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2126 : :
2127 : 3180862 : TREE_SET_CODE (t, VECTOR_CST);
2128 : 3180862 : TREE_CONSTANT (t) = 1;
2129 : 3180862 : VECTOR_CST_LOG2_NPATTERNS (t) = log2_npatterns;
2130 : 3180862 : VECTOR_CST_NELTS_PER_PATTERN (t) = nelts_per_pattern;
2131 : :
2132 : 3180862 : return t;
2133 : : }
2134 : :
2135 : : /* Return a new VECTOR_CST node whose type is TYPE and whose values
2136 : : are extracted from V, a vector of CONSTRUCTOR_ELT. */
2137 : :
2138 : : tree
2139 : 657580 : build_vector_from_ctor (tree type, const vec<constructor_elt, va_gc> *v)
2140 : : {
2141 : 657580 : if (vec_safe_length (v) == 0)
2142 : 677 : return build_zero_cst (type);
2143 : :
2144 : 656903 : unsigned HOST_WIDE_INT idx, nelts, step = 1;
2145 : 656903 : tree value;
2146 : :
2147 : : /* If the vector is a VLA, build a VLA constant vector. */
2148 : 656903 : if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&nelts))
2149 : : {
2150 : : nelts = constant_lower_bound (TYPE_VECTOR_SUBPARTS (type));
2151 : : gcc_assert (vec_safe_length (v) <= nelts);
2152 : : step = 2;
2153 : : }
2154 : :
2155 : 656903 : tree_vector_builder vec (type, nelts, step);
2156 : 4366847 : FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
2157 : : {
2158 : 3709944 : if (TREE_CODE (value) == VECTOR_CST)
2159 : : {
2160 : : /* If NELTS is constant then this must be too. */
2161 : 354 : unsigned int sub_nelts = VECTOR_CST_NELTS (value).to_constant ();
2162 : 1382 : for (unsigned i = 0; i < sub_nelts; ++i)
2163 : 1028 : vec.quick_push (VECTOR_CST_ELT (value, i));
2164 : : }
2165 : : else
2166 : 3709590 : vec.quick_push (value);
2167 : : }
2168 : 1857156 : while (vec.length () < nelts * step)
2169 : 271675 : vec.quick_push (build_zero_cst (TREE_TYPE (type)));
2170 : :
2171 : 656903 : return vec.build ();
2172 : 656903 : }
2173 : :
2174 : : /* Build a vector of type VECTYPE where all the elements are SCs. */
2175 : : tree
2176 : 660890 : build_vector_from_val (tree vectype, tree sc)
2177 : : {
2178 : 660890 : unsigned HOST_WIDE_INT i, nunits;
2179 : :
2180 : 660890 : if (sc == error_mark_node)
2181 : : return sc;
2182 : :
2183 : : /* Verify that the vector type is suitable for SC. Note that there
2184 : : is some inconsistency in the type-system with respect to restrict
2185 : : qualifications of pointers. Vector types always have a main-variant
2186 : : element type and the qualification is applied to the vector-type.
2187 : : So TREE_TYPE (vector-type) does not return a properly qualified
2188 : : vector element-type. */
2189 : 660890 : gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
2190 : : TREE_TYPE (vectype)));
2191 : :
2192 : 660890 : if (CONSTANT_CLASS_P (sc))
2193 : : {
2194 : 622689 : tree_vector_builder v (vectype, 1, 1);
2195 : 622689 : v.quick_push (sc);
2196 : 622689 : return v.build ();
2197 : 622689 : }
2198 : 38201 : else if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
2199 : : return fold_build1 (VEC_DUPLICATE_EXPR, vectype, sc);
2200 : : else
2201 : : {
2202 : 38201 : vec<constructor_elt, va_gc> *v;
2203 : 38201 : vec_alloc (v, nunits);
2204 : 160978 : for (i = 0; i < nunits; ++i)
2205 : 122777 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
2206 : 38201 : return build_constructor (vectype, v);
2207 : : }
2208 : : }
2209 : :
2210 : : /* If TYPE is not a vector type, just return SC, otherwise return
2211 : : build_vector_from_val (TYPE, SC). */
2212 : :
2213 : : tree
2214 : 4845136 : build_uniform_cst (tree type, tree sc)
2215 : : {
2216 : 4845136 : if (!VECTOR_TYPE_P (type))
2217 : : return sc;
2218 : :
2219 : 239 : return build_vector_from_val (type, sc);
2220 : : }
2221 : :
2222 : : /* Build a vector series of type TYPE in which element I has the value
2223 : : BASE + I * STEP. The result is a constant if BASE and STEP are constant
2224 : : and a VEC_SERIES_EXPR otherwise. */
2225 : :
2226 : : tree
2227 : 18 : build_vec_series (tree type, tree base, tree step)
2228 : : {
2229 : 18 : if (integer_zerop (step))
2230 : 0 : return build_vector_from_val (type, base);
2231 : 18 : if (TREE_CODE (base) == INTEGER_CST && TREE_CODE (step) == INTEGER_CST)
2232 : : {
2233 : 18 : tree_vector_builder builder (type, 1, 3);
2234 : 18 : tree elt1 = wide_int_to_tree (TREE_TYPE (base),
2235 : 36 : wi::to_wide (base) + wi::to_wide (step));
2236 : 18 : tree elt2 = wide_int_to_tree (TREE_TYPE (base),
2237 : 36 : wi::to_wide (elt1) + wi::to_wide (step));
2238 : 18 : builder.quick_push (base);
2239 : 18 : builder.quick_push (elt1);
2240 : 18 : builder.quick_push (elt2);
2241 : 18 : return builder.build ();
2242 : 18 : }
2243 : 0 : return build2 (VEC_SERIES_EXPR, type, base, step);
2244 : : }
2245 : :
2246 : : /* Return a vector with the same number of units and number of bits
2247 : : as VEC_TYPE, but in which the elements are a linear series of unsigned
2248 : : integers { BASE, BASE + STEP, BASE + STEP * 2, ... }. */
2249 : :
2250 : : tree
2251 : 1776 : build_index_vector (tree vec_type, poly_uint64 base, poly_uint64 step)
2252 : : {
2253 : 1776 : tree index_vec_type = vec_type;
2254 : 1776 : tree index_elt_type = TREE_TYPE (vec_type);
2255 : 1776 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vec_type);
2256 : 1776 : if (!INTEGRAL_TYPE_P (index_elt_type) || !TYPE_UNSIGNED (index_elt_type))
2257 : : {
2258 : 4 : index_elt_type = build_nonstandard_integer_type
2259 : 8 : (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (index_elt_type)), true);
2260 : 4 : index_vec_type = build_vector_type (index_elt_type, nunits);
2261 : : }
2262 : :
2263 : 1776 : tree_vector_builder v (index_vec_type, 1, 3);
2264 : 7104 : for (unsigned int i = 0; i < 3; ++i)
2265 : 5328 : v.quick_push (build_int_cstu (index_elt_type, base + i * step));
2266 : 1776 : return v.build ();
2267 : 1776 : }
2268 : :
2269 : : /* Return a VECTOR_CST of type VEC_TYPE in which the first NUM_A
2270 : : elements are A and the rest are B. */
2271 : :
2272 : : tree
2273 : 0 : build_vector_a_then_b (tree vec_type, unsigned int num_a, tree a, tree b)
2274 : : {
2275 : 0 : gcc_assert (known_le (num_a, TYPE_VECTOR_SUBPARTS (vec_type)));
2276 : 0 : unsigned int count = constant_lower_bound (TYPE_VECTOR_SUBPARTS (vec_type));
2277 : : /* Optimize the constant case. */
2278 : 0 : if ((count & 1) == 0 && TYPE_VECTOR_SUBPARTS (vec_type).is_constant ())
2279 : 0 : count /= 2;
2280 : 0 : tree_vector_builder builder (vec_type, count, 2);
2281 : 0 : for (unsigned int i = 0; i < count * 2; ++i)
2282 : 0 : builder.quick_push (i < num_a ? a : b);
2283 : 0 : return builder.build ();
2284 : 0 : }
2285 : :
2286 : : /* Something has messed with the elements of CONSTRUCTOR C after it was built;
2287 : : calculate TREE_CONSTANT and TREE_SIDE_EFFECTS. */
2288 : :
2289 : : void
2290 : 86256078 : recompute_constructor_flags (tree c)
2291 : : {
2292 : 86256078 : unsigned int i;
2293 : 86256078 : tree val;
2294 : 86256078 : bool constant_p = true;
2295 : 86256078 : bool side_effects_p = false;
2296 : 86256078 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2297 : :
2298 : 177489821 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2299 : : {
2300 : : /* Mostly ctors will have elts that don't have side-effects, so
2301 : : the usual case is to scan all the elements. Hence a single
2302 : : loop for both const and side effects, rather than one loop
2303 : : each (with early outs). */
2304 : 91233743 : if (!TREE_CONSTANT (val))
2305 : 14302311 : constant_p = false;
2306 : 91233743 : if (TREE_SIDE_EFFECTS (val))
2307 : 2806680 : side_effects_p = true;
2308 : : }
2309 : :
2310 : 86256078 : TREE_SIDE_EFFECTS (c) = side_effects_p;
2311 : 86256078 : TREE_CONSTANT (c) = constant_p;
2312 : 86256078 : }
2313 : :
2314 : : /* Make sure that TREE_CONSTANT and TREE_SIDE_EFFECTS are correct for
2315 : : CONSTRUCTOR C. */
2316 : :
2317 : : void
2318 : 11170876 : verify_constructor_flags (tree c)
2319 : : {
2320 : 11170876 : unsigned int i;
2321 : 11170876 : tree val;
2322 : 11170876 : bool constant_p = TREE_CONSTANT (c);
2323 : 11170876 : bool side_effects_p = TREE_SIDE_EFFECTS (c);
2324 : 11170876 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2325 : :
2326 : 47874104 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2327 : : {
2328 : 36703228 : if (constant_p && !TREE_CONSTANT (val))
2329 : 0 : internal_error ("non-constant element in constant CONSTRUCTOR");
2330 : 36703228 : if (!side_effects_p && TREE_SIDE_EFFECTS (val))
2331 : 0 : internal_error ("side-effects element in no-side-effects CONSTRUCTOR");
2332 : : }
2333 : 11170876 : }
2334 : :
2335 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2336 : : are in the vec pointed to by VALS. */
2337 : : tree
2338 : 72702193 : build_constructor (tree type, vec<constructor_elt, va_gc> *vals MEM_STAT_DECL)
2339 : : {
2340 : 72702193 : tree c = make_node (CONSTRUCTOR PASS_MEM_STAT);
2341 : :
2342 : 72702193 : TREE_TYPE (c) = type;
2343 : 72702193 : CONSTRUCTOR_ELTS (c) = vals;
2344 : :
2345 : 72702193 : recompute_constructor_flags (c);
2346 : :
2347 : 72702193 : return c;
2348 : : }
2349 : :
2350 : : /* Build a CONSTRUCTOR node made of a single initializer, with the specified
2351 : : INDEX and VALUE. */
2352 : : tree
2353 : 3568 : build_constructor_single (tree type, tree index, tree value)
2354 : : {
2355 : 3568 : vec<constructor_elt, va_gc> *v;
2356 : 3568 : constructor_elt elt = {index, value};
2357 : :
2358 : 3568 : vec_alloc (v, 1);
2359 : 3568 : v->quick_push (elt);
2360 : :
2361 : 3568 : return build_constructor (type, v);
2362 : : }
2363 : :
2364 : :
2365 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2366 : : are in a list pointed to by VALS. */
2367 : : tree
2368 : 5603 : build_constructor_from_list (tree type, tree vals)
2369 : : {
2370 : 5603 : tree t;
2371 : 5603 : vec<constructor_elt, va_gc> *v = NULL;
2372 : :
2373 : 5603 : if (vals)
2374 : : {
2375 : 5603 : vec_alloc (v, list_length (vals));
2376 : 54386 : for (t = vals; t; t = TREE_CHAIN (t))
2377 : 48783 : CONSTRUCTOR_APPEND_ELT (v, TREE_PURPOSE (t), TREE_VALUE (t));
2378 : : }
2379 : :
2380 : 5603 : return build_constructor (type, v);
2381 : : }
2382 : :
2383 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2384 : : are in a vector pointed to by VALS. Note that the TREE_PURPOSE
2385 : : fields in the constructor remain null. */
2386 : :
2387 : : tree
2388 : 1330 : build_constructor_from_vec (tree type, const vec<tree, va_gc> *vals)
2389 : : {
2390 : 1330 : vec<constructor_elt, va_gc> *v = NULL;
2391 : :
2392 : 68986 : for (tree t : vals)
2393 : 67656 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t);
2394 : :
2395 : 1330 : return build_constructor (type, v);
2396 : : }
2397 : :
2398 : : /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
2399 : : of elements, provided as index/value pairs. */
2400 : :
2401 : : tree
2402 : 37356 : build_constructor_va (tree type, int nelts, ...)
2403 : : {
2404 : 37356 : vec<constructor_elt, va_gc> *v = NULL;
2405 : 37356 : va_list p;
2406 : :
2407 : 37356 : va_start (p, nelts);
2408 : 37356 : vec_alloc (v, nelts);
2409 : 37356 : while (nelts--)
2410 : : {
2411 : 112304 : tree index = va_arg (p, tree);
2412 : 112304 : tree value = va_arg (p, tree);
2413 : 261964 : CONSTRUCTOR_APPEND_ELT (v, index, value);
2414 : : }
2415 : 37356 : va_end (p);
2416 : 37356 : return build_constructor (type, v);
2417 : : }
2418 : :
2419 : : /* Return a node of type TYPE for which TREE_CLOBBER_P is true. */
2420 : :
2421 : : tree
2422 : 11133658 : build_clobber (tree type, enum clobber_kind kind)
2423 : : {
2424 : 11133658 : tree clobber = build_constructor (type, NULL);
2425 : 11133658 : TREE_THIS_VOLATILE (clobber) = true;
2426 : 11133658 : CLOBBER_KIND (clobber) = kind;
2427 : 11133658 : return clobber;
2428 : : }
2429 : :
2430 : : /* Return a new FIXED_CST node whose type is TYPE and value is F. */
2431 : :
2432 : : tree
2433 : 54 : build_fixed (tree type, FIXED_VALUE_TYPE f)
2434 : : {
2435 : 54 : tree v;
2436 : 54 : FIXED_VALUE_TYPE *fp;
2437 : :
2438 : 54 : v = make_node (FIXED_CST);
2439 : 54 : fp = ggc_alloc<fixed_value> ();
2440 : 54 : memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
2441 : :
2442 : 54 : TREE_TYPE (v) = type;
2443 : 54 : TREE_FIXED_CST_PTR (v) = fp;
2444 : 54 : return v;
2445 : : }
2446 : :
2447 : : /* Return a new REAL_CST node whose type is TYPE and value is D. */
2448 : :
2449 : : tree
2450 : 41640886 : build_real (tree type, REAL_VALUE_TYPE d)
2451 : : {
2452 : 41640886 : tree v;
2453 : 41640886 : int overflow = 0;
2454 : :
2455 : : /* dconst{0,1,2,m1,half} are used in various places in
2456 : : the middle-end and optimizers, allow them here
2457 : : even for decimal floating point types as an exception
2458 : : by converting them to decimal. */
2459 : 41640886 : if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type))
2460 : : && (d.cl == rvc_normal || d.cl == rvc_zero)
2461 : 41640886 : && !d.decimal)
2462 : : {
2463 : 716 : if (memcmp (&d, &dconst1, sizeof (d)) == 0)
2464 : 0 : decimal_real_from_string (&d, "1");
2465 : 716 : else if (memcmp (&d, &dconst2, sizeof (d)) == 0)
2466 : 22 : decimal_real_from_string (&d, "2");
2467 : 694 : else if (memcmp (&d, &dconstm1, sizeof (d)) == 0)
2468 : 90 : decimal_real_from_string (&d, "-1");
2469 : 604 : else if (memcmp (&d, &dconsthalf, sizeof (d)) == 0)
2470 : 0 : decimal_real_from_string (&d, "0.5");
2471 : 604 : else if (memcmp (&d, &dconst0, sizeof (d)) == 0)
2472 : : {
2473 : : /* Make sure to give zero the minimum quantum exponent for
2474 : : the type (which corresponds to all bits zero). */
2475 : 604 : const struct real_format *fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
2476 : 604 : char buf[16];
2477 : 604 : sprintf (buf, "0e%d", fmt->emin - fmt->p);
2478 : 604 : decimal_real_from_string (&d, buf);
2479 : : }
2480 : : else
2481 : 0 : gcc_unreachable ();
2482 : : }
2483 : :
2484 : : /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
2485 : : Consider doing it via real_convert now. */
2486 : :
2487 : 41640886 : v = make_node (REAL_CST);
2488 : 41640886 : TREE_TYPE (v) = type;
2489 : 41640886 : memcpy (TREE_REAL_CST_PTR (v), &d, sizeof (REAL_VALUE_TYPE));
2490 : 41640886 : TREE_OVERFLOW (v) = overflow;
2491 : 41640886 : return v;
2492 : : }
2493 : :
2494 : : /* Like build_real, but first truncate D to the type. */
2495 : :
2496 : : tree
2497 : 175457 : build_real_truncate (tree type, REAL_VALUE_TYPE d)
2498 : : {
2499 : 175457 : return build_real (type, real_value_truncate (TYPE_MODE (type), d));
2500 : : }
2501 : :
2502 : : /* Return a new REAL_CST node whose type is TYPE
2503 : : and whose value is the integer value of the INTEGER_CST node I. */
2504 : :
2505 : : REAL_VALUE_TYPE
2506 : 24163402 : real_value_from_int_cst (const_tree type, const_tree i)
2507 : : {
2508 : 24163402 : REAL_VALUE_TYPE d;
2509 : :
2510 : : /* Clear all bits of the real value type so that we can later do
2511 : : bitwise comparisons to see if two values are the same. */
2512 : 24163402 : memset (&d, 0, sizeof d);
2513 : :
2514 : 24163402 : real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, wi::to_wide (i),
2515 : 24163402 : TYPE_SIGN (TREE_TYPE (i)));
2516 : 24163402 : return d;
2517 : : }
2518 : :
2519 : : /* Given a tree representing an integer constant I, return a tree
2520 : : representing the same value as a floating-point constant of type TYPE. */
2521 : :
2522 : : tree
2523 : 24095295 : build_real_from_int_cst (tree type, const_tree i)
2524 : : {
2525 : 24095295 : tree v;
2526 : 24095295 : int overflow = TREE_OVERFLOW (i);
2527 : :
2528 : 24095295 : v = build_real (type, real_value_from_int_cst (type, i));
2529 : :
2530 : 24095295 : TREE_OVERFLOW (v) |= overflow;
2531 : 24095295 : return v;
2532 : : }
2533 : :
2534 : : /* Return a new REAL_CST node whose type is TYPE
2535 : : and whose value is the integer value I which has sign SGN. */
2536 : :
2537 : : tree
2538 : 129 : build_real_from_wide (tree type, const wide_int_ref &i, signop sgn)
2539 : : {
2540 : 129 : REAL_VALUE_TYPE d;
2541 : :
2542 : : /* Clear all bits of the real value type so that we can later do
2543 : : bitwise comparisons to see if two values are the same. */
2544 : 129 : memset (&d, 0, sizeof d);
2545 : :
2546 : 129 : real_from_integer (&d, TYPE_MODE (type), i, sgn);
2547 : 129 : return build_real (type, d);
2548 : : }
2549 : :
2550 : : /* Return a newly constructed STRING_CST node whose value is the LEN
2551 : : characters at STR when STR is nonnull, or all zeros otherwise.
2552 : : Note that for a C string literal, LEN should include the trailing NUL.
2553 : : The TREE_TYPE is not initialized. */
2554 : :
2555 : : tree
2556 : 87525359 : build_string (unsigned len, const char *str /*= NULL */)
2557 : : {
2558 : : /* Do not waste bytes provided by padding of struct tree_string. */
2559 : 87525359 : unsigned size = len + offsetof (struct tree_string, str) + 1;
2560 : :
2561 : 87525359 : record_node_allocation_statistics (STRING_CST, size);
2562 : :
2563 : 87525359 : tree s = (tree) ggc_internal_alloc (size);
2564 : :
2565 : 87525359 : memset (s, 0, sizeof (struct tree_typed));
2566 : 87525359 : TREE_SET_CODE (s, STRING_CST);
2567 : 87525359 : TREE_CONSTANT (s) = 1;
2568 : 87525359 : TREE_STRING_LENGTH (s) = len;
2569 : 87525359 : if (str)
2570 : 87516182 : memcpy (s->string.str, str, len);
2571 : : else
2572 : 9177 : memset (s->string.str, 0, len);
2573 : 87525359 : s->string.str[len] = '\0';
2574 : :
2575 : 87525359 : return s;
2576 : : }
2577 : :
2578 : : /* Return a newly constructed COMPLEX_CST node whose value is
2579 : : specified by the real and imaginary parts REAL and IMAG.
2580 : : Both REAL and IMAG should be constant nodes. TYPE, if specified,
2581 : : will be the type of the COMPLEX_CST; otherwise a new type will be made. */
2582 : :
2583 : : tree
2584 : 500061 : build_complex (tree type, tree real, tree imag)
2585 : : {
2586 : 500061 : gcc_assert (CONSTANT_CLASS_P (real));
2587 : 500061 : gcc_assert (CONSTANT_CLASS_P (imag));
2588 : :
2589 : 500061 : tree t = make_node (COMPLEX_CST);
2590 : :
2591 : 500061 : TREE_REALPART (t) = real;
2592 : 500061 : TREE_IMAGPART (t) = imag;
2593 : 500061 : TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
2594 : 500061 : TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
2595 : 500061 : return t;
2596 : : }
2597 : :
2598 : : /* Build a complex (inf +- 0i), such as for the result of cproj.
2599 : : TYPE is the complex tree type of the result. If NEG is true, the
2600 : : imaginary zero is negative. */
2601 : :
2602 : : tree
2603 : 840 : build_complex_inf (tree type, bool neg)
2604 : : {
2605 : 840 : REAL_VALUE_TYPE rzero = dconst0;
2606 : :
2607 : 840 : rzero.sign = neg;
2608 : 840 : return build_complex (type, build_real (TREE_TYPE (type), dconstinf),
2609 : 840 : build_real (TREE_TYPE (type), rzero));
2610 : : }
2611 : :
2612 : : /* Return the constant 1 in type TYPE. If TYPE has several elements, each
2613 : : element is set to 1. In particular, this is 1 + i for complex types. */
2614 : :
2615 : : tree
2616 : 3906 : build_each_one_cst (tree type)
2617 : : {
2618 : 3906 : if (TREE_CODE (type) == COMPLEX_TYPE)
2619 : : {
2620 : 0 : tree scalar = build_one_cst (TREE_TYPE (type));
2621 : 0 : return build_complex (type, scalar, scalar);
2622 : : }
2623 : : else
2624 : 3906 : return build_one_cst (type);
2625 : : }
2626 : :
2627 : : /* Return a constant of arithmetic type TYPE which is the
2628 : : multiplicative identity of the set TYPE. */
2629 : :
2630 : : tree
2631 : 9107656 : build_one_cst (tree type)
2632 : : {
2633 : 9107656 : switch (TREE_CODE (type))
2634 : : {
2635 : 9093721 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2636 : 9093721 : case POINTER_TYPE: case REFERENCE_TYPE:
2637 : 9093721 : case OFFSET_TYPE: case BITINT_TYPE:
2638 : 9093721 : return build_int_cst (type, 1);
2639 : :
2640 : 10593 : case REAL_TYPE:
2641 : 10593 : return build_real (type, dconst1);
2642 : :
2643 : 0 : case FIXED_POINT_TYPE:
2644 : : /* We can only generate 1 for accum types. */
2645 : 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2646 : 0 : return build_fixed (type, FCONST1 (TYPE_MODE (type)));
2647 : :
2648 : 339 : case VECTOR_TYPE:
2649 : 339 : {
2650 : 339 : tree scalar = build_one_cst (TREE_TYPE (type));
2651 : :
2652 : 339 : return build_vector_from_val (type, scalar);
2653 : : }
2654 : :
2655 : 3003 : case COMPLEX_TYPE:
2656 : 6006 : return build_complex (type,
2657 : 3003 : build_one_cst (TREE_TYPE (type)),
2658 : 6006 : build_zero_cst (TREE_TYPE (type)));
2659 : :
2660 : 0 : default:
2661 : 0 : gcc_unreachable ();
2662 : : }
2663 : : }
2664 : :
2665 : : /* Return an integer of type TYPE containing all 1's in as much precision as
2666 : : it contains, or a complex or vector whose subparts are such integers. */
2667 : :
2668 : : tree
2669 : 1801219 : build_all_ones_cst (tree type)
2670 : : {
2671 : 1801219 : if (TREE_CODE (type) == COMPLEX_TYPE)
2672 : : {
2673 : 0 : tree scalar = build_all_ones_cst (TREE_TYPE (type));
2674 : 0 : return build_complex (type, scalar, scalar);
2675 : : }
2676 : : else
2677 : 1801219 : return build_minus_one_cst (type);
2678 : : }
2679 : :
2680 : : /* Return a constant of arithmetic type TYPE which is the
2681 : : opposite of the multiplicative identity of the set TYPE. */
2682 : :
2683 : : tree
2684 : 2448100 : build_minus_one_cst (tree type)
2685 : : {
2686 : 2448100 : switch (TREE_CODE (type))
2687 : : {
2688 : 2329623 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2689 : 2329623 : case POINTER_TYPE: case REFERENCE_TYPE:
2690 : 2329623 : case OFFSET_TYPE: case BITINT_TYPE:
2691 : 2329623 : return build_int_cst (type, -1);
2692 : :
2693 : 9778 : case REAL_TYPE:
2694 : 9778 : return build_real (type, dconstm1);
2695 : :
2696 : 0 : case FIXED_POINT_TYPE:
2697 : : /* We can only generate 1 for accum types. */
2698 : 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2699 : 0 : return build_fixed (type,
2700 : : fixed_from_double_int (double_int_minus_one,
2701 : 0 : SCALAR_TYPE_MODE (type)));
2702 : :
2703 : 108699 : case VECTOR_TYPE:
2704 : 108699 : {
2705 : 108699 : tree scalar = build_minus_one_cst (TREE_TYPE (type));
2706 : :
2707 : 108699 : return build_vector_from_val (type, scalar);
2708 : : }
2709 : :
2710 : 0 : case COMPLEX_TYPE:
2711 : 0 : return build_complex (type,
2712 : 0 : build_minus_one_cst (TREE_TYPE (type)),
2713 : 0 : build_zero_cst (TREE_TYPE (type)));
2714 : :
2715 : 0 : default:
2716 : 0 : gcc_unreachable ();
2717 : : }
2718 : : }
2719 : :
2720 : : /* Build 0 constant of type TYPE. This is used by constructor folding
2721 : : and thus the constant should be represented in memory by
2722 : : zero(es). */
2723 : :
2724 : : tree
2725 : 67392928 : build_zero_cst (tree type)
2726 : : {
2727 : 67392928 : switch (TREE_CODE (type))
2728 : : {
2729 : 66790639 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2730 : 66790639 : case POINTER_TYPE: case REFERENCE_TYPE:
2731 : 66790639 : case OFFSET_TYPE: case NULLPTR_TYPE: case BITINT_TYPE:
2732 : 66790639 : return build_int_cst (type, 0);
2733 : :
2734 : 208118 : case REAL_TYPE:
2735 : 208118 : return build_real (type, dconst0);
2736 : :
2737 : 0 : case FIXED_POINT_TYPE:
2738 : 0 : return build_fixed (type, FCONST0 (TYPE_MODE (type)));
2739 : :
2740 : 204658 : case VECTOR_TYPE:
2741 : 204658 : {
2742 : 204658 : tree scalar = build_zero_cst (TREE_TYPE (type));
2743 : :
2744 : 204658 : return build_vector_from_val (type, scalar);
2745 : : }
2746 : :
2747 : 3589 : case COMPLEX_TYPE:
2748 : 3589 : {
2749 : 3589 : tree zero = build_zero_cst (TREE_TYPE (type));
2750 : :
2751 : 3589 : return build_complex (type, zero, zero);
2752 : : }
2753 : :
2754 : 185924 : default:
2755 : 185924 : if (!AGGREGATE_TYPE_P (type))
2756 : 1 : return fold_convert (type, integer_zero_node);
2757 : 185923 : return build_constructor (type, NULL);
2758 : : }
2759 : : }
2760 : :
2761 : : /* Build a constant of integer type TYPE, made of VALUE's bits replicated
2762 : : every WIDTH bits to fit TYPE's precision. */
2763 : :
2764 : : tree
2765 : 14 : build_replicated_int_cst (tree type, unsigned int width, HOST_WIDE_INT value)
2766 : : {
2767 : 14 : int n = ((TYPE_PRECISION (type) + HOST_BITS_PER_WIDE_INT - 1)
2768 : 14 : / HOST_BITS_PER_WIDE_INT);
2769 : 14 : unsigned HOST_WIDE_INT low, mask;
2770 : 14 : HOST_WIDE_INT a[WIDE_INT_MAX_INL_ELTS];
2771 : 14 : int i;
2772 : :
2773 : 14 : gcc_assert (n && n <= WIDE_INT_MAX_INL_ELTS);
2774 : :
2775 : 14 : if (width == HOST_BITS_PER_WIDE_INT)
2776 : 0 : low = value;
2777 : : else
2778 : : {
2779 : 14 : mask = (HOST_WIDE_INT_1U << width) - 1;
2780 : 14 : low = (unsigned HOST_WIDE_INT) ~0 / mask * (value & mask);
2781 : : }
2782 : :
2783 : 28 : for (i = 0; i < n; i++)
2784 : 14 : a[i] = low;
2785 : :
2786 : 14 : gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
2787 : 14 : return wide_int_to_tree (type, wide_int::from_array (a, n,
2788 : 14 : TYPE_PRECISION (type)));
2789 : : }
2790 : :
2791 : : /* If floating-point type TYPE has an IEEE-style sign bit, return an
2792 : : unsigned constant in which only the sign bit is set. Return null
2793 : : otherwise. */
2794 : :
2795 : : tree
2796 : 0 : sign_mask_for (tree type)
2797 : : {
2798 : : /* Avoid having to choose between a real-only sign and a pair of signs.
2799 : : This could be relaxed if the choice becomes obvious later. */
2800 : 0 : if (TREE_CODE (type) == COMPLEX_TYPE)
2801 : : return NULL_TREE;
2802 : :
2803 : 0 : auto eltmode = as_a<scalar_float_mode> (element_mode (type));
2804 : 0 : auto bits = REAL_MODE_FORMAT (eltmode)->ieee_bits;
2805 : 0 : if (!bits || !pow2p_hwi (bits))
2806 : : return NULL_TREE;
2807 : :
2808 : 0 : tree inttype = unsigned_type_for (type);
2809 : 0 : if (!inttype)
2810 : : return NULL_TREE;
2811 : :
2812 : 0 : auto mask = wi::set_bit_in_zero (bits - 1, bits);
2813 : 0 : if (VECTOR_TYPE_P (inttype))
2814 : : {
2815 : 0 : tree elt = wide_int_to_tree (TREE_TYPE (inttype), mask);
2816 : 0 : return build_vector_from_val (inttype, elt);
2817 : : }
2818 : 0 : return wide_int_to_tree (inttype, mask);
2819 : 0 : }
2820 : :
2821 : : /* Build a BINFO with LEN language slots. */
2822 : :
2823 : : tree
2824 : 81926490 : make_tree_binfo (unsigned base_binfos MEM_STAT_DECL)
2825 : : {
2826 : 81926490 : tree t;
2827 : 81926490 : size_t length = (offsetof (struct tree_binfo, base_binfos)
2828 : 81926490 : + vec<tree, va_gc>::embedded_size (base_binfos));
2829 : :
2830 : 81926490 : record_node_allocation_statistics (TREE_BINFO, length);
2831 : :
2832 : 81926490 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
2833 : :
2834 : 81926490 : memset (t, 0, offsetof (struct tree_binfo, base_binfos));
2835 : :
2836 : 81926490 : TREE_SET_CODE (t, TREE_BINFO);
2837 : :
2838 : 81926490 : BINFO_BASE_BINFOS (t)->embedded_init (base_binfos);
2839 : :
2840 : 81926490 : return t;
2841 : : }
2842 : :
2843 : : /* Create a CASE_LABEL_EXPR tree node and return it. */
2844 : :
2845 : : tree
2846 : 4276569 : build_case_label (tree low_value, tree high_value, tree label_decl)
2847 : : {
2848 : 4276569 : tree t = make_node (CASE_LABEL_EXPR);
2849 : :
2850 : 4276569 : TREE_TYPE (t) = void_type_node;
2851 : 4276569 : SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (label_decl));
2852 : :
2853 : 4276569 : CASE_LOW (t) = low_value;
2854 : 4276569 : CASE_HIGH (t) = high_value;
2855 : 4276569 : CASE_LABEL (t) = label_decl;
2856 : 4276569 : CASE_CHAIN (t) = NULL_TREE;
2857 : :
2858 : 4276569 : return t;
2859 : : }
2860 : :
2861 : : /* Build a newly constructed INTEGER_CST node. LEN and EXT_LEN are the
2862 : : values of TREE_INT_CST_NUNITS and TREE_INT_CST_EXT_NUNITS respectively.
2863 : : The latter determines the length of the HOST_WIDE_INT vector. */
2864 : :
2865 : : tree
2866 : 170781018 : make_int_cst (int len, int ext_len MEM_STAT_DECL)
2867 : : {
2868 : 170781018 : tree t;
2869 : 170781018 : int length = ((ext_len - 1) * sizeof (HOST_WIDE_INT)
2870 : 170781018 : + sizeof (struct tree_int_cst));
2871 : :
2872 : 170781018 : gcc_assert (len);
2873 : 170781018 : record_node_allocation_statistics (INTEGER_CST, length);
2874 : :
2875 : 170781018 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2876 : :
2877 : 170781018 : TREE_SET_CODE (t, INTEGER_CST);
2878 : 170781018 : TREE_INT_CST_NUNITS (t) = len;
2879 : 170781018 : TREE_INT_CST_EXT_NUNITS (t) = ext_len;
2880 : 170781018 : TREE_CONSTANT (t) = 1;
2881 : :
2882 : 170781018 : return t;
2883 : : }
2884 : :
2885 : : /* Build a newly constructed TREE_VEC node of length LEN. */
2886 : :
2887 : : tree
2888 : 2136419959 : make_tree_vec (int len MEM_STAT_DECL)
2889 : : {
2890 : 2136419959 : tree t;
2891 : 2136419959 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2892 : :
2893 : 2136419959 : record_node_allocation_statistics (TREE_VEC, length);
2894 : :
2895 : 2136419959 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2896 : :
2897 : 2136419959 : TREE_SET_CODE (t, TREE_VEC);
2898 : 2136419959 : TREE_VEC_LENGTH (t) = len;
2899 : :
2900 : 2136419959 : return t;
2901 : : }
2902 : :
2903 : : /* Grow a TREE_VEC node to new length LEN. */
2904 : :
2905 : : tree
2906 : 135073 : grow_tree_vec (tree v, int len MEM_STAT_DECL)
2907 : : {
2908 : 135073 : gcc_assert (TREE_CODE (v) == TREE_VEC);
2909 : :
2910 : 135073 : int oldlen = TREE_VEC_LENGTH (v);
2911 : 135073 : gcc_assert (len > oldlen);
2912 : :
2913 : 135073 : size_t oldlength = (oldlen - 1) * sizeof (tree) + sizeof (struct tree_vec);
2914 : 135073 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2915 : :
2916 : 135073 : record_node_allocation_statistics (TREE_VEC, length - oldlength);
2917 : :
2918 : 135073 : v = (tree) ggc_realloc (v, length PASS_MEM_STAT);
2919 : :
2920 : 135073 : TREE_VEC_LENGTH (v) = len;
2921 : :
2922 : 135073 : return v;
2923 : : }
2924 : :
2925 : : /* Return true if EXPR is the constant zero, whether it is integral, float or
2926 : : fixed, and scalar, complex or vector. */
2927 : :
2928 : : bool
2929 : 15365494 : zerop (const_tree expr)
2930 : : {
2931 : 15365494 : return (integer_zerop (expr)
2932 : 10715068 : || real_zerop (expr)
2933 : 25692357 : || fixed_zerop (expr));
2934 : : }
2935 : :
2936 : : /* Return true if EXPR is the integer constant zero or a complex constant
2937 : : of zero, or a location wrapper for such a constant. */
2938 : :
2939 : : bool
2940 : 4890271472 : integer_zerop (const_tree expr)
2941 : : {
2942 : 4890271472 : STRIP_ANY_LOCATION_WRAPPER (expr);
2943 : :
2944 : 4890271472 : switch (TREE_CODE (expr))
2945 : : {
2946 : 4063897866 : case INTEGER_CST:
2947 : 4063897866 : return wi::to_wide (expr) == 0;
2948 : 1223377 : case COMPLEX_CST:
2949 : 1223377 : return (integer_zerop (TREE_REALPART (expr))
2950 : 1245563 : && integer_zerop (TREE_IMAGPART (expr)));
2951 : 1950119 : case VECTOR_CST:
2952 : 1950119 : return (VECTOR_CST_NPATTERNS (expr) == 1
2953 : 1879981 : && VECTOR_CST_DUPLICATE_P (expr)
2954 : 3619769 : && integer_zerop (VECTOR_CST_ENCODED_ELT (expr, 0)));
2955 : : default:
2956 : : return false;
2957 : : }
2958 : : }
2959 : :
2960 : : /* Return true if EXPR is the integer constant one or the corresponding
2961 : : complex constant, or a location wrapper for such a constant. */
2962 : :
2963 : : bool
2964 : 816357740 : integer_onep (const_tree expr)
2965 : : {
2966 : 816357740 : STRIP_ANY_LOCATION_WRAPPER (expr);
2967 : :
2968 : 816357740 : switch (TREE_CODE (expr))
2969 : : {
2970 : 692218683 : case INTEGER_CST:
2971 : 692218683 : return wi::eq_p (wi::to_widest (expr), 1);
2972 : 21484 : case COMPLEX_CST:
2973 : 21484 : return (integer_onep (TREE_REALPART (expr))
2974 : 21504 : && integer_zerop (TREE_IMAGPART (expr)));
2975 : 131990 : case VECTOR_CST:
2976 : 131990 : return (VECTOR_CST_NPATTERNS (expr) == 1
2977 : 117384 : && VECTOR_CST_DUPLICATE_P (expr)
2978 : 238744 : && integer_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
2979 : : default:
2980 : : return false;
2981 : : }
2982 : : }
2983 : :
2984 : : /* Return true if EXPR is the integer constant one. For complex and vector,
2985 : : return true if every piece is the integer constant one.
2986 : : Also return true for location wrappers for such a constant. */
2987 : :
2988 : : bool
2989 : 698313 : integer_each_onep (const_tree expr)
2990 : : {
2991 : 698313 : STRIP_ANY_LOCATION_WRAPPER (expr);
2992 : :
2993 : 698313 : if (TREE_CODE (expr) == COMPLEX_CST)
2994 : 34 : return (integer_onep (TREE_REALPART (expr))
2995 : 48 : && integer_onep (TREE_IMAGPART (expr)));
2996 : : else
2997 : 698279 : return integer_onep (expr);
2998 : : }
2999 : :
3000 : : /* Return true if EXPR is an integer containing all 1's in as much precision
3001 : : as it contains, or a complex or vector whose subparts are such integers,
3002 : : or a location wrapper for such a constant. */
3003 : :
3004 : : bool
3005 : 249397118 : integer_all_onesp (const_tree expr)
3006 : : {
3007 : 249397118 : STRIP_ANY_LOCATION_WRAPPER (expr);
3008 : :
3009 : 249397118 : if (TREE_CODE (expr) == COMPLEX_CST
3010 : 927 : && integer_all_onesp (TREE_REALPART (expr))
3011 : 249397158 : && integer_all_onesp (TREE_IMAGPART (expr)))
3012 : : return true;
3013 : :
3014 : 249397082 : else if (TREE_CODE (expr) == VECTOR_CST)
3015 : 412576 : return (VECTOR_CST_NPATTERNS (expr) == 1
3016 : 397970 : && VECTOR_CST_DUPLICATE_P (expr)
3017 : 794134 : && integer_all_onesp (VECTOR_CST_ENCODED_ELT (expr, 0)));
3018 : :
3019 : 248984506 : else if (TREE_CODE (expr) != INTEGER_CST)
3020 : : return false;
3021 : :
3022 : 162632109 : return (wi::max_value (TYPE_PRECISION (TREE_TYPE (expr)), UNSIGNED)
3023 : 325264430 : == wi::to_wide (expr));
3024 : : }
3025 : :
3026 : : /* Return true if EXPR is the integer constant minus one, or a location
3027 : : wrapper for such a constant. */
3028 : :
3029 : : bool
3030 : 180112004 : integer_minus_onep (const_tree expr)
3031 : : {
3032 : 180112004 : STRIP_ANY_LOCATION_WRAPPER (expr);
3033 : :
3034 : 180112004 : if (TREE_CODE (expr) == COMPLEX_CST)
3035 : 9043 : return (integer_all_onesp (TREE_REALPART (expr))
3036 : 9047 : && integer_zerop (TREE_IMAGPART (expr)));
3037 : : else
3038 : 180102961 : return integer_all_onesp (expr);
3039 : : }
3040 : :
3041 : : /* Return true if EXPR is an integer constant that is a power of 2 (i.e., has
3042 : : only one bit on), or a location wrapper for such a constant. */
3043 : :
3044 : : bool
3045 : 18751328 : integer_pow2p (const_tree expr)
3046 : : {
3047 : 18751328 : STRIP_ANY_LOCATION_WRAPPER (expr);
3048 : :
3049 : 18751328 : if (TREE_CODE (expr) == COMPLEX_CST
3050 : 543 : && integer_pow2p (TREE_REALPART (expr))
3051 : 18751555 : && integer_zerop (TREE_IMAGPART (expr)))
3052 : : return true;
3053 : :
3054 : 18751175 : if (TREE_CODE (expr) != INTEGER_CST)
3055 : : return false;
3056 : :
3057 : 12642692 : return wi::popcount (wi::to_wide (expr)) == 1;
3058 : : }
3059 : :
3060 : : /* Return true if EXPR is an integer constant other than zero or a
3061 : : complex constant other than zero, or a location wrapper for such a
3062 : : constant. */
3063 : :
3064 : : bool
3065 : 127625412 : integer_nonzerop (const_tree expr)
3066 : : {
3067 : 127625412 : STRIP_ANY_LOCATION_WRAPPER (expr);
3068 : :
3069 : 127625412 : return ((TREE_CODE (expr) == INTEGER_CST
3070 : 58774598 : && wi::to_wide (expr) != 0)
3071 : 140814159 : || (TREE_CODE (expr) == COMPLEX_CST
3072 : 234 : && (integer_nonzerop (TREE_REALPART (expr))
3073 : 174 : || integer_nonzerop (TREE_IMAGPART (expr)))));
3074 : : }
3075 : :
3076 : : /* Return true if EXPR is the integer constant one. For vector,
3077 : : return true if every piece is the integer constant minus one
3078 : : (representing the value TRUE).
3079 : : Also return true for location wrappers for such a constant. */
3080 : :
3081 : : bool
3082 : 1005274 : integer_truep (const_tree expr)
3083 : : {
3084 : 1005274 : STRIP_ANY_LOCATION_WRAPPER (expr);
3085 : :
3086 : 1005274 : if (TREE_CODE (expr) == VECTOR_CST)
3087 : 11413 : return integer_all_onesp (expr);
3088 : 993861 : return integer_onep (expr);
3089 : : }
3090 : :
3091 : : /* Return true if EXPR is the fixed-point constant zero, or a location wrapper
3092 : : for such a constant. */
3093 : :
3094 : : bool
3095 : 23432977 : fixed_zerop (const_tree expr)
3096 : : {
3097 : 23432977 : STRIP_ANY_LOCATION_WRAPPER (expr);
3098 : :
3099 : 23432977 : return (TREE_CODE (expr) == FIXED_CST
3100 : 23432977 : && TREE_FIXED_CST (expr).data.is_zero ());
3101 : : }
3102 : :
3103 : : /* Return the power of two represented by a tree node known to be a
3104 : : power of two. */
3105 : :
3106 : : int
3107 : 640758 : tree_log2 (const_tree expr)
3108 : : {
3109 : 640758 : if (TREE_CODE (expr) == COMPLEX_CST)
3110 : 0 : return tree_log2 (TREE_REALPART (expr));
3111 : :
3112 : 640758 : return wi::exact_log2 (wi::to_wide (expr));
3113 : : }
3114 : :
3115 : : /* Similar, but return the largest integer Y such that 2 ** Y is less
3116 : : than or equal to EXPR. */
3117 : :
3118 : : int
3119 : 2520798 : tree_floor_log2 (const_tree expr)
3120 : : {
3121 : 2520798 : if (TREE_CODE (expr) == COMPLEX_CST)
3122 : 0 : return tree_log2 (TREE_REALPART (expr));
3123 : :
3124 : 2520798 : return wi::floor_log2 (wi::to_wide (expr));
3125 : : }
3126 : :
3127 : : /* Return number of known trailing zero bits in EXPR, or, if the value of
3128 : : EXPR is known to be zero, the precision of it's type. */
3129 : :
3130 : : unsigned int
3131 : 67873768 : tree_ctz (const_tree expr)
3132 : : {
3133 : 135745913 : if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
3134 : 67880835 : && !POINTER_TYPE_P (TREE_TYPE (expr)))
3135 : : return 0;
3136 : :
3137 : 67873746 : unsigned int ret1, ret2, prec = TYPE_PRECISION (TREE_TYPE (expr));
3138 : 67873746 : switch (TREE_CODE (expr))
3139 : : {
3140 : 38363220 : case INTEGER_CST:
3141 : 38363220 : ret1 = wi::ctz (wi::to_wide (expr));
3142 : 38363220 : return MIN (ret1, prec);
3143 : 9512192 : case SSA_NAME:
3144 : 9512192 : ret1 = wi::ctz (get_nonzero_bits (expr));
3145 : 9512192 : return MIN (ret1, prec);
3146 : 2030294 : case PLUS_EXPR:
3147 : 2030294 : case MINUS_EXPR:
3148 : 2030294 : case BIT_IOR_EXPR:
3149 : 2030294 : case BIT_XOR_EXPR:
3150 : 2030294 : case MIN_EXPR:
3151 : 2030294 : case MAX_EXPR:
3152 : 2030294 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3153 : 2030294 : if (ret1 == 0)
3154 : : return ret1;
3155 : 959932 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3156 : 959932 : return MIN (ret1, ret2);
3157 : 0 : case POINTER_PLUS_EXPR:
3158 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3159 : 0 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3160 : : /* Second operand is sizetype, which could be in theory
3161 : : wider than pointer's precision. Make sure we never
3162 : : return more than prec. */
3163 : 0 : ret2 = MIN (ret2, prec);
3164 : 0 : return MIN (ret1, ret2);
3165 : 311 : case BIT_AND_EXPR:
3166 : 311 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3167 : 311 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3168 : 311 : return MAX (ret1, ret2);
3169 : 8729007 : case MULT_EXPR:
3170 : 8729007 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3171 : 8729007 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3172 : 8729007 : return MIN (ret1 + ret2, prec);
3173 : 0 : case LSHIFT_EXPR:
3174 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3175 : 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3176 : 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3177 : : {
3178 : 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3179 : 0 : return MIN (ret1 + ret2, prec);
3180 : : }
3181 : : return ret1;
3182 : 0 : case RSHIFT_EXPR:
3183 : 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3184 : 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3185 : : {
3186 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3187 : 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3188 : 0 : if (ret1 > ret2)
3189 : 0 : return ret1 - ret2;
3190 : : }
3191 : : return 0;
3192 : 6049 : case TRUNC_DIV_EXPR:
3193 : 6049 : case CEIL_DIV_EXPR:
3194 : 6049 : case FLOOR_DIV_EXPR:
3195 : 6049 : case ROUND_DIV_EXPR:
3196 : 6049 : case EXACT_DIV_EXPR:
3197 : 6049 : if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
3198 : 6049 : && tree_int_cst_sgn (TREE_OPERAND (expr, 1)) == 1)
3199 : : {
3200 : 6049 : int l = tree_log2 (TREE_OPERAND (expr, 1));
3201 : 6049 : if (l >= 0)
3202 : : {
3203 : 4918 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3204 : 4918 : ret2 = l;
3205 : 4918 : if (ret1 > ret2)
3206 : 0 : return ret1 - ret2;
3207 : : }
3208 : : }
3209 : : return 0;
3210 : 9210634 : CASE_CONVERT:
3211 : 9210634 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3212 : 9210634 : if (ret1 && ret1 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
3213 : : ret1 = prec;
3214 : 9210634 : return MIN (ret1, prec);
3215 : 0 : case SAVE_EXPR:
3216 : 0 : return tree_ctz (TREE_OPERAND (expr, 0));
3217 : 10039 : case COND_EXPR:
3218 : 10039 : ret1 = tree_ctz (TREE_OPERAND (expr, 1));
3219 : 10039 : if (ret1 == 0)
3220 : : return 0;
3221 : 204 : ret2 = tree_ctz (TREE_OPERAND (expr, 2));
3222 : 204 : return MIN (ret1, ret2);
3223 : 0 : case COMPOUND_EXPR:
3224 : 0 : return tree_ctz (TREE_OPERAND (expr, 1));
3225 : 27 : case ADDR_EXPR:
3226 : 27 : ret1 = get_pointer_alignment (CONST_CAST_TREE (expr));
3227 : 27 : if (ret1 > BITS_PER_UNIT)
3228 : : {
3229 : 27 : ret1 = ctz_hwi (ret1 / BITS_PER_UNIT);
3230 : 27 : return MIN (ret1, prec);
3231 : : }
3232 : : return 0;
3233 : : default:
3234 : : return 0;
3235 : : }
3236 : : }
3237 : :
3238 : : /* Return true if EXPR is the real constant zero. Trailing zeroes matter for
3239 : : decimal float constants, so don't return true for them.
3240 : : Also return true for location wrappers around such a constant. */
3241 : :
3242 : : bool
3243 : 528276180 : real_zerop (const_tree expr)
3244 : : {
3245 : 528276180 : STRIP_ANY_LOCATION_WRAPPER (expr);
3246 : :
3247 : 528276180 : switch (TREE_CODE (expr))
3248 : : {
3249 : 18482971 : case REAL_CST:
3250 : 18482971 : return real_equal (&TREE_REAL_CST (expr), &dconst0)
3251 : 18482971 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3252 : 43927 : case COMPLEX_CST:
3253 : 43927 : return real_zerop (TREE_REALPART (expr))
3254 : 56908 : && real_zerop (TREE_IMAGPART (expr));
3255 : 417820 : case VECTOR_CST:
3256 : 417820 : {
3257 : : /* Don't simply check for a duplicate because the predicate
3258 : : accepts both +0.0 and -0.0. */
3259 : 417820 : unsigned count = vector_cst_encoded_nelts (expr);
3260 : 442475 : for (unsigned int i = 0; i < count; ++i)
3261 : 427104 : if (!real_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3262 : : return false;
3263 : : return true;
3264 : : }
3265 : : default:
3266 : : return false;
3267 : : }
3268 : : }
3269 : :
3270 : : /* Return true if EXPR is the real constant one in real or complex form.
3271 : : Trailing zeroes matter for decimal float constants, so don't return
3272 : : true for them.
3273 : : Also return true for location wrappers around such a constant. */
3274 : :
3275 : : bool
3276 : 108140485 : real_onep (const_tree expr)
3277 : : {
3278 : 108140485 : STRIP_ANY_LOCATION_WRAPPER (expr);
3279 : :
3280 : 108140485 : switch (TREE_CODE (expr))
3281 : : {
3282 : 6683649 : case REAL_CST:
3283 : 6683649 : return real_equal (&TREE_REAL_CST (expr), &dconst1)
3284 : 6683649 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3285 : 12576 : case COMPLEX_CST:
3286 : 12576 : return real_onep (TREE_REALPART (expr))
3287 : 16065 : && real_zerop (TREE_IMAGPART (expr));
3288 : 56664 : case VECTOR_CST:
3289 : 56664 : return (VECTOR_CST_NPATTERNS (expr) == 1
3290 : 48661 : && VECTOR_CST_DUPLICATE_P (expr)
3291 : 96959 : && real_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3292 : : default:
3293 : : return false;
3294 : : }
3295 : : }
3296 : :
3297 : : /* Return true if EXPR is the real constant minus one. Trailing zeroes
3298 : : matter for decimal float constants, so don't return true for them.
3299 : : Also return true for location wrappers around such a constant. */
3300 : :
3301 : : bool
3302 : 109041107 : real_minus_onep (const_tree expr)
3303 : : {
3304 : 109041107 : STRIP_ANY_LOCATION_WRAPPER (expr);
3305 : :
3306 : 109041107 : switch (TREE_CODE (expr))
3307 : : {
3308 : 6622048 : case REAL_CST:
3309 : 6622048 : return real_equal (&TREE_REAL_CST (expr), &dconstm1)
3310 : 6622048 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3311 : 12556 : case COMPLEX_CST:
3312 : 12556 : return real_minus_onep (TREE_REALPART (expr))
3313 : 14928 : && real_zerop (TREE_IMAGPART (expr));
3314 : 58359 : case VECTOR_CST:
3315 : 58359 : return (VECTOR_CST_NPATTERNS (expr) == 1
3316 : 49788 : && VECTOR_CST_DUPLICATE_P (expr)
3317 : 99630 : && real_minus_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3318 : : default:
3319 : : return false;
3320 : : }
3321 : : }
3322 : :
3323 : : /* Return true if T could be a floating point zero. */
3324 : :
3325 : : bool
3326 : 678598 : real_maybe_zerop (const_tree expr)
3327 : : {
3328 : 678598 : switch (TREE_CODE (expr))
3329 : : {
3330 : 467163 : case REAL_CST:
3331 : : /* Can't use real_zerop here, as it always returns false for decimal
3332 : : floats. And can't use TREE_REAL_CST (expr).cl == rvc_zero
3333 : : either, as decimal zeros are rvc_normal. */
3334 : 467163 : return real_equal (&TREE_REAL_CST (expr), &dconst0);
3335 : 0 : case COMPLEX_CST:
3336 : 0 : return (real_maybe_zerop (TREE_REALPART (expr))
3337 : 0 : || real_maybe_zerop (TREE_IMAGPART (expr)));
3338 : 0 : case VECTOR_CST:
3339 : 0 : {
3340 : 0 : unsigned count = vector_cst_encoded_nelts (expr);
3341 : 0 : for (unsigned int i = 0; i < count; ++i)
3342 : 0 : if (real_maybe_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3343 : : return true;
3344 : : return false;
3345 : : }
3346 : : default:
3347 : : /* Perhaps for SSA_NAMEs we could query frange. */
3348 : : return true;
3349 : : }
3350 : : }
3351 : :
3352 : : /* True if EXP is a constant or a cast of a constant. */
3353 : :
3354 : : bool
3355 : 3436 : really_constant_p (const_tree exp)
3356 : : {
3357 : : /* This is not quite the same as STRIP_NOPS. It does more. */
3358 : 6880 : while (CONVERT_EXPR_P (exp)
3359 : 6932 : || TREE_CODE (exp) == NON_LVALUE_EXPR)
3360 : 60 : exp = TREE_OPERAND (exp, 0);
3361 : 3436 : return TREE_CONSTANT (exp);
3362 : : }
3363 : :
3364 : : /* Return true if T holds a polynomial pointer difference, storing it in
3365 : : *VALUE if so. A true return means that T's precision is no greater
3366 : : than 64 bits, which is the largest address space we support, so *VALUE
3367 : : never loses precision. However, the signedness of the result does
3368 : : not necessarily match the signedness of T: sometimes an unsigned type
3369 : : like sizetype is used to encode a value that is actually negative. */
3370 : :
3371 : : bool
3372 : 10208635 : ptrdiff_tree_p (const_tree t, poly_int64 *value)
3373 : : {
3374 : 10208635 : if (!t)
3375 : : return false;
3376 : 10208635 : if (TREE_CODE (t) == INTEGER_CST)
3377 : : {
3378 : 2776870 : if (!cst_and_fits_in_hwi (t))
3379 : : return false;
3380 : 2776308 : *value = int_cst_value (t);
3381 : 2776308 : return true;
3382 : : }
3383 : : if (POLY_INT_CST_P (t))
3384 : : {
3385 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3386 : : if (!cst_and_fits_in_hwi (POLY_INT_CST_COEFF (t, i)))
3387 : : return false;
3388 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3389 : : value->coeffs[i] = int_cst_value (POLY_INT_CST_COEFF (t, i));
3390 : : return true;
3391 : : }
3392 : : return false;
3393 : : }
3394 : :
3395 : : poly_int64
3396 : 390980862 : tree_to_poly_int64 (const_tree t)
3397 : : {
3398 : 390980862 : gcc_assert (tree_fits_poly_int64_p (t));
3399 : 390980862 : if (POLY_INT_CST_P (t))
3400 : : return poly_int_cst_value (t).force_shwi ();
3401 : 390980862 : return TREE_INT_CST_LOW (t);
3402 : : }
3403 : :
3404 : : poly_uint64
3405 : 411163536 : tree_to_poly_uint64 (const_tree t)
3406 : : {
3407 : 411163536 : gcc_assert (tree_fits_poly_uint64_p (t));
3408 : 411163536 : if (POLY_INT_CST_P (t))
3409 : : return poly_int_cst_value (t).force_uhwi ();
3410 : 411163536 : return TREE_INT_CST_LOW (t);
3411 : : }
3412 : :
3413 : : /* Return first list element whose TREE_VALUE is ELEM.
3414 : : Return 0 if ELEM is not in LIST. */
3415 : :
3416 : : tree
3417 : 7416334 : value_member (tree elem, tree list)
3418 : : {
3419 : 21755338 : while (list)
3420 : : {
3421 : 18918588 : if (elem == TREE_VALUE (list))
3422 : : return list;
3423 : 14339004 : list = TREE_CHAIN (list);
3424 : : }
3425 : : return NULL_TREE;
3426 : : }
3427 : :
3428 : : /* Return first list element whose TREE_PURPOSE is ELEM.
3429 : : Return 0 if ELEM is not in LIST. */
3430 : :
3431 : : tree
3432 : 112567820 : purpose_member (const_tree elem, tree list)
3433 : : {
3434 : 231687048 : while (list)
3435 : : {
3436 : 128627532 : if (elem == TREE_PURPOSE (list))
3437 : : return list;
3438 : 119119228 : list = TREE_CHAIN (list);
3439 : : }
3440 : : return NULL_TREE;
3441 : : }
3442 : :
3443 : : /* Return true if ELEM is in V. */
3444 : :
3445 : : bool
3446 : 1740632 : vec_member (const_tree elem, vec<tree, va_gc> *v)
3447 : : {
3448 : 1740632 : unsigned ix;
3449 : 1740632 : tree t;
3450 : 3279458 : FOR_EACH_VEC_SAFE_ELT (v, ix, t)
3451 : 1540668 : if (elem == t)
3452 : : return true;
3453 : : return false;
3454 : : }
3455 : :
3456 : : /* Returns element number IDX (zero-origin) of chain CHAIN, or
3457 : : NULL_TREE. */
3458 : :
3459 : : tree
3460 : 16140642 : chain_index (int idx, tree chain)
3461 : : {
3462 : 20578752 : for (; chain && idx > 0; --idx)
3463 : 4438110 : chain = TREE_CHAIN (chain);
3464 : 16140642 : return chain;
3465 : : }
3466 : :
3467 : : /* Return true if ELEM is part of the chain CHAIN. */
3468 : :
3469 : : bool
3470 : 167427 : chain_member (const_tree elem, const_tree chain)
3471 : : {
3472 : 328831 : while (chain)
3473 : : {
3474 : 327560 : if (elem == chain)
3475 : : return true;
3476 : 161404 : chain = DECL_CHAIN (chain);
3477 : : }
3478 : :
3479 : : return false;
3480 : : }
3481 : :
3482 : : /* Return the length of a chain of nodes chained through TREE_CHAIN.
3483 : : We expect a null pointer to mark the end of the chain.
3484 : : This is the Lisp primitive `length'. */
3485 : :
3486 : : int
3487 : 1799706157 : list_length (const_tree t)
3488 : : {
3489 : 1799706157 : const_tree p = t;
3490 : : #ifdef ENABLE_TREE_CHECKING
3491 : 1799706157 : const_tree q = t;
3492 : : #endif
3493 : 1799706157 : int len = 0;
3494 : :
3495 : 2824907921 : while (p)
3496 : : {
3497 : 1025201764 : p = TREE_CHAIN (p);
3498 : : #ifdef ENABLE_TREE_CHECKING
3499 : 1025201764 : if (len % 2)
3500 : 333874024 : q = TREE_CHAIN (q);
3501 : 1025201764 : gcc_assert (p != q);
3502 : : #endif
3503 : 1025201764 : len++;
3504 : : }
3505 : :
3506 : 1799706157 : return len;
3507 : : }
3508 : :
3509 : : /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3510 : : UNION_TYPE TYPE, or NULL_TREE if none. */
3511 : :
3512 : : tree
3513 : 38116 : first_field (const_tree type)
3514 : : {
3515 : 38116 : tree t = TYPE_FIELDS (type);
3516 : 2753316 : while (t && TREE_CODE (t) != FIELD_DECL)
3517 : 2715200 : t = TREE_CHAIN (t);
3518 : 38116 : return t;
3519 : : }
3520 : :
3521 : : /* Returns the last FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3522 : : UNION_TYPE TYPE, or NULL_TREE if none. */
3523 : :
3524 : : tree
3525 : 2535630 : last_field (const_tree type)
3526 : : {
3527 : 2535630 : tree last = NULL_TREE;
3528 : :
3529 : 47587373 : for (tree fld = TYPE_FIELDS (type); fld; fld = TREE_CHAIN (fld))
3530 : : {
3531 : 45051743 : if (TREE_CODE (fld) != FIELD_DECL)
3532 : 37272065 : continue;
3533 : :
3534 : : last = fld;
3535 : : }
3536 : :
3537 : 2535630 : return last;
3538 : : }
3539 : :
3540 : : /* Concatenate two chains of nodes (chained through TREE_CHAIN)
3541 : : by modifying the last node in chain 1 to point to chain 2.
3542 : : This is the Lisp primitive `nconc'. */
3543 : :
3544 : : tree
3545 : 3766140209 : chainon (tree op1, tree op2)
3546 : : {
3547 : 3766140209 : tree t1;
3548 : :
3549 : 3766140209 : if (!op1)
3550 : : return op2;
3551 : 673660024 : if (!op2)
3552 : : return op1;
3553 : :
3554 : 1420291049 : for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
3555 : 819822168 : continue;
3556 : 600468881 : TREE_CHAIN (t1) = op2;
3557 : :
3558 : : #ifdef ENABLE_TREE_CHECKING
3559 : 600468881 : {
3560 : 600468881 : tree t2;
3561 : 1582867386 : for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
3562 : 982398505 : gcc_assert (t2 != t1);
3563 : : }
3564 : : #endif
3565 : :
3566 : : return op1;
3567 : 819822168 : }
3568 : :
3569 : : /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
3570 : :
3571 : : tree
3572 : 85650118 : tree_last (tree chain)
3573 : : {
3574 : 85650118 : tree next;
3575 : 85650118 : if (chain)
3576 : 161672267 : while ((next = TREE_CHAIN (chain)))
3577 : : chain = next;
3578 : 85650118 : return chain;
3579 : : }
3580 : :
3581 : : /* Reverse the order of elements in the chain T,
3582 : : and return the new head of the chain (old last element). */
3583 : :
3584 : : tree
3585 : 1225129394 : nreverse (tree t)
3586 : : {
3587 : 1225129394 : tree prev = 0, decl, next;
3588 : 3175756800 : for (decl = t; decl; decl = next)
3589 : : {
3590 : : /* We shouldn't be using this function to reverse BLOCK chains; we
3591 : : have blocks_nreverse for that. */
3592 : 1950627406 : gcc_checking_assert (TREE_CODE (decl) != BLOCK);
3593 : 1950627406 : next = TREE_CHAIN (decl);
3594 : 1950627406 : TREE_CHAIN (decl) = prev;
3595 : 1950627406 : prev = decl;
3596 : : }
3597 : 1225129394 : return prev;
3598 : : }
3599 : :
3600 : : /* Return a newly created TREE_LIST node whose
3601 : : purpose and value fields are PARM and VALUE. */
3602 : :
3603 : : tree
3604 : 1158842539 : build_tree_list (tree parm, tree value MEM_STAT_DECL)
3605 : : {
3606 : 1158842539 : tree t = make_node (TREE_LIST PASS_MEM_STAT);
3607 : 1158842539 : TREE_PURPOSE (t) = parm;
3608 : 1158842539 : TREE_VALUE (t) = value;
3609 : 1158842539 : return t;
3610 : : }
3611 : :
3612 : : /* Build a chain of TREE_LIST nodes from a vector. */
3613 : :
3614 : : tree
3615 : 77799247 : build_tree_list_vec (const vec<tree, va_gc> *vec MEM_STAT_DECL)
3616 : : {
3617 : 77799247 : tree ret = NULL_TREE;
3618 : 77799247 : tree *pp = &ret;
3619 : 77799247 : unsigned int i;
3620 : 77799247 : tree t;
3621 : 164225244 : FOR_EACH_VEC_SAFE_ELT (vec, i, t)
3622 : : {
3623 : 86425997 : *pp = build_tree_list (NULL, t PASS_MEM_STAT);
3624 : 86425997 : pp = &TREE_CHAIN (*pp);
3625 : : }
3626 : 77799247 : return ret;
3627 : : }
3628 : :
3629 : : /* Return a newly created TREE_LIST node whose
3630 : : purpose and value fields are PURPOSE and VALUE
3631 : : and whose TREE_CHAIN is CHAIN. */
3632 : :
3633 : : tree
3634 : 4691625831 : tree_cons (tree purpose, tree value, tree chain MEM_STAT_DECL)
3635 : : {
3636 : 4691625831 : tree node;
3637 : :
3638 : 4691625831 : node = ggc_alloc_tree_node_stat (sizeof (struct tree_list) PASS_MEM_STAT);
3639 : 4691625831 : memset (node, 0, sizeof (struct tree_common));
3640 : :
3641 : 4691625831 : record_node_allocation_statistics (TREE_LIST, sizeof (struct tree_list));
3642 : :
3643 : 4691625831 : TREE_SET_CODE (node, TREE_LIST);
3644 : 4691625831 : TREE_CHAIN (node) = chain;
3645 : 4691625831 : TREE_PURPOSE (node) = purpose;
3646 : 4691625831 : TREE_VALUE (node) = value;
3647 : 4691625831 : return node;
3648 : : }
3649 : :
3650 : : /* Return the values of the elements of a CONSTRUCTOR as a vector of
3651 : : trees. */
3652 : :
3653 : : vec<tree, va_gc> *
3654 : 0 : ctor_to_vec (tree ctor)
3655 : : {
3656 : 0 : vec<tree, va_gc> *vec;
3657 : 0 : vec_alloc (vec, CONSTRUCTOR_NELTS (ctor));
3658 : 0 : unsigned int ix;
3659 : 0 : tree val;
3660 : :
3661 : 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val)
3662 : 0 : vec->quick_push (val);
3663 : :
3664 : 0 : return vec;
3665 : : }
3666 : :
3667 : : /* Return the size nominally occupied by an object of type TYPE
3668 : : when it resides in memory. The value is measured in units of bytes,
3669 : : and its data type is that normally used for type sizes
3670 : : (which is the first type created by make_signed_type or
3671 : : make_unsigned_type). */
3672 : :
3673 : : tree
3674 : 24731601 : size_in_bytes_loc (location_t loc, const_tree type)
3675 : : {
3676 : 24731601 : tree t;
3677 : :
3678 : 24731601 : if (type == error_mark_node)
3679 : 0 : return integer_zero_node;
3680 : :
3681 : 24731601 : type = TYPE_MAIN_VARIANT (type);
3682 : 24731601 : t = TYPE_SIZE_UNIT (type);
3683 : :
3684 : 24731601 : if (t == 0)
3685 : : {
3686 : 56 : lang_hooks.types.incomplete_type_error (loc, NULL_TREE, type);
3687 : 56 : return size_zero_node;
3688 : : }
3689 : :
3690 : : return t;
3691 : : }
3692 : :
3693 : : /* Return the size of TYPE (in bytes) as a wide integer
3694 : : or return -1 if the size can vary or is larger than an integer. */
3695 : :
3696 : : HOST_WIDE_INT
3697 : 460920197 : int_size_in_bytes (const_tree type)
3698 : : {
3699 : 460920197 : tree t;
3700 : :
3701 : 460920197 : if (type == error_mark_node)
3702 : : return 0;
3703 : :
3704 : 460920197 : type = TYPE_MAIN_VARIANT (type);
3705 : 460920197 : t = TYPE_SIZE_UNIT (type);
3706 : :
3707 : 460920197 : if (t && tree_fits_uhwi_p (t))
3708 : 460871845 : return TREE_INT_CST_LOW (t);
3709 : : else
3710 : : return -1;
3711 : : }
3712 : :
3713 : : /* Return the maximum size of TYPE (in bytes) as a wide integer
3714 : : or return -1 if the size can vary or is larger than an integer. */
3715 : :
3716 : : HOST_WIDE_INT
3717 : 9084 : max_int_size_in_bytes (const_tree type)
3718 : : {
3719 : 9084 : HOST_WIDE_INT size = -1;
3720 : 9084 : tree size_tree;
3721 : :
3722 : : /* If this is an array type, check for a possible MAX_SIZE attached. */
3723 : :
3724 : 9084 : if (TREE_CODE (type) == ARRAY_TYPE)
3725 : : {
3726 : 8367 : size_tree = TYPE_ARRAY_MAX_SIZE (type);
3727 : :
3728 : 8367 : if (size_tree && tree_fits_uhwi_p (size_tree))
3729 : 0 : size = tree_to_uhwi (size_tree);
3730 : : }
3731 : :
3732 : : /* If we still haven't been able to get a size, see if the language
3733 : : can compute a maximum size. */
3734 : :
3735 : 0 : if (size == -1)
3736 : : {
3737 : 9084 : size_tree = lang_hooks.types.max_size (type);
3738 : :
3739 : 9084 : if (size_tree && tree_fits_uhwi_p (size_tree))
3740 : 0 : size = tree_to_uhwi (size_tree);
3741 : : }
3742 : :
3743 : 9084 : return size;
3744 : : }
3745 : :
3746 : : /* Return the bit position of FIELD, in bits from the start of the record.
3747 : : This is a tree of type bitsizetype. */
3748 : :
3749 : : tree
3750 : 89274528 : bit_position (const_tree field)
3751 : : {
3752 : 89274528 : return bit_from_pos (DECL_FIELD_OFFSET (field),
3753 : 89274528 : DECL_FIELD_BIT_OFFSET (field));
3754 : : }
3755 : :
3756 : : /* Return the byte position of FIELD, in bytes from the start of the record.
3757 : : This is a tree of type sizetype. */
3758 : :
3759 : : tree
3760 : 95681983 : byte_position (const_tree field)
3761 : : {
3762 : 95681983 : return byte_from_pos (DECL_FIELD_OFFSET (field),
3763 : 95681983 : DECL_FIELD_BIT_OFFSET (field));
3764 : : }
3765 : :
3766 : : /* Likewise, but return as an integer. It must be representable in
3767 : : that way (since it could be a signed value, we don't have the
3768 : : option of returning -1 like int_size_in_byte can. */
3769 : :
3770 : : HOST_WIDE_INT
3771 : 9683041 : int_byte_position (const_tree field)
3772 : : {
3773 : 9683041 : return tree_to_shwi (byte_position (field));
3774 : : }
3775 : :
3776 : : /* Return, as a tree node, the number of elements for TYPE (which is an
3777 : : ARRAY_TYPE) minus one. This counts only elements of the top array. */
3778 : :
3779 : : tree
3780 : 71352518 : array_type_nelts_minus_one (const_tree type)
3781 : : {
3782 : 71352518 : tree index_type, min, max;
3783 : :
3784 : : /* If they did it with unspecified bounds, then we should have already
3785 : : given an error about it before we got here. */
3786 : 71352518 : if (! TYPE_DOMAIN (type))
3787 : 4298192 : return error_mark_node;
3788 : :
3789 : 67054326 : index_type = TYPE_DOMAIN (type);
3790 : 67054326 : min = TYPE_MIN_VALUE (index_type);
3791 : 67054326 : max = TYPE_MAX_VALUE (index_type);
3792 : :
3793 : : /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
3794 : 67054326 : if (!max)
3795 : : {
3796 : : /* zero sized arrays are represented from C FE as complete types with
3797 : : NULL TYPE_MAX_VALUE and zero TYPE_SIZE, while C++ FE represents
3798 : : them as min 0, max -1. */
3799 : 1231750 : if (COMPLETE_TYPE_P (type)
3800 : 3120 : && integer_zerop (TYPE_SIZE (type))
3801 : 1234870 : && integer_zerop (min))
3802 : 3120 : return build_int_cst (TREE_TYPE (min), -1);
3803 : :
3804 : 1228630 : return error_mark_node;
3805 : : }
3806 : :
3807 : 65822576 : return (integer_zerop (min)
3808 : 65822576 : ? max
3809 : 1030074 : : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
3810 : : }
3811 : :
3812 : : /* Return, as an INTEGER_CST node, the number of elements for TYPE
3813 : : (which is an ARRAY_TYPE). This counts only elements of the top
3814 : : array. */
3815 : :
3816 : : tree
3817 : 4035434 : array_type_nelts_top (tree type)
3818 : : {
3819 : 4035434 : return fold_build2_loc (input_location,
3820 : : PLUS_EXPR, sizetype,
3821 : : array_type_nelts_minus_one (type),
3822 : 4035434 : size_one_node);
3823 : : }
3824 : :
3825 : : /* If arg is static -- a reference to an object in static storage -- then
3826 : : return the object. This is not the same as the C meaning of `static'.
3827 : : If arg isn't static, return NULL. */
3828 : :
3829 : : tree
3830 : 918373322 : staticp (tree arg)
3831 : : {
3832 : 921018573 : switch (TREE_CODE (arg))
3833 : : {
3834 : : case FUNCTION_DECL:
3835 : : /* Nested functions are static, even though taking their address will
3836 : : involve a trampoline as we unnest the nested function and create
3837 : : the trampoline on the tree level. */
3838 : : return arg;
3839 : :
3840 : 579913290 : case VAR_DECL:
3841 : 455961426 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3842 : 167639062 : && ! DECL_THREAD_LOCAL_P (arg)
3843 : 165877814 : && ! DECL_DLLIMPORT_P (arg)
3844 : 579913290 : ? arg : NULL);
3845 : :
3846 : 535047 : case CONST_DECL:
3847 : 62 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3848 : 535047 : ? arg : NULL);
3849 : :
3850 : 0 : case CONSTRUCTOR:
3851 : 0 : return TREE_STATIC (arg) ? arg : NULL;
3852 : :
3853 : : case LABEL_DECL:
3854 : : case STRING_CST:
3855 : : return arg;
3856 : :
3857 : 2356121 : case COMPONENT_REF:
3858 : : /* If the thing being referenced is not a field, then it is
3859 : : something language specific. */
3860 : 2356121 : gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL);
3861 : :
3862 : : /* If we are referencing a bitfield, we can't evaluate an
3863 : : ADDR_EXPR at compile time and so it isn't a constant. */
3864 : 2356121 : if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
3865 : : return NULL;
3866 : :
3867 : 2356121 : return staticp (TREE_OPERAND (arg, 0));
3868 : :
3869 : : case BIT_FIELD_REF:
3870 : : return NULL;
3871 : :
3872 : 1015175 : case INDIRECT_REF:
3873 : 1015175 : return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
3874 : :
3875 : 289473 : case ARRAY_REF:
3876 : 289473 : case ARRAY_RANGE_REF:
3877 : 289473 : if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
3878 : 289473 : && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
3879 : 289130 : return staticp (TREE_OPERAND (arg, 0));
3880 : : else
3881 : : return NULL;
3882 : :
3883 : 930 : case COMPOUND_LITERAL_EXPR:
3884 : 930 : return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;
3885 : :
3886 : : default:
3887 : : return NULL;
3888 : : }
3889 : : }
3890 : :
3891 : :
3892 : :
3893 : :
3894 : : /* Return whether OP is a DECL whose address is function-invariant. */
3895 : :
3896 : : bool
3897 : 4601162312 : decl_address_invariant_p (const_tree op)
3898 : : {
3899 : : /* The conditions below are slightly less strict than the one in
3900 : : staticp. */
3901 : :
3902 : 4601162312 : switch (TREE_CODE (op))
3903 : : {
3904 : : case PARM_DECL:
3905 : : case RESULT_DECL:
3906 : : case LABEL_DECL:
3907 : : case FUNCTION_DECL:
3908 : : return true;
3909 : :
3910 : 2494985795 : case VAR_DECL:
3911 : 1842834417 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3912 : 1718271163 : || DECL_THREAD_LOCAL_P (op)
3913 : 1718271163 : || DECL_CONTEXT (op) == current_function_decl
3914 : 2500888990 : || decl_function_context (op) == current_function_decl)
3915 : 2489082600 : return true;
3916 : : break;
3917 : :
3918 : 25370700 : case CONST_DECL:
3919 : 0 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3920 : 25370700 : || decl_function_context (op) == current_function_decl)
3921 : 25370700 : return true;
3922 : : break;
3923 : :
3924 : : default:
3925 : : break;
3926 : : }
3927 : :
3928 : : return false;
3929 : : }
3930 : :
3931 : : /* Return whether OP is a DECL whose address is interprocedural-invariant. */
3932 : :
3933 : : bool
3934 : 1528957 : decl_address_ip_invariant_p (const_tree op)
3935 : : {
3936 : : /* The conditions below are slightly less strict than the one in
3937 : : staticp. */
3938 : :
3939 : 1528957 : switch (TREE_CODE (op))
3940 : : {
3941 : : case LABEL_DECL:
3942 : : case FUNCTION_DECL:
3943 : : case STRING_CST:
3944 : : return true;
3945 : :
3946 : 1369436 : case VAR_DECL:
3947 : 946563 : if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
3948 : 456216 : && !DECL_DLLIMPORT_P (op))
3949 : 2282656 : || DECL_THREAD_LOCAL_P (op))
3950 : 456216 : return true;
3951 : : break;
3952 : :
3953 : 51606 : case CONST_DECL:
3954 : 51606 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
3955 : : return true;
3956 : : break;
3957 : :
3958 : : default:
3959 : : break;
3960 : : }
3961 : :
3962 : : return false;
3963 : : }
3964 : :
3965 : :
3966 : : /* Return true if T is function-invariant (internal function, does
3967 : : not handle arithmetic; that's handled in skip_simple_arithmetic and
3968 : : tree_invariant_p). */
3969 : :
3970 : : static bool
3971 : 14022543 : tree_invariant_p_1 (tree t)
3972 : : {
3973 : 14022543 : tree op;
3974 : :
3975 : 14022543 : if (TREE_CONSTANT (t)
3976 : 14022543 : || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
3977 : : return true;
3978 : :
3979 : 12306350 : switch (TREE_CODE (t))
3980 : : {
3981 : : case SAVE_EXPR:
3982 : : case TARGET_EXPR:
3983 : : return true;
3984 : :
3985 : 19575 : case ADDR_EXPR:
3986 : 19575 : op = TREE_OPERAND (t, 0);
3987 : 25661 : while (handled_component_p (op))
3988 : : {
3989 : 6983 : switch (TREE_CODE (op))
3990 : : {
3991 : 1333 : case ARRAY_REF:
3992 : 1333 : case ARRAY_RANGE_REF:
3993 : 1333 : if (!tree_invariant_p (TREE_OPERAND (op, 1))
3994 : 436 : || TREE_OPERAND (op, 2) != NULL_TREE
3995 : 1769 : || TREE_OPERAND (op, 3) != NULL_TREE)
3996 : : return false;
3997 : : break;
3998 : :
3999 : 5535 : case COMPONENT_REF:
4000 : 5535 : if (TREE_OPERAND (op, 2) != NULL_TREE)
4001 : : return false;
4002 : : break;
4003 : :
4004 : 6086 : default:;
4005 : : }
4006 : 6086 : op = TREE_OPERAND (op, 0);
4007 : : }
4008 : :
4009 : 18678 : return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
4010 : :
4011 : : default:
4012 : : break;
4013 : : }
4014 : :
4015 : : return false;
4016 : : }
4017 : :
4018 : : /* Return true if T is function-invariant. */
4019 : :
4020 : : bool
4021 : 11451466 : tree_invariant_p (tree t)
4022 : : {
4023 : 11451466 : tree inner = skip_simple_arithmetic (t);
4024 : 11451466 : return tree_invariant_p_1 (inner);
4025 : : }
4026 : :
4027 : : /* Wrap a SAVE_EXPR around EXPR, if appropriate.
4028 : : Do this to any expression which may be used in more than one place,
4029 : : but must be evaluated only once.
4030 : :
4031 : : Normally, expand_expr would reevaluate the expression each time.
4032 : : Calling save_expr produces something that is evaluated and recorded
4033 : : the first time expand_expr is called on it. Subsequent calls to
4034 : : expand_expr just reuse the recorded value.
4035 : :
4036 : : The call to expand_expr that generates code that actually computes
4037 : : the value is the first call *at compile time*. Subsequent calls
4038 : : *at compile time* generate code to use the saved value.
4039 : : This produces correct result provided that *at run time* control
4040 : : always flows through the insns made by the first expand_expr
4041 : : before reaching the other places where the save_expr was evaluated.
4042 : : You, the caller of save_expr, must make sure this is so.
4043 : :
4044 : : Constants, and certain read-only nodes, are returned with no
4045 : : SAVE_EXPR because that is safe. Expressions containing placeholders
4046 : : are not touched; see tree.def for an explanation of what these
4047 : : are used for. */
4048 : :
4049 : : tree
4050 : 2571088 : save_expr (tree expr)
4051 : : {
4052 : 2571088 : tree inner;
4053 : :
4054 : : /* If the tree evaluates to a constant, then we don't want to hide that
4055 : : fact (i.e. this allows further folding, and direct checks for constants).
4056 : : However, a read-only object that has side effects cannot be bypassed.
4057 : : Since it is no problem to reevaluate literals, we just return the
4058 : : literal node. */
4059 : 2571088 : inner = skip_simple_arithmetic (expr);
4060 : 2571088 : if (TREE_CODE (inner) == ERROR_MARK)
4061 : : return inner;
4062 : :
4063 : 2571077 : if (tree_invariant_p_1 (inner))
4064 : : return expr;
4065 : :
4066 : : /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
4067 : : it means that the size or offset of some field of an object depends on
4068 : : the value within another field.
4069 : :
4070 : : Note that it must not be the case that EXPR contains both a PLACEHOLDER_EXPR
4071 : : and some variable since it would then need to be both evaluated once and
4072 : : evaluated more than once. Front-ends must assure this case cannot
4073 : : happen by surrounding any such subexpressions in their own SAVE_EXPR
4074 : : and forcing evaluation at the proper time. */
4075 : 1909975 : if (contains_placeholder_p (inner))
4076 : : return expr;
4077 : :
4078 : 1909975 : expr = build1_loc (EXPR_LOCATION (expr), SAVE_EXPR, TREE_TYPE (expr), expr);
4079 : :
4080 : : /* This expression might be placed ahead of a jump to ensure that the
4081 : : value was computed on both sides of the jump. So make sure it isn't
4082 : : eliminated as dead. */
4083 : 1909975 : TREE_SIDE_EFFECTS (expr) = 1;
4084 : 1909975 : return expr;
4085 : : }
4086 : :
4087 : : /* Look inside EXPR into any simple arithmetic operations. Return the
4088 : : outermost non-arithmetic or non-invariant node. */
4089 : :
4090 : : tree
4091 : 14022554 : skip_simple_arithmetic (tree expr)
4092 : : {
4093 : : /* We don't care about whether this can be used as an lvalue in this
4094 : : context. */
4095 : 14032958 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4096 : 10404 : expr = TREE_OPERAND (expr, 0);
4097 : :
4098 : : /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
4099 : : a constant, it will be more efficient to not make another SAVE_EXPR since
4100 : : it will allow better simplification and GCSE will be able to merge the
4101 : : computations if they actually occur. */
4102 : 37870726 : while (true)
4103 : : {
4104 : 37870726 : if (UNARY_CLASS_P (expr))
4105 : 14685519 : expr = TREE_OPERAND (expr, 0);
4106 : 23185207 : else if (BINARY_CLASS_P (expr))
4107 : : {
4108 : : /* Before commutative binary operands are canonicalized,
4109 : : it is quite common to have constants in the first operand.
4110 : : Check for that common case first so that we don't walk
4111 : : large expressions with tree_invariant_p unnecessarily.
4112 : : This can still have terrible compile time complexity,
4113 : : we should limit the depth of the tree_invariant_p and
4114 : : skip_simple_arithmetic recursion. */
4115 : 9222019 : if ((TREE_CONSTANT (TREE_OPERAND (expr, 0))
4116 : 9211969 : || (TREE_READONLY (TREE_OPERAND (expr, 0))
4117 : 9659 : && !TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0))))
4118 : 9231642 : && tree_invariant_p (TREE_OPERAND (expr, 0)))
4119 : 19673 : expr = TREE_OPERAND (expr, 1);
4120 : 9202346 : else if (tree_invariant_p (TREE_OPERAND (expr, 1)))
4121 : 9133723 : expr = TREE_OPERAND (expr, 0);
4122 : 68623 : else if (tree_invariant_p (TREE_OPERAND (expr, 0)))
4123 : 9257 : expr = TREE_OPERAND (expr, 1);
4124 : : else
4125 : : break;
4126 : : }
4127 : : else
4128 : : break;
4129 : : }
4130 : :
4131 : 14022554 : return expr;
4132 : : }
4133 : :
4134 : : /* Look inside EXPR into simple arithmetic operations involving constants.
4135 : : Return the outermost non-arithmetic or non-constant node. */
4136 : :
4137 : : tree
4138 : 0 : skip_simple_constant_arithmetic (tree expr)
4139 : : {
4140 : 0 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4141 : 0 : expr = TREE_OPERAND (expr, 0);
4142 : :
4143 : 0 : while (true)
4144 : : {
4145 : 0 : if (UNARY_CLASS_P (expr))
4146 : 0 : expr = TREE_OPERAND (expr, 0);
4147 : 0 : else if (BINARY_CLASS_P (expr))
4148 : : {
4149 : 0 : if (TREE_CONSTANT (TREE_OPERAND (expr, 1)))
4150 : 0 : expr = TREE_OPERAND (expr, 0);
4151 : 0 : else if (TREE_CONSTANT (TREE_OPERAND (expr, 0)))
4152 : 0 : expr = TREE_OPERAND (expr, 1);
4153 : : else
4154 : : break;
4155 : : }
4156 : : else
4157 : : break;
4158 : : }
4159 : :
4160 : 0 : return expr;
4161 : : }
4162 : :
4163 : : /* Return which tree structure is used by T. */
4164 : :
4165 : : enum tree_node_structure_enum
4166 : 34120879047 : tree_node_structure (const_tree t)
4167 : : {
4168 : 34120879047 : const enum tree_code code = TREE_CODE (t);
4169 : 34120879047 : return tree_node_structure_for_code (code);
4170 : : }
4171 : :
4172 : : /* Set various status flags when building a CALL_EXPR object T. */
4173 : :
4174 : : static void
4175 : 213511269 : process_call_operands (tree t)
4176 : : {
4177 : 213511269 : bool side_effects = TREE_SIDE_EFFECTS (t);
4178 : 213511269 : bool read_only = false;
4179 : 213511269 : int i = call_expr_flags (t);
4180 : :
4181 : : /* Calls have side-effects, except those to const or pure functions. */
4182 : 213511269 : if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
4183 : : side_effects = true;
4184 : : /* Propagate TREE_READONLY of arguments for const functions. */
4185 : 52488038 : if (i & ECF_CONST)
4186 : 50911908 : read_only = true;
4187 : :
4188 : 213511269 : if (!side_effects || read_only)
4189 : 278804220 : for (i = 1; i < TREE_OPERAND_LENGTH (t); i++)
4190 : : {
4191 : 226316686 : tree op = TREE_OPERAND (t, i);
4192 : 226316686 : if (op && TREE_SIDE_EFFECTS (op))
4193 : : side_effects = true;
4194 : 226316686 : if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op))
4195 : : read_only = false;
4196 : : }
4197 : :
4198 : 213511269 : TREE_SIDE_EFFECTS (t) = side_effects;
4199 : 213511269 : TREE_READONLY (t) = read_only;
4200 : 213511269 : }
4201 : :
4202 : : /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
4203 : : size or offset that depends on a field within a record. */
4204 : :
4205 : : bool
4206 : 37492674 : contains_placeholder_p (const_tree exp)
4207 : : {
4208 : 37492674 : enum tree_code code;
4209 : :
4210 : 37492674 : if (!exp)
4211 : : return false;
4212 : :
4213 : 37492674 : code = TREE_CODE (exp);
4214 : 37492674 : if (code == PLACEHOLDER_EXPR)
4215 : : return true;
4216 : :
4217 : 37492674 : switch (TREE_CODE_CLASS (code))
4218 : : {
4219 : 1163455 : case tcc_reference:
4220 : : /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
4221 : : position computations since they will be converted into a
4222 : : WITH_RECORD_EXPR involving the reference, which will assume
4223 : : here will be valid. */
4224 : 1163455 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4225 : :
4226 : 481046 : case tcc_exceptional:
4227 : 481046 : if (code == TREE_LIST)
4228 : 0 : return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
4229 : 0 : || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
4230 : : break;
4231 : :
4232 : 33430428 : case tcc_unary:
4233 : 33430428 : case tcc_binary:
4234 : 33430428 : case tcc_comparison:
4235 : 33430428 : case tcc_expression:
4236 : 33430428 : switch (code)
4237 : : {
4238 : 5148 : case COMPOUND_EXPR:
4239 : : /* Ignoring the first operand isn't quite right, but works best. */
4240 : 5148 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
4241 : :
4242 : 2937 : case COND_EXPR:
4243 : 5874 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4244 : 2937 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
4245 : 5874 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
4246 : :
4247 : : case SAVE_EXPR:
4248 : : /* The save_expr function never wraps anything containing
4249 : : a PLACEHOLDER_EXPR. */
4250 : : return false;
4251 : :
4252 : 24212709 : default:
4253 : 24212709 : break;
4254 : : }
4255 : :
4256 : 24212709 : switch (TREE_CODE_LENGTH (code))
4257 : : {
4258 : 14751020 : case 1:
4259 : 14751020 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4260 : 9434183 : case 2:
4261 : 18867217 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4262 : 18867217 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
4263 : : default:
4264 : : return false;
4265 : : }
4266 : :
4267 : 434682 : case tcc_vl_exp:
4268 : 434682 : switch (code)
4269 : : {
4270 : 434682 : case CALL_EXPR:
4271 : 434682 : {
4272 : 434682 : const_tree arg;
4273 : 434682 : const_call_expr_arg_iterator iter;
4274 : 1420578 : FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
4275 : 551214 : if (CONTAINS_PLACEHOLDER_P (arg))
4276 : : return true;
4277 : : return false;
4278 : : }
4279 : : default:
4280 : : return false;
4281 : : }
4282 : :
4283 : : default:
4284 : : return false;
4285 : : }
4286 : : return false;
4287 : : }
4288 : :
4289 : : /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
4290 : : directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
4291 : : field positions. */
4292 : :
4293 : : static bool
4294 : 734977 : type_contains_placeholder_1 (const_tree type)
4295 : : {
4296 : : /* If the size contains a placeholder or the parent type (component type in
4297 : : the case of arrays) type involves a placeholder, this type does. */
4298 : 1450537 : if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
4299 : 734977 : || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
4300 : 1469954 : || (!POINTER_TYPE_P (type)
4301 : 606370 : && TREE_TYPE (type)
4302 : 101734 : && type_contains_placeholder_p (TREE_TYPE (type))))
4303 : 0 : return true;
4304 : :
4305 : : /* Now do type-specific checks. Note that the last part of the check above
4306 : : greatly limits what we have to do below. */
4307 : 734977 : switch (TREE_CODE (type))
4308 : : {
4309 : : case VOID_TYPE:
4310 : : case OPAQUE_TYPE:
4311 : : case COMPLEX_TYPE:
4312 : : case ENUMERAL_TYPE:
4313 : : case BOOLEAN_TYPE:
4314 : : case POINTER_TYPE:
4315 : : case OFFSET_TYPE:
4316 : : case REFERENCE_TYPE:
4317 : : case METHOD_TYPE:
4318 : : case FUNCTION_TYPE:
4319 : : case VECTOR_TYPE:
4320 : : case NULLPTR_TYPE:
4321 : : return false;
4322 : :
4323 : 163066 : case INTEGER_TYPE:
4324 : 163066 : case BITINT_TYPE:
4325 : 163066 : case REAL_TYPE:
4326 : 163066 : case FIXED_POINT_TYPE:
4327 : : /* Here we just check the bounds. */
4328 : 317183 : return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
4329 : 317183 : || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
4330 : :
4331 : 52724 : case ARRAY_TYPE:
4332 : : /* We have already checked the component type above, so just check
4333 : : the domain type. Flexible array members have a null domain. */
4334 : 105436 : return TYPE_DOMAIN (type) ?
4335 : 52712 : type_contains_placeholder_p (TYPE_DOMAIN (type)) : false;
4336 : :
4337 : 367856 : case RECORD_TYPE:
4338 : 367856 : case UNION_TYPE:
4339 : 367856 : case QUAL_UNION_TYPE:
4340 : 367856 : {
4341 : 367856 : tree field;
4342 : :
4343 : 10433290 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
4344 : 10065434 : if (TREE_CODE (field) == FIELD_DECL
4345 : 10065434 : && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
4346 : 863632 : || (TREE_CODE (type) == QUAL_UNION_TYPE
4347 : 0 : && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
4348 : 863632 : || type_contains_placeholder_p (TREE_TYPE (field))))
4349 : 0 : return true;
4350 : :
4351 : : return false;
4352 : : }
4353 : :
4354 : 0 : default:
4355 : 0 : gcc_unreachable ();
4356 : : }
4357 : : }
4358 : :
4359 : : /* Wrapper around above function used to cache its result. */
4360 : :
4361 : : bool
4362 : 3127421 : type_contains_placeholder_p (tree type)
4363 : : {
4364 : 3127421 : bool result;
4365 : :
4366 : : /* If the contains_placeholder_bits field has been initialized,
4367 : : then we know the answer. */
4368 : 3127421 : if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
4369 : 2392444 : return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
4370 : :
4371 : : /* Indicate that we've seen this type node, and the answer is false.
4372 : : This is what we want to return if we run into recursion via fields. */
4373 : 734977 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
4374 : :
4375 : : /* Compute the real value. */
4376 : 734977 : result = type_contains_placeholder_1 (type);
4377 : :
4378 : : /* Store the real value. */
4379 : 734977 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
4380 : :
4381 : 734977 : return result;
4382 : : }
4383 : :
4384 : : /* Push tree EXP onto vector QUEUE if it is not already present. */
4385 : :
4386 : : static void
4387 : 0 : push_without_duplicates (tree exp, vec<tree> *queue)
4388 : : {
4389 : 0 : unsigned int i;
4390 : 0 : tree iter;
4391 : :
4392 : 0 : FOR_EACH_VEC_ELT (*queue, i, iter)
4393 : 0 : if (simple_cst_equal (iter, exp) == 1)
4394 : : break;
4395 : :
4396 : 0 : if (!iter)
4397 : 0 : queue->safe_push (exp);
4398 : 0 : }
4399 : :
4400 : : /* Given a tree EXP, find all occurrences of references to fields
4401 : : in a PLACEHOLDER_EXPR and place them in vector REFS without
4402 : : duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
4403 : : we assume here that EXP contains only arithmetic expressions
4404 : : or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
4405 : : argument list. */
4406 : :
4407 : : void
4408 : 0 : find_placeholder_in_expr (tree exp, vec<tree> *refs)
4409 : : {
4410 : 0 : enum tree_code code = TREE_CODE (exp);
4411 : 0 : tree inner;
4412 : 0 : int i;
4413 : :
4414 : : /* We handle TREE_LIST and COMPONENT_REF separately. */
4415 : 0 : if (code == TREE_LIST)
4416 : : {
4417 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs);
4418 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs);
4419 : : }
4420 : 0 : else if (code == COMPONENT_REF)
4421 : : {
4422 : 0 : for (inner = TREE_OPERAND (exp, 0);
4423 : 0 : REFERENCE_CLASS_P (inner);
4424 : 0 : inner = TREE_OPERAND (inner, 0))
4425 : : ;
4426 : :
4427 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
4428 : 0 : push_without_duplicates (exp, refs);
4429 : : else
4430 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs);
4431 : : }
4432 : : else
4433 : 0 : switch (TREE_CODE_CLASS (code))
4434 : : {
4435 : : case tcc_constant:
4436 : : break;
4437 : :
4438 : 0 : case tcc_declaration:
4439 : : /* Variables allocated to static storage can stay. */
4440 : 0 : if (!TREE_STATIC (exp))
4441 : 0 : push_without_duplicates (exp, refs);
4442 : : break;
4443 : :
4444 : 0 : case tcc_expression:
4445 : : /* This is the pattern built in ada/make_aligning_type. */
4446 : 0 : if (code == ADDR_EXPR
4447 : 0 : && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR)
4448 : : {
4449 : 0 : push_without_duplicates (exp, refs);
4450 : 0 : break;
4451 : : }
4452 : :
4453 : : /* Fall through. */
4454 : :
4455 : : case tcc_exceptional:
4456 : : case tcc_unary:
4457 : : case tcc_binary:
4458 : : case tcc_comparison:
4459 : : case tcc_reference:
4460 : 0 : for (i = 0; i < TREE_CODE_LENGTH (code); i++)
4461 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4462 : : break;
4463 : :
4464 : : case tcc_vl_exp:
4465 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4466 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4467 : : break;
4468 : :
4469 : 0 : default:
4470 : 0 : gcc_unreachable ();
4471 : : }
4472 : 0 : }
4473 : :
4474 : : /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
4475 : : return a tree with all occurrences of references to F in a
4476 : : PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
4477 : : CONST_DECLs. Note that we assume here that EXP contains only
4478 : : arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
4479 : : occurring only in their argument list. */
4480 : :
4481 : : tree
4482 : 0 : substitute_in_expr (tree exp, tree f, tree r)
4483 : : {
4484 : 0 : enum tree_code code = TREE_CODE (exp);
4485 : 0 : tree op0, op1, op2, op3;
4486 : 0 : tree new_tree;
4487 : :
4488 : : /* We handle TREE_LIST and COMPONENT_REF separately. */
4489 : 0 : if (code == TREE_LIST)
4490 : : {
4491 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
4492 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
4493 : 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4494 : : return exp;
4495 : :
4496 : 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4497 : : }
4498 : 0 : else if (code == COMPONENT_REF)
4499 : : {
4500 : 0 : tree inner;
4501 : :
4502 : : /* If this expression is getting a value from a PLACEHOLDER_EXPR
4503 : : and it is the right field, replace it with R. */
4504 : 0 : for (inner = TREE_OPERAND (exp, 0);
4505 : 0 : REFERENCE_CLASS_P (inner);
4506 : 0 : inner = TREE_OPERAND (inner, 0))
4507 : : ;
4508 : :
4509 : : /* The field. */
4510 : 0 : op1 = TREE_OPERAND (exp, 1);
4511 : :
4512 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f)
4513 : : return r;
4514 : :
4515 : : /* If this expression hasn't been completed let, leave it alone. */
4516 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner))
4517 : : return exp;
4518 : :
4519 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4520 : 0 : if (op0 == TREE_OPERAND (exp, 0))
4521 : : return exp;
4522 : :
4523 : 0 : new_tree
4524 : 0 : = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE);
4525 : : }
4526 : : else
4527 : 0 : switch (TREE_CODE_CLASS (code))
4528 : : {
4529 : : case tcc_constant:
4530 : : return exp;
4531 : :
4532 : 0 : case tcc_declaration:
4533 : 0 : if (exp == f)
4534 : : return r;
4535 : : else
4536 : : return exp;
4537 : :
4538 : 0 : case tcc_expression:
4539 : 0 : if (exp == f)
4540 : : return r;
4541 : :
4542 : : /* Fall through. */
4543 : :
4544 : 0 : case tcc_exceptional:
4545 : 0 : case tcc_unary:
4546 : 0 : case tcc_binary:
4547 : 0 : case tcc_comparison:
4548 : 0 : case tcc_reference:
4549 : 0 : switch (TREE_CODE_LENGTH (code))
4550 : : {
4551 : : case 0:
4552 : : return exp;
4553 : :
4554 : 0 : case 1:
4555 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4556 : 0 : if (op0 == TREE_OPERAND (exp, 0))
4557 : : return exp;
4558 : :
4559 : 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4560 : 0 : break;
4561 : :
4562 : 0 : case 2:
4563 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4564 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4565 : :
4566 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4567 : : return exp;
4568 : :
4569 : 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4570 : 0 : break;
4571 : :
4572 : 0 : case 3:
4573 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4574 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4575 : 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4576 : :
4577 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4578 : 0 : && op2 == TREE_OPERAND (exp, 2))
4579 : : return exp;
4580 : :
4581 : 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4582 : 0 : break;
4583 : :
4584 : 0 : case 4:
4585 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4586 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4587 : 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4588 : 0 : op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
4589 : :
4590 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4591 : 0 : && op2 == TREE_OPERAND (exp, 2)
4592 : 0 : && op3 == TREE_OPERAND (exp, 3))
4593 : : return exp;
4594 : :
4595 : 0 : new_tree
4596 : 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4597 : 0 : break;
4598 : :
4599 : 0 : default:
4600 : 0 : gcc_unreachable ();
4601 : : }
4602 : : break;
4603 : :
4604 : 0 : case tcc_vl_exp:
4605 : 0 : {
4606 : 0 : int i;
4607 : :
4608 : 0 : new_tree = NULL_TREE;
4609 : :
4610 : : /* If we are trying to replace F with a constant or with another
4611 : : instance of one of the arguments of the call, inline back
4612 : : functions which do nothing else than computing a value from
4613 : : the arguments they are passed. This makes it possible to
4614 : : fold partially or entirely the replacement expression. */
4615 : 0 : if (code == CALL_EXPR)
4616 : : {
4617 : 0 : bool maybe_inline = false;
4618 : 0 : if (CONSTANT_CLASS_P (r))
4619 : : maybe_inline = true;
4620 : : else
4621 : 0 : for (i = 3; i < TREE_OPERAND_LENGTH (exp); i++)
4622 : 0 : if (operand_equal_p (TREE_OPERAND (exp, i), r, 0))
4623 : : {
4624 : : maybe_inline = true;
4625 : : break;
4626 : : }
4627 : 0 : if (maybe_inline)
4628 : : {
4629 : 0 : tree t = maybe_inline_call_in_expr (exp);
4630 : 0 : if (t)
4631 : 0 : return SUBSTITUTE_IN_EXPR (t, f, r);
4632 : : }
4633 : : }
4634 : :
4635 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4636 : : {
4637 : 0 : tree op = TREE_OPERAND (exp, i);
4638 : 0 : tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
4639 : 0 : if (new_op != op)
4640 : : {
4641 : 0 : if (!new_tree)
4642 : 0 : new_tree = copy_node (exp);
4643 : 0 : TREE_OPERAND (new_tree, i) = new_op;
4644 : : }
4645 : : }
4646 : :
4647 : 0 : if (new_tree)
4648 : : {
4649 : 0 : new_tree = fold (new_tree);
4650 : 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4651 : 0 : process_call_operands (new_tree);
4652 : : }
4653 : : else
4654 : : return exp;
4655 : : }
4656 : : break;
4657 : :
4658 : 0 : default:
4659 : 0 : gcc_unreachable ();
4660 : : }
4661 : :
4662 : 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4663 : :
4664 : 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4665 : 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4666 : :
4667 : : return new_tree;
4668 : : }
4669 : :
4670 : : /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
4671 : : for it within OBJ, a tree that is an object or a chain of references. */
4672 : :
4673 : : tree
4674 : 203702 : substitute_placeholder_in_expr (tree exp, tree obj)
4675 : : {
4676 : 203702 : enum tree_code code = TREE_CODE (exp);
4677 : 203702 : tree op0, op1, op2, op3;
4678 : 203702 : tree new_tree;
4679 : :
4680 : : /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
4681 : : in the chain of OBJ. */
4682 : 203702 : if (code == PLACEHOLDER_EXPR)
4683 : : {
4684 : 0 : tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
4685 : 0 : tree elt;
4686 : :
4687 : 0 : for (elt = obj; elt != 0;
4688 : 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4689 : 0 : || TREE_CODE (elt) == COND_EXPR)
4690 : 0 : ? TREE_OPERAND (elt, 1)
4691 : 0 : : (REFERENCE_CLASS_P (elt)
4692 : : || UNARY_CLASS_P (elt)
4693 : : || BINARY_CLASS_P (elt)
4694 : : || VL_EXP_CLASS_P (elt)
4695 : : || EXPRESSION_CLASS_P (elt))
4696 : 0 : ? TREE_OPERAND (elt, 0) : 0))
4697 : 0 : if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
4698 : : return elt;
4699 : :
4700 : 0 : for (elt = obj; elt != 0;
4701 : 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4702 : 0 : || TREE_CODE (elt) == COND_EXPR)
4703 : 0 : ? TREE_OPERAND (elt, 1)
4704 : 0 : : (REFERENCE_CLASS_P (elt)
4705 : : || UNARY_CLASS_P (elt)
4706 : : || BINARY_CLASS_P (elt)
4707 : : || VL_EXP_CLASS_P (elt)
4708 : : || EXPRESSION_CLASS_P (elt))
4709 : 0 : ? TREE_OPERAND (elt, 0) : 0))
4710 : 0 : if (POINTER_TYPE_P (TREE_TYPE (elt))
4711 : 0 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
4712 : : == need_type))
4713 : 0 : return fold_build1 (INDIRECT_REF, need_type, elt);
4714 : :
4715 : : /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
4716 : : survives until RTL generation, there will be an error. */
4717 : : return exp;
4718 : : }
4719 : :
4720 : : /* TREE_LIST is special because we need to look at TREE_VALUE
4721 : : and TREE_CHAIN, not TREE_OPERANDS. */
4722 : 203702 : else if (code == TREE_LIST)
4723 : : {
4724 : 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
4725 : 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
4726 : 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4727 : : return exp;
4728 : :
4729 : 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4730 : : }
4731 : : else
4732 : 203702 : switch (TREE_CODE_CLASS (code))
4733 : : {
4734 : : case tcc_constant:
4735 : : case tcc_declaration:
4736 : : return exp;
4737 : :
4738 : 9059 : case tcc_exceptional:
4739 : 9059 : case tcc_unary:
4740 : 9059 : case tcc_binary:
4741 : 9059 : case tcc_comparison:
4742 : 9059 : case tcc_expression:
4743 : 9059 : case tcc_reference:
4744 : 9059 : case tcc_statement:
4745 : 9059 : switch (TREE_CODE_LENGTH (code))
4746 : : {
4747 : : case 0:
4748 : : return exp;
4749 : :
4750 : 6861 : case 1:
4751 : 6861 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4752 : 6861 : if (op0 == TREE_OPERAND (exp, 0))
4753 : : return exp;
4754 : :
4755 : 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4756 : 0 : break;
4757 : :
4758 : 2186 : case 2:
4759 : 2186 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4760 : 2186 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4761 : :
4762 : 2186 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4763 : : return exp;
4764 : :
4765 : 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4766 : 0 : break;
4767 : :
4768 : 12 : case 3:
4769 : 12 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4770 : 12 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4771 : 12 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4772 : :
4773 : 24 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4774 : 24 : && op2 == TREE_OPERAND (exp, 2))
4775 : : return exp;
4776 : :
4777 : 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4778 : 0 : break;
4779 : :
4780 : 0 : case 4:
4781 : 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4782 : 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4783 : 0 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4784 : 0 : op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
4785 : :
4786 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4787 : 0 : && op2 == TREE_OPERAND (exp, 2)
4788 : 0 : && op3 == TREE_OPERAND (exp, 3))
4789 : : return exp;
4790 : :
4791 : 0 : new_tree
4792 : 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4793 : 0 : break;
4794 : :
4795 : 0 : default:
4796 : 0 : gcc_unreachable ();
4797 : : }
4798 : : break;
4799 : :
4800 : : case tcc_vl_exp:
4801 : : {
4802 : : int i;
4803 : :
4804 : : new_tree = NULL_TREE;
4805 : :
4806 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4807 : : {
4808 : 0 : tree op = TREE_OPERAND (exp, i);
4809 : 0 : tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
4810 : 0 : if (new_op != op)
4811 : : {
4812 : 0 : if (!new_tree)
4813 : 0 : new_tree = copy_node (exp);
4814 : 0 : TREE_OPERAND (new_tree, i) = new_op;
4815 : : }
4816 : : }
4817 : :
4818 : 0 : if (new_tree)
4819 : : {
4820 : 0 : new_tree = fold (new_tree);
4821 : 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4822 : 0 : process_call_operands (new_tree);
4823 : : }
4824 : : else
4825 : : return exp;
4826 : : }
4827 : : break;
4828 : :
4829 : 0 : default:
4830 : 0 : gcc_unreachable ();
4831 : : }
4832 : :
4833 : 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4834 : :
4835 : 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4836 : 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4837 : :
4838 : : return new_tree;
4839 : : }
4840 : :
4841 : :
4842 : : /* Subroutine of stabilize_reference; this is called for subtrees of
4843 : : references. Any expression with side-effects must be put in a SAVE_EXPR
4844 : : to ensure that it is only evaluated once.
4845 : :
4846 : : We don't put SAVE_EXPR nodes around everything, because assigning very
4847 : : simple expressions to temporaries causes us to miss good opportunities
4848 : : for optimizations. Among other things, the opportunity to fold in the
4849 : : addition of a constant into an addressing mode often gets lost, e.g.
4850 : : "y[i+1] += x;". In general, we take the approach that we should not make
4851 : : an assignment unless we are forced into it - i.e., that any non-side effect
4852 : : operator should be allowed, and that cse should take care of coalescing
4853 : : multiple utterances of the same expression should that prove fruitful. */
4854 : :
4855 : : static tree
4856 : 520016 : stabilize_reference_1 (tree e)
4857 : : {
4858 : 520016 : tree result;
4859 : 520016 : enum tree_code code = TREE_CODE (e);
4860 : :
4861 : : /* We cannot ignore const expressions because it might be a reference
4862 : : to a const array but whose index contains side-effects. But we can
4863 : : ignore things that are actual constant or that already have been
4864 : : handled by this function. */
4865 : :
4866 : 520016 : if (tree_invariant_p (e))
4867 : : return e;
4868 : :
4869 : 144007 : switch (TREE_CODE_CLASS (code))
4870 : : {
4871 : 0 : case tcc_exceptional:
4872 : : /* Always wrap STATEMENT_LIST into SAVE_EXPR, even if it doesn't
4873 : : have side-effects. */
4874 : 0 : if (code == STATEMENT_LIST)
4875 : 0 : return save_expr (e);
4876 : : /* FALLTHRU */
4877 : 115955 : case tcc_type:
4878 : 115955 : case tcc_declaration:
4879 : 115955 : case tcc_comparison:
4880 : 115955 : case tcc_statement:
4881 : 115955 : case tcc_expression:
4882 : 115955 : case tcc_reference:
4883 : 115955 : case tcc_vl_exp:
4884 : : /* If the expression has side-effects, then encase it in a SAVE_EXPR
4885 : : so that it will only be evaluated once. */
4886 : : /* The reference (r) and comparison (<) classes could be handled as
4887 : : below, but it is generally faster to only evaluate them once. */
4888 : 115955 : if (TREE_SIDE_EFFECTS (e))
4889 : 963 : return save_expr (e);
4890 : : return e;
4891 : :
4892 : : case tcc_constant:
4893 : : /* Constants need no processing. In fact, we should never reach
4894 : : here. */
4895 : : return e;
4896 : :
4897 : 21086 : case tcc_binary:
4898 : : /* Division is slow and tends to be compiled with jumps,
4899 : : especially the division by powers of 2 that is often
4900 : : found inside of an array reference. So do it just once. */
4901 : 21086 : if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
4902 : 19046 : || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
4903 : 19046 : || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
4904 : 19046 : || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
4905 : 2040 : return save_expr (e);
4906 : : /* Recursively stabilize each operand. */
4907 : 19046 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
4908 : 19046 : stabilize_reference_1 (TREE_OPERAND (e, 1)));
4909 : 19046 : break;
4910 : :
4911 : 6966 : case tcc_unary:
4912 : : /* Recursively stabilize each operand. */
4913 : 6966 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
4914 : 6966 : break;
4915 : :
4916 : 0 : default:
4917 : 0 : gcc_unreachable ();
4918 : : }
4919 : :
4920 : 26012 : TREE_TYPE (result) = TREE_TYPE (e);
4921 : 26012 : TREE_READONLY (result) = TREE_READONLY (e);
4922 : 26012 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
4923 : 26012 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
4924 : :
4925 : 26012 : return result;
4926 : : }
4927 : :
4928 : : /* Stabilize a reference so that we can use it any number of times
4929 : : without causing its operands to be evaluated more than once.
4930 : : Returns the stabilized reference. This works by means of save_expr,
4931 : : so see the caveats in the comments about save_expr.
4932 : :
4933 : : Also allows conversion expressions whose operands are references.
4934 : : Any other kind of expression is returned unchanged. */
4935 : :
4936 : : tree
4937 : 3866200 : stabilize_reference (tree ref)
4938 : : {
4939 : 3866200 : tree result;
4940 : 3866200 : enum tree_code code = TREE_CODE (ref);
4941 : :
4942 : 3866200 : switch (code)
4943 : : {
4944 : : case VAR_DECL:
4945 : : case PARM_DECL:
4946 : : case RESULT_DECL:
4947 : : /* No action is needed in this case. */
4948 : : return ref;
4949 : :
4950 : 0 : CASE_CONVERT:
4951 : 0 : case FLOAT_EXPR:
4952 : 0 : case FIX_TRUNC_EXPR:
4953 : 0 : result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
4954 : 0 : break;
4955 : :
4956 : 428787 : case INDIRECT_REF:
4957 : 428787 : result = build_nt (INDIRECT_REF,
4958 : 428787 : stabilize_reference_1 (TREE_OPERAND (ref, 0)));
4959 : 428787 : break;
4960 : :
4961 : 290678 : case COMPONENT_REF:
4962 : 290678 : result = build_nt (COMPONENT_REF,
4963 : 290678 : stabilize_reference (TREE_OPERAND (ref, 0)),
4964 : 290678 : TREE_OPERAND (ref, 1), NULL_TREE);
4965 : 290678 : break;
4966 : :
4967 : 0 : case BIT_FIELD_REF:
4968 : 0 : result = build_nt (BIT_FIELD_REF,
4969 : 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
4970 : 0 : TREE_OPERAND (ref, 1), TREE_OPERAND (ref, 2));
4971 : 0 : REF_REVERSE_STORAGE_ORDER (result) = REF_REVERSE_STORAGE_ORDER (ref);
4972 : 0 : break;
4973 : :
4974 : 46171 : case ARRAY_REF:
4975 : 92342 : result = build_nt (ARRAY_REF,
4976 : 46171 : stabilize_reference (TREE_OPERAND (ref, 0)),
4977 : 46171 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
4978 : 46171 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
4979 : 46171 : break;
4980 : :
4981 : 0 : case ARRAY_RANGE_REF:
4982 : 0 : result = build_nt (ARRAY_RANGE_REF,
4983 : 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
4984 : 0 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
4985 : 0 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
4986 : 0 : break;
4987 : :
4988 : 0 : case COMPOUND_EXPR:
4989 : : /* We cannot wrap the first expression in a SAVE_EXPR, as then
4990 : : it wouldn't be ignored. This matters when dealing with
4991 : : volatiles. */
4992 : 0 : return stabilize_reference_1 (ref);
4993 : :
4994 : : /* If arg isn't a kind of lvalue we recognize, make no change.
4995 : : Caller should recognize the error for an invalid lvalue. */
4996 : : default:
4997 : : return ref;
4998 : :
4999 : 0 : case ERROR_MARK:
5000 : 0 : return error_mark_node;
5001 : : }
5002 : :
5003 : 765636 : TREE_TYPE (result) = TREE_TYPE (ref);
5004 : 765636 : TREE_READONLY (result) = TREE_READONLY (ref);
5005 : 765636 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
5006 : 765636 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
5007 : 765636 : protected_set_expr_location (result, EXPR_LOCATION (ref));
5008 : :
5009 : 765636 : return result;
5010 : : }
5011 : :
5012 : : /* Low-level constructors for expressions. */
5013 : :
5014 : : /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
5015 : : and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
5016 : :
5017 : : void
5018 : 1095489619 : recompute_tree_invariant_for_addr_expr (tree t)
5019 : : {
5020 : 1095489619 : tree node;
5021 : 1095489619 : bool tc = true, se = false;
5022 : :
5023 : 1095489619 : gcc_assert (TREE_CODE (t) == ADDR_EXPR);
5024 : :
5025 : : /* We started out assuming this address is both invariant and constant, but
5026 : : does not have side effects. Now go down any handled components and see if
5027 : : any of them involve offsets that are either non-constant or non-invariant.
5028 : : Also check for side-effects.
5029 : :
5030 : : ??? Note that this code makes no attempt to deal with the case where
5031 : : taking the address of something causes a copy due to misalignment. */
5032 : :
5033 : : #define UPDATE_FLAGS(NODE) \
5034 : : do { tree _node = (NODE); \
5035 : : if (_node && !TREE_CONSTANT (_node)) tc = false; \
5036 : : if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
5037 : :
5038 : 1289473977 : for (node = TREE_OPERAND (t, 0); handled_component_p (node);
5039 : 193984358 : node = TREE_OPERAND (node, 0))
5040 : : {
5041 : : /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
5042 : : array reference (probably made temporarily by the G++ front end),
5043 : : so ignore all the operands. */
5044 : 193984358 : if ((TREE_CODE (node) == ARRAY_REF
5045 : 193984358 : || TREE_CODE (node) == ARRAY_RANGE_REF)
5046 : 193984358 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
5047 : : {
5048 : 29619584 : UPDATE_FLAGS (TREE_OPERAND (node, 1));
5049 : 29619584 : if (TREE_OPERAND (node, 2))
5050 : 1924649 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5051 : 29619584 : if (TREE_OPERAND (node, 3))
5052 : 261785 : UPDATE_FLAGS (TREE_OPERAND (node, 3));
5053 : : }
5054 : : /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
5055 : : FIELD_DECL, apparently. The G++ front end can put something else
5056 : : there, at least temporarily. */
5057 : 164364774 : else if (TREE_CODE (node) == COMPONENT_REF
5058 : 164364774 : && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
5059 : : {
5060 : 163612774 : if (TREE_OPERAND (node, 2))
5061 : 16529 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5062 : : }
5063 : : }
5064 : :
5065 : 1095489619 : node = lang_hooks.expr_to_decl (node, &tc, &se);
5066 : :
5067 : : /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
5068 : : the address, since &(*a)->b is a form of addition. If it's a constant, the
5069 : : address is constant too. If it's a decl, its address is constant if the
5070 : : decl is static. Everything else is not constant and, furthermore,
5071 : : taking the address of a volatile variable is not volatile. */
5072 : 1095489619 : if (INDIRECT_REF_P (node)
5073 : 1060879049 : || TREE_CODE (node) == MEM_REF)
5074 : 136747218 : UPDATE_FLAGS (TREE_OPERAND (node, 0));
5075 : 958742401 : else if (CONSTANT_CLASS_P (node))
5076 : : ;
5077 : 891994281 : else if (DECL_P (node))
5078 : 878017663 : tc &= (staticp (node) != NULL_TREE);
5079 : : else
5080 : : {
5081 : 13976618 : tc = false;
5082 : 13976618 : se |= TREE_SIDE_EFFECTS (node);
5083 : : }
5084 : :
5085 : :
5086 : 1095489619 : TREE_CONSTANT (t) = tc;
5087 : 1095489619 : TREE_SIDE_EFFECTS (t) = se;
5088 : : #undef UPDATE_FLAGS
5089 : 1095489619 : }
5090 : :
5091 : : /* Build an expression of code CODE, data type TYPE, and operands as
5092 : : specified. Expressions and reference nodes can be created this way.
5093 : : Constants, decls, types and misc nodes cannot be.
5094 : :
5095 : : We define 5 non-variadic functions, from 0 to 4 arguments. This is
5096 : : enough for all extant tree codes. */
5097 : :
5098 : : tree
5099 : 308691904 : build0 (enum tree_code code, tree tt MEM_STAT_DECL)
5100 : : {
5101 : 308691904 : tree t;
5102 : :
5103 : 308691904 : gcc_assert (TREE_CODE_LENGTH (code) == 0);
5104 : :
5105 : 308691904 : t = make_node (code PASS_MEM_STAT);
5106 : 308691904 : TREE_TYPE (t) = tt;
5107 : :
5108 : 308691904 : return t;
5109 : : }
5110 : :
5111 : : tree
5112 : 2982506048 : build1 (enum tree_code code, tree type, tree node MEM_STAT_DECL)
5113 : : {
5114 : 2982506048 : int length = sizeof (struct tree_exp);
5115 : 2982506048 : tree t;
5116 : :
5117 : 2982506048 : record_node_allocation_statistics (code, length);
5118 : :
5119 : 2982506048 : gcc_assert (TREE_CODE_LENGTH (code) == 1);
5120 : :
5121 : 2982506048 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
5122 : :
5123 : 2982506048 : memset (t, 0, sizeof (struct tree_common));
5124 : :
5125 : 2982506048 : TREE_SET_CODE (t, code);
5126 : :
5127 : 2982506048 : TREE_TYPE (t) = type;
5128 : 2982506048 : SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
5129 : 2982506048 : TREE_OPERAND (t, 0) = node;
5130 : 2982506048 : if (node && !TYPE_P (node))
5131 : : {
5132 : 2982491060 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
5133 : 2982491060 : TREE_READONLY (t) = TREE_READONLY (node);
5134 : : }
5135 : :
5136 : 2982506048 : if (TREE_CODE_CLASS (code) == tcc_statement)
5137 : : {
5138 : 21162084 : if (code != DEBUG_BEGIN_STMT)
5139 : 21162084 : TREE_SIDE_EFFECTS (t) = 1;
5140 : : }
5141 : 2961343964 : else switch (code)
5142 : : {
5143 : 50791 : case VA_ARG_EXPR:
5144 : : /* All of these have side-effects, no matter what their
5145 : : operands are. */
5146 : 50791 : TREE_SIDE_EFFECTS (t) = 1;
5147 : 50791 : TREE_READONLY (t) = 0;
5148 : 50791 : break;
5149 : :
5150 : 460470394 : case INDIRECT_REF:
5151 : : /* Whether a dereference is readonly has nothing to do with whether
5152 : : its operand is readonly. */
5153 : 460470394 : TREE_READONLY (t) = 0;
5154 : 460470394 : break;
5155 : :
5156 : 480829951 : case ADDR_EXPR:
5157 : 480829951 : if (node)
5158 : 480829951 : recompute_tree_invariant_for_addr_expr (t);
5159 : : break;
5160 : :
5161 : 2019992828 : default:
5162 : 793466320 : if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
5163 : 1912153962 : && node && !TYPE_P (node)
5164 : 3932146790 : && TREE_CONSTANT (node))
5165 : 462509623 : TREE_CONSTANT (t) = 1;
5166 : 2019992828 : if (TREE_CODE_CLASS (code) == tcc_reference
5167 : 687950035 : && node && TREE_THIS_VOLATILE (node))
5168 : 2231633 : TREE_THIS_VOLATILE (t) = 1;
5169 : : break;
5170 : : }
5171 : :
5172 : 2982506048 : return t;
5173 : : }
5174 : :
5175 : : #define PROCESS_ARG(N) \
5176 : : do { \
5177 : : TREE_OPERAND (t, N) = arg##N; \
5178 : : if (arg##N &&!TYPE_P (arg##N)) \
5179 : : { \
5180 : : if (TREE_SIDE_EFFECTS (arg##N)) \
5181 : : side_effects = 1; \
5182 : : if (!TREE_READONLY (arg##N) \
5183 : : && !CONSTANT_CLASS_P (arg##N)) \
5184 : : (void) (read_only = 0); \
5185 : : if (!TREE_CONSTANT (arg##N)) \
5186 : : (void) (constant = 0); \
5187 : : } \
5188 : : } while (0)
5189 : :
5190 : : tree
5191 : 982837130 : build2 (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
5192 : : {
5193 : 982837130 : bool constant, read_only, side_effects, div_by_zero;
5194 : 982837130 : tree t;
5195 : :
5196 : 982837130 : gcc_assert (TREE_CODE_LENGTH (code) == 2);
5197 : :
5198 : 982837130 : if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
5199 : 170889023 : && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
5200 : : /* When sizetype precision doesn't match that of pointers
5201 : : we need to be able to build explicit extensions or truncations
5202 : : of the offset argument. */
5203 : 982837130 : && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
5204 : 0 : gcc_assert (TREE_CODE (arg0) == INTEGER_CST
5205 : : && TREE_CODE (arg1) == INTEGER_CST);
5206 : :
5207 : 982837130 : if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
5208 : 21161896 : gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
5209 : : && ptrofftype_p (TREE_TYPE (arg1)));
5210 : :
5211 : 982837130 : t = make_node (code PASS_MEM_STAT);
5212 : 982837130 : TREE_TYPE (t) = tt;
5213 : :
5214 : : /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
5215 : : result based on those same flags for the arguments. But if the
5216 : : arguments aren't really even `tree' expressions, we shouldn't be trying
5217 : : to do this. */
5218 : :
5219 : : /* Expressions without side effects may be constant if their
5220 : : arguments are as well. */
5221 : 1965674260 : constant = (TREE_CODE_CLASS (code) == tcc_comparison
5222 : 982837130 : || TREE_CODE_CLASS (code) == tcc_binary);
5223 : 982837130 : read_only = 1;
5224 : 982837130 : side_effects = TREE_SIDE_EFFECTS (t);
5225 : :
5226 : 982837130 : switch (code)
5227 : : {
5228 : 9332914 : case TRUNC_DIV_EXPR:
5229 : 9332914 : case CEIL_DIV_EXPR:
5230 : 9332914 : case FLOOR_DIV_EXPR:
5231 : 9332914 : case ROUND_DIV_EXPR:
5232 : 9332914 : case EXACT_DIV_EXPR:
5233 : 9332914 : case CEIL_MOD_EXPR:
5234 : 9332914 : case FLOOR_MOD_EXPR:
5235 : 9332914 : case ROUND_MOD_EXPR:
5236 : 9332914 : case TRUNC_MOD_EXPR:
5237 : 9332914 : div_by_zero = integer_zerop (arg1);
5238 : 9332914 : break;
5239 : : default:
5240 : : div_by_zero = false;
5241 : : }
5242 : :
5243 : 1069608270 : PROCESS_ARG (0);
5244 : 1379897565 : PROCESS_ARG (1);
5245 : :
5246 : 982837130 : TREE_SIDE_EFFECTS (t) = side_effects;
5247 : 982837130 : if (code == MEM_REF)
5248 : : {
5249 : 61702611 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5250 : : {
5251 : 11692305 : tree o = TREE_OPERAND (arg0, 0);
5252 : 11692305 : TREE_READONLY (t) = TREE_READONLY (o);
5253 : 11692305 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5254 : : }
5255 : : }
5256 : : else
5257 : : {
5258 : 921134519 : TREE_READONLY (t) = read_only;
5259 : : /* Don't mark X / 0 as constant. */
5260 : 921134519 : TREE_CONSTANT (t) = constant && !div_by_zero;
5261 : 921134519 : TREE_THIS_VOLATILE (t)
5262 : 921134519 : = (TREE_CODE_CLASS (code) == tcc_reference
5263 : 921134519 : && arg0 && TREE_THIS_VOLATILE (arg0));
5264 : : }
5265 : :
5266 : 982837130 : return t;
5267 : : }
5268 : :
5269 : :
5270 : : tree
5271 : 372059503 : build3 (enum tree_code code, tree tt, tree arg0, tree arg1,
5272 : : tree arg2 MEM_STAT_DECL)
5273 : : {
5274 : 372059503 : bool constant, read_only, side_effects;
5275 : 372059503 : tree t;
5276 : :
5277 : 372059503 : gcc_assert (TREE_CODE_LENGTH (code) == 3);
5278 : 372059503 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5279 : :
5280 : 372059503 : t = make_node (code PASS_MEM_STAT);
5281 : 372059503 : TREE_TYPE (t) = tt;
5282 : :
5283 : 372059503 : read_only = 1;
5284 : :
5285 : : /* As a special exception, if COND_EXPR has NULL branches, we
5286 : : assume that it is a gimple statement and always consider
5287 : : it to have side effects. */
5288 : 372059503 : if (code == COND_EXPR
5289 : 29841674 : && tt == void_type_node
5290 : 20010874 : && arg1 == NULL_TREE
5291 : 20010874 : && arg2 == NULL_TREE)
5292 : : side_effects = true;
5293 : : else
5294 : 372059503 : side_effects = TREE_SIDE_EFFECTS (t);
5295 : :
5296 : 403982702 : PROCESS_ARG (0);
5297 : 381552687 : PROCESS_ARG (1);
5298 : 381269484 : PROCESS_ARG (2);
5299 : :
5300 : 372059503 : if (code == COND_EXPR)
5301 : 29841674 : TREE_READONLY (t) = read_only;
5302 : :
5303 : 372059503 : TREE_SIDE_EFFECTS (t) = side_effects;
5304 : 372059503 : TREE_THIS_VOLATILE (t)
5305 : 372059503 : = (TREE_CODE_CLASS (code) == tcc_reference
5306 : 372059503 : && arg0 && TREE_THIS_VOLATILE (arg0));
5307 : :
5308 : 372059503 : return t;
5309 : : }
5310 : :
5311 : : tree
5312 : 33458766 : build4 (enum tree_code code, tree tt, tree arg0, tree arg1,
5313 : : tree arg2, tree arg3 MEM_STAT_DECL)
5314 : : {
5315 : 33458766 : bool constant, read_only, side_effects;
5316 : 33458766 : tree t;
5317 : :
5318 : 33458766 : gcc_assert (TREE_CODE_LENGTH (code) == 4);
5319 : :
5320 : 33458766 : t = make_node (code PASS_MEM_STAT);
5321 : 33458766 : TREE_TYPE (t) = tt;
5322 : :
5323 : 33458766 : side_effects = TREE_SIDE_EFFECTS (t);
5324 : :
5325 : 33458766 : PROCESS_ARG (0);
5326 : 33458766 : PROCESS_ARG (1);
5327 : 33458766 : PROCESS_ARG (2);
5328 : 33458766 : PROCESS_ARG (3);
5329 : :
5330 : 33458766 : TREE_SIDE_EFFECTS (t) = side_effects;
5331 : 33458766 : TREE_THIS_VOLATILE (t)
5332 : 66917532 : = (TREE_CODE_CLASS (code) == tcc_reference
5333 : 33458766 : && arg0 && TREE_THIS_VOLATILE (arg0));
5334 : :
5335 : 33458766 : return t;
5336 : : }
5337 : :
5338 : : tree
5339 : 1007836 : build5 (enum tree_code code, tree tt, tree arg0, tree arg1,
5340 : : tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
5341 : : {
5342 : 1007836 : bool constant, read_only, side_effects;
5343 : 1007836 : tree t;
5344 : :
5345 : 1007836 : gcc_assert (TREE_CODE_LENGTH (code) == 5);
5346 : :
5347 : 1007836 : t = make_node (code PASS_MEM_STAT);
5348 : 1007836 : TREE_TYPE (t) = tt;
5349 : :
5350 : 1007836 : side_effects = TREE_SIDE_EFFECTS (t);
5351 : :
5352 : 1007836 : PROCESS_ARG (0);
5353 : 1007836 : PROCESS_ARG (1);
5354 : 1007836 : PROCESS_ARG (2);
5355 : 1007836 : PROCESS_ARG (3);
5356 : 1007836 : PROCESS_ARG (4);
5357 : :
5358 : 1007836 : TREE_SIDE_EFFECTS (t) = side_effects;
5359 : 1007836 : if (code == TARGET_MEM_REF)
5360 : : {
5361 : 1001729 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5362 : : {
5363 : 183983 : tree o = TREE_OPERAND (arg0, 0);
5364 : 183983 : TREE_READONLY (t) = TREE_READONLY (o);
5365 : 183983 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5366 : : }
5367 : : }
5368 : : else
5369 : 6107 : TREE_THIS_VOLATILE (t)
5370 : 6107 : = (TREE_CODE_CLASS (code) == tcc_reference
5371 : 6107 : && arg0 && TREE_THIS_VOLATILE (arg0));
5372 : :
5373 : 1007836 : return t;
5374 : : }
5375 : :
5376 : : /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
5377 : : on the pointer PTR. */
5378 : :
5379 : : tree
5380 : 472332 : build_simple_mem_ref_loc (location_t loc, tree ptr)
5381 : : {
5382 : 472332 : poly_int64 offset = 0;
5383 : 472332 : tree ptype = TREE_TYPE (ptr);
5384 : 472332 : tree tem;
5385 : : /* For convenience allow addresses that collapse to a simple base
5386 : : and offset. */
5387 : 472332 : if (TREE_CODE (ptr) == ADDR_EXPR
5388 : 472332 : && (handled_component_p (TREE_OPERAND (ptr, 0))
5389 : 15316 : || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF))
5390 : : {
5391 : 187 : ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset);
5392 : 187 : gcc_assert (ptr);
5393 : 187 : if (TREE_CODE (ptr) == MEM_REF)
5394 : : {
5395 : 77 : offset += mem_ref_offset (ptr).force_shwi ();
5396 : 77 : ptr = TREE_OPERAND (ptr, 0);
5397 : : }
5398 : : else
5399 : 110 : ptr = build_fold_addr_expr (ptr);
5400 : 187 : gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr));
5401 : : }
5402 : 472332 : tem = build2 (MEM_REF, TREE_TYPE (ptype),
5403 : : ptr, build_int_cst (ptype, offset));
5404 : 472332 : SET_EXPR_LOCATION (tem, loc);
5405 : 472332 : return tem;
5406 : : }
5407 : :
5408 : : /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
5409 : :
5410 : : poly_offset_int
5411 : 871501288 : mem_ref_offset (const_tree t)
5412 : : {
5413 : 871501288 : return poly_offset_int::from (wi::to_poly_wide (TREE_OPERAND (t, 1)),
5414 : 871501288 : SIGNED);
5415 : : }
5416 : :
5417 : : /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
5418 : : offsetted by OFFSET units. */
5419 : :
5420 : : tree
5421 : 184745 : build_invariant_address (tree type, tree base, poly_int64 offset)
5422 : : {
5423 : 184745 : tree ref = fold_build2 (MEM_REF, TREE_TYPE (type),
5424 : : build_fold_addr_expr (base),
5425 : : build_int_cst (ptr_type_node, offset));
5426 : 184745 : tree addr = build1 (ADDR_EXPR, type, ref);
5427 : 184745 : recompute_tree_invariant_for_addr_expr (addr);
5428 : 184745 : return addr;
5429 : : }
5430 : :
5431 : : /* Similar except don't specify the TREE_TYPE
5432 : : and leave the TREE_SIDE_EFFECTS as 0.
5433 : : It is permissible for arguments to be null,
5434 : : or even garbage if their values do not matter. */
5435 : :
5436 : : tree
5437 : 1798100 : build_nt (enum tree_code code, ...)
5438 : : {
5439 : 1798100 : tree t;
5440 : 1798100 : int length;
5441 : 1798100 : int i;
5442 : 1798100 : va_list p;
5443 : :
5444 : 1798100 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5445 : :
5446 : 1798100 : va_start (p, code);
5447 : :
5448 : 1798100 : t = make_node (code);
5449 : 1798100 : length = TREE_CODE_LENGTH (code);
5450 : :
5451 : 5073394 : for (i = 0; i < length; i++)
5452 : 3275294 : TREE_OPERAND (t, i) = va_arg (p, tree);
5453 : :
5454 : 1798100 : va_end (p);
5455 : 1798100 : return t;
5456 : : }
5457 : :
5458 : : /* Similar to build_nt, but for creating a CALL_EXPR object with a
5459 : : tree vec. */
5460 : :
5461 : : tree
5462 : 0 : build_nt_call_vec (tree fn, vec<tree, va_gc> *args)
5463 : : {
5464 : 0 : tree ret, t;
5465 : 0 : unsigned int ix;
5466 : :
5467 : 0 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
5468 : 0 : CALL_EXPR_FN (ret) = fn;
5469 : 0 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
5470 : 0 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
5471 : 0 : CALL_EXPR_ARG (ret, ix) = t;
5472 : 0 : return ret;
5473 : : }
5474 : :
5475 : : /* Create a DECL_... node of code CODE, name NAME (if non-null)
5476 : : and data type TYPE.
5477 : : We do NOT enter this node in any sort of symbol table.
5478 : :
5479 : : LOC is the location of the decl.
5480 : :
5481 : : layout_decl is used to set up the decl's storage layout.
5482 : : Other slots are initialized to 0 or null pointers. */
5483 : :
5484 : : tree
5485 : 2764692139 : build_decl (location_t loc, enum tree_code code, tree name,
5486 : : tree type MEM_STAT_DECL)
5487 : : {
5488 : 2764692139 : tree t;
5489 : :
5490 : 2764692139 : t = make_node (code PASS_MEM_STAT);
5491 : 2764692139 : DECL_SOURCE_LOCATION (t) = loc;
5492 : :
5493 : : /* if (type == error_mark_node)
5494 : : type = integer_type_node; */
5495 : : /* That is not done, deliberately, so that having error_mark_node
5496 : : as the type can suppress useless errors in the use of this variable. */
5497 : :
5498 : 2764692139 : DECL_NAME (t) = name;
5499 : 2764692139 : TREE_TYPE (t) = type;
5500 : :
5501 : 2764692139 : if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
5502 : 977024652 : layout_decl (t, 0);
5503 : :
5504 : 2764692139 : return t;
5505 : : }
5506 : :
5507 : : /* Create and return a DEBUG_EXPR_DECL node of the given TYPE. */
5508 : :
5509 : : tree
5510 : 1434203 : build_debug_expr_decl (tree type)
5511 : : {
5512 : 1434203 : tree vexpr = make_node (DEBUG_EXPR_DECL);
5513 : 1434203 : DECL_ARTIFICIAL (vexpr) = 1;
5514 : 1434203 : TREE_TYPE (vexpr) = type;
5515 : 1434203 : SET_DECL_MODE (vexpr, TYPE_MODE (type));
5516 : 1434203 : return vexpr;
5517 : : }
5518 : :
5519 : : /* Builds and returns function declaration with NAME and TYPE. */
5520 : :
5521 : : tree
5522 : 18730 : build_fn_decl (const char *name, tree type)
5523 : : {
5524 : 18730 : tree id = get_identifier (name);
5525 : 18730 : tree decl = build_decl (input_location, FUNCTION_DECL, id, type);
5526 : :
5527 : 18730 : DECL_EXTERNAL (decl) = 1;
5528 : 18730 : TREE_PUBLIC (decl) = 1;
5529 : 18730 : DECL_ARTIFICIAL (decl) = 1;
5530 : 18730 : TREE_NOTHROW (decl) = 1;
5531 : :
5532 : 18730 : return decl;
5533 : : }
5534 : :
5535 : : vec<tree, va_gc> *all_translation_units;
5536 : :
5537 : : /* Builds a new translation-unit decl with name NAME, queues it in the
5538 : : global list of translation-unit decls and returns it. */
5539 : :
5540 : : tree
5541 : 246448 : build_translation_unit_decl (tree name)
5542 : : {
5543 : 246448 : tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL,
5544 : 246448 : name, NULL_TREE);
5545 : 246448 : TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
5546 : 246448 : vec_safe_push (all_translation_units, tu);
5547 : 246448 : return tu;
5548 : : }
5549 : :
5550 : :
5551 : : /* BLOCK nodes are used to represent the structure of binding contours
5552 : : and declarations, once those contours have been exited and their contents
5553 : : compiled. This information is used for outputting debugging info. */
5554 : :
5555 : : tree
5556 : 672481 : build_block (tree vars, tree subblocks, tree supercontext, tree chain)
5557 : : {
5558 : 672481 : tree block = make_node (BLOCK);
5559 : :
5560 : 672481 : BLOCK_VARS (block) = vars;
5561 : 672481 : BLOCK_SUBBLOCKS (block) = subblocks;
5562 : 672481 : BLOCK_SUPERCONTEXT (block) = supercontext;
5563 : 672481 : BLOCK_CHAIN (block) = chain;
5564 : 672481 : return block;
5565 : : }
5566 : :
5567 : :
5568 : : /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
5569 : :
5570 : : LOC is the location to use in tree T. */
5571 : :
5572 : : void
5573 : 11445726305 : protected_set_expr_location (tree t, location_t loc)
5574 : : {
5575 : 11445726305 : if (CAN_HAVE_LOCATION_P (t))
5576 : 1836038903 : SET_EXPR_LOCATION (t, loc);
5577 : 9553585787 : else if (t && TREE_CODE (t) == STATEMENT_LIST)
5578 : : {
5579 : 22231 : t = expr_single (t);
5580 : 22231 : if (t && CAN_HAVE_LOCATION_P (t))
5581 : 18 : SET_EXPR_LOCATION (t, loc);
5582 : : }
5583 : 11445726305 : }
5584 : :
5585 : : /* Like PROTECTED_SET_EXPR_LOCATION, but only do that if T has
5586 : : UNKNOWN_LOCATION. */
5587 : :
5588 : : void
5589 : 19103845 : protected_set_expr_location_if_unset (tree t, location_t loc)
5590 : : {
5591 : 19103845 : t = expr_single (t);
5592 : 19103845 : if (t && !EXPR_HAS_LOCATION (t))
5593 : 14656008 : protected_set_expr_location (t, loc);
5594 : 19103845 : }
5595 : :
5596 : : /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5597 : : of the various TYPE_QUAL values. */
5598 : :
5599 : : static void
5600 : 85525177 : set_type_quals (tree type, int type_quals)
5601 : : {
5602 : 85525177 : TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
5603 : 85525177 : TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
5604 : 85525177 : TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
5605 : 85525177 : TYPE_ATOMIC (type) = (type_quals & TYPE_QUAL_ATOMIC) != 0;
5606 : 85525177 : TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals);
5607 : 85525177 : }
5608 : :
5609 : : /* Returns true iff CAND and BASE have equivalent language-specific
5610 : : qualifiers. */
5611 : :
5612 : : bool
5613 : 2186375381 : check_lang_type (const_tree cand, const_tree base)
5614 : : {
5615 : 2186375381 : if (lang_hooks.types.type_hash_eq == NULL)
5616 : : return true;
5617 : : /* type_hash_eq currently only applies to these types. */
5618 : 2126291509 : if (TREE_CODE (cand) != FUNCTION_TYPE
5619 : 2126291509 : && TREE_CODE (cand) != METHOD_TYPE)
5620 : : return true;
5621 : 963483 : return lang_hooks.types.type_hash_eq (cand, base);
5622 : : }
5623 : :
5624 : : /* This function checks to see if TYPE matches the size one of the built-in
5625 : : atomic types, and returns that core atomic type. */
5626 : :
5627 : : static tree
5628 : 8279 : find_atomic_core_type (const_tree type)
5629 : : {
5630 : 8279 : tree base_atomic_type;
5631 : :
5632 : : /* Only handle complete types. */
5633 : 8279 : if (!tree_fits_uhwi_p (TYPE_SIZE (type)))
5634 : : return NULL_TREE;
5635 : :
5636 : 8275 : switch (tree_to_uhwi (TYPE_SIZE (type)))
5637 : : {
5638 : 2444 : case 8:
5639 : 2444 : base_atomic_type = atomicQI_type_node;
5640 : 2444 : break;
5641 : :
5642 : 786 : case 16:
5643 : 786 : base_atomic_type = atomicHI_type_node;
5644 : 786 : break;
5645 : :
5646 : 987 : case 32:
5647 : 987 : base_atomic_type = atomicSI_type_node;
5648 : 987 : break;
5649 : :
5650 : 2629 : case 64:
5651 : 2629 : base_atomic_type = atomicDI_type_node;
5652 : 2629 : break;
5653 : :
5654 : 1309 : case 128:
5655 : 1309 : base_atomic_type = atomicTI_type_node;
5656 : 1309 : break;
5657 : :
5658 : : default:
5659 : : base_atomic_type = NULL_TREE;
5660 : : }
5661 : :
5662 : : return base_atomic_type;
5663 : : }
5664 : :
5665 : : /* Returns true iff unqualified CAND and BASE are equivalent. */
5666 : :
5667 : : bool
5668 : 3470146482 : check_base_type (const_tree cand, const_tree base)
5669 : : {
5670 : 3470146482 : if (TYPE_NAME (cand) != TYPE_NAME (base)
5671 : : /* Apparently this is needed for Objective-C. */
5672 : 3190385019 : || TYPE_CONTEXT (cand) != TYPE_CONTEXT (base)
5673 : 6660531501 : || !attribute_list_equal (TYPE_ATTRIBUTES (cand),
5674 : 3190385019 : TYPE_ATTRIBUTES (base)))
5675 : 279761463 : return false;
5676 : : /* Check alignment. */
5677 : 3190385019 : if (TYPE_ALIGN (cand) == TYPE_ALIGN (base)
5678 : 3190385019 : && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base))
5679 : : return true;
5680 : : /* Atomic types increase minimal alignment. We must to do so as well
5681 : : or we get duplicated canonical types. See PR88686. */
5682 : 10216 : if ((TYPE_QUALS (cand) & TYPE_QUAL_ATOMIC))
5683 : : {
5684 : : /* See if this object can map to a basic atomic type. */
5685 : 1775 : tree atomic_type = find_atomic_core_type (cand);
5686 : 1775 : if (atomic_type && TYPE_ALIGN (atomic_type) == TYPE_ALIGN (cand))
5687 : : return true;
5688 : : }
5689 : : return false;
5690 : : }
5691 : :
5692 : : /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
5693 : :
5694 : : bool
5695 : 3646534802 : check_qualified_type (const_tree cand, const_tree base, int type_quals)
5696 : : {
5697 : 3646534802 : return (TYPE_QUALS (cand) == type_quals
5698 : 2464566637 : && check_base_type (cand, base)
5699 : 5831426727 : && check_lang_type (cand, base));
5700 : : }
5701 : :
5702 : : /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5703 : :
5704 : : static bool
5705 : 2630305 : check_aligned_type (const_tree cand, const_tree base, unsigned int align)
5706 : : {
5707 : 2630305 : return (TYPE_QUALS (cand) == TYPE_QUALS (base)
5708 : 2219532 : && TYPE_NAME (cand) == TYPE_NAME (base)
5709 : : /* Apparently this is needed for Objective-C. */
5710 : 1648044 : && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
5711 : : /* Check alignment. */
5712 : 1648044 : && TYPE_ALIGN (cand) == align
5713 : : /* Check this is a user-aligned type as build_aligned_type
5714 : : would create. */
5715 : 777374 : && TYPE_USER_ALIGN (cand)
5716 : 774872 : && attribute_list_equal (TYPE_ATTRIBUTES (cand),
5717 : 774872 : TYPE_ATTRIBUTES (base))
5718 : 3405177 : && check_lang_type (cand, base));
5719 : : }
5720 : :
5721 : : /* Return a version of the TYPE, qualified as indicated by the
5722 : : TYPE_QUALS, if one exists. If no qualified version exists yet,
5723 : : return NULL_TREE. */
5724 : :
5725 : : tree
5726 : 3467387091 : get_qualified_type (tree type, int type_quals)
5727 : : {
5728 : 3467387091 : if (TYPE_QUALS (type) == type_quals)
5729 : : return type;
5730 : :
5731 : 2270458317 : tree mv = TYPE_MAIN_VARIANT (type);
5732 : 2270458317 : if (check_qualified_type (mv, type, type_quals))
5733 : : return mv;
5734 : :
5735 : : /* Search the chain of variants to see if there is already one there just
5736 : : like the one we need to have. If so, use that existing one. We must
5737 : : preserve the TYPE_NAME, since there is code that depends on this. */
5738 : 1461655754 : for (tree *tp = &TYPE_NEXT_VARIANT (mv); *tp; tp = &TYPE_NEXT_VARIANT (*tp))
5739 : 1376015331 : if (check_qualified_type (*tp, type, type_quals))
5740 : : {
5741 : : /* Put the found variant at the head of the variant list so
5742 : : frequently searched variants get found faster. The C++ FE
5743 : : benefits greatly from this. */
5744 : 928355958 : tree t = *tp;
5745 : 928355958 : *tp = TYPE_NEXT_VARIANT (t);
5746 : 928355958 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
5747 : 928355958 : TYPE_NEXT_VARIANT (mv) = t;
5748 : 928355958 : return t;
5749 : : }
5750 : :
5751 : : return NULL_TREE;
5752 : : }
5753 : :
5754 : : /* Like get_qualified_type, but creates the type if it does not
5755 : : exist. This function never returns NULL_TREE. */
5756 : :
5757 : : tree
5758 : 3099721560 : build_qualified_type (tree type, int type_quals MEM_STAT_DECL)
5759 : : {
5760 : 3099721560 : tree t;
5761 : :
5762 : : /* See if we already have the appropriate qualified variant. */
5763 : 3099721560 : t = get_qualified_type (type, type_quals);
5764 : :
5765 : : /* If not, build it. */
5766 : 3099721560 : if (!t)
5767 : : {
5768 : 84112337 : t = build_variant_type_copy (type PASS_MEM_STAT);
5769 : 84112337 : set_type_quals (t, type_quals);
5770 : :
5771 : 84112337 : if (((type_quals & TYPE_QUAL_ATOMIC) == TYPE_QUAL_ATOMIC))
5772 : : {
5773 : : /* See if this object can map to a basic atomic type. */
5774 : 6504 : tree atomic_type = find_atomic_core_type (type);
5775 : 6504 : if (atomic_type)
5776 : : {
5777 : : /* Ensure the alignment of this type is compatible with
5778 : : the required alignment of the atomic type. */
5779 : 6380 : if (TYPE_ALIGN (atomic_type) > TYPE_ALIGN (t))
5780 : 94 : SET_TYPE_ALIGN (t, TYPE_ALIGN (atomic_type));
5781 : : }
5782 : : }
5783 : :
5784 : 84112337 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5785 : : /* Propagate structural equality. */
5786 : 4055410 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5787 : 80056927 : else if (TYPE_CANONICAL (type) != type)
5788 : : /* Build the underlying canonical type, since it is different
5789 : : from TYPE. */
5790 : : {
5791 : 25951216 : tree c = build_qualified_type (TYPE_CANONICAL (type), type_quals);
5792 : 25951216 : TYPE_CANONICAL (t) = TYPE_CANONICAL (c);
5793 : : }
5794 : : else
5795 : : /* T is its own canonical type. */
5796 : 54105711 : TYPE_CANONICAL (t) = t;
5797 : :
5798 : : }
5799 : :
5800 : 3099721560 : return t;
5801 : : }
5802 : :
5803 : : /* Create a variant of type T with alignment ALIGN which
5804 : : is measured in bits. */
5805 : :
5806 : : tree
5807 : 1034328 : build_aligned_type (tree type, unsigned int align)
5808 : : {
5809 : 1034328 : tree t;
5810 : :
5811 : 1034328 : if (TYPE_PACKED (type)
5812 : 1034328 : || TYPE_ALIGN (type) == align)
5813 : : return type;
5814 : :
5815 : 2718959 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
5816 : 2630305 : if (check_aligned_type (t, type, align))
5817 : : return t;
5818 : :
5819 : 88654 : t = build_variant_type_copy (type);
5820 : 88654 : SET_TYPE_ALIGN (t, align);
5821 : 88654 : TYPE_USER_ALIGN (t) = 1;
5822 : :
5823 : 88654 : return t;
5824 : : }
5825 : :
5826 : : /* Create a new distinct copy of TYPE. The new type is made its own
5827 : : MAIN_VARIANT. If TYPE requires structural equality checks, the
5828 : : resulting type requires structural equality checks; otherwise, its
5829 : : TYPE_CANONICAL points to itself. */
5830 : :
5831 : : tree
5832 : 634261142 : build_distinct_type_copy (tree type MEM_STAT_DECL)
5833 : : {
5834 : 634261142 : tree t = copy_node (type PASS_MEM_STAT);
5835 : :
5836 : 634261142 : TYPE_POINTER_TO (t) = 0;
5837 : 634261142 : TYPE_REFERENCE_TO (t) = 0;
5838 : :
5839 : : /* Set the canonical type either to a new equivalence class, or
5840 : : propagate the need for structural equality checks. */
5841 : 634261142 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5842 : 54067127 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5843 : : else
5844 : 580194015 : TYPE_CANONICAL (t) = t;
5845 : :
5846 : : /* Make it its own variant. */
5847 : 634261142 : TYPE_MAIN_VARIANT (t) = t;
5848 : 634261142 : TYPE_NEXT_VARIANT (t) = 0;
5849 : :
5850 : : /* Note that it is now possible for TYPE_MIN_VALUE to be a value
5851 : : whose TREE_TYPE is not t. This can also happen in the Ada
5852 : : frontend when using subtypes. */
5853 : :
5854 : 634261142 : return t;
5855 : : }
5856 : :
5857 : : /* Create a new variant of TYPE, equivalent but distinct. This is so
5858 : : the caller can modify it. TYPE_CANONICAL for the return type will
5859 : : be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
5860 : : are considered equal by the language itself (or that both types
5861 : : require structural equality checks). */
5862 : :
5863 : : tree
5864 : 385923429 : build_variant_type_copy (tree type MEM_STAT_DECL)
5865 : : {
5866 : 385923429 : tree t, m = TYPE_MAIN_VARIANT (type);
5867 : :
5868 : 385923429 : t = build_distinct_type_copy (type PASS_MEM_STAT);
5869 : :
5870 : : /* Since we're building a variant, assume that it is a non-semantic
5871 : : variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
5872 : 385923429 : TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
5873 : : /* Type variants have no alias set defined. */
5874 : 385923429 : TYPE_ALIAS_SET (t) = -1;
5875 : :
5876 : : /* Add the new type to the chain of variants of TYPE. */
5877 : 385923429 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
5878 : 385923429 : TYPE_NEXT_VARIANT (m) = t;
5879 : 385923429 : TYPE_MAIN_VARIANT (t) = m;
5880 : :
5881 : 385923429 : return t;
5882 : : }
5883 : :
5884 : : /* Return true if the from tree in both tree maps are equal. */
5885 : :
5886 : : int
5887 : 1568470658 : tree_map_base_eq (const void *va, const void *vb)
5888 : : {
5889 : 1568470658 : const struct tree_map_base *const a = (const struct tree_map_base *) va,
5890 : 1568470658 : *const b = (const struct tree_map_base *) vb;
5891 : 1568470658 : return (a->from == b->from);
5892 : : }
5893 : :
5894 : : /* Hash a from tree in a tree_base_map. */
5895 : :
5896 : : unsigned int
5897 : 0 : tree_map_base_hash (const void *item)
5898 : : {
5899 : 0 : return htab_hash_pointer (((const struct tree_map_base *)item)->from);
5900 : : }
5901 : :
5902 : : /* Return true if this tree map structure is marked for garbage collection
5903 : : purposes. We simply return true if the from tree is marked, so that this
5904 : : structure goes away when the from tree goes away. */
5905 : :
5906 : : bool
5907 : 0 : tree_map_base_marked_p (const void *p)
5908 : : {
5909 : 0 : return ggc_marked_p (((const struct tree_map_base *) p)->from);
5910 : : }
5911 : :
5912 : : /* Hash a from tree in a tree_map. */
5913 : :
5914 : : unsigned int
5915 : 248 : tree_map_hash (const void *item)
5916 : : {
5917 : 248 : return (((const struct tree_map *) item)->hash);
5918 : : }
5919 : :
5920 : : /* Hash a from tree in a tree_decl_map. */
5921 : :
5922 : : unsigned int
5923 : 1053972928 : tree_decl_map_hash (const void *item)
5924 : : {
5925 : 1053972928 : return DECL_UID (((const struct tree_decl_map *) item)->base.from);
5926 : : }
5927 : :
5928 : : /* Return the initialization priority for DECL. */
5929 : :
5930 : : priority_type
5931 : 22945 : decl_init_priority_lookup (tree decl)
5932 : : {
5933 : 22945 : symtab_node *snode = symtab_node::get (decl);
5934 : :
5935 : 22945 : if (!snode)
5936 : : return DEFAULT_INIT_PRIORITY;
5937 : 22945 : return
5938 : 22945 : snode->get_init_priority ();
5939 : : }
5940 : :
5941 : : /* Return the finalization priority for DECL. */
5942 : :
5943 : : priority_type
5944 : 1748 : decl_fini_priority_lookup (tree decl)
5945 : : {
5946 : 1748 : cgraph_node *node = cgraph_node::get (decl);
5947 : :
5948 : 1748 : if (!node)
5949 : : return DEFAULT_INIT_PRIORITY;
5950 : 1748 : return
5951 : 1748 : node->get_fini_priority ();
5952 : : }
5953 : :
5954 : : /* Set the initialization priority for DECL to PRIORITY. */
5955 : :
5956 : : void
5957 : 24454 : decl_init_priority_insert (tree decl, priority_type priority)
5958 : : {
5959 : 24454 : struct symtab_node *snode;
5960 : :
5961 : 24454 : if (priority == DEFAULT_INIT_PRIORITY)
5962 : : {
5963 : 20929 : snode = symtab_node::get (decl);
5964 : 20929 : if (!snode)
5965 : : return;
5966 : : }
5967 : 3525 : else if (VAR_P (decl))
5968 : 41 : snode = varpool_node::get_create (decl);
5969 : : else
5970 : 3484 : snode = cgraph_node::get_create (decl);
5971 : 23790 : snode->set_init_priority (priority);
5972 : : }
5973 : :
5974 : : /* Set the finalization priority for DECL to PRIORITY. */
5975 : :
5976 : : void
5977 : 1607 : decl_fini_priority_insert (tree decl, priority_type priority)
5978 : : {
5979 : 1607 : struct cgraph_node *node;
5980 : :
5981 : 1607 : if (priority == DEFAULT_INIT_PRIORITY)
5982 : : {
5983 : 98 : node = cgraph_node::get (decl);
5984 : 98 : if (!node)
5985 : : return;
5986 : : }
5987 : : else
5988 : 1509 : node = cgraph_node::get_create (decl);
5989 : 1518 : node->set_fini_priority (priority);
5990 : : }
5991 : :
5992 : : /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
5993 : :
5994 : : static void
5995 : 0 : print_debug_expr_statistics (void)
5996 : : {
5997 : 0 : fprintf (stderr, "DECL_DEBUG_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
5998 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
5999 : 0 : (fmt_size_t) debug_expr_for_decl->size (),
6000 : 0 : (fmt_size_t) debug_expr_for_decl->elements (),
6001 : : debug_expr_for_decl->collisions ());
6002 : 0 : }
6003 : :
6004 : : /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6005 : :
6006 : : static void
6007 : 0 : print_value_expr_statistics (void)
6008 : : {
6009 : 0 : fprintf (stderr, "DECL_VALUE_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6010 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6011 : 0 : (fmt_size_t) value_expr_for_decl->size (),
6012 : 0 : (fmt_size_t) value_expr_for_decl->elements (),
6013 : : value_expr_for_decl->collisions ());
6014 : 0 : }
6015 : :
6016 : : /* Lookup a debug expression for FROM, and return it if we find one. */
6017 : :
6018 : : tree
6019 : 413760717 : decl_debug_expr_lookup (tree from)
6020 : : {
6021 : 413760717 : struct tree_decl_map *h, in;
6022 : 413760717 : in.base.from = from;
6023 : :
6024 : 413760717 : h = debug_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6025 : 413760717 : if (h)
6026 : 413760717 : return h->to;
6027 : : return NULL_TREE;
6028 : : }
6029 : :
6030 : : /* Insert a mapping FROM->TO in the debug expression hashtable. */
6031 : :
6032 : : void
6033 : 1280175 : decl_debug_expr_insert (tree from, tree to)
6034 : : {
6035 : 1280175 : struct tree_decl_map *h;
6036 : :
6037 : 1280175 : h = ggc_alloc<tree_decl_map> ();
6038 : 1280175 : h->base.from = from;
6039 : 1280175 : h->to = to;
6040 : 1280175 : *debug_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6041 : 1280175 : }
6042 : :
6043 : : /* Lookup a value expression for FROM, and return it if we find one. */
6044 : :
6045 : : tree
6046 : 9087071 : decl_value_expr_lookup (tree from)
6047 : : {
6048 : 9087071 : struct tree_decl_map *h, in;
6049 : 9087071 : in.base.from = from;
6050 : :
6051 : 9087071 : h = value_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6052 : 9087071 : if (h)
6053 : 9087071 : return h->to;
6054 : : return NULL_TREE;
6055 : : }
6056 : :
6057 : : /* Insert a mapping FROM->TO in the value expression hashtable. */
6058 : :
6059 : : void
6060 : 3497450 : decl_value_expr_insert (tree from, tree to)
6061 : : {
6062 : 3497450 : struct tree_decl_map *h;
6063 : :
6064 : : /* Uses of FROM shouldn't look like they happen at the location of TO. */
6065 : 3497450 : to = protected_set_expr_location_unshare (to, UNKNOWN_LOCATION);
6066 : :
6067 : 3497450 : h = ggc_alloc<tree_decl_map> ();
6068 : 3497450 : h->base.from = from;
6069 : 3497450 : h->to = to;
6070 : 3497450 : *value_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6071 : 3497450 : }
6072 : :
6073 : : /* Lookup a vector of debug arguments for FROM, and return it if we
6074 : : find one. */
6075 : :
6076 : : vec<tree, va_gc> **
6077 : 682726 : decl_debug_args_lookup (tree from)
6078 : : {
6079 : 682726 : struct tree_vec_map *h, in;
6080 : :
6081 : 682726 : if (!DECL_HAS_DEBUG_ARGS_P (from))
6082 : : return NULL;
6083 : 554125 : gcc_checking_assert (debug_args_for_decl != NULL);
6084 : 554125 : in.base.from = from;
6085 : 554125 : h = debug_args_for_decl->find_with_hash (&in, DECL_UID (from));
6086 : 554125 : if (h)
6087 : 550845 : return &h->to;
6088 : : return NULL;
6089 : : }
6090 : :
6091 : : /* Insert a mapping FROM->empty vector of debug arguments in the value
6092 : : expression hashtable. */
6093 : :
6094 : : vec<tree, va_gc> **
6095 : 194594 : decl_debug_args_insert (tree from)
6096 : : {
6097 : 194594 : struct tree_vec_map *h;
6098 : 194594 : tree_vec_map **loc;
6099 : :
6100 : 194594 : if (DECL_HAS_DEBUG_ARGS_P (from))
6101 : 124259 : return decl_debug_args_lookup (from);
6102 : 70335 : if (debug_args_for_decl == NULL)
6103 : 7910 : debug_args_for_decl = hash_table<tree_vec_map_cache_hasher>::create_ggc (64);
6104 : 70335 : h = ggc_alloc<tree_vec_map> ();
6105 : 70335 : h->base.from = from;
6106 : 70335 : h->to = NULL;
6107 : 70335 : loc = debug_args_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT);
6108 : 70335 : *loc = h;
6109 : 70335 : DECL_HAS_DEBUG_ARGS_P (from) = 1;
6110 : 70335 : return &h->to;
6111 : : }
6112 : :
6113 : : /* Hashing of types so that we don't make duplicates.
6114 : : The entry point is `type_hash_canon'. */
6115 : :
6116 : : /* Generate the default hash code for TYPE. This is designed for
6117 : : speed, rather than maximum entropy. */
6118 : :
6119 : : hashval_t
6120 : 1232939082 : type_hash_canon_hash (tree type)
6121 : : {
6122 : 1232939082 : inchash::hash hstate;
6123 : :
6124 : 1232939082 : hstate.add_int (TREE_CODE (type));
6125 : :
6126 : 1232939082 : hstate.add_flag (TYPE_STRUCTURAL_EQUALITY_P (type));
6127 : :
6128 : 1232939082 : if (TREE_TYPE (type))
6129 : 1232917257 : hstate.add_object (TYPE_HASH (TREE_TYPE (type)));
6130 : :
6131 : 1483252105 : for (tree t = TYPE_ATTRIBUTES (type); t; t = TREE_CHAIN (t))
6132 : : /* Just the identifier is adequate to distinguish. */
6133 : 250313023 : hstate.add_object (IDENTIFIER_HASH_VALUE (get_attribute_name (t)));
6134 : :
6135 : 1232939082 : switch (TREE_CODE (type))
6136 : : {
6137 : 269213495 : case METHOD_TYPE:
6138 : 269213495 : hstate.add_object (TYPE_HASH (TYPE_METHOD_BASETYPE (type)));
6139 : : /* FALLTHROUGH. */
6140 : 1068691689 : case FUNCTION_TYPE:
6141 : 4278954398 : for (tree t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
6142 : 3210262709 : if (TREE_VALUE (t) != error_mark_node)
6143 : 3210259432 : hstate.add_object (TYPE_HASH (TREE_VALUE (t)));
6144 : : break;
6145 : :
6146 : 958357 : case OFFSET_TYPE:
6147 : 958357 : hstate.add_object (TYPE_HASH (TYPE_OFFSET_BASETYPE (type)));
6148 : 958357 : break;
6149 : :
6150 : 56593808 : case ARRAY_TYPE:
6151 : 56593808 : {
6152 : 56593808 : if (TYPE_DOMAIN (type))
6153 : 55432740 : hstate.add_object (TYPE_HASH (TYPE_DOMAIN (type)));
6154 : 56593808 : if (!AGGREGATE_TYPE_P (TREE_TYPE (type)))
6155 : : {
6156 : 55634052 : unsigned typeless = TYPE_TYPELESS_STORAGE (type);
6157 : 55634052 : hstate.add_object (typeless);
6158 : : }
6159 : : }
6160 : : break;
6161 : :
6162 : 34710807 : case INTEGER_TYPE:
6163 : 34710807 : {
6164 : 34710807 : tree t = TYPE_MAX_VALUE (type);
6165 : 34710807 : if (!t)
6166 : 535975 : t = TYPE_MIN_VALUE (type);
6167 : 69421615 : for (int i = 0; i < TREE_INT_CST_NUNITS (t); i++)
6168 : 34710808 : hstate.add_object (TREE_INT_CST_ELT (t, i));
6169 : : break;
6170 : : }
6171 : :
6172 : 1 : case BITINT_TYPE:
6173 : 1 : {
6174 : 1 : unsigned prec = TYPE_PRECISION (type);
6175 : 1 : unsigned uns = TYPE_UNSIGNED (type);
6176 : 1 : hstate.add_object (prec);
6177 : 1 : hstate.add_int (uns);
6178 : 1 : break;
6179 : : }
6180 : :
6181 : 11710 : case REAL_TYPE:
6182 : 11710 : case FIXED_POINT_TYPE:
6183 : 11710 : {
6184 : 11710 : unsigned prec = TYPE_PRECISION (type);
6185 : 11710 : hstate.add_object (prec);
6186 : 11710 : break;
6187 : : }
6188 : :
6189 : 66645859 : case VECTOR_TYPE:
6190 : 66645859 : hstate.add_poly_int (TYPE_VECTOR_SUBPARTS (type));
6191 : 66645859 : break;
6192 : :
6193 : : case REFERENCE_TYPE:
6194 : 1232939082 : hstate.add_flag (TYPE_REF_IS_RVALUE (type));
6195 : : break;
6196 : :
6197 : : default:
6198 : : break;
6199 : : }
6200 : :
6201 : 1232939082 : return hstate.end ();
6202 : : }
6203 : :
6204 : : /* These are the Hashtable callback functions. */
6205 : :
6206 : : /* Returns true iff the types are equivalent. */
6207 : :
6208 : : bool
6209 : 7933759285 : type_cache_hasher::equal (type_hash *a, type_hash *b)
6210 : : {
6211 : : /* First test the things that are the same for all types. */
6212 : 7933759285 : if (a->hash != b->hash
6213 : 604210779 : || TREE_CODE (a->type) != TREE_CODE (b->type)
6214 : 604202843 : || TREE_TYPE (a->type) != TREE_TYPE (b->type)
6215 : 604202513 : || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
6216 : 604202513 : TYPE_ATTRIBUTES (b->type))
6217 : 8531011397 : || (TREE_CODE (a->type) != COMPLEX_TYPE
6218 : 595266521 : && TYPE_NAME (a->type) != TYPE_NAME (b->type)))
6219 : 7337272202 : return false;
6220 : :
6221 : : /* Be careful about comparing arrays before and after the element type
6222 : : has been completed; don't compare TYPE_ALIGN unless both types are
6223 : : complete. */
6224 : 1191558124 : if (COMPLETE_TYPE_P (a->type) && COMPLETE_TYPE_P (b->type)
6225 : 1191558124 : && (TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
6226 : 595070484 : || TYPE_MODE (a->type) != TYPE_MODE (b->type)))
6227 : 661 : return false;
6228 : :
6229 : 596486422 : if (TYPE_STRUCTURAL_EQUALITY_P (a->type)
6230 : 596486422 : != TYPE_STRUCTURAL_EQUALITY_P (b->type))
6231 : : return false;
6232 : :
6233 : 596483232 : switch (TREE_CODE (a->type))
6234 : : {
6235 : : case VOID_TYPE:
6236 : : case OPAQUE_TYPE:
6237 : : case COMPLEX_TYPE:
6238 : : case POINTER_TYPE:
6239 : : case NULLPTR_TYPE:
6240 : : return true;
6241 : :
6242 : 60474560 : case VECTOR_TYPE:
6243 : 60474560 : return known_eq (TYPE_VECTOR_SUBPARTS (a->type),
6244 : : TYPE_VECTOR_SUBPARTS (b->type));
6245 : :
6246 : 0 : case ENUMERAL_TYPE:
6247 : 0 : if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
6248 : 0 : && !(TYPE_VALUES (a->type)
6249 : 0 : && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
6250 : 0 : && TYPE_VALUES (b->type)
6251 : 0 : && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
6252 : 0 : && type_list_equal (TYPE_VALUES (a->type),
6253 : 0 : TYPE_VALUES (b->type))))
6254 : 0 : return false;
6255 : :
6256 : : /* fall through */
6257 : :
6258 : 33547664 : case INTEGER_TYPE:
6259 : 33547664 : case REAL_TYPE:
6260 : 33547664 : case BOOLEAN_TYPE:
6261 : 33547664 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6262 : : return false;
6263 : 33543269 : return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
6264 : 2115985 : || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
6265 : 2115985 : TYPE_MAX_VALUE (b->type)))
6266 : 35236837 : && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
6267 : 1816139 : || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
6268 : 1816139 : TYPE_MIN_VALUE (b->type))));
6269 : :
6270 : 1518632 : case BITINT_TYPE:
6271 : 1518632 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6272 : : return false;
6273 : 1472812 : return TYPE_UNSIGNED (a->type) == TYPE_UNSIGNED (b->type);
6274 : :
6275 : 0 : case FIXED_POINT_TYPE:
6276 : 0 : return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
6277 : :
6278 : 769585 : case OFFSET_TYPE:
6279 : 769585 : return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
6280 : :
6281 : 78139357 : case METHOD_TYPE:
6282 : 78139357 : if (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
6283 : 78139357 : && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6284 : 78095964 : || (TYPE_ARG_TYPES (a->type)
6285 : 78095964 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6286 : 78095964 : && TYPE_ARG_TYPES (b->type)
6287 : 78095964 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6288 : 78095964 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6289 : 78095964 : TYPE_ARG_TYPES (b->type)))))
6290 : : break;
6291 : : return false;
6292 : 46966217 : case ARRAY_TYPE:
6293 : : /* Don't compare TYPE_TYPELESS_STORAGE flag on aggregates,
6294 : : where the flag should be inherited from the element type
6295 : : and can change after ARRAY_TYPEs are created; on non-aggregates
6296 : : compare it and hash it, scalars will never have that flag set
6297 : : and we need to differentiate between arrays created by different
6298 : : front-ends or middle-end created arrays. */
6299 : 46966217 : return (TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type)
6300 : 46966217 : && (AGGREGATE_TYPE_P (TREE_TYPE (a->type))
6301 : 46608840 : || (TYPE_TYPELESS_STORAGE (a->type)
6302 : 46608840 : == TYPE_TYPELESS_STORAGE (b->type))));
6303 : :
6304 : 0 : case RECORD_TYPE:
6305 : 0 : case UNION_TYPE:
6306 : 0 : case QUAL_UNION_TYPE:
6307 : 0 : return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
6308 : 0 : || (TYPE_FIELDS (a->type)
6309 : 0 : && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
6310 : 0 : && TYPE_FIELDS (b->type)
6311 : 0 : && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
6312 : 0 : && type_list_equal (TYPE_FIELDS (a->type),
6313 : 0 : TYPE_FIELDS (b->type))));
6314 : :
6315 : 373081138 : case FUNCTION_TYPE:
6316 : 373081138 : if ((TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6317 : 228155717 : && (TYPE_NO_NAMED_ARGS_STDARG_P (a->type)
6318 : 228155717 : == TYPE_NO_NAMED_ARGS_STDARG_P (b->type)))
6319 : 373386503 : || (TYPE_ARG_TYPES (a->type)
6320 : 144925421 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6321 : 144925421 : && TYPE_ARG_TYPES (b->type)
6322 : 144925421 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6323 : 144925421 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6324 : 144925421 : TYPE_ARG_TYPES (b->type))))
6325 : : break;
6326 : : return false;
6327 : :
6328 : 9 : case REFERENCE_TYPE:
6329 : 9 : return TYPE_REF_IS_RVALUE (a->type) == TYPE_REF_IS_RVALUE (b->type);
6330 : :
6331 : : default:
6332 : : return false;
6333 : : }
6334 : :
6335 : 427699104 : if (lang_hooks.types.type_hash_eq != NULL)
6336 : 263645999 : return lang_hooks.types.type_hash_eq (a->type, b->type);
6337 : :
6338 : : return true;
6339 : : }
6340 : :
6341 : : /* Given TYPE, and HASHCODE its hash code, return the canonical
6342 : : object for an identical type if one already exists.
6343 : : Otherwise, return TYPE, and record it as the canonical object.
6344 : :
6345 : : To use this function, first create a type of the sort you want.
6346 : : Then compute its hash code from the fields of the type that
6347 : : make it different from other similar types.
6348 : : Then call this function and use the value. */
6349 : :
6350 : : tree
6351 : 1236758253 : type_hash_canon (unsigned int hashcode, tree type)
6352 : : {
6353 : 1236758253 : type_hash in;
6354 : 1236758253 : type_hash **loc;
6355 : :
6356 : : /* The hash table only contains main variants, so ensure that's what we're
6357 : : being passed. */
6358 : 1236758253 : gcc_assert (TYPE_MAIN_VARIANT (type) == type);
6359 : :
6360 : : /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6361 : : must call that routine before comparing TYPE_ALIGNs. */
6362 : 1236758253 : layout_type (type);
6363 : :
6364 : 1236758253 : in.hash = hashcode;
6365 : 1236758253 : in.type = type;
6366 : :
6367 : 1236758253 : loc = type_hash_table->find_slot_with_hash (&in, hashcode, INSERT);
6368 : 1236758253 : if (*loc)
6369 : : {
6370 : 572365618 : tree t1 = ((type_hash *) *loc)->type;
6371 : 572365618 : gcc_assert (TYPE_MAIN_VARIANT (t1) == t1
6372 : : && t1 != type);
6373 : 572365618 : if (TYPE_UID (type) + 1 == next_type_uid)
6374 : 567339710 : --next_type_uid;
6375 : : /* Free also min/max values and the cache for integer
6376 : : types. This can't be done in free_node, as LTO frees
6377 : : those on its own. */
6378 : 572365618 : if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == BITINT_TYPE)
6379 : : {
6380 : 34470070 : if (TYPE_MIN_VALUE (type)
6381 : 34470070 : && TREE_TYPE (TYPE_MIN_VALUE (type)) == type)
6382 : : {
6383 : : /* Zero is always in TYPE_CACHED_VALUES. */
6384 : 3164801 : if (! TYPE_UNSIGNED (type))
6385 : 2909293 : int_cst_hash_table->remove_elt (TYPE_MIN_VALUE (type));
6386 : 3164801 : ggc_free (TYPE_MIN_VALUE (type));
6387 : : }
6388 : 34470070 : if (TYPE_MAX_VALUE (type)
6389 : 34470070 : && TREE_TYPE (TYPE_MAX_VALUE (type)) == type)
6390 : : {
6391 : 3164801 : int_cst_hash_table->remove_elt (TYPE_MAX_VALUE (type));
6392 : 3164801 : ggc_free (TYPE_MAX_VALUE (type));
6393 : : }
6394 : 34470070 : if (TYPE_CACHED_VALUES_P (type))
6395 : 255508 : ggc_free (TYPE_CACHED_VALUES (type));
6396 : : }
6397 : 572365618 : free_node (type);
6398 : 572365618 : return t1;
6399 : : }
6400 : : else
6401 : : {
6402 : 664392635 : struct type_hash *h;
6403 : :
6404 : 664392635 : h = ggc_alloc<type_hash> ();
6405 : 664392635 : h->hash = hashcode;
6406 : 664392635 : h->type = type;
6407 : 664392635 : *loc = h;
6408 : :
6409 : 664392635 : return type;
6410 : : }
6411 : : }
6412 : :
6413 : : static void
6414 : 0 : print_type_hash_statistics (void)
6415 : : {
6416 : 0 : fprintf (stderr, "Type hash: size " HOST_SIZE_T_PRINT_DEC ", "
6417 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6418 : 0 : (fmt_size_t) type_hash_table->size (),
6419 : 0 : (fmt_size_t) type_hash_table->elements (),
6420 : : type_hash_table->collisions ());
6421 : 0 : }
6422 : :
6423 : : /* Given two lists of types
6424 : : (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6425 : : return 1 if the lists contain the same types in the same order.
6426 : : Also, the TREE_PURPOSEs must match. */
6427 : :
6428 : : bool
6429 : 223021901 : type_list_equal (const_tree l1, const_tree l2)
6430 : : {
6431 : 223021901 : const_tree t1, t2;
6432 : :
6433 : 848443918 : for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
6434 : 648637827 : if (TREE_VALUE (t1) != TREE_VALUE (t2)
6435 : 648637827 : || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
6436 : 23217080 : && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
6437 : 1305 : && (TREE_TYPE (TREE_PURPOSE (t1))
6438 : 1305 : == TREE_TYPE (TREE_PURPOSE (t2))))))
6439 : 23215810 : return false;
6440 : :
6441 : 199806091 : return t1 == t2;
6442 : : }
6443 : :
6444 : : /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6445 : : given by TYPE. If the argument list accepts variable arguments,
6446 : : then this function counts only the ordinary arguments. */
6447 : :
6448 : : int
6449 : 74414801 : type_num_arguments (const_tree fntype)
6450 : : {
6451 : 74414801 : int i = 0;
6452 : :
6453 : 286468399 : for (tree t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
6454 : : /* If the function does not take a variable number of arguments,
6455 : : the last element in the list will have type `void'. */
6456 : 268125058 : if (VOID_TYPE_P (TREE_VALUE (t)))
6457 : : break;
6458 : : else
6459 : 212053598 : ++i;
6460 : :
6461 : 74414801 : return i;
6462 : : }
6463 : :
6464 : : /* Return the type of the function TYPE's argument ARGNO if known.
6465 : : For vararg function's where ARGNO refers to one of the variadic
6466 : : arguments return null. Otherwise, return a void_type_node for
6467 : : out-of-bounds ARGNO. */
6468 : :
6469 : : tree
6470 : 73974138 : type_argument_type (const_tree fntype, unsigned argno)
6471 : : {
6472 : : /* Treat zero the same as an out-of-bounds argument number. */
6473 : 73974138 : if (!argno)
6474 : 0 : return void_type_node;
6475 : :
6476 : 73974138 : function_args_iterator iter;
6477 : :
6478 : 73974138 : tree argtype;
6479 : 73974138 : unsigned i = 1;
6480 : 158506458 : FOREACH_FUNCTION_ARGS (fntype, argtype, iter)
6481 : : {
6482 : : /* A vararg function's argument list ends in a null. Otherwise,
6483 : : an ordinary function's argument list ends with void. Return
6484 : : null if ARGNO refers to a vararg argument, void_type_node if
6485 : : it's out of bounds, and the formal argument type otherwise. */
6486 : 153004957 : if (!argtype)
6487 : : break;
6488 : :
6489 : 153004957 : if (i == argno || VOID_TYPE_P (argtype))
6490 : : return argtype;
6491 : :
6492 : 84532320 : ++i;
6493 : : }
6494 : :
6495 : : return NULL_TREE;
6496 : : }
6497 : :
6498 : : /* True if integer constants T1 and T2
6499 : : represent the same constant value. */
6500 : :
6501 : : bool
6502 : 1037096519 : tree_int_cst_equal (const_tree t1, const_tree t2)
6503 : : {
6504 : 1037096519 : if (t1 == t2)
6505 : : return true;
6506 : :
6507 : 465547225 : if (t1 == 0 || t2 == 0)
6508 : : return false;
6509 : :
6510 : 465096932 : STRIP_ANY_LOCATION_WRAPPER (t1);
6511 : 465096932 : STRIP_ANY_LOCATION_WRAPPER (t2);
6512 : :
6513 : 465096932 : if (TREE_CODE (t1) == INTEGER_CST
6514 : 461803862 : && TREE_CODE (t2) == INTEGER_CST
6515 : 926900794 : && wi::to_widest (t1) == wi::to_widest (t2))
6516 : 19260728 : return true;
6517 : :
6518 : : return false;
6519 : : }
6520 : :
6521 : : /* Return true if T is an INTEGER_CST whose numerical value (extended
6522 : : according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. */
6523 : :
6524 : : bool
6525 : 1851165270 : tree_fits_shwi_p (const_tree t)
6526 : : {
6527 : 1851165270 : return (t != NULL_TREE
6528 : 1851165174 : && TREE_CODE (t) == INTEGER_CST
6529 : 3699123470 : && wi::fits_shwi_p (wi::to_widest (t)));
6530 : : }
6531 : :
6532 : : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6533 : : value (extended according to TYPE_UNSIGNED) fits in a poly_int64. */
6534 : :
6535 : : bool
6536 : 818917448 : tree_fits_poly_int64_p (const_tree t)
6537 : : {
6538 : 818917448 : if (t == NULL_TREE)
6539 : : return false;
6540 : 785557096 : if (POLY_INT_CST_P (t))
6541 : : {
6542 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6543 : : if (!wi::fits_shwi_p (wi::to_wide (POLY_INT_CST_COEFF (t, i))))
6544 : : return false;
6545 : : return true;
6546 : : }
6547 : 785557096 : return (TREE_CODE (t) == INTEGER_CST
6548 : 1571207500 : && wi::fits_shwi_p (wi::to_widest (t)));
6549 : : }
6550 : :
6551 : : /* Return true if T is an INTEGER_CST whose numerical value (extended
6552 : : according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
6553 : :
6554 : : bool
6555 : 3090353665 : tree_fits_uhwi_p (const_tree t)
6556 : : {
6557 : 3090353665 : return (t != NULL_TREE
6558 : 3089930025 : && TREE_CODE (t) == INTEGER_CST
6559 : 6175983031 : && wi::fits_uhwi_p (wi::to_widest (t)));
6560 : : }
6561 : :
6562 : : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6563 : : value (extended according to TYPE_UNSIGNED) fits in a poly_uint64. */
6564 : :
6565 : : bool
6566 : 820692756 : tree_fits_poly_uint64_p (const_tree t)
6567 : : {
6568 : 820692756 : if (t == NULL_TREE)
6569 : : return false;
6570 : 820344716 : if (POLY_INT_CST_P (t))
6571 : : {
6572 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6573 : : if (!wi::fits_uhwi_p (wi::to_widest (POLY_INT_CST_COEFF (t, i))))
6574 : : return false;
6575 : : return true;
6576 : : }
6577 : 820344716 : return (TREE_CODE (t) == INTEGER_CST
6578 : 1640690766 : && wi::fits_uhwi_p (wi::to_widest (t)));
6579 : : }
6580 : :
6581 : : /* T is an INTEGER_CST whose numerical value (extended according to
6582 : : TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that
6583 : : HOST_WIDE_INT. */
6584 : :
6585 : : HOST_WIDE_INT
6586 : 1188183296 : tree_to_shwi (const_tree t)
6587 : : {
6588 : 1188183296 : gcc_assert (tree_fits_shwi_p (t));
6589 : 1188183296 : return TREE_INT_CST_LOW (t);
6590 : : }
6591 : :
6592 : : /* T is an INTEGER_CST whose numerical value (extended according to
6593 : : TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. Return that
6594 : : HOST_WIDE_INT. */
6595 : :
6596 : : unsigned HOST_WIDE_INT
6597 : 668057222 : tree_to_uhwi (const_tree t)
6598 : : {
6599 : 668057222 : gcc_assert (tree_fits_uhwi_p (t));
6600 : 668057222 : return TREE_INT_CST_LOW (t);
6601 : : }
6602 : :
6603 : : /* Return the most significant (sign) bit of T. */
6604 : :
6605 : : int
6606 : 38675317 : tree_int_cst_sign_bit (const_tree t)
6607 : : {
6608 : 38675317 : unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1;
6609 : :
6610 : 38675317 : return wi::extract_uhwi (wi::to_wide (t), bitno, 1);
6611 : : }
6612 : :
6613 : : /* Return an indication of the sign of the integer constant T.
6614 : : The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6615 : : Note that -1 will never be returned if T's type is unsigned. */
6616 : :
6617 : : int
6618 : 1478497987 : tree_int_cst_sgn (const_tree t)
6619 : : {
6620 : 1478497987 : if (wi::to_wide (t) == 0)
6621 : : return 0;
6622 : 1388741734 : else if (TYPE_UNSIGNED (TREE_TYPE (t)))
6623 : : return 1;
6624 : 57078244 : else if (wi::neg_p (wi::to_wide (t)))
6625 : : return -1;
6626 : : else
6627 : : return 1;
6628 : : }
6629 : :
6630 : : /* Return the minimum number of bits needed to represent VALUE in a
6631 : : signed or unsigned type, UNSIGNEDP says which. */
6632 : :
6633 : : unsigned int
6634 : 3196291 : tree_int_cst_min_precision (tree value, signop sgn)
6635 : : {
6636 : : /* If the value is negative, compute its negative minus 1. The latter
6637 : : adjustment is because the absolute value of the largest negative value
6638 : : is one larger than the largest positive value. This is equivalent to
6639 : : a bit-wise negation, so use that operation instead. */
6640 : :
6641 : 3196291 : if (tree_int_cst_sgn (value) < 0)
6642 : 94275 : value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value);
6643 : :
6644 : : /* Return the number of bits needed, taking into account the fact
6645 : : that we need one more bit for a signed than unsigned type.
6646 : : If value is 0 or -1, the minimum precision is 1 no matter
6647 : : whether unsignedp is true or false. */
6648 : :
6649 : 3196291 : if (integer_zerop (value))
6650 : : return 1;
6651 : : else
6652 : 4588407 : return tree_floor_log2 (value) + 1 + (sgn == SIGNED ? 1 : 0) ;
6653 : : }
6654 : :
6655 : : /* Return truthvalue of whether T1 is the same tree structure as T2.
6656 : : Return 1 if they are the same.
6657 : : Return 0 if they are understandably different.
6658 : : Return -1 if either contains tree structure not understood by
6659 : : this function. */
6660 : :
6661 : : int
6662 : 165818142 : simple_cst_equal (const_tree t1, const_tree t2)
6663 : : {
6664 : 169650701 : enum tree_code code1, code2;
6665 : 169650701 : int cmp;
6666 : 169650701 : int i;
6667 : :
6668 : 169650701 : if (t1 == t2)
6669 : : return 1;
6670 : 108624491 : if (t1 == 0 || t2 == 0)
6671 : : return 0;
6672 : :
6673 : : /* For location wrappers to be the same, they must be at the same
6674 : : source location (and wrap the same thing). */
6675 : 100574566 : if (location_wrapper_p (t1) && location_wrapper_p (t2))
6676 : : {
6677 : 10425392 : if (EXPR_LOCATION (t1) != EXPR_LOCATION (t2))
6678 : : return 0;
6679 : 597 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6680 : : }
6681 : :
6682 : 90149174 : code1 = TREE_CODE (t1);
6683 : 90149174 : code2 = TREE_CODE (t2);
6684 : :
6685 : 90149174 : if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR)
6686 : : {
6687 : 3819813 : if (CONVERT_EXPR_CODE_P (code2)
6688 : 3819117 : || code2 == NON_LVALUE_EXPR)
6689 : 696 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6690 : : else
6691 : 3819117 : return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
6692 : : }
6693 : :
6694 : 86329361 : else if (CONVERT_EXPR_CODE_P (code2)
6695 : 86329349 : || code2 == NON_LVALUE_EXPR)
6696 : 113 : return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
6697 : :
6698 : 86329248 : if (code1 != code2)
6699 : : return 0;
6700 : :
6701 : 81995047 : switch (code1)
6702 : : {
6703 : 67672058 : case INTEGER_CST:
6704 : 67672058 : return wi::to_widest (t1) == wi::to_widest (t2);
6705 : :
6706 : 89 : case REAL_CST:
6707 : 89 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
6708 : :
6709 : 0 : case FIXED_CST:
6710 : 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
6711 : :
6712 : 3022919 : case STRING_CST:
6713 : 3022919 : return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
6714 : 3022919 : && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
6715 : 3438031 : TREE_STRING_LENGTH (t1)));
6716 : :
6717 : 58 : case CONSTRUCTOR:
6718 : 58 : {
6719 : 58 : unsigned HOST_WIDE_INT idx;
6720 : 58 : vec<constructor_elt, va_gc> *v1 = CONSTRUCTOR_ELTS (t1);
6721 : 58 : vec<constructor_elt, va_gc> *v2 = CONSTRUCTOR_ELTS (t2);
6722 : :
6723 : 76 : if (vec_safe_length (v1) != vec_safe_length (v2))
6724 : : return false;
6725 : :
6726 : 64 : for (idx = 0; idx < vec_safe_length (v1); ++idx)
6727 : : /* ??? Should we handle also fields here? */
6728 : 9 : if (!simple_cst_equal ((*v1)[idx].value, (*v2)[idx].value))
6729 : : return false;
6730 : : return true;
6731 : : }
6732 : :
6733 : 0 : case SAVE_EXPR:
6734 : 0 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6735 : :
6736 : 202108 : case CALL_EXPR:
6737 : 202108 : cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2));
6738 : 202108 : if (cmp <= 0)
6739 : : return cmp;
6740 : 82714 : if (call_expr_nargs (t1) != call_expr_nargs (t2))
6741 : : return 0;
6742 : 82714 : {
6743 : 82714 : const_tree arg1, arg2;
6744 : 82714 : const_call_expr_arg_iterator iter1, iter2;
6745 : 165428 : for (arg1 = first_const_call_expr_arg (t1, &iter1),
6746 : 82714 : arg2 = first_const_call_expr_arg (t2, &iter2);
6747 : 82802 : arg1 && arg2;
6748 : 88 : arg1 = next_const_call_expr_arg (&iter1),
6749 : 88 : arg2 = next_const_call_expr_arg (&iter2))
6750 : : {
6751 : 82715 : cmp = simple_cst_equal (arg1, arg2);
6752 : 82715 : if (cmp <= 0)
6753 : : return cmp;
6754 : : }
6755 : 87 : return arg1 == arg2;
6756 : : }
6757 : :
6758 : 11611 : case TARGET_EXPR:
6759 : : /* Special case: if either target is an unallocated VAR_DECL,
6760 : : it means that it's going to be unified with whatever the
6761 : : TARGET_EXPR is really supposed to initialize, so treat it
6762 : : as being equivalent to anything. */
6763 : 11611 : if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
6764 : 11611 : && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
6765 : 11611 : && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
6766 : 11611 : || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
6767 : 0 : && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
6768 : 0 : && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
6769 : : cmp = 1;
6770 : : else
6771 : 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6772 : :
6773 : 0 : if (cmp <= 0)
6774 : : return cmp;
6775 : :
6776 : 11611 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
6777 : :
6778 : 0 : case WITH_CLEANUP_EXPR:
6779 : 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6780 : 0 : if (cmp <= 0)
6781 : : return cmp;
6782 : :
6783 : 0 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
6784 : :
6785 : 425 : case COMPONENT_REF:
6786 : 425 : if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
6787 : 425 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6788 : :
6789 : : return 0;
6790 : :
6791 : : case VAR_DECL:
6792 : : case PARM_DECL:
6793 : : case CONST_DECL:
6794 : : case FUNCTION_DECL:
6795 : : return 0;
6796 : :
6797 : 11025825 : default:
6798 : 11025825 : if (POLY_INT_CST_P (t1))
6799 : : /* A false return means maybe_ne rather than known_ne. */
6800 : : return known_eq (poly_widest_int::from (poly_int_cst_value (t1),
6801 : : TYPE_SIGN (TREE_TYPE (t1))),
6802 : : poly_widest_int::from (poly_int_cst_value (t2),
6803 : : TYPE_SIGN (TREE_TYPE (t2))));
6804 : 11025825 : break;
6805 : : }
6806 : :
6807 : : /* This general rule works for most tree codes. All exceptions should be
6808 : : handled above. If this is a language-specific tree code, we can't
6809 : : trust what might be in the operand, so say we don't know
6810 : : the situation. */
6811 : 11025825 : if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
6812 : : return -1;
6813 : :
6814 : 6518664 : switch (TREE_CODE_CLASS (code1))
6815 : : {
6816 : : case tcc_unary:
6817 : : case tcc_binary:
6818 : : case tcc_comparison:
6819 : : case tcc_expression:
6820 : : case tcc_reference:
6821 : : case tcc_statement:
6822 : : cmp = 1;
6823 : 2095 : for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
6824 : : {
6825 : 1620 : cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
6826 : 1620 : if (cmp <= 0)
6827 : : return cmp;
6828 : : }
6829 : :
6830 : : return cmp;
6831 : :
6832 : : default:
6833 : : return -1;
6834 : : }
6835 : : }
6836 : :
6837 : : /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
6838 : : Return -1, 0, or 1 if the value of T is less than, equal to, or greater
6839 : : than U, respectively. */
6840 : :
6841 : : int
6842 : 1247943346 : compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u)
6843 : : {
6844 : 1247943346 : if (tree_int_cst_sgn (t) < 0)
6845 : : return -1;
6846 : 1247943082 : else if (!tree_fits_uhwi_p (t))
6847 : : return 1;
6848 : 1247943057 : else if (TREE_INT_CST_LOW (t) == u)
6849 : : return 0;
6850 : 1132740409 : else if (TREE_INT_CST_LOW (t) < u)
6851 : : return -1;
6852 : : else
6853 : 11688331 : return 1;
6854 : : }
6855 : :
6856 : : /* Return true if SIZE represents a constant size that is in bounds of
6857 : : what the middle-end and the backend accepts (covering not more than
6858 : : half of the address-space).
6859 : : When PERR is non-null, set *PERR on failure to the description of
6860 : : why SIZE is not valid. */
6861 : :
6862 : : bool
6863 : 49607860 : valid_constant_size_p (const_tree size, cst_size_error *perr /* = NULL */)
6864 : : {
6865 : 49607860 : if (POLY_INT_CST_P (size))
6866 : : {
6867 : : if (TREE_OVERFLOW (size))
6868 : : return false;
6869 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
6870 : : if (!valid_constant_size_p (POLY_INT_CST_COEFF (size, i)))
6871 : : return false;
6872 : : return true;
6873 : : }
6874 : :
6875 : 49607860 : cst_size_error error;
6876 : 49607860 : if (!perr)
6877 : 45044237 : perr = &error;
6878 : :
6879 : 49607860 : if (TREE_CODE (size) != INTEGER_CST)
6880 : : {
6881 : 3 : *perr = cst_size_not_constant;
6882 : 3 : return false;
6883 : : }
6884 : :
6885 : 49607857 : if (TREE_OVERFLOW_P (size))
6886 : : {
6887 : 60 : *perr = cst_size_overflow;
6888 : 60 : return false;
6889 : : }
6890 : :
6891 : 49607797 : if (tree_int_cst_sgn (size) < 0)
6892 : : {
6893 : 424 : *perr = cst_size_negative;
6894 : 424 : return false;
6895 : : }
6896 : 99214746 : if (!tree_fits_uhwi_p (size)
6897 : 148822119 : || (wi::to_widest (TYPE_MAX_VALUE (sizetype))
6898 : 148822119 : < wi::to_widest (size) * 2))
6899 : : {
6900 : 624 : *perr = cst_size_too_big;
6901 : 624 : return false;
6902 : : }
6903 : :
6904 : : return true;
6905 : : }
6906 : :
6907 : : /* Return the precision of the type, or for a complex or vector type the
6908 : : precision of the type of its elements. */
6909 : :
6910 : : unsigned int
6911 : 6782968928 : element_precision (const_tree type)
6912 : : {
6913 : 6782968928 : if (!TYPE_P (type))
6914 : 5741442 : type = TREE_TYPE (type);
6915 : 6782968928 : enum tree_code code = TREE_CODE (type);
6916 : 6782968928 : if (code == COMPLEX_TYPE || code == VECTOR_TYPE)
6917 : 56509905 : type = TREE_TYPE (type);
6918 : :
6919 : 6782968928 : return TYPE_PRECISION (type);
6920 : : }
6921 : :
6922 : : /* Return true if CODE represents an associative tree code. Otherwise
6923 : : return false. */
6924 : : bool
6925 : 32496088 : associative_tree_code (enum tree_code code)
6926 : : {
6927 : 32496088 : switch (code)
6928 : : {
6929 : : case BIT_IOR_EXPR:
6930 : : case BIT_AND_EXPR:
6931 : : case BIT_XOR_EXPR:
6932 : : case PLUS_EXPR:
6933 : : case MULT_EXPR:
6934 : : case MIN_EXPR:
6935 : : case MAX_EXPR:
6936 : : return true;
6937 : :
6938 : 22947288 : default:
6939 : 22947288 : break;
6940 : : }
6941 : 22947288 : return false;
6942 : : }
6943 : :
6944 : : /* Return true if CODE represents a commutative tree code. Otherwise
6945 : : return false. */
6946 : : bool
6947 : 1519478955 : commutative_tree_code (enum tree_code code)
6948 : : {
6949 : 1519478955 : switch (code)
6950 : : {
6951 : : case PLUS_EXPR:
6952 : : case MULT_EXPR:
6953 : : case MULT_HIGHPART_EXPR:
6954 : : case MIN_EXPR:
6955 : : case MAX_EXPR:
6956 : : case BIT_IOR_EXPR:
6957 : : case BIT_XOR_EXPR:
6958 : : case BIT_AND_EXPR:
6959 : : case NE_EXPR:
6960 : : case EQ_EXPR:
6961 : : case UNORDERED_EXPR:
6962 : : case ORDERED_EXPR:
6963 : : case UNEQ_EXPR:
6964 : : case LTGT_EXPR:
6965 : : case TRUTH_AND_EXPR:
6966 : : case TRUTH_XOR_EXPR:
6967 : : case TRUTH_OR_EXPR:
6968 : : case WIDEN_MULT_EXPR:
6969 : : case VEC_WIDEN_MULT_HI_EXPR:
6970 : : case VEC_WIDEN_MULT_LO_EXPR:
6971 : : case VEC_WIDEN_MULT_EVEN_EXPR:
6972 : : case VEC_WIDEN_MULT_ODD_EXPR:
6973 : : return true;
6974 : :
6975 : 789120511 : default:
6976 : 789120511 : break;
6977 : : }
6978 : 789120511 : return false;
6979 : : }
6980 : :
6981 : : /* Return true if CODE represents a ternary tree code for which the
6982 : : first two operands are commutative. Otherwise return false. */
6983 : : bool
6984 : 74306954 : commutative_ternary_tree_code (enum tree_code code)
6985 : : {
6986 : 74306954 : switch (code)
6987 : : {
6988 : : case WIDEN_MULT_PLUS_EXPR:
6989 : : case WIDEN_MULT_MINUS_EXPR:
6990 : : case DOT_PROD_EXPR:
6991 : : return true;
6992 : :
6993 : 74301389 : default:
6994 : 74301389 : break;
6995 : : }
6996 : 74301389 : return false;
6997 : : }
6998 : :
6999 : : /* Returns true if CODE can overflow. */
7000 : :
7001 : : bool
7002 : 2945 : operation_can_overflow (enum tree_code code)
7003 : : {
7004 : 2945 : switch (code)
7005 : : {
7006 : : case PLUS_EXPR:
7007 : : case MINUS_EXPR:
7008 : : case MULT_EXPR:
7009 : : case LSHIFT_EXPR:
7010 : : /* Can overflow in various ways. */
7011 : : return true;
7012 : : case TRUNC_DIV_EXPR:
7013 : : case EXACT_DIV_EXPR:
7014 : : case FLOOR_DIV_EXPR:
7015 : : case CEIL_DIV_EXPR:
7016 : : /* For INT_MIN / -1. */
7017 : : return true;
7018 : : case NEGATE_EXPR:
7019 : : case ABS_EXPR:
7020 : : /* For -INT_MIN. */
7021 : : return true;
7022 : 140 : default:
7023 : : /* These operators cannot overflow. */
7024 : 140 : return false;
7025 : : }
7026 : : }
7027 : :
7028 : : /* Returns true if CODE operating on operands of type TYPE doesn't overflow, or
7029 : : ftrapv doesn't generate trapping insns for CODE. */
7030 : :
7031 : : bool
7032 : 5351604 : operation_no_trapping_overflow (tree type, enum tree_code code)
7033 : : {
7034 : 5351604 : gcc_checking_assert (ANY_INTEGRAL_TYPE_P (type));
7035 : :
7036 : : /* We don't generate instructions that trap on overflow for complex or vector
7037 : : types. */
7038 : 5351604 : if (!INTEGRAL_TYPE_P (type))
7039 : : return true;
7040 : :
7041 : 5351604 : if (!TYPE_OVERFLOW_TRAPS (type))
7042 : : return true;
7043 : :
7044 : 468 : switch (code)
7045 : : {
7046 : : case PLUS_EXPR:
7047 : : case MINUS_EXPR:
7048 : : case MULT_EXPR:
7049 : : case NEGATE_EXPR:
7050 : : case ABS_EXPR:
7051 : : /* These operators can overflow, and -ftrapv generates trapping code for
7052 : : these. */
7053 : : return false;
7054 : : case TRUNC_DIV_EXPR:
7055 : : case EXACT_DIV_EXPR:
7056 : : case FLOOR_DIV_EXPR:
7057 : : case CEIL_DIV_EXPR:
7058 : : case LSHIFT_EXPR:
7059 : : /* These operators can overflow, but -ftrapv does not generate trapping
7060 : : code for these. */
7061 : : return true;
7062 : : default:
7063 : : /* These operators cannot overflow. */
7064 : : return true;
7065 : : }
7066 : : }
7067 : :
7068 : : /* Constructors for pointer, array and function types.
7069 : : (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7070 : : constructed by language-dependent code, not here.) */
7071 : :
7072 : : /* Construct, lay out and return the type of pointers to TO_TYPE with
7073 : : mode MODE. If MODE is VOIDmode, a pointer mode for the address
7074 : : space of TO_TYPE will be picked. If CAN_ALIAS_ALL is TRUE,
7075 : : indicate this type can reference all of memory. If such a type has
7076 : : already been constructed, reuse it. */
7077 : :
7078 : : tree
7079 : 1885599546 : build_pointer_type_for_mode (tree to_type, machine_mode mode,
7080 : : bool can_alias_all)
7081 : : {
7082 : 1885599546 : tree t;
7083 : 1885599546 : bool could_alias = can_alias_all;
7084 : :
7085 : 1885599546 : if (to_type == error_mark_node)
7086 : : return error_mark_node;
7087 : :
7088 : 1885599540 : if (mode == VOIDmode)
7089 : : {
7090 : 1768424980 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7091 : 1768424980 : mode = targetm.addr_space.pointer_mode (as);
7092 : : }
7093 : :
7094 : : /* If the pointed-to type has the may_alias attribute set, force
7095 : : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7096 : 1885599540 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7097 : 4251244 : can_alias_all = true;
7098 : :
7099 : : /* In some cases, languages will have things that aren't a POINTER_TYPE
7100 : : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7101 : : In that case, return that type without regard to the rest of our
7102 : : operands.
7103 : :
7104 : : ??? This is a kludge, but consistent with the way this function has
7105 : : always operated and there doesn't seem to be a good way to avoid this
7106 : : at the moment. */
7107 : 1885599540 : if (TYPE_POINTER_TO (to_type) != 0
7108 : 1885599540 : && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
7109 : 41187 : return TYPE_POINTER_TO (to_type);
7110 : :
7111 : : /* First, if we already have a type for pointers to TO_TYPE and it's
7112 : : the proper mode, use it. */
7113 : 1886091033 : for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
7114 : 1768110652 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7115 : : return t;
7116 : :
7117 : 117980381 : t = make_node (POINTER_TYPE);
7118 : :
7119 : 117980381 : TREE_TYPE (t) = to_type;
7120 : 117980381 : SET_TYPE_MODE (t, mode);
7121 : 117980381 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7122 : 117980381 : TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
7123 : 117980381 : TYPE_POINTER_TO (to_type) = t;
7124 : :
7125 : : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7126 : 117980381 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7127 : 4995748 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7128 : 112984633 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7129 : 68787188 : TYPE_CANONICAL (t)
7130 : 34393594 : = build_pointer_type_for_mode (TYPE_CANONICAL (to_type),
7131 : : mode, false);
7132 : :
7133 : : /* Lay out the type. This function has many callers that are concerned
7134 : : with expression-construction, and this simplifies them all. */
7135 : 117980381 : layout_type (t);
7136 : :
7137 : 117980381 : return t;
7138 : : }
7139 : :
7140 : : /* By default build pointers in ptr_mode. */
7141 : :
7142 : : tree
7143 : 1767754506 : build_pointer_type (tree to_type)
7144 : : {
7145 : 1767754506 : return build_pointer_type_for_mode (to_type, VOIDmode, false);
7146 : : }
7147 : :
7148 : : /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7149 : :
7150 : : tree
7151 : 460353022 : build_reference_type_for_mode (tree to_type, machine_mode mode,
7152 : : bool can_alias_all)
7153 : : {
7154 : 460353022 : tree t;
7155 : 460353022 : bool could_alias = can_alias_all;
7156 : :
7157 : 460353022 : if (to_type == error_mark_node)
7158 : : return error_mark_node;
7159 : :
7160 : 460353022 : if (mode == VOIDmode)
7161 : : {
7162 : 381663836 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7163 : 381663836 : mode = targetm.addr_space.pointer_mode (as);
7164 : : }
7165 : :
7166 : : /* If the pointed-to type has the may_alias attribute set, force
7167 : : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7168 : 460353022 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7169 : 667912 : can_alias_all = true;
7170 : :
7171 : : /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7172 : : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7173 : : In that case, return that type without regard to the rest of our
7174 : : operands.
7175 : :
7176 : : ??? This is a kludge, but consistent with the way this function has
7177 : : always operated and there doesn't seem to be a good way to avoid this
7178 : : at the moment. */
7179 : 460353022 : if (TYPE_REFERENCE_TO (to_type) != 0
7180 : 460353022 : && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
7181 : 0 : return TYPE_REFERENCE_TO (to_type);
7182 : :
7183 : : /* First, if we already have a type for pointers to TO_TYPE and it's
7184 : : the proper mode, use it. */
7185 : 460353022 : for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
7186 : 391838967 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7187 : : return t;
7188 : :
7189 : 68514055 : t = make_node (REFERENCE_TYPE);
7190 : :
7191 : 68514055 : TREE_TYPE (t) = to_type;
7192 : 68514055 : SET_TYPE_MODE (t, mode);
7193 : 68514055 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7194 : 68514055 : TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
7195 : 68514055 : TYPE_REFERENCE_TO (to_type) = t;
7196 : :
7197 : : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7198 : 68514055 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7199 : 3260770 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7200 : 65253285 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7201 : 76673024 : TYPE_CANONICAL (t)
7202 : 38336512 : = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
7203 : : mode, false);
7204 : :
7205 : 68514055 : layout_type (t);
7206 : :
7207 : 68514055 : return t;
7208 : : }
7209 : :
7210 : :
7211 : : /* Build the node for the type of references-to-TO_TYPE by default
7212 : : in ptr_mode. */
7213 : :
7214 : : tree
7215 : 18988929 : build_reference_type (tree to_type)
7216 : : {
7217 : 18988929 : return build_reference_type_for_mode (to_type, VOIDmode, false);
7218 : : }
7219 : :
7220 : : #define MAX_INT_CACHED_PREC \
7221 : : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7222 : : static GTY(()) tree nonstandard_integer_type_cache[2 * MAX_INT_CACHED_PREC + 2];
7223 : :
7224 : : static void
7225 : 255021 : clear_nonstandard_integer_type_cache (void)
7226 : : {
7227 : 33407751 : for (size_t i = 0 ; i < 2 * MAX_INT_CACHED_PREC + 2 ; i++)
7228 : : {
7229 : 33152730 : nonstandard_integer_type_cache[i] = NULL;
7230 : : }
7231 : 0 : }
7232 : :
7233 : : /* Builds a signed or unsigned integer type of precision PRECISION.
7234 : : Used for C bitfields whose precision does not match that of
7235 : : built-in target types. */
7236 : : tree
7237 : 60284748 : build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
7238 : : int unsignedp)
7239 : : {
7240 : 60284748 : tree itype, ret;
7241 : :
7242 : 60284748 : if (unsignedp)
7243 : 51121893 : unsignedp = MAX_INT_CACHED_PREC + 1;
7244 : :
7245 : 60284748 : if (precision <= MAX_INT_CACHED_PREC)
7246 : : {
7247 : 58550783 : itype = nonstandard_integer_type_cache[precision + unsignedp];
7248 : 58550783 : if (itype)
7249 : : return itype;
7250 : : }
7251 : :
7252 : 2341588 : itype = make_node (INTEGER_TYPE);
7253 : 2341588 : TYPE_PRECISION (itype) = precision;
7254 : :
7255 : 2341588 : if (unsignedp)
7256 : 754449 : fixup_unsigned_type (itype);
7257 : : else
7258 : 1587139 : fixup_signed_type (itype);
7259 : :
7260 : 2341588 : inchash::hash hstate;
7261 : 2341588 : inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7262 : 2341588 : ret = type_hash_canon (hstate.end (), itype);
7263 : 2341588 : if (precision <= MAX_INT_CACHED_PREC)
7264 : 607623 : nonstandard_integer_type_cache[precision + unsignedp] = ret;
7265 : :
7266 : : return ret;
7267 : : }
7268 : :
7269 : : #define MAX_BOOL_CACHED_PREC \
7270 : : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7271 : : static GTY(()) tree nonstandard_boolean_type_cache[MAX_BOOL_CACHED_PREC + 1];
7272 : :
7273 : : /* Builds a boolean type of precision PRECISION.
7274 : : Used for boolean vectors to choose proper vector element size. */
7275 : : tree
7276 : 1766631 : build_nonstandard_boolean_type (unsigned HOST_WIDE_INT precision)
7277 : : {
7278 : 1766631 : tree type;
7279 : :
7280 : 1766631 : if (precision <= MAX_BOOL_CACHED_PREC)
7281 : : {
7282 : 1763855 : type = nonstandard_boolean_type_cache[precision];
7283 : 1763855 : if (type)
7284 : : return type;
7285 : : }
7286 : :
7287 : 73300 : type = make_node (BOOLEAN_TYPE);
7288 : 73300 : TYPE_PRECISION (type) = precision;
7289 : 73300 : fixup_signed_type (type);
7290 : :
7291 : 73300 : if (precision <= MAX_INT_CACHED_PREC)
7292 : 70524 : nonstandard_boolean_type_cache[precision] = type;
7293 : :
7294 : : return type;
7295 : : }
7296 : :
7297 : : static GTY(()) vec<tree, va_gc> *bitint_type_cache;
7298 : :
7299 : : /* Builds a signed or unsigned _BitInt(PRECISION) type. */
7300 : : tree
7301 : 1511744 : build_bitint_type (unsigned HOST_WIDE_INT precision, int unsignedp)
7302 : : {
7303 : 1511744 : tree itype, ret;
7304 : :
7305 : 1545531 : gcc_checking_assert (precision >= 1 + !unsignedp);
7306 : :
7307 : 1511744 : if (unsignedp)
7308 : 33787 : unsignedp = MAX_INT_CACHED_PREC + 1;
7309 : :
7310 : 1511744 : if (bitint_type_cache == NULL)
7311 : 433 : vec_safe_grow_cleared (bitint_type_cache, 2 * MAX_INT_CACHED_PREC + 2);
7312 : :
7313 : 1511744 : if (precision <= MAX_INT_CACHED_PREC)
7314 : : {
7315 : 35456 : itype = (*bitint_type_cache)[precision + unsignedp];
7316 : 35456 : if (itype)
7317 : : return itype;
7318 : : }
7319 : :
7320 : 1477583 : itype = make_node (BITINT_TYPE);
7321 : 1477583 : TYPE_PRECISION (itype) = precision;
7322 : :
7323 : 1477583 : if (unsignedp)
7324 : 27582 : fixup_unsigned_type (itype);
7325 : : else
7326 : 1450001 : fixup_signed_type (itype);
7327 : :
7328 : 1477583 : inchash::hash hstate;
7329 : 1477583 : inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7330 : 1477583 : ret = type_hash_canon (hstate.end (), itype);
7331 : 1477583 : if (precision <= MAX_INT_CACHED_PREC)
7332 : 1295 : (*bitint_type_cache)[precision + unsignedp] = ret;
7333 : :
7334 : : return ret;
7335 : : }
7336 : :
7337 : : /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7338 : : or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7339 : : is true, reuse such a type that has already been constructed. */
7340 : :
7341 : : static tree
7342 : 35568188 : build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
7343 : : {
7344 : 35568188 : tree itype = make_node (INTEGER_TYPE);
7345 : :
7346 : 35568188 : TREE_TYPE (itype) = type;
7347 : :
7348 : 35568188 : TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
7349 : 35568188 : TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
7350 : :
7351 : 35568188 : TYPE_PRECISION (itype) = TYPE_PRECISION (type);
7352 : 35568188 : SET_TYPE_MODE (itype, TYPE_MODE (type));
7353 : 35568188 : TYPE_SIZE (itype) = TYPE_SIZE (type);
7354 : 35568188 : TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
7355 : 35568188 : SET_TYPE_ALIGN (itype, TYPE_ALIGN (type));
7356 : 35568188 : TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
7357 : 35568188 : SET_TYPE_WARN_IF_NOT_ALIGN (itype, TYPE_WARN_IF_NOT_ALIGN (type));
7358 : :
7359 : 35568188 : if (!shared)
7360 : : return itype;
7361 : :
7362 : 35568188 : if ((TYPE_MIN_VALUE (itype)
7363 : 35568188 : && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST)
7364 : 71135547 : || (TYPE_MAX_VALUE (itype)
7365 : 35031384 : && TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST))
7366 : : {
7367 : : /* Since we cannot reliably merge this type, we need to compare it using
7368 : : structural equality checks. */
7369 : 867594 : SET_TYPE_STRUCTURAL_EQUALITY (itype);
7370 : 867594 : return itype;
7371 : : }
7372 : :
7373 : 34700594 : hashval_t hash = type_hash_canon_hash (itype);
7374 : 34700594 : itype = type_hash_canon (hash, itype);
7375 : :
7376 : 34700594 : return itype;
7377 : : }
7378 : :
7379 : : /* Wrapper around build_range_type_1 with SHARED set to true. */
7380 : :
7381 : : tree
7382 : 35568188 : build_range_type (tree type, tree lowval, tree highval)
7383 : : {
7384 : 35568188 : return build_range_type_1 (type, lowval, highval, true);
7385 : : }
7386 : :
7387 : : /* Wrapper around build_range_type_1 with SHARED set to false. */
7388 : :
7389 : : tree
7390 : 0 : build_nonshared_range_type (tree type, tree lowval, tree highval)
7391 : : {
7392 : 0 : return build_range_type_1 (type, lowval, highval, false);
7393 : : }
7394 : :
7395 : : /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7396 : : MAXVAL should be the maximum value in the domain
7397 : : (one less than the length of the array).
7398 : :
7399 : : The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7400 : : We don't enforce this limit, that is up to caller (e.g. language front end).
7401 : : The limit exists because the result is a signed type and we don't handle
7402 : : sizes that use more than one HOST_WIDE_INT. */
7403 : :
7404 : : tree
7405 : 33220160 : build_index_type (tree maxval)
7406 : : {
7407 : 33220160 : return build_range_type (sizetype, size_zero_node, maxval);
7408 : : }
7409 : :
7410 : : /* Return true if the debug information for TYPE, a subtype, should be emitted
7411 : : as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7412 : : high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7413 : : debug info and doesn't reflect the source code. */
7414 : :
7415 : : bool
7416 : 18 : subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval)
7417 : : {
7418 : 18 : tree base_type = TREE_TYPE (type), low, high;
7419 : :
7420 : : /* Subrange types have a base type which is an integral type. */
7421 : 18 : if (!INTEGRAL_TYPE_P (base_type))
7422 : : return false;
7423 : :
7424 : : /* Get the real bounds of the subtype. */
7425 : 18 : if (lang_hooks.types.get_subrange_bounds)
7426 : 0 : lang_hooks.types.get_subrange_bounds (type, &low, &high);
7427 : : else
7428 : : {
7429 : 18 : low = TYPE_MIN_VALUE (type);
7430 : 18 : high = TYPE_MAX_VALUE (type);
7431 : : }
7432 : :
7433 : : /* If the type and its base type have the same representation and the same
7434 : : name, then the type is not a subrange but a copy of the base type. */
7435 : 18 : if ((TREE_CODE (base_type) == INTEGER_TYPE
7436 : 18 : || TREE_CODE (base_type) == BOOLEAN_TYPE)
7437 : 18 : && int_size_in_bytes (type) == int_size_in_bytes (base_type)
7438 : 18 : && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type))
7439 : 0 : && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type))
7440 : 18 : && TYPE_IDENTIFIER (type) == TYPE_IDENTIFIER (base_type))
7441 : : return false;
7442 : :
7443 : 18 : if (lowval)
7444 : 18 : *lowval = low;
7445 : 18 : if (highval)
7446 : 18 : *highval = high;
7447 : : return true;
7448 : : }
7449 : :
7450 : : /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7451 : : and number of elements specified by the range of values of INDEX_TYPE.
7452 : : If TYPELESS_STORAGE is true, TYPE_TYPELESS_STORAGE flag is set on the type.
7453 : : If SHARED is true, reuse such a type that has already been constructed.
7454 : : If SET_CANONICAL is true, compute TYPE_CANONICAL from the element type. */
7455 : :
7456 : : tree
7457 : 56106316 : build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
7458 : : bool shared, bool set_canonical)
7459 : : {
7460 : 56106316 : tree t;
7461 : :
7462 : 56106316 : if (TREE_CODE (elt_type) == FUNCTION_TYPE)
7463 : : {
7464 : 0 : error ("arrays of functions are not meaningful");
7465 : 0 : elt_type = integer_type_node;
7466 : : }
7467 : :
7468 : 56106316 : t = make_node (ARRAY_TYPE);
7469 : 56106316 : TREE_TYPE (t) = elt_type;
7470 : 56106316 : TYPE_DOMAIN (t) = index_type;
7471 : 56106316 : TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type);
7472 : 56106316 : TYPE_TYPELESS_STORAGE (t) = typeless_storage;
7473 : :
7474 : : /* Set TYPE_STRUCTURAL_EQUALITY_P. */
7475 : 56106316 : if (set_canonical
7476 : 56106316 : && (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7477 : 56075485 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7478 : 55845024 : || in_lto_p))
7479 : 335057 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7480 : :
7481 : 56106316 : layout_type (t);
7482 : :
7483 : 56106316 : if (shared)
7484 : : {
7485 : 56106289 : hashval_t hash = type_hash_canon_hash (t);
7486 : 56106289 : tree probe_type = t;
7487 : 56106289 : t = type_hash_canon (hash, t);
7488 : 56106289 : if (t != probe_type)
7489 : : return t;
7490 : : }
7491 : :
7492 : 9556491 : if (TYPE_CANONICAL (t) == t && set_canonical)
7493 : : {
7494 : 9270308 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7495 : 9270308 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7496 : 18540616 : || in_lto_p)
7497 : 0 : gcc_unreachable ();
7498 : 9270308 : else if (TYPE_CANONICAL (elt_type) != elt_type
7499 : 9270308 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
7500 : 199460 : TYPE_CANONICAL (t)
7501 : 189471 : = build_array_type_1 (TYPE_CANONICAL (elt_type),
7502 : : index_type
7503 : 89741 : ? TYPE_CANONICAL (index_type) : NULL_TREE,
7504 : : typeless_storage, shared, set_canonical);
7505 : : }
7506 : :
7507 : : return t;
7508 : : }
7509 : :
7510 : : /* Wrapper around build_array_type_1 with SHARED set to true. */
7511 : :
7512 : : tree
7513 : 56006559 : build_array_type (tree elt_type, tree index_type, bool typeless_storage)
7514 : : {
7515 : 56006559 : return
7516 : 56006559 : build_array_type_1 (elt_type, index_type, typeless_storage, true, true);
7517 : : }
7518 : :
7519 : : /* Wrapper around build_array_type_1 with SHARED set to false. */
7520 : :
7521 : : tree
7522 : 0 : build_nonshared_array_type (tree elt_type, tree index_type)
7523 : : {
7524 : 0 : return build_array_type_1 (elt_type, index_type, false, false, true);
7525 : : }
7526 : :
7527 : : /* Return a representation of ELT_TYPE[NELTS], using indices of type
7528 : : sizetype. */
7529 : :
7530 : : tree
7531 : 1391979 : build_array_type_nelts (tree elt_type, poly_uint64 nelts)
7532 : : {
7533 : 1391979 : return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
7534 : : }
7535 : :
7536 : : /* Computes the canonical argument types from the argument type list
7537 : : ARGTYPES.
7538 : :
7539 : : Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7540 : : on entry to this function, or if any of the ARGTYPES are
7541 : : structural.
7542 : :
7543 : : Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7544 : : true on entry to this function, or if any of the ARGTYPES are
7545 : : non-canonical.
7546 : :
7547 : : Returns a canonical argument list, which may be ARGTYPES when the
7548 : : canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7549 : : true) or would not differ from ARGTYPES. */
7550 : :
7551 : : static tree
7552 : 845579510 : maybe_canonicalize_argtypes (tree argtypes,
7553 : : bool *any_structural_p,
7554 : : bool *any_noncanonical_p)
7555 : : {
7556 : 845579510 : tree arg;
7557 : 845579510 : bool any_noncanonical_argtypes_p = false;
7558 : :
7559 : 2977617763 : for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
7560 : : {
7561 : 2132038253 : if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
7562 : : /* Fail gracefully by stating that the type is structural. */
7563 : 3267 : *any_structural_p = true;
7564 : 2132034986 : else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg)))
7565 : 31851337 : *any_structural_p = true;
7566 : 2100183649 : else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg)
7567 : 2100183649 : || TREE_PURPOSE (arg))
7568 : : /* If the argument has a default argument, we consider it
7569 : : non-canonical even though the type itself is canonical.
7570 : : That way, different variants of function and method types
7571 : : with default arguments will all point to the variant with
7572 : : no defaults as their canonical type. */
7573 : : any_noncanonical_argtypes_p = true;
7574 : : }
7575 : :
7576 : 845579510 : if (*any_structural_p)
7577 : : return argtypes;
7578 : :
7579 : 760396871 : if (any_noncanonical_argtypes_p)
7580 : : {
7581 : : /* Build the canonical list of argument types. */
7582 : : tree canon_argtypes = NULL_TREE;
7583 : : bool is_void = false;
7584 : :
7585 : 777146189 : for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
7586 : : {
7587 : 598764147 : if (arg == void_list_node)
7588 : : is_void = true;
7589 : : else
7590 : 843142670 : canon_argtypes = tree_cons (NULL_TREE,
7591 : 421571335 : TYPE_CANONICAL (TREE_VALUE (arg)),
7592 : : canon_argtypes);
7593 : : }
7594 : :
7595 : 178382042 : canon_argtypes = nreverse (canon_argtypes);
7596 : 178382042 : if (is_void)
7597 : 177192812 : canon_argtypes = chainon (canon_argtypes, void_list_node);
7598 : :
7599 : : /* There is a non-canonical type. */
7600 : 178382042 : *any_noncanonical_p = true;
7601 : 178382042 : return canon_argtypes;
7602 : : }
7603 : :
7604 : : /* The canonical argument types are the same as ARGTYPES. */
7605 : : return argtypes;
7606 : : }
7607 : :
7608 : : /* Construct, lay out and return
7609 : : the type of functions returning type VALUE_TYPE
7610 : : given arguments of types ARG_TYPES.
7611 : : ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7612 : : are data type nodes for the arguments of the function.
7613 : : NO_NAMED_ARGS_STDARG_P is true if this is a prototyped
7614 : : variable-arguments function with (...) prototype (no named arguments).
7615 : : If such a type has already been constructed, reuse it. */
7616 : :
7617 : : tree
7618 : 577049683 : build_function_type (tree value_type, tree arg_types,
7619 : : bool no_named_args_stdarg_p)
7620 : : {
7621 : 577049683 : tree t;
7622 : 577049683 : inchash::hash hstate;
7623 : 577049683 : bool any_structural_p, any_noncanonical_p;
7624 : 577049683 : tree canon_argtypes;
7625 : :
7626 : 577049683 : gcc_assert (arg_types != error_mark_node);
7627 : :
7628 : 577049683 : if (TREE_CODE (value_type) == FUNCTION_TYPE)
7629 : : {
7630 : 0 : error ("function return type cannot be function");
7631 : 0 : value_type = integer_type_node;
7632 : : }
7633 : :
7634 : : /* Make a node of the sort we want. */
7635 : 577049683 : t = make_node (FUNCTION_TYPE);
7636 : 577049683 : TREE_TYPE (t) = value_type;
7637 : 577049683 : TYPE_ARG_TYPES (t) = arg_types;
7638 : 577049683 : if (no_named_args_stdarg_p)
7639 : : {
7640 : 217448 : gcc_assert (arg_types == NULL_TREE);
7641 : 217448 : TYPE_NO_NAMED_ARGS_STDARG_P (t) = 1;
7642 : : }
7643 : :
7644 : : /* Set up the canonical type. */
7645 : 577049683 : any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type);
7646 : 577049683 : any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
7647 : 577049683 : canon_argtypes = maybe_canonicalize_argtypes (arg_types,
7648 : : &any_structural_p,
7649 : : &any_noncanonical_p);
7650 : : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7651 : 577049683 : if (any_structural_p)
7652 : 63580753 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7653 : :
7654 : : /* If we already have such a type, use the old one. */
7655 : 577049683 : hashval_t hash = type_hash_canon_hash (t);
7656 : 577049683 : tree probe_type = t;
7657 : 577049683 : t = type_hash_canon (hash, t);
7658 : 577049683 : if (t != probe_type)
7659 : : return t;
7660 : :
7661 : 379754178 : if (any_structural_p)
7662 : 51979037 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7663 : 327775141 : else if (any_noncanonical_p)
7664 : 73698921 : TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
7665 : : canon_argtypes);
7666 : :
7667 : 379754178 : if (!COMPLETE_TYPE_P (t))
7668 : 0 : layout_type (t);
7669 : : return t;
7670 : : }
7671 : :
7672 : : /* Build a function type. The RETURN_TYPE is the type returned by the
7673 : : function. If VAARGS is set, no void_type_node is appended to the
7674 : : list. ARGP must be always be terminated be a NULL_TREE. */
7675 : :
7676 : : static tree
7677 : 14477396 : build_function_type_list_1 (bool vaargs, tree return_type, va_list argp)
7678 : : {
7679 : 14477396 : tree t, args, last;
7680 : :
7681 : 14477396 : t = va_arg (argp, tree);
7682 : 61163381 : for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree))
7683 : 32208589 : args = tree_cons (NULL_TREE, t, args);
7684 : :
7685 : 14477396 : if (vaargs)
7686 : : {
7687 : 819015 : last = args;
7688 : 819015 : if (args != NULL_TREE)
7689 : 694317 : args = nreverse (args);
7690 : 819015 : gcc_assert (last != void_list_node);
7691 : : }
7692 : 13658381 : else if (args == NULL_TREE)
7693 : 1121943 : args = void_list_node;
7694 : : else
7695 : : {
7696 : 12536438 : last = args;
7697 : 12536438 : args = nreverse (args);
7698 : 12536438 : TREE_CHAIN (last) = void_list_node;
7699 : : }
7700 : 14477396 : args = build_function_type (return_type, args, vaargs && args == NULL_TREE);
7701 : :
7702 : 14477396 : return args;
7703 : : }
7704 : :
7705 : : /* Build a function type. The RETURN_TYPE is the type returned by the
7706 : : function. If additional arguments are provided, they are
7707 : : additional argument types. The list of argument types must always
7708 : : be terminated by NULL_TREE. */
7709 : :
7710 : : tree
7711 : 13658381 : build_function_type_list (tree return_type, ...)
7712 : : {
7713 : 13658381 : tree args;
7714 : 13658381 : va_list p;
7715 : :
7716 : 13658381 : va_start (p, return_type);
7717 : 13658381 : args = build_function_type_list_1 (false, return_type, p);
7718 : 13658381 : va_end (p);
7719 : 13658381 : return args;
7720 : : }
7721 : :
7722 : : /* Build a variable argument function type. The RETURN_TYPE is the
7723 : : type returned by the function. If additional arguments are provided,
7724 : : they are additional argument types. The list of argument types must
7725 : : always be terminated by NULL_TREE. */
7726 : :
7727 : : tree
7728 : 819015 : build_varargs_function_type_list (tree return_type, ...)
7729 : : {
7730 : 819015 : tree args;
7731 : 819015 : va_list p;
7732 : :
7733 : 819015 : va_start (p, return_type);
7734 : 819015 : args = build_function_type_list_1 (true, return_type, p);
7735 : 819015 : va_end (p);
7736 : :
7737 : 819015 : return args;
7738 : : }
7739 : :
7740 : : /* Build a function type. RETURN_TYPE is the type returned by the
7741 : : function; VAARGS indicates whether the function takes varargs. The
7742 : : function takes N named arguments, the types of which are provided in
7743 : : ARG_TYPES. */
7744 : :
7745 : : static tree
7746 : 114293970 : build_function_type_array_1 (bool vaargs, tree return_type, int n,
7747 : : tree *arg_types)
7748 : : {
7749 : 114293970 : int i;
7750 : 114293970 : tree t = vaargs ? NULL_TREE : void_list_node;
7751 : :
7752 : 372639810 : for (i = n - 1; i >= 0; i--)
7753 : 258345840 : t = tree_cons (NULL_TREE, arg_types[i], t);
7754 : :
7755 : 114293970 : return build_function_type (return_type, t, vaargs && n == 0);
7756 : : }
7757 : :
7758 : : /* Build a function type. RETURN_TYPE is the type returned by the
7759 : : function. The function takes N named arguments, the types of which
7760 : : are provided in ARG_TYPES. */
7761 : :
7762 : : tree
7763 : 108111183 : build_function_type_array (tree return_type, int n, tree *arg_types)
7764 : : {
7765 : 108111183 : return build_function_type_array_1 (false, return_type, n, arg_types);
7766 : : }
7767 : :
7768 : : /* Build a variable argument function type. RETURN_TYPE is the type
7769 : : returned by the function. The function takes N named arguments, the
7770 : : types of which are provided in ARG_TYPES. */
7771 : :
7772 : : tree
7773 : 6182787 : build_varargs_function_type_array (tree return_type, int n, tree *arg_types)
7774 : : {
7775 : 6182787 : return build_function_type_array_1 (true, return_type, n, arg_types);
7776 : : }
7777 : :
7778 : : /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
7779 : : and ARGTYPES (a TREE_LIST) are the return type and arguments types
7780 : : for the method. An implicit additional parameter (of type
7781 : : pointer-to-BASETYPE) is added to the ARGTYPES. */
7782 : :
7783 : : tree
7784 : 268529827 : build_method_type_directly (tree basetype,
7785 : : tree rettype,
7786 : : tree argtypes)
7787 : : {
7788 : 268529827 : tree t;
7789 : 268529827 : tree ptype;
7790 : 268529827 : bool any_structural_p, any_noncanonical_p;
7791 : 268529827 : tree canon_argtypes;
7792 : :
7793 : : /* Make a node of the sort we want. */
7794 : 268529827 : t = make_node (METHOD_TYPE);
7795 : :
7796 : 268529827 : TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7797 : 268529827 : TREE_TYPE (t) = rettype;
7798 : 268529827 : ptype = build_pointer_type (basetype);
7799 : :
7800 : : /* The actual arglist for this function includes a "hidden" argument
7801 : : which is "this". Put it into the list of argument types. */
7802 : 268529827 : argtypes = tree_cons (NULL_TREE, ptype, argtypes);
7803 : 268529827 : TYPE_ARG_TYPES (t) = argtypes;
7804 : :
7805 : : /* Set up the canonical type. */
7806 : 268529827 : any_structural_p
7807 : 268529827 : = (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7808 : 268529827 : || TYPE_STRUCTURAL_EQUALITY_P (rettype));
7809 : 268529827 : any_noncanonical_p
7810 : 268529827 : = (TYPE_CANONICAL (basetype) != basetype
7811 : 268529827 : || TYPE_CANONICAL (rettype) != rettype);
7812 : 268529827 : canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes),
7813 : : &any_structural_p,
7814 : : &any_noncanonical_p);
7815 : :
7816 : : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7817 : 268529827 : if (any_structural_p)
7818 : 21601886 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7819 : :
7820 : : /* If we already have such a type, use the old one. */
7821 : 268529827 : hashval_t hash = type_hash_canon_hash (t);
7822 : 268529827 : tree probe_type = t;
7823 : 268529827 : t = type_hash_canon (hash, t);
7824 : 268529827 : if (t != probe_type)
7825 : : return t;
7826 : :
7827 : 203841109 : if (any_structural_p)
7828 : 17886058 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7829 : 185955051 : else if (any_noncanonical_p)
7830 : 139027768 : TYPE_CANONICAL (t)
7831 : 69513884 : = build_method_type_directly (TYPE_CANONICAL (basetype),
7832 : 69513884 : TYPE_CANONICAL (rettype),
7833 : : canon_argtypes);
7834 : 203841109 : if (!COMPLETE_TYPE_P (t))
7835 : 0 : layout_type (t);
7836 : :
7837 : : return t;
7838 : : }
7839 : :
7840 : : /* Construct, lay out and return the type of methods belonging to class
7841 : : BASETYPE and whose arguments and values are described by TYPE.
7842 : : If that type exists already, reuse it.
7843 : : TYPE must be a FUNCTION_TYPE node. */
7844 : :
7845 : : tree
7846 : 155 : build_method_type (tree basetype, tree type)
7847 : : {
7848 : 155 : gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
7849 : :
7850 : 155 : return build_method_type_directly (basetype,
7851 : 155 : TREE_TYPE (type),
7852 : 155 : TYPE_ARG_TYPES (type));
7853 : : }
7854 : :
7855 : : /* Construct, lay out and return the type of offsets to a value
7856 : : of type TYPE, within an object of type BASETYPE.
7857 : : If a suitable offset type exists already, reuse it. */
7858 : :
7859 : : tree
7860 : 958351 : build_offset_type (tree basetype, tree type)
7861 : : {
7862 : 958351 : tree t;
7863 : :
7864 : : /* Make a node of the sort we want. */
7865 : 958351 : t = make_node (OFFSET_TYPE);
7866 : :
7867 : 958351 : TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7868 : 958351 : TREE_TYPE (t) = type;
7869 : 958351 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7870 : 958351 : || TYPE_STRUCTURAL_EQUALITY_P (type))
7871 : 4 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7872 : :
7873 : : /* If we already have such a type, use the old one. */
7874 : 958351 : hashval_t hash = type_hash_canon_hash (t);
7875 : 958351 : tree probe_type = t;
7876 : 958351 : t = type_hash_canon (hash, t);
7877 : 958351 : if (t != probe_type)
7878 : : return t;
7879 : :
7880 : 188766 : if (!COMPLETE_TYPE_P (t))
7881 : 0 : layout_type (t);
7882 : :
7883 : 188766 : if (TYPE_CANONICAL (t) == t)
7884 : : {
7885 : 188762 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7886 : 188762 : || TYPE_STRUCTURAL_EQUALITY_P (type))
7887 : 0 : gcc_unreachable ();
7888 : 188762 : else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
7889 : 188762 : || TYPE_CANONICAL (type) != type)
7890 : 223186 : TYPE_CANONICAL (t)
7891 : 111593 : = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
7892 : 111593 : TYPE_CANONICAL (type));
7893 : : }
7894 : :
7895 : : return t;
7896 : : }
7897 : :
7898 : : /* Create a complex type whose components are COMPONENT_TYPE.
7899 : :
7900 : : If NAMED is true, the type is given a TYPE_NAME. We do not always
7901 : : do so because this creates a DECL node and thus make the DECL_UIDs
7902 : : dependent on the type canonicalization hashtable, which is GC-ed,
7903 : : so the DECL_UIDs would not be stable wrt garbage collection. */
7904 : :
7905 : : tree
7906 : 5050207 : build_complex_type (tree component_type, bool named)
7907 : : {
7908 : 5050207 : gcc_assert (INTEGRAL_TYPE_P (component_type)
7909 : : || SCALAR_FLOAT_TYPE_P (component_type)
7910 : : || FIXED_POINT_TYPE_P (component_type));
7911 : :
7912 : : /* Make a node of the sort we want. */
7913 : 5050207 : tree probe = make_node (COMPLEX_TYPE);
7914 : :
7915 : 5050207 : TREE_TYPE (probe) = TYPE_MAIN_VARIANT (component_type);
7916 : 5050207 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (probe)))
7917 : 0 : SET_TYPE_STRUCTURAL_EQUALITY (probe);
7918 : :
7919 : : /* If we already have such a type, use the old one. */
7920 : 5050207 : hashval_t hash = type_hash_canon_hash (probe);
7921 : 5050207 : tree t = type_hash_canon (hash, probe);
7922 : :
7923 : 5050207 : if (t == probe)
7924 : : {
7925 : : /* We created a new type. The hash insertion will have laid
7926 : : out the type. We need to check the canonicalization and
7927 : : maybe set the name. */
7928 : 3064616 : gcc_checking_assert (COMPLETE_TYPE_P (t)
7929 : : && !TYPE_NAME (t));
7930 : :
7931 : 3064616 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t)))
7932 : : ;
7933 : 3064616 : else if (TYPE_CANONICAL (TREE_TYPE (t)) != TREE_TYPE (t))
7934 : 194 : TYPE_CANONICAL (t)
7935 : 97 : = build_complex_type (TYPE_CANONICAL (TREE_TYPE (t)), named);
7936 : :
7937 : : /* We need to create a name, since complex is a fundamental type. */
7938 : 3064616 : if (named)
7939 : : {
7940 : 1130272 : const char *name = NULL;
7941 : :
7942 : 1130272 : if (TREE_TYPE (t) == char_type_node)
7943 : : name = "complex char";
7944 : 1130272 : else if (TREE_TYPE (t) == signed_char_type_node)
7945 : : name = "complex signed char";
7946 : 1130272 : else if (TREE_TYPE (t) == unsigned_char_type_node)
7947 : : name = "complex unsigned char";
7948 : 1130272 : else if (TREE_TYPE (t) == short_integer_type_node)
7949 : : name = "complex short int";
7950 : 1130272 : else if (TREE_TYPE (t) == short_unsigned_type_node)
7951 : : name = "complex short unsigned int";
7952 : 1130272 : else if (TREE_TYPE (t) == integer_type_node)
7953 : : name = "complex int";
7954 : 847704 : else if (TREE_TYPE (t) == unsigned_type_node)
7955 : : name = "complex unsigned int";
7956 : 847704 : else if (TREE_TYPE (t) == long_integer_type_node)
7957 : : name = "complex long int";
7958 : 847704 : else if (TREE_TYPE (t) == long_unsigned_type_node)
7959 : : name = "complex long unsigned int";
7960 : 847704 : else if (TREE_TYPE (t) == long_long_integer_type_node)
7961 : : name = "complex long long int";
7962 : 847704 : else if (TREE_TYPE (t) == long_long_unsigned_type_node)
7963 : : name = "complex long long unsigned int";
7964 : :
7965 : : if (name != NULL)
7966 : 282568 : TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
7967 : : get_identifier (name), t);
7968 : : }
7969 : : }
7970 : :
7971 : 5050207 : return build_qualified_type (t, TYPE_QUALS (component_type));
7972 : : }
7973 : :
7974 : : /* If TYPE is a real or complex floating-point type and the target
7975 : : does not directly support arithmetic on TYPE then return the wider
7976 : : type to be used for arithmetic on TYPE. Otherwise, return
7977 : : NULL_TREE. */
7978 : :
7979 : : tree
7980 : 88773058 : excess_precision_type (tree type)
7981 : : {
7982 : : /* The target can give two different responses to the question of
7983 : : which excess precision mode it would like depending on whether we
7984 : : are in -fexcess-precision=standard or -fexcess-precision=fast. */
7985 : :
7986 : 177546116 : enum excess_precision_type requested_type
7987 : 88773058 : = (flag_excess_precision == EXCESS_PRECISION_FAST
7988 : 88773058 : ? EXCESS_PRECISION_TYPE_FAST
7989 : : : (flag_excess_precision == EXCESS_PRECISION_FLOAT16
7990 : 3234637 : ? EXCESS_PRECISION_TYPE_FLOAT16 : EXCESS_PRECISION_TYPE_STANDARD));
7991 : :
7992 : 88773058 : enum flt_eval_method target_flt_eval_method
7993 : 88773058 : = targetm.c.excess_precision (requested_type);
7994 : :
7995 : : /* The target should not ask for unpredictable float evaluation (though
7996 : : it might advertise that implicitly the evaluation is unpredictable,
7997 : : but we don't care about that here, it will have been reported
7998 : : elsewhere). If it does ask for unpredictable evaluation, we have
7999 : : nothing to do here. */
8000 : 88773058 : gcc_assert (target_flt_eval_method != FLT_EVAL_METHOD_UNPREDICTABLE);
8001 : :
8002 : : /* Nothing to do. The target has asked for all types we know about
8003 : : to be computed with their native precision and range. */
8004 : 88773058 : if (target_flt_eval_method == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
8005 : : return NULL_TREE;
8006 : :
8007 : : /* The target will promote this type in a target-dependent way, so excess
8008 : : precision ought to leave it alone. */
8009 : 87371624 : if (targetm.promoted_type (type) != NULL_TREE)
8010 : : return NULL_TREE;
8011 : :
8012 : 87371624 : machine_mode float16_type_mode = (float16_type_node
8013 : 87371624 : ? TYPE_MODE (float16_type_node)
8014 : 87371624 : : VOIDmode);
8015 : 87371624 : machine_mode bfloat16_type_mode = (bfloat16_type_node
8016 : 87371624 : ? TYPE_MODE (bfloat16_type_node)
8017 : 87371624 : : VOIDmode);
8018 : 87371624 : machine_mode float_type_mode = TYPE_MODE (float_type_node);
8019 : 87371624 : machine_mode double_type_mode = TYPE_MODE (double_type_node);
8020 : :
8021 : 87371624 : switch (TREE_CODE (type))
8022 : : {
8023 : 60205731 : case REAL_TYPE:
8024 : 60205731 : {
8025 : 60205731 : machine_mode type_mode = TYPE_MODE (type);
8026 : 60205731 : switch (target_flt_eval_method)
8027 : : {
8028 : 60192898 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8029 : 60192898 : if (type_mode == float16_type_mode
8030 : 60192898 : || type_mode == bfloat16_type_mode)
8031 : 251917 : return float_type_node;
8032 : : break;
8033 : 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8034 : 0 : if (type_mode == float16_type_mode
8035 : 0 : || type_mode == bfloat16_type_mode
8036 : 0 : || type_mode == float_type_mode)
8037 : 0 : return double_type_node;
8038 : : break;
8039 : 12833 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8040 : 12833 : if (type_mode == float16_type_mode
8041 : 12833 : || type_mode == bfloat16_type_mode
8042 : 12828 : || type_mode == float_type_mode
8043 : 12828 : || type_mode == double_type_mode)
8044 : 12384 : return long_double_type_node;
8045 : : break;
8046 : 0 : default:
8047 : 0 : gcc_unreachable ();
8048 : : }
8049 : : break;
8050 : : }
8051 : 379835 : case COMPLEX_TYPE:
8052 : 379835 : {
8053 : 379835 : if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
8054 : : return NULL_TREE;
8055 : 370355 : machine_mode type_mode = TYPE_MODE (TREE_TYPE (type));
8056 : 370355 : switch (target_flt_eval_method)
8057 : : {
8058 : 370022 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8059 : 370022 : if (type_mode == float16_type_mode
8060 : 370022 : || type_mode == bfloat16_type_mode)
8061 : 271 : return complex_float_type_node;
8062 : : break;
8063 : 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8064 : 0 : if (type_mode == float16_type_mode
8065 : 0 : || type_mode == bfloat16_type_mode
8066 : 0 : || type_mode == float_type_mode)
8067 : 0 : return complex_double_type_node;
8068 : : break;
8069 : 333 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8070 : 333 : if (type_mode == float16_type_mode
8071 : 333 : || type_mode == bfloat16_type_mode
8072 : 333 : || type_mode == float_type_mode
8073 : 333 : || type_mode == double_type_mode)
8074 : 281 : return complex_long_double_type_node;
8075 : : break;
8076 : 0 : default:
8077 : 0 : gcc_unreachable ();
8078 : : }
8079 : : break;
8080 : : }
8081 : : default:
8082 : : break;
8083 : : }
8084 : :
8085 : : return NULL_TREE;
8086 : : }
8087 : :
8088 : : /* Return OP, stripped of any conversions to wider types as much as is safe.
8089 : : Converting the value back to OP's type makes a value equivalent to OP.
8090 : :
8091 : : If FOR_TYPE is nonzero, we return a value which, if converted to
8092 : : type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8093 : :
8094 : : OP must have integer, real or enumeral type. Pointers are not allowed!
8095 : :
8096 : : There are some cases where the obvious value we could return
8097 : : would regenerate to OP if converted to OP's type,
8098 : : but would not extend like OP to wider types.
8099 : : If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8100 : : For example, if OP is (unsigned short)(signed char)-1,
8101 : : we avoid returning (signed char)-1 if FOR_TYPE is int,
8102 : : even though extending that to an unsigned short would regenerate OP,
8103 : : since the result of extending (signed char)-1 to (int)
8104 : : is different from (int) OP. */
8105 : :
8106 : : tree
8107 : 10049860 : get_unwidened (tree op, tree for_type)
8108 : : {
8109 : : /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8110 : 10049860 : tree type = TREE_TYPE (op);
8111 : 10049860 : unsigned final_prec
8112 : 17469209 : = TYPE_PRECISION (for_type != 0 ? for_type : type);
8113 : 10049860 : int uns
8114 : 10049860 : = (for_type != 0 && for_type != type
8115 : 2374884 : && final_prec > TYPE_PRECISION (type)
8116 : 10111482 : && TYPE_UNSIGNED (type));
8117 : 10049860 : tree win = op;
8118 : :
8119 : 10238167 : while (CONVERT_EXPR_P (op))
8120 : : {
8121 : 188336 : int bitschange;
8122 : :
8123 : : /* TYPE_PRECISION on vector types has different meaning
8124 : : (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8125 : : so avoid them here. */
8126 : 188336 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
8127 : : break;
8128 : :
8129 : 188336 : bitschange = TYPE_PRECISION (TREE_TYPE (op))
8130 : 188336 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
8131 : :
8132 : : /* Truncations are many-one so cannot be removed.
8133 : : Unless we are later going to truncate down even farther. */
8134 : 188336 : if (bitschange < 0
8135 : 188336 : && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
8136 : : break;
8137 : :
8138 : : /* See what's inside this conversion. If we decide to strip it,
8139 : : we will set WIN. */
8140 : 188307 : op = TREE_OPERAND (op, 0);
8141 : :
8142 : : /* If we have not stripped any zero-extensions (uns is 0),
8143 : : we can strip any kind of extension.
8144 : : If we have previously stripped a zero-extension,
8145 : : only zero-extensions can safely be stripped.
8146 : : Any extension can be stripped if the bits it would produce
8147 : : are all going to be discarded later by truncating to FOR_TYPE. */
8148 : :
8149 : 188307 : if (bitschange > 0)
8150 : : {
8151 : 103571 : if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
8152 : : win = op;
8153 : : /* TYPE_UNSIGNED says whether this is a zero-extension.
8154 : : Let's avoid computing it if it does not affect WIN
8155 : : and if UNS will not be needed again. */
8156 : 103571 : if ((uns
8157 : 103540 : || CONVERT_EXPR_P (op))
8158 : 104105 : && TYPE_UNSIGNED (TREE_TYPE (op)))
8159 : : {
8160 : : uns = 1;
8161 : : win = op;
8162 : : }
8163 : : }
8164 : : }
8165 : :
8166 : : /* If we finally reach a constant see if it fits in sth smaller and
8167 : : in that case convert it. */
8168 : 10049860 : if (TREE_CODE (win) == INTEGER_CST)
8169 : : {
8170 : 422509 : tree wtype = TREE_TYPE (win);
8171 : 422509 : unsigned prec = wi::min_precision (wi::to_wide (win), TYPE_SIGN (wtype));
8172 : 422509 : if (for_type)
8173 : 418125 : prec = MAX (prec, final_prec);
8174 : 422509 : if (prec < TYPE_PRECISION (wtype))
8175 : : {
8176 : 421153 : tree t = lang_hooks.types.type_for_size (prec, TYPE_UNSIGNED (wtype));
8177 : 421153 : if (t && TYPE_PRECISION (t) < TYPE_PRECISION (wtype))
8178 : 416196 : win = fold_convert (t, win);
8179 : : }
8180 : : }
8181 : :
8182 : 10049860 : return win;
8183 : : }
8184 : :
8185 : : /* Return OP or a simpler expression for a narrower value
8186 : : which can be sign-extended or zero-extended to give back OP.
8187 : : Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8188 : : or 0 if the value should be sign-extended. */
8189 : :
8190 : : tree
8191 : 61272744 : get_narrower (tree op, int *unsignedp_ptr)
8192 : : {
8193 : 61272744 : int uns = 0;
8194 : 61272744 : bool first = true;
8195 : 61272744 : tree win = op;
8196 : 61272744 : bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
8197 : :
8198 : 61272744 : if (TREE_CODE (op) == COMPOUND_EXPR)
8199 : : {
8200 : 81579 : do
8201 : 81579 : op = TREE_OPERAND (op, 1);
8202 : 81579 : while (TREE_CODE (op) == COMPOUND_EXPR);
8203 : 81564 : tree ret = get_narrower (op, unsignedp_ptr);
8204 : 81564 : if (ret == op)
8205 : : return win;
8206 : 4264 : auto_vec <tree, 16> v;
8207 : 4264 : unsigned int i;
8208 : 8535 : for (op = win; TREE_CODE (op) == COMPOUND_EXPR;
8209 : 4271 : op = TREE_OPERAND (op, 1))
8210 : 4271 : v.safe_push (op);
8211 : 12799 : FOR_EACH_VEC_ELT_REVERSE (v, i, op)
8212 : 4271 : ret = build2_loc (EXPR_LOCATION (op), COMPOUND_EXPR,
8213 : 4271 : TREE_TYPE (ret), TREE_OPERAND (op, 0),
8214 : : ret);
8215 : 4264 : return ret;
8216 : 4264 : }
8217 : 73058801 : while (TREE_CODE (op) == NOP_EXPR)
8218 : : {
8219 : 11900451 : int bitschange
8220 : 11900451 : = (TYPE_PRECISION (TREE_TYPE (op))
8221 : 11900451 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
8222 : :
8223 : : /* Truncations are many-one so cannot be removed. */
8224 : 11900451 : if (bitschange < 0)
8225 : : break;
8226 : :
8227 : : /* See what's inside this conversion. If we decide to strip it,
8228 : : we will set WIN. */
8229 : :
8230 : 11867717 : if (bitschange > 0)
8231 : : {
8232 : 2442099 : op = TREE_OPERAND (op, 0);
8233 : : /* An extension: the outermost one can be stripped,
8234 : : but remember whether it is zero or sign extension. */
8235 : 2442099 : if (first)
8236 : 2441625 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8237 : : /* Otherwise, if a sign extension has been stripped,
8238 : : only sign extensions can now be stripped;
8239 : : if a zero extension has been stripped, only zero-extensions. */
8240 : 474 : else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
8241 : : break;
8242 : : first = false;
8243 : : }
8244 : : else /* bitschange == 0 */
8245 : : {
8246 : : /* A change in nominal type can always be stripped, but we must
8247 : : preserve the unsignedness. */
8248 : 9425618 : if (first)
8249 : 8913930 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8250 : 9425618 : first = false;
8251 : 9425618 : op = TREE_OPERAND (op, 0);
8252 : : /* Keep trying to narrow, but don't assign op to win if it
8253 : : would turn an integral type into something else. */
8254 : 17131645 : if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
8255 : 99061 : continue;
8256 : : }
8257 : :
8258 : 11768560 : win = op;
8259 : : }
8260 : :
8261 : 61191180 : if (TREE_CODE (op) == COMPONENT_REF
8262 : : /* Since type_for_size always gives an integer type. */
8263 : 1881623 : && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
8264 : 1780260 : && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE
8265 : : /* Ensure field is laid out already. */
8266 : 1780260 : && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
8267 : 62971440 : && tree_fits_uhwi_p (DECL_SIZE (TREE_OPERAND (op, 1))))
8268 : : {
8269 : 1780260 : unsigned HOST_WIDE_INT innerprec
8270 : 1780260 : = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (op, 1)));
8271 : 1780260 : int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
8272 : 1780260 : || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
8273 : 1780260 : tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
8274 : :
8275 : : /* We can get this structure field in a narrower type that fits it,
8276 : : but the resulting extension to its nominal type (a fullword type)
8277 : : must satisfy the same conditions as for other extensions.
8278 : :
8279 : : Do this only for fields that are aligned (not bit-fields),
8280 : : because when bit-field insns will be used there is no
8281 : : advantage in doing this. */
8282 : :
8283 : 1780260 : if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
8284 : 0 : && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
8285 : 0 : && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
8286 : 1780260 : && type != 0)
8287 : : {
8288 : 0 : if (first)
8289 : 0 : uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
8290 : 0 : win = fold_convert (type, op);
8291 : : }
8292 : : }
8293 : :
8294 : 61191180 : *unsignedp_ptr = uns;
8295 : 61191180 : return win;
8296 : : }
8297 : :
8298 : : /* Return true if integer constant C has a value that is permissible
8299 : : for TYPE, an integral type. */
8300 : :
8301 : : bool
8302 : 110672202 : int_fits_type_p (const_tree c, const_tree type)
8303 : : {
8304 : 110672202 : tree type_low_bound, type_high_bound;
8305 : 110672202 : bool ok_for_low_bound, ok_for_high_bound;
8306 : 110672202 : signop sgn_c = TYPE_SIGN (TREE_TYPE (c));
8307 : :
8308 : : /* Non-standard boolean types can have arbitrary precision but various
8309 : : transformations assume that they can only take values 0 and +/-1. */
8310 : 110672202 : if (TREE_CODE (type) == BOOLEAN_TYPE)
8311 : 995070 : return wi::fits_to_boolean_p (wi::to_wide (c), type);
8312 : :
8313 : 109677132 : retry:
8314 : 109688957 : type_low_bound = TYPE_MIN_VALUE (type);
8315 : 109688957 : type_high_bound = TYPE_MAX_VALUE (type);
8316 : :
8317 : : /* If at least one bound of the type is a constant integer, we can check
8318 : : ourselves and maybe make a decision. If no such decision is possible, but
8319 : : this type is a subtype, try checking against that. Otherwise, use
8320 : : fits_to_tree_p, which checks against the precision.
8321 : :
8322 : : Compute the status for each possibly constant bound, and return if we see
8323 : : one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8324 : : for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8325 : : for "constant known to fit". */
8326 : :
8327 : : /* Check if c >= type_low_bound. */
8328 : 109688957 : if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
8329 : : {
8330 : 109688957 : if (tree_int_cst_lt (c, type_low_bound))
8331 : : return false;
8332 : : ok_for_low_bound = true;
8333 : : }
8334 : : else
8335 : : ok_for_low_bound = false;
8336 : :
8337 : : /* Check if c <= type_high_bound. */
8338 : 109442126 : if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
8339 : : {
8340 : 109410685 : if (tree_int_cst_lt (type_high_bound, c))
8341 : : return false;
8342 : : ok_for_high_bound = true;
8343 : : }
8344 : : else
8345 : : ok_for_high_bound = false;
8346 : :
8347 : : /* If the constant fits both bounds, the result is known. */
8348 : 107782105 : if (ok_for_low_bound && ok_for_high_bound)
8349 : : return true;
8350 : :
8351 : : /* Perform some generic filtering which may allow making a decision
8352 : : even if the bounds are not constant. First, negative integers
8353 : : never fit in unsigned types, */
8354 : 31441 : if (TYPE_UNSIGNED (type) && sgn_c == SIGNED && wi::neg_p (wi::to_wide (c)))
8355 : 0 : return false;
8356 : :
8357 : : /* Second, narrower types always fit in wider ones. */
8358 : 31441 : if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
8359 : : return true;
8360 : :
8361 : : /* Third, unsigned integers with top bit set never fit signed types. */
8362 : 11834 : if (!TYPE_UNSIGNED (type) && sgn_c == UNSIGNED)
8363 : : {
8364 : 14 : int prec = GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (c))) - 1;
8365 : 14 : if (prec < TYPE_PRECISION (TREE_TYPE (c)))
8366 : : {
8367 : : /* When a tree_cst is converted to a wide-int, the precision
8368 : : is taken from the type. However, if the precision of the
8369 : : mode underneath the type is smaller than that, it is
8370 : : possible that the value will not fit. The test below
8371 : : fails if any bit is set between the sign bit of the
8372 : : underlying mode and the top bit of the type. */
8373 : 14 : if (wi::zext (wi::to_wide (c), prec - 1) != wi::to_wide (c))
8374 : : return false;
8375 : : }
8376 : 0 : else if (wi::neg_p (wi::to_wide (c)))
8377 : : return false;
8378 : : }
8379 : :
8380 : : /* If we haven't been able to decide at this point, there nothing more we
8381 : : can check ourselves here. Look at the base type if we have one and it
8382 : : has the same precision. */
8383 : 11825 : if (TREE_CODE (type) == INTEGER_TYPE
8384 : 11825 : && TREE_TYPE (type) != 0
8385 : 23650 : && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
8386 : : {
8387 : 11825 : type = TREE_TYPE (type);
8388 : 11825 : goto retry;
8389 : : }
8390 : :
8391 : : /* Or to fits_to_tree_p, if nothing else. */
8392 : 0 : return wi::fits_to_tree_p (wi::to_wide (c), type);
8393 : : }
8394 : :
8395 : : /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8396 : : bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8397 : : represented (assuming two's-complement arithmetic) within the bit
8398 : : precision of the type are returned instead. */
8399 : :
8400 : : void
8401 : 19702660 : get_type_static_bounds (const_tree type, mpz_t min, mpz_t max)
8402 : : {
8403 : 18521231 : if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type)
8404 : 38223891 : && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
8405 : 18521231 : wi::to_mpz (wi::to_wide (TYPE_MIN_VALUE (type)), min, TYPE_SIGN (type));
8406 : : else
8407 : : {
8408 : 1181429 : if (TYPE_UNSIGNED (type))
8409 : 1181429 : mpz_set_ui (min, 0);
8410 : : else
8411 : : {
8412 : 0 : wide_int mn = wi::min_value (TYPE_PRECISION (type), SIGNED);
8413 : 0 : wi::to_mpz (mn, min, SIGNED);
8414 : 0 : }
8415 : : }
8416 : :
8417 : 18521231 : if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
8418 : 38223891 : && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
8419 : 18521231 : wi::to_mpz (wi::to_wide (TYPE_MAX_VALUE (type)), max, TYPE_SIGN (type));
8420 : : else
8421 : : {
8422 : 1181429 : wide_int mn = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
8423 : 1181429 : wi::to_mpz (mn, max, TYPE_SIGN (type));
8424 : 1181429 : }
8425 : 19702660 : }
8426 : :
8427 : : /* Return true if VAR is an automatic variable. */
8428 : :
8429 : : bool
8430 : 332507399 : auto_var_p (const_tree var)
8431 : : {
8432 : 177822510 : return ((((VAR_P (var) && ! DECL_EXTERNAL (var))
8433 : 157976532 : || TREE_CODE (var) == PARM_DECL)
8434 : 232131365 : && ! TREE_STATIC (var))
8435 : 441083073 : || TREE_CODE (var) == RESULT_DECL);
8436 : : }
8437 : :
8438 : : /* Return true if VAR is an automatic variable defined in function FN. */
8439 : :
8440 : : bool
8441 : 966065684 : auto_var_in_fn_p (const_tree var, const_tree fn)
8442 : : {
8443 : 299063879 : return (DECL_P (var) && DECL_CONTEXT (var) == fn
8444 : 1180667753 : && (auto_var_p (var)
8445 : 3970225 : || TREE_CODE (var) == LABEL_DECL));
8446 : : }
8447 : :
8448 : : /* Subprogram of following function. Called by walk_tree.
8449 : :
8450 : : Return *TP if it is an automatic variable or parameter of the
8451 : : function passed in as DATA. */
8452 : :
8453 : : static tree
8454 : 100491 : find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
8455 : : {
8456 : 100491 : tree fn = (tree) data;
8457 : :
8458 : 100491 : if (TYPE_P (*tp))
8459 : 0 : *walk_subtrees = 0;
8460 : :
8461 : 100491 : else if (DECL_P (*tp)
8462 : 100491 : && auto_var_in_fn_p (*tp, fn))
8463 : 92667 : return *tp;
8464 : :
8465 : : return NULL_TREE;
8466 : : }
8467 : :
8468 : : /* Returns true if T is, contains, or refers to a type with variable
8469 : : size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8470 : : arguments, but not the return type. If FN is nonzero, only return
8471 : : true if a modifier of the type or position of FN is a variable or
8472 : : parameter inside FN.
8473 : :
8474 : : This concept is more general than that of C99 'variably modified types':
8475 : : in C99, a struct type is never variably modified because a VLA may not
8476 : : appear as a structure member. However, in GNU C code like:
8477 : :
8478 : : struct S { int i[f()]; };
8479 : :
8480 : : is valid, and other languages may define similar constructs. */
8481 : :
8482 : : bool
8483 : 1655993571 : variably_modified_type_p (tree type, tree fn)
8484 : : {
8485 : 1655993571 : tree t;
8486 : :
8487 : : /* Test if T is either variable (if FN is zero) or an expression containing
8488 : : a variable in FN. If TYPE isn't gimplified, return true also if
8489 : : gimplify_one_sizepos would gimplify the expression into a local
8490 : : variable. */
8491 : : #define RETURN_TRUE_IF_VAR(T) \
8492 : : do { tree _t = (T); \
8493 : : if (_t != NULL_TREE \
8494 : : && _t != error_mark_node \
8495 : : && !CONSTANT_CLASS_P (_t) \
8496 : : && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8497 : : && (!fn \
8498 : : || (!TYPE_SIZES_GIMPLIFIED (type) \
8499 : : && (TREE_CODE (_t) != VAR_DECL \
8500 : : && !CONTAINS_PLACEHOLDER_P (_t))) \
8501 : : || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8502 : : return true; } while (0)
8503 : :
8504 : 1655993571 : if (type == error_mark_node)
8505 : : return false;
8506 : :
8507 : : /* If TYPE itself has variable size, it is variably modified. */
8508 : 1655768429 : RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
8509 : 1655664646 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
8510 : :
8511 : 1655664022 : switch (TREE_CODE (type))
8512 : : {
8513 : 466486420 : case POINTER_TYPE:
8514 : 466486420 : case REFERENCE_TYPE:
8515 : 466486420 : case VECTOR_TYPE:
8516 : : /* Ada can have pointer types refering to themselves indirectly. */
8517 : 466486420 : if (TREE_VISITED (type))
8518 : : return false;
8519 : 466486420 : TREE_VISITED (type) = true;
8520 : 466486420 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8521 : : {
8522 : 66747 : TREE_VISITED (type) = false;
8523 : 66747 : return true;
8524 : : }
8525 : 466419673 : TREE_VISITED (type) = false;
8526 : 466419673 : break;
8527 : :
8528 : 79275881 : case FUNCTION_TYPE:
8529 : 79275881 : case METHOD_TYPE:
8530 : : /* If TYPE is a function type, it is variably modified if the
8531 : : return type is variably modified. */
8532 : 79275881 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8533 : : return true;
8534 : : break;
8535 : :
8536 : 393223168 : case INTEGER_TYPE:
8537 : 393223168 : case REAL_TYPE:
8538 : 393223168 : case FIXED_POINT_TYPE:
8539 : 393223168 : case ENUMERAL_TYPE:
8540 : 393223168 : case BOOLEAN_TYPE:
8541 : : /* Scalar types are variably modified if their end points
8542 : : aren't constant. */
8543 : 393223168 : RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
8544 : 393223168 : RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
8545 : 393195433 : break;
8546 : :
8547 : 585343175 : case RECORD_TYPE:
8548 : 585343175 : case UNION_TYPE:
8549 : 585343175 : case QUAL_UNION_TYPE:
8550 : : /* We can't see if any of the fields are variably-modified by the
8551 : : definition we normally use, since that would produce infinite
8552 : : recursion via pointers. */
8553 : : /* This is variably modified if some field's type is. */
8554 : 26860038027 : for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
8555 : 26274694852 : if (TREE_CODE (t) == FIELD_DECL)
8556 : : {
8557 : 880365106 : RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
8558 : 880365106 : RETURN_TRUE_IF_VAR (DECL_SIZE (t));
8559 : 880365106 : RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
8560 : :
8561 : : /* If the type is a qualified union, then the DECL_QUALIFIER
8562 : : of fields can also be an expression containing a variable. */
8563 : 880365106 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
8564 : 0 : RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
8565 : :
8566 : : /* If the field is a qualified union, then it's only a container
8567 : : for what's inside so we look into it. That's necessary in LTO
8568 : : mode because the sizes of the field tested above have been set
8569 : : to PLACEHOLDER_EXPRs by free_lang_data. */
8570 : 880365106 : if (TREE_CODE (TREE_TYPE (t)) == QUAL_UNION_TYPE
8571 : 880365106 : && variably_modified_type_p (TREE_TYPE (t), fn))
8572 : : return true;
8573 : : }
8574 : : break;
8575 : :
8576 : 10416982 : case ARRAY_TYPE:
8577 : : /* Do not call ourselves to avoid infinite recursion. This is
8578 : : variably modified if the element type is. */
8579 : 10416982 : RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
8580 : 10413863 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
8581 : 10413845 : break;
8582 : :
8583 : : default:
8584 : : break;
8585 : : }
8586 : :
8587 : : /* The current language may have other cases to check, but in general,
8588 : : all other types are not variably modified. */
8589 : 1655566173 : return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
8590 : :
8591 : : #undef RETURN_TRUE_IF_VAR
8592 : : }
8593 : :
8594 : : /* Given a DECL or TYPE, return the scope in which it was declared, or
8595 : : NULL_TREE if there is no containing scope. */
8596 : :
8597 : : tree
8598 : 2108821403 : get_containing_scope (const_tree t)
8599 : : {
8600 : 2108821403 : return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
8601 : : }
8602 : :
8603 : : /* Returns the ultimate TRANSLATION_UNIT_DECL context of DECL or NULL. */
8604 : :
8605 : : const_tree
8606 : 14817 : get_ultimate_context (const_tree decl)
8607 : : {
8608 : 40825 : while (decl && TREE_CODE (decl) != TRANSLATION_UNIT_DECL)
8609 : : {
8610 : 26008 : if (TREE_CODE (decl) == BLOCK)
8611 : 0 : decl = BLOCK_SUPERCONTEXT (decl);
8612 : : else
8613 : 26008 : decl = get_containing_scope (decl);
8614 : : }
8615 : 14817 : return decl;
8616 : : }
8617 : :
8618 : : /* Return the innermost context enclosing DECL that is
8619 : : a FUNCTION_DECL, or zero if none. */
8620 : :
8621 : : tree
8622 : 1201979491 : decl_function_context (const_tree decl)
8623 : : {
8624 : 1201979491 : tree context;
8625 : :
8626 : 1201979491 : if (TREE_CODE (decl) == ERROR_MARK)
8627 : : return 0;
8628 : :
8629 : : /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8630 : : where we look up the function at runtime. Such functions always take
8631 : : a first argument of type 'pointer to real context'.
8632 : :
8633 : : C++ should really be fixed to use DECL_CONTEXT for the real context,
8634 : : and use something else for the "virtual context". */
8635 : 1201979491 : else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
8636 : 3924420 : context
8637 : 3924420 : = TYPE_MAIN_VARIANT
8638 : : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
8639 : : else
8640 : 1198055071 : context = DECL_CONTEXT (decl);
8641 : :
8642 : 2712660801 : while (context && TREE_CODE (context) != FUNCTION_DECL)
8643 : : {
8644 : 1510681310 : if (TREE_CODE (context) == BLOCK)
8645 : 0 : context = BLOCK_SUPERCONTEXT (context);
8646 : : else
8647 : 1510681310 : context = get_containing_scope (context);
8648 : : }
8649 : :
8650 : : return context;
8651 : : }
8652 : :
8653 : : /* Return the innermost context enclosing DECL that is
8654 : : a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8655 : : TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8656 : :
8657 : : tree
8658 : 48723903 : decl_type_context (const_tree decl)
8659 : : {
8660 : 48723903 : tree context = DECL_CONTEXT (decl);
8661 : :
8662 : 51060598 : while (context)
8663 : 45501119 : switch (TREE_CODE (context))
8664 : : {
8665 : : case NAMESPACE_DECL:
8666 : : case TRANSLATION_UNIT_DECL:
8667 : : return NULL_TREE;
8668 : :
8669 : : case RECORD_TYPE:
8670 : : case UNION_TYPE:
8671 : : case QUAL_UNION_TYPE:
8672 : : return context;
8673 : :
8674 : 2336695 : case TYPE_DECL:
8675 : 2336695 : case FUNCTION_DECL:
8676 : 2336695 : context = DECL_CONTEXT (context);
8677 : 2336695 : break;
8678 : :
8679 : 0 : case BLOCK:
8680 : 0 : context = BLOCK_SUPERCONTEXT (context);
8681 : 0 : break;
8682 : :
8683 : 0 : default:
8684 : 0 : gcc_unreachable ();
8685 : : }
8686 : :
8687 : : return NULL_TREE;
8688 : : }
8689 : :
8690 : : /* CALL is a CALL_EXPR. Return the declaration for the function
8691 : : called, or NULL_TREE if the called function cannot be
8692 : : determined. */
8693 : :
8694 : : tree
8695 : 872876556 : get_callee_fndecl (const_tree call)
8696 : : {
8697 : 872876556 : tree addr;
8698 : :
8699 : 872876556 : if (call == error_mark_node)
8700 : : return error_mark_node;
8701 : :
8702 : : /* It's invalid to call this function with anything but a
8703 : : CALL_EXPR. */
8704 : 872876556 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8705 : :
8706 : : /* The first operand to the CALL is the address of the function
8707 : : called. */
8708 : 872876556 : addr = CALL_EXPR_FN (call);
8709 : :
8710 : : /* If there is no function, return early. */
8711 : 872876556 : if (addr == NULL_TREE)
8712 : : return NULL_TREE;
8713 : :
8714 : 871455495 : STRIP_NOPS (addr);
8715 : :
8716 : : /* If this is a readonly function pointer, extract its initial value. */
8717 : 15542015 : if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
8718 : 1619571 : && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
8719 : 871595501 : && DECL_INITIAL (addr))
8720 : 139915 : addr = DECL_INITIAL (addr);
8721 : :
8722 : : /* If the address is just `&f' for some function `f', then we know
8723 : : that `f' is being called. */
8724 : 871455495 : if (TREE_CODE (addr) == ADDR_EXPR
8725 : 871455495 : && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
8726 : 833214161 : return TREE_OPERAND (addr, 0);
8727 : :
8728 : : /* We couldn't figure out what was being called. */
8729 : : return NULL_TREE;
8730 : : }
8731 : :
8732 : : /* Return true when STMTs arguments and return value match those of FNDECL,
8733 : : a decl of a builtin function. */
8734 : :
8735 : : static bool
8736 : 4984663 : tree_builtin_call_types_compatible_p (const_tree call, tree fndecl)
8737 : : {
8738 : 4984663 : gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN);
8739 : :
8740 : 4984663 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
8741 : 4984663 : if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
8742 : 4984663 : fndecl = decl;
8743 : :
8744 : 4984663 : bool gimple_form = (cfun && (cfun->curr_properties & PROP_gimple)) != 0;
8745 : 4984663 : if (gimple_form
8746 : 13024 : ? !useless_type_conversion_p (TREE_TYPE (call),
8747 : 13024 : TREE_TYPE (TREE_TYPE (fndecl)))
8748 : 4971639 : : (TYPE_MAIN_VARIANT (TREE_TYPE (call))
8749 : 4971639 : != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))))
8750 : : return false;
8751 : :
8752 : 4984447 : tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
8753 : 4984447 : unsigned nargs = call_expr_nargs (call);
8754 : 13398964 : for (unsigned i = 0; i < nargs; ++i, targs = TREE_CHAIN (targs))
8755 : : {
8756 : : /* Variadic args follow. */
8757 : 9269090 : if (!targs)
8758 : : return true;
8759 : 8415174 : tree arg = CALL_EXPR_ARG (call, i);
8760 : 8415174 : tree type = TREE_VALUE (targs);
8761 : 8415174 : if (gimple_form
8762 : 8415174 : ? !useless_type_conversion_p (type, TREE_TYPE (arg))
8763 : 8402150 : : TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (TREE_TYPE (arg)))
8764 : : {
8765 : : /* For pointer arguments be more forgiving, e.g. due to
8766 : : FILE * vs. fileptr_type_node, or say char * vs. const char *
8767 : : differences etc. */
8768 : 1227872 : if (!gimple_form
8769 : 674904 : && POINTER_TYPE_P (type)
8770 : 553073 : && POINTER_TYPE_P (TREE_TYPE (arg))
8771 : 1227872 : && tree_nop_conversion_p (type, TREE_TYPE (arg)))
8772 : 552968 : continue;
8773 : : /* char/short integral arguments are promoted to int
8774 : : by several frontends if targetm.calls.promote_prototypes
8775 : : is true. Allow such promotion too. */
8776 : 243215 : if (INTEGRAL_TYPE_P (type)
8777 : 121825 : && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)
8778 : 121279 : && INTEGRAL_TYPE_P (TREE_TYPE (arg))
8779 : 121279 : && !TYPE_UNSIGNED (TREE_TYPE (arg))
8780 : 121279 : && targetm.calls.promote_prototypes (TREE_TYPE (fndecl))
8781 : 243215 : && (gimple_form
8782 : 121279 : ? useless_type_conversion_p (integer_type_node,
8783 : 0 : TREE_TYPE (arg))
8784 : 121279 : : tree_nop_conversion_p (integer_type_node,
8785 : 121279 : TREE_TYPE (arg))))
8786 : 121279 : continue;
8787 : 657 : return false;
8788 : : }
8789 : : }
8790 : 8259101 : if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
8791 : : return false;
8792 : : return true;
8793 : : }
8794 : :
8795 : : /* If CALL_EXPR CALL calls a normal built-in function or an internal function,
8796 : : return the associated function code, otherwise return CFN_LAST. */
8797 : :
8798 : : combined_fn
8799 : 36241993 : get_call_combined_fn (const_tree call)
8800 : : {
8801 : : /* It's invalid to call this function with anything but a CALL_EXPR. */
8802 : 36241993 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8803 : :
8804 : 36241993 : if (!CALL_EXPR_FN (call))
8805 : 65673 : return as_combined_fn (CALL_EXPR_IFN (call));
8806 : :
8807 : 36176320 : tree fndecl = get_callee_fndecl (call);
8808 : 36176320 : if (fndecl
8809 : 36156086 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
8810 : 41160983 : && tree_builtin_call_types_compatible_p (call, fndecl))
8811 : 4983785 : return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
8812 : :
8813 : : return CFN_LAST;
8814 : : }
8815 : :
8816 : : /* Comparator of indices based on tree_node_counts. */
8817 : :
8818 : : static int
8819 : 0 : tree_nodes_cmp (const void *p1, const void *p2)
8820 : : {
8821 : 0 : const unsigned *n1 = (const unsigned *)p1;
8822 : 0 : const unsigned *n2 = (const unsigned *)p2;
8823 : :
8824 : 0 : return tree_node_counts[*n1] - tree_node_counts[*n2];
8825 : : }
8826 : :
8827 : : /* Comparator of indices based on tree_code_counts. */
8828 : :
8829 : : static int
8830 : 0 : tree_codes_cmp (const void *p1, const void *p2)
8831 : : {
8832 : 0 : const unsigned *n1 = (const unsigned *)p1;
8833 : 0 : const unsigned *n2 = (const unsigned *)p2;
8834 : :
8835 : 0 : return tree_code_counts[*n1] - tree_code_counts[*n2];
8836 : : }
8837 : :
8838 : : #define TREE_MEM_USAGE_SPACES 40
8839 : :
8840 : : /* Print debugging information about tree nodes generated during the compile,
8841 : : and any language-specific information. */
8842 : :
8843 : : void
8844 : 0 : dump_tree_statistics (void)
8845 : : {
8846 : 0 : if (GATHER_STATISTICS)
8847 : : {
8848 : : uint64_t total_nodes, total_bytes;
8849 : : fprintf (stderr, "\nKind Nodes Bytes\n");
8850 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8851 : : total_nodes = total_bytes = 0;
8852 : :
8853 : : {
8854 : : auto_vec<unsigned> indices (all_kinds);
8855 : : for (unsigned i = 0; i < all_kinds; i++)
8856 : : indices.quick_push (i);
8857 : : indices.qsort (tree_nodes_cmp);
8858 : :
8859 : : for (unsigned i = 0; i < (int) all_kinds; i++)
8860 : : {
8861 : : unsigned j = indices[i];
8862 : : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n",
8863 : : tree_node_kind_names[j], SIZE_AMOUNT (tree_node_counts[j]),
8864 : : SIZE_AMOUNT (tree_node_sizes[j]));
8865 : : total_nodes += tree_node_counts[j];
8866 : : total_bytes += tree_node_sizes[j];
8867 : : }
8868 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8869 : : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n", "Total",
8870 : : SIZE_AMOUNT (total_nodes), SIZE_AMOUNT (total_bytes));
8871 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8872 : : }
8873 : :
8874 : : {
8875 : : fprintf (stderr, "Code Nodes\n");
8876 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8877 : :
8878 : : auto_vec<unsigned> indices (MAX_TREE_CODES);
8879 : : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8880 : : indices.quick_push (i);
8881 : : indices.qsort (tree_codes_cmp);
8882 : :
8883 : : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8884 : : {
8885 : : unsigned j = indices[i];
8886 : : fprintf (stderr, "%-32s %6" PRIu64 "%c\n",
8887 : : get_tree_code_name ((enum tree_code) j),
8888 : : SIZE_AMOUNT (tree_code_counts[j]));
8889 : : }
8890 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8891 : : fprintf (stderr, "\n");
8892 : : ssanames_print_statistics ();
8893 : : fprintf (stderr, "\n");
8894 : : phinodes_print_statistics ();
8895 : : fprintf (stderr, "\n");
8896 : : }
8897 : : }
8898 : : else
8899 : 0 : fprintf (stderr, "(No per-node statistics)\n");
8900 : :
8901 : 0 : print_type_hash_statistics ();
8902 : 0 : print_debug_expr_statistics ();
8903 : 0 : print_value_expr_statistics ();
8904 : 0 : lang_hooks.print_statistics ();
8905 : 0 : }
8906 : :
8907 : : #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
8908 : :
8909 : : /* Generate a crc32 of the low BYTES bytes of VALUE. */
8910 : :
8911 : : unsigned
8912 : 15408647 : crc32_unsigned_n (unsigned chksum, unsigned value, unsigned bytes)
8913 : : {
8914 : : /* This relies on the raw feedback's top 4 bits being zero. */
8915 : : #define FEEDBACK(X) ((X) * 0x04c11db7)
8916 : : #define SYNDROME(X) (FEEDBACK ((X) & 1) ^ FEEDBACK ((X) & 2) \
8917 : : ^ FEEDBACK ((X) & 4) ^ FEEDBACK ((X) & 8))
8918 : 15408647 : static const unsigned syndromes[16] =
8919 : : {
8920 : : SYNDROME(0x0), SYNDROME(0x1), SYNDROME(0x2), SYNDROME(0x3),
8921 : : SYNDROME(0x4), SYNDROME(0x5), SYNDROME(0x6), SYNDROME(0x7),
8922 : : SYNDROME(0x8), SYNDROME(0x9), SYNDROME(0xa), SYNDROME(0xb),
8923 : : SYNDROME(0xc), SYNDROME(0xd), SYNDROME(0xe), SYNDROME(0xf),
8924 : : };
8925 : : #undef FEEDBACK
8926 : : #undef SYNDROME
8927 : :
8928 : 15408647 : value <<= (32 - bytes * 8);
8929 : 50910663 : for (unsigned ix = bytes * 2; ix--; value <<= 4)
8930 : : {
8931 : 35502016 : unsigned feedback = syndromes[((value ^ chksum) >> 28) & 0xf];
8932 : :
8933 : 35502016 : chksum = (chksum << 4) ^ feedback;
8934 : : }
8935 : :
8936 : 15408647 : return chksum;
8937 : : }
8938 : :
8939 : : /* Generate a crc32 of a string. */
8940 : :
8941 : : unsigned
8942 : 7670 : crc32_string (unsigned chksum, const char *string)
8943 : : {
8944 : 298155 : do
8945 : 298155 : chksum = crc32_byte (chksum, *string);
8946 : 298155 : while (*string++);
8947 : 7670 : return chksum;
8948 : : }
8949 : :
8950 : : /* P is a string that will be used in a symbol. Mask out any characters
8951 : : that are not valid in that context. */
8952 : :
8953 : : void
8954 : 7022 : clean_symbol_name (char *p)
8955 : : {
8956 : 79312 : for (; *p; p++)
8957 : 72290 : if (! (ISALNUM (*p)
8958 : : #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
8959 : : || *p == '$'
8960 : : #endif
8961 : : #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
8962 : : || *p == '.'
8963 : : #endif
8964 : : ))
8965 : 6519 : *p = '_';
8966 : 7022 : }
8967 : :
8968 : : static GTY(()) unsigned anon_cnt = 0; /* Saved for PCH. */
8969 : :
8970 : : /* Create a unique anonymous identifier. The identifier is still a
8971 : : valid assembly label. */
8972 : :
8973 : : tree
8974 : 2425674 : make_anon_name ()
8975 : : {
8976 : 2425674 : const char *fmt =
8977 : : #if !defined (NO_DOT_IN_LABEL)
8978 : : "."
8979 : : #elif !defined (NO_DOLLAR_IN_LABEL)
8980 : : "$"
8981 : : #else
8982 : : "_"
8983 : : #endif
8984 : : "_anon_%d";
8985 : :
8986 : 2425674 : char buf[24];
8987 : 2425674 : int len = snprintf (buf, sizeof (buf), fmt, anon_cnt++);
8988 : 2425674 : gcc_checking_assert (len < int (sizeof (buf)));
8989 : :
8990 : 2425674 : tree id = get_identifier_with_length (buf, len);
8991 : 2425674 : IDENTIFIER_ANON_P (id) = true;
8992 : :
8993 : 2425674 : return id;
8994 : : }
8995 : :
8996 : : /* Generate a name for a special-purpose function.
8997 : : The generated name may need to be unique across the whole link.
8998 : : Changes to this function may also require corresponding changes to
8999 : : xstrdup_mask_random.
9000 : : TYPE is some string to identify the purpose of this function to the
9001 : : linker or collect2; it must start with an uppercase letter,
9002 : : one of:
9003 : : I - for constructors
9004 : : D - for destructors
9005 : : N - for C++ anonymous namespaces
9006 : : F - for DWARF unwind frame information. */
9007 : :
9008 : : tree
9009 : 5102 : get_file_function_name (const char *type)
9010 : : {
9011 : 5102 : char *buf;
9012 : 5102 : const char *p;
9013 : 5102 : char *q;
9014 : :
9015 : : /* If we already have a name we know to be unique, just use that. */
9016 : 5102 : if (first_global_object_name)
9017 : 4816 : p = q = ASTRDUP (first_global_object_name);
9018 : : /* If the target is handling the constructors/destructors, they
9019 : : will be local to this file and the name is only necessary for
9020 : : debugging purposes.
9021 : : We also assign sub_I and sub_D sufixes to constructors called from
9022 : : the global static constructors. These are always local.
9023 : : OpenMP "declare target" offloaded constructors/destructors use "off_I" and
9024 : : "off_D" for the same purpose. */
9025 : 286 : else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
9026 : 572 : || ((startswith (type, "sub_") || startswith (type, "off_"))
9027 : 286 : && (type[4] == 'I' || type[4] == 'D')))
9028 : : {
9029 : 286 : const char *file = main_input_filename;
9030 : 286 : if (! file)
9031 : 0 : file = LOCATION_FILE (input_location);
9032 : : /* Just use the file's basename, because the full pathname
9033 : : might be quite long. */
9034 : 286 : p = q = ASTRDUP (lbasename (file));
9035 : : }
9036 : : else
9037 : : {
9038 : : /* Otherwise, the name must be unique across the entire link.
9039 : : We don't have anything that we know to be unique to this translation
9040 : : unit, so use what we do have and throw in some randomness. */
9041 : 0 : unsigned len;
9042 : 0 : const char *name = weak_global_object_name;
9043 : 0 : const char *file = main_input_filename;
9044 : :
9045 : 0 : if (! name)
9046 : 0 : name = "";
9047 : 0 : if (! file)
9048 : 0 : file = LOCATION_FILE (input_location);
9049 : :
9050 : 0 : len = strlen (file);
9051 : 0 : q = (char *) alloca (9 + 19 + len + 1);
9052 : 0 : memcpy (q, file, len + 1);
9053 : :
9054 : 0 : snprintf (q + len, 9 + 19 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX,
9055 : : crc32_string (0, name), get_random_seed (false));
9056 : :
9057 : 0 : p = q;
9058 : : }
9059 : :
9060 : 5102 : clean_symbol_name (q);
9061 : 5102 : buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
9062 : : + strlen (type));
9063 : :
9064 : : /* Set up the name of the file-level functions we may need.
9065 : : Use a global object (which is already required to be unique over
9066 : : the program) rather than the file name (which imposes extra
9067 : : constraints). */
9068 : 5102 : sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
9069 : :
9070 : 5102 : return get_identifier (buf);
9071 : : }
9072 : :
9073 : : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9074 : :
9075 : : /* Complain that the tree code of NODE does not match the expected 0
9076 : : terminated list of trailing codes. The trailing code list can be
9077 : : empty, for a more vague error message. FILE, LINE, and FUNCTION
9078 : : are of the caller. */
9079 : :
9080 : : void
9081 : 0 : tree_check_failed (const_tree node, const char *file,
9082 : : int line, const char *function, ...)
9083 : : {
9084 : 0 : va_list args;
9085 : 0 : const char *buffer;
9086 : 0 : unsigned length = 0;
9087 : 0 : enum tree_code code;
9088 : :
9089 : 0 : va_start (args, function);
9090 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9091 : 0 : length += 4 + strlen (get_tree_code_name (code));
9092 : 0 : va_end (args);
9093 : 0 : if (length)
9094 : : {
9095 : 0 : char *tmp;
9096 : 0 : va_start (args, function);
9097 : 0 : length += strlen ("expected ");
9098 : 0 : buffer = tmp = (char *) alloca (length);
9099 : 0 : length = 0;
9100 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9101 : : {
9102 : 0 : const char *prefix = length ? " or " : "expected ";
9103 : :
9104 : 0 : strcpy (tmp + length, prefix);
9105 : 0 : length += strlen (prefix);
9106 : 0 : strcpy (tmp + length, get_tree_code_name (code));
9107 : 0 : length += strlen (get_tree_code_name (code));
9108 : : }
9109 : 0 : va_end (args);
9110 : : }
9111 : : else
9112 : : buffer = "unexpected node";
9113 : :
9114 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9115 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9116 : : function, trim_filename (file), line);
9117 : : }
9118 : :
9119 : : /* Complain that the tree code of NODE does match the expected 0
9120 : : terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9121 : : the caller. */
9122 : :
9123 : : void
9124 : 0 : tree_not_check_failed (const_tree node, const char *file,
9125 : : int line, const char *function, ...)
9126 : : {
9127 : 0 : va_list args;
9128 : 0 : char *buffer;
9129 : 0 : unsigned length = 0;
9130 : 0 : enum tree_code code;
9131 : :
9132 : 0 : va_start (args, function);
9133 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9134 : 0 : length += 4 + strlen (get_tree_code_name (code));
9135 : 0 : va_end (args);
9136 : 0 : va_start (args, function);
9137 : 0 : buffer = (char *) alloca (length);
9138 : 0 : length = 0;
9139 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9140 : : {
9141 : 0 : if (length)
9142 : : {
9143 : 0 : strcpy (buffer + length, " or ");
9144 : 0 : length += 4;
9145 : : }
9146 : 0 : strcpy (buffer + length, get_tree_code_name (code));
9147 : 0 : length += strlen (get_tree_code_name (code));
9148 : : }
9149 : 0 : va_end (args);
9150 : :
9151 : 0 : internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9152 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9153 : : function, trim_filename (file), line);
9154 : : }
9155 : :
9156 : : /* Similar to tree_check_failed, except that we check for a class of tree
9157 : : code, given in CL. */
9158 : :
9159 : : void
9160 : 0 : tree_class_check_failed (const_tree node, const enum tree_code_class cl,
9161 : : const char *file, int line, const char *function)
9162 : : {
9163 : 0 : internal_error
9164 : 0 : ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9165 : 0 : TREE_CODE_CLASS_STRING (cl),
9166 : 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9167 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9168 : : }
9169 : :
9170 : : /* Similar to tree_check_failed, except that instead of specifying a
9171 : : dozen codes, use the knowledge that they're all sequential. */
9172 : :
9173 : : void
9174 : 0 : tree_range_check_failed (const_tree node, const char *file, int line,
9175 : : const char *function, enum tree_code c1,
9176 : : enum tree_code c2)
9177 : : {
9178 : 0 : char *buffer;
9179 : 0 : unsigned length = 0;
9180 : 0 : unsigned int c;
9181 : :
9182 : 0 : for (c = c1; c <= c2; ++c)
9183 : 0 : length += 4 + strlen (get_tree_code_name ((enum tree_code) c));
9184 : :
9185 : 0 : length += strlen ("expected ");
9186 : 0 : buffer = (char *) alloca (length);
9187 : 0 : length = 0;
9188 : :
9189 : 0 : for (c = c1; c <= c2; ++c)
9190 : : {
9191 : 0 : const char *prefix = length ? " or " : "expected ";
9192 : :
9193 : 0 : strcpy (buffer + length, prefix);
9194 : 0 : length += strlen (prefix);
9195 : 0 : strcpy (buffer + length, get_tree_code_name ((enum tree_code) c));
9196 : 0 : length += strlen (get_tree_code_name ((enum tree_code) c));
9197 : : }
9198 : :
9199 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9200 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9201 : : function, trim_filename (file), line);
9202 : : }
9203 : :
9204 : :
9205 : : /* Similar to tree_check_failed, except that we check that a tree does
9206 : : not have the specified code, given in CL. */
9207 : :
9208 : : void
9209 : 0 : tree_not_class_check_failed (const_tree node, const enum tree_code_class cl,
9210 : : const char *file, int line, const char *function)
9211 : : {
9212 : 0 : internal_error
9213 : 0 : ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9214 : 0 : TREE_CODE_CLASS_STRING (cl),
9215 : 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9216 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9217 : : }
9218 : :
9219 : :
9220 : : /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9221 : :
9222 : : void
9223 : 0 : omp_clause_check_failed (const_tree node, const char *file, int line,
9224 : : const char *function, enum omp_clause_code code)
9225 : : {
9226 : 0 : internal_error ("tree check: expected %<omp_clause %s%>, have %qs "
9227 : : "in %s, at %s:%d",
9228 : 0 : omp_clause_code_name[code],
9229 : 0 : get_tree_code_name (TREE_CODE (node)),
9230 : : function, trim_filename (file), line);
9231 : : }
9232 : :
9233 : :
9234 : : /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9235 : :
9236 : : void
9237 : 0 : omp_clause_range_check_failed (const_tree node, const char *file, int line,
9238 : : const char *function, enum omp_clause_code c1,
9239 : : enum omp_clause_code c2)
9240 : : {
9241 : 0 : char *buffer;
9242 : 0 : unsigned length = 0;
9243 : 0 : unsigned int c;
9244 : :
9245 : 0 : for (c = c1; c <= c2; ++c)
9246 : 0 : length += 4 + strlen (omp_clause_code_name[c]);
9247 : :
9248 : 0 : length += strlen ("expected ");
9249 : 0 : buffer = (char *) alloca (length);
9250 : 0 : length = 0;
9251 : :
9252 : 0 : for (c = c1; c <= c2; ++c)
9253 : : {
9254 : 0 : const char *prefix = length ? " or " : "expected ";
9255 : :
9256 : 0 : strcpy (buffer + length, prefix);
9257 : 0 : length += strlen (prefix);
9258 : 0 : strcpy (buffer + length, omp_clause_code_name[c]);
9259 : 0 : length += strlen (omp_clause_code_name[c]);
9260 : : }
9261 : :
9262 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9263 : 0 : buffer, omp_clause_code_name[TREE_CODE (node)],
9264 : : function, trim_filename (file), line);
9265 : : }
9266 : :
9267 : :
9268 : : #undef DEFTREESTRUCT
9269 : : #define DEFTREESTRUCT(VAL, NAME) NAME,
9270 : :
9271 : : static const char *ts_enum_names[] = {
9272 : : #include "treestruct.def"
9273 : : };
9274 : : #undef DEFTREESTRUCT
9275 : :
9276 : : #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9277 : :
9278 : : /* Similar to tree_class_check_failed, except that we check for
9279 : : whether CODE contains the tree structure identified by EN. */
9280 : :
9281 : : void
9282 : 0 : tree_contains_struct_check_failed (const_tree node,
9283 : : const enum tree_node_structure_enum en,
9284 : : const char *file, int line,
9285 : : const char *function)
9286 : : {
9287 : 0 : internal_error
9288 : 0 : ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9289 : 0 : TS_ENUM_NAME (en),
9290 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9291 : : }
9292 : :
9293 : :
9294 : : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9295 : : (dynamically sized) vector. */
9296 : :
9297 : : void
9298 : 0 : tree_int_cst_elt_check_failed (int idx, int len, const char *file, int line,
9299 : : const char *function)
9300 : : {
9301 : 0 : internal_error
9302 : 0 : ("tree check: accessed elt %d of %<tree_int_cst%> with %d elts in %s, "
9303 : : "at %s:%d",
9304 : : idx + 1, len, function, trim_filename (file), line);
9305 : : }
9306 : :
9307 : : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9308 : : (dynamically sized) vector. */
9309 : :
9310 : : void
9311 : 0 : tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
9312 : : const char *function)
9313 : : {
9314 : 0 : internal_error
9315 : 0 : ("tree check: accessed elt %d of %<tree_vec%> with %d elts in %s, at %s:%d",
9316 : : idx + 1, len, function, trim_filename (file), line);
9317 : : }
9318 : :
9319 : : /* Similar to above, except that the check is for the bounds of the operand
9320 : : vector of an expression node EXP. */
9321 : :
9322 : : void
9323 : 0 : tree_operand_check_failed (int idx, const_tree exp, const char *file,
9324 : : int line, const char *function)
9325 : : {
9326 : 0 : enum tree_code code = TREE_CODE (exp);
9327 : 0 : internal_error
9328 : 0 : ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9329 : : idx + 1, get_tree_code_name (code), TREE_OPERAND_LENGTH (exp),
9330 : : function, trim_filename (file), line);
9331 : : }
9332 : :
9333 : : /* Similar to above, except that the check is for the number of
9334 : : operands of an OMP_CLAUSE node. */
9335 : :
9336 : : void
9337 : 0 : omp_clause_operand_check_failed (int idx, const_tree t, const char *file,
9338 : : int line, const char *function)
9339 : : {
9340 : 0 : internal_error
9341 : 0 : ("tree check: accessed operand %d of %<omp_clause %s%> with %d operands "
9342 : 0 : "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
9343 : 0 : omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
9344 : : trim_filename (file), line);
9345 : : }
9346 : : #endif /* ENABLE_TREE_CHECKING */
9347 : :
9348 : : /* Create a new vector type node holding NUNITS units of type INNERTYPE,
9349 : : and mapped to the machine mode MODE. Initialize its fields and build
9350 : : the information necessary for debugging output. */
9351 : :
9352 : : static tree
9353 : 66051875 : make_vector_type (tree innertype, poly_int64 nunits, machine_mode mode)
9354 : : {
9355 : 66051875 : tree t;
9356 : 66051875 : tree mv_innertype = TYPE_MAIN_VARIANT (innertype);
9357 : :
9358 : 66051875 : t = make_node (VECTOR_TYPE);
9359 : 66051875 : TREE_TYPE (t) = mv_innertype;
9360 : 66051875 : SET_TYPE_VECTOR_SUBPARTS (t, nunits);
9361 : 66051875 : SET_TYPE_MODE (t, mode);
9362 : :
9363 : 66051875 : if (TYPE_STRUCTURAL_EQUALITY_P (mv_innertype) || in_lto_p)
9364 : 1235034 : SET_TYPE_STRUCTURAL_EQUALITY (t);
9365 : 64816841 : else if ((TYPE_CANONICAL (mv_innertype) != innertype
9366 : 61702196 : || mode != VOIDmode)
9367 : 93529768 : && !VECTOR_BOOLEAN_TYPE_P (t))
9368 : 60240122 : TYPE_CANONICAL (t)
9369 : 30120061 : = make_vector_type (TYPE_CANONICAL (mv_innertype), nunits, VOIDmode);
9370 : :
9371 : 66051875 : layout_type (t);
9372 : :
9373 : 66051875 : hashval_t hash = type_hash_canon_hash (t);
9374 : 66051875 : t = type_hash_canon (hash, t);
9375 : :
9376 : : /* We have built a main variant, based on the main variant of the
9377 : : inner type. Use it to build the variant we return. */
9378 : 132098778 : if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
9379 : 66711478 : && TREE_TYPE (t) != innertype)
9380 : 663428 : return build_type_attribute_qual_variant (t,
9381 : 663428 : TYPE_ATTRIBUTES (innertype),
9382 : 1326856 : TYPE_QUALS (innertype));
9383 : :
9384 : : return t;
9385 : : }
9386 : :
9387 : : static tree
9388 : 3948907 : make_or_reuse_type (unsigned size, int unsignedp)
9389 : : {
9390 : 3948907 : int i;
9391 : :
9392 : 3948907 : if (size == INT_TYPE_SIZE)
9393 : 847704 : return unsignedp ? unsigned_type_node : integer_type_node;
9394 : 3101203 : if (size == CHAR_TYPE_SIZE)
9395 : 565136 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
9396 : 2536067 : if (size == SHORT_TYPE_SIZE)
9397 : 847704 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
9398 : 1724200 : if (size == LONG_TYPE_SIZE)
9399 : 826263 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
9400 : 862100 : if (size == LONG_LONG_TYPE_SIZE)
9401 : 21441 : return (unsignedp ? long_long_unsigned_type_node
9402 : 21441 : : long_long_integer_type_node);
9403 : :
9404 : 854749 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9405 : 840659 : if (size == int_n_data[i].bitsize
9406 : 840659 : && int_n_enabled_p[i])
9407 : 826569 : return (unsignedp ? int_n_trees[i].unsigned_type
9408 : 826569 : : int_n_trees[i].signed_type);
9409 : :
9410 : 14090 : if (unsignedp)
9411 : 7045 : return make_unsigned_type (size);
9412 : : else
9413 : 7045 : return make_signed_type (size);
9414 : : }
9415 : :
9416 : : /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9417 : :
9418 : : static tree
9419 : 5651360 : make_or_reuse_fract_type (unsigned size, int unsignedp, int satp)
9420 : : {
9421 : 5651360 : if (satp)
9422 : : {
9423 : 2825680 : if (size == SHORT_FRACT_TYPE_SIZE)
9424 : 565136 : return unsignedp ? sat_unsigned_short_fract_type_node
9425 : 565136 : : sat_short_fract_type_node;
9426 : 2260544 : if (size == FRACT_TYPE_SIZE)
9427 : 565136 : return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node;
9428 : 1695408 : if (size == LONG_FRACT_TYPE_SIZE)
9429 : 565136 : return unsignedp ? sat_unsigned_long_fract_type_node
9430 : 565136 : : sat_long_fract_type_node;
9431 : 1130272 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9432 : 565136 : return unsignedp ? sat_unsigned_long_long_fract_type_node
9433 : 565136 : : sat_long_long_fract_type_node;
9434 : : }
9435 : : else
9436 : : {
9437 : 2825680 : if (size == SHORT_FRACT_TYPE_SIZE)
9438 : 565136 : return unsignedp ? unsigned_short_fract_type_node
9439 : 565136 : : short_fract_type_node;
9440 : 2260544 : if (size == FRACT_TYPE_SIZE)
9441 : 565136 : return unsignedp ? unsigned_fract_type_node : fract_type_node;
9442 : 1695408 : if (size == LONG_FRACT_TYPE_SIZE)
9443 : 565136 : return unsignedp ? unsigned_long_fract_type_node
9444 : 565136 : : long_fract_type_node;
9445 : 1130272 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9446 : 565136 : return unsignedp ? unsigned_long_long_fract_type_node
9447 : 565136 : : long_long_fract_type_node;
9448 : : }
9449 : :
9450 : 1130272 : return make_fract_type (size, unsignedp, satp);
9451 : : }
9452 : :
9453 : : /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9454 : :
9455 : : static tree
9456 : 4521088 : make_or_reuse_accum_type (unsigned size, int unsignedp, int satp)
9457 : : {
9458 : 4521088 : if (satp)
9459 : : {
9460 : 2260544 : if (size == SHORT_ACCUM_TYPE_SIZE)
9461 : 565136 : return unsignedp ? sat_unsigned_short_accum_type_node
9462 : 565136 : : sat_short_accum_type_node;
9463 : 1695408 : if (size == ACCUM_TYPE_SIZE)
9464 : 565136 : return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node;
9465 : 1130272 : if (size == LONG_ACCUM_TYPE_SIZE)
9466 : 565136 : return unsignedp ? sat_unsigned_long_accum_type_node
9467 : 565136 : : sat_long_accum_type_node;
9468 : 565136 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9469 : 565136 : return unsignedp ? sat_unsigned_long_long_accum_type_node
9470 : 565136 : : sat_long_long_accum_type_node;
9471 : : }
9472 : : else
9473 : : {
9474 : 2260544 : if (size == SHORT_ACCUM_TYPE_SIZE)
9475 : 565136 : return unsignedp ? unsigned_short_accum_type_node
9476 : 565136 : : short_accum_type_node;
9477 : 1695408 : if (size == ACCUM_TYPE_SIZE)
9478 : 565136 : return unsignedp ? unsigned_accum_type_node : accum_type_node;
9479 : 1130272 : if (size == LONG_ACCUM_TYPE_SIZE)
9480 : 565136 : return unsignedp ? unsigned_long_accum_type_node
9481 : 565136 : : long_accum_type_node;
9482 : 565136 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9483 : 565136 : return unsignedp ? unsigned_long_long_accum_type_node
9484 : 565136 : : long_long_accum_type_node;
9485 : : }
9486 : :
9487 : 0 : return make_accum_type (size, unsignedp, satp);
9488 : : }
9489 : :
9490 : :
9491 : : /* Create an atomic variant node for TYPE. This routine is called
9492 : : during initialization of data types to create the 5 basic atomic
9493 : : types. The generic build_variant_type function requires these to
9494 : : already be set up in order to function properly, so cannot be
9495 : : called from there. If ALIGN is non-zero, then ensure alignment is
9496 : : overridden to this value. */
9497 : :
9498 : : static tree
9499 : 1412840 : build_atomic_base (tree type, unsigned int align)
9500 : : {
9501 : 1412840 : tree t;
9502 : :
9503 : : /* Make sure its not already registered. */
9504 : 1412840 : if ((t = get_qualified_type (type, TYPE_QUAL_ATOMIC)))
9505 : : return t;
9506 : :
9507 : 1412840 : t = build_variant_type_copy (type);
9508 : 1412840 : set_type_quals (t, TYPE_QUAL_ATOMIC);
9509 : :
9510 : 1412840 : if (align)
9511 : 0 : SET_TYPE_ALIGN (t, align);
9512 : :
9513 : : return t;
9514 : : }
9515 : :
9516 : : /* Information about the _FloatN and _FloatNx types. This must be in
9517 : : the same order as the corresponding TI_* enum values. */
9518 : : const floatn_type_info floatn_nx_types[NUM_FLOATN_NX_TYPES] =
9519 : : {
9520 : : { 16, false },
9521 : : { 32, false },
9522 : : { 64, false },
9523 : : { 128, false },
9524 : : { 32, true },
9525 : : { 64, true },
9526 : : { 128, true },
9527 : : };
9528 : :
9529 : :
9530 : : /* Create nodes for all integer types (and error_mark_node) using the sizes
9531 : : of C datatypes. SIGNED_CHAR specifies whether char is signed. */
9532 : :
9533 : : void
9534 : 282568 : build_common_tree_nodes (bool signed_char)
9535 : : {
9536 : 282568 : int i;
9537 : :
9538 : 282568 : error_mark_node = make_node (ERROR_MARK);
9539 : 282568 : TREE_TYPE (error_mark_node) = error_mark_node;
9540 : :
9541 : 282568 : initialize_sizetypes ();
9542 : :
9543 : : /* Define both `signed char' and `unsigned char'. */
9544 : 282568 : signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
9545 : 282568 : TYPE_STRING_FLAG (signed_char_type_node) = 1;
9546 : 282568 : unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
9547 : 282568 : TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
9548 : :
9549 : : /* Define `char', which is like either `signed char' or `unsigned char'
9550 : : but not the same as either. */
9551 : 282568 : char_type_node
9552 : 282568 : = (signed_char
9553 : 282568 : ? make_signed_type (CHAR_TYPE_SIZE)
9554 : 55084 : : make_unsigned_type (CHAR_TYPE_SIZE));
9555 : 282568 : TYPE_STRING_FLAG (char_type_node) = 1;
9556 : :
9557 : 282568 : short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
9558 : 282568 : short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
9559 : 282568 : integer_type_node = make_signed_type (INT_TYPE_SIZE);
9560 : 282568 : unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
9561 : 289715 : long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
9562 : 289715 : long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
9563 : 282568 : long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
9564 : 282568 : long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
9565 : :
9566 : 847704 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9567 : : {
9568 : 282568 : int_n_trees[i].signed_type = make_signed_type (int_n_data[i].bitsize);
9569 : 282568 : int_n_trees[i].unsigned_type = make_unsigned_type (int_n_data[i].bitsize);
9570 : :
9571 : 282568 : if (int_n_enabled_p[i])
9572 : : {
9573 : 275523 : integer_types[itk_intN_0 + i * 2] = int_n_trees[i].signed_type;
9574 : 275523 : integer_types[itk_unsigned_intN_0 + i * 2] = int_n_trees[i].unsigned_type;
9575 : : }
9576 : : }
9577 : :
9578 : : /* Define a boolean type. This type only represents boolean values but
9579 : : may be larger than char depending on the value of BOOL_TYPE_SIZE. */
9580 : 282568 : boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
9581 : 282568 : TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
9582 : 282568 : TYPE_PRECISION (boolean_type_node) = 1;
9583 : 282568 : TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
9584 : :
9585 : : /* Define what type to use for size_t. */
9586 : 289715 : if (strcmp (SIZE_TYPE, "unsigned int") == 0)
9587 : 7147 : size_type_node = unsigned_type_node;
9588 : 275421 : else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
9589 : 275421 : size_type_node = long_unsigned_type_node;
9590 : 0 : else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
9591 : 0 : size_type_node = long_long_unsigned_type_node;
9592 : 0 : else if (strcmp (SIZE_TYPE, "short unsigned int") == 0)
9593 : 0 : size_type_node = short_unsigned_type_node;
9594 : : else
9595 : : {
9596 : 0 : int i;
9597 : :
9598 : 0 : size_type_node = NULL_TREE;
9599 : 0 : for (i = 0; i < NUM_INT_N_ENTS; i++)
9600 : 0 : if (int_n_enabled_p[i])
9601 : : {
9602 : 0 : char name[50], altname[50];
9603 : 0 : sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
9604 : 0 : sprintf (altname, "__int%d__ unsigned", int_n_data[i].bitsize);
9605 : :
9606 : 0 : if (strcmp (name, SIZE_TYPE) == 0
9607 : 0 : || strcmp (altname, SIZE_TYPE) == 0)
9608 : : {
9609 : 0 : size_type_node = int_n_trees[i].unsigned_type;
9610 : : }
9611 : : }
9612 : 0 : if (size_type_node == NULL_TREE)
9613 : 0 : gcc_unreachable ();
9614 : : }
9615 : :
9616 : : /* Define what type to use for ptrdiff_t. */
9617 : 289715 : if (strcmp (PTRDIFF_TYPE, "int") == 0)
9618 : 7147 : ptrdiff_type_node = integer_type_node;
9619 : 275421 : else if (strcmp (PTRDIFF_TYPE, "long int") == 0)
9620 : 275421 : ptrdiff_type_node = long_integer_type_node;
9621 : 0 : else if (strcmp (PTRDIFF_TYPE, "long long int") == 0)
9622 : 0 : ptrdiff_type_node = long_long_integer_type_node;
9623 : 0 : else if (strcmp (PTRDIFF_TYPE, "short int") == 0)
9624 : 0 : ptrdiff_type_node = short_integer_type_node;
9625 : : else
9626 : : {
9627 : 0 : ptrdiff_type_node = NULL_TREE;
9628 : 0 : for (int i = 0; i < NUM_INT_N_ENTS; i++)
9629 : 0 : if (int_n_enabled_p[i])
9630 : : {
9631 : 0 : char name[50], altname[50];
9632 : 0 : sprintf (name, "__int%d", int_n_data[i].bitsize);
9633 : 0 : sprintf (altname, "__int%d__", int_n_data[i].bitsize);
9634 : :
9635 : 0 : if (strcmp (name, PTRDIFF_TYPE) == 0
9636 : 0 : || strcmp (altname, PTRDIFF_TYPE) == 0)
9637 : 0 : ptrdiff_type_node = int_n_trees[i].signed_type;
9638 : : }
9639 : 0 : if (ptrdiff_type_node == NULL_TREE)
9640 : 0 : gcc_unreachable ();
9641 : : }
9642 : :
9643 : : /* Fill in the rest of the sized types. Reuse existing type nodes
9644 : : when possible. */
9645 : 282568 : intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
9646 : 282568 : intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
9647 : 282568 : intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
9648 : 282568 : intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
9649 : 282568 : intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
9650 : :
9651 : 282568 : unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
9652 : 282568 : unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
9653 : 282568 : unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
9654 : 282568 : unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
9655 : 282568 : unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
9656 : :
9657 : : /* Don't call build_qualified type for atomics. That routine does
9658 : : special processing for atomics, and until they are initialized
9659 : : it's better not to make that call.
9660 : :
9661 : : Check to see if there is a target override for atomic types. */
9662 : :
9663 : 282568 : atomicQI_type_node = build_atomic_base (unsigned_intQI_type_node,
9664 : 282568 : targetm.atomic_align_for_mode (QImode));
9665 : 282568 : atomicHI_type_node = build_atomic_base (unsigned_intHI_type_node,
9666 : 282568 : targetm.atomic_align_for_mode (HImode));
9667 : 282568 : atomicSI_type_node = build_atomic_base (unsigned_intSI_type_node,
9668 : 282568 : targetm.atomic_align_for_mode (SImode));
9669 : 282568 : atomicDI_type_node = build_atomic_base (unsigned_intDI_type_node,
9670 : 282568 : targetm.atomic_align_for_mode (DImode));
9671 : 282568 : atomicTI_type_node = build_atomic_base (unsigned_intTI_type_node,
9672 : 282568 : targetm.atomic_align_for_mode (TImode));
9673 : :
9674 : 282568 : access_public_node = get_identifier ("public");
9675 : 282568 : access_protected_node = get_identifier ("protected");
9676 : 282568 : access_private_node = get_identifier ("private");
9677 : :
9678 : : /* Define these next since types below may used them. */
9679 : 282568 : integer_zero_node = build_int_cst (integer_type_node, 0);
9680 : 282568 : integer_one_node = build_int_cst (integer_type_node, 1);
9681 : 282568 : integer_minus_one_node = build_int_cst (integer_type_node, -1);
9682 : :
9683 : 282568 : size_zero_node = size_int (0);
9684 : 282568 : size_one_node = size_int (1);
9685 : 282568 : bitsize_zero_node = bitsize_int (0);
9686 : 282568 : bitsize_one_node = bitsize_int (1);
9687 : 282568 : bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
9688 : :
9689 : 282568 : boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
9690 : 282568 : boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
9691 : :
9692 : 282568 : void_type_node = make_node (VOID_TYPE);
9693 : 282568 : layout_type (void_type_node);
9694 : :
9695 : : /* We are not going to have real types in C with less than byte alignment,
9696 : : so we might as well not have any types that claim to have it. */
9697 : 282568 : SET_TYPE_ALIGN (void_type_node, BITS_PER_UNIT);
9698 : 282568 : TYPE_USER_ALIGN (void_type_node) = 0;
9699 : :
9700 : 282568 : void_node = make_node (VOID_CST);
9701 : 282568 : TREE_TYPE (void_node) = void_type_node;
9702 : :
9703 : 282568 : void_list_node = build_tree_list (NULL_TREE, void_type_node);
9704 : :
9705 : 282568 : null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
9706 : 282568 : layout_type (TREE_TYPE (null_pointer_node));
9707 : :
9708 : 282568 : ptr_type_node = build_pointer_type (void_type_node);
9709 : 282568 : const_ptr_type_node
9710 : 282568 : = build_pointer_type (build_type_variant (void_type_node, 1, 0));
9711 : 1977976 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
9712 : 1695408 : builtin_structptr_types[i].node = builtin_structptr_types[i].base;
9713 : :
9714 : 289715 : pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
9715 : :
9716 : 282568 : float_type_node = make_node (REAL_TYPE);
9717 : 282568 : machine_mode float_type_mode
9718 : 282568 : = targetm.c.mode_for_floating_type (TI_FLOAT_TYPE);
9719 : 282568 : SET_TYPE_MODE (float_type_node, float_type_mode);
9720 : 282568 : TYPE_PRECISION (float_type_node)
9721 : 282568 : = GET_MODE_PRECISION (float_type_mode).to_constant ();
9722 : 282568 : layout_type (float_type_node);
9723 : :
9724 : 282568 : double_type_node = make_node (REAL_TYPE);
9725 : 282568 : machine_mode double_type_mode
9726 : 282568 : = targetm.c.mode_for_floating_type (TI_DOUBLE_TYPE);
9727 : 282568 : SET_TYPE_MODE (double_type_node, double_type_mode);
9728 : 282568 : TYPE_PRECISION (double_type_node)
9729 : 282568 : = GET_MODE_PRECISION (double_type_mode).to_constant ();
9730 : 282568 : layout_type (double_type_node);
9731 : :
9732 : 282568 : long_double_type_node = make_node (REAL_TYPE);
9733 : 282568 : machine_mode long_double_type_mode
9734 : 282568 : = targetm.c.mode_for_floating_type (TI_LONG_DOUBLE_TYPE);
9735 : 282568 : SET_TYPE_MODE (long_double_type_node, long_double_type_mode);
9736 : 282568 : TYPE_PRECISION (long_double_type_node)
9737 : 282568 : = GET_MODE_PRECISION (long_double_type_mode).to_constant ();
9738 : 282568 : layout_type (long_double_type_node);
9739 : :
9740 : 2260544 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9741 : : {
9742 : 1977976 : int n = floatn_nx_types[i].n;
9743 : 1977976 : bool extended = floatn_nx_types[i].extended;
9744 : 1977976 : scalar_float_mode mode;
9745 : 1977976 : if (!targetm.floatn_mode (n, extended).exists (&mode))
9746 : 282568 : continue;
9747 : 1695408 : int precision = GET_MODE_PRECISION (mode);
9748 : 1695408 : FLOATN_NX_TYPE_NODE (i) = make_node (REAL_TYPE);
9749 : 1695408 : TYPE_PRECISION (FLOATN_NX_TYPE_NODE (i)) = precision;
9750 : 1695408 : layout_type (FLOATN_NX_TYPE_NODE (i));
9751 : 1695408 : SET_TYPE_MODE (FLOATN_NX_TYPE_NODE (i), mode);
9752 : : }
9753 : 282568 : float128t_type_node = float128_type_node;
9754 : : #ifdef HAVE_BFmode
9755 : 282568 : if (REAL_MODE_FORMAT (BFmode) == &arm_bfloat_half_format
9756 : 282568 : && targetm.scalar_mode_supported_p (BFmode)
9757 : 565136 : && targetm.libgcc_floating_mode_supported_p (BFmode))
9758 : : {
9759 : 282568 : bfloat16_type_node = make_node (REAL_TYPE);
9760 : 282568 : TYPE_PRECISION (bfloat16_type_node) = GET_MODE_PRECISION (BFmode);
9761 : 282568 : layout_type (bfloat16_type_node);
9762 : 282568 : SET_TYPE_MODE (bfloat16_type_node, BFmode);
9763 : : }
9764 : : #endif
9765 : :
9766 : 282568 : float_ptr_type_node = build_pointer_type (float_type_node);
9767 : 282568 : double_ptr_type_node = build_pointer_type (double_type_node);
9768 : 282568 : long_double_ptr_type_node = build_pointer_type (long_double_type_node);
9769 : 282568 : integer_ptr_type_node = build_pointer_type (integer_type_node);
9770 : :
9771 : : /* Fixed size integer types. */
9772 : 282568 : uint16_type_node = make_or_reuse_type (16, 1);
9773 : 282568 : uint32_type_node = make_or_reuse_type (32, 1);
9774 : 282568 : uint64_type_node = make_or_reuse_type (64, 1);
9775 : 282568 : if (targetm.scalar_mode_supported_p (TImode))
9776 : 275523 : uint128_type_node = make_or_reuse_type (128, 1);
9777 : :
9778 : : /* Decimal float types. */
9779 : 282568 : if (targetm.decimal_float_supported_p ())
9780 : : {
9781 : 282568 : dfloat32_type_node = make_node (REAL_TYPE);
9782 : 282568 : TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
9783 : 282568 : SET_TYPE_MODE (dfloat32_type_node, SDmode);
9784 : 282568 : layout_type (dfloat32_type_node);
9785 : :
9786 : 282568 : dfloat64_type_node = make_node (REAL_TYPE);
9787 : 282568 : TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
9788 : 282568 : SET_TYPE_MODE (dfloat64_type_node, DDmode);
9789 : 282568 : layout_type (dfloat64_type_node);
9790 : :
9791 : 282568 : dfloat128_type_node = make_node (REAL_TYPE);
9792 : 282568 : TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
9793 : 282568 : SET_TYPE_MODE (dfloat128_type_node, TDmode);
9794 : 282568 : layout_type (dfloat128_type_node);
9795 : :
9796 : 282568 : dfloat64x_type_node = make_node (REAL_TYPE);
9797 : 282568 : TYPE_PRECISION (dfloat64x_type_node) = DECIMAL128_TYPE_SIZE;
9798 : 282568 : SET_TYPE_MODE (dfloat64x_type_node, TDmode);
9799 : 282568 : layout_type (dfloat64x_type_node);
9800 : : }
9801 : :
9802 : 282568 : complex_integer_type_node = build_complex_type (integer_type_node, true);
9803 : 282568 : complex_float_type_node = build_complex_type (float_type_node, true);
9804 : 282568 : complex_double_type_node = build_complex_type (double_type_node, true);
9805 : 282568 : complex_long_double_type_node = build_complex_type (long_double_type_node,
9806 : : true);
9807 : :
9808 : 2260544 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9809 : : {
9810 : 1977976 : if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
9811 : 1695408 : COMPLEX_FLOATN_NX_TYPE_NODE (i)
9812 : 1695408 : = build_complex_type (FLOATN_NX_TYPE_NODE (i));
9813 : : }
9814 : :
9815 : : /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9816 : : #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9817 : : sat_ ## KIND ## _type_node = \
9818 : : make_sat_signed_ ## KIND ## _type (SIZE); \
9819 : : sat_unsigned_ ## KIND ## _type_node = \
9820 : : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9821 : : KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9822 : : unsigned_ ## KIND ## _type_node = \
9823 : : make_unsigned_ ## KIND ## _type (SIZE);
9824 : :
9825 : : #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9826 : : sat_ ## WIDTH ## KIND ## _type_node = \
9827 : : make_sat_signed_ ## KIND ## _type (SIZE); \
9828 : : sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9829 : : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9830 : : WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9831 : : unsigned_ ## WIDTH ## KIND ## _type_node = \
9832 : : make_unsigned_ ## KIND ## _type (SIZE);
9833 : :
9834 : : /* Make fixed-point type nodes based on four different widths. */
9835 : : #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9836 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9837 : : MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9838 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9839 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9840 : :
9841 : : /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9842 : : #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9843 : : NAME ## _type_node = \
9844 : : make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9845 : : u ## NAME ## _type_node = \
9846 : : make_or_reuse_unsigned_ ## KIND ## _type \
9847 : : (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9848 : : sat_ ## NAME ## _type_node = \
9849 : : make_or_reuse_sat_signed_ ## KIND ## _type \
9850 : : (GET_MODE_BITSIZE (MODE ## mode)); \
9851 : : sat_u ## NAME ## _type_node = \
9852 : : make_or_reuse_sat_unsigned_ ## KIND ## _type \
9853 : : (GET_MODE_BITSIZE (U ## MODE ## mode));
9854 : :
9855 : : /* Fixed-point type and mode nodes. */
9856 : 282568 : MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT)
9857 : 282568 : MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM)
9858 : 282568 : MAKE_FIXED_MODE_NODE (fract, qq, QQ)
9859 : 282568 : MAKE_FIXED_MODE_NODE (fract, hq, HQ)
9860 : 282568 : MAKE_FIXED_MODE_NODE (fract, sq, SQ)
9861 : 282568 : MAKE_FIXED_MODE_NODE (fract, dq, DQ)
9862 : 282568 : MAKE_FIXED_MODE_NODE (fract, tq, TQ)
9863 : 282568 : MAKE_FIXED_MODE_NODE (accum, ha, HA)
9864 : 282568 : MAKE_FIXED_MODE_NODE (accum, sa, SA)
9865 : 282568 : MAKE_FIXED_MODE_NODE (accum, da, DA)
9866 : 282568 : MAKE_FIXED_MODE_NODE (accum, ta, TA)
9867 : :
9868 : 282568 : {
9869 : 282568 : tree t = targetm.build_builtin_va_list ();
9870 : :
9871 : : /* Many back-ends define record types without setting TYPE_NAME.
9872 : : If we copied the record type here, we'd keep the original
9873 : : record type without a name. This breaks name mangling. So,
9874 : : don't copy record types and let c_common_nodes_and_builtins()
9875 : : declare the type to be __builtin_va_list. */
9876 : 282568 : if (TREE_CODE (t) != RECORD_TYPE)
9877 : 282568 : t = build_variant_type_copy (t);
9878 : :
9879 : 282568 : va_list_type_node = t;
9880 : : }
9881 : :
9882 : : /* SCEV analyzer global shared trees. */
9883 : 282568 : chrec_dont_know = make_node (SCEV_NOT_KNOWN);
9884 : 282568 : TREE_TYPE (chrec_dont_know) = void_type_node;
9885 : 282568 : chrec_known = make_node (SCEV_KNOWN);
9886 : 282568 : TREE_TYPE (chrec_known) = void_type_node;
9887 : 282568 : }
9888 : :
9889 : : /* Modify DECL for given flags.
9890 : : TM_PURE attribute is set only on types, so the function will modify
9891 : : DECL's type when ECF_TM_PURE is used. */
9892 : :
9893 : : void
9894 : 29887244 : set_call_expr_flags (tree decl, int flags)
9895 : : {
9896 : 29887244 : if (flags & ECF_NOTHROW)
9897 : 25710579 : TREE_NOTHROW (decl) = 1;
9898 : 29887244 : if (flags & ECF_CONST)
9899 : 12009727 : TREE_READONLY (decl) = 1;
9900 : 29887244 : if (flags & ECF_PURE)
9901 : 1469752 : DECL_PURE_P (decl) = 1;
9902 : 29887244 : if (flags & ECF_LOOPING_CONST_OR_PURE)
9903 : 0 : DECL_LOOPING_CONST_OR_PURE_P (decl) = 1;
9904 : 29887244 : if (flags & ECF_NOVOPS)
9905 : 0 : DECL_IS_NOVOPS (decl) = 1;
9906 : 29887244 : if (flags & ECF_NORETURN)
9907 : 1196829 : TREE_THIS_VOLATILE (decl) = 1;
9908 : 29887244 : if (flags & ECF_MALLOC)
9909 : 726015 : DECL_IS_MALLOC (decl) = 1;
9910 : 29887244 : if (flags & ECF_RETURNS_TWICE)
9911 : 0 : DECL_IS_RETURNS_TWICE (decl) = 1;
9912 : 29887244 : if (flags & ECF_LEAF)
9913 : 25624949 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("leaf"),
9914 : 25624949 : NULL, DECL_ATTRIBUTES (decl));
9915 : 29887244 : if (flags & ECF_COLD)
9916 : 626828 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("cold"),
9917 : 626828 : NULL, DECL_ATTRIBUTES (decl));
9918 : 29887244 : if (flags & ECF_RET1)
9919 : 0 : DECL_ATTRIBUTES (decl)
9920 : 0 : = tree_cons (get_identifier ("fn spec"),
9921 : : build_tree_list (NULL_TREE, build_string (2, "1 ")),
9922 : 0 : DECL_ATTRIBUTES (decl));
9923 : 29887244 : if ((flags & ECF_TM_PURE) && flag_tm)
9924 : 579 : apply_tm_attr (decl, get_identifier ("transaction_pure"));
9925 : 29887244 : if ((flags & ECF_XTHROW))
9926 : 402784 : DECL_ATTRIBUTES (decl)
9927 : 805568 : = tree_cons (get_identifier ("expected_throw"),
9928 : 402784 : NULL, DECL_ATTRIBUTES (decl));
9929 : : /* Looping const or pure is implied by noreturn.
9930 : : There is currently no way to declare looping const or looping pure alone. */
9931 : 29887244 : gcc_assert (!(flags & ECF_LOOPING_CONST_OR_PURE)
9932 : : || ((flags & ECF_NORETURN) && (flags & (ECF_CONST | ECF_PURE))));
9933 : 29887244 : }
9934 : :
9935 : :
9936 : : /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
9937 : :
9938 : : static void
9939 : 9356475 : local_define_builtin (const char *name, tree type, enum built_in_function code,
9940 : : const char *library_name, int ecf_flags)
9941 : : {
9942 : 9356475 : tree decl;
9943 : :
9944 : 9356475 : decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
9945 : : library_name, NULL_TREE);
9946 : 9356475 : set_call_expr_flags (decl, ecf_flags);
9947 : :
9948 : 9356475 : set_builtin_decl (code, decl, true);
9949 : 9356475 : }
9950 : :
9951 : : /* Call this function after instantiating all builtins that the language
9952 : : front end cares about. This will build the rest of the builtins
9953 : : and internal functions that are relied upon by the tree optimizers and
9954 : : the middle-end. */
9955 : :
9956 : : void
9957 : 282552 : build_common_builtin_nodes (void)
9958 : : {
9959 : 282552 : tree tmp, ftype;
9960 : 282552 : int ecf_flags;
9961 : :
9962 : 282552 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_PADDING))
9963 : : {
9964 : 56269 : ftype = build_function_type_list (void_type_node,
9965 : : ptr_type_node,
9966 : : ptr_type_node,
9967 : : NULL_TREE);
9968 : 56269 : local_define_builtin ("__builtin_clear_padding", ftype,
9969 : : BUILT_IN_CLEAR_PADDING,
9970 : : "__builtin_clear_padding",
9971 : : ECF_LEAF | ECF_NOTHROW);
9972 : : }
9973 : :
9974 : 282552 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE)
9975 : 230928 : || !builtin_decl_explicit_p (BUILT_IN_TRAP)
9976 : 230928 : || !builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP)
9977 : 508835 : || !builtin_decl_explicit_p (BUILT_IN_ABORT))
9978 : : {
9979 : 56269 : ftype = build_function_type (void_type_node, void_list_node);
9980 : 56269 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE))
9981 : 51624 : local_define_builtin ("__builtin_unreachable", ftype,
9982 : : BUILT_IN_UNREACHABLE,
9983 : : "__builtin_unreachable",
9984 : : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
9985 : : | ECF_CONST | ECF_COLD);
9986 : 56269 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP))
9987 : 56269 : local_define_builtin ("__builtin_unreachable trap", ftype,
9988 : : BUILT_IN_UNREACHABLE_TRAP,
9989 : : "__builtin_unreachable trap",
9990 : : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
9991 : : | ECF_CONST | ECF_COLD);
9992 : 56269 : if (!builtin_decl_explicit_p (BUILT_IN_ABORT))
9993 : 56269 : local_define_builtin ("__builtin_abort", ftype, BUILT_IN_ABORT,
9994 : : "abort",
9995 : : ECF_LEAF | ECF_NORETURN | ECF_CONST | ECF_COLD);
9996 : 56269 : if (!builtin_decl_explicit_p (BUILT_IN_TRAP))
9997 : 20851 : local_define_builtin ("__builtin_trap", ftype, BUILT_IN_TRAP,
9998 : : "__builtin_trap",
9999 : : ECF_NORETURN | ECF_NOTHROW | ECF_LEAF | ECF_COLD);
10000 : : }
10001 : :
10002 : 282552 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY)
10003 : 282552 : || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10004 : : {
10005 : 56269 : ftype = build_function_type_list (ptr_type_node,
10006 : : ptr_type_node, const_ptr_type_node,
10007 : : size_type_node, NULL_TREE);
10008 : :
10009 : 56269 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY))
10010 : 56269 : local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
10011 : : "memcpy", ECF_NOTHROW | ECF_LEAF);
10012 : 56269 : if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10013 : 51624 : local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
10014 : : "memmove", ECF_NOTHROW | ECF_LEAF);
10015 : : }
10016 : :
10017 : 282552 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP))
10018 : : {
10019 : 51624 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10020 : : const_ptr_type_node, size_type_node,
10021 : : NULL_TREE);
10022 : 51624 : local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
10023 : : "memcmp", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10024 : : }
10025 : :
10026 : 282552 : if (!builtin_decl_explicit_p (BUILT_IN_MEMSET))
10027 : : {
10028 : 51624 : ftype = build_function_type_list (ptr_type_node,
10029 : : ptr_type_node, integer_type_node,
10030 : : size_type_node, NULL_TREE);
10031 : 51624 : local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
10032 : : "memset", ECF_NOTHROW | ECF_LEAF);
10033 : : }
10034 : :
10035 : : /* If we're checking the stack, `alloca' can throw. */
10036 : 565104 : const int alloca_flags
10037 : 282552 : = ECF_MALLOC | ECF_LEAF | (flag_stack_check ? 0 : ECF_NOTHROW);
10038 : :
10039 : 282552 : if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA))
10040 : : {
10041 : 56269 : ftype = build_function_type_list (ptr_type_node,
10042 : : size_type_node, NULL_TREE);
10043 : 56269 : local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
10044 : : "alloca", alloca_flags);
10045 : : }
10046 : :
10047 : 282552 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10048 : : size_type_node, NULL_TREE);
10049 : 282552 : local_define_builtin ("__builtin_alloca_with_align", ftype,
10050 : : BUILT_IN_ALLOCA_WITH_ALIGN,
10051 : : "__builtin_alloca_with_align",
10052 : : alloca_flags);
10053 : :
10054 : 282552 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10055 : : size_type_node, size_type_node, NULL_TREE);
10056 : 282552 : local_define_builtin ("__builtin_alloca_with_align_and_max", ftype,
10057 : : BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX,
10058 : : "__builtin_alloca_with_align_and_max",
10059 : : alloca_flags);
10060 : :
10061 : 282552 : ftype = build_function_type_list (void_type_node,
10062 : : ptr_type_node, ptr_type_node,
10063 : : ptr_type_node, NULL_TREE);
10064 : 282552 : local_define_builtin ("__builtin_init_trampoline", ftype,
10065 : : BUILT_IN_INIT_TRAMPOLINE,
10066 : : "__builtin_init_trampoline", ECF_NOTHROW | ECF_LEAF);
10067 : 282552 : local_define_builtin ("__builtin_init_heap_trampoline", ftype,
10068 : : BUILT_IN_INIT_HEAP_TRAMPOLINE,
10069 : : "__builtin_init_heap_trampoline",
10070 : : ECF_NOTHROW | ECF_LEAF);
10071 : 282552 : local_define_builtin ("__builtin_init_descriptor", ftype,
10072 : : BUILT_IN_INIT_DESCRIPTOR,
10073 : : "__builtin_init_descriptor", ECF_NOTHROW | ECF_LEAF);
10074 : :
10075 : 282552 : ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
10076 : 282552 : local_define_builtin ("__builtin_adjust_trampoline", ftype,
10077 : : BUILT_IN_ADJUST_TRAMPOLINE,
10078 : : "__builtin_adjust_trampoline",
10079 : : ECF_CONST | ECF_NOTHROW);
10080 : 282552 : local_define_builtin ("__builtin_adjust_descriptor", ftype,
10081 : : BUILT_IN_ADJUST_DESCRIPTOR,
10082 : : "__builtin_adjust_descriptor",
10083 : : ECF_CONST | ECF_NOTHROW);
10084 : :
10085 : 282552 : ftype = build_function_type_list (void_type_node,
10086 : : ptr_type_node, ptr_type_node, NULL_TREE);
10087 : 282552 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_CACHE))
10088 : 56269 : local_define_builtin ("__builtin___clear_cache", ftype,
10089 : : BUILT_IN_CLEAR_CACHE,
10090 : : "__clear_cache",
10091 : : ECF_NOTHROW);
10092 : :
10093 : 282552 : local_define_builtin ("__builtin_nonlocal_goto", ftype,
10094 : : BUILT_IN_NONLOCAL_GOTO,
10095 : : "__builtin_nonlocal_goto",
10096 : : ECF_NORETURN | ECF_NOTHROW);
10097 : :
10098 : 282552 : tree ptr_ptr_type_node = build_pointer_type (ptr_type_node);
10099 : :
10100 : 282552 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_CREATED))
10101 : : {
10102 : 56269 : ftype = build_function_type_list (void_type_node,
10103 : : ptr_type_node, // void *chain
10104 : : ptr_type_node, // void *func
10105 : : ptr_ptr_type_node, // void **dst
10106 : : NULL_TREE);
10107 : 56269 : local_define_builtin ("__builtin___gcc_nested_func_ptr_created", ftype,
10108 : : BUILT_IN_GCC_NESTED_PTR_CREATED,
10109 : : "__gcc_nested_func_ptr_created", ECF_NOTHROW);
10110 : : }
10111 : :
10112 : 282552 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_DELETED))
10113 : : {
10114 : 56269 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10115 : 56269 : local_define_builtin ("__builtin___gcc_nested_func_ptr_deleted", ftype,
10116 : : BUILT_IN_GCC_NESTED_PTR_DELETED,
10117 : : "__gcc_nested_func_ptr_deleted", ECF_NOTHROW);
10118 : : }
10119 : :
10120 : 282552 : ftype = build_function_type_list (void_type_node,
10121 : : ptr_type_node, ptr_type_node, NULL_TREE);
10122 : 282552 : local_define_builtin ("__builtin_setjmp_setup", ftype,
10123 : : BUILT_IN_SETJMP_SETUP,
10124 : : "__builtin_setjmp_setup", ECF_NOTHROW);
10125 : :
10126 : 282552 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10127 : 282552 : local_define_builtin ("__builtin_setjmp_receiver", ftype,
10128 : : BUILT_IN_SETJMP_RECEIVER,
10129 : : "__builtin_setjmp_receiver", ECF_NOTHROW | ECF_LEAF);
10130 : :
10131 : 282552 : ftype = build_function_type_list (ptr_type_node, NULL_TREE);
10132 : 282552 : local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
10133 : : "__builtin_stack_save", ECF_NOTHROW | ECF_LEAF);
10134 : :
10135 : 282552 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10136 : 282552 : local_define_builtin ("__builtin_stack_restore", ftype,
10137 : : BUILT_IN_STACK_RESTORE,
10138 : : "__builtin_stack_restore", ECF_NOTHROW | ECF_LEAF);
10139 : :
10140 : 282552 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10141 : : const_ptr_type_node, size_type_node,
10142 : : NULL_TREE);
10143 : 282552 : local_define_builtin ("__builtin_memcmp_eq", ftype, BUILT_IN_MEMCMP_EQ,
10144 : : "__builtin_memcmp_eq",
10145 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10146 : :
10147 : 282552 : local_define_builtin ("__builtin_strncmp_eq", ftype, BUILT_IN_STRNCMP_EQ,
10148 : : "__builtin_strncmp_eq",
10149 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10150 : :
10151 : 282552 : local_define_builtin ("__builtin_strcmp_eq", ftype, BUILT_IN_STRCMP_EQ,
10152 : : "__builtin_strcmp_eq",
10153 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10154 : :
10155 : : /* If there's a possibility that we might use the ARM EABI, build the
10156 : : alternate __cxa_end_cleanup node used to resume from C++. */
10157 : 282552 : if (targetm.arm_eabi_unwinder)
10158 : : {
10159 : 0 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10160 : 0 : local_define_builtin ("__builtin_cxa_end_cleanup", ftype,
10161 : : BUILT_IN_CXA_END_CLEANUP,
10162 : : "__cxa_end_cleanup",
10163 : : ECF_NORETURN | ECF_XTHROW | ECF_LEAF);
10164 : : }
10165 : :
10166 : 282552 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10167 : 565104 : local_define_builtin ("__builtin_unwind_resume", ftype,
10168 : : BUILT_IN_UNWIND_RESUME,
10169 : 282552 : ((targetm_common.except_unwind_info (&global_options)
10170 : : == UI_SJLJ)
10171 : : ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
10172 : : ECF_NORETURN | ECF_XTHROW);
10173 : :
10174 : 282552 : if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS) == NULL_TREE)
10175 : : {
10176 : 51624 : ftype = build_function_type_list (ptr_type_node, integer_type_node,
10177 : : NULL_TREE);
10178 : 51624 : local_define_builtin ("__builtin_return_address", ftype,
10179 : : BUILT_IN_RETURN_ADDRESS,
10180 : : "__builtin_return_address",
10181 : : ECF_NOTHROW);
10182 : : }
10183 : :
10184 : 282552 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER)
10185 : 282552 : || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10186 : : {
10187 : 56269 : ftype = build_function_type_list (void_type_node, ptr_type_node,
10188 : : ptr_type_node, NULL_TREE);
10189 : 56269 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER))
10190 : 56269 : local_define_builtin ("__cyg_profile_func_enter", ftype,
10191 : : BUILT_IN_PROFILE_FUNC_ENTER,
10192 : : "__cyg_profile_func_enter", 0);
10193 : 56269 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10194 : 56269 : local_define_builtin ("__cyg_profile_func_exit", ftype,
10195 : : BUILT_IN_PROFILE_FUNC_EXIT,
10196 : : "__cyg_profile_func_exit", 0);
10197 : : }
10198 : :
10199 : : /* The exception object and filter values from the runtime. The argument
10200 : : must be zero before exception lowering, i.e. from the front end. After
10201 : : exception lowering, it will be the region number for the exception
10202 : : landing pad. These functions are PURE instead of CONST to prevent
10203 : : them from being hoisted past the exception edge that will initialize
10204 : : its value in the landing pad. */
10205 : 282552 : ftype = build_function_type_list (ptr_type_node,
10206 : : integer_type_node, NULL_TREE);
10207 : 282552 : ecf_flags = ECF_PURE | ECF_NOTHROW | ECF_LEAF;
10208 : : /* Only use TM_PURE if we have TM language support. */
10209 : 282552 : if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1))
10210 : 517 : ecf_flags |= ECF_TM_PURE;
10211 : 282552 : local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER,
10212 : : "__builtin_eh_pointer", ecf_flags);
10213 : :
10214 : 282552 : tmp = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0);
10215 : 282552 : ftype = build_function_type_list (tmp, integer_type_node, NULL_TREE);
10216 : 282552 : local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER,
10217 : : "__builtin_eh_filter", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10218 : :
10219 : 282552 : ftype = build_function_type_list (void_type_node,
10220 : : integer_type_node, integer_type_node,
10221 : : NULL_TREE);
10222 : 282552 : local_define_builtin ("__builtin_eh_copy_values", ftype,
10223 : : BUILT_IN_EH_COPY_VALUES,
10224 : : "__builtin_eh_copy_values", ECF_NOTHROW);
10225 : :
10226 : : /* Complex multiplication and division. These are handled as builtins
10227 : : rather than optabs because emit_library_call_value doesn't support
10228 : : complex. Further, we can do slightly better with folding these
10229 : : beasties if the real and complex parts of the arguments are separate. */
10230 : 282552 : {
10231 : 282552 : int mode;
10232 : :
10233 : 1977864 : for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
10234 : : {
10235 : 1695312 : char mode_name_buf[4], *q;
10236 : 1695312 : const char *p;
10237 : 1695312 : enum built_in_function mcode, dcode;
10238 : 1695312 : tree type, inner_type;
10239 : 1695312 : const char *prefix = "__";
10240 : :
10241 : 1695312 : if (targetm.libfunc_gnu_prefix)
10242 : 0 : prefix = "__gnu_";
10243 : :
10244 : 1695312 : type = lang_hooks.types.type_for_mode ((machine_mode) mode, 0);
10245 : 1695312 : if (type == NULL)
10246 : 122149 : continue;
10247 : 1573163 : inner_type = TREE_TYPE (type);
10248 : :
10249 : 1573163 : ftype = build_function_type_list (type, inner_type, inner_type,
10250 : : inner_type, inner_type, NULL_TREE);
10251 : :
10252 : 1573163 : mcode = ((enum built_in_function)
10253 : 1573163 : (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10254 : 1573163 : dcode = ((enum built_in_function)
10255 : 1573163 : (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10256 : :
10257 : 4719489 : for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
10258 : 3146326 : *q = TOLOWER (*p);
10259 : 1573163 : *q = '\0';
10260 : :
10261 : : /* For -ftrapping-math these should throw from a former
10262 : : -fnon-call-exception stmt. */
10263 : 1573163 : built_in_names[mcode] = concat (prefix, "mul", mode_name_buf, "3",
10264 : : NULL);
10265 : 1573163 : local_define_builtin (built_in_names[mcode], ftype, mcode,
10266 : : built_in_names[mcode],
10267 : : ECF_CONST | ECF_LEAF);
10268 : :
10269 : 1573163 : built_in_names[dcode] = concat (prefix, "div", mode_name_buf, "3",
10270 : : NULL);
10271 : 1573163 : local_define_builtin (built_in_names[dcode], ftype, dcode,
10272 : : built_in_names[dcode],
10273 : : ECF_CONST | ECF_LEAF);
10274 : : }
10275 : : }
10276 : :
10277 : 282552 : init_internal_fns ();
10278 : 282552 : }
10279 : :
10280 : : /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10281 : : better way.
10282 : :
10283 : : If we requested a pointer to a vector, build up the pointers that
10284 : : we stripped off while looking for the inner type. Similarly for
10285 : : return values from functions.
10286 : :
10287 : : The argument TYPE is the top of the chain, and BOTTOM is the
10288 : : new type which we will point to. */
10289 : :
10290 : : tree
10291 : 0 : reconstruct_complex_type (tree type, tree bottom)
10292 : : {
10293 : 0 : tree inner, outer;
10294 : :
10295 : 0 : if (TREE_CODE (type) == POINTER_TYPE)
10296 : : {
10297 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10298 : 0 : outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
10299 : 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10300 : : }
10301 : : else if (TREE_CODE (type) == REFERENCE_TYPE)
10302 : : {
10303 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10304 : 0 : outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
10305 : 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10306 : : }
10307 : : else if (TREE_CODE (type) == ARRAY_TYPE)
10308 : : {
10309 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10310 : 0 : outer = build_array_type (inner, TYPE_DOMAIN (type));
10311 : : }
10312 : : else if (TREE_CODE (type) == FUNCTION_TYPE)
10313 : : {
10314 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10315 : 0 : outer = build_function_type (inner, TYPE_ARG_TYPES (type),
10316 : 0 : TYPE_NO_NAMED_ARGS_STDARG_P (type));
10317 : : }
10318 : : else if (TREE_CODE (type) == METHOD_TYPE)
10319 : : {
10320 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10321 : : /* The build_method_type_directly() routine prepends 'this' to argument list,
10322 : : so we must compensate by getting rid of it. */
10323 : 0 : outer
10324 : : = build_method_type_directly
10325 : 0 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
10326 : : inner,
10327 : 0 : TREE_CHAIN (TYPE_ARG_TYPES (type)));
10328 : : }
10329 : : else if (TREE_CODE (type) == OFFSET_TYPE)
10330 : : {
10331 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10332 : 0 : outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
10333 : : }
10334 : : else
10335 : : return bottom;
10336 : :
10337 : 0 : return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
10338 : 0 : TYPE_QUALS (type));
10339 : : }
10340 : :
10341 : : /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10342 : : the inner type. */
10343 : : tree
10344 : 31287146 : build_vector_type_for_mode (tree innertype, machine_mode mode)
10345 : : {
10346 : 31287146 : poly_int64 nunits;
10347 : 31287146 : unsigned int bitsize;
10348 : :
10349 : 31287146 : switch (GET_MODE_CLASS (mode))
10350 : : {
10351 : 31285963 : case MODE_VECTOR_BOOL:
10352 : 31285963 : case MODE_VECTOR_INT:
10353 : 31285963 : case MODE_VECTOR_FLOAT:
10354 : 31285963 : case MODE_VECTOR_FRACT:
10355 : 31285963 : case MODE_VECTOR_UFRACT:
10356 : 31285963 : case MODE_VECTOR_ACCUM:
10357 : 31285963 : case MODE_VECTOR_UACCUM:
10358 : 62571926 : nunits = GET_MODE_NUNITS (mode);
10359 : 31285963 : break;
10360 : :
10361 : 1183 : case MODE_INT:
10362 : : /* Check that there are no leftover bits. */
10363 : 1183 : bitsize = GET_MODE_BITSIZE (as_a <scalar_int_mode> (mode));
10364 : 1183 : gcc_assert (bitsize % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
10365 : 1183 : nunits = bitsize / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
10366 : 1183 : break;
10367 : :
10368 : 0 : default:
10369 : 0 : gcc_unreachable ();
10370 : : }
10371 : :
10372 : 31287146 : return make_vector_type (innertype, nunits, mode);
10373 : : }
10374 : :
10375 : : /* Similarly, but takes the inner type and number of units, which must be
10376 : : a power of two. */
10377 : :
10378 : : tree
10379 : 2772578 : build_vector_type (tree innertype, poly_int64 nunits)
10380 : : {
10381 : 2772578 : return make_vector_type (innertype, nunits, VOIDmode);
10382 : : }
10383 : :
10384 : : /* Build a truth vector with NUNITS units, giving it mode MASK_MODE. */
10385 : :
10386 : : tree
10387 : 1766061 : build_truth_vector_type_for_mode (poly_uint64 nunits, machine_mode mask_mode)
10388 : : {
10389 : 1766061 : gcc_assert (mask_mode != BLKmode);
10390 : :
10391 : 1766061 : unsigned HOST_WIDE_INT esize;
10392 : 1766061 : if (VECTOR_MODE_P (mask_mode))
10393 : : {
10394 : 1707344 : poly_uint64 vsize = GET_MODE_PRECISION (mask_mode);
10395 : 1707344 : esize = vector_element_size (vsize, nunits);
10396 : 1707344 : }
10397 : : else
10398 : : esize = 1;
10399 : :
10400 : 1766061 : tree bool_type = build_nonstandard_boolean_type (esize);
10401 : :
10402 : 1766061 : return make_vector_type (bool_type, nunits, mask_mode);
10403 : : }
10404 : :
10405 : : /* Build a vector type that holds one boolean result for each element of
10406 : : vector type VECTYPE. The public interface for this operation is
10407 : : truth_type_for. */
10408 : :
10409 : : static tree
10410 : 1760811 : build_truth_vector_type_for (tree vectype)
10411 : : {
10412 : 1760811 : machine_mode vector_mode = TYPE_MODE (vectype);
10413 : 1760811 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
10414 : :
10415 : 1760811 : machine_mode mask_mode;
10416 : 70177 : if (VECTOR_MODE_P (vector_mode)
10417 : 1830429 : && targetm.vectorize.get_mask_mode (vector_mode).exists (&mask_mode))
10418 : 1760252 : return build_truth_vector_type_for_mode (nunits, mask_mode);
10419 : :
10420 : 559 : poly_uint64 vsize = tree_to_poly_uint64 (TYPE_SIZE (vectype));
10421 : 559 : unsigned HOST_WIDE_INT esize = vector_element_size (vsize, nunits);
10422 : 559 : tree bool_type = build_nonstandard_boolean_type (esize);
10423 : :
10424 : 559 : return make_vector_type (bool_type, nunits, VOIDmode);
10425 : : }
10426 : :
10427 : : /* Like build_vector_type, but builds a variant type with TYPE_VECTOR_OPAQUE
10428 : : set. */
10429 : :
10430 : : tree
10431 : 105470 : build_opaque_vector_type (tree innertype, poly_int64 nunits)
10432 : : {
10433 : 105470 : tree t = make_vector_type (innertype, nunits, VOIDmode);
10434 : 105470 : tree cand;
10435 : : /* We always build the non-opaque variant before the opaque one,
10436 : : so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10437 : 105470 : cand = TYPE_NEXT_VARIANT (t);
10438 : 105470 : if (cand
10439 : 94070 : && TYPE_VECTOR_OPAQUE (cand)
10440 : 166624 : && check_qualified_type (cand, t, TYPE_QUALS (t)))
10441 : : return cand;
10442 : : /* Othewise build a variant type and make sure to queue it after
10443 : : the non-opaque type. */
10444 : 44317 : cand = build_distinct_type_copy (t);
10445 : 44317 : TYPE_VECTOR_OPAQUE (cand) = true;
10446 : 44317 : TYPE_CANONICAL (cand) = TYPE_CANONICAL (t);
10447 : 44317 : TYPE_NEXT_VARIANT (cand) = TYPE_NEXT_VARIANT (t);
10448 : 44317 : TYPE_NEXT_VARIANT (t) = cand;
10449 : 44317 : TYPE_MAIN_VARIANT (cand) = TYPE_MAIN_VARIANT (t);
10450 : : /* Type variants have no alias set defined. */
10451 : 44317 : TYPE_ALIAS_SET (cand) = -1;
10452 : 44317 : return cand;
10453 : : }
10454 : :
10455 : : /* Return the value of element I of VECTOR_CST T as a wide_int. */
10456 : :
10457 : : static poly_wide_int
10458 : 479024 : vector_cst_int_elt (const_tree t, unsigned int i)
10459 : : {
10460 : : /* First handle elements that are directly encoded. */
10461 : 479024 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10462 : 479024 : if (i < encoded_nelts)
10463 : 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, i));
10464 : :
10465 : : /* Identify the pattern that contains element I and work out the index of
10466 : : the last encoded element for that pattern. */
10467 : 479024 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10468 : 479024 : unsigned int pattern = i % npatterns;
10469 : 479024 : unsigned int count = i / npatterns;
10470 : 479024 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10471 : :
10472 : : /* If there are no steps, the final encoded value is the right one. */
10473 : 479024 : if (!VECTOR_CST_STEPPED_P (t))
10474 : 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, final_i));
10475 : :
10476 : : /* Otherwise work out the value from the last two encoded elements. */
10477 : 479024 : tree v1 = VECTOR_CST_ENCODED_ELT (t, final_i - npatterns);
10478 : 479024 : tree v2 = VECTOR_CST_ENCODED_ELT (t, final_i);
10479 : 479024 : poly_wide_int diff = wi::to_poly_wide (v2) - wi::to_poly_wide (v1);
10480 : 479024 : return wi::to_poly_wide (v2) + (count - 2) * diff;
10481 : 479024 : }
10482 : :
10483 : : /* Return the value of element I of VECTOR_CST T. */
10484 : :
10485 : : tree
10486 : 5657865 : vector_cst_elt (const_tree t, unsigned int i)
10487 : : {
10488 : : /* First handle elements that are directly encoded. */
10489 : 5657865 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10490 : 5657865 : if (i < encoded_nelts)
10491 : 3976106 : return VECTOR_CST_ENCODED_ELT (t, i);
10492 : :
10493 : : /* If there are no steps, the final encoded value is the right one. */
10494 : 1681759 : if (!VECTOR_CST_STEPPED_P (t))
10495 : : {
10496 : : /* Identify the pattern that contains element I and work out the index of
10497 : : the last encoded element for that pattern. */
10498 : 1202735 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10499 : 1202735 : unsigned int pattern = i % npatterns;
10500 : 1202735 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10501 : 1202735 : return VECTOR_CST_ENCODED_ELT (t, final_i);
10502 : : }
10503 : :
10504 : : /* Otherwise work out the value from the last two encoded elements. */
10505 : 479024 : return wide_int_to_tree (TREE_TYPE (TREE_TYPE (t)),
10506 : 958048 : vector_cst_int_elt (t, i));
10507 : : }
10508 : :
10509 : : /* Given an initializer INIT, return TRUE if INIT is zero or some
10510 : : aggregate of zeros. Otherwise return FALSE. If NONZERO is not
10511 : : null, set *NONZERO if and only if INIT is known not to be all
10512 : : zeros. The combination of return value of false and *NONZERO
10513 : : false implies that INIT may but need not be all zeros. Other
10514 : : combinations indicate definitive answers. */
10515 : :
10516 : : bool
10517 : 40455930 : initializer_zerop (const_tree init, bool *nonzero /* = NULL */)
10518 : : {
10519 : 40455930 : bool dummy;
10520 : 40455930 : if (!nonzero)
10521 : 37754759 : nonzero = &dummy;
10522 : :
10523 : : /* Conservatively clear NONZERO and set it only if INIT is definitely
10524 : : not all zero. */
10525 : 40455930 : *nonzero = false;
10526 : :
10527 : 40455930 : STRIP_NOPS (init);
10528 : :
10529 : 40455930 : unsigned HOST_WIDE_INT off = 0;
10530 : :
10531 : 40455930 : switch (TREE_CODE (init))
10532 : : {
10533 : 15043399 : case INTEGER_CST:
10534 : 15043399 : if (integer_zerop (init))
10535 : : return true;
10536 : :
10537 : 9596474 : *nonzero = true;
10538 : 9596474 : return false;
10539 : :
10540 : 500154 : case REAL_CST:
10541 : : /* ??? Note that this is not correct for C4X float formats. There,
10542 : : a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10543 : : negative exponent. */
10544 : 500154 : if (real_zerop (init)
10545 : 582201 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init)))
10546 : : return true;
10547 : :
10548 : 420950 : *nonzero = true;
10549 : 420950 : return false;
10550 : :
10551 : 0 : case FIXED_CST:
10552 : 0 : if (fixed_zerop (init))
10553 : : return true;
10554 : :
10555 : 0 : *nonzero = true;
10556 : 0 : return false;
10557 : :
10558 : 17535 : case COMPLEX_CST:
10559 : 17535 : if (integer_zerop (init)
10560 : 17535 : || (real_zerop (init)
10561 : 2949 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
10562 : 2907 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init)))))
10563 : 3135 : return true;
10564 : :
10565 : 14400 : *nonzero = true;
10566 : 14400 : return false;
10567 : :
10568 : 1050905 : case VECTOR_CST:
10569 : 1050905 : if (VECTOR_CST_NPATTERNS (init) == 1
10570 : 959161 : && VECTOR_CST_DUPLICATE_P (init)
10571 : 1654073 : && initializer_zerop (VECTOR_CST_ENCODED_ELT (init, 0)))
10572 : : return true;
10573 : :
10574 : 741894 : *nonzero = true;
10575 : 741894 : return false;
10576 : :
10577 : : case RAW_DATA_CST:
10578 : 1562 : for (unsigned int i = 0; i < (unsigned int) RAW_DATA_LENGTH (init); ++i)
10579 : 1562 : if (RAW_DATA_POINTER (init)[i])
10580 : : {
10581 : 1512 : *nonzero = true;
10582 : 1512 : return false;
10583 : : }
10584 : : return true;
10585 : :
10586 : 5290975 : case CONSTRUCTOR:
10587 : 5290975 : {
10588 : 5290975 : if (TREE_CLOBBER_P (init))
10589 : : return false;
10590 : :
10591 : : unsigned HOST_WIDE_INT idx;
10592 : : tree elt;
10593 : :
10594 : 3488229 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
10595 : 2701171 : if (!initializer_zerop (elt, nonzero))
10596 : : return false;
10597 : :
10598 : : return true;
10599 : : }
10600 : :
10601 : 323112 : case MEM_REF:
10602 : 323112 : {
10603 : 323112 : tree arg = TREE_OPERAND (init, 0);
10604 : 323112 : if (TREE_CODE (arg) != ADDR_EXPR)
10605 : : return false;
10606 : 71454 : tree offset = TREE_OPERAND (init, 1);
10607 : 71454 : if (TREE_CODE (offset) != INTEGER_CST
10608 : 71454 : || !tree_fits_uhwi_p (offset))
10609 : : return false;
10610 : 71454 : off = tree_to_uhwi (offset);
10611 : 71454 : if (INT_MAX < off)
10612 : : return false;
10613 : 71450 : arg = TREE_OPERAND (arg, 0);
10614 : 71450 : if (TREE_CODE (arg) != STRING_CST)
10615 : : return false;
10616 : : init = arg;
10617 : : }
10618 : : /* Fall through. */
10619 : :
10620 : : case STRING_CST:
10621 : : {
10622 : : gcc_assert (off <= INT_MAX);
10623 : :
10624 : 151373 : int i = off;
10625 : 151373 : int n = TREE_STRING_LENGTH (init);
10626 : 151373 : if (n <= i)
10627 : : return false;
10628 : :
10629 : : /* We need to loop through all elements to handle cases like
10630 : : "\0" and "\0foobar". */
10631 : 163225 : for (i = 0; i < n; ++i)
10632 : 157993 : if (TREE_STRING_POINTER (init)[i] != '\0')
10633 : : {
10634 : 146108 : *nonzero = true;
10635 : 146108 : return false;
10636 : : }
10637 : :
10638 : : return true;
10639 : : }
10640 : :
10641 : : default:
10642 : : return false;
10643 : : }
10644 : : }
10645 : :
10646 : : /* Return true if EXPR is an initializer expression in which every element
10647 : : is a constant that is numerically equal to 0 or 1. The elements do not
10648 : : need to be equal to each other. */
10649 : :
10650 : : bool
10651 : 121827 : initializer_each_zero_or_onep (const_tree expr)
10652 : : {
10653 : 121827 : STRIP_ANY_LOCATION_WRAPPER (expr);
10654 : :
10655 : 121827 : switch (TREE_CODE (expr))
10656 : : {
10657 : 46154 : case INTEGER_CST:
10658 : 46154 : return integer_zerop (expr) || integer_onep (expr);
10659 : :
10660 : 19518 : case REAL_CST:
10661 : 19518 : return real_zerop (expr) || real_onep (expr);
10662 : :
10663 : 56155 : case VECTOR_CST:
10664 : 56155 : {
10665 : 56155 : unsigned HOST_WIDE_INT nelts = vector_cst_encoded_nelts (expr);
10666 : 56155 : if (VECTOR_CST_STEPPED_P (expr)
10667 : 56155 : && !TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)).is_constant (&nelts))
10668 : : return false;
10669 : :
10670 : 66986 : for (unsigned int i = 0; i < nelts; ++i)
10671 : : {
10672 : 65672 : tree elt = vector_cst_elt (expr, i);
10673 : 65672 : if (!initializer_each_zero_or_onep (elt))
10674 : : return false;
10675 : : }
10676 : :
10677 : : return true;
10678 : : }
10679 : :
10680 : : default:
10681 : : return false;
10682 : : }
10683 : : }
10684 : :
10685 : : /* Check if vector VEC consists of all the equal elements and
10686 : : that the number of elements corresponds to the type of VEC.
10687 : : The function returns first element of the vector
10688 : : or NULL_TREE if the vector is not uniform. */
10689 : : tree
10690 : 2502563 : uniform_vector_p (const_tree vec)
10691 : : {
10692 : 2502563 : tree first, t;
10693 : 2502563 : unsigned HOST_WIDE_INT i, nelts;
10694 : :
10695 : 2502563 : if (vec == NULL_TREE)
10696 : : return NULL_TREE;
10697 : :
10698 : 2502563 : gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec)));
10699 : :
10700 : 2502563 : if (TREE_CODE (vec) == VEC_DUPLICATE_EXPR)
10701 : 0 : return TREE_OPERAND (vec, 0);
10702 : :
10703 : 2502563 : else if (TREE_CODE (vec) == VECTOR_CST)
10704 : : {
10705 : 199379 : if (VECTOR_CST_NPATTERNS (vec) == 1 && VECTOR_CST_DUPLICATE_P (vec))
10706 : 158106 : return VECTOR_CST_ENCODED_ELT (vec, 0);
10707 : : return NULL_TREE;
10708 : : }
10709 : :
10710 : 2303184 : else if (TREE_CODE (vec) == CONSTRUCTOR
10711 : 2303184 : && TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec)).is_constant (&nelts))
10712 : : {
10713 : 155416 : first = error_mark_node;
10714 : :
10715 : 519140 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t)
10716 : : {
10717 : 454175 : if (i == 0)
10718 : : {
10719 : 155416 : first = t;
10720 : 155416 : continue;
10721 : : }
10722 : 298759 : if (!operand_equal_p (first, t, 0))
10723 : : return NULL_TREE;
10724 : : }
10725 : 64965 : if (i != nelts)
10726 : : return NULL_TREE;
10727 : :
10728 : 64779 : if (TREE_CODE (first) == CONSTRUCTOR || TREE_CODE (first) == VECTOR_CST)
10729 : : return uniform_vector_p (first);
10730 : : return first;
10731 : : }
10732 : :
10733 : : return NULL_TREE;
10734 : : }
10735 : :
10736 : : /* If the argument is INTEGER_CST, return it. If the argument is vector
10737 : : with all elements the same INTEGER_CST, return that INTEGER_CST. Otherwise
10738 : : return NULL_TREE.
10739 : : Look through location wrappers. */
10740 : :
10741 : : tree
10742 : 785043488 : uniform_integer_cst_p (tree t)
10743 : : {
10744 : 785043488 : STRIP_ANY_LOCATION_WRAPPER (t);
10745 : :
10746 : 785043488 : if (TREE_CODE (t) == INTEGER_CST)
10747 : : return t;
10748 : :
10749 : 322776133 : if (VECTOR_TYPE_P (TREE_TYPE (t)))
10750 : : {
10751 : 884086 : t = uniform_vector_p (t);
10752 : 884086 : if (t && TREE_CODE (t) == INTEGER_CST)
10753 : : return t;
10754 : : }
10755 : :
10756 : : return NULL_TREE;
10757 : : }
10758 : :
10759 : : /* Checks to see if T is a constant or a constant vector and if each element E
10760 : : adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE. */
10761 : :
10762 : : tree
10763 : 2724868 : bitmask_inv_cst_vector_p (tree t)
10764 : : {
10765 : :
10766 : 2724868 : tree_code code = TREE_CODE (t);
10767 : 2724868 : tree type = TREE_TYPE (t);
10768 : :
10769 : 2724868 : if (!INTEGRAL_TYPE_P (type)
10770 : 2724868 : && !VECTOR_INTEGER_TYPE_P (type))
10771 : : return NULL_TREE;
10772 : :
10773 : 2724868 : unsigned HOST_WIDE_INT nelts = 1;
10774 : 2724868 : tree cst;
10775 : 2724868 : unsigned int idx = 0;
10776 : 2724868 : bool uniform = uniform_integer_cst_p (t);
10777 : 2724868 : tree newtype = unsigned_type_for (type);
10778 : 2724868 : tree_vector_builder builder;
10779 : 2724868 : if (code == INTEGER_CST)
10780 : : cst = t;
10781 : : else
10782 : : {
10783 : 6390 : if (!VECTOR_CST_NELTS (t).is_constant (&nelts))
10784 : : return NULL_TREE;
10785 : :
10786 : 6390 : cst = vector_cst_elt (t, 0);
10787 : 6390 : builder.new_vector (newtype, nelts, 1);
10788 : : }
10789 : :
10790 : 2724868 : tree ty = unsigned_type_for (TREE_TYPE (cst));
10791 : :
10792 : 2724880 : do
10793 : : {
10794 : 2724880 : if (idx > 0)
10795 : 12 : cst = vector_cst_elt (t, idx);
10796 : 2724880 : wide_int icst = wi::to_wide (cst);
10797 : 2724880 : wide_int inv = wi::bit_not (icst);
10798 : 2724880 : icst = wi::add (1, inv);
10799 : 2724880 : if (wi::popcount (icst) != 1)
10800 : : return NULL_TREE;
10801 : :
10802 : 19509 : tree newcst = wide_int_to_tree (ty, inv);
10803 : :
10804 : 19509 : if (uniform)
10805 : 19493 : return build_uniform_cst (newtype, newcst);
10806 : :
10807 : 16 : builder.quick_push (newcst);
10808 : 2724880 : }
10809 : 16 : while (++idx < nelts);
10810 : :
10811 : 4 : return builder.build ();
10812 : 2724868 : }
10813 : :
10814 : : /* If VECTOR_CST T has a single nonzero element, return the index of that
10815 : : element, otherwise return -1. */
10816 : :
10817 : : int
10818 : 201 : single_nonzero_element (const_tree t)
10819 : : {
10820 : 201 : unsigned HOST_WIDE_INT nelts;
10821 : 201 : unsigned int repeat_nelts;
10822 : 201 : if (VECTOR_CST_NELTS (t).is_constant (&nelts))
10823 : 201 : repeat_nelts = nelts;
10824 : : else if (VECTOR_CST_NELTS_PER_PATTERN (t) == 2)
10825 : : {
10826 : : nelts = vector_cst_encoded_nelts (t);
10827 : : repeat_nelts = VECTOR_CST_NPATTERNS (t);
10828 : : }
10829 : : else
10830 : : return -1;
10831 : :
10832 : 201 : int res = -1;
10833 : 609 : for (unsigned int i = 0; i < nelts; ++i)
10834 : : {
10835 : 576 : tree elt = vector_cst_elt (t, i);
10836 : 576 : if (!integer_zerop (elt) && !real_zerop (elt))
10837 : : {
10838 : 369 : if (res >= 0 || i >= repeat_nelts)
10839 : : return -1;
10840 : 201 : res = i;
10841 : : }
10842 : : }
10843 : : return res;
10844 : : }
10845 : :
10846 : : /* Build an empty statement at location LOC. */
10847 : :
10848 : : tree
10849 : 11402746 : build_empty_stmt (location_t loc)
10850 : : {
10851 : 11402746 : tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
10852 : 11402746 : SET_EXPR_LOCATION (t, loc);
10853 : 11402746 : return t;
10854 : : }
10855 : :
10856 : :
10857 : : /* Build an OMP clause with code CODE. LOC is the location of the
10858 : : clause. */
10859 : :
10860 : : tree
10861 : 1703068 : build_omp_clause (location_t loc, enum omp_clause_code code)
10862 : : {
10863 : 1703068 : tree t;
10864 : 1703068 : int size, length;
10865 : :
10866 : 1703068 : length = omp_clause_num_ops[code];
10867 : 1703068 : size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
10868 : :
10869 : 1703068 : record_node_allocation_statistics (OMP_CLAUSE, size);
10870 : :
10871 : 1703068 : t = (tree) ggc_internal_alloc (size);
10872 : 1703068 : memset (t, 0, size);
10873 : 1703068 : TREE_SET_CODE (t, OMP_CLAUSE);
10874 : 1703068 : OMP_CLAUSE_SET_CODE (t, code);
10875 : 1703068 : OMP_CLAUSE_LOCATION (t) = loc;
10876 : :
10877 : 1703068 : return t;
10878 : : }
10879 : :
10880 : : /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
10881 : : includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
10882 : : Except for the CODE and operand count field, other storage for the
10883 : : object is initialized to zeros. */
10884 : :
10885 : : tree
10886 : 405661601 : build_vl_exp (enum tree_code code, int len MEM_STAT_DECL)
10887 : : {
10888 : 405661601 : tree t;
10889 : 405661601 : int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
10890 : :
10891 : 405661601 : gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp);
10892 : 405661601 : gcc_assert (len >= 1);
10893 : :
10894 : 405661601 : record_node_allocation_statistics (code, length);
10895 : :
10896 : 405661601 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
10897 : :
10898 : 405661601 : TREE_SET_CODE (t, code);
10899 : :
10900 : : /* Can't use TREE_OPERAND to store the length because if checking is
10901 : : enabled, it will try to check the length before we store it. :-P */
10902 : 405661601 : t->exp.operands[0] = build_int_cst (sizetype, len);
10903 : :
10904 : 405661601 : return t;
10905 : : }
10906 : :
10907 : : /* Helper function for build_call_* functions; build a CALL_EXPR with
10908 : : indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
10909 : : the argument slots. */
10910 : :
10911 : : static tree
10912 : 213511269 : build_call_1 (tree return_type, tree fn, int nargs)
10913 : : {
10914 : 213511269 : tree t;
10915 : :
10916 : 213511269 : t = build_vl_exp (CALL_EXPR, nargs + 3);
10917 : 213511269 : TREE_TYPE (t) = return_type;
10918 : 213511269 : CALL_EXPR_FN (t) = fn;
10919 : 213511269 : CALL_EXPR_STATIC_CHAIN (t) = NULL;
10920 : :
10921 : 213511269 : return t;
10922 : : }
10923 : :
10924 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10925 : : FN and a null static chain slot. NARGS is the number of call arguments
10926 : : which are specified as "..." arguments. */
10927 : :
10928 : : tree
10929 : 157 : build_call_nary (tree return_type, tree fn, int nargs, ...)
10930 : : {
10931 : 157 : tree ret;
10932 : 157 : va_list args;
10933 : 157 : va_start (args, nargs);
10934 : 157 : ret = build_call_valist (return_type, fn, nargs, args);
10935 : 157 : va_end (args);
10936 : 157 : return ret;
10937 : : }
10938 : :
10939 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10940 : : FN and a null static chain slot. NARGS is the number of call arguments
10941 : : which are specified as a va_list ARGS. */
10942 : :
10943 : : tree
10944 : 135653 : build_call_valist (tree return_type, tree fn, int nargs, va_list args)
10945 : : {
10946 : 135653 : tree t;
10947 : 135653 : int i;
10948 : :
10949 : 135653 : t = build_call_1 (return_type, fn, nargs);
10950 : 550043 : for (i = 0; i < nargs; i++)
10951 : 278737 : CALL_EXPR_ARG (t, i) = va_arg (args, tree);
10952 : 135653 : process_call_operands (t);
10953 : 135653 : return t;
10954 : : }
10955 : :
10956 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10957 : : FN and a null static chain slot. NARGS is the number of call arguments
10958 : : which are specified as a tree array ARGS. */
10959 : :
10960 : : tree
10961 : 173932005 : build_call_array_loc (location_t loc, tree return_type, tree fn,
10962 : : int nargs, const tree *args)
10963 : : {
10964 : 173932005 : tree t;
10965 : 173932005 : int i;
10966 : :
10967 : 173932005 : t = build_call_1 (return_type, fn, nargs);
10968 : 617075348 : for (i = 0; i < nargs; i++)
10969 : 269211338 : CALL_EXPR_ARG (t, i) = args[i];
10970 : 173932005 : process_call_operands (t);
10971 : 173932005 : SET_EXPR_LOCATION (t, loc);
10972 : 173932005 : return t;
10973 : : }
10974 : :
10975 : : /* Like build_call_array, but takes a vec. */
10976 : :
10977 : : tree
10978 : 39134748 : build_call_vec (tree return_type, tree fn, const vec<tree, va_gc> *args)
10979 : : {
10980 : 39134748 : tree ret, t;
10981 : 39134748 : unsigned int ix;
10982 : :
10983 : 39134748 : ret = build_call_1 (return_type, fn, vec_safe_length (args));
10984 : 103394998 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
10985 : 25125502 : CALL_EXPR_ARG (ret, ix) = t;
10986 : 39134748 : process_call_operands (ret);
10987 : 39134748 : return ret;
10988 : : }
10989 : :
10990 : : /* Conveniently construct a function call expression. FNDECL names the
10991 : : function to be called and N arguments are passed in the array
10992 : : ARGARRAY. */
10993 : :
10994 : : tree
10995 : 16472007 : build_call_expr_loc_array (location_t loc, tree fndecl, int n, tree *argarray)
10996 : : {
10997 : 16472007 : tree fntype = TREE_TYPE (fndecl);
10998 : 16472007 : tree fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fndecl);
10999 : :
11000 : 16472007 : return fold_build_call_array_loc (loc, TREE_TYPE (fntype), fn, n, argarray);
11001 : : }
11002 : :
11003 : : /* Conveniently construct a function call expression. FNDECL names the
11004 : : function to be called and the arguments are passed in the vector
11005 : : VEC. */
11006 : :
11007 : : tree
11008 : 20600 : build_call_expr_loc_vec (location_t loc, tree fndecl, vec<tree, va_gc> *vec)
11009 : : {
11010 : 20600 : return build_call_expr_loc_array (loc, fndecl, vec_safe_length (vec),
11011 : 20600 : vec_safe_address (vec));
11012 : : }
11013 : :
11014 : :
11015 : : /* Conveniently construct a function call expression. FNDECL names the
11016 : : function to be called, N is the number of arguments, and the "..."
11017 : : parameters are the argument expressions. */
11018 : :
11019 : : tree
11020 : 14976187 : build_call_expr_loc (location_t loc, tree fndecl, int n, ...)
11021 : : {
11022 : 14976187 : va_list ap;
11023 : 14976187 : tree *argarray = XALLOCAVEC (tree, n);
11024 : 14976187 : int i;
11025 : :
11026 : 14976187 : va_start (ap, n);
11027 : 17277551 : for (i = 0; i < n; i++)
11028 : 2301364 : argarray[i] = va_arg (ap, tree);
11029 : 14976187 : va_end (ap);
11030 : 14976187 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11031 : : }
11032 : :
11033 : : /* Like build_call_expr_loc (UNKNOWN_LOCATION, ...). Duplicated because
11034 : : varargs macros aren't supported by all bootstrap compilers. */
11035 : :
11036 : : tree
11037 : 1470732 : build_call_expr (tree fndecl, int n, ...)
11038 : : {
11039 : 1470732 : va_list ap;
11040 : 1470732 : tree *argarray = XALLOCAVEC (tree, n);
11041 : 1470732 : int i;
11042 : :
11043 : 1470732 : va_start (ap, n);
11044 : 4284123 : for (i = 0; i < n; i++)
11045 : 2813391 : argarray[i] = va_arg (ap, tree);
11046 : 1470732 : va_end (ap);
11047 : 1470732 : return build_call_expr_loc_array (UNKNOWN_LOCATION, fndecl, n, argarray);
11048 : : }
11049 : :
11050 : : /* Build an internal call to IFN, with arguments ARGS[0:N-1] and with return
11051 : : type TYPE. This is just like CALL_EXPR, except its CALL_EXPR_FN is NULL.
11052 : : It will get gimplified later into an ordinary internal function. */
11053 : :
11054 : : tree
11055 : 308863 : build_call_expr_internal_loc_array (location_t loc, internal_fn ifn,
11056 : : tree type, int n, const tree *args)
11057 : : {
11058 : 308863 : tree t = build_call_1 (type, NULL_TREE, n);
11059 : 1060589 : for (int i = 0; i < n; ++i)
11060 : 751726 : CALL_EXPR_ARG (t, i) = args[i];
11061 : 308863 : SET_EXPR_LOCATION (t, loc);
11062 : 308863 : CALL_EXPR_IFN (t) = ifn;
11063 : 308863 : process_call_operands (t);
11064 : 308863 : return t;
11065 : : }
11066 : :
11067 : : /* Build internal call expression. This is just like CALL_EXPR, except
11068 : : its CALL_EXPR_FN is NULL. It will get gimplified later into ordinary
11069 : : internal function. */
11070 : :
11071 : : tree
11072 : 307885 : build_call_expr_internal_loc (location_t loc, enum internal_fn ifn,
11073 : : tree type, int n, ...)
11074 : : {
11075 : 307885 : va_list ap;
11076 : 307885 : tree *argarray = XALLOCAVEC (tree, n);
11077 : 307885 : int i;
11078 : :
11079 : 307885 : va_start (ap, n);
11080 : 1057657 : for (i = 0; i < n; i++)
11081 : 749772 : argarray[i] = va_arg (ap, tree);
11082 : 307885 : va_end (ap);
11083 : 307885 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11084 : : }
11085 : :
11086 : : /* Return a function call to FN, if the target is guaranteed to support it,
11087 : : or null otherwise.
11088 : :
11089 : : N is the number of arguments, passed in the "...", and TYPE is the
11090 : : type of the return value. */
11091 : :
11092 : : tree
11093 : 1782 : maybe_build_call_expr_loc (location_t loc, combined_fn fn, tree type,
11094 : : int n, ...)
11095 : : {
11096 : 1782 : va_list ap;
11097 : 1782 : tree *argarray = XALLOCAVEC (tree, n);
11098 : 1782 : int i;
11099 : :
11100 : 1782 : va_start (ap, n);
11101 : 4609 : for (i = 0; i < n; i++)
11102 : 2827 : argarray[i] = va_arg (ap, tree);
11103 : 1782 : va_end (ap);
11104 : 1782 : if (internal_fn_p (fn))
11105 : : {
11106 : 976 : internal_fn ifn = as_internal_fn (fn);
11107 : 976 : if (direct_internal_fn_p (ifn))
11108 : : {
11109 : 1 : tree_pair types = direct_internal_fn_types (ifn, type, argarray);
11110 : 1 : if (!direct_internal_fn_supported_p (ifn, types,
11111 : : OPTIMIZE_FOR_BOTH))
11112 : 1 : return NULL_TREE;
11113 : : }
11114 : 975 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11115 : : }
11116 : : else
11117 : : {
11118 : 806 : tree fndecl = builtin_decl_implicit (as_builtin_fn (fn));
11119 : 806 : if (!fndecl)
11120 : : return NULL_TREE;
11121 : 698 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11122 : : }
11123 : : }
11124 : :
11125 : : /* Return a function call to the appropriate builtin alloca variant.
11126 : :
11127 : : SIZE is the size to be allocated. ALIGN, if non-zero, is the requested
11128 : : alignment of the allocated area. MAX_SIZE, if non-negative, is an upper
11129 : : bound for SIZE in case it is not a fixed value. */
11130 : :
11131 : : tree
11132 : 8829 : build_alloca_call_expr (tree size, unsigned int align, HOST_WIDE_INT max_size)
11133 : : {
11134 : 8829 : if (max_size >= 0)
11135 : : {
11136 : 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX);
11137 : 0 : return
11138 : 0 : build_call_expr (t, 3, size, size_int (align), size_int (max_size));
11139 : : }
11140 : 8829 : else if (align > 0)
11141 : : {
11142 : 8829 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
11143 : 8829 : return build_call_expr (t, 2, size, size_int (align));
11144 : : }
11145 : : else
11146 : : {
11147 : 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA);
11148 : 0 : return build_call_expr (t, 1, size);
11149 : : }
11150 : : }
11151 : :
11152 : : /* The built-in decl to use to mark code points believed to be unreachable.
11153 : : Typically __builtin_unreachable, but __builtin_trap if
11154 : : -fsanitize=unreachable -fsanitize-trap=unreachable. If only
11155 : : -fsanitize=unreachable, we rely on sanopt to replace calls with the
11156 : : appropriate ubsan function. When building a call directly, use
11157 : : {gimple_},build_builtin_unreachable instead. */
11158 : :
11159 : : tree
11160 : 186231 : builtin_decl_unreachable ()
11161 : : {
11162 : 186231 : enum built_in_function fncode = BUILT_IN_UNREACHABLE;
11163 : :
11164 : 372462 : if (sanitize_flags_p (SANITIZE_UNREACHABLE)
11165 : 186231 : ? (flag_sanitize_trap & SANITIZE_UNREACHABLE)
11166 : 185765 : : flag_unreachable_traps)
11167 : 22 : fncode = BUILT_IN_UNREACHABLE_TRAP;
11168 : : /* For non-trapping sanitize, we will rewrite __builtin_unreachable () later,
11169 : : in the sanopt pass. */
11170 : :
11171 : 186231 : return builtin_decl_explicit (fncode);
11172 : : }
11173 : :
11174 : : /* Build a call to __builtin_unreachable, possibly rewritten by
11175 : : -fsanitize=unreachable. Use this rather than the above when practical. */
11176 : :
11177 : : tree
11178 : 13808560 : build_builtin_unreachable (location_t loc)
11179 : : {
11180 : 13808560 : tree data = NULL_TREE;
11181 : 13808560 : tree fn = sanitize_unreachable_fn (&data, loc);
11182 : 13808560 : return build_call_expr_loc (loc, fn, data != NULL_TREE, data);
11183 : : }
11184 : :
11185 : : /* Create a new constant string literal of type ELTYPE[SIZE] (or LEN
11186 : : if SIZE == -1) and return a tree node representing char* pointer to
11187 : : it as an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)). When STR is nonnull
11188 : : the STRING_CST value is the LEN bytes at STR (the representation
11189 : : of the string, which may be wide). Otherwise it's all zeros. */
11190 : :
11191 : : tree
11192 : 86260 : build_string_literal (unsigned len, const char *str /* = NULL */,
11193 : : tree eltype /* = char_type_node */,
11194 : : unsigned HOST_WIDE_INT size /* = -1 */)
11195 : : {
11196 : 86260 : tree t = build_string (len, str);
11197 : : /* Set the maximum valid index based on the string length or SIZE. */
11198 : 172520 : unsigned HOST_WIDE_INT maxidx
11199 : 86260 : = (size == HOST_WIDE_INT_M1U ? len : size) - 1;
11200 : :
11201 : 86260 : tree index = build_index_type (size_int (maxidx));
11202 : 86260 : eltype = build_type_variant (eltype, 1, 0);
11203 : 86260 : tree type = build_array_type (eltype, index);
11204 : 86260 : TREE_TYPE (t) = type;
11205 : 86260 : TREE_CONSTANT (t) = 1;
11206 : 86260 : TREE_READONLY (t) = 1;
11207 : 86260 : TREE_STATIC (t) = 1;
11208 : :
11209 : 86260 : type = build_pointer_type (eltype);
11210 : 86260 : t = build1 (ADDR_EXPR, type,
11211 : : build4 (ARRAY_REF, eltype,
11212 : : t, integer_zero_node, NULL_TREE, NULL_TREE));
11213 : 86260 : return t;
11214 : : }
11215 : :
11216 : :
11217 : :
11218 : : /* Return true if T (assumed to be a DECL) must be assigned a memory
11219 : : location. */
11220 : :
11221 : : bool
11222 : 1882790237 : needs_to_live_in_memory (const_tree t)
11223 : : {
11224 : 1882790237 : return (TREE_ADDRESSABLE (t)
11225 : 1513979777 : || is_global_var (t)
11226 : 2980449644 : || (TREE_CODE (t) == RESULT_DECL
11227 : 7645941 : && !DECL_BY_REFERENCE (t)
11228 : 5574838 : && aggregate_value_p (t, current_function_decl)));
11229 : : }
11230 : :
11231 : : /* Return value of a constant X and sign-extend it. */
11232 : :
11233 : : HOST_WIDE_INT
11234 : 490073619 : int_cst_value (const_tree x)
11235 : : {
11236 : 490073619 : unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
11237 : 490073619 : unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
11238 : :
11239 : : /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
11240 : 490073619 : gcc_assert (cst_and_fits_in_hwi (x));
11241 : :
11242 : 490073619 : if (bits < HOST_BITS_PER_WIDE_INT)
11243 : : {
11244 : 479618919 : bool negative = ((val >> (bits - 1)) & 1) != 0;
11245 : 479618919 : if (negative)
11246 : 184833 : val |= HOST_WIDE_INT_M1U << (bits - 1) << 1;
11247 : : else
11248 : 479434086 : val &= ~(HOST_WIDE_INT_M1U << (bits - 1) << 1);
11249 : : }
11250 : :
11251 : 490073619 : return val;
11252 : : }
11253 : :
11254 : : /* If TYPE is an integral or pointer type, return an integer type with
11255 : : the same precision which is unsigned iff UNSIGNEDP is true, or itself
11256 : : if TYPE is already an integer type of signedness UNSIGNEDP.
11257 : : If TYPE is a floating-point type, return an integer type with the same
11258 : : bitsize and with the signedness given by UNSIGNEDP; this is useful
11259 : : when doing bit-level operations on a floating-point value. */
11260 : :
11261 : : tree
11262 : 81923443 : signed_or_unsigned_type_for (int unsignedp, tree type)
11263 : : {
11264 : 81923443 : if (ANY_INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) == unsignedp)
11265 : : return type;
11266 : :
11267 : 53762320 : if (TREE_CODE (type) == VECTOR_TYPE)
11268 : : {
11269 : 18763 : tree inner = TREE_TYPE (type);
11270 : 18763 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11271 : 18763 : if (!inner2)
11272 : : return NULL_TREE;
11273 : 18763 : if (inner == inner2)
11274 : : return type;
11275 : 18763 : machine_mode new_mode;
11276 : 37526 : if (VECTOR_MODE_P (TYPE_MODE (type))
11277 : 37457 : && related_int_vector_mode (TYPE_MODE (type)).exists (&new_mode))
11278 : 18694 : return build_vector_type_for_mode (inner2, new_mode);
11279 : 69 : return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type));
11280 : : }
11281 : :
11282 : : if (TREE_CODE (type) == COMPLEX_TYPE)
11283 : : {
11284 : 24 : tree inner = TREE_TYPE (type);
11285 : 24 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11286 : 24 : if (!inner2)
11287 : : return NULL_TREE;
11288 : 24 : if (inner == inner2)
11289 : : return type;
11290 : 24 : return build_complex_type (inner2);
11291 : : }
11292 : :
11293 : : unsigned int bits;
11294 : : if (INTEGRAL_TYPE_P (type)
11295 : : || POINTER_TYPE_P (type)
11296 : : || TREE_CODE (type) == OFFSET_TYPE)
11297 : 53743439 : bits = TYPE_PRECISION (type);
11298 : : else if (TREE_CODE (type) == REAL_TYPE)
11299 : 188 : bits = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (type));
11300 : : else
11301 : : return NULL_TREE;
11302 : :
11303 : 53743533 : if (TREE_CODE (type) == BITINT_TYPE && (unsignedp || bits > 1))
11304 : 1481 : return build_bitint_type (bits, unsignedp);
11305 : 53742052 : return build_nonstandard_integer_type (bits, unsignedp);
11306 : : }
11307 : :
11308 : : /* If TYPE is an integral or pointer type, return an integer type with
11309 : : the same precision which is unsigned, or itself if TYPE is already an
11310 : : unsigned integer type. If TYPE is a floating-point type, return an
11311 : : unsigned integer type with the same bitsize as TYPE. */
11312 : :
11313 : : tree
11314 : 72165565 : unsigned_type_for (tree type)
11315 : : {
11316 : 72165565 : return signed_or_unsigned_type_for (1, type);
11317 : : }
11318 : :
11319 : : /* If TYPE is an integral or pointer type, return an integer type with
11320 : : the same precision which is signed, or itself if TYPE is already a
11321 : : signed integer type. If TYPE is a floating-point type, return a
11322 : : signed integer type with the same bitsize as TYPE. */
11323 : :
11324 : : tree
11325 : 9734439 : signed_type_for (tree type)
11326 : : {
11327 : 9734439 : return signed_or_unsigned_type_for (0, type);
11328 : : }
11329 : :
11330 : : /* - For VECTOR_TYPEs:
11331 : : - The truth type must be a VECTOR_BOOLEAN_TYPE.
11332 : : - The number of elements must match (known_eq).
11333 : : - targetm.vectorize.get_mask_mode exists, and exactly
11334 : : the same mode as the truth type.
11335 : : - Otherwise, the truth type must be a BOOLEAN_TYPE
11336 : : or useless_type_conversion_p to BOOLEAN_TYPE. */
11337 : : bool
11338 : 2143 : is_truth_type_for (tree type, tree truth_type)
11339 : : {
11340 : 2143 : machine_mode mask_mode = TYPE_MODE (truth_type);
11341 : 2143 : machine_mode vmode = TYPE_MODE (type);
11342 : 2143 : machine_mode tmask_mode;
11343 : :
11344 : 2143 : if (TREE_CODE (type) == VECTOR_TYPE)
11345 : : {
11346 : 2143 : if (VECTOR_BOOLEAN_TYPE_P (truth_type)
11347 : 2143 : && known_eq (TYPE_VECTOR_SUBPARTS (type),
11348 : : TYPE_VECTOR_SUBPARTS (truth_type))
11349 : 2143 : && targetm.vectorize.get_mask_mode (vmode).exists (&tmask_mode)
11350 : 4286 : && tmask_mode == mask_mode)
11351 : 2124 : return true;
11352 : :
11353 : 19 : return false;
11354 : : }
11355 : :
11356 : 0 : return useless_type_conversion_p (boolean_type_node, truth_type);
11357 : : }
11358 : :
11359 : : /* If TYPE is a vector type, return a signed integer vector type with the
11360 : : same width and number of subparts. Otherwise return boolean_type_node. */
11361 : :
11362 : : tree
11363 : 3654478 : truth_type_for (tree type)
11364 : : {
11365 : 3654478 : if (TREE_CODE (type) == VECTOR_TYPE)
11366 : : {
11367 : 1827990 : if (VECTOR_BOOLEAN_TYPE_P (type))
11368 : : return type;
11369 : 1760811 : return build_truth_vector_type_for (type);
11370 : : }
11371 : : else
11372 : 1826488 : return boolean_type_node;
11373 : : }
11374 : :
11375 : : /* Returns the largest value obtainable by casting something in INNER type to
11376 : : OUTER type. */
11377 : :
11378 : : tree
11379 : 9894163 : upper_bound_in_type (tree outer, tree inner)
11380 : : {
11381 : 9894163 : unsigned int det = 0;
11382 : 9894163 : unsigned oprec = TYPE_PRECISION (outer);
11383 : 9894163 : unsigned iprec = TYPE_PRECISION (inner);
11384 : 9894163 : unsigned prec;
11385 : :
11386 : : /* Compute a unique number for every combination. */
11387 : 9894163 : det |= (oprec > iprec) ? 4 : 0;
11388 : 9894163 : det |= TYPE_UNSIGNED (outer) ? 2 : 0;
11389 : 9894163 : det |= TYPE_UNSIGNED (inner) ? 1 : 0;
11390 : :
11391 : : /* Determine the exponent to use. */
11392 : 9894163 : switch (det)
11393 : : {
11394 : 6571606 : case 0:
11395 : 6571606 : case 1:
11396 : : /* oprec <= iprec, outer: signed, inner: don't care. */
11397 : 6571606 : prec = oprec - 1;
11398 : 6571606 : break;
11399 : : case 2:
11400 : : case 3:
11401 : : /* oprec <= iprec, outer: unsigned, inner: don't care. */
11402 : : prec = oprec;
11403 : : break;
11404 : 21678 : case 4:
11405 : : /* oprec > iprec, outer: signed, inner: signed. */
11406 : 21678 : prec = iprec - 1;
11407 : 21678 : break;
11408 : : case 5:
11409 : : /* oprec > iprec, outer: signed, inner: unsigned. */
11410 : 8236 : prec = iprec;
11411 : : break;
11412 : : case 6:
11413 : : /* oprec > iprec, outer: unsigned, inner: signed. */
11414 : : prec = oprec;
11415 : : break;
11416 : : case 7:
11417 : : /* oprec > iprec, outer: unsigned, inner: unsigned. */
11418 : 8236 : prec = iprec;
11419 : : break;
11420 : : default:
11421 : : gcc_unreachable ();
11422 : : }
11423 : :
11424 : 9894163 : return wide_int_to_tree (outer,
11425 : 9894163 : wi::mask (prec, false, TYPE_PRECISION (outer)));
11426 : : }
11427 : :
11428 : : /* Returns the smallest value obtainable by casting something in INNER type to
11429 : : OUTER type. */
11430 : :
11431 : : tree
11432 : 7555186 : lower_bound_in_type (tree outer, tree inner)
11433 : : {
11434 : 7555186 : unsigned oprec = TYPE_PRECISION (outer);
11435 : 7555186 : unsigned iprec = TYPE_PRECISION (inner);
11436 : :
11437 : : /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
11438 : : and obtain 0. */
11439 : 7555186 : if (TYPE_UNSIGNED (outer)
11440 : : /* If we are widening something of an unsigned type, OUTER type
11441 : : contains all values of INNER type. In particular, both INNER
11442 : : and OUTER types have zero in common. */
11443 : 7555186 : || (oprec > iprec && TYPE_UNSIGNED (inner)))
11444 : 1982124 : return build_int_cst (outer, 0);
11445 : : else
11446 : : {
11447 : : /* If we are widening a signed type to another signed type, we
11448 : : want to obtain -2^^(iprec-1). If we are keeping the
11449 : : precision or narrowing to a signed type, we want to obtain
11450 : : -2^(oprec-1). */
11451 : 5573062 : unsigned prec = oprec > iprec ? iprec : oprec;
11452 : 5573062 : return wide_int_to_tree (outer,
11453 : 11146124 : wi::mask (prec - 1, true,
11454 : 5573062 : TYPE_PRECISION (outer)));
11455 : : }
11456 : : }
11457 : :
11458 : : /* Return true if two operands that are suitable for PHI nodes are
11459 : : necessarily equal. Specifically, both ARG0 and ARG1 must be either
11460 : : SSA_NAME or invariant. Note that this is strictly an optimization.
11461 : : That is, callers of this function can directly call operand_equal_p
11462 : : and get the same result, only slower. */
11463 : :
11464 : : bool
11465 : 19654662 : operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1)
11466 : : {
11467 : 19654662 : if (arg0 == arg1)
11468 : : return true;
11469 : 18049908 : if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
11470 : : return false;
11471 : 3417658 : return operand_equal_p (arg0, arg1, 0);
11472 : : }
11473 : :
11474 : : /* Returns number of zeros at the end of binary representation of X. */
11475 : :
11476 : : tree
11477 : 8245192 : num_ending_zeros (const_tree x)
11478 : : {
11479 : 8245192 : return build_int_cst (TREE_TYPE (x), wi::ctz (wi::to_wide (x)));
11480 : : }
11481 : :
11482 : :
11483 : : #define WALK_SUBTREE(NODE) \
11484 : : do \
11485 : : { \
11486 : : result = walk_tree_1 (&(NODE), func, data, pset, lh); \
11487 : : if (result) \
11488 : : return result; \
11489 : : } \
11490 : : while (0)
11491 : :
11492 : : /* This is a subroutine of walk_tree that walks field of TYPE that are to
11493 : : be walked whenever a type is seen in the tree. Rest of operands and return
11494 : : value are as for walk_tree. */
11495 : :
11496 : : static tree
11497 : 3290536153 : walk_type_fields (tree type, walk_tree_fn func, void *data,
11498 : : hash_set<tree> *pset, walk_tree_lh lh)
11499 : : {
11500 : 3290536153 : tree result = NULL_TREE;
11501 : :
11502 : 3290536153 : switch (TREE_CODE (type))
11503 : : {
11504 : 986915924 : case POINTER_TYPE:
11505 : 986915924 : case REFERENCE_TYPE:
11506 : 986915924 : case VECTOR_TYPE:
11507 : : /* We have to worry about mutually recursive pointers. These can't
11508 : : be written in C. They can in Ada. It's pathological, but
11509 : : there's an ACATS test (c38102a) that checks it. Deal with this
11510 : : by checking if we're pointing to another pointer, that one
11511 : : points to another pointer, that one does too, and we have no htab.
11512 : : If so, get a hash table. We check three levels deep to avoid
11513 : : the cost of the hash table if we don't need one. */
11514 : 1950649773 : if (POINTER_TYPE_P (TREE_TYPE (type))
11515 : 23182142 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
11516 : 4847007 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
11517 : 991738302 : && !pset)
11518 : : {
11519 : 0 : result = walk_tree_without_duplicates (&TREE_TYPE (type),
11520 : : func, data);
11521 : 0 : if (result)
11522 : : return result;
11523 : :
11524 : : break;
11525 : : }
11526 : :
11527 : : /* fall through */
11528 : :
11529 : 989933438 : case COMPLEX_TYPE:
11530 : 989933438 : WALK_SUBTREE (TREE_TYPE (type));
11531 : : break;
11532 : :
11533 : 196494661 : case METHOD_TYPE:
11534 : 196494661 : WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
11535 : :
11536 : : /* Fall through. */
11537 : :
11538 : 317157498 : case FUNCTION_TYPE:
11539 : 317157498 : WALK_SUBTREE (TREE_TYPE (type));
11540 : 317157467 : {
11541 : 317157467 : tree arg;
11542 : :
11543 : : /* We never want to walk into default arguments. */
11544 : 1230730701 : for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
11545 : 913592475 : WALK_SUBTREE (TREE_VALUE (arg));
11546 : : }
11547 : : break;
11548 : :
11549 : 10992111 : case ARRAY_TYPE:
11550 : : /* Don't follow this nodes's type if a pointer for fear that
11551 : : we'll have infinite recursion. If we have a PSET, then we
11552 : : need not fear. */
11553 : 10992111 : if (pset
11554 : 10992111 : || (!POINTER_TYPE_P (TREE_TYPE (type))
11555 : 98344 : && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
11556 : 10990447 : WALK_SUBTREE (TREE_TYPE (type));
11557 : 10991045 : WALK_SUBTREE (TYPE_DOMAIN (type));
11558 : : break;
11559 : :
11560 : 900892 : case OFFSET_TYPE:
11561 : 900892 : WALK_SUBTREE (TREE_TYPE (type));
11562 : 900062 : WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
11563 : : break;
11564 : :
11565 : : default:
11566 : : break;
11567 : : }
11568 : :
11569 : : return NULL_TREE;
11570 : : }
11571 : :
11572 : : /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
11573 : : called with the DATA and the address of each sub-tree. If FUNC returns a
11574 : : non-NULL value, the traversal is stopped, and the value returned by FUNC
11575 : : is returned. If PSET is non-NULL it is used to record the nodes visited,
11576 : : and to avoid visiting a node more than once. */
11577 : :
11578 : : tree
11579 : 88031991507 : walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
11580 : : hash_set<tree> *pset, walk_tree_lh lh)
11581 : : {
11582 : : #define WALK_SUBTREE_TAIL(NODE) \
11583 : : do \
11584 : : { \
11585 : : tp = & (NODE); \
11586 : : goto tail_recurse; \
11587 : : } \
11588 : : while (0)
11589 : :
11590 : >10654*10^7 : tail_recurse:
11591 : : /* Skip empty subtrees. */
11592 : >10654*10^7 : if (!*tp)
11593 : : return NULL_TREE;
11594 : :
11595 : : /* Don't walk the same tree twice, if the user has requested
11596 : : that we avoid doing so. */
11597 : 87232581450 : if (pset && pset->add (*tp))
11598 : : return NULL_TREE;
11599 : :
11600 : : /* Call the function. */
11601 : 86121664433 : int walk_subtrees = 1;
11602 : 86121664433 : tree result = (*func) (tp, &walk_subtrees, data);
11603 : :
11604 : : /* If we found something, return it. */
11605 : 86121664433 : if (result)
11606 : : return result;
11607 : :
11608 : 86068206053 : tree t = *tp;
11609 : 86068206053 : tree_code code = TREE_CODE (t);
11610 : :
11611 : : /* Even if we didn't, FUNC may have decided that there was nothing
11612 : : interesting below this point in the tree. */
11613 : 86068206053 : if (!walk_subtrees)
11614 : : {
11615 : : /* But we still need to check our siblings. */
11616 : 57214536283 : if (code == TREE_LIST)
11617 : 91732 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11618 : 57214444551 : else if (code == OMP_CLAUSE)
11619 : 867247 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11620 : : else
11621 : : return NULL_TREE;
11622 : : }
11623 : :
11624 : 28853669770 : if (lh)
11625 : : {
11626 : 13582052925 : result = (*lh) (tp, &walk_subtrees, func, data, pset);
11627 : 13582052925 : if (result || !walk_subtrees)
11628 : 2065442398 : return result;
11629 : : }
11630 : :
11631 : 26788227372 : switch (code)
11632 : : {
11633 : : case ERROR_MARK:
11634 : : case IDENTIFIER_NODE:
11635 : : case INTEGER_CST:
11636 : : case REAL_CST:
11637 : : case FIXED_CST:
11638 : : case STRING_CST:
11639 : : case BLOCK:
11640 : : case PLACEHOLDER_EXPR:
11641 : : case SSA_NAME:
11642 : : case FIELD_DECL:
11643 : : case RESULT_DECL:
11644 : : /* None of these have subtrees other than those already walked
11645 : : above. */
11646 : : break;
11647 : :
11648 : 223170606 : case TREE_LIST:
11649 : 223170606 : WALK_SUBTREE (TREE_VALUE (t));
11650 : 222692920 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11651 : :
11652 : 751440169 : case TREE_VEC:
11653 : 751440169 : {
11654 : 751440169 : int len = TREE_VEC_LENGTH (t);
11655 : :
11656 : 751440169 : if (len == 0)
11657 : : break;
11658 : :
11659 : : /* Walk all elements but the last. */
11660 : 1535314004 : for (int i = 0; i < len - 1; ++i)
11661 : 791568347 : WALK_SUBTREE (TREE_VEC_ELT (t, i));
11662 : :
11663 : : /* Now walk the last one as a tail call. */
11664 : 743745657 : WALK_SUBTREE_TAIL (TREE_VEC_ELT (t, len - 1));
11665 : : }
11666 : :
11667 : 4479495 : case VECTOR_CST:
11668 : 4479495 : {
11669 : 4479495 : unsigned len = vector_cst_encoded_nelts (t);
11670 : 4479495 : if (len == 0)
11671 : : break;
11672 : : /* Walk all elements but the last. */
11673 : 15603792 : for (unsigned i = 0; i < len - 1; ++i)
11674 : 11124441 : WALK_SUBTREE (VECTOR_CST_ENCODED_ELT (t, i));
11675 : : /* Now walk the last one as a tail call. */
11676 : 4479351 : WALK_SUBTREE_TAIL (VECTOR_CST_ENCODED_ELT (t, len - 1));
11677 : : }
11678 : :
11679 : 530599 : case COMPLEX_CST:
11680 : 530599 : WALK_SUBTREE (TREE_REALPART (t));
11681 : 529033 : WALK_SUBTREE_TAIL (TREE_IMAGPART (t));
11682 : :
11683 : : case CONSTRUCTOR:
11684 : : {
11685 : : unsigned HOST_WIDE_INT idx;
11686 : : constructor_elt *ce;
11687 : :
11688 : 553957162 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce);
11689 : : idx++)
11690 : 159826420 : WALK_SUBTREE (ce->value);
11691 : : }
11692 : : break;
11693 : :
11694 : 2922204 : case SAVE_EXPR:
11695 : 2922204 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, 0));
11696 : :
11697 : 132780679 : case BIND_EXPR:
11698 : 132780679 : {
11699 : 132780679 : tree decl;
11700 : 214455679 : for (decl = BIND_EXPR_VARS (t); decl; decl = DECL_CHAIN (decl))
11701 : : {
11702 : : /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
11703 : : into declarations that are just mentioned, rather than
11704 : : declared; they don't really belong to this part of the tree.
11705 : : And, we can see cycles: the initializer for a declaration
11706 : : can refer to the declaration itself. */
11707 : 81675012 : WALK_SUBTREE (DECL_INITIAL (decl));
11708 : 81675000 : WALK_SUBTREE (DECL_SIZE (decl));
11709 : 81675000 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
11710 : : }
11711 : 132780667 : WALK_SUBTREE_TAIL (BIND_EXPR_BODY (t));
11712 : : }
11713 : :
11714 : 141098278 : case STATEMENT_LIST:
11715 : 141098278 : {
11716 : 141098278 : tree_stmt_iterator i;
11717 : 512279927 : for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
11718 : 371296535 : WALK_SUBTREE (*tsi_stmt_ptr (i));
11719 : : }
11720 : 140983392 : break;
11721 : :
11722 : 1640797 : case OMP_CLAUSE:
11723 : 1640797 : {
11724 : 1640797 : int len = omp_clause_num_ops[OMP_CLAUSE_CODE (t)];
11725 : 4290832 : for (int i = 0; i < len; i++)
11726 : 2650035 : WALK_SUBTREE (OMP_CLAUSE_OPERAND (t, i));
11727 : 1640797 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11728 : : }
11729 : :
11730 : 29184302 : case TARGET_EXPR:
11731 : 29184302 : {
11732 : 29184302 : int i, len;
11733 : :
11734 : : /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
11735 : : But, we only want to walk once. */
11736 : 29184302 : len = (TREE_OPERAND (t, 3) == TREE_OPERAND (t, 1)) ? 2 : 3;
11737 : 116690541 : for (i = 0; i < len; ++i)
11738 : 87528362 : WALK_SUBTREE (TREE_OPERAND (t, i));
11739 : 29162179 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len));
11740 : : }
11741 : :
11742 : 77718529 : case DECL_EXPR:
11743 : : /* If this is a TYPE_DECL, walk into the fields of the type that it's
11744 : : defining. We only want to walk into these fields of a type in this
11745 : : case and not in the general case of a mere reference to the type.
11746 : :
11747 : : The criterion is as follows: if the field can be an expression, it
11748 : : must be walked only here. This should be in keeping with the fields
11749 : : that are directly gimplified in gimplify_type_sizes in order for the
11750 : : mark/copy-if-shared/unmark machinery of the gimplifier to work with
11751 : : variable-sized types.
11752 : :
11753 : : Note that DECLs get walked as part of processing the BIND_EXPR. */
11754 : 77718529 : if (TREE_CODE (DECL_EXPR_DECL (t)) == TYPE_DECL)
11755 : : {
11756 : : /* Call the function for the decl so e.g. copy_tree_body_r can
11757 : : replace it with the remapped one. */
11758 : 795727 : result = (*func) (&DECL_EXPR_DECL (t), &walk_subtrees, data);
11759 : 795727 : if (result || !walk_subtrees)
11760 : 48548 : return result;
11761 : :
11762 : 747179 : tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (t));
11763 : 747179 : if (TREE_CODE (*type_p) == ERROR_MARK)
11764 : : return NULL_TREE;
11765 : :
11766 : : /* Call the function for the type. See if it returns anything or
11767 : : doesn't want us to continue. If we are to continue, walk both
11768 : : the normal fields and those for the declaration case. */
11769 : 747179 : result = (*func) (type_p, &walk_subtrees, data);
11770 : 747179 : if (result || !walk_subtrees)
11771 : 70669 : return result;
11772 : :
11773 : 676510 : tree type = *type_p;
11774 : :
11775 : : /* But do not walk a pointed-to type since it may itself need to
11776 : : be walked in the declaration case if it isn't anonymous. */
11777 : 676510 : if (!POINTER_TYPE_P (type))
11778 : : {
11779 : 660817 : result = walk_type_fields (type, func, data, pset, lh);
11780 : 660817 : if (result)
11781 : : return result;
11782 : : }
11783 : :
11784 : : /* If this is a record type, also walk the fields. */
11785 : 676510 : if (RECORD_OR_UNION_TYPE_P (type))
11786 : : {
11787 : 258948 : tree field;
11788 : :
11789 : 1069903 : for (field = TYPE_FIELDS (type); field;
11790 : 810955 : field = DECL_CHAIN (field))
11791 : : {
11792 : : /* We'd like to look at the type of the field, but we can
11793 : : easily get infinite recursion. So assume it's pointed
11794 : : to elsewhere in the tree. Also, ignore things that
11795 : : aren't fields. */
11796 : 810955 : if (TREE_CODE (field) != FIELD_DECL)
11797 : 629785 : continue;
11798 : :
11799 : 181170 : WALK_SUBTREE (DECL_FIELD_OFFSET (field));
11800 : 181170 : WALK_SUBTREE (DECL_SIZE (field));
11801 : 181170 : WALK_SUBTREE (DECL_SIZE_UNIT (field));
11802 : 181170 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
11803 : 0 : WALK_SUBTREE (DECL_QUALIFIER (field));
11804 : : }
11805 : : }
11806 : :
11807 : : /* Same for scalar types. */
11808 : 417562 : else if (TREE_CODE (type) == BOOLEAN_TYPE
11809 : : || TREE_CODE (type) == ENUMERAL_TYPE
11810 : 417562 : || TREE_CODE (type) == INTEGER_TYPE
11811 : 417525 : || TREE_CODE (type) == FIXED_POINT_TYPE
11812 : 417525 : || TREE_CODE (type) == REAL_TYPE)
11813 : : {
11814 : 37 : WALK_SUBTREE (TYPE_MIN_VALUE (type));
11815 : 37 : WALK_SUBTREE (TYPE_MAX_VALUE (type));
11816 : : }
11817 : :
11818 : 676510 : WALK_SUBTREE (TYPE_SIZE (type));
11819 : 676510 : WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (type));
11820 : : }
11821 : : /* FALLTHRU */
11822 : :
11823 : 22722844097 : default:
11824 : 22722844097 : if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
11825 : : {
11826 : 17483708377 : int i, len;
11827 : :
11828 : : /* Walk over all the sub-trees of this operand. */
11829 : 17483708377 : len = TREE_OPERAND_LENGTH (t);
11830 : :
11831 : : /* Go through the subtrees. We need to do this in forward order so
11832 : : that the scope of a FOR_EXPR is handled properly. */
11833 : 17483708377 : if (len)
11834 : : {
11835 : 36914213475 : for (i = 0; i < len - 1; ++i)
11836 : 19542975102 : WALK_SUBTREE (TREE_OPERAND (t, i));
11837 : 17371238373 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len - 1));
11838 : : }
11839 : : }
11840 : : /* If this is a type, walk the needed fields in the type. */
11841 : 5239135720 : else if (TYPE_P (t))
11842 : 3289875336 : return walk_type_fields (t, func, data, pset, lh);
11843 : : break;
11844 : : }
11845 : :
11846 : : /* We didn't find what we were looking for. */
11847 : : return NULL_TREE;
11848 : :
11849 : : #undef WALK_SUBTREE_TAIL
11850 : : }
11851 : : #undef WALK_SUBTREE
11852 : :
11853 : : /* Like walk_tree, but does not walk duplicate nodes more than once. */
11854 : :
11855 : : tree
11856 : 2289410236 : walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data,
11857 : : walk_tree_lh lh)
11858 : : {
11859 : 2289410236 : tree result;
11860 : :
11861 : 2289410236 : hash_set<tree> pset;
11862 : 2289410236 : result = walk_tree_1 (tp, func, data, &pset, lh);
11863 : 2289410236 : return result;
11864 : 2289410236 : }
11865 : :
11866 : :
11867 : : tree
11868 : 784551264 : tree_block (tree t)
11869 : : {
11870 : 784551264 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
11871 : :
11872 : 784551264 : if (IS_EXPR_CODE_CLASS (c))
11873 : 784551264 : return LOCATION_BLOCK (t->exp.locus);
11874 : 0 : gcc_unreachable ();
11875 : : return NULL;
11876 : : }
11877 : :
11878 : : void
11879 : 410842147 : tree_set_block (tree t, tree b)
11880 : : {
11881 : 410842147 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
11882 : :
11883 : 410842147 : if (IS_EXPR_CODE_CLASS (c))
11884 : : {
11885 : 410842147 : t->exp.locus = set_block (t->exp.locus, b);
11886 : : }
11887 : : else
11888 : 0 : gcc_unreachable ();
11889 : 410842147 : }
11890 : :
11891 : : /* Create a nameless artificial label and put it in the current
11892 : : function context. The label has a location of LOC. Returns the
11893 : : newly created label. */
11894 : :
11895 : : tree
11896 : 29281000 : create_artificial_label (location_t loc)
11897 : : {
11898 : 29281000 : tree lab = build_decl (loc,
11899 : : LABEL_DECL, NULL_TREE, void_type_node);
11900 : :
11901 : 29281000 : DECL_ARTIFICIAL (lab) = 1;
11902 : 29281000 : DECL_IGNORED_P (lab) = 1;
11903 : 29281000 : DECL_CONTEXT (lab) = current_function_decl;
11904 : 29281000 : return lab;
11905 : : }
11906 : :
11907 : : /* Given a tree, try to return a useful variable name that we can use
11908 : : to prefix a temporary that is being assigned the value of the tree.
11909 : : I.E. given <temp> = &A, return A. */
11910 : :
11911 : : const char *
11912 : 24086587 : get_name (tree t)
11913 : : {
11914 : 25880339 : tree stripped_decl;
11915 : :
11916 : 25880339 : stripped_decl = t;
11917 : 25880339 : STRIP_NOPS (stripped_decl);
11918 : 25880339 : if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl))
11919 : 3978871 : return IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
11920 : 21901468 : else if (TREE_CODE (stripped_decl) == SSA_NAME)
11921 : : {
11922 : 1245801 : tree name = SSA_NAME_IDENTIFIER (stripped_decl);
11923 : 292414 : if (!name)
11924 : : return NULL;
11925 : 291053 : return IDENTIFIER_POINTER (name);
11926 : : }
11927 : : else
11928 : : {
11929 : 20655667 : switch (TREE_CODE (stripped_decl))
11930 : : {
11931 : 1793752 : case ADDR_EXPR:
11932 : 1793752 : return get_name (TREE_OPERAND (stripped_decl, 0));
11933 : : default:
11934 : : return NULL;
11935 : : }
11936 : : }
11937 : : }
11938 : :
11939 : : /* Return true if TYPE has a variable argument list. */
11940 : :
11941 : : bool
11942 : 199987139 : stdarg_p (const_tree fntype)
11943 : : {
11944 : 199987139 : function_args_iterator args_iter;
11945 : 199987139 : tree n = NULL_TREE, t;
11946 : :
11947 : 199987139 : if (!fntype)
11948 : : return false;
11949 : :
11950 : 199855293 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
11951 : : return true;
11952 : :
11953 : 818288372 : FOREACH_FUNCTION_ARGS (fntype, t, args_iter)
11954 : : {
11955 : 619097273 : n = t;
11956 : : }
11957 : :
11958 : 199191099 : return n != NULL_TREE && n != void_type_node;
11959 : : }
11960 : :
11961 : : /* Return true if TYPE has a prototype. */
11962 : :
11963 : : bool
11964 : 680282994 : prototype_p (const_tree fntype)
11965 : : {
11966 : 680282994 : tree t;
11967 : :
11968 : 680282994 : gcc_assert (fntype != NULL_TREE);
11969 : :
11970 : 680282994 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
11971 : : return true;
11972 : :
11973 : 679530824 : t = TYPE_ARG_TYPES (fntype);
11974 : 679530824 : return (t != NULL_TREE);
11975 : : }
11976 : :
11977 : : /* If BLOCK is inlined from an __attribute__((__artificial__))
11978 : : routine, return pointer to location from where it has been
11979 : : called. */
11980 : : location_t *
11981 : 157299 : block_nonartificial_location (tree block)
11982 : : {
11983 : 157299 : location_t *ret = NULL;
11984 : :
11985 : 401806 : while (block && TREE_CODE (block) == BLOCK
11986 : 484184 : && BLOCK_ABSTRACT_ORIGIN (block))
11987 : : {
11988 : 148256 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
11989 : 148256 : if (TREE_CODE (ao) == FUNCTION_DECL)
11990 : : {
11991 : : /* If AO is an artificial inline, point RET to the
11992 : : call site locus at which it has been inlined and continue
11993 : : the loop, in case AO's caller is also an artificial
11994 : : inline. */
11995 : 62713 : if (DECL_DECLARED_INLINE_P (ao)
11996 : 62713 : && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
11997 : 1790 : ret = &BLOCK_SOURCE_LOCATION (block);
11998 : : else
11999 : : break;
12000 : : }
12001 : 85543 : else if (TREE_CODE (ao) != BLOCK)
12002 : : break;
12003 : :
12004 : 87333 : block = BLOCK_SUPERCONTEXT (block);
12005 : : }
12006 : 157299 : return ret;
12007 : : }
12008 : :
12009 : :
12010 : : /* If EXP is inlined from an __attribute__((__artificial__))
12011 : : function, return the location of the original call expression. */
12012 : :
12013 : : location_t
12014 : 125 : tree_nonartificial_location (tree exp)
12015 : : {
12016 : 125 : location_t *loc = block_nonartificial_location (TREE_BLOCK (exp));
12017 : :
12018 : 125 : if (loc)
12019 : 0 : return *loc;
12020 : : else
12021 : 125 : return EXPR_LOCATION (exp);
12022 : : }
12023 : :
12024 : : /* Return the location into which EXP has been inlined. Analogous
12025 : : to tree_nonartificial_location() above but not limited to artificial
12026 : : functions declared inline. If SYSTEM_HEADER is true, return
12027 : : the macro expansion point of the location if it's in a system header */
12028 : :
12029 : : location_t
12030 : 0 : tree_inlined_location (tree exp, bool system_header /* = true */)
12031 : : {
12032 : 0 : location_t loc = UNKNOWN_LOCATION;
12033 : :
12034 : 0 : tree block = TREE_BLOCK (exp);
12035 : :
12036 : 0 : while (block && TREE_CODE (block) == BLOCK
12037 : 0 : && BLOCK_ABSTRACT_ORIGIN (block))
12038 : : {
12039 : 0 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12040 : 0 : if (TREE_CODE (ao) == FUNCTION_DECL)
12041 : 0 : loc = BLOCK_SOURCE_LOCATION (block);
12042 : 0 : else if (TREE_CODE (ao) != BLOCK)
12043 : : break;
12044 : :
12045 : 0 : block = BLOCK_SUPERCONTEXT (block);
12046 : : }
12047 : :
12048 : 0 : if (loc == UNKNOWN_LOCATION)
12049 : : {
12050 : 0 : loc = EXPR_LOCATION (exp);
12051 : 0 : if (system_header)
12052 : : /* Only consider macro expansion when the block traversal failed
12053 : : to find a location. Otherwise it's not relevant. */
12054 : 0 : return expansion_point_location_if_in_system_header (loc);
12055 : : }
12056 : :
12057 : : return loc;
12058 : : }
12059 : :
12060 : : /* These are the hash table functions for the hash table of OPTIMIZATION_NODE
12061 : : nodes. */
12062 : :
12063 : : /* Return the hash code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
12064 : :
12065 : : hashval_t
12066 : 987036918 : cl_option_hasher::hash (tree x)
12067 : : {
12068 : 987036918 : const_tree const t = x;
12069 : :
12070 : 987036918 : if (TREE_CODE (t) == OPTIMIZATION_NODE)
12071 : 116448758 : return cl_optimization_hash (TREE_OPTIMIZATION (t));
12072 : 870588160 : else if (TREE_CODE (t) == TARGET_OPTION_NODE)
12073 : 870588160 : return cl_target_option_hash (TREE_TARGET_OPTION (t));
12074 : : else
12075 : 0 : gcc_unreachable ();
12076 : : }
12077 : :
12078 : : /* Return nonzero if the value represented by *X (an OPTIMIZATION or
12079 : : TARGET_OPTION tree node) is the same as that given by *Y, which is the
12080 : : same. */
12081 : :
12082 : : bool
12083 : 1060657283 : cl_option_hasher::equal (tree x, tree y)
12084 : : {
12085 : 1060657283 : const_tree const xt = x;
12086 : 1060657283 : const_tree const yt = y;
12087 : :
12088 : 1060657283 : if (TREE_CODE (xt) != TREE_CODE (yt))
12089 : : return false;
12090 : :
12091 : 610677590 : if (TREE_CODE (xt) == OPTIMIZATION_NODE)
12092 : 113640285 : return cl_optimization_option_eq (TREE_OPTIMIZATION (xt),
12093 : 113640285 : TREE_OPTIMIZATION (yt));
12094 : 497037305 : else if (TREE_CODE (xt) == TARGET_OPTION_NODE)
12095 : 497037305 : return cl_target_option_eq (TREE_TARGET_OPTION (xt),
12096 : 497037305 : TREE_TARGET_OPTION (yt));
12097 : : else
12098 : 0 : gcc_unreachable ();
12099 : : }
12100 : :
12101 : : /* Build an OPTIMIZATION_NODE based on the options in OPTS and OPTS_SET. */
12102 : :
12103 : : tree
12104 : 113616865 : build_optimization_node (struct gcc_options *opts,
12105 : : struct gcc_options *opts_set)
12106 : : {
12107 : 113616865 : tree t;
12108 : :
12109 : : /* Use the cache of optimization nodes. */
12110 : :
12111 : 113616865 : cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node),
12112 : : opts, opts_set);
12113 : :
12114 : 113616865 : tree *slot = cl_option_hash_table->find_slot (cl_optimization_node, INSERT);
12115 : 113616865 : t = *slot;
12116 : 113616865 : if (!t)
12117 : : {
12118 : : /* Insert this one into the hash table. */
12119 : 284999 : t = cl_optimization_node;
12120 : 284999 : *slot = t;
12121 : :
12122 : : /* Make a new node for next time round. */
12123 : 284999 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
12124 : : }
12125 : :
12126 : 113616865 : return t;
12127 : : }
12128 : :
12129 : : /* Build a TARGET_OPTION_NODE based on the options in OPTS and OPTS_SET. */
12130 : :
12131 : : tree
12132 : 87741878 : build_target_option_node (struct gcc_options *opts,
12133 : : struct gcc_options *opts_set)
12134 : : {
12135 : 87741878 : tree t;
12136 : :
12137 : : /* Use the cache of optimization nodes. */
12138 : :
12139 : 87741878 : cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node),
12140 : : opts, opts_set);
12141 : :
12142 : 87741878 : tree *slot = cl_option_hash_table->find_slot (cl_target_option_node, INSERT);
12143 : 87741878 : t = *slot;
12144 : 87741878 : if (!t)
12145 : : {
12146 : : /* Insert this one into the hash table. */
12147 : 827065 : t = cl_target_option_node;
12148 : 827065 : *slot = t;
12149 : :
12150 : : /* Make a new node for next time round. */
12151 : 827065 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
12152 : : }
12153 : :
12154 : 87741878 : return t;
12155 : : }
12156 : :
12157 : : /* Clear TREE_TARGET_GLOBALS of all TARGET_OPTION_NODE trees,
12158 : : so that they aren't saved during PCH writing. */
12159 : :
12160 : : void
12161 : 470 : prepare_target_option_nodes_for_pch (void)
12162 : : {
12163 : 470 : hash_table<cl_option_hasher>::iterator iter = cl_option_hash_table->begin ();
12164 : 2820 : for (; iter != cl_option_hash_table->end (); ++iter)
12165 : 940 : if (TREE_CODE (*iter) == TARGET_OPTION_NODE)
12166 : 470 : TREE_TARGET_GLOBALS (*iter) = NULL;
12167 : 470 : }
12168 : :
12169 : : /* Determine the "ultimate origin" of a block. */
12170 : :
12171 : : tree
12172 : 194778746 : block_ultimate_origin (const_tree block)
12173 : : {
12174 : 194778746 : tree origin = BLOCK_ABSTRACT_ORIGIN (block);
12175 : :
12176 : 194778746 : if (origin == NULL_TREE)
12177 : : return NULL_TREE;
12178 : : else
12179 : : {
12180 : 226551369 : gcc_checking_assert ((DECL_P (origin)
12181 : : && DECL_ORIGIN (origin) == origin)
12182 : : || BLOCK_ORIGIN (origin) == origin);
12183 : : return origin;
12184 : : }
12185 : : }
12186 : :
12187 : : /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates
12188 : : no instruction. */
12189 : :
12190 : : bool
12191 : 1310037088 : tree_nop_conversion_p (const_tree outer_type, const_tree inner_type)
12192 : : {
12193 : : /* Do not strip casts into or out of differing address spaces. */
12194 : 1310037088 : if (POINTER_TYPE_P (outer_type)
12195 : 1310037088 : && TYPE_ADDR_SPACE (TREE_TYPE (outer_type)) != ADDR_SPACE_GENERIC)
12196 : : {
12197 : 647 : if (!POINTER_TYPE_P (inner_type)
12198 : 647 : || (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
12199 : 570 : != TYPE_ADDR_SPACE (TREE_TYPE (inner_type))))
12200 : : return false;
12201 : : }
12202 : 1310036441 : else if (POINTER_TYPE_P (inner_type)
12203 : 1310036441 : && TYPE_ADDR_SPACE (TREE_TYPE (inner_type)) != ADDR_SPACE_GENERIC)
12204 : : {
12205 : : /* We already know that outer_type is not a pointer with
12206 : : a non-generic address space. */
12207 : : return false;
12208 : : }
12209 : :
12210 : : /* Use precision rather then machine mode when we can, which gives
12211 : : the correct answer even for submode (bit-field) types. */
12212 : 1310034492 : if ((INTEGRAL_TYPE_P (outer_type)
12213 : 466580811 : || POINTER_TYPE_P (outer_type)
12214 : 69412065 : || TREE_CODE (outer_type) == OFFSET_TYPE)
12215 : 1240633293 : && (INTEGRAL_TYPE_P (inner_type)
12216 : 467075350 : || POINTER_TYPE_P (inner_type)
12217 : 992007 : || TREE_CODE (inner_type) == OFFSET_TYPE))
12218 : 1239664929 : return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type);
12219 : :
12220 : : /* Otherwise fall back on comparing machine modes (e.g. for
12221 : : aggregate types, floats). */
12222 : 70369563 : return TYPE_MODE (outer_type) == TYPE_MODE (inner_type);
12223 : : }
12224 : :
12225 : : /* Return true iff conversion in EXP generates no instruction. Mark
12226 : : it inline so that we fully inline into the stripping functions even
12227 : : though we have two uses of this function. */
12228 : :
12229 : : static inline bool
12230 : 16789666399 : tree_nop_conversion (const_tree exp)
12231 : : {
12232 : 16789666399 : tree outer_type, inner_type;
12233 : :
12234 : 16789666399 : if (location_wrapper_p (exp))
12235 : : return true;
12236 : 16747460813 : if (!CONVERT_EXPR_P (exp)
12237 : 15939428247 : && TREE_CODE (exp) != NON_LVALUE_EXPR)
12238 : : return false;
12239 : :
12240 : 822952700 : outer_type = TREE_TYPE (exp);
12241 : 822952700 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12242 : 822952700 : if (!inner_type || inner_type == error_mark_node)
12243 : : return false;
12244 : :
12245 : 822952700 : return tree_nop_conversion_p (outer_type, inner_type);
12246 : : }
12247 : :
12248 : : /* Return true iff conversion in EXP generates no instruction. Don't
12249 : : consider conversions changing the signedness. */
12250 : :
12251 : : static bool
12252 : 1779422707 : tree_sign_nop_conversion (const_tree exp)
12253 : : {
12254 : 1779422707 : tree outer_type, inner_type;
12255 : :
12256 : 1779422707 : if (!tree_nop_conversion (exp))
12257 : : return false;
12258 : :
12259 : 150848051 : outer_type = TREE_TYPE (exp);
12260 : 150848051 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12261 : :
12262 : 150848051 : return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type)
12263 : 150848051 : && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
12264 : : }
12265 : :
12266 : : /* Strip conversions from EXP according to tree_nop_conversion and
12267 : : return the resulting expression. */
12268 : :
12269 : : tree
12270 : 14429734209 : tree_strip_nop_conversions (tree exp)
12271 : : {
12272 : 15010243692 : while (tree_nop_conversion (exp))
12273 : 580509483 : exp = TREE_OPERAND (exp, 0);
12274 : 14429734209 : return exp;
12275 : : }
12276 : :
12277 : : /* Strip conversions from EXP according to tree_sign_nop_conversion
12278 : : and return the resulting expression. */
12279 : :
12280 : : tree
12281 : 1652754104 : tree_strip_sign_nop_conversions (tree exp)
12282 : : {
12283 : 1779422707 : while (tree_sign_nop_conversion (exp))
12284 : 126668603 : exp = TREE_OPERAND (exp, 0);
12285 : 1652754104 : return exp;
12286 : : }
12287 : :
12288 : : /* Avoid any floating point extensions from EXP. */
12289 : : tree
12290 : 79560553 : strip_float_extensions (tree exp)
12291 : : {
12292 : 79686635 : tree sub, expt, subt;
12293 : :
12294 : : /* For floating point constant look up the narrowest type that can hold
12295 : : it properly and handle it like (type)(narrowest_type)constant.
12296 : : This way we can optimize for instance a=a*2.0 where "a" is float
12297 : : but 2.0 is double constant. */
12298 : 79686635 : if (TREE_CODE (exp) == REAL_CST && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp)))
12299 : : {
12300 : 2396346 : REAL_VALUE_TYPE orig;
12301 : 2396346 : tree type = NULL;
12302 : :
12303 : 2396346 : orig = TREE_REAL_CST (exp);
12304 : 2396346 : if (TYPE_PRECISION (TREE_TYPE (exp)) > TYPE_PRECISION (float_type_node)
12305 : 2396346 : && exact_real_truncate (TYPE_MODE (float_type_node), &orig))
12306 : 139846 : type = float_type_node;
12307 : 2256500 : else if (TYPE_PRECISION (TREE_TYPE (exp))
12308 : 2256500 : > TYPE_PRECISION (double_type_node)
12309 : 2256500 : && exact_real_truncate (TYPE_MODE (double_type_node), &orig))
12310 : 35084 : type = double_type_node;
12311 : 2396346 : if (type)
12312 : 174930 : return build_real_truncate (type, orig);
12313 : : }
12314 : :
12315 : 79511705 : if (!CONVERT_EXPR_P (exp))
12316 : : return exp;
12317 : :
12318 : 4725920 : sub = TREE_OPERAND (exp, 0);
12319 : 4725920 : subt = TREE_TYPE (sub);
12320 : 4725920 : expt = TREE_TYPE (exp);
12321 : :
12322 : 4725920 : if (!FLOAT_TYPE_P (subt))
12323 : : return exp;
12324 : :
12325 : 448558 : if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_FLOAT_TYPE_P (subt))
12326 : : return exp;
12327 : :
12328 : 149884 : if (element_precision (subt) > element_precision (expt))
12329 : : return exp;
12330 : :
12331 : : return strip_float_extensions (sub);
12332 : : }
12333 : :
12334 : : /* Strip out all handled components that produce invariant
12335 : : offsets. */
12336 : :
12337 : : const_tree
12338 : 5182960166 : strip_invariant_refs (const_tree op)
12339 : : {
12340 : 5982258394 : while (handled_component_p (op))
12341 : : {
12342 : 810370389 : switch (TREE_CODE (op))
12343 : : {
12344 : 157368652 : case ARRAY_REF:
12345 : 157368652 : case ARRAY_RANGE_REF:
12346 : 157368652 : if (!is_gimple_constant (TREE_OPERAND (op, 1))
12347 : 147687376 : || TREE_OPERAND (op, 2) != NULL_TREE
12348 : 146425845 : || TREE_OPERAND (op, 3) != NULL_TREE)
12349 : : return NULL;
12350 : : break;
12351 : :
12352 : 652818480 : case COMPONENT_REF:
12353 : 652818480 : if (TREE_OPERAND (op, 2) != NULL_TREE)
12354 : : return NULL;
12355 : : break;
12356 : :
12357 : 799298228 : default:;
12358 : : }
12359 : 799298228 : op = TREE_OPERAND (op, 0);
12360 : : }
12361 : :
12362 : : return op;
12363 : : }
12364 : :
12365 : : /* Strip handled components with zero offset from OP. */
12366 : :
12367 : : tree
12368 : 554284 : strip_zero_offset_components (tree op)
12369 : : {
12370 : 554284 : while (TREE_CODE (op) == COMPONENT_REF
12371 : 512863 : && integer_zerop (DECL_FIELD_OFFSET (TREE_OPERAND (op, 1)))
12372 : 1211401 : && integer_zerop (DECL_FIELD_BIT_OFFSET (TREE_OPERAND (op, 1))))
12373 : 217028 : op = TREE_OPERAND (op, 0);
12374 : 554284 : return op;
12375 : : }
12376 : :
12377 : : static GTY(()) tree gcc_eh_personality_decl;
12378 : :
12379 : : /* Return the GCC personality function decl. */
12380 : :
12381 : : tree
12382 : 372 : lhd_gcc_personality (void)
12383 : : {
12384 : 372 : if (!gcc_eh_personality_decl)
12385 : 136 : gcc_eh_personality_decl = build_personality_function ("gcc");
12386 : 372 : return gcc_eh_personality_decl;
12387 : : }
12388 : :
12389 : : /* TARGET is a call target of GIMPLE call statement
12390 : : (obtained by gimple_call_fn). Return true if it is
12391 : : OBJ_TYPE_REF representing an virtual call of C++ method.
12392 : : (As opposed to OBJ_TYPE_REF representing objc calls
12393 : : through a cast where middle-end devirtualization machinery
12394 : : can't apply.) FOR_DUMP_P is true when being called from
12395 : : the dump routines. */
12396 : :
12397 : : bool
12398 : 26143642 : virtual_method_call_p (const_tree target, bool for_dump_p)
12399 : : {
12400 : 26143642 : if (TREE_CODE (target) != OBJ_TYPE_REF)
12401 : : return false;
12402 : 1023911 : tree t = TREE_TYPE (target);
12403 : 1023911 : gcc_checking_assert (TREE_CODE (t) == POINTER_TYPE);
12404 : 1023911 : t = TREE_TYPE (t);
12405 : 1023911 : if (TREE_CODE (t) == FUNCTION_TYPE)
12406 : : return false;
12407 : 1023259 : gcc_checking_assert (TREE_CODE (t) == METHOD_TYPE);
12408 : : /* If we do not have BINFO associated, it means that type was built
12409 : : without devirtualization enabled. Do not consider this a virtual
12410 : : call. */
12411 : 1023259 : if (!TYPE_BINFO (obj_type_ref_class (target, for_dump_p)))
12412 : : return false;
12413 : : return true;
12414 : : }
12415 : :
12416 : : /* Lookup sub-BINFO of BINFO of TYPE at offset POS. */
12417 : :
12418 : : static tree
12419 : 75 : lookup_binfo_at_offset (tree binfo, tree type, HOST_WIDE_INT pos)
12420 : : {
12421 : 75 : unsigned int i;
12422 : 75 : tree base_binfo, b;
12423 : :
12424 : 84 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12425 : 75 : if (pos == tree_to_shwi (BINFO_OFFSET (base_binfo))
12426 : 75 : && types_same_for_odr (TREE_TYPE (base_binfo), type))
12427 : : return base_binfo;
12428 : 50 : else if ((b = lookup_binfo_at_offset (base_binfo, type, pos)) != NULL)
12429 : : return b;
12430 : : return NULL;
12431 : : }
12432 : :
12433 : : /* Try to find a base info of BINFO that would have its field decl at offset
12434 : : OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
12435 : : found, return, otherwise return NULL_TREE. */
12436 : :
12437 : : tree
12438 : 292446 : get_binfo_at_offset (tree binfo, poly_int64 offset, tree expected_type)
12439 : : {
12440 : 292446 : tree type = BINFO_TYPE (binfo);
12441 : :
12442 : 764198 : while (true)
12443 : : {
12444 : 528322 : HOST_WIDE_INT pos, size;
12445 : 528322 : tree fld;
12446 : 528322 : int i;
12447 : :
12448 : 528322 : if (types_same_for_odr (type, expected_type))
12449 : 292446 : return binfo;
12450 : 235876 : if (maybe_lt (offset, 0))
12451 : : return NULL_TREE;
12452 : :
12453 : 1111858 : for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
12454 : : {
12455 : 1111858 : if (TREE_CODE (fld) != FIELD_DECL || !DECL_ARTIFICIAL (fld))
12456 : 875809 : continue;
12457 : :
12458 : 236049 : pos = int_bit_position (fld);
12459 : 236049 : size = tree_to_uhwi (DECL_SIZE (fld));
12460 : 1112031 : if (known_in_range_p (offset, pos, size))
12461 : : break;
12462 : : }
12463 : 235876 : if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE)
12464 : : return NULL_TREE;
12465 : :
12466 : : /* Offset 0 indicates the primary base, whose vtable contents are
12467 : : represented in the binfo for the derived class. */
12468 : 235876 : else if (maybe_ne (offset, 0))
12469 : : {
12470 : 184 : tree found_binfo = NULL, base_binfo;
12471 : : /* Offsets in BINFO are in bytes relative to the whole structure
12472 : : while POS is in bits relative to the containing field. */
12473 : 184 : int binfo_offset = (tree_to_shwi (BINFO_OFFSET (binfo)) + pos
12474 : 184 : / BITS_PER_UNIT);
12475 : :
12476 : 347 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12477 : 322 : if (tree_to_shwi (BINFO_OFFSET (base_binfo)) == binfo_offset
12478 : 322 : && types_same_for_odr (TREE_TYPE (base_binfo), TREE_TYPE (fld)))
12479 : : {
12480 : : found_binfo = base_binfo;
12481 : : break;
12482 : : }
12483 : 184 : if (found_binfo)
12484 : : binfo = found_binfo;
12485 : : else
12486 : 25 : binfo = lookup_binfo_at_offset (binfo, TREE_TYPE (fld),
12487 : : binfo_offset);
12488 : : }
12489 : :
12490 : 235876 : type = TREE_TYPE (fld);
12491 : 235876 : offset -= pos;
12492 : 235876 : }
12493 : : }
12494 : :
12495 : : /* PR 84195: Replace control characters in "unescaped" with their
12496 : : escaped equivalents. Allow newlines if -fmessage-length has
12497 : : been set to a non-zero value. This is done here, rather than
12498 : : where the attribute is recorded as the message length can
12499 : : change between these two locations. */
12500 : :
12501 : : void
12502 : 126963 : escaped_string::escape (const char *unescaped)
12503 : : {
12504 : 126963 : char *escaped;
12505 : 126963 : size_t i, new_i, len;
12506 : :
12507 : 126963 : if (m_owned)
12508 : 8 : free (m_str);
12509 : :
12510 : 126963 : m_str = const_cast<char *> (unescaped);
12511 : 126963 : m_owned = false;
12512 : :
12513 : 126963 : if (unescaped == NULL || *unescaped == 0)
12514 : : return;
12515 : :
12516 : 126955 : len = strlen (unescaped);
12517 : 126955 : escaped = NULL;
12518 : 126955 : new_i = 0;
12519 : :
12520 : 3717516 : for (i = 0; i < len; i++)
12521 : : {
12522 : 3590561 : char c = unescaped[i];
12523 : :
12524 : 3590561 : if (!ISCNTRL (c))
12525 : : {
12526 : 3590476 : if (escaped)
12527 : 33 : escaped[new_i++] = c;
12528 : 3590476 : continue;
12529 : : }
12530 : :
12531 : 85 : if (c != '\n' || !pp_is_wrapping_line (global_dc->get_reference_printer ()))
12532 : : {
12533 : 77 : if (escaped == NULL)
12534 : : {
12535 : : /* We only allocate space for a new string if we
12536 : : actually encounter a control character that
12537 : : needs replacing. */
12538 : 19 : escaped = (char *) xmalloc (len * 2 + 1);
12539 : 19 : strncpy (escaped, unescaped, i);
12540 : 19 : new_i = i;
12541 : : }
12542 : :
12543 : 77 : escaped[new_i++] = '\\';
12544 : :
12545 : 77 : switch (c)
12546 : : {
12547 : 8 : case '\a': escaped[new_i++] = 'a'; break;
12548 : 8 : case '\b': escaped[new_i++] = 'b'; break;
12549 : 8 : case '\f': escaped[new_i++] = 'f'; break;
12550 : 15 : case '\n': escaped[new_i++] = 'n'; break;
12551 : 15 : case '\r': escaped[new_i++] = 'r'; break;
12552 : 15 : case '\t': escaped[new_i++] = 't'; break;
12553 : 8 : case '\v': escaped[new_i++] = 'v'; break;
12554 : 0 : default: escaped[new_i++] = '?'; break;
12555 : : }
12556 : : }
12557 : 8 : else if (escaped)
12558 : 4 : escaped[new_i++] = c;
12559 : : }
12560 : :
12561 : 126955 : if (escaped)
12562 : : {
12563 : 19 : escaped[new_i] = 0;
12564 : 19 : m_str = escaped;
12565 : 19 : m_owned = true;
12566 : : }
12567 : : }
12568 : :
12569 : : /* Warn about a use of an identifier which was marked deprecated. Returns
12570 : : whether a warning was given. */
12571 : :
12572 : : bool
12573 : 1223271 : warn_deprecated_use (tree node, tree attr)
12574 : : {
12575 : 1223271 : escaped_string msg;
12576 : :
12577 : 1223271 : if (node == 0 || !warn_deprecated_decl)
12578 : : return false;
12579 : :
12580 : 1218089 : if (!attr)
12581 : : {
12582 : 1111249 : if (DECL_P (node))
12583 : 1111121 : attr = DECL_ATTRIBUTES (node);
12584 : 128 : else if (TYPE_P (node))
12585 : : {
12586 : 128 : tree decl = TYPE_STUB_DECL (node);
12587 : 128 : if (decl)
12588 : 104 : attr = TYPE_ATTRIBUTES (TREE_TYPE (decl));
12589 : 24 : else if ((decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (node)))
12590 : : != NULL_TREE)
12591 : : {
12592 : 6 : node = TREE_TYPE (decl);
12593 : 6 : attr = TYPE_ATTRIBUTES (node);
12594 : : }
12595 : : }
12596 : : }
12597 : :
12598 : 1111249 : if (attr)
12599 : 126650 : attr = lookup_attribute ("deprecated", attr);
12600 : :
12601 : 126650 : if (attr)
12602 : 126644 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12603 : :
12604 : 1218089 : bool w = false;
12605 : 1218089 : if (DECL_P (node))
12606 : : {
12607 : 1217951 : auto_diagnostic_group d;
12608 : 1217951 : if (msg)
12609 : 126595 : w = warning (OPT_Wdeprecated_declarations,
12610 : : "%qD is deprecated: %s", node, (const char *) msg);
12611 : : else
12612 : 1091356 : w = warning (OPT_Wdeprecated_declarations,
12613 : : "%qD is deprecated", node);
12614 : 1217951 : if (w)
12615 : 773 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12616 : 1217951 : }
12617 : 138 : else if (TYPE_P (node))
12618 : : {
12619 : 138 : tree what = NULL_TREE;
12620 : 138 : tree decl = TYPE_STUB_DECL (node);
12621 : :
12622 : 138 : if (TYPE_NAME (node))
12623 : : {
12624 : 133 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12625 : 10 : what = TYPE_NAME (node);
12626 : 123 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12627 : 123 : && DECL_NAME (TYPE_NAME (node)))
12628 : 123 : what = DECL_NAME (TYPE_NAME (node));
12629 : : }
12630 : :
12631 : 138 : auto_diagnostic_group d;
12632 : 138 : if (what)
12633 : : {
12634 : 133 : if (msg)
12635 : 47 : w = warning (OPT_Wdeprecated_declarations,
12636 : : "%qE is deprecated: %s", what, (const char *) msg);
12637 : : else
12638 : 86 : w = warning (OPT_Wdeprecated_declarations,
12639 : : "%qE is deprecated", what);
12640 : : }
12641 : : else
12642 : : {
12643 : 5 : if (msg)
12644 : 2 : w = warning (OPT_Wdeprecated_declarations,
12645 : : "type is deprecated: %s", (const char *) msg);
12646 : : else
12647 : 3 : w = warning (OPT_Wdeprecated_declarations,
12648 : : "type is deprecated");
12649 : : }
12650 : :
12651 : 138 : if (w && decl)
12652 : 111 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12653 : 138 : }
12654 : :
12655 : : return w;
12656 : 1223271 : }
12657 : :
12658 : : /* Error out with an identifier which was marked 'unavailable'. */
12659 : : void
12660 : 364 : error_unavailable_use (tree node, tree attr)
12661 : : {
12662 : 364 : escaped_string msg;
12663 : :
12664 : 364 : if (node == 0)
12665 : 0 : return;
12666 : :
12667 : 364 : if (!attr)
12668 : : {
12669 : 354 : if (DECL_P (node))
12670 : 294 : attr = DECL_ATTRIBUTES (node);
12671 : 60 : else if (TYPE_P (node))
12672 : : {
12673 : 60 : tree decl = TYPE_STUB_DECL (node);
12674 : 60 : if (decl)
12675 : 51 : attr = lookup_attribute ("unavailable",
12676 : 51 : TYPE_ATTRIBUTES (TREE_TYPE (decl)));
12677 : : }
12678 : : }
12679 : :
12680 : 354 : if (attr)
12681 : 152 : attr = lookup_attribute ("unavailable", attr);
12682 : :
12683 : 152 : if (attr)
12684 : 152 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12685 : :
12686 : 364 : if (DECL_P (node))
12687 : : {
12688 : 294 : auto_diagnostic_group d;
12689 : 294 : if (msg)
12690 : 117 : error ("%qD is unavailable: %s", node, (const char *) msg);
12691 : : else
12692 : 177 : error ("%qD is unavailable", node);
12693 : 294 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12694 : 294 : }
12695 : 70 : else if (TYPE_P (node))
12696 : : {
12697 : 70 : tree what = NULL_TREE;
12698 : 70 : tree decl = TYPE_STUB_DECL (node);
12699 : :
12700 : 70 : if (TYPE_NAME (node))
12701 : : {
12702 : 66 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12703 : 4 : what = TYPE_NAME (node);
12704 : 62 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12705 : 62 : && DECL_NAME (TYPE_NAME (node)))
12706 : 62 : what = DECL_NAME (TYPE_NAME (node));
12707 : : }
12708 : :
12709 : 70 : auto_diagnostic_group d;
12710 : 70 : if (what)
12711 : : {
12712 : 66 : if (msg)
12713 : 33 : error ("%qE is unavailable: %s", what, (const char *) msg);
12714 : : else
12715 : 33 : error ("%qE is unavailable", what);
12716 : : }
12717 : : else
12718 : : {
12719 : 4 : if (msg)
12720 : 2 : error ("type is unavailable: %s", (const char *) msg);
12721 : : else
12722 : 2 : error ("type is unavailable");
12723 : : }
12724 : :
12725 : 70 : if (decl)
12726 : 52 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12727 : 70 : }
12728 : 364 : }
12729 : :
12730 : : /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
12731 : : somewhere in it. */
12732 : :
12733 : : bool
12734 : 5118081 : contains_bitfld_component_ref_p (const_tree ref)
12735 : : {
12736 : 10741176 : while (handled_component_p (ref))
12737 : : {
12738 : 5642024 : if (TREE_CODE (ref) == COMPONENT_REF
12739 : 5642024 : && DECL_BIT_FIELD (TREE_OPERAND (ref, 1)))
12740 : : return true;
12741 : 5623095 : ref = TREE_OPERAND (ref, 0);
12742 : : }
12743 : :
12744 : : return false;
12745 : : }
12746 : :
12747 : : /* Try to determine whether a TRY_CATCH expression can fall through.
12748 : : This is a subroutine of block_may_fallthru. */
12749 : :
12750 : : static bool
12751 : 1 : try_catch_may_fallthru (const_tree stmt)
12752 : : {
12753 : 1 : tree_stmt_iterator i;
12754 : :
12755 : : /* If the TRY block can fall through, the whole TRY_CATCH can
12756 : : fall through. */
12757 : 1 : if (block_may_fallthru (TREE_OPERAND (stmt, 0)))
12758 : : return true;
12759 : :
12760 : 1 : switch (TREE_CODE (TREE_OPERAND (stmt, 1)))
12761 : : {
12762 : 0 : case CATCH_EXPR:
12763 : : /* See below. */
12764 : 0 : return block_may_fallthru (CATCH_BODY (TREE_OPERAND (stmt, 1)));
12765 : :
12766 : 0 : case EH_FILTER_EXPR:
12767 : : /* See below. */
12768 : 0 : return block_may_fallthru (EH_FILTER_FAILURE (TREE_OPERAND (stmt, 1)));
12769 : :
12770 : 0 : case STATEMENT_LIST:
12771 : 0 : break;
12772 : :
12773 : : default:
12774 : : /* See below. */
12775 : : return false;
12776 : : }
12777 : :
12778 : 0 : i = tsi_start (TREE_OPERAND (stmt, 1));
12779 : 0 : switch (TREE_CODE (tsi_stmt (i)))
12780 : : {
12781 : : case CATCH_EXPR:
12782 : : /* We expect to see a sequence of CATCH_EXPR trees, each with a
12783 : : catch expression and a body. The whole TRY_CATCH may fall
12784 : : through iff any of the catch bodies falls through. */
12785 : 0 : for (; !tsi_end_p (i); tsi_next (&i))
12786 : : {
12787 : 0 : if (block_may_fallthru (CATCH_BODY (tsi_stmt (i))))
12788 : : return true;
12789 : : }
12790 : : return false;
12791 : :
12792 : 0 : case EH_FILTER_EXPR:
12793 : : /* The exception filter expression only matters if there is an
12794 : : exception. If the exception does not match EH_FILTER_TYPES,
12795 : : we will execute EH_FILTER_FAILURE, and we will fall through
12796 : : if that falls through. If the exception does match
12797 : : EH_FILTER_TYPES, the stack unwinder will continue up the
12798 : : stack, so we will not fall through. We don't know whether we
12799 : : will throw an exception which matches EH_FILTER_TYPES or not,
12800 : : so we just ignore EH_FILTER_TYPES and assume that we might
12801 : : throw an exception which doesn't match. */
12802 : 0 : return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i)));
12803 : :
12804 : : default:
12805 : : /* This case represents statements to be executed when an
12806 : : exception occurs. Those statements are implicitly followed
12807 : : by a RESX statement to resume execution after the exception.
12808 : : So in this case the TRY_CATCH never falls through. */
12809 : : return false;
12810 : : }
12811 : : }
12812 : :
12813 : : /* Try to determine if we can fall out of the bottom of BLOCK. This guess
12814 : : need not be 100% accurate; simply be conservative and return true if we
12815 : : don't know. This is used only to avoid stupidly generating extra code.
12816 : : If we're wrong, we'll just delete the extra code later. */
12817 : :
12818 : : bool
12819 : 5935038 : block_may_fallthru (const_tree block)
12820 : : {
12821 : : /* This CONST_CAST is okay because expr_last returns its argument
12822 : : unmodified and we assign it to a const_tree. */
12823 : 6970595 : const_tree stmt = expr_last (CONST_CAST_TREE (block));
12824 : :
12825 : 6970595 : switch (stmt ? TREE_CODE (stmt) : ERROR_MARK)
12826 : : {
12827 : : case GOTO_EXPR:
12828 : : case RETURN_EXPR:
12829 : : /* Easy cases. If the last statement of the block implies
12830 : : control transfer, then we can't fall through. */
12831 : : return false;
12832 : :
12833 : 8 : case SWITCH_EXPR:
12834 : : /* If there is a default: label or case labels cover all possible
12835 : : SWITCH_COND values, then the SWITCH_EXPR will transfer control
12836 : : to some case label in all cases and all we care is whether the
12837 : : SWITCH_BODY falls through. */
12838 : 8 : if (SWITCH_ALL_CASES_P (stmt))
12839 : 7 : return block_may_fallthru (SWITCH_BODY (stmt));
12840 : : return true;
12841 : :
12842 : 19500 : case COND_EXPR:
12843 : 19500 : if (block_may_fallthru (COND_EXPR_THEN (stmt)))
12844 : : return true;
12845 : 2779 : return block_may_fallthru (COND_EXPR_ELSE (stmt));
12846 : :
12847 : 506246 : case BIND_EXPR:
12848 : 506246 : return block_may_fallthru (BIND_EXPR_BODY (stmt));
12849 : :
12850 : 1 : case TRY_CATCH_EXPR:
12851 : 1 : return try_catch_may_fallthru (stmt);
12852 : :
12853 : 141 : case TRY_FINALLY_EXPR:
12854 : : /* The finally clause is always executed after the try clause,
12855 : : so if it does not fall through, then the try-finally will not
12856 : : fall through. Otherwise, if the try clause does not fall
12857 : : through, then when the finally clause falls through it will
12858 : : resume execution wherever the try clause was going. So the
12859 : : whole try-finally will only fall through if both the try
12860 : : clause and the finally clause fall through. */
12861 : 141 : return (block_may_fallthru (TREE_OPERAND (stmt, 0))
12862 : 141 : && block_may_fallthru (TREE_OPERAND (stmt, 1)));
12863 : :
12864 : 0 : case EH_ELSE_EXPR:
12865 : 0 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
12866 : :
12867 : 88363 : case MODIFY_EXPR:
12868 : 88363 : if (TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR)
12869 : 1540 : stmt = TREE_OPERAND (stmt, 1);
12870 : : else
12871 : : return true;
12872 : : /* FALLTHRU */
12873 : :
12874 : 396670 : case CALL_EXPR:
12875 : : /* Functions that do not return do not fall through. */
12876 : 396670 : return (call_expr_flags (stmt) & ECF_NORETURN) == 0;
12877 : :
12878 : 526515 : case CLEANUP_POINT_EXPR:
12879 : 526515 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
12880 : :
12881 : 10 : case TARGET_EXPR:
12882 : 10 : return block_may_fallthru (TREE_OPERAND (stmt, 1));
12883 : :
12884 : : case ERROR_MARK:
12885 : : return true;
12886 : :
12887 : 3755111 : default:
12888 : 3755111 : return lang_hooks.block_may_fallthru (stmt);
12889 : : }
12890 : : }
12891 : :
12892 : : /* True if we are using EH to handle cleanups. */
12893 : : static bool using_eh_for_cleanups_flag = false;
12894 : :
12895 : : /* This routine is called from front ends to indicate eh should be used for
12896 : : cleanups. */
12897 : : void
12898 : 117187 : using_eh_for_cleanups (void)
12899 : : {
12900 : 117187 : using_eh_for_cleanups_flag = true;
12901 : 117187 : }
12902 : :
12903 : : /* Query whether EH is used for cleanups. */
12904 : : bool
12905 : 1503957 : using_eh_for_cleanups_p (void)
12906 : : {
12907 : 1503957 : return using_eh_for_cleanups_flag;
12908 : : }
12909 : :
12910 : : /* Wrapper for tree_code_name to ensure that tree code is valid */
12911 : : const char *
12912 : 13534176912 : get_tree_code_name (enum tree_code code)
12913 : : {
12914 : 13534176912 : const char *invalid = "<invalid tree code>";
12915 : :
12916 : : /* The tree_code enum promotes to signed, but we could be getting
12917 : : invalid values, so force an unsigned comparison. */
12918 : 13534176912 : if (unsigned (code) >= MAX_TREE_CODES)
12919 : : {
12920 : 0 : if ((unsigned)code == 0xa5a5)
12921 : : return "ggc_freed";
12922 : 0 : return invalid;
12923 : : }
12924 : :
12925 : 13534176912 : return tree_code_name[code];
12926 : : }
12927 : :
12928 : : /* Drops the TREE_OVERFLOW flag from T. */
12929 : :
12930 : : tree
12931 : 38550 : drop_tree_overflow (tree t)
12932 : : {
12933 : 38550 : gcc_checking_assert (TREE_OVERFLOW (t));
12934 : :
12935 : : /* For tree codes with a sharing machinery re-build the result. */
12936 : 38550 : if (poly_int_tree_p (t))
12937 : 38538 : return wide_int_to_tree (TREE_TYPE (t), wi::to_poly_wide (t));
12938 : :
12939 : : /* For VECTOR_CST, remove the overflow bits from the encoded elements
12940 : : and canonicalize the result. */
12941 : 12 : if (TREE_CODE (t) == VECTOR_CST)
12942 : : {
12943 : 0 : tree_vector_builder builder;
12944 : 0 : builder.new_unary_operation (TREE_TYPE (t), t, true);
12945 : 0 : unsigned int count = builder.encoded_nelts ();
12946 : 0 : for (unsigned int i = 0; i < count; ++i)
12947 : : {
12948 : 0 : tree elt = VECTOR_CST_ELT (t, i);
12949 : 0 : if (TREE_OVERFLOW (elt))
12950 : 0 : elt = drop_tree_overflow (elt);
12951 : 0 : builder.quick_push (elt);
12952 : : }
12953 : 0 : return builder.build ();
12954 : 0 : }
12955 : :
12956 : : /* Otherwise, as all tcc_constants are possibly shared, copy the node
12957 : : and drop the flag. */
12958 : 12 : t = copy_node (t);
12959 : 12 : TREE_OVERFLOW (t) = 0;
12960 : :
12961 : : /* For constants that contain nested constants, drop the flag
12962 : : from those as well. */
12963 : 12 : if (TREE_CODE (t) == COMPLEX_CST)
12964 : : {
12965 : 12 : if (TREE_OVERFLOW (TREE_REALPART (t)))
12966 : 12 : TREE_REALPART (t) = drop_tree_overflow (TREE_REALPART (t));
12967 : 12 : if (TREE_OVERFLOW (TREE_IMAGPART (t)))
12968 : 0 : TREE_IMAGPART (t) = drop_tree_overflow (TREE_IMAGPART (t));
12969 : : }
12970 : :
12971 : : return t;
12972 : : }
12973 : :
12974 : : /* Given a memory reference expression T, return its base address.
12975 : : The base address of a memory reference expression is the main
12976 : : object being referenced. For instance, the base address for
12977 : : 'array[i].fld[j]' is 'array'. You can think of this as stripping
12978 : : away the offset part from a memory address.
12979 : :
12980 : : This function calls handled_component_p to strip away all the inner
12981 : : parts of the memory reference until it reaches the base object. */
12982 : :
12983 : : tree
12984 : 2947749200 : get_base_address (tree t)
12985 : : {
12986 : 2947749200 : if (TREE_CODE (t) == WITH_SIZE_EXPR)
12987 : 971 : t = TREE_OPERAND (t, 0);
12988 : 3664132870 : while (handled_component_p (t))
12989 : 716383670 : t = TREE_OPERAND (t, 0);
12990 : :
12991 : 2947749200 : if ((TREE_CODE (t) == MEM_REF
12992 : 2947749200 : || TREE_CODE (t) == TARGET_MEM_REF)
12993 : 2947749200 : && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
12994 : 119151915 : t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
12995 : :
12996 : 2947749200 : return t;
12997 : : }
12998 : :
12999 : : /* Return a tree of sizetype representing the size, in bytes, of the element
13000 : : of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13001 : :
13002 : : tree
13003 : 784993562 : array_ref_element_size (tree exp)
13004 : : {
13005 : 784993562 : tree aligned_size = TREE_OPERAND (exp, 3);
13006 : 784993562 : tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
13007 : 784993562 : location_t loc = EXPR_LOCATION (exp);
13008 : :
13009 : : /* If a size was specified in the ARRAY_REF, it's the size measured
13010 : : in alignment units of the element type. So multiply by that value. */
13011 : 784993562 : if (aligned_size)
13012 : : {
13013 : : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13014 : : sizetype from another type of the same width and signedness. */
13015 : 386508 : if (TREE_TYPE (aligned_size) != sizetype)
13016 : 2014 : aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
13017 : 386508 : return size_binop_loc (loc, MULT_EXPR, aligned_size,
13018 : 386508 : size_int (TYPE_ALIGN_UNIT (elmt_type)));
13019 : : }
13020 : :
13021 : : /* Otherwise, take the size from that of the element type. Substitute
13022 : : any PLACEHOLDER_EXPR that we have. */
13023 : : else
13024 : 784607054 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
13025 : : }
13026 : :
13027 : : /* Return a tree representing the lower bound of the array mentioned in
13028 : : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13029 : :
13030 : : tree
13031 : 1126624586 : array_ref_low_bound (tree exp)
13032 : : {
13033 : 1126624586 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13034 : :
13035 : : /* If a lower bound is specified in EXP, use it. */
13036 : 1126624586 : if (TREE_OPERAND (exp, 2))
13037 : 1082341 : return TREE_OPERAND (exp, 2);
13038 : :
13039 : : /* Otherwise, if there is a domain type and it has a lower bound, use it,
13040 : : substituting for a PLACEHOLDER_EXPR as needed. */
13041 : 1125542245 : if (domain_type && TYPE_MIN_VALUE (domain_type))
13042 : 1124658040 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
13043 : :
13044 : : /* Otherwise, return a zero of the appropriate type. */
13045 : 884205 : tree idxtype = TREE_TYPE (TREE_OPERAND (exp, 1));
13046 : 884205 : return (idxtype == error_mark_node
13047 : 884205 : ? integer_zero_node : build_int_cst (idxtype, 0));
13048 : : }
13049 : :
13050 : : /* Return a tree representing the upper bound of the array mentioned in
13051 : : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13052 : :
13053 : : tree
13054 : 296513952 : array_ref_up_bound (tree exp)
13055 : : {
13056 : 296513952 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13057 : :
13058 : : /* If there is a domain type and it has an upper bound, use it, substituting
13059 : : for a PLACEHOLDER_EXPR as needed. */
13060 : 296513952 : if (domain_type && TYPE_MAX_VALUE (domain_type))
13061 : 295707971 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
13062 : :
13063 : : /* Otherwise fail. */
13064 : : return NULL_TREE;
13065 : : }
13066 : :
13067 : : /* Returns true if REF is an array reference, a component reference,
13068 : : or a memory reference to an array whose actual size might be larger
13069 : : than its upper bound implies, there are multiple cases:
13070 : : A. a ref to a flexible array member at the end of a structure;
13071 : : B. a ref to an array with a different type against the original decl;
13072 : : for example:
13073 : :
13074 : : short a[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
13075 : : (*((char(*)[16])&a[0]))[i+8]
13076 : :
13077 : : C. a ref to an array that was passed as a parameter;
13078 : : for example:
13079 : :
13080 : : int test (uint8_t *p, uint32_t t[1][1], int n) {
13081 : : for (int i = 0; i < 4; i++, p++)
13082 : : t[i][0] = ...;
13083 : :
13084 : : If non-null, set IS_TRAILING_ARRAY to true if the ref is the above case A.
13085 : : */
13086 : :
13087 : : bool
13088 : 80725345 : array_ref_flexible_size_p (tree ref, bool *is_trailing_array /* = NULL */)
13089 : : {
13090 : : /* The TYPE for this array referece. */
13091 : 80725345 : tree atype = NULL_TREE;
13092 : : /* The FIELD_DECL for the array field in the containing structure. */
13093 : 80725345 : tree afield_decl = NULL_TREE;
13094 : : /* Whether this array is the trailing array of a structure. */
13095 : 80725345 : bool is_trailing_array_tmp = false;
13096 : 80725345 : if (!is_trailing_array)
13097 : 80647869 : is_trailing_array = &is_trailing_array_tmp;
13098 : :
13099 : 80725345 : if (TREE_CODE (ref) == ARRAY_REF
13100 : 80725345 : || TREE_CODE (ref) == ARRAY_RANGE_REF)
13101 : : {
13102 : 80506718 : atype = TREE_TYPE (TREE_OPERAND (ref, 0));
13103 : 80506718 : ref = TREE_OPERAND (ref, 0);
13104 : : }
13105 : 218627 : else if (TREE_CODE (ref) == COMPONENT_REF
13106 : 218627 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 1))) == ARRAY_TYPE)
13107 : : {
13108 : 156749 : atype = TREE_TYPE (TREE_OPERAND (ref, 1));
13109 : 156749 : afield_decl = TREE_OPERAND (ref, 1);
13110 : : }
13111 : 61878 : else if (TREE_CODE (ref) == MEM_REF)
13112 : : {
13113 : 7815 : tree arg = TREE_OPERAND (ref, 0);
13114 : 7815 : if (TREE_CODE (arg) == ADDR_EXPR)
13115 : 7815 : arg = TREE_OPERAND (arg, 0);
13116 : 7815 : tree argtype = TREE_TYPE (arg);
13117 : 7815 : if (TREE_CODE (argtype) == RECORD_TYPE)
13118 : : {
13119 : 174 : if (tree fld = last_field (argtype))
13120 : : {
13121 : 174 : atype = TREE_TYPE (fld);
13122 : 174 : afield_decl = fld;
13123 : 174 : if (TREE_CODE (atype) != ARRAY_TYPE)
13124 : : return false;
13125 : 174 : if (VAR_P (arg) && DECL_SIZE (fld))
13126 : : return false;
13127 : : }
13128 : : else
13129 : : return false;
13130 : : }
13131 : : else
13132 : : return false;
13133 : : }
13134 : : else
13135 : : return false;
13136 : :
13137 : 80663592 : if (TREE_CODE (ref) == STRING_CST)
13138 : : return false;
13139 : :
13140 : : tree ref_to_array = ref;
13141 : 96918422 : while (handled_component_p (ref))
13142 : : {
13143 : : /* If the reference chain contains a component reference to a
13144 : : non-union type and there follows another field the reference
13145 : : is not at the end of a structure. */
13146 : 19413130 : if (TREE_CODE (ref) == COMPONENT_REF)
13147 : : {
13148 : 18298501 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
13149 : : {
13150 : 17072203 : tree nextf = DECL_CHAIN (TREE_OPERAND (ref, 1));
13151 : 23303348 : while (nextf && TREE_CODE (nextf) != FIELD_DECL)
13152 : 6231145 : nextf = DECL_CHAIN (nextf);
13153 : : if (nextf)
13154 : : return false;
13155 : : }
13156 : : }
13157 : : /* If we have a multi-dimensional array we do not consider
13158 : : a non-innermost dimension as flex array if the whole
13159 : : multi-dimensional array is at struct end.
13160 : : Same for an array of aggregates with a trailing array
13161 : : member. */
13162 : 1114629 : else if (TREE_CODE (ref) == ARRAY_REF)
13163 : : return false;
13164 : 175434 : else if (TREE_CODE (ref) == ARRAY_RANGE_REF)
13165 : : ;
13166 : : /* If we view an underlying object as sth else then what we
13167 : : gathered up to now is what we have to rely on. */
13168 : 175424 : else if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
13169 : : break;
13170 : : else
13171 : 0 : gcc_unreachable ();
13172 : :
13173 : 16256312 : ref = TREE_OPERAND (ref, 0);
13174 : : }
13175 : :
13176 : 77680716 : gcc_assert (!afield_decl
13177 : : || (afield_decl && TREE_CODE (afield_decl) == FIELD_DECL));
13178 : :
13179 : : /* The array now is at struct end. Treat flexible array member as
13180 : : always subject to extend, even into just padding constrained by
13181 : : an underlying decl. */
13182 : 77680716 : if (! TYPE_SIZE (atype)
13183 : 74299510 : || ! TYPE_DOMAIN (atype)
13184 : 151980226 : || ! TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13185 : : {
13186 : 3385954 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13187 : 3462096 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13188 : : }
13189 : :
13190 : : /* If the reference is based on a declared entity, the size of the array
13191 : : is constrained by its given domain. (Do not trust commons PR/69368). */
13192 : 74294762 : ref = get_base_address (ref);
13193 : 74294762 : if (ref
13194 : 74294762 : && DECL_P (ref)
13195 : 64471391 : && !(flag_unconstrained_commons
13196 : 14 : && VAR_P (ref) && DECL_COMMON (ref))
13197 : 64471377 : && DECL_SIZE_UNIT (ref)
13198 : 138765762 : && TREE_CODE (DECL_SIZE_UNIT (ref)) == INTEGER_CST)
13199 : : {
13200 : : /* If the object itself is the array it is not at struct end. */
13201 : 64470972 : if (DECL_P (ref_to_array))
13202 : : return false;
13203 : :
13204 : : /* Check whether the array domain covers all of the available
13205 : : padding. */
13206 : 15219683 : poly_int64 offset;
13207 : 15219683 : if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
13208 : 15218371 : || TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST
13209 : 30421977 : || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST)
13210 : : {
13211 : 17389 : *is_trailing_array
13212 : 17389 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13213 : 17432 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13214 : : }
13215 : 15202294 : if (! get_addr_base_and_unit_offset (ref_to_array, &offset))
13216 : : {
13217 : 2630 : *is_trailing_array
13218 : 2630 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13219 : 2630 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13220 : : }
13221 : :
13222 : : /* If at least one extra element fits it is a flexarray. */
13223 : 15199664 : if (known_le ((wi::to_offset (TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13224 : : - wi::to_offset (TYPE_MIN_VALUE (TYPE_DOMAIN (atype)))
13225 : : + 2)
13226 : : * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (atype))),
13227 : : wi::to_offset (DECL_SIZE_UNIT (ref)) - offset))
13228 : : {
13229 : 578672 : *is_trailing_array
13230 : 578672 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13231 : 586642 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13232 : : }
13233 : :
13234 : : return false;
13235 : : }
13236 : :
13237 : 9823790 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13238 : 9838116 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13239 : : }
13240 : :
13241 : :
13242 : : /* Return a tree representing the offset, in bytes, of the field referenced
13243 : : by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
13244 : :
13245 : : tree
13246 : 2657247670 : component_ref_field_offset (tree exp)
13247 : : {
13248 : 2657247670 : tree aligned_offset = TREE_OPERAND (exp, 2);
13249 : 2657247670 : tree field = TREE_OPERAND (exp, 1);
13250 : 2657247670 : location_t loc = EXPR_LOCATION (exp);
13251 : :
13252 : : /* If an offset was specified in the COMPONENT_REF, it's the offset measured
13253 : : in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
13254 : : value. */
13255 : 2657247670 : if (aligned_offset)
13256 : : {
13257 : : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13258 : : sizetype from another type of the same width and signedness. */
13259 : 10846 : if (TREE_TYPE (aligned_offset) != sizetype)
13260 : 122 : aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
13261 : 10846 : return size_binop_loc (loc, MULT_EXPR, aligned_offset,
13262 : 10846 : size_int (DECL_OFFSET_ALIGN (field)
13263 : : / BITS_PER_UNIT));
13264 : : }
13265 : :
13266 : : /* Otherwise, take the offset from that of the field. Substitute
13267 : : any PLACEHOLDER_EXPR that we have. */
13268 : : else
13269 : 2657236824 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
13270 : : }
13271 : :
13272 : : /* Given the initializer INIT, return the initializer for the field
13273 : : DECL if it exists, otherwise null. Used to obtain the initializer
13274 : : for a flexible array member and determine its size. */
13275 : :
13276 : : static tree
13277 : 1268 : get_initializer_for (tree init, tree decl)
13278 : : {
13279 : 1268 : STRIP_NOPS (init);
13280 : :
13281 : 1268 : tree fld, fld_init;
13282 : 1268 : unsigned HOST_WIDE_INT i;
13283 : 3572 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), i, fld, fld_init)
13284 : : {
13285 : 1927 : if (decl == fld)
13286 : : return fld_init;
13287 : :
13288 : 1036 : if (TREE_CODE (fld) == CONSTRUCTOR)
13289 : : {
13290 : 0 : fld_init = get_initializer_for (fld_init, decl);
13291 : 0 : if (fld_init)
13292 : : return fld_init;
13293 : : }
13294 : : }
13295 : :
13296 : : return NULL_TREE;
13297 : : }
13298 : :
13299 : : /* Determines the special array member type for the array reference REF. */
13300 : : special_array_member
13301 : 245717 : component_ref_sam_type (tree ref)
13302 : : {
13303 : 245717 : special_array_member sam_type = special_array_member::none;
13304 : :
13305 : 245717 : tree member = TREE_OPERAND (ref, 1);
13306 : 245717 : tree memsize = DECL_SIZE_UNIT (member);
13307 : 245717 : if (memsize)
13308 : : {
13309 : 115252 : tree memtype = TREE_TYPE (member);
13310 : 115252 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13311 : 115131 : return sam_type;
13312 : :
13313 : 77476 : bool trailing = false;
13314 : 77476 : (void) array_ref_flexible_size_p (ref, &trailing);
13315 : 77476 : bool zero_elts = integer_zerop (memsize);
13316 : 77476 : if (zero_elts && integer_zerop (TYPE_SIZE_UNIT (TREE_TYPE (memtype))))
13317 : : {
13318 : : /* If array element has zero size, verify if it is a flexible
13319 : : array member or zero length array. Clear zero_elts if
13320 : : it has one or more members or is a VLA member. */
13321 : 7 : if (tree dom = TYPE_DOMAIN (memtype))
13322 : 7 : if (tree min = TYPE_MIN_VALUE (dom))
13323 : 7 : if (tree max = TYPE_MAX_VALUE (dom))
13324 : 5 : if (TREE_CODE (min) != INTEGER_CST
13325 : 5 : || TREE_CODE (max) != INTEGER_CST
13326 : 15 : || !((integer_zerop (min) && integer_all_onesp (max))
13327 : 5 : || tree_int_cst_lt (max, min)))
13328 : : zero_elts = false;
13329 : : }
13330 : 77476 : if (!trailing && !zero_elts)
13331 : : /* MEMBER is an interior array with more than one element. */
13332 : : return special_array_member::int_n;
13333 : :
13334 : 21188 : if (zero_elts)
13335 : : {
13336 : 1075 : if (trailing)
13337 : : return special_array_member::trail_0;
13338 : : else
13339 : 463 : return special_array_member::int_0;
13340 : : }
13341 : :
13342 : 20576 : if (!zero_elts)
13343 : 20576 : if (tree dom = TYPE_DOMAIN (memtype))
13344 : 20576 : if (tree min = TYPE_MIN_VALUE (dom))
13345 : 20576 : if (tree max = TYPE_MAX_VALUE (dom))
13346 : 20576 : if (TREE_CODE (min) == INTEGER_CST
13347 : 20576 : && TREE_CODE (max) == INTEGER_CST)
13348 : : {
13349 : 20455 : offset_int minidx = wi::to_offset (min);
13350 : 20455 : offset_int maxidx = wi::to_offset (max);
13351 : 20455 : offset_int neltsm1 = maxidx - minidx;
13352 : 20455 : if (neltsm1 > 0)
13353 : : /* MEMBER is a trailing array with more than
13354 : : one elements. */
13355 : 20455 : return special_array_member::trail_n;
13356 : :
13357 : 1964 : if (neltsm1 == 0)
13358 : : return special_array_member::trail_1;
13359 : : }
13360 : : }
13361 : :
13362 : : return sam_type;
13363 : : }
13364 : :
13365 : : /* Determines the size of the member referenced by the COMPONENT_REF
13366 : : REF, using its initializer expression if necessary in order to
13367 : : determine the size of an initialized flexible array member.
13368 : : If non-null, set *SAM to the type of special array member.
13369 : : Returns the size as sizetype (which might be zero for an object
13370 : : with an uninitialized flexible array member) or null if the size
13371 : : cannot be determined. */
13372 : :
13373 : : tree
13374 : 147003 : component_ref_size (tree ref, special_array_member *sam /* = NULL */)
13375 : : {
13376 : 147003 : gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
13377 : :
13378 : 147003 : special_array_member sambuf;
13379 : 147003 : if (!sam)
13380 : 94797 : sam = &sambuf;
13381 : 147003 : *sam = component_ref_sam_type (ref);
13382 : :
13383 : : /* The object/argument referenced by the COMPONENT_REF and its type. */
13384 : 147003 : tree arg = TREE_OPERAND (ref, 0);
13385 : 147003 : tree argtype = TREE_TYPE (arg);
13386 : : /* The referenced member. */
13387 : 147003 : tree member = TREE_OPERAND (ref, 1);
13388 : :
13389 : 147003 : tree memsize = DECL_SIZE_UNIT (member);
13390 : 147003 : if (memsize)
13391 : : {
13392 : 80285 : tree memtype = TREE_TYPE (member);
13393 : 80285 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13394 : : /* DECL_SIZE may be less than TYPE_SIZE in C++ when referring
13395 : : to the type of a class with a virtual base which doesn't
13396 : : reflect the size of the virtual's members (see pr97595).
13397 : : If that's the case fail for now and implement something
13398 : : more robust in the future. */
13399 : 37776 : return (tree_int_cst_equal (memsize, TYPE_SIZE_UNIT (memtype))
13400 : 37776 : ? memsize : NULL_TREE);
13401 : :
13402 : : /* 2-or-more elements arrays are treated as normal arrays by default. */
13403 : 42509 : if (*sam == special_array_member::int_n
13404 : 42509 : || *sam == special_array_member::trail_n)
13405 : : return memsize;
13406 : :
13407 : 1740 : tree afield_decl = TREE_OPERAND (ref, 1);
13408 : 1740 : gcc_assert (TREE_CODE (afield_decl) == FIELD_DECL);
13409 : : /* If the trailing array is a not a flexible array member, treat it as
13410 : : a normal array. */
13411 : 1740 : if (DECL_NOT_FLEXARRAY (afield_decl)
13412 : 1740 : && *sam != special_array_member::int_0)
13413 : : return memsize;
13414 : :
13415 : 1731 : if (*sam == special_array_member::int_0)
13416 : 270 : memsize = NULL_TREE;
13417 : :
13418 : : /* For a reference to a flexible array member of a union
13419 : : use the size of the union instead of the size of the member. */
13420 : 1731 : if (TREE_CODE (argtype) == UNION_TYPE)
13421 : 277 : memsize = TYPE_SIZE_UNIT (argtype);
13422 : : }
13423 : :
13424 : : /* MEMBER is either a bona fide flexible array member, or a zero-elements
13425 : : array member, or an array of length one treated as such. */
13426 : :
13427 : : /* If the reference is to a declared object and the member a true
13428 : : flexible array, try to determine its size from its initializer. */
13429 : 68449 : poly_int64 baseoff = 0;
13430 : 68449 : tree base = get_addr_base_and_unit_offset (ref, &baseoff);
13431 : 68449 : if (!base || !VAR_P (base))
13432 : : {
13433 : 65313 : if (*sam != special_array_member::int_0)
13434 : : return NULL_TREE;
13435 : :
13436 : 52 : if (TREE_CODE (arg) != COMPONENT_REF)
13437 : : return NULL_TREE;
13438 : :
13439 : : base = arg;
13440 : 6 : while (TREE_CODE (base) == COMPONENT_REF)
13441 : 3 : base = TREE_OPERAND (base, 0);
13442 : 3 : baseoff = tree_to_poly_int64 (byte_position (TREE_OPERAND (ref, 1)));
13443 : : }
13444 : :
13445 : : /* BASE is the declared object of which MEMBER is either a member
13446 : : or that is cast to ARGTYPE (e.g., a char buffer used to store
13447 : : an ARGTYPE object). */
13448 : 3139 : tree basetype = TREE_TYPE (base);
13449 : :
13450 : : /* Determine the base type of the referenced object. If it's
13451 : : the same as ARGTYPE and MEMBER has a known size, return it. */
13452 : 3139 : tree bt = basetype;
13453 : 3139 : if (*sam != special_array_member::int_0)
13454 : 3140 : while (TREE_CODE (bt) == ARRAY_TYPE)
13455 : 222 : bt = TREE_TYPE (bt);
13456 : 3139 : bool typematch = useless_type_conversion_p (argtype, bt);
13457 : 3139 : if (memsize && typematch)
13458 : : return memsize;
13459 : :
13460 : 3049 : memsize = NULL_TREE;
13461 : :
13462 : 3049 : if (typematch)
13463 : : /* MEMBER is a true flexible array member. Compute its size from
13464 : : the initializer of the BASE object if it has one. */
13465 : 2587 : if (tree init = DECL_P (base) ? DECL_INITIAL (base) : NULL_TREE)
13466 : 1301 : if (init != error_mark_node)
13467 : : {
13468 : 1268 : init = get_initializer_for (init, member);
13469 : 1268 : if (init)
13470 : : {
13471 : 891 : memsize = TYPE_SIZE_UNIT (TREE_TYPE (init));
13472 : 891 : if (tree refsize = TYPE_SIZE_UNIT (argtype))
13473 : : {
13474 : : /* Use the larger of the initializer size and the tail
13475 : : padding in the enclosing struct. */
13476 : 891 : poly_int64 rsz = tree_to_poly_int64 (refsize);
13477 : 891 : rsz -= baseoff;
13478 : 891 : if (known_lt (tree_to_poly_int64 (memsize), rsz))
13479 : 56 : memsize = wide_int_to_tree (TREE_TYPE (memsize), rsz);
13480 : : }
13481 : :
13482 : 891 : baseoff = 0;
13483 : : }
13484 : : }
13485 : :
13486 : 891 : if (!memsize)
13487 : : {
13488 : 2158 : if (typematch)
13489 : : {
13490 : 1696 : if (DECL_P (base)
13491 : 1696 : && DECL_EXTERNAL (base)
13492 : 392 : && bt == basetype
13493 : 2082 : && *sam != special_array_member::int_0)
13494 : : /* The size of a flexible array member of an extern struct
13495 : : with no initializer cannot be determined (it's defined
13496 : : in another translation unit and can have an initializer
13497 : : with an arbitrary number of elements). */
13498 : : return NULL_TREE;
13499 : :
13500 : : /* Use the size of the base struct or, for interior zero-length
13501 : : arrays, the size of the enclosing type. */
13502 : 1333 : memsize = TYPE_SIZE_UNIT (bt);
13503 : : }
13504 : 462 : else if (DECL_P (base))
13505 : : /* Use the size of the BASE object (possibly an array of some
13506 : : other type such as char used to store the struct). */
13507 : 459 : memsize = DECL_SIZE_UNIT (base);
13508 : : else
13509 : : return NULL_TREE;
13510 : : }
13511 : :
13512 : : /* If the flexible array member has a known size use the greater
13513 : : of it and the tail padding in the enclosing struct.
13514 : : Otherwise, when the size of the flexible array member is unknown
13515 : : and the referenced object is not a struct, use the size of its
13516 : : type when known. This detects sizes of array buffers when cast
13517 : : to struct types with flexible array members. */
13518 : 1792 : if (memsize)
13519 : : {
13520 : 2658 : if (!tree_fits_poly_int64_p (memsize))
13521 : : return NULL_TREE;
13522 : 2658 : poly_int64 memsz64 = memsize ? tree_to_poly_int64 (memsize) : 0;
13523 : 2658 : if (known_lt (baseoff, memsz64))
13524 : : {
13525 : 1241 : memsz64 -= baseoff;
13526 : 1241 : return wide_int_to_tree (TREE_TYPE (memsize), memsz64);
13527 : : }
13528 : 1417 : return size_zero_node;
13529 : : }
13530 : :
13531 : : /* Return "don't know" for an external non-array object since its
13532 : : flexible array member can be initialized to have any number of
13533 : : elements. Otherwise, return zero because the flexible array
13534 : : member has no elements. */
13535 : 25 : return (DECL_P (base)
13536 : 25 : && DECL_EXTERNAL (base)
13537 : 25 : && (!typematch
13538 : 0 : || TREE_CODE (basetype) != ARRAY_TYPE)
13539 : 25 : ? NULL_TREE : size_zero_node);
13540 : : }
13541 : :
13542 : : /* Return true if the given node CALL is a call to a .ACCESS_WITH_SIZE
13543 : : function. */
13544 : : bool
13545 : 59948537 : is_access_with_size_p (const_tree call)
13546 : : {
13547 : 59948537 : if (TREE_CODE (call) != CALL_EXPR)
13548 : : return false;
13549 : 7149750 : if (CALL_EXPR_IFN (call) == IFN_ACCESS_WITH_SIZE)
13550 : 130 : return true;
13551 : : return false;
13552 : : }
13553 : :
13554 : : /* Get the corresponding reference from the call to a .ACCESS_WITH_SIZE.
13555 : : * i.e the first argument of this call. Return NULL_TREE otherwise. */
13556 : : tree
13557 : 2 : get_ref_from_access_with_size (tree call)
13558 : : {
13559 : 2 : if (is_access_with_size_p (call))
13560 : 2 : return CALL_EXPR_ARG (call, 0);
13561 : : return NULL_TREE;
13562 : : }
13563 : :
13564 : : /* Return the machine mode of T. For vectors, returns the mode of the
13565 : : inner type. The main use case is to feed the result to HONOR_NANS,
13566 : : avoiding the BLKmode that a direct TYPE_MODE (T) might return. */
13567 : :
13568 : : machine_mode
13569 : 5080759697 : element_mode (const_tree t)
13570 : : {
13571 : 5080759697 : if (!TYPE_P (t))
13572 : 190768436 : t = TREE_TYPE (t);
13573 : 5080759697 : if (VECTOR_TYPE_P (t) || TREE_CODE (t) == COMPLEX_TYPE)
13574 : 1550822870 : t = TREE_TYPE (t);
13575 : 5080759697 : return TYPE_MODE (t);
13576 : : }
13577 : :
13578 : : /* Vector types need to re-check the target flags each time we report
13579 : : the machine mode. We need to do this because attribute target can
13580 : : change the result of vector_mode_supported_p and have_regs_of_mode
13581 : : on a per-function basis. Thus the TYPE_MODE of a VECTOR_TYPE can
13582 : : change on a per-function basis. */
13583 : : /* ??? Possibly a better solution is to run through all the types
13584 : : referenced by a function and re-compute the TYPE_MODE once, rather
13585 : : than make the TYPE_MODE macro call a function. */
13586 : :
13587 : : machine_mode
13588 : 1278861257 : vector_type_mode (const_tree t)
13589 : : {
13590 : 1278861257 : machine_mode mode;
13591 : :
13592 : 1278861257 : gcc_assert (TREE_CODE (t) == VECTOR_TYPE);
13593 : :
13594 : 1278861257 : mode = t->type_common.mode;
13595 : 310514096 : if (VECTOR_MODE_P (mode)
13596 : 1554855556 : && (!targetm.vector_mode_supported_p (mode)
13597 : 1226001540 : || !have_regs_of_mode[mode]))
13598 : : {
13599 : 19100450 : scalar_int_mode innermode;
13600 : :
13601 : : /* For integers, try mapping it to a same-sized scalar mode. */
13602 : 19100450 : if (is_int_mode (TREE_TYPE (t)->type_common.mode, &innermode))
13603 : : {
13604 : 26605416 : poly_int64 size = (TYPE_VECTOR_SUBPARTS (t)
13605 : 13302708 : * GET_MODE_BITSIZE (innermode));
13606 : 13302708 : scalar_int_mode mode;
13607 : 26471890 : if (int_mode_for_size (size, 0).exists (&mode)
13608 : 13221309 : && have_regs_of_mode[mode])
13609 : 52127 : return mode;
13610 : : }
13611 : :
13612 : 19048323 : return BLKmode;
13613 : : }
13614 : :
13615 : : return mode;
13616 : : }
13617 : :
13618 : : /* Return the size in bits of each element of vector type TYPE. */
13619 : :
13620 : : unsigned int
13621 : 197583 : vector_element_bits (const_tree type)
13622 : : {
13623 : 197583 : gcc_checking_assert (VECTOR_TYPE_P (type));
13624 : 197583 : if (VECTOR_BOOLEAN_TYPE_P (type))
13625 : 1012 : return TYPE_PRECISION (TREE_TYPE (type));
13626 : 196571 : return tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)));
13627 : : }
13628 : :
13629 : : /* Calculate the size in bits of each element of vector type TYPE
13630 : : and return the result as a tree of type bitsizetype. */
13631 : :
13632 : : tree
13633 : 108545 : vector_element_bits_tree (const_tree type)
13634 : : {
13635 : 108545 : gcc_checking_assert (VECTOR_TYPE_P (type));
13636 : 108545 : if (VECTOR_BOOLEAN_TYPE_P (type))
13637 : 597 : return bitsize_int (vector_element_bits (type));
13638 : 107948 : return TYPE_SIZE (TREE_TYPE (type));
13639 : : }
13640 : :
13641 : : /* Verify that basic properties of T match TV and thus T can be a variant of
13642 : : TV. TV should be the more specified variant (i.e. the main variant). */
13643 : :
13644 : : static bool
13645 : 135479045 : verify_type_variant (const_tree t, tree tv)
13646 : : {
13647 : : /* Type variant can differ by:
13648 : :
13649 : : - TYPE_QUALS: TYPE_READONLY, TYPE_VOLATILE, TYPE_ATOMIC, TYPE_RESTRICT,
13650 : : ENCODE_QUAL_ADDR_SPACE.
13651 : : - main variant may be TYPE_COMPLETE_P and variant types !TYPE_COMPLETE_P
13652 : : in this case some values may not be set in the variant types
13653 : : (see TYPE_COMPLETE_P checks).
13654 : : - it is possible to have TYPE_ARTIFICIAL variant of non-artifical type
13655 : : - by TYPE_NAME and attributes (i.e. when variant originate by typedef)
13656 : : - TYPE_CANONICAL (TYPE_ALIAS_SET is the same among variants)
13657 : : - by the alignment: TYPE_ALIGN and TYPE_USER_ALIGN
13658 : : - during LTO by TYPE_CONTEXT if type is TYPE_FILE_SCOPE_P
13659 : : this is necessary to make it possible to merge types form different TUs
13660 : : - arrays, pointers and references may have TREE_TYPE that is a variant
13661 : : of TREE_TYPE of their main variants.
13662 : : - aggregates may have new TYPE_FIELDS list that list variants of
13663 : : the main variant TYPE_FIELDS.
13664 : : - vector types may differ by TYPE_VECTOR_OPAQUE
13665 : : */
13666 : :
13667 : : /* Convenience macro for matching individual fields. */
13668 : : #define verify_variant_match(flag) \
13669 : : do { \
13670 : : if (flag (tv) != flag (t)) \
13671 : : { \
13672 : : error ("type variant differs by %s", #flag); \
13673 : : debug_tree (tv); \
13674 : : return false; \
13675 : : } \
13676 : : } while (false)
13677 : :
13678 : : /* tree_base checks. */
13679 : :
13680 : 135479045 : verify_variant_match (TREE_CODE);
13681 : : /* FIXME: Ada builds non-artificial variants of artificial types. */
13682 : : #if 0
13683 : : if (TYPE_ARTIFICIAL (tv))
13684 : : verify_variant_match (TYPE_ARTIFICIAL);
13685 : : #endif
13686 : 135479045 : if (POINTER_TYPE_P (tv))
13687 : 10987236 : verify_variant_match (TYPE_REF_CAN_ALIAS_ALL);
13688 : : /* FIXME: TYPE_SIZES_GIMPLIFIED may differs for Ada build. */
13689 : 135479045 : verify_variant_match (TYPE_UNSIGNED);
13690 : 135479045 : verify_variant_match (TYPE_PACKED);
13691 : 135479045 : if (TREE_CODE (t) == REFERENCE_TYPE)
13692 : 2745934 : verify_variant_match (TYPE_REF_IS_RVALUE);
13693 : 135479045 : if (AGGREGATE_TYPE_P (t))
13694 : 57939163 : verify_variant_match (TYPE_REVERSE_STORAGE_ORDER);
13695 : : else
13696 : 77539882 : verify_variant_match (TYPE_SATURATING);
13697 : : /* FIXME: This check trigger during libstdc++ build. */
13698 : : #if 0
13699 : : if (RECORD_OR_UNION_TYPE_P (t) && COMPLETE_TYPE_P (t))
13700 : : verify_variant_match (TYPE_FINAL_P);
13701 : : #endif
13702 : :
13703 : : /* tree_type_common checks. */
13704 : :
13705 : 135479045 : if (COMPLETE_TYPE_P (t))
13706 : : {
13707 : 125296800 : verify_variant_match (TYPE_MODE);
13708 : 125296800 : if (TREE_CODE (TYPE_SIZE (t)) != PLACEHOLDER_EXPR
13709 : 125296800 : && TREE_CODE (TYPE_SIZE (tv)) != PLACEHOLDER_EXPR)
13710 : 125296800 : verify_variant_match (TYPE_SIZE);
13711 : 125296800 : if (TREE_CODE (TYPE_SIZE_UNIT (t)) != PLACEHOLDER_EXPR
13712 : 125296800 : && TREE_CODE (TYPE_SIZE_UNIT (tv)) != PLACEHOLDER_EXPR
13713 : 250593600 : && TYPE_SIZE_UNIT (t) != TYPE_SIZE_UNIT (tv))
13714 : : {
13715 : 0 : gcc_assert (!operand_equal_p (TYPE_SIZE_UNIT (t),
13716 : : TYPE_SIZE_UNIT (tv), 0));
13717 : 0 : error ("type variant has different %<TYPE_SIZE_UNIT%>");
13718 : 0 : debug_tree (tv);
13719 : 0 : error ("type variant%'s %<TYPE_SIZE_UNIT%>");
13720 : 0 : debug_tree (TYPE_SIZE_UNIT (tv));
13721 : 0 : error ("type%'s %<TYPE_SIZE_UNIT%>");
13722 : 0 : debug_tree (TYPE_SIZE_UNIT (t));
13723 : 0 : return false;
13724 : : }
13725 : 125296800 : verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
13726 : : }
13727 : 135479045 : verify_variant_match (TYPE_PRECISION_RAW);
13728 : 135479045 : if (RECORD_OR_UNION_TYPE_P (t))
13729 : 57456987 : verify_variant_match (TYPE_TRANSPARENT_AGGR);
13730 : 78022058 : else if (TREE_CODE (t) == ARRAY_TYPE)
13731 : 482176 : verify_variant_match (TYPE_NONALIASED_COMPONENT);
13732 : : /* During LTO we merge variant lists from diferent translation units
13733 : : that may differ BY TYPE_CONTEXT that in turn may point
13734 : : to TRANSLATION_UNIT_DECL.
13735 : : Ada also builds variants of types with different TYPE_CONTEXT. */
13736 : : #if 0
13737 : : if (!in_lto_p || !TYPE_FILE_SCOPE_P (t))
13738 : : verify_variant_match (TYPE_CONTEXT);
13739 : : #endif
13740 : 135479045 : if (TREE_CODE (t) == ARRAY_TYPE || TREE_CODE (t) == INTEGER_TYPE)
13741 : 48403149 : verify_variant_match (TYPE_STRING_FLAG);
13742 : 135479045 : if (TREE_CODE (t) == RECORD_TYPE || TREE_CODE (t) == UNION_TYPE)
13743 : 57456987 : verify_variant_match (TYPE_CXX_ODR_P);
13744 : 135479045 : if (TYPE_ALIAS_SET_KNOWN_P (t))
13745 : : {
13746 : 0 : error ("type variant with %<TYPE_ALIAS_SET_KNOWN_P%>");
13747 : 0 : debug_tree (tv);
13748 : 0 : return false;
13749 : : }
13750 : :
13751 : : /* tree_type_non_common checks. */
13752 : :
13753 : : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
13754 : : and dangle the pointer from time to time. */
13755 : 57456987 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_VFIELD (t) != TYPE_VFIELD (tv)
13756 : 135479045 : && (in_lto_p || !TYPE_VFIELD (tv)
13757 : 0 : || TREE_CODE (TYPE_VFIELD (tv)) != TREE_LIST))
13758 : : {
13759 : 0 : error ("type variant has different %<TYPE_VFIELD%>");
13760 : 0 : debug_tree (tv);
13761 : 0 : return false;
13762 : : }
13763 : 2285244 : if ((TREE_CODE (t) == ENUMERAL_TYPE && COMPLETE_TYPE_P (t))
13764 : 133193854 : || TREE_CODE (t) == INTEGER_TYPE
13765 : 85272881 : || TREE_CODE (t) == BOOLEAN_TYPE
13766 : 70521485 : || TREE_CODE (t) == BITINT_TYPE
13767 : 70521350 : || SCALAR_FLOAT_TYPE_P (t)
13768 : 205107056 : || FIXED_POINT_TYPE_P (t))
13769 : : {
13770 : 65851034 : verify_variant_match (TYPE_MAX_VALUE);
13771 : 65851034 : verify_variant_match (TYPE_MIN_VALUE);
13772 : : }
13773 : 135479045 : if (TREE_CODE (t) == METHOD_TYPE)
13774 : 18781 : verify_variant_match (TYPE_METHOD_BASETYPE);
13775 : 135479045 : if (TREE_CODE (t) == OFFSET_TYPE)
13776 : 132 : verify_variant_match (TYPE_OFFSET_BASETYPE);
13777 : 135479045 : if (TREE_CODE (t) == ARRAY_TYPE)
13778 : 482176 : verify_variant_match (TYPE_ARRAY_MAX_SIZE);
13779 : : /* FIXME: Be lax and allow TYPE_BINFO to be missing in variant types
13780 : : or even type's main variant. This is needed to make bootstrap pass
13781 : : and the bug seems new in GCC 5.
13782 : : C++ FE should be updated to make this consistent and we should check
13783 : : that TYPE_BINFO is always NULL for !COMPLETE_TYPE_P and otherwise there
13784 : : is a match with main variant.
13785 : :
13786 : : Also disable the check for Java for now because of parser hack that builds
13787 : : first an dummy BINFO and then sometimes replace it by real BINFO in some
13788 : : of the copies. */
13789 : 57456987 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t) && TYPE_BINFO (tv)
13790 : 47069297 : && TYPE_BINFO (t) != TYPE_BINFO (tv)
13791 : : /* FIXME: Java sometimes keep dump TYPE_BINFOs on variant types.
13792 : : Since there is no cheap way to tell C++/Java type w/o LTO, do checking
13793 : : at LTO time only. */
13794 : 135479045 : && (in_lto_p && odr_type_p (t)))
13795 : : {
13796 : 0 : error ("type variant has different %<TYPE_BINFO%>");
13797 : 0 : debug_tree (tv);
13798 : 0 : error ("type variant%'s %<TYPE_BINFO%>");
13799 : 0 : debug_tree (TYPE_BINFO (tv));
13800 : 0 : error ("type%'s %<TYPE_BINFO%>");
13801 : 0 : debug_tree (TYPE_BINFO (t));
13802 : 0 : return false;
13803 : : }
13804 : :
13805 : : /* Check various uses of TYPE_VALUES_RAW. */
13806 : 135479045 : if (TREE_CODE (t) == ENUMERAL_TYPE
13807 : 135479045 : && TYPE_VALUES (t))
13808 : 2266716 : verify_variant_match (TYPE_VALUES);
13809 : 133212329 : else if (TREE_CODE (t) == ARRAY_TYPE)
13810 : 482176 : verify_variant_match (TYPE_DOMAIN);
13811 : : /* Permit incomplete variants of complete type. While FEs may complete
13812 : : all variants, this does not happen for C++ templates in all cases. */
13813 : 132730153 : else if (RECORD_OR_UNION_TYPE_P (t)
13814 : 57456987 : && COMPLETE_TYPE_P (t)
13815 : 180212834 : && TYPE_FIELDS (t) != TYPE_FIELDS (tv))
13816 : : {
13817 : 3113 : tree f1, f2;
13818 : :
13819 : : /* Fortran builds qualified variants as new records with items of
13820 : : qualified type. Verify that they looks same. */
13821 : 3113 : for (f1 = TYPE_FIELDS (t), f2 = TYPE_FIELDS (tv);
13822 : 10247 : f1 && f2;
13823 : 7134 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
13824 : 7134 : if (TREE_CODE (f1) != FIELD_DECL || TREE_CODE (f2) != FIELD_DECL
13825 : 7134 : || (TYPE_MAIN_VARIANT (TREE_TYPE (f1))
13826 : 7134 : != TYPE_MAIN_VARIANT (TREE_TYPE (f2))
13827 : : /* FIXME: gfc_nonrestricted_type builds all types as variants
13828 : : with exception of pointer types. It deeply copies the type
13829 : : which means that we may end up with a variant type
13830 : : referring non-variant pointer. We may change it to
13831 : : produce types as variants, too, like
13832 : : objc_get_protocol_qualified_type does. */
13833 : 21 : && !POINTER_TYPE_P (TREE_TYPE (f1)))
13834 : 7134 : || DECL_FIELD_OFFSET (f1) != DECL_FIELD_OFFSET (f2)
13835 : 14268 : || DECL_FIELD_BIT_OFFSET (f1) != DECL_FIELD_BIT_OFFSET (f2))
13836 : : break;
13837 : 3113 : if (f1 || f2)
13838 : : {
13839 : 0 : error ("type variant has different %<TYPE_FIELDS%>");
13840 : 0 : debug_tree (tv);
13841 : 0 : error ("first mismatch is field");
13842 : 0 : debug_tree (f1);
13843 : 0 : error ("and field");
13844 : 0 : debug_tree (f2);
13845 : 0 : return false;
13846 : : }
13847 : : }
13848 : 132727040 : else if (FUNC_OR_METHOD_TYPE_P (t))
13849 : 174852 : verify_variant_match (TYPE_ARG_TYPES);
13850 : : /* For C++ the qualified variant of array type is really an array type
13851 : : of qualified TREE_TYPE.
13852 : : objc builds variants of pointer where pointer to type is a variant, too
13853 : : in objc_get_protocol_qualified_type. */
13854 : 135479045 : if (TREE_TYPE (t) != TREE_TYPE (tv)
13855 : 135479045 : && ((TREE_CODE (t) != ARRAY_TYPE
13856 : 0 : && !POINTER_TYPE_P (t))
13857 : 413963 : || TYPE_MAIN_VARIANT (TREE_TYPE (t))
13858 : 413963 : != TYPE_MAIN_VARIANT (TREE_TYPE (tv))))
13859 : : {
13860 : 0 : error ("type variant has different %<TREE_TYPE%>");
13861 : 0 : debug_tree (tv);
13862 : 0 : error ("type variant%'s %<TREE_TYPE%>");
13863 : 0 : debug_tree (TREE_TYPE (tv));
13864 : 0 : error ("type%'s %<TREE_TYPE%>");
13865 : 0 : debug_tree (TREE_TYPE (t));
13866 : 0 : return false;
13867 : : }
13868 : 135479045 : if (type_with_alias_set_p (t)
13869 : 135479045 : && !gimple_canonical_types_compatible_p (t, tv, false))
13870 : : {
13871 : 0 : error ("type is not compatible with its variant");
13872 : 0 : debug_tree (tv);
13873 : 0 : error ("type variant%'s %<TREE_TYPE%>");
13874 : 0 : debug_tree (TREE_TYPE (tv));
13875 : 0 : error ("type%'s %<TREE_TYPE%>");
13876 : 0 : debug_tree (TREE_TYPE (t));
13877 : 0 : return false;
13878 : : }
13879 : : return true;
13880 : : #undef verify_variant_match
13881 : : }
13882 : :
13883 : :
13884 : : /* The TYPE_CANONICAL merging machinery. It should closely resemble
13885 : : the middle-end types_compatible_p function. It needs to avoid
13886 : : claiming types are different for types that should be treated
13887 : : the same with respect to TBAA. Canonical types are also used
13888 : : for IL consistency checks via the useless_type_conversion_p
13889 : : predicate which does not handle all type kinds itself but falls
13890 : : back to pointer-comparison of TYPE_CANONICAL for aggregates
13891 : : for example. */
13892 : :
13893 : : /* Return true if TYPE_UNSIGNED of TYPE should be ignored for canonical
13894 : : type calculation because we need to allow inter-operability between signed
13895 : : and unsigned variants. */
13896 : :
13897 : : bool
13898 : 1776220 : type_with_interoperable_signedness (const_tree type)
13899 : : {
13900 : : /* Fortran standard require C_SIGNED_CHAR to be interoperable with both
13901 : : signed char and unsigned char. Similarly fortran FE builds
13902 : : C_SIZE_T as signed type, while C defines it unsigned. */
13903 : :
13904 : 1776220 : return tree_code_for_canonical_type_merging (TREE_CODE (type))
13905 : : == INTEGER_TYPE
13906 : 1776019 : && (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node)
13907 : 475980 : || TYPE_PRECISION (type) == TYPE_PRECISION (size_type_node));
13908 : : }
13909 : :
13910 : : /* Return true iff T1 and T2 are structurally identical for what
13911 : : TBAA is concerned.
13912 : : This function is used both by lto.cc canonical type merging and by the
13913 : : verifier. If TRUST_TYPE_CANONICAL we do not look into structure of types
13914 : : that have TYPE_CANONICAL defined and assume them equivalent. This is useful
13915 : : only for LTO because only in these cases TYPE_CANONICAL equivalence
13916 : : correspond to one defined by gimple_canonical_types_compatible_p. */
13917 : :
13918 : : bool
13919 : 292908783 : gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
13920 : : bool trust_type_canonical)
13921 : : {
13922 : : /* Type variants should be same as the main variant. When not doing sanity
13923 : : checking to verify this fact, go to main variants and save some work. */
13924 : 292908783 : if (trust_type_canonical)
13925 : : {
13926 : 952129 : t1 = TYPE_MAIN_VARIANT (t1);
13927 : 952129 : t2 = TYPE_MAIN_VARIANT (t2);
13928 : : }
13929 : :
13930 : : /* Check first for the obvious case of pointer identity. */
13931 : 292908783 : if (t1 == t2)
13932 : : return true;
13933 : :
13934 : : /* Check that we have two types to compare. */
13935 : 244073518 : if (t1 == NULL_TREE || t2 == NULL_TREE)
13936 : : return false;
13937 : :
13938 : : /* We consider complete types always compatible with incomplete type.
13939 : : This does not make sense for canonical type calculation and thus we
13940 : : need to ensure that we are never called on it.
13941 : :
13942 : : FIXME: For more correctness the function probably should have three modes
13943 : : 1) mode assuming that types are complete mathcing their structure
13944 : : 2) mode allowing incomplete types but producing equivalence classes
13945 : : and thus ignoring all info from complete types
13946 : : 3) mode allowing incomplete types to match complete but checking
13947 : : compatibility between complete types.
13948 : :
13949 : : 1 and 2 can be used for canonical type calculation. 3 is the real
13950 : : definition of type compatibility that can be used i.e. for warnings during
13951 : : declaration merging. */
13952 : :
13953 : 244073518 : gcc_assert (!trust_type_canonical
13954 : : || (type_with_alias_set_p (t1) && type_with_alias_set_p (t2)));
13955 : :
13956 : : /* If the types have been previously registered and found equal
13957 : : they still are. */
13958 : :
13959 : 487916014 : if (TYPE_CANONICAL (t1) && TYPE_CANONICAL (t2)
13960 : 487055847 : && trust_type_canonical)
13961 : : {
13962 : : /* Do not use TYPE_CANONICAL of pointer types. For LTO streamed types
13963 : : they are always NULL, but they are set to non-NULL for types
13964 : : constructed by build_pointer_type and variants. In this case the
13965 : : TYPE_CANONICAL is more fine grained than the equivalnce we test (where
13966 : : all pointers are considered equal. Be sure to not return false
13967 : : negatives. */
13968 : 177030 : gcc_checking_assert (canonical_type_used_p (t1)
13969 : : && canonical_type_used_p (t2));
13970 : 88515 : return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
13971 : : }
13972 : :
13973 : : /* For types where we do ODR based TBAA the canonical type is always
13974 : : set correctly, so we know that types are different if their
13975 : : canonical types does not match. */
13976 : 243985003 : if (trust_type_canonical
13977 : 244845667 : && (odr_type_p (t1) && odr_based_tbaa_p (t1))
13978 : 860664 : != (odr_type_p (t2) && odr_based_tbaa_p (t2)))
13979 : : return false;
13980 : :
13981 : : /* Can't be the same type if the types don't have the same code. */
13982 : 243985003 : enum tree_code code = tree_code_for_canonical_type_merging (TREE_CODE (t1));
13983 : 485239030 : if (code != tree_code_for_canonical_type_merging (TREE_CODE (t2)))
13984 : : return false;
13985 : :
13986 : : /* Qualifiers do not matter for canonical type comparison purposes. */
13987 : :
13988 : : /* Void types and nullptr types are always the same. */
13989 : 243984968 : if (VOID_TYPE_P (t1)
13990 : 243948477 : || TREE_CODE (t1) == NULLPTR_TYPE)
13991 : : return true;
13992 : :
13993 : : /* Can't be compatible types if they have different mode. Because of
13994 : : flexible array members, we allow mismatching modes for structures or
13995 : : unions. */
13996 : 243420302 : if (!RECORD_OR_UNION_TYPE_P (t1)
13997 : 243420302 : && TREE_CODE (t1) != ARRAY_TYPE
13998 : 243420302 : && TYPE_MODE (t1) != TYPE_MODE (t2))
13999 : : return false;
14000 : :
14001 : : /* Non-aggregate types can be handled cheaply. */
14002 : 243420302 : if (INTEGRAL_TYPE_P (t1)
14003 : 243420302 : || SCALAR_FLOAT_TYPE_P (t1)
14004 : 132859553 : || FIXED_POINT_TYPE_P (t1)
14005 : 132461681 : || VECTOR_TYPE_P (t1)
14006 : 132435715 : || TREE_CODE (t1) == COMPLEX_TYPE
14007 : 132083691 : || TREE_CODE (t1) == OFFSET_TYPE
14008 : 132083044 : || POINTER_TYPE_P (t1))
14009 : : {
14010 : : /* Can't be the same type if they have different precision. */
14011 : 146599176 : if (TYPE_PRECISION_RAW (t1) != TYPE_PRECISION_RAW (t2))
14012 : : return false;
14013 : :
14014 : : /* In some cases the signed and unsigned types are required to be
14015 : : inter-operable. */
14016 : 146599176 : if (TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)
14017 : 146599176 : && !type_with_interoperable_signedness (t1))
14018 : : return false;
14019 : :
14020 : : /* Fortran's C_SIGNED_CHAR is !TYPE_STRING_FLAG but needs to be
14021 : : interoperable with "signed char". Unless all frontends are revisited
14022 : : to agree on these types, we must ignore the flag completely. */
14023 : :
14024 : : /* Fortran standard define C_PTR type that is compatible with every
14025 : : C pointer. For this reason we need to glob all pointers into one.
14026 : : Still pointers in different address spaces are not compatible. */
14027 : 146599176 : if (POINTER_TYPE_P (t1))
14028 : : {
14029 : 35261918 : if (TYPE_ADDR_SPACE (TREE_TYPE (t1))
14030 : 35261918 : != TYPE_ADDR_SPACE (TREE_TYPE (t2)))
14031 : : return false;
14032 : : }
14033 : :
14034 : : /* Tail-recurse to components. */
14035 : 146599176 : if (VECTOR_TYPE_P (t1)
14036 : 146599176 : || TREE_CODE (t1) == COMPLEX_TYPE)
14037 : 377990 : return gimple_canonical_types_compatible_p (TREE_TYPE (t1),
14038 : 377990 : TREE_TYPE (t2),
14039 : 377990 : trust_type_canonical);
14040 : :
14041 : : return true;
14042 : : }
14043 : :
14044 : : /* Do type-specific comparisons. */
14045 : 96821126 : switch (TREE_CODE (t1))
14046 : : {
14047 : 905433 : case ARRAY_TYPE:
14048 : : /* Array types are the same if the element types are the same and
14049 : : minimum and maximum index are the same. */
14050 : 905433 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14051 : : trust_type_canonical)
14052 : 905398 : || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
14053 : 905398 : || TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2)
14054 : 1810831 : || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
14055 : : return false;
14056 : : else
14057 : : {
14058 : 905398 : tree i1 = TYPE_DOMAIN (t1);
14059 : 905398 : tree i2 = TYPE_DOMAIN (t2);
14060 : :
14061 : : /* For an incomplete external array, the type domain can be
14062 : : NULL_TREE. Check this condition also. */
14063 : 905398 : if (i1 == NULL_TREE && i2 == NULL_TREE)
14064 : : return true;
14065 : 813514 : else if (i1 == NULL_TREE || i2 == NULL_TREE)
14066 : : return false;
14067 : : else
14068 : : {
14069 : 813514 : tree min1 = TYPE_MIN_VALUE (i1);
14070 : 813514 : tree min2 = TYPE_MIN_VALUE (i2);
14071 : 813514 : tree max1 = TYPE_MAX_VALUE (i1);
14072 : 813514 : tree max2 = TYPE_MAX_VALUE (i2);
14073 : :
14074 : : /* The minimum/maximum values have to be the same. */
14075 : 813514 : if ((min1 == min2
14076 : 0 : || (min1 && min2
14077 : 0 : && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
14078 : 0 : && TREE_CODE (min2) == PLACEHOLDER_EXPR)
14079 : 0 : || operand_equal_p (min1, min2, 0))))
14080 : 813514 : && (max1 == max2
14081 : 0 : || (max1 && max2
14082 : 0 : && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
14083 : 0 : && TREE_CODE (max2) == PLACEHOLDER_EXPR)
14084 : 0 : || operand_equal_p (max1, max2, 0)))))
14085 : 813514 : return true;
14086 : : else
14087 : 0 : return false;
14088 : : }
14089 : : }
14090 : :
14091 : 14785 : case METHOD_TYPE:
14092 : 14785 : case FUNCTION_TYPE:
14093 : : /* Function types are the same if the return type and arguments types
14094 : : are the same. */
14095 : 14785 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14096 : : trust_type_canonical))
14097 : : return false;
14098 : :
14099 : 14785 : if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2)
14100 : 14785 : && (TYPE_NO_NAMED_ARGS_STDARG_P (t1)
14101 : 539 : == TYPE_NO_NAMED_ARGS_STDARG_P (t2)))
14102 : : return true;
14103 : : else
14104 : : {
14105 : 14246 : tree parms1, parms2;
14106 : :
14107 : 14246 : for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
14108 : 61289 : parms1 && parms2;
14109 : 47043 : parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
14110 : : {
14111 : 47043 : if (!gimple_canonical_types_compatible_p
14112 : 47043 : (TREE_VALUE (parms1), TREE_VALUE (parms2),
14113 : : trust_type_canonical))
14114 : : return false;
14115 : : }
14116 : :
14117 : 14246 : if (parms1 || parms2)
14118 : : return false;
14119 : :
14120 : : return true;
14121 : : }
14122 : :
14123 : 95705252 : case RECORD_TYPE:
14124 : 95705252 : case UNION_TYPE:
14125 : 95705252 : case QUAL_UNION_TYPE:
14126 : 95705252 : {
14127 : 95705252 : tree f1, f2;
14128 : :
14129 : : /* Don't try to compare variants of an incomplete type, before
14130 : : TYPE_FIELDS has been copied around. */
14131 : 95705252 : if (!COMPLETE_TYPE_P (t1) && !COMPLETE_TYPE_P (t2))
14132 : : return true;
14133 : :
14134 : :
14135 : 86319848 : if (TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2))
14136 : : return false;
14137 : :
14138 : : /* For aggregate types, all the fields must be the same. */
14139 : 86319848 : for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
14140 : 134706996 : f1 || f2;
14141 : 48387148 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
14142 : : {
14143 : : /* Skip non-fields and zero-sized fields, except zero-sized
14144 : : arrays at the end. */
14145 : 1420026857 : while (f1 && (TREE_CODE (f1) != FIELD_DECL
14146 : 88363773 : || (DECL_SIZE (f1)
14147 : 88349290 : && integer_zerop (DECL_SIZE (f1))
14148 : 39976603 : && (TREE_CHAIN (f1)
14149 : 4202 : || TREE_CODE (TREE_TYPE (f1))
14150 : : != ARRAY_TYPE))))
14151 : 1286388657 : f1 = TREE_CHAIN (f1);
14152 : 1420028592 : while (f2 && (TREE_CODE (f2) != FIELD_DECL
14153 : 88415363 : || (DECL_SIZE (f2)
14154 : 88400859 : && integer_zerop (DECL_SIZE (f2))
14155 : 39978342 : && (TREE_CHAIN (f2)
14156 : 5391 : || TREE_CODE (TREE_TYPE (f2))
14157 : : != ARRAY_TYPE))))
14158 : 1286390392 : f2 = TREE_CHAIN (f2);
14159 : 133638200 : if (!f1 || !f2)
14160 : : break;
14161 : :
14162 : 48387375 : tree t1 = TREE_TYPE (f1);
14163 : 48387375 : tree t2 = TREE_TYPE (f2);
14164 : :
14165 : : /* If the last element are arrays, we only compare the element
14166 : : types. */
14167 : 49442603 : if (TREE_CHAIN (f1) == NULL_TREE && TREE_CODE (t1) == ARRAY_TYPE
14168 : 48463858 : && TREE_CHAIN (f2) == NULL_TREE && TREE_CODE (t2) == ARRAY_TYPE)
14169 : : {
14170 : : /* If both arrays have zero size, this is a match. */
14171 : 138891 : if (DECL_SIZE (f1) && integer_zerop (DECL_SIZE (f1))
14172 : 76683 : && DECL_SIZE (f2) && integer_zerop (DECL_SIZE (f2)))
14173 : : return true;
14174 : :
14175 : 76275 : t1 = TREE_TYPE (t1);
14176 : 76275 : t2 = TREE_TYPE (t2);
14177 : : }
14178 : :
14179 : 48387172 : if (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
14180 : 48387167 : || !gimple_compare_field_offset (f1, f2)
14181 : 96774339 : || !gimple_canonical_types_compatible_p
14182 : 48387167 : (t1, t2, trust_type_canonical))
14183 : 24 : return false;
14184 : : }
14185 : :
14186 : : /* If one aggregate has more fields than the other, they
14187 : : are not the same. */
14188 : 86319621 : if (f1 || f2)
14189 : : return false;
14190 : :
14191 : : return true;
14192 : : }
14193 : :
14194 : 195656 : default:
14195 : : /* Consider all types with language specific trees in them mutually
14196 : : compatible. This is executed only from verify_type and false
14197 : : positives can be tolerated. */
14198 : 195656 : gcc_assert (!in_lto_p);
14199 : : return true;
14200 : : }
14201 : : }
14202 : :
14203 : : /* For OPAQUE_TYPE T, it should have only size and alignment information
14204 : : and its mode should be of class MODE_OPAQUE. This function verifies
14205 : : these properties of T match TV which is the main variant of T and TC
14206 : : which is the canonical of T. */
14207 : :
14208 : : static void
14209 : 0 : verify_opaque_type (const_tree t, tree tv, tree tc)
14210 : : {
14211 : 0 : gcc_assert (OPAQUE_TYPE_P (t));
14212 : 0 : gcc_assert (tv && tv == TYPE_MAIN_VARIANT (tv));
14213 : 0 : gcc_assert (tc && tc == TYPE_CANONICAL (tc));
14214 : :
14215 : : /* For an opaque type T1, check if some of its properties match
14216 : : the corresponding ones of the other opaque type T2, emit some
14217 : : error messages for those inconsistent ones. */
14218 : 0 : auto check_properties_for_opaque_type = [](const_tree t1, tree t2,
14219 : : const char *kind_msg)
14220 : : {
14221 : 0 : if (!OPAQUE_TYPE_P (t2))
14222 : : {
14223 : 0 : error ("type %s is not an opaque type", kind_msg);
14224 : 0 : debug_tree (t2);
14225 : 0 : return;
14226 : : }
14227 : 0 : if (!OPAQUE_MODE_P (TYPE_MODE (t2)))
14228 : : {
14229 : 0 : error ("type %s is not with opaque mode", kind_msg);
14230 : 0 : debug_tree (t2);
14231 : 0 : return;
14232 : : }
14233 : 0 : if (TYPE_MODE (t1) != TYPE_MODE (t2))
14234 : : {
14235 : 0 : error ("type %s differs by %<TYPE_MODE%>", kind_msg);
14236 : 0 : debug_tree (t2);
14237 : 0 : return;
14238 : : }
14239 : 0 : poly_uint64 t1_size = tree_to_poly_uint64 (TYPE_SIZE (t1));
14240 : 0 : poly_uint64 t2_size = tree_to_poly_uint64 (TYPE_SIZE (t2));
14241 : 0 : if (maybe_ne (t1_size, t2_size))
14242 : : {
14243 : 0 : error ("type %s differs by %<TYPE_SIZE%>", kind_msg);
14244 : 0 : debug_tree (t2);
14245 : 0 : return;
14246 : : }
14247 : 0 : if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2))
14248 : : {
14249 : 0 : error ("type %s differs by %<TYPE_ALIGN%>", kind_msg);
14250 : 0 : debug_tree (t2);
14251 : 0 : return;
14252 : : }
14253 : 0 : if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
14254 : : {
14255 : 0 : error ("type %s differs by %<TYPE_USER_ALIGN%>", kind_msg);
14256 : 0 : debug_tree (t2);
14257 : 0 : return;
14258 : : }
14259 : : };
14260 : :
14261 : 0 : if (t != tv)
14262 : 0 : check_properties_for_opaque_type (t, tv, "variant");
14263 : :
14264 : 0 : if (t != tc)
14265 : 0 : check_properties_for_opaque_type (t, tc, "canonical");
14266 : 0 : }
14267 : :
14268 : : /* Verify type T. */
14269 : :
14270 : : void
14271 : 683284271 : verify_type (const_tree t)
14272 : : {
14273 : 683284271 : bool error_found = false;
14274 : 683284271 : tree mv = TYPE_MAIN_VARIANT (t);
14275 : 683284271 : tree ct = TYPE_CANONICAL (t);
14276 : :
14277 : 683284271 : if (OPAQUE_TYPE_P (t))
14278 : : {
14279 : 0 : verify_opaque_type (t, mv, ct);
14280 : 0 : return;
14281 : : }
14282 : :
14283 : 683284271 : if (!mv)
14284 : : {
14285 : 0 : error ("main variant is not defined");
14286 : 0 : error_found = true;
14287 : : }
14288 : 683284271 : else if (mv != TYPE_MAIN_VARIANT (mv))
14289 : : {
14290 : 0 : error ("%<TYPE_MAIN_VARIANT%> has different %<TYPE_MAIN_VARIANT%>");
14291 : 0 : debug_tree (mv);
14292 : 0 : error_found = true;
14293 : : }
14294 : 683284271 : else if (t != mv && !verify_type_variant (t, mv))
14295 : : error_found = true;
14296 : :
14297 : 683284271 : if (!ct)
14298 : : ;
14299 : 681295188 : else if (TYPE_CANONICAL (ct) != ct)
14300 : : {
14301 : 0 : error ("%<TYPE_CANONICAL%> has different %<TYPE_CANONICAL%>");
14302 : 0 : debug_tree (ct);
14303 : 0 : error_found = true;
14304 : : }
14305 : : /* Method and function types cannot be used to address memory and thus
14306 : : TYPE_CANONICAL really matters only for determining useless conversions.
14307 : :
14308 : : FIXME: C++ FE produce declarations of builtin functions that are not
14309 : : compatible with main variants. */
14310 : 681295188 : else if (TREE_CODE (t) == FUNCTION_TYPE)
14311 : : ;
14312 : 678476819 : else if (t != ct
14313 : : /* FIXME: gimple_canonical_types_compatible_p cannot compare types
14314 : : with variably sized arrays because their sizes possibly
14315 : : gimplified to different variables. */
14316 : 117108834 : && !variably_modified_type_p (ct, NULL)
14317 : 117106062 : && !gimple_canonical_types_compatible_p (t, ct, false)
14318 : 678526674 : && COMPLETE_TYPE_P (t))
14319 : : {
14320 : 0 : error ("%<TYPE_CANONICAL%> is not compatible");
14321 : 0 : debug_tree (ct);
14322 : 0 : error_found = true;
14323 : : }
14324 : 1227909502 : if (COMPLETE_TYPE_P (t) && TYPE_CANONICAL (t)
14325 : : /* We allow a mismatch for structure or union because of
14326 : : flexible array members. */
14327 : 542701884 : && !RECORD_OR_UNION_TYPE_P (t)
14328 : 228511387 : && !RECORD_OR_UNION_TYPE_P (TYPE_CANONICAL (t))
14329 : 228511387 : && TREE_CODE (t) != ARRAY_TYPE
14330 : 910494579 : && TYPE_MODE (t) != TYPE_MODE (TYPE_CANONICAL (t)))
14331 : : {
14332 : 0 : error ("%<TYPE_MODE%> of %<TYPE_CANONICAL%> is not compatible");
14333 : 0 : debug_tree (ct);
14334 : 0 : error_found = true;
14335 : : }
14336 : 683284271 : if (TYPE_MAIN_VARIANT (t) == t && ct && TYPE_MAIN_VARIANT (ct) != ct)
14337 : : {
14338 : 0 : error ("%<TYPE_CANONICAL%> of main variant is not main variant");
14339 : 0 : debug_tree (ct);
14340 : 0 : debug_tree (TYPE_MAIN_VARIANT (ct));
14341 : 0 : error_found = true;
14342 : : }
14343 : :
14344 : :
14345 : : /* Check various uses of TYPE_MIN_VALUE_RAW. */
14346 : 683284271 : if (RECORD_OR_UNION_TYPE_P (t))
14347 : : {
14348 : : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
14349 : : and danagle the pointer from time to time. */
14350 : 352878042 : if (TYPE_VFIELD (t)
14351 : 9538622 : && TREE_CODE (TYPE_VFIELD (t)) != FIELD_DECL
14352 : 352878042 : && TREE_CODE (TYPE_VFIELD (t)) != TREE_LIST)
14353 : : {
14354 : 0 : error ("%<TYPE_VFIELD%> is not %<FIELD_DECL%> nor %<TREE_LIST%>");
14355 : 0 : debug_tree (TYPE_VFIELD (t));
14356 : 0 : error_found = true;
14357 : : }
14358 : : }
14359 : 330406229 : else if (TREE_CODE (t) == POINTER_TYPE)
14360 : : {
14361 : 88877594 : if (TYPE_NEXT_PTR_TO (t)
14362 : 88877594 : && TREE_CODE (TYPE_NEXT_PTR_TO (t)) != POINTER_TYPE)
14363 : : {
14364 : 0 : error ("%<TYPE_NEXT_PTR_TO%> is not %<POINTER_TYPE%>");
14365 : 0 : debug_tree (TYPE_NEXT_PTR_TO (t));
14366 : 0 : error_found = true;
14367 : : }
14368 : : }
14369 : 241528635 : else if (TREE_CODE (t) == REFERENCE_TYPE)
14370 : : {
14371 : 40637342 : if (TYPE_NEXT_REF_TO (t)
14372 : 40637342 : && TREE_CODE (TYPE_NEXT_REF_TO (t)) != REFERENCE_TYPE)
14373 : : {
14374 : 0 : error ("%<TYPE_NEXT_REF_TO%> is not %<REFERENCE_TYPE%>");
14375 : 0 : debug_tree (TYPE_NEXT_REF_TO (t));
14376 : 0 : error_found = true;
14377 : : }
14378 : : }
14379 : : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14380 : : || FIXED_POINT_TYPE_P (t))
14381 : : {
14382 : : /* FIXME: The following check should pass:
14383 : : useless_type_conversion_p (const_cast <tree> (t),
14384 : : TREE_TYPE (TYPE_MIN_VALUE (t))
14385 : : but does not for C sizetypes in LTO. */
14386 : : }
14387 : :
14388 : : /* Check various uses of TYPE_MAXVAL_RAW. */
14389 : 683284271 : if (RECORD_OR_UNION_TYPE_P (t))
14390 : : {
14391 : 352878042 : if (!TYPE_BINFO (t))
14392 : : ;
14393 : 328688090 : else if (TREE_CODE (TYPE_BINFO (t)) != TREE_BINFO)
14394 : : {
14395 : 0 : error ("%<TYPE_BINFO%> is not %<TREE_BINFO%>");
14396 : 0 : debug_tree (TYPE_BINFO (t));
14397 : 0 : error_found = true;
14398 : : }
14399 : 328688090 : else if (TREE_TYPE (TYPE_BINFO (t)) != TYPE_MAIN_VARIANT (t))
14400 : : {
14401 : 0 : error ("%<TYPE_BINFO%> type is not %<TYPE_MAIN_VARIANT%>");
14402 : 0 : debug_tree (TREE_TYPE (TYPE_BINFO (t)));
14403 : 0 : error_found = true;
14404 : : }
14405 : : }
14406 : : else if (FUNC_OR_METHOD_TYPE_P (t))
14407 : : {
14408 : 3062476 : if (TYPE_METHOD_BASETYPE (t)
14409 : 94977 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != RECORD_TYPE
14410 : 3062694 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != UNION_TYPE)
14411 : : {
14412 : 0 : error ("%<TYPE_METHOD_BASETYPE%> is not record nor union");
14413 : 0 : debug_tree (TYPE_METHOD_BASETYPE (t));
14414 : 0 : error_found = true;
14415 : : }
14416 : : }
14417 : : else if (TREE_CODE (t) == OFFSET_TYPE)
14418 : : {
14419 : 34433 : if (TYPE_OFFSET_BASETYPE (t)
14420 : 34433 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != RECORD_TYPE
14421 : 34441 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != UNION_TYPE)
14422 : : {
14423 : 0 : error ("%<TYPE_OFFSET_BASETYPE%> is not record nor union");
14424 : 0 : debug_tree (TYPE_OFFSET_BASETYPE (t));
14425 : 0 : error_found = true;
14426 : : }
14427 : : }
14428 : : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14429 : : || FIXED_POINT_TYPE_P (t))
14430 : : {
14431 : : /* FIXME: The following check should pass:
14432 : : useless_type_conversion_p (const_cast <tree> (t),
14433 : : TREE_TYPE (TYPE_MAX_VALUE (t))
14434 : : but does not for C sizetypes in LTO. */
14435 : : }
14436 : : else if (TREE_CODE (t) == ARRAY_TYPE)
14437 : : {
14438 : 1533250 : if (TYPE_ARRAY_MAX_SIZE (t)
14439 : 1533250 : && TREE_CODE (TYPE_ARRAY_MAX_SIZE (t)) != INTEGER_CST)
14440 : : {
14441 : 0 : error ("%<TYPE_ARRAY_MAX_SIZE%> not %<INTEGER_CST%>");
14442 : 0 : debug_tree (TYPE_ARRAY_MAX_SIZE (t));
14443 : 0 : error_found = true;
14444 : : }
14445 : : }
14446 : 230710292 : else if (TYPE_MAX_VALUE_RAW (t))
14447 : : {
14448 : 0 : error ("%<TYPE_MAX_VALUE_RAW%> non-NULL");
14449 : 0 : debug_tree (TYPE_MAX_VALUE_RAW (t));
14450 : 0 : error_found = true;
14451 : : }
14452 : :
14453 : 683284271 : if (TYPE_LANG_SLOT_1 (t) && in_lto_p)
14454 : : {
14455 : 0 : error ("%<TYPE_LANG_SLOT_1 (binfo)%> field is non-NULL");
14456 : 0 : debug_tree (TYPE_LANG_SLOT_1 (t));
14457 : 0 : error_found = true;
14458 : : }
14459 : :
14460 : : /* Check various uses of TYPE_VALUES_RAW. */
14461 : 683284271 : if (TREE_CODE (t) == ENUMERAL_TYPE)
14462 : 80817231 : for (tree l = TYPE_VALUES (t); l; l = TREE_CHAIN (l))
14463 : : {
14464 : 70799534 : tree value = TREE_VALUE (l);
14465 : 70799534 : tree name = TREE_PURPOSE (l);
14466 : :
14467 : : /* C FE porduce INTEGER_CST of INTEGER_TYPE, while C++ FE uses
14468 : : CONST_DECL of ENUMERAL TYPE. */
14469 : 70799534 : if (TREE_CODE (value) != INTEGER_CST && TREE_CODE (value) != CONST_DECL)
14470 : : {
14471 : 0 : error ("enum value is not %<CONST_DECL%> or %<INTEGER_CST%>");
14472 : 0 : debug_tree (value);
14473 : 0 : debug_tree (name);
14474 : 0 : error_found = true;
14475 : : }
14476 : 70799534 : if (TREE_CODE (TREE_TYPE (value)) != INTEGER_TYPE
14477 : 70782432 : && TREE_CODE (TREE_TYPE (value)) != BOOLEAN_TYPE
14478 : 141581963 : && !useless_type_conversion_p (const_cast <tree> (t), TREE_TYPE (value)))
14479 : : {
14480 : 0 : error ("enum value type is not %<INTEGER_TYPE%> nor convertible "
14481 : : "to the enum");
14482 : 0 : debug_tree (value);
14483 : 0 : debug_tree (name);
14484 : 0 : error_found = true;
14485 : : }
14486 : 70799534 : if (TREE_CODE (name) != IDENTIFIER_NODE)
14487 : : {
14488 : 0 : error ("enum value name is not %<IDENTIFIER_NODE%>");
14489 : 0 : debug_tree (value);
14490 : 0 : debug_tree (name);
14491 : 0 : error_found = true;
14492 : : }
14493 : : }
14494 : 673266574 : else if (TREE_CODE (t) == ARRAY_TYPE)
14495 : : {
14496 : 1533250 : if (TYPE_DOMAIN (t) && TREE_CODE (TYPE_DOMAIN (t)) != INTEGER_TYPE)
14497 : : {
14498 : 0 : error ("array %<TYPE_DOMAIN%> is not integer type");
14499 : 0 : debug_tree (TYPE_DOMAIN (t));
14500 : 0 : error_found = true;
14501 : : }
14502 : : }
14503 : 671733324 : else if (RECORD_OR_UNION_TYPE_P (t))
14504 : : {
14505 : 352878042 : if (TYPE_FIELDS (t) && !COMPLETE_TYPE_P (t) && in_lto_p)
14506 : : {
14507 : 0 : error ("%<TYPE_FIELDS%> defined in incomplete type");
14508 : 0 : error_found = true;
14509 : : }
14510 : 16325807012 : for (tree fld = TYPE_FIELDS (t); fld; fld = TREE_CHAIN (fld))
14511 : : {
14512 : : /* TODO: verify properties of decls. */
14513 : 15972928970 : if (TREE_CODE (fld) == FIELD_DECL)
14514 : : ;
14515 : : else if (TREE_CODE (fld) == TYPE_DECL)
14516 : : ;
14517 : : else if (TREE_CODE (fld) == CONST_DECL)
14518 : : ;
14519 : : else if (VAR_P (fld))
14520 : : ;
14521 : : else if (TREE_CODE (fld) == TEMPLATE_DECL)
14522 : : ;
14523 : : else if (TREE_CODE (fld) == USING_DECL)
14524 : : ;
14525 : : else if (TREE_CODE (fld) == FUNCTION_DECL)
14526 : : ;
14527 : : else
14528 : : {
14529 : 0 : error ("wrong tree in %<TYPE_FIELDS%> list");
14530 : 0 : debug_tree (fld);
14531 : 0 : error_found = true;
14532 : : }
14533 : : }
14534 : : }
14535 : 318855282 : else if (TREE_CODE (t) == INTEGER_TYPE
14536 : : || TREE_CODE (t) == BOOLEAN_TYPE
14537 : 318855282 : || TREE_CODE (t) == BITINT_TYPE
14538 : 237297346 : || TREE_CODE (t) == OFFSET_TYPE
14539 : 237262913 : || TREE_CODE (t) == REFERENCE_TYPE
14540 : 196625571 : || TREE_CODE (t) == NULLPTR_TYPE
14541 : 196346267 : || TREE_CODE (t) == POINTER_TYPE)
14542 : : {
14543 : 211386609 : if (TYPE_CACHED_VALUES_P (t) != (TYPE_CACHED_VALUES (t) != NULL))
14544 : : {
14545 : 0 : error ("%<TYPE_CACHED_VALUES_P%> is %i while %<TYPE_CACHED_VALUES%> "
14546 : : "is %p",
14547 : 0 : TYPE_CACHED_VALUES_P (t), (void *)TYPE_CACHED_VALUES (t));
14548 : 0 : error_found = true;
14549 : : }
14550 : 211386609 : else if (TYPE_CACHED_VALUES_P (t) && TREE_CODE (TYPE_CACHED_VALUES (t)) != TREE_VEC)
14551 : : {
14552 : 0 : error ("%<TYPE_CACHED_VALUES%> is not %<TREE_VEC%>");
14553 : 0 : debug_tree (TYPE_CACHED_VALUES (t));
14554 : 0 : error_found = true;
14555 : : }
14556 : : /* Verify just enough of cache to ensure that no one copied it to new type.
14557 : : All copying should go by copy_node that should clear it. */
14558 : 211386609 : else if (TYPE_CACHED_VALUES_P (t))
14559 : : {
14560 : : int i;
14561 : 7356382494 : for (i = 0; i < TREE_VEC_LENGTH (TYPE_CACHED_VALUES (t)); i++)
14562 : 7313822596 : if (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)
14563 : 7313822596 : && TREE_TYPE (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)) != t)
14564 : : {
14565 : 0 : error ("wrong %<TYPE_CACHED_VALUES%> entry");
14566 : 0 : debug_tree (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i));
14567 : 0 : error_found = true;
14568 : 0 : break;
14569 : : }
14570 : : }
14571 : : }
14572 : 107468673 : else if (FUNC_OR_METHOD_TYPE_P (t))
14573 : 12328481 : for (tree l = TYPE_ARG_TYPES (t); l; l = TREE_CHAIN (l))
14574 : : {
14575 : : /* C++ FE uses TREE_PURPOSE to store initial values. */
14576 : 9266005 : if (TREE_PURPOSE (l) && in_lto_p)
14577 : : {
14578 : 0 : error ("%<TREE_PURPOSE%> is non-NULL in %<TYPE_ARG_TYPES%> list");
14579 : 0 : debug_tree (l);
14580 : 0 : error_found = true;
14581 : : }
14582 : 9266005 : if (!TYPE_P (TREE_VALUE (l)))
14583 : : {
14584 : 0 : error ("wrong entry in %<TYPE_ARG_TYPES%> list");
14585 : 0 : debug_tree (l);
14586 : 0 : error_found = true;
14587 : : }
14588 : : }
14589 : 208604776 : else if (!is_lang_specific (t) && TYPE_VALUES_RAW (t))
14590 : : {
14591 : 0 : error ("%<TYPE_VALUES_RAW%> field is non-NULL");
14592 : 0 : debug_tree (TYPE_VALUES_RAW (t));
14593 : 0 : error_found = true;
14594 : : }
14595 : 683284271 : if (TREE_CODE (t) != INTEGER_TYPE
14596 : : && TREE_CODE (t) != BOOLEAN_TYPE
14597 : 683284271 : && TREE_CODE (t) != BITINT_TYPE
14598 : : && TREE_CODE (t) != OFFSET_TYPE
14599 : : && TREE_CODE (t) != REFERENCE_TYPE
14600 : : && TREE_CODE (t) != NULLPTR_TYPE
14601 : : && TREE_CODE (t) != POINTER_TYPE
14602 : 471897662 : && TYPE_CACHED_VALUES_P (t))
14603 : : {
14604 : 0 : error ("%<TYPE_CACHED_VALUES_P%> is set while it should not be");
14605 : 0 : error_found = true;
14606 : : }
14607 : :
14608 : : /* ipa-devirt makes an assumption that TYPE_METHOD_BASETYPE is always
14609 : : TYPE_MAIN_VARIANT and it would be odd to add methods only to variatns
14610 : : of a type. */
14611 : 683284271 : if (TREE_CODE (t) == METHOD_TYPE
14612 : 683284271 : && TYPE_MAIN_VARIANT (TYPE_METHOD_BASETYPE (t)) != TYPE_METHOD_BASETYPE (t))
14613 : : {
14614 : 0 : error ("%<TYPE_METHOD_BASETYPE%> is not main variant");
14615 : 0 : error_found = true;
14616 : : }
14617 : :
14618 : 683284271 : if (error_found)
14619 : : {
14620 : 0 : debug_tree (const_cast <tree> (t));
14621 : 0 : internal_error ("%qs failed", __func__);
14622 : : }
14623 : : }
14624 : :
14625 : :
14626 : : /* Return 1 if ARG interpreted as signed in its precision is known to be
14627 : : always non-negative or 2 if ARG is known to be always negative, or 3 if
14628 : : ARG may be non-negative or negative. */
14629 : :
14630 : : int
14631 : 281270 : get_range_pos_neg (tree arg)
14632 : : {
14633 : 281270 : if (arg == error_mark_node)
14634 : : return 3;
14635 : :
14636 : 281270 : int prec = TYPE_PRECISION (TREE_TYPE (arg));
14637 : 281270 : int cnt = 0;
14638 : 281270 : if (TREE_CODE (arg) == INTEGER_CST)
14639 : : {
14640 : 74254 : wide_int w = wi::sext (wi::to_wide (arg), prec);
14641 : 74254 : if (wi::neg_p (w))
14642 : : return 2;
14643 : : else
14644 : 59924 : return 1;
14645 : 74254 : }
14646 : 205753 : while (CONVERT_EXPR_P (arg)
14647 : 14621 : && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
14648 : 234995 : && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg, 0))) <= prec)
14649 : : {
14650 : 13977 : arg = TREE_OPERAND (arg, 0);
14651 : : /* Narrower value zero extended into wider type
14652 : : will always result in positive values. */
14653 : 13977 : if (TYPE_UNSIGNED (TREE_TYPE (arg))
14654 : 13977 : && TYPE_PRECISION (TREE_TYPE (arg)) < prec)
14655 : : return 1;
14656 : 13358 : prec = TYPE_PRECISION (TREE_TYPE (arg));
14657 : 13358 : if (++cnt > 30)
14658 : : return 3;
14659 : : }
14660 : :
14661 : 206397 : if (TREE_CODE (arg) != SSA_NAME)
14662 : : return 3;
14663 : 203062 : int_range_max r;
14664 : 411516 : while (!get_global_range_query ()->range_of_expr (r, arg)
14665 : 208454 : || r.undefined_p () || r.varying_p ())
14666 : : {
14667 : 151004 : gimple *g = SSA_NAME_DEF_STMT (arg);
14668 : 151004 : if (is_gimple_assign (g)
14669 : 151004 : && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (g)))
14670 : : {
14671 : 10287 : tree t = gimple_assign_rhs1 (g);
14672 : 20574 : if (INTEGRAL_TYPE_P (TREE_TYPE (t))
14673 : 18403 : && TYPE_PRECISION (TREE_TYPE (t)) <= prec)
14674 : : {
14675 : 7789 : if (TYPE_UNSIGNED (TREE_TYPE (t))
14676 : 7789 : && TYPE_PRECISION (TREE_TYPE (t)) < prec)
14677 : : return 1;
14678 : 5392 : prec = TYPE_PRECISION (TREE_TYPE (t));
14679 : 5392 : arg = t;
14680 : 5392 : if (++cnt > 30)
14681 : : return 3;
14682 : 5392 : continue;
14683 : : }
14684 : : }
14685 : : return 3;
14686 : : }
14687 : 57450 : if (TYPE_UNSIGNED (TREE_TYPE (arg)))
14688 : : {
14689 : : /* For unsigned values, the "positive" range comes
14690 : : below the "negative" range. */
14691 : 22657 : if (!wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14692 : : return 1;
14693 : 14177 : if (wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14694 : : return 2;
14695 : : }
14696 : : else
14697 : : {
14698 : 34793 : if (!wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14699 : : return 1;
14700 : 18694 : if (wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14701 : : return 2;
14702 : : }
14703 : : return 3;
14704 : 203062 : }
14705 : :
14706 : :
14707 : :
14708 : :
14709 : : /* Return true if ARG is marked with the nonnull attribute in the
14710 : : current function signature. */
14711 : :
14712 : : bool
14713 : 24230720 : nonnull_arg_p (const_tree arg)
14714 : : {
14715 : 24230720 : tree t, attrs, fntype;
14716 : 24230720 : unsigned HOST_WIDE_INT arg_num;
14717 : :
14718 : 24230720 : gcc_assert (TREE_CODE (arg) == PARM_DECL
14719 : : && (POINTER_TYPE_P (TREE_TYPE (arg))
14720 : : || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE));
14721 : :
14722 : : /* The static chain decl is always non null. */
14723 : 24230720 : if (arg == cfun->static_chain_decl)
14724 : : return true;
14725 : :
14726 : : /* THIS argument of method is always non-NULL. */
14727 : 23962353 : if (TREE_CODE (TREE_TYPE (cfun->decl)) == METHOD_TYPE
14728 : 8992868 : && arg == DECL_ARGUMENTS (cfun->decl)
14729 : 29612578 : && flag_delete_null_pointer_checks)
14730 : : return true;
14731 : :
14732 : : /* Values passed by reference are always non-NULL. */
14733 : 18314236 : if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE
14734 : 18314236 : && flag_delete_null_pointer_checks)
14735 : : return true;
14736 : :
14737 : 13058152 : fntype = TREE_TYPE (cfun->decl);
14738 : 13081096 : for (attrs = TYPE_ATTRIBUTES (fntype); attrs; attrs = TREE_CHAIN (attrs))
14739 : : {
14740 : 528163 : attrs = lookup_attribute ("nonnull", attrs);
14741 : :
14742 : : /* If "nonnull" wasn't specified, we know nothing about the argument. */
14743 : 528163 : if (attrs == NULL_TREE)
14744 : : return false;
14745 : :
14746 : : /* If "nonnull" applies to all the arguments, then ARG is non-null. */
14747 : 108732 : if (TREE_VALUE (attrs) == NULL_TREE)
14748 : : return true;
14749 : :
14750 : : /* Get the position number for ARG in the function signature. */
14751 : 55651 : for (arg_num = 1, t = DECL_ARGUMENTS (cfun->decl);
14752 : 130205 : t;
14753 : 74554 : t = DECL_CHAIN (t), arg_num++)
14754 : : {
14755 : 130205 : if (t == arg)
14756 : : break;
14757 : : }
14758 : :
14759 : 55651 : gcc_assert (t == arg);
14760 : :
14761 : : /* Now see if ARG_NUM is mentioned in the nonnull list. */
14762 : 88349 : for (t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
14763 : : {
14764 : 65405 : if (compare_tree_int (TREE_VALUE (t), arg_num) == 0)
14765 : : return true;
14766 : : }
14767 : : }
14768 : :
14769 : : return false;
14770 : : }
14771 : :
14772 : : /* Combine LOC and BLOCK to a combined adhoc loc, retaining any range
14773 : : information. */
14774 : :
14775 : : location_t
14776 : 588029207 : set_block (location_t loc, tree block)
14777 : : {
14778 : 588029207 : location_t pure_loc = get_pure_location (loc);
14779 : 588029207 : source_range src_range = get_range_from_loc (line_table, loc);
14780 : 588029207 : unsigned discriminator = get_discriminator_from_loc (line_table, loc);
14781 : 588029207 : return line_table->get_or_create_combined_loc (pure_loc, src_range, block,
14782 : 588029207 : discriminator);
14783 : : }
14784 : :
14785 : : location_t
14786 : 225576548 : set_source_range (tree expr, location_t start, location_t finish)
14787 : : {
14788 : 225576548 : source_range src_range;
14789 : 225576548 : src_range.m_start = start;
14790 : 225576548 : src_range.m_finish = finish;
14791 : 225576548 : return set_source_range (expr, src_range);
14792 : : }
14793 : :
14794 : : location_t
14795 : 460199055 : set_source_range (tree expr, source_range src_range)
14796 : : {
14797 : 460199055 : if (!EXPR_P (expr))
14798 : : return UNKNOWN_LOCATION;
14799 : :
14800 : 202839811 : location_t expr_location = EXPR_LOCATION (expr);
14801 : 202839811 : location_t pure_loc = get_pure_location (expr_location);
14802 : 202839811 : unsigned discriminator = get_discriminator_from_loc (expr_location);
14803 : 202839811 : location_t adhoc = line_table->get_or_create_combined_loc (pure_loc,
14804 : : src_range,
14805 : : nullptr,
14806 : : discriminator);
14807 : 202839811 : SET_EXPR_LOCATION (expr, adhoc);
14808 : 202839811 : return adhoc;
14809 : : }
14810 : :
14811 : : /* Return EXPR, potentially wrapped with a node expression LOC,
14812 : : if !CAN_HAVE_LOCATION_P (expr).
14813 : :
14814 : : NON_LVALUE_EXPR is used for wrapping constants, apart from STRING_CST.
14815 : : VIEW_CONVERT_EXPR is used for wrapping non-constants and STRING_CST.
14816 : :
14817 : : Wrapper nodes can be identified using location_wrapper_p. */
14818 : :
14819 : : tree
14820 : 1147752901 : maybe_wrap_with_location (tree expr, location_t loc)
14821 : : {
14822 : 1147752901 : if (expr == NULL)
14823 : : return NULL;
14824 : 1147752897 : if (loc == UNKNOWN_LOCATION)
14825 : : return expr;
14826 : 1109918514 : if (CAN_HAVE_LOCATION_P (expr))
14827 : : return expr;
14828 : : /* We should only be adding wrappers for constants and for decls,
14829 : : or for some exceptional tree nodes (e.g. BASELINK in the C++ FE). */
14830 : 667009773 : gcc_assert (CONSTANT_CLASS_P (expr)
14831 : : || DECL_P (expr)
14832 : : || EXCEPTIONAL_CLASS_P (expr));
14833 : :
14834 : : /* For now, don't add wrappers to exceptional tree nodes, to minimize
14835 : : any impact of the wrapper nodes. */
14836 : 667009773 : if (EXCEPTIONAL_CLASS_P (expr) || error_operand_p (expr))
14837 : : return expr;
14838 : :
14839 : : /* Compiler-generated temporary variables don't need a wrapper. */
14840 : 613576810 : if (DECL_P (expr) && DECL_ARTIFICIAL (expr) && DECL_IGNORED_P (expr))
14841 : : return expr;
14842 : :
14843 : : /* If any auto_suppress_location_wrappers are active, don't create
14844 : : wrappers. */
14845 : 613574554 : if (suppress_location_wrappers > 0)
14846 : : return expr;
14847 : :
14848 : 1175885060 : tree_code code
14849 : 144463606 : = (((CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST)
14850 : 449749358 : || (TREE_CODE (expr) == CONST_DECL && !TREE_STATIC (expr)))
14851 : 587942530 : ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR);
14852 : 587942530 : tree wrapper = build1_loc (loc, code, TREE_TYPE (expr), expr);
14853 : : /* Mark this node as being a wrapper. */
14854 : 587942530 : EXPR_LOCATION_WRAPPER_P (wrapper) = 1;
14855 : 587942530 : return wrapper;
14856 : : }
14857 : :
14858 : : int suppress_location_wrappers;
14859 : :
14860 : : /* Return the name of combined function FN, for debugging purposes. */
14861 : :
14862 : : const char *
14863 : 0 : combined_fn_name (combined_fn fn)
14864 : : {
14865 : 0 : if (builtin_fn_p (fn))
14866 : : {
14867 : 0 : tree fndecl = builtin_decl_explicit (as_builtin_fn (fn));
14868 : 0 : return IDENTIFIER_POINTER (DECL_NAME (fndecl));
14869 : : }
14870 : : else
14871 : 0 : return internal_fn_name (as_internal_fn (fn));
14872 : : }
14873 : :
14874 : : /* Return a bitmap with a bit set corresponding to each argument in
14875 : : a function call type FNTYPE declared with attribute nonnull,
14876 : : or null if none of the function's argument are nonnull. The caller
14877 : : must free the bitmap. */
14878 : :
14879 : : bitmap
14880 : 19735577 : get_nonnull_args (const_tree fntype)
14881 : : {
14882 : 19735577 : if (fntype == NULL_TREE)
14883 : : return NULL;
14884 : :
14885 : 19342067 : bitmap argmap = NULL;
14886 : 19342067 : if (TREE_CODE (fntype) == METHOD_TYPE)
14887 : : {
14888 : : /* The this pointer in C++ non-static member functions is
14889 : : implicitly nonnull whether or not it's declared as such. */
14890 : 2508354 : argmap = BITMAP_ALLOC (NULL);
14891 : 2508354 : bitmap_set_bit (argmap, 0);
14892 : : }
14893 : :
14894 : 19342067 : tree attrs = TYPE_ATTRIBUTES (fntype);
14895 : 19342067 : if (!attrs)
14896 : : return argmap;
14897 : :
14898 : : /* A function declaration can specify multiple attribute nonnull,
14899 : : each with zero or more arguments. The loop below creates a bitmap
14900 : : representing a union of all the arguments. An empty (but non-null)
14901 : : bitmap means that all arguments have been declared nonnull. */
14902 : 5170059 : for ( ; attrs; attrs = TREE_CHAIN (attrs))
14903 : : {
14904 : 5087000 : attrs = lookup_attribute ("nonnull", attrs);
14905 : 5087000 : if (!attrs)
14906 : : break;
14907 : :
14908 : 1533802 : if (!argmap)
14909 : 1494408 : argmap = BITMAP_ALLOC (NULL);
14910 : :
14911 : 1533802 : if (!TREE_VALUE (attrs))
14912 : : {
14913 : : /* Clear the bitmap in case a previous attribute nonnull
14914 : : set it and this one overrides it for all arguments. */
14915 : 988594 : bitmap_clear (argmap);
14916 : 988594 : return argmap;
14917 : : }
14918 : :
14919 : : /* Iterate over the indices of the format arguments declared nonnull
14920 : : and set a bit for each. */
14921 : 1428412 : for (tree idx = TREE_VALUE (attrs); idx; idx = TREE_CHAIN (idx))
14922 : : {
14923 : 883204 : unsigned int val = TREE_INT_CST_LOW (TREE_VALUE (idx)) - 1;
14924 : 883204 : bitmap_set_bit (argmap, val);
14925 : : }
14926 : : }
14927 : :
14928 : : return argmap;
14929 : : }
14930 : :
14931 : : /* Returns true if TYPE is a type where it and all of its subobjects
14932 : : (recursively) are of structure, union, or array type. */
14933 : :
14934 : : bool
14935 : 1709275392 : is_empty_type (const_tree type)
14936 : : {
14937 : 1709275392 : if (RECORD_OR_UNION_TYPE_P (type))
14938 : : {
14939 : 725280653 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
14940 : 676203858 : if (TREE_CODE (field) == FIELD_DECL
14941 : 392344448 : && !DECL_PADDING_P (field)
14942 : 1068547071 : && !is_empty_type (TREE_TYPE (field)))
14943 : : return false;
14944 : : return true;
14945 : : }
14946 : 1288541288 : else if (TREE_CODE (type) == ARRAY_TYPE)
14947 : 66364356 : return (integer_minus_onep (array_type_nelts_minus_one (type))
14948 : 66321142 : || TYPE_DOMAIN (type) == NULL_TREE
14949 : 128387604 : || is_empty_type (TREE_TYPE (type)));
14950 : : return false;
14951 : : }
14952 : :
14953 : : /* Implement TARGET_EMPTY_RECORD_P. Return true if TYPE is an empty type
14954 : : that shouldn't be passed via stack. */
14955 : :
14956 : : bool
14957 : 1207479688 : default_is_empty_record (const_tree type)
14958 : : {
14959 : 1207479688 : if (!abi_version_at_least (12))
14960 : : return false;
14961 : :
14962 : 1206411942 : if (type == error_mark_node)
14963 : : return false;
14964 : :
14965 : 1206411942 : if (TREE_ADDRESSABLE (type))
14966 : : return false;
14967 : :
14968 : 1206411942 : return is_empty_type (TYPE_MAIN_VARIANT (type));
14969 : : }
14970 : :
14971 : : /* Determine whether TYPE is a structure with a flexible array member,
14972 : : or a union containing such a structure (possibly recursively). */
14973 : :
14974 : : bool
14975 : 71580 : flexible_array_type_p (const_tree type)
14976 : : {
14977 : 71580 : tree x, last;
14978 : 71580 : switch (TREE_CODE (type))
14979 : : {
14980 : 36676 : case RECORD_TYPE:
14981 : 36676 : last = NULL_TREE;
14982 : 168101 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
14983 : 131425 : if (TREE_CODE (x) == FIELD_DECL)
14984 : 131425 : last = x;
14985 : 36676 : if (last == NULL_TREE)
14986 : : return false;
14987 : 36669 : if (TREE_CODE (TREE_TYPE (last)) == ARRAY_TYPE
14988 : 270 : && TYPE_SIZE (TREE_TYPE (last)) == NULL_TREE
14989 : 36 : && TYPE_DOMAIN (TREE_TYPE (last)) != NULL_TREE
14990 : 36705 : && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (last))) == NULL_TREE)
14991 : : return true;
14992 : : return false;
14993 : 616 : case UNION_TYPE:
14994 : 1782 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
14995 : : {
14996 : 1208 : if (TREE_CODE (x) == FIELD_DECL
14997 : 1208 : && flexible_array_type_p (TREE_TYPE (x)))
14998 : : return true;
14999 : : }
15000 : : return false;
15001 : : default:
15002 : : return false;
15003 : : }
15004 : : }
15005 : :
15006 : : /* Like int_size_in_bytes, but handle empty records specially. */
15007 : :
15008 : : HOST_WIDE_INT
15009 : 364963 : arg_int_size_in_bytes (const_tree type)
15010 : : {
15011 : 364963 : return TYPE_EMPTY_P (type) ? 0 : int_size_in_bytes (type);
15012 : : }
15013 : :
15014 : : /* Like size_in_bytes, but handle empty records specially. */
15015 : :
15016 : : tree
15017 : 5574702 : arg_size_in_bytes (const_tree type)
15018 : : {
15019 : 5574702 : return TYPE_EMPTY_P (type) ? size_zero_node : size_in_bytes (type);
15020 : : }
15021 : :
15022 : : /* Return true if an expression with CODE has to have the same result type as
15023 : : its first operand. */
15024 : :
15025 : : bool
15026 : 3246 : expr_type_first_operand_type_p (tree_code code)
15027 : : {
15028 : 3246 : switch (code)
15029 : : {
15030 : : case NEGATE_EXPR:
15031 : : case ABS_EXPR:
15032 : : case BIT_NOT_EXPR:
15033 : : case PAREN_EXPR:
15034 : : case CONJ_EXPR:
15035 : :
15036 : : case PLUS_EXPR:
15037 : : case MINUS_EXPR:
15038 : : case MULT_EXPR:
15039 : : case TRUNC_DIV_EXPR:
15040 : : case CEIL_DIV_EXPR:
15041 : : case FLOOR_DIV_EXPR:
15042 : : case ROUND_DIV_EXPR:
15043 : : case TRUNC_MOD_EXPR:
15044 : : case CEIL_MOD_EXPR:
15045 : : case FLOOR_MOD_EXPR:
15046 : : case ROUND_MOD_EXPR:
15047 : : case RDIV_EXPR:
15048 : : case EXACT_DIV_EXPR:
15049 : : case MIN_EXPR:
15050 : : case MAX_EXPR:
15051 : : case BIT_IOR_EXPR:
15052 : : case BIT_XOR_EXPR:
15053 : : case BIT_AND_EXPR:
15054 : :
15055 : : case LSHIFT_EXPR:
15056 : : case RSHIFT_EXPR:
15057 : : case LROTATE_EXPR:
15058 : : case RROTATE_EXPR:
15059 : : return true;
15060 : :
15061 : 659 : default:
15062 : 659 : return false;
15063 : : }
15064 : : }
15065 : :
15066 : : /* Return a typenode for the "standard" C type with a given name. */
15067 : : tree
15068 : 894687 : get_typenode_from_name (const char *name)
15069 : : {
15070 : 894687 : if (name == NULL || *name == '\0')
15071 : : return NULL_TREE;
15072 : :
15073 : 894687 : if (strcmp (name, "char") == 0)
15074 : 0 : return char_type_node;
15075 : 894687 : if (strcmp (name, "unsigned char") == 0)
15076 : 92367 : return unsigned_char_type_node;
15077 : 802320 : if (strcmp (name, "signed char") == 0)
15078 : 92367 : return signed_char_type_node;
15079 : :
15080 : 709953 : if (strcmp (name, "short int") == 0)
15081 : 63084 : return short_integer_type_node;
15082 : 646869 : if (strcmp (name, "short unsigned int") == 0)
15083 : 61578 : return short_unsigned_type_node;
15084 : :
15085 : 585291 : if (strcmp (name, "int") == 0)
15086 : 63913 : return integer_type_node;
15087 : 521378 : if (strcmp (name, "unsigned int") == 0)
15088 : 62392 : return unsigned_type_node;
15089 : :
15090 : 458986 : if (strcmp (name, "long int") == 0)
15091 : 273438 : return long_integer_type_node;
15092 : 185548 : if (strcmp (name, "long unsigned int") == 0)
15093 : 182292 : return long_unsigned_type_node;
15094 : :
15095 : 3256 : if (strcmp (name, "long long int") == 0)
15096 : 1628 : return long_long_integer_type_node;
15097 : 1628 : if (strcmp (name, "long long unsigned int") == 0)
15098 : 1628 : return long_long_unsigned_type_node;
15099 : :
15100 : 0 : gcc_unreachable ();
15101 : : }
15102 : :
15103 : : /* List of pointer types used to declare builtins before we have seen their
15104 : : real declaration.
15105 : :
15106 : : Keep the size up to date in tree.h ! */
15107 : : const builtin_structptr_type builtin_structptr_types[6] =
15108 : : {
15109 : : { fileptr_type_node, ptr_type_node, "FILE" },
15110 : : { const_tm_ptr_type_node, const_ptr_type_node, "tm" },
15111 : : { fenv_t_ptr_type_node, ptr_type_node, "fenv_t" },
15112 : : { const_fenv_t_ptr_type_node, const_ptr_type_node, "fenv_t" },
15113 : : { fexcept_t_ptr_type_node, ptr_type_node, "fexcept_t" },
15114 : : { const_fexcept_t_ptr_type_node, const_ptr_type_node, "fexcept_t" }
15115 : : };
15116 : :
15117 : : /* Return the maximum object size. */
15118 : :
15119 : : tree
15120 : 6687912 : max_object_size (void)
15121 : : {
15122 : : /* To do: Make this a configurable parameter. */
15123 : 6687912 : return TYPE_MAX_VALUE (ptrdiff_type_node);
15124 : : }
15125 : :
15126 : : /* A wrapper around TARGET_VERIFY_TYPE_CONTEXT that makes the silent_p
15127 : : parameter default to false and that weeds out error_mark_node. */
15128 : :
15129 : : bool
15130 : 106409358 : verify_type_context (location_t loc, type_context_kind context,
15131 : : const_tree type, bool silent_p)
15132 : : {
15133 : 106409358 : if (type == error_mark_node)
15134 : : return true;
15135 : :
15136 : 106409266 : gcc_assert (TYPE_P (type));
15137 : 106409266 : return (!targetm.verify_type_context
15138 : 106409266 : || targetm.verify_type_context (loc, context, type, silent_p));
15139 : : }
15140 : :
15141 : : /* Return true if NEW_ASM and DELETE_ASM name a valid pair of new and
15142 : : delete operators. Return false if they may or may not name such
15143 : : a pair and, when nonnull, set *PCERTAIN to true if they certainly
15144 : : do not. */
15145 : :
15146 : : bool
15147 : 48189 : valid_new_delete_pair_p (tree new_asm, tree delete_asm,
15148 : : bool *pcertain /* = NULL */)
15149 : : {
15150 : 48189 : bool certain;
15151 : 48189 : if (!pcertain)
15152 : 39199 : pcertain = &certain;
15153 : :
15154 : 48189 : const char *new_name = IDENTIFIER_POINTER (new_asm);
15155 : 48189 : const char *delete_name = IDENTIFIER_POINTER (delete_asm);
15156 : 48189 : unsigned int new_len = IDENTIFIER_LENGTH (new_asm);
15157 : 48189 : unsigned int delete_len = IDENTIFIER_LENGTH (delete_asm);
15158 : :
15159 : : /* The following failures are due to invalid names so they're not
15160 : : considered certain mismatches. */
15161 : 48189 : *pcertain = false;
15162 : :
15163 : 48189 : if (new_len < 5 || delete_len < 6)
15164 : : return false;
15165 : 48189 : if (new_name[0] == '_')
15166 : 48133 : ++new_name, --new_len;
15167 : 48189 : if (new_name[0] == '_')
15168 : 0 : ++new_name, --new_len;
15169 : 48189 : if (delete_name[0] == '_')
15170 : 48189 : ++delete_name, --delete_len;
15171 : 48189 : if (delete_name[0] == '_')
15172 : 0 : ++delete_name, --delete_len;
15173 : 48189 : if (new_len < 4 || delete_len < 5)
15174 : : return false;
15175 : :
15176 : : /* The following failures are due to names of user-defined operators
15177 : : so they're also not considered certain mismatches. */
15178 : :
15179 : : /* *_len is now just the length after initial underscores. */
15180 : 48189 : if (new_name[0] != 'Z' || new_name[1] != 'n')
15181 : : return false;
15182 : 47582 : if (delete_name[0] != 'Z' || delete_name[1] != 'd')
15183 : : return false;
15184 : :
15185 : : /* The following failures are certain mismatches. */
15186 : 47552 : *pcertain = true;
15187 : :
15188 : : /* _Znw must match _Zdl, _Zna must match _Zda. */
15189 : 47552 : if ((new_name[2] != 'w' || delete_name[2] != 'l')
15190 : 7021 : && (new_name[2] != 'a' || delete_name[2] != 'a'))
15191 : : return false;
15192 : : /* 'j', 'm' and 'y' correspond to size_t. */
15193 : 47438 : if (new_name[3] != 'j' && new_name[3] != 'm' && new_name[3] != 'y')
15194 : : return false;
15195 : 47438 : if (delete_name[3] != 'P' || delete_name[4] != 'v')
15196 : : return false;
15197 : 47438 : if (new_len == 4
15198 : 188 : || (new_len == 18 && !memcmp (new_name + 4, "RKSt9nothrow_t", 14)))
15199 : : {
15200 : : /* _ZnXY or _ZnXYRKSt9nothrow_t matches
15201 : : _ZdXPv, _ZdXPvY and _ZdXPvRKSt9nothrow_t. */
15202 : 47353 : if (delete_len == 5)
15203 : : return true;
15204 : 38465 : if (delete_len == 6 && delete_name[5] == new_name[3])
15205 : : return true;
15206 : 33 : if (delete_len == 19 && !memcmp (delete_name + 5, "RKSt9nothrow_t", 14))
15207 : : return true;
15208 : : }
15209 : 85 : else if ((new_len == 19 && !memcmp (new_name + 4, "St11align_val_t", 15))
15210 : 42 : || (new_len == 33
15211 : 10 : && !memcmp (new_name + 4, "St11align_val_tRKSt9nothrow_t", 29)))
15212 : : {
15213 : : /* _ZnXYSt11align_val_t or _ZnXYSt11align_val_tRKSt9nothrow_t matches
15214 : : _ZdXPvSt11align_val_t or _ZdXPvYSt11align_val_t or
15215 : : _ZdXPvSt11align_val_tRKSt9nothrow_t. */
15216 : 53 : if (delete_len == 20 && !memcmp (delete_name + 5, "St11align_val_t", 15))
15217 : : return true;
15218 : 34 : if (delete_len == 21
15219 : 19 : && delete_name[5] == new_name[3]
15220 : 19 : && !memcmp (delete_name + 6, "St11align_val_t", 15))
15221 : : return true;
15222 : 15 : if (delete_len == 34
15223 : 9 : && !memcmp (delete_name + 5, "St11align_val_tRKSt9nothrow_t", 29))
15224 : : return true;
15225 : : }
15226 : :
15227 : : /* The negative result is conservative. */
15228 : 38 : *pcertain = false;
15229 : 38 : return false;
15230 : : }
15231 : :
15232 : : /* Return the zero-based number corresponding to the argument being
15233 : : deallocated if FNDECL is a deallocation function or an out-of-bounds
15234 : : value if it isn't. */
15235 : :
15236 : : unsigned
15237 : 26788625 : fndecl_dealloc_argno (tree fndecl)
15238 : : {
15239 : : /* A call to operator delete isn't recognized as one to a built-in. */
15240 : 26788625 : if (DECL_IS_OPERATOR_DELETE_P (fndecl))
15241 : : {
15242 : 401754 : if (DECL_IS_REPLACEABLE_OPERATOR (fndecl))
15243 : : return 0;
15244 : :
15245 : : /* Avoid placement delete that's not been inlined. */
15246 : 22817 : tree fname = DECL_ASSEMBLER_NAME (fndecl);
15247 : 22817 : if (id_equal (fname, "_ZdlPvS_") // ordinary form
15248 : 22817 : || id_equal (fname, "_ZdaPvS_")) // array form
15249 : : return UINT_MAX;
15250 : : return 0;
15251 : : }
15252 : :
15253 : : /* TODO: Handle user-defined functions with attribute malloc? Handle
15254 : : known non-built-ins like fopen? */
15255 : 26386871 : if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
15256 : : {
15257 : 6812362 : switch (DECL_FUNCTION_CODE (fndecl))
15258 : : {
15259 : : case BUILT_IN_FREE:
15260 : : case BUILT_IN_REALLOC:
15261 : : case BUILT_IN_GOMP_FREE:
15262 : : case BUILT_IN_GOMP_REALLOC:
15263 : : return 0;
15264 : : default:
15265 : : break;
15266 : : }
15267 : : return UINT_MAX;
15268 : : }
15269 : :
15270 : 19574509 : tree attrs = DECL_ATTRIBUTES (fndecl);
15271 : 19574509 : if (!attrs)
15272 : : return UINT_MAX;
15273 : :
15274 : 0 : for (tree atfree = attrs;
15275 : 4350622 : (atfree = lookup_attribute ("*dealloc", atfree));
15276 : 0 : atfree = TREE_CHAIN (atfree))
15277 : : {
15278 : 5543 : tree alloc = TREE_VALUE (atfree);
15279 : 5543 : if (!alloc)
15280 : 0 : continue;
15281 : :
15282 : 5543 : tree pos = TREE_CHAIN (alloc);
15283 : 5543 : if (!pos)
15284 : : return 0;
15285 : :
15286 : 3516 : pos = TREE_VALUE (pos);
15287 : 3516 : return TREE_INT_CST_LOW (pos) - 1;
15288 : : }
15289 : :
15290 : : return UINT_MAX;
15291 : : }
15292 : :
15293 : : /* If EXPR refers to a character array or pointer declared attribute
15294 : : nonstring, return a decl for that array or pointer and set *REF
15295 : : to the referenced enclosing object or pointer. Otherwise return
15296 : : null. */
15297 : :
15298 : : tree
15299 : 1376999 : get_attr_nonstring_decl (tree expr, tree *ref)
15300 : : {
15301 : 1382718 : tree decl = expr;
15302 : 1382718 : tree var = NULL_TREE;
15303 : 1382718 : if (TREE_CODE (decl) == SSA_NAME)
15304 : : {
15305 : 836062 : gimple *def = SSA_NAME_DEF_STMT (decl);
15306 : :
15307 : 836062 : if (is_gimple_assign (def))
15308 : : {
15309 : 45785 : tree_code code = gimple_assign_rhs_code (def);
15310 : 45785 : if (code == ADDR_EXPR
15311 : 45785 : || code == COMPONENT_REF
15312 : 30934 : || code == VAR_DECL)
15313 : 19692 : decl = gimple_assign_rhs1 (def);
15314 : : }
15315 : : else
15316 : 790277 : var = SSA_NAME_VAR (decl);
15317 : : }
15318 : :
15319 : 1382718 : if (TREE_CODE (decl) == ADDR_EXPR)
15320 : 27240 : decl = TREE_OPERAND (decl, 0);
15321 : :
15322 : : /* To simplify calling code, store the referenced DECL regardless of
15323 : : the attribute determined below, but avoid storing the SSA_NAME_VAR
15324 : : obtained above (it's not useful for dataflow purposes). */
15325 : 1382718 : if (ref)
15326 : 5435 : *ref = decl;
15327 : :
15328 : : /* Use the SSA_NAME_VAR that was determined above to see if it's
15329 : : declared nonstring. Otherwise drill down into the referenced
15330 : : DECL. */
15331 : 1382718 : if (var)
15332 : : decl = var;
15333 : : else
15334 : : {
15335 : 617941 : while (TREE_CODE (decl) == ARRAY_REF)
15336 : 18746 : decl = TREE_OPERAND (decl, 0);
15337 : 599195 : if (TREE_CODE (decl) == COMPONENT_REF)
15338 : 16751 : decl = TREE_OPERAND (decl, 1);
15339 : 582444 : else if (TREE_CODE (decl) == MEM_REF)
15340 : 5719 : return get_attr_nonstring_decl (TREE_OPERAND (decl, 0), ref);
15341 : : }
15342 : :
15343 : 1376999 : if (DECL_P (decl) && lookup_attribute ("nonstring", DECL_ATTRIBUTES (decl)))
15344 : : return decl;
15345 : :
15346 : : return NULL_TREE;
15347 : : }
15348 : :
15349 : : /* Return length of attribute names string,
15350 : : if arglist chain > 1, -1 otherwise. */
15351 : :
15352 : : int
15353 : 156 : get_target_clone_attr_len (tree arglist)
15354 : : {
15355 : 156 : tree arg;
15356 : 156 : int str_len_sum = 0;
15357 : 156 : int argnum = 0;
15358 : :
15359 : 560 : for (arg = arglist; arg; arg = TREE_CHAIN (arg))
15360 : : {
15361 : 404 : const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
15362 : 404 : size_t len = strlen (str);
15363 : 404 : str_len_sum += len + 1;
15364 : 404 : for (const char *p = strchr (str, TARGET_CLONES_ATTR_SEPARATOR);
15365 : 432 : p;
15366 : 28 : p = strchr (p + 1, TARGET_CLONES_ATTR_SEPARATOR))
15367 : 28 : argnum++;
15368 : 404 : argnum++;
15369 : : }
15370 : 156 : if (argnum <= 1)
15371 : 1 : return -1;
15372 : : return str_len_sum;
15373 : : }
15374 : :
15375 : : void
15376 : 255021 : tree_cc_finalize (void)
15377 : : {
15378 : 255021 : clear_nonstandard_integer_type_cache ();
15379 : 255021 : vec_free (bitint_type_cache);
15380 : 255021 : }
15381 : :
15382 : : void
15383 : 129 : gt_ggc_mx (tree_raw_data *x)
15384 : : {
15385 : 129 : gt_ggc_m_9tree_node (x->typed.type);
15386 : 129 : gt_ggc_m_9tree_node (x->owner);
15387 : 129 : }
15388 : :
15389 : : void
15390 : 12 : gt_pch_nx (tree_raw_data *x)
15391 : : {
15392 : 12 : gt_pch_n_9tree_node (x->typed.type);
15393 : 12 : gt_pch_n_9tree_node (x->owner);
15394 : 12 : }
15395 : :
15396 : : /* For PCH we guarantee that RAW_DATA_CST's RAW_DATA_OWNER is a STRING_CST and
15397 : : RAW_DATA_POINTER points into it. We don't want to save/restore
15398 : : RAW_DATA_POINTER on its own but want to restore it pointing at the same
15399 : : offset of the STRING_CST as before. */
15400 : :
15401 : : void
15402 : 12 : gt_pch_nx (tree_raw_data *x, gt_pointer_operator op, void *cookie)
15403 : : {
15404 : 12 : op (&x->typed.type, NULL, cookie);
15405 : 12 : gcc_checking_assert (x->owner
15406 : : && TREE_CODE (x->owner) == STRING_CST
15407 : : && x->str >= TREE_STRING_POINTER (x->owner)
15408 : : && (x->str + x->length
15409 : : <= (TREE_STRING_POINTER (x->owner)
15410 : : + TREE_STRING_LENGTH (x->owner))));
15411 : 12 : ptrdiff_t off = x->str - (const char *) (x->owner);
15412 : 12 : tree owner = x->owner;
15413 : 12 : op (&x->owner, NULL, cookie);
15414 : 12 : x->owner = owner;
15415 : : /* The above op call relocates x->owner and remembers the address
15416 : : for relocation e.g. if the compiler is position independent.
15417 : : We then restore x->owner back to its previous value and call
15418 : : op again, for x->owner itself this just repeats (uselessly) what
15419 : : the first call did, but as the second argument is now non-NULL
15420 : : and different, it also arranges for &x->str to be noted for the
15421 : : PIE relocation. */
15422 : 12 : op (&x->owner, &x->str, cookie);
15423 : 12 : x->str = (const char *) (x->owner) + off;
15424 : 12 : }
15425 : :
15426 : : #if CHECKING_P
15427 : :
15428 : : namespace selftest {
15429 : :
15430 : : /* Selftests for tree. */
15431 : :
15432 : : /* Verify that integer constants are sane. */
15433 : :
15434 : : static void
15435 : 4 : test_integer_constants ()
15436 : : {
15437 : 4 : ASSERT_TRUE (integer_type_node != NULL);
15438 : 4 : ASSERT_TRUE (build_int_cst (integer_type_node, 0) != NULL);
15439 : :
15440 : 4 : tree type = integer_type_node;
15441 : :
15442 : 4 : tree zero = build_zero_cst (type);
15443 : 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (zero));
15444 : 4 : ASSERT_EQ (type, TREE_TYPE (zero));
15445 : :
15446 : 4 : tree one = build_int_cst (type, 1);
15447 : 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (one));
15448 : 4 : ASSERT_EQ (type, TREE_TYPE (zero));
15449 : 4 : }
15450 : :
15451 : : /* Verify identifiers. */
15452 : :
15453 : : static void
15454 : 4 : test_identifiers ()
15455 : : {
15456 : 4 : tree identifier = get_identifier ("foo");
15457 : 4 : ASSERT_EQ (3, IDENTIFIER_LENGTH (identifier));
15458 : 4 : ASSERT_STREQ ("foo", IDENTIFIER_POINTER (identifier));
15459 : 4 : }
15460 : :
15461 : : /* Verify LABEL_DECL. */
15462 : :
15463 : : static void
15464 : 4 : test_labels ()
15465 : : {
15466 : 4 : tree identifier = get_identifier ("err");
15467 : 4 : tree label_decl = build_decl (UNKNOWN_LOCATION, LABEL_DECL,
15468 : : identifier, void_type_node);
15469 : 4 : ASSERT_EQ (-1, LABEL_DECL_UID (label_decl));
15470 : 4 : ASSERT_FALSE (FORCED_LABEL (label_decl));
15471 : 4 : }
15472 : :
15473 : : /* Return a new VECTOR_CST node whose type is TYPE and whose values
15474 : : are given by VALS. */
15475 : :
15476 : : static tree
15477 : 40 : build_vector (tree type, const vec<tree> &vals MEM_STAT_DECL)
15478 : : {
15479 : 80 : gcc_assert (known_eq (vals.length (), TYPE_VECTOR_SUBPARTS (type)));
15480 : 40 : tree_vector_builder builder (type, vals.length (), 1);
15481 : 40 : builder.splice (vals);
15482 : 40 : return builder.build ();
15483 : 40 : }
15484 : :
15485 : : /* Check that VECTOR_CST ACTUAL contains the elements in EXPECTED. */
15486 : :
15487 : : static void
15488 : 40 : check_vector_cst (const vec<tree> &expected, tree actual)
15489 : : {
15490 : 80 : ASSERT_KNOWN_EQ (expected.length (),
15491 : : TYPE_VECTOR_SUBPARTS (TREE_TYPE (actual)));
15492 : 360 : for (unsigned int i = 0; i < expected.length (); ++i)
15493 : 320 : ASSERT_EQ (wi::to_wide (expected[i]),
15494 : : wi::to_wide (vector_cst_elt (actual, i)));
15495 : 40 : }
15496 : :
15497 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS duplicated elements,
15498 : : and that its elements match EXPECTED. */
15499 : :
15500 : : static void
15501 : 8 : check_vector_cst_duplicate (const vec<tree> &expected, tree actual,
15502 : : unsigned int npatterns)
15503 : : {
15504 : 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15505 : 8 : ASSERT_EQ (1, VECTOR_CST_NELTS_PER_PATTERN (actual));
15506 : 8 : ASSERT_EQ (npatterns, vector_cst_encoded_nelts (actual));
15507 : 8 : ASSERT_TRUE (VECTOR_CST_DUPLICATE_P (actual));
15508 : 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
15509 : 8 : check_vector_cst (expected, actual);
15510 : 8 : }
15511 : :
15512 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS foreground elements
15513 : : and NPATTERNS background elements, and that its elements match
15514 : : EXPECTED. */
15515 : :
15516 : : static void
15517 : 8 : check_vector_cst_fill (const vec<tree> &expected, tree actual,
15518 : : unsigned int npatterns)
15519 : : {
15520 : 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15521 : 8 : ASSERT_EQ (2, VECTOR_CST_NELTS_PER_PATTERN (actual));
15522 : 8 : ASSERT_EQ (2 * npatterns, vector_cst_encoded_nelts (actual));
15523 : 8 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
15524 : 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
15525 : 8 : check_vector_cst (expected, actual);
15526 : 8 : }
15527 : :
15528 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS stepped patterns,
15529 : : and that its elements match EXPECTED. */
15530 : :
15531 : : static void
15532 : 24 : check_vector_cst_stepped (const vec<tree> &expected, tree actual,
15533 : : unsigned int npatterns)
15534 : : {
15535 : 24 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15536 : 24 : ASSERT_EQ (3, VECTOR_CST_NELTS_PER_PATTERN (actual));
15537 : 24 : ASSERT_EQ (3 * npatterns, vector_cst_encoded_nelts (actual));
15538 : 24 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
15539 : 24 : ASSERT_TRUE (VECTOR_CST_STEPPED_P (actual));
15540 : 24 : check_vector_cst (expected, actual);
15541 : 24 : }
15542 : :
15543 : : /* Test the creation of VECTOR_CSTs. */
15544 : :
15545 : : static void
15546 : 4 : test_vector_cst_patterns (ALONE_CXX_MEM_STAT_INFO)
15547 : : {
15548 : 4 : auto_vec<tree, 8> elements (8);
15549 : 4 : elements.quick_grow (8);
15550 : 4 : tree element_type = build_nonstandard_integer_type (16, true);
15551 : 4 : tree vector_type = build_vector_type (element_type, 8);
15552 : :
15553 : : /* Test a simple linear series with a base of 0 and a step of 1:
15554 : : { 0, 1, 2, 3, 4, 5, 6, 7 }. */
15555 : 36 : for (unsigned int i = 0; i < 8; ++i)
15556 : 32 : elements[i] = build_int_cst (element_type, i);
15557 : 4 : tree vector = build_vector (vector_type, elements PASS_MEM_STAT);
15558 : 4 : check_vector_cst_stepped (elements, vector, 1);
15559 : :
15560 : : /* Try the same with the first element replaced by 100:
15561 : : { 100, 1, 2, 3, 4, 5, 6, 7 }. */
15562 : 4 : elements[0] = build_int_cst (element_type, 100);
15563 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15564 : 4 : check_vector_cst_stepped (elements, vector, 1);
15565 : :
15566 : : /* Try a series that wraps around.
15567 : : { 100, 65531, 65532, 65533, 65534, 65535, 0, 1 }. */
15568 : 32 : for (unsigned int i = 1; i < 8; ++i)
15569 : 28 : elements[i] = build_int_cst (element_type, (65530 + i) & 0xffff);
15570 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15571 : 4 : check_vector_cst_stepped (elements, vector, 1);
15572 : :
15573 : : /* Try a downward series:
15574 : : { 100, 79, 78, 77, 76, 75, 75, 73 }. */
15575 : 32 : for (unsigned int i = 1; i < 8; ++i)
15576 : 28 : elements[i] = build_int_cst (element_type, 80 - i);
15577 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15578 : 4 : check_vector_cst_stepped (elements, vector, 1);
15579 : :
15580 : : /* Try two interleaved series with different bases and steps:
15581 : : { 100, 53, 66, 206, 62, 212, 58, 218 }. */
15582 : 4 : elements[1] = build_int_cst (element_type, 53);
15583 : 16 : for (unsigned int i = 2; i < 8; i += 2)
15584 : : {
15585 : 12 : elements[i] = build_int_cst (element_type, 70 - i * 2);
15586 : 12 : elements[i + 1] = build_int_cst (element_type, 200 + i * 3);
15587 : : }
15588 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15589 : 4 : check_vector_cst_stepped (elements, vector, 2);
15590 : :
15591 : : /* Try a duplicated value:
15592 : : { 100, 100, 100, 100, 100, 100, 100, 100 }. */
15593 : 32 : for (unsigned int i = 1; i < 8; ++i)
15594 : 28 : elements[i] = elements[0];
15595 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15596 : 4 : check_vector_cst_duplicate (elements, vector, 1);
15597 : :
15598 : : /* Try an interleaved duplicated value:
15599 : : { 100, 55, 100, 55, 100, 55, 100, 55 }. */
15600 : 4 : elements[1] = build_int_cst (element_type, 55);
15601 : 28 : for (unsigned int i = 2; i < 8; ++i)
15602 : 24 : elements[i] = elements[i - 2];
15603 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15604 : 4 : check_vector_cst_duplicate (elements, vector, 2);
15605 : :
15606 : : /* Try a duplicated value with 2 exceptions
15607 : : { 41, 97, 100, 55, 100, 55, 100, 55 }. */
15608 : 4 : elements[0] = build_int_cst (element_type, 41);
15609 : 4 : elements[1] = build_int_cst (element_type, 97);
15610 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15611 : 4 : check_vector_cst_fill (elements, vector, 2);
15612 : :
15613 : : /* Try with and without a step
15614 : : { 41, 97, 100, 21, 100, 35, 100, 49 }. */
15615 : 16 : for (unsigned int i = 3; i < 8; i += 2)
15616 : 12 : elements[i] = build_int_cst (element_type, i * 7);
15617 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15618 : 4 : check_vector_cst_stepped (elements, vector, 2);
15619 : :
15620 : : /* Try a fully-general constant:
15621 : : { 41, 97, 100, 21, 100, 9990, 100, 49 }. */
15622 : 4 : elements[5] = build_int_cst (element_type, 9990);
15623 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15624 : 4 : check_vector_cst_fill (elements, vector, 4);
15625 : 4 : }
15626 : :
15627 : : /* Verify that STRIP_NOPS (NODE) is EXPECTED.
15628 : : Helper function for test_location_wrappers, to deal with STRIP_NOPS
15629 : : modifying its argument in-place. */
15630 : :
15631 : : static void
15632 : 12 : check_strip_nops (tree node, tree expected)
15633 : : {
15634 : 12 : STRIP_NOPS (node);
15635 : 12 : ASSERT_EQ (expected, node);
15636 : 12 : }
15637 : :
15638 : : /* Verify location wrappers. */
15639 : :
15640 : : static void
15641 : 4 : test_location_wrappers ()
15642 : : {
15643 : 4 : location_t loc = BUILTINS_LOCATION;
15644 : :
15645 : 4 : ASSERT_EQ (NULL_TREE, maybe_wrap_with_location (NULL_TREE, loc));
15646 : :
15647 : : /* Wrapping a constant. */
15648 : 4 : tree int_cst = build_int_cst (integer_type_node, 42);
15649 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_cst));
15650 : 4 : ASSERT_FALSE (location_wrapper_p (int_cst));
15651 : :
15652 : 4 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
15653 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
15654 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_cst));
15655 : 4 : ASSERT_EQ (int_cst, tree_strip_any_location_wrapper (wrapped_int_cst));
15656 : :
15657 : : /* We shouldn't add wrapper nodes for UNKNOWN_LOCATION. */
15658 : 4 : ASSERT_EQ (int_cst, maybe_wrap_with_location (int_cst, UNKNOWN_LOCATION));
15659 : :
15660 : : /* We shouldn't add wrapper nodes for nodes that CAN_HAVE_LOCATION_P. */
15661 : 4 : tree cast = build1 (NOP_EXPR, char_type_node, int_cst);
15662 : 4 : ASSERT_TRUE (CAN_HAVE_LOCATION_P (cast));
15663 : 4 : ASSERT_EQ (cast, maybe_wrap_with_location (cast, loc));
15664 : :
15665 : : /* Wrapping a STRING_CST. */
15666 : 4 : tree string_cst = build_string (4, "foo");
15667 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (string_cst));
15668 : 4 : ASSERT_FALSE (location_wrapper_p (string_cst));
15669 : :
15670 : 4 : tree wrapped_string_cst = maybe_wrap_with_location (string_cst, loc);
15671 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_string_cst));
15672 : 4 : ASSERT_EQ (VIEW_CONVERT_EXPR, TREE_CODE (wrapped_string_cst));
15673 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_string_cst));
15674 : 4 : ASSERT_EQ (string_cst, tree_strip_any_location_wrapper (wrapped_string_cst));
15675 : :
15676 : :
15677 : : /* Wrapping a variable. */
15678 : 4 : tree int_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
15679 : : get_identifier ("some_int_var"),
15680 : : integer_type_node);
15681 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_var));
15682 : 4 : ASSERT_FALSE (location_wrapper_p (int_var));
15683 : :
15684 : 4 : tree wrapped_int_var = maybe_wrap_with_location (int_var, loc);
15685 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_var));
15686 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_var));
15687 : 4 : ASSERT_EQ (int_var, tree_strip_any_location_wrapper (wrapped_int_var));
15688 : :
15689 : : /* Verify that "reinterpret_cast<int>(some_int_var)" is not a location
15690 : : wrapper. */
15691 : 4 : tree r_cast = build1 (NON_LVALUE_EXPR, integer_type_node, int_var);
15692 : 4 : ASSERT_FALSE (location_wrapper_p (r_cast));
15693 : 4 : ASSERT_EQ (r_cast, tree_strip_any_location_wrapper (r_cast));
15694 : :
15695 : : /* Verify that STRIP_NOPS removes wrappers. */
15696 : 4 : check_strip_nops (wrapped_int_cst, int_cst);
15697 : 4 : check_strip_nops (wrapped_string_cst, string_cst);
15698 : 4 : check_strip_nops (wrapped_int_var, int_var);
15699 : 4 : }
15700 : :
15701 : : /* Test various tree predicates. Verify that location wrappers don't
15702 : : affect the results. */
15703 : :
15704 : : static void
15705 : 4 : test_predicates ()
15706 : : {
15707 : : /* Build various constants and wrappers around them. */
15708 : :
15709 : 4 : location_t loc = BUILTINS_LOCATION;
15710 : :
15711 : 4 : tree i_0 = build_int_cst (integer_type_node, 0);
15712 : 4 : tree wr_i_0 = maybe_wrap_with_location (i_0, loc);
15713 : :
15714 : 4 : tree i_1 = build_int_cst (integer_type_node, 1);
15715 : 4 : tree wr_i_1 = maybe_wrap_with_location (i_1, loc);
15716 : :
15717 : 4 : tree i_m1 = build_int_cst (integer_type_node, -1);
15718 : 4 : tree wr_i_m1 = maybe_wrap_with_location (i_m1, loc);
15719 : :
15720 : 4 : tree f_0 = build_real_from_int_cst (float_type_node, i_0);
15721 : 4 : tree wr_f_0 = maybe_wrap_with_location (f_0, loc);
15722 : 4 : tree f_1 = build_real_from_int_cst (float_type_node, i_1);
15723 : 4 : tree wr_f_1 = maybe_wrap_with_location (f_1, loc);
15724 : 4 : tree f_m1 = build_real_from_int_cst (float_type_node, i_m1);
15725 : 4 : tree wr_f_m1 = maybe_wrap_with_location (f_m1, loc);
15726 : :
15727 : 4 : tree c_i_0 = build_complex (NULL_TREE, i_0, i_0);
15728 : 4 : tree c_i_1 = build_complex (NULL_TREE, i_1, i_0);
15729 : 4 : tree c_i_m1 = build_complex (NULL_TREE, i_m1, i_0);
15730 : :
15731 : 4 : tree c_f_0 = build_complex (NULL_TREE, f_0, f_0);
15732 : 4 : tree c_f_1 = build_complex (NULL_TREE, f_1, f_0);
15733 : 4 : tree c_f_m1 = build_complex (NULL_TREE, f_m1, f_0);
15734 : :
15735 : : /* TODO: vector constants. */
15736 : :
15737 : : /* Test integer_onep. */
15738 : 4 : ASSERT_FALSE (integer_onep (i_0));
15739 : 4 : ASSERT_FALSE (integer_onep (wr_i_0));
15740 : 4 : ASSERT_TRUE (integer_onep (i_1));
15741 : 4 : ASSERT_TRUE (integer_onep (wr_i_1));
15742 : 4 : ASSERT_FALSE (integer_onep (i_m1));
15743 : 4 : ASSERT_FALSE (integer_onep (wr_i_m1));
15744 : 4 : ASSERT_FALSE (integer_onep (f_0));
15745 : 4 : ASSERT_FALSE (integer_onep (wr_f_0));
15746 : 4 : ASSERT_FALSE (integer_onep (f_1));
15747 : 4 : ASSERT_FALSE (integer_onep (wr_f_1));
15748 : 4 : ASSERT_FALSE (integer_onep (f_m1));
15749 : 4 : ASSERT_FALSE (integer_onep (wr_f_m1));
15750 : 4 : ASSERT_FALSE (integer_onep (c_i_0));
15751 : 4 : ASSERT_TRUE (integer_onep (c_i_1));
15752 : 4 : ASSERT_FALSE (integer_onep (c_i_m1));
15753 : 4 : ASSERT_FALSE (integer_onep (c_f_0));
15754 : 4 : ASSERT_FALSE (integer_onep (c_f_1));
15755 : 4 : ASSERT_FALSE (integer_onep (c_f_m1));
15756 : :
15757 : : /* Test integer_zerop. */
15758 : 4 : ASSERT_TRUE (integer_zerop (i_0));
15759 : 4 : ASSERT_TRUE (integer_zerop (wr_i_0));
15760 : 4 : ASSERT_FALSE (integer_zerop (i_1));
15761 : 4 : ASSERT_FALSE (integer_zerop (wr_i_1));
15762 : 4 : ASSERT_FALSE (integer_zerop (i_m1));
15763 : 4 : ASSERT_FALSE (integer_zerop (wr_i_m1));
15764 : 4 : ASSERT_FALSE (integer_zerop (f_0));
15765 : 4 : ASSERT_FALSE (integer_zerop (wr_f_0));
15766 : 4 : ASSERT_FALSE (integer_zerop (f_1));
15767 : 4 : ASSERT_FALSE (integer_zerop (wr_f_1));
15768 : 4 : ASSERT_FALSE (integer_zerop (f_m1));
15769 : 4 : ASSERT_FALSE (integer_zerop (wr_f_m1));
15770 : 4 : ASSERT_TRUE (integer_zerop (c_i_0));
15771 : 4 : ASSERT_FALSE (integer_zerop (c_i_1));
15772 : 4 : ASSERT_FALSE (integer_zerop (c_i_m1));
15773 : 4 : ASSERT_FALSE (integer_zerop (c_f_0));
15774 : 4 : ASSERT_FALSE (integer_zerop (c_f_1));
15775 : 4 : ASSERT_FALSE (integer_zerop (c_f_m1));
15776 : :
15777 : : /* Test integer_all_onesp. */
15778 : 4 : ASSERT_FALSE (integer_all_onesp (i_0));
15779 : 4 : ASSERT_FALSE (integer_all_onesp (wr_i_0));
15780 : 4 : ASSERT_FALSE (integer_all_onesp (i_1));
15781 : 4 : ASSERT_FALSE (integer_all_onesp (wr_i_1));
15782 : 4 : ASSERT_TRUE (integer_all_onesp (i_m1));
15783 : 4 : ASSERT_TRUE (integer_all_onesp (wr_i_m1));
15784 : 4 : ASSERT_FALSE (integer_all_onesp (f_0));
15785 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_0));
15786 : 4 : ASSERT_FALSE (integer_all_onesp (f_1));
15787 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_1));
15788 : 4 : ASSERT_FALSE (integer_all_onesp (f_m1));
15789 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_m1));
15790 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_0));
15791 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_1));
15792 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_m1));
15793 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_0));
15794 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_1));
15795 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_m1));
15796 : :
15797 : : /* Test integer_minus_onep. */
15798 : 4 : ASSERT_FALSE (integer_minus_onep (i_0));
15799 : 4 : ASSERT_FALSE (integer_minus_onep (wr_i_0));
15800 : 4 : ASSERT_FALSE (integer_minus_onep (i_1));
15801 : 4 : ASSERT_FALSE (integer_minus_onep (wr_i_1));
15802 : 4 : ASSERT_TRUE (integer_minus_onep (i_m1));
15803 : 4 : ASSERT_TRUE (integer_minus_onep (wr_i_m1));
15804 : 4 : ASSERT_FALSE (integer_minus_onep (f_0));
15805 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_0));
15806 : 4 : ASSERT_FALSE (integer_minus_onep (f_1));
15807 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_1));
15808 : 4 : ASSERT_FALSE (integer_minus_onep (f_m1));
15809 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_m1));
15810 : 4 : ASSERT_FALSE (integer_minus_onep (c_i_0));
15811 : 4 : ASSERT_FALSE (integer_minus_onep (c_i_1));
15812 : 4 : ASSERT_TRUE (integer_minus_onep (c_i_m1));
15813 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_0));
15814 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_1));
15815 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_m1));
15816 : :
15817 : : /* Test integer_each_onep. */
15818 : 4 : ASSERT_FALSE (integer_each_onep (i_0));
15819 : 4 : ASSERT_FALSE (integer_each_onep (wr_i_0));
15820 : 4 : ASSERT_TRUE (integer_each_onep (i_1));
15821 : 4 : ASSERT_TRUE (integer_each_onep (wr_i_1));
15822 : 4 : ASSERT_FALSE (integer_each_onep (i_m1));
15823 : 4 : ASSERT_FALSE (integer_each_onep (wr_i_m1));
15824 : 4 : ASSERT_FALSE (integer_each_onep (f_0));
15825 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_0));
15826 : 4 : ASSERT_FALSE (integer_each_onep (f_1));
15827 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_1));
15828 : 4 : ASSERT_FALSE (integer_each_onep (f_m1));
15829 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_m1));
15830 : 4 : ASSERT_FALSE (integer_each_onep (c_i_0));
15831 : 4 : ASSERT_FALSE (integer_each_onep (c_i_1));
15832 : 4 : ASSERT_FALSE (integer_each_onep (c_i_m1));
15833 : 4 : ASSERT_FALSE (integer_each_onep (c_f_0));
15834 : 4 : ASSERT_FALSE (integer_each_onep (c_f_1));
15835 : 4 : ASSERT_FALSE (integer_each_onep (c_f_m1));
15836 : :
15837 : : /* Test integer_truep. */
15838 : 4 : ASSERT_FALSE (integer_truep (i_0));
15839 : 4 : ASSERT_FALSE (integer_truep (wr_i_0));
15840 : 4 : ASSERT_TRUE (integer_truep (i_1));
15841 : 4 : ASSERT_TRUE (integer_truep (wr_i_1));
15842 : 4 : ASSERT_FALSE (integer_truep (i_m1));
15843 : 4 : ASSERT_FALSE (integer_truep (wr_i_m1));
15844 : 4 : ASSERT_FALSE (integer_truep (f_0));
15845 : 4 : ASSERT_FALSE (integer_truep (wr_f_0));
15846 : 4 : ASSERT_FALSE (integer_truep (f_1));
15847 : 4 : ASSERT_FALSE (integer_truep (wr_f_1));
15848 : 4 : ASSERT_FALSE (integer_truep (f_m1));
15849 : 4 : ASSERT_FALSE (integer_truep (wr_f_m1));
15850 : 4 : ASSERT_FALSE (integer_truep (c_i_0));
15851 : 4 : ASSERT_TRUE (integer_truep (c_i_1));
15852 : 4 : ASSERT_FALSE (integer_truep (c_i_m1));
15853 : 4 : ASSERT_FALSE (integer_truep (c_f_0));
15854 : 4 : ASSERT_FALSE (integer_truep (c_f_1));
15855 : 4 : ASSERT_FALSE (integer_truep (c_f_m1));
15856 : :
15857 : : /* Test integer_nonzerop. */
15858 : 4 : ASSERT_FALSE (integer_nonzerop (i_0));
15859 : 4 : ASSERT_FALSE (integer_nonzerop (wr_i_0));
15860 : 4 : ASSERT_TRUE (integer_nonzerop (i_1));
15861 : 4 : ASSERT_TRUE (integer_nonzerop (wr_i_1));
15862 : 4 : ASSERT_TRUE (integer_nonzerop (i_m1));
15863 : 4 : ASSERT_TRUE (integer_nonzerop (wr_i_m1));
15864 : 4 : ASSERT_FALSE (integer_nonzerop (f_0));
15865 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_0));
15866 : 4 : ASSERT_FALSE (integer_nonzerop (f_1));
15867 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_1));
15868 : 4 : ASSERT_FALSE (integer_nonzerop (f_m1));
15869 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_m1));
15870 : 4 : ASSERT_FALSE (integer_nonzerop (c_i_0));
15871 : 4 : ASSERT_TRUE (integer_nonzerop (c_i_1));
15872 : 4 : ASSERT_TRUE (integer_nonzerop (c_i_m1));
15873 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_0));
15874 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_1));
15875 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_m1));
15876 : :
15877 : : /* Test real_zerop. */
15878 : 4 : ASSERT_FALSE (real_zerop (i_0));
15879 : 4 : ASSERT_FALSE (real_zerop (wr_i_0));
15880 : 4 : ASSERT_FALSE (real_zerop (i_1));
15881 : 4 : ASSERT_FALSE (real_zerop (wr_i_1));
15882 : 4 : ASSERT_FALSE (real_zerop (i_m1));
15883 : 4 : ASSERT_FALSE (real_zerop (wr_i_m1));
15884 : 4 : ASSERT_TRUE (real_zerop (f_0));
15885 : 4 : ASSERT_TRUE (real_zerop (wr_f_0));
15886 : 4 : ASSERT_FALSE (real_zerop (f_1));
15887 : 4 : ASSERT_FALSE (real_zerop (wr_f_1));
15888 : 4 : ASSERT_FALSE (real_zerop (f_m1));
15889 : 4 : ASSERT_FALSE (real_zerop (wr_f_m1));
15890 : 4 : ASSERT_FALSE (real_zerop (c_i_0));
15891 : 4 : ASSERT_FALSE (real_zerop (c_i_1));
15892 : 4 : ASSERT_FALSE (real_zerop (c_i_m1));
15893 : 4 : ASSERT_TRUE (real_zerop (c_f_0));
15894 : 4 : ASSERT_FALSE (real_zerop (c_f_1));
15895 : 4 : ASSERT_FALSE (real_zerop (c_f_m1));
15896 : :
15897 : : /* Test real_onep. */
15898 : 4 : ASSERT_FALSE (real_onep (i_0));
15899 : 4 : ASSERT_FALSE (real_onep (wr_i_0));
15900 : 4 : ASSERT_FALSE (real_onep (i_1));
15901 : 4 : ASSERT_FALSE (real_onep (wr_i_1));
15902 : 4 : ASSERT_FALSE (real_onep (i_m1));
15903 : 4 : ASSERT_FALSE (real_onep (wr_i_m1));
15904 : 4 : ASSERT_FALSE (real_onep (f_0));
15905 : 4 : ASSERT_FALSE (real_onep (wr_f_0));
15906 : 4 : ASSERT_TRUE (real_onep (f_1));
15907 : 4 : ASSERT_TRUE (real_onep (wr_f_1));
15908 : 4 : ASSERT_FALSE (real_onep (f_m1));
15909 : 4 : ASSERT_FALSE (real_onep (wr_f_m1));
15910 : 4 : ASSERT_FALSE (real_onep (c_i_0));
15911 : 4 : ASSERT_FALSE (real_onep (c_i_1));
15912 : 4 : ASSERT_FALSE (real_onep (c_i_m1));
15913 : 4 : ASSERT_FALSE (real_onep (c_f_0));
15914 : 4 : ASSERT_TRUE (real_onep (c_f_1));
15915 : 4 : ASSERT_FALSE (real_onep (c_f_m1));
15916 : :
15917 : : /* Test real_minus_onep. */
15918 : 4 : ASSERT_FALSE (real_minus_onep (i_0));
15919 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_0));
15920 : 4 : ASSERT_FALSE (real_minus_onep (i_1));
15921 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_1));
15922 : 4 : ASSERT_FALSE (real_minus_onep (i_m1));
15923 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_m1));
15924 : 4 : ASSERT_FALSE (real_minus_onep (f_0));
15925 : 4 : ASSERT_FALSE (real_minus_onep (wr_f_0));
15926 : 4 : ASSERT_FALSE (real_minus_onep (f_1));
15927 : 4 : ASSERT_FALSE (real_minus_onep (wr_f_1));
15928 : 4 : ASSERT_TRUE (real_minus_onep (f_m1));
15929 : 4 : ASSERT_TRUE (real_minus_onep (wr_f_m1));
15930 : 4 : ASSERT_FALSE (real_minus_onep (c_i_0));
15931 : 4 : ASSERT_FALSE (real_minus_onep (c_i_1));
15932 : 4 : ASSERT_FALSE (real_minus_onep (c_i_m1));
15933 : 4 : ASSERT_FALSE (real_minus_onep (c_f_0));
15934 : 4 : ASSERT_FALSE (real_minus_onep (c_f_1));
15935 : 4 : ASSERT_TRUE (real_minus_onep (c_f_m1));
15936 : :
15937 : : /* Test zerop. */
15938 : 4 : ASSERT_TRUE (zerop (i_0));
15939 : 4 : ASSERT_TRUE (zerop (wr_i_0));
15940 : 4 : ASSERT_FALSE (zerop (i_1));
15941 : 4 : ASSERT_FALSE (zerop (wr_i_1));
15942 : 4 : ASSERT_FALSE (zerop (i_m1));
15943 : 4 : ASSERT_FALSE (zerop (wr_i_m1));
15944 : 4 : ASSERT_TRUE (zerop (f_0));
15945 : 4 : ASSERT_TRUE (zerop (wr_f_0));
15946 : 4 : ASSERT_FALSE (zerop (f_1));
15947 : 4 : ASSERT_FALSE (zerop (wr_f_1));
15948 : 4 : ASSERT_FALSE (zerop (f_m1));
15949 : 4 : ASSERT_FALSE (zerop (wr_f_m1));
15950 : 4 : ASSERT_TRUE (zerop (c_i_0));
15951 : 4 : ASSERT_FALSE (zerop (c_i_1));
15952 : 4 : ASSERT_FALSE (zerop (c_i_m1));
15953 : 4 : ASSERT_TRUE (zerop (c_f_0));
15954 : 4 : ASSERT_FALSE (zerop (c_f_1));
15955 : 4 : ASSERT_FALSE (zerop (c_f_m1));
15956 : :
15957 : : /* Test tree_expr_nonnegative_p. */
15958 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_0));
15959 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_0));
15960 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_1));
15961 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_1));
15962 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (i_m1));
15963 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_i_m1));
15964 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_0));
15965 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_0));
15966 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_1));
15967 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_1));
15968 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (f_m1));
15969 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_f_m1));
15970 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_0));
15971 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_1));
15972 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_m1));
15973 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_0));
15974 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_1));
15975 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_m1));
15976 : :
15977 : : /* Test tree_expr_nonzero_p. */
15978 : 4 : ASSERT_FALSE (tree_expr_nonzero_p (i_0));
15979 : 4 : ASSERT_FALSE (tree_expr_nonzero_p (wr_i_0));
15980 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_1));
15981 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_1));
15982 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_m1));
15983 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_m1));
15984 : :
15985 : : /* Test integer_valued_real_p. */
15986 : 4 : ASSERT_FALSE (integer_valued_real_p (i_0));
15987 : 4 : ASSERT_TRUE (integer_valued_real_p (f_0));
15988 : 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_0));
15989 : 4 : ASSERT_TRUE (integer_valued_real_p (f_1));
15990 : 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_1));
15991 : :
15992 : : /* Test integer_pow2p. */
15993 : 4 : ASSERT_FALSE (integer_pow2p (i_0));
15994 : 4 : ASSERT_TRUE (integer_pow2p (i_1));
15995 : 4 : ASSERT_TRUE (integer_pow2p (wr_i_1));
15996 : :
15997 : : /* Test uniform_integer_cst_p. */
15998 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_0));
15999 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_0));
16000 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_1));
16001 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_1));
16002 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_m1));
16003 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_m1));
16004 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_0));
16005 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_0));
16006 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_1));
16007 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_1));
16008 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_m1));
16009 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_m1));
16010 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_0));
16011 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_1));
16012 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_m1));
16013 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_0));
16014 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_1));
16015 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_m1));
16016 : 4 : }
16017 : :
16018 : : /* Check that string escaping works correctly. */
16019 : :
16020 : : static void
16021 : 4 : test_escaped_strings (void)
16022 : : {
16023 : 4 : int saved_cutoff;
16024 : 4 : escaped_string msg;
16025 : :
16026 : 4 : msg.escape (NULL);
16027 : : /* ASSERT_STREQ does not accept NULL as a valid test
16028 : : result, so we have to use ASSERT_EQ instead. */
16029 : 4 : ASSERT_EQ (NULL, (const char *) msg);
16030 : :
16031 : 4 : msg.escape ("");
16032 : 4 : ASSERT_STREQ ("", (const char *) msg);
16033 : :
16034 : 4 : msg.escape ("foobar");
16035 : 4 : ASSERT_STREQ ("foobar", (const char *) msg);
16036 : :
16037 : : /* Ensure that we have -fmessage-length set to 0. */
16038 : 4 : pretty_printer *pp = global_dc->get_reference_printer ();
16039 : 4 : saved_cutoff = pp_line_cutoff (pp);
16040 : 4 : pp_line_cutoff (pp) = 0;
16041 : :
16042 : 4 : msg.escape ("foo\nbar");
16043 : 4 : ASSERT_STREQ ("foo\\nbar", (const char *) msg);
16044 : :
16045 : 4 : msg.escape ("\a\b\f\n\r\t\v");
16046 : 4 : ASSERT_STREQ ("\\a\\b\\f\\n\\r\\t\\v", (const char *) msg);
16047 : :
16048 : : /* Now repeat the tests with -fmessage-length set to 5. */
16049 : 4 : pp_line_cutoff (pp) = 5;
16050 : :
16051 : : /* Note that the newline is not translated into an escape. */
16052 : 4 : msg.escape ("foo\nbar");
16053 : 4 : ASSERT_STREQ ("foo\nbar", (const char *) msg);
16054 : :
16055 : 4 : msg.escape ("\a\b\f\n\r\t\v");
16056 : 4 : ASSERT_STREQ ("\\a\\b\\f\n\\r\\t\\v", (const char *) msg);
16057 : :
16058 : : /* Restore the original message length setting. */
16059 : 4 : pp_line_cutoff (pp) = saved_cutoff;
16060 : 4 : }
16061 : :
16062 : : /* Run all of the selftests within this file. */
16063 : :
16064 : : void
16065 : 4 : tree_cc_tests ()
16066 : : {
16067 : 4 : test_integer_constants ();
16068 : 4 : test_identifiers ();
16069 : 4 : test_labels ();
16070 : 4 : test_vector_cst_patterns ();
16071 : 4 : test_location_wrappers ();
16072 : 4 : test_predicates ();
16073 : 4 : test_escaped_strings ();
16074 : 4 : }
16075 : :
16076 : : } // namespace selftest
16077 : :
16078 : : #endif /* CHECKING_P */
16079 : :
16080 : : #include "gt-tree.h"
|