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 : 230197 : 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 : 2835311 : add_tree_to_fld_list (tree t, class free_lang_data_d *fld)
80 : : {
81 : 2835311 : if (DECL_P (t))
82 : 1988965 : fld->decls.safe_push (t);
83 : 846346 : else if (TYPE_P (t))
84 : 846346 : fld->types.safe_push (t);
85 : : else
86 : 0 : gcc_unreachable ();
87 : 2835311 : }
88 : :
89 : : /* Push tree node T into FLD->WORKLIST. */
90 : :
91 : : static inline void
92 : 33769993 : fld_worklist_push (tree t, class free_lang_data_d *fld)
93 : : {
94 : 54395637 : if (t && !is_lang_specific (t) && !fld->pset.contains (t))
95 : 5348933 : fld->worklist.safe_push ((t));
96 : 33769993 : }
97 : :
98 : :
99 : :
100 : : /* Return simplified TYPE_NAME of TYPE. */
101 : :
102 : : static tree
103 : 1026319 : fld_simplified_type_name (tree type)
104 : : {
105 : 1026319 : if (!TYPE_NAME (type) || TREE_CODE (TYPE_NAME (type)) != TYPE_DECL)
106 : 824340 : 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 : 201979 : if (type != TYPE_MAIN_VARIANT (type)
111 : 201979 : || (!DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (type))
112 : 82154 : && (TREE_CODE (type) != RECORD_TYPE
113 : 7767 : || !TYPE_BINFO (type)
114 : 0 : || !BINFO_VTABLE (TYPE_BINFO (type)))))
115 : 158248 : return DECL_NAME (TYPE_NAME (type));
116 : 43731 : 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 : 99731 : fld_type_variant_equal_p (tree t, tree v, tree inner_type)
126 : : {
127 : 99731 : 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 : 83592 : || ((!RECORD_OR_UNION_TYPE_P (t) || COMPLETE_TYPE_P (v))
131 : 61818 : && (TYPE_ALIGN (t) != TYPE_ALIGN (v)
132 : 61806 : || TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (v)))
133 : 83580 : || fld_simplified_type_name (t) != fld_simplified_type_name (v)
134 : 69833 : || !attribute_list_equal (TYPE_ATTRIBUTES (t),
135 : 69833 : TYPE_ATTRIBUTES (v))
136 : 169564 : || (inner_type && TREE_TYPE (v) != inner_type))
137 : 29898 : 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 : 69833 : fld_type_variant (tree first, tree t, class free_lang_data_d *fld,
147 : : tree inner_type = NULL)
148 : : {
149 : 69833 : if (first == TYPE_MAIN_VARIANT (t))
150 : : return t;
151 : 91722 : for (tree v = first; v; v = TYPE_NEXT_VARIANT (v))
152 : 85166 : if (fld_type_variant_equal_p (t, v, inner_type))
153 : : {
154 : 63277 : if (flag_checking)
155 : 71286 : for (tree v2 = TYPE_NEXT_VARIANT (v); v2; v2 = TYPE_NEXT_VARIANT (v2))
156 : 8009 : gcc_assert (!fld_type_variant_equal_p (t, v2, inner_type));
157 : 63277 : return v;
158 : : }
159 : 6556 : tree v = build_variant_type_copy (first);
160 : 6556 : TYPE_READONLY (v) = TYPE_READONLY (t);
161 : 6556 : TYPE_VOLATILE (v) = TYPE_VOLATILE (t);
162 : 6556 : TYPE_ATOMIC (v) = TYPE_ATOMIC (t);
163 : 6556 : TYPE_RESTRICT (v) = TYPE_RESTRICT (t);
164 : 6556 : TYPE_ADDR_SPACE (v) = TYPE_ADDR_SPACE (t);
165 : 6556 : TYPE_NAME (v) = TYPE_NAME (t);
166 : 6556 : TYPE_ATTRIBUTES (v) = TYPE_ATTRIBUTES (t);
167 : 6556 : TYPE_CANONICAL (v) = TYPE_CANONICAL (t);
168 : : /* Variants of incomplete types should have alignment
169 : : set to BITS_PER_UNIT. Do not copy the actual alignment. */
170 : 6556 : if (!RECORD_OR_UNION_TYPE_P (v) || COMPLETE_TYPE_P (v))
171 : : {
172 : 1523 : SET_TYPE_ALIGN (v, TYPE_ALIGN (t));
173 : 1523 : TYPE_USER_ALIGN (v) = TYPE_USER_ALIGN (t);
174 : : }
175 : 6556 : if (inner_type)
176 : 18 : TREE_TYPE (v) = inner_type;
177 : 6556 : gcc_checking_assert (fld_type_variant_equal_p (t,v, inner_type));
178 : 6556 : if (!fld->pset.add (v))
179 : 6556 : add_tree_to_fld_list (v, fld);
180 : : return v;
181 : : }
182 : :
183 : : /* Map complete types to incomplete types. */
184 : :
185 : : static hash_map<tree, tree> *fld_incomplete_types;
186 : :
187 : : /* Map types to simplified types. */
188 : :
189 : : static hash_map<tree, tree> *fld_simplified_types;
190 : :
191 : : /* Produce variant of T whose TREE_TYPE is T2. If it is main variant,
192 : : use MAP to prevent duplicates. */
193 : :
194 : : static tree
195 : 2839 : fld_process_array_type (tree t, tree t2, hash_map<tree, tree> *map,
196 : : class free_lang_data_d *fld)
197 : : {
198 : 2839 : if (TREE_TYPE (t) == t2)
199 : : return t;
200 : :
201 : 100 : if (TYPE_MAIN_VARIANT (t) != t)
202 : : {
203 : 18 : return fld_type_variant
204 : 18 : (fld_process_array_type (TYPE_MAIN_VARIANT (t),
205 : 18 : TYPE_MAIN_VARIANT (t2), map, fld),
206 : 18 : t, fld, t2);
207 : : }
208 : :
209 : 82 : bool existed;
210 : 82 : tree &array
211 : 82 : = map->get_or_insert (t, &existed);
212 : 82 : if (!existed)
213 : : {
214 : 27 : array
215 : 27 : = build_array_type_1 (t2, TYPE_DOMAIN (t), TYPE_TYPELESS_STORAGE (t),
216 : : false, false);
217 : 27 : TYPE_CANONICAL (array) = TYPE_CANONICAL (t);
218 : 27 : if (!fld->pset.add (array))
219 : 27 : add_tree_to_fld_list (array, fld);
220 : : }
221 : 82 : return array;
222 : : }
223 : :
224 : : /* Return CTX after removal of contexts that are not relevant */
225 : :
226 : : static tree
227 : 1888492 : fld_decl_context (tree ctx)
228 : : {
229 : : /* Variably modified types are needed for tree_is_indexable to decide
230 : : whether the type needs to go to local or global section.
231 : : This code is semi-broken but for now it is easiest to keep contexts
232 : : as expected. */
233 : 1746031 : if (ctx && TYPE_P (ctx)
234 : 1923693 : && !variably_modified_type_p (ctx, NULL_TREE))
235 : : {
236 : 75416 : while (ctx && TYPE_P (ctx))
237 : 40215 : ctx = TYPE_CONTEXT (ctx);
238 : : }
239 : 1888492 : return ctx;
240 : : }
241 : :
242 : : /* For T being aggregate type try to turn it into an incomplete variant.
243 : : Return T if no simplification is possible. */
244 : :
245 : : static tree
246 : 339499 : fld_incomplete_type_of (tree t, class free_lang_data_d *fld)
247 : : {
248 : 339499 : if (!t)
249 : : return NULL;
250 : 339499 : if (POINTER_TYPE_P (t))
251 : : {
252 : 164573 : tree t2 = fld_incomplete_type_of (TREE_TYPE (t), fld);
253 : 164573 : if (t2 != TREE_TYPE (t))
254 : : {
255 : 55014 : tree first;
256 : 55014 : if (TREE_CODE (t) == POINTER_TYPE)
257 : 44719 : first = build_pointer_type_for_mode (t2, TYPE_MODE (t),
258 : 44719 : TYPE_REF_CAN_ALIAS_ALL (t));
259 : : else
260 : 10295 : first = build_reference_type_for_mode (t2, TYPE_MODE (t),
261 : 10295 : TYPE_REF_CAN_ALIAS_ALL (t));
262 : 55014 : gcc_assert (TYPE_CANONICAL (t2) != t2
263 : : && TYPE_CANONICAL (t2) == TYPE_CANONICAL (TREE_TYPE (t)));
264 : 55014 : if (!fld->pset.add (first))
265 : 18761 : add_tree_to_fld_list (first, fld);
266 : 55014 : return fld_type_variant (first, t, fld);
267 : : }
268 : : return t;
269 : : }
270 : 174926 : if (TREE_CODE (t) == ARRAY_TYPE)
271 : 2821 : return fld_process_array_type (t,
272 : 2821 : fld_incomplete_type_of (TREE_TYPE (t), fld),
273 : 2821 : fld_incomplete_types, fld);
274 : 172105 : if ((!RECORD_OR_UNION_TYPE_P (t) && TREE_CODE (t) != ENUMERAL_TYPE)
275 : 172105 : || !COMPLETE_TYPE_P (t))
276 : : return t;
277 : 68215 : if (TYPE_MAIN_VARIANT (t) == t)
278 : : {
279 : 53414 : bool existed;
280 : 53414 : tree ©
281 : 53414 : = fld_incomplete_types->get_or_insert (t, &existed);
282 : :
283 : 53414 : if (!existed)
284 : : {
285 : 12696 : copy = build_distinct_type_copy (t);
286 : :
287 : : /* It is possible that type was not seen by free_lang_data yet. */
288 : 12696 : if (!fld->pset.add (copy))
289 : 12696 : add_tree_to_fld_list (copy, fld);
290 : 12696 : TYPE_SIZE (copy) = NULL;
291 : 12696 : TYPE_USER_ALIGN (copy) = 0;
292 : 12696 : TYPE_SIZE_UNIT (copy) = NULL;
293 : 12696 : TYPE_CANONICAL (copy) = TYPE_CANONICAL (t);
294 : 12696 : TREE_ADDRESSABLE (copy) = 0;
295 : 12696 : if (AGGREGATE_TYPE_P (t))
296 : : {
297 : 12626 : SET_TYPE_MODE (copy, VOIDmode);
298 : 12626 : SET_TYPE_ALIGN (copy, BITS_PER_UNIT);
299 : 12626 : TYPE_TYPELESS_STORAGE (copy) = 0;
300 : 12626 : TYPE_FIELDS (copy) = NULL;
301 : 12626 : TYPE_BINFO (copy) = NULL;
302 : 12626 : TYPE_FINAL_P (copy) = 0;
303 : 12626 : TYPE_EMPTY_P (copy) = 0;
304 : : }
305 : : else
306 : : {
307 : 70 : TYPE_VALUES (copy) = NULL;
308 : 70 : ENUM_IS_OPAQUE (copy) = 0;
309 : 70 : ENUM_IS_SCOPED (copy) = 0;
310 : : }
311 : :
312 : : /* Build copy of TYPE_DECL in TYPE_NAME if necessary.
313 : : This is needed for ODR violation warnings to come out right (we
314 : : want duplicate TYPE_DECLs whenever the type is duplicated because
315 : : of ODR violation. Because lang data in the TYPE_DECL may not
316 : : have been freed yet, rebuild it from scratch and copy relevant
317 : : fields. */
318 : 12696 : TYPE_NAME (copy) = fld_simplified_type_name (copy);
319 : 12696 : tree name = TYPE_NAME (copy);
320 : :
321 : 12696 : if (name && TREE_CODE (name) == TYPE_DECL)
322 : : {
323 : 8397 : gcc_checking_assert (TREE_TYPE (name) == t);
324 : 8397 : tree name2 = build_decl (DECL_SOURCE_LOCATION (name), TYPE_DECL,
325 : 8397 : DECL_NAME (name), copy);
326 : 8397 : if (DECL_ASSEMBLER_NAME_SET_P (name))
327 : 8397 : SET_DECL_ASSEMBLER_NAME (name2, DECL_ASSEMBLER_NAME (name));
328 : 8397 : SET_DECL_ALIGN (name2, 0);
329 : 8397 : DECL_CONTEXT (name2) = fld_decl_context
330 : 8397 : (DECL_CONTEXT (name));
331 : 8397 : TYPE_NAME (copy) = name2;
332 : : }
333 : : }
334 : 53414 : return copy;
335 : : }
336 : 14801 : return (fld_type_variant
337 : 14801 : (fld_incomplete_type_of (TYPE_MAIN_VARIANT (t), fld), t, fld));
338 : : }
339 : :
340 : : /* Simplify type T for scenarios where we do not need complete pointer
341 : : types. */
342 : :
343 : : static tree
344 : 1168716 : fld_simplified_type (tree t, class free_lang_data_d *fld)
345 : : {
346 : 1168716 : if (!t)
347 : : return t;
348 : 1168716 : if (POINTER_TYPE_P (t))
349 : 157304 : return fld_incomplete_type_of (t, fld);
350 : : /* FIXME: This triggers verification error, see PR88140. */
351 : : #if 0
352 : : if (TREE_CODE (t) == ARRAY_TYPE)
353 : : return fld_process_array_type (t, fld_simplified_type (TREE_TYPE (t), fld),
354 : : fld_simplified_types, fld);
355 : : #endif
356 : : return t;
357 : : }
358 : :
359 : : /* Reset the expression *EXPR_P, a size or position.
360 : :
361 : : ??? We could reset all non-constant sizes or positions. But it's cheap
362 : : enough to not do so and refrain from adding workarounds to dwarf2out.cc.
363 : :
364 : : We need to reset self-referential sizes or positions because they cannot
365 : : be gimplified and thus can contain a CALL_EXPR after the gimplification
366 : : is finished, which will run afoul of LTO streaming. And they need to be
367 : : reset to something essentially dummy but not constant, so as to preserve
368 : : the properties of the object they are attached to. */
369 : :
370 : : static inline void
371 : 6068921 : free_lang_data_in_one_sizepos (tree *expr_p)
372 : : {
373 : 6068921 : tree expr = *expr_p;
374 : 6068921 : if (CONTAINS_PLACEHOLDER_P (expr))
375 : 0 : *expr_p = build0 (PLACEHOLDER_EXPR, TREE_TYPE (expr));
376 : 6068921 : }
377 : :
378 : :
379 : : /* Reset all the fields in a binfo node BINFO. We only keep
380 : : BINFO_VTABLE, which is used by gimple_fold_obj_type_ref. */
381 : :
382 : : static void
383 : 37962 : free_lang_data_in_binfo (tree binfo)
384 : : {
385 : 37962 : unsigned i;
386 : 37962 : tree t;
387 : :
388 : 37962 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
389 : :
390 : 37962 : BINFO_VIRTUALS (binfo) = NULL_TREE;
391 : 37962 : BINFO_BASE_ACCESSES (binfo) = NULL;
392 : 37962 : BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE;
393 : 37962 : BINFO_SUBVTT_INDEX (binfo) = NULL_TREE;
394 : 37962 : BINFO_VPTR_FIELD (binfo) = NULL_TREE;
395 : 37962 : TREE_PUBLIC (binfo) = 0;
396 : :
397 : 52145 : FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo), i, t)
398 : 14183 : free_lang_data_in_binfo (t);
399 : 37962 : }
400 : :
401 : :
402 : : /* Reset all language specific information still present in TYPE. */
403 : :
404 : : static void
405 : 846463 : free_lang_data_in_type (tree type, class free_lang_data_d *fld)
406 : : {
407 : 846463 : gcc_assert (TYPE_P (type));
408 : :
409 : : /* Give the FE a chance to remove its own data first. */
410 : 846463 : lang_hooks.free_lang_data (type);
411 : :
412 : 846463 : TREE_LANG_FLAG_0 (type) = 0;
413 : 846463 : TREE_LANG_FLAG_1 (type) = 0;
414 : 846463 : TREE_LANG_FLAG_2 (type) = 0;
415 : 846463 : TREE_LANG_FLAG_3 (type) = 0;
416 : 846463 : TREE_LANG_FLAG_4 (type) = 0;
417 : 846463 : TREE_LANG_FLAG_5 (type) = 0;
418 : 846463 : TREE_LANG_FLAG_6 (type) = 0;
419 : :
420 : 846463 : TYPE_NEEDS_CONSTRUCTING (type) = 0;
421 : :
422 : : /* Purge non-marked variants from the variants chain, so that they
423 : : don't reappear in the IL after free_lang_data. */
424 : 846463 : while (TYPE_NEXT_VARIANT (type)
425 : 1284509 : && !fld->pset.contains (TYPE_NEXT_VARIANT (type)))
426 : : {
427 : 438046 : tree t = TYPE_NEXT_VARIANT (type);
428 : 438046 : TYPE_NEXT_VARIANT (type) = TYPE_NEXT_VARIANT (t);
429 : : /* Turn the removed types into distinct types. */
430 : 438046 : TYPE_MAIN_VARIANT (t) = t;
431 : 438046 : TYPE_NEXT_VARIANT (t) = NULL_TREE;
432 : : }
433 : :
434 : 846463 : if (TREE_CODE (type) == FUNCTION_TYPE)
435 : : {
436 : 127830 : TREE_TYPE (type) = fld_simplified_type (TREE_TYPE (type), fld);
437 : : /* Remove the const and volatile qualifiers from arguments. The
438 : : C++ front end removes them, but the C front end does not,
439 : : leading to false ODR violation errors when merging two
440 : : instances of the same function signature compiled by
441 : : different front ends. */
442 : 587801 : for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
443 : : {
444 : 459971 : tree arg_type = TREE_VALUE (p);
445 : 459971 : if (TYPE_READONLY (arg_type) || TYPE_VOLATILE (arg_type))
446 : : {
447 : 301 : int quals = TYPE_QUALS (arg_type)
448 : : & ~TYPE_QUAL_CONST
449 : 301 : & ~TYPE_QUAL_VOLATILE;
450 : 301 : TREE_VALUE (p) = build_qualified_type (arg_type, quals);
451 : 301 : if (!fld->pset.add (TREE_VALUE (p)))
452 : 117 : free_lang_data_in_type (TREE_VALUE (p), fld);
453 : : }
454 : 459971 : TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld);
455 : : /* C++ FE uses TREE_PURPOSE to store initial values. */
456 : 459971 : TREE_PURPOSE (p) = NULL;
457 : : }
458 : : }
459 : : else if (TREE_CODE (type) == METHOD_TYPE)
460 : : {
461 : 30054 : TREE_TYPE (type) = fld_simplified_type (TREE_TYPE (type), fld);
462 : 113204 : for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
463 : : {
464 : : /* C++ FE uses TREE_PURPOSE to store initial values. */
465 : 83150 : TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld);
466 : 83150 : TREE_PURPOSE (p) = NULL;
467 : : }
468 : : }
469 : : else if (RECORD_OR_UNION_TYPE_P (type))
470 : : {
471 : : /* Remove members that are not FIELD_DECLs from the field list
472 : : of an aggregate. These occur in C++. */
473 : 498023 : for (tree *prev = &TYPE_FIELDS (type), member; (member = *prev);)
474 : 411987 : if (TREE_CODE (member) == FIELD_DECL)
475 : 127732 : prev = &DECL_CHAIN (member);
476 : : else
477 : 284255 : *prev = DECL_CHAIN (member);
478 : :
479 : 86036 : TYPE_VFIELD (type) = NULL_TREE;
480 : :
481 : 86036 : if (TYPE_BINFO (type))
482 : : {
483 : 23779 : free_lang_data_in_binfo (TYPE_BINFO (type));
484 : : /* We need to preserve link to bases and virtual table for all
485 : : polymorphic types to make devirtualization machinery working. */
486 : 23779 : if (!BINFO_VTABLE (TYPE_BINFO (type)))
487 : 21592 : TYPE_BINFO (type) = NULL;
488 : : }
489 : : }
490 : : else if (INTEGRAL_TYPE_P (type)
491 : : || SCALAR_FLOAT_TYPE_P (type)
492 : : || FIXED_POINT_TYPE_P (type))
493 : : {
494 : 151613 : if (TREE_CODE (type) == ENUMERAL_TYPE)
495 : : {
496 : 1200 : ENUM_IS_OPAQUE (type) = 0;
497 : 1200 : ENUM_IS_SCOPED (type) = 0;
498 : : /* Type values are used only for C++ ODR checking. Drop them
499 : : for all type variants and non-ODR types.
500 : : For ODR types the data is freed in free_odr_warning_data. */
501 : 1200 : if (!TYPE_VALUES (type))
502 : : ;
503 : 990 : else if (TYPE_MAIN_VARIANT (type) != type
504 : 671 : || !type_with_linkage_p (type)
505 : 1315 : || type_in_anonymous_namespace_p (type))
506 : 670 : TYPE_VALUES (type) = NULL;
507 : : else
508 : 320 : register_odr_enum (type);
509 : : }
510 : 151613 : free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type));
511 : 151613 : free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type));
512 : : }
513 : :
514 : 846463 : TYPE_LANG_SLOT_1 (type) = NULL_TREE;
515 : :
516 : 846463 : free_lang_data_in_one_sizepos (&TYPE_SIZE (type));
517 : 846463 : free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type));
518 : :
519 : 846463 : if (TYPE_CONTEXT (type)
520 : 846463 : && TREE_CODE (TYPE_CONTEXT (type)) == BLOCK)
521 : : {
522 : 0 : tree ctx = TYPE_CONTEXT (type);
523 : 0 : do
524 : : {
525 : 0 : ctx = BLOCK_SUPERCONTEXT (ctx);
526 : : }
527 : 0 : while (ctx && TREE_CODE (ctx) == BLOCK);
528 : 0 : TYPE_CONTEXT (type) = ctx;
529 : : }
530 : :
531 : 846463 : TYPE_STUB_DECL (type) = NULL;
532 : 846463 : TYPE_NAME (type) = fld_simplified_type_name (type);
533 : 846463 : }
534 : :
535 : : /* Reset all language specific information still present in symbol
536 : : DECL. */
537 : :
538 : : static void
539 : 1988965 : free_lang_data_in_decl (tree decl, class free_lang_data_d *fld)
540 : : {
541 : 1988965 : gcc_assert (DECL_P (decl));
542 : :
543 : : /* Give the FE a chance to remove its own data first. */
544 : 1988965 : lang_hooks.free_lang_data (decl);
545 : :
546 : 1988965 : TREE_LANG_FLAG_0 (decl) = 0;
547 : 1988965 : TREE_LANG_FLAG_1 (decl) = 0;
548 : 1988965 : TREE_LANG_FLAG_2 (decl) = 0;
549 : 1988965 : TREE_LANG_FLAG_3 (decl) = 0;
550 : 1988965 : TREE_LANG_FLAG_4 (decl) = 0;
551 : 1988965 : TREE_LANG_FLAG_5 (decl) = 0;
552 : 1988965 : TREE_LANG_FLAG_6 (decl) = 0;
553 : :
554 : 1988965 : free_lang_data_in_one_sizepos (&DECL_SIZE (decl));
555 : 1988965 : free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl));
556 : 1988965 : if (TREE_CODE (decl) == FIELD_DECL)
557 : : {
558 : 94839 : DECL_FCONTEXT (decl) = NULL;
559 : 94839 : free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl));
560 : 94839 : if (TREE_CODE (DECL_CONTEXT (decl)) == QUAL_UNION_TYPE)
561 : 0 : DECL_QUALIFIER (decl) = NULL_TREE;
562 : : }
563 : :
564 : 1988965 : if (TREE_CODE (decl) == FUNCTION_DECL)
565 : : {
566 : 372872 : struct cgraph_node *node;
567 : : /* Frontends do not set TREE_ADDRESSABLE on public variables even though
568 : : the address may be taken in other unit, so this flag has no practical
569 : : use for middle-end.
570 : :
571 : : It would make more sense if frontends set TREE_ADDRESSABLE to 0 only
572 : : for public objects that indeed cannot be adressed, but it is not
573 : : the case. Set the flag to true so we do not get merge failures for
574 : : i.e. virtual tables between units that take address of it and
575 : : units that don't. */
576 : 372872 : if (TREE_PUBLIC (decl))
577 : 361142 : TREE_ADDRESSABLE (decl) = true;
578 : 372872 : TREE_TYPE (decl) = fld_simplified_type (TREE_TYPE (decl), fld);
579 : 372872 : if (!(node = cgraph_node::get (decl))
580 : 372872 : || (!node->definition && !node->clones))
581 : : {
582 : 247386 : if (node)
583 : 235848 : node->release_body ();
584 : : else
585 : : {
586 : 11538 : release_function_body (decl);
587 : 11538 : DECL_ARGUMENTS (decl) = NULL;
588 : 11538 : DECL_RESULT (decl) = NULL;
589 : 11538 : DECL_INITIAL (decl) = error_mark_node;
590 : : }
591 : : }
592 : 372872 : if (gimple_has_body_p (decl) || (node && node->thunk))
593 : : {
594 : 119024 : tree t;
595 : :
596 : : /* If DECL has a gimple body, then the context for its
597 : : arguments must be DECL. Otherwise, it doesn't really
598 : : matter, as we will not be emitting any code for DECL. In
599 : : general, there may be other instances of DECL created by
600 : : the front end and since PARM_DECLs are generally shared,
601 : : their DECL_CONTEXT changes as the replicas of DECL are
602 : : created. The only time where DECL_CONTEXT is important
603 : : is for the FUNCTION_DECLs that have a gimple body (since
604 : : the PARM_DECL will be used in the function's body). */
605 : 460401 : for (t = DECL_ARGUMENTS (decl); t; t = TREE_CHAIN (t))
606 : 341377 : DECL_CONTEXT (t) = decl;
607 : 119024 : if (!DECL_FUNCTION_SPECIFIC_TARGET (decl))
608 : 119010 : DECL_FUNCTION_SPECIFIC_TARGET (decl)
609 : 119010 : = target_option_default_node;
610 : 119024 : if (!DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl))
611 : 115285 : DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl)
612 : 115285 : = optimization_default_node;
613 : : }
614 : :
615 : : /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
616 : : At this point, it is not needed anymore. */
617 : 372872 : DECL_SAVED_TREE (decl) = NULL_TREE;
618 : :
619 : : /* Clear the abstract origin if it refers to a method.
620 : : Otherwise dwarf2out.cc will ICE as we splice functions out of
621 : : TYPE_FIELDS and thus the origin will not be output
622 : : correctly. */
623 : 372872 : if (DECL_ABSTRACT_ORIGIN (decl)
624 : 16722 : && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))
625 : 389594 : && RECORD_OR_UNION_TYPE_P
626 : : (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))))
627 : 12693 : DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
628 : :
629 : 372872 : DECL_VINDEX (decl) = NULL_TREE;
630 : : }
631 : : else if (VAR_P (decl))
632 : : {
633 : : /* See comment above why we set the flag for functions. */
634 : 794022 : if (TREE_PUBLIC (decl))
635 : 235093 : TREE_ADDRESSABLE (decl) = true;
636 : 794022 : if ((DECL_EXTERNAL (decl)
637 : 4618 : && (!TREE_STATIC (decl) || !TREE_READONLY (decl)))
638 : 796390 : || (decl_function_context (decl) && !TREE_STATIC (decl)))
639 : 534091 : DECL_INITIAL (decl) = NULL_TREE;
640 : : }
641 : : else if (TREE_CODE (decl) == TYPE_DECL)
642 : : {
643 : 153085 : DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
644 : 153085 : DECL_VISIBILITY_SPECIFIED (decl) = 0;
645 : 153085 : TREE_PUBLIC (decl) = 0;
646 : 153085 : TREE_PRIVATE (decl) = 0;
647 : 153085 : DECL_ARTIFICIAL (decl) = 0;
648 : 153085 : TYPE_DECL_SUPPRESS_DEBUG (decl) = 0;
649 : 153085 : DECL_INITIAL (decl) = NULL_TREE;
650 : 153085 : DECL_ORIGINAL_TYPE (decl) = NULL_TREE;
651 : 153085 : DECL_MODE (decl) = VOIDmode;
652 : 153085 : SET_DECL_ALIGN (decl, 0);
653 : : /* TREE_TYPE is cleared at WPA time in free_odr_warning_data. */
654 : : }
655 : : else if (TREE_CODE (decl) == FIELD_DECL)
656 : : {
657 : 94839 : TREE_TYPE (decl) = fld_simplified_type (TREE_TYPE (decl), fld);
658 : 94839 : DECL_INITIAL (decl) = NULL_TREE;
659 : : }
660 : : else if (TREE_CODE (decl) == TRANSLATION_UNIT_DECL
661 : 21710 : && DECL_INITIAL (decl)
662 : 18232 : && TREE_CODE (DECL_INITIAL (decl)) == BLOCK)
663 : : {
664 : : /* Strip builtins from the translation-unit BLOCK. We still have targets
665 : : without builtin_decl_explicit support and also builtins are shared
666 : : nodes and thus we can't use TREE_CHAIN in multiple lists. */
667 : 18232 : tree *nextp = &BLOCK_VARS (DECL_INITIAL (decl));
668 : 18232 : while (*nextp)
669 : : {
670 : 0 : tree var = *nextp;
671 : 0 : if (TREE_CODE (var) == FUNCTION_DECL
672 : 0 : && fndecl_built_in_p (var))
673 : 0 : *nextp = TREE_CHAIN (var);
674 : : else
675 : 0 : nextp = &TREE_CHAIN (var);
676 : : }
677 : : }
678 : : /* We need to keep field decls associated with their trees. Otherwise tree
679 : : merging may merge some fields and keep others disjoint which in turn will
680 : : not do well with TREE_CHAIN pointers linking them.
681 : :
682 : : Also do not drop containing types for virtual methods and tables because
683 : : these are needed by devirtualization.
684 : : C++ destructors are special because C++ frontends sometimes produces
685 : : virtual destructor as an alias of non-virtual destructor. In
686 : : devirutalization code we always walk through aliases and we need
687 : : context to be preserved too. See PR89335 */
688 : 1988965 : if (TREE_CODE (decl) != FIELD_DECL
689 : 1988965 : && ((TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
690 : 1166894 : || (!DECL_VIRTUAL_P (decl)
691 : 1159728 : && (TREE_CODE (decl) != FUNCTION_DECL
692 : 368388 : || !DECL_CXX_DESTRUCTOR_P (decl)))))
693 : 1880095 : DECL_CONTEXT (decl) = fld_decl_context (DECL_CONTEXT (decl));
694 : 1988965 : }
695 : :
696 : :
697 : : /* Operand callback helper for free_lang_data_in_node. *TP is the
698 : : subtree operand being considered. */
699 : :
700 : : static tree
701 : 9538562 : find_decls_types_r (tree *tp, int *ws, void *data)
702 : : {
703 : 9538562 : tree t = *tp;
704 : 9538562 : class free_lang_data_d *fld = (class free_lang_data_d *) data;
705 : :
706 : 9538562 : if (TREE_CODE (t) == TREE_LIST)
707 : : return NULL_TREE;
708 : :
709 : : /* Language specific nodes will be removed, so there is no need
710 : : to gather anything under them. */
711 : 8901242 : if (is_lang_specific (t))
712 : : {
713 : 15 : *ws = 0;
714 : 15 : return NULL_TREE;
715 : : }
716 : :
717 : 8901227 : if (DECL_P (t))
718 : : {
719 : : /* Note that walk_tree does not traverse every possible field in
720 : : decls, so we have to do our own traversals here. */
721 : 1988965 : add_tree_to_fld_list (t, fld);
722 : :
723 : 1988965 : fld_worklist_push (DECL_NAME (t), fld);
724 : 1988965 : fld_worklist_push (DECL_CONTEXT (t), fld);
725 : 1988965 : fld_worklist_push (DECL_SIZE (t), fld);
726 : 1988965 : fld_worklist_push (DECL_SIZE_UNIT (t), fld);
727 : :
728 : : /* We are going to remove everything under DECL_INITIAL for
729 : : TYPE_DECLs. No point walking them. */
730 : 1988965 : if (TREE_CODE (t) != TYPE_DECL)
731 : 1835880 : fld_worklist_push (DECL_INITIAL (t), fld);
732 : :
733 : 1988965 : fld_worklist_push (DECL_ATTRIBUTES (t), fld);
734 : 1988965 : fld_worklist_push (DECL_ABSTRACT_ORIGIN (t), fld);
735 : :
736 : 1988965 : if (TREE_CODE (t) == FUNCTION_DECL)
737 : : {
738 : 757431 : for (tree arg = DECL_ARGUMENTS (t); arg; arg = DECL_CHAIN (arg))
739 : 384559 : fld_worklist_push (arg, fld);
740 : 372872 : fld_worklist_push (DECL_RESULT (t), fld);
741 : : }
742 : 1616093 : else if (TREE_CODE (t) == FIELD_DECL)
743 : : {
744 : 94839 : fld_worklist_push (DECL_FIELD_OFFSET (t), fld);
745 : 94839 : fld_worklist_push (DECL_BIT_FIELD_TYPE (t), fld);
746 : 94839 : fld_worklist_push (DECL_FIELD_BIT_OFFSET (t), fld);
747 : 94839 : fld_worklist_push (DECL_FCONTEXT (t), fld);
748 : : }
749 : :
750 : 1988965 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
751 : 1988965 : && DECL_HAS_VALUE_EXPR_P (t))
752 : 6353 : fld_worklist_push (DECL_VALUE_EXPR (t), fld);
753 : :
754 : 1988965 : *ws = 0;
755 : : }
756 : 6912262 : else if (TYPE_P (t))
757 : : {
758 : : /* Note that walk_tree does not traverse every possible field in
759 : : types, so we have to do our own traversals here. */
760 : 808306 : add_tree_to_fld_list (t, fld);
761 : :
762 : 808306 : if (!RECORD_OR_UNION_TYPE_P (t))
763 : 739931 : fld_worklist_push (TYPE_CACHED_VALUES (t), fld);
764 : 808306 : fld_worklist_push (TYPE_SIZE (t), fld);
765 : 808306 : fld_worklist_push (TYPE_SIZE_UNIT (t), fld);
766 : 808306 : fld_worklist_push (TYPE_ATTRIBUTES (t), fld);
767 : 808306 : fld_worklist_push (TYPE_POINTER_TO (t), fld);
768 : 808306 : fld_worklist_push (TYPE_REFERENCE_TO (t), fld);
769 : 808306 : fld_worklist_push (TYPE_NAME (t), fld);
770 : : /* While we do not stream TYPE_POINTER_TO and TYPE_REFERENCE_TO
771 : : lists, we may look types up in these lists and use them while
772 : : optimizing the function body. Thus we need to free lang data
773 : : in them. */
774 : 808306 : if (TREE_CODE (t) == POINTER_TYPE)
775 : 336610 : fld_worklist_push (TYPE_NEXT_PTR_TO (t), fld);
776 : 808306 : if (TREE_CODE (t) == REFERENCE_TYPE)
777 : 33934 : fld_worklist_push (TYPE_NEXT_REF_TO (t), fld);
778 : 808306 : if (!POINTER_TYPE_P (t))
779 : 437762 : fld_worklist_push (TYPE_MIN_VALUE_RAW (t), fld);
780 : : /* TYPE_MAX_VALUE_RAW is TYPE_BINFO for record types. */
781 : 808306 : if (!RECORD_OR_UNION_TYPE_P (t))
782 : 739931 : fld_worklist_push (TYPE_MAX_VALUE_RAW (t), fld);
783 : 808306 : fld_worklist_push (TYPE_MAIN_VARIANT (t), fld);
784 : : /* Do not walk TYPE_NEXT_VARIANT. We do not stream it and thus
785 : : do not and want not to reach unused variants this way. */
786 : 808306 : if (TYPE_CONTEXT (t))
787 : : {
788 : 22588 : tree ctx = TYPE_CONTEXT (t);
789 : : /* We adjust BLOCK TYPE_CONTEXTs to the innermost non-BLOCK one.
790 : : So push that instead. */
791 : 22588 : while (ctx && TREE_CODE (ctx) == BLOCK)
792 : 0 : ctx = BLOCK_SUPERCONTEXT (ctx);
793 : 22588 : fld_worklist_push (ctx, fld);
794 : : }
795 : 808306 : fld_worklist_push (TYPE_CANONICAL (t), fld);
796 : :
797 : 808306 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t))
798 : : {
799 : : unsigned i;
800 : : tree tem;
801 : 30281 : FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t)), i, tem)
802 : 6502 : fld_worklist_push (TREE_TYPE (tem), fld);
803 : 23779 : fld_worklist_push (BINFO_TYPE (TYPE_BINFO (t)), fld);
804 : 23779 : fld_worklist_push (BINFO_VTABLE (TYPE_BINFO (t)), fld);
805 : : }
806 : 808306 : if (RECORD_OR_UNION_TYPE_P (t))
807 : : {
808 : 68375 : tree tem;
809 : : /* Push all TYPE_FIELDS - there can be interleaving interesting
810 : : and non-interesting things. */
811 : 68375 : tem = TYPE_FIELDS (t);
812 : 611140 : while (tem)
813 : : {
814 : 542765 : if (TREE_CODE (tem) == FIELD_DECL)
815 : 127728 : fld_worklist_push (tem, fld);
816 : 542765 : tem = TREE_CHAIN (tem);
817 : : }
818 : : }
819 : 808306 : if (FUNC_OR_METHOD_TYPE_P (t))
820 : 157884 : fld_worklist_push (TYPE_METHOD_BASETYPE (t), fld);
821 : :
822 : 808306 : fld_worklist_push (TYPE_STUB_DECL (t), fld);
823 : 808306 : *ws = 0;
824 : : }
825 : 6103956 : else if (TREE_CODE (t) == BLOCK)
826 : : {
827 : 992068 : for (tree *tem = &BLOCK_VARS (t); *tem; )
828 : : {
829 : 797731 : if (TREE_CODE (*tem) != LABEL_DECL
830 : 797731 : && (TREE_CODE (*tem) != VAR_DECL
831 : 374050 : || !auto_var_in_fn_p (*tem, DECL_CONTEXT (*tem))))
832 : : {
833 : 441734 : gcc_assert (TREE_CODE (*tem) != RESULT_DECL
834 : : && TREE_CODE (*tem) != PARM_DECL);
835 : 441734 : *tem = TREE_CHAIN (*tem);
836 : : }
837 : : else
838 : : {
839 : 355997 : fld_worklist_push (*tem, fld);
840 : 355997 : tem = &TREE_CHAIN (*tem);
841 : : }
842 : : }
843 : 238482 : for (tree tem = BLOCK_SUBBLOCKS (t); tem; tem = BLOCK_CHAIN (tem))
844 : 44145 : fld_worklist_push (tem, fld);
845 : 194337 : fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t), fld);
846 : : }
847 : : /* walk_tree does not visit ce->index which can be a FIELD_DECL, pulling
848 : : in otherwise unused structure fields so handle CTORs explicitly. */
849 : 5909619 : else if (TREE_CODE (t) == CONSTRUCTOR)
850 : : {
851 : : unsigned HOST_WIDE_INT idx;
852 : : constructor_elt *ce;
853 : 854646 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce); idx++)
854 : : {
855 : 576717 : if (ce->index)
856 : 452976 : fld_worklist_push (ce->index, fld);
857 : 576717 : fld_worklist_push (ce->value, fld);
858 : : }
859 : 277929 : *ws = 0;
860 : : }
861 : :
862 : 8901227 : if (TREE_CODE (t) != IDENTIFIER_NODE
863 : 7502166 : && CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPED))
864 : 7307829 : fld_worklist_push (TREE_TYPE (t), fld);
865 : :
866 : : return NULL_TREE;
867 : : }
868 : :
869 : :
870 : : /* Find decls and types in T. */
871 : :
872 : : static void
873 : 8158016 : find_decls_types (tree t, class free_lang_data_d *fld)
874 : : {
875 : 18855882 : while (1)
876 : : {
877 : 13506949 : if (!fld->pset.contains (t))
878 : 9346752 : walk_tree (&t, find_decls_types_r, fld, &fld->pset);
879 : 13506949 : if (fld->worklist.is_empty ())
880 : : break;
881 : 5348933 : t = fld->worklist.pop ();
882 : : }
883 : 8158016 : }
884 : :
885 : : /* Translate all the types in LIST with the corresponding runtime
886 : : types. */
887 : :
888 : : static tree
889 : 573 : get_eh_types_for_runtime (tree list)
890 : : {
891 : 573 : tree head, prev;
892 : :
893 : 573 : if (list == NULL_TREE)
894 : : return NULL_TREE;
895 : :
896 : 200 : head = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
897 : 200 : prev = head;
898 : 200 : list = TREE_CHAIN (list);
899 : 200 : while (list)
900 : : {
901 : 0 : tree n = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
902 : 0 : TREE_CHAIN (prev) = n;
903 : 0 : prev = TREE_CHAIN (prev);
904 : 0 : list = TREE_CHAIN (list);
905 : : }
906 : :
907 : : return head;
908 : : }
909 : :
910 : :
911 : : /* Find decls and types referenced in EH region R and store them in
912 : : FLD->DECLS and FLD->TYPES. */
913 : :
914 : : static void
915 : 37535 : find_decls_types_in_eh_region (eh_region r, class free_lang_data_d *fld)
916 : : {
917 : 37535 : switch (r->type)
918 : : {
919 : : case ERT_CLEANUP:
920 : : break;
921 : :
922 : 585 : case ERT_TRY:
923 : 585 : {
924 : 585 : eh_catch c;
925 : :
926 : : /* The types referenced in each catch must first be changed to the
927 : : EH types used at runtime. This removes references to FE types
928 : : in the region. */
929 : 991 : for (c = r->u.eh_try.first_catch; c ; c = c->next_catch)
930 : : {
931 : 406 : c->type_list = get_eh_types_for_runtime (c->type_list);
932 : 406 : walk_tree (&c->type_list, find_decls_types_r, fld, &fld->pset);
933 : : }
934 : : }
935 : : break;
936 : :
937 : 167 : case ERT_ALLOWED_EXCEPTIONS:
938 : 167 : r->u.allowed.type_list
939 : 167 : = get_eh_types_for_runtime (r->u.allowed.type_list);
940 : 167 : walk_tree (&r->u.allowed.type_list, find_decls_types_r, fld, &fld->pset);
941 : 167 : break;
942 : :
943 : 14086 : case ERT_MUST_NOT_THROW:
944 : 14086 : walk_tree (&r->u.must_not_throw.failure_decl,
945 : : find_decls_types_r, fld, &fld->pset);
946 : 14086 : break;
947 : : }
948 : 37535 : }
949 : :
950 : :
951 : : /* Find decls and types referenced in cgraph node N and store them in
952 : : FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
953 : : look for *every* kind of DECL and TYPE node reachable from N,
954 : : including those embedded inside types and decls (i.e,, TYPE_DECLs,
955 : : NAMESPACE_DECLs, etc). */
956 : :
957 : : static void
958 : 361334 : find_decls_types_in_node (struct cgraph_node *n, class free_lang_data_d *fld)
959 : : {
960 : 361334 : basic_block bb;
961 : 361334 : struct function *fn;
962 : 361334 : unsigned ix;
963 : 361334 : tree t;
964 : :
965 : 361334 : find_decls_types (n->decl, fld);
966 : :
967 : 361334 : if (!gimple_has_body_p (n->decl))
968 : 361334 : return;
969 : :
970 : 118854 : gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
971 : :
972 : 118854 : fn = DECL_STRUCT_FUNCTION (n->decl);
973 : :
974 : : /* Traverse locals. */
975 : 758935 : FOR_EACH_LOCAL_DECL (fn, ix, t)
976 : 552282 : find_decls_types (t, fld);
977 : :
978 : : /* Traverse EH regions in FN. */
979 : 118854 : {
980 : 118854 : eh_region r;
981 : 156389 : FOR_ALL_EH_REGION_FN (r, fn)
982 : 37535 : find_decls_types_in_eh_region (r, fld);
983 : : }
984 : :
985 : : /* Traverse every statement in FN. */
986 : 862015 : FOR_EACH_BB_FN (bb, fn)
987 : : {
988 : 743161 : gphi_iterator psi;
989 : 743161 : gimple_stmt_iterator si;
990 : 743161 : unsigned i;
991 : :
992 : 743231 : for (psi = gsi_start_phis (bb); !gsi_end_p (psi); gsi_next (&psi))
993 : : {
994 : 70 : gphi *phi = psi.phi ();
995 : :
996 : 205 : for (i = 0; i < gimple_phi_num_args (phi); i++)
997 : : {
998 : 135 : tree *arg_p = gimple_phi_arg_def_ptr (phi, i);
999 : 135 : find_decls_types (*arg_p, fld);
1000 : : }
1001 : : }
1002 : :
1003 : 3716915 : for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
1004 : : {
1005 : 2230593 : gimple *stmt = gsi_stmt (si);
1006 : :
1007 : 2230593 : if (is_gimple_call (stmt))
1008 : 516540 : find_decls_types (gimple_call_fntype (stmt), fld);
1009 : :
1010 : 8681447 : for (i = 0; i < gimple_num_ops (stmt); i++)
1011 : : {
1012 : 6450854 : tree arg = gimple_op (stmt, i);
1013 : 6450854 : find_decls_types (arg, fld);
1014 : : /* find_decls_types doesn't walk TREE_PURPOSE of TREE_LISTs,
1015 : : which we need for asm stmts. */
1016 : 6450854 : if (arg
1017 : 4826661 : && TREE_CODE (arg) == TREE_LIST
1018 : 17847 : && TREE_PURPOSE (arg)
1019 : 6467395 : && gimple_code (stmt) == GIMPLE_ASM)
1020 : 16541 : find_decls_types (TREE_PURPOSE (arg), fld);
1021 : : }
1022 : : }
1023 : : }
1024 : : }
1025 : :
1026 : :
1027 : : /* Find decls and types referenced in varpool node N and store them in
1028 : : FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
1029 : : look for *every* kind of DECL and TYPE node reachable from N,
1030 : : including those embedded inside types and decls (i.e,, TYPE_DECLs,
1031 : : NAMESPACE_DECLs, etc). */
1032 : :
1033 : : static void
1034 : 260330 : find_decls_types_in_var (varpool_node *v, class free_lang_data_d *fld)
1035 : : {
1036 : 0 : find_decls_types (v->decl, fld);
1037 : 0 : }
1038 : :
1039 : : /* Free language specific information for every operand and expression
1040 : : in every node of the call graph. This process operates in three stages:
1041 : :
1042 : : 1- Every callgraph node and varpool node is traversed looking for
1043 : : decls and types embedded in them. This is a more exhaustive
1044 : : search than that done by find_referenced_vars, because it will
1045 : : also collect individual fields, decls embedded in types, etc.
1046 : :
1047 : : 2- All the decls found are sent to free_lang_data_in_decl.
1048 : :
1049 : : 3- All the types found are sent to free_lang_data_in_type.
1050 : :
1051 : : The ordering between decls and types is important because
1052 : : free_lang_data_in_decl sets assembler names, which includes
1053 : : mangling. So types cannot be freed up until assembler names have
1054 : : been set up. */
1055 : :
1056 : : static void
1057 : 22961 : free_lang_data_in_cgraph (class free_lang_data_d *fld)
1058 : : {
1059 : 22961 : struct cgraph_node *n;
1060 : 22961 : varpool_node *v;
1061 : 22961 : tree t;
1062 : 22961 : unsigned i;
1063 : 22961 : alias_pair *p;
1064 : :
1065 : : /* Find decls and types in the body of every function in the callgraph. */
1066 : 768590 : FOR_EACH_FUNCTION (n)
1067 : 361334 : find_decls_types_in_node (n, fld);
1068 : :
1069 : 22961 : FOR_EACH_VEC_SAFE_ELT (alias_pairs, i, p)
1070 : 0 : find_decls_types (p->decl, fld);
1071 : :
1072 : : /* Find decls and types in every varpool symbol. */
1073 : 306252 : FOR_EACH_VARIABLE (v)
1074 : 260330 : find_decls_types_in_var (v, fld);
1075 : :
1076 : : /* Set the assembler name on every decl found. We need to do this
1077 : : now because free_lang_data_in_decl will invalidate data needed
1078 : : for mangling. This breaks mangling on interdependent decls. */
1079 : 2011926 : FOR_EACH_VEC_ELT (fld->decls, i, t)
1080 : 1988965 : assign_assembler_name_if_needed (t);
1081 : :
1082 : : /* Traverse every decl found freeing its language data. */
1083 : 2011926 : FOR_EACH_VEC_ELT (fld->decls, i, t)
1084 : 1988965 : free_lang_data_in_decl (t, fld);
1085 : :
1086 : : /* Traverse every type found freeing its language data. */
1087 : 869307 : FOR_EACH_VEC_ELT (fld->types, i, t)
1088 : 846346 : free_lang_data_in_type (t, fld);
1089 : 22961 : }
1090 : :
1091 : :
1092 : : /* Free resources that are used by FE but are not needed once they are done. */
1093 : :
1094 : : static unsigned
1095 : 230197 : free_lang_data (void)
1096 : : {
1097 : 230197 : unsigned i;
1098 : 230197 : class free_lang_data_d fld;
1099 : :
1100 : : /* If we are the LTO frontend we have freed lang-specific data already. */
1101 : 230197 : if (in_lto_p
1102 : 230197 : || (!flag_generate_lto && !flag_generate_offload))
1103 : : {
1104 : : /* Rebuild type inheritance graph even when not doing LTO to get
1105 : : consistent profile data. */
1106 : 207236 : rebuild_type_inheritance_graph ();
1107 : 207236 : return 0;
1108 : : }
1109 : :
1110 : 22961 : fld_incomplete_types = new hash_map<tree, tree>;
1111 : 22961 : fld_simplified_types = new hash_map<tree, tree>;
1112 : :
1113 : : /* Provide a dummy TRANSLATION_UNIT_DECL if the FE failed to provide one. */
1114 : 22961 : if (vec_safe_is_empty (all_translation_units))
1115 : 1023 : build_translation_unit_decl (NULL_TREE);
1116 : :
1117 : : /* Allocate and assign alias sets to the standard integer types
1118 : : while the slots are still in the way the frontends generated them. */
1119 : 459220 : for (i = 0; i < itk_none; ++i)
1120 : 436259 : if (integer_types[i])
1121 : 298493 : TYPE_ALIAS_SET (integer_types[i]) = get_alias_set (integer_types[i]);
1122 : :
1123 : : /* Traverse the IL resetting language specific information for
1124 : : operands, expressions, etc. */
1125 : 22961 : free_lang_data_in_cgraph (&fld);
1126 : :
1127 : : /* Create gimple variants for common types. */
1128 : 160727 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
1129 : 137766 : builtin_structptr_types[i].node = builtin_structptr_types[i].base;
1130 : :
1131 : : /* Reset some langhooks. Do not reset types_compatible_p, it may
1132 : : still be used indirectly via the get_alias_set langhook. */
1133 : 22961 : lang_hooks.dwarf_name = lhd_dwarf_name;
1134 : 22961 : lang_hooks.decl_printable_name = gimple_decl_printable_name;
1135 : 22961 : lang_hooks.gimplify_expr = lhd_gimplify_expr;
1136 : 22961 : lang_hooks.overwrite_decl_assembler_name = lhd_overwrite_decl_assembler_name;
1137 : 22961 : lang_hooks.print_xnode = lhd_print_tree_nothing;
1138 : 22961 : lang_hooks.print_decl = lhd_print_tree_nothing;
1139 : 22961 : lang_hooks.print_type = lhd_print_tree_nothing;
1140 : 22961 : lang_hooks.print_identifier = lhd_print_tree_nothing;
1141 : :
1142 : 22961 : lang_hooks.tree_inlining.var_mod_type_p = hook_bool_tree_tree_false;
1143 : :
1144 : 22961 : if (flag_checking)
1145 : : {
1146 : : int i;
1147 : : tree t;
1148 : :
1149 : 869247 : FOR_EACH_VEC_ELT (fld.types, i, t)
1150 : 846292 : verify_type (t);
1151 : : }
1152 : :
1153 : : /* We do not want the default decl_assembler_name implementation,
1154 : : rather if we have fixed everything we want a wrapper around it
1155 : : asserting that all non-local symbols already got their assembler
1156 : : name and only produce assembler names for local symbols. Or rather
1157 : : make sure we never call decl_assembler_name on local symbols and
1158 : : devise a separate, middle-end private scheme for it. */
1159 : :
1160 : : /* Reset diagnostic machinery. */
1161 : 22961 : tree_diagnostics_defaults (global_dc);
1162 : :
1163 : 22961 : rebuild_type_inheritance_graph ();
1164 : :
1165 : 45922 : delete fld_incomplete_types;
1166 : 45922 : delete fld_simplified_types;
1167 : :
1168 : : return 0;
1169 : 230197 : }
1170 : :
1171 : : const pass_data pass_data_ipa_free_lang_data =
1172 : : {
1173 : : SIMPLE_IPA_PASS, /* type */
1174 : : "*free_lang_data", /* name */
1175 : : OPTGROUP_NONE, /* optinfo_flags */
1176 : : TV_IPA_FREE_LANG_DATA, /* tv_id */
1177 : : 0, /* properties_required */
1178 : : 0, /* properties_provided */
1179 : : 0, /* properties_destroyed */
1180 : : 0, /* todo_flags_start */
1181 : : 0, /* todo_flags_finish */
1182 : : };
1183 : :
1184 : : class pass_ipa_free_lang_data : public simple_ipa_opt_pass
1185 : : {
1186 : : public:
1187 : 285689 : pass_ipa_free_lang_data (gcc::context *ctxt)
1188 : 571378 : : simple_ipa_opt_pass (pass_data_ipa_free_lang_data, ctxt)
1189 : : {}
1190 : :
1191 : : /* opt_pass methods: */
1192 : 230197 : unsigned int execute (function *) final override { return free_lang_data (); }
1193 : :
1194 : : }; // class pass_ipa_free_lang_data
1195 : :
1196 : : } // anon namespace
1197 : :
1198 : : simple_ipa_opt_pass *
1199 : 285689 : make_pass_ipa_free_lang_data (gcc::context *ctxt)
1200 : : {
1201 : 285689 : return new pass_ipa_free_lang_data (ctxt);
1202 : : }
|