integrate.c: Remove.
[gcc.git] / gcc / toplev.c
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 2011 Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
21
22 /* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
26
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include "line-map.h"
32 #include "input.h"
33 #include "tree.h"
34 #include "realmpfr.h" /* For GMP/MPFR/MPC versions, in print_version. */
35 #include "version.h"
36 #include "rtl.h"
37 #include "tm_p.h"
38 #include "flags.h"
39 #include "insn-attr.h"
40 #include "insn-config.h"
41 #include "insn-flags.h"
42 #include "hard-reg-set.h"
43 #include "recog.h"
44 #include "output.h"
45 #include "except.h"
46 #include "function.h"
47 #include "toplev.h"
48 #include "expr.h"
49 #include "basic-block.h"
50 #include "intl.h"
51 #include "ggc.h"
52 #include "graph.h"
53 #include "regs.h"
54 #include "timevar.h"
55 #include "diagnostic.h"
56 #include "tree-diagnostic.h"
57 #include "tree-pretty-print.h"
58 #include "params.h"
59 #include "reload.h"
60 #include "ira.h"
61 #include "dwarf2asm.h"
62 #include "debug.h"
63 #include "target.h"
64 #include "common/common-target.h"
65 #include "langhooks.h"
66 #include "cfglayout.h"
67 #include "cfgloop.h"
68 #include "hosthooks.h"
69 #include "cgraph.h"
70 #include "opts.h"
71 #include "opts-diagnostic.h"
72 #include "coverage.h"
73 #include "value-prof.h"
74 #include "alloc-pool.h"
75 #include "tree-mudflap.h"
76 #include "gimple.h"
77 #include "tree-ssa-alias.h"
78 #include "plugin.h"
79
80 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
81 #include "dwarf2out.h"
82 #endif
83
84 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
85 #include "dbxout.h"
86 #endif
87
88 #ifdef SDB_DEBUGGING_INFO
89 #include "sdbout.h"
90 #endif
91
92 #ifdef XCOFF_DEBUGGING_INFO
93 #include "xcoffout.h" /* Needed for external data
94 declarations for e.g. AIX 4.x. */
95 #endif
96
97 static void general_init (const char *);
98 static void do_compile (void);
99 static void process_options (void);
100 static void backend_init (void);
101 static int lang_dependent_init (const char *);
102 static void init_asm_output (const char *);
103 static void finalize (bool);
104
105 static void crash_signal (int) ATTRIBUTE_NORETURN;
106 static void compile_file (void);
107
108 /* True if we don't need a backend (e.g. preprocessing only). */
109 static bool no_backend;
110
111 /* Length of line when printing switch values. */
112 #define MAX_LINE 75
113
114 /* Decoded options, and number of such options. */
115 struct cl_decoded_option *save_decoded_options;
116 unsigned int save_decoded_options_count;
117
118 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
119 to optimize in process_options (). */
120 #define AUTODETECT_VALUE 2
121
122 /* Debug hooks - dependent upon command line options. */
123
124 const struct gcc_debug_hooks *debug_hooks;
125
126 /* The FUNCTION_DECL for the function currently being compiled,
127 or 0 if between functions. */
128 tree current_function_decl;
129
130 /* Set to the FUNC_BEGIN label of the current function, or NULL
131 if none. */
132 const char * current_function_func_begin_label;
133
134 /* A random sequence of characters, unless overridden by user. */
135 static const char *flag_random_seed;
136
137 /* A local time stamp derived from the time of compilation. It will be
138 zero if the system cannot provide a time. It will be -1u, if the
139 user has specified a particular random seed. */
140 unsigned local_tick;
141
142 /* Random number for this compilation */
143 HOST_WIDE_INT random_seed;
144
145 /* -f flags. */
146
147 /* When non-NULL, indicates that whenever space is allocated on the
148 stack, the resulting stack pointer must not pass this
149 address---that is, for stacks that grow downward, the stack pointer
150 must always be greater than or equal to this address; for stacks
151 that grow upward, the stack pointer must be less than this address.
152 At present, the rtx may be either a REG or a SYMBOL_REF, although
153 the support provided depends on the backend. */
154 rtx stack_limit_rtx;
155
156 /* True if the user has tagged the function with the 'section'
157 attribute. */
158
159 bool user_defined_section_attribute = false;
160
161 struct target_flag_state default_target_flag_state;
162 #if SWITCHABLE_TARGET
163 struct target_flag_state *this_target_flag_state = &default_target_flag_state;
164 #else
165 #define this_target_flag_state (&default_target_flag_state)
166 #endif
167
168 /* The user symbol prefix after having resolved same. */
169 const char *user_label_prefix;
170
171 /* Output files for assembler code (real compiler output)
172 and debugging dumps. */
173
174 FILE *asm_out_file;
175 FILE *aux_info_file;
176 FILE *stack_usage_file = NULL;
177 FILE *dump_file = NULL;
178 const char *dump_file_name;
179
180 /* The current working directory of a translation. It's generally the
181 directory from which compilation was initiated, but a preprocessed
182 file may specify the original directory in which it was
183 created. */
184
185 static const char *src_pwd;
186
187 /* Initialize src_pwd with the given string, and return true. If it
188 was already initialized, return false. As a special case, it may
189 be called with a NULL argument to test whether src_pwd has NOT been
190 initialized yet. */
191
192 bool
193 set_src_pwd (const char *pwd)
194 {
195 if (src_pwd)
196 {
197 if (strcmp (src_pwd, pwd) == 0)
198 return true;
199 else
200 return false;
201 }
202
203 src_pwd = xstrdup (pwd);
204 return true;
205 }
206
207 /* Return the directory from which the translation unit was initiated,
208 in case set_src_pwd() was not called before to assign it a
209 different value. */
210
211 const char *
212 get_src_pwd (void)
213 {
214 if (! src_pwd)
215 {
216 src_pwd = getpwd ();
217 if (!src_pwd)
218 src_pwd = ".";
219 }
220
221 return src_pwd;
222 }
223
224 /* Called when the start of a function definition is parsed,
225 this function prints on stderr the name of the function. */
226 void
227 announce_function (tree decl)
228 {
229 if (!quiet_flag)
230 {
231 if (rtl_dump_and_exit)
232 fprintf (stderr, "%s ",
233 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
234 else
235 fprintf (stderr, " %s",
236 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
237 fflush (stderr);
238 pp_needs_newline (global_dc->printer) = true;
239 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
240 }
241 }
242
243 /* Initialize local_tick with a random number or -1 if
244 flag_random_seed is set. */
245
246 static void
247 init_local_tick (void)
248 {
249 if (!flag_random_seed)
250 {
251 /* Try urandom first. Time of day is too likely to collide.
252 In case of any error we just use the local tick. */
253
254 int fd = open ("/dev/urandom", O_RDONLY);
255 if (fd >= 0)
256 {
257 read (fd, &random_seed, sizeof (random_seed));
258 close (fd);
259 }
260
261 /* Now get the tick anyways */
262 #ifdef HAVE_GETTIMEOFDAY
263 {
264 struct timeval tv;
265
266 gettimeofday (&tv, NULL);
267 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
268 }
269 #else
270 {
271 time_t now = time (NULL);
272
273 if (now != (time_t)-1)
274 local_tick = (unsigned) now;
275 }
276 #endif
277 }
278 else
279 local_tick = -1;
280 }
281
282 /* Set up a default flag_random_seed and local_tick, unless the user
283 already specified one. Must be called after init_local_tick. */
284
285 static void
286 init_random_seed (void)
287 {
288 if (flag_random_seed)
289 {
290 char *endp;
291
292 /* When the driver passed in a hex number don't crc it again */
293 random_seed = strtoul (flag_random_seed, &endp, 0);
294 if (!(endp > flag_random_seed && *endp == 0))
295 random_seed = crc32_string (0, flag_random_seed);
296 }
297 else if (!random_seed)
298 random_seed = local_tick ^ getpid (); /* Old racey fallback method */
299 }
300
301 /* Obtain the random_seed. Unless NOINIT, initialize it if
302 it's not provided in the command line. */
303
304 HOST_WIDE_INT
305 get_random_seed (bool noinit)
306 {
307 if (!flag_random_seed && !noinit)
308 init_random_seed ();
309 return random_seed;
310 }
311
312 /* Modify the random_seed string to VAL. Return its previous
313 value. */
314
315 const char *
316 set_random_seed (const char *val)
317 {
318 const char *old = flag_random_seed;
319 flag_random_seed = val;
320 return old;
321 }
322
323 /* Handler for fatal signals, such as SIGSEGV. These are transformed
324 into ICE messages, which is much more user friendly. In case the
325 error printer crashes, reset the signal to prevent infinite recursion. */
326
327 static void
328 crash_signal (int signo)
329 {
330 signal (signo, SIG_DFL);
331
332 /* If we crashed while processing an ASM statement, then be a little more
333 graceful. It's most likely the user's fault. */
334 if (this_is_asm_operands)
335 {
336 output_operand_lossage ("unrecoverable error");
337 exit (FATAL_EXIT_CODE);
338 }
339
340 internal_error ("%s", strsignal (signo));
341 }
342
343 /* A subroutine of wrapup_global_declarations. We've come to the end of
344 the compilation unit. All deferred variables should be undeferred,
345 and all incomplete decls should be finalized. */
346
347 void
348 wrapup_global_declaration_1 (tree decl)
349 {
350 /* We're not deferring this any longer. Assignment is conditional to
351 avoid needlessly dirtying PCH pages. */
352 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
353 && DECL_DEFER_OUTPUT (decl) != 0)
354 DECL_DEFER_OUTPUT (decl) = 0;
355
356 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
357 lang_hooks.finish_incomplete_decl (decl);
358 }
359
360 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
361 needs to be output. Return true if it is output. */
362
363 bool
364 wrapup_global_declaration_2 (tree decl)
365 {
366 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl)
367 || (TREE_CODE (decl) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (decl)))
368 return false;
369
370 /* Don't write out static consts, unless we still need them.
371
372 We also keep static consts if not optimizing (for debugging),
373 unless the user specified -fno-keep-static-consts.
374 ??? They might be better written into the debug information.
375 This is possible when using DWARF.
376
377 A language processor that wants static constants to be always
378 written out (even if it is not used) is responsible for
379 calling rest_of_decl_compilation itself. E.g. the C front-end
380 calls rest_of_decl_compilation from finish_decl.
381 One motivation for this is that is conventional in some
382 environments to write things like:
383 static const char rcsid[] = "... version string ...";
384 intending to force the string to be in the executable.
385
386 A language processor that would prefer to have unneeded
387 static constants "optimized away" would just defer writing
388 them out until here. E.g. C++ does this, because static
389 constants are often defined in header files.
390
391 ??? A tempting alternative (for both C and C++) would be
392 to force a constant to be written if and only if it is
393 defined in a main file, as opposed to an include file. */
394
395 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
396 {
397 struct varpool_node *node;
398 bool needed = true;
399 node = varpool_get_node (decl);
400
401 if (!node && flag_ltrans)
402 needed = false;
403 else if (node && node->finalized)
404 needed = false;
405 else if (node && node->alias)
406 needed = false;
407 else if (!cgraph_global_info_ready
408 && (TREE_USED (decl)
409 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
410 /* needed */;
411 else if (node && node->analyzed)
412 /* needed */;
413 else if (DECL_COMDAT (decl))
414 needed = false;
415 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
416 && (optimize || !flag_keep_static_consts
417 || DECL_ARTIFICIAL (decl)))
418 needed = false;
419
420 if (needed)
421 {
422 rest_of_decl_compilation (decl, 1, 1);
423 return true;
424 }
425 }
426
427 return false;
428 }
429
430 /* Do any final processing required for the declarations in VEC, of
431 which there are LEN. We write out inline functions and variables
432 that have been deferred until this point, but which are required.
433 Returns nonzero if anything was put out. */
434
435 bool
436 wrapup_global_declarations (tree *vec, int len)
437 {
438 bool reconsider, output_something = false;
439 int i;
440
441 for (i = 0; i < len; i++)
442 wrapup_global_declaration_1 (vec[i]);
443
444 /* Now emit any global variables or functions that we have been
445 putting off. We need to loop in case one of the things emitted
446 here references another one which comes earlier in the list. */
447 do
448 {
449 reconsider = false;
450 for (i = 0; i < len; i++)
451 reconsider |= wrapup_global_declaration_2 (vec[i]);
452 if (reconsider)
453 output_something = true;
454 }
455 while (reconsider);
456
457 return output_something;
458 }
459
460 /* A subroutine of check_global_declarations. Issue appropriate warnings
461 for the global declaration DECL. */
462
463 void
464 check_global_declaration_1 (tree decl)
465 {
466 /* Warn about any function declared static but not defined. We don't
467 warn about variables, because many programs have static variables
468 that exist only to get some text into the object file. */
469 if (TREE_CODE (decl) == FUNCTION_DECL
470 && DECL_INITIAL (decl) == 0
471 && DECL_EXTERNAL (decl)
472 && ! DECL_ARTIFICIAL (decl)
473 && ! TREE_NO_WARNING (decl)
474 && ! TREE_PUBLIC (decl)
475 && (warn_unused_function
476 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
477 {
478 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
479 pedwarn (input_location, 0, "%q+F used but never defined", decl);
480 else
481 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
482 /* This symbol is effectively an "extern" declaration now. */
483 TREE_PUBLIC (decl) = 1;
484 }
485
486 /* Warn about static fns or vars defined but not used. */
487 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
488 /* We don't warn about "static const" variables because the
489 "rcs_id" idiom uses that construction. */
490 || (warn_unused_variable
491 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
492 && ! DECL_IN_SYSTEM_HEADER (decl)
493 && ! TREE_USED (decl)
494 /* The TREE_USED bit for file-scope decls is kept in the identifier,
495 to handle multiple external decls in different scopes. */
496 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
497 && ! DECL_EXTERNAL (decl)
498 && ! TREE_PUBLIC (decl)
499 /* A volatile variable might be used in some non-obvious way. */
500 && ! TREE_THIS_VOLATILE (decl)
501 /* Global register variables must be declared to reserve them. */
502 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
503 /* Otherwise, ask the language. */
504 && lang_hooks.decls.warn_unused_global (decl))
505 warning ((TREE_CODE (decl) == FUNCTION_DECL)
506 ? OPT_Wunused_function
507 : OPT_Wunused_variable,
508 "%q+D defined but not used", decl);
509 }
510
511 /* Issue appropriate warnings for the global declarations in VEC (of
512 which there are LEN). */
513
514 void
515 check_global_declarations (tree *vec, int len)
516 {
517 int i;
518
519 for (i = 0; i < len; i++)
520 check_global_declaration_1 (vec[i]);
521 }
522
523 /* Emit debugging information for all global declarations in VEC. */
524
525 void
526 emit_debug_global_declarations (tree *vec, int len)
527 {
528 int i;
529
530 /* Avoid confusing the debug information machinery when there are errors. */
531 if (seen_error ())
532 return;
533
534 timevar_push (TV_SYMOUT);
535 for (i = 0; i < len; i++)
536 debug_hooks->global_decl (vec[i]);
537 timevar_pop (TV_SYMOUT);
538 }
539
540 /* Compile an entire translation unit. Write a file of assembly
541 output and various debugging dumps. */
542
543 static void
544 compile_file (void)
545 {
546 timevar_start (TV_PHASE_PARSING);
547 timevar_push (TV_PARSE_GLOBAL);
548
549 /* Call the parser, which parses the entire file (calling
550 rest_of_compilation for each function). */
551 lang_hooks.parse_file ();
552
553 timevar_pop (TV_PARSE_GLOBAL);
554 timevar_stop (TV_PHASE_PARSING);
555
556 /* Compilation is now finished except for writing
557 what's left of the symbol table output. */
558
559 if (flag_syntax_only || flag_wpa)
560 return;
561
562 timevar_start (TV_PHASE_GENERATE);
563
564 ggc_protect_identifiers = false;
565
566 /* This must also call finalize_compilation_unit. */
567 lang_hooks.decls.final_write_globals ();
568
569 if (seen_error ())
570 {
571 timevar_stop (TV_PHASE_GENERATE);
572 return;
573 }
574
575 /* Compilation unit is finalized. When producing non-fat LTO object, we are
576 basically finished. */
577 if (in_lto_p || !flag_lto || flag_fat_lto_objects)
578 {
579 /* Likewise for mudflap static object registrations. */
580 if (flag_mudflap)
581 mudflap_finish_file ();
582
583 output_shared_constant_pool ();
584 output_object_blocks ();
585 finish_tm_clone_pairs ();
586
587 /* Write out any pending weak symbol declarations. */
588 weak_finish ();
589
590 /* This must be at the end before unwind and debug info.
591 Some target ports emit PIC setup thunks here. */
592 targetm.asm_out.code_end ();
593
594 /* Do dbx symbols. */
595 timevar_push (TV_SYMOUT);
596
597 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
598 if (dwarf2out_do_frame ())
599 dwarf2out_frame_finish ();
600 #endif
601
602 (*debug_hooks->finish) (main_input_filename);
603 timevar_pop (TV_SYMOUT);
604
605 /* Output some stuff at end of file if nec. */
606
607 dw2_output_indirect_constants ();
608
609 /* Flush any pending external directives. */
610 process_pending_assemble_externals ();
611 }
612
613 /* Emit LTO marker if LTO info has been previously emitted. This is
614 used by collect2 to determine whether an object file contains IL.
615 We used to emit an undefined reference here, but this produces
616 link errors if an object file with IL is stored into a shared
617 library without invoking lto1. */
618 if (flag_generate_lto)
619 {
620 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
621 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
622 "__gnu_lto_v1",
623 (unsigned HOST_WIDE_INT) 1, 8);
624 #elif defined ASM_OUTPUT_ALIGNED_COMMON
625 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1",
626 (unsigned HOST_WIDE_INT) 1, 8);
627 #else
628 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1",
629 (unsigned HOST_WIDE_INT) 1,
630 (unsigned HOST_WIDE_INT) 1);
631 #endif
632 /* Let linker plugin know that this is a slim object and must be LTOed
633 even when user did not ask for it. */
634 if (!flag_fat_lto_objects)
635 {
636 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
637 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
638 "__gnu_lto_slim",
639 (unsigned HOST_WIDE_INT) 1, 8);
640 #elif defined ASM_OUTPUT_ALIGNED_COMMON
641 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_slim",
642 (unsigned HOST_WIDE_INT) 1, 8);
643 #else
644 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_slim",
645 (unsigned HOST_WIDE_INT) 1,
646 (unsigned HOST_WIDE_INT) 1);
647 #endif
648 }
649 }
650
651 /* Attach a special .ident directive to the end of the file to identify
652 the version of GCC which compiled this code. The format of the .ident
653 string is patterned after the ones produced by native SVR4 compilers. */
654 #ifdef IDENT_ASM_OP
655 if (!flag_no_ident)
656 {
657 const char *pkg_version = "(GNU) ";
658
659 if (strcmp ("(GCC) ", pkgversion_string))
660 pkg_version = pkgversion_string;
661 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
662 IDENT_ASM_OP, pkg_version, version_string);
663 }
664 #endif
665
666 /* Invoke registered plugin callbacks. */
667 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
668
669 /* This must be at the end. Some target ports emit end of file directives
670 into the assembly file here, and hence we can not output anything to the
671 assembly file after this point. */
672 targetm.asm_out.file_end ();
673
674 timevar_stop (TV_PHASE_GENERATE);
675 }
676
677 /* Print version information to FILE.
678 Each line begins with INDENT (for the case where FILE is the
679 assembler output file). */
680
681 void
682 print_version (FILE *file, const char *indent)
683 {
684 static const char fmt1[] =
685 #ifdef __GNUC__
686 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
687 #else
688 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
689 #endif
690 ;
691 static const char fmt2[] =
692 N_("GMP version %s, MPFR version %s, MPC version %s\n");
693 static const char fmt3[] =
694 N_("%s%swarning: %s header version %s differs from library version %s.\n");
695 static const char fmt4[] =
696 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
697 #ifndef __VERSION__
698 #define __VERSION__ "[?]"
699 #endif
700 fprintf (file,
701 file == stderr ? _(fmt1) : fmt1,
702 indent, *indent != 0 ? " " : "",
703 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
704 indent, __VERSION__);
705
706 /* We need to stringify the GMP macro values. Ugh, gmp_version has
707 two string formats, "i.j.k" and "i.j" when k is zero. As of
708 gmp-4.3.0, GMP always uses the 3 number format. */
709 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
710 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
711 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
712 #define GCC_GMP_VERSION \
713 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
714 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
715 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
716 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
717 #else
718 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
719 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
720 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
721 #endif
722 fprintf (file,
723 file == stderr ? _(fmt2) : fmt2,
724 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING);
725 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
726 fprintf (file,
727 file == stderr ? _(fmt3) : fmt3,
728 indent, *indent != 0 ? " " : "",
729 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
730 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
731 fprintf (file,
732 file == stderr ? _(fmt3) : fmt3,
733 indent, *indent != 0 ? " " : "",
734 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
735 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
736 fprintf (file,
737 file == stderr ? _(fmt3) : fmt3,
738 indent, *indent != 0 ? " " : "",
739 "MPC", MPC_VERSION_STRING, mpc_get_version ());
740 fprintf (file,
741 file == stderr ? _(fmt4) : fmt4,
742 indent, *indent != 0 ? " " : "",
743 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
744
745 print_plugins_versions (file, indent);
746 }
747
748 static int
749 print_to_asm_out_file (print_switch_type type, const char * text)
750 {
751 bool prepend_sep = true;
752
753 switch (type)
754 {
755 case SWITCH_TYPE_LINE_END:
756 putc ('\n', asm_out_file);
757 return 1;
758
759 case SWITCH_TYPE_LINE_START:
760 fputs (ASM_COMMENT_START, asm_out_file);
761 return strlen (ASM_COMMENT_START);
762
763 case SWITCH_TYPE_DESCRIPTIVE:
764 if (ASM_COMMENT_START[0] == 0)
765 prepend_sep = false;
766 /* Drop through. */
767 case SWITCH_TYPE_PASSED:
768 case SWITCH_TYPE_ENABLED:
769 if (prepend_sep)
770 fputc (' ', asm_out_file);
771 fputs (text, asm_out_file);
772 /* No need to return the length here as
773 print_single_switch has already done it. */
774 return 0;
775
776 default:
777 return -1;
778 }
779 }
780
781 static int
782 print_to_stderr (print_switch_type type, const char * text)
783 {
784 switch (type)
785 {
786 case SWITCH_TYPE_LINE_END:
787 putc ('\n', stderr);
788 return 1;
789
790 case SWITCH_TYPE_LINE_START:
791 return 0;
792
793 case SWITCH_TYPE_PASSED:
794 case SWITCH_TYPE_ENABLED:
795 fputc (' ', stderr);
796 /* Drop through. */
797
798 case SWITCH_TYPE_DESCRIPTIVE:
799 fputs (text, stderr);
800 /* No need to return the length here as
801 print_single_switch has already done it. */
802 return 0;
803
804 default:
805 return -1;
806 }
807 }
808
809 /* Print an option value and return the adjusted position in the line.
810 ??? print_fn doesn't handle errors, eg disk full; presumably other
811 code will catch a disk full though. */
812
813 static int
814 print_single_switch (print_switch_fn_type print_fn,
815 int pos,
816 print_switch_type type,
817 const char * text)
818 {
819 /* The ultrix fprintf returns 0 on success, so compute the result
820 we want here since we need it for the following test. The +1
821 is for the separator character that will probably be emitted. */
822 int len = strlen (text) + 1;
823
824 if (pos != 0
825 && pos + len > MAX_LINE)
826 {
827 print_fn (SWITCH_TYPE_LINE_END, NULL);
828 pos = 0;
829 }
830
831 if (pos == 0)
832 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
833
834 print_fn (type, text);
835 return pos + len;
836 }
837
838 /* Print active target switches using PRINT_FN.
839 POS is the current cursor position and MAX is the size of a "line".
840 Each line begins with INDENT and ends with TERM.
841 Each switch is separated from the next by SEP. */
842
843 static void
844 print_switch_values (print_switch_fn_type print_fn)
845 {
846 int pos = 0;
847 size_t j;
848
849 /* Fill in the -frandom-seed option, if the user didn't pass it, so
850 that it can be printed below. This helps reproducibility. */
851 if (!flag_random_seed)
852 init_random_seed ();
853
854 /* Print the options as passed. */
855 pos = print_single_switch (print_fn, pos,
856 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
857
858 for (j = 1; j < save_decoded_options_count; j++)
859 {
860 switch (save_decoded_options[j].opt_index)
861 {
862 case OPT_o:
863 case OPT_d:
864 case OPT_dumpbase:
865 case OPT_dumpdir:
866 case OPT_auxbase:
867 case OPT_quiet:
868 case OPT_version:
869 /* Ignore these. */
870 continue;
871 }
872
873 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED,
874 save_decoded_options[j].orig_option_with_args_text);
875 }
876
877 if (pos > 0)
878 print_fn (SWITCH_TYPE_LINE_END, NULL);
879
880 /* Print the -f and -m options that have been enabled.
881 We don't handle language specific options but printing argv
882 should suffice. */
883 pos = print_single_switch (print_fn, 0,
884 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
885
886 for (j = 0; j < cl_options_count; j++)
887 if (cl_options[j].cl_report
888 && option_enabled (j, &global_options) > 0)
889 pos = print_single_switch (print_fn, pos,
890 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
891
892 print_fn (SWITCH_TYPE_LINE_END, NULL);
893 }
894
895 /* Open assembly code output file. Do this even if -fsyntax-only is
896 on, because then the driver will have provided the name of a
897 temporary file or bit bucket for us. NAME is the file specified on
898 the command line, possibly NULL. */
899 static void
900 init_asm_output (const char *name)
901 {
902 if (name == NULL && asm_file_name == 0)
903 asm_out_file = stdout;
904 else
905 {
906 if (asm_file_name == 0)
907 {
908 int len = strlen (dump_base_name);
909 char *dumpname = XNEWVEC (char, len + 6);
910
911 memcpy (dumpname, dump_base_name, len + 1);
912 strip_off_ending (dumpname, len);
913 strcat (dumpname, ".s");
914 asm_file_name = dumpname;
915 }
916 if (!strcmp (asm_file_name, "-"))
917 asm_out_file = stdout;
918 else
919 asm_out_file = fopen (asm_file_name, "w+b");
920 if (asm_out_file == 0)
921 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
922 }
923
924 if (!flag_syntax_only)
925 {
926 targetm.asm_out.file_start ();
927
928 if (flag_record_gcc_switches)
929 {
930 if (targetm.asm_out.record_gcc_switches)
931 {
932 /* Let the target know that we are about to start recording. */
933 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
934 NULL);
935 /* Now record the switches. */
936 print_switch_values (targetm.asm_out.record_gcc_switches);
937 /* Let the target know that the recording is over. */
938 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
939 NULL);
940 }
941 else
942 inform (input_location, "-frecord-gcc-switches is not supported by the current target");
943 }
944
945 if (flag_verbose_asm)
946 {
947 /* Print the list of switches in effect
948 into the assembler file as comments. */
949 print_version (asm_out_file, ASM_COMMENT_START);
950 print_switch_values (print_to_asm_out_file);
951 putc ('\n', asm_out_file);
952 }
953 }
954 }
955
956 /* A helper function; used as the reallocator function for cpp's line
957 table. */
958 static void *
959 realloc_for_line_map (void *ptr, size_t len)
960 {
961 return GGC_RESIZEVAR (void, ptr, len);
962 }
963
964 /* A helper function: used as the allocator function for
965 identifier_to_locale. */
966 static void *
967 alloc_for_identifier_to_locale (size_t len)
968 {
969 return ggc_alloc_atomic (len);
970 }
971
972 /* Output stack usage information. */
973 void
974 output_stack_usage (void)
975 {
976 static bool warning_issued = false;
977 enum stack_usage_kind_type { STATIC = 0, DYNAMIC, DYNAMIC_BOUNDED };
978 const char *stack_usage_kind_str[] = {
979 "static",
980 "dynamic",
981 "dynamic,bounded"
982 };
983 HOST_WIDE_INT stack_usage = current_function_static_stack_size;
984 enum stack_usage_kind_type stack_usage_kind;
985
986 if (stack_usage < 0)
987 {
988 if (!warning_issued)
989 {
990 warning (0, "stack usage computation not supported for this target");
991 warning_issued = true;
992 }
993 return;
994 }
995
996 stack_usage_kind = STATIC;
997
998 /* Add the maximum amount of space pushed onto the stack. */
999 if (current_function_pushed_stack_size > 0)
1000 {
1001 stack_usage += current_function_pushed_stack_size;
1002 stack_usage_kind = DYNAMIC_BOUNDED;
1003 }
1004
1005 /* Now on to the tricky part: dynamic stack allocation. */
1006 if (current_function_allocates_dynamic_stack_space)
1007 {
1008 if (current_function_has_unbounded_dynamic_stack_size)
1009 stack_usage_kind = DYNAMIC;
1010 else
1011 stack_usage_kind = DYNAMIC_BOUNDED;
1012
1013 /* Add the size even in the unbounded case, this can't hurt. */
1014 stack_usage += current_function_dynamic_stack_size;
1015 }
1016
1017 if (flag_stack_usage)
1018 {
1019 expanded_location loc
1020 = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
1021 const char *raw_id, *id;
1022
1023 /* Strip the scope prefix if any. */
1024 raw_id = lang_hooks.decl_printable_name (current_function_decl, 2);
1025 id = strrchr (raw_id, '.');
1026 if (id)
1027 id++;
1028 else
1029 id = raw_id;
1030
1031 fprintf (stack_usage_file,
1032 "%s:%d:%d:%s\t"HOST_WIDE_INT_PRINT_DEC"\t%s\n",
1033 lbasename (loc.file),
1034 loc.line,
1035 loc.column,
1036 id,
1037 stack_usage,
1038 stack_usage_kind_str[stack_usage_kind]);
1039 }
1040
1041 if (warn_stack_usage >= 0)
1042 {
1043 if (stack_usage_kind == DYNAMIC)
1044 warning (OPT_Wstack_usage_, "stack usage might be unbounded");
1045 else if (stack_usage > warn_stack_usage)
1046 {
1047 if (stack_usage_kind == DYNAMIC_BOUNDED)
1048 warning (OPT_Wstack_usage_, "stack usage might be %wd bytes",
1049 stack_usage);
1050 else
1051 warning (OPT_Wstack_usage_, "stack usage is %wd bytes",
1052 stack_usage);
1053 }
1054 }
1055 }
1056
1057 /* Open an auxiliary output file. */
1058 static FILE *
1059 open_auxiliary_file (const char *ext)
1060 {
1061 char *filename;
1062 FILE *file;
1063
1064 filename = concat (aux_base_name, ".", ext, NULL);
1065 file = fopen (filename, "w");
1066 if (!file)
1067 fatal_error ("can%'t open %s for writing: %m", filename);
1068 free (filename);
1069 return file;
1070 }
1071
1072 /* Initialization of the front end environment, before command line
1073 options are parsed. Signal handlers, internationalization etc.
1074 ARGV0 is main's argv[0]. */
1075 static void
1076 general_init (const char *argv0)
1077 {
1078 const char *p;
1079
1080 p = argv0 + strlen (argv0);
1081 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1082 --p;
1083 progname = p;
1084
1085 xmalloc_set_program_name (progname);
1086
1087 hex_init ();
1088
1089 /* Unlock the stdio streams. */
1090 unlock_std_streams ();
1091
1092 gcc_init_libintl ();
1093
1094 identifier_to_locale_alloc = alloc_for_identifier_to_locale;
1095 identifier_to_locale_free = ggc_free;
1096
1097 /* Initialize the diagnostics reporting machinery, so option parsing
1098 can give warnings and errors. */
1099 diagnostic_initialize (global_dc, N_OPTS);
1100 /* Set a default printer. Language specific initializations will
1101 override it later. */
1102 tree_diagnostics_defaults (global_dc);
1103 /* FIXME: This should probably be moved to C-family
1104 language-specific initializations. */
1105 /* By default print macro expansion contexts in the diagnostic
1106 finalizer -- for tokens resulting from macro expansion. */
1107 diagnostic_finalizer (global_dc) = virt_loc_aware_diagnostic_finalizer;
1108
1109 global_dc->show_caret
1110 = global_options_init.x_flag_diagnostics_show_caret;
1111 global_dc->show_option_requested
1112 = global_options_init.x_flag_diagnostics_show_option;
1113 global_dc->show_column
1114 = global_options_init.x_flag_show_column;
1115 global_dc->internal_error = plugins_internal_error_function;
1116 global_dc->option_enabled = option_enabled;
1117 global_dc->option_state = &global_options;
1118 global_dc->option_name = option_name;
1119
1120 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1121 #ifdef SIGSEGV
1122 signal (SIGSEGV, crash_signal);
1123 #endif
1124 #ifdef SIGILL
1125 signal (SIGILL, crash_signal);
1126 #endif
1127 #ifdef SIGBUS
1128 signal (SIGBUS, crash_signal);
1129 #endif
1130 #ifdef SIGABRT
1131 signal (SIGABRT, crash_signal);
1132 #endif
1133 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1134 signal (SIGIOT, crash_signal);
1135 #endif
1136 #ifdef SIGFPE
1137 signal (SIGFPE, crash_signal);
1138 #endif
1139
1140 /* Other host-specific signal setup. */
1141 (*host_hooks.extra_signals)();
1142
1143 /* Initialize the garbage-collector, string pools and tree type hash
1144 table. */
1145 init_ggc ();
1146 init_stringpool ();
1147 line_table = ggc_alloc_line_maps ();
1148 linemap_init (line_table);
1149 line_table->reallocator = realloc_for_line_map;
1150 line_table->round_alloc_size = ggc_round_alloc_size;
1151 init_ttree ();
1152
1153 /* Initialize register usage now so switches may override. */
1154 init_reg_sets ();
1155
1156 /* Register the language-independent parameters. */
1157 global_init_params ();
1158
1159 /* This must be done after global_init_params but before argument
1160 processing. */
1161 init_ggc_heuristics();
1162 init_optimization_passes ();
1163 statistics_early_init ();
1164 finish_params ();
1165 }
1166
1167 /* Return true if the current target supports -fsection-anchors. */
1168
1169 static bool
1170 target_supports_section_anchors_p (void)
1171 {
1172 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1173 return false;
1174
1175 if (targetm.asm_out.output_anchor == NULL)
1176 return false;
1177
1178 return true;
1179 }
1180
1181 /* Default the align_* variables to 1 if they're still unset, and
1182 set up the align_*_log variables. */
1183 static void
1184 init_alignments (void)
1185 {
1186 if (align_loops <= 0)
1187 align_loops = 1;
1188 if (align_loops_max_skip > align_loops)
1189 align_loops_max_skip = align_loops - 1;
1190 align_loops_log = floor_log2 (align_loops * 2 - 1);
1191 if (align_jumps <= 0)
1192 align_jumps = 1;
1193 if (align_jumps_max_skip > align_jumps)
1194 align_jumps_max_skip = align_jumps - 1;
1195 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1196 if (align_labels <= 0)
1197 align_labels = 1;
1198 align_labels_log = floor_log2 (align_labels * 2 - 1);
1199 if (align_labels_max_skip > align_labels)
1200 align_labels_max_skip = align_labels - 1;
1201 if (align_functions <= 0)
1202 align_functions = 1;
1203 align_functions_log = floor_log2 (align_functions * 2 - 1);
1204 }
1205
1206 /* Process the options that have been parsed. */
1207 static void
1208 process_options (void)
1209 {
1210 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1211 This can happen with incorrect pre-processed input. */
1212 debug_hooks = &do_nothing_debug_hooks;
1213
1214 maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
1215
1216 /* Allow the front end to perform consistency checks and do further
1217 initialization based on the command line options. This hook also
1218 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1219 so we can correctly initialize debug output. */
1220 no_backend = lang_hooks.post_options (&main_input_filename);
1221
1222 /* Some machines may reject certain combinations of options. */
1223 targetm.target_option.override ();
1224
1225 /* Avoid any informative notes in the second run of -fcompare-debug. */
1226 if (flag_compare_debug)
1227 diagnostic_inhibit_notes (global_dc);
1228
1229 if (flag_section_anchors && !target_supports_section_anchors_p ())
1230 {
1231 warning (OPT_fsection_anchors,
1232 "this target does not support %qs", "-fsection-anchors");
1233 flag_section_anchors = 0;
1234 }
1235
1236 if (flag_short_enums == 2)
1237 flag_short_enums = targetm.default_short_enums ();
1238
1239 /* Set aux_base_name if not already set. */
1240 if (aux_base_name)
1241 ;
1242 else if (main_input_filename)
1243 {
1244 char *name = xstrdup (lbasename (main_input_filename));
1245
1246 strip_off_ending (name, strlen (name));
1247 aux_base_name = name;
1248 }
1249 else
1250 aux_base_name = "gccaux";
1251
1252 #ifndef HAVE_cloog
1253 if (flag_graphite
1254 || flag_graphite_identity
1255 || flag_loop_block
1256 || flag_loop_interchange
1257 || flag_loop_strip_mine
1258 || flag_loop_parallelize_all)
1259 sorry ("Graphite loop optimizations cannot be used (-fgraphite, "
1260 "-fgraphite-identity, -floop-block, "
1261 "-floop-interchange, -floop-strip-mine, -floop-parallelize-all, "
1262 "and -ftree-loop-linear)");
1263 #endif
1264
1265 if (flag_mudflap && flag_lto)
1266 sorry ("mudflap cannot be used together with link-time optimization");
1267
1268 /* One region RA really helps to decrease the code size. */
1269 if (flag_ira_region == IRA_REGION_AUTODETECT)
1270 flag_ira_region
1271 = optimize_size || !optimize ? IRA_REGION_ONE : IRA_REGION_MIXED;
1272
1273 if (flag_strict_volatile_bitfields > 0 && !abi_version_at_least (2))
1274 {
1275 warning (0, "-fstrict-volatile-bitfields disabled; "
1276 "it is incompatible with ABI versions < 2");
1277 flag_strict_volatile_bitfields = 0;
1278 }
1279
1280 /* Unrolling all loops implies that standard loop unrolling must also
1281 be done. */
1282 if (flag_unroll_all_loops)
1283 flag_unroll_loops = 1;
1284
1285 /* web and rename-registers help when run after loop unrolling. */
1286 if (flag_web == AUTODETECT_VALUE)
1287 flag_web = flag_unroll_loops || flag_peel_loops;
1288
1289 if (flag_rename_registers == AUTODETECT_VALUE)
1290 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1291
1292 if (flag_non_call_exceptions)
1293 flag_asynchronous_unwind_tables = 1;
1294 if (flag_asynchronous_unwind_tables)
1295 flag_unwind_tables = 1;
1296
1297 if (flag_value_profile_transformations)
1298 flag_profile_values = 1;
1299
1300 /* Warn about options that are not supported on this machine. */
1301 #ifndef INSN_SCHEDULING
1302 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1303 warning (0, "instruction scheduling not supported on this target machine");
1304 #endif
1305 #ifndef DELAY_SLOTS
1306 if (flag_delayed_branch)
1307 warning (0, "this target machine does not have delayed branches");
1308 #endif
1309
1310 user_label_prefix = USER_LABEL_PREFIX;
1311 if (flag_leading_underscore != -1)
1312 {
1313 /* If the default prefix is more complicated than "" or "_",
1314 issue a warning and ignore this option. */
1315 if (user_label_prefix[0] == 0 ||
1316 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1317 {
1318 user_label_prefix = flag_leading_underscore ? "_" : "";
1319 }
1320 else
1321 warning (0, "-f%sleading-underscore not supported on this target machine",
1322 flag_leading_underscore ? "" : "no-");
1323 }
1324
1325 /* If we are in verbose mode, write out the version and maybe all the
1326 option flags in use. */
1327 if (version_flag)
1328 {
1329 print_version (stderr, "");
1330 if (! quiet_flag)
1331 print_switch_values (print_to_stderr);
1332 }
1333
1334 if (flag_syntax_only)
1335 {
1336 write_symbols = NO_DEBUG;
1337 profile_flag = 0;
1338 }
1339
1340 if (flag_gtoggle)
1341 {
1342 if (debug_info_level == DINFO_LEVEL_NONE)
1343 {
1344 debug_info_level = DINFO_LEVEL_NORMAL;
1345
1346 if (write_symbols == NO_DEBUG)
1347 write_symbols = PREFERRED_DEBUGGING_TYPE;
1348 }
1349 else
1350 debug_info_level = DINFO_LEVEL_NONE;
1351 }
1352
1353 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1354 {
1355 FILE *final_output = fopen (flag_dump_final_insns, "w");
1356 if (!final_output)
1357 {
1358 error ("could not open final insn dump file %qs: %m",
1359 flag_dump_final_insns);
1360 flag_dump_final_insns = NULL;
1361 }
1362 else if (fclose (final_output))
1363 {
1364 error ("could not close zeroed insn dump file %qs: %m",
1365 flag_dump_final_insns);
1366 flag_dump_final_insns = NULL;
1367 }
1368 }
1369
1370 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1371 level is 0. */
1372 if (debug_info_level == DINFO_LEVEL_NONE)
1373 write_symbols = NO_DEBUG;
1374
1375 if (write_symbols == NO_DEBUG)
1376 ;
1377 #if defined(DBX_DEBUGGING_INFO)
1378 else if (write_symbols == DBX_DEBUG)
1379 debug_hooks = &dbx_debug_hooks;
1380 #endif
1381 #if defined(XCOFF_DEBUGGING_INFO)
1382 else if (write_symbols == XCOFF_DEBUG)
1383 debug_hooks = &xcoff_debug_hooks;
1384 #endif
1385 #ifdef SDB_DEBUGGING_INFO
1386 else if (write_symbols == SDB_DEBUG)
1387 debug_hooks = &sdb_debug_hooks;
1388 #endif
1389 #ifdef DWARF2_DEBUGGING_INFO
1390 else if (write_symbols == DWARF2_DEBUG)
1391 debug_hooks = &dwarf2_debug_hooks;
1392 #endif
1393 #ifdef VMS_DEBUGGING_INFO
1394 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1395 debug_hooks = &vmsdbg_debug_hooks;
1396 #endif
1397 else
1398 error ("target system does not support the \"%s\" debug format",
1399 debug_type_names[write_symbols]);
1400
1401 /* We know which debug output will be used so we can set flag_var_tracking
1402 and flag_var_tracking_uninit if the user has not specified them. */
1403 if (debug_info_level < DINFO_LEVEL_NORMAL
1404 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1405 {
1406 if (flag_var_tracking == 1
1407 || flag_var_tracking_uninit == 1)
1408 {
1409 if (debug_info_level < DINFO_LEVEL_NORMAL)
1410 warning (0, "variable tracking requested, but useless unless "
1411 "producing debug info");
1412 else
1413 warning (0, "variable tracking requested, but not supported "
1414 "by this debug format");
1415 }
1416 flag_var_tracking = 0;
1417 flag_var_tracking_uninit = 0;
1418 }
1419
1420 /* The debug hooks are used to implement -fdump-go-spec because it
1421 gives a simple and stable API for all the information we need to
1422 dump. */
1423 if (flag_dump_go_spec != NULL)
1424 debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
1425
1426 /* If the user specifically requested variable tracking with tagging
1427 uninitialized variables, we need to turn on variable tracking.
1428 (We already determined above that variable tracking is feasible.) */
1429 if (flag_var_tracking_uninit)
1430 flag_var_tracking = 1;
1431
1432 if (flag_var_tracking == AUTODETECT_VALUE)
1433 flag_var_tracking = optimize >= 1;
1434
1435 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
1436 flag_var_tracking_assignments = flag_var_tracking
1437 && !(flag_selective_scheduling || flag_selective_scheduling2);
1438
1439 if (flag_var_tracking_assignments_toggle)
1440 flag_var_tracking_assignments = !flag_var_tracking_assignments;
1441
1442 if (flag_var_tracking_assignments && !flag_var_tracking)
1443 flag_var_tracking = flag_var_tracking_assignments = -1;
1444
1445 if (flag_var_tracking_assignments
1446 && (flag_selective_scheduling || flag_selective_scheduling2))
1447 warning (0, "var-tracking-assignments changes selective scheduling");
1448
1449 if (flag_tree_cselim == AUTODETECT_VALUE)
1450 #ifdef HAVE_conditional_move
1451 flag_tree_cselim = 1;
1452 #else
1453 flag_tree_cselim = 0;
1454 #endif
1455
1456 /* If auxiliary info generation is desired, open the output file.
1457 This goes in the same directory as the source file--unlike
1458 all the other output files. */
1459 if (flag_gen_aux_info)
1460 {
1461 aux_info_file = fopen (aux_info_file_name, "w");
1462 if (aux_info_file == 0)
1463 fatal_error ("can%'t open %s: %m", aux_info_file_name);
1464 }
1465
1466 if (!targetm_common.have_named_sections)
1467 {
1468 if (flag_function_sections)
1469 {
1470 warning (0, "-ffunction-sections not supported for this target");
1471 flag_function_sections = 0;
1472 }
1473 if (flag_data_sections)
1474 {
1475 warning (0, "-fdata-sections not supported for this target");
1476 flag_data_sections = 0;
1477 }
1478 }
1479
1480 if (flag_function_sections && profile_flag)
1481 {
1482 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
1483 flag_function_sections = 0;
1484 }
1485
1486 #ifndef HAVE_prefetch
1487 if (flag_prefetch_loop_arrays > 0)
1488 {
1489 warning (0, "-fprefetch-loop-arrays not supported for this target");
1490 flag_prefetch_loop_arrays = 0;
1491 }
1492 #else
1493 if (flag_prefetch_loop_arrays > 0 && !HAVE_prefetch)
1494 {
1495 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
1496 flag_prefetch_loop_arrays = 0;
1497 }
1498 #endif
1499
1500 /* This combination of options isn't handled for i386 targets and doesn't
1501 make much sense anyway, so don't allow it. */
1502 if (flag_prefetch_loop_arrays > 0 && optimize_size)
1503 {
1504 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
1505 flag_prefetch_loop_arrays = 0;
1506 }
1507
1508 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1509 if (flag_signaling_nans)
1510 flag_trapping_math = 1;
1511
1512 /* We cannot reassociate if we want traps or signed zeros. */
1513 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1514 {
1515 warning (0, "-fassociative-math disabled; other options take precedence");
1516 flag_associative_math = 0;
1517 }
1518
1519 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1520 if (flag_cx_limited_range)
1521 flag_complex_method = 0;
1522
1523 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1524 if (flag_cx_fortran_rules)
1525 flag_complex_method = 1;
1526
1527 /* Targets must be able to place spill slots at lower addresses. If the
1528 target already uses a soft frame pointer, the transition is trivial. */
1529 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1530 {
1531 warning (0, "-fstack-protector not supported for this target");
1532 flag_stack_protect = 0;
1533 }
1534 if (!flag_stack_protect)
1535 warn_stack_protect = 0;
1536
1537 /* ??? Unwind info is not correct around the CFG unless either a frame
1538 pointer is present or A_O_A is set. Fixing this requires rewriting
1539 unwind info generation to be aware of the CFG and propagating states
1540 around edges. */
1541 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
1542 && flag_omit_frame_pointer)
1543 {
1544 warning (0, "unwind tables currently require a frame pointer "
1545 "for correctness");
1546 flag_omit_frame_pointer = 0;
1547 }
1548
1549 /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
1550 have not been set. */
1551 if (!global_options_set.x_warnings_are_errors
1552 && warn_coverage_mismatch
1553 && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
1554 DK_UNSPECIFIED))
1555 diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
1556 DK_ERROR, UNKNOWN_LOCATION);
1557
1558 /* Save the current optimization options. */
1559 optimization_default_node = build_optimization_node ();
1560 optimization_current_node = optimization_default_node;
1561 }
1562
1563 /* This function can be called multiple times to reinitialize the compiler
1564 back end when register classes or instruction sets have changed,
1565 before each function. */
1566 static void
1567 backend_init_target (void)
1568 {
1569 /* Initialize alignment variables. */
1570 init_alignments ();
1571
1572 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
1573 to initialize reg_raw_mode[]. */
1574 init_emit_regs ();
1575
1576 /* This invokes target hooks to set fixed_reg[] etc, which is
1577 mode-dependent. */
1578 init_regs ();
1579
1580 /* This depends on stack_pointer_rtx. */
1581 init_fake_stack_mems ();
1582
1583 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1584 mode-dependent. */
1585 init_alias_target ();
1586
1587 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1588 init_reload ();
1589
1590 /* The following initialization functions need to generate rtl, so
1591 provide a dummy function context for them. */
1592 init_dummy_function_start ();
1593
1594 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1595 on a mode change. */
1596 init_expmed ();
1597 init_lower_subreg ();
1598
1599 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1600 after a mode change as well. */
1601 caller_save_initialized_p = false;
1602
1603 expand_dummy_function_end ();
1604 }
1605
1606 /* Initialize the compiler back end. This function is called only once,
1607 when starting the compiler. */
1608 static void
1609 backend_init (void)
1610 {
1611 init_emit_once ();
1612
1613 init_rtlanal ();
1614 init_inline_once ();
1615 init_varasm_once ();
1616 save_register_info ();
1617
1618 /* Initialize the target-specific back end pieces. */
1619 ira_init_once ();
1620 backend_init_target ();
1621 }
1622
1623 /* Initialize excess precision settings. */
1624 static void
1625 init_excess_precision (void)
1626 {
1627 /* Adjust excess precision handling based on the target options. If
1628 the front end cannot handle it, flag_excess_precision_cmdline
1629 will already have been set accordingly in the post_options
1630 hook. */
1631 gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
1632 flag_excess_precision = flag_excess_precision_cmdline;
1633 if (flag_unsafe_math_optimizations)
1634 flag_excess_precision = EXCESS_PRECISION_FAST;
1635 if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
1636 {
1637 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
1638 switch (flt_eval_method)
1639 {
1640 case -1:
1641 case 0:
1642 /* Either the target acts unpredictably (-1) or has all the
1643 operations required not to have excess precision (0). */
1644 flag_excess_precision = EXCESS_PRECISION_FAST;
1645 break;
1646 case 1:
1647 case 2:
1648 /* In these cases, predictable excess precision makes
1649 sense. */
1650 break;
1651 default:
1652 /* Any other implementation-defined FLT_EVAL_METHOD values
1653 require the compiler to handle the associated excess
1654 precision rules in excess_precision_type. */
1655 gcc_unreachable ();
1656 }
1657 }
1658 }
1659
1660 /* Initialize things that are both lang-dependent and target-dependent.
1661 This function can be called more than once if target parameters change. */
1662 static void
1663 lang_dependent_init_target (void)
1664 {
1665 /* This determines excess precision settings. */
1666 init_excess_precision ();
1667
1668 /* This creates various _DECL nodes, so needs to be called after the
1669 front end is initialized. It also depends on the HAVE_xxx macros
1670 generated from the target machine description. */
1671 init_optabs ();
1672
1673 /* The following initialization functions need to generate rtl, so
1674 provide a dummy function context for them. */
1675 init_dummy_function_start ();
1676
1677 /* Do the target-specific parts of expr initialization. */
1678 init_expr_target ();
1679
1680 /* Although the actions of these functions are language-independent,
1681 they use optabs, so we cannot call them from backend_init. */
1682 init_set_costs ();
1683 ira_init ();
1684
1685 expand_dummy_function_end ();
1686 }
1687
1688 /* Language-dependent initialization. Returns nonzero on success. */
1689 static int
1690 lang_dependent_init (const char *name)
1691 {
1692 location_t save_loc = input_location;
1693 if (dump_base_name == 0)
1694 dump_base_name = name && name[0] ? name : "gccdump";
1695
1696 /* Other front-end initialization. */
1697 input_location = BUILTINS_LOCATION;
1698 if (lang_hooks.init () == 0)
1699 return 0;
1700 input_location = save_loc;
1701
1702 if (!flag_wpa)
1703 {
1704 init_asm_output (name);
1705
1706 /* If stack usage information is desired, open the output file. */
1707 if (flag_stack_usage)
1708 stack_usage_file = open_auxiliary_file ("su");
1709 }
1710
1711 /* This creates various _DECL nodes, so needs to be called after the
1712 front end is initialized. */
1713 init_eh ();
1714
1715 /* Do the target-specific parts of the initialization. */
1716 lang_dependent_init_target ();
1717
1718 if (!flag_wpa)
1719 {
1720 /* If dbx symbol table desired, initialize writing it and output the
1721 predefined types. */
1722 timevar_push (TV_SYMOUT);
1723
1724 /* Now we have the correct original filename, we can initialize
1725 debug output. */
1726 (*debug_hooks->init) (name);
1727
1728 timevar_pop (TV_SYMOUT);
1729 }
1730
1731 return 1;
1732 }
1733
1734
1735 /* Reinitialize everything when target parameters, such as register usage,
1736 have changed. */
1737 void
1738 target_reinit (void)
1739 {
1740 struct rtl_data saved_x_rtl;
1741 rtx *saved_regno_reg_rtx;
1742
1743 /* Save *crtl and regno_reg_rtx around the reinitialization
1744 to allow target_reinit being called even after prepare_function_start. */
1745 saved_regno_reg_rtx = regno_reg_rtx;
1746 if (saved_regno_reg_rtx)
1747 {
1748 saved_x_rtl = *crtl;
1749 memset (crtl, '\0', sizeof (*crtl));
1750 regno_reg_rtx = NULL;
1751 }
1752
1753 /* Reinitialize RTL backend. */
1754 backend_init_target ();
1755
1756 /* Reinitialize lang-dependent parts. */
1757 lang_dependent_init_target ();
1758
1759 /* And restore it at the end, as free_after_compilation from
1760 expand_dummy_function_end clears it. */
1761 if (saved_regno_reg_rtx)
1762 {
1763 *crtl = saved_x_rtl;
1764 regno_reg_rtx = saved_regno_reg_rtx;
1765 saved_regno_reg_rtx = NULL;
1766 }
1767 }
1768
1769 void
1770 dump_memory_report (bool final)
1771 {
1772 dump_line_table_statistics ();
1773 ggc_print_statistics ();
1774 stringpool_statistics ();
1775 dump_tree_statistics ();
1776 dump_gimple_statistics ();
1777 dump_rtx_statistics ();
1778 dump_alloc_pool_statistics ();
1779 dump_bitmap_statistics ();
1780 dump_vec_loc_statistics ();
1781 dump_ggc_loc_statistics (final);
1782 dump_alias_stats (stderr);
1783 dump_pta_stats (stderr);
1784 }
1785
1786 /* Clean up: close opened files, etc. */
1787
1788 static void
1789 finalize (bool no_backend)
1790 {
1791 /* Close the dump files. */
1792 if (flag_gen_aux_info)
1793 {
1794 fclose (aux_info_file);
1795 if (seen_error ())
1796 unlink (aux_info_file_name);
1797 }
1798
1799 /* Close non-debugging input and output files. Take special care to note
1800 whether fclose returns an error, since the pages might still be on the
1801 buffer chain while the file is open. */
1802
1803 if (asm_out_file)
1804 {
1805 if (ferror (asm_out_file) != 0)
1806 fatal_error ("error writing to %s: %m", asm_file_name);
1807 if (fclose (asm_out_file) != 0)
1808 fatal_error ("error closing %s: %m", asm_file_name);
1809 }
1810
1811 if (stack_usage_file)
1812 fclose (stack_usage_file);
1813
1814 if (!no_backend)
1815 {
1816 statistics_fini ();
1817
1818 finish_optimization_passes ();
1819
1820 ira_finish_once ();
1821 }
1822
1823 if (mem_report)
1824 dump_memory_report (true);
1825
1826 /* Language-specific end of compilation actions. */
1827 lang_hooks.finish ();
1828 }
1829
1830 /* Initialize the compiler, and compile the input file. */
1831 static void
1832 do_compile (void)
1833 {
1834 /* Initialize timing first. The C front ends read the main file in
1835 the post_options hook, and C++ does file timings. */
1836 if (time_report || !quiet_flag || flag_detailed_statistics)
1837 timevar_init ();
1838 timevar_start (TV_TOTAL);
1839
1840 process_options ();
1841
1842 /* Don't do any more if an error has already occurred. */
1843 if (!seen_error ())
1844 {
1845 timevar_start (TV_PHASE_SETUP);
1846
1847 /* This must be run always, because it is needed to compute the FP
1848 predefined macros, such as __LDBL_MAX__, for targets using non
1849 default FP formats. */
1850 init_adjust_machine_modes ();
1851
1852 /* Set up the back-end if requested. */
1853 if (!no_backend)
1854 backend_init ();
1855
1856 /* Language-dependent initialization. Returns true on success. */
1857 if (lang_dependent_init (main_input_filename))
1858 {
1859 /* Initialize yet another pass. */
1860
1861 ggc_protect_identifiers = true;
1862
1863 init_cgraph ();
1864 init_final (main_input_filename);
1865 coverage_init (aux_base_name);
1866 statistics_init ();
1867 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
1868
1869 timevar_stop (TV_PHASE_SETUP);
1870
1871 compile_file ();
1872 }
1873 else
1874 {
1875 timevar_stop (TV_PHASE_SETUP);
1876 }
1877
1878 timevar_start (TV_PHASE_FINALIZE);
1879
1880 finalize (no_backend);
1881
1882 timevar_stop (TV_PHASE_FINALIZE);
1883 }
1884
1885 /* Stop timing and print the times. */
1886 timevar_stop (TV_TOTAL);
1887 timevar_print (stderr);
1888 }
1889
1890 /* Entry point of cc1, cc1plus, jc1, f771, etc.
1891 Exit code is FATAL_EXIT_CODE if can't open files or if there were
1892 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
1893
1894 It is not safe to call this function more than once. */
1895
1896 int
1897 toplev_main (int argc, char **argv)
1898 {
1899 /* Parsing and gimplification sometimes need quite large stack.
1900 Increase stack size limits if possible. */
1901 stack_limit_increase (64 * 1024 * 1024);
1902
1903 expandargv (&argc, &argv);
1904
1905 /* Initialization of GCC's environment, and diagnostics. */
1906 general_init (argv[0]);
1907
1908 /* One-off initialization of options that does not need to be
1909 repeated when options are added for particular functions. */
1910 init_options_once ();
1911
1912 /* Initialize global options structures; this must be repeated for
1913 each structure used for parsing options. */
1914 init_options_struct (&global_options, &global_options_set);
1915 lang_hooks.init_options_struct (&global_options);
1916
1917 /* Convert the options to an array. */
1918 decode_cmdline_options_to_array_default_mask (argc,
1919 CONST_CAST2 (const char **,
1920 char **, argv),
1921 &save_decoded_options,
1922 &save_decoded_options_count);
1923
1924 /* Perform language-specific options initialization. */
1925 lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
1926
1927 /* Parse the options and do minimal processing; basically just
1928 enough to default flags appropriately. */
1929 decode_options (&global_options, &global_options_set,
1930 save_decoded_options, save_decoded_options_count,
1931 UNKNOWN_LOCATION, global_dc);
1932
1933 handle_common_deferred_options ();
1934
1935 init_local_tick ();
1936
1937 initialize_plugins ();
1938
1939 if (version_flag)
1940 print_version (stderr, "");
1941
1942 if (help_flag)
1943 print_plugins_help (stderr, "");
1944
1945 /* Exit early if we can (e.g. -help). */
1946 if (!exit_after_options)
1947 do_compile ();
1948
1949 if (warningcount || errorcount)
1950 print_ignored_options ();
1951 diagnostic_finish (global_dc);
1952
1953 /* Invoke registered plugin callbacks if any. */
1954 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
1955
1956 finalize_plugins ();
1957 if (seen_error ())
1958 return (FATAL_EXIT_CODE);
1959
1960 return (SUCCESS_EXIT_CODE);
1961 }