OSDN Git Service

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