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 "memmodel.h"
36 : : #include "tm_p.h"
37 : : #include "tree.h"
38 : : #include "gimple.h"
39 : : #include "tree-pass.h"
40 : : #include "ssa.h"
41 : : #include "cgraph.h"
42 : : #include "diagnostic.h"
43 : : #include "flags.h"
44 : : #include "alias.h"
45 : : #include "fold-const.h"
46 : : #include "stor-layout.h"
47 : : #include "calls.h"
48 : : #include "attribs.h"
49 : : #include "toplev.h" /* get_random_seed */
50 : : #include "output.h"
51 : : #include "common/common-target.h"
52 : : #include "langhooks.h"
53 : : #include "tree-inline.h"
54 : : #include "tree-iterator.h"
55 : : #include "internal-fn.h"
56 : : #include "gimple-iterator.h"
57 : : #include "gimplify.h"
58 : : #include "tree-dfa.h"
59 : : #include "langhooks-def.h"
60 : : #include "tree-diagnostic.h"
61 : : #include "except.h"
62 : : #include "builtins.h"
63 : : #include "print-tree.h"
64 : : #include "ipa-utils.h"
65 : : #include "selftest.h"
66 : : #include "stringpool.h"
67 : : #include "attribs.h"
68 : : #include "rtl.h"
69 : : #include "regs.h"
70 : : #include "tree-vector-builder.h"
71 : : #include "gimple-fold.h"
72 : : #include "escaped_string.h"
73 : : #include "gimple-range.h"
74 : : #include "gomp-constants.h"
75 : : #include "dfp.h"
76 : : #include "asan.h"
77 : : #include "ubsan.h"
78 : : #include "attr-callback.h"
79 : :
80 : : /* Names of tree components.
81 : : Used for printing out the tree and error messages. */
82 : : #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
83 : : #define END_OF_BASE_TREE_CODES "@dummy",
84 : :
85 : : static const char *const tree_code_name[] = {
86 : : #include "all-tree.def"
87 : : };
88 : :
89 : : #undef DEFTREECODE
90 : : #undef END_OF_BASE_TREE_CODES
91 : :
92 : : /* Each tree code class has an associated string representation.
93 : : These must correspond to the tree_code_class entries. */
94 : :
95 : : const char *const tree_code_class_strings[] =
96 : : {
97 : : "exceptional",
98 : : "constant",
99 : : "type",
100 : : "declaration",
101 : : "reference",
102 : : "comparison",
103 : : "unary",
104 : : "binary",
105 : : "statement",
106 : : "vl_exp",
107 : : "expression"
108 : : };
109 : :
110 : : /* obstack.[ch] explicitly declined to prototype this. */
111 : : extern int _obstack_allocated_p (struct obstack *h, void *obj);
112 : :
113 : : /* Statistics-gathering stuff. */
114 : :
115 : : static uint64_t tree_code_counts[MAX_TREE_CODES];
116 : : uint64_t tree_node_counts[(int) all_kinds];
117 : : uint64_t tree_node_sizes[(int) all_kinds];
118 : :
119 : : /* Keep in sync with tree.h:enum tree_node_kind. */
120 : : static const char * const tree_node_kind_names[] = {
121 : : "decls",
122 : : "types",
123 : : "blocks",
124 : : "stmts",
125 : : "refs",
126 : : "exprs",
127 : : "constants",
128 : : "identifiers",
129 : : "vecs",
130 : : "binfos",
131 : : "ssa names",
132 : : "constructors",
133 : : "random kinds",
134 : : "lang_decl kinds",
135 : : "lang_type kinds",
136 : : "omp clauses",
137 : : };
138 : :
139 : : /* Unique id for next decl created. */
140 : : static GTY(()) int next_decl_uid;
141 : : /* Unique id for next type created. */
142 : : static GTY(()) unsigned next_type_uid = 1;
143 : : /* Unique id for next debug decl created. Use negative numbers,
144 : : to catch erroneous uses. */
145 : : static GTY(()) int next_debug_decl_uid;
146 : :
147 : : /* Since we cannot rehash a type after it is in the table, we have to
148 : : keep the hash code. */
149 : :
150 : : struct GTY((for_user)) type_hash {
151 : : unsigned long hash;
152 : : tree type;
153 : : };
154 : :
155 : : /* Initial size of the hash table (rounded to next prime). */
156 : : #define TYPE_HASH_INITIAL_SIZE 1000
157 : :
158 : : struct type_cache_hasher : ggc_cache_ptr_hash<type_hash>
159 : : {
160 : 7016278211 : static hashval_t hash (type_hash *t) { return t->hash; }
161 : : static bool equal (type_hash *a, type_hash *b);
162 : :
163 : : static int
164 : 1699703763 : keep_cache_entry (type_hash *&t)
165 : : {
166 : 1699703763 : return ggc_marked_p (t->type);
167 : : }
168 : : };
169 : :
170 : : /* Now here is the hash table. When recording a type, it is added to
171 : : the slot whose index is the hash code. Note that the hash table is
172 : : used for several kinds of types (function types, array types and
173 : : array index range types, for now). While all these live in the
174 : : same table, they are completely independent, and the hash code is
175 : : computed differently for each of these. */
176 : :
177 : : static GTY ((cache)) hash_table<type_cache_hasher> *type_hash_table;
178 : :
179 : : /* Hash table and temporary node for larger integer const values. */
180 : : static GTY (()) tree int_cst_node;
181 : :
182 : : struct int_cst_hasher : ggc_cache_ptr_hash<tree_node>
183 : : {
184 : : static hashval_t hash (tree t);
185 : : static bool equal (tree x, tree y);
186 : : };
187 : :
188 : : static GTY ((cache)) hash_table<int_cst_hasher> *int_cst_hash_table;
189 : :
190 : : /* Class and variable for making sure that there is a single POLY_INT_CST
191 : : for a given value. */
192 : : struct poly_int_cst_hasher : ggc_cache_ptr_hash<tree_node>
193 : : {
194 : : typedef std::pair<tree, const poly_wide_int *> compare_type;
195 : : static hashval_t hash (tree t);
196 : : static bool equal (tree x, const compare_type &y);
197 : : };
198 : :
199 : : static GTY ((cache)) hash_table<poly_int_cst_hasher> *poly_int_cst_hash_table;
200 : :
201 : : /* Hash table for optimization flags and target option flags. Use the same
202 : : hash table for both sets of options. Nodes for building the current
203 : : optimization and target option nodes. The assumption is most of the time
204 : : the options created will already be in the hash table, so we avoid
205 : : allocating and freeing up a node repeatably. */
206 : : static GTY (()) tree cl_optimization_node;
207 : : static GTY (()) tree cl_target_option_node;
208 : :
209 : : struct cl_option_hasher : ggc_cache_ptr_hash<tree_node>
210 : : {
211 : : static hashval_t hash (tree t);
212 : : static bool equal (tree x, tree y);
213 : : };
214 : :
215 : : static GTY ((cache)) hash_table<cl_option_hasher> *cl_option_hash_table;
216 : :
217 : 710496 : struct gt_value_expr_mark_data {
218 : : hash_set<tree> pset;
219 : : auto_vec<tree, 16> to_mark;
220 : : };
221 : :
222 : : /* Callback called through walk_tree_1 to discover DECL_HAS_VALUE_EXPR_P
223 : : VAR_DECLs which weren't marked yet, in that case marks them and
224 : : walks their DECL_VALUE_EXPR expressions. */
225 : :
226 : : static tree
227 : 13815956 : gt_value_expr_mark_2 (tree *tp, int *, void *data)
228 : : {
229 : 13815956 : tree t = *tp;
230 : 13815956 : if (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t) && !ggc_marked_p (t))
231 : : {
232 : 1039 : tree dve = DECL_VALUE_EXPR (t);
233 : 1039 : gt_value_expr_mark_data *d = (gt_value_expr_mark_data *) data;
234 : 1039 : walk_tree_1 (&dve, gt_value_expr_mark_2, data, &d->pset, NULL);
235 : 1039 : d->to_mark.safe_push (t);
236 : : }
237 : 13815956 : return NULL_TREE;
238 : : }
239 : :
240 : : /* Callback called through traverse_noresize on the
241 : : value_expr_for_decl hash table. */
242 : :
243 : : int
244 : 5702246 : gt_value_expr_mark_1 (tree_decl_map **e, gt_value_expr_mark_data *data)
245 : : {
246 : 5702246 : if (ggc_marked_p ((*e)->base.from))
247 : 4924723 : walk_tree_1 (&(*e)->to, gt_value_expr_mark_2, data, &data->pset, NULL);
248 : 5702246 : return 1;
249 : : }
250 : :
251 : : /* The value_expr_for_decl hash table can have mappings for trees
252 : : which are only referenced from mappings of other trees in the
253 : : same table, see PR118790. Without this routine, gt_cleare_cache
254 : : could clear hash table slot of a tree which isn't marked but
255 : : will be marked when processing later hash table slot of another
256 : : tree which is marked. This function marks with the above
257 : : helpers marks all the not yet marked DECL_HAS_VALUE_EXPR_P
258 : : VAR_DECLs mentioned in DECL_VALUE_EXPR expressions of marked
259 : : trees and in that case also recurses on their DECL_VALUE_EXPR. */
260 : :
261 : : void
262 : 710496 : gt_value_expr_mark (hash_table<tree_decl_map_cache_hasher> *h)
263 : : {
264 : 710496 : if (!h)
265 : 0 : return;
266 : :
267 : 710496 : gt_value_expr_mark_data data;
268 : 710496 : h->traverse_noresize<gt_value_expr_mark_data *,
269 : 6412742 : gt_value_expr_mark_1> (&data);
270 : 2132527 : for (auto v : data.to_mark)
271 : 1039 : gt_ggc_mx (v);
272 : 710496 : }
273 : :
274 : : /* General tree->tree mapping structure for use in hash tables. */
275 : :
276 : :
277 : : static GTY ((cache))
278 : : hash_table<tree_decl_map_cache_hasher> *debug_expr_for_decl;
279 : :
280 : : static GTY ((cache ("gt_value_expr_mark")))
281 : : hash_table<tree_decl_map_cache_hasher> *value_expr_for_decl;
282 : :
283 : : static GTY ((cache))
284 : : hash_table<tree_vec_map_cache_hasher> *debug_args_for_decl;
285 : :
286 : : static void set_type_quals (tree, int);
287 : : static void print_type_hash_statistics (void);
288 : : static void print_debug_expr_statistics (void);
289 : : static void print_value_expr_statistics (void);
290 : :
291 : : tree global_trees[TI_MAX];
292 : : tree integer_types[itk_none];
293 : :
294 : : bool int_n_enabled_p[NUM_INT_N_ENTS];
295 : : struct int_n_trees_t int_n_trees [NUM_INT_N_ENTS];
296 : :
297 : : bool tree_contains_struct[MAX_TREE_CODES][64];
298 : :
299 : : /* Number of operands for each OMP clause. */
300 : : unsigned const char omp_clause_num_ops[] =
301 : : {
302 : : 0, /* OMP_CLAUSE_ERROR */
303 : : 1, /* OMP_CLAUSE_PRIVATE */
304 : : 1, /* OMP_CLAUSE_SHARED */
305 : : 1, /* OMP_CLAUSE_FIRSTPRIVATE */
306 : : 2, /* OMP_CLAUSE_LASTPRIVATE */
307 : : 5, /* OMP_CLAUSE_REDUCTION */
308 : : 5, /* OMP_CLAUSE_TASK_REDUCTION */
309 : : 5, /* OMP_CLAUSE_IN_REDUCTION */
310 : : 1, /* OMP_CLAUSE_COPYIN */
311 : : 1, /* OMP_CLAUSE_COPYPRIVATE */
312 : : 3, /* OMP_CLAUSE_LINEAR */
313 : : 1, /* OMP_CLAUSE_AFFINITY */
314 : : 2, /* OMP_CLAUSE_ALIGNED */
315 : : 3, /* OMP_CLAUSE_ALLOCATE */
316 : : 1, /* OMP_CLAUSE_DEPEND */
317 : : 1, /* OMP_CLAUSE_NONTEMPORAL */
318 : : 1, /* OMP_CLAUSE_UNIFORM */
319 : : 1, /* OMP_CLAUSE_ENTER */
320 : : 1, /* OMP_CLAUSE_LINK */
321 : : 1, /* OMP_CLAUSE_DETACH */
322 : : 1, /* OMP_CLAUSE_USE_DEVICE_PTR */
323 : : 1, /* OMP_CLAUSE_USE_DEVICE_ADDR */
324 : : 1, /* OMP_CLAUSE_IS_DEVICE_PTR */
325 : : 1, /* OMP_CLAUSE_INCLUSIVE */
326 : : 1, /* OMP_CLAUSE_EXCLUSIVE */
327 : : 3, /* OMP_CLAUSE_FROM */
328 : : 3, /* OMP_CLAUSE_TO */
329 : : 3, /* OMP_CLAUSE_MAP (update walk_tree_1 if this is changed) */
330 : : 1, /* OMP_CLAUSE_HAS_DEVICE_ADDR */
331 : : 1, /* OMP_CLAUSE_DOACROSS */
332 : : 3, /* OMP_CLAUSE__MAPPER_BINDING_ */
333 : : 2, /* OMP_CLAUSE__CACHE_ */
334 : : 1, /* OMP_CLAUSE_DESTROY */
335 : : 2, /* OMP_CLAUSE_INIT */
336 : : 1, /* OMP_CLAUSE_USE */
337 : : 1, /* OMP_CLAUSE_INTEROP */
338 : : 2, /* OMP_CLAUSE_GANG */
339 : : 1, /* OMP_CLAUSE_ASYNC */
340 : : 1, /* OMP_CLAUSE_WAIT */
341 : : 0, /* OMP_CLAUSE_AUTO */
342 : : 0, /* OMP_CLAUSE_SEQ */
343 : : 1, /* OMP_CLAUSE__LOOPTEMP_ */
344 : : 1, /* OMP_CLAUSE__REDUCTEMP_ */
345 : : 1, /* OMP_CLAUSE__CONDTEMP_ */
346 : : 1, /* OMP_CLAUSE__SCANTEMP_ */
347 : : 1, /* OMP_CLAUSE_IF */
348 : : 1, /* OMP_CLAUSE_SELF */
349 : : 1, /* OMP_CLAUSE_NUM_THREADS */
350 : : 1, /* OMP_CLAUSE_SCHEDULE */
351 : : 0, /* OMP_CLAUSE_NOWAIT */
352 : : 1, /* OMP_CLAUSE_ORDERED */
353 : : 0, /* OMP_CLAUSE_DEFAULT */
354 : : 3, /* OMP_CLAUSE_COLLAPSE */
355 : : 0, /* OMP_CLAUSE_UNTIED */
356 : : 1, /* OMP_CLAUSE_FINAL */
357 : : 0, /* OMP_CLAUSE_MERGEABLE */
358 : : 1, /* OMP_CLAUSE_DEVICE */
359 : : 1, /* OMP_CLAUSE_DIST_SCHEDULE */
360 : : 0, /* OMP_CLAUSE_INBRANCH */
361 : : 0, /* OMP_CLAUSE_NOTINBRANCH */
362 : : 2, /* OMP_CLAUSE_NUM_TEAMS */
363 : : 1, /* OMP_CLAUSE_THREAD_LIMIT */
364 : : 0, /* OMP_CLAUSE_PROC_BIND */
365 : : 1, /* OMP_CLAUSE_SAFELEN */
366 : : 1, /* OMP_CLAUSE_SIMDLEN */
367 : : 0, /* OMP_CLAUSE_DEVICE_TYPE */
368 : : 0, /* OMP_CLAUSE_FOR */
369 : : 0, /* OMP_CLAUSE_PARALLEL */
370 : : 0, /* OMP_CLAUSE_SECTIONS */
371 : : 0, /* OMP_CLAUSE_TASKGROUP */
372 : : 1, /* OMP_CLAUSE_PRIORITY */
373 : : 1, /* OMP_CLAUSE_GRAINSIZE */
374 : : 1, /* OMP_CLAUSE_NUM_TASKS */
375 : : 0, /* OMP_CLAUSE_NOGROUP */
376 : : 0, /* OMP_CLAUSE_THREADS */
377 : : 0, /* OMP_CLAUSE_SIMD */
378 : : 1, /* OMP_CLAUSE_HINT */
379 : : 0, /* OMP_CLAUSE_DEFAULTMAP */
380 : : 0, /* OMP_CLAUSE_ORDER */
381 : : 0, /* OMP_CLAUSE_BIND */
382 : : 1, /* OMP_CLAUSE_FILTER */
383 : : 1, /* OMP_CLAUSE_INDIRECT */
384 : : 1, /* OMP_CLAUSE_PARTIAL */
385 : : 0, /* OMP_CLAUSE_FULL */
386 : : 1, /* OMP_CLAUSE_SIZES */
387 : : 1, /* OMP_CLAUSE__SIMDUID_ */
388 : : 0, /* OMP_CLAUSE__SIMT_ */
389 : : 0, /* OMP_CLAUSE_INDEPENDENT */
390 : : 1, /* OMP_CLAUSE_WORKER */
391 : : 1, /* OMP_CLAUSE_VECTOR */
392 : : 1, /* OMP_CLAUSE_NUM_GANGS */
393 : : 1, /* OMP_CLAUSE_NUM_WORKERS */
394 : : 1, /* OMP_CLAUSE_VECTOR_LENGTH */
395 : : 3, /* OMP_CLAUSE_TILE */
396 : : 0, /* OMP_CLAUSE_IF_PRESENT */
397 : : 0, /* OMP_CLAUSE_FINALIZE */
398 : : 0, /* OMP_CLAUSE_NOHOST */
399 : : 1, /* OMP_CLAUSE_NOVARIANTS */
400 : : 1, /* OMP_CLAUSE_NOCONTEXT */
401 : : };
402 : :
403 : : const char * const omp_clause_code_name[] =
404 : : {
405 : : "error_clause",
406 : : "private",
407 : : "shared",
408 : : "firstprivate",
409 : : "lastprivate",
410 : : "reduction",
411 : : "task_reduction",
412 : : "in_reduction",
413 : : "copyin",
414 : : "copyprivate",
415 : : "linear",
416 : : "affinity",
417 : : "aligned",
418 : : "allocate",
419 : : "depend",
420 : : "nontemporal",
421 : : "uniform",
422 : : "enter",
423 : : "link",
424 : : "detach",
425 : : "use_device_ptr",
426 : : "use_device_addr",
427 : : "is_device_ptr",
428 : : "inclusive",
429 : : "exclusive",
430 : : "from",
431 : : "to",
432 : : "map",
433 : : "has_device_addr",
434 : : "doacross",
435 : : "_mapper_binding_",
436 : : "_cache_",
437 : : "destroy",
438 : : "init",
439 : : "use",
440 : : "interop",
441 : : "gang",
442 : : "async",
443 : : "wait",
444 : : "auto",
445 : : "seq",
446 : : "_looptemp_",
447 : : "_reductemp_",
448 : : "_condtemp_",
449 : : "_scantemp_",
450 : : "if",
451 : : "self",
452 : : "num_threads",
453 : : "schedule",
454 : : "nowait",
455 : : "ordered",
456 : : "default",
457 : : "collapse",
458 : : "untied",
459 : : "final",
460 : : "mergeable",
461 : : "device",
462 : : "dist_schedule",
463 : : "inbranch",
464 : : "notinbranch",
465 : : "num_teams",
466 : : "thread_limit",
467 : : "proc_bind",
468 : : "safelen",
469 : : "simdlen",
470 : : "device_type",
471 : : "for",
472 : : "parallel",
473 : : "sections",
474 : : "taskgroup",
475 : : "priority",
476 : : "grainsize",
477 : : "num_tasks",
478 : : "nogroup",
479 : : "threads",
480 : : "simd",
481 : : "hint",
482 : : "defaultmap",
483 : : "order",
484 : : "bind",
485 : : "filter",
486 : : "indirect",
487 : : "partial",
488 : : "full",
489 : : "sizes",
490 : : "_simduid_",
491 : : "_simt_",
492 : : "independent",
493 : : "worker",
494 : : "vector",
495 : : "num_gangs",
496 : : "num_workers",
497 : : "vector_length",
498 : : "tile",
499 : : "if_present",
500 : : "finalize",
501 : : "nohost",
502 : : "novariants",
503 : : "nocontext",
504 : : };
505 : :
506 : : /* Unless specific to OpenACC, we tend to internally maintain OpenMP-centric
507 : : clause names, but for use in diagnostics etc. would like to use the "user"
508 : : clause names. */
509 : :
510 : : const char *
511 : 445 : user_omp_clause_code_name (tree clause, bool oacc)
512 : : {
513 : : /* For OpenACC, the 'OMP_CLAUSE_MAP_KIND' of an 'OMP_CLAUSE_MAP' is used to
514 : : distinguish clauses as seen by the user. See also where front ends do
515 : : 'build_omp_clause' with 'OMP_CLAUSE_MAP'. */
516 : 890 : if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP)
517 : 445 : switch (OMP_CLAUSE_MAP_KIND (clause))
518 : : {
519 : : case GOMP_MAP_FORCE_ALLOC:
520 : : case GOMP_MAP_ALLOC: return "create";
521 : 0 : case GOMP_MAP_FORCE_TO:
522 : 0 : case GOMP_MAP_TO: return "copyin";
523 : 0 : case GOMP_MAP_FORCE_FROM:
524 : 0 : case GOMP_MAP_FROM: return "copyout";
525 : 361 : case GOMP_MAP_FORCE_TOFROM:
526 : 361 : case GOMP_MAP_TOFROM: return "copy";
527 : 0 : case GOMP_MAP_RELEASE: return "delete";
528 : 0 : case GOMP_MAP_FORCE_PRESENT: return "present";
529 : 42 : case GOMP_MAP_ATTACH: return "attach";
530 : 42 : case GOMP_MAP_FORCE_DETACH:
531 : 42 : case GOMP_MAP_DETACH: return "detach";
532 : 0 : case GOMP_MAP_DEVICE_RESIDENT: return "device_resident";
533 : 0 : case GOMP_MAP_LINK: return "link";
534 : 0 : case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr";
535 : : default: break;
536 : : }
537 : :
538 : 0 : return omp_clause_code_name[OMP_CLAUSE_CODE (clause)];
539 : : }
540 : :
541 : :
542 : : /* Return the tree node structure used by tree code CODE. */
543 : :
544 : : static inline enum tree_node_structure_enum
545 : 36369781667 : tree_node_structure_for_code (enum tree_code code)
546 : : {
547 : 36369781667 : switch (TREE_CODE_CLASS (code))
548 : : {
549 : 9089150459 : case tcc_declaration:
550 : 9089150459 : switch (code)
551 : : {
552 : : case CONST_DECL: return TS_CONST_DECL;
553 : : case DEBUG_EXPR_DECL: return TS_DECL_WRTL;
554 : : case FIELD_DECL: return TS_FIELD_DECL;
555 : : case FUNCTION_DECL: return TS_FUNCTION_DECL;
556 : : case LABEL_DECL: return TS_LABEL_DECL;
557 : : case PARM_DECL: return TS_PARM_DECL;
558 : : case RESULT_DECL: return TS_RESULT_DECL;
559 : : case TRANSLATION_UNIT_DECL: return TS_TRANSLATION_UNIT_DECL;
560 : : case TYPE_DECL: return TS_TYPE_DECL;
561 : : case VAR_DECL: return TS_VAR_DECL;
562 : : default: return TS_DECL_NON_COMMON;
563 : : }
564 : :
565 : : case tcc_type: return TS_TYPE_NON_COMMON;
566 : :
567 : 9198585349 : case tcc_binary:
568 : 9198585349 : case tcc_comparison:
569 : 9198585349 : case tcc_expression:
570 : 9198585349 : case tcc_reference:
571 : 9198585349 : case tcc_statement:
572 : 9198585349 : case tcc_unary:
573 : 9198585349 : case tcc_vl_exp: return TS_EXP;
574 : :
575 : 13049058449 : default: /* tcc_constant and tcc_exceptional */
576 : 13049058449 : break;
577 : : }
578 : :
579 : 13049058449 : switch (code)
580 : : {
581 : : /* tcc_constant cases. */
582 : : case COMPLEX_CST: return TS_COMPLEX;
583 : 289080 : case FIXED_CST: return TS_FIXED_CST;
584 : 435246280 : case INTEGER_CST: return TS_INT_CST;
585 : 289080 : case POLY_INT_CST: return TS_POLY_INT_CST;
586 : 39895740 : case REAL_CST: return TS_REAL_CST;
587 : 225991534 : case STRING_CST: return TS_STRING;
588 : 11436576 : case VECTOR_CST: return TS_VECTOR;
589 : 1000510 : case VOID_CST: return TS_TYPED;
590 : 289248 : case RAW_DATA_CST: return TS_RAW_DATA_CST;
591 : :
592 : : /* tcc_exceptional cases. */
593 : 604343974 : case BLOCK: return TS_BLOCK;
594 : 104308746 : case CONSTRUCTOR: return TS_CONSTRUCTOR;
595 : : case ERROR_MARK: return TS_COMMON;
596 : 8764903 : case IDENTIFIER_NODE: return TS_IDENTIFIER;
597 : 819968 : case OMP_CLAUSE: return TS_OMP_CLAUSE;
598 : 1724227 : case OPTIMIZATION_NODE: return TS_OPTIMIZATION;
599 : : case PLACEHOLDER_EXPR: return TS_COMMON;
600 : 251870737 : case SSA_NAME: return TS_SSA_NAME;
601 : 619282099 : case STATEMENT_LIST: return TS_STATEMENT_LIST;
602 : 3609159 : case TARGET_OPTION_NODE: return TS_TARGET_OPTION;
603 : 237161010 : case TREE_BINFO: return TS_BINFO;
604 : 8738826060 : case TREE_LIST: return TS_LIST;
605 : 1762132928 : case TREE_VEC: return TS_VEC;
606 : :
607 : 0 : default:
608 : 0 : gcc_unreachable ();
609 : : }
610 : : }
611 : :
612 : :
613 : : /* Initialize tree_contains_struct to describe the hierarchy of tree
614 : : nodes. */
615 : :
616 : : static void
617 : 289080 : initialize_tree_contains_struct (void)
618 : : {
619 : 289080 : unsigned i;
620 : :
621 : 71113680 : for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++)
622 : : {
623 : 70824600 : enum tree_code code;
624 : 70824600 : enum tree_node_structure_enum ts_code;
625 : :
626 : 70824600 : code = (enum tree_code) i;
627 : 70824600 : ts_code = tree_node_structure_for_code (code);
628 : :
629 : : /* Mark the TS structure itself. */
630 : 70824600 : tree_contains_struct[code][ts_code] = 1;
631 : :
632 : : /* Mark all the structures that TS is derived from. */
633 : 70824600 : switch (ts_code)
634 : : {
635 : 1156320 : case TS_TYPED:
636 : 1156320 : case TS_BLOCK:
637 : 1156320 : case TS_OPTIMIZATION:
638 : 1156320 : case TS_TARGET_OPTION:
639 : 1156320 : MARK_TS_BASE (code);
640 : 1156320 : break;
641 : :
642 : 58394160 : case TS_COMMON:
643 : 58394160 : case TS_INT_CST:
644 : 58394160 : case TS_POLY_INT_CST:
645 : 58394160 : case TS_REAL_CST:
646 : 58394160 : case TS_FIXED_CST:
647 : 58394160 : case TS_VECTOR:
648 : 58394160 : case TS_STRING:
649 : 58394160 : case TS_RAW_DATA_CST:
650 : 58394160 : case TS_COMPLEX:
651 : 58394160 : case TS_SSA_NAME:
652 : 58394160 : case TS_CONSTRUCTOR:
653 : 58394160 : case TS_EXP:
654 : 58394160 : case TS_STATEMENT_LIST:
655 : 58394160 : MARK_TS_TYPED (code);
656 : 58394160 : break;
657 : :
658 : 1445400 : case TS_IDENTIFIER:
659 : 1445400 : case TS_DECL_MINIMAL:
660 : 1445400 : case TS_TYPE_COMMON:
661 : 1445400 : case TS_LIST:
662 : 1445400 : case TS_VEC:
663 : 1445400 : case TS_BINFO:
664 : 1445400 : case TS_OMP_CLAUSE:
665 : 1445400 : MARK_TS_COMMON (code);
666 : 1445400 : break;
667 : :
668 : 0 : case TS_TYPE_WITH_LANG_SPECIFIC:
669 : 0 : MARK_TS_TYPE_COMMON (code);
670 : 0 : break;
671 : :
672 : 6070680 : case TS_TYPE_NON_COMMON:
673 : 6070680 : MARK_TS_TYPE_WITH_LANG_SPECIFIC (code);
674 : 6070680 : break;
675 : :
676 : 0 : case TS_DECL_COMMON:
677 : 0 : MARK_TS_DECL_MINIMAL (code);
678 : 0 : break;
679 : :
680 : 578160 : case TS_DECL_WRTL:
681 : 578160 : case TS_CONST_DECL:
682 : 578160 : MARK_TS_DECL_COMMON (code);
683 : 578160 : break;
684 : :
685 : 867240 : case TS_DECL_NON_COMMON:
686 : 867240 : MARK_TS_DECL_WITH_VIS (code);
687 : 867240 : break;
688 : :
689 : 867240 : case TS_DECL_WITH_VIS:
690 : 867240 : case TS_PARM_DECL:
691 : 867240 : case TS_LABEL_DECL:
692 : 867240 : case TS_RESULT_DECL:
693 : 867240 : MARK_TS_DECL_WRTL (code);
694 : 867240 : break;
695 : :
696 : 289080 : case TS_FIELD_DECL:
697 : 289080 : MARK_TS_DECL_COMMON (code);
698 : 289080 : break;
699 : :
700 : 289080 : case TS_VAR_DECL:
701 : 289080 : MARK_TS_DECL_WITH_VIS (code);
702 : 289080 : break;
703 : :
704 : 578160 : case TS_TYPE_DECL:
705 : 578160 : case TS_FUNCTION_DECL:
706 : 578160 : MARK_TS_DECL_NON_COMMON (code);
707 : 578160 : break;
708 : :
709 : 289080 : case TS_TRANSLATION_UNIT_DECL:
710 : 289080 : MARK_TS_DECL_COMMON (code);
711 : 289080 : break;
712 : :
713 : : default:
714 : : gcc_unreachable ();
715 : : }
716 : : }
717 : :
718 : : /* Basic consistency checks for attributes used in fold. */
719 : 289080 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]);
720 : 289080 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]);
721 : 289080 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]);
722 : 289080 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]);
723 : 289080 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]);
724 : 289080 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]);
725 : 289080 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]);
726 : 289080 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]);
727 : 289080 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]);
728 : 289080 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]);
729 : 289080 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]);
730 : 289080 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]);
731 : 289080 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]);
732 : 289080 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]);
733 : 289080 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]);
734 : 289080 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]);
735 : 289080 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]);
736 : 289080 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]);
737 : 289080 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]);
738 : 289080 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]);
739 : 289080 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]);
740 : 289080 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]);
741 : 289080 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]);
742 : 289080 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]);
743 : 289080 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]);
744 : 289080 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]);
745 : 289080 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]);
746 : 289080 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]);
747 : 289080 : gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]);
748 : 289080 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]);
749 : 289080 : gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]);
750 : 289080 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]);
751 : 289080 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]);
752 : 289080 : gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]);
753 : 289080 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]);
754 : 289080 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]);
755 : 289080 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]);
756 : 289080 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]);
757 : 289080 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_MINIMAL]);
758 : 289080 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_COMMON]);
759 : 289080 : }
760 : :
761 : :
762 : : /* Init tree.cc. */
763 : :
764 : : void
765 : 289080 : init_ttree (void)
766 : : {
767 : : /* Initialize the hash table of types. */
768 : 289080 : type_hash_table
769 : 289080 : = hash_table<type_cache_hasher>::create_ggc (TYPE_HASH_INITIAL_SIZE);
770 : :
771 : 289080 : debug_expr_for_decl
772 : 289080 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
773 : :
774 : 289080 : value_expr_for_decl
775 : 289080 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
776 : :
777 : 289080 : int_cst_hash_table = hash_table<int_cst_hasher>::create_ggc (1024);
778 : :
779 : 289080 : poly_int_cst_hash_table = hash_table<poly_int_cst_hasher>::create_ggc (64);
780 : :
781 : 289080 : int_cst_node = make_int_cst (1, 1);
782 : :
783 : 289080 : cl_option_hash_table = hash_table<cl_option_hasher>::create_ggc (64);
784 : :
785 : 289080 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
786 : 289080 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
787 : :
788 : : /* Initialize the tree_contains_struct array. */
789 : 289080 : initialize_tree_contains_struct ();
790 : 289080 : lang_hooks.init_ts ();
791 : 289080 : }
792 : :
793 : :
794 : : /* Mapping from prefix to label number. */
795 : :
796 : : struct identifier_hash : ggc_ptr_hash <tree_node>
797 : : {
798 : 33759 : static inline hashval_t hash (tree t)
799 : : {
800 : 33759 : return IDENTIFIER_HASH_VALUE (t);
801 : : }
802 : : };
803 : : struct identifier_count_traits
804 : : : simple_hashmap_traits<identifier_hash, long> {};
805 : : typedef hash_map<tree, long, identifier_count_traits> internal_label_map;
806 : : static GTY(()) internal_label_map *internal_label_nums;
807 : :
808 : : /* Generates an identifier intended to be used internally with the
809 : : given PREFIX. This is intended to be used by the frontend so that
810 : : C++ modules can regenerate appropriate (non-clashing) identifiers on
811 : : stream-in. */
812 : :
813 : : tree
814 : 33576 : generate_internal_label (const char *prefix)
815 : : {
816 : 33576 : tree prefix_id = get_identifier (prefix);
817 : 33576 : if (!internal_label_nums)
818 : 2655 : internal_label_nums = internal_label_map::create_ggc();
819 : 33576 : long &num = internal_label_nums->get_or_insert (prefix_id);
820 : :
821 : 33576 : char tmp[32];
822 : 33576 : ASM_GENERATE_INTERNAL_LABEL (tmp, prefix, num++);
823 : :
824 : 33576 : tree id = get_identifier (tmp);
825 : 33576 : IDENTIFIER_INTERNAL_P (id) = true;
826 : :
827 : : /* Cache the prefix on the identifier so we can retrieve it later. */
828 : 33576 : TREE_CHAIN (id) = prefix_id;
829 : :
830 : 33576 : return id;
831 : : }
832 : :
833 : : /* Get the PREFIX we created the internal identifier LABEL with. */
834 : :
835 : : const char *
836 : 7 : prefix_for_internal_label (tree label)
837 : : {
838 : 7 : gcc_assert (IDENTIFIER_INTERNAL_P (label)
839 : : && !IDENTIFIER_TRANSPARENT_ALIAS (label)
840 : : && TREE_CHAIN (label)
841 : : && TREE_CODE (TREE_CHAIN (label)) == IDENTIFIER_NODE);
842 : 7 : return IDENTIFIER_POINTER (TREE_CHAIN (label));
843 : : }
844 : :
845 : : /* The name of the object as the assembler will see it (but before any
846 : : translations made by ASM_OUTPUT_LABELREF). Often this is the same
847 : : as DECL_NAME. It is an IDENTIFIER_NODE. */
848 : : tree
849 : 1591751390 : decl_assembler_name (tree decl)
850 : : {
851 : 1591751390 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
852 : 135022328 : lang_hooks.set_decl_assembler_name (decl);
853 : 1591751390 : return DECL_ASSEMBLER_NAME_RAW (decl);
854 : : }
855 : :
856 : : /* The DECL_ASSEMBLER_NAME_RAW of DECL is being explicitly set to NAME
857 : : (either of which may be NULL). Inform the FE, if this changes the
858 : : name. */
859 : :
860 : : void
861 : 778672662 : overwrite_decl_assembler_name (tree decl, tree name)
862 : : {
863 : 778672662 : if (DECL_ASSEMBLER_NAME_RAW (decl) != name)
864 : 411209162 : lang_hooks.overwrite_decl_assembler_name (decl, name);
865 : 778672662 : }
866 : :
867 : : /* Return true if DECL may need an assembler name to be set. */
868 : :
869 : : static inline bool
870 : 5035602 : need_assembler_name_p (tree decl)
871 : : {
872 : : /* We use DECL_ASSEMBLER_NAME to hold mangled type names for One Definition
873 : : Rule merging. This makes type_odr_p to return true on those types during
874 : : LTO and by comparing the mangled name, we can say what types are intended
875 : : to be equivalent across compilation unit.
876 : :
877 : : We do not store names of type_in_anonymous_namespace_p.
878 : :
879 : : Record, union and enumeration type have linkage that allows use
880 : : to check type_in_anonymous_namespace_p. We do not mangle compound types
881 : : that always can be compared structurally.
882 : :
883 : : Similarly for builtin types, we compare properties of their main variant.
884 : : A special case are integer types where mangling do make differences
885 : : between char/signed char/unsigned char etc. Storing name for these makes
886 : : e.g. -fno-signed-char/-fsigned-char mismatches to be handled well.
887 : : See cp/mangle.cc:write_builtin_type for details. */
888 : :
889 : 5035602 : if (TREE_CODE (decl) == TYPE_DECL)
890 : : {
891 : 155626 : if (DECL_NAME (decl)
892 : 126512 : && decl == TYPE_NAME (TREE_TYPE (decl))
893 : 126361 : && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TREE_TYPE (decl)
894 : 107839 : && !TYPE_ARTIFICIAL (TREE_TYPE (decl))
895 : 104816 : && ((TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
896 : 87594 : && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE)
897 : 17460 : || TYPE_CXX_ODR_P (TREE_TYPE (decl)))
898 : 103417 : && (type_with_linkage_p (TREE_TYPE (decl))
899 : 89153 : || TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE)
900 : 223588 : && !variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
901 : 67962 : return !DECL_ASSEMBLER_NAME_SET_P (decl);
902 : 87664 : return false;
903 : : }
904 : : /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
905 : 4879976 : if (!VAR_OR_FUNCTION_DECL_P (decl))
906 : : return false;
907 : :
908 : : /* If DECL already has its assembler name set, it does not need a
909 : : new one. */
910 : 4205693 : if (!HAS_DECL_ASSEMBLER_NAME_P (decl)
911 : 4205693 : || DECL_ASSEMBLER_NAME_SET_P (decl))
912 : : return false;
913 : :
914 : : /* Abstract decls do not need an assembler name, except they
915 : : can be looked up by autofdo. */
916 : 1665879 : if (DECL_ABSTRACT_P (decl) && !flag_auto_profile)
917 : : return false;
918 : :
919 : : /* For VAR_DECLs, only static, public and external symbols need an
920 : : assembler name. */
921 : 1664560 : if (VAR_P (decl)
922 : 534958 : && !TREE_STATIC (decl)
923 : 534630 : && !TREE_PUBLIC (decl)
924 : 2199190 : && !DECL_EXTERNAL (decl))
925 : : return false;
926 : :
927 : 1129930 : if (TREE_CODE (decl) == FUNCTION_DECL)
928 : : {
929 : : /* Do not set assembler name on builtins. Allow RTL expansion to
930 : : decide whether to expand inline or via a regular call. */
931 : 1129602 : if (fndecl_built_in_p (decl)
932 : 1129602 : && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND)
933 : : return false;
934 : :
935 : : /* Functions represented in the callgraph need an assembler name. */
936 : 1124893 : if (cgraph_node::get (decl) != NULL)
937 : : return true;
938 : :
939 : : /* Unused and not public functions don't need an assembler name. */
940 : 3169 : if (!TREE_USED (decl) && !TREE_PUBLIC (decl))
941 : : return false;
942 : : }
943 : :
944 : : return true;
945 : : }
946 : :
947 : : /* If T needs an assembler name, have one created for it. */
948 : :
949 : : void
950 : 5035602 : assign_assembler_name_if_needed (tree t)
951 : : {
952 : 5035602 : if (need_assembler_name_p (t))
953 : : {
954 : : /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
955 : : diagnostics that use input_location to show locus
956 : : information. The problem here is that, at this point,
957 : : input_location is generally anchored to the end of the file
958 : : (since the parser is long gone), so we don't have a good
959 : : position to pin it to.
960 : :
961 : : To alleviate this problem, this uses the location of T's
962 : : declaration. Examples of this are
963 : : testsuite/g++.dg/template/cond2.C and
964 : : testsuite/g++.dg/template/pr35240.C. */
965 : 1193157 : location_t saved_location = input_location;
966 : 1193157 : input_location = DECL_SOURCE_LOCATION (t);
967 : :
968 : 1193157 : decl_assembler_name (t);
969 : :
970 : 1193157 : input_location = saved_location;
971 : : }
972 : 5035602 : }
973 : :
974 : : /* When the target supports COMDAT groups, this indicates which group the
975 : : DECL is associated with. This can be either an IDENTIFIER_NODE or a
976 : : decl, in which case its DECL_ASSEMBLER_NAME identifies the group. */
977 : : tree
978 : 367114169 : decl_comdat_group (const_tree node)
979 : : {
980 : 367114169 : struct symtab_node *snode = symtab_node::get (node);
981 : 367114169 : if (!snode)
982 : : return NULL;
983 : 350478682 : return snode->get_comdat_group ();
984 : : }
985 : :
986 : : /* Likewise, but make sure it's been reduced to an IDENTIFIER_NODE. */
987 : : tree
988 : 11748 : decl_comdat_group_id (const_tree node)
989 : : {
990 : 11748 : struct symtab_node *snode = symtab_node::get (node);
991 : 11748 : if (!snode)
992 : : return NULL;
993 : 11748 : return snode->get_comdat_group_id ();
994 : : }
995 : :
996 : : /* When the target supports named section, return its name as IDENTIFIER_NODE
997 : : or NULL if it is in no section. */
998 : : const char *
999 : 688509506 : decl_section_name (const_tree node)
1000 : : {
1001 : 688509506 : struct symtab_node *snode = symtab_node::get (node);
1002 : 688509506 : if (!snode)
1003 : : return NULL;
1004 : 539220305 : return snode->get_section ();
1005 : : }
1006 : :
1007 : : /* Set section name of NODE to VALUE (that is expected to be
1008 : : identifier node) */
1009 : : void
1010 : 1803117 : set_decl_section_name (tree node, const char *value)
1011 : : {
1012 : 1803117 : struct symtab_node *snode;
1013 : :
1014 : 1803117 : if (value == NULL)
1015 : : {
1016 : 46 : snode = symtab_node::get (node);
1017 : 46 : if (!snode)
1018 : : return;
1019 : : }
1020 : 1803071 : else if (VAR_P (node))
1021 : 1554822 : snode = varpool_node::get_create (node);
1022 : : else
1023 : 248249 : snode = cgraph_node::get_create (node);
1024 : 1803117 : snode->set_section (value);
1025 : : }
1026 : :
1027 : : /* Set section name of NODE to match the section name of OTHER.
1028 : :
1029 : : set_decl_section_name (decl, other) is equivalent to
1030 : : set_decl_section_name (decl, DECL_SECTION_NAME (other)), but possibly more
1031 : : efficient. */
1032 : : void
1033 : 13906586 : set_decl_section_name (tree decl, const_tree other)
1034 : : {
1035 : 13906586 : struct symtab_node *other_node = symtab_node::get (other);
1036 : 13906586 : if (other_node)
1037 : : {
1038 : 13906240 : struct symtab_node *decl_node;
1039 : 13906240 : if (VAR_P (decl))
1040 : 23 : decl_node = varpool_node::get_create (decl);
1041 : : else
1042 : 13906217 : decl_node = cgraph_node::get_create (decl);
1043 : 13906240 : decl_node->set_section (*other_node);
1044 : : }
1045 : : else
1046 : : {
1047 : 346 : struct symtab_node *decl_node = symtab_node::get (decl);
1048 : 346 : if (!decl_node)
1049 : : return;
1050 : 0 : decl_node->set_section (NULL);
1051 : : }
1052 : : }
1053 : :
1054 : : /* Return TLS model of a variable NODE. */
1055 : : enum tls_model
1056 : 245047536 : decl_tls_model (const_tree node)
1057 : : {
1058 : 245047536 : struct varpool_node *snode = varpool_node::get (node);
1059 : 245047536 : if (!snode)
1060 : : return TLS_MODEL_NONE;
1061 : 205094762 : return snode->tls_model;
1062 : : }
1063 : :
1064 : : /* Set TLS model of variable NODE to MODEL. */
1065 : : void
1066 : 58566 : set_decl_tls_model (tree node, enum tls_model model)
1067 : : {
1068 : 58566 : struct varpool_node *vnode;
1069 : :
1070 : 58566 : if (model == TLS_MODEL_NONE)
1071 : : {
1072 : 5864 : vnode = varpool_node::get (node);
1073 : 5864 : if (!vnode)
1074 : : return;
1075 : : }
1076 : : else
1077 : 52702 : vnode = varpool_node::get_create (node);
1078 : 52702 : vnode->tls_model = model;
1079 : : }
1080 : :
1081 : : /* Compute the number of bytes occupied by a tree with code CODE.
1082 : : This function cannot be used for nodes that have variable sizes,
1083 : : including TREE_VEC, INTEGER_CST, STRING_CST, and CALL_EXPR. */
1084 : : size_t
1085 : 16013962530 : tree_code_size (enum tree_code code)
1086 : : {
1087 : 16013962530 : switch (TREE_CODE_CLASS (code))
1088 : : {
1089 : 3964380168 : case tcc_declaration: /* A decl node */
1090 : 3964380168 : switch (code)
1091 : : {
1092 : : case FIELD_DECL: return sizeof (tree_field_decl);
1093 : : case PARM_DECL: return sizeof (tree_parm_decl);
1094 : 222350763 : case VAR_DECL: return sizeof (tree_var_decl);
1095 : : case LABEL_DECL: return sizeof (tree_label_decl);
1096 : : case RESULT_DECL: return sizeof (tree_result_decl);
1097 : 31810107 : case CONST_DECL: return sizeof (tree_const_decl);
1098 : : case TYPE_DECL: return sizeof (tree_type_decl);
1099 : 1360900027 : case FUNCTION_DECL: return sizeof (tree_function_decl);
1100 : : case DEBUG_EXPR_DECL: return sizeof (tree_decl_with_rtl);
1101 : : case TRANSLATION_UNIT_DECL: return sizeof (tree_translation_unit_decl);
1102 : : case NAMESPACE_DECL:
1103 : : case IMPORTED_DECL:
1104 : : case NAMELIST_DECL: return sizeof (tree_decl_non_common);
1105 : 238274481 : default:
1106 : 238274481 : gcc_checking_assert (code >= NUM_TREE_CODES);
1107 : 238274481 : return lang_hooks.tree_size (code);
1108 : : }
1109 : :
1110 : 2743502238 : case tcc_type: /* a type node */
1111 : 2743502238 : switch (code)
1112 : : {
1113 : : case OFFSET_TYPE:
1114 : : case ENUMERAL_TYPE:
1115 : : case BOOLEAN_TYPE:
1116 : : case INTEGER_TYPE:
1117 : : case REAL_TYPE:
1118 : : case OPAQUE_TYPE:
1119 : : case POINTER_TYPE:
1120 : : case REFERENCE_TYPE:
1121 : : case NULLPTR_TYPE:
1122 : : case FIXED_POINT_TYPE:
1123 : : case COMPLEX_TYPE:
1124 : : case VECTOR_TYPE:
1125 : : case ARRAY_TYPE:
1126 : : case RECORD_TYPE:
1127 : : case UNION_TYPE:
1128 : : case QUAL_UNION_TYPE:
1129 : : case VOID_TYPE:
1130 : : case FUNCTION_TYPE:
1131 : : case METHOD_TYPE:
1132 : : case BITINT_TYPE:
1133 : : case LANG_TYPE: return sizeof (tree_type_non_common);
1134 : 644467282 : default:
1135 : 644467282 : gcc_checking_assert (code >= NUM_TREE_CODES);
1136 : 644467282 : return lang_hooks.tree_size (code);
1137 : : }
1138 : :
1139 : 4110366525 : case tcc_reference: /* a reference */
1140 : 4110366525 : case tcc_expression: /* an expression */
1141 : 4110366525 : case tcc_statement: /* an expression with side effects */
1142 : 4110366525 : case tcc_comparison: /* a comparison expression */
1143 : 4110366525 : case tcc_unary: /* a unary arithmetic expression */
1144 : 4110366525 : case tcc_binary: /* a binary arithmetic expression */
1145 : 4110366525 : return (sizeof (struct tree_exp)
1146 : 4110366525 : + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
1147 : :
1148 : 43424568 : case tcc_constant: /* a constant */
1149 : 43424568 : switch (code)
1150 : : {
1151 : : case VOID_CST: return sizeof (tree_typed);
1152 : 0 : case INTEGER_CST: gcc_unreachable ();
1153 : : case POLY_INT_CST: return sizeof (tree_poly_int_cst);
1154 : 42576065 : case REAL_CST: return sizeof (tree_real_cst);
1155 : : case FIXED_CST: return sizeof (tree_fixed_cst);
1156 : : case COMPLEX_CST: return sizeof (tree_complex);
1157 : : case RAW_DATA_CST: return sizeof (tree_raw_data);
1158 : 0 : case VECTOR_CST: gcc_unreachable ();
1159 : 0 : case STRING_CST: gcc_unreachable ();
1160 : 66459 : default:
1161 : 66459 : gcc_checking_assert (code >= NUM_TREE_CODES);
1162 : 66459 : return lang_hooks.tree_size (code);
1163 : : }
1164 : :
1165 : 5152289031 : case tcc_exceptional: /* something random, like an identifier. */
1166 : 5152289031 : switch (code)
1167 : : {
1168 : 1649614124 : case IDENTIFIER_NODE: return lang_hooks.identifier_size;
1169 : : case TREE_LIST: return sizeof (tree_list);
1170 : :
1171 : : case ERROR_MARK:
1172 : : case PLACEHOLDER_EXPR: return sizeof (tree_common);
1173 : :
1174 : 0 : case TREE_VEC: gcc_unreachable ();
1175 : 0 : case OMP_CLAUSE: gcc_unreachable ();
1176 : :
1177 : : case SSA_NAME: return sizeof (tree_ssa_name);
1178 : :
1179 : : case STATEMENT_LIST: return sizeof (tree_statement_list);
1180 : 269828525 : case BLOCK: return sizeof (struct tree_block);
1181 : : case CONSTRUCTOR: return sizeof (tree_constructor);
1182 : : case OPTIMIZATION_NODE: return sizeof (tree_optimization_option);
1183 : : case TARGET_OPTION_NODE: return sizeof (tree_target_option);
1184 : :
1185 : 1347627665 : default:
1186 : 1347627665 : gcc_checking_assert (code >= NUM_TREE_CODES);
1187 : 1347627665 : return lang_hooks.tree_size (code);
1188 : : }
1189 : :
1190 : 0 : default:
1191 : 0 : gcc_unreachable ();
1192 : : }
1193 : : }
1194 : :
1195 : : /* Compute the number of bytes occupied by NODE. This routine only
1196 : : looks at TREE_CODE, except for those nodes that have variable sizes. */
1197 : : size_t
1198 : 3607654777 : tree_size (const_tree node)
1199 : : {
1200 : 3607654777 : const enum tree_code code = TREE_CODE (node);
1201 : 3607654777 : switch (code)
1202 : : {
1203 : 11154884 : case INTEGER_CST:
1204 : 11154884 : return (sizeof (struct tree_int_cst)
1205 : 11154884 : + (TREE_INT_CST_EXT_NUNITS (node) - 1) * sizeof (HOST_WIDE_INT));
1206 : :
1207 : 0 : case TREE_BINFO:
1208 : 0 : return (offsetof (struct tree_binfo, base_binfos)
1209 : : + vec<tree, va_gc>
1210 : 0 : ::embedded_size (BINFO_N_BASE_BINFOS (node)));
1211 : :
1212 : 359777999 : case TREE_VEC:
1213 : 359777999 : return (sizeof (struct tree_vec)
1214 : 359777999 : + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
1215 : :
1216 : 0 : case VECTOR_CST:
1217 : 0 : return (sizeof (struct tree_vector)
1218 : 0 : + (vector_cst_encoded_nelts (node) - 1) * sizeof (tree));
1219 : :
1220 : 22277 : case STRING_CST:
1221 : 22277 : return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
1222 : :
1223 : 32640 : case OMP_CLAUSE:
1224 : 32640 : return (sizeof (struct tree_omp_clause)
1225 : 32640 : + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
1226 : 32640 : * sizeof (tree));
1227 : :
1228 : 3236666977 : default:
1229 : 3236666977 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
1230 : 146789689 : return (sizeof (struct tree_exp)
1231 : 146789689 : + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
1232 : : else
1233 : 3089877288 : return tree_code_size (code);
1234 : : }
1235 : : }
1236 : :
1237 : : /* Return tree node kind based on tree CODE. */
1238 : :
1239 : : static tree_node_kind
1240 : 0 : get_stats_node_kind (enum tree_code code)
1241 : : {
1242 : 0 : enum tree_code_class type = TREE_CODE_CLASS (code);
1243 : :
1244 : 0 : switch (type)
1245 : : {
1246 : : case tcc_declaration: /* A decl node */
1247 : : return d_kind;
1248 : 0 : case tcc_type: /* a type node */
1249 : 0 : return t_kind;
1250 : 0 : case tcc_statement: /* an expression with side effects */
1251 : 0 : return s_kind;
1252 : 0 : case tcc_reference: /* a reference */
1253 : 0 : return r_kind;
1254 : : case tcc_expression: /* an expression */
1255 : : case tcc_comparison: /* a comparison expression */
1256 : : case tcc_unary: /* a unary arithmetic expression */
1257 : : case tcc_binary: /* a binary arithmetic expression */
1258 : : return e_kind;
1259 : 0 : case tcc_constant: /* a constant */
1260 : 0 : return c_kind;
1261 : 0 : case tcc_exceptional: /* something random, like an identifier. */
1262 : 0 : switch (code)
1263 : : {
1264 : : case IDENTIFIER_NODE:
1265 : : return id_kind;
1266 : 0 : case TREE_VEC:
1267 : 0 : return vec_kind;
1268 : 0 : case TREE_BINFO:
1269 : 0 : return binfo_kind;
1270 : 0 : case SSA_NAME:
1271 : 0 : return ssa_name_kind;
1272 : 0 : case BLOCK:
1273 : 0 : return b_kind;
1274 : 0 : case CONSTRUCTOR:
1275 : 0 : return constr_kind;
1276 : 0 : case OMP_CLAUSE:
1277 : 0 : return omp_clause_kind;
1278 : 0 : default:
1279 : 0 : return x_kind;
1280 : : }
1281 : : break;
1282 : : case tcc_vl_exp:
1283 : : return e_kind;
1284 : 0 : default:
1285 : 0 : gcc_unreachable ();
1286 : : }
1287 : : }
1288 : :
1289 : : /* Record interesting allocation statistics for a tree node with CODE
1290 : : and LENGTH. */
1291 : :
1292 : : static void
1293 : 0 : record_node_allocation_statistics (enum tree_code code, size_t length)
1294 : : {
1295 : 0 : if (!GATHER_STATISTICS)
1296 : 0 : return;
1297 : :
1298 : : tree_node_kind kind = get_stats_node_kind (code);
1299 : :
1300 : : tree_code_counts[(int) code]++;
1301 : : tree_node_counts[(int) kind]++;
1302 : : tree_node_sizes[(int) kind] += length;
1303 : : }
1304 : :
1305 : : /* Allocate and return a new UID from the DECL_UID namespace. */
1306 : :
1307 : : int
1308 : 3958079758 : allocate_decl_uid (void)
1309 : : {
1310 : 3958079758 : return next_decl_uid++;
1311 : : }
1312 : :
1313 : : /* Return a newly allocated node of code CODE. For decl and type
1314 : : nodes, some other fields are initialized. The rest of the node is
1315 : : initialized to zero. This function cannot be used for TREE_VEC,
1316 : : INTEGER_CST or OMP_CLAUSE nodes, which is enforced by asserts in
1317 : : tree_code_size.
1318 : :
1319 : : Achoo! I got a code in the node. */
1320 : :
1321 : : tree
1322 : 12918759870 : make_node (enum tree_code code MEM_STAT_DECL)
1323 : : {
1324 : 12918759870 : tree t;
1325 : 12918759870 : enum tree_code_class type = TREE_CODE_CLASS (code);
1326 : 12918759870 : size_t length = tree_code_size (code);
1327 : :
1328 : 12918759870 : record_node_allocation_statistics (code, length);
1329 : :
1330 : 12918759870 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1331 : 12918759870 : TREE_SET_CODE (t, code);
1332 : :
1333 : 12918759870 : switch (type)
1334 : : {
1335 : 639576521 : case tcc_statement:
1336 : 639576521 : if (code != DEBUG_BEGIN_STMT)
1337 : 333900071 : TREE_SIDE_EFFECTS (t) = 1;
1338 : : break;
1339 : :
1340 : 2918892505 : case tcc_declaration:
1341 : 2918892505 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1342 : : {
1343 : 2918892505 : if (code == FUNCTION_DECL)
1344 : : {
1345 : 1094891146 : SET_DECL_ALIGN (t, FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY));
1346 : 1094891146 : SET_DECL_MODE (t, FUNCTION_MODE);
1347 : : }
1348 : : else
1349 : 1824001359 : SET_DECL_ALIGN (t, 1);
1350 : : }
1351 : 2918892505 : DECL_SOURCE_LOCATION (t) = input_location;
1352 : 2918892505 : if (TREE_CODE (t) == DEBUG_EXPR_DECL)
1353 : 1949332 : DECL_UID (t) = --next_debug_decl_uid;
1354 : : else
1355 : : {
1356 : 2916943173 : DECL_UID (t) = allocate_decl_uid ();
1357 : 2916943173 : SET_DECL_PT_UID (t, -1);
1358 : : }
1359 : 2918892505 : if (TREE_CODE (t) == LABEL_DECL)
1360 : 33573215 : LABEL_DECL_UID (t) = -1;
1361 : :
1362 : : break;
1363 : :
1364 : 2037770111 : case tcc_type:
1365 : 2037770111 : TYPE_UID (t) = next_type_uid++;
1366 : 2037770111 : SET_TYPE_ALIGN (t, BITS_PER_UNIT);
1367 : 2037770111 : TYPE_USER_ALIGN (t) = 0;
1368 : 2037770111 : TYPE_MAIN_VARIANT (t) = t;
1369 : 2037770111 : TYPE_CANONICAL (t) = t;
1370 : :
1371 : : /* Default to no attributes for type, but let target change that. */
1372 : 2037770111 : TYPE_ATTRIBUTES (t) = NULL_TREE;
1373 : 2037770111 : targetm.set_default_type_attributes (t);
1374 : :
1375 : : /* We have not yet computed the alias set for this type. */
1376 : 2037770111 : TYPE_ALIAS_SET (t) = -1;
1377 : 2037770111 : break;
1378 : :
1379 : 43423303 : case tcc_constant:
1380 : 43423303 : TREE_CONSTANT (t) = 1;
1381 : 43423303 : break;
1382 : :
1383 : 1086583215 : case tcc_expression:
1384 : 1086583215 : switch (code)
1385 : : {
1386 : 253061593 : case INIT_EXPR:
1387 : 253061593 : case MODIFY_EXPR:
1388 : 253061593 : case VA_ARG_EXPR:
1389 : 253061593 : case PREDECREMENT_EXPR:
1390 : 253061593 : case PREINCREMENT_EXPR:
1391 : 253061593 : case POSTDECREMENT_EXPR:
1392 : 253061593 : case POSTINCREMENT_EXPR:
1393 : : /* All of these have side-effects, no matter what their
1394 : : operands are. */
1395 : 253061593 : TREE_SIDE_EFFECTS (t) = 1;
1396 : 253061593 : break;
1397 : :
1398 : : default:
1399 : : break;
1400 : : }
1401 : : break;
1402 : :
1403 : 4958608617 : case tcc_exceptional:
1404 : 4958608617 : switch (code)
1405 : : {
1406 : 1065663 : case TARGET_OPTION_NODE:
1407 : 2131326 : TREE_TARGET_OPTION(t)
1408 : 1065663 : = ggc_cleared_alloc<struct cl_target_option> ();
1409 : 1065663 : break;
1410 : :
1411 : 604288 : case OPTIMIZATION_NODE:
1412 : 1208576 : TREE_OPTIMIZATION (t)
1413 : 604288 : = ggc_cleared_alloc<struct cl_optimization> ();
1414 : 604288 : break;
1415 : :
1416 : : default:
1417 : : break;
1418 : : }
1419 : : break;
1420 : :
1421 : : default:
1422 : : /* Other classes need no special treatment. */
1423 : : break;
1424 : : }
1425 : :
1426 : 12918759870 : return t;
1427 : : }
1428 : :
1429 : : /* Free tree node. */
1430 : :
1431 : : void
1432 : 627962646 : free_node (tree node)
1433 : : {
1434 : 627962646 : enum tree_code code = TREE_CODE (node);
1435 : 627962646 : if (GATHER_STATISTICS)
1436 : : {
1437 : : enum tree_node_kind kind = get_stats_node_kind (code);
1438 : :
1439 : : gcc_checking_assert (tree_code_counts[(int) TREE_CODE (node)] != 0);
1440 : : gcc_checking_assert (tree_node_counts[(int) kind] != 0);
1441 : : gcc_checking_assert (tree_node_sizes[(int) kind] >= tree_size (node));
1442 : :
1443 : : tree_code_counts[(int) TREE_CODE (node)]--;
1444 : : tree_node_counts[(int) kind]--;
1445 : : tree_node_sizes[(int) kind] -= tree_size (node);
1446 : : }
1447 : 627962646 : if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1448 : 349 : vec_free (CONSTRUCTOR_ELTS (node));
1449 : 627962453 : else if (code == BLOCK)
1450 : 0 : vec_free (BLOCK_NONLOCALIZED_VARS (node));
1451 : 627962453 : else if (code == TREE_BINFO)
1452 : 363 : vec_free (BINFO_BASE_ACCESSES (node));
1453 : 627962090 : else if (code == OPTIMIZATION_NODE)
1454 : 813 : cl_optimization_option_free (TREE_OPTIMIZATION (node));
1455 : 627961277 : else if (code == TARGET_OPTION_NODE)
1456 : 878 : cl_target_option_free (TREE_TARGET_OPTION (node));
1457 : 627962646 : ggc_free (node);
1458 : 627962646 : }
1459 : :
1460 : : /* Return a new node with the same contents as NODE except that its
1461 : : TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
1462 : :
1463 : : tree
1464 : 3525094323 : copy_node (tree node MEM_STAT_DECL)
1465 : : {
1466 : 3525094323 : tree t;
1467 : 3525094323 : enum tree_code code = TREE_CODE (node);
1468 : 3525094323 : size_t length;
1469 : :
1470 : 3525094323 : gcc_assert (code != STATEMENT_LIST);
1471 : :
1472 : 3525094323 : length = tree_size (node);
1473 : 3525094323 : record_node_allocation_statistics (code, length);
1474 : 3525094323 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
1475 : 3525094323 : memcpy (t, node, length);
1476 : :
1477 : 3525094323 : if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
1478 : 2158873183 : TREE_CHAIN (t) = 0;
1479 : 3525094323 : TREE_ASM_WRITTEN (t) = 0;
1480 : 3525094323 : TREE_VISITED (t) = 0;
1481 : :
1482 : 3525094323 : if (TREE_CODE_CLASS (code) == tcc_declaration)
1483 : : {
1484 : 1040162291 : if (code == DEBUG_EXPR_DECL)
1485 : 0 : DECL_UID (t) = --next_debug_decl_uid;
1486 : : else
1487 : : {
1488 : 1040162291 : DECL_UID (t) = allocate_decl_uid ();
1489 : 1040162291 : if (DECL_PT_UID_SET_P (node))
1490 : 3482 : SET_DECL_PT_UID (t, DECL_PT_UID (node));
1491 : : }
1492 : 513382584 : if ((TREE_CODE (node) == PARM_DECL || VAR_P (node))
1493 : 1101719576 : && DECL_HAS_VALUE_EXPR_P (node))
1494 : : {
1495 : 921315 : SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
1496 : 921315 : DECL_HAS_VALUE_EXPR_P (t) = 1;
1497 : : }
1498 : : /* DECL_DEBUG_EXPR is copied explicitly by callers. */
1499 : 1040162291 : if (VAR_P (node))
1500 : : {
1501 : 61557285 : DECL_HAS_DEBUG_EXPR_P (t) = 0;
1502 : 61557285 : t->decl_with_vis.symtab_node = NULL;
1503 : : }
1504 : 1040162291 : if (VAR_P (node) && DECL_HAS_INIT_PRIORITY_P (node))
1505 : : {
1506 : 0 : SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
1507 : 0 : DECL_HAS_INIT_PRIORITY_P (t) = 1;
1508 : : }
1509 : 1040162291 : if (TREE_CODE (node) == FUNCTION_DECL)
1510 : : {
1511 : 261163643 : DECL_STRUCT_FUNCTION (t) = NULL;
1512 : 261163643 : t->decl_with_vis.symtab_node = NULL;
1513 : : }
1514 : : }
1515 : 2484932032 : else if (TREE_CODE_CLASS (code) == tcc_type)
1516 : : {
1517 : 705732127 : TYPE_UID (t) = next_type_uid++;
1518 : : /* The following is so that the debug code for
1519 : : the copy is different from the original type.
1520 : : The two statements usually duplicate each other
1521 : : (because they clear fields of the same union),
1522 : : but the optimizer should catch that. */
1523 : 705732127 : TYPE_SYMTAB_ADDRESS (t) = 0;
1524 : 705732127 : TYPE_SYMTAB_DIE (t) = 0;
1525 : :
1526 : : /* Do not copy the values cache. */
1527 : 705732127 : if (TYPE_CACHED_VALUES_P (t))
1528 : : {
1529 : 17550304 : TYPE_CACHED_VALUES_P (t) = 0;
1530 : 17550304 : TYPE_CACHED_VALUES (t) = NULL_TREE;
1531 : : }
1532 : : }
1533 : 1779199905 : else if (code == TARGET_OPTION_NODE)
1534 : : {
1535 : 0 : TREE_TARGET_OPTION (t) = ggc_alloc<struct cl_target_option>();
1536 : 0 : memcpy (TREE_TARGET_OPTION (t), TREE_TARGET_OPTION (node),
1537 : : sizeof (struct cl_target_option));
1538 : : }
1539 : 1779199905 : else if (code == OPTIMIZATION_NODE)
1540 : : {
1541 : 0 : TREE_OPTIMIZATION (t) = ggc_alloc<struct cl_optimization>();
1542 : 0 : memcpy (TREE_OPTIMIZATION (t), TREE_OPTIMIZATION (node),
1543 : : sizeof (struct cl_optimization));
1544 : : }
1545 : :
1546 : 3525094323 : return t;
1547 : : }
1548 : :
1549 : : /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1550 : : For example, this can copy a list made of TREE_LIST nodes. */
1551 : :
1552 : : tree
1553 : 137432955 : copy_list (tree list)
1554 : : {
1555 : 137432955 : tree head;
1556 : 137432955 : tree prev, next;
1557 : :
1558 : 137432955 : if (list == 0)
1559 : : return 0;
1560 : :
1561 : 132421729 : head = prev = copy_node (list);
1562 : 132421729 : next = TREE_CHAIN (list);
1563 : 262353119 : while (next)
1564 : : {
1565 : 129931390 : TREE_CHAIN (prev) = copy_node (next);
1566 : 129931390 : prev = TREE_CHAIN (prev);
1567 : 129931390 : next = TREE_CHAIN (next);
1568 : : }
1569 : : return head;
1570 : : }
1571 : :
1572 : :
1573 : : /* Return the value that TREE_INT_CST_EXT_NUNITS should have for an
1574 : : INTEGER_CST with value CST and type TYPE. */
1575 : :
1576 : : static unsigned int
1577 : 9133550064 : get_int_cst_ext_nunits (tree type, const wide_int &cst)
1578 : : {
1579 : 9133550064 : gcc_checking_assert (cst.get_precision () == TYPE_PRECISION (type));
1580 : : /* We need extra HWIs if CST is an unsigned integer with its
1581 : : upper bit set. */
1582 : 9133550064 : if (TYPE_UNSIGNED (type) && wi::neg_p (cst))
1583 : 168442464 : return cst.get_precision () / HOST_BITS_PER_WIDE_INT + 1;
1584 : 8965107600 : return cst.get_len ();
1585 : : }
1586 : :
1587 : : /* Return a new INTEGER_CST with value CST and type TYPE. */
1588 : :
1589 : : static tree
1590 : 123655595 : build_new_int_cst (tree type, const wide_int &cst)
1591 : : {
1592 : 123655595 : unsigned int len = cst.get_len ();
1593 : 123655595 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1594 : 123655595 : tree nt = make_int_cst (len, ext_len);
1595 : :
1596 : 123655595 : if (len < ext_len)
1597 : : {
1598 : 61422821 : --ext_len;
1599 : 122845642 : TREE_INT_CST_ELT (nt, ext_len)
1600 : 61422821 : = zext_hwi (-1, cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1601 : 80587347 : for (unsigned int i = len; i < ext_len; ++i)
1602 : 19164526 : TREE_INT_CST_ELT (nt, i) = -1;
1603 : : }
1604 : 62232774 : else if (TYPE_UNSIGNED (type)
1605 : 62232774 : && cst.get_precision () < len * HOST_BITS_PER_WIDE_INT)
1606 : : {
1607 : 12790422 : len--;
1608 : 25580844 : TREE_INT_CST_ELT (nt, len)
1609 : 12790422 : = zext_hwi (cst.elt (len),
1610 : 12790422 : cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1611 : : }
1612 : :
1613 : 256324705 : for (unsigned int i = 0; i < len; i++)
1614 : 132669110 : TREE_INT_CST_ELT (nt, i) = cst.elt (i);
1615 : 123655595 : TREE_TYPE (nt) = type;
1616 : 123655595 : return nt;
1617 : : }
1618 : :
1619 : : /* Return a new POLY_INT_CST with coefficients COEFFS and type TYPE. */
1620 : :
1621 : : static tree
1622 : 0 : build_new_poly_int_cst (tree type, tree (&coeffs)[NUM_POLY_INT_COEFFS]
1623 : : CXX_MEM_STAT_INFO)
1624 : : {
1625 : 0 : size_t length = sizeof (struct tree_poly_int_cst);
1626 : 0 : record_node_allocation_statistics (POLY_INT_CST, length);
1627 : :
1628 : 0 : tree t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1629 : :
1630 : 0 : TREE_SET_CODE (t, POLY_INT_CST);
1631 : 0 : TREE_CONSTANT (t) = 1;
1632 : 0 : TREE_TYPE (t) = type;
1633 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1634 : 0 : POLY_INT_CST_COEFF (t, i) = coeffs[i];
1635 : 0 : return t;
1636 : : }
1637 : :
1638 : : /* Create a constant tree that contains CST sign-extended to TYPE. */
1639 : :
1640 : : tree
1641 : 6094902679 : build_int_cst (tree type, poly_int64 cst)
1642 : : {
1643 : : /* Support legacy code. */
1644 : 6094902679 : if (!type)
1645 : 1992554550 : type = integer_type_node;
1646 : :
1647 : 6094902679 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1648 : : }
1649 : :
1650 : : /* Create a constant tree that contains CST zero-extended to TYPE. */
1651 : :
1652 : : tree
1653 : 9471489 : build_int_cstu (tree type, poly_uint64 cst)
1654 : : {
1655 : 9471489 : return wide_int_to_tree (type, wi::uhwi (cst, TYPE_PRECISION (type)));
1656 : : }
1657 : :
1658 : : /* Create a constant tree that contains CST sign-extended to TYPE. */
1659 : :
1660 : : tree
1661 : 25255325 : build_int_cst_type (tree type, poly_int64 cst)
1662 : : {
1663 : 25255325 : gcc_assert (type);
1664 : 25255325 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1665 : : }
1666 : :
1667 : : /* Constructs tree in type TYPE from with value given by CST. Signedness
1668 : : of CST is assumed to be the same as the signedness of TYPE. */
1669 : :
1670 : : tree
1671 : 7287762 : double_int_to_tree (tree type, double_int cst)
1672 : : {
1673 : 7287762 : return wide_int_to_tree (type, widest_int::from (cst, TYPE_SIGN (type)));
1674 : : }
1675 : :
1676 : : /* We force the wide_int CST to the range of the type TYPE by sign or
1677 : : zero extending it. OVERFLOWABLE indicates if we are interested in
1678 : : overflow of the value, when >0 we are only interested in signed
1679 : : overflow, for <0 we are interested in any overflow. OVERFLOWED
1680 : : indicates whether overflow has already occurred. CONST_OVERFLOWED
1681 : : indicates whether constant overflow has already occurred. We force
1682 : : T's value to be within range of T's type (by setting to 0 or 1 all
1683 : : the bits outside the type's range). We set TREE_OVERFLOWED if,
1684 : : OVERFLOWED is nonzero,
1685 : : or OVERFLOWABLE is >0 and signed overflow occurs
1686 : : or OVERFLOWABLE is <0 and any overflow occurs
1687 : : We return a new tree node for the extended wide_int. The node
1688 : : is shared if no overflow flags are set. */
1689 : :
1690 : :
1691 : : tree
1692 : 2358230075 : force_fit_type (tree type, const poly_wide_int_ref &cst,
1693 : : int overflowable, bool overflowed)
1694 : : {
1695 : 2358230075 : signop sign = TYPE_SIGN (type);
1696 : :
1697 : : /* If we need to set overflow flags, return a new unshared node. */
1698 : 2358230075 : if (overflowed || !wi::fits_to_tree_p (cst, type))
1699 : : {
1700 : 6622368 : if (overflowed
1701 : 6622368 : || overflowable < 0
1702 : 5387105 : || (overflowable > 0 && sign == SIGNED))
1703 : : {
1704 : 1293202 : poly_wide_int tmp = poly_wide_int::from (cst, TYPE_PRECISION (type),
1705 : 1293202 : sign);
1706 : 1293202 : tree t;
1707 : 1293202 : if (tmp.is_constant ())
1708 : 1293202 : t = build_new_int_cst (type, tmp.coeffs[0]);
1709 : : else
1710 : : {
1711 : : tree coeffs[NUM_POLY_INT_COEFFS];
1712 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1713 : : {
1714 : : coeffs[i] = build_new_int_cst (type, tmp.coeffs[i]);
1715 : : TREE_OVERFLOW (coeffs[i]) = 1;
1716 : : }
1717 : : t = build_new_poly_int_cst (type, coeffs);
1718 : : }
1719 : 1293202 : TREE_OVERFLOW (t) = 1;
1720 : 1293202 : return t;
1721 : 1293202 : }
1722 : : }
1723 : :
1724 : : /* Else build a shared node. */
1725 : 2356936873 : return wide_int_to_tree (type, cst);
1726 : : }
1727 : :
1728 : : /* These are the hash table functions for the hash table of INTEGER_CST
1729 : : nodes of a sizetype. */
1730 : :
1731 : : /* Return the hash code X, an INTEGER_CST. */
1732 : :
1733 : : hashval_t
1734 : 1707032137 : int_cst_hasher::hash (tree x)
1735 : : {
1736 : 1707032137 : const_tree const t = x;
1737 : 1707032137 : hashval_t code = TYPE_UID (TREE_TYPE (t));
1738 : 1707032137 : int i;
1739 : :
1740 : 3474244796 : for (i = 0; i < TREE_INT_CST_NUNITS (t); i++)
1741 : 1767212659 : code = iterative_hash_host_wide_int (TREE_INT_CST_ELT(t, i), code);
1742 : :
1743 : 1707032137 : return code;
1744 : : }
1745 : :
1746 : : /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1747 : : is the same as that given by *Y, which is the same. */
1748 : :
1749 : : bool
1750 : 1714227914 : int_cst_hasher::equal (tree x, tree y)
1751 : : {
1752 : 1714227914 : const_tree const xt = x;
1753 : 1714227914 : const_tree const yt = y;
1754 : :
1755 : 1714227914 : if (TREE_TYPE (xt) != TREE_TYPE (yt)
1756 : 594570619 : || TREE_INT_CST_NUNITS (xt) != TREE_INT_CST_NUNITS (yt)
1757 : 2308744366 : || TREE_INT_CST_EXT_NUNITS (xt) != TREE_INT_CST_EXT_NUNITS (yt))
1758 : : return false;
1759 : :
1760 : 880535994 : for (int i = 0; i < TREE_INT_CST_NUNITS (xt); i++)
1761 : 567018506 : if (TREE_INT_CST_ELT (xt, i) != TREE_INT_CST_ELT (yt, i))
1762 : : return false;
1763 : :
1764 : : return true;
1765 : : }
1766 : :
1767 : : /* Cache wide_int CST into the TYPE_CACHED_VALUES cache for TYPE.
1768 : : SLOT is the slot entry to store it in, and MAX_SLOTS is the maximum
1769 : : number of slots that can be cached for the type. */
1770 : :
1771 : : static inline tree
1772 : 8621388535 : cache_wide_int_in_type_cache (tree type, const wide_int &cst,
1773 : : int slot, int max_slots)
1774 : : {
1775 : 8621388535 : gcc_checking_assert (slot >= 0);
1776 : : /* Initialize cache. */
1777 : 8621388535 : if (!TYPE_CACHED_VALUES_P (type))
1778 : : {
1779 : 17608525 : TYPE_CACHED_VALUES_P (type) = 1;
1780 : 17608525 : TYPE_CACHED_VALUES (type) = make_tree_vec (max_slots);
1781 : : }
1782 : 8621388535 : tree t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot);
1783 : 8621388535 : if (!t)
1784 : : {
1785 : : /* Create a new shared int. */
1786 : 55844321 : t = build_new_int_cst (type, cst);
1787 : 55844321 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot) = t;
1788 : : }
1789 : 8621388535 : return t;
1790 : : }
1791 : :
1792 : : /* Create an INT_CST node of TYPE and value CST.
1793 : : The returned node is always shared. For small integers we use a
1794 : : per-type vector cache, for larger ones we use a single hash table.
1795 : : The value is extended from its precision according to the sign of
1796 : : the type to be a multiple of HOST_BITS_PER_WIDE_INT. This defines
1797 : : the upper bits and ensures that hashing and value equality based
1798 : : upon the underlying HOST_WIDE_INTs works without masking. */
1799 : :
1800 : : static tree
1801 : 9009894469 : wide_int_to_tree_1 (tree type, const wide_int_ref &pcst)
1802 : : {
1803 : 9009894469 : tree t;
1804 : 9009894469 : int ix = -1;
1805 : 9009894469 : int limit = 0;
1806 : :
1807 : 9009894469 : gcc_assert (type);
1808 : 9009894469 : unsigned int prec = TYPE_PRECISION (type);
1809 : 9009894469 : signop sgn = TYPE_SIGN (type);
1810 : :
1811 : : /* Verify that everything is canonical. */
1812 : 9009894469 : int l = pcst.get_len ();
1813 : 9009894469 : if (l > 1)
1814 : : {
1815 : 6765470 : if (pcst.elt (l - 1) == 0)
1816 : 1101854 : gcc_checking_assert (pcst.elt (l - 2) < 0);
1817 : 6765470 : if (pcst.elt (l - 1) == HOST_WIDE_INT_M1)
1818 : 11864 : gcc_checking_assert (pcst.elt (l - 2) >= 0);
1819 : : }
1820 : :
1821 : 9009894469 : wide_int cst = wide_int::from (pcst, prec, sgn);
1822 : 9009894469 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1823 : :
1824 : 9009894469 : enum tree_code code = TREE_CODE (type);
1825 : 9009894469 : if (code == POINTER_TYPE || code == REFERENCE_TYPE)
1826 : : {
1827 : : /* Cache NULL pointer and zero bounds. */
1828 : 169643243 : if (cst == 0)
1829 : : ix = 0;
1830 : : /* Cache upper bounds of pointers. */
1831 : 33131481 : else if (cst == wi::max_value (prec, sgn))
1832 : : ix = 1;
1833 : : /* Cache 1 which is used for a non-zero range. */
1834 : 31041421 : else if (cst == 1)
1835 : : ix = 2;
1836 : :
1837 : : if (ix >= 0)
1838 : : {
1839 : 142634752 : t = cache_wide_int_in_type_cache (type, cst, ix, 3);
1840 : : /* Make sure no one is clobbering the shared constant. */
1841 : 142634752 : gcc_checking_assert (TREE_TYPE (t) == type
1842 : : && cst == wi::to_wide (t));
1843 : 142634752 : return t;
1844 : : }
1845 : : }
1846 : 8867259717 : if (ext_len == 1)
1847 : : {
1848 : : /* We just need to store a single HOST_WIDE_INT. */
1849 : 8800741645 : HOST_WIDE_INT hwi;
1850 : 8800741645 : if (TYPE_UNSIGNED (type))
1851 : 5976897143 : hwi = cst.to_uhwi ();
1852 : : else
1853 : 2823844880 : hwi = cst.to_shwi ();
1854 : :
1855 : 8800741645 : switch (code)
1856 : : {
1857 : 209616 : case NULLPTR_TYPE:
1858 : 209616 : gcc_assert (hwi == 0);
1859 : : /* Fallthru. */
1860 : :
1861 : : case POINTER_TYPE:
1862 : : case REFERENCE_TYPE:
1863 : : /* Ignore pointers, as they were already handled above. */
1864 : : break;
1865 : :
1866 : 109735045 : case BOOLEAN_TYPE:
1867 : : /* Cache false or true. */
1868 : 109735045 : limit = 2;
1869 : 109735045 : if (IN_RANGE (hwi, 0, 1))
1870 : 109562183 : ix = hwi;
1871 : : break;
1872 : :
1873 : 8659933729 : case INTEGER_TYPE:
1874 : 8659933729 : case OFFSET_TYPE:
1875 : 8659933729 : case BITINT_TYPE:
1876 : 8659933729 : if (TYPE_SIGN (type) == UNSIGNED)
1877 : : {
1878 : : /* Cache [0, N). */
1879 : 5839457524 : limit = param_integer_share_limit;
1880 : 5839457524 : if (IN_RANGE (hwi, 0, param_integer_share_limit - 1))
1881 : 5654841800 : ix = hwi;
1882 : : }
1883 : : else
1884 : : {
1885 : : /* Cache [-1, N). */
1886 : 2820476205 : limit = param_integer_share_limit + 1;
1887 : 2820476205 : if (IN_RANGE (hwi, -1, param_integer_share_limit - 1))
1888 : 2714349800 : ix = hwi + 1;
1889 : : }
1890 : : break;
1891 : :
1892 : : case ENUMERAL_TYPE:
1893 : : break;
1894 : :
1895 : 0 : default:
1896 : 0 : gcc_unreachable ();
1897 : : }
1898 : :
1899 : 8800741645 : if (ix >= 0)
1900 : : {
1901 : 8478753783 : t = cache_wide_int_in_type_cache (type, cst, ix, limit);
1902 : : /* Make sure no one is clobbering the shared constant. */
1903 : 16957507566 : gcc_checking_assert (TREE_TYPE (t) == type
1904 : : && TREE_INT_CST_NUNITS (t) == 1
1905 : : && TREE_INT_CST_EXT_NUNITS (t) == 1
1906 : : && TREE_INT_CST_ELT (t, 0) == hwi);
1907 : : return t;
1908 : : }
1909 : : else
1910 : : {
1911 : : /* Use the cache of larger shared ints, using int_cst_node as
1912 : : a temporary. */
1913 : :
1914 : 321987862 : TREE_INT_CST_ELT (int_cst_node, 0) = hwi;
1915 : 321987862 : TREE_TYPE (int_cst_node) = type;
1916 : :
1917 : 321987862 : tree *slot = int_cst_hash_table->find_slot (int_cst_node, INSERT);
1918 : 321987862 : t = *slot;
1919 : 321987862 : if (!t)
1920 : : {
1921 : : /* Insert this one into the hash table. */
1922 : 65009853 : t = int_cst_node;
1923 : 65009853 : *slot = t;
1924 : : /* Make a new node for next time round. */
1925 : 65009853 : int_cst_node = make_int_cst (1, 1);
1926 : : }
1927 : : }
1928 : : }
1929 : : else
1930 : : {
1931 : : /* The value either hashes properly or we drop it on the floor
1932 : : for the gc to take care of. There will not be enough of them
1933 : : to worry about. */
1934 : :
1935 : 66518072 : tree nt = build_new_int_cst (type, cst);
1936 : 66518072 : tree *slot = int_cst_hash_table->find_slot (nt, INSERT);
1937 : 66518072 : t = *slot;
1938 : 66518072 : if (!t)
1939 : : {
1940 : : /* Insert this one into the hash table. */
1941 : 13632788 : t = nt;
1942 : 13632788 : *slot = t;
1943 : : }
1944 : : else
1945 : 52885284 : ggc_free (nt);
1946 : : }
1947 : :
1948 : : return t;
1949 : 9009894469 : }
1950 : :
1951 : : hashval_t
1952 : 0 : poly_int_cst_hasher::hash (tree t)
1953 : : {
1954 : 0 : inchash::hash hstate;
1955 : :
1956 : 0 : hstate.add_int (TYPE_UID (TREE_TYPE (t)));
1957 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1958 : 0 : hstate.add_wide_int (wi::to_wide (POLY_INT_CST_COEFF (t, i)));
1959 : :
1960 : 0 : return hstate.end ();
1961 : : }
1962 : :
1963 : : bool
1964 : 0 : poly_int_cst_hasher::equal (tree x, const compare_type &y)
1965 : : {
1966 : 0 : if (TREE_TYPE (x) != y.first)
1967 : : return false;
1968 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1969 : 0 : if (wi::to_wide (POLY_INT_CST_COEFF (x, i)) != y.second->coeffs[i])
1970 : : return false;
1971 : : return true;
1972 : : }
1973 : :
1974 : : /* Build a POLY_INT_CST node with type TYPE and with the elements in VALUES.
1975 : : The elements must also have type TYPE. */
1976 : :
1977 : : tree
1978 : 0 : build_poly_int_cst (tree type, const poly_wide_int_ref &values)
1979 : : {
1980 : 0 : unsigned int prec = TYPE_PRECISION (type);
1981 : 0 : gcc_assert (prec <= values.coeffs[0].get_precision ());
1982 : 0 : poly_wide_int c = poly_wide_int::from (values, prec, SIGNED);
1983 : :
1984 : 0 : inchash::hash h;
1985 : 0 : h.add_int (TYPE_UID (type));
1986 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1987 : 0 : h.add_wide_int (c.coeffs[i]);
1988 : 0 : poly_int_cst_hasher::compare_type comp (type, &c);
1989 : 0 : tree *slot = poly_int_cst_hash_table->find_slot_with_hash (comp, h.end (),
1990 : : INSERT);
1991 : 0 : if (*slot == NULL_TREE)
1992 : : {
1993 : : tree coeffs[NUM_POLY_INT_COEFFS];
1994 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1995 : 0 : coeffs[i] = wide_int_to_tree_1 (type, c.coeffs[i]);
1996 : 0 : *slot = build_new_poly_int_cst (type, coeffs);
1997 : : }
1998 : 0 : return *slot;
1999 : 0 : }
2000 : :
2001 : : /* Create a constant tree with value VALUE in type TYPE. */
2002 : :
2003 : : tree
2004 : 9009894469 : wide_int_to_tree (tree type, const poly_wide_int_ref &value)
2005 : : {
2006 : 9009894469 : if (value.is_constant ())
2007 : 9009894469 : return wide_int_to_tree_1 (type, value.coeffs[0]);
2008 : : return build_poly_int_cst (type, value);
2009 : : }
2010 : :
2011 : : /* Insert INTEGER_CST T into a cache of integer constants. And return
2012 : : the cached constant (which may or may not be T). If MIGHT_DUPLICATE
2013 : : is false, and T falls into the type's 'smaller values' range, there
2014 : : cannot be an existing entry. Otherwise, if MIGHT_DUPLICATE is true,
2015 : : or the value is large, should an existing entry exist, it is
2016 : : returned (rather than inserting T). */
2017 : :
2018 : : tree
2019 : 504412 : cache_integer_cst (tree t, bool might_duplicate ATTRIBUTE_UNUSED)
2020 : : {
2021 : 504412 : tree type = TREE_TYPE (t);
2022 : 504412 : int ix = -1;
2023 : 504412 : int limit = 0;
2024 : 504412 : int prec = TYPE_PRECISION (type);
2025 : :
2026 : 504412 : gcc_assert (!TREE_OVERFLOW (t));
2027 : :
2028 : : /* The caching indices here must match those in
2029 : : wide_int_to_type_1. */
2030 : 504412 : switch (TREE_CODE (type))
2031 : : {
2032 : 0 : case NULLPTR_TYPE:
2033 : 0 : gcc_checking_assert (integer_zerop (t));
2034 : : /* Fallthru. */
2035 : :
2036 : 3191 : case POINTER_TYPE:
2037 : 3191 : case REFERENCE_TYPE:
2038 : 3191 : {
2039 : 3191 : if (integer_zerop (t))
2040 : : ix = 0;
2041 : 1349 : else if (integer_onep (t))
2042 : : ix = 2;
2043 : :
2044 : : if (ix >= 0)
2045 : : limit = 3;
2046 : : }
2047 : : break;
2048 : :
2049 : 10176 : case BOOLEAN_TYPE:
2050 : : /* Cache false or true. */
2051 : 10176 : limit = 2;
2052 : 10176 : if (wi::ltu_p (wi::to_wide (t), 2))
2053 : 0 : ix = TREE_INT_CST_ELT (t, 0);
2054 : : break;
2055 : :
2056 : 479170 : case INTEGER_TYPE:
2057 : 479170 : case OFFSET_TYPE:
2058 : 479170 : case BITINT_TYPE:
2059 : 479170 : if (TYPE_UNSIGNED (type))
2060 : : {
2061 : : /* Cache 0..N */
2062 : 358463 : limit = param_integer_share_limit;
2063 : :
2064 : : /* This is a little hokie, but if the prec is smaller than
2065 : : what is necessary to hold param_integer_share_limit, then the
2066 : : obvious test will not get the correct answer. */
2067 : 358463 : if (prec < HOST_BITS_PER_WIDE_INT)
2068 : : {
2069 : 76561 : if (tree_to_uhwi (t)
2070 : 76561 : < (unsigned HOST_WIDE_INT) param_integer_share_limit)
2071 : 11046 : ix = tree_to_uhwi (t);
2072 : : }
2073 : 281902 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2074 : 217472 : ix = tree_to_uhwi (t);
2075 : : }
2076 : : else
2077 : : {
2078 : : /* Cache -1..N */
2079 : 120707 : limit = param_integer_share_limit + 1;
2080 : :
2081 : 120707 : if (integer_minus_onep (t))
2082 : : ix = 0;
2083 : 120332 : else if (!wi::neg_p (wi::to_wide (t)))
2084 : : {
2085 : 105230 : if (prec < HOST_BITS_PER_WIDE_INT)
2086 : : {
2087 : 100714 : if (tree_to_shwi (t) < param_integer_share_limit)
2088 : 93018 : ix = tree_to_shwi (t) + 1;
2089 : : }
2090 : 4516 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2091 : 3669 : ix = tree_to_shwi (t) + 1;
2092 : : }
2093 : : }
2094 : : break;
2095 : :
2096 : : case ENUMERAL_TYPE:
2097 : : /* The slot used by TYPE_CACHED_VALUES is used for the enum
2098 : : members. */
2099 : : break;
2100 : :
2101 : 0 : default:
2102 : 0 : gcc_unreachable ();
2103 : : }
2104 : :
2105 : 327047 : if (ix >= 0)
2106 : : {
2107 : : /* Look for it in the type's vector of small shared ints. */
2108 : 327718 : if (!TYPE_CACHED_VALUES_P (type))
2109 : : {
2110 : 12623 : TYPE_CACHED_VALUES_P (type) = 1;
2111 : 12623 : TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
2112 : : }
2113 : :
2114 : 327718 : if (tree r = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix))
2115 : : {
2116 : 306265 : gcc_checking_assert (might_duplicate);
2117 : 306265 : t = r;
2118 : : }
2119 : : else
2120 : 21453 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
2121 : : }
2122 : : else
2123 : : {
2124 : : /* Use the cache of larger shared ints. */
2125 : 176694 : tree *slot = int_cst_hash_table->find_slot (t, INSERT);
2126 : 176694 : if (tree r = *slot)
2127 : : {
2128 : : /* If there is already an entry for the number verify it's the
2129 : : same value. */
2130 : 105895 : gcc_checking_assert (wi::to_wide (tree (r)) == wi::to_wide (t));
2131 : : /* And return the cached value. */
2132 : 105895 : t = r;
2133 : : }
2134 : : else
2135 : : /* Otherwise insert this one into the hash table. */
2136 : 70799 : *slot = t;
2137 : : }
2138 : :
2139 : 504412 : return t;
2140 : : }
2141 : :
2142 : :
2143 : : /* Builds an integer constant in TYPE such that lowest BITS bits are ones
2144 : : and the rest are zeros. */
2145 : :
2146 : : tree
2147 : 9243198 : build_low_bits_mask (tree type, unsigned bits)
2148 : : {
2149 : 9243198 : gcc_assert (bits <= TYPE_PRECISION (type));
2150 : :
2151 : 9243198 : return wide_int_to_tree (type, wi::mask (bits, false,
2152 : 9243198 : TYPE_PRECISION (type)));
2153 : : }
2154 : :
2155 : : /* Checks that X is integer constant that can be expressed in (unsigned)
2156 : : HOST_WIDE_INT without loss of precision. */
2157 : :
2158 : : bool
2159 : 617790610 : cst_and_fits_in_hwi (const_tree x)
2160 : : {
2161 : 617790610 : return (TREE_CODE (x) == INTEGER_CST
2162 : 617790610 : && (tree_fits_shwi_p (x) || tree_fits_uhwi_p (x)));
2163 : : }
2164 : :
2165 : : /* Build a newly constructed VECTOR_CST with the given values of
2166 : : (VECTOR_CST_)LOG2_NPATTERNS and (VECTOR_CST_)NELTS_PER_PATTERN. */
2167 : :
2168 : : tree
2169 : 3214758 : make_vector (unsigned log2_npatterns,
2170 : : unsigned int nelts_per_pattern MEM_STAT_DECL)
2171 : : {
2172 : 3214758 : gcc_assert (IN_RANGE (nelts_per_pattern, 1, 3));
2173 : 3214758 : tree t;
2174 : 3214758 : unsigned npatterns = 1 << log2_npatterns;
2175 : 3214758 : unsigned encoded_nelts = npatterns * nelts_per_pattern;
2176 : 3214758 : unsigned length = (sizeof (struct tree_vector)
2177 : : + (encoded_nelts - 1) * sizeof (tree));
2178 : :
2179 : 3214758 : record_node_allocation_statistics (VECTOR_CST, length);
2180 : :
2181 : 3214758 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2182 : :
2183 : 3214758 : TREE_SET_CODE (t, VECTOR_CST);
2184 : 3214758 : TREE_CONSTANT (t) = 1;
2185 : 3214758 : VECTOR_CST_LOG2_NPATTERNS (t) = log2_npatterns;
2186 : 3214758 : VECTOR_CST_NELTS_PER_PATTERN (t) = nelts_per_pattern;
2187 : :
2188 : 3214758 : return t;
2189 : : }
2190 : :
2191 : : /* Return a new VECTOR_CST node whose type is TYPE and whose values
2192 : : are extracted from V, a vector of CONSTRUCTOR_ELT. */
2193 : :
2194 : : tree
2195 : 656434 : build_vector_from_ctor (tree type, const vec<constructor_elt, va_gc> *v)
2196 : : {
2197 : 656434 : if (vec_safe_length (v) == 0)
2198 : 685 : return build_zero_cst (type);
2199 : :
2200 : 655749 : unsigned HOST_WIDE_INT idx, nelts, step = 1;
2201 : 655749 : tree value;
2202 : :
2203 : : /* If the vector is a VLA, build a VLA constant vector. */
2204 : 655749 : if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&nelts))
2205 : : {
2206 : : nelts = constant_lower_bound (TYPE_VECTOR_SUBPARTS (type));
2207 : : gcc_assert (vec_safe_length (v) <= nelts);
2208 : : step = 2;
2209 : : }
2210 : :
2211 : 655749 : tree_vector_builder vec (type, nelts, step);
2212 : 4360767 : FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
2213 : : {
2214 : 3705018 : if (TREE_CODE (value) == VECTOR_CST)
2215 : : {
2216 : : /* If NELTS is constant then this must be too. */
2217 : 366 : unsigned int sub_nelts = VECTOR_CST_NELTS (value).to_constant ();
2218 : 1418 : for (unsigned i = 0; i < sub_nelts; ++i)
2219 : 1052 : vec.quick_push (VECTOR_CST_ELT (value, i));
2220 : : }
2221 : : else
2222 : 3704652 : vec.quick_push (value);
2223 : : }
2224 : 1853642 : while (vec.length () < nelts * step)
2225 : 271072 : vec.quick_push (build_zero_cst (TREE_TYPE (type)));
2226 : :
2227 : 655749 : return vec.build ();
2228 : 655749 : }
2229 : :
2230 : : /* Build a vector of type VECTYPE where all the elements are SCs. */
2231 : : tree
2232 : 627403 : build_vector_from_val (tree vectype, tree sc)
2233 : : {
2234 : 627403 : unsigned HOST_WIDE_INT i, nunits;
2235 : :
2236 : 627403 : if (sc == error_mark_node)
2237 : : return sc;
2238 : :
2239 : : /* Verify that the vector type is suitable for SC. Note that there
2240 : : is some inconsistency in the type-system with respect to restrict
2241 : : qualifications of pointers. Vector types always have a main-variant
2242 : : element type and the qualification is applied to the vector-type.
2243 : : So TREE_TYPE (vector-type) does not return a properly qualified
2244 : : vector element-type. */
2245 : 627403 : gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
2246 : : TREE_TYPE (vectype)));
2247 : :
2248 : 627403 : if (CONSTANT_CLASS_P (sc))
2249 : : {
2250 : 598270 : tree_vector_builder v (vectype, 1, 1);
2251 : 598270 : v.quick_push (sc);
2252 : 598270 : return v.build ();
2253 : 598270 : }
2254 : 29133 : else if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
2255 : : return fold_build1 (VEC_DUPLICATE_EXPR, vectype, sc);
2256 : : else
2257 : : {
2258 : 29133 : vec<constructor_elt, va_gc> *v;
2259 : 29133 : vec_alloc (v, nunits);
2260 : 135505 : for (i = 0; i < nunits; ++i)
2261 : 106372 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
2262 : 29133 : return build_constructor (vectype, v);
2263 : : }
2264 : : }
2265 : :
2266 : : /* If TYPE is not a vector type, just return SC, otherwise return
2267 : : build_vector_from_val (TYPE, SC). */
2268 : :
2269 : : tree
2270 : 5108281 : build_uniform_cst (tree type, tree sc)
2271 : : {
2272 : 5108281 : if (!VECTOR_TYPE_P (type))
2273 : : return sc;
2274 : :
2275 : 249 : return build_vector_from_val (type, sc);
2276 : : }
2277 : :
2278 : : /* Build a vector series of type TYPE in which element I has the value
2279 : : BASE + I * STEP. The result is a constant if BASE and STEP are constant
2280 : : and a VEC_SERIES_EXPR otherwise. */
2281 : :
2282 : : tree
2283 : 18 : build_vec_series (tree type, tree base, tree step)
2284 : : {
2285 : 18 : if (integer_zerop (step))
2286 : 0 : return build_vector_from_val (type, base);
2287 : 18 : if (TREE_CODE (base) == INTEGER_CST && TREE_CODE (step) == INTEGER_CST)
2288 : : {
2289 : 18 : tree_vector_builder builder (type, 1, 3);
2290 : 18 : tree elt1 = wide_int_to_tree (TREE_TYPE (base),
2291 : 36 : wi::to_wide (base) + wi::to_wide (step));
2292 : 18 : tree elt2 = wide_int_to_tree (TREE_TYPE (base),
2293 : 36 : wi::to_wide (elt1) + wi::to_wide (step));
2294 : 18 : builder.quick_push (base);
2295 : 18 : builder.quick_push (elt1);
2296 : 18 : builder.quick_push (elt2);
2297 : 18 : return builder.build ();
2298 : 18 : }
2299 : 0 : return build2 (VEC_SERIES_EXPR, type, base, step);
2300 : : }
2301 : :
2302 : : /* Return a vector with the same number of units and number of bits
2303 : : as VEC_TYPE, but in which the elements are a linear series of unsigned
2304 : : integers { BASE, BASE + STEP, BASE + STEP * 2, ... }. */
2305 : :
2306 : : tree
2307 : 1781 : build_index_vector (tree vec_type, poly_uint64 base, poly_uint64 step)
2308 : : {
2309 : 1781 : tree index_vec_type = vec_type;
2310 : 1781 : tree index_elt_type = TREE_TYPE (vec_type);
2311 : 1781 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vec_type);
2312 : 1781 : if (!INTEGRAL_TYPE_P (index_elt_type) || !TYPE_UNSIGNED (index_elt_type))
2313 : : {
2314 : 4 : index_elt_type = build_nonstandard_integer_type
2315 : 8 : (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (index_elt_type)), true);
2316 : 4 : index_vec_type = build_vector_type (index_elt_type, nunits);
2317 : : }
2318 : :
2319 : 1781 : tree_vector_builder v (index_vec_type, 1, 3);
2320 : 7124 : for (unsigned int i = 0; i < 3; ++i)
2321 : 5343 : v.quick_push (build_int_cstu (index_elt_type, base + i * step));
2322 : 1781 : return v.build ();
2323 : 1781 : }
2324 : :
2325 : : /* Return a VECTOR_CST of type VEC_TYPE in which the first NUM_A
2326 : : elements are A and the rest are B. */
2327 : :
2328 : : tree
2329 : 0 : build_vector_a_then_b (tree vec_type, unsigned int num_a, tree a, tree b)
2330 : : {
2331 : 0 : gcc_assert (known_le (num_a, TYPE_VECTOR_SUBPARTS (vec_type)));
2332 : 0 : unsigned int count = constant_lower_bound (TYPE_VECTOR_SUBPARTS (vec_type));
2333 : : /* Optimize the constant case. */
2334 : 0 : if ((count & 1) == 0 && TYPE_VECTOR_SUBPARTS (vec_type).is_constant ())
2335 : 0 : count /= 2;
2336 : 0 : tree_vector_builder builder (vec_type, count, 2);
2337 : 0 : for (unsigned int i = 0; i < count * 2; ++i)
2338 : 0 : builder.quick_push (i < num_a ? a : b);
2339 : 0 : return builder.build ();
2340 : 0 : }
2341 : :
2342 : : /* Something has messed with the elements of CONSTRUCTOR C after it was built;
2343 : : calculate TREE_CONSTANT and TREE_SIDE_EFFECTS. */
2344 : :
2345 : : void
2346 : 86526534 : recompute_constructor_flags (tree c)
2347 : : {
2348 : 86526534 : unsigned int i;
2349 : 86526534 : tree val;
2350 : 86526534 : bool constant_p = true;
2351 : 86526534 : bool side_effects_p = false;
2352 : 86526534 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2353 : :
2354 : 194304658 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2355 : : {
2356 : : /* Mostly ctors will have elts that don't have side-effects, so
2357 : : the usual case is to scan all the elements. Hence a single
2358 : : loop for both const and side effects, rather than one loop
2359 : : each (with early outs). */
2360 : 107778124 : if (!TREE_CONSTANT (val))
2361 : 15387739 : constant_p = false;
2362 : 107778124 : if (TREE_SIDE_EFFECTS (val))
2363 : 2929880 : side_effects_p = true;
2364 : : }
2365 : :
2366 : 86526534 : TREE_SIDE_EFFECTS (c) = side_effects_p;
2367 : 86526534 : TREE_CONSTANT (c) = constant_p;
2368 : 86526534 : }
2369 : :
2370 : : /* Make sure that TREE_CONSTANT and TREE_SIDE_EFFECTS are correct for
2371 : : CONSTRUCTOR C. */
2372 : :
2373 : : void
2374 : 11595669 : verify_constructor_flags (tree c)
2375 : : {
2376 : 11595669 : unsigned int i;
2377 : 11595669 : tree val;
2378 : 11595669 : bool constant_p = TREE_CONSTANT (c);
2379 : 11595669 : bool side_effects_p = TREE_SIDE_EFFECTS (c);
2380 : 11595669 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2381 : :
2382 : 64261665 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2383 : : {
2384 : 52665996 : if (constant_p && !TREE_CONSTANT (val))
2385 : 0 : internal_error ("non-constant element in constant CONSTRUCTOR");
2386 : 52665996 : if (!side_effects_p && TREE_SIDE_EFFECTS (val))
2387 : 0 : internal_error ("side-effects element in no-side-effects CONSTRUCTOR");
2388 : : }
2389 : 11595669 : }
2390 : :
2391 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2392 : : are in the vec pointed to by VALS. */
2393 : : tree
2394 : 71308693 : build_constructor (tree type, vec<constructor_elt, va_gc> *vals MEM_STAT_DECL)
2395 : : {
2396 : 71308693 : tree c = make_node (CONSTRUCTOR PASS_MEM_STAT);
2397 : :
2398 : 71308693 : TREE_TYPE (c) = type;
2399 : 71308693 : CONSTRUCTOR_ELTS (c) = vals;
2400 : :
2401 : 71308693 : recompute_constructor_flags (c);
2402 : :
2403 : 71308693 : return c;
2404 : : }
2405 : :
2406 : : /* Build a CONSTRUCTOR node made of a single initializer, with the specified
2407 : : INDEX and VALUE. */
2408 : : tree
2409 : 3856 : build_constructor_single (tree type, tree index, tree value)
2410 : : {
2411 : 3856 : vec<constructor_elt, va_gc> *v;
2412 : 3856 : constructor_elt elt = {index, value};
2413 : :
2414 : 3856 : vec_alloc (v, 1);
2415 : 3856 : v->quick_push (elt);
2416 : :
2417 : 3856 : return build_constructor (type, v);
2418 : : }
2419 : :
2420 : :
2421 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2422 : : are in a list pointed to by VALS. */
2423 : : tree
2424 : 992 : build_constructor_from_list (tree type, tree vals)
2425 : : {
2426 : 992 : tree t;
2427 : 992 : vec<constructor_elt, va_gc> *v = NULL;
2428 : :
2429 : 992 : if (vals)
2430 : : {
2431 : 992 : vec_alloc (v, list_length (vals));
2432 : 20809 : for (t = vals; t; t = TREE_CHAIN (t))
2433 : 19817 : CONSTRUCTOR_APPEND_ELT (v, TREE_PURPOSE (t), TREE_VALUE (t));
2434 : : }
2435 : :
2436 : 992 : return build_constructor (type, v);
2437 : : }
2438 : :
2439 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2440 : : are in a vector pointed to by VALS. Note that the TREE_PURPOSE
2441 : : fields in the constructor remain null. */
2442 : :
2443 : : tree
2444 : 1444 : build_constructor_from_vec (tree type, const vec<tree, va_gc> *vals)
2445 : : {
2446 : 1444 : vec<constructor_elt, va_gc> *v = NULL;
2447 : :
2448 : 72589 : for (tree t : vals)
2449 : 71145 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t);
2450 : :
2451 : 1444 : return build_constructor (type, v);
2452 : : }
2453 : :
2454 : : /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
2455 : : of elements, provided as index/value pairs. */
2456 : :
2457 : : tree
2458 : 38316 : build_constructor_va (tree type, int nelts, ...)
2459 : : {
2460 : 38316 : vec<constructor_elt, va_gc> *v = NULL;
2461 : 38316 : va_list p;
2462 : :
2463 : 38316 : va_start (p, nelts);
2464 : 38316 : vec_alloc (v, nelts);
2465 : 38316 : while (nelts--)
2466 : : {
2467 : 115141 : tree index = va_arg (p, tree);
2468 : 115141 : tree value = va_arg (p, tree);
2469 : 268598 : CONSTRUCTOR_APPEND_ELT (v, index, value);
2470 : : }
2471 : 38316 : va_end (p);
2472 : 38316 : return build_constructor (type, v);
2473 : : }
2474 : :
2475 : : /* Return a node of type TYPE for which TREE_CLOBBER_P is true. */
2476 : :
2477 : : tree
2478 : 7893998 : build_clobber (tree type, enum clobber_kind kind)
2479 : : {
2480 : 7893998 : tree clobber = build_constructor (type, NULL);
2481 : 7893998 : TREE_THIS_VOLATILE (clobber) = true;
2482 : 7893998 : CLOBBER_KIND (clobber) = kind;
2483 : 7893998 : return clobber;
2484 : : }
2485 : :
2486 : : /* Return a new FIXED_CST node whose type is TYPE and value is F. */
2487 : :
2488 : : tree
2489 : 54 : build_fixed (tree type, FIXED_VALUE_TYPE f)
2490 : : {
2491 : 54 : tree v;
2492 : 54 : FIXED_VALUE_TYPE *fp;
2493 : :
2494 : 54 : v = make_node (FIXED_CST);
2495 : 54 : fp = ggc_alloc<fixed_value> ();
2496 : 54 : memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
2497 : :
2498 : 54 : TREE_TYPE (v) = type;
2499 : 54 : TREE_FIXED_CST_PTR (v) = fp;
2500 : 54 : return v;
2501 : : }
2502 : :
2503 : : /* Return a new REAL_CST node whose type is TYPE and value is D. */
2504 : :
2505 : : tree
2506 : 42458614 : build_real (tree type, REAL_VALUE_TYPE d)
2507 : : {
2508 : 42458614 : tree v;
2509 : 42458614 : int overflow = 0;
2510 : :
2511 : : /* dconst{0,1,2,m1,half} are used in various places in
2512 : : the middle-end and optimizers, allow them here
2513 : : even for decimal floating point types as an exception
2514 : : by converting them to decimal. */
2515 : 42458614 : if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type))
2516 : 610494 : && (d.cl == rvc_normal || d.cl == rvc_zero)
2517 : 43067062 : && !d.decimal)
2518 : : {
2519 : 606 : if (memcmp (&d, &dconst1, sizeof (d)) == 0)
2520 : 0 : decimal_real_from_string (&d, "1");
2521 : 606 : else if (memcmp (&d, &dconst2, sizeof (d)) == 0)
2522 : 22 : decimal_real_from_string (&d, "2");
2523 : 584 : else if (memcmp (&d, &dconstm1, sizeof (d)) == 0)
2524 : 90 : decimal_real_from_string (&d, "-1");
2525 : 494 : else if (memcmp (&d, &dconsthalf, sizeof (d)) == 0)
2526 : 0 : decimal_real_from_string (&d, "0.5");
2527 : 494 : else if (memcmp (&d, &dconst0, sizeof (d)) == 0)
2528 : : {
2529 : : /* Make sure to give zero the minimum quantum exponent for
2530 : : the type (which corresponds to all bits zero). */
2531 : 494 : const struct real_format *fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
2532 : 494 : char buf[16];
2533 : 494 : sprintf (buf, "0e%d", fmt->emin - fmt->p);
2534 : 494 : decimal_real_from_string (&d, buf);
2535 : : }
2536 : : else
2537 : 0 : gcc_unreachable ();
2538 : : }
2539 : :
2540 : : /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
2541 : : Consider doing it via real_convert now. */
2542 : :
2543 : 42458614 : v = make_node (REAL_CST);
2544 : 42458614 : TREE_TYPE (v) = type;
2545 : 42458614 : memcpy (TREE_REAL_CST_PTR (v), &d, sizeof (REAL_VALUE_TYPE));
2546 : 42458614 : TREE_OVERFLOW (v) = overflow;
2547 : 42458614 : return v;
2548 : : }
2549 : :
2550 : : /* Like build_real, but first truncate D to the type. */
2551 : :
2552 : : tree
2553 : 176267 : build_real_truncate (tree type, REAL_VALUE_TYPE d)
2554 : : {
2555 : 176267 : return build_real (type, real_value_truncate (TYPE_MODE (type), d));
2556 : : }
2557 : :
2558 : : /* Return a new REAL_CST node whose type is TYPE
2559 : : and whose value is the integer value of the INTEGER_CST node I. */
2560 : :
2561 : : REAL_VALUE_TYPE
2562 : 24807059 : real_value_from_int_cst (const_tree type, const_tree i)
2563 : : {
2564 : 24807059 : REAL_VALUE_TYPE d;
2565 : :
2566 : : /* Clear all bits of the real value type so that we can later do
2567 : : bitwise comparisons to see if two values are the same. */
2568 : 24807059 : memset (&d, 0, sizeof d);
2569 : :
2570 : 24807059 : real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, wi::to_wide (i),
2571 : 24807059 : TYPE_SIGN (TREE_TYPE (i)));
2572 : 24807059 : return d;
2573 : : }
2574 : :
2575 : : /* Given a tree representing an integer constant I, return a tree
2576 : : representing the same value as a floating-point constant of type TYPE. */
2577 : :
2578 : : tree
2579 : 24218998 : build_real_from_int_cst (tree type, const_tree i)
2580 : : {
2581 : 24218998 : tree v;
2582 : 24218998 : int overflow = TREE_OVERFLOW (i);
2583 : :
2584 : 24218998 : v = build_real (type, real_value_from_int_cst (type, i));
2585 : :
2586 : 24218998 : TREE_OVERFLOW (v) |= overflow;
2587 : 24218998 : return v;
2588 : : }
2589 : :
2590 : : /* Return a new REAL_CST node whose type is TYPE
2591 : : and whose value is the integer value I which has sign SGN. */
2592 : :
2593 : : tree
2594 : 133 : build_real_from_wide (tree type, const wide_int_ref &i, signop sgn)
2595 : : {
2596 : 133 : REAL_VALUE_TYPE d;
2597 : :
2598 : : /* Clear all bits of the real value type so that we can later do
2599 : : bitwise comparisons to see if two values are the same. */
2600 : 133 : memset (&d, 0, sizeof d);
2601 : :
2602 : 133 : real_from_integer (&d, TYPE_MODE (type), i, sgn);
2603 : 133 : return build_real (type, d);
2604 : : }
2605 : :
2606 : : /* Return a newly constructed STRING_CST node whose value is the LEN
2607 : : characters at STR when STR is nonnull, or all zeros otherwise.
2608 : : Note that for a C string literal, LEN should include the trailing NUL.
2609 : : The TREE_TYPE is not initialized. */
2610 : :
2611 : : tree
2612 : 92050396 : build_string (unsigned len, const char *str /*= NULL */)
2613 : : {
2614 : : /* Do not waste bytes provided by padding of struct tree_string. */
2615 : 92050396 : unsigned size = len + offsetof (struct tree_string, str) + 1;
2616 : :
2617 : 92050396 : record_node_allocation_statistics (STRING_CST, size);
2618 : :
2619 : 92050396 : tree s = (tree) ggc_internal_alloc (size);
2620 : :
2621 : 92050396 : memset (s, 0, sizeof (struct tree_typed));
2622 : 92050396 : TREE_SET_CODE (s, STRING_CST);
2623 : 92050396 : TREE_CONSTANT (s) = 1;
2624 : 92050396 : TREE_STRING_LENGTH (s) = len;
2625 : 92050396 : if (str)
2626 : 92041233 : memcpy (s->string.str, str, len);
2627 : : else
2628 : 9163 : memset (s->string.str, 0, len);
2629 : 92050396 : s->string.str[len] = '\0';
2630 : :
2631 : 92050396 : return s;
2632 : : }
2633 : :
2634 : : /* Return a newly constructed COMPLEX_CST node whose value is
2635 : : specified by the real and imaginary parts REAL and IMAG.
2636 : : Both REAL and IMAG should be constant nodes. TYPE, if specified,
2637 : : will be the type of the COMPLEX_CST; otherwise a new type will be made. */
2638 : :
2639 : : tree
2640 : 484856 : build_complex (tree type, tree real, tree imag)
2641 : : {
2642 : 484856 : gcc_assert (CONSTANT_CLASS_P (real));
2643 : 484856 : gcc_assert (CONSTANT_CLASS_P (imag));
2644 : :
2645 : 484856 : tree t = make_node (COMPLEX_CST);
2646 : :
2647 : 484856 : TREE_REALPART (t) = real;
2648 : 484856 : TREE_IMAGPART (t) = imag;
2649 : 484856 : TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
2650 : 484856 : TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
2651 : 484856 : return t;
2652 : : }
2653 : :
2654 : : /* Build a complex (inf +- 0i), such as for the result of cproj.
2655 : : TYPE is the complex tree type of the result. If NEG is true, the
2656 : : imaginary zero is negative. */
2657 : :
2658 : : tree
2659 : 840 : build_complex_inf (tree type, bool neg)
2660 : : {
2661 : 840 : REAL_VALUE_TYPE rzero = dconst0;
2662 : :
2663 : 840 : rzero.sign = neg;
2664 : 840 : return build_complex (type, build_real (TREE_TYPE (type), dconstinf),
2665 : 840 : build_real (TREE_TYPE (type), rzero));
2666 : : }
2667 : :
2668 : : /* Return the constant 1 in type TYPE. If TYPE has several elements, each
2669 : : element is set to 1. In particular, this is 1 + i for complex types. */
2670 : :
2671 : : tree
2672 : 3764 : build_each_one_cst (tree type)
2673 : : {
2674 : 3764 : if (TREE_CODE (type) == COMPLEX_TYPE)
2675 : : {
2676 : 0 : tree scalar = build_one_cst (TREE_TYPE (type));
2677 : 0 : return build_complex (type, scalar, scalar);
2678 : : }
2679 : : else
2680 : 3764 : return build_one_cst (type);
2681 : : }
2682 : :
2683 : : /* Return a constant of arithmetic type TYPE which is the
2684 : : multiplicative identity of the set TYPE. */
2685 : :
2686 : : tree
2687 : 9391741 : build_one_cst (tree type)
2688 : : {
2689 : 9391741 : switch (TREE_CODE (type))
2690 : : {
2691 : 9377891 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2692 : 9377891 : case POINTER_TYPE: case REFERENCE_TYPE:
2693 : 9377891 : case OFFSET_TYPE: case BITINT_TYPE:
2694 : 9377891 : return build_int_cst (type, 1);
2695 : :
2696 : 10504 : case REAL_TYPE:
2697 : 10504 : return build_real (type, dconst1);
2698 : :
2699 : 0 : case FIXED_POINT_TYPE:
2700 : : /* We can only generate 1 for accum types. */
2701 : 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2702 : 0 : return build_fixed (type, FCONST1 (TYPE_MODE (type)));
2703 : :
2704 : 343 : case VECTOR_TYPE:
2705 : 343 : {
2706 : 343 : tree scalar = build_one_cst (TREE_TYPE (type));
2707 : :
2708 : 343 : return build_vector_from_val (type, scalar);
2709 : : }
2710 : :
2711 : 3003 : case COMPLEX_TYPE:
2712 : 6006 : return build_complex (type,
2713 : 3003 : build_one_cst (TREE_TYPE (type)),
2714 : 6006 : build_zero_cst (TREE_TYPE (type)));
2715 : :
2716 : 0 : default:
2717 : 0 : gcc_unreachable ();
2718 : : }
2719 : : }
2720 : :
2721 : : /* Return an integer of type TYPE containing all 1's in as much precision as
2722 : : it contains, or a complex or vector whose subparts are such integers. */
2723 : :
2724 : : tree
2725 : 1718812 : build_all_ones_cst (tree type)
2726 : : {
2727 : 1718812 : if (TREE_CODE (type) == COMPLEX_TYPE)
2728 : : {
2729 : 0 : tree scalar = build_all_ones_cst (TREE_TYPE (type));
2730 : 0 : return build_complex (type, scalar, scalar);
2731 : : }
2732 : : else
2733 : 1718812 : return build_minus_one_cst (type);
2734 : : }
2735 : :
2736 : : /* Return a constant of arithmetic type TYPE which is the
2737 : : opposite of the multiplicative identity of the set TYPE. */
2738 : :
2739 : : tree
2740 : 2309862 : build_minus_one_cst (tree type)
2741 : : {
2742 : 2309862 : switch (TREE_CODE (type))
2743 : : {
2744 : 2194479 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2745 : 2194479 : case POINTER_TYPE: case REFERENCE_TYPE:
2746 : 2194479 : case OFFSET_TYPE: case BITINT_TYPE:
2747 : 2194479 : return build_int_cst (type, -1);
2748 : :
2749 : 9786 : case REAL_TYPE:
2750 : 9786 : return build_real (type, dconstm1);
2751 : :
2752 : 0 : case FIXED_POINT_TYPE:
2753 : : /* We can only generate 1 for accum types. */
2754 : 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2755 : 0 : return build_fixed (type,
2756 : : fixed_from_double_int (double_int_minus_one,
2757 : 0 : SCALAR_TYPE_MODE (type)));
2758 : :
2759 : 105597 : case VECTOR_TYPE:
2760 : 105597 : {
2761 : 105597 : tree scalar = build_minus_one_cst (TREE_TYPE (type));
2762 : :
2763 : 105597 : return build_vector_from_val (type, scalar);
2764 : : }
2765 : :
2766 : 0 : case COMPLEX_TYPE:
2767 : 0 : return build_complex (type,
2768 : 0 : build_minus_one_cst (TREE_TYPE (type)),
2769 : 0 : build_zero_cst (TREE_TYPE (type)));
2770 : :
2771 : 0 : default:
2772 : 0 : gcc_unreachable ();
2773 : : }
2774 : : }
2775 : :
2776 : : /* Build 0 constant of type TYPE. This is used by constructor folding
2777 : : and thus the constant should be represented in memory by
2778 : : zero(es). */
2779 : :
2780 : : tree
2781 : 81624667 : build_zero_cst (tree type)
2782 : : {
2783 : 81624667 : switch (TREE_CODE (type))
2784 : : {
2785 : 81057770 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2786 : 81057770 : case POINTER_TYPE: case REFERENCE_TYPE:
2787 : 81057770 : case OFFSET_TYPE: case NULLPTR_TYPE: case BITINT_TYPE:
2788 : 81057770 : return build_int_cst (type, 0);
2789 : :
2790 : 224214 : case REAL_TYPE:
2791 : 224214 : return build_real (type, dconst0);
2792 : :
2793 : 0 : case FIXED_POINT_TYPE:
2794 : 0 : return build_fixed (type, FCONST0 (TYPE_MODE (type)));
2795 : :
2796 : 153479 : case VECTOR_TYPE:
2797 : 153479 : {
2798 : 153479 : tree scalar = build_zero_cst (TREE_TYPE (type));
2799 : :
2800 : 153479 : return build_vector_from_val (type, scalar);
2801 : : }
2802 : :
2803 : 3064 : case COMPLEX_TYPE:
2804 : 3064 : {
2805 : 3064 : tree zero = build_zero_cst (TREE_TYPE (type));
2806 : :
2807 : 3064 : return build_complex (type, zero, zero);
2808 : : }
2809 : :
2810 : 186140 : default:
2811 : 186140 : if (!AGGREGATE_TYPE_P (type))
2812 : 1 : return fold_convert (type, integer_zero_node);
2813 : 186139 : return build_constructor (type, NULL);
2814 : : }
2815 : : }
2816 : :
2817 : : /* Build a constant of integer type TYPE, made of VALUE's bits replicated
2818 : : every WIDTH bits to fit TYPE's precision. */
2819 : :
2820 : : tree
2821 : 14 : build_replicated_int_cst (tree type, unsigned int width, HOST_WIDE_INT value)
2822 : : {
2823 : 14 : int n = ((TYPE_PRECISION (type) + HOST_BITS_PER_WIDE_INT - 1)
2824 : 14 : / HOST_BITS_PER_WIDE_INT);
2825 : 14 : unsigned HOST_WIDE_INT low, mask;
2826 : 14 : HOST_WIDE_INT a[WIDE_INT_MAX_INL_ELTS];
2827 : 14 : int i;
2828 : :
2829 : 14 : gcc_assert (n && n <= WIDE_INT_MAX_INL_ELTS);
2830 : :
2831 : 14 : if (width == HOST_BITS_PER_WIDE_INT)
2832 : 0 : low = value;
2833 : : else
2834 : : {
2835 : 14 : mask = (HOST_WIDE_INT_1U << width) - 1;
2836 : 14 : low = (unsigned HOST_WIDE_INT) ~0 / mask * (value & mask);
2837 : : }
2838 : :
2839 : 28 : for (i = 0; i < n; i++)
2840 : 14 : a[i] = low;
2841 : :
2842 : 14 : gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
2843 : 14 : return wide_int_to_tree (type, wide_int::from_array (a, n,
2844 : 14 : TYPE_PRECISION (type)));
2845 : : }
2846 : :
2847 : : /* If floating-point type TYPE has an IEEE-style sign bit, return an
2848 : : unsigned constant in which only the sign bit is set. Return null
2849 : : otherwise. */
2850 : :
2851 : : tree
2852 : 0 : sign_mask_for (tree type)
2853 : : {
2854 : : /* Avoid having to choose between a real-only sign and a pair of signs.
2855 : : This could be relaxed if the choice becomes obvious later. */
2856 : 0 : if (TREE_CODE (type) == COMPLEX_TYPE)
2857 : : return NULL_TREE;
2858 : :
2859 : 0 : auto eltmode = as_a<scalar_float_mode> (element_mode (type));
2860 : 0 : auto bits = REAL_MODE_FORMAT (eltmode)->ieee_bits;
2861 : 0 : if (!bits || !pow2p_hwi (bits))
2862 : : return NULL_TREE;
2863 : :
2864 : 0 : tree inttype = unsigned_type_for (type);
2865 : 0 : if (!inttype)
2866 : : return NULL_TREE;
2867 : :
2868 : 0 : auto mask = wi::set_bit_in_zero (bits - 1, bits);
2869 : 0 : if (VECTOR_TYPE_P (inttype))
2870 : : {
2871 : 0 : tree elt = wide_int_to_tree (TREE_TYPE (inttype), mask);
2872 : 0 : return build_vector_from_val (inttype, elt);
2873 : : }
2874 : 0 : return wide_int_to_tree (inttype, mask);
2875 : 0 : }
2876 : :
2877 : : /* Build a BINFO with LEN language slots. */
2878 : :
2879 : : tree
2880 : 89233522 : make_tree_binfo (unsigned base_binfos MEM_STAT_DECL)
2881 : : {
2882 : 89233522 : tree t;
2883 : 89233522 : size_t length = (offsetof (struct tree_binfo, base_binfos)
2884 : 89233522 : + vec<tree, va_gc>::embedded_size (base_binfos));
2885 : :
2886 : 89233522 : record_node_allocation_statistics (TREE_BINFO, length);
2887 : :
2888 : 89233522 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
2889 : :
2890 : 89233522 : memset (t, 0, offsetof (struct tree_binfo, base_binfos));
2891 : :
2892 : 89233522 : TREE_SET_CODE (t, TREE_BINFO);
2893 : :
2894 : 89233522 : BINFO_BASE_BINFOS (t)->embedded_init (base_binfos);
2895 : :
2896 : 89233522 : return t;
2897 : : }
2898 : :
2899 : : /* Create a CASE_LABEL_EXPR tree node and return it. */
2900 : :
2901 : : tree
2902 : 4839786 : build_case_label (tree low_value, tree high_value, tree label_decl)
2903 : : {
2904 : 4839786 : tree t = make_node (CASE_LABEL_EXPR);
2905 : :
2906 : 4839786 : TREE_TYPE (t) = void_type_node;
2907 : 4839786 : SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (label_decl));
2908 : :
2909 : 4839786 : CASE_LOW (t) = low_value;
2910 : 4839786 : CASE_HIGH (t) = high_value;
2911 : 4839786 : CASE_LABEL (t) = label_decl;
2912 : 4839786 : CASE_CHAIN (t) = NULL_TREE;
2913 : :
2914 : 4839786 : return t;
2915 : : }
2916 : :
2917 : : /* Build a newly constructed INTEGER_CST node. LEN and EXT_LEN are the
2918 : : values of TREE_INT_CST_NUNITS and TREE_INT_CST_EXT_NUNITS respectively.
2919 : : The latter determines the length of the HOST_WIDE_INT vector. */
2920 : :
2921 : : tree
2922 : 189669134 : make_int_cst (int len, int ext_len MEM_STAT_DECL)
2923 : : {
2924 : 189669134 : tree t;
2925 : 189669134 : int length = ((ext_len - 1) * sizeof (HOST_WIDE_INT)
2926 : 189669134 : + sizeof (struct tree_int_cst));
2927 : :
2928 : 189669134 : gcc_assert (len);
2929 : 189669134 : record_node_allocation_statistics (INTEGER_CST, length);
2930 : :
2931 : 189669134 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2932 : :
2933 : 189669134 : TREE_SET_CODE (t, INTEGER_CST);
2934 : 189669134 : TREE_INT_CST_NUNITS (t) = len;
2935 : 189669134 : TREE_INT_CST_EXT_NUNITS (t) = ext_len;
2936 : 189669134 : TREE_CONSTANT (t) = 1;
2937 : :
2938 : 189669134 : return t;
2939 : : }
2940 : :
2941 : : /* Build a newly constructed TREE_VEC node of length LEN. */
2942 : :
2943 : : tree
2944 : 2476214974 : make_tree_vec (int len MEM_STAT_DECL)
2945 : : {
2946 : 2476214974 : tree t;
2947 : 2476214974 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2948 : :
2949 : 2476214974 : record_node_allocation_statistics (TREE_VEC, length);
2950 : :
2951 : 2476214974 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2952 : :
2953 : 2476214974 : TREE_SET_CODE (t, TREE_VEC);
2954 : 2476214974 : TREE_VEC_LENGTH (t) = len;
2955 : :
2956 : 2476214974 : return t;
2957 : : }
2958 : :
2959 : : /* Grow a TREE_VEC node to new length LEN. */
2960 : :
2961 : : tree
2962 : 138440 : grow_tree_vec (tree v, int len MEM_STAT_DECL)
2963 : : {
2964 : 138440 : gcc_assert (TREE_CODE (v) == TREE_VEC);
2965 : :
2966 : 138440 : int oldlen = TREE_VEC_LENGTH (v);
2967 : 138440 : gcc_assert (len > oldlen);
2968 : :
2969 : 138440 : size_t oldlength = (oldlen - 1) * sizeof (tree) + sizeof (struct tree_vec);
2970 : 138440 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2971 : :
2972 : 138440 : record_node_allocation_statistics (TREE_VEC, length - oldlength);
2973 : :
2974 : 138440 : v = (tree) ggc_realloc (v, length PASS_MEM_STAT);
2975 : :
2976 : 138440 : TREE_VEC_LENGTH (v) = len;
2977 : :
2978 : 138440 : return v;
2979 : : }
2980 : :
2981 : : /* Return true if EXPR is the constant zero, whether it is integral, float or
2982 : : fixed, and scalar, complex or vector. */
2983 : :
2984 : : bool
2985 : 15982451 : zerop (const_tree expr)
2986 : : {
2987 : 15982451 : return (integer_zerop (expr)
2988 : 10941154 : || real_zerop (expr)
2989 : 26515123 : || fixed_zerop (expr));
2990 : : }
2991 : :
2992 : : /* Return true if EXPR is the integer constant zero or a complex constant
2993 : : of zero, or a location wrapper for such a constant. */
2994 : :
2995 : : bool
2996 : 5493756111 : integer_zerop (const_tree expr)
2997 : : {
2998 : 5493756111 : STRIP_ANY_LOCATION_WRAPPER (expr);
2999 : :
3000 : 5493756111 : switch (TREE_CODE (expr))
3001 : : {
3002 : 4593809023 : case INTEGER_CST:
3003 : 4593809023 : return wi::to_wide (expr) == 0;
3004 : 1202465 : case COMPLEX_CST:
3005 : 1202465 : return (integer_zerop (TREE_REALPART (expr))
3006 : 1224587 : && integer_zerop (TREE_IMAGPART (expr)));
3007 : 2560171 : case VECTOR_CST:
3008 : 2560171 : return (VECTOR_CST_NPATTERNS (expr) == 1
3009 : 2427766 : && VECTOR_CST_DUPLICATE_P (expr)
3010 : 4580886 : && integer_zerop (VECTOR_CST_ENCODED_ELT (expr, 0)));
3011 : : default:
3012 : : return false;
3013 : : }
3014 : : }
3015 : :
3016 : : /* Return true if EXPR is the integer constant one or the corresponding
3017 : : complex constant, or a location wrapper for such a constant. */
3018 : :
3019 : : bool
3020 : 920171238 : integer_onep (const_tree expr)
3021 : : {
3022 : 920171238 : STRIP_ANY_LOCATION_WRAPPER (expr);
3023 : :
3024 : 920171238 : switch (TREE_CODE (expr))
3025 : : {
3026 : 784974509 : case INTEGER_CST:
3027 : 784974509 : return wi::eq_p (wi::to_widest (expr), 1);
3028 : 21352 : case COMPLEX_CST:
3029 : 21352 : return (integer_onep (TREE_REALPART (expr))
3030 : 21372 : && integer_zerop (TREE_IMAGPART (expr)));
3031 : 151052 : case VECTOR_CST:
3032 : 151052 : return (VECTOR_CST_NPATTERNS (expr) == 1
3033 : 136183 : && VECTOR_CST_DUPLICATE_P (expr)
3034 : 276129 : && integer_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3035 : : default:
3036 : : return false;
3037 : : }
3038 : : }
3039 : :
3040 : : /* Return true if EXPR is the integer constant one. For complex and vector,
3041 : : return true if every piece is the integer constant one.
3042 : : Also return true for location wrappers for such a constant. */
3043 : :
3044 : : bool
3045 : 734793 : integer_each_onep (const_tree expr)
3046 : : {
3047 : 734793 : STRIP_ANY_LOCATION_WRAPPER (expr);
3048 : :
3049 : 734793 : if (TREE_CODE (expr) == COMPLEX_CST)
3050 : 34 : return (integer_onep (TREE_REALPART (expr))
3051 : 48 : && integer_onep (TREE_IMAGPART (expr)));
3052 : : else
3053 : 734759 : return integer_onep (expr);
3054 : : }
3055 : :
3056 : : /* Return true if EXPR is an integer containing all 1's in as much precision
3057 : : as it contains, or a complex or vector whose subparts are such integers,
3058 : : or a location wrapper for such a constant. */
3059 : :
3060 : : bool
3061 : 270338555 : integer_all_onesp (const_tree expr)
3062 : : {
3063 : 270338555 : STRIP_ANY_LOCATION_WRAPPER (expr);
3064 : :
3065 : 270338555 : if (TREE_CODE (expr) == COMPLEX_CST
3066 : 926 : && integer_all_onesp (TREE_REALPART (expr))
3067 : 270338595 : && integer_all_onesp (TREE_IMAGPART (expr)))
3068 : : return true;
3069 : :
3070 : 270338519 : else if (TREE_CODE (expr) == VECTOR_CST)
3071 : 458265 : return (VECTOR_CST_NPATTERNS (expr) == 1
3072 : 422809 : && VECTOR_CST_DUPLICATE_P (expr)
3073 : 862728 : && integer_all_onesp (VECTOR_CST_ENCODED_ELT (expr, 0)));
3074 : :
3075 : 269880254 : else if (TREE_CODE (expr) != INTEGER_CST)
3076 : : return false;
3077 : :
3078 : 177796525 : return (wi::max_value (TYPE_PRECISION (TREE_TYPE (expr)), UNSIGNED)
3079 : 355593492 : == wi::to_wide (expr));
3080 : : }
3081 : :
3082 : : /* Return true if EXPR is the integer constant minus one, or a location
3083 : : wrapper for such a constant. */
3084 : :
3085 : : bool
3086 : 196500011 : integer_minus_onep (const_tree expr)
3087 : : {
3088 : 196500011 : STRIP_ANY_LOCATION_WRAPPER (expr);
3089 : :
3090 : 196500011 : if (TREE_CODE (expr) == COMPLEX_CST)
3091 : 9060 : return (integer_all_onesp (TREE_REALPART (expr))
3092 : 9064 : && integer_zerop (TREE_IMAGPART (expr)));
3093 : : else
3094 : 196490951 : return integer_all_onesp (expr);
3095 : : }
3096 : :
3097 : : /* Return true if EXPR is an integer constant that is a power of 2 (i.e., has
3098 : : only one bit on), or a location wrapper for such a constant. */
3099 : :
3100 : : bool
3101 : 21060571 : integer_pow2p (const_tree expr)
3102 : : {
3103 : 21060571 : STRIP_ANY_LOCATION_WRAPPER (expr);
3104 : :
3105 : 21060571 : if (TREE_CODE (expr) == COMPLEX_CST
3106 : 543 : && integer_pow2p (TREE_REALPART (expr))
3107 : 21060798 : && integer_zerop (TREE_IMAGPART (expr)))
3108 : : return true;
3109 : :
3110 : 21060418 : if (TREE_CODE (expr) != INTEGER_CST)
3111 : : return false;
3112 : :
3113 : 14501663 : return wi::popcount (wi::to_wide (expr)) == 1;
3114 : : }
3115 : :
3116 : : /* Return true if EXPR is an integer constant other than zero or a
3117 : : complex constant other than zero, or a location wrapper for such a
3118 : : constant. */
3119 : :
3120 : : bool
3121 : 135704981 : integer_nonzerop (const_tree expr)
3122 : : {
3123 : 135704981 : STRIP_ANY_LOCATION_WRAPPER (expr);
3124 : :
3125 : 135704981 : return ((TREE_CODE (expr) == INTEGER_CST
3126 : 63059426 : && wi::to_wide (expr) != 0)
3127 : 149215670 : || (TREE_CODE (expr) == COMPLEX_CST
3128 : 244 : && (integer_nonzerop (TREE_REALPART (expr))
3129 : 184 : || integer_nonzerop (TREE_IMAGPART (expr)))));
3130 : : }
3131 : :
3132 : : /* Return true if EXPR is the integer constant one. For vector,
3133 : : return true if every piece is the integer constant minus one
3134 : : (representing the value TRUE).
3135 : : Also return true for location wrappers for such a constant. */
3136 : :
3137 : : bool
3138 : 1101762 : integer_truep (const_tree expr)
3139 : : {
3140 : 1101762 : STRIP_ANY_LOCATION_WRAPPER (expr);
3141 : :
3142 : 1101762 : if (TREE_CODE (expr) == VECTOR_CST)
3143 : 12497 : return integer_all_onesp (expr);
3144 : 1089265 : return integer_onep (expr);
3145 : : }
3146 : :
3147 : : /* Return true if EXPR is the fixed-point constant zero, or a location wrapper
3148 : : for such a constant. */
3149 : :
3150 : : bool
3151 : 24314033 : fixed_zerop (const_tree expr)
3152 : : {
3153 : 24314033 : STRIP_ANY_LOCATION_WRAPPER (expr);
3154 : :
3155 : 24314033 : return (TREE_CODE (expr) == FIXED_CST
3156 : 24314033 : && TREE_FIXED_CST (expr).data.is_zero ());
3157 : : }
3158 : :
3159 : : /* Return the power of two represented by a tree node known to be a
3160 : : power of two. */
3161 : :
3162 : : int
3163 : 698780 : tree_log2 (const_tree expr)
3164 : : {
3165 : 698780 : if (TREE_CODE (expr) == COMPLEX_CST)
3166 : 0 : return tree_log2 (TREE_REALPART (expr));
3167 : :
3168 : 698780 : return wi::exact_log2 (wi::to_wide (expr));
3169 : : }
3170 : :
3171 : : /* Similar, but return the largest integer Y such that 2 ** Y is less
3172 : : than or equal to EXPR. */
3173 : :
3174 : : int
3175 : 2674063 : tree_floor_log2 (const_tree expr)
3176 : : {
3177 : 2674063 : if (TREE_CODE (expr) == COMPLEX_CST)
3178 : 0 : return tree_log2 (TREE_REALPART (expr));
3179 : :
3180 : 2674063 : return wi::floor_log2 (wi::to_wide (expr));
3181 : : }
3182 : :
3183 : : /* Return number of known trailing zero bits in EXPR, or, if the value of
3184 : : EXPR is known to be zero, the precision of it's type. */
3185 : :
3186 : : unsigned int
3187 : 82142646 : tree_ctz (const_tree expr)
3188 : : {
3189 : 164283666 : if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
3190 : 82150204 : && !POINTER_TYPE_P (TREE_TYPE (expr)))
3191 : : return 0;
3192 : :
3193 : 82142634 : unsigned int ret1, ret2, prec = TYPE_PRECISION (TREE_TYPE (expr));
3194 : 82142634 : switch (TREE_CODE (expr))
3195 : : {
3196 : 43849796 : case INTEGER_CST:
3197 : 43849796 : ret1 = wi::ctz (wi::to_wide (expr));
3198 : 43849796 : return MIN (ret1, prec);
3199 : 12480118 : case SSA_NAME:
3200 : 12480118 : ret1 = wi::ctz (get_nonzero_bits (expr));
3201 : 12480118 : return MIN (ret1, prec);
3202 : 2009201 : case PLUS_EXPR:
3203 : 2009201 : case MINUS_EXPR:
3204 : 2009201 : case BIT_IOR_EXPR:
3205 : 2009201 : case BIT_XOR_EXPR:
3206 : 2009201 : case MIN_EXPR:
3207 : 2009201 : case MAX_EXPR:
3208 : 2009201 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3209 : 2009201 : if (ret1 == 0)
3210 : : return ret1;
3211 : 912037 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3212 : 912037 : return MIN (ret1, ret2);
3213 : 0 : case POINTER_PLUS_EXPR:
3214 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3215 : 0 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3216 : : /* Second operand is sizetype, which could be in theory
3217 : : wider than pointer's precision. Make sure we never
3218 : : return more than prec. */
3219 : 0 : ret2 = MIN (ret2, prec);
3220 : 0 : return MIN (ret1, ret2);
3221 : 270 : case BIT_AND_EXPR:
3222 : 270 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3223 : 270 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3224 : 270 : return MAX (ret1, ret2);
3225 : 11612616 : case MULT_EXPR:
3226 : 11612616 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3227 : 11612616 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3228 : 11612616 : return MIN (ret1 + ret2, prec);
3229 : 0 : case LSHIFT_EXPR:
3230 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3231 : 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3232 : 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3233 : : {
3234 : 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3235 : 0 : return MIN (ret1 + ret2, prec);
3236 : : }
3237 : : return ret1;
3238 : 0 : case RSHIFT_EXPR:
3239 : 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3240 : 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3241 : : {
3242 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3243 : 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3244 : 0 : if (ret1 > ret2)
3245 : 0 : return ret1 - ret2;
3246 : : }
3247 : : return 0;
3248 : 5788 : case TRUNC_DIV_EXPR:
3249 : 5788 : case CEIL_DIV_EXPR:
3250 : 5788 : case FLOOR_DIV_EXPR:
3251 : 5788 : case ROUND_DIV_EXPR:
3252 : 5788 : case EXACT_DIV_EXPR:
3253 : 5788 : if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
3254 : 5788 : && tree_int_cst_sgn (TREE_OPERAND (expr, 1)) == 1)
3255 : : {
3256 : 5788 : int l = tree_log2 (TREE_OPERAND (expr, 1));
3257 : 5788 : if (l >= 0)
3258 : : {
3259 : 4634 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3260 : 4634 : ret2 = l;
3261 : 4634 : if (ret1 > ret2)
3262 : 0 : return ret1 - ret2;
3263 : : }
3264 : : }
3265 : : return 0;
3266 : 12161227 : CASE_CONVERT:
3267 : 12161227 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3268 : 12161227 : if (ret1 && ret1 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
3269 : : ret1 = prec;
3270 : 12161227 : return MIN (ret1, prec);
3271 : 0 : case SAVE_EXPR:
3272 : 0 : return tree_ctz (TREE_OPERAND (expr, 0));
3273 : 9663 : case COND_EXPR:
3274 : 9663 : ret1 = tree_ctz (TREE_OPERAND (expr, 1));
3275 : 9663 : if (ret1 == 0)
3276 : : return 0;
3277 : 186 : ret2 = tree_ctz (TREE_OPERAND (expr, 2));
3278 : 186 : return MIN (ret1, ret2);
3279 : 0 : case COMPOUND_EXPR:
3280 : 0 : return tree_ctz (TREE_OPERAND (expr, 1));
3281 : 220 : case ADDR_EXPR:
3282 : 220 : ret1 = get_pointer_alignment (CONST_CAST_TREE (expr));
3283 : 220 : if (ret1 > BITS_PER_UNIT)
3284 : : {
3285 : 220 : ret1 = ctz_hwi (ret1 / BITS_PER_UNIT);
3286 : 220 : return MIN (ret1, prec);
3287 : : }
3288 : : return 0;
3289 : : default:
3290 : : return 0;
3291 : : }
3292 : : }
3293 : :
3294 : : /* Return true if EXPR is the real constant zero. Trailing zeroes matter for
3295 : : decimal float constants, so don't return true for them.
3296 : : Also return true for location wrappers around such a constant. */
3297 : :
3298 : : bool
3299 : 561396769 : real_zerop (const_tree expr)
3300 : : {
3301 : 561396769 : STRIP_ANY_LOCATION_WRAPPER (expr);
3302 : :
3303 : 561396769 : switch (TREE_CODE (expr))
3304 : : {
3305 : 19667609 : case REAL_CST:
3306 : 19667609 : return real_equal (&TREE_REAL_CST (expr), &dconst0)
3307 : 19667609 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3308 : 44326 : case COMPLEX_CST:
3309 : 44326 : return real_zerop (TREE_REALPART (expr))
3310 : 57352 : && real_zerop (TREE_IMAGPART (expr));
3311 : 444856 : case VECTOR_CST:
3312 : 444856 : {
3313 : : /* Don't simply check for a duplicate because the predicate
3314 : : accepts both +0.0 and -0.0. */
3315 : 444856 : unsigned count = vector_cst_encoded_nelts (expr);
3316 : 476473 : for (unsigned int i = 0; i < count; ++i)
3317 : 454148 : if (!real_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3318 : : return false;
3319 : : return true;
3320 : : }
3321 : : default:
3322 : : return false;
3323 : : }
3324 : : }
3325 : :
3326 : : /* Return true if EXPR is the real constant one in real or complex form.
3327 : : Trailing zeroes matter for decimal float constants, so don't return
3328 : : true for them.
3329 : : Also return true for location wrappers around such a constant. */
3330 : :
3331 : : bool
3332 : 116261647 : real_onep (const_tree expr)
3333 : : {
3334 : 116261647 : STRIP_ANY_LOCATION_WRAPPER (expr);
3335 : :
3336 : 116261647 : switch (TREE_CODE (expr))
3337 : : {
3338 : 7382733 : case REAL_CST:
3339 : 7382733 : return real_equal (&TREE_REAL_CST (expr), &dconst1)
3340 : 7382733 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3341 : 12622 : case COMPLEX_CST:
3342 : 12622 : return real_onep (TREE_REALPART (expr))
3343 : 16111 : && real_zerop (TREE_IMAGPART (expr));
3344 : 59090 : case VECTOR_CST:
3345 : 59090 : return (VECTOR_CST_NPATTERNS (expr) == 1
3346 : 50926 : && VECTOR_CST_DUPLICATE_P (expr)
3347 : 101277 : && real_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3348 : : default:
3349 : : return false;
3350 : : }
3351 : : }
3352 : :
3353 : : /* Return true if EXPR is the real constant minus one. Trailing zeroes
3354 : : matter for decimal float constants, so don't return true for them.
3355 : : Also return true for location wrappers around such a constant. */
3356 : :
3357 : : bool
3358 : 117259822 : real_minus_onep (const_tree expr)
3359 : : {
3360 : 117259822 : STRIP_ANY_LOCATION_WRAPPER (expr);
3361 : :
3362 : 117259822 : switch (TREE_CODE (expr))
3363 : : {
3364 : 7320060 : case REAL_CST:
3365 : 7320060 : return real_equal (&TREE_REAL_CST (expr), &dconstm1)
3366 : 7320060 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3367 : 12602 : case COMPLEX_CST:
3368 : 12602 : return real_minus_onep (TREE_REALPART (expr))
3369 : 14974 : && real_zerop (TREE_IMAGPART (expr));
3370 : 60842 : case VECTOR_CST:
3371 : 60842 : return (VECTOR_CST_NPATTERNS (expr) == 1
3372 : 52110 : && VECTOR_CST_DUPLICATE_P (expr)
3373 : 104058 : && real_minus_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3374 : : default:
3375 : : return false;
3376 : : }
3377 : : }
3378 : :
3379 : : /* Return true if T could be a floating point zero. */
3380 : :
3381 : : bool
3382 : 686905 : real_maybe_zerop (const_tree expr)
3383 : : {
3384 : 686905 : switch (TREE_CODE (expr))
3385 : : {
3386 : 471542 : case REAL_CST:
3387 : : /* Can't use real_zerop here, as it always returns false for decimal
3388 : : floats. And can't use TREE_REAL_CST (expr).cl == rvc_zero
3389 : : either, as decimal zeros are rvc_normal. */
3390 : 471542 : return real_equal (&TREE_REAL_CST (expr), &dconst0);
3391 : 0 : case COMPLEX_CST:
3392 : 0 : return (real_maybe_zerop (TREE_REALPART (expr))
3393 : 0 : || real_maybe_zerop (TREE_IMAGPART (expr)));
3394 : 0 : case VECTOR_CST:
3395 : 0 : {
3396 : 0 : unsigned count = vector_cst_encoded_nelts (expr);
3397 : 0 : for (unsigned int i = 0; i < count; ++i)
3398 : 0 : if (real_maybe_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3399 : : return true;
3400 : : return false;
3401 : : }
3402 : : default:
3403 : : /* Perhaps for SSA_NAMEs we could query frange. */
3404 : : return true;
3405 : : }
3406 : : }
3407 : :
3408 : : /* True if EXP is a constant or a cast of a constant. */
3409 : :
3410 : : bool
3411 : 3680 : really_constant_p (const_tree exp)
3412 : : {
3413 : : /* This is not quite the same as STRIP_NOPS. It does more. */
3414 : 7368 : while (CONVERT_EXPR_P (exp)
3415 : 7420 : || TREE_CODE (exp) == NON_LVALUE_EXPR)
3416 : 60 : exp = TREE_OPERAND (exp, 0);
3417 : 3680 : return TREE_CONSTANT (exp);
3418 : : }
3419 : :
3420 : : /* Return true if T holds a polynomial pointer difference, storing it in
3421 : : *VALUE if so. A true return means that T's precision is no greater
3422 : : than 64 bits, which is the largest address space we support, so *VALUE
3423 : : never loses precision. However, the signedness of the result does
3424 : : not necessarily match the signedness of T: sometimes an unsigned type
3425 : : like sizetype is used to encode a value that is actually negative. */
3426 : :
3427 : : bool
3428 : 10885942 : ptrdiff_tree_p (const_tree t, poly_int64 *value)
3429 : : {
3430 : 10885942 : if (!t)
3431 : : return false;
3432 : 10885942 : if (TREE_CODE (t) == INTEGER_CST)
3433 : : {
3434 : 3012800 : if (!cst_and_fits_in_hwi (t))
3435 : : return false;
3436 : 3012034 : *value = int_cst_value (t);
3437 : 3012034 : return true;
3438 : : }
3439 : : if (POLY_INT_CST_P (t))
3440 : : {
3441 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3442 : : if (!cst_and_fits_in_hwi (POLY_INT_CST_COEFF (t, i)))
3443 : : return false;
3444 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3445 : : value->coeffs[i] = int_cst_value (POLY_INT_CST_COEFF (t, i));
3446 : : return true;
3447 : : }
3448 : : return false;
3449 : : }
3450 : :
3451 : : poly_int64
3452 : 424655633 : tree_to_poly_int64 (const_tree t)
3453 : : {
3454 : 424655633 : gcc_assert (tree_fits_poly_int64_p (t));
3455 : 424655633 : if (POLY_INT_CST_P (t))
3456 : : return poly_int_cst_value (t).force_shwi ();
3457 : 424655633 : return TREE_INT_CST_LOW (t);
3458 : : }
3459 : :
3460 : : poly_uint64
3461 : 471966397 : tree_to_poly_uint64 (const_tree t)
3462 : : {
3463 : 471966397 : gcc_assert (tree_fits_poly_uint64_p (t));
3464 : 471966397 : if (POLY_INT_CST_P (t))
3465 : : return poly_int_cst_value (t).force_uhwi ();
3466 : 471966397 : return TREE_INT_CST_LOW (t);
3467 : : }
3468 : :
3469 : : /* Return first list element whose TREE_VALUE is ELEM.
3470 : : Return 0 if ELEM is not in LIST. */
3471 : :
3472 : : tree
3473 : 7749851 : value_member (tree elem, tree list)
3474 : : {
3475 : 22690445 : while (list)
3476 : : {
3477 : 19736853 : if (elem == TREE_VALUE (list))
3478 : : return list;
3479 : 14940594 : list = TREE_CHAIN (list);
3480 : : }
3481 : : return NULL_TREE;
3482 : : }
3483 : :
3484 : : /* Return first list element whose TREE_PURPOSE is ELEM.
3485 : : Return 0 if ELEM is not in LIST. */
3486 : :
3487 : : tree
3488 : 143807387 : purpose_member (const_tree elem, tree list)
3489 : : {
3490 : 325471441 : while (list)
3491 : : {
3492 : 195924034 : if (elem == TREE_PURPOSE (list))
3493 : : return list;
3494 : 181664054 : list = TREE_CHAIN (list);
3495 : : }
3496 : : return NULL_TREE;
3497 : : }
3498 : :
3499 : : /* Return true if ELEM is in V. */
3500 : :
3501 : : bool
3502 : 1948199 : vec_member (const_tree elem, vec<tree, va_gc> *v)
3503 : : {
3504 : 1948199 : unsigned ix;
3505 : 1948199 : tree t;
3506 : 3534722 : FOR_EACH_VEC_SAFE_ELT (v, ix, t)
3507 : 1589464 : if (elem == t)
3508 : : return true;
3509 : : return false;
3510 : : }
3511 : :
3512 : : /* Returns element number IDX (zero-origin) of chain CHAIN, or
3513 : : NULL_TREE. */
3514 : :
3515 : : tree
3516 : 17961929 : chain_index (int idx, tree chain)
3517 : : {
3518 : 22979375 : for (; chain && idx > 0; --idx)
3519 : 5017446 : chain = TREE_CHAIN (chain);
3520 : 17961929 : return chain;
3521 : : }
3522 : :
3523 : : /* Return true if ELEM is part of the chain CHAIN. */
3524 : :
3525 : : bool
3526 : 181177 : chain_member (const_tree elem, const_tree chain)
3527 : : {
3528 : 351530 : while (chain)
3529 : : {
3530 : 350222 : if (elem == chain)
3531 : : return true;
3532 : 170353 : chain = DECL_CHAIN (chain);
3533 : : }
3534 : :
3535 : : return false;
3536 : : }
3537 : :
3538 : : /* Return the length of a chain of nodes chained through TREE_CHAIN.
3539 : : We expect a null pointer to mark the end of the chain.
3540 : : This is the Lisp primitive `length'. */
3541 : :
3542 : : int
3543 : 1935158099 : list_length (const_tree t)
3544 : : {
3545 : 1935158099 : const_tree p = t;
3546 : : #ifdef ENABLE_TREE_CHECKING
3547 : 1935158099 : const_tree q = t;
3548 : : #endif
3549 : 1935158099 : int len = 0;
3550 : :
3551 : 3054242844 : while (p)
3552 : : {
3553 : 1119084745 : p = TREE_CHAIN (p);
3554 : : #ifdef ENABLE_TREE_CHECKING
3555 : 1119084745 : if (len % 2)
3556 : 361293296 : q = TREE_CHAIN (q);
3557 : 1119084745 : gcc_assert (p != q);
3558 : : #endif
3559 : 1119084745 : len++;
3560 : : }
3561 : :
3562 : 1935158099 : return len;
3563 : : }
3564 : :
3565 : : /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3566 : : UNION_TYPE TYPE, or NULL_TREE if none. */
3567 : :
3568 : : tree
3569 : 64750 : first_field (const_tree type)
3570 : : {
3571 : 64750 : tree t = TYPE_FIELDS (type);
3572 : 3069396 : while (t && TREE_CODE (t) != FIELD_DECL)
3573 : 3004646 : t = TREE_CHAIN (t);
3574 : 64750 : return t;
3575 : : }
3576 : :
3577 : : /* Returns the last FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3578 : : UNION_TYPE TYPE, or NULL_TREE if none. */
3579 : :
3580 : : tree
3581 : 2729052 : last_field (const_tree type)
3582 : : {
3583 : 2729052 : tree last = NULL_TREE;
3584 : :
3585 : 60378154 : for (tree fld = TYPE_FIELDS (type); fld; fld = TREE_CHAIN (fld))
3586 : : {
3587 : 57649102 : if (TREE_CODE (fld) != FIELD_DECL)
3588 : 49229526 : continue;
3589 : :
3590 : : last = fld;
3591 : : }
3592 : :
3593 : 2729052 : return last;
3594 : : }
3595 : :
3596 : : /* Concatenate two chains of nodes (chained through TREE_CHAIN)
3597 : : by modifying the last node in chain 1 to point to chain 2.
3598 : : This is the Lisp primitive `nconc'. */
3599 : :
3600 : : tree
3601 : 3907240445 : chainon (tree op1, tree op2)
3602 : : {
3603 : 3907240445 : tree t1;
3604 : :
3605 : 3907240445 : if (!op1)
3606 : : return op2;
3607 : 698793679 : if (!op2)
3608 : : return op1;
3609 : :
3610 : 1445073944 : for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
3611 : 819640658 : continue;
3612 : 625433286 : TREE_CHAIN (t1) = op2;
3613 : :
3614 : : #ifdef ENABLE_TREE_CHECKING
3615 : 625433286 : {
3616 : 625433286 : tree t2;
3617 : 1635747291 : for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
3618 : 1010314005 : gcc_assert (t2 != t1);
3619 : : }
3620 : : #endif
3621 : :
3622 : : return op1;
3623 : 819640658 : }
3624 : :
3625 : : /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
3626 : :
3627 : : tree
3628 : 91031912 : tree_last (tree chain)
3629 : : {
3630 : 91031912 : tree next;
3631 : 91031912 : if (chain)
3632 : 171091266 : while ((next = TREE_CHAIN (chain)))
3633 : : chain = next;
3634 : 91031912 : return chain;
3635 : : }
3636 : :
3637 : : /* Reverse the order of elements in the chain T,
3638 : : and return the new head of the chain (old last element). */
3639 : :
3640 : : tree
3641 : 1317688823 : nreverse (tree t)
3642 : : {
3643 : 1317688823 : tree prev = 0, decl, next;
3644 : 3387802045 : for (decl = t; decl; decl = next)
3645 : : {
3646 : : /* We shouldn't be using this function to reverse BLOCK chains; we
3647 : : have blocks_nreverse for that. */
3648 : 2070113222 : gcc_checking_assert (TREE_CODE (decl) != BLOCK);
3649 : 2070113222 : next = TREE_CHAIN (decl);
3650 : 2070113222 : TREE_CHAIN (decl) = prev;
3651 : 2070113222 : prev = decl;
3652 : : }
3653 : 1317688823 : return prev;
3654 : : }
3655 : :
3656 : : /* Return a newly created TREE_LIST node whose
3657 : : purpose and value fields are PARM and VALUE. */
3658 : :
3659 : : tree
3660 : 1227737708 : build_tree_list (tree parm, tree value MEM_STAT_DECL)
3661 : : {
3662 : 1227737708 : tree t = make_node (TREE_LIST PASS_MEM_STAT);
3663 : 1227737708 : TREE_PURPOSE (t) = parm;
3664 : 1227737708 : TREE_VALUE (t) = value;
3665 : 1227737708 : return t;
3666 : : }
3667 : :
3668 : : /* Build a chain of TREE_LIST nodes from a vector. */
3669 : :
3670 : : tree
3671 : 82564234 : build_tree_list_vec (const vec<tree, va_gc> *vec MEM_STAT_DECL)
3672 : : {
3673 : 82564234 : tree ret = NULL_TREE;
3674 : 82564234 : tree *pp = &ret;
3675 : 82564234 : unsigned int i;
3676 : 82564234 : tree t;
3677 : 174073518 : FOR_EACH_VEC_SAFE_ELT (vec, i, t)
3678 : : {
3679 : 91509284 : *pp = build_tree_list (NULL, t PASS_MEM_STAT);
3680 : 91509284 : pp = &TREE_CHAIN (*pp);
3681 : : }
3682 : 82564234 : return ret;
3683 : : }
3684 : :
3685 : : /* Return a newly created TREE_LIST node whose
3686 : : purpose and value fields are PURPOSE and VALUE
3687 : : and whose TREE_CHAIN is CHAIN. */
3688 : :
3689 : : tree
3690 : 4983782286 : tree_cons (tree purpose, tree value, tree chain MEM_STAT_DECL)
3691 : : {
3692 : 4983782286 : tree node;
3693 : :
3694 : 4983782286 : node = ggc_alloc_tree_node_stat (sizeof (struct tree_list) PASS_MEM_STAT);
3695 : 4983782286 : memset (node, 0, sizeof (struct tree_common));
3696 : :
3697 : 4983782286 : record_node_allocation_statistics (TREE_LIST, sizeof (struct tree_list));
3698 : :
3699 : 4983782286 : TREE_SET_CODE (node, TREE_LIST);
3700 : 4983782286 : TREE_CHAIN (node) = chain;
3701 : 4983782286 : TREE_PURPOSE (node) = purpose;
3702 : 4983782286 : TREE_VALUE (node) = value;
3703 : 4983782286 : return node;
3704 : : }
3705 : :
3706 : : /* Return the values of the elements of a CONSTRUCTOR as a vector of
3707 : : trees. */
3708 : :
3709 : : vec<tree, va_gc> *
3710 : 0 : ctor_to_vec (tree ctor)
3711 : : {
3712 : 0 : vec<tree, va_gc> *vec;
3713 : 0 : vec_alloc (vec, CONSTRUCTOR_NELTS (ctor));
3714 : 0 : unsigned int ix;
3715 : 0 : tree val;
3716 : :
3717 : 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val)
3718 : 0 : vec->quick_push (val);
3719 : :
3720 : 0 : return vec;
3721 : : }
3722 : :
3723 : : /* Return the size nominally occupied by an object of type TYPE
3724 : : when it resides in memory. The value is measured in units of bytes,
3725 : : and its data type is that normally used for type sizes
3726 : : (which is the first type created by make_signed_type or
3727 : : make_unsigned_type). */
3728 : :
3729 : : tree
3730 : 26094659 : size_in_bytes_loc (location_t loc, const_tree type)
3731 : : {
3732 : 26094659 : tree t;
3733 : :
3734 : 26094659 : if (type == error_mark_node)
3735 : 0 : return integer_zero_node;
3736 : :
3737 : 26094659 : type = TYPE_MAIN_VARIANT (type);
3738 : 26094659 : t = TYPE_SIZE_UNIT (type);
3739 : :
3740 : 26094659 : if (t == 0)
3741 : : {
3742 : 56 : lang_hooks.types.incomplete_type_error (loc, NULL_TREE, type);
3743 : 56 : return size_zero_node;
3744 : : }
3745 : :
3746 : : return t;
3747 : : }
3748 : :
3749 : : /* Return the size of TYPE (in bytes) as a wide integer
3750 : : or return -1 if the size can vary or is larger than an integer. */
3751 : :
3752 : : HOST_WIDE_INT
3753 : 495462023 : int_size_in_bytes (const_tree type)
3754 : : {
3755 : 495462023 : tree t;
3756 : :
3757 : 495462023 : if (type == error_mark_node)
3758 : : return 0;
3759 : :
3760 : 495462023 : type = TYPE_MAIN_VARIANT (type);
3761 : 495462023 : t = TYPE_SIZE_UNIT (type);
3762 : :
3763 : 495462023 : if (t && tree_fits_uhwi_p (t))
3764 : 495410549 : return TREE_INT_CST_LOW (t);
3765 : : else
3766 : : return -1;
3767 : : }
3768 : :
3769 : : /* Return the maximum size of TYPE (in bytes) as a wide integer
3770 : : or return -1 if the size can vary or is larger than an integer. */
3771 : :
3772 : : HOST_WIDE_INT
3773 : 9125 : max_int_size_in_bytes (const_tree type)
3774 : : {
3775 : 9125 : HOST_WIDE_INT size = -1;
3776 : 9125 : tree size_tree;
3777 : :
3778 : : /* If this is an array type, check for a possible MAX_SIZE attached. */
3779 : :
3780 : 9125 : if (TREE_CODE (type) == ARRAY_TYPE)
3781 : : {
3782 : 8408 : size_tree = TYPE_ARRAY_MAX_SIZE (type);
3783 : :
3784 : 8408 : if (size_tree && tree_fits_uhwi_p (size_tree))
3785 : 0 : size = tree_to_uhwi (size_tree);
3786 : : }
3787 : :
3788 : : /* If we still haven't been able to get a size, see if the language
3789 : : can compute a maximum size. */
3790 : :
3791 : 0 : if (size == -1)
3792 : : {
3793 : 9125 : size_tree = lang_hooks.types.max_size (type);
3794 : :
3795 : 9125 : if (size_tree && tree_fits_uhwi_p (size_tree))
3796 : 0 : size = tree_to_uhwi (size_tree);
3797 : : }
3798 : :
3799 : 9125 : return size;
3800 : : }
3801 : :
3802 : : /* Return the bit position of FIELD, in bits from the start of the record.
3803 : : This is a tree of type bitsizetype. */
3804 : :
3805 : : tree
3806 : 100035381 : bit_position (const_tree field)
3807 : : {
3808 : 100035381 : return bit_from_pos (DECL_FIELD_OFFSET (field),
3809 : 100035381 : DECL_FIELD_BIT_OFFSET (field));
3810 : : }
3811 : :
3812 : : /* Return the byte position of FIELD, in bytes from the start of the record.
3813 : : This is a tree of type sizetype. */
3814 : :
3815 : : tree
3816 : 101393645 : byte_position (const_tree field)
3817 : : {
3818 : 101393645 : return byte_from_pos (DECL_FIELD_OFFSET (field),
3819 : 101393645 : DECL_FIELD_BIT_OFFSET (field));
3820 : : }
3821 : :
3822 : : /* Likewise, but return as an integer. It must be representable in
3823 : : that way (since it could be a signed value, we don't have the
3824 : : option of returning -1 like int_size_in_byte can. */
3825 : :
3826 : : HOST_WIDE_INT
3827 : 9761188 : int_byte_position (const_tree field)
3828 : : {
3829 : 9761188 : return tree_to_shwi (byte_position (field));
3830 : : }
3831 : :
3832 : : /* Return, as a tree node, the number of elements for TYPE (which is an
3833 : : ARRAY_TYPE) minus one. This counts only elements of the top array. */
3834 : :
3835 : : tree
3836 : 79744735 : array_type_nelts_minus_one (const_tree type)
3837 : : {
3838 : 79744735 : tree index_type, min, max;
3839 : :
3840 : : /* If they did it with unspecified bounds, then we should have already
3841 : : given an error about it before we got here. */
3842 : 79744735 : if (! TYPE_DOMAIN (type))
3843 : 5802534 : return error_mark_node;
3844 : :
3845 : 73942201 : index_type = TYPE_DOMAIN (type);
3846 : 73942201 : min = TYPE_MIN_VALUE (index_type);
3847 : 73942201 : max = TYPE_MAX_VALUE (index_type);
3848 : :
3849 : : /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
3850 : 73942201 : if (!max)
3851 : : {
3852 : : /* zero sized arrays are represented from C FE as complete types with
3853 : : NULL TYPE_MAX_VALUE and zero TYPE_SIZE, while C++ FE represents
3854 : : them as min 0, max -1. */
3855 : 1248360 : if (COMPLETE_TYPE_P (type)
3856 : 3127 : && integer_zerop (TYPE_SIZE (type))
3857 : 1251487 : && integer_zerop (min))
3858 : 3127 : return build_int_cst (TREE_TYPE (min), -1);
3859 : :
3860 : 1245233 : return error_mark_node;
3861 : : }
3862 : :
3863 : 72693841 : return (integer_zerop (min)
3864 : 72693841 : ? max
3865 : 1091490 : : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
3866 : : }
3867 : :
3868 : : /* Return, as an INTEGER_CST node, the number of elements for TYPE
3869 : : (which is an ARRAY_TYPE). This counts only elements of the top
3870 : : array. */
3871 : :
3872 : : tree
3873 : 5363696 : array_type_nelts_top (tree type)
3874 : : {
3875 : 5363696 : return fold_build2_loc (input_location,
3876 : : PLUS_EXPR, sizetype,
3877 : : array_type_nelts_minus_one (type),
3878 : 5363696 : size_one_node);
3879 : : }
3880 : :
3881 : : /* If arg is static -- a reference to an object in static storage -- then
3882 : : return the object. This is not the same as the C meaning of `static'.
3883 : : If arg isn't static, return NULL. */
3884 : :
3885 : : tree
3886 : 1043342557 : staticp (tree arg)
3887 : : {
3888 : 1044255213 : switch (TREE_CODE (arg))
3889 : : {
3890 : : case FUNCTION_DECL:
3891 : : /* Nested functions are static, even though taking their address will
3892 : : involve a trampoline as we unnest the nested function and create
3893 : : the trampoline on the tree level. */
3894 : : return arg;
3895 : :
3896 : 659661613 : case VAR_DECL:
3897 : 524575195 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3898 : 179331061 : && ! DECL_THREAD_LOCAL_P (arg)
3899 : 177524696 : && ! DECL_DLLIMPORT_P (arg)
3900 : 659661613 : ? arg : NULL);
3901 : :
3902 : 586266 : case CONST_DECL:
3903 : 60 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3904 : 586266 : ? arg : NULL);
3905 : :
3906 : 0 : case CONSTRUCTOR:
3907 : 0 : return TREE_STATIC (arg) ? arg : NULL;
3908 : :
3909 : : case LABEL_DECL:
3910 : : case STRING_CST:
3911 : : return arg;
3912 : :
3913 : 668526 : case COMPONENT_REF:
3914 : : /* If the thing being referenced is not a field, then it is
3915 : : something language specific. */
3916 : 668526 : gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL);
3917 : :
3918 : : /* If we are referencing a bitfield, we can't evaluate an
3919 : : ADDR_EXPR at compile time and so it isn't a constant. */
3920 : 668526 : if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
3921 : : return NULL;
3922 : :
3923 : 668526 : return staticp (TREE_OPERAND (arg, 0));
3924 : :
3925 : : case BIT_FIELD_REF:
3926 : : return NULL;
3927 : :
3928 : 65627 : case INDIRECT_REF:
3929 : 65627 : return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
3930 : :
3931 : 244217 : case ARRAY_REF:
3932 : 244217 : case ARRAY_RANGE_REF:
3933 : 244217 : if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
3934 : 244217 : && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
3935 : 243874 : return staticp (TREE_OPERAND (arg, 0));
3936 : : else
3937 : : return NULL;
3938 : :
3939 : 256 : case REALPART_EXPR:
3940 : 256 : case IMAGPART_EXPR:
3941 : 256 : return staticp (TREE_OPERAND (arg, 0));
3942 : :
3943 : 934 : case COMPOUND_LITERAL_EXPR:
3944 : 934 : return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;
3945 : :
3946 : : default:
3947 : : return NULL;
3948 : : }
3949 : : }
3950 : :
3951 : :
3952 : :
3953 : :
3954 : : /* Return whether OP is a DECL whose address is function-invariant. */
3955 : :
3956 : : bool
3957 : 5114590104 : decl_address_invariant_p (const_tree op)
3958 : : {
3959 : : /* The conditions below are slightly less strict than the one in
3960 : : staticp. */
3961 : :
3962 : 5114590104 : switch (TREE_CODE (op))
3963 : : {
3964 : : case PARM_DECL:
3965 : : case RESULT_DECL:
3966 : : case LABEL_DECL:
3967 : : case FUNCTION_DECL:
3968 : : return true;
3969 : :
3970 : 2847736169 : case VAR_DECL:
3971 : 2162342553 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3972 : 2036630243 : || DECL_THREAD_LOCAL_P (op)
3973 : 2036630243 : || DECL_CONTEXT (op) == current_function_decl
3974 : 2855113852 : || decl_function_context (op) == current_function_decl)
3975 : 2840358486 : return true;
3976 : : break;
3977 : :
3978 : 25287891 : case CONST_DECL:
3979 : 0 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3980 : 25287891 : || decl_function_context (op) == current_function_decl)
3981 : 25287891 : return true;
3982 : : break;
3983 : :
3984 : : default:
3985 : : break;
3986 : : }
3987 : :
3988 : : return false;
3989 : : }
3990 : :
3991 : : /* Return whether OP is a DECL whose address is interprocedural-invariant. */
3992 : :
3993 : : bool
3994 : 1721432 : decl_address_ip_invariant_p (const_tree op)
3995 : : {
3996 : : /* The conditions below are slightly less strict than the one in
3997 : : staticp. */
3998 : :
3999 : 1721432 : switch (TREE_CODE (op))
4000 : : {
4001 : : case LABEL_DECL:
4002 : : case FUNCTION_DECL:
4003 : : case STRING_CST:
4004 : : return true;
4005 : :
4006 : 1552556 : case VAR_DECL:
4007 : 1133656 : if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
4008 : 452328 : && !DECL_DLLIMPORT_P (op))
4009 : 2652784 : || DECL_THREAD_LOCAL_P (op))
4010 : 452328 : return true;
4011 : : break;
4012 : :
4013 : 52116 : case CONST_DECL:
4014 : 52116 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
4015 : : return true;
4016 : : break;
4017 : :
4018 : : default:
4019 : : break;
4020 : : }
4021 : :
4022 : : return false;
4023 : : }
4024 : :
4025 : : /* Return true if T is an object with invariant address. */
4026 : :
4027 : : bool
4028 : 48362 : address_invariant_p (tree t)
4029 : : {
4030 : 54985 : while (handled_component_p (t))
4031 : : {
4032 : 7528 : switch (TREE_CODE (t))
4033 : : {
4034 : 1380 : case ARRAY_REF:
4035 : 1380 : case ARRAY_RANGE_REF:
4036 : 1380 : if (!tree_invariant_p (TREE_OPERAND (t, 1))
4037 : 475 : || TREE_OPERAND (t, 2) != NULL_TREE
4038 : 1855 : || TREE_OPERAND (t, 3) != NULL_TREE)
4039 : : return false;
4040 : : break;
4041 : :
4042 : 6001 : case COMPONENT_REF:
4043 : 6001 : if (TREE_OPERAND (t, 2) != NULL_TREE)
4044 : : return false;
4045 : : break;
4046 : :
4047 : : default:
4048 : : break;
4049 : : }
4050 : 6623 : t = TREE_OPERAND (t, 0);
4051 : : }
4052 : :
4053 : 47457 : STRIP_ANY_LOCATION_WRAPPER (t);
4054 : 47457 : return CONSTANT_CLASS_P (t) || decl_address_invariant_p (t);
4055 : : }
4056 : :
4057 : :
4058 : : /* Return true if T is function-invariant (internal function, does
4059 : : not handle arithmetic; that's handled in skip_simple_arithmetic and
4060 : : tree_invariant_p). */
4061 : :
4062 : : static bool
4063 : 14623369 : tree_invariant_p_1 (tree t)
4064 : : {
4065 : 14623369 : if (TREE_CONSTANT (t) || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
4066 : : return true;
4067 : :
4068 : 12608748 : switch (TREE_CODE (t))
4069 : : {
4070 : : case SAVE_EXPR:
4071 : : case TARGET_EXPR:
4072 : : return true;
4073 : :
4074 : 48322 : case ADDR_EXPR:
4075 : 48322 : return address_invariant_p (TREE_OPERAND (t, 0));
4076 : :
4077 : : default:
4078 : : break;
4079 : : }
4080 : :
4081 : : return false;
4082 : : }
4083 : :
4084 : : /* Return true if T is function-invariant. */
4085 : :
4086 : : bool
4087 : 11771164 : tree_invariant_p (tree t)
4088 : : {
4089 : 11771164 : tree inner = skip_simple_arithmetic (t);
4090 : 11771164 : return tree_invariant_p_1 (inner);
4091 : : }
4092 : :
4093 : : /* Wrap a SAVE_EXPR around EXPR, if appropriate.
4094 : : Do this to any expression which may be used in more than one place,
4095 : : but must be evaluated only once.
4096 : :
4097 : : Normally, expand_expr would reevaluate the expression each time.
4098 : : Calling save_expr produces something that is evaluated and recorded
4099 : : the first time expand_expr is called on it. Subsequent calls to
4100 : : expand_expr just reuse the recorded value.
4101 : :
4102 : : The call to expand_expr that generates code that actually computes
4103 : : the value is the first call *at compile time*. Subsequent calls
4104 : : *at compile time* generate code to use the saved value.
4105 : : This produces correct result provided that *at run time* control
4106 : : always flows through the insns made by the first expand_expr
4107 : : before reaching the other places where the save_expr was evaluated.
4108 : : You, the caller of save_expr, must make sure this is so.
4109 : :
4110 : : Constants, and certain read-only nodes, are returned with no
4111 : : SAVE_EXPR because that is safe. Expressions containing placeholders
4112 : : are not touched; see tree.def for an explanation of what these
4113 : : are used for. */
4114 : :
4115 : : tree
4116 : 2852216 : save_expr (tree expr)
4117 : : {
4118 : 2852216 : tree inner;
4119 : :
4120 : : /* If the tree evaluates to a constant, then we don't want to hide that
4121 : : fact (i.e. this allows further folding, and direct checks for constants).
4122 : : However, a read-only object that has side effects cannot be bypassed.
4123 : : Since it is no problem to reevaluate literals, we just return the
4124 : : literal node. */
4125 : 2852216 : inner = skip_simple_arithmetic (expr);
4126 : 2852216 : if (TREE_CODE (inner) == ERROR_MARK)
4127 : : return inner;
4128 : :
4129 : 2852205 : if (tree_invariant_p_1 (inner))
4130 : : return expr;
4131 : :
4132 : : /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
4133 : : it means that the size or offset of some field of an object depends on
4134 : : the value within another field.
4135 : :
4136 : : Note that it must not be the case that EXPR contains both a PLACEHOLDER_EXPR
4137 : : and some variable since it would then need to be both evaluated once and
4138 : : evaluated more than once. Front-ends must assure this case cannot
4139 : : happen by surrounding any such subexpressions in their own SAVE_EXPR
4140 : : and forcing evaluation at the proper time. */
4141 : 2049410 : if (contains_placeholder_p (inner))
4142 : : return expr;
4143 : :
4144 : 2049410 : expr = build1_loc (EXPR_LOCATION (expr), SAVE_EXPR, TREE_TYPE (expr), expr);
4145 : :
4146 : : /* This expression might be placed ahead of a jump to ensure that the
4147 : : value was computed on both sides of the jump. So make sure it isn't
4148 : : eliminated as dead. */
4149 : 2049410 : TREE_SIDE_EFFECTS (expr) = 1;
4150 : 2049410 : return expr;
4151 : : }
4152 : :
4153 : : /* Look inside EXPR into any simple arithmetic operations. Return the
4154 : : outermost non-arithmetic or non-invariant node. */
4155 : :
4156 : : tree
4157 : 14623380 : skip_simple_arithmetic (tree expr)
4158 : : {
4159 : : /* We don't care about whether this can be used as an lvalue in this
4160 : : context. */
4161 : 14633795 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4162 : 10415 : expr = TREE_OPERAND (expr, 0);
4163 : :
4164 : : /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
4165 : : a constant, it will be more efficient to not make another SAVE_EXPR since
4166 : : it will allow better simplification and GCSE will be able to merge the
4167 : : computations if they actually occur. */
4168 : 38642300 : while (true)
4169 : : {
4170 : 38642300 : if (UNARY_CLASS_P (expr))
4171 : 14869522 : expr = TREE_OPERAND (expr, 0);
4172 : 23772778 : else if (BINARY_CLASS_P (expr))
4173 : : {
4174 : : /* Before commutative binary operands are canonicalized,
4175 : : it is quite common to have constants in the first operand.
4176 : : Check for that common case first so that we don't walk
4177 : : large expressions with tree_invariant_p unnecessarily.
4178 : : This can still have terrible compile time complexity,
4179 : : we should limit the depth of the tree_invariant_p and
4180 : : skip_simple_arithmetic recursion. */
4181 : 9215635 : if ((TREE_CONSTANT (TREE_OPERAND (expr, 0))
4182 : 9205562 : || (TREE_READONLY (TREE_OPERAND (expr, 0))
4183 : 9952 : && !TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0))))
4184 : 9225551 : && tree_invariant_p (TREE_OPERAND (expr, 0)))
4185 : 19989 : expr = TREE_OPERAND (expr, 1);
4186 : 9195646 : else if (tree_invariant_p (TREE_OPERAND (expr, 1)))
4187 : 9119929 : expr = TREE_OPERAND (expr, 0);
4188 : 75717 : else if (tree_invariant_p (TREE_OPERAND (expr, 0)))
4189 : 9480 : expr = TREE_OPERAND (expr, 1);
4190 : : else
4191 : : break;
4192 : : }
4193 : : else
4194 : : break;
4195 : : }
4196 : :
4197 : 14623380 : return expr;
4198 : : }
4199 : :
4200 : : /* Look inside EXPR into simple arithmetic operations involving constants.
4201 : : Return the outermost non-arithmetic or non-constant node. */
4202 : :
4203 : : tree
4204 : 0 : skip_simple_constant_arithmetic (tree expr)
4205 : : {
4206 : 0 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4207 : 0 : expr = TREE_OPERAND (expr, 0);
4208 : :
4209 : 0 : while (true)
4210 : : {
4211 : 0 : if (UNARY_CLASS_P (expr))
4212 : 0 : expr = TREE_OPERAND (expr, 0);
4213 : 0 : else if (BINARY_CLASS_P (expr))
4214 : : {
4215 : 0 : if (TREE_CONSTANT (TREE_OPERAND (expr, 1)))
4216 : 0 : expr = TREE_OPERAND (expr, 0);
4217 : 0 : else if (TREE_CONSTANT (TREE_OPERAND (expr, 0)))
4218 : 0 : expr = TREE_OPERAND (expr, 1);
4219 : : else
4220 : : break;
4221 : : }
4222 : : else
4223 : : break;
4224 : : }
4225 : :
4226 : 0 : return expr;
4227 : : }
4228 : :
4229 : : /* Return which tree structure is used by T. */
4230 : :
4231 : : enum tree_node_structure_enum
4232 : 36298957067 : tree_node_structure (const_tree t)
4233 : : {
4234 : 36298957067 : const enum tree_code code = TREE_CODE (t);
4235 : 36298957067 : return tree_node_structure_for_code (code);
4236 : : }
4237 : :
4238 : : /* Set various status flags when building a CALL_EXPR object T. */
4239 : :
4240 : : static void
4241 : 237414544 : process_call_operands (tree t)
4242 : : {
4243 : 237414544 : bool side_effects = TREE_SIDE_EFFECTS (t);
4244 : 237414544 : bool read_only = false;
4245 : 237414544 : int i = call_expr_flags (t);
4246 : :
4247 : : /* Calls have side-effects, except those to const or pure functions. */
4248 : 237414544 : if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
4249 : : side_effects = true;
4250 : : /* Propagate TREE_READONLY of arguments for const functions. */
4251 : 52960324 : if (i & ECF_CONST)
4252 : 51332704 : read_only = true;
4253 : :
4254 : 237414544 : if (!side_effects || read_only)
4255 : 273714765 : for (i = 1; i < TREE_OPERAND_LENGTH (t); i++)
4256 : : {
4257 : 220754945 : tree op = TREE_OPERAND (t, i);
4258 : 220754945 : if (op && TREE_SIDE_EFFECTS (op))
4259 : : side_effects = true;
4260 : 220754945 : if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op))
4261 : : read_only = false;
4262 : : }
4263 : :
4264 : 237414544 : TREE_SIDE_EFFECTS (t) = side_effects;
4265 : 237414544 : TREE_READONLY (t) = read_only;
4266 : 237414544 : }
4267 : :
4268 : : /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
4269 : : size or offset that depends on a field within a record. */
4270 : :
4271 : : bool
4272 : 37902011 : contains_placeholder_p (const_tree exp)
4273 : : {
4274 : 37902011 : enum tree_code code;
4275 : :
4276 : 37902011 : if (!exp)
4277 : : return false;
4278 : :
4279 : 37902011 : code = TREE_CODE (exp);
4280 : 37902011 : if (code == PLACEHOLDER_EXPR)
4281 : : return true;
4282 : :
4283 : 37902011 : switch (TREE_CODE_CLASS (code))
4284 : : {
4285 : 1188239 : case tcc_reference:
4286 : : /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
4287 : : position computations since they will be converted into a
4288 : : WITH_RECORD_EXPR involving the reference, which will assume
4289 : : here will be valid. */
4290 : 1188239 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4291 : :
4292 : 530579 : case tcc_exceptional:
4293 : 530579 : if (code == TREE_LIST)
4294 : 0 : return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
4295 : 0 : || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
4296 : : break;
4297 : :
4298 : 33615148 : case tcc_unary:
4299 : 33615148 : case tcc_binary:
4300 : 33615148 : case tcc_comparison:
4301 : 33615148 : case tcc_expression:
4302 : 33615148 : switch (code)
4303 : : {
4304 : 6350 : case COMPOUND_EXPR:
4305 : : /* Ignoring the first operand isn't quite right, but works best. */
4306 : 6350 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
4307 : :
4308 : 4482 : case COND_EXPR:
4309 : 8964 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4310 : 4482 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
4311 : 8964 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
4312 : :
4313 : : case SAVE_EXPR:
4314 : : /* The save_expr function never wraps anything containing
4315 : : a PLACEHOLDER_EXPR. */
4316 : : return false;
4317 : :
4318 : 24346784 : default:
4319 : 24346784 : break;
4320 : : }
4321 : :
4322 : 24346784 : switch (TREE_CODE_LENGTH (code))
4323 : : {
4324 : 14842310 : case 1:
4325 : 14842310 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4326 : 9477446 : case 2:
4327 : 18953381 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4328 : 18953381 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
4329 : : default:
4330 : : return false;
4331 : : }
4332 : :
4333 : 463895 : case tcc_vl_exp:
4334 : 463895 : switch (code)
4335 : : {
4336 : 463895 : case CALL_EXPR:
4337 : 463895 : {
4338 : 463895 : const_tree arg;
4339 : 463895 : const_call_expr_arg_iterator iter;
4340 : 1530095 : FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
4341 : 602305 : if (CONTAINS_PLACEHOLDER_P (arg))
4342 : : return true;
4343 : : return false;
4344 : : }
4345 : : default:
4346 : : return false;
4347 : : }
4348 : :
4349 : : default:
4350 : : return false;
4351 : : }
4352 : : return false;
4353 : : }
4354 : :
4355 : : /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
4356 : : directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
4357 : : field positions. */
4358 : :
4359 : : static bool
4360 : 780939 : type_contains_placeholder_1 (const_tree type)
4361 : : {
4362 : : /* If the size contains a placeholder or the parent type (component type in
4363 : : the case of arrays) type involves a placeholder, this type does. */
4364 : 1541693 : if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
4365 : 780939 : || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
4366 : 1561878 : || (!POINTER_TYPE_P (type)
4367 : 646044 : && TREE_TYPE (type)
4368 : 106857 : && type_contains_placeholder_p (TREE_TYPE (type))))
4369 : 0 : return true;
4370 : :
4371 : : /* Now do type-specific checks. Note that the last part of the check above
4372 : : greatly limits what we have to do below. */
4373 : 780939 : switch (TREE_CODE (type))
4374 : : {
4375 : : case VOID_TYPE:
4376 : : case OPAQUE_TYPE:
4377 : : case COMPLEX_TYPE:
4378 : : case ENUMERAL_TYPE:
4379 : : case BOOLEAN_TYPE:
4380 : : case POINTER_TYPE:
4381 : : case OFFSET_TYPE:
4382 : : case REFERENCE_TYPE:
4383 : : case METHOD_TYPE:
4384 : : case FUNCTION_TYPE:
4385 : : case VECTOR_TYPE:
4386 : : case NULLPTR_TYPE:
4387 : : return false;
4388 : :
4389 : 169827 : case INTEGER_TYPE:
4390 : 169827 : case BITINT_TYPE:
4391 : 169827 : case REAL_TYPE:
4392 : 169827 : case FIXED_POINT_TYPE:
4393 : : /* Here we just check the bounds. */
4394 : 329967 : return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
4395 : 329967 : || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
4396 : :
4397 : 55840 : case ARRAY_TYPE:
4398 : : /* We have already checked the component type above, so just check
4399 : : the domain type. Flexible array members have a null domain. */
4400 : 111668 : return TYPE_DOMAIN (type) ?
4401 : 55828 : type_contains_placeholder_p (TYPE_DOMAIN (type)) : false;
4402 : :
4403 : 397054 : case RECORD_TYPE:
4404 : 397054 : case UNION_TYPE:
4405 : 397054 : case QUAL_UNION_TYPE:
4406 : 397054 : {
4407 : 397054 : tree field;
4408 : :
4409 : 11699454 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
4410 : 11302400 : if (TREE_CODE (field) == FIELD_DECL
4411 : 11302400 : && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
4412 : 918232 : || (TREE_CODE (type) == QUAL_UNION_TYPE
4413 : 0 : && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
4414 : 918232 : || type_contains_placeholder_p (TREE_TYPE (field))))
4415 : 0 : return true;
4416 : :
4417 : : return false;
4418 : : }
4419 : :
4420 : 0 : default:
4421 : 0 : gcc_unreachable ();
4422 : : }
4423 : : }
4424 : :
4425 : : /* Wrapper around above function used to cache its result. */
4426 : :
4427 : : bool
4428 : 3015184 : type_contains_placeholder_p (tree type)
4429 : : {
4430 : 3015184 : bool result;
4431 : :
4432 : : /* If the contains_placeholder_bits field has been initialized,
4433 : : then we know the answer. */
4434 : 3015184 : if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
4435 : 2234245 : return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
4436 : :
4437 : : /* Indicate that we've seen this type node, and the answer is false.
4438 : : This is what we want to return if we run into recursion via fields. */
4439 : 780939 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
4440 : :
4441 : : /* Compute the real value. */
4442 : 780939 : result = type_contains_placeholder_1 (type);
4443 : :
4444 : : /* Store the real value. */
4445 : 780939 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
4446 : :
4447 : 780939 : return result;
4448 : : }
4449 : :
4450 : : /* Push tree EXP onto vector QUEUE if it is not already present. */
4451 : :
4452 : : static void
4453 : 0 : push_without_duplicates (tree exp, vec<tree> *queue)
4454 : : {
4455 : 0 : unsigned int i;
4456 : 0 : tree iter;
4457 : :
4458 : 0 : FOR_EACH_VEC_ELT (*queue, i, iter)
4459 : 0 : if (simple_cst_equal (iter, exp) == 1)
4460 : : break;
4461 : :
4462 : 0 : if (!iter)
4463 : 0 : queue->safe_push (exp);
4464 : 0 : }
4465 : :
4466 : : /* Given a tree EXP, find all occurrences of references to fields
4467 : : in a PLACEHOLDER_EXPR and place them in vector REFS without
4468 : : duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
4469 : : we assume here that EXP contains only arithmetic expressions
4470 : : or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
4471 : : argument list. */
4472 : :
4473 : : void
4474 : 0 : find_placeholder_in_expr (tree exp, vec<tree> *refs)
4475 : : {
4476 : 0 : enum tree_code code = TREE_CODE (exp);
4477 : 0 : tree inner;
4478 : 0 : int i;
4479 : :
4480 : : /* We handle TREE_LIST and COMPONENT_REF separately. */
4481 : 0 : if (code == TREE_LIST)
4482 : : {
4483 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs);
4484 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs);
4485 : : }
4486 : 0 : else if (code == COMPONENT_REF)
4487 : : {
4488 : 0 : for (inner = TREE_OPERAND (exp, 0);
4489 : 0 : REFERENCE_CLASS_P (inner);
4490 : 0 : inner = TREE_OPERAND (inner, 0))
4491 : : ;
4492 : :
4493 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
4494 : 0 : push_without_duplicates (exp, refs);
4495 : : else
4496 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs);
4497 : : }
4498 : : else
4499 : 0 : switch (TREE_CODE_CLASS (code))
4500 : : {
4501 : : case tcc_constant:
4502 : : break;
4503 : :
4504 : 0 : case tcc_declaration:
4505 : : /* Variables allocated to static storage can stay. */
4506 : 0 : if (!TREE_STATIC (exp))
4507 : 0 : push_without_duplicates (exp, refs);
4508 : : break;
4509 : :
4510 : 0 : case tcc_expression:
4511 : : /* This is the pattern built in ada/make_aligning_type. */
4512 : 0 : if (code == ADDR_EXPR
4513 : 0 : && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR)
4514 : : {
4515 : 0 : push_without_duplicates (exp, refs);
4516 : 0 : break;
4517 : : }
4518 : :
4519 : : /* Fall through. */
4520 : :
4521 : : case tcc_exceptional:
4522 : : case tcc_unary:
4523 : : case tcc_binary:
4524 : : case tcc_comparison:
4525 : : case tcc_reference:
4526 : 0 : for (i = 0; i < TREE_CODE_LENGTH (code); i++)
4527 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4528 : : break;
4529 : :
4530 : : case tcc_vl_exp:
4531 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4532 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4533 : : break;
4534 : :
4535 : 0 : default:
4536 : 0 : gcc_unreachable ();
4537 : : }
4538 : 0 : }
4539 : :
4540 : : /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
4541 : : return a tree with all occurrences of references to F in a
4542 : : PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
4543 : : CONST_DECLs. Note that we assume here that EXP contains only
4544 : : arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
4545 : : occurring only in their argument list. */
4546 : :
4547 : : tree
4548 : 0 : substitute_in_expr (tree exp, tree f, tree r)
4549 : : {
4550 : 0 : enum tree_code code = TREE_CODE (exp);
4551 : 0 : tree op0, op1, op2, op3;
4552 : 0 : tree new_tree;
4553 : :
4554 : : /* We handle TREE_LIST and COMPONENT_REF separately. */
4555 : 0 : if (code == TREE_LIST)
4556 : : {
4557 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
4558 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
4559 : 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4560 : : return exp;
4561 : :
4562 : 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4563 : : }
4564 : 0 : else if (code == COMPONENT_REF)
4565 : : {
4566 : 0 : tree inner;
4567 : :
4568 : : /* If this expression is getting a value from a PLACEHOLDER_EXPR
4569 : : and it is the right field, replace it with R. */
4570 : 0 : for (inner = TREE_OPERAND (exp, 0);
4571 : 0 : REFERENCE_CLASS_P (inner);
4572 : 0 : inner = TREE_OPERAND (inner, 0))
4573 : : ;
4574 : :
4575 : : /* The field. */
4576 : 0 : op1 = TREE_OPERAND (exp, 1);
4577 : :
4578 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f)
4579 : : return r;
4580 : :
4581 : : /* If this expression hasn't been completed let, leave it alone. */
4582 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner))
4583 : : return exp;
4584 : :
4585 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4586 : 0 : if (op0 == TREE_OPERAND (exp, 0))
4587 : : return exp;
4588 : :
4589 : 0 : new_tree
4590 : 0 : = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE);
4591 : : }
4592 : : else
4593 : 0 : switch (TREE_CODE_CLASS (code))
4594 : : {
4595 : : case tcc_constant:
4596 : : return exp;
4597 : :
4598 : 0 : case tcc_declaration:
4599 : 0 : if (exp == f)
4600 : : return r;
4601 : : else
4602 : : return exp;
4603 : :
4604 : 0 : case tcc_expression:
4605 : 0 : if (exp == f)
4606 : : return r;
4607 : :
4608 : : /* Fall through. */
4609 : :
4610 : 0 : case tcc_exceptional:
4611 : 0 : case tcc_unary:
4612 : 0 : case tcc_binary:
4613 : 0 : case tcc_comparison:
4614 : 0 : case tcc_reference:
4615 : 0 : switch (TREE_CODE_LENGTH (code))
4616 : : {
4617 : : case 0:
4618 : : return exp;
4619 : :
4620 : 0 : case 1:
4621 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4622 : 0 : if (op0 == TREE_OPERAND (exp, 0))
4623 : : return exp;
4624 : :
4625 : 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4626 : 0 : break;
4627 : :
4628 : 0 : case 2:
4629 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4630 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4631 : :
4632 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4633 : : return exp;
4634 : :
4635 : 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4636 : 0 : break;
4637 : :
4638 : 0 : case 3:
4639 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4640 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4641 : 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4642 : :
4643 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4644 : 0 : && op2 == TREE_OPERAND (exp, 2))
4645 : : return exp;
4646 : :
4647 : 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4648 : 0 : break;
4649 : :
4650 : 0 : case 4:
4651 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4652 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4653 : 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4654 : 0 : op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
4655 : :
4656 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4657 : 0 : && op2 == TREE_OPERAND (exp, 2)
4658 : 0 : && op3 == TREE_OPERAND (exp, 3))
4659 : : return exp;
4660 : :
4661 : 0 : new_tree
4662 : 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4663 : 0 : break;
4664 : :
4665 : 0 : default:
4666 : 0 : gcc_unreachable ();
4667 : : }
4668 : : break;
4669 : :
4670 : 0 : case tcc_vl_exp:
4671 : 0 : {
4672 : 0 : int i;
4673 : :
4674 : 0 : new_tree = NULL_TREE;
4675 : :
4676 : : /* If we are trying to replace F with a constant or with another
4677 : : instance of one of the arguments of the call, inline back
4678 : : functions which do nothing else than computing a value from
4679 : : the arguments they are passed. This makes it possible to
4680 : : fold partially or entirely the replacement expression. */
4681 : 0 : if (code == CALL_EXPR)
4682 : : {
4683 : 0 : bool maybe_inline = false;
4684 : 0 : if (CONSTANT_CLASS_P (r))
4685 : : maybe_inline = true;
4686 : : else
4687 : 0 : for (i = 3; i < TREE_OPERAND_LENGTH (exp); i++)
4688 : 0 : if (operand_equal_p (TREE_OPERAND (exp, i), r, 0))
4689 : : {
4690 : : maybe_inline = true;
4691 : : break;
4692 : : }
4693 : 0 : if (maybe_inline)
4694 : : {
4695 : 0 : tree t = maybe_inline_call_in_expr (exp);
4696 : 0 : if (t)
4697 : 0 : return SUBSTITUTE_IN_EXPR (t, f, r);
4698 : : }
4699 : : }
4700 : :
4701 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4702 : : {
4703 : 0 : tree op = TREE_OPERAND (exp, i);
4704 : 0 : tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
4705 : 0 : if (new_op != op)
4706 : : {
4707 : 0 : if (!new_tree)
4708 : 0 : new_tree = copy_node (exp);
4709 : 0 : TREE_OPERAND (new_tree, i) = new_op;
4710 : : }
4711 : : }
4712 : :
4713 : 0 : if (new_tree)
4714 : : {
4715 : 0 : new_tree = fold (new_tree);
4716 : 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4717 : 0 : process_call_operands (new_tree);
4718 : : }
4719 : : else
4720 : : return exp;
4721 : : }
4722 : : break;
4723 : :
4724 : 0 : default:
4725 : 0 : gcc_unreachable ();
4726 : : }
4727 : :
4728 : 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4729 : :
4730 : 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4731 : 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4732 : :
4733 : : return new_tree;
4734 : : }
4735 : :
4736 : : /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
4737 : : for it within OBJ, a tree that is an object or a chain of references. */
4738 : :
4739 : : tree
4740 : 211474 : substitute_placeholder_in_expr (tree exp, tree obj)
4741 : : {
4742 : 211474 : enum tree_code code = TREE_CODE (exp);
4743 : 211474 : tree op0, op1, op2, op3;
4744 : 211474 : tree new_tree;
4745 : :
4746 : : /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
4747 : : in the chain of OBJ. */
4748 : 211474 : if (code == PLACEHOLDER_EXPR)
4749 : : {
4750 : 0 : tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
4751 : 0 : tree elt;
4752 : :
4753 : 0 : for (elt = obj; elt != 0;
4754 : 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4755 : 0 : || TREE_CODE (elt) == COND_EXPR)
4756 : 0 : ? TREE_OPERAND (elt, 1)
4757 : 0 : : (REFERENCE_CLASS_P (elt)
4758 : : || UNARY_CLASS_P (elt)
4759 : : || BINARY_CLASS_P (elt)
4760 : : || VL_EXP_CLASS_P (elt)
4761 : : || EXPRESSION_CLASS_P (elt))
4762 : 0 : ? TREE_OPERAND (elt, 0) : 0))
4763 : 0 : if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
4764 : : return elt;
4765 : :
4766 : 0 : for (elt = obj; elt != 0;
4767 : 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4768 : 0 : || TREE_CODE (elt) == COND_EXPR)
4769 : 0 : ? TREE_OPERAND (elt, 1)
4770 : 0 : : (REFERENCE_CLASS_P (elt)
4771 : : || UNARY_CLASS_P (elt)
4772 : : || BINARY_CLASS_P (elt)
4773 : : || VL_EXP_CLASS_P (elt)
4774 : : || EXPRESSION_CLASS_P (elt))
4775 : 0 : ? TREE_OPERAND (elt, 0) : 0))
4776 : 0 : if (POINTER_TYPE_P (TREE_TYPE (elt))
4777 : 0 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
4778 : : == need_type))
4779 : 0 : return fold_build1 (INDIRECT_REF, need_type, elt);
4780 : :
4781 : : /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
4782 : : survives until RTL generation, there will be an error. */
4783 : : return exp;
4784 : : }
4785 : :
4786 : : /* TREE_LIST is special because we need to look at TREE_VALUE
4787 : : and TREE_CHAIN, not TREE_OPERANDS. */
4788 : 211474 : else if (code == TREE_LIST)
4789 : : {
4790 : 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
4791 : 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
4792 : 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4793 : : return exp;
4794 : :
4795 : 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4796 : : }
4797 : : else
4798 : 211474 : switch (TREE_CODE_CLASS (code))
4799 : : {
4800 : : case tcc_constant:
4801 : : case tcc_declaration:
4802 : : return exp;
4803 : :
4804 : 9509 : case tcc_exceptional:
4805 : 9509 : case tcc_unary:
4806 : 9509 : case tcc_binary:
4807 : 9509 : case tcc_comparison:
4808 : 9509 : case tcc_expression:
4809 : 9509 : case tcc_reference:
4810 : 9509 : case tcc_statement:
4811 : 9509 : switch (TREE_CODE_LENGTH (code))
4812 : : {
4813 : : case 0:
4814 : : return exp;
4815 : :
4816 : 7212 : case 1:
4817 : 7212 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4818 : 7212 : if (op0 == TREE_OPERAND (exp, 0))
4819 : : return exp;
4820 : :
4821 : 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4822 : 0 : break;
4823 : :
4824 : 2285 : case 2:
4825 : 2285 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4826 : 2285 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4827 : :
4828 : 2285 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4829 : : return exp;
4830 : :
4831 : 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4832 : 0 : break;
4833 : :
4834 : 12 : case 3:
4835 : 12 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4836 : 12 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4837 : 12 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4838 : :
4839 : 24 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4840 : 24 : && op2 == TREE_OPERAND (exp, 2))
4841 : : return exp;
4842 : :
4843 : 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4844 : 0 : break;
4845 : :
4846 : 0 : case 4:
4847 : 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4848 : 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4849 : 0 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4850 : 0 : op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
4851 : :
4852 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4853 : 0 : && op2 == TREE_OPERAND (exp, 2)
4854 : 0 : && op3 == TREE_OPERAND (exp, 3))
4855 : : return exp;
4856 : :
4857 : 0 : new_tree
4858 : 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4859 : 0 : break;
4860 : :
4861 : 0 : default:
4862 : 0 : gcc_unreachable ();
4863 : : }
4864 : : break;
4865 : :
4866 : : case tcc_vl_exp:
4867 : : {
4868 : : int i;
4869 : :
4870 : : new_tree = NULL_TREE;
4871 : :
4872 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4873 : : {
4874 : 0 : tree op = TREE_OPERAND (exp, i);
4875 : 0 : tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
4876 : 0 : if (new_op != op)
4877 : : {
4878 : 0 : if (!new_tree)
4879 : 0 : new_tree = copy_node (exp);
4880 : 0 : TREE_OPERAND (new_tree, i) = new_op;
4881 : : }
4882 : : }
4883 : :
4884 : 0 : if (new_tree)
4885 : : {
4886 : 0 : new_tree = fold (new_tree);
4887 : 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4888 : 0 : process_call_operands (new_tree);
4889 : : }
4890 : : else
4891 : : return exp;
4892 : : }
4893 : : break;
4894 : :
4895 : 0 : default:
4896 : 0 : gcc_unreachable ();
4897 : : }
4898 : :
4899 : 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4900 : :
4901 : 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4902 : 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4903 : :
4904 : : return new_tree;
4905 : : }
4906 : :
4907 : :
4908 : : /* Subroutine of stabilize_reference; this is called for subtrees of
4909 : : references. Any expression with side-effects must be put in a SAVE_EXPR
4910 : : to ensure that it is only evaluated once.
4911 : :
4912 : : We don't put SAVE_EXPR nodes around everything, because assigning very
4913 : : simple expressions to temporaries causes us to miss good opportunities
4914 : : for optimizations. Among other things, the opportunity to fold in the
4915 : : addition of a constant into an addressing mode often gets lost, e.g.
4916 : : "y[i+1] += x;". In general, we take the approach that we should not make
4917 : : an assignment unless we are forced into it - i.e., that any non-side effect
4918 : : operator should be allowed, and that cse should take care of coalescing
4919 : : multiple utterances of the same expression should that prove fruitful. */
4920 : :
4921 : : static tree
4922 : 589117 : stabilize_reference_1 (tree e)
4923 : : {
4924 : 589117 : tree result;
4925 : 589117 : enum tree_code code = TREE_CODE (e);
4926 : :
4927 : : /* We cannot ignore const expressions because it might be a reference
4928 : : to a const array but whose index contains side-effects. But we can
4929 : : ignore things that are actual constant or that already have been
4930 : : handled by this function. */
4931 : :
4932 : 589117 : if (tree_invariant_p (e))
4933 : : return e;
4934 : :
4935 : 128131 : switch (TREE_CODE_CLASS (code))
4936 : : {
4937 : 0 : case tcc_exceptional:
4938 : : /* Always wrap STATEMENT_LIST into SAVE_EXPR, even if it doesn't
4939 : : have side-effects. */
4940 : 0 : if (code == STATEMENT_LIST)
4941 : 0 : return save_expr (e);
4942 : : /* FALLTHRU */
4943 : 99352 : case tcc_type:
4944 : 99352 : case tcc_declaration:
4945 : 99352 : case tcc_comparison:
4946 : 99352 : case tcc_statement:
4947 : 99352 : case tcc_expression:
4948 : 99352 : case tcc_reference:
4949 : 99352 : case tcc_vl_exp:
4950 : : /* If the expression has side-effects, then encase it in a SAVE_EXPR
4951 : : so that it will only be evaluated once. */
4952 : : /* The reference (r) and comparison (<) classes could be handled as
4953 : : below, but it is generally faster to only evaluate them once. */
4954 : 99352 : if (TREE_SIDE_EFFECTS (e))
4955 : 977 : return save_expr (e);
4956 : : return e;
4957 : :
4958 : : case tcc_constant:
4959 : : /* Constants need no processing. In fact, we should never reach
4960 : : here. */
4961 : : return e;
4962 : :
4963 : 21462 : case tcc_binary:
4964 : : /* Division is slow and tends to be compiled with jumps,
4965 : : especially the division by powers of 2 that is often
4966 : : found inside of an array reference. So do it just once. */
4967 : 21462 : if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
4968 : 19422 : || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
4969 : 19422 : || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
4970 : 19422 : || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
4971 : 2040 : return save_expr (e);
4972 : : /* Recursively stabilize each operand. */
4973 : 19422 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
4974 : 19422 : stabilize_reference_1 (TREE_OPERAND (e, 1)));
4975 : 19422 : break;
4976 : :
4977 : 7317 : case tcc_unary:
4978 : : /* Recursively stabilize each operand. */
4979 : 7317 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
4980 : 7317 : break;
4981 : :
4982 : 0 : default:
4983 : 0 : gcc_unreachable ();
4984 : : }
4985 : :
4986 : 26739 : TREE_TYPE (result) = TREE_TYPE (e);
4987 : 26739 : TREE_READONLY (result) = TREE_READONLY (e);
4988 : 26739 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
4989 : 26739 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
4990 : :
4991 : 26739 : return result;
4992 : : }
4993 : :
4994 : : /* Stabilize a reference so that we can use it any number of times
4995 : : without causing its operands to be evaluated more than once.
4996 : : Returns the stabilized reference. This works by means of save_expr,
4997 : : so see the caveats in the comments about save_expr.
4998 : :
4999 : : Also allows conversion expressions whose operands are references.
5000 : : Any other kind of expression is returned unchanged. */
5001 : :
5002 : : tree
5003 : 4204093 : stabilize_reference (tree ref)
5004 : : {
5005 : 4204093 : tree result;
5006 : 4204093 : enum tree_code code = TREE_CODE (ref);
5007 : :
5008 : 4204093 : switch (code)
5009 : : {
5010 : : case VAR_DECL:
5011 : : case PARM_DECL:
5012 : : case RESULT_DECL:
5013 : : /* No action is needed in this case. */
5014 : : return ref;
5015 : :
5016 : 0 : CASE_CONVERT:
5017 : 0 : case FLOAT_EXPR:
5018 : 0 : case FIX_TRUNC_EXPR:
5019 : 0 : result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
5020 : 0 : break;
5021 : :
5022 : 496801 : case INDIRECT_REF:
5023 : 496801 : result = build_nt (INDIRECT_REF,
5024 : 496801 : stabilize_reference_1 (TREE_OPERAND (ref, 0)));
5025 : 496801 : break;
5026 : :
5027 : 320579 : case COMPONENT_REF:
5028 : 320579 : result = build_nt (COMPONENT_REF,
5029 : 320579 : stabilize_reference (TREE_OPERAND (ref, 0)),
5030 : 320579 : TREE_OPERAND (ref, 1), NULL_TREE);
5031 : 320579 : break;
5032 : :
5033 : 0 : case BIT_FIELD_REF:
5034 : 0 : result = build_nt (BIT_FIELD_REF,
5035 : 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5036 : 0 : TREE_OPERAND (ref, 1), TREE_OPERAND (ref, 2));
5037 : 0 : REF_REVERSE_STORAGE_ORDER (result) = REF_REVERSE_STORAGE_ORDER (ref);
5038 : 0 : break;
5039 : :
5040 : 46155 : case ARRAY_REF:
5041 : 92310 : result = build_nt (ARRAY_REF,
5042 : 46155 : stabilize_reference (TREE_OPERAND (ref, 0)),
5043 : 46155 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5044 : 46155 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5045 : 46155 : break;
5046 : :
5047 : 0 : case ARRAY_RANGE_REF:
5048 : 0 : result = build_nt (ARRAY_RANGE_REF,
5049 : 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5050 : 0 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5051 : 0 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5052 : 0 : break;
5053 : :
5054 : 0 : case COMPOUND_EXPR:
5055 : : /* We cannot wrap the first expression in a SAVE_EXPR, as then
5056 : : it wouldn't be ignored. This matters when dealing with
5057 : : volatiles. */
5058 : 0 : return stabilize_reference_1 (ref);
5059 : :
5060 : : /* If arg isn't a kind of lvalue we recognize, make no change.
5061 : : Caller should recognize the error for an invalid lvalue. */
5062 : : default:
5063 : : return ref;
5064 : :
5065 : 0 : case ERROR_MARK:
5066 : 0 : return error_mark_node;
5067 : : }
5068 : :
5069 : 863535 : TREE_TYPE (result) = TREE_TYPE (ref);
5070 : 863535 : TREE_READONLY (result) = TREE_READONLY (ref);
5071 : 863535 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
5072 : 863535 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
5073 : 863535 : protected_set_expr_location (result, EXPR_LOCATION (ref));
5074 : :
5075 : 863535 : return result;
5076 : : }
5077 : :
5078 : : /* Low-level constructors for expressions. */
5079 : :
5080 : : /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
5081 : : and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
5082 : :
5083 : : void
5084 : 1232667151 : recompute_tree_invariant_for_addr_expr (tree t)
5085 : : {
5086 : 1232667151 : tree node;
5087 : 1232667151 : bool tc = true, se = false;
5088 : :
5089 : 1232667151 : gcc_assert (TREE_CODE (t) == ADDR_EXPR);
5090 : :
5091 : : /* We started out assuming this address is both invariant and constant, but
5092 : : does not have side effects. Now go down any handled components and see if
5093 : : any of them involve offsets that are either non-constant or non-invariant.
5094 : : Also check for side-effects.
5095 : :
5096 : : ??? Note that this code makes no attempt to deal with the case where
5097 : : taking the address of something causes a copy due to misalignment. */
5098 : :
5099 : : #define UPDATE_FLAGS(NODE) \
5100 : : do { tree _node = (NODE); \
5101 : : if (_node && !TREE_CONSTANT (_node)) tc = false; \
5102 : : if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
5103 : :
5104 : 1440153655 : for (node = TREE_OPERAND (t, 0); handled_component_p (node);
5105 : 207486504 : node = TREE_OPERAND (node, 0))
5106 : : {
5107 : : /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
5108 : : array reference (probably made temporarily by the G++ front end),
5109 : : so ignore all the operands. */
5110 : 207486504 : if ((TREE_CODE (node) == ARRAY_REF
5111 : 207486504 : || TREE_CODE (node) == ARRAY_RANGE_REF)
5112 : 207486504 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
5113 : : {
5114 : 31171035 : UPDATE_FLAGS (TREE_OPERAND (node, 1));
5115 : 31171035 : if (TREE_OPERAND (node, 2))
5116 : 2232594 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5117 : 31171035 : if (TREE_OPERAND (node, 3))
5118 : 268160 : UPDATE_FLAGS (TREE_OPERAND (node, 3));
5119 : : }
5120 : : /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
5121 : : FIELD_DECL, apparently. The G++ front end can put something else
5122 : : there, at least temporarily. */
5123 : 176315469 : else if (TREE_CODE (node) == COMPONENT_REF
5124 : 176315469 : && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
5125 : : {
5126 : 175438433 : if (TREE_OPERAND (node, 2))
5127 : 17033 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5128 : : }
5129 : : }
5130 : :
5131 : 1232667151 : node = lang_hooks.expr_to_decl (node, &tc, &se);
5132 : :
5133 : : /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
5134 : : the address, since &(*a)->b is a form of addition. If it's a constant, the
5135 : : address is constant too. If it's a decl, its address is constant if the
5136 : : decl is static. Everything else is not constant and, furthermore,
5137 : : taking the address of a volatile variable is not volatile. */
5138 : 1232667151 : if (INDIRECT_REF_P (node)
5139 : 1201472359 : || TREE_CODE (node) == MEM_REF)
5140 : 146497912 : UPDATE_FLAGS (TREE_OPERAND (node, 0));
5141 : 1086169239 : else if (CONSTANT_CLASS_P (node))
5142 : : ;
5143 : 1013958839 : else if (DECL_P (node))
5144 : 998039558 : tc &= (staticp (node) != NULL_TREE);
5145 : : else
5146 : : {
5147 : 15919281 : tc = false;
5148 : 15919281 : se |= TREE_SIDE_EFFECTS (node);
5149 : : }
5150 : :
5151 : :
5152 : 1232667151 : TREE_CONSTANT (t) = tc;
5153 : 1232667151 : TREE_SIDE_EFFECTS (t) = se;
5154 : : #undef UPDATE_FLAGS
5155 : 1232667151 : }
5156 : :
5157 : : /* Build an expression of code CODE, data type TYPE, and operands as
5158 : : specified. Expressions and reference nodes can be created this way.
5159 : : Constants, decls, types and misc nodes cannot be.
5160 : :
5161 : : We define 5 non-variadic functions, from 0 to 4 arguments. This is
5162 : : enough for all extant tree codes. */
5163 : :
5164 : : tree
5165 : 330234705 : build0 (enum tree_code code, tree tt MEM_STAT_DECL)
5166 : : {
5167 : 330234705 : tree t;
5168 : :
5169 : 330234705 : gcc_assert (TREE_CODE_LENGTH (code) == 0);
5170 : :
5171 : 330234705 : t = make_node (code PASS_MEM_STAT);
5172 : 330234705 : TREE_TYPE (t) = tt;
5173 : :
5174 : 330234705 : return t;
5175 : : }
5176 : :
5177 : : tree
5178 : 3205544630 : build1 (enum tree_code code, tree type, tree node MEM_STAT_DECL)
5179 : : {
5180 : 3205544630 : int length = sizeof (struct tree_exp);
5181 : 3205544630 : tree t;
5182 : :
5183 : 3205544630 : record_node_allocation_statistics (code, length);
5184 : :
5185 : 3205544630 : gcc_assert (TREE_CODE_LENGTH (code) == 1);
5186 : :
5187 : 3205544630 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
5188 : :
5189 : 3205544630 : memset (t, 0, sizeof (struct tree_common));
5190 : :
5191 : 3205544630 : TREE_SET_CODE (t, code);
5192 : :
5193 : 3205544630 : TREE_TYPE (t) = type;
5194 : 3205544630 : SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
5195 : 3205544630 : TREE_OPERAND (t, 0) = node;
5196 : 3205544630 : if (node && !TYPE_P (node))
5197 : : {
5198 : 3205529593 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
5199 : 3205529593 : TREE_READONLY (t) = TREE_READONLY (node);
5200 : : }
5201 : :
5202 : 3205544630 : if (TREE_CODE_CLASS (code) == tcc_statement)
5203 : : {
5204 : 22125588 : if (code != DEBUG_BEGIN_STMT)
5205 : 22125588 : TREE_SIDE_EFFECTS (t) = 1;
5206 : : }
5207 : 3183419042 : else switch (code)
5208 : : {
5209 : 50942 : case VA_ARG_EXPR:
5210 : : /* All of these have side-effects, no matter what their
5211 : : operands are. */
5212 : 50942 : TREE_SIDE_EFFECTS (t) = 1;
5213 : 50942 : TREE_READONLY (t) = 0;
5214 : 50942 : break;
5215 : :
5216 : 508612192 : case INDIRECT_REF:
5217 : : /* Whether a dereference is readonly has nothing to do with whether
5218 : : its operand is readonly. */
5219 : 508612192 : TREE_READONLY (t) = 0;
5220 : 508612192 : break;
5221 : :
5222 : 523201870 : case ADDR_EXPR:
5223 : 523201870 : if (node)
5224 : 523201870 : recompute_tree_invariant_for_addr_expr (t);
5225 : : break;
5226 : :
5227 : 2151554038 : default:
5228 : 837313622 : if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
5229 : 2037911462 : && node && !TYPE_P (node)
5230 : 4189465500 : && TREE_CONSTANT (node))
5231 : 522135853 : TREE_CONSTANT (t) = 1;
5232 : 2151554038 : if (TREE_CODE_CLASS (code) == tcc_reference
5233 : 726162631 : && node && TREE_THIS_VOLATILE (node))
5234 : 2463384 : TREE_THIS_VOLATILE (t) = 1;
5235 : : break;
5236 : : }
5237 : :
5238 : 3205544630 : return t;
5239 : : }
5240 : :
5241 : : #define PROCESS_ARG(N) \
5242 : : do { \
5243 : : TREE_OPERAND (t, N) = arg##N; \
5244 : : if (arg##N &&!TYPE_P (arg##N)) \
5245 : : { \
5246 : : if (TREE_SIDE_EFFECTS (arg##N)) \
5247 : : side_effects = 1; \
5248 : : if (!TREE_READONLY (arg##N) \
5249 : : && !CONSTANT_CLASS_P (arg##N)) \
5250 : : (void) (read_only = 0); \
5251 : : if (!TREE_CONSTANT (arg##N)) \
5252 : : (void) (constant = 0); \
5253 : : } \
5254 : : } while (0)
5255 : :
5256 : : tree
5257 : 1069754802 : build2 (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
5258 : : {
5259 : 1069754802 : bool constant, read_only, side_effects, div_by_zero;
5260 : 1069754802 : tree t;
5261 : :
5262 : 1069754802 : gcc_assert (TREE_CODE_LENGTH (code) == 2);
5263 : :
5264 : 1069754802 : if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
5265 : 182013006 : && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
5266 : : /* When sizetype precision doesn't match that of pointers
5267 : : we need to be able to build explicit extensions or truncations
5268 : : of the offset argument. */
5269 : 1069754802 : && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
5270 : 0 : gcc_assert (TREE_CODE (arg0) == INTEGER_CST
5271 : : && TREE_CODE (arg1) == INTEGER_CST);
5272 : :
5273 : 1069754802 : if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
5274 : 24850077 : gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
5275 : : && ptrofftype_p (TREE_TYPE (arg1)));
5276 : :
5277 : 1069754802 : t = make_node (code PASS_MEM_STAT);
5278 : 1069754802 : TREE_TYPE (t) = tt;
5279 : :
5280 : : /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
5281 : : result based on those same flags for the arguments. But if the
5282 : : arguments aren't really even `tree' expressions, we shouldn't be trying
5283 : : to do this. */
5284 : :
5285 : : /* Expressions without side effects may be constant if their
5286 : : arguments are as well. */
5287 : 2139509604 : constant = (TREE_CODE_CLASS (code) == tcc_comparison
5288 : 1069754802 : || TREE_CODE_CLASS (code) == tcc_binary);
5289 : 1069754802 : read_only = 1;
5290 : 1069754802 : side_effects = TREE_SIDE_EFFECTS (t);
5291 : :
5292 : 1069754802 : switch (code)
5293 : : {
5294 : 10145605 : case TRUNC_DIV_EXPR:
5295 : 10145605 : case CEIL_DIV_EXPR:
5296 : 10145605 : case FLOOR_DIV_EXPR:
5297 : 10145605 : case ROUND_DIV_EXPR:
5298 : 10145605 : case EXACT_DIV_EXPR:
5299 : 10145605 : case CEIL_MOD_EXPR:
5300 : 10145605 : case FLOOR_MOD_EXPR:
5301 : 10145605 : case ROUND_MOD_EXPR:
5302 : 10145605 : case TRUNC_MOD_EXPR:
5303 : 10145605 : div_by_zero = integer_zerop (arg1);
5304 : 10145605 : break;
5305 : : default:
5306 : : div_by_zero = false;
5307 : : }
5308 : :
5309 : 1164297607 : PROCESS_ARG (0);
5310 : 1505666891 : PROCESS_ARG (1);
5311 : :
5312 : 1069754802 : TREE_SIDE_EFFECTS (t) = side_effects;
5313 : 1069754802 : if (code == MEM_REF)
5314 : : {
5315 : 69780792 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5316 : : {
5317 : 14700732 : tree o = TREE_OPERAND (arg0, 0);
5318 : 14700732 : TREE_READONLY (t) = TREE_READONLY (o);
5319 : 14700732 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5320 : : }
5321 : : }
5322 : : else
5323 : : {
5324 : 999974010 : TREE_READONLY (t) = read_only;
5325 : : /* Don't mark X / 0 as constant. */
5326 : 999974010 : TREE_CONSTANT (t) = constant && !div_by_zero;
5327 : 999974010 : TREE_THIS_VOLATILE (t)
5328 : 999974010 : = (TREE_CODE_CLASS (code) == tcc_reference
5329 : 999974010 : && arg0 && TREE_THIS_VOLATILE (arg0));
5330 : : }
5331 : :
5332 : 1069754802 : return t;
5333 : : }
5334 : :
5335 : :
5336 : : tree
5337 : 396200038 : build3 (enum tree_code code, tree tt, tree arg0, tree arg1,
5338 : : tree arg2 MEM_STAT_DECL)
5339 : : {
5340 : 396200038 : bool constant, read_only, side_effects;
5341 : 396200038 : tree t;
5342 : :
5343 : 396200038 : gcc_assert (TREE_CODE_LENGTH (code) == 3);
5344 : 396200038 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5345 : :
5346 : 396200038 : t = make_node (code PASS_MEM_STAT);
5347 : 396200038 : TREE_TYPE (t) = tt;
5348 : :
5349 : 396200038 : read_only = 1;
5350 : :
5351 : : /* As a special exception, if COND_EXPR has NULL branches, we
5352 : : assume that it is a gimple statement and always consider
5353 : : it to have side effects. */
5354 : 396200038 : if (code == COND_EXPR
5355 : 32985746 : && tt == void_type_node
5356 : 21825808 : && arg1 == NULL_TREE
5357 : 21825808 : && arg2 == NULL_TREE)
5358 : : side_effects = true;
5359 : : else
5360 : 396200038 : side_effects = TREE_SIDE_EFFECTS (t);
5361 : :
5362 : 431922038 : PROCESS_ARG (0);
5363 : 407600493 : PROCESS_ARG (1);
5364 : 406751889 : PROCESS_ARG (2);
5365 : :
5366 : 396200038 : if (code == COND_EXPR)
5367 : 32985746 : TREE_READONLY (t) = read_only;
5368 : :
5369 : 396200038 : TREE_SIDE_EFFECTS (t) = side_effects;
5370 : 396200038 : TREE_THIS_VOLATILE (t)
5371 : 396200038 : = (TREE_CODE_CLASS (code) == tcc_reference
5372 : 396200038 : && arg0 && TREE_THIS_VOLATILE (arg0));
5373 : :
5374 : 396200038 : return t;
5375 : : }
5376 : :
5377 : : tree
5378 : 37967070 : build4 (enum tree_code code, tree tt, tree arg0, tree arg1,
5379 : : tree arg2, tree arg3 MEM_STAT_DECL)
5380 : : {
5381 : 37967070 : bool constant, read_only, side_effects;
5382 : 37967070 : tree t;
5383 : :
5384 : 37967070 : gcc_assert (TREE_CODE_LENGTH (code) == 4);
5385 : :
5386 : 37967070 : t = make_node (code PASS_MEM_STAT);
5387 : 37967070 : TREE_TYPE (t) = tt;
5388 : :
5389 : 37967070 : side_effects = TREE_SIDE_EFFECTS (t);
5390 : :
5391 : 37967070 : PROCESS_ARG (0);
5392 : 37967070 : PROCESS_ARG (1);
5393 : 37967070 : PROCESS_ARG (2);
5394 : 37967070 : PROCESS_ARG (3);
5395 : :
5396 : 37967070 : TREE_SIDE_EFFECTS (t) = side_effects;
5397 : 37967070 : TREE_THIS_VOLATILE (t)
5398 : 75934140 : = (TREE_CODE_CLASS (code) == tcc_reference
5399 : 37967070 : && arg0 && TREE_THIS_VOLATILE (arg0));
5400 : :
5401 : 37967070 : return t;
5402 : : }
5403 : :
5404 : : tree
5405 : 1136077 : build5 (enum tree_code code, tree tt, tree arg0, tree arg1,
5406 : : tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
5407 : : {
5408 : 1136077 : bool constant, read_only, side_effects;
5409 : 1136077 : tree t;
5410 : :
5411 : 1136077 : gcc_assert (TREE_CODE_LENGTH (code) == 5);
5412 : :
5413 : 1136077 : t = make_node (code PASS_MEM_STAT);
5414 : 1136077 : TREE_TYPE (t) = tt;
5415 : :
5416 : 1136077 : side_effects = TREE_SIDE_EFFECTS (t);
5417 : :
5418 : 1136077 : PROCESS_ARG (0);
5419 : 1136077 : PROCESS_ARG (1);
5420 : 1136077 : PROCESS_ARG (2);
5421 : 1136077 : PROCESS_ARG (3);
5422 : 1136077 : PROCESS_ARG (4);
5423 : :
5424 : 1136077 : TREE_SIDE_EFFECTS (t) = side_effects;
5425 : 1136077 : if (code == TARGET_MEM_REF)
5426 : : {
5427 : 1129318 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5428 : : {
5429 : 193278 : tree o = TREE_OPERAND (arg0, 0);
5430 : 193278 : TREE_READONLY (t) = TREE_READONLY (o);
5431 : 193278 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5432 : : }
5433 : : }
5434 : : else
5435 : 6759 : TREE_THIS_VOLATILE (t)
5436 : 6759 : = (TREE_CODE_CLASS (code) == tcc_reference
5437 : 6759 : && arg0 && TREE_THIS_VOLATILE (arg0));
5438 : :
5439 : 1136077 : return t;
5440 : : }
5441 : :
5442 : : /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
5443 : : on the pointer PTR. */
5444 : :
5445 : : tree
5446 : 487031 : build_simple_mem_ref_loc (location_t loc, tree ptr)
5447 : : {
5448 : 487031 : poly_int64 offset = 0;
5449 : 487031 : tree ptype = TREE_TYPE (ptr);
5450 : 487031 : tree tem;
5451 : : /* For convenience allow addresses that collapse to a simple base
5452 : : and offset. */
5453 : 487031 : if (TREE_CODE (ptr) == ADDR_EXPR
5454 : 487031 : && (handled_component_p (TREE_OPERAND (ptr, 0))
5455 : 15495 : || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF))
5456 : : {
5457 : 187 : ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset);
5458 : 187 : gcc_assert (ptr);
5459 : 187 : if (TREE_CODE (ptr) == MEM_REF)
5460 : : {
5461 : 77 : offset += mem_ref_offset (ptr).force_shwi ();
5462 : 77 : ptr = TREE_OPERAND (ptr, 0);
5463 : : }
5464 : : else
5465 : 110 : ptr = build_fold_addr_expr (ptr);
5466 : 187 : gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr));
5467 : : }
5468 : 487031 : tem = build2 (MEM_REF, TREE_TYPE (ptype),
5469 : : ptr, build_int_cst (ptype, offset));
5470 : 487031 : SET_EXPR_LOCATION (tem, loc);
5471 : 487031 : return tem;
5472 : : }
5473 : :
5474 : : /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
5475 : :
5476 : : poly_offset_int
5477 : 1179543186 : mem_ref_offset (const_tree t)
5478 : : {
5479 : 1179543186 : return poly_offset_int::from (wi::to_poly_wide (TREE_OPERAND (t, 1)),
5480 : 1179543186 : SIGNED);
5481 : : }
5482 : :
5483 : : /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
5484 : : offsetted by OFFSET units. */
5485 : :
5486 : : tree
5487 : 189881 : build_invariant_address (tree type, tree base, poly_int64 offset)
5488 : : {
5489 : 189881 : tree ref = fold_build2 (MEM_REF, TREE_TYPE (type),
5490 : : build_fold_addr_expr (base),
5491 : : build_int_cst (ptr_type_node, offset));
5492 : 189881 : tree addr = build1 (ADDR_EXPR, type, ref);
5493 : 189881 : recompute_tree_invariant_for_addr_expr (addr);
5494 : 189881 : return addr;
5495 : : }
5496 : :
5497 : : /* Similar except don't specify the TREE_TYPE
5498 : : and leave the TREE_SIDE_EFFECTS as 0.
5499 : : It is permissible for arguments to be null,
5500 : : or even garbage if their values do not matter. */
5501 : :
5502 : : tree
5503 : 2113837 : build_nt (enum tree_code code, ...)
5504 : : {
5505 : 2113837 : tree t;
5506 : 2113837 : int length;
5507 : 2113837 : int i;
5508 : 2113837 : va_list p;
5509 : :
5510 : 2113837 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5511 : :
5512 : 2113837 : va_start (p, code);
5513 : :
5514 : 2113837 : t = make_node (code);
5515 : 2113837 : length = TREE_CODE_LENGTH (code);
5516 : :
5517 : 5916742 : for (i = 0; i < length; i++)
5518 : 3802905 : TREE_OPERAND (t, i) = va_arg (p, tree);
5519 : :
5520 : 2113837 : va_end (p);
5521 : 2113837 : return t;
5522 : : }
5523 : :
5524 : : /* Similar to build_nt, but for creating a CALL_EXPR object with a
5525 : : tree vec. */
5526 : :
5527 : : tree
5528 : 0 : build_nt_call_vec (tree fn, vec<tree, va_gc> *args)
5529 : : {
5530 : 0 : tree ret, t;
5531 : 0 : unsigned int ix;
5532 : :
5533 : 0 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
5534 : 0 : CALL_EXPR_FN (ret) = fn;
5535 : 0 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
5536 : 0 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
5537 : 0 : CALL_EXPR_ARG (ret, ix) = t;
5538 : 0 : return ret;
5539 : : }
5540 : :
5541 : : /* Create a DECL_... node of code CODE, name NAME (if non-null)
5542 : : and data type TYPE.
5543 : : We do NOT enter this node in any sort of symbol table.
5544 : :
5545 : : LOC is the location of the decl.
5546 : :
5547 : : layout_decl is used to set up the decl's storage layout.
5548 : : Other slots are initialized to 0 or null pointers. */
5549 : :
5550 : : tree
5551 : 2913756058 : build_decl (location_t loc, enum tree_code code, tree name,
5552 : : tree type MEM_STAT_DECL)
5553 : : {
5554 : 2913756058 : tree t;
5555 : :
5556 : 2913756058 : t = make_node (code PASS_MEM_STAT);
5557 : 2913756058 : DECL_SOURCE_LOCATION (t) = loc;
5558 : :
5559 : : /* if (type == error_mark_node)
5560 : : type = integer_type_node; */
5561 : : /* That is not done, deliberately, so that having error_mark_node
5562 : : as the type can suppress useless errors in the use of this variable. */
5563 : :
5564 : 2913756058 : DECL_NAME (t) = name;
5565 : 2913756058 : TREE_TYPE (t) = type;
5566 : :
5567 : 2913756058 : if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
5568 : 1025846113 : layout_decl (t, 0);
5569 : :
5570 : 2913756058 : return t;
5571 : : }
5572 : :
5573 : : /* Create and return a DEBUG_EXPR_DECL node of the given TYPE. */
5574 : :
5575 : : tree
5576 : 1647139 : build_debug_expr_decl (tree type)
5577 : : {
5578 : 1647139 : tree vexpr = make_node (DEBUG_EXPR_DECL);
5579 : 1647139 : DECL_ARTIFICIAL (vexpr) = 1;
5580 : 1647139 : TREE_TYPE (vexpr) = type;
5581 : 1647139 : SET_DECL_MODE (vexpr, TYPE_MODE (type));
5582 : 1647139 : return vexpr;
5583 : : }
5584 : :
5585 : : /* Builds and returns function declaration with NAME and TYPE. */
5586 : :
5587 : : tree
5588 : 19284 : build_fn_decl (const char *name, tree type)
5589 : : {
5590 : 19284 : tree id = get_identifier (name);
5591 : 19284 : tree decl = build_decl (input_location, FUNCTION_DECL, id, type);
5592 : :
5593 : 19284 : DECL_EXTERNAL (decl) = 1;
5594 : 19284 : TREE_PUBLIC (decl) = 1;
5595 : 19284 : DECL_ARTIFICIAL (decl) = 1;
5596 : 19284 : TREE_NOTHROW (decl) = 1;
5597 : :
5598 : 19284 : return decl;
5599 : : }
5600 : :
5601 : : vec<tree, va_gc> *all_translation_units;
5602 : :
5603 : : /* Builds a new translation-unit decl with name NAME, queues it in the
5604 : : global list of translation-unit decls and returns it. */
5605 : :
5606 : : tree
5607 : 250986 : build_translation_unit_decl (tree name)
5608 : : {
5609 : 250986 : tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL,
5610 : 250986 : name, NULL_TREE);
5611 : 250986 : TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
5612 : 250986 : vec_safe_push (all_translation_units, tu);
5613 : 250986 : return tu;
5614 : : }
5615 : :
5616 : :
5617 : : /* BLOCK nodes are used to represent the structure of binding contours
5618 : : and declarations, once those contours have been exited and their contents
5619 : : compiled. This information is used for outputting debugging info. */
5620 : :
5621 : : tree
5622 : 699034 : build_block (tree vars, tree subblocks, tree supercontext, tree chain)
5623 : : {
5624 : 699034 : tree block = make_node (BLOCK);
5625 : :
5626 : 699034 : BLOCK_VARS (block) = vars;
5627 : 699034 : BLOCK_SUBBLOCKS (block) = subblocks;
5628 : 699034 : BLOCK_SUPERCONTEXT (block) = supercontext;
5629 : 699034 : BLOCK_CHAIN (block) = chain;
5630 : 699034 : return block;
5631 : : }
5632 : :
5633 : :
5634 : : /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
5635 : :
5636 : : LOC is the location to use in tree T. */
5637 : :
5638 : : void
5639 : 12211087784 : protected_set_expr_location (tree t, location_t loc)
5640 : : {
5641 : 12211087784 : if (CAN_HAVE_LOCATION_P (t))
5642 : 1949658635 : SET_EXPR_LOCATION (t, loc);
5643 : 10196994015 : else if (t && TREE_CODE (t) == STATEMENT_LIST)
5644 : : {
5645 : 22243 : t = expr_single (t);
5646 : 22243 : if (t && CAN_HAVE_LOCATION_P (t))
5647 : 18 : SET_EXPR_LOCATION (t, loc);
5648 : : }
5649 : 12211087784 : }
5650 : :
5651 : : /* Like PROTECTED_SET_EXPR_LOCATION, but only do that if T has
5652 : : UNKNOWN_LOCATION. */
5653 : :
5654 : : void
5655 : 21007057 : protected_set_expr_location_if_unset (tree t, location_t loc)
5656 : : {
5657 : 21007057 : t = expr_single (t);
5658 : 21007057 : if (t && !EXPR_HAS_LOCATION (t))
5659 : 15876026 : protected_set_expr_location (t, loc);
5660 : 21007057 : }
5661 : :
5662 : : /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5663 : : of the various TYPE_QUAL values. */
5664 : :
5665 : : static void
5666 : 90927666 : set_type_quals (tree type, int type_quals)
5667 : : {
5668 : 90927666 : TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
5669 : 90927666 : TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
5670 : 90927666 : TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
5671 : 90927666 : TYPE_ATOMIC (type) = (type_quals & TYPE_QUAL_ATOMIC) != 0;
5672 : 90927666 : TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals);
5673 : 90927666 : }
5674 : :
5675 : : /* Returns true iff CAND and BASE have equivalent language-specific
5676 : : qualifiers. */
5677 : :
5678 : : bool
5679 : 2391416598 : check_lang_type (const_tree cand, const_tree base)
5680 : : {
5681 : 2391416598 : if (lang_hooks.types.type_hash_eq == NULL)
5682 : : return true;
5683 : : /* type_hash_eq currently only applies to these types. */
5684 : 2336560569 : if (TREE_CODE (cand) != FUNCTION_TYPE
5685 : 2336560569 : && TREE_CODE (cand) != METHOD_TYPE)
5686 : : return true;
5687 : 1078834 : return lang_hooks.types.type_hash_eq (cand, base);
5688 : : }
5689 : :
5690 : : /* This function checks to see if TYPE matches the size one of the built-in
5691 : : atomic types, and returns that core atomic type. */
5692 : :
5693 : : static tree
5694 : 8316 : find_atomic_core_type (const_tree type)
5695 : : {
5696 : 8316 : tree base_atomic_type;
5697 : :
5698 : : /* Only handle complete types. */
5699 : 8316 : if (!tree_fits_uhwi_p (TYPE_SIZE (type)))
5700 : : return NULL_TREE;
5701 : :
5702 : 8304 : switch (tree_to_uhwi (TYPE_SIZE (type)))
5703 : : {
5704 : 2451 : case 8:
5705 : 2451 : base_atomic_type = atomicQI_type_node;
5706 : 2451 : break;
5707 : :
5708 : 788 : case 16:
5709 : 788 : base_atomic_type = atomicHI_type_node;
5710 : 788 : break;
5711 : :
5712 : 1006 : case 32:
5713 : 1006 : base_atomic_type = atomicSI_type_node;
5714 : 1006 : break;
5715 : :
5716 : 2630 : case 64:
5717 : 2630 : base_atomic_type = atomicDI_type_node;
5718 : 2630 : break;
5719 : :
5720 : 1309 : case 128:
5721 : 1309 : base_atomic_type = atomicTI_type_node;
5722 : 1309 : break;
5723 : :
5724 : : default:
5725 : : base_atomic_type = NULL_TREE;
5726 : : }
5727 : :
5728 : : return base_atomic_type;
5729 : : }
5730 : :
5731 : : /* Returns true iff unqualified CAND and BASE are equivalent. */
5732 : :
5733 : : bool
5734 : 3823059884 : check_base_type (const_tree cand, const_tree base)
5735 : : {
5736 : 3823059884 : if (TYPE_NAME (cand) != TYPE_NAME (base)
5737 : : /* Apparently this is needed for Objective-C. */
5738 : 3475010588 : || TYPE_CONTEXT (cand) != TYPE_CONTEXT (base)
5739 : 7298070472 : || !attribute_list_equal (TYPE_ATTRIBUTES (cand),
5740 : 3475010588 : TYPE_ATTRIBUTES (base)))
5741 : 348049296 : return false;
5742 : : /* Check alignment. */
5743 : 3475010588 : if (TYPE_ALIGN (cand) == TYPE_ALIGN (base)
5744 : 3475010588 : && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base))
5745 : : return true;
5746 : : /* Atomic types increase minimal alignment. We must to do so as well
5747 : : or we get duplicated canonical types. See PR88686. */
5748 : 10758 : if ((TYPE_QUALS (cand) & TYPE_QUAL_ATOMIC))
5749 : : {
5750 : : /* See if this object can map to a basic atomic type. */
5751 : 1775 : tree atomic_type = find_atomic_core_type (cand);
5752 : 1775 : if (atomic_type && TYPE_ALIGN (atomic_type) == TYPE_ALIGN (cand))
5753 : : return true;
5754 : : }
5755 : : return false;
5756 : : }
5757 : :
5758 : : /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
5759 : :
5760 : : bool
5761 : 4048086405 : check_qualified_type (const_tree cand, const_tree base, int type_quals)
5762 : : {
5763 : 4048086405 : return (TYPE_QUALS (cand) == type_quals
5764 : 2737567713 : && check_base_type (cand, base)
5765 : 6437816923 : && check_lang_type (cand, base));
5766 : : }
5767 : :
5768 : : /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5769 : :
5770 : : static bool
5771 : 3434799 : check_aligned_type (const_tree cand, const_tree base, unsigned int align)
5772 : : {
5773 : 3434799 : return (TYPE_QUALS (cand) == TYPE_QUALS (base)
5774 : 2809770 : && TYPE_NAME (cand) == TYPE_NAME (base)
5775 : : /* Apparently this is needed for Objective-C. */
5776 : 2011657 : && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
5777 : : /* Check alignment. */
5778 : 2011657 : && TYPE_ALIGN (cand) == align
5779 : : /* Check this is a user-aligned type as build_aligned_type
5780 : : would create. */
5781 : 944471 : && TYPE_USER_ALIGN (cand)
5782 : 941856 : && attribute_list_equal (TYPE_ATTRIBUTES (cand),
5783 : 941856 : TYPE_ATTRIBUTES (base))
5784 : 4376655 : && check_lang_type (cand, base));
5785 : : }
5786 : :
5787 : : /* Return a version of the TYPE, qualified as indicated by the
5788 : : TYPE_QUALS, if one exists. If no qualified version exists yet,
5789 : : return NULL_TREE. */
5790 : :
5791 : : tree
5792 : 3744173794 : get_qualified_type (tree type, int type_quals)
5793 : : {
5794 : 3744173794 : if (TYPE_QUALS (type) == type_quals)
5795 : : return type;
5796 : :
5797 : 2480712458 : tree mv = TYPE_MAIN_VARIANT (type);
5798 : 2480712458 : if (check_qualified_type (mv, type, type_quals))
5799 : : return mv;
5800 : :
5801 : : /* Search the chain of variants to see if there is already one there just
5802 : : like the one we need to have. If so, use that existing one. We must
5803 : : preserve the TYPE_NAME, since there is code that depends on this. */
5804 : 1658370714 : for (tree *tp = &TYPE_NEXT_VARIANT (mv); *tp; tp = &TYPE_NEXT_VARIANT (*tp))
5805 : 1567312609 : if (check_qualified_type (*tp, type, type_quals))
5806 : : {
5807 : : /* Put the found variant at the head of the variant list so
5808 : : frequently searched variants get found faster. The C++ FE
5809 : : benefits greatly from this. */
5810 : 1029602859 : tree t = *tp;
5811 : 1029602859 : *tp = TYPE_NEXT_VARIANT (t);
5812 : 1029602859 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
5813 : 1029602859 : TYPE_NEXT_VARIANT (mv) = t;
5814 : 1029602859 : return t;
5815 : : }
5816 : :
5817 : : return NULL_TREE;
5818 : : }
5819 : :
5820 : : /* Like get_qualified_type, but creates the type if it does not
5821 : : exist. This function never returns NULL_TREE. */
5822 : :
5823 : : tree
5824 : 3350089583 : build_qualified_type (tree type, int type_quals MEM_STAT_DECL)
5825 : : {
5826 : 3350089583 : tree t;
5827 : :
5828 : : /* See if we already have the appropriate qualified variant. */
5829 : 3350089583 : t = get_qualified_type (type, type_quals);
5830 : :
5831 : : /* If not, build it. */
5832 : 3350089583 : if (!t)
5833 : : {
5834 : 89483851 : t = build_variant_type_copy (type PASS_MEM_STAT);
5835 : 89483851 : set_type_quals (t, type_quals);
5836 : :
5837 : 89483851 : if (((type_quals & TYPE_QUAL_ATOMIC) == TYPE_QUAL_ATOMIC))
5838 : : {
5839 : : /* See if this object can map to a basic atomic type. */
5840 : 6541 : tree atomic_type = find_atomic_core_type (type);
5841 : 6541 : if (atomic_type)
5842 : : {
5843 : : /* Ensure the alignment of this type is compatible with
5844 : : the required alignment of the atomic type. */
5845 : 6409 : if (TYPE_ALIGN (atomic_type) > TYPE_ALIGN (t))
5846 : 94 : SET_TYPE_ALIGN (t, TYPE_ALIGN (atomic_type));
5847 : : }
5848 : : }
5849 : :
5850 : 89483851 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5851 : : /* Propagate structural equality. */
5852 : 4393549 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5853 : 85090302 : else if (TYPE_CANONICAL (type) != type)
5854 : : /* Build the underlying canonical type, since it is different
5855 : : from TYPE. */
5856 : : {
5857 : 27857880 : tree c = build_qualified_type (TYPE_CANONICAL (type), type_quals);
5858 : 27857880 : TYPE_CANONICAL (t) = TYPE_CANONICAL (c);
5859 : : }
5860 : : else
5861 : : /* T is its own canonical type. */
5862 : 57232422 : TYPE_CANONICAL (t) = t;
5863 : :
5864 : : }
5865 : :
5866 : 3350089583 : return t;
5867 : : }
5868 : :
5869 : : /* Create a variant of type T with alignment ALIGN which
5870 : : is measured in bits. */
5871 : :
5872 : : tree
5873 : 1223496 : build_aligned_type (tree type, unsigned int align)
5874 : : {
5875 : 1223496 : tree t;
5876 : :
5877 : 1223496 : if (TYPE_PACKED (type)
5878 : 1223496 : || TYPE_ALIGN (type) == align)
5879 : : return type;
5880 : :
5881 : 3536658 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
5882 : 3434799 : if (check_aligned_type (t, type, align))
5883 : : return t;
5884 : :
5885 : 101859 : t = build_variant_type_copy (type);
5886 : 101859 : SET_TYPE_ALIGN (t, align);
5887 : 101859 : TYPE_USER_ALIGN (t) = 1;
5888 : :
5889 : 101859 : return t;
5890 : : }
5891 : :
5892 : : /* Create a new distinct copy of TYPE. The new type is made its own
5893 : : MAIN_VARIANT. If TYPE requires structural equality checks, the
5894 : : resulting type requires structural equality checks; otherwise, its
5895 : : TYPE_CANONICAL points to itself. */
5896 : :
5897 : : tree
5898 : 692911848 : build_distinct_type_copy (tree type MEM_STAT_DECL)
5899 : : {
5900 : 692911848 : tree t = copy_node (type PASS_MEM_STAT);
5901 : :
5902 : 692911848 : TYPE_POINTER_TO (t) = 0;
5903 : 692911848 : TYPE_REFERENCE_TO (t) = 0;
5904 : :
5905 : : /* Set the canonical type either to a new equivalence class, or
5906 : : propagate the need for structural equality checks. */
5907 : 692911848 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5908 : 58278551 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5909 : : else
5910 : 634633297 : TYPE_CANONICAL (t) = t;
5911 : :
5912 : : /* Make it its own variant. */
5913 : 692911848 : TYPE_MAIN_VARIANT (t) = t;
5914 : 692911848 : TYPE_NEXT_VARIANT (t) = 0;
5915 : :
5916 : : /* Note that it is now possible for TYPE_MIN_VALUE to be a value
5917 : : whose TREE_TYPE is not t. This can also happen in the Ada
5918 : : frontend when using subtypes. */
5919 : :
5920 : 692911848 : return t;
5921 : : }
5922 : :
5923 : : /* Create a new variant of TYPE, equivalent but distinct. This is so
5924 : : the caller can modify it. TYPE_CANONICAL for the return type will
5925 : : be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
5926 : : are considered equal by the language itself (or that both types
5927 : : require structural equality checks). */
5928 : :
5929 : : tree
5930 : 415566302 : build_variant_type_copy (tree type MEM_STAT_DECL)
5931 : : {
5932 : 415566302 : tree t, m = TYPE_MAIN_VARIANT (type);
5933 : :
5934 : 415566302 : t = build_distinct_type_copy (type PASS_MEM_STAT);
5935 : :
5936 : : /* Since we're building a variant, assume that it is a non-semantic
5937 : : variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
5938 : 415566302 : TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
5939 : : /* Type variants have no alias set defined. */
5940 : 415566302 : TYPE_ALIAS_SET (t) = -1;
5941 : :
5942 : : /* Add the new type to the chain of variants of TYPE. */
5943 : 415566302 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
5944 : 415566302 : TYPE_NEXT_VARIANT (m) = t;
5945 : 415566302 : TYPE_MAIN_VARIANT (t) = m;
5946 : :
5947 : 415566302 : return t;
5948 : : }
5949 : :
5950 : : /* Return true if the from tree in both tree maps are equal. */
5951 : :
5952 : : int
5953 : 1929169530 : tree_map_base_eq (const void *va, const void *vb)
5954 : : {
5955 : 1929169530 : const struct tree_map_base *const a = (const struct tree_map_base *) va,
5956 : 1929169530 : *const b = (const struct tree_map_base *) vb;
5957 : 1929169530 : return (a->from == b->from);
5958 : : }
5959 : :
5960 : : /* Hash a from tree in a tree_base_map. */
5961 : :
5962 : : unsigned int
5963 : 0 : tree_map_base_hash (const void *item)
5964 : : {
5965 : 0 : return htab_hash_pointer (((const struct tree_map_base *)item)->from);
5966 : : }
5967 : :
5968 : : /* Return true if this tree map structure is marked for garbage collection
5969 : : purposes. We simply return true if the from tree is marked, so that this
5970 : : structure goes away when the from tree goes away. */
5971 : :
5972 : : bool
5973 : 0 : tree_map_base_marked_p (const void *p)
5974 : : {
5975 : 0 : return ggc_marked_p (((const struct tree_map_base *) p)->from);
5976 : : }
5977 : :
5978 : : /* Hash a from tree in a tree_map. */
5979 : :
5980 : : unsigned int
5981 : 202 : tree_map_hash (const void *item)
5982 : : {
5983 : 202 : return (((const struct tree_map *) item)->hash);
5984 : : }
5985 : :
5986 : : /* Hash a from tree in a tree_decl_map. */
5987 : :
5988 : : unsigned int
5989 : 1326443920 : tree_decl_map_hash (const void *item)
5990 : : {
5991 : 1326443920 : return DECL_UID (((const struct tree_decl_map *) item)->base.from);
5992 : : }
5993 : :
5994 : : /* Return the initialization priority for DECL. */
5995 : :
5996 : : priority_type
5997 : 22971 : decl_init_priority_lookup (tree decl)
5998 : : {
5999 : 22971 : symtab_node *snode = symtab_node::get (decl);
6000 : :
6001 : 22971 : if (!snode)
6002 : : return DEFAULT_INIT_PRIORITY;
6003 : 22971 : return
6004 : 22971 : snode->get_init_priority ();
6005 : : }
6006 : :
6007 : : /* Return the finalization priority for DECL. */
6008 : :
6009 : : priority_type
6010 : 1808 : decl_fini_priority_lookup (tree decl)
6011 : : {
6012 : 1808 : cgraph_node *node = cgraph_node::get (decl);
6013 : :
6014 : 1808 : if (!node)
6015 : : return DEFAULT_INIT_PRIORITY;
6016 : 1808 : return
6017 : 1808 : node->get_fini_priority ();
6018 : : }
6019 : :
6020 : : /* Set the initialization priority for DECL to PRIORITY. */
6021 : :
6022 : : void
6023 : 24434 : decl_init_priority_insert (tree decl, priority_type priority)
6024 : : {
6025 : 24434 : struct symtab_node *snode;
6026 : :
6027 : 24434 : if (priority == DEFAULT_INIT_PRIORITY)
6028 : : {
6029 : 20739 : snode = symtab_node::get (decl);
6030 : 20739 : if (!snode)
6031 : : return;
6032 : : }
6033 : 3695 : else if (VAR_P (decl))
6034 : 45 : snode = varpool_node::get_create (decl);
6035 : : else
6036 : 3650 : snode = cgraph_node::get_create (decl);
6037 : 23716 : snode->set_init_priority (priority);
6038 : : }
6039 : :
6040 : : /* Set the finalization priority for DECL to PRIORITY. */
6041 : :
6042 : : void
6043 : 1667 : decl_fini_priority_insert (tree decl, priority_type priority)
6044 : : {
6045 : 1667 : struct cgraph_node *node;
6046 : :
6047 : 1667 : if (priority == DEFAULT_INIT_PRIORITY)
6048 : : {
6049 : 104 : node = cgraph_node::get (decl);
6050 : 104 : if (!node)
6051 : : return;
6052 : : }
6053 : : else
6054 : 1563 : node = cgraph_node::get_create (decl);
6055 : 1572 : node->set_fini_priority (priority);
6056 : : }
6057 : :
6058 : : /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
6059 : :
6060 : : static void
6061 : 0 : print_debug_expr_statistics (void)
6062 : : {
6063 : 0 : fprintf (stderr, "DECL_DEBUG_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6064 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6065 : 0 : (fmt_size_t) debug_expr_for_decl->size (),
6066 : 0 : (fmt_size_t) debug_expr_for_decl->elements (),
6067 : : debug_expr_for_decl->collisions ());
6068 : 0 : }
6069 : :
6070 : : /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6071 : :
6072 : : static void
6073 : 0 : print_value_expr_statistics (void)
6074 : : {
6075 : 0 : fprintf (stderr, "DECL_VALUE_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6076 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6077 : 0 : (fmt_size_t) value_expr_for_decl->size (),
6078 : 0 : (fmt_size_t) value_expr_for_decl->elements (),
6079 : : value_expr_for_decl->collisions ());
6080 : 0 : }
6081 : :
6082 : : /* Lookup a debug expression for FROM, and return it if we find one. */
6083 : :
6084 : : tree
6085 : 459146024 : decl_debug_expr_lookup (tree from)
6086 : : {
6087 : 459146024 : struct tree_decl_map *h, in;
6088 : 459146024 : in.base.from = from;
6089 : :
6090 : 459146024 : h = debug_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6091 : 459146024 : if (h)
6092 : 459146024 : return h->to;
6093 : : return NULL_TREE;
6094 : : }
6095 : :
6096 : : /* Insert a mapping FROM->TO in the debug expression hashtable. */
6097 : :
6098 : : void
6099 : 1368408 : decl_debug_expr_insert (tree from, tree to)
6100 : : {
6101 : 1368408 : struct tree_decl_map *h;
6102 : :
6103 : 1368408 : h = ggc_alloc<tree_decl_map> ();
6104 : 1368408 : h->base.from = from;
6105 : 1368408 : h->to = to;
6106 : 1368408 : *debug_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6107 : 1368408 : }
6108 : :
6109 : : /* Lookup a value expression for FROM, and return it if we find one. */
6110 : :
6111 : : tree
6112 : 12521698 : decl_value_expr_lookup (tree from)
6113 : : {
6114 : 12521698 : struct tree_decl_map *h, in;
6115 : 12521698 : in.base.from = from;
6116 : :
6117 : 12521698 : h = value_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6118 : 12521698 : if (h)
6119 : 12521698 : return h->to;
6120 : : return NULL_TREE;
6121 : : }
6122 : :
6123 : : /* Insert a mapping FROM->TO in the value expression hashtable. */
6124 : :
6125 : : void
6126 : 5373324 : decl_value_expr_insert (tree from, tree to)
6127 : : {
6128 : 5373324 : struct tree_decl_map *h;
6129 : :
6130 : : /* Uses of FROM shouldn't look like they happen at the location of TO. */
6131 : 5373324 : to = protected_set_expr_location_unshare (to, UNKNOWN_LOCATION);
6132 : :
6133 : 5373324 : h = ggc_alloc<tree_decl_map> ();
6134 : 5373324 : h->base.from = from;
6135 : 5373324 : h->to = to;
6136 : 5373324 : *value_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6137 : 5373324 : }
6138 : :
6139 : : /* Lookup a vector of debug arguments for FROM, and return it if we
6140 : : find one. */
6141 : :
6142 : : vec<tree, va_gc> **
6143 : 810348 : decl_debug_args_lookup (tree from)
6144 : : {
6145 : 810348 : struct tree_vec_map *h, in;
6146 : :
6147 : 810348 : if (!DECL_HAS_DEBUG_ARGS_P (from))
6148 : : return NULL;
6149 : 677222 : gcc_checking_assert (debug_args_for_decl != NULL);
6150 : 677222 : in.base.from = from;
6151 : 677222 : h = debug_args_for_decl->find_with_hash (&in, DECL_UID (from));
6152 : 677222 : if (h)
6153 : 674138 : return &h->to;
6154 : : return NULL;
6155 : : }
6156 : :
6157 : : /* Insert a mapping FROM->empty vector of debug arguments in the value
6158 : : expression hashtable. */
6159 : :
6160 : : vec<tree, va_gc> **
6161 : 240012 : decl_debug_args_insert (tree from)
6162 : : {
6163 : 240012 : struct tree_vec_map *h;
6164 : 240012 : tree_vec_map **loc;
6165 : :
6166 : 240012 : if (DECL_HAS_DEBUG_ARGS_P (from))
6167 : 158658 : return decl_debug_args_lookup (from);
6168 : 81354 : if (debug_args_for_decl == NULL)
6169 : 8318 : debug_args_for_decl = hash_table<tree_vec_map_cache_hasher>::create_ggc (64);
6170 : 81354 : h = ggc_alloc<tree_vec_map> ();
6171 : 81354 : h->base.from = from;
6172 : 81354 : h->to = NULL;
6173 : 81354 : loc = debug_args_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT);
6174 : 81354 : *loc = h;
6175 : 81354 : DECL_HAS_DEBUG_ARGS_P (from) = 1;
6176 : 81354 : return &h->to;
6177 : : }
6178 : :
6179 : : /* Hashing of types so that we don't make duplicates.
6180 : : The entry point is `type_hash_canon'. */
6181 : :
6182 : : /* Generate the default hash code for TYPE. This is designed for
6183 : : speed, rather than maximum entropy. */
6184 : :
6185 : : hashval_t
6186 : 1318529216 : type_hash_canon_hash (tree type)
6187 : : {
6188 : 1318529216 : inchash::hash hstate;
6189 : :
6190 : 1318529216 : hstate.add_int (TREE_CODE (type));
6191 : :
6192 : 1318529216 : hstate.add_flag (TYPE_STRUCTURAL_EQUALITY_P (type));
6193 : :
6194 : 1318529216 : if (TREE_TYPE (type))
6195 : 1318507376 : hstate.add_object (TYPE_HASH (TREE_TYPE (type)));
6196 : :
6197 : 1597302949 : for (tree t = TYPE_ATTRIBUTES (type); t; t = TREE_CHAIN (t))
6198 : : /* Just the identifier is adequate to distinguish. */
6199 : 278773733 : hstate.add_object (IDENTIFIER_HASH_VALUE (get_attribute_name (t)));
6200 : :
6201 : 1318529216 : switch (TREE_CODE (type))
6202 : : {
6203 : 287396876 : case METHOD_TYPE:
6204 : 287396876 : hstate.add_object (TYPE_HASH (TYPE_METHOD_BASETYPE (type)));
6205 : : /* FALLTHROUGH. */
6206 : 1139044093 : case FUNCTION_TYPE:
6207 : 4518584639 : for (tree t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
6208 : 3379540546 : if (TREE_VALUE (t) != error_mark_node)
6209 : 3379530003 : hstate.add_object (TYPE_HASH (TREE_VALUE (t)));
6210 : : break;
6211 : :
6212 : 950580 : case OFFSET_TYPE:
6213 : 950580 : hstate.add_object (TYPE_HASH (TYPE_OFFSET_BASETYPE (type)));
6214 : 950580 : break;
6215 : :
6216 : 62366640 : case ARRAY_TYPE:
6217 : 62366640 : {
6218 : 62366640 : if (TYPE_DOMAIN (type))
6219 : 60732744 : hstate.add_object (TYPE_HASH (TYPE_DOMAIN (type)));
6220 : 62366640 : if (!AGGREGATE_TYPE_P (TREE_TYPE (type)))
6221 : : {
6222 : 61012607 : unsigned typeless = TYPE_TYPELESS_STORAGE (type);
6223 : 61012607 : hstate.add_object (typeless);
6224 : : }
6225 : : }
6226 : : break;
6227 : :
6228 : 37955651 : case INTEGER_TYPE:
6229 : 37955651 : {
6230 : 37955651 : tree t = TYPE_MAX_VALUE (type);
6231 : 37955651 : if (!t)
6232 : 541310 : t = TYPE_MIN_VALUE (type);
6233 : 75911303 : for (int i = 0; i < TREE_INT_CST_NUNITS (t); i++)
6234 : 37955652 : hstate.add_object (TREE_INT_CST_ELT (t, i));
6235 : : break;
6236 : : }
6237 : :
6238 : 1 : case BITINT_TYPE:
6239 : 1 : {
6240 : 1 : unsigned prec = TYPE_PRECISION (type);
6241 : 1 : unsigned uns = TYPE_UNSIGNED (type);
6242 : 1 : hstate.add_object (prec);
6243 : 1 : hstate.add_int (uns);
6244 : 1 : break;
6245 : : }
6246 : :
6247 : 11692 : case REAL_TYPE:
6248 : 11692 : case FIXED_POINT_TYPE:
6249 : 11692 : {
6250 : 11692 : unsigned prec = TYPE_PRECISION (type);
6251 : 11692 : hstate.add_object (prec);
6252 : 11692 : break;
6253 : : }
6254 : :
6255 : 72694534 : case VECTOR_TYPE:
6256 : 72694534 : hstate.add_poly_int (TYPE_VECTOR_SUBPARTS (type));
6257 : 72694534 : break;
6258 : :
6259 : : case REFERENCE_TYPE:
6260 : 1318529216 : hstate.add_flag (TYPE_REF_IS_RVALUE (type));
6261 : : break;
6262 : :
6263 : : default:
6264 : : break;
6265 : : }
6266 : :
6267 : 1318529216 : return hstate.end ();
6268 : : }
6269 : :
6270 : : /* These are the Hashtable callback functions. */
6271 : :
6272 : : /* Returns true iff the types are equivalent. */
6273 : :
6274 : : bool
6275 : 8241388691 : type_cache_hasher::equal (type_hash *a, type_hash *b)
6276 : : {
6277 : : /* First test the things that are the same for all types. */
6278 : 8241388691 : if (a->hash != b->hash
6279 : 660913558 : || TREE_CODE (a->type) != TREE_CODE (b->type)
6280 : 660906816 : || TREE_TYPE (a->type) != TREE_TYPE (b->type)
6281 : 660906410 : || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
6282 : 660906410 : TYPE_ATTRIBUTES (b->type))
6283 : 8895245827 : || (TREE_CODE (a->type) != COMPLEX_TYPE
6284 : 651767355 : && TYPE_NAME (a->type) != TYPE_NAME (b->type)))
6285 : 7588390709 : return false;
6286 : :
6287 : : /* Be careful about comparing arrays before and after the element type
6288 : : has been completed; don't compare TYPE_ALIGN unless both types are
6289 : : complete. */
6290 : 1304116286 : if (COMPLETE_TYPE_P (a->type) && COMPLETE_TYPE_P (b->type)
6291 : 1304116286 : && (TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
6292 : 651117746 : || TYPE_MODE (a->type) != TYPE_MODE (b->type)))
6293 : 672 : return false;
6294 : :
6295 : 652997310 : if (TYPE_STRUCTURAL_EQUALITY_P (a->type)
6296 : 652997310 : != TYPE_STRUCTURAL_EQUALITY_P (b->type))
6297 : : return false;
6298 : :
6299 : 652993842 : switch (TREE_CODE (a->type))
6300 : : {
6301 : : case VOID_TYPE:
6302 : : case OPAQUE_TYPE:
6303 : : case COMPLEX_TYPE:
6304 : : case POINTER_TYPE:
6305 : : case NULLPTR_TYPE:
6306 : : return true;
6307 : :
6308 : 66382438 : case VECTOR_TYPE:
6309 : 66382438 : return known_eq (TYPE_VECTOR_SUBPARTS (a->type),
6310 : : TYPE_VECTOR_SUBPARTS (b->type));
6311 : :
6312 : 0 : case ENUMERAL_TYPE:
6313 : 0 : if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
6314 : 0 : && !(TYPE_VALUES (a->type)
6315 : 0 : && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
6316 : 0 : && TYPE_VALUES (b->type)
6317 : 0 : && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
6318 : 0 : && type_list_equal (TYPE_VALUES (a->type),
6319 : 0 : TYPE_VALUES (b->type))))
6320 : 0 : return false;
6321 : :
6322 : : /* fall through */
6323 : :
6324 : 35330220 : case INTEGER_TYPE:
6325 : 35330220 : case REAL_TYPE:
6326 : 35330220 : case BOOLEAN_TYPE:
6327 : 35330220 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6328 : : return false;
6329 : 35323380 : return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
6330 : 789701 : || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
6331 : 789701 : TYPE_MAX_VALUE (b->type)))
6332 : 35714443 : && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
6333 : 544910 : || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
6334 : 544910 : TYPE_MIN_VALUE (b->type))));
6335 : :
6336 : 1548265 : case BITINT_TYPE:
6337 : 1548265 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6338 : : return false;
6339 : 1500359 : return TYPE_UNSIGNED (a->type) == TYPE_UNSIGNED (b->type);
6340 : :
6341 : 0 : case FIXED_POINT_TYPE:
6342 : 0 : return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
6343 : :
6344 : 755886 : case OFFSET_TYPE:
6345 : 755886 : return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
6346 : :
6347 : 82597474 : case METHOD_TYPE:
6348 : 82597474 : if (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
6349 : 82597474 : && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6350 : 82546689 : || (TYPE_ARG_TYPES (a->type)
6351 : 82546689 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6352 : 82546689 : && TYPE_ARG_TYPES (b->type)
6353 : 82546689 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6354 : 82546689 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6355 : 82546689 : TYPE_ARG_TYPES (b->type)))))
6356 : : break;
6357 : : return false;
6358 : 52278471 : case ARRAY_TYPE:
6359 : : /* Don't compare TYPE_TYPELESS_STORAGE flag on aggregates,
6360 : : where the flag should be inherited from the element type
6361 : : and can change after ARRAY_TYPEs are created; on non-aggregates
6362 : : compare it and hash it, scalars will never have that flag set
6363 : : and we need to differentiate between arrays created by different
6364 : : front-ends or middle-end created arrays. */
6365 : 52278471 : return (TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type)
6366 : 52278471 : && (AGGREGATE_TYPE_P (TREE_TYPE (a->type))
6367 : 51542848 : || (TYPE_TYPELESS_STORAGE (a->type)
6368 : 51542848 : == TYPE_TYPELESS_STORAGE (b->type))));
6369 : :
6370 : 0 : case RECORD_TYPE:
6371 : 0 : case UNION_TYPE:
6372 : 0 : case QUAL_UNION_TYPE:
6373 : 0 : return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
6374 : 0 : || (TYPE_FIELDS (a->type)
6375 : 0 : && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
6376 : 0 : && TYPE_FIELDS (b->type)
6377 : 0 : && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
6378 : 0 : && type_list_equal (TYPE_FIELDS (a->type),
6379 : 0 : TYPE_FIELDS (b->type))));
6380 : :
6381 : 412010821 : case FUNCTION_TYPE:
6382 : 412010821 : if ((TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6383 : 260114757 : && (TYPE_NO_NAMED_ARGS_STDARG_P (a->type)
6384 : 260114757 : == TYPE_NO_NAMED_ARGS_STDARG_P (b->type)))
6385 : 412325183 : || (TYPE_ARG_TYPES (a->type)
6386 : 151896064 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6387 : 151896064 : && TYPE_ARG_TYPES (b->type)
6388 : 151896049 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6389 : 151896049 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6390 : 151896049 : TYPE_ARG_TYPES (b->type))))
6391 : : break;
6392 : : return false;
6393 : :
6394 : 9 : case REFERENCE_TYPE:
6395 : 9 : return TYPE_REF_IS_RVALUE (a->type) == TYPE_REF_IS_RVALUE (b->type);
6396 : :
6397 : : default:
6398 : : return false;
6399 : : }
6400 : :
6401 : 470035599 : if (lang_hooks.types.type_hash_eq != NULL)
6402 : 288006910 : return lang_hooks.types.type_hash_eq (a->type, b->type);
6403 : :
6404 : : return true;
6405 : : }
6406 : :
6407 : : /* Given TYPE, and HASHCODE its hash code, return the canonical
6408 : : object for an identical type if one already exists.
6409 : : Otherwise, return TYPE, and record it as the canonical object.
6410 : :
6411 : : To use this function, first create a type of the sort you want.
6412 : : Then compute its hash code from the fields of the type that
6413 : : make it different from other similar types.
6414 : : Then call this function and use the value. */
6415 : :
6416 : : tree
6417 : 1321115839 : type_hash_canon (unsigned int hashcode, tree type)
6418 : : {
6419 : 1321115839 : type_hash in;
6420 : 1321115839 : type_hash **loc;
6421 : :
6422 : : /* The hash table only contains main variants, so ensure that's what we're
6423 : : being passed. */
6424 : 1321115839 : gcc_assert (TYPE_MAIN_VARIANT (type) == type);
6425 : :
6426 : : /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6427 : : must call that routine before comparing TYPE_ALIGNs. */
6428 : 1321115839 : layout_type (type);
6429 : :
6430 : 1321115839 : in.hash = hashcode;
6431 : 1321115839 : in.type = type;
6432 : :
6433 : 1321115839 : loc = type_hash_table->find_slot_with_hash (&in, hashcode, INSERT);
6434 : 1321115839 : if (*loc)
6435 : : {
6436 : 627807701 : tree t1 = ((type_hash *) *loc)->type;
6437 : 627807701 : gcc_assert (TYPE_MAIN_VARIANT (t1) == t1
6438 : : && t1 != type);
6439 : 627807701 : if (TYPE_UID (type) + 1 == next_type_uid)
6440 : 622670815 : --next_type_uid;
6441 : : /* Free also min/max values and the cache for integer
6442 : : types. This can't be done in free_node, as LTO frees
6443 : : those on its own. */
6444 : 627807701 : if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == BITINT_TYPE)
6445 : : {
6446 : 36265037 : if (TYPE_MIN_VALUE (type)
6447 : 36265037 : && TREE_TYPE (TYPE_MIN_VALUE (type)) == type)
6448 : : {
6449 : : /* Zero is always in TYPE_CACHED_VALUES. */
6450 : 1884553 : if (! TYPE_UNSIGNED (type))
6451 : 1663747 : int_cst_hash_table->remove_elt (TYPE_MIN_VALUE (type));
6452 : 1884553 : ggc_free (TYPE_MIN_VALUE (type));
6453 : : }
6454 : 36265037 : if (TYPE_MAX_VALUE (type)
6455 : 36265037 : && TREE_TYPE (TYPE_MAX_VALUE (type)) == type)
6456 : : {
6457 : 1884553 : int_cst_hash_table->remove_elt (TYPE_MAX_VALUE (type));
6458 : 1884553 : ggc_free (TYPE_MAX_VALUE (type));
6459 : : }
6460 : 36265037 : if (TYPE_CACHED_VALUES_P (type))
6461 : 220806 : ggc_free (TYPE_CACHED_VALUES (type));
6462 : : }
6463 : 627807701 : free_node (type);
6464 : 627807701 : return t1;
6465 : : }
6466 : : else
6467 : : {
6468 : 693308138 : struct type_hash *h;
6469 : :
6470 : 693308138 : h = ggc_alloc<type_hash> ();
6471 : 693308138 : h->hash = hashcode;
6472 : 693308138 : h->type = type;
6473 : 693308138 : *loc = h;
6474 : :
6475 : 693308138 : return type;
6476 : : }
6477 : : }
6478 : :
6479 : : static void
6480 : 0 : print_type_hash_statistics (void)
6481 : : {
6482 : 0 : fprintf (stderr, "Type hash: size " HOST_SIZE_T_PRINT_DEC ", "
6483 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6484 : 0 : (fmt_size_t) type_hash_table->size (),
6485 : 0 : (fmt_size_t) type_hash_table->elements (),
6486 : : type_hash_table->collisions ());
6487 : 0 : }
6488 : :
6489 : : /* Given two lists of types
6490 : : (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6491 : : return 1 if the lists contain the same types in the same order.
6492 : : Also, the TREE_PURPOSEs must match. */
6493 : :
6494 : : bool
6495 : 234443262 : type_list_equal (const_tree l1, const_tree l2)
6496 : : {
6497 : 234443262 : const_tree t1, t2;
6498 : :
6499 : 885904194 : for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
6500 : 675718339 : if (TREE_VALUE (t1) != TREE_VALUE (t2)
6501 : 675718339 : || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
6502 : 24258665 : && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
6503 : 1288 : && (TREE_TYPE (TREE_PURPOSE (t1))
6504 : 1288 : == TREE_TYPE (TREE_PURPOSE (t2))))))
6505 : 24257407 : return false;
6506 : :
6507 : 210185855 : return t1 == t2;
6508 : : }
6509 : :
6510 : : /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6511 : : given by TYPE. If the argument list accepts variable arguments,
6512 : : then this function counts only the ordinary arguments. */
6513 : :
6514 : : int
6515 : 79439217 : type_num_arguments (const_tree fntype)
6516 : : {
6517 : 79439217 : int i = 0;
6518 : :
6519 : 309260274 : for (tree t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
6520 : : /* If the function does not take a variable number of arguments,
6521 : : the last element in the list will have type `void'. */
6522 : 290461320 : if (VOID_TYPE_P (TREE_VALUE (t)))
6523 : : break;
6524 : : else
6525 : 229821057 : ++i;
6526 : :
6527 : 79439217 : return i;
6528 : : }
6529 : :
6530 : : /* Return the type of the function TYPE's argument ARGNO if known.
6531 : : For vararg function's where ARGNO refers to one of the variadic
6532 : : arguments return null. Otherwise, return a void_type_node for
6533 : : out-of-bounds ARGNO. */
6534 : :
6535 : : tree
6536 : 78921315 : type_argument_type (const_tree fntype, unsigned argno)
6537 : : {
6538 : : /* Treat zero the same as an out-of-bounds argument number. */
6539 : 78921315 : if (!argno)
6540 : 0 : return void_type_node;
6541 : :
6542 : 78921315 : function_args_iterator iter;
6543 : :
6544 : 78921315 : tree argtype;
6545 : 78921315 : unsigned i = 1;
6546 : 170218259 : FOREACH_FUNCTION_ARGS (fntype, argtype, iter)
6547 : : {
6548 : : /* A vararg function's argument list ends in a null. Otherwise,
6549 : : an ordinary function's argument list ends with void. Return
6550 : : null if ARGNO refers to a vararg argument, void_type_node if
6551 : : it's out of bounds, and the formal argument type otherwise. */
6552 : 164579606 : if (!argtype)
6553 : : break;
6554 : :
6555 : 164579606 : if (i == argno || VOID_TYPE_P (argtype))
6556 : : return argtype;
6557 : :
6558 : 91296944 : ++i;
6559 : : }
6560 : :
6561 : : return NULL_TREE;
6562 : : }
6563 : :
6564 : : /* True if integer constants T1 and T2
6565 : : represent the same constant value. */
6566 : :
6567 : : bool
6568 : 1092861556 : tree_int_cst_equal (const_tree t1, const_tree t2)
6569 : : {
6570 : 1092861556 : if (t1 == t2)
6571 : : return true;
6572 : :
6573 : 508505084 : if (t1 == 0 || t2 == 0)
6574 : : return false;
6575 : :
6576 : 508104718 : STRIP_ANY_LOCATION_WRAPPER (t1);
6577 : 508104718 : STRIP_ANY_LOCATION_WRAPPER (t2);
6578 : :
6579 : 508104718 : if (TREE_CODE (t1) == INTEGER_CST
6580 : 504545973 : && TREE_CODE (t2) == INTEGER_CST
6581 : 1012650691 : && wi::to_widest (t1) == wi::to_widest (t2))
6582 : 18053767 : return true;
6583 : :
6584 : : return false;
6585 : : }
6586 : :
6587 : : /* Return true if T is an INTEGER_CST whose numerical value (extended
6588 : : according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. */
6589 : :
6590 : : bool
6591 : 2035264557 : tree_fits_shwi_p (const_tree t)
6592 : : {
6593 : 2035264557 : return (t != NULL_TREE
6594 : 2035264465 : && TREE_CODE (t) == INTEGER_CST
6595 : 4067188318 : && wi::fits_shwi_p (wi::to_widest (t)));
6596 : : }
6597 : :
6598 : : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6599 : : value (extended according to TYPE_UNSIGNED) fits in a poly_int64. */
6600 : :
6601 : : bool
6602 : 891093883 : tree_fits_poly_int64_p (const_tree t)
6603 : : {
6604 : 891093883 : if (t == NULL_TREE)
6605 : : return false;
6606 : 853374325 : if (POLY_INT_CST_P (t))
6607 : : {
6608 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6609 : : if (!wi::fits_shwi_p (wi::to_wide (POLY_INT_CST_COEFF (t, i))))
6610 : : return false;
6611 : : return true;
6612 : : }
6613 : 853374325 : return (TREE_CODE (t) == INTEGER_CST
6614 : 1706854549 : && wi::fits_shwi_p (wi::to_widest (t)));
6615 : : }
6616 : :
6617 : : /* Return true if T is an INTEGER_CST whose numerical value (extended
6618 : : according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
6619 : :
6620 : : bool
6621 : 3285901825 : tree_fits_uhwi_p (const_tree t)
6622 : : {
6623 : 3285901825 : return (t != NULL_TREE
6624 : 3285465293 : && TREE_CODE (t) == INTEGER_CST
6625 : 6566603650 : && wi::fits_uhwi_p (wi::to_widest (t)));
6626 : : }
6627 : :
6628 : : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6629 : : value (extended according to TYPE_UNSIGNED) fits in a poly_uint64. */
6630 : :
6631 : : bool
6632 : 938790875 : tree_fits_poly_uint64_p (const_tree t)
6633 : : {
6634 : 938790875 : if (t == NULL_TREE)
6635 : : return false;
6636 : 938441334 : if (POLY_INT_CST_P (t))
6637 : : {
6638 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6639 : : if (!wi::fits_uhwi_p (wi::to_widest (POLY_INT_CST_COEFF (t, i))))
6640 : : return false;
6641 : : return true;
6642 : : }
6643 : 938441334 : return (TREE_CODE (t) == INTEGER_CST
6644 : 1876884067 : && wi::fits_uhwi_p (wi::to_widest (t)));
6645 : : }
6646 : :
6647 : : /* Return true if T is an INTEGER_CST whose numerical value (extended according
6648 : : to TYPE_UNSIGNED) fits in a sanitize_code_type (uint64_t). */
6649 : :
6650 : : bool
6651 : 90 : tree_fits_sanitize_code_type_p (const_tree t)
6652 : : {
6653 : 90 : if (t == NULL_TREE)
6654 : : return false;
6655 : 90 : return (TREE_CODE (t) == INTEGER_CST
6656 : 180 : && wi::fits_uhwi_p (wi::to_widest (t)));
6657 : : }
6658 : :
6659 : : /* T is an INTEGER_CST whose numerical value (extended according to
6660 : : TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that
6661 : : HOST_WIDE_INT. */
6662 : :
6663 : : HOST_WIDE_INT
6664 : 1246052864 : tree_to_shwi (const_tree t)
6665 : : {
6666 : 1246052864 : gcc_assert (tree_fits_shwi_p (t));
6667 : 1246052864 : return TREE_INT_CST_LOW (t);
6668 : : }
6669 : :
6670 : : /* T is an INTEGER_CST whose numerical value (extended according to
6671 : : TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. Return that
6672 : : HOST_WIDE_INT. */
6673 : :
6674 : : unsigned HOST_WIDE_INT
6675 : 716629600 : tree_to_uhwi (const_tree t)
6676 : : {
6677 : 716629600 : gcc_assert (tree_fits_uhwi_p (t));
6678 : 716629600 : return TREE_INT_CST_LOW (t);
6679 : : }
6680 : :
6681 : : /* T is an INTEGER_CST whose numerical value (extended according to
6682 : : TYPE_UNSIGNED) fits in a sanitize_code_type. Return that
6683 : : sanitize_code_type. */
6684 : :
6685 : : sanitize_code_type
6686 : 90 : tree_to_sanitize_code_type (const_tree t)
6687 : : {
6688 : 90 : gcc_assert (tree_fits_sanitize_code_type_p (t));
6689 : 90 : return TREE_INT_CST_LOW (t);
6690 : : }
6691 : :
6692 : : /* Return the most significant (sign) bit of T. */
6693 : :
6694 : : int
6695 : 39877469 : tree_int_cst_sign_bit (const_tree t)
6696 : : {
6697 : 39877469 : unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1;
6698 : :
6699 : 39877469 : return wi::extract_uhwi (wi::to_wide (t), bitno, 1);
6700 : : }
6701 : :
6702 : : /* Return an indication of the sign of the integer constant T.
6703 : : The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6704 : : Note that -1 will never be returned if T's type is unsigned. */
6705 : :
6706 : : int
6707 : 1586945796 : tree_int_cst_sgn (const_tree t)
6708 : : {
6709 : 1586945796 : if (wi::to_wide (t) == 0)
6710 : : return 0;
6711 : 1484132819 : else if (TYPE_UNSIGNED (TREE_TYPE (t)))
6712 : : return 1;
6713 : 64830353 : else if (wi::neg_p (wi::to_wide (t)))
6714 : : return -1;
6715 : : else
6716 : : return 1;
6717 : : }
6718 : :
6719 : : /* Return the minimum number of bits needed to represent VALUE in a
6720 : : signed or unsigned type, UNSIGNEDP says which. */
6721 : :
6722 : : unsigned int
6723 : 3394332 : tree_int_cst_min_precision (tree value, signop sgn)
6724 : : {
6725 : : /* If the value is negative, compute its negative minus 1. The latter
6726 : : adjustment is because the absolute value of the largest negative value
6727 : : is one larger than the largest positive value. This is equivalent to
6728 : : a bit-wise negation, so use that operation instead. */
6729 : :
6730 : 3394332 : if (tree_int_cst_sgn (value) < 0)
6731 : 99189 : value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value);
6732 : :
6733 : : /* Return the number of bits needed, taking into account the fact
6734 : : that we need one more bit for a signed than unsigned type.
6735 : : If value is 0 or -1, the minimum precision is 1 no matter
6736 : : whether unsignedp is true or false. */
6737 : :
6738 : 3394332 : if (integer_zerop (value))
6739 : : return 1;
6740 : : else
6741 : 4861843 : return tree_floor_log2 (value) + 1 + (sgn == SIGNED ? 1 : 0) ;
6742 : : }
6743 : :
6744 : : /* Return truthvalue of whether T1 is the same tree structure as T2.
6745 : : Return 1 if they are the same.
6746 : : Return 0 if they are understandably different.
6747 : : Return -1 if either contains tree structure not understood by
6748 : : this function. */
6749 : :
6750 : : int
6751 : 178028408 : simple_cst_equal (const_tree t1, const_tree t2)
6752 : : {
6753 : 182082239 : enum tree_code code1, code2;
6754 : 182082239 : int cmp;
6755 : 182082239 : int i;
6756 : :
6757 : 182082239 : if (t1 == t2)
6758 : : return 1;
6759 : 115890580 : if (t1 == 0 || t2 == 0)
6760 : : return 0;
6761 : :
6762 : : /* For location wrappers to be the same, they must be at the same
6763 : : source location (and wrap the same thing). */
6764 : 107827307 : if (location_wrapper_p (t1) && location_wrapper_p (t2))
6765 : : {
6766 : 10893987 : if (EXPR_LOCATION (t1) != EXPR_LOCATION (t2))
6767 : : return 0;
6768 : 554 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6769 : : }
6770 : :
6771 : 96933320 : code1 = TREE_CODE (t1);
6772 : 96933320 : code2 = TREE_CODE (t2);
6773 : :
6774 : 96933320 : if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR)
6775 : : {
6776 : 4040803 : if (CONVERT_EXPR_CODE_P (code2)
6777 : 4040124 : || code2 == NON_LVALUE_EXPR)
6778 : 679 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6779 : : else
6780 : 4040124 : return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
6781 : : }
6782 : :
6783 : 92892517 : else if (CONVERT_EXPR_CODE_P (code2)
6784 : 92892502 : || code2 == NON_LVALUE_EXPR)
6785 : 118 : return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
6786 : :
6787 : 92892399 : if (code1 != code2)
6788 : : return 0;
6789 : :
6790 : 88301047 : switch (code1)
6791 : : {
6792 : 73635685 : case INTEGER_CST:
6793 : 73635685 : return wi::to_widest (t1) == wi::to_widest (t2);
6794 : :
6795 : 89 : case REAL_CST:
6796 : 89 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
6797 : :
6798 : 0 : case FIXED_CST:
6799 : 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
6800 : :
6801 : 3042840 : case STRING_CST:
6802 : 3042840 : return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
6803 : 3042840 : && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
6804 : 3461929 : TREE_STRING_LENGTH (t1)));
6805 : :
6806 : 76 : case CONSTRUCTOR:
6807 : 76 : {
6808 : 76 : unsigned HOST_WIDE_INT idx;
6809 : 76 : vec<constructor_elt, va_gc> *v1 = CONSTRUCTOR_ELTS (t1);
6810 : 76 : vec<constructor_elt, va_gc> *v2 = CONSTRUCTOR_ELTS (t2);
6811 : :
6812 : 94 : if (vec_safe_length (v1) != vec_safe_length (v2))
6813 : : return false;
6814 : :
6815 : 82 : for (idx = 0; idx < vec_safe_length (v1); ++idx)
6816 : : /* ??? Should we handle also fields here? */
6817 : 9 : if (!simple_cst_equal ((*v1)[idx].value, (*v2)[idx].value))
6818 : : return false;
6819 : : return true;
6820 : : }
6821 : :
6822 : 0 : case SAVE_EXPR:
6823 : 0 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6824 : :
6825 : 209088 : case CALL_EXPR:
6826 : 209088 : cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2));
6827 : 209088 : if (cmp <= 0)
6828 : : return cmp;
6829 : 85698 : if (call_expr_nargs (t1) != call_expr_nargs (t2))
6830 : : return 0;
6831 : 85698 : {
6832 : 85698 : const_tree arg1, arg2;
6833 : 85698 : const_call_expr_arg_iterator iter1, iter2;
6834 : 171396 : for (arg1 = first_const_call_expr_arg (t1, &iter1),
6835 : 85698 : arg2 = first_const_call_expr_arg (t2, &iter2);
6836 : 85768 : arg1 && arg2;
6837 : 70 : arg1 = next_const_call_expr_arg (&iter1),
6838 : 70 : arg2 = next_const_call_expr_arg (&iter2))
6839 : : {
6840 : 85686 : cmp = simple_cst_equal (arg1, arg2);
6841 : 85686 : if (cmp <= 0)
6842 : : return cmp;
6843 : : }
6844 : 82 : return arg1 == arg2;
6845 : : }
6846 : :
6847 : 11931 : case TARGET_EXPR:
6848 : : /* Special case: if either target is an unallocated VAR_DECL,
6849 : : it means that it's going to be unified with whatever the
6850 : : TARGET_EXPR is really supposed to initialize, so treat it
6851 : : as being equivalent to anything. */
6852 : 11931 : if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
6853 : 11931 : && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
6854 : 11931 : && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
6855 : 11931 : || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
6856 : 0 : && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
6857 : 0 : && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
6858 : : cmp = 1;
6859 : : else
6860 : 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6861 : :
6862 : 0 : if (cmp <= 0)
6863 : : return cmp;
6864 : :
6865 : 11931 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
6866 : :
6867 : 0 : case WITH_CLEANUP_EXPR:
6868 : 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6869 : 0 : if (cmp <= 0)
6870 : : return cmp;
6871 : :
6872 : 0 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
6873 : :
6874 : 425 : case COMPONENT_REF:
6875 : 425 : if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
6876 : 425 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6877 : :
6878 : : return 0;
6879 : :
6880 : : case VAR_DECL:
6881 : : case PARM_DECL:
6882 : : case CONST_DECL:
6883 : : case FUNCTION_DECL:
6884 : : return 0;
6885 : :
6886 : 11339687 : default:
6887 : 11339687 : if (POLY_INT_CST_P (t1))
6888 : : /* A false return means maybe_ne rather than known_ne. */
6889 : : return known_eq (poly_widest_int::from (poly_int_cst_value (t1),
6890 : : TYPE_SIGN (TREE_TYPE (t1))),
6891 : : poly_widest_int::from (poly_int_cst_value (t2),
6892 : : TYPE_SIGN (TREE_TYPE (t2))));
6893 : 11339687 : break;
6894 : : }
6895 : :
6896 : : /* This general rule works for most tree codes. All exceptions should be
6897 : : handled above. If this is a language-specific tree code, we can't
6898 : : trust what might be in the operand, so say we don't know
6899 : : the situation. */
6900 : 11339687 : if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
6901 : : return -1;
6902 : :
6903 : 6682858 : switch (TREE_CODE_CLASS (code1))
6904 : : {
6905 : : case tcc_unary:
6906 : : case tcc_binary:
6907 : : case tcc_comparison:
6908 : : case tcc_expression:
6909 : : case tcc_reference:
6910 : : case tcc_statement:
6911 : : cmp = 1;
6912 : 2105 : for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
6913 : : {
6914 : 1625 : cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
6915 : 1625 : if (cmp <= 0)
6916 : : return cmp;
6917 : : }
6918 : :
6919 : : return cmp;
6920 : :
6921 : : default:
6922 : : return -1;
6923 : : }
6924 : : }
6925 : :
6926 : : /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
6927 : : Return -1, 0, or 1 if the value of T is less than, equal to, or greater
6928 : : than U, respectively. */
6929 : :
6930 : : int
6931 : 1309919756 : compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u)
6932 : : {
6933 : 1309919756 : if (tree_int_cst_sgn (t) < 0)
6934 : : return -1;
6935 : 1309919480 : else if (!tree_fits_uhwi_p (t))
6936 : : return 1;
6937 : 1309919455 : else if (TREE_INT_CST_LOW (t) == u)
6938 : : return 0;
6939 : 1186879782 : else if (TREE_INT_CST_LOW (t) < u)
6940 : : return -1;
6941 : : else
6942 : 12133057 : return 1;
6943 : : }
6944 : :
6945 : : /* Return true if SIZE represents a constant size that is in bounds of
6946 : : what the middle-end and the backend accepts (covering not more than
6947 : : half of the address-space).
6948 : : When PERR is non-null, set *PERR on failure to the description of
6949 : : why SIZE is not valid. */
6950 : :
6951 : : bool
6952 : 54309734 : valid_constant_size_p (const_tree size, cst_size_error *perr /* = NULL */)
6953 : : {
6954 : 54309734 : if (POLY_INT_CST_P (size))
6955 : : {
6956 : : if (TREE_OVERFLOW (size))
6957 : : return false;
6958 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
6959 : : if (!valid_constant_size_p (POLY_INT_CST_COEFF (size, i)))
6960 : : return false;
6961 : : return true;
6962 : : }
6963 : :
6964 : 54309734 : cst_size_error error;
6965 : 54309734 : if (!perr)
6966 : 49480457 : perr = &error;
6967 : :
6968 : 54309734 : if (TREE_CODE (size) != INTEGER_CST)
6969 : : {
6970 : 3 : *perr = cst_size_not_constant;
6971 : 3 : return false;
6972 : : }
6973 : :
6974 : 54309731 : if (TREE_OVERFLOW_P (size))
6975 : : {
6976 : 60 : *perr = cst_size_overflow;
6977 : 60 : return false;
6978 : : }
6979 : :
6980 : 54309671 : if (tree_int_cst_sgn (size) < 0)
6981 : : {
6982 : 429 : *perr = cst_size_negative;
6983 : 429 : return false;
6984 : : }
6985 : 108618484 : if (!tree_fits_uhwi_p (size)
6986 : 162927726 : || (wi::to_widest (TYPE_MAX_VALUE (sizetype))
6987 : 162927726 : < wi::to_widest (size) * 2))
6988 : : {
6989 : 624 : *perr = cst_size_too_big;
6990 : 624 : return false;
6991 : : }
6992 : :
6993 : : return true;
6994 : : }
6995 : :
6996 : : /* Return the precision of the type, or for a complex or vector type the
6997 : : precision of the type of its elements. */
6998 : :
6999 : : unsigned int
7000 : 6997058478 : element_precision (const_tree type)
7001 : : {
7002 : 6997058478 : if (!TYPE_P (type))
7003 : 6567698 : type = TREE_TYPE (type);
7004 : 6997058478 : enum tree_code code = TREE_CODE (type);
7005 : 6997058478 : if (code == COMPLEX_TYPE || code == VECTOR_TYPE)
7006 : 53712852 : type = TREE_TYPE (type);
7007 : :
7008 : 6997058478 : return TYPE_PRECISION (type);
7009 : : }
7010 : :
7011 : : /* Return true if CODE represents an associative tree code. Otherwise
7012 : : return false. */
7013 : : bool
7014 : 35269171 : associative_tree_code (enum tree_code code)
7015 : : {
7016 : 35269171 : switch (code)
7017 : : {
7018 : : case BIT_IOR_EXPR:
7019 : : case BIT_AND_EXPR:
7020 : : case BIT_XOR_EXPR:
7021 : : case PLUS_EXPR:
7022 : : case MULT_EXPR:
7023 : : case MIN_EXPR:
7024 : : case MAX_EXPR:
7025 : : return true;
7026 : :
7027 : 24966366 : default:
7028 : 24966366 : break;
7029 : : }
7030 : 24966366 : return false;
7031 : : }
7032 : :
7033 : : /* Return true if CODE represents a commutative tree code. Otherwise
7034 : : return false. */
7035 : : bool
7036 : 1629605288 : commutative_tree_code (enum tree_code code)
7037 : : {
7038 : 1629605288 : switch (code)
7039 : : {
7040 : : case PLUS_EXPR:
7041 : : case MULT_EXPR:
7042 : : case MULT_HIGHPART_EXPR:
7043 : : case MIN_EXPR:
7044 : : case MAX_EXPR:
7045 : : case BIT_IOR_EXPR:
7046 : : case BIT_XOR_EXPR:
7047 : : case BIT_AND_EXPR:
7048 : : case NE_EXPR:
7049 : : case EQ_EXPR:
7050 : : case UNORDERED_EXPR:
7051 : : case ORDERED_EXPR:
7052 : : case UNEQ_EXPR:
7053 : : case LTGT_EXPR:
7054 : : case TRUTH_AND_EXPR:
7055 : : case TRUTH_XOR_EXPR:
7056 : : case TRUTH_OR_EXPR:
7057 : : case WIDEN_MULT_EXPR:
7058 : : case VEC_WIDEN_MULT_HI_EXPR:
7059 : : case VEC_WIDEN_MULT_LO_EXPR:
7060 : : case VEC_WIDEN_MULT_EVEN_EXPR:
7061 : : case VEC_WIDEN_MULT_ODD_EXPR:
7062 : : return true;
7063 : :
7064 : 841167117 : default:
7065 : 841167117 : break;
7066 : : }
7067 : 841167117 : return false;
7068 : : }
7069 : :
7070 : : /* Return true if CODE represents a ternary tree code for which the
7071 : : first two operands are commutative. Otherwise return false. */
7072 : : bool
7073 : 76443607 : commutative_ternary_tree_code (enum tree_code code)
7074 : : {
7075 : 76443607 : switch (code)
7076 : : {
7077 : : case WIDEN_MULT_PLUS_EXPR:
7078 : : case WIDEN_MULT_MINUS_EXPR:
7079 : : case DOT_PROD_EXPR:
7080 : : return true;
7081 : :
7082 : 76435304 : default:
7083 : 76435304 : break;
7084 : : }
7085 : 76435304 : return false;
7086 : : }
7087 : :
7088 : : /* Returns true if CODE can overflow. */
7089 : :
7090 : : bool
7091 : 2961 : operation_can_overflow (enum tree_code code)
7092 : : {
7093 : 2961 : switch (code)
7094 : : {
7095 : : case PLUS_EXPR:
7096 : : case MINUS_EXPR:
7097 : : case MULT_EXPR:
7098 : : case LSHIFT_EXPR:
7099 : : /* Can overflow in various ways. */
7100 : : return true;
7101 : : case TRUNC_DIV_EXPR:
7102 : : case EXACT_DIV_EXPR:
7103 : : case FLOOR_DIV_EXPR:
7104 : : case CEIL_DIV_EXPR:
7105 : : /* For INT_MIN / -1. */
7106 : : return true;
7107 : : case NEGATE_EXPR:
7108 : : case ABS_EXPR:
7109 : : /* For -INT_MIN. */
7110 : : return true;
7111 : 144 : default:
7112 : : /* These operators cannot overflow. */
7113 : 144 : return false;
7114 : : }
7115 : : }
7116 : :
7117 : : /* Returns true if CODE operating on operands of type TYPE doesn't overflow, or
7118 : : ftrapv doesn't generate trapping insns for CODE. */
7119 : :
7120 : : bool
7121 : 5819148 : operation_no_trapping_overflow (tree type, enum tree_code code)
7122 : : {
7123 : 5819148 : gcc_checking_assert (ANY_INTEGRAL_TYPE_P (type));
7124 : :
7125 : : /* We don't generate instructions that trap on overflow for complex or vector
7126 : : types. */
7127 : 5819148 : if (!INTEGRAL_TYPE_P (type))
7128 : : return true;
7129 : :
7130 : 5819148 : if (!TYPE_OVERFLOW_TRAPS (type))
7131 : : return true;
7132 : :
7133 : 1352 : switch (code)
7134 : : {
7135 : : case PLUS_EXPR:
7136 : : case MINUS_EXPR:
7137 : : case MULT_EXPR:
7138 : : case NEGATE_EXPR:
7139 : : case ABS_EXPR:
7140 : : /* These operators can overflow, and -ftrapv generates trapping code for
7141 : : these. */
7142 : : return false;
7143 : : case TRUNC_DIV_EXPR:
7144 : : case EXACT_DIV_EXPR:
7145 : : case FLOOR_DIV_EXPR:
7146 : : case CEIL_DIV_EXPR:
7147 : : case LSHIFT_EXPR:
7148 : : /* These operators can overflow, but -ftrapv does not generate trapping
7149 : : code for these. */
7150 : : return true;
7151 : : default:
7152 : : /* These operators cannot overflow. */
7153 : : return true;
7154 : : }
7155 : : }
7156 : :
7157 : : /* Constructors for pointer, array and function types.
7158 : : (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7159 : : constructed by language-dependent code, not here.) */
7160 : :
7161 : : /* Construct, lay out and return the type of pointers to TO_TYPE with
7162 : : mode MODE. If MODE is VOIDmode, a pointer mode for the address
7163 : : space of TO_TYPE will be picked. If CAN_ALIAS_ALL is TRUE,
7164 : : indicate this type can reference all of memory. If such a type has
7165 : : already been constructed, reuse it. */
7166 : :
7167 : : tree
7168 : 2089012260 : build_pointer_type_for_mode (tree to_type, machine_mode mode,
7169 : : bool can_alias_all)
7170 : : {
7171 : 2089012260 : tree t;
7172 : 2089012260 : bool could_alias = can_alias_all;
7173 : :
7174 : 2089012260 : if (to_type == error_mark_node)
7175 : : return error_mark_node;
7176 : :
7177 : 2089012254 : if (mode == VOIDmode)
7178 : : {
7179 : 1971450680 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7180 : 1971450680 : mode = targetm.addr_space.pointer_mode (as);
7181 : : }
7182 : :
7183 : : /* If the pointed-to type has the may_alias attribute set, force
7184 : : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7185 : 2089012254 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7186 : 4422403 : can_alias_all = true;
7187 : :
7188 : : /* In some cases, languages will have things that aren't a POINTER_TYPE
7189 : : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7190 : : In that case, return that type without regard to the rest of our
7191 : : operands.
7192 : :
7193 : : ??? This is a kludge, but consistent with the way this function has
7194 : : always operated and there doesn't seem to be a good way to avoid this
7195 : : at the moment. */
7196 : 2089012254 : if (TYPE_POINTER_TO (to_type) != 0
7197 : 2089012254 : && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
7198 : 41670 : return TYPE_POINTER_TO (to_type);
7199 : :
7200 : : /* First, if we already have a type for pointers to TO_TYPE and it's
7201 : : the proper mode, use it. */
7202 : 2089527941 : for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
7203 : 1963627811 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7204 : : return t;
7205 : :
7206 : 125900130 : t = make_node (POINTER_TYPE);
7207 : :
7208 : 125900130 : TREE_TYPE (t) = to_type;
7209 : 125900130 : SET_TYPE_MODE (t, mode);
7210 : 125900130 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7211 : 125900130 : TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
7212 : 125900130 : TYPE_POINTER_TO (to_type) = t;
7213 : :
7214 : : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7215 : 125900130 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7216 : 5070965 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7217 : 120829165 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7218 : 36753214 : TYPE_CANONICAL (t)
7219 : 73506428 : = build_pointer_type_for_mode (TYPE_CANONICAL (to_type),
7220 : : mode, false);
7221 : :
7222 : : /* Lay out the type. This function has many callers that are concerned
7223 : : with expression-construction, and this simplifies them all. */
7224 : 125900130 : layout_type (t);
7225 : :
7226 : 125900130 : return t;
7227 : : }
7228 : :
7229 : : /* By default build pointers in ptr_mode. */
7230 : :
7231 : : tree
7232 : 1970758320 : build_pointer_type (tree to_type)
7233 : : {
7234 : 1970758320 : return build_pointer_type_for_mode (to_type, VOIDmode, false);
7235 : : }
7236 : :
7237 : : /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7238 : :
7239 : : tree
7240 : 541703042 : build_reference_type_for_mode (tree to_type, machine_mode mode,
7241 : : bool can_alias_all)
7242 : : {
7243 : 541703042 : tree t;
7244 : 541703042 : bool could_alias = can_alias_all;
7245 : :
7246 : 541703042 : if (to_type == error_mark_node)
7247 : : return error_mark_node;
7248 : :
7249 : 541703042 : if (mode == VOIDmode)
7250 : : {
7251 : 446291605 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7252 : 446291605 : mode = targetm.addr_space.pointer_mode (as);
7253 : : }
7254 : :
7255 : : /* If the pointed-to type has the may_alias attribute set, force
7256 : : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7257 : 541703042 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7258 : 712026 : can_alias_all = true;
7259 : :
7260 : : /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7261 : : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7262 : : In that case, return that type without regard to the rest of our
7263 : : operands.
7264 : :
7265 : : ??? This is a kludge, but consistent with the way this function has
7266 : : always operated and there doesn't seem to be a good way to avoid this
7267 : : at the moment. */
7268 : 541703042 : if (TYPE_REFERENCE_TO (to_type) != 0
7269 : 541703042 : && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
7270 : 0 : return TYPE_REFERENCE_TO (to_type);
7271 : :
7272 : : /* First, if we already have a type for pointers to TO_TYPE and it's
7273 : : the proper mode, use it. */
7274 : 541703042 : for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
7275 : 468368982 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7276 : : return t;
7277 : :
7278 : 73334060 : t = make_node (REFERENCE_TYPE);
7279 : :
7280 : 73334060 : TREE_TYPE (t) = to_type;
7281 : 73334060 : SET_TYPE_MODE (t, mode);
7282 : 73334060 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7283 : 73334060 : TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
7284 : 73334060 : TYPE_REFERENCE_TO (to_type) = t;
7285 : :
7286 : : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7287 : 73334060 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7288 : 3544972 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7289 : 69789088 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7290 : 41512931 : TYPE_CANONICAL (t)
7291 : 83025862 : = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
7292 : : mode, false);
7293 : :
7294 : 73334060 : layout_type (t);
7295 : :
7296 : 73334060 : return t;
7297 : : }
7298 : :
7299 : :
7300 : : /* Build the node for the type of references-to-TO_TYPE by default
7301 : : in ptr_mode. */
7302 : :
7303 : : tree
7304 : 21250630 : build_reference_type (tree to_type)
7305 : : {
7306 : 21250630 : return build_reference_type_for_mode (to_type, VOIDmode, false);
7307 : : }
7308 : :
7309 : : #define MAX_INT_CACHED_PREC \
7310 : : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7311 : : static GTY(()) tree nonstandard_integer_type_cache[2 * MAX_INT_CACHED_PREC + 2];
7312 : :
7313 : : static void
7314 : 260181 : clear_nonstandard_integer_type_cache (void)
7315 : : {
7316 : 34083711 : for (size_t i = 0 ; i < 2 * MAX_INT_CACHED_PREC + 2 ; i++)
7317 : : {
7318 : 33823530 : nonstandard_integer_type_cache[i] = NULL;
7319 : : }
7320 : 0 : }
7321 : :
7322 : : /* Builds a signed or unsigned integer type of precision PRECISION.
7323 : : Used for C bitfields whose precision does not match that of
7324 : : built-in target types. */
7325 : : tree
7326 : 63471955 : build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
7327 : : int unsignedp)
7328 : : {
7329 : 63471955 : tree itype, ret;
7330 : :
7331 : 63471955 : if (unsignedp)
7332 : 54821952 : unsignedp = MAX_INT_CACHED_PREC + 1;
7333 : :
7334 : 63471955 : if (precision <= MAX_INT_CACHED_PREC)
7335 : : {
7336 : 63044867 : itype = nonstandard_integer_type_cache[precision + unsignedp];
7337 : 63044867 : if (itype)
7338 : : return itype;
7339 : : }
7340 : :
7341 : 1081008 : itype = make_node (INTEGER_TYPE);
7342 : 1081008 : TYPE_PRECISION (itype) = precision;
7343 : :
7344 : 1081008 : if (unsignedp)
7345 : 736553 : fixup_unsigned_type (itype);
7346 : : else
7347 : 344455 : fixup_signed_type (itype);
7348 : :
7349 : 1081008 : inchash::hash hstate;
7350 : 1081008 : inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7351 : 1081008 : ret = type_hash_canon (hstate.end (), itype);
7352 : 1081008 : if (precision <= MAX_INT_CACHED_PREC)
7353 : 653920 : nonstandard_integer_type_cache[precision + unsignedp] = ret;
7354 : :
7355 : : return ret;
7356 : : }
7357 : :
7358 : : #define MAX_BOOL_CACHED_PREC \
7359 : : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7360 : : static GTY(()) tree nonstandard_boolean_type_cache[MAX_BOOL_CACHED_PREC + 1];
7361 : :
7362 : : /* Builds a boolean type of precision PRECISION.
7363 : : Used for boolean vectors to choose proper vector element size. */
7364 : : tree
7365 : 2303991 : build_nonstandard_boolean_type (unsigned HOST_WIDE_INT precision)
7366 : : {
7367 : 2303991 : tree type;
7368 : :
7369 : 2303991 : if (precision <= MAX_BOOL_CACHED_PREC)
7370 : : {
7371 : 2299236 : type = nonstandard_boolean_type_cache[precision];
7372 : 2299236 : if (type)
7373 : : return type;
7374 : : }
7375 : :
7376 : 77660 : type = make_node (BOOLEAN_TYPE);
7377 : 77660 : TYPE_PRECISION (type) = precision;
7378 : 77660 : fixup_signed_type (type);
7379 : :
7380 : 77660 : if (precision <= MAX_INT_CACHED_PREC)
7381 : 72905 : nonstandard_boolean_type_cache[precision] = type;
7382 : :
7383 : : return type;
7384 : : }
7385 : :
7386 : : static GTY(()) vec<tree, va_gc> *bitint_type_cache;
7387 : :
7388 : : /* Builds a signed or unsigned _BitInt(PRECISION) type. */
7389 : : tree
7390 : 1540730 : build_bitint_type (unsigned HOST_WIDE_INT precision, int unsignedp)
7391 : : {
7392 : 1540730 : tree itype, ret;
7393 : :
7394 : 1575616 : gcc_checking_assert (precision >= 1 + !unsignedp);
7395 : :
7396 : 1540730 : if (unsignedp)
7397 : 34886 : unsignedp = MAX_INT_CACHED_PREC + 1;
7398 : :
7399 : 1540730 : if (bitint_type_cache == NULL)
7400 : 498 : vec_safe_grow_cleared (bitint_type_cache, 2 * MAX_INT_CACHED_PREC + 2);
7401 : :
7402 : 1540730 : if (precision <= MAX_INT_CACHED_PREC)
7403 : : {
7404 : 36541 : itype = (*bitint_type_cache)[precision + unsignedp];
7405 : 36541 : if (itype)
7406 : : return itype;
7407 : : }
7408 : :
7409 : 1505615 : itype = make_node (BITINT_TYPE);
7410 : 1505615 : TYPE_PRECISION (itype) = precision;
7411 : :
7412 : 1505615 : if (unsignedp)
7413 : 28427 : fixup_unsigned_type (itype);
7414 : : else
7415 : 1477188 : fixup_signed_type (itype);
7416 : :
7417 : 1505615 : inchash::hash hstate;
7418 : 1505615 : inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7419 : 1505615 : ret = type_hash_canon (hstate.end (), itype);
7420 : 1505615 : if (precision <= MAX_INT_CACHED_PREC)
7421 : 1426 : (*bitint_type_cache)[precision + unsignedp] = ret;
7422 : :
7423 : : return ret;
7424 : : }
7425 : :
7426 : : /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7427 : : or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7428 : : is true, reuse such a type that has already been constructed. */
7429 : :
7430 : : static tree
7431 : 38912541 : build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
7432 : : {
7433 : 38912541 : tree itype = make_node (INTEGER_TYPE);
7434 : :
7435 : 38912541 : TREE_TYPE (itype) = type;
7436 : :
7437 : 38912541 : TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
7438 : 38912541 : TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
7439 : :
7440 : 38912541 : TYPE_PRECISION (itype) = TYPE_PRECISION (type);
7441 : 38912541 : SET_TYPE_MODE (itype, TYPE_MODE (type));
7442 : 38912541 : TYPE_SIZE (itype) = TYPE_SIZE (type);
7443 : 38912541 : TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
7444 : 38912541 : SET_TYPE_ALIGN (itype, TYPE_ALIGN (type));
7445 : 38912541 : TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
7446 : 38912541 : SET_TYPE_WARN_IF_NOT_ALIGN (itype, TYPE_WARN_IF_NOT_ALIGN (type));
7447 : :
7448 : 38912541 : if (!shared)
7449 : : return itype;
7450 : :
7451 : 38912541 : if ((TYPE_MIN_VALUE (itype)
7452 : 38912541 : && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST)
7453 : 77824253 : || (TYPE_MAX_VALUE (itype)
7454 : 38370402 : && TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST))
7455 : : {
7456 : : /* Since we cannot reliably merge this type, we need to compare it using
7457 : : structural equality checks. */
7458 : 967136 : SET_TYPE_STRUCTURAL_EQUALITY (itype);
7459 : 967136 : return itype;
7460 : : }
7461 : :
7462 : 37945405 : hashval_t hash = type_hash_canon_hash (itype);
7463 : 37945405 : itype = type_hash_canon (hash, itype);
7464 : :
7465 : 37945405 : return itype;
7466 : : }
7467 : :
7468 : : /* Wrapper around build_range_type_1 with SHARED set to true. */
7469 : :
7470 : : tree
7471 : 38912541 : build_range_type (tree type, tree lowval, tree highval)
7472 : : {
7473 : 38912541 : return build_range_type_1 (type, lowval, highval, true);
7474 : : }
7475 : :
7476 : : /* Wrapper around build_range_type_1 with SHARED set to false. */
7477 : :
7478 : : tree
7479 : 0 : build_nonshared_range_type (tree type, tree lowval, tree highval)
7480 : : {
7481 : 0 : return build_range_type_1 (type, lowval, highval, false);
7482 : : }
7483 : :
7484 : : /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7485 : : MAXVAL should be the maximum value in the domain
7486 : : (one less than the length of the array).
7487 : :
7488 : : The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7489 : : We don't enforce this limit, that is up to caller (e.g. language front end).
7490 : : The limit exists because the result is a signed type and we don't handle
7491 : : sizes that use more than one HOST_WIDE_INT. */
7492 : :
7493 : : tree
7494 : 36206644 : build_index_type (tree maxval)
7495 : : {
7496 : 36206644 : return build_range_type (sizetype, size_zero_node, maxval);
7497 : : }
7498 : :
7499 : : /* Return true if the debug information for TYPE, a subtype, should be emitted
7500 : : as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7501 : : high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7502 : : debug info and doesn't reflect the source code. */
7503 : :
7504 : : bool
7505 : 18 : subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval)
7506 : : {
7507 : 18 : tree base_type = TREE_TYPE (type), low, high;
7508 : :
7509 : : /* Subrange types have a base type which is an integral type. */
7510 : 18 : if (!INTEGRAL_TYPE_P (base_type))
7511 : : return false;
7512 : :
7513 : : /* Get the real bounds of the subtype. */
7514 : 18 : if (lang_hooks.types.get_subrange_bounds)
7515 : 0 : lang_hooks.types.get_subrange_bounds (type, &low, &high);
7516 : : else
7517 : : {
7518 : 18 : low = TYPE_MIN_VALUE (type);
7519 : 18 : high = TYPE_MAX_VALUE (type);
7520 : : }
7521 : :
7522 : : /* If the type and its base type have the same representation and the same
7523 : : name, then the type is not a subrange but a copy of the base type. */
7524 : 18 : if ((TREE_CODE (base_type) == INTEGER_TYPE
7525 : 18 : || TREE_CODE (base_type) == BOOLEAN_TYPE)
7526 : 18 : && int_size_in_bytes (type) == int_size_in_bytes (base_type)
7527 : 18 : && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type))
7528 : 0 : && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type))
7529 : 18 : && TYPE_IDENTIFIER (type) == TYPE_IDENTIFIER (base_type))
7530 : : return false;
7531 : :
7532 : 18 : if (lowval)
7533 : 18 : *lowval = low;
7534 : 18 : if (highval)
7535 : 18 : *highval = high;
7536 : : return true;
7537 : : }
7538 : :
7539 : : /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7540 : : and number of elements specified by the range of values of INDEX_TYPE.
7541 : : If TYPELESS_STORAGE is true, TYPE_TYPELESS_STORAGE flag is set on the type.
7542 : : If SHARED is true, reuse such a type that has already been constructed.
7543 : : If SET_CANONICAL is true, compute TYPE_CANONICAL from the element type. */
7544 : :
7545 : : tree
7546 : 61826756 : build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
7547 : : bool shared, bool set_canonical)
7548 : : {
7549 : 61826756 : tree t;
7550 : :
7551 : 61826756 : if (TREE_CODE (elt_type) == FUNCTION_TYPE)
7552 : : {
7553 : 0 : error ("arrays of functions are not meaningful");
7554 : 0 : elt_type = integer_type_node;
7555 : : }
7556 : :
7557 : 61826756 : t = make_node (ARRAY_TYPE);
7558 : 61826756 : TREE_TYPE (t) = elt_type;
7559 : 61826756 : TYPE_DOMAIN (t) = index_type;
7560 : 61826756 : TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type);
7561 : 61826756 : TYPE_TYPELESS_STORAGE (t) = typeless_storage;
7562 : :
7563 : : /* Set TYPE_STRUCTURAL_EQUALITY_P. */
7564 : 61826756 : if (set_canonical
7565 : 61826756 : && (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7566 : 61795577 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7567 : 61543587 : || in_lto_p))
7568 : 357338 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7569 : :
7570 : 61826756 : layout_type (t);
7571 : :
7572 : 61826756 : if (shared)
7573 : : {
7574 : 61826729 : hashval_t hash = type_hash_canon_hash (t);
7575 : 61826729 : tree probe_type = t;
7576 : 61826729 : t = type_hash_canon (hash, t);
7577 : 61826729 : if (t != probe_type)
7578 : : return t;
7579 : : }
7580 : :
7581 : 10008613 : if (TYPE_CANONICAL (t) == t && set_canonical)
7582 : : {
7583 : 9700043 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7584 : 9700043 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7585 : 19400086 : || in_lto_p)
7586 : 0 : gcc_unreachable ();
7587 : 9700043 : else if (TYPE_CANONICAL (elt_type) != elt_type
7588 : 9700043 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
7589 : 101287 : TYPE_CANONICAL (t)
7590 : 293785 : = build_array_type_1 (TYPE_CANONICAL (elt_type),
7591 : : index_type
7592 : 91211 : ? TYPE_CANONICAL (index_type) : NULL_TREE,
7593 : : typeless_storage, shared, set_canonical);
7594 : : }
7595 : :
7596 : : return t;
7597 : : }
7598 : :
7599 : : /* Wrapper around build_array_type_1 with SHARED set to true. */
7600 : :
7601 : : tree
7602 : 61725442 : build_array_type (tree elt_type, tree index_type, bool typeless_storage)
7603 : : {
7604 : 61725442 : return
7605 : 61725442 : build_array_type_1 (elt_type, index_type, typeless_storage, true, true);
7606 : : }
7607 : :
7608 : : /* Wrapper around build_array_type_1 with SHARED set to false. */
7609 : :
7610 : : tree
7611 : 0 : build_nonshared_array_type (tree elt_type, tree index_type)
7612 : : {
7613 : 0 : return build_array_type_1 (elt_type, index_type, false, false, true);
7614 : : }
7615 : :
7616 : : /* Return a representation of ELT_TYPE[NELTS], using indices of type
7617 : : sizetype. */
7618 : :
7619 : : tree
7620 : 1450701 : build_array_type_nelts (tree elt_type, poly_uint64 nelts)
7621 : : {
7622 : 1450701 : return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
7623 : : }
7624 : :
7625 : : /* Computes the canonical argument types from the argument type list
7626 : : ARGTYPES.
7627 : :
7628 : : Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7629 : : on entry to this function, or if any of the ARGTYPES are
7630 : : structural.
7631 : :
7632 : : Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7633 : : true on entry to this function, or if any of the ARGTYPES are
7634 : : non-canonical.
7635 : :
7636 : : Returns a canonical argument list, which may be ARGTYPES when the
7637 : : canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7638 : : true) or would not differ from ARGTYPES. */
7639 : :
7640 : : static tree
7641 : 888920222 : maybe_canonicalize_argtypes (tree argtypes,
7642 : : bool *any_structural_p,
7643 : : bool *any_noncanonical_p)
7644 : : {
7645 : 888920222 : tree arg;
7646 : 888920222 : bool any_noncanonical_argtypes_p = false;
7647 : :
7648 : 3106011538 : for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
7649 : : {
7650 : 2217091316 : if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
7651 : : /* Fail gracefully by stating that the type is structural. */
7652 : 4068 : *any_structural_p = true;
7653 : 2217087248 : else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg)))
7654 : 33526526 : *any_structural_p = true;
7655 : 2183560722 : else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg)
7656 : 2183560722 : || TREE_PURPOSE (arg))
7657 : : /* If the argument has a default argument, we consider it
7658 : : non-canonical even though the type itself is canonical.
7659 : : That way, different variants of function and method types
7660 : : with default arguments will all point to the variant with
7661 : : no defaults as their canonical type. */
7662 : : any_noncanonical_argtypes_p = true;
7663 : : }
7664 : :
7665 : 888920222 : if (*any_structural_p)
7666 : : return argtypes;
7667 : :
7668 : 800005262 : if (any_noncanonical_argtypes_p)
7669 : : {
7670 : : /* Build the canonical list of argument types. */
7671 : : tree canon_argtypes = NULL_TREE;
7672 : : bool is_void = false;
7673 : :
7674 : 798629146 : for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
7675 : : {
7676 : 614317053 : if (arg == void_list_node)
7677 : : is_void = true;
7678 : : else
7679 : 862438822 : canon_argtypes = tree_cons (NULL_TREE,
7680 : 431219411 : TYPE_CANONICAL (TREE_VALUE (arg)),
7681 : : canon_argtypes);
7682 : : }
7683 : :
7684 : 184312093 : canon_argtypes = nreverse (canon_argtypes);
7685 : 184312093 : if (is_void)
7686 : 183097642 : canon_argtypes = chainon (canon_argtypes, void_list_node);
7687 : :
7688 : : /* There is a non-canonical type. */
7689 : 184312093 : *any_noncanonical_p = true;
7690 : 184312093 : return canon_argtypes;
7691 : : }
7692 : :
7693 : : /* The canonical argument types are the same as ARGTYPES. */
7694 : : return argtypes;
7695 : : }
7696 : :
7697 : : /* Construct, lay out and return
7698 : : the type of functions returning type VALUE_TYPE
7699 : : given arguments of types ARG_TYPES.
7700 : : ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7701 : : are data type nodes for the arguments of the function.
7702 : : NO_NAMED_ARGS_STDARG_P is true if this is a prototyped
7703 : : variable-arguments function with (...) prototype (no named arguments).
7704 : : If such a type has already been constructed, reuse it. */
7705 : :
7706 : : tree
7707 : 602244672 : build_function_type (tree value_type, tree arg_types,
7708 : : bool no_named_args_stdarg_p)
7709 : : {
7710 : 602244672 : tree t;
7711 : 602244672 : inchash::hash hstate;
7712 : 602244672 : bool any_structural_p, any_noncanonical_p;
7713 : 602244672 : tree canon_argtypes;
7714 : :
7715 : 602244672 : gcc_assert (arg_types != error_mark_node);
7716 : :
7717 : 602244672 : if (TREE_CODE (value_type) == FUNCTION_TYPE)
7718 : : {
7719 : 0 : error ("function return type cannot be function");
7720 : 0 : value_type = integer_type_node;
7721 : : }
7722 : :
7723 : : /* Make a node of the sort we want. */
7724 : 602244672 : t = make_node (FUNCTION_TYPE);
7725 : 602244672 : TREE_TYPE (t) = value_type;
7726 : 602244672 : TYPE_ARG_TYPES (t) = arg_types;
7727 : 602244672 : if (no_named_args_stdarg_p)
7728 : : {
7729 : 1371876 : gcc_assert (arg_types == NULL_TREE);
7730 : 1371876 : TYPE_NO_NAMED_ARGS_STDARG_P (t) = 1;
7731 : : }
7732 : :
7733 : : /* Set up the canonical type. */
7734 : 602244672 : any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type);
7735 : 602244672 : any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
7736 : 602244672 : canon_argtypes = maybe_canonicalize_argtypes (arg_types,
7737 : : &any_structural_p,
7738 : : &any_noncanonical_p);
7739 : : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7740 : 602244672 : if (any_structural_p)
7741 : 65863438 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7742 : :
7743 : : /* If we already have such a type, use the old one. */
7744 : 602244672 : hashval_t hash = type_hash_canon_hash (t);
7745 : 602244672 : tree probe_type = t;
7746 : 602244672 : t = type_hash_canon (hash, t);
7747 : 602244672 : if (t != probe_type)
7748 : : return t;
7749 : :
7750 : 391587091 : if (any_structural_p)
7751 : 53351898 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7752 : 338235193 : else if (any_noncanonical_p)
7753 : 77062573 : TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
7754 : : canon_argtypes);
7755 : :
7756 : 391587091 : if (!COMPLETE_TYPE_P (t))
7757 : 0 : layout_type (t);
7758 : : return t;
7759 : : }
7760 : :
7761 : : /* Build a function type. The RETURN_TYPE is the type returned by the
7762 : : function. If VAARGS is set, no void_type_node is appended to the
7763 : : list. ARGP must be always be terminated be a NULL_TREE. */
7764 : :
7765 : : static tree
7766 : 14744985 : build_function_type_list_1 (bool vaargs, tree return_type, va_list argp)
7767 : : {
7768 : 14744985 : tree t, args, last;
7769 : :
7770 : 14744985 : t = va_arg (argp, tree);
7771 : 62500304 : for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree))
7772 : 33010334 : args = tree_cons (NULL_TREE, t, args);
7773 : :
7774 : 14744985 : if (vaargs)
7775 : : {
7776 : 834147 : last = args;
7777 : 834147 : if (args != NULL_TREE)
7778 : 706364 : args = nreverse (args);
7779 : 834147 : gcc_assert (last != void_list_node);
7780 : : }
7781 : 13910838 : else if (args == NULL_TREE)
7782 : 1141398 : args = void_list_node;
7783 : : else
7784 : : {
7785 : 12769440 : last = args;
7786 : 12769440 : args = nreverse (args);
7787 : 12769440 : TREE_CHAIN (last) = void_list_node;
7788 : : }
7789 : 14744985 : args = build_function_type (return_type, args, vaargs && args == NULL_TREE);
7790 : :
7791 : 14744985 : return args;
7792 : : }
7793 : :
7794 : : /* Build a function type. The RETURN_TYPE is the type returned by the
7795 : : function. If additional arguments are provided, they are
7796 : : additional argument types. The list of argument types must always
7797 : : be terminated by NULL_TREE. */
7798 : :
7799 : : tree
7800 : 13910838 : build_function_type_list (tree return_type, ...)
7801 : : {
7802 : 13910838 : tree args;
7803 : 13910838 : va_list p;
7804 : :
7805 : 13910838 : va_start (p, return_type);
7806 : 13910838 : args = build_function_type_list_1 (false, return_type, p);
7807 : 13910838 : va_end (p);
7808 : 13910838 : return args;
7809 : : }
7810 : :
7811 : : /* Build a variable argument function type. The RETURN_TYPE is the
7812 : : type returned by the function. If additional arguments are provided,
7813 : : they are additional argument types. The list of argument types must
7814 : : always be terminated by NULL_TREE. */
7815 : :
7816 : : tree
7817 : 834147 : build_varargs_function_type_list (tree return_type, ...)
7818 : : {
7819 : 834147 : tree args;
7820 : 834147 : va_list p;
7821 : :
7822 : 834147 : va_start (p, return_type);
7823 : 834147 : args = build_function_type_list_1 (true, return_type, p);
7824 : 834147 : va_end (p);
7825 : :
7826 : 834147 : return args;
7827 : : }
7828 : :
7829 : : /* Build a function type. RETURN_TYPE is the type returned by the
7830 : : function; VAARGS indicates whether the function takes varargs. The
7831 : : function takes N named arguments, the types of which are provided in
7832 : : ARG_TYPES. */
7833 : :
7834 : : static tree
7835 : 117721417 : build_function_type_array_1 (bool vaargs, tree return_type, int n,
7836 : : tree *arg_types)
7837 : : {
7838 : 117721417 : int i;
7839 : 117721417 : tree t = vaargs ? NULL_TREE : void_list_node;
7840 : :
7841 : 386286782 : for (i = n - 1; i >= 0; i--)
7842 : 268565365 : t = tree_cons (NULL_TREE, arg_types[i], t);
7843 : :
7844 : 117721417 : return build_function_type (return_type, t, vaargs && n == 0);
7845 : : }
7846 : :
7847 : : /* Build a function type. RETURN_TYPE is the type returned by the
7848 : : function. The function takes N named arguments, the types of which
7849 : : are provided in ARG_TYPES. */
7850 : :
7851 : : tree
7852 : 111377614 : build_function_type_array (tree return_type, int n, tree *arg_types)
7853 : : {
7854 : 111377614 : return build_function_type_array_1 (false, return_type, n, arg_types);
7855 : : }
7856 : :
7857 : : /* Build a variable argument function type. RETURN_TYPE is the type
7858 : : returned by the function. The function takes N named arguments, the
7859 : : types of which are provided in ARG_TYPES. */
7860 : :
7861 : : tree
7862 : 6343803 : build_varargs_function_type_array (tree return_type, int n, tree *arg_types)
7863 : : {
7864 : 6343803 : return build_function_type_array_1 (true, return_type, n, arg_types);
7865 : : }
7866 : :
7867 : : /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
7868 : : and ARGTYPES (a TREE_LIST) are the return type and arguments types
7869 : : for the method. An implicit additional parameter (of type
7870 : : pointer-to-BASETYPE) is added to the ARGTYPES. */
7871 : :
7872 : : tree
7873 : 286675550 : build_method_type_directly (tree basetype,
7874 : : tree rettype,
7875 : : tree argtypes)
7876 : : {
7877 : 286675550 : tree t;
7878 : 286675550 : tree ptype;
7879 : 286675550 : bool any_structural_p, any_noncanonical_p;
7880 : 286675550 : tree canon_argtypes;
7881 : :
7882 : : /* Make a node of the sort we want. */
7883 : 286675550 : t = make_node (METHOD_TYPE);
7884 : :
7885 : 286675550 : TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7886 : 286675550 : TREE_TYPE (t) = rettype;
7887 : 286675550 : ptype = build_pointer_type (basetype);
7888 : :
7889 : : /* The actual arglist for this function includes a "hidden" argument
7890 : : which is "this". Put it into the list of argument types. */
7891 : 286675550 : argtypes = tree_cons (NULL_TREE, ptype, argtypes);
7892 : 286675550 : TYPE_ARG_TYPES (t) = argtypes;
7893 : :
7894 : : /* Set up the canonical type. */
7895 : 286675550 : any_structural_p
7896 : 286675550 : = (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7897 : 286675550 : || TYPE_STRUCTURAL_EQUALITY_P (rettype));
7898 : 286675550 : any_noncanonical_p
7899 : 286675550 : = (TYPE_CANONICAL (basetype) != basetype
7900 : 286675550 : || TYPE_CANONICAL (rettype) != rettype);
7901 : 286675550 : canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes),
7902 : : &any_structural_p,
7903 : : &any_noncanonical_p);
7904 : :
7905 : : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7906 : 286675550 : if (any_structural_p)
7907 : 23051522 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7908 : :
7909 : : /* If we already have such a type, use the old one. */
7910 : 286675550 : hashval_t hash = type_hash_canon_hash (t);
7911 : 286675550 : tree probe_type = t;
7912 : 286675550 : t = type_hash_canon (hash, t);
7913 : 286675550 : if (t != probe_type)
7914 : : return t;
7915 : :
7916 : 218128226 : if (any_structural_p)
7917 : 19116517 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7918 : 199011709 : else if (any_noncanonical_p)
7919 : 74525857 : TYPE_CANONICAL (t)
7920 : 149051714 : = build_method_type_directly (TYPE_CANONICAL (basetype),
7921 : 74525857 : TYPE_CANONICAL (rettype),
7922 : : canon_argtypes);
7923 : 218128226 : if (!COMPLETE_TYPE_P (t))
7924 : 0 : layout_type (t);
7925 : :
7926 : : return t;
7927 : : }
7928 : :
7929 : : /* Construct, lay out and return the type of methods belonging to class
7930 : : BASETYPE and whose arguments and values are described by TYPE.
7931 : : If that type exists already, reuse it.
7932 : : TYPE must be a FUNCTION_TYPE node. */
7933 : :
7934 : : tree
7935 : 155 : build_method_type (tree basetype, tree type)
7936 : : {
7937 : 155 : gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
7938 : :
7939 : 155 : return build_method_type_directly (basetype,
7940 : 155 : TREE_TYPE (type),
7941 : 155 : TYPE_ARG_TYPES (type));
7942 : : }
7943 : :
7944 : : /* Construct, lay out and return the type of offsets to a value
7945 : : of type TYPE, within an object of type BASETYPE.
7946 : : If a suitable offset type exists already, reuse it. */
7947 : :
7948 : : tree
7949 : 950574 : build_offset_type (tree basetype, tree type)
7950 : : {
7951 : 950574 : tree t;
7952 : :
7953 : : /* Make a node of the sort we want. */
7954 : 950574 : t = make_node (OFFSET_TYPE);
7955 : :
7956 : 950574 : TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7957 : 950574 : TREE_TYPE (t) = type;
7958 : 950574 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7959 : 950574 : || TYPE_STRUCTURAL_EQUALITY_P (type))
7960 : 4 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7961 : :
7962 : : /* If we already have such a type, use the old one. */
7963 : 950574 : hashval_t hash = type_hash_canon_hash (t);
7964 : 950574 : tree probe_type = t;
7965 : 950574 : t = type_hash_canon (hash, t);
7966 : 950574 : if (t != probe_type)
7967 : : return t;
7968 : :
7969 : 194688 : if (!COMPLETE_TYPE_P (t))
7970 : 0 : layout_type (t);
7971 : :
7972 : 194688 : if (TYPE_CANONICAL (t) == t)
7973 : : {
7974 : 194684 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7975 : 194684 : || TYPE_STRUCTURAL_EQUALITY_P (type))
7976 : 0 : gcc_unreachable ();
7977 : 194684 : else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
7978 : 194684 : || TYPE_CANONICAL (type) != type)
7979 : 115062 : TYPE_CANONICAL (t)
7980 : 230124 : = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
7981 : 115062 : TYPE_CANONICAL (type));
7982 : : }
7983 : :
7984 : : return t;
7985 : : }
7986 : :
7987 : : /* Create a complex type whose components are COMPONENT_TYPE.
7988 : :
7989 : : If NAMED is true, the type is given a TYPE_NAME. We do not always
7990 : : do so because this creates a DECL node and thus make the DECL_UIDs
7991 : : dependent on the type canonicalization hashtable, which is GC-ed,
7992 : : so the DECL_UIDs would not be stable wrt garbage collection. */
7993 : :
7994 : : tree
7995 : 5223225 : build_complex_type (tree component_type, bool named)
7996 : : {
7997 : 5223225 : gcc_assert (INTEGRAL_TYPE_P (component_type)
7998 : : || SCALAR_FLOAT_TYPE_P (component_type)
7999 : : || FIXED_POINT_TYPE_P (component_type));
8000 : :
8001 : : /* Make a node of the sort we want. */
8002 : 5223225 : tree probe = make_node (COMPLEX_TYPE);
8003 : :
8004 : 5223225 : TREE_TYPE (probe) = TYPE_MAIN_VARIANT (component_type);
8005 : 5223225 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (probe)))
8006 : 0 : SET_TYPE_STRUCTURAL_EQUALITY (probe);
8007 : :
8008 : : /* If we already have such a type, use the old one. */
8009 : 5223225 : hashval_t hash = type_hash_canon_hash (probe);
8010 : 5223225 : tree t = type_hash_canon (hash, probe);
8011 : :
8012 : 5223225 : if (t == probe)
8013 : : {
8014 : : /* We created a new type. The hash insertion will have laid
8015 : : out the type. We need to check the canonicalization and
8016 : : maybe set the name. */
8017 : 3133444 : gcc_checking_assert (COMPLETE_TYPE_P (t)
8018 : : && !TYPE_NAME (t));
8019 : :
8020 : 3133444 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t)))
8021 : : ;
8022 : 3133444 : else if (TYPE_CANONICAL (TREE_TYPE (t)) != TREE_TYPE (t))
8023 : 101 : TYPE_CANONICAL (t)
8024 : 202 : = build_complex_type (TYPE_CANONICAL (TREE_TYPE (t)), named);
8025 : :
8026 : : /* We need to create a name, since complex is a fundamental type. */
8027 : 3133444 : if (named)
8028 : : {
8029 : 1155052 : const char *name = NULL;
8030 : :
8031 : 1155052 : if (TREE_TYPE (t) == char_type_node)
8032 : : name = "complex char";
8033 : 1155052 : else if (TREE_TYPE (t) == signed_char_type_node)
8034 : : name = "complex signed char";
8035 : 1155052 : else if (TREE_TYPE (t) == unsigned_char_type_node)
8036 : : name = "complex unsigned char";
8037 : 1155052 : else if (TREE_TYPE (t) == short_integer_type_node)
8038 : : name = "complex short int";
8039 : 1155052 : else if (TREE_TYPE (t) == short_unsigned_type_node)
8040 : : name = "complex short unsigned int";
8041 : 1155052 : else if (TREE_TYPE (t) == integer_type_node)
8042 : : name = "complex int";
8043 : 866289 : else if (TREE_TYPE (t) == unsigned_type_node)
8044 : : name = "complex unsigned int";
8045 : 866289 : else if (TREE_TYPE (t) == long_integer_type_node)
8046 : : name = "complex long int";
8047 : 866289 : else if (TREE_TYPE (t) == long_unsigned_type_node)
8048 : : name = "complex long unsigned int";
8049 : 866289 : else if (TREE_TYPE (t) == long_long_integer_type_node)
8050 : : name = "complex long long int";
8051 : 866289 : else if (TREE_TYPE (t) == long_long_unsigned_type_node)
8052 : : name = "complex long long unsigned int";
8053 : :
8054 : : if (name != NULL)
8055 : 288763 : TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
8056 : : get_identifier (name), t);
8057 : : }
8058 : : }
8059 : :
8060 : 5223225 : return build_qualified_type (t, TYPE_QUALS (component_type));
8061 : : }
8062 : :
8063 : : /* If TYPE is a real or complex floating-point type and the target
8064 : : does not directly support arithmetic on TYPE then return the wider
8065 : : type to be used for arithmetic on TYPE. Otherwise, return
8066 : : NULL_TREE. */
8067 : :
8068 : : tree
8069 : 90921228 : excess_precision_type (tree type)
8070 : : {
8071 : : /* The target can give two different responses to the question of
8072 : : which excess precision mode it would like depending on whether we
8073 : : are in -fexcess-precision=standard or -fexcess-precision=fast. */
8074 : :
8075 : 3294237 : enum excess_precision_type requested_type
8076 : 90921228 : = (flag_excess_precision == EXCESS_PRECISION_FAST
8077 : 90921228 : ? EXCESS_PRECISION_TYPE_FAST
8078 : : : (flag_excess_precision == EXCESS_PRECISION_FLOAT16
8079 : 3294306 : ? EXCESS_PRECISION_TYPE_FLOAT16 : EXCESS_PRECISION_TYPE_STANDARD));
8080 : :
8081 : 90921228 : enum flt_eval_method target_flt_eval_method
8082 : 90921228 : = targetm.c.excess_precision (requested_type);
8083 : :
8084 : : /* The target should not ask for unpredictable float evaluation (though
8085 : : it might advertise that implicitly the evaluation is unpredictable,
8086 : : but we don't care about that here, it will have been reported
8087 : : elsewhere). If it does ask for unpredictable evaluation, we have
8088 : : nothing to do here. */
8089 : 90921228 : gcc_assert (target_flt_eval_method != FLT_EVAL_METHOD_UNPREDICTABLE);
8090 : :
8091 : : /* Nothing to do. The target has asked for all types we know about
8092 : : to be computed with their native precision and range. */
8093 : 90921228 : if (target_flt_eval_method == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
8094 : : return NULL_TREE;
8095 : :
8096 : : /* The target will promote this type in a target-dependent way, so excess
8097 : : precision ought to leave it alone. */
8098 : 89539787 : if (targetm.promoted_type (type) != NULL_TREE)
8099 : : return NULL_TREE;
8100 : :
8101 : 89539787 : machine_mode float16_type_mode = (float16_type_node
8102 : 89539787 : ? TYPE_MODE (float16_type_node)
8103 : 89539787 : : VOIDmode);
8104 : 89539787 : machine_mode bfloat16_type_mode = (bfloat16_type_node
8105 : 89539787 : ? TYPE_MODE (bfloat16_type_node)
8106 : 89539787 : : VOIDmode);
8107 : 89539787 : machine_mode float_type_mode = TYPE_MODE (float_type_node);
8108 : 89539787 : machine_mode double_type_mode = TYPE_MODE (double_type_node);
8109 : :
8110 : 89539787 : switch (TREE_CODE (type))
8111 : : {
8112 : 62244613 : case REAL_TYPE:
8113 : 62244613 : {
8114 : 62244613 : machine_mode type_mode = TYPE_MODE (type);
8115 : 62244613 : switch (target_flt_eval_method)
8116 : : {
8117 : 62231780 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8118 : 62231780 : if (type_mode == float16_type_mode
8119 : 62231780 : || type_mode == bfloat16_type_mode)
8120 : 301950 : return float_type_node;
8121 : : break;
8122 : 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8123 : 0 : if (type_mode == float16_type_mode
8124 : 0 : || type_mode == bfloat16_type_mode
8125 : 0 : || type_mode == float_type_mode)
8126 : 0 : return double_type_node;
8127 : : break;
8128 : 12833 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8129 : 12833 : if (type_mode == float16_type_mode
8130 : 12833 : || type_mode == bfloat16_type_mode
8131 : 12828 : || type_mode == float_type_mode
8132 : 12828 : || type_mode == double_type_mode)
8133 : 12384 : return long_double_type_node;
8134 : : break;
8135 : 0 : default:
8136 : 0 : gcc_unreachable ();
8137 : : }
8138 : : break;
8139 : : }
8140 : 387564 : case COMPLEX_TYPE:
8141 : 387564 : {
8142 : 387564 : if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
8143 : : return NULL_TREE;
8144 : 378084 : machine_mode type_mode = TYPE_MODE (TREE_TYPE (type));
8145 : 378084 : switch (target_flt_eval_method)
8146 : : {
8147 : 377751 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8148 : 377751 : if (type_mode == float16_type_mode
8149 : 377751 : || type_mode == bfloat16_type_mode)
8150 : 271 : return complex_float_type_node;
8151 : : break;
8152 : 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8153 : 0 : if (type_mode == float16_type_mode
8154 : 0 : || type_mode == bfloat16_type_mode
8155 : 0 : || type_mode == float_type_mode)
8156 : 0 : return complex_double_type_node;
8157 : : break;
8158 : 333 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8159 : 333 : if (type_mode == float16_type_mode
8160 : 333 : || type_mode == bfloat16_type_mode
8161 : 333 : || type_mode == float_type_mode
8162 : 333 : || type_mode == double_type_mode)
8163 : 281 : return complex_long_double_type_node;
8164 : : break;
8165 : 0 : default:
8166 : 0 : gcc_unreachable ();
8167 : : }
8168 : : break;
8169 : : }
8170 : : default:
8171 : : break;
8172 : : }
8173 : :
8174 : : return NULL_TREE;
8175 : : }
8176 : :
8177 : : /* Return OP, stripped of any conversions to wider types as much as is safe.
8178 : : Converting the value back to OP's type makes a value equivalent to OP.
8179 : :
8180 : : If FOR_TYPE is nonzero, we return a value which, if converted to
8181 : : type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8182 : :
8183 : : OP must have integer, real or enumeral type. Pointers are not allowed!
8184 : :
8185 : : There are some cases where the obvious value we could return
8186 : : would regenerate to OP if converted to OP's type,
8187 : : but would not extend like OP to wider types.
8188 : : If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8189 : : For example, if OP is (unsigned short)(signed char)-1,
8190 : : we avoid returning (signed char)-1 if FOR_TYPE is int,
8191 : : even though extending that to an unsigned short would regenerate OP,
8192 : : since the result of extending (signed char)-1 to (int)
8193 : : is different from (int) OP. */
8194 : :
8195 : : tree
8196 : 10417971 : get_unwidened (tree op, tree for_type)
8197 : : {
8198 : : /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8199 : 10417971 : tree type = TREE_TYPE (op);
8200 : 10417971 : unsigned final_prec
8201 : 17987714 : = TYPE_PRECISION (for_type != 0 ? for_type : type);
8202 : 10417971 : int uns
8203 : 10417971 : = (for_type != 0 && for_type != type
8204 : 2527595 : && final_prec > TYPE_PRECISION (type)
8205 : 10488166 : && TYPE_UNSIGNED (type));
8206 : 10417971 : tree win = op;
8207 : :
8208 : 10620152 : while (CONVERT_EXPR_P (op))
8209 : : {
8210 : 202210 : int bitschange;
8211 : :
8212 : : /* TYPE_PRECISION on vector types has different meaning
8213 : : (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8214 : : so avoid them here. */
8215 : 202210 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
8216 : : break;
8217 : :
8218 : 202210 : bitschange = TYPE_PRECISION (TREE_TYPE (op))
8219 : 202210 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
8220 : :
8221 : : /* Truncations are many-one so cannot be removed.
8222 : : Unless we are later going to truncate down even farther. */
8223 : 202210 : if (bitschange < 0
8224 : 202210 : && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
8225 : : break;
8226 : :
8227 : : /* See what's inside this conversion. If we decide to strip it,
8228 : : we will set WIN. */
8229 : 202181 : op = TREE_OPERAND (op, 0);
8230 : :
8231 : : /* If we have not stripped any zero-extensions (uns is 0),
8232 : : we can strip any kind of extension.
8233 : : If we have previously stripped a zero-extension,
8234 : : only zero-extensions can safely be stripped.
8235 : : Any extension can be stripped if the bits it would produce
8236 : : are all going to be discarded later by truncating to FOR_TYPE. */
8237 : :
8238 : 202181 : if (bitschange > 0)
8239 : : {
8240 : 112220 : if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
8241 : : win = op;
8242 : : /* TYPE_UNSIGNED says whether this is a zero-extension.
8243 : : Let's avoid computing it if it does not affect WIN
8244 : : and if UNS will not be needed again. */
8245 : 112220 : if ((uns
8246 : 112189 : || CONVERT_EXPR_P (op))
8247 : 112761 : && TYPE_UNSIGNED (TREE_TYPE (op)))
8248 : : {
8249 : : uns = 1;
8250 : : win = op;
8251 : : }
8252 : : }
8253 : : }
8254 : :
8255 : : /* If we finally reach a constant see if it fits in sth smaller and
8256 : : in that case convert it. */
8257 : 10417971 : if (TREE_CODE (win) == INTEGER_CST)
8258 : : {
8259 : 437558 : tree wtype = TREE_TYPE (win);
8260 : 437558 : unsigned prec = wi::min_precision (wi::to_wide (win), TYPE_SIGN (wtype));
8261 : 437558 : if (for_type)
8262 : 432798 : prec = MAX (prec, final_prec);
8263 : 437558 : if (prec < TYPE_PRECISION (wtype))
8264 : : {
8265 : 431153 : tree t = lang_hooks.types.type_for_size (prec, TYPE_UNSIGNED (wtype));
8266 : 431153 : if (t && TYPE_PRECISION (t) < TYPE_PRECISION (wtype))
8267 : 425395 : win = fold_convert (t, win);
8268 : : }
8269 : : }
8270 : :
8271 : 10417971 : return win;
8272 : : }
8273 : :
8274 : : /* Return OP or a simpler expression for a narrower value
8275 : : which can be sign-extended or zero-extended to give back OP.
8276 : : Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8277 : : or 0 if the value should be sign-extended. */
8278 : :
8279 : : tree
8280 : 65748958 : get_narrower (tree op, int *unsignedp_ptr)
8281 : : {
8282 : 65748958 : int uns = 0;
8283 : 65748958 : bool first = true;
8284 : 65748958 : tree win = op;
8285 : 65748958 : bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
8286 : :
8287 : 65748958 : if (TREE_CODE (op) == COMPOUND_EXPR)
8288 : : {
8289 : 87815 : do
8290 : 87815 : op = TREE_OPERAND (op, 1);
8291 : 87815 : while (TREE_CODE (op) == COMPOUND_EXPR);
8292 : 87800 : tree ret = get_narrower (op, unsignedp_ptr);
8293 : 87800 : if (ret == op)
8294 : : return win;
8295 : 4264 : auto_vec <tree, 16> v;
8296 : 4264 : unsigned int i;
8297 : 8535 : for (op = win; TREE_CODE (op) == COMPOUND_EXPR;
8298 : 4271 : op = TREE_OPERAND (op, 1))
8299 : 4271 : v.safe_push (op);
8300 : 12799 : FOR_EACH_VEC_ELT_REVERSE (v, i, op)
8301 : 4271 : ret = build2_loc (EXPR_LOCATION (op), COMPOUND_EXPR,
8302 : 4271 : TREE_TYPE (ret), TREE_OPERAND (op, 0),
8303 : : ret);
8304 : 4264 : return ret;
8305 : 4264 : }
8306 : 78367677 : while (TREE_CODE (op) == NOP_EXPR)
8307 : : {
8308 : 12740327 : int bitschange
8309 : 12740327 : = (TYPE_PRECISION (TREE_TYPE (op))
8310 : 12740327 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
8311 : :
8312 : : /* Truncations are many-one so cannot be removed. */
8313 : 12740327 : if (bitschange < 0)
8314 : : break;
8315 : :
8316 : : /* See what's inside this conversion. If we decide to strip it,
8317 : : we will set WIN. */
8318 : :
8319 : 12706615 : if (bitschange > 0)
8320 : : {
8321 : 3055773 : op = TREE_OPERAND (op, 0);
8322 : : /* An extension: the outermost one can be stripped,
8323 : : but remember whether it is zero or sign extension. */
8324 : 3055773 : if (first)
8325 : 3052556 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8326 : : /* Otherwise, if a sign extension has been stripped,
8327 : : only sign extensions can now be stripped;
8328 : : if a zero extension has been stripped, only zero-extensions. */
8329 : 3217 : else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
8330 : : break;
8331 : : first = false;
8332 : : }
8333 : : else /* bitschange == 0 */
8334 : : {
8335 : : /* A change in nominal type can always be stripped, but we must
8336 : : preserve the unsignedness. */
8337 : 9650842 : if (first)
8338 : 9105325 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8339 : 9650842 : first = false;
8340 : 9650842 : op = TREE_OPERAND (op, 0);
8341 : : /* Keep trying to narrow, but don't assign op to win if it
8342 : : would turn an integral type into something else. */
8343 : 17526470 : if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
8344 : 102091 : continue;
8345 : : }
8346 : :
8347 : 12604428 : win = op;
8348 : : }
8349 : :
8350 : 65661158 : if (TREE_CODE (op) == COMPONENT_REF
8351 : : /* Since type_for_size always gives an integer type. */
8352 : 2356644 : && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
8353 : 2253622 : && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE
8354 : : /* Ensure field is laid out already. */
8355 : 2253622 : && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
8356 : 67914777 : && tree_fits_uhwi_p (DECL_SIZE (TREE_OPERAND (op, 1))))
8357 : : {
8358 : 2253619 : unsigned HOST_WIDE_INT innerprec
8359 : 2253619 : = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (op, 1)));
8360 : 2253619 : int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
8361 : 2253619 : || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
8362 : 2253619 : tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
8363 : :
8364 : : /* We can get this structure field in a narrower type that fits it,
8365 : : but the resulting extension to its nominal type (a fullword type)
8366 : : must satisfy the same conditions as for other extensions.
8367 : :
8368 : : Do this only for fields that are aligned (not bit-fields),
8369 : : because when bit-field insns will be used there is no
8370 : : advantage in doing this. */
8371 : :
8372 : 2253619 : if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
8373 : 0 : && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
8374 : 0 : && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
8375 : 2253619 : && type != 0)
8376 : : {
8377 : 0 : if (first)
8378 : 0 : uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
8379 : 0 : win = fold_convert (type, op);
8380 : : }
8381 : : }
8382 : :
8383 : 65661158 : *unsignedp_ptr = uns;
8384 : 65661158 : return win;
8385 : : }
8386 : :
8387 : : /* Return true if integer constant C has a value that is permissible
8388 : : for TYPE, an integral type. */
8389 : :
8390 : : bool
8391 : 119914577 : int_fits_type_p (const_tree c, const_tree type)
8392 : : {
8393 : 119914577 : tree type_low_bound, type_high_bound;
8394 : 119914577 : bool ok_for_low_bound, ok_for_high_bound;
8395 : 119914577 : signop sgn_c = TYPE_SIGN (TREE_TYPE (c));
8396 : :
8397 : : /* Non-standard boolean types can have arbitrary precision but various
8398 : : transformations assume that they can only take values 0 and +/-1. */
8399 : 119914577 : if (TREE_CODE (type) == BOOLEAN_TYPE)
8400 : 1063892 : return wi::fits_to_boolean_p (wi::to_wide (c), type);
8401 : :
8402 : 118850685 : retry:
8403 : 118862520 : type_low_bound = TYPE_MIN_VALUE (type);
8404 : 118862520 : type_high_bound = TYPE_MAX_VALUE (type);
8405 : :
8406 : : /* If at least one bound of the type is a constant integer, we can check
8407 : : ourselves and maybe make a decision. If no such decision is possible, but
8408 : : this type is a subtype, try checking against that. Otherwise, use
8409 : : fits_to_tree_p, which checks against the precision.
8410 : :
8411 : : Compute the status for each possibly constant bound, and return if we see
8412 : : one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8413 : : for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8414 : : for "constant known to fit". */
8415 : :
8416 : : /* Check if c >= type_low_bound. */
8417 : 118862520 : if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
8418 : : {
8419 : 118862520 : if (tree_int_cst_lt (c, type_low_bound))
8420 : : return false;
8421 : : ok_for_low_bound = true;
8422 : : }
8423 : : else
8424 : : ok_for_low_bound = false;
8425 : :
8426 : : /* Check if c <= type_high_bound. */
8427 : 118617861 : if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
8428 : : {
8429 : 118586374 : if (tree_int_cst_lt (type_high_bound, c))
8430 : : return false;
8431 : : ok_for_high_bound = true;
8432 : : }
8433 : : else
8434 : : ok_for_high_bound = false;
8435 : :
8436 : : /* If the constant fits both bounds, the result is known. */
8437 : 116854745 : if (ok_for_low_bound && ok_for_high_bound)
8438 : : return true;
8439 : :
8440 : : /* Perform some generic filtering which may allow making a decision
8441 : : even if the bounds are not constant. First, negative integers
8442 : : never fit in unsigned types, */
8443 : 31487 : if (TYPE_UNSIGNED (type) && sgn_c == SIGNED && wi::neg_p (wi::to_wide (c)))
8444 : 0 : return false;
8445 : :
8446 : : /* Second, narrower types always fit in wider ones. */
8447 : 31487 : if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
8448 : : return true;
8449 : :
8450 : : /* Third, unsigned integers with top bit set never fit signed types. */
8451 : 11844 : if (!TYPE_UNSIGNED (type) && sgn_c == UNSIGNED)
8452 : : {
8453 : 14 : int prec = GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (c))) - 1;
8454 : 14 : if (prec < TYPE_PRECISION (TREE_TYPE (c)))
8455 : : {
8456 : : /* When a tree_cst is converted to a wide-int, the precision
8457 : : is taken from the type. However, if the precision of the
8458 : : mode underneath the type is smaller than that, it is
8459 : : possible that the value will not fit. The test below
8460 : : fails if any bit is set between the sign bit of the
8461 : : underlying mode and the top bit of the type. */
8462 : 14 : if (wi::zext (wi::to_wide (c), prec - 1) != wi::to_wide (c))
8463 : : return false;
8464 : : }
8465 : 0 : else if (wi::neg_p (wi::to_wide (c)))
8466 : : return false;
8467 : : }
8468 : :
8469 : : /* If we haven't been able to decide at this point, there nothing more we
8470 : : can check ourselves here. Look at the base type if we have one and it
8471 : : has the same precision. */
8472 : 11835 : if (TREE_CODE (type) == INTEGER_TYPE
8473 : 11835 : && TREE_TYPE (type) != 0
8474 : 23670 : && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
8475 : : {
8476 : 11835 : type = TREE_TYPE (type);
8477 : 11835 : goto retry;
8478 : : }
8479 : :
8480 : : /* Or to fits_to_tree_p, if nothing else. */
8481 : 0 : return wi::fits_to_tree_p (wi::to_wide (c), type);
8482 : : }
8483 : :
8484 : : /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8485 : : bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8486 : : represented (assuming two's-complement arithmetic) within the bit
8487 : : precision of the type are returned instead. */
8488 : :
8489 : : void
8490 : 21147849 : get_type_static_bounds (const_tree type, mpz_t min, mpz_t max)
8491 : : {
8492 : 19670835 : if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type)
8493 : 40818684 : && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
8494 : 19670835 : wi::to_mpz (wi::to_wide (TYPE_MIN_VALUE (type)), min, TYPE_SIGN (type));
8495 : : else
8496 : : {
8497 : 1477014 : if (TYPE_UNSIGNED (type))
8498 : 1477014 : mpz_set_ui (min, 0);
8499 : : else
8500 : : {
8501 : 0 : wide_int mn = wi::min_value (TYPE_PRECISION (type), SIGNED);
8502 : 0 : wi::to_mpz (mn, min, SIGNED);
8503 : 0 : }
8504 : : }
8505 : :
8506 : 19670835 : if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
8507 : 40818684 : && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
8508 : 19670835 : wi::to_mpz (wi::to_wide (TYPE_MAX_VALUE (type)), max, TYPE_SIGN (type));
8509 : : else
8510 : : {
8511 : 1477014 : wide_int mn = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
8512 : 1477014 : wi::to_mpz (mn, max, TYPE_SIGN (type));
8513 : 1477014 : }
8514 : 21147849 : }
8515 : :
8516 : : /* Return true if VAR is an automatic variable. */
8517 : :
8518 : : bool
8519 : 370815671 : auto_var_p (const_tree var)
8520 : : {
8521 : 208009509 : return ((((VAR_P (var) && ! DECL_EXTERNAL (var))
8522 : 166156588 : || TREE_CODE (var) == PARM_DECL)
8523 : 263936387 : && ! TREE_STATIC (var))
8524 : 486239783 : || TREE_CODE (var) == RESULT_DECL);
8525 : : }
8526 : :
8527 : : /* Return true if VAR is an automatic variable defined in function FN. */
8528 : :
8529 : : bool
8530 : 1073863481 : auto_var_in_fn_p (const_tree var, const_tree fn)
8531 : : {
8532 : 342919097 : return (DECL_P (var) && DECL_CONTEXT (var) == fn
8533 : 1318416047 : && (auto_var_p (var)
8534 : 4297281 : || TREE_CODE (var) == LABEL_DECL));
8535 : : }
8536 : :
8537 : : /* Subprogram of following function. Called by walk_tree.
8538 : :
8539 : : Return *TP if it is an automatic variable or parameter of the
8540 : : function passed in as DATA. */
8541 : :
8542 : : static tree
8543 : 122956 : find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
8544 : : {
8545 : 122956 : tree fn = (tree) data;
8546 : :
8547 : 122956 : if (TYPE_P (*tp))
8548 : 0 : *walk_subtrees = 0;
8549 : :
8550 : 122956 : else if (DECL_P (*tp)
8551 : 122956 : && auto_var_in_fn_p (*tp, fn))
8552 : 114248 : return *tp;
8553 : :
8554 : : return NULL_TREE;
8555 : : }
8556 : :
8557 : : /* Returns true if T is, contains, or refers to a type with variable
8558 : : size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8559 : : arguments, but not the return type. If FN is nonzero, only return
8560 : : true if a modifier of the type or position of FN is a variable or
8561 : : parameter inside FN.
8562 : :
8563 : : This concept is more general than that of C99 'variably modified types':
8564 : : in C99, a struct type is never variably modified because a VLA may not
8565 : : appear as a structure member. However, in GNU C code like:
8566 : :
8567 : : struct S { int i[f()]; };
8568 : :
8569 : : is valid, and other languages may define similar constructs. */
8570 : :
8571 : : bool
8572 : 1821429583 : variably_modified_type_p (tree type, tree fn)
8573 : : {
8574 : 1821429583 : tree t;
8575 : :
8576 : : /* Test if T is either variable (if FN is zero) or an expression containing
8577 : : a variable in FN. If TYPE isn't gimplified, return true also if
8578 : : gimplify_one_sizepos would gimplify the expression into a local
8579 : : variable. */
8580 : : #define RETURN_TRUE_IF_VAR(T) \
8581 : : do { tree _t = (T); \
8582 : : if (_t != NULL_TREE \
8583 : : && _t != error_mark_node \
8584 : : && !CONSTANT_CLASS_P (_t) \
8585 : : && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8586 : : && (!fn \
8587 : : || (!TYPE_SIZES_GIMPLIFIED (type) \
8588 : : && (TREE_CODE (_t) != VAR_DECL \
8589 : : && !CONTAINS_PLACEHOLDER_P (_t))) \
8590 : : || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8591 : : return true; } while (0)
8592 : :
8593 : 1821429583 : if (type == error_mark_node)
8594 : : return false;
8595 : :
8596 : : /* If TYPE itself has variable size, it is variably modified. */
8597 : 1821168375 : RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
8598 : 1821044623 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
8599 : :
8600 : 1821043999 : switch (TREE_CODE (type))
8601 : : {
8602 : 506310648 : case POINTER_TYPE:
8603 : 506310648 : case REFERENCE_TYPE:
8604 : 506310648 : case VECTOR_TYPE:
8605 : : /* Ada can have pointer types refering to themselves indirectly. */
8606 : 506310648 : if (TREE_VISITED (type))
8607 : : return false;
8608 : 506310648 : TREE_VISITED (type) = true;
8609 : 506310648 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8610 : : {
8611 : 78120 : TREE_VISITED (type) = false;
8612 : 78120 : return true;
8613 : : }
8614 : 506232528 : TREE_VISITED (type) = false;
8615 : 506232528 : break;
8616 : :
8617 : 89195104 : case FUNCTION_TYPE:
8618 : 89195104 : case METHOD_TYPE:
8619 : : /* If TYPE is a function type, it is variably modified if the
8620 : : return type is variably modified. */
8621 : 89195104 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8622 : : return true;
8623 : : break;
8624 : :
8625 : 437969844 : case INTEGER_TYPE:
8626 : 437969844 : case REAL_TYPE:
8627 : 437969844 : case FIXED_POINT_TYPE:
8628 : 437969844 : case ENUMERAL_TYPE:
8629 : 437969844 : case BOOLEAN_TYPE:
8630 : : /* Scalar types are variably modified if their end points
8631 : : aren't constant. */
8632 : 437969844 : RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
8633 : 437969844 : RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
8634 : 437935619 : break;
8635 : :
8636 : 645147665 : case RECORD_TYPE:
8637 : 645147665 : case UNION_TYPE:
8638 : 645147665 : case QUAL_UNION_TYPE:
8639 : : /* We can't see if any of the fields are variably-modified by the
8640 : : definition we normally use, since that would produce infinite
8641 : : recursion via pointers. */
8642 : : /* This is variably modified if some field's type is. */
8643 : 29565856856 : for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
8644 : 28920709191 : if (TREE_CODE (t) == FIELD_DECL)
8645 : : {
8646 : 984894146 : RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
8647 : 984894146 : RETURN_TRUE_IF_VAR (DECL_SIZE (t));
8648 : 984894146 : RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
8649 : :
8650 : : /* If the type is a qualified union, then the DECL_QUALIFIER
8651 : : of fields can also be an expression containing a variable. */
8652 : 984894146 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
8653 : 0 : RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
8654 : :
8655 : : /* If the field is a qualified union, then it's only a container
8656 : : for what's inside so we look into it. That's necessary in LTO
8657 : : mode because the sizes of the field tested above have been set
8658 : : to PLACEHOLDER_EXPRs by free_lang_data. */
8659 : 984894146 : if (TREE_CODE (TREE_TYPE (t)) == QUAL_UNION_TYPE
8660 : 984894146 : && variably_modified_type_p (TREE_TYPE (t), fn))
8661 : : return true;
8662 : : }
8663 : : break;
8664 : :
8665 : 11628230 : case ARRAY_TYPE:
8666 : : /* Do not call ourselves to avoid infinite recursion. This is
8667 : : variably modified if the element type is. */
8668 : 11628230 : RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
8669 : 11624695 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
8670 : 11624677 : break;
8671 : :
8672 : : default:
8673 : : break;
8674 : : }
8675 : :
8676 : : /* The current language may have other cases to check, but in general,
8677 : : all other types are not variably modified. */
8678 : 1820927871 : return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
8679 : :
8680 : : #undef RETURN_TRUE_IF_VAR
8681 : : }
8682 : :
8683 : : /* Given a DECL or TYPE, return the scope in which it was declared, or
8684 : : NULL_TREE if there is no containing scope. */
8685 : :
8686 : : tree
8687 : 2374843684 : get_containing_scope (const_tree t)
8688 : : {
8689 : 2374843684 : return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
8690 : : }
8691 : :
8692 : : /* Returns the ultimate TRANSLATION_UNIT_DECL context of DECL or NULL. */
8693 : :
8694 : : const_tree
8695 : 13300 : get_ultimate_context (const_tree decl)
8696 : : {
8697 : 35781 : while (decl && TREE_CODE (decl) != TRANSLATION_UNIT_DECL)
8698 : : {
8699 : 22481 : if (TREE_CODE (decl) == BLOCK)
8700 : 0 : decl = BLOCK_SUPERCONTEXT (decl);
8701 : : else
8702 : 22481 : decl = get_containing_scope (decl);
8703 : : }
8704 : 13300 : return decl;
8705 : : }
8706 : :
8707 : : /* Return the innermost context enclosing DECL that is
8708 : : a FUNCTION_DECL, or zero if none. */
8709 : :
8710 : : tree
8711 : 1296607652 : decl_function_context (const_tree decl)
8712 : : {
8713 : 1296607652 : tree context;
8714 : :
8715 : 1296607652 : if (TREE_CODE (decl) == ERROR_MARK)
8716 : : return 0;
8717 : :
8718 : : /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8719 : : where we look up the function at runtime. Such functions always take
8720 : : a first argument of type 'pointer to real context'.
8721 : :
8722 : : C++ should really be fixed to use DECL_CONTEXT for the real context,
8723 : : and use something else for the "virtual context". */
8724 : 1296607652 : else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
8725 : 4295891 : context
8726 : 4295891 : = TYPE_MAIN_VARIANT
8727 : : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
8728 : : else
8729 : 1292311761 : context = DECL_CONTEXT (decl);
8730 : :
8731 : 2954132471 : while (context && TREE_CODE (context) != FUNCTION_DECL)
8732 : : {
8733 : 1657524819 : if (TREE_CODE (context) == BLOCK)
8734 : 0 : context = BLOCK_SUPERCONTEXT (context);
8735 : : else
8736 : 1657524819 : context = get_containing_scope (context);
8737 : : }
8738 : :
8739 : : return context;
8740 : : }
8741 : :
8742 : : /* Return the innermost context enclosing DECL that is
8743 : : a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8744 : : TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8745 : :
8746 : : tree
8747 : 68858048 : decl_type_context (const_tree decl)
8748 : : {
8749 : 68858048 : tree context = DECL_CONTEXT (decl);
8750 : :
8751 : 71434099 : while (context)
8752 : 65824876 : switch (TREE_CODE (context))
8753 : : {
8754 : : case NAMESPACE_DECL:
8755 : : case TRANSLATION_UNIT_DECL:
8756 : : return NULL_TREE;
8757 : :
8758 : : case RECORD_TYPE:
8759 : : case UNION_TYPE:
8760 : : case QUAL_UNION_TYPE:
8761 : : return context;
8762 : :
8763 : 2576051 : case TYPE_DECL:
8764 : 2576051 : case FUNCTION_DECL:
8765 : 2576051 : context = DECL_CONTEXT (context);
8766 : 2576051 : break;
8767 : :
8768 : 0 : case BLOCK:
8769 : 0 : context = BLOCK_SUPERCONTEXT (context);
8770 : 0 : break;
8771 : :
8772 : 0 : default:
8773 : 0 : gcc_unreachable ();
8774 : : }
8775 : :
8776 : : return NULL_TREE;
8777 : : }
8778 : :
8779 : : /* CALL is a CALL_EXPR. Return the declaration for the function
8780 : : called, or NULL_TREE if the called function cannot be
8781 : : determined. */
8782 : :
8783 : : tree
8784 : 971876821 : get_callee_fndecl (const_tree call)
8785 : : {
8786 : 971876821 : tree addr;
8787 : :
8788 : 971876821 : if (call == error_mark_node)
8789 : : return error_mark_node;
8790 : :
8791 : : /* It's invalid to call this function with anything but a
8792 : : CALL_EXPR. */
8793 : 971876821 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8794 : :
8795 : : /* The first operand to the CALL is the address of the function
8796 : : called. */
8797 : 971876821 : addr = CALL_EXPR_FN (call);
8798 : :
8799 : : /* If there is no function, return early. */
8800 : 971876821 : if (addr == NULL_TREE)
8801 : : return NULL_TREE;
8802 : :
8803 : 969703978 : STRIP_NOPS (addr);
8804 : :
8805 : : /* If this is a readonly function pointer, extract its initial value. */
8806 : 16543030 : if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
8807 : 1706097 : && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
8808 : 969876794 : && DECL_INITIAL (addr))
8809 : 172723 : addr = DECL_INITIAL (addr);
8810 : :
8811 : : /* If the address is just `&f' for some function `f', then we know
8812 : : that `f' is being called. */
8813 : 969703978 : if (TREE_CODE (addr) == ADDR_EXPR
8814 : 969703978 : && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
8815 : 926645672 : return TREE_OPERAND (addr, 0);
8816 : :
8817 : : /* We couldn't figure out what was being called. */
8818 : : return NULL_TREE;
8819 : : }
8820 : :
8821 : : /* Return true when STMTs arguments and return value match those of FNDECL,
8822 : : a decl of a builtin function. */
8823 : :
8824 : : static bool
8825 : 5281842 : tree_builtin_call_types_compatible_p (const_tree call, tree fndecl)
8826 : : {
8827 : 5281842 : gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN);
8828 : :
8829 : 5281842 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
8830 : 5281842 : if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
8831 : 5281842 : fndecl = decl;
8832 : :
8833 : 5281842 : bool gimple_form = (cfun && (cfun->curr_properties & PROP_gimple)) != 0;
8834 : 5281842 : if (gimple_form
8835 : 12989 : ? !useless_type_conversion_p (TREE_TYPE (call),
8836 : 12989 : TREE_TYPE (TREE_TYPE (fndecl)))
8837 : 5268853 : : (TYPE_MAIN_VARIANT (TREE_TYPE (call))
8838 : 5268853 : != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))))
8839 : : return false;
8840 : :
8841 : 5281626 : tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
8842 : 5281626 : unsigned nargs = call_expr_nargs (call);
8843 : 14050906 : for (unsigned i = 0; i < nargs; ++i, targs = TREE_CHAIN (targs))
8844 : : {
8845 : : /* Variadic args follow. */
8846 : 9717552 : if (!targs)
8847 : : return true;
8848 : 8769961 : tree arg = CALL_EXPR_ARG (call, i);
8849 : 8769961 : tree type = TREE_VALUE (targs);
8850 : 8769961 : if (gimple_form
8851 : 8769961 : ? !useless_type_conversion_p (type, TREE_TYPE (arg))
8852 : 8756972 : : TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (TREE_TYPE (arg)))
8853 : : {
8854 : : /* For pointer arguments be more forgiving, e.g. due to
8855 : : FILE * vs. fileptr_type_node, or say char * vs. const char *
8856 : : differences etc. */
8857 : 1111575 : if (!gimple_form
8858 : 556128 : && POINTER_TYPE_P (type)
8859 : 555552 : && POINTER_TYPE_P (TREE_TYPE (arg))
8860 : 1111575 : && tree_nop_conversion_p (type, TREE_TYPE (arg)))
8861 : 555447 : continue;
8862 : 681 : return false;
8863 : : }
8864 : : }
8865 : 8666061 : if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
8866 : : return false;
8867 : : return true;
8868 : : }
8869 : :
8870 : : /* If CALL_EXPR CALL calls a normal built-in function or an internal function,
8871 : : return the associated function code, otherwise return CFN_LAST. */
8872 : :
8873 : : combined_fn
8874 : 39160747 : get_call_combined_fn (const_tree call)
8875 : : {
8876 : : /* It's invalid to call this function with anything but a CALL_EXPR. */
8877 : 39160747 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8878 : :
8879 : 39160747 : if (!CALL_EXPR_FN (call))
8880 : 65968 : return as_combined_fn (CALL_EXPR_IFN (call));
8881 : :
8882 : 39094779 : tree fndecl = get_callee_fndecl (call);
8883 : 39094779 : if (fndecl
8884 : 39074070 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
8885 : 44376621 : && tree_builtin_call_types_compatible_p (call, fndecl))
8886 : 5280940 : return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
8887 : :
8888 : : return CFN_LAST;
8889 : : }
8890 : :
8891 : : /* Comparator of indices based on tree_node_counts. */
8892 : :
8893 : : static int
8894 : 0 : tree_nodes_cmp (const void *p1, const void *p2)
8895 : : {
8896 : 0 : const unsigned *n1 = (const unsigned *)p1;
8897 : 0 : const unsigned *n2 = (const unsigned *)p2;
8898 : :
8899 : 0 : return tree_node_counts[*n1] - tree_node_counts[*n2];
8900 : : }
8901 : :
8902 : : /* Comparator of indices based on tree_code_counts. */
8903 : :
8904 : : static int
8905 : 0 : tree_codes_cmp (const void *p1, const void *p2)
8906 : : {
8907 : 0 : const unsigned *n1 = (const unsigned *)p1;
8908 : 0 : const unsigned *n2 = (const unsigned *)p2;
8909 : :
8910 : 0 : return tree_code_counts[*n1] - tree_code_counts[*n2];
8911 : : }
8912 : :
8913 : : #define TREE_MEM_USAGE_SPACES 40
8914 : :
8915 : : /* Print debugging information about tree nodes generated during the compile,
8916 : : and any language-specific information. */
8917 : :
8918 : : void
8919 : 0 : dump_tree_statistics (void)
8920 : : {
8921 : 0 : if (GATHER_STATISTICS)
8922 : : {
8923 : : uint64_t total_nodes, total_bytes;
8924 : : fprintf (stderr, "\nKind Nodes Bytes\n");
8925 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8926 : : total_nodes = total_bytes = 0;
8927 : :
8928 : : {
8929 : : auto_vec<unsigned> indices (all_kinds);
8930 : : for (unsigned i = 0; i < all_kinds; i++)
8931 : : indices.quick_push (i);
8932 : : indices.qsort (tree_nodes_cmp);
8933 : :
8934 : : for (unsigned i = 0; i < (int) all_kinds; i++)
8935 : : {
8936 : : unsigned j = indices[i];
8937 : : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n",
8938 : : tree_node_kind_names[j], SIZE_AMOUNT (tree_node_counts[j]),
8939 : : SIZE_AMOUNT (tree_node_sizes[j]));
8940 : : total_nodes += tree_node_counts[j];
8941 : : total_bytes += tree_node_sizes[j];
8942 : : }
8943 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8944 : : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n", "Total",
8945 : : SIZE_AMOUNT (total_nodes), SIZE_AMOUNT (total_bytes));
8946 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8947 : : }
8948 : :
8949 : : {
8950 : : fprintf (stderr, "Code Nodes\n");
8951 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8952 : :
8953 : : auto_vec<unsigned> indices (MAX_TREE_CODES);
8954 : : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8955 : : indices.quick_push (i);
8956 : : indices.qsort (tree_codes_cmp);
8957 : :
8958 : : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8959 : : {
8960 : : unsigned j = indices[i];
8961 : : fprintf (stderr, "%-32s %6" PRIu64 "%c\n",
8962 : : get_tree_code_name ((enum tree_code) j),
8963 : : SIZE_AMOUNT (tree_code_counts[j]));
8964 : : }
8965 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8966 : : fprintf (stderr, "\n");
8967 : : ssanames_print_statistics ();
8968 : : fprintf (stderr, "\n");
8969 : : phinodes_print_statistics ();
8970 : : fprintf (stderr, "\n");
8971 : : }
8972 : : }
8973 : : else
8974 : 0 : fprintf (stderr, "(No per-node statistics)\n");
8975 : :
8976 : 0 : print_type_hash_statistics ();
8977 : 0 : print_debug_expr_statistics ();
8978 : 0 : print_value_expr_statistics ();
8979 : 0 : lang_hooks.print_statistics ();
8980 : 0 : }
8981 : :
8982 : : #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
8983 : :
8984 : : /* Generate a crc32 of the low BYTES bytes of VALUE. */
8985 : :
8986 : : unsigned
8987 : 16795690 : crc32_unsigned_n (unsigned chksum, unsigned value, unsigned bytes)
8988 : : {
8989 : : /* This relies on the raw feedback's top 4 bits being zero. */
8990 : : #define FEEDBACK(X) ((X) * 0x04c11db7)
8991 : : #define SYNDROME(X) (FEEDBACK ((X) & 1) ^ FEEDBACK ((X) & 2) \
8992 : : ^ FEEDBACK ((X) & 4) ^ FEEDBACK ((X) & 8))
8993 : 16795690 : static const unsigned syndromes[16] =
8994 : : {
8995 : : SYNDROME(0x0), SYNDROME(0x1), SYNDROME(0x2), SYNDROME(0x3),
8996 : : SYNDROME(0x4), SYNDROME(0x5), SYNDROME(0x6), SYNDROME(0x7),
8997 : : SYNDROME(0x8), SYNDROME(0x9), SYNDROME(0xa), SYNDROME(0xb),
8998 : : SYNDROME(0xc), SYNDROME(0xd), SYNDROME(0xe), SYNDROME(0xf),
8999 : : };
9000 : : #undef FEEDBACK
9001 : : #undef SYNDROME
9002 : :
9003 : 16795690 : value <<= (32 - bytes * 8);
9004 : 55585818 : for (unsigned ix = bytes * 2; ix--; value <<= 4)
9005 : : {
9006 : 38790128 : unsigned feedback = syndromes[((value ^ chksum) >> 28) & 0xf];
9007 : :
9008 : 38790128 : chksum = (chksum << 4) ^ feedback;
9009 : : }
9010 : :
9011 : 16795690 : return chksum;
9012 : : }
9013 : :
9014 : : /* Generate a crc32 of a string. */
9015 : :
9016 : : unsigned
9017 : 8619 : crc32_string (unsigned chksum, const char *string)
9018 : : {
9019 : 345106 : do
9020 : 345106 : chksum = crc32_byte (chksum, *string);
9021 : 345106 : while (*string++);
9022 : 8619 : return chksum;
9023 : : }
9024 : :
9025 : : /* P is a string that will be used in a symbol. Mask out any characters
9026 : : that are not valid in that context. */
9027 : :
9028 : : void
9029 : 7257 : clean_symbol_name (char *p)
9030 : : {
9031 : 82028 : for (; *p; p++)
9032 : 74771 : if (! (ISALNUM (*p)
9033 : : #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
9034 : : || *p == '$'
9035 : : #endif
9036 : : #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
9037 : : || *p == '.'
9038 : : #endif
9039 : : ))
9040 : 6742 : *p = '_';
9041 : 7257 : }
9042 : :
9043 : : static GTY(()) unsigned anon_cnt = 0; /* Saved for PCH. */
9044 : :
9045 : : /* Create a unique anonymous identifier. The identifier is still a
9046 : : valid assembly label. */
9047 : :
9048 : : tree
9049 : 2741439 : make_anon_name ()
9050 : : {
9051 : 2741439 : const char *fmt =
9052 : : #if !defined (NO_DOT_IN_LABEL)
9053 : : "."
9054 : : #elif !defined (NO_DOLLAR_IN_LABEL)
9055 : : "$"
9056 : : #else
9057 : : "_"
9058 : : #endif
9059 : : "_anon_%d";
9060 : :
9061 : 2741439 : char buf[24];
9062 : 2741439 : int len = snprintf (buf, sizeof (buf), fmt, anon_cnt++);
9063 : 2741439 : gcc_checking_assert (len < int (sizeof (buf)));
9064 : :
9065 : 2741439 : tree id = get_identifier_with_length (buf, len);
9066 : 2741439 : IDENTIFIER_ANON_P (id) = true;
9067 : :
9068 : 2741439 : return id;
9069 : : }
9070 : :
9071 : : /* Generate a name for a special-purpose function.
9072 : : The generated name may need to be unique across the whole link.
9073 : : Changes to this function may also require corresponding changes to
9074 : : xstrdup_mask_random.
9075 : : TYPE is some string to identify the purpose of this function to the
9076 : : linker or collect2; it must start with an uppercase letter,
9077 : : one of:
9078 : : I - for constructors
9079 : : D - for destructors
9080 : : N - for C++ anonymous namespaces
9081 : : F - for DWARF unwind frame information. */
9082 : :
9083 : : tree
9084 : 5307 : get_file_function_name (const char *type)
9085 : : {
9086 : 5307 : char *buf;
9087 : 5307 : const char *p;
9088 : 5307 : char *q;
9089 : :
9090 : : /* If we already have a name we know to be unique, just use that. */
9091 : 5307 : if (first_global_object_name)
9092 : 5011 : p = q = ASTRDUP (first_global_object_name);
9093 : : /* If the target is handling the constructors/destructors, they
9094 : : will be local to this file and the name is only necessary for
9095 : : debugging purposes.
9096 : : We also assign sub_I and sub_D sufixes to constructors called from
9097 : : the global static constructors. These are always local.
9098 : : OpenMP "declare target" offloaded constructors/destructors use "off_I" and
9099 : : "off_D" for the same purpose. */
9100 : 296 : else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
9101 : 592 : || ((startswith (type, "sub_") || startswith (type, "off_"))
9102 : 296 : && (type[4] == 'I' || type[4] == 'D')))
9103 : : {
9104 : 296 : const char *file = main_input_filename;
9105 : 296 : if (! file)
9106 : 0 : file = LOCATION_FILE (input_location);
9107 : : /* Just use the file's basename, because the full pathname
9108 : : might be quite long. */
9109 : 296 : p = q = ASTRDUP (lbasename (file));
9110 : : }
9111 : : else
9112 : : {
9113 : : /* Otherwise, the name must be unique across the entire link.
9114 : : We don't have anything that we know to be unique to this translation
9115 : : unit, so use what we do have and throw in some randomness. */
9116 : 0 : unsigned len;
9117 : 0 : const char *name = weak_global_object_name;
9118 : 0 : const char *file = main_input_filename;
9119 : :
9120 : 0 : if (! name)
9121 : 0 : name = "";
9122 : 0 : if (! file)
9123 : 0 : file = LOCATION_FILE (input_location);
9124 : :
9125 : 0 : len = strlen (file);
9126 : 0 : q = (char *) alloca (9 + 19 + len + 1);
9127 : 0 : memcpy (q, file, len + 1);
9128 : :
9129 : 0 : snprintf (q + len, 9 + 19 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX,
9130 : : crc32_string (0, name), get_random_seed (false));
9131 : :
9132 : 0 : p = q;
9133 : : }
9134 : :
9135 : 5307 : clean_symbol_name (q);
9136 : 5307 : buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
9137 : : + strlen (type));
9138 : :
9139 : : /* Set up the name of the file-level functions we may need.
9140 : : Use a global object (which is already required to be unique over
9141 : : the program) rather than the file name (which imposes extra
9142 : : constraints). */
9143 : 5307 : sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
9144 : :
9145 : 5307 : return get_identifier (buf);
9146 : : }
9147 : :
9148 : : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9149 : :
9150 : : /* Complain that the tree code of NODE does not match the expected 0
9151 : : terminated list of trailing codes. The trailing code list can be
9152 : : empty, for a more vague error message. FILE, LINE, and FUNCTION
9153 : : are of the caller. */
9154 : :
9155 : : void
9156 : 0 : tree_check_failed (const_tree node, const char *file,
9157 : : int line, const char *function, ...)
9158 : : {
9159 : 0 : va_list args;
9160 : 0 : const char *buffer;
9161 : 0 : unsigned length = 0;
9162 : 0 : enum tree_code code;
9163 : :
9164 : 0 : va_start (args, function);
9165 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9166 : 0 : length += 4 + strlen (get_tree_code_name (code));
9167 : 0 : va_end (args);
9168 : 0 : if (length)
9169 : : {
9170 : 0 : char *tmp;
9171 : 0 : va_start (args, function);
9172 : 0 : length += strlen ("expected ");
9173 : 0 : buffer = tmp = (char *) alloca (length);
9174 : 0 : length = 0;
9175 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9176 : : {
9177 : 0 : const char *prefix = length ? " or " : "expected ";
9178 : :
9179 : 0 : strcpy (tmp + length, prefix);
9180 : 0 : length += strlen (prefix);
9181 : 0 : strcpy (tmp + length, get_tree_code_name (code));
9182 : 0 : length += strlen (get_tree_code_name (code));
9183 : : }
9184 : 0 : va_end (args);
9185 : : }
9186 : : else
9187 : : buffer = "unexpected node";
9188 : :
9189 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9190 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9191 : : function, trim_filename (file), line);
9192 : : }
9193 : :
9194 : : /* Complain that the tree code of NODE does match the expected 0
9195 : : terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9196 : : the caller. */
9197 : :
9198 : : void
9199 : 0 : tree_not_check_failed (const_tree node, const char *file,
9200 : : int line, const char *function, ...)
9201 : : {
9202 : 0 : va_list args;
9203 : 0 : char *buffer;
9204 : 0 : unsigned length = 0;
9205 : 0 : enum tree_code code;
9206 : :
9207 : 0 : va_start (args, function);
9208 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9209 : 0 : length += 4 + strlen (get_tree_code_name (code));
9210 : 0 : va_end (args);
9211 : 0 : va_start (args, function);
9212 : 0 : buffer = (char *) alloca (length);
9213 : 0 : length = 0;
9214 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9215 : : {
9216 : 0 : if (length)
9217 : : {
9218 : 0 : strcpy (buffer + length, " or ");
9219 : 0 : length += 4;
9220 : : }
9221 : 0 : strcpy (buffer + length, get_tree_code_name (code));
9222 : 0 : length += strlen (get_tree_code_name (code));
9223 : : }
9224 : 0 : va_end (args);
9225 : :
9226 : 0 : internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9227 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9228 : : function, trim_filename (file), line);
9229 : : }
9230 : :
9231 : : /* Similar to tree_check_failed, except that we check for a class of tree
9232 : : code, given in CL. */
9233 : :
9234 : : void
9235 : 0 : tree_class_check_failed (const_tree node, const enum tree_code_class cl,
9236 : : const char *file, int line, const char *function)
9237 : : {
9238 : 0 : internal_error
9239 : 0 : ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9240 : 0 : TREE_CODE_CLASS_STRING (cl),
9241 : 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9242 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9243 : : }
9244 : :
9245 : : /* Similar to tree_check_failed, except that instead of specifying a
9246 : : dozen codes, use the knowledge that they're all sequential. */
9247 : :
9248 : : void
9249 : 0 : tree_range_check_failed (const_tree node, const char *file, int line,
9250 : : const char *function, enum tree_code c1,
9251 : : enum tree_code c2)
9252 : : {
9253 : 0 : char *buffer;
9254 : 0 : unsigned length = 0;
9255 : 0 : unsigned int c;
9256 : :
9257 : 0 : for (c = c1; c <= c2; ++c)
9258 : 0 : length += 4 + strlen (get_tree_code_name ((enum tree_code) c));
9259 : :
9260 : 0 : length += strlen ("expected ");
9261 : 0 : buffer = (char *) alloca (length);
9262 : 0 : length = 0;
9263 : :
9264 : 0 : for (c = c1; c <= c2; ++c)
9265 : : {
9266 : 0 : const char *prefix = length ? " or " : "expected ";
9267 : :
9268 : 0 : strcpy (buffer + length, prefix);
9269 : 0 : length += strlen (prefix);
9270 : 0 : strcpy (buffer + length, get_tree_code_name ((enum tree_code) c));
9271 : 0 : length += strlen (get_tree_code_name ((enum tree_code) c));
9272 : : }
9273 : :
9274 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9275 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9276 : : function, trim_filename (file), line);
9277 : : }
9278 : :
9279 : :
9280 : : /* Similar to tree_check_failed, except that we check that a tree does
9281 : : not have the specified code, given in CL. */
9282 : :
9283 : : void
9284 : 0 : tree_not_class_check_failed (const_tree node, const enum tree_code_class cl,
9285 : : const char *file, int line, const char *function)
9286 : : {
9287 : 0 : internal_error
9288 : 0 : ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9289 : 0 : TREE_CODE_CLASS_STRING (cl),
9290 : 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9291 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9292 : : }
9293 : :
9294 : :
9295 : : /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9296 : :
9297 : : void
9298 : 0 : omp_clause_check_failed (const_tree node, const char *file, int line,
9299 : : const char *function, enum omp_clause_code code)
9300 : : {
9301 : 0 : internal_error ("tree check: expected %<omp_clause %s%>, have %qs "
9302 : : "in %s, at %s:%d",
9303 : 0 : omp_clause_code_name[code],
9304 : 0 : get_tree_code_name (TREE_CODE (node)),
9305 : : function, trim_filename (file), line);
9306 : : }
9307 : :
9308 : :
9309 : : /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9310 : :
9311 : : void
9312 : 0 : omp_clause_range_check_failed (const_tree node, const char *file, int line,
9313 : : const char *function, enum omp_clause_code c1,
9314 : : enum omp_clause_code c2)
9315 : : {
9316 : 0 : char *buffer;
9317 : 0 : unsigned length = 0;
9318 : 0 : unsigned int c;
9319 : :
9320 : 0 : for (c = c1; c <= c2; ++c)
9321 : 0 : length += 4 + strlen (omp_clause_code_name[c]);
9322 : :
9323 : 0 : length += strlen ("expected ");
9324 : 0 : buffer = (char *) alloca (length);
9325 : 0 : length = 0;
9326 : :
9327 : 0 : for (c = c1; c <= c2; ++c)
9328 : : {
9329 : 0 : const char *prefix = length ? " or " : "expected ";
9330 : :
9331 : 0 : strcpy (buffer + length, prefix);
9332 : 0 : length += strlen (prefix);
9333 : 0 : strcpy (buffer + length, omp_clause_code_name[c]);
9334 : 0 : length += strlen (omp_clause_code_name[c]);
9335 : : }
9336 : :
9337 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9338 : 0 : buffer, omp_clause_code_name[TREE_CODE (node)],
9339 : : function, trim_filename (file), line);
9340 : : }
9341 : :
9342 : :
9343 : : #undef DEFTREESTRUCT
9344 : : #define DEFTREESTRUCT(VAL, NAME) NAME,
9345 : :
9346 : : static const char *ts_enum_names[] = {
9347 : : #include "treestruct.def"
9348 : : };
9349 : : #undef DEFTREESTRUCT
9350 : :
9351 : : #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9352 : :
9353 : : /* Similar to tree_class_check_failed, except that we check for
9354 : : whether CODE contains the tree structure identified by EN. */
9355 : :
9356 : : void
9357 : 0 : tree_contains_struct_check_failed (const_tree node,
9358 : : const enum tree_node_structure_enum en,
9359 : : const char *file, int line,
9360 : : const char *function)
9361 : : {
9362 : 0 : internal_error
9363 : 0 : ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9364 : 0 : TS_ENUM_NAME (en),
9365 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9366 : : }
9367 : :
9368 : :
9369 : : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9370 : : (dynamically sized) vector. */
9371 : :
9372 : : void
9373 : 0 : tree_int_cst_elt_check_failed (int idx, int len, const char *file, int line,
9374 : : const char *function)
9375 : : {
9376 : 0 : internal_error
9377 : 0 : ("tree check: accessed elt %d of %<tree_int_cst%> with %d elts in %s, "
9378 : : "at %s:%d",
9379 : : idx + 1, len, function, trim_filename (file), line);
9380 : : }
9381 : :
9382 : : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9383 : : (dynamically sized) vector. */
9384 : :
9385 : : void
9386 : 0 : tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
9387 : : const char *function)
9388 : : {
9389 : 0 : internal_error
9390 : 0 : ("tree check: accessed elt %d of %<tree_vec%> with %d elts in %s, at %s:%d",
9391 : : idx + 1, len, function, trim_filename (file), line);
9392 : : }
9393 : :
9394 : : /* Similar to above, except that the check is for the bounds of the operand
9395 : : vector of an expression node EXP. */
9396 : :
9397 : : void
9398 : 0 : tree_operand_check_failed (int idx, const_tree exp, const char *file,
9399 : : int line, const char *function)
9400 : : {
9401 : 0 : enum tree_code code = TREE_CODE (exp);
9402 : 0 : internal_error
9403 : 0 : ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9404 : : idx + 1, get_tree_code_name (code), TREE_OPERAND_LENGTH (exp),
9405 : : function, trim_filename (file), line);
9406 : : }
9407 : :
9408 : : /* Similar to above, except that the check is for the number of
9409 : : operands of an OMP_CLAUSE node. */
9410 : :
9411 : : void
9412 : 0 : omp_clause_operand_check_failed (int idx, const_tree t, const char *file,
9413 : : int line, const char *function)
9414 : : {
9415 : 0 : internal_error
9416 : 0 : ("tree check: accessed operand %d of %<omp_clause %s%> with %d operands "
9417 : 0 : "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
9418 : 0 : omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
9419 : : trim_filename (file), line);
9420 : : }
9421 : : #endif /* ENABLE_TREE_CHECKING */
9422 : :
9423 : : /* Create a new vector type node holding NUNITS units of type INNERTYPE,
9424 : : and mapped to the machine mode MODE. Initialize its fields and build
9425 : : the information necessary for debugging output. */
9426 : :
9427 : : static tree
9428 : 72101659 : make_vector_type (tree innertype, poly_int64 nunits, machine_mode mode)
9429 : : {
9430 : 72101659 : tree t;
9431 : 72101659 : tree mv_innertype = TYPE_MAIN_VARIANT (innertype);
9432 : :
9433 : 72101659 : t = make_node (VECTOR_TYPE);
9434 : 72101659 : TREE_TYPE (t) = mv_innertype;
9435 : 72101659 : SET_TYPE_VECTOR_SUBPARTS (t, nunits);
9436 : 72101659 : SET_TYPE_MODE (t, mode);
9437 : :
9438 : 72101659 : if (TYPE_STRUCTURAL_EQUALITY_P (mv_innertype) || in_lto_p)
9439 : 1292342 : SET_TYPE_STRUCTURAL_EQUALITY (t);
9440 : 70809317 : else if ((TYPE_CANONICAL (mv_innertype) != innertype
9441 : 67326366 : || mode != VOIDmode)
9442 : 102412368 : && !VECTOR_BOOLEAN_TYPE_P (t))
9443 : 32852051 : TYPE_CANONICAL (t)
9444 : 65704102 : = make_vector_type (TYPE_CANONICAL (mv_innertype), nunits, VOIDmode);
9445 : :
9446 : 72101659 : layout_type (t);
9447 : :
9448 : 72101659 : hashval_t hash = type_hash_canon_hash (t);
9449 : 72101659 : t = type_hash_canon (hash, t);
9450 : :
9451 : : /* We have built a main variant, based on the main variant of the
9452 : : inner type. Use it to build the variant we return. */
9453 : 144197989 : if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
9454 : 72908921 : && TREE_TYPE (t) != innertype)
9455 : 811270 : return build_type_attribute_qual_variant (t,
9456 : 811270 : TYPE_ATTRIBUTES (innertype),
9457 : 1622540 : TYPE_QUALS (innertype));
9458 : :
9459 : : return t;
9460 : : }
9461 : :
9462 : : static tree
9463 : 4035566 : make_or_reuse_type (unsigned size, int unsignedp)
9464 : : {
9465 : 4035566 : int i;
9466 : :
9467 : 4035566 : if (size == INT_TYPE_SIZE)
9468 : 866289 : return unsignedp ? unsigned_type_node : integer_type_node;
9469 : 3169277 : if (size == CHAR_TYPE_SIZE)
9470 : 577526 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
9471 : 2591751 : if (size == SHORT_TYPE_SIZE)
9472 : 866289 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
9473 : 1761642 : if (size == LONG_TYPE_SIZE)
9474 : 844641 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
9475 : 880821 : if (size == LONG_LONG_TYPE_SIZE)
9476 : 21648 : return (unsignedp ? long_long_unsigned_type_node
9477 : 21648 : : long_long_integer_type_node);
9478 : :
9479 : 873405 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9480 : 859173 : if (size == int_n_data[i].bitsize
9481 : 859173 : && int_n_enabled_p[i])
9482 : 844941 : return (unsignedp ? int_n_trees[i].unsigned_type
9483 : 844941 : : int_n_trees[i].signed_type);
9484 : :
9485 : 14232 : if (unsignedp)
9486 : 7116 : return make_unsigned_type (size);
9487 : : else
9488 : 7116 : return make_signed_type (size);
9489 : : }
9490 : :
9491 : : /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9492 : :
9493 : : static tree
9494 : 5775260 : make_or_reuse_fract_type (unsigned size, int unsignedp, int satp)
9495 : : {
9496 : 5775260 : if (satp)
9497 : : {
9498 : 2887630 : if (size == SHORT_FRACT_TYPE_SIZE)
9499 : 577526 : return unsignedp ? sat_unsigned_short_fract_type_node
9500 : 577526 : : sat_short_fract_type_node;
9501 : 2310104 : if (size == FRACT_TYPE_SIZE)
9502 : 577526 : return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node;
9503 : 1732578 : if (size == LONG_FRACT_TYPE_SIZE)
9504 : 577526 : return unsignedp ? sat_unsigned_long_fract_type_node
9505 : 577526 : : sat_long_fract_type_node;
9506 : 1155052 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9507 : 577526 : return unsignedp ? sat_unsigned_long_long_fract_type_node
9508 : 577526 : : sat_long_long_fract_type_node;
9509 : : }
9510 : : else
9511 : : {
9512 : 2887630 : if (size == SHORT_FRACT_TYPE_SIZE)
9513 : 577526 : return unsignedp ? unsigned_short_fract_type_node
9514 : 577526 : : short_fract_type_node;
9515 : 2310104 : if (size == FRACT_TYPE_SIZE)
9516 : 577526 : return unsignedp ? unsigned_fract_type_node : fract_type_node;
9517 : 1732578 : if (size == LONG_FRACT_TYPE_SIZE)
9518 : 577526 : return unsignedp ? unsigned_long_fract_type_node
9519 : 577526 : : long_fract_type_node;
9520 : 1155052 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9521 : 577526 : return unsignedp ? unsigned_long_long_fract_type_node
9522 : 577526 : : long_long_fract_type_node;
9523 : : }
9524 : :
9525 : 1155052 : return make_fract_type (size, unsignedp, satp);
9526 : : }
9527 : :
9528 : : /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9529 : :
9530 : : static tree
9531 : 4620208 : make_or_reuse_accum_type (unsigned size, int unsignedp, int satp)
9532 : : {
9533 : 4620208 : if (satp)
9534 : : {
9535 : 2310104 : if (size == SHORT_ACCUM_TYPE_SIZE)
9536 : 577526 : return unsignedp ? sat_unsigned_short_accum_type_node
9537 : 577526 : : sat_short_accum_type_node;
9538 : 1732578 : if (size == ACCUM_TYPE_SIZE)
9539 : 577526 : return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node;
9540 : 1155052 : if (size == LONG_ACCUM_TYPE_SIZE)
9541 : 577526 : return unsignedp ? sat_unsigned_long_accum_type_node
9542 : 577526 : : sat_long_accum_type_node;
9543 : 577526 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9544 : 577526 : return unsignedp ? sat_unsigned_long_long_accum_type_node
9545 : 577526 : : sat_long_long_accum_type_node;
9546 : : }
9547 : : else
9548 : : {
9549 : 2310104 : if (size == SHORT_ACCUM_TYPE_SIZE)
9550 : 577526 : return unsignedp ? unsigned_short_accum_type_node
9551 : 577526 : : short_accum_type_node;
9552 : 1732578 : if (size == ACCUM_TYPE_SIZE)
9553 : 577526 : return unsignedp ? unsigned_accum_type_node : accum_type_node;
9554 : 1155052 : if (size == LONG_ACCUM_TYPE_SIZE)
9555 : 577526 : return unsignedp ? unsigned_long_accum_type_node
9556 : 577526 : : long_accum_type_node;
9557 : 577526 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9558 : 577526 : return unsignedp ? unsigned_long_long_accum_type_node
9559 : 577526 : : long_long_accum_type_node;
9560 : : }
9561 : :
9562 : 0 : return make_accum_type (size, unsignedp, satp);
9563 : : }
9564 : :
9565 : :
9566 : : /* Create an atomic variant node for TYPE. This routine is called
9567 : : during initialization of data types to create the 5 basic atomic
9568 : : types. The generic build_variant_type function requires these to
9569 : : already be set up in order to function properly, so cannot be
9570 : : called from there. If ALIGN is non-zero, then ensure alignment is
9571 : : overridden to this value. */
9572 : :
9573 : : static tree
9574 : 1443815 : build_atomic_base (tree type, unsigned int align)
9575 : : {
9576 : 1443815 : tree t;
9577 : :
9578 : : /* Make sure its not already registered. */
9579 : 1443815 : if ((t = get_qualified_type (type, TYPE_QUAL_ATOMIC)))
9580 : : return t;
9581 : :
9582 : 1443815 : t = build_variant_type_copy (type);
9583 : 1443815 : set_type_quals (t, TYPE_QUAL_ATOMIC);
9584 : :
9585 : 1443815 : if (align)
9586 : 0 : SET_TYPE_ALIGN (t, align);
9587 : :
9588 : : return t;
9589 : : }
9590 : :
9591 : : /* Information about the _FloatN and _FloatNx types. This must be in
9592 : : the same order as the corresponding TI_* enum values. */
9593 : : const floatn_type_info floatn_nx_types[NUM_FLOATN_NX_TYPES] =
9594 : : {
9595 : : { 16, false },
9596 : : { 32, false },
9597 : : { 64, false },
9598 : : { 128, false },
9599 : : { 32, true },
9600 : : { 64, true },
9601 : : { 128, true },
9602 : : };
9603 : :
9604 : :
9605 : : /* Create nodes for all integer types (and error_mark_node) using the sizes
9606 : : of C datatypes. SIGNED_CHAR specifies whether char is signed. */
9607 : :
9608 : : void
9609 : 288763 : build_common_tree_nodes (bool signed_char)
9610 : : {
9611 : 288763 : int i;
9612 : :
9613 : 288763 : error_mark_node = make_node (ERROR_MARK);
9614 : 288763 : TREE_TYPE (error_mark_node) = error_mark_node;
9615 : :
9616 : 288763 : initialize_sizetypes ();
9617 : :
9618 : : /* Define both `signed char' and `unsigned char'. */
9619 : 288763 : signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
9620 : 288763 : TYPE_STRING_FLAG (signed_char_type_node) = 1;
9621 : 288763 : unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
9622 : 288763 : TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
9623 : :
9624 : : /* Define `char', which is like either `signed char' or `unsigned char'
9625 : : but not the same as either. */
9626 : 288763 : char_type_node
9627 : 288763 : = (signed_char
9628 : 288763 : ? make_signed_type (CHAR_TYPE_SIZE)
9629 : 55455 : : make_unsigned_type (CHAR_TYPE_SIZE));
9630 : 288763 : TYPE_STRING_FLAG (char_type_node) = 1;
9631 : :
9632 : 288763 : short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
9633 : 288763 : short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
9634 : 288763 : integer_type_node = make_signed_type (INT_TYPE_SIZE);
9635 : 288763 : unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
9636 : 295979 : long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
9637 : 295979 : long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
9638 : 288763 : long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
9639 : 288763 : long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
9640 : :
9641 : 866289 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9642 : : {
9643 : 288763 : int_n_trees[i].signed_type = make_signed_type (int_n_data[i].bitsize);
9644 : 288763 : int_n_trees[i].unsigned_type = make_unsigned_type (int_n_data[i].bitsize);
9645 : :
9646 : 288763 : if (int_n_enabled_p[i])
9647 : : {
9648 : 281647 : integer_types[itk_intN_0 + i * 2] = int_n_trees[i].signed_type;
9649 : 281647 : integer_types[itk_unsigned_intN_0 + i * 2] = int_n_trees[i].unsigned_type;
9650 : : }
9651 : : }
9652 : :
9653 : : /* Define a boolean type. This type only represents boolean values but
9654 : : may be larger than char depending on the value of BOOL_TYPE_SIZE. */
9655 : 288763 : boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
9656 : 288763 : TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
9657 : 288763 : TYPE_PRECISION (boolean_type_node) = 1;
9658 : 288763 : TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
9659 : :
9660 : : /* Define what type to use for size_t. */
9661 : 295979 : if (strcmp (SIZE_TYPE, "unsigned int") == 0)
9662 : 7216 : size_type_node = unsigned_type_node;
9663 : 281547 : else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
9664 : 281547 : size_type_node = long_unsigned_type_node;
9665 : 0 : else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
9666 : 0 : size_type_node = long_long_unsigned_type_node;
9667 : 0 : else if (strcmp (SIZE_TYPE, "short unsigned int") == 0)
9668 : 0 : size_type_node = short_unsigned_type_node;
9669 : : else
9670 : : {
9671 : 0 : int i;
9672 : :
9673 : 0 : size_type_node = NULL_TREE;
9674 : 0 : for (i = 0; i < NUM_INT_N_ENTS; i++)
9675 : 0 : if (int_n_enabled_p[i])
9676 : : {
9677 : 0 : char name[50], altname[50];
9678 : 0 : sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
9679 : 0 : sprintf (altname, "__int%d__ unsigned", int_n_data[i].bitsize);
9680 : :
9681 : 0 : if (strcmp (name, SIZE_TYPE) == 0
9682 : 0 : || strcmp (altname, SIZE_TYPE) == 0)
9683 : : {
9684 : 0 : size_type_node = int_n_trees[i].unsigned_type;
9685 : : }
9686 : : }
9687 : 0 : if (size_type_node == NULL_TREE)
9688 : 0 : gcc_unreachable ();
9689 : : }
9690 : :
9691 : : /* Define what type to use for ptrdiff_t. */
9692 : 295979 : if (strcmp (PTRDIFF_TYPE, "int") == 0)
9693 : 7216 : ptrdiff_type_node = integer_type_node;
9694 : 281547 : else if (strcmp (PTRDIFF_TYPE, "long int") == 0)
9695 : 281547 : ptrdiff_type_node = long_integer_type_node;
9696 : 0 : else if (strcmp (PTRDIFF_TYPE, "long long int") == 0)
9697 : 0 : ptrdiff_type_node = long_long_integer_type_node;
9698 : 0 : else if (strcmp (PTRDIFF_TYPE, "short int") == 0)
9699 : 0 : ptrdiff_type_node = short_integer_type_node;
9700 : : else
9701 : : {
9702 : 0 : ptrdiff_type_node = NULL_TREE;
9703 : 0 : for (int i = 0; i < NUM_INT_N_ENTS; i++)
9704 : 0 : if (int_n_enabled_p[i])
9705 : : {
9706 : 0 : char name[50], altname[50];
9707 : 0 : sprintf (name, "__int%d", int_n_data[i].bitsize);
9708 : 0 : sprintf (altname, "__int%d__", int_n_data[i].bitsize);
9709 : :
9710 : 0 : if (strcmp (name, PTRDIFF_TYPE) == 0
9711 : 0 : || strcmp (altname, PTRDIFF_TYPE) == 0)
9712 : 0 : ptrdiff_type_node = int_n_trees[i].signed_type;
9713 : : }
9714 : 0 : if (ptrdiff_type_node == NULL_TREE)
9715 : 0 : gcc_unreachable ();
9716 : : }
9717 : :
9718 : : /* Fill in the rest of the sized types. Reuse existing type nodes
9719 : : when possible. */
9720 : 288763 : intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
9721 : 288763 : intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
9722 : 288763 : intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
9723 : 288763 : intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
9724 : 288763 : intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
9725 : :
9726 : 288763 : unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
9727 : 288763 : unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
9728 : 288763 : unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
9729 : 288763 : unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
9730 : 288763 : unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
9731 : :
9732 : : /* Don't call build_qualified type for atomics. That routine does
9733 : : special processing for atomics, and until they are initialized
9734 : : it's better not to make that call.
9735 : :
9736 : : Check to see if there is a target override for atomic types. */
9737 : :
9738 : 288763 : atomicQI_type_node = build_atomic_base (unsigned_intQI_type_node,
9739 : 288763 : targetm.atomic_align_for_mode (QImode));
9740 : 288763 : atomicHI_type_node = build_atomic_base (unsigned_intHI_type_node,
9741 : 288763 : targetm.atomic_align_for_mode (HImode));
9742 : 288763 : atomicSI_type_node = build_atomic_base (unsigned_intSI_type_node,
9743 : 288763 : targetm.atomic_align_for_mode (SImode));
9744 : 288763 : atomicDI_type_node = build_atomic_base (unsigned_intDI_type_node,
9745 : 288763 : targetm.atomic_align_for_mode (DImode));
9746 : 288763 : atomicTI_type_node = build_atomic_base (unsigned_intTI_type_node,
9747 : 288763 : targetm.atomic_align_for_mode (TImode));
9748 : :
9749 : 288763 : access_public_node = get_identifier ("public");
9750 : 288763 : access_protected_node = get_identifier ("protected");
9751 : 288763 : access_private_node = get_identifier ("private");
9752 : :
9753 : : /* Define these next since types below may used them. */
9754 : 288763 : integer_zero_node = build_int_cst (integer_type_node, 0);
9755 : 288763 : integer_one_node = build_int_cst (integer_type_node, 1);
9756 : 288763 : integer_minus_one_node = build_int_cst (integer_type_node, -1);
9757 : :
9758 : 288763 : size_zero_node = size_int (0);
9759 : 288763 : size_one_node = size_int (1);
9760 : 288763 : bitsize_zero_node = bitsize_int (0);
9761 : 288763 : bitsize_one_node = bitsize_int (1);
9762 : 288763 : bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
9763 : :
9764 : 288763 : boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
9765 : 288763 : boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
9766 : :
9767 : 288763 : void_type_node = make_node (VOID_TYPE);
9768 : 288763 : layout_type (void_type_node);
9769 : :
9770 : : /* We are not going to have real types in C with less than byte alignment,
9771 : : so we might as well not have any types that claim to have it. */
9772 : 288763 : SET_TYPE_ALIGN (void_type_node, BITS_PER_UNIT);
9773 : 288763 : TYPE_USER_ALIGN (void_type_node) = 0;
9774 : :
9775 : 288763 : void_node = make_node (VOID_CST);
9776 : 288763 : TREE_TYPE (void_node) = void_type_node;
9777 : :
9778 : 288763 : void_list_node = build_tree_list (NULL_TREE, void_type_node);
9779 : :
9780 : 288763 : null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
9781 : 288763 : layout_type (TREE_TYPE (null_pointer_node));
9782 : :
9783 : 288763 : ptr_type_node = build_pointer_type (void_type_node);
9784 : 288763 : const_ptr_type_node
9785 : 288763 : = build_pointer_type (build_type_variant (void_type_node, 1, 0));
9786 : 2021341 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
9787 : 1732578 : builtin_structptr_types[i].node = builtin_structptr_types[i].base;
9788 : :
9789 : 295979 : pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
9790 : :
9791 : 288763 : float_type_node = make_node (REAL_TYPE);
9792 : 288763 : machine_mode float_type_mode
9793 : 288763 : = targetm.c.mode_for_floating_type (TI_FLOAT_TYPE);
9794 : 288763 : SET_TYPE_MODE (float_type_node, float_type_mode);
9795 : 288763 : TYPE_PRECISION (float_type_node)
9796 : 288763 : = GET_MODE_PRECISION (float_type_mode).to_constant ();
9797 : 288763 : layout_type (float_type_node);
9798 : :
9799 : 288763 : double_type_node = make_node (REAL_TYPE);
9800 : 288763 : machine_mode double_type_mode
9801 : 288763 : = targetm.c.mode_for_floating_type (TI_DOUBLE_TYPE);
9802 : 288763 : SET_TYPE_MODE (double_type_node, double_type_mode);
9803 : 288763 : TYPE_PRECISION (double_type_node)
9804 : 288763 : = GET_MODE_PRECISION (double_type_mode).to_constant ();
9805 : 288763 : layout_type (double_type_node);
9806 : :
9807 : 288763 : long_double_type_node = make_node (REAL_TYPE);
9808 : 288763 : machine_mode long_double_type_mode
9809 : 288763 : = targetm.c.mode_for_floating_type (TI_LONG_DOUBLE_TYPE);
9810 : 288763 : SET_TYPE_MODE (long_double_type_node, long_double_type_mode);
9811 : 288763 : TYPE_PRECISION (long_double_type_node)
9812 : 288763 : = GET_MODE_PRECISION (long_double_type_mode).to_constant ();
9813 : 288763 : layout_type (long_double_type_node);
9814 : :
9815 : 2310104 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9816 : : {
9817 : 2021341 : int n = floatn_nx_types[i].n;
9818 : 2021341 : bool extended = floatn_nx_types[i].extended;
9819 : 2021341 : scalar_float_mode mode;
9820 : 2021341 : if (!targetm.floatn_mode (n, extended).exists (&mode))
9821 : 288763 : continue;
9822 : 1732578 : int precision = GET_MODE_PRECISION (mode);
9823 : 1732578 : FLOATN_NX_TYPE_NODE (i) = make_node (REAL_TYPE);
9824 : 1732578 : TYPE_PRECISION (FLOATN_NX_TYPE_NODE (i)) = precision;
9825 : 1732578 : layout_type (FLOATN_NX_TYPE_NODE (i));
9826 : 1732578 : SET_TYPE_MODE (FLOATN_NX_TYPE_NODE (i), mode);
9827 : : }
9828 : 288763 : float128t_type_node = float128_type_node;
9829 : : #ifdef HAVE_BFmode
9830 : 288763 : if (REAL_MODE_FORMAT (BFmode) == &arm_bfloat_half_format
9831 : 288763 : && targetm.scalar_mode_supported_p (BFmode)
9832 : 577526 : && targetm.libgcc_floating_mode_supported_p (BFmode))
9833 : : {
9834 : 288763 : bfloat16_type_node = make_node (REAL_TYPE);
9835 : 288763 : TYPE_PRECISION (bfloat16_type_node) = GET_MODE_PRECISION (BFmode);
9836 : 288763 : layout_type (bfloat16_type_node);
9837 : 288763 : SET_TYPE_MODE (bfloat16_type_node, BFmode);
9838 : : }
9839 : : #endif
9840 : :
9841 : 288763 : float_ptr_type_node = build_pointer_type (float_type_node);
9842 : 288763 : double_ptr_type_node = build_pointer_type (double_type_node);
9843 : 288763 : long_double_ptr_type_node = build_pointer_type (long_double_type_node);
9844 : 288763 : integer_ptr_type_node = build_pointer_type (integer_type_node);
9845 : :
9846 : : /* Fixed size integer types. */
9847 : 288763 : uint16_type_node = make_or_reuse_type (16, 1);
9848 : 288763 : uint32_type_node = make_or_reuse_type (32, 1);
9849 : 288763 : uint64_type_node = make_or_reuse_type (64, 1);
9850 : 288763 : if (targetm.scalar_mode_supported_p (TImode))
9851 : 281647 : uint128_type_node = make_or_reuse_type (128, 1);
9852 : :
9853 : : /* Decimal float types. */
9854 : 288763 : if (targetm.decimal_float_supported_p ())
9855 : : {
9856 : 288763 : dfloat32_type_node = make_node (REAL_TYPE);
9857 : 288763 : TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
9858 : 288763 : SET_TYPE_MODE (dfloat32_type_node, SDmode);
9859 : 288763 : layout_type (dfloat32_type_node);
9860 : :
9861 : 288763 : dfloat64_type_node = make_node (REAL_TYPE);
9862 : 288763 : TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
9863 : 288763 : SET_TYPE_MODE (dfloat64_type_node, DDmode);
9864 : 288763 : layout_type (dfloat64_type_node);
9865 : :
9866 : 288763 : dfloat128_type_node = make_node (REAL_TYPE);
9867 : 288763 : TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
9868 : 288763 : SET_TYPE_MODE (dfloat128_type_node, TDmode);
9869 : 288763 : layout_type (dfloat128_type_node);
9870 : :
9871 : 288763 : dfloat64x_type_node = make_node (REAL_TYPE);
9872 : 288763 : TYPE_PRECISION (dfloat64x_type_node) = DECIMAL128_TYPE_SIZE;
9873 : 288763 : SET_TYPE_MODE (dfloat64x_type_node, TDmode);
9874 : 288763 : layout_type (dfloat64x_type_node);
9875 : : }
9876 : :
9877 : 288763 : complex_integer_type_node = build_complex_type (integer_type_node, true);
9878 : 288763 : complex_float_type_node = build_complex_type (float_type_node, true);
9879 : 288763 : complex_double_type_node = build_complex_type (double_type_node, true);
9880 : 288763 : complex_long_double_type_node = build_complex_type (long_double_type_node,
9881 : : true);
9882 : :
9883 : 2310104 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9884 : : {
9885 : 2021341 : if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
9886 : 1732578 : COMPLEX_FLOATN_NX_TYPE_NODE (i)
9887 : 1732578 : = build_complex_type (FLOATN_NX_TYPE_NODE (i));
9888 : : }
9889 : :
9890 : : /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9891 : : #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9892 : : sat_ ## KIND ## _type_node = \
9893 : : make_sat_signed_ ## KIND ## _type (SIZE); \
9894 : : sat_unsigned_ ## KIND ## _type_node = \
9895 : : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9896 : : KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9897 : : unsigned_ ## KIND ## _type_node = \
9898 : : make_unsigned_ ## KIND ## _type (SIZE);
9899 : :
9900 : : #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9901 : : sat_ ## WIDTH ## KIND ## _type_node = \
9902 : : make_sat_signed_ ## KIND ## _type (SIZE); \
9903 : : sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9904 : : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9905 : : WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9906 : : unsigned_ ## WIDTH ## KIND ## _type_node = \
9907 : : make_unsigned_ ## KIND ## _type (SIZE);
9908 : :
9909 : : /* Make fixed-point type nodes based on four different widths. */
9910 : : #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9911 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9912 : : MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9913 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9914 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9915 : :
9916 : : /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9917 : : #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9918 : : NAME ## _type_node = \
9919 : : make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9920 : : u ## NAME ## _type_node = \
9921 : : make_or_reuse_unsigned_ ## KIND ## _type \
9922 : : (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9923 : : sat_ ## NAME ## _type_node = \
9924 : : make_or_reuse_sat_signed_ ## KIND ## _type \
9925 : : (GET_MODE_BITSIZE (MODE ## mode)); \
9926 : : sat_u ## NAME ## _type_node = \
9927 : : make_or_reuse_sat_unsigned_ ## KIND ## _type \
9928 : : (GET_MODE_BITSIZE (U ## MODE ## mode));
9929 : :
9930 : : /* Fixed-point type and mode nodes. */
9931 : 288763 : MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT)
9932 : 288763 : MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM)
9933 : 288763 : MAKE_FIXED_MODE_NODE (fract, qq, QQ)
9934 : 288763 : MAKE_FIXED_MODE_NODE (fract, hq, HQ)
9935 : 288763 : MAKE_FIXED_MODE_NODE (fract, sq, SQ)
9936 : 288763 : MAKE_FIXED_MODE_NODE (fract, dq, DQ)
9937 : 288763 : MAKE_FIXED_MODE_NODE (fract, tq, TQ)
9938 : 288763 : MAKE_FIXED_MODE_NODE (accum, ha, HA)
9939 : 288763 : MAKE_FIXED_MODE_NODE (accum, sa, SA)
9940 : 288763 : MAKE_FIXED_MODE_NODE (accum, da, DA)
9941 : 288763 : MAKE_FIXED_MODE_NODE (accum, ta, TA)
9942 : :
9943 : 288763 : {
9944 : 288763 : tree t = targetm.build_builtin_va_list ();
9945 : :
9946 : : /* Many back-ends define record types without setting TYPE_NAME.
9947 : : If we copied the record type here, we'd keep the original
9948 : : record type without a name. This breaks name mangling. So,
9949 : : don't copy record types and let c_common_nodes_and_builtins()
9950 : : declare the type to be __builtin_va_list. */
9951 : 288763 : if (TREE_CODE (t) != RECORD_TYPE)
9952 : 288763 : t = build_variant_type_copy (t);
9953 : :
9954 : 288763 : va_list_type_node = t;
9955 : : }
9956 : :
9957 : : /* SCEV analyzer global shared trees. */
9958 : 288763 : chrec_dont_know = make_node (SCEV_NOT_KNOWN);
9959 : 288763 : TREE_TYPE (chrec_dont_know) = void_type_node;
9960 : 288763 : chrec_known = make_node (SCEV_KNOWN);
9961 : 288763 : TREE_TYPE (chrec_known) = void_type_node;
9962 : 288763 : }
9963 : :
9964 : : /* Modify DECL for given flags.
9965 : : TM_PURE attribute is set only on types, so the function will modify
9966 : : DECL's type when ECF_TM_PURE is used. */
9967 : :
9968 : : void
9969 : 30850951 : set_call_expr_flags (tree decl, int flags)
9970 : : {
9971 : 30850951 : if (flags & ECF_NOTHROW)
9972 : 26576782 : TREE_NOTHROW (decl) = 1;
9973 : 30850951 : if (flags & ECF_CONST)
9974 : 12760170 : TREE_READONLY (decl) = 1;
9975 : 30850951 : if (flags & ECF_PURE)
9976 : 1507380 : DECL_PURE_P (decl) = 1;
9977 : 30850951 : if (flags & ECF_LOOPING_CONST_OR_PURE)
9978 : 0 : DECL_LOOPING_CONST_OR_PURE_P (decl) = 1;
9979 : 30850951 : if (flags & ECF_NOVOPS)
9980 : 0 : DECL_IS_NOVOPS (decl) = 1;
9981 : 30850951 : if (flags & ECF_NORETURN)
9982 : 1223597 : TREE_THIS_VOLATILE (decl) = 1;
9983 : 30850951 : if (flags & ECF_MALLOC)
9984 : 739518 : DECL_IS_MALLOC (decl) = 1;
9985 : 30850951 : if (flags & ECF_RETURNS_TWICE)
9986 : 0 : DECL_IS_RETURNS_TWICE (decl) = 1;
9987 : 30850951 : if (flags & ECF_LEAF)
9988 : 26457718 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("leaf"),
9989 : 26457718 : NULL, DECL_ATTRIBUTES (decl));
9990 : 30850951 : if (flags & ECF_COLD)
9991 : 641743 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("cold"),
9992 : 641743 : NULL, DECL_ATTRIBUTES (decl));
9993 : 30850951 : if (flags & ECF_RET1)
9994 : 0 : DECL_ATTRIBUTES (decl)
9995 : 0 : = tree_cons (get_identifier ("fn spec"),
9996 : : build_tree_list (NULL_TREE, build_string (2, "1 ")),
9997 : 0 : DECL_ATTRIBUTES (decl));
9998 : 30850951 : if ((flags & ECF_TM_PURE) && flag_tm)
9999 : 576 : apply_tm_attr (decl, get_identifier ("transaction_pure"));
10000 : 30850951 : if ((flags & ECF_XTHROW))
10001 : 413234 : DECL_ATTRIBUTES (decl)
10002 : 826468 : = tree_cons (get_identifier ("expected_throw"),
10003 : 413234 : NULL, DECL_ATTRIBUTES (decl));
10004 : :
10005 : 30850951 : if (flags & ECF_CB_1_2)
10006 : : {
10007 : 370032 : tree attr = callback_build_attr (1, 1, 2);
10008 : 370032 : TREE_CHAIN (attr) = DECL_ATTRIBUTES (decl);
10009 : 370032 : DECL_ATTRIBUTES (decl) = attr;
10010 : : }
10011 : :
10012 : : /* Looping const or pure is implied by noreturn.
10013 : : There is currently no way to declare looping const or looping pure alone. */
10014 : 30850951 : gcc_assert (!(flags & ECF_LOOPING_CONST_OR_PURE)
10015 : : || ((flags & ECF_NORETURN) && (flags & (ECF_CONST | ECF_PURE))));
10016 : 30850951 : }
10017 : :
10018 : :
10019 : : /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
10020 : :
10021 : : static void
10022 : 9551749 : local_define_builtin (const char *name, tree type, enum built_in_function code,
10023 : : const char *library_name, int ecf_flags)
10024 : : {
10025 : 9551749 : tree decl;
10026 : :
10027 : 9551749 : decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
10028 : : library_name, NULL_TREE);
10029 : 9551749 : set_call_expr_flags (decl, ecf_flags);
10030 : :
10031 : 9551749 : set_builtin_decl (code, decl, true);
10032 : 9551749 : }
10033 : :
10034 : : /* Call this function after instantiating all builtins that the language
10035 : : front end cares about. This will build the rest of the builtins
10036 : : and internal functions that are relied upon by the tree optimizers and
10037 : : the middle-end. */
10038 : :
10039 : : void
10040 : 288747 : build_common_builtin_nodes (void)
10041 : : {
10042 : 288747 : tree tmp, ftype;
10043 : 288747 : int ecf_flags;
10044 : :
10045 : 288747 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_PADDING))
10046 : : {
10047 : 56662 : ftype = build_function_type_list (void_type_node,
10048 : : ptr_type_node,
10049 : : ptr_type_node,
10050 : : NULL_TREE);
10051 : 56662 : local_define_builtin ("__builtin_clear_padding", ftype,
10052 : : BUILT_IN_CLEAR_PADDING,
10053 : : "__builtin_clear_padding",
10054 : : ECF_LEAF | ECF_NOTHROW);
10055 : : }
10056 : :
10057 : 288747 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE)
10058 : 236731 : || !builtin_decl_explicit_p (BUILT_IN_TRAP)
10059 : 236731 : || !builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP)
10060 : 520832 : || !builtin_decl_explicit_p (BUILT_IN_ABORT))
10061 : : {
10062 : 56662 : ftype = build_function_type (void_type_node, void_list_node);
10063 : 56662 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE))
10064 : 52016 : local_define_builtin ("__builtin_unreachable", ftype,
10065 : : BUILT_IN_UNREACHABLE,
10066 : : "__builtin_unreachable",
10067 : : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10068 : : | ECF_CONST | ECF_COLD);
10069 : 56662 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP))
10070 : 56662 : local_define_builtin ("__builtin_unreachable trap", ftype,
10071 : : BUILT_IN_UNREACHABLE_TRAP,
10072 : : "__builtin_unreachable trap",
10073 : : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10074 : : | ECF_CONST | ECF_COLD);
10075 : 56662 : if (!builtin_decl_explicit_p (BUILT_IN_ABORT))
10076 : 56662 : local_define_builtin ("__builtin_abort", ftype, BUILT_IN_ABORT,
10077 : : "abort",
10078 : : ECF_LEAF | ECF_NORETURN | ECF_CONST | ECF_COLD);
10079 : 56662 : if (!builtin_decl_explicit_p (BUILT_IN_TRAP))
10080 : 21180 : local_define_builtin ("__builtin_trap", ftype, BUILT_IN_TRAP,
10081 : : "__builtin_trap",
10082 : : ECF_NORETURN | ECF_NOTHROW | ECF_LEAF | ECF_COLD);
10083 : : }
10084 : :
10085 : 288747 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY)
10086 : 288747 : || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10087 : : {
10088 : 56662 : ftype = build_function_type_list (ptr_type_node,
10089 : : ptr_type_node, const_ptr_type_node,
10090 : : size_type_node, NULL_TREE);
10091 : :
10092 : 56662 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY))
10093 : 56662 : local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
10094 : : "memcpy", ECF_NOTHROW | ECF_LEAF);
10095 : 56662 : if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10096 : 52016 : local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
10097 : : "memmove", ECF_NOTHROW | ECF_LEAF);
10098 : : }
10099 : :
10100 : 288747 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP))
10101 : : {
10102 : 52016 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10103 : : const_ptr_type_node, size_type_node,
10104 : : NULL_TREE);
10105 : 52016 : local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
10106 : : "memcmp", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10107 : : }
10108 : :
10109 : 288747 : if (!builtin_decl_explicit_p (BUILT_IN_MEMSET))
10110 : : {
10111 : 52016 : ftype = build_function_type_list (ptr_type_node,
10112 : : ptr_type_node, integer_type_node,
10113 : : size_type_node, NULL_TREE);
10114 : 52016 : local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
10115 : : "memset", ECF_NOTHROW | ECF_LEAF);
10116 : : }
10117 : :
10118 : : /* If we're checking the stack, `alloca' can throw. */
10119 : 288686 : const int alloca_flags
10120 : 288747 : = ECF_MALLOC | ECF_LEAF | (flag_stack_check ? 0 : ECF_NOTHROW);
10121 : :
10122 : 288747 : if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA))
10123 : : {
10124 : 56662 : ftype = build_function_type_list (ptr_type_node,
10125 : : size_type_node, NULL_TREE);
10126 : 56662 : local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
10127 : : "alloca", alloca_flags);
10128 : : }
10129 : :
10130 : 288747 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10131 : : size_type_node, NULL_TREE);
10132 : 288747 : local_define_builtin ("__builtin_alloca_with_align", ftype,
10133 : : BUILT_IN_ALLOCA_WITH_ALIGN,
10134 : : "__builtin_alloca_with_align",
10135 : : alloca_flags);
10136 : :
10137 : 288747 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10138 : : size_type_node, size_type_node, NULL_TREE);
10139 : 288747 : local_define_builtin ("__builtin_alloca_with_align_and_max", ftype,
10140 : : BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX,
10141 : : "__builtin_alloca_with_align_and_max",
10142 : : alloca_flags);
10143 : :
10144 : 288747 : ftype = build_function_type_list (void_type_node,
10145 : : ptr_type_node, ptr_type_node,
10146 : : ptr_type_node, NULL_TREE);
10147 : 288747 : local_define_builtin ("__builtin_init_trampoline", ftype,
10148 : : BUILT_IN_INIT_TRAMPOLINE,
10149 : : "__builtin_init_trampoline", ECF_NOTHROW | ECF_LEAF);
10150 : 288747 : local_define_builtin ("__builtin_init_heap_trampoline", ftype,
10151 : : BUILT_IN_INIT_HEAP_TRAMPOLINE,
10152 : : "__builtin_init_heap_trampoline",
10153 : : ECF_NOTHROW | ECF_LEAF);
10154 : 288747 : local_define_builtin ("__builtin_init_descriptor", ftype,
10155 : : BUILT_IN_INIT_DESCRIPTOR,
10156 : : "__builtin_init_descriptor", ECF_NOTHROW | ECF_LEAF);
10157 : :
10158 : 288747 : ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
10159 : 288747 : local_define_builtin ("__builtin_adjust_trampoline", ftype,
10160 : : BUILT_IN_ADJUST_TRAMPOLINE,
10161 : : "__builtin_adjust_trampoline",
10162 : : ECF_CONST | ECF_NOTHROW);
10163 : 288747 : local_define_builtin ("__builtin_adjust_descriptor", ftype,
10164 : : BUILT_IN_ADJUST_DESCRIPTOR,
10165 : : "__builtin_adjust_descriptor",
10166 : : ECF_CONST | ECF_NOTHROW);
10167 : :
10168 : 288747 : ftype = build_function_type_list (void_type_node,
10169 : : ptr_type_node, ptr_type_node, NULL_TREE);
10170 : 288747 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_CACHE))
10171 : 56662 : local_define_builtin ("__builtin___clear_cache", ftype,
10172 : : BUILT_IN_CLEAR_CACHE,
10173 : : "__clear_cache",
10174 : : ECF_NOTHROW);
10175 : :
10176 : 288747 : local_define_builtin ("__builtin_nonlocal_goto", ftype,
10177 : : BUILT_IN_NONLOCAL_GOTO,
10178 : : "__builtin_nonlocal_goto",
10179 : : ECF_NORETURN | ECF_NOTHROW);
10180 : :
10181 : 288747 : tree ptr_ptr_type_node = build_pointer_type (ptr_type_node);
10182 : :
10183 : 288747 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_CREATED))
10184 : : {
10185 : 56662 : ftype = build_function_type_list (void_type_node,
10186 : : ptr_type_node, // void *chain
10187 : : ptr_type_node, // void *func
10188 : : ptr_ptr_type_node, // void **dst
10189 : : NULL_TREE);
10190 : 56662 : local_define_builtin ("__builtin___gcc_nested_func_ptr_created", ftype,
10191 : : BUILT_IN_GCC_NESTED_PTR_CREATED,
10192 : : "__gcc_nested_func_ptr_created", ECF_NOTHROW);
10193 : : }
10194 : :
10195 : 288747 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_DELETED))
10196 : : {
10197 : 56662 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10198 : 56662 : local_define_builtin ("__builtin___gcc_nested_func_ptr_deleted", ftype,
10199 : : BUILT_IN_GCC_NESTED_PTR_DELETED,
10200 : : "__gcc_nested_func_ptr_deleted", ECF_NOTHROW);
10201 : : }
10202 : :
10203 : 288747 : ftype = build_function_type_list (void_type_node,
10204 : : ptr_type_node, ptr_type_node, NULL_TREE);
10205 : 288747 : local_define_builtin ("__builtin_setjmp_setup", ftype,
10206 : : BUILT_IN_SETJMP_SETUP,
10207 : : "__builtin_setjmp_setup", ECF_NOTHROW);
10208 : :
10209 : 288747 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10210 : 288747 : local_define_builtin ("__builtin_setjmp_receiver", ftype,
10211 : : BUILT_IN_SETJMP_RECEIVER,
10212 : : "__builtin_setjmp_receiver", ECF_NOTHROW | ECF_LEAF);
10213 : :
10214 : 288747 : ftype = build_function_type_list (ptr_type_node, NULL_TREE);
10215 : 288747 : local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
10216 : : "__builtin_stack_save", ECF_NOTHROW | ECF_LEAF);
10217 : :
10218 : 288747 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10219 : 288747 : local_define_builtin ("__builtin_stack_restore", ftype,
10220 : : BUILT_IN_STACK_RESTORE,
10221 : : "__builtin_stack_restore", ECF_NOTHROW | ECF_LEAF);
10222 : :
10223 : 288747 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10224 : : const_ptr_type_node, size_type_node,
10225 : : NULL_TREE);
10226 : 288747 : local_define_builtin ("__builtin_memcmp_eq", ftype, BUILT_IN_MEMCMP_EQ,
10227 : : "__builtin_memcmp_eq",
10228 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10229 : :
10230 : 288747 : local_define_builtin ("__builtin_strncmp_eq", ftype, BUILT_IN_STRNCMP_EQ,
10231 : : "__builtin_strncmp_eq",
10232 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10233 : :
10234 : 288747 : local_define_builtin ("__builtin_strcmp_eq", ftype, BUILT_IN_STRCMP_EQ,
10235 : : "__builtin_strcmp_eq",
10236 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10237 : :
10238 : : /* If there's a possibility that we might use the ARM EABI, build the
10239 : : alternate __cxa_end_cleanup node used to resume from C++. */
10240 : 288747 : if (targetm.arm_eabi_unwinder)
10241 : : {
10242 : 0 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10243 : 0 : local_define_builtin ("__builtin_cxa_end_cleanup", ftype,
10244 : : BUILT_IN_CXA_END_CLEANUP,
10245 : : "__cxa_end_cleanup",
10246 : : ECF_NORETURN | ECF_XTHROW | ECF_LEAF);
10247 : : }
10248 : :
10249 : 288747 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10250 : 577494 : local_define_builtin ("__builtin_unwind_resume", ftype,
10251 : : BUILT_IN_UNWIND_RESUME,
10252 : 288747 : ((targetm_common.except_unwind_info (&global_options)
10253 : : == UI_SJLJ)
10254 : : ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
10255 : : ECF_NORETURN | ECF_XTHROW);
10256 : :
10257 : 288747 : if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS) == NULL_TREE)
10258 : : {
10259 : 52016 : ftype = build_function_type_list (ptr_type_node, integer_type_node,
10260 : : NULL_TREE);
10261 : 52016 : local_define_builtin ("__builtin_return_address", ftype,
10262 : : BUILT_IN_RETURN_ADDRESS,
10263 : : "__builtin_return_address",
10264 : : ECF_NOTHROW);
10265 : : }
10266 : :
10267 : 288747 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER)
10268 : 288747 : || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10269 : : {
10270 : 56662 : ftype = build_function_type_list (void_type_node, ptr_type_node,
10271 : : ptr_type_node, NULL_TREE);
10272 : 56662 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER))
10273 : 56662 : local_define_builtin ("__cyg_profile_func_enter", ftype,
10274 : : BUILT_IN_PROFILE_FUNC_ENTER,
10275 : : "__cyg_profile_func_enter", 0);
10276 : 56662 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10277 : 56662 : local_define_builtin ("__cyg_profile_func_exit", ftype,
10278 : : BUILT_IN_PROFILE_FUNC_EXIT,
10279 : : "__cyg_profile_func_exit", 0);
10280 : : }
10281 : :
10282 : : /* The exception object and filter values from the runtime. The argument
10283 : : must be zero before exception lowering, i.e. from the front end. After
10284 : : exception lowering, it will be the region number for the exception
10285 : : landing pad. These functions are PURE instead of CONST to prevent
10286 : : them from being hoisted past the exception edge that will initialize
10287 : : its value in the landing pad. */
10288 : 288747 : ftype = build_function_type_list (ptr_type_node,
10289 : : integer_type_node, NULL_TREE);
10290 : 288747 : ecf_flags = ECF_PURE | ECF_NOTHROW | ECF_LEAF;
10291 : : /* Only use TM_PURE if we have TM language support. */
10292 : 288747 : if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1))
10293 : 514 : ecf_flags |= ECF_TM_PURE;
10294 : 288747 : local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER,
10295 : : "__builtin_eh_pointer", ecf_flags);
10296 : :
10297 : 288747 : tmp = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0);
10298 : 288747 : ftype = build_function_type_list (tmp, integer_type_node, NULL_TREE);
10299 : 288747 : local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER,
10300 : : "__builtin_eh_filter", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10301 : :
10302 : 288747 : ftype = build_function_type_list (void_type_node,
10303 : : integer_type_node, integer_type_node,
10304 : : NULL_TREE);
10305 : 288747 : local_define_builtin ("__builtin_eh_copy_values", ftype,
10306 : : BUILT_IN_EH_COPY_VALUES,
10307 : : "__builtin_eh_copy_values", ECF_NOTHROW);
10308 : :
10309 : : /* Complex multiplication and division. These are handled as builtins
10310 : : rather than optabs because emit_library_call_value doesn't support
10311 : : complex. Further, we can do slightly better with folding these
10312 : : beasties if the real and complex parts of the arguments are separate. */
10313 : 288747 : {
10314 : 288747 : int mode;
10315 : :
10316 : 2021229 : for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
10317 : : {
10318 : 1732482 : char mode_name_buf[4], *q;
10319 : 1732482 : const char *p;
10320 : 1732482 : enum built_in_function mcode, dcode;
10321 : 1732482 : tree type, inner_type;
10322 : 1732482 : const char *prefix = "__";
10323 : :
10324 : 1732482 : if (targetm.libfunc_gnu_prefix)
10325 : 0 : prefix = "__gnu_";
10326 : :
10327 : 1732482 : type = lang_hooks.types.type_for_mode ((machine_mode) mode, 0);
10328 : 1732482 : if (type == NULL)
10329 : 123644 : continue;
10330 : 1608838 : inner_type = TREE_TYPE (type);
10331 : :
10332 : 1608838 : ftype = build_function_type_list (type, inner_type, inner_type,
10333 : : inner_type, inner_type, NULL_TREE);
10334 : :
10335 : 1608838 : mcode = ((enum built_in_function)
10336 : 1608838 : (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10337 : 1608838 : dcode = ((enum built_in_function)
10338 : 1608838 : (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10339 : :
10340 : 4826514 : for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
10341 : 3217676 : *q = TOLOWER (*p);
10342 : 1608838 : *q = '\0';
10343 : :
10344 : : /* For -ftrapping-math these should throw from a former
10345 : : -fnon-call-exception stmt. */
10346 : 1608838 : built_in_names[mcode] = concat (prefix, "mul", mode_name_buf, "3",
10347 : : NULL);
10348 : 1608838 : local_define_builtin (built_in_names[mcode], ftype, mcode,
10349 : : built_in_names[mcode],
10350 : : ECF_CONST | ECF_LEAF);
10351 : :
10352 : 1608838 : built_in_names[dcode] = concat (prefix, "div", mode_name_buf, "3",
10353 : : NULL);
10354 : 1608838 : local_define_builtin (built_in_names[dcode], ftype, dcode,
10355 : : built_in_names[dcode],
10356 : : ECF_CONST | ECF_LEAF);
10357 : : }
10358 : : }
10359 : :
10360 : 288747 : init_internal_fns ();
10361 : 288747 : }
10362 : :
10363 : : /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10364 : : better way.
10365 : :
10366 : : If we requested a pointer to a vector, build up the pointers that
10367 : : we stripped off while looking for the inner type. Similarly for
10368 : : return values from functions.
10369 : :
10370 : : The argument TYPE is the top of the chain, and BOTTOM is the
10371 : : new type which we will point to. */
10372 : :
10373 : : tree
10374 : 0 : reconstruct_complex_type (tree type, tree bottom)
10375 : : {
10376 : 0 : tree inner, outer;
10377 : :
10378 : 0 : if (TREE_CODE (type) == POINTER_TYPE)
10379 : : {
10380 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10381 : 0 : outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
10382 : 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10383 : : }
10384 : : else if (TREE_CODE (type) == REFERENCE_TYPE)
10385 : : {
10386 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10387 : 0 : outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
10388 : 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10389 : : }
10390 : : else if (TREE_CODE (type) == ARRAY_TYPE)
10391 : : {
10392 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10393 : 0 : outer = build_array_type (inner, TYPE_DOMAIN (type));
10394 : : }
10395 : : else if (TREE_CODE (type) == FUNCTION_TYPE)
10396 : : {
10397 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10398 : 0 : outer = build_function_type (inner, TYPE_ARG_TYPES (type),
10399 : 0 : TYPE_NO_NAMED_ARGS_STDARG_P (type));
10400 : : }
10401 : : else if (TREE_CODE (type) == METHOD_TYPE)
10402 : : {
10403 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10404 : : /* The build_method_type_directly() routine prepends 'this' to argument list,
10405 : : so we must compensate by getting rid of it. */
10406 : 0 : outer
10407 : : = build_method_type_directly
10408 : 0 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
10409 : : inner,
10410 : 0 : TREE_CHAIN (TYPE_ARG_TYPES (type)));
10411 : : }
10412 : : else if (TREE_CODE (type) == OFFSET_TYPE)
10413 : : {
10414 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10415 : 0 : outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
10416 : : }
10417 : : else
10418 : : return bottom;
10419 : :
10420 : 0 : return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
10421 : 0 : TYPE_QUALS (type));
10422 : : }
10423 : :
10424 : : /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10425 : : the inner type. */
10426 : : tree
10427 : 34065524 : build_vector_type_for_mode (tree innertype, machine_mode mode)
10428 : : {
10429 : 34065524 : poly_int64 nunits;
10430 : 34065524 : unsigned int bitsize;
10431 : :
10432 : 34065524 : switch (GET_MODE_CLASS (mode))
10433 : : {
10434 : 34064266 : case MODE_VECTOR_BOOL:
10435 : 34064266 : case MODE_VECTOR_INT:
10436 : 34064266 : case MODE_VECTOR_FLOAT:
10437 : 34064266 : case MODE_VECTOR_FRACT:
10438 : 34064266 : case MODE_VECTOR_UFRACT:
10439 : 34064266 : case MODE_VECTOR_ACCUM:
10440 : 34064266 : case MODE_VECTOR_UACCUM:
10441 : 68128532 : nunits = GET_MODE_NUNITS (mode);
10442 : 34064266 : break;
10443 : :
10444 : 1258 : case MODE_INT:
10445 : : /* Check that there are no leftover bits. */
10446 : 1258 : bitsize = GET_MODE_BITSIZE (as_a <scalar_int_mode> (mode));
10447 : 1258 : gcc_assert (bitsize % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
10448 : 1258 : nunits = bitsize / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
10449 : 1258 : break;
10450 : :
10451 : 0 : default:
10452 : 0 : gcc_unreachable ();
10453 : : }
10454 : :
10455 : 34065524 : return make_vector_type (innertype, nunits, mode);
10456 : : }
10457 : :
10458 : : /* Similarly, but takes the inner type and number of units, which must be
10459 : : a power of two. */
10460 : :
10461 : : tree
10462 : 2774763 : build_vector_type (tree innertype, poly_int64 nunits)
10463 : : {
10464 : 2774763 : return make_vector_type (innertype, nunits, VOIDmode);
10465 : : }
10466 : :
10467 : : /* Build a truth vector with NUNITS units, giving it mode MASK_MODE. */
10468 : :
10469 : : tree
10470 : 2303412 : build_truth_vector_type_for_mode (poly_uint64 nunits, machine_mode mask_mode)
10471 : : {
10472 : 2303412 : gcc_assert (mask_mode != BLKmode);
10473 : :
10474 : 2303412 : unsigned HOST_WIDE_INT esize;
10475 : 2303412 : if (VECTOR_MODE_P (mask_mode))
10476 : : {
10477 : 2240053 : poly_uint64 vsize = GET_MODE_PRECISION (mask_mode);
10478 : 2240053 : esize = vector_element_size (vsize, nunits);
10479 : 2240053 : }
10480 : : else
10481 : : esize = 1;
10482 : :
10483 : 2303412 : tree bool_type = build_nonstandard_boolean_type (esize);
10484 : :
10485 : 2303412 : return make_vector_type (bool_type, nunits, mask_mode);
10486 : : }
10487 : :
10488 : : /* Build a vector type that holds one boolean result for each element of
10489 : : vector type VECTYPE. The public interface for this operation is
10490 : : truth_type_for. */
10491 : :
10492 : : static tree
10493 : 2294481 : build_truth_vector_type_for (tree vectype)
10494 : : {
10495 : 2294481 : machine_mode vector_mode = TYPE_MODE (vectype);
10496 : 2294481 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
10497 : :
10498 : 2294481 : machine_mode mask_mode;
10499 : 68526 : if (VECTOR_MODE_P (vector_mode)
10500 : 2362439 : && targetm.vectorize.get_mask_mode (vector_mode).exists (&mask_mode))
10501 : 2293913 : return build_truth_vector_type_for_mode (nunits, mask_mode);
10502 : :
10503 : 568 : poly_uint64 vsize = tree_to_poly_uint64 (TYPE_SIZE (vectype));
10504 : 568 : unsigned HOST_WIDE_INT esize = vector_element_size (vsize, nunits);
10505 : 568 : tree bool_type = build_nonstandard_boolean_type (esize);
10506 : :
10507 : 568 : return make_vector_type (bool_type, nunits, VOIDmode);
10508 : : }
10509 : :
10510 : : /* Like build_vector_type, but builds a variant type with TYPE_VECTOR_OPAQUE
10511 : : set. */
10512 : :
10513 : : tree
10514 : 105341 : build_opaque_vector_type (tree innertype, poly_int64 nunits)
10515 : : {
10516 : 105341 : tree t = make_vector_type (innertype, nunits, VOIDmode);
10517 : 105341 : tree cand;
10518 : : /* We always build the non-opaque variant before the opaque one,
10519 : : so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10520 : 105341 : cand = TYPE_NEXT_VARIANT (t);
10521 : 105341 : if (cand
10522 : 94200 : && TYPE_VECTOR_OPAQUE (cand)
10523 : 166679 : && check_qualified_type (cand, t, TYPE_QUALS (t)))
10524 : : return cand;
10525 : : /* Othewise build a variant type and make sure to queue it after
10526 : : the non-opaque type. */
10527 : 44004 : cand = build_distinct_type_copy (t);
10528 : 44004 : TYPE_VECTOR_OPAQUE (cand) = true;
10529 : 44004 : TYPE_CANONICAL (cand) = TYPE_CANONICAL (t);
10530 : 44004 : TYPE_NEXT_VARIANT (cand) = TYPE_NEXT_VARIANT (t);
10531 : 44004 : TYPE_NEXT_VARIANT (t) = cand;
10532 : 44004 : TYPE_MAIN_VARIANT (cand) = TYPE_MAIN_VARIANT (t);
10533 : : /* Type variants have no alias set defined. */
10534 : 44004 : TYPE_ALIAS_SET (cand) = -1;
10535 : 44004 : return cand;
10536 : : }
10537 : :
10538 : : /* Return the value of element I of VECTOR_CST T as a wide_int. */
10539 : :
10540 : : static poly_wide_int
10541 : 519614 : vector_cst_int_elt (const_tree t, unsigned int i)
10542 : : {
10543 : : /* First handle elements that are directly encoded. */
10544 : 519614 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10545 : 519614 : if (i < encoded_nelts)
10546 : 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, i));
10547 : :
10548 : : /* Identify the pattern that contains element I and work out the index of
10549 : : the last encoded element for that pattern. */
10550 : 519614 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10551 : 519614 : unsigned int pattern = i % npatterns;
10552 : 519614 : unsigned int count = i / npatterns;
10553 : 519614 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10554 : :
10555 : : /* If there are no steps, the final encoded value is the right one. */
10556 : 519614 : if (!VECTOR_CST_STEPPED_P (t))
10557 : 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, final_i));
10558 : :
10559 : : /* Otherwise work out the value from the last two encoded elements. */
10560 : 519614 : tree v1 = VECTOR_CST_ENCODED_ELT (t, final_i - npatterns);
10561 : 519614 : tree v2 = VECTOR_CST_ENCODED_ELT (t, final_i);
10562 : 519614 : poly_wide_int diff = wi::to_poly_wide (v2) - wi::to_poly_wide (v1);
10563 : 519614 : return wi::to_poly_wide (v2) + (count - 2) * diff;
10564 : 519614 : }
10565 : :
10566 : : /* Return the value of element I of VECTOR_CST T. */
10567 : :
10568 : : tree
10569 : 6241356 : vector_cst_elt (const_tree t, unsigned int i)
10570 : : {
10571 : : /* First handle elements that are directly encoded. */
10572 : 6241356 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10573 : 6241356 : if (i < encoded_nelts)
10574 : 4282756 : return VECTOR_CST_ENCODED_ELT (t, i);
10575 : :
10576 : : /* If there are no steps, the final encoded value is the right one. */
10577 : 1958600 : if (!VECTOR_CST_STEPPED_P (t))
10578 : : {
10579 : : /* Identify the pattern that contains element I and work out the index of
10580 : : the last encoded element for that pattern. */
10581 : 1438986 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10582 : 1438986 : unsigned int pattern = i % npatterns;
10583 : 1438986 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10584 : 1438986 : return VECTOR_CST_ENCODED_ELT (t, final_i);
10585 : : }
10586 : :
10587 : : /* Otherwise work out the value from the last two encoded elements. */
10588 : 519614 : return wide_int_to_tree (TREE_TYPE (TREE_TYPE (t)),
10589 : 1039228 : vector_cst_int_elt (t, i));
10590 : : }
10591 : :
10592 : : /* Given an initializer INIT, return TRUE if INIT is zero or some
10593 : : aggregate of zeros. Otherwise return FALSE. If NONZERO is not
10594 : : null, set *NONZERO if and only if INIT is known not to be all
10595 : : zeros. The combination of return value of false and *NONZERO
10596 : : false implies that INIT may but need not be all zeros. Other
10597 : : combinations indicate definitive answers. */
10598 : :
10599 : : bool
10600 : 42975800 : initializer_zerop (const_tree init, bool *nonzero /* = NULL */)
10601 : : {
10602 : 42975800 : bool dummy;
10603 : 42975800 : if (!nonzero)
10604 : 40218263 : nonzero = &dummy;
10605 : :
10606 : : /* Conservatively clear NONZERO and set it only if INIT is definitely
10607 : : not all zero. */
10608 : 42975800 : *nonzero = false;
10609 : :
10610 : 42975800 : STRIP_NOPS (init);
10611 : :
10612 : 42975800 : unsigned HOST_WIDE_INT off = 0;
10613 : :
10614 : 42975800 : switch (TREE_CODE (init))
10615 : : {
10616 : 16751084 : case INTEGER_CST:
10617 : 16751084 : if (integer_zerop (init))
10618 : : return true;
10619 : :
10620 : 10429397 : *nonzero = true;
10621 : 10429397 : return false;
10622 : :
10623 : 545667 : case REAL_CST:
10624 : : /* ??? Note that this is not correct for C4X float formats. There,
10625 : : a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10626 : : negative exponent. */
10627 : 545667 : if (real_zerop (init)
10628 : 633822 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init)))
10629 : : return true;
10630 : :
10631 : 460413 : *nonzero = true;
10632 : 460413 : return false;
10633 : :
10634 : 0 : case FIXED_CST:
10635 : 0 : if (fixed_zerop (init))
10636 : : return true;
10637 : :
10638 : 0 : *nonzero = true;
10639 : 0 : return false;
10640 : :
10641 : 17368 : case COMPLEX_CST:
10642 : 17368 : if (integer_zerop (init)
10643 : 17368 : || (real_zerop (init)
10644 : 2962 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
10645 : 2920 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init)))))
10646 : 3148 : return true;
10647 : :
10648 : 14220 : *nonzero = true;
10649 : 14220 : return false;
10650 : :
10651 : 1115805 : case VECTOR_CST:
10652 : 1115805 : if (VECTOR_CST_NPATTERNS (init) == 1
10653 : 1022504 : && VECTOR_CST_DUPLICATE_P (init)
10654 : 1759332 : && initializer_zerop (VECTOR_CST_ENCODED_ELT (init, 0)))
10655 : : return true;
10656 : :
10657 : 774607 : *nonzero = true;
10658 : 774607 : return false;
10659 : :
10660 : : case RAW_DATA_CST:
10661 : 1571 : for (unsigned int i = 0; i < (unsigned int) RAW_DATA_LENGTH (init); ++i)
10662 : 1571 : if (RAW_DATA_POINTER (init)[i])
10663 : : {
10664 : 1524 : *nonzero = true;
10665 : 1524 : return false;
10666 : : }
10667 : : return true;
10668 : :
10669 : 4291213 : case CONSTRUCTOR:
10670 : 4291213 : {
10671 : 4291213 : if (TREE_CLOBBER_P (init))
10672 : : return false;
10673 : :
10674 : : unsigned HOST_WIDE_INT idx;
10675 : : tree elt;
10676 : :
10677 : 3620502 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
10678 : 2757537 : if (!initializer_zerop (elt, nonzero))
10679 : : return false;
10680 : :
10681 : : return true;
10682 : : }
10683 : :
10684 : 350047 : case MEM_REF:
10685 : 350047 : {
10686 : 350047 : tree arg = TREE_OPERAND (init, 0);
10687 : 350047 : if (TREE_CODE (arg) != ADDR_EXPR)
10688 : : return false;
10689 : 80606 : tree offset = TREE_OPERAND (init, 1);
10690 : 80606 : if (TREE_CODE (offset) != INTEGER_CST
10691 : 80606 : || !tree_fits_uhwi_p (offset))
10692 : : return false;
10693 : 80606 : off = tree_to_uhwi (offset);
10694 : 80606 : if (INT_MAX < off)
10695 : : return false;
10696 : 80602 : arg = TREE_OPERAND (arg, 0);
10697 : 80602 : if (TREE_CODE (arg) != STRING_CST)
10698 : : return false;
10699 : : init = arg;
10700 : : }
10701 : : /* Fall through. */
10702 : :
10703 : : case STRING_CST:
10704 : : {
10705 : : gcc_assert (off <= INT_MAX);
10706 : :
10707 : 160684 : int i = off;
10708 : 160684 : int n = TREE_STRING_LENGTH (init);
10709 : 160684 : if (n <= i)
10710 : : return false;
10711 : :
10712 : : /* We need to loop through all elements to handle cases like
10713 : : "\0" and "\0foobar". */
10714 : 172991 : for (i = 0; i < n; ++i)
10715 : 167204 : if (TREE_STRING_POINTER (init)[i] != '\0')
10716 : : {
10717 : 154864 : *nonzero = true;
10718 : 154864 : return false;
10719 : : }
10720 : :
10721 : : return true;
10722 : : }
10723 : :
10724 : : default:
10725 : : return false;
10726 : : }
10727 : : }
10728 : :
10729 : : /* Return true if EXPR is an initializer expression in which every element
10730 : : is a constant that is numerically equal to 0 or 1. The elements do not
10731 : : need to be equal to each other. */
10732 : :
10733 : : bool
10734 : 126901 : initializer_each_zero_or_onep (const_tree expr)
10735 : : {
10736 : 126901 : STRIP_ANY_LOCATION_WRAPPER (expr);
10737 : :
10738 : 126901 : switch (TREE_CODE (expr))
10739 : : {
10740 : 47521 : case INTEGER_CST:
10741 : 47521 : return integer_zerop (expr) || integer_onep (expr);
10742 : :
10743 : 20731 : case REAL_CST:
10744 : 20731 : return real_zerop (expr) || real_onep (expr);
10745 : :
10746 : 58649 : case VECTOR_CST:
10747 : 58649 : {
10748 : 58649 : unsigned HOST_WIDE_INT nelts = vector_cst_encoded_nelts (expr);
10749 : 58649 : if (VECTOR_CST_STEPPED_P (expr)
10750 : 58649 : && !TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)).is_constant (&nelts))
10751 : : return false;
10752 : :
10753 : 69491 : for (unsigned int i = 0; i < nelts; ++i)
10754 : : {
10755 : 68252 : tree elt = vector_cst_elt (expr, i);
10756 : 68252 : if (!initializer_each_zero_or_onep (elt))
10757 : : return false;
10758 : : }
10759 : :
10760 : : return true;
10761 : : }
10762 : :
10763 : : default:
10764 : : return false;
10765 : : }
10766 : : }
10767 : :
10768 : : /* Check if vector VEC consists of all the equal elements and
10769 : : that the number of elements corresponds to the type of VEC.
10770 : : The function returns first element of the vector
10771 : : or NULL_TREE if the vector is not uniform. */
10772 : : tree
10773 : 2689758 : uniform_vector_p (const_tree vec)
10774 : : {
10775 : 2689758 : tree first, t;
10776 : 2689758 : unsigned HOST_WIDE_INT i, nelts;
10777 : :
10778 : 2689758 : if (vec == NULL_TREE)
10779 : : return NULL_TREE;
10780 : :
10781 : 2689758 : gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec)));
10782 : :
10783 : 2689758 : if (TREE_CODE (vec) == VEC_DUPLICATE_EXPR)
10784 : 0 : return TREE_OPERAND (vec, 0);
10785 : :
10786 : 2689758 : else if (TREE_CODE (vec) == VECTOR_CST)
10787 : : {
10788 : 227782 : if (VECTOR_CST_NPATTERNS (vec) == 1 && VECTOR_CST_DUPLICATE_P (vec))
10789 : 178428 : return VECTOR_CST_ENCODED_ELT (vec, 0);
10790 : : return NULL_TREE;
10791 : : }
10792 : :
10793 : 2461976 : else if (TREE_CODE (vec) == CONSTRUCTOR
10794 : 2461976 : && TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec)).is_constant (&nelts))
10795 : : {
10796 : 162092 : first = error_mark_node;
10797 : :
10798 : 535151 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t)
10799 : : {
10800 : 475682 : if (i == 0)
10801 : : {
10802 : 162092 : first = t;
10803 : 162092 : continue;
10804 : : }
10805 : 313590 : if (!operand_equal_p (first, t, 0))
10806 : : return NULL_TREE;
10807 : : }
10808 : 59469 : if (i != nelts)
10809 : : return NULL_TREE;
10810 : :
10811 : 59277 : if (TREE_CODE (first) == CONSTRUCTOR || TREE_CODE (first) == VECTOR_CST)
10812 : : return uniform_vector_p (first);
10813 : : return first;
10814 : : }
10815 : :
10816 : : return NULL_TREE;
10817 : : }
10818 : :
10819 : : /* If the argument is INTEGER_CST, return it. If the argument is vector
10820 : : with all elements the same INTEGER_CST, return that INTEGER_CST. Otherwise
10821 : : return NULL_TREE.
10822 : : Look through location wrappers. */
10823 : :
10824 : : tree
10825 : 843122349 : uniform_integer_cst_p (tree t)
10826 : : {
10827 : 843122349 : STRIP_ANY_LOCATION_WRAPPER (t);
10828 : :
10829 : 843122349 : if (TREE_CODE (t) == INTEGER_CST)
10830 : : return t;
10831 : :
10832 : 344829563 : if (VECTOR_TYPE_P (TREE_TYPE (t)))
10833 : : {
10834 : 922872 : t = uniform_vector_p (t);
10835 : 922872 : if (t && TREE_CODE (t) == INTEGER_CST)
10836 : : return t;
10837 : : }
10838 : :
10839 : : return NULL_TREE;
10840 : : }
10841 : :
10842 : : /* Checks to see if T is a constant or a constant vector and if each element E
10843 : : adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE. */
10844 : :
10845 : : tree
10846 : 3119469 : bitmask_inv_cst_vector_p (tree t)
10847 : : {
10848 : :
10849 : 3119469 : tree_code code = TREE_CODE (t);
10850 : 3119469 : tree type = TREE_TYPE (t);
10851 : :
10852 : 3119469 : if (!INTEGRAL_TYPE_P (type)
10853 : 3119469 : && !VECTOR_INTEGER_TYPE_P (type))
10854 : : return NULL_TREE;
10855 : :
10856 : 3119469 : unsigned HOST_WIDE_INT nelts = 1;
10857 : 3119469 : tree cst;
10858 : 3119469 : unsigned int idx = 0;
10859 : 3119469 : bool uniform = uniform_integer_cst_p (t);
10860 : 3119469 : tree newtype = unsigned_type_for (type);
10861 : 3119469 : tree_vector_builder builder;
10862 : 3119469 : if (code == INTEGER_CST)
10863 : : cst = t;
10864 : : else
10865 : : {
10866 : 13927 : if (!VECTOR_CST_NELTS (t).is_constant (&nelts))
10867 : : return NULL_TREE;
10868 : :
10869 : 13927 : cst = vector_cst_elt (t, 0);
10870 : 13927 : builder.new_vector (newtype, nelts, 1);
10871 : : }
10872 : :
10873 : 3119469 : tree ty = unsigned_type_for (TREE_TYPE (cst));
10874 : :
10875 : 3119481 : do
10876 : : {
10877 : 3119481 : if (idx > 0)
10878 : 12 : cst = vector_cst_elt (t, idx);
10879 : 3119481 : wide_int icst = wi::to_wide (cst);
10880 : 3119481 : wide_int inv = wi::bit_not (icst);
10881 : 3119481 : icst = wi::add (1, inv);
10882 : 3119481 : if (wi::popcount (icst) != 1)
10883 : : return NULL_TREE;
10884 : :
10885 : 8040 : tree newcst = wide_int_to_tree (ty, inv);
10886 : :
10887 : 8040 : if (uniform)
10888 : 8024 : return build_uniform_cst (newtype, newcst);
10889 : :
10890 : 16 : builder.quick_push (newcst);
10891 : 3119481 : }
10892 : 16 : while (++idx < nelts);
10893 : :
10894 : 4 : return builder.build ();
10895 : 3119469 : }
10896 : :
10897 : : /* If VECTOR_CST T has a single nonzero element, return the index of that
10898 : : element, otherwise return -1. */
10899 : :
10900 : : int
10901 : 177 : single_nonzero_element (const_tree t)
10902 : : {
10903 : 177 : unsigned HOST_WIDE_INT nelts;
10904 : 177 : unsigned int repeat_nelts;
10905 : 177 : if (VECTOR_CST_NELTS (t).is_constant (&nelts))
10906 : 177 : repeat_nelts = nelts;
10907 : : else if (VECTOR_CST_NELTS_PER_PATTERN (t) == 2)
10908 : : {
10909 : : nelts = vector_cst_encoded_nelts (t);
10910 : : repeat_nelts = VECTOR_CST_NPATTERNS (t);
10911 : : }
10912 : : else
10913 : : return -1;
10914 : :
10915 : 177 : int res = -1;
10916 : 561 : for (unsigned int i = 0; i < nelts; ++i)
10917 : : {
10918 : 528 : tree elt = vector_cst_elt (t, i);
10919 : 528 : if (!integer_zerop (elt) && !real_zerop (elt))
10920 : : {
10921 : 321 : if (res >= 0 || i >= repeat_nelts)
10922 : : return -1;
10923 : 177 : res = i;
10924 : : }
10925 : : }
10926 : : return res;
10927 : : }
10928 : :
10929 : : /* Build an empty statement at location LOC. */
10930 : :
10931 : : tree
10932 : 12748275 : build_empty_stmt (location_t loc)
10933 : : {
10934 : 12748275 : tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
10935 : 12748275 : SET_EXPR_LOCATION (t, loc);
10936 : 12748275 : return t;
10937 : : }
10938 : :
10939 : :
10940 : : /* Build an OMP clause with code CODE. LOC is the location of the
10941 : : clause. */
10942 : :
10943 : : tree
10944 : 1709976 : build_omp_clause (location_t loc, enum omp_clause_code code)
10945 : : {
10946 : 1709976 : tree t;
10947 : 1709976 : int size, length;
10948 : :
10949 : 1709976 : length = omp_clause_num_ops[code];
10950 : 1709976 : size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
10951 : :
10952 : 1709976 : record_node_allocation_statistics (OMP_CLAUSE, size);
10953 : :
10954 : 1709976 : t = (tree) ggc_internal_alloc (size);
10955 : 1709976 : memset (t, 0, size);
10956 : 1709976 : TREE_SET_CODE (t, OMP_CLAUSE);
10957 : 1709976 : OMP_CLAUSE_SET_CODE (t, code);
10958 : 1709976 : OMP_CLAUSE_LOCATION (t) = loc;
10959 : :
10960 : 1709976 : return t;
10961 : : }
10962 : :
10963 : : /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
10964 : : includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
10965 : : Except for the CODE and operand count field, other storage for the
10966 : : object is initialized to zeros. */
10967 : :
10968 : : tree
10969 : 443682676 : build_vl_exp (enum tree_code code, int len MEM_STAT_DECL)
10970 : : {
10971 : 443682676 : tree t;
10972 : 443682676 : int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
10973 : :
10974 : 443682676 : gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp);
10975 : 443682676 : gcc_assert (len >= 1);
10976 : :
10977 : 443682676 : record_node_allocation_statistics (code, length);
10978 : :
10979 : 443682676 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
10980 : :
10981 : 443682676 : TREE_SET_CODE (t, code);
10982 : :
10983 : : /* Can't use TREE_OPERAND to store the length because if checking is
10984 : : enabled, it will try to check the length before we store it. :-P */
10985 : 443682676 : t->exp.operands[0] = build_int_cst (sizetype, len);
10986 : :
10987 : 443682676 : return t;
10988 : : }
10989 : :
10990 : : /* Helper function for build_call_* functions; build a CALL_EXPR with
10991 : : indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
10992 : : the argument slots. */
10993 : :
10994 : : static tree
10995 : 237414544 : build_call_1 (tree return_type, tree fn, int nargs)
10996 : : {
10997 : 237414544 : tree t;
10998 : :
10999 : 237414544 : t = build_vl_exp (CALL_EXPR, nargs + 3);
11000 : 237414544 : TREE_TYPE (t) = return_type;
11001 : 237414544 : CALL_EXPR_FN (t) = fn;
11002 : 237414544 : CALL_EXPR_STATIC_CHAIN (t) = NULL;
11003 : :
11004 : 237414544 : return t;
11005 : : }
11006 : :
11007 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11008 : : FN and a null static chain slot. NARGS is the number of call arguments
11009 : : which are specified as "..." arguments. */
11010 : :
11011 : : tree
11012 : 152 : build_call_nary (tree return_type, tree fn, int nargs, ...)
11013 : : {
11014 : 152 : tree ret;
11015 : 152 : va_list args;
11016 : 152 : va_start (args, nargs);
11017 : 152 : ret = build_call_valist (return_type, fn, nargs, args);
11018 : 152 : va_end (args);
11019 : 152 : return ret;
11020 : : }
11021 : :
11022 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11023 : : FN and a null static chain slot. NARGS is the number of call arguments
11024 : : which are specified as a va_list ARGS. */
11025 : :
11026 : : tree
11027 : 136689 : build_call_valist (tree return_type, tree fn, int nargs, va_list args)
11028 : : {
11029 : 136689 : tree t;
11030 : 136689 : int i;
11031 : :
11032 : 136689 : t = build_call_1 (return_type, fn, nargs);
11033 : 555129 : for (i = 0; i < nargs; i++)
11034 : 281751 : CALL_EXPR_ARG (t, i) = va_arg (args, tree);
11035 : 136689 : process_call_operands (t);
11036 : 136689 : return t;
11037 : : }
11038 : :
11039 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11040 : : FN and a null static chain slot. NARGS is the number of call arguments
11041 : : which are specified as a tree array ARGS. */
11042 : :
11043 : : tree
11044 : 195447341 : build_call_array_loc (location_t loc, tree return_type, tree fn,
11045 : : int nargs, const tree *args)
11046 : : {
11047 : 195447341 : tree t;
11048 : 195447341 : int i;
11049 : :
11050 : 195447341 : t = build_call_1 (return_type, fn, nargs);
11051 : 673261538 : for (i = 0; i < nargs; i++)
11052 : 282366856 : CALL_EXPR_ARG (t, i) = args[i];
11053 : 195447341 : process_call_operands (t);
11054 : 195447341 : SET_EXPR_LOCATION (t, loc);
11055 : 195447341 : return t;
11056 : : }
11057 : :
11058 : : /* Like build_call_array, but takes a vec. */
11059 : :
11060 : : tree
11061 : 41336235 : build_call_vec (tree return_type, tree fn, const vec<tree, va_gc> *args)
11062 : : {
11063 : 41336235 : tree ret, t;
11064 : 41336235 : unsigned int ix;
11065 : :
11066 : 41336235 : ret = build_call_1 (return_type, fn, vec_safe_length (args));
11067 : 109744812 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
11068 : 27072342 : CALL_EXPR_ARG (ret, ix) = t;
11069 : 41336235 : process_call_operands (ret);
11070 : 41336235 : return ret;
11071 : : }
11072 : :
11073 : : /* Conveniently construct a function call expression. FNDECL names the
11074 : : function to be called and N arguments are passed in the array
11075 : : ARGARRAY. */
11076 : :
11077 : : tree
11078 : 17991630 : build_call_expr_loc_array (location_t loc, tree fndecl, int n, tree *argarray)
11079 : : {
11080 : 17991630 : tree fntype = TREE_TYPE (fndecl);
11081 : 17991630 : tree fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fndecl);
11082 : :
11083 : 17991630 : return fold_build_call_array_loc (loc, TREE_TYPE (fntype), fn, n, argarray);
11084 : : }
11085 : :
11086 : : /* Conveniently construct a function call expression. FNDECL names the
11087 : : function to be called and the arguments are passed in the vector
11088 : : VEC. */
11089 : :
11090 : : tree
11091 : 20642 : build_call_expr_loc_vec (location_t loc, tree fndecl, vec<tree, va_gc> *vec)
11092 : : {
11093 : 20642 : return build_call_expr_loc_array (loc, fndecl, vec_safe_length (vec),
11094 : 20642 : vec_safe_address (vec));
11095 : : }
11096 : :
11097 : :
11098 : : /* Conveniently construct a function call expression. FNDECL names the
11099 : : function to be called, N is the number of arguments, and the "..."
11100 : : parameters are the argument expressions. */
11101 : :
11102 : : tree
11103 : 16332915 : build_call_expr_loc (location_t loc, tree fndecl, int n, ...)
11104 : : {
11105 : 16332915 : va_list ap;
11106 : 16332915 : tree *argarray = XALLOCAVEC (tree, n);
11107 : 16332915 : int i;
11108 : :
11109 : 16332915 : va_start (ap, n);
11110 : 18769242 : for (i = 0; i < n; i++)
11111 : 2436327 : argarray[i] = va_arg (ap, tree);
11112 : 16332915 : va_end (ap);
11113 : 16332915 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11114 : : }
11115 : :
11116 : : /* Like build_call_expr_loc (UNKNOWN_LOCATION, ...). Duplicated because
11117 : : varargs macros aren't supported by all bootstrap compilers. */
11118 : :
11119 : : tree
11120 : 1633590 : build_call_expr (tree fndecl, int n, ...)
11121 : : {
11122 : 1633590 : va_list ap;
11123 : 1633590 : tree *argarray = XALLOCAVEC (tree, n);
11124 : 1633590 : int i;
11125 : :
11126 : 1633590 : va_start (ap, n);
11127 : 4831308 : for (i = 0; i < n; i++)
11128 : 3197718 : argarray[i] = va_arg (ap, tree);
11129 : 1633590 : va_end (ap);
11130 : 1633590 : return build_call_expr_loc_array (UNKNOWN_LOCATION, fndecl, n, argarray);
11131 : : }
11132 : :
11133 : : /* Build an internal call to IFN, with arguments ARGS[0:N-1] and with return
11134 : : type TYPE. This is just like CALL_EXPR, except its CALL_EXPR_FN is NULL.
11135 : : It will get gimplified later into an ordinary internal function. */
11136 : :
11137 : : tree
11138 : 494279 : build_call_expr_internal_loc_array (location_t loc, internal_fn ifn,
11139 : : tree type, int n, const tree *args)
11140 : : {
11141 : 494279 : tree t = build_call_1 (type, NULL_TREE, n);
11142 : 1780622 : for (int i = 0; i < n; ++i)
11143 : 1286343 : CALL_EXPR_ARG (t, i) = args[i];
11144 : 494279 : SET_EXPR_LOCATION (t, loc);
11145 : 494279 : CALL_EXPR_IFN (t) = ifn;
11146 : 494279 : process_call_operands (t);
11147 : 494279 : return t;
11148 : : }
11149 : :
11150 : : /* Build internal call expression. This is just like CALL_EXPR, except
11151 : : its CALL_EXPR_FN is NULL. It will get gimplified later into ordinary
11152 : : internal function. */
11153 : :
11154 : : tree
11155 : 493253 : build_call_expr_internal_loc (location_t loc, enum internal_fn ifn,
11156 : : tree type, int n, ...)
11157 : : {
11158 : 493253 : va_list ap;
11159 : 493253 : tree *argarray = XALLOCAVEC (tree, n);
11160 : 493253 : int i;
11161 : :
11162 : 493253 : va_start (ap, n);
11163 : 1777546 : for (i = 0; i < n; i++)
11164 : 1284293 : argarray[i] = va_arg (ap, tree);
11165 : 493253 : va_end (ap);
11166 : 493253 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11167 : : }
11168 : :
11169 : : /* Return a function call to FN, if the target is guaranteed to support it,
11170 : : or null otherwise.
11171 : :
11172 : : N is the number of arguments, passed in the "...", and TYPE is the
11173 : : type of the return value. */
11174 : :
11175 : : tree
11176 : 1825 : maybe_build_call_expr_loc (location_t loc, combined_fn fn, tree type,
11177 : : int n, ...)
11178 : : {
11179 : 1825 : va_list ap;
11180 : 1825 : tree *argarray = XALLOCAVEC (tree, n);
11181 : 1825 : int i;
11182 : :
11183 : 1825 : va_start (ap, n);
11184 : 4743 : for (i = 0; i < n; i++)
11185 : 2918 : argarray[i] = va_arg (ap, tree);
11186 : 1825 : va_end (ap);
11187 : 1825 : if (internal_fn_p (fn))
11188 : : {
11189 : 1024 : internal_fn ifn = as_internal_fn (fn);
11190 : 1024 : if (direct_internal_fn_p (ifn))
11191 : : {
11192 : 1 : tree_pair types = direct_internal_fn_types (ifn, type, argarray);
11193 : 1 : if (!direct_internal_fn_supported_p (ifn, types,
11194 : : OPTIMIZE_FOR_BOTH))
11195 : 1 : return NULL_TREE;
11196 : : }
11197 : 1023 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11198 : : }
11199 : : else
11200 : : {
11201 : 801 : tree fndecl = builtin_decl_implicit (as_builtin_fn (fn));
11202 : 801 : if (!fndecl)
11203 : : return NULL_TREE;
11204 : 693 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11205 : : }
11206 : : }
11207 : :
11208 : : /* Return a function call to the appropriate builtin alloca variant.
11209 : :
11210 : : SIZE is the size to be allocated. ALIGN, if non-zero, is the requested
11211 : : alignment of the allocated area. MAX_SIZE, if non-negative, is an upper
11212 : : bound for SIZE in case it is not a fixed value. */
11213 : :
11214 : : tree
11215 : 8870 : build_alloca_call_expr (tree size, unsigned int align, HOST_WIDE_INT max_size)
11216 : : {
11217 : 8870 : if (max_size >= 0)
11218 : : {
11219 : 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX);
11220 : 0 : return
11221 : 0 : build_call_expr (t, 3, size, size_int (align), size_int (max_size));
11222 : : }
11223 : 8870 : else if (align > 0)
11224 : : {
11225 : 8870 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
11226 : 8870 : return build_call_expr (t, 2, size, size_int (align));
11227 : : }
11228 : : else
11229 : : {
11230 : 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA);
11231 : 0 : return build_call_expr (t, 1, size);
11232 : : }
11233 : : }
11234 : :
11235 : : /* The built-in decl to use to mark code points believed to be unreachable.
11236 : : Typically __builtin_unreachable, but __builtin_trap if
11237 : : -fsanitize=unreachable -fsanitize-trap=unreachable. If only
11238 : : -fsanitize=unreachable, we rely on sanopt to replace calls with the
11239 : : appropriate ubsan function. When building a call directly, use
11240 : : {gimple_},build_builtin_unreachable instead. */
11241 : :
11242 : : tree
11243 : 232990 : builtin_decl_unreachable ()
11244 : : {
11245 : 232990 : enum built_in_function fncode = BUILT_IN_UNREACHABLE;
11246 : :
11247 : 465980 : if (sanitize_flags_p (SANITIZE_UNREACHABLE)
11248 : 232990 : ? (flag_sanitize_trap & SANITIZE_UNREACHABLE)
11249 : 232394 : : flag_unreachable_traps)
11250 : 22 : fncode = BUILT_IN_UNREACHABLE_TRAP;
11251 : : /* For non-trapping sanitize, we will rewrite __builtin_unreachable () later,
11252 : : in the sanopt pass. */
11253 : :
11254 : 232990 : return builtin_decl_explicit (fncode);
11255 : : }
11256 : :
11257 : : /* Build a call to __builtin_unreachable, possibly rewritten by
11258 : : -fsanitize=unreachable. Use this rather than the above when practical. */
11259 : :
11260 : : tree
11261 : 15065508 : build_builtin_unreachable (location_t loc)
11262 : : {
11263 : 15065508 : tree data = NULL_TREE;
11264 : 15065508 : tree fn = sanitize_unreachable_fn (&data, loc);
11265 : 15065508 : return build_call_expr_loc (loc, fn, data != NULL_TREE, data);
11266 : : }
11267 : :
11268 : : /* Create a new constant string literal of type ELTYPE[SIZE] (or LEN
11269 : : if SIZE == -1) and return a tree node representing char* pointer to
11270 : : it as an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)). When STR is nonnull
11271 : : the STRING_CST value is the LEN bytes at STR (the representation
11272 : : of the string, which may be wide). Otherwise it's all zeros. */
11273 : :
11274 : : tree
11275 : 251994 : build_string_literal (unsigned len, const char *str /* = NULL */,
11276 : : tree eltype /* = char_type_node */,
11277 : : unsigned HOST_WIDE_INT size /* = -1 */)
11278 : : {
11279 : 251994 : tree t = build_string (len, str);
11280 : : /* Set the maximum valid index based on the string length or SIZE. */
11281 : 503988 : unsigned HOST_WIDE_INT maxidx
11282 : 251994 : = (size == HOST_WIDE_INT_M1U ? len : size) - 1;
11283 : :
11284 : 251994 : tree index = build_index_type (size_int (maxidx));
11285 : 251994 : eltype = build_type_variant (eltype, 1, 0);
11286 : 251994 : tree type = build_array_type (eltype, index);
11287 : 251994 : TREE_TYPE (t) = type;
11288 : 251994 : TREE_CONSTANT (t) = 1;
11289 : 251994 : TREE_READONLY (t) = 1;
11290 : 251994 : TREE_STATIC (t) = 1;
11291 : :
11292 : 251994 : type = build_pointer_type (eltype);
11293 : 251994 : t = build1 (ADDR_EXPR, type,
11294 : : build4 (ARRAY_REF, eltype,
11295 : : t, integer_zero_node, NULL_TREE, NULL_TREE));
11296 : 251994 : return t;
11297 : : }
11298 : :
11299 : :
11300 : :
11301 : : /* Return true if T (assumed to be a DECL) must be assigned a memory
11302 : : location. */
11303 : :
11304 : : bool
11305 : 1979264477 : needs_to_live_in_memory (const_tree t)
11306 : : {
11307 : 1979264477 : return (TREE_ADDRESSABLE (t)
11308 : 1581159621 : || is_global_var (t)
11309 : 3121980638 : || (TREE_CODE (t) == RESULT_DECL
11310 : 8123056 : && !DECL_BY_REFERENCE (t)
11311 : 5701791 : && aggregate_value_p (t, current_function_decl)));
11312 : : }
11313 : :
11314 : : /* Return value of a constant X and sign-extend it. */
11315 : :
11316 : : HOST_WIDE_INT
11317 : 600518291 : int_cst_value (const_tree x)
11318 : : {
11319 : 600518291 : unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
11320 : 600518291 : unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
11321 : :
11322 : : /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
11323 : 600518291 : gcc_assert (cst_and_fits_in_hwi (x));
11324 : :
11325 : 600518291 : if (bits < HOST_BITS_PER_WIDE_INT)
11326 : : {
11327 : 586330037 : bool negative = ((val >> (bits - 1)) & 1) != 0;
11328 : 586330037 : if (negative)
11329 : 221942 : val |= HOST_WIDE_INT_M1U << (bits - 1) << 1;
11330 : : else
11331 : 586108095 : val &= ~(HOST_WIDE_INT_M1U << (bits - 1) << 1);
11332 : : }
11333 : :
11334 : 600518291 : return val;
11335 : : }
11336 : :
11337 : : /* If TYPE is an integral or pointer type, return an integer type with
11338 : : the same precision which is unsigned iff UNSIGNEDP is true, or itself
11339 : : if TYPE is already an integer type of signedness UNSIGNEDP.
11340 : : If TYPE is a floating-point type, return an integer type with the same
11341 : : bitsize and with the signedness given by UNSIGNEDP; this is useful
11342 : : when doing bit-level operations on a floating-point value. */
11343 : :
11344 : : tree
11345 : 86689865 : signed_or_unsigned_type_for (int unsignedp, tree type)
11346 : : {
11347 : 86689865 : if (ANY_INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) == unsignedp)
11348 : : return type;
11349 : :
11350 : 55851579 : if (TREE_CODE (type) == VECTOR_TYPE)
11351 : : {
11352 : 23893 : tree inner = TREE_TYPE (type);
11353 : 23893 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11354 : 23893 : if (!inner2)
11355 : : return NULL_TREE;
11356 : 23893 : if (inner == inner2)
11357 : : return type;
11358 : 23893 : machine_mode new_mode;
11359 : 47786 : if (VECTOR_MODE_P (TYPE_MODE (type))
11360 : 47717 : && related_int_vector_mode (TYPE_MODE (type)).exists (&new_mode))
11361 : 23824 : return build_vector_type_for_mode (inner2, new_mode);
11362 : 69 : return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type));
11363 : : }
11364 : :
11365 : : if (TREE_CODE (type) == COMPLEX_TYPE)
11366 : : {
11367 : 24 : tree inner = TREE_TYPE (type);
11368 : 24 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11369 : 24 : if (!inner2)
11370 : : return NULL_TREE;
11371 : 24 : if (inner == inner2)
11372 : : return type;
11373 : 24 : return build_complex_type (inner2);
11374 : : }
11375 : :
11376 : : unsigned int bits;
11377 : : if (INTEGRAL_TYPE_P (type)
11378 : : || POINTER_TYPE_P (type)
11379 : : || TREE_CODE (type) == OFFSET_TYPE)
11380 : 55827568 : bits = TYPE_PRECISION (type);
11381 : : else if (TREE_CODE (type) == REAL_TYPE)
11382 : 188 : bits = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (type));
11383 : : else
11384 : : return NULL_TREE;
11385 : :
11386 : 55827662 : if (TREE_CODE (type) == BITINT_TYPE && (unsignedp || bits > 1))
11387 : 1644 : return build_bitint_type (bits, unsignedp);
11388 : 55826018 : return build_nonstandard_integer_type (bits, unsignedp);
11389 : : }
11390 : :
11391 : : /* If TYPE is an integral or pointer type, return an integer type with
11392 : : the same precision which is unsigned, or itself if TYPE is already an
11393 : : unsigned integer type. If TYPE is a floating-point type, return an
11394 : : unsigned integer type with the same bitsize as TYPE. */
11395 : :
11396 : : tree
11397 : 77423204 : unsigned_type_for (tree type)
11398 : : {
11399 : 77423204 : return signed_or_unsigned_type_for (1, type);
11400 : : }
11401 : :
11402 : : /* If TYPE is an integral or pointer type, return an integer type with
11403 : : the same precision which is signed, or itself if TYPE is already a
11404 : : signed integer type. If TYPE is a floating-point type, return a
11405 : : signed integer type with the same bitsize as TYPE. */
11406 : :
11407 : : tree
11408 : 9237682 : signed_type_for (tree type)
11409 : : {
11410 : 9237682 : return signed_or_unsigned_type_for (0, type);
11411 : : }
11412 : :
11413 : : /* - For VECTOR_TYPEs:
11414 : : - The truth type must be a VECTOR_BOOLEAN_TYPE.
11415 : : - The number of elements must match (known_eq).
11416 : : - targetm.vectorize.get_mask_mode exists, and exactly
11417 : : the same mode as the truth type.
11418 : : - Otherwise, the truth type must be a BOOLEAN_TYPE
11419 : : or useless_type_conversion_p to BOOLEAN_TYPE. */
11420 : : bool
11421 : 1932 : is_truth_type_for (tree type, tree truth_type)
11422 : : {
11423 : 1932 : machine_mode mask_mode = TYPE_MODE (truth_type);
11424 : 1932 : machine_mode vmode = TYPE_MODE (type);
11425 : 1932 : machine_mode tmask_mode;
11426 : :
11427 : 1932 : if (TREE_CODE (type) == VECTOR_TYPE)
11428 : : {
11429 : 1932 : if (VECTOR_BOOLEAN_TYPE_P (truth_type)
11430 : 1932 : && known_eq (TYPE_VECTOR_SUBPARTS (type),
11431 : : TYPE_VECTOR_SUBPARTS (truth_type))
11432 : 1932 : && targetm.vectorize.get_mask_mode (vmode).exists (&tmask_mode)
11433 : 3864 : && tmask_mode == mask_mode)
11434 : 1913 : return true;
11435 : :
11436 : 19 : return false;
11437 : : }
11438 : :
11439 : 0 : return useless_type_conversion_p (boolean_type_node, truth_type);
11440 : : }
11441 : :
11442 : : /* If TYPE is a vector type, return a signed integer vector type with the
11443 : : same width and number of subparts. Otherwise return boolean_type_node. */
11444 : :
11445 : : tree
11446 : 4205108 : truth_type_for (tree type)
11447 : : {
11448 : 4205108 : if (TREE_CODE (type) == VECTOR_TYPE)
11449 : : {
11450 : 2364615 : if (VECTOR_BOOLEAN_TYPE_P (type))
11451 : : return type;
11452 : 2294481 : return build_truth_vector_type_for (type);
11453 : : }
11454 : : else
11455 : 1840493 : return boolean_type_node;
11456 : : }
11457 : :
11458 : : /* Returns the largest value obtainable by casting something in INNER type to
11459 : : OUTER type. */
11460 : :
11461 : : tree
11462 : 10642818 : upper_bound_in_type (tree outer, tree inner)
11463 : : {
11464 : 10642818 : unsigned int det = 0;
11465 : 10642818 : unsigned oprec = TYPE_PRECISION (outer);
11466 : 10642818 : unsigned iprec = TYPE_PRECISION (inner);
11467 : 10642818 : unsigned prec;
11468 : :
11469 : : /* Compute a unique number for every combination. */
11470 : 10642818 : det |= (oprec > iprec) ? 4 : 0;
11471 : 10642818 : det |= TYPE_UNSIGNED (outer) ? 2 : 0;
11472 : 10642818 : det |= TYPE_UNSIGNED (inner) ? 1 : 0;
11473 : :
11474 : : /* Determine the exponent to use. */
11475 : 10642818 : switch (det)
11476 : : {
11477 : 7014049 : case 0:
11478 : 7014049 : case 1:
11479 : : /* oprec <= iprec, outer: signed, inner: don't care. */
11480 : 7014049 : prec = oprec - 1;
11481 : 7014049 : break;
11482 : : case 2:
11483 : : case 3:
11484 : : /* oprec <= iprec, outer: unsigned, inner: don't care. */
11485 : : prec = oprec;
11486 : : break;
11487 : 21947 : case 4:
11488 : : /* oprec > iprec, outer: signed, inner: signed. */
11489 : 21947 : prec = iprec - 1;
11490 : 21947 : break;
11491 : : case 5:
11492 : : /* oprec > iprec, outer: signed, inner: unsigned. */
11493 : 10782 : prec = iprec;
11494 : : break;
11495 : : case 6:
11496 : : /* oprec > iprec, outer: unsigned, inner: signed. */
11497 : : prec = oprec;
11498 : : break;
11499 : : case 7:
11500 : : /* oprec > iprec, outer: unsigned, inner: unsigned. */
11501 : 10782 : prec = iprec;
11502 : : break;
11503 : : default:
11504 : : gcc_unreachable ();
11505 : : }
11506 : :
11507 : 10642818 : return wide_int_to_tree (outer,
11508 : 10642818 : wi::mask (prec, false, TYPE_PRECISION (outer)));
11509 : : }
11510 : :
11511 : : /* Returns the smallest value obtainable by casting something in INNER type to
11512 : : OUTER type. */
11513 : :
11514 : : tree
11515 : 8096967 : lower_bound_in_type (tree outer, tree inner)
11516 : : {
11517 : 8096967 : unsigned oprec = TYPE_PRECISION (outer);
11518 : 8096967 : unsigned iprec = TYPE_PRECISION (inner);
11519 : :
11520 : : /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
11521 : : and obtain 0. */
11522 : 8096967 : if (TYPE_UNSIGNED (outer)
11523 : : /* If we are widening something of an unsigned type, OUTER type
11524 : : contains all values of INNER type. In particular, both INNER
11525 : : and OUTER types have zero in common. */
11526 : 8096967 : || (oprec > iprec && TYPE_UNSIGNED (inner)))
11527 : 2173000 : return build_int_cst (outer, 0);
11528 : : else
11529 : : {
11530 : : /* If we are widening a signed type to another signed type, we
11531 : : want to obtain -2^^(iprec-1). If we are keeping the
11532 : : precision or narrowing to a signed type, we want to obtain
11533 : : -2^(oprec-1). */
11534 : 5923967 : unsigned prec = oprec > iprec ? iprec : oprec;
11535 : 5923967 : return wide_int_to_tree (outer,
11536 : 11847934 : wi::mask (prec - 1, true,
11537 : 5923967 : TYPE_PRECISION (outer)));
11538 : : }
11539 : : }
11540 : :
11541 : : /* Return true if two operands that are suitable for PHI nodes are
11542 : : necessarily equal. Specifically, both ARG0 and ARG1 must be either
11543 : : SSA_NAME or invariant. Note that this is strictly an optimization.
11544 : : That is, callers of this function can directly call operand_equal_p
11545 : : and get the same result, only slower. */
11546 : :
11547 : : bool
11548 : 21492418 : operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1)
11549 : : {
11550 : 21492418 : if (arg0 == arg1)
11551 : : return true;
11552 : 19694463 : if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
11553 : : return false;
11554 : 3790804 : return operand_equal_p (arg0, arg1, 0);
11555 : : }
11556 : :
11557 : : /* Returns number of zeros at the end of binary representation of X. */
11558 : :
11559 : : tree
11560 : 8863490 : num_ending_zeros (const_tree x)
11561 : : {
11562 : 8863490 : return build_int_cst (TREE_TYPE (x), wi::ctz (wi::to_wide (x)));
11563 : : }
11564 : :
11565 : :
11566 : : #define WALK_SUBTREE(NODE) \
11567 : : do \
11568 : : { \
11569 : : result = walk_tree_1 (&(NODE), func, data, pset, lh); \
11570 : : if (result) \
11571 : : return result; \
11572 : : } \
11573 : : while (0)
11574 : :
11575 : : /* This is a subroutine of walk_tree that walks field of TYPE that are to
11576 : : be walked whenever a type is seen in the tree. Rest of operands and return
11577 : : value are as for walk_tree. */
11578 : :
11579 : : static tree
11580 : 3859560884 : walk_type_fields (tree type, walk_tree_fn func, void *data,
11581 : : hash_set<tree> *pset, walk_tree_lh lh)
11582 : : {
11583 : 3859560884 : tree result = NULL_TREE;
11584 : :
11585 : 3859560884 : switch (TREE_CODE (type))
11586 : : {
11587 : 1139946283 : case POINTER_TYPE:
11588 : 1139946283 : case REFERENCE_TYPE:
11589 : 1139946283 : case VECTOR_TYPE:
11590 : : /* We have to worry about mutually recursive pointers. These can't
11591 : : be written in C. They can in Ada. It's pathological, but
11592 : : there's an ACATS test (c38102a) that checks it. Deal with this
11593 : : by checking if we're pointing to another pointer, that one
11594 : : points to another pointer, that one does too, and we have no htab.
11595 : : If so, get a hash table. We check three levels deep to avoid
11596 : : the cost of the hash table if we don't need one. */
11597 : 2252372240 : if (POINTER_TYPE_P (TREE_TYPE (type))
11598 : 27520393 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
11599 : 4859459 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
11600 : 1144768661 : && !pset)
11601 : : {
11602 : 0 : result = walk_tree_without_duplicates (&TREE_TYPE (type),
11603 : : func, data);
11604 : 0 : if (result)
11605 : : return result;
11606 : :
11607 : : break;
11608 : : }
11609 : :
11610 : : /* fall through */
11611 : :
11612 : 1143144025 : case COMPLEX_TYPE:
11613 : 1143144025 : WALK_SUBTREE (TREE_TYPE (type));
11614 : : break;
11615 : :
11616 : 218571378 : case METHOD_TYPE:
11617 : 218571378 : WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
11618 : :
11619 : : /* Fall through. */
11620 : :
11621 : 359935044 : case FUNCTION_TYPE:
11622 : 359935044 : WALK_SUBTREE (TREE_TYPE (type));
11623 : 359935006 : {
11624 : 359935006 : tree arg;
11625 : :
11626 : : /* We never want to walk into default arguments. */
11627 : 1388472668 : for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
11628 : 1028567292 : WALK_SUBTREE (TREE_VALUE (arg));
11629 : : }
11630 : : break;
11631 : :
11632 : 12418563 : case ARRAY_TYPE:
11633 : : /* Don't follow this nodes's type if a pointer for fear that
11634 : : we'll have infinite recursion. If we have a PSET, then we
11635 : : need not fear. */
11636 : 12418563 : if (pset
11637 : 12418563 : || (!POINTER_TYPE_P (TREE_TYPE (type))
11638 : 107287 : && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
11639 : 12416862 : WALK_SUBTREE (TREE_TYPE (type));
11640 : 12415958 : WALK_SUBTREE (TYPE_DOMAIN (type));
11641 : : break;
11642 : :
11643 : 926915 : case OFFSET_TYPE:
11644 : 926915 : WALK_SUBTREE (TREE_TYPE (type));
11645 : 926083 : WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
11646 : : break;
11647 : :
11648 : : default:
11649 : : break;
11650 : : }
11651 : :
11652 : : return NULL_TREE;
11653 : : }
11654 : :
11655 : : /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
11656 : : called with the DATA and the address of each sub-tree. If FUNC returns a
11657 : : non-NULL value, the traversal is stopped, and the value returned by FUNC
11658 : : is returned. If PSET is non-NULL it is used to record the nodes visited,
11659 : : and to avoid visiting a node more than once. */
11660 : :
11661 : : tree
11662 : 97652215178 : walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
11663 : : hash_set<tree> *pset, walk_tree_lh lh)
11664 : : {
11665 : : #define WALK_SUBTREE_TAIL(NODE) \
11666 : : do \
11667 : : { \
11668 : : tp = & (NODE); \
11669 : : goto tail_recurse; \
11670 : : } \
11671 : : while (0)
11672 : :
11673 : >11837*10^7 : tail_recurse:
11674 : : /* Skip empty subtrees. */
11675 : >11837*10^7 : if (!*tp)
11676 : : return NULL_TREE;
11677 : :
11678 : : /* Don't walk the same tree twice, if the user has requested
11679 : : that we avoid doing so. */
11680 : 97100553353 : if (pset && pset->add (*tp))
11681 : : return NULL_TREE;
11682 : :
11683 : : /* Call the function. */
11684 : 95917594867 : int walk_subtrees = 1;
11685 : 95917594867 : tree result = (*func) (tp, &walk_subtrees, data);
11686 : :
11687 : : /* If we found something, return it. */
11688 : 95917594867 : if (result)
11689 : : return result;
11690 : :
11691 : 95855178242 : tree t = *tp;
11692 : 95855178242 : tree_code code = TREE_CODE (t);
11693 : :
11694 : : /* Even if we didn't, FUNC may have decided that there was nothing
11695 : : interesting below this point in the tree. */
11696 : 95855178242 : if (!walk_subtrees)
11697 : : {
11698 : : /* But we still need to check our siblings. */
11699 : 63200299470 : if (code == TREE_LIST)
11700 : 84198 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11701 : 63200215272 : else if (code == OMP_CLAUSE)
11702 : 874441 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11703 : : else
11704 : : return NULL_TREE;
11705 : : }
11706 : :
11707 : 32654878772 : if (lh)
11708 : : {
11709 : 16024765329 : result = (*lh) (tp, &walk_subtrees, func, data, pset);
11710 : 16024765329 : if (result || !walk_subtrees)
11711 : 2276326658 : return result;
11712 : : }
11713 : :
11714 : 30378552114 : switch (code)
11715 : : {
11716 : : case ERROR_MARK:
11717 : : case IDENTIFIER_NODE:
11718 : : case INTEGER_CST:
11719 : : case REAL_CST:
11720 : : case FIXED_CST:
11721 : : case STRING_CST:
11722 : : case BLOCK:
11723 : : case PLACEHOLDER_EXPR:
11724 : : case SSA_NAME:
11725 : : case FIELD_DECL:
11726 : : case RESULT_DECL:
11727 : : /* None of these have subtrees other than those already walked
11728 : : above. */
11729 : : break;
11730 : :
11731 : 226728400 : case TREE_LIST:
11732 : 226728400 : WALK_SUBTREE (TREE_VALUE (t));
11733 : 226220630 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11734 : :
11735 : 839926054 : case TREE_VEC:
11736 : 839926054 : {
11737 : 839926054 : int len = TREE_VEC_LENGTH (t);
11738 : :
11739 : 839926054 : if (len == 0)
11740 : : break;
11741 : :
11742 : : /* Walk all elements but the last. */
11743 : 1676663843 : for (int i = 0; i < len - 1; ++i)
11744 : 846029902 : WALK_SUBTREE (TREE_VEC_ELT (t, i));
11745 : :
11746 : : /* Now walk the last one as a tail call. */
11747 : 830633941 : WALK_SUBTREE_TAIL (TREE_VEC_ELT (t, len - 1));
11748 : : }
11749 : :
11750 : 4614350 : case VECTOR_CST:
11751 : 4614350 : {
11752 : 4614350 : unsigned len = vector_cst_encoded_nelts (t);
11753 : 4614350 : if (len == 0)
11754 : : break;
11755 : : /* Walk all elements but the last. */
11756 : 15903012 : for (unsigned i = 0; i < len - 1; ++i)
11757 : 11288806 : WALK_SUBTREE (VECTOR_CST_ENCODED_ELT (t, i));
11758 : : /* Now walk the last one as a tail call. */
11759 : 4614206 : WALK_SUBTREE_TAIL (VECTOR_CST_ENCODED_ELT (t, len - 1));
11760 : : }
11761 : :
11762 : 533229 : case COMPLEX_CST:
11763 : 533229 : WALK_SUBTREE (TREE_REALPART (t));
11764 : 531663 : WALK_SUBTREE_TAIL (TREE_IMAGPART (t));
11765 : :
11766 : : case CONSTRUCTOR:
11767 : : {
11768 : : unsigned HOST_WIDE_INT idx;
11769 : : constructor_elt *ce;
11770 : :
11771 : 618013920 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce);
11772 : : idx++)
11773 : 224150114 : WALK_SUBTREE (ce->value);
11774 : : }
11775 : : break;
11776 : :
11777 : 3439529 : case SAVE_EXPR:
11778 : 3439529 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, 0));
11779 : :
11780 : 156526371 : case BIND_EXPR:
11781 : 156526371 : {
11782 : 156526371 : tree decl;
11783 : 256219752 : for (decl = BIND_EXPR_VARS (t); decl; decl = DECL_CHAIN (decl))
11784 : : {
11785 : : /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
11786 : : into declarations that are just mentioned, rather than
11787 : : declared; they don't really belong to this part of the tree.
11788 : : And, we can see cycles: the initializer for a declaration
11789 : : can refer to the declaration itself. */
11790 : 99693405 : WALK_SUBTREE (DECL_INITIAL (decl));
11791 : 99693381 : WALK_SUBTREE (DECL_SIZE (decl));
11792 : 99693381 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
11793 : : }
11794 : 156526347 : WALK_SUBTREE_TAIL (BIND_EXPR_BODY (t));
11795 : : }
11796 : :
11797 : 164375768 : case STATEMENT_LIST:
11798 : 164375768 : {
11799 : 164375768 : tree_stmt_iterator i;
11800 : 606715371 : for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
11801 : 442481123 : WALK_SUBTREE (*tsi_stmt_ptr (i));
11802 : : }
11803 : 164234248 : break;
11804 : :
11805 : 1677144 : case OMP_CLAUSE:
11806 : 1677144 : {
11807 : 1677144 : int len = omp_clause_num_ops[OMP_CLAUSE_CODE (t)];
11808 : : /* Do not walk the iterator operand of OpenMP MAP clauses. */
11809 : 1677144 : if (OMP_CLAUSE_HAS_ITERATORS (t))
11810 : 781 : len--;
11811 : 4738226 : for (int i = 0; i < len; i++)
11812 : 3061082 : WALK_SUBTREE (OMP_CLAUSE_OPERAND (t, i));
11813 : 1677144 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11814 : : }
11815 : :
11816 : 43922842 : case TARGET_EXPR:
11817 : 43922842 : {
11818 : 43922842 : int i, len;
11819 : :
11820 : : /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
11821 : : But, we only want to walk once. */
11822 : 43922842 : len = (TREE_OPERAND (t, 3) == TREE_OPERAND (t, 1)) ? 2 : 3;
11823 : 175657625 : for (i = 0; i < len; ++i)
11824 : 131750446 : WALK_SUBTREE (TREE_OPERAND (t, i));
11825 : 43907179 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len));
11826 : : }
11827 : :
11828 : 95093424 : case DECL_EXPR:
11829 : : /* If this is a TYPE_DECL, walk into the fields of the type that it's
11830 : : defining. We only want to walk into these fields of a type in this
11831 : : case and not in the general case of a mere reference to the type.
11832 : :
11833 : : The criterion is as follows: if the field can be an expression, it
11834 : : must be walked only here. This should be in keeping with the fields
11835 : : that are directly gimplified in gimplify_type_sizes in order for the
11836 : : mark/copy-if-shared/unmark machinery of the gimplifier to work with
11837 : : variable-sized types.
11838 : :
11839 : : Note that DECLs get walked as part of processing the BIND_EXPR. */
11840 : 95093424 : if (TREE_CODE (DECL_EXPR_DECL (t)) == TYPE_DECL)
11841 : : {
11842 : : /* Call the function for the decl so e.g. copy_tree_body_r can
11843 : : replace it with the remapped one. */
11844 : 885125 : result = (*func) (&DECL_EXPR_DECL (t), &walk_subtrees, data);
11845 : 885125 : if (result || !walk_subtrees)
11846 : 43851 : return result;
11847 : :
11848 : 841274 : tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (t));
11849 : 841274 : if (TREE_CODE (*type_p) == ERROR_MARK)
11850 : : return NULL_TREE;
11851 : :
11852 : : /* Call the function for the type. See if it returns anything or
11853 : : doesn't want us to continue. If we are to continue, walk both
11854 : : the normal fields and those for the declaration case. */
11855 : 841274 : result = (*func) (type_p, &walk_subtrees, data);
11856 : 841274 : if (result || !walk_subtrees)
11857 : 71280 : return result;
11858 : :
11859 : 769994 : tree type = *type_p;
11860 : :
11861 : : /* But do not walk a pointed-to type since it may itself need to
11862 : : be walked in the declaration case if it isn't anonymous. */
11863 : 769994 : if (!POINTER_TYPE_P (type))
11864 : : {
11865 : 754301 : result = walk_type_fields (type, func, data, pset, lh);
11866 : 754301 : if (result)
11867 : : return result;
11868 : : }
11869 : :
11870 : : /* If this is a record type, also walk the fields. */
11871 : 769994 : if (RECORD_OR_UNION_TYPE_P (type))
11872 : : {
11873 : 297889 : tree field;
11874 : :
11875 : 1251785 : for (field = TYPE_FIELDS (type); field;
11876 : 953896 : field = DECL_CHAIN (field))
11877 : : {
11878 : : /* We'd like to look at the type of the field, but we can
11879 : : easily get infinite recursion. So assume it's pointed
11880 : : to elsewhere in the tree. Also, ignore things that
11881 : : aren't fields. */
11882 : 953896 : if (TREE_CODE (field) != FIELD_DECL)
11883 : 686280 : continue;
11884 : :
11885 : 267616 : WALK_SUBTREE (DECL_FIELD_OFFSET (field));
11886 : 267616 : WALK_SUBTREE (DECL_SIZE (field));
11887 : 267616 : WALK_SUBTREE (DECL_SIZE_UNIT (field));
11888 : 267616 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
11889 : 0 : WALK_SUBTREE (DECL_QUALIFIER (field));
11890 : : }
11891 : : }
11892 : :
11893 : : /* Same for scalar types. */
11894 : 472105 : else if (TREE_CODE (type) == BOOLEAN_TYPE
11895 : : || TREE_CODE (type) == ENUMERAL_TYPE
11896 : 472105 : || TREE_CODE (type) == INTEGER_TYPE
11897 : 472068 : || TREE_CODE (type) == FIXED_POINT_TYPE
11898 : 472068 : || TREE_CODE (type) == REAL_TYPE)
11899 : : {
11900 : 37 : WALK_SUBTREE (TYPE_MIN_VALUE (type));
11901 : 37 : WALK_SUBTREE (TYPE_MAX_VALUE (type));
11902 : : }
11903 : :
11904 : 769994 : WALK_SUBTREE (TYPE_SIZE (type));
11905 : 769994 : WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (type));
11906 : : }
11907 : : /* FALLTHRU */
11908 : :
11909 : 25674712422 : default:
11910 : 25674712422 : if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
11911 : : {
11912 : 19586681118 : int i, len;
11913 : :
11914 : : /* Walk over all the sub-trees of this operand. */
11915 : 19586681118 : len = TREE_OPERAND_LENGTH (t);
11916 : :
11917 : : /* Go through the subtrees. We need to do this in forward order so
11918 : : that the scope of a FOR_EXPR is handled properly. */
11919 : 19586681118 : if (len)
11920 : : {
11921 : 40710825059 : for (i = 0; i < len - 1; ++i)
11922 : 21257449555 : WALK_SUBTREE (TREE_OPERAND (t, i));
11923 : 19453375504 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len - 1));
11924 : : }
11925 : : }
11926 : : /* If this is a type, walk the needed fields in the type. */
11927 : 6088031304 : else if (TYPE_P (t))
11928 : 3858806583 : return walk_type_fields (t, func, data, pset, lh);
11929 : : break;
11930 : : }
11931 : :
11932 : : /* We didn't find what we were looking for. */
11933 : : return NULL_TREE;
11934 : :
11935 : : #undef WALK_SUBTREE_TAIL
11936 : : }
11937 : : #undef WALK_SUBTREE
11938 : :
11939 : : /* Like walk_tree, but does not walk duplicate nodes more than once. */
11940 : :
11941 : : tree
11942 : 2752652283 : walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data,
11943 : : walk_tree_lh lh)
11944 : : {
11945 : 2752652283 : tree result;
11946 : :
11947 : 2752652283 : hash_set<tree> pset;
11948 : 2752652283 : result = walk_tree_1 (tp, func, data, &pset, lh);
11949 : 2752652283 : return result;
11950 : 2752652283 : }
11951 : :
11952 : :
11953 : : tree
11954 : 866837367 : tree_block (tree t)
11955 : : {
11956 : 866837367 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
11957 : :
11958 : 866837367 : if (IS_EXPR_CODE_CLASS (c))
11959 : 866837367 : return LOCATION_BLOCK (t->exp.locus);
11960 : 0 : gcc_unreachable ();
11961 : : return NULL;
11962 : : }
11963 : :
11964 : : void
11965 : 442381149 : tree_set_block (tree t, tree b)
11966 : : {
11967 : 442381149 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
11968 : :
11969 : 442381149 : if (IS_EXPR_CODE_CLASS (c))
11970 : : {
11971 : 442381149 : t->exp.locus = set_block (t->exp.locus, b);
11972 : : }
11973 : : else
11974 : 0 : gcc_unreachable ();
11975 : 442381149 : }
11976 : :
11977 : : /* Create a nameless artificial label and put it in the current
11978 : : function context. The label has a location of LOC. Returns the
11979 : : newly created label. */
11980 : :
11981 : : tree
11982 : 31066537 : create_artificial_label (location_t loc)
11983 : : {
11984 : 31066537 : tree lab = build_decl (loc,
11985 : : LABEL_DECL, NULL_TREE, void_type_node);
11986 : :
11987 : 31066537 : DECL_ARTIFICIAL (lab) = 1;
11988 : 31066537 : DECL_IGNORED_P (lab) = 1;
11989 : 31066537 : DECL_CONTEXT (lab) = current_function_decl;
11990 : 31066537 : return lab;
11991 : : }
11992 : :
11993 : : /* Given a tree, try to return a useful variable name that we can use
11994 : : to prefix a temporary that is being assigned the value of the tree.
11995 : : I.E. given <temp> = &A, return A. */
11996 : :
11997 : : const char *
11998 : 24785019 : get_name (tree t)
11999 : : {
12000 : 26670948 : tree stripped_decl;
12001 : :
12002 : 26670948 : stripped_decl = t;
12003 : 26670948 : STRIP_NOPS (stripped_decl);
12004 : 26670948 : if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl))
12005 : 4061271 : return IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
12006 : 22609677 : else if (TREE_CODE (stripped_decl) == SSA_NAME)
12007 : : {
12008 : 1292364 : tree name = SSA_NAME_IDENTIFIER (stripped_decl);
12009 : 318722 : if (!name)
12010 : : return NULL;
12011 : 317450 : return IDENTIFIER_POINTER (name);
12012 : : }
12013 : : else
12014 : : {
12015 : 21317313 : switch (TREE_CODE (stripped_decl))
12016 : : {
12017 : 1885929 : case ADDR_EXPR:
12018 : 1885929 : return get_name (TREE_OPERAND (stripped_decl, 0));
12019 : : default:
12020 : : return NULL;
12021 : : }
12022 : : }
12023 : : }
12024 : :
12025 : : /* Return true if TYPE has a variable argument list. */
12026 : :
12027 : : bool
12028 : 209150332 : stdarg_p (const_tree fntype)
12029 : : {
12030 : 209150332 : function_args_iterator args_iter;
12031 : 209150332 : tree n = NULL_TREE, t;
12032 : :
12033 : 209150332 : if (!fntype)
12034 : : return false;
12035 : :
12036 : 209016945 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
12037 : : return true;
12038 : :
12039 : 849359562 : FOREACH_FUNCTION_ARGS (fntype, t, args_iter)
12040 : : {
12041 : 641056317 : n = t;
12042 : : }
12043 : :
12044 : 208303245 : return n != NULL_TREE && n != void_type_node;
12045 : : }
12046 : :
12047 : : /* Return true if TYPE has a prototype. */
12048 : :
12049 : : bool
12050 : 719628806 : prototype_p (const_tree fntype)
12051 : : {
12052 : 719628806 : tree t;
12053 : :
12054 : 719628806 : gcc_assert (fntype != NULL_TREE);
12055 : :
12056 : 719628806 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
12057 : : return true;
12058 : :
12059 : 718820862 : t = TYPE_ARG_TYPES (fntype);
12060 : 718820862 : return (t != NULL_TREE);
12061 : : }
12062 : :
12063 : : /* If BLOCK is inlined from an __attribute__((__artificial__))
12064 : : routine, return pointer to location from where it has been
12065 : : called. */
12066 : : location_t *
12067 : 176098 : block_nonartificial_location (tree block)
12068 : : {
12069 : 176098 : location_t *ret = NULL;
12070 : :
12071 : 451819 : while (block && TREE_CODE (block) == BLOCK
12072 : 546044 : && BLOCK_ABSTRACT_ORIGIN (block))
12073 : : {
12074 : 169957 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12075 : 169957 : if (TREE_CODE (ao) == FUNCTION_DECL)
12076 : : {
12077 : : /* If AO is an artificial inline, point RET to the
12078 : : call site locus at which it has been inlined and continue
12079 : : the loop, in case AO's caller is also an artificial
12080 : : inline. */
12081 : 72070 : if (DECL_DECLARED_INLINE_P (ao)
12082 : 72070 : && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
12083 : 1789 : ret = &BLOCK_SOURCE_LOCATION (block);
12084 : : else
12085 : : break;
12086 : : }
12087 : 97887 : else if (TREE_CODE (ao) != BLOCK)
12088 : : break;
12089 : :
12090 : 99676 : block = BLOCK_SUPERCONTEXT (block);
12091 : : }
12092 : 176098 : return ret;
12093 : : }
12094 : :
12095 : :
12096 : : /* If EXP is inlined from an __attribute__((__artificial__))
12097 : : function, return the location of the original call expression. */
12098 : :
12099 : : location_t
12100 : 53 : tree_nonartificial_location (tree exp)
12101 : : {
12102 : 53 : location_t *loc = block_nonartificial_location (TREE_BLOCK (exp));
12103 : :
12104 : 53 : if (loc)
12105 : 0 : return *loc;
12106 : : else
12107 : 53 : return EXPR_LOCATION (exp);
12108 : : }
12109 : :
12110 : : /* Return the location into which EXP has been inlined. Analogous
12111 : : to tree_nonartificial_location() above but not limited to artificial
12112 : : functions declared inline. If SYSTEM_HEADER is true, return
12113 : : the macro expansion point of the location if it's in a system header */
12114 : :
12115 : : location_t
12116 : 0 : tree_inlined_location (tree exp, bool system_header /* = true */)
12117 : : {
12118 : 0 : location_t loc = UNKNOWN_LOCATION;
12119 : :
12120 : 0 : tree block = TREE_BLOCK (exp);
12121 : :
12122 : 0 : while (block && TREE_CODE (block) == BLOCK
12123 : 0 : && BLOCK_ABSTRACT_ORIGIN (block))
12124 : : {
12125 : 0 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12126 : 0 : if (TREE_CODE (ao) == FUNCTION_DECL)
12127 : 0 : loc = BLOCK_SOURCE_LOCATION (block);
12128 : 0 : else if (TREE_CODE (ao) != BLOCK)
12129 : : break;
12130 : :
12131 : 0 : block = BLOCK_SUPERCONTEXT (block);
12132 : : }
12133 : :
12134 : 0 : if (loc == UNKNOWN_LOCATION)
12135 : : {
12136 : 0 : loc = EXPR_LOCATION (exp);
12137 : 0 : if (system_header)
12138 : : /* Only consider macro expansion when the block traversal failed
12139 : : to find a location. Otherwise it's not relevant. */
12140 : 0 : return expansion_point_location_if_in_system_header (loc);
12141 : : }
12142 : :
12143 : : return loc;
12144 : : }
12145 : :
12146 : : /* These are the hash table functions for the hash table of OPTIMIZATION_NODE
12147 : : nodes. */
12148 : :
12149 : : /* Return the hash code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
12150 : :
12151 : : hashval_t
12152 : 861068589 : cl_option_hasher::hash (tree x)
12153 : : {
12154 : 861068589 : const_tree const t = x;
12155 : :
12156 : 861068589 : if (TREE_CODE (t) == OPTIMIZATION_NODE)
12157 : 96414519 : return cl_optimization_hash (TREE_OPTIMIZATION (t));
12158 : 764654070 : else if (TREE_CODE (t) == TARGET_OPTION_NODE)
12159 : 764654070 : return cl_target_option_hash (TREE_TARGET_OPTION (t));
12160 : : else
12161 : 0 : gcc_unreachable ();
12162 : : }
12163 : :
12164 : : /* Return nonzero if the value represented by *X (an OPTIMIZATION or
12165 : : TARGET_OPTION tree node) is the same as that given by *Y, which is the
12166 : : same. */
12167 : :
12168 : : bool
12169 : 924898865 : cl_option_hasher::equal (tree x, tree y)
12170 : : {
12171 : 924898865 : const_tree const xt = x;
12172 : 924898865 : const_tree const yt = y;
12173 : :
12174 : 924898865 : if (TREE_CODE (xt) != TREE_CODE (yt))
12175 : : return false;
12176 : :
12177 : 531044540 : if (TREE_CODE (xt) == OPTIMIZATION_NODE)
12178 : 95415170 : return cl_optimization_option_eq (TREE_OPTIMIZATION (xt),
12179 : 95415170 : TREE_OPTIMIZATION (yt));
12180 : 435629370 : else if (TREE_CODE (xt) == TARGET_OPTION_NODE)
12181 : 435629370 : return cl_target_option_eq (TREE_TARGET_OPTION (xt),
12182 : 435629370 : TREE_TARGET_OPTION (yt));
12183 : : else
12184 : 0 : gcc_unreachable ();
12185 : : }
12186 : :
12187 : : /* Build an OPTIMIZATION_NODE based on the options in OPTS and OPTS_SET. */
12188 : :
12189 : : tree
12190 : 95701685 : build_optimization_node (struct gcc_options *opts,
12191 : : struct gcc_options *opts_set)
12192 : : {
12193 : 95701685 : tree t;
12194 : :
12195 : : /* Use the cache of optimization nodes. */
12196 : :
12197 : 95701685 : cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node),
12198 : : opts, opts_set);
12199 : :
12200 : 95701685 : tree *slot = cl_option_hash_table->find_slot (cl_optimization_node, INSERT);
12201 : 95701685 : t = *slot;
12202 : 95701685 : if (!t)
12203 : : {
12204 : : /* Insert this one into the hash table. */
12205 : 291328 : t = cl_optimization_node;
12206 : 291328 : *slot = t;
12207 : :
12208 : : /* Make a new node for next time round. */
12209 : 291328 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
12210 : : }
12211 : :
12212 : 95701685 : return t;
12213 : : }
12214 : :
12215 : : /* Build a TARGET_OPTION_NODE based on the options in OPTS and OPTS_SET. */
12216 : :
12217 : : tree
12218 : 74133060 : build_target_option_node (struct gcc_options *opts,
12219 : : struct gcc_options *opts_set)
12220 : : {
12221 : 74133060 : tree t;
12222 : :
12223 : : /* Use the cache of optimization nodes. */
12224 : :
12225 : 74133060 : cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node),
12226 : : opts, opts_set);
12227 : :
12228 : 74133060 : tree *slot = cl_option_hash_table->find_slot (cl_target_option_node, INSERT);
12229 : 74133060 : t = *slot;
12230 : 74133060 : if (!t)
12231 : : {
12232 : : /* Insert this one into the hash table. */
12233 : 753197 : t = cl_target_option_node;
12234 : 753197 : *slot = t;
12235 : :
12236 : : /* Make a new node for next time round. */
12237 : 753197 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
12238 : : }
12239 : :
12240 : 74133060 : return t;
12241 : : }
12242 : :
12243 : : /* Clear TREE_TARGET_GLOBALS of all TARGET_OPTION_NODE trees,
12244 : : so that they aren't saved during PCH writing. */
12245 : :
12246 : : void
12247 : 467 : prepare_target_option_nodes_for_pch (void)
12248 : : {
12249 : 467 : hash_table<cl_option_hasher>::iterator iter = cl_option_hash_table->begin ();
12250 : 2802 : for (; iter != cl_option_hash_table->end (); ++iter)
12251 : 934 : if (TREE_CODE (*iter) == TARGET_OPTION_NODE)
12252 : 467 : TREE_TARGET_GLOBALS (*iter) = NULL;
12253 : 467 : }
12254 : :
12255 : : /* Determine the "ultimate origin" of a block. */
12256 : :
12257 : : tree
12258 : 217780554 : block_ultimate_origin (const_tree block)
12259 : : {
12260 : 217780554 : tree origin = BLOCK_ABSTRACT_ORIGIN (block);
12261 : :
12262 : 217780554 : if (origin == NULL_TREE)
12263 : : return NULL_TREE;
12264 : : else
12265 : : {
12266 : 264052084 : gcc_checking_assert ((DECL_P (origin)
12267 : : && DECL_ORIGIN (origin) == origin)
12268 : : || BLOCK_ORIGIN (origin) == origin);
12269 : : return origin;
12270 : : }
12271 : : }
12272 : :
12273 : : /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates
12274 : : no instruction. */
12275 : :
12276 : : bool
12277 : 1328153391 : tree_nop_conversion_p (const_tree outer_type, const_tree inner_type)
12278 : : {
12279 : : /* Do not strip casts into or out of differing address spaces. */
12280 : 1328153391 : if (POINTER_TYPE_P (outer_type)
12281 : 1328153391 : && TYPE_ADDR_SPACE (TREE_TYPE (outer_type)) != ADDR_SPACE_GENERIC)
12282 : : {
12283 : 570 : if (!POINTER_TYPE_P (inner_type)
12284 : 570 : || (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
12285 : 547 : != TYPE_ADDR_SPACE (TREE_TYPE (inner_type))))
12286 : : return false;
12287 : : }
12288 : 1328152821 : else if (POINTER_TYPE_P (inner_type)
12289 : 1328152821 : && TYPE_ADDR_SPACE (TREE_TYPE (inner_type)) != ADDR_SPACE_GENERIC)
12290 : : {
12291 : : /* We already know that outer_type is not a pointer with
12292 : : a non-generic address space. */
12293 : : return false;
12294 : : }
12295 : :
12296 : : /* Use precision rather then machine mode when we can, which gives
12297 : : the correct answer even for submode (bit-field) types. */
12298 : 1328150654 : if ((INTEGRAL_TYPE_P (outer_type)
12299 : 447425504 : || POINTER_TYPE_P (outer_type)
12300 : 73093499 : || TREE_CODE (outer_type) == OFFSET_TYPE)
12301 : 1255067684 : && (INTEGRAL_TYPE_P (inner_type)
12302 : 451794418 : || POINTER_TYPE_P (inner_type)
12303 : 1406808 : || TREE_CODE (inner_type) == OFFSET_TYPE))
12304 : 1253683745 : return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type);
12305 : :
12306 : : /* Otherwise fall back on comparing machine modes (e.g. for
12307 : : aggregate types, floats). */
12308 : 74466909 : return TYPE_MODE (outer_type) == TYPE_MODE (inner_type);
12309 : : }
12310 : :
12311 : : /* Return true iff conversion in EXP generates no instruction. Mark
12312 : : it inline so that we fully inline into the stripping functions even
12313 : : though we have two uses of this function. */
12314 : :
12315 : : static inline bool
12316 : 17654048139 : tree_nop_conversion (const_tree exp)
12317 : : {
12318 : 17654048139 : tree outer_type, inner_type;
12319 : :
12320 : 17654048139 : if (location_wrapper_p (exp))
12321 : : return true;
12322 : 17609628363 : if (!CONVERT_EXPR_P (exp)
12323 : 16817852521 : && TREE_CODE (exp) != NON_LVALUE_EXPR)
12324 : : return false;
12325 : :
12326 : 804671247 : outer_type = TREE_TYPE (exp);
12327 : 804671247 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12328 : 804671247 : if (!inner_type || inner_type == error_mark_node)
12329 : : return false;
12330 : :
12331 : 804671247 : return tree_nop_conversion_p (outer_type, inner_type);
12332 : : }
12333 : :
12334 : : /* Return true iff conversion in EXP generates no instruction. Don't
12335 : : consider conversions changing the signedness. */
12336 : :
12337 : : static bool
12338 : 1782712411 : tree_sign_nop_conversion (const_tree exp)
12339 : : {
12340 : 1782712411 : tree outer_type, inner_type;
12341 : :
12342 : 1782712411 : if (!tree_nop_conversion (exp))
12343 : : return false;
12344 : :
12345 : 134705817 : outer_type = TREE_TYPE (exp);
12346 : 134705817 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12347 : :
12348 : 134705817 : return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type)
12349 : 134705817 : && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
12350 : : }
12351 : :
12352 : : /* Strip conversions from EXP according to tree_nop_conversion and
12353 : : return the resulting expression. */
12354 : :
12355 : : tree
12356 : 15297381013 : tree_strip_nop_conversions (tree exp)
12357 : : {
12358 : 15871335728 : while (tree_nop_conversion (exp))
12359 : 573954715 : exp = TREE_OPERAND (exp, 0);
12360 : 15297381013 : return exp;
12361 : : }
12362 : :
12363 : : /* Strip conversions from EXP according to tree_sign_nop_conversion
12364 : : and return the resulting expression. */
12365 : :
12366 : : tree
12367 : 1671519325 : tree_strip_sign_nop_conversions (tree exp)
12368 : : {
12369 : 1782712411 : while (tree_sign_nop_conversion (exp))
12370 : 111193086 : exp = TREE_OPERAND (exp, 0);
12371 : 1671519325 : return exp;
12372 : : }
12373 : :
12374 : : /* Avoid any floating point extensions from EXP. */
12375 : : tree
12376 : 84077334 : strip_float_extensions (tree exp)
12377 : : {
12378 : 84220317 : tree sub, expt, subt;
12379 : :
12380 : : /* For floating point constant look up the narrowest type that can hold
12381 : : it properly and handle it like (type)(narrowest_type)constant.
12382 : : This way we can optimize for instance a=a*2.0 where "a" is float
12383 : : but 2.0 is double constant. */
12384 : 84220317 : if (TREE_CODE (exp) == REAL_CST && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp)))
12385 : : {
12386 : 2581998 : REAL_VALUE_TYPE orig;
12387 : 2581998 : tree type = NULL;
12388 : :
12389 : 2581998 : orig = TREE_REAL_CST (exp);
12390 : 2581998 : if (TYPE_PRECISION (TREE_TYPE (exp)) > TYPE_PRECISION (float_type_node)
12391 : 2581998 : && exact_real_truncate (TYPE_MODE (float_type_node), &orig))
12392 : 140541 : type = float_type_node;
12393 : 2441457 : else if (TYPE_PRECISION (TREE_TYPE (exp))
12394 : 2441457 : > TYPE_PRECISION (double_type_node)
12395 : 2441457 : && exact_real_truncate (TYPE_MODE (double_type_node), &orig))
12396 : 35199 : type = double_type_node;
12397 : 2581998 : if (type)
12398 : 175740 : return build_real_truncate (type, orig);
12399 : : }
12400 : :
12401 : 84044577 : if (!CONVERT_EXPR_P (exp))
12402 : : return exp;
12403 : :
12404 : 4068195 : sub = TREE_OPERAND (exp, 0);
12405 : 4068195 : subt = TREE_TYPE (sub);
12406 : 4068195 : expt = TREE_TYPE (exp);
12407 : :
12408 : 4068195 : if (!FLOAT_TYPE_P (subt))
12409 : : return exp;
12410 : :
12411 : 500218 : if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_FLOAT_TYPE_P (subt))
12412 : : return exp;
12413 : :
12414 : 167104 : if (element_precision (subt) > element_precision (expt))
12415 : : return exp;
12416 : :
12417 : : return strip_float_extensions (sub);
12418 : : }
12419 : :
12420 : : /* Strip out all handled components that produce invariant
12421 : : offsets. */
12422 : :
12423 : : const_tree
12424 : 5769811995 : strip_invariant_refs (const_tree op)
12425 : : {
12426 : 6724530105 : while (handled_component_p (op))
12427 : : {
12428 : 966462234 : switch (TREE_CODE (op))
12429 : : {
12430 : 193048996 : case ARRAY_REF:
12431 : 193048996 : case ARRAY_RANGE_REF:
12432 : 193048996 : if (!is_gimple_constant (TREE_OPERAND (op, 1))
12433 : 182988266 : || TREE_OPERAND (op, 2) != NULL_TREE
12434 : 181437447 : || TREE_OPERAND (op, 3) != NULL_TREE)
12435 : : return NULL;
12436 : : break;
12437 : :
12438 : 773124585 : case COMPONENT_REF:
12439 : 773124585 : if (TREE_OPERAND (op, 2) != NULL_TREE)
12440 : : return NULL;
12441 : : break;
12442 : :
12443 : 954718110 : default:;
12444 : : }
12445 : 954718110 : op = TREE_OPERAND (op, 0);
12446 : : }
12447 : :
12448 : : return op;
12449 : : }
12450 : :
12451 : : /* Strip handled components with zero offset from OP. */
12452 : :
12453 : : tree
12454 : 566675 : strip_zero_offset_components (tree op)
12455 : : {
12456 : 566675 : while (TREE_CODE (op) == COMPONENT_REF
12457 : 438262 : && integer_zerop (DECL_FIELD_OFFSET (TREE_OPERAND (op, 1)))
12458 : 1115551 : && integer_zerop (DECL_FIELD_BIT_OFFSET (TREE_OPERAND (op, 1))))
12459 : 180141 : op = TREE_OPERAND (op, 0);
12460 : 566675 : return op;
12461 : : }
12462 : :
12463 : : static GTY(()) tree gcc_eh_personality_decl;
12464 : :
12465 : : /* Return the GCC personality function decl. */
12466 : :
12467 : : tree
12468 : 395 : lhd_gcc_personality (void)
12469 : : {
12470 : 395 : if (!gcc_eh_personality_decl)
12471 : 153 : gcc_eh_personality_decl = build_personality_function ("gcc");
12472 : 395 : return gcc_eh_personality_decl;
12473 : : }
12474 : :
12475 : : /* TARGET is a call target of GIMPLE call statement
12476 : : (obtained by gimple_call_fn). Return true if it is
12477 : : OBJ_TYPE_REF representing an virtual call of C++ method.
12478 : : (As opposed to OBJ_TYPE_REF representing objc calls
12479 : : through a cast where middle-end devirtualization machinery
12480 : : can't apply.) FOR_DUMP_P is true when being called from
12481 : : the dump routines. */
12482 : :
12483 : : bool
12484 : 27819547 : virtual_method_call_p (const_tree target, bool for_dump_p)
12485 : : {
12486 : 27819547 : if (TREE_CODE (target) != OBJ_TYPE_REF)
12487 : : return false;
12488 : 1418543 : tree t = TREE_TYPE (target);
12489 : 1418543 : gcc_checking_assert (TREE_CODE (t) == POINTER_TYPE);
12490 : 1418543 : t = TREE_TYPE (t);
12491 : 1418543 : if (TREE_CODE (t) == FUNCTION_TYPE)
12492 : : return false;
12493 : 1417455 : gcc_checking_assert (TREE_CODE (t) == METHOD_TYPE);
12494 : : /* If we do not have BINFO associated, it means that type was built
12495 : : without devirtualization enabled. Do not consider this a virtual
12496 : : call. */
12497 : 1417455 : if (!TYPE_BINFO (obj_type_ref_class (target, for_dump_p)))
12498 : : return false;
12499 : : return true;
12500 : : }
12501 : :
12502 : : /* Lookup sub-BINFO of BINFO of TYPE at offset POS. */
12503 : :
12504 : : static tree
12505 : 108 : lookup_binfo_at_offset (tree binfo, tree type, HOST_WIDE_INT pos)
12506 : : {
12507 : 108 : unsigned int i;
12508 : 108 : tree base_binfo, b;
12509 : :
12510 : 124 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12511 : 108 : if (pos == tree_to_shwi (BINFO_OFFSET (base_binfo))
12512 : 108 : && types_same_for_odr (TREE_TYPE (base_binfo), type))
12513 : : return base_binfo;
12514 : 70 : else if ((b = lookup_binfo_at_offset (base_binfo, type, pos)) != NULL)
12515 : : return b;
12516 : : return NULL;
12517 : : }
12518 : :
12519 : : /* Try to find a base info of BINFO that would have its field decl at offset
12520 : : OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
12521 : : found, return, otherwise return NULL_TREE. */
12522 : :
12523 : : tree
12524 : 372474 : get_binfo_at_offset (tree binfo, poly_int64 offset, tree expected_type)
12525 : : {
12526 : 372474 : tree type = BINFO_TYPE (binfo);
12527 : :
12528 : 1046188 : while (true)
12529 : : {
12530 : 709331 : HOST_WIDE_INT pos, size;
12531 : 709331 : tree fld;
12532 : 709331 : int i;
12533 : :
12534 : 709331 : if (types_same_for_odr (type, expected_type))
12535 : 372474 : return binfo;
12536 : 336857 : if (maybe_lt (offset, 0))
12537 : : return NULL_TREE;
12538 : :
12539 : 2075663 : for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
12540 : : {
12541 : 2075663 : if (TREE_CODE (fld) != FIELD_DECL || !DECL_ARTIFICIAL (fld))
12542 : 1738609 : continue;
12543 : :
12544 : 337054 : pos = int_bit_position (fld);
12545 : 337054 : size = tree_to_uhwi (DECL_SIZE (fld));
12546 : 2075860 : if (known_in_range_p (offset, pos, size))
12547 : : break;
12548 : : }
12549 : 336857 : if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE)
12550 : : return NULL_TREE;
12551 : :
12552 : : /* Offset 0 indicates the primary base, whose vtable contents are
12553 : : represented in the binfo for the derived class. */
12554 : 336857 : else if (maybe_ne (offset, 0))
12555 : : {
12556 : 197 : tree found_binfo = NULL, base_binfo;
12557 : : /* Offsets in BINFO are in bytes relative to the whole structure
12558 : : while POS is in bits relative to the containing field. */
12559 : 197 : int binfo_offset = (tree_to_shwi (BINFO_OFFSET (binfo)) + pos
12560 : 197 : / BITS_PER_UNIT);
12561 : :
12562 : 377 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12563 : 339 : if (tree_to_shwi (BINFO_OFFSET (base_binfo)) == binfo_offset
12564 : 339 : && types_same_for_odr (TREE_TYPE (base_binfo), TREE_TYPE (fld)))
12565 : : {
12566 : : found_binfo = base_binfo;
12567 : : break;
12568 : : }
12569 : 197 : if (found_binfo)
12570 : : binfo = found_binfo;
12571 : : else
12572 : 38 : binfo = lookup_binfo_at_offset (binfo, TREE_TYPE (fld),
12573 : : binfo_offset);
12574 : : }
12575 : :
12576 : 336857 : type = TREE_TYPE (fld);
12577 : 336857 : offset -= pos;
12578 : 336857 : }
12579 : : }
12580 : :
12581 : : /* PR 84195: Replace control characters in "unescaped" with their
12582 : : escaped equivalents. Allow newlines if -fmessage-length has
12583 : : been set to a non-zero value. This is done here, rather than
12584 : : where the attribute is recorded as the message length can
12585 : : change between these two locations. */
12586 : :
12587 : : void
12588 : 133649 : escaped_string::escape (const char *unescaped)
12589 : : {
12590 : 133649 : char *escaped;
12591 : 133649 : size_t i, new_i, len;
12592 : :
12593 : 133649 : if (m_owned)
12594 : 8 : free (m_str);
12595 : :
12596 : 133649 : m_str = const_cast<char *> (unescaped);
12597 : 133649 : m_owned = false;
12598 : :
12599 : 133649 : if (unescaped == NULL || *unescaped == 0)
12600 : : return;
12601 : :
12602 : 133641 : len = strlen (unescaped);
12603 : 133641 : escaped = NULL;
12604 : 133641 : new_i = 0;
12605 : :
12606 : 3902950 : for (i = 0; i < len; i++)
12607 : : {
12608 : 3769309 : char c = unescaped[i];
12609 : :
12610 : 3769309 : if (!ISCNTRL (c))
12611 : : {
12612 : 3769224 : if (escaped)
12613 : 33 : escaped[new_i++] = c;
12614 : 3769224 : continue;
12615 : : }
12616 : :
12617 : 85 : if (c != '\n' || !pp_is_wrapping_line (global_dc->get_reference_printer ()))
12618 : : {
12619 : 77 : if (escaped == NULL)
12620 : : {
12621 : : /* We only allocate space for a new string if we
12622 : : actually encounter a control character that
12623 : : needs replacing. */
12624 : 19 : escaped = (char *) xmalloc (len * 2 + 1);
12625 : 19 : strncpy (escaped, unescaped, i);
12626 : 19 : new_i = i;
12627 : : }
12628 : :
12629 : 77 : escaped[new_i++] = '\\';
12630 : :
12631 : 77 : switch (c)
12632 : : {
12633 : 8 : case '\a': escaped[new_i++] = 'a'; break;
12634 : 8 : case '\b': escaped[new_i++] = 'b'; break;
12635 : 8 : case '\f': escaped[new_i++] = 'f'; break;
12636 : 15 : case '\n': escaped[new_i++] = 'n'; break;
12637 : 15 : case '\r': escaped[new_i++] = 'r'; break;
12638 : 15 : case '\t': escaped[new_i++] = 't'; break;
12639 : 8 : case '\v': escaped[new_i++] = 'v'; break;
12640 : 0 : default: escaped[new_i++] = '?'; break;
12641 : : }
12642 : : }
12643 : 8 : else if (escaped)
12644 : 4 : escaped[new_i++] = c;
12645 : : }
12646 : :
12647 : 133641 : if (escaped)
12648 : : {
12649 : 19 : escaped[new_i] = 0;
12650 : 19 : m_str = escaped;
12651 : 19 : m_owned = true;
12652 : : }
12653 : : }
12654 : :
12655 : : /* Warn about a use of an identifier which was marked deprecated. Returns
12656 : : whether a warning was given. */
12657 : :
12658 : : bool
12659 : 1285985 : warn_deprecated_use (tree node, tree attr)
12660 : : {
12661 : 1285985 : escaped_string msg;
12662 : :
12663 : 1285985 : if (node == 0 || !warn_deprecated_decl)
12664 : : return false;
12665 : :
12666 : 1280924 : if (!attr)
12667 : : {
12668 : 1168128 : if (DECL_P (node))
12669 : 1168000 : attr = DECL_ATTRIBUTES (node);
12670 : 128 : else if (TYPE_P (node))
12671 : : {
12672 : 128 : tree decl = TYPE_STUB_DECL (node);
12673 : 128 : if (decl)
12674 : 104 : attr = TYPE_ATTRIBUTES (TREE_TYPE (decl));
12675 : 24 : else if ((decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (node)))
12676 : : != NULL_TREE)
12677 : : {
12678 : 6 : node = TREE_TYPE (decl);
12679 : 6 : attr = TYPE_ATTRIBUTES (node);
12680 : : }
12681 : : }
12682 : : }
12683 : :
12684 : 1168128 : if (attr)
12685 : 133336 : attr = lookup_attribute ("deprecated", attr);
12686 : :
12687 : 133336 : if (attr)
12688 : 133330 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12689 : :
12690 : 1280924 : bool w = false;
12691 : 1280924 : if (DECL_P (node))
12692 : : {
12693 : 1280786 : auto_diagnostic_group d;
12694 : 1280786 : if (msg)
12695 : 133281 : w = warning (OPT_Wdeprecated_declarations,
12696 : : "%qD is deprecated: %s", node, (const char *) msg);
12697 : : else
12698 : 1147505 : w = warning (OPT_Wdeprecated_declarations,
12699 : : "%qD is deprecated", node);
12700 : 1280786 : if (w)
12701 : 786 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12702 : 1280786 : }
12703 : 138 : else if (TYPE_P (node))
12704 : : {
12705 : 138 : tree what = NULL_TREE;
12706 : 138 : tree decl = TYPE_STUB_DECL (node);
12707 : :
12708 : 138 : if (TYPE_NAME (node))
12709 : : {
12710 : 133 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12711 : 10 : what = TYPE_NAME (node);
12712 : 123 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12713 : 123 : && DECL_NAME (TYPE_NAME (node)))
12714 : 123 : what = DECL_NAME (TYPE_NAME (node));
12715 : : }
12716 : :
12717 : 138 : auto_diagnostic_group d;
12718 : 138 : if (what)
12719 : : {
12720 : 133 : if (msg)
12721 : 47 : w = warning (OPT_Wdeprecated_declarations,
12722 : : "%qE is deprecated: %s", what, (const char *) msg);
12723 : : else
12724 : 86 : w = warning (OPT_Wdeprecated_declarations,
12725 : : "%qE is deprecated", what);
12726 : : }
12727 : : else
12728 : : {
12729 : 5 : if (msg)
12730 : 2 : w = warning (OPT_Wdeprecated_declarations,
12731 : : "type is deprecated: %s", (const char *) msg);
12732 : : else
12733 : 3 : w = warning (OPT_Wdeprecated_declarations,
12734 : : "type is deprecated");
12735 : : }
12736 : :
12737 : 138 : if (w && decl)
12738 : 111 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12739 : 138 : }
12740 : :
12741 : : return w;
12742 : 1285985 : }
12743 : :
12744 : : /* Error out with an identifier which was marked 'unavailable'. */
12745 : : void
12746 : 364 : error_unavailable_use (tree node, tree attr)
12747 : : {
12748 : 364 : escaped_string msg;
12749 : :
12750 : 364 : if (node == 0)
12751 : 0 : return;
12752 : :
12753 : 364 : if (!attr)
12754 : : {
12755 : 354 : if (DECL_P (node))
12756 : 294 : attr = DECL_ATTRIBUTES (node);
12757 : 60 : else if (TYPE_P (node))
12758 : : {
12759 : 60 : tree decl = TYPE_STUB_DECL (node);
12760 : 60 : if (decl)
12761 : 51 : attr = lookup_attribute ("unavailable",
12762 : 51 : TYPE_ATTRIBUTES (TREE_TYPE (decl)));
12763 : : }
12764 : : }
12765 : :
12766 : 354 : if (attr)
12767 : 152 : attr = lookup_attribute ("unavailable", attr);
12768 : :
12769 : 152 : if (attr)
12770 : 152 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12771 : :
12772 : 364 : if (DECL_P (node))
12773 : : {
12774 : 294 : auto_diagnostic_group d;
12775 : 294 : if (msg)
12776 : 117 : error ("%qD is unavailable: %s", node, (const char *) msg);
12777 : : else
12778 : 177 : error ("%qD is unavailable", node);
12779 : 294 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12780 : 294 : }
12781 : 70 : else if (TYPE_P (node))
12782 : : {
12783 : 70 : tree what = NULL_TREE;
12784 : 70 : tree decl = TYPE_STUB_DECL (node);
12785 : :
12786 : 70 : if (TYPE_NAME (node))
12787 : : {
12788 : 66 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12789 : 4 : what = TYPE_NAME (node);
12790 : 62 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12791 : 62 : && DECL_NAME (TYPE_NAME (node)))
12792 : 62 : what = DECL_NAME (TYPE_NAME (node));
12793 : : }
12794 : :
12795 : 70 : auto_diagnostic_group d;
12796 : 70 : if (what)
12797 : : {
12798 : 66 : if (msg)
12799 : 33 : error ("%qE is unavailable: %s", what, (const char *) msg);
12800 : : else
12801 : 33 : error ("%qE is unavailable", what);
12802 : : }
12803 : : else
12804 : : {
12805 : 4 : if (msg)
12806 : 2 : error ("type is unavailable: %s", (const char *) msg);
12807 : : else
12808 : 2 : error ("type is unavailable");
12809 : : }
12810 : :
12811 : 70 : if (decl)
12812 : 52 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12813 : 70 : }
12814 : 364 : }
12815 : :
12816 : : /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
12817 : : somewhere in it. */
12818 : :
12819 : : bool
12820 : 5659861 : contains_bitfld_component_ref_p (const_tree ref)
12821 : : {
12822 : 11562014 : while (handled_component_p (ref))
12823 : : {
12824 : 5927961 : if (TREE_CODE (ref) == COMPONENT_REF
12825 : 5927961 : && DECL_BIT_FIELD (TREE_OPERAND (ref, 1)))
12826 : : return true;
12827 : 5902153 : ref = TREE_OPERAND (ref, 0);
12828 : : }
12829 : :
12830 : : return false;
12831 : : }
12832 : :
12833 : : /* Try to determine whether a TRY_CATCH expression can fall through.
12834 : : This is a subroutine of block_may_fallthru. */
12835 : :
12836 : : static bool
12837 : 1 : try_catch_may_fallthru (const_tree stmt)
12838 : : {
12839 : 1 : tree_stmt_iterator i;
12840 : :
12841 : : /* If the TRY block can fall through, the whole TRY_CATCH can
12842 : : fall through. */
12843 : 1 : if (block_may_fallthru (TREE_OPERAND (stmt, 0)))
12844 : : return true;
12845 : :
12846 : 1 : switch (TREE_CODE (TREE_OPERAND (stmt, 1)))
12847 : : {
12848 : 0 : case CATCH_EXPR:
12849 : : /* See below. */
12850 : 0 : return block_may_fallthru (CATCH_BODY (TREE_OPERAND (stmt, 1)));
12851 : :
12852 : 0 : case EH_FILTER_EXPR:
12853 : : /* See below. */
12854 : 0 : return block_may_fallthru (EH_FILTER_FAILURE (TREE_OPERAND (stmt, 1)));
12855 : :
12856 : 0 : case STATEMENT_LIST:
12857 : 0 : break;
12858 : :
12859 : : default:
12860 : : /* See below. */
12861 : : return false;
12862 : : }
12863 : :
12864 : 0 : i = tsi_start (TREE_OPERAND (stmt, 1));
12865 : 0 : switch (TREE_CODE (tsi_stmt (i)))
12866 : : {
12867 : : case CATCH_EXPR:
12868 : : /* We expect to see a sequence of CATCH_EXPR trees, each with a
12869 : : catch expression and a body. The whole TRY_CATCH may fall
12870 : : through iff any of the catch bodies falls through. */
12871 : 0 : for (; !tsi_end_p (i); tsi_next (&i))
12872 : : {
12873 : 0 : if (block_may_fallthru (CATCH_BODY (tsi_stmt (i))))
12874 : : return true;
12875 : : }
12876 : : return false;
12877 : :
12878 : 0 : case EH_FILTER_EXPR:
12879 : : /* The exception filter expression only matters if there is an
12880 : : exception. If the exception does not match EH_FILTER_TYPES,
12881 : : we will execute EH_FILTER_FAILURE, and we will fall through
12882 : : if that falls through. If the exception does match
12883 : : EH_FILTER_TYPES, the stack unwinder will continue up the
12884 : : stack, so we will not fall through. We don't know whether we
12885 : : will throw an exception which matches EH_FILTER_TYPES or not,
12886 : : so we just ignore EH_FILTER_TYPES and assume that we might
12887 : : throw an exception which doesn't match. */
12888 : 0 : return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i)));
12889 : :
12890 : : default:
12891 : : /* This case represents statements to be executed when an
12892 : : exception occurs. Those statements are implicitly followed
12893 : : by a RESX statement to resume execution after the exception.
12894 : : So in this case the TRY_CATCH never falls through. */
12895 : : return false;
12896 : : }
12897 : : }
12898 : :
12899 : : /* Try to determine if we can fall out of the bottom of BLOCK. This guess
12900 : : need not be 100% accurate; simply be conservative and return true if we
12901 : : don't know. This is used only to avoid stupidly generating extra code.
12902 : : If we're wrong, we'll just delete the extra code later. */
12903 : :
12904 : : bool
12905 : 6403514 : block_may_fallthru (const_tree block)
12906 : : {
12907 : : /* This CONST_CAST is okay because expr_last returns its argument
12908 : : unmodified and we assign it to a const_tree. */
12909 : 7549173 : const_tree stmt = expr_last (CONST_CAST_TREE (block));
12910 : :
12911 : 7549173 : switch (stmt ? TREE_CODE (stmt) : ERROR_MARK)
12912 : : {
12913 : : case GOTO_EXPR:
12914 : : case RETURN_EXPR:
12915 : : /* Easy cases. If the last statement of the block implies
12916 : : control transfer, then we can't fall through. */
12917 : : return false;
12918 : :
12919 : 8 : case SWITCH_EXPR:
12920 : : /* If there is a default: label or case labels cover all possible
12921 : : SWITCH_COND values, then the SWITCH_EXPR will transfer control
12922 : : to some case label in all cases and all we care is whether the
12923 : : SWITCH_BODY falls through. */
12924 : 8 : if (SWITCH_ALL_CASES_P (stmt))
12925 : 7 : return block_may_fallthru (SWITCH_BODY (stmt));
12926 : : return true;
12927 : :
12928 : 19840 : case COND_EXPR:
12929 : 19840 : if (block_may_fallthru (COND_EXPR_THEN (stmt)))
12930 : : return true;
12931 : 2784 : return block_may_fallthru (COND_EXPR_ELSE (stmt));
12932 : :
12933 : 573082 : case BIND_EXPR:
12934 : 573082 : return block_may_fallthru (BIND_EXPR_BODY (stmt));
12935 : :
12936 : 1 : case TRY_CATCH_EXPR:
12937 : 1 : return try_catch_may_fallthru (stmt);
12938 : :
12939 : 141 : case TRY_FINALLY_EXPR:
12940 : : /* The finally clause is always executed after the try clause,
12941 : : so if it does not fall through, then the try-finally will not
12942 : : fall through. Otherwise, if the try clause does not fall
12943 : : through, then when the finally clause falls through it will
12944 : : resume execution wherever the try clause was going. So the
12945 : : whole try-finally will only fall through if both the try
12946 : : clause and the finally clause fall through. */
12947 : 141 : return (block_may_fallthru (TREE_OPERAND (stmt, 0))
12948 : 141 : && block_may_fallthru (TREE_OPERAND (stmt, 1)));
12949 : :
12950 : 0 : case EH_ELSE_EXPR:
12951 : 0 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
12952 : :
12953 : 89011 : case MODIFY_EXPR:
12954 : 89011 : if (TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR)
12955 : 1544 : stmt = TREE_OPERAND (stmt, 1);
12956 : : else
12957 : : return true;
12958 : : /* FALLTHRU */
12959 : :
12960 : 411449 : case CALL_EXPR:
12961 : : /* Functions that do not return do not fall through. */
12962 : 411449 : return (call_expr_flags (stmt) & ECF_NORETURN) == 0;
12963 : :
12964 : 569776 : case CLEANUP_POINT_EXPR:
12965 : 569776 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
12966 : :
12967 : 10 : case TARGET_EXPR:
12968 : 10 : return block_may_fallthru (TREE_OPERAND (stmt, 1));
12969 : :
12970 : : case ERROR_MARK:
12971 : : return true;
12972 : :
12973 : 4096304 : default:
12974 : 4096304 : return lang_hooks.block_may_fallthru (stmt);
12975 : : }
12976 : : }
12977 : :
12978 : : /* True if we are using EH to handle cleanups. */
12979 : : static bool using_eh_for_cleanups_flag = false;
12980 : :
12981 : : /* This routine is called from front ends to indicate eh should be used for
12982 : : cleanups. */
12983 : : void
12984 : 120302 : using_eh_for_cleanups (void)
12985 : : {
12986 : 120302 : using_eh_for_cleanups_flag = true;
12987 : 120302 : }
12988 : :
12989 : : /* Query whether EH is used for cleanups. */
12990 : : bool
12991 : 1651494 : using_eh_for_cleanups_p (void)
12992 : : {
12993 : 1651494 : return using_eh_for_cleanups_flag;
12994 : : }
12995 : :
12996 : : /* Wrapper for tree_code_name to ensure that tree code is valid */
12997 : : const char *
12998 : 14303749841 : get_tree_code_name (enum tree_code code)
12999 : : {
13000 : 14303749841 : const char *invalid = "<invalid tree code>";
13001 : :
13002 : : /* The tree_code enum promotes to signed, but we could be getting
13003 : : invalid values, so force an unsigned comparison. */
13004 : 14303749841 : if (unsigned (code) >= MAX_TREE_CODES)
13005 : : {
13006 : 0 : if ((unsigned)code == 0xa5a5)
13007 : : return "ggc_freed";
13008 : 0 : return invalid;
13009 : : }
13010 : :
13011 : 14303749841 : return tree_code_name[code];
13012 : : }
13013 : :
13014 : : /* Drops the TREE_OVERFLOW flag from T. */
13015 : :
13016 : : tree
13017 : 35446 : drop_tree_overflow (tree t)
13018 : : {
13019 : 35446 : gcc_checking_assert (TREE_OVERFLOW (t));
13020 : :
13021 : : /* For tree codes with a sharing machinery re-build the result. */
13022 : 35446 : if (poly_int_tree_p (t))
13023 : 35434 : return wide_int_to_tree (TREE_TYPE (t), wi::to_poly_wide (t));
13024 : :
13025 : : /* For VECTOR_CST, remove the overflow bits from the encoded elements
13026 : : and canonicalize the result. */
13027 : 12 : if (TREE_CODE (t) == VECTOR_CST)
13028 : : {
13029 : 0 : tree_vector_builder builder;
13030 : 0 : builder.new_unary_operation (TREE_TYPE (t), t, true);
13031 : 0 : unsigned int count = builder.encoded_nelts ();
13032 : 0 : for (unsigned int i = 0; i < count; ++i)
13033 : : {
13034 : 0 : tree elt = VECTOR_CST_ELT (t, i);
13035 : 0 : if (TREE_OVERFLOW (elt))
13036 : 0 : elt = drop_tree_overflow (elt);
13037 : 0 : builder.quick_push (elt);
13038 : : }
13039 : 0 : return builder.build ();
13040 : 0 : }
13041 : :
13042 : : /* Otherwise, as all tcc_constants are possibly shared, copy the node
13043 : : and drop the flag. */
13044 : 12 : t = copy_node (t);
13045 : 12 : TREE_OVERFLOW (t) = 0;
13046 : :
13047 : : /* For constants that contain nested constants, drop the flag
13048 : : from those as well. */
13049 : 12 : if (TREE_CODE (t) == COMPLEX_CST)
13050 : : {
13051 : 12 : if (TREE_OVERFLOW (TREE_REALPART (t)))
13052 : 12 : TREE_REALPART (t) = drop_tree_overflow (TREE_REALPART (t));
13053 : 12 : if (TREE_OVERFLOW (TREE_IMAGPART (t)))
13054 : 0 : TREE_IMAGPART (t) = drop_tree_overflow (TREE_IMAGPART (t));
13055 : : }
13056 : :
13057 : : return t;
13058 : : }
13059 : :
13060 : : /* Given a memory reference expression T, return its base address.
13061 : : The base address of a memory reference expression is the main
13062 : : object being referenced. For instance, the base address for
13063 : : 'array[i].fld[j]' is 'array'. You can think of this as stripping
13064 : : away the offset part from a memory address.
13065 : :
13066 : : This function calls handled_component_p to strip away all the inner
13067 : : parts of the memory reference until it reaches the base object. */
13068 : :
13069 : : tree
13070 : 3139531567 : get_base_address (tree t)
13071 : : {
13072 : 3139531567 : if (TREE_CODE (t) == WITH_SIZE_EXPR)
13073 : 893 : t = TREE_OPERAND (t, 0);
13074 : 3895578027 : while (handled_component_p (t))
13075 : 756046460 : t = TREE_OPERAND (t, 0);
13076 : :
13077 : 3139531567 : if ((TREE_CODE (t) == MEM_REF
13078 : 3139531567 : || TREE_CODE (t) == TARGET_MEM_REF)
13079 : 3139531567 : && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
13080 : 148613877 : t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
13081 : :
13082 : 3139531567 : return t;
13083 : : }
13084 : :
13085 : : /* Return a tree of sizetype representing the size, in bytes, of the element
13086 : : of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13087 : :
13088 : : tree
13089 : 788088938 : array_ref_element_size (tree exp)
13090 : : {
13091 : 788088938 : tree aligned_size = TREE_OPERAND (exp, 3);
13092 : 788088938 : tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
13093 : 788088938 : location_t loc = EXPR_LOCATION (exp);
13094 : :
13095 : : /* If a size was specified in the ARRAY_REF, it's the size measured
13096 : : in alignment units of the element type. So multiply by that value. */
13097 : 788088938 : if (aligned_size)
13098 : : {
13099 : : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13100 : : sizetype from another type of the same width and signedness. */
13101 : 388878 : if (TREE_TYPE (aligned_size) != sizetype)
13102 : 2026 : aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
13103 : 388878 : return size_binop_loc (loc, MULT_EXPR, aligned_size,
13104 : 388878 : size_int (TYPE_ALIGN_UNIT (elmt_type)));
13105 : : }
13106 : :
13107 : : /* Otherwise, take the size from that of the element type. Substitute
13108 : : any PLACEHOLDER_EXPR that we have. */
13109 : : else
13110 : 787700060 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
13111 : : }
13112 : :
13113 : : /* Return a tree representing the lower bound of the array mentioned in
13114 : : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13115 : :
13116 : : tree
13117 : 1085935234 : array_ref_low_bound (tree exp)
13118 : : {
13119 : 1085935234 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13120 : :
13121 : : /* If a lower bound is specified in EXP, use it. */
13122 : 1085935234 : if (TREE_OPERAND (exp, 2))
13123 : 1915012 : return TREE_OPERAND (exp, 2);
13124 : :
13125 : : /* Otherwise, if there is a domain type and it has a lower bound, use it,
13126 : : substituting for a PLACEHOLDER_EXPR as needed. */
13127 : 1084020222 : if (domain_type && TYPE_MIN_VALUE (domain_type))
13128 : 1083104061 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
13129 : :
13130 : : /* Otherwise, return a zero of the appropriate type. */
13131 : 916161 : tree idxtype = TREE_TYPE (TREE_OPERAND (exp, 1));
13132 : 916161 : return (idxtype == error_mark_node
13133 : 916161 : ? integer_zero_node : build_int_cst (idxtype, 0));
13134 : : }
13135 : :
13136 : : /* Return a tree representing the upper bound of the array mentioned in
13137 : : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13138 : :
13139 : : tree
13140 : 251709042 : array_ref_up_bound (tree exp)
13141 : : {
13142 : 251709042 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13143 : :
13144 : : /* If there is a domain type and it has an upper bound, use it, substituting
13145 : : for a PLACEHOLDER_EXPR as needed. */
13146 : 251709042 : if (domain_type && TYPE_MAX_VALUE (domain_type))
13147 : 250922988 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
13148 : :
13149 : : /* Otherwise fail. */
13150 : : return NULL_TREE;
13151 : : }
13152 : :
13153 : : /* Returns true if REF is an array reference, a component reference,
13154 : : or a memory reference to an array whose actual size might be larger
13155 : : than its upper bound implies, there are multiple cases:
13156 : : A. a ref to a flexible array member at the end of a structure;
13157 : : B. a ref to an array with a different type against the original decl;
13158 : : for example:
13159 : :
13160 : : short a[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
13161 : : (*((char(*)[16])&a[0]))[i+8]
13162 : :
13163 : : C. a ref to an array that was passed as a parameter;
13164 : : for example:
13165 : :
13166 : : int test (uint8_t *p, uint32_t t[1][1], int n) {
13167 : : for (int i = 0; i < 4; i++, p++)
13168 : : t[i][0] = ...;
13169 : :
13170 : : If non-null, set IS_TRAILING_ARRAY to true if the ref is the above case A.
13171 : : */
13172 : :
13173 : : bool
13174 : 77546224 : array_ref_flexible_size_p (tree ref, bool *is_trailing_array /* = NULL */)
13175 : : {
13176 : : /* The TYPE for this array referece. */
13177 : 77546224 : tree atype = NULL_TREE;
13178 : : /* The FIELD_DECL for the array field in the containing structure. */
13179 : 77546224 : tree afield_decl = NULL_TREE;
13180 : : /* Whether this array is the trailing array of a structure. */
13181 : 77546224 : bool is_trailing_array_tmp = false;
13182 : 77546224 : if (!is_trailing_array)
13183 : 77466338 : is_trailing_array = &is_trailing_array_tmp;
13184 : :
13185 : 77546224 : if (TREE_CODE (ref) == ARRAY_REF
13186 : 77546224 : || TREE_CODE (ref) == ARRAY_RANGE_REF)
13187 : : {
13188 : 77315221 : atype = TREE_TYPE (TREE_OPERAND (ref, 0));
13189 : 77315221 : ref = TREE_OPERAND (ref, 0);
13190 : : }
13191 : 231003 : else if (TREE_CODE (ref) == COMPONENT_REF
13192 : 231003 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 1))) == ARRAY_TYPE)
13193 : : {
13194 : 167142 : atype = TREE_TYPE (TREE_OPERAND (ref, 1));
13195 : 167142 : afield_decl = TREE_OPERAND (ref, 1);
13196 : : }
13197 : 63861 : else if (TREE_CODE (ref) == MEM_REF)
13198 : : {
13199 : 8317 : tree arg = TREE_OPERAND (ref, 0);
13200 : 8317 : if (TREE_CODE (arg) == ADDR_EXPR)
13201 : 8317 : arg = TREE_OPERAND (arg, 0);
13202 : 8317 : tree argtype = TREE_TYPE (arg);
13203 : 8317 : if (TREE_CODE (argtype) == RECORD_TYPE)
13204 : : {
13205 : 157 : if (tree fld = last_field (argtype))
13206 : : {
13207 : 157 : atype = TREE_TYPE (fld);
13208 : 157 : afield_decl = fld;
13209 : 157 : if (TREE_CODE (atype) != ARRAY_TYPE)
13210 : : return false;
13211 : 157 : if (VAR_P (arg) && DECL_SIZE (fld))
13212 : : return false;
13213 : : }
13214 : : else
13215 : : return false;
13216 : : }
13217 : : else
13218 : : return false;
13219 : : }
13220 : : else
13221 : : return false;
13222 : :
13223 : 77482476 : if (TREE_CODE (ref) == STRING_CST)
13224 : : return false;
13225 : :
13226 : : tree ref_to_array = ref;
13227 : 94256243 : while (handled_component_p (ref))
13228 : : {
13229 : : /* If the reference chain contains a component reference to a
13230 : : non-union type and there follows another field the reference
13231 : : is not at the end of a structure. */
13232 : 19835600 : if (TREE_CODE (ref) == COMPONENT_REF)
13233 : : {
13234 : 18720147 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
13235 : : {
13236 : 17479160 : tree nextf = DECL_CHAIN (TREE_OPERAND (ref, 1));
13237 : 26789370 : while (nextf && TREE_CODE (nextf) != FIELD_DECL)
13238 : 9310210 : nextf = DECL_CHAIN (nextf);
13239 : : if (nextf)
13240 : : return false;
13241 : : }
13242 : : }
13243 : : /* If we have a multi-dimensional array we do not consider
13244 : : a non-innermost dimension as flex array if the whole
13245 : : multi-dimensional array is at struct end.
13246 : : Same for an array of aggregates with a trailing array
13247 : : member. */
13248 : 1115453 : else if (TREE_CODE (ref) == ARRAY_REF)
13249 : : return false;
13250 : 181640 : else if (TREE_CODE (ref) == ARRAY_RANGE_REF)
13251 : : ;
13252 : : /* If we view an underlying object as sth else then what we
13253 : : gathered up to now is what we have to rely on. */
13254 : 181630 : else if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
13255 : : break;
13256 : : else
13257 : 0 : gcc_unreachable ();
13258 : :
13259 : 16775230 : ref = TREE_OPERAND (ref, 0);
13260 : : }
13261 : :
13262 : 74602273 : gcc_assert (!afield_decl
13263 : : || (afield_decl && TREE_CODE (afield_decl) == FIELD_DECL));
13264 : :
13265 : : /* The array now is at struct end. Treat flexible array member as
13266 : : always subject to extend, even into just padding constrained by
13267 : : an underlying decl. */
13268 : 74602273 : if (! TYPE_SIZE (atype)
13269 : 72314303 : || ! TYPE_DOMAIN (atype)
13270 : 146916576 : || ! TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13271 : : {
13272 : 2293567 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13273 : 2375388 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13274 : : }
13275 : :
13276 : : /* If the reference is based on a declared entity, the size of the array
13277 : : is constrained by its given domain. (Do not trust commons PR/69368). */
13278 : 72308706 : ref = get_base_address (ref);
13279 : 72308706 : if (ref
13280 : 72308706 : && DECL_P (ref)
13281 : 62366336 : && !(flag_unconstrained_commons
13282 : 14 : && VAR_P (ref) && DECL_COMMON (ref))
13283 : 62366322 : && DECL_SIZE_UNIT (ref)
13284 : 134674651 : && TREE_CODE (DECL_SIZE_UNIT (ref)) == INTEGER_CST)
13285 : : {
13286 : : /* If the object itself is the array it is not at struct end. */
13287 : 62365917 : if (DECL_P (ref_to_array))
13288 : : return false;
13289 : :
13290 : : /* Check whether the array domain covers all of the available
13291 : : padding. */
13292 : 15805864 : poly_int64 offset;
13293 : 15805864 : if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
13294 : 15804504 : || TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST
13295 : 31587557 : || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST)
13296 : : {
13297 : 24171 : *is_trailing_array
13298 : 24171 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13299 : 24214 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13300 : : }
13301 : 15781693 : if (! get_addr_base_and_unit_offset (ref_to_array, &offset))
13302 : : {
13303 : 2743 : *is_trailing_array
13304 : 2743 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13305 : 2743 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13306 : : }
13307 : :
13308 : : /* If at least one extra element fits it is a flexarray. */
13309 : 15778950 : if (known_le ((wi::to_offset (TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13310 : : - wi::to_offset (TYPE_MIN_VALUE (TYPE_DOMAIN (atype)))
13311 : : + 2)
13312 : : * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (atype))),
13313 : : wi::to_offset (DECL_SIZE_UNIT (ref)) - offset))
13314 : : {
13315 : 561374 : *is_trailing_array
13316 : 561374 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13317 : 573567 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13318 : : }
13319 : :
13320 : : return false;
13321 : : }
13322 : :
13323 : 9942789 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13324 : 9957254 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13325 : : }
13326 : :
13327 : :
13328 : : /* Return a tree representing the offset, in bytes, of the field referenced
13329 : : by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
13330 : :
13331 : : tree
13332 : 2648061239 : component_ref_field_offset (tree exp)
13333 : : {
13334 : 2648061239 : tree aligned_offset = TREE_OPERAND (exp, 2);
13335 : 2648061239 : tree field = TREE_OPERAND (exp, 1);
13336 : 2648061239 : location_t loc = EXPR_LOCATION (exp);
13337 : :
13338 : : /* If an offset was specified in the COMPONENT_REF, it's the offset measured
13339 : : in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
13340 : : value. */
13341 : 2648061239 : if (aligned_offset)
13342 : : {
13343 : : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13344 : : sizetype from another type of the same width and signedness. */
13345 : 12005 : if (TREE_TYPE (aligned_offset) != sizetype)
13346 : 135 : aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
13347 : 12005 : return size_binop_loc (loc, MULT_EXPR, aligned_offset,
13348 : 12005 : size_int (DECL_OFFSET_ALIGN (field)
13349 : : / BITS_PER_UNIT));
13350 : : }
13351 : :
13352 : : /* Otherwise, take the offset from that of the field. Substitute
13353 : : any PLACEHOLDER_EXPR that we have. */
13354 : : else
13355 : 2648049234 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
13356 : : }
13357 : :
13358 : : /* Given the initializer INIT, return the initializer for the field
13359 : : DECL if it exists, otherwise null. Used to obtain the initializer
13360 : : for a flexible array member and determine its size. */
13361 : :
13362 : : static tree
13363 : 1267 : get_initializer_for (tree init, tree decl)
13364 : : {
13365 : 1267 : STRIP_NOPS (init);
13366 : :
13367 : 1267 : tree fld, fld_init;
13368 : 1267 : unsigned HOST_WIDE_INT i;
13369 : 3571 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), i, fld, fld_init)
13370 : : {
13371 : 1926 : if (decl == fld)
13372 : : return fld_init;
13373 : :
13374 : 1037 : if (TREE_CODE (fld) == CONSTRUCTOR)
13375 : : {
13376 : 0 : fld_init = get_initializer_for (fld_init, decl);
13377 : 0 : if (fld_init)
13378 : : return fld_init;
13379 : : }
13380 : : }
13381 : :
13382 : : return NULL_TREE;
13383 : : }
13384 : :
13385 : : /* Determines the special array member type for the array reference REF. */
13386 : : special_array_member
13387 : 252612 : component_ref_sam_type (tree ref)
13388 : : {
13389 : 252612 : special_array_member sam_type = special_array_member::none;
13390 : :
13391 : 252612 : tree member = TREE_OPERAND (ref, 1);
13392 : 252612 : tree memsize = DECL_SIZE_UNIT (member);
13393 : 252612 : if (memsize)
13394 : : {
13395 : 120658 : tree memtype = TREE_TYPE (member);
13396 : 120658 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13397 : 120537 : return sam_type;
13398 : :
13399 : 79886 : bool trailing = false;
13400 : 79886 : (void) array_ref_flexible_size_p (ref, &trailing);
13401 : 79886 : bool zero_elts = integer_zerop (memsize);
13402 : 79886 : if (zero_elts && integer_zerop (TYPE_SIZE_UNIT (TREE_TYPE (memtype))))
13403 : : {
13404 : : /* If array element has zero size, verify if it is a flexible
13405 : : array member or zero length array. Clear zero_elts if
13406 : : it has one or more members or is a VLA member. */
13407 : 7 : if (tree dom = TYPE_DOMAIN (memtype))
13408 : 7 : if (tree min = TYPE_MIN_VALUE (dom))
13409 : 7 : if (tree max = TYPE_MAX_VALUE (dom))
13410 : 5 : if (TREE_CODE (min) != INTEGER_CST
13411 : 5 : || TREE_CODE (max) != INTEGER_CST
13412 : 15 : || !((integer_zerop (min) && integer_all_onesp (max))
13413 : 5 : || tree_int_cst_lt (max, min)))
13414 : : zero_elts = false;
13415 : : }
13416 : 79886 : if (!trailing && !zero_elts)
13417 : : /* MEMBER is an interior array with more than one element. */
13418 : : return special_array_member::int_n;
13419 : :
13420 : 23420 : if (zero_elts)
13421 : : {
13422 : 1075 : if (trailing)
13423 : : return special_array_member::trail_0;
13424 : : else
13425 : 463 : return special_array_member::int_0;
13426 : : }
13427 : :
13428 : 22808 : if (!zero_elts)
13429 : 22808 : if (tree dom = TYPE_DOMAIN (memtype))
13430 : 22808 : if (tree min = TYPE_MIN_VALUE (dom))
13431 : 22808 : if (tree max = TYPE_MAX_VALUE (dom))
13432 : 22808 : if (TREE_CODE (min) == INTEGER_CST
13433 : 22808 : && TREE_CODE (max) == INTEGER_CST)
13434 : : {
13435 : 22687 : offset_int minidx = wi::to_offset (min);
13436 : 22687 : offset_int maxidx = wi::to_offset (max);
13437 : 22687 : offset_int neltsm1 = maxidx - minidx;
13438 : 22687 : if (neltsm1 > 0)
13439 : : /* MEMBER is a trailing array with more than
13440 : : one elements. */
13441 : 22687 : return special_array_member::trail_n;
13442 : :
13443 : 1966 : if (neltsm1 == 0)
13444 : : return special_array_member::trail_1;
13445 : : }
13446 : : }
13447 : :
13448 : : return sam_type;
13449 : : }
13450 : :
13451 : : /* Determines the size of the member referenced by the COMPONENT_REF
13452 : : REF, using its initializer expression if necessary in order to
13453 : : determine the size of an initialized flexible array member.
13454 : : If non-null, set *SAM to the type of special array member.
13455 : : Returns the size as sizetype (which might be zero for an object
13456 : : with an uninitialized flexible array member) or null if the size
13457 : : cannot be determined. */
13458 : :
13459 : : tree
13460 : 153616 : component_ref_size (tree ref, special_array_member *sam /* = NULL */)
13461 : : {
13462 : 153616 : gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
13463 : :
13464 : 153616 : special_array_member sambuf;
13465 : 153616 : if (!sam)
13466 : 97928 : sam = &sambuf;
13467 : 153616 : *sam = component_ref_sam_type (ref);
13468 : :
13469 : : /* The object/argument referenced by the COMPONENT_REF and its type. */
13470 : 153616 : tree arg = TREE_OPERAND (ref, 0);
13471 : 153616 : tree argtype = TREE_TYPE (arg);
13472 : : /* The referenced member. */
13473 : 153616 : tree member = TREE_OPERAND (ref, 1);
13474 : :
13475 : 153616 : tree memsize = DECL_SIZE_UNIT (member);
13476 : 153616 : if (memsize)
13477 : : {
13478 : 86119 : tree memtype = TREE_TYPE (member);
13479 : 86119 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13480 : : /* DECL_SIZE may be less than TYPE_SIZE in C++ when referring
13481 : : to the type of a class with a virtual base which doesn't
13482 : : reflect the size of the virtual's members (see pr97595).
13483 : : If that's the case fail for now and implement something
13484 : : more robust in the future. */
13485 : 40772 : return (tree_int_cst_equal (memsize, TYPE_SIZE_UNIT (memtype))
13486 : 40772 : ? memsize : NULL_TREE);
13487 : :
13488 : : /* 2-or-more elements arrays are treated as normal arrays by default. */
13489 : 45347 : if (*sam == special_array_member::int_n
13490 : 45347 : || *sam == special_array_member::trail_n)
13491 : : return memsize;
13492 : :
13493 : 1742 : tree afield_decl = TREE_OPERAND (ref, 1);
13494 : 1742 : gcc_assert (TREE_CODE (afield_decl) == FIELD_DECL);
13495 : : /* If the trailing array is a not a flexible array member, treat it as
13496 : : a normal array. */
13497 : 1742 : if (DECL_NOT_FLEXARRAY (afield_decl)
13498 : 1742 : && *sam != special_array_member::int_0)
13499 : : return memsize;
13500 : :
13501 : 1733 : if (*sam == special_array_member::int_0)
13502 : 270 : memsize = NULL_TREE;
13503 : :
13504 : : /* For a reference to a flexible array member of a union
13505 : : use the size of the union instead of the size of the member. */
13506 : 1733 : if (TREE_CODE (argtype) == UNION_TYPE)
13507 : 277 : memsize = TYPE_SIZE_UNIT (argtype);
13508 : : }
13509 : :
13510 : : /* MEMBER is either a bona fide flexible array member, or a zero-elements
13511 : : array member, or an array of length one treated as such. */
13512 : :
13513 : : /* If the reference is to a declared object and the member a true
13514 : : flexible array, try to determine its size from its initializer. */
13515 : 69230 : poly_int64 baseoff = 0;
13516 : 69230 : tree base = get_addr_base_and_unit_offset (ref, &baseoff);
13517 : 69230 : if (!base || !VAR_P (base))
13518 : : {
13519 : 66025 : if (*sam != special_array_member::int_0)
13520 : : return NULL_TREE;
13521 : :
13522 : 52 : if (TREE_CODE (arg) != COMPONENT_REF)
13523 : : return NULL_TREE;
13524 : :
13525 : : base = arg;
13526 : 6 : while (TREE_CODE (base) == COMPONENT_REF)
13527 : 3 : base = TREE_OPERAND (base, 0);
13528 : 3 : baseoff = tree_to_poly_int64 (byte_position (TREE_OPERAND (ref, 1)));
13529 : : }
13530 : :
13531 : : /* BASE is the declared object of which MEMBER is either a member
13532 : : or that is cast to ARGTYPE (e.g., a char buffer used to store
13533 : : an ARGTYPE object). */
13534 : 3208 : tree basetype = TREE_TYPE (base);
13535 : :
13536 : : /* Determine the base type of the referenced object. If it's
13537 : : the same as ARGTYPE and MEMBER has a known size, return it. */
13538 : 3208 : tree bt = basetype;
13539 : 3208 : if (*sam != special_array_member::int_0)
13540 : 3209 : while (TREE_CODE (bt) == ARRAY_TYPE)
13541 : 222 : bt = TREE_TYPE (bt);
13542 : 3208 : bool typematch = useless_type_conversion_p (argtype, bt);
13543 : 3208 : if (memsize && typematch)
13544 : : return memsize;
13545 : :
13546 : 3118 : memsize = NULL_TREE;
13547 : :
13548 : 3118 : if (typematch)
13549 : : /* MEMBER is a true flexible array member. Compute its size from
13550 : : the initializer of the BASE object if it has one. */
13551 : 2656 : if (tree init = DECL_P (base) ? DECL_INITIAL (base) : NULL_TREE)
13552 : 1300 : if (init != error_mark_node)
13553 : : {
13554 : 1267 : init = get_initializer_for (init, member);
13555 : 1267 : if (init)
13556 : : {
13557 : 889 : memsize = TYPE_SIZE_UNIT (TREE_TYPE (init));
13558 : 889 : if (tree refsize = TYPE_SIZE_UNIT (argtype))
13559 : : {
13560 : : /* Use the larger of the initializer size and the tail
13561 : : padding in the enclosing struct. */
13562 : 889 : poly_int64 rsz = tree_to_poly_int64 (refsize);
13563 : 889 : rsz -= baseoff;
13564 : 889 : if (known_lt (tree_to_poly_int64 (memsize), rsz))
13565 : 56 : memsize = wide_int_to_tree (TREE_TYPE (memsize), rsz);
13566 : : }
13567 : :
13568 : 889 : baseoff = 0;
13569 : : }
13570 : : }
13571 : :
13572 : 889 : if (!memsize)
13573 : : {
13574 : 2229 : if (typematch)
13575 : : {
13576 : 1767 : if (DECL_P (base)
13577 : 1767 : && DECL_EXTERNAL (base)
13578 : 454 : && bt == basetype
13579 : 2215 : && *sam != special_array_member::int_0)
13580 : : /* The size of a flexible array member of an extern struct
13581 : : with no initializer cannot be determined (it's defined
13582 : : in another translation unit and can have an initializer
13583 : : with an arbitrary number of elements). */
13584 : : return NULL_TREE;
13585 : :
13586 : : /* Use the size of the base struct or, for interior zero-length
13587 : : arrays, the size of the enclosing type. */
13588 : 1342 : memsize = TYPE_SIZE_UNIT (bt);
13589 : : }
13590 : 462 : else if (DECL_P (base))
13591 : : /* Use the size of the BASE object (possibly an array of some
13592 : : other type such as char used to store the struct). */
13593 : 459 : memsize = DECL_SIZE_UNIT (base);
13594 : : else
13595 : : return NULL_TREE;
13596 : : }
13597 : :
13598 : : /* If the flexible array member has a known size use the greater
13599 : : of it and the tail padding in the enclosing struct.
13600 : : Otherwise, when the size of the flexible array member is unknown
13601 : : and the referenced object is not a struct, use the size of its
13602 : : type when known. This detects sizes of array buffers when cast
13603 : : to struct types with flexible array members. */
13604 : 1801 : if (memsize)
13605 : : {
13606 : 2665 : if (!tree_fits_poly_int64_p (memsize))
13607 : : return NULL_TREE;
13608 : 2665 : poly_int64 memsz64 = memsize ? tree_to_poly_int64 (memsize) : 0;
13609 : 2665 : if (known_lt (baseoff, memsz64))
13610 : : {
13611 : 1239 : memsz64 -= baseoff;
13612 : 1239 : return wide_int_to_tree (TREE_TYPE (memsize), memsz64);
13613 : : }
13614 : 1426 : return size_zero_node;
13615 : : }
13616 : :
13617 : : /* Return "don't know" for an external non-array object since its
13618 : : flexible array member can be initialized to have any number of
13619 : : elements. Otherwise, return zero because the flexible array
13620 : : member has no elements. */
13621 : 25 : return (DECL_P (base)
13622 : 25 : && DECL_EXTERNAL (base)
13623 : 25 : && (!typematch
13624 : 0 : || TREE_CODE (basetype) != ARRAY_TYPE)
13625 : 25 : ? NULL_TREE : size_zero_node);
13626 : : }
13627 : :
13628 : : /* Return true if the given node CALL is a call to a .ACCESS_WITH_SIZE
13629 : : function. */
13630 : : bool
13631 : 57666020 : is_access_with_size_p (const_tree call)
13632 : : {
13633 : 57666020 : if (TREE_CODE (call) != CALL_EXPR)
13634 : : return false;
13635 : 6994661 : if (CALL_EXPR_IFN (call) == IFN_ACCESS_WITH_SIZE)
13636 : 353 : return true;
13637 : : return false;
13638 : : }
13639 : :
13640 : : /* Get the corresponding reference from the call to a .ACCESS_WITH_SIZE.
13641 : : * i.e the first argument of this call. Return NULL_TREE otherwise. */
13642 : : tree
13643 : 2 : get_ref_from_access_with_size (tree call)
13644 : : {
13645 : 2 : if (is_access_with_size_p (call))
13646 : 2 : return CALL_EXPR_ARG (call, 0);
13647 : : return NULL_TREE;
13648 : : }
13649 : :
13650 : : /* Return the machine mode of T. For vectors, returns the mode of the
13651 : : inner type. The main use case is to feed the result to HONOR_NANS,
13652 : : avoiding the BLKmode that a direct TYPE_MODE (T) might return. */
13653 : :
13654 : : machine_mode
13655 : 5138755534 : element_mode (const_tree t)
13656 : : {
13657 : 5138755534 : if (!TYPE_P (t))
13658 : 202512566 : t = TREE_TYPE (t);
13659 : 5138755534 : if (VECTOR_TYPE_P (t) || TREE_CODE (t) == COMPLEX_TYPE)
13660 : 1476716525 : t = TREE_TYPE (t);
13661 : 5138755534 : return TYPE_MODE (t);
13662 : : }
13663 : :
13664 : : /* Vector types need to re-check the target flags each time we report
13665 : : the machine mode. We need to do this because attribute target can
13666 : : change the result of vector_mode_supported_p and have_regs_of_mode
13667 : : on a per-function basis. Thus the TYPE_MODE of a VECTOR_TYPE can
13668 : : change on a per-function basis. */
13669 : : /* ??? Possibly a better solution is to run through all the types
13670 : : referenced by a function and re-compute the TYPE_MODE once, rather
13671 : : than make the TYPE_MODE macro call a function. */
13672 : :
13673 : : machine_mode
13674 : 1327624142 : vector_type_mode (const_tree t)
13675 : : {
13676 : 1327624142 : machine_mode mode;
13677 : :
13678 : 1327624142 : gcc_assert (TREE_CODE (t) == VECTOR_TYPE);
13679 : :
13680 : 1327624142 : mode = t->type_common.mode;
13681 : 298966508 : if (VECTOR_MODE_P (mode)
13682 : 1589280472 : && (!targetm.vector_mode_supported_p (mode)
13683 : 1271731995 : || !have_regs_of_mode[mode]))
13684 : : {
13685 : 19483544 : scalar_int_mode innermode;
13686 : :
13687 : : /* For integers, try mapping it to a same-sized scalar mode. */
13688 : 19483544 : if (is_int_mode (TREE_TYPE (t)->type_common.mode, &innermode))
13689 : : {
13690 : 27226616 : poly_int64 size = (TYPE_VECTOR_SUBPARTS (t)
13691 : 13613308 : * GET_MODE_BITSIZE (innermode));
13692 : 13613308 : scalar_int_mode mode;
13693 : 27092605 : if (int_mode_for_size (size, 0).exists (&mode)
13694 : 13533027 : && have_regs_of_mode[mode])
13695 : 53730 : return mode;
13696 : : }
13697 : :
13698 : 19429814 : return BLKmode;
13699 : : }
13700 : :
13701 : : return mode;
13702 : : }
13703 : :
13704 : : /* Return the size in bits of each element of vector type TYPE. */
13705 : :
13706 : : unsigned int
13707 : 213738 : vector_element_bits (const_tree type)
13708 : : {
13709 : 213738 : gcc_checking_assert (VECTOR_TYPE_P (type));
13710 : 213738 : if (VECTOR_BOOLEAN_TYPE_P (type))
13711 : 1026 : return TYPE_PRECISION (TREE_TYPE (type));
13712 : 212712 : return tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)));
13713 : : }
13714 : :
13715 : : /* Calculate the size in bits of each element of vector type TYPE
13716 : : and return the result as a tree of type bitsizetype. */
13717 : :
13718 : : tree
13719 : 111694 : vector_element_bits_tree (const_tree type)
13720 : : {
13721 : 111694 : gcc_checking_assert (VECTOR_TYPE_P (type));
13722 : 111694 : if (VECTOR_BOOLEAN_TYPE_P (type))
13723 : 610 : return bitsize_int (vector_element_bits (type));
13724 : 111084 : return TYPE_SIZE (TREE_TYPE (type));
13725 : : }
13726 : :
13727 : : /* Verify that basic properties of T match TV and thus T can be a variant of
13728 : : TV. TV should be the more specified variant (i.e. the main variant). */
13729 : :
13730 : : static bool
13731 : 147484964 : verify_type_variant (const_tree t, tree tv)
13732 : : {
13733 : : /* Type variant can differ by:
13734 : :
13735 : : - TYPE_QUALS: TYPE_READONLY, TYPE_VOLATILE, TYPE_ATOMIC, TYPE_RESTRICT,
13736 : : ENCODE_QUAL_ADDR_SPACE.
13737 : : - main variant may be TYPE_COMPLETE_P and variant types !TYPE_COMPLETE_P
13738 : : in this case some values may not be set in the variant types
13739 : : (see TYPE_COMPLETE_P checks).
13740 : : - it is possible to have TYPE_ARTIFICIAL variant of non-artifical type
13741 : : - by TYPE_NAME and attributes (i.e. when variant originate by typedef)
13742 : : - TYPE_CANONICAL (TYPE_ALIAS_SET is the same among variants)
13743 : : - by the alignment: TYPE_ALIGN and TYPE_USER_ALIGN
13744 : : - during LTO by TYPE_CONTEXT if type is TYPE_FILE_SCOPE_P
13745 : : this is necessary to make it possible to merge types form different TUs
13746 : : - arrays, pointers and references may have TREE_TYPE that is a variant
13747 : : of TREE_TYPE of their main variants.
13748 : : - aggregates may have new TYPE_FIELDS list that list variants of
13749 : : the main variant TYPE_FIELDS.
13750 : : - vector types may differ by TYPE_VECTOR_OPAQUE
13751 : : */
13752 : :
13753 : : /* Convenience macro for matching individual fields. */
13754 : : #define verify_variant_match(flag) \
13755 : : do { \
13756 : : if (flag (tv) != flag (t)) \
13757 : : { \
13758 : : error ("type variant differs by %s", #flag); \
13759 : : debug_tree (tv); \
13760 : : return false; \
13761 : : } \
13762 : : } while (false)
13763 : :
13764 : : /* tree_base checks. */
13765 : :
13766 : 147484964 : verify_variant_match (TREE_CODE);
13767 : : /* FIXME: Ada builds non-artificial variants of artificial types. */
13768 : : #if 0
13769 : : if (TYPE_ARTIFICIAL (tv))
13770 : : verify_variant_match (TYPE_ARTIFICIAL);
13771 : : #endif
13772 : 147484964 : if (POINTER_TYPE_P (tv))
13773 : 11213684 : verify_variant_match (TYPE_REF_CAN_ALIAS_ALL);
13774 : : /* FIXME: TYPE_SIZES_GIMPLIFIED may differs for Ada build. */
13775 : 147484964 : verify_variant_match (TYPE_UNSIGNED);
13776 : 147484964 : verify_variant_match (TYPE_PACKED);
13777 : 147484964 : if (TREE_CODE (t) == REFERENCE_TYPE)
13778 : 2955842 : verify_variant_match (TYPE_REF_IS_RVALUE);
13779 : 147484964 : if (AGGREGATE_TYPE_P (t))
13780 : 62619883 : verify_variant_match (TYPE_REVERSE_STORAGE_ORDER);
13781 : : else
13782 : 84865081 : verify_variant_match (TYPE_SATURATING);
13783 : : /* FIXME: This check trigger during libstdc++ build. */
13784 : : #if 0
13785 : : if (RECORD_OR_UNION_TYPE_P (t) && COMPLETE_TYPE_P (t))
13786 : : verify_variant_match (TYPE_FINAL_P);
13787 : : #endif
13788 : :
13789 : : /* tree_type_common checks. */
13790 : :
13791 : 147484964 : if (COMPLETE_TYPE_P (t))
13792 : : {
13793 : 137156645 : verify_variant_match (TYPE_MODE);
13794 : 137156645 : if (TREE_CODE (TYPE_SIZE (t)) != PLACEHOLDER_EXPR
13795 : 137156645 : && TREE_CODE (TYPE_SIZE (tv)) != PLACEHOLDER_EXPR)
13796 : 137156645 : verify_variant_match (TYPE_SIZE);
13797 : 137156645 : if (TREE_CODE (TYPE_SIZE_UNIT (t)) != PLACEHOLDER_EXPR
13798 : 137156645 : && TREE_CODE (TYPE_SIZE_UNIT (tv)) != PLACEHOLDER_EXPR
13799 : 274313290 : && TYPE_SIZE_UNIT (t) != TYPE_SIZE_UNIT (tv))
13800 : : {
13801 : 0 : gcc_assert (!operand_equal_p (TYPE_SIZE_UNIT (t),
13802 : : TYPE_SIZE_UNIT (tv), 0));
13803 : 0 : error ("type variant has different %<TYPE_SIZE_UNIT%>");
13804 : 0 : debug_tree (tv);
13805 : 0 : error ("type variant%'s %<TYPE_SIZE_UNIT%>");
13806 : 0 : debug_tree (TYPE_SIZE_UNIT (tv));
13807 : 0 : error ("type%'s %<TYPE_SIZE_UNIT%>");
13808 : 0 : debug_tree (TYPE_SIZE_UNIT (t));
13809 : 0 : return false;
13810 : : }
13811 : 137156645 : verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
13812 : : }
13813 : 147484964 : verify_variant_match (TYPE_PRECISION_RAW);
13814 : 147484964 : if (RECORD_OR_UNION_TYPE_P (t))
13815 : 62100445 : verify_variant_match (TYPE_TRANSPARENT_AGGR);
13816 : 85384519 : else if (TREE_CODE (t) == ARRAY_TYPE)
13817 : 519438 : verify_variant_match (TYPE_NONALIASED_COMPONENT);
13818 : : /* During LTO we merge variant lists from diferent translation units
13819 : : that may differ BY TYPE_CONTEXT that in turn may point
13820 : : to TRANSLATION_UNIT_DECL.
13821 : : Ada also builds variants of types with different TYPE_CONTEXT. */
13822 : : #if 0
13823 : : if (!in_lto_p || !TYPE_FILE_SCOPE_P (t))
13824 : : verify_variant_match (TYPE_CONTEXT);
13825 : : #endif
13826 : 147484964 : if (TREE_CODE (t) == ARRAY_TYPE || TREE_CODE (t) == INTEGER_TYPE)
13827 : 51090885 : verify_variant_match (TYPE_STRING_FLAG);
13828 : 147484964 : if (TREE_CODE (t) == RECORD_TYPE || TREE_CODE (t) == UNION_TYPE)
13829 : 62100445 : verify_variant_match (TYPE_CXX_ODR_P);
13830 : 147484964 : if (TYPE_ALIAS_SET_KNOWN_P (t))
13831 : : {
13832 : 0 : error ("type variant with %<TYPE_ALIAS_SET_KNOWN_P%>");
13833 : 0 : debug_tree (tv);
13834 : 0 : return false;
13835 : : }
13836 : :
13837 : : /* tree_type_non_common checks. */
13838 : :
13839 : : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
13840 : : and dangle the pointer from time to time. */
13841 : 62100445 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_VFIELD (t) != TYPE_VFIELD (tv)
13842 : 147484964 : && (in_lto_p || !TYPE_VFIELD (tv)
13843 : 0 : || TREE_CODE (TYPE_VFIELD (tv)) != TREE_LIST))
13844 : : {
13845 : 0 : error ("type variant has different %<TYPE_VFIELD%>");
13846 : 0 : debug_tree (tv);
13847 : 0 : return false;
13848 : : }
13849 : 2447495 : if ((TREE_CODE (t) == ENUMERAL_TYPE && COMPLETE_TYPE_P (t))
13850 : 145037524 : || TREE_CODE (t) == INTEGER_TYPE
13851 : 94466077 : || TREE_CODE (t) == BOOLEAN_TYPE
13852 : 75493200 : || TREE_CODE (t) == BITINT_TYPE
13853 : 75493052 : || SCALAR_FLOAT_TYPE_P (t)
13854 : 221982216 : || FIXED_POINT_TYPE_P (t))
13855 : : {
13856 : 72987712 : verify_variant_match (TYPE_MAX_VALUE);
13857 : 72987712 : verify_variant_match (TYPE_MIN_VALUE);
13858 : : }
13859 : 147484964 : if (TREE_CODE (t) == METHOD_TYPE)
13860 : 11188 : verify_variant_match (TYPE_METHOD_BASETYPE);
13861 : 147484964 : if (TREE_CODE (t) == OFFSET_TYPE)
13862 : 165 : verify_variant_match (TYPE_OFFSET_BASETYPE);
13863 : 147484964 : if (TREE_CODE (t) == ARRAY_TYPE)
13864 : 519438 : verify_variant_match (TYPE_ARRAY_MAX_SIZE);
13865 : : /* FIXME: Be lax and allow TYPE_BINFO to be missing in variant types
13866 : : or even type's main variant. This is needed to make bootstrap pass
13867 : : and the bug seems new in GCC 5.
13868 : : C++ FE should be updated to make this consistent and we should check
13869 : : that TYPE_BINFO is always NULL for !COMPLETE_TYPE_P and otherwise there
13870 : : is a match with main variant.
13871 : :
13872 : : Also disable the check for Java for now because of parser hack that builds
13873 : : first an dummy BINFO and then sometimes replace it by real BINFO in some
13874 : : of the copies. */
13875 : 62100445 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t) && TYPE_BINFO (tv)
13876 : 51577305 : && TYPE_BINFO (t) != TYPE_BINFO (tv)
13877 : : /* FIXME: Java sometimes keep dump TYPE_BINFOs on variant types.
13878 : : Since there is no cheap way to tell C++/Java type w/o LTO, do checking
13879 : : at LTO time only. */
13880 : 147484964 : && (in_lto_p && odr_type_p (t)))
13881 : : {
13882 : 0 : error ("type variant has different %<TYPE_BINFO%>");
13883 : 0 : debug_tree (tv);
13884 : 0 : error ("type variant%'s %<TYPE_BINFO%>");
13885 : 0 : debug_tree (TYPE_BINFO (tv));
13886 : 0 : error ("type%'s %<TYPE_BINFO%>");
13887 : 0 : debug_tree (TYPE_BINFO (t));
13888 : 0 : return false;
13889 : : }
13890 : :
13891 : : /* Check various uses of TYPE_VALUES_RAW. */
13892 : 147484964 : if (TREE_CODE (t) == ENUMERAL_TYPE
13893 : 147484964 : && TYPE_VALUES (t))
13894 : 2401610 : verify_variant_match (TYPE_VALUES);
13895 : 145083354 : else if (TREE_CODE (t) == ARRAY_TYPE)
13896 : 519438 : verify_variant_match (TYPE_DOMAIN);
13897 : : /* Permit incomplete variants of complete type. While FEs may complete
13898 : : all variants, this does not happen for C++ templates in all cases. */
13899 : 144563916 : else if (RECORD_OR_UNION_TYPE_P (t)
13900 : 62100445 : && COMPLETE_TYPE_P (t)
13901 : 196533950 : && TYPE_FIELDS (t) != TYPE_FIELDS (tv))
13902 : : {
13903 : 3661 : tree f1, f2;
13904 : :
13905 : : /* Fortran builds qualified variants as new records with items of
13906 : : qualified type. Verify that they looks same. */
13907 : 3661 : for (f1 = TYPE_FIELDS (t), f2 = TYPE_FIELDS (tv);
13908 : 11921 : f1 && f2;
13909 : 8260 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
13910 : 8260 : if (TREE_CODE (f1) != FIELD_DECL || TREE_CODE (f2) != FIELD_DECL
13911 : 8260 : || (TYPE_MAIN_VARIANT (TREE_TYPE (f1))
13912 : 8260 : != TYPE_MAIN_VARIANT (TREE_TYPE (f2))
13913 : : /* FIXME: gfc_nonrestricted_type builds all types as variants
13914 : : with exception of pointer types. It deeply copies the type
13915 : : which means that we may end up with a variant type
13916 : : referring non-variant pointer. We may change it to
13917 : : produce types as variants, too, like
13918 : : objc_get_protocol_qualified_type does. */
13919 : 21 : && !POINTER_TYPE_P (TREE_TYPE (f1)))
13920 : 8260 : || DECL_FIELD_OFFSET (f1) != DECL_FIELD_OFFSET (f2)
13921 : 16520 : || DECL_FIELD_BIT_OFFSET (f1) != DECL_FIELD_BIT_OFFSET (f2))
13922 : : break;
13923 : 3661 : if (f1 || f2)
13924 : : {
13925 : 0 : error ("type variant has different %<TYPE_FIELDS%>");
13926 : 0 : debug_tree (tv);
13927 : 0 : error ("first mismatch is field");
13928 : 0 : debug_tree (f1);
13929 : 0 : error ("and field");
13930 : 0 : debug_tree (f2);
13931 : 0 : return false;
13932 : : }
13933 : : }
13934 : 144560255 : else if (FUNC_OR_METHOD_TYPE_P (t))
13935 : 135075 : verify_variant_match (TYPE_ARG_TYPES);
13936 : : /* For C++ the qualified variant of array type is really an array type
13937 : : of qualified TREE_TYPE.
13938 : : objc builds variants of pointer where pointer to type is a variant, too
13939 : : in objc_get_protocol_qualified_type. */
13940 : 147484964 : if (TREE_TYPE (t) != TREE_TYPE (tv)
13941 : 147484964 : && ((TREE_CODE (t) != ARRAY_TYPE
13942 : 0 : && !POINTER_TYPE_P (t))
13943 : 446882 : || TYPE_MAIN_VARIANT (TREE_TYPE (t))
13944 : 446882 : != TYPE_MAIN_VARIANT (TREE_TYPE (tv))))
13945 : : {
13946 : 0 : error ("type variant has different %<TREE_TYPE%>");
13947 : 0 : debug_tree (tv);
13948 : 0 : error ("type variant%'s %<TREE_TYPE%>");
13949 : 0 : debug_tree (TREE_TYPE (tv));
13950 : 0 : error ("type%'s %<TREE_TYPE%>");
13951 : 0 : debug_tree (TREE_TYPE (t));
13952 : 0 : return false;
13953 : : }
13954 : 147484964 : if (type_with_alias_set_p (t)
13955 : 147484964 : && !gimple_canonical_types_compatible_p (t, tv, false))
13956 : : {
13957 : 0 : error ("type is not compatible with its variant");
13958 : 0 : debug_tree (tv);
13959 : 0 : error ("type variant%'s %<TREE_TYPE%>");
13960 : 0 : debug_tree (TREE_TYPE (tv));
13961 : 0 : error ("type%'s %<TREE_TYPE%>");
13962 : 0 : debug_tree (TREE_TYPE (t));
13963 : 0 : return false;
13964 : : }
13965 : : return true;
13966 : : #undef verify_variant_match
13967 : : }
13968 : :
13969 : :
13970 : : /* The TYPE_CANONICAL merging machinery. It should closely resemble
13971 : : the middle-end types_compatible_p function. It needs to avoid
13972 : : claiming types are different for types that should be treated
13973 : : the same with respect to TBAA. Canonical types are also used
13974 : : for IL consistency checks via the useless_type_conversion_p
13975 : : predicate which does not handle all type kinds itself but falls
13976 : : back to pointer-comparison of TYPE_CANONICAL for aggregates
13977 : : for example. */
13978 : :
13979 : : /* Return true if TYPE_UNSIGNED of TYPE should be ignored for canonical
13980 : : type calculation because we need to allow inter-operability between signed
13981 : : and unsigned variants. */
13982 : :
13983 : : bool
13984 : 1815875 : type_with_interoperable_signedness (const_tree type)
13985 : : {
13986 : : /* Fortran standard require C_SIGNED_CHAR to be interoperable with both
13987 : : signed char and unsigned char. Similarly fortran FE builds
13988 : : C_SIZE_T as signed type, while C defines it unsigned. */
13989 : :
13990 : 1815875 : return tree_code_for_canonical_type_merging (TREE_CODE (type))
13991 : : == INTEGER_TYPE
13992 : 1815674 : && (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node)
13993 : 486923 : || TYPE_PRECISION (type) == TYPE_PRECISION (size_type_node));
13994 : : }
13995 : :
13996 : : /* Return true iff T1 and T2 are structurally identical for what
13997 : : TBAA is concerned.
13998 : : This function is used both by lto.cc canonical type merging and by the
13999 : : verifier. If TRUST_TYPE_CANONICAL we do not look into structure of types
14000 : : that have TYPE_CANONICAL defined and assume them equivalent. This is useful
14001 : : only for LTO because only in these cases TYPE_CANONICAL equivalence
14002 : : correspond to one defined by gimple_canonical_types_compatible_p. */
14003 : :
14004 : : bool
14005 : 316262013 : gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
14006 : : bool trust_type_canonical)
14007 : : {
14008 : : /* Type variants should be same as the main variant. When not doing sanity
14009 : : checking to verify this fact, go to main variants and save some work. */
14010 : 316262013 : if (trust_type_canonical)
14011 : : {
14012 : 972350 : t1 = TYPE_MAIN_VARIANT (t1);
14013 : 972350 : t2 = TYPE_MAIN_VARIANT (t2);
14014 : : }
14015 : :
14016 : : /* Check first for the obvious case of pointer identity. */
14017 : 316262013 : if (t1 == t2)
14018 : : return true;
14019 : :
14020 : : /* Check that we have two types to compare. */
14021 : 263419988 : if (t1 == NULL_TREE || t2 == NULL_TREE)
14022 : : return false;
14023 : :
14024 : : /* We consider complete types always compatible with incomplete type.
14025 : : This does not make sense for canonical type calculation and thus we
14026 : : need to ensure that we are never called on it.
14027 : :
14028 : : FIXME: For more correctness the function probably should have three modes
14029 : : 1) mode assuming that types are complete mathcing their structure
14030 : : 2) mode allowing incomplete types but producing equivalence classes
14031 : : and thus ignoring all info from complete types
14032 : : 3) mode allowing incomplete types to match complete but checking
14033 : : compatibility between complete types.
14034 : :
14035 : : 1 and 2 can be used for canonical type calculation. 3 is the real
14036 : : definition of type compatibility that can be used i.e. for warnings during
14037 : : declaration merging. */
14038 : :
14039 : 263419988 : gcc_assert (!trust_type_canonical
14040 : : || (type_with_alias_set_p (t1) && type_with_alias_set_p (t2)));
14041 : :
14042 : : /* If the types have been previously registered and found equal
14043 : : they still are. */
14044 : :
14045 : 526606259 : if (TYPE_CANONICAL (t1) && TYPE_CANONICAL (t2)
14046 : 525727696 : && trust_type_canonical)
14047 : : {
14048 : : /* Do not use TYPE_CANONICAL of pointer types. For LTO streamed types
14049 : : they are always NULL, but they are set to non-NULL for types
14050 : : constructed by build_pointer_type and variants. In this case the
14051 : : TYPE_CANONICAL is more fine grained than the equivalnce we test (where
14052 : : all pointers are considered equal. Be sure to not return false
14053 : : negatives. */
14054 : 180588 : gcc_checking_assert (canonical_type_used_p (t1)
14055 : : && canonical_type_used_p (t2));
14056 : 90294 : return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
14057 : : }
14058 : :
14059 : : /* For types where we do ODR based TBAA the canonical type is always
14060 : : set correctly, so we know that types are different if their
14061 : : canonical types does not match. */
14062 : 263329694 : if (trust_type_canonical
14063 : 264208757 : && (odr_type_p (t1) && odr_based_tbaa_p (t1))
14064 : 879063 : != (odr_type_p (t2) && odr_based_tbaa_p (t2)))
14065 : : return false;
14066 : :
14067 : : /* Can't be the same type if the types don't have the same code. */
14068 : 263329694 : enum tree_code code = tree_code_for_canonical_type_merging (TREE_CODE (t1));
14069 : 523715018 : if (code != tree_code_for_canonical_type_merging (TREE_CODE (t2)))
14070 : : return false;
14071 : :
14072 : : /* Qualifiers do not matter for canonical type comparison purposes. */
14073 : :
14074 : : /* Void types and nullptr types are always the same. */
14075 : 263329659 : if (VOID_TYPE_P (t1)
14076 : 263290884 : || TREE_CODE (t1) == NULLPTR_TYPE)
14077 : : return true;
14078 : :
14079 : : /* Can't be compatible types if they have different mode. Because of
14080 : : flexible array members, we allow mismatching modes for structures or
14081 : : unions. */
14082 : 262728092 : if (!RECORD_OR_UNION_TYPE_P (t1)
14083 : 262728092 : && TREE_CODE (t1) != ARRAY_TYPE
14084 : 262728092 : && TYPE_MODE (t1) != TYPE_MODE (t2))
14085 : : return false;
14086 : :
14087 : : /* Non-aggregate types can be handled cheaply. */
14088 : 262728092 : if (INTEGRAL_TYPE_P (t1)
14089 : 262728092 : || SCALAR_FLOAT_TYPE_P (t1)
14090 : 142490425 : || FIXED_POINT_TYPE_P (t1)
14091 : 142084579 : || VECTOR_TYPE_P (t1)
14092 : 142060512 : || TREE_CODE (t1) == COMPLEX_TYPE
14093 : 141698831 : || TREE_CODE (t1) == OFFSET_TYPE
14094 : 141698120 : || POINTER_TYPE_P (t1))
14095 : : {
14096 : : /* Can't be the same type if they have different precision. */
14097 : 157238329 : if (TYPE_PRECISION_RAW (t1) != TYPE_PRECISION_RAW (t2))
14098 : : return false;
14099 : :
14100 : : /* In some cases the signed and unsigned types are required to be
14101 : : inter-operable. */
14102 : 157238329 : if (TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)
14103 : 157238329 : && !type_with_interoperable_signedness (t1))
14104 : : return false;
14105 : :
14106 : : /* Fortran's C_SIGNED_CHAR is !TYPE_STRING_FLAG but needs to be
14107 : : interoperable with "signed char". Unless all frontends are revisited
14108 : : to agree on these types, we must ignore the flag completely. */
14109 : :
14110 : : /* Fortran standard define C_PTR type that is compatible with every
14111 : : C pointer. For this reason we need to glob all pointers into one.
14112 : : Still pointers in different address spaces are not compatible. */
14113 : 157238329 : if (POINTER_TYPE_P (t1))
14114 : : {
14115 : 36208357 : if (TYPE_ADDR_SPACE (TREE_TYPE (t1))
14116 : 36208357 : != TYPE_ADDR_SPACE (TREE_TYPE (t2)))
14117 : : return false;
14118 : : }
14119 : :
14120 : : /* Tail-recurse to components. */
14121 : 157238329 : if (VECTOR_TYPE_P (t1)
14122 : 157238329 : || TREE_CODE (t1) == COMPLEX_TYPE)
14123 : 385748 : return gimple_canonical_types_compatible_p (TREE_TYPE (t1),
14124 : 385748 : TREE_TYPE (t2),
14125 : 385748 : trust_type_canonical);
14126 : :
14127 : : return true;
14128 : : }
14129 : :
14130 : : /* Do type-specific comparisons. */
14131 : 105489763 : switch (TREE_CODE (t1))
14132 : : {
14133 : 961451 : case ARRAY_TYPE:
14134 : : /* Array types are the same if the element types are the same and
14135 : : minimum and maximum index are the same. */
14136 : 961451 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14137 : : trust_type_canonical)
14138 : 961416 : || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
14139 : 961416 : || TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2)
14140 : 1922867 : || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
14141 : : return false;
14142 : : else
14143 : : {
14144 : 961416 : tree i1 = TYPE_DOMAIN (t1);
14145 : 961416 : tree i2 = TYPE_DOMAIN (t2);
14146 : :
14147 : : /* For an incomplete external array, the type domain can be
14148 : : NULL_TREE. Check this condition also. */
14149 : 961416 : if (i1 == NULL_TREE && i2 == NULL_TREE)
14150 : : return true;
14151 : 861542 : else if (i1 == NULL_TREE || i2 == NULL_TREE)
14152 : : return false;
14153 : : else
14154 : : {
14155 : 861542 : tree min1 = TYPE_MIN_VALUE (i1);
14156 : 861542 : tree min2 = TYPE_MIN_VALUE (i2);
14157 : 861542 : tree max1 = TYPE_MAX_VALUE (i1);
14158 : 861542 : tree max2 = TYPE_MAX_VALUE (i2);
14159 : :
14160 : : /* The minimum/maximum values have to be the same. */
14161 : 861542 : if ((min1 == min2
14162 : 0 : || (min1 && min2
14163 : 0 : && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
14164 : 0 : && TREE_CODE (min2) == PLACEHOLDER_EXPR)
14165 : 0 : || operand_equal_p (min1, min2, 0))))
14166 : 861542 : && (max1 == max2
14167 : 0 : || (max1 && max2
14168 : 0 : && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
14169 : 0 : && TREE_CODE (max2) == PLACEHOLDER_EXPR)
14170 : 0 : || operand_equal_p (max1, max2, 0)))))
14171 : 861542 : return true;
14172 : : else
14173 : 0 : return false;
14174 : : }
14175 : : }
14176 : :
14177 : 6649 : case METHOD_TYPE:
14178 : 6649 : case FUNCTION_TYPE:
14179 : : /* Function types are the same if the return type and arguments types
14180 : : are the same. */
14181 : 6649 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14182 : : trust_type_canonical))
14183 : : return false;
14184 : :
14185 : 6649 : if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2)
14186 : 6649 : && (TYPE_NO_NAMED_ARGS_STDARG_P (t1)
14187 : 322 : == TYPE_NO_NAMED_ARGS_STDARG_P (t2)))
14188 : : return true;
14189 : : else
14190 : : {
14191 : 6327 : tree parms1, parms2;
14192 : :
14193 : 6327 : for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
14194 : 27789 : parms1 && parms2;
14195 : 21462 : parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
14196 : : {
14197 : 21462 : if (!gimple_canonical_types_compatible_p
14198 : 21462 : (TREE_VALUE (parms1), TREE_VALUE (parms2),
14199 : : trust_type_canonical))
14200 : : return false;
14201 : : }
14202 : :
14203 : 6327 : if (parms1 || parms2)
14204 : : return false;
14205 : :
14206 : : return true;
14207 : : }
14208 : :
14209 : 104158482 : case RECORD_TYPE:
14210 : 104158482 : case UNION_TYPE:
14211 : 104158482 : case QUAL_UNION_TYPE:
14212 : 104158482 : {
14213 : 104158482 : tree f1, f2;
14214 : :
14215 : : /* Don't try to compare variants of an incomplete type, before
14216 : : TYPE_FIELDS has been copied around. */
14217 : 104158482 : if (!COMPLETE_TYPE_P (t1) && !COMPLETE_TYPE_P (t2))
14218 : : return true;
14219 : :
14220 : :
14221 : 94634988 : if (TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2))
14222 : : return false;
14223 : :
14224 : : /* For aggregate types, all the fields must be the same. */
14225 : 94634988 : for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
14226 : 147038187 : f1 || f2;
14227 : 52403199 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
14228 : : {
14229 : : /* Skip non-fields and zero-sized fields, except zero-sized
14230 : : arrays at the end. */
14231 : 1539527161 : while (f1 && (TREE_CODE (f1) != FIELD_DECL
14232 : 96300702 : || (DECL_SIZE (f1)
14233 : 96286097 : && integer_zerop (DECL_SIZE (f1))
14234 : 43897480 : && (TREE_CHAIN (f1)
14235 : 2906 : || TREE_CODE (TREE_TYPE (f1))
14236 : : != ARRAY_TYPE))))
14237 : 1393533888 : f1 = TREE_CHAIN (f1);
14238 : 1539528640 : while (f2 && (TREE_CODE (f2) != FIELD_DECL
14239 : 96314676 : || (DECL_SIZE (f2)
14240 : 96300051 : && integer_zerop (DECL_SIZE (f2))
14241 : 43898964 : && (TREE_CHAIN (f2)
14242 : 3904 : || TREE_CODE (TREE_TYPE (f2))
14243 : : != ARRAY_TYPE))))
14244 : 1393535367 : f2 = TREE_CHAIN (f2);
14245 : 145993273 : if (!f1 || !f2)
14246 : : break;
14247 : :
14248 : 52403426 : tree t1 = TREE_TYPE (f1);
14249 : 52403426 : tree t2 = TREE_TYPE (f2);
14250 : :
14251 : : /* If the last element are arrays, we only compare the element
14252 : : types. */
14253 : 53438487 : if (TREE_CHAIN (f1) == NULL_TREE && TREE_CODE (t1) == ARRAY_TYPE
14254 : 52470207 : && TREE_CHAIN (f2) == NULL_TREE && TREE_CODE (t2) == ARRAY_TYPE)
14255 : : {
14256 : : /* If both arrays have zero size, this is a match. */
14257 : 119365 : if (DECL_SIZE (f1) && integer_zerop (DECL_SIZE (f1))
14258 : 66980 : && DECL_SIZE (f2) && integer_zerop (DECL_SIZE (f2)))
14259 : : return true;
14260 : :
14261 : 66573 : t1 = TREE_TYPE (t1);
14262 : 66573 : t2 = TREE_TYPE (t2);
14263 : : }
14264 : :
14265 : 52403223 : if (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
14266 : 52403218 : || !gimple_compare_field_offset (f1, f2)
14267 : 104806441 : || !gimple_canonical_types_compatible_p
14268 : 52403218 : (t1, t2, trust_type_canonical))
14269 : 24 : return false;
14270 : : }
14271 : :
14272 : : /* If one aggregate has more fields than the other, they
14273 : : are not the same. */
14274 : 94634761 : if (f1 || f2)
14275 : : return false;
14276 : :
14277 : : return true;
14278 : : }
14279 : :
14280 : 363181 : default:
14281 : : /* Consider all types with language specific trees in them mutually
14282 : : compatible. This is executed only from verify_type and false
14283 : : positives can be tolerated. */
14284 : 363181 : gcc_assert (!in_lto_p);
14285 : : return true;
14286 : : }
14287 : : }
14288 : :
14289 : : /* For OPAQUE_TYPE T, it should have only size and alignment information
14290 : : and its mode should be of class MODE_OPAQUE. This function verifies
14291 : : these properties of T match TV which is the main variant of T and TC
14292 : : which is the canonical of T. */
14293 : :
14294 : : static void
14295 : 0 : verify_opaque_type (const_tree t, tree tv, tree tc)
14296 : : {
14297 : 0 : gcc_assert (OPAQUE_TYPE_P (t));
14298 : 0 : gcc_assert (tv && tv == TYPE_MAIN_VARIANT (tv));
14299 : 0 : gcc_assert (tc && tc == TYPE_CANONICAL (tc));
14300 : :
14301 : : /* For an opaque type T1, check if some of its properties match
14302 : : the corresponding ones of the other opaque type T2, emit some
14303 : : error messages for those inconsistent ones. */
14304 : 0 : auto check_properties_for_opaque_type = [](const_tree t1, tree t2,
14305 : : const char *kind_msg)
14306 : : {
14307 : 0 : if (!OPAQUE_TYPE_P (t2))
14308 : : {
14309 : 0 : error ("type %s is not an opaque type", kind_msg);
14310 : 0 : debug_tree (t2);
14311 : 0 : return;
14312 : : }
14313 : 0 : if (!OPAQUE_MODE_P (TYPE_MODE (t2)))
14314 : : {
14315 : 0 : error ("type %s is not with opaque mode", kind_msg);
14316 : 0 : debug_tree (t2);
14317 : 0 : return;
14318 : : }
14319 : 0 : if (TYPE_MODE (t1) != TYPE_MODE (t2))
14320 : : {
14321 : 0 : error ("type %s differs by %<TYPE_MODE%>", kind_msg);
14322 : 0 : debug_tree (t2);
14323 : 0 : return;
14324 : : }
14325 : 0 : poly_uint64 t1_size = tree_to_poly_uint64 (TYPE_SIZE (t1));
14326 : 0 : poly_uint64 t2_size = tree_to_poly_uint64 (TYPE_SIZE (t2));
14327 : 0 : if (maybe_ne (t1_size, t2_size))
14328 : : {
14329 : 0 : error ("type %s differs by %<TYPE_SIZE%>", kind_msg);
14330 : 0 : debug_tree (t2);
14331 : 0 : return;
14332 : : }
14333 : 0 : if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2))
14334 : : {
14335 : 0 : error ("type %s differs by %<TYPE_ALIGN%>", kind_msg);
14336 : 0 : debug_tree (t2);
14337 : 0 : return;
14338 : : }
14339 : 0 : if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
14340 : : {
14341 : 0 : error ("type %s differs by %<TYPE_USER_ALIGN%>", kind_msg);
14342 : 0 : debug_tree (t2);
14343 : 0 : return;
14344 : : }
14345 : : };
14346 : :
14347 : 0 : if (t != tv)
14348 : 0 : check_properties_for_opaque_type (t, tv, "variant");
14349 : :
14350 : 0 : if (t != tc)
14351 : 0 : check_properties_for_opaque_type (t, tc, "canonical");
14352 : 0 : }
14353 : :
14354 : : /* Verify type T. */
14355 : :
14356 : : void
14357 : 728161431 : verify_type (const_tree t)
14358 : : {
14359 : 728161431 : bool error_found = false;
14360 : 728161431 : tree mv = TYPE_MAIN_VARIANT (t);
14361 : 728161431 : tree ct = TYPE_CANONICAL (t);
14362 : :
14363 : 728161431 : if (OPAQUE_TYPE_P (t))
14364 : : {
14365 : 0 : verify_opaque_type (t, mv, ct);
14366 : 0 : return;
14367 : : }
14368 : :
14369 : 728161431 : if (!mv)
14370 : : {
14371 : 0 : error ("main variant is not defined");
14372 : 0 : error_found = true;
14373 : : }
14374 : 728161431 : else if (mv != TYPE_MAIN_VARIANT (mv))
14375 : : {
14376 : 0 : error ("%<TYPE_MAIN_VARIANT%> has different %<TYPE_MAIN_VARIANT%>");
14377 : 0 : debug_tree (mv);
14378 : 0 : error_found = true;
14379 : : }
14380 : 728161431 : else if (t != mv && !verify_type_variant (t, mv))
14381 : : error_found = true;
14382 : :
14383 : 728161431 : if (!ct)
14384 : : ;
14385 : 726163145 : else if (TYPE_CANONICAL (ct) != ct)
14386 : : {
14387 : 0 : error ("%<TYPE_CANONICAL%> has different %<TYPE_CANONICAL%>");
14388 : 0 : debug_tree (ct);
14389 : 0 : error_found = true;
14390 : : }
14391 : : /* Method and function types cannot be used to address memory and thus
14392 : : TYPE_CANONICAL really matters only for determining useless conversions.
14393 : :
14394 : : FIXME: C++ FE produce declarations of builtin functions that are not
14395 : : compatible with main variants. */
14396 : 726163145 : else if (TREE_CODE (t) == FUNCTION_TYPE)
14397 : : ;
14398 : 725560117 : else if (t != ct
14399 : : /* FIXME: gimple_canonical_types_compatible_p cannot compare types
14400 : : with variably sized arrays because their sizes possibly
14401 : : gimplified to different variables. */
14402 : 124491456 : && !variably_modified_type_p (ct, NULL)
14403 : 124487172 : && !gimple_canonical_types_compatible_p (t, ct, false)
14404 : 725572612 : && COMPLETE_TYPE_P (t))
14405 : : {
14406 : 0 : error ("%<TYPE_CANONICAL%> is not compatible");
14407 : 0 : debug_tree (ct);
14408 : 0 : error_found = true;
14409 : : }
14410 : 1309978181 : if (COMPLETE_TYPE_P (t) && TYPE_CANONICAL (t)
14411 : : /* We allow a mismatch for structure or union because of
14412 : : flexible array members. */
14413 : 579884968 : && !RECORD_OR_UNION_TYPE_P (t)
14414 : 241145039 : && !RECORD_OR_UNION_TYPE_P (TYPE_CANONICAL (t))
14415 : 241145039 : && TREE_CODE (t) != ARRAY_TYPE
14416 : 967951564 : && TYPE_MODE (t) != TYPE_MODE (TYPE_CANONICAL (t)))
14417 : : {
14418 : 0 : error ("%<TYPE_MODE%> of %<TYPE_CANONICAL%> is not compatible");
14419 : 0 : debug_tree (ct);
14420 : 0 : error_found = true;
14421 : : }
14422 : 728161431 : if (TYPE_MAIN_VARIANT (t) == t && ct && TYPE_MAIN_VARIANT (ct) != ct)
14423 : : {
14424 : 0 : error ("%<TYPE_CANONICAL%> of main variant is not main variant");
14425 : 0 : debug_tree (ct);
14426 : 0 : debug_tree (TYPE_MAIN_VARIANT (ct));
14427 : 0 : error_found = true;
14428 : : }
14429 : :
14430 : :
14431 : : /* Check various uses of TYPE_MIN_VALUE_RAW. */
14432 : 728161431 : if (RECORD_OR_UNION_TYPE_P (t))
14433 : : {
14434 : : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
14435 : : and danagle the pointer from time to time. */
14436 : 379242810 : if (TYPE_VFIELD (t)
14437 : 10607409 : && TREE_CODE (TYPE_VFIELD (t)) != FIELD_DECL
14438 : 379242810 : && TREE_CODE (TYPE_VFIELD (t)) != TREE_LIST)
14439 : : {
14440 : 0 : error ("%<TYPE_VFIELD%> is not %<FIELD_DECL%> nor %<TREE_LIST%>");
14441 : 0 : debug_tree (TYPE_VFIELD (t));
14442 : 0 : error_found = true;
14443 : : }
14444 : : }
14445 : 348918621 : else if (TREE_CODE (t) == POINTER_TYPE)
14446 : : {
14447 : 92759819 : if (TYPE_NEXT_PTR_TO (t)
14448 : 92759819 : && TREE_CODE (TYPE_NEXT_PTR_TO (t)) != POINTER_TYPE)
14449 : : {
14450 : 0 : error ("%<TYPE_NEXT_PTR_TO%> is not %<POINTER_TYPE%>");
14451 : 0 : debug_tree (TYPE_NEXT_PTR_TO (t));
14452 : 0 : error_found = true;
14453 : : }
14454 : : }
14455 : 256158802 : else if (TREE_CODE (t) == REFERENCE_TYPE)
14456 : : {
14457 : 42838733 : if (TYPE_NEXT_REF_TO (t)
14458 : 42838733 : && TREE_CODE (TYPE_NEXT_REF_TO (t)) != REFERENCE_TYPE)
14459 : : {
14460 : 0 : error ("%<TYPE_NEXT_REF_TO%> is not %<REFERENCE_TYPE%>");
14461 : 0 : debug_tree (TYPE_NEXT_REF_TO (t));
14462 : 0 : error_found = true;
14463 : : }
14464 : : }
14465 : : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14466 : : || FIXED_POINT_TYPE_P (t))
14467 : : {
14468 : : /* FIXME: The following check should pass:
14469 : : useless_type_conversion_p (const_cast <tree> (t),
14470 : : TREE_TYPE (TYPE_MIN_VALUE (t))
14471 : : but does not for C sizetypes in LTO. */
14472 : : }
14473 : :
14474 : : /* Check various uses of TYPE_MAXVAL_RAW. */
14475 : 728161431 : if (RECORD_OR_UNION_TYPE_P (t))
14476 : : {
14477 : 379242810 : if (!TYPE_BINFO (t))
14478 : : ;
14479 : 354429231 : else if (TREE_CODE (TYPE_BINFO (t)) != TREE_BINFO)
14480 : : {
14481 : 0 : error ("%<TYPE_BINFO%> is not %<TREE_BINFO%>");
14482 : 0 : debug_tree (TYPE_BINFO (t));
14483 : 0 : error_found = true;
14484 : : }
14485 : 354429231 : else if (TREE_TYPE (TYPE_BINFO (t)) != TYPE_MAIN_VARIANT (t))
14486 : : {
14487 : 0 : error ("%<TYPE_BINFO%> type is not %<TYPE_MAIN_VARIANT%>");
14488 : 0 : debug_tree (TREE_TYPE (TYPE_BINFO (t)));
14489 : 0 : error_found = true;
14490 : : }
14491 : : }
14492 : : else if (FUNC_OR_METHOD_TYPE_P (t))
14493 : : {
14494 : 821361 : if (TYPE_METHOD_BASETYPE (t)
14495 : 68983 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != RECORD_TYPE
14496 : 821549 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != UNION_TYPE)
14497 : : {
14498 : 0 : error ("%<TYPE_METHOD_BASETYPE%> is not record nor union");
14499 : 0 : debug_tree (TYPE_METHOD_BASETYPE (t));
14500 : 0 : error_found = true;
14501 : : }
14502 : : }
14503 : : else if (TREE_CODE (t) == OFFSET_TYPE)
14504 : : {
14505 : 35652 : if (TYPE_OFFSET_BASETYPE (t)
14506 : 35652 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != RECORD_TYPE
14507 : 35660 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != UNION_TYPE)
14508 : : {
14509 : 0 : error ("%<TYPE_OFFSET_BASETYPE%> is not record nor union");
14510 : 0 : debug_tree (TYPE_OFFSET_BASETYPE (t));
14511 : 0 : error_found = true;
14512 : : }
14513 : : }
14514 : : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14515 : : || FIXED_POINT_TYPE_P (t))
14516 : : {
14517 : : /* FIXME: The following check should pass:
14518 : : useless_type_conversion_p (const_cast <tree> (t),
14519 : : TREE_TYPE (TYPE_MAX_VALUE (t))
14520 : : but does not for C sizetypes in LTO. */
14521 : : }
14522 : : else if (TREE_CODE (t) == ARRAY_TYPE)
14523 : : {
14524 : 1599810 : if (TYPE_ARRAY_MAX_SIZE (t)
14525 : 1599810 : && TREE_CODE (TYPE_ARRAY_MAX_SIZE (t)) != INTEGER_CST)
14526 : : {
14527 : 0 : error ("%<TYPE_ARRAY_MAX_SIZE%> not %<INTEGER_CST%>");
14528 : 0 : debug_tree (TYPE_ARRAY_MAX_SIZE (t));
14529 : 0 : error_found = true;
14530 : : }
14531 : : }
14532 : 242649018 : else if (TYPE_MAX_VALUE_RAW (t))
14533 : : {
14534 : 0 : error ("%<TYPE_MAX_VALUE_RAW%> non-NULL");
14535 : 0 : debug_tree (TYPE_MAX_VALUE_RAW (t));
14536 : 0 : error_found = true;
14537 : : }
14538 : :
14539 : 728161431 : if (TYPE_LANG_SLOT_1 (t) && in_lto_p)
14540 : : {
14541 : 0 : error ("%<TYPE_LANG_SLOT_1 (binfo)%> field is non-NULL");
14542 : 0 : debug_tree (TYPE_LANG_SLOT_1 (t));
14543 : 0 : error_found = true;
14544 : : }
14545 : :
14546 : : /* Check various uses of TYPE_VALUES_RAW. */
14547 : 728161431 : if (TREE_CODE (t) == ENUMERAL_TYPE)
14548 : 86185220 : for (tree l = TYPE_VALUES (t); l; l = TREE_CHAIN (l))
14549 : : {
14550 : 75527156 : tree value = TREE_VALUE (l);
14551 : 75527156 : tree name = TREE_PURPOSE (l);
14552 : :
14553 : : /* C FE porduce INTEGER_CST of INTEGER_TYPE, while C++ FE uses
14554 : : CONST_DECL of ENUMERAL TYPE. */
14555 : 75527156 : if (TREE_CODE (value) != INTEGER_CST && TREE_CODE (value) != CONST_DECL)
14556 : : {
14557 : 0 : error ("enum value is not %<CONST_DECL%> or %<INTEGER_CST%>");
14558 : 0 : debug_tree (value);
14559 : 0 : debug_tree (name);
14560 : 0 : error_found = true;
14561 : : }
14562 : 75527156 : if (TREE_CODE (TREE_TYPE (value)) != INTEGER_TYPE
14563 : 75510204 : && TREE_CODE (TREE_TYPE (value)) != BOOLEAN_TYPE
14564 : 151037357 : && !useless_type_conversion_p (const_cast <tree> (t), TREE_TYPE (value)))
14565 : : {
14566 : 0 : error ("enum value type is not %<INTEGER_TYPE%> nor convertible "
14567 : : "to the enum");
14568 : 0 : debug_tree (value);
14569 : 0 : debug_tree (name);
14570 : 0 : error_found = true;
14571 : : }
14572 : 75527156 : if (TREE_CODE (name) != IDENTIFIER_NODE)
14573 : : {
14574 : 0 : error ("enum value name is not %<IDENTIFIER_NODE%>");
14575 : 0 : debug_tree (value);
14576 : 0 : debug_tree (name);
14577 : 0 : error_found = true;
14578 : : }
14579 : : }
14580 : 717503367 : else if (TREE_CODE (t) == ARRAY_TYPE)
14581 : : {
14582 : 1599810 : if (TYPE_DOMAIN (t) && TREE_CODE (TYPE_DOMAIN (t)) != INTEGER_TYPE)
14583 : : {
14584 : 0 : error ("array %<TYPE_DOMAIN%> is not integer type");
14585 : 0 : debug_tree (TYPE_DOMAIN (t));
14586 : 0 : error_found = true;
14587 : : }
14588 : : }
14589 : 715903557 : else if (RECORD_OR_UNION_TYPE_P (t))
14590 : : {
14591 : 379242810 : if (TYPE_FIELDS (t) && !COMPLETE_TYPE_P (t) && in_lto_p)
14592 : : {
14593 : 0 : error ("%<TYPE_FIELDS%> defined in incomplete type");
14594 : 0 : error_found = true;
14595 : : }
14596 : 17180737350 : for (tree fld = TYPE_FIELDS (t); fld; fld = TREE_CHAIN (fld))
14597 : : {
14598 : : /* TODO: verify properties of decls. */
14599 : 16801494540 : if (TREE_CODE (fld) == FIELD_DECL)
14600 : : ;
14601 : : else if (TREE_CODE (fld) == TYPE_DECL)
14602 : : ;
14603 : : else if (TREE_CODE (fld) == CONST_DECL)
14604 : : ;
14605 : : else if (VAR_P (fld))
14606 : : ;
14607 : : else if (TREE_CODE (fld) == TEMPLATE_DECL)
14608 : : ;
14609 : : else if (TREE_CODE (fld) == USING_DECL)
14610 : : ;
14611 : : else if (TREE_CODE (fld) == FUNCTION_DECL)
14612 : : ;
14613 : : else
14614 : : {
14615 : 0 : error ("wrong tree in %<TYPE_FIELDS%> list");
14616 : 0 : debug_tree (fld);
14617 : 0 : error_found = true;
14618 : : }
14619 : : }
14620 : : }
14621 : 336660747 : else if (TREE_CODE (t) == INTEGER_TYPE
14622 : : || TREE_CODE (t) == BOOLEAN_TYPE
14623 : 336660747 : || TREE_CODE (t) == BITINT_TYPE
14624 : 247196306 : || TREE_CODE (t) == OFFSET_TYPE
14625 : 247160654 : || TREE_CODE (t) == REFERENCE_TYPE
14626 : 204321921 : || TREE_CODE (t) == NULLPTR_TYPE
14627 : 204024767 : || TREE_CODE (t) == POINTER_TYPE)
14628 : : {
14629 : 225395799 : if (TYPE_CACHED_VALUES_P (t) != (TYPE_CACHED_VALUES (t) != NULL))
14630 : : {
14631 : 0 : error ("%<TYPE_CACHED_VALUES_P%> is %i while %<TYPE_CACHED_VALUES%> "
14632 : : "is %p",
14633 : 0 : TYPE_CACHED_VALUES_P (t), (void *)TYPE_CACHED_VALUES (t));
14634 : 0 : error_found = true;
14635 : : }
14636 : 225395799 : else if (TYPE_CACHED_VALUES_P (t) && TREE_CODE (TYPE_CACHED_VALUES (t)) != TREE_VEC)
14637 : : {
14638 : 0 : error ("%<TYPE_CACHED_VALUES%> is not %<TREE_VEC%>");
14639 : 0 : debug_tree (TYPE_CACHED_VALUES (t));
14640 : 0 : error_found = true;
14641 : : }
14642 : : /* Verify just enough of cache to ensure that no one copied it to new type.
14643 : : All copying should go by copy_node that should clear it. */
14644 : 225395799 : else if (TYPE_CACHED_VALUES_P (t))
14645 : : {
14646 : : int i;
14647 : 7542869461 : for (i = 0; i < TREE_VEC_LENGTH (TYPE_CACHED_VALUES (t)); i++)
14648 : 7496890403 : if (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)
14649 : 7496890403 : && TREE_TYPE (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)) != t)
14650 : : {
14651 : 0 : error ("wrong %<TYPE_CACHED_VALUES%> entry");
14652 : 0 : debug_tree (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i));
14653 : 0 : error_found = true;
14654 : 0 : break;
14655 : : }
14656 : : }
14657 : : }
14658 : 111264948 : else if (FUNC_OR_METHOD_TYPE_P (t))
14659 : 3090730 : for (tree l = TYPE_ARG_TYPES (t); l; l = TREE_CHAIN (l))
14660 : : {
14661 : : /* C++ FE uses TREE_PURPOSE to store initial values. */
14662 : 2269369 : if (TREE_PURPOSE (l) && in_lto_p)
14663 : : {
14664 : 0 : error ("%<TREE_PURPOSE%> is non-NULL in %<TYPE_ARG_TYPES%> list");
14665 : 0 : debug_tree (l);
14666 : 0 : error_found = true;
14667 : : }
14668 : 2269369 : if (!TYPE_P (TREE_VALUE (l)))
14669 : : {
14670 : 0 : error ("wrong entry in %<TYPE_ARG_TYPES%> list");
14671 : 0 : debug_tree (l);
14672 : 0 : error_found = true;
14673 : : }
14674 : : }
14675 : 220502223 : else if (!is_lang_specific (t) && TYPE_VALUES_RAW (t))
14676 : : {
14677 : 0 : error ("%<TYPE_VALUES_RAW%> field is non-NULL");
14678 : 0 : debug_tree (TYPE_VALUES_RAW (t));
14679 : 0 : error_found = true;
14680 : : }
14681 : 728161431 : if (TREE_CODE (t) != INTEGER_TYPE
14682 : : && TREE_CODE (t) != BOOLEAN_TYPE
14683 : 728161431 : && TREE_CODE (t) != BITINT_TYPE
14684 : : && TREE_CODE (t) != OFFSET_TYPE
14685 : : && TREE_CODE (t) != REFERENCE_TYPE
14686 : : && TREE_CODE (t) != NULLPTR_TYPE
14687 : : && TREE_CODE (t) != POINTER_TYPE
14688 : 502765632 : && TYPE_CACHED_VALUES_P (t))
14689 : : {
14690 : 0 : error ("%<TYPE_CACHED_VALUES_P%> is set while it should not be");
14691 : 0 : error_found = true;
14692 : : }
14693 : :
14694 : : /* ipa-devirt makes an assumption that TYPE_METHOD_BASETYPE is always
14695 : : TYPE_MAIN_VARIANT and it would be odd to add methods only to variatns
14696 : : of a type. */
14697 : 728161431 : if (TREE_CODE (t) == METHOD_TYPE
14698 : 728161431 : && TYPE_MAIN_VARIANT (TYPE_METHOD_BASETYPE (t)) != TYPE_METHOD_BASETYPE (t))
14699 : : {
14700 : 0 : error ("%<TYPE_METHOD_BASETYPE%> is not main variant");
14701 : 0 : error_found = true;
14702 : : }
14703 : :
14704 : 728161431 : if (error_found)
14705 : : {
14706 : 0 : debug_tree (const_cast <tree> (t));
14707 : 0 : internal_error ("%qs failed", __func__);
14708 : : }
14709 : : }
14710 : :
14711 : :
14712 : : /* Return 1 if ARG interpreted as signed in its precision is known to be
14713 : : always non-negative or 2 if ARG is known to be always negative, or 3 if
14714 : : ARG may be non-negative or negative. STMT if specified is the statement
14715 : : on which it is being tested. */
14716 : :
14717 : : int
14718 : 821891 : get_range_pos_neg (tree arg, gimple *stmt)
14719 : : {
14720 : 821891 : if (arg == error_mark_node || !INTEGRAL_TYPE_P (TREE_TYPE (arg)))
14721 : : return 3;
14722 : :
14723 : 821891 : int prec = TYPE_PRECISION (TREE_TYPE (arg));
14724 : 821891 : int cnt = 0;
14725 : 821891 : if (TREE_CODE (arg) == INTEGER_CST)
14726 : : {
14727 : 83499 : wide_int w = wi::sext (wi::to_wide (arg), prec);
14728 : 83499 : if (wi::neg_p (w))
14729 : : return 2;
14730 : : else
14731 : 69096 : return 1;
14732 : 83499 : }
14733 : 737181 : while (CONVERT_EXPR_P (arg)
14734 : 14499 : && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
14735 : 766179 : && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg, 0))) <= prec)
14736 : : {
14737 : 13715 : arg = TREE_OPERAND (arg, 0);
14738 : : /* Narrower value zero extended into wider type
14739 : : will always result in positive values. */
14740 : 13715 : if (TYPE_UNSIGNED (TREE_TYPE (arg))
14741 : 13715 : && TYPE_PRECISION (TREE_TYPE (arg)) < prec)
14742 : : return 1;
14743 : 13288 : prec = TYPE_PRECISION (TREE_TYPE (arg));
14744 : 13288 : if (++cnt > 30)
14745 : : return 3;
14746 : : }
14747 : :
14748 : 737965 : if (TREE_CODE (arg) != SSA_NAME)
14749 : : return 3;
14750 : 731301 : int_range_max r;
14751 : 1477134 : while (!get_range_query (cfun)->range_of_expr (r, arg, stmt)
14752 : 1491666 : || r.undefined_p () || r.varying_p ())
14753 : : {
14754 : 442911 : gimple *g = SSA_NAME_DEF_STMT (arg);
14755 : 442911 : if (is_gimple_assign (g)
14756 : 442911 : && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (g)))
14757 : : {
14758 : 25118 : tree t = gimple_assign_rhs1 (g);
14759 : 49882 : if (INTEGRAL_TYPE_P (TREE_TYPE (t))
14760 : 47203 : && TYPE_PRECISION (TREE_TYPE (t)) <= prec)
14761 : : {
14762 : 14532 : if (TYPE_UNSIGNED (TREE_TYPE (t))
14763 : 14532 : && TYPE_PRECISION (TREE_TYPE (t)) < prec)
14764 : : return 1;
14765 : 14532 : prec = TYPE_PRECISION (TREE_TYPE (t));
14766 : 14532 : arg = t;
14767 : 14532 : if (++cnt > 30)
14768 : : return 3;
14769 : 14532 : continue;
14770 : : }
14771 : : }
14772 : : return 3;
14773 : : }
14774 : 302922 : if (TYPE_UNSIGNED (TREE_TYPE (arg)))
14775 : : {
14776 : : /* For unsigned values, the "positive" range comes
14777 : : below the "negative" range. */
14778 : 133286 : if (!wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14779 : : return 1;
14780 : 38115 : if (wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14781 : : return 2;
14782 : : }
14783 : : else
14784 : : {
14785 : 169636 : if (!wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14786 : : return 1;
14787 : 70640 : if (wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14788 : : return 2;
14789 : : }
14790 : : return 3;
14791 : 731301 : }
14792 : :
14793 : :
14794 : :
14795 : :
14796 : : /* Return true if ARG is marked with the nonnull attribute in the
14797 : : current function signature. */
14798 : :
14799 : : bool
14800 : 26429929 : nonnull_arg_p (const_tree arg)
14801 : : {
14802 : 26429929 : tree t, attrs, fntype;
14803 : 26429929 : unsigned HOST_WIDE_INT arg_num;
14804 : :
14805 : 26429929 : gcc_assert (TREE_CODE (arg) == PARM_DECL
14806 : : && (POINTER_TYPE_P (TREE_TYPE (arg))
14807 : : || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE));
14808 : :
14809 : : /* The static chain decl is always non null. */
14810 : 26429929 : if (arg == cfun->static_chain_decl)
14811 : : return true;
14812 : :
14813 : : /* THIS argument of method is always non-NULL. */
14814 : 26161838 : if (TREE_CODE (TREE_TYPE (cfun->decl)) == METHOD_TYPE
14815 : 10306977 : && arg == DECL_ARGUMENTS (cfun->decl)
14816 : 32612065 : && flag_delete_null_pointer_checks)
14817 : : return true;
14818 : :
14819 : : /* Values passed by reference are always non-NULL. */
14820 : 19713689 : if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE
14821 : 19713689 : && flag_delete_null_pointer_checks)
14822 : : return true;
14823 : :
14824 : 13468503 : fntype = TREE_TYPE (cfun->decl);
14825 : 13491447 : for (attrs = TYPE_ATTRIBUTES (fntype); attrs; attrs = TREE_CHAIN (attrs))
14826 : : {
14827 : 535845 : attrs = lookup_attribute ("nonnull", attrs);
14828 : :
14829 : : /* If "nonnull" wasn't specified, we know nothing about the argument. */
14830 : 535845 : if (attrs == NULL_TREE)
14831 : : return false;
14832 : :
14833 : : /* If "nonnull" applies to all the arguments, then ARG is non-null. */
14834 : 111085 : if (TREE_VALUE (attrs) == NULL_TREE)
14835 : : return true;
14836 : :
14837 : : /* Get the position number for ARG in the function signature. */
14838 : 55725 : for (arg_num = 1, t = DECL_ARGUMENTS (cfun->decl);
14839 : 130292 : t;
14840 : 74567 : t = DECL_CHAIN (t), arg_num++)
14841 : : {
14842 : 130292 : if (t == arg)
14843 : : break;
14844 : : }
14845 : :
14846 : 55725 : gcc_assert (t == arg);
14847 : :
14848 : : /* Now see if ARG_NUM is mentioned in the nonnull list. */
14849 : 88415 : for (t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
14850 : : {
14851 : 65471 : if (compare_tree_int (TREE_VALUE (t), arg_num) == 0)
14852 : : return true;
14853 : : }
14854 : : }
14855 : :
14856 : : return false;
14857 : : }
14858 : :
14859 : : /* Combine LOC and BLOCK to a combined adhoc loc, retaining any range
14860 : : information. */
14861 : :
14862 : : location_t
14863 : 631969483 : set_block (location_t loc, tree block)
14864 : : {
14865 : 631969483 : location_t pure_loc = get_pure_location (loc);
14866 : 631969483 : source_range src_range = get_range_from_loc (line_table, loc);
14867 : 631969483 : unsigned discriminator = get_discriminator_from_loc (line_table, loc);
14868 : 631969483 : return line_table->get_or_create_combined_loc (pure_loc, src_range, block,
14869 : 631969483 : discriminator);
14870 : : }
14871 : :
14872 : : location_t
14873 : 216402060 : set_source_range (tree expr, location_t start, location_t finish)
14874 : : {
14875 : 216402060 : source_range src_range;
14876 : 216402060 : src_range.m_start = start;
14877 : 216402060 : src_range.m_finish = finish;
14878 : 216402060 : return set_source_range (expr, src_range);
14879 : : }
14880 : :
14881 : : location_t
14882 : 442050931 : set_source_range (tree expr, source_range src_range)
14883 : : {
14884 : 442050931 : if (!EXPR_P (expr))
14885 : : return UNKNOWN_LOCATION;
14886 : :
14887 : 194523763 : location_t expr_location = EXPR_LOCATION (expr);
14888 : 194523763 : location_t pure_loc = get_pure_location (expr_location);
14889 : 194523763 : unsigned discriminator = get_discriminator_from_loc (expr_location);
14890 : 194523763 : location_t adhoc = line_table->get_or_create_combined_loc (pure_loc,
14891 : : src_range,
14892 : : nullptr,
14893 : : discriminator);
14894 : 194523763 : SET_EXPR_LOCATION (expr, adhoc);
14895 : 194523763 : return adhoc;
14896 : : }
14897 : :
14898 : : /* Return EXPR, potentially wrapped with a node expression LOC,
14899 : : if !CAN_HAVE_LOCATION_P (expr).
14900 : :
14901 : : NON_LVALUE_EXPR is used for wrapping constants, apart from STRING_CST.
14902 : : VIEW_CONVERT_EXPR is used for wrapping non-constants and STRING_CST.
14903 : :
14904 : : Wrapper nodes can be identified using location_wrapper_p. */
14905 : :
14906 : : tree
14907 : 1246361326 : maybe_wrap_with_location (tree expr, location_t loc)
14908 : : {
14909 : 1246361326 : if (expr == NULL)
14910 : : return NULL;
14911 : 1246361322 : if (loc == UNKNOWN_LOCATION)
14912 : : return expr;
14913 : 1204220399 : if (CAN_HAVE_LOCATION_P (expr))
14914 : : return expr;
14915 : : /* We should only be adding wrappers for constants and for decls,
14916 : : or for some exceptional tree nodes (e.g. BASELINK in the C++ FE). */
14917 : 729260272 : gcc_assert (CONSTANT_CLASS_P (expr)
14918 : : || DECL_P (expr)
14919 : : || EXCEPTIONAL_CLASS_P (expr));
14920 : :
14921 : : /* For now, don't add wrappers to exceptional tree nodes, to minimize
14922 : : any impact of the wrapper nodes. */
14923 : 729260272 : if (EXCEPTIONAL_CLASS_P (expr) || error_operand_p (expr))
14924 : : return expr;
14925 : :
14926 : : /* Compiler-generated temporary variables don't need a wrapper. */
14927 : 672342805 : if (DECL_P (expr) && DECL_ARTIFICIAL (expr) && DECL_IGNORED_P (expr))
14928 : : return expr;
14929 : :
14930 : : /* If any auto_suppress_location_wrappers are active, don't create
14931 : : wrappers. */
14932 : 672340523 : if (suppress_location_wrappers > 0)
14933 : : return expr;
14934 : :
14935 : 1282279664 : tree_code code
14936 : 159481798 : = (((CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST)
14937 : 488716595 : || (TREE_CODE (expr) == CONST_DECL && !TREE_STATIC (expr)))
14938 : 641139832 : ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR);
14939 : 641139832 : tree wrapper = build1_loc (loc, code, TREE_TYPE (expr), expr);
14940 : : /* Mark this node as being a wrapper. */
14941 : 641139832 : EXPR_LOCATION_WRAPPER_P (wrapper) = 1;
14942 : 641139832 : return wrapper;
14943 : : }
14944 : :
14945 : : int suppress_location_wrappers;
14946 : :
14947 : : /* Return the name of combined function FN, for debugging purposes. */
14948 : :
14949 : : const char *
14950 : 0 : combined_fn_name (combined_fn fn)
14951 : : {
14952 : 0 : if (builtin_fn_p (fn))
14953 : : {
14954 : 0 : tree fndecl = builtin_decl_explicit (as_builtin_fn (fn));
14955 : 0 : return IDENTIFIER_POINTER (DECL_NAME (fndecl));
14956 : : }
14957 : : else
14958 : 0 : return internal_fn_name (as_internal_fn (fn));
14959 : : }
14960 : :
14961 : : /* Return a bitmap with a bit set corresponding to each argument in
14962 : : a function call type FNTYPE declared with attribute nonnull,
14963 : : or null if none of the function's argument are nonnull. The caller
14964 : : must free the bitmap. */
14965 : :
14966 : : bitmap
14967 : 21338752 : get_nonnull_args (const_tree fntype)
14968 : : {
14969 : 21338752 : if (fntype == NULL_TREE)
14970 : : return NULL;
14971 : :
14972 : 20657666 : bitmap argmap = NULL;
14973 : 20657666 : if (TREE_CODE (fntype) == METHOD_TYPE)
14974 : : {
14975 : : /* The this pointer in C++ non-static member functions is
14976 : : implicitly nonnull whether or not it's declared as such. */
14977 : 2912076 : argmap = BITMAP_ALLOC (NULL);
14978 : 2912076 : bitmap_set_bit (argmap, 0);
14979 : : }
14980 : :
14981 : 20657666 : tree attrs = TYPE_ATTRIBUTES (fntype);
14982 : 20657666 : if (!attrs)
14983 : : return argmap;
14984 : :
14985 : : /* A function declaration can specify multiple attribute nonnull,
14986 : : each with zero or more arguments. The loop below creates a bitmap
14987 : : representing a union of all the arguments. An empty (but non-null)
14988 : : bitmap means that all arguments have been declared nonnull. */
14989 : 5675787 : for ( ; attrs; attrs = TREE_CHAIN (attrs))
14990 : : {
14991 : 5574872 : attrs = lookup_attribute ("nonnull", attrs);
14992 : 5574872 : if (!attrs)
14993 : : break;
14994 : :
14995 : 1611781 : if (!argmap)
14996 : 1571852 : argmap = BITMAP_ALLOC (NULL);
14997 : :
14998 : 1611781 : if (!TREE_VALUE (attrs))
14999 : : {
15000 : : /* Clear the bitmap in case a previous attribute nonnull
15001 : : set it and this one overrides it for all arguments. */
15002 : 982972 : bitmap_clear (argmap);
15003 : 982972 : return argmap;
15004 : : }
15005 : :
15006 : : /* Iterate over the indices of the format arguments declared nonnull
15007 : : and set a bit for each. */
15008 : 1656767 : for (tree idx = TREE_VALUE (attrs); idx; idx = TREE_CHAIN (idx))
15009 : : {
15010 : 1027958 : unsigned int val = TREE_INT_CST_LOW (TREE_VALUE (idx)) - 1;
15011 : 1027958 : bitmap_set_bit (argmap, val);
15012 : : }
15013 : : }
15014 : :
15015 : : return argmap;
15016 : : }
15017 : :
15018 : : /* Returns true if TYPE is a type where it and all of its subobjects
15019 : : (recursively) are of structure, union, or array type. */
15020 : :
15021 : : bool
15022 : 1795386658 : is_empty_type (const_tree type)
15023 : : {
15024 : 1795386658 : if (RECORD_OR_UNION_TYPE_P (type))
15025 : : {
15026 : 787799407 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
15027 : 732450553 : if (TREE_CODE (field) == FIELD_DECL
15028 : 397180344 : && !DECL_PADDING_P (field)
15029 : 1129629644 : && !is_empty_type (TREE_TYPE (field)))
15030 : : return false;
15031 : : return true;
15032 : : }
15033 : 1366124776 : else if (TREE_CODE (type) == ARRAY_TYPE)
15034 : 73433846 : return (integer_minus_onep (array_type_nelts_minus_one (type))
15035 : 73390457 : || TYPE_DOMAIN (type) == NULL_TREE
15036 : 141022067 : || is_empty_type (TREE_TYPE (type)));
15037 : : return false;
15038 : : }
15039 : :
15040 : : /* Implement TARGET_EMPTY_RECORD_P. Return true if TYPE is an empty type
15041 : : that shouldn't be passed via stack. */
15042 : :
15043 : : bool
15044 : 1280250641 : default_is_empty_record (const_tree type)
15045 : : {
15046 : 1280250641 : if (!abi_version_at_least (12))
15047 : : return false;
15048 : :
15049 : 1279206043 : if (type == error_mark_node)
15050 : : return false;
15051 : :
15052 : 1279206043 : if (TREE_ADDRESSABLE (type))
15053 : : return false;
15054 : :
15055 : 1279206043 : return is_empty_type (TYPE_MAIN_VARIANT (type));
15056 : : }
15057 : :
15058 : : /* Determine whether TYPE is a structure with a flexible array member,
15059 : : or a union containing such a structure (possibly recursively). */
15060 : :
15061 : : bool
15062 : 73376 : flexible_array_type_p (const_tree type)
15063 : : {
15064 : 73376 : tree x, last;
15065 : 73376 : switch (TREE_CODE (type))
15066 : : {
15067 : 37418 : case RECORD_TYPE:
15068 : 37418 : last = NULL_TREE;
15069 : 171200 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15070 : 133782 : if (TREE_CODE (x) == FIELD_DECL)
15071 : 133782 : last = x;
15072 : 37418 : if (last == NULL_TREE)
15073 : : return false;
15074 : 37410 : if (TREE_CODE (TREE_TYPE (last)) == ARRAY_TYPE
15075 : 474 : && TYPE_SIZE (TREE_TYPE (last)) == NULL_TREE
15076 : 239 : && TYPE_DOMAIN (TREE_TYPE (last)) != NULL_TREE
15077 : 37649 : && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (last))) == NULL_TREE)
15078 : : return true;
15079 : : return false;
15080 : 617 : case UNION_TYPE:
15081 : 1784 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15082 : : {
15083 : 1209 : if (TREE_CODE (x) == FIELD_DECL
15084 : 1209 : && flexible_array_type_p (TREE_TYPE (x)))
15085 : : return true;
15086 : : }
15087 : : return false;
15088 : : default:
15089 : : return false;
15090 : : }
15091 : : }
15092 : :
15093 : : /* Like int_size_in_bytes, but handle empty records specially. */
15094 : :
15095 : : HOST_WIDE_INT
15096 : 371631 : arg_int_size_in_bytes (const_tree type)
15097 : : {
15098 : 371631 : return TYPE_EMPTY_P (type) ? 0 : int_size_in_bytes (type);
15099 : : }
15100 : :
15101 : : /* Like size_in_bytes, but handle empty records specially. */
15102 : :
15103 : : tree
15104 : 5642761 : arg_size_in_bytes (const_tree type)
15105 : : {
15106 : 5642761 : return TYPE_EMPTY_P (type) ? size_zero_node : size_in_bytes (type);
15107 : : }
15108 : :
15109 : : /* Return true if an expression with CODE has to have the same result type as
15110 : : its first operand. */
15111 : :
15112 : : bool
15113 : 0 : expr_type_first_operand_type_p (tree_code code)
15114 : : {
15115 : 0 : switch (code)
15116 : : {
15117 : : case NEGATE_EXPR:
15118 : : case ABS_EXPR:
15119 : : case BIT_NOT_EXPR:
15120 : : case PAREN_EXPR:
15121 : : case CONJ_EXPR:
15122 : :
15123 : : case PLUS_EXPR:
15124 : : case MINUS_EXPR:
15125 : : case MULT_EXPR:
15126 : : case TRUNC_DIV_EXPR:
15127 : : case CEIL_DIV_EXPR:
15128 : : case FLOOR_DIV_EXPR:
15129 : : case ROUND_DIV_EXPR:
15130 : : case TRUNC_MOD_EXPR:
15131 : : case CEIL_MOD_EXPR:
15132 : : case FLOOR_MOD_EXPR:
15133 : : case ROUND_MOD_EXPR:
15134 : : case RDIV_EXPR:
15135 : : case EXACT_DIV_EXPR:
15136 : : case MIN_EXPR:
15137 : : case MAX_EXPR:
15138 : : case BIT_IOR_EXPR:
15139 : : case BIT_XOR_EXPR:
15140 : : case BIT_AND_EXPR:
15141 : :
15142 : : case LSHIFT_EXPR:
15143 : : case RSHIFT_EXPR:
15144 : : case LROTATE_EXPR:
15145 : : case RROTATE_EXPR:
15146 : : return true;
15147 : :
15148 : 0 : default:
15149 : 0 : return false;
15150 : : }
15151 : : }
15152 : :
15153 : : /* Return a typenode for the "standard" C type with a given name. */
15154 : : tree
15155 : 896521 : get_typenode_from_name (const char *name)
15156 : : {
15157 : 896521 : if (name == NULL || *name == '\0')
15158 : : return NULL_TREE;
15159 : :
15160 : 896521 : if (strcmp (name, "char") == 0)
15161 : 0 : return char_type_node;
15162 : 896521 : if (strcmp (name, "unsigned char") == 0)
15163 : 92556 : return unsigned_char_type_node;
15164 : 803965 : if (strcmp (name, "signed char") == 0)
15165 : 92556 : return signed_char_type_node;
15166 : :
15167 : 711409 : if (strcmp (name, "short int") == 0)
15168 : 63217 : return short_integer_type_node;
15169 : 648192 : if (strcmp (name, "short unsigned int") == 0)
15170 : 61704 : return short_unsigned_type_node;
15171 : :
15172 : 586488 : if (strcmp (name, "int") == 0)
15173 : 64039 : return integer_type_node;
15174 : 522449 : if (strcmp (name, "unsigned int") == 0)
15175 : 62518 : return unsigned_type_node;
15176 : :
15177 : 459931 : if (strcmp (name, "long int") == 0)
15178 : 274005 : return long_integer_type_node;
15179 : 185926 : if (strcmp (name, "long unsigned int") == 0)
15180 : 182670 : return long_unsigned_type_node;
15181 : :
15182 : 3256 : if (strcmp (name, "long long int") == 0)
15183 : 1628 : return long_long_integer_type_node;
15184 : 1628 : if (strcmp (name, "long long unsigned int") == 0)
15185 : 1628 : return long_long_unsigned_type_node;
15186 : :
15187 : 0 : gcc_unreachable ();
15188 : : }
15189 : :
15190 : : /* List of pointer types used to declare builtins before we have seen their
15191 : : real declaration.
15192 : :
15193 : : Keep the size up to date in tree.h ! */
15194 : : const builtin_structptr_type builtin_structptr_types[6] =
15195 : : {
15196 : : { fileptr_type_node, ptr_type_node, "FILE" },
15197 : : { const_tm_ptr_type_node, const_ptr_type_node, "tm" },
15198 : : { fenv_t_ptr_type_node, ptr_type_node, "fenv_t" },
15199 : : { const_fenv_t_ptr_type_node, const_ptr_type_node, "fenv_t" },
15200 : : { fexcept_t_ptr_type_node, ptr_type_node, "fexcept_t" },
15201 : : { const_fexcept_t_ptr_type_node, const_ptr_type_node, "fexcept_t" }
15202 : : };
15203 : :
15204 : : /* Return the maximum object size. */
15205 : :
15206 : : tree
15207 : 7116069 : max_object_size (void)
15208 : : {
15209 : : /* To do: Make this a configurable parameter. */
15210 : 7116069 : return TYPE_MAX_VALUE (ptrdiff_type_node);
15211 : : }
15212 : :
15213 : : /* A wrapper around TARGET_VERIFY_TYPE_CONTEXT that makes the silent_p
15214 : : parameter default to false and that weeds out error_mark_node. */
15215 : :
15216 : : bool
15217 : 115191719 : verify_type_context (location_t loc, type_context_kind context,
15218 : : const_tree type, bool silent_p)
15219 : : {
15220 : 115191719 : if (type == error_mark_node)
15221 : : return true;
15222 : :
15223 : 115191627 : gcc_assert (TYPE_P (type));
15224 : 115191627 : return (!targetm.verify_type_context
15225 : 115191627 : || targetm.verify_type_context (loc, context, type, silent_p));
15226 : : }
15227 : :
15228 : : /* Return true if NEW_ASM and DELETE_ASM name a valid pair of new and
15229 : : delete operators. Return false if they may or may not name such
15230 : : a pair and, when nonnull, set *PCERTAIN to true if they certainly
15231 : : do not. */
15232 : :
15233 : : bool
15234 : 60645 : valid_new_delete_pair_p (tree new_asm, tree delete_asm,
15235 : : bool *pcertain /* = NULL */)
15236 : : {
15237 : 60645 : bool certain;
15238 : 60645 : if (!pcertain)
15239 : 49032 : pcertain = &certain;
15240 : :
15241 : 60645 : const char *new_name = IDENTIFIER_POINTER (new_asm);
15242 : 60645 : const char *delete_name = IDENTIFIER_POINTER (delete_asm);
15243 : 60645 : unsigned int new_len = IDENTIFIER_LENGTH (new_asm);
15244 : 60645 : unsigned int delete_len = IDENTIFIER_LENGTH (delete_asm);
15245 : :
15246 : : /* The following failures are due to invalid names so they're not
15247 : : considered certain mismatches. */
15248 : 60645 : *pcertain = false;
15249 : :
15250 : 60645 : if (new_len < 5 || delete_len < 6)
15251 : : return false;
15252 : 60645 : if (new_name[0] == '_')
15253 : 60573 : ++new_name, --new_len;
15254 : 60645 : if (new_name[0] == '_')
15255 : 0 : ++new_name, --new_len;
15256 : 60645 : if (delete_name[0] == '_')
15257 : 60645 : ++delete_name, --delete_len;
15258 : 60645 : if (delete_name[0] == '_')
15259 : 0 : ++delete_name, --delete_len;
15260 : 60645 : if (new_len < 4 || delete_len < 5)
15261 : : return false;
15262 : :
15263 : : /* The following failures are due to names of user-defined operators
15264 : : so they're also not considered certain mismatches. */
15265 : :
15266 : : /* *_len is now just the length after initial underscores. */
15267 : 60645 : if (new_name[0] != 'Z' || new_name[1] != 'n')
15268 : : return false;
15269 : 59978 : if (delete_name[0] != 'Z' || delete_name[1] != 'd')
15270 : : return false;
15271 : :
15272 : : /* The following failures are certain mismatches. */
15273 : 59906 : *pcertain = true;
15274 : :
15275 : : /* _Znw must match _Zdl, _Zna must match _Zda. */
15276 : 59906 : if ((new_name[2] != 'w' || delete_name[2] != 'l')
15277 : 7368 : && (new_name[2] != 'a' || delete_name[2] != 'a'))
15278 : : return false;
15279 : : /* 'j', 'm' and 'y' correspond to size_t. */
15280 : 59810 : if (new_name[3] != 'j' && new_name[3] != 'm' && new_name[3] != 'y')
15281 : : return false;
15282 : 59810 : if (delete_name[3] != 'P' || delete_name[4] != 'v')
15283 : : return false;
15284 : 59810 : if (new_len == 4
15285 : 489 : || (new_len == 18 && !memcmp (new_name + 4, "RKSt9nothrow_t", 14)))
15286 : : {
15287 : : /* _ZnXY or _ZnXYRKSt9nothrow_t matches
15288 : : _ZdXPv, _ZdXPvY and _ZdXPvRKSt9nothrow_t. */
15289 : 59487 : if (delete_len == 5)
15290 : : return true;
15291 : 50390 : if (delete_len == 6 && delete_name[5] == new_name[3])
15292 : : return true;
15293 : 39 : if (delete_len == 19 && !memcmp (delete_name + 5, "RKSt9nothrow_t", 14))
15294 : : return true;
15295 : : }
15296 : 323 : else if ((new_len == 19 && !memcmp (new_name + 4, "St11align_val_t", 15))
15297 : 42 : || (new_len == 33
15298 : 10 : && !memcmp (new_name + 4, "St11align_val_tRKSt9nothrow_t", 29)))
15299 : : {
15300 : : /* _ZnXYSt11align_val_t or _ZnXYSt11align_val_tRKSt9nothrow_t matches
15301 : : _ZdXPvSt11align_val_t or _ZdXPvYSt11align_val_t or
15302 : : _ZdXPvSt11align_val_tRKSt9nothrow_t. */
15303 : 291 : if (delete_len == 20 && !memcmp (delete_name + 5, "St11align_val_t", 15))
15304 : : return true;
15305 : 56 : if (delete_len == 21
15306 : 41 : && delete_name[5] == new_name[3]
15307 : 41 : && !memcmp (delete_name + 6, "St11align_val_t", 15))
15308 : : return true;
15309 : 15 : if (delete_len == 34
15310 : 9 : && !memcmp (delete_name + 5, "St11align_val_tRKSt9nothrow_t", 29))
15311 : : return true;
15312 : : }
15313 : :
15314 : : /* The negative result is conservative. */
15315 : 38 : *pcertain = false;
15316 : 38 : return false;
15317 : : }
15318 : :
15319 : : /* Return the zero-based number corresponding to the argument being
15320 : : deallocated if FNDECL is a deallocation function or an out-of-bounds
15321 : : value if it isn't. */
15322 : :
15323 : : unsigned
15324 : 28210280 : fndecl_dealloc_argno (tree fndecl)
15325 : : {
15326 : : /* A call to operator delete isn't recognized as one to a built-in. */
15327 : 28210280 : if (DECL_IS_OPERATOR_DELETE_P (fndecl))
15328 : : {
15329 : 455938 : if (DECL_IS_REPLACEABLE_OPERATOR (fndecl))
15330 : : return 0;
15331 : :
15332 : : /* Avoid placement delete that's not been inlined. */
15333 : 25005 : tree fname = DECL_ASSEMBLER_NAME (fndecl);
15334 : 25005 : if (id_equal (fname, "_ZdlPvS_") // ordinary form
15335 : 25005 : || id_equal (fname, "_ZdaPvS_")) // array form
15336 : : return UINT_MAX;
15337 : : return 0;
15338 : : }
15339 : :
15340 : : /* TODO: Handle user-defined functions with attribute malloc? Handle
15341 : : known non-built-ins like fopen? */
15342 : 27754342 : if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
15343 : : {
15344 : 7202454 : switch (DECL_FUNCTION_CODE (fndecl))
15345 : : {
15346 : : case BUILT_IN_FREE:
15347 : : case BUILT_IN_REALLOC:
15348 : : case BUILT_IN_GOMP_FREE:
15349 : : case BUILT_IN_GOMP_REALLOC:
15350 : : return 0;
15351 : : default:
15352 : : break;
15353 : : }
15354 : : return UINT_MAX;
15355 : : }
15356 : :
15357 : 20551888 : tree attrs = DECL_ATTRIBUTES (fndecl);
15358 : 20551888 : if (!attrs)
15359 : : return UINT_MAX;
15360 : :
15361 : 0 : for (tree atfree = attrs;
15362 : 4643920 : (atfree = lookup_attribute ("*dealloc", atfree));
15363 : 0 : atfree = TREE_CHAIN (atfree))
15364 : : {
15365 : 6242 : tree alloc = TREE_VALUE (atfree);
15366 : 6242 : if (!alloc)
15367 : 0 : continue;
15368 : :
15369 : 6242 : tree pos = TREE_CHAIN (alloc);
15370 : 6242 : if (!pos)
15371 : : return 0;
15372 : :
15373 : 3722 : pos = TREE_VALUE (pos);
15374 : 3722 : return TREE_INT_CST_LOW (pos) - 1;
15375 : : }
15376 : :
15377 : : return UINT_MAX;
15378 : : }
15379 : :
15380 : : /* If EXPR refers to a character array or pointer declared attribute
15381 : : nonstring, return a decl for that array or pointer and set *REF
15382 : : to the referenced enclosing object or pointer. Otherwise return
15383 : : null. */
15384 : :
15385 : : tree
15386 : 1396981 : get_attr_nonstring_decl (tree expr, tree *ref)
15387 : : {
15388 : 1402632 : tree decl = expr;
15389 : 1402632 : tree var = NULL_TREE;
15390 : 1402632 : if (TREE_CODE (decl) == SSA_NAME)
15391 : : {
15392 : 834834 : gimple *def = SSA_NAME_DEF_STMT (decl);
15393 : :
15394 : 834834 : if (is_gimple_assign (def))
15395 : : {
15396 : 45178 : tree_code code = gimple_assign_rhs_code (def);
15397 : 45178 : if (code == ADDR_EXPR
15398 : 45178 : || code == COMPONENT_REF
15399 : 31254 : || code == VAR_DECL)
15400 : 18692 : decl = gimple_assign_rhs1 (def);
15401 : : }
15402 : : else
15403 : 789656 : var = SSA_NAME_VAR (decl);
15404 : : }
15405 : :
15406 : 1402632 : if (TREE_CODE (decl) == ADDR_EXPR)
15407 : 25853 : decl = TREE_OPERAND (decl, 0);
15408 : :
15409 : : /* To simplify calling code, store the referenced DECL regardless of
15410 : : the attribute determined below, but avoid storing the SSA_NAME_VAR
15411 : : obtained above (it's not useful for dataflow purposes). */
15412 : 1402632 : if (ref)
15413 : 5446 : *ref = decl;
15414 : :
15415 : : /* Use the SSA_NAME_VAR that was determined above to see if it's
15416 : : declared nonstring. Otherwise drill down into the referenced
15417 : : DECL. */
15418 : 1402632 : if (var)
15419 : : decl = var;
15420 : : else
15421 : : {
15422 : 637911 : while (TREE_CODE (decl) == ARRAY_REF)
15423 : 18498 : decl = TREE_OPERAND (decl, 0);
15424 : 619413 : if (TREE_CODE (decl) == COMPONENT_REF)
15425 : 15759 : decl = TREE_OPERAND (decl, 1);
15426 : 603654 : else if (TREE_CODE (decl) == MEM_REF)
15427 : 5651 : return get_attr_nonstring_decl (TREE_OPERAND (decl, 0), ref);
15428 : : }
15429 : :
15430 : 1396981 : if (DECL_P (decl) && lookup_attribute ("nonstring", DECL_ATTRIBUTES (decl)))
15431 : : return decl;
15432 : :
15433 : : return NULL_TREE;
15434 : : }
15435 : :
15436 : : /* Returns an auto_vec of string_slices containing the version strings from
15437 : : ARGLIST. DEFAULT_COUNT is incremented for each default version found.
15438 : : If FILTER is true then any invalid versions strings are not included. */
15439 : :
15440 : : auto_vec<string_slice>
15441 : 202 : get_clone_attr_versions (const tree arglist,
15442 : : int *default_count,
15443 : : bool filter)
15444 : : {
15445 : 202 : gcc_assert (TREE_CODE (arglist) == TREE_LIST);
15446 : 202 : auto_vec<string_slice> versions;
15447 : :
15448 : 202 : static const char separator_str[] = {TARGET_CLONES_ATTR_SEPARATOR, 0};
15449 : 202 : string_slice separators = string_slice (separator_str);
15450 : :
15451 : 740 : for (tree arg = arglist; arg; arg = TREE_CHAIN (arg))
15452 : : {
15453 : 538 : string_slice str = string_slice (TREE_STRING_POINTER (TREE_VALUE (arg)));
15454 : 1642 : while (str.is_valid ())
15455 : : {
15456 : 566 : string_slice attr = string_slice::tokenize (&str, separators);
15457 : 566 : attr = attr.strip ();
15458 : :
15459 : 566 : if (filter && !targetm.check_target_clone_version (attr, NULL))
15460 : 0 : continue;
15461 : :
15462 : 566 : if (attr == "default" && default_count)
15463 : 200 : (*default_count)++;
15464 : 566 : versions.safe_push (attr);
15465 : : }
15466 : : }
15467 : 202 : return versions;
15468 : : }
15469 : :
15470 : : /* Returns an auto_vec of string_slices containing the version strings from
15471 : : the target_clone attribute from DECL. DEFAULT_COUNT is incremented for each
15472 : : default version found. If FILTER is true then any invalid versions strings
15473 : : are not included. */
15474 : : auto_vec<string_slice>
15475 : 94 : get_clone_versions (const tree decl, int *default_count, bool filter)
15476 : : {
15477 : 94 : tree attr = lookup_attribute ("target_clones", DECL_ATTRIBUTES (decl));
15478 : 94 : if (!attr)
15479 : 0 : return auto_vec<string_slice> ();
15480 : 94 : tree arglist = TREE_VALUE (attr);
15481 : 94 : return get_clone_attr_versions (arglist, default_count, filter);
15482 : : }
15483 : :
15484 : : /* If DECL has a target_version attribute, returns a string_slice containing the
15485 : : attribute value. Otherwise, returns string_slice::invalid.
15486 : : Only works for target_version due to target attributes allowing multiple
15487 : : string arguments to specify one target. */
15488 : : string_slice
15489 : 0 : get_target_version (const tree decl)
15490 : : {
15491 : 0 : gcc_assert (!TARGET_HAS_FMV_TARGET_ATTRIBUTE);
15492 : :
15493 : : tree attr = lookup_attribute ("target_version", DECL_ATTRIBUTES (decl));
15494 : :
15495 : : if (!attr)
15496 : : return string_slice::invalid ();
15497 : :
15498 : : return string_slice (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))))
15499 : : .strip ();
15500 : : }
15501 : :
15502 : : /* Returns true if FN1 and FN2 define disjoint function versions in an FMV
15503 : : function set. That is, the two declarations are completely non-overlapping.
15504 : : For target_version semantics, that means if one is a target clone and one is
15505 : : a target version, the target_version must not be defined by the target_clone,
15506 : : and for two target_clones, they must not define any of the same version.
15507 : :
15508 : : FN1 and FN2 should be function decls. */
15509 : :
15510 : : bool
15511 : 29640055 : disjoint_version_decls (tree fn1, tree fn2)
15512 : : {
15513 : 29640055 : if (TREE_CODE (fn1) != FUNCTION_DECL
15514 : 29639076 : || TREE_CODE (fn2) != FUNCTION_DECL)
15515 : : return false;
15516 : :
15517 : 27491093 : if (TARGET_HAS_FMV_TARGET_ATTRIBUTE)
15518 : : {
15519 : 27491093 : tree attr1 = lookup_attribute ("target", DECL_ATTRIBUTES (fn1));
15520 : 27491093 : tree attr2 = lookup_attribute ("target", DECL_ATTRIBUTES (fn2));
15521 : :
15522 : : /* At least one function decl should have the target attribute
15523 : : specified. */
15524 : 27491093 : if (attr1 == NULL_TREE && attr2 == NULL_TREE)
15525 : : return false;
15526 : :
15527 : : /* Diagnose missing target attribute if one of the decls is already
15528 : : multi-versioned. */
15529 : 18570 : if (attr1 == NULL_TREE || attr2 == NULL_TREE)
15530 : : {
15531 : 360 : if (DECL_FUNCTION_VERSIONED (fn1) || DECL_FUNCTION_VERSIONED (fn2))
15532 : : {
15533 : 114 : if (attr2 != NULL_TREE)
15534 : : {
15535 : 114 : std::swap (fn1, fn2);
15536 : 114 : attr1 = attr2;
15537 : : }
15538 : 114 : auto_diagnostic_group d;
15539 : 114 : error_at (DECL_SOURCE_LOCATION (fn2),
15540 : : "missing %<target%> attribute for multi-versioned %qD",
15541 : : fn2);
15542 : 114 : inform (DECL_SOURCE_LOCATION (fn1),
15543 : : "previous declaration of %qD", fn1);
15544 : : /* Prevent diagnosing of the same error multiple times. */
15545 : 114 : DECL_ATTRIBUTES (fn2)
15546 : 228 : = tree_cons (get_identifier ("target"),
15547 : 114 : copy_node (TREE_VALUE (attr1)),
15548 : 114 : DECL_ATTRIBUTES (fn2));
15549 : 114 : }
15550 : 360 : return false;
15551 : : }
15552 : :
15553 : 18210 : char *target1 = sorted_attr_string (TREE_VALUE (attr1));
15554 : 18210 : char *target2 = sorted_attr_string (TREE_VALUE (attr2));
15555 : :
15556 : : /* The sorted target strings must be different for fn1 and fn2
15557 : : to be versions. */
15558 : 18210 : bool result = strcmp (target1, target2) != 0;
15559 : :
15560 : 18210 : XDELETEVEC (target1);
15561 : 18210 : XDELETEVEC (target2);
15562 : :
15563 : 18210 : return result;
15564 : : }
15565 : : else
15566 : : {
15567 : : /* As this is symmetric, can remove the case where fn2 is target clone
15568 : : and fn1 is target version by swapping here. */
15569 : : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn2)))
15570 : : std::swap (fn1, fn2);
15571 : :
15572 : : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn1)))
15573 : : {
15574 : : auto_vec<string_slice> fn1_versions = get_clone_versions (fn1);
15575 : : /* fn1 is target_clone. */
15576 : : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn2)))
15577 : : {
15578 : : /* Both are target_clone. */
15579 : : auto_vec<string_slice> fn2_versions = get_clone_versions (fn2);
15580 : : for (string_slice v1 : fn1_versions)
15581 : : {
15582 : : for (string_slice v2 : fn2_versions)
15583 : : if (targetm.target_option.same_function_versions (v1, v2))
15584 : : return false;
15585 : : }
15586 : : return true;
15587 : : }
15588 : : else
15589 : : {
15590 : : string_slice v2 = get_target_version (fn2);
15591 : :
15592 : : /* target and target_clones is always conflicting for target
15593 : : semantics. */
15594 : : if (TARGET_HAS_FMV_TARGET_ATTRIBUTE)
15595 : : return false;
15596 : :
15597 : : /* Only fn1 is target clone. */
15598 : : if (!v2.is_valid ())
15599 : : v2 = "default";
15600 : : for (string_slice v1 : fn1_versions)
15601 : : if (targetm.target_option.same_function_versions (v1, v2))
15602 : : return false;
15603 : : return true;
15604 : : }
15605 : : }
15606 : : else
15607 : : {
15608 : : /* Both are target_version. */
15609 : : string_slice v1 = get_target_version (fn1);
15610 : : string_slice v2 = get_target_version (fn2);
15611 : :
15612 : : if (!v1.is_valid () && !v2.is_valid ())
15613 : : return false;
15614 : :
15615 : : if (!v1.is_valid ())
15616 : : v1 = "default";
15617 : : if (!v2.is_valid ())
15618 : : v2 = "default";
15619 : :
15620 : : if (targetm.target_option.same_function_versions (v1, v2))
15621 : : return false;
15622 : :
15623 : : return true;
15624 : : }
15625 : : }
15626 : : }
15627 : :
15628 : : /* Check if the target_version/target_clones attributes are mergeable
15629 : : for two decls, and if so returns false.
15630 : : If they aren't mergeable, diagnose this and return true.
15631 : : Only works for target_version semantics. */
15632 : : bool
15633 : 0 : diagnose_versioned_decls (tree old_decl, tree new_decl)
15634 : : {
15635 : 0 : gcc_assert (!TARGET_HAS_FMV_TARGET_ATTRIBUTE);
15636 : :
15637 : : string_slice old_target_attr = get_target_version (old_decl);
15638 : : string_slice new_target_attr = get_target_version (new_decl);
15639 : :
15640 : : tree old_target_clones_attr = lookup_attribute ("target_clones",
15641 : : DECL_ATTRIBUTES (old_decl));
15642 : : tree new_target_clones_attr = lookup_attribute ("target_clones",
15643 : : DECL_ATTRIBUTES (new_decl));
15644 : :
15645 : : /* If none of these are annotated, then it is mergeable. */
15646 : : if (!old_target_attr.is_valid ()
15647 : : && !old_target_attr.is_valid ()
15648 : : && !old_target_clones_attr
15649 : : && !new_target_clones_attr)
15650 : : return false;
15651 : :
15652 : : /* If fn1 is unnanotated and fn2 contains default, then is mergeable. */
15653 : : if (!old_target_attr.is_valid ()
15654 : : && !old_target_clones_attr
15655 : : && is_function_default_version (new_decl))
15656 : : return false;
15657 : :
15658 : : /* If fn2 is unnanotated and fn1 contains default, then is mergeable. */
15659 : : if (!new_target_attr.is_valid ()
15660 : : && !new_target_clones_attr
15661 : : && is_function_default_version (old_decl))
15662 : : return false;
15663 : :
15664 : : /* In the case where both are annotated with target_clones, only mergeable if
15665 : : the two sets of target_clones imply the same set of versions. */
15666 : : if (old_target_clones_attr && new_target_clones_attr)
15667 : : {
15668 : : auto_vec<string_slice> fn1_versions = get_clone_versions (old_decl);
15669 : : auto_vec<string_slice> fn2_versions = get_clone_versions (new_decl);
15670 : :
15671 : : bool mergeable = true;
15672 : :
15673 : : if (fn1_versions.length () != fn2_versions.length ())
15674 : : mergeable = false;
15675 : :
15676 : : /* Check both inclusion directions. */
15677 : : for (auto fn1v : fn1_versions)
15678 : : {
15679 : : bool matched = false;
15680 : : for (auto fn2v : fn2_versions)
15681 : : if (targetm.target_option.same_function_versions (fn1v, fn2v))
15682 : : matched = true;
15683 : : if (!matched)
15684 : : mergeable = false;
15685 : : }
15686 : :
15687 : : for (auto fn2v : fn2_versions)
15688 : : {
15689 : : bool matched = false;
15690 : : for (auto fn1v : fn1_versions)
15691 : : if (targetm.target_option.same_function_versions (fn1v, fn2v))
15692 : : matched = true;
15693 : : if (!matched)
15694 : : mergeable = false;
15695 : : }
15696 : :
15697 : : if (!mergeable)
15698 : : {
15699 : : error_at (DECL_SOURCE_LOCATION (new_decl),
15700 : : "%qD conflicts with overlapping %<target_clone%> "
15701 : : "declaration",
15702 : : new_decl);
15703 : : inform (DECL_SOURCE_LOCATION (old_decl),
15704 : : "previous declaration of %qD", old_decl);
15705 : : return true;
15706 : : }
15707 : :
15708 : : return false;
15709 : : }
15710 : :
15711 : : /* If olddecl is target clones and newdecl is a target_version.
15712 : : As they are not distinct this implies newdecl redefines a version of
15713 : : olddecl. Not mergeable. */
15714 : : if (new_target_clones_attr)
15715 : : {
15716 : : gcc_assert (old_target_attr.is_valid ());
15717 : :
15718 : : error_at (DECL_SOURCE_LOCATION (new_decl),
15719 : : "%qD conflicts for version %qB",
15720 : : new_decl, &old_target_attr);
15721 : : inform (DECL_SOURCE_LOCATION (old_decl),
15722 : : "previous declaration of %qD",
15723 : : old_decl);
15724 : : return true;
15725 : : }
15726 : :
15727 : : if (old_target_clones_attr)
15728 : : {
15729 : : gcc_assert (new_target_attr.is_valid ());
15730 : :
15731 : : error_at (DECL_SOURCE_LOCATION (new_decl),
15732 : : "%qD conflicts with a previous declaration for version %qB",
15733 : : new_decl, &new_target_attr);
15734 : : inform (DECL_SOURCE_LOCATION (old_decl),
15735 : : "previous declaration of %qD",
15736 : : old_decl);
15737 : : return true;
15738 : : }
15739 : :
15740 : : /* The only remaining case is two target_version annotated decls. Must
15741 : : be mergeable as otherwise are distinct. */
15742 : : return false;
15743 : : }
15744 : :
15745 : : void
15746 : 260181 : tree_cc_finalize (void)
15747 : : {
15748 : 260181 : clear_nonstandard_integer_type_cache ();
15749 : 260181 : vec_free (bitint_type_cache);
15750 : 260181 : }
15751 : :
15752 : : void
15753 : 144 : gt_ggc_mx (tree_raw_data *x)
15754 : : {
15755 : 144 : gt_ggc_m_9tree_node (x->typed.type);
15756 : 144 : gt_ggc_m_9tree_node (x->owner);
15757 : 144 : }
15758 : :
15759 : : void
15760 : 12 : gt_pch_nx (tree_raw_data *x)
15761 : : {
15762 : 12 : gt_pch_n_9tree_node (x->typed.type);
15763 : 12 : gt_pch_n_9tree_node (x->owner);
15764 : 12 : }
15765 : :
15766 : : /* For PCH we guarantee that RAW_DATA_CST's RAW_DATA_OWNER is a STRING_CST and
15767 : : RAW_DATA_POINTER points into it. We don't want to save/restore
15768 : : RAW_DATA_POINTER on its own but want to restore it pointing at the same
15769 : : offset of the STRING_CST as before. */
15770 : :
15771 : : void
15772 : 12 : gt_pch_nx (tree_raw_data *x, gt_pointer_operator op, void *cookie)
15773 : : {
15774 : 12 : op (&x->typed.type, NULL, cookie);
15775 : 12 : gcc_checking_assert (x->owner
15776 : : && TREE_CODE (x->owner) == STRING_CST
15777 : : && x->str >= TREE_STRING_POINTER (x->owner)
15778 : : && (x->str + x->length
15779 : : <= (TREE_STRING_POINTER (x->owner)
15780 : : + TREE_STRING_LENGTH (x->owner))));
15781 : 12 : ptrdiff_t off = x->str - (const char *) (x->owner);
15782 : 12 : tree owner = x->owner;
15783 : 12 : op (&x->owner, NULL, cookie);
15784 : 12 : x->owner = owner;
15785 : : /* The above op call relocates x->owner and remembers the address
15786 : : for relocation e.g. if the compiler is position independent.
15787 : : We then restore x->owner back to its previous value and call
15788 : : op again, for x->owner itself this just repeats (uselessly) what
15789 : : the first call did, but as the second argument is now non-NULL
15790 : : and different, it also arranges for &x->str to be noted for the
15791 : : PIE relocation. */
15792 : 12 : op (&x->owner, &x->str, cookie);
15793 : 12 : x->str = (const char *) (x->owner) + off;
15794 : 12 : }
15795 : :
15796 : : #if CHECKING_P
15797 : :
15798 : : namespace selftest {
15799 : :
15800 : : /* Selftests for tree. */
15801 : :
15802 : : /* Verify that integer constants are sane. */
15803 : :
15804 : : static void
15805 : 4 : test_integer_constants ()
15806 : : {
15807 : 4 : ASSERT_TRUE (integer_type_node != NULL);
15808 : 4 : ASSERT_TRUE (build_int_cst (integer_type_node, 0) != NULL);
15809 : :
15810 : 4 : tree type = integer_type_node;
15811 : :
15812 : 4 : tree zero = build_zero_cst (type);
15813 : 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (zero));
15814 : 4 : ASSERT_EQ (type, TREE_TYPE (zero));
15815 : :
15816 : 4 : tree one = build_int_cst (type, 1);
15817 : 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (one));
15818 : 4 : ASSERT_EQ (type, TREE_TYPE (zero));
15819 : 4 : }
15820 : :
15821 : : /* Verify identifiers. */
15822 : :
15823 : : static void
15824 : 4 : test_identifiers ()
15825 : : {
15826 : 4 : tree identifier = get_identifier ("foo");
15827 : 4 : ASSERT_EQ (3, IDENTIFIER_LENGTH (identifier));
15828 : 4 : ASSERT_STREQ ("foo", IDENTIFIER_POINTER (identifier));
15829 : 4 : }
15830 : :
15831 : : /* Verify LABEL_DECL. */
15832 : :
15833 : : static void
15834 : 4 : test_labels ()
15835 : : {
15836 : 4 : tree identifier = get_identifier ("err");
15837 : 4 : tree label_decl = build_decl (UNKNOWN_LOCATION, LABEL_DECL,
15838 : : identifier, void_type_node);
15839 : 4 : ASSERT_EQ (-1, LABEL_DECL_UID (label_decl));
15840 : 4 : ASSERT_FALSE (FORCED_LABEL (label_decl));
15841 : 4 : }
15842 : :
15843 : : /* Return a new VECTOR_CST node whose type is TYPE and whose values
15844 : : are given by VALS. */
15845 : :
15846 : : static tree
15847 : 40 : build_vector (tree type, const vec<tree> &vals MEM_STAT_DECL)
15848 : : {
15849 : 80 : gcc_assert (known_eq (vals.length (), TYPE_VECTOR_SUBPARTS (type)));
15850 : 40 : tree_vector_builder builder (type, vals.length (), 1);
15851 : 40 : builder.splice (vals);
15852 : 40 : return builder.build ();
15853 : 40 : }
15854 : :
15855 : : /* Check that VECTOR_CST ACTUAL contains the elements in EXPECTED. */
15856 : :
15857 : : static void
15858 : 40 : check_vector_cst (const vec<tree> &expected, tree actual)
15859 : : {
15860 : 80 : ASSERT_KNOWN_EQ (expected.length (),
15861 : : TYPE_VECTOR_SUBPARTS (TREE_TYPE (actual)));
15862 : 360 : for (unsigned int i = 0; i < expected.length (); ++i)
15863 : 320 : ASSERT_EQ (wi::to_wide (expected[i]),
15864 : : wi::to_wide (vector_cst_elt (actual, i)));
15865 : 40 : }
15866 : :
15867 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS duplicated elements,
15868 : : and that its elements match EXPECTED. */
15869 : :
15870 : : static void
15871 : 8 : check_vector_cst_duplicate (const vec<tree> &expected, tree actual,
15872 : : unsigned int npatterns)
15873 : : {
15874 : 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15875 : 8 : ASSERT_EQ (1, VECTOR_CST_NELTS_PER_PATTERN (actual));
15876 : 8 : ASSERT_EQ (npatterns, vector_cst_encoded_nelts (actual));
15877 : 8 : ASSERT_TRUE (VECTOR_CST_DUPLICATE_P (actual));
15878 : 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
15879 : 8 : check_vector_cst (expected, actual);
15880 : 8 : }
15881 : :
15882 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS foreground elements
15883 : : and NPATTERNS background elements, and that its elements match
15884 : : EXPECTED. */
15885 : :
15886 : : static void
15887 : 8 : check_vector_cst_fill (const vec<tree> &expected, tree actual,
15888 : : unsigned int npatterns)
15889 : : {
15890 : 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15891 : 8 : ASSERT_EQ (2, VECTOR_CST_NELTS_PER_PATTERN (actual));
15892 : 8 : ASSERT_EQ (2 * npatterns, vector_cst_encoded_nelts (actual));
15893 : 8 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
15894 : 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
15895 : 8 : check_vector_cst (expected, actual);
15896 : 8 : }
15897 : :
15898 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS stepped patterns,
15899 : : and that its elements match EXPECTED. */
15900 : :
15901 : : static void
15902 : 24 : check_vector_cst_stepped (const vec<tree> &expected, tree actual,
15903 : : unsigned int npatterns)
15904 : : {
15905 : 24 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15906 : 24 : ASSERT_EQ (3, VECTOR_CST_NELTS_PER_PATTERN (actual));
15907 : 24 : ASSERT_EQ (3 * npatterns, vector_cst_encoded_nelts (actual));
15908 : 24 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
15909 : 24 : ASSERT_TRUE (VECTOR_CST_STEPPED_P (actual));
15910 : 24 : check_vector_cst (expected, actual);
15911 : 24 : }
15912 : :
15913 : : /* Test the creation of VECTOR_CSTs. */
15914 : :
15915 : : static void
15916 : 4 : test_vector_cst_patterns (ALONE_CXX_MEM_STAT_INFO)
15917 : : {
15918 : 4 : auto_vec<tree, 8> elements (8);
15919 : 4 : elements.quick_grow (8);
15920 : 4 : tree element_type = build_nonstandard_integer_type (16, true);
15921 : 4 : tree vector_type = build_vector_type (element_type, 8);
15922 : :
15923 : : /* Test a simple linear series with a base of 0 and a step of 1:
15924 : : { 0, 1, 2, 3, 4, 5, 6, 7 }. */
15925 : 36 : for (unsigned int i = 0; i < 8; ++i)
15926 : 32 : elements[i] = build_int_cst (element_type, i);
15927 : 4 : tree vector = build_vector (vector_type, elements PASS_MEM_STAT);
15928 : 4 : check_vector_cst_stepped (elements, vector, 1);
15929 : :
15930 : : /* Try the same with the first element replaced by 100:
15931 : : { 100, 1, 2, 3, 4, 5, 6, 7 }. */
15932 : 4 : elements[0] = build_int_cst (element_type, 100);
15933 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15934 : 4 : check_vector_cst_stepped (elements, vector, 1);
15935 : :
15936 : : /* Try a series that wraps around.
15937 : : { 100, 65531, 65532, 65533, 65534, 65535, 0, 1 }. */
15938 : 32 : for (unsigned int i = 1; i < 8; ++i)
15939 : 28 : elements[i] = build_int_cst (element_type, (65530 + i) & 0xffff);
15940 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15941 : 4 : check_vector_cst_stepped (elements, vector, 1);
15942 : :
15943 : : /* Try a downward series:
15944 : : { 100, 79, 78, 77, 76, 75, 75, 73 }. */
15945 : 32 : for (unsigned int i = 1; i < 8; ++i)
15946 : 28 : elements[i] = build_int_cst (element_type, 80 - i);
15947 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15948 : 4 : check_vector_cst_stepped (elements, vector, 1);
15949 : :
15950 : : /* Try two interleaved series with different bases and steps:
15951 : : { 100, 53, 66, 206, 62, 212, 58, 218 }. */
15952 : 4 : elements[1] = build_int_cst (element_type, 53);
15953 : 16 : for (unsigned int i = 2; i < 8; i += 2)
15954 : : {
15955 : 12 : elements[i] = build_int_cst (element_type, 70 - i * 2);
15956 : 12 : elements[i + 1] = build_int_cst (element_type, 200 + i * 3);
15957 : : }
15958 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15959 : 4 : check_vector_cst_stepped (elements, vector, 2);
15960 : :
15961 : : /* Try a duplicated value:
15962 : : { 100, 100, 100, 100, 100, 100, 100, 100 }. */
15963 : 32 : for (unsigned int i = 1; i < 8; ++i)
15964 : 28 : elements[i] = elements[0];
15965 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15966 : 4 : check_vector_cst_duplicate (elements, vector, 1);
15967 : :
15968 : : /* Try an interleaved duplicated value:
15969 : : { 100, 55, 100, 55, 100, 55, 100, 55 }. */
15970 : 4 : elements[1] = build_int_cst (element_type, 55);
15971 : 28 : for (unsigned int i = 2; i < 8; ++i)
15972 : 24 : elements[i] = elements[i - 2];
15973 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15974 : 4 : check_vector_cst_duplicate (elements, vector, 2);
15975 : :
15976 : : /* Try a duplicated value with 2 exceptions
15977 : : { 41, 97, 100, 55, 100, 55, 100, 55 }. */
15978 : 4 : elements[0] = build_int_cst (element_type, 41);
15979 : 4 : elements[1] = build_int_cst (element_type, 97);
15980 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15981 : 4 : check_vector_cst_fill (elements, vector, 2);
15982 : :
15983 : : /* Try with and without a step
15984 : : { 41, 97, 100, 21, 100, 35, 100, 49 }. */
15985 : 16 : for (unsigned int i = 3; i < 8; i += 2)
15986 : 12 : elements[i] = build_int_cst (element_type, i * 7);
15987 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15988 : 4 : check_vector_cst_stepped (elements, vector, 2);
15989 : :
15990 : : /* Try a fully-general constant:
15991 : : { 41, 97, 100, 21, 100, 9990, 100, 49 }. */
15992 : 4 : elements[5] = build_int_cst (element_type, 9990);
15993 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15994 : 4 : check_vector_cst_fill (elements, vector, 4);
15995 : 4 : }
15996 : :
15997 : : /* Verify that STRIP_NOPS (NODE) is EXPECTED.
15998 : : Helper function for test_location_wrappers, to deal with STRIP_NOPS
15999 : : modifying its argument in-place. */
16000 : :
16001 : : static void
16002 : 12 : check_strip_nops (tree node, tree expected)
16003 : : {
16004 : 12 : STRIP_NOPS (node);
16005 : 12 : ASSERT_EQ (expected, node);
16006 : 12 : }
16007 : :
16008 : : /* Verify location wrappers. */
16009 : :
16010 : : static void
16011 : 4 : test_location_wrappers ()
16012 : : {
16013 : 4 : location_t loc = BUILTINS_LOCATION;
16014 : :
16015 : 4 : ASSERT_EQ (NULL_TREE, maybe_wrap_with_location (NULL_TREE, loc));
16016 : :
16017 : : /* Wrapping a constant. */
16018 : 4 : tree int_cst = build_int_cst (integer_type_node, 42);
16019 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_cst));
16020 : 4 : ASSERT_FALSE (location_wrapper_p (int_cst));
16021 : :
16022 : 4 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
16023 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
16024 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_cst));
16025 : 4 : ASSERT_EQ (int_cst, tree_strip_any_location_wrapper (wrapped_int_cst));
16026 : :
16027 : : /* We shouldn't add wrapper nodes for UNKNOWN_LOCATION. */
16028 : 4 : ASSERT_EQ (int_cst, maybe_wrap_with_location (int_cst, UNKNOWN_LOCATION));
16029 : :
16030 : : /* We shouldn't add wrapper nodes for nodes that CAN_HAVE_LOCATION_P. */
16031 : 4 : tree cast = build1 (NOP_EXPR, char_type_node, int_cst);
16032 : 4 : ASSERT_TRUE (CAN_HAVE_LOCATION_P (cast));
16033 : 4 : ASSERT_EQ (cast, maybe_wrap_with_location (cast, loc));
16034 : :
16035 : : /* Wrapping a STRING_CST. */
16036 : 4 : tree string_cst = build_string (4, "foo");
16037 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (string_cst));
16038 : 4 : ASSERT_FALSE (location_wrapper_p (string_cst));
16039 : :
16040 : 4 : tree wrapped_string_cst = maybe_wrap_with_location (string_cst, loc);
16041 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_string_cst));
16042 : 4 : ASSERT_EQ (VIEW_CONVERT_EXPR, TREE_CODE (wrapped_string_cst));
16043 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_string_cst));
16044 : 4 : ASSERT_EQ (string_cst, tree_strip_any_location_wrapper (wrapped_string_cst));
16045 : :
16046 : :
16047 : : /* Wrapping a variable. */
16048 : 4 : tree int_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
16049 : : get_identifier ("some_int_var"),
16050 : : integer_type_node);
16051 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_var));
16052 : 4 : ASSERT_FALSE (location_wrapper_p (int_var));
16053 : :
16054 : 4 : tree wrapped_int_var = maybe_wrap_with_location (int_var, loc);
16055 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_var));
16056 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_var));
16057 : 4 : ASSERT_EQ (int_var, tree_strip_any_location_wrapper (wrapped_int_var));
16058 : :
16059 : : /* Verify that "reinterpret_cast<int>(some_int_var)" is not a location
16060 : : wrapper. */
16061 : 4 : tree r_cast = build1 (NON_LVALUE_EXPR, integer_type_node, int_var);
16062 : 4 : ASSERT_FALSE (location_wrapper_p (r_cast));
16063 : 4 : ASSERT_EQ (r_cast, tree_strip_any_location_wrapper (r_cast));
16064 : :
16065 : : /* Verify that STRIP_NOPS removes wrappers. */
16066 : 4 : check_strip_nops (wrapped_int_cst, int_cst);
16067 : 4 : check_strip_nops (wrapped_string_cst, string_cst);
16068 : 4 : check_strip_nops (wrapped_int_var, int_var);
16069 : 4 : }
16070 : :
16071 : : /* Test various tree predicates. Verify that location wrappers don't
16072 : : affect the results. */
16073 : :
16074 : : static void
16075 : 4 : test_predicates ()
16076 : : {
16077 : : /* Build various constants and wrappers around them. */
16078 : :
16079 : 4 : location_t loc = BUILTINS_LOCATION;
16080 : :
16081 : 4 : tree i_0 = build_int_cst (integer_type_node, 0);
16082 : 4 : tree wr_i_0 = maybe_wrap_with_location (i_0, loc);
16083 : :
16084 : 4 : tree i_1 = build_int_cst (integer_type_node, 1);
16085 : 4 : tree wr_i_1 = maybe_wrap_with_location (i_1, loc);
16086 : :
16087 : 4 : tree i_m1 = build_int_cst (integer_type_node, -1);
16088 : 4 : tree wr_i_m1 = maybe_wrap_with_location (i_m1, loc);
16089 : :
16090 : 4 : tree f_0 = build_real_from_int_cst (float_type_node, i_0);
16091 : 4 : tree wr_f_0 = maybe_wrap_with_location (f_0, loc);
16092 : 4 : tree f_1 = build_real_from_int_cst (float_type_node, i_1);
16093 : 4 : tree wr_f_1 = maybe_wrap_with_location (f_1, loc);
16094 : 4 : tree f_m1 = build_real_from_int_cst (float_type_node, i_m1);
16095 : 4 : tree wr_f_m1 = maybe_wrap_with_location (f_m1, loc);
16096 : :
16097 : 4 : tree c_i_0 = build_complex (NULL_TREE, i_0, i_0);
16098 : 4 : tree c_i_1 = build_complex (NULL_TREE, i_1, i_0);
16099 : 4 : tree c_i_m1 = build_complex (NULL_TREE, i_m1, i_0);
16100 : :
16101 : 4 : tree c_f_0 = build_complex (NULL_TREE, f_0, f_0);
16102 : 4 : tree c_f_1 = build_complex (NULL_TREE, f_1, f_0);
16103 : 4 : tree c_f_m1 = build_complex (NULL_TREE, f_m1, f_0);
16104 : :
16105 : : /* TODO: vector constants. */
16106 : :
16107 : : /* Test integer_onep. */
16108 : 4 : ASSERT_FALSE (integer_onep (i_0));
16109 : 4 : ASSERT_FALSE (integer_onep (wr_i_0));
16110 : 4 : ASSERT_TRUE (integer_onep (i_1));
16111 : 4 : ASSERT_TRUE (integer_onep (wr_i_1));
16112 : 4 : ASSERT_FALSE (integer_onep (i_m1));
16113 : 4 : ASSERT_FALSE (integer_onep (wr_i_m1));
16114 : 4 : ASSERT_FALSE (integer_onep (f_0));
16115 : 4 : ASSERT_FALSE (integer_onep (wr_f_0));
16116 : 4 : ASSERT_FALSE (integer_onep (f_1));
16117 : 4 : ASSERT_FALSE (integer_onep (wr_f_1));
16118 : 4 : ASSERT_FALSE (integer_onep (f_m1));
16119 : 4 : ASSERT_FALSE (integer_onep (wr_f_m1));
16120 : 4 : ASSERT_FALSE (integer_onep (c_i_0));
16121 : 4 : ASSERT_TRUE (integer_onep (c_i_1));
16122 : 4 : ASSERT_FALSE (integer_onep (c_i_m1));
16123 : 4 : ASSERT_FALSE (integer_onep (c_f_0));
16124 : 4 : ASSERT_FALSE (integer_onep (c_f_1));
16125 : 4 : ASSERT_FALSE (integer_onep (c_f_m1));
16126 : :
16127 : : /* Test integer_zerop. */
16128 : 4 : ASSERT_TRUE (integer_zerop (i_0));
16129 : 4 : ASSERT_TRUE (integer_zerop (wr_i_0));
16130 : 4 : ASSERT_FALSE (integer_zerop (i_1));
16131 : 4 : ASSERT_FALSE (integer_zerop (wr_i_1));
16132 : 4 : ASSERT_FALSE (integer_zerop (i_m1));
16133 : 4 : ASSERT_FALSE (integer_zerop (wr_i_m1));
16134 : 4 : ASSERT_FALSE (integer_zerop (f_0));
16135 : 4 : ASSERT_FALSE (integer_zerop (wr_f_0));
16136 : 4 : ASSERT_FALSE (integer_zerop (f_1));
16137 : 4 : ASSERT_FALSE (integer_zerop (wr_f_1));
16138 : 4 : ASSERT_FALSE (integer_zerop (f_m1));
16139 : 4 : ASSERT_FALSE (integer_zerop (wr_f_m1));
16140 : 4 : ASSERT_TRUE (integer_zerop (c_i_0));
16141 : 4 : ASSERT_FALSE (integer_zerop (c_i_1));
16142 : 4 : ASSERT_FALSE (integer_zerop (c_i_m1));
16143 : 4 : ASSERT_FALSE (integer_zerop (c_f_0));
16144 : 4 : ASSERT_FALSE (integer_zerop (c_f_1));
16145 : 4 : ASSERT_FALSE (integer_zerop (c_f_m1));
16146 : :
16147 : : /* Test integer_all_onesp. */
16148 : 4 : ASSERT_FALSE (integer_all_onesp (i_0));
16149 : 4 : ASSERT_FALSE (integer_all_onesp (wr_i_0));
16150 : 4 : ASSERT_FALSE (integer_all_onesp (i_1));
16151 : 4 : ASSERT_FALSE (integer_all_onesp (wr_i_1));
16152 : 4 : ASSERT_TRUE (integer_all_onesp (i_m1));
16153 : 4 : ASSERT_TRUE (integer_all_onesp (wr_i_m1));
16154 : 4 : ASSERT_FALSE (integer_all_onesp (f_0));
16155 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_0));
16156 : 4 : ASSERT_FALSE (integer_all_onesp (f_1));
16157 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_1));
16158 : 4 : ASSERT_FALSE (integer_all_onesp (f_m1));
16159 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_m1));
16160 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_0));
16161 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_1));
16162 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_m1));
16163 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_0));
16164 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_1));
16165 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_m1));
16166 : :
16167 : : /* Test integer_minus_onep. */
16168 : 4 : ASSERT_FALSE (integer_minus_onep (i_0));
16169 : 4 : ASSERT_FALSE (integer_minus_onep (wr_i_0));
16170 : 4 : ASSERT_FALSE (integer_minus_onep (i_1));
16171 : 4 : ASSERT_FALSE (integer_minus_onep (wr_i_1));
16172 : 4 : ASSERT_TRUE (integer_minus_onep (i_m1));
16173 : 4 : ASSERT_TRUE (integer_minus_onep (wr_i_m1));
16174 : 4 : ASSERT_FALSE (integer_minus_onep (f_0));
16175 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_0));
16176 : 4 : ASSERT_FALSE (integer_minus_onep (f_1));
16177 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_1));
16178 : 4 : ASSERT_FALSE (integer_minus_onep (f_m1));
16179 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_m1));
16180 : 4 : ASSERT_FALSE (integer_minus_onep (c_i_0));
16181 : 4 : ASSERT_FALSE (integer_minus_onep (c_i_1));
16182 : 4 : ASSERT_TRUE (integer_minus_onep (c_i_m1));
16183 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_0));
16184 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_1));
16185 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_m1));
16186 : :
16187 : : /* Test integer_each_onep. */
16188 : 4 : ASSERT_FALSE (integer_each_onep (i_0));
16189 : 4 : ASSERT_FALSE (integer_each_onep (wr_i_0));
16190 : 4 : ASSERT_TRUE (integer_each_onep (i_1));
16191 : 4 : ASSERT_TRUE (integer_each_onep (wr_i_1));
16192 : 4 : ASSERT_FALSE (integer_each_onep (i_m1));
16193 : 4 : ASSERT_FALSE (integer_each_onep (wr_i_m1));
16194 : 4 : ASSERT_FALSE (integer_each_onep (f_0));
16195 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_0));
16196 : 4 : ASSERT_FALSE (integer_each_onep (f_1));
16197 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_1));
16198 : 4 : ASSERT_FALSE (integer_each_onep (f_m1));
16199 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_m1));
16200 : 4 : ASSERT_FALSE (integer_each_onep (c_i_0));
16201 : 4 : ASSERT_FALSE (integer_each_onep (c_i_1));
16202 : 4 : ASSERT_FALSE (integer_each_onep (c_i_m1));
16203 : 4 : ASSERT_FALSE (integer_each_onep (c_f_0));
16204 : 4 : ASSERT_FALSE (integer_each_onep (c_f_1));
16205 : 4 : ASSERT_FALSE (integer_each_onep (c_f_m1));
16206 : :
16207 : : /* Test integer_truep. */
16208 : 4 : ASSERT_FALSE (integer_truep (i_0));
16209 : 4 : ASSERT_FALSE (integer_truep (wr_i_0));
16210 : 4 : ASSERT_TRUE (integer_truep (i_1));
16211 : 4 : ASSERT_TRUE (integer_truep (wr_i_1));
16212 : 4 : ASSERT_FALSE (integer_truep (i_m1));
16213 : 4 : ASSERT_FALSE (integer_truep (wr_i_m1));
16214 : 4 : ASSERT_FALSE (integer_truep (f_0));
16215 : 4 : ASSERT_FALSE (integer_truep (wr_f_0));
16216 : 4 : ASSERT_FALSE (integer_truep (f_1));
16217 : 4 : ASSERT_FALSE (integer_truep (wr_f_1));
16218 : 4 : ASSERT_FALSE (integer_truep (f_m1));
16219 : 4 : ASSERT_FALSE (integer_truep (wr_f_m1));
16220 : 4 : ASSERT_FALSE (integer_truep (c_i_0));
16221 : 4 : ASSERT_TRUE (integer_truep (c_i_1));
16222 : 4 : ASSERT_FALSE (integer_truep (c_i_m1));
16223 : 4 : ASSERT_FALSE (integer_truep (c_f_0));
16224 : 4 : ASSERT_FALSE (integer_truep (c_f_1));
16225 : 4 : ASSERT_FALSE (integer_truep (c_f_m1));
16226 : :
16227 : : /* Test integer_nonzerop. */
16228 : 4 : ASSERT_FALSE (integer_nonzerop (i_0));
16229 : 4 : ASSERT_FALSE (integer_nonzerop (wr_i_0));
16230 : 4 : ASSERT_TRUE (integer_nonzerop (i_1));
16231 : 4 : ASSERT_TRUE (integer_nonzerop (wr_i_1));
16232 : 4 : ASSERT_TRUE (integer_nonzerop (i_m1));
16233 : 4 : ASSERT_TRUE (integer_nonzerop (wr_i_m1));
16234 : 4 : ASSERT_FALSE (integer_nonzerop (f_0));
16235 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_0));
16236 : 4 : ASSERT_FALSE (integer_nonzerop (f_1));
16237 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_1));
16238 : 4 : ASSERT_FALSE (integer_nonzerop (f_m1));
16239 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_m1));
16240 : 4 : ASSERT_FALSE (integer_nonzerop (c_i_0));
16241 : 4 : ASSERT_TRUE (integer_nonzerop (c_i_1));
16242 : 4 : ASSERT_TRUE (integer_nonzerop (c_i_m1));
16243 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_0));
16244 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_1));
16245 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_m1));
16246 : :
16247 : : /* Test real_zerop. */
16248 : 4 : ASSERT_FALSE (real_zerop (i_0));
16249 : 4 : ASSERT_FALSE (real_zerop (wr_i_0));
16250 : 4 : ASSERT_FALSE (real_zerop (i_1));
16251 : 4 : ASSERT_FALSE (real_zerop (wr_i_1));
16252 : 4 : ASSERT_FALSE (real_zerop (i_m1));
16253 : 4 : ASSERT_FALSE (real_zerop (wr_i_m1));
16254 : 4 : ASSERT_TRUE (real_zerop (f_0));
16255 : 4 : ASSERT_TRUE (real_zerop (wr_f_0));
16256 : 4 : ASSERT_FALSE (real_zerop (f_1));
16257 : 4 : ASSERT_FALSE (real_zerop (wr_f_1));
16258 : 4 : ASSERT_FALSE (real_zerop (f_m1));
16259 : 4 : ASSERT_FALSE (real_zerop (wr_f_m1));
16260 : 4 : ASSERT_FALSE (real_zerop (c_i_0));
16261 : 4 : ASSERT_FALSE (real_zerop (c_i_1));
16262 : 4 : ASSERT_FALSE (real_zerop (c_i_m1));
16263 : 4 : ASSERT_TRUE (real_zerop (c_f_0));
16264 : 4 : ASSERT_FALSE (real_zerop (c_f_1));
16265 : 4 : ASSERT_FALSE (real_zerop (c_f_m1));
16266 : :
16267 : : /* Test real_onep. */
16268 : 4 : ASSERT_FALSE (real_onep (i_0));
16269 : 4 : ASSERT_FALSE (real_onep (wr_i_0));
16270 : 4 : ASSERT_FALSE (real_onep (i_1));
16271 : 4 : ASSERT_FALSE (real_onep (wr_i_1));
16272 : 4 : ASSERT_FALSE (real_onep (i_m1));
16273 : 4 : ASSERT_FALSE (real_onep (wr_i_m1));
16274 : 4 : ASSERT_FALSE (real_onep (f_0));
16275 : 4 : ASSERT_FALSE (real_onep (wr_f_0));
16276 : 4 : ASSERT_TRUE (real_onep (f_1));
16277 : 4 : ASSERT_TRUE (real_onep (wr_f_1));
16278 : 4 : ASSERT_FALSE (real_onep (f_m1));
16279 : 4 : ASSERT_FALSE (real_onep (wr_f_m1));
16280 : 4 : ASSERT_FALSE (real_onep (c_i_0));
16281 : 4 : ASSERT_FALSE (real_onep (c_i_1));
16282 : 4 : ASSERT_FALSE (real_onep (c_i_m1));
16283 : 4 : ASSERT_FALSE (real_onep (c_f_0));
16284 : 4 : ASSERT_TRUE (real_onep (c_f_1));
16285 : 4 : ASSERT_FALSE (real_onep (c_f_m1));
16286 : :
16287 : : /* Test real_minus_onep. */
16288 : 4 : ASSERT_FALSE (real_minus_onep (i_0));
16289 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_0));
16290 : 4 : ASSERT_FALSE (real_minus_onep (i_1));
16291 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_1));
16292 : 4 : ASSERT_FALSE (real_minus_onep (i_m1));
16293 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_m1));
16294 : 4 : ASSERT_FALSE (real_minus_onep (f_0));
16295 : 4 : ASSERT_FALSE (real_minus_onep (wr_f_0));
16296 : 4 : ASSERT_FALSE (real_minus_onep (f_1));
16297 : 4 : ASSERT_FALSE (real_minus_onep (wr_f_1));
16298 : 4 : ASSERT_TRUE (real_minus_onep (f_m1));
16299 : 4 : ASSERT_TRUE (real_minus_onep (wr_f_m1));
16300 : 4 : ASSERT_FALSE (real_minus_onep (c_i_0));
16301 : 4 : ASSERT_FALSE (real_minus_onep (c_i_1));
16302 : 4 : ASSERT_FALSE (real_minus_onep (c_i_m1));
16303 : 4 : ASSERT_FALSE (real_minus_onep (c_f_0));
16304 : 4 : ASSERT_FALSE (real_minus_onep (c_f_1));
16305 : 4 : ASSERT_TRUE (real_minus_onep (c_f_m1));
16306 : :
16307 : : /* Test zerop. */
16308 : 4 : ASSERT_TRUE (zerop (i_0));
16309 : 4 : ASSERT_TRUE (zerop (wr_i_0));
16310 : 4 : ASSERT_FALSE (zerop (i_1));
16311 : 4 : ASSERT_FALSE (zerop (wr_i_1));
16312 : 4 : ASSERT_FALSE (zerop (i_m1));
16313 : 4 : ASSERT_FALSE (zerop (wr_i_m1));
16314 : 4 : ASSERT_TRUE (zerop (f_0));
16315 : 4 : ASSERT_TRUE (zerop (wr_f_0));
16316 : 4 : ASSERT_FALSE (zerop (f_1));
16317 : 4 : ASSERT_FALSE (zerop (wr_f_1));
16318 : 4 : ASSERT_FALSE (zerop (f_m1));
16319 : 4 : ASSERT_FALSE (zerop (wr_f_m1));
16320 : 4 : ASSERT_TRUE (zerop (c_i_0));
16321 : 4 : ASSERT_FALSE (zerop (c_i_1));
16322 : 4 : ASSERT_FALSE (zerop (c_i_m1));
16323 : 4 : ASSERT_TRUE (zerop (c_f_0));
16324 : 4 : ASSERT_FALSE (zerop (c_f_1));
16325 : 4 : ASSERT_FALSE (zerop (c_f_m1));
16326 : :
16327 : : /* Test tree_expr_nonnegative_p. */
16328 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_0));
16329 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_0));
16330 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_1));
16331 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_1));
16332 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (i_m1));
16333 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_i_m1));
16334 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_0));
16335 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_0));
16336 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_1));
16337 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_1));
16338 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (f_m1));
16339 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_f_m1));
16340 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_0));
16341 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_1));
16342 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_m1));
16343 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_0));
16344 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_1));
16345 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_m1));
16346 : :
16347 : : /* Test tree_expr_nonzero_p. */
16348 : 4 : ASSERT_FALSE (tree_expr_nonzero_p (i_0));
16349 : 4 : ASSERT_FALSE (tree_expr_nonzero_p (wr_i_0));
16350 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_1));
16351 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_1));
16352 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_m1));
16353 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_m1));
16354 : :
16355 : : /* Test integer_valued_real_p. */
16356 : 4 : ASSERT_FALSE (integer_valued_real_p (i_0));
16357 : 4 : ASSERT_TRUE (integer_valued_real_p (f_0));
16358 : 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_0));
16359 : 4 : ASSERT_TRUE (integer_valued_real_p (f_1));
16360 : 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_1));
16361 : :
16362 : : /* Test integer_pow2p. */
16363 : 4 : ASSERT_FALSE (integer_pow2p (i_0));
16364 : 4 : ASSERT_TRUE (integer_pow2p (i_1));
16365 : 4 : ASSERT_TRUE (integer_pow2p (wr_i_1));
16366 : :
16367 : : /* Test uniform_integer_cst_p. */
16368 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_0));
16369 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_0));
16370 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_1));
16371 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_1));
16372 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_m1));
16373 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_m1));
16374 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_0));
16375 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_0));
16376 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_1));
16377 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_1));
16378 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_m1));
16379 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_m1));
16380 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_0));
16381 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_1));
16382 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_m1));
16383 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_0));
16384 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_1));
16385 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_m1));
16386 : 4 : }
16387 : :
16388 : : /* Check that string escaping works correctly. */
16389 : :
16390 : : static void
16391 : 4 : test_escaped_strings (void)
16392 : : {
16393 : 4 : int saved_cutoff;
16394 : 4 : escaped_string msg;
16395 : :
16396 : 4 : msg.escape (NULL);
16397 : : /* ASSERT_STREQ does not accept NULL as a valid test
16398 : : result, so we have to use ASSERT_EQ instead. */
16399 : 4 : ASSERT_EQ (NULL, (const char *) msg);
16400 : :
16401 : 4 : msg.escape ("");
16402 : 4 : ASSERT_STREQ ("", (const char *) msg);
16403 : :
16404 : 4 : msg.escape ("foobar");
16405 : 4 : ASSERT_STREQ ("foobar", (const char *) msg);
16406 : :
16407 : : /* Ensure that we have -fmessage-length set to 0. */
16408 : 4 : pretty_printer *pp = global_dc->get_reference_printer ();
16409 : 4 : saved_cutoff = pp_line_cutoff (pp);
16410 : 4 : pp_line_cutoff (pp) = 0;
16411 : :
16412 : 4 : msg.escape ("foo\nbar");
16413 : 4 : ASSERT_STREQ ("foo\\nbar", (const char *) msg);
16414 : :
16415 : 4 : msg.escape ("\a\b\f\n\r\t\v");
16416 : 4 : ASSERT_STREQ ("\\a\\b\\f\\n\\r\\t\\v", (const char *) msg);
16417 : :
16418 : : /* Now repeat the tests with -fmessage-length set to 5. */
16419 : 4 : pp_line_cutoff (pp) = 5;
16420 : :
16421 : : /* Note that the newline is not translated into an escape. */
16422 : 4 : msg.escape ("foo\nbar");
16423 : 4 : ASSERT_STREQ ("foo\nbar", (const char *) msg);
16424 : :
16425 : 4 : msg.escape ("\a\b\f\n\r\t\v");
16426 : 4 : ASSERT_STREQ ("\\a\\b\\f\n\\r\\t\\v", (const char *) msg);
16427 : :
16428 : : /* Restore the original message length setting. */
16429 : 4 : pp_line_cutoff (pp) = saved_cutoff;
16430 : 4 : }
16431 : :
16432 : : /* Run all of the selftests within this file. */
16433 : :
16434 : : void
16435 : 4 : tree_cc_tests ()
16436 : : {
16437 : 4 : test_integer_constants ();
16438 : 4 : test_identifiers ();
16439 : 4 : test_labels ();
16440 : 4 : test_vector_cst_patterns ();
16441 : 4 : test_location_wrappers ();
16442 : 4 : test_predicates ();
16443 : 4 : test_escaped_strings ();
16444 : 4 : }
16445 : :
16446 : : } // namespace selftest
16447 : :
16448 : : #endif /* CHECKING_P */
16449 : :
16450 : : #include "gt-tree.h"
|