OSDN Git Service

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