Branch data Line data Source code
1 : : /* Pass to free or clear language-specific data structures from
2 : : the IL before they reach the middle end.
3 : :
4 : : Copyright (C) 1987-2025 Free Software Foundation, Inc.
5 : :
6 : : This file is part of GCC.
7 : :
8 : : GCC is free software; you can redistribute it and/or modify it under
9 : : the terms of the GNU General Public License as published by the Free
10 : : Software Foundation; either version 3, or (at your option) any later
11 : : version.
12 : :
13 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 : : for more details.
17 : :
18 : : You should have received a copy of the GNU General Public License
19 : : along with GCC; see the file COPYING3. If not see
20 : : <http://www.gnu.org/licenses/>. */
21 : :
22 : : /* This file contains the low level primitives for operating on tree nodes,
23 : : including allocation, list operations, interning of identifiers,
24 : : construction of data type nodes and statement nodes,
25 : : and construction of type conversion nodes. It also contains
26 : : tables index by tree code that describe how to take apart
27 : : nodes of that code.
28 : :
29 : : It is intended to be language-independent but can occasionally
30 : : calls language-dependent routines. */
31 : :
32 : : #include "config.h"
33 : : #include "system.h"
34 : : #include "coretypes.h"
35 : : #include "backend.h"
36 : : #include "target.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 "alias.h"
44 : : #include "attribs.h"
45 : : #include "langhooks.h"
46 : : #include "gimple-iterator.h"
47 : : #include "langhooks-def.h"
48 : : #include "tree-diagnostic.h"
49 : : #include "except.h"
50 : : #include "ipa-utils.h"
51 : :
52 : : namespace {
53 : :
54 : : /* Data used when collecting DECLs and TYPEs for language data removal. */
55 : :
56 : : class free_lang_data_d
57 : : {
58 : : public:
59 : 227253 : free_lang_data_d () : decls (100), types (100) {}
60 : :
61 : : /* Worklist to avoid excessive recursion. */
62 : : auto_vec<tree> worklist;
63 : :
64 : : /* Set of traversed objects. Used to avoid duplicate visits. */
65 : : hash_set<tree> pset;
66 : :
67 : : /* Array of symbols to process with free_lang_data_in_decl. */
68 : : auto_vec<tree> decls;
69 : :
70 : : /* Array of types to process with free_lang_data_in_type. */
71 : : auto_vec<tree> types;
72 : : };
73 : :
74 : :
75 : : /* Add type or decl T to one of the list of tree nodes that need their
76 : : language data removed. The lists are held inside FLD. */
77 : :
78 : : static void
79 : 13481813 : add_tree_to_fld_list (tree t, class free_lang_data_d *fld)
80 : : {
81 : 13481813 : if (DECL_P (t))
82 : 9677272 : fld->decls.safe_push (t);
83 : 3804541 : else if (TYPE_P (t))
84 : 3804541 : fld->types.safe_push (t);
85 : : else
86 : 0 : gcc_unreachable ();
87 : 13481813 : }
88 : :
89 : : /* Push tree node T into FLD->WORKLIST. */
90 : :
91 : : static inline void
92 : 159128116 : fld_worklist_push (tree t, class free_lang_data_d *fld)
93 : : {
94 : 236667703 : if (t && !is_lang_specific (t) && !fld->pset.contains (t))
95 : 35999982 : fld->worklist.safe_push ((t));
96 : 159128116 : }
97 : :
98 : :
99 : :
100 : : /* Return simplified TYPE_NAME of TYPE. */
101 : :
102 : : static tree
103 : 4583980 : fld_simplified_type_name (tree type)
104 : : {
105 : 4583980 : if (!TYPE_NAME (type) || TREE_CODE (TYPE_NAME (type)) != TYPE_DECL)
106 : 4061351 : return TYPE_NAME (type);
107 : : /* Drop TYPE_DECLs in TYPE_NAME in favor of the identifier in the
108 : : TYPE_DECL if the type doesn't have linkage.
109 : : this must match fld_ */
110 : 522629 : if (type != TYPE_MAIN_VARIANT (type)
111 : 522629 : || (!DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (type))
112 : 244584 : && (TREE_CODE (type) != RECORD_TYPE
113 : 26439 : || !TYPE_BINFO (type)
114 : 0 : || !BINFO_VTABLE (TYPE_BINFO (type)))))
115 : 462303 : return DECL_NAME (TYPE_NAME (type));
116 : 60326 : return TYPE_NAME (type);
117 : : }
118 : :
119 : : /* Do same comparsion as check_qualified_type skipping lang part of type
120 : : and be more permissive about type names: we only care that names are
121 : : same (for diagnostics) and that ODR names are the same.
122 : : If INNER_TYPE is non-NULL, be sure that TREE_TYPE match it. */
123 : :
124 : : static bool
125 : 472061 : fld_type_variant_equal_p (tree t, tree v, tree inner_type)
126 : : {
127 : 472061 : if (TYPE_QUALS (t) != TYPE_QUALS (v)
128 : : /* We want to match incomplete variants with complete types.
129 : : In this case we need to ignore alignment. */
130 : 372357 : || ((!RECORD_OR_UNION_TYPE_P (t) || COMPLETE_TYPE_P (v))
131 : 264239 : && (TYPE_ALIGN (t) != TYPE_ALIGN (v)
132 : 264227 : || TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (v)))
133 : 372345 : || fld_simplified_type_name (t) != fld_simplified_type_name (v)
134 : 326554 : || !attribute_list_equal (TYPE_ATTRIBUTES (t),
135 : 326554 : TYPE_ATTRIBUTES (v))
136 : 798615 : || (inner_type && TREE_TYPE (v) != inner_type))
137 : 145507 : return false;
138 : :
139 : : return true;
140 : : }
141 : :
142 : : /* Find variant of FIRST that match T and create new one if necessary.
143 : : Set TREE_TYPE to INNER_TYPE if non-NULL. */
144 : :
145 : : static tree
146 : 326554 : fld_type_variant (tree first, tree t, class free_lang_data_d *fld,
147 : : tree inner_type = NULL)
148 : : {
149 : 326554 : if (first == TYPE_MAIN_VARIANT (t))
150 : : return t;
151 : 472061 : for (tree v = first; v; v = TYPE_NEXT_VARIANT (v))
152 : 430709 : if (fld_type_variant_equal_p (t, v, inner_type))
153 : : return v;
154 : 41352 : tree v = build_variant_type_copy (first);
155 : 41352 : TYPE_READONLY (v) = TYPE_READONLY (t);
156 : 41352 : TYPE_VOLATILE (v) = TYPE_VOLATILE (t);
157 : 41352 : TYPE_ATOMIC (v) = TYPE_ATOMIC (t);
158 : 41352 : TYPE_RESTRICT (v) = TYPE_RESTRICT (t);
159 : 41352 : TYPE_ADDR_SPACE (v) = TYPE_ADDR_SPACE (t);
160 : 41352 : TYPE_NAME (v) = TYPE_NAME (t);
161 : 41352 : TYPE_ATTRIBUTES (v) = TYPE_ATTRIBUTES (t);
162 : 41352 : TYPE_CANONICAL (v) = TYPE_CANONICAL (t);
163 : : /* Variants of incomplete types should have alignment
164 : : set to BITS_PER_UNIT. Do not copy the actual alignment. */
165 : 41352 : if (!RECORD_OR_UNION_TYPE_P (v) || COMPLETE_TYPE_P (v))
166 : : {
167 : 19314 : SET_TYPE_ALIGN (v, TYPE_ALIGN (t));
168 : 19314 : TYPE_USER_ALIGN (v) = TYPE_USER_ALIGN (t);
169 : : }
170 : 41352 : if (inner_type)
171 : 18 : TREE_TYPE (v) = inner_type;
172 : 41352 : gcc_checking_assert (fld_type_variant_equal_p (t,v, inner_type));
173 : 41352 : if (!fld->pset.add (v))
174 : 41352 : add_tree_to_fld_list (v, fld);
175 : : return v;
176 : : }
177 : :
178 : : /* Map complete types to incomplete types. */
179 : :
180 : : static hash_map<tree, tree> *fld_incomplete_types;
181 : :
182 : : /* Map types to simplified types. */
183 : :
184 : : static hash_map<tree, tree> *fld_simplified_types;
185 : :
186 : : /* Produce variant of T whose TREE_TYPE is T2. If it is main variant,
187 : : use MAP to prevent duplicates. */
188 : :
189 : : static tree
190 : 2877 : fld_process_array_type (tree t, tree t2, hash_map<tree, tree> *map,
191 : : class free_lang_data_d *fld)
192 : : {
193 : 2877 : if (TREE_TYPE (t) == t2)
194 : : return t;
195 : :
196 : 142 : if (TYPE_MAIN_VARIANT (t) != t)
197 : : {
198 : 18 : return fld_type_variant
199 : 18 : (fld_process_array_type (TYPE_MAIN_VARIANT (t),
200 : 18 : TYPE_MAIN_VARIANT (t2), map, fld),
201 : 18 : t, fld, t2);
202 : : }
203 : :
204 : 124 : bool existed;
205 : 124 : tree &array
206 : 124 : = map->get_or_insert (t, &existed);
207 : 124 : if (!existed)
208 : : {
209 : 27 : array
210 : 27 : = build_array_type_1 (t2, TYPE_DOMAIN (t), TYPE_TYPELESS_STORAGE (t),
211 : : false, false);
212 : 27 : TYPE_CANONICAL (array) = TYPE_CANONICAL (t);
213 : 27 : if (!fld->pset.add (array))
214 : 27 : add_tree_to_fld_list (array, fld);
215 : : }
216 : 124 : return array;
217 : : }
218 : :
219 : : /* Return CTX after removal of contexts that are not relevant */
220 : :
221 : : static tree
222 : 9405090 : fld_decl_context (tree ctx)
223 : : {
224 : : /* Variably modified types are needed for tree_is_indexable to decide
225 : : whether the type needs to go to local or global section.
226 : : This code is semi-broken but for now it is easiest to keep contexts
227 : : as expected. */
228 : 7929632 : if (ctx && TYPE_P (ctx)
229 : 9473619 : && !variably_modified_type_p (ctx, NULL_TREE))
230 : : {
231 : 144882 : while (ctx && TYPE_P (ctx))
232 : 76353 : ctx = TYPE_CONTEXT (ctx);
233 : : }
234 : 9405090 : return ctx;
235 : : }
236 : :
237 : : /* For T being aggregate type try to turn it into an incomplete variant.
238 : : Return T if no simplification is possible. */
239 : :
240 : : static tree
241 : 5585280 : fld_incomplete_type_of (tree t, class free_lang_data_d *fld)
242 : : {
243 : 5585280 : if (!t)
244 : : return NULL;
245 : 5585280 : if (POINTER_TYPE_P (t))
246 : : {
247 : 2790750 : tree t2 = fld_incomplete_type_of (TREE_TYPE (t), fld);
248 : 2790750 : if (t2 != TREE_TYPE (t))
249 : : {
250 : 258454 : tree first;
251 : 258454 : if (TREE_CODE (t) == POINTER_TYPE)
252 : 233451 : first = build_pointer_type_for_mode (t2, TYPE_MODE (t),
253 : 233451 : TYPE_REF_CAN_ALIAS_ALL (t));
254 : : else
255 : 25003 : first = build_reference_type_for_mode (t2, TYPE_MODE (t),
256 : 25003 : TYPE_REF_CAN_ALIAS_ALL (t));
257 : 258454 : gcc_assert (TYPE_CANONICAL (t2) != t2
258 : : && TYPE_CANONICAL (t2) == TYPE_CANONICAL (TREE_TYPE (t)));
259 : 258454 : if (!fld->pset.add (first))
260 : 56798 : add_tree_to_fld_list (first, fld);
261 : 258454 : return fld_type_variant (first, t, fld);
262 : : }
263 : : return t;
264 : : }
265 : 2794530 : if (TREE_CODE (t) == ARRAY_TYPE)
266 : 2859 : return fld_process_array_type (t,
267 : 2859 : fld_incomplete_type_of (TREE_TYPE (t), fld),
268 : 2859 : fld_incomplete_types, fld);
269 : 2791671 : if ((!RECORD_OR_UNION_TYPE_P (t) && TREE_CODE (t) != ENUMERAL_TYPE)
270 : 2791671 : || !COMPLETE_TYPE_P (t))
271 : : return t;
272 : 324350 : if (TYPE_MAIN_VARIANT (t) == t)
273 : : {
274 : 256268 : bool existed;
275 : 256268 : tree ©
276 : 256268 : = fld_incomplete_types->get_or_insert (t, &existed);
277 : :
278 : 256268 : if (!existed)
279 : : {
280 : 33124 : copy = build_distinct_type_copy (t);
281 : :
282 : : /* It is possible that type was not seen by free_lang_data yet. */
283 : 33124 : if (!fld->pset.add (copy))
284 : 33124 : add_tree_to_fld_list (copy, fld);
285 : 33124 : TYPE_SIZE (copy) = NULL;
286 : 33124 : TYPE_USER_ALIGN (copy) = 0;
287 : 33124 : TYPE_SIZE_UNIT (copy) = NULL;
288 : 33124 : TYPE_CANONICAL (copy) = TYPE_CANONICAL (t);
289 : 33124 : TREE_ADDRESSABLE (copy) = 0;
290 : 33124 : if (AGGREGATE_TYPE_P (t))
291 : : {
292 : 33056 : SET_TYPE_MODE (copy, VOIDmode);
293 : 33056 : SET_TYPE_ALIGN (copy, BITS_PER_UNIT);
294 : 33056 : TYPE_TYPELESS_STORAGE (copy) = 0;
295 : 33056 : TYPE_FIELDS (copy) = NULL;
296 : 33056 : TYPE_BINFO (copy) = NULL;
297 : 33056 : TYPE_FINAL_P (copy) = 0;
298 : 33056 : TYPE_EMPTY_P (copy) = 0;
299 : : }
300 : : else
301 : : {
302 : 68 : TYPE_VALUES (copy) = NULL;
303 : 68 : ENUM_IS_OPAQUE (copy) = 0;
304 : 68 : ENUM_IS_SCOPED (copy) = 0;
305 : : }
306 : :
307 : : /* Build copy of TYPE_DECL in TYPE_NAME if necessary.
308 : : This is needed for ODR violation warnings to come out right (we
309 : : want duplicate TYPE_DECLs whenever the type is duplicated because
310 : : of ODR violation. Because lang data in the TYPE_DECL may not
311 : : have been freed yet, rebuild it from scratch and copy relevant
312 : : fields. */
313 : 33124 : TYPE_NAME (copy) = fld_simplified_type_name (copy);
314 : 33124 : tree name = TYPE_NAME (copy);
315 : :
316 : 33124 : if (name && TREE_CODE (name) == TYPE_DECL)
317 : : {
318 : 8946 : gcc_checking_assert (TREE_TYPE (name) == t);
319 : 8946 : tree name2 = build_decl (DECL_SOURCE_LOCATION (name), TYPE_DECL,
320 : 8946 : DECL_NAME (name), copy);
321 : 8946 : if (DECL_ASSEMBLER_NAME_SET_P (name))
322 : 8946 : SET_DECL_ASSEMBLER_NAME (name2, DECL_ASSEMBLER_NAME (name));
323 : 8946 : SET_DECL_ALIGN (name2, 0);
324 : 26838 : DECL_CONTEXT (name2) = fld_decl_context
325 : 8946 : (DECL_CONTEXT (name));
326 : 8946 : TYPE_NAME (copy) = name2;
327 : : }
328 : : }
329 : 256268 : return copy;
330 : : }
331 : 68082 : return (fld_type_variant
332 : 68082 : (fld_incomplete_type_of (TYPE_MAIN_VARIANT (t), fld), t, fld));
333 : : }
334 : :
335 : : /* Simplify type T for scenarios where we do not need complete pointer
336 : : types. */
337 : :
338 : : static tree
339 : 17585310 : fld_simplified_type (tree t, class free_lang_data_d *fld)
340 : : {
341 : 17585310 : if (!t)
342 : : return t;
343 : 17585310 : if (POINTER_TYPE_P (t))
344 : 2723589 : return fld_incomplete_type_of (t, fld);
345 : : /* FIXME: This triggers verification error, see PR88140. */
346 : : #if 0
347 : : if (TREE_CODE (t) == ARRAY_TYPE)
348 : : return fld_process_array_type (t, fld_simplified_type (TREE_TYPE (t), fld),
349 : : fld_simplified_types, fld);
350 : : #endif
351 : : return t;
352 : : }
353 : :
354 : : /* Reset the expression *EXPR_P, a size or position.
355 : :
356 : : ??? We could reset all non-constant sizes or positions. But it's cheap
357 : : enough to not do so and refrain from adding workarounds to dwarf2out.cc.
358 : :
359 : : We need to reset self-referential sizes or positions because they cannot
360 : : be gimplified and thus can contain a CALL_EXPR after the gimplification
361 : : is finished, which will run afoul of LTO streaming. And they need to be
362 : : reset to something essentially dummy but not constant, so as to preserve
363 : : the properties of the object they are attached to. */
364 : :
365 : : static inline void
366 : 27901889 : free_lang_data_in_one_sizepos (tree *expr_p)
367 : : {
368 : 27901889 : tree expr = *expr_p;
369 : 27901889 : if (CONTAINS_PLACEHOLDER_P (expr))
370 : 0 : *expr_p = build0 (PLACEHOLDER_EXPR, TREE_TYPE (expr));
371 : 27901889 : }
372 : :
373 : :
374 : : /* Reset all the fields in a binfo node BINFO. We only keep
375 : : BINFO_VTABLE, which is used by gimple_fold_obj_type_ref. */
376 : :
377 : : static void
378 : 55681 : free_lang_data_in_binfo (tree binfo)
379 : : {
380 : 55681 : unsigned i;
381 : 55681 : tree t;
382 : :
383 : 55681 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
384 : :
385 : 55681 : BINFO_VIRTUALS (binfo) = NULL_TREE;
386 : 55681 : BINFO_BASE_ACCESSES (binfo) = NULL;
387 : 55681 : BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE;
388 : 55681 : BINFO_SUBVTT_INDEX (binfo) = NULL_TREE;
389 : 55681 : BINFO_VPTR_FIELD (binfo) = NULL_TREE;
390 : 55681 : TREE_PUBLIC (binfo) = 0;
391 : :
392 : 79045 : FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo), i, t)
393 : 23364 : free_lang_data_in_binfo (t);
394 : 55681 : }
395 : :
396 : :
397 : : /* Reset all language specific information still present in TYPE. */
398 : :
399 : : static void
400 : 3806166 : free_lang_data_in_type (tree type, class free_lang_data_d *fld)
401 : : {
402 : 3806166 : gcc_assert (TYPE_P (type));
403 : :
404 : : /* Give the FE a chance to remove its own data first. */
405 : 3806166 : lang_hooks.free_lang_data (type);
406 : :
407 : 3806166 : TREE_LANG_FLAG_0 (type) = 0;
408 : 3806166 : TREE_LANG_FLAG_1 (type) = 0;
409 : 3806166 : TREE_LANG_FLAG_2 (type) = 0;
410 : 3806166 : TREE_LANG_FLAG_3 (type) = 0;
411 : 3806166 : TREE_LANG_FLAG_4 (type) = 0;
412 : 3806166 : TREE_LANG_FLAG_5 (type) = 0;
413 : 3806166 : TREE_LANG_FLAG_6 (type) = 0;
414 : :
415 : 3806166 : TYPE_NEEDS_CONSTRUCTING (type) = 0;
416 : :
417 : : /* Purge non-marked variants from the variants chain, so that they
418 : : don't reappear in the IL after free_lang_data. */
419 : 3806166 : while (TYPE_NEXT_VARIANT (type)
420 : 4332384 : && !fld->pset.contains (TYPE_NEXT_VARIANT (type)))
421 : : {
422 : 526218 : tree t = TYPE_NEXT_VARIANT (type);
423 : 526218 : TYPE_NEXT_VARIANT (type) = TYPE_NEXT_VARIANT (t);
424 : : /* Turn the removed types into distinct types. */
425 : 526218 : TYPE_MAIN_VARIANT (t) = t;
426 : 526218 : TYPE_NEXT_VARIANT (t) = NULL_TREE;
427 : : }
428 : :
429 : 3806166 : if (TREE_CODE (type) == FUNCTION_TYPE)
430 : : {
431 : 2363548 : TREE_TYPE (type) = fld_simplified_type (TREE_TYPE (type), fld);
432 : : /* Remove the const and volatile qualifiers from arguments. The
433 : : C++ front end removes them, but the C front end does not,
434 : : leading to false ODR violation errors when merging two
435 : : instances of the same function signature compiled by
436 : : different front ends. */
437 : 9793716 : for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
438 : : {
439 : 7430168 : tree arg_type = TREE_VALUE (p);
440 : 7430168 : if (TYPE_READONLY (arg_type) || TYPE_VOLATILE (arg_type))
441 : : {
442 : 24477 : int quals = TYPE_QUALS (arg_type)
443 : : & ~TYPE_QUAL_CONST
444 : 24477 : & ~TYPE_QUAL_VOLATILE;
445 : 24477 : TREE_VALUE (p) = build_qualified_type (arg_type, quals);
446 : 24477 : if (!fld->pset.add (TREE_VALUE (p)))
447 : 1625 : free_lang_data_in_type (TREE_VALUE (p), fld);
448 : : }
449 : 7430168 : TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld);
450 : : /* C++ FE uses TREE_PURPOSE to store initial values. */
451 : 7430168 : TREE_PURPOSE (p) = NULL;
452 : : }
453 : : }
454 : : else if (TREE_CODE (type) == METHOD_TYPE)
455 : : {
456 : 57217 : TREE_TYPE (type) = fld_simplified_type (TREE_TYPE (type), fld);
457 : 224628 : for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
458 : : {
459 : : /* C++ FE uses TREE_PURPOSE to store initial values. */
460 : 167411 : TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld);
461 : 167411 : TREE_PURPOSE (p) = NULL;
462 : : }
463 : : }
464 : : else if (RECORD_OR_UNION_TYPE_P (type))
465 : : {
466 : : /* Remove members that are not FIELD_DECLs from the field list
467 : : of an aggregate. These occur in C++. */
468 : 895057 : for (tree *prev = &TYPE_FIELDS (type), member; (member = *prev);)
469 : 708885 : if (TREE_CODE (member) == FIELD_DECL)
470 : 359311 : prev = &DECL_CHAIN (member);
471 : : else
472 : 349574 : *prev = DECL_CHAIN (member);
473 : :
474 : 186172 : TYPE_VFIELD (type) = NULL_TREE;
475 : :
476 : 186172 : if (TYPE_BINFO (type))
477 : : {
478 : 32317 : free_lang_data_in_binfo (TYPE_BINFO (type));
479 : : /* We need to preserve link to bases and virtual table for all
480 : : polymorphic types to make devirtualization machinery working. */
481 : 32317 : if (!BINFO_VTABLE (TYPE_BINFO (type)))
482 : 28289 : TYPE_BINFO (type) = NULL;
483 : : }
484 : : }
485 : : else if (INTEGRAL_TYPE_P (type)
486 : : || SCALAR_FLOAT_TYPE_P (type)
487 : : || FIXED_POINT_TYPE_P (type))
488 : : {
489 : 336460 : if (TREE_CODE (type) == ENUMERAL_TYPE)
490 : : {
491 : 3509 : ENUM_IS_OPAQUE (type) = 0;
492 : 3509 : ENUM_IS_SCOPED (type) = 0;
493 : : /* Type values are used only for C++ ODR checking. Drop them
494 : : for all type variants and non-ODR types.
495 : : For ODR types the data is freed in free_odr_warning_data. */
496 : 3509 : if (!TYPE_VALUES (type))
497 : : ;
498 : 1096 : else if (TYPE_MAIN_VARIANT (type) != type
499 : 755 : || !type_with_linkage_p (type)
500 : 1465 : || type_in_anonymous_namespace_p (type))
501 : 759 : TYPE_VALUES (type) = NULL;
502 : : else
503 : 337 : register_odr_enum (type);
504 : : }
505 : 336460 : free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type));
506 : 336460 : free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type));
507 : : }
508 : :
509 : 3806166 : TYPE_LANG_SLOT_1 (type) = NULL_TREE;
510 : :
511 : 3806166 : free_lang_data_in_one_sizepos (&TYPE_SIZE (type));
512 : 3806166 : free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type));
513 : :
514 : 3806166 : if (TYPE_CONTEXT (type)
515 : 3806166 : && TREE_CODE (TYPE_CONTEXT (type)) == BLOCK)
516 : : {
517 : 0 : tree ctx = TYPE_CONTEXT (type);
518 : 0 : do
519 : : {
520 : 0 : ctx = BLOCK_SUPERCONTEXT (ctx);
521 : : }
522 : 0 : while (ctx && TREE_CODE (ctx) == BLOCK);
523 : 0 : TYPE_CONTEXT (type) = ctx;
524 : : }
525 : :
526 : 3806166 : TYPE_STUB_DECL (type) = NULL;
527 : 3806166 : TYPE_NAME (type) = fld_simplified_type_name (type);
528 : 3806166 : }
529 : :
530 : : /* Reset all language specific information still present in symbol
531 : : DECL. */
532 : :
533 : : static void
534 : 9677272 : free_lang_data_in_decl (tree decl, class free_lang_data_d *fld)
535 : : {
536 : 9677272 : gcc_assert (DECL_P (decl));
537 : :
538 : : /* Give the FE a chance to remove its own data first. */
539 : 9677272 : lang_hooks.free_lang_data (decl);
540 : :
541 : 9677272 : TREE_LANG_FLAG_0 (decl) = 0;
542 : 9677272 : TREE_LANG_FLAG_1 (decl) = 0;
543 : 9677272 : TREE_LANG_FLAG_2 (decl) = 0;
544 : 9677272 : TREE_LANG_FLAG_3 (decl) = 0;
545 : 9677272 : TREE_LANG_FLAG_4 (decl) = 0;
546 : 9677272 : TREE_LANG_FLAG_5 (decl) = 0;
547 : 9677272 : TREE_LANG_FLAG_6 (decl) = 0;
548 : :
549 : 9677272 : free_lang_data_in_one_sizepos (&DECL_SIZE (decl));
550 : 9677272 : free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl));
551 : 9677272 : if (TREE_CODE (decl) == FIELD_DECL)
552 : : {
553 : 262093 : DECL_FCONTEXT (decl) = NULL;
554 : 262093 : free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl));
555 : 262093 : if (TREE_CODE (DECL_CONTEXT (decl)) == QUAL_UNION_TYPE)
556 : 0 : DECL_QUALIFIER (decl) = NULL_TREE;
557 : : }
558 : :
559 : 9677272 : if (TREE_CODE (decl) == FUNCTION_DECL)
560 : : {
561 : 7304873 : struct cgraph_node *node;
562 : : /* Frontends do not set TREE_ADDRESSABLE on public variables even though
563 : : the address may be taken in other unit, so this flag has no practical
564 : : use for middle-end.
565 : :
566 : : It would make more sense if frontends set TREE_ADDRESSABLE to 0 only
567 : : for public objects that indeed cannot be adressed, but it is not
568 : : the case. Set the flag to true so we do not get merge failures for
569 : : i.e. virtual tables between units that take address of it and
570 : : units that don't. */
571 : 7304873 : if (TREE_PUBLIC (decl))
572 : 7291856 : TREE_ADDRESSABLE (decl) = true;
573 : 7304873 : TREE_TYPE (decl) = fld_simplified_type (TREE_TYPE (decl), fld);
574 : 7304873 : if (!(node = cgraph_node::get (decl))
575 : 7304873 : || (!node->definition && !node->clones))
576 : : {
577 : 7179800 : if (node)
578 : 235846 : node->release_body ();
579 : : else
580 : : {
581 : 6943954 : release_function_body (decl);
582 : 6943954 : DECL_ARGUMENTS (decl) = NULL;
583 : 6943954 : DECL_RESULT (decl) = NULL;
584 : 6943954 : DECL_INITIAL (decl) = error_mark_node;
585 : : }
586 : : }
587 : 7304873 : if (gimple_has_body_p (decl) || (node && node->thunk))
588 : : {
589 : 118661 : tree t;
590 : :
591 : : /* If DECL has a gimple body, then the context for its
592 : : arguments must be DECL. Otherwise, it doesn't really
593 : : matter, as we will not be emitting any code for DECL. In
594 : : general, there may be other instances of DECL created by
595 : : the front end and since PARM_DECLs are generally shared,
596 : : their DECL_CONTEXT changes as the replicas of DECL are
597 : : created. The only time where DECL_CONTEXT is important
598 : : is for the FUNCTION_DECLs that have a gimple body (since
599 : : the PARM_DECL will be used in the function's body). */
600 : 457879 : for (t = DECL_ARGUMENTS (decl); t; t = TREE_CHAIN (t))
601 : 339218 : DECL_CONTEXT (t) = decl;
602 : 118661 : if (!DECL_FUNCTION_SPECIFIC_TARGET (decl))
603 : 118647 : DECL_FUNCTION_SPECIFIC_TARGET (decl)
604 : 118647 : = target_option_default_node;
605 : 118661 : if (!DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl))
606 : 114922 : DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl)
607 : 114922 : = optimization_default_node;
608 : : }
609 : :
610 : : /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
611 : : At this point, it is not needed anymore. */
612 : 7304873 : DECL_SAVED_TREE (decl) = NULL_TREE;
613 : :
614 : : /* Clear the abstract origin if it refers to a method.
615 : : Otherwise dwarf2out.cc will ICE as we splice functions out of
616 : : TYPE_FIELDS and thus the origin will not be output
617 : : correctly. */
618 : 7304873 : if (DECL_ABSTRACT_ORIGIN (decl)
619 : 25585 : && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))
620 : 7330458 : && RECORD_OR_UNION_TYPE_P
621 : : (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))))
622 : 13497 : DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
623 : :
624 : 7304873 : DECL_VINDEX (decl) = NULL_TREE;
625 : : }
626 : : else if (VAR_P (decl))
627 : : {
628 : : /* See comment above why we set the flag for functions. */
629 : 792005 : if (TREE_PUBLIC (decl))
630 : 241391 : TREE_ADDRESSABLE (decl) = true;
631 : 792005 : if ((DECL_EXTERNAL (decl)
632 : 7686 : && (!TREE_STATIC (decl) || !TREE_READONLY (decl)))
633 : 796314 : || (decl_function_context (decl) && !TREE_STATIC (decl)))
634 : 526892 : DECL_INITIAL (decl) = NULL_TREE;
635 : : }
636 : : else if (TREE_CODE (decl) == TYPE_DECL)
637 : : {
638 : 387516 : DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
639 : 387516 : DECL_VISIBILITY_SPECIFIED (decl) = 0;
640 : 387516 : TREE_PUBLIC (decl) = 0;
641 : 387516 : TREE_PRIVATE (decl) = 0;
642 : 387516 : DECL_ARTIFICIAL (decl) = 0;
643 : 387516 : TYPE_DECL_SUPPRESS_DEBUG (decl) = 0;
644 : 387516 : DECL_INITIAL (decl) = NULL_TREE;
645 : 387516 : DECL_ORIGINAL_TYPE (decl) = NULL_TREE;
646 : 387516 : DECL_MODE (decl) = VOIDmode;
647 : 387516 : SET_DECL_ALIGN (decl, 0);
648 : : /* TREE_TYPE is cleared at WPA time in free_odr_warning_data. */
649 : : }
650 : : else if (TREE_CODE (decl) == FIELD_DECL)
651 : : {
652 : 262093 : TREE_TYPE (decl) = fld_simplified_type (TREE_TYPE (decl), fld);
653 : 262093 : DECL_INITIAL (decl) = NULL_TREE;
654 : : }
655 : : else if (TREE_CODE (decl) == TRANSLATION_UNIT_DECL
656 : 22793 : && DECL_INITIAL (decl)
657 : 19316 : && TREE_CODE (DECL_INITIAL (decl)) == BLOCK)
658 : : {
659 : : /* Strip builtins from the translation-unit BLOCK. We still have targets
660 : : without builtin_decl_explicit support and also builtins are shared
661 : : nodes and thus we can't use TREE_CHAIN in multiple lists. */
662 : 19316 : tree *nextp = &BLOCK_VARS (DECL_INITIAL (decl));
663 : 19316 : while (*nextp)
664 : : {
665 : 0 : tree var = *nextp;
666 : 0 : if (TREE_CODE (var) == FUNCTION_DECL
667 : 0 : && fndecl_built_in_p (var))
668 : 0 : *nextp = TREE_CHAIN (var);
669 : : else
670 : 0 : nextp = &TREE_CHAIN (var);
671 : : }
672 : : }
673 : : /* We need to keep field decls associated with their trees. Otherwise tree
674 : : merging may merge some fields and keep others disjoint which in turn will
675 : : not do well with TREE_CHAIN pointers linking them.
676 : :
677 : : Also do not drop containing types for virtual methods and tables because
678 : : these are needed by devirtualization.
679 : : C++ destructors are special because C++ frontends sometimes produces
680 : : virtual destructor as an alias of non-virtual destructor. In
681 : : devirutalization code we always walk through aliases and we need
682 : : context to be preserved too. See PR89335 */
683 : 9677272 : if (TREE_CODE (decl) != FIELD_DECL
684 : 9677272 : && ((TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
685 : 8096878 : || (!DECL_VIRTUAL_P (decl)
686 : 8085433 : && (TREE_CODE (decl) != FUNCTION_DECL
687 : 7299797 : || !DECL_CXX_DESTRUCTOR_P (decl)))))
688 : 9396144 : DECL_CONTEXT (decl) = fld_decl_context (DECL_CONTEXT (decl));
689 : 9677272 : }
690 : :
691 : :
692 : : /* Operand callback helper for free_lang_data_in_node. *TP is the
693 : : subtree operand being considered. */
694 : :
695 : : static tree
696 : 47503221 : find_decls_types_r (tree *tp, int *ws, void *data)
697 : : {
698 : 47503221 : tree t = *tp;
699 : 47503221 : class free_lang_data_d *fld = (class free_lang_data_d *) data;
700 : :
701 : 47503221 : if (TREE_CODE (t) == TREE_LIST)
702 : : return NULL_TREE;
703 : :
704 : : /* Language specific nodes will be removed, so there is no need
705 : : to gather anything under them. */
706 : 27184214 : if (is_lang_specific (t))
707 : : {
708 : 15 : *ws = 0;
709 : 15 : return NULL_TREE;
710 : : }
711 : :
712 : 27184199 : if (DECL_P (t))
713 : : {
714 : : /* Note that walk_tree does not traverse every possible field in
715 : : decls, so we have to do our own traversals here. */
716 : 9677272 : add_tree_to_fld_list (t, fld);
717 : :
718 : 9677272 : fld_worklist_push (DECL_NAME (t), fld);
719 : 9677272 : fld_worklist_push (DECL_CONTEXT (t), fld);
720 : 9677272 : fld_worklist_push (DECL_SIZE (t), fld);
721 : 9677272 : fld_worklist_push (DECL_SIZE_UNIT (t), fld);
722 : :
723 : : /* We are going to remove everything under DECL_INITIAL for
724 : : TYPE_DECLs. No point walking them. */
725 : 9677272 : if (TREE_CODE (t) != TYPE_DECL)
726 : 9289756 : fld_worklist_push (DECL_INITIAL (t), fld);
727 : :
728 : 9677272 : fld_worklist_push (DECL_ATTRIBUTES (t), fld);
729 : 9677272 : fld_worklist_push (DECL_ABSTRACT_ORIGIN (t), fld);
730 : :
731 : 9677272 : if (TREE_CODE (t) == FUNCTION_DECL)
732 : : {
733 : 7304873 : fld_worklist_push (DECL_ARGUMENTS (t), fld);
734 : 7304873 : fld_worklist_push (DECL_RESULT (t), fld);
735 : : }
736 : 2372399 : else if (TREE_CODE (t) == FIELD_DECL)
737 : : {
738 : 262093 : fld_worklist_push (DECL_FIELD_OFFSET (t), fld);
739 : 262093 : fld_worklist_push (DECL_BIT_FIELD_TYPE (t), fld);
740 : 262093 : fld_worklist_push (DECL_FIELD_BIT_OFFSET (t), fld);
741 : 262093 : fld_worklist_push (DECL_FCONTEXT (t), fld);
742 : : }
743 : :
744 : 9677272 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
745 : 9677272 : && DECL_HAS_VALUE_EXPR_P (t))
746 : 5995 : fld_worklist_push (DECL_VALUE_EXPR (t), fld);
747 : :
748 : 9677272 : if (TREE_CODE (t) != FIELD_DECL
749 : 9677272 : && TREE_CODE (t) != TYPE_DECL)
750 : 9027663 : fld_worklist_push (TREE_CHAIN (t), fld);
751 : 9677272 : *ws = 0;
752 : : }
753 : 17506927 : else if (TYPE_P (t))
754 : : {
755 : : /* Note that walk_tree does not traverse every possible field in
756 : : types, so we have to do our own traversals here. */
757 : 3673240 : add_tree_to_fld_list (t, fld);
758 : :
759 : 3673240 : if (!RECORD_OR_UNION_TYPE_P (t))
760 : 3542164 : fld_worklist_push (TYPE_CACHED_VALUES (t), fld);
761 : 3673240 : fld_worklist_push (TYPE_SIZE (t), fld);
762 : 3673240 : fld_worklist_push (TYPE_SIZE_UNIT (t), fld);
763 : 3673240 : fld_worklist_push (TYPE_ATTRIBUTES (t), fld);
764 : 3673240 : fld_worklist_push (TYPE_POINTER_TO (t), fld);
765 : 3673240 : fld_worklist_push (TYPE_REFERENCE_TO (t), fld);
766 : 3673240 : fld_worklist_push (TYPE_NAME (t), fld);
767 : : /* While we do not stream TYPE_POINTER_TO and TYPE_REFERENCE_TO
768 : : lists, we may look types up in these lists and use them while
769 : : optimizing the function body. Thus we need to free lang data
770 : : in them. */
771 : 3673240 : if (TREE_CODE (t) == POINTER_TYPE)
772 : 610570 : fld_worklist_push (TYPE_NEXT_PTR_TO (t), fld);
773 : 3673240 : if (TREE_CODE (t) == REFERENCE_TYPE)
774 : 43035 : fld_worklist_push (TYPE_NEXT_REF_TO (t), fld);
775 : 3673240 : if (!POINTER_TYPE_P (t))
776 : 3019635 : fld_worklist_push (TYPE_MIN_VALUE_RAW (t), fld);
777 : : /* TYPE_MAX_VALUE_RAW is TYPE_BINFO for record types. */
778 : 3673240 : if (!RECORD_OR_UNION_TYPE_P (t))
779 : 3542164 : fld_worklist_push (TYPE_MAX_VALUE_RAW (t), fld);
780 : 3673240 : fld_worklist_push (TYPE_MAIN_VARIANT (t), fld);
781 : : /* Do not walk TYPE_NEXT_VARIANT. We do not stream it and thus
782 : : do not and want not to reach unused variants this way. */
783 : 3673240 : if (TYPE_CONTEXT (t))
784 : : {
785 : 33868 : tree ctx = TYPE_CONTEXT (t);
786 : : /* We adjust BLOCK TYPE_CONTEXTs to the innermost non-BLOCK one.
787 : : So push that instead. */
788 : 33868 : while (ctx && TREE_CODE (ctx) == BLOCK)
789 : 0 : ctx = BLOCK_SUPERCONTEXT (ctx);
790 : 33868 : fld_worklist_push (ctx, fld);
791 : : }
792 : 3673240 : fld_worklist_push (TYPE_CANONICAL (t), fld);
793 : :
794 : 3673240 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t))
795 : : {
796 : : unsigned i;
797 : : tree tem;
798 : 41951 : FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t)), i, tem)
799 : 9634 : fld_worklist_push (TREE_TYPE (tem), fld);
800 : 32317 : fld_worklist_push (BINFO_TYPE (TYPE_BINFO (t)), fld);
801 : 32317 : fld_worklist_push (BINFO_VTABLE (TYPE_BINFO (t)), fld);
802 : : }
803 : 3673240 : if (RECORD_OR_UNION_TYPE_P (t))
804 : : {
805 : 131076 : tree tem;
806 : : /* Push all TYPE_FIELDS - there can be interleaving interesting
807 : : and non-interesting things. */
808 : 131076 : tem = TYPE_FIELDS (t);
809 : 1080885 : while (tem)
810 : : {
811 : 949809 : if (TREE_CODE (tem) == FIELD_DECL)
812 : 359307 : fld_worklist_push (tem, fld);
813 : 949809 : tem = TREE_CHAIN (tem);
814 : : }
815 : : }
816 : 3673240 : if (FUNC_OR_METHOD_TYPE_P (t))
817 : 2420765 : fld_worklist_push (TYPE_METHOD_BASETYPE (t), fld);
818 : :
819 : 3673240 : fld_worklist_push (TYPE_STUB_DECL (t), fld);
820 : 3673240 : *ws = 0;
821 : : }
822 : 13833687 : else if (TREE_CODE (t) == BLOCK)
823 : : {
824 : 981151 : for (tree *tem = &BLOCK_VARS (t); *tem; )
825 : : {
826 : 787662 : if (TREE_CODE (*tem) != LABEL_DECL
827 : 787662 : && (TREE_CODE (*tem) != VAR_DECL
828 : 372442 : || !auto_var_in_fn_p (*tem, DECL_CONTEXT (*tem))))
829 : : {
830 : 433294 : gcc_assert (TREE_CODE (*tem) != RESULT_DECL
831 : : && TREE_CODE (*tem) != PARM_DECL);
832 : 433294 : *tem = TREE_CHAIN (*tem);
833 : : }
834 : : else
835 : : {
836 : 354368 : fld_worklist_push (*tem, fld);
837 : 354368 : tem = &TREE_CHAIN (*tem);
838 : : }
839 : : }
840 : 236242 : for (tree tem = BLOCK_SUBBLOCKS (t); tem; tem = BLOCK_CHAIN (tem))
841 : 42753 : fld_worklist_push (tem, fld);
842 : 193489 : fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t), fld);
843 : : }
844 : : /* walk_tree does not visit ce->index which can be a FIELD_DECL, pulling
845 : : in otherwise unused structure fields so handle CTORs explicitly. */
846 : 13640198 : else if (TREE_CODE (t) == CONSTRUCTOR)
847 : : {
848 : : unsigned HOST_WIDE_INT idx;
849 : : constructor_elt *ce;
850 : 1332940 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce); idx++)
851 : : {
852 : 1053462 : if (ce->index)
853 : 459650 : fld_worklist_push (ce->index, fld);
854 : 1053462 : fld_worklist_push (ce->value, fld);
855 : : }
856 : 279478 : *ws = 0;
857 : : }
858 : :
859 : 27184199 : if (TREE_CODE (t) != IDENTIFIER_NODE
860 : 18467783 : && CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPED))
861 : 18274294 : fld_worklist_push (TREE_TYPE (t), fld);
862 : :
863 : : return NULL_TREE;
864 : : }
865 : :
866 : :
867 : : /* Find decls and types in T. */
868 : :
869 : : static void
870 : 8081446 : find_decls_types (tree t, class free_lang_data_d *fld)
871 : : {
872 : 80081410 : while (1)
873 : : {
874 : 44081428 : if (!fld->pset.contains (t))
875 : 35471080 : walk_tree (&t, find_decls_types_r, fld, &fld->pset);
876 : 44081428 : if (fld->worklist.is_empty ())
877 : : break;
878 : 35999982 : t = fld->worklist.pop ();
879 : : }
880 : 8081446 : }
881 : :
882 : : /* Translate all the types in LIST with the corresponding runtime
883 : : types. */
884 : :
885 : : static tree
886 : 754 : get_eh_types_for_runtime (tree list)
887 : : {
888 : 754 : tree head, prev;
889 : :
890 : 754 : if (list == NULL_TREE)
891 : : return NULL_TREE;
892 : :
893 : 148 : head = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
894 : 148 : prev = head;
895 : 148 : list = TREE_CHAIN (list);
896 : 148 : while (list)
897 : : {
898 : 0 : tree n = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
899 : 0 : TREE_CHAIN (prev) = n;
900 : 0 : prev = TREE_CHAIN (prev);
901 : 0 : list = TREE_CHAIN (list);
902 : : }
903 : :
904 : : return head;
905 : : }
906 : :
907 : :
908 : : /* Find decls and types referenced in EH region R and store them in
909 : : FLD->DECLS and FLD->TYPES. */
910 : :
911 : : static void
912 : 35916 : find_decls_types_in_eh_region (eh_region r, class free_lang_data_d *fld)
913 : : {
914 : 35916 : switch (r->type)
915 : : {
916 : : case ERT_CLEANUP:
917 : : break;
918 : :
919 : 832 : case ERT_TRY:
920 : 832 : {
921 : 832 : eh_catch c;
922 : :
923 : : /* The types referenced in each catch must first be changed to the
924 : : EH types used at runtime. This removes references to FE types
925 : : in the region. */
926 : 1419 : for (c = r->u.eh_try.first_catch; c ; c = c->next_catch)
927 : : {
928 : 587 : c->type_list = get_eh_types_for_runtime (c->type_list);
929 : 587 : walk_tree (&c->type_list, find_decls_types_r, fld, &fld->pset);
930 : : }
931 : : }
932 : : break;
933 : :
934 : 167 : case ERT_ALLOWED_EXCEPTIONS:
935 : 167 : r->u.allowed.type_list
936 : 167 : = get_eh_types_for_runtime (r->u.allowed.type_list);
937 : 167 : walk_tree (&r->u.allowed.type_list, find_decls_types_r, fld, &fld->pset);
938 : 167 : break;
939 : :
940 : 13588 : case ERT_MUST_NOT_THROW:
941 : 13588 : walk_tree (&r->u.must_not_throw.failure_decl,
942 : : find_decls_types_r, fld, &fld->pset);
943 : 13588 : break;
944 : : }
945 : 35916 : }
946 : :
947 : :
948 : : /* Find decls and types referenced in cgraph node N and store them in
949 : : FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
950 : : look for *every* kind of DECL and TYPE node reachable from N,
951 : : including those embedded inside types and decls (i.e,, TYPE_DECLs,
952 : : NAMESPACE_DECLs, etc). */
953 : :
954 : : static void
955 : 360919 : find_decls_types_in_node (struct cgraph_node *n, class free_lang_data_d *fld)
956 : : {
957 : 360919 : basic_block bb;
958 : 360919 : struct function *fn;
959 : 360919 : unsigned ix;
960 : 360919 : tree t;
961 : :
962 : 360919 : find_decls_types (n->decl, fld);
963 : :
964 : 360919 : if (!gimple_has_body_p (n->decl))
965 : 360919 : return;
966 : :
967 : 118491 : gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
968 : :
969 : 118491 : fn = DECL_STRUCT_FUNCTION (n->decl);
970 : :
971 : : /* Traverse locals. */
972 : 749888 : FOR_EACH_LOCAL_DECL (fn, ix, t)
973 : 543881 : find_decls_types (t, fld);
974 : :
975 : : /* Traverse EH regions in FN. */
976 : 118491 : {
977 : 118491 : eh_region r;
978 : 154407 : FOR_ALL_EH_REGION_FN (r, fn)
979 : 35916 : find_decls_types_in_eh_region (r, fld);
980 : : }
981 : :
982 : : /* Traverse every statement in FN. */
983 : 848330 : FOR_EACH_BB_FN (bb, fn)
984 : : {
985 : 729839 : gphi_iterator psi;
986 : 729839 : gimple_stmt_iterator si;
987 : 729839 : unsigned i;
988 : :
989 : 729881 : for (psi = gsi_start_phis (bb); !gsi_end_p (psi); gsi_next (&psi))
990 : : {
991 : 42 : gphi *phi = psi.phi ();
992 : :
993 : 122 : for (i = 0; i < gimple_phi_num_args (phi); i++)
994 : : {
995 : 80 : tree *arg_p = gimple_phi_arg_def_ptr (phi, i);
996 : 80 : find_decls_types (*arg_p, fld);
997 : : }
998 : : }
999 : :
1000 : 3670058 : for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
1001 : : {
1002 : 2210380 : gimple *stmt = gsi_stmt (si);
1003 : :
1004 : 2210380 : if (is_gimple_call (stmt))
1005 : 510847 : find_decls_types (gimple_call_fntype (stmt), fld);
1006 : :
1007 : 8600065 : for (i = 0; i < gimple_num_ops (stmt); i++)
1008 : : {
1009 : 6389685 : tree arg = gimple_op (stmt, i);
1010 : 6389685 : find_decls_types (arg, fld);
1011 : : /* find_decls_types doesn't walk TREE_PURPOSE of TREE_LISTs,
1012 : : which we need for asm stmts. */
1013 : 6389685 : if (arg
1014 : 4785863 : && TREE_CODE (arg) == TREE_LIST
1015 : 17648 : && TREE_PURPOSE (arg)
1016 : 6406027 : && gimple_code (stmt) == GIMPLE_ASM)
1017 : 16342 : find_decls_types (TREE_PURPOSE (arg), fld);
1018 : : }
1019 : : }
1020 : : }
1021 : : }
1022 : :
1023 : :
1024 : : /* Find decls and types referenced in varpool node N and store them in
1025 : : FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
1026 : : look for *every* kind of DECL and TYPE node reachable from N,
1027 : : including those embedded inside types and decls (i.e,, TYPE_DECLs,
1028 : : NAMESPACE_DECLs, etc). */
1029 : :
1030 : : static void
1031 : 259692 : find_decls_types_in_var (varpool_node *v, class free_lang_data_d *fld)
1032 : : {
1033 : 0 : find_decls_types (v->decl, fld);
1034 : 0 : }
1035 : :
1036 : : /* Free language specific information for every operand and expression
1037 : : in every node of the call graph. This process operates in three stages:
1038 : :
1039 : : 1- Every callgraph node and varpool node is traversed looking for
1040 : : decls and types embedded in them. This is a more exhaustive
1041 : : search than that done by find_referenced_vars, because it will
1042 : : also collect individual fields, decls embedded in types, etc.
1043 : :
1044 : : 2- All the decls found are sent to free_lang_data_in_decl.
1045 : :
1046 : : 3- All the types found are sent to free_lang_data_in_type.
1047 : :
1048 : : The ordering between decls and types is important because
1049 : : free_lang_data_in_decl sets assembler names, which includes
1050 : : mangling. So types cannot be freed up until assembler names have
1051 : : been set up. */
1052 : :
1053 : : static void
1054 : 23922 : free_lang_data_in_cgraph (class free_lang_data_d *fld)
1055 : : {
1056 : 23922 : struct cgraph_node *n;
1057 : 23922 : varpool_node *v;
1058 : 23922 : tree t;
1059 : 23922 : unsigned i;
1060 : 23922 : alias_pair *p;
1061 : :
1062 : : /* Find decls and types in the body of every function in the callgraph. */
1063 : 769682 : FOR_EACH_FUNCTION (n)
1064 : 360919 : find_decls_types_in_node (n, fld);
1065 : :
1066 : 23922 : FOR_EACH_VEC_SAFE_ELT (alias_pairs, i, p)
1067 : 0 : find_decls_types (p->decl, fld);
1068 : :
1069 : : /* Find decls and types in every varpool symbol. */
1070 : 307536 : FOR_EACH_VARIABLE (v)
1071 : 259692 : find_decls_types_in_var (v, fld);
1072 : :
1073 : : /* Set the assembler name on every decl found. We need to do this
1074 : : now because free_lang_data_in_decl will invalidate data needed
1075 : : for mangling. This breaks mangling on interdependent decls. */
1076 : 9701194 : FOR_EACH_VEC_ELT (fld->decls, i, t)
1077 : 9677272 : assign_assembler_name_if_needed (t);
1078 : :
1079 : : /* Traverse every decl found freeing its language data. */
1080 : 9701194 : FOR_EACH_VEC_ELT (fld->decls, i, t)
1081 : 9677272 : free_lang_data_in_decl (t, fld);
1082 : :
1083 : : /* Traverse every type found freeing its language data. */
1084 : 3828463 : FOR_EACH_VEC_ELT (fld->types, i, t)
1085 : 3804541 : free_lang_data_in_type (t, fld);
1086 : 23922 : }
1087 : :
1088 : :
1089 : : /* Free resources that are used by FE but are not needed once they are done. */
1090 : :
1091 : : static unsigned
1092 : 227253 : free_lang_data (void)
1093 : : {
1094 : 227253 : unsigned i;
1095 : 227253 : class free_lang_data_d fld;
1096 : :
1097 : : /* If we are the LTO frontend we have freed lang-specific data already. */
1098 : 227253 : if (in_lto_p
1099 : 227253 : || (!flag_generate_lto && !flag_generate_offload))
1100 : : {
1101 : : /* Rebuild type inheritance graph even when not doing LTO to get
1102 : : consistent profile data. */
1103 : 203331 : rebuild_type_inheritance_graph ();
1104 : 203331 : return 0;
1105 : : }
1106 : :
1107 : 23922 : fld_incomplete_types = new hash_map<tree, tree>;
1108 : 23922 : fld_simplified_types = new hash_map<tree, tree>;
1109 : :
1110 : : /* Provide a dummy TRANSLATION_UNIT_DECL if the FE failed to provide one. */
1111 : 23922 : if (vec_safe_is_empty (all_translation_units))
1112 : 901 : build_translation_unit_decl (NULL_TREE);
1113 : :
1114 : : /* Allocate and assign alias sets to the standard integer types
1115 : : while the slots are still in the way the frontends generated them. */
1116 : 478440 : for (i = 0; i < itk_none; ++i)
1117 : 454518 : if (integer_types[i])
1118 : 310986 : TYPE_ALIAS_SET (integer_types[i]) = get_alias_set (integer_types[i]);
1119 : :
1120 : : /* Traverse the IL resetting language specific information for
1121 : : operands, expressions, etc. */
1122 : 23922 : free_lang_data_in_cgraph (&fld);
1123 : :
1124 : : /* Create gimple variants for common types. */
1125 : 167454 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
1126 : 143532 : builtin_structptr_types[i].node = builtin_structptr_types[i].base;
1127 : :
1128 : : /* Reset some langhooks. Do not reset types_compatible_p, it may
1129 : : still be used indirectly via the get_alias_set langhook. */
1130 : 23922 : lang_hooks.dwarf_name = lhd_dwarf_name;
1131 : 23922 : lang_hooks.decl_printable_name = gimple_decl_printable_name;
1132 : 23922 : lang_hooks.gimplify_expr = lhd_gimplify_expr;
1133 : 23922 : lang_hooks.overwrite_decl_assembler_name = lhd_overwrite_decl_assembler_name;
1134 : 23922 : lang_hooks.print_xnode = lhd_print_tree_nothing;
1135 : 23922 : lang_hooks.print_decl = lhd_print_tree_nothing;
1136 : 23922 : lang_hooks.print_type = lhd_print_tree_nothing;
1137 : 23922 : lang_hooks.print_identifier = lhd_print_tree_nothing;
1138 : :
1139 : 23922 : lang_hooks.tree_inlining.var_mod_type_p = hook_bool_tree_tree_false;
1140 : :
1141 : 23922 : if (flag_checking)
1142 : : {
1143 : : int i;
1144 : : tree t;
1145 : :
1146 : 3828355 : FOR_EACH_VEC_ELT (fld.types, i, t)
1147 : 3804439 : verify_type (t);
1148 : : }
1149 : :
1150 : : /* We do not want the default decl_assembler_name implementation,
1151 : : rather if we have fixed everything we want a wrapper around it
1152 : : asserting that all non-local symbols already got their assembler
1153 : : name and only produce assembler names for local symbols. Or rather
1154 : : make sure we never call decl_assembler_name on local symbols and
1155 : : devise a separate, middle-end private scheme for it. */
1156 : :
1157 : : /* Reset diagnostic machinery. */
1158 : 23922 : tree_diagnostics_defaults (global_dc);
1159 : :
1160 : 23922 : rebuild_type_inheritance_graph ();
1161 : :
1162 : 47844 : delete fld_incomplete_types;
1163 : 47844 : delete fld_simplified_types;
1164 : :
1165 : : return 0;
1166 : 227253 : }
1167 : :
1168 : : const pass_data pass_data_ipa_free_lang_data =
1169 : : {
1170 : : SIMPLE_IPA_PASS, /* type */
1171 : : "*free_lang_data", /* name */
1172 : : OPTGROUP_NONE, /* optinfo_flags */
1173 : : TV_IPA_FREE_LANG_DATA, /* tv_id */
1174 : : 0, /* properties_required */
1175 : : 0, /* properties_provided */
1176 : : 0, /* properties_destroyed */
1177 : : 0, /* todo_flags_start */
1178 : : 0, /* todo_flags_finish */
1179 : : };
1180 : :
1181 : : class pass_ipa_free_lang_data : public simple_ipa_opt_pass
1182 : : {
1183 : : public:
1184 : 282866 : pass_ipa_free_lang_data (gcc::context *ctxt)
1185 : 565732 : : simple_ipa_opt_pass (pass_data_ipa_free_lang_data, ctxt)
1186 : : {}
1187 : :
1188 : : /* opt_pass methods: */
1189 : 227253 : unsigned int execute (function *) final override { return free_lang_data (); }
1190 : :
1191 : : }; // class pass_ipa_free_lang_data
1192 : :
1193 : : } // anon namespace
1194 : :
1195 : : simple_ipa_opt_pass *
1196 : 282866 : make_pass_ipa_free_lang_data (gcc::context *ctxt)
1197 : : {
1198 : 282866 : return new pass_ipa_free_lang_data (ctxt);
1199 : : }
|