OSDN Git Service

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