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 : 7106416654 : 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 : 1666839878 : keep_cache_entry (type_hash *&t)
162 : : {
163 : 1666839878 : 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 : 699144 : 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 : 13021286 : gt_value_expr_mark_2 (tree *tp, int *, void *data)
225 : : {
226 : 13021286 : tree t = *tp;
227 : 13021286 : if (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t) && !ggc_marked_p (t))
228 : : {
229 : 1025 : tree dve = DECL_VALUE_EXPR (t);
230 : 1025 : gt_value_expr_mark_data *d = (gt_value_expr_mark_data *) data;
231 : 1025 : walk_tree_1 (&dve, gt_value_expr_mark_2, data, &d->pset, NULL);
232 : 1025 : d->to_mark.safe_push (t);
233 : : }
234 : 13021286 : return NULL_TREE;
235 : : }
236 : :
237 : : /* Callback called through traverse_noresize on the
238 : : value_expr_for_decl hash table. */
239 : :
240 : : int
241 : 4966851 : gt_value_expr_mark_1 (tree_decl_map **e, gt_value_expr_mark_data *data)
242 : : {
243 : 4966851 : if (ggc_marked_p ((*e)->base.from))
244 : 4674583 : walk_tree_1 (&(*e)->to, gt_value_expr_mark_2, data, &data->pset, NULL);
245 : 4966851 : 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 : 699144 : gt_value_expr_mark (hash_table<tree_decl_map_cache_hasher> *h)
260 : : {
261 : 699144 : if (!h)
262 : 0 : return;
263 : :
264 : 699144 : gt_value_expr_mark_data data;
265 : 699144 : h->traverse_noresize<gt_value_expr_mark_data *,
266 : 5665995 : gt_value_expr_mark_1> (&data);
267 : 2098457 : for (auto v : data.to_mark)
268 : 1025 : gt_ggc_mx (v);
269 : 699144 : }
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 : : 3, /* OMP_CLAUSE__MAPPER_BINDING_ */
330 : : 2, /* OMP_CLAUSE__CACHE_ */
331 : : 1, /* OMP_CLAUSE_DESTROY */
332 : : 2, /* OMP_CLAUSE_INIT */
333 : : 1, /* OMP_CLAUSE_USE */
334 : : 1, /* OMP_CLAUSE_INTEROP */
335 : : 2, /* OMP_CLAUSE_GANG */
336 : : 1, /* OMP_CLAUSE_ASYNC */
337 : : 1, /* OMP_CLAUSE_WAIT */
338 : : 0, /* OMP_CLAUSE_AUTO */
339 : : 0, /* OMP_CLAUSE_SEQ */
340 : : 1, /* OMP_CLAUSE__LOOPTEMP_ */
341 : : 1, /* OMP_CLAUSE__REDUCTEMP_ */
342 : : 1, /* OMP_CLAUSE__CONDTEMP_ */
343 : : 1, /* OMP_CLAUSE__SCANTEMP_ */
344 : : 1, /* OMP_CLAUSE_IF */
345 : : 1, /* OMP_CLAUSE_SELF */
346 : : 1, /* OMP_CLAUSE_NUM_THREADS */
347 : : 1, /* OMP_CLAUSE_SCHEDULE */
348 : : 0, /* OMP_CLAUSE_NOWAIT */
349 : : 1, /* OMP_CLAUSE_ORDERED */
350 : : 0, /* OMP_CLAUSE_DEFAULT */
351 : : 3, /* OMP_CLAUSE_COLLAPSE */
352 : : 0, /* OMP_CLAUSE_UNTIED */
353 : : 1, /* OMP_CLAUSE_FINAL */
354 : : 0, /* OMP_CLAUSE_MERGEABLE */
355 : : 1, /* OMP_CLAUSE_DEVICE */
356 : : 1, /* OMP_CLAUSE_DIST_SCHEDULE */
357 : : 0, /* OMP_CLAUSE_INBRANCH */
358 : : 0, /* OMP_CLAUSE_NOTINBRANCH */
359 : : 2, /* OMP_CLAUSE_NUM_TEAMS */
360 : : 1, /* OMP_CLAUSE_THREAD_LIMIT */
361 : : 0, /* OMP_CLAUSE_PROC_BIND */
362 : : 1, /* OMP_CLAUSE_SAFELEN */
363 : : 1, /* OMP_CLAUSE_SIMDLEN */
364 : : 0, /* OMP_CLAUSE_DEVICE_TYPE */
365 : : 0, /* OMP_CLAUSE_FOR */
366 : : 0, /* OMP_CLAUSE_PARALLEL */
367 : : 0, /* OMP_CLAUSE_SECTIONS */
368 : : 0, /* OMP_CLAUSE_TASKGROUP */
369 : : 1, /* OMP_CLAUSE_PRIORITY */
370 : : 1, /* OMP_CLAUSE_GRAINSIZE */
371 : : 1, /* OMP_CLAUSE_NUM_TASKS */
372 : : 0, /* OMP_CLAUSE_NOGROUP */
373 : : 0, /* OMP_CLAUSE_THREADS */
374 : : 0, /* OMP_CLAUSE_SIMD */
375 : : 1, /* OMP_CLAUSE_HINT */
376 : : 0, /* OMP_CLAUSE_DEFAULTMAP */
377 : : 0, /* OMP_CLAUSE_ORDER */
378 : : 0, /* OMP_CLAUSE_BIND */
379 : : 1, /* OMP_CLAUSE_FILTER */
380 : : 1, /* OMP_CLAUSE_INDIRECT */
381 : : 1, /* OMP_CLAUSE_PARTIAL */
382 : : 0, /* OMP_CLAUSE_FULL */
383 : : 1, /* OMP_CLAUSE_SIZES */
384 : : 1, /* OMP_CLAUSE__SIMDUID_ */
385 : : 0, /* OMP_CLAUSE__SIMT_ */
386 : : 0, /* OMP_CLAUSE_INDEPENDENT */
387 : : 1, /* OMP_CLAUSE_WORKER */
388 : : 1, /* OMP_CLAUSE_VECTOR */
389 : : 1, /* OMP_CLAUSE_NUM_GANGS */
390 : : 1, /* OMP_CLAUSE_NUM_WORKERS */
391 : : 1, /* OMP_CLAUSE_VECTOR_LENGTH */
392 : : 3, /* OMP_CLAUSE_TILE */
393 : : 0, /* OMP_CLAUSE_IF_PRESENT */
394 : : 0, /* OMP_CLAUSE_FINALIZE */
395 : : 0, /* OMP_CLAUSE_NOHOST */
396 : : 1, /* OMP_CLAUSE_NOVARIANTS */
397 : : 1, /* OMP_CLAUSE_NOCONTEXT */
398 : : };
399 : :
400 : : const char * const omp_clause_code_name[] =
401 : : {
402 : : "error_clause",
403 : : "private",
404 : : "shared",
405 : : "firstprivate",
406 : : "lastprivate",
407 : : "reduction",
408 : : "task_reduction",
409 : : "in_reduction",
410 : : "copyin",
411 : : "copyprivate",
412 : : "linear",
413 : : "affinity",
414 : : "aligned",
415 : : "allocate",
416 : : "depend",
417 : : "nontemporal",
418 : : "uniform",
419 : : "enter",
420 : : "link",
421 : : "detach",
422 : : "use_device_ptr",
423 : : "use_device_addr",
424 : : "is_device_ptr",
425 : : "inclusive",
426 : : "exclusive",
427 : : "from",
428 : : "to",
429 : : "map",
430 : : "has_device_addr",
431 : : "doacross",
432 : : "_mapper_binding_",
433 : : "_cache_",
434 : : "destroy",
435 : : "init",
436 : : "use",
437 : : "interop",
438 : : "gang",
439 : : "async",
440 : : "wait",
441 : : "auto",
442 : : "seq",
443 : : "_looptemp_",
444 : : "_reductemp_",
445 : : "_condtemp_",
446 : : "_scantemp_",
447 : : "if",
448 : : "self",
449 : : "num_threads",
450 : : "schedule",
451 : : "nowait",
452 : : "ordered",
453 : : "default",
454 : : "collapse",
455 : : "untied",
456 : : "final",
457 : : "mergeable",
458 : : "device",
459 : : "dist_schedule",
460 : : "inbranch",
461 : : "notinbranch",
462 : : "num_teams",
463 : : "thread_limit",
464 : : "proc_bind",
465 : : "safelen",
466 : : "simdlen",
467 : : "device_type",
468 : : "for",
469 : : "parallel",
470 : : "sections",
471 : : "taskgroup",
472 : : "priority",
473 : : "grainsize",
474 : : "num_tasks",
475 : : "nogroup",
476 : : "threads",
477 : : "simd",
478 : : "hint",
479 : : "defaultmap",
480 : : "order",
481 : : "bind",
482 : : "filter",
483 : : "indirect",
484 : : "partial",
485 : : "full",
486 : : "sizes",
487 : : "_simduid_",
488 : : "_simt_",
489 : : "independent",
490 : : "worker",
491 : : "vector",
492 : : "num_gangs",
493 : : "num_workers",
494 : : "vector_length",
495 : : "tile",
496 : : "if_present",
497 : : "finalize",
498 : : "nohost",
499 : : "novariants",
500 : : "nocontext",
501 : : };
502 : :
503 : : /* Unless specific to OpenACC, we tend to internally maintain OpenMP-centric
504 : : clause names, but for use in diagnostics etc. would like to use the "user"
505 : : clause names. */
506 : :
507 : : const char *
508 : 465 : user_omp_clause_code_name (tree clause, bool oacc)
509 : : {
510 : : /* For OpenACC, the 'OMP_CLAUSE_MAP_KIND' of an 'OMP_CLAUSE_MAP' is used to
511 : : distinguish clauses as seen by the user. See also where front ends do
512 : : 'build_omp_clause' with 'OMP_CLAUSE_MAP'. */
513 : 930 : if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP)
514 : 465 : switch (OMP_CLAUSE_MAP_KIND (clause))
515 : : {
516 : : case GOMP_MAP_FORCE_ALLOC:
517 : : case GOMP_MAP_ALLOC: return "create";
518 : 0 : case GOMP_MAP_FORCE_TO:
519 : 0 : case GOMP_MAP_TO: return "copyin";
520 : 0 : case GOMP_MAP_FORCE_FROM:
521 : 0 : case GOMP_MAP_FROM: return "copyout";
522 : 381 : case GOMP_MAP_FORCE_TOFROM:
523 : 381 : case GOMP_MAP_TOFROM: return "copy";
524 : 0 : case GOMP_MAP_RELEASE: return "delete";
525 : 0 : case GOMP_MAP_FORCE_PRESENT: return "present";
526 : 42 : case GOMP_MAP_ATTACH: return "attach";
527 : 42 : case GOMP_MAP_FORCE_DETACH:
528 : 42 : case GOMP_MAP_DETACH: return "detach";
529 : 0 : case GOMP_MAP_DEVICE_RESIDENT: return "device_resident";
530 : 0 : case GOMP_MAP_LINK: return "link";
531 : 0 : case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr";
532 : : default: break;
533 : : }
534 : :
535 : 0 : return omp_clause_code_name[OMP_CLAUSE_CODE (clause)];
536 : : }
537 : :
538 : :
539 : : /* Return the tree node structure used by tree code CODE. */
540 : :
541 : : static inline enum tree_node_structure_enum
542 : 35420371664 : tree_node_structure_for_code (enum tree_code code)
543 : : {
544 : 35420371664 : switch (TREE_CODE_CLASS (code))
545 : : {
546 : 8868428355 : case tcc_declaration:
547 : 8868428355 : switch (code)
548 : : {
549 : : case CONST_DECL: return TS_CONST_DECL;
550 : : case DEBUG_EXPR_DECL: return TS_DECL_WRTL;
551 : : case FIELD_DECL: return TS_FIELD_DECL;
552 : : case FUNCTION_DECL: return TS_FUNCTION_DECL;
553 : : case LABEL_DECL: return TS_LABEL_DECL;
554 : : case PARM_DECL: return TS_PARM_DECL;
555 : : case RESULT_DECL: return TS_RESULT_DECL;
556 : : case TRANSLATION_UNIT_DECL: return TS_TRANSLATION_UNIT_DECL;
557 : : case TYPE_DECL: return TS_TYPE_DECL;
558 : : case VAR_DECL: return TS_VAR_DECL;
559 : : default: return TS_DECL_NON_COMMON;
560 : : }
561 : :
562 : : case tcc_type: return TS_TYPE_NON_COMMON;
563 : :
564 : 8949353435 : case tcc_binary:
565 : 8949353435 : case tcc_comparison:
566 : 8949353435 : case tcc_expression:
567 : 8949353435 : case tcc_reference:
568 : 8949353435 : case tcc_statement:
569 : 8949353435 : case tcc_unary:
570 : 8949353435 : case tcc_vl_exp: return TS_EXP;
571 : :
572 : 12705984709 : default: /* tcc_constant and tcc_exceptional */
573 : 12705984709 : break;
574 : : }
575 : :
576 : 12705984709 : switch (code)
577 : : {
578 : : /* tcc_constant cases. */
579 : : case COMPLEX_CST: return TS_COMPLEX;
580 : 285081 : case FIXED_CST: return TS_FIXED_CST;
581 : 414780613 : case INTEGER_CST: return TS_INT_CST;
582 : 285081 : case POLY_INT_CST: return TS_POLY_INT_CST;
583 : 38788914 : case REAL_CST: return TS_REAL_CST;
584 : 216139777 : case STRING_CST: return TS_STRING;
585 : 11337207 : case VECTOR_CST: return TS_VECTOR;
586 : 985153 : case VOID_CST: return TS_TYPED;
587 : 285249 : case RAW_DATA_CST: return TS_RAW_DATA_CST;
588 : :
589 : : /* tcc_exceptional cases. */
590 : 592670311 : case BLOCK: return TS_BLOCK;
591 : 112421973 : case CONSTRUCTOR: return TS_CONSTRUCTOR;
592 : : case ERROR_MARK: return TS_COMMON;
593 : 8697045 : case IDENTIFIER_NODE: return TS_IDENTIFIER;
594 : 813852 : case OMP_CLAUSE: return TS_OMP_CLAUSE;
595 : 1697472 : case OPTIMIZATION_NODE: return TS_OPTIMIZATION;
596 : : case PLACEHOLDER_EXPR: return TS_COMMON;
597 : 251728399 : case SSA_NAME: return TS_SSA_NAME;
598 : 606442608 : case STATEMENT_LIST: return TS_STATEMENT_LIST;
599 : 3577109 : case TARGET_OPTION_NODE: return TS_TARGET_OPTION;
600 : 228829593 : case TREE_BINFO: return TS_BINFO;
601 : 8513056939 : case TREE_LIST: return TS_LIST;
602 : 1701404720 : case TREE_VEC: return TS_VEC;
603 : :
604 : 0 : default:
605 : 0 : gcc_unreachable ();
606 : : }
607 : : }
608 : :
609 : :
610 : : /* Initialize tree_contains_struct to describe the hierarchy of tree
611 : : nodes. */
612 : :
613 : : static void
614 : 285081 : initialize_tree_contains_struct (void)
615 : : {
616 : 285081 : unsigned i;
617 : :
618 : 70129926 : for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++)
619 : : {
620 : 69844845 : enum tree_code code;
621 : 69844845 : enum tree_node_structure_enum ts_code;
622 : :
623 : 69844845 : code = (enum tree_code) i;
624 : 69844845 : ts_code = tree_node_structure_for_code (code);
625 : :
626 : : /* Mark the TS structure itself. */
627 : 69844845 : tree_contains_struct[code][ts_code] = 1;
628 : :
629 : : /* Mark all the structures that TS is derived from. */
630 : 69844845 : switch (ts_code)
631 : : {
632 : 1140324 : case TS_TYPED:
633 : 1140324 : case TS_BLOCK:
634 : 1140324 : case TS_OPTIMIZATION:
635 : 1140324 : case TS_TARGET_OPTION:
636 : 1140324 : MARK_TS_BASE (code);
637 : 1140324 : break;
638 : :
639 : 57586362 : case TS_COMMON:
640 : 57586362 : case TS_INT_CST:
641 : 57586362 : case TS_POLY_INT_CST:
642 : 57586362 : case TS_REAL_CST:
643 : 57586362 : case TS_FIXED_CST:
644 : 57586362 : case TS_VECTOR:
645 : 57586362 : case TS_STRING:
646 : 57586362 : case TS_RAW_DATA_CST:
647 : 57586362 : case TS_COMPLEX:
648 : 57586362 : case TS_SSA_NAME:
649 : 57586362 : case TS_CONSTRUCTOR:
650 : 57586362 : case TS_EXP:
651 : 57586362 : case TS_STATEMENT_LIST:
652 : 57586362 : MARK_TS_TYPED (code);
653 : 57586362 : break;
654 : :
655 : 1425405 : case TS_IDENTIFIER:
656 : 1425405 : case TS_DECL_MINIMAL:
657 : 1425405 : case TS_TYPE_COMMON:
658 : 1425405 : case TS_LIST:
659 : 1425405 : case TS_VEC:
660 : 1425405 : case TS_BINFO:
661 : 1425405 : case TS_OMP_CLAUSE:
662 : 1425405 : MARK_TS_COMMON (code);
663 : 1425405 : break;
664 : :
665 : 0 : case TS_TYPE_WITH_LANG_SPECIFIC:
666 : 0 : MARK_TS_TYPE_COMMON (code);
667 : 0 : break;
668 : :
669 : 5986701 : case TS_TYPE_NON_COMMON:
670 : 5986701 : MARK_TS_TYPE_WITH_LANG_SPECIFIC (code);
671 : 5986701 : break;
672 : :
673 : 0 : case TS_DECL_COMMON:
674 : 0 : MARK_TS_DECL_MINIMAL (code);
675 : 0 : break;
676 : :
677 : 570162 : case TS_DECL_WRTL:
678 : 570162 : case TS_CONST_DECL:
679 : 570162 : MARK_TS_DECL_COMMON (code);
680 : 570162 : break;
681 : :
682 : 855243 : case TS_DECL_NON_COMMON:
683 : 855243 : MARK_TS_DECL_WITH_VIS (code);
684 : 855243 : break;
685 : :
686 : 855243 : case TS_DECL_WITH_VIS:
687 : 855243 : case TS_PARM_DECL:
688 : 855243 : case TS_LABEL_DECL:
689 : 855243 : case TS_RESULT_DECL:
690 : 855243 : MARK_TS_DECL_WRTL (code);
691 : 855243 : break;
692 : :
693 : 285081 : case TS_FIELD_DECL:
694 : 285081 : MARK_TS_DECL_COMMON (code);
695 : 285081 : break;
696 : :
697 : 285081 : case TS_VAR_DECL:
698 : 285081 : MARK_TS_DECL_WITH_VIS (code);
699 : 285081 : break;
700 : :
701 : 570162 : case TS_TYPE_DECL:
702 : 570162 : case TS_FUNCTION_DECL:
703 : 570162 : MARK_TS_DECL_NON_COMMON (code);
704 : 570162 : break;
705 : :
706 : 285081 : case TS_TRANSLATION_UNIT_DECL:
707 : 285081 : MARK_TS_DECL_COMMON (code);
708 : 285081 : break;
709 : :
710 : : default:
711 : : gcc_unreachable ();
712 : : }
713 : : }
714 : :
715 : : /* Basic consistency checks for attributes used in fold. */
716 : 285081 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]);
717 : 285081 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]);
718 : 285081 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]);
719 : 285081 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]);
720 : 285081 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]);
721 : 285081 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]);
722 : 285081 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]);
723 : 285081 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]);
724 : 285081 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]);
725 : 285081 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]);
726 : 285081 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]);
727 : 285081 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]);
728 : 285081 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]);
729 : 285081 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]);
730 : 285081 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]);
731 : 285081 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]);
732 : 285081 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]);
733 : 285081 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]);
734 : 285081 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]);
735 : 285081 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]);
736 : 285081 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]);
737 : 285081 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]);
738 : 285081 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]);
739 : 285081 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]);
740 : 285081 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]);
741 : 285081 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]);
742 : 285081 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]);
743 : 285081 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]);
744 : 285081 : gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]);
745 : 285081 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]);
746 : 285081 : gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]);
747 : 285081 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]);
748 : 285081 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]);
749 : 285081 : gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]);
750 : 285081 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]);
751 : 285081 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]);
752 : 285081 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]);
753 : 285081 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]);
754 : 285081 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_MINIMAL]);
755 : 285081 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_COMMON]);
756 : 285081 : }
757 : :
758 : :
759 : : /* Init tree.cc. */
760 : :
761 : : void
762 : 285081 : init_ttree (void)
763 : : {
764 : : /* Initialize the hash table of types. */
765 : 285081 : type_hash_table
766 : 285081 : = hash_table<type_cache_hasher>::create_ggc (TYPE_HASH_INITIAL_SIZE);
767 : :
768 : 285081 : debug_expr_for_decl
769 : 285081 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
770 : :
771 : 285081 : value_expr_for_decl
772 : 285081 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
773 : :
774 : 285081 : int_cst_hash_table = hash_table<int_cst_hasher>::create_ggc (1024);
775 : :
776 : 285081 : poly_int_cst_hash_table = hash_table<poly_int_cst_hasher>::create_ggc (64);
777 : :
778 : 285081 : int_cst_node = make_int_cst (1, 1);
779 : :
780 : 285081 : cl_option_hash_table = hash_table<cl_option_hasher>::create_ggc (64);
781 : :
782 : 285081 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
783 : 285081 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
784 : :
785 : : /* Initialize the tree_contains_struct array. */
786 : 285081 : initialize_tree_contains_struct ();
787 : 285081 : lang_hooks.init_ts ();
788 : 285081 : }
789 : :
790 : :
791 : : /* The name of the object as the assembler will see it (but before any
792 : : translations made by ASM_OUTPUT_LABELREF). Often this is the same
793 : : as DECL_NAME. It is an IDENTIFIER_NODE. */
794 : : tree
795 : 1565213578 : decl_assembler_name (tree decl)
796 : : {
797 : 1565213578 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
798 : 131324080 : lang_hooks.set_decl_assembler_name (decl);
799 : 1565213578 : return DECL_ASSEMBLER_NAME_RAW (decl);
800 : : }
801 : :
802 : : /* The DECL_ASSEMBLER_NAME_RAW of DECL is being explicitly set to NAME
803 : : (either of which may be NULL). Inform the FE, if this changes the
804 : : name. */
805 : :
806 : : void
807 : 755902098 : overwrite_decl_assembler_name (tree decl, tree name)
808 : : {
809 : 755902098 : if (DECL_ASSEMBLER_NAME_RAW (decl) != name)
810 : 402682318 : lang_hooks.overwrite_decl_assembler_name (decl, name);
811 : 755902098 : }
812 : :
813 : : /* Return true if DECL may need an assembler name to be set. */
814 : :
815 : : static inline bool
816 : 12771448 : need_assembler_name_p (tree decl)
817 : : {
818 : : /* We use DECL_ASSEMBLER_NAME to hold mangled type names for One Definition
819 : : Rule merging. This makes type_odr_p to return true on those types during
820 : : LTO and by comparing the mangled name, we can say what types are intended
821 : : to be equivalent across compilation unit.
822 : :
823 : : We do not store names of type_in_anonymous_namespace_p.
824 : :
825 : : Record, union and enumeration type have linkage that allows use
826 : : to check type_in_anonymous_namespace_p. We do not mangle compound types
827 : : that always can be compared structurally.
828 : :
829 : : Similarly for builtin types, we compare properties of their main variant.
830 : : A special case are integer types where mangling do make differences
831 : : between char/signed char/unsigned char etc. Storing name for these makes
832 : : e.g. -fno-signed-char/-fsigned-char mismatches to be handled well.
833 : : See cp/mangle.cc:write_builtin_type for details. */
834 : :
835 : 12771448 : if (TREE_CODE (decl) == TYPE_DECL)
836 : : {
837 : 389168 : if (DECL_NAME (decl)
838 : 332659 : && decl == TYPE_NAME (TREE_TYPE (decl))
839 : 323784 : && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TREE_TYPE (decl)
840 : 274984 : && !TYPE_ARTIFICIAL (TREE_TYPE (decl))
841 : 271964 : && ((TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
842 : 243330 : && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE)
843 : 28995 : || TYPE_CXX_ODR_P (TREE_TYPE (decl)))
844 : 262557 : && (type_with_linkage_p (TREE_TYPE (decl))
845 : 244094 : || TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE)
846 : 530927 : && !variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
847 : 141759 : return !DECL_ASSEMBLER_NAME_SET_P (decl);
848 : 247409 : return false;
849 : : }
850 : : /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
851 : 12382280 : if (!VAR_OR_FUNCTION_DECL_P (decl))
852 : : return false;
853 : :
854 : : /* If DECL already has its assembler name set, it does not need a
855 : : new one. */
856 : 11192232 : if (!HAS_DECL_ASSEMBLER_NAME_P (decl)
857 : 11192232 : || DECL_ASSEMBLER_NAME_SET_P (decl))
858 : : return false;
859 : :
860 : : /* Abstract decls do not need an assembler name, except they
861 : : can be looked up by autofdo. */
862 : 6389692 : if (DECL_ABSTRACT_P (decl) && !flag_auto_profile)
863 : : return false;
864 : :
865 : : /* For VAR_DECLs, only static, public and external symbols need an
866 : : assembler name. */
867 : 6386095 : if (VAR_P (decl)
868 : 527242 : && !TREE_STATIC (decl)
869 : 526860 : && !TREE_PUBLIC (decl)
870 : 6912044 : && !DECL_EXTERNAL (decl))
871 : : return false;
872 : :
873 : 5860146 : if (TREE_CODE (decl) == FUNCTION_DECL)
874 : : {
875 : : /* Do not set assembler name on builtins. Allow RTL expansion to
876 : : decide whether to expand inline or via a regular call. */
877 : 5858853 : if (fndecl_built_in_p (decl)
878 : 5858853 : && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND)
879 : : return false;
880 : :
881 : : /* Functions represented in the callgraph need an assembler name. */
882 : 1345835 : if (cgraph_node::get (decl) != NULL)
883 : : return true;
884 : :
885 : : /* Unused and not public functions don't need an assembler name. */
886 : 238504 : if (!TREE_USED (decl) && !TREE_PUBLIC (decl))
887 : : return false;
888 : : }
889 : :
890 : : return true;
891 : : }
892 : :
893 : : /* If T needs an assembler name, have one created for it. */
894 : :
895 : : void
896 : 12771448 : assign_assembler_name_if_needed (tree t)
897 : : {
898 : 12771448 : if (need_assembler_name_p (t))
899 : : {
900 : : /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
901 : : diagnostics that use input_location to show locus
902 : : information. The problem here is that, at this point,
903 : : input_location is generally anchored to the end of the file
904 : : (since the parser is long gone), so we don't have a good
905 : : position to pin it to.
906 : :
907 : : To alleviate this problem, this uses the location of T's
908 : : declaration. Examples of this are
909 : : testsuite/g++.dg/template/cond2.C and
910 : : testsuite/g++.dg/template/pr35240.C. */
911 : 1486683 : location_t saved_location = input_location;
912 : 1486683 : input_location = DECL_SOURCE_LOCATION (t);
913 : :
914 : 1486683 : decl_assembler_name (t);
915 : :
916 : 1486683 : input_location = saved_location;
917 : : }
918 : 12771448 : }
919 : :
920 : : /* When the target supports COMDAT groups, this indicates which group the
921 : : DECL is associated with. This can be either an IDENTIFIER_NODE or a
922 : : decl, in which case its DECL_ASSEMBLER_NAME identifies the group. */
923 : : tree
924 : 361940470 : decl_comdat_group (const_tree node)
925 : : {
926 : 361940470 : struct symtab_node *snode = symtab_node::get (node);
927 : 361940470 : if (!snode)
928 : : return NULL;
929 : 346246821 : return snode->get_comdat_group ();
930 : : }
931 : :
932 : : /* Likewise, but make sure it's been reduced to an IDENTIFIER_NODE. */
933 : : tree
934 : 11730 : decl_comdat_group_id (const_tree node)
935 : : {
936 : 11730 : struct symtab_node *snode = symtab_node::get (node);
937 : 11730 : if (!snode)
938 : : return NULL;
939 : 11730 : return snode->get_comdat_group_id ();
940 : : }
941 : :
942 : : /* When the target supports named section, return its name as IDENTIFIER_NODE
943 : : or NULL if it is in no section. */
944 : : const char *
945 : 681972606 : decl_section_name (const_tree node)
946 : : {
947 : 681972606 : struct symtab_node *snode = symtab_node::get (node);
948 : 681972606 : if (!snode)
949 : : return NULL;
950 : 539111812 : return snode->get_section ();
951 : : }
952 : :
953 : : /* Set section name of NODE to VALUE (that is expected to be
954 : : identifier node) */
955 : : void
956 : 1796394 : set_decl_section_name (tree node, const char *value)
957 : : {
958 : 1796394 : struct symtab_node *snode;
959 : :
960 : 1796394 : if (value == NULL)
961 : : {
962 : 55 : snode = symtab_node::get (node);
963 : 55 : if (!snode)
964 : : return;
965 : : }
966 : 1796339 : else if (VAR_P (node))
967 : 1551449 : snode = varpool_node::get_create (node);
968 : : else
969 : 244890 : snode = cgraph_node::get_create (node);
970 : 1796394 : snode->set_section (value);
971 : : }
972 : :
973 : : /* Set section name of NODE to match the section name of OTHER.
974 : :
975 : : set_decl_section_name (decl, other) is equivalent to
976 : : set_decl_section_name (decl, DECL_SECTION_NAME (other)), but possibly more
977 : : efficient. */
978 : : void
979 : 13624505 : set_decl_section_name (tree decl, const_tree other)
980 : : {
981 : 13624505 : struct symtab_node *other_node = symtab_node::get (other);
982 : 13624505 : if (other_node)
983 : : {
984 : 13624159 : struct symtab_node *decl_node;
985 : 13624159 : if (VAR_P (decl))
986 : 23 : decl_node = varpool_node::get_create (decl);
987 : : else
988 : 13624136 : decl_node = cgraph_node::get_create (decl);
989 : 13624159 : decl_node->set_section (*other_node);
990 : : }
991 : : else
992 : : {
993 : 346 : struct symtab_node *decl_node = symtab_node::get (decl);
994 : 346 : if (!decl_node)
995 : : return;
996 : 0 : decl_node->set_section (NULL);
997 : : }
998 : : }
999 : :
1000 : : /* Return TLS model of a variable NODE. */
1001 : : enum tls_model
1002 : 239164058 : decl_tls_model (const_tree node)
1003 : : {
1004 : 239164058 : struct varpool_node *snode = varpool_node::get (node);
1005 : 239164058 : if (!snode)
1006 : : return TLS_MODEL_NONE;
1007 : 202106403 : return snode->tls_model;
1008 : : }
1009 : :
1010 : : /* Set TLS model of variable NODE to MODEL. */
1011 : : void
1012 : 35028 : set_decl_tls_model (tree node, enum tls_model model)
1013 : : {
1014 : 35028 : struct varpool_node *vnode;
1015 : :
1016 : 35028 : if (model == TLS_MODEL_NONE)
1017 : : {
1018 : 5369 : vnode = varpool_node::get (node);
1019 : 5369 : if (!vnode)
1020 : : return;
1021 : : }
1022 : : else
1023 : 29659 : vnode = varpool_node::get_create (node);
1024 : 29659 : vnode->tls_model = model;
1025 : : }
1026 : :
1027 : : /* Compute the number of bytes occupied by a tree with code CODE.
1028 : : This function cannot be used for nodes that have variable sizes,
1029 : : including TREE_VEC, INTEGER_CST, STRING_CST, and CALL_EXPR. */
1030 : : size_t
1031 : 15608282513 : tree_code_size (enum tree_code code)
1032 : : {
1033 : 15608282513 : switch (TREE_CODE_CLASS (code))
1034 : : {
1035 : 3854717882 : case tcc_declaration: /* A decl node */
1036 : 3854717882 : switch (code)
1037 : : {
1038 : : case FIELD_DECL: return sizeof (tree_field_decl);
1039 : : case PARM_DECL: return sizeof (tree_parm_decl);
1040 : 215117937 : case VAR_DECL: return sizeof (tree_var_decl);
1041 : : case LABEL_DECL: return sizeof (tree_label_decl);
1042 : : case RESULT_DECL: return sizeof (tree_result_decl);
1043 : 31204496 : case CONST_DECL: return sizeof (tree_const_decl);
1044 : : case TYPE_DECL: return sizeof (tree_type_decl);
1045 : 1331673840 : case FUNCTION_DECL: return sizeof (tree_function_decl);
1046 : : case DEBUG_EXPR_DECL: return sizeof (tree_decl_with_rtl);
1047 : : case TRANSLATION_UNIT_DECL: return sizeof (tree_translation_unit_decl);
1048 : : case NAMESPACE_DECL:
1049 : : case IMPORTED_DECL:
1050 : : case NAMELIST_DECL: return sizeof (tree_decl_non_common);
1051 : 226466025 : default:
1052 : 226466025 : gcc_checking_assert (code >= NUM_TREE_CODES);
1053 : 226466025 : return lang_hooks.tree_size (code);
1054 : : }
1055 : :
1056 : 2657452408 : case tcc_type: /* a type node */
1057 : 2657452408 : switch (code)
1058 : : {
1059 : : case OFFSET_TYPE:
1060 : : case ENUMERAL_TYPE:
1061 : : case BOOLEAN_TYPE:
1062 : : case INTEGER_TYPE:
1063 : : case REAL_TYPE:
1064 : : case OPAQUE_TYPE:
1065 : : case POINTER_TYPE:
1066 : : case REFERENCE_TYPE:
1067 : : case NULLPTR_TYPE:
1068 : : case FIXED_POINT_TYPE:
1069 : : case COMPLEX_TYPE:
1070 : : case VECTOR_TYPE:
1071 : : case ARRAY_TYPE:
1072 : : case RECORD_TYPE:
1073 : : case UNION_TYPE:
1074 : : case QUAL_UNION_TYPE:
1075 : : case VOID_TYPE:
1076 : : case FUNCTION_TYPE:
1077 : : case METHOD_TYPE:
1078 : : case BITINT_TYPE:
1079 : : case LANG_TYPE: return sizeof (tree_type_non_common);
1080 : 618396280 : default:
1081 : 618396280 : gcc_checking_assert (code >= NUM_TREE_CODES);
1082 : 618396280 : return lang_hooks.tree_size (code);
1083 : : }
1084 : :
1085 : 4012888034 : case tcc_reference: /* a reference */
1086 : 4012888034 : case tcc_expression: /* an expression */
1087 : 4012888034 : case tcc_statement: /* an expression with side effects */
1088 : 4012888034 : case tcc_comparison: /* a comparison expression */
1089 : 4012888034 : case tcc_unary: /* a unary arithmetic expression */
1090 : 4012888034 : case tcc_binary: /* a binary arithmetic expression */
1091 : 4012888034 : return (sizeof (struct tree_exp)
1092 : 4012888034 : + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
1093 : :
1094 : 42774963 : case tcc_constant: /* a constant */
1095 : 42774963 : switch (code)
1096 : : {
1097 : : case VOID_CST: return sizeof (tree_typed);
1098 : 0 : case INTEGER_CST: gcc_unreachable ();
1099 : : case POLY_INT_CST: return sizeof (tree_poly_int_cst);
1100 : 41931307 : case REAL_CST: return sizeof (tree_real_cst);
1101 : : case FIXED_CST: return sizeof (tree_fixed_cst);
1102 : : case COMPLEX_CST: return sizeof (tree_complex);
1103 : : case RAW_DATA_CST: return sizeof (tree_raw_data);
1104 : 0 : case VECTOR_CST: gcc_unreachable ();
1105 : 0 : case STRING_CST: gcc_unreachable ();
1106 : 65466 : default:
1107 : 65466 : gcc_checking_assert (code >= NUM_TREE_CODES);
1108 : 65466 : return lang_hooks.tree_size (code);
1109 : : }
1110 : :
1111 : 5040449226 : case tcc_exceptional: /* something random, like an identifier. */
1112 : 5040449226 : switch (code)
1113 : : {
1114 : 1615365875 : case IDENTIFIER_NODE: return lang_hooks.identifier_size;
1115 : : case TREE_LIST: return sizeof (tree_list);
1116 : :
1117 : : case ERROR_MARK:
1118 : : case PLACEHOLDER_EXPR: return sizeof (tree_common);
1119 : :
1120 : 0 : case TREE_VEC: gcc_unreachable ();
1121 : 0 : case OMP_CLAUSE: gcc_unreachable ();
1122 : :
1123 : : case SSA_NAME: return sizeof (tree_ssa_name);
1124 : :
1125 : : case STATEMENT_LIST: return sizeof (tree_statement_list);
1126 : 265540865 : case BLOCK: return sizeof (struct tree_block);
1127 : : case CONSTRUCTOR: return sizeof (tree_constructor);
1128 : : case OPTIMIZATION_NODE: return sizeof (tree_optimization_option);
1129 : : case TARGET_OPTION_NODE: return sizeof (tree_target_option);
1130 : :
1131 : 1303127793 : default:
1132 : 1303127793 : gcc_checking_assert (code >= NUM_TREE_CODES);
1133 : 1303127793 : return lang_hooks.tree_size (code);
1134 : : }
1135 : :
1136 : 0 : default:
1137 : 0 : gcc_unreachable ();
1138 : : }
1139 : : }
1140 : :
1141 : : /* Compute the number of bytes occupied by NODE. This routine only
1142 : : looks at TREE_CODE, except for those nodes that have variable sizes. */
1143 : : size_t
1144 : 3530716298 : tree_size (const_tree node)
1145 : : {
1146 : 3530716298 : const enum tree_code code = TREE_CODE (node);
1147 : 3530716298 : switch (code)
1148 : : {
1149 : 10866543 : case INTEGER_CST:
1150 : 10866543 : return (sizeof (struct tree_int_cst)
1151 : 10866543 : + (TREE_INT_CST_EXT_NUNITS (node) - 1) * sizeof (HOST_WIDE_INT));
1152 : :
1153 : 0 : case TREE_BINFO:
1154 : 0 : return (offsetof (struct tree_binfo, base_binfos)
1155 : : + vec<tree, va_gc>
1156 : 0 : ::embedded_size (BINFO_N_BASE_BINFOS (node)));
1157 : :
1158 : 350378306 : case TREE_VEC:
1159 : 350378306 : return (sizeof (struct tree_vec)
1160 : 350378306 : + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
1161 : :
1162 : 0 : case VECTOR_CST:
1163 : 0 : return (sizeof (struct tree_vector)
1164 : 0 : + (vector_cst_encoded_nelts (node) - 1) * sizeof (tree));
1165 : :
1166 : 21987 : case STRING_CST:
1167 : 21987 : return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
1168 : :
1169 : 32729 : case OMP_CLAUSE:
1170 : 32729 : return (sizeof (struct tree_omp_clause)
1171 : 32729 : + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
1172 : 32729 : * sizeof (tree));
1173 : :
1174 : 3169416733 : default:
1175 : 3169416733 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
1176 : 141764300 : return (sizeof (struct tree_exp)
1177 : 141764300 : + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
1178 : : else
1179 : 3027652433 : return tree_code_size (code);
1180 : : }
1181 : : }
1182 : :
1183 : : /* Return tree node kind based on tree CODE. */
1184 : :
1185 : : static tree_node_kind
1186 : 0 : get_stats_node_kind (enum tree_code code)
1187 : : {
1188 : 0 : enum tree_code_class type = TREE_CODE_CLASS (code);
1189 : :
1190 : 0 : switch (type)
1191 : : {
1192 : : case tcc_declaration: /* A decl node */
1193 : : return d_kind;
1194 : 0 : case tcc_type: /* a type node */
1195 : 0 : return t_kind;
1196 : 0 : case tcc_statement: /* an expression with side effects */
1197 : 0 : return s_kind;
1198 : 0 : case tcc_reference: /* a reference */
1199 : 0 : return r_kind;
1200 : : case tcc_expression: /* an expression */
1201 : : case tcc_comparison: /* a comparison expression */
1202 : : case tcc_unary: /* a unary arithmetic expression */
1203 : : case tcc_binary: /* a binary arithmetic expression */
1204 : : return e_kind;
1205 : 0 : case tcc_constant: /* a constant */
1206 : 0 : return c_kind;
1207 : 0 : case tcc_exceptional: /* something random, like an identifier. */
1208 : 0 : switch (code)
1209 : : {
1210 : : case IDENTIFIER_NODE:
1211 : : return id_kind;
1212 : 0 : case TREE_VEC:
1213 : 0 : return vec_kind;
1214 : 0 : case TREE_BINFO:
1215 : 0 : return binfo_kind;
1216 : 0 : case SSA_NAME:
1217 : 0 : return ssa_name_kind;
1218 : 0 : case BLOCK:
1219 : 0 : return b_kind;
1220 : 0 : case CONSTRUCTOR:
1221 : 0 : return constr_kind;
1222 : 0 : case OMP_CLAUSE:
1223 : 0 : return omp_clause_kind;
1224 : 0 : default:
1225 : 0 : return x_kind;
1226 : : }
1227 : : break;
1228 : : case tcc_vl_exp:
1229 : : return e_kind;
1230 : 0 : default:
1231 : 0 : gcc_unreachable ();
1232 : : }
1233 : : }
1234 : :
1235 : : /* Record interesting allocation statistics for a tree node with CODE
1236 : : and LENGTH. */
1237 : :
1238 : : static void
1239 : 0 : record_node_allocation_statistics (enum tree_code code, size_t length)
1240 : : {
1241 : 0 : if (!GATHER_STATISTICS)
1242 : 0 : return;
1243 : :
1244 : : tree_node_kind kind = get_stats_node_kind (code);
1245 : :
1246 : : tree_code_counts[(int) code]++;
1247 : : tree_node_counts[(int) kind]++;
1248 : : tree_node_sizes[(int) kind] += length;
1249 : : }
1250 : :
1251 : : /* Allocate and return a new UID from the DECL_UID namespace. */
1252 : :
1253 : : int
1254 : 3848666753 : allocate_decl_uid (void)
1255 : : {
1256 : 3848666753 : return next_decl_uid++;
1257 : : }
1258 : :
1259 : : /* Return a newly allocated node of code CODE. For decl and type
1260 : : nodes, some other fields are initialized. The rest of the node is
1261 : : initialized to zero. This function cannot be used for TREE_VEC,
1262 : : INTEGER_CST or OMP_CLAUSE nodes, which is enforced by asserts in
1263 : : tree_code_size.
1264 : :
1265 : : Achoo! I got a code in the node. */
1266 : :
1267 : : tree
1268 : 12575567826 : make_node (enum tree_code code MEM_STAT_DECL)
1269 : : {
1270 : 12575567826 : tree t;
1271 : 12575567826 : enum tree_code_class type = TREE_CODE_CLASS (code);
1272 : 12575567826 : size_t length = tree_code_size (code);
1273 : :
1274 : 12575567826 : record_node_allocation_statistics (code, length);
1275 : :
1276 : 12575567826 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1277 : 12575567826 : TREE_SET_CODE (t, code);
1278 : :
1279 : 12575567826 : switch (type)
1280 : : {
1281 : 619089924 : case tcc_statement:
1282 : 619089924 : if (code != DEBUG_BEGIN_STMT)
1283 : 322532298 : TREE_SIDE_EFFECTS (t) = 1;
1284 : : break;
1285 : :
1286 : 2841143324 : case tcc_declaration:
1287 : 2841143324 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1288 : : {
1289 : 2841143324 : if (code == FUNCTION_DECL)
1290 : : {
1291 : 1072651004 : SET_DECL_ALIGN (t, FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY));
1292 : 1072651004 : SET_DECL_MODE (t, FUNCTION_MODE);
1293 : : }
1294 : : else
1295 : 1768492320 : SET_DECL_ALIGN (t, 1);
1296 : : }
1297 : 2841143324 : DECL_SOURCE_LOCATION (t) = input_location;
1298 : 2841143324 : if (TREE_CODE (t) == DEBUG_EXPR_DECL)
1299 : 1949648 : DECL_UID (t) = --next_debug_decl_uid;
1300 : : else
1301 : : {
1302 : 2839193676 : DECL_UID (t) = allocate_decl_uid ();
1303 : 2839193676 : SET_DECL_PT_UID (t, -1);
1304 : : }
1305 : 2841143324 : if (TREE_CODE (t) == LABEL_DECL)
1306 : 33267867 : LABEL_DECL_UID (t) = -1;
1307 : :
1308 : : break;
1309 : :
1310 : 1971976714 : case tcc_type:
1311 : 1971976714 : TYPE_UID (t) = next_type_uid++;
1312 : 1971976714 : SET_TYPE_ALIGN (t, BITS_PER_UNIT);
1313 : 1971976714 : TYPE_USER_ALIGN (t) = 0;
1314 : 1971976714 : TYPE_MAIN_VARIANT (t) = t;
1315 : 1971976714 : TYPE_CANONICAL (t) = t;
1316 : :
1317 : : /* Default to no attributes for type, but let target change that. */
1318 : 1971976714 : TYPE_ATTRIBUTES (t) = NULL_TREE;
1319 : 1971976714 : targetm.set_default_type_attributes (t);
1320 : :
1321 : : /* We have not yet computed the alias set for this type. */
1322 : 1971976714 : TYPE_ALIAS_SET (t) = -1;
1323 : 1971976714 : break;
1324 : :
1325 : 42773779 : case tcc_constant:
1326 : 42773779 : TREE_CONSTANT (t) = 1;
1327 : 42773779 : break;
1328 : :
1329 : 1061357337 : case tcc_expression:
1330 : 1061357337 : switch (code)
1331 : : {
1332 : 251850435 : case INIT_EXPR:
1333 : 251850435 : case MODIFY_EXPR:
1334 : 251850435 : case VA_ARG_EXPR:
1335 : 251850435 : case PREDECREMENT_EXPR:
1336 : 251850435 : case PREINCREMENT_EXPR:
1337 : 251850435 : case POSTDECREMENT_EXPR:
1338 : 251850435 : case POSTINCREMENT_EXPR:
1339 : : /* All of these have side-effects, no matter what their
1340 : : operands are. */
1341 : 251850435 : TREE_SIDE_EFFECTS (t) = 1;
1342 : 251850435 : break;
1343 : :
1344 : : default:
1345 : : break;
1346 : : }
1347 : : break;
1348 : :
1349 : 4842765529 : case tcc_exceptional:
1350 : 4842765529 : switch (code)
1351 : : {
1352 : 1086056 : case TARGET_OPTION_NODE:
1353 : 2172112 : TREE_TARGET_OPTION(t)
1354 : 1086056 : = ggc_cleared_alloc<struct cl_target_option> ();
1355 : 1086056 : break;
1356 : :
1357 : 595503 : case OPTIMIZATION_NODE:
1358 : 1191006 : TREE_OPTIMIZATION (t)
1359 : 595503 : = ggc_cleared_alloc<struct cl_optimization> ();
1360 : 595503 : break;
1361 : :
1362 : : default:
1363 : : break;
1364 : : }
1365 : : break;
1366 : :
1367 : : default:
1368 : : /* Other classes need no special treatment. */
1369 : : break;
1370 : : }
1371 : :
1372 : 12575567826 : return t;
1373 : : }
1374 : :
1375 : : /* Free tree node. */
1376 : :
1377 : : void
1378 : 607270745 : free_node (tree node)
1379 : : {
1380 : 607270745 : enum tree_code code = TREE_CODE (node);
1381 : 607270745 : if (GATHER_STATISTICS)
1382 : : {
1383 : : enum tree_node_kind kind = get_stats_node_kind (code);
1384 : :
1385 : : gcc_checking_assert (tree_code_counts[(int) TREE_CODE (node)] != 0);
1386 : : gcc_checking_assert (tree_node_counts[(int) kind] != 0);
1387 : : gcc_checking_assert (tree_node_sizes[(int) kind] >= tree_size (node));
1388 : :
1389 : : tree_code_counts[(int) TREE_CODE (node)]--;
1390 : : tree_node_counts[(int) kind]--;
1391 : : tree_node_sizes[(int) kind] -= tree_size (node);
1392 : : }
1393 : 607270745 : if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1394 : 349 : vec_free (CONSTRUCTOR_ELTS (node));
1395 : 607270552 : else if (code == BLOCK)
1396 : 0 : vec_free (BLOCK_NONLOCALIZED_VARS (node));
1397 : 607270552 : else if (code == TREE_BINFO)
1398 : 363 : vec_free (BINFO_BASE_ACCESSES (node));
1399 : 607270189 : else if (code == OPTIMIZATION_NODE)
1400 : 808 : cl_optimization_option_free (TREE_OPTIMIZATION (node));
1401 : 607269381 : else if (code == TARGET_OPTION_NODE)
1402 : 873 : cl_target_option_free (TREE_TARGET_OPTION (node));
1403 : 607270745 : ggc_free (node);
1404 : 607270745 : }
1405 : :
1406 : : /* Return a new node with the same contents as NODE except that its
1407 : : TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
1408 : :
1409 : : tree
1410 : 3448784975 : copy_node (tree node MEM_STAT_DECL)
1411 : : {
1412 : 3448784975 : tree t;
1413 : 3448784975 : enum tree_code code = TREE_CODE (node);
1414 : 3448784975 : size_t length;
1415 : :
1416 : 3448784975 : gcc_assert (code != STATEMENT_LIST);
1417 : :
1418 : 3448784975 : length = tree_size (node);
1419 : 3448784975 : record_node_allocation_statistics (code, length);
1420 : 3448784975 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
1421 : 3448784975 : memcpy (t, node, length);
1422 : :
1423 : 3448784975 : if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
1424 : 2097158442 : TREE_CHAIN (t) = 0;
1425 : 3448784975 : TREE_ASM_WRITTEN (t) = 0;
1426 : 3448784975 : TREE_VISITED (t) = 0;
1427 : :
1428 : 3448784975 : if (TREE_CODE_CLASS (code) == tcc_declaration)
1429 : : {
1430 : 1008512304 : if (code == DEBUG_EXPR_DECL)
1431 : 0 : DECL_UID (t) = --next_debug_decl_uid;
1432 : : else
1433 : : {
1434 : 1008512304 : DECL_UID (t) = allocate_decl_uid ();
1435 : 1008512304 : if (DECL_PT_UID_SET_P (node))
1436 : 3513 : SET_DECL_PT_UID (t, DECL_PT_UID (node));
1437 : : }
1438 : 496164024 : if ((TREE_CODE (node) == PARM_DECL || VAR_P (node))
1439 : 1068045390 : && DECL_HAS_VALUE_EXPR_P (node))
1440 : : {
1441 : 822931 : SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
1442 : 822931 : DECL_HAS_VALUE_EXPR_P (t) = 1;
1443 : : }
1444 : : /* DECL_DEBUG_EXPR is copied explicitly by callers. */
1445 : 1008512304 : if (VAR_P (node))
1446 : : {
1447 : 59533086 : DECL_HAS_DEBUG_EXPR_P (t) = 0;
1448 : 59533086 : t->decl_with_vis.symtab_node = NULL;
1449 : : }
1450 : 1008512304 : if (VAR_P (node) && DECL_HAS_INIT_PRIORITY_P (node))
1451 : : {
1452 : 0 : SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
1453 : 0 : DECL_HAS_INIT_PRIORITY_P (t) = 1;
1454 : : }
1455 : 1008512304 : if (TREE_CODE (node) == FUNCTION_DECL)
1456 : : {
1457 : 254432851 : DECL_STRUCT_FUNCTION (t) = NULL;
1458 : 254432851 : t->decl_with_vis.symtab_node = NULL;
1459 : : }
1460 : : }
1461 : 2440272671 : else if (TREE_CODE_CLASS (code) == tcc_type)
1462 : : {
1463 : 685475694 : TYPE_UID (t) = next_type_uid++;
1464 : : /* The following is so that the debug code for
1465 : : the copy is different from the original type.
1466 : : The two statements usually duplicate each other
1467 : : (because they clear fields of the same union),
1468 : : but the optimizer should catch that. */
1469 : 685475694 : TYPE_SYMTAB_ADDRESS (t) = 0;
1470 : 685475694 : TYPE_SYMTAB_DIE (t) = 0;
1471 : :
1472 : : /* Do not copy the values cache. */
1473 : 685475694 : if (TYPE_CACHED_VALUES_P (t))
1474 : : {
1475 : 17203382 : TYPE_CACHED_VALUES_P (t) = 0;
1476 : 17203382 : TYPE_CACHED_VALUES (t) = NULL_TREE;
1477 : : }
1478 : : }
1479 : 1754796977 : else if (code == TARGET_OPTION_NODE)
1480 : : {
1481 : 0 : TREE_TARGET_OPTION (t) = ggc_alloc<struct cl_target_option>();
1482 : 0 : memcpy (TREE_TARGET_OPTION (t), TREE_TARGET_OPTION (node),
1483 : : sizeof (struct cl_target_option));
1484 : : }
1485 : 1754796977 : else if (code == OPTIMIZATION_NODE)
1486 : : {
1487 : 0 : TREE_OPTIMIZATION (t) = ggc_alloc<struct cl_optimization>();
1488 : 0 : memcpy (TREE_OPTIMIZATION (t), TREE_OPTIMIZATION (node),
1489 : : sizeof (struct cl_optimization));
1490 : : }
1491 : :
1492 : 3448784975 : return t;
1493 : : }
1494 : :
1495 : : /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1496 : : For example, this can copy a list made of TREE_LIST nodes. */
1497 : :
1498 : : tree
1499 : 135153363 : copy_list (tree list)
1500 : : {
1501 : 135153363 : tree head;
1502 : 135153363 : tree prev, next;
1503 : :
1504 : 135153363 : if (list == 0)
1505 : : return 0;
1506 : :
1507 : 130119928 : head = prev = copy_node (list);
1508 : 130119928 : next = TREE_CHAIN (list);
1509 : 257522243 : while (next)
1510 : : {
1511 : 127402315 : TREE_CHAIN (prev) = copy_node (next);
1512 : 127402315 : prev = TREE_CHAIN (prev);
1513 : 127402315 : next = TREE_CHAIN (next);
1514 : : }
1515 : : return head;
1516 : : }
1517 : :
1518 : :
1519 : : /* Return the value that TREE_INT_CST_EXT_NUNITS should have for an
1520 : : INTEGER_CST with value CST and type TYPE. */
1521 : :
1522 : : static unsigned int
1523 : 8867234635 : get_int_cst_ext_nunits (tree type, const wide_int &cst)
1524 : : {
1525 : 8867234635 : gcc_checking_assert (cst.get_precision () == TYPE_PRECISION (type));
1526 : : /* We need extra HWIs if CST is an unsigned integer with its
1527 : : upper bit set. */
1528 : 8867234635 : if (TYPE_UNSIGNED (type) && wi::neg_p (cst))
1529 : 164486886 : return cst.get_precision () / HOST_BITS_PER_WIDE_INT + 1;
1530 : 8702747749 : return cst.get_len ();
1531 : : }
1532 : :
1533 : : /* Return a new INTEGER_CST with value CST and type TYPE. */
1534 : :
1535 : : static tree
1536 : 120766426 : build_new_int_cst (tree type, const wide_int &cst)
1537 : : {
1538 : 120766426 : unsigned int len = cst.get_len ();
1539 : 120766426 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1540 : 120766426 : tree nt = make_int_cst (len, ext_len);
1541 : :
1542 : 120766426 : if (len < ext_len)
1543 : : {
1544 : 59690347 : --ext_len;
1545 : 119380694 : TREE_INT_CST_ELT (nt, ext_len)
1546 : 59690347 : = zext_hwi (-1, cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1547 : 77517938 : for (unsigned int i = len; i < ext_len; ++i)
1548 : 17827591 : TREE_INT_CST_ELT (nt, i) = -1;
1549 : : }
1550 : 61076079 : else if (TYPE_UNSIGNED (type)
1551 : 61076079 : && cst.get_precision () < len * HOST_BITS_PER_WIDE_INT)
1552 : : {
1553 : 12558920 : len--;
1554 : 25117840 : TREE_INT_CST_ELT (nt, len)
1555 : 12558920 : = zext_hwi (cst.elt (len),
1556 : 12558920 : cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1557 : : }
1558 : :
1559 : 250390426 : for (unsigned int i = 0; i < len; i++)
1560 : 129624000 : TREE_INT_CST_ELT (nt, i) = cst.elt (i);
1561 : 120766426 : TREE_TYPE (nt) = type;
1562 : 120766426 : return nt;
1563 : : }
1564 : :
1565 : : /* Return a new POLY_INT_CST with coefficients COEFFS and type TYPE. */
1566 : :
1567 : : static tree
1568 : 0 : build_new_poly_int_cst (tree type, tree (&coeffs)[NUM_POLY_INT_COEFFS]
1569 : : CXX_MEM_STAT_INFO)
1570 : : {
1571 : 0 : size_t length = sizeof (struct tree_poly_int_cst);
1572 : 0 : record_node_allocation_statistics (POLY_INT_CST, length);
1573 : :
1574 : 0 : tree t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1575 : :
1576 : 0 : TREE_SET_CODE (t, POLY_INT_CST);
1577 : 0 : TREE_CONSTANT (t) = 1;
1578 : 0 : TREE_TYPE (t) = type;
1579 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1580 : 0 : POLY_INT_CST_COEFF (t, i) = coeffs[i];
1581 : 0 : return t;
1582 : : }
1583 : :
1584 : : /* Create a constant tree that contains CST sign-extended to TYPE. */
1585 : :
1586 : : tree
1587 : 5903544362 : build_int_cst (tree type, poly_int64 cst)
1588 : : {
1589 : : /* Support legacy code. */
1590 : 5903544362 : if (!type)
1591 : 1878219923 : type = integer_type_node;
1592 : :
1593 : 5903544362 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1594 : : }
1595 : :
1596 : : /* Create a constant tree that contains CST zero-extended to TYPE. */
1597 : :
1598 : : tree
1599 : 9252549 : build_int_cstu (tree type, poly_uint64 cst)
1600 : : {
1601 : 9252549 : return wide_int_to_tree (type, wi::uhwi (cst, TYPE_PRECISION (type)));
1602 : : }
1603 : :
1604 : : /* Create a constant tree that contains CST sign-extended to TYPE. */
1605 : :
1606 : : tree
1607 : 24870998 : build_int_cst_type (tree type, poly_int64 cst)
1608 : : {
1609 : 24870998 : gcc_assert (type);
1610 : 24870998 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1611 : : }
1612 : :
1613 : : /* Constructs tree in type TYPE from with value given by CST. Signedness
1614 : : of CST is assumed to be the same as the signedness of TYPE. */
1615 : :
1616 : : tree
1617 : 7287125 : double_int_to_tree (tree type, double_int cst)
1618 : : {
1619 : 7287125 : return wide_int_to_tree (type, widest_int::from (cst, TYPE_SIGN (type)));
1620 : : }
1621 : :
1622 : : /* We force the wide_int CST to the range of the type TYPE by sign or
1623 : : zero extending it. OVERFLOWABLE indicates if we are interested in
1624 : : overflow of the value, when >0 we are only interested in signed
1625 : : overflow, for <0 we are interested in any overflow. OVERFLOWED
1626 : : indicates whether overflow has already occurred. CONST_OVERFLOWED
1627 : : indicates whether constant overflow has already occurred. We force
1628 : : T's value to be within range of T's type (by setting to 0 or 1 all
1629 : : the bits outside the type's range). We set TREE_OVERFLOWED if,
1630 : : OVERFLOWED is nonzero,
1631 : : or OVERFLOWABLE is >0 and signed overflow occurs
1632 : : or OVERFLOWABLE is <0 and any overflow occurs
1633 : : We return a new tree node for the extended wide_int. The node
1634 : : is shared if no overflow flags are set. */
1635 : :
1636 : :
1637 : : tree
1638 : 2293476908 : force_fit_type (tree type, const poly_wide_int_ref &cst,
1639 : : int overflowable, bool overflowed)
1640 : : {
1641 : 2293476908 : signop sign = TYPE_SIGN (type);
1642 : :
1643 : : /* If we need to set overflow flags, return a new unshared node. */
1644 : 2293476908 : if (overflowed || !wi::fits_to_tree_p (cst, type))
1645 : : {
1646 : 6586972 : if (overflowed
1647 : 6586972 : || overflowable < 0
1648 : 5346850 : || (overflowable > 0 && sign == SIGNED))
1649 : : {
1650 : 1286531 : poly_wide_int tmp = poly_wide_int::from (cst, TYPE_PRECISION (type),
1651 : 1286531 : sign);
1652 : 1286531 : tree t;
1653 : 1286531 : if (tmp.is_constant ())
1654 : 1286531 : t = build_new_int_cst (type, tmp.coeffs[0]);
1655 : : else
1656 : : {
1657 : : tree coeffs[NUM_POLY_INT_COEFFS];
1658 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1659 : : {
1660 : : coeffs[i] = build_new_int_cst (type, tmp.coeffs[i]);
1661 : : TREE_OVERFLOW (coeffs[i]) = 1;
1662 : : }
1663 : : t = build_new_poly_int_cst (type, coeffs);
1664 : : }
1665 : 1286531 : TREE_OVERFLOW (t) = 1;
1666 : 1286531 : return t;
1667 : 1286531 : }
1668 : : }
1669 : :
1670 : : /* Else build a shared node. */
1671 : 2292190377 : return wide_int_to_tree (type, cst);
1672 : : }
1673 : :
1674 : : /* These are the hash table functions for the hash table of INTEGER_CST
1675 : : nodes of a sizetype. */
1676 : :
1677 : : /* Return the hash code X, an INTEGER_CST. */
1678 : :
1679 : : hashval_t
1680 : 1571021737 : int_cst_hasher::hash (tree x)
1681 : : {
1682 : 1571021737 : const_tree const t = x;
1683 : 1571021737 : hashval_t code = TYPE_UID (TREE_TYPE (t));
1684 : 1571021737 : int i;
1685 : :
1686 : 3193943264 : for (i = 0; i < TREE_INT_CST_NUNITS (t); i++)
1687 : 1622921527 : code = iterative_hash_host_wide_int (TREE_INT_CST_ELT(t, i), code);
1688 : :
1689 : 1571021737 : return code;
1690 : : }
1691 : :
1692 : : /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1693 : : is the same as that given by *Y, which is the same. */
1694 : :
1695 : : bool
1696 : 1576144532 : int_cst_hasher::equal (tree x, tree y)
1697 : : {
1698 : 1576144532 : const_tree const xt = x;
1699 : 1576144532 : const_tree const yt = y;
1700 : :
1701 : 1576144532 : if (TREE_TYPE (xt) != TREE_TYPE (yt)
1702 : 568884878 : || TREE_INT_CST_NUNITS (xt) != TREE_INT_CST_NUNITS (yt)
1703 : 2144976561 : || TREE_INT_CST_EXT_NUNITS (xt) != TREE_INT_CST_EXT_NUNITS (yt))
1704 : : return false;
1705 : :
1706 : 845430888 : for (int i = 0; i < TREE_INT_CST_NUNITS (xt); i++)
1707 : 540280853 : if (TREE_INT_CST_ELT (xt, i) != TREE_INT_CST_ELT (yt, i))
1708 : : return false;
1709 : :
1710 : : return true;
1711 : : }
1712 : :
1713 : : /* Cache wide_int CST into the TYPE_CACHED_VALUES cache for TYPE.
1714 : : SLOT is the slot entry to store it in, and MAX_SLOTS is the maximum
1715 : : number of slots that can be cached for the type. */
1716 : :
1717 : : static inline tree
1718 : 8369707433 : cache_wide_int_in_type_cache (tree type, const wide_int &cst,
1719 : : int slot, int max_slots)
1720 : : {
1721 : 8369707433 : gcc_checking_assert (slot >= 0);
1722 : : /* Initialize cache. */
1723 : 8369707433 : if (!TYPE_CACHED_VALUES_P (type))
1724 : : {
1725 : 17285306 : TYPE_CACHED_VALUES_P (type) = 1;
1726 : 17285306 : TYPE_CACHED_VALUES (type) = make_tree_vec (max_slots);
1727 : : }
1728 : 8369707433 : tree t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot);
1729 : 8369707433 : if (!t)
1730 : : {
1731 : : /* Create a new shared int. */
1732 : 54819101 : t = build_new_int_cst (type, cst);
1733 : 54819101 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot) = t;
1734 : : }
1735 : 8369707433 : return t;
1736 : : }
1737 : :
1738 : : /* Create an INT_CST node of TYPE and value CST.
1739 : : The returned node is always shared. For small integers we use a
1740 : : per-type vector cache, for larger ones we use a single hash table.
1741 : : The value is extended from its precision according to the sign of
1742 : : the type to be a multiple of HOST_BITS_PER_WIDE_INT. This defines
1743 : : the upper bits and ensures that hashing and value equality based
1744 : : upon the underlying HOST_WIDE_INTs works without masking. */
1745 : :
1746 : : static tree
1747 : 8746468209 : wide_int_to_tree_1 (tree type, const wide_int_ref &pcst)
1748 : : {
1749 : 8746468209 : tree t;
1750 : 8746468209 : int ix = -1;
1751 : 8746468209 : int limit = 0;
1752 : :
1753 : 8746468209 : gcc_assert (type);
1754 : 8746468209 : unsigned int prec = TYPE_PRECISION (type);
1755 : 8746468209 : signop sgn = TYPE_SIGN (type);
1756 : :
1757 : : /* Verify that everything is canonical. */
1758 : 8746468209 : int l = pcst.get_len ();
1759 : 8746468209 : if (l > 1)
1760 : : {
1761 : 6619305 : if (pcst.elt (l - 1) == 0)
1762 : 1083822 : gcc_checking_assert (pcst.elt (l - 2) < 0);
1763 : 6619305 : if (pcst.elt (l - 1) == HOST_WIDE_INT_M1)
1764 : 11574 : gcc_checking_assert (pcst.elt (l - 2) >= 0);
1765 : : }
1766 : :
1767 : 8746468209 : wide_int cst = wide_int::from (pcst, prec, sgn);
1768 : 8746468209 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1769 : :
1770 : 8746468209 : enum tree_code code = TREE_CODE (type);
1771 : 8746468209 : if (code == POINTER_TYPE || code == REFERENCE_TYPE)
1772 : : {
1773 : : /* Cache NULL pointer and zero bounds. */
1774 : 167472033 : if (cst == 0)
1775 : : ix = 0;
1776 : : /* Cache upper bounds of pointers. */
1777 : 32104397 : else if (cst == wi::max_value (prec, sgn))
1778 : : ix = 1;
1779 : : /* Cache 1 which is used for a non-zero range. */
1780 : 30054748 : else if (cst == 1)
1781 : : ix = 2;
1782 : :
1783 : : if (ix >= 0)
1784 : : {
1785 : 141304860 : t = cache_wide_int_in_type_cache (type, cst, ix, 3);
1786 : : /* Make sure no one is clobbering the shared constant. */
1787 : 141304860 : gcc_checking_assert (TREE_TYPE (t) == type
1788 : : && cst == wi::to_wide (t));
1789 : 141304860 : return t;
1790 : : }
1791 : : }
1792 : 8605163349 : if (ext_len == 1)
1793 : : {
1794 : : /* We just need to store a single HOST_WIDE_INT. */
1795 : 8540502555 : HOST_WIDE_INT hwi;
1796 : 8540502555 : if (TYPE_UNSIGNED (type))
1797 : 5853063879 : hwi = cst.to_uhwi ();
1798 : : else
1799 : 2687439047 : hwi = cst.to_shwi ();
1800 : :
1801 : 8540502555 : switch (code)
1802 : : {
1803 : 206115 : case NULLPTR_TYPE:
1804 : 206115 : gcc_assert (hwi == 0);
1805 : : /* Fallthru. */
1806 : :
1807 : : case POINTER_TYPE:
1808 : : case REFERENCE_TYPE:
1809 : : /* Ignore pointers, as they were already handled above. */
1810 : : break;
1811 : :
1812 : 105537166 : case BOOLEAN_TYPE:
1813 : : /* Cache false or true. */
1814 : 105537166 : limit = 2;
1815 : 105537166 : if (IN_RANGE (hwi, 0, 1))
1816 : 105383345 : ix = hwi;
1817 : : break;
1818 : :
1819 : 8405072781 : case INTEGER_TYPE:
1820 : 8405072781 : case OFFSET_TYPE:
1821 : 8405072781 : case BITINT_TYPE:
1822 : 8405072781 : if (TYPE_SIGN (type) == UNSIGNED)
1823 : : {
1824 : : /* Cache [0, N). */
1825 : 5720934000 : limit = param_integer_share_limit;
1826 : 5720934000 : if (IN_RANGE (hwi, 0, param_integer_share_limit - 1))
1827 : 5541467287 : ix = hwi;
1828 : : }
1829 : : else
1830 : : {
1831 : : /* Cache [-1, N). */
1832 : 2684138781 : limit = param_integer_share_limit + 1;
1833 : 2684138781 : if (IN_RANGE (hwi, -1, param_integer_share_limit - 1))
1834 : 2581551941 : ix = hwi + 1;
1835 : : }
1836 : : break;
1837 : :
1838 : : case ENUMERAL_TYPE:
1839 : : break;
1840 : :
1841 : 0 : default:
1842 : 0 : gcc_unreachable ();
1843 : : }
1844 : :
1845 : 8540502555 : if (ix >= 0)
1846 : : {
1847 : 8228402573 : t = cache_wide_int_in_type_cache (type, cst, ix, limit);
1848 : : /* Make sure no one is clobbering the shared constant. */
1849 : 16456805146 : gcc_checking_assert (TREE_TYPE (t) == type
1850 : : && TREE_INT_CST_NUNITS (t) == 1
1851 : : && TREE_INT_CST_EXT_NUNITS (t) == 1
1852 : : && TREE_INT_CST_ELT (t, 0) == hwi);
1853 : : return t;
1854 : : }
1855 : : else
1856 : : {
1857 : : /* Use the cache of larger shared ints, using int_cst_node as
1858 : : a temporary. */
1859 : :
1860 : 312099982 : TREE_INT_CST_ELT (int_cst_node, 0) = hwi;
1861 : 312099982 : TREE_TYPE (int_cst_node) = type;
1862 : :
1863 : 312099982 : tree *slot = int_cst_hash_table->find_slot (int_cst_node, INSERT);
1864 : 312099982 : t = *slot;
1865 : 312099982 : if (!t)
1866 : : {
1867 : : /* Insert this one into the hash table. */
1868 : 61752588 : t = int_cst_node;
1869 : 61752588 : *slot = t;
1870 : : /* Make a new node for next time round. */
1871 : 61752588 : int_cst_node = make_int_cst (1, 1);
1872 : : }
1873 : : }
1874 : : }
1875 : : else
1876 : : {
1877 : : /* The value either hashes properly or we drop it on the floor
1878 : : for the gc to take care of. There will not be enough of them
1879 : : to worry about. */
1880 : :
1881 : 64660794 : tree nt = build_new_int_cst (type, cst);
1882 : 64660794 : tree *slot = int_cst_hash_table->find_slot (nt, INSERT);
1883 : 64660794 : t = *slot;
1884 : 64660794 : if (!t)
1885 : : {
1886 : : /* Insert this one into the hash table. */
1887 : 13452301 : t = nt;
1888 : 13452301 : *slot = t;
1889 : : }
1890 : : else
1891 : 51208493 : ggc_free (nt);
1892 : : }
1893 : :
1894 : : return t;
1895 : 8746468209 : }
1896 : :
1897 : : hashval_t
1898 : 0 : poly_int_cst_hasher::hash (tree t)
1899 : : {
1900 : 0 : inchash::hash hstate;
1901 : :
1902 : 0 : hstate.add_int (TYPE_UID (TREE_TYPE (t)));
1903 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1904 : 0 : hstate.add_wide_int (wi::to_wide (POLY_INT_CST_COEFF (t, i)));
1905 : :
1906 : 0 : return hstate.end ();
1907 : : }
1908 : :
1909 : : bool
1910 : 0 : poly_int_cst_hasher::equal (tree x, const compare_type &y)
1911 : : {
1912 : 0 : if (TREE_TYPE (x) != y.first)
1913 : : return false;
1914 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1915 : 0 : if (wi::to_wide (POLY_INT_CST_COEFF (x, i)) != y.second->coeffs[i])
1916 : : return false;
1917 : : return true;
1918 : : }
1919 : :
1920 : : /* Build a POLY_INT_CST node with type TYPE and with the elements in VALUES.
1921 : : The elements must also have type TYPE. */
1922 : :
1923 : : tree
1924 : 0 : build_poly_int_cst (tree type, const poly_wide_int_ref &values)
1925 : : {
1926 : 0 : unsigned int prec = TYPE_PRECISION (type);
1927 : 0 : gcc_assert (prec <= values.coeffs[0].get_precision ());
1928 : 0 : poly_wide_int c = poly_wide_int::from (values, prec, SIGNED);
1929 : :
1930 : 0 : inchash::hash h;
1931 : 0 : h.add_int (TYPE_UID (type));
1932 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1933 : 0 : h.add_wide_int (c.coeffs[i]);
1934 : 0 : poly_int_cst_hasher::compare_type comp (type, &c);
1935 : 0 : tree *slot = poly_int_cst_hash_table->find_slot_with_hash (comp, h.end (),
1936 : : INSERT);
1937 : 0 : if (*slot == NULL_TREE)
1938 : : {
1939 : : tree coeffs[NUM_POLY_INT_COEFFS];
1940 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1941 : 0 : coeffs[i] = wide_int_to_tree_1 (type, c.coeffs[i]);
1942 : 0 : *slot = build_new_poly_int_cst (type, coeffs);
1943 : : }
1944 : 0 : return *slot;
1945 : 0 : }
1946 : :
1947 : : /* Create a constant tree with value VALUE in type TYPE. */
1948 : :
1949 : : tree
1950 : 8746468209 : wide_int_to_tree (tree type, const poly_wide_int_ref &value)
1951 : : {
1952 : 8746468209 : if (value.is_constant ())
1953 : 8746468209 : return wide_int_to_tree_1 (type, value.coeffs[0]);
1954 : : return build_poly_int_cst (type, value);
1955 : : }
1956 : :
1957 : : /* Insert INTEGER_CST T into a cache of integer constants. And return
1958 : : the cached constant (which may or may not be T). If MIGHT_DUPLICATE
1959 : : is false, and T falls into the type's 'smaller values' range, there
1960 : : cannot be an existing entry. Otherwise, if MIGHT_DUPLICATE is true,
1961 : : or the value is large, should an existing entry exist, it is
1962 : : returned (rather than inserting T). */
1963 : :
1964 : : tree
1965 : 493721 : cache_integer_cst (tree t, bool might_duplicate ATTRIBUTE_UNUSED)
1966 : : {
1967 : 493721 : tree type = TREE_TYPE (t);
1968 : 493721 : int ix = -1;
1969 : 493721 : int limit = 0;
1970 : 493721 : int prec = TYPE_PRECISION (type);
1971 : :
1972 : 493721 : gcc_assert (!TREE_OVERFLOW (t));
1973 : :
1974 : : /* The caching indices here must match those in
1975 : : wide_int_to_type_1. */
1976 : 493721 : switch (TREE_CODE (type))
1977 : : {
1978 : 0 : case NULLPTR_TYPE:
1979 : 0 : gcc_checking_assert (integer_zerop (t));
1980 : : /* Fallthru. */
1981 : :
1982 : 3137 : case POINTER_TYPE:
1983 : 3137 : case REFERENCE_TYPE:
1984 : 3137 : {
1985 : 3137 : if (integer_zerop (t))
1986 : : ix = 0;
1987 : 1330 : else if (integer_onep (t))
1988 : : ix = 2;
1989 : :
1990 : : if (ix >= 0)
1991 : : limit = 3;
1992 : : }
1993 : : break;
1994 : :
1995 : 9870 : case BOOLEAN_TYPE:
1996 : : /* Cache false or true. */
1997 : 9870 : limit = 2;
1998 : 9870 : if (wi::ltu_p (wi::to_wide (t), 2))
1999 : 0 : ix = TREE_INT_CST_ELT (t, 0);
2000 : : break;
2001 : :
2002 : 469105 : case INTEGER_TYPE:
2003 : 469105 : case OFFSET_TYPE:
2004 : 469105 : case BITINT_TYPE:
2005 : 469105 : if (TYPE_UNSIGNED (type))
2006 : : {
2007 : : /* Cache 0..N */
2008 : 350375 : limit = param_integer_share_limit;
2009 : :
2010 : : /* This is a little hokie, but if the prec is smaller than
2011 : : what is necessary to hold param_integer_share_limit, then the
2012 : : obvious test will not get the correct answer. */
2013 : 350375 : if (prec < HOST_BITS_PER_WIDE_INT)
2014 : : {
2015 : 71957 : if (tree_to_uhwi (t)
2016 : 71957 : < (unsigned HOST_WIDE_INT) param_integer_share_limit)
2017 : 10494 : ix = tree_to_uhwi (t);
2018 : : }
2019 : 278418 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2020 : 216574 : ix = tree_to_uhwi (t);
2021 : : }
2022 : : else
2023 : : {
2024 : : /* Cache -1..N */
2025 : 118730 : limit = param_integer_share_limit + 1;
2026 : :
2027 : 118730 : if (integer_minus_onep (t))
2028 : : ix = 0;
2029 : 118393 : else if (!wi::neg_p (wi::to_wide (t)))
2030 : : {
2031 : 103757 : if (prec < HOST_BITS_PER_WIDE_INT)
2032 : : {
2033 : 99568 : if (tree_to_shwi (t) < param_integer_share_limit)
2034 : 92062 : ix = tree_to_shwi (t) + 1;
2035 : : }
2036 : 4189 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2037 : 3400 : ix = tree_to_shwi (t) + 1;
2038 : : }
2039 : : }
2040 : : break;
2041 : :
2042 : : case ENUMERAL_TYPE:
2043 : : /* The slot used by TYPE_CACHED_VALUES is used for the enum
2044 : : members. */
2045 : : break;
2046 : :
2047 : 0 : default:
2048 : 0 : gcc_unreachable ();
2049 : : }
2050 : :
2051 : 324337 : if (ix >= 0)
2052 : : {
2053 : : /* Look for it in the type's vector of small shared ints. */
2054 : 324951 : if (!TYPE_CACHED_VALUES_P (type))
2055 : : {
2056 : 12218 : TYPE_CACHED_VALUES_P (type) = 1;
2057 : 12218 : TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
2058 : : }
2059 : :
2060 : 324951 : if (tree r = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix))
2061 : : {
2062 : 304093 : gcc_checking_assert (might_duplicate);
2063 : 304093 : t = r;
2064 : : }
2065 : : else
2066 : 20858 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
2067 : : }
2068 : : else
2069 : : {
2070 : : /* Use the cache of larger shared ints. */
2071 : 168770 : tree *slot = int_cst_hash_table->find_slot (t, INSERT);
2072 : 168770 : if (tree r = *slot)
2073 : : {
2074 : : /* If there is already an entry for the number verify it's the
2075 : : same value. */
2076 : 100271 : gcc_checking_assert (wi::to_wide (tree (r)) == wi::to_wide (t));
2077 : : /* And return the cached value. */
2078 : 100271 : t = r;
2079 : : }
2080 : : else
2081 : : /* Otherwise insert this one into the hash table. */
2082 : 68499 : *slot = t;
2083 : : }
2084 : :
2085 : 493721 : return t;
2086 : : }
2087 : :
2088 : :
2089 : : /* Builds an integer constant in TYPE such that lowest BITS bits are ones
2090 : : and the rest are zeros. */
2091 : :
2092 : : tree
2093 : 9177929 : build_low_bits_mask (tree type, unsigned bits)
2094 : : {
2095 : 9177929 : gcc_assert (bits <= TYPE_PRECISION (type));
2096 : :
2097 : 9177929 : return wide_int_to_tree (type, wi::mask (bits, false,
2098 : 9177929 : TYPE_PRECISION (type)));
2099 : : }
2100 : :
2101 : : /* Checks that X is integer constant that can be expressed in (unsigned)
2102 : : HOST_WIDE_INT without loss of precision. */
2103 : :
2104 : : bool
2105 : 572410045 : cst_and_fits_in_hwi (const_tree x)
2106 : : {
2107 : 572410045 : return (TREE_CODE (x) == INTEGER_CST
2108 : 572410045 : && (tree_fits_shwi_p (x) || tree_fits_uhwi_p (x)));
2109 : : }
2110 : :
2111 : : /* Build a newly constructed VECTOR_CST with the given values of
2112 : : (VECTOR_CST_)LOG2_NPATTERNS and (VECTOR_CST_)NELTS_PER_PATTERN. */
2113 : :
2114 : : tree
2115 : 3194226 : make_vector (unsigned log2_npatterns,
2116 : : unsigned int nelts_per_pattern MEM_STAT_DECL)
2117 : : {
2118 : 3194226 : gcc_assert (IN_RANGE (nelts_per_pattern, 1, 3));
2119 : 3194226 : tree t;
2120 : 3194226 : unsigned npatterns = 1 << log2_npatterns;
2121 : 3194226 : unsigned encoded_nelts = npatterns * nelts_per_pattern;
2122 : 3194226 : unsigned length = (sizeof (struct tree_vector)
2123 : : + (encoded_nelts - 1) * sizeof (tree));
2124 : :
2125 : 3194226 : record_node_allocation_statistics (VECTOR_CST, length);
2126 : :
2127 : 3194226 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2128 : :
2129 : 3194226 : TREE_SET_CODE (t, VECTOR_CST);
2130 : 3194226 : TREE_CONSTANT (t) = 1;
2131 : 3194226 : VECTOR_CST_LOG2_NPATTERNS (t) = log2_npatterns;
2132 : 3194226 : VECTOR_CST_NELTS_PER_PATTERN (t) = nelts_per_pattern;
2133 : :
2134 : 3194226 : return t;
2135 : : }
2136 : :
2137 : : /* Return a new VECTOR_CST node whose type is TYPE and whose values
2138 : : are extracted from V, a vector of CONSTRUCTOR_ELT. */
2139 : :
2140 : : tree
2141 : 655851 : build_vector_from_ctor (tree type, const vec<constructor_elt, va_gc> *v)
2142 : : {
2143 : 655851 : if (vec_safe_length (v) == 0)
2144 : 684 : return build_zero_cst (type);
2145 : :
2146 : 655167 : unsigned HOST_WIDE_INT idx, nelts, step = 1;
2147 : 655167 : tree value;
2148 : :
2149 : : /* If the vector is a VLA, build a VLA constant vector. */
2150 : 655167 : if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&nelts))
2151 : : {
2152 : : nelts = constant_lower_bound (TYPE_VECTOR_SUBPARTS (type));
2153 : : gcc_assert (vec_safe_length (v) <= nelts);
2154 : : step = 2;
2155 : : }
2156 : :
2157 : 655167 : tree_vector_builder vec (type, nelts, step);
2158 : 4356624 : FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
2159 : : {
2160 : 3701457 : if (TREE_CODE (value) == VECTOR_CST)
2161 : : {
2162 : : /* If NELTS is constant then this must be too. */
2163 : 360 : unsigned int sub_nelts = VECTOR_CST_NELTS (value).to_constant ();
2164 : 1400 : for (unsigned i = 0; i < sub_nelts; ++i)
2165 : 1040 : vec.quick_push (VECTOR_CST_ELT (value, i));
2166 : : }
2167 : : else
2168 : 3701097 : vec.quick_push (value);
2169 : : }
2170 : 1851998 : while (vec.length () < nelts * step)
2171 : 270832 : vec.quick_push (build_zero_cst (TREE_TYPE (type)));
2172 : :
2173 : 655167 : return vec.build ();
2174 : 655167 : }
2175 : :
2176 : : /* Build a vector of type VECTYPE where all the elements are SCs. */
2177 : : tree
2178 : 663116 : build_vector_from_val (tree vectype, tree sc)
2179 : : {
2180 : 663116 : unsigned HOST_WIDE_INT i, nunits;
2181 : :
2182 : 663116 : if (sc == error_mark_node)
2183 : : return sc;
2184 : :
2185 : : /* Verify that the vector type is suitable for SC. Note that there
2186 : : is some inconsistency in the type-system with respect to restrict
2187 : : qualifications of pointers. Vector types always have a main-variant
2188 : : element type and the qualification is applied to the vector-type.
2189 : : So TREE_TYPE (vector-type) does not return a properly qualified
2190 : : vector element-type. */
2191 : 663116 : gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
2192 : : TREE_TYPE (vectype)));
2193 : :
2194 : 663116 : if (CONSTANT_CLASS_P (sc))
2195 : : {
2196 : 635159 : tree_vector_builder v (vectype, 1, 1);
2197 : 635159 : v.quick_push (sc);
2198 : 635159 : return v.build ();
2199 : 635159 : }
2200 : 27957 : else if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
2201 : : return fold_build1 (VEC_DUPLICATE_EXPR, vectype, sc);
2202 : : else
2203 : : {
2204 : 27957 : vec<constructor_elt, va_gc> *v;
2205 : 27957 : vec_alloc (v, nunits);
2206 : 128940 : for (i = 0; i < nunits; ++i)
2207 : 100983 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
2208 : 27957 : return build_constructor (vectype, v);
2209 : : }
2210 : : }
2211 : :
2212 : : /* If TYPE is not a vector type, just return SC, otherwise return
2213 : : build_vector_from_val (TYPE, SC). */
2214 : :
2215 : : tree
2216 : 5005410 : build_uniform_cst (tree type, tree sc)
2217 : : {
2218 : 5005410 : if (!VECTOR_TYPE_P (type))
2219 : : return sc;
2220 : :
2221 : 241 : return build_vector_from_val (type, sc);
2222 : : }
2223 : :
2224 : : /* Build a vector series of type TYPE in which element I has the value
2225 : : BASE + I * STEP. The result is a constant if BASE and STEP are constant
2226 : : and a VEC_SERIES_EXPR otherwise. */
2227 : :
2228 : : tree
2229 : 18 : build_vec_series (tree type, tree base, tree step)
2230 : : {
2231 : 18 : if (integer_zerop (step))
2232 : 0 : return build_vector_from_val (type, base);
2233 : 18 : if (TREE_CODE (base) == INTEGER_CST && TREE_CODE (step) == INTEGER_CST)
2234 : : {
2235 : 18 : tree_vector_builder builder (type, 1, 3);
2236 : 18 : tree elt1 = wide_int_to_tree (TREE_TYPE (base),
2237 : 36 : wi::to_wide (base) + wi::to_wide (step));
2238 : 18 : tree elt2 = wide_int_to_tree (TREE_TYPE (base),
2239 : 36 : wi::to_wide (elt1) + wi::to_wide (step));
2240 : 18 : builder.quick_push (base);
2241 : 18 : builder.quick_push (elt1);
2242 : 18 : builder.quick_push (elt2);
2243 : 18 : return builder.build ();
2244 : 18 : }
2245 : 0 : return build2 (VEC_SERIES_EXPR, type, base, step);
2246 : : }
2247 : :
2248 : : /* Return a vector with the same number of units and number of bits
2249 : : as VEC_TYPE, but in which the elements are a linear series of unsigned
2250 : : integers { BASE, BASE + STEP, BASE + STEP * 2, ... }. */
2251 : :
2252 : : tree
2253 : 1776 : build_index_vector (tree vec_type, poly_uint64 base, poly_uint64 step)
2254 : : {
2255 : 1776 : tree index_vec_type = vec_type;
2256 : 1776 : tree index_elt_type = TREE_TYPE (vec_type);
2257 : 1776 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vec_type);
2258 : 1776 : if (!INTEGRAL_TYPE_P (index_elt_type) || !TYPE_UNSIGNED (index_elt_type))
2259 : : {
2260 : 4 : index_elt_type = build_nonstandard_integer_type
2261 : 8 : (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (index_elt_type)), true);
2262 : 4 : index_vec_type = build_vector_type (index_elt_type, nunits);
2263 : : }
2264 : :
2265 : 1776 : tree_vector_builder v (index_vec_type, 1, 3);
2266 : 7104 : for (unsigned int i = 0; i < 3; ++i)
2267 : 5328 : v.quick_push (build_int_cstu (index_elt_type, base + i * step));
2268 : 1776 : return v.build ();
2269 : 1776 : }
2270 : :
2271 : : /* Return a VECTOR_CST of type VEC_TYPE in which the first NUM_A
2272 : : elements are A and the rest are B. */
2273 : :
2274 : : tree
2275 : 0 : build_vector_a_then_b (tree vec_type, unsigned int num_a, tree a, tree b)
2276 : : {
2277 : 0 : gcc_assert (known_le (num_a, TYPE_VECTOR_SUBPARTS (vec_type)));
2278 : 0 : unsigned int count = constant_lower_bound (TYPE_VECTOR_SUBPARTS (vec_type));
2279 : : /* Optimize the constant case. */
2280 : 0 : if ((count & 1) == 0 && TYPE_VECTOR_SUBPARTS (vec_type).is_constant ())
2281 : 0 : count /= 2;
2282 : 0 : tree_vector_builder builder (vec_type, count, 2);
2283 : 0 : for (unsigned int i = 0; i < count * 2; ++i)
2284 : 0 : builder.quick_push (i < num_a ? a : b);
2285 : 0 : return builder.build ();
2286 : 0 : }
2287 : :
2288 : : /* Something has messed with the elements of CONSTRUCTOR C after it was built;
2289 : : calculate TREE_CONSTANT and TREE_SIDE_EFFECTS. */
2290 : :
2291 : : void
2292 : 86451650 : recompute_constructor_flags (tree c)
2293 : : {
2294 : 86451650 : unsigned int i;
2295 : 86451650 : tree val;
2296 : 86451650 : bool constant_p = true;
2297 : 86451650 : bool side_effects_p = false;
2298 : 86451650 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2299 : :
2300 : 189794048 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2301 : : {
2302 : : /* Mostly ctors will have elts that don't have side-effects, so
2303 : : the usual case is to scan all the elements. Hence a single
2304 : : loop for both const and side effects, rather than one loop
2305 : : each (with early outs). */
2306 : 103342398 : if (!TREE_CONSTANT (val))
2307 : 15072060 : constant_p = false;
2308 : 103342398 : if (TREE_SIDE_EFFECTS (val))
2309 : 2996358 : side_effects_p = true;
2310 : : }
2311 : :
2312 : 86451650 : TREE_SIDE_EFFECTS (c) = side_effects_p;
2313 : 86451650 : TREE_CONSTANT (c) = constant_p;
2314 : 86451650 : }
2315 : :
2316 : : /* Make sure that TREE_CONSTANT and TREE_SIDE_EFFECTS are correct for
2317 : : CONSTRUCTOR C. */
2318 : :
2319 : : void
2320 : 11475295 : verify_constructor_flags (tree c)
2321 : : {
2322 : 11475295 : unsigned int i;
2323 : 11475295 : tree val;
2324 : 11475295 : bool constant_p = TREE_CONSTANT (c);
2325 : 11475295 : bool side_effects_p = TREE_SIDE_EFFECTS (c);
2326 : 11475295 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2327 : :
2328 : 59650560 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2329 : : {
2330 : 48175265 : if (constant_p && !TREE_CONSTANT (val))
2331 : 0 : internal_error ("non-constant element in constant CONSTRUCTOR");
2332 : 48175265 : if (!side_effects_p && TREE_SIDE_EFFECTS (val))
2333 : 0 : internal_error ("side-effects element in no-side-effects CONSTRUCTOR");
2334 : : }
2335 : 11475295 : }
2336 : :
2337 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2338 : : are in the vec pointed to by VALS. */
2339 : : tree
2340 : 71868580 : build_constructor (tree type, vec<constructor_elt, va_gc> *vals MEM_STAT_DECL)
2341 : : {
2342 : 71868580 : tree c = make_node (CONSTRUCTOR PASS_MEM_STAT);
2343 : :
2344 : 71868580 : TREE_TYPE (c) = type;
2345 : 71868580 : CONSTRUCTOR_ELTS (c) = vals;
2346 : :
2347 : 71868580 : recompute_constructor_flags (c);
2348 : :
2349 : 71868580 : return c;
2350 : : }
2351 : :
2352 : : /* Build a CONSTRUCTOR node made of a single initializer, with the specified
2353 : : INDEX and VALUE. */
2354 : : tree
2355 : 3628 : build_constructor_single (tree type, tree index, tree value)
2356 : : {
2357 : 3628 : vec<constructor_elt, va_gc> *v;
2358 : 3628 : constructor_elt elt = {index, value};
2359 : :
2360 : 3628 : vec_alloc (v, 1);
2361 : 3628 : v->quick_push (elt);
2362 : :
2363 : 3628 : return build_constructor (type, v);
2364 : : }
2365 : :
2366 : :
2367 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2368 : : are in a list pointed to by VALS. */
2369 : : tree
2370 : 5612 : build_constructor_from_list (tree type, tree vals)
2371 : : {
2372 : 5612 : tree t;
2373 : 5612 : vec<constructor_elt, va_gc> *v = NULL;
2374 : :
2375 : 5612 : if (vals)
2376 : : {
2377 : 5612 : vec_alloc (v, list_length (vals));
2378 : 54503 : for (t = vals; t; t = TREE_CHAIN (t))
2379 : 48891 : CONSTRUCTOR_APPEND_ELT (v, TREE_PURPOSE (t), TREE_VALUE (t));
2380 : : }
2381 : :
2382 : 5612 : return build_constructor (type, v);
2383 : : }
2384 : :
2385 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2386 : : are in a vector pointed to by VALS. Note that the TREE_PURPOSE
2387 : : fields in the constructor remain null. */
2388 : :
2389 : : tree
2390 : 1360 : build_constructor_from_vec (tree type, const vec<tree, va_gc> *vals)
2391 : : {
2392 : 1360 : vec<constructor_elt, va_gc> *v = NULL;
2393 : :
2394 : 71108 : for (tree t : vals)
2395 : 69748 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t);
2396 : :
2397 : 1360 : return build_constructor (type, v);
2398 : : }
2399 : :
2400 : : /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
2401 : : of elements, provided as index/value pairs. */
2402 : :
2403 : : tree
2404 : 37460 : build_constructor_va (tree type, int nelts, ...)
2405 : : {
2406 : 37460 : vec<constructor_elt, va_gc> *v = NULL;
2407 : 37460 : va_list p;
2408 : :
2409 : 37460 : va_start (p, nelts);
2410 : 37460 : vec_alloc (v, nelts);
2411 : 37460 : while (nelts--)
2412 : : {
2413 : 112577 : tree index = va_arg (p, tree);
2414 : 112577 : tree value = va_arg (p, tree);
2415 : 262614 : CONSTRUCTOR_APPEND_ELT (v, index, value);
2416 : : }
2417 : 37460 : va_end (p);
2418 : 37460 : return build_constructor (type, v);
2419 : : }
2420 : :
2421 : : /* Return a node of type TYPE for which TREE_CLOBBER_P is true. */
2422 : :
2423 : : tree
2424 : 11764067 : build_clobber (tree type, enum clobber_kind kind)
2425 : : {
2426 : 11764067 : tree clobber = build_constructor (type, NULL);
2427 : 11764067 : TREE_THIS_VOLATILE (clobber) = true;
2428 : 11764067 : CLOBBER_KIND (clobber) = kind;
2429 : 11764067 : return clobber;
2430 : : }
2431 : :
2432 : : /* Return a new FIXED_CST node whose type is TYPE and value is F. */
2433 : :
2434 : : tree
2435 : 54 : build_fixed (tree type, FIXED_VALUE_TYPE f)
2436 : : {
2437 : 54 : tree v;
2438 : 54 : FIXED_VALUE_TYPE *fp;
2439 : :
2440 : 54 : v = make_node (FIXED_CST);
2441 : 54 : fp = ggc_alloc<fixed_value> ();
2442 : 54 : memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
2443 : :
2444 : 54 : TREE_TYPE (v) = type;
2445 : 54 : TREE_FIXED_CST_PTR (v) = fp;
2446 : 54 : return v;
2447 : : }
2448 : :
2449 : : /* Return a new REAL_CST node whose type is TYPE and value is D. */
2450 : :
2451 : : tree
2452 : 41814284 : build_real (tree type, REAL_VALUE_TYPE d)
2453 : : {
2454 : 41814284 : tree v;
2455 : 41814284 : int overflow = 0;
2456 : :
2457 : : /* dconst{0,1,2,m1,half} are used in various places in
2458 : : the middle-end and optimizers, allow them here
2459 : : even for decimal floating point types as an exception
2460 : : by converting them to decimal. */
2461 : 41814284 : if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type))
2462 : 610437 : && (d.cl == rvc_normal || d.cl == rvc_zero)
2463 : 42422675 : && !d.decimal)
2464 : : {
2465 : 715 : if (memcmp (&d, &dconst1, sizeof (d)) == 0)
2466 : 0 : decimal_real_from_string (&d, "1");
2467 : 715 : else if (memcmp (&d, &dconst2, sizeof (d)) == 0)
2468 : 22 : decimal_real_from_string (&d, "2");
2469 : 693 : else if (memcmp (&d, &dconstm1, sizeof (d)) == 0)
2470 : 90 : decimal_real_from_string (&d, "-1");
2471 : 603 : else if (memcmp (&d, &dconsthalf, sizeof (d)) == 0)
2472 : 0 : decimal_real_from_string (&d, "0.5");
2473 : 603 : else if (memcmp (&d, &dconst0, sizeof (d)) == 0)
2474 : : {
2475 : : /* Make sure to give zero the minimum quantum exponent for
2476 : : the type (which corresponds to all bits zero). */
2477 : 603 : const struct real_format *fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
2478 : 603 : char buf[16];
2479 : 603 : sprintf (buf, "0e%d", fmt->emin - fmt->p);
2480 : 603 : decimal_real_from_string (&d, buf);
2481 : : }
2482 : : else
2483 : 0 : gcc_unreachable ();
2484 : : }
2485 : :
2486 : : /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
2487 : : Consider doing it via real_convert now. */
2488 : :
2489 : 41814284 : v = make_node (REAL_CST);
2490 : 41814284 : TREE_TYPE (v) = type;
2491 : 41814284 : memcpy (TREE_REAL_CST_PTR (v), &d, sizeof (REAL_VALUE_TYPE));
2492 : 41814284 : TREE_OVERFLOW (v) = overflow;
2493 : 41814284 : return v;
2494 : : }
2495 : :
2496 : : /* Like build_real, but first truncate D to the type. */
2497 : :
2498 : : tree
2499 : 176305 : build_real_truncate (tree type, REAL_VALUE_TYPE d)
2500 : : {
2501 : 176305 : return build_real (type, real_value_truncate (TYPE_MODE (type), d));
2502 : : }
2503 : :
2504 : : /* Return a new REAL_CST node whose type is TYPE
2505 : : and whose value is the integer value of the INTEGER_CST node I. */
2506 : :
2507 : : REAL_VALUE_TYPE
2508 : 24471889 : real_value_from_int_cst (const_tree type, const_tree i)
2509 : : {
2510 : 24471889 : REAL_VALUE_TYPE d;
2511 : :
2512 : : /* Clear all bits of the real value type so that we can later do
2513 : : bitwise comparisons to see if two values are the same. */
2514 : 24471889 : memset (&d, 0, sizeof d);
2515 : :
2516 : 24471889 : real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, wi::to_wide (i),
2517 : 24471889 : TYPE_SIGN (TREE_TYPE (i)));
2518 : 24471889 : return d;
2519 : : }
2520 : :
2521 : : /* Given a tree representing an integer constant I, return a tree
2522 : : representing the same value as a floating-point constant of type TYPE. */
2523 : :
2524 : : tree
2525 : 23882177 : build_real_from_int_cst (tree type, const_tree i)
2526 : : {
2527 : 23882177 : tree v;
2528 : 23882177 : int overflow = TREE_OVERFLOW (i);
2529 : :
2530 : 23882177 : v = build_real (type, real_value_from_int_cst (type, i));
2531 : :
2532 : 23882177 : TREE_OVERFLOW (v) |= overflow;
2533 : 23882177 : return v;
2534 : : }
2535 : :
2536 : : /* Return a new REAL_CST node whose type is TYPE
2537 : : and whose value is the integer value I which has sign SGN. */
2538 : :
2539 : : tree
2540 : 129 : build_real_from_wide (tree type, const wide_int_ref &i, signop sgn)
2541 : : {
2542 : 129 : REAL_VALUE_TYPE d;
2543 : :
2544 : : /* Clear all bits of the real value type so that we can later do
2545 : : bitwise comparisons to see if two values are the same. */
2546 : 129 : memset (&d, 0, sizeof d);
2547 : :
2548 : 129 : real_from_integer (&d, TYPE_MODE (type), i, sgn);
2549 : 129 : return build_real (type, d);
2550 : : }
2551 : :
2552 : : /* Return a newly constructed STRING_CST node whose value is the LEN
2553 : : characters at STR when STR is nonnull, or all zeros otherwise.
2554 : : Note that for a C string literal, LEN should include the trailing NUL.
2555 : : The TREE_TYPE is not initialized. */
2556 : :
2557 : : tree
2558 : 89962778 : build_string (unsigned len, const char *str /*= NULL */)
2559 : : {
2560 : : /* Do not waste bytes provided by padding of struct tree_string. */
2561 : 89962778 : unsigned size = len + offsetof (struct tree_string, str) + 1;
2562 : :
2563 : 89962778 : record_node_allocation_statistics (STRING_CST, size);
2564 : :
2565 : 89962778 : tree s = (tree) ggc_internal_alloc (size);
2566 : :
2567 : 89962778 : memset (s, 0, sizeof (struct tree_typed));
2568 : 89962778 : TREE_SET_CODE (s, STRING_CST);
2569 : 89962778 : TREE_CONSTANT (s) = 1;
2570 : 89962778 : TREE_STRING_LENGTH (s) = len;
2571 : 89962778 : if (str)
2572 : 89953601 : memcpy (s->string.str, str, len);
2573 : : else
2574 : 9177 : memset (s->string.str, 0, len);
2575 : 89962778 : s->string.str[len] = '\0';
2576 : :
2577 : 89962778 : return s;
2578 : : }
2579 : :
2580 : : /* Return a newly constructed COMPLEX_CST node whose value is
2581 : : specified by the real and imaginary parts REAL and IMAG.
2582 : : Both REAL and IMAG should be constant nodes. TYPE, if specified,
2583 : : will be the type of the COMPLEX_CST; otherwise a new type will be made. */
2584 : :
2585 : : tree
2586 : 484987 : build_complex (tree type, tree real, tree imag)
2587 : : {
2588 : 484987 : gcc_assert (CONSTANT_CLASS_P (real));
2589 : 484987 : gcc_assert (CONSTANT_CLASS_P (imag));
2590 : :
2591 : 484987 : tree t = make_node (COMPLEX_CST);
2592 : :
2593 : 484987 : TREE_REALPART (t) = real;
2594 : 484987 : TREE_IMAGPART (t) = imag;
2595 : 484987 : TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
2596 : 484987 : TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
2597 : 484987 : return t;
2598 : : }
2599 : :
2600 : : /* Build a complex (inf +- 0i), such as for the result of cproj.
2601 : : TYPE is the complex tree type of the result. If NEG is true, the
2602 : : imaginary zero is negative. */
2603 : :
2604 : : tree
2605 : 840 : build_complex_inf (tree type, bool neg)
2606 : : {
2607 : 840 : REAL_VALUE_TYPE rzero = dconst0;
2608 : :
2609 : 840 : rzero.sign = neg;
2610 : 840 : return build_complex (type, build_real (TREE_TYPE (type), dconstinf),
2611 : 840 : build_real (TREE_TYPE (type), rzero));
2612 : : }
2613 : :
2614 : : /* Return the constant 1 in type TYPE. If TYPE has several elements, each
2615 : : element is set to 1. In particular, this is 1 + i for complex types. */
2616 : :
2617 : : tree
2618 : 3965 : build_each_one_cst (tree type)
2619 : : {
2620 : 3965 : if (TREE_CODE (type) == COMPLEX_TYPE)
2621 : : {
2622 : 0 : tree scalar = build_one_cst (TREE_TYPE (type));
2623 : 0 : return build_complex (type, scalar, scalar);
2624 : : }
2625 : : else
2626 : 3965 : return build_one_cst (type);
2627 : : }
2628 : :
2629 : : /* Return a constant of arithmetic type TYPE which is the
2630 : : multiplicative identity of the set TYPE. */
2631 : :
2632 : : tree
2633 : 9225454 : build_one_cst (tree type)
2634 : : {
2635 : 9225454 : switch (TREE_CODE (type))
2636 : : {
2637 : 9211625 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2638 : 9211625 : case POINTER_TYPE: case REFERENCE_TYPE:
2639 : 9211625 : case OFFSET_TYPE: case BITINT_TYPE:
2640 : 9211625 : return build_int_cst (type, 1);
2641 : :
2642 : 10487 : case REAL_TYPE:
2643 : 10487 : return build_real (type, dconst1);
2644 : :
2645 : 0 : case FIXED_POINT_TYPE:
2646 : : /* We can only generate 1 for accum types. */
2647 : 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2648 : 0 : return build_fixed (type, FCONST1 (TYPE_MODE (type)));
2649 : :
2650 : 339 : case VECTOR_TYPE:
2651 : 339 : {
2652 : 339 : tree scalar = build_one_cst (TREE_TYPE (type));
2653 : :
2654 : 339 : return build_vector_from_val (type, scalar);
2655 : : }
2656 : :
2657 : 3003 : case COMPLEX_TYPE:
2658 : 6006 : return build_complex (type,
2659 : 3003 : build_one_cst (TREE_TYPE (type)),
2660 : 6006 : build_zero_cst (TREE_TYPE (type)));
2661 : :
2662 : 0 : default:
2663 : 0 : gcc_unreachable ();
2664 : : }
2665 : : }
2666 : :
2667 : : /* Return an integer of type TYPE containing all 1's in as much precision as
2668 : : it contains, or a complex or vector whose subparts are such integers. */
2669 : :
2670 : : tree
2671 : 1808697 : build_all_ones_cst (tree type)
2672 : : {
2673 : 1808697 : if (TREE_CODE (type) == COMPLEX_TYPE)
2674 : : {
2675 : 0 : tree scalar = build_all_ones_cst (TREE_TYPE (type));
2676 : 0 : return build_complex (type, scalar, scalar);
2677 : : }
2678 : : else
2679 : 1808697 : return build_minus_one_cst (type);
2680 : : }
2681 : :
2682 : : /* Return a constant of arithmetic type TYPE which is the
2683 : : opposite of the multiplicative identity of the set TYPE. */
2684 : :
2685 : : tree
2686 : 2468922 : build_minus_one_cst (tree type)
2687 : : {
2688 : 2468922 : switch (TREE_CODE (type))
2689 : : {
2690 : 2353652 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2691 : 2353652 : case POINTER_TYPE: case REFERENCE_TYPE:
2692 : 2353652 : case OFFSET_TYPE: case BITINT_TYPE:
2693 : 2353652 : return build_int_cst (type, -1);
2694 : :
2695 : 9786 : case REAL_TYPE:
2696 : 9786 : return build_real (type, dconstm1);
2697 : :
2698 : 0 : case FIXED_POINT_TYPE:
2699 : : /* We can only generate 1 for accum types. */
2700 : 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2701 : 0 : return build_fixed (type,
2702 : : fixed_from_double_int (double_int_minus_one,
2703 : 0 : SCALAR_TYPE_MODE (type)));
2704 : :
2705 : 105484 : case VECTOR_TYPE:
2706 : 105484 : {
2707 : 105484 : tree scalar = build_minus_one_cst (TREE_TYPE (type));
2708 : :
2709 : 105484 : return build_vector_from_val (type, scalar);
2710 : : }
2711 : :
2712 : 0 : case COMPLEX_TYPE:
2713 : 0 : return build_complex (type,
2714 : 0 : build_minus_one_cst (TREE_TYPE (type)),
2715 : 0 : build_zero_cst (TREE_TYPE (type)));
2716 : :
2717 : 0 : default:
2718 : 0 : gcc_unreachable ();
2719 : : }
2720 : : }
2721 : :
2722 : : /* Build 0 constant of type TYPE. This is used by constructor folding
2723 : : and thus the constant should be represented in memory by
2724 : : zero(es). */
2725 : :
2726 : : tree
2727 : 78858406 : build_zero_cst (tree type)
2728 : : {
2729 : 78858406 : switch (TREE_CODE (type))
2730 : : {
2731 : 78233528 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2732 : 78233528 : case POINTER_TYPE: case REFERENCE_TYPE:
2733 : 78233528 : case OFFSET_TYPE: case NULLPTR_TYPE: case BITINT_TYPE:
2734 : 78233528 : return build_int_cst (type, 0);
2735 : :
2736 : 226261 : case REAL_TYPE:
2737 : 226261 : return build_real (type, dconst0);
2738 : :
2739 : 0 : case FIXED_POINT_TYPE:
2740 : 0 : return build_fixed (type, FCONST0 (TYPE_MODE (type)));
2741 : :
2742 : 208923 : case VECTOR_TYPE:
2743 : 208923 : {
2744 : 208923 : tree scalar = build_zero_cst (TREE_TYPE (type));
2745 : :
2746 : 208923 : return build_vector_from_val (type, scalar);
2747 : : }
2748 : :
2749 : 3574 : case COMPLEX_TYPE:
2750 : 3574 : {
2751 : 3574 : tree zero = build_zero_cst (TREE_TYPE (type));
2752 : :
2753 : 3574 : return build_complex (type, zero, zero);
2754 : : }
2755 : :
2756 : 186120 : default:
2757 : 186120 : if (!AGGREGATE_TYPE_P (type))
2758 : 1 : return fold_convert (type, integer_zero_node);
2759 : 186119 : return build_constructor (type, NULL);
2760 : : }
2761 : : }
2762 : :
2763 : : /* Build a constant of integer type TYPE, made of VALUE's bits replicated
2764 : : every WIDTH bits to fit TYPE's precision. */
2765 : :
2766 : : tree
2767 : 14 : build_replicated_int_cst (tree type, unsigned int width, HOST_WIDE_INT value)
2768 : : {
2769 : 14 : int n = ((TYPE_PRECISION (type) + HOST_BITS_PER_WIDE_INT - 1)
2770 : 14 : / HOST_BITS_PER_WIDE_INT);
2771 : 14 : unsigned HOST_WIDE_INT low, mask;
2772 : 14 : HOST_WIDE_INT a[WIDE_INT_MAX_INL_ELTS];
2773 : 14 : int i;
2774 : :
2775 : 14 : gcc_assert (n && n <= WIDE_INT_MAX_INL_ELTS);
2776 : :
2777 : 14 : if (width == HOST_BITS_PER_WIDE_INT)
2778 : 0 : low = value;
2779 : : else
2780 : : {
2781 : 14 : mask = (HOST_WIDE_INT_1U << width) - 1;
2782 : 14 : low = (unsigned HOST_WIDE_INT) ~0 / mask * (value & mask);
2783 : : }
2784 : :
2785 : 28 : for (i = 0; i < n; i++)
2786 : 14 : a[i] = low;
2787 : :
2788 : 14 : gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
2789 : 14 : return wide_int_to_tree (type, wide_int::from_array (a, n,
2790 : 14 : TYPE_PRECISION (type)));
2791 : : }
2792 : :
2793 : : /* If floating-point type TYPE has an IEEE-style sign bit, return an
2794 : : unsigned constant in which only the sign bit is set. Return null
2795 : : otherwise. */
2796 : :
2797 : : tree
2798 : 0 : sign_mask_for (tree type)
2799 : : {
2800 : : /* Avoid having to choose between a real-only sign and a pair of signs.
2801 : : This could be relaxed if the choice becomes obvious later. */
2802 : 0 : if (TREE_CODE (type) == COMPLEX_TYPE)
2803 : : return NULL_TREE;
2804 : :
2805 : 0 : auto eltmode = as_a<scalar_float_mode> (element_mode (type));
2806 : 0 : auto bits = REAL_MODE_FORMAT (eltmode)->ieee_bits;
2807 : 0 : if (!bits || !pow2p_hwi (bits))
2808 : : return NULL_TREE;
2809 : :
2810 : 0 : tree inttype = unsigned_type_for (type);
2811 : 0 : if (!inttype)
2812 : : return NULL_TREE;
2813 : :
2814 : 0 : auto mask = wi::set_bit_in_zero (bits - 1, bits);
2815 : 0 : if (VECTOR_TYPE_P (inttype))
2816 : : {
2817 : 0 : tree elt = wide_int_to_tree (TREE_TYPE (inttype), mask);
2818 : 0 : return build_vector_from_val (inttype, elt);
2819 : : }
2820 : 0 : return wide_int_to_tree (inttype, mask);
2821 : 0 : }
2822 : :
2823 : : /* Build a BINFO with LEN language slots. */
2824 : :
2825 : : tree
2826 : 85265558 : make_tree_binfo (unsigned base_binfos MEM_STAT_DECL)
2827 : : {
2828 : 85265558 : tree t;
2829 : 85265558 : size_t length = (offsetof (struct tree_binfo, base_binfos)
2830 : 85265558 : + vec<tree, va_gc>::embedded_size (base_binfos));
2831 : :
2832 : 85265558 : record_node_allocation_statistics (TREE_BINFO, length);
2833 : :
2834 : 85265558 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
2835 : :
2836 : 85265558 : memset (t, 0, offsetof (struct tree_binfo, base_binfos));
2837 : :
2838 : 85265558 : TREE_SET_CODE (t, TREE_BINFO);
2839 : :
2840 : 85265558 : BINFO_BASE_BINFOS (t)->embedded_init (base_binfos);
2841 : :
2842 : 85265558 : return t;
2843 : : }
2844 : :
2845 : : /* Create a CASE_LABEL_EXPR tree node and return it. */
2846 : :
2847 : : tree
2848 : 4668293 : build_case_label (tree low_value, tree high_value, tree label_decl)
2849 : : {
2850 : 4668293 : tree t = make_node (CASE_LABEL_EXPR);
2851 : :
2852 : 4668293 : TREE_TYPE (t) = void_type_node;
2853 : 4668293 : SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (label_decl));
2854 : :
2855 : 4668293 : CASE_LOW (t) = low_value;
2856 : 4668293 : CASE_HIGH (t) = high_value;
2857 : 4668293 : CASE_LABEL (t) = label_decl;
2858 : 4668293 : CASE_CHAIN (t) = NULL_TREE;
2859 : :
2860 : 4668293 : return t;
2861 : : }
2862 : :
2863 : : /* Build a newly constructed INTEGER_CST node. LEN and EXT_LEN are the
2864 : : values of TREE_INT_CST_NUNITS and TREE_INT_CST_EXT_NUNITS respectively.
2865 : : The latter determines the length of the HOST_WIDE_INT vector. */
2866 : :
2867 : : tree
2868 : 183504502 : make_int_cst (int len, int ext_len MEM_STAT_DECL)
2869 : : {
2870 : 183504502 : tree t;
2871 : 183504502 : int length = ((ext_len - 1) * sizeof (HOST_WIDE_INT)
2872 : 183504502 : + sizeof (struct tree_int_cst));
2873 : :
2874 : 183504502 : gcc_assert (len);
2875 : 183504502 : record_node_allocation_statistics (INTEGER_CST, length);
2876 : :
2877 : 183504502 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2878 : :
2879 : 183504502 : TREE_SET_CODE (t, INTEGER_CST);
2880 : 183504502 : TREE_INT_CST_NUNITS (t) = len;
2881 : 183504502 : TREE_INT_CST_EXT_NUNITS (t) = ext_len;
2882 : 183504502 : TREE_CONSTANT (t) = 1;
2883 : :
2884 : 183504502 : return t;
2885 : : }
2886 : :
2887 : : /* Build a newly constructed TREE_VEC node of length LEN. */
2888 : :
2889 : : tree
2890 : 2344671321 : make_tree_vec (int len MEM_STAT_DECL)
2891 : : {
2892 : 2344671321 : tree t;
2893 : 2344671321 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2894 : :
2895 : 2344671321 : record_node_allocation_statistics (TREE_VEC, length);
2896 : :
2897 : 2344671321 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2898 : :
2899 : 2344671321 : TREE_SET_CODE (t, TREE_VEC);
2900 : 2344671321 : TREE_VEC_LENGTH (t) = len;
2901 : :
2902 : 2344671321 : return t;
2903 : : }
2904 : :
2905 : : /* Grow a TREE_VEC node to new length LEN. */
2906 : :
2907 : : tree
2908 : 136085 : grow_tree_vec (tree v, int len MEM_STAT_DECL)
2909 : : {
2910 : 136085 : gcc_assert (TREE_CODE (v) == TREE_VEC);
2911 : :
2912 : 136085 : int oldlen = TREE_VEC_LENGTH (v);
2913 : 136085 : gcc_assert (len > oldlen);
2914 : :
2915 : 136085 : size_t oldlength = (oldlen - 1) * sizeof (tree) + sizeof (struct tree_vec);
2916 : 136085 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2917 : :
2918 : 136085 : record_node_allocation_statistics (TREE_VEC, length - oldlength);
2919 : :
2920 : 136085 : v = (tree) ggc_realloc (v, length PASS_MEM_STAT);
2921 : :
2922 : 136085 : TREE_VEC_LENGTH (v) = len;
2923 : :
2924 : 136085 : return v;
2925 : : }
2926 : :
2927 : : /* Return true if EXPR is the constant zero, whether it is integral, float or
2928 : : fixed, and scalar, complex or vector. */
2929 : :
2930 : : bool
2931 : 16065337 : zerop (const_tree expr)
2932 : : {
2933 : 16065337 : return (integer_zerop (expr)
2934 : 10953554 : || real_zerop (expr)
2935 : 26617345 : || fixed_zerop (expr));
2936 : : }
2937 : :
2938 : : /* Return true if EXPR is the integer constant zero or a complex constant
2939 : : of zero, or a location wrapper for such a constant. */
2940 : :
2941 : : bool
2942 : 5331937970 : integer_zerop (const_tree expr)
2943 : : {
2944 : 5331937970 : STRIP_ANY_LOCATION_WRAPPER (expr);
2945 : :
2946 : 5331937970 : switch (TREE_CODE (expr))
2947 : : {
2948 : 4474466366 : case INTEGER_CST:
2949 : 4474466366 : return wi::to_wide (expr) == 0;
2950 : 1195289 : case COMPLEX_CST:
2951 : 1195289 : return (integer_zerop (TREE_REALPART (expr))
2952 : 1217185 : && integer_zerop (TREE_IMAGPART (expr)));
2953 : 1976486 : case VECTOR_CST:
2954 : 1976486 : return (VECTOR_CST_NPATTERNS (expr) == 1
2955 : 1905135 : && VECTOR_CST_DUPLICATE_P (expr)
2956 : 3669784 : && integer_zerop (VECTOR_CST_ENCODED_ELT (expr, 0)));
2957 : : default:
2958 : : return false;
2959 : : }
2960 : : }
2961 : :
2962 : : /* Return true if EXPR is the integer constant one or the corresponding
2963 : : complex constant, or a location wrapper for such a constant. */
2964 : :
2965 : : bool
2966 : 889323363 : integer_onep (const_tree expr)
2967 : : {
2968 : 889323363 : STRIP_ANY_LOCATION_WRAPPER (expr);
2969 : :
2970 : 889323363 : switch (TREE_CODE (expr))
2971 : : {
2972 : 757845781 : case INTEGER_CST:
2973 : 757845781 : return wi::eq_p (wi::to_widest (expr), 1);
2974 : 21346 : case COMPLEX_CST:
2975 : 21346 : return (integer_onep (TREE_REALPART (expr))
2976 : 21366 : && integer_zerop (TREE_IMAGPART (expr)));
2977 : 131889 : case VECTOR_CST:
2978 : 131889 : return (VECTOR_CST_NPATTERNS (expr) == 1
2979 : 117100 : && VECTOR_CST_DUPLICATE_P (expr)
2980 : 238091 : && integer_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
2981 : : default:
2982 : : return false;
2983 : : }
2984 : : }
2985 : :
2986 : : /* Return true if EXPR is the integer constant one. For complex and vector,
2987 : : return true if every piece is the integer constant one.
2988 : : Also return true for location wrappers for such a constant. */
2989 : :
2990 : : bool
2991 : 726040 : integer_each_onep (const_tree expr)
2992 : : {
2993 : 726040 : STRIP_ANY_LOCATION_WRAPPER (expr);
2994 : :
2995 : 726040 : if (TREE_CODE (expr) == COMPLEX_CST)
2996 : 34 : return (integer_onep (TREE_REALPART (expr))
2997 : 48 : && integer_onep (TREE_IMAGPART (expr)));
2998 : : else
2999 : 726006 : return integer_onep (expr);
3000 : : }
3001 : :
3002 : : /* Return true if EXPR is an integer containing all 1's in as much precision
3003 : : as it contains, or a complex or vector whose subparts are such integers,
3004 : : or a location wrapper for such a constant. */
3005 : :
3006 : : bool
3007 : 266280514 : integer_all_onesp (const_tree expr)
3008 : : {
3009 : 266280514 : STRIP_ANY_LOCATION_WRAPPER (expr);
3010 : :
3011 : 266280514 : if (TREE_CODE (expr) == COMPLEX_CST
3012 : 926 : && integer_all_onesp (TREE_REALPART (expr))
3013 : 266280554 : && integer_all_onesp (TREE_IMAGPART (expr)))
3014 : : return true;
3015 : :
3016 : 266280478 : else if (TREE_CODE (expr) == VECTOR_CST)
3017 : 416488 : return (VECTOR_CST_NPATTERNS (expr) == 1
3018 : 401502 : && VECTOR_CST_DUPLICATE_P (expr)
3019 : 801900 : && integer_all_onesp (VECTOR_CST_ENCODED_ELT (expr, 0)));
3020 : :
3021 : 265863990 : else if (TREE_CODE (expr) != INTEGER_CST)
3022 : : return false;
3023 : :
3024 : 175152796 : return (wi::max_value (TYPE_PRECISION (TREE_TYPE (expr)), UNSIGNED)
3025 : 350306028 : == wi::to_wide (expr));
3026 : : }
3027 : :
3028 : : /* Return true if EXPR is the integer constant minus one, or a location
3029 : : wrapper for such a constant. */
3030 : :
3031 : : bool
3032 : 192916131 : integer_minus_onep (const_tree expr)
3033 : : {
3034 : 192916131 : STRIP_ANY_LOCATION_WRAPPER (expr);
3035 : :
3036 : 192916131 : if (TREE_CODE (expr) == COMPLEX_CST)
3037 : 9060 : return (integer_all_onesp (TREE_REALPART (expr))
3038 : 9064 : && integer_zerop (TREE_IMAGPART (expr)));
3039 : : else
3040 : 192907071 : return integer_all_onesp (expr);
3041 : : }
3042 : :
3043 : : /* Return true if EXPR is an integer constant that is a power of 2 (i.e., has
3044 : : only one bit on), or a location wrapper for such a constant. */
3045 : :
3046 : : bool
3047 : 21668758 : integer_pow2p (const_tree expr)
3048 : : {
3049 : 21668758 : STRIP_ANY_LOCATION_WRAPPER (expr);
3050 : :
3051 : 21668758 : if (TREE_CODE (expr) == COMPLEX_CST
3052 : 543 : && integer_pow2p (TREE_REALPART (expr))
3053 : 21668985 : && integer_zerop (TREE_IMAGPART (expr)))
3054 : : return true;
3055 : :
3056 : 21668605 : if (TREE_CODE (expr) != INTEGER_CST)
3057 : : return false;
3058 : :
3059 : 15287759 : return wi::popcount (wi::to_wide (expr)) == 1;
3060 : : }
3061 : :
3062 : : /* Return true if EXPR is an integer constant other than zero or a
3063 : : complex constant other than zero, or a location wrapper for such a
3064 : : constant. */
3065 : :
3066 : : bool
3067 : 133008279 : integer_nonzerop (const_tree expr)
3068 : : {
3069 : 133008279 : STRIP_ANY_LOCATION_WRAPPER (expr);
3070 : :
3071 : 133008279 : return ((TREE_CODE (expr) == INTEGER_CST
3072 : 61770817 : && wi::to_wide (expr) != 0)
3073 : 146277526 : || (TREE_CODE (expr) == COMPLEX_CST
3074 : 242 : && (integer_nonzerop (TREE_REALPART (expr))
3075 : 182 : || integer_nonzerop (TREE_IMAGPART (expr)))));
3076 : : }
3077 : :
3078 : : /* Return true if EXPR is the integer constant one. For vector,
3079 : : return true if every piece is the integer constant minus one
3080 : : (representing the value TRUE).
3081 : : Also return true for location wrappers for such a constant. */
3082 : :
3083 : : bool
3084 : 1081875 : integer_truep (const_tree expr)
3085 : : {
3086 : 1081875 : STRIP_ANY_LOCATION_WRAPPER (expr);
3087 : :
3088 : 1081875 : if (TREE_CODE (expr) == VECTOR_CST)
3089 : 11547 : return integer_all_onesp (expr);
3090 : 1070328 : return integer_onep (expr);
3091 : : }
3092 : :
3093 : : /* Return true if EXPR is the fixed-point constant zero, or a location wrapper
3094 : : for such a constant. */
3095 : :
3096 : : bool
3097 : 23949336 : fixed_zerop (const_tree expr)
3098 : : {
3099 : 23949336 : STRIP_ANY_LOCATION_WRAPPER (expr);
3100 : :
3101 : 23949336 : return (TREE_CODE (expr) == FIXED_CST
3102 : 23949336 : && TREE_FIXED_CST (expr).data.is_zero ());
3103 : : }
3104 : :
3105 : : /* Return the power of two represented by a tree node known to be a
3106 : : power of two. */
3107 : :
3108 : : int
3109 : 686967 : tree_log2 (const_tree expr)
3110 : : {
3111 : 686967 : if (TREE_CODE (expr) == COMPLEX_CST)
3112 : 0 : return tree_log2 (TREE_REALPART (expr));
3113 : :
3114 : 686967 : return wi::exact_log2 (wi::to_wide (expr));
3115 : : }
3116 : :
3117 : : /* Similar, but return the largest integer Y such that 2 ** Y is less
3118 : : than or equal to EXPR. */
3119 : :
3120 : : int
3121 : 2590883 : tree_floor_log2 (const_tree expr)
3122 : : {
3123 : 2590883 : if (TREE_CODE (expr) == COMPLEX_CST)
3124 : 0 : return tree_log2 (TREE_REALPART (expr));
3125 : :
3126 : 2590883 : return wi::floor_log2 (wi::to_wide (expr));
3127 : : }
3128 : :
3129 : : /* Return number of known trailing zero bits in EXPR, or, if the value of
3130 : : EXPR is known to be zero, the precision of it's type. */
3131 : :
3132 : : unsigned int
3133 : 82350170 : tree_ctz (const_tree expr)
3134 : : {
3135 : 164698717 : if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
3136 : 82358021 : && !POINTER_TYPE_P (TREE_TYPE (expr)))
3137 : : return 0;
3138 : :
3139 : 82350154 : unsigned int ret1, ret2, prec = TYPE_PRECISION (TREE_TYPE (expr));
3140 : 82350154 : switch (TREE_CODE (expr))
3141 : : {
3142 : 43599256 : case INTEGER_CST:
3143 : 43599256 : ret1 = wi::ctz (wi::to_wide (expr));
3144 : 43599256 : return MIN (ret1, prec);
3145 : 12626728 : case SSA_NAME:
3146 : 12626728 : ret1 = wi::ctz (get_nonzero_bits (expr));
3147 : 12626728 : return MIN (ret1, prec);
3148 : 1998085 : case PLUS_EXPR:
3149 : 1998085 : case MINUS_EXPR:
3150 : 1998085 : case BIT_IOR_EXPR:
3151 : 1998085 : case BIT_XOR_EXPR:
3152 : 1998085 : case MIN_EXPR:
3153 : 1998085 : case MAX_EXPR:
3154 : 1998085 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3155 : 1998085 : if (ret1 == 0)
3156 : : return ret1;
3157 : 909628 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3158 : 909628 : return MIN (ret1, ret2);
3159 : 0 : case POINTER_PLUS_EXPR:
3160 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3161 : 0 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3162 : : /* Second operand is sizetype, which could be in theory
3163 : : wider than pointer's precision. Make sure we never
3164 : : return more than prec. */
3165 : 0 : ret2 = MIN (ret2, prec);
3166 : 0 : return MIN (ret1, ret2);
3167 : 311 : case BIT_AND_EXPR:
3168 : 311 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3169 : 311 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3170 : 311 : return MAX (ret1, ret2);
3171 : 11782828 : case MULT_EXPR:
3172 : 11782828 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3173 : 11782828 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3174 : 11782828 : return MIN (ret1 + ret2, prec);
3175 : 0 : case LSHIFT_EXPR:
3176 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3177 : 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3178 : 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3179 : : {
3180 : 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3181 : 0 : return MIN (ret1 + ret2, prec);
3182 : : }
3183 : : return ret1;
3184 : 0 : case RSHIFT_EXPR:
3185 : 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3186 : 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3187 : : {
3188 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3189 : 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3190 : 0 : if (ret1 > ret2)
3191 : 0 : return ret1 - ret2;
3192 : : }
3193 : : return 0;
3194 : 6587 : case TRUNC_DIV_EXPR:
3195 : 6587 : case CEIL_DIV_EXPR:
3196 : 6587 : case FLOOR_DIV_EXPR:
3197 : 6587 : case ROUND_DIV_EXPR:
3198 : 6587 : case EXACT_DIV_EXPR:
3199 : 6587 : if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
3200 : 6587 : && tree_int_cst_sgn (TREE_OPERAND (expr, 1)) == 1)
3201 : : {
3202 : 6587 : int l = tree_log2 (TREE_OPERAND (expr, 1));
3203 : 6587 : if (l >= 0)
3204 : : {
3205 : 5388 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3206 : 5388 : ret2 = l;
3207 : 5388 : if (ret1 > ret2)
3208 : 0 : return ret1 - ret2;
3209 : : }
3210 : : }
3211 : : return 0;
3212 : 12312810 : CASE_CONVERT:
3213 : 12312810 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3214 : 12312810 : if (ret1 && ret1 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
3215 : : ret1 = prec;
3216 : 12312810 : return MIN (ret1, prec);
3217 : 0 : case SAVE_EXPR:
3218 : 0 : return tree_ctz (TREE_OPERAND (expr, 0));
3219 : 10128 : case COND_EXPR:
3220 : 10128 : ret1 = tree_ctz (TREE_OPERAND (expr, 1));
3221 : 10128 : if (ret1 == 0)
3222 : : return 0;
3223 : 204 : ret2 = tree_ctz (TREE_OPERAND (expr, 2));
3224 : 204 : return MIN (ret1, ret2);
3225 : 0 : case COMPOUND_EXPR:
3226 : 0 : return tree_ctz (TREE_OPERAND (expr, 1));
3227 : 189 : case ADDR_EXPR:
3228 : 189 : ret1 = get_pointer_alignment (CONST_CAST_TREE (expr));
3229 : 189 : if (ret1 > BITS_PER_UNIT)
3230 : : {
3231 : 189 : ret1 = ctz_hwi (ret1 / BITS_PER_UNIT);
3232 : 189 : return MIN (ret1, prec);
3233 : : }
3234 : : return 0;
3235 : : default:
3236 : : return 0;
3237 : : }
3238 : : }
3239 : :
3240 : : /* Return true if EXPR is the real constant zero. Trailing zeroes matter for
3241 : : decimal float constants, so don't return true for them.
3242 : : Also return true for location wrappers around such a constant. */
3243 : :
3244 : : bool
3245 : 555611058 : real_zerop (const_tree expr)
3246 : : {
3247 : 555611058 : STRIP_ANY_LOCATION_WRAPPER (expr);
3248 : :
3249 : 555611058 : switch (TREE_CODE (expr))
3250 : : {
3251 : 19365438 : case REAL_CST:
3252 : 19365438 : return real_equal (&TREE_REAL_CST (expr), &dconst0)
3253 : 19365438 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3254 : 44655 : case COMPLEX_CST:
3255 : 44655 : return real_zerop (TREE_REALPART (expr))
3256 : 57737 : && real_zerop (TREE_IMAGPART (expr));
3257 : 425570 : case VECTOR_CST:
3258 : 425570 : {
3259 : : /* Don't simply check for a duplicate because the predicate
3260 : : accepts both +0.0 and -0.0. */
3261 : 425570 : unsigned count = vector_cst_encoded_nelts (expr);
3262 : 450723 : for (unsigned int i = 0; i < count; ++i)
3263 : 434854 : if (!real_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3264 : : return false;
3265 : : return true;
3266 : : }
3267 : : default:
3268 : : return false;
3269 : : }
3270 : : }
3271 : :
3272 : : /* Return true if EXPR is the real constant one in real or complex form.
3273 : : Trailing zeroes matter for decimal float constants, so don't return
3274 : : true for them.
3275 : : Also return true for location wrappers around such a constant. */
3276 : :
3277 : : bool
3278 : 115188404 : real_onep (const_tree expr)
3279 : : {
3280 : 115188404 : STRIP_ANY_LOCATION_WRAPPER (expr);
3281 : :
3282 : 115188404 : switch (TREE_CODE (expr))
3283 : : {
3284 : 7301916 : case REAL_CST:
3285 : 7301916 : return real_equal (&TREE_REAL_CST (expr), &dconst1)
3286 : 7301916 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3287 : 12593 : case COMPLEX_CST:
3288 : 12593 : return real_onep (TREE_REALPART (expr))
3289 : 16082 : && real_zerop (TREE_IMAGPART (expr));
3290 : 56913 : case VECTOR_CST:
3291 : 56913 : return (VECTOR_CST_NPATTERNS (expr) == 1
3292 : 48749 : && VECTOR_CST_DUPLICATE_P (expr)
3293 : 97031 : && real_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3294 : : default:
3295 : : return false;
3296 : : }
3297 : : }
3298 : :
3299 : : /* Return true if EXPR is the real constant minus one. Trailing zeroes
3300 : : matter for decimal float constants, so don't return true for them.
3301 : : Also return true for location wrappers around such a constant. */
3302 : :
3303 : : bool
3304 : 116174285 : real_minus_onep (const_tree expr)
3305 : : {
3306 : 116174285 : STRIP_ANY_LOCATION_WRAPPER (expr);
3307 : :
3308 : 116174285 : switch (TREE_CODE (expr))
3309 : : {
3310 : 7240208 : case REAL_CST:
3311 : 7240208 : return real_equal (&TREE_REAL_CST (expr), &dconstm1)
3312 : 7240208 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3313 : 12573 : case COMPLEX_CST:
3314 : 12573 : return real_minus_onep (TREE_REALPART (expr))
3315 : 14945 : && real_zerop (TREE_IMAGPART (expr));
3316 : 58596 : case VECTOR_CST:
3317 : 58596 : return (VECTOR_CST_NPATTERNS (expr) == 1
3318 : 49864 : && VECTOR_CST_DUPLICATE_P (expr)
3319 : 99678 : && real_minus_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3320 : : default:
3321 : : return false;
3322 : : }
3323 : : }
3324 : :
3325 : : /* Return true if T could be a floating point zero. */
3326 : :
3327 : : bool
3328 : 688194 : real_maybe_zerop (const_tree expr)
3329 : : {
3330 : 688194 : switch (TREE_CODE (expr))
3331 : : {
3332 : 471053 : case REAL_CST:
3333 : : /* Can't use real_zerop here, as it always returns false for decimal
3334 : : floats. And can't use TREE_REAL_CST (expr).cl == rvc_zero
3335 : : either, as decimal zeros are rvc_normal. */
3336 : 471053 : return real_equal (&TREE_REAL_CST (expr), &dconst0);
3337 : 0 : case COMPLEX_CST:
3338 : 0 : return (real_maybe_zerop (TREE_REALPART (expr))
3339 : 0 : || real_maybe_zerop (TREE_IMAGPART (expr)));
3340 : 0 : case VECTOR_CST:
3341 : 0 : {
3342 : 0 : unsigned count = vector_cst_encoded_nelts (expr);
3343 : 0 : for (unsigned int i = 0; i < count; ++i)
3344 : 0 : if (real_maybe_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3345 : : return true;
3346 : : return false;
3347 : : }
3348 : : default:
3349 : : /* Perhaps for SSA_NAMEs we could query frange. */
3350 : : return true;
3351 : : }
3352 : : }
3353 : :
3354 : : /* True if EXP is a constant or a cast of a constant. */
3355 : :
3356 : : bool
3357 : 3471 : really_constant_p (const_tree exp)
3358 : : {
3359 : : /* This is not quite the same as STRIP_NOPS. It does more. */
3360 : 6950 : while (CONVERT_EXPR_P (exp)
3361 : 7002 : || TREE_CODE (exp) == NON_LVALUE_EXPR)
3362 : 60 : exp = TREE_OPERAND (exp, 0);
3363 : 3471 : return TREE_CONSTANT (exp);
3364 : : }
3365 : :
3366 : : /* Return true if T holds a polynomial pointer difference, storing it in
3367 : : *VALUE if so. A true return means that T's precision is no greater
3368 : : than 64 bits, which is the largest address space we support, so *VALUE
3369 : : never loses precision. However, the signedness of the result does
3370 : : not necessarily match the signedness of T: sometimes an unsigned type
3371 : : like sizetype is used to encode a value that is actually negative. */
3372 : :
3373 : : bool
3374 : 10627807 : ptrdiff_tree_p (const_tree t, poly_int64 *value)
3375 : : {
3376 : 10627807 : if (!t)
3377 : : return false;
3378 : 10627807 : if (TREE_CODE (t) == INTEGER_CST)
3379 : : {
3380 : 2952548 : if (!cst_and_fits_in_hwi (t))
3381 : : return false;
3382 : 2951940 : *value = int_cst_value (t);
3383 : 2951940 : return true;
3384 : : }
3385 : : if (POLY_INT_CST_P (t))
3386 : : {
3387 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3388 : : if (!cst_and_fits_in_hwi (POLY_INT_CST_COEFF (t, i)))
3389 : : return false;
3390 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3391 : : value->coeffs[i] = int_cst_value (POLY_INT_CST_COEFF (t, i));
3392 : : return true;
3393 : : }
3394 : : return false;
3395 : : }
3396 : :
3397 : : poly_int64
3398 : 419980319 : tree_to_poly_int64 (const_tree t)
3399 : : {
3400 : 419980319 : gcc_assert (tree_fits_poly_int64_p (t));
3401 : 419980319 : if (POLY_INT_CST_P (t))
3402 : : return poly_int_cst_value (t).force_shwi ();
3403 : 419980319 : return TREE_INT_CST_LOW (t);
3404 : : }
3405 : :
3406 : : poly_uint64
3407 : 440015552 : tree_to_poly_uint64 (const_tree t)
3408 : : {
3409 : 440015552 : gcc_assert (tree_fits_poly_uint64_p (t));
3410 : 440015552 : if (POLY_INT_CST_P (t))
3411 : : return poly_int_cst_value (t).force_uhwi ();
3412 : 440015552 : return TREE_INT_CST_LOW (t);
3413 : : }
3414 : :
3415 : : /* Return first list element whose TREE_VALUE is ELEM.
3416 : : Return 0 if ELEM is not in LIST. */
3417 : :
3418 : : tree
3419 : 7627954 : value_member (tree elem, tree list)
3420 : : {
3421 : 22340260 : while (list)
3422 : : {
3423 : 19431800 : if (elem == TREE_VALUE (list))
3424 : : return list;
3425 : 14712306 : list = TREE_CHAIN (list);
3426 : : }
3427 : : return NULL_TREE;
3428 : : }
3429 : :
3430 : : /* Return first list element whose TREE_PURPOSE is ELEM.
3431 : : Return 0 if ELEM is not in LIST. */
3432 : :
3433 : : tree
3434 : 126000613 : purpose_member (const_tree elem, tree list)
3435 : : {
3436 : 254477394 : while (list)
3437 : : {
3438 : 139082152 : if (elem == TREE_PURPOSE (list))
3439 : : return list;
3440 : 128476781 : list = TREE_CHAIN (list);
3441 : : }
3442 : : return NULL_TREE;
3443 : : }
3444 : :
3445 : : /* Return true if ELEM is in V. */
3446 : :
3447 : : bool
3448 : 1852690 : vec_member (const_tree elem, vec<tree, va_gc> *v)
3449 : : {
3450 : 1852690 : unsigned ix;
3451 : 1852690 : tree t;
3452 : 3420722 : FOR_EACH_VEC_SAFE_ELT (v, ix, t)
3453 : 1569920 : if (elem == t)
3454 : : return true;
3455 : : return false;
3456 : : }
3457 : :
3458 : : /* Returns element number IDX (zero-origin) of chain CHAIN, or
3459 : : NULL_TREE. */
3460 : :
3461 : : tree
3462 : 17490123 : chain_index (int idx, tree chain)
3463 : : {
3464 : 22378576 : for (; chain && idx > 0; --idx)
3465 : 4888453 : chain = TREE_CHAIN (chain);
3466 : 17490123 : return chain;
3467 : : }
3468 : :
3469 : : /* Return true if ELEM is part of the chain CHAIN. */
3470 : :
3471 : : bool
3472 : 177310 : chain_member (const_tree elem, const_tree chain)
3473 : : {
3474 : 344545 : while (chain)
3475 : : {
3476 : 343329 : if (elem == chain)
3477 : : return true;
3478 : 167235 : chain = DECL_CHAIN (chain);
3479 : : }
3480 : :
3481 : : return false;
3482 : : }
3483 : :
3484 : : /* Return the length of a chain of nodes chained through TREE_CHAIN.
3485 : : We expect a null pointer to mark the end of the chain.
3486 : : This is the Lisp primitive `length'. */
3487 : :
3488 : : int
3489 : 1888401259 : list_length (const_tree t)
3490 : : {
3491 : 1888401259 : const_tree p = t;
3492 : : #ifdef ENABLE_TREE_CHECKING
3493 : 1888401259 : const_tree q = t;
3494 : : #endif
3495 : 1888401259 : int len = 0;
3496 : :
3497 : 2971755899 : while (p)
3498 : : {
3499 : 1083354640 : p = TREE_CHAIN (p);
3500 : : #ifdef ENABLE_TREE_CHECKING
3501 : 1083354640 : if (len % 2)
3502 : 349889386 : q = TREE_CHAIN (q);
3503 : 1083354640 : gcc_assert (p != q);
3504 : : #endif
3505 : 1083354640 : len++;
3506 : : }
3507 : :
3508 : 1888401259 : return len;
3509 : : }
3510 : :
3511 : : /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3512 : : UNION_TYPE TYPE, or NULL_TREE if none. */
3513 : :
3514 : : tree
3515 : 38116 : first_field (const_tree type)
3516 : : {
3517 : 38116 : tree t = TYPE_FIELDS (type);
3518 : 2753316 : while (t && TREE_CODE (t) != FIELD_DECL)
3519 : 2715200 : t = TREE_CHAIN (t);
3520 : 38116 : return t;
3521 : : }
3522 : :
3523 : : /* Returns the last FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3524 : : UNION_TYPE TYPE, or NULL_TREE if none. */
3525 : :
3526 : : tree
3527 : 2701047 : last_field (const_tree type)
3528 : : {
3529 : 2701047 : tree last = NULL_TREE;
3530 : :
3531 : 56127005 : for (tree fld = TYPE_FIELDS (type); fld; fld = TREE_CHAIN (fld))
3532 : : {
3533 : 53425958 : if (TREE_CODE (fld) != FIELD_DECL)
3534 : 45021821 : continue;
3535 : :
3536 : : last = fld;
3537 : : }
3538 : :
3539 : 2701047 : return last;
3540 : : }
3541 : :
3542 : : /* Concatenate two chains of nodes (chained through TREE_CHAIN)
3543 : : by modifying the last node in chain 1 to point to chain 2.
3544 : : This is the Lisp primitive `nconc'. */
3545 : :
3546 : : tree
3547 : 3826881569 : chainon (tree op1, tree op2)
3548 : : {
3549 : 3826881569 : tree t1;
3550 : :
3551 : 3826881569 : if (!op1)
3552 : : return op2;
3553 : 681388892 : if (!op2)
3554 : : return op1;
3555 : :
3556 : 1441596706 : for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
3557 : 830909845 : continue;
3558 : 610686861 : TREE_CHAIN (t1) = op2;
3559 : :
3560 : : #ifdef ENABLE_TREE_CHECKING
3561 : 610686861 : {
3562 : 610686861 : tree t2;
3563 : 1604012854 : for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
3564 : 993325993 : gcc_assert (t2 != t1);
3565 : : }
3566 : : #endif
3567 : :
3568 : : return op1;
3569 : 830909845 : }
3570 : :
3571 : : /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
3572 : :
3573 : : tree
3574 : 88867476 : tree_last (tree chain)
3575 : : {
3576 : 88867476 : tree next;
3577 : 88867476 : if (chain)
3578 : 167551412 : while ((next = TREE_CHAIN (chain)))
3579 : : chain = next;
3580 : 88867476 : return chain;
3581 : : }
3582 : :
3583 : : /* Reverse the order of elements in the chain T,
3584 : : and return the new head of the chain (old last element). */
3585 : :
3586 : : tree
3587 : 1277588745 : nreverse (tree t)
3588 : : {
3589 : 1277588745 : tree prev = 0, decl, next;
3590 : 3292723592 : for (decl = t; decl; decl = next)
3591 : : {
3592 : : /* We shouldn't be using this function to reverse BLOCK chains; we
3593 : : have blocks_nreverse for that. */
3594 : 2015134847 : gcc_checking_assert (TREE_CODE (decl) != BLOCK);
3595 : 2015134847 : next = TREE_CHAIN (decl);
3596 : 2015134847 : TREE_CHAIN (decl) = prev;
3597 : 2015134847 : prev = decl;
3598 : : }
3599 : 1277588745 : return prev;
3600 : : }
3601 : :
3602 : : /* Return a newly created TREE_LIST node whose
3603 : : purpose and value fields are PARM and VALUE. */
3604 : :
3605 : : tree
3606 : 1193517345 : build_tree_list (tree parm, tree value MEM_STAT_DECL)
3607 : : {
3608 : 1193517345 : tree t = make_node (TREE_LIST PASS_MEM_STAT);
3609 : 1193517345 : TREE_PURPOSE (t) = parm;
3610 : 1193517345 : TREE_VALUE (t) = value;
3611 : 1193517345 : return t;
3612 : : }
3613 : :
3614 : : /* Build a chain of TREE_LIST nodes from a vector. */
3615 : :
3616 : : tree
3617 : 80560590 : build_tree_list_vec (const vec<tree, va_gc> *vec MEM_STAT_DECL)
3618 : : {
3619 : 80560590 : tree ret = NULL_TREE;
3620 : 80560590 : tree *pp = &ret;
3621 : 80560590 : unsigned int i;
3622 : 80560590 : tree t;
3623 : 170249301 : FOR_EACH_VEC_SAFE_ELT (vec, i, t)
3624 : : {
3625 : 89688711 : *pp = build_tree_list (NULL, t PASS_MEM_STAT);
3626 : 89688711 : pp = &TREE_CHAIN (*pp);
3627 : : }
3628 : 80560590 : return ret;
3629 : : }
3630 : :
3631 : : /* Return a newly created TREE_LIST node whose
3632 : : purpose and value fields are PURPOSE and VALUE
3633 : : and whose TREE_CHAIN is CHAIN. */
3634 : :
3635 : : tree
3636 : 4842358163 : tree_cons (tree purpose, tree value, tree chain MEM_STAT_DECL)
3637 : : {
3638 : 4842358163 : tree node;
3639 : :
3640 : 4842358163 : node = ggc_alloc_tree_node_stat (sizeof (struct tree_list) PASS_MEM_STAT);
3641 : 4842358163 : memset (node, 0, sizeof (struct tree_common));
3642 : :
3643 : 4842358163 : record_node_allocation_statistics (TREE_LIST, sizeof (struct tree_list));
3644 : :
3645 : 4842358163 : TREE_SET_CODE (node, TREE_LIST);
3646 : 4842358163 : TREE_CHAIN (node) = chain;
3647 : 4842358163 : TREE_PURPOSE (node) = purpose;
3648 : 4842358163 : TREE_VALUE (node) = value;
3649 : 4842358163 : return node;
3650 : : }
3651 : :
3652 : : /* Return the values of the elements of a CONSTRUCTOR as a vector of
3653 : : trees. */
3654 : :
3655 : : vec<tree, va_gc> *
3656 : 0 : ctor_to_vec (tree ctor)
3657 : : {
3658 : 0 : vec<tree, va_gc> *vec;
3659 : 0 : vec_alloc (vec, CONSTRUCTOR_NELTS (ctor));
3660 : 0 : unsigned int ix;
3661 : 0 : tree val;
3662 : :
3663 : 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val)
3664 : 0 : vec->quick_push (val);
3665 : :
3666 : 0 : return vec;
3667 : : }
3668 : :
3669 : : /* Return the size nominally occupied by an object of type TYPE
3670 : : when it resides in memory. The value is measured in units of bytes,
3671 : : and its data type is that normally used for type sizes
3672 : : (which is the first type created by make_signed_type or
3673 : : make_unsigned_type). */
3674 : :
3675 : : tree
3676 : 25664434 : size_in_bytes_loc (location_t loc, const_tree type)
3677 : : {
3678 : 25664434 : tree t;
3679 : :
3680 : 25664434 : if (type == error_mark_node)
3681 : 0 : return integer_zero_node;
3682 : :
3683 : 25664434 : type = TYPE_MAIN_VARIANT (type);
3684 : 25664434 : t = TYPE_SIZE_UNIT (type);
3685 : :
3686 : 25664434 : if (t == 0)
3687 : : {
3688 : 56 : lang_hooks.types.incomplete_type_error (loc, NULL_TREE, type);
3689 : 56 : return size_zero_node;
3690 : : }
3691 : :
3692 : : return t;
3693 : : }
3694 : :
3695 : : /* Return the size of TYPE (in bytes) as a wide integer
3696 : : or return -1 if the size can vary or is larger than an integer. */
3697 : :
3698 : : HOST_WIDE_INT
3699 : 491449539 : int_size_in_bytes (const_tree type)
3700 : : {
3701 : 491449539 : tree t;
3702 : :
3703 : 491449539 : if (type == error_mark_node)
3704 : : return 0;
3705 : :
3706 : 491449539 : type = TYPE_MAIN_VARIANT (type);
3707 : 491449539 : t = TYPE_SIZE_UNIT (type);
3708 : :
3709 : 491449539 : if (t && tree_fits_uhwi_p (t))
3710 : 491399717 : return TREE_INT_CST_LOW (t);
3711 : : else
3712 : : return -1;
3713 : : }
3714 : :
3715 : : /* Return the maximum size of TYPE (in bytes) as a wide integer
3716 : : or return -1 if the size can vary or is larger than an integer. */
3717 : :
3718 : : HOST_WIDE_INT
3719 : 9093 : max_int_size_in_bytes (const_tree type)
3720 : : {
3721 : 9093 : HOST_WIDE_INT size = -1;
3722 : 9093 : tree size_tree;
3723 : :
3724 : : /* If this is an array type, check for a possible MAX_SIZE attached. */
3725 : :
3726 : 9093 : if (TREE_CODE (type) == ARRAY_TYPE)
3727 : : {
3728 : 8376 : size_tree = TYPE_ARRAY_MAX_SIZE (type);
3729 : :
3730 : 8376 : if (size_tree && tree_fits_uhwi_p (size_tree))
3731 : 0 : size = tree_to_uhwi (size_tree);
3732 : : }
3733 : :
3734 : : /* If we still haven't been able to get a size, see if the language
3735 : : can compute a maximum size. */
3736 : :
3737 : 0 : if (size == -1)
3738 : : {
3739 : 9093 : size_tree = lang_hooks.types.max_size (type);
3740 : :
3741 : 9093 : if (size_tree && tree_fits_uhwi_p (size_tree))
3742 : 0 : size = tree_to_uhwi (size_tree);
3743 : : }
3744 : :
3745 : 9093 : return size;
3746 : : }
3747 : :
3748 : : /* Return the bit position of FIELD, in bits from the start of the record.
3749 : : This is a tree of type bitsizetype. */
3750 : :
3751 : : tree
3752 : 93855645 : bit_position (const_tree field)
3753 : : {
3754 : 93855645 : return bit_from_pos (DECL_FIELD_OFFSET (field),
3755 : 93855645 : DECL_FIELD_BIT_OFFSET (field));
3756 : : }
3757 : :
3758 : : /* Return the byte position of FIELD, in bytes from the start of the record.
3759 : : This is a tree of type sizetype. */
3760 : :
3761 : : tree
3762 : 99016632 : byte_position (const_tree field)
3763 : : {
3764 : 99016632 : return byte_from_pos (DECL_FIELD_OFFSET (field),
3765 : 99016632 : DECL_FIELD_BIT_OFFSET (field));
3766 : : }
3767 : :
3768 : : /* Likewise, but return as an integer. It must be representable in
3769 : : that way (since it could be a signed value, we don't have the
3770 : : option of returning -1 like int_size_in_byte can. */
3771 : :
3772 : : HOST_WIDE_INT
3773 : 9742028 : int_byte_position (const_tree field)
3774 : : {
3775 : 9742028 : return tree_to_shwi (byte_position (field));
3776 : : }
3777 : :
3778 : : /* Return, as a tree node, the number of elements for TYPE (which is an
3779 : : ARRAY_TYPE) minus one. This counts only elements of the top array. */
3780 : :
3781 : : tree
3782 : 76971210 : array_type_nelts_minus_one (const_tree type)
3783 : : {
3784 : 76971210 : tree index_type, min, max;
3785 : :
3786 : : /* If they did it with unspecified bounds, then we should have already
3787 : : given an error about it before we got here. */
3788 : 76971210 : if (! TYPE_DOMAIN (type))
3789 : 5610891 : return error_mark_node;
3790 : :
3791 : 71360319 : index_type = TYPE_DOMAIN (type);
3792 : 71360319 : min = TYPE_MIN_VALUE (index_type);
3793 : 71360319 : max = TYPE_MAX_VALUE (index_type);
3794 : :
3795 : : /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
3796 : 71360319 : if (!max)
3797 : : {
3798 : : /* zero sized arrays are represented from C FE as complete types with
3799 : : NULL TYPE_MAX_VALUE and zero TYPE_SIZE, while C++ FE represents
3800 : : them as min 0, max -1. */
3801 : 1245448 : if (COMPLETE_TYPE_P (type)
3802 : 3128 : && integer_zerop (TYPE_SIZE (type))
3803 : 1248576 : && integer_zerop (min))
3804 : 3128 : return build_int_cst (TREE_TYPE (min), -1);
3805 : :
3806 : 1242320 : return error_mark_node;
3807 : : }
3808 : :
3809 : 70114871 : return (integer_zerop (min)
3810 : 70114871 : ? max
3811 : 1053161 : : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
3812 : : }
3813 : :
3814 : : /* Return, as an INTEGER_CST node, the number of elements for TYPE
3815 : : (which is an ARRAY_TYPE). This counts only elements of the top
3816 : : array. */
3817 : :
3818 : : tree
3819 : 5243772 : array_type_nelts_top (tree type)
3820 : : {
3821 : 5243772 : return fold_build2_loc (input_location,
3822 : : PLUS_EXPR, sizetype,
3823 : : array_type_nelts_minus_one (type),
3824 : 5243772 : size_one_node);
3825 : : }
3826 : :
3827 : : /* If arg is static -- a reference to an object in static storage -- then
3828 : : return the object. This is not the same as the C meaning of `static'.
3829 : : If arg isn't static, return NULL. */
3830 : :
3831 : : tree
3832 : 1051573077 : staticp (tree arg)
3833 : : {
3834 : 1052453461 : switch (TREE_CODE (arg))
3835 : : {
3836 : : case FUNCTION_DECL:
3837 : : /* Nested functions are static, even though taking their address will
3838 : : involve a trampoline as we unnest the nested function and create
3839 : : the trampoline on the tree level. */
3840 : : return arg;
3841 : :
3842 : 678469201 : case VAR_DECL:
3843 : 545821717 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3844 : 176783999 : && ! DECL_THREAD_LOCAL_P (arg)
3845 : 174998427 : && ! DECL_DLLIMPORT_P (arg)
3846 : 678469201 : ? arg : NULL);
3847 : :
3848 : 577026 : case CONST_DECL:
3849 : 62 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3850 : 577026 : ? arg : NULL);
3851 : :
3852 : 0 : case CONSTRUCTOR:
3853 : 0 : return TREE_STATIC (arg) ? arg : NULL;
3854 : :
3855 : : case LABEL_DECL:
3856 : : case STRING_CST:
3857 : : return arg;
3858 : :
3859 : 638086 : case COMPONENT_REF:
3860 : : /* If the thing being referenced is not a field, then it is
3861 : : something language specific. */
3862 : 638086 : gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL);
3863 : :
3864 : : /* If we are referencing a bitfield, we can't evaluate an
3865 : : ADDR_EXPR at compile time and so it isn't a constant. */
3866 : 638086 : if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
3867 : : return NULL;
3868 : :
3869 : 638086 : return staticp (TREE_OPERAND (arg, 0));
3870 : :
3871 : : case BIT_FIELD_REF:
3872 : : return NULL;
3873 : :
3874 : 63417 : case INDIRECT_REF:
3875 : 63417 : return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
3876 : :
3877 : 242641 : case ARRAY_REF:
3878 : 242641 : case ARRAY_RANGE_REF:
3879 : 242641 : if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
3880 : 242641 : && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
3881 : 242298 : return staticp (TREE_OPERAND (arg, 0));
3882 : : else
3883 : : return NULL;
3884 : :
3885 : 930 : case COMPOUND_LITERAL_EXPR:
3886 : 930 : return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;
3887 : :
3888 : : default:
3889 : : return NULL;
3890 : : }
3891 : : }
3892 : :
3893 : :
3894 : :
3895 : :
3896 : : /* Return whether OP is a DECL whose address is function-invariant. */
3897 : :
3898 : : bool
3899 : 5162512624 : decl_address_invariant_p (const_tree op)
3900 : : {
3901 : : /* The conditions below are slightly less strict than the one in
3902 : : staticp. */
3903 : :
3904 : 5162512624 : switch (TREE_CODE (op))
3905 : : {
3906 : : case PARM_DECL:
3907 : : case RESULT_DECL:
3908 : : case LABEL_DECL:
3909 : : case FUNCTION_DECL:
3910 : : return true;
3911 : :
3912 : 2916916649 : case VAR_DECL:
3913 : 2228819328 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3914 : 2103167273 : || DECL_THREAD_LOCAL_P (op)
3915 : 2103167273 : || DECL_CONTEXT (op) == current_function_decl
3916 : 2924422973 : || decl_function_context (op) == current_function_decl)
3917 : 2909410325 : return true;
3918 : : break;
3919 : :
3920 : 25153558 : case CONST_DECL:
3921 : 0 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3922 : 25153558 : || decl_function_context (op) == current_function_decl)
3923 : 25153558 : return true;
3924 : : break;
3925 : :
3926 : : default:
3927 : : break;
3928 : : }
3929 : :
3930 : : return false;
3931 : : }
3932 : :
3933 : : /* Return whether OP is a DECL whose address is interprocedural-invariant. */
3934 : :
3935 : : bool
3936 : 1734453 : decl_address_ip_invariant_p (const_tree op)
3937 : : {
3938 : : /* The conditions below are slightly less strict than the one in
3939 : : staticp. */
3940 : :
3941 : 1734453 : switch (TREE_CODE (op))
3942 : : {
3943 : : case LABEL_DECL:
3944 : : case FUNCTION_DECL:
3945 : : case STRING_CST:
3946 : : return true;
3947 : :
3948 : 1564803 : case VAR_DECL:
3949 : 1128201 : if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
3950 : 470103 : && !DECL_DLLIMPORT_P (op))
3951 : 2659503 : || DECL_THREAD_LOCAL_P (op))
3952 : 470103 : return true;
3953 : : break;
3954 : :
3955 : 52054 : case CONST_DECL:
3956 : 52054 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
3957 : : return true;
3958 : : break;
3959 : :
3960 : : default:
3961 : : break;
3962 : : }
3963 : :
3964 : : return false;
3965 : : }
3966 : :
3967 : :
3968 : : /* Return true if T is function-invariant (internal function, does
3969 : : not handle arithmetic; that's handled in skip_simple_arithmetic and
3970 : : tree_invariant_p). */
3971 : :
3972 : : static bool
3973 : 14320598 : tree_invariant_p_1 (tree t)
3974 : : {
3975 : 14320598 : tree op;
3976 : :
3977 : 14320598 : if (TREE_CONSTANT (t)
3978 : 14320598 : || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
3979 : : return true;
3980 : :
3981 : 12458546 : switch (TREE_CODE (t))
3982 : : {
3983 : : case SAVE_EXPR:
3984 : : case TARGET_EXPR:
3985 : : return true;
3986 : :
3987 : 20316 : case ADDR_EXPR:
3988 : 20316 : op = TREE_OPERAND (t, 0);
3989 : 26894 : while (handled_component_p (op))
3990 : : {
3991 : 7483 : switch (TREE_CODE (op))
3992 : : {
3993 : 1377 : case ARRAY_REF:
3994 : 1377 : case ARRAY_RANGE_REF:
3995 : 1377 : if (!tree_invariant_p (TREE_OPERAND (op, 1))
3996 : 472 : || TREE_OPERAND (op, 2) != NULL_TREE
3997 : 1849 : || TREE_OPERAND (op, 3) != NULL_TREE)
3998 : : return false;
3999 : : break;
4000 : :
4001 : 5991 : case COMPONENT_REF:
4002 : 5991 : if (TREE_OPERAND (op, 2) != NULL_TREE)
4003 : : return false;
4004 : : break;
4005 : :
4006 : 6578 : default:;
4007 : : }
4008 : 6578 : op = TREE_OPERAND (op, 0);
4009 : : }
4010 : :
4011 : 19411 : return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
4012 : :
4013 : : default:
4014 : : break;
4015 : : }
4016 : :
4017 : : return false;
4018 : : }
4019 : :
4020 : : /* Return true if T is function-invariant. */
4021 : :
4022 : : bool
4023 : 11656530 : tree_invariant_p (tree t)
4024 : : {
4025 : 11656530 : tree inner = skip_simple_arithmetic (t);
4026 : 11656530 : return tree_invariant_p_1 (inner);
4027 : : }
4028 : :
4029 : : /* Wrap a SAVE_EXPR around EXPR, if appropriate.
4030 : : Do this to any expression which may be used in more than one place,
4031 : : but must be evaluated only once.
4032 : :
4033 : : Normally, expand_expr would reevaluate the expression each time.
4034 : : Calling save_expr produces something that is evaluated and recorded
4035 : : the first time expand_expr is called on it. Subsequent calls to
4036 : : expand_expr just reuse the recorded value.
4037 : :
4038 : : The call to expand_expr that generates code that actually computes
4039 : : the value is the first call *at compile time*. Subsequent calls
4040 : : *at compile time* generate code to use the saved value.
4041 : : This produces correct result provided that *at run time* control
4042 : : always flows through the insns made by the first expand_expr
4043 : : before reaching the other places where the save_expr was evaluated.
4044 : : You, the caller of save_expr, must make sure this is so.
4045 : :
4046 : : Constants, and certain read-only nodes, are returned with no
4047 : : SAVE_EXPR because that is safe. Expressions containing placeholders
4048 : : are not touched; see tree.def for an explanation of what these
4049 : : are used for. */
4050 : :
4051 : : tree
4052 : 2664079 : save_expr (tree expr)
4053 : : {
4054 : 2664079 : tree inner;
4055 : :
4056 : : /* If the tree evaluates to a constant, then we don't want to hide that
4057 : : fact (i.e. this allows further folding, and direct checks for constants).
4058 : : However, a read-only object that has side effects cannot be bypassed.
4059 : : Since it is no problem to reevaluate literals, we just return the
4060 : : literal node. */
4061 : 2664079 : inner = skip_simple_arithmetic (expr);
4062 : 2664079 : if (TREE_CODE (inner) == ERROR_MARK)
4063 : : return inner;
4064 : :
4065 : 2664068 : if (tree_invariant_p_1 (inner))
4066 : : return expr;
4067 : :
4068 : : /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
4069 : : it means that the size or offset of some field of an object depends on
4070 : : the value within another field.
4071 : :
4072 : : Note that it must not be the case that EXPR contains both a PLACEHOLDER_EXPR
4073 : : and some variable since it would then need to be both evaluated once and
4074 : : evaluated more than once. Front-ends must assure this case cannot
4075 : : happen by surrounding any such subexpressions in their own SAVE_EXPR
4076 : : and forcing evaluation at the proper time. */
4077 : 1974050 : if (contains_placeholder_p (inner))
4078 : : return expr;
4079 : :
4080 : 1974050 : expr = build1_loc (EXPR_LOCATION (expr), SAVE_EXPR, TREE_TYPE (expr), expr);
4081 : :
4082 : : /* This expression might be placed ahead of a jump to ensure that the
4083 : : value was computed on both sides of the jump. So make sure it isn't
4084 : : eliminated as dead. */
4085 : 1974050 : TREE_SIDE_EFFECTS (expr) = 1;
4086 : 1974050 : return expr;
4087 : : }
4088 : :
4089 : : /* Look inside EXPR into any simple arithmetic operations. Return the
4090 : : outermost non-arithmetic or non-invariant node. */
4091 : :
4092 : : tree
4093 : 14320609 : skip_simple_arithmetic (tree expr)
4094 : : {
4095 : : /* We don't care about whether this can be used as an lvalue in this
4096 : : context. */
4097 : 14330911 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4098 : 10302 : expr = TREE_OPERAND (expr, 0);
4099 : :
4100 : : /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
4101 : : a constant, it will be more efficient to not make another SAVE_EXPR since
4102 : : it will allow better simplification and GCSE will be able to merge the
4103 : : computations if they actually occur. */
4104 : 38227635 : while (true)
4105 : : {
4106 : 38227635 : if (UNARY_CLASS_P (expr))
4107 : 14764113 : expr = TREE_OPERAND (expr, 0);
4108 : 23463522 : else if (BINARY_CLASS_P (expr))
4109 : : {
4110 : : /* Before commutative binary operands are canonicalized,
4111 : : it is quite common to have constants in the first operand.
4112 : : Check for that common case first so that we don't walk
4113 : : large expressions with tree_invariant_p unnecessarily.
4114 : : This can still have terrible compile time complexity,
4115 : : we should limit the depth of the tree_invariant_p and
4116 : : skip_simple_arithmetic recursion. */
4117 : 9206259 : if ((TREE_CONSTANT (TREE_OPERAND (expr, 0))
4118 : 9196195 : || (TREE_READONLY (TREE_OPERAND (expr, 0))
4119 : 9625 : && !TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0))))
4120 : 9215848 : && tree_invariant_p (TREE_OPERAND (expr, 0)))
4121 : 19653 : expr = TREE_OPERAND (expr, 1);
4122 : 9186606 : else if (tree_invariant_p (TREE_OPERAND (expr, 1)))
4123 : 9114046 : expr = TREE_OPERAND (expr, 0);
4124 : 72560 : else if (tree_invariant_p (TREE_OPERAND (expr, 0)))
4125 : 9214 : expr = TREE_OPERAND (expr, 1);
4126 : : else
4127 : : break;
4128 : : }
4129 : : else
4130 : : break;
4131 : : }
4132 : :
4133 : 14320609 : return expr;
4134 : : }
4135 : :
4136 : : /* Look inside EXPR into simple arithmetic operations involving constants.
4137 : : Return the outermost non-arithmetic or non-constant node. */
4138 : :
4139 : : tree
4140 : 0 : skip_simple_constant_arithmetic (tree expr)
4141 : : {
4142 : 0 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4143 : 0 : expr = TREE_OPERAND (expr, 0);
4144 : :
4145 : 0 : while (true)
4146 : : {
4147 : 0 : if (UNARY_CLASS_P (expr))
4148 : 0 : expr = TREE_OPERAND (expr, 0);
4149 : 0 : else if (BINARY_CLASS_P (expr))
4150 : : {
4151 : 0 : if (TREE_CONSTANT (TREE_OPERAND (expr, 1)))
4152 : 0 : expr = TREE_OPERAND (expr, 0);
4153 : 0 : else if (TREE_CONSTANT (TREE_OPERAND (expr, 0)))
4154 : 0 : expr = TREE_OPERAND (expr, 1);
4155 : : else
4156 : : break;
4157 : : }
4158 : : else
4159 : : break;
4160 : : }
4161 : :
4162 : 0 : return expr;
4163 : : }
4164 : :
4165 : : /* Return which tree structure is used by T. */
4166 : :
4167 : : enum tree_node_structure_enum
4168 : 35350526819 : tree_node_structure (const_tree t)
4169 : : {
4170 : 35350526819 : const enum tree_code code = TREE_CODE (t);
4171 : 35350526819 : return tree_node_structure_for_code (code);
4172 : : }
4173 : :
4174 : : /* Set various status flags when building a CALL_EXPR object T. */
4175 : :
4176 : : static void
4177 : 229389617 : process_call_operands (tree t)
4178 : : {
4179 : 229389617 : bool side_effects = TREE_SIDE_EFFECTS (t);
4180 : 229389617 : bool read_only = false;
4181 : 229389617 : int i = call_expr_flags (t);
4182 : :
4183 : : /* Calls have side-effects, except those to const or pure functions. */
4184 : 229389617 : if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
4185 : : side_effects = true;
4186 : : /* Propagate TREE_READONLY of arguments for const functions. */
4187 : 52024911 : if (i & ECF_CONST)
4188 : 50425747 : read_only = true;
4189 : :
4190 : 229389617 : if (!side_effects || read_only)
4191 : 270125576 : for (i = 1; i < TREE_OPERAND_LENGTH (t); i++)
4192 : : {
4193 : 218101169 : tree op = TREE_OPERAND (t, i);
4194 : 218101169 : if (op && TREE_SIDE_EFFECTS (op))
4195 : : side_effects = true;
4196 : 218101169 : if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op))
4197 : : read_only = false;
4198 : : }
4199 : :
4200 : 229389617 : TREE_SIDE_EFFECTS (t) = side_effects;
4201 : 229389617 : TREE_READONLY (t) = read_only;
4202 : 229389617 : }
4203 : :
4204 : : /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
4205 : : size or offset that depends on a field within a record. */
4206 : :
4207 : : bool
4208 : 37656881 : contains_placeholder_p (const_tree exp)
4209 : : {
4210 : 37656881 : enum tree_code code;
4211 : :
4212 : 37656881 : if (!exp)
4213 : : return false;
4214 : :
4215 : 37656881 : code = TREE_CODE (exp);
4216 : 37656881 : if (code == PLACEHOLDER_EXPR)
4217 : : return true;
4218 : :
4219 : 37656881 : switch (TREE_CODE_CLASS (code))
4220 : : {
4221 : 1149587 : case tcc_reference:
4222 : : /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
4223 : : position computations since they will be converted into a
4224 : : WITH_RECORD_EXPR involving the reference, which will assume
4225 : : here will be valid. */
4226 : 1149587 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4227 : :
4228 : 511289 : case tcc_exceptional:
4229 : 511289 : if (code == TREE_LIST)
4230 : 0 : return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
4231 : 0 : || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
4232 : : break;
4233 : :
4234 : 33506770 : case tcc_unary:
4235 : 33506770 : case tcc_binary:
4236 : 33506770 : case tcc_comparison:
4237 : 33506770 : case tcc_expression:
4238 : 33506770 : switch (code)
4239 : : {
4240 : 5191 : case COMPOUND_EXPR:
4241 : : /* Ignoring the first operand isn't quite right, but works best. */
4242 : 5191 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
4243 : :
4244 : 2969 : case COND_EXPR:
4245 : 5938 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4246 : 2969 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
4247 : 5938 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
4248 : :
4249 : : case SAVE_EXPR:
4250 : : /* The save_expr function never wraps anything containing
4251 : : a PLACEHOLDER_EXPR. */
4252 : : return false;
4253 : :
4254 : 24261225 : default:
4255 : 24261225 : break;
4256 : : }
4257 : :
4258 : 24261225 : switch (TREE_CODE_LENGTH (code))
4259 : : {
4260 : 14789525 : case 1:
4261 : 14789525 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4262 : 9455338 : case 2:
4263 : 18909527 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4264 : 18909527 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
4265 : : default:
4266 : : return false;
4267 : : }
4268 : :
4269 : 438608 : case tcc_vl_exp:
4270 : 438608 : switch (code)
4271 : : {
4272 : 438608 : case CALL_EXPR:
4273 : 438608 : {
4274 : 438608 : const_tree arg;
4275 : 438608 : const_call_expr_arg_iterator iter;
4276 : 1449937 : FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
4277 : 572721 : if (CONTAINS_PLACEHOLDER_P (arg))
4278 : : return true;
4279 : : return false;
4280 : : }
4281 : : default:
4282 : : return false;
4283 : : }
4284 : :
4285 : : default:
4286 : : return false;
4287 : : }
4288 : : return false;
4289 : : }
4290 : :
4291 : : /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
4292 : : directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
4293 : : field positions. */
4294 : :
4295 : : static bool
4296 : 753623 : type_contains_placeholder_1 (const_tree type)
4297 : : {
4298 : : /* If the size contains a placeholder or the parent type (component type in
4299 : : the case of arrays) type involves a placeholder, this type does. */
4300 : 1487221 : if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
4301 : 753623 : || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
4302 : 1507246 : || (!POINTER_TYPE_P (type)
4303 : 621962 : && TREE_TYPE (type)
4304 : 104371 : && type_contains_placeholder_p (TREE_TYPE (type))))
4305 : 0 : return true;
4306 : :
4307 : : /* Now do type-specific checks. Note that the last part of the check above
4308 : : greatly limits what we have to do below. */
4309 : 753623 : switch (TREE_CODE (type))
4310 : : {
4311 : : case VOID_TYPE:
4312 : : case OPAQUE_TYPE:
4313 : : case COMPLEX_TYPE:
4314 : : case ENUMERAL_TYPE:
4315 : : case BOOLEAN_TYPE:
4316 : : case POINTER_TYPE:
4317 : : case OFFSET_TYPE:
4318 : : case REFERENCE_TYPE:
4319 : : case METHOD_TYPE:
4320 : : case FUNCTION_TYPE:
4321 : : case VECTOR_TYPE:
4322 : : case NULLPTR_TYPE:
4323 : : return false;
4324 : :
4325 : 161106 : case INTEGER_TYPE:
4326 : 161106 : case BITINT_TYPE:
4327 : 161106 : case REAL_TYPE:
4328 : 161106 : case FIXED_POINT_TYPE:
4329 : : /* Here we just check the bounds. */
4330 : 312585 : return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
4331 : 312585 : || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
4332 : :
4333 : 54371 : case ARRAY_TYPE:
4334 : : /* We have already checked the component type above, so just check
4335 : : the domain type. Flexible array members have a null domain. */
4336 : 108730 : return TYPE_DOMAIN (type) ?
4337 : 54359 : type_contains_placeholder_p (TYPE_DOMAIN (type)) : false;
4338 : :
4339 : 383329 : case RECORD_TYPE:
4340 : 383329 : case UNION_TYPE:
4341 : 383329 : case QUAL_UNION_TYPE:
4342 : 383329 : {
4343 : 383329 : tree field;
4344 : :
4345 : 11463996 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
4346 : 11080667 : if (TREE_CODE (field) == FIELD_DECL
4347 : 11080667 : && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
4348 : 885676 : || (TREE_CODE (type) == QUAL_UNION_TYPE
4349 : 0 : && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
4350 : 885676 : || type_contains_placeholder_p (TREE_TYPE (field))))
4351 : 0 : return true;
4352 : :
4353 : : return false;
4354 : : }
4355 : :
4356 : 0 : default:
4357 : 0 : gcc_unreachable ();
4358 : : }
4359 : : }
4360 : :
4361 : : /* Wrapper around above function used to cache its result. */
4362 : :
4363 : : bool
4364 : 3060300 : type_contains_placeholder_p (tree type)
4365 : : {
4366 : 3060300 : bool result;
4367 : :
4368 : : /* If the contains_placeholder_bits field has been initialized,
4369 : : then we know the answer. */
4370 : 3060300 : if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
4371 : 2306677 : return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
4372 : :
4373 : : /* Indicate that we've seen this type node, and the answer is false.
4374 : : This is what we want to return if we run into recursion via fields. */
4375 : 753623 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
4376 : :
4377 : : /* Compute the real value. */
4378 : 753623 : result = type_contains_placeholder_1 (type);
4379 : :
4380 : : /* Store the real value. */
4381 : 753623 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
4382 : :
4383 : 753623 : return result;
4384 : : }
4385 : :
4386 : : /* Push tree EXP onto vector QUEUE if it is not already present. */
4387 : :
4388 : : static void
4389 : 0 : push_without_duplicates (tree exp, vec<tree> *queue)
4390 : : {
4391 : 0 : unsigned int i;
4392 : 0 : tree iter;
4393 : :
4394 : 0 : FOR_EACH_VEC_ELT (*queue, i, iter)
4395 : 0 : if (simple_cst_equal (iter, exp) == 1)
4396 : : break;
4397 : :
4398 : 0 : if (!iter)
4399 : 0 : queue->safe_push (exp);
4400 : 0 : }
4401 : :
4402 : : /* Given a tree EXP, find all occurrences of references to fields
4403 : : in a PLACEHOLDER_EXPR and place them in vector REFS without
4404 : : duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
4405 : : we assume here that EXP contains only arithmetic expressions
4406 : : or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
4407 : : argument list. */
4408 : :
4409 : : void
4410 : 0 : find_placeholder_in_expr (tree exp, vec<tree> *refs)
4411 : : {
4412 : 0 : enum tree_code code = TREE_CODE (exp);
4413 : 0 : tree inner;
4414 : 0 : int i;
4415 : :
4416 : : /* We handle TREE_LIST and COMPONENT_REF separately. */
4417 : 0 : if (code == TREE_LIST)
4418 : : {
4419 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs);
4420 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs);
4421 : : }
4422 : 0 : else if (code == COMPONENT_REF)
4423 : : {
4424 : 0 : for (inner = TREE_OPERAND (exp, 0);
4425 : 0 : REFERENCE_CLASS_P (inner);
4426 : 0 : inner = TREE_OPERAND (inner, 0))
4427 : : ;
4428 : :
4429 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
4430 : 0 : push_without_duplicates (exp, refs);
4431 : : else
4432 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs);
4433 : : }
4434 : : else
4435 : 0 : switch (TREE_CODE_CLASS (code))
4436 : : {
4437 : : case tcc_constant:
4438 : : break;
4439 : :
4440 : 0 : case tcc_declaration:
4441 : : /* Variables allocated to static storage can stay. */
4442 : 0 : if (!TREE_STATIC (exp))
4443 : 0 : push_without_duplicates (exp, refs);
4444 : : break;
4445 : :
4446 : 0 : case tcc_expression:
4447 : : /* This is the pattern built in ada/make_aligning_type. */
4448 : 0 : if (code == ADDR_EXPR
4449 : 0 : && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR)
4450 : : {
4451 : 0 : push_without_duplicates (exp, refs);
4452 : 0 : break;
4453 : : }
4454 : :
4455 : : /* Fall through. */
4456 : :
4457 : : case tcc_exceptional:
4458 : : case tcc_unary:
4459 : : case tcc_binary:
4460 : : case tcc_comparison:
4461 : : case tcc_reference:
4462 : 0 : for (i = 0; i < TREE_CODE_LENGTH (code); i++)
4463 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4464 : : break;
4465 : :
4466 : : case tcc_vl_exp:
4467 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4468 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4469 : : break;
4470 : :
4471 : 0 : default:
4472 : 0 : gcc_unreachable ();
4473 : : }
4474 : 0 : }
4475 : :
4476 : : /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
4477 : : return a tree with all occurrences of references to F in a
4478 : : PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
4479 : : CONST_DECLs. Note that we assume here that EXP contains only
4480 : : arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
4481 : : occurring only in their argument list. */
4482 : :
4483 : : tree
4484 : 0 : substitute_in_expr (tree exp, tree f, tree r)
4485 : : {
4486 : 0 : enum tree_code code = TREE_CODE (exp);
4487 : 0 : tree op0, op1, op2, op3;
4488 : 0 : tree new_tree;
4489 : :
4490 : : /* We handle TREE_LIST and COMPONENT_REF separately. */
4491 : 0 : if (code == TREE_LIST)
4492 : : {
4493 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
4494 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
4495 : 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4496 : : return exp;
4497 : :
4498 : 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4499 : : }
4500 : 0 : else if (code == COMPONENT_REF)
4501 : : {
4502 : 0 : tree inner;
4503 : :
4504 : : /* If this expression is getting a value from a PLACEHOLDER_EXPR
4505 : : and it is the right field, replace it with R. */
4506 : 0 : for (inner = TREE_OPERAND (exp, 0);
4507 : 0 : REFERENCE_CLASS_P (inner);
4508 : 0 : inner = TREE_OPERAND (inner, 0))
4509 : : ;
4510 : :
4511 : : /* The field. */
4512 : 0 : op1 = TREE_OPERAND (exp, 1);
4513 : :
4514 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f)
4515 : : return r;
4516 : :
4517 : : /* If this expression hasn't been completed let, leave it alone. */
4518 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner))
4519 : : return exp;
4520 : :
4521 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4522 : 0 : if (op0 == TREE_OPERAND (exp, 0))
4523 : : return exp;
4524 : :
4525 : 0 : new_tree
4526 : 0 : = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE);
4527 : : }
4528 : : else
4529 : 0 : switch (TREE_CODE_CLASS (code))
4530 : : {
4531 : : case tcc_constant:
4532 : : return exp;
4533 : :
4534 : 0 : case tcc_declaration:
4535 : 0 : if (exp == f)
4536 : : return r;
4537 : : else
4538 : : return exp;
4539 : :
4540 : 0 : case tcc_expression:
4541 : 0 : if (exp == f)
4542 : : return r;
4543 : :
4544 : : /* Fall through. */
4545 : :
4546 : 0 : case tcc_exceptional:
4547 : 0 : case tcc_unary:
4548 : 0 : case tcc_binary:
4549 : 0 : case tcc_comparison:
4550 : 0 : case tcc_reference:
4551 : 0 : switch (TREE_CODE_LENGTH (code))
4552 : : {
4553 : : case 0:
4554 : : return exp;
4555 : :
4556 : 0 : case 1:
4557 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4558 : 0 : if (op0 == TREE_OPERAND (exp, 0))
4559 : : return exp;
4560 : :
4561 : 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4562 : 0 : break;
4563 : :
4564 : 0 : case 2:
4565 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4566 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4567 : :
4568 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4569 : : return exp;
4570 : :
4571 : 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4572 : 0 : break;
4573 : :
4574 : 0 : case 3:
4575 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4576 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4577 : 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4578 : :
4579 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4580 : 0 : && op2 == TREE_OPERAND (exp, 2))
4581 : : return exp;
4582 : :
4583 : 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4584 : 0 : break;
4585 : :
4586 : 0 : case 4:
4587 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4588 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4589 : 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4590 : 0 : op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
4591 : :
4592 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4593 : 0 : && op2 == TREE_OPERAND (exp, 2)
4594 : 0 : && op3 == TREE_OPERAND (exp, 3))
4595 : : return exp;
4596 : :
4597 : 0 : new_tree
4598 : 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4599 : 0 : break;
4600 : :
4601 : 0 : default:
4602 : 0 : gcc_unreachable ();
4603 : : }
4604 : : break;
4605 : :
4606 : 0 : case tcc_vl_exp:
4607 : 0 : {
4608 : 0 : int i;
4609 : :
4610 : 0 : new_tree = NULL_TREE;
4611 : :
4612 : : /* If we are trying to replace F with a constant or with another
4613 : : instance of one of the arguments of the call, inline back
4614 : : functions which do nothing else than computing a value from
4615 : : the arguments they are passed. This makes it possible to
4616 : : fold partially or entirely the replacement expression. */
4617 : 0 : if (code == CALL_EXPR)
4618 : : {
4619 : 0 : bool maybe_inline = false;
4620 : 0 : if (CONSTANT_CLASS_P (r))
4621 : : maybe_inline = true;
4622 : : else
4623 : 0 : for (i = 3; i < TREE_OPERAND_LENGTH (exp); i++)
4624 : 0 : if (operand_equal_p (TREE_OPERAND (exp, i), r, 0))
4625 : : {
4626 : : maybe_inline = true;
4627 : : break;
4628 : : }
4629 : 0 : if (maybe_inline)
4630 : : {
4631 : 0 : tree t = maybe_inline_call_in_expr (exp);
4632 : 0 : if (t)
4633 : 0 : return SUBSTITUTE_IN_EXPR (t, f, r);
4634 : : }
4635 : : }
4636 : :
4637 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4638 : : {
4639 : 0 : tree op = TREE_OPERAND (exp, i);
4640 : 0 : tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
4641 : 0 : if (new_op != op)
4642 : : {
4643 : 0 : if (!new_tree)
4644 : 0 : new_tree = copy_node (exp);
4645 : 0 : TREE_OPERAND (new_tree, i) = new_op;
4646 : : }
4647 : : }
4648 : :
4649 : 0 : if (new_tree)
4650 : : {
4651 : 0 : new_tree = fold (new_tree);
4652 : 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4653 : 0 : process_call_operands (new_tree);
4654 : : }
4655 : : else
4656 : : return exp;
4657 : : }
4658 : : break;
4659 : :
4660 : 0 : default:
4661 : 0 : gcc_unreachable ();
4662 : : }
4663 : :
4664 : 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4665 : :
4666 : 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4667 : 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4668 : :
4669 : : return new_tree;
4670 : : }
4671 : :
4672 : : /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
4673 : : for it within OBJ, a tree that is an object or a chain of references. */
4674 : :
4675 : : tree
4676 : 210053 : substitute_placeholder_in_expr (tree exp, tree obj)
4677 : : {
4678 : 210053 : enum tree_code code = TREE_CODE (exp);
4679 : 210053 : tree op0, op1, op2, op3;
4680 : 210053 : tree new_tree;
4681 : :
4682 : : /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
4683 : : in the chain of OBJ. */
4684 : 210053 : if (code == PLACEHOLDER_EXPR)
4685 : : {
4686 : 0 : tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
4687 : 0 : tree elt;
4688 : :
4689 : 0 : for (elt = obj; elt != 0;
4690 : 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4691 : 0 : || TREE_CODE (elt) == COND_EXPR)
4692 : 0 : ? TREE_OPERAND (elt, 1)
4693 : 0 : : (REFERENCE_CLASS_P (elt)
4694 : : || UNARY_CLASS_P (elt)
4695 : : || BINARY_CLASS_P (elt)
4696 : : || VL_EXP_CLASS_P (elt)
4697 : : || EXPRESSION_CLASS_P (elt))
4698 : 0 : ? TREE_OPERAND (elt, 0) : 0))
4699 : 0 : if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
4700 : : return elt;
4701 : :
4702 : 0 : for (elt = obj; elt != 0;
4703 : 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4704 : 0 : || TREE_CODE (elt) == COND_EXPR)
4705 : 0 : ? TREE_OPERAND (elt, 1)
4706 : 0 : : (REFERENCE_CLASS_P (elt)
4707 : : || UNARY_CLASS_P (elt)
4708 : : || BINARY_CLASS_P (elt)
4709 : : || VL_EXP_CLASS_P (elt)
4710 : : || EXPRESSION_CLASS_P (elt))
4711 : 0 : ? TREE_OPERAND (elt, 0) : 0))
4712 : 0 : if (POINTER_TYPE_P (TREE_TYPE (elt))
4713 : 0 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
4714 : : == need_type))
4715 : 0 : return fold_build1 (INDIRECT_REF, need_type, elt);
4716 : :
4717 : : /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
4718 : : survives until RTL generation, there will be an error. */
4719 : : return exp;
4720 : : }
4721 : :
4722 : : /* TREE_LIST is special because we need to look at TREE_VALUE
4723 : : and TREE_CHAIN, not TREE_OPERANDS. */
4724 : 210053 : else if (code == TREE_LIST)
4725 : : {
4726 : 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
4727 : 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
4728 : 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4729 : : return exp;
4730 : :
4731 : 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4732 : : }
4733 : : else
4734 : 210053 : switch (TREE_CODE_CLASS (code))
4735 : : {
4736 : : case tcc_constant:
4737 : : case tcc_declaration:
4738 : : return exp;
4739 : :
4740 : 9437 : case tcc_exceptional:
4741 : 9437 : case tcc_unary:
4742 : 9437 : case tcc_binary:
4743 : 9437 : case tcc_comparison:
4744 : 9437 : case tcc_expression:
4745 : 9437 : case tcc_reference:
4746 : 9437 : case tcc_statement:
4747 : 9437 : switch (TREE_CODE_LENGTH (code))
4748 : : {
4749 : : case 0:
4750 : : return exp;
4751 : :
4752 : 7185 : case 1:
4753 : 7185 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4754 : 7185 : if (op0 == TREE_OPERAND (exp, 0))
4755 : : return exp;
4756 : :
4757 : 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4758 : 0 : break;
4759 : :
4760 : 2240 : case 2:
4761 : 2240 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4762 : 2240 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4763 : :
4764 : 2240 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4765 : : return exp;
4766 : :
4767 : 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4768 : 0 : break;
4769 : :
4770 : 12 : case 3:
4771 : 12 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4772 : 12 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4773 : 12 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4774 : :
4775 : 24 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4776 : 24 : && op2 == TREE_OPERAND (exp, 2))
4777 : : return exp;
4778 : :
4779 : 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4780 : 0 : break;
4781 : :
4782 : 0 : case 4:
4783 : 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4784 : 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4785 : 0 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4786 : 0 : op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
4787 : :
4788 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4789 : 0 : && op2 == TREE_OPERAND (exp, 2)
4790 : 0 : && op3 == TREE_OPERAND (exp, 3))
4791 : : return exp;
4792 : :
4793 : 0 : new_tree
4794 : 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4795 : 0 : break;
4796 : :
4797 : 0 : default:
4798 : 0 : gcc_unreachable ();
4799 : : }
4800 : : break;
4801 : :
4802 : : case tcc_vl_exp:
4803 : : {
4804 : : int i;
4805 : :
4806 : : new_tree = NULL_TREE;
4807 : :
4808 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4809 : : {
4810 : 0 : tree op = TREE_OPERAND (exp, i);
4811 : 0 : tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
4812 : 0 : if (new_op != op)
4813 : : {
4814 : 0 : if (!new_tree)
4815 : 0 : new_tree = copy_node (exp);
4816 : 0 : TREE_OPERAND (new_tree, i) = new_op;
4817 : : }
4818 : : }
4819 : :
4820 : 0 : if (new_tree)
4821 : : {
4822 : 0 : new_tree = fold (new_tree);
4823 : 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4824 : 0 : process_call_operands (new_tree);
4825 : : }
4826 : : else
4827 : : return exp;
4828 : : }
4829 : : break;
4830 : :
4831 : 0 : default:
4832 : 0 : gcc_unreachable ();
4833 : : }
4834 : :
4835 : 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4836 : :
4837 : 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4838 : 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4839 : :
4840 : : return new_tree;
4841 : : }
4842 : :
4843 : :
4844 : : /* Subroutine of stabilize_reference; this is called for subtrees of
4845 : : references. Any expression with side-effects must be put in a SAVE_EXPR
4846 : : to ensure that it is only evaluated once.
4847 : :
4848 : : We don't put SAVE_EXPR nodes around everything, because assigning very
4849 : : simple expressions to temporaries causes us to miss good opportunities
4850 : : for optimizations. Among other things, the opportunity to fold in the
4851 : : addition of a constant into an addressing mode often gets lost, e.g.
4852 : : "y[i+1] += x;". In general, we take the approach that we should not make
4853 : : an assignment unless we are forced into it - i.e., that any non-side effect
4854 : : operator should be allowed, and that cse should take care of coalescing
4855 : : multiple utterances of the same expression should that prove fruitful. */
4856 : :
4857 : : static tree
4858 : 545960 : stabilize_reference_1 (tree e)
4859 : : {
4860 : 545960 : tree result;
4861 : 545960 : enum tree_code code = TREE_CODE (e);
4862 : :
4863 : : /* We cannot ignore const expressions because it might be a reference
4864 : : to a const array but whose index contains side-effects. But we can
4865 : : ignore things that are actual constant or that already have been
4866 : : handled by this function. */
4867 : :
4868 : 545960 : if (tree_invariant_p (e))
4869 : : return e;
4870 : :
4871 : 146537 : switch (TREE_CODE_CLASS (code))
4872 : : {
4873 : 0 : case tcc_exceptional:
4874 : : /* Always wrap STATEMENT_LIST into SAVE_EXPR, even if it doesn't
4875 : : have side-effects. */
4876 : 0 : if (code == STATEMENT_LIST)
4877 : 0 : return save_expr (e);
4878 : : /* FALLTHRU */
4879 : 118304 : case tcc_type:
4880 : 118304 : case tcc_declaration:
4881 : 118304 : case tcc_comparison:
4882 : 118304 : case tcc_statement:
4883 : 118304 : case tcc_expression:
4884 : 118304 : case tcc_reference:
4885 : 118304 : case tcc_vl_exp:
4886 : : /* If the expression has side-effects, then encase it in a SAVE_EXPR
4887 : : so that it will only be evaluated once. */
4888 : : /* The reference (r) and comparison (<) classes could be handled as
4889 : : below, but it is generally faster to only evaluate them once. */
4890 : 118304 : if (TREE_SIDE_EFFECTS (e))
4891 : 973 : return save_expr (e);
4892 : : return e;
4893 : :
4894 : : case tcc_constant:
4895 : : /* Constants need no processing. In fact, we should never reach
4896 : : here. */
4897 : : return e;
4898 : :
4899 : 21180 : case tcc_binary:
4900 : : /* Division is slow and tends to be compiled with jumps,
4901 : : especially the division by powers of 2 that is often
4902 : : found inside of an array reference. So do it just once. */
4903 : 21180 : if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
4904 : 19140 : || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
4905 : 19140 : || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
4906 : 19140 : || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
4907 : 2040 : return save_expr (e);
4908 : : /* Recursively stabilize each operand. */
4909 : 19140 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
4910 : 19140 : stabilize_reference_1 (TREE_OPERAND (e, 1)));
4911 : 19140 : break;
4912 : :
4913 : 7053 : case tcc_unary:
4914 : : /* Recursively stabilize each operand. */
4915 : 7053 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
4916 : 7053 : break;
4917 : :
4918 : 0 : default:
4919 : 0 : gcc_unreachable ();
4920 : : }
4921 : :
4922 : 26193 : TREE_TYPE (result) = TREE_TYPE (e);
4923 : 26193 : TREE_READONLY (result) = TREE_READONLY (e);
4924 : 26193 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
4925 : 26193 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
4926 : :
4927 : 26193 : return result;
4928 : : }
4929 : :
4930 : : /* Stabilize a reference so that we can use it any number of times
4931 : : without causing its operands to be evaluated more than once.
4932 : : Returns the stabilized reference. This works by means of save_expr,
4933 : : so see the caveats in the comments about save_expr.
4934 : :
4935 : : Also allows conversion expressions whose operands are references.
4936 : : Any other kind of expression is returned unchanged. */
4937 : :
4938 : : tree
4939 : 4020983 : stabilize_reference (tree ref)
4940 : : {
4941 : 4020983 : tree result;
4942 : 4020983 : enum tree_code code = TREE_CODE (ref);
4943 : :
4944 : 4020983 : switch (code)
4945 : : {
4946 : : case VAR_DECL:
4947 : : case PARM_DECL:
4948 : : case RESULT_DECL:
4949 : : /* No action is needed in this case. */
4950 : : return ref;
4951 : :
4952 : 0 : CASE_CONVERT:
4953 : 0 : case FLOAT_EXPR:
4954 : 0 : case FIX_TRUNC_EXPR:
4955 : 0 : result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
4956 : 0 : break;
4957 : :
4958 : 454500 : case INDIRECT_REF:
4959 : 454500 : result = build_nt (INDIRECT_REF,
4960 : 454500 : stabilize_reference_1 (TREE_OPERAND (ref, 0)));
4961 : 454500 : break;
4962 : :
4963 : 307132 : case COMPONENT_REF:
4964 : 307132 : result = build_nt (COMPONENT_REF,
4965 : 307132 : stabilize_reference (TREE_OPERAND (ref, 0)),
4966 : 307132 : TREE_OPERAND (ref, 1), NULL_TREE);
4967 : 307132 : break;
4968 : :
4969 : 0 : case BIT_FIELD_REF:
4970 : 0 : result = build_nt (BIT_FIELD_REF,
4971 : 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
4972 : 0 : TREE_OPERAND (ref, 1), TREE_OPERAND (ref, 2));
4973 : 0 : REF_REVERSE_STORAGE_ORDER (result) = REF_REVERSE_STORAGE_ORDER (ref);
4974 : 0 : break;
4975 : :
4976 : 46127 : case ARRAY_REF:
4977 : 92254 : result = build_nt (ARRAY_REF,
4978 : 46127 : stabilize_reference (TREE_OPERAND (ref, 0)),
4979 : 46127 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
4980 : 46127 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
4981 : 46127 : break;
4982 : :
4983 : 0 : case ARRAY_RANGE_REF:
4984 : 0 : result = build_nt (ARRAY_RANGE_REF,
4985 : 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
4986 : 0 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
4987 : 0 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
4988 : 0 : break;
4989 : :
4990 : 0 : case COMPOUND_EXPR:
4991 : : /* We cannot wrap the first expression in a SAVE_EXPR, as then
4992 : : it wouldn't be ignored. This matters when dealing with
4993 : : volatiles. */
4994 : 0 : return stabilize_reference_1 (ref);
4995 : :
4996 : : /* If arg isn't a kind of lvalue we recognize, make no change.
4997 : : Caller should recognize the error for an invalid lvalue. */
4998 : : default:
4999 : : return ref;
5000 : :
5001 : 0 : case ERROR_MARK:
5002 : 0 : return error_mark_node;
5003 : : }
5004 : :
5005 : 807759 : TREE_TYPE (result) = TREE_TYPE (ref);
5006 : 807759 : TREE_READONLY (result) = TREE_READONLY (ref);
5007 : 807759 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
5008 : 807759 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
5009 : 807759 : protected_set_expr_location (result, EXPR_LOCATION (ref));
5010 : :
5011 : 807759 : return result;
5012 : : }
5013 : :
5014 : : /* Low-level constructors for expressions. */
5015 : :
5016 : : /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
5017 : : and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
5018 : :
5019 : : void
5020 : 1237282481 : recompute_tree_invariant_for_addr_expr (tree t)
5021 : : {
5022 : 1237282481 : tree node;
5023 : 1237282481 : bool tc = true, se = false;
5024 : :
5025 : 1237282481 : gcc_assert (TREE_CODE (t) == ADDR_EXPR);
5026 : :
5027 : : /* We started out assuming this address is both invariant and constant, but
5028 : : does not have side effects. Now go down any handled components and see if
5029 : : any of them involve offsets that are either non-constant or non-invariant.
5030 : : Also check for side-effects.
5031 : :
5032 : : ??? Note that this code makes no attempt to deal with the case where
5033 : : taking the address of something causes a copy due to misalignment. */
5034 : :
5035 : : #define UPDATE_FLAGS(NODE) \
5036 : : do { tree _node = (NODE); \
5037 : : if (_node && !TREE_CONSTANT (_node)) tc = false; \
5038 : : if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
5039 : :
5040 : 1437237778 : for (node = TREE_OPERAND (t, 0); handled_component_p (node);
5041 : 199955297 : node = TREE_OPERAND (node, 0))
5042 : : {
5043 : : /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
5044 : : array reference (probably made temporarily by the G++ front end),
5045 : : so ignore all the operands. */
5046 : 199955297 : if ((TREE_CODE (node) == ARRAY_REF
5047 : 199955297 : || TREE_CODE (node) == ARRAY_RANGE_REF)
5048 : 199955297 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
5049 : : {
5050 : 29645356 : UPDATE_FLAGS (TREE_OPERAND (node, 1));
5051 : 29645356 : if (TREE_OPERAND (node, 2))
5052 : 1879468 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5053 : 29645356 : if (TREE_OPERAND (node, 3))
5054 : 265811 : UPDATE_FLAGS (TREE_OPERAND (node, 3));
5055 : : }
5056 : : /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
5057 : : FIELD_DECL, apparently. The G++ front end can put something else
5058 : : there, at least temporarily. */
5059 : 170309941 : else if (TREE_CODE (node) == COMPONENT_REF
5060 : 170309941 : && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
5061 : : {
5062 : 169509597 : if (TREE_OPERAND (node, 2))
5063 : 16542 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5064 : : }
5065 : : }
5066 : :
5067 : 1237282481 : node = lang_hooks.expr_to_decl (node, &tc, &se);
5068 : :
5069 : : /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
5070 : : the address, since &(*a)->b is a form of addition. If it's a constant, the
5071 : : address is constant too. If it's a decl, its address is constant if the
5072 : : decl is static. Everything else is not constant and, furthermore,
5073 : : taking the address of a volatile variable is not volatile. */
5074 : 1237282481 : if (INDIRECT_REF_P (node)
5075 : 1207146978 : || TREE_CODE (node) == MEM_REF)
5076 : 142916400 : UPDATE_FLAGS (TREE_OPERAND (node, 0));
5077 : 1094366081 : else if (CONSTANT_CLASS_P (node))
5078 : : ;
5079 : 1023608060 : else if (DECL_P (node))
5080 : 1008406316 : tc &= (staticp (node) != NULL_TREE);
5081 : : else
5082 : : {
5083 : 15201744 : tc = false;
5084 : 15201744 : se |= TREE_SIDE_EFFECTS (node);
5085 : : }
5086 : :
5087 : :
5088 : 1237282481 : TREE_CONSTANT (t) = tc;
5089 : 1237282481 : TREE_SIDE_EFFECTS (t) = se;
5090 : : #undef UPDATE_FLAGS
5091 : 1237282481 : }
5092 : :
5093 : : /* Build an expression of code CODE, data type TYPE, and operands as
5094 : : specified. Expressions and reference nodes can be created this way.
5095 : : Constants, decls, types and misc nodes cannot be.
5096 : :
5097 : : We define 5 non-variadic functions, from 0 to 4 arguments. This is
5098 : : enough for all extant tree codes. */
5099 : :
5100 : : tree
5101 : 320656655 : build0 (enum tree_code code, tree tt MEM_STAT_DECL)
5102 : : {
5103 : 320656655 : tree t;
5104 : :
5105 : 320656655 : gcc_assert (TREE_CODE_LENGTH (code) == 0);
5106 : :
5107 : 320656655 : t = make_node (code PASS_MEM_STAT);
5108 : 320656655 : TREE_TYPE (t) = tt;
5109 : :
5110 : 320656655 : return t;
5111 : : }
5112 : :
5113 : : tree
5114 : 3102201502 : build1 (enum tree_code code, tree type, tree node MEM_STAT_DECL)
5115 : : {
5116 : 3102201502 : int length = sizeof (struct tree_exp);
5117 : 3102201502 : tree t;
5118 : :
5119 : 3102201502 : record_node_allocation_statistics (code, length);
5120 : :
5121 : 3102201502 : gcc_assert (TREE_CODE_LENGTH (code) == 1);
5122 : :
5123 : 3102201502 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
5124 : :
5125 : 3102201502 : memset (t, 0, sizeof (struct tree_common));
5126 : :
5127 : 3102201502 : TREE_SET_CODE (t, code);
5128 : :
5129 : 3102201502 : TREE_TYPE (t) = type;
5130 : 3102201502 : SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
5131 : 3102201502 : TREE_OPERAND (t, 0) = node;
5132 : 3102201502 : if (node && !TYPE_P (node))
5133 : : {
5134 : 3102186483 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
5135 : 3102186483 : TREE_READONLY (t) = TREE_READONLY (node);
5136 : : }
5137 : :
5138 : 3102201502 : if (TREE_CODE_CLASS (code) == tcc_statement)
5139 : : {
5140 : 21798483 : if (code != DEBUG_BEGIN_STMT)
5141 : 21798483 : TREE_SIDE_EFFECTS (t) = 1;
5142 : : }
5143 : 3080403019 : else switch (code)
5144 : : {
5145 : 50780 : case VA_ARG_EXPR:
5146 : : /* All of these have side-effects, no matter what their
5147 : : operands are. */
5148 : 50780 : TREE_SIDE_EFFECTS (t) = 1;
5149 : 50780 : TREE_READONLY (t) = 0;
5150 : 50780 : break;
5151 : :
5152 : 490636663 : case INDIRECT_REF:
5153 : : /* Whether a dereference is readonly has nothing to do with whether
5154 : : its operand is readonly. */
5155 : 490636663 : TREE_READONLY (t) = 0;
5156 : 490636663 : break;
5157 : :
5158 : 504098307 : case ADDR_EXPR:
5159 : 504098307 : if (node)
5160 : 504098307 : recompute_tree_invariant_for_addr_expr (t);
5161 : : break;
5162 : :
5163 : 2085617269 : default:
5164 : 819883433 : if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
5165 : 1969943089 : && node && !TYPE_P (node)
5166 : 4055560358 : && TREE_CONSTANT (node))
5167 : 496213701 : TREE_CONSTANT (t) = 1;
5168 : 2085617269 : if (TREE_CODE_CLASS (code) == tcc_reference
5169 : 706633437 : && node && TREE_THIS_VOLATILE (node))
5170 : 2342984 : TREE_THIS_VOLATILE (t) = 1;
5171 : : break;
5172 : : }
5173 : :
5174 : 3102201502 : return t;
5175 : : }
5176 : :
5177 : : #define PROCESS_ARG(N) \
5178 : : do { \
5179 : : TREE_OPERAND (t, N) = arg##N; \
5180 : : if (arg##N &&!TYPE_P (arg##N)) \
5181 : : { \
5182 : : if (TREE_SIDE_EFFECTS (arg##N)) \
5183 : : side_effects = 1; \
5184 : : if (!TREE_READONLY (arg##N) \
5185 : : && !CONSTANT_CLASS_P (arg##N)) \
5186 : : (void) (read_only = 0); \
5187 : : if (!TREE_CONSTANT (arg##N)) \
5188 : : (void) (constant = 0); \
5189 : : } \
5190 : : } while (0)
5191 : :
5192 : : tree
5193 : 1042524270 : build2 (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
5194 : : {
5195 : 1042524270 : bool constant, read_only, side_effects, div_by_zero;
5196 : 1042524270 : tree t;
5197 : :
5198 : 1042524270 : gcc_assert (TREE_CODE_LENGTH (code) == 2);
5199 : :
5200 : 1042524270 : if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
5201 : 178912441 : && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
5202 : : /* When sizetype precision doesn't match that of pointers
5203 : : we need to be able to build explicit extensions or truncations
5204 : : of the offset argument. */
5205 : 1042524270 : && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
5206 : 0 : gcc_assert (TREE_CODE (arg0) == INTEGER_CST
5207 : : && TREE_CODE (arg1) == INTEGER_CST);
5208 : :
5209 : 1042524270 : if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
5210 : 23177585 : gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
5211 : : && ptrofftype_p (TREE_TYPE (arg1)));
5212 : :
5213 : 1042524270 : t = make_node (code PASS_MEM_STAT);
5214 : 1042524270 : TREE_TYPE (t) = tt;
5215 : :
5216 : : /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
5217 : : result based on those same flags for the arguments. But if the
5218 : : arguments aren't really even `tree' expressions, we shouldn't be trying
5219 : : to do this. */
5220 : :
5221 : : /* Expressions without side effects may be constant if their
5222 : : arguments are as well. */
5223 : 2085048540 : constant = (TREE_CODE_CLASS (code) == tcc_comparison
5224 : 1042524270 : || TREE_CODE_CLASS (code) == tcc_binary);
5225 : 1042524270 : read_only = 1;
5226 : 1042524270 : side_effects = TREE_SIDE_EFFECTS (t);
5227 : :
5228 : 1042524270 : switch (code)
5229 : : {
5230 : 9765410 : case TRUNC_DIV_EXPR:
5231 : 9765410 : case CEIL_DIV_EXPR:
5232 : 9765410 : case FLOOR_DIV_EXPR:
5233 : 9765410 : case ROUND_DIV_EXPR:
5234 : 9765410 : case EXACT_DIV_EXPR:
5235 : 9765410 : case CEIL_MOD_EXPR:
5236 : 9765410 : case FLOOR_MOD_EXPR:
5237 : 9765410 : case ROUND_MOD_EXPR:
5238 : 9765410 : case TRUNC_MOD_EXPR:
5239 : 9765410 : div_by_zero = integer_zerop (arg1);
5240 : 9765410 : break;
5241 : : default:
5242 : : div_by_zero = false;
5243 : : }
5244 : :
5245 : 1133991917 : PROCESS_ARG (0);
5246 : 1467628710 : PROCESS_ARG (1);
5247 : :
5248 : 1042524270 : TREE_SIDE_EFFECTS (t) = side_effects;
5249 : 1042524270 : if (code == MEM_REF)
5250 : : {
5251 : 68855056 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5252 : : {
5253 : 14717964 : tree o = TREE_OPERAND (arg0, 0);
5254 : 14717964 : TREE_READONLY (t) = TREE_READONLY (o);
5255 : 14717964 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5256 : : }
5257 : : }
5258 : : else
5259 : : {
5260 : 973669214 : TREE_READONLY (t) = read_only;
5261 : : /* Don't mark X / 0 as constant. */
5262 : 973669214 : TREE_CONSTANT (t) = constant && !div_by_zero;
5263 : 973669214 : TREE_THIS_VOLATILE (t)
5264 : 973669214 : = (TREE_CODE_CLASS (code) == tcc_reference
5265 : 973669214 : && arg0 && TREE_THIS_VOLATILE (arg0));
5266 : : }
5267 : :
5268 : 1042524270 : return t;
5269 : : }
5270 : :
5271 : :
5272 : : tree
5273 : 383913968 : build3 (enum tree_code code, tree tt, tree arg0, tree arg1,
5274 : : tree arg2 MEM_STAT_DECL)
5275 : : {
5276 : 383913968 : bool constant, read_only, side_effects;
5277 : 383913968 : tree t;
5278 : :
5279 : 383913968 : gcc_assert (TREE_CODE_LENGTH (code) == 3);
5280 : 383913968 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5281 : :
5282 : 383913968 : t = make_node (code PASS_MEM_STAT);
5283 : 383913968 : TREE_TYPE (t) = tt;
5284 : :
5285 : 383913968 : read_only = 1;
5286 : :
5287 : : /* As a special exception, if COND_EXPR has NULL branches, we
5288 : : assume that it is a gimple statement and always consider
5289 : : it to have side effects. */
5290 : 383913968 : if (code == COND_EXPR
5291 : 31670469 : && tt == void_type_node
5292 : 21171656 : && arg1 == NULL_TREE
5293 : 21171656 : && arg2 == NULL_TREE)
5294 : : side_effects = true;
5295 : : else
5296 : 383913968 : side_effects = TREE_SIDE_EFFECTS (t);
5297 : :
5298 : 417774988 : PROCESS_ARG (0);
5299 : 394086598 : PROCESS_ARG (1);
5300 : 393918859 : PROCESS_ARG (2);
5301 : :
5302 : 383913968 : if (code == COND_EXPR)
5303 : 31670469 : TREE_READONLY (t) = read_only;
5304 : :
5305 : 383913968 : TREE_SIDE_EFFECTS (t) = side_effects;
5306 : 383913968 : TREE_THIS_VOLATILE (t)
5307 : 383913968 : = (TREE_CODE_CLASS (code) == tcc_reference
5308 : 383913968 : && arg0 && TREE_THIS_VOLATILE (arg0));
5309 : :
5310 : 383913968 : return t;
5311 : : }
5312 : :
5313 : : tree
5314 : 36196319 : build4 (enum tree_code code, tree tt, tree arg0, tree arg1,
5315 : : tree arg2, tree arg3 MEM_STAT_DECL)
5316 : : {
5317 : 36196319 : bool constant, read_only, side_effects;
5318 : 36196319 : tree t;
5319 : :
5320 : 36196319 : gcc_assert (TREE_CODE_LENGTH (code) == 4);
5321 : :
5322 : 36196319 : t = make_node (code PASS_MEM_STAT);
5323 : 36196319 : TREE_TYPE (t) = tt;
5324 : :
5325 : 36196319 : side_effects = TREE_SIDE_EFFECTS (t);
5326 : :
5327 : 36196319 : PROCESS_ARG (0);
5328 : 36196319 : PROCESS_ARG (1);
5329 : 36196319 : PROCESS_ARG (2);
5330 : 36196319 : PROCESS_ARG (3);
5331 : :
5332 : 36196319 : TREE_SIDE_EFFECTS (t) = side_effects;
5333 : 36196319 : TREE_THIS_VOLATILE (t)
5334 : 72392638 : = (TREE_CODE_CLASS (code) == tcc_reference
5335 : 36196319 : && arg0 && TREE_THIS_VOLATILE (arg0));
5336 : :
5337 : 36196319 : return t;
5338 : : }
5339 : :
5340 : : tree
5341 : 1141212 : build5 (enum tree_code code, tree tt, tree arg0, tree arg1,
5342 : : tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
5343 : : {
5344 : 1141212 : bool constant, read_only, side_effects;
5345 : 1141212 : tree t;
5346 : :
5347 : 1141212 : gcc_assert (TREE_CODE_LENGTH (code) == 5);
5348 : :
5349 : 1141212 : t = make_node (code PASS_MEM_STAT);
5350 : 1141212 : TREE_TYPE (t) = tt;
5351 : :
5352 : 1141212 : side_effects = TREE_SIDE_EFFECTS (t);
5353 : :
5354 : 1141212 : PROCESS_ARG (0);
5355 : 1141212 : PROCESS_ARG (1);
5356 : 1141212 : PROCESS_ARG (2);
5357 : 1141212 : PROCESS_ARG (3);
5358 : 1141212 : PROCESS_ARG (4);
5359 : :
5360 : 1141212 : TREE_SIDE_EFFECTS (t) = side_effects;
5361 : 1141212 : if (code == TARGET_MEM_REF)
5362 : : {
5363 : 1134531 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5364 : : {
5365 : 193753 : tree o = TREE_OPERAND (arg0, 0);
5366 : 193753 : TREE_READONLY (t) = TREE_READONLY (o);
5367 : 193753 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5368 : : }
5369 : : }
5370 : : else
5371 : 6681 : TREE_THIS_VOLATILE (t)
5372 : 6681 : = (TREE_CODE_CLASS (code) == tcc_reference
5373 : 6681 : && arg0 && TREE_THIS_VOLATILE (arg0));
5374 : :
5375 : 1141212 : return t;
5376 : : }
5377 : :
5378 : : /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
5379 : : on the pointer PTR. */
5380 : :
5381 : : tree
5382 : 482320 : build_simple_mem_ref_loc (location_t loc, tree ptr)
5383 : : {
5384 : 482320 : poly_int64 offset = 0;
5385 : 482320 : tree ptype = TREE_TYPE (ptr);
5386 : 482320 : tree tem;
5387 : : /* For convenience allow addresses that collapse to a simple base
5388 : : and offset. */
5389 : 482320 : if (TREE_CODE (ptr) == ADDR_EXPR
5390 : 482320 : && (handled_component_p (TREE_OPERAND (ptr, 0))
5391 : 15396 : || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF))
5392 : : {
5393 : 187 : ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset);
5394 : 187 : gcc_assert (ptr);
5395 : 187 : if (TREE_CODE (ptr) == MEM_REF)
5396 : : {
5397 : 77 : offset += mem_ref_offset (ptr).force_shwi ();
5398 : 77 : ptr = TREE_OPERAND (ptr, 0);
5399 : : }
5400 : : else
5401 : 110 : ptr = build_fold_addr_expr (ptr);
5402 : 187 : gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr));
5403 : : }
5404 : 482320 : tem = build2 (MEM_REF, TREE_TYPE (ptype),
5405 : : ptr, build_int_cst (ptype, offset));
5406 : 482320 : SET_EXPR_LOCATION (tem, loc);
5407 : 482320 : return tem;
5408 : : }
5409 : :
5410 : : /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
5411 : :
5412 : : poly_offset_int
5413 : 1164096332 : mem_ref_offset (const_tree t)
5414 : : {
5415 : 1164096332 : return poly_offset_int::from (wi::to_poly_wide (TREE_OPERAND (t, 1)),
5416 : 1164096332 : SIGNED);
5417 : : }
5418 : :
5419 : : /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
5420 : : offsetted by OFFSET units. */
5421 : :
5422 : : tree
5423 : 188892 : build_invariant_address (tree type, tree base, poly_int64 offset)
5424 : : {
5425 : 188892 : tree ref = fold_build2 (MEM_REF, TREE_TYPE (type),
5426 : : build_fold_addr_expr (base),
5427 : : build_int_cst (ptr_type_node, offset));
5428 : 188892 : tree addr = build1 (ADDR_EXPR, type, ref);
5429 : 188892 : recompute_tree_invariant_for_addr_expr (addr);
5430 : 188892 : return addr;
5431 : : }
5432 : :
5433 : : /* Similar except don't specify the TREE_TYPE
5434 : : and leave the TREE_SIDE_EFFECTS as 0.
5435 : : It is permissible for arguments to be null,
5436 : : or even garbage if their values do not matter. */
5437 : :
5438 : : tree
5439 : 1964092 : build_nt (enum tree_code code, ...)
5440 : : {
5441 : 1964092 : tree t;
5442 : 1964092 : int length;
5443 : 1964092 : int i;
5444 : 1964092 : va_list p;
5445 : :
5446 : 1964092 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5447 : :
5448 : 1964092 : va_start (p, code);
5449 : :
5450 : 1964092 : t = make_node (code);
5451 : 1964092 : length = TREE_CODE_LENGTH (code);
5452 : :
5453 : 5526385 : for (i = 0; i < length; i++)
5454 : 3562293 : TREE_OPERAND (t, i) = va_arg (p, tree);
5455 : :
5456 : 1964092 : va_end (p);
5457 : 1964092 : return t;
5458 : : }
5459 : :
5460 : : /* Similar to build_nt, but for creating a CALL_EXPR object with a
5461 : : tree vec. */
5462 : :
5463 : : tree
5464 : 0 : build_nt_call_vec (tree fn, vec<tree, va_gc> *args)
5465 : : {
5466 : 0 : tree ret, t;
5467 : 0 : unsigned int ix;
5468 : :
5469 : 0 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
5470 : 0 : CALL_EXPR_FN (ret) = fn;
5471 : 0 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
5472 : 0 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
5473 : 0 : CALL_EXPR_ARG (ret, ix) = t;
5474 : 0 : return ret;
5475 : : }
5476 : :
5477 : : /* Create a DECL_... node of code CODE, name NAME (if non-null)
5478 : : and data type TYPE.
5479 : : We do NOT enter this node in any sort of symbol table.
5480 : :
5481 : : LOC is the location of the decl.
5482 : :
5483 : : layout_decl is used to set up the decl's storage layout.
5484 : : Other slots are initialized to 0 or null pointers. */
5485 : :
5486 : : tree
5487 : 2836055535 : build_decl (location_t loc, enum tree_code code, tree name,
5488 : : tree type MEM_STAT_DECL)
5489 : : {
5490 : 2836055535 : tree t;
5491 : :
5492 : 2836055535 : t = make_node (code PASS_MEM_STAT);
5493 : 2836055535 : DECL_SOURCE_LOCATION (t) = loc;
5494 : :
5495 : : /* if (type == error_mark_node)
5496 : : type = integer_type_node; */
5497 : : /* That is not done, deliberately, so that having error_mark_node
5498 : : as the type can suppress useless errors in the use of this variable. */
5499 : :
5500 : 2836055535 : DECL_NAME (t) = name;
5501 : 2836055535 : TREE_TYPE (t) = type;
5502 : :
5503 : 2836055535 : if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
5504 : 997975608 : layout_decl (t, 0);
5505 : :
5506 : 2836055535 : return t;
5507 : : }
5508 : :
5509 : : /* Create and return a DEBUG_EXPR_DECL node of the given TYPE. */
5510 : :
5511 : : tree
5512 : 1636190 : build_debug_expr_decl (tree type)
5513 : : {
5514 : 1636190 : tree vexpr = make_node (DEBUG_EXPR_DECL);
5515 : 1636190 : DECL_ARTIFICIAL (vexpr) = 1;
5516 : 1636190 : TREE_TYPE (vexpr) = type;
5517 : 1636190 : SET_DECL_MODE (vexpr, TYPE_MODE (type));
5518 : 1636190 : return vexpr;
5519 : : }
5520 : :
5521 : : /* Builds and returns function declaration with NAME and TYPE. */
5522 : :
5523 : : tree
5524 : 19027 : build_fn_decl (const char *name, tree type)
5525 : : {
5526 : 19027 : tree id = get_identifier (name);
5527 : 19027 : tree decl = build_decl (input_location, FUNCTION_DECL, id, type);
5528 : :
5529 : 19027 : DECL_EXTERNAL (decl) = 1;
5530 : 19027 : TREE_PUBLIC (decl) = 1;
5531 : 19027 : DECL_ARTIFICIAL (decl) = 1;
5532 : 19027 : TREE_NOTHROW (decl) = 1;
5533 : :
5534 : 19027 : return decl;
5535 : : }
5536 : :
5537 : : vec<tree, va_gc> *all_translation_units;
5538 : :
5539 : : /* Builds a new translation-unit decl with name NAME, queues it in the
5540 : : global list of translation-unit decls and returns it. */
5541 : :
5542 : : tree
5543 : 247462 : build_translation_unit_decl (tree name)
5544 : : {
5545 : 247462 : tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL,
5546 : 247462 : name, NULL_TREE);
5547 : 247462 : TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
5548 : 247462 : vec_safe_push (all_translation_units, tu);
5549 : 247462 : return tu;
5550 : : }
5551 : :
5552 : :
5553 : : /* BLOCK nodes are used to represent the structure of binding contours
5554 : : and declarations, once those contours have been exited and their contents
5555 : : compiled. This information is used for outputting debugging info. */
5556 : :
5557 : : tree
5558 : 689633 : build_block (tree vars, tree subblocks, tree supercontext, tree chain)
5559 : : {
5560 : 689633 : tree block = make_node (BLOCK);
5561 : :
5562 : 689633 : BLOCK_VARS (block) = vars;
5563 : 689633 : BLOCK_SUBBLOCKS (block) = subblocks;
5564 : 689633 : BLOCK_SUPERCONTEXT (block) = supercontext;
5565 : 689633 : BLOCK_CHAIN (block) = chain;
5566 : 689633 : return block;
5567 : : }
5568 : :
5569 : :
5570 : : /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
5571 : :
5572 : : LOC is the location to use in tree T. */
5573 : :
5574 : : void
5575 : 11884443537 : protected_set_expr_location (tree t, location_t loc)
5576 : : {
5577 : 11884443537 : if (CAN_HAVE_LOCATION_P (t))
5578 : 1896471670 : SET_EXPR_LOCATION (t, loc);
5579 : 9926798594 : else if (t && TREE_CODE (t) == STATEMENT_LIST)
5580 : : {
5581 : 22243 : t = expr_single (t);
5582 : 22243 : if (t && CAN_HAVE_LOCATION_P (t))
5583 : 18 : SET_EXPR_LOCATION (t, loc);
5584 : : }
5585 : 11884443537 : }
5586 : :
5587 : : /* Like PROTECTED_SET_EXPR_LOCATION, but only do that if T has
5588 : : UNKNOWN_LOCATION. */
5589 : :
5590 : : void
5591 : 20820063 : protected_set_expr_location_if_unset (tree t, location_t loc)
5592 : : {
5593 : 20820063 : t = expr_single (t);
5594 : 20820063 : if (t && !EXPR_HAS_LOCATION (t))
5595 : 15597338 : protected_set_expr_location (t, loc);
5596 : 20820063 : }
5597 : :
5598 : : /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5599 : : of the various TYPE_QUAL values. */
5600 : :
5601 : : static void
5602 : 88939609 : set_type_quals (tree type, int type_quals)
5603 : : {
5604 : 88939609 : TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
5605 : 88939609 : TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
5606 : 88939609 : TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
5607 : 88939609 : TYPE_ATOMIC (type) = (type_quals & TYPE_QUAL_ATOMIC) != 0;
5608 : 88939609 : TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals);
5609 : 88939609 : }
5610 : :
5611 : : /* Returns true iff CAND and BASE have equivalent language-specific
5612 : : qualifiers. */
5613 : :
5614 : : bool
5615 : 2319423678 : check_lang_type (const_tree cand, const_tree base)
5616 : : {
5617 : 2319423678 : if (lang_hooks.types.type_hash_eq == NULL)
5618 : : return true;
5619 : : /* type_hash_eq currently only applies to these types. */
5620 : 2264720542 : if (TREE_CODE (cand) != FUNCTION_TYPE
5621 : 2264720542 : && TREE_CODE (cand) != METHOD_TYPE)
5622 : : return true;
5623 : 1050369 : return lang_hooks.types.type_hash_eq (cand, base);
5624 : : }
5625 : :
5626 : : /* This function checks to see if TYPE matches the size one of the built-in
5627 : : atomic types, and returns that core atomic type. */
5628 : :
5629 : : static tree
5630 : 8283 : find_atomic_core_type (const_tree type)
5631 : : {
5632 : 8283 : tree base_atomic_type;
5633 : :
5634 : : /* Only handle complete types. */
5635 : 8283 : if (!tree_fits_uhwi_p (TYPE_SIZE (type)))
5636 : : return NULL_TREE;
5637 : :
5638 : 8278 : switch (tree_to_uhwi (TYPE_SIZE (type)))
5639 : : {
5640 : 2446 : case 8:
5641 : 2446 : base_atomic_type = atomicQI_type_node;
5642 : 2446 : break;
5643 : :
5644 : 786 : case 16:
5645 : 786 : base_atomic_type = atomicHI_type_node;
5646 : 786 : break;
5647 : :
5648 : 987 : case 32:
5649 : 987 : base_atomic_type = atomicSI_type_node;
5650 : 987 : break;
5651 : :
5652 : 2630 : case 64:
5653 : 2630 : base_atomic_type = atomicDI_type_node;
5654 : 2630 : break;
5655 : :
5656 : 1309 : case 128:
5657 : 1309 : base_atomic_type = atomicTI_type_node;
5658 : 1309 : break;
5659 : :
5660 : : default:
5661 : : base_atomic_type = NULL_TREE;
5662 : : }
5663 : :
5664 : : return base_atomic_type;
5665 : : }
5666 : :
5667 : : /* Returns true iff unqualified CAND and BASE are equivalent. */
5668 : :
5669 : : bool
5670 : 3689695291 : check_base_type (const_tree cand, const_tree base)
5671 : : {
5672 : 3689695291 : if (TYPE_NAME (cand) != TYPE_NAME (base)
5673 : : /* Apparently this is needed for Objective-C. */
5674 : 3363706740 : || TYPE_CONTEXT (cand) != TYPE_CONTEXT (base)
5675 : 7053402031 : || !attribute_list_equal (TYPE_ATTRIBUTES (cand),
5676 : 3363706740 : TYPE_ATTRIBUTES (base)))
5677 : 325988551 : return false;
5678 : : /* Check alignment. */
5679 : 3363706740 : if (TYPE_ALIGN (cand) == TYPE_ALIGN (base)
5680 : 3363706740 : && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base))
5681 : : return true;
5682 : : /* Atomic types increase minimal alignment. We must to do so as well
5683 : : or we get duplicated canonical types. See PR88686. */
5684 : 10908 : if ((TYPE_QUALS (cand) & TYPE_QUAL_ATOMIC))
5685 : : {
5686 : : /* See if this object can map to a basic atomic type. */
5687 : 1775 : tree atomic_type = find_atomic_core_type (cand);
5688 : 1775 : if (atomic_type && TYPE_ALIGN (atomic_type) == TYPE_ALIGN (cand))
5689 : : return true;
5690 : : }
5691 : : return false;
5692 : : }
5693 : :
5694 : : /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
5695 : :
5696 : : bool
5697 : 3901773211 : check_qualified_type (const_tree cand, const_tree base, int type_quals)
5698 : : {
5699 : 3901773211 : return (TYPE_QUALS (cand) == type_quals
5700 : 2643682635 : && check_base_type (cand, base)
5701 : 6219561306 : && check_lang_type (cand, base));
5702 : : }
5703 : :
5704 : : /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5705 : :
5706 : : static bool
5707 : 3235360 : check_aligned_type (const_tree cand, const_tree base, unsigned int align)
5708 : : {
5709 : 3235360 : return (TYPE_QUALS (cand) == TYPE_QUALS (base)
5710 : 2678669 : && TYPE_NAME (cand) == TYPE_NAME (base)
5711 : : /* Apparently this is needed for Objective-C. */
5712 : 1902100 : && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
5713 : : /* Check alignment. */
5714 : 1902100 : && TYPE_ALIGN (cand) == align
5715 : : /* Check this is a user-aligned type as build_aligned_type
5716 : : would create. */
5717 : 903343 : && TYPE_USER_ALIGN (cand)
5718 : 900184 : && attribute_list_equal (TYPE_ATTRIBUTES (cand),
5719 : 900184 : TYPE_ATTRIBUTES (base))
5720 : 4135544 : && check_lang_type (cand, base));
5721 : : }
5722 : :
5723 : : /* Return a version of the TYPE, qualified as indicated by the
5724 : : TYPE_QUALS, if one exists. If no qualified version exists yet,
5725 : : return NULL_TREE. */
5726 : :
5727 : : tree
5728 : 3645126223 : get_qualified_type (tree type, int type_quals)
5729 : : {
5730 : 3645126223 : if (TYPE_QUALS (type) == type_quals)
5731 : : return type;
5732 : :
5733 : 2406779011 : tree mv = TYPE_MAIN_VARIANT (type);
5734 : 2406779011 : if (check_qualified_type (mv, type, type_quals))
5735 : : return mv;
5736 : :
5737 : : /* Search the chain of variants to see if there is already one there just
5738 : : like the one we need to have. If so, use that existing one. We must
5739 : : preserve the TYPE_NAME, since there is code that depends on this. */
5740 : 1583998954 : for (tree *tp = &TYPE_NEXT_VARIANT (mv); *tp; tp = &TYPE_NEXT_VARIANT (*tp))
5741 : 1494933102 : if (check_qualified_type (*tp, type, type_quals))
5742 : : {
5743 : : /* Put the found variant at the head of the variant list so
5744 : : frequently searched variants get found faster. The C++ FE
5745 : : benefits greatly from this. */
5746 : 994869065 : tree t = *tp;
5747 : 994869065 : *tp = TYPE_NEXT_VARIANT (t);
5748 : 994869065 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
5749 : 994869065 : TYPE_NEXT_VARIANT (mv) = t;
5750 : 994869065 : return t;
5751 : : }
5752 : :
5753 : : return NULL_TREE;
5754 : : }
5755 : :
5756 : : /* Like get_qualified_type, but creates the type if it does not
5757 : : exist. This function never returns NULL_TREE. */
5758 : :
5759 : : tree
5760 : 3263574281 : build_qualified_type (tree type, int type_quals MEM_STAT_DECL)
5761 : : {
5762 : 3263574281 : tree t;
5763 : :
5764 : : /* See if we already have the appropriate qualified variant. */
5765 : 3263574281 : t = get_qualified_type (type, type_quals);
5766 : :
5767 : : /* If not, build it. */
5768 : 3263574281 : if (!t)
5769 : : {
5770 : 87515689 : t = build_variant_type_copy (type PASS_MEM_STAT);
5771 : 87515689 : set_type_quals (t, type_quals);
5772 : :
5773 : 87515689 : if (((type_quals & TYPE_QUAL_ATOMIC) == TYPE_QUAL_ATOMIC))
5774 : : {
5775 : : /* See if this object can map to a basic atomic type. */
5776 : 6508 : tree atomic_type = find_atomic_core_type (type);
5777 : 6508 : if (atomic_type)
5778 : : {
5779 : : /* Ensure the alignment of this type is compatible with
5780 : : the required alignment of the atomic type. */
5781 : 6383 : if (TYPE_ALIGN (atomic_type) > TYPE_ALIGN (t))
5782 : 94 : SET_TYPE_ALIGN (t, TYPE_ALIGN (atomic_type));
5783 : : }
5784 : : }
5785 : :
5786 : 87515689 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5787 : : /* Propagate structural equality. */
5788 : 4239713 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5789 : 83275976 : else if (TYPE_CANONICAL (type) != type)
5790 : : /* Build the underlying canonical type, since it is different
5791 : : from TYPE. */
5792 : : {
5793 : 27171459 : tree c = build_qualified_type (TYPE_CANONICAL (type), type_quals);
5794 : 27171459 : TYPE_CANONICAL (t) = TYPE_CANONICAL (c);
5795 : : }
5796 : : else
5797 : : /* T is its own canonical type. */
5798 : 56104517 : TYPE_CANONICAL (t) = t;
5799 : :
5800 : : }
5801 : :
5802 : 3263574281 : return t;
5803 : : }
5804 : :
5805 : : /* Create a variant of type T with alignment ALIGN which
5806 : : is measured in bits. */
5807 : :
5808 : : tree
5809 : 1177728 : build_aligned_type (tree type, unsigned int align)
5810 : : {
5811 : 1177728 : tree t;
5812 : :
5813 : 1177728 : if (TYPE_PACKED (type)
5814 : 1177728 : || TYPE_ALIGN (type) == align)
5815 : : return type;
5816 : :
5817 : 3332116 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
5818 : 3235360 : if (check_aligned_type (t, type, align))
5819 : : return t;
5820 : :
5821 : 96756 : t = build_variant_type_copy (type);
5822 : 96756 : SET_TYPE_ALIGN (t, align);
5823 : 96756 : TYPE_USER_ALIGN (t) = 1;
5824 : :
5825 : 96756 : return t;
5826 : : }
5827 : :
5828 : : /* Create a new distinct copy of TYPE. The new type is made its own
5829 : : MAIN_VARIANT. If TYPE requires structural equality checks, the
5830 : : resulting type requires structural equality checks; otherwise, its
5831 : : TYPE_CANONICAL points to itself. */
5832 : :
5833 : : tree
5834 : 672999065 : build_distinct_type_copy (tree type MEM_STAT_DECL)
5835 : : {
5836 : 672999065 : tree t = copy_node (type PASS_MEM_STAT);
5837 : :
5838 : 672999065 : TYPE_POINTER_TO (t) = 0;
5839 : 672999065 : TYPE_REFERENCE_TO (t) = 0;
5840 : :
5841 : : /* Set the canonical type either to a new equivalence class, or
5842 : : propagate the need for structural equality checks. */
5843 : 672999065 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5844 : 56291200 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5845 : : else
5846 : 616707865 : TYPE_CANONICAL (t) = t;
5847 : :
5848 : : /* Make it its own variant. */
5849 : 672999065 : TYPE_MAIN_VARIANT (t) = t;
5850 : 672999065 : TYPE_NEXT_VARIANT (t) = 0;
5851 : :
5852 : : /* Note that it is now possible for TYPE_MIN_VALUE to be a value
5853 : : whose TREE_TYPE is not t. This can also happen in the Ada
5854 : : frontend when using subtypes. */
5855 : :
5856 : 672999065 : return t;
5857 : : }
5858 : :
5859 : : /* Create a new variant of TYPE, equivalent but distinct. This is so
5860 : : the caller can modify it. TYPE_CANONICAL for the return type will
5861 : : be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
5862 : : are considered equal by the language itself (or that both types
5863 : : require structural equality checks). */
5864 : :
5865 : : tree
5866 : 402281357 : build_variant_type_copy (tree type MEM_STAT_DECL)
5867 : : {
5868 : 402281357 : tree t, m = TYPE_MAIN_VARIANT (type);
5869 : :
5870 : 402281357 : t = build_distinct_type_copy (type PASS_MEM_STAT);
5871 : :
5872 : : /* Since we're building a variant, assume that it is a non-semantic
5873 : : variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
5874 : 402281357 : TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
5875 : : /* Type variants have no alias set defined. */
5876 : 402281357 : TYPE_ALIAS_SET (t) = -1;
5877 : :
5878 : : /* Add the new type to the chain of variants of TYPE. */
5879 : 402281357 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
5880 : 402281357 : TYPE_NEXT_VARIANT (m) = t;
5881 : 402281357 : TYPE_MAIN_VARIANT (t) = m;
5882 : :
5883 : 402281357 : return t;
5884 : : }
5885 : :
5886 : : /* Return true if the from tree in both tree maps are equal. */
5887 : :
5888 : : int
5889 : 1821148345 : tree_map_base_eq (const void *va, const void *vb)
5890 : : {
5891 : 1821148345 : const struct tree_map_base *const a = (const struct tree_map_base *) va,
5892 : 1821148345 : *const b = (const struct tree_map_base *) vb;
5893 : 1821148345 : return (a->from == b->from);
5894 : : }
5895 : :
5896 : : /* Hash a from tree in a tree_base_map. */
5897 : :
5898 : : unsigned int
5899 : 0 : tree_map_base_hash (const void *item)
5900 : : {
5901 : 0 : return htab_hash_pointer (((const struct tree_map_base *)item)->from);
5902 : : }
5903 : :
5904 : : /* Return true if this tree map structure is marked for garbage collection
5905 : : purposes. We simply return true if the from tree is marked, so that this
5906 : : structure goes away when the from tree goes away. */
5907 : :
5908 : : bool
5909 : 0 : tree_map_base_marked_p (const void *p)
5910 : : {
5911 : 0 : return ggc_marked_p (((const struct tree_map_base *) p)->from);
5912 : : }
5913 : :
5914 : : /* Hash a from tree in a tree_map. */
5915 : :
5916 : : unsigned int
5917 : 203 : tree_map_hash (const void *item)
5918 : : {
5919 : 203 : return (((const struct tree_map *) item)->hash);
5920 : : }
5921 : :
5922 : : /* Hash a from tree in a tree_decl_map. */
5923 : :
5924 : : unsigned int
5925 : 1243065890 : tree_decl_map_hash (const void *item)
5926 : : {
5927 : 1243065890 : return DECL_UID (((const struct tree_decl_map *) item)->base.from);
5928 : : }
5929 : :
5930 : : /* Return the initialization priority for DECL. */
5931 : :
5932 : : priority_type
5933 : 22384 : decl_init_priority_lookup (tree decl)
5934 : : {
5935 : 22384 : symtab_node *snode = symtab_node::get (decl);
5936 : :
5937 : 22384 : if (!snode)
5938 : : return DEFAULT_INIT_PRIORITY;
5939 : 22384 : return
5940 : 22384 : snode->get_init_priority ();
5941 : : }
5942 : :
5943 : : /* Return the finalization priority for DECL. */
5944 : :
5945 : : priority_type
5946 : 1795 : decl_fini_priority_lookup (tree decl)
5947 : : {
5948 : 1795 : cgraph_node *node = cgraph_node::get (decl);
5949 : :
5950 : 1795 : if (!node)
5951 : : return DEFAULT_INIT_PRIORITY;
5952 : 1795 : return
5953 : 1795 : node->get_fini_priority ();
5954 : : }
5955 : :
5956 : : /* Set the initialization priority for DECL to PRIORITY. */
5957 : :
5958 : : void
5959 : 23817 : decl_init_priority_insert (tree decl, priority_type priority)
5960 : : {
5961 : 23817 : struct symtab_node *snode;
5962 : :
5963 : 23817 : if (priority == DEFAULT_INIT_PRIORITY)
5964 : : {
5965 : 20283 : snode = symtab_node::get (decl);
5966 : 20283 : if (!snode)
5967 : : return;
5968 : : }
5969 : 3534 : else if (VAR_P (decl))
5970 : 45 : snode = varpool_node::get_create (decl);
5971 : : else
5972 : 3489 : snode = cgraph_node::get_create (decl);
5973 : 23101 : snode->set_init_priority (priority);
5974 : : }
5975 : :
5976 : : /* Set the finalization priority for DECL to PRIORITY. */
5977 : :
5978 : : void
5979 : 1654 : decl_fini_priority_insert (tree decl, priority_type priority)
5980 : : {
5981 : 1654 : struct cgraph_node *node;
5982 : :
5983 : 1654 : if (priority == DEFAULT_INIT_PRIORITY)
5984 : : {
5985 : 104 : node = cgraph_node::get (decl);
5986 : 104 : if (!node)
5987 : : return;
5988 : : }
5989 : : else
5990 : 1550 : node = cgraph_node::get_create (decl);
5991 : 1559 : node->set_fini_priority (priority);
5992 : : }
5993 : :
5994 : : /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
5995 : :
5996 : : static void
5997 : 0 : print_debug_expr_statistics (void)
5998 : : {
5999 : 0 : fprintf (stderr, "DECL_DEBUG_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6000 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6001 : 0 : (fmt_size_t) debug_expr_for_decl->size (),
6002 : 0 : (fmt_size_t) debug_expr_for_decl->elements (),
6003 : : debug_expr_for_decl->collisions ());
6004 : 0 : }
6005 : :
6006 : : /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6007 : :
6008 : : static void
6009 : 0 : print_value_expr_statistics (void)
6010 : : {
6011 : 0 : fprintf (stderr, "DECL_VALUE_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6012 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6013 : 0 : (fmt_size_t) value_expr_for_decl->size (),
6014 : 0 : (fmt_size_t) value_expr_for_decl->elements (),
6015 : : value_expr_for_decl->collisions ());
6016 : 0 : }
6017 : :
6018 : : /* Lookup a debug expression for FROM, and return it if we find one. */
6019 : :
6020 : : tree
6021 : 446071316 : decl_debug_expr_lookup (tree from)
6022 : : {
6023 : 446071316 : struct tree_decl_map *h, in;
6024 : 446071316 : in.base.from = from;
6025 : :
6026 : 446071316 : h = debug_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6027 : 446071316 : if (h)
6028 : 446071316 : return h->to;
6029 : : return NULL_TREE;
6030 : : }
6031 : :
6032 : : /* Insert a mapping FROM->TO in the debug expression hashtable. */
6033 : :
6034 : : void
6035 : 1335558 : decl_debug_expr_insert (tree from, tree to)
6036 : : {
6037 : 1335558 : struct tree_decl_map *h;
6038 : :
6039 : 1335558 : h = ggc_alloc<tree_decl_map> ();
6040 : 1335558 : h->base.from = from;
6041 : 1335558 : h->to = to;
6042 : 1335558 : *debug_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6043 : 1335558 : }
6044 : :
6045 : : /* Lookup a value expression for FROM, and return it if we find one. */
6046 : :
6047 : : tree
6048 : 11387651 : decl_value_expr_lookup (tree from)
6049 : : {
6050 : 11387651 : struct tree_decl_map *h, in;
6051 : 11387651 : in.base.from = from;
6052 : :
6053 : 11387651 : h = value_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6054 : 11387651 : if (h)
6055 : 11387651 : return h->to;
6056 : : return NULL_TREE;
6057 : : }
6058 : :
6059 : : /* Insert a mapping FROM->TO in the value expression hashtable. */
6060 : :
6061 : : void
6062 : 4183569 : decl_value_expr_insert (tree from, tree to)
6063 : : {
6064 : 4183569 : struct tree_decl_map *h;
6065 : :
6066 : : /* Uses of FROM shouldn't look like they happen at the location of TO. */
6067 : 4183569 : to = protected_set_expr_location_unshare (to, UNKNOWN_LOCATION);
6068 : :
6069 : 4183569 : h = ggc_alloc<tree_decl_map> ();
6070 : 4183569 : h->base.from = from;
6071 : 4183569 : h->to = to;
6072 : 4183569 : *value_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6073 : 4183569 : }
6074 : :
6075 : : /* Lookup a vector of debug arguments for FROM, and return it if we
6076 : : find one. */
6077 : :
6078 : : vec<tree, va_gc> **
6079 : 820327 : decl_debug_args_lookup (tree from)
6080 : : {
6081 : 820327 : struct tree_vec_map *h, in;
6082 : :
6083 : 820327 : if (!DECL_HAS_DEBUG_ARGS_P (from))
6084 : : return NULL;
6085 : 689008 : gcc_checking_assert (debug_args_for_decl != NULL);
6086 : 689008 : in.base.from = from;
6087 : 689008 : h = debug_args_for_decl->find_with_hash (&in, DECL_UID (from));
6088 : 689008 : if (h)
6089 : 685793 : return &h->to;
6090 : : return NULL;
6091 : : }
6092 : :
6093 : : /* Insert a mapping FROM->empty vector of debug arguments in the value
6094 : : expression hashtable. */
6095 : :
6096 : : vec<tree, va_gc> **
6097 : 247421 : decl_debug_args_insert (tree from)
6098 : : {
6099 : 247421 : struct tree_vec_map *h;
6100 : 247421 : tree_vec_map **loc;
6101 : :
6102 : 247421 : if (DECL_HAS_DEBUG_ARGS_P (from))
6103 : 164977 : return decl_debug_args_lookup (from);
6104 : 82444 : if (debug_args_for_decl == NULL)
6105 : 8250 : debug_args_for_decl = hash_table<tree_vec_map_cache_hasher>::create_ggc (64);
6106 : 82444 : h = ggc_alloc<tree_vec_map> ();
6107 : 82444 : h->base.from = from;
6108 : 82444 : h->to = NULL;
6109 : 82444 : loc = debug_args_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT);
6110 : 82444 : *loc = h;
6111 : 82444 : DECL_HAS_DEBUG_ARGS_P (from) = 1;
6112 : 82444 : return &h->to;
6113 : : }
6114 : :
6115 : : /* Hashing of types so that we don't make duplicates.
6116 : : The entry point is `type_hash_canon'. */
6117 : :
6118 : : /* Generate the default hash code for TYPE. This is designed for
6119 : : speed, rather than maximum entropy. */
6120 : :
6121 : : hashval_t
6122 : 1282675491 : type_hash_canon_hash (tree type)
6123 : : {
6124 : 1282675491 : inchash::hash hstate;
6125 : :
6126 : 1282675491 : hstate.add_int (TREE_CODE (type));
6127 : :
6128 : 1282675491 : hstate.add_flag (TYPE_STRUCTURAL_EQUALITY_P (type));
6129 : :
6130 : 1282675491 : if (TREE_TYPE (type))
6131 : 1282653676 : hstate.add_object (TYPE_HASH (TREE_TYPE (type)));
6132 : :
6133 : 1554347238 : for (tree t = TYPE_ATTRIBUTES (type); t; t = TREE_CHAIN (t))
6134 : : /* Just the identifier is adequate to distinguish. */
6135 : 271671747 : hstate.add_object (IDENTIFIER_HASH_VALUE (get_attribute_name (t)));
6136 : :
6137 : 1282675491 : switch (TREE_CODE (type))
6138 : : {
6139 : 281185779 : case METHOD_TYPE:
6140 : 281185779 : hstate.add_object (TYPE_HASH (TYPE_METHOD_BASETYPE (type)));
6141 : : /* FALLTHROUGH. */
6142 : 1109110525 : case FUNCTION_TYPE:
6143 : 4407718637 : for (tree t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
6144 : 3298608112 : if (TREE_VALUE (t) != error_mark_node)
6145 : 3298604241 : hstate.add_object (TYPE_HASH (TREE_VALUE (t)));
6146 : : break;
6147 : :
6148 : 946344 : case OFFSET_TYPE:
6149 : 946344 : hstate.add_object (TYPE_HASH (TYPE_OFFSET_BASETYPE (type)));
6150 : 946344 : break;
6151 : :
6152 : 59974565 : case ARRAY_TYPE:
6153 : 59974565 : {
6154 : 59974565 : if (TYPE_DOMAIN (type))
6155 : 58393674 : hstate.add_object (TYPE_HASH (TYPE_DOMAIN (type)));
6156 : 59974565 : if (!AGGREGATE_TYPE_P (TREE_TYPE (type)))
6157 : : {
6158 : 58659011 : unsigned typeless = TYPE_TYPELESS_STORAGE (type);
6159 : 58659011 : hstate.add_object (typeless);
6160 : : }
6161 : : }
6162 : : break;
6163 : :
6164 : 36312923 : case INTEGER_TYPE:
6165 : 36312923 : {
6166 : 36312923 : tree t = TYPE_MAX_VALUE (type);
6167 : 36312923 : if (!t)
6168 : 540020 : t = TYPE_MIN_VALUE (type);
6169 : 72625847 : for (int i = 0; i < TREE_INT_CST_NUNITS (t); i++)
6170 : 36312924 : hstate.add_object (TREE_INT_CST_ELT (t, i));
6171 : : break;
6172 : : }
6173 : :
6174 : 1 : case BITINT_TYPE:
6175 : 1 : {
6176 : 1 : unsigned prec = TYPE_PRECISION (type);
6177 : 1 : unsigned uns = TYPE_UNSIGNED (type);
6178 : 1 : hstate.add_object (prec);
6179 : 1 : hstate.add_int (uns);
6180 : 1 : break;
6181 : : }
6182 : :
6183 : 11684 : case REAL_TYPE:
6184 : 11684 : case FIXED_POINT_TYPE:
6185 : 11684 : {
6186 : 11684 : unsigned prec = TYPE_PRECISION (type);
6187 : 11684 : hstate.add_object (prec);
6188 : 11684 : break;
6189 : : }
6190 : :
6191 : 70913559 : case VECTOR_TYPE:
6192 : 70913559 : hstate.add_poly_int (TYPE_VECTOR_SUBPARTS (type));
6193 : 70913559 : break;
6194 : :
6195 : : case REFERENCE_TYPE:
6196 : 1282675491 : hstate.add_flag (TYPE_REF_IS_RVALUE (type));
6197 : : break;
6198 : :
6199 : : default:
6200 : : break;
6201 : : }
6202 : :
6203 : 1282675491 : return hstate.end ();
6204 : : }
6205 : :
6206 : : /* These are the Hashtable callback functions. */
6207 : :
6208 : : /* Returns true iff the types are equivalent. */
6209 : :
6210 : : bool
6211 : 8272571172 : type_cache_hasher::equal (type_hash *a, type_hash *b)
6212 : : {
6213 : : /* First test the things that are the same for all types. */
6214 : 8272571172 : if (a->hash != b->hash
6215 : 639737053 : || TREE_CODE (a->type) != TREE_CODE (b->type)
6216 : 639729488 : || TREE_TYPE (a->type) != TREE_TYPE (b->type)
6217 : 639729016 : || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
6218 : 639729016 : TYPE_ATTRIBUTES (b->type))
6219 : 8905345670 : || (TREE_CODE (a->type) != COMPLEX_TYPE
6220 : 630736484 : && TYPE_NAME (a->type) != TYPE_NAME (b->type)))
6221 : 7640672203 : return false;
6222 : :
6223 : : /* Be careful about comparing arrays before and after the element type
6224 : : has been completed; don't compare TYPE_ALIGN unless both types are
6225 : : complete. */
6226 : 1261967597 : if (COMPLETE_TYPE_P (a->type) && COMPLETE_TYPE_P (b->type)
6227 : 1261967597 : && (TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
6228 : 630068072 : || TYPE_MODE (a->type) != TYPE_MODE (b->type)))
6229 : 669 : return false;
6230 : :
6231 : 631898300 : if (TYPE_STRUCTURAL_EQUALITY_P (a->type)
6232 : 631898300 : != TYPE_STRUCTURAL_EQUALITY_P (b->type))
6233 : : return false;
6234 : :
6235 : 631894913 : switch (TREE_CODE (a->type))
6236 : : {
6237 : : case VOID_TYPE:
6238 : : case OPAQUE_TYPE:
6239 : : case COMPLEX_TYPE:
6240 : : case POINTER_TYPE:
6241 : : case NULLPTR_TYPE:
6242 : : return true;
6243 : :
6244 : 64716868 : case VECTOR_TYPE:
6245 : 64716868 : return known_eq (TYPE_VECTOR_SUBPARTS (a->type),
6246 : : TYPE_VECTOR_SUBPARTS (b->type));
6247 : :
6248 : 0 : case ENUMERAL_TYPE:
6249 : 0 : if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
6250 : 0 : && !(TYPE_VALUES (a->type)
6251 : 0 : && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
6252 : 0 : && TYPE_VALUES (b->type)
6253 : 0 : && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
6254 : 0 : && type_list_equal (TYPE_VALUES (a->type),
6255 : 0 : TYPE_VALUES (b->type))))
6256 : 0 : return false;
6257 : :
6258 : : /* fall through */
6259 : :
6260 : 33774568 : case INTEGER_TYPE:
6261 : 33774568 : case REAL_TYPE:
6262 : 33774568 : case BOOLEAN_TYPE:
6263 : 33774568 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6264 : : return false;
6265 : 33768939 : return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
6266 : 776169 : || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
6267 : 776169 : TYPE_MAX_VALUE (b->type)))
6268 : 34131838 : && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
6269 : 482594 : || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
6270 : 482594 : TYPE_MIN_VALUE (b->type))));
6271 : :
6272 : 1531567 : case BITINT_TYPE:
6273 : 1531567 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6274 : : return false;
6275 : 1484873 : return TYPE_UNSIGNED (a->type) == TYPE_UNSIGNED (b->type);
6276 : :
6277 : 0 : case FIXED_POINT_TYPE:
6278 : 0 : return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
6279 : :
6280 : 752558 : case OFFSET_TYPE:
6281 : 752558 : return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
6282 : :
6283 : 81076585 : case METHOD_TYPE:
6284 : 81076585 : if (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
6285 : 81076585 : && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6286 : 81028673 : || (TYPE_ARG_TYPES (a->type)
6287 : 81028673 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6288 : 81028673 : && TYPE_ARG_TYPES (b->type)
6289 : 81028673 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6290 : 81028673 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6291 : 81028673 : TYPE_ARG_TYPES (b->type)))))
6292 : : break;
6293 : : return false;
6294 : 50081006 : case ARRAY_TYPE:
6295 : : /* Don't compare TYPE_TYPELESS_STORAGE flag on aggregates,
6296 : : where the flag should be inherited from the element type
6297 : : and can change after ARRAY_TYPEs are created; on non-aggregates
6298 : : compare it and hash it, scalars will never have that flag set
6299 : : and we need to differentiate between arrays created by different
6300 : : front-ends or middle-end created arrays. */
6301 : 50081006 : return (TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type)
6302 : 50081006 : && (AGGREGATE_TYPE_P (TREE_TYPE (a->type))
6303 : 49375639 : || (TYPE_TYPELESS_STORAGE (a->type)
6304 : 49375639 : == TYPE_TYPELESS_STORAGE (b->type))));
6305 : :
6306 : 0 : case RECORD_TYPE:
6307 : 0 : case UNION_TYPE:
6308 : 0 : case QUAL_UNION_TYPE:
6309 : 0 : return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
6310 : 0 : || (TYPE_FIELDS (a->type)
6311 : 0 : && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
6312 : 0 : && TYPE_FIELDS (b->type)
6313 : 0 : && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
6314 : 0 : && type_list_equal (TYPE_FIELDS (a->type),
6315 : 0 : TYPE_FIELDS (b->type))));
6316 : :
6317 : 397923259 : case FUNCTION_TYPE:
6318 : 397923259 : if ((TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6319 : 251565336 : && (TYPE_NO_NAMED_ARGS_STDARG_P (a->type)
6320 : 251565336 : == TYPE_NO_NAMED_ARGS_STDARG_P (b->type)))
6321 : 398235008 : || (TYPE_ARG_TYPES (a->type)
6322 : 146357923 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6323 : 146357923 : && TYPE_ARG_TYPES (b->type)
6324 : 146357923 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6325 : 146357923 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6326 : 146357923 : TYPE_ARG_TYPES (b->type))))
6327 : : break;
6328 : : return false;
6329 : :
6330 : 9 : case REFERENCE_TYPE:
6331 : 9 : return TYPE_REF_IS_RVALUE (a->type) == TYPE_REF_IS_RVALUE (b->type);
6332 : :
6333 : : default:
6334 : : return false;
6335 : : }
6336 : :
6337 : 454808198 : if (lang_hooks.types.type_hash_eq != NULL)
6338 : 278084273 : return lang_hooks.types.type_hash_eq (a->type, b->type);
6339 : :
6340 : : return true;
6341 : : }
6342 : :
6343 : : /* Given TYPE, and HASHCODE its hash code, return the canonical
6344 : : object for an identical type if one already exists.
6345 : : Otherwise, return TYPE, and record it as the canonical object.
6346 : :
6347 : : To use this function, first create a type of the sort you want.
6348 : : Then compute its hash code from the fields of the type that
6349 : : make it different from other similar types.
6350 : : Then call this function and use the value. */
6351 : :
6352 : : tree
6353 : 1285211090 : type_hash_canon (unsigned int hashcode, tree type)
6354 : : {
6355 : 1285211090 : type_hash in;
6356 : 1285211090 : type_hash **loc;
6357 : :
6358 : : /* The hash table only contains main variants, so ensure that's what we're
6359 : : being passed. */
6360 : 1285211090 : gcc_assert (TYPE_MAIN_VARIANT (type) == type);
6361 : :
6362 : : /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6363 : : must call that routine before comparing TYPE_ALIGNs. */
6364 : 1285211090 : layout_type (type);
6365 : :
6366 : 1285211090 : in.hash = hashcode;
6367 : 1285211090 : in.type = type;
6368 : :
6369 : 1285211090 : loc = type_hash_table->find_slot_with_hash (&in, hashcode, INSERT);
6370 : 1285211090 : if (*loc)
6371 : : {
6372 : 607116959 : tree t1 = ((type_hash *) *loc)->type;
6373 : 607116959 : gcc_assert (TYPE_MAIN_VARIANT (t1) == t1
6374 : : && t1 != type);
6375 : 607116959 : if (TYPE_UID (type) + 1 == next_type_uid)
6376 : 602066353 : --next_type_uid;
6377 : : /* Free also min/max values and the cache for integer
6378 : : types. This can't be done in free_node, as LTO frees
6379 : : those on its own. */
6380 : 607116959 : if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == BITINT_TYPE)
6381 : : {
6382 : 34719824 : if (TYPE_MIN_VALUE (type)
6383 : 34719824 : && TREE_TYPE (TYPE_MIN_VALUE (type)) == type)
6384 : : {
6385 : : /* Zero is always in TYPE_CACHED_VALUES. */
6386 : 1846193 : if (! TYPE_UNSIGNED (type))
6387 : 1647684 : int_cst_hash_table->remove_elt (TYPE_MIN_VALUE (type));
6388 : 1846193 : ggc_free (TYPE_MIN_VALUE (type));
6389 : : }
6390 : 34719824 : if (TYPE_MAX_VALUE (type)
6391 : 34719824 : && TREE_TYPE (TYPE_MAX_VALUE (type)) == type)
6392 : : {
6393 : 1846193 : int_cst_hash_table->remove_elt (TYPE_MAX_VALUE (type));
6394 : 1846193 : ggc_free (TYPE_MAX_VALUE (type));
6395 : : }
6396 : 34719824 : if (TYPE_CACHED_VALUES_P (type))
6397 : 198509 : ggc_free (TYPE_CACHED_VALUES (type));
6398 : : }
6399 : 607116959 : free_node (type);
6400 : 607116959 : return t1;
6401 : : }
6402 : : else
6403 : : {
6404 : 678094131 : struct type_hash *h;
6405 : :
6406 : 678094131 : h = ggc_alloc<type_hash> ();
6407 : 678094131 : h->hash = hashcode;
6408 : 678094131 : h->type = type;
6409 : 678094131 : *loc = h;
6410 : :
6411 : 678094131 : return type;
6412 : : }
6413 : : }
6414 : :
6415 : : static void
6416 : 0 : print_type_hash_statistics (void)
6417 : : {
6418 : 0 : fprintf (stderr, "Type hash: size " HOST_SIZE_T_PRINT_DEC ", "
6419 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6420 : 0 : (fmt_size_t) type_hash_table->size (),
6421 : 0 : (fmt_size_t) type_hash_table->elements (),
6422 : : type_hash_table->collisions ());
6423 : 0 : }
6424 : :
6425 : : /* Given two lists of types
6426 : : (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6427 : : return 1 if the lists contain the same types in the same order.
6428 : : Also, the TREE_PURPOSEs must match. */
6429 : :
6430 : : bool
6431 : 227387119 : type_list_equal (const_tree l1, const_tree l2)
6432 : : {
6433 : 227387119 : const_tree t1, t2;
6434 : :
6435 : 860432797 : for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
6436 : 656925347 : if (TREE_VALUE (t1) != TREE_VALUE (t2)
6437 : 656925347 : || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
6438 : 23880913 : && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
6439 : 1274 : && (TREE_TYPE (TREE_PURPOSE (t1))
6440 : 1274 : == TREE_TYPE (TREE_PURPOSE (t2))))))
6441 : 23879669 : return false;
6442 : :
6443 : 203507450 : return t1 == t2;
6444 : : }
6445 : :
6446 : : /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6447 : : given by TYPE. If the argument list accepts variable arguments,
6448 : : then this function counts only the ordinary arguments. */
6449 : :
6450 : : int
6451 : 75111814 : type_num_arguments (const_tree fntype)
6452 : : {
6453 : 75111814 : int i = 0;
6454 : :
6455 : 289050793 : for (tree t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
6456 : : /* If the function does not take a variable number of arguments,
6457 : : the last element in the list will have type `void'. */
6458 : 270556369 : if (VOID_TYPE_P (TREE_VALUE (t)))
6459 : : break;
6460 : : else
6461 : 213938979 : ++i;
6462 : :
6463 : 75111814 : return i;
6464 : : }
6465 : :
6466 : : /* Return the type of the function TYPE's argument ARGNO if known.
6467 : : For vararg function's where ARGNO refers to one of the variadic
6468 : : arguments return null. Otherwise, return a void_type_node for
6469 : : out-of-bounds ARGNO. */
6470 : :
6471 : : tree
6472 : 74629406 : type_argument_type (const_tree fntype, unsigned argno)
6473 : : {
6474 : : /* Treat zero the same as an out-of-bounds argument number. */
6475 : 74629406 : if (!argno)
6476 : 0 : return void_type_node;
6477 : :
6478 : 74629406 : function_args_iterator iter;
6479 : :
6480 : 74629406 : tree argtype;
6481 : 74629406 : unsigned i = 1;
6482 : 159886121 : FOREACH_FUNCTION_ARGS (fntype, argtype, iter)
6483 : : {
6484 : : /* A vararg function's argument list ends in a null. Otherwise,
6485 : : an ordinary function's argument list ends with void. Return
6486 : : null if ARGNO refers to a vararg argument, void_type_node if
6487 : : it's out of bounds, and the formal argument type otherwise. */
6488 : 154338340 : if (!argtype)
6489 : : break;
6490 : :
6491 : 154338340 : if (i == argno || VOID_TYPE_P (argtype))
6492 : : return argtype;
6493 : :
6494 : 85256715 : ++i;
6495 : : }
6496 : :
6497 : : return NULL_TREE;
6498 : : }
6499 : :
6500 : : /* True if integer constants T1 and T2
6501 : : represent the same constant value. */
6502 : :
6503 : : bool
6504 : 1067278345 : tree_int_cst_equal (const_tree t1, const_tree t2)
6505 : : {
6506 : 1067278345 : if (t1 == t2)
6507 : : return true;
6508 : :
6509 : 499447872 : if (t1 == 0 || t2 == 0)
6510 : : return false;
6511 : :
6512 : 499032542 : STRIP_ANY_LOCATION_WRAPPER (t1);
6513 : 499032542 : STRIP_ANY_LOCATION_WRAPPER (t2);
6514 : :
6515 : 499032542 : if (TREE_CODE (t1) == INTEGER_CST
6516 : 495485830 : && TREE_CODE (t2) == INTEGER_CST
6517 : 994518372 : && wi::to_widest (t1) == wi::to_widest (t2))
6518 : 18361943 : return true;
6519 : :
6520 : : return false;
6521 : : }
6522 : :
6523 : : /* Return true if T is an INTEGER_CST whose numerical value (extended
6524 : : according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. */
6525 : :
6526 : : bool
6527 : 1958959044 : tree_fits_shwi_p (const_tree t)
6528 : : {
6529 : 1958959044 : return (t != NULL_TREE
6530 : 1958958945 : && TREE_CODE (t) == INTEGER_CST
6531 : 3914546002 : && wi::fits_shwi_p (wi::to_widest (t)));
6532 : : }
6533 : :
6534 : : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6535 : : value (extended according to TYPE_UNSIGNED) fits in a poly_int64. */
6536 : :
6537 : : bool
6538 : 879034210 : tree_fits_poly_int64_p (const_tree t)
6539 : : {
6540 : 879034210 : if (t == NULL_TREE)
6541 : : return false;
6542 : 843766106 : if (POLY_INT_CST_P (t))
6543 : : {
6544 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6545 : : if (!wi::fits_shwi_p (wi::to_wide (POLY_INT_CST_COEFF (t, i))))
6546 : : return false;
6547 : : return true;
6548 : : }
6549 : 843766106 : return (TREE_CODE (t) == INTEGER_CST
6550 : 1687636772 : && wi::fits_shwi_p (wi::to_widest (t)));
6551 : : }
6552 : :
6553 : : /* Return true if T is an INTEGER_CST whose numerical value (extended
6554 : : according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
6555 : :
6556 : : bool
6557 : 3208816827 : tree_fits_uhwi_p (const_tree t)
6558 : : {
6559 : 3208816827 : return (t != NULL_TREE
6560 : 3208383666 : && TREE_CODE (t) == INTEGER_CST
6561 : 6412607409 : && wi::fits_uhwi_p (wi::to_widest (t)));
6562 : : }
6563 : :
6564 : : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6565 : : value (extended according to TYPE_UNSIGNED) fits in a poly_uint64. */
6566 : :
6567 : : bool
6568 : 871954095 : tree_fits_poly_uint64_p (const_tree t)
6569 : : {
6570 : 871954095 : if (t == NULL_TREE)
6571 : : return false;
6572 : 871605638 : if (POLY_INT_CST_P (t))
6573 : : {
6574 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6575 : : if (!wi::fits_uhwi_p (wi::to_widest (POLY_INT_CST_COEFF (t, i))))
6576 : : return false;
6577 : : return true;
6578 : : }
6579 : 871605638 : return (TREE_CODE (t) == INTEGER_CST
6580 : 1743212610 : && wi::fits_uhwi_p (wi::to_widest (t)));
6581 : : }
6582 : :
6583 : : /* T is an INTEGER_CST whose numerical value (extended according to
6584 : : TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that
6585 : : HOST_WIDE_INT. */
6586 : :
6587 : : HOST_WIDE_INT
6588 : 1217822859 : tree_to_shwi (const_tree t)
6589 : : {
6590 : 1217822859 : gcc_assert (tree_fits_shwi_p (t));
6591 : 1217822859 : return TREE_INT_CST_LOW (t);
6592 : : }
6593 : :
6594 : : /* T is an INTEGER_CST whose numerical value (extended according to
6595 : : TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. Return that
6596 : : HOST_WIDE_INT. */
6597 : :
6598 : : unsigned HOST_WIDE_INT
6599 : 696671353 : tree_to_uhwi (const_tree t)
6600 : : {
6601 : 696671353 : gcc_assert (tree_fits_uhwi_p (t));
6602 : 696671353 : return TREE_INT_CST_LOW (t);
6603 : : }
6604 : :
6605 : : /* Return the most significant (sign) bit of T. */
6606 : :
6607 : : int
6608 : 39497220 : tree_int_cst_sign_bit (const_tree t)
6609 : : {
6610 : 39497220 : unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1;
6611 : :
6612 : 39497220 : return wi::extract_uhwi (wi::to_wide (t), bitno, 1);
6613 : : }
6614 : :
6615 : : /* Return an indication of the sign of the integer constant T.
6616 : : The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6617 : : Note that -1 will never be returned if T's type is unsigned. */
6618 : :
6619 : : int
6620 : 1545287853 : tree_int_cst_sgn (const_tree t)
6621 : : {
6622 : 1545287853 : if (wi::to_wide (t) == 0)
6623 : : return 0;
6624 : 1445167783 : else if (TYPE_UNSIGNED (TREE_TYPE (t)))
6625 : : return 1;
6626 : 63398452 : else if (wi::neg_p (wi::to_wide (t)))
6627 : : return -1;
6628 : : else
6629 : : return 1;
6630 : : }
6631 : :
6632 : : /* Return the minimum number of bits needed to represent VALUE in a
6633 : : signed or unsigned type, UNSIGNEDP says which. */
6634 : :
6635 : : unsigned int
6636 : 3296028 : tree_int_cst_min_precision (tree value, signop sgn)
6637 : : {
6638 : : /* If the value is negative, compute its negative minus 1. The latter
6639 : : adjustment is because the absolute value of the largest negative value
6640 : : is one larger than the largest positive value. This is equivalent to
6641 : : a bit-wise negation, so use that operation instead. */
6642 : :
6643 : 3296028 : if (tree_int_cst_sgn (value) < 0)
6644 : 97021 : value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value);
6645 : :
6646 : : /* Return the number of bits needed, taking into account the fact
6647 : : that we need one more bit for a signed than unsigned type.
6648 : : If value is 0 or -1, the minimum precision is 1 no matter
6649 : : whether unsignedp is true or false. */
6650 : :
6651 : 3296028 : if (integer_zerop (value))
6652 : : return 1;
6653 : : else
6654 : 4719857 : return tree_floor_log2 (value) + 1 + (sgn == SIGNED ? 1 : 0) ;
6655 : : }
6656 : :
6657 : : /* Return truthvalue of whether T1 is the same tree structure as T2.
6658 : : Return 1 if they are the same.
6659 : : Return 0 if they are understandably different.
6660 : : Return -1 if either contains tree structure not understood by
6661 : : this function. */
6662 : :
6663 : : int
6664 : 171945574 : simple_cst_equal (const_tree t1, const_tree t2)
6665 : : {
6666 : 175842846 : enum tree_code code1, code2;
6667 : 175842846 : int cmp;
6668 : 175842846 : int i;
6669 : :
6670 : 175842846 : if (t1 == t2)
6671 : : return 1;
6672 : 112454928 : if (t1 == 0 || t2 == 0)
6673 : : return 0;
6674 : :
6675 : : /* For location wrappers to be the same, they must be at the same
6676 : : source location (and wrap the same thing). */
6677 : 104225019 : if (location_wrapper_p (t1) && location_wrapper_p (t2))
6678 : : {
6679 : 10714641 : if (EXPR_LOCATION (t1) != EXPR_LOCATION (t2))
6680 : : return 0;
6681 : 558 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6682 : : }
6683 : :
6684 : 93510378 : code1 = TREE_CODE (t1);
6685 : 93510378 : code2 = TREE_CODE (t2);
6686 : :
6687 : 93510378 : if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR)
6688 : : {
6689 : 3884380 : if (CONVERT_EXPR_CODE_P (code2)
6690 : 3883720 : || code2 == NON_LVALUE_EXPR)
6691 : 660 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6692 : : else
6693 : 3883720 : return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
6694 : : }
6695 : :
6696 : 89625998 : else if (CONVERT_EXPR_CODE_P (code2)
6697 : 89625983 : || code2 == NON_LVALUE_EXPR)
6698 : 116 : return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
6699 : :
6700 : 89625882 : if (code1 != code2)
6701 : : return 0;
6702 : :
6703 : 85203594 : switch (code1)
6704 : : {
6705 : 70709304 : case INTEGER_CST:
6706 : 70709304 : return wi::to_widest (t1) == wi::to_widest (t2);
6707 : :
6708 : 89 : case REAL_CST:
6709 : 89 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
6710 : :
6711 : 0 : case FIXED_CST:
6712 : 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
6713 : :
6714 : 3018040 : case STRING_CST:
6715 : 3018040 : return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
6716 : 3018040 : && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
6717 : 3433455 : TREE_STRING_LENGTH (t1)));
6718 : :
6719 : 64 : case CONSTRUCTOR:
6720 : 64 : {
6721 : 64 : unsigned HOST_WIDE_INT idx;
6722 : 64 : vec<constructor_elt, va_gc> *v1 = CONSTRUCTOR_ELTS (t1);
6723 : 64 : vec<constructor_elt, va_gc> *v2 = CONSTRUCTOR_ELTS (t2);
6724 : :
6725 : 82 : if (vec_safe_length (v1) != vec_safe_length (v2))
6726 : : return false;
6727 : :
6728 : 70 : for (idx = 0; idx < vec_safe_length (v1); ++idx)
6729 : : /* ??? Should we handle also fields here? */
6730 : 9 : if (!simple_cst_equal ((*v1)[idx].value, (*v2)[idx].value))
6731 : : return false;
6732 : : return true;
6733 : : }
6734 : :
6735 : 0 : case SAVE_EXPR:
6736 : 0 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6737 : :
6738 : 206206 : case CALL_EXPR:
6739 : 206206 : cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2));
6740 : 206206 : if (cmp <= 0)
6741 : : return cmp;
6742 : 84466 : if (call_expr_nargs (t1) != call_expr_nargs (t2))
6743 : : return 0;
6744 : 84466 : {
6745 : 84466 : const_tree arg1, arg2;
6746 : 84466 : const_call_expr_arg_iterator iter1, iter2;
6747 : 168932 : for (arg1 = first_const_call_expr_arg (t1, &iter1),
6748 : 84466 : arg2 = first_const_call_expr_arg (t2, &iter2);
6749 : 84536 : arg1 && arg2;
6750 : 70 : arg1 = next_const_call_expr_arg (&iter1),
6751 : 70 : arg2 = next_const_call_expr_arg (&iter2))
6752 : : {
6753 : 84455 : cmp = simple_cst_equal (arg1, arg2);
6754 : 84455 : if (cmp <= 0)
6755 : : return cmp;
6756 : : }
6757 : 81 : return arg1 == arg2;
6758 : : }
6759 : :
6760 : 11793 : case TARGET_EXPR:
6761 : : /* Special case: if either target is an unallocated VAR_DECL,
6762 : : it means that it's going to be unified with whatever the
6763 : : TARGET_EXPR is really supposed to initialize, so treat it
6764 : : as being equivalent to anything. */
6765 : 11793 : if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
6766 : 11793 : && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
6767 : 11793 : && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
6768 : 11793 : || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
6769 : 0 : && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
6770 : 0 : && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
6771 : : cmp = 1;
6772 : : else
6773 : 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6774 : :
6775 : 0 : if (cmp <= 0)
6776 : : return cmp;
6777 : :
6778 : 11793 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
6779 : :
6780 : 0 : case WITH_CLEANUP_EXPR:
6781 : 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6782 : 0 : if (cmp <= 0)
6783 : : return cmp;
6784 : :
6785 : 0 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
6786 : :
6787 : 425 : case COMPONENT_REF:
6788 : 425 : if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
6789 : 425 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6790 : :
6791 : : return 0;
6792 : :
6793 : : case VAR_DECL:
6794 : : case PARM_DECL:
6795 : : case CONST_DECL:
6796 : : case FUNCTION_DECL:
6797 : : return 0;
6798 : :
6799 : 11196979 : default:
6800 : 11196979 : if (POLY_INT_CST_P (t1))
6801 : : /* A false return means maybe_ne rather than known_ne. */
6802 : : return known_eq (poly_widest_int::from (poly_int_cst_value (t1),
6803 : : TYPE_SIGN (TREE_TYPE (t1))),
6804 : : poly_widest_int::from (poly_int_cst_value (t2),
6805 : : TYPE_SIGN (TREE_TYPE (t2))));
6806 : 11196979 : break;
6807 : : }
6808 : :
6809 : : /* This general rule works for most tree codes. All exceptions should be
6810 : : handled above. If this is a language-specific tree code, we can't
6811 : : trust what might be in the operand, so say we don't know
6812 : : the situation. */
6813 : 11196979 : if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
6814 : : return -1;
6815 : :
6816 : 6579979 : switch (TREE_CODE_CLASS (code1))
6817 : : {
6818 : : case tcc_unary:
6819 : : case tcc_binary:
6820 : : case tcc_comparison:
6821 : : case tcc_expression:
6822 : : case tcc_reference:
6823 : : case tcc_statement:
6824 : : cmp = 1;
6825 : 2103 : for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
6826 : : {
6827 : 1624 : cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
6828 : 1624 : if (cmp <= 0)
6829 : : return cmp;
6830 : : }
6831 : :
6832 : : return cmp;
6833 : :
6834 : : default:
6835 : : return -1;
6836 : : }
6837 : : }
6838 : :
6839 : : /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
6840 : : Return -1, 0, or 1 if the value of T is less than, equal to, or greater
6841 : : than U, respectively. */
6842 : :
6843 : : int
6844 : 1274917373 : compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u)
6845 : : {
6846 : 1274917373 : if (tree_int_cst_sgn (t) < 0)
6847 : : return -1;
6848 : 1274917097 : else if (!tree_fits_uhwi_p (t))
6849 : : return 1;
6850 : 1274917072 : else if (TREE_INT_CST_LOW (t) == u)
6851 : : return 0;
6852 : 1157469062 : else if (TREE_INT_CST_LOW (t) < u)
6853 : : return -1;
6854 : : else
6855 : 11992706 : return 1;
6856 : : }
6857 : :
6858 : : /* Return true if SIZE represents a constant size that is in bounds of
6859 : : what the middle-end and the backend accepts (covering not more than
6860 : : half of the address-space).
6861 : : When PERR is non-null, set *PERR on failure to the description of
6862 : : why SIZE is not valid. */
6863 : :
6864 : : bool
6865 : 52080960 : valid_constant_size_p (const_tree size, cst_size_error *perr /* = NULL */)
6866 : : {
6867 : 52080960 : if (POLY_INT_CST_P (size))
6868 : : {
6869 : : if (TREE_OVERFLOW (size))
6870 : : return false;
6871 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
6872 : : if (!valid_constant_size_p (POLY_INT_CST_COEFF (size, i)))
6873 : : return false;
6874 : : return true;
6875 : : }
6876 : :
6877 : 52080960 : cst_size_error error;
6878 : 52080960 : if (!perr)
6879 : 47332365 : perr = &error;
6880 : :
6881 : 52080960 : if (TREE_CODE (size) != INTEGER_CST)
6882 : : {
6883 : 3 : *perr = cst_size_not_constant;
6884 : 3 : return false;
6885 : : }
6886 : :
6887 : 52080957 : if (TREE_OVERFLOW_P (size))
6888 : : {
6889 : 60 : *perr = cst_size_overflow;
6890 : 60 : return false;
6891 : : }
6892 : :
6893 : 52080897 : if (tree_int_cst_sgn (size) < 0)
6894 : : {
6895 : 421 : *perr = cst_size_negative;
6896 : 421 : return false;
6897 : : }
6898 : 104160952 : if (!tree_fits_uhwi_p (size)
6899 : 156241428 : || (wi::to_widest (TYPE_MAX_VALUE (sizetype))
6900 : 156241428 : < wi::to_widest (size) * 2))
6901 : : {
6902 : 624 : *perr = cst_size_too_big;
6903 : 624 : return false;
6904 : : }
6905 : :
6906 : : return true;
6907 : : }
6908 : :
6909 : : /* Return the precision of the type, or for a complex or vector type the
6910 : : precision of the type of its elements. */
6911 : :
6912 : : unsigned int
6913 : 6911968758 : element_precision (const_tree type)
6914 : : {
6915 : 6911968758 : if (!TYPE_P (type))
6916 : 6738200 : type = TREE_TYPE (type);
6917 : 6911968758 : enum tree_code code = TREE_CODE (type);
6918 : 6911968758 : if (code == COMPLEX_TYPE || code == VECTOR_TYPE)
6919 : 52975132 : type = TREE_TYPE (type);
6920 : :
6921 : 6911968758 : return TYPE_PRECISION (type);
6922 : : }
6923 : :
6924 : : /* Return true if CODE represents an associative tree code. Otherwise
6925 : : return false. */
6926 : : bool
6927 : 35104805 : associative_tree_code (enum tree_code code)
6928 : : {
6929 : 35104805 : switch (code)
6930 : : {
6931 : : case BIT_IOR_EXPR:
6932 : : case BIT_AND_EXPR:
6933 : : case BIT_XOR_EXPR:
6934 : : case PLUS_EXPR:
6935 : : case MULT_EXPR:
6936 : : case MIN_EXPR:
6937 : : case MAX_EXPR:
6938 : : return true;
6939 : :
6940 : 24899998 : default:
6941 : 24899998 : break;
6942 : : }
6943 : 24899998 : return false;
6944 : : }
6945 : :
6946 : : /* Return true if CODE represents a commutative tree code. Otherwise
6947 : : return false. */
6948 : : bool
6949 : 1621699296 : commutative_tree_code (enum tree_code code)
6950 : : {
6951 : 1621699296 : switch (code)
6952 : : {
6953 : : case PLUS_EXPR:
6954 : : case MULT_EXPR:
6955 : : case MULT_HIGHPART_EXPR:
6956 : : case MIN_EXPR:
6957 : : case MAX_EXPR:
6958 : : case BIT_IOR_EXPR:
6959 : : case BIT_XOR_EXPR:
6960 : : case BIT_AND_EXPR:
6961 : : case NE_EXPR:
6962 : : case EQ_EXPR:
6963 : : case UNORDERED_EXPR:
6964 : : case ORDERED_EXPR:
6965 : : case UNEQ_EXPR:
6966 : : case LTGT_EXPR:
6967 : : case TRUTH_AND_EXPR:
6968 : : case TRUTH_XOR_EXPR:
6969 : : case TRUTH_OR_EXPR:
6970 : : case WIDEN_MULT_EXPR:
6971 : : case VEC_WIDEN_MULT_HI_EXPR:
6972 : : case VEC_WIDEN_MULT_LO_EXPR:
6973 : : case VEC_WIDEN_MULT_EVEN_EXPR:
6974 : : case VEC_WIDEN_MULT_ODD_EXPR:
6975 : : return true;
6976 : :
6977 : 841274670 : default:
6978 : 841274670 : break;
6979 : : }
6980 : 841274670 : return false;
6981 : : }
6982 : :
6983 : : /* Return true if CODE represents a ternary tree code for which the
6984 : : first two operands are commutative. Otherwise return false. */
6985 : : bool
6986 : 74848354 : commutative_ternary_tree_code (enum tree_code code)
6987 : : {
6988 : 74848354 : switch (code)
6989 : : {
6990 : : case WIDEN_MULT_PLUS_EXPR:
6991 : : case WIDEN_MULT_MINUS_EXPR:
6992 : : case DOT_PROD_EXPR:
6993 : : return true;
6994 : :
6995 : 74842849 : default:
6996 : 74842849 : break;
6997 : : }
6998 : 74842849 : return false;
6999 : : }
7000 : :
7001 : : /* Returns true if CODE can overflow. */
7002 : :
7003 : : bool
7004 : 2956 : operation_can_overflow (enum tree_code code)
7005 : : {
7006 : 2956 : switch (code)
7007 : : {
7008 : : case PLUS_EXPR:
7009 : : case MINUS_EXPR:
7010 : : case MULT_EXPR:
7011 : : case LSHIFT_EXPR:
7012 : : /* Can overflow in various ways. */
7013 : : return true;
7014 : : case TRUNC_DIV_EXPR:
7015 : : case EXACT_DIV_EXPR:
7016 : : case FLOOR_DIV_EXPR:
7017 : : case CEIL_DIV_EXPR:
7018 : : /* For INT_MIN / -1. */
7019 : : return true;
7020 : : case NEGATE_EXPR:
7021 : : case ABS_EXPR:
7022 : : /* For -INT_MIN. */
7023 : : return true;
7024 : 141 : default:
7025 : : /* These operators cannot overflow. */
7026 : 141 : return false;
7027 : : }
7028 : : }
7029 : :
7030 : : /* Returns true if CODE operating on operands of type TYPE doesn't overflow, or
7031 : : ftrapv doesn't generate trapping insns for CODE. */
7032 : :
7033 : : bool
7034 : 5765255 : operation_no_trapping_overflow (tree type, enum tree_code code)
7035 : : {
7036 : 5765255 : gcc_checking_assert (ANY_INTEGRAL_TYPE_P (type));
7037 : :
7038 : : /* We don't generate instructions that trap on overflow for complex or vector
7039 : : types. */
7040 : 5765255 : if (!INTEGRAL_TYPE_P (type))
7041 : : return true;
7042 : :
7043 : 5765255 : if (!TYPE_OVERFLOW_TRAPS (type))
7044 : : return true;
7045 : :
7046 : 468 : switch (code)
7047 : : {
7048 : : case PLUS_EXPR:
7049 : : case MINUS_EXPR:
7050 : : case MULT_EXPR:
7051 : : case NEGATE_EXPR:
7052 : : case ABS_EXPR:
7053 : : /* These operators can overflow, and -ftrapv generates trapping code for
7054 : : these. */
7055 : : return false;
7056 : : case TRUNC_DIV_EXPR:
7057 : : case EXACT_DIV_EXPR:
7058 : : case FLOOR_DIV_EXPR:
7059 : : case CEIL_DIV_EXPR:
7060 : : case LSHIFT_EXPR:
7061 : : /* These operators can overflow, but -ftrapv does not generate trapping
7062 : : code for these. */
7063 : : return true;
7064 : : default:
7065 : : /* These operators cannot overflow. */
7066 : : return true;
7067 : : }
7068 : : }
7069 : :
7070 : : /* Constructors for pointer, array and function types.
7071 : : (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7072 : : constructed by language-dependent code, not here.) */
7073 : :
7074 : : /* Construct, lay out and return the type of pointers to TO_TYPE with
7075 : : mode MODE. If MODE is VOIDmode, a pointer mode for the address
7076 : : space of TO_TYPE will be picked. If CAN_ALIAS_ALL is TRUE,
7077 : : indicate this type can reference all of memory. If such a type has
7078 : : already been constructed, reuse it. */
7079 : :
7080 : : tree
7081 : 2027746021 : build_pointer_type_for_mode (tree to_type, machine_mode mode,
7082 : : bool can_alias_all)
7083 : : {
7084 : 2027746021 : tree t;
7085 : 2027746021 : bool could_alias = can_alias_all;
7086 : :
7087 : 2027746021 : if (to_type == error_mark_node)
7088 : : return error_mark_node;
7089 : :
7090 : 2027746015 : if (mode == VOIDmode)
7091 : : {
7092 : 1910581260 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7093 : 1910581260 : mode = targetm.addr_space.pointer_mode (as);
7094 : : }
7095 : :
7096 : : /* If the pointed-to type has the may_alias attribute set, force
7097 : : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7098 : 2027746015 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7099 : 4314668 : can_alias_all = true;
7100 : :
7101 : : /* In some cases, languages will have things that aren't a POINTER_TYPE
7102 : : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7103 : : In that case, return that type without regard to the rest of our
7104 : : operands.
7105 : :
7106 : : ??? This is a kludge, but consistent with the way this function has
7107 : : always operated and there doesn't seem to be a good way to avoid this
7108 : : at the moment. */
7109 : 2027746015 : if (TYPE_POINTER_TO (to_type) != 0
7110 : 2027746015 : && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
7111 : 41430 : return TYPE_POINTER_TO (to_type);
7112 : :
7113 : : /* First, if we already have a type for pointers to TO_TYPE and it's
7114 : : the proper mode, use it. */
7115 : 2028257283 : for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
7116 : 1905319701 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7117 : : return t;
7118 : :
7119 : 122937582 : t = make_node (POINTER_TYPE);
7120 : :
7121 : 122937582 : TREE_TYPE (t) = to_type;
7122 : 122937582 : SET_TYPE_MODE (t, mode);
7123 : 122937582 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7124 : 122937582 : TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
7125 : 122937582 : TYPE_POINTER_TO (to_type) = t;
7126 : :
7127 : : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7128 : 122937582 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7129 : 5057455 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7130 : 117880127 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7131 : 35910032 : TYPE_CANONICAL (t)
7132 : 71820064 : = build_pointer_type_for_mode (TYPE_CANONICAL (to_type),
7133 : : mode, false);
7134 : :
7135 : : /* Lay out the type. This function has many callers that are concerned
7136 : : with expression-construction, and this simplifies them all. */
7137 : 122937582 : layout_type (t);
7138 : :
7139 : 122937582 : return t;
7140 : : }
7141 : :
7142 : : /* By default build pointers in ptr_mode. */
7143 : :
7144 : : tree
7145 : 1909900426 : build_pointer_type (tree to_type)
7146 : : {
7147 : 1909900426 : return build_pointer_type_for_mode (to_type, VOIDmode, false);
7148 : : }
7149 : :
7150 : : /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7151 : :
7152 : : tree
7153 : 510837633 : build_reference_type_for_mode (tree to_type, machine_mode mode,
7154 : : bool can_alias_all)
7155 : : {
7156 : 510837633 : tree t;
7157 : 510837633 : bool could_alias = can_alias_all;
7158 : :
7159 : 510837633 : if (to_type == error_mark_node)
7160 : : return error_mark_node;
7161 : :
7162 : 510837633 : if (mode == VOIDmode)
7163 : : {
7164 : 421565526 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7165 : 421565526 : mode = targetm.addr_space.pointer_mode (as);
7166 : : }
7167 : :
7168 : : /* If the pointed-to type has the may_alias attribute set, force
7169 : : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7170 : 510837633 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7171 : 680724 : can_alias_all = true;
7172 : :
7173 : : /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7174 : : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7175 : : In that case, return that type without regard to the rest of our
7176 : : operands.
7177 : :
7178 : : ??? This is a kludge, but consistent with the way this function has
7179 : : always operated and there doesn't seem to be a good way to avoid this
7180 : : at the moment. */
7181 : 510837633 : if (TYPE_REFERENCE_TO (to_type) != 0
7182 : 510837633 : && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
7183 : 0 : return TYPE_REFERENCE_TO (to_type);
7184 : :
7185 : : /* First, if we already have a type for pointers to TO_TYPE and it's
7186 : : the proper mode, use it. */
7187 : 510837633 : for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
7188 : 439227885 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7189 : : return t;
7190 : :
7191 : 71609748 : t = make_node (REFERENCE_TYPE);
7192 : :
7193 : 71609748 : TREE_TYPE (t) = to_type;
7194 : 71609748 : SET_TYPE_MODE (t, mode);
7195 : 71609748 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7196 : 71609748 : TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
7197 : 71609748 : TYPE_REFERENCE_TO (to_type) = t;
7198 : :
7199 : : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7200 : 71609748 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7201 : 3420308 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7202 : 68189440 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7203 : 40209735 : TYPE_CANONICAL (t)
7204 : 80419470 : = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
7205 : : mode, false);
7206 : :
7207 : 71609748 : layout_type (t);
7208 : :
7209 : 71609748 : return t;
7210 : : }
7211 : :
7212 : :
7213 : : /* Build the node for the type of references-to-TO_TYPE by default
7214 : : in ptr_mode. */
7215 : :
7216 : : tree
7217 : 20809373 : build_reference_type (tree to_type)
7218 : : {
7219 : 20809373 : return build_reference_type_for_mode (to_type, VOIDmode, false);
7220 : : }
7221 : :
7222 : : #define MAX_INT_CACHED_PREC \
7223 : : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7224 : : static GTY(()) tree nonstandard_integer_type_cache[2 * MAX_INT_CACHED_PREC + 2];
7225 : :
7226 : : static void
7227 : 256374 : clear_nonstandard_integer_type_cache (void)
7228 : : {
7229 : 33584994 : for (size_t i = 0 ; i < 2 * MAX_INT_CACHED_PREC + 2 ; i++)
7230 : : {
7231 : 33328620 : nonstandard_integer_type_cache[i] = NULL;
7232 : : }
7233 : 0 : }
7234 : :
7235 : : /* Builds a signed or unsigned integer type of precision PRECISION.
7236 : : Used for C bitfields whose precision does not match that of
7237 : : built-in target types. */
7238 : : tree
7239 : 62468654 : build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
7240 : : int unsignedp)
7241 : : {
7242 : 62468654 : tree itype, ret;
7243 : :
7244 : 62468654 : if (unsignedp)
7245 : 53984781 : unsignedp = MAX_INT_CACHED_PREC + 1;
7246 : :
7247 : 62468654 : if (precision <= MAX_INT_CACHED_PREC)
7248 : : {
7249 : 62065528 : itype = nonstandard_integer_type_cache[precision + unsignedp];
7250 : 62065528 : if (itype)
7251 : : return itype;
7252 : : }
7253 : :
7254 : 1045594 : itype = make_node (INTEGER_TYPE);
7255 : 1045594 : TYPE_PRECISION (itype) = precision;
7256 : :
7257 : 1045594 : if (unsignedp)
7258 : 704696 : fixup_unsigned_type (itype);
7259 : : else
7260 : 340898 : fixup_signed_type (itype);
7261 : :
7262 : 1045594 : inchash::hash hstate;
7263 : 1045594 : inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7264 : 1045594 : ret = type_hash_canon (hstate.end (), itype);
7265 : 1045594 : if (precision <= MAX_INT_CACHED_PREC)
7266 : 642468 : nonstandard_integer_type_cache[precision + unsignedp] = ret;
7267 : :
7268 : : return ret;
7269 : : }
7270 : :
7271 : : #define MAX_BOOL_CACHED_PREC \
7272 : : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7273 : : static GTY(()) tree nonstandard_boolean_type_cache[MAX_BOOL_CACHED_PREC + 1];
7274 : :
7275 : : /* Builds a boolean type of precision PRECISION.
7276 : : Used for boolean vectors to choose proper vector element size. */
7277 : : tree
7278 : 1919490 : build_nonstandard_boolean_type (unsigned HOST_WIDE_INT precision)
7279 : : {
7280 : 1919490 : tree type;
7281 : :
7282 : 1919490 : if (precision <= MAX_BOOL_CACHED_PREC)
7283 : : {
7284 : 1916503 : type = nonstandard_boolean_type_cache[precision];
7285 : 1916503 : if (type)
7286 : : return type;
7287 : : }
7288 : :
7289 : 73323 : type = make_node (BOOLEAN_TYPE);
7290 : 73323 : TYPE_PRECISION (type) = precision;
7291 : 73323 : fixup_signed_type (type);
7292 : :
7293 : 73323 : if (precision <= MAX_INT_CACHED_PREC)
7294 : 70336 : nonstandard_boolean_type_cache[precision] = type;
7295 : :
7296 : : return type;
7297 : : }
7298 : :
7299 : : static GTY(()) vec<tree, va_gc> *bitint_type_cache;
7300 : :
7301 : : /* Builds a signed or unsigned _BitInt(PRECISION) type. */
7302 : : tree
7303 : 1524437 : build_bitint_type (unsigned HOST_WIDE_INT precision, int unsignedp)
7304 : : {
7305 : 1524437 : tree itype, ret;
7306 : :
7307 : 1559123 : gcc_checking_assert (precision >= 1 + !unsignedp);
7308 : :
7309 : 1524437 : if (unsignedp)
7310 : 34686 : unsignedp = MAX_INT_CACHED_PREC + 1;
7311 : :
7312 : 1524437 : if (bitint_type_cache == NULL)
7313 : 465 : vec_safe_grow_cleared (bitint_type_cache, 2 * MAX_INT_CACHED_PREC + 2);
7314 : :
7315 : 1524437 : if (precision <= MAX_INT_CACHED_PREC)
7316 : : {
7317 : 35797 : itype = (*bitint_type_cache)[precision + unsignedp];
7318 : 35797 : if (itype)
7319 : : return itype;
7320 : : }
7321 : :
7322 : 1490005 : itype = make_node (BITINT_TYPE);
7323 : 1490005 : TYPE_PRECISION (itype) = precision;
7324 : :
7325 : 1490005 : if (unsignedp)
7326 : 28364 : fixup_unsigned_type (itype);
7327 : : else
7328 : 1461641 : fixup_signed_type (itype);
7329 : :
7330 : 1490005 : inchash::hash hstate;
7331 : 1490005 : inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7332 : 1490005 : ret = type_hash_canon (hstate.end (), itype);
7333 : 1490005 : if (precision <= MAX_INT_CACHED_PREC)
7334 : 1365 : (*bitint_type_cache)[precision + unsignedp] = ret;
7335 : :
7336 : : return ret;
7337 : : }
7338 : :
7339 : : /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7340 : : or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7341 : : is true, reuse such a type that has already been constructed. */
7342 : :
7343 : : static tree
7344 : 37219619 : build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
7345 : : {
7346 : 37219619 : tree itype = make_node (INTEGER_TYPE);
7347 : :
7348 : 37219619 : TREE_TYPE (itype) = type;
7349 : :
7350 : 37219619 : TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
7351 : 37219619 : TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
7352 : :
7353 : 37219619 : TYPE_PRECISION (itype) = TYPE_PRECISION (type);
7354 : 37219619 : SET_TYPE_MODE (itype, TYPE_MODE (type));
7355 : 37219619 : TYPE_SIZE (itype) = TYPE_SIZE (type);
7356 : 37219619 : TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
7357 : 37219619 : SET_TYPE_ALIGN (itype, TYPE_ALIGN (type));
7358 : 37219619 : TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
7359 : 37219619 : SET_TYPE_WARN_IF_NOT_ALIGN (itype, TYPE_WARN_IF_NOT_ALIGN (type));
7360 : :
7361 : 37219619 : if (!shared)
7362 : : return itype;
7363 : :
7364 : 37219619 : if ((TYPE_MIN_VALUE (itype)
7365 : 37219619 : && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST)
7366 : 74438424 : || (TYPE_MAX_VALUE (itype)
7367 : 36678785 : && TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST))
7368 : : {
7369 : : /* Since we cannot reliably merge this type, we need to compare it using
7370 : : structural equality checks. */
7371 : 916925 : SET_TYPE_STRUCTURAL_EQUALITY (itype);
7372 : 916925 : return itype;
7373 : : }
7374 : :
7375 : 36302694 : hashval_t hash = type_hash_canon_hash (itype);
7376 : 36302694 : itype = type_hash_canon (hash, itype);
7377 : :
7378 : 36302694 : return itype;
7379 : : }
7380 : :
7381 : : /* Wrapper around build_range_type_1 with SHARED set to true. */
7382 : :
7383 : : tree
7384 : 37219619 : build_range_type (tree type, tree lowval, tree highval)
7385 : : {
7386 : 37219619 : return build_range_type_1 (type, lowval, highval, true);
7387 : : }
7388 : :
7389 : : /* Wrapper around build_range_type_1 with SHARED set to false. */
7390 : :
7391 : : tree
7392 : 0 : build_nonshared_range_type (tree type, tree lowval, tree highval)
7393 : : {
7394 : 0 : return build_range_type_1 (type, lowval, highval, false);
7395 : : }
7396 : :
7397 : : /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7398 : : MAXVAL should be the maximum value in the domain
7399 : : (one less than the length of the array).
7400 : :
7401 : : The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7402 : : We don't enforce this limit, that is up to caller (e.g. language front end).
7403 : : The limit exists because the result is a signed type and we don't handle
7404 : : sizes that use more than one HOST_WIDE_INT. */
7405 : :
7406 : : tree
7407 : 34819176 : build_index_type (tree maxval)
7408 : : {
7409 : 34819176 : return build_range_type (sizetype, size_zero_node, maxval);
7410 : : }
7411 : :
7412 : : /* Return true if the debug information for TYPE, a subtype, should be emitted
7413 : : as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7414 : : high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7415 : : debug info and doesn't reflect the source code. */
7416 : :
7417 : : bool
7418 : 18 : subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval)
7419 : : {
7420 : 18 : tree base_type = TREE_TYPE (type), low, high;
7421 : :
7422 : : /* Subrange types have a base type which is an integral type. */
7423 : 18 : if (!INTEGRAL_TYPE_P (base_type))
7424 : : return false;
7425 : :
7426 : : /* Get the real bounds of the subtype. */
7427 : 18 : if (lang_hooks.types.get_subrange_bounds)
7428 : 0 : lang_hooks.types.get_subrange_bounds (type, &low, &high);
7429 : : else
7430 : : {
7431 : 18 : low = TYPE_MIN_VALUE (type);
7432 : 18 : high = TYPE_MAX_VALUE (type);
7433 : : }
7434 : :
7435 : : /* If the type and its base type have the same representation and the same
7436 : : name, then the type is not a subrange but a copy of the base type. */
7437 : 18 : if ((TREE_CODE (base_type) == INTEGER_TYPE
7438 : 18 : || TREE_CODE (base_type) == BOOLEAN_TYPE)
7439 : 18 : && int_size_in_bytes (type) == int_size_in_bytes (base_type)
7440 : 18 : && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type))
7441 : 0 : && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type))
7442 : 18 : && TYPE_IDENTIFIER (type) == TYPE_IDENTIFIER (base_type))
7443 : : return false;
7444 : :
7445 : 18 : if (lowval)
7446 : 18 : *lowval = low;
7447 : 18 : if (highval)
7448 : 18 : *highval = high;
7449 : : return true;
7450 : : }
7451 : :
7452 : : /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7453 : : and number of elements specified by the range of values of INDEX_TYPE.
7454 : : If TYPELESS_STORAGE is true, TYPE_TYPELESS_STORAGE flag is set on the type.
7455 : : If SHARED is true, reuse such a type that has already been constructed.
7456 : : If SET_CANONICAL is true, compute TYPE_CANONICAL from the element type. */
7457 : :
7458 : : tree
7459 : 59458742 : build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
7460 : : bool shared, bool set_canonical)
7461 : : {
7462 : 59458742 : tree t;
7463 : :
7464 : 59458742 : if (TREE_CODE (elt_type) == FUNCTION_TYPE)
7465 : : {
7466 : 0 : error ("arrays of functions are not meaningful");
7467 : 0 : elt_type = integer_type_node;
7468 : : }
7469 : :
7470 : 59458742 : t = make_node (ARRAY_TYPE);
7471 : 59458742 : TREE_TYPE (t) = elt_type;
7472 : 59458742 : TYPE_DOMAIN (t) = index_type;
7473 : 59458742 : TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type);
7474 : 59458742 : TYPE_TYPELESS_STORAGE (t) = typeless_storage;
7475 : :
7476 : : /* Set TYPE_STRUCTURAL_EQUALITY_P. */
7477 : 59458742 : if (set_canonical
7478 : 59458742 : && (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7479 : 59427824 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7480 : 59182223 : || in_lto_p))
7481 : 350302 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7482 : :
7483 : 59458742 : layout_type (t);
7484 : :
7485 : 59458742 : if (shared)
7486 : : {
7487 : 59458715 : hashval_t hash = type_hash_canon_hash (t);
7488 : 59458715 : tree probe_type = t;
7489 : 59458715 : t = type_hash_canon (hash, t);
7490 : 59458715 : if (t != probe_type)
7491 : : return t;
7492 : : }
7493 : :
7494 : 9816115 : if (TYPE_CANONICAL (t) == t && set_canonical)
7495 : : {
7496 : 9514887 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7497 : 9514887 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7498 : 19029774 : || in_lto_p)
7499 : 0 : gcc_unreachable ();
7500 : 9514887 : else if (TYPE_CANONICAL (elt_type) != elt_type
7501 : 9514887 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
7502 : 99996 : TYPE_CANONICAL (t)
7503 : 289926 : = build_array_type_1 (TYPE_CANONICAL (elt_type),
7504 : : index_type
7505 : 89934 : ? TYPE_CANONICAL (index_type) : NULL_TREE,
7506 : : typeless_storage, shared, set_canonical);
7507 : : }
7508 : :
7509 : : return t;
7510 : : }
7511 : :
7512 : : /* Wrapper around build_array_type_1 with SHARED set to true. */
7513 : :
7514 : : tree
7515 : 59358719 : build_array_type (tree elt_type, tree index_type, bool typeless_storage)
7516 : : {
7517 : 59358719 : return
7518 : 59358719 : build_array_type_1 (elt_type, index_type, typeless_storage, true, true);
7519 : : }
7520 : :
7521 : : /* Wrapper around build_array_type_1 with SHARED set to false. */
7522 : :
7523 : : tree
7524 : 0 : build_nonshared_array_type (tree elt_type, tree index_type)
7525 : : {
7526 : 0 : return build_array_type_1 (elt_type, index_type, false, false, true);
7527 : : }
7528 : :
7529 : : /* Return a representation of ELT_TYPE[NELTS], using indices of type
7530 : : sizetype. */
7531 : :
7532 : : tree
7533 : 1422522 : build_array_type_nelts (tree elt_type, poly_uint64 nelts)
7534 : : {
7535 : 1422522 : return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
7536 : : }
7537 : :
7538 : : /* Computes the canonical argument types from the argument type list
7539 : : ARGTYPES.
7540 : :
7541 : : Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7542 : : on entry to this function, or if any of the ARGTYPES are
7543 : : structural.
7544 : :
7545 : : Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7546 : : true on entry to this function, or if any of the ARGTYPES are
7547 : : non-canonical.
7548 : :
7549 : : Returns a canonical argument list, which may be ARGTYPES when the
7550 : : canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7551 : : true) or would not differ from ARGTYPES. */
7552 : :
7553 : : static tree
7554 : 864877737 : maybe_canonicalize_argtypes (tree argtypes,
7555 : : bool *any_structural_p,
7556 : : bool *any_noncanonical_p)
7557 : : {
7558 : 864877737 : tree arg;
7559 : 864877737 : bool any_noncanonical_argtypes_p = false;
7560 : :
7561 : 3030314984 : for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
7562 : : {
7563 : 2165437247 : if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
7564 : : /* Fail gracefully by stating that the type is structural. */
7565 : 3861 : *any_structural_p = true;
7566 : 2165433386 : else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg)))
7567 : 32746619 : *any_structural_p = true;
7568 : 2132686767 : else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg)
7569 : 2132686767 : || TREE_PURPOSE (arg))
7570 : : /* If the argument has a default argument, we consider it
7571 : : non-canonical even though the type itself is canonical.
7572 : : That way, different variants of function and method types
7573 : : with default arguments will all point to the variant with
7574 : : no defaults as their canonical type. */
7575 : : any_noncanonical_argtypes_p = true;
7576 : : }
7577 : :
7578 : 864877737 : if (*any_structural_p)
7579 : : return argtypes;
7580 : :
7581 : 778322059 : if (any_noncanonical_argtypes_p)
7582 : : {
7583 : : /* Build the canonical list of argument types. */
7584 : : tree canon_argtypes = NULL_TREE;
7585 : : bool is_void = false;
7586 : :
7587 : 787920842 : for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
7588 : : {
7589 : 606086033 : if (arg == void_list_node)
7590 : : is_void = true;
7591 : : else
7592 : 850902280 : canon_argtypes = tree_cons (NULL_TREE,
7593 : 425451140 : TYPE_CANONICAL (TREE_VALUE (arg)),
7594 : : canon_argtypes);
7595 : : }
7596 : :
7597 : 181834809 : canon_argtypes = nreverse (canon_argtypes);
7598 : 181834809 : if (is_void)
7599 : 180634893 : canon_argtypes = chainon (canon_argtypes, void_list_node);
7600 : :
7601 : : /* There is a non-canonical type. */
7602 : 181834809 : *any_noncanonical_p = true;
7603 : 181834809 : return canon_argtypes;
7604 : : }
7605 : :
7606 : : /* The canonical argument types are the same as ARGTYPES. */
7607 : : return argtypes;
7608 : : }
7609 : :
7610 : : /* Construct, lay out and return
7611 : : the type of functions returning type VALUE_TYPE
7612 : : given arguments of types ARG_TYPES.
7613 : : ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7614 : : are data type nodes for the arguments of the function.
7615 : : NO_NAMED_ARGS_STDARG_P is true if this is a prototyped
7616 : : variable-arguments function with (...) prototype (no named arguments).
7617 : : If such a type has already been constructed, reuse it. */
7618 : :
7619 : : tree
7620 : 584399200 : build_function_type (tree value_type, tree arg_types,
7621 : : bool no_named_args_stdarg_p)
7622 : : {
7623 : 584399200 : tree t;
7624 : 584399200 : inchash::hash hstate;
7625 : 584399200 : bool any_structural_p, any_noncanonical_p;
7626 : 584399200 : tree canon_argtypes;
7627 : :
7628 : 584399200 : gcc_assert (arg_types != error_mark_node);
7629 : :
7630 : 584399200 : if (TREE_CODE (value_type) == FUNCTION_TYPE)
7631 : : {
7632 : 0 : error ("function return type cannot be function");
7633 : 0 : value_type = integer_type_node;
7634 : : }
7635 : :
7636 : : /* Make a node of the sort we want. */
7637 : 584399200 : t = make_node (FUNCTION_TYPE);
7638 : 584399200 : TREE_TYPE (t) = value_type;
7639 : 584399200 : TYPE_ARG_TYPES (t) = arg_types;
7640 : 584399200 : if (no_named_args_stdarg_p)
7641 : : {
7642 : 218772 : gcc_assert (arg_types == NULL_TREE);
7643 : 218772 : TYPE_NO_NAMED_ARGS_STDARG_P (t) = 1;
7644 : : }
7645 : :
7646 : : /* Set up the canonical type. */
7647 : 584399200 : any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type);
7648 : 584399200 : any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
7649 : 584399200 : canon_argtypes = maybe_canonicalize_argtypes (arg_types,
7650 : : &any_structural_p,
7651 : : &any_noncanonical_p);
7652 : : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7653 : 584399200 : if (any_structural_p)
7654 : 64005977 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7655 : :
7656 : : /* If we already have such a type, use the old one. */
7657 : 584399200 : hashval_t hash = type_hash_canon_hash (t);
7658 : 584399200 : tree probe_type = t;
7659 : 584399200 : t = type_hash_canon (hash, t);
7660 : 584399200 : if (t != probe_type)
7661 : : return t;
7662 : :
7663 : 383117544 : if (any_structural_p)
7664 : 51891941 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7665 : 331225603 : else if (any_noncanonical_p)
7666 : 75374896 : TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
7667 : : canon_argtypes);
7668 : :
7669 : 383117544 : if (!COMPLETE_TYPE_P (t))
7670 : 0 : layout_type (t);
7671 : : return t;
7672 : : }
7673 : :
7674 : : /* Build a function type. The RETURN_TYPE is the type returned by the
7675 : : function. If VAARGS is set, no void_type_node is appended to the
7676 : : list. ARGP must be always be terminated be a NULL_TREE. */
7677 : :
7678 : : static tree
7679 : 14549550 : build_function_type_list_1 (bool vaargs, tree return_type, va_list argp)
7680 : : {
7681 : 14549550 : tree t, args, last;
7682 : :
7683 : 14549550 : t = va_arg (argp, tree);
7684 : 61690288 : for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree))
7685 : 32591188 : args = tree_cons (NULL_TREE, t, args);
7686 : :
7687 : 14549550 : if (vaargs)
7688 : : {
7689 : 822045 : last = args;
7690 : 822045 : if (args != NULL_TREE)
7691 : 695960 : args = nreverse (args);
7692 : 822045 : gcc_assert (last != void_list_node);
7693 : : }
7694 : 13727505 : else if (args == NULL_TREE)
7695 : 1128166 : args = void_list_node;
7696 : : else
7697 : : {
7698 : 12599339 : last = args;
7699 : 12599339 : args = nreverse (args);
7700 : 12599339 : TREE_CHAIN (last) = void_list_node;
7701 : : }
7702 : 14549550 : args = build_function_type (return_type, args, vaargs && args == NULL_TREE);
7703 : :
7704 : 14549550 : return args;
7705 : : }
7706 : :
7707 : : /* Build a function type. The RETURN_TYPE is the type returned by the
7708 : : function. If additional arguments are provided, they are
7709 : : additional argument types. The list of argument types must always
7710 : : be terminated by NULL_TREE. */
7711 : :
7712 : : tree
7713 : 13727505 : build_function_type_list (tree return_type, ...)
7714 : : {
7715 : 13727505 : tree args;
7716 : 13727505 : va_list p;
7717 : :
7718 : 13727505 : va_start (p, return_type);
7719 : 13727505 : args = build_function_type_list_1 (false, return_type, p);
7720 : 13727505 : va_end (p);
7721 : 13727505 : return args;
7722 : : }
7723 : :
7724 : : /* Build a variable argument function type. The RETURN_TYPE is the
7725 : : type returned by the function. If additional arguments are provided,
7726 : : they are additional argument types. The list of argument types must
7727 : : always be terminated by NULL_TREE. */
7728 : :
7729 : : tree
7730 : 822045 : build_varargs_function_type_list (tree return_type, ...)
7731 : : {
7732 : 822045 : tree args;
7733 : 822045 : va_list p;
7734 : :
7735 : 822045 : va_start (p, return_type);
7736 : 822045 : args = build_function_type_list_1 (true, return_type, p);
7737 : 822045 : va_end (p);
7738 : :
7739 : 822045 : return args;
7740 : : }
7741 : :
7742 : : /* Build a function type. RETURN_TYPE is the type returned by the
7743 : : function; VAARGS indicates whether the function takes varargs. The
7744 : : function takes N named arguments, the types of which are provided in
7745 : : ARG_TYPES. */
7746 : :
7747 : : static tree
7748 : 115383532 : build_function_type_array_1 (bool vaargs, tree return_type, int n,
7749 : : tree *arg_types)
7750 : : {
7751 : 115383532 : int i;
7752 : 115383532 : tree t = vaargs ? NULL_TREE : void_list_node;
7753 : :
7754 : 378166946 : for (i = n - 1; i >= 0; i--)
7755 : 262783414 : t = tree_cons (NULL_TREE, arg_types[i], t);
7756 : :
7757 : 115383532 : return build_function_type (return_type, t, vaargs && n == 0);
7758 : : }
7759 : :
7760 : : /* Build a function type. RETURN_TYPE is the type returned by the
7761 : : function. The function takes N named arguments, the types of which
7762 : : are provided in ARG_TYPES. */
7763 : :
7764 : : tree
7765 : 109154300 : build_function_type_array (tree return_type, int n, tree *arg_types)
7766 : : {
7767 : 109154300 : return build_function_type_array_1 (false, return_type, n, arg_types);
7768 : : }
7769 : :
7770 : : /* Build a variable argument function type. RETURN_TYPE is the type
7771 : : returned by the function. The function takes N named arguments, the
7772 : : types of which are provided in ARG_TYPES. */
7773 : :
7774 : : tree
7775 : 6229232 : build_varargs_function_type_array (tree return_type, int n, tree *arg_types)
7776 : : {
7777 : 6229232 : return build_function_type_array_1 (true, return_type, n, arg_types);
7778 : : }
7779 : :
7780 : : /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
7781 : : and ARGTYPES (a TREE_LIST) are the return type and arguments types
7782 : : for the method. An implicit additional parameter (of type
7783 : : pointer-to-BASETYPE) is added to the ARGTYPES. */
7784 : :
7785 : : tree
7786 : 280478537 : build_method_type_directly (tree basetype,
7787 : : tree rettype,
7788 : : tree argtypes)
7789 : : {
7790 : 280478537 : tree t;
7791 : 280478537 : tree ptype;
7792 : 280478537 : bool any_structural_p, any_noncanonical_p;
7793 : 280478537 : tree canon_argtypes;
7794 : :
7795 : : /* Make a node of the sort we want. */
7796 : 280478537 : t = make_node (METHOD_TYPE);
7797 : :
7798 : 280478537 : TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7799 : 280478537 : TREE_TYPE (t) = rettype;
7800 : 280478537 : ptype = build_pointer_type (basetype);
7801 : :
7802 : : /* The actual arglist for this function includes a "hidden" argument
7803 : : which is "this". Put it into the list of argument types. */
7804 : 280478537 : argtypes = tree_cons (NULL_TREE, ptype, argtypes);
7805 : 280478537 : TYPE_ARG_TYPES (t) = argtypes;
7806 : :
7807 : : /* Set up the canonical type. */
7808 : 280478537 : any_structural_p
7809 : 280478537 : = (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7810 : 280478537 : || TYPE_STRUCTURAL_EQUALITY_P (rettype));
7811 : 280478537 : any_noncanonical_p
7812 : 280478537 : = (TYPE_CANONICAL (basetype) != basetype
7813 : 280478537 : || TYPE_CANONICAL (rettype) != rettype);
7814 : 280478537 : canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes),
7815 : : &any_structural_p,
7816 : : &any_noncanonical_p);
7817 : :
7818 : : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7819 : 280478537 : if (any_structural_p)
7820 : 22549701 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7821 : :
7822 : : /* If we already have such a type, use the old one. */
7823 : 280478537 : hashval_t hash = type_hash_canon_hash (t);
7824 : 280478537 : tree probe_type = t;
7825 : 280478537 : t = type_hash_canon (hash, t);
7826 : 280478537 : if (t != probe_type)
7827 : : return t;
7828 : :
7829 : 213283310 : if (any_structural_p)
7830 : 18708856 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7831 : 194574454 : else if (any_noncanonical_p)
7832 : 72834870 : TYPE_CANONICAL (t)
7833 : 145669740 : = build_method_type_directly (TYPE_CANONICAL (basetype),
7834 : 72834870 : TYPE_CANONICAL (rettype),
7835 : : canon_argtypes);
7836 : 213283310 : if (!COMPLETE_TYPE_P (t))
7837 : 0 : layout_type (t);
7838 : :
7839 : : return t;
7840 : : }
7841 : :
7842 : : /* Construct, lay out and return the type of methods belonging to class
7843 : : BASETYPE and whose arguments and values are described by TYPE.
7844 : : If that type exists already, reuse it.
7845 : : TYPE must be a FUNCTION_TYPE node. */
7846 : :
7847 : : tree
7848 : 155 : build_method_type (tree basetype, tree type)
7849 : : {
7850 : 155 : gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
7851 : :
7852 : 155 : return build_method_type_directly (basetype,
7853 : 155 : TREE_TYPE (type),
7854 : 155 : TYPE_ARG_TYPES (type));
7855 : : }
7856 : :
7857 : : /* Construct, lay out and return the type of offsets to a value
7858 : : of type TYPE, within an object of type BASETYPE.
7859 : : If a suitable offset type exists already, reuse it. */
7860 : :
7861 : : tree
7862 : 946338 : build_offset_type (tree basetype, tree type)
7863 : : {
7864 : 946338 : tree t;
7865 : :
7866 : : /* Make a node of the sort we want. */
7867 : 946338 : t = make_node (OFFSET_TYPE);
7868 : :
7869 : 946338 : TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7870 : 946338 : TREE_TYPE (t) = type;
7871 : 946338 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7872 : 946338 : || TYPE_STRUCTURAL_EQUALITY_P (type))
7873 : 4 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7874 : :
7875 : : /* If we already have such a type, use the old one. */
7876 : 946338 : hashval_t hash = type_hash_canon_hash (t);
7877 : 946338 : tree probe_type = t;
7878 : 946338 : t = type_hash_canon (hash, t);
7879 : 946338 : if (t != probe_type)
7880 : : return t;
7881 : :
7882 : 193780 : if (!COMPLETE_TYPE_P (t))
7883 : 0 : layout_type (t);
7884 : :
7885 : 193780 : if (TYPE_CANONICAL (t) == t)
7886 : : {
7887 : 193776 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7888 : 193776 : || TYPE_STRUCTURAL_EQUALITY_P (type))
7889 : 0 : gcc_unreachable ();
7890 : 193776 : else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
7891 : 193776 : || TYPE_CANONICAL (type) != type)
7892 : 115208 : TYPE_CANONICAL (t)
7893 : 230416 : = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
7894 : 115208 : TYPE_CANONICAL (type));
7895 : : }
7896 : :
7897 : : return t;
7898 : : }
7899 : :
7900 : : /* Create a complex type whose components are COMPONENT_TYPE.
7901 : :
7902 : : If NAMED is true, the type is given a TYPE_NAME. We do not always
7903 : : do so because this creates a DECL node and thus make the DECL_UIDs
7904 : : dependent on the type canonicalization hashtable, which is GC-ed,
7905 : : so the DECL_UIDs would not be stable wrt garbage collection. */
7906 : :
7907 : : tree
7908 : 5127065 : build_complex_type (tree component_type, bool named)
7909 : : {
7910 : 5127065 : gcc_assert (INTEGRAL_TYPE_P (component_type)
7911 : : || SCALAR_FLOAT_TYPE_P (component_type)
7912 : : || FIXED_POINT_TYPE_P (component_type));
7913 : :
7914 : : /* Make a node of the sort we want. */
7915 : 5127065 : tree probe = make_node (COMPLEX_TYPE);
7916 : :
7917 : 5127065 : TREE_TYPE (probe) = TYPE_MAIN_VARIANT (component_type);
7918 : 5127065 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (probe)))
7919 : 0 : SET_TYPE_STRUCTURAL_EQUALITY (probe);
7920 : :
7921 : : /* If we already have such a type, use the old one. */
7922 : 5127065 : hashval_t hash = type_hash_canon_hash (probe);
7923 : 5127065 : tree t = type_hash_canon (hash, probe);
7924 : :
7925 : 5127065 : if (t == probe)
7926 : : {
7927 : : /* We created a new type. The hash insertion will have laid
7928 : : out the type. We need to check the canonicalization and
7929 : : maybe set the name. */
7930 : 3089051 : gcc_checking_assert (COMPLETE_TYPE_P (t)
7931 : : && !TYPE_NAME (t));
7932 : :
7933 : 3089051 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t)))
7934 : : ;
7935 : 3089051 : else if (TYPE_CANONICAL (TREE_TYPE (t)) != TREE_TYPE (t))
7936 : 99 : TYPE_CANONICAL (t)
7937 : 198 : = build_complex_type (TYPE_CANONICAL (TREE_TYPE (t)), named);
7938 : :
7939 : : /* We need to create a name, since complex is a fundamental type. */
7940 : 3089051 : if (named)
7941 : : {
7942 : 1139136 : const char *name = NULL;
7943 : :
7944 : 1139136 : if (TREE_TYPE (t) == char_type_node)
7945 : : name = "complex char";
7946 : 1139136 : else if (TREE_TYPE (t) == signed_char_type_node)
7947 : : name = "complex signed char";
7948 : 1139136 : else if (TREE_TYPE (t) == unsigned_char_type_node)
7949 : : name = "complex unsigned char";
7950 : 1139136 : else if (TREE_TYPE (t) == short_integer_type_node)
7951 : : name = "complex short int";
7952 : 1139136 : else if (TREE_TYPE (t) == short_unsigned_type_node)
7953 : : name = "complex short unsigned int";
7954 : 1139136 : else if (TREE_TYPE (t) == integer_type_node)
7955 : : name = "complex int";
7956 : 854352 : else if (TREE_TYPE (t) == unsigned_type_node)
7957 : : name = "complex unsigned int";
7958 : 854352 : else if (TREE_TYPE (t) == long_integer_type_node)
7959 : : name = "complex long int";
7960 : 854352 : else if (TREE_TYPE (t) == long_unsigned_type_node)
7961 : : name = "complex long unsigned int";
7962 : 854352 : else if (TREE_TYPE (t) == long_long_integer_type_node)
7963 : : name = "complex long long int";
7964 : 854352 : else if (TREE_TYPE (t) == long_long_unsigned_type_node)
7965 : : name = "complex long long unsigned int";
7966 : :
7967 : : if (name != NULL)
7968 : 284784 : TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
7969 : : get_identifier (name), t);
7970 : : }
7971 : : }
7972 : :
7973 : 5127065 : return build_qualified_type (t, TYPE_QUALS (component_type));
7974 : : }
7975 : :
7976 : : /* If TYPE is a real or complex floating-point type and the target
7977 : : does not directly support arithmetic on TYPE then return the wider
7978 : : type to be used for arithmetic on TYPE. Otherwise, return
7979 : : NULL_TREE. */
7980 : :
7981 : : tree
7982 : 89982232 : excess_precision_type (tree type)
7983 : : {
7984 : : /* The target can give two different responses to the question of
7985 : : which excess precision mode it would like depending on whether we
7986 : : are in -fexcess-precision=standard or -fexcess-precision=fast. */
7987 : :
7988 : 3269511 : enum excess_precision_type requested_type
7989 : 89982232 : = (flag_excess_precision == EXCESS_PRECISION_FAST
7990 : 89982232 : ? EXCESS_PRECISION_TYPE_FAST
7991 : : : (flag_excess_precision == EXCESS_PRECISION_FLOAT16
7992 : 3269580 : ? EXCESS_PRECISION_TYPE_FLOAT16 : EXCESS_PRECISION_TYPE_STANDARD));
7993 : :
7994 : 89982232 : enum flt_eval_method target_flt_eval_method
7995 : 89982232 : = targetm.c.excess_precision (requested_type);
7996 : :
7997 : : /* The target should not ask for unpredictable float evaluation (though
7998 : : it might advertise that implicitly the evaluation is unpredictable,
7999 : : but we don't care about that here, it will have been reported
8000 : : elsewhere). If it does ask for unpredictable evaluation, we have
8001 : : nothing to do here. */
8002 : 89982232 : gcc_assert (target_flt_eval_method != FLT_EVAL_METHOD_UNPREDICTABLE);
8003 : :
8004 : : /* Nothing to do. The target has asked for all types we know about
8005 : : to be computed with their native precision and range. */
8006 : 89982232 : if (target_flt_eval_method == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
8007 : : return NULL_TREE;
8008 : :
8009 : : /* The target will promote this type in a target-dependent way, so excess
8010 : : precision ought to leave it alone. */
8011 : 88598869 : if (targetm.promoted_type (type) != NULL_TREE)
8012 : : return NULL_TREE;
8013 : :
8014 : 88598869 : machine_mode float16_type_mode = (float16_type_node
8015 : 88598869 : ? TYPE_MODE (float16_type_node)
8016 : 88598869 : : VOIDmode);
8017 : 88598869 : machine_mode bfloat16_type_mode = (bfloat16_type_node
8018 : 88598869 : ? TYPE_MODE (bfloat16_type_node)
8019 : 88598869 : : VOIDmode);
8020 : 88598869 : machine_mode float_type_mode = TYPE_MODE (float_type_node);
8021 : 88598869 : machine_mode double_type_mode = TYPE_MODE (double_type_node);
8022 : :
8023 : 88598869 : switch (TREE_CODE (type))
8024 : : {
8025 : 61347413 : case REAL_TYPE:
8026 : 61347413 : {
8027 : 61347413 : machine_mode type_mode = TYPE_MODE (type);
8028 : 61347413 : switch (target_flt_eval_method)
8029 : : {
8030 : 61334580 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8031 : 61334580 : if (type_mode == float16_type_mode
8032 : 61334580 : || type_mode == bfloat16_type_mode)
8033 : 280923 : return float_type_node;
8034 : : break;
8035 : 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8036 : 0 : if (type_mode == float16_type_mode
8037 : 0 : || type_mode == bfloat16_type_mode
8038 : 0 : || type_mode == float_type_mode)
8039 : 0 : return double_type_node;
8040 : : break;
8041 : 12833 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8042 : 12833 : if (type_mode == float16_type_mode
8043 : 12833 : || type_mode == bfloat16_type_mode
8044 : 12828 : || type_mode == float_type_mode
8045 : 12828 : || type_mode == double_type_mode)
8046 : 12384 : return long_double_type_node;
8047 : : break;
8048 : 0 : default:
8049 : 0 : gcc_unreachable ();
8050 : : }
8051 : : break;
8052 : : }
8053 : 384134 : case COMPLEX_TYPE:
8054 : 384134 : {
8055 : 384134 : if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
8056 : : return NULL_TREE;
8057 : 374654 : machine_mode type_mode = TYPE_MODE (TREE_TYPE (type));
8058 : 374654 : switch (target_flt_eval_method)
8059 : : {
8060 : 374321 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8061 : 374321 : if (type_mode == float16_type_mode
8062 : 374321 : || type_mode == bfloat16_type_mode)
8063 : 271 : return complex_float_type_node;
8064 : : break;
8065 : 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8066 : 0 : if (type_mode == float16_type_mode
8067 : 0 : || type_mode == bfloat16_type_mode
8068 : 0 : || type_mode == float_type_mode)
8069 : 0 : return complex_double_type_node;
8070 : : break;
8071 : 333 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8072 : 333 : if (type_mode == float16_type_mode
8073 : 333 : || type_mode == bfloat16_type_mode
8074 : 333 : || type_mode == float_type_mode
8075 : 333 : || type_mode == double_type_mode)
8076 : 281 : return complex_long_double_type_node;
8077 : : break;
8078 : 0 : default:
8079 : 0 : gcc_unreachable ();
8080 : : }
8081 : : break;
8082 : : }
8083 : : default:
8084 : : break;
8085 : : }
8086 : :
8087 : : return NULL_TREE;
8088 : : }
8089 : :
8090 : : /* Return OP, stripped of any conversions to wider types as much as is safe.
8091 : : Converting the value back to OP's type makes a value equivalent to OP.
8092 : :
8093 : : If FOR_TYPE is nonzero, we return a value which, if converted to
8094 : : type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8095 : :
8096 : : OP must have integer, real or enumeral type. Pointers are not allowed!
8097 : :
8098 : : There are some cases where the obvious value we could return
8099 : : would regenerate to OP if converted to OP's type,
8100 : : but would not extend like OP to wider types.
8101 : : If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8102 : : For example, if OP is (unsigned short)(signed char)-1,
8103 : : we avoid returning (signed char)-1 if FOR_TYPE is int,
8104 : : even though extending that to an unsigned short would regenerate OP,
8105 : : since the result of extending (signed char)-1 to (int)
8106 : : is different from (int) OP. */
8107 : :
8108 : : tree
8109 : 10359972 : get_unwidened (tree op, tree for_type)
8110 : : {
8111 : : /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8112 : 10359972 : tree type = TREE_TYPE (op);
8113 : 10359972 : unsigned final_prec
8114 : 17919167 : = TYPE_PRECISION (for_type != 0 ? for_type : type);
8115 : 10359972 : int uns
8116 : 10359972 : = (for_type != 0 && for_type != type
8117 : 2498517 : && final_prec > TYPE_PRECISION (type)
8118 : 10426055 : && TYPE_UNSIGNED (type));
8119 : 10359972 : tree win = op;
8120 : :
8121 : 10566674 : while (CONVERT_EXPR_P (op))
8122 : : {
8123 : 206731 : int bitschange;
8124 : :
8125 : : /* TYPE_PRECISION on vector types has different meaning
8126 : : (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8127 : : so avoid them here. */
8128 : 206731 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
8129 : : break;
8130 : :
8131 : 206731 : bitschange = TYPE_PRECISION (TREE_TYPE (op))
8132 : 206731 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
8133 : :
8134 : : /* Truncations are many-one so cannot be removed.
8135 : : Unless we are later going to truncate down even farther. */
8136 : 206731 : if (bitschange < 0
8137 : 206731 : && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
8138 : : break;
8139 : :
8140 : : /* See what's inside this conversion. If we decide to strip it,
8141 : : we will set WIN. */
8142 : 206702 : op = TREE_OPERAND (op, 0);
8143 : :
8144 : : /* If we have not stripped any zero-extensions (uns is 0),
8145 : : we can strip any kind of extension.
8146 : : If we have previously stripped a zero-extension,
8147 : : only zero-extensions can safely be stripped.
8148 : : Any extension can be stripped if the bits it would produce
8149 : : are all going to be discarded later by truncating to FOR_TYPE. */
8150 : :
8151 : 206702 : if (bitschange > 0)
8152 : : {
8153 : 118895 : if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
8154 : : win = op;
8155 : : /* TYPE_UNSIGNED says whether this is a zero-extension.
8156 : : Let's avoid computing it if it does not affect WIN
8157 : : and if UNS will not be needed again. */
8158 : 118895 : if ((uns
8159 : 118864 : || CONVERT_EXPR_P (op))
8160 : 119436 : && TYPE_UNSIGNED (TREE_TYPE (op)))
8161 : : {
8162 : : uns = 1;
8163 : : win = op;
8164 : : }
8165 : : }
8166 : : }
8167 : :
8168 : : /* If we finally reach a constant see if it fits in sth smaller and
8169 : : in that case convert it. */
8170 : 10359972 : if (TREE_CODE (win) == INTEGER_CST)
8171 : : {
8172 : 449394 : tree wtype = TREE_TYPE (win);
8173 : 449394 : unsigned prec = wi::min_precision (wi::to_wide (win), TYPE_SIGN (wtype));
8174 : 449394 : if (for_type)
8175 : 444824 : prec = MAX (prec, final_prec);
8176 : 449394 : if (prec < TYPE_PRECISION (wtype))
8177 : : {
8178 : 443427 : tree t = lang_hooks.types.type_for_size (prec, TYPE_UNSIGNED (wtype));
8179 : 443427 : if (t && TYPE_PRECISION (t) < TYPE_PRECISION (wtype))
8180 : 437984 : win = fold_convert (t, win);
8181 : : }
8182 : : }
8183 : :
8184 : 10359972 : return win;
8185 : : }
8186 : :
8187 : : /* Return OP or a simpler expression for a narrower value
8188 : : which can be sign-extended or zero-extended to give back OP.
8189 : : Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8190 : : or 0 if the value should be sign-extended. */
8191 : :
8192 : : tree
8193 : 63945437 : get_narrower (tree op, int *unsignedp_ptr)
8194 : : {
8195 : 63945437 : int uns = 0;
8196 : 63945437 : bool first = true;
8197 : 63945437 : tree win = op;
8198 : 63945437 : bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
8199 : :
8200 : 63945437 : if (TREE_CODE (op) == COMPOUND_EXPR)
8201 : : {
8202 : 81612 : do
8203 : 81612 : op = TREE_OPERAND (op, 1);
8204 : 81612 : while (TREE_CODE (op) == COMPOUND_EXPR);
8205 : 81597 : tree ret = get_narrower (op, unsignedp_ptr);
8206 : 81597 : if (ret == op)
8207 : : return win;
8208 : 4264 : auto_vec <tree, 16> v;
8209 : 4264 : unsigned int i;
8210 : 8535 : for (op = win; TREE_CODE (op) == COMPOUND_EXPR;
8211 : 4271 : op = TREE_OPERAND (op, 1))
8212 : 4271 : v.safe_push (op);
8213 : 12799 : FOR_EACH_VEC_ELT_REVERSE (v, i, op)
8214 : 4271 : ret = build2_loc (EXPR_LOCATION (op), COMPOUND_EXPR,
8215 : 4271 : TREE_TYPE (ret), TREE_OPERAND (op, 0),
8216 : : ret);
8217 : 4264 : return ret;
8218 : 4264 : }
8219 : 76132531 : while (TREE_CODE (op) == NOP_EXPR)
8220 : : {
8221 : 12302051 : int bitschange
8222 : 12302051 : = (TYPE_PRECISION (TREE_TYPE (op))
8223 : 12302051 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
8224 : :
8225 : : /* Truncations are many-one so cannot be removed. */
8226 : 12302051 : if (bitschange < 0)
8227 : : break;
8228 : :
8229 : : /* See what's inside this conversion. If we decide to strip it,
8230 : : we will set WIN. */
8231 : :
8232 : 12268787 : if (bitschange > 0)
8233 : : {
8234 : 2932548 : op = TREE_OPERAND (op, 0);
8235 : : /* An extension: the outermost one can be stripped,
8236 : : but remember whether it is zero or sign extension. */
8237 : 2932548 : if (first)
8238 : 2929609 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8239 : : /* Otherwise, if a sign extension has been stripped,
8240 : : only sign extensions can now be stripped;
8241 : : if a zero extension has been stripped, only zero-extensions. */
8242 : 2939 : else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
8243 : : break;
8244 : : first = false;
8245 : : }
8246 : : else /* bitschange == 0 */
8247 : : {
8248 : : /* A change in nominal type can always be stripped, but we must
8249 : : preserve the unsignedness. */
8250 : 9336239 : if (first)
8251 : 8808378 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8252 : 9336239 : first = false;
8253 : 9336239 : op = TREE_OPERAND (op, 0);
8254 : : /* Keep trying to narrow, but don't assign op to win if it
8255 : : would turn an integral type into something else. */
8256 : 16920947 : if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
8257 : 100785 : continue;
8258 : : }
8259 : :
8260 : 12167906 : win = op;
8261 : : }
8262 : :
8263 : 63863840 : if (TREE_CODE (op) == COMPONENT_REF
8264 : : /* Since type_for_size always gives an integer type. */
8265 : 2324744 : && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
8266 : 2222321 : && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE
8267 : : /* Ensure field is laid out already. */
8268 : 2222321 : && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
8269 : 66086158 : && tree_fits_uhwi_p (DECL_SIZE (TREE_OPERAND (op, 1))))
8270 : : {
8271 : 2222318 : unsigned HOST_WIDE_INT innerprec
8272 : 2222318 : = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (op, 1)));
8273 : 2222318 : int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
8274 : 2222318 : || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
8275 : 2222318 : tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
8276 : :
8277 : : /* We can get this structure field in a narrower type that fits it,
8278 : : but the resulting extension to its nominal type (a fullword type)
8279 : : must satisfy the same conditions as for other extensions.
8280 : :
8281 : : Do this only for fields that are aligned (not bit-fields),
8282 : : because when bit-field insns will be used there is no
8283 : : advantage in doing this. */
8284 : :
8285 : 2222318 : if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
8286 : 0 : && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
8287 : 0 : && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
8288 : 2222318 : && type != 0)
8289 : : {
8290 : 0 : if (first)
8291 : 0 : uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
8292 : 0 : win = fold_convert (type, op);
8293 : : }
8294 : : }
8295 : :
8296 : 63863840 : *unsignedp_ptr = uns;
8297 : 63863840 : return win;
8298 : : }
8299 : :
8300 : : /* Return true if integer constant C has a value that is permissible
8301 : : for TYPE, an integral type. */
8302 : :
8303 : : bool
8304 : 116670665 : int_fits_type_p (const_tree c, const_tree type)
8305 : : {
8306 : 116670665 : tree type_low_bound, type_high_bound;
8307 : 116670665 : bool ok_for_low_bound, ok_for_high_bound;
8308 : 116670665 : signop sgn_c = TYPE_SIGN (TREE_TYPE (c));
8309 : :
8310 : : /* Non-standard boolean types can have arbitrary precision but various
8311 : : transformations assume that they can only take values 0 and +/-1. */
8312 : 116670665 : if (TREE_CODE (type) == BOOLEAN_TYPE)
8313 : 1035728 : return wi::fits_to_boolean_p (wi::to_wide (c), type);
8314 : :
8315 : 115634937 : retry:
8316 : 115646772 : type_low_bound = TYPE_MIN_VALUE (type);
8317 : 115646772 : type_high_bound = TYPE_MAX_VALUE (type);
8318 : :
8319 : : /* If at least one bound of the type is a constant integer, we can check
8320 : : ourselves and maybe make a decision. If no such decision is possible, but
8321 : : this type is a subtype, try checking against that. Otherwise, use
8322 : : fits_to_tree_p, which checks against the precision.
8323 : :
8324 : : Compute the status for each possibly constant bound, and return if we see
8325 : : one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8326 : : for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8327 : : for "constant known to fit". */
8328 : :
8329 : : /* Check if c >= type_low_bound. */
8330 : 115646772 : if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
8331 : : {
8332 : 115646772 : if (tree_int_cst_lt (c, type_low_bound))
8333 : : return false;
8334 : : ok_for_low_bound = true;
8335 : : }
8336 : : else
8337 : : ok_for_low_bound = false;
8338 : :
8339 : : /* Check if c <= type_high_bound. */
8340 : 115402220 : if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
8341 : : {
8342 : 115370753 : if (tree_int_cst_lt (type_high_bound, c))
8343 : : return false;
8344 : : ok_for_high_bound = true;
8345 : : }
8346 : : else
8347 : : ok_for_high_bound = false;
8348 : :
8349 : : /* If the constant fits both bounds, the result is known. */
8350 : 113659315 : if (ok_for_low_bound && ok_for_high_bound)
8351 : : return true;
8352 : :
8353 : : /* Perform some generic filtering which may allow making a decision
8354 : : even if the bounds are not constant. First, negative integers
8355 : : never fit in unsigned types, */
8356 : 31467 : if (TYPE_UNSIGNED (type) && sgn_c == SIGNED && wi::neg_p (wi::to_wide (c)))
8357 : 0 : return false;
8358 : :
8359 : : /* Second, narrower types always fit in wider ones. */
8360 : 31467 : if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
8361 : : return true;
8362 : :
8363 : : /* Third, unsigned integers with top bit set never fit signed types. */
8364 : 11844 : if (!TYPE_UNSIGNED (type) && sgn_c == UNSIGNED)
8365 : : {
8366 : 14 : int prec = GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (c))) - 1;
8367 : 14 : if (prec < TYPE_PRECISION (TREE_TYPE (c)))
8368 : : {
8369 : : /* When a tree_cst is converted to a wide-int, the precision
8370 : : is taken from the type. However, if the precision of the
8371 : : mode underneath the type is smaller than that, it is
8372 : : possible that the value will not fit. The test below
8373 : : fails if any bit is set between the sign bit of the
8374 : : underlying mode and the top bit of the type. */
8375 : 14 : if (wi::zext (wi::to_wide (c), prec - 1) != wi::to_wide (c))
8376 : : return false;
8377 : : }
8378 : 0 : else if (wi::neg_p (wi::to_wide (c)))
8379 : : return false;
8380 : : }
8381 : :
8382 : : /* If we haven't been able to decide at this point, there nothing more we
8383 : : can check ourselves here. Look at the base type if we have one and it
8384 : : has the same precision. */
8385 : 11835 : if (TREE_CODE (type) == INTEGER_TYPE
8386 : 11835 : && TREE_TYPE (type) != 0
8387 : 23670 : && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
8388 : : {
8389 : 11835 : type = TREE_TYPE (type);
8390 : 11835 : goto retry;
8391 : : }
8392 : :
8393 : : /* Or to fits_to_tree_p, if nothing else. */
8394 : 0 : return wi::fits_to_tree_p (wi::to_wide (c), type);
8395 : : }
8396 : :
8397 : : /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8398 : : bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8399 : : represented (assuming two's-complement arithmetic) within the bit
8400 : : precision of the type are returned instead. */
8401 : :
8402 : : void
8403 : 20831222 : get_type_static_bounds (const_tree type, mpz_t min, mpz_t max)
8404 : : {
8405 : 19374596 : if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type)
8406 : 40205818 : && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
8407 : 19374596 : wi::to_mpz (wi::to_wide (TYPE_MIN_VALUE (type)), min, TYPE_SIGN (type));
8408 : : else
8409 : : {
8410 : 1456626 : if (TYPE_UNSIGNED (type))
8411 : 1456626 : mpz_set_ui (min, 0);
8412 : : else
8413 : : {
8414 : 0 : wide_int mn = wi::min_value (TYPE_PRECISION (type), SIGNED);
8415 : 0 : wi::to_mpz (mn, min, SIGNED);
8416 : 0 : }
8417 : : }
8418 : :
8419 : 19374596 : if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
8420 : 40205818 : && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
8421 : 19374596 : wi::to_mpz (wi::to_wide (TYPE_MAX_VALUE (type)), max, TYPE_SIGN (type));
8422 : : else
8423 : : {
8424 : 1456626 : wide_int mn = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
8425 : 1456626 : wi::to_mpz (mn, max, TYPE_SIGN (type));
8426 : 1456626 : }
8427 : 20831222 : }
8428 : :
8429 : : /* Return true if VAR is an automatic variable. */
8430 : :
8431 : : bool
8432 : 368928112 : auto_var_p (const_tree var)
8433 : : {
8434 : 202943340 : return ((((VAR_P (var) && ! DECL_EXTERNAL (var))
8435 : 169327696 : || TREE_CODE (var) == PARM_DECL)
8436 : 262506448 : && ! TREE_STATIC (var))
8437 : 483665419 : || TREE_CODE (var) == RESULT_DECL);
8438 : : }
8439 : :
8440 : : /* Return true if VAR is an automatic variable defined in function FN. */
8441 : :
8442 : : bool
8443 : 1079414823 : auto_var_in_fn_p (const_tree var, const_tree fn)
8444 : : {
8445 : 339733284 : return (DECL_P (var) && DECL_CONTEXT (var) == fn
8446 : 1324755612 : && (auto_var_p (var)
8447 : 4213324 : || TREE_CODE (var) == LABEL_DECL));
8448 : : }
8449 : :
8450 : : /* Subprogram of following function. Called by walk_tree.
8451 : :
8452 : : Return *TP if it is an automatic variable or parameter of the
8453 : : function passed in as DATA. */
8454 : :
8455 : : static tree
8456 : 120279 : find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
8457 : : {
8458 : 120279 : tree fn = (tree) data;
8459 : :
8460 : 120279 : if (TYPE_P (*tp))
8461 : 0 : *walk_subtrees = 0;
8462 : :
8463 : 120279 : else if (DECL_P (*tp)
8464 : 120279 : && auto_var_in_fn_p (*tp, fn))
8465 : 111731 : return *tp;
8466 : :
8467 : : return NULL_TREE;
8468 : : }
8469 : :
8470 : : /* Returns true if T is, contains, or refers to a type with variable
8471 : : size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8472 : : arguments, but not the return type. If FN is nonzero, only return
8473 : : true if a modifier of the type or position of FN is a variable or
8474 : : parameter inside FN.
8475 : :
8476 : : This concept is more general than that of C99 'variably modified types':
8477 : : in C99, a struct type is never variably modified because a VLA may not
8478 : : appear as a structure member. However, in GNU C code like:
8479 : :
8480 : : struct S { int i[f()]; };
8481 : :
8482 : : is valid, and other languages may define similar constructs. */
8483 : :
8484 : : bool
8485 : 1767675602 : variably_modified_type_p (tree type, tree fn)
8486 : : {
8487 : 1767675602 : tree t;
8488 : :
8489 : : /* Test if T is either variable (if FN is zero) or an expression containing
8490 : : a variable in FN. If TYPE isn't gimplified, return true also if
8491 : : gimplify_one_sizepos would gimplify the expression into a local
8492 : : variable. */
8493 : : #define RETURN_TRUE_IF_VAR(T) \
8494 : : do { tree _t = (T); \
8495 : : if (_t != NULL_TREE \
8496 : : && _t != error_mark_node \
8497 : : && !CONSTANT_CLASS_P (_t) \
8498 : : && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8499 : : && (!fn \
8500 : : || (!TYPE_SIZES_GIMPLIFIED (type) \
8501 : : && (TREE_CODE (_t) != VAR_DECL \
8502 : : && !CONTAINS_PLACEHOLDER_P (_t))) \
8503 : : || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8504 : : return true; } while (0)
8505 : :
8506 : 1767675602 : if (type == error_mark_node)
8507 : : return false;
8508 : :
8509 : : /* If TYPE itself has variable size, it is variably modified. */
8510 : 1767439367 : RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
8511 : 1767317940 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
8512 : :
8513 : 1767317316 : switch (TREE_CODE (type))
8514 : : {
8515 : 494128132 : case POINTER_TYPE:
8516 : 494128132 : case REFERENCE_TYPE:
8517 : 494128132 : case VECTOR_TYPE:
8518 : : /* Ada can have pointer types refering to themselves indirectly. */
8519 : 494128132 : if (TREE_VISITED (type))
8520 : : return false;
8521 : 494128132 : TREE_VISITED (type) = true;
8522 : 494128132 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8523 : : {
8524 : 76547 : TREE_VISITED (type) = false;
8525 : 76547 : return true;
8526 : : }
8527 : 494051585 : TREE_VISITED (type) = false;
8528 : 494051585 : break;
8529 : :
8530 : 85486473 : case FUNCTION_TYPE:
8531 : 85486473 : case METHOD_TYPE:
8532 : : /* If TYPE is a function type, it is variably modified if the
8533 : : return type is variably modified. */
8534 : 85486473 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8535 : : return true;
8536 : : break;
8537 : :
8538 : 419952071 : case INTEGER_TYPE:
8539 : 419952071 : case REAL_TYPE:
8540 : 419952071 : case FIXED_POINT_TYPE:
8541 : 419952071 : case ENUMERAL_TYPE:
8542 : 419952071 : case BOOLEAN_TYPE:
8543 : : /* Scalar types are variably modified if their end points
8544 : : aren't constant. */
8545 : 419952071 : RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
8546 : 419952071 : RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
8547 : 419918512 : break;
8548 : :
8549 : 627527348 : case RECORD_TYPE:
8550 : 627527348 : case UNION_TYPE:
8551 : 627527348 : case QUAL_UNION_TYPE:
8552 : : /* We can't see if any of the fields are variably-modified by the
8553 : : definition we normally use, since that would produce infinite
8554 : : recursion via pointers. */
8555 : : /* This is variably modified if some field's type is. */
8556 : 29122340651 : for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
8557 : 28494813303 : if (TREE_CODE (t) == FIELD_DECL)
8558 : : {
8559 : 957194311 : RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
8560 : 957194311 : RETURN_TRUE_IF_VAR (DECL_SIZE (t));
8561 : 957194311 : RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
8562 : :
8563 : : /* If the type is a qualified union, then the DECL_QUALIFIER
8564 : : of fields can also be an expression containing a variable. */
8565 : 957194311 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
8566 : 0 : RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
8567 : :
8568 : : /* If the field is a qualified union, then it's only a container
8569 : : for what's inside so we look into it. That's necessary in LTO
8570 : : mode because the sizes of the field tested above have been set
8571 : : to PLACEHOLDER_EXPRs by free_lang_data. */
8572 : 957194311 : if (TREE_CODE (TREE_TYPE (t)) == QUAL_UNION_TYPE
8573 : 957194311 : && variably_modified_type_p (TREE_TYPE (t), fn))
8574 : : return true;
8575 : : }
8576 : : break;
8577 : :
8578 : 11234237 : case ARRAY_TYPE:
8579 : : /* Do not call ourselves to avoid infinite recursion. This is
8580 : : variably modified if the element type is. */
8581 : 11234237 : RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
8582 : 11230776 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
8583 : 11230758 : break;
8584 : :
8585 : : default:
8586 : : break;
8587 : : }
8588 : :
8589 : : /* The current language may have other cases to check, but in general,
8590 : : all other types are not variably modified. */
8591 : 1767203501 : return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
8592 : :
8593 : : #undef RETURN_TRUE_IF_VAR
8594 : : }
8595 : :
8596 : : /* Given a DECL or TYPE, return the scope in which it was declared, or
8597 : : NULL_TREE if there is no containing scope. */
8598 : :
8599 : : tree
8600 : 2267309194 : get_containing_scope (const_tree t)
8601 : : {
8602 : 2267309194 : return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
8603 : : }
8604 : :
8605 : : /* Returns the ultimate TRANSLATION_UNIT_DECL context of DECL or NULL. */
8606 : :
8607 : : const_tree
8608 : 13263 : get_ultimate_context (const_tree decl)
8609 : : {
8610 : 35760 : while (decl && TREE_CODE (decl) != TRANSLATION_UNIT_DECL)
8611 : : {
8612 : 22497 : if (TREE_CODE (decl) == BLOCK)
8613 : 0 : decl = BLOCK_SUPERCONTEXT (decl);
8614 : : else
8615 : 22497 : decl = get_containing_scope (decl);
8616 : : }
8617 : 13263 : return decl;
8618 : : }
8619 : :
8620 : : /* Return the innermost context enclosing DECL that is
8621 : : a FUNCTION_DECL, or zero if none. */
8622 : :
8623 : : tree
8624 : 1262665081 : decl_function_context (const_tree decl)
8625 : : {
8626 : 1262665081 : tree context;
8627 : :
8628 : 1262665081 : if (TREE_CODE (decl) == ERROR_MARK)
8629 : : return 0;
8630 : :
8631 : : /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8632 : : where we look up the function at runtime. Such functions always take
8633 : : a first argument of type 'pointer to real context'.
8634 : :
8635 : : C++ should really be fixed to use DECL_CONTEXT for the real context,
8636 : : and use something else for the "virtual context". */
8637 : 1262665081 : else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
8638 : 4109632 : context
8639 : 4109632 : = TYPE_MAIN_VARIANT
8640 : : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
8641 : : else
8642 : 1258555449 : context = DECL_CONTEXT (decl);
8643 : :
8644 : 2856337132 : while (context && TREE_CODE (context) != FUNCTION_DECL)
8645 : : {
8646 : 1593672051 : if (TREE_CODE (context) == BLOCK)
8647 : 0 : context = BLOCK_SUPERCONTEXT (context);
8648 : : else
8649 : 1593672051 : context = get_containing_scope (context);
8650 : : }
8651 : :
8652 : : return context;
8653 : : }
8654 : :
8655 : : /* Return the innermost context enclosing DECL that is
8656 : : a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8657 : : TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8658 : :
8659 : : tree
8660 : 52042173 : decl_type_context (const_tree decl)
8661 : : {
8662 : 52042173 : tree context = DECL_CONTEXT (decl);
8663 : :
8664 : 54482687 : while (context)
8665 : 48901820 : switch (TREE_CODE (context))
8666 : : {
8667 : : case NAMESPACE_DECL:
8668 : : case TRANSLATION_UNIT_DECL:
8669 : : return NULL_TREE;
8670 : :
8671 : : case RECORD_TYPE:
8672 : : case UNION_TYPE:
8673 : : case QUAL_UNION_TYPE:
8674 : : return context;
8675 : :
8676 : 2440514 : case TYPE_DECL:
8677 : 2440514 : case FUNCTION_DECL:
8678 : 2440514 : context = DECL_CONTEXT (context);
8679 : 2440514 : break;
8680 : :
8681 : 0 : case BLOCK:
8682 : 0 : context = BLOCK_SUPERCONTEXT (context);
8683 : 0 : break;
8684 : :
8685 : 0 : default:
8686 : 0 : gcc_unreachable ();
8687 : : }
8688 : :
8689 : : return NULL_TREE;
8690 : : }
8691 : :
8692 : : /* CALL is a CALL_EXPR. Return the declaration for the function
8693 : : called, or NULL_TREE if the called function cannot be
8694 : : determined. */
8695 : :
8696 : : tree
8697 : 943382220 : get_callee_fndecl (const_tree call)
8698 : : {
8699 : 943382220 : tree addr;
8700 : :
8701 : 943382220 : if (call == error_mark_node)
8702 : : return error_mark_node;
8703 : :
8704 : : /* It's invalid to call this function with anything but a
8705 : : CALL_EXPR. */
8706 : 943382220 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8707 : :
8708 : : /* The first operand to the CALL is the address of the function
8709 : : called. */
8710 : 943382220 : addr = CALL_EXPR_FN (call);
8711 : :
8712 : : /* If there is no function, return early. */
8713 : 943382220 : if (addr == NULL_TREE)
8714 : : return NULL_TREE;
8715 : :
8716 : 941915633 : STRIP_NOPS (addr);
8717 : :
8718 : : /* If this is a readonly function pointer, extract its initial value. */
8719 : 16343488 : if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
8720 : 1679335 : && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
8721 : 942081240 : && DECL_INITIAL (addr))
8722 : 165516 : addr = DECL_INITIAL (addr);
8723 : :
8724 : : /* If the address is just `&f' for some function `f', then we know
8725 : : that `f' is being called. */
8726 : 941915633 : if (TREE_CODE (addr) == ADDR_EXPR
8727 : 941915633 : && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
8728 : 901368245 : return TREE_OPERAND (addr, 0);
8729 : :
8730 : : /* We couldn't figure out what was being called. */
8731 : : return NULL_TREE;
8732 : : }
8733 : :
8734 : : /* Return true when STMTs arguments and return value match those of FNDECL,
8735 : : a decl of a builtin function. */
8736 : :
8737 : : static bool
8738 : 5184815 : tree_builtin_call_types_compatible_p (const_tree call, tree fndecl)
8739 : : {
8740 : 5184815 : gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN);
8741 : :
8742 : 5184815 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
8743 : 5184815 : if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
8744 : 5184815 : fndecl = decl;
8745 : :
8746 : 5184815 : bool gimple_form = (cfun && (cfun->curr_properties & PROP_gimple)) != 0;
8747 : 5184815 : if (gimple_form
8748 : 12989 : ? !useless_type_conversion_p (TREE_TYPE (call),
8749 : 12989 : TREE_TYPE (TREE_TYPE (fndecl)))
8750 : 5171826 : : (TYPE_MAIN_VARIANT (TREE_TYPE (call))
8751 : 5171826 : != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))))
8752 : : return false;
8753 : :
8754 : 5184599 : tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
8755 : 5184599 : unsigned nargs = call_expr_nargs (call);
8756 : 13814280 : for (unsigned i = 0; i < nargs; ++i, targs = TREE_CHAIN (targs))
8757 : : {
8758 : : /* Variadic args follow. */
8759 : 9553402 : if (!targs)
8760 : : return true;
8761 : 8630338 : tree arg = CALL_EXPR_ARG (call, i);
8762 : 8630338 : tree type = TREE_VALUE (targs);
8763 : 8630338 : if (gimple_form
8764 : 8630338 : ? !useless_type_conversion_p (type, TREE_TYPE (arg))
8765 : 8617349 : : TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (TREE_TYPE (arg)))
8766 : : {
8767 : : /* For pointer arguments be more forgiving, e.g. due to
8768 : : FILE * vs. fileptr_type_node, or say char * vs. const char *
8769 : : differences etc. */
8770 : 1105835 : if (!gimple_form
8771 : 553246 : && POINTER_TYPE_P (type)
8772 : 552694 : && POINTER_TYPE_P (TREE_TYPE (arg))
8773 : 1105835 : && tree_nop_conversion_p (type, TREE_TYPE (arg)))
8774 : 552589 : continue;
8775 : 657 : return false;
8776 : : }
8777 : : }
8778 : 8521109 : if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
8779 : : return false;
8780 : : return true;
8781 : : }
8782 : :
8783 : : /* If CALL_EXPR CALL calls a normal built-in function or an internal function,
8784 : : return the associated function code, otherwise return CFN_LAST. */
8785 : :
8786 : : combined_fn
8787 : 38200138 : get_call_combined_fn (const_tree call)
8788 : : {
8789 : : /* It's invalid to call this function with anything but a CALL_EXPR. */
8790 : 38200138 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8791 : :
8792 : 38200138 : if (!CALL_EXPR_FN (call))
8793 : 65968 : return as_combined_fn (CALL_EXPR_IFN (call));
8794 : :
8795 : 38134170 : tree fndecl = get_callee_fndecl (call);
8796 : 38134170 : if (fndecl
8797 : 38113675 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
8798 : 43318985 : && tree_builtin_call_types_compatible_p (call, fndecl))
8799 : 5183937 : return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
8800 : :
8801 : : return CFN_LAST;
8802 : : }
8803 : :
8804 : : /* Comparator of indices based on tree_node_counts. */
8805 : :
8806 : : static int
8807 : 0 : tree_nodes_cmp (const void *p1, const void *p2)
8808 : : {
8809 : 0 : const unsigned *n1 = (const unsigned *)p1;
8810 : 0 : const unsigned *n2 = (const unsigned *)p2;
8811 : :
8812 : 0 : return tree_node_counts[*n1] - tree_node_counts[*n2];
8813 : : }
8814 : :
8815 : : /* Comparator of indices based on tree_code_counts. */
8816 : :
8817 : : static int
8818 : 0 : tree_codes_cmp (const void *p1, const void *p2)
8819 : : {
8820 : 0 : const unsigned *n1 = (const unsigned *)p1;
8821 : 0 : const unsigned *n2 = (const unsigned *)p2;
8822 : :
8823 : 0 : return tree_code_counts[*n1] - tree_code_counts[*n2];
8824 : : }
8825 : :
8826 : : #define TREE_MEM_USAGE_SPACES 40
8827 : :
8828 : : /* Print debugging information about tree nodes generated during the compile,
8829 : : and any language-specific information. */
8830 : :
8831 : : void
8832 : 0 : dump_tree_statistics (void)
8833 : : {
8834 : 0 : if (GATHER_STATISTICS)
8835 : : {
8836 : : uint64_t total_nodes, total_bytes;
8837 : : fprintf (stderr, "\nKind Nodes Bytes\n");
8838 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8839 : : total_nodes = total_bytes = 0;
8840 : :
8841 : : {
8842 : : auto_vec<unsigned> indices (all_kinds);
8843 : : for (unsigned i = 0; i < all_kinds; i++)
8844 : : indices.quick_push (i);
8845 : : indices.qsort (tree_nodes_cmp);
8846 : :
8847 : : for (unsigned i = 0; i < (int) all_kinds; i++)
8848 : : {
8849 : : unsigned j = indices[i];
8850 : : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n",
8851 : : tree_node_kind_names[j], SIZE_AMOUNT (tree_node_counts[j]),
8852 : : SIZE_AMOUNT (tree_node_sizes[j]));
8853 : : total_nodes += tree_node_counts[j];
8854 : : total_bytes += tree_node_sizes[j];
8855 : : }
8856 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8857 : : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n", "Total",
8858 : : SIZE_AMOUNT (total_nodes), SIZE_AMOUNT (total_bytes));
8859 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8860 : : }
8861 : :
8862 : : {
8863 : : fprintf (stderr, "Code Nodes\n");
8864 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8865 : :
8866 : : auto_vec<unsigned> indices (MAX_TREE_CODES);
8867 : : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8868 : : indices.quick_push (i);
8869 : : indices.qsort (tree_codes_cmp);
8870 : :
8871 : : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8872 : : {
8873 : : unsigned j = indices[i];
8874 : : fprintf (stderr, "%-32s %6" PRIu64 "%c\n",
8875 : : get_tree_code_name ((enum tree_code) j),
8876 : : SIZE_AMOUNT (tree_code_counts[j]));
8877 : : }
8878 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8879 : : fprintf (stderr, "\n");
8880 : : ssanames_print_statistics ();
8881 : : fprintf (stderr, "\n");
8882 : : phinodes_print_statistics ();
8883 : : fprintf (stderr, "\n");
8884 : : }
8885 : : }
8886 : : else
8887 : 0 : fprintf (stderr, "(No per-node statistics)\n");
8888 : :
8889 : 0 : print_type_hash_statistics ();
8890 : 0 : print_debug_expr_statistics ();
8891 : 0 : print_value_expr_statistics ();
8892 : 0 : lang_hooks.print_statistics ();
8893 : 0 : }
8894 : :
8895 : : #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
8896 : :
8897 : : /* Generate a crc32 of the low BYTES bytes of VALUE. */
8898 : :
8899 : : unsigned
8900 : 16705837 : crc32_unsigned_n (unsigned chksum, unsigned value, unsigned bytes)
8901 : : {
8902 : : /* This relies on the raw feedback's top 4 bits being zero. */
8903 : : #define FEEDBACK(X) ((X) * 0x04c11db7)
8904 : : #define SYNDROME(X) (FEEDBACK ((X) & 1) ^ FEEDBACK ((X) & 2) \
8905 : : ^ FEEDBACK ((X) & 4) ^ FEEDBACK ((X) & 8))
8906 : 16705837 : static const unsigned syndromes[16] =
8907 : : {
8908 : : SYNDROME(0x0), SYNDROME(0x1), SYNDROME(0x2), SYNDROME(0x3),
8909 : : SYNDROME(0x4), SYNDROME(0x5), SYNDROME(0x6), SYNDROME(0x7),
8910 : : SYNDROME(0x8), SYNDROME(0x9), SYNDROME(0xa), SYNDROME(0xb),
8911 : : SYNDROME(0xc), SYNDROME(0xd), SYNDROME(0xe), SYNDROME(0xf),
8912 : : };
8913 : : #undef FEEDBACK
8914 : : #undef SYNDROME
8915 : :
8916 : 16705837 : value <<= (32 - bytes * 8);
8917 : 55086129 : for (unsigned ix = bytes * 2; ix--; value <<= 4)
8918 : : {
8919 : 38380292 : unsigned feedback = syndromes[((value ^ chksum) >> 28) & 0xf];
8920 : :
8921 : 38380292 : chksum = (chksum << 4) ^ feedback;
8922 : : }
8923 : :
8924 : 16705837 : return chksum;
8925 : : }
8926 : :
8927 : : /* Generate a crc32 of a string. */
8928 : :
8929 : : unsigned
8930 : 8597 : crc32_string (unsigned chksum, const char *string)
8931 : : {
8932 : 344461 : do
8933 : 344461 : chksum = crc32_byte (chksum, *string);
8934 : 344461 : while (*string++);
8935 : 8597 : return chksum;
8936 : : }
8937 : :
8938 : : /* P is a string that will be used in a symbol. Mask out any characters
8939 : : that are not valid in that context. */
8940 : :
8941 : : void
8942 : 7087 : clean_symbol_name (char *p)
8943 : : {
8944 : 79659 : for (; *p; p++)
8945 : 72572 : if (! (ISALNUM (*p)
8946 : : #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
8947 : : || *p == '$'
8948 : : #endif
8949 : : #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
8950 : : || *p == '.'
8951 : : #endif
8952 : : ))
8953 : 6538 : *p = '_';
8954 : 7087 : }
8955 : :
8956 : : static GTY(()) unsigned anon_cnt = 0; /* Saved for PCH. */
8957 : :
8958 : : /* Create a unique anonymous identifier. The identifier is still a
8959 : : valid assembly label. */
8960 : :
8961 : : tree
8962 : 2620961 : make_anon_name ()
8963 : : {
8964 : 2620961 : const char *fmt =
8965 : : #if !defined (NO_DOT_IN_LABEL)
8966 : : "."
8967 : : #elif !defined (NO_DOLLAR_IN_LABEL)
8968 : : "$"
8969 : : #else
8970 : : "_"
8971 : : #endif
8972 : : "_anon_%d";
8973 : :
8974 : 2620961 : char buf[24];
8975 : 2620961 : int len = snprintf (buf, sizeof (buf), fmt, anon_cnt++);
8976 : 2620961 : gcc_checking_assert (len < int (sizeof (buf)));
8977 : :
8978 : 2620961 : tree id = get_identifier_with_length (buf, len);
8979 : 2620961 : IDENTIFIER_ANON_P (id) = true;
8980 : :
8981 : 2620961 : return id;
8982 : : }
8983 : :
8984 : : /* Generate a name for a special-purpose function.
8985 : : The generated name may need to be unique across the whole link.
8986 : : Changes to this function may also require corresponding changes to
8987 : : xstrdup_mask_random.
8988 : : TYPE is some string to identify the purpose of this function to the
8989 : : linker or collect2; it must start with an uppercase letter,
8990 : : one of:
8991 : : I - for constructors
8992 : : D - for destructors
8993 : : N - for C++ anonymous namespaces
8994 : : F - for DWARF unwind frame information. */
8995 : :
8996 : : tree
8997 : 5183 : get_file_function_name (const char *type)
8998 : : {
8999 : 5183 : char *buf;
9000 : 5183 : const char *p;
9001 : 5183 : char *q;
9002 : :
9003 : : /* If we already have a name we know to be unique, just use that. */
9004 : 5183 : if (first_global_object_name)
9005 : 4893 : p = q = ASTRDUP (first_global_object_name);
9006 : : /* If the target is handling the constructors/destructors, they
9007 : : will be local to this file and the name is only necessary for
9008 : : debugging purposes.
9009 : : We also assign sub_I and sub_D sufixes to constructors called from
9010 : : the global static constructors. These are always local.
9011 : : OpenMP "declare target" offloaded constructors/destructors use "off_I" and
9012 : : "off_D" for the same purpose. */
9013 : 290 : else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
9014 : 580 : || ((startswith (type, "sub_") || startswith (type, "off_"))
9015 : 290 : && (type[4] == 'I' || type[4] == 'D')))
9016 : : {
9017 : 290 : const char *file = main_input_filename;
9018 : 290 : if (! file)
9019 : 0 : file = LOCATION_FILE (input_location);
9020 : : /* Just use the file's basename, because the full pathname
9021 : : might be quite long. */
9022 : 290 : p = q = ASTRDUP (lbasename (file));
9023 : : }
9024 : : else
9025 : : {
9026 : : /* Otherwise, the name must be unique across the entire link.
9027 : : We don't have anything that we know to be unique to this translation
9028 : : unit, so use what we do have and throw in some randomness. */
9029 : 0 : unsigned len;
9030 : 0 : const char *name = weak_global_object_name;
9031 : 0 : const char *file = main_input_filename;
9032 : :
9033 : 0 : if (! name)
9034 : 0 : name = "";
9035 : 0 : if (! file)
9036 : 0 : file = LOCATION_FILE (input_location);
9037 : :
9038 : 0 : len = strlen (file);
9039 : 0 : q = (char *) alloca (9 + 19 + len + 1);
9040 : 0 : memcpy (q, file, len + 1);
9041 : :
9042 : 0 : snprintf (q + len, 9 + 19 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX,
9043 : : crc32_string (0, name), get_random_seed (false));
9044 : :
9045 : 0 : p = q;
9046 : : }
9047 : :
9048 : 5183 : clean_symbol_name (q);
9049 : 5183 : buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
9050 : : + strlen (type));
9051 : :
9052 : : /* Set up the name of the file-level functions we may need.
9053 : : Use a global object (which is already required to be unique over
9054 : : the program) rather than the file name (which imposes extra
9055 : : constraints). */
9056 : 5183 : sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
9057 : :
9058 : 5183 : return get_identifier (buf);
9059 : : }
9060 : :
9061 : : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9062 : :
9063 : : /* Complain that the tree code of NODE does not match the expected 0
9064 : : terminated list of trailing codes. The trailing code list can be
9065 : : empty, for a more vague error message. FILE, LINE, and FUNCTION
9066 : : are of the caller. */
9067 : :
9068 : : void
9069 : 0 : tree_check_failed (const_tree node, const char *file,
9070 : : int line, const char *function, ...)
9071 : : {
9072 : 0 : va_list args;
9073 : 0 : const char *buffer;
9074 : 0 : unsigned length = 0;
9075 : 0 : enum tree_code code;
9076 : :
9077 : 0 : va_start (args, function);
9078 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9079 : 0 : length += 4 + strlen (get_tree_code_name (code));
9080 : 0 : va_end (args);
9081 : 0 : if (length)
9082 : : {
9083 : 0 : char *tmp;
9084 : 0 : va_start (args, function);
9085 : 0 : length += strlen ("expected ");
9086 : 0 : buffer = tmp = (char *) alloca (length);
9087 : 0 : length = 0;
9088 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9089 : : {
9090 : 0 : const char *prefix = length ? " or " : "expected ";
9091 : :
9092 : 0 : strcpy (tmp + length, prefix);
9093 : 0 : length += strlen (prefix);
9094 : 0 : strcpy (tmp + length, get_tree_code_name (code));
9095 : 0 : length += strlen (get_tree_code_name (code));
9096 : : }
9097 : 0 : va_end (args);
9098 : : }
9099 : : else
9100 : : buffer = "unexpected node";
9101 : :
9102 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9103 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9104 : : function, trim_filename (file), line);
9105 : : }
9106 : :
9107 : : /* Complain that the tree code of NODE does match the expected 0
9108 : : terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9109 : : the caller. */
9110 : :
9111 : : void
9112 : 0 : tree_not_check_failed (const_tree node, const char *file,
9113 : : int line, const char *function, ...)
9114 : : {
9115 : 0 : va_list args;
9116 : 0 : char *buffer;
9117 : 0 : unsigned length = 0;
9118 : 0 : enum tree_code code;
9119 : :
9120 : 0 : va_start (args, function);
9121 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9122 : 0 : length += 4 + strlen (get_tree_code_name (code));
9123 : 0 : va_end (args);
9124 : 0 : va_start (args, function);
9125 : 0 : buffer = (char *) alloca (length);
9126 : 0 : length = 0;
9127 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9128 : : {
9129 : 0 : if (length)
9130 : : {
9131 : 0 : strcpy (buffer + length, " or ");
9132 : 0 : length += 4;
9133 : : }
9134 : 0 : strcpy (buffer + length, get_tree_code_name (code));
9135 : 0 : length += strlen (get_tree_code_name (code));
9136 : : }
9137 : 0 : va_end (args);
9138 : :
9139 : 0 : internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9140 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9141 : : function, trim_filename (file), line);
9142 : : }
9143 : :
9144 : : /* Similar to tree_check_failed, except that we check for a class of tree
9145 : : code, given in CL. */
9146 : :
9147 : : void
9148 : 0 : tree_class_check_failed (const_tree node, const enum tree_code_class cl,
9149 : : const char *file, int line, const char *function)
9150 : : {
9151 : 0 : internal_error
9152 : 0 : ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9153 : 0 : TREE_CODE_CLASS_STRING (cl),
9154 : 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9155 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9156 : : }
9157 : :
9158 : : /* Similar to tree_check_failed, except that instead of specifying a
9159 : : dozen codes, use the knowledge that they're all sequential. */
9160 : :
9161 : : void
9162 : 0 : tree_range_check_failed (const_tree node, const char *file, int line,
9163 : : const char *function, enum tree_code c1,
9164 : : enum tree_code c2)
9165 : : {
9166 : 0 : char *buffer;
9167 : 0 : unsigned length = 0;
9168 : 0 : unsigned int c;
9169 : :
9170 : 0 : for (c = c1; c <= c2; ++c)
9171 : 0 : length += 4 + strlen (get_tree_code_name ((enum tree_code) c));
9172 : :
9173 : 0 : length += strlen ("expected ");
9174 : 0 : buffer = (char *) alloca (length);
9175 : 0 : length = 0;
9176 : :
9177 : 0 : for (c = c1; c <= c2; ++c)
9178 : : {
9179 : 0 : const char *prefix = length ? " or " : "expected ";
9180 : :
9181 : 0 : strcpy (buffer + length, prefix);
9182 : 0 : length += strlen (prefix);
9183 : 0 : strcpy (buffer + length, get_tree_code_name ((enum tree_code) c));
9184 : 0 : length += strlen (get_tree_code_name ((enum tree_code) c));
9185 : : }
9186 : :
9187 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9188 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9189 : : function, trim_filename (file), line);
9190 : : }
9191 : :
9192 : :
9193 : : /* Similar to tree_check_failed, except that we check that a tree does
9194 : : not have the specified code, given in CL. */
9195 : :
9196 : : void
9197 : 0 : tree_not_class_check_failed (const_tree node, const enum tree_code_class cl,
9198 : : const char *file, int line, const char *function)
9199 : : {
9200 : 0 : internal_error
9201 : 0 : ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9202 : 0 : TREE_CODE_CLASS_STRING (cl),
9203 : 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9204 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9205 : : }
9206 : :
9207 : :
9208 : : /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9209 : :
9210 : : void
9211 : 0 : omp_clause_check_failed (const_tree node, const char *file, int line,
9212 : : const char *function, enum omp_clause_code code)
9213 : : {
9214 : 0 : internal_error ("tree check: expected %<omp_clause %s%>, have %qs "
9215 : : "in %s, at %s:%d",
9216 : 0 : omp_clause_code_name[code],
9217 : 0 : get_tree_code_name (TREE_CODE (node)),
9218 : : function, trim_filename (file), line);
9219 : : }
9220 : :
9221 : :
9222 : : /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9223 : :
9224 : : void
9225 : 0 : omp_clause_range_check_failed (const_tree node, const char *file, int line,
9226 : : const char *function, enum omp_clause_code c1,
9227 : : enum omp_clause_code c2)
9228 : : {
9229 : 0 : char *buffer;
9230 : 0 : unsigned length = 0;
9231 : 0 : unsigned int c;
9232 : :
9233 : 0 : for (c = c1; c <= c2; ++c)
9234 : 0 : length += 4 + strlen (omp_clause_code_name[c]);
9235 : :
9236 : 0 : length += strlen ("expected ");
9237 : 0 : buffer = (char *) alloca (length);
9238 : 0 : length = 0;
9239 : :
9240 : 0 : for (c = c1; c <= c2; ++c)
9241 : : {
9242 : 0 : const char *prefix = length ? " or " : "expected ";
9243 : :
9244 : 0 : strcpy (buffer + length, prefix);
9245 : 0 : length += strlen (prefix);
9246 : 0 : strcpy (buffer + length, omp_clause_code_name[c]);
9247 : 0 : length += strlen (omp_clause_code_name[c]);
9248 : : }
9249 : :
9250 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9251 : 0 : buffer, omp_clause_code_name[TREE_CODE (node)],
9252 : : function, trim_filename (file), line);
9253 : : }
9254 : :
9255 : :
9256 : : #undef DEFTREESTRUCT
9257 : : #define DEFTREESTRUCT(VAL, NAME) NAME,
9258 : :
9259 : : static const char *ts_enum_names[] = {
9260 : : #include "treestruct.def"
9261 : : };
9262 : : #undef DEFTREESTRUCT
9263 : :
9264 : : #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9265 : :
9266 : : /* Similar to tree_class_check_failed, except that we check for
9267 : : whether CODE contains the tree structure identified by EN. */
9268 : :
9269 : : void
9270 : 0 : tree_contains_struct_check_failed (const_tree node,
9271 : : const enum tree_node_structure_enum en,
9272 : : const char *file, int line,
9273 : : const char *function)
9274 : : {
9275 : 0 : internal_error
9276 : 0 : ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9277 : 0 : TS_ENUM_NAME (en),
9278 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9279 : : }
9280 : :
9281 : :
9282 : : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9283 : : (dynamically sized) vector. */
9284 : :
9285 : : void
9286 : 0 : tree_int_cst_elt_check_failed (int idx, int len, const char *file, int line,
9287 : : const char *function)
9288 : : {
9289 : 0 : internal_error
9290 : 0 : ("tree check: accessed elt %d of %<tree_int_cst%> with %d elts in %s, "
9291 : : "at %s:%d",
9292 : : idx + 1, len, function, trim_filename (file), line);
9293 : : }
9294 : :
9295 : : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9296 : : (dynamically sized) vector. */
9297 : :
9298 : : void
9299 : 0 : tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
9300 : : const char *function)
9301 : : {
9302 : 0 : internal_error
9303 : 0 : ("tree check: accessed elt %d of %<tree_vec%> with %d elts in %s, 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 the operand
9308 : : vector of an expression node EXP. */
9309 : :
9310 : : void
9311 : 0 : tree_operand_check_failed (int idx, const_tree exp, const char *file,
9312 : : int line, const char *function)
9313 : : {
9314 : 0 : enum tree_code code = TREE_CODE (exp);
9315 : 0 : internal_error
9316 : 0 : ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9317 : : idx + 1, get_tree_code_name (code), TREE_OPERAND_LENGTH (exp),
9318 : : function, trim_filename (file), line);
9319 : : }
9320 : :
9321 : : /* Similar to above, except that the check is for the number of
9322 : : operands of an OMP_CLAUSE node. */
9323 : :
9324 : : void
9325 : 0 : omp_clause_operand_check_failed (int idx, const_tree t, const char *file,
9326 : : int line, const char *function)
9327 : : {
9328 : 0 : internal_error
9329 : 0 : ("tree check: accessed operand %d of %<omp_clause %s%> with %d operands "
9330 : 0 : "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
9331 : 0 : omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
9332 : : trim_filename (file), line);
9333 : : }
9334 : : #endif /* ENABLE_TREE_CHECKING */
9335 : :
9336 : : /* Create a new vector type node holding NUNITS units of type INNERTYPE,
9337 : : and mapped to the machine mode MODE. Initialize its fields and build
9338 : : the information necessary for debugging output. */
9339 : :
9340 : : static tree
9341 : 70321170 : make_vector_type (tree innertype, poly_int64 nunits, machine_mode mode)
9342 : : {
9343 : 70321170 : tree t;
9344 : 70321170 : tree mv_innertype = TYPE_MAIN_VARIANT (innertype);
9345 : :
9346 : 70321170 : t = make_node (VECTOR_TYPE);
9347 : 70321170 : TREE_TYPE (t) = mv_innertype;
9348 : 70321170 : SET_TYPE_VECTOR_SUBPARTS (t, nunits);
9349 : 70321170 : SET_TYPE_MODE (t, mode);
9350 : :
9351 : 70321170 : if (TYPE_STRUCTURAL_EQUALITY_P (mv_innertype) || in_lto_p)
9352 : 1244772 : SET_TYPE_STRUCTURAL_EQUALITY (t);
9353 : 69076398 : else if ((TYPE_CANONICAL (mv_innertype) != innertype
9354 : 65578416 : || mode != VOIDmode)
9355 : 99613077 : && !VECTOR_BOOLEAN_TYPE_P (t))
9356 : 32175095 : TYPE_CANONICAL (t)
9357 : 64350190 : = make_vector_type (TYPE_CANONICAL (mv_innertype), nunits, VOIDmode);
9358 : :
9359 : 70321170 : layout_type (t);
9360 : :
9361 : 70321170 : hashval_t hash = type_hash_canon_hash (t);
9362 : 70321170 : t = type_hash_canon (hash, t);
9363 : :
9364 : : /* We have built a main variant, based on the main variant of the
9365 : : inner type. Use it to build the variant we return. */
9366 : 140637219 : if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
9367 : 71160843 : && TREE_TYPE (t) != innertype)
9368 : 843603 : return build_type_attribute_qual_variant (t,
9369 : 843603 : TYPE_ATTRIBUTES (innertype),
9370 : 1687206 : TYPE_QUALS (innertype));
9371 : :
9372 : : return t;
9373 : : }
9374 : :
9375 : : static tree
9376 : 3979893 : make_or_reuse_type (unsigned size, int unsignedp)
9377 : : {
9378 : 3979893 : int i;
9379 : :
9380 : 3979893 : if (size == INT_TYPE_SIZE)
9381 : 854352 : return unsignedp ? unsigned_type_node : integer_type_node;
9382 : 3125541 : if (size == CHAR_TYPE_SIZE)
9383 : 569568 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
9384 : 2555973 : if (size == SHORT_TYPE_SIZE)
9385 : 854352 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
9386 : 1737612 : if (size == LONG_TYPE_SIZE)
9387 : 832815 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
9388 : 868806 : if (size == LONG_LONG_TYPE_SIZE)
9389 : 21537 : return (unsignedp ? long_long_unsigned_type_node
9390 : 21537 : : long_long_integer_type_node);
9391 : :
9392 : 861435 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9393 : 847269 : if (size == int_n_data[i].bitsize
9394 : 847269 : && int_n_enabled_p[i])
9395 : 833103 : return (unsignedp ? int_n_trees[i].unsigned_type
9396 : 833103 : : int_n_trees[i].signed_type);
9397 : :
9398 : 14166 : if (unsignedp)
9399 : 7083 : return make_unsigned_type (size);
9400 : : else
9401 : 7083 : return make_signed_type (size);
9402 : : }
9403 : :
9404 : : /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9405 : :
9406 : : static tree
9407 : 5695680 : make_or_reuse_fract_type (unsigned size, int unsignedp, int satp)
9408 : : {
9409 : 5695680 : if (satp)
9410 : : {
9411 : 2847840 : if (size == SHORT_FRACT_TYPE_SIZE)
9412 : 569568 : return unsignedp ? sat_unsigned_short_fract_type_node
9413 : 569568 : : sat_short_fract_type_node;
9414 : 2278272 : if (size == FRACT_TYPE_SIZE)
9415 : 569568 : return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node;
9416 : 1708704 : if (size == LONG_FRACT_TYPE_SIZE)
9417 : 569568 : return unsignedp ? sat_unsigned_long_fract_type_node
9418 : 569568 : : sat_long_fract_type_node;
9419 : 1139136 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9420 : 569568 : return unsignedp ? sat_unsigned_long_long_fract_type_node
9421 : 569568 : : sat_long_long_fract_type_node;
9422 : : }
9423 : : else
9424 : : {
9425 : 2847840 : if (size == SHORT_FRACT_TYPE_SIZE)
9426 : 569568 : return unsignedp ? unsigned_short_fract_type_node
9427 : 569568 : : short_fract_type_node;
9428 : 2278272 : if (size == FRACT_TYPE_SIZE)
9429 : 569568 : return unsignedp ? unsigned_fract_type_node : fract_type_node;
9430 : 1708704 : if (size == LONG_FRACT_TYPE_SIZE)
9431 : 569568 : return unsignedp ? unsigned_long_fract_type_node
9432 : 569568 : : long_fract_type_node;
9433 : 1139136 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9434 : 569568 : return unsignedp ? unsigned_long_long_fract_type_node
9435 : 569568 : : long_long_fract_type_node;
9436 : : }
9437 : :
9438 : 1139136 : return make_fract_type (size, unsignedp, satp);
9439 : : }
9440 : :
9441 : : /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9442 : :
9443 : : static tree
9444 : 4556544 : make_or_reuse_accum_type (unsigned size, int unsignedp, int satp)
9445 : : {
9446 : 4556544 : if (satp)
9447 : : {
9448 : 2278272 : if (size == SHORT_ACCUM_TYPE_SIZE)
9449 : 569568 : return unsignedp ? sat_unsigned_short_accum_type_node
9450 : 569568 : : sat_short_accum_type_node;
9451 : 1708704 : if (size == ACCUM_TYPE_SIZE)
9452 : 569568 : return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node;
9453 : 1139136 : if (size == LONG_ACCUM_TYPE_SIZE)
9454 : 569568 : return unsignedp ? sat_unsigned_long_accum_type_node
9455 : 569568 : : sat_long_accum_type_node;
9456 : 569568 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9457 : 569568 : return unsignedp ? sat_unsigned_long_long_accum_type_node
9458 : 569568 : : sat_long_long_accum_type_node;
9459 : : }
9460 : : else
9461 : : {
9462 : 2278272 : if (size == SHORT_ACCUM_TYPE_SIZE)
9463 : 569568 : return unsignedp ? unsigned_short_accum_type_node
9464 : 569568 : : short_accum_type_node;
9465 : 1708704 : if (size == ACCUM_TYPE_SIZE)
9466 : 569568 : return unsignedp ? unsigned_accum_type_node : accum_type_node;
9467 : 1139136 : if (size == LONG_ACCUM_TYPE_SIZE)
9468 : 569568 : return unsignedp ? unsigned_long_accum_type_node
9469 : 569568 : : long_accum_type_node;
9470 : 569568 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9471 : 569568 : return unsignedp ? unsigned_long_long_accum_type_node
9472 : 569568 : : long_long_accum_type_node;
9473 : : }
9474 : :
9475 : 0 : return make_accum_type (size, unsignedp, satp);
9476 : : }
9477 : :
9478 : :
9479 : : /* Create an atomic variant node for TYPE. This routine is called
9480 : : during initialization of data types to create the 5 basic atomic
9481 : : types. The generic build_variant_type function requires these to
9482 : : already be set up in order to function properly, so cannot be
9483 : : called from there. If ALIGN is non-zero, then ensure alignment is
9484 : : overridden to this value. */
9485 : :
9486 : : static tree
9487 : 1423920 : build_atomic_base (tree type, unsigned int align)
9488 : : {
9489 : 1423920 : tree t;
9490 : :
9491 : : /* Make sure its not already registered. */
9492 : 1423920 : if ((t = get_qualified_type (type, TYPE_QUAL_ATOMIC)))
9493 : : return t;
9494 : :
9495 : 1423920 : t = build_variant_type_copy (type);
9496 : 1423920 : set_type_quals (t, TYPE_QUAL_ATOMIC);
9497 : :
9498 : 1423920 : if (align)
9499 : 0 : SET_TYPE_ALIGN (t, align);
9500 : :
9501 : : return t;
9502 : : }
9503 : :
9504 : : /* Information about the _FloatN and _FloatNx types. This must be in
9505 : : the same order as the corresponding TI_* enum values. */
9506 : : const floatn_type_info floatn_nx_types[NUM_FLOATN_NX_TYPES] =
9507 : : {
9508 : : { 16, false },
9509 : : { 32, false },
9510 : : { 64, false },
9511 : : { 128, false },
9512 : : { 32, true },
9513 : : { 64, true },
9514 : : { 128, true },
9515 : : };
9516 : :
9517 : :
9518 : : /* Create nodes for all integer types (and error_mark_node) using the sizes
9519 : : of C datatypes. SIGNED_CHAR specifies whether char is signed. */
9520 : :
9521 : : void
9522 : 284784 : build_common_tree_nodes (bool signed_char)
9523 : : {
9524 : 284784 : int i;
9525 : :
9526 : 284784 : error_mark_node = make_node (ERROR_MARK);
9527 : 284784 : TREE_TYPE (error_mark_node) = error_mark_node;
9528 : :
9529 : 284784 : initialize_sizetypes ();
9530 : :
9531 : : /* Define both `signed char' and `unsigned char'. */
9532 : 284784 : signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
9533 : 284784 : TYPE_STRING_FLAG (signed_char_type_node) = 1;
9534 : 284784 : unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
9535 : 284784 : TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
9536 : :
9537 : : /* Define `char', which is like either `signed char' or `unsigned char'
9538 : : but not the same as either. */
9539 : 284784 : char_type_node
9540 : 284784 : = (signed_char
9541 : 284784 : ? make_signed_type (CHAR_TYPE_SIZE)
9542 : 55665 : : make_unsigned_type (CHAR_TYPE_SIZE));
9543 : 284784 : TYPE_STRING_FLAG (char_type_node) = 1;
9544 : :
9545 : 284784 : short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
9546 : 284784 : short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
9547 : 284784 : integer_type_node = make_signed_type (INT_TYPE_SIZE);
9548 : 284784 : unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
9549 : 291963 : long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
9550 : 291963 : long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
9551 : 284784 : long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
9552 : 284784 : long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
9553 : :
9554 : 854352 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9555 : : {
9556 : 284784 : int_n_trees[i].signed_type = make_signed_type (int_n_data[i].bitsize);
9557 : 284784 : int_n_trees[i].unsigned_type = make_unsigned_type (int_n_data[i].bitsize);
9558 : :
9559 : 284784 : if (int_n_enabled_p[i])
9560 : : {
9561 : 277701 : integer_types[itk_intN_0 + i * 2] = int_n_trees[i].signed_type;
9562 : 277701 : integer_types[itk_unsigned_intN_0 + i * 2] = int_n_trees[i].unsigned_type;
9563 : : }
9564 : : }
9565 : :
9566 : : /* Define a boolean type. This type only represents boolean values but
9567 : : may be larger than char depending on the value of BOOL_TYPE_SIZE. */
9568 : 284784 : boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
9569 : 284784 : TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
9570 : 284784 : TYPE_PRECISION (boolean_type_node) = 1;
9571 : 284784 : TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
9572 : :
9573 : : /* Define what type to use for size_t. */
9574 : 291963 : if (strcmp (SIZE_TYPE, "unsigned int") == 0)
9575 : 7179 : size_type_node = unsigned_type_node;
9576 : 277605 : else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
9577 : 277605 : size_type_node = long_unsigned_type_node;
9578 : 0 : else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
9579 : 0 : size_type_node = long_long_unsigned_type_node;
9580 : 0 : else if (strcmp (SIZE_TYPE, "short unsigned int") == 0)
9581 : 0 : size_type_node = short_unsigned_type_node;
9582 : : else
9583 : : {
9584 : 0 : int i;
9585 : :
9586 : 0 : size_type_node = NULL_TREE;
9587 : 0 : for (i = 0; i < NUM_INT_N_ENTS; i++)
9588 : 0 : if (int_n_enabled_p[i])
9589 : : {
9590 : 0 : char name[50], altname[50];
9591 : 0 : sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
9592 : 0 : sprintf (altname, "__int%d__ unsigned", int_n_data[i].bitsize);
9593 : :
9594 : 0 : if (strcmp (name, SIZE_TYPE) == 0
9595 : 0 : || strcmp (altname, SIZE_TYPE) == 0)
9596 : : {
9597 : 0 : size_type_node = int_n_trees[i].unsigned_type;
9598 : : }
9599 : : }
9600 : 0 : if (size_type_node == NULL_TREE)
9601 : 0 : gcc_unreachable ();
9602 : : }
9603 : :
9604 : : /* Define what type to use for ptrdiff_t. */
9605 : 291963 : if (strcmp (PTRDIFF_TYPE, "int") == 0)
9606 : 7179 : ptrdiff_type_node = integer_type_node;
9607 : 277605 : else if (strcmp (PTRDIFF_TYPE, "long int") == 0)
9608 : 277605 : ptrdiff_type_node = long_integer_type_node;
9609 : 0 : else if (strcmp (PTRDIFF_TYPE, "long long int") == 0)
9610 : 0 : ptrdiff_type_node = long_long_integer_type_node;
9611 : 0 : else if (strcmp (PTRDIFF_TYPE, "short int") == 0)
9612 : 0 : ptrdiff_type_node = short_integer_type_node;
9613 : : else
9614 : : {
9615 : 0 : ptrdiff_type_node = NULL_TREE;
9616 : 0 : for (int i = 0; i < NUM_INT_N_ENTS; i++)
9617 : 0 : if (int_n_enabled_p[i])
9618 : : {
9619 : 0 : char name[50], altname[50];
9620 : 0 : sprintf (name, "__int%d", int_n_data[i].bitsize);
9621 : 0 : sprintf (altname, "__int%d__", int_n_data[i].bitsize);
9622 : :
9623 : 0 : if (strcmp (name, PTRDIFF_TYPE) == 0
9624 : 0 : || strcmp (altname, PTRDIFF_TYPE) == 0)
9625 : 0 : ptrdiff_type_node = int_n_trees[i].signed_type;
9626 : : }
9627 : 0 : if (ptrdiff_type_node == NULL_TREE)
9628 : 0 : gcc_unreachable ();
9629 : : }
9630 : :
9631 : : /* Fill in the rest of the sized types. Reuse existing type nodes
9632 : : when possible. */
9633 : 284784 : intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
9634 : 284784 : intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
9635 : 284784 : intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
9636 : 284784 : intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
9637 : 284784 : intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
9638 : :
9639 : 284784 : unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
9640 : 284784 : unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
9641 : 284784 : unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
9642 : 284784 : unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
9643 : 284784 : unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
9644 : :
9645 : : /* Don't call build_qualified type for atomics. That routine does
9646 : : special processing for atomics, and until they are initialized
9647 : : it's better not to make that call.
9648 : :
9649 : : Check to see if there is a target override for atomic types. */
9650 : :
9651 : 284784 : atomicQI_type_node = build_atomic_base (unsigned_intQI_type_node,
9652 : 284784 : targetm.atomic_align_for_mode (QImode));
9653 : 284784 : atomicHI_type_node = build_atomic_base (unsigned_intHI_type_node,
9654 : 284784 : targetm.atomic_align_for_mode (HImode));
9655 : 284784 : atomicSI_type_node = build_atomic_base (unsigned_intSI_type_node,
9656 : 284784 : targetm.atomic_align_for_mode (SImode));
9657 : 284784 : atomicDI_type_node = build_atomic_base (unsigned_intDI_type_node,
9658 : 284784 : targetm.atomic_align_for_mode (DImode));
9659 : 284784 : atomicTI_type_node = build_atomic_base (unsigned_intTI_type_node,
9660 : 284784 : targetm.atomic_align_for_mode (TImode));
9661 : :
9662 : 284784 : access_public_node = get_identifier ("public");
9663 : 284784 : access_protected_node = get_identifier ("protected");
9664 : 284784 : access_private_node = get_identifier ("private");
9665 : :
9666 : : /* Define these next since types below may used them. */
9667 : 284784 : integer_zero_node = build_int_cst (integer_type_node, 0);
9668 : 284784 : integer_one_node = build_int_cst (integer_type_node, 1);
9669 : 284784 : integer_minus_one_node = build_int_cst (integer_type_node, -1);
9670 : :
9671 : 284784 : size_zero_node = size_int (0);
9672 : 284784 : size_one_node = size_int (1);
9673 : 284784 : bitsize_zero_node = bitsize_int (0);
9674 : 284784 : bitsize_one_node = bitsize_int (1);
9675 : 284784 : bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
9676 : :
9677 : 284784 : boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
9678 : 284784 : boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
9679 : :
9680 : 284784 : void_type_node = make_node (VOID_TYPE);
9681 : 284784 : layout_type (void_type_node);
9682 : :
9683 : : /* We are not going to have real types in C with less than byte alignment,
9684 : : so we might as well not have any types that claim to have it. */
9685 : 284784 : SET_TYPE_ALIGN (void_type_node, BITS_PER_UNIT);
9686 : 284784 : TYPE_USER_ALIGN (void_type_node) = 0;
9687 : :
9688 : 284784 : void_node = make_node (VOID_CST);
9689 : 284784 : TREE_TYPE (void_node) = void_type_node;
9690 : :
9691 : 284784 : void_list_node = build_tree_list (NULL_TREE, void_type_node);
9692 : :
9693 : 284784 : null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
9694 : 284784 : layout_type (TREE_TYPE (null_pointer_node));
9695 : :
9696 : 284784 : ptr_type_node = build_pointer_type (void_type_node);
9697 : 284784 : const_ptr_type_node
9698 : 284784 : = build_pointer_type (build_type_variant (void_type_node, 1, 0));
9699 : 1993488 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
9700 : 1708704 : builtin_structptr_types[i].node = builtin_structptr_types[i].base;
9701 : :
9702 : 291963 : pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
9703 : :
9704 : 284784 : float_type_node = make_node (REAL_TYPE);
9705 : 284784 : machine_mode float_type_mode
9706 : 284784 : = targetm.c.mode_for_floating_type (TI_FLOAT_TYPE);
9707 : 284784 : SET_TYPE_MODE (float_type_node, float_type_mode);
9708 : 284784 : TYPE_PRECISION (float_type_node)
9709 : 284784 : = GET_MODE_PRECISION (float_type_mode).to_constant ();
9710 : 284784 : layout_type (float_type_node);
9711 : :
9712 : 284784 : double_type_node = make_node (REAL_TYPE);
9713 : 284784 : machine_mode double_type_mode
9714 : 284784 : = targetm.c.mode_for_floating_type (TI_DOUBLE_TYPE);
9715 : 284784 : SET_TYPE_MODE (double_type_node, double_type_mode);
9716 : 284784 : TYPE_PRECISION (double_type_node)
9717 : 284784 : = GET_MODE_PRECISION (double_type_mode).to_constant ();
9718 : 284784 : layout_type (double_type_node);
9719 : :
9720 : 284784 : long_double_type_node = make_node (REAL_TYPE);
9721 : 284784 : machine_mode long_double_type_mode
9722 : 284784 : = targetm.c.mode_for_floating_type (TI_LONG_DOUBLE_TYPE);
9723 : 284784 : SET_TYPE_MODE (long_double_type_node, long_double_type_mode);
9724 : 284784 : TYPE_PRECISION (long_double_type_node)
9725 : 284784 : = GET_MODE_PRECISION (long_double_type_mode).to_constant ();
9726 : 284784 : layout_type (long_double_type_node);
9727 : :
9728 : 2278272 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9729 : : {
9730 : 1993488 : int n = floatn_nx_types[i].n;
9731 : 1993488 : bool extended = floatn_nx_types[i].extended;
9732 : 1993488 : scalar_float_mode mode;
9733 : 1993488 : if (!targetm.floatn_mode (n, extended).exists (&mode))
9734 : 284784 : continue;
9735 : 1708704 : int precision = GET_MODE_PRECISION (mode);
9736 : 1708704 : FLOATN_NX_TYPE_NODE (i) = make_node (REAL_TYPE);
9737 : 1708704 : TYPE_PRECISION (FLOATN_NX_TYPE_NODE (i)) = precision;
9738 : 1708704 : layout_type (FLOATN_NX_TYPE_NODE (i));
9739 : 1708704 : SET_TYPE_MODE (FLOATN_NX_TYPE_NODE (i), mode);
9740 : : }
9741 : 284784 : float128t_type_node = float128_type_node;
9742 : : #ifdef HAVE_BFmode
9743 : 284784 : if (REAL_MODE_FORMAT (BFmode) == &arm_bfloat_half_format
9744 : 284784 : && targetm.scalar_mode_supported_p (BFmode)
9745 : 569568 : && targetm.libgcc_floating_mode_supported_p (BFmode))
9746 : : {
9747 : 284784 : bfloat16_type_node = make_node (REAL_TYPE);
9748 : 284784 : TYPE_PRECISION (bfloat16_type_node) = GET_MODE_PRECISION (BFmode);
9749 : 284784 : layout_type (bfloat16_type_node);
9750 : 284784 : SET_TYPE_MODE (bfloat16_type_node, BFmode);
9751 : : }
9752 : : #endif
9753 : :
9754 : 284784 : float_ptr_type_node = build_pointer_type (float_type_node);
9755 : 284784 : double_ptr_type_node = build_pointer_type (double_type_node);
9756 : 284784 : long_double_ptr_type_node = build_pointer_type (long_double_type_node);
9757 : 284784 : integer_ptr_type_node = build_pointer_type (integer_type_node);
9758 : :
9759 : : /* Fixed size integer types. */
9760 : 284784 : uint16_type_node = make_or_reuse_type (16, 1);
9761 : 284784 : uint32_type_node = make_or_reuse_type (32, 1);
9762 : 284784 : uint64_type_node = make_or_reuse_type (64, 1);
9763 : 284784 : if (targetm.scalar_mode_supported_p (TImode))
9764 : 277701 : uint128_type_node = make_or_reuse_type (128, 1);
9765 : :
9766 : : /* Decimal float types. */
9767 : 284784 : if (targetm.decimal_float_supported_p ())
9768 : : {
9769 : 284784 : dfloat32_type_node = make_node (REAL_TYPE);
9770 : 284784 : TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
9771 : 284784 : SET_TYPE_MODE (dfloat32_type_node, SDmode);
9772 : 284784 : layout_type (dfloat32_type_node);
9773 : :
9774 : 284784 : dfloat64_type_node = make_node (REAL_TYPE);
9775 : 284784 : TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
9776 : 284784 : SET_TYPE_MODE (dfloat64_type_node, DDmode);
9777 : 284784 : layout_type (dfloat64_type_node);
9778 : :
9779 : 284784 : dfloat128_type_node = make_node (REAL_TYPE);
9780 : 284784 : TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
9781 : 284784 : SET_TYPE_MODE (dfloat128_type_node, TDmode);
9782 : 284784 : layout_type (dfloat128_type_node);
9783 : :
9784 : 284784 : dfloat64x_type_node = make_node (REAL_TYPE);
9785 : 284784 : TYPE_PRECISION (dfloat64x_type_node) = DECIMAL128_TYPE_SIZE;
9786 : 284784 : SET_TYPE_MODE (dfloat64x_type_node, TDmode);
9787 : 284784 : layout_type (dfloat64x_type_node);
9788 : : }
9789 : :
9790 : 284784 : complex_integer_type_node = build_complex_type (integer_type_node, true);
9791 : 284784 : complex_float_type_node = build_complex_type (float_type_node, true);
9792 : 284784 : complex_double_type_node = build_complex_type (double_type_node, true);
9793 : 284784 : complex_long_double_type_node = build_complex_type (long_double_type_node,
9794 : : true);
9795 : :
9796 : 2278272 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9797 : : {
9798 : 1993488 : if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
9799 : 1708704 : COMPLEX_FLOATN_NX_TYPE_NODE (i)
9800 : 1708704 : = build_complex_type (FLOATN_NX_TYPE_NODE (i));
9801 : : }
9802 : :
9803 : : /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9804 : : #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9805 : : sat_ ## KIND ## _type_node = \
9806 : : make_sat_signed_ ## KIND ## _type (SIZE); \
9807 : : sat_unsigned_ ## KIND ## _type_node = \
9808 : : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9809 : : KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9810 : : unsigned_ ## KIND ## _type_node = \
9811 : : make_unsigned_ ## KIND ## _type (SIZE);
9812 : :
9813 : : #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9814 : : sat_ ## WIDTH ## KIND ## _type_node = \
9815 : : make_sat_signed_ ## KIND ## _type (SIZE); \
9816 : : sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9817 : : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9818 : : WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9819 : : unsigned_ ## WIDTH ## KIND ## _type_node = \
9820 : : make_unsigned_ ## KIND ## _type (SIZE);
9821 : :
9822 : : /* Make fixed-point type nodes based on four different widths. */
9823 : : #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9824 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9825 : : MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9826 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9827 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9828 : :
9829 : : /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9830 : : #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9831 : : NAME ## _type_node = \
9832 : : make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9833 : : u ## NAME ## _type_node = \
9834 : : make_or_reuse_unsigned_ ## KIND ## _type \
9835 : : (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9836 : : sat_ ## NAME ## _type_node = \
9837 : : make_or_reuse_sat_signed_ ## KIND ## _type \
9838 : : (GET_MODE_BITSIZE (MODE ## mode)); \
9839 : : sat_u ## NAME ## _type_node = \
9840 : : make_or_reuse_sat_unsigned_ ## KIND ## _type \
9841 : : (GET_MODE_BITSIZE (U ## MODE ## mode));
9842 : :
9843 : : /* Fixed-point type and mode nodes. */
9844 : 284784 : MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT)
9845 : 284784 : MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM)
9846 : 284784 : MAKE_FIXED_MODE_NODE (fract, qq, QQ)
9847 : 284784 : MAKE_FIXED_MODE_NODE (fract, hq, HQ)
9848 : 284784 : MAKE_FIXED_MODE_NODE (fract, sq, SQ)
9849 : 284784 : MAKE_FIXED_MODE_NODE (fract, dq, DQ)
9850 : 284784 : MAKE_FIXED_MODE_NODE (fract, tq, TQ)
9851 : 284784 : MAKE_FIXED_MODE_NODE (accum, ha, HA)
9852 : 284784 : MAKE_FIXED_MODE_NODE (accum, sa, SA)
9853 : 284784 : MAKE_FIXED_MODE_NODE (accum, da, DA)
9854 : 284784 : MAKE_FIXED_MODE_NODE (accum, ta, TA)
9855 : :
9856 : 284784 : {
9857 : 284784 : tree t = targetm.build_builtin_va_list ();
9858 : :
9859 : : /* Many back-ends define record types without setting TYPE_NAME.
9860 : : If we copied the record type here, we'd keep the original
9861 : : record type without a name. This breaks name mangling. So,
9862 : : don't copy record types and let c_common_nodes_and_builtins()
9863 : : declare the type to be __builtin_va_list. */
9864 : 284784 : if (TREE_CODE (t) != RECORD_TYPE)
9865 : 284784 : t = build_variant_type_copy (t);
9866 : :
9867 : 284784 : va_list_type_node = t;
9868 : : }
9869 : :
9870 : : /* SCEV analyzer global shared trees. */
9871 : 284784 : chrec_dont_know = make_node (SCEV_NOT_KNOWN);
9872 : 284784 : TREE_TYPE (chrec_dont_know) = void_type_node;
9873 : 284784 : chrec_known = make_node (SCEV_KNOWN);
9874 : 284784 : TREE_TYPE (chrec_known) = void_type_node;
9875 : 284784 : }
9876 : :
9877 : : /* Modify DECL for given flags.
9878 : : TM_PURE attribute is set only on types, so the function will modify
9879 : : DECL's type when ECF_TM_PURE is used. */
9880 : :
9881 : : void
9882 : 30505309 : set_call_expr_flags (tree decl, int flags)
9883 : : {
9884 : 30505309 : if (flags & ECF_NOTHROW)
9885 : 26293512 : TREE_NOTHROW (decl) = 1;
9886 : 30505309 : if (flags & ECF_CONST)
9887 : 12621823 : TREE_READONLY (decl) = 1;
9888 : 30505309 : if (flags & ECF_PURE)
9889 : 1487536 : DECL_PURE_P (decl) = 1;
9890 : 30505309 : if (flags & ECF_LOOPING_CONST_OR_PURE)
9891 : 0 : DECL_LOOPING_CONST_OR_PURE_P (decl) = 1;
9892 : 30505309 : if (flags & ECF_NOVOPS)
9893 : 0 : DECL_IS_NOVOPS (decl) = 1;
9894 : 30505309 : if (flags & ECF_NORETURN)
9895 : 1209547 : TREE_THIS_VOLATILE (decl) = 1;
9896 : 30505309 : if (flags & ECF_MALLOC)
9897 : 730759 : DECL_IS_MALLOC (decl) = 1;
9898 : 30505309 : if (flags & ECF_RETURNS_TWICE)
9899 : 0 : DECL_IS_RETURNS_TWICE (decl) = 1;
9900 : 30505309 : if (flags & ECF_LEAF)
9901 : 26165309 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("leaf"),
9902 : 26165309 : NULL, DECL_ATTRIBUTES (decl));
9903 : 30505309 : if (flags & ECF_COLD)
9904 : 636068 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("cold"),
9905 : 636068 : NULL, DECL_ATTRIBUTES (decl));
9906 : 30505309 : if (flags & ECF_RET1)
9907 : 0 : DECL_ATTRIBUTES (decl)
9908 : 0 : = tree_cons (get_identifier ("fn spec"),
9909 : : build_tree_list (NULL_TREE, build_string (2, "1 ")),
9910 : 0 : DECL_ATTRIBUTES (decl));
9911 : 30505309 : if ((flags & ECF_TM_PURE) && flag_tm)
9912 : 573 : apply_tm_attr (decl, get_identifier ("transaction_pure"));
9913 : 30505309 : if ((flags & ECF_XTHROW))
9914 : 407311 : DECL_ATTRIBUTES (decl)
9915 : 814622 : = tree_cons (get_identifier ("expected_throw"),
9916 : 407311 : NULL, DECL_ATTRIBUTES (decl));
9917 : : /* Looping const or pure is implied by noreturn.
9918 : : There is currently no way to declare looping const or looping pure alone. */
9919 : 30505309 : gcc_assert (!(flags & ECF_LOOPING_CONST_OR_PURE)
9920 : : || ((flags & ECF_NORETURN) && (flags & (ECF_CONST | ECF_PURE))));
9921 : 30505309 : }
9922 : :
9923 : :
9924 : : /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
9925 : :
9926 : : static void
9927 : 9429527 : local_define_builtin (const char *name, tree type, enum built_in_function code,
9928 : : const char *library_name, int ecf_flags)
9929 : : {
9930 : 9429527 : tree decl;
9931 : :
9932 : 9429527 : decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
9933 : : library_name, NULL_TREE);
9934 : 9429527 : set_call_expr_flags (decl, ecf_flags);
9935 : :
9936 : 9429527 : set_builtin_decl (code, decl, true);
9937 : 9429527 : }
9938 : :
9939 : : /* Call this function after instantiating all builtins that the language
9940 : : front end cares about. This will build the rest of the builtins
9941 : : and internal functions that are relied upon by the tree optimizers and
9942 : : the middle-end. */
9943 : :
9944 : : void
9945 : 284768 : build_common_builtin_nodes (void)
9946 : : {
9947 : 284768 : tree tmp, ftype;
9948 : 284768 : int ecf_flags;
9949 : :
9950 : 284768 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_PADDING))
9951 : : {
9952 : 56850 : ftype = build_function_type_list (void_type_node,
9953 : : ptr_type_node,
9954 : : ptr_type_node,
9955 : : NULL_TREE);
9956 : 56850 : local_define_builtin ("__builtin_clear_padding", ftype,
9957 : : BUILT_IN_CLEAR_PADDING,
9958 : : "__builtin_clear_padding",
9959 : : ECF_LEAF | ECF_NOTHROW);
9960 : : }
9961 : :
9962 : 284768 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE)
9963 : 232564 : || !builtin_decl_explicit_p (BUILT_IN_TRAP)
9964 : 232564 : || !builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP)
9965 : 512686 : || !builtin_decl_explicit_p (BUILT_IN_ABORT))
9966 : : {
9967 : 56850 : ftype = build_function_type (void_type_node, void_list_node);
9968 : 56850 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE))
9969 : 52204 : local_define_builtin ("__builtin_unreachable", ftype,
9970 : : BUILT_IN_UNREACHABLE,
9971 : : "__builtin_unreachable",
9972 : : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
9973 : : | ECF_CONST | ECF_COLD);
9974 : 56850 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP))
9975 : 56850 : local_define_builtin ("__builtin_unreachable trap", ftype,
9976 : : BUILT_IN_UNREACHABLE_TRAP,
9977 : : "__builtin_unreachable trap",
9978 : : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
9979 : : | ECF_CONST | ECF_COLD);
9980 : 56850 : if (!builtin_decl_explicit_p (BUILT_IN_ABORT))
9981 : 56850 : local_define_builtin ("__builtin_abort", ftype, BUILT_IN_ABORT,
9982 : : "abort",
9983 : : ECF_LEAF | ECF_NORETURN | ECF_CONST | ECF_COLD);
9984 : 56850 : if (!builtin_decl_explicit_p (BUILT_IN_TRAP))
9985 : 21629 : local_define_builtin ("__builtin_trap", ftype, BUILT_IN_TRAP,
9986 : : "__builtin_trap",
9987 : : ECF_NORETURN | ECF_NOTHROW | ECF_LEAF | ECF_COLD);
9988 : : }
9989 : :
9990 : 284768 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY)
9991 : 284768 : || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
9992 : : {
9993 : 56850 : ftype = build_function_type_list (ptr_type_node,
9994 : : ptr_type_node, const_ptr_type_node,
9995 : : size_type_node, NULL_TREE);
9996 : :
9997 : 56850 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY))
9998 : 56850 : local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
9999 : : "memcpy", ECF_NOTHROW | ECF_LEAF);
10000 : 56850 : if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10001 : 52204 : local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
10002 : : "memmove", ECF_NOTHROW | ECF_LEAF);
10003 : : }
10004 : :
10005 : 284768 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP))
10006 : : {
10007 : 52204 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10008 : : const_ptr_type_node, size_type_node,
10009 : : NULL_TREE);
10010 : 52204 : local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
10011 : : "memcmp", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10012 : : }
10013 : :
10014 : 284768 : if (!builtin_decl_explicit_p (BUILT_IN_MEMSET))
10015 : : {
10016 : 52204 : ftype = build_function_type_list (ptr_type_node,
10017 : : ptr_type_node, integer_type_node,
10018 : : size_type_node, NULL_TREE);
10019 : 52204 : local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
10020 : : "memset", ECF_NOTHROW | ECF_LEAF);
10021 : : }
10022 : :
10023 : : /* If we're checking the stack, `alloca' can throw. */
10024 : 284708 : const int alloca_flags
10025 : 284768 : = ECF_MALLOC | ECF_LEAF | (flag_stack_check ? 0 : ECF_NOTHROW);
10026 : :
10027 : 284768 : if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA))
10028 : : {
10029 : 56850 : ftype = build_function_type_list (ptr_type_node,
10030 : : size_type_node, NULL_TREE);
10031 : 56850 : local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
10032 : : "alloca", alloca_flags);
10033 : : }
10034 : :
10035 : 284768 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10036 : : size_type_node, NULL_TREE);
10037 : 284768 : local_define_builtin ("__builtin_alloca_with_align", ftype,
10038 : : BUILT_IN_ALLOCA_WITH_ALIGN,
10039 : : "__builtin_alloca_with_align",
10040 : : alloca_flags);
10041 : :
10042 : 284768 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10043 : : size_type_node, size_type_node, NULL_TREE);
10044 : 284768 : local_define_builtin ("__builtin_alloca_with_align_and_max", ftype,
10045 : : BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX,
10046 : : "__builtin_alloca_with_align_and_max",
10047 : : alloca_flags);
10048 : :
10049 : 284768 : ftype = build_function_type_list (void_type_node,
10050 : : ptr_type_node, ptr_type_node,
10051 : : ptr_type_node, NULL_TREE);
10052 : 284768 : local_define_builtin ("__builtin_init_trampoline", ftype,
10053 : : BUILT_IN_INIT_TRAMPOLINE,
10054 : : "__builtin_init_trampoline", ECF_NOTHROW | ECF_LEAF);
10055 : 284768 : local_define_builtin ("__builtin_init_heap_trampoline", ftype,
10056 : : BUILT_IN_INIT_HEAP_TRAMPOLINE,
10057 : : "__builtin_init_heap_trampoline",
10058 : : ECF_NOTHROW | ECF_LEAF);
10059 : 284768 : local_define_builtin ("__builtin_init_descriptor", ftype,
10060 : : BUILT_IN_INIT_DESCRIPTOR,
10061 : : "__builtin_init_descriptor", ECF_NOTHROW | ECF_LEAF);
10062 : :
10063 : 284768 : ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
10064 : 284768 : local_define_builtin ("__builtin_adjust_trampoline", ftype,
10065 : : BUILT_IN_ADJUST_TRAMPOLINE,
10066 : : "__builtin_adjust_trampoline",
10067 : : ECF_CONST | ECF_NOTHROW);
10068 : 284768 : local_define_builtin ("__builtin_adjust_descriptor", ftype,
10069 : : BUILT_IN_ADJUST_DESCRIPTOR,
10070 : : "__builtin_adjust_descriptor",
10071 : : ECF_CONST | ECF_NOTHROW);
10072 : :
10073 : 284768 : ftype = build_function_type_list (void_type_node,
10074 : : ptr_type_node, ptr_type_node, NULL_TREE);
10075 : 284768 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_CACHE))
10076 : 56850 : local_define_builtin ("__builtin___clear_cache", ftype,
10077 : : BUILT_IN_CLEAR_CACHE,
10078 : : "__clear_cache",
10079 : : ECF_NOTHROW);
10080 : :
10081 : 284768 : local_define_builtin ("__builtin_nonlocal_goto", ftype,
10082 : : BUILT_IN_NONLOCAL_GOTO,
10083 : : "__builtin_nonlocal_goto",
10084 : : ECF_NORETURN | ECF_NOTHROW);
10085 : :
10086 : 284768 : tree ptr_ptr_type_node = build_pointer_type (ptr_type_node);
10087 : :
10088 : 284768 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_CREATED))
10089 : : {
10090 : 56850 : ftype = build_function_type_list (void_type_node,
10091 : : ptr_type_node, // void *chain
10092 : : ptr_type_node, // void *func
10093 : : ptr_ptr_type_node, // void **dst
10094 : : NULL_TREE);
10095 : 56850 : local_define_builtin ("__builtin___gcc_nested_func_ptr_created", ftype,
10096 : : BUILT_IN_GCC_NESTED_PTR_CREATED,
10097 : : "__gcc_nested_func_ptr_created", ECF_NOTHROW);
10098 : : }
10099 : :
10100 : 284768 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_DELETED))
10101 : : {
10102 : 56850 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10103 : 56850 : local_define_builtin ("__builtin___gcc_nested_func_ptr_deleted", ftype,
10104 : : BUILT_IN_GCC_NESTED_PTR_DELETED,
10105 : : "__gcc_nested_func_ptr_deleted", ECF_NOTHROW);
10106 : : }
10107 : :
10108 : 284768 : ftype = build_function_type_list (void_type_node,
10109 : : ptr_type_node, ptr_type_node, NULL_TREE);
10110 : 284768 : local_define_builtin ("__builtin_setjmp_setup", ftype,
10111 : : BUILT_IN_SETJMP_SETUP,
10112 : : "__builtin_setjmp_setup", ECF_NOTHROW);
10113 : :
10114 : 284768 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10115 : 284768 : local_define_builtin ("__builtin_setjmp_receiver", ftype,
10116 : : BUILT_IN_SETJMP_RECEIVER,
10117 : : "__builtin_setjmp_receiver", ECF_NOTHROW | ECF_LEAF);
10118 : :
10119 : 284768 : ftype = build_function_type_list (ptr_type_node, NULL_TREE);
10120 : 284768 : local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
10121 : : "__builtin_stack_save", ECF_NOTHROW | ECF_LEAF);
10122 : :
10123 : 284768 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10124 : 284768 : local_define_builtin ("__builtin_stack_restore", ftype,
10125 : : BUILT_IN_STACK_RESTORE,
10126 : : "__builtin_stack_restore", ECF_NOTHROW | ECF_LEAF);
10127 : :
10128 : 284768 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10129 : : const_ptr_type_node, size_type_node,
10130 : : NULL_TREE);
10131 : 284768 : local_define_builtin ("__builtin_memcmp_eq", ftype, BUILT_IN_MEMCMP_EQ,
10132 : : "__builtin_memcmp_eq",
10133 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10134 : :
10135 : 284768 : local_define_builtin ("__builtin_strncmp_eq", ftype, BUILT_IN_STRNCMP_EQ,
10136 : : "__builtin_strncmp_eq",
10137 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10138 : :
10139 : 284768 : local_define_builtin ("__builtin_strcmp_eq", ftype, BUILT_IN_STRCMP_EQ,
10140 : : "__builtin_strcmp_eq",
10141 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10142 : :
10143 : : /* If there's a possibility that we might use the ARM EABI, build the
10144 : : alternate __cxa_end_cleanup node used to resume from C++. */
10145 : 284768 : if (targetm.arm_eabi_unwinder)
10146 : : {
10147 : 0 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10148 : 0 : local_define_builtin ("__builtin_cxa_end_cleanup", ftype,
10149 : : BUILT_IN_CXA_END_CLEANUP,
10150 : : "__cxa_end_cleanup",
10151 : : ECF_NORETURN | ECF_XTHROW | ECF_LEAF);
10152 : : }
10153 : :
10154 : 284768 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10155 : 569536 : local_define_builtin ("__builtin_unwind_resume", ftype,
10156 : : BUILT_IN_UNWIND_RESUME,
10157 : 284768 : ((targetm_common.except_unwind_info (&global_options)
10158 : : == UI_SJLJ)
10159 : : ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
10160 : : ECF_NORETURN | ECF_XTHROW);
10161 : :
10162 : 284768 : if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS) == NULL_TREE)
10163 : : {
10164 : 52204 : ftype = build_function_type_list (ptr_type_node, integer_type_node,
10165 : : NULL_TREE);
10166 : 52204 : local_define_builtin ("__builtin_return_address", ftype,
10167 : : BUILT_IN_RETURN_ADDRESS,
10168 : : "__builtin_return_address",
10169 : : ECF_NOTHROW);
10170 : : }
10171 : :
10172 : 284768 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER)
10173 : 284768 : || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10174 : : {
10175 : 56850 : ftype = build_function_type_list (void_type_node, ptr_type_node,
10176 : : ptr_type_node, NULL_TREE);
10177 : 56850 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER))
10178 : 56850 : local_define_builtin ("__cyg_profile_func_enter", ftype,
10179 : : BUILT_IN_PROFILE_FUNC_ENTER,
10180 : : "__cyg_profile_func_enter", 0);
10181 : 56850 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10182 : 56850 : local_define_builtin ("__cyg_profile_func_exit", ftype,
10183 : : BUILT_IN_PROFILE_FUNC_EXIT,
10184 : : "__cyg_profile_func_exit", 0);
10185 : : }
10186 : :
10187 : : /* The exception object and filter values from the runtime. The argument
10188 : : must be zero before exception lowering, i.e. from the front end. After
10189 : : exception lowering, it will be the region number for the exception
10190 : : landing pad. These functions are PURE instead of CONST to prevent
10191 : : them from being hoisted past the exception edge that will initialize
10192 : : its value in the landing pad. */
10193 : 284768 : ftype = build_function_type_list (ptr_type_node,
10194 : : integer_type_node, NULL_TREE);
10195 : 284768 : ecf_flags = ECF_PURE | ECF_NOTHROW | ECF_LEAF;
10196 : : /* Only use TM_PURE if we have TM language support. */
10197 : 284768 : if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1))
10198 : 511 : ecf_flags |= ECF_TM_PURE;
10199 : 284768 : local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER,
10200 : : "__builtin_eh_pointer", ecf_flags);
10201 : :
10202 : 284768 : tmp = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0);
10203 : 284768 : ftype = build_function_type_list (tmp, integer_type_node, NULL_TREE);
10204 : 284768 : local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER,
10205 : : "__builtin_eh_filter", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10206 : :
10207 : 284768 : ftype = build_function_type_list (void_type_node,
10208 : : integer_type_node, integer_type_node,
10209 : : NULL_TREE);
10210 : 284768 : local_define_builtin ("__builtin_eh_copy_values", ftype,
10211 : : BUILT_IN_EH_COPY_VALUES,
10212 : : "__builtin_eh_copy_values", ECF_NOTHROW);
10213 : :
10214 : : /* Complex multiplication and division. These are handled as builtins
10215 : : rather than optabs because emit_library_call_value doesn't support
10216 : : complex. Further, we can do slightly better with folding these
10217 : : beasties if the real and complex parts of the arguments are separate. */
10218 : 284768 : {
10219 : 284768 : int mode;
10220 : :
10221 : 1993376 : for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
10222 : : {
10223 : 1708608 : char mode_name_buf[4], *q;
10224 : 1708608 : const char *p;
10225 : 1708608 : enum built_in_function mcode, dcode;
10226 : 1708608 : tree type, inner_type;
10227 : 1708608 : const char *prefix = "__";
10228 : :
10229 : 1708608 : if (targetm.libfunc_gnu_prefix)
10230 : 0 : prefix = "__gnu_";
10231 : :
10232 : 1708608 : type = lang_hooks.types.type_for_mode ((machine_mode) mode, 0);
10233 : 1708608 : if (type == NULL)
10234 : 124715 : continue;
10235 : 1583893 : inner_type = TREE_TYPE (type);
10236 : :
10237 : 1583893 : ftype = build_function_type_list (type, inner_type, inner_type,
10238 : : inner_type, inner_type, NULL_TREE);
10239 : :
10240 : 1583893 : mcode = ((enum built_in_function)
10241 : 1583893 : (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10242 : 1583893 : dcode = ((enum built_in_function)
10243 : 1583893 : (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10244 : :
10245 : 4751679 : for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
10246 : 3167786 : *q = TOLOWER (*p);
10247 : 1583893 : *q = '\0';
10248 : :
10249 : : /* For -ftrapping-math these should throw from a former
10250 : : -fnon-call-exception stmt. */
10251 : 1583893 : built_in_names[mcode] = concat (prefix, "mul", mode_name_buf, "3",
10252 : : NULL);
10253 : 1583893 : local_define_builtin (built_in_names[mcode], ftype, mcode,
10254 : : built_in_names[mcode],
10255 : : ECF_CONST | ECF_LEAF);
10256 : :
10257 : 1583893 : built_in_names[dcode] = concat (prefix, "div", mode_name_buf, "3",
10258 : : NULL);
10259 : 1583893 : local_define_builtin (built_in_names[dcode], ftype, dcode,
10260 : : built_in_names[dcode],
10261 : : ECF_CONST | ECF_LEAF);
10262 : : }
10263 : : }
10264 : :
10265 : 284768 : init_internal_fns ();
10266 : 284768 : }
10267 : :
10268 : : /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10269 : : better way.
10270 : :
10271 : : If we requested a pointer to a vector, build up the pointers that
10272 : : we stripped off while looking for the inner type. Similarly for
10273 : : return values from functions.
10274 : :
10275 : : The argument TYPE is the top of the chain, and BOTTOM is the
10276 : : new type which we will point to. */
10277 : :
10278 : : tree
10279 : 0 : reconstruct_complex_type (tree type, tree bottom)
10280 : : {
10281 : 0 : tree inner, outer;
10282 : :
10283 : 0 : if (TREE_CODE (type) == POINTER_TYPE)
10284 : : {
10285 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10286 : 0 : outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
10287 : 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10288 : : }
10289 : : else if (TREE_CODE (type) == REFERENCE_TYPE)
10290 : : {
10291 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10292 : 0 : outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
10293 : 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10294 : : }
10295 : : else if (TREE_CODE (type) == ARRAY_TYPE)
10296 : : {
10297 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10298 : 0 : outer = build_array_type (inner, TYPE_DOMAIN (type));
10299 : : }
10300 : : else if (TREE_CODE (type) == FUNCTION_TYPE)
10301 : : {
10302 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10303 : 0 : outer = build_function_type (inner, TYPE_ARG_TYPES (type),
10304 : 0 : TYPE_NO_NAMED_ARGS_STDARG_P (type));
10305 : : }
10306 : : else if (TREE_CODE (type) == METHOD_TYPE)
10307 : : {
10308 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10309 : : /* The build_method_type_directly() routine prepends 'this' to argument list,
10310 : : so we must compensate by getting rid of it. */
10311 : 0 : outer
10312 : : = build_method_type_directly
10313 : 0 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
10314 : : inner,
10315 : 0 : TREE_CHAIN (TYPE_ARG_TYPES (type)));
10316 : : }
10317 : : else if (TREE_CODE (type) == OFFSET_TYPE)
10318 : : {
10319 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10320 : 0 : outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
10321 : : }
10322 : : else
10323 : : return bottom;
10324 : :
10325 : 0 : return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
10326 : 0 : TYPE_QUALS (type));
10327 : : }
10328 : :
10329 : : /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10330 : : the inner type. */
10331 : : tree
10332 : 33351088 : build_vector_type_for_mode (tree innertype, machine_mode mode)
10333 : : {
10334 : 33351088 : poly_int64 nunits;
10335 : 33351088 : unsigned int bitsize;
10336 : :
10337 : 33351088 : switch (GET_MODE_CLASS (mode))
10338 : : {
10339 : 33349833 : case MODE_VECTOR_BOOL:
10340 : 33349833 : case MODE_VECTOR_INT:
10341 : 33349833 : case MODE_VECTOR_FLOAT:
10342 : 33349833 : case MODE_VECTOR_FRACT:
10343 : 33349833 : case MODE_VECTOR_UFRACT:
10344 : 33349833 : case MODE_VECTOR_ACCUM:
10345 : 33349833 : case MODE_VECTOR_UACCUM:
10346 : 66699666 : nunits = GET_MODE_NUNITS (mode);
10347 : 33349833 : break;
10348 : :
10349 : 1255 : case MODE_INT:
10350 : : /* Check that there are no leftover bits. */
10351 : 1255 : bitsize = GET_MODE_BITSIZE (as_a <scalar_int_mode> (mode));
10352 : 1255 : gcc_assert (bitsize % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
10353 : 1255 : nunits = bitsize / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
10354 : 1255 : break;
10355 : :
10356 : 0 : default:
10357 : 0 : gcc_unreachable ();
10358 : : }
10359 : :
10360 : 33351088 : return make_vector_type (innertype, nunits, mode);
10361 : : }
10362 : :
10363 : : /* Similarly, but takes the inner type and number of units, which must be
10364 : : a power of two. */
10365 : :
10366 : : tree
10367 : 2770280 : build_vector_type (tree innertype, poly_int64 nunits)
10368 : : {
10369 : 2770280 : return make_vector_type (innertype, nunits, VOIDmode);
10370 : : }
10371 : :
10372 : : /* Build a truth vector with NUNITS units, giving it mode MASK_MODE. */
10373 : :
10374 : : tree
10375 : 1918918 : build_truth_vector_type_for_mode (poly_uint64 nunits, machine_mode mask_mode)
10376 : : {
10377 : 1918918 : gcc_assert (mask_mode != BLKmode);
10378 : :
10379 : 1918918 : unsigned HOST_WIDE_INT esize;
10380 : 1918918 : if (VECTOR_MODE_P (mask_mode))
10381 : : {
10382 : 1858848 : poly_uint64 vsize = GET_MODE_PRECISION (mask_mode);
10383 : 1858848 : esize = vector_element_size (vsize, nunits);
10384 : 1858848 : }
10385 : : else
10386 : : esize = 1;
10387 : :
10388 : 1918918 : tree bool_type = build_nonstandard_boolean_type (esize);
10389 : :
10390 : 1918918 : return make_vector_type (bool_type, nunits, mask_mode);
10391 : : }
10392 : :
10393 : : /* Build a vector type that holds one boolean result for each element of
10394 : : vector type VECTYPE. The public interface for this operation is
10395 : : truth_type_for. */
10396 : :
10397 : : static tree
10398 : 1913200 : build_truth_vector_type_for (tree vectype)
10399 : : {
10400 : 1913200 : machine_mode vector_mode = TYPE_MODE (vectype);
10401 : 1913200 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
10402 : :
10403 : 1913200 : machine_mode mask_mode;
10404 : 69030 : if (VECTOR_MODE_P (vector_mode)
10405 : 1981669 : && targetm.vectorize.get_mask_mode (vector_mode).exists (&mask_mode))
10406 : 1912639 : return build_truth_vector_type_for_mode (nunits, mask_mode);
10407 : :
10408 : 561 : poly_uint64 vsize = tree_to_poly_uint64 (TYPE_SIZE (vectype));
10409 : 561 : unsigned HOST_WIDE_INT esize = vector_element_size (vsize, nunits);
10410 : 561 : tree bool_type = build_nonstandard_boolean_type (esize);
10411 : :
10412 : 561 : return make_vector_type (bool_type, nunits, VOIDmode);
10413 : : }
10414 : :
10415 : : /* Like build_vector_type, but builds a variant type with TYPE_VECTOR_OPAQUE
10416 : : set. */
10417 : :
10418 : : tree
10419 : 105228 : build_opaque_vector_type (tree innertype, poly_int64 nunits)
10420 : : {
10421 : 105228 : tree t = make_vector_type (innertype, nunits, VOIDmode);
10422 : 105228 : tree cand;
10423 : : /* We always build the non-opaque variant before the opaque one,
10424 : : so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10425 : 105228 : cand = TYPE_NEXT_VARIANT (t);
10426 : 105228 : if (cand
10427 : 93936 : && TYPE_VECTOR_OPAQUE (cand)
10428 : 166326 : && check_qualified_type (cand, t, TYPE_QUALS (t)))
10429 : : return cand;
10430 : : /* Othewise build a variant type and make sure to queue it after
10431 : : the non-opaque type. */
10432 : 44131 : cand = build_distinct_type_copy (t);
10433 : 44131 : TYPE_VECTOR_OPAQUE (cand) = true;
10434 : 44131 : TYPE_CANONICAL (cand) = TYPE_CANONICAL (t);
10435 : 44131 : TYPE_NEXT_VARIANT (cand) = TYPE_NEXT_VARIANT (t);
10436 : 44131 : TYPE_NEXT_VARIANT (t) = cand;
10437 : 44131 : TYPE_MAIN_VARIANT (cand) = TYPE_MAIN_VARIANT (t);
10438 : : /* Type variants have no alias set defined. */
10439 : 44131 : TYPE_ALIAS_SET (cand) = -1;
10440 : 44131 : return cand;
10441 : : }
10442 : :
10443 : : /* Return the value of element I of VECTOR_CST T as a wide_int. */
10444 : :
10445 : : static poly_wide_int
10446 : 483161 : vector_cst_int_elt (const_tree t, unsigned int i)
10447 : : {
10448 : : /* First handle elements that are directly encoded. */
10449 : 483161 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10450 : 483161 : if (i < encoded_nelts)
10451 : 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, i));
10452 : :
10453 : : /* Identify the pattern that contains element I and work out the index of
10454 : : the last encoded element for that pattern. */
10455 : 483161 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10456 : 483161 : unsigned int pattern = i % npatterns;
10457 : 483161 : unsigned int count = i / npatterns;
10458 : 483161 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10459 : :
10460 : : /* If there are no steps, the final encoded value is the right one. */
10461 : 483161 : if (!VECTOR_CST_STEPPED_P (t))
10462 : 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, final_i));
10463 : :
10464 : : /* Otherwise work out the value from the last two encoded elements. */
10465 : 483161 : tree v1 = VECTOR_CST_ENCODED_ELT (t, final_i - npatterns);
10466 : 483161 : tree v2 = VECTOR_CST_ENCODED_ELT (t, final_i);
10467 : 483161 : poly_wide_int diff = wi::to_poly_wide (v2) - wi::to_poly_wide (v1);
10468 : 483161 : return wi::to_poly_wide (v2) + (count - 2) * diff;
10469 : 483161 : }
10470 : :
10471 : : /* Return the value of element I of VECTOR_CST T. */
10472 : :
10473 : : tree
10474 : 5802710 : vector_cst_elt (const_tree t, unsigned int i)
10475 : : {
10476 : : /* First handle elements that are directly encoded. */
10477 : 5802710 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10478 : 5802710 : if (i < encoded_nelts)
10479 : 4072636 : return VECTOR_CST_ENCODED_ELT (t, i);
10480 : :
10481 : : /* If there are no steps, the final encoded value is the right one. */
10482 : 1730074 : if (!VECTOR_CST_STEPPED_P (t))
10483 : : {
10484 : : /* Identify the pattern that contains element I and work out the index of
10485 : : the last encoded element for that pattern. */
10486 : 1246913 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10487 : 1246913 : unsigned int pattern = i % npatterns;
10488 : 1246913 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10489 : 1246913 : return VECTOR_CST_ENCODED_ELT (t, final_i);
10490 : : }
10491 : :
10492 : : /* Otherwise work out the value from the last two encoded elements. */
10493 : 483161 : return wide_int_to_tree (TREE_TYPE (TREE_TYPE (t)),
10494 : 966322 : vector_cst_int_elt (t, i));
10495 : : }
10496 : :
10497 : : /* Given an initializer INIT, return TRUE if INIT is zero or some
10498 : : aggregate of zeros. Otherwise return FALSE. If NONZERO is not
10499 : : null, set *NONZERO if and only if INIT is known not to be all
10500 : : zeros. The combination of return value of false and *NONZERO
10501 : : false implies that INIT may but need not be all zeros. Other
10502 : : combinations indicate definitive answers. */
10503 : :
10504 : : bool
10505 : 44187518 : initializer_zerop (const_tree init, bool *nonzero /* = NULL */)
10506 : : {
10507 : 44187518 : bool dummy;
10508 : 44187518 : if (!nonzero)
10509 : 41452571 : nonzero = &dummy;
10510 : :
10511 : : /* Conservatively clear NONZERO and set it only if INIT is definitely
10512 : : not all zero. */
10513 : 44187518 : *nonzero = false;
10514 : :
10515 : 44187518 : STRIP_NOPS (init);
10516 : :
10517 : 44187518 : unsigned HOST_WIDE_INT off = 0;
10518 : :
10519 : 44187518 : switch (TREE_CODE (init))
10520 : : {
10521 : 16328318 : case INTEGER_CST:
10522 : 16328318 : if (integer_zerop (init))
10523 : : return true;
10524 : :
10525 : 10296731 : *nonzero = true;
10526 : 10296731 : return false;
10527 : :
10528 : 528245 : case REAL_CST:
10529 : : /* ??? Note that this is not correct for C4X float formats. There,
10530 : : a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10531 : : negative exponent. */
10532 : 528245 : if (real_zerop (init)
10533 : 614622 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init)))
10534 : : return true;
10535 : :
10536 : 444771 : *nonzero = true;
10537 : 444771 : return false;
10538 : :
10539 : 0 : case FIXED_CST:
10540 : 0 : if (fixed_zerop (init))
10541 : : return true;
10542 : :
10543 : 0 : *nonzero = true;
10544 : 0 : return false;
10545 : :
10546 : 17702 : case COMPLEX_CST:
10547 : 17702 : if (integer_zerop (init)
10548 : 17702 : || (real_zerop (init)
10549 : 2988 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
10550 : 2938 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init)))))
10551 : 3160 : return true;
10552 : :
10553 : 14542 : *nonzero = true;
10554 : 14542 : return false;
10555 : :
10556 : 1093255 : case VECTOR_CST:
10557 : 1093255 : if (VECTOR_CST_NPATTERNS (init) == 1
10558 : 1001372 : && VECTOR_CST_DUPLICATE_P (init)
10559 : 1719954 : && initializer_zerop (VECTOR_CST_ENCODED_ELT (init, 0)))
10560 : : return true;
10561 : :
10562 : 765190 : *nonzero = true;
10563 : 765190 : return false;
10564 : :
10565 : : case RAW_DATA_CST:
10566 : 1563 : for (unsigned int i = 0; i < (unsigned int) RAW_DATA_LENGTH (init); ++i)
10567 : 1563 : if (RAW_DATA_POINTER (init)[i])
10568 : : {
10569 : 1516 : *nonzero = true;
10570 : 1516 : return false;
10571 : : }
10572 : : return true;
10573 : :
10574 : 5820251 : case CONSTRUCTOR:
10575 : 5820251 : {
10576 : 5820251 : if (TREE_CLOBBER_P (init))
10577 : : return false;
10578 : :
10579 : : unsigned HOST_WIDE_INT idx;
10580 : : tree elt;
10581 : :
10582 : 3587961 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
10583 : 2734947 : if (!initializer_zerop (elt, nonzero))
10584 : : return false;
10585 : :
10586 : : return true;
10587 : : }
10588 : :
10589 : 433951 : case MEM_REF:
10590 : 433951 : {
10591 : 433951 : tree arg = TREE_OPERAND (init, 0);
10592 : 433951 : if (TREE_CODE (arg) != ADDR_EXPR)
10593 : : return false;
10594 : 78732 : tree offset = TREE_OPERAND (init, 1);
10595 : 78732 : if (TREE_CODE (offset) != INTEGER_CST
10596 : 78732 : || !tree_fits_uhwi_p (offset))
10597 : : return false;
10598 : 78732 : off = tree_to_uhwi (offset);
10599 : 78732 : if (INT_MAX < off)
10600 : : return false;
10601 : 78728 : arg = TREE_OPERAND (arg, 0);
10602 : 78728 : if (TREE_CODE (arg) != STRING_CST)
10603 : : return false;
10604 : : init = arg;
10605 : : }
10606 : : /* Fall through. */
10607 : :
10608 : : case STRING_CST:
10609 : : {
10610 : : gcc_assert (off <= INT_MAX);
10611 : :
10612 : 159405 : int i = off;
10613 : 159405 : int n = TREE_STRING_LENGTH (init);
10614 : 159405 : if (n <= i)
10615 : : return false;
10616 : :
10617 : : /* We need to loop through all elements to handle cases like
10618 : : "\0" and "\0foobar". */
10619 : 171705 : for (i = 0; i < n; ++i)
10620 : 166034 : if (TREE_STRING_POINTER (init)[i] != '\0')
10621 : : {
10622 : 153701 : *nonzero = true;
10623 : 153701 : return false;
10624 : : }
10625 : :
10626 : : return true;
10627 : : }
10628 : :
10629 : : default:
10630 : : return false;
10631 : : }
10632 : : }
10633 : :
10634 : : /* Return true if EXPR is an initializer expression in which every element
10635 : : is a constant that is numerically equal to 0 or 1. The elements do not
10636 : : need to be equal to each other. */
10637 : :
10638 : : bool
10639 : 122495 : initializer_each_zero_or_onep (const_tree expr)
10640 : : {
10641 : 122495 : STRIP_ANY_LOCATION_WRAPPER (expr);
10642 : :
10643 : 122495 : switch (TREE_CODE (expr))
10644 : : {
10645 : 46614 : case INTEGER_CST:
10646 : 46614 : return integer_zerop (expr) || integer_onep (expr);
10647 : :
10648 : 19381 : case REAL_CST:
10649 : 19381 : return real_zerop (expr) || real_onep (expr);
10650 : :
10651 : 56500 : case VECTOR_CST:
10652 : 56500 : {
10653 : 56500 : unsigned HOST_WIDE_INT nelts = vector_cst_encoded_nelts (expr);
10654 : 56500 : if (VECTOR_CST_STEPPED_P (expr)
10655 : 56500 : && !TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)).is_constant (&nelts))
10656 : : return false;
10657 : :
10658 : 67220 : for (unsigned int i = 0; i < nelts; ++i)
10659 : : {
10660 : 65995 : tree elt = vector_cst_elt (expr, i);
10661 : 65995 : if (!initializer_each_zero_or_onep (elt))
10662 : : return false;
10663 : : }
10664 : :
10665 : : return true;
10666 : : }
10667 : :
10668 : : default:
10669 : : return false;
10670 : : }
10671 : : }
10672 : :
10673 : : /* Check if vector VEC consists of all the equal elements and
10674 : : that the number of elements corresponds to the type of VEC.
10675 : : The function returns first element of the vector
10676 : : or NULL_TREE if the vector is not uniform. */
10677 : : tree
10678 : 2556750 : uniform_vector_p (const_tree vec)
10679 : : {
10680 : 2556750 : tree first, t;
10681 : 2556750 : unsigned HOST_WIDE_INT i, nelts;
10682 : :
10683 : 2556750 : if (vec == NULL_TREE)
10684 : : return NULL_TREE;
10685 : :
10686 : 2556750 : gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec)));
10687 : :
10688 : 2556750 : if (TREE_CODE (vec) == VEC_DUPLICATE_EXPR)
10689 : 0 : return TREE_OPERAND (vec, 0);
10690 : :
10691 : 2556750 : else if (TREE_CODE (vec) == VECTOR_CST)
10692 : : {
10693 : 205966 : if (VECTOR_CST_NPATTERNS (vec) == 1 && VECTOR_CST_DUPLICATE_P (vec))
10694 : 164569 : return VECTOR_CST_ENCODED_ELT (vec, 0);
10695 : : return NULL_TREE;
10696 : : }
10697 : :
10698 : 2350784 : else if (TREE_CODE (vec) == CONSTRUCTOR
10699 : 2350784 : && TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec)).is_constant (&nelts))
10700 : : {
10701 : 158814 : first = error_mark_node;
10702 : :
10703 : 517509 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t)
10704 : : {
10705 : 460636 : if (i == 0)
10706 : : {
10707 : 158814 : first = t;
10708 : 158814 : continue;
10709 : : }
10710 : 301822 : if (!operand_equal_p (first, t, 0))
10711 : : return NULL_TREE;
10712 : : }
10713 : 56873 : if (i != nelts)
10714 : : return NULL_TREE;
10715 : :
10716 : 56682 : if (TREE_CODE (first) == CONSTRUCTOR || TREE_CODE (first) == VECTOR_CST)
10717 : : return uniform_vector_p (first);
10718 : : return first;
10719 : : }
10720 : :
10721 : : return NULL_TREE;
10722 : : }
10723 : :
10724 : : /* If the argument is INTEGER_CST, return it. If the argument is vector
10725 : : with all elements the same INTEGER_CST, return that INTEGER_CST. Otherwise
10726 : : return NULL_TREE.
10727 : : Look through location wrappers. */
10728 : :
10729 : : tree
10730 : 835040501 : uniform_integer_cst_p (tree t)
10731 : : {
10732 : 835040501 : STRIP_ANY_LOCATION_WRAPPER (t);
10733 : :
10734 : 835040501 : if (TREE_CODE (t) == INTEGER_CST)
10735 : : return t;
10736 : :
10737 : 340917979 : if (VECTOR_TYPE_P (TREE_TYPE (t)))
10738 : : {
10739 : 887477 : t = uniform_vector_p (t);
10740 : 887477 : if (t && TREE_CODE (t) == INTEGER_CST)
10741 : : return t;
10742 : : }
10743 : :
10744 : : return NULL_TREE;
10745 : : }
10746 : :
10747 : : /* Checks to see if T is a constant or a constant vector and if each element E
10748 : : adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE. */
10749 : :
10750 : : tree
10751 : 3168978 : bitmask_inv_cst_vector_p (tree t)
10752 : : {
10753 : :
10754 : 3168978 : tree_code code = TREE_CODE (t);
10755 : 3168978 : tree type = TREE_TYPE (t);
10756 : :
10757 : 3168978 : if (!INTEGRAL_TYPE_P (type)
10758 : 3168978 : && !VECTOR_INTEGER_TYPE_P (type))
10759 : : return NULL_TREE;
10760 : :
10761 : 3168978 : unsigned HOST_WIDE_INT nelts = 1;
10762 : 3168978 : tree cst;
10763 : 3168978 : unsigned int idx = 0;
10764 : 3168978 : bool uniform = uniform_integer_cst_p (t);
10765 : 3168978 : tree newtype = unsigned_type_for (type);
10766 : 3168978 : tree_vector_builder builder;
10767 : 3168978 : if (code == INTEGER_CST)
10768 : : cst = t;
10769 : : else
10770 : : {
10771 : 6024 : if (!VECTOR_CST_NELTS (t).is_constant (&nelts))
10772 : : return NULL_TREE;
10773 : :
10774 : 6024 : cst = vector_cst_elt (t, 0);
10775 : 6024 : builder.new_vector (newtype, nelts, 1);
10776 : : }
10777 : :
10778 : 3168978 : tree ty = unsigned_type_for (TREE_TYPE (cst));
10779 : :
10780 : 3168990 : do
10781 : : {
10782 : 3168990 : if (idx > 0)
10783 : 12 : cst = vector_cst_elt (t, idx);
10784 : 3168990 : wide_int icst = wi::to_wide (cst);
10785 : 3168990 : wide_int inv = wi::bit_not (icst);
10786 : 3168990 : icst = wi::add (1, inv);
10787 : 3168990 : if (wi::popcount (icst) != 1)
10788 : : return NULL_TREE;
10789 : :
10790 : 22358 : tree newcst = wide_int_to_tree (ty, inv);
10791 : :
10792 : 22358 : if (uniform)
10793 : 22342 : return build_uniform_cst (newtype, newcst);
10794 : :
10795 : 16 : builder.quick_push (newcst);
10796 : 3168990 : }
10797 : 16 : while (++idx < nelts);
10798 : :
10799 : 4 : return builder.build ();
10800 : 3168978 : }
10801 : :
10802 : : /* If VECTOR_CST T has a single nonzero element, return the index of that
10803 : : element, otherwise return -1. */
10804 : :
10805 : : int
10806 : 177 : single_nonzero_element (const_tree t)
10807 : : {
10808 : 177 : unsigned HOST_WIDE_INT nelts;
10809 : 177 : unsigned int repeat_nelts;
10810 : 177 : if (VECTOR_CST_NELTS (t).is_constant (&nelts))
10811 : 177 : repeat_nelts = nelts;
10812 : : else if (VECTOR_CST_NELTS_PER_PATTERN (t) == 2)
10813 : : {
10814 : : nelts = vector_cst_encoded_nelts (t);
10815 : : repeat_nelts = VECTOR_CST_NPATTERNS (t);
10816 : : }
10817 : : else
10818 : : return -1;
10819 : :
10820 : 177 : int res = -1;
10821 : 561 : for (unsigned int i = 0; i < nelts; ++i)
10822 : : {
10823 : 528 : tree elt = vector_cst_elt (t, i);
10824 : 528 : if (!integer_zerop (elt) && !real_zerop (elt))
10825 : : {
10826 : 321 : if (res >= 0 || i >= repeat_nelts)
10827 : : return -1;
10828 : 177 : res = i;
10829 : : }
10830 : : }
10831 : : return res;
10832 : : }
10833 : :
10834 : : /* Build an empty statement at location LOC. */
10835 : :
10836 : : tree
10837 : 12497269 : build_empty_stmt (location_t loc)
10838 : : {
10839 : 12497269 : tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
10840 : 12497269 : SET_EXPR_LOCATION (t, loc);
10841 : 12497269 : return t;
10842 : : }
10843 : :
10844 : :
10845 : : /* Build an OMP clause with code CODE. LOC is the location of the
10846 : : clause. */
10847 : :
10848 : : tree
10849 : 1699153 : build_omp_clause (location_t loc, enum omp_clause_code code)
10850 : : {
10851 : 1699153 : tree t;
10852 : 1699153 : int size, length;
10853 : :
10854 : 1699153 : length = omp_clause_num_ops[code];
10855 : 1699153 : size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
10856 : :
10857 : 1699153 : record_node_allocation_statistics (OMP_CLAUSE, size);
10858 : :
10859 : 1699153 : t = (tree) ggc_internal_alloc (size);
10860 : 1699153 : memset (t, 0, size);
10861 : 1699153 : TREE_SET_CODE (t, OMP_CLAUSE);
10862 : 1699153 : OMP_CLAUSE_SET_CODE (t, code);
10863 : 1699153 : OMP_CLAUSE_LOCATION (t) = loc;
10864 : :
10865 : 1699153 : return t;
10866 : : }
10867 : :
10868 : : /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
10869 : : includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
10870 : : Except for the CODE and operand count field, other storage for the
10871 : : object is initialized to zeros. */
10872 : :
10873 : : tree
10874 : 430574862 : build_vl_exp (enum tree_code code, int len MEM_STAT_DECL)
10875 : : {
10876 : 430574862 : tree t;
10877 : 430574862 : int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
10878 : :
10879 : 430574862 : gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp);
10880 : 430574862 : gcc_assert (len >= 1);
10881 : :
10882 : 430574862 : record_node_allocation_statistics (code, length);
10883 : :
10884 : 430574862 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
10885 : :
10886 : 430574862 : TREE_SET_CODE (t, code);
10887 : :
10888 : : /* Can't use TREE_OPERAND to store the length because if checking is
10889 : : enabled, it will try to check the length before we store it. :-P */
10890 : 430574862 : t->exp.operands[0] = build_int_cst (sizetype, len);
10891 : :
10892 : 430574862 : return t;
10893 : : }
10894 : :
10895 : : /* Helper function for build_call_* functions; build a CALL_EXPR with
10896 : : indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
10897 : : the argument slots. */
10898 : :
10899 : : static tree
10900 : 229389617 : build_call_1 (tree return_type, tree fn, int nargs)
10901 : : {
10902 : 229389617 : tree t;
10903 : :
10904 : 229389617 : t = build_vl_exp (CALL_EXPR, nargs + 3);
10905 : 229389617 : TREE_TYPE (t) = return_type;
10906 : 229389617 : CALL_EXPR_FN (t) = fn;
10907 : 229389617 : CALL_EXPR_STATIC_CHAIN (t) = NULL;
10908 : :
10909 : 229389617 : return t;
10910 : : }
10911 : :
10912 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10913 : : FN and a null static chain slot. NARGS is the number of call arguments
10914 : : which are specified as "..." arguments. */
10915 : :
10916 : : tree
10917 : 151 : build_call_nary (tree return_type, tree fn, int nargs, ...)
10918 : : {
10919 : 151 : tree ret;
10920 : 151 : va_list args;
10921 : 151 : va_start (args, nargs);
10922 : 151 : ret = build_call_valist (return_type, fn, nargs, args);
10923 : 151 : va_end (args);
10924 : 151 : return ret;
10925 : : }
10926 : :
10927 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10928 : : FN and a null static chain slot. NARGS is the number of call arguments
10929 : : which are specified as a va_list ARGS. */
10930 : :
10931 : : tree
10932 : 136008 : build_call_valist (tree return_type, tree fn, int nargs, va_list args)
10933 : : {
10934 : 136008 : tree t;
10935 : 136008 : int i;
10936 : :
10937 : 136008 : t = build_call_1 (return_type, fn, nargs);
10938 : 551770 : for (i = 0; i < nargs; i++)
10939 : 279754 : CALL_EXPR_ARG (t, i) = va_arg (args, tree);
10940 : 136008 : process_call_operands (t);
10941 : 136008 : return t;
10942 : : }
10943 : :
10944 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10945 : : FN and a null static chain slot. NARGS is the number of call arguments
10946 : : which are specified as a tree array ARGS. */
10947 : :
10948 : : tree
10949 : 188476299 : build_call_array_loc (location_t loc, tree return_type, tree fn,
10950 : : int nargs, const tree *args)
10951 : : {
10952 : 188476299 : tree t;
10953 : 188476299 : int i;
10954 : :
10955 : 188476299 : t = build_call_1 (return_type, fn, nargs);
10956 : 653385577 : for (i = 0; i < nargs; i++)
10957 : 276432979 : CALL_EXPR_ARG (t, i) = args[i];
10958 : 188476299 : process_call_operands (t);
10959 : 188476299 : SET_EXPR_LOCATION (t, loc);
10960 : 188476299 : return t;
10961 : : }
10962 : :
10963 : : /* Like build_call_array, but takes a vec. */
10964 : :
10965 : : tree
10966 : 40456283 : build_call_vec (tree return_type, tree fn, const vec<tree, va_gc> *args)
10967 : : {
10968 : 40456283 : tree ret, t;
10969 : 40456283 : unsigned int ix;
10970 : :
10971 : 40456283 : ret = build_call_1 (return_type, fn, vec_safe_length (args));
10972 : 106851278 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
10973 : 25938712 : CALL_EXPR_ARG (ret, ix) = t;
10974 : 40456283 : process_call_operands (ret);
10975 : 40456283 : return ret;
10976 : : }
10977 : :
10978 : : /* Conveniently construct a function call expression. FNDECL names the
10979 : : function to be called and N arguments are passed in the array
10980 : : ARGARRAY. */
10981 : :
10982 : : tree
10983 : 17304951 : build_call_expr_loc_array (location_t loc, tree fndecl, int n, tree *argarray)
10984 : : {
10985 : 17304951 : tree fntype = TREE_TYPE (fndecl);
10986 : 17304951 : tree fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fndecl);
10987 : :
10988 : 17304951 : return fold_build_call_array_loc (loc, TREE_TYPE (fntype), fn, n, argarray);
10989 : : }
10990 : :
10991 : : /* Conveniently construct a function call expression. FNDECL names the
10992 : : function to be called and the arguments are passed in the vector
10993 : : VEC. */
10994 : :
10995 : : tree
10996 : 20604 : build_call_expr_loc_vec (location_t loc, tree fndecl, vec<tree, va_gc> *vec)
10997 : : {
10998 : 20604 : return build_call_expr_loc_array (loc, fndecl, vec_safe_length (vec),
10999 : 20604 : vec_safe_address (vec));
11000 : : }
11001 : :
11002 : :
11003 : : /* Conveniently construct a function call expression. FNDECL names the
11004 : : function to be called, N is the number of arguments, and the "..."
11005 : : parameters are the argument expressions. */
11006 : :
11007 : : tree
11008 : 15743711 : build_call_expr_loc (location_t loc, tree fndecl, int n, ...)
11009 : : {
11010 : 15743711 : va_list ap;
11011 : 15743711 : tree *argarray = XALLOCAVEC (tree, n);
11012 : 15743711 : int i;
11013 : :
11014 : 15743711 : va_start (ap, n);
11015 : 18139530 : for (i = 0; i < n; i++)
11016 : 2395819 : argarray[i] = va_arg (ap, tree);
11017 : 15743711 : va_end (ap);
11018 : 15743711 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11019 : : }
11020 : :
11021 : : /* Like build_call_expr_loc (UNKNOWN_LOCATION, ...). Duplicated because
11022 : : varargs macros aren't supported by all bootstrap compilers. */
11023 : :
11024 : : tree
11025 : 1536153 : build_call_expr (tree fndecl, int n, ...)
11026 : : {
11027 : 1536153 : va_list ap;
11028 : 1536153 : tree *argarray = XALLOCAVEC (tree, n);
11029 : 1536153 : int i;
11030 : :
11031 : 1536153 : va_start (ap, n);
11032 : 4483565 : for (i = 0; i < n; i++)
11033 : 2947412 : argarray[i] = va_arg (ap, tree);
11034 : 1536153 : va_end (ap);
11035 : 1536153 : return build_call_expr_loc_array (UNKNOWN_LOCATION, fndecl, n, argarray);
11036 : : }
11037 : :
11038 : : /* Build an internal call to IFN, with arguments ARGS[0:N-1] and with return
11039 : : type TYPE. This is just like CALL_EXPR, except its CALL_EXPR_FN is NULL.
11040 : : It will get gimplified later into an ordinary internal function. */
11041 : :
11042 : : tree
11043 : 321027 : build_call_expr_internal_loc_array (location_t loc, internal_fn ifn,
11044 : : tree type, int n, const tree *args)
11045 : : {
11046 : 321027 : tree t = build_call_1 (type, NULL_TREE, n);
11047 : 1094438 : for (int i = 0; i < n; ++i)
11048 : 773411 : CALL_EXPR_ARG (t, i) = args[i];
11049 : 321027 : SET_EXPR_LOCATION (t, loc);
11050 : 321027 : CALL_EXPR_IFN (t) = ifn;
11051 : 321027 : process_call_operands (t);
11052 : 321027 : return t;
11053 : : }
11054 : :
11055 : : /* Build internal call expression. This is just like CALL_EXPR, except
11056 : : its CALL_EXPR_FN is NULL. It will get gimplified later into ordinary
11057 : : internal function. */
11058 : :
11059 : : tree
11060 : 320001 : build_call_expr_internal_loc (location_t loc, enum internal_fn ifn,
11061 : : tree type, int n, ...)
11062 : : {
11063 : 320001 : va_list ap;
11064 : 320001 : tree *argarray = XALLOCAVEC (tree, n);
11065 : 320001 : int i;
11066 : :
11067 : 320001 : va_start (ap, n);
11068 : 1091362 : for (i = 0; i < n; i++)
11069 : 771361 : argarray[i] = va_arg (ap, tree);
11070 : 320001 : va_end (ap);
11071 : 320001 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11072 : : }
11073 : :
11074 : : /* Return a function call to FN, if the target is guaranteed to support it,
11075 : : or null otherwise.
11076 : :
11077 : : N is the number of arguments, passed in the "...", and TYPE is the
11078 : : type of the return value. */
11079 : :
11080 : : tree
11081 : 1825 : maybe_build_call_expr_loc (location_t loc, combined_fn fn, tree type,
11082 : : int n, ...)
11083 : : {
11084 : 1825 : va_list ap;
11085 : 1825 : tree *argarray = XALLOCAVEC (tree, n);
11086 : 1825 : int i;
11087 : :
11088 : 1825 : va_start (ap, n);
11089 : 4743 : for (i = 0; i < n; i++)
11090 : 2918 : argarray[i] = va_arg (ap, tree);
11091 : 1825 : va_end (ap);
11092 : 1825 : if (internal_fn_p (fn))
11093 : : {
11094 : 1024 : internal_fn ifn = as_internal_fn (fn);
11095 : 1024 : if (direct_internal_fn_p (ifn))
11096 : : {
11097 : 1 : tree_pair types = direct_internal_fn_types (ifn, type, argarray);
11098 : 1 : if (!direct_internal_fn_supported_p (ifn, types,
11099 : : OPTIMIZE_FOR_BOTH))
11100 : 1 : return NULL_TREE;
11101 : : }
11102 : 1023 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11103 : : }
11104 : : else
11105 : : {
11106 : 801 : tree fndecl = builtin_decl_implicit (as_builtin_fn (fn));
11107 : 801 : if (!fndecl)
11108 : : return NULL_TREE;
11109 : 693 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11110 : : }
11111 : : }
11112 : :
11113 : : /* Return a function call to the appropriate builtin alloca variant.
11114 : :
11115 : : SIZE is the size to be allocated. ALIGN, if non-zero, is the requested
11116 : : alignment of the allocated area. MAX_SIZE, if non-negative, is an upper
11117 : : bound for SIZE in case it is not a fixed value. */
11118 : :
11119 : : tree
11120 : 8838 : build_alloca_call_expr (tree size, unsigned int align, HOST_WIDE_INT max_size)
11121 : : {
11122 : 8838 : if (max_size >= 0)
11123 : : {
11124 : 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX);
11125 : 0 : return
11126 : 0 : build_call_expr (t, 3, size, size_int (align), size_int (max_size));
11127 : : }
11128 : 8838 : else if (align > 0)
11129 : : {
11130 : 8838 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
11131 : 8838 : return build_call_expr (t, 2, size, size_int (align));
11132 : : }
11133 : : else
11134 : : {
11135 : 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA);
11136 : 0 : return build_call_expr (t, 1, size);
11137 : : }
11138 : : }
11139 : :
11140 : : /* The built-in decl to use to mark code points believed to be unreachable.
11141 : : Typically __builtin_unreachable, but __builtin_trap if
11142 : : -fsanitize=unreachable -fsanitize-trap=unreachable. If only
11143 : : -fsanitize=unreachable, we rely on sanopt to replace calls with the
11144 : : appropriate ubsan function. When building a call directly, use
11145 : : {gimple_},build_builtin_unreachable instead. */
11146 : :
11147 : : tree
11148 : 232755 : builtin_decl_unreachable ()
11149 : : {
11150 : 232755 : enum built_in_function fncode = BUILT_IN_UNREACHABLE;
11151 : :
11152 : 465510 : if (sanitize_flags_p (SANITIZE_UNREACHABLE)
11153 : 232755 : ? (flag_sanitize_trap & SANITIZE_UNREACHABLE)
11154 : 232289 : : flag_unreachable_traps)
11155 : 22 : fncode = BUILT_IN_UNREACHABLE_TRAP;
11156 : : /* For non-trapping sanitize, we will rewrite __builtin_unreachable () later,
11157 : : in the sanopt pass. */
11158 : :
11159 : 232755 : return builtin_decl_explicit (fncode);
11160 : : }
11161 : :
11162 : : /* Build a call to __builtin_unreachable, possibly rewritten by
11163 : : -fsanitize=unreachable. Use this rather than the above when practical. */
11164 : :
11165 : : tree
11166 : 14508130 : build_builtin_unreachable (location_t loc)
11167 : : {
11168 : 14508130 : tree data = NULL_TREE;
11169 : 14508130 : tree fn = sanitize_unreachable_fn (&data, loc);
11170 : 14508130 : return build_call_expr_loc (loc, fn, data != NULL_TREE, data);
11171 : : }
11172 : :
11173 : : /* Create a new constant string literal of type ELTYPE[SIZE] (or LEN
11174 : : if SIZE == -1) and return a tree node representing char* pointer to
11175 : : it as an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)). When STR is nonnull
11176 : : the STRING_CST value is the LEN bytes at STR (the representation
11177 : : of the string, which may be wide). Otherwise it's all zeros. */
11178 : :
11179 : : tree
11180 : 86553 : build_string_literal (unsigned len, const char *str /* = NULL */,
11181 : : tree eltype /* = char_type_node */,
11182 : : unsigned HOST_WIDE_INT size /* = -1 */)
11183 : : {
11184 : 86553 : tree t = build_string (len, str);
11185 : : /* Set the maximum valid index based on the string length or SIZE. */
11186 : 173106 : unsigned HOST_WIDE_INT maxidx
11187 : 86553 : = (size == HOST_WIDE_INT_M1U ? len : size) - 1;
11188 : :
11189 : 86553 : tree index = build_index_type (size_int (maxidx));
11190 : 86553 : eltype = build_type_variant (eltype, 1, 0);
11191 : 86553 : tree type = build_array_type (eltype, index);
11192 : 86553 : TREE_TYPE (t) = type;
11193 : 86553 : TREE_CONSTANT (t) = 1;
11194 : 86553 : TREE_READONLY (t) = 1;
11195 : 86553 : TREE_STATIC (t) = 1;
11196 : :
11197 : 86553 : type = build_pointer_type (eltype);
11198 : 86553 : t = build1 (ADDR_EXPR, type,
11199 : : build4 (ARRAY_REF, eltype,
11200 : : t, integer_zero_node, NULL_TREE, NULL_TREE));
11201 : 86553 : return t;
11202 : : }
11203 : :
11204 : :
11205 : :
11206 : : /* Return true if T (assumed to be a DECL) must be assigned a memory
11207 : : location. */
11208 : :
11209 : : bool
11210 : 1954470173 : needs_to_live_in_memory (const_tree t)
11211 : : {
11212 : 1954470173 : return (TREE_ADDRESSABLE (t)
11213 : 1565634514 : || is_global_var (t)
11214 : 3091878146 : || (TREE_CODE (t) == RESULT_DECL
11215 : 7983706 : && !DECL_BY_REFERENCE (t)
11216 : 5605646 : && aggregate_value_p (t, current_function_decl)));
11217 : : }
11218 : :
11219 : : /* Return value of a constant X and sign-extend it. */
11220 : :
11221 : : HOST_WIDE_INT
11222 : 555468349 : int_cst_value (const_tree x)
11223 : : {
11224 : 555468349 : unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
11225 : 555468349 : unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
11226 : :
11227 : : /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
11228 : 555468349 : gcc_assert (cst_and_fits_in_hwi (x));
11229 : :
11230 : 555468349 : if (bits < HOST_BITS_PER_WIDE_INT)
11231 : : {
11232 : 541465874 : bool negative = ((val >> (bits - 1)) & 1) != 0;
11233 : 541465874 : if (negative)
11234 : 189744 : val |= HOST_WIDE_INT_M1U << (bits - 1) << 1;
11235 : : else
11236 : 541276130 : val &= ~(HOST_WIDE_INT_M1U << (bits - 1) << 1);
11237 : : }
11238 : :
11239 : 555468349 : return val;
11240 : : }
11241 : :
11242 : : /* If TYPE is an integral or pointer type, return an integer type with
11243 : : the same precision which is unsigned iff UNSIGNEDP is true, or itself
11244 : : if TYPE is already an integer type of signedness UNSIGNEDP.
11245 : : If TYPE is a floating-point type, return an integer type with the same
11246 : : bitsize and with the signedness given by UNSIGNEDP; this is useful
11247 : : when doing bit-level operations on a floating-point value. */
11248 : :
11249 : : tree
11250 : 85976736 : signed_or_unsigned_type_for (int unsignedp, tree type)
11251 : : {
11252 : 85976736 : if (ANY_INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) == unsignedp)
11253 : : return type;
11254 : :
11255 : 55463437 : if (TREE_CODE (type) == VECTOR_TYPE)
11256 : : {
11257 : 18344 : tree inner = TREE_TYPE (type);
11258 : 18344 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11259 : 18344 : if (!inner2)
11260 : : return NULL_TREE;
11261 : 18344 : if (inner == inner2)
11262 : : return type;
11263 : 18344 : machine_mode new_mode;
11264 : 36688 : if (VECTOR_MODE_P (TYPE_MODE (type))
11265 : 36619 : && related_int_vector_mode (TYPE_MODE (type)).exists (&new_mode))
11266 : 18275 : return build_vector_type_for_mode (inner2, new_mode);
11267 : 69 : return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type));
11268 : : }
11269 : :
11270 : : if (TREE_CODE (type) == COMPLEX_TYPE)
11271 : : {
11272 : 24 : tree inner = TREE_TYPE (type);
11273 : 24 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11274 : 24 : if (!inner2)
11275 : : return NULL_TREE;
11276 : 24 : if (inner == inner2)
11277 : : return type;
11278 : 24 : return build_complex_type (inner2);
11279 : : }
11280 : :
11281 : : unsigned int bits;
11282 : : if (INTEGRAL_TYPE_P (type)
11283 : : || POINTER_TYPE_P (type)
11284 : : || TREE_CODE (type) == OFFSET_TYPE)
11285 : 55444975 : bits = TYPE_PRECISION (type);
11286 : : else if (TREE_CODE (type) == REAL_TYPE)
11287 : 188 : bits = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (type));
11288 : : else
11289 : : return NULL_TREE;
11290 : :
11291 : 55445069 : if (TREE_CODE (type) == BITINT_TYPE && (unsignedp || bits > 1))
11292 : 1488 : return build_bitint_type (bits, unsignedp);
11293 : 55443581 : return build_nonstandard_integer_type (bits, unsignedp);
11294 : : }
11295 : :
11296 : : /* If TYPE is an integral or pointer type, return an integer type with
11297 : : the same precision which is unsigned, or itself if TYPE is already an
11298 : : unsigned integer type. If TYPE is a floating-point type, return an
11299 : : unsigned integer type with the same bitsize as TYPE. */
11300 : :
11301 : : tree
11302 : 76837745 : unsigned_type_for (tree type)
11303 : : {
11304 : 76837745 : return signed_or_unsigned_type_for (1, type);
11305 : : }
11306 : :
11307 : : /* If TYPE is an integral or pointer type, return an integer type with
11308 : : the same precision which is signed, or itself if TYPE is already a
11309 : : signed integer type. If TYPE is a floating-point type, return a
11310 : : signed integer type with the same bitsize as TYPE. */
11311 : :
11312 : : tree
11313 : 9115723 : signed_type_for (tree type)
11314 : : {
11315 : 9115723 : return signed_or_unsigned_type_for (0, type);
11316 : : }
11317 : :
11318 : : /* - For VECTOR_TYPEs:
11319 : : - The truth type must be a VECTOR_BOOLEAN_TYPE.
11320 : : - The number of elements must match (known_eq).
11321 : : - targetm.vectorize.get_mask_mode exists, and exactly
11322 : : the same mode as the truth type.
11323 : : - Otherwise, the truth type must be a BOOLEAN_TYPE
11324 : : or useless_type_conversion_p to BOOLEAN_TYPE. */
11325 : : bool
11326 : 1924 : is_truth_type_for (tree type, tree truth_type)
11327 : : {
11328 : 1924 : machine_mode mask_mode = TYPE_MODE (truth_type);
11329 : 1924 : machine_mode vmode = TYPE_MODE (type);
11330 : 1924 : machine_mode tmask_mode;
11331 : :
11332 : 1924 : if (TREE_CODE (type) == VECTOR_TYPE)
11333 : : {
11334 : 1924 : if (VECTOR_BOOLEAN_TYPE_P (truth_type)
11335 : 1924 : && known_eq (TYPE_VECTOR_SUBPARTS (type),
11336 : : TYPE_VECTOR_SUBPARTS (truth_type))
11337 : 1924 : && targetm.vectorize.get_mask_mode (vmode).exists (&tmask_mode)
11338 : 3848 : && tmask_mode == mask_mode)
11339 : 1905 : return true;
11340 : :
11341 : 19 : return false;
11342 : : }
11343 : :
11344 : 0 : return useless_type_conversion_p (boolean_type_node, truth_type);
11345 : : }
11346 : :
11347 : : /* If TYPE is a vector type, return a signed integer vector type with the
11348 : : same width and number of subparts. Otherwise return boolean_type_node. */
11349 : :
11350 : : tree
11351 : 3879016 : truth_type_for (tree type)
11352 : : {
11353 : 3879016 : if (TREE_CODE (type) == VECTOR_TYPE)
11354 : : {
11355 : 1985363 : if (VECTOR_BOOLEAN_TYPE_P (type))
11356 : : return type;
11357 : 1913200 : return build_truth_vector_type_for (type);
11358 : : }
11359 : : else
11360 : 1893653 : return boolean_type_node;
11361 : : }
11362 : :
11363 : : /* Returns the largest value obtainable by casting something in INNER type to
11364 : : OUTER type. */
11365 : :
11366 : : tree
11367 : 10512633 : upper_bound_in_type (tree outer, tree inner)
11368 : : {
11369 : 10512633 : unsigned int det = 0;
11370 : 10512633 : unsigned oprec = TYPE_PRECISION (outer);
11371 : 10512633 : unsigned iprec = TYPE_PRECISION (inner);
11372 : 10512633 : unsigned prec;
11373 : :
11374 : : /* Compute a unique number for every combination. */
11375 : 10512633 : det |= (oprec > iprec) ? 4 : 0;
11376 : 10512633 : det |= TYPE_UNSIGNED (outer) ? 2 : 0;
11377 : 10512633 : det |= TYPE_UNSIGNED (inner) ? 1 : 0;
11378 : :
11379 : : /* Determine the exponent to use. */
11380 : 10512633 : switch (det)
11381 : : {
11382 : 6943095 : case 0:
11383 : 6943095 : case 1:
11384 : : /* oprec <= iprec, outer: signed, inner: don't care. */
11385 : 6943095 : prec = oprec - 1;
11386 : 6943095 : break;
11387 : : case 2:
11388 : : case 3:
11389 : : /* oprec <= iprec, outer: unsigned, inner: don't care. */
11390 : : prec = oprec;
11391 : : break;
11392 : 21563 : case 4:
11393 : : /* oprec > iprec, outer: signed, inner: signed. */
11394 : 21563 : prec = iprec - 1;
11395 : 21563 : break;
11396 : : case 5:
11397 : : /* oprec > iprec, outer: signed, inner: unsigned. */
11398 : 8406 : prec = iprec;
11399 : : break;
11400 : : case 6:
11401 : : /* oprec > iprec, outer: unsigned, inner: signed. */
11402 : : prec = oprec;
11403 : : break;
11404 : : case 7:
11405 : : /* oprec > iprec, outer: unsigned, inner: unsigned. */
11406 : 8406 : prec = iprec;
11407 : : break;
11408 : : default:
11409 : : gcc_unreachable ();
11410 : : }
11411 : :
11412 : 10512633 : return wide_int_to_tree (outer,
11413 : 10512633 : wi::mask (prec, false, TYPE_PRECISION (outer)));
11414 : : }
11415 : :
11416 : : /* Returns the smallest value obtainable by casting something in INNER type to
11417 : : OUTER type. */
11418 : :
11419 : : tree
11420 : 7995495 : lower_bound_in_type (tree outer, tree inner)
11421 : : {
11422 : 7995495 : unsigned oprec = TYPE_PRECISION (outer);
11423 : 7995495 : unsigned iprec = TYPE_PRECISION (inner);
11424 : :
11425 : : /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
11426 : : and obtain 0. */
11427 : 7995495 : if (TYPE_UNSIGNED (outer)
11428 : : /* If we are widening something of an unsigned type, OUTER type
11429 : : contains all values of INNER type. In particular, both INNER
11430 : : and OUTER types have zero in common. */
11431 : 7995495 : || (oprec > iprec && TYPE_UNSIGNED (inner)))
11432 : 2118629 : return build_int_cst (outer, 0);
11433 : : else
11434 : : {
11435 : : /* If we are widening a signed type to another signed type, we
11436 : : want to obtain -2^^(iprec-1). If we are keeping the
11437 : : precision or narrowing to a signed type, we want to obtain
11438 : : -2^(oprec-1). */
11439 : 5876866 : unsigned prec = oprec > iprec ? iprec : oprec;
11440 : 5876866 : return wide_int_to_tree (outer,
11441 : 11753732 : wi::mask (prec - 1, true,
11442 : 5876866 : TYPE_PRECISION (outer)));
11443 : : }
11444 : : }
11445 : :
11446 : : /* Return true if two operands that are suitable for PHI nodes are
11447 : : necessarily equal. Specifically, both ARG0 and ARG1 must be either
11448 : : SSA_NAME or invariant. Note that this is strictly an optimization.
11449 : : That is, callers of this function can directly call operand_equal_p
11450 : : and get the same result, only slower. */
11451 : :
11452 : : bool
11453 : 21270543 : operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1)
11454 : : {
11455 : 21270543 : if (arg0 == arg1)
11456 : : return true;
11457 : 19536316 : if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
11458 : : return false;
11459 : 3729271 : return operand_equal_p (arg0, arg1, 0);
11460 : : }
11461 : :
11462 : : /* Returns number of zeros at the end of binary representation of X. */
11463 : :
11464 : : tree
11465 : 8783527 : num_ending_zeros (const_tree x)
11466 : : {
11467 : 8783527 : return build_int_cst (TREE_TYPE (x), wi::ctz (wi::to_wide (x)));
11468 : : }
11469 : :
11470 : :
11471 : : #define WALK_SUBTREE(NODE) \
11472 : : do \
11473 : : { \
11474 : : result = walk_tree_1 (&(NODE), func, data, pset, lh); \
11475 : : if (result) \
11476 : : return result; \
11477 : : } \
11478 : : while (0)
11479 : :
11480 : : /* This is a subroutine of walk_tree that walks field of TYPE that are to
11481 : : be walked whenever a type is seen in the tree. Rest of operands and return
11482 : : value are as for walk_tree. */
11483 : :
11484 : : static tree
11485 : 3740681691 : walk_type_fields (tree type, walk_tree_fn func, void *data,
11486 : : hash_set<tree> *pset, walk_tree_lh lh)
11487 : : {
11488 : 3740681691 : tree result = NULL_TREE;
11489 : :
11490 : 3740681691 : switch (TREE_CODE (type))
11491 : : {
11492 : 1106134707 : case POINTER_TYPE:
11493 : 1106134707 : case REFERENCE_TYPE:
11494 : 1106134707 : case VECTOR_TYPE:
11495 : : /* We have to worry about mutually recursive pointers. These can't
11496 : : be written in C. They can in Ada. It's pathological, but
11497 : : there's an ACATS test (c38102a) that checks it. Deal with this
11498 : : by checking if we're pointing to another pointer, that one
11499 : : points to another pointer, that one does too, and we have no htab.
11500 : : If so, get a hash table. We check three levels deep to avoid
11501 : : the cost of the hash table if we don't need one. */
11502 : 2186788874 : if (POINTER_TYPE_P (TREE_TYPE (type))
11503 : 25480607 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
11504 : 4851693 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
11505 : 1110957085 : && !pset)
11506 : : {
11507 : 0 : result = walk_tree_without_duplicates (&TREE_TYPE (type),
11508 : : func, data);
11509 : 0 : if (result)
11510 : : return result;
11511 : :
11512 : : break;
11513 : : }
11514 : :
11515 : : /* fall through */
11516 : :
11517 : 1109259114 : case COMPLEX_TYPE:
11518 : 1109259114 : WALK_SUBTREE (TREE_TYPE (type));
11519 : : break;
11520 : :
11521 : 214536960 : case METHOD_TYPE:
11522 : 214536960 : WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
11523 : :
11524 : : /* Fall through. */
11525 : :
11526 : 349417270 : case FUNCTION_TYPE:
11527 : 349417270 : WALK_SUBTREE (TREE_TYPE (type));
11528 : 349417232 : {
11529 : 349417232 : tree arg;
11530 : :
11531 : : /* We never want to walk into default arguments. */
11532 : 1350745152 : for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
11533 : 1001357122 : WALK_SUBTREE (TREE_VALUE (arg));
11534 : : }
11535 : : break;
11536 : :
11537 : 12069880 : case ARRAY_TYPE:
11538 : : /* Don't follow this nodes's type if a pointer for fear that
11539 : : we'll have infinite recursion. If we have a PSET, then we
11540 : : need not fear. */
11541 : 12069880 : if (pset
11542 : 12069880 : || (!POINTER_TYPE_P (TREE_TYPE (type))
11543 : 106016 : && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
11544 : 12068181 : WALK_SUBTREE (TREE_TYPE (type));
11545 : 12067336 : WALK_SUBTREE (TYPE_DOMAIN (type));
11546 : : break;
11547 : :
11548 : 926875 : case OFFSET_TYPE:
11549 : 926875 : WALK_SUBTREE (TREE_TYPE (type));
11550 : 926043 : WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
11551 : : break;
11552 : :
11553 : : default:
11554 : : break;
11555 : : }
11556 : :
11557 : : return NULL_TREE;
11558 : : }
11559 : :
11560 : : /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
11561 : : called with the DATA and the address of each sub-tree. If FUNC returns a
11562 : : non-NULL value, the traversal is stopped, and the value returned by FUNC
11563 : : is returned. If PSET is non-NULL it is used to record the nodes visited,
11564 : : and to avoid visiting a node more than once. */
11565 : :
11566 : : tree
11567 : 96675960561 : walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
11568 : : hash_set<tree> *pset, walk_tree_lh lh)
11569 : : {
11570 : : #define WALK_SUBTREE_TAIL(NODE) \
11571 : : do \
11572 : : { \
11573 : : tp = & (NODE); \
11574 : : goto tail_recurse; \
11575 : : } \
11576 : : while (0)
11577 : :
11578 : >11726*10^7 : tail_recurse:
11579 : : /* Skip empty subtrees. */
11580 : >11726*10^7 : if (!*tp)
11581 : : return NULL_TREE;
11582 : :
11583 : : /* Don't walk the same tree twice, if the user has requested
11584 : : that we avoid doing so. */
11585 : 96360693207 : if (pset && pset->add (*tp))
11586 : : return NULL_TREE;
11587 : :
11588 : : /* Call the function. */
11589 : 95207862576 : int walk_subtrees = 1;
11590 : 95207862576 : tree result = (*func) (tp, &walk_subtrees, data);
11591 : :
11592 : : /* If we found something, return it. */
11593 : 95207862576 : if (result)
11594 : : return result;
11595 : :
11596 : 95148638128 : tree t = *tp;
11597 : 95148638128 : tree_code code = TREE_CODE (t);
11598 : :
11599 : : /* Even if we didn't, FUNC may have decided that there was nothing
11600 : : interesting below this point in the tree. */
11601 : 95148638128 : if (!walk_subtrees)
11602 : : {
11603 : : /* But we still need to check our siblings. */
11604 : 62865240787 : if (code == TREE_LIST)
11605 : 94386 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11606 : 62865146401 : else if (code == OMP_CLAUSE)
11607 : 873942 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11608 : : else
11609 : : return NULL_TREE;
11610 : : }
11611 : :
11612 : 32283397341 : if (lh)
11613 : : {
11614 : 15590088735 : result = (*lh) (tp, &walk_subtrees, func, data, pset);
11615 : 15590088735 : if (result || !walk_subtrees)
11616 : 2215533951 : return result;
11617 : : }
11618 : :
11619 : 30067863390 : switch (code)
11620 : : {
11621 : : case ERROR_MARK:
11622 : : case IDENTIFIER_NODE:
11623 : : case INTEGER_CST:
11624 : : case REAL_CST:
11625 : : case FIXED_CST:
11626 : : case STRING_CST:
11627 : : case BLOCK:
11628 : : case PLACEHOLDER_EXPR:
11629 : : case SSA_NAME:
11630 : : case FIELD_DECL:
11631 : : case RESULT_DECL:
11632 : : /* None of these have subtrees other than those already walked
11633 : : above. */
11634 : : break;
11635 : :
11636 : 235694307 : case TREE_LIST:
11637 : 235694307 : WALK_SUBTREE (TREE_VALUE (t));
11638 : 235196176 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11639 : :
11640 : 813333910 : case TREE_VEC:
11641 : 813333910 : {
11642 : 813333910 : int len = TREE_VEC_LENGTH (t);
11643 : :
11644 : 813333910 : if (len == 0)
11645 : : break;
11646 : :
11647 : : /* Walk all elements but the last. */
11648 : 1647093576 : for (int i = 0; i < len - 1; ++i)
11649 : 842799311 : WALK_SUBTREE (TREE_VEC_ELT (t, i));
11650 : :
11651 : : /* Now walk the last one as a tail call. */
11652 : 804294265 : WALK_SUBTREE_TAIL (TREE_VEC_ELT (t, len - 1));
11653 : : }
11654 : :
11655 : 4557005 : case VECTOR_CST:
11656 : 4557005 : {
11657 : 4557005 : unsigned len = vector_cst_encoded_nelts (t);
11658 : 4557005 : if (len == 0)
11659 : : break;
11660 : : /* Walk all elements but the last. */
11661 : 15750179 : for (unsigned i = 0; i < len - 1; ++i)
11662 : 11193318 : WALK_SUBTREE (VECTOR_CST_ENCODED_ELT (t, i));
11663 : : /* Now walk the last one as a tail call. */
11664 : 4556861 : WALK_SUBTREE_TAIL (VECTOR_CST_ENCODED_ELT (t, len - 1));
11665 : : }
11666 : :
11667 : 533408 : case COMPLEX_CST:
11668 : 533408 : WALK_SUBTREE (TREE_REALPART (t));
11669 : 531842 : WALK_SUBTREE_TAIL (TREE_IMAGPART (t));
11670 : :
11671 : : case CONSTRUCTOR:
11672 : : {
11673 : : unsigned HOST_WIDE_INT idx;
11674 : : constructor_elt *ce;
11675 : :
11676 : 668968914 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce);
11677 : : idx++)
11678 : 210504342 : WALK_SUBTREE (ce->value);
11679 : : }
11680 : : break;
11681 : :
11682 : 3328158 : case SAVE_EXPR:
11683 : 3328158 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, 0));
11684 : :
11685 : 151740782 : case BIND_EXPR:
11686 : 151740782 : {
11687 : 151740782 : tree decl;
11688 : 248633687 : for (decl = BIND_EXPR_VARS (t); decl; decl = DECL_CHAIN (decl))
11689 : : {
11690 : : /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
11691 : : into declarations that are just mentioned, rather than
11692 : : declared; they don't really belong to this part of the tree.
11693 : : And, we can see cycles: the initializer for a declaration
11694 : : can refer to the declaration itself. */
11695 : 96892929 : WALK_SUBTREE (DECL_INITIAL (decl));
11696 : 96892905 : WALK_SUBTREE (DECL_SIZE (decl));
11697 : 96892905 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
11698 : : }
11699 : 151740758 : WALK_SUBTREE_TAIL (BIND_EXPR_BODY (t));
11700 : : }
11701 : :
11702 : 177757503 : case STATEMENT_LIST:
11703 : 177757503 : {
11704 : 177757503 : tree_stmt_iterator i;
11705 : 641872621 : for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
11706 : 464248035 : WALK_SUBTREE (*tsi_stmt_ptr (i));
11707 : : }
11708 : 177624586 : break;
11709 : :
11710 : 1675866 : case OMP_CLAUSE:
11711 : 1675866 : {
11712 : 1675866 : int len = omp_clause_num_ops[OMP_CLAUSE_CODE (t)];
11713 : 4387641 : for (int i = 0; i < len; i++)
11714 : 2711775 : WALK_SUBTREE (OMP_CLAUSE_OPERAND (t, i));
11715 : 1675866 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11716 : : }
11717 : :
11718 : 42319793 : case TARGET_EXPR:
11719 : 42319793 : {
11720 : 42319793 : int i, len;
11721 : :
11722 : : /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
11723 : : But, we only want to walk once. */
11724 : 42319793 : len = (TREE_OPERAND (t, 3) == TREE_OPERAND (t, 1)) ? 2 : 3;
11725 : 169248935 : for (i = 0; i < len; ++i)
11726 : 126943048 : WALK_SUBTREE (TREE_OPERAND (t, i));
11727 : 42305887 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len));
11728 : : }
11729 : :
11730 : 91347406 : case DECL_EXPR:
11731 : : /* If this is a TYPE_DECL, walk into the fields of the type that it's
11732 : : defining. We only want to walk into these fields of a type in this
11733 : : case and not in the general case of a mere reference to the type.
11734 : :
11735 : : The criterion is as follows: if the field can be an expression, it
11736 : : must be walked only here. This should be in keeping with the fields
11737 : : that are directly gimplified in gimplify_type_sizes in order for the
11738 : : mark/copy-if-shared/unmark machinery of the gimplifier to work with
11739 : : variable-sized types.
11740 : :
11741 : : Note that DECLs get walked as part of processing the BIND_EXPR. */
11742 : 91347406 : if (TREE_CODE (DECL_EXPR_DECL (t)) == TYPE_DECL)
11743 : : {
11744 : : /* Call the function for the decl so e.g. copy_tree_body_r can
11745 : : replace it with the remapped one. */
11746 : 826727 : result = (*func) (&DECL_EXPR_DECL (t), &walk_subtrees, data);
11747 : 826727 : if (result || !walk_subtrees)
11748 : 49478 : return result;
11749 : :
11750 : 777249 : tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (t));
11751 : 777249 : if (TREE_CODE (*type_p) == ERROR_MARK)
11752 : : return NULL_TREE;
11753 : :
11754 : : /* Call the function for the type. See if it returns anything or
11755 : : doesn't want us to continue. If we are to continue, walk both
11756 : : the normal fields and those for the declaration case. */
11757 : 777249 : result = (*func) (type_p, &walk_subtrees, data);
11758 : 777249 : if (result || !walk_subtrees)
11759 : 69356 : return result;
11760 : :
11761 : 707893 : tree type = *type_p;
11762 : :
11763 : : /* But do not walk a pointed-to type since it may itself need to
11764 : : be walked in the declaration case if it isn't anonymous. */
11765 : 707893 : if (!POINTER_TYPE_P (type))
11766 : : {
11767 : 692200 : result = walk_type_fields (type, func, data, pset, lh);
11768 : 692200 : if (result)
11769 : : return result;
11770 : : }
11771 : :
11772 : : /* If this is a record type, also walk the fields. */
11773 : 707893 : if (RECORD_OR_UNION_TYPE_P (type))
11774 : : {
11775 : 265892 : tree field;
11776 : :
11777 : 1093277 : for (field = TYPE_FIELDS (type); field;
11778 : 827385 : field = DECL_CHAIN (field))
11779 : : {
11780 : : /* We'd like to look at the type of the field, but we can
11781 : : easily get infinite recursion. So assume it's pointed
11782 : : to elsewhere in the tree. Also, ignore things that
11783 : : aren't fields. */
11784 : 827385 : if (TREE_CODE (field) != FIELD_DECL)
11785 : 609522 : continue;
11786 : :
11787 : 217863 : WALK_SUBTREE (DECL_FIELD_OFFSET (field));
11788 : 217863 : WALK_SUBTREE (DECL_SIZE (field));
11789 : 217863 : WALK_SUBTREE (DECL_SIZE_UNIT (field));
11790 : 217863 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
11791 : 0 : WALK_SUBTREE (DECL_QUALIFIER (field));
11792 : : }
11793 : : }
11794 : :
11795 : : /* Same for scalar types. */
11796 : 442001 : else if (TREE_CODE (type) == BOOLEAN_TYPE
11797 : : || TREE_CODE (type) == ENUMERAL_TYPE
11798 : 442001 : || TREE_CODE (type) == INTEGER_TYPE
11799 : 441964 : || TREE_CODE (type) == FIXED_POINT_TYPE
11800 : 441964 : || TREE_CODE (type) == REAL_TYPE)
11801 : : {
11802 : 37 : WALK_SUBTREE (TYPE_MIN_VALUE (type));
11803 : 37 : WALK_SUBTREE (TYPE_MAX_VALUE (type));
11804 : : }
11805 : :
11806 : 707893 : WALK_SUBTREE (TYPE_SIZE (type));
11807 : 707893 : WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (type));
11808 : : }
11809 : : /* FALLTHRU */
11810 : :
11811 : 25385090469 : default:
11812 : 25385090469 : if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
11813 : : {
11814 : 19472690384 : int i, len;
11815 : :
11816 : : /* Walk over all the sub-trees of this operand. */
11817 : 19472690384 : len = TREE_OPERAND_LENGTH (t);
11818 : :
11819 : : /* Go through the subtrees. We need to do this in forward order so
11820 : : that the scope of a FOR_EXPR is handled properly. */
11821 : 19472690384 : if (len)
11822 : : {
11823 : 40376127374 : for (i = 0; i < len - 1; ++i)
11824 : 21032772885 : WALK_SUBTREE (TREE_OPERAND (t, i));
11825 : 19343354489 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len - 1));
11826 : : }
11827 : : }
11828 : : /* If this is a type, walk the needed fields in the type. */
11829 : 5912400085 : else if (TYPE_P (t))
11830 : 3739989491 : return walk_type_fields (t, func, data, pset, lh);
11831 : : break;
11832 : : }
11833 : :
11834 : : /* We didn't find what we were looking for. */
11835 : : return NULL_TREE;
11836 : :
11837 : : #undef WALK_SUBTREE_TAIL
11838 : : }
11839 : : #undef WALK_SUBTREE
11840 : :
11841 : : /* Like walk_tree, but does not walk duplicate nodes more than once. */
11842 : :
11843 : : tree
11844 : 2644628148 : walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data,
11845 : : walk_tree_lh lh)
11846 : : {
11847 : 2644628148 : tree result;
11848 : :
11849 : 2644628148 : hash_set<tree> pset;
11850 : 2644628148 : result = walk_tree_1 (tp, func, data, &pset, lh);
11851 : 2644628148 : return result;
11852 : 2644628148 : }
11853 : :
11854 : :
11855 : : tree
11856 : 877016011 : tree_block (tree t)
11857 : : {
11858 : 877016011 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
11859 : :
11860 : 877016011 : if (IS_EXPR_CODE_CLASS (c))
11861 : 877016011 : return LOCATION_BLOCK (t->exp.locus);
11862 : 0 : gcc_unreachable ();
11863 : : return NULL;
11864 : : }
11865 : :
11866 : : void
11867 : 450196500 : tree_set_block (tree t, tree b)
11868 : : {
11869 : 450196500 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
11870 : :
11871 : 450196500 : if (IS_EXPR_CODE_CLASS (c))
11872 : : {
11873 : 450196500 : t->exp.locus = set_block (t->exp.locus, b);
11874 : : }
11875 : : else
11876 : 0 : gcc_unreachable ();
11877 : 450196500 : }
11878 : :
11879 : : /* Create a nameless artificial label and put it in the current
11880 : : function context. The label has a location of LOC. Returns the
11881 : : newly created label. */
11882 : :
11883 : : tree
11884 : 30911584 : create_artificial_label (location_t loc)
11885 : : {
11886 : 30911584 : tree lab = build_decl (loc,
11887 : : LABEL_DECL, NULL_TREE, void_type_node);
11888 : :
11889 : 30911584 : DECL_ARTIFICIAL (lab) = 1;
11890 : 30911584 : DECL_IGNORED_P (lab) = 1;
11891 : 30911584 : DECL_CONTEXT (lab) = current_function_decl;
11892 : 30911584 : return lab;
11893 : : }
11894 : :
11895 : : /* Given a tree, try to return a useful variable name that we can use
11896 : : to prefix a temporary that is being assigned the value of the tree.
11897 : : I.E. given <temp> = &A, return A. */
11898 : :
11899 : : const char *
11900 : 24716172 : get_name (tree t)
11901 : : {
11902 : 26614348 : tree stripped_decl;
11903 : :
11904 : 26614348 : stripped_decl = t;
11905 : 26614348 : STRIP_NOPS (stripped_decl);
11906 : 26614348 : if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl))
11907 : 4085897 : return IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
11908 : 22528451 : else if (TREE_CODE (stripped_decl) == SSA_NAME)
11909 : : {
11910 : 1258219 : tree name = SSA_NAME_IDENTIFIER (stripped_decl);
11911 : 297122 : if (!name)
11912 : : return NULL;
11913 : 295725 : return IDENTIFIER_POINTER (name);
11914 : : }
11915 : : else
11916 : : {
11917 : 21270232 : switch (TREE_CODE (stripped_decl))
11918 : : {
11919 : 1898176 : case ADDR_EXPR:
11920 : 1898176 : return get_name (TREE_OPERAND (stripped_decl, 0));
11921 : : default:
11922 : : return NULL;
11923 : : }
11924 : : }
11925 : : }
11926 : :
11927 : : /* Return true if TYPE has a variable argument list. */
11928 : :
11929 : : bool
11930 : 205612348 : stdarg_p (const_tree fntype)
11931 : : {
11932 : 205612348 : function_args_iterator args_iter;
11933 : 205612348 : tree n = NULL_TREE, t;
11934 : :
11935 : 205612348 : if (!fntype)
11936 : : return false;
11937 : :
11938 : 205479417 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
11939 : : return true;
11940 : :
11941 : 836310307 : FOREACH_FUNCTION_ARGS (fntype, t, args_iter)
11942 : : {
11943 : 631488742 : n = t;
11944 : : }
11945 : :
11946 : 204821565 : return n != NULL_TREE && n != void_type_node;
11947 : : }
11948 : :
11949 : : /* Return true if TYPE has a prototype. */
11950 : :
11951 : : bool
11952 : 700950092 : prototype_p (const_tree fntype)
11953 : : {
11954 : 700950092 : tree t;
11955 : :
11956 : 700950092 : gcc_assert (fntype != NULL_TREE);
11957 : :
11958 : 700950092 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
11959 : : return true;
11960 : :
11961 : 700205129 : t = TYPE_ARG_TYPES (fntype);
11962 : 700205129 : return (t != NULL_TREE);
11963 : : }
11964 : :
11965 : : /* If BLOCK is inlined from an __attribute__((__artificial__))
11966 : : routine, return pointer to location from where it has been
11967 : : called. */
11968 : : location_t *
11969 : 166985 : block_nonartificial_location (tree block)
11970 : : {
11971 : 166985 : location_t *ret = NULL;
11972 : :
11973 : 431888 : while (block && TREE_CODE (block) == BLOCK
11974 : 524833 : && BLOCK_ABSTRACT_ORIGIN (block))
11975 : : {
11976 : 166877 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
11977 : 166877 : if (TREE_CODE (ao) == FUNCTION_DECL)
11978 : : {
11979 : : /* If AO is an artificial inline, point RET to the
11980 : : call site locus at which it has been inlined and continue
11981 : : the loop, in case AO's caller is also an artificial
11982 : : inline. */
11983 : 70644 : if (DECL_DECLARED_INLINE_P (ao)
11984 : 70644 : && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
11985 : 1789 : ret = &BLOCK_SOURCE_LOCATION (block);
11986 : : else
11987 : : break;
11988 : : }
11989 : 96233 : else if (TREE_CODE (ao) != BLOCK)
11990 : : break;
11991 : :
11992 : 98022 : block = BLOCK_SUPERCONTEXT (block);
11993 : : }
11994 : 166985 : return ret;
11995 : : }
11996 : :
11997 : :
11998 : : /* If EXP is inlined from an __attribute__((__artificial__))
11999 : : function, return the location of the original call expression. */
12000 : :
12001 : : location_t
12002 : 104 : tree_nonartificial_location (tree exp)
12003 : : {
12004 : 104 : location_t *loc = block_nonartificial_location (TREE_BLOCK (exp));
12005 : :
12006 : 104 : if (loc)
12007 : 0 : return *loc;
12008 : : else
12009 : 104 : return EXPR_LOCATION (exp);
12010 : : }
12011 : :
12012 : : /* Return the location into which EXP has been inlined. Analogous
12013 : : to tree_nonartificial_location() above but not limited to artificial
12014 : : functions declared inline. If SYSTEM_HEADER is true, return
12015 : : the macro expansion point of the location if it's in a system header */
12016 : :
12017 : : location_t
12018 : 0 : tree_inlined_location (tree exp, bool system_header /* = true */)
12019 : : {
12020 : 0 : location_t loc = UNKNOWN_LOCATION;
12021 : :
12022 : 0 : tree block = TREE_BLOCK (exp);
12023 : :
12024 : 0 : while (block && TREE_CODE (block) == BLOCK
12025 : 0 : && BLOCK_ABSTRACT_ORIGIN (block))
12026 : : {
12027 : 0 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12028 : 0 : if (TREE_CODE (ao) == FUNCTION_DECL)
12029 : 0 : loc = BLOCK_SOURCE_LOCATION (block);
12030 : 0 : else if (TREE_CODE (ao) != BLOCK)
12031 : : break;
12032 : :
12033 : 0 : block = BLOCK_SUPERCONTEXT (block);
12034 : : }
12035 : :
12036 : 0 : if (loc == UNKNOWN_LOCATION)
12037 : : {
12038 : 0 : loc = EXPR_LOCATION (exp);
12039 : 0 : if (system_header)
12040 : : /* Only consider macro expansion when the block traversal failed
12041 : : to find a location. Otherwise it's not relevant. */
12042 : 0 : return expansion_point_location_if_in_system_header (loc);
12043 : : }
12044 : :
12045 : : return loc;
12046 : : }
12047 : :
12048 : : /* These are the hash table functions for the hash table of OPTIMIZATION_NODE
12049 : : nodes. */
12050 : :
12051 : : /* Return the hash code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
12052 : :
12053 : : hashval_t
12054 : 825850941 : cl_option_hasher::hash (tree x)
12055 : : {
12056 : 825850941 : const_tree const t = x;
12057 : :
12058 : 825850941 : if (TREE_CODE (t) == OPTIMIZATION_NODE)
12059 : 97710936 : return cl_optimization_hash (TREE_OPTIMIZATION (t));
12060 : 728140005 : else if (TREE_CODE (t) == TARGET_OPTION_NODE)
12061 : 728140005 : return cl_target_option_hash (TREE_TARGET_OPTION (t));
12062 : : else
12063 : 0 : gcc_unreachable ();
12064 : : }
12065 : :
12066 : : /* Return nonzero if the value represented by *X (an OPTIMIZATION or
12067 : : TARGET_OPTION tree node) is the same as that given by *Y, which is the
12068 : : same. */
12069 : :
12070 : : bool
12071 : 889375796 : cl_option_hasher::equal (tree x, tree y)
12072 : : {
12073 : 889375796 : const_tree const xt = x;
12074 : 889375796 : const_tree const yt = y;
12075 : :
12076 : 889375796 : if (TREE_CODE (xt) != TREE_CODE (yt))
12077 : : return false;
12078 : :
12079 : 513581822 : if (TREE_CODE (xt) == OPTIMIZATION_NODE)
12080 : 95380686 : return cl_optimization_option_eq (TREE_OPTIMIZATION (xt),
12081 : 95380686 : TREE_OPTIMIZATION (yt));
12082 : 418201136 : else if (TREE_CODE (xt) == TARGET_OPTION_NODE)
12083 : 418201136 : return cl_target_option_eq (TREE_TARGET_OPTION (xt),
12084 : 418201136 : TREE_TARGET_OPTION (yt));
12085 : : else
12086 : 0 : gcc_unreachable ();
12087 : : }
12088 : :
12089 : : /* Build an OPTIMIZATION_NODE based on the options in OPTS and OPTS_SET. */
12090 : :
12091 : : tree
12092 : 95667685 : build_optimization_node (struct gcc_options *opts,
12093 : : struct gcc_options *opts_set)
12094 : : {
12095 : 95667685 : tree t;
12096 : :
12097 : : /* Use the cache of optimization nodes. */
12098 : :
12099 : 95667685 : cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node),
12100 : : opts, opts_set);
12101 : :
12102 : 95667685 : tree *slot = cl_option_hash_table->find_slot (cl_optimization_node, INSERT);
12103 : 95667685 : t = *slot;
12104 : 95667685 : if (!t)
12105 : : {
12106 : : /* Insert this one into the hash table. */
12107 : 287262 : t = cl_optimization_node;
12108 : 287262 : *slot = t;
12109 : :
12110 : : /* Make a new node for next time round. */
12111 : 287262 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
12112 : : }
12113 : :
12114 : 95667685 : return t;
12115 : : }
12116 : :
12117 : : /* Build a TARGET_OPTION_NODE based on the options in OPTS and OPTS_SET. */
12118 : :
12119 : : tree
12120 : 74158119 : build_target_option_node (struct gcc_options *opts,
12121 : : struct gcc_options *opts_set)
12122 : : {
12123 : 74158119 : tree t;
12124 : :
12125 : : /* Use the cache of optimization nodes. */
12126 : :
12127 : 74158119 : cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node),
12128 : : opts, opts_set);
12129 : :
12130 : 74158119 : tree *slot = cl_option_hash_table->find_slot (cl_target_option_node, INSERT);
12131 : 74158119 : t = *slot;
12132 : 74158119 : if (!t)
12133 : : {
12134 : : /* Insert this one into the hash table. */
12135 : 778249 : t = cl_target_option_node;
12136 : 778249 : *slot = t;
12137 : :
12138 : : /* Make a new node for next time round. */
12139 : 778249 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
12140 : : }
12141 : :
12142 : 74158119 : return t;
12143 : : }
12144 : :
12145 : : /* Clear TREE_TARGET_GLOBALS of all TARGET_OPTION_NODE trees,
12146 : : so that they aren't saved during PCH writing. */
12147 : :
12148 : : void
12149 : 464 : prepare_target_option_nodes_for_pch (void)
12150 : : {
12151 : 464 : hash_table<cl_option_hasher>::iterator iter = cl_option_hash_table->begin ();
12152 : 2784 : for (; iter != cl_option_hash_table->end (); ++iter)
12153 : 928 : if (TREE_CODE (*iter) == TARGET_OPTION_NODE)
12154 : 464 : TREE_TARGET_GLOBALS (*iter) = NULL;
12155 : 464 : }
12156 : :
12157 : : /* Determine the "ultimate origin" of a block. */
12158 : :
12159 : : tree
12160 : 223844875 : block_ultimate_origin (const_tree block)
12161 : : {
12162 : 223844875 : tree origin = BLOCK_ABSTRACT_ORIGIN (block);
12163 : :
12164 : 223844875 : if (origin == NULL_TREE)
12165 : : return NULL_TREE;
12166 : : else
12167 : : {
12168 : 274740149 : gcc_checking_assert ((DECL_P (origin)
12169 : : && DECL_ORIGIN (origin) == origin)
12170 : : || BLOCK_ORIGIN (origin) == origin);
12171 : : return origin;
12172 : : }
12173 : : }
12174 : :
12175 : : /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates
12176 : : no instruction. */
12177 : :
12178 : : bool
12179 : 1300266107 : tree_nop_conversion_p (const_tree outer_type, const_tree inner_type)
12180 : : {
12181 : : /* Do not strip casts into or out of differing address spaces. */
12182 : 1300266107 : if (POINTER_TYPE_P (outer_type)
12183 : 1300266107 : && TYPE_ADDR_SPACE (TREE_TYPE (outer_type)) != ADDR_SPACE_GENERIC)
12184 : : {
12185 : 639 : if (!POINTER_TYPE_P (inner_type)
12186 : 639 : || (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
12187 : 558 : != TYPE_ADDR_SPACE (TREE_TYPE (inner_type))))
12188 : : return false;
12189 : : }
12190 : 1300265468 : else if (POINTER_TYPE_P (inner_type)
12191 : 1300265468 : && TYPE_ADDR_SPACE (TREE_TYPE (inner_type)) != ADDR_SPACE_GENERIC)
12192 : : {
12193 : : /* We already know that outer_type is not a pointer with
12194 : : a non-generic address space. */
12195 : : return false;
12196 : : }
12197 : :
12198 : : /* Use precision rather then machine mode when we can, which gives
12199 : : the correct answer even for submode (bit-field) types. */
12200 : 1300263171 : if ((INTEGRAL_TYPE_P (outer_type)
12201 : 431910022 : || POINTER_TYPE_P (outer_type)
12202 : 71731738 : || TREE_CODE (outer_type) == OFFSET_TYPE)
12203 : 1228541912 : && (INTEGRAL_TYPE_P (inner_type)
12204 : 436906044 : || POINTER_TYPE_P (inner_type)
12205 : 1030635 : || TREE_CODE (inner_type) == OFFSET_TYPE))
12206 : 1227534118 : return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type);
12207 : :
12208 : : /* Otherwise fall back on comparing machine modes (e.g. for
12209 : : aggregate types, floats). */
12210 : 72729053 : return TYPE_MODE (outer_type) == TYPE_MODE (inner_type);
12211 : : }
12212 : :
12213 : : /* Return true iff conversion in EXP generates no instruction. Mark
12214 : : it inline so that we fully inline into the stripping functions even
12215 : : though we have two uses of this function. */
12216 : :
12217 : : static inline bool
12218 : 17392119646 : tree_nop_conversion (const_tree exp)
12219 : : {
12220 : 17392119646 : tree outer_type, inner_type;
12221 : :
12222 : 17392119646 : if (location_wrapper_p (exp))
12223 : : return true;
12224 : 17348969120 : if (!CONVERT_EXPR_P (exp)
12225 : 16578249988 : && TREE_CODE (exp) != NON_LVALUE_EXPR)
12226 : : return false;
12227 : :
12228 : 783345143 : outer_type = TREE_TYPE (exp);
12229 : 783345143 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12230 : 783345143 : if (!inner_type || inner_type == error_mark_node)
12231 : : return false;
12232 : :
12233 : 783345143 : return tree_nop_conversion_p (outer_type, inner_type);
12234 : : }
12235 : :
12236 : : /* Return true iff conversion in EXP generates no instruction. Don't
12237 : : consider conversions changing the signedness. */
12238 : :
12239 : : static bool
12240 : 1734785701 : tree_sign_nop_conversion (const_tree exp)
12241 : : {
12242 : 1734785701 : tree outer_type, inner_type;
12243 : :
12244 : 1734785701 : if (!tree_nop_conversion (exp))
12245 : : return false;
12246 : :
12247 : 128150553 : outer_type = TREE_TYPE (exp);
12248 : 128150553 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12249 : :
12250 : 128150553 : return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type)
12251 : 128150553 : && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
12252 : : }
12253 : :
12254 : : /* Strip conversions from EXP according to tree_nop_conversion and
12255 : : return the resulting expression. */
12256 : :
12257 : : tree
12258 : 15096594487 : tree_strip_nop_conversions (tree exp)
12259 : : {
12260 : 15657333945 : while (tree_nop_conversion (exp))
12261 : 560739458 : exp = TREE_OPERAND (exp, 0);
12262 : 15096594487 : return exp;
12263 : : }
12264 : :
12265 : : /* Strip conversions from EXP according to tree_sign_nop_conversion
12266 : : and return the resulting expression. */
12267 : :
12268 : : tree
12269 : 1629652534 : tree_strip_sign_nop_conversions (tree exp)
12270 : : {
12271 : 1734785701 : while (tree_sign_nop_conversion (exp))
12272 : 105133167 : exp = TREE_OPERAND (exp, 0);
12273 : 1629652534 : return exp;
12274 : : }
12275 : :
12276 : : /* Avoid any floating point extensions from EXP. */
12277 : : tree
12278 : 81854226 : strip_float_extensions (tree exp)
12279 : : {
12280 : 81990859 : tree sub, expt, subt;
12281 : :
12282 : : /* For floating point constant look up the narrowest type that can hold
12283 : : it properly and handle it like (type)(narrowest_type)constant.
12284 : : This way we can optimize for instance a=a*2.0 where "a" is float
12285 : : but 2.0 is double constant. */
12286 : 81990859 : if (TREE_CODE (exp) == REAL_CST && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp)))
12287 : : {
12288 : 2514311 : REAL_VALUE_TYPE orig;
12289 : 2514311 : tree type = NULL;
12290 : :
12291 : 2514311 : orig = TREE_REAL_CST (exp);
12292 : 2514311 : if (TYPE_PRECISION (TREE_TYPE (exp)) > TYPE_PRECISION (float_type_node)
12293 : 2514311 : && exact_real_truncate (TYPE_MODE (float_type_node), &orig))
12294 : 140579 : type = float_type_node;
12295 : 2373732 : else if (TYPE_PRECISION (TREE_TYPE (exp))
12296 : 2373732 : > TYPE_PRECISION (double_type_node)
12297 : 2373732 : && exact_real_truncate (TYPE_MODE (double_type_node), &orig))
12298 : 35199 : type = double_type_node;
12299 : 2514311 : if (type)
12300 : 175778 : return build_real_truncate (type, orig);
12301 : : }
12302 : :
12303 : 81815081 : if (!CONVERT_EXPR_P (exp))
12304 : : return exp;
12305 : :
12306 : 3914068 : sub = TREE_OPERAND (exp, 0);
12307 : 3914068 : subt = TREE_TYPE (sub);
12308 : 3914068 : expt = TREE_TYPE (exp);
12309 : :
12310 : 3914068 : if (!FLOAT_TYPE_P (subt))
12311 : : return exp;
12312 : :
12313 : 480757 : if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_FLOAT_TYPE_P (subt))
12314 : : return exp;
12315 : :
12316 : 160617 : if (element_precision (subt) > element_precision (expt))
12317 : : return exp;
12318 : :
12319 : : return strip_float_extensions (sub);
12320 : : }
12321 : :
12322 : : /* Strip out all handled components that produce invariant
12323 : : offsets. */
12324 : :
12325 : : const_tree
12326 : 5741408081 : strip_invariant_refs (const_tree op)
12327 : : {
12328 : 6656579154 : while (handled_component_p (op))
12329 : : {
12330 : 925731946 : switch (TREE_CODE (op))
12331 : : {
12332 : 158867164 : case ARRAY_REF:
12333 : 158867164 : case ARRAY_RANGE_REF:
12334 : 158867164 : if (!is_gimple_constant (TREE_OPERAND (op, 1))
12335 : 149715598 : || TREE_OPERAND (op, 2) != NULL_TREE
12336 : 148438488 : || TREE_OPERAND (op, 3) != NULL_TREE)
12337 : : return NULL;
12338 : : break;
12339 : :
12340 : 766672584 : case COMPONENT_REF:
12341 : 766672584 : if (TREE_OPERAND (op, 2) != NULL_TREE)
12342 : : return NULL;
12343 : : break;
12344 : :
12345 : 915171073 : default:;
12346 : : }
12347 : 915171073 : op = TREE_OPERAND (op, 0);
12348 : : }
12349 : :
12350 : : return op;
12351 : : }
12352 : :
12353 : : /* Strip handled components with zero offset from OP. */
12354 : :
12355 : : tree
12356 : 561846 : strip_zero_offset_components (tree op)
12357 : : {
12358 : 561846 : while (TREE_CODE (op) == COMPONENT_REF
12359 : 429499 : && integer_zerop (DECL_FIELD_OFFSET (TREE_OPERAND (op, 1)))
12360 : 1097331 : && integer_zerop (DECL_FIELD_BIT_OFFSET (TREE_OPERAND (op, 1))))
12361 : 174703 : op = TREE_OPERAND (op, 0);
12362 : 561846 : return op;
12363 : : }
12364 : :
12365 : : static GTY(()) tree gcc_eh_personality_decl;
12366 : :
12367 : : /* Return the GCC personality function decl. */
12368 : :
12369 : : tree
12370 : 395 : lhd_gcc_personality (void)
12371 : : {
12372 : 395 : if (!gcc_eh_personality_decl)
12373 : 153 : gcc_eh_personality_decl = build_personality_function ("gcc");
12374 : 395 : return gcc_eh_personality_decl;
12375 : : }
12376 : :
12377 : : /* TARGET is a call target of GIMPLE call statement
12378 : : (obtained by gimple_call_fn). Return true if it is
12379 : : OBJ_TYPE_REF representing an virtual call of C++ method.
12380 : : (As opposed to OBJ_TYPE_REF representing objc calls
12381 : : through a cast where middle-end devirtualization machinery
12382 : : can't apply.) FOR_DUMP_P is true when being called from
12383 : : the dump routines. */
12384 : :
12385 : : bool
12386 : 27538943 : virtual_method_call_p (const_tree target, bool for_dump_p)
12387 : : {
12388 : 27538943 : if (TREE_CODE (target) != OBJ_TYPE_REF)
12389 : : return false;
12390 : 1140046 : tree t = TREE_TYPE (target);
12391 : 1140046 : gcc_checking_assert (TREE_CODE (t) == POINTER_TYPE);
12392 : 1140046 : t = TREE_TYPE (t);
12393 : 1140046 : if (TREE_CODE (t) == FUNCTION_TYPE)
12394 : : return false;
12395 : 1138938 : gcc_checking_assert (TREE_CODE (t) == METHOD_TYPE);
12396 : : /* If we do not have BINFO associated, it means that type was built
12397 : : without devirtualization enabled. Do not consider this a virtual
12398 : : call. */
12399 : 1138938 : if (!TYPE_BINFO (obj_type_ref_class (target, for_dump_p)))
12400 : : return false;
12401 : : return true;
12402 : : }
12403 : :
12404 : : /* Lookup sub-BINFO of BINFO of TYPE at offset POS. */
12405 : :
12406 : : static tree
12407 : 75 : lookup_binfo_at_offset (tree binfo, tree type, HOST_WIDE_INT pos)
12408 : : {
12409 : 75 : unsigned int i;
12410 : 75 : tree base_binfo, b;
12411 : :
12412 : 84 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12413 : 75 : if (pos == tree_to_shwi (BINFO_OFFSET (base_binfo))
12414 : 75 : && types_same_for_odr (TREE_TYPE (base_binfo), type))
12415 : : return base_binfo;
12416 : 50 : else if ((b = lookup_binfo_at_offset (base_binfo, type, pos)) != NULL)
12417 : : return b;
12418 : : return NULL;
12419 : : }
12420 : :
12421 : : /* Try to find a base info of BINFO that would have its field decl at offset
12422 : : OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
12423 : : found, return, otherwise return NULL_TREE. */
12424 : :
12425 : : tree
12426 : 374510 : get_binfo_at_offset (tree binfo, poly_int64 offset, tree expected_type)
12427 : : {
12428 : 374510 : tree type = BINFO_TYPE (binfo);
12429 : :
12430 : 1046368 : while (true)
12431 : : {
12432 : 710439 : HOST_WIDE_INT pos, size;
12433 : 710439 : tree fld;
12434 : 710439 : int i;
12435 : :
12436 : 710439 : if (types_same_for_odr (type, expected_type))
12437 : 374510 : return binfo;
12438 : 335929 : if (maybe_lt (offset, 0))
12439 : : return NULL_TREE;
12440 : :
12441 : 2096894 : for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
12442 : : {
12443 : 2096894 : if (TREE_CODE (fld) != FIELD_DECL || !DECL_ARTIFICIAL (fld))
12444 : 1760789 : continue;
12445 : :
12446 : 336105 : pos = int_bit_position (fld);
12447 : 336105 : size = tree_to_uhwi (DECL_SIZE (fld));
12448 : 2097070 : if (known_in_range_p (offset, pos, size))
12449 : : break;
12450 : : }
12451 : 335929 : if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE)
12452 : : return NULL_TREE;
12453 : :
12454 : : /* Offset 0 indicates the primary base, whose vtable contents are
12455 : : represented in the binfo for the derived class. */
12456 : 335929 : else if (maybe_ne (offset, 0))
12457 : : {
12458 : 187 : tree found_binfo = NULL, base_binfo;
12459 : : /* Offsets in BINFO are in bytes relative to the whole structure
12460 : : while POS is in bits relative to the containing field. */
12461 : 187 : int binfo_offset = (tree_to_shwi (BINFO_OFFSET (binfo)) + pos
12462 : 187 : / BITS_PER_UNIT);
12463 : :
12464 : 353 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12465 : 328 : if (tree_to_shwi (BINFO_OFFSET (base_binfo)) == binfo_offset
12466 : 328 : && types_same_for_odr (TREE_TYPE (base_binfo), TREE_TYPE (fld)))
12467 : : {
12468 : : found_binfo = base_binfo;
12469 : : break;
12470 : : }
12471 : 187 : if (found_binfo)
12472 : : binfo = found_binfo;
12473 : : else
12474 : 25 : binfo = lookup_binfo_at_offset (binfo, TREE_TYPE (fld),
12475 : : binfo_offset);
12476 : : }
12477 : :
12478 : 335929 : type = TREE_TYPE (fld);
12479 : 335929 : offset -= pos;
12480 : 335929 : }
12481 : : }
12482 : :
12483 : : /* PR 84195: Replace control characters in "unescaped" with their
12484 : : escaped equivalents. Allow newlines if -fmessage-length has
12485 : : been set to a non-zero value. This is done here, rather than
12486 : : where the attribute is recorded as the message length can
12487 : : change between these two locations. */
12488 : :
12489 : : void
12490 : 129958 : escaped_string::escape (const char *unescaped)
12491 : : {
12492 : 129958 : char *escaped;
12493 : 129958 : size_t i, new_i, len;
12494 : :
12495 : 129958 : if (m_owned)
12496 : 8 : free (m_str);
12497 : :
12498 : 129958 : m_str = const_cast<char *> (unescaped);
12499 : 129958 : m_owned = false;
12500 : :
12501 : 129958 : if (unescaped == NULL || *unescaped == 0)
12502 : : return;
12503 : :
12504 : 129950 : len = strlen (unescaped);
12505 : 129950 : escaped = NULL;
12506 : 129950 : new_i = 0;
12507 : :
12508 : 3803272 : for (i = 0; i < len; i++)
12509 : : {
12510 : 3673322 : char c = unescaped[i];
12511 : :
12512 : 3673322 : if (!ISCNTRL (c))
12513 : : {
12514 : 3673237 : if (escaped)
12515 : 33 : escaped[new_i++] = c;
12516 : 3673237 : continue;
12517 : : }
12518 : :
12519 : 85 : if (c != '\n' || !pp_is_wrapping_line (global_dc->get_reference_printer ()))
12520 : : {
12521 : 77 : if (escaped == NULL)
12522 : : {
12523 : : /* We only allocate space for a new string if we
12524 : : actually encounter a control character that
12525 : : needs replacing. */
12526 : 19 : escaped = (char *) xmalloc (len * 2 + 1);
12527 : 19 : strncpy (escaped, unescaped, i);
12528 : 19 : new_i = i;
12529 : : }
12530 : :
12531 : 77 : escaped[new_i++] = '\\';
12532 : :
12533 : 77 : switch (c)
12534 : : {
12535 : 8 : case '\a': escaped[new_i++] = 'a'; break;
12536 : 8 : case '\b': escaped[new_i++] = 'b'; break;
12537 : 8 : case '\f': escaped[new_i++] = 'f'; break;
12538 : 15 : case '\n': escaped[new_i++] = 'n'; break;
12539 : 15 : case '\r': escaped[new_i++] = 'r'; break;
12540 : 15 : case '\t': escaped[new_i++] = 't'; break;
12541 : 8 : case '\v': escaped[new_i++] = 'v'; break;
12542 : 0 : default: escaped[new_i++] = '?'; break;
12543 : : }
12544 : : }
12545 : 8 : else if (escaped)
12546 : 4 : escaped[new_i++] = c;
12547 : : }
12548 : :
12549 : 129950 : if (escaped)
12550 : : {
12551 : 19 : escaped[new_i] = 0;
12552 : 19 : m_str = escaped;
12553 : 19 : m_owned = true;
12554 : : }
12555 : : }
12556 : :
12557 : : /* Warn about a use of an identifier which was marked deprecated. Returns
12558 : : whether a warning was given. */
12559 : :
12560 : : bool
12561 : 1256335 : warn_deprecated_use (tree node, tree attr)
12562 : : {
12563 : 1256335 : escaped_string msg;
12564 : :
12565 : 1256335 : if (node == 0 || !warn_deprecated_decl)
12566 : : return false;
12567 : :
12568 : 1251152 : if (!attr)
12569 : : {
12570 : 1141732 : if (DECL_P (node))
12571 : 1141604 : attr = DECL_ATTRIBUTES (node);
12572 : 128 : else if (TYPE_P (node))
12573 : : {
12574 : 128 : tree decl = TYPE_STUB_DECL (node);
12575 : 128 : if (decl)
12576 : 104 : attr = TYPE_ATTRIBUTES (TREE_TYPE (decl));
12577 : 24 : else if ((decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (node)))
12578 : : != NULL_TREE)
12579 : : {
12580 : 6 : node = TREE_TYPE (decl);
12581 : 6 : attr = TYPE_ATTRIBUTES (node);
12582 : : }
12583 : : }
12584 : : }
12585 : :
12586 : 1141732 : if (attr)
12587 : 129647 : attr = lookup_attribute ("deprecated", attr);
12588 : :
12589 : 129647 : if (attr)
12590 : 129638 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12591 : :
12592 : 1251152 : bool w = false;
12593 : 1251152 : if (DECL_P (node))
12594 : : {
12595 : 1251014 : auto_diagnostic_group d;
12596 : 1251014 : if (msg)
12597 : 129589 : w = warning (OPT_Wdeprecated_declarations,
12598 : : "%qD is deprecated: %s", node, (const char *) msg);
12599 : : else
12600 : 1121425 : w = warning (OPT_Wdeprecated_declarations,
12601 : : "%qD is deprecated", node);
12602 : 1251014 : if (w)
12603 : 778 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12604 : 1251014 : }
12605 : 138 : else if (TYPE_P (node))
12606 : : {
12607 : 138 : tree what = NULL_TREE;
12608 : 138 : tree decl = TYPE_STUB_DECL (node);
12609 : :
12610 : 138 : if (TYPE_NAME (node))
12611 : : {
12612 : 133 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12613 : 10 : what = TYPE_NAME (node);
12614 : 123 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12615 : 123 : && DECL_NAME (TYPE_NAME (node)))
12616 : 123 : what = DECL_NAME (TYPE_NAME (node));
12617 : : }
12618 : :
12619 : 138 : auto_diagnostic_group d;
12620 : 138 : if (what)
12621 : : {
12622 : 133 : if (msg)
12623 : 47 : w = warning (OPT_Wdeprecated_declarations,
12624 : : "%qE is deprecated: %s", what, (const char *) msg);
12625 : : else
12626 : 86 : w = warning (OPT_Wdeprecated_declarations,
12627 : : "%qE is deprecated", what);
12628 : : }
12629 : : else
12630 : : {
12631 : 5 : if (msg)
12632 : 2 : w = warning (OPT_Wdeprecated_declarations,
12633 : : "type is deprecated: %s", (const char *) msg);
12634 : : else
12635 : 3 : w = warning (OPT_Wdeprecated_declarations,
12636 : : "type is deprecated");
12637 : : }
12638 : :
12639 : 138 : if (w && decl)
12640 : 111 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12641 : 138 : }
12642 : :
12643 : : return w;
12644 : 1256335 : }
12645 : :
12646 : : /* Error out with an identifier which was marked 'unavailable'. */
12647 : : void
12648 : 364 : error_unavailable_use (tree node, tree attr)
12649 : : {
12650 : 364 : escaped_string msg;
12651 : :
12652 : 364 : if (node == 0)
12653 : 0 : return;
12654 : :
12655 : 364 : if (!attr)
12656 : : {
12657 : 354 : if (DECL_P (node))
12658 : 294 : attr = DECL_ATTRIBUTES (node);
12659 : 60 : else if (TYPE_P (node))
12660 : : {
12661 : 60 : tree decl = TYPE_STUB_DECL (node);
12662 : 60 : if (decl)
12663 : 51 : attr = lookup_attribute ("unavailable",
12664 : 51 : TYPE_ATTRIBUTES (TREE_TYPE (decl)));
12665 : : }
12666 : : }
12667 : :
12668 : 354 : if (attr)
12669 : 152 : attr = lookup_attribute ("unavailable", attr);
12670 : :
12671 : 152 : if (attr)
12672 : 152 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12673 : :
12674 : 364 : if (DECL_P (node))
12675 : : {
12676 : 294 : auto_diagnostic_group d;
12677 : 294 : if (msg)
12678 : 117 : error ("%qD is unavailable: %s", node, (const char *) msg);
12679 : : else
12680 : 177 : error ("%qD is unavailable", node);
12681 : 294 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12682 : 294 : }
12683 : 70 : else if (TYPE_P (node))
12684 : : {
12685 : 70 : tree what = NULL_TREE;
12686 : 70 : tree decl = TYPE_STUB_DECL (node);
12687 : :
12688 : 70 : if (TYPE_NAME (node))
12689 : : {
12690 : 66 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12691 : 4 : what = TYPE_NAME (node);
12692 : 62 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12693 : 62 : && DECL_NAME (TYPE_NAME (node)))
12694 : 62 : what = DECL_NAME (TYPE_NAME (node));
12695 : : }
12696 : :
12697 : 70 : auto_diagnostic_group d;
12698 : 70 : if (what)
12699 : : {
12700 : 66 : if (msg)
12701 : 33 : error ("%qE is unavailable: %s", what, (const char *) msg);
12702 : : else
12703 : 33 : error ("%qE is unavailable", what);
12704 : : }
12705 : : else
12706 : : {
12707 : 4 : if (msg)
12708 : 2 : error ("type is unavailable: %s", (const char *) msg);
12709 : : else
12710 : 2 : error ("type is unavailable");
12711 : : }
12712 : :
12713 : 70 : if (decl)
12714 : 52 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12715 : 70 : }
12716 : 364 : }
12717 : :
12718 : : /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
12719 : : somewhere in it. */
12720 : :
12721 : : bool
12722 : 5635007 : contains_bitfld_component_ref_p (const_tree ref)
12723 : : {
12724 : 11462452 : while (handled_component_p (ref))
12725 : : {
12726 : 5853590 : if (TREE_CODE (ref) == COMPONENT_REF
12727 : 5853590 : && DECL_BIT_FIELD (TREE_OPERAND (ref, 1)))
12728 : : return true;
12729 : 5827445 : ref = TREE_OPERAND (ref, 0);
12730 : : }
12731 : :
12732 : : return false;
12733 : : }
12734 : :
12735 : : /* Try to determine whether a TRY_CATCH expression can fall through.
12736 : : This is a subroutine of block_may_fallthru. */
12737 : :
12738 : : static bool
12739 : 1 : try_catch_may_fallthru (const_tree stmt)
12740 : : {
12741 : 1 : tree_stmt_iterator i;
12742 : :
12743 : : /* If the TRY block can fall through, the whole TRY_CATCH can
12744 : : fall through. */
12745 : 1 : if (block_may_fallthru (TREE_OPERAND (stmt, 0)))
12746 : : return true;
12747 : :
12748 : 1 : switch (TREE_CODE (TREE_OPERAND (stmt, 1)))
12749 : : {
12750 : 0 : case CATCH_EXPR:
12751 : : /* See below. */
12752 : 0 : return block_may_fallthru (CATCH_BODY (TREE_OPERAND (stmt, 1)));
12753 : :
12754 : 0 : case EH_FILTER_EXPR:
12755 : : /* See below. */
12756 : 0 : return block_may_fallthru (EH_FILTER_FAILURE (TREE_OPERAND (stmt, 1)));
12757 : :
12758 : 0 : case STATEMENT_LIST:
12759 : 0 : break;
12760 : :
12761 : : default:
12762 : : /* See below. */
12763 : : return false;
12764 : : }
12765 : :
12766 : 0 : i = tsi_start (TREE_OPERAND (stmt, 1));
12767 : 0 : switch (TREE_CODE (tsi_stmt (i)))
12768 : : {
12769 : : case CATCH_EXPR:
12770 : : /* We expect to see a sequence of CATCH_EXPR trees, each with a
12771 : : catch expression and a body. The whole TRY_CATCH may fall
12772 : : through iff any of the catch bodies falls through. */
12773 : 0 : for (; !tsi_end_p (i); tsi_next (&i))
12774 : : {
12775 : 0 : if (block_may_fallthru (CATCH_BODY (tsi_stmt (i))))
12776 : : return true;
12777 : : }
12778 : : return false;
12779 : :
12780 : 0 : case EH_FILTER_EXPR:
12781 : : /* The exception filter expression only matters if there is an
12782 : : exception. If the exception does not match EH_FILTER_TYPES,
12783 : : we will execute EH_FILTER_FAILURE, and we will fall through
12784 : : if that falls through. If the exception does match
12785 : : EH_FILTER_TYPES, the stack unwinder will continue up the
12786 : : stack, so we will not fall through. We don't know whether we
12787 : : will throw an exception which matches EH_FILTER_TYPES or not,
12788 : : so we just ignore EH_FILTER_TYPES and assume that we might
12789 : : throw an exception which doesn't match. */
12790 : 0 : return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i)));
12791 : :
12792 : : default:
12793 : : /* This case represents statements to be executed when an
12794 : : exception occurs. Those statements are implicitly followed
12795 : : by a RESX statement to resume execution after the exception.
12796 : : So in this case the TRY_CATCH never falls through. */
12797 : : return false;
12798 : : }
12799 : : }
12800 : :
12801 : : /* Try to determine if we can fall out of the bottom of BLOCK. This guess
12802 : : need not be 100% accurate; simply be conservative and return true if we
12803 : : don't know. This is used only to avoid stupidly generating extra code.
12804 : : If we're wrong, we'll just delete the extra code later. */
12805 : :
12806 : : bool
12807 : 6185434 : block_may_fallthru (const_tree block)
12808 : : {
12809 : : /* This CONST_CAST is okay because expr_last returns its argument
12810 : : unmodified and we assign it to a const_tree. */
12811 : 7301232 : const_tree stmt = expr_last (CONST_CAST_TREE (block));
12812 : :
12813 : 7301232 : switch (stmt ? TREE_CODE (stmt) : ERROR_MARK)
12814 : : {
12815 : : case GOTO_EXPR:
12816 : : case RETURN_EXPR:
12817 : : /* Easy cases. If the last statement of the block implies
12818 : : control transfer, then we can't fall through. */
12819 : : return false;
12820 : :
12821 : 8 : case SWITCH_EXPR:
12822 : : /* If there is a default: label or case labels cover all possible
12823 : : SWITCH_COND values, then the SWITCH_EXPR will transfer control
12824 : : to some case label in all cases and all we care is whether the
12825 : : SWITCH_BODY falls through. */
12826 : 8 : if (SWITCH_ALL_CASES_P (stmt))
12827 : 7 : return block_may_fallthru (SWITCH_BODY (stmt));
12828 : : return true;
12829 : :
12830 : 19773 : case COND_EXPR:
12831 : 19773 : if (block_may_fallthru (COND_EXPR_THEN (stmt)))
12832 : : return true;
12833 : 2781 : return block_may_fallthru (COND_EXPR_ELSE (stmt));
12834 : :
12835 : 541886 : case BIND_EXPR:
12836 : 541886 : return block_may_fallthru (BIND_EXPR_BODY (stmt));
12837 : :
12838 : 1 : case TRY_CATCH_EXPR:
12839 : 1 : return try_catch_may_fallthru (stmt);
12840 : :
12841 : 141 : case TRY_FINALLY_EXPR:
12842 : : /* The finally clause is always executed after the try clause,
12843 : : so if it does not fall through, then the try-finally will not
12844 : : fall through. Otherwise, if the try clause does not fall
12845 : : through, then when the finally clause falls through it will
12846 : : resume execution wherever the try clause was going. So the
12847 : : whole try-finally will only fall through if both the try
12848 : : clause and the finally clause fall through. */
12849 : 141 : return (block_may_fallthru (TREE_OPERAND (stmt, 0))
12850 : 141 : && block_may_fallthru (TREE_OPERAND (stmt, 1)));
12851 : :
12852 : 0 : case EH_ELSE_EXPR:
12853 : 0 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
12854 : :
12855 : 88369 : case MODIFY_EXPR:
12856 : 88369 : if (TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR)
12857 : 1534 : stmt = TREE_OPERAND (stmt, 1);
12858 : : else
12859 : : return true;
12860 : : /* FALLTHRU */
12861 : :
12862 : 407632 : case CALL_EXPR:
12863 : : /* Functions that do not return do not fall through. */
12864 : 407632 : return (call_expr_flags (stmt) & ECF_NORETURN) == 0;
12865 : :
12866 : 571114 : case CLEANUP_POINT_EXPR:
12867 : 571114 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
12868 : :
12869 : 10 : case TARGET_EXPR:
12870 : 10 : return block_may_fallthru (TREE_OPERAND (stmt, 1));
12871 : :
12872 : : case ERROR_MARK:
12873 : : return true;
12874 : :
12875 : 3952764 : default:
12876 : 3952764 : return lang_hooks.block_may_fallthru (stmt);
12877 : : }
12878 : : }
12879 : :
12880 : : /* True if we are using EH to handle cleanups. */
12881 : : static bool using_eh_for_cleanups_flag = false;
12882 : :
12883 : : /* This routine is called from front ends to indicate eh should be used for
12884 : : cleanups. */
12885 : : void
12886 : 119345 : using_eh_for_cleanups (void)
12887 : : {
12888 : 119345 : using_eh_for_cleanups_flag = true;
12889 : 119345 : }
12890 : :
12891 : : /* Query whether EH is used for cleanups. */
12892 : : bool
12893 : 1703132 : using_eh_for_cleanups_p (void)
12894 : : {
12895 : 1703132 : return using_eh_for_cleanups_flag;
12896 : : }
12897 : :
12898 : : /* Wrapper for tree_code_name to ensure that tree code is valid */
12899 : : const char *
12900 : 14259447090 : get_tree_code_name (enum tree_code code)
12901 : : {
12902 : 14259447090 : const char *invalid = "<invalid tree code>";
12903 : :
12904 : : /* The tree_code enum promotes to signed, but we could be getting
12905 : : invalid values, so force an unsigned comparison. */
12906 : 14259447090 : if (unsigned (code) >= MAX_TREE_CODES)
12907 : : {
12908 : 0 : if ((unsigned)code == 0xa5a5)
12909 : : return "ggc_freed";
12910 : 0 : return invalid;
12911 : : }
12912 : :
12913 : 14259447090 : return tree_code_name[code];
12914 : : }
12915 : :
12916 : : /* Drops the TREE_OVERFLOW flag from T. */
12917 : :
12918 : : tree
12919 : 40121 : drop_tree_overflow (tree t)
12920 : : {
12921 : 40121 : gcc_checking_assert (TREE_OVERFLOW (t));
12922 : :
12923 : : /* For tree codes with a sharing machinery re-build the result. */
12924 : 40121 : if (poly_int_tree_p (t))
12925 : 40109 : return wide_int_to_tree (TREE_TYPE (t), wi::to_poly_wide (t));
12926 : :
12927 : : /* For VECTOR_CST, remove the overflow bits from the encoded elements
12928 : : and canonicalize the result. */
12929 : 12 : if (TREE_CODE (t) == VECTOR_CST)
12930 : : {
12931 : 0 : tree_vector_builder builder;
12932 : 0 : builder.new_unary_operation (TREE_TYPE (t), t, true);
12933 : 0 : unsigned int count = builder.encoded_nelts ();
12934 : 0 : for (unsigned int i = 0; i < count; ++i)
12935 : : {
12936 : 0 : tree elt = VECTOR_CST_ELT (t, i);
12937 : 0 : if (TREE_OVERFLOW (elt))
12938 : 0 : elt = drop_tree_overflow (elt);
12939 : 0 : builder.quick_push (elt);
12940 : : }
12941 : 0 : return builder.build ();
12942 : 0 : }
12943 : :
12944 : : /* Otherwise, as all tcc_constants are possibly shared, copy the node
12945 : : and drop the flag. */
12946 : 12 : t = copy_node (t);
12947 : 12 : TREE_OVERFLOW (t) = 0;
12948 : :
12949 : : /* For constants that contain nested constants, drop the flag
12950 : : from those as well. */
12951 : 12 : if (TREE_CODE (t) == COMPLEX_CST)
12952 : : {
12953 : 12 : if (TREE_OVERFLOW (TREE_REALPART (t)))
12954 : 12 : TREE_REALPART (t) = drop_tree_overflow (TREE_REALPART (t));
12955 : 12 : if (TREE_OVERFLOW (TREE_IMAGPART (t)))
12956 : 0 : TREE_IMAGPART (t) = drop_tree_overflow (TREE_IMAGPART (t));
12957 : : }
12958 : :
12959 : : return t;
12960 : : }
12961 : :
12962 : : /* Given a memory reference expression T, return its base address.
12963 : : The base address of a memory reference expression is the main
12964 : : object being referenced. For instance, the base address for
12965 : : 'array[i].fld[j]' is 'array'. You can think of this as stripping
12966 : : away the offset part from a memory address.
12967 : :
12968 : : This function calls handled_component_p to strip away all the inner
12969 : : parts of the memory reference until it reaches the base object. */
12970 : :
12971 : : tree
12972 : 3132233197 : get_base_address (tree t)
12973 : : {
12974 : 3132233197 : if (TREE_CODE (t) == WITH_SIZE_EXPR)
12975 : 971 : t = TREE_OPERAND (t, 0);
12976 : 3872860637 : while (handled_component_p (t))
12977 : 740627440 : t = TREE_OPERAND (t, 0);
12978 : :
12979 : 3132233197 : if ((TREE_CODE (t) == MEM_REF
12980 : 3132233197 : || TREE_CODE (t) == TARGET_MEM_REF)
12981 : 3132233197 : && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
12982 : 151504877 : t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
12983 : :
12984 : 3132233197 : return t;
12985 : : }
12986 : :
12987 : : /* Return a tree of sizetype representing the size, in bytes, of the element
12988 : : of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
12989 : :
12990 : : tree
12991 : 757464078 : array_ref_element_size (tree exp)
12992 : : {
12993 : 757464078 : tree aligned_size = TREE_OPERAND (exp, 3);
12994 : 757464078 : tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
12995 : 757464078 : location_t loc = EXPR_LOCATION (exp);
12996 : :
12997 : : /* If a size was specified in the ARRAY_REF, it's the size measured
12998 : : in alignment units of the element type. So multiply by that value. */
12999 : 757464078 : if (aligned_size)
13000 : : {
13001 : : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13002 : : sizetype from another type of the same width and signedness. */
13003 : 375283 : if (TREE_TYPE (aligned_size) != sizetype)
13004 : 2026 : aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
13005 : 375283 : return size_binop_loc (loc, MULT_EXPR, aligned_size,
13006 : 375283 : size_int (TYPE_ALIGN_UNIT (elmt_type)));
13007 : : }
13008 : :
13009 : : /* Otherwise, take the size from that of the element type. Substitute
13010 : : any PLACEHOLDER_EXPR that we have. */
13011 : : else
13012 : 757088795 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
13013 : : }
13014 : :
13015 : : /* Return a tree representing the lower bound of the array mentioned in
13016 : : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13017 : :
13018 : : tree
13019 : 1055416608 : array_ref_low_bound (tree exp)
13020 : : {
13021 : 1055416608 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13022 : :
13023 : : /* If a lower bound is specified in EXP, use it. */
13024 : 1055416608 : if (TREE_OPERAND (exp, 2))
13025 : 1104272 : return TREE_OPERAND (exp, 2);
13026 : :
13027 : : /* Otherwise, if there is a domain type and it has a lower bound, use it,
13028 : : substituting for a PLACEHOLDER_EXPR as needed. */
13029 : 1054312336 : if (domain_type && TYPE_MIN_VALUE (domain_type))
13030 : 1053415170 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
13031 : :
13032 : : /* Otherwise, return a zero of the appropriate type. */
13033 : 897166 : tree idxtype = TREE_TYPE (TREE_OPERAND (exp, 1));
13034 : 897166 : return (idxtype == error_mark_node
13035 : 897166 : ? integer_zero_node : build_int_cst (idxtype, 0));
13036 : : }
13037 : :
13038 : : /* Return a tree representing the upper bound of the array mentioned in
13039 : : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13040 : :
13041 : : tree
13042 : 252299462 : array_ref_up_bound (tree exp)
13043 : : {
13044 : 252299462 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13045 : :
13046 : : /* If there is a domain type and it has an upper bound, use it, substituting
13047 : : for a PLACEHOLDER_EXPR as needed. */
13048 : 252299462 : if (domain_type && TYPE_MAX_VALUE (domain_type))
13049 : 251506441 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
13050 : :
13051 : : /* Otherwise fail. */
13052 : : return NULL_TREE;
13053 : : }
13054 : :
13055 : : /* Returns true if REF is an array reference, a component reference,
13056 : : or a memory reference to an array whose actual size might be larger
13057 : : than its upper bound implies, there are multiple cases:
13058 : : A. a ref to a flexible array member at the end of a structure;
13059 : : B. a ref to an array with a different type against the original decl;
13060 : : for example:
13061 : :
13062 : : short a[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
13063 : : (*((char(*)[16])&a[0]))[i+8]
13064 : :
13065 : : C. a ref to an array that was passed as a parameter;
13066 : : for example:
13067 : :
13068 : : int test (uint8_t *p, uint32_t t[1][1], int n) {
13069 : : for (int i = 0; i < 4; i++, p++)
13070 : : t[i][0] = ...;
13071 : :
13072 : : If non-null, set IS_TRAILING_ARRAY to true if the ref is the above case A.
13073 : : */
13074 : :
13075 : : bool
13076 : 72661227 : array_ref_flexible_size_p (tree ref, bool *is_trailing_array /* = NULL */)
13077 : : {
13078 : : /* The TYPE for this array referece. */
13079 : 72661227 : tree atype = NULL_TREE;
13080 : : /* The FIELD_DECL for the array field in the containing structure. */
13081 : 72661227 : tree afield_decl = NULL_TREE;
13082 : : /* Whether this array is the trailing array of a structure. */
13083 : 72661227 : bool is_trailing_array_tmp = false;
13084 : 72661227 : if (!is_trailing_array)
13085 : 72581620 : is_trailing_array = &is_trailing_array_tmp;
13086 : :
13087 : 72661227 : if (TREE_CODE (ref) == ARRAY_REF
13088 : 72661227 : || TREE_CODE (ref) == ARRAY_RANGE_REF)
13089 : : {
13090 : 72433589 : atype = TREE_TYPE (TREE_OPERAND (ref, 0));
13091 : 72433589 : ref = TREE_OPERAND (ref, 0);
13092 : : }
13093 : 227638 : else if (TREE_CODE (ref) == COMPONENT_REF
13094 : 227638 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 1))) == ARRAY_TYPE)
13095 : : {
13096 : 164326 : atype = TREE_TYPE (TREE_OPERAND (ref, 1));
13097 : 164326 : afield_decl = TREE_OPERAND (ref, 1);
13098 : : }
13099 : 63312 : else if (TREE_CODE (ref) == MEM_REF)
13100 : : {
13101 : 8300 : tree arg = TREE_OPERAND (ref, 0);
13102 : 8300 : if (TREE_CODE (arg) == ADDR_EXPR)
13103 : 8300 : arg = TREE_OPERAND (arg, 0);
13104 : 8300 : tree argtype = TREE_TYPE (arg);
13105 : 8300 : if (TREE_CODE (argtype) == RECORD_TYPE)
13106 : : {
13107 : 174 : if (tree fld = last_field (argtype))
13108 : : {
13109 : 174 : atype = TREE_TYPE (fld);
13110 : 174 : afield_decl = fld;
13111 : 174 : if (TREE_CODE (atype) != ARRAY_TYPE)
13112 : : return false;
13113 : 174 : if (VAR_P (arg) && DECL_SIZE (fld))
13114 : : return false;
13115 : : }
13116 : : else
13117 : : return false;
13118 : : }
13119 : : else
13120 : : return false;
13121 : : }
13122 : : else
13123 : : return false;
13124 : :
13125 : 72598040 : if (TREE_CODE (ref) == STRING_CST)
13126 : : return false;
13127 : :
13128 : : tree ref_to_array = ref;
13129 : 89226184 : while (handled_component_p (ref))
13130 : : {
13131 : : /* If the reference chain contains a component reference to a
13132 : : non-union type and there follows another field the reference
13133 : : is not at the end of a structure. */
13134 : 19533959 : if (TREE_CODE (ref) == COMPONENT_REF)
13135 : : {
13136 : 18421413 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
13137 : : {
13138 : 17188368 : tree nextf = DECL_CHAIN (TREE_OPERAND (ref, 1));
13139 : 25278919 : while (nextf && TREE_CODE (nextf) != FIELD_DECL)
13140 : 8090551 : nextf = DECL_CHAIN (nextf);
13141 : : if (nextf)
13142 : : return false;
13143 : : }
13144 : : }
13145 : : /* If we have a multi-dimensional array we do not consider
13146 : : a non-innermost dimension as flex array if the whole
13147 : : multi-dimensional array is at struct end.
13148 : : Same for an array of aggregates with a trailing array
13149 : : member. */
13150 : 1112546 : else if (TREE_CODE (ref) == ARRAY_REF)
13151 : : return false;
13152 : 179211 : else if (TREE_CODE (ref) == ARRAY_RANGE_REF)
13153 : : ;
13154 : : /* If we view an underlying object as sth else then what we
13155 : : gathered up to now is what we have to rely on. */
13156 : 179201 : else if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
13157 : : break;
13158 : : else
13159 : 0 : gcc_unreachable ();
13160 : :
13161 : 16630403 : ref = TREE_OPERAND (ref, 0);
13162 : : }
13163 : :
13164 : 69871426 : gcc_assert (!afield_decl
13165 : : || (afield_decl && TREE_CODE (afield_decl) == FIELD_DECL));
13166 : :
13167 : : /* The array now is at struct end. Treat flexible array member as
13168 : : always subject to extend, even into just padding constrained by
13169 : : an underlying decl. */
13170 : 69871426 : if (! TYPE_SIZE (atype)
13171 : 67567386 : || ! TYPE_DOMAIN (atype)
13172 : 137438812 : || ! TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13173 : : {
13174 : 2309630 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13175 : 2388963 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13176 : : }
13177 : :
13178 : : /* If the reference is based on a declared entity, the size of the array
13179 : : is constrained by its given domain. (Do not trust commons PR/69368). */
13180 : 67561796 : ref = get_base_address (ref);
13181 : 67561796 : if (ref
13182 : 67561796 : && DECL_P (ref)
13183 : 57625615 : && !(flag_unconstrained_commons
13184 : 14 : && VAR_P (ref) && DECL_COMMON (ref))
13185 : 57625601 : && DECL_SIZE_UNIT (ref)
13186 : 125187020 : && TREE_CODE (DECL_SIZE_UNIT (ref)) == INTEGER_CST)
13187 : : {
13188 : : /* If the object itself is the array it is not at struct end. */
13189 : 57625196 : if (DECL_P (ref_to_array))
13190 : : return false;
13191 : :
13192 : : /* Check whether the array domain covers all of the available
13193 : : padding. */
13194 : 15495840 : poly_int64 offset;
13195 : 15495840 : if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
13196 : 15494504 : || TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST
13197 : 30968252 : || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST)
13198 : : {
13199 : 23428 : *is_trailing_array
13200 : 23428 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13201 : 23471 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13202 : : }
13203 : 15472412 : if (! get_addr_base_and_unit_offset (ref_to_array, &offset))
13204 : : {
13205 : 2630 : *is_trailing_array
13206 : 2630 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13207 : 2630 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13208 : : }
13209 : :
13210 : : /* If at least one extra element fits it is a flexarray. */
13211 : 15469782 : if (known_le ((wi::to_offset (TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13212 : : - wi::to_offset (TYPE_MIN_VALUE (TYPE_DOMAIN (atype)))
13213 : : + 2)
13214 : : * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (atype))),
13215 : : wi::to_offset (DECL_SIZE_UNIT (ref)) - offset))
13216 : : {
13217 : 366660 : *is_trailing_array
13218 : 366660 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13219 : 379000 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13220 : : }
13221 : :
13222 : : return false;
13223 : : }
13224 : :
13225 : 9936600 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13226 : 9951136 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13227 : : }
13228 : :
13229 : :
13230 : : /* Return a tree representing the offset, in bytes, of the field referenced
13231 : : by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
13232 : :
13233 : : tree
13234 : 2604613347 : component_ref_field_offset (tree exp)
13235 : : {
13236 : 2604613347 : tree aligned_offset = TREE_OPERAND (exp, 2);
13237 : 2604613347 : tree field = TREE_OPERAND (exp, 1);
13238 : 2604613347 : location_t loc = EXPR_LOCATION (exp);
13239 : :
13240 : : /* If an offset was specified in the COMPONENT_REF, it's the offset measured
13241 : : in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
13242 : : value. */
13243 : 2604613347 : if (aligned_offset)
13244 : : {
13245 : : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13246 : : sizetype from another type of the same width and signedness. */
13247 : 11862 : if (TREE_TYPE (aligned_offset) != sizetype)
13248 : 122 : aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
13249 : 11862 : return size_binop_loc (loc, MULT_EXPR, aligned_offset,
13250 : 11862 : size_int (DECL_OFFSET_ALIGN (field)
13251 : : / BITS_PER_UNIT));
13252 : : }
13253 : :
13254 : : /* Otherwise, take the offset from that of the field. Substitute
13255 : : any PLACEHOLDER_EXPR that we have. */
13256 : : else
13257 : 2604601485 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
13258 : : }
13259 : :
13260 : : /* Given the initializer INIT, return the initializer for the field
13261 : : DECL if it exists, otherwise null. Used to obtain the initializer
13262 : : for a flexible array member and determine its size. */
13263 : :
13264 : : static tree
13265 : 1268 : get_initializer_for (tree init, tree decl)
13266 : : {
13267 : 1268 : STRIP_NOPS (init);
13268 : :
13269 : 1268 : tree fld, fld_init;
13270 : 1268 : unsigned HOST_WIDE_INT i;
13271 : 3572 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), i, fld, fld_init)
13272 : : {
13273 : 1927 : if (decl == fld)
13274 : : return fld_init;
13275 : :
13276 : 1036 : if (TREE_CODE (fld) == CONSTRUCTOR)
13277 : : {
13278 : 0 : fld_init = get_initializer_for (fld_init, decl);
13279 : 0 : if (fld_init)
13280 : : return fld_init;
13281 : : }
13282 : : }
13283 : :
13284 : : return NULL_TREE;
13285 : : }
13286 : :
13287 : : /* Determines the special array member type for the array reference REF. */
13288 : : special_array_member
13289 : 253003 : component_ref_sam_type (tree ref)
13290 : : {
13291 : 253003 : special_array_member sam_type = special_array_member::none;
13292 : :
13293 : 253003 : tree member = TREE_OPERAND (ref, 1);
13294 : 253003 : tree memsize = DECL_SIZE_UNIT (member);
13295 : 253003 : if (memsize)
13296 : : {
13297 : 121056 : tree memtype = TREE_TYPE (member);
13298 : 121056 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13299 : 120935 : return sam_type;
13300 : :
13301 : 79607 : bool trailing = false;
13302 : 79607 : (void) array_ref_flexible_size_p (ref, &trailing);
13303 : 79607 : bool zero_elts = integer_zerop (memsize);
13304 : 79607 : if (zero_elts && integer_zerop (TYPE_SIZE_UNIT (TREE_TYPE (memtype))))
13305 : : {
13306 : : /* If array element has zero size, verify if it is a flexible
13307 : : array member or zero length array. Clear zero_elts if
13308 : : it has one or more members or is a VLA member. */
13309 : 7 : if (tree dom = TYPE_DOMAIN (memtype))
13310 : 7 : if (tree min = TYPE_MIN_VALUE (dom))
13311 : 7 : if (tree max = TYPE_MAX_VALUE (dom))
13312 : 5 : if (TREE_CODE (min) != INTEGER_CST
13313 : 5 : || TREE_CODE (max) != INTEGER_CST
13314 : 15 : || !((integer_zerop (min) && integer_all_onesp (max))
13315 : 5 : || tree_int_cst_lt (max, min)))
13316 : : zero_elts = false;
13317 : : }
13318 : 79607 : if (!trailing && !zero_elts)
13319 : : /* MEMBER is an interior array with more than one element. */
13320 : : return special_array_member::int_n;
13321 : :
13322 : 23665 : if (zero_elts)
13323 : : {
13324 : 1075 : if (trailing)
13325 : : return special_array_member::trail_0;
13326 : : else
13327 : 463 : return special_array_member::int_0;
13328 : : }
13329 : :
13330 : 23053 : if (!zero_elts)
13331 : 23053 : if (tree dom = TYPE_DOMAIN (memtype))
13332 : 23053 : if (tree min = TYPE_MIN_VALUE (dom))
13333 : 23053 : if (tree max = TYPE_MAX_VALUE (dom))
13334 : 23053 : if (TREE_CODE (min) == INTEGER_CST
13335 : 23053 : && TREE_CODE (max) == INTEGER_CST)
13336 : : {
13337 : 22932 : offset_int minidx = wi::to_offset (min);
13338 : 22932 : offset_int maxidx = wi::to_offset (max);
13339 : 22932 : offset_int neltsm1 = maxidx - minidx;
13340 : 22932 : if (neltsm1 > 0)
13341 : : /* MEMBER is a trailing array with more than
13342 : : one elements. */
13343 : 22932 : return special_array_member::trail_n;
13344 : :
13345 : 1966 : if (neltsm1 == 0)
13346 : : return special_array_member::trail_1;
13347 : : }
13348 : : }
13349 : :
13350 : : return sam_type;
13351 : : }
13352 : :
13353 : : /* Determines the size of the member referenced by the COMPONENT_REF
13354 : : REF, using its initializer expression if necessary in order to
13355 : : determine the size of an initialized flexible array member.
13356 : : If non-null, set *SAM to the type of special array member.
13357 : : Returns the size as sizetype (which might be zero for an object
13358 : : with an uninitialized flexible array member) or null if the size
13359 : : cannot be determined. */
13360 : :
13361 : : tree
13362 : 154084 : component_ref_size (tree ref, special_array_member *sam /* = NULL */)
13363 : : {
13364 : 154084 : gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
13365 : :
13366 : 154084 : special_array_member sambuf;
13367 : 154084 : if (!sam)
13368 : 97962 : sam = &sambuf;
13369 : 154084 : *sam = component_ref_sam_type (ref);
13370 : :
13371 : : /* The object/argument referenced by the COMPONENT_REF and its type. */
13372 : 154084 : tree arg = TREE_OPERAND (ref, 0);
13373 : 154084 : tree argtype = TREE_TYPE (arg);
13374 : : /* The referenced member. */
13375 : 154084 : tree member = TREE_OPERAND (ref, 1);
13376 : :
13377 : 154084 : tree memsize = DECL_SIZE_UNIT (member);
13378 : 154084 : if (memsize)
13379 : : {
13380 : 86594 : tree memtype = TREE_TYPE (member);
13381 : 86594 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13382 : : /* DECL_SIZE may be less than TYPE_SIZE in C++ when referring
13383 : : to the type of a class with a virtual base which doesn't
13384 : : reflect the size of the virtual's members (see pr97595).
13385 : : If that's the case fail for now and implement something
13386 : : more robust in the future. */
13387 : 41449 : return (tree_int_cst_equal (memsize, TYPE_SIZE_UNIT (memtype))
13388 : 41449 : ? memsize : NULL_TREE);
13389 : :
13390 : : /* 2-or-more elements arrays are treated as normal arrays by default. */
13391 : 45145 : if (*sam == special_array_member::int_n
13392 : 45145 : || *sam == special_array_member::trail_n)
13393 : : return memsize;
13394 : :
13395 : 1742 : tree afield_decl = TREE_OPERAND (ref, 1);
13396 : 1742 : gcc_assert (TREE_CODE (afield_decl) == FIELD_DECL);
13397 : : /* If the trailing array is a not a flexible array member, treat it as
13398 : : a normal array. */
13399 : 1742 : if (DECL_NOT_FLEXARRAY (afield_decl)
13400 : 1742 : && *sam != special_array_member::int_0)
13401 : : return memsize;
13402 : :
13403 : 1733 : if (*sam == special_array_member::int_0)
13404 : 270 : memsize = NULL_TREE;
13405 : :
13406 : : /* For a reference to a flexible array member of a union
13407 : : use the size of the union instead of the size of the member. */
13408 : 1733 : if (TREE_CODE (argtype) == UNION_TYPE)
13409 : 277 : memsize = TYPE_SIZE_UNIT (argtype);
13410 : : }
13411 : :
13412 : : /* MEMBER is either a bona fide flexible array member, or a zero-elements
13413 : : array member, or an array of length one treated as such. */
13414 : :
13415 : : /* If the reference is to a declared object and the member a true
13416 : : flexible array, try to determine its size from its initializer. */
13417 : 69223 : poly_int64 baseoff = 0;
13418 : 69223 : tree base = get_addr_base_and_unit_offset (ref, &baseoff);
13419 : 69223 : if (!base || !VAR_P (base))
13420 : : {
13421 : 66025 : if (*sam != special_array_member::int_0)
13422 : : return NULL_TREE;
13423 : :
13424 : 52 : if (TREE_CODE (arg) != COMPONENT_REF)
13425 : : return NULL_TREE;
13426 : :
13427 : : base = arg;
13428 : 6 : while (TREE_CODE (base) == COMPONENT_REF)
13429 : 3 : base = TREE_OPERAND (base, 0);
13430 : 3 : baseoff = tree_to_poly_int64 (byte_position (TREE_OPERAND (ref, 1)));
13431 : : }
13432 : :
13433 : : /* BASE is the declared object of which MEMBER is either a member
13434 : : or that is cast to ARGTYPE (e.g., a char buffer used to store
13435 : : an ARGTYPE object). */
13436 : 3201 : tree basetype = TREE_TYPE (base);
13437 : :
13438 : : /* Determine the base type of the referenced object. If it's
13439 : : the same as ARGTYPE and MEMBER has a known size, return it. */
13440 : 3201 : tree bt = basetype;
13441 : 3201 : if (*sam != special_array_member::int_0)
13442 : 3202 : while (TREE_CODE (bt) == ARRAY_TYPE)
13443 : 222 : bt = TREE_TYPE (bt);
13444 : 3201 : bool typematch = useless_type_conversion_p (argtype, bt);
13445 : 3201 : if (memsize && typematch)
13446 : : return memsize;
13447 : :
13448 : 3111 : memsize = NULL_TREE;
13449 : :
13450 : 3111 : if (typematch)
13451 : : /* MEMBER is a true flexible array member. Compute its size from
13452 : : the initializer of the BASE object if it has one. */
13453 : 2649 : if (tree init = DECL_P (base) ? DECL_INITIAL (base) : NULL_TREE)
13454 : 1301 : if (init != error_mark_node)
13455 : : {
13456 : 1268 : init = get_initializer_for (init, member);
13457 : 1268 : if (init)
13458 : : {
13459 : 891 : memsize = TYPE_SIZE_UNIT (TREE_TYPE (init));
13460 : 891 : if (tree refsize = TYPE_SIZE_UNIT (argtype))
13461 : : {
13462 : : /* Use the larger of the initializer size and the tail
13463 : : padding in the enclosing struct. */
13464 : 891 : poly_int64 rsz = tree_to_poly_int64 (refsize);
13465 : 891 : rsz -= baseoff;
13466 : 891 : if (known_lt (tree_to_poly_int64 (memsize), rsz))
13467 : 56 : memsize = wide_int_to_tree (TREE_TYPE (memsize), rsz);
13468 : : }
13469 : :
13470 : 891 : baseoff = 0;
13471 : : }
13472 : : }
13473 : :
13474 : 891 : if (!memsize)
13475 : : {
13476 : 2220 : if (typematch)
13477 : : {
13478 : 1758 : if (DECL_P (base)
13479 : 1758 : && DECL_EXTERNAL (base)
13480 : 454 : && bt == basetype
13481 : 2206 : && *sam != special_array_member::int_0)
13482 : : /* The size of a flexible array member of an extern struct
13483 : : with no initializer cannot be determined (it's defined
13484 : : in another translation unit and can have an initializer
13485 : : with an arbitrary number of elements). */
13486 : : return NULL_TREE;
13487 : :
13488 : : /* Use the size of the base struct or, for interior zero-length
13489 : : arrays, the size of the enclosing type. */
13490 : 1333 : memsize = TYPE_SIZE_UNIT (bt);
13491 : : }
13492 : 462 : else if (DECL_P (base))
13493 : : /* Use the size of the BASE object (possibly an array of some
13494 : : other type such as char used to store the struct). */
13495 : 459 : memsize = DECL_SIZE_UNIT (base);
13496 : : else
13497 : : return NULL_TREE;
13498 : : }
13499 : :
13500 : : /* If the flexible array member has a known size use the greater
13501 : : of it and the tail padding in the enclosing struct.
13502 : : Otherwise, when the size of the flexible array member is unknown
13503 : : and the referenced object is not a struct, use the size of its
13504 : : type when known. This detects sizes of array buffers when cast
13505 : : to struct types with flexible array members. */
13506 : 1792 : if (memsize)
13507 : : {
13508 : 2658 : if (!tree_fits_poly_int64_p (memsize))
13509 : : return NULL_TREE;
13510 : 2658 : poly_int64 memsz64 = memsize ? tree_to_poly_int64 (memsize) : 0;
13511 : 2658 : if (known_lt (baseoff, memsz64))
13512 : : {
13513 : 1241 : memsz64 -= baseoff;
13514 : 1241 : return wide_int_to_tree (TREE_TYPE (memsize), memsz64);
13515 : : }
13516 : 1417 : return size_zero_node;
13517 : : }
13518 : :
13519 : : /* Return "don't know" for an external non-array object since its
13520 : : flexible array member can be initialized to have any number of
13521 : : elements. Otherwise, return zero because the flexible array
13522 : : member has no elements. */
13523 : 25 : return (DECL_P (base)
13524 : 25 : && DECL_EXTERNAL (base)
13525 : 25 : && (!typematch
13526 : 0 : || TREE_CODE (basetype) != ARRAY_TYPE)
13527 : 25 : ? NULL_TREE : size_zero_node);
13528 : : }
13529 : :
13530 : : /* Return true if the given node CALL is a call to a .ACCESS_WITH_SIZE
13531 : : function. */
13532 : : bool
13533 : 57610740 : is_access_with_size_p (const_tree call)
13534 : : {
13535 : 57610740 : if (TREE_CODE (call) != CALL_EXPR)
13536 : : return false;
13537 : 6992313 : if (CALL_EXPR_IFN (call) == IFN_ACCESS_WITH_SIZE)
13538 : 130 : return true;
13539 : : return false;
13540 : : }
13541 : :
13542 : : /* Get the corresponding reference from the call to a .ACCESS_WITH_SIZE.
13543 : : * i.e the first argument of this call. Return NULL_TREE otherwise. */
13544 : : tree
13545 : 2 : get_ref_from_access_with_size (tree call)
13546 : : {
13547 : 2 : if (is_access_with_size_p (call))
13548 : 2 : return CALL_EXPR_ARG (call, 0);
13549 : : return NULL_TREE;
13550 : : }
13551 : :
13552 : : /* Return the machine mode of T. For vectors, returns the mode of the
13553 : : inner type. The main use case is to feed the result to HONOR_NANS,
13554 : : avoiding the BLKmode that a direct TYPE_MODE (T) might return. */
13555 : :
13556 : : machine_mode
13557 : 5070428575 : element_mode (const_tree t)
13558 : : {
13559 : 5070428575 : if (!TYPE_P (t))
13560 : 199544218 : t = TREE_TYPE (t);
13561 : 5070428575 : if (VECTOR_TYPE_P (t) || TREE_CODE (t) == COMPLEX_TYPE)
13562 : 1475448580 : t = TREE_TYPE (t);
13563 : 5070428575 : return TYPE_MODE (t);
13564 : : }
13565 : :
13566 : : /* Vector types need to re-check the target flags each time we report
13567 : : the machine mode. We need to do this because attribute target can
13568 : : change the result of vector_mode_supported_p and have_regs_of_mode
13569 : : on a per-function basis. Thus the TYPE_MODE of a VECTOR_TYPE can
13570 : : change on a per-function basis. */
13571 : : /* ??? Possibly a better solution is to run through all the types
13572 : : referenced by a function and re-compute the TYPE_MODE once, rather
13573 : : than make the TYPE_MODE macro call a function. */
13574 : :
13575 : : machine_mode
13576 : 1314046267 : vector_type_mode (const_tree t)
13577 : : {
13578 : 1314046267 : machine_mode mode;
13579 : :
13580 : 1314046267 : gcc_assert (TREE_CODE (t) == VECTOR_TYPE);
13581 : :
13582 : 1314046267 : mode = t->type_common.mode;
13583 : 297634213 : if (VECTOR_MODE_P (mode)
13584 : 1575140378 : && (!targetm.vector_mode_supported_p (mode)
13585 : 1259185569 : || !have_regs_of_mode[mode]))
13586 : : {
13587 : 19146748 : scalar_int_mode innermode;
13588 : :
13589 : : /* For integers, try mapping it to a same-sized scalar mode. */
13590 : 19146748 : if (is_int_mode (TREE_TYPE (t)->type_common.mode, &innermode))
13591 : : {
13592 : 26748162 : poly_int64 size = (TYPE_VECTOR_SUBPARTS (t)
13593 : 13374081 : * GET_MODE_BITSIZE (innermode));
13594 : 13374081 : scalar_int_mode mode;
13595 : 26612513 : if (int_mode_for_size (size, 0).exists (&mode)
13596 : 13291650 : && have_regs_of_mode[mode])
13597 : 53218 : return mode;
13598 : : }
13599 : :
13600 : 19093530 : return BLKmode;
13601 : : }
13602 : :
13603 : : return mode;
13604 : : }
13605 : :
13606 : : /* Return the size in bits of each element of vector type TYPE. */
13607 : :
13608 : : unsigned int
13609 : 205871 : vector_element_bits (const_tree type)
13610 : : {
13611 : 205871 : gcc_checking_assert (VECTOR_TYPE_P (type));
13612 : 205871 : if (VECTOR_BOOLEAN_TYPE_P (type))
13613 : 974 : return TYPE_PRECISION (TREE_TYPE (type));
13614 : 204897 : return tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)));
13615 : : }
13616 : :
13617 : : /* Calculate the size in bits of each element of vector type TYPE
13618 : : and return the result as a tree of type bitsizetype. */
13619 : :
13620 : : tree
13621 : 111350 : vector_element_bits_tree (const_tree type)
13622 : : {
13623 : 111350 : gcc_checking_assert (VECTOR_TYPE_P (type));
13624 : 111350 : if (VECTOR_BOOLEAN_TYPE_P (type))
13625 : 600 : return bitsize_int (vector_element_bits (type));
13626 : 110750 : return TYPE_SIZE (TREE_TYPE (type));
13627 : : }
13628 : :
13629 : : /* Verify that basic properties of T match TV and thus T can be a variant of
13630 : : TV. TV should be the more specified variant (i.e. the main variant). */
13631 : :
13632 : : static bool
13633 : 141239562 : verify_type_variant (const_tree t, tree tv)
13634 : : {
13635 : : /* Type variant can differ by:
13636 : :
13637 : : - TYPE_QUALS: TYPE_READONLY, TYPE_VOLATILE, TYPE_ATOMIC, TYPE_RESTRICT,
13638 : : ENCODE_QUAL_ADDR_SPACE.
13639 : : - main variant may be TYPE_COMPLETE_P and variant types !TYPE_COMPLETE_P
13640 : : in this case some values may not be set in the variant types
13641 : : (see TYPE_COMPLETE_P checks).
13642 : : - it is possible to have TYPE_ARTIFICIAL variant of non-artifical type
13643 : : - by TYPE_NAME and attributes (i.e. when variant originate by typedef)
13644 : : - TYPE_CANONICAL (TYPE_ALIAS_SET is the same among variants)
13645 : : - by the alignment: TYPE_ALIGN and TYPE_USER_ALIGN
13646 : : - during LTO by TYPE_CONTEXT if type is TYPE_FILE_SCOPE_P
13647 : : this is necessary to make it possible to merge types form different TUs
13648 : : - arrays, pointers and references may have TREE_TYPE that is a variant
13649 : : of TREE_TYPE of their main variants.
13650 : : - aggregates may have new TYPE_FIELDS list that list variants of
13651 : : the main variant TYPE_FIELDS.
13652 : : - vector types may differ by TYPE_VECTOR_OPAQUE
13653 : : */
13654 : :
13655 : : /* Convenience macro for matching individual fields. */
13656 : : #define verify_variant_match(flag) \
13657 : : do { \
13658 : : if (flag (tv) != flag (t)) \
13659 : : { \
13660 : : error ("type variant differs by %s", #flag); \
13661 : : debug_tree (tv); \
13662 : : return false; \
13663 : : } \
13664 : : } while (false)
13665 : :
13666 : : /* tree_base checks. */
13667 : :
13668 : 141239562 : verify_variant_match (TREE_CODE);
13669 : : /* FIXME: Ada builds non-artificial variants of artificial types. */
13670 : : #if 0
13671 : : if (TYPE_ARTIFICIAL (tv))
13672 : : verify_variant_match (TYPE_ARTIFICIAL);
13673 : : #endif
13674 : 141239562 : if (POINTER_TYPE_P (tv))
13675 : 11006296 : verify_variant_match (TYPE_REF_CAN_ALIAS_ALL);
13676 : : /* FIXME: TYPE_SIZES_GIMPLIFIED may differs for Ada build. */
13677 : 141239562 : verify_variant_match (TYPE_UNSIGNED);
13678 : 141239562 : verify_variant_match (TYPE_PACKED);
13679 : 141239562 : if (TREE_CODE (t) == REFERENCE_TYPE)
13680 : 2800472 : verify_variant_match (TYPE_REF_IS_RVALUE);
13681 : 141239562 : if (AGGREGATE_TYPE_P (t))
13682 : 60120723 : verify_variant_match (TYPE_REVERSE_STORAGE_ORDER);
13683 : : else
13684 : 81118839 : verify_variant_match (TYPE_SATURATING);
13685 : : /* FIXME: This check trigger during libstdc++ build. */
13686 : : #if 0
13687 : : if (RECORD_OR_UNION_TYPE_P (t) && COMPLETE_TYPE_P (t))
13688 : : verify_variant_match (TYPE_FINAL_P);
13689 : : #endif
13690 : :
13691 : : /* tree_type_common checks. */
13692 : :
13693 : 141239562 : if (COMPLETE_TYPE_P (t))
13694 : : {
13695 : 131025785 : verify_variant_match (TYPE_MODE);
13696 : 131025785 : if (TREE_CODE (TYPE_SIZE (t)) != PLACEHOLDER_EXPR
13697 : 131025785 : && TREE_CODE (TYPE_SIZE (tv)) != PLACEHOLDER_EXPR)
13698 : 131025785 : verify_variant_match (TYPE_SIZE);
13699 : 131025785 : if (TREE_CODE (TYPE_SIZE_UNIT (t)) != PLACEHOLDER_EXPR
13700 : 131025785 : && TREE_CODE (TYPE_SIZE_UNIT (tv)) != PLACEHOLDER_EXPR
13701 : 262051570 : && TYPE_SIZE_UNIT (t) != TYPE_SIZE_UNIT (tv))
13702 : : {
13703 : 0 : gcc_assert (!operand_equal_p (TYPE_SIZE_UNIT (t),
13704 : : TYPE_SIZE_UNIT (tv), 0));
13705 : 0 : error ("type variant has different %<TYPE_SIZE_UNIT%>");
13706 : 0 : debug_tree (tv);
13707 : 0 : error ("type variant%'s %<TYPE_SIZE_UNIT%>");
13708 : 0 : debug_tree (TYPE_SIZE_UNIT (tv));
13709 : 0 : error ("type%'s %<TYPE_SIZE_UNIT%>");
13710 : 0 : debug_tree (TYPE_SIZE_UNIT (t));
13711 : 0 : return false;
13712 : : }
13713 : 131025785 : verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
13714 : : }
13715 : 141239562 : verify_variant_match (TYPE_PRECISION_RAW);
13716 : 141239562 : if (RECORD_OR_UNION_TYPE_P (t))
13717 : 59617746 : verify_variant_match (TYPE_TRANSPARENT_AGGR);
13718 : 81621816 : else if (TREE_CODE (t) == ARRAY_TYPE)
13719 : 502977 : verify_variant_match (TYPE_NONALIASED_COMPONENT);
13720 : : /* During LTO we merge variant lists from diferent translation units
13721 : : that may differ BY TYPE_CONTEXT that in turn may point
13722 : : to TRANSLATION_UNIT_DECL.
13723 : : Ada also builds variants of types with different TYPE_CONTEXT. */
13724 : : #if 0
13725 : : if (!in_lto_p || !TYPE_FILE_SCOPE_P (t))
13726 : : verify_variant_match (TYPE_CONTEXT);
13727 : : #endif
13728 : 141239562 : if (TREE_CODE (t) == ARRAY_TYPE || TREE_CODE (t) == INTEGER_TYPE)
13729 : 49685774 : verify_variant_match (TYPE_STRING_FLAG);
13730 : 141239562 : if (TREE_CODE (t) == RECORD_TYPE || TREE_CODE (t) == UNION_TYPE)
13731 : 59617746 : verify_variant_match (TYPE_CXX_ODR_P);
13732 : 141239562 : if (TYPE_ALIAS_SET_KNOWN_P (t))
13733 : : {
13734 : 0 : error ("type variant with %<TYPE_ALIAS_SET_KNOWN_P%>");
13735 : 0 : debug_tree (tv);
13736 : 0 : return false;
13737 : : }
13738 : :
13739 : : /* tree_type_non_common checks. */
13740 : :
13741 : : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
13742 : : and dangle the pointer from time to time. */
13743 : 59617746 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_VFIELD (t) != TYPE_VFIELD (tv)
13744 : 141239562 : && (in_lto_p || !TYPE_VFIELD (tv)
13745 : 0 : || TREE_CODE (TYPE_VFIELD (tv)) != TREE_LIST))
13746 : : {
13747 : 0 : error ("type variant has different %<TYPE_VFIELD%>");
13748 : 0 : debug_tree (tv);
13749 : 0 : return false;
13750 : : }
13751 : 2344192 : if ((TREE_CODE (t) == ENUMERAL_TYPE && COMPLETE_TYPE_P (t))
13752 : 138895423 : || TREE_CODE (t) == INTEGER_TYPE
13753 : 89712626 : || TREE_CODE (t) == BOOLEAN_TYPE
13754 : 72805035 : || TREE_CODE (t) == BITINT_TYPE
13755 : 72804900 : || SCALAR_FLOAT_TYPE_P (t)
13756 : 213088577 : || FIXED_POINT_TYPE_P (t))
13757 : : {
13758 : 69390547 : verify_variant_match (TYPE_MAX_VALUE);
13759 : 69390547 : verify_variant_match (TYPE_MIN_VALUE);
13760 : : }
13761 : 141239562 : if (TREE_CODE (t) == METHOD_TYPE)
13762 : 18845 : verify_variant_match (TYPE_METHOD_BASETYPE);
13763 : 141239562 : if (TREE_CODE (t) == OFFSET_TYPE)
13764 : 159 : verify_variant_match (TYPE_OFFSET_BASETYPE);
13765 : 141239562 : if (TREE_CODE (t) == ARRAY_TYPE)
13766 : 502977 : verify_variant_match (TYPE_ARRAY_MAX_SIZE);
13767 : : /* FIXME: Be lax and allow TYPE_BINFO to be missing in variant types
13768 : : or even type's main variant. This is needed to make bootstrap pass
13769 : : and the bug seems new in GCC 5.
13770 : : C++ FE should be updated to make this consistent and we should check
13771 : : that TYPE_BINFO is always NULL for !COMPLETE_TYPE_P and otherwise there
13772 : : is a match with main variant.
13773 : :
13774 : : Also disable the check for Java for now because of parser hack that builds
13775 : : first an dummy BINFO and then sometimes replace it by real BINFO in some
13776 : : of the copies. */
13777 : 59617746 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t) && TYPE_BINFO (tv)
13778 : 49205852 : && TYPE_BINFO (t) != TYPE_BINFO (tv)
13779 : : /* FIXME: Java sometimes keep dump TYPE_BINFOs on variant types.
13780 : : Since there is no cheap way to tell C++/Java type w/o LTO, do checking
13781 : : at LTO time only. */
13782 : 141239562 : && (in_lto_p && odr_type_p (t)))
13783 : : {
13784 : 0 : error ("type variant has different %<TYPE_BINFO%>");
13785 : 0 : debug_tree (tv);
13786 : 0 : error ("type variant%'s %<TYPE_BINFO%>");
13787 : 0 : debug_tree (TYPE_BINFO (tv));
13788 : 0 : error ("type%'s %<TYPE_BINFO%>");
13789 : 0 : debug_tree (TYPE_BINFO (t));
13790 : 0 : return false;
13791 : : }
13792 : :
13793 : : /* Check various uses of TYPE_VALUES_RAW. */
13794 : 141239562 : if (TREE_CODE (t) == ENUMERAL_TYPE
13795 : 141239562 : && TYPE_VALUES (t))
13796 : 2324272 : verify_variant_match (TYPE_VALUES);
13797 : 138915290 : else if (TREE_CODE (t) == ARRAY_TYPE)
13798 : 502977 : verify_variant_match (TYPE_DOMAIN);
13799 : : /* Permit incomplete variants of complete type. While FEs may complete
13800 : : all variants, this does not happen for C++ templates in all cases. */
13801 : 138412313 : else if (RECORD_OR_UNION_TYPE_P (t)
13802 : 59617746 : && COMPLETE_TYPE_P (t)
13803 : 188033875 : && TYPE_FIELDS (t) != TYPE_FIELDS (tv))
13804 : : {
13805 : 3319 : tree f1, f2;
13806 : :
13807 : : /* Fortran builds qualified variants as new records with items of
13808 : : qualified type. Verify that they looks same. */
13809 : 3319 : for (f1 = TYPE_FIELDS (t), f2 = TYPE_FIELDS (tv);
13810 : 10879 : f1 && f2;
13811 : 7560 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
13812 : 7560 : if (TREE_CODE (f1) != FIELD_DECL || TREE_CODE (f2) != FIELD_DECL
13813 : 7560 : || (TYPE_MAIN_VARIANT (TREE_TYPE (f1))
13814 : 7560 : != TYPE_MAIN_VARIANT (TREE_TYPE (f2))
13815 : : /* FIXME: gfc_nonrestricted_type builds all types as variants
13816 : : with exception of pointer types. It deeply copies the type
13817 : : which means that we may end up with a variant type
13818 : : referring non-variant pointer. We may change it to
13819 : : produce types as variants, too, like
13820 : : objc_get_protocol_qualified_type does. */
13821 : 21 : && !POINTER_TYPE_P (TREE_TYPE (f1)))
13822 : 7560 : || DECL_FIELD_OFFSET (f1) != DECL_FIELD_OFFSET (f2)
13823 : 15120 : || DECL_FIELD_BIT_OFFSET (f1) != DECL_FIELD_BIT_OFFSET (f2))
13824 : : break;
13825 : 3319 : if (f1 || f2)
13826 : : {
13827 : 0 : error ("type variant has different %<TYPE_FIELDS%>");
13828 : 0 : debug_tree (tv);
13829 : 0 : error ("first mismatch is field");
13830 : 0 : debug_tree (f1);
13831 : 0 : error ("and field");
13832 : 0 : debug_tree (f2);
13833 : 0 : return false;
13834 : : }
13835 : : }
13836 : 138408994 : else if (FUNC_OR_METHOD_TYPE_P (t))
13837 : 177424 : verify_variant_match (TYPE_ARG_TYPES);
13838 : : /* For C++ the qualified variant of array type is really an array type
13839 : : of qualified TREE_TYPE.
13840 : : objc builds variants of pointer where pointer to type is a variant, too
13841 : : in objc_get_protocol_qualified_type. */
13842 : 141239562 : if (TREE_TYPE (t) != TREE_TYPE (tv)
13843 : 141239562 : && ((TREE_CODE (t) != ARRAY_TYPE
13844 : 0 : && !POINTER_TYPE_P (t))
13845 : 430428 : || TYPE_MAIN_VARIANT (TREE_TYPE (t))
13846 : 430428 : != TYPE_MAIN_VARIANT (TREE_TYPE (tv))))
13847 : : {
13848 : 0 : error ("type variant has different %<TREE_TYPE%>");
13849 : 0 : debug_tree (tv);
13850 : 0 : error ("type variant%'s %<TREE_TYPE%>");
13851 : 0 : debug_tree (TREE_TYPE (tv));
13852 : 0 : error ("type%'s %<TREE_TYPE%>");
13853 : 0 : debug_tree (TREE_TYPE (t));
13854 : 0 : return false;
13855 : : }
13856 : 141239562 : if (type_with_alias_set_p (t)
13857 : 141239562 : && !gimple_canonical_types_compatible_p (t, tv, false))
13858 : : {
13859 : 0 : error ("type is not compatible with its variant");
13860 : 0 : debug_tree (tv);
13861 : 0 : error ("type variant%'s %<TREE_TYPE%>");
13862 : 0 : debug_tree (TREE_TYPE (tv));
13863 : 0 : error ("type%'s %<TREE_TYPE%>");
13864 : 0 : debug_tree (TREE_TYPE (t));
13865 : 0 : return false;
13866 : : }
13867 : : return true;
13868 : : #undef verify_variant_match
13869 : : }
13870 : :
13871 : :
13872 : : /* The TYPE_CANONICAL merging machinery. It should closely resemble
13873 : : the middle-end types_compatible_p function. It needs to avoid
13874 : : claiming types are different for types that should be treated
13875 : : the same with respect to TBAA. Canonical types are also used
13876 : : for IL consistency checks via the useless_type_conversion_p
13877 : : predicate which does not handle all type kinds itself but falls
13878 : : back to pointer-comparison of TYPE_CANONICAL for aggregates
13879 : : for example. */
13880 : :
13881 : : /* Return true if TYPE_UNSIGNED of TYPE should be ignored for canonical
13882 : : type calculation because we need to allow inter-operability between signed
13883 : : and unsigned variants. */
13884 : :
13885 : : bool
13886 : 1763955 : type_with_interoperable_signedness (const_tree type)
13887 : : {
13888 : : /* Fortran standard require C_SIGNED_CHAR to be interoperable with both
13889 : : signed char and unsigned char. Similarly fortran FE builds
13890 : : C_SIZE_T as signed type, while C defines it unsigned. */
13891 : :
13892 : 1763955 : return tree_code_for_canonical_type_merging (TREE_CODE (type))
13893 : : == INTEGER_TYPE
13894 : 1763754 : && (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node)
13895 : 473135 : || TYPE_PRECISION (type) == TYPE_PRECISION (size_type_node));
13896 : : }
13897 : :
13898 : : /* Return true iff T1 and T2 are structurally identical for what
13899 : : TBAA is concerned.
13900 : : This function is used both by lto.cc canonical type merging and by the
13901 : : verifier. If TRUST_TYPE_CANONICAL we do not look into structure of types
13902 : : that have TYPE_CANONICAL defined and assume them equivalent. This is useful
13903 : : only for LTO because only in these cases TYPE_CANONICAL equivalence
13904 : : correspond to one defined by gimple_canonical_types_compatible_p. */
13905 : :
13906 : : bool
13907 : 304821956 : gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
13908 : : bool trust_type_canonical)
13909 : : {
13910 : : /* Type variants should be same as the main variant. When not doing sanity
13911 : : checking to verify this fact, go to main variants and save some work. */
13912 : 304821956 : if (trust_type_canonical)
13913 : : {
13914 : 944063 : t1 = TYPE_MAIN_VARIANT (t1);
13915 : 944063 : t2 = TYPE_MAIN_VARIANT (t2);
13916 : : }
13917 : :
13918 : : /* Check first for the obvious case of pointer identity. */
13919 : 304821956 : if (t1 == t2)
13920 : : return true;
13921 : :
13922 : : /* Check that we have two types to compare. */
13923 : 253157846 : if (t1 == NULL_TREE || t2 == NULL_TREE)
13924 : : return false;
13925 : :
13926 : : /* We consider complete types always compatible with incomplete type.
13927 : : This does not make sense for canonical type calculation and thus we
13928 : : need to ensure that we are never called on it.
13929 : :
13930 : : FIXME: For more correctness the function probably should have three modes
13931 : : 1) mode assuming that types are complete mathcing their structure
13932 : : 2) mode allowing incomplete types but producing equivalence classes
13933 : : and thus ignoring all info from complete types
13934 : : 3) mode allowing incomplete types to match complete but checking
13935 : : compatibility between complete types.
13936 : :
13937 : : 1 and 2 can be used for canonical type calculation. 3 is the real
13938 : : definition of type compatibility that can be used i.e. for warnings during
13939 : : declaration merging. */
13940 : :
13941 : 253157846 : gcc_assert (!trust_type_canonical
13942 : : || (type_with_alias_set_p (t1) && type_with_alias_set_p (t2)));
13943 : :
13944 : : /* If the types have been previously registered and found equal
13945 : : they still are. */
13946 : :
13947 : 506083602 : if (TYPE_CANONICAL (t1) && TYPE_CANONICAL (t2)
13948 : 505230674 : && trust_type_canonical)
13949 : : {
13950 : : /* Do not use TYPE_CANONICAL of pointer types. For LTO streamed types
13951 : : they are always NULL, but they are set to non-NULL for types
13952 : : constructed by build_pointer_type and variants. In this case the
13953 : : TYPE_CANONICAL is more fine grained than the equivalnce we test (where
13954 : : all pointers are considered equal. Be sure to not return false
13955 : : negatives. */
13956 : 175344 : gcc_checking_assert (canonical_type_used_p (t1)
13957 : : && canonical_type_used_p (t2));
13958 : 87672 : return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
13959 : : }
13960 : :
13961 : : /* For types where we do ODR based TBAA the canonical type is always
13962 : : set correctly, so we know that types are different if their
13963 : : canonical types does not match. */
13964 : 253070174 : if (trust_type_canonical
13965 : 253923599 : && (odr_type_p (t1) && odr_based_tbaa_p (t1))
13966 : 853425 : != (odr_type_p (t2) && odr_based_tbaa_p (t2)))
13967 : : return false;
13968 : :
13969 : : /* Can't be the same type if the types don't have the same code. */
13970 : 253070174 : enum tree_code code = tree_code_for_canonical_type_merging (TREE_CODE (t1));
13971 : 503340790 : if (code != tree_code_for_canonical_type_merging (TREE_CODE (t2)))
13972 : : return false;
13973 : :
13974 : : /* Qualifiers do not matter for canonical type comparison purposes. */
13975 : :
13976 : : /* Void types and nullptr types are always the same. */
13977 : 253070139 : if (VOID_TYPE_P (t1)
13978 : 253030778 : || TREE_CODE (t1) == NULLPTR_TYPE)
13979 : : return true;
13980 : :
13981 : : /* Can't be compatible types if they have different mode. Because of
13982 : : flexible array members, we allow mismatching modes for structures or
13983 : : unions. */
13984 : 252478653 : if (!RECORD_OR_UNION_TYPE_P (t1)
13985 : 252478653 : && TREE_CODE (t1) != ARRAY_TYPE
13986 : 252478653 : && TYPE_MODE (t1) != TYPE_MODE (t2))
13987 : : return false;
13988 : :
13989 : : /* Non-aggregate types can be handled cheaply. */
13990 : 252478653 : if (INTEGRAL_TYPE_P (t1)
13991 : 252478653 : || SCALAR_FLOAT_TYPE_P (t1)
13992 : 137186725 : || FIXED_POINT_TYPE_P (t1)
13993 : 136792669 : || VECTOR_TYPE_P (t1)
13994 : 136766863 : || TREE_CODE (t1) == COMPLEX_TYPE
13995 : 136411162 : || TREE_CODE (t1) == OFFSET_TYPE
13996 : 136410462 : || POINTER_TYPE_P (t1))
13997 : : {
13998 : : /* Can't be the same type if they have different precision. */
13999 : 151597265 : if (TYPE_PRECISION_RAW (t1) != TYPE_PRECISION_RAW (t2))
14000 : : return false;
14001 : :
14002 : : /* In some cases the signed and unsigned types are required to be
14003 : : inter-operable. */
14004 : 151597265 : if (TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)
14005 : 151597265 : && !type_with_interoperable_signedness (t1))
14006 : : return false;
14007 : :
14008 : : /* Fortran's C_SIGNED_CHAR is !TYPE_STRING_FLAG but needs to be
14009 : : interoperable with "signed char". Unless all frontends are revisited
14010 : : to agree on these types, we must ignore the flag completely. */
14011 : :
14012 : : /* Fortran standard define C_PTR type that is compatible with every
14013 : : C pointer. For this reason we need to glob all pointers into one.
14014 : : Still pointers in different address spaces are not compatible. */
14015 : 151597265 : if (POINTER_TYPE_P (t1))
14016 : : {
14017 : 35529074 : if (TYPE_ADDR_SPACE (TREE_TYPE (t1))
14018 : 35529074 : != TYPE_ADDR_SPACE (TREE_TYPE (t2)))
14019 : : return false;
14020 : : }
14021 : :
14022 : : /* Tail-recurse to components. */
14023 : 151597265 : if (VECTOR_TYPE_P (t1)
14024 : 151597265 : || TREE_CODE (t1) == COMPLEX_TYPE)
14025 : 381507 : return gimple_canonical_types_compatible_p (TREE_TYPE (t1),
14026 : 381507 : TREE_TYPE (t2),
14027 : 381507 : trust_type_canonical);
14028 : :
14029 : : return true;
14030 : : }
14031 : :
14032 : : /* Do type-specific comparisons. */
14033 : 100881388 : switch (TREE_CODE (t1))
14034 : : {
14035 : 936681 : case ARRAY_TYPE:
14036 : : /* Array types are the same if the element types are the same and
14037 : : minimum and maximum index are the same. */
14038 : 936681 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14039 : : trust_type_canonical)
14040 : 936646 : || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
14041 : 936646 : || TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2)
14042 : 1873327 : || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
14043 : : return false;
14044 : : else
14045 : : {
14046 : 936646 : tree i1 = TYPE_DOMAIN (t1);
14047 : 936646 : tree i2 = TYPE_DOMAIN (t2);
14048 : :
14049 : : /* For an incomplete external array, the type domain can be
14050 : : NULL_TREE. Check this condition also. */
14051 : 936646 : if (i1 == NULL_TREE && i2 == NULL_TREE)
14052 : : return true;
14053 : 838827 : else if (i1 == NULL_TREE || i2 == NULL_TREE)
14054 : : return false;
14055 : : else
14056 : : {
14057 : 838827 : tree min1 = TYPE_MIN_VALUE (i1);
14058 : 838827 : tree min2 = TYPE_MIN_VALUE (i2);
14059 : 838827 : tree max1 = TYPE_MAX_VALUE (i1);
14060 : 838827 : tree max2 = TYPE_MAX_VALUE (i2);
14061 : :
14062 : : /* The minimum/maximum values have to be the same. */
14063 : 838827 : if ((min1 == min2
14064 : 0 : || (min1 && min2
14065 : 0 : && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
14066 : 0 : && TREE_CODE (min2) == PLACEHOLDER_EXPR)
14067 : 0 : || operand_equal_p (min1, min2, 0))))
14068 : 838827 : && (max1 == max2
14069 : 0 : || (max1 && max2
14070 : 0 : && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
14071 : 0 : && TREE_CODE (max2) == PLACEHOLDER_EXPR)
14072 : 0 : || operand_equal_p (max1, max2, 0)))))
14073 : 838827 : return true;
14074 : : else
14075 : 0 : return false;
14076 : : }
14077 : : }
14078 : :
14079 : 14773 : case METHOD_TYPE:
14080 : 14773 : case FUNCTION_TYPE:
14081 : : /* Function types are the same if the return type and arguments types
14082 : : are the same. */
14083 : 14773 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14084 : : trust_type_canonical))
14085 : : return false;
14086 : :
14087 : 14773 : if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2)
14088 : 14773 : && (TYPE_NO_NAMED_ARGS_STDARG_P (t1)
14089 : 539 : == TYPE_NO_NAMED_ARGS_STDARG_P (t2)))
14090 : : return true;
14091 : : else
14092 : : {
14093 : 14234 : tree parms1, parms2;
14094 : :
14095 : 14234 : for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
14096 : 61127 : parms1 && parms2;
14097 : 46893 : parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
14098 : : {
14099 : 46893 : if (!gimple_canonical_types_compatible_p
14100 : 46893 : (TREE_VALUE (parms1), TREE_VALUE (parms2),
14101 : : trust_type_canonical))
14102 : : return false;
14103 : : }
14104 : :
14105 : 14234 : if (parms1 || parms2)
14106 : : return false;
14107 : :
14108 : : return true;
14109 : : }
14110 : :
14111 : 99583761 : case RECORD_TYPE:
14112 : 99583761 : case UNION_TYPE:
14113 : 99583761 : case QUAL_UNION_TYPE:
14114 : 99583761 : {
14115 : 99583761 : tree f1, f2;
14116 : :
14117 : : /* Don't try to compare variants of an incomplete type, before
14118 : : TYPE_FIELDS has been copied around. */
14119 : 99583761 : if (!COMPLETE_TYPE_P (t1) && !COMPLETE_TYPE_P (t2))
14120 : : return true;
14121 : :
14122 : :
14123 : 90200167 : if (TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2))
14124 : : return false;
14125 : :
14126 : : /* For aggregate types, all the fields must be the same. */
14127 : 90200167 : for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
14128 : 141403370 : f1 || f2;
14129 : 51203203 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
14130 : : {
14131 : : /* Skip non-fields and zero-sized fields, except zero-sized
14132 : : arrays at the end. */
14133 : 1498683289 : while (f1 && (TREE_CODE (f1) != FIELD_DECL
14134 : 92602271 : || (DECL_SIZE (f1)
14135 : 92587656 : && integer_zerop (DECL_SIZE (f1))
14136 : 41399045 : && (TREE_CHAIN (f1)
14137 : 4239 : || TREE_CODE (TREE_TYPE (f1))
14138 : : != ARRAY_TYPE))))
14139 : 1358360134 : f1 = TREE_CHAIN (f1);
14140 : 1498685031 : while (f2 && (TREE_CODE (f2) != FIELD_DECL
14141 : 92653763 : || (DECL_SIZE (f2)
14142 : 92639128 : && integer_zerop (DECL_SIZE (f2))
14143 : 41400792 : && (TREE_CHAIN (f2)
14144 : 5434 : || TREE_CODE (TREE_TYPE (f2))
14145 : : != ARRAY_TYPE))))
14146 : 1358361876 : f2 = TREE_CHAIN (f2);
14147 : 140323155 : if (!f1 || !f2)
14148 : : break;
14149 : :
14150 : 51203430 : tree t1 = TREE_TYPE (f1);
14151 : 51203430 : tree t2 = TREE_TYPE (f2);
14152 : :
14153 : : /* If the last element are arrays, we only compare the element
14154 : : types. */
14155 : 52269341 : if (TREE_CHAIN (f1) == NULL_TREE && TREE_CODE (t1) == ARRAY_TYPE
14156 : 51280188 : && TREE_CHAIN (f2) == NULL_TREE && TREE_CODE (t2) == ARRAY_TYPE)
14157 : : {
14158 : : /* If both arrays have zero size, this is a match. */
14159 : 139309 : if (DECL_SIZE (f1) && integer_zerop (DECL_SIZE (f1))
14160 : 76957 : && DECL_SIZE (f2) && integer_zerop (DECL_SIZE (f2)))
14161 : : return true;
14162 : :
14163 : 76550 : t1 = TREE_TYPE (t1);
14164 : 76550 : t2 = TREE_TYPE (t2);
14165 : : }
14166 : :
14167 : 51203227 : if (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
14168 : 51203222 : || !gimple_compare_field_offset (f1, f2)
14169 : 102406449 : || !gimple_canonical_types_compatible_p
14170 : 51203222 : (t1, t2, trust_type_canonical))
14171 : 24 : return false;
14172 : : }
14173 : :
14174 : : /* If one aggregate has more fields than the other, they
14175 : : are not the same. */
14176 : 90199940 : if (f1 || f2)
14177 : : return false;
14178 : :
14179 : : return true;
14180 : : }
14181 : :
14182 : 346173 : default:
14183 : : /* Consider all types with language specific trees in them mutually
14184 : : compatible. This is executed only from verify_type and false
14185 : : positives can be tolerated. */
14186 : 346173 : gcc_assert (!in_lto_p);
14187 : : return true;
14188 : : }
14189 : : }
14190 : :
14191 : : /* For OPAQUE_TYPE T, it should have only size and alignment information
14192 : : and its mode should be of class MODE_OPAQUE. This function verifies
14193 : : these properties of T match TV which is the main variant of T and TC
14194 : : which is the canonical of T. */
14195 : :
14196 : : static void
14197 : 0 : verify_opaque_type (const_tree t, tree tv, tree tc)
14198 : : {
14199 : 0 : gcc_assert (OPAQUE_TYPE_P (t));
14200 : 0 : gcc_assert (tv && tv == TYPE_MAIN_VARIANT (tv));
14201 : 0 : gcc_assert (tc && tc == TYPE_CANONICAL (tc));
14202 : :
14203 : : /* For an opaque type T1, check if some of its properties match
14204 : : the corresponding ones of the other opaque type T2, emit some
14205 : : error messages for those inconsistent ones. */
14206 : 0 : auto check_properties_for_opaque_type = [](const_tree t1, tree t2,
14207 : : const char *kind_msg)
14208 : : {
14209 : 0 : if (!OPAQUE_TYPE_P (t2))
14210 : : {
14211 : 0 : error ("type %s is not an opaque type", kind_msg);
14212 : 0 : debug_tree (t2);
14213 : 0 : return;
14214 : : }
14215 : 0 : if (!OPAQUE_MODE_P (TYPE_MODE (t2)))
14216 : : {
14217 : 0 : error ("type %s is not with opaque mode", kind_msg);
14218 : 0 : debug_tree (t2);
14219 : 0 : return;
14220 : : }
14221 : 0 : if (TYPE_MODE (t1) != TYPE_MODE (t2))
14222 : : {
14223 : 0 : error ("type %s differs by %<TYPE_MODE%>", kind_msg);
14224 : 0 : debug_tree (t2);
14225 : 0 : return;
14226 : : }
14227 : 0 : poly_uint64 t1_size = tree_to_poly_uint64 (TYPE_SIZE (t1));
14228 : 0 : poly_uint64 t2_size = tree_to_poly_uint64 (TYPE_SIZE (t2));
14229 : 0 : if (maybe_ne (t1_size, t2_size))
14230 : : {
14231 : 0 : error ("type %s differs by %<TYPE_SIZE%>", kind_msg);
14232 : 0 : debug_tree (t2);
14233 : 0 : return;
14234 : : }
14235 : 0 : if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2))
14236 : : {
14237 : 0 : error ("type %s differs by %<TYPE_ALIGN%>", kind_msg);
14238 : 0 : debug_tree (t2);
14239 : 0 : return;
14240 : : }
14241 : 0 : if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
14242 : : {
14243 : 0 : error ("type %s differs by %<TYPE_USER_ALIGN%>", kind_msg);
14244 : 0 : debug_tree (t2);
14245 : 0 : return;
14246 : : }
14247 : : };
14248 : :
14249 : 0 : if (t != tv)
14250 : 0 : check_properties_for_opaque_type (t, tv, "variant");
14251 : :
14252 : 0 : if (t != tc)
14253 : 0 : check_properties_for_opaque_type (t, tc, "canonical");
14254 : 0 : }
14255 : :
14256 : : /* Verify type T. */
14257 : :
14258 : : void
14259 : 708734879 : verify_type (const_tree t)
14260 : : {
14261 : 708734879 : bool error_found = false;
14262 : 708734879 : tree mv = TYPE_MAIN_VARIANT (t);
14263 : 708734879 : tree ct = TYPE_CANONICAL (t);
14264 : :
14265 : 708734879 : if (OPAQUE_TYPE_P (t))
14266 : : {
14267 : 0 : verify_opaque_type (t, mv, ct);
14268 : 0 : return;
14269 : : }
14270 : :
14271 : 708734879 : if (!mv)
14272 : : {
14273 : 0 : error ("main variant is not defined");
14274 : 0 : error_found = true;
14275 : : }
14276 : 708734879 : else if (mv != TYPE_MAIN_VARIANT (mv))
14277 : : {
14278 : 0 : error ("%<TYPE_MAIN_VARIANT%> has different %<TYPE_MAIN_VARIANT%>");
14279 : 0 : debug_tree (mv);
14280 : 0 : error_found = true;
14281 : : }
14282 : 708734879 : else if (t != mv && !verify_type_variant (t, mv))
14283 : : error_found = true;
14284 : :
14285 : 708734879 : if (!ct)
14286 : : ;
14287 : 706741002 : else if (TYPE_CANONICAL (ct) != ct)
14288 : : {
14289 : 0 : error ("%<TYPE_CANONICAL%> has different %<TYPE_CANONICAL%>");
14290 : 0 : debug_tree (ct);
14291 : 0 : error_found = true;
14292 : : }
14293 : : /* Method and function types cannot be used to address memory and thus
14294 : : TYPE_CANONICAL really matters only for determining useless conversions.
14295 : :
14296 : : FIXME: C++ FE produce declarations of builtin functions that are not
14297 : : compatible with main variants. */
14298 : 706741002 : else if (TREE_CODE (t) == FUNCTION_TYPE)
14299 : : ;
14300 : 703920818 : else if (t != ct
14301 : : /* FIXME: gimple_canonical_types_compatible_p cannot compare types
14302 : : with variably sized arrays because their sizes possibly
14303 : : gimplified to different variables. */
14304 : 120447722 : && !variably_modified_type_p (ct, NULL)
14305 : 120443468 : && !gimple_canonical_types_compatible_p (t, ct, false)
14306 : 703970568 : && COMPLETE_TYPE_P (t))
14307 : : {
14308 : 0 : error ("%<TYPE_CANONICAL%> is not compatible");
14309 : 0 : debug_tree (ct);
14310 : 0 : error_found = true;
14311 : : }
14312 : 1274052907 : if (COMPLETE_TYPE_P (t) && TYPE_CANONICAL (t)
14313 : : /* We allow a mismatch for structure or union because of
14314 : : flexible array members. */
14315 : 563390048 : && !RECORD_OR_UNION_TYPE_P (t)
14316 : 237048691 : && !RECORD_OR_UNION_TYPE_P (TYPE_CANONICAL (t))
14317 : 237048691 : && TREE_CODE (t) != ARRAY_TYPE
14318 : 944432074 : && TYPE_MODE (t) != TYPE_MODE (TYPE_CANONICAL (t)))
14319 : : {
14320 : 0 : error ("%<TYPE_MODE%> of %<TYPE_CANONICAL%> is not compatible");
14321 : 0 : debug_tree (ct);
14322 : 0 : error_found = true;
14323 : : }
14324 : 708734879 : if (TYPE_MAIN_VARIANT (t) == t && ct && TYPE_MAIN_VARIANT (ct) != ct)
14325 : : {
14326 : 0 : error ("%<TYPE_CANONICAL%> of main variant is not main variant");
14327 : 0 : debug_tree (ct);
14328 : 0 : debug_tree (TYPE_MAIN_VARIANT (ct));
14329 : 0 : error_found = true;
14330 : : }
14331 : :
14332 : :
14333 : : /* Check various uses of TYPE_MIN_VALUE_RAW. */
14334 : 708734879 : if (RECORD_OR_UNION_TYPE_P (t))
14335 : : {
14336 : : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
14337 : : and danagle the pointer from time to time. */
14338 : 366137816 : if (TYPE_VFIELD (t)
14339 : 10168353 : && TREE_CODE (TYPE_VFIELD (t)) != FIELD_DECL
14340 : 366137816 : && TREE_CODE (TYPE_VFIELD (t)) != TREE_LIST)
14341 : : {
14342 : 0 : error ("%<TYPE_VFIELD%> is not %<FIELD_DECL%> nor %<TREE_LIST%>");
14343 : 0 : debug_tree (TYPE_VFIELD (t));
14344 : 0 : error_found = true;
14345 : : }
14346 : : }
14347 : 342597063 : else if (TREE_CODE (t) == POINTER_TYPE)
14348 : : {
14349 : 91326400 : if (TYPE_NEXT_PTR_TO (t)
14350 : 91326400 : && TREE_CODE (TYPE_NEXT_PTR_TO (t)) != POINTER_TYPE)
14351 : : {
14352 : 0 : error ("%<TYPE_NEXT_PTR_TO%> is not %<POINTER_TYPE%>");
14353 : 0 : debug_tree (TYPE_NEXT_PTR_TO (t));
14354 : 0 : error_found = true;
14355 : : }
14356 : : }
14357 : 251270663 : else if (TREE_CODE (t) == REFERENCE_TYPE)
14358 : : {
14359 : 41961031 : if (TYPE_NEXT_REF_TO (t)
14360 : 41961031 : && TREE_CODE (TYPE_NEXT_REF_TO (t)) != REFERENCE_TYPE)
14361 : : {
14362 : 0 : error ("%<TYPE_NEXT_REF_TO%> is not %<REFERENCE_TYPE%>");
14363 : 0 : debug_tree (TYPE_NEXT_REF_TO (t));
14364 : 0 : error_found = true;
14365 : : }
14366 : : }
14367 : : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14368 : : || FIXED_POINT_TYPE_P (t))
14369 : : {
14370 : : /* FIXME: The following check should pass:
14371 : : useless_type_conversion_p (const_cast <tree> (t),
14372 : : TREE_TYPE (TYPE_MIN_VALUE (t))
14373 : : but does not for C sizetypes in LTO. */
14374 : : }
14375 : :
14376 : : /* Check various uses of TYPE_MAXVAL_RAW. */
14377 : 708734879 : if (RECORD_OR_UNION_TYPE_P (t))
14378 : : {
14379 : 366137816 : if (!TYPE_BINFO (t))
14380 : : ;
14381 : 341287651 : else if (TREE_CODE (TYPE_BINFO (t)) != TREE_BINFO)
14382 : : {
14383 : 0 : error ("%<TYPE_BINFO%> is not %<TREE_BINFO%>");
14384 : 0 : debug_tree (TYPE_BINFO (t));
14385 : 0 : error_found = true;
14386 : : }
14387 : 341287651 : else if (TREE_TYPE (TYPE_BINFO (t)) != TYPE_MAIN_VARIANT (t))
14388 : : {
14389 : 0 : error ("%<TYPE_BINFO%> type is not %<TYPE_MAIN_VARIANT%>");
14390 : 0 : debug_tree (TREE_TYPE (TYPE_BINFO (t)));
14391 : 0 : error_found = true;
14392 : : }
14393 : : }
14394 : : else if (FUNC_OR_METHOD_TYPE_P (t))
14395 : : {
14396 : 3065153 : if (TYPE_METHOD_BASETYPE (t)
14397 : 95634 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != RECORD_TYPE
14398 : 3065371 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != UNION_TYPE)
14399 : : {
14400 : 0 : error ("%<TYPE_METHOD_BASETYPE%> is not record nor union");
14401 : 0 : debug_tree (TYPE_METHOD_BASETYPE (t));
14402 : 0 : error_found = true;
14403 : : }
14404 : : }
14405 : : else if (TREE_CODE (t) == OFFSET_TYPE)
14406 : : {
14407 : 35133 : if (TYPE_OFFSET_BASETYPE (t)
14408 : 35133 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != RECORD_TYPE
14409 : 35141 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != UNION_TYPE)
14410 : : {
14411 : 0 : error ("%<TYPE_OFFSET_BASETYPE%> is not record nor union");
14412 : 0 : debug_tree (TYPE_OFFSET_BASETYPE (t));
14413 : 0 : error_found = true;
14414 : : }
14415 : : }
14416 : : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14417 : : || FIXED_POINT_TYPE_P (t))
14418 : : {
14419 : : /* FIXME: The following check should pass:
14420 : : useless_type_conversion_p (const_cast <tree> (t),
14421 : : TREE_TYPE (TYPE_MAX_VALUE (t))
14422 : : but does not for C sizetypes in LTO. */
14423 : : }
14424 : : else if (TREE_CODE (t) == ARRAY_TYPE)
14425 : : {
14426 : 1593384 : if (TYPE_ARRAY_MAX_SIZE (t)
14427 : 1593384 : && TREE_CODE (TYPE_ARRAY_MAX_SIZE (t)) != INTEGER_CST)
14428 : : {
14429 : 0 : error ("%<TYPE_ARRAY_MAX_SIZE%> not %<INTEGER_CST%>");
14430 : 0 : debug_tree (TYPE_ARRAY_MAX_SIZE (t));
14431 : 0 : error_found = true;
14432 : : }
14433 : : }
14434 : 238135055 : else if (TYPE_MAX_VALUE_RAW (t))
14435 : : {
14436 : 0 : error ("%<TYPE_MAX_VALUE_RAW%> non-NULL");
14437 : 0 : debug_tree (TYPE_MAX_VALUE_RAW (t));
14438 : 0 : error_found = true;
14439 : : }
14440 : :
14441 : 708734879 : if (TYPE_LANG_SLOT_1 (t) && in_lto_p)
14442 : : {
14443 : 0 : error ("%<TYPE_LANG_SLOT_1 (binfo)%> field is non-NULL");
14444 : 0 : debug_tree (TYPE_LANG_SLOT_1 (t));
14445 : 0 : error_found = true;
14446 : : }
14447 : :
14448 : : /* Check various uses of TYPE_VALUES_RAW. */
14449 : 708734879 : if (TREE_CODE (t) == ENUMERAL_TYPE)
14450 : 84000829 : for (tree l = TYPE_VALUES (t); l; l = TREE_CHAIN (l))
14451 : : {
14452 : 73576268 : tree value = TREE_VALUE (l);
14453 : 73576268 : tree name = TREE_PURPOSE (l);
14454 : :
14455 : : /* C FE porduce INTEGER_CST of INTEGER_TYPE, while C++ FE uses
14456 : : CONST_DECL of ENUMERAL TYPE. */
14457 : 73576268 : if (TREE_CODE (value) != INTEGER_CST && TREE_CODE (value) != CONST_DECL)
14458 : : {
14459 : 0 : error ("enum value is not %<CONST_DECL%> or %<INTEGER_CST%>");
14460 : 0 : debug_tree (value);
14461 : 0 : debug_tree (name);
14462 : 0 : error_found = true;
14463 : : }
14464 : 73576268 : if (TREE_CODE (TREE_TYPE (value)) != INTEGER_TYPE
14465 : 73559712 : && TREE_CODE (TREE_TYPE (value)) != BOOLEAN_TYPE
14466 : 147135977 : && !useless_type_conversion_p (const_cast <tree> (t), TREE_TYPE (value)))
14467 : : {
14468 : 0 : error ("enum value type is not %<INTEGER_TYPE%> nor convertible "
14469 : : "to the enum");
14470 : 0 : debug_tree (value);
14471 : 0 : debug_tree (name);
14472 : 0 : error_found = true;
14473 : : }
14474 : 73576268 : if (TREE_CODE (name) != IDENTIFIER_NODE)
14475 : : {
14476 : 0 : error ("enum value name is not %<IDENTIFIER_NODE%>");
14477 : 0 : debug_tree (value);
14478 : 0 : debug_tree (name);
14479 : 0 : error_found = true;
14480 : : }
14481 : : }
14482 : 698310318 : else if (TREE_CODE (t) == ARRAY_TYPE)
14483 : : {
14484 : 1593384 : if (TYPE_DOMAIN (t) && TREE_CODE (TYPE_DOMAIN (t)) != INTEGER_TYPE)
14485 : : {
14486 : 0 : error ("array %<TYPE_DOMAIN%> is not integer type");
14487 : 0 : debug_tree (TYPE_DOMAIN (t));
14488 : 0 : error_found = true;
14489 : : }
14490 : : }
14491 : 696716934 : else if (RECORD_OR_UNION_TYPE_P (t))
14492 : : {
14493 : 366137816 : if (TYPE_FIELDS (t) && !COMPLETE_TYPE_P (t) && in_lto_p)
14494 : : {
14495 : 0 : error ("%<TYPE_FIELDS%> defined in incomplete type");
14496 : 0 : error_found = true;
14497 : : }
14498 : 16793642260 : for (tree fld = TYPE_FIELDS (t); fld; fld = TREE_CHAIN (fld))
14499 : : {
14500 : : /* TODO: verify properties of decls. */
14501 : 16427504444 : if (TREE_CODE (fld) == FIELD_DECL)
14502 : : ;
14503 : : else if (TREE_CODE (fld) == TYPE_DECL)
14504 : : ;
14505 : : else if (TREE_CODE (fld) == CONST_DECL)
14506 : : ;
14507 : : else if (VAR_P (fld))
14508 : : ;
14509 : : else if (TREE_CODE (fld) == TEMPLATE_DECL)
14510 : : ;
14511 : : else if (TREE_CODE (fld) == USING_DECL)
14512 : : ;
14513 : : else if (TREE_CODE (fld) == FUNCTION_DECL)
14514 : : ;
14515 : : else
14516 : : {
14517 : 0 : error ("wrong tree in %<TYPE_FIELDS%> list");
14518 : 0 : debug_tree (fld);
14519 : 0 : error_found = true;
14520 : : }
14521 : : }
14522 : : }
14523 : 330579118 : else if (TREE_CODE (t) == INTEGER_TYPE
14524 : : || TREE_CODE (t) == BOOLEAN_TYPE
14525 : 330579118 : || TREE_CODE (t) == BITINT_TYPE
14526 : 244885466 : || TREE_CODE (t) == OFFSET_TYPE
14527 : 244850333 : || TREE_CODE (t) == REFERENCE_TYPE
14528 : 202889302 : || TREE_CODE (t) == NULLPTR_TYPE
14529 : 202597780 : || TREE_CODE (t) == POINTER_TYPE)
14530 : : {
14531 : 219307738 : if (TYPE_CACHED_VALUES_P (t) != (TYPE_CACHED_VALUES (t) != NULL))
14532 : : {
14533 : 0 : error ("%<TYPE_CACHED_VALUES_P%> is %i while %<TYPE_CACHED_VALUES%> "
14534 : : "is %p",
14535 : 0 : TYPE_CACHED_VALUES_P (t), (void *)TYPE_CACHED_VALUES (t));
14536 : 0 : error_found = true;
14537 : : }
14538 : 219307738 : else if (TYPE_CACHED_VALUES_P (t) && TREE_CODE (TYPE_CACHED_VALUES (t)) != TREE_VEC)
14539 : : {
14540 : 0 : error ("%<TYPE_CACHED_VALUES%> is not %<TREE_VEC%>");
14541 : 0 : debug_tree (TYPE_CACHED_VALUES (t));
14542 : 0 : error_found = true;
14543 : : }
14544 : : /* Verify just enough of cache to ensure that no one copied it to new type.
14545 : : All copying should go by copy_node that should clear it. */
14546 : 219307738 : else if (TYPE_CACHED_VALUES_P (t))
14547 : : {
14548 : : int i;
14549 : 7659058750 : for (i = 0; i < TREE_VEC_LENGTH (TYPE_CACHED_VALUES (t)); i++)
14550 : 7612899319 : if (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)
14551 : 7612899319 : && TREE_TYPE (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)) != t)
14552 : : {
14553 : 0 : error ("wrong %<TYPE_CACHED_VALUES%> entry");
14554 : 0 : debug_tree (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i));
14555 : 0 : error_found = true;
14556 : 0 : break;
14557 : : }
14558 : : }
14559 : : }
14560 : 111271380 : else if (FUNC_OR_METHOD_TYPE_P (t))
14561 : 12336749 : for (tree l = TYPE_ARG_TYPES (t); l; l = TREE_CHAIN (l))
14562 : : {
14563 : : /* C++ FE uses TREE_PURPOSE to store initial values. */
14564 : 9271596 : if (TREE_PURPOSE (l) && in_lto_p)
14565 : : {
14566 : 0 : error ("%<TREE_PURPOSE%> is non-NULL in %<TYPE_ARG_TYPES%> list");
14567 : 0 : debug_tree (l);
14568 : 0 : error_found = true;
14569 : : }
14570 : 9271596 : if (!TYPE_P (TREE_VALUE (l)))
14571 : : {
14572 : 0 : error ("wrong entry in %<TYPE_ARG_TYPES%> list");
14573 : 0 : debug_tree (l);
14574 : 0 : error_found = true;
14575 : : }
14576 : : }
14577 : 216045873 : else if (!is_lang_specific (t) && TYPE_VALUES_RAW (t))
14578 : : {
14579 : 0 : error ("%<TYPE_VALUES_RAW%> field is non-NULL");
14580 : 0 : debug_tree (TYPE_VALUES_RAW (t));
14581 : 0 : error_found = true;
14582 : : }
14583 : 708734879 : if (TREE_CODE (t) != INTEGER_TYPE
14584 : : && TREE_CODE (t) != BOOLEAN_TYPE
14585 : 708734879 : && TREE_CODE (t) != BITINT_TYPE
14586 : : && TREE_CODE (t) != OFFSET_TYPE
14587 : : && TREE_CODE (t) != REFERENCE_TYPE
14588 : : && TREE_CODE (t) != NULLPTR_TYPE
14589 : : && TREE_CODE (t) != POINTER_TYPE
14590 : 489427141 : && TYPE_CACHED_VALUES_P (t))
14591 : : {
14592 : 0 : error ("%<TYPE_CACHED_VALUES_P%> is set while it should not be");
14593 : 0 : error_found = true;
14594 : : }
14595 : :
14596 : : /* ipa-devirt makes an assumption that TYPE_METHOD_BASETYPE is always
14597 : : TYPE_MAIN_VARIANT and it would be odd to add methods only to variatns
14598 : : of a type. */
14599 : 708734879 : if (TREE_CODE (t) == METHOD_TYPE
14600 : 708734879 : && TYPE_MAIN_VARIANT (TYPE_METHOD_BASETYPE (t)) != TYPE_METHOD_BASETYPE (t))
14601 : : {
14602 : 0 : error ("%<TYPE_METHOD_BASETYPE%> is not main variant");
14603 : 0 : error_found = true;
14604 : : }
14605 : :
14606 : 708734879 : if (error_found)
14607 : : {
14608 : 0 : debug_tree (const_cast <tree> (t));
14609 : 0 : internal_error ("%qs failed", __func__);
14610 : : }
14611 : : }
14612 : :
14613 : :
14614 : : /* Return 1 if ARG interpreted as signed in its precision is known to be
14615 : : always non-negative or 2 if ARG is known to be always negative, or 3 if
14616 : : ARG may be non-negative or negative. STMT if specified is the statement
14617 : : on which it is being tested. */
14618 : :
14619 : : int
14620 : 832770 : get_range_pos_neg (tree arg, gimple *stmt)
14621 : : {
14622 : 832770 : if (arg == error_mark_node)
14623 : : return 3;
14624 : :
14625 : 832770 : int prec = TYPE_PRECISION (TREE_TYPE (arg));
14626 : 832770 : int cnt = 0;
14627 : 832770 : if (TREE_CODE (arg) == INTEGER_CST)
14628 : : {
14629 : 83205 : wide_int w = wi::sext (wi::to_wide (arg), prec);
14630 : 83205 : if (wi::neg_p (w))
14631 : : return 2;
14632 : : else
14633 : 68868 : return 1;
14634 : 83205 : }
14635 : 748354 : while (CONVERT_EXPR_P (arg)
14636 : 14493 : && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
14637 : 777340 : && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg, 0))) <= prec)
14638 : : {
14639 : 13709 : arg = TREE_OPERAND (arg, 0);
14640 : : /* Narrower value zero extended into wider type
14641 : : will always result in positive values. */
14642 : 13709 : if (TYPE_UNSIGNED (TREE_TYPE (arg))
14643 : 13709 : && TYPE_PRECISION (TREE_TYPE (arg)) < prec)
14644 : : return 1;
14645 : 13282 : prec = TYPE_PRECISION (TREE_TYPE (arg));
14646 : 13282 : if (++cnt > 30)
14647 : : return 3;
14648 : : }
14649 : :
14650 : 749138 : if (TREE_CODE (arg) != SSA_NAME)
14651 : : return 3;
14652 : 742602 : int_range_max r;
14653 : 1499498 : while (!get_range_query (cfun)->range_of_expr (r, arg, stmt)
14654 : 1513792 : || r.undefined_p () || r.varying_p ())
14655 : : {
14656 : 444908 : gimple *g = SSA_NAME_DEF_STMT (arg);
14657 : 444908 : if (is_gimple_assign (g)
14658 : 444908 : && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (g)))
14659 : : {
14660 : 25881 : tree t = gimple_assign_rhs1 (g);
14661 : 51408 : if (INTEGRAL_TYPE_P (TREE_TYPE (t))
14662 : 48770 : && TYPE_PRECISION (TREE_TYPE (t)) <= prec)
14663 : : {
14664 : 14294 : if (TYPE_UNSIGNED (TREE_TYPE (t))
14665 : 14294 : && TYPE_PRECISION (TREE_TYPE (t)) < prec)
14666 : : return 1;
14667 : 14294 : prec = TYPE_PRECISION (TREE_TYPE (t));
14668 : 14294 : arg = t;
14669 : 14294 : if (++cnt > 30)
14670 : : return 3;
14671 : 14294 : continue;
14672 : : }
14673 : : }
14674 : : return 3;
14675 : : }
14676 : 311988 : if (TYPE_UNSIGNED (TREE_TYPE (arg)))
14677 : : {
14678 : : /* For unsigned values, the "positive" range comes
14679 : : below the "negative" range. */
14680 : 140949 : if (!wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14681 : : return 1;
14682 : 44783 : if (wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14683 : : return 2;
14684 : : }
14685 : : else
14686 : : {
14687 : 171039 : if (!wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14688 : : return 1;
14689 : 69811 : if (wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14690 : : return 2;
14691 : : }
14692 : : return 3;
14693 : 742602 : }
14694 : :
14695 : :
14696 : :
14697 : :
14698 : : /* Return true if ARG is marked with the nonnull attribute in the
14699 : : current function signature. */
14700 : :
14701 : : bool
14702 : 26208176 : nonnull_arg_p (const_tree arg)
14703 : : {
14704 : 26208176 : tree t, attrs, fntype;
14705 : 26208176 : unsigned HOST_WIDE_INT arg_num;
14706 : :
14707 : 26208176 : gcc_assert (TREE_CODE (arg) == PARM_DECL
14708 : : && (POINTER_TYPE_P (TREE_TYPE (arg))
14709 : : || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE));
14710 : :
14711 : : /* The static chain decl is always non null. */
14712 : 26208176 : if (arg == cfun->static_chain_decl)
14713 : : return true;
14714 : :
14715 : : /* THIS argument of method is always non-NULL. */
14716 : 25939916 : if (TREE_CODE (TREE_TYPE (cfun->decl)) == METHOD_TYPE
14717 : 10312452 : && arg == DECL_ARGUMENTS (cfun->decl)
14718 : 32304843 : && flag_delete_null_pointer_checks)
14719 : : return true;
14720 : :
14721 : : /* Values passed by reference are always non-NULL. */
14722 : 19577121 : if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE
14723 : 19577121 : && flag_delete_null_pointer_checks)
14724 : : return true;
14725 : :
14726 : 13351156 : fntype = TREE_TYPE (cfun->decl);
14727 : 13374100 : for (attrs = TYPE_ATTRIBUTES (fntype); attrs; attrs = TREE_CHAIN (attrs))
14728 : : {
14729 : 533757 : attrs = lookup_attribute ("nonnull", attrs);
14730 : :
14731 : : /* If "nonnull" wasn't specified, we know nothing about the argument. */
14732 : 533757 : if (attrs == NULL_TREE)
14733 : : return false;
14734 : :
14735 : : /* If "nonnull" applies to all the arguments, then ARG is non-null. */
14736 : 110729 : if (TREE_VALUE (attrs) == NULL_TREE)
14737 : : return true;
14738 : :
14739 : : /* Get the position number for ARG in the function signature. */
14740 : 55628 : for (arg_num = 1, t = DECL_ARGUMENTS (cfun->decl);
14741 : 130138 : t;
14742 : 74510 : t = DECL_CHAIN (t), arg_num++)
14743 : : {
14744 : 130138 : if (t == arg)
14745 : : break;
14746 : : }
14747 : :
14748 : 55628 : gcc_assert (t == arg);
14749 : :
14750 : : /* Now see if ARG_NUM is mentioned in the nonnull list. */
14751 : 88294 : for (t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
14752 : : {
14753 : 65350 : if (compare_tree_int (TREE_VALUE (t), arg_num) == 0)
14754 : : return true;
14755 : : }
14756 : : }
14757 : :
14758 : : return false;
14759 : : }
14760 : :
14761 : : /* Combine LOC and BLOCK to a combined adhoc loc, retaining any range
14762 : : information. */
14763 : :
14764 : : location_t
14765 : 646634793 : set_block (location_t loc, tree block)
14766 : : {
14767 : 646634793 : location_t pure_loc = get_pure_location (loc);
14768 : 646634793 : source_range src_range = get_range_from_loc (line_table, loc);
14769 : 646634793 : unsigned discriminator = get_discriminator_from_loc (line_table, loc);
14770 : 646634793 : return line_table->get_or_create_combined_loc (pure_loc, src_range, block,
14771 : 646634793 : discriminator);
14772 : : }
14773 : :
14774 : : location_t
14775 : 216130496 : set_source_range (tree expr, location_t start, location_t finish)
14776 : : {
14777 : 216130496 : source_range src_range;
14778 : 216130496 : src_range.m_start = start;
14779 : 216130496 : src_range.m_finish = finish;
14780 : 216130496 : return set_source_range (expr, src_range);
14781 : : }
14782 : :
14783 : : location_t
14784 : 441556306 : set_source_range (tree expr, source_range src_range)
14785 : : {
14786 : 441556306 : if (!EXPR_P (expr))
14787 : : return UNKNOWN_LOCATION;
14788 : :
14789 : 194277009 : location_t expr_location = EXPR_LOCATION (expr);
14790 : 194277009 : location_t pure_loc = get_pure_location (expr_location);
14791 : 194277009 : unsigned discriminator = get_discriminator_from_loc (expr_location);
14792 : 194277009 : location_t adhoc = line_table->get_or_create_combined_loc (pure_loc,
14793 : : src_range,
14794 : : nullptr,
14795 : : discriminator);
14796 : 194277009 : SET_EXPR_LOCATION (expr, adhoc);
14797 : 194277009 : return adhoc;
14798 : : }
14799 : :
14800 : : /* Return EXPR, potentially wrapped with a node expression LOC,
14801 : : if !CAN_HAVE_LOCATION_P (expr).
14802 : :
14803 : : NON_LVALUE_EXPR is used for wrapping constants, apart from STRING_CST.
14804 : : VIEW_CONVERT_EXPR is used for wrapping non-constants and STRING_CST.
14805 : :
14806 : : Wrapper nodes can be identified using location_wrapper_p. */
14807 : :
14808 : : tree
14809 : 1206000901 : maybe_wrap_with_location (tree expr, location_t loc)
14810 : : {
14811 : 1206000901 : if (expr == NULL)
14812 : : return NULL;
14813 : 1206000897 : if (loc == UNKNOWN_LOCATION)
14814 : : return expr;
14815 : 1166431647 : if (CAN_HAVE_LOCATION_P (expr))
14816 : : return expr;
14817 : : /* We should only be adding wrappers for constants and for decls,
14818 : : or for some exceptional tree nodes (e.g. BASELINK in the C++ FE). */
14819 : 703633029 : gcc_assert (CONSTANT_CLASS_P (expr)
14820 : : || DECL_P (expr)
14821 : : || EXCEPTIONAL_CLASS_P (expr));
14822 : :
14823 : : /* For now, don't add wrappers to exceptional tree nodes, to minimize
14824 : : any impact of the wrapper nodes. */
14825 : 703633029 : if (EXCEPTIONAL_CLASS_P (expr) || error_operand_p (expr))
14826 : : return expr;
14827 : :
14828 : : /* Compiler-generated temporary variables don't need a wrapper. */
14829 : 647540917 : if (DECL_P (expr) && DECL_ARTIFICIAL (expr) && DECL_IGNORED_P (expr))
14830 : : return expr;
14831 : :
14832 : : /* If any auto_suppress_location_wrappers are active, don't create
14833 : : wrappers. */
14834 : 647538660 : if (suppress_location_wrappers > 0)
14835 : : return expr;
14836 : :
14837 : 1235293602 : tree_code code
14838 : 153110564 : = (((CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST)
14839 : 471297081 : || (TREE_CODE (expr) == CONST_DECL && !TREE_STATIC (expr)))
14840 : 617646801 : ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR);
14841 : 617646801 : tree wrapper = build1_loc (loc, code, TREE_TYPE (expr), expr);
14842 : : /* Mark this node as being a wrapper. */
14843 : 617646801 : EXPR_LOCATION_WRAPPER_P (wrapper) = 1;
14844 : 617646801 : return wrapper;
14845 : : }
14846 : :
14847 : : int suppress_location_wrappers;
14848 : :
14849 : : /* Return the name of combined function FN, for debugging purposes. */
14850 : :
14851 : : const char *
14852 : 0 : combined_fn_name (combined_fn fn)
14853 : : {
14854 : 0 : if (builtin_fn_p (fn))
14855 : : {
14856 : 0 : tree fndecl = builtin_decl_explicit (as_builtin_fn (fn));
14857 : 0 : return IDENTIFIER_POINTER (DECL_NAME (fndecl));
14858 : : }
14859 : : else
14860 : 0 : return internal_fn_name (as_internal_fn (fn));
14861 : : }
14862 : :
14863 : : /* Return a bitmap with a bit set corresponding to each argument in
14864 : : a function call type FNTYPE declared with attribute nonnull,
14865 : : or null if none of the function's argument are nonnull. The caller
14866 : : must free the bitmap. */
14867 : :
14868 : : bitmap
14869 : 20980534 : get_nonnull_args (const_tree fntype)
14870 : : {
14871 : 20980534 : if (fntype == NULL_TREE)
14872 : : return NULL;
14873 : :
14874 : 20571872 : bitmap argmap = NULL;
14875 : 20571872 : if (TREE_CODE (fntype) == METHOD_TYPE)
14876 : : {
14877 : : /* The this pointer in C++ non-static member functions is
14878 : : implicitly nonnull whether or not it's declared as such. */
14879 : 2897396 : argmap = BITMAP_ALLOC (NULL);
14880 : 2897396 : bitmap_set_bit (argmap, 0);
14881 : : }
14882 : :
14883 : 20571872 : tree attrs = TYPE_ATTRIBUTES (fntype);
14884 : 20571872 : if (!attrs)
14885 : : return argmap;
14886 : :
14887 : : /* A function declaration can specify multiple attribute nonnull,
14888 : : each with zero or more arguments. The loop below creates a bitmap
14889 : : representing a union of all the arguments. An empty (but non-null)
14890 : : bitmap means that all arguments have been declared nonnull. */
14891 : 5592042 : for ( ; attrs; attrs = TREE_CHAIN (attrs))
14892 : : {
14893 : 5505626 : attrs = lookup_attribute ("nonnull", attrs);
14894 : 5505626 : if (!attrs)
14895 : : break;
14896 : :
14897 : 1602715 : if (!argmap)
14898 : 1562840 : argmap = BITMAP_ALLOC (NULL);
14899 : :
14900 : 1602715 : if (!TREE_VALUE (attrs))
14901 : : {
14902 : : /* Clear the bitmap in case a previous attribute nonnull
14903 : : set it and this one overrides it for all arguments. */
14904 : 994918 : bitmap_clear (argmap);
14905 : 994918 : return argmap;
14906 : : }
14907 : :
14908 : : /* Iterate over the indices of the format arguments declared nonnull
14909 : : and set a bit for each. */
14910 : 1608736 : for (tree idx = TREE_VALUE (attrs); idx; idx = TREE_CHAIN (idx))
14911 : : {
14912 : 1000939 : unsigned int val = TREE_INT_CST_LOW (TREE_VALUE (idx)) - 1;
14913 : 1000939 : bitmap_set_bit (argmap, val);
14914 : : }
14915 : : }
14916 : :
14917 : : return argmap;
14918 : : }
14919 : :
14920 : : /* Returns true if TYPE is a type where it and all of its subobjects
14921 : : (recursively) are of structure, union, or array type. */
14922 : :
14923 : : bool
14924 : 1753676141 : is_empty_type (const_tree type)
14925 : : {
14926 : 1753676141 : if (RECORD_OR_UNION_TYPE_P (type))
14927 : : {
14928 : 755423058 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
14929 : 703793235 : if (TREE_CODE (field) == FIELD_DECL
14930 : 394389374 : && !DECL_PADDING_P (field)
14931 : 1098181373 : && !is_empty_type (TREE_TYPE (field)))
14932 : : return false;
14933 : : return true;
14934 : : }
14935 : 1329331645 : else if (TREE_CODE (type) == ARRAY_TYPE)
14936 : 70775949 : return (integer_minus_onep (array_type_nelts_minus_one (type))
14937 : 70732679 : || TYPE_DOMAIN (type) == NULL_TREE
14938 : 135898035 : || is_empty_type (TREE_TYPE (type)));
14939 : : return false;
14940 : : }
14941 : :
14942 : : /* Implement TARGET_EMPTY_RECORD_P. Return true if TYPE is an empty type
14943 : : that shouldn't be passed via stack. */
14944 : :
14945 : : bool
14946 : 1244980341 : default_is_empty_record (const_tree type)
14947 : : {
14948 : 1244980341 : if (!abi_version_at_least (12))
14949 : : return false;
14950 : :
14951 : 1243935077 : if (type == error_mark_node)
14952 : : return false;
14953 : :
14954 : 1243935077 : if (TREE_ADDRESSABLE (type))
14955 : : return false;
14956 : :
14957 : 1243935077 : return is_empty_type (TYPE_MAIN_VARIANT (type));
14958 : : }
14959 : :
14960 : : /* Determine whether TYPE is a structure with a flexible array member,
14961 : : or a union containing such a structure (possibly recursively). */
14962 : :
14963 : : bool
14964 : 72522 : flexible_array_type_p (const_tree type)
14965 : : {
14966 : 72522 : tree x, last;
14967 : 72522 : switch (TREE_CODE (type))
14968 : : {
14969 : 37377 : case RECORD_TYPE:
14970 : 37377 : last = NULL_TREE;
14971 : 171072 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
14972 : 133695 : if (TREE_CODE (x) == FIELD_DECL)
14973 : 133695 : last = x;
14974 : 37377 : if (last == NULL_TREE)
14975 : : return false;
14976 : 37370 : if (TREE_CODE (TREE_TYPE (last)) == ARRAY_TYPE
14977 : 473 : && TYPE_SIZE (TREE_TYPE (last)) == NULL_TREE
14978 : 239 : && TYPE_DOMAIN (TREE_TYPE (last)) != NULL_TREE
14979 : 37609 : && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (last))) == NULL_TREE)
14980 : : return true;
14981 : : return false;
14982 : 616 : case UNION_TYPE:
14983 : 1782 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
14984 : : {
14985 : 1208 : if (TREE_CODE (x) == FIELD_DECL
14986 : 1208 : && flexible_array_type_p (TREE_TYPE (x)))
14987 : : return true;
14988 : : }
14989 : : return false;
14990 : : default:
14991 : : return false;
14992 : : }
14993 : : }
14994 : :
14995 : : /* Like int_size_in_bytes, but handle empty records specially. */
14996 : :
14997 : : HOST_WIDE_INT
14998 : 371005 : arg_int_size_in_bytes (const_tree type)
14999 : : {
15000 : 371005 : return TYPE_EMPTY_P (type) ? 0 : int_size_in_bytes (type);
15001 : : }
15002 : :
15003 : : /* Like size_in_bytes, but handle empty records specially. */
15004 : :
15005 : : tree
15006 : 5607308 : arg_size_in_bytes (const_tree type)
15007 : : {
15008 : 5607308 : return TYPE_EMPTY_P (type) ? size_zero_node : size_in_bytes (type);
15009 : : }
15010 : :
15011 : : /* Return true if an expression with CODE has to have the same result type as
15012 : : its first operand. */
15013 : :
15014 : : bool
15015 : 0 : expr_type_first_operand_type_p (tree_code code)
15016 : : {
15017 : 0 : switch (code)
15018 : : {
15019 : : case NEGATE_EXPR:
15020 : : case ABS_EXPR:
15021 : : case BIT_NOT_EXPR:
15022 : : case PAREN_EXPR:
15023 : : case CONJ_EXPR:
15024 : :
15025 : : case PLUS_EXPR:
15026 : : case MINUS_EXPR:
15027 : : case MULT_EXPR:
15028 : : case TRUNC_DIV_EXPR:
15029 : : case CEIL_DIV_EXPR:
15030 : : case FLOOR_DIV_EXPR:
15031 : : case ROUND_DIV_EXPR:
15032 : : case TRUNC_MOD_EXPR:
15033 : : case CEIL_MOD_EXPR:
15034 : : case FLOOR_MOD_EXPR:
15035 : : case ROUND_MOD_EXPR:
15036 : : case RDIV_EXPR:
15037 : : case EXACT_DIV_EXPR:
15038 : : case MIN_EXPR:
15039 : : case MAX_EXPR:
15040 : : case BIT_IOR_EXPR:
15041 : : case BIT_XOR_EXPR:
15042 : : case BIT_AND_EXPR:
15043 : :
15044 : : case LSHIFT_EXPR:
15045 : : case RSHIFT_EXPR:
15046 : : case LROTATE_EXPR:
15047 : : case RROTATE_EXPR:
15048 : : return true;
15049 : :
15050 : 0 : default:
15051 : 0 : return false;
15052 : : }
15053 : : }
15054 : :
15055 : : /* Return a typenode for the "standard" C type with a given name. */
15056 : : tree
15057 : 888945 : get_typenode_from_name (const char *name)
15058 : : {
15059 : 888945 : if (name == NULL || *name == '\0')
15060 : : return NULL_TREE;
15061 : :
15062 : 888945 : if (strcmp (name, "char") == 0)
15063 : 0 : return char_type_node;
15064 : 888945 : if (strcmp (name, "unsigned char") == 0)
15065 : 91773 : return unsigned_char_type_node;
15066 : 797172 : if (strcmp (name, "signed char") == 0)
15067 : 91773 : return signed_char_type_node;
15068 : :
15069 : 705399 : if (strcmp (name, "short int") == 0)
15070 : 62688 : return short_integer_type_node;
15071 : 642711 : if (strcmp (name, "short unsigned int") == 0)
15072 : 61182 : return short_unsigned_type_node;
15073 : :
15074 : 581529 : if (strcmp (name, "int") == 0)
15075 : 63517 : return integer_type_node;
15076 : 518012 : if (strcmp (name, "unsigned int") == 0)
15077 : 61996 : return unsigned_type_node;
15078 : :
15079 : 456016 : if (strcmp (name, "long int") == 0)
15080 : 271656 : return long_integer_type_node;
15081 : 184360 : if (strcmp (name, "long unsigned int") == 0)
15082 : 181104 : return long_unsigned_type_node;
15083 : :
15084 : 3256 : if (strcmp (name, "long long int") == 0)
15085 : 1628 : return long_long_integer_type_node;
15086 : 1628 : if (strcmp (name, "long long unsigned int") == 0)
15087 : 1628 : return long_long_unsigned_type_node;
15088 : :
15089 : 0 : gcc_unreachable ();
15090 : : }
15091 : :
15092 : : /* List of pointer types used to declare builtins before we have seen their
15093 : : real declaration.
15094 : :
15095 : : Keep the size up to date in tree.h ! */
15096 : : const builtin_structptr_type builtin_structptr_types[6] =
15097 : : {
15098 : : { fileptr_type_node, ptr_type_node, "FILE" },
15099 : : { const_tm_ptr_type_node, const_ptr_type_node, "tm" },
15100 : : { fenv_t_ptr_type_node, ptr_type_node, "fenv_t" },
15101 : : { const_fenv_t_ptr_type_node, const_ptr_type_node, "fenv_t" },
15102 : : { fexcept_t_ptr_type_node, ptr_type_node, "fexcept_t" },
15103 : : { const_fexcept_t_ptr_type_node, const_ptr_type_node, "fexcept_t" }
15104 : : };
15105 : :
15106 : : /* Return the maximum object size. */
15107 : :
15108 : : tree
15109 : 7119662 : max_object_size (void)
15110 : : {
15111 : : /* To do: Make this a configurable parameter. */
15112 : 7119662 : return TYPE_MAX_VALUE (ptrdiff_type_node);
15113 : : }
15114 : :
15115 : : /* A wrapper around TARGET_VERIFY_TYPE_CONTEXT that makes the silent_p
15116 : : parameter default to false and that weeds out error_mark_node. */
15117 : :
15118 : : bool
15119 : 110025763 : verify_type_context (location_t loc, type_context_kind context,
15120 : : const_tree type, bool silent_p)
15121 : : {
15122 : 110025763 : if (type == error_mark_node)
15123 : : return true;
15124 : :
15125 : 110025671 : gcc_assert (TYPE_P (type));
15126 : 110025671 : return (!targetm.verify_type_context
15127 : 110025671 : || targetm.verify_type_context (loc, context, type, silent_p));
15128 : : }
15129 : :
15130 : : /* Return true if NEW_ASM and DELETE_ASM name a valid pair of new and
15131 : : delete operators. Return false if they may or may not name such
15132 : : a pair and, when nonnull, set *PCERTAIN to true if they certainly
15133 : : do not. */
15134 : :
15135 : : bool
15136 : 60787 : valid_new_delete_pair_p (tree new_asm, tree delete_asm,
15137 : : bool *pcertain /* = NULL */)
15138 : : {
15139 : 60787 : bool certain;
15140 : 60787 : if (!pcertain)
15141 : 49190 : pcertain = &certain;
15142 : :
15143 : 60787 : const char *new_name = IDENTIFIER_POINTER (new_asm);
15144 : 60787 : const char *delete_name = IDENTIFIER_POINTER (delete_asm);
15145 : 60787 : unsigned int new_len = IDENTIFIER_LENGTH (new_asm);
15146 : 60787 : unsigned int delete_len = IDENTIFIER_LENGTH (delete_asm);
15147 : :
15148 : : /* The following failures are due to invalid names so they're not
15149 : : considered certain mismatches. */
15150 : 60787 : *pcertain = false;
15151 : :
15152 : 60787 : if (new_len < 5 || delete_len < 6)
15153 : : return false;
15154 : 60787 : if (new_name[0] == '_')
15155 : 60721 : ++new_name, --new_len;
15156 : 60787 : if (new_name[0] == '_')
15157 : 0 : ++new_name, --new_len;
15158 : 60787 : if (delete_name[0] == '_')
15159 : 60787 : ++delete_name, --delete_len;
15160 : 60787 : if (delete_name[0] == '_')
15161 : 0 : ++delete_name, --delete_len;
15162 : 60787 : if (new_len < 4 || delete_len < 5)
15163 : : return false;
15164 : :
15165 : : /* The following failures are due to names of user-defined operators
15166 : : so they're also not considered certain mismatches. */
15167 : :
15168 : : /* *_len is now just the length after initial underscores. */
15169 : 60787 : if (new_name[0] != 'Z' || new_name[1] != 'n')
15170 : : return false;
15171 : 60143 : if (delete_name[0] != 'Z' || delete_name[1] != 'd')
15172 : : return false;
15173 : :
15174 : : /* The following failures are certain mismatches. */
15175 : 60075 : *pcertain = true;
15176 : :
15177 : : /* _Znw must match _Zdl, _Zna must match _Zda. */
15178 : 60075 : if ((new_name[2] != 'w' || delete_name[2] != 'l')
15179 : 7319 : && (new_name[2] != 'a' || delete_name[2] != 'a'))
15180 : : return false;
15181 : : /* 'j', 'm' and 'y' correspond to size_t. */
15182 : 59961 : if (new_name[3] != 'j' && new_name[3] != 'm' && new_name[3] != 'y')
15183 : : return false;
15184 : 59961 : if (delete_name[3] != 'P' || delete_name[4] != 'v')
15185 : : return false;
15186 : 59961 : if (new_len == 4
15187 : 411 : || (new_len == 18 && !memcmp (new_name + 4, "RKSt9nothrow_t", 14)))
15188 : : {
15189 : : /* _ZnXY or _ZnXYRKSt9nothrow_t matches
15190 : : _ZdXPv, _ZdXPvY and _ZdXPvRKSt9nothrow_t. */
15191 : 59704 : if (delete_len == 5)
15192 : : return true;
15193 : 50583 : if (delete_len == 6 && delete_name[5] == new_name[3])
15194 : : return true;
15195 : 33 : if (delete_len == 19 && !memcmp (delete_name + 5, "RKSt9nothrow_t", 14))
15196 : : return true;
15197 : : }
15198 : 257 : else if ((new_len == 19 && !memcmp (new_name + 4, "St11align_val_t", 15))
15199 : 42 : || (new_len == 33
15200 : 10 : && !memcmp (new_name + 4, "St11align_val_tRKSt9nothrow_t", 29)))
15201 : : {
15202 : : /* _ZnXYSt11align_val_t or _ZnXYSt11align_val_tRKSt9nothrow_t matches
15203 : : _ZdXPvSt11align_val_t or _ZdXPvYSt11align_val_t or
15204 : : _ZdXPvSt11align_val_tRKSt9nothrow_t. */
15205 : 225 : if (delete_len == 20 && !memcmp (delete_name + 5, "St11align_val_t", 15))
15206 : : return true;
15207 : 46 : if (delete_len == 21
15208 : 31 : && delete_name[5] == new_name[3]
15209 : 31 : && !memcmp (delete_name + 6, "St11align_val_t", 15))
15210 : : return true;
15211 : 15 : if (delete_len == 34
15212 : 9 : && !memcmp (delete_name + 5, "St11align_val_tRKSt9nothrow_t", 29))
15213 : : return true;
15214 : : }
15215 : :
15216 : : /* The negative result is conservative. */
15217 : 38 : *pcertain = false;
15218 : 38 : return false;
15219 : : }
15220 : :
15221 : : /* Return the zero-based number corresponding to the argument being
15222 : : deallocated if FNDECL is a deallocation function or an out-of-bounds
15223 : : value if it isn't. */
15224 : :
15225 : : unsigned
15226 : 28187384 : fndecl_dealloc_argno (tree fndecl)
15227 : : {
15228 : : /* A call to operator delete isn't recognized as one to a built-in. */
15229 : 28187384 : if (DECL_IS_OPERATOR_DELETE_P (fndecl))
15230 : : {
15231 : 441471 : if (DECL_IS_REPLACEABLE_OPERATOR (fndecl))
15232 : : return 0;
15233 : :
15234 : : /* Avoid placement delete that's not been inlined. */
15235 : 24623 : tree fname = DECL_ASSEMBLER_NAME (fndecl);
15236 : 24623 : if (id_equal (fname, "_ZdlPvS_") // ordinary form
15237 : 24623 : || id_equal (fname, "_ZdaPvS_")) // array form
15238 : : return UINT_MAX;
15239 : : return 0;
15240 : : }
15241 : :
15242 : : /* TODO: Handle user-defined functions with attribute malloc? Handle
15243 : : known non-built-ins like fopen? */
15244 : 27745913 : if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
15245 : : {
15246 : 7151142 : switch (DECL_FUNCTION_CODE (fndecl))
15247 : : {
15248 : : case BUILT_IN_FREE:
15249 : : case BUILT_IN_REALLOC:
15250 : : case BUILT_IN_GOMP_FREE:
15251 : : case BUILT_IN_GOMP_REALLOC:
15252 : : return 0;
15253 : : default:
15254 : : break;
15255 : : }
15256 : : return UINT_MAX;
15257 : : }
15258 : :
15259 : 20594771 : tree attrs = DECL_ATTRIBUTES (fndecl);
15260 : 20594771 : if (!attrs)
15261 : : return UINT_MAX;
15262 : :
15263 : 0 : for (tree atfree = attrs;
15264 : 4655299 : (atfree = lookup_attribute ("*dealloc", atfree));
15265 : 0 : atfree = TREE_CHAIN (atfree))
15266 : : {
15267 : 6039 : tree alloc = TREE_VALUE (atfree);
15268 : 6039 : if (!alloc)
15269 : 0 : continue;
15270 : :
15271 : 6039 : tree pos = TREE_CHAIN (alloc);
15272 : 6039 : if (!pos)
15273 : : return 0;
15274 : :
15275 : 3519 : pos = TREE_VALUE (pos);
15276 : 3519 : return TREE_INT_CST_LOW (pos) - 1;
15277 : : }
15278 : :
15279 : : return UINT_MAX;
15280 : : }
15281 : :
15282 : : /* If EXPR refers to a character array or pointer declared attribute
15283 : : nonstring, return a decl for that array or pointer and set *REF
15284 : : to the referenced enclosing object or pointer. Otherwise return
15285 : : null. */
15286 : :
15287 : : tree
15288 : 1395641 : get_attr_nonstring_decl (tree expr, tree *ref)
15289 : : {
15290 : 1401370 : tree decl = expr;
15291 : 1401370 : tree var = NULL_TREE;
15292 : 1401370 : if (TREE_CODE (decl) == SSA_NAME)
15293 : : {
15294 : 836563 : gimple *def = SSA_NAME_DEF_STMT (decl);
15295 : :
15296 : 836563 : if (is_gimple_assign (def))
15297 : : {
15298 : 46076 : tree_code code = gimple_assign_rhs_code (def);
15299 : 46076 : if (code == ADDR_EXPR
15300 : 46076 : || code == COMPONENT_REF
15301 : 31738 : || code == VAR_DECL)
15302 : 19164 : decl = gimple_assign_rhs1 (def);
15303 : : }
15304 : : else
15305 : 790487 : var = SSA_NAME_VAR (decl);
15306 : : }
15307 : :
15308 : 1401370 : if (TREE_CODE (decl) == ADDR_EXPR)
15309 : 26986 : decl = TREE_OPERAND (decl, 0);
15310 : :
15311 : : /* To simplify calling code, store the referenced DECL regardless of
15312 : : the attribute determined below, but avoid storing the SSA_NAME_VAR
15313 : : obtained above (it's not useful for dataflow purposes). */
15314 : 1401370 : if (ref)
15315 : 5444 : *ref = decl;
15316 : :
15317 : : /* Use the SSA_NAME_VAR that was determined above to see if it's
15318 : : declared nonstring. Otherwise drill down into the referenced
15319 : : DECL. */
15320 : 1401370 : if (var)
15321 : : decl = var;
15322 : : else
15323 : : {
15324 : 636515 : while (TREE_CODE (decl) == ARRAY_REF)
15325 : 18738 : decl = TREE_OPERAND (decl, 0);
15326 : 617777 : if (TREE_CODE (decl) == COMPONENT_REF)
15327 : 16238 : decl = TREE_OPERAND (decl, 1);
15328 : 601539 : else if (TREE_CODE (decl) == MEM_REF)
15329 : 5729 : return get_attr_nonstring_decl (TREE_OPERAND (decl, 0), ref);
15330 : : }
15331 : :
15332 : 1395641 : if (DECL_P (decl) && lookup_attribute ("nonstring", DECL_ATTRIBUTES (decl)))
15333 : : return decl;
15334 : :
15335 : : return NULL_TREE;
15336 : : }
15337 : :
15338 : : /* Return length of attribute names string,
15339 : : if arglist chain > 1, -1 otherwise. */
15340 : :
15341 : : int
15342 : 202 : get_target_clone_attr_len (tree arglist)
15343 : : {
15344 : 202 : tree arg;
15345 : 202 : int str_len_sum = 0;
15346 : 202 : int argnum = 0;
15347 : :
15348 : 740 : for (arg = arglist; arg; arg = TREE_CHAIN (arg))
15349 : : {
15350 : 538 : const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
15351 : 538 : size_t len = strlen (str);
15352 : 538 : str_len_sum += len + 1;
15353 : 538 : for (const char *p = strchr (str, TARGET_CLONES_ATTR_SEPARATOR);
15354 : 566 : p;
15355 : 28 : p = strchr (p + 1, TARGET_CLONES_ATTR_SEPARATOR))
15356 : 28 : argnum++;
15357 : 538 : argnum++;
15358 : : }
15359 : 202 : if (argnum <= 1)
15360 : 1 : return -1;
15361 : : return str_len_sum;
15362 : : }
15363 : :
15364 : : void
15365 : 256374 : tree_cc_finalize (void)
15366 : : {
15367 : 256374 : clear_nonstandard_integer_type_cache ();
15368 : 256374 : vec_free (bitint_type_cache);
15369 : 256374 : }
15370 : :
15371 : : void
15372 : 144 : gt_ggc_mx (tree_raw_data *x)
15373 : : {
15374 : 144 : gt_ggc_m_9tree_node (x->typed.type);
15375 : 144 : gt_ggc_m_9tree_node (x->owner);
15376 : 144 : }
15377 : :
15378 : : void
15379 : 12 : gt_pch_nx (tree_raw_data *x)
15380 : : {
15381 : 12 : gt_pch_n_9tree_node (x->typed.type);
15382 : 12 : gt_pch_n_9tree_node (x->owner);
15383 : 12 : }
15384 : :
15385 : : /* For PCH we guarantee that RAW_DATA_CST's RAW_DATA_OWNER is a STRING_CST and
15386 : : RAW_DATA_POINTER points into it. We don't want to save/restore
15387 : : RAW_DATA_POINTER on its own but want to restore it pointing at the same
15388 : : offset of the STRING_CST as before. */
15389 : :
15390 : : void
15391 : 12 : gt_pch_nx (tree_raw_data *x, gt_pointer_operator op, void *cookie)
15392 : : {
15393 : 12 : op (&x->typed.type, NULL, cookie);
15394 : 12 : gcc_checking_assert (x->owner
15395 : : && TREE_CODE (x->owner) == STRING_CST
15396 : : && x->str >= TREE_STRING_POINTER (x->owner)
15397 : : && (x->str + x->length
15398 : : <= (TREE_STRING_POINTER (x->owner)
15399 : : + TREE_STRING_LENGTH (x->owner))));
15400 : 12 : ptrdiff_t off = x->str - (const char *) (x->owner);
15401 : 12 : tree owner = x->owner;
15402 : 12 : op (&x->owner, NULL, cookie);
15403 : 12 : x->owner = owner;
15404 : : /* The above op call relocates x->owner and remembers the address
15405 : : for relocation e.g. if the compiler is position independent.
15406 : : We then restore x->owner back to its previous value and call
15407 : : op again, for x->owner itself this just repeats (uselessly) what
15408 : : the first call did, but as the second argument is now non-NULL
15409 : : and different, it also arranges for &x->str to be noted for the
15410 : : PIE relocation. */
15411 : 12 : op (&x->owner, &x->str, cookie);
15412 : 12 : x->str = (const char *) (x->owner) + off;
15413 : 12 : }
15414 : :
15415 : : #if CHECKING_P
15416 : :
15417 : : namespace selftest {
15418 : :
15419 : : /* Selftests for tree. */
15420 : :
15421 : : /* Verify that integer constants are sane. */
15422 : :
15423 : : static void
15424 : 4 : test_integer_constants ()
15425 : : {
15426 : 4 : ASSERT_TRUE (integer_type_node != NULL);
15427 : 4 : ASSERT_TRUE (build_int_cst (integer_type_node, 0) != NULL);
15428 : :
15429 : 4 : tree type = integer_type_node;
15430 : :
15431 : 4 : tree zero = build_zero_cst (type);
15432 : 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (zero));
15433 : 4 : ASSERT_EQ (type, TREE_TYPE (zero));
15434 : :
15435 : 4 : tree one = build_int_cst (type, 1);
15436 : 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (one));
15437 : 4 : ASSERT_EQ (type, TREE_TYPE (zero));
15438 : 4 : }
15439 : :
15440 : : /* Verify identifiers. */
15441 : :
15442 : : static void
15443 : 4 : test_identifiers ()
15444 : : {
15445 : 4 : tree identifier = get_identifier ("foo");
15446 : 4 : ASSERT_EQ (3, IDENTIFIER_LENGTH (identifier));
15447 : 4 : ASSERT_STREQ ("foo", IDENTIFIER_POINTER (identifier));
15448 : 4 : }
15449 : :
15450 : : /* Verify LABEL_DECL. */
15451 : :
15452 : : static void
15453 : 4 : test_labels ()
15454 : : {
15455 : 4 : tree identifier = get_identifier ("err");
15456 : 4 : tree label_decl = build_decl (UNKNOWN_LOCATION, LABEL_DECL,
15457 : : identifier, void_type_node);
15458 : 4 : ASSERT_EQ (-1, LABEL_DECL_UID (label_decl));
15459 : 4 : ASSERT_FALSE (FORCED_LABEL (label_decl));
15460 : 4 : }
15461 : :
15462 : : /* Return a new VECTOR_CST node whose type is TYPE and whose values
15463 : : are given by VALS. */
15464 : :
15465 : : static tree
15466 : 40 : build_vector (tree type, const vec<tree> &vals MEM_STAT_DECL)
15467 : : {
15468 : 80 : gcc_assert (known_eq (vals.length (), TYPE_VECTOR_SUBPARTS (type)));
15469 : 40 : tree_vector_builder builder (type, vals.length (), 1);
15470 : 40 : builder.splice (vals);
15471 : 40 : return builder.build ();
15472 : 40 : }
15473 : :
15474 : : /* Check that VECTOR_CST ACTUAL contains the elements in EXPECTED. */
15475 : :
15476 : : static void
15477 : 40 : check_vector_cst (const vec<tree> &expected, tree actual)
15478 : : {
15479 : 80 : ASSERT_KNOWN_EQ (expected.length (),
15480 : : TYPE_VECTOR_SUBPARTS (TREE_TYPE (actual)));
15481 : 360 : for (unsigned int i = 0; i < expected.length (); ++i)
15482 : 320 : ASSERT_EQ (wi::to_wide (expected[i]),
15483 : : wi::to_wide (vector_cst_elt (actual, i)));
15484 : 40 : }
15485 : :
15486 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS duplicated elements,
15487 : : and that its elements match EXPECTED. */
15488 : :
15489 : : static void
15490 : 8 : check_vector_cst_duplicate (const vec<tree> &expected, tree actual,
15491 : : unsigned int npatterns)
15492 : : {
15493 : 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15494 : 8 : ASSERT_EQ (1, VECTOR_CST_NELTS_PER_PATTERN (actual));
15495 : 8 : ASSERT_EQ (npatterns, vector_cst_encoded_nelts (actual));
15496 : 8 : ASSERT_TRUE (VECTOR_CST_DUPLICATE_P (actual));
15497 : 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
15498 : 8 : check_vector_cst (expected, actual);
15499 : 8 : }
15500 : :
15501 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS foreground elements
15502 : : and NPATTERNS background elements, and that its elements match
15503 : : EXPECTED. */
15504 : :
15505 : : static void
15506 : 8 : check_vector_cst_fill (const vec<tree> &expected, tree actual,
15507 : : unsigned int npatterns)
15508 : : {
15509 : 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15510 : 8 : ASSERT_EQ (2, VECTOR_CST_NELTS_PER_PATTERN (actual));
15511 : 8 : ASSERT_EQ (2 * npatterns, vector_cst_encoded_nelts (actual));
15512 : 8 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
15513 : 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
15514 : 8 : check_vector_cst (expected, actual);
15515 : 8 : }
15516 : :
15517 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS stepped patterns,
15518 : : and that its elements match EXPECTED. */
15519 : :
15520 : : static void
15521 : 24 : check_vector_cst_stepped (const vec<tree> &expected, tree actual,
15522 : : unsigned int npatterns)
15523 : : {
15524 : 24 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15525 : 24 : ASSERT_EQ (3, VECTOR_CST_NELTS_PER_PATTERN (actual));
15526 : 24 : ASSERT_EQ (3 * npatterns, vector_cst_encoded_nelts (actual));
15527 : 24 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
15528 : 24 : ASSERT_TRUE (VECTOR_CST_STEPPED_P (actual));
15529 : 24 : check_vector_cst (expected, actual);
15530 : 24 : }
15531 : :
15532 : : /* Test the creation of VECTOR_CSTs. */
15533 : :
15534 : : static void
15535 : 4 : test_vector_cst_patterns (ALONE_CXX_MEM_STAT_INFO)
15536 : : {
15537 : 4 : auto_vec<tree, 8> elements (8);
15538 : 4 : elements.quick_grow (8);
15539 : 4 : tree element_type = build_nonstandard_integer_type (16, true);
15540 : 4 : tree vector_type = build_vector_type (element_type, 8);
15541 : :
15542 : : /* Test a simple linear series with a base of 0 and a step of 1:
15543 : : { 0, 1, 2, 3, 4, 5, 6, 7 }. */
15544 : 36 : for (unsigned int i = 0; i < 8; ++i)
15545 : 32 : elements[i] = build_int_cst (element_type, i);
15546 : 4 : tree vector = build_vector (vector_type, elements PASS_MEM_STAT);
15547 : 4 : check_vector_cst_stepped (elements, vector, 1);
15548 : :
15549 : : /* Try the same with the first element replaced by 100:
15550 : : { 100, 1, 2, 3, 4, 5, 6, 7 }. */
15551 : 4 : elements[0] = build_int_cst (element_type, 100);
15552 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15553 : 4 : check_vector_cst_stepped (elements, vector, 1);
15554 : :
15555 : : /* Try a series that wraps around.
15556 : : { 100, 65531, 65532, 65533, 65534, 65535, 0, 1 }. */
15557 : 32 : for (unsigned int i = 1; i < 8; ++i)
15558 : 28 : elements[i] = build_int_cst (element_type, (65530 + i) & 0xffff);
15559 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15560 : 4 : check_vector_cst_stepped (elements, vector, 1);
15561 : :
15562 : : /* Try a downward series:
15563 : : { 100, 79, 78, 77, 76, 75, 75, 73 }. */
15564 : 32 : for (unsigned int i = 1; i < 8; ++i)
15565 : 28 : elements[i] = build_int_cst (element_type, 80 - i);
15566 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15567 : 4 : check_vector_cst_stepped (elements, vector, 1);
15568 : :
15569 : : /* Try two interleaved series with different bases and steps:
15570 : : { 100, 53, 66, 206, 62, 212, 58, 218 }. */
15571 : 4 : elements[1] = build_int_cst (element_type, 53);
15572 : 16 : for (unsigned int i = 2; i < 8; i += 2)
15573 : : {
15574 : 12 : elements[i] = build_int_cst (element_type, 70 - i * 2);
15575 : 12 : elements[i + 1] = build_int_cst (element_type, 200 + i * 3);
15576 : : }
15577 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15578 : 4 : check_vector_cst_stepped (elements, vector, 2);
15579 : :
15580 : : /* Try a duplicated value:
15581 : : { 100, 100, 100, 100, 100, 100, 100, 100 }. */
15582 : 32 : for (unsigned int i = 1; i < 8; ++i)
15583 : 28 : elements[i] = elements[0];
15584 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15585 : 4 : check_vector_cst_duplicate (elements, vector, 1);
15586 : :
15587 : : /* Try an interleaved duplicated value:
15588 : : { 100, 55, 100, 55, 100, 55, 100, 55 }. */
15589 : 4 : elements[1] = build_int_cst (element_type, 55);
15590 : 28 : for (unsigned int i = 2; i < 8; ++i)
15591 : 24 : elements[i] = elements[i - 2];
15592 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15593 : 4 : check_vector_cst_duplicate (elements, vector, 2);
15594 : :
15595 : : /* Try a duplicated value with 2 exceptions
15596 : : { 41, 97, 100, 55, 100, 55, 100, 55 }. */
15597 : 4 : elements[0] = build_int_cst (element_type, 41);
15598 : 4 : elements[1] = build_int_cst (element_type, 97);
15599 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15600 : 4 : check_vector_cst_fill (elements, vector, 2);
15601 : :
15602 : : /* Try with and without a step
15603 : : { 41, 97, 100, 21, 100, 35, 100, 49 }. */
15604 : 16 : for (unsigned int i = 3; i < 8; i += 2)
15605 : 12 : elements[i] = build_int_cst (element_type, i * 7);
15606 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15607 : 4 : check_vector_cst_stepped (elements, vector, 2);
15608 : :
15609 : : /* Try a fully-general constant:
15610 : : { 41, 97, 100, 21, 100, 9990, 100, 49 }. */
15611 : 4 : elements[5] = build_int_cst (element_type, 9990);
15612 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15613 : 4 : check_vector_cst_fill (elements, vector, 4);
15614 : 4 : }
15615 : :
15616 : : /* Verify that STRIP_NOPS (NODE) is EXPECTED.
15617 : : Helper function for test_location_wrappers, to deal with STRIP_NOPS
15618 : : modifying its argument in-place. */
15619 : :
15620 : : static void
15621 : 12 : check_strip_nops (tree node, tree expected)
15622 : : {
15623 : 12 : STRIP_NOPS (node);
15624 : 12 : ASSERT_EQ (expected, node);
15625 : 12 : }
15626 : :
15627 : : /* Verify location wrappers. */
15628 : :
15629 : : static void
15630 : 4 : test_location_wrappers ()
15631 : : {
15632 : 4 : location_t loc = BUILTINS_LOCATION;
15633 : :
15634 : 4 : ASSERT_EQ (NULL_TREE, maybe_wrap_with_location (NULL_TREE, loc));
15635 : :
15636 : : /* Wrapping a constant. */
15637 : 4 : tree int_cst = build_int_cst (integer_type_node, 42);
15638 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_cst));
15639 : 4 : ASSERT_FALSE (location_wrapper_p (int_cst));
15640 : :
15641 : 4 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
15642 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
15643 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_cst));
15644 : 4 : ASSERT_EQ (int_cst, tree_strip_any_location_wrapper (wrapped_int_cst));
15645 : :
15646 : : /* We shouldn't add wrapper nodes for UNKNOWN_LOCATION. */
15647 : 4 : ASSERT_EQ (int_cst, maybe_wrap_with_location (int_cst, UNKNOWN_LOCATION));
15648 : :
15649 : : /* We shouldn't add wrapper nodes for nodes that CAN_HAVE_LOCATION_P. */
15650 : 4 : tree cast = build1 (NOP_EXPR, char_type_node, int_cst);
15651 : 4 : ASSERT_TRUE (CAN_HAVE_LOCATION_P (cast));
15652 : 4 : ASSERT_EQ (cast, maybe_wrap_with_location (cast, loc));
15653 : :
15654 : : /* Wrapping a STRING_CST. */
15655 : 4 : tree string_cst = build_string (4, "foo");
15656 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (string_cst));
15657 : 4 : ASSERT_FALSE (location_wrapper_p (string_cst));
15658 : :
15659 : 4 : tree wrapped_string_cst = maybe_wrap_with_location (string_cst, loc);
15660 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_string_cst));
15661 : 4 : ASSERT_EQ (VIEW_CONVERT_EXPR, TREE_CODE (wrapped_string_cst));
15662 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_string_cst));
15663 : 4 : ASSERT_EQ (string_cst, tree_strip_any_location_wrapper (wrapped_string_cst));
15664 : :
15665 : :
15666 : : /* Wrapping a variable. */
15667 : 4 : tree int_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
15668 : : get_identifier ("some_int_var"),
15669 : : integer_type_node);
15670 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_var));
15671 : 4 : ASSERT_FALSE (location_wrapper_p (int_var));
15672 : :
15673 : 4 : tree wrapped_int_var = maybe_wrap_with_location (int_var, loc);
15674 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_var));
15675 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_var));
15676 : 4 : ASSERT_EQ (int_var, tree_strip_any_location_wrapper (wrapped_int_var));
15677 : :
15678 : : /* Verify that "reinterpret_cast<int>(some_int_var)" is not a location
15679 : : wrapper. */
15680 : 4 : tree r_cast = build1 (NON_LVALUE_EXPR, integer_type_node, int_var);
15681 : 4 : ASSERT_FALSE (location_wrapper_p (r_cast));
15682 : 4 : ASSERT_EQ (r_cast, tree_strip_any_location_wrapper (r_cast));
15683 : :
15684 : : /* Verify that STRIP_NOPS removes wrappers. */
15685 : 4 : check_strip_nops (wrapped_int_cst, int_cst);
15686 : 4 : check_strip_nops (wrapped_string_cst, string_cst);
15687 : 4 : check_strip_nops (wrapped_int_var, int_var);
15688 : 4 : }
15689 : :
15690 : : /* Test various tree predicates. Verify that location wrappers don't
15691 : : affect the results. */
15692 : :
15693 : : static void
15694 : 4 : test_predicates ()
15695 : : {
15696 : : /* Build various constants and wrappers around them. */
15697 : :
15698 : 4 : location_t loc = BUILTINS_LOCATION;
15699 : :
15700 : 4 : tree i_0 = build_int_cst (integer_type_node, 0);
15701 : 4 : tree wr_i_0 = maybe_wrap_with_location (i_0, loc);
15702 : :
15703 : 4 : tree i_1 = build_int_cst (integer_type_node, 1);
15704 : 4 : tree wr_i_1 = maybe_wrap_with_location (i_1, loc);
15705 : :
15706 : 4 : tree i_m1 = build_int_cst (integer_type_node, -1);
15707 : 4 : tree wr_i_m1 = maybe_wrap_with_location (i_m1, loc);
15708 : :
15709 : 4 : tree f_0 = build_real_from_int_cst (float_type_node, i_0);
15710 : 4 : tree wr_f_0 = maybe_wrap_with_location (f_0, loc);
15711 : 4 : tree f_1 = build_real_from_int_cst (float_type_node, i_1);
15712 : 4 : tree wr_f_1 = maybe_wrap_with_location (f_1, loc);
15713 : 4 : tree f_m1 = build_real_from_int_cst (float_type_node, i_m1);
15714 : 4 : tree wr_f_m1 = maybe_wrap_with_location (f_m1, loc);
15715 : :
15716 : 4 : tree c_i_0 = build_complex (NULL_TREE, i_0, i_0);
15717 : 4 : tree c_i_1 = build_complex (NULL_TREE, i_1, i_0);
15718 : 4 : tree c_i_m1 = build_complex (NULL_TREE, i_m1, i_0);
15719 : :
15720 : 4 : tree c_f_0 = build_complex (NULL_TREE, f_0, f_0);
15721 : 4 : tree c_f_1 = build_complex (NULL_TREE, f_1, f_0);
15722 : 4 : tree c_f_m1 = build_complex (NULL_TREE, f_m1, f_0);
15723 : :
15724 : : /* TODO: vector constants. */
15725 : :
15726 : : /* Test integer_onep. */
15727 : 4 : ASSERT_FALSE (integer_onep (i_0));
15728 : 4 : ASSERT_FALSE (integer_onep (wr_i_0));
15729 : 4 : ASSERT_TRUE (integer_onep (i_1));
15730 : 4 : ASSERT_TRUE (integer_onep (wr_i_1));
15731 : 4 : ASSERT_FALSE (integer_onep (i_m1));
15732 : 4 : ASSERT_FALSE (integer_onep (wr_i_m1));
15733 : 4 : ASSERT_FALSE (integer_onep (f_0));
15734 : 4 : ASSERT_FALSE (integer_onep (wr_f_0));
15735 : 4 : ASSERT_FALSE (integer_onep (f_1));
15736 : 4 : ASSERT_FALSE (integer_onep (wr_f_1));
15737 : 4 : ASSERT_FALSE (integer_onep (f_m1));
15738 : 4 : ASSERT_FALSE (integer_onep (wr_f_m1));
15739 : 4 : ASSERT_FALSE (integer_onep (c_i_0));
15740 : 4 : ASSERT_TRUE (integer_onep (c_i_1));
15741 : 4 : ASSERT_FALSE (integer_onep (c_i_m1));
15742 : 4 : ASSERT_FALSE (integer_onep (c_f_0));
15743 : 4 : ASSERT_FALSE (integer_onep (c_f_1));
15744 : 4 : ASSERT_FALSE (integer_onep (c_f_m1));
15745 : :
15746 : : /* Test integer_zerop. */
15747 : 4 : ASSERT_TRUE (integer_zerop (i_0));
15748 : 4 : ASSERT_TRUE (integer_zerop (wr_i_0));
15749 : 4 : ASSERT_FALSE (integer_zerop (i_1));
15750 : 4 : ASSERT_FALSE (integer_zerop (wr_i_1));
15751 : 4 : ASSERT_FALSE (integer_zerop (i_m1));
15752 : 4 : ASSERT_FALSE (integer_zerop (wr_i_m1));
15753 : 4 : ASSERT_FALSE (integer_zerop (f_0));
15754 : 4 : ASSERT_FALSE (integer_zerop (wr_f_0));
15755 : 4 : ASSERT_FALSE (integer_zerop (f_1));
15756 : 4 : ASSERT_FALSE (integer_zerop (wr_f_1));
15757 : 4 : ASSERT_FALSE (integer_zerop (f_m1));
15758 : 4 : ASSERT_FALSE (integer_zerop (wr_f_m1));
15759 : 4 : ASSERT_TRUE (integer_zerop (c_i_0));
15760 : 4 : ASSERT_FALSE (integer_zerop (c_i_1));
15761 : 4 : ASSERT_FALSE (integer_zerop (c_i_m1));
15762 : 4 : ASSERT_FALSE (integer_zerop (c_f_0));
15763 : 4 : ASSERT_FALSE (integer_zerop (c_f_1));
15764 : 4 : ASSERT_FALSE (integer_zerop (c_f_m1));
15765 : :
15766 : : /* Test integer_all_onesp. */
15767 : 4 : ASSERT_FALSE (integer_all_onesp (i_0));
15768 : 4 : ASSERT_FALSE (integer_all_onesp (wr_i_0));
15769 : 4 : ASSERT_FALSE (integer_all_onesp (i_1));
15770 : 4 : ASSERT_FALSE (integer_all_onesp (wr_i_1));
15771 : 4 : ASSERT_TRUE (integer_all_onesp (i_m1));
15772 : 4 : ASSERT_TRUE (integer_all_onesp (wr_i_m1));
15773 : 4 : ASSERT_FALSE (integer_all_onesp (f_0));
15774 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_0));
15775 : 4 : ASSERT_FALSE (integer_all_onesp (f_1));
15776 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_1));
15777 : 4 : ASSERT_FALSE (integer_all_onesp (f_m1));
15778 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_m1));
15779 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_0));
15780 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_1));
15781 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_m1));
15782 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_0));
15783 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_1));
15784 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_m1));
15785 : :
15786 : : /* Test integer_minus_onep. */
15787 : 4 : ASSERT_FALSE (integer_minus_onep (i_0));
15788 : 4 : ASSERT_FALSE (integer_minus_onep (wr_i_0));
15789 : 4 : ASSERT_FALSE (integer_minus_onep (i_1));
15790 : 4 : ASSERT_FALSE (integer_minus_onep (wr_i_1));
15791 : 4 : ASSERT_TRUE (integer_minus_onep (i_m1));
15792 : 4 : ASSERT_TRUE (integer_minus_onep (wr_i_m1));
15793 : 4 : ASSERT_FALSE (integer_minus_onep (f_0));
15794 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_0));
15795 : 4 : ASSERT_FALSE (integer_minus_onep (f_1));
15796 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_1));
15797 : 4 : ASSERT_FALSE (integer_minus_onep (f_m1));
15798 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_m1));
15799 : 4 : ASSERT_FALSE (integer_minus_onep (c_i_0));
15800 : 4 : ASSERT_FALSE (integer_minus_onep (c_i_1));
15801 : 4 : ASSERT_TRUE (integer_minus_onep (c_i_m1));
15802 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_0));
15803 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_1));
15804 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_m1));
15805 : :
15806 : : /* Test integer_each_onep. */
15807 : 4 : ASSERT_FALSE (integer_each_onep (i_0));
15808 : 4 : ASSERT_FALSE (integer_each_onep (wr_i_0));
15809 : 4 : ASSERT_TRUE (integer_each_onep (i_1));
15810 : 4 : ASSERT_TRUE (integer_each_onep (wr_i_1));
15811 : 4 : ASSERT_FALSE (integer_each_onep (i_m1));
15812 : 4 : ASSERT_FALSE (integer_each_onep (wr_i_m1));
15813 : 4 : ASSERT_FALSE (integer_each_onep (f_0));
15814 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_0));
15815 : 4 : ASSERT_FALSE (integer_each_onep (f_1));
15816 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_1));
15817 : 4 : ASSERT_FALSE (integer_each_onep (f_m1));
15818 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_m1));
15819 : 4 : ASSERT_FALSE (integer_each_onep (c_i_0));
15820 : 4 : ASSERT_FALSE (integer_each_onep (c_i_1));
15821 : 4 : ASSERT_FALSE (integer_each_onep (c_i_m1));
15822 : 4 : ASSERT_FALSE (integer_each_onep (c_f_0));
15823 : 4 : ASSERT_FALSE (integer_each_onep (c_f_1));
15824 : 4 : ASSERT_FALSE (integer_each_onep (c_f_m1));
15825 : :
15826 : : /* Test integer_truep. */
15827 : 4 : ASSERT_FALSE (integer_truep (i_0));
15828 : 4 : ASSERT_FALSE (integer_truep (wr_i_0));
15829 : 4 : ASSERT_TRUE (integer_truep (i_1));
15830 : 4 : ASSERT_TRUE (integer_truep (wr_i_1));
15831 : 4 : ASSERT_FALSE (integer_truep (i_m1));
15832 : 4 : ASSERT_FALSE (integer_truep (wr_i_m1));
15833 : 4 : ASSERT_FALSE (integer_truep (f_0));
15834 : 4 : ASSERT_FALSE (integer_truep (wr_f_0));
15835 : 4 : ASSERT_FALSE (integer_truep (f_1));
15836 : 4 : ASSERT_FALSE (integer_truep (wr_f_1));
15837 : 4 : ASSERT_FALSE (integer_truep (f_m1));
15838 : 4 : ASSERT_FALSE (integer_truep (wr_f_m1));
15839 : 4 : ASSERT_FALSE (integer_truep (c_i_0));
15840 : 4 : ASSERT_TRUE (integer_truep (c_i_1));
15841 : 4 : ASSERT_FALSE (integer_truep (c_i_m1));
15842 : 4 : ASSERT_FALSE (integer_truep (c_f_0));
15843 : 4 : ASSERT_FALSE (integer_truep (c_f_1));
15844 : 4 : ASSERT_FALSE (integer_truep (c_f_m1));
15845 : :
15846 : : /* Test integer_nonzerop. */
15847 : 4 : ASSERT_FALSE (integer_nonzerop (i_0));
15848 : 4 : ASSERT_FALSE (integer_nonzerop (wr_i_0));
15849 : 4 : ASSERT_TRUE (integer_nonzerop (i_1));
15850 : 4 : ASSERT_TRUE (integer_nonzerop (wr_i_1));
15851 : 4 : ASSERT_TRUE (integer_nonzerop (i_m1));
15852 : 4 : ASSERT_TRUE (integer_nonzerop (wr_i_m1));
15853 : 4 : ASSERT_FALSE (integer_nonzerop (f_0));
15854 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_0));
15855 : 4 : ASSERT_FALSE (integer_nonzerop (f_1));
15856 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_1));
15857 : 4 : ASSERT_FALSE (integer_nonzerop (f_m1));
15858 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_m1));
15859 : 4 : ASSERT_FALSE (integer_nonzerop (c_i_0));
15860 : 4 : ASSERT_TRUE (integer_nonzerop (c_i_1));
15861 : 4 : ASSERT_TRUE (integer_nonzerop (c_i_m1));
15862 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_0));
15863 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_1));
15864 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_m1));
15865 : :
15866 : : /* Test real_zerop. */
15867 : 4 : ASSERT_FALSE (real_zerop (i_0));
15868 : 4 : ASSERT_FALSE (real_zerop (wr_i_0));
15869 : 4 : ASSERT_FALSE (real_zerop (i_1));
15870 : 4 : ASSERT_FALSE (real_zerop (wr_i_1));
15871 : 4 : ASSERT_FALSE (real_zerop (i_m1));
15872 : 4 : ASSERT_FALSE (real_zerop (wr_i_m1));
15873 : 4 : ASSERT_TRUE (real_zerop (f_0));
15874 : 4 : ASSERT_TRUE (real_zerop (wr_f_0));
15875 : 4 : ASSERT_FALSE (real_zerop (f_1));
15876 : 4 : ASSERT_FALSE (real_zerop (wr_f_1));
15877 : 4 : ASSERT_FALSE (real_zerop (f_m1));
15878 : 4 : ASSERT_FALSE (real_zerop (wr_f_m1));
15879 : 4 : ASSERT_FALSE (real_zerop (c_i_0));
15880 : 4 : ASSERT_FALSE (real_zerop (c_i_1));
15881 : 4 : ASSERT_FALSE (real_zerop (c_i_m1));
15882 : 4 : ASSERT_TRUE (real_zerop (c_f_0));
15883 : 4 : ASSERT_FALSE (real_zerop (c_f_1));
15884 : 4 : ASSERT_FALSE (real_zerop (c_f_m1));
15885 : :
15886 : : /* Test real_onep. */
15887 : 4 : ASSERT_FALSE (real_onep (i_0));
15888 : 4 : ASSERT_FALSE (real_onep (wr_i_0));
15889 : 4 : ASSERT_FALSE (real_onep (i_1));
15890 : 4 : ASSERT_FALSE (real_onep (wr_i_1));
15891 : 4 : ASSERT_FALSE (real_onep (i_m1));
15892 : 4 : ASSERT_FALSE (real_onep (wr_i_m1));
15893 : 4 : ASSERT_FALSE (real_onep (f_0));
15894 : 4 : ASSERT_FALSE (real_onep (wr_f_0));
15895 : 4 : ASSERT_TRUE (real_onep (f_1));
15896 : 4 : ASSERT_TRUE (real_onep (wr_f_1));
15897 : 4 : ASSERT_FALSE (real_onep (f_m1));
15898 : 4 : ASSERT_FALSE (real_onep (wr_f_m1));
15899 : 4 : ASSERT_FALSE (real_onep (c_i_0));
15900 : 4 : ASSERT_FALSE (real_onep (c_i_1));
15901 : 4 : ASSERT_FALSE (real_onep (c_i_m1));
15902 : 4 : ASSERT_FALSE (real_onep (c_f_0));
15903 : 4 : ASSERT_TRUE (real_onep (c_f_1));
15904 : 4 : ASSERT_FALSE (real_onep (c_f_m1));
15905 : :
15906 : : /* Test real_minus_onep. */
15907 : 4 : ASSERT_FALSE (real_minus_onep (i_0));
15908 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_0));
15909 : 4 : ASSERT_FALSE (real_minus_onep (i_1));
15910 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_1));
15911 : 4 : ASSERT_FALSE (real_minus_onep (i_m1));
15912 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_m1));
15913 : 4 : ASSERT_FALSE (real_minus_onep (f_0));
15914 : 4 : ASSERT_FALSE (real_minus_onep (wr_f_0));
15915 : 4 : ASSERT_FALSE (real_minus_onep (f_1));
15916 : 4 : ASSERT_FALSE (real_minus_onep (wr_f_1));
15917 : 4 : ASSERT_TRUE (real_minus_onep (f_m1));
15918 : 4 : ASSERT_TRUE (real_minus_onep (wr_f_m1));
15919 : 4 : ASSERT_FALSE (real_minus_onep (c_i_0));
15920 : 4 : ASSERT_FALSE (real_minus_onep (c_i_1));
15921 : 4 : ASSERT_FALSE (real_minus_onep (c_i_m1));
15922 : 4 : ASSERT_FALSE (real_minus_onep (c_f_0));
15923 : 4 : ASSERT_FALSE (real_minus_onep (c_f_1));
15924 : 4 : ASSERT_TRUE (real_minus_onep (c_f_m1));
15925 : :
15926 : : /* Test zerop. */
15927 : 4 : ASSERT_TRUE (zerop (i_0));
15928 : 4 : ASSERT_TRUE (zerop (wr_i_0));
15929 : 4 : ASSERT_FALSE (zerop (i_1));
15930 : 4 : ASSERT_FALSE (zerop (wr_i_1));
15931 : 4 : ASSERT_FALSE (zerop (i_m1));
15932 : 4 : ASSERT_FALSE (zerop (wr_i_m1));
15933 : 4 : ASSERT_TRUE (zerop (f_0));
15934 : 4 : ASSERT_TRUE (zerop (wr_f_0));
15935 : 4 : ASSERT_FALSE (zerop (f_1));
15936 : 4 : ASSERT_FALSE (zerop (wr_f_1));
15937 : 4 : ASSERT_FALSE (zerop (f_m1));
15938 : 4 : ASSERT_FALSE (zerop (wr_f_m1));
15939 : 4 : ASSERT_TRUE (zerop (c_i_0));
15940 : 4 : ASSERT_FALSE (zerop (c_i_1));
15941 : 4 : ASSERT_FALSE (zerop (c_i_m1));
15942 : 4 : ASSERT_TRUE (zerop (c_f_0));
15943 : 4 : ASSERT_FALSE (zerop (c_f_1));
15944 : 4 : ASSERT_FALSE (zerop (c_f_m1));
15945 : :
15946 : : /* Test tree_expr_nonnegative_p. */
15947 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_0));
15948 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_0));
15949 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_1));
15950 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_1));
15951 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (i_m1));
15952 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_i_m1));
15953 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_0));
15954 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_0));
15955 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_1));
15956 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_1));
15957 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (f_m1));
15958 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_f_m1));
15959 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_0));
15960 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_1));
15961 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_m1));
15962 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_0));
15963 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_1));
15964 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_m1));
15965 : :
15966 : : /* Test tree_expr_nonzero_p. */
15967 : 4 : ASSERT_FALSE (tree_expr_nonzero_p (i_0));
15968 : 4 : ASSERT_FALSE (tree_expr_nonzero_p (wr_i_0));
15969 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_1));
15970 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_1));
15971 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_m1));
15972 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_m1));
15973 : :
15974 : : /* Test integer_valued_real_p. */
15975 : 4 : ASSERT_FALSE (integer_valued_real_p (i_0));
15976 : 4 : ASSERT_TRUE (integer_valued_real_p (f_0));
15977 : 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_0));
15978 : 4 : ASSERT_TRUE (integer_valued_real_p (f_1));
15979 : 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_1));
15980 : :
15981 : : /* Test integer_pow2p. */
15982 : 4 : ASSERT_FALSE (integer_pow2p (i_0));
15983 : 4 : ASSERT_TRUE (integer_pow2p (i_1));
15984 : 4 : ASSERT_TRUE (integer_pow2p (wr_i_1));
15985 : :
15986 : : /* Test uniform_integer_cst_p. */
15987 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_0));
15988 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_0));
15989 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_1));
15990 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_1));
15991 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_m1));
15992 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_m1));
15993 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_0));
15994 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_0));
15995 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_1));
15996 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_1));
15997 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_m1));
15998 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_m1));
15999 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_0));
16000 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_1));
16001 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_m1));
16002 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_0));
16003 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_1));
16004 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_m1));
16005 : 4 : }
16006 : :
16007 : : /* Check that string escaping works correctly. */
16008 : :
16009 : : static void
16010 : 4 : test_escaped_strings (void)
16011 : : {
16012 : 4 : int saved_cutoff;
16013 : 4 : escaped_string msg;
16014 : :
16015 : 4 : msg.escape (NULL);
16016 : : /* ASSERT_STREQ does not accept NULL as a valid test
16017 : : result, so we have to use ASSERT_EQ instead. */
16018 : 4 : ASSERT_EQ (NULL, (const char *) msg);
16019 : :
16020 : 4 : msg.escape ("");
16021 : 4 : ASSERT_STREQ ("", (const char *) msg);
16022 : :
16023 : 4 : msg.escape ("foobar");
16024 : 4 : ASSERT_STREQ ("foobar", (const char *) msg);
16025 : :
16026 : : /* Ensure that we have -fmessage-length set to 0. */
16027 : 4 : pretty_printer *pp = global_dc->get_reference_printer ();
16028 : 4 : saved_cutoff = pp_line_cutoff (pp);
16029 : 4 : pp_line_cutoff (pp) = 0;
16030 : :
16031 : 4 : msg.escape ("foo\nbar");
16032 : 4 : ASSERT_STREQ ("foo\\nbar", (const char *) msg);
16033 : :
16034 : 4 : msg.escape ("\a\b\f\n\r\t\v");
16035 : 4 : ASSERT_STREQ ("\\a\\b\\f\\n\\r\\t\\v", (const char *) msg);
16036 : :
16037 : : /* Now repeat the tests with -fmessage-length set to 5. */
16038 : 4 : pp_line_cutoff (pp) = 5;
16039 : :
16040 : : /* Note that the newline is not translated into an escape. */
16041 : 4 : msg.escape ("foo\nbar");
16042 : 4 : ASSERT_STREQ ("foo\nbar", (const char *) msg);
16043 : :
16044 : 4 : msg.escape ("\a\b\f\n\r\t\v");
16045 : 4 : ASSERT_STREQ ("\\a\\b\\f\n\\r\\t\\v", (const char *) msg);
16046 : :
16047 : : /* Restore the original message length setting. */
16048 : 4 : pp_line_cutoff (pp) = saved_cutoff;
16049 : 4 : }
16050 : :
16051 : : /* Run all of the selftests within this file. */
16052 : :
16053 : : void
16054 : 4 : tree_cc_tests ()
16055 : : {
16056 : 4 : test_integer_constants ();
16057 : 4 : test_identifiers ();
16058 : 4 : test_labels ();
16059 : 4 : test_vector_cst_patterns ();
16060 : 4 : test_location_wrappers ();
16061 : 4 : test_predicates ();
16062 : 4 : test_escaped_strings ();
16063 : 4 : }
16064 : :
16065 : : } // namespace selftest
16066 : :
16067 : : #endif /* CHECKING_P */
16068 : :
16069 : : #include "gt-tree.h"
|