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 : : #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 : 72979 : get_src_pwd (void)
210 : : {
211 : 72979 : if (! src_pwd)
212 : : {
213 : 63813 : src_pwd = getpwd ();
214 : 63813 : if (!src_pwd)
215 : 0 : src_pwd = ".";
216 : : }
217 : :
218 : 72979 : 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 : 181705337 : announce_function (tree decl)
225 : : {
226 : 181705337 : 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 : 181705337 : }
240 : :
241 : : /* Initialize local_tick with the time of day, or -1 if
242 : : flag_random_seed is set. */
243 : :
244 : : static void
245 : 289298 : init_local_tick (void)
246 : : {
247 : 289298 : if (!flag_random_seed)
248 : : {
249 : : #ifdef HAVE_GETTIMEOFDAY
250 : 287504 : {
251 : 287504 : struct timeval tv;
252 : :
253 : 287504 : gettimeofday (&tv, NULL);
254 : 287504 : 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 : 1794 : local_tick = -1;
267 : 289298 : }
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 : 410347 : get_random_seed (bool noinit)
274 : : {
275 : 410347 : if (!random_seed && !noinit)
276 : : {
277 : 24146 : int fd = open ("/dev/urandom", O_RDONLY);
278 : 24146 : if (fd >= 0)
279 : : {
280 : 24146 : if (read (fd, &random_seed, sizeof (random_seed))
281 : : != sizeof (random_seed))
282 : 0 : random_seed = 0;
283 : 24146 : close (fd);
284 : : }
285 : 24146 : if (!random_seed)
286 : 0 : random_seed = local_tick ^ getpid ();
287 : : }
288 : 410347 : return random_seed;
289 : : }
290 : :
291 : : /* Set flag_random_seed to VAL, and if non-null, reinitialize random_seed. */
292 : :
293 : : void
294 : 1794 : set_random_seed (const char *val)
295 : : {
296 : 1794 : flag_random_seed = val;
297 : 1794 : if (flag_random_seed)
298 : : {
299 : 1794 : char *endp;
300 : :
301 : : /* When the driver passed in a hex number don't crc it again */
302 : 1794 : random_seed = strtoul (flag_random_seed, &endp, 0);
303 : 1794 : if (!(endp > flag_random_seed && *endp == 0))
304 : 560 : random_seed = crc32_string (0, flag_random_seed);
305 : : }
306 : 1794 : }
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 : 613771342 : 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 : 613771342 : if (HAS_DECL_ASSEMBLER_NAME_P (decl)
338 : 613771342 : && DECL_DEFER_OUTPUT (decl) != 0)
339 : 22314789 : DECL_DEFER_OUTPUT (decl) = 0;
340 : :
341 : 613771342 : if (VAR_P (decl) && DECL_SIZE (decl) == 0)
342 : 360050 : lang_hooks.finish_incomplete_decl (decl);
343 : 613771342 : }
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 : 755968389 : wrapup_global_declaration_2 (tree decl)
350 : : {
351 : 754184786 : if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl)
352 : 857917210 : || (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 : 101947751 : if (VAR_P (decl) && TREE_STATIC (decl))
381 : : {
382 : 77044904 : varpool_node *node;
383 : 77044904 : bool needed = true;
384 : 77044904 : node = varpool_node::get (decl);
385 : :
386 : 77044904 : if (!node && flag_ltrans)
387 : : needed = false;
388 : 76943350 : else if (node && node->definition)
389 : : needed = false;
390 : 7818854 : else if (node && node->alias)
391 : : needed = false;
392 : 7920176 : else if (!symtab->global_info_ready
393 : 7920176 : && (TREE_USED (decl)
394 : 750476 : || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
395 : : /* needed */;
396 : 750465 : else if (node && node->analyzed)
397 : : /* needed */;
398 : 750465 : else if (DECL_COMDAT (decl))
399 : : needed = false;
400 : 724705 : else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
401 : 724570 : && (optimize || !flag_keep_static_consts
402 : 6 : || DECL_ARTIFICIAL (decl)))
403 : : needed = false;
404 : :
405 : : if (needed)
406 : : {
407 : 7894275 : rest_of_decl_compilation (decl, 1, 1);
408 : 7894275 : 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 : 228715 : wrapup_global_declarations (tree *vec, int len)
422 : : {
423 : 228715 : bool reconsider, output_something = false;
424 : 228715 : int i;
425 : :
426 : 223512608 : for (i = 0; i < len; i++)
427 : 223283893 : 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 : 259968 : do
433 : : {
434 : 259968 : reconsider = false;
435 : 252894344 : for (i = 0; i < len; i++)
436 : 252634376 : reconsider |= wrapup_global_declaration_2 (vec[i]);
437 : 259968 : if (reconsider)
438 : 31253 : output_something = true;
439 : : }
440 : : while (reconsider);
441 : :
442 : 228715 : 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 : 282166 : compile_file (void)
450 : : {
451 : 282166 : timevar_start (TV_PHASE_PARSING);
452 : 282166 : timevar_push (TV_PARSE_GLOBAL);
453 : :
454 : : /* Parse entire file and generate initial debug information. */
455 : 282166 : lang_hooks.parse_file ();
456 : :
457 : 280321 : timevar_pop (TV_PARSE_GLOBAL);
458 : 280321 : timevar_stop (TV_PHASE_PARSING);
459 : :
460 : 280321 : if (flag_dump_locations)
461 : 1 : dump_location_info (stderr);
462 : :
463 : 280321 : free_attr_data ();
464 : :
465 : : /* Compilation is now finished except for writing
466 : : what's left of the symbol table output. */
467 : :
468 : 280321 : 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 : 270777 : maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
475 : :
476 : 270777 : ggc_protect_identifiers = false;
477 : :
478 : : /* Run the actual compilation process. */
479 : 270777 : if (!in_lto_p)
480 : : {
481 : 257222 : timevar_start (TV_PHASE_OPT_GEN);
482 : 257222 : symtab->finalize_compilation_unit ();
483 : 257201 : 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 : 270756 : if (lang_hooks.decls.post_compilation_parsing_cleanups)
491 : 94738 : lang_hooks.decls.post_compilation_parsing_cleanups ();
492 : :
493 : 270756 : dump_context::get ().finish_any_json_writer ();
494 : :
495 : 270756 : if (seen_error ())
496 : : return;
497 : :
498 : 244694 : timevar_start (TV_PHASE_LATE_ASM);
499 : :
500 : : /* Compilation unit is finalized. When producing non-fat LTO object, we are
501 : : basically finished. */
502 : 244694 : if ((in_lto_p && flag_incremental_link != INCREMENTAL_LINK_LTO)
503 : 231173 : || !flag_lto || flag_fat_lto_objects)
504 : : {
505 : : /* File-scope initialization for AddressSanitizer. */
506 : 231294 : if (flag_sanitize & SANITIZE_ADDRESS)
507 : 2483 : asan_finish_file ();
508 : :
509 : 231294 : if (flag_sanitize & SANITIZE_THREAD)
510 : 319 : tsan_finish_file ();
511 : :
512 : 231294 : if (gate_hwasan ())
513 : 319 : hwasan_finish_file ();
514 : :
515 : 231294 : omp_finish_file ();
516 : :
517 : 231294 : output_shared_constant_pool ();
518 : 231294 : output_object_blocks ();
519 : 231294 : finish_tm_clone_pairs ();
520 : :
521 : : /* Write out any pending weak symbol declarations. */
522 : 231294 : 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 : 231294 : insn_locations_init ();
527 : 231294 : targetm.asm_out.code_end ();
528 : :
529 : : /* Do dbx symbols. */
530 : 231294 : timevar_push (TV_SYMOUT);
531 : :
532 : : #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
533 : 231294 : dwarf2out_frame_finish ();
534 : : #endif
535 : :
536 : 231294 : debuginfo_start ();
537 : 231294 : (*debug_hooks->finish) (main_input_filename);
538 : 231294 : debuginfo_stop ();
539 : 231294 : timevar_pop (TV_SYMOUT);
540 : :
541 : : /* Output some stuff at end of file if nec. */
542 : :
543 : 231294 : dw2_output_indirect_constants ();
544 : :
545 : : /* Flush any pending external directives. */
546 : 231294 : 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 : 244694 : if (flag_generate_lto && !flag_fat_lto_objects)
552 : : {
553 : : #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
554 : 13400 : ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE, "__gnu_lto_slim",
555 : 13400 : 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 : 244694 : if (!flag_no_ident)
570 : : {
571 : 236923 : const char *pkg_version = "(GNU) ";
572 : 236923 : char *ident_str;
573 : :
574 : 236923 : if (strcmp ("(GCC) ", pkgversion_string))
575 : : pkg_version = pkgversion_string;
576 : :
577 : 236923 : ident_str = ACONCAT (("GCC: ", pkg_version, version_string, NULL));
578 : 236923 : targetm.asm_out.output_ident (ident_str);
579 : : }
580 : :
581 : : /* Auto profile finalization. */
582 : 244694 : if (flag_auto_profile)
583 : 0 : end_auto_profile ();
584 : :
585 : : /* Invoke registered plugin callbacks. */
586 : 244694 : 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 : 244694 : targetm.asm_out.file_end ();
592 : :
593 : 244694 : 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 : 2409 : print_version (FILE *file, const char *indent, bool show_global_state)
611 : : {
612 : 2409 : 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 : 2409 : static const char fmt2[] =
620 : : N_("GMP version %s, MPFR version %s, MPC version %s, isl version %s\n");
621 : 2409 : static const char fmt3[] =
622 : : N_("%s%swarning: %s header version %s differs from library version %s.\n");
623 : 2409 : 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 : 2409 : fprintf (file,
629 : 2409 : file == stderr ? _(fmt1) : fmt1,
630 : 2409 : 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 : 4818 : fprintf (file,
653 : 2409 : 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 : 2409 : 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 : 2409 : 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 : 2409 : 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 : 2409 : if (show_global_state)
678 : : {
679 : 125 : fprintf (file,
680 : 125 : file == stderr ? _(fmt4) : fmt4,
681 : 125 : indent, *indent != 0 ? " " : "",
682 : : param_ggc_min_expand, param_ggc_min_heapsize);
683 : :
684 : 125 : print_plugins_versions (file, indent);
685 : : }
686 : 2409 : }
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 : 273348 : init_asm_output (const char *name)
696 : : {
697 : 273348 : if (name == NULL && asm_file_name == 0)
698 : 0 : asm_out_file = stdout;
699 : : else
700 : : {
701 : 273348 : 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 : 273348 : if (!strcmp (asm_file_name, "-"))
712 : 163 : asm_out_file = stdout;
713 : 273185 : else if (!canonical_filename_eq (asm_file_name, name)
714 : 273185 : || !strcmp (asm_file_name, HOST_BIT_BUCKET))
715 : 273185 : 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 : 273348 : if (asm_out_file == 0)
723 : 0 : fatal_error (UNKNOWN_LOCATION,
724 : : "cannot open %qs for writing: %m", asm_file_name);
725 : : }
726 : :
727 : 273348 : if (!flag_syntax_only && !(global_dc->get_lang_mask () & CL_LTODump))
728 : : {
729 : 273081 : targetm.asm_out.file_start ();
730 : :
731 : 273081 : 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 : 273081 : 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 : 273348 : }
760 : :
761 : : /* A helper function; used as the reallocator function for cpp's line
762 : : table. */
763 : : static void *
764 : 651627449 : realloc_for_line_map (void *ptr, size_t len)
765 : : {
766 : 651627449 : 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 : 1285 : alloc_for_identifier_to_locale (size_t len)
773 : : {
774 : 1285 : 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 : fprintf (stack_usage_file, "\t" HOST_WIDE_INT_PRINT_DEC"\t%s\n",
846 : 329 : stack_usage, stack_usage_kind_str[stack_usage_kind]);
847 : : }
848 : :
849 : 355 : if (warn_stack_usage >= 0 && warn_stack_usage < HOST_WIDE_INT_MAX)
850 : : {
851 : 13 : const location_t loc = DECL_SOURCE_LOCATION (current_function_decl);
852 : :
853 : 13 : if (stack_usage_kind == DYNAMIC)
854 : 1 : warning_at (loc, OPT_Wstack_usage_, "stack usage might be unbounded");
855 : 12 : else if (stack_usage > warn_stack_usage)
856 : : {
857 : 2 : if (stack_usage_kind == DYNAMIC_BOUNDED)
858 : 1 : warning_at (loc,
859 : 1 : OPT_Wstack_usage_, "stack usage might be %wu bytes",
860 : : stack_usage);
861 : : else
862 : 1 : warning_at (loc, OPT_Wstack_usage_, "stack usage is %wu bytes",
863 : : stack_usage);
864 : : }
865 : : }
866 : : }
867 : :
868 : : /* Dump placeholder node for indirect calls in VCG format. */
869 : :
870 : : #define INDIRECT_CALL_NAME "__indirect_call"
871 : :
872 : : static void
873 : 2 : dump_final_node_vcg_start (FILE *f, tree decl)
874 : : {
875 : 2 : fputs ("node: { title: \"", f);
876 : 2 : if (decl)
877 : 2 : print_decl_identifier (f, decl, PRINT_DECL_UNIQUE_NAME);
878 : : else
879 : 0 : fputs (INDIRECT_CALL_NAME, f);
880 : 2 : fputs ("\" label: \"", f);
881 : 2 : if (decl)
882 : : {
883 : 2 : print_decl_identifier (f, decl, PRINT_DECL_NAME);
884 : 2 : fputs ("\\n", f);
885 : 2 : print_decl_identifier (f, decl, PRINT_DECL_ORIGIN);
886 : : }
887 : : else
888 : 0 : fputs ("Indirect Call Placeholder", f);
889 : 2 : }
890 : :
891 : : /* Dump final cgraph edge in VCG format. */
892 : :
893 : : static void
894 : 0 : dump_final_callee_vcg (FILE *f, location_t location, tree callee)
895 : : {
896 : 0 : if ((!callee || DECL_EXTERNAL (callee))
897 : 0 : && bitmap_set_bit (callgraph_info_external_printed,
898 : 0 : callee ? DECL_UID (callee) + 1 : 0))
899 : : {
900 : 0 : dump_final_node_vcg_start (f, callee);
901 : 0 : fputs ("\" shape : ellipse }\n", f);
902 : : }
903 : :
904 : 0 : fputs ("edge: { sourcename: \"", f);
905 : 0 : print_decl_identifier (f, current_function_decl, PRINT_DECL_UNIQUE_NAME);
906 : 0 : fputs ("\" targetname: \"", f);
907 : 0 : if (callee)
908 : 0 : print_decl_identifier (f, callee, PRINT_DECL_UNIQUE_NAME);
909 : : else
910 : 0 : fputs (INDIRECT_CALL_NAME, f);
911 : 0 : if (LOCATION_LOCUS (location) != UNKNOWN_LOCATION)
912 : : {
913 : 0 : expanded_location loc;
914 : 0 : fputs ("\" label: \"", f);
915 : 0 : loc = expand_location (location);
916 : 0 : fprintf (f, "%s:%d:%d", loc.file, loc.line, loc.column);
917 : : }
918 : 0 : fputs ("\" }\n", f);
919 : 0 : }
920 : :
921 : : /* Callback for cgraph_node::call_for_symbol_thunks_and_aliases to dump to F_ a
922 : : node and an edge from ALIAS->DECL to CURRENT_FUNCTION_DECL. */
923 : :
924 : : static bool
925 : 2 : dump_final_alias_vcg (cgraph_node *alias, void *f_)
926 : : {
927 : 2 : FILE *f = (FILE *)f_;
928 : :
929 : 2 : if (alias->decl == current_function_decl)
930 : : return false;
931 : :
932 : 1 : dump_final_node_vcg_start (f, alias->decl);
933 : 1 : fputs ("\" shape : triangle }\n", f);
934 : :
935 : 1 : fputs ("edge: { sourcename: \"", f);
936 : 1 : print_decl_identifier (f, alias->decl, PRINT_DECL_UNIQUE_NAME);
937 : 1 : fputs ("\" targetname: \"", f);
938 : 1 : print_decl_identifier (f, current_function_decl, PRINT_DECL_UNIQUE_NAME);
939 : 1 : location_t location = DECL_SOURCE_LOCATION (alias->decl);
940 : 1 : if (LOCATION_LOCUS (location) != UNKNOWN_LOCATION)
941 : : {
942 : 1 : expanded_location loc;
943 : 1 : fputs ("\" label: \"", f);
944 : 1 : loc = expand_location (location);
945 : 1 : fprintf (f, "%s:%d:%d", loc.file, loc.line, loc.column);
946 : : }
947 : 1 : fputs ("\" }\n", f);
948 : :
949 : 1 : return false;
950 : : }
951 : :
952 : : /* Dump final cgraph node in VCG format. */
953 : :
954 : : static void
955 : 1 : dump_final_node_vcg (FILE *f)
956 : : {
957 : 1 : dump_final_node_vcg_start (f, current_function_decl);
958 : :
959 : 1 : if (flag_stack_usage_info
960 : 1 : || (flag_callgraph_info & CALLGRAPH_INFO_STACK_USAGE))
961 : 0 : output_stack_usage_1 (f);
962 : :
963 : 1 : if (flag_callgraph_info & CALLGRAPH_INFO_DYNAMIC_ALLOC)
964 : : {
965 : 0 : fprintf (f, "\\n%u dynamic objects", vec_safe_length (cfun->su->dallocs));
966 : :
967 : 0 : unsigned i;
968 : 0 : callinfo_dalloc *cda;
969 : 0 : FOR_EACH_VEC_SAFE_ELT (cfun->su->dallocs, i, cda)
970 : : {
971 : 0 : expanded_location loc = expand_location (cda->location);
972 : 0 : fprintf (f, "\\n %s", cda->name);
973 : 0 : fprintf (f, " %s:%d:%d", loc.file, loc.line, loc.column);
974 : : }
975 : :
976 : 0 : vec_free (cfun->su->dallocs);
977 : 0 : cfun->su->dallocs = NULL;
978 : : }
979 : :
980 : 1 : fputs ("\" }\n", f);
981 : :
982 : 1 : unsigned i;
983 : 1 : callinfo_callee *c;
984 : 2 : FOR_EACH_VEC_SAFE_ELT (cfun->su->callees, i, c)
985 : 0 : dump_final_callee_vcg (f, c->location, c->decl);
986 : 1 : vec_free (cfun->su->callees);
987 : 1 : cfun->su->callees = NULL;
988 : :
989 : 1 : cgraph_node *node = cgraph_node::get (current_function_decl);
990 : 1 : if (!node)
991 : 1 : return;
992 : 1 : node->call_for_symbol_thunks_and_aliases (dump_final_alias_vcg, f,
993 : : true, false);
994 : : }
995 : :
996 : : /* Output stack usage and callgraph info, as requested. */
997 : : void
998 : 356 : output_stack_usage (void)
999 : : {
1000 : 356 : if (flag_callgraph_info)
1001 : 1 : dump_final_node_vcg (callgraph_info_file);
1002 : : else
1003 : 355 : output_stack_usage_1 (NULL);
1004 : 356 : }
1005 : :
1006 : : /* Open an auxiliary output file. */
1007 : : static FILE *
1008 : 312 : open_auxiliary_file (const char *ext)
1009 : : {
1010 : 312 : char *filename;
1011 : 312 : FILE *file;
1012 : :
1013 : 312 : filename = concat (aux_base_name, ".", ext, NULL);
1014 : 312 : file = fopen (filename, "w");
1015 : 312 : if (!file)
1016 : 0 : fatal_error (input_location, "cannot open %s for writing: %m", filename);
1017 : 312 : free (filename);
1018 : 312 : return file;
1019 : : }
1020 : :
1021 : : /* Alternative diagnostics callback for reentered ICE reporting. */
1022 : :
1023 : : static void
1024 : 0 : internal_error_reentered (diagnostics::context *, const char *, va_list *)
1025 : : {
1026 : : /* Flush the dump file if emergency_dump_function itself caused an ICE. */
1027 : 0 : if (dump_file)
1028 : 0 : fflush (dump_file);
1029 : 0 : }
1030 : :
1031 : : /* Auxiliary callback for the diagnostics code. */
1032 : :
1033 : : static void
1034 : 21 : internal_error_function (diagnostics::context *, const char *, va_list *)
1035 : : {
1036 : 21 : global_dc->set_internal_error_callback (internal_error_reentered);
1037 : 21 : warn_if_plugins ();
1038 : 21 : emergency_dump_function ();
1039 : 21 : }
1040 : :
1041 : : /* Initialization of the front end environment, before command line
1042 : : options are parsed. Signal handlers, internationalization etc.
1043 : : ARGV0 is main's argv[0]. */
1044 : : static void
1045 : 289302 : general_init (const char *argv0, bool init_signals, unique_argv original_argv)
1046 : : {
1047 : 289302 : const char *p;
1048 : :
1049 : 289302 : p = argv0 + strlen (argv0);
1050 : 1676736 : while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1051 : 1387434 : --p;
1052 : 289302 : progname = p;
1053 : :
1054 : 289302 : xmalloc_set_program_name (progname);
1055 : :
1056 : 289302 : hex_init ();
1057 : :
1058 : : /* Unlock the stdio streams. */
1059 : 289302 : unlock_std_streams ();
1060 : :
1061 : 289302 : gcc_init_libintl ();
1062 : :
1063 : 289302 : identifier_to_locale_alloc = alloc_for_identifier_to_locale;
1064 : 289302 : identifier_to_locale_free = ggc_free;
1065 : :
1066 : : /* Initialize the diagnostics reporting machinery, so option parsing
1067 : : can give warnings and errors. */
1068 : 289302 : diagnostic_initialize (global_dc, N_OPTS);
1069 : : /* Set a default printer. Language specific initializations will
1070 : : override it later. */
1071 : 289302 : tree_diagnostics_defaults (global_dc);
1072 : :
1073 : 289302 : global_dc->set_original_argv (std::move (original_argv));
1074 : :
1075 : 289302 : auto &source_printing_opts = global_dc->get_source_printing_options ();
1076 : 289302 : source_printing_opts.enabled
1077 : 289302 : = global_options_init.x_flag_diagnostics_show_caret;
1078 : 289302 : source_printing_opts.show_event_links_p
1079 : 289302 : = global_options_init.x_flag_diagnostics_show_event_links;
1080 : 289302 : source_printing_opts.show_labels_p
1081 : 289302 : = global_options_init.x_flag_diagnostics_show_labels;
1082 : 289302 : source_printing_opts.show_line_numbers_p
1083 : 289302 : = global_options_init.x_flag_diagnostics_show_line_numbers;
1084 : 289302 : global_dc->set_show_cwe (global_options_init.x_flag_diagnostics_show_cwe);
1085 : 289302 : global_dc->set_show_rules (global_options_init.x_flag_diagnostics_show_rules);
1086 : 289302 : global_dc->set_path_format
1087 : 289302 : ((enum diagnostic_path_format)
1088 : 289302 : global_options_init.x_flag_diagnostics_path_format);
1089 : 289302 : global_dc->set_show_path_depths
1090 : 289302 : (global_options_init.x_flag_diagnostics_show_path_depths);
1091 : 289302 : global_dc->set_show_option_requested
1092 : 289302 : (global_options_init.x_flag_diagnostics_show_option);
1093 : 289302 : source_printing_opts.min_margin_width
1094 : 289302 : = global_options_init.x_diagnostics_minimum_margin_width;
1095 : 289302 : global_dc->m_show_column
1096 : 289302 : = global_options_init.x_flag_show_column;
1097 : 289302 : global_dc->set_show_highlight_colors
1098 : 289302 : (global_options_init.x_flag_diagnostics_show_highlight_colors);
1099 : 289302 : global_dc->set_show_nesting
1100 : 289302 : (global_options_init.x_flag_diagnostics_show_nesting);
1101 : 289302 : global_dc->set_show_nesting_locations
1102 : 289302 : (global_options_init.x_flag_diagnostics_show_nesting_locations);
1103 : 289302 : global_dc->set_show_nesting_levels
1104 : 289302 : (global_options_init.x_flag_diagnostics_show_nesting_levels);
1105 : 289302 : global_dc->set_internal_error_callback (internal_error_function);
1106 : 289302 : const unsigned lang_mask = lang_hooks.option_lang_mask ();
1107 : 289302 : global_dc->set_option_id_manager
1108 : 289302 : (std::make_unique<compiler_diagnostic_option_id_manager> (*global_dc,
1109 : : lang_mask,
1110 : 289302 : &global_options),
1111 : : lang_mask);
1112 : 289302 : global_dc->push_owned_urlifier (make_gcc_urlifier (lang_mask));
1113 : :
1114 : 289302 : if (init_signals)
1115 : : {
1116 : : /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1117 : : #ifdef SIGSEGV
1118 : 287971 : signal (SIGSEGV, crash_signal);
1119 : : #endif
1120 : : #ifdef SIGILL
1121 : 287971 : signal (SIGILL, crash_signal);
1122 : : #endif
1123 : : #ifdef SIGBUS
1124 : 287971 : signal (SIGBUS, crash_signal);
1125 : : #endif
1126 : : #ifdef SIGABRT
1127 : 287971 : signal (SIGABRT, crash_signal);
1128 : : #endif
1129 : : #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1130 : : signal (SIGIOT, crash_signal);
1131 : : #endif
1132 : : #ifdef SIGFPE
1133 : 287971 : signal (SIGFPE, crash_signal);
1134 : : #endif
1135 : :
1136 : : /* Other host-specific signal setup. */
1137 : 287971 : (*host_hooks.extra_signals)();
1138 : : }
1139 : :
1140 : : /* Initialize the garbage-collector, string pools and tree type hash
1141 : : table. */
1142 : 289302 : init_ggc ();
1143 : 289302 : init_stringpool ();
1144 : 289302 : input_location = UNKNOWN_LOCATION;
1145 : 289302 : line_table = ggc_alloc<line_maps> ();
1146 : 289302 : linemap_init (line_table, BUILTINS_LOCATION);
1147 : 289302 : line_table->m_reallocator = realloc_for_line_map;
1148 : 289302 : line_table->m_round_alloc_size = ggc_round_alloc_size;
1149 : 289302 : line_table->default_range_bits = line_map_suggested_range_bits;
1150 : 289302 : init_ttree ();
1151 : :
1152 : : /* Initialize register usage now so switches may override. */
1153 : 289302 : init_reg_sets ();
1154 : :
1155 : : /* Create the singleton holder for global state. This creates the
1156 : : dump manager. */
1157 : 289302 : g = new gcc::context ();
1158 : :
1159 : : /* Allow languages and middle-end to register their dumps before the
1160 : : optimization passes. */
1161 : 289302 : g->get_dumps ()->register_dumps ();
1162 : :
1163 : : /* Create the passes. */
1164 : 289302 : g->set_passes (new gcc::pass_manager (g));
1165 : :
1166 : 289302 : symtab = new (ggc_alloc <symbol_table> ()) symbol_table ();
1167 : :
1168 : 289302 : statistics_early_init ();
1169 : 289302 : debuginfo_early_init ();
1170 : 289302 : }
1171 : :
1172 : : /* Return true if the current target supports -fsection-anchors. */
1173 : :
1174 : : static bool
1175 : 0 : target_supports_section_anchors_p (void)
1176 : : {
1177 : 0 : if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1178 : : return false;
1179 : :
1180 : 0 : if (targetm.asm_out.output_anchor == NULL)
1181 : 0 : return false;
1182 : :
1183 : : return true;
1184 : : }
1185 : :
1186 : : /* Parse "N[:M][:...]" into struct align_flags A.
1187 : : VALUES contains parsed values (in reverse order), all processed
1188 : : values are popped. */
1189 : :
1190 : : static void
1191 : 597451 : read_log_maxskip (auto_vec<unsigned> &values, align_flags_tuple *a)
1192 : : {
1193 : 597451 : unsigned n = values.pop ();
1194 : 597451 : if (n != 0)
1195 : 477965 : a->log = floor_log2 (n * 2 - 1);
1196 : :
1197 : 597451 : if (values.is_empty ())
1198 : 358469 : a->maxskip = n ? n - 1 : 0;
1199 : : else
1200 : : {
1201 : 238982 : unsigned m = values.pop ();
1202 : : /* -falign-foo=N:M means M-1 max bytes of padding, not M. */
1203 : 238982 : if (m > 0)
1204 : 119496 : m--;
1205 : 238982 : a->maxskip = m;
1206 : : }
1207 : :
1208 : : /* Normalize the tuple. */
1209 : 597451 : a->normalize ();
1210 : 597451 : }
1211 : :
1212 : : /* Parse "N[:M[:N2[:M2]]]" string FLAG into a pair of struct align_flags. */
1213 : :
1214 : : static void
1215 : 2885146036 : parse_N_M (const char *flag, align_flags &a)
1216 : : {
1217 : 2885146036 : if (flag)
1218 : : {
1219 : 2621445708 : static hash_map <nofree_string_hash, align_flags> cache;
1220 : 2621445708 : align_flags *entry = cache.get (flag);
1221 : 2621445708 : if (entry)
1222 : : {
1223 : 2621087236 : a = *entry;
1224 : 2621087236 : return;
1225 : : }
1226 : :
1227 : 358472 : auto_vec<unsigned> result_values;
1228 : 358472 : bool r = parse_and_check_align_values (flag, NULL, result_values, false,
1229 : : UNKNOWN_LOCATION);
1230 : 358472 : if (!r)
1231 : 0 : return;
1232 : :
1233 : : /* Reverse values for easier manipulation. */
1234 : 358472 : result_values.reverse ();
1235 : :
1236 : 358472 : read_log_maxskip (result_values, &a.levels[0]);
1237 : 358472 : if (!result_values.is_empty ())
1238 : 238979 : read_log_maxskip (result_values, &a.levels[1]);
1239 : : #ifdef SUBALIGN_LOG
1240 : : else
1241 : : {
1242 : : /* N2[:M2] is not specified. This arch has a default for N2.
1243 : : Before -falign-foo=N:M:N2:M2 was introduced, x86 had a tweak.
1244 : : -falign-functions=N with N > 8 was adding secondary alignment.
1245 : : -falign-functions=10 was emitting this before every function:
1246 : : .p2align 4,,9
1247 : : .p2align 3
1248 : : Now this behavior (and more) can be explicitly requested:
1249 : : -falign-functions=16:10:8
1250 : : Retain old behavior if N2 is missing: */
1251 : :
1252 : 119493 : int align = 1 << a.levels[0].log;
1253 : 119493 : int subalign = 1 << SUBALIGN_LOG;
1254 : :
1255 : 119493 : if (a.levels[0].log > SUBALIGN_LOG
1256 : 119492 : && a.levels[0].maxskip >= subalign - 1)
1257 : : {
1258 : : /* Set N2 unless subalign can never have any effect. */
1259 : 119492 : if (align > a.levels[0].maxskip + 1)
1260 : : {
1261 : 32 : a.levels[1].log = SUBALIGN_LOG;
1262 : 32 : a.levels[1].normalize ();
1263 : : }
1264 : : }
1265 : : }
1266 : : #endif
1267 : :
1268 : : /* Cache seen value. */
1269 : 358472 : cache.put (flag, a);
1270 : 358472 : }
1271 : : }
1272 : :
1273 : : /* Process -falign-foo=N[:M[:N2[:M2]]] options. */
1274 : :
1275 : : void
1276 : 721286509 : parse_alignment_opts (void)
1277 : : {
1278 : 721286509 : parse_N_M (str_align_loops, align_loops);
1279 : 721286509 : parse_N_M (str_align_jumps, align_jumps);
1280 : 721286509 : parse_N_M (str_align_labels, align_labels);
1281 : 721286509 : parse_N_M (str_align_functions, align_functions);
1282 : 721286509 : }
1283 : :
1284 : : /* Process the options that have been parsed. */
1285 : : static void
1286 : 289199 : process_options ()
1287 : : {
1288 : 289199 : const char *language_string = lang_hooks.name;
1289 : :
1290 : 289199 : maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
1291 : :
1292 : : /* Some machines may reject certain combinations of options. */
1293 : 289199 : location_t saved_location = input_location;
1294 : 289199 : input_location = UNKNOWN_LOCATION;
1295 : 289199 : targetm.target_option.override ();
1296 : 289199 : input_location = saved_location;
1297 : :
1298 : 289199 : if (flag_diagnostics_generate_patch)
1299 : 17 : global_dc->initialize_fixits_change_set ();
1300 : :
1301 : : /* Avoid any informative notes in the second run of -fcompare-debug. */
1302 : 289199 : if (flag_compare_debug)
1303 : 616 : global_dc->inhibit_notes ();
1304 : :
1305 : 289199 : if (flag_section_anchors && !target_supports_section_anchors_p ())
1306 : : {
1307 : 0 : warning_at (UNKNOWN_LOCATION, OPT_fsection_anchors,
1308 : : "this target does not support %qs",
1309 : : "-fsection-anchors");
1310 : 0 : flag_section_anchors = 0;
1311 : : }
1312 : :
1313 : 289199 : if (!OPTION_SET_P (flag_short_enums))
1314 : 289071 : flag_short_enums = targetm.default_short_enums ();
1315 : :
1316 : : /* Set aux_base_name if not already set. */
1317 : 289199 : if (aux_base_name)
1318 : : ;
1319 : 289199 : else if (dump_base_name)
1320 : : {
1321 : 286427 : const char *name = dump_base_name;
1322 : 286427 : int nlen, len;
1323 : :
1324 : 263795 : if (dump_base_ext && (len = strlen (dump_base_ext))
1325 : 263795 : && (nlen = strlen (name)) && nlen > len
1326 : 550222 : && strcmp (name + nlen - len, dump_base_ext) == 0)
1327 : : {
1328 : 263795 : char *p = xstrndup (name, nlen - len);
1329 : 263795 : name = p;
1330 : : }
1331 : :
1332 : 286427 : aux_base_name = name;
1333 : : }
1334 : : else
1335 : 2772 : aux_base_name = "gccaux";
1336 : :
1337 : : #ifndef HAVE_isl
1338 : : if (flag_graphite
1339 : : || flag_loop_nest_optimize
1340 : : || flag_graphite_identity
1341 : : || flag_loop_parallelize_all)
1342 : : sorry ("Graphite loop optimizations cannot be used (isl is not available) "
1343 : : "(%<-fgraphite%>, %<-fgraphite-identity%>, "
1344 : : "%<-floop-nest-optimize%>, %<-floop-parallelize-all%>)");
1345 : : #endif
1346 : :
1347 : 289199 : if (flag_cf_protection != CF_NONE
1348 : 20758 : && !(flag_cf_protection & CF_SET))
1349 : : {
1350 : 0 : if (flag_cf_protection == CF_FULL)
1351 : : {
1352 : 0 : error_at (UNKNOWN_LOCATION,
1353 : : "%<-fcf-protection=full%> is not supported for this "
1354 : : "target");
1355 : 0 : flag_cf_protection = CF_NONE;
1356 : : }
1357 : 0 : if (flag_cf_protection == CF_BRANCH)
1358 : : {
1359 : 0 : error_at (UNKNOWN_LOCATION,
1360 : : "%<-fcf-protection=branch%> is not supported for this "
1361 : : "target");
1362 : 0 : flag_cf_protection = CF_NONE;
1363 : : }
1364 : 0 : if (flag_cf_protection == CF_RETURN)
1365 : : {
1366 : 0 : error_at (UNKNOWN_LOCATION,
1367 : : "%<-fcf-protection=return%> is not supported for this "
1368 : : "target");
1369 : 0 : flag_cf_protection = CF_NONE;
1370 : : }
1371 : : }
1372 : :
1373 : : /* One region RA really helps to decrease the code size. */
1374 : 289199 : if (!OPTION_SET_P (flag_ira_region))
1375 : 289196 : flag_ira_region
1376 : 418758 : = optimize_size || !optimize ? IRA_REGION_ONE : IRA_REGION_MIXED;
1377 : :
1378 : 289199 : if (!abi_version_at_least (2))
1379 : : {
1380 : : /* -fabi-version=1 support was removed after GCC 4.9. */
1381 : 0 : error_at (UNKNOWN_LOCATION,
1382 : : "%<-fabi-version=1%> is no longer supported");
1383 : 0 : flag_abi_version = 2;
1384 : : }
1385 : :
1386 : 289199 : if (flag_non_call_exceptions)
1387 : 5514 : flag_asynchronous_unwind_tables = 1;
1388 : 289199 : if (flag_asynchronous_unwind_tables)
1389 : 289171 : flag_unwind_tables = 1;
1390 : :
1391 : 289199 : if (flag_value_profile_transformations)
1392 : 152 : flag_profile_values = 1;
1393 : :
1394 : : /* Warn about options that are not supported on this machine. */
1395 : : #ifndef INSN_SCHEDULING
1396 : : if (flag_schedule_insns || flag_schedule_insns_after_reload)
1397 : : warning_at (UNKNOWN_LOCATION, 0,
1398 : : "instruction scheduling not supported on this target machine");
1399 : : #endif
1400 : 289199 : if (!DELAY_SLOTS && flag_delayed_branch)
1401 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1402 : : "this target machine does not have delayed branches");
1403 : :
1404 : 289199 : user_label_prefix = USER_LABEL_PREFIX;
1405 : 289199 : if (flag_leading_underscore != -1)
1406 : : {
1407 : : /* If the default prefix is more complicated than "" or "_",
1408 : : issue a warning and ignore this option. */
1409 : 3 : if (user_label_prefix[0] == 0 ||
1410 : : (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1411 : : {
1412 : 3 : user_label_prefix = flag_leading_underscore ? "_" : "";
1413 : : }
1414 : : else
1415 : : warning_at (UNKNOWN_LOCATION, 0,
1416 : : "%<-f%sleading-underscore%> not supported on this "
1417 : : "target machine", flag_leading_underscore ? "" : "no-");
1418 : : }
1419 : :
1420 : : /* If we are in verbose mode, write out the version and maybe all the
1421 : : option flags in use. */
1422 : 289199 : if (version_flag)
1423 : : {
1424 : : /* We already printed the version header in main (). */
1425 : 111 : if (!quiet_flag)
1426 : : {
1427 : 0 : fputs ("options passed: ", stderr);
1428 : 0 : char *cmdline = gen_command_line_string (save_decoded_options,
1429 : : save_decoded_options_count);
1430 : :
1431 : 0 : fputs (cmdline, stderr);
1432 : 0 : free (cmdline);
1433 : 0 : fputc ('\n', stderr);
1434 : : }
1435 : : }
1436 : :
1437 : : /* CTF is supported for only C at this time. */
1438 : 289199 : if (!lang_GNU_C ()
1439 : 289199 : && ctf_debug_info_level > CTFINFO_LEVEL_NONE)
1440 : : {
1441 : : /* Compiling with -flto results in frontend language of GNU GIMPLE. It
1442 : : is not useful to warn in that case. */
1443 : 38 : if (!startswith (lang_hooks.name, "GNU GIMPLE"))
1444 : 36 : inform (UNKNOWN_LOCATION,
1445 : : "CTF debug info requested, but not supported for %qs frontend",
1446 : : language_string);
1447 : 38 : ctf_debug_info_level = CTFINFO_LEVEL_NONE;
1448 : : }
1449 : :
1450 : 289199 : if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1451 : : {
1452 : 1233 : FILE *final_output = fopen (flag_dump_final_insns, "w");
1453 : 1233 : if (!final_output)
1454 : : {
1455 : 0 : error_at (UNKNOWN_LOCATION,
1456 : : "could not open final insn dump file %qs: %m",
1457 : : flag_dump_final_insns);
1458 : 0 : flag_dump_final_insns = NULL;
1459 : : }
1460 : 1233 : else if (fclose (final_output))
1461 : : {
1462 : 0 : error_at (UNKNOWN_LOCATION,
1463 : : "could not close zeroed insn dump file %qs: %m",
1464 : : flag_dump_final_insns);
1465 : 0 : flag_dump_final_insns = NULL;
1466 : : }
1467 : : }
1468 : :
1469 : : /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1470 : : level is 0. */
1471 : 289199 : if (debug_info_level == DINFO_LEVEL_NONE
1472 : 229976 : && ctf_debug_info_level == CTFINFO_LEVEL_NONE)
1473 : 229972 : write_symbols = NO_DEBUG;
1474 : :
1475 : 289199 : if (write_symbols == NO_DEBUG)
1476 : : ;
1477 : : #ifdef DWARF2_DEBUGGING_INFO
1478 : 59227 : else if (dwarf_debuginfo_p ())
1479 : 58794 : debug_hooks = &dwarf2_debug_hooks;
1480 : : #endif
1481 : : #ifdef CTF_DEBUGGING_INFO
1482 : 433 : else if (ctf_debuginfo_p ())
1483 : 325 : debug_hooks = &dwarf2_debug_hooks;
1484 : : #endif
1485 : : #ifdef BTF_DEBUGGING_INFO
1486 : 108 : else if (btf_debuginfo_p ())
1487 : 108 : debug_hooks = &dwarf2_debug_hooks;
1488 : : #endif
1489 : : #ifdef VMS_DEBUGGING_INFO
1490 : : else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1491 : : debug_hooks = &vmsdbg_debug_hooks;
1492 : : #endif
1493 : : #ifdef DWARF2_LINENO_DEBUGGING_INFO
1494 : : else if (write_symbols == DWARF2_DEBUG)
1495 : : debug_hooks = &dwarf2_lineno_debug_hooks;
1496 : : #endif
1497 : : #ifdef CODEVIEW_DEBUGGING_INFO
1498 : : else if (codeview_debuginfo_p ())
1499 : : debug_hooks = &dwarf2_debug_hooks;
1500 : : #endif
1501 : : else
1502 : : {
1503 : 0 : gcc_assert (debug_set_count (write_symbols) <= 1);
1504 : 0 : error_at (UNKNOWN_LOCATION,
1505 : : "target system does not support the %qs debug format",
1506 : 0 : debug_type_names[debug_set_to_format (write_symbols)]);
1507 : : }
1508 : :
1509 : : /* The debug hooks are used to implement -fdump-go-spec because it
1510 : : gives a simple and stable API for all the information we need to
1511 : : dump. */
1512 : 289199 : if (flag_dump_go_spec != NULL)
1513 : 4 : debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
1514 : :
1515 : 289199 : if (!OPTION_SET_P (dwarf2out_as_loc_support))
1516 : 289193 : dwarf2out_as_loc_support = dwarf2out_default_as_loc_support ();
1517 : 289199 : if (!OPTION_SET_P (dwarf2out_as_locview_support))
1518 : 289199 : dwarf2out_as_locview_support = dwarf2out_default_as_locview_support ();
1519 : 289199 : if (dwarf2out_as_locview_support && !dwarf2out_as_loc_support)
1520 : : {
1521 : 6 : if (OPTION_SET_P (dwarf2out_as_locview_support))
1522 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1523 : : "%<-gas-locview-support%> is forced disabled "
1524 : : "without %<-gas-loc-support%>");
1525 : 6 : dwarf2out_as_locview_support = false;
1526 : : }
1527 : :
1528 : 289199 : if (!OPTION_SET_P (debug_variable_location_views))
1529 : : {
1530 : 289199 : debug_variable_location_views
1531 : 578398 : = (flag_var_tracking
1532 : 50264 : && debug_info_level >= DINFO_LEVEL_NORMAL
1533 : 50264 : && dwarf_debuginfo_p ()
1534 : 578399 : && !dwarf_strict);
1535 : : }
1536 : 0 : else if (debug_variable_location_views == -1 && dwarf_version != 5)
1537 : : {
1538 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1539 : : "without %<-gdwarf-5%>, "
1540 : : "%<-gvariable-location-views=incompat5%> "
1541 : : "is equivalent to %<-gvariable-location-views%>");
1542 : 0 : debug_variable_location_views = 1;
1543 : : }
1544 : :
1545 : 289199 : if (debug_internal_reset_location_views == 2)
1546 : : {
1547 : 289199 : debug_internal_reset_location_views
1548 : 578398 : = (debug_variable_location_views
1549 : 578398 : && targetm.reset_location_view);
1550 : : }
1551 : 0 : else if (debug_internal_reset_location_views
1552 : 0 : && !debug_variable_location_views)
1553 : : {
1554 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1555 : : "%<-ginternal-reset-location-views%> is forced disabled "
1556 : : "without %<-gvariable-location-views%>");
1557 : 0 : debug_internal_reset_location_views = 0;
1558 : : }
1559 : :
1560 : 289199 : if (!OPTION_SET_P (debug_inline_points))
1561 : 289199 : debug_inline_points = debug_variable_location_views;
1562 : 0 : else if (debug_inline_points && !debug_nonbind_markers_p)
1563 : : {
1564 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1565 : : "%<-ginline-points%> is forced disabled without "
1566 : : "%<-gstatement-frontiers%>");
1567 : 0 : debug_inline_points = 0;
1568 : : }
1569 : :
1570 : 289199 : if (!OPTION_SET_P (flag_tree_cselim))
1571 : : {
1572 : 289169 : if (HAVE_conditional_move)
1573 : 289169 : flag_tree_cselim = 1;
1574 : : else
1575 : : flag_tree_cselim = 0;
1576 : : }
1577 : :
1578 : : /* If auxiliary info generation is desired, open the output file.
1579 : : This goes in the same directory as the source file--unlike
1580 : : all the other output files. */
1581 : 289199 : if (flag_gen_aux_info)
1582 : : {
1583 : 0 : aux_info_file = fopen (aux_info_file_name, "w");
1584 : 0 : if (aux_info_file == 0)
1585 : 0 : fatal_error (UNKNOWN_LOCATION,
1586 : : "cannot open %s: %m", aux_info_file_name);
1587 : : }
1588 : :
1589 : 289199 : if (!targetm_common.have_named_sections)
1590 : : {
1591 : 0 : if (flag_function_sections)
1592 : : {
1593 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1594 : : "%<-ffunction-sections%> not supported for this target");
1595 : 0 : flag_function_sections = 0;
1596 : : }
1597 : 0 : if (flag_data_sections)
1598 : : {
1599 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1600 : : "%<-fdata-sections%> not supported for this target");
1601 : 0 : flag_data_sections = 0;
1602 : : }
1603 : : }
1604 : :
1605 : 289199 : if (flag_prefetch_loop_arrays > 0 && !targetm.code_for_prefetch)
1606 : : {
1607 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1608 : : "%<-fprefetch-loop-arrays%> not supported for this target");
1609 : 0 : flag_prefetch_loop_arrays = 0;
1610 : : }
1611 : 289199 : else if (flag_prefetch_loop_arrays > 0 && !targetm.have_prefetch ())
1612 : : {
1613 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1614 : : "%<-fprefetch-loop-arrays%> not supported for this target "
1615 : : "(try %<-march%> switches)");
1616 : 0 : flag_prefetch_loop_arrays = 0;
1617 : : }
1618 : :
1619 : : /* This combination of options isn't handled for i386 targets and doesn't
1620 : : make much sense anyway, so don't allow it. */
1621 : 289199 : if (flag_prefetch_loop_arrays > 0 && optimize_size)
1622 : : {
1623 : 2 : warning_at (UNKNOWN_LOCATION, 0,
1624 : : "%<-fprefetch-loop-arrays%> is not supported with %<-Os%>");
1625 : 2 : flag_prefetch_loop_arrays = 0;
1626 : : }
1627 : :
1628 : : /* The presence of IEEE signaling NaNs, implies all math can trap. */
1629 : 289199 : if (flag_signaling_nans)
1630 : 597 : flag_trapping_math = 1;
1631 : :
1632 : : /* We cannot reassociate if we want traps or signed zeros. */
1633 : 289199 : if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1634 : : {
1635 : 18 : warning_at (UNKNOWN_LOCATION, 0,
1636 : : "%<-fassociative-math%> disabled; other options take "
1637 : : "precedence");
1638 : 18 : flag_associative_math = 0;
1639 : : }
1640 : :
1641 : 289199 : if (flag_hardened && !HAVE_FHARDENED_SUPPORT)
1642 : : {
1643 : : warning_at (UNKNOWN_LOCATION, 0,
1644 : : "%<-fhardened%> not supported for this target");
1645 : : flag_hardened = 0;
1646 : : }
1647 : :
1648 : : /* -fstack-clash-protection is not currently supported on targets
1649 : : where the stack grows up. */
1650 : 289199 : if (flag_stack_clash_protection && !STACK_GROWS_DOWNWARD)
1651 : : {
1652 : : warning_at (UNKNOWN_LOCATION, 0,
1653 : : "%<-fstack-clash-protection%> is not supported on targets "
1654 : : "where the stack grows from lower to higher addresses");
1655 : : flag_stack_clash_protection = 0;
1656 : : }
1657 : 289199 : else if (flag_hardened)
1658 : : {
1659 : 91 : if (!flag_stack_clash_protection
1660 : : /* Don't enable -fstack-clash-protection when -fstack-check=
1661 : : is used: it would result in confusing errors. */
1662 : 91 : && flag_stack_check == NO_STACK_CHECK)
1663 : 87 : flag_stack_clash_protection = 1;
1664 : 4 : else if (flag_stack_check != NO_STACK_CHECK)
1665 : 4 : warning_at (UNKNOWN_LOCATION, OPT_Whardened,
1666 : : "%<-fstack-clash-protection%> is not enabled by "
1667 : : "%<-fhardened%> because %<-fstack-check%> was "
1668 : : "specified on the command line");
1669 : : }
1670 : :
1671 : : /* We cannot support -fstack-check= and -fstack-clash-protection at
1672 : : the same time. */
1673 : 289199 : if (flag_stack_check != NO_STACK_CHECK && flag_stack_clash_protection)
1674 : : {
1675 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1676 : : "%<-fstack-check=%> and %<-fstack-clash-protection%> are "
1677 : : "mutually exclusive; disabling %<-fstack-check=%>");
1678 : 0 : flag_stack_check = NO_STACK_CHECK;
1679 : : }
1680 : :
1681 : : /* Targets must be able to place spill slots at lower addresses. If the
1682 : : target already uses a soft frame pointer, the transition is trivial. */
1683 : 289199 : if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1684 : : {
1685 : : if (!flag_stack_protector_set_by_fhardened_p)
1686 : : warning_at (UNKNOWN_LOCATION, 0,
1687 : : "%<-fstack-protector%> not supported for this target");
1688 : : flag_stack_protect = 0;
1689 : : }
1690 : 289199 : if (!flag_stack_protect)
1691 : 288914 : warn_stack_protect = 0;
1692 : :
1693 : : /* Address Sanitizer needs porting to each target architecture. */
1694 : :
1695 : 289199 : if ((flag_sanitize & SANITIZE_ADDRESS)
1696 : : && !FRAME_GROWS_DOWNWARD)
1697 : : {
1698 : : warning_at (UNKNOWN_LOCATION, 0,
1699 : : "%<-fsanitize=address%> and %<-fsanitize=kernel-address%> "
1700 : : "are not supported for this target");
1701 : : flag_sanitize &= ~SANITIZE_ADDRESS;
1702 : : }
1703 : :
1704 : 289199 : if ((flag_sanitize & SANITIZE_USER_ADDRESS)
1705 : 289199 : && ((targetm.asan_shadow_offset == NULL)
1706 : 2996 : || ((targetm.asan_shadow_offset () == 0)
1707 : 0 : && !targetm.asan_dynamic_shadow_offset_p ())))
1708 : : {
1709 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1710 : : "%<-fsanitize=address%> not supported for this target");
1711 : 0 : flag_sanitize &= ~SANITIZE_ADDRESS;
1712 : : }
1713 : :
1714 : 289199 : if ((flag_sanitize & SANITIZE_KERNEL_ADDRESS)
1715 : 289199 : && (targetm.asan_shadow_offset == NULL
1716 : 0 : && !asan_shadow_offset_set_p ()))
1717 : : {
1718 : 0 : warning_at (UNKNOWN_LOCATION, 0,
1719 : : "%<-fsanitize=kernel-address%> with stack protection "
1720 : : "is not supported without %<-fasan-shadow-offset=%> "
1721 : : "for this target");
1722 : 0 : flag_sanitize &= ~SANITIZE_ADDRESS;
1723 : : }
1724 : :
1725 : : /* HWAsan requires top byte ignore feature in the backend. */
1726 : 289199 : if (flag_sanitize & SANITIZE_HWADDRESS
1727 : 289199 : && ! targetm.memtag.can_tag_addresses ())
1728 : : {
1729 : 0 : warning_at (UNKNOWN_LOCATION, 0, "%qs is not supported for this target",
1730 : : "-fsanitize=hwaddress");
1731 : 0 : flag_sanitize &= ~SANITIZE_HWADDRESS;
1732 : : }
1733 : :
1734 : 289199 : if (flag_sanitize & SANITIZE_SHADOW_CALL_STACK)
1735 : : {
1736 : 0 : if (!targetm.have_shadow_call_stack)
1737 : 0 : sorry ("%<-fsanitize=shadow-call-stack%> not supported "
1738 : : "in current platform");
1739 : 0 : else if (flag_exceptions)
1740 : 0 : error_at (UNKNOWN_LOCATION, "%<-fsanitize=shadow-call-stack%> "
1741 : : "requires %<-fno-exceptions%>");
1742 : : }
1743 : :
1744 : 289199 : HOST_WIDE_INT patch_area_size, patch_area_start;
1745 : 289199 : parse_and_check_patch_area (flag_patchable_function_entry, false,
1746 : : &patch_area_size, &patch_area_start);
1747 : :
1748 : : /* Do not use IPA optimizations for register allocation if profiler is active
1749 : : or patchable function entries are inserted for run-time instrumentation
1750 : : or port does not emit prologue and epilogue as RTL. */
1751 : 288841 : if (profile_flag || patch_area_size
1752 : 578007 : || !targetm.have_prologue () || !targetm.have_epilogue ())
1753 : 391 : flag_ipa_ra = 0;
1754 : :
1755 : : /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
1756 : : have not been set. */
1757 : 289199 : if (!OPTION_SET_P (warnings_are_errors))
1758 : : {
1759 : 284796 : if (warn_coverage_mismatch
1760 : 284796 : && option_unspecified_p (OPT_Wcoverage_mismatch))
1761 : 284790 : diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
1762 : : diagnostics::kind::error,
1763 : : UNKNOWN_LOCATION);
1764 : 284796 : if (warn_coverage_invalid_linenum
1765 : 284796 : && option_unspecified_p (OPT_Wcoverage_invalid_line_number))
1766 : 284795 : diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_invalid_line_number,
1767 : : diagnostics::kind::error,
1768 : : UNKNOWN_LOCATION);
1769 : : }
1770 : :
1771 : : /* Save the current optimization options. */
1772 : 289199 : optimization_default_node
1773 : 289199 : = build_optimization_node (&global_options, &global_options_set);
1774 : 289199 : optimization_current_node = optimization_default_node;
1775 : :
1776 : 289199 : if (flag_checking >= 2)
1777 : 289137 : hash_table_sanitize_eq_limit
1778 : 289137 : = param_hash_table_verification_limit;
1779 : :
1780 : 289199 : diagnose_options (&global_options, &global_options_set, UNKNOWN_LOCATION);
1781 : :
1782 : : /* Please don't change global_options after this point, those changes won't
1783 : : be reflected in optimization_{default,current}_node. */
1784 : 289199 : }
1785 : :
1786 : : /* This function can be called multiple times to reinitialize the compiler
1787 : : back end when register classes or instruction sets have changed,
1788 : : before each function. */
1789 : : static void
1790 : 214285 : backend_init_target (void)
1791 : : {
1792 : : /* This depends on stack_pointer_rtx. */
1793 : 214285 : init_fake_stack_mems ();
1794 : :
1795 : : /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1796 : : mode-dependent. */
1797 : 214285 : init_alias_target ();
1798 : :
1799 : : /* Depends on HARD_FRAME_POINTER_REGNUM. */
1800 : 214285 : if (!ira_use_lra_p)
1801 : 0 : init_reload ();
1802 : :
1803 : : /* Depends on the enabled attribute. */
1804 : 214285 : recog_init ();
1805 : :
1806 : : /* The following initialization functions need to generate rtl, so
1807 : : provide a dummy function context for them. */
1808 : 214285 : init_dummy_function_start ();
1809 : :
1810 : : /* rtx_cost is mode-dependent, so cached values need to be recomputed
1811 : : on a mode change. */
1812 : 214285 : init_expmed ();
1813 : 214285 : init_lower_subreg ();
1814 : 214285 : init_set_costs ();
1815 : :
1816 : 214285 : init_expr_target ();
1817 : 214285 : ira_init ();
1818 : :
1819 : : /* We may need to recompute regno_save_code[] and regno_restore_code[]
1820 : : after a mode change as well. */
1821 : 214285 : caller_save_initialized_p = false;
1822 : :
1823 : 214285 : expand_dummy_function_end ();
1824 : 214285 : }
1825 : :
1826 : : /* Initialize the compiler back end. This function is called only once,
1827 : : when starting the compiler. */
1828 : : static void
1829 : 282169 : backend_init (void)
1830 : : {
1831 : : #if CHECKING_P
1832 : 282169 : verify_reg_names_in_constraints ();
1833 : : #endif
1834 : :
1835 : 282169 : init_emit_once ();
1836 : :
1837 : 282169 : init_rtlanal ();
1838 : 282169 : init_inline_once ();
1839 : 282169 : init_varasm_once ();
1840 : 282169 : save_register_info ();
1841 : :
1842 : : /* Middle end needs this initialization for default mem attributes
1843 : : used by early calls to make_decl_rtl. */
1844 : 282169 : init_emit_regs ();
1845 : :
1846 : : /* Middle end needs this initialization for mode tables used to assign
1847 : : modes to vector variables. */
1848 : 282169 : init_regs ();
1849 : 282169 : }
1850 : :
1851 : : /* Initialize things that are both lang-dependent and target-dependent.
1852 : : This function can be called more than once if target parameters change. */
1853 : : static void
1854 : 769060 : lang_dependent_init_target (void)
1855 : : {
1856 : : /* This creates various _DECL nodes, so needs to be called after the
1857 : : front end is initialized. It also depends on the HAVE_xxx macros
1858 : : generated from the target machine description. */
1859 : 769060 : init_optabs ();
1860 : :
1861 : 769060 : gcc_assert (!this_target_rtl->target_specific_initialized);
1862 : 769060 : }
1863 : :
1864 : : /* Perform initializations that are lang-dependent or target-dependent.
1865 : : but matters only for late optimizations and RTL generation. */
1866 : :
1867 : : static int rtl_initialized;
1868 : :
1869 : : void
1870 : 1478497 : initialize_rtl (void)
1871 : : {
1872 : 1478497 : auto_timevar tv (g_timer, TV_INITIALIZE_RTL);
1873 : :
1874 : : /* Initialization done just once per compilation, but delayed
1875 : : till code generation. */
1876 : 1478497 : if (!rtl_initialized)
1877 : 210017 : ira_init_once ();
1878 : 1478497 : rtl_initialized = true;
1879 : :
1880 : : /* Target specific RTL backend initialization. */
1881 : 1478497 : if (!this_target_rtl->target_specific_initialized)
1882 : : {
1883 : 214285 : backend_init_target ();
1884 : 214285 : this_target_rtl->target_specific_initialized = true;
1885 : : }
1886 : 1478497 : }
1887 : :
1888 : : /* Language-dependent initialization. Returns nonzero on success. */
1889 : : static int
1890 : 288981 : lang_dependent_init (const char *name)
1891 : : {
1892 : 288981 : location_t save_loc = input_location;
1893 : 288981 : if (!dump_base_name)
1894 : : {
1895 : 2767 : dump_base_name = name && name[0] ? name : "gccdump";
1896 : :
1897 : : /* We do not want to derive a non-empty dumpbase-ext from an
1898 : : explicit -dumpbase argument, only from a defaulted
1899 : : dumpbase. */
1900 : 2767 : if (!dump_base_ext)
1901 : : {
1902 : 2767 : const char *base = lbasename (dump_base_name);
1903 : 2767 : const char *ext = strrchr (base, '.');
1904 : 2767 : if (ext)
1905 : 2767 : dump_base_ext = ext;
1906 : : }
1907 : : }
1908 : :
1909 : : /* Other front-end initialization. */
1910 : 288981 : input_location = BUILTINS_LOCATION;
1911 : 288981 : if (lang_hooks.init () == 0)
1912 : : return 0;
1913 : 282166 : input_location = save_loc;
1914 : :
1915 : 282166 : if (!flag_wpa)
1916 : : {
1917 : 273348 : init_asm_output (name);
1918 : :
1919 : 273348 : if (!flag_generate_lto && !flag_compare_debug)
1920 : : {
1921 : : /* If stack usage information is desired, open the output file. */
1922 : 248226 : if (flag_stack_usage)
1923 : 311 : stack_usage_file = open_auxiliary_file ("su");
1924 : :
1925 : : /* If call graph information is desired, open the output file. */
1926 : 248226 : if (flag_callgraph_info)
1927 : : {
1928 : 1 : callgraph_info_file = open_auxiliary_file ("ci");
1929 : : /* Write the file header. */
1930 : 1 : fprintf (callgraph_info_file,
1931 : : "graph: { title: \"%s\"\n", main_input_filename);
1932 : 1 : bitmap_obstack_initialize (NULL);
1933 : 1 : callgraph_info_external_printed = BITMAP_ALLOC (NULL);
1934 : : }
1935 : : }
1936 : : else
1937 : 25122 : flag_stack_usage = flag_callgraph_info = false;
1938 : : }
1939 : :
1940 : : /* This creates various _DECL nodes, so needs to be called after the
1941 : : front end is initialized. */
1942 : 282166 : init_eh ();
1943 : :
1944 : : /* Do the target-specific parts of the initialization. */
1945 : 282166 : lang_dependent_init_target ();
1946 : :
1947 : 282166 : if (!flag_wpa)
1948 : : {
1949 : : /* If dbx symbol table desired, initialize writing it and output the
1950 : : predefined types. */
1951 : 273348 : timevar_push (TV_SYMOUT);
1952 : :
1953 : : /* Now we have the correct original filename, we can initialize
1954 : : debug output. */
1955 : 273348 : (*debug_hooks->init) (name);
1956 : :
1957 : 273348 : timevar_pop (TV_SYMOUT);
1958 : : }
1959 : :
1960 : : return 1;
1961 : : }
1962 : :
1963 : :
1964 : : /* Reinitialize everything when target parameters, such as register usage,
1965 : : have changed. */
1966 : : void
1967 : 489082 : target_reinit (void)
1968 : : {
1969 : 489082 : if (no_backend)
1970 : 2188 : return;
1971 : :
1972 : 486894 : struct rtl_data saved_x_rtl;
1973 : 486894 : rtx *saved_regno_reg_rtx;
1974 : 486894 : tree saved_optimization_current_node;
1975 : 486894 : struct target_optabs *saved_this_fn_optabs;
1976 : :
1977 : : /* Temporarily switch to the default optimization node, so that
1978 : : *this_target_optabs is set to the default, not reflecting
1979 : : whatever a previous function used for the optimize
1980 : : attribute. */
1981 : 486894 : saved_optimization_current_node = optimization_current_node;
1982 : 486894 : saved_this_fn_optabs = this_fn_optabs;
1983 : 486894 : if (saved_optimization_current_node != optimization_default_node)
1984 : : {
1985 : 0 : optimization_current_node = optimization_default_node;
1986 : 0 : cl_optimization_restore
1987 : 0 : (&global_options, &global_options_set,
1988 : 0 : TREE_OPTIMIZATION (optimization_default_node));
1989 : : }
1990 : 486894 : this_fn_optabs = this_target_optabs;
1991 : :
1992 : : /* Save *crtl and regno_reg_rtx around the reinitialization
1993 : : to allow target_reinit being called even after prepare_function_start. */
1994 : 486894 : saved_regno_reg_rtx = regno_reg_rtx;
1995 : 486894 : if (saved_regno_reg_rtx)
1996 : : {
1997 : 5 : saved_x_rtl = *crtl;
1998 : 5 : memset (crtl, '\0', sizeof (*crtl));
1999 : 5 : regno_reg_rtx = NULL;
2000 : : }
2001 : :
2002 : 486894 : this_target_rtl->target_specific_initialized = false;
2003 : :
2004 : : /* This initializes hard_frame_pointer, and calls init_reg_modes_target()
2005 : : to initialize reg_raw_mode[]. */
2006 : 486894 : init_emit_regs ();
2007 : :
2008 : : /* This invokes target hooks to set fixed_reg[] etc, which is
2009 : : mode-dependent. */
2010 : 486894 : init_regs ();
2011 : :
2012 : : /* Reinitialize lang-dependent parts. */
2013 : 486894 : lang_dependent_init_target ();
2014 : :
2015 : : /* Restore the original optimization node. */
2016 : 486894 : if (saved_optimization_current_node != optimization_default_node)
2017 : : {
2018 : 0 : optimization_current_node = saved_optimization_current_node;
2019 : 0 : cl_optimization_restore (&global_options, &global_options_set,
2020 : 0 : TREE_OPTIMIZATION (optimization_current_node));
2021 : : }
2022 : 486894 : this_fn_optabs = saved_this_fn_optabs;
2023 : :
2024 : : /* Restore regno_reg_rtx at the end, as free_after_compilation from
2025 : : expand_dummy_function_end clears it. */
2026 : 486894 : if (saved_regno_reg_rtx)
2027 : : {
2028 : 5 : *crtl = saved_x_rtl;
2029 : 5 : regno_reg_rtx = saved_regno_reg_rtx;
2030 : 5 : saved_regno_reg_rtx = NULL;
2031 : : }
2032 : : }
2033 : :
2034 : : void
2035 : 0 : dump_memory_report (const char *header)
2036 : : {
2037 : : /* Print significant header. */
2038 : 0 : fputc ('\n', stderr);
2039 : 0 : for (unsigned i = 0; i < 80; i++)
2040 : 0 : fputc ('#', stderr);
2041 : 0 : fprintf (stderr, "\n# %-77s#\n", header);
2042 : 0 : for (unsigned i = 0; i < 80; i++)
2043 : 0 : fputc ('#', stderr);
2044 : 0 : fputs ("\n\n", stderr);
2045 : :
2046 : 0 : dump_line_table_statistics ();
2047 : 0 : ggc_print_statistics ();
2048 : 0 : stringpool_statistics ();
2049 : 0 : dump_tree_statistics ();
2050 : 0 : dump_gimple_statistics ();
2051 : 0 : dump_rtx_statistics ();
2052 : 0 : dump_alloc_pool_statistics ();
2053 : 0 : dump_bitmap_statistics ();
2054 : 0 : dump_hash_table_loc_statistics ();
2055 : 0 : dump_vec_loc_statistics ();
2056 : 0 : dump_ggc_loc_statistics ();
2057 : 0 : dump_alias_stats (stderr);
2058 : 0 : dump_pta_stats (stderr);
2059 : 0 : }
2060 : :
2061 : : /* Clean up: close opened files, etc. */
2062 : :
2063 : : static void
2064 : 286936 : finalize ()
2065 : : {
2066 : : /* Close the dump files. */
2067 : 286936 : if (flag_gen_aux_info)
2068 : : {
2069 : 0 : fclose (aux_info_file);
2070 : 0 : aux_info_file = NULL;
2071 : 0 : if (seen_error ())
2072 : 0 : unlink (aux_info_file_name);
2073 : : }
2074 : :
2075 : : /* Close non-debugging input and output files. Take special care to note
2076 : : whether fclose returns an error, since the pages might still be on the
2077 : : buffer chain while the file is open. */
2078 : :
2079 : 286936 : if (asm_out_file)
2080 : : {
2081 : 271482 : if (ferror (asm_out_file) != 0)
2082 : 0 : fatal_error (input_location, "error writing to %s: %m", asm_file_name);
2083 : 271482 : if (fclose (asm_out_file) != 0)
2084 : 0 : fatal_error (input_location, "error closing %s: %m", asm_file_name);
2085 : 271482 : asm_out_file = NULL;
2086 : : }
2087 : :
2088 : 286936 : if (stack_usage_file)
2089 : : {
2090 : 311 : fclose (stack_usage_file);
2091 : 311 : stack_usage_file = NULL;
2092 : : }
2093 : :
2094 : 286936 : if (callgraph_info_file)
2095 : : {
2096 : 1 : fputs ("}\n", callgraph_info_file);
2097 : 1 : fclose (callgraph_info_file);
2098 : 1 : callgraph_info_file = NULL;
2099 : 1 : BITMAP_FREE (callgraph_info_external_printed);
2100 : 1 : bitmap_obstack_release (NULL);
2101 : : }
2102 : :
2103 : 286936 : if (seen_error ())
2104 : 26617 : coverage_remove_note_file ();
2105 : :
2106 : 286936 : if (!no_backend)
2107 : : {
2108 : 280300 : statistics_fini ();
2109 : 280300 : debuginfo_fini ();
2110 : :
2111 : 280300 : g->get_passes ()->finish_optimization_passes ();
2112 : :
2113 : 280300 : lra_finish_once ();
2114 : : }
2115 : :
2116 : 286936 : if (mem_report)
2117 : 0 : dump_memory_report ("Final");
2118 : :
2119 : 286936 : if (profile_report)
2120 : 0 : dump_profile_report ();
2121 : :
2122 : 286936 : if (flag_dbg_cnt_list)
2123 : 0 : dbg_cnt_list_all_counters ();
2124 : :
2125 : : /* Language-specific end of compilation actions. */
2126 : 286936 : lang_hooks.finish ();
2127 : 286936 : }
2128 : :
2129 : : static bool
2130 : 281859 : standard_type_bitsize (int bitsize)
2131 : : {
2132 : : /* As a special exception, we always want __int128 enabled if possible. */
2133 : 281859 : if (bitsize == 128)
2134 : : return false;
2135 : : if (bitsize == CHAR_TYPE_SIZE
2136 : : || bitsize == SHORT_TYPE_SIZE
2137 : : || bitsize == INT_TYPE_SIZE
2138 : 0 : || bitsize == LONG_TYPE_SIZE
2139 : 0 : || bitsize == LONG_LONG_TYPE_SIZE)
2140 : 0 : return true;
2141 : : return false;
2142 : : }
2143 : :
2144 : : /* Initialize the compiler, and compile the input file. */
2145 : : static void
2146 : 289199 : do_compile ()
2147 : : {
2148 : : /* Don't do any more if an error has already occurred. */
2149 : 289199 : if (!seen_error ())
2150 : : {
2151 : 288981 : int i;
2152 : :
2153 : 288981 : timevar_start (TV_PHASE_SETUP);
2154 : :
2155 : 288981 : if (flag_save_optimization_record)
2156 : : {
2157 : 41 : dump_context::get ().set_json_writer (new optrecord_json_writer ());
2158 : : }
2159 : :
2160 : : /* This must be run always, because it is needed to compute the FP
2161 : : predefined macros, such as __LDBL_MAX__, for targets using non
2162 : : default FP formats. */
2163 : 288981 : init_adjust_machine_modes ();
2164 : 288981 : init_derived_machine_modes ();
2165 : :
2166 : : /* This must happen after the backend has a chance to process
2167 : : command line options, but before the parsers are
2168 : : initialized. */
2169 : 866943 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
2170 : 288981 : if (targetm.scalar_mode_supported_p (int_n_data[i].m)
2171 : 288981 : && ! standard_type_bitsize (int_n_data[i].bitsize))
2172 : 281859 : int_n_enabled_p[i] = true;
2173 : : else
2174 : 7122 : int_n_enabled_p[i] = false;
2175 : :
2176 : : /* Initialize mpfrs exponent range. This is important to get
2177 : : underflow/overflow in a reasonable timeframe. */
2178 : 288981 : machine_mode mode;
2179 : 288981 : int min_exp = -1;
2180 : 288981 : int max_exp = 1;
2181 : 2022867 : FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT)
2182 : 1733886 : if (SCALAR_FLOAT_MODE_P (mode))
2183 : : {
2184 : 1733886 : const real_format *fmt = REAL_MODE_FORMAT (mode);
2185 : 1733886 : if (fmt)
2186 : : {
2187 : : /* fmt->emin - fmt->p + 1 should be enough but the
2188 : : back-and-forth dance in real_to_decimal_for_mode we
2189 : : do for checking fails due to rounding effects then. */
2190 : 1733886 : if ((fmt->emin - fmt->p) < min_exp)
2191 : : min_exp = fmt->emin - fmt->p;
2192 : 1733886 : if (fmt->emax > max_exp)
2193 : : max_exp = fmt->emax;
2194 : : }
2195 : : }
2196 : : /* E.g. mpc_norm assumes it can square a number without bothering with
2197 : : with range scaling, so until that is fixed, double the minimum
2198 : : and maximum exponents, plus add some buffer for arithmetics
2199 : : on the squared numbers. */
2200 : 288981 : if (mpfr_set_emin (2 * (min_exp - 1))
2201 : 288981 : || mpfr_set_emax (2 * (max_exp + 1)))
2202 : 0 : sorry ("mpfr not configured to handle all floating modes");
2203 : :
2204 : : /* Set up the back-end if requested. */
2205 : 288981 : if (!no_backend)
2206 : 282169 : backend_init ();
2207 : :
2208 : : /* Language-dependent initialization. Returns true on success. */
2209 : 288981 : if (lang_dependent_init (main_input_filename))
2210 : : {
2211 : : /* Initialize yet another pass. */
2212 : :
2213 : 282166 : ggc_protect_identifiers = true;
2214 : :
2215 : 282166 : symtab->initialize ();
2216 : 282166 : init_final (main_input_filename);
2217 : 282166 : coverage_init (aux_base_name);
2218 : 282166 : statistics_init ();
2219 : 282166 : debuginfo_init ();
2220 : 282166 : invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
2221 : :
2222 : 282166 : timevar_stop (TV_PHASE_SETUP);
2223 : :
2224 : 282166 : compile_file ();
2225 : : }
2226 : : else
2227 : : {
2228 : 6636 : timevar_stop (TV_PHASE_SETUP);
2229 : : }
2230 : :
2231 : 286936 : timevar_start (TV_PHASE_FINALIZE);
2232 : :
2233 : 286936 : finalize ();
2234 : :
2235 : 286936 : timevar_stop (TV_PHASE_FINALIZE);
2236 : : }
2237 : 287154 : }
2238 : :
2239 : 289302 : toplev::toplev (timer *external_timer,
2240 : 289302 : bool init_signals)
2241 : 289302 : : m_use_TV_TOTAL (external_timer == NULL),
2242 : 289302 : m_init_signals (init_signals)
2243 : : {
2244 : 289302 : if (external_timer)
2245 : 400 : g_timer = external_timer;
2246 : 289302 : }
2247 : :
2248 : 287252 : toplev::~toplev ()
2249 : : {
2250 : 287252 : if (g_timer && m_use_TV_TOTAL)
2251 : : {
2252 : 12 : g_timer->stop (TV_TOTAL);
2253 : 12 : g_timer->print (stderr);
2254 : 12 : delete g_timer;
2255 : 12 : g_timer = NULL;
2256 : : }
2257 : 287252 : }
2258 : :
2259 : : /* Potentially call timevar_init (which will create g_timevars if it
2260 : : doesn't already exist). */
2261 : :
2262 : : void
2263 : 288799 : toplev::start_timevars ()
2264 : : {
2265 : 288799 : if (time_report || !quiet_flag || flag_detailed_statistics)
2266 : 20 : timevar_init ();
2267 : :
2268 : 288799 : timevar_start (TV_TOTAL);
2269 : 288799 : }
2270 : :
2271 : : /* Handle -fself-test. */
2272 : :
2273 : : void
2274 : 4 : toplev::run_self_tests ()
2275 : : {
2276 : : #if CHECKING_P
2277 : : /* Reset some state. */
2278 : 4 : input_location = UNKNOWN_LOCATION;
2279 : 4 : bitmap_obstack_initialize (NULL);
2280 : :
2281 : : /* Run the tests; any failures will lead to an abort of the process.
2282 : : Use "make selftests-gdb" to run under the debugger. */
2283 : 4 : ::selftest::run_tests ();
2284 : :
2285 : : /* Cleanup. */
2286 : 4 : bitmap_obstack_release (NULL);
2287 : : #else
2288 : : inform (UNKNOWN_LOCATION, "self-tests are not enabled in this build");
2289 : : #endif /* #if CHECKING_P */
2290 : 4 : }
2291 : :
2292 : : /* Entry point of cc1, cc1plus, jc1, f771, etc.
2293 : : Exit code is FATAL_EXIT_CODE if can't open files or if there were
2294 : : any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2295 : :
2296 : : It is not safe to call this function more than once. */
2297 : :
2298 : : int
2299 : 289302 : toplev::main (int argc, char **argv)
2300 : : {
2301 : : /* Parsing and gimplification sometimes need quite large stack.
2302 : : Increase stack size limits if possible. */
2303 : 289302 : stack_limit_increase (64 * 1024 * 1024);
2304 : :
2305 : : /* Stash a copy of the original argv before expansion
2306 : : for use by SARIF output. */
2307 : 289302 : unique_argv original_argv (dupargv (argv));
2308 : :
2309 : 289302 : expandargv (&argc, &argv);
2310 : :
2311 : : /* Initialization of GCC's environment, and diagnostics. */
2312 : 289302 : general_init (argv[0], m_init_signals, std::move (original_argv));
2313 : :
2314 : : /* One-off initialization of options that does not need to be
2315 : : repeated when options are added for particular functions. */
2316 : 289302 : init_options_once ();
2317 : 289302 : init_opts_obstack ();
2318 : :
2319 : : /* Initialize global options structures; this must be repeated for
2320 : : each structure used for parsing options. */
2321 : 289302 : init_options_struct (&global_options, &global_options_set);
2322 : 289302 : lang_hooks.init_options_struct (&global_options);
2323 : :
2324 : : /* Init GGC heuristics must be caller after we initialize
2325 : : options. */
2326 : 289302 : init_ggc_heuristics ();
2327 : :
2328 : : /* Convert the options to an array. */
2329 : 289302 : decode_cmdline_options_to_array_default_mask (argc,
2330 : : CONST_CAST2 (const char **,
2331 : : char **, argv),
2332 : : &save_decoded_options,
2333 : : &save_decoded_options_count);
2334 : :
2335 : : /* Save Optimization decoded options. */
2336 : 289302 : save_opt_decoded_options = new vec<cl_decoded_option> ();
2337 : 8389177 : for (unsigned i = 1; i < save_decoded_options_count; ++i)
2338 : 8099875 : if (save_decoded_options[i].opt_index < cl_options_count
2339 : 7799712 : && cl_options[save_decoded_options[i].opt_index].flags & CL_OPTIMIZATION)
2340 : 318645 : save_opt_decoded_options->safe_push (save_decoded_options[i]);
2341 : :
2342 : : /* Perform language-specific options initialization. */
2343 : 289302 : lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
2344 : :
2345 : : /* Parse the options and do minimal processing; basically just
2346 : : enough to default flags appropriately. */
2347 : 289302 : decode_options (&global_options, &global_options_set,
2348 : : save_decoded_options, save_decoded_options_count,
2349 : : UNKNOWN_LOCATION, global_dc,
2350 : : targetm.target_option.override);
2351 : :
2352 : 289302 : global_dc->get_file_cache ().tune (param_file_cache_files,
2353 : 289302 : param_file_cache_lines);
2354 : :
2355 : 289302 : handle_common_deferred_options ();
2356 : :
2357 : 289298 : diagnostics::maybe_open_sarif_sink_for_socket (*global_dc);
2358 : :
2359 : 289298 : init_local_tick ();
2360 : :
2361 : 289298 : initialize_plugins ();
2362 : :
2363 : : /* Handle the dump options now that plugins have had a chance to install new
2364 : : passes. */
2365 : 289298 : handle_deferred_dump_options ();
2366 : :
2367 : 289298 : if (version_flag)
2368 : 114 : print_version (stderr, "", true);
2369 : :
2370 : 289298 : if (help_flag)
2371 : 3 : print_plugins_help (stderr, "");
2372 : :
2373 : : /* Exit early if we can (e.g. -help). */
2374 : 289298 : if (!exit_after_options)
2375 : : {
2376 : : /* Just in case lang_hooks.post_options ends up calling a debug_hook.
2377 : : This can happen with incorrect pre-processed input. */
2378 : 289200 : debug_hooks = &do_nothing_debug_hooks;
2379 : : /* Allow the front end to perform consistency checks and do further
2380 : : initialization based on the command line options. This hook also
2381 : : sets the original filename if appropriate (e.g. foo.i -> foo.c)
2382 : : so we can correctly initialize debug output. */
2383 : 289200 : no_backend = lang_hooks.post_options (&main_input_filename);
2384 : :
2385 : 289199 : process_options ();
2386 : :
2387 : 289199 : if (m_use_TV_TOTAL)
2388 : 288799 : start_timevars ();
2389 : 289199 : do_compile ();
2390 : :
2391 : 287154 : if (flag_self_test && !seen_error ())
2392 : : {
2393 : 5 : if (no_backend)
2394 : 1 : error_at (UNKNOWN_LOCATION, "self-tests incompatible with %<-E%>");
2395 : : else
2396 : 4 : run_self_tests ();
2397 : : }
2398 : : }
2399 : :
2400 : 287252 : if (warningcount || errorcount || werrorcount)
2401 : 39639 : print_ignored_options ();
2402 : :
2403 : : /* Invoke registered plugin callbacks if any. Some plugins could
2404 : : emit some diagnostics here. */
2405 : 287252 : invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2406 : :
2407 : 287252 : if (auto change_set_ptr = global_dc->get_fixits_change_set ())
2408 : : {
2409 : 17 : pretty_printer pp;
2410 : 17 : pp_show_color (&pp) = pp_show_color (global_dc->get_reference_printer ());
2411 : 17 : change_set_ptr->print_diff (&pp, true);
2412 : 17 : pp_flush (&pp);
2413 : 17 : }
2414 : :
2415 : 287252 : diagnostic_finish (global_dc);
2416 : :
2417 : 287252 : finalize_plugins ();
2418 : :
2419 : 287252 : after_memory_report = true;
2420 : :
2421 : 287252 : if (global_dc->execution_failed_p ())
2422 : 27101 : return (FATAL_EXIT_CODE);
2423 : :
2424 : : return (SUCCESS_EXIT_CODE);
2425 : 287252 : }
2426 : :
2427 : : /* For those that want to, this function aims to clean up enough state that
2428 : : you can call toplev::main again. */
2429 : : void
2430 : 260333 : toplev::finalize (void)
2431 : : {
2432 : 260333 : no_backend = false;
2433 : 260333 : rtl_initialized = false;
2434 : 260333 : this_target_rtl->target_specific_initialized = false;
2435 : :
2436 : : /* Needs to be called before cgraph_cc_finalize since it uses symtab. */
2437 : 260333 : ipa_reference_cc_finalize ();
2438 : 260333 : ipa_fnsummary_cc_finalize ();
2439 : 260333 : ipa_modref_cc_finalize ();
2440 : 260333 : ipa_edge_modifications_finalize ();
2441 : 260333 : ipa_icf_cc_finalize ();
2442 : :
2443 : 260333 : ipa_prop_cc_finalize ();
2444 : 260333 : ipa_profile_cc_finalize ();
2445 : 260333 : ipa_sra_cc_finalize ();
2446 : 260333 : cgraph_cc_finalize ();
2447 : 260333 : cgraphunit_cc_finalize ();
2448 : 260333 : symtab_thunks_cc_finalize ();
2449 : 260333 : dwarf2cfi_cc_finalize ();
2450 : 260333 : dwarf2out_cc_finalize ();
2451 : 260333 : gcse_cc_finalize ();
2452 : 260333 : ipa_cp_cc_finalize ();
2453 : 260333 : ira_costs_cc_finalize ();
2454 : 260333 : tree_cc_finalize ();
2455 : 260333 : reginfo_cc_finalize ();
2456 : 260333 : varasm_cc_finalize ();
2457 : :
2458 : : /* save_decoded_options uses opts_obstack, so these must
2459 : : be cleaned up together. */
2460 : 260333 : obstack_free (&opts_obstack, NULL);
2461 : 260333 : XDELETEVEC (save_decoded_options);
2462 : 260333 : save_decoded_options = NULL;
2463 : 260333 : save_decoded_options_count = 0;
2464 : :
2465 : 260333 : ggc_common_finalize ();
2466 : :
2467 : : /* Clean up the context (and pass_manager etc). */
2468 : 260333 : delete g;
2469 : 260333 : g = NULL;
2470 : :
2471 : 260333 : }
|