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 : 7279000834 : 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 : 1743075125 : keep_cache_entry (type_hash *&t)
165 : : {
166 : 1743075125 : 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 : 721840 : 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 : 14735221 : gt_value_expr_mark_2 (tree *tp, int *, void *data)
228 : : {
229 : 14735221 : tree t = *tp;
230 : 14735221 : 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 : 14735221 : return NULL_TREE;
238 : : }
239 : :
240 : : /* Callback called through traverse_noresize on the
241 : : value_expr_for_decl hash table. */
242 : :
243 : : int
244 : 6120510 : gt_value_expr_mark_1 (tree_decl_map **e, gt_value_expr_mark_data *data)
245 : : {
246 : 6120510 : if (ggc_marked_p ((*e)->base.from))
247 : 5279976 : walk_tree_1 (&(*e)->to, gt_value_expr_mark_2, data, &data->pset, NULL);
248 : 6120510 : 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 : 721840 : gt_value_expr_mark (hash_table<tree_decl_map_cache_hasher> *h)
263 : : {
264 : 721840 : if (!h)
265 : 0 : return;
266 : :
267 : 721840 : gt_value_expr_mark_data data;
268 : 721840 : h->traverse_noresize<gt_value_expr_mark_data *,
269 : 6842350 : gt_value_expr_mark_1> (&data);
270 : 2166559 : for (auto v : data.to_mark)
271 : 1039 : gt_ggc_mx (v);
272 : 721840 : }
273 : :
274 : : /* General tree->tree mapping structure for use in hash tables. */
275 : :
276 : :
277 : : static GTY ((cache))
278 : : hash_table<tree_decl_map_cache_hasher> *debug_expr_for_decl;
279 : :
280 : : static GTY ((cache ("gt_value_expr_mark")))
281 : : hash_table<tree_decl_map_cache_hasher> *value_expr_for_decl;
282 : :
283 : : static GTY ((cache))
284 : : hash_table<tree_vec_map_cache_hasher> *debug_args_for_decl;
285 : :
286 : : static void set_type_quals (tree, int);
287 : : static void print_type_hash_statistics (void);
288 : : static void print_debug_expr_statistics (void);
289 : : static void print_value_expr_statistics (void);
290 : :
291 : : tree global_trees[TI_MAX];
292 : : tree integer_types[itk_none];
293 : :
294 : : bool int_n_enabled_p[NUM_INT_N_ENTS];
295 : : struct int_n_trees_t int_n_trees [NUM_INT_N_ENTS];
296 : :
297 : : bool tree_contains_struct[MAX_TREE_CODES][64];
298 : :
299 : : /* Number of operands for each OMP clause. */
300 : : unsigned const char omp_clause_num_ops[] =
301 : : {
302 : : 0, /* OMP_CLAUSE_ERROR */
303 : : 1, /* OMP_CLAUSE_PRIVATE */
304 : : 1, /* OMP_CLAUSE_SHARED */
305 : : 1, /* OMP_CLAUSE_FIRSTPRIVATE */
306 : : 2, /* OMP_CLAUSE_LASTPRIVATE */
307 : : 5, /* OMP_CLAUSE_REDUCTION */
308 : : 5, /* OMP_CLAUSE_TASK_REDUCTION */
309 : : 5, /* OMP_CLAUSE_IN_REDUCTION */
310 : : 1, /* OMP_CLAUSE_COPYIN */
311 : : 1, /* OMP_CLAUSE_COPYPRIVATE */
312 : : 3, /* OMP_CLAUSE_LINEAR */
313 : : 1, /* OMP_CLAUSE_AFFINITY */
314 : : 2, /* OMP_CLAUSE_ALIGNED */
315 : : 3, /* OMP_CLAUSE_ALLOCATE */
316 : : 1, /* OMP_CLAUSE_DEPEND */
317 : : 1, /* OMP_CLAUSE_NONTEMPORAL */
318 : : 1, /* OMP_CLAUSE_UNIFORM */
319 : : 1, /* OMP_CLAUSE_ENTER */
320 : : 1, /* OMP_CLAUSE_LINK */
321 : : 1, /* OMP_CLAUSE_DETACH */
322 : : 1, /* OMP_CLAUSE_USE_DEVICE_PTR */
323 : : 1, /* OMP_CLAUSE_USE_DEVICE_ADDR */
324 : : 1, /* OMP_CLAUSE_IS_DEVICE_PTR */
325 : : 1, /* OMP_CLAUSE_INCLUSIVE */
326 : : 1, /* OMP_CLAUSE_EXCLUSIVE */
327 : : 3, /* OMP_CLAUSE_FROM */
328 : : 3, /* OMP_CLAUSE_TO */
329 : : 3, /* OMP_CLAUSE_MAP (update walk_tree_1 if this is changed) */
330 : : 1, /* OMP_CLAUSE_HAS_DEVICE_ADDR */
331 : : 1, /* OMP_CLAUSE_DOACROSS */
332 : : 3, /* OMP_CLAUSE__MAPPER_BINDING_ */
333 : : 2, /* OMP_CLAUSE__CACHE_ */
334 : : 1, /* OMP_CLAUSE_DESTROY */
335 : : 2, /* OMP_CLAUSE_INIT */
336 : : 1, /* OMP_CLAUSE_USE */
337 : : 1, /* OMP_CLAUSE_INTEROP */
338 : : 2, /* OMP_CLAUSE_GANG */
339 : : 1, /* OMP_CLAUSE_ASYNC */
340 : : 1, /* OMP_CLAUSE_WAIT */
341 : : 0, /* OMP_CLAUSE_AUTO */
342 : : 0, /* OMP_CLAUSE_SEQ */
343 : : 1, /* OMP_CLAUSE__LOOPTEMP_ */
344 : : 1, /* OMP_CLAUSE__REDUCTEMP_ */
345 : : 1, /* OMP_CLAUSE__CONDTEMP_ */
346 : : 1, /* OMP_CLAUSE__SCANTEMP_ */
347 : : 1, /* OMP_CLAUSE_IF */
348 : : 1, /* OMP_CLAUSE_SELF */
349 : : 1, /* OMP_CLAUSE_NUM_THREADS */
350 : : 1, /* OMP_CLAUSE_SCHEDULE */
351 : : 0, /* OMP_CLAUSE_NOWAIT */
352 : : 1, /* OMP_CLAUSE_ORDERED */
353 : : 0, /* OMP_CLAUSE_DEFAULT */
354 : : 3, /* OMP_CLAUSE_COLLAPSE */
355 : : 0, /* OMP_CLAUSE_UNTIED */
356 : : 1, /* OMP_CLAUSE_FINAL */
357 : : 0, /* OMP_CLAUSE_MERGEABLE */
358 : : 1, /* OMP_CLAUSE_DEVICE */
359 : : 1, /* OMP_CLAUSE_DIST_SCHEDULE */
360 : : 0, /* OMP_CLAUSE_INBRANCH */
361 : : 0, /* OMP_CLAUSE_NOTINBRANCH */
362 : : 2, /* OMP_CLAUSE_NUM_TEAMS */
363 : : 1, /* OMP_CLAUSE_THREAD_LIMIT */
364 : : 0, /* OMP_CLAUSE_PROC_BIND */
365 : : 1, /* OMP_CLAUSE_SAFELEN */
366 : : 1, /* OMP_CLAUSE_SIMDLEN */
367 : : 0, /* OMP_CLAUSE_DEVICE_TYPE */
368 : : 0, /* OMP_CLAUSE_FOR */
369 : : 0, /* OMP_CLAUSE_PARALLEL */
370 : : 0, /* OMP_CLAUSE_SECTIONS */
371 : : 0, /* OMP_CLAUSE_TASKGROUP */
372 : : 1, /* OMP_CLAUSE_PRIORITY */
373 : : 1, /* OMP_CLAUSE_GRAINSIZE */
374 : : 1, /* OMP_CLAUSE_NUM_TASKS */
375 : : 0, /* OMP_CLAUSE_NOGROUP */
376 : : 0, /* OMP_CLAUSE_THREADS */
377 : : 0, /* OMP_CLAUSE_SIMD */
378 : : 1, /* OMP_CLAUSE_HINT */
379 : : 0, /* OMP_CLAUSE_DEFAULTMAP */
380 : : 0, /* OMP_CLAUSE_ORDER */
381 : : 0, /* OMP_CLAUSE_BIND */
382 : : 1, /* OMP_CLAUSE_FILTER */
383 : : 1, /* OMP_CLAUSE_INDIRECT */
384 : : 1, /* OMP_CLAUSE_PARTIAL */
385 : : 0, /* OMP_CLAUSE_FULL */
386 : : 1, /* OMP_CLAUSE_SIZES */
387 : : 1, /* OMP_CLAUSE__SIMDUID_ */
388 : : 0, /* OMP_CLAUSE__SIMT_ */
389 : : 0, /* OMP_CLAUSE_INDEPENDENT */
390 : : 1, /* OMP_CLAUSE_WORKER */
391 : : 1, /* OMP_CLAUSE_VECTOR */
392 : : 1, /* OMP_CLAUSE_NUM_GANGS */
393 : : 1, /* OMP_CLAUSE_NUM_WORKERS */
394 : : 1, /* OMP_CLAUSE_VECTOR_LENGTH */
395 : : 3, /* OMP_CLAUSE_TILE */
396 : : 0, /* OMP_CLAUSE_IF_PRESENT */
397 : : 0, /* OMP_CLAUSE_FINALIZE */
398 : : 0, /* OMP_CLAUSE_NOHOST */
399 : : 1, /* OMP_CLAUSE_NOVARIANTS */
400 : : 1, /* OMP_CLAUSE_NOCONTEXT */
401 : : 1, /* OMP_CLAUSE_DYN_GROUPPRIVATE */
402 : : };
403 : :
404 : : const char * const omp_clause_code_name[] =
405 : : {
406 : : "error_clause",
407 : : "private",
408 : : "shared",
409 : : "firstprivate",
410 : : "lastprivate",
411 : : "reduction",
412 : : "task_reduction",
413 : : "in_reduction",
414 : : "copyin",
415 : : "copyprivate",
416 : : "linear",
417 : : "affinity",
418 : : "aligned",
419 : : "allocate",
420 : : "depend",
421 : : "nontemporal",
422 : : "uniform",
423 : : "enter",
424 : : "link",
425 : : "detach",
426 : : "use_device_ptr",
427 : : "use_device_addr",
428 : : "is_device_ptr",
429 : : "inclusive",
430 : : "exclusive",
431 : : "from",
432 : : "to",
433 : : "map",
434 : : "has_device_addr",
435 : : "doacross",
436 : : "_mapper_binding_",
437 : : "_cache_",
438 : : "destroy",
439 : : "init",
440 : : "use",
441 : : "interop",
442 : : "gang",
443 : : "async",
444 : : "wait",
445 : : "auto",
446 : : "seq",
447 : : "_looptemp_",
448 : : "_reductemp_",
449 : : "_condtemp_",
450 : : "_scantemp_",
451 : : "if",
452 : : "self",
453 : : "num_threads",
454 : : "schedule",
455 : : "nowait",
456 : : "ordered",
457 : : "default",
458 : : "collapse",
459 : : "untied",
460 : : "final",
461 : : "mergeable",
462 : : "device",
463 : : "dist_schedule",
464 : : "inbranch",
465 : : "notinbranch",
466 : : "num_teams",
467 : : "thread_limit",
468 : : "proc_bind",
469 : : "safelen",
470 : : "simdlen",
471 : : "device_type",
472 : : "for",
473 : : "parallel",
474 : : "sections",
475 : : "taskgroup",
476 : : "priority",
477 : : "grainsize",
478 : : "num_tasks",
479 : : "nogroup",
480 : : "threads",
481 : : "simd",
482 : : "hint",
483 : : "defaultmap",
484 : : "order",
485 : : "bind",
486 : : "filter",
487 : : "indirect",
488 : : "partial",
489 : : "full",
490 : : "sizes",
491 : : "_simduid_",
492 : : "_simt_",
493 : : "independent",
494 : : "worker",
495 : : "vector",
496 : : "num_gangs",
497 : : "num_workers",
498 : : "vector_length",
499 : : "tile",
500 : : "if_present",
501 : : "finalize",
502 : : "nohost",
503 : : "novariants",
504 : : "nocontext",
505 : : "dyn_groupprivate",
506 : : };
507 : :
508 : : /* Unless specific to OpenACC, we tend to internally maintain OpenMP-centric
509 : : clause names, but for use in diagnostics etc. would like to use the "user"
510 : : clause names. */
511 : :
512 : : const char *
513 : 445 : user_omp_clause_code_name (tree clause, bool oacc)
514 : : {
515 : : /* For OpenACC, the 'OMP_CLAUSE_MAP_KIND' of an 'OMP_CLAUSE_MAP' is used to
516 : : distinguish clauses as seen by the user. See also where front ends do
517 : : 'build_omp_clause' with 'OMP_CLAUSE_MAP'. */
518 : 890 : if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP)
519 : 445 : switch (OMP_CLAUSE_MAP_KIND (clause))
520 : : {
521 : : case GOMP_MAP_FORCE_ALLOC:
522 : : case GOMP_MAP_ALLOC: return "create";
523 : 0 : case GOMP_MAP_FORCE_TO:
524 : 0 : case GOMP_MAP_TO: return "copyin";
525 : 0 : case GOMP_MAP_FORCE_FROM:
526 : 0 : case GOMP_MAP_FROM: return "copyout";
527 : 361 : case GOMP_MAP_FORCE_TOFROM:
528 : 361 : case GOMP_MAP_TOFROM: return "copy";
529 : 0 : case GOMP_MAP_RELEASE: return "delete";
530 : 0 : case GOMP_MAP_FORCE_PRESENT: return "present";
531 : 42 : case GOMP_MAP_ATTACH: return "attach";
532 : 42 : case GOMP_MAP_FORCE_DETACH:
533 : 42 : case GOMP_MAP_DETACH: return "detach";
534 : 0 : case GOMP_MAP_DEVICE_RESIDENT: return "device_resident";
535 : 0 : case GOMP_MAP_LINK: return "link";
536 : 0 : case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr";
537 : : default: break;
538 : : }
539 : :
540 : 0 : return omp_clause_code_name[OMP_CLAUSE_CODE (clause)];
541 : : }
542 : :
543 : :
544 : : /* Return the tree node structure used by tree code CODE. */
545 : :
546 : : static inline enum tree_node_structure_enum
547 : 37633645918 : tree_node_structure_for_code (enum tree_code code)
548 : : {
549 : 37633645918 : switch (TREE_CODE_CLASS (code))
550 : : {
551 : 9370773831 : case tcc_declaration:
552 : 9370773831 : switch (code)
553 : : {
554 : : case CONST_DECL: return TS_CONST_DECL;
555 : : case DEBUG_EXPR_DECL: return TS_DECL_WRTL;
556 : : case FIELD_DECL: return TS_FIELD_DECL;
557 : : case FUNCTION_DECL: return TS_FUNCTION_DECL;
558 : : case LABEL_DECL: return TS_LABEL_DECL;
559 : : case PARM_DECL: return TS_PARM_DECL;
560 : : case RESULT_DECL: return TS_RESULT_DECL;
561 : : case TRANSLATION_UNIT_DECL: return TS_TRANSLATION_UNIT_DECL;
562 : : case TYPE_DECL: return TS_TYPE_DECL;
563 : : case VAR_DECL: return TS_VAR_DECL;
564 : : default: return TS_DECL_NON_COMMON;
565 : : }
566 : :
567 : : case tcc_type: return TS_TYPE_NON_COMMON;
568 : :
569 : 9600670337 : case tcc_binary:
570 : 9600670337 : case tcc_comparison:
571 : 9600670337 : case tcc_expression:
572 : 9600670337 : case tcc_reference:
573 : 9600670337 : case tcc_statement:
574 : 9600670337 : case tcc_unary:
575 : 9600670337 : case tcc_vl_exp: return TS_EXP;
576 : :
577 : 13463885711 : default: /* tcc_constant and tcc_exceptional */
578 : 13463885711 : break;
579 : : }
580 : :
581 : 13463885711 : switch (code)
582 : : {
583 : : /* tcc_constant cases. */
584 : : case COMPLEX_CST: return TS_COMPLEX;
585 : 290033 : case FIXED_CST: return TS_FIXED_CST;
586 : 452718173 : case INTEGER_CST: return TS_INT_CST;
587 : 290033 : case POLY_INT_CST: return TS_POLY_INT_CST;
588 : 42268918 : case REAL_CST: return TS_REAL_CST;
589 : 232161852 : case STRING_CST: return TS_STRING;
590 : 11637580 : case VECTOR_CST: return TS_VECTOR;
591 : 1012789 : case VOID_CST: return TS_TYPED;
592 : 290205 : case RAW_DATA_CST: return TS_RAW_DATA_CST;
593 : :
594 : : /* tcc_exceptional cases. */
595 : 625786635 : case BLOCK: return TS_BLOCK;
596 : 108419470 : case CONSTRUCTOR: return TS_CONSTRUCTOR;
597 : : case ERROR_MARK: return TS_COMMON;
598 : 8839894 : case IDENTIFIER_NODE: return TS_IDENTIFIER;
599 : 829305 : case OMP_CLAUSE: return TS_OMP_CLAUSE;
600 : 1747943 : case OPTIMIZATION_NODE: return TS_OPTIMIZATION;
601 : : case PLACEHOLDER_EXPR: return TS_COMMON;
602 : 255218574 : case SSA_NAME: return TS_SSA_NAME;
603 : 647562638 : case STATEMENT_LIST: return TS_STATEMENT_LIST;
604 : 3674580 : case TARGET_OPTION_NODE: return TS_TARGET_OPTION;
605 : 247486686 : case TREE_BINFO: return TS_BINFO;
606 : 8982901746 : case TREE_LIST: return TS_LIST;
607 : 1838956594 : case TREE_VEC: return TS_VEC;
608 : :
609 : 0 : default:
610 : 0 : gcc_unreachable ();
611 : : }
612 : : }
613 : :
614 : :
615 : : /* Initialize tree_contains_struct to describe the hierarchy of tree
616 : : nodes. */
617 : :
618 : : static void
619 : 290033 : initialize_tree_contains_struct (void)
620 : : {
621 : 290033 : unsigned i;
622 : :
623 : 71348118 : for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++)
624 : : {
625 : 71058085 : enum tree_code code;
626 : 71058085 : enum tree_node_structure_enum ts_code;
627 : :
628 : 71058085 : code = (enum tree_code) i;
629 : 71058085 : ts_code = tree_node_structure_for_code (code);
630 : :
631 : : /* Mark the TS structure itself. */
632 : 71058085 : tree_contains_struct[code][ts_code] = 1;
633 : :
634 : : /* Mark all the structures that TS is derived from. */
635 : 71058085 : switch (ts_code)
636 : : {
637 : 1160132 : case TS_TYPED:
638 : 1160132 : case TS_BLOCK:
639 : 1160132 : case TS_OPTIMIZATION:
640 : 1160132 : case TS_TARGET_OPTION:
641 : 1160132 : MARK_TS_BASE (code);
642 : 1160132 : break;
643 : :
644 : 58586666 : case TS_COMMON:
645 : 58586666 : case TS_INT_CST:
646 : 58586666 : case TS_POLY_INT_CST:
647 : 58586666 : case TS_REAL_CST:
648 : 58586666 : case TS_FIXED_CST:
649 : 58586666 : case TS_VECTOR:
650 : 58586666 : case TS_STRING:
651 : 58586666 : case TS_RAW_DATA_CST:
652 : 58586666 : case TS_COMPLEX:
653 : 58586666 : case TS_SSA_NAME:
654 : 58586666 : case TS_CONSTRUCTOR:
655 : 58586666 : case TS_EXP:
656 : 58586666 : case TS_STATEMENT_LIST:
657 : 58586666 : MARK_TS_TYPED (code);
658 : 58586666 : break;
659 : :
660 : 1450165 : case TS_IDENTIFIER:
661 : 1450165 : case TS_DECL_MINIMAL:
662 : 1450165 : case TS_TYPE_COMMON:
663 : 1450165 : case TS_LIST:
664 : 1450165 : case TS_VEC:
665 : 1450165 : case TS_BINFO:
666 : 1450165 : case TS_OMP_CLAUSE:
667 : 1450165 : MARK_TS_COMMON (code);
668 : 1450165 : break;
669 : :
670 : 0 : case TS_TYPE_WITH_LANG_SPECIFIC:
671 : 0 : MARK_TS_TYPE_COMMON (code);
672 : 0 : break;
673 : :
674 : 6090693 : case TS_TYPE_NON_COMMON:
675 : 6090693 : MARK_TS_TYPE_WITH_LANG_SPECIFIC (code);
676 : 6090693 : break;
677 : :
678 : 0 : case TS_DECL_COMMON:
679 : 0 : MARK_TS_DECL_MINIMAL (code);
680 : 0 : break;
681 : :
682 : 580066 : case TS_DECL_WRTL:
683 : 580066 : case TS_CONST_DECL:
684 : 580066 : MARK_TS_DECL_COMMON (code);
685 : 580066 : break;
686 : :
687 : 870099 : case TS_DECL_NON_COMMON:
688 : 870099 : MARK_TS_DECL_WITH_VIS (code);
689 : 870099 : break;
690 : :
691 : 870099 : case TS_DECL_WITH_VIS:
692 : 870099 : case TS_PARM_DECL:
693 : 870099 : case TS_LABEL_DECL:
694 : 870099 : case TS_RESULT_DECL:
695 : 870099 : MARK_TS_DECL_WRTL (code);
696 : 870099 : break;
697 : :
698 : 290033 : case TS_FIELD_DECL:
699 : 290033 : MARK_TS_DECL_COMMON (code);
700 : 290033 : break;
701 : :
702 : 290033 : case TS_VAR_DECL:
703 : 290033 : MARK_TS_DECL_WITH_VIS (code);
704 : 290033 : break;
705 : :
706 : 580066 : case TS_TYPE_DECL:
707 : 580066 : case TS_FUNCTION_DECL:
708 : 580066 : MARK_TS_DECL_NON_COMMON (code);
709 : 580066 : break;
710 : :
711 : 290033 : case TS_TRANSLATION_UNIT_DECL:
712 : 290033 : MARK_TS_DECL_COMMON (code);
713 : 290033 : break;
714 : :
715 : : default:
716 : : gcc_unreachable ();
717 : : }
718 : : }
719 : :
720 : : /* Basic consistency checks for attributes used in fold. */
721 : 290033 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]);
722 : 290033 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]);
723 : 290033 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]);
724 : 290033 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]);
725 : 290033 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]);
726 : 290033 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]);
727 : 290033 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]);
728 : 290033 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]);
729 : 290033 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]);
730 : 290033 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]);
731 : 290033 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]);
732 : 290033 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]);
733 : 290033 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]);
734 : 290033 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]);
735 : 290033 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]);
736 : 290033 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]);
737 : 290033 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]);
738 : 290033 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]);
739 : 290033 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]);
740 : 290033 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]);
741 : 290033 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]);
742 : 290033 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]);
743 : 290033 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]);
744 : 290033 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]);
745 : 290033 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]);
746 : 290033 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]);
747 : 290033 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]);
748 : 290033 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]);
749 : 290033 : gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]);
750 : 290033 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]);
751 : 290033 : gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]);
752 : 290033 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]);
753 : 290033 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]);
754 : 290033 : gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]);
755 : 290033 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]);
756 : 290033 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]);
757 : 290033 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]);
758 : 290033 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]);
759 : 290033 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_MINIMAL]);
760 : 290033 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_COMMON]);
761 : 290033 : }
762 : :
763 : :
764 : : /* Init tree.cc. */
765 : :
766 : : void
767 : 290033 : init_ttree (void)
768 : : {
769 : : /* Initialize the hash table of types. */
770 : 290033 : type_hash_table
771 : 290033 : = hash_table<type_cache_hasher>::create_ggc (TYPE_HASH_INITIAL_SIZE);
772 : :
773 : 290033 : debug_expr_for_decl
774 : 290033 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
775 : :
776 : 290033 : value_expr_for_decl
777 : 290033 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
778 : :
779 : 290033 : int_cst_hash_table = hash_table<int_cst_hasher>::create_ggc (1024);
780 : :
781 : 290033 : poly_int_cst_hash_table = hash_table<poly_int_cst_hasher>::create_ggc (64);
782 : :
783 : 290033 : int_cst_node = make_int_cst (1, 1);
784 : :
785 : 290033 : cl_option_hash_table = hash_table<cl_option_hasher>::create_ggc (64);
786 : :
787 : 290033 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
788 : 290033 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
789 : :
790 : : /* Initialize the tree_contains_struct array. */
791 : 290033 : initialize_tree_contains_struct ();
792 : 290033 : lang_hooks.init_ts ();
793 : 290033 : }
794 : :
795 : :
796 : : /* Mapping from prefix to label number. */
797 : :
798 : : struct identifier_hash : ggc_ptr_hash <tree_node>
799 : : {
800 : 34377 : static inline hashval_t hash (tree t)
801 : : {
802 : 34377 : return IDENTIFIER_HASH_VALUE (t);
803 : : }
804 : : };
805 : : struct identifier_count_traits
806 : : : simple_hashmap_traits<identifier_hash, long> {};
807 : : typedef hash_map<tree, long, identifier_count_traits> internal_label_map;
808 : : static GTY(()) internal_label_map *internal_label_nums;
809 : :
810 : : /* Generates an identifier intended to be used internally with the
811 : : given PREFIX. This is intended to be used by the frontend so that
812 : : C++ modules can regenerate appropriate (non-clashing) identifiers on
813 : : stream-in. */
814 : :
815 : : tree
816 : 34194 : generate_internal_label (const char *prefix)
817 : : {
818 : 34194 : tree prefix_id = get_identifier (prefix);
819 : 34194 : if (!internal_label_nums)
820 : 2648 : internal_label_nums = internal_label_map::create_ggc();
821 : 34194 : long &num = internal_label_nums->get_or_insert (prefix_id);
822 : :
823 : 34194 : char tmp[32];
824 : 34194 : ASM_GENERATE_INTERNAL_LABEL (tmp, prefix, num++);
825 : :
826 : 34194 : tree id = get_identifier (tmp);
827 : 34194 : IDENTIFIER_INTERNAL_P (id) = true;
828 : :
829 : : /* Cache the prefix on the identifier so we can retrieve it later. */
830 : 34194 : TREE_CHAIN (id) = prefix_id;
831 : :
832 : 34194 : return id;
833 : : }
834 : :
835 : : /* Get the PREFIX we created the internal identifier LABEL with. */
836 : :
837 : : const char *
838 : 7 : prefix_for_internal_label (tree label)
839 : : {
840 : 7 : gcc_assert (IDENTIFIER_INTERNAL_P (label)
841 : : && !IDENTIFIER_TRANSPARENT_ALIAS (label)
842 : : && TREE_CHAIN (label)
843 : : && TREE_CODE (TREE_CHAIN (label)) == IDENTIFIER_NODE);
844 : 7 : return IDENTIFIER_POINTER (TREE_CHAIN (label));
845 : : }
846 : :
847 : : /* The name of the object as the assembler will see it (but before any
848 : : translations made by ASM_OUTPUT_LABELREF). Often this is the same
849 : : as DECL_NAME. It is an IDENTIFIER_NODE. */
850 : : tree
851 : 1622560344 : decl_assembler_name (tree decl)
852 : : {
853 : 1622560344 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
854 : 141180102 : lang_hooks.set_decl_assembler_name (decl);
855 : 1622560344 : return DECL_ASSEMBLER_NAME_RAW (decl);
856 : : }
857 : :
858 : : /* The DECL_ASSEMBLER_NAME_RAW of DECL is being explicitly set to NAME
859 : : (either of which may be NULL). Inform the FE, if this changes the
860 : : name. */
861 : :
862 : : void
863 : 800334654 : overwrite_decl_assembler_name (tree decl, tree name)
864 : : {
865 : 800334654 : if (DECL_ASSEMBLER_NAME_RAW (decl) != name)
866 : 418174836 : lang_hooks.overwrite_decl_assembler_name (decl, name);
867 : 800334654 : }
868 : :
869 : : /* Return true if DECL may need an assembler name to be set. */
870 : :
871 : : static inline bool
872 : 5071329 : need_assembler_name_p (tree decl)
873 : : {
874 : : /* We use DECL_ASSEMBLER_NAME to hold mangled type names for One Definition
875 : : Rule merging. This makes type_odr_p to return true on those types during
876 : : LTO and by comparing the mangled name, we can say what types are intended
877 : : to be equivalent across compilation unit.
878 : :
879 : : We do not store names of type_in_anonymous_namespace_p.
880 : :
881 : : Record, union and enumeration type have linkage that allows use
882 : : to check type_in_anonymous_namespace_p. We do not mangle compound types
883 : : that always can be compared structurally.
884 : :
885 : : Similarly for builtin types, we compare properties of their main variant.
886 : : A special case are integer types where mangling do make differences
887 : : between char/signed char/unsigned char etc. Storing name for these makes
888 : : e.g. -fno-signed-char/-fsigned-char mismatches to be handled well.
889 : : See cp/mangle.cc:write_builtin_type for details. */
890 : :
891 : 5071329 : if (TREE_CODE (decl) == TYPE_DECL)
892 : : {
893 : 155739 : if (DECL_NAME (decl)
894 : 126606 : && decl == TYPE_NAME (TREE_TYPE (decl))
895 : 126453 : && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TREE_TYPE (decl)
896 : 107851 : && !TYPE_ARTIFICIAL (TREE_TYPE (decl))
897 : 104831 : && ((TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
898 : 87597 : && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE)
899 : 17474 : || TYPE_CXX_ODR_P (TREE_TYPE (decl)))
900 : 103432 : && (type_with_linkage_p (TREE_TYPE (decl))
901 : 89142 : || TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE)
902 : 223817 : && !variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
903 : 68078 : return !DECL_ASSEMBLER_NAME_SET_P (decl);
904 : 87661 : return false;
905 : : }
906 : : /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
907 : 4915590 : if (!VAR_OR_FUNCTION_DECL_P (decl))
908 : : return false;
909 : :
910 : : /* If DECL already has its assembler name set, it does not need a
911 : : new one. */
912 : 4241340 : if (!HAS_DECL_ASSEMBLER_NAME_P (decl)
913 : 4241340 : || DECL_ASSEMBLER_NAME_SET_P (decl))
914 : : return false;
915 : :
916 : : /* Abstract decls do not need an assembler name, except they
917 : : can be looked up by autofdo. */
918 : 1667535 : if (DECL_ABSTRACT_P (decl) && !flag_auto_profile)
919 : : return false;
920 : :
921 : : /* For VAR_DECLs, only static, public and external symbols need an
922 : : assembler name. */
923 : 1666299 : if (VAR_P (decl)
924 : 536638 : && !TREE_STATIC (decl)
925 : 536310 : && !TREE_PUBLIC (decl)
926 : 2202609 : && !DECL_EXTERNAL (decl))
927 : : return false;
928 : :
929 : 1129989 : if (TREE_CODE (decl) == FUNCTION_DECL)
930 : : {
931 : : /* Do not set assembler name on builtins. Allow RTL expansion to
932 : : decide whether to expand inline or via a regular call. */
933 : 1129661 : if (fndecl_built_in_p (decl)
934 : 1129661 : && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND)
935 : : return false;
936 : :
937 : : /* Functions represented in the callgraph need an assembler name. */
938 : 1124952 : if (cgraph_node::get (decl) != NULL)
939 : : return true;
940 : :
941 : : /* Unused and not public functions don't need an assembler name. */
942 : 3161 : if (!TREE_USED (decl) && !TREE_PUBLIC (decl))
943 : : return false;
944 : : }
945 : :
946 : : return true;
947 : : }
948 : :
949 : : /* If T needs an assembler name, have one created for it. */
950 : :
951 : : void
952 : 5071329 : assign_assembler_name_if_needed (tree t)
953 : : {
954 : 5071329 : if (need_assembler_name_p (t))
955 : : {
956 : : /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
957 : : diagnostics that use input_location to show locus
958 : : information. The problem here is that, at this point,
959 : : input_location is generally anchored to the end of the file
960 : : (since the parser is long gone), so we don't have a good
961 : : position to pin it to.
962 : :
963 : : To alleviate this problem, this uses the location of T's
964 : : declaration. Examples of this are
965 : : testsuite/g++.dg/template/cond2.C and
966 : : testsuite/g++.dg/template/pr35240.C. */
967 : 1193332 : location_t saved_location = input_location;
968 : 1193332 : input_location = DECL_SOURCE_LOCATION (t);
969 : :
970 : 1193332 : decl_assembler_name (t);
971 : :
972 : 1193332 : input_location = saved_location;
973 : : }
974 : 5071329 : }
975 : :
976 : : /* When the target supports COMDAT groups, this indicates which group the
977 : : DECL is associated with. This can be either an IDENTIFIER_NODE or a
978 : : decl, in which case its DECL_ASSEMBLER_NAME identifies the group. */
979 : : tree
980 : 370170904 : decl_comdat_group (const_tree node)
981 : : {
982 : 370170904 : struct symtab_node *snode = symtab_node::get (node);
983 : 370170904 : if (!snode)
984 : : return NULL;
985 : 353320586 : return snode->get_comdat_group ();
986 : : }
987 : :
988 : : /* Likewise, but make sure it's been reduced to an IDENTIFIER_NODE. */
989 : : tree
990 : 11727 : decl_comdat_group_id (const_tree node)
991 : : {
992 : 11727 : struct symtab_node *snode = symtab_node::get (node);
993 : 11727 : if (!snode)
994 : : return NULL;
995 : 11727 : return snode->get_comdat_group_id ();
996 : : }
997 : :
998 : : /* When the target supports named section, return its name as IDENTIFIER_NODE
999 : : or NULL if it is in no section. */
1000 : : const char *
1001 : 698212708 : decl_section_name (const_tree node)
1002 : : {
1003 : 698212708 : struct symtab_node *snode = symtab_node::get (node);
1004 : 698212708 : if (!snode)
1005 : : return NULL;
1006 : 543270181 : return snode->get_section ();
1007 : : }
1008 : :
1009 : : /* Set section name of NODE to VALUE (that is expected to be
1010 : : identifier node) */
1011 : : void
1012 : 1808231 : set_decl_section_name (tree node, const char *value)
1013 : : {
1014 : 1808231 : struct symtab_node *snode;
1015 : :
1016 : 1808231 : if (value == NULL)
1017 : : {
1018 : 46 : snode = symtab_node::get (node);
1019 : 46 : if (!snode)
1020 : : return;
1021 : : }
1022 : 1808185 : else if (VAR_P (node))
1023 : 1556146 : snode = varpool_node::get_create (node);
1024 : : else
1025 : 252039 : snode = cgraph_node::get_create (node);
1026 : 1808231 : snode->set_section (value);
1027 : : }
1028 : :
1029 : : /* Set section name of NODE to match the section name of OTHER.
1030 : :
1031 : : set_decl_section_name (decl, other) is equivalent to
1032 : : set_decl_section_name (decl, DECL_SECTION_NAME (other)), but possibly more
1033 : : efficient. */
1034 : : void
1035 : 14287867 : set_decl_section_name (tree decl, const_tree other)
1036 : : {
1037 : 14287867 : struct symtab_node *other_node = symtab_node::get (other);
1038 : 14287867 : if (other_node)
1039 : : {
1040 : 14287355 : struct symtab_node *decl_node;
1041 : 14287355 : if (VAR_P (decl))
1042 : 23 : decl_node = varpool_node::get_create (decl);
1043 : : else
1044 : 14287332 : decl_node = cgraph_node::get_create (decl);
1045 : 14287355 : decl_node->set_section (*other_node);
1046 : : }
1047 : : else
1048 : : {
1049 : 512 : struct symtab_node *decl_node = symtab_node::get (decl);
1050 : 512 : if (!decl_node)
1051 : : return;
1052 : 0 : decl_node->set_section (NULL);
1053 : : }
1054 : : }
1055 : :
1056 : : /* Return TLS model of a variable NODE. */
1057 : : enum tls_model
1058 : 248935073 : decl_tls_model (const_tree node)
1059 : : {
1060 : 248935073 : struct varpool_node *snode = varpool_node::get (node);
1061 : 248935073 : if (!snode)
1062 : : return TLS_MODEL_NONE;
1063 : 207216699 : return snode->tls_model;
1064 : : }
1065 : :
1066 : : /* Set TLS model of variable NODE to MODEL. */
1067 : : void
1068 : 58988 : set_decl_tls_model (tree node, enum tls_model model)
1069 : : {
1070 : 58988 : struct varpool_node *vnode;
1071 : :
1072 : 58988 : if (model == TLS_MODEL_NONE)
1073 : : {
1074 : 5928 : vnode = varpool_node::get (node);
1075 : 5928 : if (!vnode)
1076 : : return;
1077 : : }
1078 : : else
1079 : 53060 : vnode = varpool_node::get_create (node);
1080 : 53060 : vnode->tls_model = model;
1081 : : }
1082 : :
1083 : : /* Compute the number of bytes occupied by a tree with code CODE.
1084 : : This function cannot be used for nodes that have variable sizes,
1085 : : including TREE_VEC, INTEGER_CST, STRING_CST, and CALL_EXPR. */
1086 : : size_t
1087 : 16466242761 : tree_code_size (enum tree_code code)
1088 : : {
1089 : 16466242761 : switch (TREE_CODE_CLASS (code))
1090 : : {
1091 : 4061158356 : case tcc_declaration: /* A decl node */
1092 : 4061158356 : switch (code)
1093 : : {
1094 : : case FIELD_DECL: return sizeof (tree_field_decl);
1095 : : case PARM_DECL: return sizeof (tree_parm_decl);
1096 : 231152430 : case VAR_DECL: return sizeof (tree_var_decl);
1097 : : case LABEL_DECL: return sizeof (tree_label_decl);
1098 : : case RESULT_DECL: return sizeof (tree_result_decl);
1099 : 32219581 : case CONST_DECL: return sizeof (tree_const_decl);
1100 : : case TYPE_DECL: return sizeof (tree_type_decl);
1101 : 1376560330 : case FUNCTION_DECL: return sizeof (tree_function_decl);
1102 : : case DEBUG_EXPR_DECL: return sizeof (tree_decl_with_rtl);
1103 : : case TRANSLATION_UNIT_DECL: return sizeof (tree_translation_unit_decl);
1104 : : case NAMESPACE_DECL:
1105 : : case IMPORTED_DECL:
1106 : : case NAMELIST_DECL: return sizeof (tree_decl_non_common);
1107 : 245460036 : default:
1108 : 245460036 : gcc_checking_assert (code >= NUM_TREE_CODES);
1109 : 245460036 : return lang_hooks.tree_size (code);
1110 : : }
1111 : :
1112 : 2807862257 : case tcc_type: /* a type node */
1113 : 2807862257 : switch (code)
1114 : : {
1115 : : case OFFSET_TYPE:
1116 : : case ENUMERAL_TYPE:
1117 : : case BOOLEAN_TYPE:
1118 : : case INTEGER_TYPE:
1119 : : case REAL_TYPE:
1120 : : case OPAQUE_TYPE:
1121 : : case POINTER_TYPE:
1122 : : case REFERENCE_TYPE:
1123 : : case NULLPTR_TYPE:
1124 : : case FIXED_POINT_TYPE:
1125 : : case COMPLEX_TYPE:
1126 : : case VECTOR_TYPE:
1127 : : case ARRAY_TYPE:
1128 : : case RECORD_TYPE:
1129 : : case UNION_TYPE:
1130 : : case QUAL_UNION_TYPE:
1131 : : case VOID_TYPE:
1132 : : case FUNCTION_TYPE:
1133 : : case METHOD_TYPE:
1134 : : case BITINT_TYPE:
1135 : : case LANG_TYPE: return sizeof (tree_type_non_common);
1136 : 661537787 : default:
1137 : 661537787 : gcc_checking_assert (code >= NUM_TREE_CODES);
1138 : 661537787 : return lang_hooks.tree_size (code);
1139 : : }
1140 : :
1141 : 4270473186 : case tcc_reference: /* a reference */
1142 : 4270473186 : case tcc_expression: /* an expression */
1143 : 4270473186 : case tcc_statement: /* an expression with side effects */
1144 : 4270473186 : case tcc_comparison: /* a comparison expression */
1145 : 4270473186 : case tcc_unary: /* a unary arithmetic expression */
1146 : 4270473186 : case tcc_binary: /* a binary arithmetic expression */
1147 : 4270473186 : return (sizeof (struct tree_exp)
1148 : 4270473186 : + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
1149 : :
1150 : 44172637 : case tcc_constant: /* a constant */
1151 : 44172637 : switch (code)
1152 : : {
1153 : : case VOID_CST: return sizeof (tree_typed);
1154 : 0 : case INTEGER_CST: gcc_unreachable ();
1155 : : case POLY_INT_CST: return sizeof (tree_poly_int_cst);
1156 : 43321906 : case REAL_CST: return sizeof (tree_real_cst);
1157 : : case FIXED_CST: return sizeof (tree_fixed_cst);
1158 : : case COMPLEX_CST: return sizeof (tree_complex);
1159 : : case RAW_DATA_CST: return sizeof (tree_raw_data);
1160 : 0 : case VECTOR_CST: gcc_unreachable ();
1161 : 0 : case STRING_CST: gcc_unreachable ();
1162 : 67101 : default:
1163 : 67101 : gcc_checking_assert (code >= NUM_TREE_CODES);
1164 : 67101 : return lang_hooks.tree_size (code);
1165 : : }
1166 : :
1167 : 5282576325 : case tcc_exceptional: /* something random, like an identifier. */
1168 : 5282576325 : switch (code)
1169 : : {
1170 : 1665874311 : case IDENTIFIER_NODE: return lang_hooks.identifier_size;
1171 : : case TREE_LIST: return sizeof (tree_list);
1172 : :
1173 : : case ERROR_MARK:
1174 : : case PLACEHOLDER_EXPR: return sizeof (tree_common);
1175 : :
1176 : 0 : case TREE_VEC: gcc_unreachable ();
1177 : 0 : case OMP_CLAUSE: gcc_unreachable ();
1178 : :
1179 : : case SSA_NAME: return sizeof (tree_ssa_name);
1180 : :
1181 : : case STATEMENT_LIST: return sizeof (tree_statement_list);
1182 : 277427152 : case BLOCK: return sizeof (struct tree_block);
1183 : : case CONSTRUCTOR: return sizeof (tree_constructor);
1184 : : case OPTIMIZATION_NODE: return sizeof (tree_optimization_option);
1185 : : case TARGET_OPTION_NODE: return sizeof (tree_target_option);
1186 : :
1187 : 1396639162 : default:
1188 : 1396639162 : gcc_checking_assert (code >= NUM_TREE_CODES);
1189 : 1396639162 : return lang_hooks.tree_size (code);
1190 : : }
1191 : :
1192 : 0 : default:
1193 : 0 : gcc_unreachable ();
1194 : : }
1195 : : }
1196 : :
1197 : : /* Compute the number of bytes occupied by NODE. This routine only
1198 : : looks at TREE_CODE, except for those nodes that have variable sizes. */
1199 : : size_t
1200 : 3743612817 : tree_size (const_tree node)
1201 : : {
1202 : 3743612817 : const enum tree_code code = TREE_CODE (node);
1203 : 3743612817 : switch (code)
1204 : : {
1205 : 528479 : case INTEGER_CST:
1206 : 528479 : return (sizeof (struct tree_int_cst)
1207 : 528479 : + (TREE_INT_CST_EXT_NUNITS (node) - 1) * sizeof (HOST_WIDE_INT));
1208 : :
1209 : 0 : case TREE_BINFO:
1210 : 0 : return (offsetof (struct tree_binfo, base_binfos)
1211 : : + vec<tree, va_gc>
1212 : 0 : ::embedded_size (BINFO_N_BASE_BINFOS (node)));
1213 : :
1214 : 369046185 : case TREE_VEC:
1215 : 369046185 : return (sizeof (struct tree_vec)
1216 : 369046185 : + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
1217 : :
1218 : 0 : case VECTOR_CST:
1219 : 0 : return (sizeof (struct tree_vector)
1220 : 0 : + (vector_cst_encoded_nelts (node) - 1) * sizeof (tree));
1221 : :
1222 : 22586 : case STRING_CST:
1223 : 22586 : return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
1224 : :
1225 : 32499 : case OMP_CLAUSE:
1226 : 32499 : return (sizeof (struct tree_omp_clause)
1227 : 32499 : + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
1228 : 32499 : * sizeof (tree));
1229 : :
1230 : 3373983068 : default:
1231 : 3373983068 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
1232 : 154454124 : return (sizeof (struct tree_exp)
1233 : 154454124 : + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
1234 : : else
1235 : 3219528944 : return tree_code_size (code);
1236 : : }
1237 : : }
1238 : :
1239 : : /* Return tree node kind based on tree CODE. */
1240 : :
1241 : : static tree_node_kind
1242 : 0 : get_stats_node_kind (enum tree_code code)
1243 : : {
1244 : 0 : enum tree_code_class type = TREE_CODE_CLASS (code);
1245 : :
1246 : 0 : switch (type)
1247 : : {
1248 : : case tcc_declaration: /* A decl node */
1249 : : return d_kind;
1250 : 0 : case tcc_type: /* a type node */
1251 : 0 : return t_kind;
1252 : 0 : case tcc_statement: /* an expression with side effects */
1253 : 0 : return s_kind;
1254 : 0 : case tcc_reference: /* a reference */
1255 : 0 : return r_kind;
1256 : : case tcc_expression: /* an expression */
1257 : : case tcc_comparison: /* a comparison expression */
1258 : : case tcc_unary: /* a unary arithmetic expression */
1259 : : case tcc_binary: /* a binary arithmetic expression */
1260 : : return e_kind;
1261 : 0 : case tcc_constant: /* a constant */
1262 : 0 : return c_kind;
1263 : 0 : case tcc_exceptional: /* something random, like an identifier. */
1264 : 0 : switch (code)
1265 : : {
1266 : : case IDENTIFIER_NODE:
1267 : : return id_kind;
1268 : 0 : case TREE_VEC:
1269 : 0 : return vec_kind;
1270 : 0 : case TREE_BINFO:
1271 : 0 : return binfo_kind;
1272 : 0 : case SSA_NAME:
1273 : 0 : return ssa_name_kind;
1274 : 0 : case BLOCK:
1275 : 0 : return b_kind;
1276 : 0 : case CONSTRUCTOR:
1277 : 0 : return constr_kind;
1278 : 0 : case OMP_CLAUSE:
1279 : 0 : return omp_clause_kind;
1280 : 0 : default:
1281 : 0 : return x_kind;
1282 : : }
1283 : : break;
1284 : : case tcc_vl_exp:
1285 : : return e_kind;
1286 : 0 : default:
1287 : 0 : gcc_unreachable ();
1288 : : }
1289 : : }
1290 : :
1291 : : /* Record interesting allocation statistics for a tree node with CODE
1292 : : and LENGTH. */
1293 : :
1294 : : static void
1295 : 0 : record_node_allocation_statistics (enum tree_code code, size_t length)
1296 : : {
1297 : 0 : if (!GATHER_STATISTICS)
1298 : 0 : return;
1299 : :
1300 : : tree_node_kind kind = get_stats_node_kind (code);
1301 : :
1302 : : tree_code_counts[(int) code]++;
1303 : : tree_node_counts[(int) kind]++;
1304 : : tree_node_sizes[(int) kind] += length;
1305 : : }
1306 : :
1307 : : /* Allocate and return a new UID from the DECL_UID namespace. */
1308 : :
1309 : : int
1310 : 4054822661 : allocate_decl_uid (void)
1311 : : {
1312 : 4054822661 : return next_decl_uid++;
1313 : : }
1314 : :
1315 : : /* Return a newly allocated node of code CODE. For decl and type
1316 : : nodes, some other fields are initialized. The rest of the node is
1317 : : initialized to zero. This function cannot be used for TREE_VEC,
1318 : : INTEGER_CST or OMP_CLAUSE nodes, which is enforced by asserts in
1319 : : tree_code_size.
1320 : :
1321 : : Achoo! I got a code in the node. */
1322 : :
1323 : : tree
1324 : 13241340167 : make_node (enum tree_code code MEM_STAT_DECL)
1325 : : {
1326 : 13241340167 : tree t;
1327 : 13241340167 : enum tree_code_class type = TREE_CODE_CLASS (code);
1328 : 13241340167 : size_t length = tree_code_size (code);
1329 : :
1330 : 13241340167 : record_node_allocation_statistics (code, length);
1331 : :
1332 : 13241340167 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1333 : 13241340167 : TREE_SET_CODE (t, code);
1334 : :
1335 : 13241340167 : switch (type)
1336 : : {
1337 : 660481437 : case tcc_statement:
1338 : 660481437 : if (code != DEBUG_BEGIN_STMT)
1339 : 345896858 : TREE_SIDE_EFFECTS (t) = 1;
1340 : : break;
1341 : :
1342 : 2976949166 : case tcc_declaration:
1343 : 2976949166 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1344 : : {
1345 : 2976949166 : if (code == FUNCTION_DECL)
1346 : : {
1347 : 1102541649 : SET_DECL_ALIGN (t, FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY));
1348 : 1102541649 : SET_DECL_MODE (t, FUNCTION_MODE);
1349 : : }
1350 : : else
1351 : 1874407517 : SET_DECL_ALIGN (t, 1);
1352 : : }
1353 : 2976949166 : DECL_SOURCE_LOCATION (t) = input_location;
1354 : 2976949166 : if (TREE_CODE (t) == DEBUG_EXPR_DECL)
1355 : 1958598 : DECL_UID (t) = --next_debug_decl_uid;
1356 : : else
1357 : : {
1358 : 2974990568 : DECL_UID (t) = allocate_decl_uid ();
1359 : 2974990568 : SET_DECL_PT_UID (t, -1);
1360 : : }
1361 : 2976949166 : if (TREE_CODE (t) == LABEL_DECL)
1362 : 34442980 : LABEL_DECL_UID (t) = -1;
1363 : :
1364 : : break;
1365 : :
1366 : 2084940478 : case tcc_type:
1367 : 2084940478 : TYPE_UID (t) = next_type_uid++;
1368 : 2084940478 : SET_TYPE_ALIGN (t, BITS_PER_UNIT);
1369 : 2084940478 : TYPE_USER_ALIGN (t) = 0;
1370 : 2084940478 : TYPE_MAIN_VARIANT (t) = t;
1371 : 2084940478 : TYPE_CANONICAL (t) = t;
1372 : :
1373 : : /* Default to no attributes for type, but let target change that. */
1374 : 2084940478 : TYPE_ATTRIBUTES (t) = NULL_TREE;
1375 : 2084940478 : targetm.set_default_type_attributes (t);
1376 : :
1377 : : /* We have not yet computed the alias set for this type. */
1378 : 2084940478 : TYPE_ALIAS_SET (t) = -1;
1379 : 2084940478 : break;
1380 : :
1381 : 44170912 : case tcc_constant:
1382 : 44170912 : TREE_CONSTANT (t) = 1;
1383 : 44170912 : break;
1384 : :
1385 : 1130490780 : case tcc_expression:
1386 : 1130490780 : switch (code)
1387 : : {
1388 : 260199431 : case INIT_EXPR:
1389 : 260199431 : case MODIFY_EXPR:
1390 : 260199431 : case VA_ARG_EXPR:
1391 : 260199431 : case PREDECREMENT_EXPR:
1392 : 260199431 : case PREINCREMENT_EXPR:
1393 : 260199431 : case POSTDECREMENT_EXPR:
1394 : 260199431 : case POSTINCREMENT_EXPR:
1395 : : /* All of these have side-effects, no matter what their
1396 : : operands are. */
1397 : 260199431 : TREE_SIDE_EFFECTS (t) = 1;
1398 : 260199431 : break;
1399 : :
1400 : : default:
1401 : : break;
1402 : : }
1403 : : break;
1404 : :
1405 : 5083732455 : case tcc_exceptional:
1406 : 5083732455 : switch (code)
1407 : : {
1408 : 1079006 : case TARGET_OPTION_NODE:
1409 : 2158012 : TREE_TARGET_OPTION(t)
1410 : 1079006 : = ggc_cleared_alloc<struct cl_target_option> ();
1411 : 1079006 : break;
1412 : :
1413 : 605737 : case OPTIMIZATION_NODE:
1414 : 1211474 : TREE_OPTIMIZATION (t)
1415 : 605737 : = ggc_cleared_alloc<struct cl_optimization> ();
1416 : 605737 : break;
1417 : :
1418 : : default:
1419 : : break;
1420 : : }
1421 : : break;
1422 : :
1423 : : default:
1424 : : /* Other classes need no special treatment. */
1425 : : break;
1426 : : }
1427 : :
1428 : 13241340167 : return t;
1429 : : }
1430 : :
1431 : : /* Free tree node. */
1432 : :
1433 : : void
1434 : 633916745 : free_node (tree node)
1435 : : {
1436 : 633916745 : enum tree_code code = TREE_CODE (node);
1437 : 633916745 : if (GATHER_STATISTICS)
1438 : : {
1439 : : enum tree_node_kind kind = get_stats_node_kind (code);
1440 : :
1441 : : gcc_checking_assert (tree_code_counts[(int) TREE_CODE (node)] != 0);
1442 : : gcc_checking_assert (tree_node_counts[(int) kind] != 0);
1443 : : gcc_checking_assert (tree_node_sizes[(int) kind] >= tree_size (node));
1444 : :
1445 : : tree_code_counts[(int) TREE_CODE (node)]--;
1446 : : tree_node_counts[(int) kind]--;
1447 : : tree_node_sizes[(int) kind] -= tree_size (node);
1448 : : }
1449 : 633916745 : if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1450 : 349 : vec_free (CONSTRUCTOR_ELTS (node));
1451 : 633916552 : else if (code == BLOCK)
1452 : 0 : vec_free (BLOCK_NONLOCALIZED_VARS (node));
1453 : 633916552 : else if (code == TREE_BINFO)
1454 : 363 : vec_free (BINFO_BASE_ACCESSES (node));
1455 : 633916189 : else if (code == OPTIMIZATION_NODE)
1456 : 816 : cl_optimization_option_free (TREE_OPTIMIZATION (node));
1457 : 633915373 : else if (code == TARGET_OPTION_NODE)
1458 : 881 : cl_target_option_free (TREE_TARGET_OPTION (node));
1459 : 633916745 : ggc_free (node);
1460 : 633916745 : }
1461 : :
1462 : : /* Return a new node with the same contents as NODE except that its
1463 : : TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
1464 : :
1465 : : tree
1466 : 3659369106 : copy_node (tree node MEM_STAT_DECL)
1467 : : {
1468 : 3659369106 : tree t;
1469 : 3659369106 : enum tree_code code = TREE_CODE (node);
1470 : 3659369106 : size_t length;
1471 : :
1472 : 3659369106 : gcc_assert (code != STATEMENT_LIST);
1473 : :
1474 : 3659369106 : length = tree_size (node);
1475 : 3659369106 : record_node_allocation_statistics (code, length);
1476 : 3659369106 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
1477 : 3659369106 : memcpy (t, node, length);
1478 : :
1479 : 3659369106 : if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
1480 : 2224669430 : TREE_CHAIN (t) = 0;
1481 : 3659369106 : TREE_ASM_WRITTEN (t) = 0;
1482 : 3659369106 : TREE_VISITED (t) = 0;
1483 : :
1484 : 3659369106 : if (TREE_CODE_CLASS (code) == tcc_declaration)
1485 : : {
1486 : 1078835540 : if (code == DEBUG_EXPR_DECL)
1487 : 0 : DECL_UID (t) = --next_debug_decl_uid;
1488 : : else
1489 : : {
1490 : 1078835540 : DECL_UID (t) = allocate_decl_uid ();
1491 : 1078835540 : if (DECL_PT_UID_SET_P (node))
1492 : 3482 : SET_DECL_PT_UID (t, DECL_PT_UID (node));
1493 : : }
1494 : 533464199 : if ((TREE_CODE (node) == PARM_DECL || VAR_P (node))
1495 : 1143534878 : && DECL_HAS_VALUE_EXPR_P (node))
1496 : : {
1497 : 972063 : SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
1498 : 972063 : DECL_HAS_VALUE_EXPR_P (t) = 1;
1499 : : }
1500 : : /* DECL_DEBUG_EXPR is copied explicitly by callers. */
1501 : 1078835540 : if (VAR_P (node))
1502 : : {
1503 : 64699338 : DECL_HAS_DEBUG_EXPR_P (t) = 0;
1504 : 64699338 : t->decl_with_vis.symtab_node = NULL;
1505 : : }
1506 : 1078835540 : if (VAR_P (node) && DECL_HAS_INIT_PRIORITY_P (node))
1507 : : {
1508 : 0 : SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
1509 : 0 : DECL_HAS_INIT_PRIORITY_P (t) = 1;
1510 : : }
1511 : 1078835540 : if (TREE_CODE (node) == FUNCTION_DECL)
1512 : : {
1513 : 269151774 : DECL_STRUCT_FUNCTION (t) = NULL;
1514 : 269151774 : t->decl_with_vis.symtab_node = NULL;
1515 : : }
1516 : : }
1517 : 2580533566 : else if (TREE_CODE_CLASS (code) == tcc_type)
1518 : : {
1519 : 722921779 : TYPE_UID (t) = next_type_uid++;
1520 : : /* The following is so that the debug code for
1521 : : the copy is different from the original type.
1522 : : The two statements usually duplicate each other
1523 : : (because they clear fields of the same union),
1524 : : but the optimizer should catch that. */
1525 : 722921779 : TYPE_SYMTAB_ADDRESS (t) = 0;
1526 : 722921779 : TYPE_SYMTAB_DIE (t) = 0;
1527 : :
1528 : : /* Do not copy the values cache. */
1529 : 722921779 : if (TYPE_CACHED_VALUES_P (t))
1530 : : {
1531 : 17977409 : TYPE_CACHED_VALUES_P (t) = 0;
1532 : 17977409 : TYPE_CACHED_VALUES (t) = NULL_TREE;
1533 : : }
1534 : : }
1535 : 1857611787 : else if (code == TARGET_OPTION_NODE)
1536 : : {
1537 : 0 : TREE_TARGET_OPTION (t) = ggc_alloc<struct cl_target_option>();
1538 : 0 : memcpy (TREE_TARGET_OPTION (t), TREE_TARGET_OPTION (node),
1539 : : sizeof (struct cl_target_option));
1540 : : }
1541 : 1857611787 : else if (code == OPTIMIZATION_NODE)
1542 : : {
1543 : 0 : TREE_OPTIMIZATION (t) = ggc_alloc<struct cl_optimization>();
1544 : 0 : memcpy (TREE_OPTIMIZATION (t), TREE_OPTIMIZATION (node),
1545 : : sizeof (struct cl_optimization));
1546 : : }
1547 : :
1548 : 3659369106 : return t;
1549 : : }
1550 : :
1551 : : /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1552 : : For example, this can copy a list made of TREE_LIST nodes. */
1553 : :
1554 : : tree
1555 : 141466142 : copy_list (tree list)
1556 : : {
1557 : 141466142 : tree head;
1558 : 141466142 : tree prev, next;
1559 : :
1560 : 141466142 : if (list == 0)
1561 : : return 0;
1562 : :
1563 : 136413991 : head = prev = copy_node (list);
1564 : 136413991 : next = TREE_CHAIN (list);
1565 : 269988146 : while (next)
1566 : : {
1567 : 133574155 : TREE_CHAIN (prev) = copy_node (next);
1568 : 133574155 : prev = TREE_CHAIN (prev);
1569 : 133574155 : next = TREE_CHAIN (next);
1570 : : }
1571 : : return head;
1572 : : }
1573 : :
1574 : :
1575 : : /* Return the value that TREE_INT_CST_EXT_NUNITS should have for an
1576 : : INTEGER_CST with value CST and type TYPE. */
1577 : :
1578 : : static unsigned int
1579 : 9438652730 : get_int_cst_ext_nunits (tree type, const wide_int &cst)
1580 : : {
1581 : 9438652730 : gcc_checking_assert (cst.get_precision () == TYPE_PRECISION (type));
1582 : : /* We need extra HWIs if CST is an unsigned integer with its
1583 : : upper bit set. */
1584 : 9438652730 : if (TYPE_UNSIGNED (type) && wi::neg_p (cst))
1585 : 175082374 : return cst.get_precision () / HOST_BITS_PER_WIDE_INT + 1;
1586 : 9263570356 : return cst.get_len ();
1587 : : }
1588 : :
1589 : : /* Return a new INTEGER_CST with value CST and type TYPE. */
1590 : :
1591 : : static tree
1592 : 125767556 : build_new_int_cst (tree type, const wide_int &cst)
1593 : : {
1594 : 125767556 : unsigned int len = cst.get_len ();
1595 : 125767556 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1596 : 125767556 : tree nt = make_int_cst (len, ext_len);
1597 : :
1598 : 125767556 : if (len < ext_len)
1599 : : {
1600 : 64271474 : --ext_len;
1601 : 128542948 : TREE_INT_CST_ELT (nt, ext_len)
1602 : 64271474 : = zext_hwi (-1, cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1603 : 84398759 : for (unsigned int i = len; i < ext_len; ++i)
1604 : 20127285 : TREE_INT_CST_ELT (nt, i) = -1;
1605 : : }
1606 : 61496082 : else if (TYPE_UNSIGNED (type)
1607 : 61496082 : && cst.get_precision () < len * HOST_BITS_PER_WIDE_INT)
1608 : : {
1609 : 13104272 : len--;
1610 : 26208544 : TREE_INT_CST_ELT (nt, len)
1611 : 13104272 : = zext_hwi (cst.elt (len),
1612 : 13104272 : cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1613 : : }
1614 : :
1615 : 241780906 : for (unsigned int i = 0; i < len; i++)
1616 : 116013350 : TREE_INT_CST_ELT (nt, i) = cst.elt (i);
1617 : 125767556 : TREE_TYPE (nt) = type;
1618 : 125767556 : return nt;
1619 : : }
1620 : :
1621 : : /* Return a new POLY_INT_CST with coefficients COEFFS and type TYPE. */
1622 : :
1623 : : static tree
1624 : 0 : build_new_poly_int_cst (tree type, tree (&coeffs)[NUM_POLY_INT_COEFFS]
1625 : : CXX_MEM_STAT_INFO)
1626 : : {
1627 : 0 : size_t length = sizeof (struct tree_poly_int_cst);
1628 : 0 : record_node_allocation_statistics (POLY_INT_CST, length);
1629 : :
1630 : 0 : tree t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1631 : :
1632 : 0 : TREE_SET_CODE (t, POLY_INT_CST);
1633 : 0 : TREE_CONSTANT (t) = 1;
1634 : 0 : TREE_TYPE (t) = type;
1635 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1636 : 0 : POLY_INT_CST_COEFF (t, i) = coeffs[i];
1637 : 0 : return t;
1638 : : }
1639 : :
1640 : : /* Create a constant tree that contains CST sign-extended to TYPE. */
1641 : :
1642 : : tree
1643 : 6288541017 : build_int_cst (tree type, poly_int64 cst)
1644 : : {
1645 : : /* Support legacy code. */
1646 : 6288541017 : if (!type)
1647 : 2087685559 : type = integer_type_node;
1648 : :
1649 : 6288541017 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1650 : : }
1651 : :
1652 : : /* Create a constant tree that contains CST zero-extended to TYPE. */
1653 : :
1654 : : tree
1655 : 9574629 : build_int_cstu (tree type, poly_uint64 cst)
1656 : : {
1657 : 9574629 : return wide_int_to_tree (type, wi::uhwi (cst, TYPE_PRECISION (type)));
1658 : : }
1659 : :
1660 : : /* Create a constant tree that contains CST sign-extended to TYPE. */
1661 : :
1662 : : tree
1663 : 25923522 : build_int_cst_type (tree type, poly_int64 cst)
1664 : : {
1665 : 25923522 : gcc_assert (type);
1666 : 25923522 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1667 : : }
1668 : :
1669 : : /* Constructs tree in type TYPE from with value given by CST. Signedness
1670 : : of CST is assumed to be the same as the signedness of TYPE. */
1671 : :
1672 : : tree
1673 : 7287760 : double_int_to_tree (tree type, double_int cst)
1674 : : {
1675 : 7287760 : return wide_int_to_tree (type, widest_int::from (cst, TYPE_SIGN (type)));
1676 : : }
1677 : :
1678 : : /* We force the wide_int CST to the range of the type TYPE by sign or
1679 : : zero extending it. OVERFLOWABLE indicates if we are interested in
1680 : : overflow of the value, when >0 we are only interested in signed
1681 : : overflow, for <0 we are interested in any overflow. OVERFLOWED
1682 : : indicates whether overflow has already occurred. CONST_OVERFLOWED
1683 : : indicates whether constant overflow has already occurred. We force
1684 : : T's value to be within range of T's type (by setting to 0 or 1 all
1685 : : the bits outside the type's range). We set TREE_OVERFLOWED if,
1686 : : OVERFLOWED is nonzero,
1687 : : or OVERFLOWABLE is >0 and signed overflow occurs
1688 : : or OVERFLOWABLE is <0 and any overflow occurs
1689 : : We return a new tree node for the extended wide_int. The node
1690 : : is shared if no overflow flags are set. */
1691 : :
1692 : :
1693 : : tree
1694 : 2457776213 : force_fit_type (tree type, const poly_wide_int_ref &cst,
1695 : : int overflowable, bool overflowed)
1696 : : {
1697 : 2457776213 : signop sign = TYPE_SIGN (type);
1698 : :
1699 : : /* If we need to set overflow flags, return a new unshared node. */
1700 : 2457776213 : if (overflowed || !wi::fits_to_tree_p (cst, type))
1701 : : {
1702 : 6810681 : if (overflowed
1703 : 6810681 : || overflowable < 0
1704 : 5555477 : || (overflowable > 0 && sign == SIGNED))
1705 : : {
1706 : 1313862 : poly_wide_int tmp = poly_wide_int::from (cst, TYPE_PRECISION (type),
1707 : 1313862 : sign);
1708 : 1313862 : tree t;
1709 : 1313862 : if (tmp.is_constant ())
1710 : 1313862 : t = build_new_int_cst (type, tmp.coeffs[0]);
1711 : : else
1712 : : {
1713 : : tree coeffs[NUM_POLY_INT_COEFFS];
1714 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1715 : : {
1716 : : coeffs[i] = build_new_int_cst (type, tmp.coeffs[i]);
1717 : : TREE_OVERFLOW (coeffs[i]) = 1;
1718 : : }
1719 : : t = build_new_poly_int_cst (type, coeffs);
1720 : : }
1721 : 1313862 : TREE_OVERFLOW (t) = 1;
1722 : 1313862 : return t;
1723 : 1313862 : }
1724 : : }
1725 : :
1726 : : /* Else build a shared node. */
1727 : 2456462351 : return wide_int_to_tree (type, cst);
1728 : : }
1729 : :
1730 : : /* These are the hash table functions for the hash table of INTEGER_CST
1731 : : nodes of a sizetype. */
1732 : :
1733 : : /* Return the hash code X, an INTEGER_CST. */
1734 : :
1735 : : hashval_t
1736 : 1941852134 : int_cst_hasher::hash (tree x)
1737 : : {
1738 : 1941852134 : const_tree const t = x;
1739 : 1941852134 : hashval_t code = TYPE_UID (TREE_TYPE (t));
1740 : 1941852134 : int i;
1741 : :
1742 : 3890402789 : for (i = 0; i < TREE_INT_CST_NUNITS (t); i++)
1743 : 1948550655 : code = iterative_hash_host_wide_int (TREE_INT_CST_ELT(t, i), code);
1744 : :
1745 : 1941852134 : return code;
1746 : : }
1747 : :
1748 : : /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1749 : : is the same as that given by *Y, which is the same. */
1750 : :
1751 : : bool
1752 : 1926295831 : int_cst_hasher::equal (tree x, tree y)
1753 : : {
1754 : 1926295831 : const_tree const xt = x;
1755 : 1926295831 : const_tree const yt = y;
1756 : :
1757 : 1926295831 : if (TREE_TYPE (xt) != TREE_TYPE (yt)
1758 : 598657019 : || TREE_INT_CST_NUNITS (xt) != TREE_INT_CST_NUNITS (yt)
1759 : 2524899255 : || TREE_INT_CST_EXT_NUNITS (xt) != TREE_INT_CST_EXT_NUNITS (yt))
1760 : : return false;
1761 : :
1762 : 873110500 : for (int i = 0; i < TREE_INT_CST_NUNITS (xt); i++)
1763 : 555524447 : if (TREE_INT_CST_ELT (xt, i) != TREE_INT_CST_ELT (yt, i))
1764 : : return false;
1765 : :
1766 : : return true;
1767 : : }
1768 : :
1769 : : /* Cache wide_int CST into the TYPE_CACHED_VALUES cache for TYPE.
1770 : : SLOT is the slot entry to store it in, and MAX_SLOTS is the maximum
1771 : : number of slots that can be cached for the type. */
1772 : :
1773 : : static inline tree
1774 : 8906051550 : cache_wide_int_in_type_cache (tree type, const wide_int &cst,
1775 : : int slot, int max_slots)
1776 : : {
1777 : 8906051550 : gcc_checking_assert (slot >= 0);
1778 : : /* Initialize cache. */
1779 : 8906051550 : if (!TYPE_CACHED_VALUES_P (type))
1780 : : {
1781 : 19114246 : TYPE_CACHED_VALUES_P (type) = 1;
1782 : 19114246 : TYPE_CACHED_VALUES (type) = make_tree_vec (max_slots);
1783 : : }
1784 : 8906051550 : tree t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot);
1785 : 8906051550 : if (!t)
1786 : : {
1787 : : /* Create a new shared int. */
1788 : 57932065 : t = build_new_int_cst (type, cst);
1789 : 57932065 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot) = t;
1790 : : }
1791 : 8906051550 : return t;
1792 : : }
1793 : :
1794 : : /* Create an INT_CST node of TYPE and value CST.
1795 : : The returned node is always shared. For small integers we use a
1796 : : per-type vector cache, for larger ones we use a single hash table.
1797 : : The value is extended from its precision according to the sign of
1798 : : the type to be a multiple of HOST_BITS_PER_WIDE_INT. This defines
1799 : : the upper bits and ensures that hashing and value equality based
1800 : : upon the underlying HOST_WIDE_INTs works without masking. */
1801 : :
1802 : : static tree
1803 : 9312885174 : wide_int_to_tree_1 (tree type, const wide_int_ref &pcst)
1804 : : {
1805 : 9312885174 : tree t;
1806 : 9312885174 : int ix = -1;
1807 : 9312885174 : int limit = 0;
1808 : :
1809 : 9312885174 : gcc_assert (type);
1810 : 9312885174 : unsigned int prec = TYPE_PRECISION (type);
1811 : 9312885174 : signop sgn = TYPE_SIGN (type);
1812 : :
1813 : : /* Verify that everything is canonical. */
1814 : 9312885174 : int l = pcst.get_len ();
1815 : 9312885174 : if (l > 1)
1816 : : {
1817 : 4014453 : if (pcst.elt (l - 1) == 0)
1818 : 1173872 : gcc_checking_assert (pcst.elt (l - 2) < 0);
1819 : 4014453 : if (pcst.elt (l - 1) == HOST_WIDE_INT_M1)
1820 : 8142 : gcc_checking_assert (pcst.elt (l - 2) >= 0);
1821 : : }
1822 : :
1823 : 9312885174 : wide_int cst = wide_int::from (pcst, prec, sgn);
1824 : 9312885174 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1825 : :
1826 : 9312885174 : enum tree_code code = TREE_CODE (type);
1827 : 9312885174 : if (code == POINTER_TYPE || code == REFERENCE_TYPE)
1828 : : {
1829 : : /* Cache NULL pointer and zero bounds. */
1830 : 171148317 : if (cst == 0)
1831 : : ix = 0;
1832 : : /* Cache upper bounds of pointers. */
1833 : 33506365 : else if (cst == wi::max_value (prec, sgn))
1834 : : ix = 1;
1835 : : /* Cache 1 which is used for a non-zero range. */
1836 : 31376353 : else if (cst == 1)
1837 : : ix = 2;
1838 : :
1839 : : if (ix >= 0)
1840 : : {
1841 : 143666663 : t = cache_wide_int_in_type_cache (type, cst, ix, 3);
1842 : : /* Make sure no one is clobbering the shared constant. */
1843 : 143666663 : gcc_checking_assert (TREE_TYPE (t) == type
1844 : : && cst == wi::to_wide (t));
1845 : 143666663 : return t;
1846 : : }
1847 : : }
1848 : 9169218511 : if (ext_len == 1)
1849 : : {
1850 : : /* We just need to store a single HOST_WIDE_INT. */
1851 : 9102696882 : HOST_WIDE_INT hwi;
1852 : 9102696882 : if (TYPE_UNSIGNED (type))
1853 : 6164493970 : hwi = cst.to_uhwi ();
1854 : : else
1855 : 2938203300 : hwi = cst.to_shwi ();
1856 : :
1857 : 9102696882 : switch (code)
1858 : : {
1859 : 210213 : case NULLPTR_TYPE:
1860 : 210213 : gcc_assert (hwi == 0);
1861 : : /* Fallthru. */
1862 : :
1863 : : case POINTER_TYPE:
1864 : : case REFERENCE_TYPE:
1865 : : /* Ignore pointers, as they were already handled above. */
1866 : : break;
1867 : :
1868 : 112567049 : case BOOLEAN_TYPE:
1869 : : /* Cache false or true. */
1870 : 112567049 : limit = 2;
1871 : 112567049 : if (IN_RANGE (hwi, 0, 1))
1872 : 112390859 : ix = hwi;
1873 : : break;
1874 : :
1875 : 8947684597 : case INTEGER_TYPE:
1876 : 8947684597 : case OFFSET_TYPE:
1877 : 8947684597 : case BITINT_TYPE:
1878 : 8947684597 : if (TYPE_SIGN (type) == UNSIGNED)
1879 : : {
1880 : : /* Cache [0, N). */
1881 : 6015781224 : limit = param_integer_share_limit;
1882 : 6015781224 : if (IN_RANGE (hwi, 0, param_integer_share_limit - 1))
1883 : 5827043681 : ix = hwi;
1884 : : }
1885 : : else
1886 : : {
1887 : : /* Cache [-1, N). */
1888 : 2931903373 : limit = param_integer_share_limit + 1;
1889 : 2931903373 : if (IN_RANGE (hwi, -1, param_integer_share_limit - 1))
1890 : 2822950347 : ix = hwi + 1;
1891 : : }
1892 : : break;
1893 : :
1894 : : case ENUMERAL_TYPE:
1895 : : break;
1896 : :
1897 : 0 : default:
1898 : 0 : gcc_unreachable ();
1899 : : }
1900 : :
1901 : 9102696882 : if (ix >= 0)
1902 : : {
1903 : 8762384887 : t = cache_wide_int_in_type_cache (type, cst, ix, limit);
1904 : : /* Make sure no one is clobbering the shared constant. */
1905 : 17524769774 : gcc_checking_assert (TREE_TYPE (t) == type
1906 : : && TREE_INT_CST_NUNITS (t) == 1
1907 : : && TREE_INT_CST_EXT_NUNITS (t) == 1
1908 : : && TREE_INT_CST_ELT (t, 0) == hwi);
1909 : : return t;
1910 : : }
1911 : : else
1912 : : {
1913 : : /* Use the cache of larger shared ints, using int_cst_node as
1914 : : a temporary. */
1915 : :
1916 : 340311995 : TREE_INT_CST_ELT (int_cst_node, 0) = hwi;
1917 : 340311995 : TREE_TYPE (int_cst_node) = type;
1918 : :
1919 : 340311995 : tree *slot = int_cst_hash_table->find_slot (int_cst_node, INSERT);
1920 : 340311995 : t = *slot;
1921 : 340311995 : if (!t)
1922 : : {
1923 : : /* Insert this one into the hash table. */
1924 : 78040064 : t = int_cst_node;
1925 : 78040064 : *slot = t;
1926 : : /* Make a new node for next time round. */
1927 : 78040064 : int_cst_node = make_int_cst (1, 1);
1928 : : }
1929 : : }
1930 : : }
1931 : : else
1932 : : {
1933 : : /* The value either hashes properly or we drop it on the floor
1934 : : for the gc to take care of. There will not be enough of them
1935 : : to worry about. */
1936 : :
1937 : 66521629 : tree nt = build_new_int_cst (type, cst);
1938 : 66521629 : tree *slot = int_cst_hash_table->find_slot (nt, INSERT);
1939 : 66521629 : t = *slot;
1940 : 66521629 : if (!t)
1941 : : {
1942 : : /* Insert this one into the hash table. */
1943 : 11997274 : t = nt;
1944 : 11997274 : *slot = t;
1945 : : }
1946 : : else
1947 : 54524355 : ggc_free (nt);
1948 : : }
1949 : :
1950 : : return t;
1951 : 9312885174 : }
1952 : :
1953 : : hashval_t
1954 : 0 : poly_int_cst_hasher::hash (tree t)
1955 : : {
1956 : 0 : inchash::hash hstate;
1957 : :
1958 : 0 : hstate.add_int (TYPE_UID (TREE_TYPE (t)));
1959 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1960 : 0 : hstate.add_wide_int (wi::to_wide (POLY_INT_CST_COEFF (t, i)));
1961 : :
1962 : 0 : return hstate.end ();
1963 : : }
1964 : :
1965 : : bool
1966 : 0 : poly_int_cst_hasher::equal (tree x, const compare_type &y)
1967 : : {
1968 : 0 : if (TREE_TYPE (x) != y.first)
1969 : : return false;
1970 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1971 : 0 : if (wi::to_wide (POLY_INT_CST_COEFF (x, i)) != y.second->coeffs[i])
1972 : : return false;
1973 : : return true;
1974 : : }
1975 : :
1976 : : /* Build a POLY_INT_CST node with type TYPE and with the elements in VALUES.
1977 : : The elements must also have type TYPE. */
1978 : :
1979 : : tree
1980 : 0 : build_poly_int_cst (tree type, const poly_wide_int_ref &values)
1981 : : {
1982 : 0 : unsigned int prec = TYPE_PRECISION (type);
1983 : 0 : gcc_assert (prec <= values.coeffs[0].get_precision ());
1984 : 0 : poly_wide_int c = poly_wide_int::from (values, prec, SIGNED);
1985 : :
1986 : 0 : inchash::hash h;
1987 : 0 : h.add_int (TYPE_UID (type));
1988 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1989 : 0 : h.add_wide_int (c.coeffs[i]);
1990 : 0 : poly_int_cst_hasher::compare_type comp (type, &c);
1991 : 0 : tree *slot = poly_int_cst_hash_table->find_slot_with_hash (comp, h.end (),
1992 : : INSERT);
1993 : 0 : if (*slot == NULL_TREE)
1994 : : {
1995 : : tree coeffs[NUM_POLY_INT_COEFFS];
1996 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1997 : 0 : coeffs[i] = wide_int_to_tree_1 (type, c.coeffs[i]);
1998 : 0 : *slot = build_new_poly_int_cst (type, coeffs);
1999 : : }
2000 : 0 : return *slot;
2001 : 0 : }
2002 : :
2003 : : /* Create a constant tree with value VALUE in type TYPE. */
2004 : :
2005 : : tree
2006 : 9312885174 : wide_int_to_tree (tree type, const poly_wide_int_ref &value)
2007 : : {
2008 : 9312885174 : if (value.is_constant ())
2009 : 9312885174 : return wide_int_to_tree_1 (type, value.coeffs[0]);
2010 : : return build_poly_int_cst (type, value);
2011 : : }
2012 : :
2013 : : /* Insert INTEGER_CST T into a cache of integer constants. And return
2014 : : the cached constant (which may or may not be T). If MIGHT_DUPLICATE
2015 : : is false, and T falls into the type's 'smaller values' range, there
2016 : : cannot be an existing entry. Otherwise, if MIGHT_DUPLICATE is true,
2017 : : or the value is large, should an existing entry exist, it is
2018 : : returned (rather than inserting T). */
2019 : :
2020 : : tree
2021 : 585543 : cache_integer_cst (tree t, bool might_duplicate ATTRIBUTE_UNUSED)
2022 : : {
2023 : 585543 : tree type = TREE_TYPE (t);
2024 : 585543 : int ix = -1;
2025 : 585543 : int limit = 0;
2026 : 585543 : int prec = TYPE_PRECISION (type);
2027 : :
2028 : 585543 : gcc_assert (!TREE_OVERFLOW (t));
2029 : :
2030 : : /* The caching indices here must match those in
2031 : : wide_int_to_type_1. */
2032 : 585543 : switch (TREE_CODE (type))
2033 : : {
2034 : 0 : case NULLPTR_TYPE:
2035 : 0 : gcc_checking_assert (integer_zerop (t));
2036 : : /* Fallthru. */
2037 : :
2038 : 3994 : case POINTER_TYPE:
2039 : 3994 : case REFERENCE_TYPE:
2040 : 3994 : {
2041 : 3994 : if (integer_zerop (t))
2042 : : ix = 0;
2043 : 1628 : else if (integer_onep (t))
2044 : : ix = 2;
2045 : :
2046 : : if (ix >= 0)
2047 : : limit = 3;
2048 : : }
2049 : : break;
2050 : :
2051 : 10261 : case BOOLEAN_TYPE:
2052 : : /* Cache false or true. */
2053 : 10261 : limit = 2;
2054 : 10261 : if (wi::ltu_p (wi::to_wide (t), 2))
2055 : 0 : ix = TREE_INT_CST_ELT (t, 0);
2056 : : break;
2057 : :
2058 : 557239 : case INTEGER_TYPE:
2059 : 557239 : case OFFSET_TYPE:
2060 : 557239 : case BITINT_TYPE:
2061 : 557239 : if (TYPE_UNSIGNED (type))
2062 : : {
2063 : : /* Cache 0..N */
2064 : 418611 : limit = param_integer_share_limit;
2065 : :
2066 : : /* This is a little hokie, but if the prec is smaller than
2067 : : what is necessary to hold param_integer_share_limit, then the
2068 : : obvious test will not get the correct answer. */
2069 : 418611 : if (prec < HOST_BITS_PER_WIDE_INT)
2070 : : {
2071 : 92619 : if (tree_to_uhwi (t)
2072 : 92619 : < (unsigned HOST_WIDE_INT) param_integer_share_limit)
2073 : 12621 : ix = tree_to_uhwi (t);
2074 : : }
2075 : 325992 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2076 : 247652 : ix = tree_to_uhwi (t);
2077 : : }
2078 : : else
2079 : : {
2080 : : /* Cache -1..N */
2081 : 138628 : limit = param_integer_share_limit + 1;
2082 : :
2083 : 138628 : if (integer_minus_onep (t))
2084 : : ix = 0;
2085 : 138186 : else if (!wi::neg_p (wi::to_wide (t)))
2086 : : {
2087 : 122093 : if (prec < HOST_BITS_PER_WIDE_INT)
2088 : : {
2089 : 116602 : if (tree_to_shwi (t) < param_integer_share_limit)
2090 : 108170 : ix = tree_to_shwi (t) + 1;
2091 : : }
2092 : 5491 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2093 : 4378 : ix = tree_to_shwi (t) + 1;
2094 : : }
2095 : : }
2096 : : break;
2097 : :
2098 : : case ENUMERAL_TYPE:
2099 : : /* The slot used by TYPE_CACHED_VALUES is used for the enum
2100 : : members. */
2101 : : break;
2102 : :
2103 : 0 : default:
2104 : 0 : gcc_unreachable ();
2105 : : }
2106 : :
2107 : 375187 : if (ix >= 0)
2108 : : {
2109 : : /* Look for it in the type's vector of small shared ints. */
2110 : 376007 : if (!TYPE_CACHED_VALUES_P (type))
2111 : : {
2112 : 13357 : TYPE_CACHED_VALUES_P (type) = 1;
2113 : 13357 : TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
2114 : : }
2115 : :
2116 : 376007 : if (tree r = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix))
2117 : : {
2118 : 351539 : gcc_checking_assert (might_duplicate);
2119 : 351539 : t = r;
2120 : : }
2121 : : else
2122 : 24468 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
2123 : : }
2124 : : else
2125 : : {
2126 : : /* Use the cache of larger shared ints. */
2127 : 209536 : tree *slot = int_cst_hash_table->find_slot (t, INSERT);
2128 : 209536 : if (tree r = *slot)
2129 : : {
2130 : : /* If there is already an entry for the number verify it's the
2131 : : same value. */
2132 : 122637 : gcc_checking_assert (wi::to_wide (tree (r)) == wi::to_wide (t));
2133 : : /* And return the cached value. */
2134 : 122637 : t = r;
2135 : : }
2136 : : else
2137 : : /* Otherwise insert this one into the hash table. */
2138 : 86899 : *slot = t;
2139 : : }
2140 : :
2141 : 585543 : return t;
2142 : : }
2143 : :
2144 : :
2145 : : /* Builds an integer constant in TYPE such that lowest BITS bits are ones
2146 : : and the rest are zeros. */
2147 : :
2148 : : tree
2149 : 9325735 : build_low_bits_mask (tree type, unsigned bits)
2150 : : {
2151 : 9325735 : gcc_assert (bits <= TYPE_PRECISION (type));
2152 : :
2153 : 9325735 : return wide_int_to_tree (type, wi::mask (bits, false,
2154 : 9325735 : TYPE_PRECISION (type)));
2155 : : }
2156 : :
2157 : : /* Checks that X is integer constant that can be expressed in (unsigned)
2158 : : HOST_WIDE_INT without loss of precision. */
2159 : :
2160 : : bool
2161 : 648363207 : cst_and_fits_in_hwi (const_tree x)
2162 : : {
2163 : 648363207 : return (TREE_CODE (x) == INTEGER_CST
2164 : 648363207 : && (tree_fits_shwi_p (x) || tree_fits_uhwi_p (x)));
2165 : : }
2166 : :
2167 : : /* Build a newly constructed VECTOR_CST with the given values of
2168 : : (VECTOR_CST_)LOG2_NPATTERNS and (VECTOR_CST_)NELTS_PER_PATTERN. */
2169 : :
2170 : : tree
2171 : 3251066 : make_vector (unsigned log2_npatterns,
2172 : : unsigned int nelts_per_pattern MEM_STAT_DECL)
2173 : : {
2174 : 3251066 : gcc_assert (IN_RANGE (nelts_per_pattern, 1, 3));
2175 : 3251066 : tree t;
2176 : 3251066 : unsigned npatterns = 1 << log2_npatterns;
2177 : 3251066 : unsigned encoded_nelts = npatterns * nelts_per_pattern;
2178 : 3251066 : unsigned length = (sizeof (struct tree_vector)
2179 : : + (encoded_nelts - 1) * sizeof (tree));
2180 : :
2181 : 3251066 : record_node_allocation_statistics (VECTOR_CST, length);
2182 : :
2183 : 3251066 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2184 : :
2185 : 3251066 : TREE_SET_CODE (t, VECTOR_CST);
2186 : 3251066 : TREE_CONSTANT (t) = 1;
2187 : 3251066 : VECTOR_CST_LOG2_NPATTERNS (t) = log2_npatterns;
2188 : 3251066 : VECTOR_CST_NELTS_PER_PATTERN (t) = nelts_per_pattern;
2189 : :
2190 : 3251066 : return t;
2191 : : }
2192 : :
2193 : : /* Return a new VECTOR_CST node whose type is TYPE and whose values
2194 : : are extracted from V, a vector of CONSTRUCTOR_ELT. */
2195 : :
2196 : : tree
2197 : 672431 : build_vector_from_ctor (tree type, const vec<constructor_elt, va_gc> *v)
2198 : : {
2199 : 672431 : if (vec_safe_length (v) == 0)
2200 : 686 : return build_zero_cst (type);
2201 : :
2202 : 671745 : unsigned HOST_WIDE_INT idx, nelts, step = 1;
2203 : 671745 : tree value;
2204 : :
2205 : : /* If the vector is a VLA, build a VLA constant vector. */
2206 : 671745 : if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&nelts))
2207 : : {
2208 : : nelts = constant_lower_bound (TYPE_VECTOR_SUBPARTS (type));
2209 : : gcc_assert (vec_safe_length (v) <= nelts);
2210 : : step = 2;
2211 : : }
2212 : :
2213 : 671745 : tree_vector_builder vec (type, nelts, step);
2214 : 4463160 : FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
2215 : : {
2216 : 3791415 : if (TREE_CODE (value) == VECTOR_CST)
2217 : : {
2218 : : /* If NELTS is constant then this must be too. */
2219 : 368 : unsigned int sub_nelts = VECTOR_CST_NELTS (value).to_constant ();
2220 : 1424 : for (unsigned i = 0; i < sub_nelts; ++i)
2221 : 1056 : vec.quick_push (VECTOR_CST_ELT (value, i));
2222 : : }
2223 : : else
2224 : 3791047 : vec.quick_push (value);
2225 : : }
2226 : 1902896 : while (vec.length () < nelts * step)
2227 : 279703 : vec.quick_push (build_zero_cst (TREE_TYPE (type)));
2228 : :
2229 : 671745 : return vec.build ();
2230 : 671745 : }
2231 : :
2232 : : /* Build a vector of type VECTYPE where all the elements are SCs. */
2233 : : tree
2234 : 632119 : build_vector_from_val (tree vectype, tree sc)
2235 : : {
2236 : 632119 : unsigned HOST_WIDE_INT i, nunits;
2237 : :
2238 : 632119 : if (sc == error_mark_node)
2239 : : return sc;
2240 : :
2241 : : /* Verify that the vector type is suitable for SC. Note that there
2242 : : is some inconsistency in the type-system with respect to restrict
2243 : : qualifications of pointers. Vector types always have a main-variant
2244 : : element type and the qualification is applied to the vector-type.
2245 : : So TREE_TYPE (vector-type) does not return a properly qualified
2246 : : vector element-type. */
2247 : 632119 : gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
2248 : : TREE_TYPE (vectype)));
2249 : :
2250 : 632119 : if (CONSTANT_CLASS_P (sc))
2251 : : {
2252 : 601997 : tree_vector_builder v (vectype, 1, 1);
2253 : 601997 : v.quick_push (sc);
2254 : 601997 : return v.build ();
2255 : 601997 : }
2256 : 30122 : else if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
2257 : : return fold_build1 (VEC_DUPLICATE_EXPR, vectype, sc);
2258 : : else
2259 : : {
2260 : 30122 : vec<constructor_elt, va_gc> *v;
2261 : 30122 : vec_alloc (v, nunits);
2262 : 144512 : for (i = 0; i < nunits; ++i)
2263 : 114390 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
2264 : 30122 : return build_constructor (vectype, v);
2265 : : }
2266 : : }
2267 : :
2268 : : /* If TYPE is not a vector type, just return SC, otherwise return
2269 : : build_vector_from_val (TYPE, SC). */
2270 : :
2271 : : tree
2272 : 5220446 : build_uniform_cst (tree type, tree sc)
2273 : : {
2274 : 5220446 : if (!VECTOR_TYPE_P (type))
2275 : : return sc;
2276 : :
2277 : 249 : return build_vector_from_val (type, sc);
2278 : : }
2279 : :
2280 : : /* Build a vector series of type TYPE in which element I has the value
2281 : : BASE + I * STEP. The result is a constant if BASE and STEP are constant
2282 : : and a VEC_SERIES_EXPR otherwise. */
2283 : :
2284 : : tree
2285 : 18 : build_vec_series (tree type, tree base, tree step)
2286 : : {
2287 : 18 : if (integer_zerop (step))
2288 : 0 : return build_vector_from_val (type, base);
2289 : 18 : if (TREE_CODE (base) == INTEGER_CST && TREE_CODE (step) == INTEGER_CST)
2290 : : {
2291 : 18 : tree_vector_builder builder (type, 1, 3);
2292 : 18 : tree elt1 = wide_int_to_tree (TREE_TYPE (base),
2293 : 36 : wi::to_wide (base) + wi::to_wide (step));
2294 : 18 : tree elt2 = wide_int_to_tree (TREE_TYPE (base),
2295 : 36 : wi::to_wide (elt1) + wi::to_wide (step));
2296 : 18 : builder.quick_push (base);
2297 : 18 : builder.quick_push (elt1);
2298 : 18 : builder.quick_push (elt2);
2299 : 18 : return builder.build ();
2300 : 18 : }
2301 : 0 : return build2 (VEC_SERIES_EXPR, type, base, step);
2302 : : }
2303 : :
2304 : : /* Return a vector with the same number of units and number of bits
2305 : : as VEC_TYPE, but in which the elements are a linear series of unsigned
2306 : : integers { BASE, BASE + STEP, BASE + STEP * 2, ... }. */
2307 : :
2308 : : tree
2309 : 1779 : build_index_vector (tree vec_type, poly_uint64 base, poly_uint64 step)
2310 : : {
2311 : 1779 : tree index_vec_type = vec_type;
2312 : 1779 : tree index_elt_type = TREE_TYPE (vec_type);
2313 : 1779 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vec_type);
2314 : 1779 : if (!INTEGRAL_TYPE_P (index_elt_type) || !TYPE_UNSIGNED (index_elt_type))
2315 : : {
2316 : 4 : index_elt_type = build_nonstandard_integer_type
2317 : 8 : (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (index_elt_type)), true);
2318 : 4 : index_vec_type = build_vector_type (index_elt_type, nunits);
2319 : : }
2320 : :
2321 : 1779 : tree_vector_builder v (index_vec_type, 1, 3);
2322 : 7116 : for (unsigned int i = 0; i < 3; ++i)
2323 : 5337 : v.quick_push (build_int_cstu (index_elt_type, base + i * step));
2324 : 1779 : return v.build ();
2325 : 1779 : }
2326 : :
2327 : : /* Return a VECTOR_CST of type VEC_TYPE in which the first NUM_A
2328 : : elements are A and the rest are B. */
2329 : :
2330 : : tree
2331 : 0 : build_vector_a_then_b (tree vec_type, unsigned int num_a, tree a, tree b)
2332 : : {
2333 : 0 : gcc_assert (known_le (num_a, TYPE_VECTOR_SUBPARTS (vec_type)));
2334 : 0 : unsigned int count = constant_lower_bound (TYPE_VECTOR_SUBPARTS (vec_type));
2335 : : /* Optimize the constant case. */
2336 : 0 : if ((count & 1) == 0 && TYPE_VECTOR_SUBPARTS (vec_type).is_constant ())
2337 : 0 : count /= 2;
2338 : 0 : tree_vector_builder builder (vec_type, count, 2);
2339 : 0 : for (unsigned int i = 0; i < count * 2; ++i)
2340 : 0 : builder.quick_push (i < num_a ? a : b);
2341 : 0 : return builder.build ();
2342 : 0 : }
2343 : :
2344 : : /* Something has messed with the elements of CONSTRUCTOR C after it was built;
2345 : : calculate TREE_CONSTANT and TREE_SIDE_EFFECTS. */
2346 : :
2347 : : void
2348 : 92190805 : recompute_constructor_flags (tree c)
2349 : : {
2350 : 92190805 : unsigned int i;
2351 : 92190805 : tree val;
2352 : 92190805 : bool constant_p = true;
2353 : 92190805 : bool side_effects_p = false;
2354 : 92190805 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2355 : :
2356 : 204096190 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2357 : : {
2358 : : /* Mostly ctors will have elts that don't have side-effects, so
2359 : : the usual case is to scan all the elements. Hence a single
2360 : : loop for both const and side effects, rather than one loop
2361 : : each (with early outs). */
2362 : 111905385 : if (!TREE_CONSTANT (val))
2363 : 16072478 : constant_p = false;
2364 : 111905385 : if (TREE_SIDE_EFFECTS (val))
2365 : 3063692 : side_effects_p = true;
2366 : : }
2367 : :
2368 : 92190805 : TREE_SIDE_EFFECTS (c) = side_effects_p;
2369 : 92190805 : TREE_CONSTANT (c) = constant_p;
2370 : 92190805 : }
2371 : :
2372 : : /* Make sure that TREE_CONSTANT and TREE_SIDE_EFFECTS are correct for
2373 : : CONSTRUCTOR C. */
2374 : :
2375 : : void
2376 : 12368075 : verify_constructor_flags (tree c)
2377 : : {
2378 : 12368075 : unsigned int i;
2379 : 12368075 : tree val;
2380 : 12368075 : bool constant_p = TREE_CONSTANT (c);
2381 : 12368075 : bool side_effects_p = TREE_SIDE_EFFECTS (c);
2382 : 12368075 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2383 : :
2384 : 68717846 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2385 : : {
2386 : 56349771 : if (constant_p && !TREE_CONSTANT (val))
2387 : 0 : internal_error ("non-constant element in constant CONSTRUCTOR");
2388 : 56349771 : if (!side_effects_p && TREE_SIDE_EFFECTS (val))
2389 : 0 : internal_error ("side-effects element in no-side-effects CONSTRUCTOR");
2390 : : }
2391 : 12368075 : }
2392 : :
2393 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2394 : : are in the vec pointed to by VALS. */
2395 : : tree
2396 : 75991797 : build_constructor (tree type, vec<constructor_elt, va_gc> *vals MEM_STAT_DECL)
2397 : : {
2398 : 75991797 : tree c = make_node (CONSTRUCTOR PASS_MEM_STAT);
2399 : :
2400 : 75991797 : TREE_TYPE (c) = type;
2401 : 75991797 : CONSTRUCTOR_ELTS (c) = vals;
2402 : :
2403 : 75991797 : recompute_constructor_flags (c);
2404 : :
2405 : 75991797 : return c;
2406 : : }
2407 : :
2408 : : /* Build a CONSTRUCTOR node made of a single initializer, with the specified
2409 : : INDEX and VALUE. */
2410 : : tree
2411 : 3993 : build_constructor_single (tree type, tree index, tree value)
2412 : : {
2413 : 3993 : vec<constructor_elt, va_gc> *v;
2414 : 3993 : constructor_elt elt = {index, value};
2415 : :
2416 : 3993 : vec_alloc (v, 1);
2417 : 3993 : v->quick_push (elt);
2418 : :
2419 : 3993 : return build_constructor (type, v);
2420 : : }
2421 : :
2422 : :
2423 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2424 : : are in a list pointed to by VALS. */
2425 : : tree
2426 : 1005 : build_constructor_from_list (tree type, tree vals)
2427 : : {
2428 : 1005 : tree t;
2429 : 1005 : vec<constructor_elt, va_gc> *v = NULL;
2430 : :
2431 : 1005 : if (vals)
2432 : : {
2433 : 1005 : vec_alloc (v, list_length (vals));
2434 : 20820 : for (t = vals; t; t = TREE_CHAIN (t))
2435 : 19815 : CONSTRUCTOR_APPEND_ELT (v, TREE_PURPOSE (t), TREE_VALUE (t));
2436 : : }
2437 : :
2438 : 1005 : return build_constructor (type, v);
2439 : : }
2440 : :
2441 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2442 : : are in a vector pointed to by VALS. Note that the TREE_PURPOSE
2443 : : fields in the constructor remain null. */
2444 : :
2445 : : tree
2446 : 1525 : build_constructor_from_vec (tree type, const vec<tree, va_gc> *vals)
2447 : : {
2448 : 1525 : vec<constructor_elt, va_gc> *v = NULL;
2449 : :
2450 : 73805 : for (tree t : vals)
2451 : 72280 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t);
2452 : :
2453 : 1525 : return build_constructor (type, v);
2454 : : }
2455 : :
2456 : : /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
2457 : : of elements, provided as index/value pairs. */
2458 : :
2459 : : tree
2460 : 38924 : build_constructor_va (tree type, int nelts, ...)
2461 : : {
2462 : 38924 : vec<constructor_elt, va_gc> *v = NULL;
2463 : 38924 : va_list p;
2464 : :
2465 : 38924 : va_start (p, nelts);
2466 : 38924 : vec_alloc (v, nelts);
2467 : 38924 : while (nelts--)
2468 : : {
2469 : 116965 : tree index = va_arg (p, tree);
2470 : 116965 : tree value = va_arg (p, tree);
2471 : 272854 : CONSTRUCTOR_APPEND_ELT (v, index, value);
2472 : : }
2473 : 38924 : va_end (p);
2474 : 38924 : return build_constructor (type, v);
2475 : : }
2476 : :
2477 : : /* Return a node of type TYPE for which TREE_CLOBBER_P is true. */
2478 : :
2479 : : tree
2480 : 8079560 : build_clobber (tree type, enum clobber_kind kind)
2481 : : {
2482 : 8079560 : tree clobber = build_constructor (type, NULL);
2483 : 8079560 : TREE_THIS_VOLATILE (clobber) = true;
2484 : 8079560 : CLOBBER_KIND (clobber) = kind;
2485 : 8079560 : return clobber;
2486 : : }
2487 : :
2488 : : /* Return a new FIXED_CST node whose type is TYPE and value is F. */
2489 : :
2490 : : tree
2491 : 54 : build_fixed (tree type, FIXED_VALUE_TYPE f)
2492 : : {
2493 : 54 : tree v;
2494 : 54 : FIXED_VALUE_TYPE *fp;
2495 : :
2496 : 54 : v = make_node (FIXED_CST);
2497 : 54 : fp = ggc_alloc<fixed_value> ();
2498 : 54 : memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
2499 : :
2500 : 54 : TREE_TYPE (v) = type;
2501 : 54 : TREE_FIXED_CST_PTR (v) = fp;
2502 : 54 : return v;
2503 : : }
2504 : :
2505 : : /* Return a new REAL_CST node whose type is TYPE and value is D. */
2506 : :
2507 : : tree
2508 : 43202372 : build_real (tree type, REAL_VALUE_TYPE d)
2509 : : {
2510 : 43202372 : tree v;
2511 : 43202372 : int overflow = 0;
2512 : :
2513 : : /* dconst{0,1,2,m1,half} are used in various places in
2514 : : the middle-end and optimizers, allow them here
2515 : : even for decimal floating point types as an exception
2516 : : by converting them to decimal. */
2517 : 43202372 : if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type))
2518 : 610433 : && (d.cl == rvc_normal || d.cl == rvc_zero)
2519 : 43810759 : && !d.decimal)
2520 : : {
2521 : 606 : if (memcmp (&d, &dconst1, sizeof (d)) == 0)
2522 : 0 : decimal_real_from_string (&d, "1");
2523 : 606 : else if (memcmp (&d, &dconst2, sizeof (d)) == 0)
2524 : 22 : decimal_real_from_string (&d, "2");
2525 : 584 : else if (memcmp (&d, &dconstm1, sizeof (d)) == 0)
2526 : 90 : decimal_real_from_string (&d, "-1");
2527 : 494 : else if (memcmp (&d, &dconsthalf, sizeof (d)) == 0)
2528 : 0 : decimal_real_from_string (&d, "0.5");
2529 : 494 : else if (memcmp (&d, &dconst0, sizeof (d)) == 0)
2530 : : {
2531 : : /* Make sure to give zero the minimum quantum exponent for
2532 : : the type (which corresponds to all bits zero). */
2533 : 494 : const struct real_format *fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
2534 : 494 : char buf[16];
2535 : 494 : sprintf (buf, "0e%d", fmt->emin - fmt->p);
2536 : 494 : decimal_real_from_string (&d, buf);
2537 : : }
2538 : : else
2539 : 0 : gcc_unreachable ();
2540 : : }
2541 : :
2542 : : /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
2543 : : Consider doing it via real_convert now. */
2544 : :
2545 : 43202372 : v = make_node (REAL_CST);
2546 : 43202372 : TREE_TYPE (v) = type;
2547 : 43202372 : memcpy (TREE_REAL_CST_PTR (v), &d, sizeof (REAL_VALUE_TYPE));
2548 : 43202372 : TREE_OVERFLOW (v) = overflow;
2549 : 43202372 : return v;
2550 : : }
2551 : :
2552 : : /* Like build_real, but first truncate D to the type. */
2553 : :
2554 : : tree
2555 : 177446 : build_real_truncate (tree type, REAL_VALUE_TYPE d)
2556 : : {
2557 : 177446 : return build_real (type, real_value_truncate (TYPE_MODE (type), d));
2558 : : }
2559 : :
2560 : : /* Return a new REAL_CST node whose type is TYPE
2561 : : and whose value is the integer value of the INTEGER_CST node I. */
2562 : :
2563 : : REAL_VALUE_TYPE
2564 : 25099499 : real_value_from_int_cst (const_tree type, const_tree i)
2565 : : {
2566 : 25099499 : REAL_VALUE_TYPE d;
2567 : :
2568 : : /* Clear all bits of the real value type so that we can later do
2569 : : bitwise comparisons to see if two values are the same. */
2570 : 25099499 : memset (&d, 0, sizeof d);
2571 : :
2572 : 25099499 : real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, wi::to_wide (i),
2573 : 25099499 : TYPE_SIGN (TREE_TYPE (i)));
2574 : 25099499 : return d;
2575 : : }
2576 : :
2577 : : /* Given a tree representing an integer constant I, return a tree
2578 : : representing the same value as a floating-point constant of type TYPE. */
2579 : :
2580 : : tree
2581 : 24487686 : build_real_from_int_cst (tree type, const_tree i)
2582 : : {
2583 : 24487686 : tree v;
2584 : 24487686 : int overflow = TREE_OVERFLOW (i);
2585 : :
2586 : 24487686 : v = build_real (type, real_value_from_int_cst (type, i));
2587 : :
2588 : 24487686 : TREE_OVERFLOW (v) |= overflow;
2589 : 24487686 : return v;
2590 : : }
2591 : :
2592 : : /* Return a new REAL_CST node whose type is TYPE
2593 : : and whose value is the integer value I which has sign SGN. */
2594 : :
2595 : : tree
2596 : 133 : build_real_from_wide (tree type, const wide_int_ref &i, signop sgn)
2597 : : {
2598 : 133 : REAL_VALUE_TYPE d;
2599 : :
2600 : : /* Clear all bits of the real value type so that we can later do
2601 : : bitwise comparisons to see if two values are the same. */
2602 : 133 : memset (&d, 0, sizeof d);
2603 : :
2604 : 133 : real_from_integer (&d, TYPE_MODE (type), i, sgn);
2605 : 133 : return build_real (type, d);
2606 : : }
2607 : :
2608 : : /* Return a newly constructed STRING_CST node whose value is the LEN
2609 : : characters at STR when STR is nonnull, or all zeros otherwise.
2610 : : Note that for a C string literal, LEN should include the trailing NUL.
2611 : : The TREE_TYPE is not initialized. */
2612 : :
2613 : : tree
2614 : 93438098 : build_string (unsigned len, const char *str /*= NULL */)
2615 : : {
2616 : : /* Do not waste bytes provided by padding of struct tree_string. */
2617 : 93438098 : unsigned size = len + offsetof (struct tree_string, str) + 1;
2618 : :
2619 : 93438098 : record_node_allocation_statistics (STRING_CST, size);
2620 : :
2621 : 93438098 : tree s = (tree) ggc_internal_alloc (size);
2622 : :
2623 : 93438098 : memset (s, 0, sizeof (struct tree_typed));
2624 : 93438098 : TREE_SET_CODE (s, STRING_CST);
2625 : 93438098 : TREE_CONSTANT (s) = 1;
2626 : 93438098 : TREE_STRING_LENGTH (s) = len;
2627 : 93438098 : if (str)
2628 : 93428935 : memcpy (s->string.str, str, len);
2629 : : else
2630 : 9163 : memset (s->string.str, 0, len);
2631 : 93438098 : s->string.str[len] = '\0';
2632 : :
2633 : 93438098 : return s;
2634 : : }
2635 : :
2636 : : /* Return a newly constructed COMPLEX_CST node whose value is
2637 : : specified by the real and imaginary parts REAL and IMAG.
2638 : : Both REAL and IMAG should be constant nodes. TYPE, if specified,
2639 : : will be the type of the COMPLEX_CST; otherwise a new type will be made. */
2640 : :
2641 : : tree
2642 : 485017 : build_complex (tree type, tree real, tree imag)
2643 : : {
2644 : 485017 : gcc_assert (CONSTANT_CLASS_P (real));
2645 : 485017 : gcc_assert (CONSTANT_CLASS_P (imag));
2646 : :
2647 : 485017 : tree t = make_node (COMPLEX_CST);
2648 : :
2649 : 485017 : TREE_REALPART (t) = real;
2650 : 485017 : TREE_IMAGPART (t) = imag;
2651 : 485017 : TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
2652 : 485017 : TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
2653 : 485017 : return t;
2654 : : }
2655 : :
2656 : : /* Build a complex (inf +- 0i), such as for the result of cproj.
2657 : : TYPE is the complex tree type of the result. If NEG is true, the
2658 : : imaginary zero is negative. */
2659 : :
2660 : : tree
2661 : 840 : build_complex_inf (tree type, bool neg)
2662 : : {
2663 : 840 : REAL_VALUE_TYPE rzero = dconst0;
2664 : :
2665 : 840 : rzero.sign = neg;
2666 : 840 : return build_complex (type, build_real (TREE_TYPE (type), dconstinf),
2667 : 840 : build_real (TREE_TYPE (type), rzero));
2668 : : }
2669 : :
2670 : : /* Return the constant 1 in type TYPE. If TYPE has several elements, each
2671 : : element is set to 1. In particular, this is 1 + i for complex types. */
2672 : :
2673 : : tree
2674 : 3768 : build_each_one_cst (tree type)
2675 : : {
2676 : 3768 : if (TREE_CODE (type) == COMPLEX_TYPE)
2677 : : {
2678 : 0 : tree scalar = build_one_cst (TREE_TYPE (type));
2679 : 0 : return build_complex (type, scalar, scalar);
2680 : : }
2681 : : else
2682 : 3768 : return build_one_cst (type);
2683 : : }
2684 : :
2685 : : /* Return a constant of arithmetic type TYPE which is the
2686 : : multiplicative identity of the set TYPE. */
2687 : :
2688 : : tree
2689 : 9514607 : build_one_cst (tree type)
2690 : : {
2691 : 9514607 : switch (TREE_CODE (type))
2692 : : {
2693 : 9500544 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2694 : 9500544 : case POINTER_TYPE: case REFERENCE_TYPE:
2695 : 9500544 : case OFFSET_TYPE: case BITINT_TYPE:
2696 : 9500544 : return build_int_cst (type, 1);
2697 : :
2698 : 10511 : case REAL_TYPE:
2699 : 10511 : return build_real (type, dconst1);
2700 : :
2701 : 0 : case FIXED_POINT_TYPE:
2702 : : /* We can only generate 1 for accum types. */
2703 : 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2704 : 0 : return build_fixed (type, FCONST1 (TYPE_MODE (type)));
2705 : :
2706 : 549 : case VECTOR_TYPE:
2707 : 549 : {
2708 : 549 : tree scalar = build_one_cst (TREE_TYPE (type));
2709 : :
2710 : 549 : return build_vector_from_val (type, scalar);
2711 : : }
2712 : :
2713 : 3003 : case COMPLEX_TYPE:
2714 : 6006 : return build_complex (type,
2715 : 3003 : build_one_cst (TREE_TYPE (type)),
2716 : 6006 : build_zero_cst (TREE_TYPE (type)));
2717 : :
2718 : 0 : default:
2719 : 0 : gcc_unreachable ();
2720 : : }
2721 : : }
2722 : :
2723 : : /* Return an integer of type TYPE containing all 1's in as much precision as
2724 : : it contains, or a complex or vector whose subparts are such integers. */
2725 : :
2726 : : tree
2727 : 1726167 : build_all_ones_cst (tree type)
2728 : : {
2729 : 1726167 : if (TREE_CODE (type) == COMPLEX_TYPE)
2730 : : {
2731 : 0 : tree scalar = build_all_ones_cst (TREE_TYPE (type));
2732 : 0 : return build_complex (type, scalar, scalar);
2733 : : }
2734 : : else
2735 : 1726167 : return build_minus_one_cst (type);
2736 : : }
2737 : :
2738 : : /* Return a constant of arithmetic type TYPE which is the
2739 : : opposite of the multiplicative identity of the set TYPE. */
2740 : :
2741 : : tree
2742 : 2339557 : build_minus_one_cst (tree type)
2743 : : {
2744 : 2339557 : switch (TREE_CODE (type))
2745 : : {
2746 : 2221653 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2747 : 2221653 : case POINTER_TYPE: case REFERENCE_TYPE:
2748 : 2221653 : case OFFSET_TYPE: case BITINT_TYPE:
2749 : 2221653 : return build_int_cst (type, -1);
2750 : :
2751 : 9798 : case REAL_TYPE:
2752 : 9798 : return build_real (type, dconstm1);
2753 : :
2754 : 0 : case FIXED_POINT_TYPE:
2755 : : /* We can only generate 1 for accum types. */
2756 : 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2757 : 0 : return build_fixed (type,
2758 : : fixed_from_double_int (double_int_minus_one,
2759 : 0 : SCALAR_TYPE_MODE (type)));
2760 : :
2761 : 108106 : case VECTOR_TYPE:
2762 : 108106 : {
2763 : 108106 : tree scalar = build_minus_one_cst (TREE_TYPE (type));
2764 : :
2765 : 108106 : return build_vector_from_val (type, scalar);
2766 : : }
2767 : :
2768 : 0 : case COMPLEX_TYPE:
2769 : 0 : return build_complex (type,
2770 : 0 : build_minus_one_cst (TREE_TYPE (type)),
2771 : 0 : build_zero_cst (TREE_TYPE (type)));
2772 : :
2773 : 0 : default:
2774 : 0 : gcc_unreachable ();
2775 : : }
2776 : : }
2777 : :
2778 : : /* Build 0 constant of type TYPE. This is used by constructor folding
2779 : : and thus the constant should be represented in memory by
2780 : : zero(es). */
2781 : :
2782 : : tree
2783 : 88085861 : build_zero_cst (tree type)
2784 : : {
2785 : 88085861 : switch (TREE_CODE (type))
2786 : : {
2787 : 87510274 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2788 : 87510274 : case POINTER_TYPE: case REFERENCE_TYPE:
2789 : 87510274 : case OFFSET_TYPE: case NULLPTR_TYPE: case BITINT_TYPE:
2790 : 87510274 : return build_int_cst (type, 0);
2791 : :
2792 : 230282 : case REAL_TYPE:
2793 : 230282 : return build_real (type, dconst0);
2794 : :
2795 : 0 : case FIXED_POINT_TYPE:
2796 : 0 : return build_fixed (type, FCONST0 (TYPE_MODE (type)));
2797 : :
2798 : 156282 : case VECTOR_TYPE:
2799 : 156282 : {
2800 : 156282 : tree scalar = build_zero_cst (TREE_TYPE (type));
2801 : :
2802 : 156282 : return build_vector_from_val (type, scalar);
2803 : : }
2804 : :
2805 : 3082 : case COMPLEX_TYPE:
2806 : 3082 : {
2807 : 3082 : tree zero = build_zero_cst (TREE_TYPE (type));
2808 : :
2809 : 3082 : return build_complex (type, zero, zero);
2810 : : }
2811 : :
2812 : 185941 : default:
2813 : 185941 : if (!AGGREGATE_TYPE_P (type))
2814 : 1 : return fold_convert (type, integer_zero_node);
2815 : 185940 : return build_constructor (type, NULL);
2816 : : }
2817 : : }
2818 : :
2819 : : /* Build a constant of integer type TYPE, made of VALUE's bits replicated
2820 : : every WIDTH bits to fit TYPE's precision. */
2821 : :
2822 : : tree
2823 : 14 : build_replicated_int_cst (tree type, unsigned int width, HOST_WIDE_INT value)
2824 : : {
2825 : 14 : int n = ((TYPE_PRECISION (type) + HOST_BITS_PER_WIDE_INT - 1)
2826 : 14 : / HOST_BITS_PER_WIDE_INT);
2827 : 14 : unsigned HOST_WIDE_INT low, mask;
2828 : 14 : HOST_WIDE_INT a[WIDE_INT_MAX_INL_ELTS];
2829 : 14 : int i;
2830 : :
2831 : 14 : gcc_assert (n && n <= WIDE_INT_MAX_INL_ELTS);
2832 : :
2833 : 14 : if (width == HOST_BITS_PER_WIDE_INT)
2834 : 0 : low = value;
2835 : : else
2836 : : {
2837 : 14 : mask = (HOST_WIDE_INT_1U << width) - 1;
2838 : 14 : low = (unsigned HOST_WIDE_INT) ~0 / mask * (value & mask);
2839 : : }
2840 : :
2841 : 28 : for (i = 0; i < n; i++)
2842 : 14 : a[i] = low;
2843 : :
2844 : 14 : gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
2845 : 14 : return wide_int_to_tree (type, wide_int::from_array (a, n,
2846 : 14 : TYPE_PRECISION (type)));
2847 : : }
2848 : :
2849 : : /* If floating-point type TYPE has an IEEE-style sign bit, return an
2850 : : unsigned constant in which only the sign bit is set. Return null
2851 : : otherwise. */
2852 : :
2853 : : tree
2854 : 0 : sign_mask_for (tree type)
2855 : : {
2856 : : /* Avoid having to choose between a real-only sign and a pair of signs.
2857 : : This could be relaxed if the choice becomes obvious later. */
2858 : 0 : if (TREE_CODE (type) == COMPLEX_TYPE)
2859 : : return NULL_TREE;
2860 : :
2861 : 0 : auto eltmode = as_a<scalar_float_mode> (element_mode (type));
2862 : 0 : auto bits = REAL_MODE_FORMAT (eltmode)->ieee_bits;
2863 : 0 : if (!bits || !pow2p_hwi (bits))
2864 : : return NULL_TREE;
2865 : :
2866 : 0 : tree inttype = unsigned_type_for (type);
2867 : 0 : if (!inttype)
2868 : : return NULL_TREE;
2869 : :
2870 : 0 : auto mask = wi::set_bit_in_zero (bits - 1, bits);
2871 : 0 : if (VECTOR_TYPE_P (inttype))
2872 : : {
2873 : 0 : tree elt = wide_int_to_tree (TREE_TYPE (inttype), mask);
2874 : 0 : return build_vector_from_val (inttype, elt);
2875 : : }
2876 : 0 : return wide_int_to_tree (inttype, mask);
2877 : 0 : }
2878 : :
2879 : : /* Build a BINFO with LEN language slots. */
2880 : :
2881 : : tree
2882 : 93354104 : make_tree_binfo (unsigned base_binfos MEM_STAT_DECL)
2883 : : {
2884 : 93354104 : tree t;
2885 : 93354104 : size_t length = (offsetof (struct tree_binfo, base_binfos)
2886 : 93354104 : + vec<tree, va_gc>::embedded_size (base_binfos));
2887 : :
2888 : 93354104 : record_node_allocation_statistics (TREE_BINFO, length);
2889 : :
2890 : 93354104 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
2891 : :
2892 : 93354104 : memset (t, 0, offsetof (struct tree_binfo, base_binfos));
2893 : :
2894 : 93354104 : TREE_SET_CODE (t, TREE_BINFO);
2895 : :
2896 : 93354104 : BINFO_BASE_BINFOS (t)->embedded_init (base_binfos);
2897 : :
2898 : 93354104 : return t;
2899 : : }
2900 : :
2901 : : /* Create a CASE_LABEL_EXPR tree node and return it. */
2902 : :
2903 : : tree
2904 : 5167718 : build_case_label (tree low_value, tree high_value, tree label_decl)
2905 : : {
2906 : 5167718 : tree t = make_node (CASE_LABEL_EXPR);
2907 : :
2908 : 5167718 : TREE_TYPE (t) = void_type_node;
2909 : 5167718 : SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (label_decl));
2910 : :
2911 : 5167718 : CASE_LOW (t) = low_value;
2912 : 5167718 : CASE_HIGH (t) = high_value;
2913 : 5167718 : CASE_LABEL (t) = label_decl;
2914 : 5167718 : CASE_CHAIN (t) = NULL_TREE;
2915 : :
2916 : 5167718 : return t;
2917 : : }
2918 : :
2919 : : /* Build a newly constructed INTEGER_CST node. LEN and EXT_LEN are the
2920 : : values of TREE_INT_CST_NUNITS and TREE_INT_CST_EXT_NUNITS respectively.
2921 : : The latter determines the length of the HOST_WIDE_INT vector. */
2922 : :
2923 : : tree
2924 : 204893985 : make_int_cst (int len, int ext_len MEM_STAT_DECL)
2925 : : {
2926 : 204893985 : tree t;
2927 : 204893985 : int length = ((ext_len - 1) * sizeof (HOST_WIDE_INT)
2928 : 204893985 : + sizeof (struct tree_int_cst));
2929 : :
2930 : 204893985 : gcc_assert (len);
2931 : 204893985 : record_node_allocation_statistics (INTEGER_CST, length);
2932 : :
2933 : 204893985 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2934 : :
2935 : 204893985 : TREE_SET_CODE (t, INTEGER_CST);
2936 : 204893985 : TREE_INT_CST_NUNITS (t) = len;
2937 : 204893985 : TREE_INT_CST_EXT_NUNITS (t) = ext_len;
2938 : 204893985 : TREE_CONSTANT (t) = 1;
2939 : :
2940 : 204893985 : return t;
2941 : : }
2942 : :
2943 : : /* Build a newly constructed TREE_VEC node of length LEN. */
2944 : :
2945 : : tree
2946 : 2612690395 : make_tree_vec (int len MEM_STAT_DECL)
2947 : : {
2948 : 2612690395 : tree t;
2949 : 2612690395 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2950 : :
2951 : 2612690395 : record_node_allocation_statistics (TREE_VEC, length);
2952 : :
2953 : 2612690395 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2954 : :
2955 : 2612690395 : TREE_SET_CODE (t, TREE_VEC);
2956 : 2612690395 : TREE_VEC_LENGTH (t) = len;
2957 : :
2958 : 2612690395 : return t;
2959 : : }
2960 : :
2961 : : /* Grow a TREE_VEC node to new length LEN. */
2962 : :
2963 : : tree
2964 : 140288 : grow_tree_vec (tree v, int len MEM_STAT_DECL)
2965 : : {
2966 : 140288 : gcc_assert (TREE_CODE (v) == TREE_VEC);
2967 : :
2968 : 140288 : int oldlen = TREE_VEC_LENGTH (v);
2969 : 140288 : gcc_assert (len > oldlen);
2970 : :
2971 : 140288 : size_t oldlength = (oldlen - 1) * sizeof (tree) + sizeof (struct tree_vec);
2972 : 140288 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2973 : :
2974 : 140288 : record_node_allocation_statistics (TREE_VEC, length - oldlength);
2975 : :
2976 : 140288 : v = (tree) ggc_realloc (v, length PASS_MEM_STAT);
2977 : :
2978 : 140288 : TREE_VEC_LENGTH (v) = len;
2979 : :
2980 : 140288 : return v;
2981 : : }
2982 : :
2983 : : /* Return true if EXPR is the constant zero, whether it is integral, float or
2984 : : fixed, and scalar, complex or vector. */
2985 : :
2986 : : bool
2987 : 16247271 : zerop (const_tree expr)
2988 : : {
2989 : 16247271 : return (integer_zerop (expr)
2990 : 11178534 : || real_zerop (expr)
2991 : 27011557 : || fixed_zerop (expr));
2992 : : }
2993 : :
2994 : : /* Return true if EXPR is the integer constant zero or a complex constant
2995 : : of zero, or a location wrapper for such a constant. */
2996 : :
2997 : : bool
2998 : 5618821833 : integer_zerop (const_tree expr)
2999 : : {
3000 : 5618821833 : STRIP_ANY_LOCATION_WRAPPER (expr);
3001 : :
3002 : 5618821833 : switch (TREE_CODE (expr))
3003 : : {
3004 : 4696828031 : case INTEGER_CST:
3005 : 4696828031 : return wi::to_wide (expr) == 0;
3006 : 1202620 : case COMPLEX_CST:
3007 : 1202620 : return (integer_zerop (TREE_REALPART (expr))
3008 : 1224742 : && integer_zerop (TREE_IMAGPART (expr)));
3009 : 2579289 : case VECTOR_CST:
3010 : 2579289 : return (VECTOR_CST_NPATTERNS (expr) == 1
3011 : 2441083 : && VECTOR_CST_DUPLICATE_P (expr)
3012 : 4623627 : && integer_zerop (VECTOR_CST_ENCODED_ELT (expr, 0)));
3013 : : default:
3014 : : return false;
3015 : : }
3016 : : }
3017 : :
3018 : : /* Return true if EXPR is the integer constant one or the corresponding
3019 : : complex constant, or a location wrapper for such a constant. */
3020 : :
3021 : : bool
3022 : 946951950 : integer_onep (const_tree expr)
3023 : : {
3024 : 946951950 : STRIP_ANY_LOCATION_WRAPPER (expr);
3025 : :
3026 : 946951950 : switch (TREE_CODE (expr))
3027 : : {
3028 : 808679823 : case INTEGER_CST:
3029 : 808679823 : return wi::eq_p (wi::to_widest (expr), 1);
3030 : 21352 : case COMPLEX_CST:
3031 : 21352 : return (integer_onep (TREE_REALPART (expr))
3032 : 21372 : && integer_zerop (TREE_IMAGPART (expr)));
3033 : 156508 : case VECTOR_CST:
3034 : 156508 : return (VECTOR_CST_NPATTERNS (expr) == 1
3035 : 141265 : && VECTOR_CST_DUPLICATE_P (expr)
3036 : 285606 : && integer_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3037 : : default:
3038 : : return false;
3039 : : }
3040 : : }
3041 : :
3042 : : /* Return true if EXPR is the integer constant one. For complex and vector,
3043 : : return true if every piece is the integer constant one.
3044 : : Also return true for location wrappers for such a constant. */
3045 : :
3046 : : bool
3047 : 755521 : integer_each_onep (const_tree expr)
3048 : : {
3049 : 755521 : STRIP_ANY_LOCATION_WRAPPER (expr);
3050 : :
3051 : 755521 : if (TREE_CODE (expr) == COMPLEX_CST)
3052 : 34 : return (integer_onep (TREE_REALPART (expr))
3053 : 48 : && integer_onep (TREE_IMAGPART (expr)));
3054 : : else
3055 : 755487 : return integer_onep (expr);
3056 : : }
3057 : :
3058 : : /* Return true if EXPR is an integer containing all 1's in as much precision
3059 : : as it contains, or a complex or vector whose subparts are such integers,
3060 : : or a location wrapper for such a constant. */
3061 : :
3062 : : bool
3063 : 275067136 : integer_all_onesp (const_tree expr)
3064 : : {
3065 : 275067136 : STRIP_ANY_LOCATION_WRAPPER (expr);
3066 : :
3067 : 275067136 : if (TREE_CODE (expr) == COMPLEX_CST
3068 : 926 : && integer_all_onesp (TREE_REALPART (expr))
3069 : 275067176 : && integer_all_onesp (TREE_IMAGPART (expr)))
3070 : : return true;
3071 : :
3072 : 275067100 : else if (TREE_CODE (expr) == VECTOR_CST)
3073 : 479084 : return (VECTOR_CST_NPATTERNS (expr) == 1
3074 : 437858 : && VECTOR_CST_DUPLICATE_P (expr)
3075 : 897943 : && integer_all_onesp (VECTOR_CST_ENCODED_ELT (expr, 0)));
3076 : :
3077 : 274588016 : else if (TREE_CODE (expr) != INTEGER_CST)
3078 : : return false;
3079 : :
3080 : 181159332 : return (wi::max_value (TYPE_PRECISION (TREE_TYPE (expr)), UNSIGNED)
3081 : 362319114 : == wi::to_wide (expr));
3082 : : }
3083 : :
3084 : : /* Return true if EXPR is the integer constant minus one, or a location
3085 : : wrapper for such a constant. */
3086 : :
3087 : : bool
3088 : 199868105 : integer_minus_onep (const_tree expr)
3089 : : {
3090 : 199868105 : STRIP_ANY_LOCATION_WRAPPER (expr);
3091 : :
3092 : 199868105 : if (TREE_CODE (expr) == COMPLEX_CST)
3093 : 9060 : return (integer_all_onesp (TREE_REALPART (expr))
3094 : 9064 : && integer_zerop (TREE_IMAGPART (expr)));
3095 : : else
3096 : 199859045 : return integer_all_onesp (expr);
3097 : : }
3098 : :
3099 : : /* Return true if EXPR is an integer constant that is a power of 2 (i.e., has
3100 : : only one bit on), or a location wrapper for such a constant. */
3101 : :
3102 : : bool
3103 : 21452329 : integer_pow2p (const_tree expr)
3104 : : {
3105 : 21452329 : STRIP_ANY_LOCATION_WRAPPER (expr);
3106 : :
3107 : 21452329 : if (TREE_CODE (expr) == COMPLEX_CST
3108 : 543 : && integer_pow2p (TREE_REALPART (expr))
3109 : 21452556 : && integer_zerop (TREE_IMAGPART (expr)))
3110 : : return true;
3111 : :
3112 : 21452176 : if (TREE_CODE (expr) != INTEGER_CST)
3113 : : return false;
3114 : :
3115 : 14757222 : return wi::popcount (wi::to_wide (expr)) == 1;
3116 : : }
3117 : :
3118 : : /* Return true if EXPR is an integer constant other than zero or a
3119 : : complex constant other than zero, or a location wrapper for such a
3120 : : constant. */
3121 : :
3122 : : bool
3123 : 138917988 : integer_nonzerop (const_tree expr)
3124 : : {
3125 : 138917988 : STRIP_ANY_LOCATION_WRAPPER (expr);
3126 : :
3127 : 138917988 : return ((TREE_CODE (expr) == INTEGER_CST
3128 : 65588567 : && wi::to_wide (expr) != 0)
3129 : 153719357 : || (TREE_CODE (expr) == COMPLEX_CST
3130 : 244 : && (integer_nonzerop (TREE_REALPART (expr))
3131 : 184 : || integer_nonzerop (TREE_IMAGPART (expr)))));
3132 : : }
3133 : :
3134 : : /* Return true if EXPR is the integer constant one. For vector,
3135 : : return true if every piece is the integer constant minus one
3136 : : (representing the value TRUE).
3137 : : Also return true for location wrappers for such a constant. */
3138 : :
3139 : : bool
3140 : 1124227 : integer_truep (const_tree expr)
3141 : : {
3142 : 1124227 : STRIP_ANY_LOCATION_WRAPPER (expr);
3143 : :
3144 : 1124227 : if (TREE_CODE (expr) == VECTOR_CST)
3145 : 16289 : return integer_all_onesp (expr);
3146 : 1107938 : return integer_onep (expr);
3147 : : }
3148 : :
3149 : : /* Return true if EXPR is the fixed-point constant zero, or a location wrapper
3150 : : for such a constant. */
3151 : :
3152 : : bool
3153 : 25038216 : fixed_zerop (const_tree expr)
3154 : : {
3155 : 25038216 : STRIP_ANY_LOCATION_WRAPPER (expr);
3156 : :
3157 : 25038216 : return (TREE_CODE (expr) == FIXED_CST
3158 : 25038216 : && TREE_FIXED_CST (expr).data.is_zero ());
3159 : : }
3160 : :
3161 : : /* Return the power of two represented by a tree node known to be a
3162 : : power of two. */
3163 : :
3164 : : int
3165 : 703178 : tree_log2 (const_tree expr)
3166 : : {
3167 : 703178 : if (TREE_CODE (expr) == COMPLEX_CST)
3168 : 0 : return tree_log2 (TREE_REALPART (expr));
3169 : :
3170 : 703178 : return wi::exact_log2 (wi::to_wide (expr));
3171 : : }
3172 : :
3173 : : /* Similar, but return the largest integer Y such that 2 ** Y is less
3174 : : than or equal to EXPR. */
3175 : :
3176 : : int
3177 : 2733108 : tree_floor_log2 (const_tree expr)
3178 : : {
3179 : 2733108 : if (TREE_CODE (expr) == COMPLEX_CST)
3180 : 0 : return tree_log2 (TREE_REALPART (expr));
3181 : :
3182 : 2733108 : return wi::floor_log2 (wi::to_wide (expr));
3183 : : }
3184 : :
3185 : : /* Return number of known trailing zero bits in EXPR, or, if the value of
3186 : : EXPR is known to be zero, the precision of it's type. */
3187 : :
3188 : : unsigned int
3189 : 82489754 : tree_ctz (const_tree expr)
3190 : : {
3191 : 164977792 : if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
3192 : 82496846 : && !POINTER_TYPE_P (TREE_TYPE (expr)))
3193 : : return 0;
3194 : :
3195 : 82489736 : unsigned int ret1, ret2, prec = TYPE_PRECISION (TREE_TYPE (expr));
3196 : 82489736 : switch (TREE_CODE (expr))
3197 : : {
3198 : 44029953 : case INTEGER_CST:
3199 : 44029953 : ret1 = wi::ctz (wi::to_wide (expr));
3200 : 44029953 : return MIN (ret1, prec);
3201 : 12535290 : case SSA_NAME:
3202 : 12535290 : ret1 = wi::ctz (get_nonzero_bits (expr));
3203 : 12535290 : return MIN (ret1, prec);
3204 : 2025723 : case PLUS_EXPR:
3205 : 2025723 : case MINUS_EXPR:
3206 : 2025723 : case BIT_IOR_EXPR:
3207 : 2025723 : case BIT_XOR_EXPR:
3208 : 2025723 : case MIN_EXPR:
3209 : 2025723 : case MAX_EXPR:
3210 : 2025723 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3211 : 2025723 : if (ret1 == 0)
3212 : : return ret1;
3213 : 934588 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3214 : 934588 : return MIN (ret1, ret2);
3215 : 0 : case POINTER_PLUS_EXPR:
3216 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3217 : 0 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3218 : : /* Second operand is sizetype, which could be in theory
3219 : : wider than pointer's precision. Make sure we never
3220 : : return more than prec. */
3221 : 0 : ret2 = MIN (ret2, prec);
3222 : 0 : return MIN (ret1, ret2);
3223 : 224 : case BIT_AND_EXPR:
3224 : 224 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3225 : 224 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3226 : 224 : return MAX (ret1, ret2);
3227 : 11657742 : case MULT_EXPR:
3228 : 11657742 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3229 : 11657742 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3230 : 11657742 : return MIN (ret1 + ret2, prec);
3231 : 0 : case LSHIFT_EXPR:
3232 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3233 : 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3234 : 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3235 : : {
3236 : 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3237 : 0 : return MIN (ret1 + ret2, prec);
3238 : : }
3239 : : return ret1;
3240 : 0 : case RSHIFT_EXPR:
3241 : 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3242 : 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3243 : : {
3244 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3245 : 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3246 : 0 : if (ret1 > ret2)
3247 : 0 : return ret1 - ret2;
3248 : : }
3249 : : return 0;
3250 : 5244 : case TRUNC_DIV_EXPR:
3251 : 5244 : case CEIL_DIV_EXPR:
3252 : 5244 : case FLOOR_DIV_EXPR:
3253 : 5244 : case ROUND_DIV_EXPR:
3254 : 5244 : case EXACT_DIV_EXPR:
3255 : 5244 : if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
3256 : 5244 : && tree_int_cst_sgn (TREE_OPERAND (expr, 1)) == 1)
3257 : : {
3258 : 5244 : int l = tree_log2 (TREE_OPERAND (expr, 1));
3259 : 5244 : if (l >= 0)
3260 : : {
3261 : 4117 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3262 : 4117 : ret2 = l;
3263 : 4117 : if (ret1 > ret2)
3264 : 0 : return ret1 - ret2;
3265 : : }
3266 : : }
3267 : : return 0;
3268 : 12214617 : CASE_CONVERT:
3269 : 12214617 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3270 : 12214617 : if (ret1 && ret1 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
3271 : : ret1 = prec;
3272 : 12214617 : return MIN (ret1, prec);
3273 : 0 : case SAVE_EXPR:
3274 : 0 : return tree_ctz (TREE_OPERAND (expr, 0));
3275 : 6907 : case COND_EXPR:
3276 : 6907 : ret1 = tree_ctz (TREE_OPERAND (expr, 1));
3277 : 6907 : if (ret1 == 0)
3278 : : return 0;
3279 : 163 : ret2 = tree_ctz (TREE_OPERAND (expr, 2));
3280 : 163 : return MIN (ret1, ret2);
3281 : 0 : case COMPOUND_EXPR:
3282 : 0 : return tree_ctz (TREE_OPERAND (expr, 1));
3283 : 218 : case ADDR_EXPR:
3284 : 218 : ret1 = get_pointer_alignment (CONST_CAST_TREE (expr));
3285 : 218 : if (ret1 > BITS_PER_UNIT)
3286 : : {
3287 : 218 : ret1 = ctz_hwi (ret1 / BITS_PER_UNIT);
3288 : 218 : return MIN (ret1, prec);
3289 : : }
3290 : : return 0;
3291 : : default:
3292 : : return 0;
3293 : : }
3294 : : }
3295 : :
3296 : : /* Return true if EXPR is the real constant zero. Trailing zeroes matter for
3297 : : decimal float constants, so don't return true for them.
3298 : : Also return true for location wrappers around such a constant. */
3299 : :
3300 : : bool
3301 : 569113447 : real_zerop (const_tree expr)
3302 : : {
3303 : 569113447 : STRIP_ANY_LOCATION_WRAPPER (expr);
3304 : :
3305 : 569113447 : switch (TREE_CODE (expr))
3306 : : {
3307 : 19843002 : case REAL_CST:
3308 : 19843002 : return real_equal (&TREE_REAL_CST (expr), &dconst0)
3309 : 19843002 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3310 : 44387 : case COMPLEX_CST:
3311 : 44387 : return real_zerop (TREE_REALPART (expr))
3312 : 57415 : && real_zerop (TREE_IMAGPART (expr));
3313 : 418550 : case VECTOR_CST:
3314 : 418550 : {
3315 : : /* Don't simply check for a duplicate because the predicate
3316 : : accepts both +0.0 and -0.0. */
3317 : 418550 : unsigned count = vector_cst_encoded_nelts (expr);
3318 : 444730 : for (unsigned int i = 0; i < count; ++i)
3319 : 427915 : if (!real_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3320 : : return false;
3321 : : return true;
3322 : : }
3323 : : default:
3324 : : return false;
3325 : : }
3326 : : }
3327 : :
3328 : : /* Return true if EXPR is the real constant one in real or complex form.
3329 : : Trailing zeroes matter for decimal float constants, so don't return
3330 : : true for them.
3331 : : Also return true for location wrappers around such a constant. */
3332 : :
3333 : : bool
3334 : 117589229 : real_onep (const_tree expr)
3335 : : {
3336 : 117589229 : STRIP_ANY_LOCATION_WRAPPER (expr);
3337 : :
3338 : 117589229 : switch (TREE_CODE (expr))
3339 : : {
3340 : 7459303 : case REAL_CST:
3341 : 7459303 : return real_equal (&TREE_REAL_CST (expr), &dconst1)
3342 : 7459303 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3343 : 12622 : case COMPLEX_CST:
3344 : 12622 : return real_onep (TREE_REALPART (expr))
3345 : 16111 : && real_zerop (TREE_IMAGPART (expr));
3346 : 60303 : case VECTOR_CST:
3347 : 60303 : return (VECTOR_CST_NPATTERNS (expr) == 1
3348 : 51787 : && VECTOR_CST_DUPLICATE_P (expr)
3349 : 103112 : && real_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3350 : : default:
3351 : : return false;
3352 : : }
3353 : : }
3354 : :
3355 : : /* Return true if EXPR is the real constant minus one. Trailing zeroes
3356 : : matter for decimal float constants, so don't return true for them.
3357 : : Also return true for location wrappers around such a constant. */
3358 : :
3359 : : bool
3360 : 118596202 : real_minus_onep (const_tree expr)
3361 : : {
3362 : 118596202 : STRIP_ANY_LOCATION_WRAPPER (expr);
3363 : :
3364 : 118596202 : switch (TREE_CODE (expr))
3365 : : {
3366 : 7394917 : case REAL_CST:
3367 : 7394917 : return real_equal (&TREE_REAL_CST (expr), &dconstm1)
3368 : 7394917 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3369 : 12602 : case COMPLEX_CST:
3370 : 12602 : return real_minus_onep (TREE_REALPART (expr))
3371 : 14974 : && real_zerop (TREE_IMAGPART (expr));
3372 : 62060 : case VECTOR_CST:
3373 : 62060 : return (VECTOR_CST_NPATTERNS (expr) == 1
3374 : 52976 : && VECTOR_CST_DUPLICATE_P (expr)
3375 : 105907 : && real_minus_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3376 : : default:
3377 : : return false;
3378 : : }
3379 : : }
3380 : :
3381 : : /* Return true if T could be a floating point zero. */
3382 : :
3383 : : bool
3384 : 694326 : real_maybe_zerop (const_tree expr)
3385 : : {
3386 : 694326 : switch (TREE_CODE (expr))
3387 : : {
3388 : 474966 : case REAL_CST:
3389 : : /* Can't use real_zerop here, as it always returns false for decimal
3390 : : floats. And can't use TREE_REAL_CST (expr).cl == rvc_zero
3391 : : either, as decimal zeros are rvc_normal. */
3392 : 474966 : return real_equal (&TREE_REAL_CST (expr), &dconst0);
3393 : 0 : case COMPLEX_CST:
3394 : 0 : return (real_maybe_zerop (TREE_REALPART (expr))
3395 : 0 : || real_maybe_zerop (TREE_IMAGPART (expr)));
3396 : 0 : case VECTOR_CST:
3397 : 0 : {
3398 : 0 : unsigned count = vector_cst_encoded_nelts (expr);
3399 : 0 : for (unsigned int i = 0; i < count; ++i)
3400 : 0 : if (real_maybe_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3401 : : return true;
3402 : : return false;
3403 : : }
3404 : : default:
3405 : : /* Perhaps for SSA_NAMEs we could query frange. */
3406 : : return true;
3407 : : }
3408 : : }
3409 : :
3410 : : /* True if EXP is a constant or a cast of a constant. */
3411 : :
3412 : : bool
3413 : 3693 : really_constant_p (const_tree exp)
3414 : : {
3415 : : /* This is not quite the same as STRIP_NOPS. It does more. */
3416 : 7394 : while (CONVERT_EXPR_P (exp)
3417 : 7446 : || TREE_CODE (exp) == NON_LVALUE_EXPR)
3418 : 60 : exp = TREE_OPERAND (exp, 0);
3419 : 3693 : return TREE_CONSTANT (exp);
3420 : : }
3421 : :
3422 : : /* Return true if T holds a polynomial pointer difference, storing it in
3423 : : *VALUE if so. A true return means that T's precision is no greater
3424 : : than 64 bits, which is the largest address space we support, so *VALUE
3425 : : never loses precision. However, the signedness of the result does
3426 : : not necessarily match the signedness of T: sometimes an unsigned type
3427 : : like sizetype is used to encode a value that is actually negative. */
3428 : :
3429 : : bool
3430 : 10981349 : ptrdiff_tree_p (const_tree t, poly_int64 *value)
3431 : : {
3432 : 10981349 : if (!t)
3433 : : return false;
3434 : 10981349 : if (TREE_CODE (t) == INTEGER_CST)
3435 : : {
3436 : 3044383 : if (!cst_and_fits_in_hwi (t))
3437 : : return false;
3438 : 3043617 : *value = int_cst_value (t);
3439 : 3043617 : return true;
3440 : : }
3441 : : if (POLY_INT_CST_P (t))
3442 : : {
3443 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3444 : : if (!cst_and_fits_in_hwi (POLY_INT_CST_COEFF (t, i)))
3445 : : return false;
3446 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3447 : : value->coeffs[i] = int_cst_value (POLY_INT_CST_COEFF (t, i));
3448 : : return true;
3449 : : }
3450 : : return false;
3451 : : }
3452 : :
3453 : : poly_int64
3454 : 428537906 : tree_to_poly_int64 (const_tree t)
3455 : : {
3456 : 428537906 : gcc_assert (tree_fits_poly_int64_p (t));
3457 : 428537906 : if (POLY_INT_CST_P (t))
3458 : : return poly_int_cst_value (t).force_shwi ();
3459 : 428537906 : return TREE_INT_CST_LOW (t);
3460 : : }
3461 : :
3462 : : poly_uint64
3463 : 484919033 : tree_to_poly_uint64 (const_tree t)
3464 : : {
3465 : 484919033 : gcc_assert (tree_fits_poly_uint64_p (t));
3466 : 484919033 : if (POLY_INT_CST_P (t))
3467 : : return poly_int_cst_value (t).force_uhwi ();
3468 : 484919033 : return TREE_INT_CST_LOW (t);
3469 : : }
3470 : :
3471 : : /* Return first list element whose TREE_VALUE is ELEM.
3472 : : Return 0 if ELEM is not in LIST. */
3473 : :
3474 : : tree
3475 : 7896701 : value_member (tree elem, tree list)
3476 : : {
3477 : 23114595 : while (list)
3478 : : {
3479 : 20102848 : if (elem == TREE_VALUE (list))
3480 : : return list;
3481 : 15217894 : list = TREE_CHAIN (list);
3482 : : }
3483 : : return NULL_TREE;
3484 : : }
3485 : :
3486 : : /* Return first list element whose TREE_PURPOSE is ELEM.
3487 : : Return 0 if ELEM is not in LIST. */
3488 : :
3489 : : tree
3490 : 153401031 : purpose_member (const_tree elem, tree list)
3491 : : {
3492 : 343425525 : while (list)
3493 : : {
3494 : 205312212 : if (elem == TREE_PURPOSE (list))
3495 : : return list;
3496 : 190024494 : list = TREE_CHAIN (list);
3497 : : }
3498 : : return NULL_TREE;
3499 : : }
3500 : :
3501 : : /* Return true if ELEM is in V. */
3502 : :
3503 : : bool
3504 : 2286951 : vec_member (const_tree elem, vec<tree, va_gc> *v)
3505 : : {
3506 : 2286951 : unsigned ix;
3507 : 2286951 : tree t;
3508 : 4019823 : FOR_EACH_VEC_SAFE_ELT (v, ix, t)
3509 : 1735538 : if (elem == t)
3510 : : return true;
3511 : : return false;
3512 : : }
3513 : :
3514 : : /* Returns element number IDX (zero-origin) of chain CHAIN, or
3515 : : NULL_TREE. */
3516 : :
3517 : : tree
3518 : 18915464 : chain_index (int idx, tree chain)
3519 : : {
3520 : 24270800 : for (; chain && idx > 0; --idx)
3521 : 5355336 : chain = TREE_CHAIN (chain);
3522 : 18915464 : return chain;
3523 : : }
3524 : :
3525 : : /* Return true if ELEM is part of the chain CHAIN. */
3526 : :
3527 : : bool
3528 : 191155 : chain_member (const_tree elem, const_tree chain)
3529 : : {
3530 : 364627 : while (chain)
3531 : : {
3532 : 363306 : if (elem == chain)
3533 : : return true;
3534 : 173472 : chain = DECL_CHAIN (chain);
3535 : : }
3536 : :
3537 : : return false;
3538 : : }
3539 : :
3540 : : /* Return the length of a chain of nodes chained through TREE_CHAIN.
3541 : : We expect a null pointer to mark the end of the chain.
3542 : : This is the Lisp primitive `length'. */
3543 : :
3544 : : int
3545 : 1959648959 : list_length (const_tree t)
3546 : : {
3547 : 1959648959 : const_tree p = t;
3548 : : #ifdef ENABLE_TREE_CHECKING
3549 : 1959648959 : const_tree q = t;
3550 : : #endif
3551 : 1959648959 : int len = 0;
3552 : :
3553 : 3113498853 : while (p)
3554 : : {
3555 : 1153849894 : p = TREE_CHAIN (p);
3556 : : #ifdef ENABLE_TREE_CHECKING
3557 : 1153849894 : if (len % 2)
3558 : 373240758 : q = TREE_CHAIN (q);
3559 : 1153849894 : gcc_assert (p != q);
3560 : : #endif
3561 : 1153849894 : len++;
3562 : : }
3563 : :
3564 : 1959648959 : return len;
3565 : : }
3566 : :
3567 : : /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3568 : : UNION_TYPE TYPE, or NULL_TREE if none. */
3569 : :
3570 : : tree
3571 : 73142 : first_field (const_tree type)
3572 : : {
3573 : 73142 : tree t = TYPE_FIELDS (type);
3574 : 3178239 : while (t && TREE_CODE (t) != FIELD_DECL)
3575 : 3105097 : t = TREE_CHAIN (t);
3576 : 73142 : return t;
3577 : : }
3578 : :
3579 : : /* Returns the last FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3580 : : UNION_TYPE TYPE, or NULL_TREE if none. */
3581 : :
3582 : : tree
3583 : 2753101 : last_field (const_tree type)
3584 : : {
3585 : 2753101 : tree last = NULL_TREE;
3586 : :
3587 : 62255658 : for (tree fld = TYPE_FIELDS (type); fld; fld = TREE_CHAIN (fld))
3588 : : {
3589 : 59502557 : if (TREE_CODE (fld) != FIELD_DECL)
3590 : 51019472 : continue;
3591 : :
3592 : : last = fld;
3593 : : }
3594 : :
3595 : 2753101 : return last;
3596 : : }
3597 : :
3598 : : /* Concatenate two chains of nodes (chained through TREE_CHAIN)
3599 : : by modifying the last node in chain 1 to point to chain 2.
3600 : : This is the Lisp primitive `nconc'. */
3601 : :
3602 : : tree
3603 : 3967918434 : chainon (tree op1, tree op2)
3604 : : {
3605 : 3967918434 : tree t1;
3606 : :
3607 : 3967918434 : if (!op1)
3608 : : return op2;
3609 : 714662724 : if (!op2)
3610 : : return op1;
3611 : :
3612 : 1477180444 : for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
3613 : 837222339 : continue;
3614 : 639958105 : TREE_CHAIN (t1) = op2;
3615 : :
3616 : : #ifdef ENABLE_TREE_CHECKING
3617 : 639958105 : {
3618 : 639958105 : tree t2;
3619 : 1665019357 : for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
3620 : 1025061252 : gcc_assert (t2 != t1);
3621 : : }
3622 : : #endif
3623 : :
3624 : : return op1;
3625 : 837222339 : }
3626 : :
3627 : : /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
3628 : :
3629 : : tree
3630 : 93292950 : tree_last (tree chain)
3631 : : {
3632 : 93292950 : tree next;
3633 : 93292950 : if (chain)
3634 : 175010579 : while ((next = TREE_CHAIN (chain)))
3635 : : chain = next;
3636 : 93292950 : return chain;
3637 : : }
3638 : :
3639 : : /* Reverse the order of elements in the chain T,
3640 : : and return the new head of the chain (old last element). */
3641 : :
3642 : : tree
3643 : 1364212479 : nreverse (tree t)
3644 : : {
3645 : 1364212479 : tree prev = 0, decl, next;
3646 : 3493493844 : for (decl = t; decl; decl = next)
3647 : : {
3648 : : /* We shouldn't be using this function to reverse BLOCK chains; we
3649 : : have blocks_nreverse for that. */
3650 : 2129281365 : gcc_checking_assert (TREE_CODE (decl) != BLOCK);
3651 : 2129281365 : next = TREE_CHAIN (decl);
3652 : 2129281365 : TREE_CHAIN (decl) = prev;
3653 : 2129281365 : prev = decl;
3654 : : }
3655 : 1364212479 : return prev;
3656 : : }
3657 : :
3658 : : /* Return a newly created TREE_LIST node whose
3659 : : purpose and value fields are PARM and VALUE. */
3660 : :
3661 : : tree
3662 : 1263452765 : build_tree_list (tree parm, tree value MEM_STAT_DECL)
3663 : : {
3664 : 1263452765 : tree t = make_node (TREE_LIST PASS_MEM_STAT);
3665 : 1263452765 : TREE_PURPOSE (t) = parm;
3666 : 1263452765 : TREE_VALUE (t) = value;
3667 : 1263452765 : return t;
3668 : : }
3669 : :
3670 : : /* Build a chain of TREE_LIST nodes from a vector. */
3671 : :
3672 : : tree
3673 : 84323322 : build_tree_list_vec (const vec<tree, va_gc> *vec MEM_STAT_DECL)
3674 : : {
3675 : 84323322 : tree ret = NULL_TREE;
3676 : 84323322 : tree *pp = &ret;
3677 : 84323322 : unsigned int i;
3678 : 84323322 : tree t;
3679 : 177597254 : FOR_EACH_VEC_SAFE_ELT (vec, i, t)
3680 : : {
3681 : 93273932 : *pp = build_tree_list (NULL, t PASS_MEM_STAT);
3682 : 93273932 : pp = &TREE_CHAIN (*pp);
3683 : : }
3684 : 84323322 : return ret;
3685 : : }
3686 : :
3687 : : /* Return a newly created TREE_LIST node whose
3688 : : purpose and value fields are PURPOSE and VALUE
3689 : : and whose TREE_CHAIN is CHAIN. */
3690 : :
3691 : : tree
3692 : 5083894686 : tree_cons (tree purpose, tree value, tree chain MEM_STAT_DECL)
3693 : : {
3694 : 5083894686 : tree node;
3695 : :
3696 : 5083894686 : node = ggc_alloc_tree_node_stat (sizeof (struct tree_list) PASS_MEM_STAT);
3697 : 5083894686 : memset (node, 0, sizeof (struct tree_common));
3698 : :
3699 : 5083894686 : record_node_allocation_statistics (TREE_LIST, sizeof (struct tree_list));
3700 : :
3701 : 5083894686 : TREE_SET_CODE (node, TREE_LIST);
3702 : 5083894686 : TREE_CHAIN (node) = chain;
3703 : 5083894686 : TREE_PURPOSE (node) = purpose;
3704 : 5083894686 : TREE_VALUE (node) = value;
3705 : 5083894686 : return node;
3706 : : }
3707 : :
3708 : : /* Return the values of the elements of a CONSTRUCTOR as a vector of
3709 : : trees. */
3710 : :
3711 : : vec<tree, va_gc> *
3712 : 0 : ctor_to_vec (tree ctor)
3713 : : {
3714 : 0 : vec<tree, va_gc> *vec;
3715 : 0 : vec_alloc (vec, CONSTRUCTOR_NELTS (ctor));
3716 : 0 : unsigned int ix;
3717 : 0 : tree val;
3718 : :
3719 : 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val)
3720 : 0 : vec->quick_push (val);
3721 : :
3722 : 0 : return vec;
3723 : : }
3724 : :
3725 : : /* Return the size nominally occupied by an object of type TYPE
3726 : : when it resides in memory. The value is measured in units of bytes,
3727 : : and its data type is that normally used for type sizes
3728 : : (which is the first type created by make_signed_type or
3729 : : make_unsigned_type). */
3730 : :
3731 : : tree
3732 : 26583450 : size_in_bytes_loc (location_t loc, const_tree type)
3733 : : {
3734 : 26583450 : tree t;
3735 : :
3736 : 26583450 : if (type == error_mark_node)
3737 : 0 : return integer_zero_node;
3738 : :
3739 : 26583450 : type = TYPE_MAIN_VARIANT (type);
3740 : 26583450 : t = TYPE_SIZE_UNIT (type);
3741 : :
3742 : 26583450 : if (t == 0)
3743 : : {
3744 : 56 : lang_hooks.types.incomplete_type_error (loc, NULL_TREE, type);
3745 : 56 : return size_zero_node;
3746 : : }
3747 : :
3748 : : return t;
3749 : : }
3750 : :
3751 : : /* Return the size of TYPE (in bytes) as a wide integer
3752 : : or return -1 if the size can vary or is larger than an integer. */
3753 : :
3754 : : HOST_WIDE_INT
3755 : 503313671 : int_size_in_bytes (const_tree type)
3756 : : {
3757 : 503313671 : tree t;
3758 : :
3759 : 503313671 : if (type == error_mark_node)
3760 : : return 0;
3761 : :
3762 : 503313671 : type = TYPE_MAIN_VARIANT (type);
3763 : 503313671 : t = TYPE_SIZE_UNIT (type);
3764 : :
3765 : 503313671 : if (t && tree_fits_uhwi_p (t))
3766 : 503261798 : return TREE_INT_CST_LOW (t);
3767 : : else
3768 : : return -1;
3769 : : }
3770 : :
3771 : : /* Return the maximum size of TYPE (in bytes) as a wide integer
3772 : : or return -1 if the size can vary or is larger than an integer. */
3773 : :
3774 : : HOST_WIDE_INT
3775 : 9166 : max_int_size_in_bytes (const_tree type)
3776 : : {
3777 : 9166 : HOST_WIDE_INT size = -1;
3778 : 9166 : tree size_tree;
3779 : :
3780 : : /* If this is an array type, check for a possible MAX_SIZE attached. */
3781 : :
3782 : 9166 : if (TREE_CODE (type) == ARRAY_TYPE)
3783 : : {
3784 : 8445 : size_tree = TYPE_ARRAY_MAX_SIZE (type);
3785 : :
3786 : 8445 : if (size_tree && tree_fits_uhwi_p (size_tree))
3787 : 0 : size = tree_to_uhwi (size_tree);
3788 : : }
3789 : :
3790 : : /* If we still haven't been able to get a size, see if the language
3791 : : can compute a maximum size. */
3792 : :
3793 : 0 : if (size == -1)
3794 : : {
3795 : 9166 : size_tree = lang_hooks.types.max_size (type);
3796 : :
3797 : 9166 : if (size_tree && tree_fits_uhwi_p (size_tree))
3798 : 0 : size = tree_to_uhwi (size_tree);
3799 : : }
3800 : :
3801 : 9166 : return size;
3802 : : }
3803 : :
3804 : : /* Return the bit position of FIELD, in bits from the start of the record.
3805 : : This is a tree of type bitsizetype. */
3806 : :
3807 : : tree
3808 : 102983662 : bit_position (const_tree field)
3809 : : {
3810 : 102983662 : return bit_from_pos (DECL_FIELD_OFFSET (field),
3811 : 102983662 : DECL_FIELD_BIT_OFFSET (field));
3812 : : }
3813 : :
3814 : : /* Return the byte position of FIELD, in bytes from the start of the record.
3815 : : This is a tree of type sizetype. */
3816 : :
3817 : : tree
3818 : 103902412 : byte_position (const_tree field)
3819 : : {
3820 : 103902412 : return byte_from_pos (DECL_FIELD_OFFSET (field),
3821 : 103902412 : DECL_FIELD_BIT_OFFSET (field));
3822 : : }
3823 : :
3824 : : /* Likewise, but return as an integer. It must be representable in
3825 : : that way (since it could be a signed value, we don't have the
3826 : : option of returning -1 like int_size_in_byte can. */
3827 : :
3828 : : HOST_WIDE_INT
3829 : 9782237 : int_byte_position (const_tree field)
3830 : : {
3831 : 9782237 : return tree_to_shwi (byte_position (field));
3832 : : }
3833 : :
3834 : : /* Return, as a tree node, the number of elements for TYPE (which is an
3835 : : ARRAY_TYPE) minus one. This counts only elements of the top array. */
3836 : :
3837 : : tree
3838 : 81845835 : array_type_nelts_minus_one (const_tree type)
3839 : : {
3840 : 81845835 : tree index_type, min, max;
3841 : :
3842 : : /* If they did it with unspecified bounds, then we should have already
3843 : : given an error about it before we got here. */
3844 : 81845835 : if (! TYPE_DOMAIN (type))
3845 : 6066954 : return error_mark_node;
3846 : :
3847 : 75778881 : index_type = TYPE_DOMAIN (type);
3848 : 75778881 : min = TYPE_MIN_VALUE (index_type);
3849 : 75778881 : max = TYPE_MAX_VALUE (index_type);
3850 : :
3851 : : /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
3852 : 75778881 : if (!max)
3853 : : {
3854 : : /* zero sized arrays are represented from C FE as complete types with
3855 : : NULL TYPE_MAX_VALUE and zero TYPE_SIZE, while C++ FE represents
3856 : : them as min 0, max -1. */
3857 : 1253117 : if (COMPLETE_TYPE_P (type)
3858 : 3131 : && integer_zerop (TYPE_SIZE (type))
3859 : 1256248 : && integer_zerop (min))
3860 : 3131 : return build_int_cst (TREE_TYPE (min), -1);
3861 : :
3862 : 1249986 : return error_mark_node;
3863 : : }
3864 : :
3865 : 74525764 : return (integer_zerop (min)
3866 : 74525764 : ? max
3867 : 1106214 : : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
3868 : : }
3869 : :
3870 : : /* Return, as an INTEGER_CST node, the number of elements for TYPE
3871 : : (which is an ARRAY_TYPE). This counts only elements of the top
3872 : : array. */
3873 : :
3874 : : tree
3875 : 5551630 : array_type_nelts_top (tree type)
3876 : : {
3877 : 5551630 : return fold_build2_loc (input_location,
3878 : : PLUS_EXPR, sizetype,
3879 : : array_type_nelts_minus_one (type),
3880 : 5551630 : size_one_node);
3881 : : }
3882 : :
3883 : : /* If arg is static -- a reference to an object in static storage -- then
3884 : : return the object. This is not the same as the C meaning of `static'.
3885 : : If arg isn't static, return NULL. */
3886 : :
3887 : : tree
3888 : 1062451919 : staticp (tree arg)
3889 : : {
3890 : 1063403850 : switch (TREE_CODE (arg))
3891 : : {
3892 : : case FUNCTION_DECL:
3893 : : /* Nested functions are static, even though taking their address will
3894 : : involve a trampoline as we unnest the nested function and create
3895 : : the trampoline on the tree level. */
3896 : : return arg;
3897 : :
3898 : 663396472 : case VAR_DECL:
3899 : 527125160 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3900 : 180582714 : && ! DECL_THREAD_LOCAL_P (arg)
3901 : 178751260 : && ! DECL_DLLIMPORT_P (arg)
3902 : 663396472 : ? arg : NULL);
3903 : :
3904 : 586747 : case CONST_DECL:
3905 : 60 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3906 : 586747 : ? arg : NULL);
3907 : :
3908 : 0 : case CONSTRUCTOR:
3909 : 0 : return TREE_STATIC (arg) ? arg : NULL;
3910 : :
3911 : : case LABEL_DECL:
3912 : : case STRING_CST:
3913 : : return arg;
3914 : :
3915 : 707654 : case COMPONENT_REF:
3916 : : /* If the thing being referenced is not a field, then it is
3917 : : something language specific. */
3918 : 707654 : gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL);
3919 : :
3920 : : /* If we are referencing a bitfield, we can't evaluate an
3921 : : ADDR_EXPR at compile time and so it isn't a constant. */
3922 : 707654 : if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
3923 : : return NULL;
3924 : :
3925 : 707654 : return staticp (TREE_OPERAND (arg, 0));
3926 : :
3927 : : case BIT_FIELD_REF:
3928 : : return NULL;
3929 : :
3930 : 67733 : case INDIRECT_REF:
3931 : 67733 : return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
3932 : :
3933 : 244365 : case ARRAY_REF:
3934 : 244365 : case ARRAY_RANGE_REF:
3935 : 244365 : if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
3936 : 244365 : && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
3937 : 244021 : return staticp (TREE_OPERAND (arg, 0));
3938 : : else
3939 : : return NULL;
3940 : :
3941 : 256 : case REALPART_EXPR:
3942 : 256 : case IMAGPART_EXPR:
3943 : 256 : return staticp (TREE_OPERAND (arg, 0));
3944 : :
3945 : 934 : case COMPOUND_LITERAL_EXPR:
3946 : 934 : return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;
3947 : :
3948 : : default:
3949 : : return NULL;
3950 : : }
3951 : : }
3952 : :
3953 : :
3954 : :
3955 : :
3956 : : /* Return whether OP is a DECL whose address is function-invariant. */
3957 : :
3958 : : bool
3959 : 5152903810 : decl_address_invariant_p (const_tree op)
3960 : : {
3961 : : /* The conditions below are slightly less strict than the one in
3962 : : staticp. */
3963 : :
3964 : 5152903810 : switch (TREE_CODE (op))
3965 : : {
3966 : : case PARM_DECL:
3967 : : case RESULT_DECL:
3968 : : case LABEL_DECL:
3969 : : case FUNCTION_DECL:
3970 : : return true;
3971 : :
3972 : 2861152881 : case VAR_DECL:
3973 : 2172615879 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3974 : 2046020851 : || DECL_THREAD_LOCAL_P (op)
3975 : 2046020851 : || DECL_CONTEXT (op) == current_function_decl
3976 : 2868667896 : || decl_function_context (op) == current_function_decl)
3977 : 2853637866 : return true;
3978 : : break;
3979 : :
3980 : 25304998 : case CONST_DECL:
3981 : 0 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3982 : 25304998 : || decl_function_context (op) == current_function_decl)
3983 : 25304998 : return true;
3984 : : break;
3985 : :
3986 : : default:
3987 : : break;
3988 : : }
3989 : :
3990 : : return false;
3991 : : }
3992 : :
3993 : : /* Return whether OP is a DECL whose address is interprocedural-invariant. */
3994 : :
3995 : : bool
3996 : 1771816 : decl_address_ip_invariant_p (const_tree op)
3997 : : {
3998 : : /* The conditions below are slightly less strict than the one in
3999 : : staticp. */
4000 : :
4001 : 1771816 : switch (TREE_CODE (op))
4002 : : {
4003 : : case LABEL_DECL:
4004 : : case FUNCTION_DECL:
4005 : : case STRING_CST:
4006 : : return true;
4007 : :
4008 : 1586484 : case VAR_DECL:
4009 : 1165158 : if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
4010 : 455203 : && !DECL_DLLIMPORT_P (op))
4011 : 2717765 : || DECL_THREAD_LOCAL_P (op))
4012 : 455203 : return true;
4013 : : break;
4014 : :
4015 : 52300 : case CONST_DECL:
4016 : 52300 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
4017 : : return true;
4018 : : break;
4019 : :
4020 : : default:
4021 : : break;
4022 : : }
4023 : :
4024 : : return false;
4025 : : }
4026 : :
4027 : : /* Return true if T is an object with invariant address. */
4028 : :
4029 : : bool
4030 : 49309 : address_invariant_p (tree t)
4031 : : {
4032 : 55997 : while (handled_component_p (t))
4033 : : {
4034 : 7593 : switch (TREE_CODE (t))
4035 : : {
4036 : 1380 : case ARRAY_REF:
4037 : 1380 : case ARRAY_RANGE_REF:
4038 : 1380 : if (!tree_invariant_p (TREE_OPERAND (t, 1))
4039 : 475 : || TREE_OPERAND (t, 2) != NULL_TREE
4040 : 1855 : || TREE_OPERAND (t, 3) != NULL_TREE)
4041 : : return false;
4042 : : break;
4043 : :
4044 : 6066 : case COMPONENT_REF:
4045 : 6066 : if (TREE_OPERAND (t, 2) != NULL_TREE)
4046 : : return false;
4047 : : break;
4048 : :
4049 : : default:
4050 : : break;
4051 : : }
4052 : 6688 : t = TREE_OPERAND (t, 0);
4053 : : }
4054 : :
4055 : 48404 : STRIP_ANY_LOCATION_WRAPPER (t);
4056 : 48404 : return CONSTANT_CLASS_P (t) || decl_address_invariant_p (t);
4057 : : }
4058 : :
4059 : :
4060 : : /* Return true if T is function-invariant (internal function, does
4061 : : not handle arithmetic; that's handled in skip_simple_arithmetic and
4062 : : tree_invariant_p). */
4063 : :
4064 : : static bool
4065 : 14825684 : tree_invariant_p_1 (tree t)
4066 : : {
4067 : 14825684 : if (TREE_CONSTANT (t) || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
4068 : : return true;
4069 : :
4070 : 12727343 : switch (TREE_CODE (t))
4071 : : {
4072 : : case SAVE_EXPR:
4073 : : case TARGET_EXPR:
4074 : : return true;
4075 : :
4076 : 49269 : case ADDR_EXPR:
4077 : 49269 : return address_invariant_p (TREE_OPERAND (t, 0));
4078 : :
4079 : : default:
4080 : : break;
4081 : : }
4082 : :
4083 : : return false;
4084 : : }
4085 : :
4086 : : /* Return true if T is function-invariant. */
4087 : :
4088 : : bool
4089 : 11871351 : tree_invariant_p (tree t)
4090 : : {
4091 : 11871351 : tree inner = skip_simple_arithmetic (t);
4092 : 11871351 : return tree_invariant_p_1 (inner);
4093 : : }
4094 : :
4095 : : /* Wrap a SAVE_EXPR around EXPR, if appropriate.
4096 : : Do this to any expression which may be used in more than one place,
4097 : : but must be evaluated only once.
4098 : :
4099 : : Normally, expand_expr would reevaluate the expression each time.
4100 : : Calling save_expr produces something that is evaluated and recorded
4101 : : the first time expand_expr is called on it. Subsequent calls to
4102 : : expand_expr just reuse the recorded value.
4103 : :
4104 : : The call to expand_expr that generates code that actually computes
4105 : : the value is the first call *at compile time*. Subsequent calls
4106 : : *at compile time* generate code to use the saved value.
4107 : : This produces correct result provided that *at run time* control
4108 : : always flows through the insns made by the first expand_expr
4109 : : before reaching the other places where the save_expr was evaluated.
4110 : : You, the caller of save_expr, must make sure this is so.
4111 : :
4112 : : Constants, and certain read-only nodes, are returned with no
4113 : : SAVE_EXPR because that is safe. Expressions containing placeholders
4114 : : are not touched; see tree.def for an explanation of what these
4115 : : are used for. */
4116 : :
4117 : : tree
4118 : 2954344 : save_expr (tree expr)
4119 : : {
4120 : 2954344 : tree inner;
4121 : :
4122 : : /* If the tree evaluates to a constant, then we don't want to hide that
4123 : : fact (i.e. this allows further folding, and direct checks for constants).
4124 : : However, a read-only object that has side effects cannot be bypassed.
4125 : : Since it is no problem to reevaluate literals, we just return the
4126 : : literal node. */
4127 : 2954344 : inner = skip_simple_arithmetic (expr);
4128 : 2954344 : if (TREE_CODE (inner) == ERROR_MARK)
4129 : : return inner;
4130 : :
4131 : 2954333 : if (tree_invariant_p_1 (inner))
4132 : : return expr;
4133 : :
4134 : : /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
4135 : : it means that the size or offset of some field of an object depends on
4136 : : the value within another field.
4137 : :
4138 : : Note that it must not be the case that EXPR contains both a PLACEHOLDER_EXPR
4139 : : and some variable since it would then need to be both evaluated once and
4140 : : evaluated more than once. Front-ends must assure this case cannot
4141 : : happen by surrounding any such subexpressions in their own SAVE_EXPR
4142 : : and forcing evaluation at the proper time. */
4143 : 2127355 : if (contains_placeholder_p (inner))
4144 : : return expr;
4145 : :
4146 : 2127355 : expr = build1_loc (EXPR_LOCATION (expr), SAVE_EXPR, TREE_TYPE (expr), expr);
4147 : :
4148 : : /* This expression might be placed ahead of a jump to ensure that the
4149 : : value was computed on both sides of the jump. So make sure it isn't
4150 : : eliminated as dead. */
4151 : 2127355 : TREE_SIDE_EFFECTS (expr) = 1;
4152 : 2127355 : return expr;
4153 : : }
4154 : :
4155 : : /* Look inside EXPR into any simple arithmetic operations. Return the
4156 : : outermost non-arithmetic or non-invariant node. */
4157 : :
4158 : : tree
4159 : 14825695 : skip_simple_arithmetic (tree expr)
4160 : : {
4161 : : /* We don't care about whether this can be used as an lvalue in this
4162 : : context. */
4163 : 14837319 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4164 : 11624 : expr = TREE_OPERAND (expr, 0);
4165 : :
4166 : : /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
4167 : : a constant, it will be more efficient to not make another SAVE_EXPR since
4168 : : it will allow better simplification and GCSE will be able to merge the
4169 : : computations if they actually occur. */
4170 : 38946068 : while (true)
4171 : : {
4172 : 38946068 : if (UNARY_CLASS_P (expr))
4173 : 14968935 : expr = TREE_OPERAND (expr, 0);
4174 : 23977133 : else if (BINARY_CLASS_P (expr))
4175 : : {
4176 : : /* Before commutative binary operands are canonicalized,
4177 : : it is quite common to have constants in the first operand.
4178 : : Check for that common case first so that we don't walk
4179 : : large expressions with tree_invariant_p unnecessarily.
4180 : : This can still have terrible compile time complexity,
4181 : : we should limit the depth of the tree_invariant_p and
4182 : : skip_simple_arithmetic recursion. */
4183 : 9219140 : if ((TREE_CONSTANT (TREE_OPERAND (expr, 0))
4184 : 9208999 : || (TREE_READONLY (TREE_OPERAND (expr, 0))
4185 : 9986 : && !TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0))))
4186 : 9229090 : && tree_invariant_p (TREE_OPERAND (expr, 0)))
4187 : 20091 : expr = TREE_OPERAND (expr, 1);
4188 : 9199049 : else if (tree_invariant_p (TREE_OPERAND (expr, 1)))
4189 : 9121843 : expr = TREE_OPERAND (expr, 0);
4190 : 77206 : else if (tree_invariant_p (TREE_OPERAND (expr, 0)))
4191 : 9504 : expr = TREE_OPERAND (expr, 1);
4192 : : else
4193 : : break;
4194 : : }
4195 : : else
4196 : : break;
4197 : : }
4198 : :
4199 : 14825695 : return expr;
4200 : : }
4201 : :
4202 : : /* Look inside EXPR into simple arithmetic operations involving constants.
4203 : : Return the outermost non-arithmetic or non-constant node. */
4204 : :
4205 : : tree
4206 : 0 : skip_simple_constant_arithmetic (tree expr)
4207 : : {
4208 : 0 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4209 : 0 : expr = TREE_OPERAND (expr, 0);
4210 : :
4211 : 0 : while (true)
4212 : : {
4213 : 0 : if (UNARY_CLASS_P (expr))
4214 : 0 : expr = TREE_OPERAND (expr, 0);
4215 : 0 : else if (BINARY_CLASS_P (expr))
4216 : : {
4217 : 0 : if (TREE_CONSTANT (TREE_OPERAND (expr, 1)))
4218 : 0 : expr = TREE_OPERAND (expr, 0);
4219 : 0 : else if (TREE_CONSTANT (TREE_OPERAND (expr, 0)))
4220 : 0 : expr = TREE_OPERAND (expr, 1);
4221 : : else
4222 : : break;
4223 : : }
4224 : : else
4225 : : break;
4226 : : }
4227 : :
4228 : 0 : return expr;
4229 : : }
4230 : :
4231 : : /* Return which tree structure is used by T. */
4232 : :
4233 : : enum tree_node_structure_enum
4234 : 37562587833 : tree_node_structure (const_tree t)
4235 : : {
4236 : 37562587833 : const enum tree_code code = TREE_CODE (t);
4237 : 37562587833 : return tree_node_structure_for_code (code);
4238 : : }
4239 : :
4240 : : /* Set various status flags when building a CALL_EXPR object T. */
4241 : :
4242 : : static void
4243 : 247967454 : process_call_operands (tree t)
4244 : : {
4245 : 247967454 : bool side_effects = TREE_SIDE_EFFECTS (t);
4246 : 247967454 : bool read_only = false;
4247 : 247967454 : int i = call_expr_flags (t);
4248 : :
4249 : : /* Calls have side-effects, except those to const or pure functions. */
4250 : 247967454 : if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
4251 : : side_effects = true;
4252 : : /* Propagate TREE_READONLY of arguments for const functions. */
4253 : 54882158 : if (i & ECF_CONST)
4254 : 53223747 : read_only = true;
4255 : :
4256 : 247967454 : if (!side_effects || read_only)
4257 : 282481678 : for (i = 1; i < TREE_OPERAND_LENGTH (t); i++)
4258 : : {
4259 : 227600024 : tree op = TREE_OPERAND (t, i);
4260 : 227600024 : if (op && TREE_SIDE_EFFECTS (op))
4261 : : side_effects = true;
4262 : 227600024 : if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op))
4263 : : read_only = false;
4264 : : }
4265 : :
4266 : 247967454 : TREE_SIDE_EFFECTS (t) = side_effects;
4267 : 247967454 : TREE_READONLY (t) = read_only;
4268 : 247967454 : }
4269 : :
4270 : : /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
4271 : : size or offset that depends on a field within a record. */
4272 : :
4273 : : bool
4274 : 38134054 : contains_placeholder_p (const_tree exp)
4275 : : {
4276 : 38134054 : enum tree_code code;
4277 : :
4278 : 38134054 : if (!exp)
4279 : : return false;
4280 : :
4281 : 38134054 : code = TREE_CODE (exp);
4282 : 38134054 : if (code == PLACEHOLDER_EXPR)
4283 : : return true;
4284 : :
4285 : 38134054 : switch (TREE_CODE_CLASS (code))
4286 : : {
4287 : 1220843 : case tcc_reference:
4288 : : /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
4289 : : position computations since they will be converted into a
4290 : : WITH_RECORD_EXPR involving the reference, which will assume
4291 : : here will be valid. */
4292 : 1220843 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4293 : :
4294 : 546805 : case tcc_exceptional:
4295 : 546805 : if (code == TREE_LIST)
4296 : 0 : return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
4297 : 0 : || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
4298 : : break;
4299 : :
4300 : 33683773 : case tcc_unary:
4301 : 33683773 : case tcc_binary:
4302 : 33683773 : case tcc_comparison:
4303 : 33683773 : case tcc_expression:
4304 : 33683773 : switch (code)
4305 : : {
4306 : 6398 : case COMPOUND_EXPR:
4307 : : /* Ignoring the first operand isn't quite right, but works best. */
4308 : 6398 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
4309 : :
4310 : 4483 : case COND_EXPR:
4311 : 8966 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4312 : 4483 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
4313 : 8966 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
4314 : :
4315 : : case SAVE_EXPR:
4316 : : /* The save_expr function never wraps anything containing
4317 : : a PLACEHOLDER_EXPR. */
4318 : : return false;
4319 : :
4320 : 24406352 : default:
4321 : 24406352 : break;
4322 : : }
4323 : :
4324 : 24406352 : switch (TREE_CODE_LENGTH (code))
4325 : : {
4326 : 14883012 : case 1:
4327 : 14883012 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4328 : 9493835 : case 2:
4329 : 18986159 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4330 : 18986159 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
4331 : : default:
4332 : : return false;
4333 : : }
4334 : :
4335 : 500320 : case tcc_vl_exp:
4336 : 500320 : switch (code)
4337 : : {
4338 : 500320 : case CALL_EXPR:
4339 : 500320 : {
4340 : 500320 : const_tree arg;
4341 : 500320 : const_call_expr_arg_iterator iter;
4342 : 1664517 : FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
4343 : 663877 : if (CONTAINS_PLACEHOLDER_P (arg))
4344 : : return true;
4345 : : return false;
4346 : : }
4347 : : default:
4348 : : return false;
4349 : : }
4350 : :
4351 : : default:
4352 : : return false;
4353 : : }
4354 : : return false;
4355 : : }
4356 : :
4357 : : /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
4358 : : directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
4359 : : field positions. */
4360 : :
4361 : : static bool
4362 : 788072 : type_contains_placeholder_1 (const_tree type)
4363 : : {
4364 : : /* If the size contains a placeholder or the parent type (component type in
4365 : : the case of arrays) type involves a placeholder, this type does. */
4366 : 1555810 : if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
4367 : 788072 : || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
4368 : 1576144 : || (!POINTER_TYPE_P (type)
4369 : 652364 : && TREE_TYPE (type)
4370 : 107665 : && type_contains_placeholder_p (TREE_TYPE (type))))
4371 : 0 : return true;
4372 : :
4373 : : /* Now do type-specific checks. Note that the last part of the check above
4374 : : greatly limits what we have to do below. */
4375 : 788072 : switch (TREE_CODE (type))
4376 : : {
4377 : : case VOID_TYPE:
4378 : : case OPAQUE_TYPE:
4379 : : case COMPLEX_TYPE:
4380 : : case ENUMERAL_TYPE:
4381 : : case BOOLEAN_TYPE:
4382 : : case POINTER_TYPE:
4383 : : case OFFSET_TYPE:
4384 : : case REFERENCE_TYPE:
4385 : : case METHOD_TYPE:
4386 : : case FUNCTION_TYPE:
4387 : : case VECTOR_TYPE:
4388 : : case NULLPTR_TYPE:
4389 : : return false;
4390 : :
4391 : 171445 : case INTEGER_TYPE:
4392 : 171445 : case BITINT_TYPE:
4393 : 171445 : case REAL_TYPE:
4394 : 171445 : case FIXED_POINT_TYPE:
4395 : : /* Here we just check the bounds. */
4396 : 333128 : return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
4397 : 333128 : || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
4398 : :
4399 : 56272 : case ARRAY_TYPE:
4400 : : /* We have already checked the component type above, so just check
4401 : : the domain type. Flexible array members have a null domain. */
4402 : 112532 : return TYPE_DOMAIN (type) ?
4403 : 56260 : type_contains_placeholder_p (TYPE_DOMAIN (type)) : false;
4404 : :
4405 : 401322 : case RECORD_TYPE:
4406 : 401322 : case UNION_TYPE:
4407 : 401322 : case QUAL_UNION_TYPE:
4408 : 401322 : {
4409 : 401322 : tree field;
4410 : :
4411 : 11791130 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
4412 : 11389808 : if (TREE_CODE (field) == FIELD_DECL
4413 : 11389808 : && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
4414 : 924782 : || (TREE_CODE (type) == QUAL_UNION_TYPE
4415 : 0 : && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
4416 : 924782 : || type_contains_placeholder_p (TREE_TYPE (field))))
4417 : 0 : return true;
4418 : :
4419 : : return false;
4420 : : }
4421 : :
4422 : 0 : default:
4423 : 0 : gcc_unreachable ();
4424 : : }
4425 : : }
4426 : :
4427 : : /* Wrapper around above function used to cache its result. */
4428 : :
4429 : : bool
4430 : 3044234 : type_contains_placeholder_p (tree type)
4431 : : {
4432 : 3044234 : bool result;
4433 : :
4434 : : /* If the contains_placeholder_bits field has been initialized,
4435 : : then we know the answer. */
4436 : 3044234 : if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
4437 : 2256162 : return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
4438 : :
4439 : : /* Indicate that we've seen this type node, and the answer is false.
4440 : : This is what we want to return if we run into recursion via fields. */
4441 : 788072 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
4442 : :
4443 : : /* Compute the real value. */
4444 : 788072 : result = type_contains_placeholder_1 (type);
4445 : :
4446 : : /* Store the real value. */
4447 : 788072 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
4448 : :
4449 : 788072 : return result;
4450 : : }
4451 : :
4452 : : /* Push tree EXP onto vector QUEUE if it is not already present. */
4453 : :
4454 : : static void
4455 : 0 : push_without_duplicates (tree exp, vec<tree> *queue)
4456 : : {
4457 : 0 : unsigned int i;
4458 : 0 : tree iter;
4459 : :
4460 : 0 : FOR_EACH_VEC_ELT (*queue, i, iter)
4461 : 0 : if (simple_cst_equal (iter, exp) == 1)
4462 : : break;
4463 : :
4464 : 0 : if (!iter)
4465 : 0 : queue->safe_push (exp);
4466 : 0 : }
4467 : :
4468 : : /* Given a tree EXP, find all occurrences of references to fields
4469 : : in a PLACEHOLDER_EXPR and place them in vector REFS without
4470 : : duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
4471 : : we assume here that EXP contains only arithmetic expressions
4472 : : or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
4473 : : argument list. */
4474 : :
4475 : : void
4476 : 0 : find_placeholder_in_expr (tree exp, vec<tree> *refs)
4477 : : {
4478 : 0 : enum tree_code code = TREE_CODE (exp);
4479 : 0 : tree inner;
4480 : 0 : int i;
4481 : :
4482 : : /* We handle TREE_LIST and COMPONENT_REF separately. */
4483 : 0 : if (code == TREE_LIST)
4484 : : {
4485 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs);
4486 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs);
4487 : : }
4488 : 0 : else if (code == COMPONENT_REF)
4489 : : {
4490 : 0 : for (inner = TREE_OPERAND (exp, 0);
4491 : 0 : REFERENCE_CLASS_P (inner);
4492 : 0 : inner = TREE_OPERAND (inner, 0))
4493 : : ;
4494 : :
4495 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
4496 : 0 : push_without_duplicates (exp, refs);
4497 : : else
4498 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs);
4499 : : }
4500 : : else
4501 : 0 : switch (TREE_CODE_CLASS (code))
4502 : : {
4503 : : case tcc_constant:
4504 : : break;
4505 : :
4506 : 0 : case tcc_declaration:
4507 : : /* Variables allocated to static storage can stay. */
4508 : 0 : if (!TREE_STATIC (exp))
4509 : 0 : push_without_duplicates (exp, refs);
4510 : : break;
4511 : :
4512 : 0 : case tcc_expression:
4513 : : /* This is the pattern built in ada/make_aligning_type. */
4514 : 0 : if (code == ADDR_EXPR
4515 : 0 : && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR)
4516 : : {
4517 : 0 : push_without_duplicates (exp, refs);
4518 : 0 : break;
4519 : : }
4520 : :
4521 : : /* Fall through. */
4522 : :
4523 : : case tcc_exceptional:
4524 : : case tcc_unary:
4525 : : case tcc_binary:
4526 : : case tcc_comparison:
4527 : : case tcc_reference:
4528 : 0 : for (i = 0; i < TREE_CODE_LENGTH (code); i++)
4529 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4530 : : break;
4531 : :
4532 : : case tcc_vl_exp:
4533 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4534 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4535 : : break;
4536 : :
4537 : 0 : default:
4538 : 0 : gcc_unreachable ();
4539 : : }
4540 : 0 : }
4541 : :
4542 : : /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
4543 : : return a tree with all occurrences of references to F in a
4544 : : PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
4545 : : CONST_DECLs. Note that we assume here that EXP contains only
4546 : : arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
4547 : : occurring only in their argument list. */
4548 : :
4549 : : tree
4550 : 0 : substitute_in_expr (tree exp, tree f, tree r)
4551 : : {
4552 : 0 : enum tree_code code = TREE_CODE (exp);
4553 : 0 : tree op0, op1, op2, op3;
4554 : 0 : tree new_tree;
4555 : :
4556 : : /* We handle TREE_LIST and COMPONENT_REF separately. */
4557 : 0 : if (code == TREE_LIST)
4558 : : {
4559 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
4560 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
4561 : 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4562 : : return exp;
4563 : :
4564 : 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4565 : : }
4566 : 0 : else if (code == COMPONENT_REF)
4567 : : {
4568 : 0 : tree inner;
4569 : :
4570 : : /* If this expression is getting a value from a PLACEHOLDER_EXPR
4571 : : and it is the right field, replace it with R. */
4572 : 0 : for (inner = TREE_OPERAND (exp, 0);
4573 : 0 : REFERENCE_CLASS_P (inner);
4574 : 0 : inner = TREE_OPERAND (inner, 0))
4575 : : ;
4576 : :
4577 : : /* The field. */
4578 : 0 : op1 = TREE_OPERAND (exp, 1);
4579 : :
4580 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f)
4581 : : return r;
4582 : :
4583 : : /* If this expression hasn't been completed let, leave it alone. */
4584 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner))
4585 : : return exp;
4586 : :
4587 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4588 : 0 : if (op0 == TREE_OPERAND (exp, 0))
4589 : : return exp;
4590 : :
4591 : 0 : new_tree
4592 : 0 : = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE);
4593 : : }
4594 : : else
4595 : 0 : switch (TREE_CODE_CLASS (code))
4596 : : {
4597 : : case tcc_constant:
4598 : : return exp;
4599 : :
4600 : 0 : case tcc_declaration:
4601 : 0 : if (exp == f)
4602 : : return r;
4603 : : else
4604 : : return exp;
4605 : :
4606 : 0 : case tcc_expression:
4607 : 0 : if (exp == f)
4608 : : return r;
4609 : :
4610 : : /* Fall through. */
4611 : :
4612 : 0 : case tcc_exceptional:
4613 : 0 : case tcc_unary:
4614 : 0 : case tcc_binary:
4615 : 0 : case tcc_comparison:
4616 : 0 : case tcc_reference:
4617 : 0 : switch (TREE_CODE_LENGTH (code))
4618 : : {
4619 : : case 0:
4620 : : return exp;
4621 : :
4622 : 0 : case 1:
4623 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4624 : 0 : if (op0 == TREE_OPERAND (exp, 0))
4625 : : return exp;
4626 : :
4627 : 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4628 : 0 : break;
4629 : :
4630 : 0 : case 2:
4631 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4632 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4633 : :
4634 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4635 : : return exp;
4636 : :
4637 : 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4638 : 0 : break;
4639 : :
4640 : 0 : case 3:
4641 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4642 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4643 : 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4644 : :
4645 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4646 : 0 : && op2 == TREE_OPERAND (exp, 2))
4647 : : return exp;
4648 : :
4649 : 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4650 : 0 : break;
4651 : :
4652 : 0 : case 4:
4653 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4654 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4655 : 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4656 : 0 : op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
4657 : :
4658 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4659 : 0 : && op2 == TREE_OPERAND (exp, 2)
4660 : 0 : && op3 == TREE_OPERAND (exp, 3))
4661 : : return exp;
4662 : :
4663 : 0 : new_tree
4664 : 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4665 : 0 : break;
4666 : :
4667 : 0 : default:
4668 : 0 : gcc_unreachable ();
4669 : : }
4670 : : break;
4671 : :
4672 : 0 : case tcc_vl_exp:
4673 : 0 : {
4674 : 0 : int i;
4675 : :
4676 : 0 : new_tree = NULL_TREE;
4677 : :
4678 : : /* If we are trying to replace F with a constant or with another
4679 : : instance of one of the arguments of the call, inline back
4680 : : functions which do nothing else than computing a value from
4681 : : the arguments they are passed. This makes it possible to
4682 : : fold partially or entirely the replacement expression. */
4683 : 0 : if (code == CALL_EXPR)
4684 : : {
4685 : 0 : bool maybe_inline = false;
4686 : 0 : if (CONSTANT_CLASS_P (r))
4687 : : maybe_inline = true;
4688 : : else
4689 : 0 : for (i = 3; i < TREE_OPERAND_LENGTH (exp); i++)
4690 : 0 : if (operand_equal_p (TREE_OPERAND (exp, i), r, 0))
4691 : : {
4692 : : maybe_inline = true;
4693 : : break;
4694 : : }
4695 : 0 : if (maybe_inline)
4696 : : {
4697 : 0 : tree t = maybe_inline_call_in_expr (exp);
4698 : 0 : if (t)
4699 : 0 : return SUBSTITUTE_IN_EXPR (t, f, r);
4700 : : }
4701 : : }
4702 : :
4703 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4704 : : {
4705 : 0 : tree op = TREE_OPERAND (exp, i);
4706 : 0 : tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
4707 : 0 : if (new_op != op)
4708 : : {
4709 : 0 : if (!new_tree)
4710 : 0 : new_tree = copy_node (exp);
4711 : 0 : TREE_OPERAND (new_tree, i) = new_op;
4712 : : }
4713 : : }
4714 : :
4715 : 0 : if (new_tree)
4716 : : {
4717 : 0 : new_tree = fold (new_tree);
4718 : 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4719 : 0 : process_call_operands (new_tree);
4720 : : }
4721 : : else
4722 : : return exp;
4723 : : }
4724 : : break;
4725 : :
4726 : 0 : default:
4727 : 0 : gcc_unreachable ();
4728 : : }
4729 : :
4730 : 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4731 : :
4732 : 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4733 : 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4734 : :
4735 : : return new_tree;
4736 : : }
4737 : :
4738 : : /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
4739 : : for it within OBJ, a tree that is an object or a chain of references. */
4740 : :
4741 : : tree
4742 : 224892 : substitute_placeholder_in_expr (tree exp, tree obj)
4743 : : {
4744 : 224892 : enum tree_code code = TREE_CODE (exp);
4745 : 224892 : tree op0, op1, op2, op3;
4746 : 224892 : tree new_tree;
4747 : :
4748 : : /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
4749 : : in the chain of OBJ. */
4750 : 224892 : if (code == PLACEHOLDER_EXPR)
4751 : : {
4752 : 0 : tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
4753 : 0 : tree elt;
4754 : :
4755 : 0 : for (elt = obj; elt != 0;
4756 : 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4757 : 0 : || TREE_CODE (elt) == COND_EXPR)
4758 : 0 : ? TREE_OPERAND (elt, 1)
4759 : 0 : : (REFERENCE_CLASS_P (elt)
4760 : : || UNARY_CLASS_P (elt)
4761 : : || BINARY_CLASS_P (elt)
4762 : : || VL_EXP_CLASS_P (elt)
4763 : : || EXPRESSION_CLASS_P (elt))
4764 : 0 : ? TREE_OPERAND (elt, 0) : 0))
4765 : 0 : if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
4766 : : return elt;
4767 : :
4768 : 0 : for (elt = obj; elt != 0;
4769 : 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4770 : 0 : || TREE_CODE (elt) == COND_EXPR)
4771 : 0 : ? TREE_OPERAND (elt, 1)
4772 : 0 : : (REFERENCE_CLASS_P (elt)
4773 : : || UNARY_CLASS_P (elt)
4774 : : || BINARY_CLASS_P (elt)
4775 : : || VL_EXP_CLASS_P (elt)
4776 : : || EXPRESSION_CLASS_P (elt))
4777 : 0 : ? TREE_OPERAND (elt, 0) : 0))
4778 : 0 : if (POINTER_TYPE_P (TREE_TYPE (elt))
4779 : 0 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
4780 : : == need_type))
4781 : 0 : return fold_build1 (INDIRECT_REF, need_type, elt);
4782 : :
4783 : : /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
4784 : : survives until RTL generation, there will be an error. */
4785 : : return exp;
4786 : : }
4787 : :
4788 : : /* TREE_LIST is special because we need to look at TREE_VALUE
4789 : : and TREE_CHAIN, not TREE_OPERANDS. */
4790 : 224892 : else if (code == TREE_LIST)
4791 : : {
4792 : 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
4793 : 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
4794 : 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4795 : : return exp;
4796 : :
4797 : 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4798 : : }
4799 : : else
4800 : 224892 : switch (TREE_CODE_CLASS (code))
4801 : : {
4802 : : case tcc_constant:
4803 : : case tcc_declaration:
4804 : : return exp;
4805 : :
4806 : 9509 : case tcc_exceptional:
4807 : 9509 : case tcc_unary:
4808 : 9509 : case tcc_binary:
4809 : 9509 : case tcc_comparison:
4810 : 9509 : case tcc_expression:
4811 : 9509 : case tcc_reference:
4812 : 9509 : case tcc_statement:
4813 : 9509 : switch (TREE_CODE_LENGTH (code))
4814 : : {
4815 : : case 0:
4816 : : return exp;
4817 : :
4818 : 7212 : case 1:
4819 : 7212 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4820 : 7212 : if (op0 == TREE_OPERAND (exp, 0))
4821 : : return exp;
4822 : :
4823 : 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4824 : 0 : break;
4825 : :
4826 : 2285 : case 2:
4827 : 2285 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4828 : 2285 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4829 : :
4830 : 2285 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4831 : : return exp;
4832 : :
4833 : 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4834 : 0 : break;
4835 : :
4836 : 12 : case 3:
4837 : 12 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4838 : 12 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4839 : 12 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4840 : :
4841 : 24 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4842 : 24 : && op2 == TREE_OPERAND (exp, 2))
4843 : : return exp;
4844 : :
4845 : 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4846 : 0 : break;
4847 : :
4848 : 0 : case 4:
4849 : 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4850 : 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4851 : 0 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4852 : 0 : op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
4853 : :
4854 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4855 : 0 : && op2 == TREE_OPERAND (exp, 2)
4856 : 0 : && op3 == TREE_OPERAND (exp, 3))
4857 : : return exp;
4858 : :
4859 : 0 : new_tree
4860 : 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4861 : 0 : break;
4862 : :
4863 : 0 : default:
4864 : 0 : gcc_unreachable ();
4865 : : }
4866 : : break;
4867 : :
4868 : : case tcc_vl_exp:
4869 : : {
4870 : : int i;
4871 : :
4872 : : new_tree = NULL_TREE;
4873 : :
4874 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4875 : : {
4876 : 0 : tree op = TREE_OPERAND (exp, i);
4877 : 0 : tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
4878 : 0 : if (new_op != op)
4879 : : {
4880 : 0 : if (!new_tree)
4881 : 0 : new_tree = copy_node (exp);
4882 : 0 : TREE_OPERAND (new_tree, i) = new_op;
4883 : : }
4884 : : }
4885 : :
4886 : 0 : if (new_tree)
4887 : : {
4888 : 0 : new_tree = fold (new_tree);
4889 : 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4890 : 0 : process_call_operands (new_tree);
4891 : : }
4892 : : else
4893 : : return exp;
4894 : : }
4895 : : break;
4896 : :
4897 : 0 : default:
4898 : 0 : gcc_unreachable ();
4899 : : }
4900 : :
4901 : 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4902 : :
4903 : 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4904 : 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4905 : :
4906 : : return new_tree;
4907 : : }
4908 : :
4909 : :
4910 : : /* Subroutine of stabilize_reference; this is called for subtrees of
4911 : : references. Any expression with side-effects must be put in a SAVE_EXPR
4912 : : to ensure that it is only evaluated once.
4913 : :
4914 : : We don't put SAVE_EXPR nodes around everything, because assigning very
4915 : : simple expressions to temporaries causes us to miss good opportunities
4916 : : for optimizations. Among other things, the opportunity to fold in the
4917 : : addition of a constant into an addressing mode often gets lost, e.g.
4918 : : "y[i+1] += x;". In general, we take the approach that we should not make
4919 : : an assignment unless we are forced into it - i.e., that any non-side effect
4920 : : operator should be allowed, and that cse should take care of coalescing
4921 : : multiple utterances of the same expression should that prove fruitful. */
4922 : :
4923 : : static tree
4924 : 649202 : stabilize_reference_1 (tree e)
4925 : : {
4926 : 649202 : tree result;
4927 : 649202 : enum tree_code code = TREE_CODE (e);
4928 : :
4929 : : /* We cannot ignore const expressions because it might be a reference
4930 : : to a const array but whose index contains side-effects. But we can
4931 : : ignore things that are actual constant or that already have been
4932 : : handled by this function. */
4933 : :
4934 : 649202 : if (tree_invariant_p (e))
4935 : : return e;
4936 : :
4937 : 129283 : switch (TREE_CODE_CLASS (code))
4938 : : {
4939 : 0 : case tcc_exceptional:
4940 : : /* Always wrap STATEMENT_LIST into SAVE_EXPR, even if it doesn't
4941 : : have side-effects. */
4942 : 0 : if (code == STATEMENT_LIST)
4943 : 0 : return save_expr (e);
4944 : : /* FALLTHRU */
4945 : 100342 : case tcc_type:
4946 : 100342 : case tcc_declaration:
4947 : 100342 : case tcc_comparison:
4948 : 100342 : case tcc_statement:
4949 : 100342 : case tcc_expression:
4950 : 100342 : case tcc_reference:
4951 : 100342 : case tcc_vl_exp:
4952 : : /* If the expression has side-effects, then encase it in a SAVE_EXPR
4953 : : so that it will only be evaluated once. */
4954 : : /* The reference (r) and comparison (<) classes could be handled as
4955 : : below, but it is generally faster to only evaluate them once. */
4956 : 100342 : if (TREE_SIDE_EFFECTS (e))
4957 : 979 : return save_expr (e);
4958 : : return e;
4959 : :
4960 : : case tcc_constant:
4961 : : /* Constants need no processing. In fact, we should never reach
4962 : : here. */
4963 : : return e;
4964 : :
4965 : 21560 : case tcc_binary:
4966 : : /* Division is slow and tends to be compiled with jumps,
4967 : : especially the division by powers of 2 that is often
4968 : : found inside of an array reference. So do it just once. */
4969 : 21560 : if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
4970 : 19520 : || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
4971 : 19520 : || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
4972 : 19520 : || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
4973 : 2040 : return save_expr (e);
4974 : : /* Recursively stabilize each operand. */
4975 : 19520 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
4976 : 19520 : stabilize_reference_1 (TREE_OPERAND (e, 1)));
4977 : 19520 : break;
4978 : :
4979 : 7381 : case tcc_unary:
4980 : : /* Recursively stabilize each operand. */
4981 : 7381 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
4982 : 7381 : break;
4983 : :
4984 : 0 : default:
4985 : 0 : gcc_unreachable ();
4986 : : }
4987 : :
4988 : 26901 : TREE_TYPE (result) = TREE_TYPE (e);
4989 : 26901 : TREE_READONLY (result) = TREE_READONLY (e);
4990 : 26901 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
4991 : 26901 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
4992 : :
4993 : 26901 : return result;
4994 : : }
4995 : :
4996 : : /* Stabilize a reference so that we can use it any number of times
4997 : : without causing its operands to be evaluated more than once.
4998 : : Returns the stabilized reference. This works by means of save_expr,
4999 : : so see the caveats in the comments about save_expr.
5000 : :
5001 : : Also allows conversion expressions whose operands are references.
5002 : : Any other kind of expression is returned unchanged. */
5003 : :
5004 : : tree
5005 : 4357598 : stabilize_reference (tree ref)
5006 : : {
5007 : 4357598 : tree result;
5008 : 4357598 : enum tree_code code = TREE_CODE (ref);
5009 : :
5010 : 4357598 : switch (code)
5011 : : {
5012 : : case VAR_DECL:
5013 : : case PARM_DECL:
5014 : : case RESULT_DECL:
5015 : : /* No action is needed in this case. */
5016 : : return ref;
5017 : :
5018 : 0 : CASE_CONVERT:
5019 : 0 : case FLOAT_EXPR:
5020 : 0 : case FIX_TRUNC_EXPR:
5021 : 0 : result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
5022 : 0 : break;
5023 : :
5024 : 556088 : case INDIRECT_REF:
5025 : 556088 : result = build_nt (INDIRECT_REF,
5026 : 556088 : stabilize_reference_1 (TREE_OPERAND (ref, 0)));
5027 : 556088 : break;
5028 : :
5029 : 354960 : case COMPONENT_REF:
5030 : 354960 : result = build_nt (COMPONENT_REF,
5031 : 354960 : stabilize_reference (TREE_OPERAND (ref, 0)),
5032 : 354960 : TREE_OPERAND (ref, 1), NULL_TREE);
5033 : 354960 : break;
5034 : :
5035 : 0 : case BIT_FIELD_REF:
5036 : 0 : result = build_nt (BIT_FIELD_REF,
5037 : 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5038 : 0 : TREE_OPERAND (ref, 1), TREE_OPERAND (ref, 2));
5039 : 0 : REF_REVERSE_STORAGE_ORDER (result) = REF_REVERSE_STORAGE_ORDER (ref);
5040 : 0 : break;
5041 : :
5042 : 46693 : case ARRAY_REF:
5043 : 93386 : result = build_nt (ARRAY_REF,
5044 : 46693 : stabilize_reference (TREE_OPERAND (ref, 0)),
5045 : 46693 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5046 : 46693 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5047 : 46693 : break;
5048 : :
5049 : 0 : case ARRAY_RANGE_REF:
5050 : 0 : result = build_nt (ARRAY_RANGE_REF,
5051 : 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5052 : 0 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5053 : 0 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5054 : 0 : break;
5055 : :
5056 : 0 : case COMPOUND_EXPR:
5057 : : /* We cannot wrap the first expression in a SAVE_EXPR, as then
5058 : : it wouldn't be ignored. This matters when dealing with
5059 : : volatiles. */
5060 : 0 : return stabilize_reference_1 (ref);
5061 : :
5062 : : /* If arg isn't a kind of lvalue we recognize, make no change.
5063 : : Caller should recognize the error for an invalid lvalue. */
5064 : : default:
5065 : : return ref;
5066 : :
5067 : 0 : case ERROR_MARK:
5068 : 0 : return error_mark_node;
5069 : : }
5070 : :
5071 : 957741 : TREE_TYPE (result) = TREE_TYPE (ref);
5072 : 957741 : TREE_READONLY (result) = TREE_READONLY (ref);
5073 : 957741 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
5074 : 957741 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
5075 : 957741 : protected_set_expr_location (result, EXPR_LOCATION (ref));
5076 : :
5077 : 957741 : return result;
5078 : : }
5079 : :
5080 : : /* Low-level constructors for expressions. */
5081 : :
5082 : : /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
5083 : : and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
5084 : :
5085 : : void
5086 : 1253518515 : recompute_tree_invariant_for_addr_expr (tree t)
5087 : : {
5088 : 1253518515 : tree node;
5089 : 1253518515 : bool tc = true, se = false;
5090 : :
5091 : 1253518515 : gcc_assert (TREE_CODE (t) == ADDR_EXPR);
5092 : :
5093 : : /* We started out assuming this address is both invariant and constant, but
5094 : : does not have side effects. Now go down any handled components and see if
5095 : : any of them involve offsets that are either non-constant or non-invariant.
5096 : : Also check for side-effects.
5097 : :
5098 : : ??? Note that this code makes no attempt to deal with the case where
5099 : : taking the address of something causes a copy due to misalignment. */
5100 : :
5101 : : #define UPDATE_FLAGS(NODE) \
5102 : : do { tree _node = (NODE); \
5103 : : if (_node && !TREE_CONSTANT (_node)) tc = false; \
5104 : : if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
5105 : :
5106 : 1463434272 : for (node = TREE_OPERAND (t, 0); handled_component_p (node);
5107 : 209915757 : node = TREE_OPERAND (node, 0))
5108 : : {
5109 : : /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
5110 : : array reference (probably made temporarily by the G++ front end),
5111 : : so ignore all the operands. */
5112 : 209915757 : if ((TREE_CODE (node) == ARRAY_REF
5113 : 209915757 : || TREE_CODE (node) == ARRAY_RANGE_REF)
5114 : 209915757 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
5115 : : {
5116 : 31299495 : UPDATE_FLAGS (TREE_OPERAND (node, 1));
5117 : 31299495 : if (TREE_OPERAND (node, 2))
5118 : 2259832 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5119 : 31299495 : if (TREE_OPERAND (node, 3))
5120 : 268121 : UPDATE_FLAGS (TREE_OPERAND (node, 3));
5121 : : }
5122 : : /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
5123 : : FIELD_DECL, apparently. The G++ front end can put something else
5124 : : there, at least temporarily. */
5125 : 178616262 : else if (TREE_CODE (node) == COMPONENT_REF
5126 : 178616262 : && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
5127 : : {
5128 : 177722102 : if (TREE_OPERAND (node, 2))
5129 : 17035 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5130 : : }
5131 : : }
5132 : :
5133 : 1253518515 : node = lang_hooks.expr_to_decl (node, &tc, &se);
5134 : :
5135 : : /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
5136 : : the address, since &(*a)->b is a form of addition. If it's a constant, the
5137 : : address is constant too. If it's a decl, its address is constant if the
5138 : : decl is static. Everything else is not constant and, furthermore,
5139 : : taking the address of a volatile variable is not volatile. */
5140 : 1253518515 : if (INDIRECT_REF_P (node)
5141 : 1221074585 : || TREE_CODE (node) == MEM_REF)
5142 : 147986243 : UPDATE_FLAGS (TREE_OPERAND (node, 0));
5143 : 1105532272 : else if (CONSTANT_CLASS_P (node))
5144 : : ;
5145 : 1032742099 : else if (DECL_P (node))
5146 : 1015733969 : tc &= (staticp (node) != NULL_TREE);
5147 : : else
5148 : : {
5149 : 17008130 : tc = false;
5150 : 17008130 : se |= TREE_SIDE_EFFECTS (node);
5151 : : }
5152 : :
5153 : :
5154 : 1253518515 : TREE_CONSTANT (t) = tc;
5155 : 1253518515 : TREE_SIDE_EFFECTS (t) = se;
5156 : : #undef UPDATE_FLAGS
5157 : 1253518515 : }
5158 : :
5159 : : /* Build an expression of code CODE, data type TYPE, and operands as
5160 : : specified. Expressions and reference nodes can be created this way.
5161 : : Constants, decls, types and misc nodes cannot be.
5162 : :
5163 : : We define 5 non-variadic functions, from 0 to 4 arguments. This is
5164 : : enough for all extant tree codes. */
5165 : :
5166 : : tree
5167 : 339534026 : build0 (enum tree_code code, tree tt MEM_STAT_DECL)
5168 : : {
5169 : 339534026 : tree t;
5170 : :
5171 : 339534026 : gcc_assert (TREE_CODE_LENGTH (code) == 0);
5172 : :
5173 : 339534026 : t = make_node (code PASS_MEM_STAT);
5174 : 339534026 : TREE_TYPE (t) = tt;
5175 : :
5176 : 339534026 : return t;
5177 : : }
5178 : :
5179 : : tree
5180 : 3333895519 : build1 (enum tree_code code, tree type, tree node MEM_STAT_DECL)
5181 : : {
5182 : 3333895519 : int length = sizeof (struct tree_exp);
5183 : 3333895519 : tree t;
5184 : :
5185 : 3333895519 : record_node_allocation_statistics (code, length);
5186 : :
5187 : 3333895519 : gcc_assert (TREE_CODE_LENGTH (code) == 1);
5188 : :
5189 : 3333895519 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
5190 : :
5191 : 3333895519 : memset (t, 0, sizeof (struct tree_common));
5192 : :
5193 : 3333895519 : TREE_SET_CODE (t, code);
5194 : :
5195 : 3333895519 : TREE_TYPE (t) = type;
5196 : 3333895519 : SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
5197 : 3333895519 : TREE_OPERAND (t, 0) = node;
5198 : 3333895519 : if (node && !TYPE_P (node))
5199 : : {
5200 : 3333880456 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
5201 : 3333880456 : TREE_READONLY (t) = TREE_READONLY (node);
5202 : : }
5203 : :
5204 : 3333895519 : if (TREE_CODE_CLASS (code) == tcc_statement)
5205 : : {
5206 : 22686554 : if (code != DEBUG_BEGIN_STMT)
5207 : 22686554 : TREE_SIDE_EFFECTS (t) = 1;
5208 : : }
5209 : 3311208965 : else switch (code)
5210 : : {
5211 : 50948 : case VA_ARG_EXPR:
5212 : : /* All of these have side-effects, no matter what their
5213 : : operands are. */
5214 : 50948 : TREE_SIDE_EFFECTS (t) = 1;
5215 : 50948 : TREE_READONLY (t) = 0;
5216 : 50948 : break;
5217 : :
5218 : 529827453 : case INDIRECT_REF:
5219 : : /* Whether a dereference is readonly has nothing to do with whether
5220 : : its operand is readonly. */
5221 : 529827453 : TREE_READONLY (t) = 0;
5222 : 529827453 : break;
5223 : :
5224 : 540829906 : case ADDR_EXPR:
5225 : 540829906 : if (node)
5226 : 540829906 : recompute_tree_invariant_for_addr_expr (t);
5227 : : break;
5228 : :
5229 : 2240500658 : default:
5230 : 867365652 : if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
5231 : 2121364587 : && node && !TYPE_P (node)
5232 : 4361865245 : && TREE_CONSTANT (node))
5233 : 551829354 : TREE_CONSTANT (t) = 1;
5234 : 2240500658 : if (TREE_CODE_CLASS (code) == tcc_reference
5235 : 750800959 : && node && TREE_THIS_VOLATILE (node))
5236 : 2534128 : TREE_THIS_VOLATILE (t) = 1;
5237 : : break;
5238 : : }
5239 : :
5240 : 3333895519 : return t;
5241 : : }
5242 : :
5243 : : #define PROCESS_ARG(N) \
5244 : : do { \
5245 : : TREE_OPERAND (t, N) = arg##N; \
5246 : : if (arg##N &&!TYPE_P (arg##N)) \
5247 : : { \
5248 : : if (TREE_SIDE_EFFECTS (arg##N)) \
5249 : : side_effects = 1; \
5250 : : if (!TREE_READONLY (arg##N) \
5251 : : && !CONSTANT_CLASS_P (arg##N)) \
5252 : : (void) (read_only = 0); \
5253 : : if (!TREE_CONSTANT (arg##N)) \
5254 : : (void) (constant = 0); \
5255 : : } \
5256 : : } while (0)
5257 : :
5258 : : tree
5259 : 1102242591 : build2 (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
5260 : : {
5261 : 1102242591 : bool constant, read_only, side_effects, div_by_zero;
5262 : 1102242591 : tree t;
5263 : :
5264 : 1102242591 : gcc_assert (TREE_CODE_LENGTH (code) == 2);
5265 : :
5266 : 1102242591 : if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
5267 : 185171973 : && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
5268 : : /* When sizetype precision doesn't match that of pointers
5269 : : we need to be able to build explicit extensions or truncations
5270 : : of the offset argument. */
5271 : 1102242591 : && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
5272 : 0 : gcc_assert (TREE_CODE (arg0) == INTEGER_CST
5273 : : && TREE_CODE (arg1) == INTEGER_CST);
5274 : :
5275 : 1102242591 : if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
5276 : 25362786 : gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
5277 : : && ptrofftype_p (TREE_TYPE (arg1)));
5278 : :
5279 : 1102242591 : t = make_node (code PASS_MEM_STAT);
5280 : 1102242591 : TREE_TYPE (t) = tt;
5281 : :
5282 : : /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
5283 : : result based on those same flags for the arguments. But if the
5284 : : arguments aren't really even `tree' expressions, we shouldn't be trying
5285 : : to do this. */
5286 : :
5287 : : /* Expressions without side effects may be constant if their
5288 : : arguments are as well. */
5289 : 2204485182 : constant = (TREE_CODE_CLASS (code) == tcc_comparison
5290 : 1102242591 : || TREE_CODE_CLASS (code) == tcc_binary);
5291 : 1102242591 : read_only = 1;
5292 : 1102242591 : side_effects = TREE_SIDE_EFFECTS (t);
5293 : :
5294 : 1102242591 : switch (code)
5295 : : {
5296 : 10538385 : case TRUNC_DIV_EXPR:
5297 : 10538385 : case CEIL_DIV_EXPR:
5298 : 10538385 : case FLOOR_DIV_EXPR:
5299 : 10538385 : case ROUND_DIV_EXPR:
5300 : 10538385 : case EXACT_DIV_EXPR:
5301 : 10538385 : case CEIL_MOD_EXPR:
5302 : 10538385 : case FLOOR_MOD_EXPR:
5303 : 10538385 : case ROUND_MOD_EXPR:
5304 : 10538385 : case TRUNC_MOD_EXPR:
5305 : 10538385 : div_by_zero = integer_zerop (arg1);
5306 : 10538385 : break;
5307 : : default:
5308 : : div_by_zero = false;
5309 : : }
5310 : :
5311 : 1199747780 : PROCESS_ARG (0);
5312 : 1547417625 : PROCESS_ARG (1);
5313 : :
5314 : 1102242591 : TREE_SIDE_EFFECTS (t) = side_effects;
5315 : 1102242591 : if (code == MEM_REF)
5316 : : {
5317 : 70803506 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5318 : : {
5319 : 14919668 : tree o = TREE_OPERAND (arg0, 0);
5320 : 14919668 : TREE_READONLY (t) = TREE_READONLY (o);
5321 : 14919668 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5322 : : }
5323 : : }
5324 : : else
5325 : : {
5326 : 1031439085 : TREE_READONLY (t) = read_only;
5327 : : /* Don't mark X / 0 as constant. */
5328 : 1031439085 : TREE_CONSTANT (t) = constant && !div_by_zero;
5329 : 1031439085 : TREE_THIS_VOLATILE (t)
5330 : 1031439085 : = (TREE_CODE_CLASS (code) == tcc_reference
5331 : 1031439085 : && arg0 && TREE_THIS_VOLATILE (arg0));
5332 : : }
5333 : :
5334 : 1102242591 : return t;
5335 : : }
5336 : :
5337 : :
5338 : : tree
5339 : 408868245 : build3 (enum tree_code code, tree tt, tree arg0, tree arg1,
5340 : : tree arg2 MEM_STAT_DECL)
5341 : : {
5342 : 408868245 : bool constant, read_only, side_effects;
5343 : 408868245 : tree t;
5344 : :
5345 : 408868245 : gcc_assert (TREE_CODE_LENGTH (code) == 3);
5346 : 408868245 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5347 : :
5348 : 408868245 : t = make_node (code PASS_MEM_STAT);
5349 : 408868245 : TREE_TYPE (t) = tt;
5350 : :
5351 : 408868245 : read_only = 1;
5352 : :
5353 : : /* As a special exception, if COND_EXPR has NULL branches, we
5354 : : assume that it is a gimple statement and always consider
5355 : : it to have side effects. */
5356 : 408868245 : if (code == COND_EXPR
5357 : 34347088 : && tt == void_type_node
5358 : 22676806 : && arg1 == NULL_TREE
5359 : 22676806 : && arg2 == NULL_TREE)
5360 : : side_effects = true;
5361 : : else
5362 : 408868245 : side_effects = TREE_SIDE_EFFECTS (t);
5363 : :
5364 : 446261752 : PROCESS_ARG (0);
5365 : 420895576 : PROCESS_ARG (1);
5366 : 420047850 : PROCESS_ARG (2);
5367 : :
5368 : 408868245 : if (code == COND_EXPR)
5369 : 34347088 : TREE_READONLY (t) = read_only;
5370 : :
5371 : 408868245 : TREE_SIDE_EFFECTS (t) = side_effects;
5372 : 408868245 : TREE_THIS_VOLATILE (t)
5373 : 408868245 : = (TREE_CODE_CLASS (code) == tcc_reference
5374 : 408868245 : && arg0 && TREE_THIS_VOLATILE (arg0));
5375 : :
5376 : 408868245 : return t;
5377 : : }
5378 : :
5379 : : tree
5380 : 40115237 : build4 (enum tree_code code, tree tt, tree arg0, tree arg1,
5381 : : tree arg2, tree arg3 MEM_STAT_DECL)
5382 : : {
5383 : 40115237 : bool constant, read_only, side_effects;
5384 : 40115237 : tree t;
5385 : :
5386 : 40115237 : gcc_assert (TREE_CODE_LENGTH (code) == 4);
5387 : :
5388 : 40115237 : t = make_node (code PASS_MEM_STAT);
5389 : 40115237 : TREE_TYPE (t) = tt;
5390 : :
5391 : 40115237 : side_effects = TREE_SIDE_EFFECTS (t);
5392 : :
5393 : 40115237 : PROCESS_ARG (0);
5394 : 40115237 : PROCESS_ARG (1);
5395 : 40115237 : PROCESS_ARG (2);
5396 : 40115237 : PROCESS_ARG (3);
5397 : :
5398 : 40115237 : TREE_SIDE_EFFECTS (t) = side_effects;
5399 : 40115237 : TREE_THIS_VOLATILE (t)
5400 : 80230474 : = (TREE_CODE_CLASS (code) == tcc_reference
5401 : 40115237 : && arg0 && TREE_THIS_VOLATILE (arg0));
5402 : :
5403 : 40115237 : return t;
5404 : : }
5405 : :
5406 : : tree
5407 : 1144582 : build5 (enum tree_code code, tree tt, tree arg0, tree arg1,
5408 : : tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
5409 : : {
5410 : 1144582 : bool constant, read_only, side_effects;
5411 : 1144582 : tree t;
5412 : :
5413 : 1144582 : gcc_assert (TREE_CODE_LENGTH (code) == 5);
5414 : :
5415 : 1144582 : t = make_node (code PASS_MEM_STAT);
5416 : 1144582 : TREE_TYPE (t) = tt;
5417 : :
5418 : 1144582 : side_effects = TREE_SIDE_EFFECTS (t);
5419 : :
5420 : 1144582 : PROCESS_ARG (0);
5421 : 1144582 : PROCESS_ARG (1);
5422 : 1144582 : PROCESS_ARG (2);
5423 : 1144582 : PROCESS_ARG (3);
5424 : 1144582 : PROCESS_ARG (4);
5425 : :
5426 : 1144582 : TREE_SIDE_EFFECTS (t) = side_effects;
5427 : 1144582 : if (code == TARGET_MEM_REF)
5428 : : {
5429 : 1137823 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5430 : : {
5431 : 192902 : tree o = TREE_OPERAND (arg0, 0);
5432 : 192902 : TREE_READONLY (t) = TREE_READONLY (o);
5433 : 192902 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5434 : : }
5435 : : }
5436 : : else
5437 : 6759 : TREE_THIS_VOLATILE (t)
5438 : 6759 : = (TREE_CODE_CLASS (code) == tcc_reference
5439 : 6759 : && arg0 && TREE_THIS_VOLATILE (arg0));
5440 : :
5441 : 1144582 : return t;
5442 : : }
5443 : :
5444 : : /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
5445 : : on the pointer PTR. */
5446 : :
5447 : : tree
5448 : 488655 : build_simple_mem_ref_loc (location_t loc, tree ptr)
5449 : : {
5450 : 488655 : poly_int64 offset = 0;
5451 : 488655 : tree ptype = TREE_TYPE (ptr);
5452 : 488655 : tree tem;
5453 : : /* For convenience allow addresses that collapse to a simple base
5454 : : and offset. */
5455 : 488655 : if (TREE_CODE (ptr) == ADDR_EXPR
5456 : 488655 : && (handled_component_p (TREE_OPERAND (ptr, 0))
5457 : 15520 : || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF))
5458 : : {
5459 : 187 : ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset);
5460 : 187 : gcc_assert (ptr);
5461 : 187 : if (TREE_CODE (ptr) == MEM_REF)
5462 : : {
5463 : 77 : offset += mem_ref_offset (ptr).force_shwi ();
5464 : 77 : ptr = TREE_OPERAND (ptr, 0);
5465 : : }
5466 : : else
5467 : 110 : ptr = build_fold_addr_expr (ptr);
5468 : 187 : gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr));
5469 : : }
5470 : 488655 : tem = build2 (MEM_REF, TREE_TYPE (ptype),
5471 : : ptr, build_int_cst (ptype, offset));
5472 : 488655 : SET_EXPR_LOCATION (tem, loc);
5473 : 488655 : return tem;
5474 : : }
5475 : :
5476 : : /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
5477 : :
5478 : : poly_offset_int
5479 : 1181951577 : mem_ref_offset (const_tree t)
5480 : : {
5481 : 1181951577 : return poly_offset_int::from (wi::to_poly_wide (TREE_OPERAND (t, 1)),
5482 : 1181951577 : SIGNED);
5483 : : }
5484 : :
5485 : : /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
5486 : : offsetted by OFFSET units. */
5487 : :
5488 : : tree
5489 : 190099 : build_invariant_address (tree type, tree base, poly_int64 offset)
5490 : : {
5491 : 190099 : tree ref = fold_build2 (MEM_REF, TREE_TYPE (type),
5492 : : build_fold_addr_expr (base),
5493 : : build_int_cst (ptr_type_node, offset));
5494 : 190099 : tree addr = build1 (ADDR_EXPR, type, ref);
5495 : 190099 : recompute_tree_invariant_for_addr_expr (addr);
5496 : 190099 : return addr;
5497 : : }
5498 : :
5499 : : /* Similar except don't specify the TREE_TYPE
5500 : : and leave the TREE_SIDE_EFFECTS as 0.
5501 : : It is permissible for arguments to be null,
5502 : : or even garbage if their values do not matter. */
5503 : :
5504 : : tree
5505 : 2614969 : build_nt (enum tree_code code, ...)
5506 : : {
5507 : 2614969 : tree t;
5508 : 2614969 : int length;
5509 : 2614969 : int i;
5510 : 2614969 : va_list p;
5511 : :
5512 : 2614969 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5513 : :
5514 : 2614969 : va_start (p, code);
5515 : :
5516 : 2614969 : t = make_node (code);
5517 : 2614969 : length = TREE_CODE_LENGTH (code);
5518 : :
5519 : 7210130 : for (i = 0; i < length; i++)
5520 : 4595161 : TREE_OPERAND (t, i) = va_arg (p, tree);
5521 : :
5522 : 2614969 : va_end (p);
5523 : 2614969 : return t;
5524 : : }
5525 : :
5526 : : /* Similar to build_nt, but for creating a CALL_EXPR object with a
5527 : : tree vec. */
5528 : :
5529 : : tree
5530 : 0 : build_nt_call_vec (tree fn, vec<tree, va_gc> *args)
5531 : : {
5532 : 0 : tree ret, t;
5533 : 0 : unsigned int ix;
5534 : :
5535 : 0 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
5536 : 0 : CALL_EXPR_FN (ret) = fn;
5537 : 0 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
5538 : 0 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
5539 : 0 : CALL_EXPR_ARG (ret, ix) = t;
5540 : 0 : return ret;
5541 : : }
5542 : :
5543 : : /* Create a DECL_... node of code CODE, name NAME (if non-null)
5544 : : and data type TYPE.
5545 : : We do NOT enter this node in any sort of symbol table.
5546 : :
5547 : : LOC is the location of the decl.
5548 : :
5549 : : layout_decl is used to set up the decl's storage layout.
5550 : : Other slots are initialized to 0 or null pointers. */
5551 : :
5552 : : tree
5553 : 2971230317 : build_decl (location_t loc, enum tree_code code, tree name,
5554 : : tree type MEM_STAT_DECL)
5555 : : {
5556 : 2971230317 : tree t;
5557 : :
5558 : 2971230317 : t = make_node (code PASS_MEM_STAT);
5559 : 2971230317 : DECL_SOURCE_LOCATION (t) = loc;
5560 : :
5561 : : /* if (type == error_mark_node)
5562 : : type = integer_type_node; */
5563 : : /* That is not done, deliberately, so that having error_mark_node
5564 : : as the type can suppress useless errors in the use of this variable. */
5565 : :
5566 : 2971230317 : DECL_NAME (t) = name;
5567 : 2971230317 : TREE_TYPE (t) = type;
5568 : :
5569 : 2971230317 : if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
5570 : 1051075941 : layout_decl (t, 0);
5571 : :
5572 : 2971230317 : return t;
5573 : : }
5574 : :
5575 : : /* Create and return a DEBUG_EXPR_DECL node of the given TYPE. */
5576 : :
5577 : : tree
5578 : 1658402 : build_debug_expr_decl (tree type)
5579 : : {
5580 : 1658402 : tree vexpr = make_node (DEBUG_EXPR_DECL);
5581 : 1658402 : DECL_ARTIFICIAL (vexpr) = 1;
5582 : 1658402 : TREE_TYPE (vexpr) = type;
5583 : 1658402 : SET_DECL_MODE (vexpr, TYPE_MODE (type));
5584 : 1658402 : return vexpr;
5585 : : }
5586 : :
5587 : : /* Builds and returns function declaration with NAME and TYPE. */
5588 : :
5589 : : tree
5590 : 19869 : build_fn_decl (const char *name, tree type)
5591 : : {
5592 : 19869 : tree id = get_identifier (name);
5593 : 19869 : tree decl = build_decl (input_location, FUNCTION_DECL, id, type);
5594 : :
5595 : 19869 : DECL_EXTERNAL (decl) = 1;
5596 : 19869 : TREE_PUBLIC (decl) = 1;
5597 : 19869 : DECL_ARTIFICIAL (decl) = 1;
5598 : 19869 : TREE_NOTHROW (decl) = 1;
5599 : :
5600 : 19869 : return decl;
5601 : : }
5602 : :
5603 : : vec<tree, va_gc> *all_translation_units;
5604 : :
5605 : : /* Builds a new translation-unit decl with name NAME, queues it in the
5606 : : global list of translation-unit decls and returns it. */
5607 : :
5608 : : tree
5609 : 252058 : build_translation_unit_decl (tree name)
5610 : : {
5611 : 252058 : tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL,
5612 : 252058 : name, NULL_TREE);
5613 : 252058 : TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
5614 : 252058 : vec_safe_push (all_translation_units, tu);
5615 : 252058 : return tu;
5616 : : }
5617 : :
5618 : :
5619 : : /* BLOCK nodes are used to represent the structure of binding contours
5620 : : and declarations, once those contours have been exited and their contents
5621 : : compiled. This information is used for outputting debugging info. */
5622 : :
5623 : : tree
5624 : 702077 : build_block (tree vars, tree subblocks, tree supercontext, tree chain)
5625 : : {
5626 : 702077 : tree block = make_node (BLOCK);
5627 : :
5628 : 702077 : BLOCK_VARS (block) = vars;
5629 : 702077 : BLOCK_SUBBLOCKS (block) = subblocks;
5630 : 702077 : BLOCK_SUPERCONTEXT (block) = supercontext;
5631 : 702077 : BLOCK_CHAIN (block) = chain;
5632 : 702077 : return block;
5633 : : }
5634 : :
5635 : :
5636 : : /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
5637 : :
5638 : : LOC is the location to use in tree T. */
5639 : :
5640 : : void
5641 : 12576883092 : protected_set_expr_location (tree t, location_t loc)
5642 : : {
5643 : 12576883092 : if (CAN_HAVE_LOCATION_P (t))
5644 : 2008933742 : SET_EXPR_LOCATION (t, loc);
5645 : 10498613360 : else if (t && TREE_CODE (t) == STATEMENT_LIST)
5646 : : {
5647 : 22243 : t = expr_single (t);
5648 : 22243 : if (t && CAN_HAVE_LOCATION_P (t))
5649 : 18 : SET_EXPR_LOCATION (t, loc);
5650 : : }
5651 : 12576883092 : }
5652 : :
5653 : : /* Like PROTECTED_SET_EXPR_LOCATION, but only do that if T has
5654 : : UNKNOWN_LOCATION. */
5655 : :
5656 : : void
5657 : 22132453 : protected_set_expr_location_if_unset (tree t, location_t loc)
5658 : : {
5659 : 22132453 : t = expr_single (t);
5660 : 22132453 : if (t && !EXPR_HAS_LOCATION (t))
5661 : 16580935 : protected_set_expr_location (t, loc);
5662 : 22132453 : }
5663 : :
5664 : : /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5665 : : of the various TYPE_QUAL values. */
5666 : :
5667 : : static void
5668 : 93836597 : set_type_quals (tree type, int type_quals)
5669 : : {
5670 : 93836597 : TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
5671 : 93836597 : TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
5672 : 93836597 : TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
5673 : 93836597 : TYPE_ATOMIC (type) = (type_quals & TYPE_QUAL_ATOMIC) != 0;
5674 : 93836597 : TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals);
5675 : 93836597 : }
5676 : :
5677 : : /* Returns true iff CAND and BASE have equivalent language-specific
5678 : : qualifiers. */
5679 : :
5680 : : bool
5681 : 2532983003 : check_lang_type (const_tree cand, const_tree base)
5682 : : {
5683 : 2532983003 : if (lang_hooks.types.type_hash_eq == NULL)
5684 : : return true;
5685 : : /* type_hash_eq currently only applies to these types. */
5686 : 2477186499 : if (TREE_CODE (cand) != FUNCTION_TYPE
5687 : 2477186499 : && TREE_CODE (cand) != METHOD_TYPE)
5688 : : return true;
5689 : 1123694 : return lang_hooks.types.type_hash_eq (cand, base);
5690 : : }
5691 : :
5692 : : /* This function checks to see if TYPE matches the size one of the built-in
5693 : : atomic types, and returns that core atomic type. */
5694 : :
5695 : : static tree
5696 : 8316 : find_atomic_core_type (const_tree type)
5697 : : {
5698 : 8316 : tree base_atomic_type;
5699 : :
5700 : : /* Only handle complete types. */
5701 : 8316 : if (!tree_fits_uhwi_p (TYPE_SIZE (type)))
5702 : : return NULL_TREE;
5703 : :
5704 : 8304 : switch (tree_to_uhwi (TYPE_SIZE (type)))
5705 : : {
5706 : 2451 : case 8:
5707 : 2451 : base_atomic_type = atomicQI_type_node;
5708 : 2451 : break;
5709 : :
5710 : 788 : case 16:
5711 : 788 : base_atomic_type = atomicHI_type_node;
5712 : 788 : break;
5713 : :
5714 : 1006 : case 32:
5715 : 1006 : base_atomic_type = atomicSI_type_node;
5716 : 1006 : break;
5717 : :
5718 : 2630 : case 64:
5719 : 2630 : base_atomic_type = atomicDI_type_node;
5720 : 2630 : break;
5721 : :
5722 : 1309 : case 128:
5723 : 1309 : base_atomic_type = atomicTI_type_node;
5724 : 1309 : break;
5725 : :
5726 : : default:
5727 : : base_atomic_type = NULL_TREE;
5728 : : }
5729 : :
5730 : : return base_atomic_type;
5731 : : }
5732 : :
5733 : : /* Returns true iff unqualified CAND and BASE are equivalent. */
5734 : :
5735 : : bool
5736 : 4023652861 : check_base_type (const_tree cand, const_tree base)
5737 : : {
5738 : 4023652861 : if (TYPE_NAME (cand) != TYPE_NAME (base)
5739 : : /* Apparently this is needed for Objective-C. */
5740 : 3650592518 : || TYPE_CONTEXT (cand) != TYPE_CONTEXT (base)
5741 : 7674245379 : || !attribute_list_equal (TYPE_ATTRIBUTES (cand),
5742 : 3650592518 : TYPE_ATTRIBUTES (base)))
5743 : 373060343 : return false;
5744 : : /* Check alignment. */
5745 : 3650592518 : if (TYPE_ALIGN (cand) == TYPE_ALIGN (base)
5746 : 3650592518 : && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base))
5747 : : return true;
5748 : : /* Atomic types increase minimal alignment. We must to do so as well
5749 : : or we get duplicated canonical types. See PR88686. */
5750 : 10876 : if ((TYPE_QUALS (cand) & TYPE_QUAL_ATOMIC))
5751 : : {
5752 : : /* See if this object can map to a basic atomic type. */
5753 : 1775 : tree atomic_type = find_atomic_core_type (cand);
5754 : 1775 : if (atomic_type && TYPE_ALIGN (atomic_type) == TYPE_ALIGN (cand))
5755 : : return true;
5756 : : }
5757 : : return false;
5758 : : }
5759 : :
5760 : : /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
5761 : :
5762 : : bool
5763 : 4266665735 : check_qualified_type (const_tree cand, const_tree base, int type_quals)
5764 : : {
5765 : 4266665735 : return (TYPE_QUALS (cand) == type_quals
5766 : 2904138830 : && check_base_type (cand, base)
5767 : 6797960584 : && check_lang_type (cand, base));
5768 : : }
5769 : :
5770 : : /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5771 : :
5772 : : static bool
5773 : 3392819 : check_aligned_type (const_tree cand, const_tree base, unsigned int align)
5774 : : {
5775 : 3392819 : return (TYPE_QUALS (cand) == TYPE_QUALS (base)
5776 : 2810269 : && TYPE_NAME (cand) == TYPE_NAME (base)
5777 : : /* Apparently this is needed for Objective-C. */
5778 : 2004999 : && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
5779 : : /* Check alignment. */
5780 : 2004999 : && TYPE_ALIGN (cand) == align
5781 : : /* Check this is a user-aligned type as build_aligned_type
5782 : : would create. */
5783 : 937199 : && TYPE_USER_ALIGN (cand)
5784 : 934245 : && attribute_list_equal (TYPE_ATTRIBUTES (cand),
5785 : 934245 : TYPE_ATTRIBUTES (base))
5786 : 4327064 : && check_lang_type (cand, base));
5787 : : }
5788 : :
5789 : : /* Return a version of the TYPE, qualified as indicated by the
5790 : : TYPE_QUALS, if one exists. If no qualified version exists yet,
5791 : : return NULL_TREE. */
5792 : :
5793 : : tree
5794 : 3913757103 : get_qualified_type (tree type, int type_quals)
5795 : : {
5796 : 3913757103 : if (TYPE_QUALS (type) == type_quals)
5797 : : return type;
5798 : :
5799 : 2625187453 : tree mv = TYPE_MAIN_VARIANT (type);
5800 : 2625187453 : if (check_qualified_type (mv, type, type_quals))
5801 : : return mv;
5802 : :
5803 : : /* Search the chain of variants to see if there is already one there just
5804 : : like the one we need to have. If so, use that existing one. We must
5805 : : preserve the TYPE_NAME, since there is code that depends on this. */
5806 : 1735386194 : for (tree *tp = &TYPE_NEXT_VARIANT (mv); *tp; tp = &TYPE_NEXT_VARIANT (*tp))
5807 : 1641415491 : if (check_qualified_type (*tp, type, type_quals))
5808 : : {
5809 : : /* Put the found variant at the head of the variant list so
5810 : : frequently searched variants get found faster. The C++ FE
5811 : : benefits greatly from this. */
5812 : 1075125955 : tree t = *tp;
5813 : 1075125955 : *tp = TYPE_NEXT_VARIANT (t);
5814 : 1075125955 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
5815 : 1075125955 : TYPE_NEXT_VARIANT (mv) = t;
5816 : 1075125955 : return t;
5817 : : }
5818 : :
5819 : : return NULL_TREE;
5820 : : }
5821 : :
5822 : : /* Like get_qualified_type, but creates the type if it does not
5823 : : exist. This function never returns NULL_TREE. */
5824 : :
5825 : : tree
5826 : 3502842964 : build_qualified_type (tree type, int type_quals MEM_STAT_DECL)
5827 : : {
5828 : 3502842964 : tree t;
5829 : :
5830 : : /* See if we already have the appropriate qualified variant. */
5831 : 3502842964 : t = get_qualified_type (type, type_quals);
5832 : :
5833 : : /* If not, build it. */
5834 : 3502842964 : if (!t)
5835 : : {
5836 : 92388047 : t = build_variant_type_copy (type PASS_MEM_STAT);
5837 : 92388047 : set_type_quals (t, type_quals);
5838 : :
5839 : 92388047 : if (((type_quals & TYPE_QUAL_ATOMIC) == TYPE_QUAL_ATOMIC))
5840 : : {
5841 : : /* See if this object can map to a basic atomic type. */
5842 : 6541 : tree atomic_type = find_atomic_core_type (type);
5843 : 6541 : if (atomic_type)
5844 : : {
5845 : : /* Ensure the alignment of this type is compatible with
5846 : : the required alignment of the atomic type. */
5847 : 6409 : if (TYPE_ALIGN (atomic_type) > TYPE_ALIGN (t))
5848 : 94 : SET_TYPE_ALIGN (t, TYPE_ALIGN (atomic_type));
5849 : : }
5850 : : }
5851 : :
5852 : 92388047 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5853 : : /* Propagate structural equality. */
5854 : 4514613 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5855 : 87873434 : else if (TYPE_CANONICAL (type) != type)
5856 : : /* Build the underlying canonical type, since it is different
5857 : : from TYPE. */
5858 : : {
5859 : 28831887 : tree c = build_qualified_type (TYPE_CANONICAL (type), type_quals);
5860 : 28831887 : TYPE_CANONICAL (t) = TYPE_CANONICAL (c);
5861 : : }
5862 : : else
5863 : : /* T is its own canonical type. */
5864 : 59041547 : TYPE_CANONICAL (t) = t;
5865 : :
5866 : : }
5867 : :
5868 : 3502842964 : return t;
5869 : : }
5870 : :
5871 : : /* Create a variant of type T with alignment ALIGN which
5872 : : is measured in bits. */
5873 : :
5874 : : tree
5875 : 1217322 : build_aligned_type (tree type, unsigned int align)
5876 : : {
5877 : 1217322 : tree t;
5878 : :
5879 : 1217322 : if (TYPE_PACKED (type)
5880 : 1217322 : || TYPE_ALIGN (type) == align)
5881 : : return type;
5882 : :
5883 : 3496141 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
5884 : 3392819 : if (check_aligned_type (t, type, align))
5885 : : return t;
5886 : :
5887 : 103322 : t = build_variant_type_copy (type);
5888 : 103322 : SET_TYPE_ALIGN (t, align);
5889 : 103322 : TYPE_USER_ALIGN (t) = 1;
5890 : :
5891 : 103322 : return t;
5892 : : }
5893 : :
5894 : : /* Create a new distinct copy of TYPE. The new type is made its own
5895 : : MAIN_VARIANT. If TYPE requires structural equality checks, the
5896 : : resulting type requires structural equality checks; otherwise, its
5897 : : TYPE_CANONICAL points to itself. */
5898 : :
5899 : : tree
5900 : 709726987 : build_distinct_type_copy (tree type MEM_STAT_DECL)
5901 : : {
5902 : 709726987 : tree t = copy_node (type PASS_MEM_STAT);
5903 : :
5904 : 709726987 : TYPE_POINTER_TO (t) = 0;
5905 : 709726987 : TYPE_REFERENCE_TO (t) = 0;
5906 : :
5907 : : /* Set the canonical type either to a new equivalence class, or
5908 : : propagate the need for structural equality checks. */
5909 : 709726987 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5910 : 59550690 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5911 : : else
5912 : 650176297 : TYPE_CANONICAL (t) = t;
5913 : :
5914 : : /* Make it its own variant. */
5915 : 709726987 : TYPE_MAIN_VARIANT (t) = t;
5916 : 709726987 : TYPE_NEXT_VARIANT (t) = 0;
5917 : :
5918 : : /* Note that it is now possible for TYPE_MIN_VALUE to be a value
5919 : : whose TREE_TYPE is not t. This can also happen in the Ada
5920 : : frontend when using subtypes. */
5921 : :
5922 : 709726987 : return t;
5923 : : }
5924 : :
5925 : : /* Create a new variant of TYPE, equivalent but distinct. This is so
5926 : : the caller can modify it. TYPE_CANONICAL for the return type will
5927 : : be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
5928 : : are considered equal by the language itself (or that both types
5929 : : require structural equality checks). */
5930 : :
5931 : : tree
5932 : 430826430 : build_variant_type_copy (tree type MEM_STAT_DECL)
5933 : : {
5934 : 430826430 : tree t, m = TYPE_MAIN_VARIANT (type);
5935 : :
5936 : 430826430 : t = build_distinct_type_copy (type PASS_MEM_STAT);
5937 : :
5938 : : /* Since we're building a variant, assume that it is a non-semantic
5939 : : variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
5940 : 430826430 : TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
5941 : : /* Type variants have no alias set defined. */
5942 : 430826430 : TYPE_ALIAS_SET (t) = -1;
5943 : :
5944 : : /* Add the new type to the chain of variants of TYPE. */
5945 : 430826430 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
5946 : 430826430 : TYPE_NEXT_VARIANT (m) = t;
5947 : 430826430 : TYPE_MAIN_VARIANT (t) = m;
5948 : :
5949 : 430826430 : return t;
5950 : : }
5951 : :
5952 : : /* Return true if the from tree in both tree maps are equal. */
5953 : :
5954 : : int
5955 : 1919989031 : tree_map_base_eq (const void *va, const void *vb)
5956 : : {
5957 : 1919989031 : const struct tree_map_base *const a = (const struct tree_map_base *) va,
5958 : 1919989031 : *const b = (const struct tree_map_base *) vb;
5959 : 1919989031 : return (a->from == b->from);
5960 : : }
5961 : :
5962 : : /* Hash a from tree in a tree_base_map. */
5963 : :
5964 : : unsigned int
5965 : 0 : tree_map_base_hash (const void *item)
5966 : : {
5967 : 0 : return htab_hash_pointer (((const struct tree_map_base *)item)->from);
5968 : : }
5969 : :
5970 : : /* Return true if this tree map structure is marked for garbage collection
5971 : : purposes. We simply return true if the from tree is marked, so that this
5972 : : structure goes away when the from tree goes away. */
5973 : :
5974 : : bool
5975 : 0 : tree_map_base_marked_p (const void *p)
5976 : : {
5977 : 0 : return ggc_marked_p (((const struct tree_map_base *) p)->from);
5978 : : }
5979 : :
5980 : : /* Hash a from tree in a tree_map. */
5981 : :
5982 : : unsigned int
5983 : 290 : tree_map_hash (const void *item)
5984 : : {
5985 : 290 : return (((const struct tree_map *) item)->hash);
5986 : : }
5987 : :
5988 : : /* Hash a from tree in a tree_decl_map. */
5989 : :
5990 : : unsigned int
5991 : 1315174325 : tree_decl_map_hash (const void *item)
5992 : : {
5993 : 1315174325 : return DECL_UID (((const struct tree_decl_map *) item)->base.from);
5994 : : }
5995 : :
5996 : : /* Return the initialization priority for DECL. */
5997 : :
5998 : : priority_type
5999 : 23189 : decl_init_priority_lookup (tree decl)
6000 : : {
6001 : 23189 : symtab_node *snode = symtab_node::get (decl);
6002 : :
6003 : 23189 : if (!snode)
6004 : : return DEFAULT_INIT_PRIORITY;
6005 : 23189 : return
6006 : 23189 : snode->get_init_priority ();
6007 : : }
6008 : :
6009 : : /* Return the finalization priority for DECL. */
6010 : :
6011 : : priority_type
6012 : 1811 : decl_fini_priority_lookup (tree decl)
6013 : : {
6014 : 1811 : cgraph_node *node = cgraph_node::get (decl);
6015 : :
6016 : 1811 : if (!node)
6017 : : return DEFAULT_INIT_PRIORITY;
6018 : 1811 : return
6019 : 1811 : node->get_fini_priority ();
6020 : : }
6021 : :
6022 : : /* Set the initialization priority for DECL to PRIORITY. */
6023 : :
6024 : : void
6025 : 24675 : decl_init_priority_insert (tree decl, priority_type priority)
6026 : : {
6027 : 24675 : struct symtab_node *snode;
6028 : :
6029 : 24675 : if (priority == DEFAULT_INIT_PRIORITY)
6030 : : {
6031 : 21058 : snode = symtab_node::get (decl);
6032 : 21058 : if (!snode)
6033 : : return;
6034 : : }
6035 : 3617 : else if (VAR_P (decl))
6036 : 45 : snode = varpool_node::get_create (decl);
6037 : : else
6038 : 3572 : snode = cgraph_node::get_create (decl);
6039 : 23957 : snode->set_init_priority (priority);
6040 : : }
6041 : :
6042 : : /* Set the finalization priority for DECL to PRIORITY. */
6043 : :
6044 : : void
6045 : 1670 : decl_fini_priority_insert (tree decl, priority_type priority)
6046 : : {
6047 : 1670 : struct cgraph_node *node;
6048 : :
6049 : 1670 : if (priority == DEFAULT_INIT_PRIORITY)
6050 : : {
6051 : 104 : node = cgraph_node::get (decl);
6052 : 104 : if (!node)
6053 : : return;
6054 : : }
6055 : : else
6056 : 1566 : node = cgraph_node::get_create (decl);
6057 : 1575 : node->set_fini_priority (priority);
6058 : : }
6059 : :
6060 : : /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
6061 : :
6062 : : static void
6063 : 0 : print_debug_expr_statistics (void)
6064 : : {
6065 : 0 : fprintf (stderr, "DECL_DEBUG_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6066 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6067 : 0 : (fmt_size_t) debug_expr_for_decl->size (),
6068 : 0 : (fmt_size_t) debug_expr_for_decl->elements (),
6069 : : debug_expr_for_decl->collisions ());
6070 : 0 : }
6071 : :
6072 : : /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6073 : :
6074 : : static void
6075 : 0 : print_value_expr_statistics (void)
6076 : : {
6077 : 0 : fprintf (stderr, "DECL_VALUE_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6078 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6079 : 0 : (fmt_size_t) value_expr_for_decl->size (),
6080 : 0 : (fmt_size_t) value_expr_for_decl->elements (),
6081 : : value_expr_for_decl->collisions ());
6082 : 0 : }
6083 : :
6084 : : /* Lookup a debug expression for FROM, and return it if we find one. */
6085 : :
6086 : : tree
6087 : 461024296 : decl_debug_expr_lookup (tree from)
6088 : : {
6089 : 461024296 : struct tree_decl_map *h, in;
6090 : 461024296 : in.base.from = from;
6091 : :
6092 : 461024296 : h = debug_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6093 : 461024296 : if (h)
6094 : 461024296 : return h->to;
6095 : : return NULL_TREE;
6096 : : }
6097 : :
6098 : : /* Insert a mapping FROM->TO in the debug expression hashtable. */
6099 : :
6100 : : void
6101 : 1382740 : decl_debug_expr_insert (tree from, tree to)
6102 : : {
6103 : 1382740 : struct tree_decl_map *h;
6104 : :
6105 : 1382740 : h = ggc_alloc<tree_decl_map> ();
6106 : 1382740 : h->base.from = from;
6107 : 1382740 : h->to = to;
6108 : 1382740 : *debug_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6109 : 1382740 : }
6110 : :
6111 : : /* Lookup a value expression for FROM, and return it if we find one. */
6112 : :
6113 : : tree
6114 : 13118736 : decl_value_expr_lookup (tree from)
6115 : : {
6116 : 13118736 : struct tree_decl_map *h, in;
6117 : 13118736 : in.base.from = from;
6118 : :
6119 : 13118736 : h = value_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6120 : 13118736 : if (h)
6121 : 13118736 : return h->to;
6122 : : return NULL_TREE;
6123 : : }
6124 : :
6125 : : /* Insert a mapping FROM->TO in the value expression hashtable. */
6126 : :
6127 : : void
6128 : 5700776 : decl_value_expr_insert (tree from, tree to)
6129 : : {
6130 : 5700776 : struct tree_decl_map *h;
6131 : :
6132 : : /* Uses of FROM shouldn't look like they happen at the location of TO. */
6133 : 5700776 : to = protected_set_expr_location_unshare (to, UNKNOWN_LOCATION);
6134 : :
6135 : 5700776 : h = ggc_alloc<tree_decl_map> ();
6136 : 5700776 : h->base.from = from;
6137 : 5700776 : h->to = to;
6138 : 5700776 : *value_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6139 : 5700776 : }
6140 : :
6141 : : /* Lookup a vector of debug arguments for FROM, and return it if we
6142 : : find one. */
6143 : :
6144 : : vec<tree, va_gc> **
6145 : 829804 : decl_debug_args_lookup (tree from)
6146 : : {
6147 : 829804 : struct tree_vec_map *h, in;
6148 : :
6149 : 829804 : if (!DECL_HAS_DEBUG_ARGS_P (from))
6150 : : return NULL;
6151 : 695762 : gcc_checking_assert (debug_args_for_decl != NULL);
6152 : 695762 : in.base.from = from;
6153 : 695762 : h = debug_args_for_decl->find_with_hash (&in, DECL_UID (from));
6154 : 695762 : if (h)
6155 : 692539 : return &h->to;
6156 : : return NULL;
6157 : : }
6158 : :
6159 : : /* Insert a mapping FROM->empty vector of debug arguments in the value
6160 : : expression hashtable. */
6161 : :
6162 : : vec<tree, va_gc> **
6163 : 254255 : decl_debug_args_insert (tree from)
6164 : : {
6165 : 254255 : struct tree_vec_map *h;
6166 : 254255 : tree_vec_map **loc;
6167 : :
6168 : 254255 : if (DECL_HAS_DEBUG_ARGS_P (from))
6169 : 170224 : return decl_debug_args_lookup (from);
6170 : 84031 : if (debug_args_for_decl == NULL)
6171 : 8501 : debug_args_for_decl = hash_table<tree_vec_map_cache_hasher>::create_ggc (64);
6172 : 84031 : h = ggc_alloc<tree_vec_map> ();
6173 : 84031 : h->base.from = from;
6174 : 84031 : h->to = NULL;
6175 : 84031 : loc = debug_args_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT);
6176 : 84031 : *loc = h;
6177 : 84031 : DECL_HAS_DEBUG_ARGS_P (from) = 1;
6178 : 84031 : return &h->to;
6179 : : }
6180 : :
6181 : : /* Hashing of types so that we don't make duplicates.
6182 : : The entry point is `type_hash_canon'. */
6183 : :
6184 : : /* Generate the default hash code for TYPE. This is designed for
6185 : : speed, rather than maximum entropy. */
6186 : :
6187 : : hashval_t
6188 : 1338058259 : type_hash_canon_hash (tree type)
6189 : : {
6190 : 1338058259 : inchash::hash hstate;
6191 : :
6192 : 1338058259 : hstate.add_int (TREE_CODE (type));
6193 : :
6194 : 1338058259 : hstate.add_flag (TYPE_STRUCTURAL_EQUALITY_P (type));
6195 : :
6196 : 1338058259 : if (TREE_TYPE (type))
6197 : 1337977561 : hstate.add_object (TYPE_HASH (TREE_TYPE (type)));
6198 : :
6199 : 1617531933 : for (tree t = TYPE_ATTRIBUTES (type); t; t = TREE_CHAIN (t))
6200 : : /* Just the identifier is adequate to distinguish. */
6201 : 279473674 : hstate.add_object (IDENTIFIER_HASH_VALUE (get_attribute_name (t)));
6202 : :
6203 : 1338058259 : switch (TREE_CODE (type))
6204 : : {
6205 : 295462255 : case METHOD_TYPE:
6206 : 295462255 : hstate.add_object (TYPE_HASH (TYPE_METHOD_BASETYPE (type)));
6207 : : /* FALLTHROUGH. */
6208 : 1158030047 : case FUNCTION_TYPE:
6209 : 4590250544 : for (tree t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
6210 : 3432220497 : if (TREE_VALUE (t) != error_mark_node)
6211 : 3432209450 : hstate.add_object (TYPE_HASH (TREE_VALUE (t)));
6212 : : break;
6213 : :
6214 : 968534 : case OFFSET_TYPE:
6215 : 968534 : hstate.add_object (TYPE_HASH (TYPE_OFFSET_BASETYPE (type)));
6216 : 968534 : break;
6217 : :
6218 : 64012413 : case ARRAY_TYPE:
6219 : 64012413 : {
6220 : 64012413 : if (TYPE_DOMAIN (type))
6221 : 62297637 : hstate.add_object (TYPE_HASH (TYPE_DOMAIN (type)));
6222 : 64012413 : if (!AGGREGATE_TYPE_P (TREE_TYPE (type)))
6223 : : {
6224 : 62610846 : unsigned typeless = TYPE_TYPELESS_STORAGE (type);
6225 : 62610846 : hstate.add_object (typeless);
6226 : : }
6227 : : }
6228 : : break;
6229 : :
6230 : 38840272 : case INTEGER_TYPE:
6231 : 38840272 : {
6232 : 38840272 : tree t = TYPE_MAX_VALUE (type);
6233 : 38840272 : if (!t)
6234 : 543869 : t = TYPE_MIN_VALUE (type);
6235 : 77680545 : for (int i = 0; i < TREE_INT_CST_NUNITS (t); i++)
6236 : 38840273 : hstate.add_object (TREE_INT_CST_ELT (t, i));
6237 : : break;
6238 : : }
6239 : :
6240 : 58595 : case BITINT_TYPE:
6241 : 58595 : {
6242 : 58595 : unsigned prec = TYPE_PRECISION (type);
6243 : 58595 : unsigned uns = TYPE_UNSIGNED (type);
6244 : 58595 : hstate.add_object (prec);
6245 : 58595 : hstate.add_int (uns);
6246 : 58595 : break;
6247 : : }
6248 : :
6249 : 11956 : case REAL_TYPE:
6250 : 11956 : case FIXED_POINT_TYPE:
6251 : 11956 : {
6252 : 11956 : unsigned prec = TYPE_PRECISION (type);
6253 : 11956 : hstate.add_object (prec);
6254 : 11956 : break;
6255 : : }
6256 : :
6257 : 70581125 : case VECTOR_TYPE:
6258 : 70581125 : hstate.add_poly_int (TYPE_VECTOR_SUBPARTS (type));
6259 : 70581125 : break;
6260 : :
6261 : : case REFERENCE_TYPE:
6262 : 1338058259 : hstate.add_flag (TYPE_REF_IS_RVALUE (type));
6263 : : break;
6264 : :
6265 : : default:
6266 : : break;
6267 : : }
6268 : :
6269 : 1338058259 : return hstate.end ();
6270 : : }
6271 : :
6272 : : /* These are the Hashtable callback functions. */
6273 : :
6274 : : /* Returns true iff the types are equivalent. */
6275 : :
6276 : : bool
6277 : 8520735000 : type_cache_hasher::equal (type_hash *a, type_hash *b)
6278 : : {
6279 : : /* First test the things that are the same for all types. */
6280 : 8520735000 : if (a->hash != b->hash
6281 : 667607116 : || TREE_CODE (a->type) != TREE_CODE (b->type)
6282 : 667600041 : || TREE_TYPE (a->type) != TREE_TYPE (b->type)
6283 : 667598363 : || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
6284 : 667598363 : TYPE_ATTRIBUTES (b->type))
6285 : 9181281486 : || (TREE_CODE (a->type) != COMPLEX_TYPE
6286 : 658419761 : && TYPE_NAME (a->type) != TYPE_NAME (b->type)))
6287 : 7861028344 : return false;
6288 : :
6289 : : /* Be careful about comparing arrays before and after the element type
6290 : : has been completed; don't compare TYPE_ALIGN unless both types are
6291 : : complete. */
6292 : 1317457722 : if (COMPLETE_TYPE_P (a->type) && COMPLETE_TYPE_P (b->type)
6293 : 1317457722 : && (TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
6294 : 657750518 : || TYPE_MODE (a->type) != TYPE_MODE (b->type)))
6295 : 548 : return false;
6296 : :
6297 : 659706108 : if (TYPE_STRUCTURAL_EQUALITY_P (a->type)
6298 : 659706108 : != TYPE_STRUCTURAL_EQUALITY_P (b->type))
6299 : : return false;
6300 : :
6301 : 659702482 : switch (TREE_CODE (a->type))
6302 : : {
6303 : : case VOID_TYPE:
6304 : : case OPAQUE_TYPE:
6305 : : case COMPLEX_TYPE:
6306 : : case POINTER_TYPE:
6307 : : case NULLPTR_TYPE:
6308 : : return true;
6309 : :
6310 : 64214349 : case VECTOR_TYPE:
6311 : 64214349 : return known_eq (TYPE_VECTOR_SUBPARTS (a->type),
6312 : : TYPE_VECTOR_SUBPARTS (b->type));
6313 : :
6314 : 0 : case ENUMERAL_TYPE:
6315 : 0 : if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
6316 : 0 : && !(TYPE_VALUES (a->type)
6317 : 0 : && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
6318 : 0 : && TYPE_VALUES (b->type)
6319 : 0 : && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
6320 : 0 : && type_list_equal (TYPE_VALUES (a->type),
6321 : 0 : TYPE_VALUES (b->type))))
6322 : 0 : return false;
6323 : :
6324 : : /* fall through */
6325 : :
6326 : 36179882 : case INTEGER_TYPE:
6327 : 36179882 : case REAL_TYPE:
6328 : 36179882 : case BOOLEAN_TYPE:
6329 : 36179882 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6330 : : return false;
6331 : 36172799 : return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
6332 : 804655 : || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
6333 : 804655 : TYPE_MAX_VALUE (b->type)))
6334 : 36577889 : && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
6335 : 561879 : || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
6336 : 561879 : TYPE_MIN_VALUE (b->type))));
6337 : :
6338 : 53101 : case BITINT_TYPE:
6339 : 53101 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6340 : : return false;
6341 : 53101 : return TYPE_UNSIGNED (a->type) == TYPE_UNSIGNED (b->type);
6342 : :
6343 : 0 : case FIXED_POINT_TYPE:
6344 : 0 : return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
6345 : :
6346 : 763103 : case OFFSET_TYPE:
6347 : 763103 : return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
6348 : :
6349 : 84726585 : case METHOD_TYPE:
6350 : 84726585 : if (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
6351 : 84726585 : && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6352 : 84663000 : || (TYPE_ARG_TYPES (a->type)
6353 : 84663000 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6354 : 84663000 : && TYPE_ARG_TYPES (b->type)
6355 : 84663000 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6356 : 84663000 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6357 : 84663000 : TYPE_ARG_TYPES (b->type)))))
6358 : : break;
6359 : : return false;
6360 : 53737712 : case ARRAY_TYPE:
6361 : : /* Don't compare TYPE_TYPELESS_STORAGE flag on aggregates,
6362 : : where the flag should be inherited from the element type
6363 : : and can change after ARRAY_TYPEs are created; on non-aggregates
6364 : : compare it and hash it, scalars will never have that flag set
6365 : : and we need to differentiate between arrays created by different
6366 : : front-ends or middle-end created arrays. */
6367 : 53737712 : return (TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type)
6368 : 53737712 : && (AGGREGATE_TYPE_P (TREE_TYPE (a->type))
6369 : 52959760 : || (TYPE_TYPELESS_STORAGE (a->type)
6370 : 52959760 : == TYPE_TYPELESS_STORAGE (b->type))));
6371 : :
6372 : 0 : case RECORD_TYPE:
6373 : 0 : case UNION_TYPE:
6374 : 0 : case QUAL_UNION_TYPE:
6375 : 0 : return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
6376 : 0 : || (TYPE_FIELDS (a->type)
6377 : 0 : && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
6378 : 0 : && TYPE_FIELDS (b->type)
6379 : 0 : && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
6380 : 0 : && type_list_equal (TYPE_FIELDS (a->type),
6381 : 0 : TYPE_FIELDS (b->type))));
6382 : :
6383 : 417900539 : case FUNCTION_TYPE:
6384 : 417900539 : if ((TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6385 : 262997933 : && (TYPE_NO_NAMED_ARGS_STDARG_P (a->type)
6386 : 262997933 : == TYPE_NO_NAMED_ARGS_STDARG_P (b->type)))
6387 : 418214504 : || (TYPE_ARG_TYPES (a->type)
6388 : 154902606 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6389 : 154902606 : && TYPE_ARG_TYPES (b->type)
6390 : 154902591 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6391 : 154902591 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6392 : 154902591 : TYPE_ARG_TYPES (b->type))))
6393 : : break;
6394 : : return false;
6395 : :
6396 : 9 : case REFERENCE_TYPE:
6397 : 9 : return TYPE_REF_IS_RVALUE (a->type) == TYPE_REF_IS_RVALUE (b->type);
6398 : :
6399 : : default:
6400 : : return false;
6401 : : }
6402 : :
6403 : 477258026 : if (lang_hooks.types.type_hash_eq != NULL)
6404 : 294438652 : return lang_hooks.types.type_hash_eq (a->type, b->type);
6405 : :
6406 : : return true;
6407 : : }
6408 : :
6409 : : /* Given TYPE, and HASHCODE its hash code, return the canonical
6410 : : object for an identical type if one already exists.
6411 : : Otherwise, return TYPE, and record it as the canonical object.
6412 : :
6413 : : To use this function, first create a type of the sort you want.
6414 : : Then compute its hash code from the fields of the type that
6415 : : make it different from other similar types.
6416 : : Then call this function and use the value. */
6417 : :
6418 : : tree
6419 : 1339170335 : type_hash_canon (unsigned int hashcode, tree type)
6420 : : {
6421 : 1339170335 : type_hash in;
6422 : 1339170335 : type_hash **loc;
6423 : :
6424 : : /* The hash table only contains main variants, so ensure that's what we're
6425 : : being passed. */
6426 : 1339170335 : gcc_assert (TYPE_MAIN_VARIANT (type) == type);
6427 : :
6428 : : /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6429 : : must call that routine before comparing TYPE_ALIGNs. */
6430 : 1339170335 : layout_type (type);
6431 : :
6432 : 1339170335 : in.hash = hashcode;
6433 : 1339170335 : in.type = type;
6434 : :
6435 : 1339170335 : loc = type_hash_table->find_slot_with_hash (&in, hashcode, INSERT);
6436 : 1339170335 : if (*loc)
6437 : : {
6438 : 633763798 : tree t1 = ((type_hash *) *loc)->type;
6439 : 633763798 : gcc_assert (TYPE_MAIN_VARIANT (t1) == t1
6440 : : && t1 != type);
6441 : 633763798 : if (TYPE_UID (type) + 1 == next_type_uid)
6442 : 628580220 : --next_type_uid;
6443 : : /* Free also min/max values and the cache for integer
6444 : : types. This can't be done in free_node, as LTO frees
6445 : : those on its own. */
6446 : 633763798 : if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == BITINT_TYPE)
6447 : : {
6448 : 35663394 : if (TYPE_MIN_VALUE (type)
6449 : 35663394 : && TREE_TYPE (TYPE_MIN_VALUE (type)) == type)
6450 : : {
6451 : : /* Zero is always in TYPE_CACHED_VALUES. */
6452 : 451387 : if (! TYPE_UNSIGNED (type))
6453 : 215743 : int_cst_hash_table->remove_elt (TYPE_MIN_VALUE (type));
6454 : 451387 : ggc_free (TYPE_MIN_VALUE (type));
6455 : : }
6456 : 35663394 : if (TYPE_MAX_VALUE (type)
6457 : 35663394 : && TREE_TYPE (TYPE_MAX_VALUE (type)) == type)
6458 : : {
6459 : 451387 : int_cst_hash_table->remove_elt (TYPE_MAX_VALUE (type));
6460 : 451387 : ggc_free (TYPE_MAX_VALUE (type));
6461 : : }
6462 : 35663394 : if (TYPE_CACHED_VALUES_P (type))
6463 : 235644 : ggc_free (TYPE_CACHED_VALUES (type));
6464 : : }
6465 : 633763798 : free_node (type);
6466 : 633763798 : return t1;
6467 : : }
6468 : : else
6469 : : {
6470 : 705406537 : struct type_hash *h;
6471 : :
6472 : 705406537 : h = ggc_alloc<type_hash> ();
6473 : 705406537 : h->hash = hashcode;
6474 : 705406537 : h->type = type;
6475 : 705406537 : *loc = h;
6476 : :
6477 : 705406537 : return type;
6478 : : }
6479 : : }
6480 : :
6481 : : static void
6482 : 0 : print_type_hash_statistics (void)
6483 : : {
6484 : 0 : fprintf (stderr, "Type hash: size " HOST_SIZE_T_PRINT_DEC ", "
6485 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6486 : 0 : (fmt_size_t) type_hash_table->size (),
6487 : 0 : (fmt_size_t) type_hash_table->elements (),
6488 : : type_hash_table->collisions ());
6489 : 0 : }
6490 : :
6491 : : /* Given two lists of types
6492 : : (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6493 : : return 1 if the lists contain the same types in the same order.
6494 : : Also, the TREE_PURPOSEs must match. */
6495 : :
6496 : : bool
6497 : 239566115 : type_list_equal (const_tree l1, const_tree l2)
6498 : : {
6499 : 239566115 : const_tree t1, t2;
6500 : :
6501 : 904560128 : for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
6502 : 690049081 : if (TREE_VALUE (t1) != TREE_VALUE (t2)
6503 : 690049081 : || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
6504 : 25056444 : && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
6505 : 1408 : && (TREE_TYPE (TREE_PURPOSE (t1))
6506 : 1408 : == TREE_TYPE (TREE_PURPOSE (t2))))))
6507 : 25055068 : return false;
6508 : :
6509 : 214511047 : return t1 == t2;
6510 : : }
6511 : :
6512 : : /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6513 : : given by TYPE. If the argument list accepts variable arguments,
6514 : : then this function counts only the ordinary arguments. */
6515 : :
6516 : : int
6517 : 79819793 : type_num_arguments (const_tree fntype)
6518 : : {
6519 : 79819793 : int i = 0;
6520 : :
6521 : 310616581 : for (tree t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
6522 : : /* If the function does not take a variable number of arguments,
6523 : : the last element in the list will have type `void'. */
6524 : 291764802 : if (VOID_TYPE_P (TREE_VALUE (t)))
6525 : : break;
6526 : : else
6527 : 230796788 : ++i;
6528 : :
6529 : 79819793 : return i;
6530 : : }
6531 : :
6532 : : /* Return the type of the function TYPE's argument ARGNO if known.
6533 : : For vararg function's where ARGNO refers to one of the variadic
6534 : : arguments return null. Otherwise, return a void_type_node for
6535 : : out-of-bounds ARGNO. */
6536 : :
6537 : : tree
6538 : 79240219 : type_argument_type (const_tree fntype, unsigned argno)
6539 : : {
6540 : : /* Treat zero the same as an out-of-bounds argument number. */
6541 : 79240219 : if (!argno)
6542 : 0 : return void_type_node;
6543 : :
6544 : 79240219 : function_args_iterator iter;
6545 : :
6546 : 79240219 : tree argtype;
6547 : 79240219 : unsigned i = 1;
6548 : 170849260 : FOREACH_FUNCTION_ARGS (fntype, argtype, iter)
6549 : : {
6550 : : /* A vararg function's argument list ends in a null. Otherwise,
6551 : : an ordinary function's argument list ends with void. Return
6552 : : null if ARGNO refers to a vararg argument, void_type_node if
6553 : : it's out of bounds, and the formal argument type otherwise. */
6554 : 165194553 : if (!argtype)
6555 : : break;
6556 : :
6557 : 165194553 : if (i == argno || VOID_TYPE_P (argtype))
6558 : : return argtype;
6559 : :
6560 : 91609041 : ++i;
6561 : : }
6562 : :
6563 : : return NULL_TREE;
6564 : : }
6565 : :
6566 : : /* True if integer constants T1 and T2
6567 : : represent the same constant value. */
6568 : :
6569 : : bool
6570 : 1109622590 : tree_int_cst_equal (const_tree t1, const_tree t2)
6571 : : {
6572 : 1109622590 : if (t1 == t2)
6573 : : return true;
6574 : :
6575 : 509571436 : if (t1 == 0 || t2 == 0)
6576 : : return false;
6577 : :
6578 : 509170131 : STRIP_ANY_LOCATION_WRAPPER (t1);
6579 : 509170131 : STRIP_ANY_LOCATION_WRAPPER (t2);
6580 : :
6581 : 509170131 : if (TREE_CODE (t1) == INTEGER_CST
6582 : 505537443 : && TREE_CODE (t2) == INTEGER_CST
6583 : 1014707574 : && wi::to_widest (t1) == wi::to_widest (t2))
6584 : 18360495 : return true;
6585 : :
6586 : : return false;
6587 : : }
6588 : :
6589 : : /* Return true if T is an INTEGER_CST whose numerical value (extended
6590 : : according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. */
6591 : :
6592 : : bool
6593 : 2103424810 : tree_fits_shwi_p (const_tree t)
6594 : : {
6595 : 2103424810 : return (t != NULL_TREE
6596 : 2103424718 : && TREE_CODE (t) == INTEGER_CST
6597 : 4203443178 : && wi::fits_shwi_p (wi::to_widest (t)));
6598 : : }
6599 : :
6600 : : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6601 : : value (extended according to TYPE_UNSIGNED) fits in a poly_int64. */
6602 : :
6603 : : bool
6604 : 898315976 : tree_fits_poly_int64_p (const_tree t)
6605 : : {
6606 : 898315976 : if (t == NULL_TREE)
6607 : : return false;
6608 : 861268113 : if (POLY_INT_CST_P (t))
6609 : : {
6610 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6611 : : if (!wi::fits_shwi_p (wi::to_wide (POLY_INT_CST_COEFF (t, i))))
6612 : : return false;
6613 : : return true;
6614 : : }
6615 : 861268113 : return (TREE_CODE (t) == INTEGER_CST
6616 : 1722642432 : && wi::fits_shwi_p (wi::to_widest (t)));
6617 : : }
6618 : :
6619 : : /* Return true if T is an INTEGER_CST whose numerical value (extended
6620 : : according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
6621 : :
6622 : : bool
6623 : 3735150048 : tree_fits_uhwi_p (const_tree t)
6624 : : {
6625 : 3735150048 : return (t != NULL_TREE
6626 : 3734550355 : && TREE_CODE (t) == INTEGER_CST
6627 : 7464785060 : && wi::fits_uhwi_p (wi::to_widest (t)));
6628 : : }
6629 : :
6630 : : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6631 : : value (extended according to TYPE_UNSIGNED) fits in a poly_uint64. */
6632 : :
6633 : : bool
6634 : 965313712 : tree_fits_poly_uint64_p (const_tree t)
6635 : : {
6636 : 965313712 : if (t == NULL_TREE)
6637 : : return false;
6638 : 964961515 : if (POLY_INT_CST_P (t))
6639 : : {
6640 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6641 : : if (!wi::fits_uhwi_p (wi::to_widest (POLY_INT_CST_COEFF (t, i))))
6642 : : return false;
6643 : : return true;
6644 : : }
6645 : 964961515 : return (TREE_CODE (t) == INTEGER_CST
6646 : 1929924424 : && wi::fits_uhwi_p (wi::to_widest (t)));
6647 : : }
6648 : :
6649 : : /* Return true if T is an INTEGER_CST whose numerical value (extended according
6650 : : to TYPE_UNSIGNED) fits in a sanitize_code_type (uint64_t). */
6651 : :
6652 : : bool
6653 : 90 : tree_fits_sanitize_code_type_p (const_tree t)
6654 : : {
6655 : 90 : if (t == NULL_TREE)
6656 : : return false;
6657 : 90 : return (TREE_CODE (t) == INTEGER_CST
6658 : 180 : && wi::fits_uhwi_p (wi::to_widest (t)));
6659 : : }
6660 : :
6661 : : /* T is an INTEGER_CST whose numerical value (extended according to
6662 : : TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that
6663 : : HOST_WIDE_INT. */
6664 : :
6665 : : HOST_WIDE_INT
6666 : 1280494128 : tree_to_shwi (const_tree t)
6667 : : {
6668 : 1280494128 : gcc_assert (tree_fits_shwi_p (t));
6669 : 1280494128 : return TREE_INT_CST_LOW (t);
6670 : : }
6671 : :
6672 : : /* T is an INTEGER_CST whose numerical value (extended according to
6673 : : TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. Return that
6674 : : HOST_WIDE_INT. */
6675 : :
6676 : : unsigned HOST_WIDE_INT
6677 : 916377784 : tree_to_uhwi (const_tree t)
6678 : : {
6679 : 916377784 : gcc_assert (tree_fits_uhwi_p (t));
6680 : 916377784 : return TREE_INT_CST_LOW (t);
6681 : : }
6682 : :
6683 : : /* T is an INTEGER_CST whose numerical value (extended according to
6684 : : TYPE_UNSIGNED) fits in a sanitize_code_type. Return that
6685 : : sanitize_code_type. */
6686 : :
6687 : : sanitize_code_type
6688 : 90 : tree_to_sanitize_code_type (const_tree t)
6689 : : {
6690 : 90 : gcc_assert (tree_fits_sanitize_code_type_p (t));
6691 : 90 : return TREE_INT_CST_LOW (t);
6692 : : }
6693 : :
6694 : : /* Return the most significant (sign) bit of T. */
6695 : :
6696 : : int
6697 : 41060116 : tree_int_cst_sign_bit (const_tree t)
6698 : : {
6699 : 41060116 : unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1;
6700 : :
6701 : 41060116 : return wi::extract_uhwi (wi::to_wide (t), bitno, 1);
6702 : : }
6703 : :
6704 : : /* Return an indication of the sign of the integer constant T.
6705 : : The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6706 : : Note that -1 will never be returned if T's type is unsigned. */
6707 : :
6708 : : int
6709 : 1635907441 : tree_int_cst_sgn (const_tree t)
6710 : : {
6711 : 1635907441 : if (wi::to_wide (t) == 0)
6712 : : return 0;
6713 : 1529754948 : else if (TYPE_UNSIGNED (TREE_TYPE (t)))
6714 : : return 1;
6715 : 66116045 : else if (wi::neg_p (wi::to_wide (t)))
6716 : : return -1;
6717 : : else
6718 : : return 1;
6719 : : }
6720 : :
6721 : : /* Return the minimum number of bits needed to represent VALUE in a
6722 : : signed or unsigned type, UNSIGNEDP says which. */
6723 : :
6724 : : unsigned int
6725 : 3469496 : tree_int_cst_min_precision (tree value, signop sgn)
6726 : : {
6727 : : /* If the value is negative, compute its negative minus 1. The latter
6728 : : adjustment is because the absolute value of the largest negative value
6729 : : is one larger than the largest positive value. This is equivalent to
6730 : : a bit-wise negation, so use that operation instead. */
6731 : :
6732 : 3469496 : if (tree_int_cst_sgn (value) < 0)
6733 : 102973 : value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value);
6734 : :
6735 : : /* Return the number of bits needed, taking into account the fact
6736 : : that we need one more bit for a signed than unsigned type.
6737 : : If value is 0 or -1, the minimum precision is 1 no matter
6738 : : whether unsignedp is true or false. */
6739 : :
6740 : 3469496 : if (integer_zerop (value))
6741 : : return 1;
6742 : : else
6743 : 4968009 : return tree_floor_log2 (value) + 1 + (sgn == SIGNED ? 1 : 0) ;
6744 : : }
6745 : :
6746 : : /* Return truthvalue of whether T1 is the same tree structure as T2.
6747 : : Return 1 if they are the same.
6748 : : Return 0 if they are understandably different.
6749 : : Return -1 if either contains tree structure not understood by
6750 : : this function. */
6751 : :
6752 : : int
6753 : 177926352 : simple_cst_equal (const_tree t1, const_tree t2)
6754 : : {
6755 : 182153114 : enum tree_code code1, code2;
6756 : 182153114 : int cmp;
6757 : 182153114 : int i;
6758 : :
6759 : 182153114 : if (t1 == t2)
6760 : : return 1;
6761 : 118948693 : if (t1 == 0 || t2 == 0)
6762 : : return 0;
6763 : :
6764 : : /* For location wrappers to be the same, they must be at the same
6765 : : source location (and wrap the same thing). */
6766 : 110747089 : if (location_wrapper_p (t1) && location_wrapper_p (t2))
6767 : : {
6768 : 11289981 : if (EXPR_LOCATION (t1) != EXPR_LOCATION (t2))
6769 : : return 0;
6770 : 666 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6771 : : }
6772 : :
6773 : 99457108 : code1 = TREE_CODE (t1);
6774 : 99457108 : code2 = TREE_CODE (t2);
6775 : :
6776 : 99457108 : if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR)
6777 : : {
6778 : 4213537 : if (CONVERT_EXPR_CODE_P (code2)
6779 : 4212827 : || code2 == NON_LVALUE_EXPR)
6780 : 710 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6781 : : else
6782 : 4212827 : return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
6783 : : }
6784 : :
6785 : 95243571 : else if (CONVERT_EXPR_CODE_P (code2)
6786 : 95243556 : || code2 == NON_LVALUE_EXPR)
6787 : 118 : return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
6788 : :
6789 : 95243453 : if (code1 != code2)
6790 : : return 0;
6791 : :
6792 : 90460151 : switch (code1)
6793 : : {
6794 : 81475581 : case INTEGER_CST:
6795 : 81475581 : return wi::to_widest (t1) == wi::to_widest (t2);
6796 : :
6797 : 93 : case REAL_CST:
6798 : 93 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
6799 : :
6800 : 0 : case FIXED_CST:
6801 : 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
6802 : :
6803 : 3121411 : case STRING_CST:
6804 : 3121411 : return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
6805 : 3121411 : && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
6806 : 3571937 : TREE_STRING_LENGTH (t1)));
6807 : :
6808 : 82 : case CONSTRUCTOR:
6809 : 82 : {
6810 : 82 : unsigned HOST_WIDE_INT idx;
6811 : 82 : vec<constructor_elt, va_gc> *v1 = CONSTRUCTOR_ELTS (t1);
6812 : 82 : vec<constructor_elt, va_gc> *v2 = CONSTRUCTOR_ELTS (t2);
6813 : :
6814 : 100 : if (vec_safe_length (v1) != vec_safe_length (v2))
6815 : : return false;
6816 : :
6817 : 88 : for (idx = 0; idx < vec_safe_length (v1); ++idx)
6818 : : /* ??? Should we handle also fields here? */
6819 : 9 : if (!simple_cst_equal ((*v1)[idx].value, (*v2)[idx].value))
6820 : : return false;
6821 : : return true;
6822 : : }
6823 : :
6824 : 0 : case SAVE_EXPR:
6825 : 0 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6826 : :
6827 : 212101 : case CALL_EXPR:
6828 : 212101 : cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2));
6829 : 212101 : if (cmp <= 0)
6830 : : return cmp;
6831 : 86994 : if (call_expr_nargs (t1) != call_expr_nargs (t2))
6832 : : return 0;
6833 : 86994 : {
6834 : 86994 : const_tree arg1, arg2;
6835 : 86994 : const_call_expr_arg_iterator iter1, iter2;
6836 : 173988 : for (arg1 = first_const_call_expr_arg (t1, &iter1),
6837 : 86994 : arg2 = first_const_call_expr_arg (t2, &iter2);
6838 : 87064 : arg1 && arg2;
6839 : 70 : arg1 = next_const_call_expr_arg (&iter1),
6840 : 70 : arg2 = next_const_call_expr_arg (&iter2))
6841 : : {
6842 : 86980 : cmp = simple_cst_equal (arg1, arg2);
6843 : 86980 : if (cmp <= 0)
6844 : : return cmp;
6845 : : }
6846 : 84 : return arg1 == arg2;
6847 : : }
6848 : :
6849 : 12016 : case TARGET_EXPR:
6850 : : /* Special case: if either target is an unallocated VAR_DECL,
6851 : : it means that it's going to be unified with whatever the
6852 : : TARGET_EXPR is really supposed to initialize, so treat it
6853 : : as being equivalent to anything. */
6854 : 12016 : if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
6855 : 12016 : && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
6856 : 12016 : && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
6857 : 12016 : || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
6858 : 0 : && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
6859 : 0 : && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
6860 : : cmp = 1;
6861 : : else
6862 : 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6863 : :
6864 : 0 : if (cmp <= 0)
6865 : : return cmp;
6866 : :
6867 : 12016 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
6868 : :
6869 : 0 : case WITH_CLEANUP_EXPR:
6870 : 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6871 : 0 : if (cmp <= 0)
6872 : : return cmp;
6873 : :
6874 : 0 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
6875 : :
6876 : 425 : case COMPONENT_REF:
6877 : 425 : if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
6878 : 425 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6879 : :
6880 : : return 0;
6881 : :
6882 : : case VAR_DECL:
6883 : : case PARM_DECL:
6884 : : case CONST_DECL:
6885 : : case FUNCTION_DECL:
6886 : : return 0;
6887 : :
6888 : 5576435 : default:
6889 : 5576435 : if (POLY_INT_CST_P (t1))
6890 : : /* A false return means maybe_ne rather than known_ne. */
6891 : : return known_eq (poly_widest_int::from (poly_int_cst_value (t1),
6892 : : TYPE_SIGN (TREE_TYPE (t1))),
6893 : : poly_widest_int::from (poly_int_cst_value (t2),
6894 : : TYPE_SIGN (TREE_TYPE (t2))));
6895 : 5576435 : break;
6896 : : }
6897 : :
6898 : : /* This general rule works for most tree codes. All exceptions should be
6899 : : handled above. If this is a language-specific tree code, we can't
6900 : : trust what might be in the operand, so say we don't know
6901 : : the situation. */
6902 : 5576435 : if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
6903 : : return -1;
6904 : :
6905 : 828000 : switch (TREE_CODE_CLASS (code1))
6906 : : {
6907 : : case tcc_unary:
6908 : : case tcc_binary:
6909 : : case tcc_comparison:
6910 : : case tcc_expression:
6911 : : case tcc_reference:
6912 : : case tcc_statement:
6913 : : cmp = 1;
6914 : 2109 : for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
6915 : : {
6916 : 1627 : cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
6917 : 1627 : if (cmp <= 0)
6918 : : return cmp;
6919 : : }
6920 : :
6921 : : return cmp;
6922 : :
6923 : : default:
6924 : : return -1;
6925 : : }
6926 : : }
6927 : :
6928 : : /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
6929 : : Return -1, 0, or 1 if the value of T is less than, equal to, or greater
6930 : : than U, respectively. */
6931 : :
6932 : : int
6933 : 1350440716 : compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u)
6934 : : {
6935 : 1350440716 : if (tree_int_cst_sgn (t) < 0)
6936 : : return -1;
6937 : 1350440438 : else if (!tree_fits_uhwi_p (t))
6938 : : return 1;
6939 : 1350440413 : else if (TREE_INT_CST_LOW (t) == u)
6940 : : return 0;
6941 : 1222328730 : else if (TREE_INT_CST_LOW (t) < u)
6942 : : return -1;
6943 : : else
6944 : 12318750 : return 1;
6945 : : }
6946 : :
6947 : : /* Return true if SIZE represents a constant size that is in bounds of
6948 : : what the middle-end and the backend accepts (covering not more than
6949 : : half of the address-space).
6950 : : When PERR is non-null, set *PERR on failure to the description of
6951 : : why SIZE is not valid. */
6952 : :
6953 : : bool
6954 : 56849945 : valid_constant_size_p (const_tree size, cst_size_error *perr /* = NULL */)
6955 : : {
6956 : 56849945 : if (POLY_INT_CST_P (size))
6957 : : {
6958 : : if (TREE_OVERFLOW (size))
6959 : : return false;
6960 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
6961 : : if (!valid_constant_size_p (POLY_INT_CST_COEFF (size, i)))
6962 : : return false;
6963 : : return true;
6964 : : }
6965 : :
6966 : 56849945 : cst_size_error error;
6967 : 56849945 : if (!perr)
6968 : 51919226 : perr = &error;
6969 : :
6970 : 56849945 : if (TREE_CODE (size) != INTEGER_CST)
6971 : : {
6972 : 3 : *perr = cst_size_not_constant;
6973 : 3 : return false;
6974 : : }
6975 : :
6976 : 56849942 : if (TREE_OVERFLOW_P (size))
6977 : : {
6978 : 60 : *perr = cst_size_overflow;
6979 : 60 : return false;
6980 : : }
6981 : :
6982 : 56849882 : if (tree_int_cst_sgn (size) < 0)
6983 : : {
6984 : 409 : *perr = cst_size_negative;
6985 : 409 : return false;
6986 : : }
6987 : 113698946 : if (!tree_fits_uhwi_p (size)
6988 : 170548419 : || (wi::to_widest (TYPE_MAX_VALUE (sizetype))
6989 : 170548419 : < wi::to_widest (size) * 2))
6990 : : {
6991 : 624 : *perr = cst_size_too_big;
6992 : 624 : return false;
6993 : : }
6994 : :
6995 : : return true;
6996 : : }
6997 : :
6998 : : /* Return the precision of the type, or for a complex or vector type the
6999 : : precision of the type of its elements. */
7000 : :
7001 : : unsigned int
7002 : 7081167050 : element_precision (const_tree type)
7003 : : {
7004 : 7081167050 : if (!TYPE_P (type))
7005 : 6663705 : type = TREE_TYPE (type);
7006 : 7081167050 : enum tree_code code = TREE_CODE (type);
7007 : 7081167050 : if (code == COMPLEX_TYPE || code == VECTOR_TYPE)
7008 : 53840859 : type = TREE_TYPE (type);
7009 : :
7010 : 7081167050 : return TYPE_PRECISION (type);
7011 : : }
7012 : :
7013 : : /* Return true if CODE represents an associative tree code. Otherwise
7014 : : return false. */
7015 : : bool
7016 : 35738913 : associative_tree_code (enum tree_code code)
7017 : : {
7018 : 35738913 : switch (code)
7019 : : {
7020 : : case BIT_IOR_EXPR:
7021 : : case BIT_AND_EXPR:
7022 : : case BIT_XOR_EXPR:
7023 : : case PLUS_EXPR:
7024 : : case MULT_EXPR:
7025 : : case MIN_EXPR:
7026 : : case MAX_EXPR:
7027 : : return true;
7028 : :
7029 : 25236013 : default:
7030 : 25236013 : break;
7031 : : }
7032 : 25236013 : return false;
7033 : : }
7034 : :
7035 : : /* Return true if CODE represents a commutative tree code. Otherwise
7036 : : return false. */
7037 : : bool
7038 : 1669782442 : commutative_tree_code (enum tree_code code)
7039 : : {
7040 : 1669782442 : switch (code)
7041 : : {
7042 : : case PLUS_EXPR:
7043 : : case MULT_EXPR:
7044 : : case MULT_HIGHPART_EXPR:
7045 : : case MIN_EXPR:
7046 : : case MAX_EXPR:
7047 : : case BIT_IOR_EXPR:
7048 : : case BIT_XOR_EXPR:
7049 : : case BIT_AND_EXPR:
7050 : : case NE_EXPR:
7051 : : case EQ_EXPR:
7052 : : case UNORDERED_EXPR:
7053 : : case ORDERED_EXPR:
7054 : : case UNEQ_EXPR:
7055 : : case LTGT_EXPR:
7056 : : case TRUTH_AND_EXPR:
7057 : : case TRUTH_XOR_EXPR:
7058 : : case TRUTH_OR_EXPR:
7059 : : case WIDEN_MULT_EXPR:
7060 : : case VEC_WIDEN_MULT_HI_EXPR:
7061 : : case VEC_WIDEN_MULT_LO_EXPR:
7062 : : case VEC_WIDEN_MULT_EVEN_EXPR:
7063 : : case VEC_WIDEN_MULT_ODD_EXPR:
7064 : : return true;
7065 : :
7066 : 860940328 : default:
7067 : 860940328 : break;
7068 : : }
7069 : 860940328 : return false;
7070 : : }
7071 : :
7072 : : /* Return true if CODE represents a ternary tree code for which the
7073 : : first two operands are commutative. Otherwise return false. */
7074 : : bool
7075 : 77951213 : commutative_ternary_tree_code (enum tree_code code)
7076 : : {
7077 : 77951213 : switch (code)
7078 : : {
7079 : : case WIDEN_MULT_PLUS_EXPR:
7080 : : case WIDEN_MULT_MINUS_EXPR:
7081 : : case DOT_PROD_EXPR:
7082 : : return true;
7083 : :
7084 : 77942508 : default:
7085 : 77942508 : break;
7086 : : }
7087 : 77942508 : return false;
7088 : : }
7089 : :
7090 : : /* Returns true if CODE can overflow. */
7091 : :
7092 : : bool
7093 : 2969 : operation_can_overflow (enum tree_code code)
7094 : : {
7095 : 2969 : switch (code)
7096 : : {
7097 : : case PLUS_EXPR:
7098 : : case MINUS_EXPR:
7099 : : case MULT_EXPR:
7100 : : case LSHIFT_EXPR:
7101 : : /* Can overflow in various ways. */
7102 : : return true;
7103 : : case TRUNC_DIV_EXPR:
7104 : : case EXACT_DIV_EXPR:
7105 : : case FLOOR_DIV_EXPR:
7106 : : case CEIL_DIV_EXPR:
7107 : : /* For INT_MIN / -1. */
7108 : : return true;
7109 : : case NEGATE_EXPR:
7110 : : case ABS_EXPR:
7111 : : /* For -INT_MIN. */
7112 : : return true;
7113 : 142 : default:
7114 : : /* These operators cannot overflow. */
7115 : 142 : return false;
7116 : : }
7117 : : }
7118 : :
7119 : : /* Returns true if CODE operating on operands of type TYPE doesn't overflow, or
7120 : : ftrapv doesn't generate trapping insns for CODE. */
7121 : :
7122 : : bool
7123 : 5946156 : operation_no_trapping_overflow (tree type, enum tree_code code)
7124 : : {
7125 : 5946156 : gcc_checking_assert (ANY_INTEGRAL_TYPE_P (type));
7126 : :
7127 : : /* We don't generate instructions that trap on overflow for complex or vector
7128 : : types. */
7129 : 5946156 : if (!INTEGRAL_TYPE_P (type))
7130 : : return true;
7131 : :
7132 : 5946156 : if (!TYPE_OVERFLOW_TRAPS (type))
7133 : : return true;
7134 : :
7135 : 1358 : switch (code)
7136 : : {
7137 : : case PLUS_EXPR:
7138 : : case MINUS_EXPR:
7139 : : case MULT_EXPR:
7140 : : case NEGATE_EXPR:
7141 : : case ABS_EXPR:
7142 : : /* These operators can overflow, and -ftrapv generates trapping code for
7143 : : these. */
7144 : : return false;
7145 : : case TRUNC_DIV_EXPR:
7146 : : case EXACT_DIV_EXPR:
7147 : : case FLOOR_DIV_EXPR:
7148 : : case CEIL_DIV_EXPR:
7149 : : case LSHIFT_EXPR:
7150 : : /* These operators can overflow, but -ftrapv does not generate trapping
7151 : : code for these. */
7152 : : return true;
7153 : : default:
7154 : : /* These operators cannot overflow. */
7155 : : return true;
7156 : : }
7157 : : }
7158 : :
7159 : : /* Constructors for pointer, array and function types.
7160 : : (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7161 : : constructed by language-dependent code, not here.) */
7162 : :
7163 : : /* Construct, lay out and return the type of pointers to TO_TYPE with
7164 : : mode MODE. If MODE is VOIDmode, a pointer mode for the address
7165 : : space of TO_TYPE will be picked. If CAN_ALIAS_ALL is TRUE,
7166 : : indicate this type can reference all of memory. If such a type has
7167 : : already been constructed, reuse it. */
7168 : :
7169 : : tree
7170 : 2174614750 : build_pointer_type_for_mode (tree to_type, machine_mode mode,
7171 : : bool can_alias_all)
7172 : : {
7173 : 2174614750 : tree t;
7174 : 2174614750 : bool could_alias = can_alias_all;
7175 : :
7176 : 2174614750 : if (to_type == error_mark_node)
7177 : : return error_mark_node;
7178 : :
7179 : 2174614744 : if (mode == VOIDmode)
7180 : : {
7181 : 2054316633 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7182 : 2054316633 : mode = targetm.addr_space.pointer_mode (as);
7183 : : }
7184 : :
7185 : : /* If the pointed-to type has the may_alias attribute set, force
7186 : : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7187 : 2174614744 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7188 : 4483583 : can_alias_all = true;
7189 : :
7190 : : /* In some cases, languages will have things that aren't a POINTER_TYPE
7191 : : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7192 : : In that case, return that type without regard to the rest of our
7193 : : operands.
7194 : :
7195 : : ??? This is a kludge, but consistent with the way this function has
7196 : : always operated and there doesn't seem to be a good way to avoid this
7197 : : at the moment. */
7198 : 2174614744 : if (TYPE_POINTER_TO (to_type) != 0
7199 : 2174614744 : && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
7200 : 43590 : return TYPE_POINTER_TO (to_type);
7201 : :
7202 : : /* First, if we already have a type for pointers to TO_TYPE and it's
7203 : : the proper mode, use it. */
7204 : 2175139910 : for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
7205 : 2045036037 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7206 : : return t;
7207 : :
7208 : 130103873 : t = make_node (POINTER_TYPE);
7209 : :
7210 : 130103873 : TREE_TYPE (t) = to_type;
7211 : 130103873 : SET_TYPE_MODE (t, mode);
7212 : 130103873 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7213 : 130103873 : TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
7214 : 130103873 : TYPE_POINTER_TO (to_type) = t;
7215 : :
7216 : : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7217 : 130103873 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7218 : 5080770 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7219 : 125023103 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7220 : 38026268 : TYPE_CANONICAL (t)
7221 : 76052536 : = build_pointer_type_for_mode (TYPE_CANONICAL (to_type),
7222 : : mode, false);
7223 : :
7224 : : /* Lay out the type. This function has many callers that are concerned
7225 : : with expression-construction, and this simplifies them all. */
7226 : 130103873 : layout_type (t);
7227 : :
7228 : 130103873 : return t;
7229 : : }
7230 : :
7231 : : /* By default build pointers in ptr_mode. */
7232 : :
7233 : : tree
7234 : 2053627028 : build_pointer_type (tree to_type)
7235 : : {
7236 : 2053627028 : return build_pointer_type_for_mode (to_type, VOIDmode, false);
7237 : : }
7238 : :
7239 : : /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7240 : :
7241 : : tree
7242 : 567098957 : build_reference_type_for_mode (tree to_type, machine_mode mode,
7243 : : bool can_alias_all)
7244 : : {
7245 : 567098957 : tree t;
7246 : 567098957 : bool could_alias = can_alias_all;
7247 : :
7248 : 567098957 : if (to_type == error_mark_node)
7249 : : return error_mark_node;
7250 : :
7251 : 567098957 : if (mode == VOIDmode)
7252 : : {
7253 : 464437438 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7254 : 464437438 : mode = targetm.addr_space.pointer_mode (as);
7255 : : }
7256 : :
7257 : : /* If the pointed-to type has the may_alias attribute set, force
7258 : : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7259 : 567098957 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7260 : 721511 : can_alias_all = true;
7261 : :
7262 : : /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7263 : : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7264 : : In that case, return that type without regard to the rest of our
7265 : : operands.
7266 : :
7267 : : ??? This is a kludge, but consistent with the way this function has
7268 : : always operated and there doesn't seem to be a good way to avoid this
7269 : : at the moment. */
7270 : 567098957 : if (TYPE_REFERENCE_TO (to_type) != 0
7271 : 567098957 : && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
7272 : 0 : return TYPE_REFERENCE_TO (to_type);
7273 : :
7274 : : /* First, if we already have a type for pointers to TO_TYPE and it's
7275 : : the proper mode, use it. */
7276 : 567098957 : for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
7277 : 491099148 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7278 : : return t;
7279 : :
7280 : 75999809 : t = make_node (REFERENCE_TYPE);
7281 : :
7282 : 75999809 : TREE_TYPE (t) = to_type;
7283 : 75999809 : SET_TYPE_MODE (t, mode);
7284 : 75999809 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7285 : 75999809 : TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
7286 : 75999809 : TYPE_REFERENCE_TO (to_type) = t;
7287 : :
7288 : : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7289 : 75999809 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7290 : 3635474 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7291 : 72364335 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7292 : 42978837 : TYPE_CANONICAL (t)
7293 : 85957674 : = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
7294 : : mode, false);
7295 : :
7296 : 75999809 : layout_type (t);
7297 : :
7298 : 75999809 : return t;
7299 : : }
7300 : :
7301 : :
7302 : : /* Build the node for the type of references-to-TO_TYPE by default
7303 : : in ptr_mode. */
7304 : :
7305 : : tree
7306 : 22357200 : build_reference_type (tree to_type)
7307 : : {
7308 : 22357200 : return build_reference_type_for_mode (to_type, VOIDmode, false);
7309 : : }
7310 : :
7311 : : #define MAX_INT_CACHED_PREC \
7312 : : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7313 : : static GTY(()) tree nonstandard_integer_type_cache[2 * MAX_INT_CACHED_PREC + 2];
7314 : :
7315 : : static void
7316 : 261000 : clear_nonstandard_integer_type_cache (void)
7317 : : {
7318 : 34191000 : for (size_t i = 0 ; i < 2 * MAX_INT_CACHED_PREC + 2 ; i++)
7319 : : {
7320 : 33930000 : nonstandard_integer_type_cache[i] = NULL;
7321 : : }
7322 : 0 : }
7323 : :
7324 : : /* Builds a signed or unsigned integer type of precision PRECISION.
7325 : : Used for C bitfields whose precision does not match that of
7326 : : built-in target types. */
7327 : : tree
7328 : 64301483 : build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
7329 : : int unsignedp)
7330 : : {
7331 : 64301483 : tree itype, ret;
7332 : :
7333 : 64301483 : if (unsignedp)
7334 : 55648111 : unsignedp = MAX_INT_CACHED_PREC + 1;
7335 : :
7336 : 64301483 : if (precision <= MAX_INT_CACHED_PREC)
7337 : : {
7338 : 63856317 : itype = nonstandard_integer_type_cache[precision + unsignedp];
7339 : 63856317 : if (itype)
7340 : : return itype;
7341 : : }
7342 : :
7343 : 1112076 : itype = make_node (INTEGER_TYPE);
7344 : 1112076 : TYPE_PRECISION (itype) = precision;
7345 : :
7346 : 1112076 : if (unsignedp)
7347 : 760700 : fixup_unsigned_type (itype);
7348 : : else
7349 : 351376 : fixup_signed_type (itype);
7350 : :
7351 : 1112076 : inchash::hash hstate;
7352 : 1112076 : inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7353 : 1112076 : ret = type_hash_canon (hstate.end (), itype);
7354 : 1112076 : if (precision <= MAX_INT_CACHED_PREC)
7355 : 666910 : nonstandard_integer_type_cache[precision + unsignedp] = ret;
7356 : :
7357 : : return ret;
7358 : : }
7359 : :
7360 : : #define MAX_BOOL_CACHED_PREC \
7361 : : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7362 : : static GTY(()) tree nonstandard_boolean_type_cache[MAX_BOOL_CACHED_PREC + 1];
7363 : :
7364 : : /* Builds a boolean type of precision PRECISION.
7365 : : Used for boolean vectors to choose proper vector element size. */
7366 : : tree
7367 : 2448497 : build_nonstandard_boolean_type (unsigned HOST_WIDE_INT precision)
7368 : : {
7369 : 2448497 : tree type;
7370 : :
7371 : 2448497 : if (precision <= MAX_BOOL_CACHED_PREC)
7372 : : {
7373 : 2443813 : type = nonstandard_boolean_type_cache[precision];
7374 : 2443813 : if (type)
7375 : : return type;
7376 : : }
7377 : :
7378 : 78996 : type = make_node (BOOLEAN_TYPE);
7379 : 78996 : TYPE_PRECISION (type) = precision;
7380 : 78996 : fixup_signed_type (type);
7381 : :
7382 : 78996 : if (precision <= MAX_INT_CACHED_PREC)
7383 : 74312 : nonstandard_boolean_type_cache[precision] = type;
7384 : :
7385 : : return type;
7386 : : }
7387 : :
7388 : : static GTY(()) vec<tree, va_gc> *bitint_type_cache;
7389 : :
7390 : : /* Builds a signed or unsigned _BitInt(PRECISION) type. */
7391 : : tree
7392 : 72530 : build_bitint_type (unsigned HOST_WIDE_INT precision, int unsignedp)
7393 : : {
7394 : 72530 : tree itype, ret;
7395 : :
7396 : 108411 : gcc_checking_assert (precision >= 1 + !unsignedp);
7397 : :
7398 : 72530 : if (unsignedp)
7399 : 35881 : unsignedp = MAX_INT_CACHED_PREC + 1;
7400 : :
7401 : 72530 : if (bitint_type_cache == NULL)
7402 : 497 : vec_safe_grow_cleared (bitint_type_cache, 2 * MAX_INT_CACHED_PREC + 2);
7403 : :
7404 : 72530 : if (precision <= MAX_INT_CACHED_PREC)
7405 : : {
7406 : 15476 : itype = (*bitint_type_cache)[precision + unsignedp];
7407 : 15476 : if (itype)
7408 : : return itype;
7409 : : }
7410 : :
7411 : 58594 : itype = make_node (BITINT_TYPE);
7412 : 58594 : TYPE_PRECISION (itype) = precision;
7413 : :
7414 : 58594 : if (unsignedp)
7415 : 29349 : fixup_unsigned_type (itype);
7416 : : else
7417 : 29245 : fixup_signed_type (itype);
7418 : :
7419 : 58594 : hashval_t hash = type_hash_canon_hash (itype);
7420 : 58594 : ret = type_hash_canon (hash, itype);
7421 : 58594 : if (precision <= MAX_INT_CACHED_PREC)
7422 : 1540 : (*bitint_type_cache)[precision + unsignedp] = ret;
7423 : :
7424 : : return ret;
7425 : : }
7426 : :
7427 : : /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7428 : : or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7429 : : is true, reuse such a type that has already been constructed. */
7430 : :
7431 : : static tree
7432 : 39834350 : build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
7433 : : {
7434 : 39834350 : tree itype = make_node (INTEGER_TYPE);
7435 : :
7436 : 39834350 : TREE_TYPE (itype) = type;
7437 : :
7438 : 39834350 : TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
7439 : 39834350 : TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
7440 : :
7441 : 39834350 : TYPE_PRECISION (itype) = TYPE_PRECISION (type);
7442 : 39834350 : SET_TYPE_MODE (itype, TYPE_MODE (type));
7443 : 39834350 : TYPE_SIZE (itype) = TYPE_SIZE (type);
7444 : 39834350 : TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
7445 : 39834350 : SET_TYPE_ALIGN (itype, TYPE_ALIGN (type));
7446 : 39834350 : TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
7447 : 39834350 : SET_TYPE_WARN_IF_NOT_ALIGN (itype, TYPE_WARN_IF_NOT_ALIGN (type));
7448 : :
7449 : 39834350 : if (!shared)
7450 : : return itype;
7451 : :
7452 : 39834350 : if ((TYPE_MIN_VALUE (itype)
7453 : 39834350 : && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST)
7454 : 79667865 : || (TYPE_MAX_VALUE (itype)
7455 : 39289646 : && TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST))
7456 : : {
7457 : : /* Since we cannot reliably merge this type, we need to compare it using
7458 : : structural equality checks. */
7459 : 1004324 : SET_TYPE_STRUCTURAL_EQUALITY (itype);
7460 : 1004324 : return itype;
7461 : : }
7462 : :
7463 : 38830026 : hashval_t hash = type_hash_canon_hash (itype);
7464 : 38830026 : itype = type_hash_canon (hash, itype);
7465 : :
7466 : 38830026 : return itype;
7467 : : }
7468 : :
7469 : : /* Wrapper around build_range_type_1 with SHARED set to true. */
7470 : :
7471 : : tree
7472 : 39834350 : build_range_type (tree type, tree lowval, tree highval)
7473 : : {
7474 : 39834350 : return build_range_type_1 (type, lowval, highval, true);
7475 : : }
7476 : :
7477 : : /* Wrapper around build_range_type_1 with SHARED set to false. */
7478 : :
7479 : : tree
7480 : 0 : build_nonshared_range_type (tree type, tree lowval, tree highval)
7481 : : {
7482 : 0 : return build_range_type_1 (type, lowval, highval, false);
7483 : : }
7484 : :
7485 : : /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7486 : : MAXVAL should be the maximum value in the domain
7487 : : (one less than the length of the array).
7488 : :
7489 : : The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7490 : : We don't enforce this limit, that is up to caller (e.g. language front end).
7491 : : The limit exists because the result is a signed type and we don't handle
7492 : : sizes that use more than one HOST_WIDE_INT. */
7493 : :
7494 : : tree
7495 : 37089358 : build_index_type (tree maxval)
7496 : : {
7497 : 37089358 : return build_range_type (sizetype, size_zero_node, maxval);
7498 : : }
7499 : :
7500 : : /* Return true if the debug information for TYPE, a subtype, should be emitted
7501 : : as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7502 : : high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7503 : : debug info and doesn't reflect the source code. */
7504 : :
7505 : : bool
7506 : 18 : subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval)
7507 : : {
7508 : 18 : tree base_type = TREE_TYPE (type), low, high;
7509 : :
7510 : : /* Subrange types have a base type which is an integral type. */
7511 : 18 : if (!INTEGRAL_TYPE_P (base_type))
7512 : : return false;
7513 : :
7514 : : /* Get the real bounds of the subtype. */
7515 : 18 : if (lang_hooks.types.get_subrange_bounds)
7516 : 0 : lang_hooks.types.get_subrange_bounds (type, &low, &high);
7517 : : else
7518 : : {
7519 : 18 : low = TYPE_MIN_VALUE (type);
7520 : 18 : high = TYPE_MAX_VALUE (type);
7521 : : }
7522 : :
7523 : : /* If the type and its base type have the same representation and the same
7524 : : name, then the type is not a subrange but a copy of the base type. */
7525 : 18 : if ((TREE_CODE (base_type) == INTEGER_TYPE
7526 : 18 : || TREE_CODE (base_type) == BOOLEAN_TYPE)
7527 : 18 : && int_size_in_bytes (type) == int_size_in_bytes (base_type)
7528 : 18 : && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type))
7529 : 0 : && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type))
7530 : 18 : && TYPE_IDENTIFIER (type) == TYPE_IDENTIFIER (base_type))
7531 : : return false;
7532 : :
7533 : 18 : if (lowval)
7534 : 18 : *lowval = low;
7535 : 18 : if (highval)
7536 : 18 : *highval = high;
7537 : : return true;
7538 : : }
7539 : :
7540 : : /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7541 : : and number of elements specified by the range of values of INDEX_TYPE.
7542 : : If TYPELESS_STORAGE is true, TYPE_TYPELESS_STORAGE flag is set on the type.
7543 : : If SHARED is true, reuse such a type that has already been constructed.
7544 : : If SET_CANONICAL is true, compute TYPE_CANONICAL from the element type. */
7545 : :
7546 : : tree
7547 : 63459300 : build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
7548 : : bool shared, bool set_canonical)
7549 : : {
7550 : 63459300 : tree t;
7551 : :
7552 : 63459300 : if (TREE_CODE (elt_type) == FUNCTION_TYPE)
7553 : : {
7554 : 0 : error ("arrays of functions are not meaningful");
7555 : 0 : elt_type = integer_type_node;
7556 : : }
7557 : :
7558 : 63459300 : t = make_node (ARRAY_TYPE);
7559 : 63459300 : TREE_TYPE (t) = elt_type;
7560 : 63459300 : TYPE_DOMAIN (t) = index_type;
7561 : 63459300 : TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type);
7562 : 63459300 : TYPE_TYPELESS_STORAGE (t) = typeless_storage;
7563 : :
7564 : : /* Set TYPE_STRUCTURAL_EQUALITY_P. */
7565 : 63459300 : if (set_canonical
7566 : 63459300 : && (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7567 : 63428023 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7568 : 63167657 : || in_lto_p))
7569 : 365620 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7570 : :
7571 : 63459300 : layout_type (t);
7572 : :
7573 : 63459300 : if (shared)
7574 : : {
7575 : 63459271 : hashval_t hash = type_hash_canon_hash (t);
7576 : 63459271 : tree probe_type = t;
7577 : 63459271 : t = type_hash_canon (hash, t);
7578 : 63459271 : if (t != probe_type)
7579 : : return t;
7580 : : }
7581 : :
7582 : 10192831 : if (TYPE_CANONICAL (t) == t && set_canonical)
7583 : : {
7584 : 9876122 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7585 : 9876122 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7586 : 19752244 : || in_lto_p)
7587 : 0 : gcc_unreachable ();
7588 : 9876122 : else if (TYPE_CANONICAL (elt_type) != elt_type
7589 : 9876122 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
7590 : 102447 : TYPE_CANONICAL (t)
7591 : 297124 : = build_array_type_1 (TYPE_CANONICAL (elt_type),
7592 : : index_type
7593 : 92230 : ? TYPE_CANONICAL (index_type) : NULL_TREE,
7594 : : typeless_storage, shared, set_canonical);
7595 : : }
7596 : :
7597 : : return t;
7598 : : }
7599 : :
7600 : : /* Wrapper around build_array_type_1 with SHARED set to true. */
7601 : :
7602 : : tree
7603 : 63356824 : build_array_type (tree elt_type, tree index_type, bool typeless_storage)
7604 : : {
7605 : 63356824 : return
7606 : 63356824 : build_array_type_1 (elt_type, index_type, typeless_storage, true, true);
7607 : : }
7608 : :
7609 : : /* Wrapper around build_array_type_1 with SHARED set to false. */
7610 : :
7611 : : tree
7612 : 0 : build_nonshared_array_type (tree elt_type, tree index_type)
7613 : : {
7614 : 0 : return build_array_type_1 (elt_type, index_type, false, false, true);
7615 : : }
7616 : :
7617 : : /* Return a representation of ELT_TYPE[NELTS], using indices of type
7618 : : sizetype. */
7619 : :
7620 : : tree
7621 : 1484906 : build_array_type_nelts (tree elt_type, poly_uint64 nelts)
7622 : : {
7623 : 1484906 : return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
7624 : : }
7625 : :
7626 : : /* Computes the canonical argument types from the argument type list
7627 : : ARGTYPES.
7628 : :
7629 : : Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7630 : : on entry to this function, or if any of the ARGTYPES are
7631 : : structural.
7632 : :
7633 : : Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7634 : : true on entry to this function, or if any of the ARGTYPES are
7635 : : non-canonical.
7636 : :
7637 : : Returns a canonical argument list, which may be ARGTYPES when the
7638 : : canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7639 : : true) or would not differ from ARGTYPES. */
7640 : :
7641 : : static tree
7642 : 907315829 : maybe_canonicalize_argtypes (tree argtypes,
7643 : : bool *any_structural_p,
7644 : : bool *any_noncanonical_p)
7645 : : {
7646 : 907315829 : tree arg;
7647 : 907315829 : bool any_noncanonical_argtypes_p = false;
7648 : :
7649 : 3166162863 : for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
7650 : : {
7651 : 2258847034 : if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
7652 : : /* Fail gracefully by stating that the type is structural. */
7653 : 4257 : *any_structural_p = true;
7654 : 2258842777 : else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg)))
7655 : 33528763 : *any_structural_p = true;
7656 : 2225314014 : else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg)
7657 : 2225314014 : || TREE_PURPOSE (arg))
7658 : : /* If the argument has a default argument, we consider it
7659 : : non-canonical even though the type itself is canonical.
7660 : : That way, different variants of function and method types
7661 : : with default arguments will all point to the variant with
7662 : : no defaults as their canonical type. */
7663 : : any_noncanonical_argtypes_p = true;
7664 : : }
7665 : :
7666 : 907315829 : if (*any_structural_p)
7667 : : return argtypes;
7668 : :
7669 : 817796391 : if (any_noncanonical_argtypes_p)
7670 : : {
7671 : : /* Build the canonical list of argument types. */
7672 : : tree canon_argtypes = NULL_TREE;
7673 : : bool is_void = false;
7674 : :
7675 : 816486368 : for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
7676 : : {
7677 : 628017944 : if (arg == void_list_node)
7678 : : is_void = true;
7679 : : else
7680 : 881507004 : canon_argtypes = tree_cons (NULL_TREE,
7681 : 440753502 : TYPE_CANONICAL (TREE_VALUE (arg)),
7682 : : canon_argtypes);
7683 : : }
7684 : :
7685 : 188468424 : canon_argtypes = nreverse (canon_argtypes);
7686 : 188468424 : if (is_void)
7687 : 187264442 : canon_argtypes = chainon (canon_argtypes, void_list_node);
7688 : :
7689 : : /* There is a non-canonical type. */
7690 : 188468424 : *any_noncanonical_p = true;
7691 : 188468424 : return canon_argtypes;
7692 : : }
7693 : :
7694 : : /* The canonical argument types are the same as ARGTYPES. */
7695 : : return argtypes;
7696 : : }
7697 : :
7698 : : /* Construct, lay out and return
7699 : : the type of functions returning type VALUE_TYPE
7700 : : given arguments of types ARG_TYPES.
7701 : : ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7702 : : are data type nodes for the arguments of the function.
7703 : : NO_NAMED_ARGS_STDARG_P is true if this is a prototyped
7704 : : variable-arguments function with (...) prototype (no named arguments).
7705 : : If such a type has already been constructed, reuse it. */
7706 : :
7707 : : tree
7708 : 612624751 : build_function_type (tree value_type, tree arg_types,
7709 : : bool no_named_args_stdarg_p)
7710 : : {
7711 : 612624751 : tree t;
7712 : 612624751 : inchash::hash hstate;
7713 : 612624751 : bool any_structural_p, any_noncanonical_p;
7714 : 612624751 : tree canon_argtypes;
7715 : :
7716 : 612624751 : gcc_assert (arg_types != error_mark_node);
7717 : :
7718 : 612624751 : if (TREE_CODE (value_type) == FUNCTION_TYPE)
7719 : : {
7720 : 0 : error ("function return type cannot be function");
7721 : 0 : value_type = integer_type_node;
7722 : : }
7723 : :
7724 : : /* Make a node of the sort we want. */
7725 : 612624751 : t = make_node (FUNCTION_TYPE);
7726 : 612624751 : TREE_TYPE (t) = value_type;
7727 : 612624751 : TYPE_ARG_TYPES (t) = arg_types;
7728 : 612624751 : if (no_named_args_stdarg_p)
7729 : : {
7730 : 1457810 : gcc_assert (arg_types == NULL_TREE);
7731 : 1457810 : TYPE_NO_NAMED_ARGS_STDARG_P (t) = 1;
7732 : : }
7733 : :
7734 : : /* Set up the canonical type. */
7735 : 612624751 : any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type);
7736 : 612624751 : any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
7737 : 612624751 : canon_argtypes = maybe_canonicalize_argtypes (arg_types,
7738 : : &any_structural_p,
7739 : : &any_noncanonical_p);
7740 : : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7741 : 612624751 : if (any_structural_p)
7742 : 66047761 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7743 : :
7744 : : /* If we already have such a type, use the old one. */
7745 : 612624751 : hashval_t hash = type_hash_canon_hash (t);
7746 : 612624751 : tree probe_type = t;
7747 : 612624751 : t = type_hash_canon (hash, t);
7748 : 612624751 : if (t != probe_type)
7749 : : return t;
7750 : :
7751 : 396808370 : if (any_structural_p)
7752 : 53432980 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7753 : 343375390 : else if (any_noncanonical_p)
7754 : 79076021 : TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
7755 : : canon_argtypes);
7756 : :
7757 : 396808370 : if (!COMPLETE_TYPE_P (t))
7758 : 0 : layout_type (t);
7759 : : return t;
7760 : : }
7761 : :
7762 : : /* Build a function type. The RETURN_TYPE is the type returned by the
7763 : : function. If VAARGS is set, no void_type_node is appended to the
7764 : : list. ARGP must be always be terminated be a NULL_TREE. */
7765 : :
7766 : : static tree
7767 : 14829665 : build_function_type_list_1 (bool vaargs, tree return_type, va_list argp)
7768 : : {
7769 : 14829665 : tree t, args, last;
7770 : :
7771 : 14829665 : t = va_arg (argp, tree);
7772 : 62852380 : for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree))
7773 : 33193050 : args = tree_cons (NULL_TREE, t, args);
7774 : :
7775 : 14829665 : if (vaargs)
7776 : : {
7777 : 836256 : last = args;
7778 : 836256 : if (args != NULL_TREE)
7779 : 707983 : args = nreverse (args);
7780 : 836256 : gcc_assert (last != void_list_node);
7781 : : }
7782 : 13993409 : else if (args == NULL_TREE)
7783 : 1146396 : args = void_list_node;
7784 : : else
7785 : : {
7786 : 12847013 : last = args;
7787 : 12847013 : args = nreverse (args);
7788 : 12847013 : TREE_CHAIN (last) = void_list_node;
7789 : : }
7790 : 14829665 : args = build_function_type (return_type, args, vaargs && args == NULL_TREE);
7791 : :
7792 : 14829665 : return args;
7793 : : }
7794 : :
7795 : : /* Build a function type. The RETURN_TYPE is the type returned by the
7796 : : function. If additional arguments are provided, they are
7797 : : additional argument types. The list of argument types must always
7798 : : be terminated by NULL_TREE. */
7799 : :
7800 : : tree
7801 : 13993409 : build_function_type_list (tree return_type, ...)
7802 : : {
7803 : 13993409 : tree args;
7804 : 13993409 : va_list p;
7805 : :
7806 : 13993409 : va_start (p, return_type);
7807 : 13993409 : args = build_function_type_list_1 (false, return_type, p);
7808 : 13993409 : va_end (p);
7809 : 13993409 : return args;
7810 : : }
7811 : :
7812 : : /* Build a variable argument function type. The RETURN_TYPE is the
7813 : : type returned by the function. If additional arguments are provided,
7814 : : they are additional argument types. The list of argument types must
7815 : : always be terminated by NULL_TREE. */
7816 : :
7817 : : tree
7818 : 836256 : build_varargs_function_type_list (tree return_type, ...)
7819 : : {
7820 : 836256 : tree args;
7821 : 836256 : va_list p;
7822 : :
7823 : 836256 : va_start (p, return_type);
7824 : 836256 : args = build_function_type_list_1 (true, return_type, p);
7825 : 836256 : va_end (p);
7826 : :
7827 : 836256 : return args;
7828 : : }
7829 : :
7830 : : /* Build a function type. RETURN_TYPE is the type returned by the
7831 : : function; VAARGS indicates whether the function takes varargs. The
7832 : : function takes N named arguments, the types of which are provided in
7833 : : ARG_TYPES. */
7834 : :
7835 : : static tree
7836 : 117933484 : build_function_type_array_1 (bool vaargs, tree return_type, int n,
7837 : : tree *arg_types)
7838 : : {
7839 : 117933484 : int i;
7840 : 117933484 : tree t = vaargs ? NULL_TREE : void_list_node;
7841 : :
7842 : 387013071 : for (i = n - 1; i >= 0; i--)
7843 : 269079587 : t = tree_cons (NULL_TREE, arg_types[i], t);
7844 : :
7845 : 117933484 : return build_function_type (return_type, t, vaargs && n == 0);
7846 : : }
7847 : :
7848 : : /* Build a function type. RETURN_TYPE is the type returned by the
7849 : : function. The function takes N named arguments, the types of which
7850 : : are provided in ARG_TYPES. */
7851 : :
7852 : : tree
7853 : 111581251 : build_function_type_array (tree return_type, int n, tree *arg_types)
7854 : : {
7855 : 111581251 : return build_function_type_array_1 (false, return_type, n, arg_types);
7856 : : }
7857 : :
7858 : : /* Build a variable argument function type. RETURN_TYPE is the type
7859 : : returned by the function. The function takes N named arguments, the
7860 : : types of which are provided in ARG_TYPES. */
7861 : :
7862 : : tree
7863 : 6352233 : build_varargs_function_type_array (tree return_type, int n, tree *arg_types)
7864 : : {
7865 : 6352233 : return build_function_type_array_1 (true, return_type, n, arg_types);
7866 : : }
7867 : :
7868 : : /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
7869 : : and ARGTYPES (a TREE_LIST) are the return type and arguments types
7870 : : for the method. An implicit additional parameter (of type
7871 : : pointer-to-BASETYPE) is added to the ARGTYPES. */
7872 : :
7873 : : tree
7874 : 294691078 : build_method_type_directly (tree basetype,
7875 : : tree rettype,
7876 : : tree argtypes)
7877 : : {
7878 : 294691078 : tree t;
7879 : 294691078 : tree ptype;
7880 : 294691078 : bool any_structural_p, any_noncanonical_p;
7881 : 294691078 : tree canon_argtypes;
7882 : :
7883 : : /* Make a node of the sort we want. */
7884 : 294691078 : t = make_node (METHOD_TYPE);
7885 : :
7886 : 294691078 : TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7887 : 294691078 : TREE_TYPE (t) = rettype;
7888 : 294691078 : ptype = build_pointer_type (basetype);
7889 : :
7890 : : /* The actual arglist for this function includes a "hidden" argument
7891 : : which is "this". Put it into the list of argument types. */
7892 : 294691078 : argtypes = tree_cons (NULL_TREE, ptype, argtypes);
7893 : 294691078 : TYPE_ARG_TYPES (t) = argtypes;
7894 : :
7895 : : /* Set up the canonical type. */
7896 : 294691078 : any_structural_p
7897 : 294691078 : = (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7898 : 294691078 : || TYPE_STRUCTURAL_EQUALITY_P (rettype));
7899 : 294691078 : any_noncanonical_p
7900 : 294691078 : = (TYPE_CANONICAL (basetype) != basetype
7901 : 294691078 : || TYPE_CANONICAL (rettype) != rettype);
7902 : 294691078 : canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes),
7903 : : &any_structural_p,
7904 : : &any_noncanonical_p);
7905 : :
7906 : : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7907 : 294691078 : if (any_structural_p)
7908 : 23471677 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7909 : :
7910 : : /* If we already have such a type, use the old one. */
7911 : 294691078 : hashval_t hash = type_hash_canon_hash (t);
7912 : 294691078 : tree probe_type = t;
7913 : 294691078 : t = type_hash_canon (hash, t);
7914 : 294691078 : if (t != probe_type)
7915 : : return t;
7916 : :
7917 : 224415774 : if (any_structural_p)
7918 : 19478011 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7919 : 204937763 : else if (any_noncanonical_p)
7920 : 76595459 : TYPE_CANONICAL (t)
7921 : 153190918 : = build_method_type_directly (TYPE_CANONICAL (basetype),
7922 : 76595459 : TYPE_CANONICAL (rettype),
7923 : : canon_argtypes);
7924 : 224415774 : if (!COMPLETE_TYPE_P (t))
7925 : 0 : layout_type (t);
7926 : :
7927 : : return t;
7928 : : }
7929 : :
7930 : : /* Construct, lay out and return the type of methods belonging to class
7931 : : BASETYPE and whose arguments and values are described by TYPE.
7932 : : If that type exists already, reuse it.
7933 : : TYPE must be a FUNCTION_TYPE node. */
7934 : :
7935 : : tree
7936 : 155 : build_method_type (tree basetype, tree type)
7937 : : {
7938 : 155 : gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
7939 : :
7940 : 155 : return build_method_type_directly (basetype,
7941 : 155 : TREE_TYPE (type),
7942 : 155 : TYPE_ARG_TYPES (type));
7943 : : }
7944 : :
7945 : : /* Construct, lay out and return the type of offsets to a value
7946 : : of type TYPE, within an object of type BASETYPE.
7947 : : If a suitable offset type exists already, reuse it. */
7948 : :
7949 : : tree
7950 : 968528 : build_offset_type (tree basetype, tree type)
7951 : : {
7952 : 968528 : tree t;
7953 : :
7954 : : /* Make a node of the sort we want. */
7955 : 968528 : t = make_node (OFFSET_TYPE);
7956 : :
7957 : 968528 : TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7958 : 968528 : TREE_TYPE (t) = type;
7959 : 968528 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7960 : 968528 : || TYPE_STRUCTURAL_EQUALITY_P (type))
7961 : 4 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7962 : :
7963 : : /* If we already have such a type, use the old one. */
7964 : 968528 : hashval_t hash = type_hash_canon_hash (t);
7965 : 968528 : tree probe_type = t;
7966 : 968528 : t = type_hash_canon (hash, t);
7967 : 968528 : if (t != probe_type)
7968 : : return t;
7969 : :
7970 : 205425 : if (!COMPLETE_TYPE_P (t))
7971 : 0 : layout_type (t);
7972 : :
7973 : 205425 : if (TYPE_CANONICAL (t) == t)
7974 : : {
7975 : 205421 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7976 : 205421 : || TYPE_STRUCTURAL_EQUALITY_P (type))
7977 : 0 : gcc_unreachable ();
7978 : 205421 : else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
7979 : 205421 : || TYPE_CANONICAL (type) != type)
7980 : 119878 : TYPE_CANONICAL (t)
7981 : 239756 : = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
7982 : 119878 : TYPE_CANONICAL (type));
7983 : : }
7984 : :
7985 : : return t;
7986 : : }
7987 : :
7988 : : /* Create a complex type whose components are COMPONENT_TYPE.
7989 : :
7990 : : If NAMED is true, the type is given a TYPE_NAME. We do not always
7991 : : do so because this creates a DECL node and thus make the DECL_UIDs
7992 : : dependent on the type canonicalization hashtable, which is GC-ed,
7993 : : so the DECL_UIDs would not be stable wrt garbage collection. */
7994 : :
7995 : : tree
7996 : 5271579 : build_complex_type (tree component_type, bool named)
7997 : : {
7998 : 5271579 : gcc_assert (INTEGRAL_TYPE_P (component_type)
7999 : : || SCALAR_FLOAT_TYPE_P (component_type)
8000 : : || FIXED_POINT_TYPE_P (component_type));
8001 : :
8002 : : /* Make a node of the sort we want. */
8003 : 5271579 : tree probe = make_node (COMPLEX_TYPE);
8004 : :
8005 : 5271579 : TREE_TYPE (probe) = TYPE_MAIN_VARIANT (component_type);
8006 : 5271579 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (probe)))
8007 : 0 : SET_TYPE_STRUCTURAL_EQUALITY (probe);
8008 : :
8009 : : /* If we already have such a type, use the old one. */
8010 : 5271579 : hashval_t hash = type_hash_canon_hash (probe);
8011 : 5271579 : tree t = type_hash_canon (hash, probe);
8012 : :
8013 : 5271579 : if (t == probe)
8014 : : {
8015 : : /* We created a new type. The hash insertion will have laid
8016 : : out the type. We need to check the canonicalization and
8017 : : maybe set the name. */
8018 : 3144854 : gcc_checking_assert (COMPLETE_TYPE_P (t)
8019 : : && !TYPE_NAME (t));
8020 : :
8021 : 3144854 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t)))
8022 : : ;
8023 : 3144854 : else if (TYPE_CANONICAL (TREE_TYPE (t)) != TREE_TYPE (t))
8024 : 101 : TYPE_CANONICAL (t)
8025 : 202 : = build_complex_type (TYPE_CANONICAL (TREE_TYPE (t)), named);
8026 : :
8027 : : /* We need to create a name, since complex is a fundamental type. */
8028 : 3144854 : if (named)
8029 : : {
8030 : 1158840 : const char *name = NULL;
8031 : :
8032 : 1158840 : if (TREE_TYPE (t) == char_type_node)
8033 : : name = "complex char";
8034 : 1158840 : else if (TREE_TYPE (t) == signed_char_type_node)
8035 : : name = "complex signed char";
8036 : 1158840 : else if (TREE_TYPE (t) == unsigned_char_type_node)
8037 : : name = "complex unsigned char";
8038 : 1158840 : else if (TREE_TYPE (t) == short_integer_type_node)
8039 : : name = "complex short int";
8040 : 1158840 : else if (TREE_TYPE (t) == short_unsigned_type_node)
8041 : : name = "complex short unsigned int";
8042 : 1158840 : else if (TREE_TYPE (t) == integer_type_node)
8043 : : name = "complex int";
8044 : 869130 : else if (TREE_TYPE (t) == unsigned_type_node)
8045 : : name = "complex unsigned int";
8046 : 869130 : else if (TREE_TYPE (t) == long_integer_type_node)
8047 : : name = "complex long int";
8048 : 869130 : else if (TREE_TYPE (t) == long_unsigned_type_node)
8049 : : name = "complex long unsigned int";
8050 : 869130 : else if (TREE_TYPE (t) == long_long_integer_type_node)
8051 : : name = "complex long long int";
8052 : 869130 : else if (TREE_TYPE (t) == long_long_unsigned_type_node)
8053 : : name = "complex long long unsigned int";
8054 : :
8055 : : if (name != NULL)
8056 : 289710 : TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
8057 : : get_identifier (name), t);
8058 : : }
8059 : : }
8060 : :
8061 : 5271579 : return build_qualified_type (t, TYPE_QUALS (component_type));
8062 : : }
8063 : :
8064 : : /* If TYPE is a real or complex floating-point type and the target
8065 : : does not directly support arithmetic on TYPE then return the wider
8066 : : type to be used for arithmetic on TYPE. Otherwise, return
8067 : : NULL_TREE. */
8068 : :
8069 : : tree
8070 : 92120773 : excess_precision_type (tree type)
8071 : : {
8072 : : /* The target can give two different responses to the question of
8073 : : which excess precision mode it would like depending on whether we
8074 : : are in -fexcess-precision=standard or -fexcess-precision=fast. */
8075 : :
8076 : 3314545 : enum excess_precision_type requested_type
8077 : 92120773 : = (flag_excess_precision == EXCESS_PRECISION_FAST
8078 : 92120773 : ? EXCESS_PRECISION_TYPE_FAST
8079 : : : (flag_excess_precision == EXCESS_PRECISION_FLOAT16
8080 : 3314614 : ? EXCESS_PRECISION_TYPE_FLOAT16 : EXCESS_PRECISION_TYPE_STANDARD));
8081 : :
8082 : 92120773 : enum flt_eval_method target_flt_eval_method
8083 : 92120773 : = targetm.c.excess_precision (requested_type);
8084 : :
8085 : : /* The target should not ask for unpredictable float evaluation (though
8086 : : it might advertise that implicitly the evaluation is unpredictable,
8087 : : but we don't care about that here, it will have been reported
8088 : : elsewhere). If it does ask for unpredictable evaluation, we have
8089 : : nothing to do here. */
8090 : 92120773 : gcc_assert (target_flt_eval_method != FLT_EVAL_METHOD_UNPREDICTABLE);
8091 : :
8092 : : /* Nothing to do. The target has asked for all types we know about
8093 : : to be computed with their native precision and range. */
8094 : 92120773 : if (target_flt_eval_method == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
8095 : : return NULL_TREE;
8096 : :
8097 : : /* The target will promote this type in a target-dependent way, so excess
8098 : : precision ought to leave it alone. */
8099 : 90514939 : if (targetm.promoted_type (type) != NULL_TREE)
8100 : : return NULL_TREE;
8101 : :
8102 : 90514939 : machine_mode float16_type_mode = (float16_type_node
8103 : 90514939 : ? TYPE_MODE (float16_type_node)
8104 : 90514939 : : VOIDmode);
8105 : 90514939 : machine_mode bfloat16_type_mode = (bfloat16_type_node
8106 : 90514939 : ? TYPE_MODE (bfloat16_type_node)
8107 : 90514939 : : VOIDmode);
8108 : 90514939 : machine_mode float_type_mode = TYPE_MODE (float_type_node);
8109 : 90514939 : machine_mode double_type_mode = TYPE_MODE (double_type_node);
8110 : :
8111 : 90514939 : switch (TREE_CODE (type))
8112 : : {
8113 : 62981938 : case REAL_TYPE:
8114 : 62981938 : {
8115 : 62981938 : machine_mode type_mode = TYPE_MODE (type);
8116 : 62981938 : switch (target_flt_eval_method)
8117 : : {
8118 : 62969105 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8119 : 62969105 : if (type_mode == float16_type_mode
8120 : 62969105 : || type_mode == bfloat16_type_mode)
8121 : 310584 : return float_type_node;
8122 : : break;
8123 : 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8124 : 0 : if (type_mode == float16_type_mode
8125 : 0 : || type_mode == bfloat16_type_mode
8126 : 0 : || type_mode == float_type_mode)
8127 : 0 : return double_type_node;
8128 : : break;
8129 : 12833 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8130 : 12833 : if (type_mode == float16_type_mode
8131 : 12833 : || type_mode == bfloat16_type_mode
8132 : 12828 : || type_mode == float_type_mode
8133 : 12828 : || type_mode == double_type_mode)
8134 : 12384 : return long_double_type_node;
8135 : : break;
8136 : 0 : default:
8137 : 0 : gcc_unreachable ();
8138 : : }
8139 : : break;
8140 : : }
8141 : 389872 : case COMPLEX_TYPE:
8142 : 389872 : {
8143 : 389872 : if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
8144 : : return NULL_TREE;
8145 : 380392 : machine_mode type_mode = TYPE_MODE (TREE_TYPE (type));
8146 : 380392 : switch (target_flt_eval_method)
8147 : : {
8148 : 380059 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8149 : 380059 : if (type_mode == float16_type_mode
8150 : 380059 : || type_mode == bfloat16_type_mode)
8151 : 271 : return complex_float_type_node;
8152 : : break;
8153 : 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8154 : 0 : if (type_mode == float16_type_mode
8155 : 0 : || type_mode == bfloat16_type_mode
8156 : 0 : || type_mode == float_type_mode)
8157 : 0 : return complex_double_type_node;
8158 : : break;
8159 : 333 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8160 : 333 : if (type_mode == float16_type_mode
8161 : 333 : || type_mode == bfloat16_type_mode
8162 : 333 : || type_mode == float_type_mode
8163 : 333 : || type_mode == double_type_mode)
8164 : 281 : return complex_long_double_type_node;
8165 : : break;
8166 : 0 : default:
8167 : 0 : gcc_unreachable ();
8168 : : }
8169 : : break;
8170 : : }
8171 : : default:
8172 : : break;
8173 : : }
8174 : :
8175 : : return NULL_TREE;
8176 : : }
8177 : :
8178 : : /* Return OP, stripped of any conversions to wider types as much as is safe.
8179 : : Converting the value back to OP's type makes a value equivalent to OP.
8180 : :
8181 : : If FOR_TYPE is nonzero, we return a value which, if converted to
8182 : : type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8183 : :
8184 : : OP must have integer, real or enumeral type. Pointers are not allowed!
8185 : :
8186 : : There are some cases where the obvious value we could return
8187 : : would regenerate to OP if converted to OP's type,
8188 : : but would not extend like OP to wider types.
8189 : : If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8190 : : For example, if OP is (unsigned short)(signed char)-1,
8191 : : we avoid returning (signed char)-1 if FOR_TYPE is int,
8192 : : even though extending that to an unsigned short would regenerate OP,
8193 : : since the result of extending (signed char)-1 to (int)
8194 : : is different from (int) OP. */
8195 : :
8196 : : tree
8197 : 10611701 : get_unwidened (tree op, tree for_type)
8198 : : {
8199 : : /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8200 : 10611701 : tree type = TREE_TYPE (op);
8201 : 10611701 : unsigned final_prec
8202 : 18244345 : = TYPE_PRECISION (for_type != 0 ? for_type : type);
8203 : 10611701 : int uns
8204 : 10611701 : = (for_type != 0 && for_type != type
8205 : 2648745 : && final_prec > TYPE_PRECISION (type)
8206 : 10709876 : && TYPE_UNSIGNED (type));
8207 : 10611701 : tree win = op;
8208 : :
8209 : 10826869 : while (CONVERT_EXPR_P (op))
8210 : : {
8211 : 215197 : int bitschange;
8212 : :
8213 : : /* TYPE_PRECISION on vector types has different meaning
8214 : : (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8215 : : so avoid them here. */
8216 : 215197 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
8217 : : break;
8218 : :
8219 : 215197 : bitschange = TYPE_PRECISION (TREE_TYPE (op))
8220 : 215197 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
8221 : :
8222 : : /* Truncations are many-one so cannot be removed.
8223 : : Unless we are later going to truncate down even farther. */
8224 : 215197 : if (bitschange < 0
8225 : 215197 : && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
8226 : : break;
8227 : :
8228 : : /* See what's inside this conversion. If we decide to strip it,
8229 : : we will set WIN. */
8230 : 215168 : op = TREE_OPERAND (op, 0);
8231 : :
8232 : : /* If we have not stripped any zero-extensions (uns is 0),
8233 : : we can strip any kind of extension.
8234 : : If we have previously stripped a zero-extension,
8235 : : only zero-extensions can safely be stripped.
8236 : : Any extension can be stripped if the bits it would produce
8237 : : are all going to be discarded later by truncating to FOR_TYPE. */
8238 : :
8239 : 215168 : if (bitschange > 0)
8240 : : {
8241 : 121064 : if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
8242 : : win = op;
8243 : : /* TYPE_UNSIGNED says whether this is a zero-extension.
8244 : : Let's avoid computing it if it does not affect WIN
8245 : : and if UNS will not be needed again. */
8246 : 121064 : if ((uns
8247 : 121033 : || CONVERT_EXPR_P (op))
8248 : 121605 : && TYPE_UNSIGNED (TREE_TYPE (op)))
8249 : : {
8250 : : uns = 1;
8251 : : win = op;
8252 : : }
8253 : : }
8254 : : }
8255 : :
8256 : : /* If we finally reach a constant see if it fits in sth smaller and
8257 : : in that case convert it. */
8258 : 10611701 : if (TREE_CODE (win) == INTEGER_CST)
8259 : : {
8260 : 454258 : tree wtype = TREE_TYPE (win);
8261 : 454258 : unsigned prec = wi::min_precision (wi::to_wide (win), TYPE_SIGN (wtype));
8262 : 454258 : if (for_type)
8263 : 449272 : prec = MAX (prec, final_prec);
8264 : 454258 : if (prec < TYPE_PRECISION (wtype))
8265 : : {
8266 : 447673 : tree t = lang_hooks.types.type_for_size (prec, TYPE_UNSIGNED (wtype));
8267 : 447673 : if (t && TYPE_PRECISION (t) < TYPE_PRECISION (wtype))
8268 : 441542 : win = fold_convert (t, win);
8269 : : }
8270 : : }
8271 : :
8272 : 10611701 : return win;
8273 : : }
8274 : :
8275 : : /* Return OP or a simpler expression for a narrower value
8276 : : which can be sign-extended or zero-extended to give back OP.
8277 : : Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8278 : : or 0 if the value should be sign-extended. */
8279 : :
8280 : : tree
8281 : 68761289 : get_narrower (tree op, int *unsignedp_ptr)
8282 : : {
8283 : 68761289 : int uns = 0;
8284 : 68761289 : bool first = true;
8285 : 68761289 : tree win = op;
8286 : 68761289 : bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
8287 : :
8288 : 68761289 : if (TREE_CODE (op) == COMPOUND_EXPR)
8289 : : {
8290 : 87845 : do
8291 : 87845 : op = TREE_OPERAND (op, 1);
8292 : 87845 : while (TREE_CODE (op) == COMPOUND_EXPR);
8293 : 87830 : tree ret = get_narrower (op, unsignedp_ptr);
8294 : 87830 : if (ret == op)
8295 : : return win;
8296 : 4262 : auto_vec <tree, 16> v;
8297 : 4262 : unsigned int i;
8298 : 8531 : for (op = win; TREE_CODE (op) == COMPOUND_EXPR;
8299 : 4269 : op = TREE_OPERAND (op, 1))
8300 : 4269 : v.safe_push (op);
8301 : 12793 : FOR_EACH_VEC_ELT_REVERSE (v, i, op)
8302 : 4269 : ret = build2_loc (EXPR_LOCATION (op), COMPOUND_EXPR,
8303 : 4269 : TREE_TYPE (ret), TREE_OPERAND (op, 0),
8304 : : ret);
8305 : 4262 : return ret;
8306 : 4262 : }
8307 : 81947862 : while (TREE_CODE (op) == NOP_EXPR)
8308 : : {
8309 : 13308514 : int bitschange
8310 : 13308514 : = (TYPE_PRECISION (TREE_TYPE (op))
8311 : 13308514 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
8312 : :
8313 : : /* Truncations are many-one so cannot be removed. */
8314 : 13308514 : if (bitschange < 0)
8315 : : break;
8316 : :
8317 : : /* See what's inside this conversion. If we decide to strip it,
8318 : : we will set WIN. */
8319 : :
8320 : 13274499 : if (bitschange > 0)
8321 : : {
8322 : 3254489 : op = TREE_OPERAND (op, 0);
8323 : : /* An extension: the outermost one can be stripped,
8324 : : but remember whether it is zero or sign extension. */
8325 : 3254489 : if (first)
8326 : 3249760 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8327 : : /* Otherwise, if a sign extension has been stripped,
8328 : : only sign extensions can now be stripped;
8329 : : if a zero extension has been stripped, only zero-extensions. */
8330 : 4729 : else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
8331 : : break;
8332 : : first = false;
8333 : : }
8334 : : else /* bitschange == 0 */
8335 : : {
8336 : : /* A change in nominal type can always be stripped, but we must
8337 : : preserve the unsignedness. */
8338 : 10020010 : if (first)
8339 : 9459965 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8340 : 10020010 : first = false;
8341 : 10020010 : op = TREE_OPERAND (op, 0);
8342 : : /* Keep trying to narrow, but don't assign op to win if it
8343 : : would turn an integral type into something else. */
8344 : 18242835 : if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
8345 : 103126 : continue;
8346 : : }
8347 : :
8348 : 13171277 : win = op;
8349 : : }
8350 : :
8351 : 68673459 : if (TREE_CODE (op) == COMPONENT_REF
8352 : : /* Since type_for_size always gives an integer type. */
8353 : 2537624 : && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
8354 : 2434208 : && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE
8355 : : /* Ensure field is laid out already. */
8356 : 2434208 : && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
8357 : 71107664 : && tree_fits_uhwi_p (DECL_SIZE (TREE_OPERAND (op, 1))))
8358 : : {
8359 : 2434205 : unsigned HOST_WIDE_INT innerprec
8360 : 2434205 : = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (op, 1)));
8361 : 2434205 : int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
8362 : 2434205 : || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
8363 : 2434205 : tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
8364 : :
8365 : : /* We can get this structure field in a narrower type that fits it,
8366 : : but the resulting extension to its nominal type (a fullword type)
8367 : : must satisfy the same conditions as for other extensions.
8368 : :
8369 : : Do this only for fields that are aligned (not bit-fields),
8370 : : because when bit-field insns will be used there is no
8371 : : advantage in doing this. */
8372 : :
8373 : 2434205 : if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
8374 : 0 : && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
8375 : 0 : && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
8376 : 2434205 : && type != 0)
8377 : : {
8378 : 0 : if (first)
8379 : 0 : uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
8380 : 0 : win = fold_convert (type, op);
8381 : : }
8382 : : }
8383 : :
8384 : 68673459 : *unsignedp_ptr = uns;
8385 : 68673459 : return win;
8386 : : }
8387 : :
8388 : : /* Return true if integer constant C has a value that is permissible
8389 : : for TYPE, an integral type. */
8390 : :
8391 : : bool
8392 : 124988836 : int_fits_type_p (const_tree c, const_tree type)
8393 : : {
8394 : 124988836 : tree type_low_bound, type_high_bound;
8395 : 124988836 : bool ok_for_low_bound, ok_for_high_bound;
8396 : 124988836 : signop sgn_c = TYPE_SIGN (TREE_TYPE (c));
8397 : :
8398 : : /* Non-standard boolean types can have arbitrary precision but various
8399 : : transformations assume that they can only take values 0 and +/-1. */
8400 : 124988836 : if (TREE_CODE (type) == BOOLEAN_TYPE)
8401 : 1099724 : return wi::fits_to_boolean_p (wi::to_wide (c), type);
8402 : :
8403 : 123889112 : retry:
8404 : 123900947 : type_low_bound = TYPE_MIN_VALUE (type);
8405 : 123900947 : type_high_bound = TYPE_MAX_VALUE (type);
8406 : :
8407 : : /* If at least one bound of the type is a constant integer, we can check
8408 : : ourselves and maybe make a decision. If no such decision is possible, but
8409 : : this type is a subtype, try checking against that. Otherwise, use
8410 : : fits_to_tree_p, which checks against the precision.
8411 : :
8412 : : Compute the status for each possibly constant bound, and return if we see
8413 : : one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8414 : : for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8415 : : for "constant known to fit". */
8416 : :
8417 : : /* Check if c >= type_low_bound. */
8418 : 123900947 : if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
8419 : : {
8420 : 123900947 : if (tree_int_cst_lt (c, type_low_bound))
8421 : : return false;
8422 : : ok_for_low_bound = true;
8423 : : }
8424 : : else
8425 : : ok_for_low_bound = false;
8426 : :
8427 : : /* Check if c <= type_high_bound. */
8428 : 123656549 : if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
8429 : : {
8430 : 123625062 : if (tree_int_cst_lt (type_high_bound, c))
8431 : : return false;
8432 : : ok_for_high_bound = true;
8433 : : }
8434 : : else
8435 : : ok_for_high_bound = false;
8436 : :
8437 : : /* If the constant fits both bounds, the result is known. */
8438 : 121845935 : if (ok_for_low_bound && ok_for_high_bound)
8439 : : return true;
8440 : :
8441 : : /* Perform some generic filtering which may allow making a decision
8442 : : even if the bounds are not constant. First, negative integers
8443 : : never fit in unsigned types, */
8444 : 31487 : if (TYPE_UNSIGNED (type) && sgn_c == SIGNED && wi::neg_p (wi::to_wide (c)))
8445 : 0 : return false;
8446 : :
8447 : : /* Second, narrower types always fit in wider ones. */
8448 : 31487 : if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
8449 : : return true;
8450 : :
8451 : : /* Third, unsigned integers with top bit set never fit signed types. */
8452 : 11844 : if (!TYPE_UNSIGNED (type) && sgn_c == UNSIGNED)
8453 : : {
8454 : 14 : int prec = GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (c))) - 1;
8455 : 14 : if (prec < TYPE_PRECISION (TREE_TYPE (c)))
8456 : : {
8457 : : /* When a tree_cst is converted to a wide-int, the precision
8458 : : is taken from the type. However, if the precision of the
8459 : : mode underneath the type is smaller than that, it is
8460 : : possible that the value will not fit. The test below
8461 : : fails if any bit is set between the sign bit of the
8462 : : underlying mode and the top bit of the type. */
8463 : 14 : if (wi::zext (wi::to_wide (c), prec - 1) != wi::to_wide (c))
8464 : : return false;
8465 : : }
8466 : 0 : else if (wi::neg_p (wi::to_wide (c)))
8467 : : return false;
8468 : : }
8469 : :
8470 : : /* If we haven't been able to decide at this point, there nothing more we
8471 : : can check ourselves here. Look at the base type if we have one and it
8472 : : has the same precision. */
8473 : 11835 : if (TREE_CODE (type) == INTEGER_TYPE
8474 : 11835 : && TREE_TYPE (type) != 0
8475 : 23670 : && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
8476 : : {
8477 : 11835 : type = TREE_TYPE (type);
8478 : 11835 : goto retry;
8479 : : }
8480 : :
8481 : : /* Or to fits_to_tree_p, if nothing else. */
8482 : 0 : return wi::fits_to_tree_p (wi::to_wide (c), type);
8483 : : }
8484 : :
8485 : : /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8486 : : bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8487 : : represented (assuming two's-complement arithmetic) within the bit
8488 : : precision of the type are returned instead. */
8489 : :
8490 : : void
8491 : 21675241 : get_type_static_bounds (const_tree type, mpz_t min, mpz_t max)
8492 : : {
8493 : 20164064 : if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type)
8494 : 41839305 : && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
8495 : 20164064 : wi::to_mpz (wi::to_wide (TYPE_MIN_VALUE (type)), min, TYPE_SIGN (type));
8496 : : else
8497 : : {
8498 : 1511177 : if (TYPE_UNSIGNED (type))
8499 : 1511177 : mpz_set_ui (min, 0);
8500 : : else
8501 : : {
8502 : 0 : wide_int mn = wi::min_value (TYPE_PRECISION (type), SIGNED);
8503 : 0 : wi::to_mpz (mn, min, SIGNED);
8504 : 0 : }
8505 : : }
8506 : :
8507 : 20164064 : if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
8508 : 41839305 : && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
8509 : 20164064 : wi::to_mpz (wi::to_wide (TYPE_MAX_VALUE (type)), max, TYPE_SIGN (type));
8510 : : else
8511 : : {
8512 : 1511177 : wide_int mn = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
8513 : 1511177 : wi::to_mpz (mn, max, TYPE_SIGN (type));
8514 : 1511177 : }
8515 : 21675241 : }
8516 : :
8517 : : /* Return true if VAR is an automatic variable. */
8518 : :
8519 : : bool
8520 : 381829698 : auto_var_p (const_tree var)
8521 : : {
8522 : 212729996 : return ((((VAR_P (var) && ! DECL_EXTERNAL (var))
8523 : 172452663 : || TREE_CODE (var) == PARM_DECL)
8524 : 272897521 : && ! TREE_STATIC (var))
8525 : 499358756 : || TREE_CODE (var) == RESULT_DECL);
8526 : : }
8527 : :
8528 : : /* Return true if VAR is an automatic variable defined in function FN. */
8529 : :
8530 : : bool
8531 : 1141544416 : auto_var_in_fn_p (const_tree var, const_tree fn)
8532 : : {
8533 : 357842071 : return (DECL_P (var) && DECL_CONTEXT (var) == fn
8534 : 1396340482 : && (auto_var_p (var)
8535 : 4363330 : || TREE_CODE (var) == LABEL_DECL));
8536 : : }
8537 : :
8538 : : /* Subprogram of following function. Called by walk_tree.
8539 : :
8540 : : Return *TP if it is an automatic variable or parameter of the
8541 : : function passed in as DATA. */
8542 : :
8543 : : static tree
8544 : 124308 : find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
8545 : : {
8546 : 124308 : tree fn = (tree) data;
8547 : :
8548 : 124308 : if (TYPE_P (*tp))
8549 : 0 : *walk_subtrees = 0;
8550 : :
8551 : 124308 : else if (DECL_P (*tp)
8552 : 124308 : && auto_var_in_fn_p (*tp, fn))
8553 : 115492 : return *tp;
8554 : :
8555 : : return NULL_TREE;
8556 : : }
8557 : :
8558 : : /* Returns true if T is, contains, or refers to a type with variable
8559 : : size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8560 : : arguments, but not the return type. If FN is nonzero, only return
8561 : : true if a modifier of the type or position of FN is a variable or
8562 : : parameter inside FN.
8563 : :
8564 : : This concept is more general than that of C99 'variably modified types':
8565 : : in C99, a struct type is never variably modified because a VLA may not
8566 : : appear as a structure member. However, in GNU C code like:
8567 : :
8568 : : struct S { int i[f()]; };
8569 : :
8570 : : is valid, and other languages may define similar constructs. */
8571 : :
8572 : : bool
8573 : 1909318071 : variably_modified_type_p (tree type, tree fn)
8574 : : {
8575 : 1909318071 : tree t;
8576 : :
8577 : : /* Test if T is either variable (if FN is zero) or an expression containing
8578 : : a variable in FN. If TYPE isn't gimplified, return true also if
8579 : : gimplify_one_sizepos would gimplify the expression into a local
8580 : : variable. */
8581 : : #define RETURN_TRUE_IF_VAR(T) \
8582 : : do { tree _t = (T); \
8583 : : if (_t != NULL_TREE \
8584 : : && _t != error_mark_node \
8585 : : && !CONSTANT_CLASS_P (_t) \
8586 : : && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8587 : : && (!fn \
8588 : : || (!TYPE_SIZES_GIMPLIFIED (type) \
8589 : : && (TREE_CODE (_t) != VAR_DECL \
8590 : : && !CONTAINS_PLACEHOLDER_P (_t))) \
8591 : : || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8592 : : return true; } while (0)
8593 : :
8594 : 1909318071 : if (type == error_mark_node)
8595 : : return false;
8596 : :
8597 : : /* If TYPE itself has variable size, it is variably modified. */
8598 : 1908989112 : RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
8599 : 1908864211 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
8600 : :
8601 : 1908863587 : switch (TREE_CODE (type))
8602 : : {
8603 : 525305707 : case POINTER_TYPE:
8604 : 525305707 : case REFERENCE_TYPE:
8605 : 525305707 : case VECTOR_TYPE:
8606 : : /* Ada can have pointer types refering to themselves indirectly. */
8607 : 525305707 : if (TREE_VISITED (type))
8608 : : return false;
8609 : 525305707 : TREE_VISITED (type) = true;
8610 : 525305707 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8611 : : {
8612 : 78717 : TREE_VISITED (type) = false;
8613 : 78717 : return true;
8614 : : }
8615 : 525226990 : TREE_VISITED (type) = false;
8616 : 525226990 : break;
8617 : :
8618 : 94967130 : case FUNCTION_TYPE:
8619 : 94967130 : case METHOD_TYPE:
8620 : : /* If TYPE is a function type, it is variably modified if the
8621 : : return type is variably modified. */
8622 : 94967130 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8623 : : return true;
8624 : : break;
8625 : :
8626 : 462214994 : case INTEGER_TYPE:
8627 : 462214994 : case REAL_TYPE:
8628 : 462214994 : case FIXED_POINT_TYPE:
8629 : 462214994 : case ENUMERAL_TYPE:
8630 : 462214994 : case BOOLEAN_TYPE:
8631 : : /* Scalar types are variably modified if their end points
8632 : : aren't constant. */
8633 : 462214994 : RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
8634 : 462214994 : RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
8635 : 462180422 : break;
8636 : :
8637 : 677575666 : case RECORD_TYPE:
8638 : 677575666 : case UNION_TYPE:
8639 : 677575666 : case QUAL_UNION_TYPE:
8640 : : /* We can't see if any of the fields are variably-modified by the
8641 : : definition we normally use, since that would produce infinite
8642 : : recursion via pointers. */
8643 : : /* This is variably modified if some field's type is. */
8644 : 31019934088 : for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
8645 : 30342358422 : if (TREE_CODE (t) == FIELD_DECL)
8646 : : {
8647 : 1030093021 : RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
8648 : 1030093021 : RETURN_TRUE_IF_VAR (DECL_SIZE (t));
8649 : 1030093021 : RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
8650 : :
8651 : : /* If the type is a qualified union, then the DECL_QUALIFIER
8652 : : of fields can also be an expression containing a variable. */
8653 : 1030093021 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
8654 : 0 : RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
8655 : :
8656 : : /* If the field is a qualified union, then it's only a container
8657 : : for what's inside so we look into it. That's necessary in LTO
8658 : : mode because the sizes of the field tested above have been set
8659 : : to PLACEHOLDER_EXPRs by free_lang_data. */
8660 : 1030093021 : if (TREE_CODE (TREE_TYPE (t)) == QUAL_UNION_TYPE
8661 : 1030093021 : && variably_modified_type_p (TREE_TYPE (t), fn))
8662 : : return true;
8663 : : }
8664 : : break;
8665 : :
8666 : 11512843 : case ARRAY_TYPE:
8667 : : /* Do not call ourselves to avoid infinite recursion. This is
8668 : : variably modified if the element type is. */
8669 : 11512843 : RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
8670 : 11509294 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
8671 : 11509268 : break;
8672 : :
8673 : : default:
8674 : : break;
8675 : : }
8676 : :
8677 : : /* The current language may have other cases to check, but in general,
8678 : : all other types are not variably modified. */
8679 : 1908746493 : return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
8680 : :
8681 : : #undef RETURN_TRUE_IF_VAR
8682 : : }
8683 : :
8684 : : /* Given a DECL or TYPE, return the scope in which it was declared, or
8685 : : NULL_TREE if there is no containing scope. */
8686 : :
8687 : : tree
8688 : 2512703625 : get_containing_scope (const_tree t)
8689 : : {
8690 : 2512703625 : return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
8691 : : }
8692 : :
8693 : : /* Returns the ultimate TRANSLATION_UNIT_DECL context of DECL or NULL. */
8694 : :
8695 : : const_tree
8696 : 13409 : get_ultimate_context (const_tree decl)
8697 : : {
8698 : 35978 : while (decl && TREE_CODE (decl) != TRANSLATION_UNIT_DECL)
8699 : : {
8700 : 22569 : if (TREE_CODE (decl) == BLOCK)
8701 : 0 : decl = BLOCK_SUPERCONTEXT (decl);
8702 : : else
8703 : 22569 : decl = get_containing_scope (decl);
8704 : : }
8705 : 13409 : return decl;
8706 : : }
8707 : :
8708 : : /* Return the innermost context enclosing DECL that is
8709 : : a FUNCTION_DECL, or zero if none. */
8710 : :
8711 : : tree
8712 : 1345657390 : decl_function_context (const_tree decl)
8713 : : {
8714 : 1345657390 : tree context;
8715 : :
8716 : 1345657390 : if (TREE_CODE (decl) == ERROR_MARK)
8717 : : return 0;
8718 : :
8719 : : /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8720 : : where we look up the function at runtime. Such functions always take
8721 : : a first argument of type 'pointer to real context'.
8722 : :
8723 : : C++ should really be fixed to use DECL_CONTEXT for the real context,
8724 : : and use something else for the "virtual context". */
8725 : 1345657390 : else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
8726 : 4431543 : context
8727 : 4431543 : = TYPE_MAIN_VARIANT
8728 : : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
8729 : : else
8730 : 1341225847 : context = DECL_CONTEXT (decl);
8731 : :
8732 : 3112224454 : while (context && TREE_CODE (context) != FUNCTION_DECL)
8733 : : {
8734 : 1766567064 : if (TREE_CODE (context) == BLOCK)
8735 : 0 : context = BLOCK_SUPERCONTEXT (context);
8736 : : else
8737 : 1766567064 : context = get_containing_scope (context);
8738 : : }
8739 : :
8740 : : return context;
8741 : : }
8742 : :
8743 : : /* Return the innermost context enclosing DECL that is
8744 : : a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8745 : : TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8746 : :
8747 : : tree
8748 : 73753705 : decl_type_context (const_tree decl)
8749 : : {
8750 : 73753705 : tree context = DECL_CONTEXT (decl);
8751 : :
8752 : 76471403 : while (context)
8753 : 70811786 : switch (TREE_CODE (context))
8754 : : {
8755 : : case NAMESPACE_DECL:
8756 : : case TRANSLATION_UNIT_DECL:
8757 : : return NULL_TREE;
8758 : :
8759 : : case RECORD_TYPE:
8760 : : case UNION_TYPE:
8761 : : case QUAL_UNION_TYPE:
8762 : : return context;
8763 : :
8764 : 2717698 : case TYPE_DECL:
8765 : 2717698 : case FUNCTION_DECL:
8766 : 2717698 : context = DECL_CONTEXT (context);
8767 : 2717698 : break;
8768 : :
8769 : 0 : case BLOCK:
8770 : 0 : context = BLOCK_SUPERCONTEXT (context);
8771 : 0 : break;
8772 : :
8773 : 0 : default:
8774 : 0 : gcc_unreachable ();
8775 : : }
8776 : :
8777 : : return NULL_TREE;
8778 : : }
8779 : :
8780 : : /* CALL is a CALL_EXPR. Return the declaration for the function
8781 : : called, or NULL_TREE if the called function cannot be
8782 : : determined. */
8783 : :
8784 : : tree
8785 : 1010462702 : get_callee_fndecl (const_tree call)
8786 : : {
8787 : 1010462702 : tree addr;
8788 : :
8789 : 1010462702 : if (call == error_mark_node)
8790 : : return error_mark_node;
8791 : :
8792 : : /* It's invalid to call this function with anything but a
8793 : : CALL_EXPR. */
8794 : 1010462702 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8795 : :
8796 : : /* The first operand to the CALL is the address of the function
8797 : : called. */
8798 : 1010462702 : addr = CALL_EXPR_FN (call);
8799 : :
8800 : : /* If there is no function, return early. */
8801 : 1010462702 : if (addr == NULL_TREE)
8802 : : return NULL_TREE;
8803 : :
8804 : 1008208067 : STRIP_NOPS (addr);
8805 : :
8806 : : /* If this is a readonly function pointer, extract its initial value. */
8807 : 17148354 : if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
8808 : 1749951 : && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
8809 : 1008399360 : && DECL_INITIAL (addr))
8810 : 191198 : addr = DECL_INITIAL (addr);
8811 : :
8812 : : /* If the address is just `&f' for some function `f', then we know
8813 : : that `f' is being called. */
8814 : 1008208067 : if (TREE_CODE (addr) == ADDR_EXPR
8815 : 1008208067 : && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
8816 : 963178469 : return TREE_OPERAND (addr, 0);
8817 : :
8818 : : /* We couldn't figure out what was being called. */
8819 : : return NULL_TREE;
8820 : : }
8821 : :
8822 : : /* Return true when STMTs arguments and return value match those of FNDECL,
8823 : : a decl of a builtin function. */
8824 : :
8825 : : static bool
8826 : 5505221 : tree_builtin_call_types_compatible_p (const_tree call, tree fndecl)
8827 : : {
8828 : 5505221 : gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN);
8829 : :
8830 : 5505221 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
8831 : 5505221 : if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
8832 : 5505221 : fndecl = decl;
8833 : :
8834 : 5505221 : bool gimple_form = (cfun && (cfun->curr_properties & PROP_gimple)) != 0;
8835 : 5505221 : if (gimple_form
8836 : 13057 : ? !useless_type_conversion_p (TREE_TYPE (call),
8837 : 13057 : TREE_TYPE (TREE_TYPE (fndecl)))
8838 : 5492164 : : (TYPE_MAIN_VARIANT (TREE_TYPE (call))
8839 : 5492164 : != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))))
8840 : : return false;
8841 : :
8842 : 5505005 : tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
8843 : 5505005 : unsigned nargs = call_expr_nargs (call);
8844 : 14497917 : for (unsigned i = 0; i < nargs; ++i, targs = TREE_CHAIN (targs))
8845 : : {
8846 : : /* Variadic args follow. */
8847 : 10044689 : if (!targs)
8848 : : return true;
8849 : 8993569 : tree arg = CALL_EXPR_ARG (call, i);
8850 : 8993569 : tree type = TREE_VALUE (targs);
8851 : 8993569 : if (gimple_form
8852 : 8993569 : ? !useless_type_conversion_p (type, TREE_TYPE (arg))
8853 : 8980512 : : TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (TREE_TYPE (arg)))
8854 : : {
8855 : : /* For pointer arguments be more forgiving, e.g. due to
8856 : : FILE * vs. fileptr_type_node, or say char * vs. const char *
8857 : : differences etc. */
8858 : 1115933 : if (!gimple_form
8859 : 558295 : && POINTER_TYPE_P (type)
8860 : 557743 : && POINTER_TYPE_P (TREE_TYPE (arg))
8861 : 1115933 : && tree_nop_conversion_p (type, TREE_TYPE (arg)))
8862 : 557638 : continue;
8863 : 657 : return false;
8864 : : }
8865 : : }
8866 : 8905809 : if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
8867 : : return false;
8868 : : return true;
8869 : : }
8870 : :
8871 : : /* If CALL_EXPR CALL calls a normal built-in function or an internal function,
8872 : : return the associated function code, otherwise return CFN_LAST. */
8873 : :
8874 : : combined_fn
8875 : 40152355 : get_call_combined_fn (const_tree call)
8876 : : {
8877 : : /* It's invalid to call this function with anything but a CALL_EXPR. */
8878 : 40152355 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8879 : :
8880 : 40152355 : if (!CALL_EXPR_FN (call))
8881 : 65127 : return as_combined_fn (CALL_EXPR_IFN (call));
8882 : :
8883 : 40087228 : tree fndecl = get_callee_fndecl (call);
8884 : 40087228 : if (fndecl
8885 : 40066474 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
8886 : 45592449 : && tree_builtin_call_types_compatible_p (call, fndecl))
8887 : 5504343 : return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
8888 : :
8889 : : return CFN_LAST;
8890 : : }
8891 : :
8892 : : /* Comparator of indices based on tree_node_counts. */
8893 : :
8894 : : static int
8895 : 0 : tree_nodes_cmp (const void *p1, const void *p2)
8896 : : {
8897 : 0 : const unsigned *n1 = (const unsigned *)p1;
8898 : 0 : const unsigned *n2 = (const unsigned *)p2;
8899 : :
8900 : 0 : return tree_node_counts[*n1] - tree_node_counts[*n2];
8901 : : }
8902 : :
8903 : : /* Comparator of indices based on tree_code_counts. */
8904 : :
8905 : : static int
8906 : 0 : tree_codes_cmp (const void *p1, const void *p2)
8907 : : {
8908 : 0 : const unsigned *n1 = (const unsigned *)p1;
8909 : 0 : const unsigned *n2 = (const unsigned *)p2;
8910 : :
8911 : 0 : return tree_code_counts[*n1] - tree_code_counts[*n2];
8912 : : }
8913 : :
8914 : : #define TREE_MEM_USAGE_SPACES 40
8915 : :
8916 : : /* Print debugging information about tree nodes generated during the compile,
8917 : : and any language-specific information. */
8918 : :
8919 : : void
8920 : 0 : dump_tree_statistics (void)
8921 : : {
8922 : 0 : if (GATHER_STATISTICS)
8923 : : {
8924 : : uint64_t total_nodes, total_bytes;
8925 : : fprintf (stderr, "\nKind Nodes Bytes\n");
8926 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8927 : : total_nodes = total_bytes = 0;
8928 : :
8929 : : {
8930 : : auto_vec<unsigned> indices (all_kinds);
8931 : : for (unsigned i = 0; i < all_kinds; i++)
8932 : : indices.quick_push (i);
8933 : : indices.qsort (tree_nodes_cmp);
8934 : :
8935 : : for (unsigned i = 0; i < (int) all_kinds; i++)
8936 : : {
8937 : : unsigned j = indices[i];
8938 : : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n",
8939 : : tree_node_kind_names[j], SIZE_AMOUNT (tree_node_counts[j]),
8940 : : SIZE_AMOUNT (tree_node_sizes[j]));
8941 : : total_nodes += tree_node_counts[j];
8942 : : total_bytes += tree_node_sizes[j];
8943 : : }
8944 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8945 : : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n", "Total",
8946 : : SIZE_AMOUNT (total_nodes), SIZE_AMOUNT (total_bytes));
8947 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8948 : : }
8949 : :
8950 : : {
8951 : : fprintf (stderr, "Code Nodes\n");
8952 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8953 : :
8954 : : auto_vec<unsigned> indices (MAX_TREE_CODES);
8955 : : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8956 : : indices.quick_push (i);
8957 : : indices.qsort (tree_codes_cmp);
8958 : :
8959 : : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8960 : : {
8961 : : unsigned j = indices[i];
8962 : : fprintf (stderr, "%-32s %6" PRIu64 "%c\n",
8963 : : get_tree_code_name ((enum tree_code) j),
8964 : : SIZE_AMOUNT (tree_code_counts[j]));
8965 : : }
8966 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8967 : : fprintf (stderr, "\n");
8968 : : ssanames_print_statistics ();
8969 : : fprintf (stderr, "\n");
8970 : : phinodes_print_statistics ();
8971 : : fprintf (stderr, "\n");
8972 : : }
8973 : : }
8974 : : else
8975 : 0 : fprintf (stderr, "(No per-node statistics)\n");
8976 : :
8977 : 0 : print_type_hash_statistics ();
8978 : 0 : print_debug_expr_statistics ();
8979 : 0 : print_value_expr_statistics ();
8980 : 0 : lang_hooks.print_statistics ();
8981 : 0 : }
8982 : :
8983 : : #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
8984 : :
8985 : : /* Generate a crc32 of the low BYTES bytes of VALUE. */
8986 : :
8987 : : unsigned
8988 : 16960860 : crc32_unsigned_n (unsigned chksum, unsigned value, unsigned bytes)
8989 : : {
8990 : : /* This relies on the raw feedback's top 4 bits being zero. */
8991 : : #define FEEDBACK(X) ((X) * 0x04c11db7)
8992 : : #define SYNDROME(X) (FEEDBACK ((X) & 1) ^ FEEDBACK ((X) & 2) \
8993 : : ^ FEEDBACK ((X) & 4) ^ FEEDBACK ((X) & 8))
8994 : 16960860 : static const unsigned syndromes[16] =
8995 : : {
8996 : : SYNDROME(0x0), SYNDROME(0x1), SYNDROME(0x2), SYNDROME(0x3),
8997 : : SYNDROME(0x4), SYNDROME(0x5), SYNDROME(0x6), SYNDROME(0x7),
8998 : : SYNDROME(0x8), SYNDROME(0x9), SYNDROME(0xa), SYNDROME(0xb),
8999 : : SYNDROME(0xc), SYNDROME(0xd), SYNDROME(0xe), SYNDROME(0xf),
9000 : : };
9001 : : #undef FEEDBACK
9002 : : #undef SYNDROME
9003 : :
9004 : 16960860 : value <<= (32 - bytes * 8);
9005 : 56266368 : for (unsigned ix = bytes * 2; ix--; value <<= 4)
9006 : : {
9007 : 39305508 : unsigned feedback = syndromes[((value ^ chksum) >> 28) & 0xf];
9008 : :
9009 : 39305508 : chksum = (chksum << 4) ^ feedback;
9010 : : }
9011 : :
9012 : 16960860 : return chksum;
9013 : : }
9014 : :
9015 : : /* Generate a crc32 of a string. */
9016 : :
9017 : : unsigned
9018 : 8595 : crc32_string (unsigned chksum, const char *string)
9019 : : {
9020 : 343473 : do
9021 : 343473 : chksum = crc32_byte (chksum, *string);
9022 : 343473 : while (*string++);
9023 : 8595 : return chksum;
9024 : : }
9025 : :
9026 : : /* P is a string that will be used in a symbol. Mask out any characters
9027 : : that are not valid in that context. */
9028 : :
9029 : : void
9030 : 7256 : clean_symbol_name (char *p)
9031 : : {
9032 : 82626 : for (; *p; p++)
9033 : 75370 : if (! (ISALNUM (*p)
9034 : : #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
9035 : : || *p == '$'
9036 : : #endif
9037 : : #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
9038 : : || *p == '.'
9039 : : #endif
9040 : : ))
9041 : 6853 : *p = '_';
9042 : 7256 : }
9043 : :
9044 : : static GTY(()) unsigned anon_cnt = 0; /* Saved for PCH. */
9045 : :
9046 : : /* Create a unique anonymous identifier. The identifier is still a
9047 : : valid assembly label. */
9048 : :
9049 : : tree
9050 : 2846929 : make_anon_name ()
9051 : : {
9052 : 2846929 : const char *fmt =
9053 : : #if !defined (NO_DOT_IN_LABEL)
9054 : : "."
9055 : : #elif !defined (NO_DOLLAR_IN_LABEL)
9056 : : "$"
9057 : : #else
9058 : : "_"
9059 : : #endif
9060 : : "_anon_%d";
9061 : :
9062 : 2846929 : char buf[24];
9063 : 2846929 : int len = snprintf (buf, sizeof (buf), fmt, anon_cnt++);
9064 : 2846929 : gcc_checking_assert (len < int (sizeof (buf)));
9065 : :
9066 : 2846929 : tree id = get_identifier_with_length (buf, len);
9067 : 2846929 : IDENTIFIER_ANON_P (id) = true;
9068 : :
9069 : 2846929 : return id;
9070 : : }
9071 : :
9072 : : /* Generate a name for a special-purpose function.
9073 : : The generated name may need to be unique across the whole link.
9074 : : Changes to this function may also require corresponding changes to
9075 : : xstrdup_mask_random.
9076 : : TYPE is some string to identify the purpose of this function to the
9077 : : linker or collect2; it must start with an uppercase letter,
9078 : : one of:
9079 : : I - for constructors
9080 : : D - for destructors
9081 : : N - for C++ anonymous namespaces
9082 : : F - for DWARF unwind frame information. */
9083 : :
9084 : : tree
9085 : 5323 : get_file_function_name (const char *type)
9086 : : {
9087 : 5323 : char *buf;
9088 : 5323 : const char *p;
9089 : 5323 : char *q;
9090 : :
9091 : : /* If we already have a name we know to be unique, just use that. */
9092 : 5323 : if (first_global_object_name)
9093 : 5031 : p = q = ASTRDUP (first_global_object_name);
9094 : : /* If the target is handling the constructors/destructors, they
9095 : : will be local to this file and the name is only necessary for
9096 : : debugging purposes.
9097 : : We also assign sub_I and sub_D sufixes to constructors called from
9098 : : the global static constructors. These are always local.
9099 : : OpenMP "declare target" offloaded constructors/destructors use "off_I" and
9100 : : "off_D" for the same purpose. */
9101 : 292 : else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
9102 : 584 : || ((startswith (type, "sub_") || startswith (type, "off_"))
9103 : 292 : && (type[4] == 'I' || type[4] == 'D')))
9104 : : {
9105 : 292 : const char *file = main_input_filename;
9106 : 292 : if (! file)
9107 : 0 : file = LOCATION_FILE (input_location);
9108 : : /* Just use the file's basename, because the full pathname
9109 : : might be quite long. */
9110 : 292 : p = q = ASTRDUP (lbasename (file));
9111 : : }
9112 : : else
9113 : : {
9114 : : /* Otherwise, the name must be unique across the entire link.
9115 : : We don't have anything that we know to be unique to this translation
9116 : : unit, so use what we do have and throw in some randomness. */
9117 : 0 : unsigned len;
9118 : 0 : const char *name = weak_global_object_name;
9119 : 0 : const char *file = main_input_filename;
9120 : :
9121 : 0 : if (! name)
9122 : 0 : name = "";
9123 : 0 : if (! file)
9124 : 0 : file = LOCATION_FILE (input_location);
9125 : :
9126 : 0 : len = strlen (file);
9127 : 0 : q = (char *) alloca (9 + 19 + len + 1);
9128 : 0 : memcpy (q, file, len + 1);
9129 : :
9130 : 0 : snprintf (q + len, 9 + 19 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX,
9131 : : crc32_string (0, name), get_random_seed (false));
9132 : :
9133 : 0 : p = q;
9134 : : }
9135 : :
9136 : 5323 : clean_symbol_name (q);
9137 : 5323 : buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
9138 : : + strlen (type));
9139 : :
9140 : : /* Set up the name of the file-level functions we may need.
9141 : : Use a global object (which is already required to be unique over
9142 : : the program) rather than the file name (which imposes extra
9143 : : constraints). */
9144 : 5323 : sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
9145 : :
9146 : 5323 : return get_identifier (buf);
9147 : : }
9148 : :
9149 : : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9150 : :
9151 : : /* Complain that the tree code of NODE does not match the expected 0
9152 : : terminated list of trailing codes. The trailing code list can be
9153 : : empty, for a more vague error message. FILE, LINE, and FUNCTION
9154 : : are of the caller. */
9155 : :
9156 : : void
9157 : 0 : tree_check_failed (const_tree node, const char *file,
9158 : : int line, const char *function, ...)
9159 : : {
9160 : 0 : va_list args;
9161 : 0 : const char *buffer;
9162 : 0 : unsigned length = 0;
9163 : 0 : enum tree_code code;
9164 : :
9165 : 0 : va_start (args, function);
9166 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9167 : 0 : length += 4 + strlen (get_tree_code_name (code));
9168 : 0 : va_end (args);
9169 : 0 : if (length)
9170 : : {
9171 : 0 : char *tmp;
9172 : 0 : va_start (args, function);
9173 : 0 : length += strlen ("expected ");
9174 : 0 : buffer = tmp = (char *) alloca (length);
9175 : 0 : length = 0;
9176 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9177 : : {
9178 : 0 : const char *prefix = length ? " or " : "expected ";
9179 : :
9180 : 0 : strcpy (tmp + length, prefix);
9181 : 0 : length += strlen (prefix);
9182 : 0 : strcpy (tmp + length, get_tree_code_name (code));
9183 : 0 : length += strlen (get_tree_code_name (code));
9184 : : }
9185 : 0 : va_end (args);
9186 : : }
9187 : : else
9188 : : buffer = "unexpected node";
9189 : :
9190 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9191 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9192 : : function, trim_filename (file), line);
9193 : : }
9194 : :
9195 : : /* Complain that the tree code of NODE does match the expected 0
9196 : : terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9197 : : the caller. */
9198 : :
9199 : : void
9200 : 0 : tree_not_check_failed (const_tree node, const char *file,
9201 : : int line, const char *function, ...)
9202 : : {
9203 : 0 : va_list args;
9204 : 0 : char *buffer;
9205 : 0 : unsigned length = 0;
9206 : 0 : enum tree_code code;
9207 : :
9208 : 0 : va_start (args, function);
9209 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9210 : 0 : length += 4 + strlen (get_tree_code_name (code));
9211 : 0 : va_end (args);
9212 : 0 : va_start (args, function);
9213 : 0 : buffer = (char *) alloca (length);
9214 : 0 : length = 0;
9215 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9216 : : {
9217 : 0 : if (length)
9218 : : {
9219 : 0 : strcpy (buffer + length, " or ");
9220 : 0 : length += 4;
9221 : : }
9222 : 0 : strcpy (buffer + length, get_tree_code_name (code));
9223 : 0 : length += strlen (get_tree_code_name (code));
9224 : : }
9225 : 0 : va_end (args);
9226 : :
9227 : 0 : internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9228 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9229 : : function, trim_filename (file), line);
9230 : : }
9231 : :
9232 : : /* Similar to tree_check_failed, except that we check for a class of tree
9233 : : code, given in CL. */
9234 : :
9235 : : void
9236 : 0 : tree_class_check_failed (const_tree node, const enum tree_code_class cl,
9237 : : const char *file, int line, const char *function)
9238 : : {
9239 : 0 : internal_error
9240 : 0 : ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9241 : 0 : TREE_CODE_CLASS_STRING (cl),
9242 : 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9243 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9244 : : }
9245 : :
9246 : : /* Similar to tree_check_failed, except that instead of specifying a
9247 : : dozen codes, use the knowledge that they're all sequential. */
9248 : :
9249 : : void
9250 : 0 : tree_range_check_failed (const_tree node, const char *file, int line,
9251 : : const char *function, enum tree_code c1,
9252 : : enum tree_code c2)
9253 : : {
9254 : 0 : char *buffer;
9255 : 0 : unsigned length = 0;
9256 : 0 : unsigned int c;
9257 : :
9258 : 0 : for (c = c1; c <= c2; ++c)
9259 : 0 : length += 4 + strlen (get_tree_code_name ((enum tree_code) c));
9260 : :
9261 : 0 : length += strlen ("expected ");
9262 : 0 : buffer = (char *) alloca (length);
9263 : 0 : length = 0;
9264 : :
9265 : 0 : for (c = c1; c <= c2; ++c)
9266 : : {
9267 : 0 : const char *prefix = length ? " or " : "expected ";
9268 : :
9269 : 0 : strcpy (buffer + length, prefix);
9270 : 0 : length += strlen (prefix);
9271 : 0 : strcpy (buffer + length, get_tree_code_name ((enum tree_code) c));
9272 : 0 : length += strlen (get_tree_code_name ((enum tree_code) c));
9273 : : }
9274 : :
9275 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9276 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9277 : : function, trim_filename (file), line);
9278 : : }
9279 : :
9280 : :
9281 : : /* Similar to tree_check_failed, except that we check that a tree does
9282 : : not have the specified code, given in CL. */
9283 : :
9284 : : void
9285 : 0 : tree_not_class_check_failed (const_tree node, const enum tree_code_class cl,
9286 : : const char *file, int line, const char *function)
9287 : : {
9288 : 0 : internal_error
9289 : 0 : ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9290 : 0 : TREE_CODE_CLASS_STRING (cl),
9291 : 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9292 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9293 : : }
9294 : :
9295 : :
9296 : : /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9297 : :
9298 : : void
9299 : 0 : omp_clause_check_failed (const_tree node, const char *file, int line,
9300 : : const char *function, enum omp_clause_code code)
9301 : : {
9302 : 0 : internal_error ("tree check: expected %<omp_clause %s%>, have %qs "
9303 : : "in %s, at %s:%d",
9304 : 0 : omp_clause_code_name[code],
9305 : 0 : get_tree_code_name (TREE_CODE (node)),
9306 : : function, trim_filename (file), line);
9307 : : }
9308 : :
9309 : :
9310 : : /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9311 : :
9312 : : void
9313 : 0 : omp_clause_range_check_failed (const_tree node, const char *file, int line,
9314 : : const char *function, enum omp_clause_code c1,
9315 : : enum omp_clause_code c2)
9316 : : {
9317 : 0 : char *buffer;
9318 : 0 : unsigned length = 0;
9319 : 0 : unsigned int c;
9320 : :
9321 : 0 : for (c = c1; c <= c2; ++c)
9322 : 0 : length += 4 + strlen (omp_clause_code_name[c]);
9323 : :
9324 : 0 : length += strlen ("expected ");
9325 : 0 : buffer = (char *) alloca (length);
9326 : 0 : length = 0;
9327 : :
9328 : 0 : for (c = c1; c <= c2; ++c)
9329 : : {
9330 : 0 : const char *prefix = length ? " or " : "expected ";
9331 : :
9332 : 0 : strcpy (buffer + length, prefix);
9333 : 0 : length += strlen (prefix);
9334 : 0 : strcpy (buffer + length, omp_clause_code_name[c]);
9335 : 0 : length += strlen (omp_clause_code_name[c]);
9336 : : }
9337 : :
9338 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9339 : 0 : buffer, omp_clause_code_name[TREE_CODE (node)],
9340 : : function, trim_filename (file), line);
9341 : : }
9342 : :
9343 : :
9344 : : #undef DEFTREESTRUCT
9345 : : #define DEFTREESTRUCT(VAL, NAME) NAME,
9346 : :
9347 : : static const char *ts_enum_names[] = {
9348 : : #include "treestruct.def"
9349 : : };
9350 : : #undef DEFTREESTRUCT
9351 : :
9352 : : #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9353 : :
9354 : : /* Similar to tree_class_check_failed, except that we check for
9355 : : whether CODE contains the tree structure identified by EN. */
9356 : :
9357 : : void
9358 : 0 : tree_contains_struct_check_failed (const_tree node,
9359 : : const enum tree_node_structure_enum en,
9360 : : const char *file, int line,
9361 : : const char *function)
9362 : : {
9363 : 0 : internal_error
9364 : 0 : ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9365 : 0 : TS_ENUM_NAME (en),
9366 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9367 : : }
9368 : :
9369 : :
9370 : : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9371 : : (dynamically sized) vector. */
9372 : :
9373 : : void
9374 : 0 : tree_int_cst_elt_check_failed (int idx, int len, const char *file, int line,
9375 : : const char *function)
9376 : : {
9377 : 0 : internal_error
9378 : 0 : ("tree check: accessed elt %d of %<tree_int_cst%> with %d elts in %s, "
9379 : : "at %s:%d",
9380 : : idx + 1, len, function, trim_filename (file), line);
9381 : : }
9382 : :
9383 : : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9384 : : (dynamically sized) vector. */
9385 : :
9386 : : void
9387 : 0 : tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
9388 : : const char *function)
9389 : : {
9390 : 0 : internal_error
9391 : 0 : ("tree check: accessed elt %d of %<tree_vec%> with %d elts in %s, at %s:%d",
9392 : : idx + 1, len, function, trim_filename (file), line);
9393 : : }
9394 : :
9395 : : /* Similar to above, except that the check is for the bounds of the operand
9396 : : vector of an expression node EXP. */
9397 : :
9398 : : void
9399 : 0 : tree_operand_check_failed (int idx, const_tree exp, const char *file,
9400 : : int line, const char *function)
9401 : : {
9402 : 0 : enum tree_code code = TREE_CODE (exp);
9403 : 0 : internal_error
9404 : 0 : ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9405 : : idx + 1, get_tree_code_name (code), TREE_OPERAND_LENGTH (exp),
9406 : : function, trim_filename (file), line);
9407 : : }
9408 : :
9409 : : /* Similar to above, except that the check is for the number of
9410 : : operands of an OMP_CLAUSE node. */
9411 : :
9412 : : void
9413 : 0 : omp_clause_operand_check_failed (int idx, const_tree t, const char *file,
9414 : : int line, const char *function)
9415 : : {
9416 : 0 : internal_error
9417 : 0 : ("tree check: accessed operand %d of %<omp_clause %s%> with %d operands "
9418 : 0 : "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
9419 : 0 : omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
9420 : : trim_filename (file), line);
9421 : : }
9422 : : #endif /* ENABLE_TREE_CHECKING */
9423 : :
9424 : : /* Create a new vector type node holding NUNITS units of type INNERTYPE,
9425 : : and mapped to the machine mode MODE. Initialize its fields and build
9426 : : the information necessary for debugging output. */
9427 : :
9428 : : static tree
9429 : 69974633 : make_vector_type (tree innertype, poly_int64 nunits, machine_mode mode)
9430 : : {
9431 : 69974633 : tree t;
9432 : 69974633 : tree mv_innertype = TYPE_MAIN_VARIANT (innertype);
9433 : :
9434 : 69974633 : t = make_node (VECTOR_TYPE);
9435 : 69974633 : TREE_TYPE (t) = mv_innertype;
9436 : 69974633 : SET_TYPE_VECTOR_SUBPARTS (t, nunits);
9437 : 69974633 : SET_TYPE_MODE (t, mode);
9438 : :
9439 : 69974633 : if (TYPE_STRUCTURAL_EQUALITY_P (mv_innertype) || in_lto_p)
9440 : 1215025 : SET_TYPE_STRUCTURAL_EQUALITY (t);
9441 : 68759608 : else if ((TYPE_CANONICAL (mv_innertype) != innertype
9442 : 65335641 : || mode != VOIDmode)
9443 : 99412399 : && !VECTOR_BOOLEAN_TYPE_P (t))
9444 : 31700448 : TYPE_CANONICAL (t)
9445 : 63400896 : = make_vector_type (TYPE_CANONICAL (mv_innertype), nunits, VOIDmode);
9446 : :
9447 : 69974633 : layout_type (t);
9448 : :
9449 : 69974633 : hashval_t hash = type_hash_canon_hash (t);
9450 : 69974633 : t = type_hash_canon (hash, t);
9451 : :
9452 : : /* We have built a main variant, based on the main variant of the
9453 : : inner type. Use it to build the variant we return. */
9454 : 139944109 : if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
9455 : 70781506 : && TREE_TYPE (t) != innertype)
9456 : 810805 : return build_type_attribute_qual_variant (t,
9457 : 810805 : TYPE_ATTRIBUTES (innertype),
9458 : 1621610 : TYPE_QUALS (innertype));
9459 : :
9460 : : return t;
9461 : : }
9462 : :
9463 : : static tree
9464 : 4048815 : make_or_reuse_type (unsigned size, int unsignedp)
9465 : : {
9466 : 4048815 : int i;
9467 : :
9468 : 4048815 : if (size == INT_TYPE_SIZE)
9469 : 869130 : return unsignedp ? unsigned_type_node : integer_type_node;
9470 : 3179685 : if (size == CHAR_TYPE_SIZE)
9471 : 579420 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
9472 : 2600265 : if (size == SHORT_TYPE_SIZE)
9473 : 869130 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
9474 : 1767378 : if (size == LONG_TYPE_SIZE)
9475 : 847446 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
9476 : 883689 : if (size == LONG_LONG_TYPE_SIZE)
9477 : 21684 : return (unsignedp ? long_long_unsigned_type_node
9478 : 21684 : : long_long_integer_type_node);
9479 : :
9480 : 876255 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9481 : 862005 : if (size == int_n_data[i].bitsize
9482 : 862005 : && int_n_enabled_p[i])
9483 : 847755 : return (unsignedp ? int_n_trees[i].unsigned_type
9484 : 847755 : : int_n_trees[i].signed_type);
9485 : :
9486 : 14250 : if (unsignedp)
9487 : 7125 : return make_unsigned_type (size);
9488 : : else
9489 : 7125 : return make_signed_type (size);
9490 : : }
9491 : :
9492 : : /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9493 : :
9494 : : static tree
9495 : 5794200 : make_or_reuse_fract_type (unsigned size, int unsignedp, int satp)
9496 : : {
9497 : 5794200 : if (satp)
9498 : : {
9499 : 2897100 : if (size == SHORT_FRACT_TYPE_SIZE)
9500 : 579420 : return unsignedp ? sat_unsigned_short_fract_type_node
9501 : 579420 : : sat_short_fract_type_node;
9502 : 2317680 : if (size == FRACT_TYPE_SIZE)
9503 : 579420 : return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node;
9504 : 1738260 : if (size == LONG_FRACT_TYPE_SIZE)
9505 : 579420 : return unsignedp ? sat_unsigned_long_fract_type_node
9506 : 579420 : : sat_long_fract_type_node;
9507 : 1158840 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9508 : 579420 : return unsignedp ? sat_unsigned_long_long_fract_type_node
9509 : 579420 : : sat_long_long_fract_type_node;
9510 : : }
9511 : : else
9512 : : {
9513 : 2897100 : if (size == SHORT_FRACT_TYPE_SIZE)
9514 : 579420 : return unsignedp ? unsigned_short_fract_type_node
9515 : 579420 : : short_fract_type_node;
9516 : 2317680 : if (size == FRACT_TYPE_SIZE)
9517 : 579420 : return unsignedp ? unsigned_fract_type_node : fract_type_node;
9518 : 1738260 : if (size == LONG_FRACT_TYPE_SIZE)
9519 : 579420 : return unsignedp ? unsigned_long_fract_type_node
9520 : 579420 : : long_fract_type_node;
9521 : 1158840 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9522 : 579420 : return unsignedp ? unsigned_long_long_fract_type_node
9523 : 579420 : : long_long_fract_type_node;
9524 : : }
9525 : :
9526 : 1158840 : return make_fract_type (size, unsignedp, satp);
9527 : : }
9528 : :
9529 : : /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9530 : :
9531 : : static tree
9532 : 4635360 : make_or_reuse_accum_type (unsigned size, int unsignedp, int satp)
9533 : : {
9534 : 4635360 : if (satp)
9535 : : {
9536 : 2317680 : if (size == SHORT_ACCUM_TYPE_SIZE)
9537 : 579420 : return unsignedp ? sat_unsigned_short_accum_type_node
9538 : 579420 : : sat_short_accum_type_node;
9539 : 1738260 : if (size == ACCUM_TYPE_SIZE)
9540 : 579420 : return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node;
9541 : 1158840 : if (size == LONG_ACCUM_TYPE_SIZE)
9542 : 579420 : return unsignedp ? sat_unsigned_long_accum_type_node
9543 : 579420 : : sat_long_accum_type_node;
9544 : 579420 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9545 : 579420 : return unsignedp ? sat_unsigned_long_long_accum_type_node
9546 : 579420 : : sat_long_long_accum_type_node;
9547 : : }
9548 : : else
9549 : : {
9550 : 2317680 : if (size == SHORT_ACCUM_TYPE_SIZE)
9551 : 579420 : return unsignedp ? unsigned_short_accum_type_node
9552 : 579420 : : short_accum_type_node;
9553 : 1738260 : if (size == ACCUM_TYPE_SIZE)
9554 : 579420 : return unsignedp ? unsigned_accum_type_node : accum_type_node;
9555 : 1158840 : if (size == LONG_ACCUM_TYPE_SIZE)
9556 : 579420 : return unsignedp ? unsigned_long_accum_type_node
9557 : 579420 : : long_accum_type_node;
9558 : 579420 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9559 : 579420 : return unsignedp ? unsigned_long_long_accum_type_node
9560 : 579420 : : long_long_accum_type_node;
9561 : : }
9562 : :
9563 : 0 : return make_accum_type (size, unsignedp, satp);
9564 : : }
9565 : :
9566 : :
9567 : : /* Create an atomic variant node for TYPE. This routine is called
9568 : : during initialization of data types to create the 5 basic atomic
9569 : : types. The generic build_variant_type function requires these to
9570 : : already be set up in order to function properly, so cannot be
9571 : : called from there. If ALIGN is non-zero, then ensure alignment is
9572 : : overridden to this value. */
9573 : :
9574 : : static tree
9575 : 1448550 : build_atomic_base (tree type, unsigned int align)
9576 : : {
9577 : 1448550 : tree t;
9578 : :
9579 : : /* Make sure its not already registered. */
9580 : 1448550 : if ((t = get_qualified_type (type, TYPE_QUAL_ATOMIC)))
9581 : : return t;
9582 : :
9583 : 1448550 : t = build_variant_type_copy (type);
9584 : 1448550 : set_type_quals (t, TYPE_QUAL_ATOMIC);
9585 : :
9586 : 1448550 : if (align)
9587 : 0 : SET_TYPE_ALIGN (t, align);
9588 : :
9589 : : return t;
9590 : : }
9591 : :
9592 : : /* Information about the _FloatN and _FloatNx types. This must be in
9593 : : the same order as the corresponding TI_* enum values. */
9594 : : const floatn_type_info floatn_nx_types[NUM_FLOATN_NX_TYPES] =
9595 : : {
9596 : : { 16, false },
9597 : : { 32, false },
9598 : : { 64, false },
9599 : : { 128, false },
9600 : : { 32, true },
9601 : : { 64, true },
9602 : : { 128, true },
9603 : : };
9604 : :
9605 : :
9606 : : /* Create nodes for all integer types (and error_mark_node) using the sizes
9607 : : of C datatypes. SIGNED_CHAR specifies whether char is signed. */
9608 : :
9609 : : void
9610 : 289710 : build_common_tree_nodes (bool signed_char)
9611 : : {
9612 : 289710 : int i;
9613 : :
9614 : 289710 : error_mark_node = make_node (ERROR_MARK);
9615 : 289710 : TREE_TYPE (error_mark_node) = error_mark_node;
9616 : :
9617 : 289710 : initialize_sizetypes ();
9618 : :
9619 : : /* Define both `signed char' and `unsigned char'. */
9620 : 289710 : signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
9621 : 289710 : TYPE_STRING_FLAG (signed_char_type_node) = 1;
9622 : 289710 : unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
9623 : 289710 : TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
9624 : :
9625 : : /* Define `char', which is like either `signed char' or `unsigned char'
9626 : : but not the same as either. */
9627 : 289710 : char_type_node
9628 : 289710 : = (signed_char
9629 : 289710 : ? make_signed_type (CHAR_TYPE_SIZE)
9630 : 56074 : : make_unsigned_type (CHAR_TYPE_SIZE));
9631 : 289710 : TYPE_STRING_FLAG (char_type_node) = 1;
9632 : :
9633 : 289710 : short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
9634 : 289710 : short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
9635 : 289710 : integer_type_node = make_signed_type (INT_TYPE_SIZE);
9636 : 289710 : unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
9637 : 296938 : long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
9638 : 296938 : long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
9639 : 289710 : long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
9640 : 289710 : long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
9641 : :
9642 : 869130 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9643 : : {
9644 : 289710 : int_n_trees[i].signed_type = make_signed_type (int_n_data[i].bitsize);
9645 : 289710 : int_n_trees[i].unsigned_type = make_unsigned_type (int_n_data[i].bitsize);
9646 : :
9647 : 289710 : if (int_n_enabled_p[i])
9648 : : {
9649 : 282585 : integer_types[itk_intN_0 + i * 2] = int_n_trees[i].signed_type;
9650 : 282585 : integer_types[itk_unsigned_intN_0 + i * 2] = int_n_trees[i].unsigned_type;
9651 : : }
9652 : : }
9653 : :
9654 : : /* Define a boolean type. This type only represents boolean values but
9655 : : may be larger than char depending on the value of BOOL_TYPE_SIZE. */
9656 : 289710 : boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
9657 : 289710 : TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
9658 : 289710 : TYPE_PRECISION (boolean_type_node) = 1;
9659 : 289710 : TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
9660 : :
9661 : : /* Define what type to use for size_t. */
9662 : 296938 : if (strcmp (SIZE_TYPE, "unsigned int") == 0)
9663 : 7228 : size_type_node = unsigned_type_node;
9664 : 282482 : else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
9665 : 282482 : size_type_node = long_unsigned_type_node;
9666 : 0 : else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
9667 : 0 : size_type_node = long_long_unsigned_type_node;
9668 : 0 : else if (strcmp (SIZE_TYPE, "short unsigned int") == 0)
9669 : 0 : size_type_node = short_unsigned_type_node;
9670 : : else
9671 : : {
9672 : 0 : int i;
9673 : :
9674 : 0 : size_type_node = NULL_TREE;
9675 : 0 : for (i = 0; i < NUM_INT_N_ENTS; i++)
9676 : 0 : if (int_n_enabled_p[i])
9677 : : {
9678 : 0 : char name[50], altname[50];
9679 : 0 : sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
9680 : 0 : sprintf (altname, "__int%d__ unsigned", int_n_data[i].bitsize);
9681 : :
9682 : 0 : if (strcmp (name, SIZE_TYPE) == 0
9683 : 0 : || strcmp (altname, SIZE_TYPE) == 0)
9684 : : {
9685 : 0 : size_type_node = int_n_trees[i].unsigned_type;
9686 : : }
9687 : : }
9688 : 0 : if (size_type_node == NULL_TREE)
9689 : 0 : gcc_unreachable ();
9690 : : }
9691 : :
9692 : : /* Define what type to use for ptrdiff_t. */
9693 : 296938 : if (strcmp (PTRDIFF_TYPE, "int") == 0)
9694 : 7228 : ptrdiff_type_node = integer_type_node;
9695 : 282482 : else if (strcmp (PTRDIFF_TYPE, "long int") == 0)
9696 : 282482 : ptrdiff_type_node = long_integer_type_node;
9697 : 0 : else if (strcmp (PTRDIFF_TYPE, "long long int") == 0)
9698 : 0 : ptrdiff_type_node = long_long_integer_type_node;
9699 : 0 : else if (strcmp (PTRDIFF_TYPE, "short int") == 0)
9700 : 0 : ptrdiff_type_node = short_integer_type_node;
9701 : : else
9702 : : {
9703 : 0 : ptrdiff_type_node = NULL_TREE;
9704 : 0 : for (int i = 0; i < NUM_INT_N_ENTS; i++)
9705 : 0 : if (int_n_enabled_p[i])
9706 : : {
9707 : 0 : char name[50], altname[50];
9708 : 0 : sprintf (name, "__int%d", int_n_data[i].bitsize);
9709 : 0 : sprintf (altname, "__int%d__", int_n_data[i].bitsize);
9710 : :
9711 : 0 : if (strcmp (name, PTRDIFF_TYPE) == 0
9712 : 0 : || strcmp (altname, PTRDIFF_TYPE) == 0)
9713 : 0 : ptrdiff_type_node = int_n_trees[i].signed_type;
9714 : : }
9715 : 0 : if (ptrdiff_type_node == NULL_TREE)
9716 : 0 : gcc_unreachable ();
9717 : : }
9718 : :
9719 : : /* Fill in the rest of the sized types. Reuse existing type nodes
9720 : : when possible. */
9721 : 289710 : intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
9722 : 289710 : intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
9723 : 289710 : intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
9724 : 289710 : intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
9725 : 289710 : intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
9726 : :
9727 : 289710 : unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
9728 : 289710 : unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
9729 : 289710 : unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
9730 : 289710 : unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
9731 : 289710 : unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
9732 : :
9733 : : /* Don't call build_qualified type for atomics. That routine does
9734 : : special processing for atomics, and until they are initialized
9735 : : it's better not to make that call.
9736 : :
9737 : : Check to see if there is a target override for atomic types. */
9738 : :
9739 : 289710 : atomicQI_type_node = build_atomic_base (unsigned_intQI_type_node,
9740 : 289710 : targetm.atomic_align_for_mode (QImode));
9741 : 289710 : atomicHI_type_node = build_atomic_base (unsigned_intHI_type_node,
9742 : 289710 : targetm.atomic_align_for_mode (HImode));
9743 : 289710 : atomicSI_type_node = build_atomic_base (unsigned_intSI_type_node,
9744 : 289710 : targetm.atomic_align_for_mode (SImode));
9745 : 289710 : atomicDI_type_node = build_atomic_base (unsigned_intDI_type_node,
9746 : 289710 : targetm.atomic_align_for_mode (DImode));
9747 : 289710 : atomicTI_type_node = build_atomic_base (unsigned_intTI_type_node,
9748 : 289710 : targetm.atomic_align_for_mode (TImode));
9749 : :
9750 : 289710 : access_public_node = get_identifier ("public");
9751 : 289710 : access_protected_node = get_identifier ("protected");
9752 : 289710 : access_private_node = get_identifier ("private");
9753 : :
9754 : : /* Define these next since types below may used them. */
9755 : 289710 : integer_zero_node = build_int_cst (integer_type_node, 0);
9756 : 289710 : integer_one_node = build_int_cst (integer_type_node, 1);
9757 : 289710 : integer_minus_one_node = build_int_cst (integer_type_node, -1);
9758 : :
9759 : 289710 : size_zero_node = size_int (0);
9760 : 289710 : size_one_node = size_int (1);
9761 : 289710 : bitsize_zero_node = bitsize_int (0);
9762 : 289710 : bitsize_one_node = bitsize_int (1);
9763 : 289710 : bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
9764 : :
9765 : 289710 : boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
9766 : 289710 : boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
9767 : :
9768 : 289710 : void_type_node = make_node (VOID_TYPE);
9769 : 289710 : layout_type (void_type_node);
9770 : :
9771 : : /* We are not going to have real types in C with less than byte alignment,
9772 : : so we might as well not have any types that claim to have it. */
9773 : 289710 : SET_TYPE_ALIGN (void_type_node, BITS_PER_UNIT);
9774 : 289710 : TYPE_USER_ALIGN (void_type_node) = 0;
9775 : :
9776 : 289710 : void_node = make_node (VOID_CST);
9777 : 289710 : TREE_TYPE (void_node) = void_type_node;
9778 : :
9779 : 289710 : void_list_node = build_tree_list (NULL_TREE, void_type_node);
9780 : :
9781 : 289710 : null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
9782 : 289710 : layout_type (TREE_TYPE (null_pointer_node));
9783 : :
9784 : 289710 : ptr_type_node = build_pointer_type (void_type_node);
9785 : 289710 : const_ptr_type_node
9786 : 289710 : = build_pointer_type (build_type_variant (void_type_node, 1, 0));
9787 : 2027970 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
9788 : 1738260 : builtin_structptr_types[i].node = builtin_structptr_types[i].base;
9789 : :
9790 : 296938 : pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
9791 : :
9792 : 289710 : float_type_node = make_node (REAL_TYPE);
9793 : 289710 : machine_mode float_type_mode
9794 : 289710 : = targetm.c.mode_for_floating_type (TI_FLOAT_TYPE);
9795 : 289710 : SET_TYPE_MODE (float_type_node, float_type_mode);
9796 : 289710 : TYPE_PRECISION (float_type_node)
9797 : 289710 : = GET_MODE_PRECISION (float_type_mode).to_constant ();
9798 : 289710 : layout_type (float_type_node);
9799 : :
9800 : 289710 : double_type_node = make_node (REAL_TYPE);
9801 : 289710 : machine_mode double_type_mode
9802 : 289710 : = targetm.c.mode_for_floating_type (TI_DOUBLE_TYPE);
9803 : 289710 : SET_TYPE_MODE (double_type_node, double_type_mode);
9804 : 289710 : TYPE_PRECISION (double_type_node)
9805 : 289710 : = GET_MODE_PRECISION (double_type_mode).to_constant ();
9806 : 289710 : layout_type (double_type_node);
9807 : :
9808 : 289710 : long_double_type_node = make_node (REAL_TYPE);
9809 : 289710 : machine_mode long_double_type_mode
9810 : 289710 : = targetm.c.mode_for_floating_type (TI_LONG_DOUBLE_TYPE);
9811 : 289710 : SET_TYPE_MODE (long_double_type_node, long_double_type_mode);
9812 : 289710 : TYPE_PRECISION (long_double_type_node)
9813 : 289710 : = GET_MODE_PRECISION (long_double_type_mode).to_constant ();
9814 : 289710 : layout_type (long_double_type_node);
9815 : :
9816 : 2317680 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9817 : : {
9818 : 2027970 : int n = floatn_nx_types[i].n;
9819 : 2027970 : bool extended = floatn_nx_types[i].extended;
9820 : 2027970 : scalar_float_mode mode;
9821 : 2027970 : if (!targetm.floatn_mode (n, extended).exists (&mode))
9822 : 289710 : continue;
9823 : 1738260 : int precision = GET_MODE_PRECISION (mode);
9824 : 1738260 : FLOATN_NX_TYPE_NODE (i) = make_node (REAL_TYPE);
9825 : 1738260 : TYPE_PRECISION (FLOATN_NX_TYPE_NODE (i)) = precision;
9826 : 1738260 : layout_type (FLOATN_NX_TYPE_NODE (i));
9827 : 1738260 : SET_TYPE_MODE (FLOATN_NX_TYPE_NODE (i), mode);
9828 : : }
9829 : 289710 : float128t_type_node = float128_type_node;
9830 : : #ifdef HAVE_BFmode
9831 : 289710 : if (REAL_MODE_FORMAT (BFmode) == &arm_bfloat_half_format
9832 : 289710 : && targetm.scalar_mode_supported_p (BFmode)
9833 : 579420 : && targetm.libgcc_floating_mode_supported_p (BFmode))
9834 : : {
9835 : 289710 : bfloat16_type_node = make_node (REAL_TYPE);
9836 : 289710 : TYPE_PRECISION (bfloat16_type_node) = GET_MODE_PRECISION (BFmode);
9837 : 289710 : layout_type (bfloat16_type_node);
9838 : 289710 : SET_TYPE_MODE (bfloat16_type_node, BFmode);
9839 : : }
9840 : : #endif
9841 : :
9842 : 289710 : float_ptr_type_node = build_pointer_type (float_type_node);
9843 : 289710 : double_ptr_type_node = build_pointer_type (double_type_node);
9844 : 289710 : long_double_ptr_type_node = build_pointer_type (long_double_type_node);
9845 : 289710 : integer_ptr_type_node = build_pointer_type (integer_type_node);
9846 : :
9847 : : /* Fixed size integer types. */
9848 : 289710 : uint16_type_node = make_or_reuse_type (16, 1);
9849 : 289710 : uint32_type_node = make_or_reuse_type (32, 1);
9850 : 289710 : uint64_type_node = make_or_reuse_type (64, 1);
9851 : 289710 : if (targetm.scalar_mode_supported_p (TImode))
9852 : 282585 : uint128_type_node = make_or_reuse_type (128, 1);
9853 : :
9854 : : /* Decimal float types. */
9855 : 289710 : if (targetm.decimal_float_supported_p ())
9856 : : {
9857 : 289710 : dfloat32_type_node = make_node (REAL_TYPE);
9858 : 289710 : TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
9859 : 289710 : SET_TYPE_MODE (dfloat32_type_node, SDmode);
9860 : 289710 : layout_type (dfloat32_type_node);
9861 : :
9862 : 289710 : dfloat64_type_node = make_node (REAL_TYPE);
9863 : 289710 : TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
9864 : 289710 : SET_TYPE_MODE (dfloat64_type_node, DDmode);
9865 : 289710 : layout_type (dfloat64_type_node);
9866 : :
9867 : 289710 : dfloat128_type_node = make_node (REAL_TYPE);
9868 : 289710 : TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
9869 : 289710 : SET_TYPE_MODE (dfloat128_type_node, TDmode);
9870 : 289710 : layout_type (dfloat128_type_node);
9871 : :
9872 : 289710 : dfloat64x_type_node = make_node (REAL_TYPE);
9873 : 289710 : TYPE_PRECISION (dfloat64x_type_node) = DECIMAL128_TYPE_SIZE;
9874 : 289710 : SET_TYPE_MODE (dfloat64x_type_node, TDmode);
9875 : 289710 : layout_type (dfloat64x_type_node);
9876 : : }
9877 : :
9878 : 289710 : complex_integer_type_node = build_complex_type (integer_type_node, true);
9879 : 289710 : complex_float_type_node = build_complex_type (float_type_node, true);
9880 : 289710 : complex_double_type_node = build_complex_type (double_type_node, true);
9881 : 289710 : complex_long_double_type_node = build_complex_type (long_double_type_node,
9882 : : true);
9883 : :
9884 : 2317680 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9885 : : {
9886 : 2027970 : if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
9887 : 1738260 : COMPLEX_FLOATN_NX_TYPE_NODE (i)
9888 : 1738260 : = build_complex_type (FLOATN_NX_TYPE_NODE (i));
9889 : : }
9890 : :
9891 : : /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9892 : : #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9893 : : sat_ ## KIND ## _type_node = \
9894 : : make_sat_signed_ ## KIND ## _type (SIZE); \
9895 : : sat_unsigned_ ## KIND ## _type_node = \
9896 : : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9897 : : KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9898 : : unsigned_ ## KIND ## _type_node = \
9899 : : make_unsigned_ ## KIND ## _type (SIZE);
9900 : :
9901 : : #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9902 : : sat_ ## WIDTH ## KIND ## _type_node = \
9903 : : make_sat_signed_ ## KIND ## _type (SIZE); \
9904 : : sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9905 : : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9906 : : WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9907 : : unsigned_ ## WIDTH ## KIND ## _type_node = \
9908 : : make_unsigned_ ## KIND ## _type (SIZE);
9909 : :
9910 : : /* Make fixed-point type nodes based on four different widths. */
9911 : : #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9912 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9913 : : MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9914 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9915 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9916 : :
9917 : : /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9918 : : #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9919 : : NAME ## _type_node = \
9920 : : make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9921 : : u ## NAME ## _type_node = \
9922 : : make_or_reuse_unsigned_ ## KIND ## _type \
9923 : : (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9924 : : sat_ ## NAME ## _type_node = \
9925 : : make_or_reuse_sat_signed_ ## KIND ## _type \
9926 : : (GET_MODE_BITSIZE (MODE ## mode)); \
9927 : : sat_u ## NAME ## _type_node = \
9928 : : make_or_reuse_sat_unsigned_ ## KIND ## _type \
9929 : : (GET_MODE_BITSIZE (U ## MODE ## mode));
9930 : :
9931 : : /* Fixed-point type and mode nodes. */
9932 : 289710 : MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT)
9933 : 289710 : MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM)
9934 : 289710 : MAKE_FIXED_MODE_NODE (fract, qq, QQ)
9935 : 289710 : MAKE_FIXED_MODE_NODE (fract, hq, HQ)
9936 : 289710 : MAKE_FIXED_MODE_NODE (fract, sq, SQ)
9937 : 289710 : MAKE_FIXED_MODE_NODE (fract, dq, DQ)
9938 : 289710 : MAKE_FIXED_MODE_NODE (fract, tq, TQ)
9939 : 289710 : MAKE_FIXED_MODE_NODE (accum, ha, HA)
9940 : 289710 : MAKE_FIXED_MODE_NODE (accum, sa, SA)
9941 : 289710 : MAKE_FIXED_MODE_NODE (accum, da, DA)
9942 : 289710 : MAKE_FIXED_MODE_NODE (accum, ta, TA)
9943 : :
9944 : 289710 : {
9945 : 289710 : tree t = targetm.build_builtin_va_list ();
9946 : :
9947 : : /* Many back-ends define record types without setting TYPE_NAME.
9948 : : If we copied the record type here, we'd keep the original
9949 : : record type without a name. This breaks name mangling. So,
9950 : : don't copy record types and let c_common_nodes_and_builtins()
9951 : : declare the type to be __builtin_va_list. */
9952 : 289710 : if (TREE_CODE (t) != RECORD_TYPE)
9953 : 289710 : t = build_variant_type_copy (t);
9954 : :
9955 : 289710 : va_list_type_node = t;
9956 : : }
9957 : :
9958 : : /* SCEV analyzer global shared trees. */
9959 : 289710 : chrec_dont_know = make_node (SCEV_NOT_KNOWN);
9960 : 289710 : TREE_TYPE (chrec_dont_know) = void_type_node;
9961 : 289710 : chrec_known = make_node (SCEV_KNOWN);
9962 : 289710 : TREE_TYPE (chrec_known) = void_type_node;
9963 : 289710 : }
9964 : :
9965 : : /* Modify DECL for given flags.
9966 : : TM_PURE attribute is set only on types, so the function will modify
9967 : : DECL's type when ECF_TM_PURE is used. */
9968 : :
9969 : : void
9970 : 31038754 : set_call_expr_flags (tree decl, int flags)
9971 : : {
9972 : 31038754 : if (flags & ECF_NOTHROW)
9973 : 26750720 : TREE_NOTHROW (decl) = 1;
9974 : 31038754 : if (flags & ECF_CONST)
9975 : 12872244 : TREE_READONLY (decl) = 1;
9976 : 31038754 : if (flags & ECF_PURE)
9977 : 1513102 : DECL_PURE_P (decl) = 1;
9978 : 31038754 : if (flags & ECF_LOOPING_CONST_OR_PURE)
9979 : 57336 : DECL_LOOPING_CONST_OR_PURE_P (decl) = 1;
9980 : 31038754 : if (flags & ECF_NOVOPS)
9981 : 0 : DECL_IS_NOVOPS (decl) = 1;
9982 : 31038754 : if (flags & ECF_NORETURN)
9983 : 1230304 : TREE_THIS_VOLATILE (decl) = 1;
9984 : 31038754 : if (flags & ECF_MALLOC)
9985 : 742581 : DECL_IS_MALLOC (decl) = 1;
9986 : 31038754 : if (flags & ECF_RETURNS_TWICE)
9987 : 0 : DECL_IS_RETURNS_TWICE (decl) = 1;
9988 : 31038754 : if (flags & ECF_LEAF)
9989 : 26625967 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("leaf"),
9990 : 26625967 : NULL, DECL_ATTRIBUTES (decl));
9991 : 31038754 : if (flags & ECF_COLD)
9992 : 646367 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("cold"),
9993 : 646367 : NULL, DECL_ATTRIBUTES (decl));
9994 : 31038754 : if (flags & ECF_RET1)
9995 : 0 : DECL_ATTRIBUTES (decl)
9996 : 0 : = tree_cons (get_identifier ("fn spec"),
9997 : : build_tree_list (NULL_TREE, build_string (2, "1 ")),
9998 : 0 : DECL_ATTRIBUTES (decl));
9999 : 31038754 : if ((flags & ECF_TM_PURE) && flag_tm)
10000 : 564 : apply_tm_attr (decl, get_identifier ("transaction_pure"));
10001 : 31038754 : if ((flags & ECF_XTHROW))
10002 : 414894 : DECL_ATTRIBUTES (decl)
10003 : 829788 : = tree_cons (get_identifier ("expected_throw"),
10004 : 414894 : NULL, DECL_ATTRIBUTES (decl));
10005 : :
10006 : 31038754 : if (flags & ECF_CB_1_2)
10007 : : {
10008 : 371508 : tree attr = callback_build_attr (1, 1, 2);
10009 : 371508 : TREE_CHAIN (attr) = DECL_ATTRIBUTES (decl);
10010 : 371508 : DECL_ATTRIBUTES (decl) = attr;
10011 : : }
10012 : :
10013 : : /* Looping const or pure is implied by noreturn.
10014 : : There is currently no way to declare looping const or looping pure alone. */
10015 : 31038754 : gcc_assert (!(flags & ECF_LOOPING_CONST_OR_PURE)
10016 : : || (flags & (ECF_CONST | ECF_PURE)));
10017 : 31038754 : }
10018 : :
10019 : :
10020 : : /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
10021 : :
10022 : : static void
10023 : 9645941 : local_define_builtin (const char *name, tree type, enum built_in_function code,
10024 : : const char *library_name, int ecf_flags)
10025 : : {
10026 : 9645941 : tree decl;
10027 : :
10028 : 9645941 : decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
10029 : : library_name, NULL_TREE);
10030 : 9645941 : set_call_expr_flags (decl, ecf_flags);
10031 : :
10032 : 9645941 : set_builtin_decl (code, decl, true);
10033 : 9645941 : }
10034 : :
10035 : : /* Call this function after instantiating all builtins that the language
10036 : : front end cares about. This will build the rest of the builtins
10037 : : and internal functions that are relied upon by the tree optimizers and
10038 : : the middle-end. */
10039 : :
10040 : : void
10041 : 289694 : build_common_builtin_nodes (void)
10042 : : {
10043 : 289694 : tree tmp, ftype;
10044 : 289694 : int ecf_flags;
10045 : :
10046 : 289694 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_PADDING))
10047 : : {
10048 : 57336 : ftype = build_function_type_list (void_type_node,
10049 : : ptr_type_node,
10050 : : ptr_type_node,
10051 : : NULL_TREE);
10052 : 57336 : local_define_builtin ("__builtin_clear_padding", ftype,
10053 : : BUILT_IN_CLEAR_PADDING,
10054 : : "__builtin_clear_padding",
10055 : : ECF_LEAF | ECF_NOTHROW);
10056 : : }
10057 : :
10058 : 289694 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE)
10059 : 237003 : || !builtin_decl_explicit_p (BUILT_IN_TRAP)
10060 : 237003 : || !builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP)
10061 : 232358 : || !builtin_decl_explicit_p (BUILT_IN_OBSERVABLE_CHKPT)
10062 : 522052 : || !builtin_decl_explicit_p (BUILT_IN_ABORT))
10063 : : {
10064 : 57336 : ftype = build_function_type (void_type_node, void_list_node);
10065 : 57336 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE))
10066 : 52691 : local_define_builtin ("__builtin_unreachable", ftype,
10067 : : BUILT_IN_UNREACHABLE,
10068 : : "__builtin_unreachable",
10069 : : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10070 : : | ECF_CONST | ECF_COLD);
10071 : 57336 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP))
10072 : 57336 : local_define_builtin ("__builtin_unreachable trap", ftype,
10073 : : BUILT_IN_UNREACHABLE_TRAP,
10074 : : "__builtin_unreachable trap",
10075 : : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10076 : : | ECF_CONST | ECF_COLD);
10077 : 57336 : if (!builtin_decl_explicit_p (BUILT_IN_ABORT))
10078 : 57336 : local_define_builtin ("__builtin_abort", ftype, BUILT_IN_ABORT,
10079 : : "abort",
10080 : : ECF_LEAF | ECF_NORETURN | ECF_CONST | ECF_COLD);
10081 : 57336 : if (!builtin_decl_explicit_p (BUILT_IN_TRAP))
10082 : 21732 : local_define_builtin ("__builtin_trap", ftype, BUILT_IN_TRAP,
10083 : : "__builtin_trap",
10084 : : ECF_NORETURN | ECF_NOTHROW | ECF_LEAF | ECF_COLD);
10085 : 57336 : if (!builtin_decl_explicit_p (BUILT_IN_OBSERVABLE_CHKPT))
10086 : 57336 : local_define_builtin ("__builtin_observable_checkpoint", ftype,
10087 : : BUILT_IN_OBSERVABLE_CHKPT,
10088 : : "__builtin_observable_checkpoint",
10089 : : ECF_NOTHROW | ECF_LEAF | ECF_CONST
10090 : : | ECF_LOOPING_CONST_OR_PURE);
10091 : : }
10092 : :
10093 : 289694 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY)
10094 : 289694 : || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10095 : : {
10096 : 57336 : ftype = build_function_type_list (ptr_type_node,
10097 : : ptr_type_node, const_ptr_type_node,
10098 : : size_type_node, NULL_TREE);
10099 : :
10100 : 57336 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY))
10101 : 57336 : local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
10102 : : "memcpy", ECF_NOTHROW | ECF_LEAF);
10103 : 57336 : if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10104 : 52691 : local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
10105 : : "memmove", ECF_NOTHROW | ECF_LEAF);
10106 : : }
10107 : :
10108 : 289694 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP))
10109 : : {
10110 : 52691 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10111 : : const_ptr_type_node, size_type_node,
10112 : : NULL_TREE);
10113 : 52691 : local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
10114 : : "memcmp", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10115 : : }
10116 : :
10117 : 289694 : if (!builtin_decl_explicit_p (BUILT_IN_MEMSET))
10118 : : {
10119 : 52691 : ftype = build_function_type_list (ptr_type_node,
10120 : : ptr_type_node, integer_type_node,
10121 : : size_type_node, NULL_TREE);
10122 : 52691 : local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
10123 : : "memset", ECF_NOTHROW | ECF_LEAF);
10124 : : }
10125 : :
10126 : : /* If we're checking the stack, `alloca' can throw. */
10127 : 289626 : const int alloca_flags
10128 : 289694 : = ECF_MALLOC | ECF_LEAF | (flag_stack_check ? 0 : ECF_NOTHROW);
10129 : :
10130 : 289694 : if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA))
10131 : : {
10132 : 57336 : ftype = build_function_type_list (ptr_type_node,
10133 : : size_type_node, NULL_TREE);
10134 : 57336 : local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
10135 : : "alloca", alloca_flags);
10136 : : }
10137 : :
10138 : 289694 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10139 : : size_type_node, NULL_TREE);
10140 : 289694 : local_define_builtin ("__builtin_alloca_with_align", ftype,
10141 : : BUILT_IN_ALLOCA_WITH_ALIGN,
10142 : : "__builtin_alloca_with_align",
10143 : : alloca_flags);
10144 : :
10145 : 289694 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10146 : : size_type_node, size_type_node, NULL_TREE);
10147 : 289694 : local_define_builtin ("__builtin_alloca_with_align_and_max", ftype,
10148 : : BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX,
10149 : : "__builtin_alloca_with_align_and_max",
10150 : : alloca_flags);
10151 : :
10152 : 289694 : ftype = build_function_type_list (void_type_node,
10153 : : ptr_type_node, ptr_type_node,
10154 : : ptr_type_node, NULL_TREE);
10155 : 289694 : local_define_builtin ("__builtin_init_trampoline", ftype,
10156 : : BUILT_IN_INIT_TRAMPOLINE,
10157 : : "__builtin_init_trampoline", ECF_NOTHROW | ECF_LEAF);
10158 : 289694 : local_define_builtin ("__builtin_init_heap_trampoline", ftype,
10159 : : BUILT_IN_INIT_HEAP_TRAMPOLINE,
10160 : : "__builtin_init_heap_trampoline",
10161 : : ECF_NOTHROW | ECF_LEAF);
10162 : 289694 : local_define_builtin ("__builtin_init_descriptor", ftype,
10163 : : BUILT_IN_INIT_DESCRIPTOR,
10164 : : "__builtin_init_descriptor", ECF_NOTHROW | ECF_LEAF);
10165 : :
10166 : 289694 : ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
10167 : 289694 : local_define_builtin ("__builtin_adjust_trampoline", ftype,
10168 : : BUILT_IN_ADJUST_TRAMPOLINE,
10169 : : "__builtin_adjust_trampoline",
10170 : : ECF_CONST | ECF_NOTHROW);
10171 : 289694 : local_define_builtin ("__builtin_adjust_descriptor", ftype,
10172 : : BUILT_IN_ADJUST_DESCRIPTOR,
10173 : : "__builtin_adjust_descriptor",
10174 : : ECF_CONST | ECF_NOTHROW);
10175 : :
10176 : 289694 : ftype = build_function_type_list (void_type_node,
10177 : : ptr_type_node, ptr_type_node, NULL_TREE);
10178 : 289694 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_CACHE))
10179 : 57336 : local_define_builtin ("__builtin___clear_cache", ftype,
10180 : : BUILT_IN_CLEAR_CACHE,
10181 : : "__clear_cache",
10182 : : ECF_NOTHROW);
10183 : :
10184 : 289694 : local_define_builtin ("__builtin_nonlocal_goto", ftype,
10185 : : BUILT_IN_NONLOCAL_GOTO,
10186 : : "__builtin_nonlocal_goto",
10187 : : ECF_NORETURN | ECF_NOTHROW);
10188 : :
10189 : 289694 : tree ptr_ptr_type_node = build_pointer_type (ptr_type_node);
10190 : :
10191 : 289694 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_CREATED))
10192 : : {
10193 : 57336 : ftype = build_function_type_list (void_type_node,
10194 : : ptr_type_node, // void *chain
10195 : : ptr_type_node, // void *func
10196 : : ptr_ptr_type_node, // void **dst
10197 : : NULL_TREE);
10198 : 57336 : local_define_builtin ("__builtin___gcc_nested_func_ptr_created", ftype,
10199 : : BUILT_IN_GCC_NESTED_PTR_CREATED,
10200 : : "__gcc_nested_func_ptr_created", ECF_NOTHROW);
10201 : : }
10202 : :
10203 : 289694 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_DELETED))
10204 : : {
10205 : 57336 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10206 : 57336 : local_define_builtin ("__builtin___gcc_nested_func_ptr_deleted", ftype,
10207 : : BUILT_IN_GCC_NESTED_PTR_DELETED,
10208 : : "__gcc_nested_func_ptr_deleted", ECF_NOTHROW);
10209 : : }
10210 : :
10211 : 289694 : ftype = build_function_type_list (void_type_node,
10212 : : ptr_type_node, ptr_type_node, NULL_TREE);
10213 : 289694 : local_define_builtin ("__builtin_setjmp_setup", ftype,
10214 : : BUILT_IN_SETJMP_SETUP,
10215 : : "__builtin_setjmp_setup", ECF_NOTHROW);
10216 : :
10217 : 289694 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10218 : 289694 : local_define_builtin ("__builtin_setjmp_receiver", ftype,
10219 : : BUILT_IN_SETJMP_RECEIVER,
10220 : : "__builtin_setjmp_receiver", ECF_NOTHROW | ECF_LEAF);
10221 : :
10222 : 289694 : ftype = build_function_type_list (ptr_type_node, NULL_TREE);
10223 : 289694 : local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
10224 : : "__builtin_stack_save", ECF_NOTHROW | ECF_LEAF);
10225 : :
10226 : 289694 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10227 : 289694 : local_define_builtin ("__builtin_stack_restore", ftype,
10228 : : BUILT_IN_STACK_RESTORE,
10229 : : "__builtin_stack_restore", ECF_NOTHROW | ECF_LEAF);
10230 : :
10231 : 289694 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10232 : : const_ptr_type_node, size_type_node,
10233 : : NULL_TREE);
10234 : 289694 : local_define_builtin ("__builtin_memcmp_eq", ftype, BUILT_IN_MEMCMP_EQ,
10235 : : "__builtin_memcmp_eq",
10236 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10237 : :
10238 : 289694 : local_define_builtin ("__builtin_strncmp_eq", ftype, BUILT_IN_STRNCMP_EQ,
10239 : : "__builtin_strncmp_eq",
10240 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10241 : :
10242 : 289694 : local_define_builtin ("__builtin_strcmp_eq", ftype, BUILT_IN_STRCMP_EQ,
10243 : : "__builtin_strcmp_eq",
10244 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10245 : :
10246 : : /* If there's a possibility that we might use the ARM EABI, build the
10247 : : alternate __cxa_end_cleanup node used to resume from C++. */
10248 : 289694 : if (targetm.arm_eabi_unwinder)
10249 : : {
10250 : 0 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10251 : 0 : local_define_builtin ("__builtin_cxa_end_cleanup", ftype,
10252 : : BUILT_IN_CXA_END_CLEANUP,
10253 : : "__cxa_end_cleanup",
10254 : : ECF_NORETURN | ECF_XTHROW | ECF_LEAF);
10255 : : }
10256 : :
10257 : 289694 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10258 : 579388 : local_define_builtin ("__builtin_unwind_resume", ftype,
10259 : : BUILT_IN_UNWIND_RESUME,
10260 : 289694 : ((targetm_common.except_unwind_info (&global_options)
10261 : : == UI_SJLJ)
10262 : : ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
10263 : : ECF_NORETURN | ECF_XTHROW);
10264 : :
10265 : 289694 : if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS) == NULL_TREE)
10266 : : {
10267 : 52691 : ftype = build_function_type_list (ptr_type_node, integer_type_node,
10268 : : NULL_TREE);
10269 : 52691 : local_define_builtin ("__builtin_return_address", ftype,
10270 : : BUILT_IN_RETURN_ADDRESS,
10271 : : "__builtin_return_address",
10272 : : ECF_NOTHROW);
10273 : : }
10274 : :
10275 : 289694 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER)
10276 : 289694 : || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10277 : : {
10278 : 57336 : ftype = build_function_type_list (void_type_node, ptr_type_node,
10279 : : ptr_type_node, NULL_TREE);
10280 : 57336 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER))
10281 : 57336 : local_define_builtin ("__cyg_profile_func_enter", ftype,
10282 : : BUILT_IN_PROFILE_FUNC_ENTER,
10283 : : "__cyg_profile_func_enter", 0);
10284 : 57336 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10285 : 57336 : local_define_builtin ("__cyg_profile_func_exit", ftype,
10286 : : BUILT_IN_PROFILE_FUNC_EXIT,
10287 : : "__cyg_profile_func_exit", 0);
10288 : : }
10289 : :
10290 : : /* The exception object and filter values from the runtime. The argument
10291 : : must be zero before exception lowering, i.e. from the front end. After
10292 : : exception lowering, it will be the region number for the exception
10293 : : landing pad. These functions are PURE instead of CONST to prevent
10294 : : them from being hoisted past the exception edge that will initialize
10295 : : its value in the landing pad. */
10296 : 289694 : ftype = build_function_type_list (ptr_type_node,
10297 : : integer_type_node, NULL_TREE);
10298 : 289694 : ecf_flags = ECF_PURE | ECF_NOTHROW | ECF_LEAF;
10299 : : /* Only use TM_PURE if we have TM language support. */
10300 : 289694 : if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1))
10301 : 502 : ecf_flags |= ECF_TM_PURE;
10302 : 289694 : local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER,
10303 : : "__builtin_eh_pointer", ecf_flags);
10304 : :
10305 : 289694 : tmp = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0);
10306 : 289694 : ftype = build_function_type_list (tmp, integer_type_node, NULL_TREE);
10307 : 289694 : local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER,
10308 : : "__builtin_eh_filter", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10309 : :
10310 : 289694 : ftype = build_function_type_list (void_type_node,
10311 : : integer_type_node, integer_type_node,
10312 : : NULL_TREE);
10313 : 289694 : local_define_builtin ("__builtin_eh_copy_values", ftype,
10314 : : BUILT_IN_EH_COPY_VALUES,
10315 : : "__builtin_eh_copy_values", ECF_NOTHROW);
10316 : :
10317 : : /* Complex multiplication and division. These are handled as builtins
10318 : : rather than optabs because emit_library_call_value doesn't support
10319 : : complex. Further, we can do slightly better with folding these
10320 : : beasties if the real and complex parts of the arguments are separate. */
10321 : 289694 : {
10322 : 289694 : int mode;
10323 : :
10324 : 2027858 : for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
10325 : : {
10326 : 1738164 : char mode_name_buf[4], *q;
10327 : 1738164 : const char *p;
10328 : 1738164 : enum built_in_function mcode, dcode;
10329 : 1738164 : tree type, inner_type;
10330 : 1738164 : const char *prefix = "__";
10331 : :
10332 : 1738164 : if (targetm.libfunc_gnu_prefix)
10333 : 0 : prefix = "__gnu_";
10334 : :
10335 : 1738164 : type = lang_hooks.types.type_for_mode ((machine_mode) mode, 0);
10336 : 1738164 : if (type == NULL)
10337 : 125228 : continue;
10338 : 1612936 : inner_type = TREE_TYPE (type);
10339 : :
10340 : 1612936 : ftype = build_function_type_list (type, inner_type, inner_type,
10341 : : inner_type, inner_type, NULL_TREE);
10342 : :
10343 : 1612936 : mcode = ((enum built_in_function)
10344 : 1612936 : (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10345 : 1612936 : dcode = ((enum built_in_function)
10346 : 1612936 : (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10347 : :
10348 : 4838808 : for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
10349 : 3225872 : *q = TOLOWER (*p);
10350 : 1612936 : *q = '\0';
10351 : :
10352 : : /* For -ftrapping-math these should throw from a former
10353 : : -fnon-call-exception stmt. */
10354 : 1612936 : built_in_names[mcode] = concat (prefix, "mul", mode_name_buf, "3",
10355 : : NULL);
10356 : 1612936 : local_define_builtin (built_in_names[mcode], ftype, mcode,
10357 : : built_in_names[mcode],
10358 : : ECF_CONST | ECF_LEAF);
10359 : :
10360 : 1612936 : built_in_names[dcode] = concat (prefix, "div", mode_name_buf, "3",
10361 : : NULL);
10362 : 1612936 : local_define_builtin (built_in_names[dcode], ftype, dcode,
10363 : : built_in_names[dcode],
10364 : : ECF_CONST | ECF_LEAF);
10365 : : }
10366 : : }
10367 : :
10368 : 289694 : init_internal_fns ();
10369 : 289694 : }
10370 : :
10371 : : /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10372 : : better way.
10373 : :
10374 : : If we requested a pointer to a vector, build up the pointers that
10375 : : we stripped off while looking for the inner type. Similarly for
10376 : : return values from functions.
10377 : :
10378 : : The argument TYPE is the top of the chain, and BOTTOM is the
10379 : : new type which we will point to. */
10380 : :
10381 : : tree
10382 : 0 : reconstruct_complex_type (tree type, tree bottom)
10383 : : {
10384 : 0 : tree inner, outer;
10385 : :
10386 : 0 : if (TREE_CODE (type) == POINTER_TYPE)
10387 : : {
10388 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10389 : 0 : outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
10390 : 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10391 : : }
10392 : : else if (TREE_CODE (type) == REFERENCE_TYPE)
10393 : : {
10394 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10395 : 0 : outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
10396 : 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10397 : : }
10398 : : else if (TREE_CODE (type) == ARRAY_TYPE)
10399 : : {
10400 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10401 : 0 : outer = build_array_type (inner, TYPE_DOMAIN (type));
10402 : : }
10403 : : else if (TREE_CODE (type) == FUNCTION_TYPE)
10404 : : {
10405 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10406 : 0 : outer = build_function_type (inner, TYPE_ARG_TYPES (type),
10407 : 0 : TYPE_NO_NAMED_ARGS_STDARG_P (type));
10408 : : }
10409 : : else if (TREE_CODE (type) == METHOD_TYPE)
10410 : : {
10411 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10412 : : /* The build_method_type_directly() routine prepends 'this' to argument list,
10413 : : so we must compensate by getting rid of it. */
10414 : 0 : outer
10415 : : = build_method_type_directly
10416 : 0 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
10417 : : inner,
10418 : 0 : TREE_CHAIN (TYPE_ARG_TYPES (type)));
10419 : : }
10420 : : else if (TREE_CODE (type) == OFFSET_TYPE)
10421 : : {
10422 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10423 : 0 : outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
10424 : : }
10425 : : else
10426 : : return bottom;
10427 : :
10428 : 0 : return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
10429 : 0 : TYPE_QUALS (type));
10430 : : }
10431 : :
10432 : : /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10433 : : the inner type. */
10434 : : tree
10435 : 32834409 : build_vector_type_for_mode (tree innertype, machine_mode mode)
10436 : : {
10437 : 32834409 : poly_int64 nunits;
10438 : 32834409 : unsigned int bitsize;
10439 : :
10440 : 32834409 : switch (GET_MODE_CLASS (mode))
10441 : : {
10442 : 32833079 : case MODE_VECTOR_BOOL:
10443 : 32833079 : case MODE_VECTOR_INT:
10444 : 32833079 : case MODE_VECTOR_FLOAT:
10445 : 32833079 : case MODE_VECTOR_FRACT:
10446 : 32833079 : case MODE_VECTOR_UFRACT:
10447 : 32833079 : case MODE_VECTOR_ACCUM:
10448 : 32833079 : case MODE_VECTOR_UACCUM:
10449 : 65666158 : nunits = GET_MODE_NUNITS (mode);
10450 : 32833079 : break;
10451 : :
10452 : 1330 : case MODE_INT:
10453 : : /* Check that there are no leftover bits. */
10454 : 1330 : bitsize = GET_MODE_BITSIZE (as_a <scalar_int_mode> (mode));
10455 : 1330 : gcc_assert (bitsize % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
10456 : 1330 : nunits = bitsize / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
10457 : 1330 : break;
10458 : :
10459 : 0 : default:
10460 : 0 : gcc_unreachable ();
10461 : : }
10462 : :
10463 : 32834409 : return make_vector_type (innertype, nunits, mode);
10464 : : }
10465 : :
10466 : : /* Similarly, but takes the inner type and number of units, which must be
10467 : : a power of two. */
10468 : :
10469 : : tree
10470 : 2883440 : build_vector_type (tree innertype, poly_int64 nunits)
10471 : : {
10472 : 2883440 : return make_vector_type (innertype, nunits, VOIDmode);
10473 : : }
10474 : :
10475 : : /* Build a truth vector with NUNITS units, giving it mode MASK_MODE. */
10476 : :
10477 : : tree
10478 : 2447918 : build_truth_vector_type_for_mode (poly_uint64 nunits, machine_mode mask_mode)
10479 : : {
10480 : 2447918 : gcc_assert (mask_mode != BLKmode);
10481 : :
10482 : 2447918 : unsigned HOST_WIDE_INT esize;
10483 : 2447918 : if (VECTOR_MODE_P (mask_mode))
10484 : : {
10485 : 2336258 : poly_uint64 vsize = GET_MODE_PRECISION (mask_mode);
10486 : 2336258 : esize = vector_element_size (vsize, nunits);
10487 : 2336258 : }
10488 : : else
10489 : : esize = 1;
10490 : :
10491 : 2447918 : tree bool_type = build_nonstandard_boolean_type (esize);
10492 : :
10493 : 2447918 : return make_vector_type (bool_type, nunits, mask_mode);
10494 : : }
10495 : :
10496 : : /* Build a vector type that holds one boolean result for each element of
10497 : : vector type VECTYPE. The public interface for this operation is
10498 : : truth_type_for. */
10499 : :
10500 : : static tree
10501 : 2438655 : build_truth_vector_type_for (tree vectype)
10502 : : {
10503 : 2438655 : machine_mode vector_mode = TYPE_MODE (vectype);
10504 : 2438655 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
10505 : :
10506 : 2438655 : machine_mode mask_mode;
10507 : 88733 : if (VECTOR_MODE_P (vector_mode)
10508 : 2526820 : && targetm.vectorize.get_mask_mode (vector_mode).exists (&mask_mode))
10509 : 2438087 : return build_truth_vector_type_for_mode (nunits, mask_mode);
10510 : :
10511 : 568 : poly_uint64 vsize = tree_to_poly_uint64 (TYPE_SIZE (vectype));
10512 : 568 : unsigned HOST_WIDE_INT esize = vector_element_size (vsize, nunits);
10513 : 568 : tree bool_type = build_nonstandard_boolean_type (esize);
10514 : :
10515 : 568 : return make_vector_type (bool_type, nunits, VOIDmode);
10516 : : }
10517 : :
10518 : : /* Like build_vector_type, but builds a variant type with TYPE_VECTOR_OPAQUE
10519 : : set. */
10520 : :
10521 : : tree
10522 : 107850 : build_opaque_vector_type (tree innertype, poly_int64 nunits)
10523 : : {
10524 : 107850 : tree t = make_vector_type (innertype, nunits, VOIDmode);
10525 : 107850 : tree cand;
10526 : : /* We always build the non-opaque variant before the opaque one,
10527 : : so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10528 : 107850 : cand = TYPE_NEXT_VARIANT (t);
10529 : 107850 : if (cand
10530 : 96445 : && TYPE_VECTOR_OPAQUE (cand)
10531 : 170641 : && check_qualified_type (cand, t, TYPE_QUALS (t)))
10532 : : return cand;
10533 : : /* Othewise build a variant type and make sure to queue it after
10534 : : the non-opaque type. */
10535 : 45060 : cand = build_distinct_type_copy (t);
10536 : 45060 : TYPE_VECTOR_OPAQUE (cand) = true;
10537 : 45060 : TYPE_CANONICAL (cand) = TYPE_CANONICAL (t);
10538 : 45060 : TYPE_NEXT_VARIANT (cand) = TYPE_NEXT_VARIANT (t);
10539 : 45060 : TYPE_NEXT_VARIANT (t) = cand;
10540 : 45060 : TYPE_MAIN_VARIANT (cand) = TYPE_MAIN_VARIANT (t);
10541 : : /* Type variants have no alias set defined. */
10542 : 45060 : TYPE_ALIAS_SET (cand) = -1;
10543 : 45060 : return cand;
10544 : : }
10545 : :
10546 : : /* Return the value of element I of VECTOR_CST T as a wide_int. */
10547 : :
10548 : : static poly_wide_int
10549 : 532745 : vector_cst_int_elt (const_tree t, unsigned int i)
10550 : : {
10551 : : /* First handle elements that are directly encoded. */
10552 : 532745 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10553 : 532745 : if (i < encoded_nelts)
10554 : 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, i));
10555 : :
10556 : : /* Identify the pattern that contains element I and work out the index of
10557 : : the last encoded element for that pattern. */
10558 : 532745 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10559 : 532745 : unsigned int pattern = i % npatterns;
10560 : 532745 : unsigned int count = i / npatterns;
10561 : 532745 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10562 : :
10563 : : /* If there are no steps, the final encoded value is the right one. */
10564 : 532745 : if (!VECTOR_CST_STEPPED_P (t))
10565 : 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, final_i));
10566 : :
10567 : : /* Otherwise work out the value from the last two encoded elements. */
10568 : 532745 : tree v1 = VECTOR_CST_ENCODED_ELT (t, final_i - npatterns);
10569 : 532745 : tree v2 = VECTOR_CST_ENCODED_ELT (t, final_i);
10570 : 532745 : poly_wide_int diff = wi::to_poly_wide (v2) - wi::to_poly_wide (v1);
10571 : 532745 : return wi::to_poly_wide (v2) + (count - 2) * diff;
10572 : 532745 : }
10573 : :
10574 : : /* Return the value of element I of VECTOR_CST T. */
10575 : :
10576 : : tree
10577 : 6240161 : vector_cst_elt (const_tree t, unsigned int i)
10578 : : {
10579 : : /* First handle elements that are directly encoded. */
10580 : 6240161 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10581 : 6240161 : if (i < encoded_nelts)
10582 : 4259381 : return VECTOR_CST_ENCODED_ELT (t, i);
10583 : :
10584 : : /* If there are no steps, the final encoded value is the right one. */
10585 : 1980780 : if (!VECTOR_CST_STEPPED_P (t))
10586 : : {
10587 : : /* Identify the pattern that contains element I and work out the index of
10588 : : the last encoded element for that pattern. */
10589 : 1448035 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10590 : 1448035 : unsigned int pattern = i % npatterns;
10591 : 1448035 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10592 : 1448035 : return VECTOR_CST_ENCODED_ELT (t, final_i);
10593 : : }
10594 : :
10595 : : /* Otherwise work out the value from the last two encoded elements. */
10596 : 532745 : return wide_int_to_tree (TREE_TYPE (TREE_TYPE (t)),
10597 : 1065490 : vector_cst_int_elt (t, i));
10598 : : }
10599 : :
10600 : : /* Given an initializer INIT, return TRUE if INIT is zero or some
10601 : : aggregate of zeros. Otherwise return FALSE. If NONZERO is not
10602 : : null, set *NONZERO if and only if INIT is known not to be all
10603 : : zeros. The combination of return value of false and *NONZERO
10604 : : false implies that INIT may but need not be all zeros. Other
10605 : : combinations indicate definitive answers. */
10606 : :
10607 : : bool
10608 : 43161205 : initializer_zerop (const_tree init, bool *nonzero /* = NULL */)
10609 : : {
10610 : 43161205 : bool dummy;
10611 : 43161205 : if (!nonzero)
10612 : 40397435 : nonzero = &dummy;
10613 : :
10614 : : /* Conservatively clear NONZERO and set it only if INIT is definitely
10615 : : not all zero. */
10616 : 43161205 : *nonzero = false;
10617 : :
10618 : 43161205 : STRIP_NOPS (init);
10619 : :
10620 : 43161205 : unsigned HOST_WIDE_INT off = 0;
10621 : :
10622 : 43161205 : switch (TREE_CODE (init))
10623 : : {
10624 : 16821262 : case INTEGER_CST:
10625 : 16821262 : if (integer_zerop (init))
10626 : : return true;
10627 : :
10628 : 10488597 : *nonzero = true;
10629 : 10488597 : return false;
10630 : :
10631 : 551386 : case REAL_CST:
10632 : : /* ??? Note that this is not correct for C4X float formats. There,
10633 : : a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10634 : : negative exponent. */
10635 : 551386 : if (real_zerop (init)
10636 : 641188 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init)))
10637 : : return true;
10638 : :
10639 : 464519 : *nonzero = true;
10640 : 464519 : return false;
10641 : :
10642 : 0 : case FIXED_CST:
10643 : 0 : if (fixed_zerop (init))
10644 : : return true;
10645 : :
10646 : 0 : *nonzero = true;
10647 : 0 : return false;
10648 : :
10649 : 17429 : case COMPLEX_CST:
10650 : 17429 : if (integer_zerop (init)
10651 : 17429 : || (real_zerop (init)
10652 : 2962 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
10653 : 2920 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init)))))
10654 : 3148 : return true;
10655 : :
10656 : 14281 : *nonzero = true;
10657 : 14281 : return false;
10658 : :
10659 : 1113257 : case VECTOR_CST:
10660 : 1113257 : if (VECTOR_CST_NPATTERNS (init) == 1
10661 : 1024962 : && VECTOR_CST_DUPLICATE_P (init)
10662 : 1762261 : && initializer_zerop (VECTOR_CST_ENCODED_ELT (init, 0)))
10663 : : return true;
10664 : :
10665 : 768864 : *nonzero = true;
10666 : 768864 : return false;
10667 : :
10668 : : case RAW_DATA_CST:
10669 : 1588 : for (unsigned int i = 0; i < (unsigned int) RAW_DATA_LENGTH (init); ++i)
10670 : 1588 : if (RAW_DATA_POINTER (init)[i])
10671 : : {
10672 : 1540 : *nonzero = true;
10673 : 1540 : return false;
10674 : : }
10675 : : return true;
10676 : :
10677 : 4263184 : case CONSTRUCTOR:
10678 : 4263184 : {
10679 : 4263184 : if (TREE_CLOBBER_P (init))
10680 : : return false;
10681 : :
10682 : : unsigned HOST_WIDE_INT idx;
10683 : : tree elt;
10684 : :
10685 : 3627646 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
10686 : 2763770 : if (!initializer_zerop (elt, nonzero))
10687 : : return false;
10688 : :
10689 : : return true;
10690 : : }
10691 : :
10692 : 351743 : case MEM_REF:
10693 : 351743 : {
10694 : 351743 : tree arg = TREE_OPERAND (init, 0);
10695 : 351743 : if (TREE_CODE (arg) != ADDR_EXPR)
10696 : : return false;
10697 : 81695 : tree offset = TREE_OPERAND (init, 1);
10698 : 81695 : if (TREE_CODE (offset) != INTEGER_CST
10699 : 81695 : || !tree_fits_uhwi_p (offset))
10700 : : return false;
10701 : 81695 : off = tree_to_uhwi (offset);
10702 : 81695 : if (INT_MAX < off)
10703 : : return false;
10704 : 81691 : arg = TREE_OPERAND (arg, 0);
10705 : 81691 : if (TREE_CODE (arg) != STRING_CST)
10706 : : return false;
10707 : : init = arg;
10708 : : }
10709 : : /* Fall through. */
10710 : :
10711 : : case STRING_CST:
10712 : : {
10713 : : gcc_assert (off <= INT_MAX);
10714 : :
10715 : 161368 : int i = off;
10716 : 161368 : int n = TREE_STRING_LENGTH (init);
10717 : 161368 : if (n <= i)
10718 : : return false;
10719 : :
10720 : : /* We need to loop through all elements to handle cases like
10721 : : "\0" and "\0foobar". */
10722 : 173908 : for (i = 0; i < n; ++i)
10723 : 168004 : if (TREE_STRING_POINTER (init)[i] != '\0')
10724 : : {
10725 : 155431 : *nonzero = true;
10726 : 155431 : return false;
10727 : : }
10728 : :
10729 : : return true;
10730 : : }
10731 : :
10732 : : default:
10733 : : return false;
10734 : : }
10735 : : }
10736 : :
10737 : : /* Return true if EXPR is an initializer expression in which every element
10738 : : is a constant that is numerically equal to 0 or 1. The elements do not
10739 : : need to be equal to each other. */
10740 : :
10741 : : bool
10742 : 130099 : initializer_each_zero_or_onep (const_tree expr)
10743 : : {
10744 : 130099 : STRIP_ANY_LOCATION_WRAPPER (expr);
10745 : :
10746 : 130099 : switch (TREE_CODE (expr))
10747 : : {
10748 : 47616 : case INTEGER_CST:
10749 : 47616 : return integer_zerop (expr) || integer_onep (expr);
10750 : :
10751 : 22518 : case REAL_CST:
10752 : 22518 : return real_zerop (expr) || real_onep (expr);
10753 : :
10754 : 59965 : case VECTOR_CST:
10755 : 59965 : {
10756 : 59965 : unsigned HOST_WIDE_INT nelts = vector_cst_encoded_nelts (expr);
10757 : 59965 : if (VECTOR_CST_STEPPED_P (expr)
10758 : 59965 : && !TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)).is_constant (&nelts))
10759 : : return false;
10760 : :
10761 : 71453 : for (unsigned int i = 0; i < nelts; ++i)
10762 : : {
10763 : 70134 : tree elt = vector_cst_elt (expr, i);
10764 : 70134 : if (!initializer_each_zero_or_onep (elt))
10765 : : return false;
10766 : : }
10767 : :
10768 : : return true;
10769 : : }
10770 : :
10771 : : default:
10772 : : return false;
10773 : : }
10774 : : }
10775 : :
10776 : : /* Check if vector VEC consists of all the equal elements and
10777 : : that the number of elements corresponds to the type of VEC.
10778 : : The function returns first element of the vector
10779 : : or NULL_TREE if the vector is not uniform. */
10780 : : tree
10781 : 2666701 : uniform_vector_p (const_tree vec)
10782 : : {
10783 : 2666701 : tree first, t;
10784 : 2666701 : unsigned HOST_WIDE_INT i, nelts;
10785 : :
10786 : 2666701 : if (vec == NULL_TREE)
10787 : : return NULL_TREE;
10788 : :
10789 : 2666701 : gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec)));
10790 : :
10791 : 2666701 : if (TREE_CODE (vec) == VEC_DUPLICATE_EXPR)
10792 : 0 : return TREE_OPERAND (vec, 0);
10793 : :
10794 : 2666701 : else if (TREE_CODE (vec) == VECTOR_CST)
10795 : : {
10796 : 242795 : if (VECTOR_CST_NPATTERNS (vec) == 1 && VECTOR_CST_DUPLICATE_P (vec))
10797 : 190192 : return VECTOR_CST_ENCODED_ELT (vec, 0);
10798 : : return NULL_TREE;
10799 : : }
10800 : :
10801 : 2423906 : else if (TREE_CODE (vec) == CONSTRUCTOR
10802 : 2423906 : && TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec)).is_constant (&nelts))
10803 : : {
10804 : 162790 : first = error_mark_node;
10805 : :
10806 : 542229 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t)
10807 : : {
10808 : 482781 : if (i == 0)
10809 : : {
10810 : 162790 : first = t;
10811 : 162790 : continue;
10812 : : }
10813 : 319991 : if (!operand_equal_p (first, t, 0))
10814 : : return NULL_TREE;
10815 : : }
10816 : 59448 : if (i != nelts)
10817 : : return NULL_TREE;
10818 : :
10819 : 59256 : if (TREE_CODE (first) == CONSTRUCTOR || TREE_CODE (first) == VECTOR_CST)
10820 : : return uniform_vector_p (first);
10821 : : return first;
10822 : : }
10823 : :
10824 : : return NULL_TREE;
10825 : : }
10826 : :
10827 : : /* If OP is a uniform vector return the element it is a splat from. */
10828 : :
10829 : : tree
10830 : 266102 : ssa_uniform_vector_p (tree op)
10831 : : {
10832 : 266102 : if (TREE_CODE (op) == VECTOR_CST
10833 : : || TREE_CODE (op) == VEC_DUPLICATE_EXPR
10834 : : || TREE_CODE (op) == CONSTRUCTOR)
10835 : 11125 : return uniform_vector_p (op);
10836 : : if (TREE_CODE (op) == SSA_NAME)
10837 : : {
10838 : 254977 : gimple *def_stmt = SSA_NAME_DEF_STMT (op);
10839 : 254977 : if (gimple_assign_single_p (def_stmt))
10840 : 105998 : return uniform_vector_p (gimple_assign_rhs1 (def_stmt));
10841 : : }
10842 : : return NULL_TREE;
10843 : : }
10844 : :
10845 : : /* If the argument is INTEGER_CST, return it. If the argument is vector
10846 : : with all elements the same INTEGER_CST, return that INTEGER_CST. Otherwise
10847 : : return NULL_TREE.
10848 : : Look through location wrappers. */
10849 : :
10850 : : tree
10851 : 860028105 : uniform_integer_cst_p (tree t)
10852 : : {
10853 : 860028105 : STRIP_ANY_LOCATION_WRAPPER (t);
10854 : :
10855 : 860028105 : if (TREE_CODE (t) == INTEGER_CST)
10856 : : return t;
10857 : :
10858 : 350355642 : if (VECTOR_TYPE_P (TREE_TYPE (t)))
10859 : : {
10860 : 936691 : t = uniform_vector_p (t);
10861 : 936691 : if (t && TREE_CODE (t) == INTEGER_CST)
10862 : : return t;
10863 : : }
10864 : :
10865 : : return NULL_TREE;
10866 : : }
10867 : :
10868 : : /* Checks to see if T is a constant or a constant vector and if each element E
10869 : : adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE. */
10870 : :
10871 : : tree
10872 : 3170756 : bitmask_inv_cst_vector_p (tree t)
10873 : : {
10874 : :
10875 : 3170756 : tree_code code = TREE_CODE (t);
10876 : 3170756 : tree type = TREE_TYPE (t);
10877 : :
10878 : 3170756 : if (!INTEGRAL_TYPE_P (type)
10879 : 3170756 : && !VECTOR_INTEGER_TYPE_P (type))
10880 : : return NULL_TREE;
10881 : :
10882 : 3170756 : unsigned HOST_WIDE_INT nelts = 1;
10883 : 3170756 : tree cst;
10884 : 3170756 : unsigned int idx = 0;
10885 : 3170756 : bool uniform = uniform_integer_cst_p (t);
10886 : 3170756 : tree newtype = unsigned_type_for (type);
10887 : 3170756 : tree_vector_builder builder;
10888 : 3170756 : if (code == INTEGER_CST)
10889 : : cst = t;
10890 : : else
10891 : : {
10892 : 17156 : if (!VECTOR_CST_NELTS (t).is_constant (&nelts))
10893 : : return NULL_TREE;
10894 : :
10895 : 17156 : cst = vector_cst_elt (t, 0);
10896 : 17156 : builder.new_vector (newtype, nelts, 1);
10897 : : }
10898 : :
10899 : 3170756 : tree ty = unsigned_type_for (TREE_TYPE (cst));
10900 : :
10901 : 3170768 : do
10902 : : {
10903 : 3170768 : if (idx > 0)
10904 : 12 : cst = vector_cst_elt (t, idx);
10905 : 3170768 : wide_int icst = wi::to_wide (cst);
10906 : 3170768 : wide_int inv = wi::bit_not (icst);
10907 : 3170768 : icst = wi::add (1, inv);
10908 : 3170768 : if (wi::popcount (icst) != 1)
10909 : : return NULL_TREE;
10910 : :
10911 : 8086 : tree newcst = wide_int_to_tree (ty, inv);
10912 : :
10913 : 8086 : if (uniform)
10914 : 8070 : return build_uniform_cst (newtype, newcst);
10915 : :
10916 : 16 : builder.quick_push (newcst);
10917 : 3170768 : }
10918 : 16 : while (++idx < nelts);
10919 : :
10920 : 4 : return builder.build ();
10921 : 3170756 : }
10922 : :
10923 : : /* If VECTOR_CST T has a single nonzero element, return the index of that
10924 : : element, otherwise return -1. */
10925 : :
10926 : : int
10927 : 177 : single_nonzero_element (const_tree t)
10928 : : {
10929 : 177 : unsigned HOST_WIDE_INT nelts;
10930 : 177 : unsigned int repeat_nelts;
10931 : 177 : if (VECTOR_CST_NELTS (t).is_constant (&nelts))
10932 : 177 : repeat_nelts = nelts;
10933 : : else if (VECTOR_CST_NELTS_PER_PATTERN (t) == 2)
10934 : : {
10935 : : nelts = vector_cst_encoded_nelts (t);
10936 : : repeat_nelts = VECTOR_CST_NPATTERNS (t);
10937 : : }
10938 : : else
10939 : : return -1;
10940 : :
10941 : 177 : int res = -1;
10942 : 561 : for (unsigned int i = 0; i < nelts; ++i)
10943 : : {
10944 : 528 : tree elt = vector_cst_elt (t, i);
10945 : 528 : if (!integer_zerop (elt) && !real_zerop (elt))
10946 : : {
10947 : 321 : if (res >= 0 || i >= repeat_nelts)
10948 : : return -1;
10949 : 177 : res = i;
10950 : : }
10951 : : }
10952 : : return res;
10953 : : }
10954 : :
10955 : : /* Build an empty statement at location LOC. */
10956 : :
10957 : : tree
10958 : 13461204 : build_empty_stmt (location_t loc)
10959 : : {
10960 : 13461204 : tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
10961 : 13461204 : SET_EXPR_LOCATION (t, loc);
10962 : 13461204 : return t;
10963 : : }
10964 : :
10965 : :
10966 : : /* Build an OMP clause with code CODE. LOC is the location of the
10967 : : clause. */
10968 : :
10969 : : tree
10970 : 1715470 : build_omp_clause (location_t loc, enum omp_clause_code code)
10971 : : {
10972 : 1715470 : tree t;
10973 : 1715470 : int size, length;
10974 : :
10975 : 1715470 : length = omp_clause_num_ops[code];
10976 : 1715470 : size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
10977 : :
10978 : 1715470 : record_node_allocation_statistics (OMP_CLAUSE, size);
10979 : :
10980 : 1715470 : t = (tree) ggc_internal_alloc (size);
10981 : 1715470 : memset (t, 0, size);
10982 : 1715470 : TREE_SET_CODE (t, OMP_CLAUSE);
10983 : 1715470 : OMP_CLAUSE_SET_CODE (t, code);
10984 : 1715470 : OMP_CLAUSE_LOCATION (t) = loc;
10985 : :
10986 : 1715470 : return t;
10987 : : }
10988 : :
10989 : : /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
10990 : : includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
10991 : : Except for the CODE and operand count field, other storage for the
10992 : : object is initialized to zeros. */
10993 : :
10994 : : tree
10995 : 460432020 : build_vl_exp (enum tree_code code, int len MEM_STAT_DECL)
10996 : : {
10997 : 460432020 : tree t;
10998 : 460432020 : int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
10999 : :
11000 : 460432020 : gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp);
11001 : 460432020 : gcc_assert (len >= 1);
11002 : :
11003 : 460432020 : record_node_allocation_statistics (code, length);
11004 : :
11005 : 460432020 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
11006 : :
11007 : 460432020 : TREE_SET_CODE (t, code);
11008 : :
11009 : : /* Can't use TREE_OPERAND to store the length because if checking is
11010 : : enabled, it will try to check the length before we store it. :-P */
11011 : 460432020 : t->exp.operands[0] = build_int_cst (sizetype, len);
11012 : :
11013 : 460432020 : return t;
11014 : : }
11015 : :
11016 : : /* Helper function for build_call_* functions; build a CALL_EXPR with
11017 : : indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
11018 : : the argument slots. */
11019 : :
11020 : : static tree
11021 : 247967454 : build_call_1 (tree return_type, tree fn, int nargs)
11022 : : {
11023 : 247967454 : tree t;
11024 : :
11025 : 247967454 : t = build_vl_exp (CALL_EXPR, nargs + 3);
11026 : 247967454 : TREE_TYPE (t) = return_type;
11027 : 247967454 : CALL_EXPR_FN (t) = fn;
11028 : 247967454 : CALL_EXPR_STATIC_CHAIN (t) = NULL;
11029 : :
11030 : 247967454 : return t;
11031 : : }
11032 : :
11033 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11034 : : FN and a null static chain slot. NARGS is the number of call arguments
11035 : : which are specified as a va_list ARGS. */
11036 : :
11037 : : tree
11038 : 136561 : build_call_valist (tree return_type, tree fn, int nargs, va_list args)
11039 : : {
11040 : 136561 : tree t;
11041 : 136561 : int i;
11042 : :
11043 : 136561 : t = build_call_1 (return_type, fn, nargs);
11044 : 554464 : for (i = 0; i < nargs; i++)
11045 : 281342 : CALL_EXPR_ARG (t, i) = va_arg (args, tree);
11046 : 136561 : process_call_operands (t);
11047 : 136561 : return t;
11048 : : }
11049 : :
11050 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11051 : : FN and a null static chain slot. ARGS specifies the call arguments. */
11052 : :
11053 : : tree
11054 : 151 : build_call (tree return_type, tree fn, std::initializer_list<tree> args)
11055 : : {
11056 : 151 : tree t;
11057 : 151 : int i;
11058 : 151 : int nargs = args.size();
11059 : :
11060 : 151 : t = build_call_1 (return_type, fn, nargs);
11061 : 755 : for (i = 0; i < nargs; i++)
11062 : 453 : CALL_EXPR_ARG (t, i) = args.begin()[i];
11063 : 151 : process_call_operands (t);
11064 : 151 : return t;
11065 : : }
11066 : :
11067 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11068 : : FN and a null static chain slot. NARGS is the number of call arguments
11069 : : which are specified as a tree array ARGS. */
11070 : :
11071 : : tree
11072 : 204927682 : build_call_array_loc (location_t loc, tree return_type, tree fn,
11073 : : int nargs, const tree *args)
11074 : : {
11075 : 204927682 : tree t;
11076 : 204927682 : int i;
11077 : :
11078 : 204927682 : t = build_call_1 (return_type, fn, nargs);
11079 : 703103183 : for (i = 0; i < nargs; i++)
11080 : 293247819 : CALL_EXPR_ARG (t, i) = args[i];
11081 : 204927682 : process_call_operands (t);
11082 : 204927682 : SET_EXPR_LOCATION (t, loc);
11083 : 204927682 : return t;
11084 : : }
11085 : :
11086 : : /* Like build_call_array, but takes a vec. */
11087 : :
11088 : : tree
11089 : 42378870 : build_call_vec (tree return_type, tree fn, const vec<tree, va_gc> *args)
11090 : : {
11091 : 42378870 : tree ret, t;
11092 : 42378870 : unsigned int ix;
11093 : :
11094 : 42378870 : ret = build_call_1 (return_type, fn, vec_safe_length (args));
11095 : 112535032 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
11096 : 27777292 : CALL_EXPR_ARG (ret, ix) = t;
11097 : 42378870 : process_call_operands (ret);
11098 : 42378870 : return ret;
11099 : : }
11100 : :
11101 : : /* Conveniently construct a function call expression. FNDECL names the
11102 : : function to be called and N arguments are passed in the array
11103 : : ARGARRAY. */
11104 : :
11105 : : tree
11106 : 18952849 : build_call_expr_loc_array (location_t loc, tree fndecl, int n, tree *argarray)
11107 : : {
11108 : 18952849 : tree fntype = TREE_TYPE (fndecl);
11109 : 18952849 : tree fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fndecl);
11110 : :
11111 : 18952849 : return fold_build_call_array_loc (loc, TREE_TYPE (fntype), fn, n, argarray);
11112 : : }
11113 : :
11114 : : /* Conveniently construct a function call expression. FNDECL names the
11115 : : function to be called and the arguments are passed in the vector
11116 : : VEC. */
11117 : :
11118 : : tree
11119 : 20557 : build_call_expr_loc_vec (location_t loc, tree fndecl, vec<tree, va_gc> *vec)
11120 : : {
11121 : 20557 : return build_call_expr_loc_array (loc, fndecl, vec_safe_length (vec),
11122 : 20557 : vec_safe_address (vec));
11123 : : }
11124 : :
11125 : :
11126 : : /* Conveniently construct a function call expression. FNDECL names the
11127 : : function to be called, N is the number of arguments, and the "..."
11128 : : parameters are the argument expressions. */
11129 : :
11130 : : tree
11131 : 17248529 : build_call_expr_loc (location_t loc, tree fndecl, int n, ...)
11132 : : {
11133 : 17248529 : va_list ap;
11134 : 17248529 : tree *argarray = XALLOCAVEC (tree, n);
11135 : 17248529 : int i;
11136 : :
11137 : 17248529 : va_start (ap, n);
11138 : 19723588 : for (i = 0; i < n; i++)
11139 : 2475059 : argarray[i] = va_arg (ap, tree);
11140 : 17248529 : va_end (ap);
11141 : 17248529 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11142 : : }
11143 : :
11144 : : /* Like build_call_expr_loc (UNKNOWN_LOCATION, ...). Duplicated because
11145 : : varargs macros aren't supported by all bootstrap compilers. */
11146 : :
11147 : : tree
11148 : 1679280 : build_call_expr (tree fndecl, int n, ...)
11149 : : {
11150 : 1679280 : va_list ap;
11151 : 1679280 : tree *argarray = XALLOCAVEC (tree, n);
11152 : 1679280 : int i;
11153 : :
11154 : 1679280 : va_start (ap, n);
11155 : 4972254 : for (i = 0; i < n; i++)
11156 : 3292974 : argarray[i] = va_arg (ap, tree);
11157 : 1679280 : va_end (ap);
11158 : 1679280 : return build_call_expr_loc_array (UNKNOWN_LOCATION, fndecl, n, argarray);
11159 : : }
11160 : :
11161 : : /* Build an internal call to IFN, with arguments ARGS[0:N-1] and with return
11162 : : type TYPE. This is just like CALL_EXPR, except its CALL_EXPR_FN is NULL.
11163 : : It will get gimplified later into an ordinary internal function. */
11164 : :
11165 : : tree
11166 : 524190 : build_call_expr_internal_loc_array (location_t loc, internal_fn ifn,
11167 : : tree type, int n, const tree *args)
11168 : : {
11169 : 524190 : tree t = build_call_1 (type, NULL_TREE, n);
11170 : 1870945 : for (int i = 0; i < n; ++i)
11171 : 1346755 : CALL_EXPR_ARG (t, i) = args[i];
11172 : 524190 : SET_EXPR_LOCATION (t, loc);
11173 : 524190 : CALL_EXPR_IFN (t) = ifn;
11174 : 524190 : process_call_operands (t);
11175 : 524190 : return t;
11176 : : }
11177 : :
11178 : : /* Build internal call expression. This is just like CALL_EXPR, except
11179 : : its CALL_EXPR_FN is NULL. It will get gimplified later into ordinary
11180 : : internal function. */
11181 : :
11182 : : tree
11183 : 523164 : build_call_expr_internal_loc (location_t loc, enum internal_fn ifn,
11184 : : tree type, int n, ...)
11185 : : {
11186 : 523164 : va_list ap;
11187 : 523164 : tree *argarray = XALLOCAVEC (tree, n);
11188 : 523164 : int i;
11189 : :
11190 : 523164 : va_start (ap, n);
11191 : 1867869 : for (i = 0; i < n; i++)
11192 : 1344705 : argarray[i] = va_arg (ap, tree);
11193 : 523164 : va_end (ap);
11194 : 523164 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11195 : : }
11196 : :
11197 : : /* Return a function call to FN, if the target is guaranteed to support it,
11198 : : or null otherwise.
11199 : :
11200 : : N is the number of arguments, passed in the "...", and TYPE is the
11201 : : type of the return value. */
11202 : :
11203 : : tree
11204 : 1825 : maybe_build_call_expr_loc (location_t loc, combined_fn fn, tree type,
11205 : : int n, ...)
11206 : : {
11207 : 1825 : va_list ap;
11208 : 1825 : tree *argarray = XALLOCAVEC (tree, n);
11209 : 1825 : int i;
11210 : :
11211 : 1825 : va_start (ap, n);
11212 : 4743 : for (i = 0; i < n; i++)
11213 : 2918 : argarray[i] = va_arg (ap, tree);
11214 : 1825 : va_end (ap);
11215 : 1825 : if (internal_fn_p (fn))
11216 : : {
11217 : 1024 : internal_fn ifn = as_internal_fn (fn);
11218 : 1024 : if (direct_internal_fn_p (ifn))
11219 : : {
11220 : 1 : tree_pair types = direct_internal_fn_types (ifn, type, argarray);
11221 : 1 : if (!direct_internal_fn_supported_p (ifn, types,
11222 : : OPTIMIZE_FOR_BOTH))
11223 : 1 : return NULL_TREE;
11224 : : }
11225 : 1023 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11226 : : }
11227 : : else
11228 : : {
11229 : 801 : tree fndecl = builtin_decl_implicit (as_builtin_fn (fn));
11230 : 801 : if (!fndecl)
11231 : : return NULL_TREE;
11232 : 693 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11233 : : }
11234 : : }
11235 : :
11236 : : /* Return a function call to the appropriate builtin alloca variant.
11237 : :
11238 : : SIZE is the size to be allocated. ALIGN, if non-zero, is the requested
11239 : : alignment of the allocated area. MAX_SIZE, if non-negative, is an upper
11240 : : bound for SIZE in case it is not a fixed value. */
11241 : :
11242 : : tree
11243 : 8909 : build_alloca_call_expr (tree size, unsigned int align, HOST_WIDE_INT max_size)
11244 : : {
11245 : 8909 : if (max_size >= 0)
11246 : : {
11247 : 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX);
11248 : 0 : return
11249 : 0 : build_call_expr (t, 3, size, size_int (align), size_int (max_size));
11250 : : }
11251 : 8909 : else if (align > 0)
11252 : : {
11253 : 8909 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
11254 : 8909 : return build_call_expr (t, 2, size, size_int (align));
11255 : : }
11256 : : else
11257 : : {
11258 : 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA);
11259 : 0 : return build_call_expr (t, 1, size);
11260 : : }
11261 : : }
11262 : :
11263 : : /* The built-in decl to use to mark code points believed to be unreachable.
11264 : : Typically __builtin_unreachable, but __builtin_trap if
11265 : : -fsanitize=unreachable -fsanitize-trap=unreachable. If only
11266 : : -fsanitize=unreachable, we rely on sanopt to replace calls with the
11267 : : appropriate ubsan function. When building a call directly, use
11268 : : {gimple_},build_builtin_unreachable instead. */
11269 : :
11270 : : tree
11271 : 238224 : builtin_decl_unreachable ()
11272 : : {
11273 : 238224 : enum built_in_function fncode = BUILT_IN_UNREACHABLE;
11274 : :
11275 : 476448 : if (sanitize_flags_p (SANITIZE_UNREACHABLE)
11276 : 238224 : ? (flag_sanitize_trap & SANITIZE_UNREACHABLE)
11277 : 237628 : : flag_unreachable_traps)
11278 : 22 : fncode = BUILT_IN_UNREACHABLE_TRAP;
11279 : : /* For non-trapping sanitize, we will rewrite __builtin_unreachable () later,
11280 : : in the sanopt pass. */
11281 : :
11282 : 238224 : return builtin_decl_explicit (fncode);
11283 : : }
11284 : :
11285 : : /* Build a call to __builtin_unreachable, possibly rewritten by
11286 : : -fsanitize=unreachable. Use this rather than the above when practical. */
11287 : :
11288 : : tree
11289 : 15956921 : build_builtin_unreachable (location_t loc)
11290 : : {
11291 : 15956921 : tree data = NULL_TREE;
11292 : 15956921 : tree fn = sanitize_unreachable_fn (&data, loc);
11293 : 15956921 : return build_call_expr_loc (loc, fn, data != NULL_TREE, data);
11294 : : }
11295 : :
11296 : : /* Create a new constant string literal of type ELTYPE[SIZE] (or LEN
11297 : : if SIZE == -1) and return a tree node representing char* pointer to
11298 : : it as an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)). When STR is nonnull
11299 : : the STRING_CST value is the LEN bytes at STR (the representation
11300 : : of the string, which may be wide). Otherwise it's all zeros. */
11301 : :
11302 : : tree
11303 : 255253 : build_string_literal (unsigned len, const char *str /* = NULL */,
11304 : : tree eltype /* = char_type_node */,
11305 : : unsigned HOST_WIDE_INT size /* = -1 */)
11306 : : {
11307 : 255253 : tree t = build_string (len, str);
11308 : : /* Set the maximum valid index based on the string length or SIZE. */
11309 : 510506 : unsigned HOST_WIDE_INT maxidx
11310 : 255253 : = (size == HOST_WIDE_INT_M1U ? len : size) - 1;
11311 : :
11312 : 255253 : tree index = build_index_type (size_int (maxidx));
11313 : 255253 : eltype = build_type_variant (eltype, 1, 0);
11314 : 255253 : tree type = build_array_type (eltype, index);
11315 : 255253 : TREE_TYPE (t) = type;
11316 : 255253 : TREE_CONSTANT (t) = 1;
11317 : 255253 : TREE_READONLY (t) = 1;
11318 : 255253 : TREE_STATIC (t) = 1;
11319 : :
11320 : 255253 : type = build_pointer_type (eltype);
11321 : 255253 : t = build1 (ADDR_EXPR, type,
11322 : : build4 (ARRAY_REF, eltype,
11323 : : t, integer_zero_node, NULL_TREE, NULL_TREE));
11324 : 255253 : return t;
11325 : : }
11326 : :
11327 : :
11328 : :
11329 : : /* Return true if T (assumed to be a DECL) must be assigned a memory
11330 : : location. */
11331 : :
11332 : : bool
11333 : 1992514408 : needs_to_live_in_memory (const_tree t)
11334 : : {
11335 : 1992514408 : return (TREE_ADDRESSABLE (t)
11336 : 1594594558 : || is_global_var (t)
11337 : 3148011665 : || (TREE_CODE (t) == RESULT_DECL
11338 : 8173377 : && !DECL_BY_REFERENCE (t)
11339 : 5715918 : && aggregate_value_p (t, current_function_decl)));
11340 : : }
11341 : :
11342 : : /* Return value of a constant X and sign-extend it. */
11343 : :
11344 : : HOST_WIDE_INT
11345 : 631005844 : int_cst_value (const_tree x)
11346 : : {
11347 : 631005844 : unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
11348 : 631005844 : unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
11349 : :
11350 : : /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
11351 : 631005844 : gcc_assert (cst_and_fits_in_hwi (x));
11352 : :
11353 : 631005844 : if (bits < HOST_BITS_PER_WIDE_INT)
11354 : : {
11355 : 616732702 : bool negative = ((val >> (bits - 1)) & 1) != 0;
11356 : 616732702 : if (negative)
11357 : 219699 : val |= HOST_WIDE_INT_M1U << (bits - 1) << 1;
11358 : : else
11359 : 616513003 : val &= ~(HOST_WIDE_INT_M1U << (bits - 1) << 1);
11360 : : }
11361 : :
11362 : 631005844 : return val;
11363 : : }
11364 : :
11365 : : /* If TYPE is an integral or pointer type, return an integer type with
11366 : : the same precision which is unsigned iff UNSIGNEDP is true, or itself
11367 : : if TYPE is already an integer type of signedness UNSIGNEDP.
11368 : : If TYPE is a floating-point type, return an integer type with the same
11369 : : bitsize and with the signedness given by UNSIGNEDP; this is useful
11370 : : when doing bit-level operations on a floating-point value. */
11371 : :
11372 : : tree
11373 : 88298021 : signed_or_unsigned_type_for (int unsignedp, tree type)
11374 : : {
11375 : 88298021 : if (ANY_INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) == unsignedp)
11376 : : return type;
11377 : :
11378 : 56920793 : if (TREE_CODE (type) == VECTOR_TYPE)
11379 : : {
11380 : 26786 : tree inner = TREE_TYPE (type);
11381 : 26786 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11382 : 26786 : if (!inner2)
11383 : : return NULL_TREE;
11384 : 26786 : if (inner == inner2)
11385 : : return type;
11386 : 26786 : machine_mode new_mode;
11387 : 53572 : if (VECTOR_MODE_P (TYPE_MODE (type))
11388 : 53503 : && related_int_vector_mode (TYPE_MODE (type)).exists (&new_mode))
11389 : 26717 : return build_vector_type_for_mode (inner2, new_mode);
11390 : 69 : return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type));
11391 : : }
11392 : :
11393 : : if (TREE_CODE (type) == COMPLEX_TYPE)
11394 : : {
11395 : 24 : tree inner = TREE_TYPE (type);
11396 : 24 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11397 : 24 : if (!inner2)
11398 : : return NULL_TREE;
11399 : 24 : if (inner == inner2)
11400 : : return type;
11401 : 24 : return build_complex_type (inner2);
11402 : : }
11403 : :
11404 : : unsigned int bits;
11405 : : if (INTEGRAL_TYPE_P (type)
11406 : : || POINTER_TYPE_P (type)
11407 : : || TREE_CODE (type) == OFFSET_TYPE)
11408 : 56893889 : bits = TYPE_PRECISION (type);
11409 : : else if (TREE_CODE (type) == REAL_TYPE)
11410 : 188 : bits = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (type));
11411 : : else
11412 : : return NULL_TREE;
11413 : :
11414 : 56893983 : if (TREE_CODE (type) == BITINT_TYPE && (unsignedp || bits > 1))
11415 : 1644 : return build_bitint_type (bits, unsignedp);
11416 : 56892339 : return build_nonstandard_integer_type (bits, unsignedp);
11417 : : }
11418 : :
11419 : : /* If TYPE is an integral or pointer type, return an integer type with
11420 : : the same precision which is unsigned, or itself if TYPE is already an
11421 : : unsigned integer type. If TYPE is a floating-point type, return an
11422 : : unsigned integer type with the same bitsize as TYPE. */
11423 : :
11424 : : tree
11425 : 78910112 : unsigned_type_for (tree type)
11426 : : {
11427 : 78910112 : return signed_or_unsigned_type_for (1, type);
11428 : : }
11429 : :
11430 : : /* If TYPE is an integral or pointer type, return an integer type with
11431 : : the same precision which is signed, or itself if TYPE is already a
11432 : : signed integer type. If TYPE is a floating-point type, return a
11433 : : signed integer type with the same bitsize as TYPE. */
11434 : :
11435 : : tree
11436 : 9355893 : signed_type_for (tree type)
11437 : : {
11438 : 9355893 : return signed_or_unsigned_type_for (0, type);
11439 : : }
11440 : :
11441 : : /* - For VECTOR_TYPEs:
11442 : : - The truth type must be a VECTOR_BOOLEAN_TYPE.
11443 : : - The number of elements must match (known_eq).
11444 : : - targetm.vectorize.get_mask_mode exists, and exactly
11445 : : the same mode as the truth type.
11446 : : - Otherwise, the truth type must be a BOOLEAN_TYPE
11447 : : or useless_type_conversion_p to BOOLEAN_TYPE. */
11448 : : bool
11449 : 1976 : is_truth_type_for (tree type, tree truth_type)
11450 : : {
11451 : 1976 : machine_mode mask_mode = TYPE_MODE (truth_type);
11452 : 1976 : machine_mode vmode = TYPE_MODE (type);
11453 : 1976 : machine_mode tmask_mode;
11454 : :
11455 : 1976 : if (TREE_CODE (type) == VECTOR_TYPE)
11456 : : {
11457 : 1976 : if (VECTOR_BOOLEAN_TYPE_P (truth_type)
11458 : 1976 : && known_eq (TYPE_VECTOR_SUBPARTS (type),
11459 : : TYPE_VECTOR_SUBPARTS (truth_type))
11460 : 1976 : && targetm.vectorize.get_mask_mode (vmode).exists (&tmask_mode)
11461 : 3952 : && tmask_mode == mask_mode)
11462 : 1957 : return true;
11463 : :
11464 : 19 : return false;
11465 : : }
11466 : :
11467 : 0 : return useless_type_conversion_p (boolean_type_node, truth_type);
11468 : : }
11469 : :
11470 : : /* If TYPE is a vector type, return a signed integer vector type with the
11471 : : same width and number of subparts. Otherwise return boolean_type_node. */
11472 : :
11473 : : tree
11474 : 4365542 : truth_type_for (tree type)
11475 : : {
11476 : 4365542 : if (TREE_CODE (type) == VECTOR_TYPE)
11477 : : {
11478 : 2509897 : if (VECTOR_BOOLEAN_TYPE_P (type))
11479 : : return type;
11480 : 2438655 : return build_truth_vector_type_for (type);
11481 : : }
11482 : : else
11483 : 1855645 : return boolean_type_node;
11484 : : }
11485 : :
11486 : : /* Returns the largest value obtainable by casting something in INNER type to
11487 : : OUTER type. */
11488 : :
11489 : : tree
11490 : 10919386 : upper_bound_in_type (tree outer, tree inner)
11491 : : {
11492 : 10919386 : unsigned int det = 0;
11493 : 10919386 : unsigned oprec = TYPE_PRECISION (outer);
11494 : 10919386 : unsigned iprec = TYPE_PRECISION (inner);
11495 : 10919386 : unsigned prec;
11496 : :
11497 : : /* Compute a unique number for every combination. */
11498 : 10919386 : det |= (oprec > iprec) ? 4 : 0;
11499 : 10919386 : det |= TYPE_UNSIGNED (outer) ? 2 : 0;
11500 : 10919386 : det |= TYPE_UNSIGNED (inner) ? 1 : 0;
11501 : :
11502 : : /* Determine the exponent to use. */
11503 : 10919386 : switch (det)
11504 : : {
11505 : 7184971 : case 0:
11506 : 7184971 : case 1:
11507 : : /* oprec <= iprec, outer: signed, inner: don't care. */
11508 : 7184971 : prec = oprec - 1;
11509 : 7184971 : break;
11510 : : case 2:
11511 : : case 3:
11512 : : /* oprec <= iprec, outer: unsigned, inner: don't care. */
11513 : : prec = oprec;
11514 : : break;
11515 : 21345 : case 4:
11516 : : /* oprec > iprec, outer: signed, inner: signed. */
11517 : 21345 : prec = iprec - 1;
11518 : 21345 : break;
11519 : : case 5:
11520 : : /* oprec > iprec, outer: signed, inner: unsigned. */
11521 : 11035 : prec = iprec;
11522 : : break;
11523 : : case 6:
11524 : : /* oprec > iprec, outer: unsigned, inner: signed. */
11525 : : prec = oprec;
11526 : : break;
11527 : : case 7:
11528 : : /* oprec > iprec, outer: unsigned, inner: unsigned. */
11529 : 11035 : prec = iprec;
11530 : : break;
11531 : : default:
11532 : : gcc_unreachable ();
11533 : : }
11534 : :
11535 : 10919386 : return wide_int_to_tree (outer,
11536 : 10919386 : wi::mask (prec, false, TYPE_PRECISION (outer)));
11537 : : }
11538 : :
11539 : : /* Returns the smallest value obtainable by casting something in INNER type to
11540 : : OUTER type. */
11541 : :
11542 : : tree
11543 : 8381079 : lower_bound_in_type (tree outer, tree inner)
11544 : : {
11545 : 8381079 : unsigned oprec = TYPE_PRECISION (outer);
11546 : 8381079 : unsigned iprec = TYPE_PRECISION (inner);
11547 : :
11548 : : /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
11549 : : and obtain 0. */
11550 : 8381079 : if (TYPE_UNSIGNED (outer)
11551 : : /* If we are widening something of an unsigned type, OUTER type
11552 : : contains all values of INNER type. In particular, both INNER
11553 : : and OUTER types have zero in common. */
11554 : 8381079 : || (oprec > iprec && TYPE_UNSIGNED (inner)))
11555 : 2314185 : return build_int_cst (outer, 0);
11556 : : else
11557 : : {
11558 : : /* If we are widening a signed type to another signed type, we
11559 : : want to obtain -2^^(iprec-1). If we are keeping the
11560 : : precision or narrowing to a signed type, we want to obtain
11561 : : -2^(oprec-1). */
11562 : 6066894 : unsigned prec = oprec > iprec ? iprec : oprec;
11563 : 6066894 : return wide_int_to_tree (outer,
11564 : 12133788 : wi::mask (prec - 1, true,
11565 : 6066894 : TYPE_PRECISION (outer)));
11566 : : }
11567 : : }
11568 : :
11569 : : /* Return true if two operands that are suitable for PHI nodes are
11570 : : necessarily equal. Specifically, both ARG0 and ARG1 must be either
11571 : : SSA_NAME or invariant. Note that this is strictly an optimization.
11572 : : That is, callers of this function can directly call operand_equal_p
11573 : : and get the same result, only slower. */
11574 : :
11575 : : bool
11576 : 22219288 : operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1)
11577 : : {
11578 : 22219288 : if (arg0 == arg1)
11579 : : return true;
11580 : 20194164 : if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
11581 : : return false;
11582 : 4225730 : return operand_equal_p (arg0, arg1, 0);
11583 : : }
11584 : :
11585 : : /* Returns number of zeros at the end of binary representation of X. */
11586 : :
11587 : : tree
11588 : 8935504 : num_ending_zeros (const_tree x)
11589 : : {
11590 : 8935504 : return build_int_cst (TREE_TYPE (x), wi::ctz (wi::to_wide (x)));
11591 : : }
11592 : :
11593 : :
11594 : : #define WALK_SUBTREE(NODE) \
11595 : : do \
11596 : : { \
11597 : : result = walk_tree_1 (&(NODE), func, data, pset, lh); \
11598 : : if (result) \
11599 : : return result; \
11600 : : } \
11601 : : while (0)
11602 : :
11603 : : /* This is a subroutine of walk_tree that walks field of TYPE that are to
11604 : : be walked whenever a type is seen in the tree. Rest of operands and return
11605 : : value are as for walk_tree. */
11606 : :
11607 : : static tree
11608 : 3986943987 : walk_type_fields (tree type, walk_tree_fn func, void *data,
11609 : : hash_set<tree> *pset, walk_tree_lh lh)
11610 : : {
11611 : 3986943987 : tree result = NULL_TREE;
11612 : :
11613 : 3986943987 : switch (TREE_CODE (type))
11614 : : {
11615 : 1180286694 : case POINTER_TYPE:
11616 : 1180286694 : case REFERENCE_TYPE:
11617 : 1180286694 : case VECTOR_TYPE:
11618 : : /* We have to worry about mutually recursive pointers. These can't
11619 : : be written in C. They can in Ada. It's pathological, but
11620 : : there's an ACATS test (c38102a) that checks it. Deal with this
11621 : : by checking if we're pointing to another pointer, that one
11622 : : points to another pointer, that one does too, and we have no htab.
11623 : : If so, get a hash table. We check three levels deep to avoid
11624 : : the cost of the hash table if we don't need one. */
11625 : 2330994116 : if (POINTER_TYPE_P (TREE_TYPE (type))
11626 : 29579339 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
11627 : 4863214 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
11628 : 1185109072 : && !pset)
11629 : : {
11630 : 0 : result = walk_tree_without_duplicates (&TREE_TYPE (type),
11631 : : func, data);
11632 : 0 : if (result)
11633 : : return result;
11634 : :
11635 : : break;
11636 : : }
11637 : :
11638 : : /* fall through */
11639 : :
11640 : 1183529700 : case COMPLEX_TYPE:
11641 : 1183529700 : WALK_SUBTREE (TREE_TYPE (type));
11642 : : break;
11643 : :
11644 : 225214070 : case METHOD_TYPE:
11645 : 225214070 : WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
11646 : :
11647 : : /* Fall through. */
11648 : :
11649 : 371622488 : case FUNCTION_TYPE:
11650 : 371622488 : WALK_SUBTREE (TREE_TYPE (type));
11651 : 371622450 : {
11652 : 371622450 : tree arg;
11653 : :
11654 : : /* We never want to walk into default arguments. */
11655 : 1430984720 : for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
11656 : 1059392188 : WALK_SUBTREE (TREE_VALUE (arg));
11657 : : }
11658 : : break;
11659 : :
11660 : 12532908 : case ARRAY_TYPE:
11661 : : /* Don't follow this nodes's type if a pointer for fear that
11662 : : we'll have infinite recursion. If we have a PSET, then we
11663 : : need not fear. */
11664 : 12532908 : if (pset
11665 : 12532908 : || (!POINTER_TYPE_P (TREE_TYPE (type))
11666 : 103004 : && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
11667 : 12531183 : WALK_SUBTREE (TREE_TYPE (type));
11668 : 12530303 : WALK_SUBTREE (TYPE_DOMAIN (type));
11669 : : break;
11670 : :
11671 : 943445 : case OFFSET_TYPE:
11672 : 943445 : WALK_SUBTREE (TREE_TYPE (type));
11673 : 942613 : WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
11674 : : break;
11675 : :
11676 : : default:
11677 : : break;
11678 : : }
11679 : :
11680 : : return NULL_TREE;
11681 : : }
11682 : :
11683 : : /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
11684 : : called with the DATA and the address of each sub-tree. If FUNC returns a
11685 : : non-NULL value, the traversal is stopped, and the value returned by FUNC
11686 : : is returned. If PSET is non-NULL it is used to record the nodes visited,
11687 : : and to avoid visiting a node more than once. */
11688 : :
11689 : : tree
11690 : 99297366064 : walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
11691 : : hash_set<tree> *pset, walk_tree_lh lh)
11692 : : {
11693 : : #define WALK_SUBTREE_TAIL(NODE) \
11694 : : do \
11695 : : { \
11696 : : tp = & (NODE); \
11697 : : goto tail_recurse; \
11698 : : } \
11699 : : while (0)
11700 : :
11701 : >12048*10^7 : tail_recurse:
11702 : : /* Skip empty subtrees. */
11703 : >12048*10^7 : if (!*tp)
11704 : : return NULL_TREE;
11705 : :
11706 : : /* Don't walk the same tree twice, if the user has requested
11707 : : that we avoid doing so. */
11708 : 98845693834 : if (pset && pset->add (*tp))
11709 : : return NULL_TREE;
11710 : :
11711 : : /* Call the function. */
11712 : 97615807778 : int walk_subtrees = 1;
11713 : 97615807778 : tree result = (*func) (tp, &walk_subtrees, data);
11714 : :
11715 : : /* If we found something, return it. */
11716 : 97615807778 : if (result)
11717 : : return result;
11718 : :
11719 : 97551679202 : tree t = *tp;
11720 : 97551679202 : tree_code code = TREE_CODE (t);
11721 : :
11722 : : /* Even if we didn't, FUNC may have decided that there was nothing
11723 : : interesting below this point in the tree. */
11724 : 97551679202 : if (!walk_subtrees)
11725 : : {
11726 : : /* But we still need to check our siblings. */
11727 : 63996045560 : if (code == TREE_LIST)
11728 : 85678 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11729 : 63995959882 : else if (code == OMP_CLAUSE)
11730 : 877324 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11731 : : else
11732 : : return NULL_TREE;
11733 : : }
11734 : :
11735 : 33555633642 : if (lh)
11736 : : {
11737 : 16751589369 : result = (*lh) (tp, &walk_subtrees, func, data, pset);
11738 : 16751589369 : if (result || !walk_subtrees)
11739 : 2335199966 : return result;
11740 : : }
11741 : :
11742 : 31220433676 : switch (code)
11743 : : {
11744 : : case ERROR_MARK:
11745 : : case IDENTIFIER_NODE:
11746 : : case INTEGER_CST:
11747 : : case REAL_CST:
11748 : : case FIXED_CST:
11749 : : case STRING_CST:
11750 : : case BLOCK:
11751 : : case PLACEHOLDER_EXPR:
11752 : : case SSA_NAME:
11753 : : case FIELD_DECL:
11754 : : case RESULT_DECL:
11755 : : /* None of these have subtrees other than those already walked
11756 : : above. */
11757 : : break;
11758 : :
11759 : 235075702 : case TREE_LIST:
11760 : 235075702 : WALK_SUBTREE (TREE_VALUE (t));
11761 : 234649048 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11762 : :
11763 : 864836730 : case TREE_VEC:
11764 : 864836730 : {
11765 : 864836730 : int len = TREE_VEC_LENGTH (t);
11766 : :
11767 : 864836730 : if (len == 0)
11768 : : break;
11769 : :
11770 : : /* Walk all elements but the last. */
11771 : 1718108447 : for (int i = 0; i < len - 1; ++i)
11772 : 862686148 : WALK_SUBTREE (TREE_VEC_ELT (t, i));
11773 : :
11774 : : /* Now walk the last one as a tail call. */
11775 : 855422299 : WALK_SUBTREE_TAIL (TREE_VEC_ELT (t, len - 1));
11776 : : }
11777 : :
11778 : 4734939 : case VECTOR_CST:
11779 : 4734939 : {
11780 : 4734939 : unsigned len = vector_cst_encoded_nelts (t);
11781 : 4734939 : if (len == 0)
11782 : : break;
11783 : : /* Walk all elements but the last. */
11784 : 16440517 : for (unsigned i = 0; i < len - 1; ++i)
11785 : 11705722 : WALK_SUBTREE (VECTOR_CST_ENCODED_ELT (t, i));
11786 : : /* Now walk the last one as a tail call. */
11787 : 4734795 : WALK_SUBTREE_TAIL (VECTOR_CST_ENCODED_ELT (t, len - 1));
11788 : : }
11789 : :
11790 : 596321 : case COMPLEX_CST:
11791 : 596321 : WALK_SUBTREE (TREE_REALPART (t));
11792 : 594755 : WALK_SUBTREE_TAIL (TREE_IMAGPART (t));
11793 : :
11794 : : case CONSTRUCTOR:
11795 : : {
11796 : : unsigned HOST_WIDE_INT idx;
11797 : : constructor_elt *ce;
11798 : :
11799 : 638359519 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce);
11800 : : idx++)
11801 : 236638598 : WALK_SUBTREE (ce->value);
11802 : : }
11803 : : break;
11804 : :
11805 : 3576786 : case SAVE_EXPR:
11806 : 3576786 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, 0));
11807 : :
11808 : 165847534 : case BIND_EXPR:
11809 : 165847534 : {
11810 : 165847534 : tree decl;
11811 : 270452109 : for (decl = BIND_EXPR_VARS (t); decl; decl = DECL_CHAIN (decl))
11812 : : {
11813 : : /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
11814 : : into declarations that are just mentioned, rather than
11815 : : declared; they don't really belong to this part of the tree.
11816 : : And, we can see cycles: the initializer for a declaration
11817 : : can refer to the declaration itself. */
11818 : 104604599 : WALK_SUBTREE (DECL_INITIAL (decl));
11819 : 104604575 : WALK_SUBTREE (DECL_SIZE (decl));
11820 : 104604575 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
11821 : : }
11822 : 165847510 : WALK_SUBTREE_TAIL (BIND_EXPR_BODY (t));
11823 : : }
11824 : :
11825 : 176908071 : case STATEMENT_LIST:
11826 : 176908071 : {
11827 : 176908071 : tree_stmt_iterator i;
11828 : 651949496 : for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
11829 : 475187408 : WALK_SUBTREE (*tsi_stmt_ptr (i));
11830 : : }
11831 : 176762088 : break;
11832 : :
11833 : 1728211 : case OMP_CLAUSE:
11834 : 1728211 : {
11835 : 1728211 : int len = omp_clause_num_ops[OMP_CLAUSE_CODE (t)];
11836 : : /* Do not walk the iterator operand of OpenMP MAP clauses. */
11837 : 1728211 : if (OMP_CLAUSE_HAS_ITERATORS (t))
11838 : 818 : len--;
11839 : 4894141 : for (int i = 0; i < len; i++)
11840 : 3165930 : WALK_SUBTREE (OMP_CLAUSE_OPERAND (t, i));
11841 : 1728211 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11842 : : }
11843 : :
11844 : 48668761 : case TARGET_EXPR:
11845 : 48668761 : {
11846 : 48668761 : int i, len;
11847 : :
11848 : : /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
11849 : : But, we only want to walk once. */
11850 : 48668761 : len = (TREE_OPERAND (t, 3) == TREE_OPERAND (t, 1)) ? 2 : 3;
11851 : 194639598 : for (i = 0; i < len; ++i)
11852 : 145987350 : WALK_SUBTREE (TREE_OPERAND (t, i));
11853 : 48652248 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len));
11854 : : }
11855 : :
11856 : 100025934 : case DECL_EXPR:
11857 : : /* If this is a TYPE_DECL, walk into the fields of the type that it's
11858 : : defining. We only want to walk into these fields of a type in this
11859 : : case and not in the general case of a mere reference to the type.
11860 : :
11861 : : The criterion is as follows: if the field can be an expression, it
11862 : : must be walked only here. This should be in keeping with the fields
11863 : : that are directly gimplified in gimplify_type_sizes in order for the
11864 : : mark/copy-if-shared/unmark machinery of the gimplifier to work with
11865 : : variable-sized types.
11866 : :
11867 : : Note that DECLs get walked as part of processing the BIND_EXPR. */
11868 : 100025934 : if (TREE_CODE (DECL_EXPR_DECL (t)) == TYPE_DECL)
11869 : : {
11870 : : /* Call the function for the decl so e.g. copy_tree_body_r can
11871 : : replace it with the remapped one. */
11872 : 961779 : result = (*func) (&DECL_EXPR_DECL (t), &walk_subtrees, data);
11873 : 961779 : if (result || !walk_subtrees)
11874 : 44137 : return result;
11875 : :
11876 : 917642 : tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (t));
11877 : 917642 : if (TREE_CODE (*type_p) == ERROR_MARK)
11878 : : return NULL_TREE;
11879 : :
11880 : : /* Call the function for the type. See if it returns anything or
11881 : : doesn't want us to continue. If we are to continue, walk both
11882 : : the normal fields and those for the declaration case. */
11883 : 917642 : result = (*func) (type_p, &walk_subtrees, data);
11884 : 917642 : if (result || !walk_subtrees)
11885 : 78063 : return result;
11886 : :
11887 : 839579 : tree type = *type_p;
11888 : :
11889 : : /* But do not walk a pointed-to type since it may itself need to
11890 : : be walked in the declaration case if it isn't anonymous. */
11891 : 839579 : if (!POINTER_TYPE_P (type))
11892 : : {
11893 : 823886 : result = walk_type_fields (type, func, data, pset, lh);
11894 : 823886 : if (result)
11895 : : return result;
11896 : : }
11897 : :
11898 : : /* If this is a record type, also walk the fields. */
11899 : 839579 : if (RECORD_OR_UNION_TYPE_P (type))
11900 : : {
11901 : 315847 : tree field;
11902 : :
11903 : 1340951 : for (field = TYPE_FIELDS (type); field;
11904 : 1025104 : field = DECL_CHAIN (field))
11905 : : {
11906 : : /* We'd like to look at the type of the field, but we can
11907 : : easily get infinite recursion. So assume it's pointed
11908 : : to elsewhere in the tree. Also, ignore things that
11909 : : aren't fields. */
11910 : 1025104 : if (TREE_CODE (field) != FIELD_DECL)
11911 : 735628 : continue;
11912 : :
11913 : 289476 : WALK_SUBTREE (DECL_FIELD_OFFSET (field));
11914 : 289476 : WALK_SUBTREE (DECL_SIZE (field));
11915 : 289476 : WALK_SUBTREE (DECL_SIZE_UNIT (field));
11916 : 289476 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
11917 : 0 : WALK_SUBTREE (DECL_QUALIFIER (field));
11918 : : }
11919 : : }
11920 : :
11921 : : /* Same for scalar types. */
11922 : 523732 : else if (TREE_CODE (type) == BOOLEAN_TYPE
11923 : : || TREE_CODE (type) == ENUMERAL_TYPE
11924 : 523732 : || TREE_CODE (type) == INTEGER_TYPE
11925 : 523694 : || TREE_CODE (type) == FIXED_POINT_TYPE
11926 : 523694 : || TREE_CODE (type) == REAL_TYPE)
11927 : : {
11928 : 38 : WALK_SUBTREE (TYPE_MIN_VALUE (type));
11929 : 38 : WALK_SUBTREE (TYPE_MAX_VALUE (type));
11930 : : }
11931 : :
11932 : 839579 : WALK_SUBTREE (TYPE_SIZE (type));
11933 : 839579 : WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (type));
11934 : : }
11935 : : /* FALLTHRU */
11936 : :
11937 : 26316398847 : default:
11938 : 26316398847 : if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
11939 : : {
11940 : 20016751920 : int i, len;
11941 : :
11942 : : /* Walk over all the sub-trees of this operand. */
11943 : 20016751920 : len = TREE_OPERAND_LENGTH (t);
11944 : :
11945 : : /* Go through the subtrees. We need to do this in forward order so
11946 : : that the scope of a FOR_EXPR is handled properly. */
11947 : 20016751920 : if (len)
11948 : : {
11949 : 41482784630 : for (i = 0; i < len - 1; ++i)
11950 : 21608430379 : WALK_SUBTREE (TREE_OPERAND (t, i));
11951 : 19874354251 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len - 1));
11952 : : }
11953 : : }
11954 : : /* If this is a type, walk the needed fields in the type. */
11955 : 6299646927 : else if (TYPE_P (t))
11956 : 3986120101 : return walk_type_fields (t, func, data, pset, lh);
11957 : : break;
11958 : : }
11959 : :
11960 : : /* We didn't find what we were looking for. */
11961 : : return NULL_TREE;
11962 : :
11963 : : #undef WALK_SUBTREE_TAIL
11964 : : }
11965 : : #undef WALK_SUBTREE
11966 : :
11967 : : /* Like walk_tree, but does not walk duplicate nodes more than once. */
11968 : :
11969 : : tree
11970 : 2880444200 : walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data,
11971 : : walk_tree_lh lh)
11972 : : {
11973 : 2880444200 : tree result;
11974 : :
11975 : 2880444200 : hash_set<tree> pset;
11976 : 2880444200 : result = walk_tree_1 (tp, func, data, &pset, lh);
11977 : 2880444200 : return result;
11978 : 2880444200 : }
11979 : :
11980 : :
11981 : : tree
11982 : 902940175 : tree_block (tree t)
11983 : : {
11984 : 902940175 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
11985 : :
11986 : 902940175 : if (IS_EXPR_CODE_CLASS (c))
11987 : 902940175 : return LOCATION_BLOCK (t->exp.locus);
11988 : 0 : gcc_unreachable ();
11989 : : return NULL;
11990 : : }
11991 : :
11992 : : void
11993 : 475733406 : tree_set_block (tree t, tree b)
11994 : : {
11995 : 475733406 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
11996 : :
11997 : 475733406 : if (IS_EXPR_CODE_CLASS (c))
11998 : : {
11999 : 475733406 : t->exp.locus = set_block (t->exp.locus, b);
12000 : : }
12001 : : else
12002 : 0 : gcc_unreachable ();
12003 : 475733406 : }
12004 : :
12005 : : /* Create a nameless artificial label and put it in the current
12006 : : function context. The label has a location of LOC. Returns the
12007 : : newly created label. */
12008 : :
12009 : : tree
12010 : 31704467 : create_artificial_label (location_t loc)
12011 : : {
12012 : 31704467 : tree lab = build_decl (loc,
12013 : : LABEL_DECL, NULL_TREE, void_type_node);
12014 : :
12015 : 31704467 : DECL_ARTIFICIAL (lab) = 1;
12016 : 31704467 : DECL_IGNORED_P (lab) = 1;
12017 : 31704467 : DECL_CONTEXT (lab) = current_function_decl;
12018 : 31704467 : return lab;
12019 : : }
12020 : :
12021 : : /* Given a tree, try to return a useful variable name that we can use
12022 : : to prefix a temporary that is being assigned the value of the tree.
12023 : : I.E. given <temp> = &A, return A. */
12024 : :
12025 : : const char *
12026 : 24949279 : get_name (tree t)
12027 : : {
12028 : 26845357 : tree stripped_decl;
12029 : :
12030 : 26845357 : stripped_decl = t;
12031 : 26845357 : STRIP_NOPS (stripped_decl);
12032 : 26845357 : if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl))
12033 : 4076188 : return IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
12034 : 22769169 : else if (TREE_CODE (stripped_decl) == SSA_NAME)
12035 : : {
12036 : 1296457 : tree name = SSA_NAME_IDENTIFIER (stripped_decl);
12037 : 319119 : if (!name)
12038 : : return NULL;
12039 : 317807 : return IDENTIFIER_POINTER (name);
12040 : : }
12041 : : else
12042 : : {
12043 : 21472712 : switch (TREE_CODE (stripped_decl))
12044 : : {
12045 : 1896078 : case ADDR_EXPR:
12046 : 1896078 : return get_name (TREE_OPERAND (stripped_decl, 0));
12047 : : default:
12048 : : return NULL;
12049 : : }
12050 : : }
12051 : : }
12052 : :
12053 : : /* Return true if TYPE has a variable argument list. */
12054 : :
12055 : : bool
12056 : 214380153 : stdarg_p (const_tree fntype)
12057 : : {
12058 : 214380153 : function_args_iterator args_iter;
12059 : 214380153 : tree n = NULL_TREE, t;
12060 : :
12061 : 214380153 : if (!fntype)
12062 : : return false;
12063 : :
12064 : 214246550 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
12065 : : return true;
12066 : :
12067 : 869945214 : FOREACH_FUNCTION_ARGS (fntype, t, args_iter)
12068 : : {
12069 : 656404345 : n = t;
12070 : : }
12071 : :
12072 : 213540869 : return n != NULL_TREE && n != void_type_node;
12073 : : }
12074 : :
12075 : : /* Return true if TYPE has a prototype. */
12076 : :
12077 : : bool
12078 : 724725759 : prototype_p (const_tree fntype)
12079 : : {
12080 : 724725759 : tree t;
12081 : :
12082 : 724725759 : gcc_assert (fntype != NULL_TREE);
12083 : :
12084 : 724725759 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
12085 : : return true;
12086 : :
12087 : 723926878 : t = TYPE_ARG_TYPES (fntype);
12088 : 723926878 : return (t != NULL_TREE);
12089 : : }
12090 : :
12091 : : /* If BLOCK is inlined from an __attribute__((__artificial__))
12092 : : routine, return pointer to location from where it has been
12093 : : called. */
12094 : : location_t *
12095 : 180103 : block_nonartificial_location (tree block)
12096 : : {
12097 : 180103 : location_t *ret = NULL;
12098 : :
12099 : 463319 : while (block && TREE_CODE (block) == BLOCK
12100 : 560867 : && BLOCK_ABSTRACT_ORIGIN (block))
12101 : : {
12102 : 176599 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12103 : 176599 : if (TREE_CODE (ao) == FUNCTION_DECL)
12104 : : {
12105 : : /* If AO is an artificial inline, point RET to the
12106 : : call site locus at which it has been inlined and continue
12107 : : the loop, in case AO's caller is also an artificial
12108 : : inline. */
12109 : 75247 : if (DECL_DECLARED_INLINE_P (ao)
12110 : 75247 : && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
12111 : 1813 : ret = &BLOCK_SOURCE_LOCATION (block);
12112 : : else
12113 : : break;
12114 : : }
12115 : 101352 : else if (TREE_CODE (ao) != BLOCK)
12116 : : break;
12117 : :
12118 : 103165 : block = BLOCK_SUPERCONTEXT (block);
12119 : : }
12120 : 180103 : return ret;
12121 : : }
12122 : :
12123 : :
12124 : : /* If EXP is inlined from an __attribute__((__artificial__))
12125 : : function, return the location of the original call expression. */
12126 : :
12127 : : location_t
12128 : 52 : tree_nonartificial_location (tree exp)
12129 : : {
12130 : 52 : location_t *loc = block_nonartificial_location (TREE_BLOCK (exp));
12131 : :
12132 : 52 : if (loc)
12133 : 0 : return *loc;
12134 : : else
12135 : 52 : return EXPR_LOCATION (exp);
12136 : : }
12137 : :
12138 : : /* Return the location into which EXP has been inlined. Analogous
12139 : : to tree_nonartificial_location() above but not limited to artificial
12140 : : functions declared inline. If SYSTEM_HEADER is true, return
12141 : : the macro expansion point of the location if it's in a system header */
12142 : :
12143 : : location_t
12144 : 0 : tree_inlined_location (tree exp, bool system_header /* = true */)
12145 : : {
12146 : 0 : location_t loc = UNKNOWN_LOCATION;
12147 : :
12148 : 0 : tree block = TREE_BLOCK (exp);
12149 : :
12150 : 0 : while (block && TREE_CODE (block) == BLOCK
12151 : 0 : && BLOCK_ABSTRACT_ORIGIN (block))
12152 : : {
12153 : 0 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12154 : 0 : if (TREE_CODE (ao) == FUNCTION_DECL)
12155 : 0 : loc = BLOCK_SOURCE_LOCATION (block);
12156 : 0 : else if (TREE_CODE (ao) != BLOCK)
12157 : : break;
12158 : :
12159 : 0 : block = BLOCK_SUPERCONTEXT (block);
12160 : : }
12161 : :
12162 : 0 : if (loc == UNKNOWN_LOCATION)
12163 : : {
12164 : 0 : loc = EXPR_LOCATION (exp);
12165 : 0 : if (system_header)
12166 : : /* Only consider macro expansion when the block traversal failed
12167 : : to find a location. Otherwise it's not relevant. */
12168 : 0 : return expansion_point_location_if_in_system_header (loc);
12169 : : }
12170 : :
12171 : : return loc;
12172 : : }
12173 : :
12174 : : /* These are the hash table functions for the hash table of OPTIMIZATION_NODE
12175 : : nodes. */
12176 : :
12177 : : /* Return the hash code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
12178 : :
12179 : : hashval_t
12180 : 987766775 : cl_option_hasher::hash (tree x)
12181 : : {
12182 : 987766775 : const_tree const t = x;
12183 : :
12184 : 987766775 : if (TREE_CODE (t) == OPTIMIZATION_NODE)
12185 : 222054051 : return cl_optimization_hash (TREE_OPTIMIZATION (t));
12186 : 765712724 : else if (TREE_CODE (t) == TARGET_OPTION_NODE)
12187 : 765712724 : return cl_target_option_hash (TREE_TARGET_OPTION (t));
12188 : : else
12189 : 0 : gcc_unreachable ();
12190 : : }
12191 : :
12192 : : /* Return nonzero if the value represented by *X (an OPTIMIZATION or
12193 : : TARGET_OPTION tree node) is the same as that given by *Y, which is the
12194 : : same. */
12195 : :
12196 : : bool
12197 : 967940669 : cl_option_hasher::equal (tree x, tree y)
12198 : : {
12199 : 967940669 : const_tree const xt = x;
12200 : 967940669 : const_tree const yt = y;
12201 : :
12202 : 967940669 : if (TREE_CODE (xt) != TREE_CODE (yt))
12203 : : return false;
12204 : :
12205 : 519680261 : if (TREE_CODE (xt) == OPTIMIZATION_NODE)
12206 : 96449982 : return cl_optimization_option_eq (TREE_OPTIMIZATION (xt),
12207 : 96449982 : TREE_OPTIMIZATION (yt));
12208 : 423230279 : else if (TREE_CODE (xt) == TARGET_OPTION_NODE)
12209 : 423230279 : return cl_target_option_eq (TREE_TARGET_OPTION (xt),
12210 : 423230279 : TREE_TARGET_OPTION (yt));
12211 : : else
12212 : 0 : gcc_unreachable ();
12213 : : }
12214 : :
12215 : : /* Build an OPTIMIZATION_NODE based on the options in OPTS and OPTS_SET. */
12216 : :
12217 : : tree
12218 : 96718332 : build_optimization_node (struct gcc_options *opts,
12219 : : struct gcc_options *opts_set)
12220 : : {
12221 : 96718332 : tree t;
12222 : :
12223 : : /* Use the cache of optimization nodes. */
12224 : :
12225 : 96718332 : cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node),
12226 : : opts, opts_set);
12227 : :
12228 : 96718332 : tree *slot = cl_option_hash_table->find_slot (cl_optimization_node, INSERT);
12229 : 96718332 : t = *slot;
12230 : 96718332 : if (!t)
12231 : : {
12232 : : /* Insert this one into the hash table. */
12233 : 292229 : t = cl_optimization_node;
12234 : 292229 : *slot = t;
12235 : :
12236 : : /* Make a new node for next time round. */
12237 : 292229 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
12238 : : }
12239 : :
12240 : 96718332 : return t;
12241 : : }
12242 : :
12243 : : /* Build a TARGET_OPTION_NODE based on the options in OPTS and OPTS_SET. */
12244 : :
12245 : : tree
12246 : 74944160 : build_target_option_node (struct gcc_options *opts,
12247 : : struct gcc_options *opts_set)
12248 : : {
12249 : 74944160 : tree t;
12250 : :
12251 : : /* Use the cache of optimization nodes. */
12252 : :
12253 : 74944160 : cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node),
12254 : : opts, opts_set);
12255 : :
12256 : 74944160 : tree *slot = cl_option_hash_table->find_slot (cl_target_option_node, INSERT);
12257 : 74944160 : t = *slot;
12258 : 74944160 : if (!t)
12259 : : {
12260 : : /* Insert this one into the hash table. */
12261 : 765932 : t = cl_target_option_node;
12262 : 765932 : *slot = t;
12263 : :
12264 : : /* Make a new node for next time round. */
12265 : 765932 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
12266 : : }
12267 : :
12268 : 74944160 : return t;
12269 : : }
12270 : :
12271 : : /* Clear TREE_TARGET_GLOBALS of all TARGET_OPTION_NODE trees,
12272 : : so that they aren't saved during PCH writing. */
12273 : :
12274 : : void
12275 : 458 : prepare_target_option_nodes_for_pch (void)
12276 : : {
12277 : 458 : hash_table<cl_option_hasher>::iterator iter = cl_option_hash_table->begin ();
12278 : 2748 : for (; iter != cl_option_hash_table->end (); ++iter)
12279 : 916 : if (TREE_CODE (*iter) == TARGET_OPTION_NODE)
12280 : 458 : TREE_TARGET_GLOBALS (*iter) = NULL;
12281 : 458 : }
12282 : :
12283 : : /* Determine the "ultimate origin" of a block. */
12284 : :
12285 : : tree
12286 : 218382894 : block_ultimate_origin (const_tree block)
12287 : : {
12288 : 218382894 : tree origin = BLOCK_ABSTRACT_ORIGIN (block);
12289 : :
12290 : 218382894 : if (origin == NULL_TREE)
12291 : : return NULL_TREE;
12292 : : else
12293 : : {
12294 : 263972007 : gcc_checking_assert ((DECL_P (origin)
12295 : : && DECL_ORIGIN (origin) == origin)
12296 : : || BLOCK_ORIGIN (origin) == origin);
12297 : : return origin;
12298 : : }
12299 : : }
12300 : :
12301 : : /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates
12302 : : no instruction. */
12303 : :
12304 : : bool
12305 : 1386875456 : tree_nop_conversion_p (const_tree outer_type, const_tree inner_type)
12306 : : {
12307 : : /* Do not strip casts into or out of differing address spaces. */
12308 : 1386875456 : if (POINTER_TYPE_P (outer_type)
12309 : 1386875456 : && TYPE_ADDR_SPACE (TREE_TYPE (outer_type)) != ADDR_SPACE_GENERIC)
12310 : : {
12311 : 570 : if (!POINTER_TYPE_P (inner_type)
12312 : 570 : || (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
12313 : 547 : != TYPE_ADDR_SPACE (TREE_TYPE (inner_type))))
12314 : : return false;
12315 : : }
12316 : 1386874886 : else if (POINTER_TYPE_P (inner_type)
12317 : 1386874886 : && TYPE_ADDR_SPACE (TREE_TYPE (inner_type)) != ADDR_SPACE_GENERIC)
12318 : : {
12319 : : /* We already know that outer_type is not a pointer with
12320 : : a non-generic address space. */
12321 : : return false;
12322 : : }
12323 : :
12324 : : /* Use precision rather then machine mode when we can, which gives
12325 : : the correct answer even for submode (bit-field) types. */
12326 : 1386872719 : if ((INTEGRAL_TYPE_P (outer_type)
12327 : 471900889 : || POINTER_TYPE_P (outer_type)
12328 : 74834354 : || TREE_CODE (outer_type) == OFFSET_TYPE)
12329 : 1312049649 : && (INTEGRAL_TYPE_P (inner_type)
12330 : 476837337 : || POINTER_TYPE_P (inner_type)
12331 : 1511067 : || TREE_CODE (inner_type) == OFFSET_TYPE))
12332 : 1310562847 : return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type);
12333 : :
12334 : : /* Otherwise fall back on comparing machine modes (e.g. for
12335 : : aggregate types, floats). */
12336 : 76309872 : return TYPE_MODE (outer_type) == TYPE_MODE (inner_type);
12337 : : }
12338 : :
12339 : : /* Return true iff conversion in EXP generates no instruction. Mark
12340 : : it inline so that we fully inline into the stripping functions even
12341 : : though we have two uses of this function. */
12342 : :
12343 : : static inline bool
12344 : 18099210866 : tree_nop_conversion (const_tree exp)
12345 : : {
12346 : 18099210866 : tree outer_type, inner_type;
12347 : :
12348 : 18099210866 : if (location_wrapper_p (exp))
12349 : : return true;
12350 : 18052102574 : if (!CONVERT_EXPR_P (exp)
12351 : 17236044898 : && TREE_CODE (exp) != NON_LVALUE_EXPR)
12352 : : return false;
12353 : :
12354 : 829778076 : outer_type = TREE_TYPE (exp);
12355 : 829778076 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12356 : 829778076 : if (!inner_type || inner_type == error_mark_node)
12357 : : return false;
12358 : :
12359 : 829767252 : return tree_nop_conversion_p (outer_type, inner_type);
12360 : : }
12361 : :
12362 : : /* Return true iff conversion in EXP generates no instruction. Don't
12363 : : consider conversions changing the signedness. */
12364 : :
12365 : : static bool
12366 : 1837898805 : tree_sign_nop_conversion (const_tree exp)
12367 : : {
12368 : 1837898805 : tree outer_type, inner_type;
12369 : :
12370 : 1837898805 : if (!tree_nop_conversion (exp))
12371 : : return false;
12372 : :
12373 : 141461758 : outer_type = TREE_TYPE (exp);
12374 : 141461758 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12375 : :
12376 : 141461758 : return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type)
12377 : 141461758 : && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
12378 : : }
12379 : :
12380 : : /* Strip conversions from EXP according to tree_nop_conversion and
12381 : : return the resulting expression. */
12382 : :
12383 : : tree
12384 : 15669643852 : tree_strip_nop_conversions (tree exp)
12385 : : {
12386 : 16261312061 : while (tree_nop_conversion (exp))
12387 : 591668209 : exp = TREE_OPERAND (exp, 0);
12388 : 15669643852 : return exp;
12389 : : }
12390 : :
12391 : : /* Strip conversions from EXP according to tree_sign_nop_conversion
12392 : : and return the resulting expression. */
12393 : :
12394 : : tree
12395 : 1720768748 : tree_strip_sign_nop_conversions (tree exp)
12396 : : {
12397 : 1837898805 : while (tree_sign_nop_conversion (exp))
12398 : 117130057 : exp = TREE_OPERAND (exp, 0);
12399 : 1720768748 : return exp;
12400 : : }
12401 : :
12402 : : /* Avoid any floating point extensions from EXP. */
12403 : : tree
12404 : 87383128 : strip_float_extensions (tree exp)
12405 : : {
12406 : 87529634 : tree sub, expt, subt;
12407 : :
12408 : : /* For floating point constant look up the narrowest type that can hold
12409 : : it properly and handle it like (type)(narrowest_type)constant.
12410 : : This way we can optimize for instance a=a*2.0 where "a" is float
12411 : : but 2.0 is double constant. */
12412 : 87529634 : if (TREE_CODE (exp) == REAL_CST && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp)))
12413 : : {
12414 : 2652794 : REAL_VALUE_TYPE orig;
12415 : 2652794 : tree type = NULL;
12416 : :
12417 : 2652794 : orig = TREE_REAL_CST (exp);
12418 : 2652794 : if (TYPE_PRECISION (TREE_TYPE (exp)) > TYPE_PRECISION (float_type_node)
12419 : 2652794 : && exact_real_truncate (TYPE_MODE (float_type_node), &orig))
12420 : 141720 : type = float_type_node;
12421 : 2511074 : else if (TYPE_PRECISION (TREE_TYPE (exp))
12422 : 2511074 : > TYPE_PRECISION (double_type_node)
12423 : 2511074 : && exact_real_truncate (TYPE_MODE (double_type_node), &orig))
12424 : 35199 : type = double_type_node;
12425 : 2652794 : if (type)
12426 : 176919 : return build_real_truncate (type, orig);
12427 : : }
12428 : :
12429 : 87352715 : if (!CONVERT_EXPR_P (exp))
12430 : : return exp;
12431 : :
12432 : 4261203 : sub = TREE_OPERAND (exp, 0);
12433 : 4261203 : subt = TREE_TYPE (sub);
12434 : 4261203 : expt = TREE_TYPE (exp);
12435 : :
12436 : 4261203 : if (!FLOAT_TYPE_P (subt))
12437 : : return exp;
12438 : :
12439 : 511036 : if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_FLOAT_TYPE_P (subt))
12440 : : return exp;
12441 : :
12442 : 170710 : if (element_precision (subt) > element_precision (expt))
12443 : : return exp;
12444 : :
12445 : : return strip_float_extensions (sub);
12446 : : }
12447 : :
12448 : : /* Strip out all handled components that produce invariant
12449 : : offsets. */
12450 : :
12451 : : const_tree
12452 : 5815046248 : strip_invariant_refs (const_tree op)
12453 : : {
12454 : 6776750022 : while (handled_component_p (op))
12455 : : {
12456 : 973570132 : switch (TREE_CODE (op))
12457 : : {
12458 : 194665244 : case ARRAY_REF:
12459 : 194665244 : case ARRAY_RANGE_REF:
12460 : 194665244 : if (!is_gimple_constant (TREE_OPERAND (op, 1))
12461 : 184484628 : || TREE_OPERAND (op, 2) != NULL_TREE
12462 : 182931369 : || TREE_OPERAND (op, 3) != NULL_TREE)
12463 : : return NULL;
12464 : : break;
12465 : :
12466 : 778612962 : case COMPONENT_REF:
12467 : 778612962 : if (TREE_OPERAND (op, 2) != NULL_TREE)
12468 : : return NULL;
12469 : : break;
12470 : :
12471 : 961703774 : default:;
12472 : : }
12473 : 961703774 : op = TREE_OPERAND (op, 0);
12474 : : }
12475 : :
12476 : : return op;
12477 : : }
12478 : :
12479 : : /* Strip handled components with zero offset from OP. */
12480 : :
12481 : : tree
12482 : 563979 : strip_zero_offset_components (tree op)
12483 : : {
12484 : 563979 : while (TREE_CODE (op) == COMPONENT_REF
12485 : 435733 : && integer_zerop (DECL_FIELD_OFFSET (TREE_OPERAND (op, 1)))
12486 : 1115002 : && integer_zerop (DECL_FIELD_BIT_OFFSET (TREE_OPERAND (op, 1))))
12487 : 181634 : op = TREE_OPERAND (op, 0);
12488 : 563979 : return op;
12489 : : }
12490 : :
12491 : : static GTY(()) tree gcc_eh_personality_decl;
12492 : :
12493 : : /* Return the GCC personality function decl. */
12494 : :
12495 : : tree
12496 : 395 : lhd_gcc_personality (void)
12497 : : {
12498 : 395 : if (!gcc_eh_personality_decl)
12499 : 153 : gcc_eh_personality_decl = build_personality_function ("gcc");
12500 : 395 : return gcc_eh_personality_decl;
12501 : : }
12502 : :
12503 : : /* TARGET is a call target of GIMPLE call statement
12504 : : (obtained by gimple_call_fn). Return true if it is
12505 : : OBJ_TYPE_REF representing an virtual call of C++ method.
12506 : : (As opposed to OBJ_TYPE_REF representing objc calls
12507 : : through a cast where middle-end devirtualization machinery
12508 : : can't apply.) FOR_DUMP_P is true when being called from
12509 : : the dump routines. */
12510 : :
12511 : : bool
12512 : 28070711 : virtual_method_call_p (const_tree target, bool for_dump_p)
12513 : : {
12514 : 28070711 : if (TREE_CODE (target) != OBJ_TYPE_REF)
12515 : : return false;
12516 : 1439666 : tree t = TREE_TYPE (target);
12517 : 1439666 : gcc_checking_assert (TREE_CODE (t) == POINTER_TYPE);
12518 : 1439666 : t = TREE_TYPE (t);
12519 : 1439666 : if (TREE_CODE (t) == FUNCTION_TYPE)
12520 : : return false;
12521 : 1438578 : gcc_checking_assert (TREE_CODE (t) == METHOD_TYPE);
12522 : : /* If we do not have BINFO associated, it means that type was built
12523 : : without devirtualization enabled. Do not consider this a virtual
12524 : : call. */
12525 : 1438578 : if (!TYPE_BINFO (obj_type_ref_class (target, for_dump_p)))
12526 : : return false;
12527 : : return true;
12528 : : }
12529 : :
12530 : : /* Lookup sub-BINFO of BINFO of TYPE at offset POS. */
12531 : :
12532 : : static tree
12533 : 108 : lookup_binfo_at_offset (tree binfo, tree type, HOST_WIDE_INT pos)
12534 : : {
12535 : 108 : unsigned int i;
12536 : 108 : tree base_binfo, b;
12537 : :
12538 : 124 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12539 : 108 : if (pos == tree_to_shwi (BINFO_OFFSET (base_binfo))
12540 : 108 : && types_same_for_odr (TREE_TYPE (base_binfo), type))
12541 : : return base_binfo;
12542 : 70 : else if ((b = lookup_binfo_at_offset (base_binfo, type, pos)) != NULL)
12543 : : return b;
12544 : : return NULL;
12545 : : }
12546 : :
12547 : : /* Try to find a base info of BINFO that would have its field decl at offset
12548 : : OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
12549 : : found, return, otherwise return NULL_TREE. */
12550 : :
12551 : : tree
12552 : 373555 : get_binfo_at_offset (tree binfo, poly_int64 offset, tree expected_type)
12553 : : {
12554 : 373555 : tree type = BINFO_TYPE (binfo);
12555 : :
12556 : 1048661 : while (true)
12557 : : {
12558 : 711108 : HOST_WIDE_INT pos, size;
12559 : 711108 : tree fld;
12560 : 711108 : int i;
12561 : :
12562 : 711108 : if (types_same_for_odr (type, expected_type))
12563 : 373555 : return binfo;
12564 : 337553 : if (maybe_lt (offset, 0))
12565 : : return NULL_TREE;
12566 : :
12567 : 2078807 : for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
12568 : : {
12569 : 2078807 : if (TREE_CODE (fld) != FIELD_DECL || !DECL_ARTIFICIAL (fld))
12570 : 1741057 : continue;
12571 : :
12572 : 337750 : pos = int_bit_position (fld);
12573 : 337750 : size = tree_to_uhwi (DECL_SIZE (fld));
12574 : 2079004 : if (known_in_range_p (offset, pos, size))
12575 : : break;
12576 : : }
12577 : 337553 : if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE)
12578 : : return NULL_TREE;
12579 : :
12580 : : /* Offset 0 indicates the primary base, whose vtable contents are
12581 : : represented in the binfo for the derived class. */
12582 : 337553 : else if (maybe_ne (offset, 0))
12583 : : {
12584 : 197 : tree found_binfo = NULL, base_binfo;
12585 : : /* Offsets in BINFO are in bytes relative to the whole structure
12586 : : while POS is in bits relative to the containing field. */
12587 : 197 : int binfo_offset = (tree_to_shwi (BINFO_OFFSET (binfo)) + pos
12588 : 197 : / BITS_PER_UNIT);
12589 : :
12590 : 377 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12591 : 339 : if (tree_to_shwi (BINFO_OFFSET (base_binfo)) == binfo_offset
12592 : 339 : && types_same_for_odr (TREE_TYPE (base_binfo), TREE_TYPE (fld)))
12593 : : {
12594 : : found_binfo = base_binfo;
12595 : : break;
12596 : : }
12597 : 197 : if (found_binfo)
12598 : : binfo = found_binfo;
12599 : : else
12600 : 38 : binfo = lookup_binfo_at_offset (binfo, TREE_TYPE (fld),
12601 : : binfo_offset);
12602 : : }
12603 : :
12604 : 337553 : type = TREE_TYPE (fld);
12605 : 337553 : offset -= pos;
12606 : 337553 : }
12607 : : }
12608 : :
12609 : : /* PR 84195: Replace control characters in "unescaped" with their
12610 : : escaped equivalents. Allow newlines if -fmessage-length has
12611 : : been set to a non-zero value. This is done here, rather than
12612 : : where the attribute is recorded as the message length can
12613 : : change between these two locations. */
12614 : :
12615 : : void
12616 : 135336 : escaped_string::escape (const char *unescaped)
12617 : : {
12618 : 135336 : char *escaped;
12619 : 135336 : size_t i, new_i, len;
12620 : :
12621 : 135336 : if (m_owned)
12622 : 8 : free (m_str);
12623 : :
12624 : 135336 : m_str = const_cast<char *> (unescaped);
12625 : 135336 : m_owned = false;
12626 : :
12627 : 135336 : if (unescaped == NULL || *unescaped == 0)
12628 : : return;
12629 : :
12630 : 135328 : len = strlen (unescaped);
12631 : 135328 : escaped = NULL;
12632 : 135328 : new_i = 0;
12633 : :
12634 : 3952477 : for (i = 0; i < len; i++)
12635 : : {
12636 : 3817149 : char c = unescaped[i];
12637 : :
12638 : 3817149 : if (!ISCNTRL (c))
12639 : : {
12640 : 3817064 : if (escaped)
12641 : 33 : escaped[new_i++] = c;
12642 : 3817064 : continue;
12643 : : }
12644 : :
12645 : 85 : if (c != '\n' || !pp_is_wrapping_line (global_dc->get_reference_printer ()))
12646 : : {
12647 : 77 : if (escaped == NULL)
12648 : : {
12649 : : /* We only allocate space for a new string if we
12650 : : actually encounter a control character that
12651 : : needs replacing. */
12652 : 19 : escaped = (char *) xmalloc (len * 2 + 1);
12653 : 19 : strncpy (escaped, unescaped, i);
12654 : 19 : new_i = i;
12655 : : }
12656 : :
12657 : 77 : escaped[new_i++] = '\\';
12658 : :
12659 : 77 : switch (c)
12660 : : {
12661 : 8 : case '\a': escaped[new_i++] = 'a'; break;
12662 : 8 : case '\b': escaped[new_i++] = 'b'; break;
12663 : 8 : case '\f': escaped[new_i++] = 'f'; break;
12664 : 15 : case '\n': escaped[new_i++] = 'n'; break;
12665 : 15 : case '\r': escaped[new_i++] = 'r'; break;
12666 : 15 : case '\t': escaped[new_i++] = 't'; break;
12667 : 8 : case '\v': escaped[new_i++] = 'v'; break;
12668 : 0 : default: escaped[new_i++] = '?'; break;
12669 : : }
12670 : : }
12671 : 8 : else if (escaped)
12672 : 4 : escaped[new_i++] = c;
12673 : : }
12674 : :
12675 : 135328 : if (escaped)
12676 : : {
12677 : 19 : escaped[new_i] = 0;
12678 : 19 : m_str = escaped;
12679 : 19 : m_owned = true;
12680 : : }
12681 : : }
12682 : :
12683 : : /* Warn about a use of an identifier which was marked deprecated. Returns
12684 : : whether a warning was given. */
12685 : :
12686 : : bool
12687 : 1303097 : warn_deprecated_use (tree node, tree attr)
12688 : : {
12689 : 1303097 : escaped_string msg;
12690 : :
12691 : 1303097 : if (node == 0 || !warn_deprecated_decl)
12692 : : return false;
12693 : :
12694 : 1296713 : if (!attr)
12695 : : {
12696 : 1182515 : if (DECL_P (node))
12697 : 1182381 : attr = DECL_ATTRIBUTES (node);
12698 : 134 : else if (TYPE_P (node))
12699 : : {
12700 : 134 : tree decl = TYPE_STUB_DECL (node);
12701 : 134 : if (decl)
12702 : 110 : attr = TYPE_ATTRIBUTES (TREE_TYPE (decl));
12703 : 24 : else if ((decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (node)))
12704 : : != NULL_TREE)
12705 : : {
12706 : 6 : node = TREE_TYPE (decl);
12707 : 6 : attr = TYPE_ATTRIBUTES (node);
12708 : : }
12709 : : }
12710 : : }
12711 : :
12712 : 1182515 : if (attr)
12713 : 135023 : attr = lookup_attribute ("deprecated", attr);
12714 : :
12715 : 135023 : if (attr)
12716 : 135017 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12717 : :
12718 : 1296713 : bool w = false;
12719 : 1296713 : if (DECL_P (node))
12720 : : {
12721 : 1296569 : auto_diagnostic_group d;
12722 : 1296569 : if (msg)
12723 : 134962 : w = warning (OPT_Wdeprecated_declarations,
12724 : : "%qD is deprecated: %s", node, (const char *) msg);
12725 : : else
12726 : 1161607 : w = warning (OPT_Wdeprecated_declarations,
12727 : : "%qD is deprecated", node);
12728 : 1296569 : if (w)
12729 : 789 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12730 : 1296569 : }
12731 : 144 : else if (TYPE_P (node))
12732 : : {
12733 : 144 : tree what = NULL_TREE;
12734 : 144 : tree decl = TYPE_STUB_DECL (node);
12735 : :
12736 : 144 : if (TYPE_NAME (node))
12737 : : {
12738 : 139 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12739 : 10 : what = TYPE_NAME (node);
12740 : 129 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12741 : 129 : && DECL_NAME (TYPE_NAME (node)))
12742 : 129 : what = DECL_NAME (TYPE_NAME (node));
12743 : : }
12744 : :
12745 : 144 : auto_diagnostic_group d;
12746 : 144 : if (what)
12747 : : {
12748 : 139 : if (msg)
12749 : 53 : w = warning (OPT_Wdeprecated_declarations,
12750 : : "%qE is deprecated: %s", what, (const char *) msg);
12751 : : else
12752 : 86 : w = warning (OPT_Wdeprecated_declarations,
12753 : : "%qE is deprecated", what);
12754 : : }
12755 : : else
12756 : : {
12757 : 5 : if (msg)
12758 : 2 : w = warning (OPT_Wdeprecated_declarations,
12759 : : "type is deprecated: %s", (const char *) msg);
12760 : : else
12761 : 3 : w = warning (OPT_Wdeprecated_declarations,
12762 : : "type is deprecated");
12763 : : }
12764 : :
12765 : 144 : if (w && decl)
12766 : 111 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12767 : 144 : }
12768 : :
12769 : : return w;
12770 : 1303097 : }
12771 : :
12772 : : /* Error out with an identifier which was marked 'unavailable'. */
12773 : : void
12774 : 364 : error_unavailable_use (tree node, tree attr)
12775 : : {
12776 : 364 : escaped_string msg;
12777 : :
12778 : 364 : if (node == 0)
12779 : 0 : return;
12780 : :
12781 : 364 : if (!attr)
12782 : : {
12783 : 354 : if (DECL_P (node))
12784 : 294 : attr = DECL_ATTRIBUTES (node);
12785 : 60 : else if (TYPE_P (node))
12786 : : {
12787 : 60 : tree decl = TYPE_STUB_DECL (node);
12788 : 60 : if (decl)
12789 : 51 : attr = lookup_attribute ("unavailable",
12790 : 51 : TYPE_ATTRIBUTES (TREE_TYPE (decl)));
12791 : : }
12792 : : }
12793 : :
12794 : 354 : if (attr)
12795 : 152 : attr = lookup_attribute ("unavailable", attr);
12796 : :
12797 : 152 : if (attr)
12798 : 152 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12799 : :
12800 : 364 : if (DECL_P (node))
12801 : : {
12802 : 294 : auto_diagnostic_group d;
12803 : 294 : if (msg)
12804 : 117 : error ("%qD is unavailable: %s", node, (const char *) msg);
12805 : : else
12806 : 177 : error ("%qD is unavailable", node);
12807 : 294 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12808 : 294 : }
12809 : 70 : else if (TYPE_P (node))
12810 : : {
12811 : 70 : tree what = NULL_TREE;
12812 : 70 : tree decl = TYPE_STUB_DECL (node);
12813 : :
12814 : 70 : if (TYPE_NAME (node))
12815 : : {
12816 : 66 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12817 : 4 : what = TYPE_NAME (node);
12818 : 62 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12819 : 62 : && DECL_NAME (TYPE_NAME (node)))
12820 : 62 : what = DECL_NAME (TYPE_NAME (node));
12821 : : }
12822 : :
12823 : 70 : auto_diagnostic_group d;
12824 : 70 : if (what)
12825 : : {
12826 : 66 : if (msg)
12827 : 33 : error ("%qE is unavailable: %s", what, (const char *) msg);
12828 : : else
12829 : 33 : error ("%qE is unavailable", what);
12830 : : }
12831 : : else
12832 : : {
12833 : 4 : if (msg)
12834 : 2 : error ("type is unavailable: %s", (const char *) msg);
12835 : : else
12836 : 2 : error ("type is unavailable");
12837 : : }
12838 : :
12839 : 70 : if (decl)
12840 : 52 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12841 : 70 : }
12842 : 364 : }
12843 : :
12844 : : /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
12845 : : somewhere in it. */
12846 : :
12847 : : bool
12848 : 5783320 : contains_bitfld_component_ref_p (const_tree ref)
12849 : : {
12850 : 11790039 : while (handled_component_p (ref))
12851 : : {
12852 : 6032527 : if (TREE_CODE (ref) == COMPONENT_REF
12853 : 6032527 : && DECL_BIT_FIELD (TREE_OPERAND (ref, 1)))
12854 : : return true;
12855 : 6006719 : ref = TREE_OPERAND (ref, 0);
12856 : : }
12857 : :
12858 : : return false;
12859 : : }
12860 : :
12861 : : /* Try to determine whether a TRY_CATCH expression can fall through.
12862 : : This is a subroutine of block_may_fallthru. */
12863 : :
12864 : : static bool
12865 : 1 : try_catch_may_fallthru (const_tree stmt)
12866 : : {
12867 : 1 : tree_stmt_iterator i;
12868 : :
12869 : : /* If the TRY block can fall through, the whole TRY_CATCH can
12870 : : fall through. */
12871 : 1 : if (block_may_fallthru (TREE_OPERAND (stmt, 0)))
12872 : : return true;
12873 : :
12874 : 1 : switch (TREE_CODE (TREE_OPERAND (stmt, 1)))
12875 : : {
12876 : 0 : case CATCH_EXPR:
12877 : : /* See below. */
12878 : 0 : return block_may_fallthru (CATCH_BODY (TREE_OPERAND (stmt, 1)));
12879 : :
12880 : 0 : case EH_FILTER_EXPR:
12881 : : /* See below. */
12882 : 0 : return block_may_fallthru (EH_FILTER_FAILURE (TREE_OPERAND (stmt, 1)));
12883 : :
12884 : 0 : case STATEMENT_LIST:
12885 : 0 : break;
12886 : :
12887 : : default:
12888 : : /* See below. */
12889 : : return false;
12890 : : }
12891 : :
12892 : 0 : i = tsi_start (TREE_OPERAND (stmt, 1));
12893 : 0 : switch (TREE_CODE (tsi_stmt (i)))
12894 : : {
12895 : : case CATCH_EXPR:
12896 : : /* We expect to see a sequence of CATCH_EXPR trees, each with a
12897 : : catch expression and a body. The whole TRY_CATCH may fall
12898 : : through iff any of the catch bodies falls through. */
12899 : 0 : for (; !tsi_end_p (i); tsi_next (&i))
12900 : : {
12901 : 0 : if (block_may_fallthru (CATCH_BODY (tsi_stmt (i))))
12902 : : return true;
12903 : : }
12904 : : return false;
12905 : :
12906 : 0 : case EH_FILTER_EXPR:
12907 : : /* The exception filter expression only matters if there is an
12908 : : exception. If the exception does not match EH_FILTER_TYPES,
12909 : : we will execute EH_FILTER_FAILURE, and we will fall through
12910 : : if that falls through. If the exception does match
12911 : : EH_FILTER_TYPES, the stack unwinder will continue up the
12912 : : stack, so we will not fall through. We don't know whether we
12913 : : will throw an exception which matches EH_FILTER_TYPES or not,
12914 : : so we just ignore EH_FILTER_TYPES and assume that we might
12915 : : throw an exception which doesn't match. */
12916 : 0 : return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i)));
12917 : :
12918 : : default:
12919 : : /* This case represents statements to be executed when an
12920 : : exception occurs. Those statements are implicitly followed
12921 : : by a RESX statement to resume execution after the exception.
12922 : : So in this case the TRY_CATCH never falls through. */
12923 : : return false;
12924 : : }
12925 : : }
12926 : :
12927 : : /* Try to determine if we can fall out of the bottom of BLOCK. This guess
12928 : : need not be 100% accurate; simply be conservative and return true if we
12929 : : don't know. This is used only to avoid stupidly generating extra code.
12930 : : If we're wrong, we'll just delete the extra code later. */
12931 : :
12932 : : bool
12933 : 6613687 : block_may_fallthru (const_tree block)
12934 : : {
12935 : : /* This CONST_CAST is okay because expr_last returns its argument
12936 : : unmodified and we assign it to a const_tree. */
12937 : 7811279 : const_tree stmt = expr_last (CONST_CAST_TREE (block));
12938 : :
12939 : 7811279 : switch (stmt ? TREE_CODE (stmt) : ERROR_MARK)
12940 : : {
12941 : : case GOTO_EXPR:
12942 : : case RETURN_EXPR:
12943 : : /* Easy cases. If the last statement of the block implies
12944 : : control transfer, then we can't fall through. */
12945 : : return false;
12946 : :
12947 : 8 : case SWITCH_EXPR:
12948 : : /* If there is a default: label or case labels cover all possible
12949 : : SWITCH_COND values, then the SWITCH_EXPR will transfer control
12950 : : to some case label in all cases and all we care is whether the
12951 : : SWITCH_BODY falls through. */
12952 : 8 : if (SWITCH_ALL_CASES_P (stmt))
12953 : 7 : return block_may_fallthru (SWITCH_BODY (stmt));
12954 : : return true;
12955 : :
12956 : 20080 : case COND_EXPR:
12957 : 20080 : if (block_may_fallthru (COND_EXPR_THEN (stmt)))
12958 : : return true;
12959 : 2790 : return block_may_fallthru (COND_EXPR_ELSE (stmt));
12960 : :
12961 : 595739 : case BIND_EXPR:
12962 : 595739 : return block_may_fallthru (BIND_EXPR_BODY (stmt));
12963 : :
12964 : 1 : case TRY_CATCH_EXPR:
12965 : 1 : return try_catch_may_fallthru (stmt);
12966 : :
12967 : 145 : case TRY_FINALLY_EXPR:
12968 : : /* The finally clause is always executed after the try clause,
12969 : : so if it does not fall through, then the try-finally will not
12970 : : fall through. Otherwise, if the try clause does not fall
12971 : : through, then when the finally clause falls through it will
12972 : : resume execution wherever the try clause was going. So the
12973 : : whole try-finally will only fall through if both the try
12974 : : clause and the finally clause fall through. */
12975 : 145 : return (block_may_fallthru (TREE_OPERAND (stmt, 0))
12976 : 145 : && block_may_fallthru (TREE_OPERAND (stmt, 1)));
12977 : :
12978 : 0 : case EH_ELSE_EXPR:
12979 : 0 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
12980 : :
12981 : 91121 : case MODIFY_EXPR:
12982 : 91121 : if (TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR)
12983 : 1550 : stmt = TREE_OPERAND (stmt, 1);
12984 : : else
12985 : : return true;
12986 : : /* FALLTHRU */
12987 : :
12988 : 415834 : case CALL_EXPR:
12989 : : /* Functions that do not return do not fall through. */
12990 : 415834 : return (call_expr_flags (stmt) & ECF_NORETURN) == 0;
12991 : :
12992 : 599046 : case CLEANUP_POINT_EXPR:
12993 : 599046 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
12994 : :
12995 : 10 : case TARGET_EXPR:
12996 : 10 : return block_may_fallthru (TREE_OPERAND (stmt, 1));
12997 : :
12998 : : case ERROR_MARK:
12999 : : return true;
13000 : :
13001 : 4267726 : default:
13002 : 4267726 : return lang_hooks.block_may_fallthru (stmt);
13003 : : }
13004 : : }
13005 : :
13006 : : /* True if we are using EH to handle cleanups. */
13007 : : static bool using_eh_for_cleanups_flag = false;
13008 : :
13009 : : /* This routine is called from front ends to indicate eh should be used for
13010 : : cleanups. */
13011 : : void
13012 : 121158 : using_eh_for_cleanups (void)
13013 : : {
13014 : 121158 : using_eh_for_cleanups_flag = true;
13015 : 121158 : }
13016 : :
13017 : : /* Query whether EH is used for cleanups. */
13018 : : bool
13019 : 1668861 : using_eh_for_cleanups_p (void)
13020 : : {
13021 : 1668861 : return using_eh_for_cleanups_flag;
13022 : : }
13023 : :
13024 : : /* Wrapper for tree_code_name to ensure that tree code is valid */
13025 : : const char *
13026 : 14396117570 : get_tree_code_name (enum tree_code code)
13027 : : {
13028 : 14396117570 : const char *invalid = "<invalid tree code>";
13029 : :
13030 : : /* The tree_code enum promotes to signed, but we could be getting
13031 : : invalid values, so force an unsigned comparison. */
13032 : 14396117570 : if (unsigned (code) >= MAX_TREE_CODES)
13033 : : {
13034 : 0 : if ((unsigned)code == 0xa5a5)
13035 : : return "ggc_freed";
13036 : 0 : return invalid;
13037 : : }
13038 : :
13039 : 14396117570 : return tree_code_name[code];
13040 : : }
13041 : :
13042 : : /* Drops the TREE_OVERFLOW flag from T. */
13043 : :
13044 : : tree
13045 : 35537 : drop_tree_overflow (tree t)
13046 : : {
13047 : 35537 : gcc_checking_assert (TREE_OVERFLOW (t));
13048 : :
13049 : : /* For tree codes with a sharing machinery re-build the result. */
13050 : 35537 : if (poly_int_tree_p (t))
13051 : 35525 : return wide_int_to_tree (TREE_TYPE (t), wi::to_poly_wide (t));
13052 : :
13053 : : /* For VECTOR_CST, remove the overflow bits from the encoded elements
13054 : : and canonicalize the result. */
13055 : 12 : if (TREE_CODE (t) == VECTOR_CST)
13056 : : {
13057 : 0 : tree_vector_builder builder;
13058 : 0 : builder.new_unary_operation (TREE_TYPE (t), t, true);
13059 : 0 : unsigned int count = builder.encoded_nelts ();
13060 : 0 : for (unsigned int i = 0; i < count; ++i)
13061 : : {
13062 : 0 : tree elt = VECTOR_CST_ELT (t, i);
13063 : 0 : if (TREE_OVERFLOW (elt))
13064 : 0 : elt = drop_tree_overflow (elt);
13065 : 0 : builder.quick_push (elt);
13066 : : }
13067 : 0 : return builder.build ();
13068 : 0 : }
13069 : :
13070 : : /* Otherwise, as all tcc_constants are possibly shared, copy the node
13071 : : and drop the flag. */
13072 : 12 : t = copy_node (t);
13073 : 12 : TREE_OVERFLOW (t) = 0;
13074 : :
13075 : : /* For constants that contain nested constants, drop the flag
13076 : : from those as well. */
13077 : 12 : if (TREE_CODE (t) == COMPLEX_CST)
13078 : : {
13079 : 12 : if (TREE_OVERFLOW (TREE_REALPART (t)))
13080 : 12 : TREE_REALPART (t) = drop_tree_overflow (TREE_REALPART (t));
13081 : 12 : if (TREE_OVERFLOW (TREE_IMAGPART (t)))
13082 : 0 : TREE_IMAGPART (t) = drop_tree_overflow (TREE_IMAGPART (t));
13083 : : }
13084 : :
13085 : : return t;
13086 : : }
13087 : :
13088 : : /* Given a memory reference expression T, return its base address.
13089 : : The base address of a memory reference expression is the main
13090 : : object being referenced. For instance, the base address for
13091 : : 'array[i].fld[j]' is 'array'. You can think of this as stripping
13092 : : away the offset part from a memory address.
13093 : :
13094 : : This function calls handled_component_p to strip away all the inner
13095 : : parts of the memory reference until it reaches the base object. */
13096 : :
13097 : : tree
13098 : 3160403779 : get_base_address (tree t)
13099 : : {
13100 : 3160403779 : if (TREE_CODE (t) == WITH_SIZE_EXPR)
13101 : 899 : t = TREE_OPERAND (t, 0);
13102 : 3922224914 : while (handled_component_p (t))
13103 : 761821135 : t = TREE_OPERAND (t, 0);
13104 : :
13105 : 3160403779 : if ((TREE_CODE (t) == MEM_REF
13106 : 3160403779 : || TREE_CODE (t) == TARGET_MEM_REF)
13107 : 3160403779 : && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
13108 : 147826381 : t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
13109 : :
13110 : 3160403779 : return t;
13111 : : }
13112 : :
13113 : : /* Return a tree of sizetype representing the size, in bytes, of the element
13114 : : of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13115 : :
13116 : : tree
13117 : 787540620 : array_ref_element_size (tree exp)
13118 : : {
13119 : 787540620 : tree aligned_size = TREE_OPERAND (exp, 3);
13120 : 787540620 : tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
13121 : 787540620 : location_t loc = EXPR_LOCATION (exp);
13122 : :
13123 : : /* If a size was specified in the ARRAY_REF, it's the size measured
13124 : : in alignment units of the element type. So multiply by that value. */
13125 : 787540620 : if (aligned_size)
13126 : : {
13127 : : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13128 : : sizetype from another type of the same width and signedness. */
13129 : 390024 : if (TREE_TYPE (aligned_size) != sizetype)
13130 : 3157 : aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
13131 : 390024 : return size_binop_loc (loc, MULT_EXPR, aligned_size,
13132 : 390024 : size_int (TYPE_ALIGN_UNIT (elmt_type)));
13133 : : }
13134 : :
13135 : : /* Otherwise, take the size from that of the element type. Substitute
13136 : : any PLACEHOLDER_EXPR that we have. */
13137 : : else
13138 : 787150596 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
13139 : : }
13140 : :
13141 : : /* Return a tree representing the lower bound of the array mentioned in
13142 : : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13143 : :
13144 : : tree
13145 : 1085748274 : array_ref_low_bound (tree exp)
13146 : : {
13147 : 1085748274 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13148 : :
13149 : : /* If a lower bound is specified in EXP, use it. */
13150 : 1085748274 : if (TREE_OPERAND (exp, 2))
13151 : 1936955 : return TREE_OPERAND (exp, 2);
13152 : :
13153 : : /* Otherwise, if there is a domain type and it has a lower bound, use it,
13154 : : substituting for a PLACEHOLDER_EXPR as needed. */
13155 : 1083811319 : if (domain_type && TYPE_MIN_VALUE (domain_type))
13156 : 1082900506 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
13157 : :
13158 : : /* Otherwise, return a zero of the appropriate type. */
13159 : 910813 : tree idxtype = TREE_TYPE (TREE_OPERAND (exp, 1));
13160 : 910813 : return (idxtype == error_mark_node
13161 : 910813 : ? integer_zero_node : build_int_cst (idxtype, 0));
13162 : : }
13163 : :
13164 : : /* Return a tree representing the upper bound of the array mentioned in
13165 : : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13166 : :
13167 : : tree
13168 : 251805837 : array_ref_up_bound (tree exp)
13169 : : {
13170 : 251805837 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13171 : :
13172 : : /* If there is a domain type and it has an upper bound, use it, substituting
13173 : : for a PLACEHOLDER_EXPR as needed. */
13174 : 251805837 : if (domain_type && TYPE_MAX_VALUE (domain_type))
13175 : 251008015 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
13176 : :
13177 : : /* Otherwise fail. */
13178 : : return NULL_TREE;
13179 : : }
13180 : :
13181 : : /* Returns true if REF is an array reference, a component reference,
13182 : : or a memory reference to an array whose actual size might be larger
13183 : : than its upper bound implies, there are multiple cases:
13184 : : A. a ref to a flexible array member at the end of a structure;
13185 : : B. a ref to an array with a different type against the original decl;
13186 : : for example:
13187 : :
13188 : : short a[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
13189 : : (*((char(*)[16])&a[0]))[i+8]
13190 : :
13191 : : C. a ref to an array that was passed as a parameter;
13192 : : for example:
13193 : :
13194 : : int test (uint8_t *p, uint32_t t[1][1], int n) {
13195 : : for (int i = 0; i < 4; i++, p++)
13196 : : t[i][0] = ...;
13197 : :
13198 : : If non-null, set IS_TRAILING_ARRAY to true if the ref is the above case A.
13199 : : */
13200 : :
13201 : : bool
13202 : 77414817 : array_ref_flexible_size_p (tree ref, bool *is_trailing_array /* = NULL */)
13203 : : {
13204 : : /* The TYPE for this array referece. */
13205 : 77414817 : tree atype = NULL_TREE;
13206 : : /* The FIELD_DECL for the array field in the containing structure. */
13207 : 77414817 : tree afield_decl = NULL_TREE;
13208 : : /* Whether this array is the trailing array of a structure. */
13209 : 77414817 : bool is_trailing_array_tmp = false;
13210 : 77414817 : if (!is_trailing_array)
13211 : 77335239 : is_trailing_array = &is_trailing_array_tmp;
13212 : :
13213 : 77414817 : if (TREE_CODE (ref) == ARRAY_REF
13214 : 77414817 : || TREE_CODE (ref) == ARRAY_RANGE_REF)
13215 : : {
13216 : 77178130 : atype = TREE_TYPE (TREE_OPERAND (ref, 0));
13217 : 77178130 : ref = TREE_OPERAND (ref, 0);
13218 : : }
13219 : 236687 : else if (TREE_CODE (ref) == COMPONENT_REF
13220 : 236687 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 1))) == ARRAY_TYPE)
13221 : : {
13222 : 172102 : atype = TREE_TYPE (TREE_OPERAND (ref, 1));
13223 : 172102 : afield_decl = TREE_OPERAND (ref, 1);
13224 : : }
13225 : 64585 : else if (TREE_CODE (ref) == MEM_REF)
13226 : : {
13227 : 8321 : tree arg = TREE_OPERAND (ref, 0);
13228 : 8321 : if (TREE_CODE (arg) == ADDR_EXPR)
13229 : 8321 : arg = TREE_OPERAND (arg, 0);
13230 : 8321 : tree argtype = TREE_TYPE (arg);
13231 : 8321 : if (TREE_CODE (argtype) == RECORD_TYPE)
13232 : : {
13233 : 157 : if (tree fld = last_field (argtype))
13234 : : {
13235 : 157 : atype = TREE_TYPE (fld);
13236 : 157 : afield_decl = fld;
13237 : 157 : if (TREE_CODE (atype) != ARRAY_TYPE)
13238 : : return false;
13239 : 157 : if (VAR_P (arg) && DECL_SIZE (fld))
13240 : : return false;
13241 : : }
13242 : : else
13243 : : return false;
13244 : : }
13245 : : else
13246 : : return false;
13247 : : }
13248 : : else
13249 : : return false;
13250 : :
13251 : 77350345 : if (TREE_CODE (ref) == STRING_CST)
13252 : : return false;
13253 : :
13254 : : tree ref_to_array = ref;
13255 : 93831488 : while (handled_component_p (ref))
13256 : : {
13257 : : /* If the reference chain contains a component reference to a
13258 : : non-union type and there follows another field the reference
13259 : : is not at the end of a structure. */
13260 : 19604701 : if (TREE_CODE (ref) == COMPONENT_REF)
13261 : : {
13262 : 18449983 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
13263 : : {
13264 : 17198157 : tree nextf = DECL_CHAIN (TREE_OPERAND (ref, 1));
13265 : 26318520 : while (nextf && TREE_CODE (nextf) != FIELD_DECL)
13266 : 9120363 : nextf = DECL_CHAIN (nextf);
13267 : : if (nextf)
13268 : : return false;
13269 : : }
13270 : : }
13271 : : /* If we have a multi-dimensional array we do not consider
13272 : : a non-innermost dimension as flex array if the whole
13273 : : multi-dimensional array is at struct end.
13274 : : Same for an array of aggregates with a trailing array
13275 : : member. */
13276 : 1154718 : else if (TREE_CODE (ref) == ARRAY_REF)
13277 : : return false;
13278 : 185303 : else if (TREE_CODE (ref) == ARRAY_RANGE_REF)
13279 : : ;
13280 : : /* If we view an underlying object as sth else then what we
13281 : : gathered up to now is what we have to rely on. */
13282 : 185293 : else if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
13283 : : break;
13284 : : else
13285 : 0 : gcc_unreachable ();
13286 : :
13287 : 16482606 : ref = TREE_OPERAND (ref, 0);
13288 : : }
13289 : :
13290 : 74412080 : gcc_assert (!afield_decl
13291 : : || (afield_decl && TREE_CODE (afield_decl) == FIELD_DECL));
13292 : :
13293 : : /* The array now is at struct end. Treat flexible array member as
13294 : : always subject to extend, even into just padding constrained by
13295 : : an underlying decl. */
13296 : 74412080 : if (! TYPE_SIZE (atype)
13297 : 72060682 : || ! TYPE_DOMAIN (atype)
13298 : 146472762 : || ! TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13299 : : {
13300 : 2357010 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13301 : 2444108 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13302 : : }
13303 : :
13304 : : /* If the reference is based on a declared entity, the size of the array
13305 : : is constrained by its given domain. (Do not trust commons PR/69368). */
13306 : 72055070 : ref = get_base_address (ref);
13307 : 72055070 : if (ref
13308 : 72055070 : && DECL_P (ref)
13309 : 62144381 : && !(flag_unconstrained_commons
13310 : 14 : && VAR_P (ref) && DECL_COMMON (ref))
13311 : 62144367 : && DECL_SIZE_UNIT (ref)
13312 : 134199060 : && TREE_CODE (DECL_SIZE_UNIT (ref)) == INTEGER_CST)
13313 : : {
13314 : : /* If the object itself is the array it is not at struct end. */
13315 : 62143962 : if (DECL_P (ref_to_array))
13316 : : return false;
13317 : :
13318 : : /* Check whether the array domain covers all of the available
13319 : : padding. */
13320 : 15522904 : poly_int64 offset;
13321 : 15522904 : if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
13322 : 15521544 : || TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST
13323 : 31021132 : || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST)
13324 : : {
13325 : 24676 : *is_trailing_array
13326 : 24676 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13327 : 24719 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13328 : : }
13329 : 15498228 : if (! get_addr_base_and_unit_offset (ref_to_array, &offset))
13330 : : {
13331 : 2821 : *is_trailing_array
13332 : 2821 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13333 : 2821 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13334 : : }
13335 : :
13336 : : /* If at least one extra element fits it is a flexarray. */
13337 : 15495407 : if (known_le ((wi::to_offset (TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13338 : : - wi::to_offset (TYPE_MIN_VALUE (TYPE_DOMAIN (atype)))
13339 : : + 2)
13340 : : * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (atype))),
13341 : : wi::to_offset (DECL_SIZE_UNIT (ref)) - offset))
13342 : : {
13343 : 562223 : *is_trailing_array
13344 : 562223 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13345 : 574496 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13346 : : }
13347 : :
13348 : : return false;
13349 : : }
13350 : :
13351 : 9911108 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13352 : 9925650 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13353 : : }
13354 : :
13355 : :
13356 : : /* Return a tree representing the offset, in bytes, of the field referenced
13357 : : by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
13358 : :
13359 : : tree
13360 : 2659423006 : component_ref_field_offset (tree exp)
13361 : : {
13362 : 2659423006 : tree aligned_offset = TREE_OPERAND (exp, 2);
13363 : 2659423006 : tree field = TREE_OPERAND (exp, 1);
13364 : 2659423006 : location_t loc = EXPR_LOCATION (exp);
13365 : :
13366 : : /* If an offset was specified in the COMPONENT_REF, it's the offset measured
13367 : : in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
13368 : : value. */
13369 : 2659423006 : if (aligned_offset)
13370 : : {
13371 : : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13372 : : sizetype from another type of the same width and signedness. */
13373 : 12016 : if (TREE_TYPE (aligned_offset) != sizetype)
13374 : 135 : aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
13375 : 12016 : return size_binop_loc (loc, MULT_EXPR, aligned_offset,
13376 : 12016 : size_int (DECL_OFFSET_ALIGN (field)
13377 : : / BITS_PER_UNIT));
13378 : : }
13379 : :
13380 : : /* Otherwise, take the offset from that of the field. Substitute
13381 : : any PLACEHOLDER_EXPR that we have. */
13382 : : else
13383 : 2659410990 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
13384 : : }
13385 : :
13386 : : /* Given the initializer INIT, return the initializer for the field
13387 : : DECL if it exists, otherwise null. Used to obtain the initializer
13388 : : for a flexible array member and determine its size. */
13389 : :
13390 : : static tree
13391 : 1267 : get_initializer_for (tree init, tree decl)
13392 : : {
13393 : 1267 : STRIP_NOPS (init);
13394 : :
13395 : 1267 : tree fld, fld_init;
13396 : 1267 : unsigned HOST_WIDE_INT i;
13397 : 3571 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), i, fld, fld_init)
13398 : : {
13399 : 1926 : if (decl == fld)
13400 : : return fld_init;
13401 : :
13402 : 1037 : if (TREE_CODE (fld) == CONSTRUCTOR)
13403 : : {
13404 : 0 : fld_init = get_initializer_for (fld_init, decl);
13405 : 0 : if (fld_init)
13406 : : return fld_init;
13407 : : }
13408 : : }
13409 : :
13410 : : return NULL_TREE;
13411 : : }
13412 : :
13413 : : /* Determines the special array member type for the array reference REF. */
13414 : : special_array_member
13415 : 252575 : component_ref_sam_type (tree ref)
13416 : : {
13417 : 252575 : special_array_member sam_type = special_array_member::none;
13418 : :
13419 : 252575 : tree member = TREE_OPERAND (ref, 1);
13420 : 252575 : tree memsize = DECL_SIZE_UNIT (member);
13421 : 252575 : if (memsize)
13422 : : {
13423 : 120589 : tree memtype = TREE_TYPE (member);
13424 : 120589 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13425 : 120467 : return sam_type;
13426 : :
13427 : 79578 : bool trailing = false;
13428 : 79578 : (void) array_ref_flexible_size_p (ref, &trailing);
13429 : 79578 : bool zero_elts = integer_zerop (memsize);
13430 : 79578 : if (zero_elts && integer_zerop (TYPE_SIZE_UNIT (TREE_TYPE (memtype))))
13431 : : {
13432 : : /* If array element has zero size, verify if it is a flexible
13433 : : array member or zero length array. Clear zero_elts if
13434 : : it has one or more members or is a VLA member. */
13435 : 7 : if (tree dom = TYPE_DOMAIN (memtype))
13436 : 7 : if (tree min = TYPE_MIN_VALUE (dom))
13437 : 7 : if (tree max = TYPE_MAX_VALUE (dom))
13438 : 5 : if (TREE_CODE (min) != INTEGER_CST
13439 : 5 : || TREE_CODE (max) != INTEGER_CST
13440 : 15 : || !((integer_zerop (min) && integer_all_onesp (max))
13441 : 5 : || tree_int_cst_lt (max, min)))
13442 : : zero_elts = false;
13443 : : }
13444 : 79578 : if (!trailing && !zero_elts)
13445 : : /* MEMBER is an interior array with more than one element. */
13446 : : return special_array_member::int_n;
13447 : :
13448 : 23577 : if (zero_elts)
13449 : : {
13450 : 1075 : if (trailing)
13451 : : return special_array_member::trail_0;
13452 : : else
13453 : 463 : return special_array_member::int_0;
13454 : : }
13455 : :
13456 : 22965 : if (!zero_elts)
13457 : 22965 : if (tree dom = TYPE_DOMAIN (memtype))
13458 : 22965 : if (tree min = TYPE_MIN_VALUE (dom))
13459 : 22965 : if (tree max = TYPE_MAX_VALUE (dom))
13460 : 22965 : if (TREE_CODE (min) == INTEGER_CST
13461 : 22965 : && TREE_CODE (max) == INTEGER_CST)
13462 : : {
13463 : 22843 : offset_int minidx = wi::to_offset (min);
13464 : 22843 : offset_int maxidx = wi::to_offset (max);
13465 : 22843 : offset_int neltsm1 = maxidx - minidx;
13466 : 22843 : if (neltsm1 > 0)
13467 : : /* MEMBER is a trailing array with more than
13468 : : one elements. */
13469 : 22843 : return special_array_member::trail_n;
13470 : :
13471 : 2018 : if (neltsm1 == 0)
13472 : : return special_array_member::trail_1;
13473 : : }
13474 : : }
13475 : :
13476 : : return sam_type;
13477 : : }
13478 : :
13479 : : /* Determines the size of the member referenced by the COMPONENT_REF
13480 : : REF, using its initializer expression if necessary in order to
13481 : : determine the size of an initialized flexible array member.
13482 : : If non-null, set *SAM to the type of special array member.
13483 : : Returns the size as sizetype (which might be zero for an object
13484 : : with an uninitialized flexible array member) or null if the size
13485 : : cannot be determined. */
13486 : :
13487 : : tree
13488 : 153521 : component_ref_size (tree ref, special_array_member *sam /* = NULL */)
13489 : : {
13490 : 153521 : gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
13491 : :
13492 : 153521 : special_array_member sambuf;
13493 : 153521 : if (!sam)
13494 : 97605 : sam = &sambuf;
13495 : 153521 : *sam = component_ref_sam_type (ref);
13496 : :
13497 : : /* The object/argument referenced by the COMPONENT_REF and its type. */
13498 : 153521 : tree arg = TREE_OPERAND (ref, 0);
13499 : 153521 : tree argtype = TREE_TYPE (arg);
13500 : : /* The referenced member. */
13501 : 153521 : tree member = TREE_OPERAND (ref, 1);
13502 : :
13503 : 153521 : tree memsize = DECL_SIZE_UNIT (member);
13504 : 153521 : if (memsize)
13505 : : {
13506 : 86008 : tree memtype = TREE_TYPE (member);
13507 : 86008 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13508 : : /* DECL_SIZE may be less than TYPE_SIZE in C++ when referring
13509 : : to the type of a class with a virtual base which doesn't
13510 : : reflect the size of the virtual's members (see pr97595).
13511 : : If that's the case fail for now and implement something
13512 : : more robust in the future. */
13513 : 41011 : return (tree_int_cst_equal (memsize, TYPE_SIZE_UNIT (memtype))
13514 : 41011 : ? memsize : NULL_TREE);
13515 : :
13516 : : /* 2-or-more elements arrays are treated as normal arrays by default. */
13517 : 44997 : if (*sam == special_array_member::int_n
13518 : 44997 : || *sam == special_array_member::trail_n)
13519 : : return memsize;
13520 : :
13521 : 1769 : tree afield_decl = TREE_OPERAND (ref, 1);
13522 : 1769 : gcc_assert (TREE_CODE (afield_decl) == FIELD_DECL);
13523 : : /* If the trailing array is a not a flexible array member, treat it as
13524 : : a normal array. */
13525 : 1769 : if (DECL_NOT_FLEXARRAY (afield_decl)
13526 : 1769 : && *sam != special_array_member::int_0)
13527 : : return memsize;
13528 : :
13529 : 1760 : if (*sam == special_array_member::int_0)
13530 : 270 : memsize = NULL_TREE;
13531 : :
13532 : : /* For a reference to a flexible array member of a union
13533 : : use the size of the union instead of the size of the member. */
13534 : 1760 : if (TREE_CODE (argtype) == UNION_TYPE)
13535 : 277 : memsize = TYPE_SIZE_UNIT (argtype);
13536 : : }
13537 : :
13538 : : /* MEMBER is either a bona fide flexible array member, or a zero-elements
13539 : : array member, or an array of length one treated as such. */
13540 : :
13541 : : /* If the reference is to a declared object and the member a true
13542 : : flexible array, try to determine its size from its initializer. */
13543 : 69273 : poly_int64 baseoff = 0;
13544 : 69273 : tree base = get_addr_base_and_unit_offset (ref, &baseoff);
13545 : 69273 : if (!base || !VAR_P (base))
13546 : : {
13547 : 66042 : if (*sam != special_array_member::int_0)
13548 : : return NULL_TREE;
13549 : :
13550 : 52 : if (TREE_CODE (arg) != COMPONENT_REF)
13551 : : return NULL_TREE;
13552 : :
13553 : : base = arg;
13554 : 6 : while (TREE_CODE (base) == COMPONENT_REF)
13555 : 3 : base = TREE_OPERAND (base, 0);
13556 : 3 : baseoff = tree_to_poly_int64 (byte_position (TREE_OPERAND (ref, 1)));
13557 : : }
13558 : :
13559 : : /* BASE is the declared object of which MEMBER is either a member
13560 : : or that is cast to ARGTYPE (e.g., a char buffer used to store
13561 : : an ARGTYPE object). */
13562 : 3234 : tree basetype = TREE_TYPE (base);
13563 : :
13564 : : /* Determine the base type of the referenced object. If it's
13565 : : the same as ARGTYPE and MEMBER has a known size, return it. */
13566 : 3234 : tree bt = basetype;
13567 : 3234 : if (*sam != special_array_member::int_0)
13568 : 3235 : while (TREE_CODE (bt) == ARRAY_TYPE)
13569 : 222 : bt = TREE_TYPE (bt);
13570 : 3234 : bool typematch = useless_type_conversion_p (argtype, bt);
13571 : 3234 : if (memsize && typematch)
13572 : : return memsize;
13573 : :
13574 : 3144 : memsize = NULL_TREE;
13575 : :
13576 : 3144 : if (typematch)
13577 : : /* MEMBER is a true flexible array member. Compute its size from
13578 : : the initializer of the BASE object if it has one. */
13579 : 2656 : if (tree init = DECL_P (base) ? DECL_INITIAL (base) : NULL_TREE)
13580 : 1300 : if (init != error_mark_node)
13581 : : {
13582 : 1267 : init = get_initializer_for (init, member);
13583 : 1267 : if (init)
13584 : : {
13585 : 889 : memsize = TYPE_SIZE_UNIT (TREE_TYPE (init));
13586 : 889 : if (tree refsize = TYPE_SIZE_UNIT (argtype))
13587 : : {
13588 : : /* Use the larger of the initializer size and the tail
13589 : : padding in the enclosing struct. */
13590 : 889 : poly_int64 rsz = tree_to_poly_int64 (refsize);
13591 : 889 : rsz -= baseoff;
13592 : 889 : if (known_lt (tree_to_poly_int64 (memsize), rsz))
13593 : 56 : memsize = wide_int_to_tree (TREE_TYPE (memsize), rsz);
13594 : : }
13595 : :
13596 : 889 : baseoff = 0;
13597 : : }
13598 : : }
13599 : :
13600 : 889 : if (!memsize)
13601 : : {
13602 : 2255 : if (typematch)
13603 : : {
13604 : 1767 : if (DECL_P (base)
13605 : 1767 : && DECL_EXTERNAL (base)
13606 : 454 : && bt == basetype
13607 : 2215 : && *sam != special_array_member::int_0)
13608 : : /* The size of a flexible array member of an extern struct
13609 : : with no initializer cannot be determined (it's defined
13610 : : in another translation unit and can have an initializer
13611 : : with an arbitrary number of elements). */
13612 : : return NULL_TREE;
13613 : :
13614 : : /* Use the size of the base struct or, for interior zero-length
13615 : : arrays, the size of the enclosing type. */
13616 : 1342 : memsize = TYPE_SIZE_UNIT (bt);
13617 : : }
13618 : 488 : else if (DECL_P (base))
13619 : : /* Use the size of the BASE object (possibly an array of some
13620 : : other type such as char used to store the struct). */
13621 : 485 : memsize = DECL_SIZE_UNIT (base);
13622 : : else
13623 : : return NULL_TREE;
13624 : : }
13625 : :
13626 : : /* If the flexible array member has a known size use the greater
13627 : : of it and the tail padding in the enclosing struct.
13628 : : Otherwise, when the size of the flexible array member is unknown
13629 : : and the referenced object is not a struct, use the size of its
13630 : : type when known. This detects sizes of array buffers when cast
13631 : : to struct types with flexible array members. */
13632 : 1827 : if (memsize)
13633 : : {
13634 : 2691 : if (!tree_fits_poly_int64_p (memsize))
13635 : : return NULL_TREE;
13636 : 2691 : poly_int64 memsz64 = memsize ? tree_to_poly_int64 (memsize) : 0;
13637 : 2691 : if (known_lt (baseoff, memsz64))
13638 : : {
13639 : 1265 : memsz64 -= baseoff;
13640 : 1265 : return wide_int_to_tree (TREE_TYPE (memsize), memsz64);
13641 : : }
13642 : 1426 : return size_zero_node;
13643 : : }
13644 : :
13645 : : /* Return "don't know" for an external non-array object since its
13646 : : flexible array member can be initialized to have any number of
13647 : : elements. Otherwise, return zero because the flexible array
13648 : : member has no elements. */
13649 : 25 : return (DECL_P (base)
13650 : 25 : && DECL_EXTERNAL (base)
13651 : 25 : && (!typematch
13652 : 0 : || TREE_CODE (basetype) != ARRAY_TYPE)
13653 : 25 : ? NULL_TREE : size_zero_node);
13654 : : }
13655 : :
13656 : : /* Return true if the given node CALL is a call to a .ACCESS_WITH_SIZE
13657 : : function. */
13658 : : bool
13659 : 58746229 : is_access_with_size_p (const_tree call)
13660 : : {
13661 : 58746229 : if (TREE_CODE (call) != CALL_EXPR)
13662 : : return false;
13663 : 7057187 : if (CALL_EXPR_IFN (call) == IFN_ACCESS_WITH_SIZE)
13664 : 353 : return true;
13665 : : return false;
13666 : : }
13667 : :
13668 : : /* Get the corresponding reference from the call to a .ACCESS_WITH_SIZE.
13669 : : * i.e the first argument of this call. Return NULL_TREE otherwise. */
13670 : : tree
13671 : 2 : get_ref_from_access_with_size (tree call)
13672 : : {
13673 : 2 : if (is_access_with_size_p (call))
13674 : 2 : return CALL_EXPR_ARG (call, 0);
13675 : : return NULL_TREE;
13676 : : }
13677 : :
13678 : : /* Return the machine mode of T. For vectors, returns the mode of the
13679 : : inner type. The main use case is to feed the result to HONOR_NANS,
13680 : : avoiding the BLKmode that a direct TYPE_MODE (T) might return. */
13681 : :
13682 : : machine_mode
13683 : 5300348201 : element_mode (const_tree t)
13684 : : {
13685 : 5300348201 : if (!TYPE_P (t))
13686 : 205580136 : t = TREE_TYPE (t);
13687 : 5300348201 : if (VECTOR_TYPE_P (t) || TREE_CODE (t) == COMPLEX_TYPE)
13688 : 1509710539 : t = TREE_TYPE (t);
13689 : 5300348201 : return TYPE_MODE (t);
13690 : : }
13691 : :
13692 : : /* Vector types need to re-check the target flags each time we report
13693 : : the machine mode. We need to do this because attribute target can
13694 : : change the result of vector_mode_supported_p and have_regs_of_mode
13695 : : on a per-function basis. Thus the TYPE_MODE of a VECTOR_TYPE can
13696 : : change on a per-function basis. */
13697 : : /* ??? Possibly a better solution is to run through all the types
13698 : : referenced by a function and re-compute the TYPE_MODE once, rather
13699 : : than make the TYPE_MODE macro call a function. */
13700 : :
13701 : : machine_mode
13702 : 1318298665 : vector_type_mode (const_tree t)
13703 : : {
13704 : 1318298665 : machine_mode mode;
13705 : :
13706 : 1318298665 : gcc_assert (TREE_CODE (t) == VECTOR_TYPE);
13707 : :
13708 : 1318298665 : mode = t->type_common.mode;
13709 : 303657656 : if (VECTOR_MODE_P (mode)
13710 : 1584995399 : && (!targetm.vector_mode_supported_p (mode)
13711 : 1262703381 : || !have_regs_of_mode[mode]))
13712 : : {
13713 : 19541971 : scalar_int_mode innermode;
13714 : :
13715 : : /* For integers, try mapping it to a same-sized scalar mode. */
13716 : 19541971 : if (is_int_mode (TREE_TYPE (t)->type_common.mode, &innermode))
13717 : : {
13718 : 27327146 : poly_int64 size = (TYPE_VECTOR_SUBPARTS (t)
13719 : 13663573 : * GET_MODE_BITSIZE (innermode));
13720 : 13663573 : scalar_int_mode mode;
13721 : 27176149 : if (int_mode_for_size (size, 0).exists (&mode)
13722 : 13566335 : && have_regs_of_mode[mode])
13723 : 53759 : return mode;
13724 : : }
13725 : :
13726 : 19488212 : return BLKmode;
13727 : : }
13728 : :
13729 : : return mode;
13730 : : }
13731 : :
13732 : : /* Return the size in bits of each element of vector type TYPE. */
13733 : :
13734 : : unsigned int
13735 : 231238 : vector_element_bits (const_tree type)
13736 : : {
13737 : 231238 : gcc_checking_assert (VECTOR_TYPE_P (type));
13738 : 231238 : if (VECTOR_BOOLEAN_TYPE_P (type))
13739 : 1033 : return TYPE_PRECISION (TREE_TYPE (type));
13740 : 230205 : return tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)));
13741 : : }
13742 : :
13743 : : /* Calculate the size in bits of each element of vector type TYPE
13744 : : and return the result as a tree of type bitsizetype. */
13745 : :
13746 : : tree
13747 : 109700 : vector_element_bits_tree (const_tree type)
13748 : : {
13749 : 109700 : gcc_checking_assert (VECTOR_TYPE_P (type));
13750 : 109700 : if (VECTOR_BOOLEAN_TYPE_P (type))
13751 : 601 : return bitsize_int (vector_element_bits (type));
13752 : 109099 : return TYPE_SIZE (TREE_TYPE (type));
13753 : : }
13754 : :
13755 : : /* Verify that basic properties of T match TV and thus T can be a variant of
13756 : : TV. TV should be the more specified variant (i.e. the main variant). */
13757 : :
13758 : : static bool
13759 : 155803237 : verify_type_variant (const_tree t, tree tv)
13760 : : {
13761 : : /* Type variant can differ by:
13762 : :
13763 : : - TYPE_QUALS: TYPE_READONLY, TYPE_VOLATILE, TYPE_ATOMIC, TYPE_RESTRICT,
13764 : : ENCODE_QUAL_ADDR_SPACE.
13765 : : - main variant may be TYPE_COMPLETE_P and variant types !TYPE_COMPLETE_P
13766 : : in this case some values may not be set in the variant types
13767 : : (see TYPE_COMPLETE_P checks).
13768 : : - it is possible to have TYPE_ARTIFICIAL variant of non-artifical type
13769 : : - by TYPE_NAME and attributes (i.e. when variant originate by typedef)
13770 : : - TYPE_CANONICAL (TYPE_ALIAS_SET is the same among variants)
13771 : : - by the alignment: TYPE_ALIGN and TYPE_USER_ALIGN
13772 : : - during LTO by TYPE_CONTEXT if type is TYPE_FILE_SCOPE_P
13773 : : this is necessary to make it possible to merge types form different TUs
13774 : : - arrays, pointers and references may have TREE_TYPE that is a variant
13775 : : of TREE_TYPE of their main variants.
13776 : : - aggregates may have new TYPE_FIELDS list that list variants of
13777 : : the main variant TYPE_FIELDS.
13778 : : - vector types may differ by TYPE_VECTOR_OPAQUE
13779 : : */
13780 : :
13781 : : /* Convenience macro for matching individual fields. */
13782 : : #define verify_variant_match(flag) \
13783 : : do { \
13784 : : if (flag (tv) != flag (t)) \
13785 : : { \
13786 : : error ("type variant differs by %s", #flag); \
13787 : : debug_tree (tv); \
13788 : : return false; \
13789 : : } \
13790 : : } while (false)
13791 : :
13792 : : /* tree_base checks. */
13793 : :
13794 : 155803237 : verify_variant_match (TREE_CODE);
13795 : : /* FIXME: Ada builds non-artificial variants of artificial types. */
13796 : : #if 0
13797 : : if (TYPE_ARTIFICIAL (tv))
13798 : : verify_variant_match (TYPE_ARTIFICIAL);
13799 : : #endif
13800 : 155803237 : if (POINTER_TYPE_P (tv))
13801 : 11520348 : verify_variant_match (TYPE_REF_CAN_ALIAS_ALL);
13802 : : /* FIXME: TYPE_SIZES_GIMPLIFIED may differs for Ada build. */
13803 : 155803237 : verify_variant_match (TYPE_UNSIGNED);
13804 : 155803237 : verify_variant_match (TYPE_PACKED);
13805 : 155803237 : if (TREE_CODE (t) == REFERENCE_TYPE)
13806 : 3067882 : verify_variant_match (TYPE_REF_IS_RVALUE);
13807 : 155803237 : if (AGGREGATE_TYPE_P (t))
13808 : 65643708 : verify_variant_match (TYPE_REVERSE_STORAGE_ORDER);
13809 : : else
13810 : 90159529 : verify_variant_match (TYPE_SATURATING);
13811 : : /* FIXME: This check trigger during libstdc++ build. */
13812 : : #if 0
13813 : : if (RECORD_OR_UNION_TYPE_P (t) && COMPLETE_TYPE_P (t))
13814 : : verify_variant_match (TYPE_FINAL_P);
13815 : : #endif
13816 : :
13817 : : /* tree_type_common checks. */
13818 : :
13819 : 155803237 : if (COMPLETE_TYPE_P (t))
13820 : : {
13821 : 145205004 : verify_variant_match (TYPE_MODE);
13822 : 145205004 : if (TREE_CODE (TYPE_SIZE (t)) != PLACEHOLDER_EXPR
13823 : 145205004 : && TREE_CODE (TYPE_SIZE (tv)) != PLACEHOLDER_EXPR)
13824 : 145205004 : verify_variant_match (TYPE_SIZE);
13825 : 145205004 : if (TREE_CODE (TYPE_SIZE_UNIT (t)) != PLACEHOLDER_EXPR
13826 : 145205004 : && TREE_CODE (TYPE_SIZE_UNIT (tv)) != PLACEHOLDER_EXPR
13827 : 290410008 : && TYPE_SIZE_UNIT (t) != TYPE_SIZE_UNIT (tv))
13828 : : {
13829 : 0 : gcc_assert (!operand_equal_p (TYPE_SIZE_UNIT (t),
13830 : : TYPE_SIZE_UNIT (tv), 0));
13831 : 0 : error ("type variant has different %<TYPE_SIZE_UNIT%>");
13832 : 0 : debug_tree (tv);
13833 : 0 : error ("type variant%'s %<TYPE_SIZE_UNIT%>");
13834 : 0 : debug_tree (TYPE_SIZE_UNIT (tv));
13835 : 0 : error ("type%'s %<TYPE_SIZE_UNIT%>");
13836 : 0 : debug_tree (TYPE_SIZE_UNIT (t));
13837 : 0 : return false;
13838 : : }
13839 : 145205004 : verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
13840 : : }
13841 : 155803237 : verify_variant_match (TYPE_PRECISION_RAW);
13842 : 155803237 : if (RECORD_OR_UNION_TYPE_P (t))
13843 : 65115645 : verify_variant_match (TYPE_TRANSPARENT_AGGR);
13844 : 90687592 : else if (TREE_CODE (t) == ARRAY_TYPE)
13845 : 528063 : verify_variant_match (TYPE_NONALIASED_COMPONENT);
13846 : : /* During LTO we merge variant lists from diferent translation units
13847 : : that may differ BY TYPE_CONTEXT that in turn may point
13848 : : to TRANSLATION_UNIT_DECL.
13849 : : Ada also builds variants of types with different TYPE_CONTEXT. */
13850 : : #if 0
13851 : : if (!in_lto_p || !TYPE_FILE_SCOPE_P (t))
13852 : : verify_variant_match (TYPE_CONTEXT);
13853 : : #endif
13854 : 155803237 : if (TREE_CODE (t) == ARRAY_TYPE || TREE_CODE (t) == INTEGER_TYPE)
13855 : 52948100 : verify_variant_match (TYPE_STRING_FLAG);
13856 : 155803237 : if (TREE_CODE (t) == RECORD_TYPE || TREE_CODE (t) == UNION_TYPE)
13857 : 65115645 : verify_variant_match (TYPE_CXX_ODR_P);
13858 : 155803237 : if (TYPE_ALIAS_SET_KNOWN_P (t))
13859 : : {
13860 : 0 : error ("type variant with %<TYPE_ALIAS_SET_KNOWN_P%>");
13861 : 0 : debug_tree (tv);
13862 : 0 : return false;
13863 : : }
13864 : :
13865 : : /* tree_type_non_common checks. */
13866 : :
13867 : : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
13868 : : and dangle the pointer from time to time. */
13869 : 65115645 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_VFIELD (t) != TYPE_VFIELD (tv)
13870 : 155803237 : && (in_lto_p || !TYPE_VFIELD (tv)
13871 : 0 : || TREE_CODE (TYPE_VFIELD (tv)) != TREE_LIST))
13872 : : {
13873 : 0 : error ("type variant has different %<TYPE_VFIELD%>");
13874 : 0 : debug_tree (tv);
13875 : 0 : return false;
13876 : : }
13877 : 2576516 : if ((TREE_CODE (t) == ENUMERAL_TYPE && COMPLETE_TYPE_P (t))
13878 : 153226776 : || TREE_CODE (t) == INTEGER_TYPE
13879 : 100806739 : || TREE_CODE (t) == BOOLEAN_TYPE
13880 : 78942356 : || TREE_CODE (t) == BITINT_TYPE
13881 : 78942208 : || SCALAR_FLOAT_TYPE_P (t)
13882 : 233641027 : || FIXED_POINT_TYPE_P (t))
13883 : : {
13884 : 77965447 : verify_variant_match (TYPE_MAX_VALUE);
13885 : 77965447 : verify_variant_match (TYPE_MIN_VALUE);
13886 : : }
13887 : 155803237 : if (TREE_CODE (t) == METHOD_TYPE)
13888 : 11027 : verify_variant_match (TYPE_METHOD_BASETYPE);
13889 : 155803237 : if (TREE_CODE (t) == OFFSET_TYPE)
13890 : 167 : verify_variant_match (TYPE_OFFSET_BASETYPE);
13891 : 155803237 : if (TREE_CODE (t) == ARRAY_TYPE)
13892 : 528063 : verify_variant_match (TYPE_ARRAY_MAX_SIZE);
13893 : : /* FIXME: Be lax and allow TYPE_BINFO to be missing in variant types
13894 : : or even type's main variant. This is needed to make bootstrap pass
13895 : : and the bug seems new in GCC 5.
13896 : : C++ FE should be updated to make this consistent and we should check
13897 : : that TYPE_BINFO is always NULL for !COMPLETE_TYPE_P and otherwise there
13898 : : is a match with main variant.
13899 : :
13900 : : Also disable the check for Java for now because of parser hack that builds
13901 : : first an dummy BINFO and then sometimes replace it by real BINFO in some
13902 : : of the copies. */
13903 : 65115645 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t) && TYPE_BINFO (tv)
13904 : 54328787 : && TYPE_BINFO (t) != TYPE_BINFO (tv)
13905 : : /* FIXME: Java sometimes keep dump TYPE_BINFOs on variant types.
13906 : : Since there is no cheap way to tell C++/Java type w/o LTO, do checking
13907 : : at LTO time only. */
13908 : 155803237 : && (in_lto_p && odr_type_p (t)))
13909 : : {
13910 : 0 : error ("type variant has different %<TYPE_BINFO%>");
13911 : 0 : debug_tree (tv);
13912 : 0 : error ("type variant%'s %<TYPE_BINFO%>");
13913 : 0 : debug_tree (TYPE_BINFO (tv));
13914 : 0 : error ("type%'s %<TYPE_BINFO%>");
13915 : 0 : debug_tree (TYPE_BINFO (t));
13916 : 0 : return false;
13917 : : }
13918 : :
13919 : : /* Check various uses of TYPE_VALUES_RAW. */
13920 : 155803237 : if (TREE_CODE (t) == ENUMERAL_TYPE
13921 : 155803237 : && TYPE_VALUES (t))
13922 : 2526491 : verify_variant_match (TYPE_VALUES);
13923 : 153276746 : else if (TREE_CODE (t) == ARRAY_TYPE)
13924 : 528063 : verify_variant_match (TYPE_DOMAIN);
13925 : : /* Permit incomplete variants of complete type. While FEs may complete
13926 : : all variants, this does not happen for C++ templates in all cases. */
13927 : 152748683 : else if (RECORD_OR_UNION_TYPE_P (t)
13928 : 65115645 : && COMPLETE_TYPE_P (t)
13929 : 207470471 : && TYPE_FIELDS (t) != TYPE_FIELDS (tv))
13930 : : {
13931 : 3717 : tree f1, f2;
13932 : :
13933 : : /* Fortran builds qualified variants as new records with items of
13934 : : qualified type. Verify that they looks same. */
13935 : 3717 : for (f1 = TYPE_FIELDS (t), f2 = TYPE_FIELDS (tv);
13936 : 12091 : f1 && f2;
13937 : 8374 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
13938 : 8374 : if (TREE_CODE (f1) != FIELD_DECL || TREE_CODE (f2) != FIELD_DECL
13939 : 8374 : || (TYPE_MAIN_VARIANT (TREE_TYPE (f1))
13940 : 8374 : != TYPE_MAIN_VARIANT (TREE_TYPE (f2))
13941 : : /* FIXME: gfc_nonrestricted_type builds all types as variants
13942 : : with exception of pointer types. It deeply copies the type
13943 : : which means that we may end up with a variant type
13944 : : referring non-variant pointer. We may change it to
13945 : : produce types as variants, too, like
13946 : : objc_get_protocol_qualified_type does. */
13947 : 21 : && !POINTER_TYPE_P (TREE_TYPE (f1)))
13948 : 8374 : || DECL_FIELD_OFFSET (f1) != DECL_FIELD_OFFSET (f2)
13949 : 16748 : || DECL_FIELD_BIT_OFFSET (f1) != DECL_FIELD_BIT_OFFSET (f2))
13950 : : break;
13951 : 3717 : if (f1 || f2)
13952 : : {
13953 : 0 : error ("type variant has different %<TYPE_FIELDS%>");
13954 : 0 : debug_tree (tv);
13955 : 0 : error ("first mismatch is field");
13956 : 0 : debug_tree (f1);
13957 : 0 : error ("and field");
13958 : 0 : debug_tree (f2);
13959 : 0 : return false;
13960 : : }
13961 : : }
13962 : 152744966 : else if (FUNC_OR_METHOD_TYPE_P (t))
13963 : 136390 : verify_variant_match (TYPE_ARG_TYPES);
13964 : : /* For C++ the qualified variant of array type is really an array type
13965 : : of qualified TREE_TYPE.
13966 : : objc builds variants of pointer where pointer to type is a variant, too
13967 : : in objc_get_protocol_qualified_type. */
13968 : 155803237 : if (TREE_TYPE (t) != TREE_TYPE (tv)
13969 : 155803237 : && ((TREE_CODE (t) != ARRAY_TYPE
13970 : 0 : && !POINTER_TYPE_P (t))
13971 : 453700 : || TYPE_MAIN_VARIANT (TREE_TYPE (t))
13972 : 453700 : != TYPE_MAIN_VARIANT (TREE_TYPE (tv))))
13973 : : {
13974 : 0 : error ("type variant has different %<TREE_TYPE%>");
13975 : 0 : debug_tree (tv);
13976 : 0 : error ("type variant%'s %<TREE_TYPE%>");
13977 : 0 : debug_tree (TREE_TYPE (tv));
13978 : 0 : error ("type%'s %<TREE_TYPE%>");
13979 : 0 : debug_tree (TREE_TYPE (t));
13980 : 0 : return false;
13981 : : }
13982 : 155803237 : if (type_with_alias_set_p (t)
13983 : 155803237 : && !gimple_canonical_types_compatible_p (t, tv, false))
13984 : : {
13985 : 0 : error ("type is not compatible with its variant");
13986 : 0 : debug_tree (tv);
13987 : 0 : error ("type variant%'s %<TREE_TYPE%>");
13988 : 0 : debug_tree (TREE_TYPE (tv));
13989 : 0 : error ("type%'s %<TREE_TYPE%>");
13990 : 0 : debug_tree (TREE_TYPE (t));
13991 : 0 : return false;
13992 : : }
13993 : : return true;
13994 : : #undef verify_variant_match
13995 : : }
13996 : :
13997 : :
13998 : : /* The TYPE_CANONICAL merging machinery. It should closely resemble
13999 : : the middle-end types_compatible_p function. It needs to avoid
14000 : : claiming types are different for types that should be treated
14001 : : the same with respect to TBAA. Canonical types are also used
14002 : : for IL consistency checks via the useless_type_conversion_p
14003 : : predicate which does not handle all type kinds itself but falls
14004 : : back to pointer-comparison of TYPE_CANONICAL for aggregates
14005 : : for example. */
14006 : :
14007 : : /* Return true if TYPE_UNSIGNED of TYPE should be ignored for canonical
14008 : : type calculation because we need to allow inter-operability between signed
14009 : : and unsigned variants. */
14010 : :
14011 : : bool
14012 : 1791828 : type_with_interoperable_signedness (const_tree type)
14013 : : {
14014 : : /* Fortran standard require C_SIGNED_CHAR to be interoperable with both
14015 : : signed char and unsigned char. Similarly fortran FE builds
14016 : : C_SIZE_T as signed type, while C defines it unsigned. */
14017 : :
14018 : 1791828 : return tree_code_for_canonical_type_merging (TREE_CODE (type))
14019 : : == INTEGER_TYPE
14020 : 1791627 : && (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node)
14021 : 481184 : || TYPE_PRECISION (type) == TYPE_PRECISION (size_type_node));
14022 : : }
14023 : :
14024 : : /* Return true iff T1 and T2 are structurally identical for what
14025 : : TBAA is concerned.
14026 : : This function is used both by lto.cc canonical type merging and by the
14027 : : verifier. If TRUST_TYPE_CANONICAL we do not look into structure of types
14028 : : that have TYPE_CANONICAL defined and assume them equivalent. This is useful
14029 : : only for LTO because only in these cases TYPE_CANONICAL equivalence
14030 : : correspond to one defined by gimple_canonical_types_compatible_p. */
14031 : :
14032 : : bool
14033 : 330536997 : gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
14034 : : bool trust_type_canonical)
14035 : : {
14036 : : /* Type variants should be same as the main variant. When not doing sanity
14037 : : checking to verify this fact, go to main variants and save some work. */
14038 : 330536997 : if (trust_type_canonical)
14039 : : {
14040 : 959369 : t1 = TYPE_MAIN_VARIANT (t1);
14041 : 959369 : t2 = TYPE_MAIN_VARIANT (t2);
14042 : : }
14043 : :
14044 : : /* Check first for the obvious case of pointer identity. */
14045 : 330536997 : if (t1 == t2)
14046 : : return true;
14047 : :
14048 : : /* Check that we have two types to compare. */
14049 : 276196680 : if (t1 == NULL_TREE || t2 == NULL_TREE)
14050 : : return false;
14051 : :
14052 : : /* We consider complete types always compatible with incomplete type.
14053 : : This does not make sense for canonical type calculation and thus we
14054 : : need to ensure that we are never called on it.
14055 : :
14056 : : FIXME: For more correctness the function probably should have three modes
14057 : : 1) mode assuming that types are complete mathcing their structure
14058 : : 2) mode allowing incomplete types but producing equivalence classes
14059 : : and thus ignoring all info from complete types
14060 : : 3) mode allowing incomplete types to match complete but checking
14061 : : compatibility between complete types.
14062 : :
14063 : : 1 and 2 can be used for canonical type calculation. 3 is the real
14064 : : definition of type compatibility that can be used i.e. for warnings during
14065 : : declaration merging. */
14066 : :
14067 : 276196680 : gcc_assert (!trust_type_canonical
14068 : : || (type_with_alias_set_p (t1) && type_with_alias_set_p (t2)));
14069 : :
14070 : : /* If the types have been previously registered and found equal
14071 : : they still are. */
14072 : :
14073 : 552159438 : if (TYPE_CANONICAL (t1) && TYPE_CANONICAL (t2)
14074 : 551292569 : && trust_type_canonical)
14075 : : {
14076 : : /* Do not use TYPE_CANONICAL of pointer types. For LTO streamed types
14077 : : they are always NULL, but they are set to non-NULL for types
14078 : : constructed by build_pointer_type and variants. In this case the
14079 : : TYPE_CANONICAL is more fine grained than the equivalnce we test (where
14080 : : all pointers are considered equal. Be sure to not return false
14081 : : negatives. */
14082 : 177988 : gcc_checking_assert (canonical_type_used_p (t1)
14083 : : && canonical_type_used_p (t2));
14084 : 88994 : return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
14085 : : }
14086 : :
14087 : : /* For types where we do ODR based TBAA the canonical type is always
14088 : : set correctly, so we know that types are different if their
14089 : : canonical types does not match. */
14090 : 276107686 : if (trust_type_canonical
14091 : 276975069 : && (odr_type_p (t1) && odr_based_tbaa_p (t1))
14092 : 867383 : != (odr_type_p (t2) && odr_based_tbaa_p (t2)))
14093 : : return false;
14094 : :
14095 : : /* Can't be the same type if the types don't have the same code. */
14096 : 276107686 : enum tree_code code = tree_code_for_canonical_type_merging (TREE_CODE (t1));
14097 : 549127745 : if (code != tree_code_for_canonical_type_merging (TREE_CODE (t2)))
14098 : : return false;
14099 : :
14100 : : /* Qualifiers do not matter for canonical type comparison purposes. */
14101 : :
14102 : : /* Void types and nullptr types are always the same. */
14103 : 276107651 : if (VOID_TYPE_P (t1)
14104 : 276067630 : || TREE_CODE (t1) == NULLPTR_TYPE)
14105 : : return true;
14106 : :
14107 : : /* Can't be compatible types if they have different mode. Because of
14108 : : flexible array members, we allow mismatching modes for structures or
14109 : : unions. */
14110 : 275493836 : if (!RECORD_OR_UNION_TYPE_P (t1)
14111 : 275493836 : && TREE_CODE (t1) != ARRAY_TYPE
14112 : 275493836 : && TYPE_MODE (t1) != TYPE_MODE (t2))
14113 : : return false;
14114 : :
14115 : : /* Non-aggregate types can be handled cheaply. */
14116 : 275493836 : if (INTEGRAL_TYPE_P (t1)
14117 : 275493836 : || SCALAR_FLOAT_TYPE_P (t1)
14118 : 148849030 : || FIXED_POINT_TYPE_P (t1)
14119 : 148449016 : || VECTOR_TYPE_P (t1)
14120 : 148424887 : || TREE_CODE (t1) == COMPLEX_TYPE
14121 : 148062142 : || TREE_CODE (t1) == OFFSET_TYPE
14122 : 148061428 : || POINTER_TYPE_P (t1))
14123 : : {
14124 : : /* Can't be the same type if they have different precision. */
14125 : 164665049 : if (TYPE_PRECISION_RAW (t1) != TYPE_PRECISION_RAW (t2))
14126 : : return false;
14127 : :
14128 : : /* In some cases the signed and unsigned types are required to be
14129 : : inter-operable. */
14130 : 164665049 : if (TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)
14131 : 164665049 : && !type_with_interoperable_signedness (t1))
14132 : : return false;
14133 : :
14134 : : /* Fortran's C_SIGNED_CHAR is !TYPE_STRING_FLAG but needs to be
14135 : : interoperable with "signed char". Unless all frontends are revisited
14136 : : to agree on these types, we must ignore the flag completely. */
14137 : :
14138 : : /* Fortran standard define C_PTR type that is compatible with every
14139 : : C pointer. For this reason we need to glob all pointers into one.
14140 : : Still pointers in different address spaces are not compatible. */
14141 : 164665049 : if (POINTER_TYPE_P (t1))
14142 : : {
14143 : 37232641 : if (TYPE_ADDR_SPACE (TREE_TYPE (t1))
14144 : 37232641 : != TYPE_ADDR_SPACE (TREE_TYPE (t2)))
14145 : : return false;
14146 : : }
14147 : :
14148 : : /* Tail-recurse to components. */
14149 : 164665049 : if (VECTOR_TYPE_P (t1)
14150 : 164665049 : || TREE_CODE (t1) == COMPLEX_TYPE)
14151 : 386874 : return gimple_canonical_types_compatible_p (TREE_TYPE (t1),
14152 : 386874 : TREE_TYPE (t2),
14153 : 386874 : trust_type_canonical);
14154 : :
14155 : : return true;
14156 : : }
14157 : :
14158 : : /* Do type-specific comparisons. */
14159 : 110828787 : switch (TREE_CODE (t1))
14160 : : {
14161 : 975989 : case ARRAY_TYPE:
14162 : : /* Array types are the same if the element types are the same and
14163 : : minimum and maximum index are the same. */
14164 : 975989 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14165 : : trust_type_canonical)
14166 : 975950 : || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
14167 : 975950 : || TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2)
14168 : 1951939 : || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
14169 : : return false;
14170 : : else
14171 : : {
14172 : 975950 : tree i1 = TYPE_DOMAIN (t1);
14173 : 975950 : tree i2 = TYPE_DOMAIN (t2);
14174 : :
14175 : : /* For an incomplete external array, the type domain can be
14176 : : NULL_TREE. Check this condition also. */
14177 : 975950 : if (i1 == NULL_TREE && i2 == NULL_TREE)
14178 : : return true;
14179 : 871654 : else if (i1 == NULL_TREE || i2 == NULL_TREE)
14180 : : return false;
14181 : : else
14182 : : {
14183 : 871654 : tree min1 = TYPE_MIN_VALUE (i1);
14184 : 871654 : tree min2 = TYPE_MIN_VALUE (i2);
14185 : 871654 : tree max1 = TYPE_MAX_VALUE (i1);
14186 : 871654 : tree max2 = TYPE_MAX_VALUE (i2);
14187 : :
14188 : : /* The minimum/maximum values have to be the same. */
14189 : 871654 : if ((min1 == min2
14190 : 0 : || (min1 && min2
14191 : 0 : && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
14192 : 0 : && TREE_CODE (min2) == PLACEHOLDER_EXPR)
14193 : 0 : || operand_equal_p (min1, min2, 0))))
14194 : 871654 : && (max1 == max2
14195 : 0 : || (max1 && max2
14196 : 0 : && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
14197 : 0 : && TREE_CODE (max2) == PLACEHOLDER_EXPR)
14198 : 0 : || operand_equal_p (max1, max2, 0)))))
14199 : 871654 : return true;
14200 : : else
14201 : 0 : return false;
14202 : : }
14203 : : }
14204 : :
14205 : 6858 : case METHOD_TYPE:
14206 : 6858 : case FUNCTION_TYPE:
14207 : : /* Function types are the same if the return type and arguments types
14208 : : are the same. */
14209 : 6858 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14210 : : trust_type_canonical))
14211 : : return false;
14212 : :
14213 : 6858 : if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2)
14214 : 6858 : && (TYPE_NO_NAMED_ARGS_STDARG_P (t1)
14215 : 317 : == TYPE_NO_NAMED_ARGS_STDARG_P (t2)))
14216 : : return true;
14217 : : else
14218 : : {
14219 : 6541 : tree parms1, parms2;
14220 : :
14221 : 6541 : for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
14222 : 28804 : parms1 && parms2;
14223 : 22263 : parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
14224 : : {
14225 : 22263 : if (!gimple_canonical_types_compatible_p
14226 : 22263 : (TREE_VALUE (parms1), TREE_VALUE (parms2),
14227 : : trust_type_canonical))
14228 : : return false;
14229 : : }
14230 : :
14231 : 6541 : if (parms1 || parms2)
14232 : : return false;
14233 : :
14234 : : return true;
14235 : : }
14236 : :
14237 : 109454415 : case RECORD_TYPE:
14238 : 109454415 : case UNION_TYPE:
14239 : 109454415 : case QUAL_UNION_TYPE:
14240 : 109454415 : {
14241 : 109454415 : tree f1, f2;
14242 : :
14243 : : /* Don't try to compare variants of an incomplete type, before
14244 : : TYPE_FIELDS has been copied around. */
14245 : 109454415 : if (!COMPLETE_TYPE_P (t1) && !COMPLETE_TYPE_P (t2))
14246 : : return true;
14247 : :
14248 : :
14249 : 99680955 : if (TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2))
14250 : : return false;
14251 : :
14252 : : /* For aggregate types, all the fields must be the same. */
14253 : 99680955 : for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
14254 : 153575878 : f1 || f2;
14255 : 53894923 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
14256 : : {
14257 : : /* Skip non-fields and zero-sized fields, except zero-sized
14258 : : arrays at the end. */
14259 : 1598032154 : while (f1 && (TREE_CODE (f1) != FIELD_DECL
14260 : 99607459 : || (DECL_SIZE (f1)
14261 : 99592844 : && integer_zerop (DECL_SIZE (f1))
14262 : 45712513 : && (TREE_CHAIN (f1)
14263 : 2858 : || TREE_CODE (TREE_TYPE (f1))
14264 : : != ARRAY_TYPE))))
14265 : 1445507475 : f1 = TREE_CHAIN (f1);
14266 : 1598033653 : while (f2 && (TREE_CODE (f2) != FIELD_DECL
14267 : 99621460 : || (DECL_SIZE (f2)
14268 : 99606825 : && integer_zerop (DECL_SIZE (f2))
14269 : 45714017 : && (TREE_CHAIN (f2)
14270 : 3869 : || TREE_CODE (TREE_TYPE (f2))
14271 : : != ARRAY_TYPE))))
14272 : 1445508974 : f2 = TREE_CHAIN (f2);
14273 : 152524679 : if (!f1 || !f2)
14274 : : break;
14275 : :
14276 : 53895150 : tree t1 = TREE_TYPE (f1);
14277 : 53895150 : tree t2 = TREE_TYPE (f2);
14278 : :
14279 : : /* If the last element are arrays, we only compare the element
14280 : : types. */
14281 : 54936465 : if (TREE_CHAIN (f1) == NULL_TREE && TREE_CODE (t1) == ARRAY_TYPE
14282 : 53962116 : && TREE_CHAIN (f2) == NULL_TREE && TREE_CODE (t2) == ARRAY_TYPE)
14283 : : {
14284 : : /* If both arrays have zero size, this is a match. */
14285 : 119725 : if (DECL_SIZE (f1) && integer_zerop (DECL_SIZE (f1))
14286 : 67165 : && DECL_SIZE (f2) && integer_zerop (DECL_SIZE (f2)))
14287 : : return true;
14288 : :
14289 : 66758 : t1 = TREE_TYPE (t1);
14290 : 66758 : t2 = TREE_TYPE (t2);
14291 : : }
14292 : :
14293 : 53894947 : if (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
14294 : 53894942 : || !gimple_compare_field_offset (f1, f2)
14295 : 107789889 : || !gimple_canonical_types_compatible_p
14296 : 53894942 : (t1, t2, trust_type_canonical))
14297 : 24 : return false;
14298 : : }
14299 : :
14300 : : /* If one aggregate has more fields than the other, they
14301 : : are not the same. */
14302 : 99680728 : if (f1 || f2)
14303 : : return false;
14304 : :
14305 : : return true;
14306 : : }
14307 : :
14308 : 391525 : default:
14309 : : /* Consider all types with language specific trees in them mutually
14310 : : compatible. This is executed only from verify_type and false
14311 : : positives can be tolerated. */
14312 : 391525 : gcc_assert (!in_lto_p);
14313 : : return true;
14314 : : }
14315 : : }
14316 : :
14317 : : /* For OPAQUE_TYPE T, it should have only size and alignment information
14318 : : and its mode should be of class MODE_OPAQUE. This function verifies
14319 : : these properties of T match TV which is the main variant of T and TC
14320 : : which is the canonical of T. */
14321 : :
14322 : : static void
14323 : 0 : verify_opaque_type (const_tree t, tree tv, tree tc)
14324 : : {
14325 : 0 : gcc_assert (OPAQUE_TYPE_P (t));
14326 : 0 : gcc_assert (tv && tv == TYPE_MAIN_VARIANT (tv));
14327 : 0 : gcc_assert (tc && tc == TYPE_CANONICAL (tc));
14328 : :
14329 : : /* For an opaque type T1, check if some of its properties match
14330 : : the corresponding ones of the other opaque type T2, emit some
14331 : : error messages for those inconsistent ones. */
14332 : 0 : auto check_properties_for_opaque_type = [](const_tree t1, tree t2,
14333 : : const char *kind_msg)
14334 : : {
14335 : 0 : if (!OPAQUE_TYPE_P (t2))
14336 : : {
14337 : 0 : error ("type %s is not an opaque type", kind_msg);
14338 : 0 : debug_tree (t2);
14339 : 0 : return;
14340 : : }
14341 : 0 : if (!OPAQUE_MODE_P (TYPE_MODE (t2)))
14342 : : {
14343 : 0 : error ("type %s is not with opaque mode", kind_msg);
14344 : 0 : debug_tree (t2);
14345 : 0 : return;
14346 : : }
14347 : 0 : if (TYPE_MODE (t1) != TYPE_MODE (t2))
14348 : : {
14349 : 0 : error ("type %s differs by %<TYPE_MODE%>", kind_msg);
14350 : 0 : debug_tree (t2);
14351 : 0 : return;
14352 : : }
14353 : 0 : poly_uint64 t1_size = tree_to_poly_uint64 (TYPE_SIZE (t1));
14354 : 0 : poly_uint64 t2_size = tree_to_poly_uint64 (TYPE_SIZE (t2));
14355 : 0 : if (maybe_ne (t1_size, t2_size))
14356 : : {
14357 : 0 : error ("type %s differs by %<TYPE_SIZE%>", kind_msg);
14358 : 0 : debug_tree (t2);
14359 : 0 : return;
14360 : : }
14361 : 0 : if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2))
14362 : : {
14363 : 0 : error ("type %s differs by %<TYPE_ALIGN%>", kind_msg);
14364 : 0 : debug_tree (t2);
14365 : 0 : return;
14366 : : }
14367 : 0 : if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
14368 : : {
14369 : 0 : error ("type %s differs by %<TYPE_USER_ALIGN%>", kind_msg);
14370 : 0 : debug_tree (t2);
14371 : 0 : return;
14372 : : }
14373 : : };
14374 : :
14375 : 0 : if (t != tv)
14376 : 0 : check_properties_for_opaque_type (t, tv, "variant");
14377 : :
14378 : 0 : if (t != tc)
14379 : 0 : check_properties_for_opaque_type (t, tc, "canonical");
14380 : 0 : }
14381 : :
14382 : : /* Verify type T. */
14383 : :
14384 : : void
14385 : 758267210 : verify_type (const_tree t)
14386 : : {
14387 : 758267210 : bool error_found = false;
14388 : 758267210 : tree mv = TYPE_MAIN_VARIANT (t);
14389 : 758267210 : tree ct = TYPE_CANONICAL (t);
14390 : :
14391 : 758267210 : if (OPAQUE_TYPE_P (t))
14392 : : {
14393 : 0 : verify_opaque_type (t, mv, ct);
14394 : 0 : return;
14395 : : }
14396 : :
14397 : 758267210 : if (!mv)
14398 : : {
14399 : 0 : error ("main variant is not defined");
14400 : 0 : error_found = true;
14401 : : }
14402 : 758267210 : else if (mv != TYPE_MAIN_VARIANT (mv))
14403 : : {
14404 : 0 : error ("%<TYPE_MAIN_VARIANT%> has different %<TYPE_MAIN_VARIANT%>");
14405 : 0 : debug_tree (mv);
14406 : 0 : error_found = true;
14407 : : }
14408 : 758267210 : else if (t != mv && !verify_type_variant (t, mv))
14409 : : error_found = true;
14410 : :
14411 : 758267210 : if (!ct)
14412 : : ;
14413 : 756265994 : else if (TYPE_CANONICAL (ct) != ct)
14414 : : {
14415 : 0 : error ("%<TYPE_CANONICAL%> has different %<TYPE_CANONICAL%>");
14416 : 0 : debug_tree (ct);
14417 : 0 : error_found = true;
14418 : : }
14419 : : /* Method and function types cannot be used to address memory and thus
14420 : : TYPE_CANONICAL really matters only for determining useless conversions.
14421 : :
14422 : : FIXME: C++ FE produce declarations of builtin functions that are not
14423 : : compatible with main variants. */
14424 : 756265994 : else if (TREE_CODE (t) == FUNCTION_TYPE)
14425 : : ;
14426 : 755656590 : else if (t != ct
14427 : : /* FIXME: gimple_canonical_types_compatible_p cannot compare types
14428 : : with variably sized arrays because their sizes possibly
14429 : : gimplified to different variables. */
14430 : 129218318 : && !variably_modified_type_p (ct, NULL)
14431 : 129213983 : && !gimple_canonical_types_compatible_p (t, ct, false)
14432 : 755669092 : && COMPLETE_TYPE_P (t))
14433 : : {
14434 : 0 : error ("%<TYPE_CANONICAL%> is not compatible");
14435 : 0 : debug_tree (ct);
14436 : 0 : error_found = true;
14437 : : }
14438 : 1365066024 : if (COMPLETE_TYPE_P (t) && TYPE_CANONICAL (t)
14439 : : /* We allow a mismatch for structure or union because of
14440 : : flexible array members. */
14441 : 604864890 : && !RECORD_OR_UNION_TYPE_P (t)
14442 : 250923126 : && !RECORD_OR_UNION_TYPE_P (TYPE_CANONICAL (t))
14443 : 250923126 : && TREE_CODE (t) != ARRAY_TYPE
14444 : 1007817768 : && TYPE_MODE (t) != TYPE_MODE (TYPE_CANONICAL (t)))
14445 : : {
14446 : 0 : error ("%<TYPE_MODE%> of %<TYPE_CANONICAL%> is not compatible");
14447 : 0 : debug_tree (ct);
14448 : 0 : error_found = true;
14449 : : }
14450 : 758267210 : if (TYPE_MAIN_VARIANT (t) == t && ct && TYPE_MAIN_VARIANT (ct) != ct)
14451 : : {
14452 : 0 : error ("%<TYPE_CANONICAL%> of main variant is not main variant");
14453 : 0 : debug_tree (ct);
14454 : 0 : debug_tree (TYPE_MAIN_VARIANT (ct));
14455 : 0 : error_found = true;
14456 : : }
14457 : :
14458 : :
14459 : : /* Check various uses of TYPE_MIN_VALUE_RAW. */
14460 : 758267210 : if (RECORD_OR_UNION_TYPE_P (t))
14461 : : {
14462 : : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
14463 : : and danagle the pointer from time to time. */
14464 : 396369194 : if (TYPE_VFIELD (t)
14465 : 10907701 : && TREE_CODE (TYPE_VFIELD (t)) != FIELD_DECL
14466 : 396369194 : && TREE_CODE (TYPE_VFIELD (t)) != TREE_LIST)
14467 : : {
14468 : 0 : error ("%<TYPE_VFIELD%> is not %<FIELD_DECL%> nor %<TREE_LIST%>");
14469 : 0 : debug_tree (TYPE_VFIELD (t));
14470 : 0 : error_found = true;
14471 : : }
14472 : : }
14473 : 361898016 : else if (TREE_CODE (t) == POINTER_TYPE)
14474 : : {
14475 : 95389833 : if (TYPE_NEXT_PTR_TO (t)
14476 : 95389833 : && TREE_CODE (TYPE_NEXT_PTR_TO (t)) != POINTER_TYPE)
14477 : : {
14478 : 0 : error ("%<TYPE_NEXT_PTR_TO%> is not %<POINTER_TYPE%>");
14479 : 0 : debug_tree (TYPE_NEXT_PTR_TO (t));
14480 : 0 : error_found = true;
14481 : : }
14482 : : }
14483 : 266508183 : else if (TREE_CODE (t) == REFERENCE_TYPE)
14484 : : {
14485 : 44003267 : if (TYPE_NEXT_REF_TO (t)
14486 : 44003267 : && TREE_CODE (TYPE_NEXT_REF_TO (t)) != REFERENCE_TYPE)
14487 : : {
14488 : 0 : error ("%<TYPE_NEXT_REF_TO%> is not %<REFERENCE_TYPE%>");
14489 : 0 : debug_tree (TYPE_NEXT_REF_TO (t));
14490 : 0 : error_found = true;
14491 : : }
14492 : : }
14493 : : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14494 : : || FIXED_POINT_TYPE_P (t))
14495 : : {
14496 : : /* FIXME: The following check should pass:
14497 : : useless_type_conversion_p (const_cast <tree> (t),
14498 : : TREE_TYPE (TYPE_MIN_VALUE (t))
14499 : : but does not for C sizetypes in LTO. */
14500 : : }
14501 : :
14502 : : /* Check various uses of TYPE_MAXVAL_RAW. */
14503 : 758267210 : if (RECORD_OR_UNION_TYPE_P (t))
14504 : : {
14505 : 396369194 : if (!TYPE_BINFO (t))
14506 : : ;
14507 : 370890126 : else if (TREE_CODE (TYPE_BINFO (t)) != TREE_BINFO)
14508 : : {
14509 : 0 : error ("%<TYPE_BINFO%> is not %<TREE_BINFO%>");
14510 : 0 : debug_tree (TYPE_BINFO (t));
14511 : 0 : error_found = true;
14512 : : }
14513 : 370890126 : else if (TREE_TYPE (TYPE_BINFO (t)) != TYPE_MAIN_VARIANT (t))
14514 : : {
14515 : 0 : error ("%<TYPE_BINFO%> type is not %<TYPE_MAIN_VARIANT%>");
14516 : 0 : debug_tree (TREE_TYPE (TYPE_BINFO (t)));
14517 : 0 : error_found = true;
14518 : : }
14519 : : }
14520 : : else if (FUNC_OR_METHOD_TYPE_P (t))
14521 : : {
14522 : 828531 : if (TYPE_METHOD_BASETYPE (t)
14523 : 69421 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != RECORD_TYPE
14524 : 828719 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != UNION_TYPE)
14525 : : {
14526 : 0 : error ("%<TYPE_METHOD_BASETYPE%> is not record nor union");
14527 : 0 : debug_tree (TYPE_METHOD_BASETYPE (t));
14528 : 0 : error_found = true;
14529 : : }
14530 : : }
14531 : : else if (TREE_CODE (t) == OFFSET_TYPE)
14532 : : {
14533 : 36106 : if (TYPE_OFFSET_BASETYPE (t)
14534 : 36106 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != RECORD_TYPE
14535 : 36114 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != UNION_TYPE)
14536 : : {
14537 : 0 : error ("%<TYPE_OFFSET_BASETYPE%> is not record nor union");
14538 : 0 : debug_tree (TYPE_OFFSET_BASETYPE (t));
14539 : 0 : error_found = true;
14540 : : }
14541 : : }
14542 : : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14543 : : || FIXED_POINT_TYPE_P (t))
14544 : : {
14545 : : /* FIXME: The following check should pass:
14546 : : useless_type_conversion_p (const_cast <tree> (t),
14547 : : TREE_TYPE (TYPE_MAX_VALUE (t))
14548 : : but does not for C sizetypes in LTO. */
14549 : : }
14550 : : else if (TREE_CODE (t) == ARRAY_TYPE)
14551 : : {
14552 : 1622996 : if (TYPE_ARRAY_MAX_SIZE (t)
14553 : 1622996 : && TREE_CODE (TYPE_ARRAY_MAX_SIZE (t)) != INTEGER_CST)
14554 : : {
14555 : 0 : error ("%<TYPE_ARRAY_MAX_SIZE%> not %<INTEGER_CST%>");
14556 : 0 : debug_tree (TYPE_ARRAY_MAX_SIZE (t));
14557 : 0 : error_found = true;
14558 : : }
14559 : : }
14560 : 249644638 : else if (TYPE_MAX_VALUE_RAW (t))
14561 : : {
14562 : 0 : error ("%<TYPE_MAX_VALUE_RAW%> non-NULL");
14563 : 0 : debug_tree (TYPE_MAX_VALUE_RAW (t));
14564 : 0 : error_found = true;
14565 : : }
14566 : :
14567 : 758267210 : if (TYPE_LANG_SLOT_1 (t) && in_lto_p)
14568 : : {
14569 : 0 : error ("%<TYPE_LANG_SLOT_1 (binfo)%> field is non-NULL");
14570 : 0 : debug_tree (TYPE_LANG_SLOT_1 (t));
14571 : 0 : error_found = true;
14572 : : }
14573 : :
14574 : : /* Check various uses of TYPE_VALUES_RAW. */
14575 : 758267210 : if (TREE_CODE (t) == ENUMERAL_TYPE)
14576 : 88219275 : for (tree l = TYPE_VALUES (t); l; l = TREE_CHAIN (l))
14577 : : {
14578 : 77257521 : tree value = TREE_VALUE (l);
14579 : 77257521 : tree name = TREE_PURPOSE (l);
14580 : :
14581 : : /* C FE porduce INTEGER_CST of INTEGER_TYPE, while C++ FE uses
14582 : : CONST_DECL of ENUMERAL TYPE. */
14583 : 77257521 : if (TREE_CODE (value) != INTEGER_CST && TREE_CODE (value) != CONST_DECL)
14584 : : {
14585 : 0 : error ("enum value is not %<CONST_DECL%> or %<INTEGER_CST%>");
14586 : 0 : debug_tree (value);
14587 : 0 : debug_tree (name);
14588 : 0 : error_found = true;
14589 : : }
14590 : 77257521 : if (TREE_CODE (TREE_TYPE (value)) != INTEGER_TYPE
14591 : 77240387 : && TREE_CODE (TREE_TYPE (value)) != BOOLEAN_TYPE
14592 : 154497905 : && !useless_type_conversion_p (const_cast <tree> (t), TREE_TYPE (value)))
14593 : : {
14594 : 0 : error ("enum value type is not %<INTEGER_TYPE%> nor convertible "
14595 : : "to the enum");
14596 : 0 : debug_tree (value);
14597 : 0 : debug_tree (name);
14598 : 0 : error_found = true;
14599 : : }
14600 : 77257521 : if (TREE_CODE (name) != IDENTIFIER_NODE)
14601 : : {
14602 : 0 : error ("enum value name is not %<IDENTIFIER_NODE%>");
14603 : 0 : debug_tree (value);
14604 : 0 : debug_tree (name);
14605 : 0 : error_found = true;
14606 : : }
14607 : : }
14608 : 747305456 : else if (TREE_CODE (t) == ARRAY_TYPE)
14609 : : {
14610 : 1622996 : if (TYPE_DOMAIN (t) && TREE_CODE (TYPE_DOMAIN (t)) != INTEGER_TYPE)
14611 : : {
14612 : 0 : error ("array %<TYPE_DOMAIN%> is not integer type");
14613 : 0 : debug_tree (TYPE_DOMAIN (t));
14614 : 0 : error_found = true;
14615 : : }
14616 : : }
14617 : 745682460 : else if (RECORD_OR_UNION_TYPE_P (t))
14618 : : {
14619 : 396369194 : if (TYPE_FIELDS (t) && !COMPLETE_TYPE_P (t) && in_lto_p)
14620 : : {
14621 : 0 : error ("%<TYPE_FIELDS%> defined in incomplete type");
14622 : 0 : error_found = true;
14623 : : }
14624 : 17764301745 : for (tree fld = TYPE_FIELDS (t); fld; fld = TREE_CHAIN (fld))
14625 : : {
14626 : : /* TODO: verify properties of decls. */
14627 : 17367932551 : if (TREE_CODE (fld) == FIELD_DECL)
14628 : : ;
14629 : : else if (TREE_CODE (fld) == TYPE_DECL)
14630 : : ;
14631 : : else if (TREE_CODE (fld) == CONST_DECL)
14632 : : ;
14633 : : else if (VAR_P (fld))
14634 : : ;
14635 : : else if (TREE_CODE (fld) == TEMPLATE_DECL)
14636 : : ;
14637 : : else if (TREE_CODE (fld) == USING_DECL)
14638 : : ;
14639 : : else if (TREE_CODE (fld) == FUNCTION_DECL)
14640 : : ;
14641 : : else
14642 : : {
14643 : 0 : error ("wrong tree in %<TYPE_FIELDS%> list");
14644 : 0 : debug_tree (fld);
14645 : 0 : error_found = true;
14646 : : }
14647 : : }
14648 : : }
14649 : 349313266 : else if (TREE_CODE (t) == INTEGER_TYPE
14650 : : || TREE_CODE (t) == BOOLEAN_TYPE
14651 : 349313266 : || TREE_CODE (t) == BITINT_TYPE
14652 : 254411948 : || TREE_CODE (t) == OFFSET_TYPE
14653 : 254375842 : || TREE_CODE (t) == REFERENCE_TYPE
14654 : 210372575 : || TREE_CODE (t) == NULLPTR_TYPE
14655 : 210069712 : || TREE_CODE (t) == POINTER_TYPE)
14656 : : {
14657 : 234633387 : if (TYPE_CACHED_VALUES_P (t) != (TYPE_CACHED_VALUES (t) != NULL))
14658 : : {
14659 : 0 : error ("%<TYPE_CACHED_VALUES_P%> is %i while %<TYPE_CACHED_VALUES%> "
14660 : : "is %p",
14661 : 0 : TYPE_CACHED_VALUES_P (t), (void *)TYPE_CACHED_VALUES (t));
14662 : 0 : error_found = true;
14663 : : }
14664 : 234633387 : else if (TYPE_CACHED_VALUES_P (t) && TREE_CODE (TYPE_CACHED_VALUES (t)) != TREE_VEC)
14665 : : {
14666 : 0 : error ("%<TYPE_CACHED_VALUES%> is not %<TREE_VEC%>");
14667 : 0 : debug_tree (TYPE_CACHED_VALUES (t));
14668 : 0 : error_found = true;
14669 : : }
14670 : : /* Verify just enough of cache to ensure that no one copied it to new type.
14671 : : All copying should go by copy_node that should clear it. */
14672 : 234633387 : else if (TYPE_CACHED_VALUES_P (t))
14673 : : {
14674 : : int i;
14675 : 7772688962 : for (i = 0; i < TREE_VEC_LENGTH (TYPE_CACHED_VALUES (t)); i++)
14676 : 7723452284 : if (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)
14677 : 7723452284 : && TREE_TYPE (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)) != t)
14678 : : {
14679 : 0 : error ("wrong %<TYPE_CACHED_VALUES%> entry");
14680 : 0 : debug_tree (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i));
14681 : 0 : error_found = true;
14682 : 0 : break;
14683 : : }
14684 : : }
14685 : : }
14686 : 114679879 : else if (FUNC_OR_METHOD_TYPE_P (t))
14687 : 3118448 : for (tree l = TYPE_ARG_TYPES (t); l; l = TREE_CHAIN (l))
14688 : : {
14689 : : /* C++ FE uses TREE_PURPOSE to store initial values. */
14690 : 2289917 : if (TREE_PURPOSE (l) && in_lto_p)
14691 : : {
14692 : 0 : error ("%<TREE_PURPOSE%> is non-NULL in %<TYPE_ARG_TYPES%> list");
14693 : 0 : debug_tree (l);
14694 : 0 : error_found = true;
14695 : : }
14696 : 2289917 : if (!TYPE_P (TREE_VALUE (l)))
14697 : : {
14698 : 0 : error ("wrong entry in %<TYPE_ARG_TYPES%> list");
14699 : 0 : debug_tree (l);
14700 : 0 : error_found = true;
14701 : : }
14702 : : }
14703 : 227288675 : else if (!is_lang_specific (t) && TYPE_VALUES_RAW (t))
14704 : : {
14705 : 0 : error ("%<TYPE_VALUES_RAW%> field is non-NULL");
14706 : 0 : debug_tree (TYPE_VALUES_RAW (t));
14707 : 0 : error_found = true;
14708 : : }
14709 : 758267210 : if (TREE_CODE (t) != INTEGER_TYPE
14710 : : && TREE_CODE (t) != BOOLEAN_TYPE
14711 : 758267210 : && TREE_CODE (t) != BITINT_TYPE
14712 : : && TREE_CODE (t) != OFFSET_TYPE
14713 : : && TREE_CODE (t) != REFERENCE_TYPE
14714 : : && TREE_CODE (t) != NULLPTR_TYPE
14715 : : && TREE_CODE (t) != POINTER_TYPE
14716 : 523633823 : && TYPE_CACHED_VALUES_P (t))
14717 : : {
14718 : 0 : error ("%<TYPE_CACHED_VALUES_P%> is set while it should not be");
14719 : 0 : error_found = true;
14720 : : }
14721 : :
14722 : : /* ipa-devirt makes an assumption that TYPE_METHOD_BASETYPE is always
14723 : : TYPE_MAIN_VARIANT and it would be odd to add methods only to variatns
14724 : : of a type. */
14725 : 758267210 : if (TREE_CODE (t) == METHOD_TYPE
14726 : 758267210 : && TYPE_MAIN_VARIANT (TYPE_METHOD_BASETYPE (t)) != TYPE_METHOD_BASETYPE (t))
14727 : : {
14728 : 0 : error ("%<TYPE_METHOD_BASETYPE%> is not main variant");
14729 : 0 : error_found = true;
14730 : : }
14731 : :
14732 : 758267210 : if (error_found)
14733 : : {
14734 : 0 : debug_tree (const_cast <tree> (t));
14735 : 0 : internal_error ("%qs failed", __func__);
14736 : : }
14737 : : }
14738 : :
14739 : :
14740 : : /* Return 1 if ARG interpreted as signed in its precision is known to be
14741 : : always non-negative or 2 if ARG is known to be always negative, or 3 if
14742 : : ARG may be non-negative or negative. STMT if specified is the statement
14743 : : on which it is being tested. */
14744 : :
14745 : : int
14746 : 891231 : get_range_pos_neg (tree arg, gimple *stmt)
14747 : : {
14748 : 891231 : if (arg == error_mark_node || !INTEGRAL_TYPE_P (TREE_TYPE (arg)))
14749 : : return 3;
14750 : :
14751 : 891231 : int prec = TYPE_PRECISION (TREE_TYPE (arg));
14752 : 891231 : int cnt = 0;
14753 : 891231 : if (TREE_CODE (arg) == INTEGER_CST)
14754 : : {
14755 : 84050 : wide_int w = wi::sext (wi::to_wide (arg), prec);
14756 : 84050 : if (wi::neg_p (w))
14757 : : return 2;
14758 : : else
14759 : 69598 : return 1;
14760 : 84050 : }
14761 : 805970 : while (CONVERT_EXPR_P (arg)
14762 : 14499 : && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
14763 : 834968 : && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg, 0))) <= prec)
14764 : : {
14765 : 13715 : arg = TREE_OPERAND (arg, 0);
14766 : : /* Narrower value zero extended into wider type
14767 : : will always result in positive values. */
14768 : 13715 : if (TYPE_UNSIGNED (TREE_TYPE (arg))
14769 : 13715 : && TYPE_PRECISION (TREE_TYPE (arg)) < prec)
14770 : : return 1;
14771 : 13288 : prec = TYPE_PRECISION (TREE_TYPE (arg));
14772 : 13288 : if (++cnt > 30)
14773 : : return 3;
14774 : : }
14775 : :
14776 : 806754 : if (TREE_CODE (arg) != SSA_NAME)
14777 : : return 3;
14778 : 799932 : int_range_max r;
14779 : 1615243 : while (!get_range_query (cfun)->range_of_expr (r, arg, stmt)
14780 : 1630622 : || r.undefined_p () || r.varying_p ())
14781 : : {
14782 : 506463 : gimple *g = SSA_NAME_DEF_STMT (arg);
14783 : 506463 : if (is_gimple_assign (g)
14784 : 506463 : && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (g)))
14785 : : {
14786 : 24941 : tree t = gimple_assign_rhs1 (g);
14787 : 49528 : if (INTEGRAL_TYPE_P (TREE_TYPE (t))
14788 : 46849 : && TYPE_PRECISION (TREE_TYPE (t)) <= prec)
14789 : : {
14790 : 15379 : if (TYPE_UNSIGNED (TREE_TYPE (t))
14791 : 15379 : && TYPE_PRECISION (TREE_TYPE (t)) < prec)
14792 : : return 1;
14793 : 15379 : prec = TYPE_PRECISION (TREE_TYPE (t));
14794 : 15379 : arg = t;
14795 : 15379 : if (++cnt > 30)
14796 : : return 3;
14797 : 15379 : continue;
14798 : : }
14799 : : }
14800 : : return 3;
14801 : : }
14802 : 308848 : if (TYPE_UNSIGNED (TREE_TYPE (arg)))
14803 : : {
14804 : : /* For unsigned values, the "positive" range comes
14805 : : below the "negative" range. */
14806 : 134123 : if (!wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14807 : : return 1;
14808 : 38331 : if (wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14809 : : return 2;
14810 : : }
14811 : : else
14812 : : {
14813 : 174725 : if (!wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14814 : : return 1;
14815 : 70618 : if (wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14816 : : return 2;
14817 : : }
14818 : : return 3;
14819 : 799932 : }
14820 : :
14821 : :
14822 : :
14823 : :
14824 : : /* Return true if ARG is marked with the nonnull attribute in the
14825 : : current function signature. */
14826 : :
14827 : : bool
14828 : 26927624 : nonnull_arg_p (const_tree arg)
14829 : : {
14830 : 26927624 : tree t, attrs, fntype;
14831 : 26927624 : unsigned HOST_WIDE_INT arg_num;
14832 : :
14833 : 26927624 : gcc_assert (TREE_CODE (arg) == PARM_DECL
14834 : : && (POINTER_TYPE_P (TREE_TYPE (arg))
14835 : : || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE));
14836 : :
14837 : : /* The static chain decl is always non null. */
14838 : 26927624 : if (arg == cfun->static_chain_decl)
14839 : : return true;
14840 : :
14841 : : /* THIS argument of method is always non-NULL. */
14842 : 26659507 : if (TREE_CODE (TREE_TYPE (cfun->decl)) == METHOD_TYPE
14843 : 10518158 : && arg == DECL_ARGUMENTS (cfun->decl)
14844 : 33240563 : && flag_delete_null_pointer_checks)
14845 : : return true;
14846 : :
14847 : : /* Values passed by reference are always non-NULL. */
14848 : 20080529 : if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE
14849 : 20080529 : && flag_delete_null_pointer_checks)
14850 : : return true;
14851 : :
14852 : 13756263 : fntype = TREE_TYPE (cfun->decl);
14853 : 13779203 : for (attrs = TYPE_ATTRIBUTES (fntype); attrs; attrs = TREE_CHAIN (attrs))
14854 : : {
14855 : 538899 : attrs = lookup_attribute ("nonnull", attrs);
14856 : :
14857 : : /* If "nonnull" wasn't specified, we know nothing about the argument. */
14858 : 538899 : if (attrs == NULL_TREE)
14859 : : return false;
14860 : :
14861 : : /* If "nonnull" applies to all the arguments, then ARG is non-null. */
14862 : 111823 : if (TREE_VALUE (attrs) == NULL_TREE)
14863 : : return true;
14864 : :
14865 : : /* Get the position number for ARG in the function signature. */
14866 : 55801 : for (arg_num = 1, t = DECL_ARGUMENTS (cfun->decl);
14867 : 130340 : t;
14868 : 74539 : t = DECL_CHAIN (t), arg_num++)
14869 : : {
14870 : 130340 : if (t == arg)
14871 : : break;
14872 : : }
14873 : :
14874 : 55801 : gcc_assert (t == arg);
14875 : :
14876 : : /* Now see if ARG_NUM is mentioned in the nonnull list. */
14877 : 88463 : for (t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
14878 : : {
14879 : 65523 : if (compare_tree_int (TREE_VALUE (t), arg_num) == 0)
14880 : : return true;
14881 : : }
14882 : : }
14883 : :
14884 : : return false;
14885 : : }
14886 : :
14887 : : /* Combine LOC and BLOCK to a combined adhoc loc, retaining any range
14888 : : information. */
14889 : :
14890 : : location_t
14891 : 667252000 : set_block (location_t loc, tree block)
14892 : : {
14893 : 667252000 : location_t pure_loc = get_pure_location (loc);
14894 : 667252000 : source_range src_range = get_range_from_loc (line_table, loc);
14895 : 667252000 : unsigned discriminator = get_discriminator_from_loc (line_table, loc);
14896 : 667252000 : return line_table->get_or_create_combined_loc (pure_loc, src_range, block,
14897 : 667252000 : discriminator);
14898 : : }
14899 : :
14900 : : location_t
14901 : 220680332 : set_source_range (tree expr, location_t start, location_t finish)
14902 : : {
14903 : 220680332 : source_range src_range;
14904 : 220680332 : src_range.m_start = start;
14905 : 220680332 : src_range.m_finish = finish;
14906 : 220680332 : return set_source_range (expr, src_range);
14907 : : }
14908 : :
14909 : : location_t
14910 : 450786698 : set_source_range (tree expr, source_range src_range)
14911 : : {
14912 : 450786698 : if (!EXPR_P (expr))
14913 : : return UNKNOWN_LOCATION;
14914 : :
14915 : 198469016 : location_t expr_location = EXPR_LOCATION (expr);
14916 : 198469016 : location_t pure_loc = get_pure_location (expr_location);
14917 : 198469016 : unsigned discriminator = get_discriminator_from_loc (expr_location);
14918 : 198469016 : location_t adhoc = line_table->get_or_create_combined_loc (pure_loc,
14919 : : src_range,
14920 : : nullptr,
14921 : : discriminator);
14922 : 198469016 : SET_EXPR_LOCATION (expr, adhoc);
14923 : 198469016 : return adhoc;
14924 : : }
14925 : :
14926 : : /* Return EXPR, potentially wrapped with a node expression LOC,
14927 : : if !CAN_HAVE_LOCATION_P (expr).
14928 : :
14929 : : NON_LVALUE_EXPR is used for wrapping constants, apart from STRING_CST.
14930 : : VIEW_CONVERT_EXPR is used for wrapping non-constants and STRING_CST.
14931 : :
14932 : : Wrapper nodes can be identified using location_wrapper_p. */
14933 : :
14934 : : tree
14935 : 1293627233 : maybe_wrap_with_location (tree expr, location_t loc)
14936 : : {
14937 : 1293627233 : if (expr == NULL)
14938 : : return NULL;
14939 : 1293627229 : if (loc == UNKNOWN_LOCATION)
14940 : : return expr;
14941 : 1249597142 : if (CAN_HAVE_LOCATION_P (expr))
14942 : : return expr;
14943 : : /* We should only be adding wrappers for constants and for decls,
14944 : : or for some exceptional tree nodes (e.g. BASELINK in the C++ FE). */
14945 : 758080567 : gcc_assert (CONSTANT_CLASS_P (expr)
14946 : : || DECL_P (expr)
14947 : : || EXCEPTIONAL_CLASS_P (expr));
14948 : :
14949 : : /* For now, don't add wrappers to exceptional tree nodes, to minimize
14950 : : any impact of the wrapper nodes. */
14951 : 758080567 : if (EXCEPTIONAL_CLASS_P (expr) || error_operand_p (expr))
14952 : : return expr;
14953 : :
14954 : : /* Compiler-generated temporary variables don't need a wrapper. */
14955 : 699292499 : if (DECL_P (expr) && DECL_ARTIFICIAL (expr) && DECL_IGNORED_P (expr))
14956 : : return expr;
14957 : :
14958 : : /* If any auto_suppress_location_wrappers are active, don't create
14959 : : wrappers. */
14960 : 699290209 : if (suppress_location_wrappers > 0)
14961 : : return expr;
14962 : :
14963 : 1333684288 : tree_code code
14964 : 167199359 : = (((CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST)
14965 : 506937058 : || (TREE_CODE (expr) == CONST_DECL && !TREE_STATIC (expr)))
14966 : 666842144 : ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR);
14967 : 666842144 : tree wrapper = build1_loc (loc, code, TREE_TYPE (expr), expr);
14968 : : /* Mark this node as being a wrapper. */
14969 : 666842144 : EXPR_LOCATION_WRAPPER_P (wrapper) = 1;
14970 : 666842144 : return wrapper;
14971 : : }
14972 : :
14973 : : int suppress_location_wrappers;
14974 : :
14975 : : /* Return the name of combined function FN, for debugging purposes. */
14976 : :
14977 : : const char *
14978 : 0 : combined_fn_name (combined_fn fn)
14979 : : {
14980 : 0 : if (builtin_fn_p (fn))
14981 : : {
14982 : 0 : tree fndecl = builtin_decl_explicit (as_builtin_fn (fn));
14983 : 0 : return IDENTIFIER_POINTER (DECL_NAME (fndecl));
14984 : : }
14985 : : else
14986 : 0 : return internal_fn_name (as_internal_fn (fn));
14987 : : }
14988 : :
14989 : : /* Return a bitmap with a bit set corresponding to each argument in
14990 : : a function call type FNTYPE declared with attribute nonnull,
14991 : : or null if none of the function's argument are nonnull. The caller
14992 : : must free the bitmap. */
14993 : :
14994 : : bitmap
14995 : 21712600 : get_nonnull_args (const_tree fntype)
14996 : : {
14997 : 21712600 : if (fntype == NULL_TREE)
14998 : : return NULL;
14999 : :
15000 : 21016458 : bitmap argmap = NULL;
15001 : 21016458 : if (TREE_CODE (fntype) == METHOD_TYPE)
15002 : : {
15003 : : /* The this pointer in C++ non-static member functions is
15004 : : implicitly nonnull whether or not it's declared as such. */
15005 : 2936127 : argmap = BITMAP_ALLOC (NULL);
15006 : 2936127 : bitmap_set_bit (argmap, 0);
15007 : : }
15008 : :
15009 : 21016458 : tree attrs = TYPE_ATTRIBUTES (fntype);
15010 : 21016458 : if (!attrs)
15011 : : return argmap;
15012 : :
15013 : : /* A function declaration can specify multiple attribute nonnull,
15014 : : each with zero or more arguments. The loop below creates a bitmap
15015 : : representing a union of all the arguments. An empty (but non-null)
15016 : : bitmap means that all arguments have been declared nonnull. */
15017 : 5832082 : for ( ; attrs; attrs = TREE_CHAIN (attrs))
15018 : : {
15019 : 5728854 : attrs = lookup_attribute ("nonnull", attrs);
15020 : 5728854 : if (!attrs)
15021 : : break;
15022 : :
15023 : 1620725 : if (!argmap)
15024 : 1580687 : argmap = BITMAP_ALLOC (NULL);
15025 : :
15026 : 1620725 : if (!TREE_VALUE (attrs))
15027 : : {
15028 : : /* Clear the bitmap in case a previous attribute nonnull
15029 : : set it and this one overrides it for all arguments. */
15030 : 987902 : bitmap_clear (argmap);
15031 : 987902 : return argmap;
15032 : : }
15033 : :
15034 : : /* Iterate over the indices of the format arguments declared nonnull
15035 : : and set a bit for each. */
15036 : 1666611 : for (tree idx = TREE_VALUE (attrs); idx; idx = TREE_CHAIN (idx))
15037 : : {
15038 : 1033788 : unsigned int val = TREE_INT_CST_LOW (TREE_VALUE (idx)) - 1;
15039 : 1033788 : bitmap_set_bit (argmap, val);
15040 : : }
15041 : : }
15042 : :
15043 : : return argmap;
15044 : : }
15045 : :
15046 : : /* Returns true if TYPE is a type where it and all of its subobjects
15047 : : (recursively) are of structure, union, or array type. */
15048 : :
15049 : : bool
15050 : 1826410398 : is_empty_type (const_tree type)
15051 : : {
15052 : 1826410398 : if (RECORD_OR_UNION_TYPE_P (type))
15053 : : {
15054 : 804702790 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
15055 : 746175324 : if (TREE_CODE (field) == FIELD_DECL
15056 : 398652455 : && !DECL_PADDING_P (field)
15057 : 1144826520 : && !is_empty_type (TREE_TYPE (field)))
15058 : : return false;
15059 : : return true;
15060 : : }
15061 : 1393498678 : else if (TREE_CODE (type) == ARRAY_TYPE)
15062 : 75335316 : return (integer_minus_onep (array_type_nelts_minus_one (type))
15063 : 75291780 : || TYPE_DOMAIN (type) == NULL_TREE
15064 : 144560261 : || is_empty_type (TREE_TYPE (type)));
15065 : : return false;
15066 : : }
15067 : :
15068 : : /* Implement TARGET_EMPTY_RECORD_P. Return true if TYPE is an empty type
15069 : : that shouldn't be passed via stack. */
15070 : :
15071 : : bool
15072 : 1307735469 : default_is_empty_record (const_tree type)
15073 : : {
15074 : 1307735469 : if (!abi_version_at_least (12))
15075 : : return false;
15076 : :
15077 : 1306690232 : if (type == error_mark_node)
15078 : : return false;
15079 : :
15080 : 1306690232 : if (TREE_ADDRESSABLE (type))
15081 : : return false;
15082 : :
15083 : 1306690232 : return is_empty_type (TYPE_MAIN_VARIANT (type));
15084 : : }
15085 : :
15086 : : /* Determine whether TYPE is a structure with a flexible array member,
15087 : : or a union containing such a structure (possibly recursively). */
15088 : :
15089 : : bool
15090 : 73350 : flexible_array_type_p (const_tree type)
15091 : : {
15092 : 73350 : tree x, last;
15093 : 73350 : switch (TREE_CODE (type))
15094 : : {
15095 : 37365 : case RECORD_TYPE:
15096 : 37365 : last = NULL_TREE;
15097 : 171140 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15098 : 133775 : if (TREE_CODE (x) == FIELD_DECL)
15099 : 133775 : last = x;
15100 : 37365 : if (last == NULL_TREE)
15101 : : return false;
15102 : 37357 : if (TREE_CODE (TREE_TYPE (last)) == ARRAY_TYPE
15103 : 492 : && TYPE_SIZE (TREE_TYPE (last)) == NULL_TREE
15104 : 263 : && TYPE_DOMAIN (TREE_TYPE (last)) != NULL_TREE
15105 : 37620 : && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (last))) == NULL_TREE)
15106 : : return true;
15107 : : return false;
15108 : 617 : case UNION_TYPE:
15109 : 1784 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15110 : : {
15111 : 1209 : if (TREE_CODE (x) == FIELD_DECL
15112 : 1209 : && flexible_array_type_p (TREE_TYPE (x)))
15113 : : return true;
15114 : : }
15115 : : return false;
15116 : : default:
15117 : : return false;
15118 : : }
15119 : : }
15120 : :
15121 : : /* Like int_size_in_bytes, but handle empty records specially. */
15122 : :
15123 : : HOST_WIDE_INT
15124 : 375309 : arg_int_size_in_bytes (const_tree type)
15125 : : {
15126 : 375309 : return TYPE_EMPTY_P (type) ? 0 : int_size_in_bytes (type);
15127 : : }
15128 : :
15129 : : /* Like size_in_bytes, but handle empty records specially. */
15130 : :
15131 : : tree
15132 : 5663535 : arg_size_in_bytes (const_tree type)
15133 : : {
15134 : 5663535 : return TYPE_EMPTY_P (type) ? size_zero_node : size_in_bytes (type);
15135 : : }
15136 : :
15137 : : /* Return true if an expression with CODE has to have the same result type as
15138 : : its first operand. */
15139 : :
15140 : : bool
15141 : 0 : expr_type_first_operand_type_p (tree_code code)
15142 : : {
15143 : 0 : switch (code)
15144 : : {
15145 : : case NEGATE_EXPR:
15146 : : case ABS_EXPR:
15147 : : case BIT_NOT_EXPR:
15148 : : case PAREN_EXPR:
15149 : : case CONJ_EXPR:
15150 : :
15151 : : case PLUS_EXPR:
15152 : : case MINUS_EXPR:
15153 : : case MULT_EXPR:
15154 : : case TRUNC_DIV_EXPR:
15155 : : case CEIL_DIV_EXPR:
15156 : : case FLOOR_DIV_EXPR:
15157 : : case ROUND_DIV_EXPR:
15158 : : case TRUNC_MOD_EXPR:
15159 : : case CEIL_MOD_EXPR:
15160 : : case FLOOR_MOD_EXPR:
15161 : : case ROUND_MOD_EXPR:
15162 : : case RDIV_EXPR:
15163 : : case EXACT_DIV_EXPR:
15164 : : case MIN_EXPR:
15165 : : case MAX_EXPR:
15166 : : case BIT_IOR_EXPR:
15167 : : case BIT_XOR_EXPR:
15168 : : case BIT_AND_EXPR:
15169 : :
15170 : : case LSHIFT_EXPR:
15171 : : case RSHIFT_EXPR:
15172 : : case LROTATE_EXPR:
15173 : : case RROTATE_EXPR:
15174 : : return true;
15175 : :
15176 : 0 : default:
15177 : 0 : return false;
15178 : : }
15179 : : }
15180 : :
15181 : : /* Return a typenode for the "standard" C type with a given name. */
15182 : : tree
15183 : 900091 : get_typenode_from_name (const char *name)
15184 : : {
15185 : 900091 : if (name == NULL || *name == '\0')
15186 : : return NULL_TREE;
15187 : :
15188 : 900091 : if (strcmp (name, "char") == 0)
15189 : 0 : return char_type_node;
15190 : 900091 : if (strcmp (name, "unsigned char") == 0)
15191 : 92925 : return unsigned_char_type_node;
15192 : 807166 : if (strcmp (name, "signed char") == 0)
15193 : 92925 : return signed_char_type_node;
15194 : :
15195 : 714241 : if (strcmp (name, "short int") == 0)
15196 : 63466 : return short_integer_type_node;
15197 : 650775 : if (strcmp (name, "short unsigned int") == 0)
15198 : 61950 : return short_unsigned_type_node;
15199 : :
15200 : 588825 : if (strcmp (name, "int") == 0)
15201 : 64285 : return integer_type_node;
15202 : 524540 : if (strcmp (name, "unsigned int") == 0)
15203 : 62764 : return unsigned_type_node;
15204 : :
15205 : 461776 : if (strcmp (name, "long int") == 0)
15206 : 275112 : return long_integer_type_node;
15207 : 186664 : if (strcmp (name, "long unsigned int") == 0)
15208 : 183408 : return long_unsigned_type_node;
15209 : :
15210 : 3256 : if (strcmp (name, "long long int") == 0)
15211 : 1628 : return long_long_integer_type_node;
15212 : 1628 : if (strcmp (name, "long long unsigned int") == 0)
15213 : 1628 : return long_long_unsigned_type_node;
15214 : :
15215 : 0 : gcc_unreachable ();
15216 : : }
15217 : :
15218 : : /* List of pointer types used to declare builtins before we have seen their
15219 : : real declaration.
15220 : :
15221 : : Keep the size up to date in tree.h ! */
15222 : : const builtin_structptr_type builtin_structptr_types[6] =
15223 : : {
15224 : : { fileptr_type_node, ptr_type_node, "FILE" },
15225 : : { const_tm_ptr_type_node, const_ptr_type_node, "tm" },
15226 : : { fenv_t_ptr_type_node, ptr_type_node, "fenv_t" },
15227 : : { const_fenv_t_ptr_type_node, const_ptr_type_node, "fenv_t" },
15228 : : { fexcept_t_ptr_type_node, ptr_type_node, "fexcept_t" },
15229 : : { const_fexcept_t_ptr_type_node, const_ptr_type_node, "fexcept_t" }
15230 : : };
15231 : :
15232 : : /* Return the maximum object size. */
15233 : :
15234 : : tree
15235 : 7244387 : max_object_size (void)
15236 : : {
15237 : : /* To do: Make this a configurable parameter. */
15238 : 7244387 : return TYPE_MAX_VALUE (ptrdiff_type_node);
15239 : : }
15240 : :
15241 : : /* A wrapper around TARGET_VERIFY_TYPE_CONTEXT that makes the silent_p
15242 : : parameter default to false and that weeds out error_mark_node. */
15243 : :
15244 : : bool
15245 : 122829855 : verify_type_context (location_t loc, type_context_kind context,
15246 : : const_tree type, bool silent_p)
15247 : : {
15248 : 122829855 : if (type == error_mark_node)
15249 : : return true;
15250 : :
15251 : 122829761 : gcc_assert (TYPE_P (type));
15252 : 122829761 : return (!targetm.verify_type_context
15253 : 122829761 : || targetm.verify_type_context (loc, context, type, silent_p));
15254 : : }
15255 : :
15256 : : /* Return true if NEW_ASM and DELETE_ASM name a valid pair of new and
15257 : : delete operators. Return false if they may or may not name such
15258 : : a pair and, when nonnull, set *PCERTAIN to true if they certainly
15259 : : do not. */
15260 : :
15261 : : bool
15262 : 62808 : valid_new_delete_pair_p (tree new_asm, tree delete_asm,
15263 : : bool *pcertain /* = NULL */)
15264 : : {
15265 : 62808 : bool certain;
15266 : 62808 : if (!pcertain)
15267 : 51230 : pcertain = &certain;
15268 : :
15269 : 62808 : const char *new_name = IDENTIFIER_POINTER (new_asm);
15270 : 62808 : const char *delete_name = IDENTIFIER_POINTER (delete_asm);
15271 : 62808 : unsigned int new_len = IDENTIFIER_LENGTH (new_asm);
15272 : 62808 : unsigned int delete_len = IDENTIFIER_LENGTH (delete_asm);
15273 : :
15274 : : /* The following failures are due to invalid names so they're not
15275 : : considered certain mismatches. */
15276 : 62808 : *pcertain = false;
15277 : :
15278 : 62808 : if (new_len < 5 || delete_len < 6)
15279 : : return false;
15280 : 62808 : if (new_name[0] == '_')
15281 : 62736 : ++new_name, --new_len;
15282 : 62808 : if (new_name[0] == '_')
15283 : 0 : ++new_name, --new_len;
15284 : 62808 : if (delete_name[0] == '_')
15285 : 62808 : ++delete_name, --delete_len;
15286 : 62808 : if (delete_name[0] == '_')
15287 : 0 : ++delete_name, --delete_len;
15288 : 62808 : if (new_len < 4 || delete_len < 5)
15289 : : return false;
15290 : :
15291 : : /* The following failures are due to names of user-defined operators
15292 : : so they're also not considered certain mismatches. */
15293 : :
15294 : : /* *_len is now just the length after initial underscores. */
15295 : 62808 : if (new_name[0] != 'Z' || new_name[1] != 'n')
15296 : : return false;
15297 : 62141 : if (delete_name[0] != 'Z' || delete_name[1] != 'd')
15298 : : return false;
15299 : :
15300 : : /* The following failures are certain mismatches. */
15301 : 62069 : *pcertain = true;
15302 : :
15303 : : /* _Znw must match _Zdl, _Zna must match _Zda. */
15304 : 62069 : if ((new_name[2] != 'w' || delete_name[2] != 'l')
15305 : 7335 : && (new_name[2] != 'a' || delete_name[2] != 'a'))
15306 : : return false;
15307 : : /* 'j', 'm' and 'y' correspond to size_t. */
15308 : 61973 : if (new_name[3] != 'j' && new_name[3] != 'm' && new_name[3] != 'y')
15309 : : return false;
15310 : 61973 : if (delete_name[3] != 'P' || delete_name[4] != 'v')
15311 : : return false;
15312 : 61973 : if (new_len == 4
15313 : 466 : || (new_len == 18 && !memcmp (new_name + 4, "RKSt9nothrow_t", 14)))
15314 : : {
15315 : : /* _ZnXY or _ZnXYRKSt9nothrow_t matches
15316 : : _ZdXPv, _ZdXPvY and _ZdXPvRKSt9nothrow_t. */
15317 : 61673 : if (delete_len == 5)
15318 : : return true;
15319 : 52868 : if (delete_len == 6 && delete_name[5] == new_name[3])
15320 : : return true;
15321 : 39 : if (delete_len == 19 && !memcmp (delete_name + 5, "RKSt9nothrow_t", 14))
15322 : : return true;
15323 : : }
15324 : 300 : else if ((new_len == 19 && !memcmp (new_name + 4, "St11align_val_t", 15))
15325 : 42 : || (new_len == 33
15326 : 10 : && !memcmp (new_name + 4, "St11align_val_tRKSt9nothrow_t", 29)))
15327 : : {
15328 : : /* _ZnXYSt11align_val_t or _ZnXYSt11align_val_tRKSt9nothrow_t matches
15329 : : _ZdXPvSt11align_val_t or _ZdXPvYSt11align_val_t or
15330 : : _ZdXPvSt11align_val_tRKSt9nothrow_t. */
15331 : 268 : if (delete_len == 20 && !memcmp (delete_name + 5, "St11align_val_t", 15))
15332 : : return true;
15333 : 61 : if (delete_len == 21
15334 : 46 : && delete_name[5] == new_name[3]
15335 : 46 : && !memcmp (delete_name + 6, "St11align_val_t", 15))
15336 : : return true;
15337 : 15 : if (delete_len == 34
15338 : 9 : && !memcmp (delete_name + 5, "St11align_val_tRKSt9nothrow_t", 29))
15339 : : return true;
15340 : : }
15341 : :
15342 : : /* The negative result is conservative. */
15343 : 38 : *pcertain = false;
15344 : 38 : return false;
15345 : : }
15346 : :
15347 : : /* Return the zero-based number corresponding to the argument being
15348 : : deallocated if FNDECL is a deallocation function or an out-of-bounds
15349 : : value if it isn't. */
15350 : :
15351 : : unsigned
15352 : 28424313 : fndecl_dealloc_argno (tree fndecl)
15353 : : {
15354 : : /* A call to operator delete isn't recognized as one to a built-in. */
15355 : 28424313 : if (DECL_IS_OPERATOR_DELETE_P (fndecl))
15356 : : {
15357 : 472677 : if (DECL_IS_REPLACEABLE_OPERATOR (fndecl))
15358 : : return 0;
15359 : :
15360 : : /* Avoid placement delete that's not been inlined. */
15361 : 25276 : tree fname = DECL_ASSEMBLER_NAME (fndecl);
15362 : 25276 : if (id_equal (fname, "_ZdlPvS_") // ordinary form
15363 : 25276 : || id_equal (fname, "_ZdaPvS_")) // array form
15364 : : return UINT_MAX;
15365 : : return 0;
15366 : : }
15367 : :
15368 : : /* TODO: Handle user-defined functions with attribute malloc? Handle
15369 : : known non-built-ins like fopen? */
15370 : 27951636 : if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
15371 : : {
15372 : 7256661 : switch (DECL_FUNCTION_CODE (fndecl))
15373 : : {
15374 : : case BUILT_IN_FREE:
15375 : : case BUILT_IN_REALLOC:
15376 : : case BUILT_IN_GOMP_FREE:
15377 : : case BUILT_IN_GOMP_REALLOC:
15378 : : return 0;
15379 : : default:
15380 : : break;
15381 : : }
15382 : : return UINT_MAX;
15383 : : }
15384 : :
15385 : 20694975 : tree attrs = DECL_ATTRIBUTES (fndecl);
15386 : 20694975 : if (!attrs)
15387 : : return UINT_MAX;
15388 : :
15389 : 0 : for (tree atfree = attrs;
15390 : 4716701 : (atfree = lookup_attribute ("*dealloc", atfree));
15391 : 0 : atfree = TREE_CHAIN (atfree))
15392 : : {
15393 : 6431 : tree alloc = TREE_VALUE (atfree);
15394 : 6431 : if (!alloc)
15395 : 0 : continue;
15396 : :
15397 : 6431 : tree pos = TREE_CHAIN (alloc);
15398 : 6431 : if (!pos)
15399 : : return 0;
15400 : :
15401 : 3711 : pos = TREE_VALUE (pos);
15402 : 3711 : return TREE_INT_CST_LOW (pos) - 1;
15403 : : }
15404 : :
15405 : : return UINT_MAX;
15406 : : }
15407 : :
15408 : : /* If EXPR refers to a character array or pointer declared attribute
15409 : : nonstring, return a decl for that array or pointer and set *REF
15410 : : to the referenced enclosing object or pointer. Otherwise return
15411 : : null. */
15412 : :
15413 : : tree
15414 : 1397911 : get_attr_nonstring_decl (tree expr, tree *ref)
15415 : : {
15416 : 1403568 : tree decl = expr;
15417 : 1403568 : tree var = NULL_TREE;
15418 : 1403568 : if (TREE_CODE (decl) == SSA_NAME)
15419 : : {
15420 : 835605 : gimple *def = SSA_NAME_DEF_STMT (decl);
15421 : :
15422 : 835605 : if (is_gimple_assign (def))
15423 : : {
15424 : 45204 : tree_code code = gimple_assign_rhs_code (def);
15425 : 45204 : if (code == ADDR_EXPR
15426 : 45204 : || code == COMPONENT_REF
15427 : 31258 : || code == VAR_DECL)
15428 : 18636 : decl = gimple_assign_rhs1 (def);
15429 : : }
15430 : : else
15431 : 790401 : var = SSA_NAME_VAR (decl);
15432 : : }
15433 : :
15434 : 1403568 : if (TREE_CODE (decl) == ADDR_EXPR)
15435 : 25847 : decl = TREE_OPERAND (decl, 0);
15436 : :
15437 : : /* To simplify calling code, store the referenced DECL regardless of
15438 : : the attribute determined below, but avoid storing the SSA_NAME_VAR
15439 : : obtained above (it's not useful for dataflow purposes). */
15440 : 1403568 : if (ref)
15441 : 5455 : *ref = decl;
15442 : :
15443 : : /* Use the SSA_NAME_VAR that was determined above to see if it's
15444 : : declared nonstring. Otherwise drill down into the referenced
15445 : : DECL. */
15446 : 1403568 : if (var)
15447 : : decl = var;
15448 : : else
15449 : : {
15450 : 638148 : while (TREE_CODE (decl) == ARRAY_REF)
15451 : 18500 : decl = TREE_OPERAND (decl, 0);
15452 : 619648 : if (TREE_CODE (decl) == COMPONENT_REF)
15453 : 15741 : decl = TREE_OPERAND (decl, 1);
15454 : 603907 : else if (TREE_CODE (decl) == MEM_REF)
15455 : 5657 : return get_attr_nonstring_decl (TREE_OPERAND (decl, 0), ref);
15456 : : }
15457 : :
15458 : 1397911 : if (DECL_P (decl) && lookup_attribute ("nonstring", DECL_ATTRIBUTES (decl)))
15459 : : return decl;
15460 : :
15461 : : return NULL_TREE;
15462 : : }
15463 : :
15464 : : /* Returns an auto_vec of string_slices containing the version strings from
15465 : : ARGLIST. DEFAULT_COUNT is incremented for each default version found.
15466 : : If FILTER is true then any invalid versions strings are not included. */
15467 : :
15468 : : auto_vec<string_slice>
15469 : 202 : get_clone_attr_versions (const tree arglist,
15470 : : int *default_count,
15471 : : bool filter)
15472 : : {
15473 : 202 : gcc_assert (TREE_CODE (arglist) == TREE_LIST);
15474 : 202 : auto_vec<string_slice> versions;
15475 : :
15476 : 202 : static const char separator_str[] = {TARGET_CLONES_ATTR_SEPARATOR, 0};
15477 : 202 : string_slice separators = string_slice (separator_str);
15478 : :
15479 : 740 : for (tree arg = arglist; arg; arg = TREE_CHAIN (arg))
15480 : : {
15481 : 538 : string_slice str = string_slice (TREE_STRING_POINTER (TREE_VALUE (arg)));
15482 : 1642 : while (str.is_valid ())
15483 : : {
15484 : 566 : string_slice attr = string_slice::tokenize (&str, separators);
15485 : 566 : attr = attr.strip ();
15486 : :
15487 : 566 : if (filter && !targetm.check_target_clone_version (attr, NULL))
15488 : 0 : continue;
15489 : :
15490 : 566 : if (attr == "default" && default_count)
15491 : 200 : (*default_count)++;
15492 : 566 : versions.safe_push (attr);
15493 : : }
15494 : : }
15495 : 202 : return versions;
15496 : : }
15497 : :
15498 : : /* Returns an auto_vec of string_slices containing the version strings from
15499 : : the target_clone attribute from DECL. DEFAULT_COUNT is incremented for each
15500 : : default version found. If FILTER is true then any invalid versions strings
15501 : : are not included. */
15502 : : auto_vec<string_slice>
15503 : 94 : get_clone_versions (const tree decl, int *default_count, bool filter)
15504 : : {
15505 : 94 : tree attr = lookup_attribute ("target_clones", DECL_ATTRIBUTES (decl));
15506 : 94 : if (!attr)
15507 : 0 : return auto_vec<string_slice> ();
15508 : 94 : tree arglist = TREE_VALUE (attr);
15509 : 94 : return get_clone_attr_versions (arglist, default_count, filter);
15510 : : }
15511 : :
15512 : : /* If DECL has a target_version attribute, returns a string_slice containing the
15513 : : attribute value. Otherwise, returns string_slice::invalid.
15514 : : Only works for target_version due to target attributes allowing multiple
15515 : : string arguments to specify one target. */
15516 : : string_slice
15517 : 0 : get_target_version (const tree decl)
15518 : : {
15519 : 0 : gcc_assert (!TARGET_HAS_FMV_TARGET_ATTRIBUTE);
15520 : :
15521 : : tree attr = lookup_attribute ("target_version", DECL_ATTRIBUTES (decl));
15522 : :
15523 : : if (!attr)
15524 : : return string_slice::invalid ();
15525 : :
15526 : : return string_slice (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))))
15527 : : .strip ();
15528 : : }
15529 : :
15530 : : /* Returns true if FN1 and FN2 define disjoint function versions in an FMV
15531 : : function set. That is, the two declarations are completely non-overlapping.
15532 : : For target_version semantics, that means if one is a target clone and one is
15533 : : a target version, the target_version must not be defined by the target_clone,
15534 : : and for two target_clones, they must not define any of the same version.
15535 : :
15536 : : FN1 and FN2 should be function decls. */
15537 : :
15538 : : bool
15539 : 30073966 : disjoint_version_decls (tree fn1, tree fn2)
15540 : : {
15541 : 30073966 : if (TREE_CODE (fn1) != FUNCTION_DECL
15542 : 30072922 : || TREE_CODE (fn2) != FUNCTION_DECL)
15543 : : return false;
15544 : :
15545 : 27897863 : if (TARGET_HAS_FMV_TARGET_ATTRIBUTE)
15546 : : {
15547 : 27897863 : tree attr1 = lookup_attribute ("target", DECL_ATTRIBUTES (fn1));
15548 : 27897863 : tree attr2 = lookup_attribute ("target", DECL_ATTRIBUTES (fn2));
15549 : :
15550 : : /* At least one function decl should have the target attribute
15551 : : specified. */
15552 : 27897863 : if (attr1 == NULL_TREE && attr2 == NULL_TREE)
15553 : : return false;
15554 : :
15555 : : /* Diagnose missing target attribute if one of the decls is already
15556 : : multi-versioned. */
15557 : 18732 : if (attr1 == NULL_TREE || attr2 == NULL_TREE)
15558 : : {
15559 : 360 : if (DECL_FUNCTION_VERSIONED (fn1) || DECL_FUNCTION_VERSIONED (fn2))
15560 : : {
15561 : 114 : if (attr2 != NULL_TREE)
15562 : : {
15563 : 114 : std::swap (fn1, fn2);
15564 : 114 : attr1 = attr2;
15565 : : }
15566 : 114 : auto_diagnostic_group d;
15567 : 114 : error_at (DECL_SOURCE_LOCATION (fn2),
15568 : : "missing %<target%> attribute for multi-versioned %qD",
15569 : : fn2);
15570 : 114 : inform (DECL_SOURCE_LOCATION (fn1),
15571 : : "previous declaration of %qD", fn1);
15572 : : /* Prevent diagnosing of the same error multiple times. */
15573 : 114 : DECL_ATTRIBUTES (fn2)
15574 : 228 : = tree_cons (get_identifier ("target"),
15575 : 114 : copy_node (TREE_VALUE (attr1)),
15576 : 114 : DECL_ATTRIBUTES (fn2));
15577 : 114 : }
15578 : 360 : return false;
15579 : : }
15580 : :
15581 : 18372 : char *target1 = sorted_attr_string (TREE_VALUE (attr1));
15582 : 18372 : char *target2 = sorted_attr_string (TREE_VALUE (attr2));
15583 : :
15584 : : /* The sorted target strings must be different for fn1 and fn2
15585 : : to be versions. */
15586 : 18372 : bool result = strcmp (target1, target2) != 0;
15587 : :
15588 : 18372 : XDELETEVEC (target1);
15589 : 18372 : XDELETEVEC (target2);
15590 : :
15591 : 18372 : return result;
15592 : : }
15593 : : else
15594 : : {
15595 : : /* As this is symmetric, can remove the case where fn2 is target clone
15596 : : and fn1 is target version by swapping here. */
15597 : : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn2)))
15598 : : std::swap (fn1, fn2);
15599 : :
15600 : : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn1)))
15601 : : {
15602 : : auto_vec<string_slice> fn1_versions = get_clone_versions (fn1);
15603 : : /* fn1 is target_clone. */
15604 : : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn2)))
15605 : : {
15606 : : /* Both are target_clone. */
15607 : : auto_vec<string_slice> fn2_versions = get_clone_versions (fn2);
15608 : : for (string_slice v1 : fn1_versions)
15609 : : {
15610 : : for (string_slice v2 : fn2_versions)
15611 : : if (targetm.target_option.same_function_versions (v1, v2))
15612 : : return false;
15613 : : }
15614 : : return true;
15615 : : }
15616 : : else
15617 : : {
15618 : : string_slice v2 = get_target_version (fn2);
15619 : :
15620 : : /* target and target_clones is always conflicting for target
15621 : : semantics. */
15622 : : if (TARGET_HAS_FMV_TARGET_ATTRIBUTE)
15623 : : return false;
15624 : :
15625 : : /* Only fn1 is target clone. */
15626 : : if (!v2.is_valid ())
15627 : : v2 = "default";
15628 : : for (string_slice v1 : fn1_versions)
15629 : : if (targetm.target_option.same_function_versions (v1, v2))
15630 : : return false;
15631 : : return true;
15632 : : }
15633 : : }
15634 : : else
15635 : : {
15636 : : /* Both are target_version. */
15637 : : string_slice v1 = get_target_version (fn1);
15638 : : string_slice v2 = get_target_version (fn2);
15639 : :
15640 : : if (!v1.is_valid () && !v2.is_valid ())
15641 : : return false;
15642 : :
15643 : : if (!v1.is_valid ())
15644 : : v1 = "default";
15645 : : if (!v2.is_valid ())
15646 : : v2 = "default";
15647 : :
15648 : : if (targetm.target_option.same_function_versions (v1, v2))
15649 : : return false;
15650 : :
15651 : : return true;
15652 : : }
15653 : : }
15654 : : }
15655 : :
15656 : : /* Check if the target_version/target_clones attributes are mergeable
15657 : : for two decls, and if so returns false.
15658 : : If they aren't mergeable, diagnose this and return true.
15659 : : Only works for target_version semantics. */
15660 : : bool
15661 : 0 : diagnose_versioned_decls (tree old_decl, tree new_decl)
15662 : : {
15663 : 0 : gcc_assert (!TARGET_HAS_FMV_TARGET_ATTRIBUTE);
15664 : :
15665 : : string_slice old_target_attr = get_target_version (old_decl);
15666 : : string_slice new_target_attr = get_target_version (new_decl);
15667 : :
15668 : : tree old_target_clones_attr = lookup_attribute ("target_clones",
15669 : : DECL_ATTRIBUTES (old_decl));
15670 : : tree new_target_clones_attr = lookup_attribute ("target_clones",
15671 : : DECL_ATTRIBUTES (new_decl));
15672 : :
15673 : : /* If none of these are annotated, then it is mergeable. */
15674 : : if (!old_target_attr.is_valid ()
15675 : : && !old_target_attr.is_valid ()
15676 : : && !old_target_clones_attr
15677 : : && !new_target_clones_attr)
15678 : : return false;
15679 : :
15680 : : /* If fn1 is unnanotated and fn2 contains default, then is mergeable. */
15681 : : if (!old_target_attr.is_valid ()
15682 : : && !old_target_clones_attr
15683 : : && is_function_default_version (new_decl))
15684 : : return false;
15685 : :
15686 : : /* If fn2 is unnanotated and fn1 contains default, then is mergeable. */
15687 : : if (!new_target_attr.is_valid ()
15688 : : && !new_target_clones_attr
15689 : : && is_function_default_version (old_decl))
15690 : : return false;
15691 : :
15692 : : /* In the case where both are annotated with target_clones, only mergeable if
15693 : : the two sets of target_clones imply the same set of versions. */
15694 : : if (old_target_clones_attr && new_target_clones_attr)
15695 : : {
15696 : : auto_vec<string_slice> fn1_versions = get_clone_versions (old_decl);
15697 : : auto_vec<string_slice> fn2_versions = get_clone_versions (new_decl);
15698 : :
15699 : : bool mergeable = true;
15700 : :
15701 : : if (fn1_versions.length () != fn2_versions.length ())
15702 : : mergeable = false;
15703 : :
15704 : : /* Check both inclusion directions. */
15705 : : for (auto fn1v : fn1_versions)
15706 : : {
15707 : : bool matched = false;
15708 : : for (auto fn2v : fn2_versions)
15709 : : if (targetm.target_option.same_function_versions (fn1v, fn2v))
15710 : : matched = true;
15711 : : if (!matched)
15712 : : mergeable = false;
15713 : : }
15714 : :
15715 : : for (auto fn2v : fn2_versions)
15716 : : {
15717 : : bool matched = false;
15718 : : for (auto fn1v : fn1_versions)
15719 : : if (targetm.target_option.same_function_versions (fn1v, fn2v))
15720 : : matched = true;
15721 : : if (!matched)
15722 : : mergeable = false;
15723 : : }
15724 : :
15725 : : if (!mergeable)
15726 : : {
15727 : : error_at (DECL_SOURCE_LOCATION (new_decl),
15728 : : "%qD conflicts with overlapping %<target_clone%> "
15729 : : "declaration",
15730 : : new_decl);
15731 : : inform (DECL_SOURCE_LOCATION (old_decl),
15732 : : "previous declaration of %qD", old_decl);
15733 : : return true;
15734 : : }
15735 : :
15736 : : return false;
15737 : : }
15738 : :
15739 : : /* If olddecl is target clones and newdecl is a target_version.
15740 : : As they are not distinct this implies newdecl redefines a version of
15741 : : olddecl. Not mergeable. */
15742 : : if (new_target_clones_attr)
15743 : : {
15744 : : gcc_assert (old_target_attr.is_valid ());
15745 : :
15746 : : error_at (DECL_SOURCE_LOCATION (new_decl),
15747 : : "%qD conflicts for version %qB",
15748 : : new_decl, &old_target_attr);
15749 : : inform (DECL_SOURCE_LOCATION (old_decl),
15750 : : "previous declaration of %qD",
15751 : : old_decl);
15752 : : return true;
15753 : : }
15754 : :
15755 : : if (old_target_clones_attr)
15756 : : {
15757 : : gcc_assert (new_target_attr.is_valid ());
15758 : :
15759 : : error_at (DECL_SOURCE_LOCATION (new_decl),
15760 : : "%qD conflicts with a previous declaration for version %qB",
15761 : : new_decl, &new_target_attr);
15762 : : inform (DECL_SOURCE_LOCATION (old_decl),
15763 : : "previous declaration of %qD",
15764 : : old_decl);
15765 : : return true;
15766 : : }
15767 : :
15768 : : /* The only remaining case is two target_version annotated decls. Must
15769 : : be mergeable as otherwise are distinct. */
15770 : : return false;
15771 : : }
15772 : :
15773 : : void
15774 : 261000 : tree_cc_finalize (void)
15775 : : {
15776 : 261000 : clear_nonstandard_integer_type_cache ();
15777 : 261000 : vec_free (bitint_type_cache);
15778 : 261000 : }
15779 : :
15780 : : void
15781 : 148 : gt_ggc_mx (tree_raw_data *x)
15782 : : {
15783 : 148 : gt_ggc_m_9tree_node (x->typed.type);
15784 : 148 : gt_ggc_m_9tree_node (x->owner);
15785 : 148 : }
15786 : :
15787 : : void
15788 : 12 : gt_pch_nx (tree_raw_data *x)
15789 : : {
15790 : 12 : gt_pch_n_9tree_node (x->typed.type);
15791 : 12 : gt_pch_n_9tree_node (x->owner);
15792 : 12 : }
15793 : :
15794 : : /* For PCH we guarantee that RAW_DATA_CST's RAW_DATA_OWNER is a STRING_CST and
15795 : : RAW_DATA_POINTER points into it. We don't want to save/restore
15796 : : RAW_DATA_POINTER on its own but want to restore it pointing at the same
15797 : : offset of the STRING_CST as before. */
15798 : :
15799 : : void
15800 : 12 : gt_pch_nx (tree_raw_data *x, gt_pointer_operator op, void *cookie)
15801 : : {
15802 : 12 : op (&x->typed.type, NULL, cookie);
15803 : 12 : gcc_checking_assert (x->owner
15804 : : && TREE_CODE (x->owner) == STRING_CST
15805 : : && x->str >= TREE_STRING_POINTER (x->owner)
15806 : : && (x->str + x->length
15807 : : <= (TREE_STRING_POINTER (x->owner)
15808 : : + TREE_STRING_LENGTH (x->owner))));
15809 : 12 : ptrdiff_t off = x->str - (const char *) (x->owner);
15810 : 12 : tree owner = x->owner;
15811 : 12 : op (&x->owner, NULL, cookie);
15812 : 12 : x->owner = owner;
15813 : : /* The above op call relocates x->owner and remembers the address
15814 : : for relocation e.g. if the compiler is position independent.
15815 : : We then restore x->owner back to its previous value and call
15816 : : op again, for x->owner itself this just repeats (uselessly) what
15817 : : the first call did, but as the second argument is now non-NULL
15818 : : and different, it also arranges for &x->str to be noted for the
15819 : : PIE relocation. */
15820 : 12 : op (&x->owner, &x->str, cookie);
15821 : 12 : x->str = (const char *) (x->owner) + off;
15822 : 12 : }
15823 : :
15824 : : #if CHECKING_P
15825 : :
15826 : : namespace selftest {
15827 : :
15828 : : /* Selftests for tree. */
15829 : :
15830 : : /* Verify that integer constants are sane. */
15831 : :
15832 : : static void
15833 : 4 : test_integer_constants ()
15834 : : {
15835 : 4 : ASSERT_TRUE (integer_type_node != NULL);
15836 : 4 : ASSERT_TRUE (build_int_cst (integer_type_node, 0) != NULL);
15837 : :
15838 : 4 : tree type = integer_type_node;
15839 : :
15840 : 4 : tree zero = build_zero_cst (type);
15841 : 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (zero));
15842 : 4 : ASSERT_EQ (type, TREE_TYPE (zero));
15843 : :
15844 : 4 : tree one = build_int_cst (type, 1);
15845 : 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (one));
15846 : 4 : ASSERT_EQ (type, TREE_TYPE (zero));
15847 : 4 : }
15848 : :
15849 : : /* Verify identifiers. */
15850 : :
15851 : : static void
15852 : 4 : test_identifiers ()
15853 : : {
15854 : 4 : tree identifier = get_identifier ("foo");
15855 : 4 : ASSERT_EQ (3, IDENTIFIER_LENGTH (identifier));
15856 : 4 : ASSERT_STREQ ("foo", IDENTIFIER_POINTER (identifier));
15857 : 4 : }
15858 : :
15859 : : /* Verify LABEL_DECL. */
15860 : :
15861 : : static void
15862 : 4 : test_labels ()
15863 : : {
15864 : 4 : tree identifier = get_identifier ("err");
15865 : 4 : tree label_decl = build_decl (UNKNOWN_LOCATION, LABEL_DECL,
15866 : : identifier, void_type_node);
15867 : 4 : ASSERT_EQ (-1, LABEL_DECL_UID (label_decl));
15868 : 4 : ASSERT_FALSE (FORCED_LABEL (label_decl));
15869 : 4 : }
15870 : :
15871 : : /* Return a new VECTOR_CST node whose type is TYPE and whose values
15872 : : are given by VALS. */
15873 : :
15874 : : static tree
15875 : 40 : build_vector (tree type, const vec<tree> &vals MEM_STAT_DECL)
15876 : : {
15877 : 80 : gcc_assert (known_eq (vals.length (), TYPE_VECTOR_SUBPARTS (type)));
15878 : 40 : tree_vector_builder builder (type, vals.length (), 1);
15879 : 40 : builder.splice (vals);
15880 : 40 : return builder.build ();
15881 : 40 : }
15882 : :
15883 : : /* Check that VECTOR_CST ACTUAL contains the elements in EXPECTED. */
15884 : :
15885 : : static void
15886 : 40 : check_vector_cst (const vec<tree> &expected, tree actual)
15887 : : {
15888 : 80 : ASSERT_KNOWN_EQ (expected.length (),
15889 : : TYPE_VECTOR_SUBPARTS (TREE_TYPE (actual)));
15890 : 360 : for (unsigned int i = 0; i < expected.length (); ++i)
15891 : 320 : ASSERT_EQ (wi::to_wide (expected[i]),
15892 : : wi::to_wide (vector_cst_elt (actual, i)));
15893 : 40 : }
15894 : :
15895 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS duplicated elements,
15896 : : and that its elements match EXPECTED. */
15897 : :
15898 : : static void
15899 : 8 : check_vector_cst_duplicate (const vec<tree> &expected, tree actual,
15900 : : unsigned int npatterns)
15901 : : {
15902 : 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15903 : 8 : ASSERT_EQ (1, VECTOR_CST_NELTS_PER_PATTERN (actual));
15904 : 8 : ASSERT_EQ (npatterns, vector_cst_encoded_nelts (actual));
15905 : 8 : ASSERT_TRUE (VECTOR_CST_DUPLICATE_P (actual));
15906 : 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
15907 : 8 : check_vector_cst (expected, actual);
15908 : 8 : }
15909 : :
15910 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS foreground elements
15911 : : and NPATTERNS background elements, and that its elements match
15912 : : EXPECTED. */
15913 : :
15914 : : static void
15915 : 8 : check_vector_cst_fill (const vec<tree> &expected, tree actual,
15916 : : unsigned int npatterns)
15917 : : {
15918 : 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15919 : 8 : ASSERT_EQ (2, VECTOR_CST_NELTS_PER_PATTERN (actual));
15920 : 8 : ASSERT_EQ (2 * npatterns, vector_cst_encoded_nelts (actual));
15921 : 8 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
15922 : 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
15923 : 8 : check_vector_cst (expected, actual);
15924 : 8 : }
15925 : :
15926 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS stepped patterns,
15927 : : and that its elements match EXPECTED. */
15928 : :
15929 : : static void
15930 : 24 : check_vector_cst_stepped (const vec<tree> &expected, tree actual,
15931 : : unsigned int npatterns)
15932 : : {
15933 : 24 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15934 : 24 : ASSERT_EQ (3, VECTOR_CST_NELTS_PER_PATTERN (actual));
15935 : 24 : ASSERT_EQ (3 * npatterns, vector_cst_encoded_nelts (actual));
15936 : 24 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
15937 : 24 : ASSERT_TRUE (VECTOR_CST_STEPPED_P (actual));
15938 : 24 : check_vector_cst (expected, actual);
15939 : 24 : }
15940 : :
15941 : : /* Test the creation of VECTOR_CSTs. */
15942 : :
15943 : : static void
15944 : 4 : test_vector_cst_patterns (ALONE_CXX_MEM_STAT_INFO)
15945 : : {
15946 : 4 : auto_vec<tree, 8> elements (8);
15947 : 4 : elements.quick_grow (8);
15948 : 4 : tree element_type = build_nonstandard_integer_type (16, true);
15949 : 4 : tree vector_type = build_vector_type (element_type, 8);
15950 : :
15951 : : /* Test a simple linear series with a base of 0 and a step of 1:
15952 : : { 0, 1, 2, 3, 4, 5, 6, 7 }. */
15953 : 36 : for (unsigned int i = 0; i < 8; ++i)
15954 : 32 : elements[i] = build_int_cst (element_type, i);
15955 : 4 : tree vector = build_vector (vector_type, elements PASS_MEM_STAT);
15956 : 4 : check_vector_cst_stepped (elements, vector, 1);
15957 : :
15958 : : /* Try the same with the first element replaced by 100:
15959 : : { 100, 1, 2, 3, 4, 5, 6, 7 }. */
15960 : 4 : elements[0] = build_int_cst (element_type, 100);
15961 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15962 : 4 : check_vector_cst_stepped (elements, vector, 1);
15963 : :
15964 : : /* Try a series that wraps around.
15965 : : { 100, 65531, 65532, 65533, 65534, 65535, 0, 1 }. */
15966 : 32 : for (unsigned int i = 1; i < 8; ++i)
15967 : 28 : elements[i] = build_int_cst (element_type, (65530 + i) & 0xffff);
15968 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15969 : 4 : check_vector_cst_stepped (elements, vector, 1);
15970 : :
15971 : : /* Try a downward series:
15972 : : { 100, 79, 78, 77, 76, 75, 75, 73 }. */
15973 : 32 : for (unsigned int i = 1; i < 8; ++i)
15974 : 28 : elements[i] = build_int_cst (element_type, 80 - i);
15975 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15976 : 4 : check_vector_cst_stepped (elements, vector, 1);
15977 : :
15978 : : /* Try two interleaved series with different bases and steps:
15979 : : { 100, 53, 66, 206, 62, 212, 58, 218 }. */
15980 : 4 : elements[1] = build_int_cst (element_type, 53);
15981 : 16 : for (unsigned int i = 2; i < 8; i += 2)
15982 : : {
15983 : 12 : elements[i] = build_int_cst (element_type, 70 - i * 2);
15984 : 12 : elements[i + 1] = build_int_cst (element_type, 200 + i * 3);
15985 : : }
15986 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15987 : 4 : check_vector_cst_stepped (elements, vector, 2);
15988 : :
15989 : : /* Try a duplicated value:
15990 : : { 100, 100, 100, 100, 100, 100, 100, 100 }. */
15991 : 32 : for (unsigned int i = 1; i < 8; ++i)
15992 : 28 : elements[i] = elements[0];
15993 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15994 : 4 : check_vector_cst_duplicate (elements, vector, 1);
15995 : :
15996 : : /* Try an interleaved duplicated value:
15997 : : { 100, 55, 100, 55, 100, 55, 100, 55 }. */
15998 : 4 : elements[1] = build_int_cst (element_type, 55);
15999 : 28 : for (unsigned int i = 2; i < 8; ++i)
16000 : 24 : elements[i] = elements[i - 2];
16001 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16002 : 4 : check_vector_cst_duplicate (elements, vector, 2);
16003 : :
16004 : : /* Try a duplicated value with 2 exceptions
16005 : : { 41, 97, 100, 55, 100, 55, 100, 55 }. */
16006 : 4 : elements[0] = build_int_cst (element_type, 41);
16007 : 4 : elements[1] = build_int_cst (element_type, 97);
16008 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16009 : 4 : check_vector_cst_fill (elements, vector, 2);
16010 : :
16011 : : /* Try with and without a step
16012 : : { 41, 97, 100, 21, 100, 35, 100, 49 }. */
16013 : 16 : for (unsigned int i = 3; i < 8; i += 2)
16014 : 12 : elements[i] = build_int_cst (element_type, i * 7);
16015 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16016 : 4 : check_vector_cst_stepped (elements, vector, 2);
16017 : :
16018 : : /* Try a fully-general constant:
16019 : : { 41, 97, 100, 21, 100, 9990, 100, 49 }. */
16020 : 4 : elements[5] = build_int_cst (element_type, 9990);
16021 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16022 : 4 : check_vector_cst_fill (elements, vector, 4);
16023 : 4 : }
16024 : :
16025 : : /* Verify that STRIP_NOPS (NODE) is EXPECTED.
16026 : : Helper function for test_location_wrappers, to deal with STRIP_NOPS
16027 : : modifying its argument in-place. */
16028 : :
16029 : : static void
16030 : 12 : check_strip_nops (tree node, tree expected)
16031 : : {
16032 : 12 : STRIP_NOPS (node);
16033 : 12 : ASSERT_EQ (expected, node);
16034 : 12 : }
16035 : :
16036 : : /* Verify location wrappers. */
16037 : :
16038 : : static void
16039 : 4 : test_location_wrappers ()
16040 : : {
16041 : 4 : location_t loc = BUILTINS_LOCATION;
16042 : :
16043 : 4 : ASSERT_EQ (NULL_TREE, maybe_wrap_with_location (NULL_TREE, loc));
16044 : :
16045 : : /* Wrapping a constant. */
16046 : 4 : tree int_cst = build_int_cst (integer_type_node, 42);
16047 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_cst));
16048 : 4 : ASSERT_FALSE (location_wrapper_p (int_cst));
16049 : :
16050 : 4 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
16051 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
16052 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_cst));
16053 : 4 : ASSERT_EQ (int_cst, tree_strip_any_location_wrapper (wrapped_int_cst));
16054 : :
16055 : : /* We shouldn't add wrapper nodes for UNKNOWN_LOCATION. */
16056 : 4 : ASSERT_EQ (int_cst, maybe_wrap_with_location (int_cst, UNKNOWN_LOCATION));
16057 : :
16058 : : /* We shouldn't add wrapper nodes for nodes that CAN_HAVE_LOCATION_P. */
16059 : 4 : tree cast = build1 (NOP_EXPR, char_type_node, int_cst);
16060 : 4 : ASSERT_TRUE (CAN_HAVE_LOCATION_P (cast));
16061 : 4 : ASSERT_EQ (cast, maybe_wrap_with_location (cast, loc));
16062 : :
16063 : : /* Wrapping a STRING_CST. */
16064 : 4 : tree string_cst = build_string (4, "foo");
16065 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (string_cst));
16066 : 4 : ASSERT_FALSE (location_wrapper_p (string_cst));
16067 : :
16068 : 4 : tree wrapped_string_cst = maybe_wrap_with_location (string_cst, loc);
16069 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_string_cst));
16070 : 4 : ASSERT_EQ (VIEW_CONVERT_EXPR, TREE_CODE (wrapped_string_cst));
16071 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_string_cst));
16072 : 4 : ASSERT_EQ (string_cst, tree_strip_any_location_wrapper (wrapped_string_cst));
16073 : :
16074 : :
16075 : : /* Wrapping a variable. */
16076 : 4 : tree int_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
16077 : : get_identifier ("some_int_var"),
16078 : : integer_type_node);
16079 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_var));
16080 : 4 : ASSERT_FALSE (location_wrapper_p (int_var));
16081 : :
16082 : 4 : tree wrapped_int_var = maybe_wrap_with_location (int_var, loc);
16083 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_var));
16084 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_var));
16085 : 4 : ASSERT_EQ (int_var, tree_strip_any_location_wrapper (wrapped_int_var));
16086 : :
16087 : : /* Verify that "reinterpret_cast<int>(some_int_var)" is not a location
16088 : : wrapper. */
16089 : 4 : tree r_cast = build1 (NON_LVALUE_EXPR, integer_type_node, int_var);
16090 : 4 : ASSERT_FALSE (location_wrapper_p (r_cast));
16091 : 4 : ASSERT_EQ (r_cast, tree_strip_any_location_wrapper (r_cast));
16092 : :
16093 : : /* Verify that STRIP_NOPS removes wrappers. */
16094 : 4 : check_strip_nops (wrapped_int_cst, int_cst);
16095 : 4 : check_strip_nops (wrapped_string_cst, string_cst);
16096 : 4 : check_strip_nops (wrapped_int_var, int_var);
16097 : 4 : }
16098 : :
16099 : : /* Test various tree predicates. Verify that location wrappers don't
16100 : : affect the results. */
16101 : :
16102 : : static void
16103 : 4 : test_predicates ()
16104 : : {
16105 : : /* Build various constants and wrappers around them. */
16106 : :
16107 : 4 : location_t loc = BUILTINS_LOCATION;
16108 : :
16109 : 4 : tree i_0 = build_int_cst (integer_type_node, 0);
16110 : 4 : tree wr_i_0 = maybe_wrap_with_location (i_0, loc);
16111 : :
16112 : 4 : tree i_1 = build_int_cst (integer_type_node, 1);
16113 : 4 : tree wr_i_1 = maybe_wrap_with_location (i_1, loc);
16114 : :
16115 : 4 : tree i_m1 = build_int_cst (integer_type_node, -1);
16116 : 4 : tree wr_i_m1 = maybe_wrap_with_location (i_m1, loc);
16117 : :
16118 : 4 : tree f_0 = build_real_from_int_cst (float_type_node, i_0);
16119 : 4 : tree wr_f_0 = maybe_wrap_with_location (f_0, loc);
16120 : 4 : tree f_1 = build_real_from_int_cst (float_type_node, i_1);
16121 : 4 : tree wr_f_1 = maybe_wrap_with_location (f_1, loc);
16122 : 4 : tree f_m1 = build_real_from_int_cst (float_type_node, i_m1);
16123 : 4 : tree wr_f_m1 = maybe_wrap_with_location (f_m1, loc);
16124 : :
16125 : 4 : tree c_i_0 = build_complex (NULL_TREE, i_0, i_0);
16126 : 4 : tree c_i_1 = build_complex (NULL_TREE, i_1, i_0);
16127 : 4 : tree c_i_m1 = build_complex (NULL_TREE, i_m1, i_0);
16128 : :
16129 : 4 : tree c_f_0 = build_complex (NULL_TREE, f_0, f_0);
16130 : 4 : tree c_f_1 = build_complex (NULL_TREE, f_1, f_0);
16131 : 4 : tree c_f_m1 = build_complex (NULL_TREE, f_m1, f_0);
16132 : :
16133 : : /* TODO: vector constants. */
16134 : :
16135 : : /* Test integer_onep. */
16136 : 4 : ASSERT_FALSE (integer_onep (i_0));
16137 : 4 : ASSERT_FALSE (integer_onep (wr_i_0));
16138 : 4 : ASSERT_TRUE (integer_onep (i_1));
16139 : 4 : ASSERT_TRUE (integer_onep (wr_i_1));
16140 : 4 : ASSERT_FALSE (integer_onep (i_m1));
16141 : 4 : ASSERT_FALSE (integer_onep (wr_i_m1));
16142 : 4 : ASSERT_FALSE (integer_onep (f_0));
16143 : 4 : ASSERT_FALSE (integer_onep (wr_f_0));
16144 : 4 : ASSERT_FALSE (integer_onep (f_1));
16145 : 4 : ASSERT_FALSE (integer_onep (wr_f_1));
16146 : 4 : ASSERT_FALSE (integer_onep (f_m1));
16147 : 4 : ASSERT_FALSE (integer_onep (wr_f_m1));
16148 : 4 : ASSERT_FALSE (integer_onep (c_i_0));
16149 : 4 : ASSERT_TRUE (integer_onep (c_i_1));
16150 : 4 : ASSERT_FALSE (integer_onep (c_i_m1));
16151 : 4 : ASSERT_FALSE (integer_onep (c_f_0));
16152 : 4 : ASSERT_FALSE (integer_onep (c_f_1));
16153 : 4 : ASSERT_FALSE (integer_onep (c_f_m1));
16154 : :
16155 : : /* Test integer_zerop. */
16156 : 4 : ASSERT_TRUE (integer_zerop (i_0));
16157 : 4 : ASSERT_TRUE (integer_zerop (wr_i_0));
16158 : 4 : ASSERT_FALSE (integer_zerop (i_1));
16159 : 4 : ASSERT_FALSE (integer_zerop (wr_i_1));
16160 : 4 : ASSERT_FALSE (integer_zerop (i_m1));
16161 : 4 : ASSERT_FALSE (integer_zerop (wr_i_m1));
16162 : 4 : ASSERT_FALSE (integer_zerop (f_0));
16163 : 4 : ASSERT_FALSE (integer_zerop (wr_f_0));
16164 : 4 : ASSERT_FALSE (integer_zerop (f_1));
16165 : 4 : ASSERT_FALSE (integer_zerop (wr_f_1));
16166 : 4 : ASSERT_FALSE (integer_zerop (f_m1));
16167 : 4 : ASSERT_FALSE (integer_zerop (wr_f_m1));
16168 : 4 : ASSERT_TRUE (integer_zerop (c_i_0));
16169 : 4 : ASSERT_FALSE (integer_zerop (c_i_1));
16170 : 4 : ASSERT_FALSE (integer_zerop (c_i_m1));
16171 : 4 : ASSERT_FALSE (integer_zerop (c_f_0));
16172 : 4 : ASSERT_FALSE (integer_zerop (c_f_1));
16173 : 4 : ASSERT_FALSE (integer_zerop (c_f_m1));
16174 : :
16175 : : /* Test integer_all_onesp. */
16176 : 4 : ASSERT_FALSE (integer_all_onesp (i_0));
16177 : 4 : ASSERT_FALSE (integer_all_onesp (wr_i_0));
16178 : 4 : ASSERT_FALSE (integer_all_onesp (i_1));
16179 : 4 : ASSERT_FALSE (integer_all_onesp (wr_i_1));
16180 : 4 : ASSERT_TRUE (integer_all_onesp (i_m1));
16181 : 4 : ASSERT_TRUE (integer_all_onesp (wr_i_m1));
16182 : 4 : ASSERT_FALSE (integer_all_onesp (f_0));
16183 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_0));
16184 : 4 : ASSERT_FALSE (integer_all_onesp (f_1));
16185 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_1));
16186 : 4 : ASSERT_FALSE (integer_all_onesp (f_m1));
16187 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_m1));
16188 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_0));
16189 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_1));
16190 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_m1));
16191 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_0));
16192 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_1));
16193 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_m1));
16194 : :
16195 : : /* Test integer_minus_onep. */
16196 : 4 : ASSERT_FALSE (integer_minus_onep (i_0));
16197 : 4 : ASSERT_FALSE (integer_minus_onep (wr_i_0));
16198 : 4 : ASSERT_FALSE (integer_minus_onep (i_1));
16199 : 4 : ASSERT_FALSE (integer_minus_onep (wr_i_1));
16200 : 4 : ASSERT_TRUE (integer_minus_onep (i_m1));
16201 : 4 : ASSERT_TRUE (integer_minus_onep (wr_i_m1));
16202 : 4 : ASSERT_FALSE (integer_minus_onep (f_0));
16203 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_0));
16204 : 4 : ASSERT_FALSE (integer_minus_onep (f_1));
16205 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_1));
16206 : 4 : ASSERT_FALSE (integer_minus_onep (f_m1));
16207 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_m1));
16208 : 4 : ASSERT_FALSE (integer_minus_onep (c_i_0));
16209 : 4 : ASSERT_FALSE (integer_minus_onep (c_i_1));
16210 : 4 : ASSERT_TRUE (integer_minus_onep (c_i_m1));
16211 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_0));
16212 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_1));
16213 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_m1));
16214 : :
16215 : : /* Test integer_each_onep. */
16216 : 4 : ASSERT_FALSE (integer_each_onep (i_0));
16217 : 4 : ASSERT_FALSE (integer_each_onep (wr_i_0));
16218 : 4 : ASSERT_TRUE (integer_each_onep (i_1));
16219 : 4 : ASSERT_TRUE (integer_each_onep (wr_i_1));
16220 : 4 : ASSERT_FALSE (integer_each_onep (i_m1));
16221 : 4 : ASSERT_FALSE (integer_each_onep (wr_i_m1));
16222 : 4 : ASSERT_FALSE (integer_each_onep (f_0));
16223 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_0));
16224 : 4 : ASSERT_FALSE (integer_each_onep (f_1));
16225 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_1));
16226 : 4 : ASSERT_FALSE (integer_each_onep (f_m1));
16227 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_m1));
16228 : 4 : ASSERT_FALSE (integer_each_onep (c_i_0));
16229 : 4 : ASSERT_FALSE (integer_each_onep (c_i_1));
16230 : 4 : ASSERT_FALSE (integer_each_onep (c_i_m1));
16231 : 4 : ASSERT_FALSE (integer_each_onep (c_f_0));
16232 : 4 : ASSERT_FALSE (integer_each_onep (c_f_1));
16233 : 4 : ASSERT_FALSE (integer_each_onep (c_f_m1));
16234 : :
16235 : : /* Test integer_truep. */
16236 : 4 : ASSERT_FALSE (integer_truep (i_0));
16237 : 4 : ASSERT_FALSE (integer_truep (wr_i_0));
16238 : 4 : ASSERT_TRUE (integer_truep (i_1));
16239 : 4 : ASSERT_TRUE (integer_truep (wr_i_1));
16240 : 4 : ASSERT_FALSE (integer_truep (i_m1));
16241 : 4 : ASSERT_FALSE (integer_truep (wr_i_m1));
16242 : 4 : ASSERT_FALSE (integer_truep (f_0));
16243 : 4 : ASSERT_FALSE (integer_truep (wr_f_0));
16244 : 4 : ASSERT_FALSE (integer_truep (f_1));
16245 : 4 : ASSERT_FALSE (integer_truep (wr_f_1));
16246 : 4 : ASSERT_FALSE (integer_truep (f_m1));
16247 : 4 : ASSERT_FALSE (integer_truep (wr_f_m1));
16248 : 4 : ASSERT_FALSE (integer_truep (c_i_0));
16249 : 4 : ASSERT_TRUE (integer_truep (c_i_1));
16250 : 4 : ASSERT_FALSE (integer_truep (c_i_m1));
16251 : 4 : ASSERT_FALSE (integer_truep (c_f_0));
16252 : 4 : ASSERT_FALSE (integer_truep (c_f_1));
16253 : 4 : ASSERT_FALSE (integer_truep (c_f_m1));
16254 : :
16255 : : /* Test integer_nonzerop. */
16256 : 4 : ASSERT_FALSE (integer_nonzerop (i_0));
16257 : 4 : ASSERT_FALSE (integer_nonzerop (wr_i_0));
16258 : 4 : ASSERT_TRUE (integer_nonzerop (i_1));
16259 : 4 : ASSERT_TRUE (integer_nonzerop (wr_i_1));
16260 : 4 : ASSERT_TRUE (integer_nonzerop (i_m1));
16261 : 4 : ASSERT_TRUE (integer_nonzerop (wr_i_m1));
16262 : 4 : ASSERT_FALSE (integer_nonzerop (f_0));
16263 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_0));
16264 : 4 : ASSERT_FALSE (integer_nonzerop (f_1));
16265 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_1));
16266 : 4 : ASSERT_FALSE (integer_nonzerop (f_m1));
16267 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_m1));
16268 : 4 : ASSERT_FALSE (integer_nonzerop (c_i_0));
16269 : 4 : ASSERT_TRUE (integer_nonzerop (c_i_1));
16270 : 4 : ASSERT_TRUE (integer_nonzerop (c_i_m1));
16271 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_0));
16272 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_1));
16273 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_m1));
16274 : :
16275 : : /* Test real_zerop. */
16276 : 4 : ASSERT_FALSE (real_zerop (i_0));
16277 : 4 : ASSERT_FALSE (real_zerop (wr_i_0));
16278 : 4 : ASSERT_FALSE (real_zerop (i_1));
16279 : 4 : ASSERT_FALSE (real_zerop (wr_i_1));
16280 : 4 : ASSERT_FALSE (real_zerop (i_m1));
16281 : 4 : ASSERT_FALSE (real_zerop (wr_i_m1));
16282 : 4 : ASSERT_TRUE (real_zerop (f_0));
16283 : 4 : ASSERT_TRUE (real_zerop (wr_f_0));
16284 : 4 : ASSERT_FALSE (real_zerop (f_1));
16285 : 4 : ASSERT_FALSE (real_zerop (wr_f_1));
16286 : 4 : ASSERT_FALSE (real_zerop (f_m1));
16287 : 4 : ASSERT_FALSE (real_zerop (wr_f_m1));
16288 : 4 : ASSERT_FALSE (real_zerop (c_i_0));
16289 : 4 : ASSERT_FALSE (real_zerop (c_i_1));
16290 : 4 : ASSERT_FALSE (real_zerop (c_i_m1));
16291 : 4 : ASSERT_TRUE (real_zerop (c_f_0));
16292 : 4 : ASSERT_FALSE (real_zerop (c_f_1));
16293 : 4 : ASSERT_FALSE (real_zerop (c_f_m1));
16294 : :
16295 : : /* Test real_onep. */
16296 : 4 : ASSERT_FALSE (real_onep (i_0));
16297 : 4 : ASSERT_FALSE (real_onep (wr_i_0));
16298 : 4 : ASSERT_FALSE (real_onep (i_1));
16299 : 4 : ASSERT_FALSE (real_onep (wr_i_1));
16300 : 4 : ASSERT_FALSE (real_onep (i_m1));
16301 : 4 : ASSERT_FALSE (real_onep (wr_i_m1));
16302 : 4 : ASSERT_FALSE (real_onep (f_0));
16303 : 4 : ASSERT_FALSE (real_onep (wr_f_0));
16304 : 4 : ASSERT_TRUE (real_onep (f_1));
16305 : 4 : ASSERT_TRUE (real_onep (wr_f_1));
16306 : 4 : ASSERT_FALSE (real_onep (f_m1));
16307 : 4 : ASSERT_FALSE (real_onep (wr_f_m1));
16308 : 4 : ASSERT_FALSE (real_onep (c_i_0));
16309 : 4 : ASSERT_FALSE (real_onep (c_i_1));
16310 : 4 : ASSERT_FALSE (real_onep (c_i_m1));
16311 : 4 : ASSERT_FALSE (real_onep (c_f_0));
16312 : 4 : ASSERT_TRUE (real_onep (c_f_1));
16313 : 4 : ASSERT_FALSE (real_onep (c_f_m1));
16314 : :
16315 : : /* Test real_minus_onep. */
16316 : 4 : ASSERT_FALSE (real_minus_onep (i_0));
16317 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_0));
16318 : 4 : ASSERT_FALSE (real_minus_onep (i_1));
16319 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_1));
16320 : 4 : ASSERT_FALSE (real_minus_onep (i_m1));
16321 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_m1));
16322 : 4 : ASSERT_FALSE (real_minus_onep (f_0));
16323 : 4 : ASSERT_FALSE (real_minus_onep (wr_f_0));
16324 : 4 : ASSERT_FALSE (real_minus_onep (f_1));
16325 : 4 : ASSERT_FALSE (real_minus_onep (wr_f_1));
16326 : 4 : ASSERT_TRUE (real_minus_onep (f_m1));
16327 : 4 : ASSERT_TRUE (real_minus_onep (wr_f_m1));
16328 : 4 : ASSERT_FALSE (real_minus_onep (c_i_0));
16329 : 4 : ASSERT_FALSE (real_minus_onep (c_i_1));
16330 : 4 : ASSERT_FALSE (real_minus_onep (c_i_m1));
16331 : 4 : ASSERT_FALSE (real_minus_onep (c_f_0));
16332 : 4 : ASSERT_FALSE (real_minus_onep (c_f_1));
16333 : 4 : ASSERT_TRUE (real_minus_onep (c_f_m1));
16334 : :
16335 : : /* Test zerop. */
16336 : 4 : ASSERT_TRUE (zerop (i_0));
16337 : 4 : ASSERT_TRUE (zerop (wr_i_0));
16338 : 4 : ASSERT_FALSE (zerop (i_1));
16339 : 4 : ASSERT_FALSE (zerop (wr_i_1));
16340 : 4 : ASSERT_FALSE (zerop (i_m1));
16341 : 4 : ASSERT_FALSE (zerop (wr_i_m1));
16342 : 4 : ASSERT_TRUE (zerop (f_0));
16343 : 4 : ASSERT_TRUE (zerop (wr_f_0));
16344 : 4 : ASSERT_FALSE (zerop (f_1));
16345 : 4 : ASSERT_FALSE (zerop (wr_f_1));
16346 : 4 : ASSERT_FALSE (zerop (f_m1));
16347 : 4 : ASSERT_FALSE (zerop (wr_f_m1));
16348 : 4 : ASSERT_TRUE (zerop (c_i_0));
16349 : 4 : ASSERT_FALSE (zerop (c_i_1));
16350 : 4 : ASSERT_FALSE (zerop (c_i_m1));
16351 : 4 : ASSERT_TRUE (zerop (c_f_0));
16352 : 4 : ASSERT_FALSE (zerop (c_f_1));
16353 : 4 : ASSERT_FALSE (zerop (c_f_m1));
16354 : :
16355 : : /* Test tree_expr_nonnegative_p. */
16356 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_0));
16357 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_0));
16358 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_1));
16359 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_1));
16360 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (i_m1));
16361 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_i_m1));
16362 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_0));
16363 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_0));
16364 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_1));
16365 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_1));
16366 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (f_m1));
16367 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_f_m1));
16368 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_0));
16369 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_1));
16370 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_m1));
16371 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_0));
16372 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_1));
16373 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_m1));
16374 : :
16375 : : /* Test tree_expr_nonzero_p. */
16376 : 4 : ASSERT_FALSE (tree_expr_nonzero_p (i_0));
16377 : 4 : ASSERT_FALSE (tree_expr_nonzero_p (wr_i_0));
16378 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_1));
16379 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_1));
16380 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_m1));
16381 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_m1));
16382 : :
16383 : : /* Test integer_valued_real_p. */
16384 : 4 : ASSERT_FALSE (integer_valued_real_p (i_0));
16385 : 4 : ASSERT_TRUE (integer_valued_real_p (f_0));
16386 : 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_0));
16387 : 4 : ASSERT_TRUE (integer_valued_real_p (f_1));
16388 : 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_1));
16389 : :
16390 : : /* Test integer_pow2p. */
16391 : 4 : ASSERT_FALSE (integer_pow2p (i_0));
16392 : 4 : ASSERT_TRUE (integer_pow2p (i_1));
16393 : 4 : ASSERT_TRUE (integer_pow2p (wr_i_1));
16394 : :
16395 : : /* Test uniform_integer_cst_p. */
16396 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_0));
16397 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_0));
16398 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_1));
16399 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_1));
16400 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_m1));
16401 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_m1));
16402 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_0));
16403 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_0));
16404 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_1));
16405 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_1));
16406 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_m1));
16407 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_m1));
16408 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_0));
16409 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_1));
16410 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_m1));
16411 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_0));
16412 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_1));
16413 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_m1));
16414 : 4 : }
16415 : :
16416 : : /* Check that string escaping works correctly. */
16417 : :
16418 : : static void
16419 : 4 : test_escaped_strings (void)
16420 : : {
16421 : 4 : int saved_cutoff;
16422 : 4 : escaped_string msg;
16423 : :
16424 : 4 : msg.escape (NULL);
16425 : : /* ASSERT_STREQ does not accept NULL as a valid test
16426 : : result, so we have to use ASSERT_EQ instead. */
16427 : 4 : ASSERT_EQ (NULL, (const char *) msg);
16428 : :
16429 : 4 : msg.escape ("");
16430 : 4 : ASSERT_STREQ ("", (const char *) msg);
16431 : :
16432 : 4 : msg.escape ("foobar");
16433 : 4 : ASSERT_STREQ ("foobar", (const char *) msg);
16434 : :
16435 : : /* Ensure that we have -fmessage-length set to 0. */
16436 : 4 : pretty_printer *pp = global_dc->get_reference_printer ();
16437 : 4 : saved_cutoff = pp_line_cutoff (pp);
16438 : 4 : pp_line_cutoff (pp) = 0;
16439 : :
16440 : 4 : msg.escape ("foo\nbar");
16441 : 4 : ASSERT_STREQ ("foo\\nbar", (const char *) msg);
16442 : :
16443 : 4 : msg.escape ("\a\b\f\n\r\t\v");
16444 : 4 : ASSERT_STREQ ("\\a\\b\\f\\n\\r\\t\\v", (const char *) msg);
16445 : :
16446 : : /* Now repeat the tests with -fmessage-length set to 5. */
16447 : 4 : pp_line_cutoff (pp) = 5;
16448 : :
16449 : : /* Note that the newline is not translated into an escape. */
16450 : 4 : msg.escape ("foo\nbar");
16451 : 4 : ASSERT_STREQ ("foo\nbar", (const char *) msg);
16452 : :
16453 : 4 : msg.escape ("\a\b\f\n\r\t\v");
16454 : 4 : ASSERT_STREQ ("\\a\\b\\f\n\\r\\t\\v", (const char *) msg);
16455 : :
16456 : : /* Restore the original message length setting. */
16457 : 4 : pp_line_cutoff (pp) = saved_cutoff;
16458 : 4 : }
16459 : :
16460 : : /* Run all of the selftests within this file. */
16461 : :
16462 : : void
16463 : 4 : tree_cc_tests ()
16464 : : {
16465 : 4 : test_integer_constants ();
16466 : 4 : test_identifiers ();
16467 : 4 : test_labels ();
16468 : 4 : test_vector_cst_patterns ();
16469 : 4 : test_location_wrappers ();
16470 : 4 : test_predicates ();
16471 : 4 : test_escaped_strings ();
16472 : 4 : }
16473 : :
16474 : : } // namespace selftest
16475 : :
16476 : : #endif /* CHECKING_P */
16477 : :
16478 : : #include "gt-tree.h"
|