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