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