Branch data Line data Source code
1 : : /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 : : Copyright (C) 1987-2025 Free Software Foundation, Inc.
3 : :
4 : : This file is part of GCC.
5 : :
6 : : GCC is free software; you can redistribute it and/or modify it under
7 : : the terms of the GNU General Public License as published by the Free
8 : : Software Foundation; either version 3, or (at your option) any later
9 : : version.
10 : :
11 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : : for more details.
15 : :
16 : : You should have received a copy of the GNU General Public License
17 : : along with GCC; see the file COPYING3. If not see
18 : : <http://www.gnu.org/licenses/>. */
19 : :
20 : : /* This is the top level of cc1/c++.
21 : : It parses command args, opens files, invokes the various passes
22 : : in the proper order, and counts the time used by each.
23 : : Error messages and low-level interface to malloc also handled here. */
24 : :
25 : : #include "config.h"
26 : : #include "system.h"
27 : : #include "coretypes.h"
28 : : #include "backend.h"
29 : : #include "target.h"
30 : : #include "rtl.h"
31 : : #include "tree.h"
32 : : #include "gimple.h"
33 : : #include "alloc-pool.h"
34 : : #include "timevar.h"
35 : : #include "memmodel.h"
36 : : #include "tm_p.h"
37 : : #include "optabs-libfuncs.h"
38 : : #include "insn-config.h"
39 : : #include "ira.h"
40 : : #include "recog.h"
41 : : #include "cgraph.h"
42 : : #include "coverage.h"
43 : : #include "diagnostic.h"
44 : : #include "pretty-print-urlifier.h"
45 : : #include "varasm.h"
46 : : #include "tree-inline.h"
47 : : #include "realmpfr.h" /* For GMP/MPFR/MPC versions, in print_version. */
48 : : #include "version.h"
49 : : #include "flags.h"
50 : : #include "insn-attr.h"
51 : : #include "output.h"
52 : : #include "toplev.h"
53 : : #include "expr.h"
54 : : #include "intl.h"
55 : : #include "tree-diagnostic.h"
56 : : #include "reload.h"
57 : : #include "lra.h"
58 : : #include "dwarf2asm.h"
59 : : #include "debug.h"
60 : : #include "common/common-target.h"
61 : : #include "langhooks.h"
62 : : #include "cfgloop.h" /* for init_set_costs */
63 : : #include "hosthooks.h"
64 : : #include "opts.h"
65 : : #include "opts-diagnostic.h"
66 : : #include "stringpool.h"
67 : : #include "attribs.h"
68 : : #include "asan.h"
69 : : #include "tsan.h"
70 : : #include "plugin.h"
71 : : #include "context.h"
72 : : #include "pass_manager.h"
73 : : #include "auto-profile.h"
74 : : #include "dwarf2out.h"
75 : : #include "ipa-reference.h"
76 : : #include "symbol-summary.h"
77 : : #include "tree-vrp.h"
78 : : #include "sreal.h"
79 : : #include "ipa-cp.h"
80 : : #include "ipa-prop.h"
81 : : #include "ipa-utils.h"
82 : : #include "gcse.h"
83 : : #include "omp-offload.h"
84 : : #include "edit-context.h"
85 : : #include "tree-pass.h"
86 : : #include "dumpfile.h"
87 : : #include "ipa-fnsummary.h"
88 : : #include "dump-context.h"
89 : : #include "print-tree.h"
90 : : #include "optinfo-emit-json.h"
91 : : #include "ipa-modref-tree.h"
92 : : #include "ipa-modref.h"
93 : : #include "ipa-param-manipulation.h"
94 : : #include "dbgcnt.h"
95 : : #include "gcc-urlifier.h"
96 : : #include "unique-argv.h"
97 : :
98 : : #include "selftest.h"
99 : :
100 : : #ifdef HAVE_isl
101 : : #include <isl/version.h>
102 : : #endif
103 : :
104 : : static void general_init (const char *, bool, unique_argv original_argv);
105 : : static void backend_init (void);
106 : : static int lang_dependent_init (const char *);
107 : : static void init_asm_output (const char *);
108 : : static void finalize ();
109 : :
110 : : static void crash_signal (int) ATTRIBUTE_NORETURN;
111 : : static void compile_file (void);
112 : :
113 : : /* Decoded options, and number of such options. */
114 : : struct cl_decoded_option *save_decoded_options;
115 : : unsigned int save_decoded_options_count;
116 : :
117 : : /* Vector of saved Optimization decoded command line options. */
118 : : vec<cl_decoded_option> *save_opt_decoded_options;
119 : :
120 : : /* Debug hooks - dependent upon command line options. */
121 : :
122 : : const struct gcc_debug_hooks *debug_hooks;
123 : :
124 : : /* The FUNCTION_DECL for the function currently being compiled,
125 : : or 0 if between functions. */
126 : : tree current_function_decl;
127 : :
128 : : /* Set to the FUNC_BEGIN label of the current function, or NULL
129 : : if none. */
130 : : const char * current_function_func_begin_label;
131 : :
132 : : /* A random sequence of characters, unless overridden by user. */
133 : : static const char *flag_random_seed;
134 : :
135 : : /* A local time stamp derived from the time of compilation. It will be
136 : : zero if the system cannot provide a time. It will be -1u, if the
137 : : user has specified a particular random seed. */
138 : : unsigned local_tick;
139 : :
140 : : /* Random number for this compilation */
141 : : HOST_WIDE_INT random_seed;
142 : :
143 : : /* -f flags. */
144 : :
145 : : /* When non-NULL, indicates that whenever space is allocated on the
146 : : stack, the resulting stack pointer must not pass this
147 : : address---that is, for stacks that grow downward, the stack pointer
148 : : must always be greater than or equal to this address; for stacks
149 : : that grow upward, the stack pointer must be less than this address.
150 : : At present, the rtx may be either a REG or a SYMBOL_REF, although
151 : : the support provided depends on the backend. */
152 : : rtx stack_limit_rtx;
153 : :
154 : : class target_flag_state default_target_flag_state;
155 : : #if SWITCHABLE_TARGET
156 : : class target_flag_state *this_target_flag_state = &default_target_flag_state;
157 : : #else
158 : : #define this_target_flag_state (&default_target_flag_state)
159 : : #endif
160 : :
161 : : /* The user symbol prefix after having resolved same. */
162 : : const char *user_label_prefix;
163 : :
164 : : /* Output files for assembler code (real compiler output)
165 : : and debugging dumps. */
166 : :
167 : : FILE *asm_out_file;
168 : : FILE *aux_info_file;
169 : : FILE *callgraph_info_file = NULL;
170 : : static bitmap callgraph_info_external_printed;
171 : : FILE *stack_usage_file = NULL;
172 : : static bool no_backend = false;
173 : :
174 : : /* The current working directory of a translation. It's generally the
175 : : directory from which compilation was initiated, but a preprocessed
176 : : file may specify the original directory in which it was
177 : : created. */
178 : :
179 : : static const char *src_pwd;
180 : :
181 : : /* Initialize src_pwd with the given string, and return true. If it
182 : : was already initialized, return false. As a special case, it may
183 : : be called with a NULL argument to test whether src_pwd has NOT been
184 : : initialized yet. */
185 : :
186 : : bool
187 : 54 : set_src_pwd (const char *pwd)
188 : : {
189 : 54 : if (src_pwd)
190 : : {
191 : 0 : if (strcmp (src_pwd, pwd) == 0)
192 : : return true;
193 : : else
194 : : return false;
195 : : }
196 : :
197 : 54 : src_pwd = xstrdup (pwd);
198 : 54 : return true;
199 : : }
200 : :
201 : : /* Return the directory from which the translation unit was initiated,
202 : : in case set_src_pwd() was not called before to assign it a
203 : : different value. */
204 : :
205 : : const char *
206 : 71878 : get_src_pwd (void)
207 : : {
208 : 71878 : if (! src_pwd)
209 : : {
210 : 62788 : src_pwd = getpwd ();
211 : 62788 : if (!src_pwd)
212 : 0 : src_pwd = ".";
213 : : }
214 : :
215 : 71878 : return src_pwd;
216 : : }
217 : :
218 : : /* Called when the start of a function definition is parsed,
219 : : this function prints on stderr the name of the function. */
220 : : void
221 : 176350811 : announce_function (tree decl)
222 : : {
223 : 176350811 : if (!quiet_flag)
224 : : {
225 : 0 : if (rtl_dump_and_exit)
226 : 0 : fprintf (stderr, "%s ",
227 : 0 : identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
228 : : else
229 : 0 : fprintf (stderr, " %s",
230 : 0 : identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
231 : 0 : fflush (stderr);
232 : 0 : pp_needs_newline (global_dc->get_reference_printer ()) = true;
233 : 0 : diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
234 : : }
235 : 176350811 : }
236 : :
237 : : /* Initialize local_tick with the time of day, or -1 if
238 : : flag_random_seed is set. */
239 : :
240 : : static void
241 : 285077 : init_local_tick (void)
242 : : {
243 : 285077 : if (!flag_random_seed)
244 : : {
245 : : #ifdef HAVE_GETTIMEOFDAY
246 : 283281 : {
247 : 283281 : struct timeval tv;
248 : :
249 : 283281 : gettimeofday (&tv, NULL);
250 : 283281 : local_tick = (unsigned) tv.tv_sec * 1000 + tv.tv_usec / 1000;
251 : : }
252 : : #else
253 : : {
254 : : time_t now = time (NULL);
255 : :
256 : : if (now != (time_t)-1)
257 : : local_tick = (unsigned) now;
258 : : }
259 : : #endif
260 : : }
261 : : else
262 : 1796 : local_tick = -1;
263 : 285077 : }
264 : :
265 : : /* Obtain the random_seed. Unless NOINIT, initialize it if
266 : : it's not provided in the command line. */
267 : :
268 : : HOST_WIDE_INT
269 : 403566 : get_random_seed (bool noinit)
270 : : {
271 : 403566 : if (!random_seed && !noinit)
272 : : {
273 : 23735 : int fd = open ("/dev/urandom", O_RDONLY);
274 : 23735 : if (fd >= 0)
275 : : {
276 : 23735 : if (read (fd, &random_seed, sizeof (random_seed))
277 : : != sizeof (random_seed))
278 : 0 : random_seed = 0;
279 : 23735 : close (fd);
280 : : }
281 : 23735 : if (!random_seed)
282 : 0 : random_seed = local_tick ^ getpid ();
283 : : }
284 : 403566 : return random_seed;
285 : : }
286 : :
287 : : /* Set flag_random_seed to VAL, and if non-null, reinitialize random_seed. */
288 : :
289 : : void
290 : 1796 : set_random_seed (const char *val)
291 : : {
292 : 1796 : flag_random_seed = val;
293 : 1796 : if (flag_random_seed)
294 : : {
295 : 1796 : char *endp;
296 : :
297 : : /* When the driver passed in a hex number don't crc it again */
298 : 1796 : random_seed = strtoul (flag_random_seed, &endp, 0);
299 : 1796 : if (!(endp > flag_random_seed && *endp == 0))
300 : 556 : random_seed = crc32_string (0, flag_random_seed);
301 : : }
302 : 1796 : }
303 : :
304 : : /* Handler for fatal signals, such as SIGSEGV. These are transformed
305 : : into ICE messages, which is much more user friendly. In case the
306 : : error printer crashes, reset the signal to prevent infinite recursion. */
307 : :
308 : : static void
309 : 2 : crash_signal (int signo)
310 : : {
311 : 2 : signal (signo, SIG_DFL);
312 : :
313 : : /* If we crashed while processing an ASM statement, then be a little more
314 : : graceful. It's most likely the user's fault. */
315 : 2 : if (this_is_asm_operands)
316 : : {
317 : 0 : output_operand_lossage ("unrecoverable error");
318 : 0 : exit (FATAL_EXIT_CODE);
319 : : }
320 : :
321 : 2 : internal_error ("%s", strsignal (signo));
322 : : }
323 : :
324 : : /* A subroutine of wrapup_global_declarations. We've come to the end of
325 : : the compilation unit. All deferred variables should be undeferred,
326 : : and all incomplete decls should be finalized. */
327 : :
328 : : void
329 : 595611475 : wrapup_global_declaration_1 (tree decl)
330 : : {
331 : : /* We're not deferring this any longer. Assignment is conditional to
332 : : avoid needlessly dirtying PCH pages. */
333 : 595611475 : if (HAS_DECL_ASSEMBLER_NAME_P (decl)
334 : 595611475 : && DECL_DEFER_OUTPUT (decl) != 0)
335 : 21773334 : DECL_DEFER_OUTPUT (decl) = 0;
336 : :
337 : 595611475 : if (VAR_P (decl) && DECL_SIZE (decl) == 0)
338 : 351491 : lang_hooks.finish_incomplete_decl (decl);
339 : 595611475 : }
340 : :
341 : : /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
342 : : needs to be output. Return true if it is output. */
343 : :
344 : : bool
345 : 731194216 : wrapup_global_declaration_2 (tree decl)
346 : : {
347 : 729429675 : if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl)
348 : 822772300 : || (VAR_P (decl) && DECL_HAS_VALUE_EXPR_P (decl)))
349 : : return false;
350 : :
351 : : /* Don't write out static consts, unless we still need them.
352 : :
353 : : We also keep static consts if not optimizing (for debugging),
354 : : unless the user specified -fno-keep-static-consts.
355 : : ??? They might be better written into the debug information.
356 : : This is possible when using DWARF.
357 : :
358 : : A language processor that wants static constants to be always
359 : : written out (even if it is not used) is responsible for
360 : : calling rest_of_decl_compilation itself. E.g. the C front-end
361 : : calls rest_of_decl_compilation from finish_decl.
362 : : One motivation for this is that is conventional in some
363 : : environments to write things like:
364 : : static const char rcsid[] = "... version string ...";
365 : : intending to force the string to be in the executable.
366 : :
367 : : A language processor that would prefer to have unneeded
368 : : static constants "optimized away" would just defer writing
369 : : them out until here. E.g. C++ does this, because static
370 : : constants are often defined in header files.
371 : :
372 : : ??? A tempting alternative (for both C and C++) would be
373 : : to force a constant to be written if and only if it is
374 : : defined in a main file, as opposed to an include file. */
375 : :
376 : 91577188 : if (VAR_P (decl) && TREE_STATIC (decl))
377 : : {
378 : 67193587 : varpool_node *node;
379 : 67193587 : bool needed = true;
380 : 67193587 : node = varpool_node::get (decl);
381 : :
382 : 67193587 : if (!node && flag_ltrans)
383 : : needed = false;
384 : 67093786 : else if (node && node->definition)
385 : : needed = false;
386 : 6508412 : else if (node && node->alias)
387 : : needed = false;
388 : 6607981 : else if (!symtab->global_info_ready
389 : 6607981 : && (TREE_USED (decl)
390 : 744896 : || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
391 : : /* needed */;
392 : 744885 : else if (node && node->analyzed)
393 : : /* needed */;
394 : 744885 : else if (DECL_COMDAT (decl))
395 : : needed = false;
396 : 724218 : else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
397 : 724093 : && (optimize || !flag_keep_static_consts
398 : 6 : || DECL_ARTIFICIAL (decl)))
399 : : needed = false;
400 : :
401 : : if (needed)
402 : : {
403 : 6587183 : rest_of_decl_compilation (decl, 1, 1);
404 : 6587183 : return true;
405 : : }
406 : : }
407 : :
408 : : return false;
409 : : }
410 : :
411 : : /* Do any final processing required for the declarations in VEC, of
412 : : which there are LEN. We write out inline functions and variables
413 : : that have been deferred until this point, but which are required.
414 : : Returns nonzero if anything was put out. */
415 : :
416 : : bool
417 : 225372 : wrapup_global_declarations (tree *vec, int len)
418 : : {
419 : 225372 : bool reconsider, output_something = false;
420 : 225372 : int i;
421 : :
422 : 212279431 : for (i = 0; i < len; i++)
423 : 212054059 : wrapup_global_declaration_1 (vec[i]);
424 : :
425 : : /* Now emit any global variables or functions that we have been
426 : : putting off. We need to loop in case one of the things emitted
427 : : here references another one which comes earlier in the list. */
428 : 255895 : do
429 : : {
430 : 255895 : reconsider = false;
431 : 236880692 : for (i = 0; i < len; i++)
432 : 236624797 : reconsider |= wrapup_global_declaration_2 (vec[i]);
433 : 255895 : if (reconsider)
434 : 30523 : output_something = true;
435 : : }
436 : : while (reconsider);
437 : :
438 : 225372 : return output_something;
439 : : }
440 : :
441 : : /* Compile an entire translation unit. Write a file of assembly
442 : : output and various debugging dumps. */
443 : :
444 : : static void
445 : 278684 : compile_file (void)
446 : : {
447 : 278684 : timevar_start (TV_PHASE_PARSING);
448 : 278684 : timevar_push (TV_PARSE_GLOBAL);
449 : :
450 : : /* Parse entire file and generate initial debug information. */
451 : 278684 : lang_hooks.parse_file ();
452 : :
453 : 276933 : timevar_pop (TV_PARSE_GLOBAL);
454 : 276933 : timevar_stop (TV_PHASE_PARSING);
455 : :
456 : 276933 : if (flag_dump_locations)
457 : 0 : dump_location_info (stderr);
458 : :
459 : 276933 : free_attr_data ();
460 : :
461 : : /* Compilation is now finished except for writing
462 : : what's left of the symbol table output. */
463 : :
464 : 276933 : if (flag_syntax_only || flag_wpa)
465 : : return;
466 : :
467 : : /* Reset maximum_field_alignment, it can be adjusted by #pragma pack
468 : : and this shouldn't influence any types built by the middle-end
469 : : from now on (like gcov_info_type). */
470 : 267552 : maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
471 : :
472 : 267552 : ggc_protect_identifiers = false;
473 : :
474 : : /* Run the actual compilation process. */
475 : 267552 : if (!in_lto_p)
476 : : {
477 : 254293 : timevar_start (TV_PHASE_OPT_GEN);
478 : 254293 : symtab->finalize_compilation_unit ();
479 : 254273 : timevar_stop (TV_PHASE_OPT_GEN);
480 : : }
481 : :
482 : : /* Perform any post compilation-proper parser cleanups and
483 : : processing. This is currently only needed for the C++ parser,
484 : : which can be hopefully cleaned up so this hook is no longer
485 : : necessary. */
486 : 267532 : if (lang_hooks.decls.post_compilation_parsing_cleanups)
487 : 93301 : lang_hooks.decls.post_compilation_parsing_cleanups ();
488 : :
489 : 267532 : dump_context::get ().finish_any_json_writer ();
490 : :
491 : 267532 : if (seen_error ())
492 : : return;
493 : :
494 : 241581 : timevar_start (TV_PHASE_LATE_ASM);
495 : :
496 : : /* Compilation unit is finalized. When producing non-fat LTO object, we are
497 : : basically finished. */
498 : 241581 : if ((in_lto_p && flag_incremental_link != INCREMENTAL_LINK_LTO)
499 : 228355 : || !flag_lto || flag_fat_lto_objects)
500 : : {
501 : : /* File-scope initialization for AddressSanitizer. */
502 : 228345 : if (flag_sanitize & SANITIZE_ADDRESS)
503 : 2360 : asan_finish_file ();
504 : :
505 : 228345 : if (flag_sanitize & SANITIZE_THREAD)
506 : 334 : tsan_finish_file ();
507 : :
508 : 228345 : if (gate_hwasan ())
509 : 331 : hwasan_finish_file ();
510 : :
511 : 228345 : omp_finish_file ();
512 : :
513 : 228345 : output_shared_constant_pool ();
514 : 228345 : output_object_blocks ();
515 : 228345 : finish_tm_clone_pairs ();
516 : :
517 : : /* Write out any pending weak symbol declarations. */
518 : 228345 : weak_finish ();
519 : :
520 : : /* This must be at the end before unwind and debug info.
521 : : Some target ports emit PIC setup thunks here. */
522 : 228345 : insn_locations_init ();
523 : 228345 : targetm.asm_out.code_end ();
524 : :
525 : : /* Do dbx symbols. */
526 : 228345 : timevar_push (TV_SYMOUT);
527 : :
528 : : #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
529 : 228345 : dwarf2out_frame_finish ();
530 : : #endif
531 : :
532 : 228345 : debuginfo_start ();
533 : 228345 : (*debug_hooks->finish) (main_input_filename);
534 : 228345 : debuginfo_stop ();
535 : 228345 : timevar_pop (TV_SYMOUT);
536 : :
537 : : /* Output some stuff at end of file if nec. */
538 : :
539 : 228345 : dw2_output_indirect_constants ();
540 : :
541 : : /* Flush any pending external directives. */
542 : 228345 : process_pending_assemble_externals ();
543 : : }
544 : :
545 : : /* Let linker plugin know that this is a slim object and must be LTOed
546 : : even when user did not ask for it. */
547 : 241581 : if (flag_generate_lto && !flag_fat_lto_objects)
548 : : {
549 : : #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
550 : 13236 : ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE, "__gnu_lto_slim",
551 : 13236 : HOST_WIDE_INT_1U, 8);
552 : : #elif defined ASM_OUTPUT_ALIGNED_COMMON
553 : : ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_slim",
554 : : HOST_WIDE_INT_1U, 8);
555 : : #else
556 : : ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_slim",
557 : : HOST_WIDE_INT_1U,
558 : : HOST_WIDE_INT_1U);
559 : : #endif
560 : : }
561 : :
562 : : /* Attach a special .ident directive to the end of the file to identify
563 : : the version of GCC which compiled this code. The format of the .ident
564 : : string is patterned after the ones produced by native SVR4 compilers. */
565 : 241581 : if (!flag_no_ident)
566 : : {
567 : 234092 : const char *pkg_version = "(GNU) ";
568 : 234092 : char *ident_str;
569 : :
570 : 234092 : if (strcmp ("(GCC) ", pkgversion_string))
571 : : pkg_version = pkgversion_string;
572 : :
573 : 234092 : ident_str = ACONCAT (("GCC: ", pkg_version, version_string, NULL));
574 : 234092 : targetm.asm_out.output_ident (ident_str);
575 : : }
576 : :
577 : : /* Auto profile finalization. */
578 : 241581 : if (flag_auto_profile)
579 : 0 : end_auto_profile ();
580 : :
581 : : /* Invoke registered plugin callbacks. */
582 : 241581 : invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
583 : :
584 : : /* This must be at the end. Some target ports emit end of file directives
585 : : into the assembly file here, and hence we cannot output anything to the
586 : : assembly file after this point. */
587 : 241581 : targetm.asm_out.file_end ();
588 : :
589 : 241581 : timevar_stop (TV_PHASE_LATE_ASM);
590 : : }
591 : :
592 : : /* Print version information to FILE.
593 : : Each line begins with INDENT (for the case where FILE is the
594 : : assembler output file).
595 : :
596 : : If SHOW_GLOBAL_STATE is true (for cc1 etc), we are within the compiler
597 : : proper and can print pertinent state (e.g. params and plugins).
598 : :
599 : : If SHOW_GLOBAL_STATE is false (for use by libgccjit), we are outside the
600 : : compiler, and we don't hold the mutex on the compiler's global state:
601 : : we can't print params and plugins, since they might not be initialized,
602 : : or might be being manipulated by a compile running in another
603 : : thread. */
604 : :
605 : : void
606 : 2337 : print_version (FILE *file, const char *indent, bool show_global_state)
607 : : {
608 : 2337 : static const char fmt1[] =
609 : : #ifdef __GNUC__
610 : : N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
611 : : #else
612 : : N_("%s%s%s %sversion %s (%s) compiled by CC, ")
613 : : #endif
614 : : ;
615 : 2337 : static const char fmt2[] =
616 : : N_("GMP version %s, MPFR version %s, MPC version %s, isl version %s\n");
617 : 2337 : static const char fmt3[] =
618 : : N_("%s%swarning: %s header version %s differs from library version %s.\n");
619 : 2337 : static const char fmt4[] =
620 : : N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
621 : : #ifndef __VERSION__
622 : : #define __VERSION__ "[?]"
623 : : #endif
624 : 2337 : fprintf (file,
625 : 2337 : file == stderr ? _(fmt1) : fmt1,
626 : 2337 : indent, *indent != 0 ? " " : "",
627 : : lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
628 : : indent, __VERSION__);
629 : :
630 : : /* We need to stringify the GMP macro values. Ugh, gmp_version has
631 : : two string formats, "i.j.k" and "i.j" when k is zero. As of
632 : : gmp-4.3.0, GMP always uses the 3 number format. */
633 : : #define GCC_GMP_STRINGIFY_VERSION3(X) #X
634 : : #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3 (X)
635 : : #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
636 : : #define GCC_GMP_VERSION \
637 : : GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
638 : : #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
639 : : #define GCC_GMP_STRINGIFY_VERSION \
640 : : GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION) "." \
641 : : GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_MINOR)
642 : : #else
643 : : #define GCC_GMP_STRINGIFY_VERSION \
644 : : GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION) "." \
645 : : GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_MINOR) "." \
646 : : GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_PATCHLEVEL)
647 : : #endif
648 : 4674 : fprintf (file,
649 : 2337 : file == stderr ? _(fmt2) : fmt2,
650 : : GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING,
651 : : #ifndef HAVE_isl
652 : : "none"
653 : : #else
654 : : isl_version ()
655 : : #endif
656 : : );
657 : 2337 : if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
658 : 0 : fprintf (file,
659 : 0 : file == stderr ? _(fmt3) : fmt3,
660 : 0 : indent, *indent != 0 ? " " : "",
661 : : "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
662 : 2337 : if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
663 : 0 : fprintf (file,
664 : 0 : file == stderr ? _(fmt3) : fmt3,
665 : 0 : indent, *indent != 0 ? " " : "",
666 : : "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
667 : 2337 : if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
668 : 0 : fprintf (file,
669 : 0 : file == stderr ? _(fmt3) : fmt3,
670 : 0 : indent, *indent != 0 ? " " : "",
671 : : "MPC", MPC_VERSION_STRING, mpc_get_version ());
672 : :
673 : 2337 : if (show_global_state)
674 : : {
675 : 123 : fprintf (file,
676 : 123 : file == stderr ? _(fmt4) : fmt4,
677 : 123 : indent, *indent != 0 ? " " : "",
678 : : param_ggc_min_expand, param_ggc_min_heapsize);
679 : :
680 : 123 : print_plugins_versions (file, indent);
681 : : }
682 : 2337 : }
683 : :
684 : :
685 : :
686 : : /* Open assembly code output file. Do this even if -fsyntax-only is
687 : : on, because then the driver will have provided the name of a
688 : : temporary file or bit bucket for us. NAME is the file specified on
689 : : the command line, possibly NULL. */
690 : : static void
691 : 270051 : init_asm_output (const char *name)
692 : : {
693 : 270051 : if (name == NULL && asm_file_name == 0)
694 : 0 : asm_out_file = stdout;
695 : : else
696 : : {
697 : 270051 : if (asm_file_name == 0)
698 : : {
699 : 1249 : int len = strlen (dump_base_name);
700 : 1249 : char *dumpname = XNEWVEC (char, len + 6);
701 : :
702 : 1249 : memcpy (dumpname, dump_base_name, len + 1);
703 : 1249 : strip_off_ending (dumpname, len);
704 : 1249 : strcat (dumpname, ".s");
705 : 1249 : asm_file_name = dumpname;
706 : : }
707 : 270051 : if (!strcmp (asm_file_name, "-"))
708 : 163 : asm_out_file = stdout;
709 : 269888 : else if (!canonical_filename_eq (asm_file_name, name)
710 : 269888 : || !strcmp (asm_file_name, HOST_BIT_BUCKET))
711 : 269888 : asm_out_file = fopen (asm_file_name, "w");
712 : : else
713 : : /* Use UNKOWN_LOCATION to prevent gcc from printing the first
714 : : line in the current file. */
715 : 0 : fatal_error (UNKNOWN_LOCATION,
716 : : "input file %qs is the same as output file",
717 : : asm_file_name);
718 : 270051 : if (asm_out_file == 0)
719 : 0 : fatal_error (UNKNOWN_LOCATION,
720 : : "cannot open %qs for writing: %m", asm_file_name);
721 : : }
722 : :
723 : 270051 : if (!flag_syntax_only && !(global_dc->get_lang_mask () & CL_LTODump))
724 : : {
725 : 269767 : targetm.asm_out.file_start ();
726 : :
727 : 269767 : if (flag_record_gcc_switches)
728 : : {
729 : 0 : if (targetm.asm_out.record_gcc_switches)
730 : : {
731 : 0 : const char *str
732 : 0 : = gen_producer_string (lang_hooks.name,
733 : : save_decoded_options,
734 : : save_decoded_options_count);
735 : 0 : targetm.asm_out.record_gcc_switches (str);
736 : : }
737 : : else
738 : 0 : inform (UNKNOWN_LOCATION,
739 : : "%<-frecord-gcc-switches%> is not supported by "
740 : : "the current target");
741 : : }
742 : :
743 : 269767 : if (flag_verbose_asm)
744 : : {
745 : 11 : print_version (asm_out_file, ASM_COMMENT_START, true);
746 : 11 : fputs (ASM_COMMENT_START, asm_out_file);
747 : 11 : fputs (" options passed: ", asm_out_file);
748 : 11 : char *cmdline = gen_command_line_string (save_decoded_options,
749 : : save_decoded_options_count);
750 : 11 : fputs (cmdline, asm_out_file);
751 : 11 : free (cmdline);
752 : 11 : fputc ('\n', asm_out_file);
753 : : }
754 : : }
755 : 270051 : }
756 : :
757 : : /* A helper function; used as the reallocator function for cpp's line
758 : : table. */
759 : : static void *
760 : 604205366 : realloc_for_line_map (void *ptr, size_t len)
761 : : {
762 : 604205366 : return ggc_realloc (ptr, len);
763 : : }
764 : :
765 : : /* A helper function: used as the allocator function for
766 : : identifier_to_locale. */
767 : : static void *
768 : 1291 : alloc_for_identifier_to_locale (size_t len)
769 : : {
770 : 1291 : return ggc_alloc_atomic (len);
771 : : }
772 : :
773 : : /* Output stack usage information. */
774 : : static void
775 : 355 : output_stack_usage_1 (FILE *cf)
776 : : {
777 : 355 : static bool warning_issued = false;
778 : 355 : enum stack_usage_kind_type { STATIC = 0, DYNAMIC, DYNAMIC_BOUNDED };
779 : 355 : const char *stack_usage_kind_str[] = {
780 : : "static",
781 : : "dynamic",
782 : : "dynamic,bounded"
783 : : };
784 : 355 : HOST_WIDE_INT stack_usage = current_function_static_stack_size;
785 : 355 : enum stack_usage_kind_type stack_usage_kind;
786 : :
787 : 355 : if (stack_usage < 0)
788 : : {
789 : 0 : if (!warning_issued)
790 : : {
791 : 0 : warning (0, "stack usage computation not supported for this target");
792 : 0 : warning_issued = true;
793 : : }
794 : 0 : return;
795 : : }
796 : :
797 : 355 : stack_usage_kind = STATIC;
798 : :
799 : : /* Add the maximum amount of space pushed onto the stack. */
800 : 355 : if (maybe_ne (current_function_pushed_stack_size, 0))
801 : : {
802 : 0 : HOST_WIDE_INT extra;
803 : 0 : if (current_function_pushed_stack_size.is_constant (&extra))
804 : : {
805 : 0 : stack_usage += extra;
806 : 0 : stack_usage_kind = DYNAMIC_BOUNDED;
807 : : }
808 : : else
809 : : {
810 : : extra = constant_lower_bound (current_function_pushed_stack_size);
811 : : stack_usage += extra;
812 : : stack_usage_kind = DYNAMIC;
813 : : }
814 : : }
815 : :
816 : : /* Now on to the tricky part: dynamic stack allocation. */
817 : 355 : if (current_function_allocates_dynamic_stack_space)
818 : : {
819 : 2 : if (stack_usage_kind != DYNAMIC)
820 : : {
821 : 2 : if (current_function_has_unbounded_dynamic_stack_size)
822 : : stack_usage_kind = DYNAMIC;
823 : : else
824 : 1 : stack_usage_kind = DYNAMIC_BOUNDED;
825 : : }
826 : :
827 : : /* Add the size even in the unbounded case, this can't hurt. */
828 : 2 : stack_usage += current_function_dynamic_stack_size;
829 : : }
830 : :
831 : 355 : if (cf && flag_callgraph_info & CALLGRAPH_INFO_STACK_USAGE)
832 : 0 : fprintf (cf, "\\n" HOST_WIDE_INT_PRINT_DEC " bytes (%s)",
833 : : stack_usage,
834 : 0 : stack_usage_kind_str[stack_usage_kind]);
835 : :
836 : 355 : if (stack_usage_file)
837 : : {
838 : 329 : print_decl_identifier (stack_usage_file, current_function_decl,
839 : : PRINT_DECL_ORIGIN | PRINT_DECL_NAME
840 : : | PRINT_DECL_REMAP_DEBUG);
841 : 329 : fprintf (stack_usage_file, "\t" HOST_WIDE_INT_PRINT_DEC"\t%s\n",
842 : 329 : stack_usage, stack_usage_kind_str[stack_usage_kind]);
843 : : }
844 : :
845 : 355 : if (warn_stack_usage >= 0 && warn_stack_usage < HOST_WIDE_INT_MAX)
846 : : {
847 : 13 : const location_t loc = DECL_SOURCE_LOCATION (current_function_decl);
848 : :
849 : 13 : if (stack_usage_kind == DYNAMIC)
850 : 1 : warning_at (loc, OPT_Wstack_usage_, "stack usage might be unbounded");
851 : 12 : else if (stack_usage > warn_stack_usage)
852 : : {
853 : 2 : if (stack_usage_kind == DYNAMIC_BOUNDED)
854 : 1 : warning_at (loc,
855 : 1 : OPT_Wstack_usage_, "stack usage might be %wu bytes",
856 : : stack_usage);
857 : : else
858 : 1 : warning_at (loc, OPT_Wstack_usage_, "stack usage is %wu bytes",
859 : : stack_usage);
860 : : }
861 : : }
862 : : }
863 : :
864 : : /* Dump placeholder node for indirect calls in VCG format. */
865 : :
866 : : #define INDIRECT_CALL_NAME "__indirect_call"
867 : :
868 : : static void
869 : 2 : dump_final_node_vcg_start (FILE *f, tree decl)
870 : : {
871 : 2 : fputs ("node: { title: \"", f);
872 : 2 : if (decl)
873 : 2 : print_decl_identifier (f, decl, PRINT_DECL_UNIQUE_NAME);
874 : : else
875 : 0 : fputs (INDIRECT_CALL_NAME, f);
876 : 2 : fputs ("\" label: \"", f);
877 : 2 : if (decl)
878 : : {
879 : 2 : print_decl_identifier (f, decl, PRINT_DECL_NAME);
880 : 2 : fputs ("\\n", f);
881 : 2 : print_decl_identifier (f, decl, PRINT_DECL_ORIGIN);
882 : : }
883 : : else
884 : 0 : fputs ("Indirect Call Placeholder", f);
885 : 2 : }
886 : :
887 : : /* Dump final cgraph edge in VCG format. */
888 : :
889 : : static void
890 : 0 : dump_final_callee_vcg (FILE *f, location_t location, tree callee)
891 : : {
892 : 0 : if ((!callee || DECL_EXTERNAL (callee))
893 : 0 : && bitmap_set_bit (callgraph_info_external_printed,
894 : 0 : callee ? DECL_UID (callee) + 1 : 0))
895 : : {
896 : 0 : dump_final_node_vcg_start (f, callee);
897 : 0 : fputs ("\" shape : ellipse }\n", f);
898 : : }
899 : :
900 : 0 : fputs ("edge: { sourcename: \"", f);
901 : 0 : print_decl_identifier (f, current_function_decl, PRINT_DECL_UNIQUE_NAME);
902 : 0 : fputs ("\" targetname: \"", f);
903 : 0 : if (callee)
904 : 0 : print_decl_identifier (f, callee, PRINT_DECL_UNIQUE_NAME);
905 : : else
906 : 0 : fputs (INDIRECT_CALL_NAME, f);
907 : 0 : if (LOCATION_LOCUS (location) != UNKNOWN_LOCATION)
908 : : {
909 : 0 : expanded_location loc;
910 : 0 : fputs ("\" label: \"", f);
911 : 0 : loc = expand_location (location);
912 : 0 : fprintf (f, "%s:%d:%d", loc.file, loc.line, loc.column);
913 : : }
914 : 0 : fputs ("\" }\n", f);
915 : 0 : }
916 : :
917 : : /* Callback for cgraph_node::call_for_symbol_thunks_and_aliases to dump to F_ a
918 : : node and an edge from ALIAS->DECL to CURRENT_FUNCTION_DECL. */
919 : :
920 : : static bool
921 : 2 : dump_final_alias_vcg (cgraph_node *alias, void *f_)
922 : : {
923 : 2 : FILE *f = (FILE *)f_;
924 : :
925 : 2 : if (alias->decl == current_function_decl)
926 : : return false;
927 : :
928 : 1 : dump_final_node_vcg_start (f, alias->decl);
929 : 1 : fputs ("\" shape : triangle }\n", f);
930 : :
931 : 1 : fputs ("edge: { sourcename: \"", f);
932 : 1 : print_decl_identifier (f, alias->decl, PRINT_DECL_UNIQUE_NAME);
933 : 1 : fputs ("\" targetname: \"", f);
934 : 1 : print_decl_identifier (f, current_function_decl, PRINT_DECL_UNIQUE_NAME);
935 : 1 : location_t location = DECL_SOURCE_LOCATION (alias->decl);
936 : 1 : if (LOCATION_LOCUS (location) != UNKNOWN_LOCATION)
937 : : {
938 : 1 : expanded_location loc;
939 : 1 : fputs ("\" label: \"", f);
940 : 1 : loc = expand_location (location);
941 : 1 : fprintf (f, "%s:%d:%d", loc.file, loc.line, loc.column);
942 : : }
943 : 1 : fputs ("\" }\n", f);
944 : :
945 : 1 : return false;
946 : : }
947 : :
948 : : /* Dump final cgraph node in VCG format. */
949 : :
950 : : static void
951 : 1 : dump_final_node_vcg (FILE *f)
952 : : {
953 : 1 : dump_final_node_vcg_start (f, current_function_decl);
954 : :
955 : 1 : if (flag_stack_usage_info
956 : 1 : || (flag_callgraph_info & CALLGRAPH_INFO_STACK_USAGE))
957 : 0 : output_stack_usage_1 (f);
958 : :
959 : 1 : if (flag_callgraph_info & CALLGRAPH_INFO_DYNAMIC_ALLOC)
960 : : {
961 : 0 : fprintf (f, "\\n%u dynamic objects", vec_safe_length (cfun->su->dallocs));
962 : :
963 : 0 : unsigned i;
964 : 0 : callinfo_dalloc *cda;
965 : 0 : FOR_EACH_VEC_SAFE_ELT (cfun->su->dallocs, i, cda)
966 : : {
967 : 0 : expanded_location loc = expand_location (cda->location);
968 : 0 : fprintf (f, "\\n %s", cda->name);
969 : 0 : fprintf (f, " %s:%d:%d", loc.file, loc.line, loc.column);
970 : : }
971 : :
972 : 0 : vec_free (cfun->su->dallocs);
973 : 0 : cfun->su->dallocs = NULL;
974 : : }
975 : :
976 : 1 : fputs ("\" }\n", f);
977 : :
978 : 1 : unsigned i;
979 : 1 : callinfo_callee *c;
980 : 2 : FOR_EACH_VEC_SAFE_ELT (cfun->su->callees, i, c)
981 : 0 : dump_final_callee_vcg (f, c->location, c->decl);
982 : 1 : vec_free (cfun->su->callees);
983 : 1 : cfun->su->callees = NULL;
984 : :
985 : 1 : cgraph_node *node = cgraph_node::get (current_function_decl);
986 : 1 : if (!node)
987 : 1 : return;
988 : 1 : node->call_for_symbol_thunks_and_aliases (dump_final_alias_vcg, f,
989 : : true, false);
990 : : }
991 : :
992 : : /* Output stack usage and callgraph info, as requested. */
993 : : void
994 : 356 : output_stack_usage (void)
995 : : {
996 : 356 : if (flag_callgraph_info)
997 : 1 : dump_final_node_vcg (callgraph_info_file);
998 : : else
999 : 355 : output_stack_usage_1 (NULL);
1000 : 356 : }
1001 : :
1002 : : /* Open an auxiliary output file. */
1003 : : static FILE *
1004 : 312 : open_auxiliary_file (const char *ext)
1005 : : {
1006 : 312 : char *filename;
1007 : 312 : FILE *file;
1008 : :
1009 : 312 : filename = concat (aux_base_name, ".", ext, NULL);
1010 : 312 : file = fopen (filename, "w");
1011 : 312 : if (!file)
1012 : 0 : fatal_error (input_location, "cannot open %s for writing: %m", filename);
1013 : 312 : free (filename);
1014 : 312 : return file;
1015 : : }
1016 : :
1017 : : /* Alternative diagnostics callback for reentered ICE reporting. */
1018 : :
1019 : : static void
1020 : 0 : internal_error_reentered (diagnostic_context *, const char *, va_list *)
1021 : : {
1022 : : /* Flush the dump file if emergency_dump_function itself caused an ICE. */
1023 : 0 : if (dump_file)
1024 : 0 : fflush (dump_file);
1025 : 0 : }
1026 : :
1027 : : /* Auxiliary callback for the diagnostics code. */
1028 : :
1029 : : static void
1030 : 23 : internal_error_function (diagnostic_context *, const char *, va_list *)
1031 : : {
1032 : 23 : global_dc->m_internal_error = internal_error_reentered;
1033 : 23 : warn_if_plugins ();
1034 : 23 : emergency_dump_function ();
1035 : 23 : }
1036 : :
1037 : : /* Initialization of the front end environment, before command line
1038 : : options are parsed. Signal handlers, internationalization etc.
1039 : : ARGV0 is main's argv[0]. */
1040 : : static void
1041 : 285081 : general_init (const char *argv0, bool init_signals, unique_argv original_argv)
1042 : : {
1043 : 285081 : const char *p;
1044 : :
1045 : 285081 : p = argv0 + strlen (argv0);
1046 : 1652662 : while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1047 : 1367581 : --p;
1048 : 285081 : progname = p;
1049 : :
1050 : 285081 : xmalloc_set_program_name (progname);
1051 : :
1052 : 285081 : hex_init ();
1053 : :
1054 : : /* Unlock the stdio streams. */
1055 : 285081 : unlock_std_streams ();
1056 : :
1057 : 285081 : gcc_init_libintl ();
1058 : :
1059 : 285081 : identifier_to_locale_alloc = alloc_for_identifier_to_locale;
1060 : 285081 : identifier_to_locale_free = ggc_free;
1061 : :
1062 : : /* Initialize the diagnostics reporting machinery, so option parsing
1063 : : can give warnings and errors. */
1064 : 285081 : diagnostic_initialize (global_dc, N_OPTS);
1065 : : /* Set a default printer. Language specific initializations will
1066 : : override it later. */
1067 : 285081 : tree_diagnostics_defaults (global_dc);
1068 : :
1069 : 285081 : global_dc->set_original_argv (std::move (original_argv));
1070 : :
1071 : 285081 : global_dc->m_source_printing.enabled
1072 : 285081 : = global_options_init.x_flag_diagnostics_show_caret;
1073 : 285081 : global_dc->m_source_printing.show_event_links_p
1074 : 285081 : = global_options_init.x_flag_diagnostics_show_event_links;
1075 : 285081 : global_dc->m_source_printing.show_labels_p
1076 : 285081 : = global_options_init.x_flag_diagnostics_show_labels;
1077 : 285081 : global_dc->m_source_printing.show_line_numbers_p
1078 : 285081 : = global_options_init.x_flag_diagnostics_show_line_numbers;
1079 : 285081 : global_dc->set_show_cwe (global_options_init.x_flag_diagnostics_show_cwe);
1080 : 285081 : global_dc->set_show_rules (global_options_init.x_flag_diagnostics_show_rules);
1081 : 285081 : global_dc->set_path_format
1082 : 285081 : ((enum diagnostic_path_format)
1083 : 285081 : global_options_init.x_flag_diagnostics_path_format);
1084 : 285081 : global_dc->set_show_path_depths
1085 : 285081 : (global_options_init.x_flag_diagnostics_show_path_depths);
1086 : 285081 : global_dc->set_show_option_requested
1087 : 285081 : (global_options_init.x_flag_diagnostics_show_option);
1088 : 285081 : global_dc->m_source_printing.min_margin_width
1089 : 285081 : = global_options_init.x_diagnostics_minimum_margin_width;
1090 : 285081 : global_dc->m_show_column
1091 : 285081 : = global_options_init.x_flag_show_column;
1092 : 285081 : global_dc->set_show_highlight_colors
1093 : 285081 : (global_options_init.x_flag_diagnostics_show_highlight_colors);
1094 : 285081 : global_dc->m_internal_error = internal_error_function;
1095 : 285081 : const unsigned lang_mask = lang_hooks.option_lang_mask ();
1096 : 285081 : global_dc->set_option_manager
1097 : 285081 : (std::make_unique<compiler_diagnostic_option_manager> (*global_dc,
1098 : : lang_mask,
1099 : 285081 : &global_options),
1100 : : lang_mask);
1101 : 285081 : global_dc->push_owned_urlifier (make_gcc_urlifier (lang_mask));
1102 : :
1103 : 285081 : if (init_signals)
1104 : : {
1105 : : /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1106 : : #ifdef SIGSEGV
1107 : 283827 : signal (SIGSEGV, crash_signal);
1108 : : #endif
1109 : : #ifdef SIGILL
1110 : 283827 : signal (SIGILL, crash_signal);
1111 : : #endif
1112 : : #ifdef SIGBUS
1113 : 283827 : signal (SIGBUS, crash_signal);
1114 : : #endif
1115 : : #ifdef SIGABRT
1116 : 283827 : signal (SIGABRT, crash_signal);
1117 : : #endif
1118 : : #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1119 : : signal (SIGIOT, crash_signal);
1120 : : #endif
1121 : : #ifdef SIGFPE
1122 : 283827 : signal (SIGFPE, crash_signal);
1123 : : #endif
1124 : :
1125 : : /* Other host-specific signal setup. */
1126 : 283827 : (*host_hooks.extra_signals)();
1127 : : }
1128 : :
1129 : : /* Initialize the garbage-collector, string pools and tree type hash
1130 : : table. */
1131 : 285081 : init_ggc ();
1132 : 285081 : init_stringpool ();
1133 : 285081 : input_location = UNKNOWN_LOCATION;
1134 : 285081 : line_table = ggc_alloc<line_maps> ();
1135 : 285081 : linemap_init (line_table, BUILTINS_LOCATION);
1136 : 285081 : line_table->m_reallocator = realloc_for_line_map;
1137 : 285081 : line_table->m_round_alloc_size = ggc_round_alloc_size;
1138 : 285081 : line_table->default_range_bits = line_map_suggested_range_bits;
1139 : 285081 : init_ttree ();
1140 : :
1141 : : /* Initialize register usage now so switches may override. */
1142 : 285081 : init_reg_sets ();
1143 : :
1144 : : /* Create the singleton holder for global state. This creates the
1145 : : dump manager. */
1146 : 285081 : g = new gcc::context ();
1147 : :
1148 : : /* Allow languages and middle-end to register their dumps before the
1149 : : optimization passes. */
1150 : 285081 : g->get_dumps ()->register_dumps ();
1151 : :
1152 : : /* Create the passes. */
1153 : 285081 : g->set_passes (new gcc::pass_manager (g));
1154 : :
1155 : 285081 : symtab = new (ggc_alloc <symbol_table> ()) symbol_table ();
1156 : :
1157 : 285081 : statistics_early_init ();
1158 : 285081 : debuginfo_early_init ();
1159 : 285081 : }
1160 : :
1161 : : /* Return true if the current target supports -fsection-anchors. */
1162 : :
1163 : : static bool
1164 : 0 : target_supports_section_anchors_p (void)
1165 : : {
1166 : 0 : if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1167 : : return false;
1168 : :
1169 : 0 : if (targetm.asm_out.output_anchor == NULL)
1170 : 0 : return false;
1171 : :
1172 : : return true;
1173 : : }
1174 : :
1175 : : /* Parse "N[:M][:...]" into struct align_flags A.
1176 : : VALUES contains parsed values (in reverse order), all processed
1177 : : values are popped. */
1178 : :
1179 : : static void
1180 : 585981 : read_log_maxskip (auto_vec<unsigned> &values, align_flags_tuple *a)
1181 : : {
1182 : 585981 : unsigned n = values.pop ();
1183 : 585981 : if (n != 0)
1184 : 468795 : a->log = floor_log2 (n * 2 - 1);
1185 : :
1186 : 585981 : if (values.is_empty ())
1187 : 351584 : a->maxskip = n ? n - 1 : 0;
1188 : : else
1189 : : {
1190 : 234397 : unsigned m = values.pop ();
1191 : : /* -falign-foo=N:M means M-1 max bytes of padding, not M. */
1192 : 234397 : if (m > 0)
1193 : 117211 : m--;
1194 : 234397 : a->maxskip = m;
1195 : : }
1196 : :
1197 : : /* Normalize the tuple. */
1198 : 585981 : a->normalize ();
1199 : 585981 : }
1200 : :
1201 : : /* Parse "N[:M[:N2[:M2]]]" string FLAG into a pair of struct align_flags. */
1202 : :
1203 : : static void
1204 : 2740155488 : parse_N_M (const char *flag, align_flags &a)
1205 : : {
1206 : 2740155488 : if (flag)
1207 : : {
1208 : 2489147622 : static hash_map <nofree_string_hash, align_flags> cache;
1209 : 2489147622 : align_flags *entry = cache.get (flag);
1210 : 2489147622 : if (entry)
1211 : : {
1212 : 2488796035 : a = *entry;
1213 : 2488796035 : return;
1214 : : }
1215 : :
1216 : 351587 : auto_vec<unsigned> result_values;
1217 : 351587 : bool r = parse_and_check_align_values (flag, NULL, result_values, false,
1218 : : UNKNOWN_LOCATION);
1219 : 351587 : if (!r)
1220 : 0 : return;
1221 : :
1222 : : /* Reverse values for easier manipulation. */
1223 : 351587 : result_values.reverse ();
1224 : :
1225 : 351587 : read_log_maxskip (result_values, &a.levels[0]);
1226 : 351587 : if (!result_values.is_empty ())
1227 : 234394 : read_log_maxskip (result_values, &a.levels[1]);
1228 : : #ifdef SUBALIGN_LOG
1229 : : else
1230 : : {
1231 : : /* N2[:M2] is not specified. This arch has a default for N2.
1232 : : Before -falign-foo=N:M:N2:M2 was introduced, x86 had a tweak.
1233 : : -falign-functions=N with N > 8 was adding secondary alignment.
1234 : : -falign-functions=10 was emitting this before every function:
1235 : : .p2align 4,,9
1236 : : .p2align 3
1237 : : Now this behavior (and more) can be explicitly requested:
1238 : : -falign-functions=16:10:8
1239 : : Retain old behavior if N2 is missing: */
1240 : :
1241 : 117193 : int align = 1 << a.levels[0].log;
1242 : 117193 : int subalign = 1 << SUBALIGN_LOG;
1243 : :
1244 : 117193 : if (a.levels[0].log > SUBALIGN_LOG
1245 : 117192 : && a.levels[0].maxskip >= subalign - 1)
1246 : : {
1247 : : /* Set N2 unless subalign can never have any effect. */
1248 : 117192 : if (align > a.levels[0].maxskip + 1)
1249 : : {
1250 : 32 : a.levels[1].log = SUBALIGN_LOG;
1251 : 32 : a.levels[1].normalize ();
1252 : : }
1253 : : }
1254 : : }
1255 : : #endif
1256 : :
1257 : : /* Cache seen value. */
1258 : 351587 : cache.put (flag, a);
1259 : 351587 : }
1260 : : }
1261 : :
1262 : : /* Process -falign-foo=N[:M[:N2[:M2]]] options. */
1263 : :
1264 : : void
1265 : 685038872 : parse_alignment_opts (void)
1266 : : {
1267 : 685038872 : parse_N_M (str_align_loops, align_loops);
1268 : 685038872 : parse_N_M (str_align_jumps, align_jumps);
1269 : 685038872 : parse_N_M (str_align_labels, align_labels);
1270 : 685038872 : parse_N_M (str_align_functions, align_functions);
1271 : 685038872 : }
1272 : :
1273 : : /* Process the options that have been parsed. */
1274 : : static void
1275 : 284977 : process_options ()
1276 : : {
1277 : 284977 : const char *language_string = lang_hooks.name;
1278 : :
1279 : 284977 : maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
1280 : :
1281 : : /* Some machines may reject certain combinations of options. */
1282 : 284977 : location_t saved_location = input_location;
1283 : 284977 : input_location = UNKNOWN_LOCATION;
1284 : 284977 : targetm.target_option.override ();
1285 : 284977 : input_location = saved_location;
1286 : :
1287 : 284977 : if (flag_diagnostics_generate_patch)
1288 : 17 : global_dc->create_edit_context ();
1289 : :
1290 : : /* Avoid any informative notes in the second run of -fcompare-debug. */
1291 : 284977 : if (flag_compare_debug)
1292 : 619 : diagnostic_inhibit_notes (global_dc);
1293 : :
1294 : 284977 : if (flag_section_anchors && !target_supports_section_anchors_p ())
1295 : : {
1296 : 0 : warning_at (UNKNOWN_LOCATION, OPT_fsection_anchors,
1297 : : "this target does not support %qs",
1298 : : "-fsection-anchors");
1299 : 0 : flag_section_anchors = 0;
1300 : : }
1301 : :
1302 : 284977 : if (!OPTION_SET_P (flag_short_enums))
1303 : 284849 : flag_short_enums = targetm.default_short_enums ();
1304 : :
1305 : : /* Set aux_base_name if not already set. */
1306 : 284977 : if (aux_base_name)
1307 : : ;
1308 : 284977 : else if (dump_base_name)
1309 : : {
1310 : 282285 : const char *name = dump_base_name;
1311 : 282285 : int nlen, len;
1312 : :
1313 : 260134 : if (dump_base_ext && (len = strlen (dump_base_ext))
1314 : 260134 : && (nlen = strlen (name)) && nlen > len
1315 : 542419 : && strcmp (name + nlen - len, dump_base_ext) == 0)
1316 : : {
1317 : 260134 : char *p = xstrndup (name, nlen - len);
1318 : 260134 : name = p;
1319 : : }
1320 : :
1321 : 282285 : aux_base_name = name;
1322 : : }
1323 : : else
1324 : 2692 : aux_base_name = "gccaux";
1325 : :
1326 : : #ifndef HAVE_isl
1327 : : if (flag_graphite
1328 : : || flag_loop_nest_optimize
1329 : : || flag_graphite_identity
1330 : : || flag_loop_parallelize_all)
1331 : : sorry ("Graphite loop optimizations cannot be used (isl is not available) "
1332 : : "(%<-fgraphite%>, %<-fgraphite-identity%>, "
1333 : : "%<-floop-nest-optimize%>, %<-floop-parallelize-all%>)");
1334 : : #endif
1335 : :
1336 : 284977 : if (flag_cf_protection != CF_NONE
1337 : 20264 : && !(flag_cf_protection & CF_SET))
1338 : : {
1339 : 0 : if (flag_cf_protection == CF_FULL)
1340 : : {
1341 : 0 : error_at (UNKNOWN_LOCATION,
1342 : : "%<-fcf-protection=full%> is not supported for this "
1343 : : "target");
1344 : 0 : flag_cf_protection = CF_NONE;
1345 : : }
1346 : 0 : if (flag_cf_protection == CF_BRANCH)
1347 : : {
1348 : 0 : error_at (UNKNOWN_LOCATION,
1349 : : "%<-fcf-protection=branch%> is not supported for this "
1350 : : "target");
1351 : 0 : flag_cf_protection = CF_NONE;
1352 : : }
1353 : 0 : if (flag_cf_protection == CF_RETURN)
1354 : : {
1355 : 0 : error_at (UNKNOWN_LOCATION,
1356 : : "%<-fcf-protection=return%> is not supported for this "
1357 : : "target");
1358 : 0 : flag_cf_protection = CF_NONE;
1359 : : }
1360 : : }
1361 : :
1362 : : /* One region RA really helps to decrease the code size. */
1363 : 284977 : if (!OPTION_SET_P (flag_ira_region))
1364 : 284974 : flag_ira_region
1365 : 413619 : = optimize_size || !optimize ? IRA_REGION_ONE : IRA_REGION_MIXED;
1366 : :
1367 : 284977 : if (!abi_version_at_least (2))
1368 : : {
1369 : : /* -fabi-version=1 support was removed after GCC 4.9. */
1370 : 0 : error_at (UNKNOWN_LOCATION,
1371 : : "%<-fabi-version=1%> is no longer supported");
1372 : 0 : flag_abi_version = 2;
1373 : : }
1374 : :
1375 : 284977 : if (flag_non_call_exceptions)
1376 : 5504 : flag_asynchronous_unwind_tables = 1;
1377 : 284977 : if (flag_asynchronous_unwind_tables)
1378 : 284949 : flag_unwind_tables = 1;
1379 : :
1380 : 284977 : if (flag_value_profile_transformations)
1381 : 151 : flag_profile_values = 1;
1382 : :
1383 : : /* Warn about options that are not supported on this machine. */
1384 : : #ifndef INSN_SCHEDULING
1385 : : if (flag_schedule_insns || flag_schedule_insns_after_reload)
1386 : : warning_at (UNKNOWN_LOCATION, 0,
1387 : : "instruction scheduling not supported on this target machine");
1388 : : #endif
1389 : 284977 : if (!DELAY_SLOTS && flag_delayed_branch)
1390 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1391 : : "this target machine does not have delayed branches");
1392 : :
1393 : 284977 : user_label_prefix = USER_LABEL_PREFIX;
1394 : 284977 : if (flag_leading_underscore != -1)
1395 : : {
1396 : : /* If the default prefix is more complicated than "" or "_",
1397 : : issue a warning and ignore this option. */
1398 : 3 : if (user_label_prefix[0] == 0 ||
1399 : : (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1400 : : {
1401 : 3 : user_label_prefix = flag_leading_underscore ? "_" : "";
1402 : : }
1403 : : else
1404 : : warning_at (UNKNOWN_LOCATION, 0,
1405 : : "%<-f%sleading-underscore%> not supported on this "
1406 : : "target machine", flag_leading_underscore ? "" : "no-");
1407 : : }
1408 : :
1409 : : /* If we are in verbose mode, write out the version and maybe all the
1410 : : option flags in use. */
1411 : 284977 : if (version_flag)
1412 : : {
1413 : : /* We already printed the version header in main (). */
1414 : 109 : if (!quiet_flag)
1415 : : {
1416 : 0 : fputs ("options passed: ", stderr);
1417 : 0 : char *cmdline = gen_command_line_string (save_decoded_options,
1418 : : save_decoded_options_count);
1419 : :
1420 : 0 : fputs (cmdline, stderr);
1421 : 0 : free (cmdline);
1422 : 0 : fputc ('\n', stderr);
1423 : : }
1424 : : }
1425 : :
1426 : : /* CTF is supported for only C at this time. */
1427 : 284977 : if (!lang_GNU_C ()
1428 : 284977 : && ctf_debug_info_level > CTFINFO_LEVEL_NONE)
1429 : : {
1430 : : /* Compiling with -flto results in frontend language of GNU GIMPLE. It
1431 : : is not useful to warn in that case. */
1432 : 52 : if (!startswith (lang_hooks.name, "GNU GIMPLE"))
1433 : 50 : inform (UNKNOWN_LOCATION,
1434 : : "CTF debug info requested, but not supported for %qs frontend",
1435 : : language_string);
1436 : 52 : ctf_debug_info_level = CTFINFO_LEVEL_NONE;
1437 : : }
1438 : :
1439 : 284977 : if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1440 : : {
1441 : 1239 : FILE *final_output = fopen (flag_dump_final_insns, "w");
1442 : 1239 : if (!final_output)
1443 : : {
1444 : 0 : error_at (UNKNOWN_LOCATION,
1445 : : "could not open final insn dump file %qs: %m",
1446 : : flag_dump_final_insns);
1447 : 0 : flag_dump_final_insns = NULL;
1448 : : }
1449 : 1239 : else if (fclose (final_output))
1450 : : {
1451 : 0 : error_at (UNKNOWN_LOCATION,
1452 : : "could not close zeroed insn dump file %qs: %m",
1453 : : flag_dump_final_insns);
1454 : 0 : flag_dump_final_insns = NULL;
1455 : : }
1456 : : }
1457 : :
1458 : : /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1459 : : level is 0. */
1460 : 284977 : if (debug_info_level == DINFO_LEVEL_NONE
1461 : 226796 : && ctf_debug_info_level == CTFINFO_LEVEL_NONE)
1462 : 226792 : write_symbols = NO_DEBUG;
1463 : :
1464 : 284977 : if (write_symbols == NO_DEBUG)
1465 : : ;
1466 : : #ifdef DWARF2_DEBUGGING_INFO
1467 : 58185 : else if (dwarf_debuginfo_p ())
1468 : 57748 : debug_hooks = &dwarf2_debug_hooks;
1469 : : #endif
1470 : : #ifdef CTF_DEBUGGING_INFO
1471 : 437 : else if (ctf_debuginfo_p ())
1472 : 338 : debug_hooks = &dwarf2_debug_hooks;
1473 : : #endif
1474 : : #ifdef BTF_DEBUGGING_INFO
1475 : 99 : else if (btf_debuginfo_p ())
1476 : 99 : debug_hooks = &dwarf2_debug_hooks;
1477 : : #endif
1478 : : #ifdef VMS_DEBUGGING_INFO
1479 : : else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1480 : : debug_hooks = &vmsdbg_debug_hooks;
1481 : : #endif
1482 : : #ifdef DWARF2_LINENO_DEBUGGING_INFO
1483 : : else if (write_symbols == DWARF2_DEBUG)
1484 : : debug_hooks = &dwarf2_lineno_debug_hooks;
1485 : : #endif
1486 : : #ifdef CODEVIEW_DEBUGGING_INFO
1487 : : else if (codeview_debuginfo_p ())
1488 : : debug_hooks = &dwarf2_debug_hooks;
1489 : : #endif
1490 : : else
1491 : : {
1492 : 0 : gcc_assert (debug_set_count (write_symbols) <= 1);
1493 : 0 : error_at (UNKNOWN_LOCATION,
1494 : : "target system does not support the %qs debug format",
1495 : 0 : debug_type_names[debug_set_to_format (write_symbols)]);
1496 : : }
1497 : :
1498 : : /* The debug hooks are used to implement -fdump-go-spec because it
1499 : : gives a simple and stable API for all the information we need to
1500 : : dump. */
1501 : 284977 : if (flag_dump_go_spec != NULL)
1502 : 4 : debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
1503 : :
1504 : 284977 : if (!OPTION_SET_P (dwarf2out_as_loc_support))
1505 : 284971 : dwarf2out_as_loc_support = dwarf2out_default_as_loc_support ();
1506 : 284977 : if (!OPTION_SET_P (dwarf2out_as_locview_support))
1507 : 284977 : dwarf2out_as_locview_support = dwarf2out_default_as_locview_support ();
1508 : 284977 : if (dwarf2out_as_locview_support && !dwarf2out_as_loc_support)
1509 : : {
1510 : 6 : if (OPTION_SET_P (dwarf2out_as_locview_support))
1511 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1512 : : "%<-gas-locview-support%> is forced disabled "
1513 : : "without %<-gas-loc-support%>");
1514 : 6 : dwarf2out_as_locview_support = false;
1515 : : }
1516 : :
1517 : 284977 : if (!OPTION_SET_P (debug_variable_location_views))
1518 : : {
1519 : 284977 : debug_variable_location_views
1520 : 569954 : = (flag_var_tracking
1521 : 49314 : && debug_info_level >= DINFO_LEVEL_NORMAL
1522 : 49314 : && dwarf_debuginfo_p ()
1523 : 569955 : && !dwarf_strict);
1524 : : }
1525 : 0 : else if (debug_variable_location_views == -1 && dwarf_version != 5)
1526 : : {
1527 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1528 : : "without %<-gdwarf-5%>, "
1529 : : "%<-gvariable-location-views=incompat5%> "
1530 : : "is equivalent to %<-gvariable-location-views%>");
1531 : 0 : debug_variable_location_views = 1;
1532 : : }
1533 : :
1534 : 284977 : if (debug_internal_reset_location_views == 2)
1535 : : {
1536 : 284977 : debug_internal_reset_location_views
1537 : 569954 : = (debug_variable_location_views
1538 : 569954 : && targetm.reset_location_view);
1539 : : }
1540 : 0 : else if (debug_internal_reset_location_views
1541 : 0 : && !debug_variable_location_views)
1542 : : {
1543 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1544 : : "%<-ginternal-reset-location-views%> is forced disabled "
1545 : : "without %<-gvariable-location-views%>");
1546 : 0 : debug_internal_reset_location_views = 0;
1547 : : }
1548 : :
1549 : 284977 : if (!OPTION_SET_P (debug_inline_points))
1550 : 284977 : debug_inline_points = debug_variable_location_views;
1551 : 0 : else if (debug_inline_points && !debug_nonbind_markers_p)
1552 : : {
1553 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1554 : : "%<-ginline-points%> is forced disabled without "
1555 : : "%<-gstatement-frontiers%>");
1556 : 0 : debug_inline_points = 0;
1557 : : }
1558 : :
1559 : 284977 : if (!OPTION_SET_P (flag_tree_cselim))
1560 : : {
1561 : 284949 : if (HAVE_conditional_move)
1562 : 284949 : flag_tree_cselim = 1;
1563 : : else
1564 : : flag_tree_cselim = 0;
1565 : : }
1566 : :
1567 : : /* If auxiliary info generation is desired, open the output file.
1568 : : This goes in the same directory as the source file--unlike
1569 : : all the other output files. */
1570 : 284977 : if (flag_gen_aux_info)
1571 : : {
1572 : 0 : aux_info_file = fopen (aux_info_file_name, "w");
1573 : 0 : if (aux_info_file == 0)
1574 : 0 : fatal_error (UNKNOWN_LOCATION,
1575 : : "cannot open %s: %m", aux_info_file_name);
1576 : : }
1577 : :
1578 : 284977 : if (!targetm_common.have_named_sections)
1579 : : {
1580 : 0 : if (flag_function_sections)
1581 : : {
1582 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1583 : : "%<-ffunction-sections%> not supported for this target");
1584 : 0 : flag_function_sections = 0;
1585 : : }
1586 : 0 : if (flag_data_sections)
1587 : : {
1588 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1589 : : "%<-fdata-sections%> not supported for this target");
1590 : 0 : flag_data_sections = 0;
1591 : : }
1592 : : }
1593 : :
1594 : 284977 : if (flag_prefetch_loop_arrays > 0 && !targetm.code_for_prefetch)
1595 : : {
1596 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1597 : : "%<-fprefetch-loop-arrays%> not supported for this target");
1598 : 0 : flag_prefetch_loop_arrays = 0;
1599 : : }
1600 : 284977 : else if (flag_prefetch_loop_arrays > 0 && !targetm.have_prefetch ())
1601 : : {
1602 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1603 : : "%<-fprefetch-loop-arrays%> not supported for this target "
1604 : : "(try %<-march%> switches)");
1605 : 0 : flag_prefetch_loop_arrays = 0;
1606 : : }
1607 : :
1608 : : /* This combination of options isn't handled for i386 targets and doesn't
1609 : : make much sense anyway, so don't allow it. */
1610 : 284977 : if (flag_prefetch_loop_arrays > 0 && optimize_size)
1611 : : {
1612 : 2 : warning_at (UNKNOWN_LOCATION, 0,
1613 : : "%<-fprefetch-loop-arrays%> is not supported with %<-Os%>");
1614 : 2 : flag_prefetch_loop_arrays = 0;
1615 : : }
1616 : :
1617 : : /* The presence of IEEE signaling NaNs, implies all math can trap. */
1618 : 284977 : if (flag_signaling_nans)
1619 : 583 : flag_trapping_math = 1;
1620 : :
1621 : : /* We cannot reassociate if we want traps or signed zeros. */
1622 : 284977 : if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1623 : : {
1624 : 18 : warning_at (UNKNOWN_LOCATION, 0,
1625 : : "%<-fassociative-math%> disabled; other options take "
1626 : : "precedence");
1627 : 18 : flag_associative_math = 0;
1628 : : }
1629 : :
1630 : 284977 : if (flag_hardened && !HAVE_FHARDENED_SUPPORT)
1631 : : {
1632 : : warning_at (UNKNOWN_LOCATION, 0,
1633 : : "%<-fhardened%> not supported for this target");
1634 : : flag_hardened = 0;
1635 : : }
1636 : :
1637 : : /* -fstack-clash-protection is not currently supported on targets
1638 : : where the stack grows up. */
1639 : 284977 : if (flag_stack_clash_protection && !STACK_GROWS_DOWNWARD)
1640 : : {
1641 : : warning_at (UNKNOWN_LOCATION, 0,
1642 : : "%<-fstack-clash-protection%> is not supported on targets "
1643 : : "where the stack grows from lower to higher addresses");
1644 : : flag_stack_clash_protection = 0;
1645 : : }
1646 : 284977 : else if (flag_hardened)
1647 : : {
1648 : 91 : if (!flag_stack_clash_protection
1649 : : /* Don't enable -fstack-clash-protection when -fstack-check=
1650 : : is used: it would result in confusing errors. */
1651 : 91 : && flag_stack_check == NO_STACK_CHECK)
1652 : 87 : flag_stack_clash_protection = 1;
1653 : 4 : else if (flag_stack_check != NO_STACK_CHECK)
1654 : 4 : warning_at (UNKNOWN_LOCATION, OPT_Whardened,
1655 : : "%<-fstack-clash-protection%> is not enabled by "
1656 : : "%<-fhardened%> because %<-fstack-check%> was "
1657 : : "specified on the command line");
1658 : : }
1659 : :
1660 : : /* We cannot support -fstack-check= and -fstack-clash-protection at
1661 : : the same time. */
1662 : 284977 : if (flag_stack_check != NO_STACK_CHECK && flag_stack_clash_protection)
1663 : : {
1664 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1665 : : "%<-fstack-check=%> and %<-fstack-clash-protection%> are "
1666 : : "mutually exclusive; disabling %<-fstack-check=%>");
1667 : 0 : flag_stack_check = NO_STACK_CHECK;
1668 : : }
1669 : :
1670 : : /* Targets must be able to place spill slots at lower addresses. If the
1671 : : target already uses a soft frame pointer, the transition is trivial. */
1672 : 284977 : if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1673 : : {
1674 : : if (!flag_stack_protector_set_by_fhardened_p)
1675 : : warning_at (UNKNOWN_LOCATION, 0,
1676 : : "%<-fstack-protector%> not supported for this target");
1677 : : flag_stack_protect = 0;
1678 : : }
1679 : 284977 : if (!flag_stack_protect)
1680 : 284693 : warn_stack_protect = 0;
1681 : :
1682 : : /* Address Sanitizer needs porting to each target architecture. */
1683 : :
1684 : 284977 : if ((flag_sanitize & SANITIZE_ADDRESS)
1685 : : && !FRAME_GROWS_DOWNWARD)
1686 : : {
1687 : : warning_at (UNKNOWN_LOCATION, 0,
1688 : : "%<-fsanitize=address%> and %<-fsanitize=kernel-address%> "
1689 : : "are not supported for this target");
1690 : : flag_sanitize &= ~SANITIZE_ADDRESS;
1691 : : }
1692 : :
1693 : 284977 : if ((flag_sanitize & SANITIZE_USER_ADDRESS)
1694 : 284977 : && ((targetm.asan_shadow_offset == NULL)
1695 : 2862 : || ((targetm.asan_shadow_offset () == 0)
1696 : 0 : && !targetm.asan_dynamic_shadow_offset_p ())))
1697 : : {
1698 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1699 : : "%<-fsanitize=address%> not supported for this target");
1700 : 0 : flag_sanitize &= ~SANITIZE_ADDRESS;
1701 : : }
1702 : :
1703 : 284977 : if ((flag_sanitize & SANITIZE_KERNEL_ADDRESS)
1704 : 284977 : && (targetm.asan_shadow_offset == NULL
1705 : 0 : && !asan_shadow_offset_set_p ()))
1706 : : {
1707 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1708 : : "%<-fsanitize=kernel-address%> with stack protection "
1709 : : "is not supported without %<-fasan-shadow-offset=%> "
1710 : : "for this target");
1711 : 0 : flag_sanitize &= ~SANITIZE_ADDRESS;
1712 : : }
1713 : :
1714 : : /* HWAsan requires top byte ignore feature in the backend. */
1715 : 284977 : if (flag_sanitize & SANITIZE_HWADDRESS
1716 : 284977 : && ! targetm.memtag.can_tag_addresses ())
1717 : : {
1718 : 0 : warning_at (UNKNOWN_LOCATION, 0, "%qs is not supported for this target",
1719 : : "-fsanitize=hwaddress");
1720 : 0 : flag_sanitize &= ~SANITIZE_HWADDRESS;
1721 : : }
1722 : :
1723 : 284977 : if (flag_sanitize & SANITIZE_SHADOW_CALL_STACK)
1724 : : {
1725 : 0 : if (!targetm.have_shadow_call_stack)
1726 : 0 : sorry ("%<-fsanitize=shadow-call-stack%> not supported "
1727 : : "in current platform");
1728 : 0 : else if (flag_exceptions)
1729 : 0 : error_at (UNKNOWN_LOCATION, "%<-fsanitize=shadow-call-stack%> "
1730 : : "requires %<-fno-exceptions%>");
1731 : : }
1732 : :
1733 : 284977 : HOST_WIDE_INT patch_area_size, patch_area_start;
1734 : 284977 : parse_and_check_patch_area (flag_patchable_function_entry, false,
1735 : : &patch_area_size, &patch_area_start);
1736 : :
1737 : : /* Do not use IPA optimizations for register allocation if profiler is active
1738 : : or patchable function entries are inserted for run-time instrumentation
1739 : : or port does not emit prologue and epilogue as RTL. */
1740 : 284626 : if (profile_flag || patch_area_size
1741 : 569570 : || !targetm.have_prologue () || !targetm.have_epilogue ())
1742 : 384 : flag_ipa_ra = 0;
1743 : :
1744 : : /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
1745 : : have not been set. */
1746 : 284977 : if (!OPTION_SET_P (warnings_are_errors))
1747 : : {
1748 : 280647 : if (warn_coverage_mismatch
1749 : 280647 : && option_unspecified_p (OPT_Wcoverage_mismatch))
1750 : 280641 : diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
1751 : : DK_ERROR, UNKNOWN_LOCATION);
1752 : 280647 : if (warn_coverage_invalid_linenum
1753 : 280647 : && option_unspecified_p (OPT_Wcoverage_invalid_line_number))
1754 : 280646 : diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_invalid_line_number,
1755 : : DK_ERROR, UNKNOWN_LOCATION);
1756 : : }
1757 : :
1758 : : /* Save the current optimization options. */
1759 : 284977 : optimization_default_node
1760 : 284977 : = build_optimization_node (&global_options, &global_options_set);
1761 : 284977 : optimization_current_node = optimization_default_node;
1762 : :
1763 : 284977 : if (flag_checking >= 2)
1764 : 284913 : hash_table_sanitize_eq_limit
1765 : 284913 : = param_hash_table_verification_limit;
1766 : :
1767 : 284977 : diagnose_options (&global_options, &global_options_set, UNKNOWN_LOCATION);
1768 : :
1769 : : /* Please don't change global_options after this point, those changes won't
1770 : : be reflected in optimization_{default,current}_node. */
1771 : 284977 : }
1772 : :
1773 : : /* This function can be called multiple times to reinitialize the compiler
1774 : : back end when register classes or instruction sets have changed,
1775 : : before each function. */
1776 : : static void
1777 : 211512 : backend_init_target (void)
1778 : : {
1779 : : /* This depends on stack_pointer_rtx. */
1780 : 211512 : init_fake_stack_mems ();
1781 : :
1782 : : /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1783 : : mode-dependent. */
1784 : 211512 : init_alias_target ();
1785 : :
1786 : : /* Depends on HARD_FRAME_POINTER_REGNUM. */
1787 : 211512 : if (!ira_use_lra_p)
1788 : 0 : init_reload ();
1789 : :
1790 : : /* Depends on the enabled attribute. */
1791 : 211512 : recog_init ();
1792 : :
1793 : : /* The following initialization functions need to generate rtl, so
1794 : : provide a dummy function context for them. */
1795 : 211512 : init_dummy_function_start ();
1796 : :
1797 : : /* rtx_cost is mode-dependent, so cached values need to be recomputed
1798 : : on a mode change. */
1799 : 211512 : init_expmed ();
1800 : 211512 : init_lower_subreg ();
1801 : 211512 : init_set_costs ();
1802 : :
1803 : 211512 : init_expr_target ();
1804 : 211512 : ira_init ();
1805 : :
1806 : : /* We may need to recompute regno_save_code[] and regno_restore_code[]
1807 : : after a mode change as well. */
1808 : 211512 : caller_save_initialized_p = false;
1809 : :
1810 : 211512 : expand_dummy_function_end ();
1811 : 211512 : }
1812 : :
1813 : : /* Initialize the compiler back end. This function is called only once,
1814 : : when starting the compiler. */
1815 : : static void
1816 : 278687 : backend_init (void)
1817 : : {
1818 : 278687 : init_emit_once ();
1819 : :
1820 : 278687 : init_rtlanal ();
1821 : 278687 : init_inline_once ();
1822 : 278687 : init_varasm_once ();
1823 : 278687 : save_register_info ();
1824 : :
1825 : : /* Middle end needs this initialization for default mem attributes
1826 : : used by early calls to make_decl_rtl. */
1827 : 278687 : init_emit_regs ();
1828 : :
1829 : : /* Middle end needs this initialization for mode tables used to assign
1830 : : modes to vector variables. */
1831 : 278687 : init_regs ();
1832 : 278687 : }
1833 : :
1834 : : /* Initialize things that are both lang-dependent and target-dependent.
1835 : : This function can be called more than once if target parameters change. */
1836 : : static void
1837 : 782432 : lang_dependent_init_target (void)
1838 : : {
1839 : : /* This creates various _DECL nodes, so needs to be called after the
1840 : : front end is initialized. It also depends on the HAVE_xxx macros
1841 : : generated from the target machine description. */
1842 : 782432 : init_optabs ();
1843 : :
1844 : 782432 : gcc_assert (!this_target_rtl->target_specific_initialized);
1845 : 782432 : }
1846 : :
1847 : : /* Perform initializations that are lang-dependent or target-dependent.
1848 : : but matters only for late optimizations and RTL generation. */
1849 : :
1850 : : static int rtl_initialized;
1851 : :
1852 : : void
1853 : 1456252 : initialize_rtl (void)
1854 : : {
1855 : 1456252 : auto_timevar tv (g_timer, TV_INITIALIZE_RTL);
1856 : :
1857 : : /* Initialization done just once per compilation, but delayed
1858 : : till code generation. */
1859 : 1456252 : if (!rtl_initialized)
1860 : 207261 : ira_init_once ();
1861 : 1456252 : rtl_initialized = true;
1862 : :
1863 : : /* Target specific RTL backend initialization. */
1864 : 1456252 : if (!this_target_rtl->target_specific_initialized)
1865 : : {
1866 : 211512 : backend_init_target ();
1867 : 211512 : this_target_rtl->target_specific_initialized = true;
1868 : : }
1869 : 1456252 : }
1870 : :
1871 : : /* Language-dependent initialization. Returns nonzero on success. */
1872 : : static int
1873 : 284784 : lang_dependent_init (const char *name)
1874 : : {
1875 : 284784 : location_t save_loc = input_location;
1876 : 284784 : if (!dump_base_name)
1877 : : {
1878 : 2687 : dump_base_name = name && name[0] ? name : "gccdump";
1879 : :
1880 : : /* We do not want to derive a non-empty dumpbase-ext from an
1881 : : explicit -dumpbase argument, only from a defaulted
1882 : : dumpbase. */
1883 : 2687 : if (!dump_base_ext)
1884 : : {
1885 : 2687 : const char *base = lbasename (dump_base_name);
1886 : 2687 : const char *ext = strrchr (base, '.');
1887 : 2687 : if (ext)
1888 : 2687 : dump_base_ext = ext;
1889 : : }
1890 : : }
1891 : :
1892 : : /* Other front-end initialization. */
1893 : 284784 : input_location = BUILTINS_LOCATION;
1894 : 284784 : if (lang_hooks.init () == 0)
1895 : : return 0;
1896 : 278684 : input_location = save_loc;
1897 : :
1898 : 278684 : if (!flag_wpa)
1899 : : {
1900 : 270051 : init_asm_output (name);
1901 : :
1902 : 270051 : if (!flag_generate_lto && !flag_compare_debug)
1903 : : {
1904 : : /* If stack usage information is desired, open the output file. */
1905 : 245339 : if (flag_stack_usage)
1906 : 311 : stack_usage_file = open_auxiliary_file ("su");
1907 : :
1908 : : /* If call graph information is desired, open the output file. */
1909 : 245339 : if (flag_callgraph_info)
1910 : : {
1911 : 1 : callgraph_info_file = open_auxiliary_file ("ci");
1912 : : /* Write the file header. */
1913 : 1 : fprintf (callgraph_info_file,
1914 : : "graph: { title: \"%s\"\n", main_input_filename);
1915 : 1 : bitmap_obstack_initialize (NULL);
1916 : 1 : callgraph_info_external_printed = BITMAP_ALLOC (NULL);
1917 : : }
1918 : : }
1919 : : else
1920 : 24712 : flag_stack_usage = flag_callgraph_info = false;
1921 : : }
1922 : :
1923 : : /* This creates various _DECL nodes, so needs to be called after the
1924 : : front end is initialized. */
1925 : 278684 : init_eh ();
1926 : :
1927 : : /* Do the target-specific parts of the initialization. */
1928 : 278684 : lang_dependent_init_target ();
1929 : :
1930 : 278684 : if (!flag_wpa)
1931 : : {
1932 : : /* If dbx symbol table desired, initialize writing it and output the
1933 : : predefined types. */
1934 : 270051 : timevar_push (TV_SYMOUT);
1935 : :
1936 : : /* Now we have the correct original filename, we can initialize
1937 : : debug output. */
1938 : 270051 : (*debug_hooks->init) (name);
1939 : :
1940 : 270051 : timevar_pop (TV_SYMOUT);
1941 : : }
1942 : :
1943 : : return 1;
1944 : : }
1945 : :
1946 : :
1947 : : /* Reinitialize everything when target parameters, such as register usage,
1948 : : have changed. */
1949 : : void
1950 : 506074 : target_reinit (void)
1951 : : {
1952 : 506074 : if (no_backend)
1953 : 2326 : return;
1954 : :
1955 : 503748 : struct rtl_data saved_x_rtl;
1956 : 503748 : rtx *saved_regno_reg_rtx;
1957 : 503748 : tree saved_optimization_current_node;
1958 : 503748 : struct target_optabs *saved_this_fn_optabs;
1959 : :
1960 : : /* Temporarily switch to the default optimization node, so that
1961 : : *this_target_optabs is set to the default, not reflecting
1962 : : whatever a previous function used for the optimize
1963 : : attribute. */
1964 : 503748 : saved_optimization_current_node = optimization_current_node;
1965 : 503748 : saved_this_fn_optabs = this_fn_optabs;
1966 : 503748 : if (saved_optimization_current_node != optimization_default_node)
1967 : : {
1968 : 0 : optimization_current_node = optimization_default_node;
1969 : 0 : cl_optimization_restore
1970 : 0 : (&global_options, &global_options_set,
1971 : 0 : TREE_OPTIMIZATION (optimization_default_node));
1972 : : }
1973 : 503748 : this_fn_optabs = this_target_optabs;
1974 : :
1975 : : /* Save *crtl and regno_reg_rtx around the reinitialization
1976 : : to allow target_reinit being called even after prepare_function_start. */
1977 : 503748 : saved_regno_reg_rtx = regno_reg_rtx;
1978 : 503748 : if (saved_regno_reg_rtx)
1979 : : {
1980 : 5 : saved_x_rtl = *crtl;
1981 : 5 : memset (crtl, '\0', sizeof (*crtl));
1982 : 5 : regno_reg_rtx = NULL;
1983 : : }
1984 : :
1985 : 503748 : this_target_rtl->target_specific_initialized = false;
1986 : :
1987 : : /* This initializes hard_frame_pointer, and calls init_reg_modes_target()
1988 : : to initialize reg_raw_mode[]. */
1989 : 503748 : init_emit_regs ();
1990 : :
1991 : : /* This invokes target hooks to set fixed_reg[] etc, which is
1992 : : mode-dependent. */
1993 : 503748 : init_regs ();
1994 : :
1995 : : /* Reinitialize lang-dependent parts. */
1996 : 503748 : lang_dependent_init_target ();
1997 : :
1998 : : /* Restore the original optimization node. */
1999 : 503748 : if (saved_optimization_current_node != optimization_default_node)
2000 : : {
2001 : 0 : optimization_current_node = saved_optimization_current_node;
2002 : 0 : cl_optimization_restore (&global_options, &global_options_set,
2003 : 0 : TREE_OPTIMIZATION (optimization_current_node));
2004 : : }
2005 : 503748 : this_fn_optabs = saved_this_fn_optabs;
2006 : :
2007 : : /* Restore regno_reg_rtx at the end, as free_after_compilation from
2008 : : expand_dummy_function_end clears it. */
2009 : 503748 : if (saved_regno_reg_rtx)
2010 : : {
2011 : 5 : *crtl = saved_x_rtl;
2012 : 5 : regno_reg_rtx = saved_regno_reg_rtx;
2013 : 5 : saved_regno_reg_rtx = NULL;
2014 : : }
2015 : : }
2016 : :
2017 : : void
2018 : 0 : dump_memory_report (const char *header)
2019 : : {
2020 : : /* Print significant header. */
2021 : 0 : fputc ('\n', stderr);
2022 : 0 : for (unsigned i = 0; i < 80; i++)
2023 : 0 : fputc ('#', stderr);
2024 : 0 : fprintf (stderr, "\n# %-77s#\n", header);
2025 : 0 : for (unsigned i = 0; i < 80; i++)
2026 : 0 : fputc ('#', stderr);
2027 : 0 : fputs ("\n\n", stderr);
2028 : :
2029 : 0 : dump_line_table_statistics ();
2030 : 0 : ggc_print_statistics ();
2031 : 0 : stringpool_statistics ();
2032 : 0 : dump_tree_statistics ();
2033 : 0 : dump_gimple_statistics ();
2034 : 0 : dump_rtx_statistics ();
2035 : 0 : dump_alloc_pool_statistics ();
2036 : 0 : dump_bitmap_statistics ();
2037 : 0 : dump_hash_table_loc_statistics ();
2038 : 0 : dump_vec_loc_statistics ();
2039 : 0 : dump_ggc_loc_statistics ();
2040 : 0 : dump_alias_stats (stderr);
2041 : 0 : dump_pta_stats (stderr);
2042 : 0 : }
2043 : :
2044 : : /* Clean up: close opened files, etc. */
2045 : :
2046 : : static void
2047 : 282836 : finalize ()
2048 : : {
2049 : : /* Close the dump files. */
2050 : 282836 : if (flag_gen_aux_info)
2051 : : {
2052 : 0 : fclose (aux_info_file);
2053 : 0 : aux_info_file = NULL;
2054 : 0 : if (seen_error ())
2055 : 0 : unlink (aux_info_file_name);
2056 : : }
2057 : :
2058 : : /* Close non-debugging input and output files. Take special care to note
2059 : : whether fclose returns an error, since the pages might still be on the
2060 : : buffer chain while the file is open. */
2061 : :
2062 : 282836 : if (asm_out_file)
2063 : : {
2064 : 268280 : if (ferror (asm_out_file) != 0)
2065 : 0 : fatal_error (input_location, "error writing to %s: %m", asm_file_name);
2066 : 268280 : if (fclose (asm_out_file) != 0)
2067 : 0 : fatal_error (input_location, "error closing %s: %m", asm_file_name);
2068 : 268280 : asm_out_file = NULL;
2069 : : }
2070 : :
2071 : 282836 : if (stack_usage_file)
2072 : : {
2073 : 311 : fclose (stack_usage_file);
2074 : 311 : stack_usage_file = NULL;
2075 : : }
2076 : :
2077 : 282836 : if (callgraph_info_file)
2078 : : {
2079 : 1 : fputs ("}\n", callgraph_info_file);
2080 : 1 : fclose (callgraph_info_file);
2081 : 1 : callgraph_info_file = NULL;
2082 : 1 : BITMAP_FREE (callgraph_info_external_printed);
2083 : 1 : bitmap_obstack_release (NULL);
2084 : : }
2085 : :
2086 : 282836 : if (seen_error ())
2087 : 26472 : coverage_remove_note_file ();
2088 : :
2089 : 282836 : if (!no_backend)
2090 : : {
2091 : 276913 : statistics_fini ();
2092 : 276913 : debuginfo_fini ();
2093 : :
2094 : 276913 : g->get_passes ()->finish_optimization_passes ();
2095 : :
2096 : 276913 : lra_finish_once ();
2097 : : }
2098 : :
2099 : 282836 : if (mem_report)
2100 : 0 : dump_memory_report ("Final");
2101 : :
2102 : 282836 : if (profile_report)
2103 : 0 : dump_profile_report ();
2104 : :
2105 : 282836 : if (flag_dbg_cnt_list)
2106 : 0 : dbg_cnt_list_all_counters ();
2107 : :
2108 : : /* Language-specific end of compilation actions. */
2109 : 282836 : lang_hooks.finish ();
2110 : 282836 : }
2111 : :
2112 : : static bool
2113 : 277701 : standard_type_bitsize (int bitsize)
2114 : : {
2115 : : /* As a special exception, we always want __int128 enabled if possible. */
2116 : 277701 : if (bitsize == 128)
2117 : : return false;
2118 : : if (bitsize == CHAR_TYPE_SIZE
2119 : : || bitsize == SHORT_TYPE_SIZE
2120 : : || bitsize == INT_TYPE_SIZE
2121 : 0 : || bitsize == LONG_TYPE_SIZE
2122 : 0 : || bitsize == LONG_LONG_TYPE_SIZE)
2123 : 0 : return true;
2124 : : return false;
2125 : : }
2126 : :
2127 : : /* Initialize the compiler, and compile the input file. */
2128 : : static void
2129 : 284977 : do_compile ()
2130 : : {
2131 : : /* Don't do any more if an error has already occurred. */
2132 : 284977 : if (!seen_error ())
2133 : : {
2134 : 284784 : int i;
2135 : :
2136 : 284784 : timevar_start (TV_PHASE_SETUP);
2137 : :
2138 : 284784 : if (flag_save_optimization_record)
2139 : : {
2140 : 41 : dump_context::get ().set_json_writer (new optrecord_json_writer ());
2141 : : }
2142 : :
2143 : : /* This must be run always, because it is needed to compute the FP
2144 : : predefined macros, such as __LDBL_MAX__, for targets using non
2145 : : default FP formats. */
2146 : 284784 : init_adjust_machine_modes ();
2147 : 284784 : init_derived_machine_modes ();
2148 : :
2149 : : /* This must happen after the backend has a chance to process
2150 : : command line options, but before the parsers are
2151 : : initialized. */
2152 : 854352 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
2153 : 284784 : if (targetm.scalar_mode_supported_p (int_n_data[i].m)
2154 : 284784 : && ! standard_type_bitsize (int_n_data[i].bitsize))
2155 : 277701 : int_n_enabled_p[i] = true;
2156 : : else
2157 : 7083 : int_n_enabled_p[i] = false;
2158 : :
2159 : : /* Initialize mpfrs exponent range. This is important to get
2160 : : underflow/overflow in a reasonable timeframe. */
2161 : 284784 : machine_mode mode;
2162 : 284784 : int min_exp = -1;
2163 : 284784 : int max_exp = 1;
2164 : 1993488 : FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT)
2165 : 1708704 : if (SCALAR_FLOAT_MODE_P (mode))
2166 : : {
2167 : 1708704 : const real_format *fmt = REAL_MODE_FORMAT (mode);
2168 : 1708704 : if (fmt)
2169 : : {
2170 : : /* fmt->emin - fmt->p + 1 should be enough but the
2171 : : back-and-forth dance in real_to_decimal_for_mode we
2172 : : do for checking fails due to rounding effects then. */
2173 : 1708704 : if ((fmt->emin - fmt->p) < min_exp)
2174 : : min_exp = fmt->emin - fmt->p;
2175 : 1708704 : if (fmt->emax > max_exp)
2176 : : max_exp = fmt->emax;
2177 : : }
2178 : : }
2179 : : /* E.g. mpc_norm assumes it can square a number without bothering with
2180 : : with range scaling, so until that is fixed, double the minimum
2181 : : and maximum exponents, plus add some buffer for arithmetics
2182 : : on the squared numbers. */
2183 : 284784 : if (mpfr_set_emin (2 * (min_exp - 1))
2184 : 284784 : || mpfr_set_emax (2 * (max_exp + 1)))
2185 : 0 : sorry ("mpfr not configured to handle all floating modes");
2186 : :
2187 : : /* Set up the back-end if requested. */
2188 : 284784 : if (!no_backend)
2189 : 278687 : backend_init ();
2190 : :
2191 : : /* Language-dependent initialization. Returns true on success. */
2192 : 284784 : if (lang_dependent_init (main_input_filename))
2193 : : {
2194 : : /* Initialize yet another pass. */
2195 : :
2196 : 278684 : ggc_protect_identifiers = true;
2197 : :
2198 : 278684 : symtab->initialize ();
2199 : 278684 : init_final (main_input_filename);
2200 : 278684 : coverage_init (aux_base_name);
2201 : 278684 : statistics_init ();
2202 : 278684 : debuginfo_init ();
2203 : 278684 : invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
2204 : :
2205 : 278684 : timevar_stop (TV_PHASE_SETUP);
2206 : :
2207 : 278684 : compile_file ();
2208 : : }
2209 : : else
2210 : : {
2211 : 5923 : timevar_stop (TV_PHASE_SETUP);
2212 : : }
2213 : :
2214 : 282836 : timevar_start (TV_PHASE_FINALIZE);
2215 : :
2216 : 282836 : finalize ();
2217 : :
2218 : 282836 : timevar_stop (TV_PHASE_FINALIZE);
2219 : : }
2220 : 283029 : }
2221 : :
2222 : 285081 : toplev::toplev (timer *external_timer,
2223 : 285081 : bool init_signals)
2224 : 285081 : : m_use_TV_TOTAL (external_timer == NULL),
2225 : 285081 : m_init_signals (init_signals)
2226 : : {
2227 : 285081 : if (external_timer)
2228 : 400 : g_timer = external_timer;
2229 : 285081 : }
2230 : :
2231 : 283128 : toplev::~toplev ()
2232 : : {
2233 : 283128 : if (g_timer && m_use_TV_TOTAL)
2234 : : {
2235 : 12 : g_timer->stop (TV_TOTAL);
2236 : 12 : g_timer->print (stderr);
2237 : 12 : delete g_timer;
2238 : 12 : g_timer = NULL;
2239 : : }
2240 : 283128 : }
2241 : :
2242 : : /* Potentially call timevar_init (which will create g_timevars if it
2243 : : doesn't already exist). */
2244 : :
2245 : : void
2246 : 284577 : toplev::start_timevars ()
2247 : : {
2248 : 284577 : if (time_report || !quiet_flag || flag_detailed_statistics)
2249 : 20 : timevar_init ();
2250 : :
2251 : 284577 : timevar_start (TV_TOTAL);
2252 : 284577 : }
2253 : :
2254 : : /* Handle -fself-test. */
2255 : :
2256 : : void
2257 : 4 : toplev::run_self_tests ()
2258 : : {
2259 : : #if CHECKING_P
2260 : : /* Reset some state. */
2261 : 4 : input_location = UNKNOWN_LOCATION;
2262 : 4 : bitmap_obstack_initialize (NULL);
2263 : :
2264 : : /* Run the tests; any failures will lead to an abort of the process.
2265 : : Use "make selftests-gdb" to run under the debugger. */
2266 : 4 : ::selftest::run_tests ();
2267 : :
2268 : : /* Cleanup. */
2269 : 4 : bitmap_obstack_release (NULL);
2270 : : #else
2271 : : inform (UNKNOWN_LOCATION, "self-tests are not enabled in this build");
2272 : : #endif /* #if CHECKING_P */
2273 : 4 : }
2274 : :
2275 : : /* Entry point of cc1, cc1plus, jc1, f771, etc.
2276 : : Exit code is FATAL_EXIT_CODE if can't open files or if there were
2277 : : any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2278 : :
2279 : : It is not safe to call this function more than once. */
2280 : :
2281 : : int
2282 : 285081 : toplev::main (int argc, char **argv)
2283 : : {
2284 : : /* Parsing and gimplification sometimes need quite large stack.
2285 : : Increase stack size limits if possible. */
2286 : 285081 : stack_limit_increase (64 * 1024 * 1024);
2287 : :
2288 : : /* Stash a copy of the original argv before expansion
2289 : : for use by SARIF output. */
2290 : 285081 : unique_argv original_argv (dupargv (argv));
2291 : :
2292 : 285081 : expandargv (&argc, &argv);
2293 : :
2294 : : /* Initialization of GCC's environment, and diagnostics. */
2295 : 285081 : general_init (argv[0], m_init_signals, std::move (original_argv));
2296 : :
2297 : : /* One-off initialization of options that does not need to be
2298 : : repeated when options are added for particular functions. */
2299 : 285081 : init_options_once ();
2300 : 285081 : init_opts_obstack ();
2301 : :
2302 : : /* Initialize global options structures; this must be repeated for
2303 : : each structure used for parsing options. */
2304 : 285081 : init_options_struct (&global_options, &global_options_set);
2305 : 285081 : lang_hooks.init_options_struct (&global_options);
2306 : :
2307 : : /* Init GGC heuristics must be caller after we initialize
2308 : : options. */
2309 : 285081 : init_ggc_heuristics ();
2310 : :
2311 : : /* Convert the options to an array. */
2312 : 285081 : decode_cmdline_options_to_array_default_mask (argc,
2313 : : CONST_CAST2 (const char **,
2314 : : char **, argv),
2315 : : &save_decoded_options,
2316 : : &save_decoded_options_count);
2317 : :
2318 : : /* Save Optimization decoded options. */
2319 : 285081 : save_opt_decoded_options = new vec<cl_decoded_option> ();
2320 : 8002513 : for (unsigned i = 1; i < save_decoded_options_count; ++i)
2321 : 7717432 : if (save_decoded_options[i].opt_index < cl_options_count
2322 : 7421493 : && cl_options[save_decoded_options[i].opt_index].flags & CL_OPTIMIZATION)
2323 : 311943 : save_opt_decoded_options->safe_push (save_decoded_options[i]);
2324 : :
2325 : : /* Perform language-specific options initialization. */
2326 : 285081 : lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
2327 : :
2328 : : /* Parse the options and do minimal processing; basically just
2329 : : enough to default flags appropriately. */
2330 : 285081 : decode_options (&global_options, &global_options_set,
2331 : : save_decoded_options, save_decoded_options_count,
2332 : : UNKNOWN_LOCATION, global_dc,
2333 : : targetm.target_option.override);
2334 : :
2335 : 285081 : global_dc->get_file_cache ().tune (param_file_cache_files,
2336 : 285081 : param_file_cache_lines);
2337 : :
2338 : 285081 : handle_common_deferred_options ();
2339 : :
2340 : 285077 : init_local_tick ();
2341 : :
2342 : 285077 : initialize_plugins ();
2343 : :
2344 : : /* Handle the dump options now that plugins have had a chance to install new
2345 : : passes. */
2346 : 285077 : handle_deferred_dump_options ();
2347 : :
2348 : 285077 : if (version_flag)
2349 : 112 : print_version (stderr, "", true);
2350 : :
2351 : 285077 : if (help_flag)
2352 : 3 : print_plugins_help (stderr, "");
2353 : :
2354 : : /* Exit early if we can (e.g. -help). */
2355 : 285077 : if (!exit_after_options)
2356 : : {
2357 : : /* Just in case lang_hooks.post_options ends up calling a debug_hook.
2358 : : This can happen with incorrect pre-processed input. */
2359 : 284978 : debug_hooks = &do_nothing_debug_hooks;
2360 : : /* Allow the front end to perform consistency checks and do further
2361 : : initialization based on the command line options. This hook also
2362 : : sets the original filename if appropriate (e.g. foo.i -> foo.c)
2363 : : so we can correctly initialize debug output. */
2364 : 284978 : no_backend = lang_hooks.post_options (&main_input_filename);
2365 : :
2366 : 284977 : process_options ();
2367 : :
2368 : 284977 : if (m_use_TV_TOTAL)
2369 : 284577 : start_timevars ();
2370 : 284977 : do_compile ();
2371 : :
2372 : 283029 : if (flag_self_test && !seen_error ())
2373 : : {
2374 : 5 : if (no_backend)
2375 : 1 : error_at (UNKNOWN_LOCATION, "self-tests incompatible with %<-E%>");
2376 : : else
2377 : 4 : run_self_tests ();
2378 : : }
2379 : : }
2380 : :
2381 : 283128 : if (warningcount || errorcount || werrorcount)
2382 : 39396 : print_ignored_options ();
2383 : :
2384 : : /* Invoke registered plugin callbacks if any. Some plugins could
2385 : : emit some diagnostics here. */
2386 : 283128 : invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2387 : :
2388 : 283128 : if (auto edit_context_ptr = global_dc->get_edit_context ())
2389 : : {
2390 : 17 : pretty_printer pp;
2391 : 17 : pp_show_color (&pp) = pp_show_color (global_dc->get_reference_printer ());
2392 : 17 : edit_context_ptr->print_diff (&pp, true);
2393 : 17 : pp_flush (&pp);
2394 : 17 : }
2395 : :
2396 : 283128 : diagnostic_finish (global_dc);
2397 : :
2398 : 283128 : finalize_plugins ();
2399 : :
2400 : 283128 : after_memory_report = true;
2401 : :
2402 : 283128 : if (global_dc->execution_failed_p ())
2403 : 26939 : return (FATAL_EXIT_CODE);
2404 : :
2405 : : return (SUCCESS_EXIT_CODE);
2406 : 283128 : }
2407 : :
2408 : : /* For those that want to, this function aims to clean up enough state that
2409 : : you can call toplev::main again. */
2410 : : void
2411 : 256374 : toplev::finalize (void)
2412 : : {
2413 : 256374 : no_backend = false;
2414 : 256374 : rtl_initialized = false;
2415 : 256374 : this_target_rtl->target_specific_initialized = false;
2416 : :
2417 : : /* Needs to be called before cgraph_cc_finalize since it uses symtab. */
2418 : 256374 : ipa_reference_cc_finalize ();
2419 : 256374 : ipa_fnsummary_cc_finalize ();
2420 : 256374 : ipa_modref_cc_finalize ();
2421 : 256374 : ipa_edge_modifications_finalize ();
2422 : 256374 : ipa_icf_cc_finalize ();
2423 : :
2424 : 256374 : ipa_prop_cc_finalize ();
2425 : 256374 : ipa_profile_cc_finalize ();
2426 : 256374 : ipa_sra_cc_finalize ();
2427 : 256374 : cgraph_cc_finalize ();
2428 : 256374 : cgraphunit_cc_finalize ();
2429 : 256374 : symtab_thunks_cc_finalize ();
2430 : 256374 : dwarf2cfi_cc_finalize ();
2431 : 256374 : dwarf2out_cc_finalize ();
2432 : 256374 : gcse_cc_finalize ();
2433 : 256374 : ipa_cp_cc_finalize ();
2434 : 256374 : ira_costs_cc_finalize ();
2435 : 256374 : tree_cc_finalize ();
2436 : 256374 : reginfo_cc_finalize ();
2437 : 256374 : varasm_cc_finalize ();
2438 : :
2439 : : /* save_decoded_options uses opts_obstack, so these must
2440 : : be cleaned up together. */
2441 : 256374 : obstack_free (&opts_obstack, NULL);
2442 : 256374 : XDELETEVEC (save_decoded_options);
2443 : 256374 : save_decoded_options = NULL;
2444 : 256374 : save_decoded_options_count = 0;
2445 : :
2446 : 256374 : ggc_common_finalize ();
2447 : :
2448 : : /* Clean up the context (and pass_manager etc). */
2449 : 256374 : delete g;
2450 : 256374 : g = NULL;
2451 : :
2452 : 256374 : }
|