OSDN Git Service

Daily bump.
[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   invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
1021
1022   timevar_push (TV_PARSE);
1023
1024   /* Call the parser, which parses the entire file (calling
1025      rest_of_compilation for each function).  */
1026   lang_hooks.parse_file (set_yydebug);
1027
1028   /* Compilation is now finished except for writing
1029      what's left of the symbol table output.  */
1030   timevar_pop (TV_PARSE);
1031
1032   if (flag_syntax_only)
1033     return;
1034
1035   ggc_protect_identifiers = false;
1036
1037   /* This must also call cgraph_finalize_compilation_unit.  */
1038   lang_hooks.decls.final_write_globals ();
1039
1040   if (errorcount || sorrycount)
1041     return;
1042
1043   varpool_assemble_pending_decls ();
1044   finish_aliases_2 ();
1045
1046   /* Likewise for mudflap static object registrations.  */
1047   if (flag_mudflap)
1048     mudflap_finish_file ();
1049
1050   /* Likewise for emulated thread-local storage.  */
1051   if (!targetm.have_tls)
1052     emutls_finish ();
1053
1054   output_shared_constant_pool ();
1055   output_object_blocks ();
1056
1057   /* Write out any pending weak symbol declarations.  */
1058   weak_finish ();
1059
1060   /* Do dbx symbols.  */
1061   timevar_push (TV_SYMOUT);
1062
1063 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
1064   if (dwarf2out_do_frame ())
1065     dwarf2out_frame_finish ();
1066 #endif
1067
1068   (*debug_hooks->finish) (main_input_filename);
1069   timevar_pop (TV_SYMOUT);
1070
1071   /* Output some stuff at end of file if nec.  */
1072
1073   dw2_output_indirect_constants ();
1074
1075   /* Flush any pending external directives.  */
1076   process_pending_assemble_externals ();
1077
1078   /* Attach a special .ident directive to the end of the file to identify
1079      the version of GCC which compiled this code.  The format of the .ident
1080      string is patterned after the ones produced by native SVR4 compilers.  */
1081 #ifdef IDENT_ASM_OP
1082   if (!flag_no_ident)
1083     {
1084       const char *pkg_version = "(GNU) ";
1085
1086       if (strcmp ("(GCC) ", pkgversion_string))
1087         pkg_version = pkgversion_string;
1088       fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
1089                IDENT_ASM_OP, pkg_version, version_string);
1090     }
1091 #endif
1092
1093   /* Invoke registered plugin callbacks.  */
1094   invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
1095   
1096   /* This must be at the end.  Some target ports emit end of file directives
1097      into the assembly file here, and hence we can not output anything to the
1098      assembly file after this point.  */
1099   targetm.asm_out.file_end ();
1100 }
1101
1102 /* Parse a -d... command line switch.  */
1103
1104 void
1105 decode_d_option (const char *arg)
1106 {
1107   int c;
1108
1109   while (*arg)
1110     switch (c = *arg++)
1111       {
1112       case 'A':
1113         flag_debug_asm = 1;
1114         break;
1115       case 'p':
1116         flag_print_asm_name = 1;
1117         break;
1118       case 'P':
1119         flag_dump_rtl_in_asm = 1;
1120         flag_print_asm_name = 1;
1121         break;
1122       case 'v':
1123         graph_dump_format = vcg;
1124         break;
1125       case 'x':
1126         rtl_dump_and_exit = 1;
1127         break;
1128       case 'y':
1129         set_yydebug = 1;
1130         break;
1131       case 'D': /* These are handled by the preprocessor.  */
1132       case 'I':
1133       case 'M':
1134       case 'N':
1135       case 'U':
1136         break;
1137       case 'H':
1138         setup_core_dumping();
1139         break;
1140       case 'a':
1141         enable_rtl_dump_file ();
1142         break;
1143
1144       default:
1145           warning (0, "unrecognized gcc debugging option: %c", c);
1146         break;
1147       }
1148 }
1149
1150 /* Indexed by enum debug_info_type.  */
1151 const char *const debug_type_names[] =
1152 {
1153   "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1154 };
1155
1156 /* Print version information to FILE.
1157    Each line begins with INDENT (for the case where FILE is the
1158    assembler output file).  */
1159
1160 void
1161 print_version (FILE *file, const char *indent)
1162 {
1163   static const char fmt1[] =
1164 #ifdef __GNUC__
1165     N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1166 #else
1167     N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1168 #endif
1169     ;
1170 #ifdef HAVE_mpc
1171   static const char fmt2[] =
1172     N_("GMP version %s, MPFR version %s, MPC version %s\n");
1173 #else
1174   static const char fmt2[] =
1175     N_("GMP version %s, MPFR version %s\n");
1176 #endif
1177   static const char fmt3[] =
1178     N_("%s%swarning: %s header version %s differs from library version %s.\n");
1179   static const char fmt4[] =
1180     N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1181 #ifndef __VERSION__
1182 #define __VERSION__ "[?]"
1183 #endif
1184   fprintf (file,
1185            file == stderr ? _(fmt1) : fmt1,
1186            indent, *indent != 0 ? " " : "",
1187            lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
1188            indent, __VERSION__);
1189
1190   /* We need to stringify the GMP macro values.  Ugh, gmp_version has
1191      two string formats, "i.j.k" and "i.j" when k is zero.  As of
1192      gmp-4.3.0, GMP always uses the 3 number format.  */
1193 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1194 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1195 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
1196 #define GCC_GMP_VERSION \
1197   GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
1198 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
1199 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1200   GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1201 #else
1202 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1203   GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1204   GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1205 #endif
1206   fprintf (file,
1207            file == stderr ? _(fmt2) : fmt2,
1208            GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING
1209 #ifdef HAVE_mpc
1210            , MPC_VERSION_STRING
1211 #endif
1212            );
1213   if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
1214     fprintf (file,
1215              file == stderr ? _(fmt3) : fmt3,
1216              indent, *indent != 0 ? " " : "",
1217              "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
1218   if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
1219     fprintf (file,
1220              file == stderr ? _(fmt3) : fmt3,
1221              indent, *indent != 0 ? " " : "",
1222              "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
1223 #ifdef HAVE_mpc
1224   if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
1225     fprintf (file,
1226              file == stderr ? _(fmt3) : fmt3,
1227              indent, *indent != 0 ? " " : "",
1228              "MPC", MPC_VERSION_STRING, mpc_get_version ());
1229 #endif
1230   fprintf (file,
1231            file == stderr ? _(fmt4) : fmt4,
1232            indent, *indent != 0 ? " " : "",
1233            PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1234
1235   print_plugins_versions (file, indent);
1236 }
1237
1238 #ifdef ASM_COMMENT_START
1239 static int
1240 print_to_asm_out_file (print_switch_type type, const char * text)
1241 {
1242   bool prepend_sep = true;
1243
1244   switch (type)
1245     {
1246     case SWITCH_TYPE_LINE_END:
1247       putc ('\n', asm_out_file);
1248       return 1;
1249
1250     case SWITCH_TYPE_LINE_START:
1251       fputs (ASM_COMMENT_START, asm_out_file);
1252       return strlen (ASM_COMMENT_START);
1253
1254     case SWITCH_TYPE_DESCRIPTIVE:
1255       if (ASM_COMMENT_START[0] == 0)
1256         prepend_sep = false;
1257       /* Drop through.  */
1258     case SWITCH_TYPE_PASSED:
1259     case SWITCH_TYPE_ENABLED:
1260       if (prepend_sep)
1261         fputc (' ', asm_out_file);
1262       fprintf (asm_out_file, text);
1263       /* No need to return the length here as
1264          print_single_switch has already done it.  */
1265       return 0;
1266
1267     default:
1268       return -1;
1269     }
1270 }
1271 #endif
1272
1273 static int
1274 print_to_stderr (print_switch_type type, const char * text)
1275 {
1276   switch (type)
1277     {
1278     case SWITCH_TYPE_LINE_END:
1279       putc ('\n', stderr);
1280       return 1;
1281
1282     case SWITCH_TYPE_LINE_START:
1283       return 0;
1284       
1285     case SWITCH_TYPE_PASSED:
1286     case SWITCH_TYPE_ENABLED:
1287       fputc (' ', stderr);
1288       /* Drop through.  */
1289
1290     case SWITCH_TYPE_DESCRIPTIVE:
1291       fprintf (stderr, text);
1292       /* No need to return the length here as
1293          print_single_switch has already done it.  */
1294       return 0;
1295
1296     default:
1297       return -1;
1298     }
1299 }
1300
1301 /* Print an option value and return the adjusted position in the line.
1302    ??? print_fn doesn't handle errors, eg disk full; presumably other
1303    code will catch a disk full though.  */
1304
1305 static int
1306 print_single_switch (print_switch_fn_type print_fn,
1307                      int pos,
1308                      print_switch_type type,
1309                      const char * text)
1310 {
1311   /* The ultrix fprintf returns 0 on success, so compute the result
1312      we want here since we need it for the following test.  The +1
1313      is for the separator character that will probably be emitted.  */
1314   int len = strlen (text) + 1;
1315
1316   if (pos != 0
1317       && pos + len > MAX_LINE)
1318     {
1319       print_fn (SWITCH_TYPE_LINE_END, NULL);
1320       pos = 0;
1321     }
1322
1323   if (pos == 0)
1324     pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1325
1326   print_fn (type, text);
1327   return pos + len;
1328 }
1329
1330 /* Print active target switches using PRINT_FN.
1331    POS is the current cursor position and MAX is the size of a "line".
1332    Each line begins with INDENT and ends with TERM.
1333    Each switch is separated from the next by SEP.  */
1334
1335 static void
1336 print_switch_values (print_switch_fn_type print_fn)
1337 {
1338   int pos = 0;
1339   size_t j;
1340   const char **p;
1341
1342   /* Fill in the -frandom-seed option, if the user didn't pass it, so
1343      that it can be printed below.  This helps reproducibility.  */
1344   if (!flag_random_seed)
1345     init_random_seed ();
1346
1347   /* Print the options as passed.  */
1348   pos = print_single_switch (print_fn, pos,
1349                              SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1350
1351   for (p = &save_argv[1]; *p != NULL; p++)
1352     {
1353       if (**p == '-')
1354         {
1355           /* Ignore these.  */
1356           if (strcmp (*p, "-o") == 0
1357               || strcmp (*p, "-dumpbase") == 0
1358               || strcmp (*p, "-auxbase") == 0)
1359             {
1360               if (p[1] != NULL)
1361                 p++;
1362               continue;
1363             }
1364
1365           if (strcmp (*p, "-quiet") == 0
1366               || strcmp (*p, "-version") == 0)
1367             continue;
1368
1369           if ((*p)[1] == 'd')
1370             continue;
1371         }
1372
1373       pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED, *p);
1374     }
1375
1376   if (pos > 0)
1377     print_fn (SWITCH_TYPE_LINE_END, NULL);
1378
1379   /* Print the -f and -m options that have been enabled.
1380      We don't handle language specific options but printing argv
1381      should suffice.  */
1382   pos = print_single_switch (print_fn, 0,
1383                              SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1384
1385   for (j = 0; j < cl_options_count; j++)
1386     if ((cl_options[j].flags & CL_REPORT)
1387         && option_enabled (j) > 0)
1388       pos = print_single_switch (print_fn, pos,
1389                                  SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1390
1391   print_fn (SWITCH_TYPE_LINE_END, NULL);
1392 }
1393
1394 /* Open assembly code output file.  Do this even if -fsyntax-only is
1395    on, because then the driver will have provided the name of a
1396    temporary file or bit bucket for us.  NAME is the file specified on
1397    the command line, possibly NULL.  */
1398 static void
1399 init_asm_output (const char *name)
1400 {
1401   if (name == NULL && asm_file_name == 0)
1402     asm_out_file = stdout;
1403   else
1404     {
1405       if (asm_file_name == 0)
1406         {
1407           int len = strlen (dump_base_name);
1408           char *dumpname = XNEWVEC (char, len + 6);
1409
1410           memcpy (dumpname, dump_base_name, len + 1);
1411           strip_off_ending (dumpname, len);
1412           strcat (dumpname, ".s");
1413           asm_file_name = dumpname;
1414         }
1415       if (!strcmp (asm_file_name, "-"))
1416         asm_out_file = stdout;
1417       else
1418         asm_out_file = fopen (asm_file_name, "w+b");
1419       if (asm_out_file == 0)
1420         fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1421     }
1422
1423   if (!flag_syntax_only)
1424     {
1425       targetm.asm_out.file_start ();
1426
1427       if (flag_record_gcc_switches)
1428         {
1429           if (targetm.asm_out.record_gcc_switches)
1430             {
1431               /* Let the target know that we are about to start recording.  */
1432               targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1433                                                    NULL);
1434               /* Now record the switches.  */
1435               print_switch_values (targetm.asm_out.record_gcc_switches);
1436               /* Let the target know that the recording is over.  */
1437               targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1438                                                    NULL);
1439             }
1440           else
1441             inform (input_location, "-frecord-gcc-switches is not supported by the current target");
1442         }
1443
1444 #ifdef ASM_COMMENT_START
1445       if (flag_verbose_asm)
1446         {
1447           /* Print the list of switches in effect
1448              into the assembler file as comments.  */
1449           print_version (asm_out_file, ASM_COMMENT_START);
1450           print_switch_values (print_to_asm_out_file);
1451           fprintf (asm_out_file, "\n");
1452         }
1453 #endif
1454     }
1455 }
1456
1457 /* Return true if the state of option OPTION should be stored in PCH files
1458    and checked by default_pch_valid_p.  Store the option's current state
1459    in STATE if so.  */
1460
1461 static inline bool
1462 option_affects_pch_p (int option, struct cl_option_state *state)
1463 {
1464   if ((cl_options[option].flags & CL_TARGET) == 0)
1465     return false;
1466   if (cl_options[option].flag_var == &target_flags)
1467     if (targetm.check_pch_target_flags)
1468       return false;
1469   return get_option_state (option, state);
1470 }
1471
1472 /* Default version of get_pch_validity.
1473    By default, every flag difference is fatal; that will be mostly right for
1474    most targets, but completely right for very few.  */
1475
1476 void *
1477 default_get_pch_validity (size_t *len)
1478 {
1479   struct cl_option_state state;
1480   size_t i;
1481   char *result, *r;
1482
1483   *len = 2;
1484   if (targetm.check_pch_target_flags)
1485     *len += sizeof (target_flags);
1486   for (i = 0; i < cl_options_count; i++)
1487     if (option_affects_pch_p (i, &state))
1488       *len += state.size;
1489
1490   result = r = XNEWVEC (char, *len);
1491   r[0] = flag_pic;
1492   r[1] = flag_pie;
1493   r += 2;
1494   if (targetm.check_pch_target_flags)
1495     {
1496       memcpy (r, &target_flags, sizeof (target_flags));
1497       r += sizeof (target_flags);
1498     }
1499
1500   for (i = 0; i < cl_options_count; i++)
1501     if (option_affects_pch_p (i, &state))
1502       {
1503         memcpy (r, state.data, state.size);
1504         r += state.size;
1505       }
1506
1507   return result;
1508 }
1509
1510 /* Return a message which says that a PCH file was created with a different
1511    setting of OPTION.  */
1512
1513 static const char *
1514 pch_option_mismatch (const char *option)
1515 {
1516   char *r;
1517
1518   asprintf (&r, _("created and used with differing settings of '%s'"), option);
1519   if (r == NULL)
1520     return _("out of memory");
1521   return r;
1522 }
1523
1524 /* Default version of pch_valid_p.  */
1525
1526 const char *
1527 default_pch_valid_p (const void *data_p, size_t len)
1528 {
1529   struct cl_option_state state;
1530   const char *data = (const char *)data_p;
1531   size_t i;
1532
1533   /* -fpic and -fpie also usually make a PCH invalid.  */
1534   if (data[0] != flag_pic)
1535     return _("created and used with different settings of -fpic");
1536   if (data[1] != flag_pie)
1537     return _("created and used with different settings of -fpie");
1538   data += 2;
1539
1540   /* Check target_flags.  */
1541   if (targetm.check_pch_target_flags)
1542     {
1543       int tf;
1544       const char *r;
1545
1546       memcpy (&tf, data, sizeof (target_flags));
1547       data += sizeof (target_flags);
1548       len -= sizeof (target_flags);
1549       r = targetm.check_pch_target_flags (tf);
1550       if (r != NULL)
1551         return r;
1552     }
1553
1554   for (i = 0; i < cl_options_count; i++)
1555     if (option_affects_pch_p (i, &state))
1556       {
1557         if (memcmp (data, state.data, state.size) != 0)
1558           return pch_option_mismatch (cl_options[i].opt_text);
1559         data += state.size;
1560         len -= state.size;
1561       }
1562
1563   return NULL;
1564 }
1565
1566 /* Default tree printer.   Handles declarations only.  */
1567 static bool
1568 default_tree_printer (pretty_printer * pp, text_info *text, const char *spec,
1569                       int precision, bool wide, bool set_locus, bool hash)
1570 {
1571   tree t;
1572
1573   /* FUTURE: %+x should set the locus.  */
1574   if (precision != 0 || wide || hash)
1575     return false;
1576
1577   switch (*spec)
1578     {
1579     case 'E':
1580       t = va_arg (*text->args_ptr, tree);
1581       if (TREE_CODE (t) == IDENTIFIER_NODE)
1582         {
1583           pp_identifier (pp, IDENTIFIER_POINTER (t));
1584           return true;
1585         }
1586       break;
1587
1588     case 'D':
1589       t = va_arg (*text->args_ptr, tree);
1590       if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1591         t = DECL_DEBUG_EXPR (t);
1592       break;
1593
1594     case 'F':
1595     case 'T':
1596       t = va_arg (*text->args_ptr, tree);
1597       break;
1598
1599     default:
1600       return false;
1601     }
1602
1603   if (set_locus && text->locus)
1604     *text->locus = DECL_SOURCE_LOCATION (t);
1605
1606   if (DECL_P (t))
1607     {
1608       const char *n = DECL_NAME (t)
1609         ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2))
1610         : _("<anonymous>");
1611       pp_string (pp, n);
1612     }
1613   else
1614     dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1615
1616   return true;
1617 }
1618
1619 /* A helper function; used as the reallocator function for cpp's line
1620    table.  */
1621 static void *
1622 realloc_for_line_map (void *ptr, size_t len)
1623 {
1624   return ggc_realloc (ptr, len);
1625 }
1626
1627 /* Initialization of the front end environment, before command line
1628    options are parsed.  Signal handlers, internationalization etc.
1629    ARGV0 is main's argv[0].  */
1630 static void
1631 general_init (const char *argv0)
1632 {
1633   const char *p;
1634
1635   p = argv0 + strlen (argv0);
1636   while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1637     --p;
1638   progname = p;
1639
1640   xmalloc_set_program_name (progname);
1641
1642   hex_init ();
1643
1644   /* Unlock the stdio streams.  */
1645   unlock_std_streams ();
1646
1647   gcc_init_libintl ();
1648
1649   /* Initialize the diagnostics reporting machinery, so option parsing
1650      can give warnings and errors.  */
1651   diagnostic_initialize (global_dc);
1652   /* Set a default printer.  Language specific initializations will
1653      override it later.  */
1654   pp_format_decoder (global_dc->printer) = &default_tree_printer;
1655
1656   /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages.  */
1657 #ifdef SIGSEGV
1658   signal (SIGSEGV, crash_signal);
1659 #endif
1660 #ifdef SIGILL
1661   signal (SIGILL, crash_signal);
1662 #endif
1663 #ifdef SIGBUS
1664   signal (SIGBUS, crash_signal);
1665 #endif
1666 #ifdef SIGABRT
1667   signal (SIGABRT, crash_signal);
1668 #endif
1669 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1670   signal (SIGIOT, crash_signal);
1671 #endif
1672 #ifdef SIGFPE
1673   signal (SIGFPE, crash_signal);
1674 #endif
1675
1676   /* Other host-specific signal setup.  */
1677   (*host_hooks.extra_signals)();
1678
1679   /* Initialize the garbage-collector, string pools and tree type hash
1680      table.  */
1681   init_ggc ();
1682   init_stringpool ();
1683   line_table = GGC_NEW (struct line_maps);
1684   linemap_init (line_table);
1685   line_table->reallocator = realloc_for_line_map;
1686   init_ttree ();
1687
1688   /* Initialize register usage now so switches may override.  */
1689   init_reg_sets ();
1690
1691   /* Register the language-independent parameters.  */
1692   add_params (lang_independent_params, LAST_PARAM);
1693
1694   /* This must be done after add_params but before argument processing.  */
1695   init_ggc_heuristics();
1696   init_optimization_passes ();
1697   statistics_early_init ();
1698 }
1699
1700 /* Return true if the current target supports -fsection-anchors.  */
1701
1702 static bool
1703 target_supports_section_anchors_p (void)
1704 {
1705   if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1706     return false;
1707
1708   if (targetm.asm_out.output_anchor == NULL)
1709     return false;
1710
1711   return true;
1712 }
1713
1714 /* Default the align_* variables to 1 if they're still unset, and
1715    set up the align_*_log variables.  */
1716 static void
1717 init_alignments (void)
1718 {
1719   if (align_loops <= 0)
1720     align_loops = 1;
1721   if (align_loops_max_skip > align_loops)
1722     align_loops_max_skip = align_loops - 1;
1723   align_loops_log = floor_log2 (align_loops * 2 - 1);
1724   if (align_jumps <= 0)
1725     align_jumps = 1;
1726   if (align_jumps_max_skip > align_jumps)
1727     align_jumps_max_skip = align_jumps - 1;
1728   align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1729   if (align_labels <= 0)
1730     align_labels = 1;
1731   align_labels_log = floor_log2 (align_labels * 2 - 1);
1732   if (align_labels_max_skip > align_labels)
1733     align_labels_max_skip = align_labels - 1;
1734   if (align_functions <= 0)
1735     align_functions = 1;
1736   align_functions_log = floor_log2 (align_functions * 2 - 1);
1737 }
1738
1739 /* Process the options that have been parsed.  */
1740 static void
1741 process_options (void)
1742 {
1743   /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1744      This can happen with incorrect pre-processed input. */
1745   debug_hooks = &do_nothing_debug_hooks;
1746
1747   /* This replaces set_Wunused.  */
1748   if (warn_unused_function == -1)
1749     warn_unused_function = warn_unused;
1750   if (warn_unused_label == -1)
1751     warn_unused_label = warn_unused;
1752   /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled.  */
1753   if (warn_unused_parameter == -1)
1754     warn_unused_parameter = (warn_unused && extra_warnings);
1755   if (warn_unused_variable == -1)
1756     warn_unused_variable = warn_unused;
1757   if (warn_unused_value == -1)
1758     warn_unused_value = warn_unused;
1759
1760   /* This replaces set_Wextra.  */
1761   if (warn_uninitialized == -1)
1762     warn_uninitialized = extra_warnings;
1763
1764   /* Allow the front end to perform consistency checks and do further
1765      initialization based on the command line options.  This hook also
1766      sets the original filename if appropriate (e.g. foo.i -> foo.c)
1767      so we can correctly initialize debug output.  */
1768   no_backend = lang_hooks.post_options (&main_input_filename);
1769
1770 #ifdef OVERRIDE_OPTIONS
1771   /* Some machines may reject certain combinations of options.  */
1772   OVERRIDE_OPTIONS;
1773 #endif
1774
1775   if (flag_section_anchors && !target_supports_section_anchors_p ())
1776     {
1777       warning (OPT_fsection_anchors,
1778                "this target does not support %qs", "-fsection-anchors");
1779       flag_section_anchors = 0;
1780     }
1781
1782   if (flag_short_enums == 2)
1783     flag_short_enums = targetm.default_short_enums ();
1784
1785   /* Set aux_base_name if not already set.  */
1786   if (aux_base_name)
1787     ;
1788   else if (main_input_filename)
1789     {
1790       char *name = xstrdup (lbasename (main_input_filename));
1791
1792       strip_off_ending (name, strlen (name));
1793       aux_base_name = name;
1794     }
1795   else
1796     aux_base_name = "gccaux";
1797
1798 #ifndef HAVE_cloog
1799   if (flag_graphite
1800       || flag_loop_block
1801       || flag_loop_interchange
1802       || flag_loop_strip_mine
1803       || flag_graphite_identity
1804       || flag_loop_parallelize_all)
1805     sorry ("Graphite loop optimizations cannot be used");
1806 #endif
1807
1808   /* Unrolling all loops implies that standard loop unrolling must also
1809      be done.  */
1810   if (flag_unroll_all_loops)
1811     flag_unroll_loops = 1;
1812
1813   /* The loop unrolling code assumes that cse will be run after loop.
1814      web and rename-registers also help when run after loop unrolling.  */
1815
1816   if (flag_rerun_cse_after_loop == AUTODETECT_VALUE)
1817     flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops;
1818   if (flag_web == AUTODETECT_VALUE)
1819     flag_web = flag_unroll_loops || flag_peel_loops;
1820   if (flag_rename_registers == AUTODETECT_VALUE)
1821     flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1822
1823   if (flag_non_call_exceptions)
1824     flag_asynchronous_unwind_tables = 1;
1825   if (flag_asynchronous_unwind_tables)
1826     flag_unwind_tables = 1;
1827
1828   if (flag_value_profile_transformations)
1829     flag_profile_values = 1;
1830
1831   /* Warn about options that are not supported on this machine.  */
1832 #ifndef INSN_SCHEDULING
1833   if (flag_schedule_insns || flag_schedule_insns_after_reload)
1834     warning (0, "instruction scheduling not supported on this target machine");
1835 #endif
1836 #ifndef DELAY_SLOTS
1837   if (flag_delayed_branch)
1838     warning (0, "this target machine does not have delayed branches");
1839 #endif
1840
1841   user_label_prefix = USER_LABEL_PREFIX;
1842   if (flag_leading_underscore != -1)
1843     {
1844       /* If the default prefix is more complicated than "" or "_",
1845          issue a warning and ignore this option.  */
1846       if (user_label_prefix[0] == 0 ||
1847           (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1848         {
1849           user_label_prefix = flag_leading_underscore ? "_" : "";
1850         }
1851       else
1852         warning (0, "-f%sleading-underscore not supported on this target machine",
1853                  flag_leading_underscore ? "" : "no-");
1854     }
1855
1856   /* If we are in verbose mode, write out the version and maybe all the
1857      option flags in use.  */
1858   if (version_flag)
1859     {
1860       print_version (stderr, "");
1861       if (! quiet_flag)
1862         print_switch_values (print_to_stderr);
1863     }
1864
1865   if (flag_syntax_only)
1866     {
1867       write_symbols = NO_DEBUG;
1868       profile_flag = 0;
1869     }
1870
1871   if (flag_gtoggle)
1872     {
1873       if (debug_info_level == DINFO_LEVEL_NONE)
1874         debug_info_level = DINFO_LEVEL_NORMAL;
1875       else
1876         debug_info_level = DINFO_LEVEL_NONE;
1877     }
1878
1879   if (flag_dump_final_insns)
1880     {
1881       FILE *final_output = fopen (flag_dump_final_insns, "w");
1882       if (!final_output)
1883         {
1884           error ("could not open final insn dump file %qs: %s",
1885                  flag_dump_final_insns, strerror (errno));
1886           flag_dump_final_insns = NULL;
1887         }
1888       else if (fclose (final_output))
1889         {
1890           error ("could not close zeroed insn dump file %qs: %s",
1891                  flag_dump_final_insns, strerror (errno));
1892           flag_dump_final_insns = NULL;
1893         }
1894     }
1895
1896   /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1897      level is 0.  */
1898   if (debug_info_level == DINFO_LEVEL_NONE)
1899     write_symbols = NO_DEBUG;
1900
1901   /* Now we know write_symbols, set up the debug hooks based on it.
1902      By default we do nothing for debug output.  */
1903   if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG)
1904     default_debug_hooks = &do_nothing_debug_hooks;
1905 #if defined(DBX_DEBUGGING_INFO)
1906   else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG)
1907     default_debug_hooks = &dbx_debug_hooks;
1908 #endif
1909 #if defined(XCOFF_DEBUGGING_INFO)
1910   else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG)
1911     default_debug_hooks = &xcoff_debug_hooks;
1912 #endif
1913 #ifdef SDB_DEBUGGING_INFO
1914   else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG)
1915     default_debug_hooks = &sdb_debug_hooks;
1916 #endif
1917 #ifdef DWARF2_DEBUGGING_INFO
1918   else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG)
1919     default_debug_hooks = &dwarf2_debug_hooks;
1920 #endif
1921 #ifdef VMS_DEBUGGING_INFO
1922   else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG
1923            || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG)
1924     default_debug_hooks = &vmsdbg_debug_hooks;
1925 #endif
1926
1927   if (write_symbols == NO_DEBUG)
1928     ;
1929 #if defined(DBX_DEBUGGING_INFO)
1930   else if (write_symbols == DBX_DEBUG)
1931     debug_hooks = &dbx_debug_hooks;
1932 #endif
1933 #if defined(XCOFF_DEBUGGING_INFO)
1934   else if (write_symbols == XCOFF_DEBUG)
1935     debug_hooks = &xcoff_debug_hooks;
1936 #endif
1937 #ifdef SDB_DEBUGGING_INFO
1938   else if (write_symbols == SDB_DEBUG)
1939     debug_hooks = &sdb_debug_hooks;
1940 #endif
1941 #ifdef DWARF2_DEBUGGING_INFO
1942   else if (write_symbols == DWARF2_DEBUG)
1943     debug_hooks = &dwarf2_debug_hooks;
1944 #endif
1945 #ifdef VMS_DEBUGGING_INFO
1946   else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1947     debug_hooks = &vmsdbg_debug_hooks;
1948 #endif
1949   else
1950     error ("target system does not support the \"%s\" debug format",
1951            debug_type_names[write_symbols]);
1952
1953   /* Now we know which debug output will be used so we can set
1954      flag_var_tracking, flag_rename_registers if the user has
1955      not specified them.  */
1956   if (debug_info_level < DINFO_LEVEL_NORMAL
1957       || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1958     {
1959       if (flag_var_tracking == 1
1960           || flag_var_tracking_uninit == 1)
1961         {
1962           if (debug_info_level < DINFO_LEVEL_NORMAL)
1963             warning (0, "variable tracking requested, but useless unless "
1964                      "producing debug info");
1965           else
1966             warning (0, "variable tracking requested, but not supported "
1967                      "by this debug format");
1968         }
1969       flag_var_tracking = 0;
1970       flag_var_tracking_uninit = 0;
1971     }
1972
1973   if (flag_rename_registers == AUTODETECT_VALUE)
1974     flag_rename_registers = default_debug_hooks->var_location
1975                             != do_nothing_debug_hooks.var_location;
1976
1977   if (flag_var_tracking == AUTODETECT_VALUE)
1978     flag_var_tracking = optimize >= 1;
1979
1980   if (flag_tree_cselim == AUTODETECT_VALUE)
1981 #ifdef HAVE_conditional_move
1982     flag_tree_cselim = 1;
1983 #else
1984     flag_tree_cselim = 0;
1985 #endif
1986
1987   /* If the user specifically requested variable tracking with tagging
1988      uninitialized variables, we need to turn on variable tracking.
1989      (We already determined above that variable tracking is feasible.)  */
1990   if (flag_var_tracking_uninit)
1991     flag_var_tracking = 1;
1992
1993   /* If auxiliary info generation is desired, open the output file.
1994      This goes in the same directory as the source file--unlike
1995      all the other output files.  */
1996   if (flag_gen_aux_info)
1997     {
1998       aux_info_file = fopen (aux_info_file_name, "w");
1999       if (aux_info_file == 0)
2000         fatal_error ("can%'t open %s: %m", aux_info_file_name);
2001     }
2002
2003   if (! targetm.have_named_sections)
2004     {
2005       if (flag_function_sections)
2006         {
2007           warning (0, "-ffunction-sections not supported for this target");
2008           flag_function_sections = 0;
2009         }
2010       if (flag_data_sections)
2011         {
2012           warning (0, "-fdata-sections not supported for this target");
2013           flag_data_sections = 0;
2014         }
2015     }
2016
2017   if (flag_function_sections && profile_flag)
2018     {
2019       warning (0, "-ffunction-sections disabled; it makes profiling impossible");
2020       flag_function_sections = 0;
2021     }
2022
2023 #ifndef HAVE_prefetch
2024   if (flag_prefetch_loop_arrays)
2025     {
2026       warning (0, "-fprefetch-loop-arrays not supported for this target");
2027       flag_prefetch_loop_arrays = 0;
2028     }
2029 #else
2030   if (flag_prefetch_loop_arrays && !HAVE_prefetch)
2031     {
2032       warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
2033       flag_prefetch_loop_arrays = 0;
2034     }
2035 #endif
2036
2037   /* This combination of options isn't handled for i386 targets and doesn't
2038      make much sense anyway, so don't allow it.  */
2039   if (flag_prefetch_loop_arrays && optimize_size)
2040     {
2041       warning (0, "-fprefetch-loop-arrays is not supported with -Os");
2042       flag_prefetch_loop_arrays = 0;
2043     }
2044
2045   /* The presence of IEEE signaling NaNs, implies all math can trap.  */
2046   if (flag_signaling_nans)
2047     flag_trapping_math = 1;
2048
2049   /* We cannot reassociate if we want traps or signed zeros.  */
2050   if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
2051     {
2052       warning (0, "-fassociative-math disabled; other options take precedence");
2053       flag_associative_math = 0;
2054     }
2055
2056   /* With -fcx-limited-range, we do cheap and quick complex arithmetic.  */
2057   if (flag_cx_limited_range)
2058     flag_complex_method = 0;
2059
2060   /* With -fcx-fortran-rules, we do something in-between cheap and C99.  */
2061   if (flag_cx_fortran_rules)
2062     flag_complex_method = 1;
2063
2064   /* Targets must be able to place spill slots at lower addresses.  If the
2065      target already uses a soft frame pointer, the transition is trivial.  */
2066   if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
2067     {
2068       warning (0, "-fstack-protector not supported for this target");
2069       flag_stack_protect = 0;
2070     }
2071   if (!flag_stack_protect)
2072     warn_stack_protect = 0;
2073
2074   /* ??? Unwind info is not correct around the CFG unless either a frame
2075      pointer is present or A_O_A is set.  Fixing this requires rewriting
2076      unwind info generation to be aware of the CFG and propagating states
2077      around edges.  */
2078   if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
2079       && flag_omit_frame_pointer)
2080     {
2081       warning (0, "unwind tables currently require a frame pointer "
2082                "for correctness");
2083       flag_omit_frame_pointer = 0;
2084     }
2085 }
2086
2087 /* This function can be called multiple times to reinitialize the compiler
2088    back end when register classes or instruction sets have changed,
2089    before each function.  */
2090 static void
2091 backend_init_target (void)
2092 {
2093   /* Initialize alignment variables.  */
2094   init_alignments ();
2095
2096   /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
2097      to initialize reg_raw_mode[].  */
2098   init_emit_regs ();
2099
2100   /* This invokes target hooks to set fixed_reg[] etc, which is
2101      mode-dependent.  */
2102   init_regs ();
2103
2104   /* This depends on stack_pointer_rtx.  */
2105   init_fake_stack_mems ();
2106
2107   /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
2108      mode-dependent.  */
2109   init_alias_target ();
2110
2111   /* Depends on HARD_FRAME_POINTER_REGNUM.  */
2112   init_reload ();
2113
2114   /* The following initialization functions need to generate rtl, so
2115      provide a dummy function context for them.  */
2116   init_dummy_function_start ();
2117
2118   /* rtx_cost is mode-dependent, so cached values need to be recomputed
2119      on a mode change.  */
2120   init_expmed ();
2121
2122   /* We may need to recompute regno_save_code[] and regno_restore_code[]
2123      after a mode change as well.  */
2124   if (flag_caller_saves)
2125     init_caller_save ();
2126   expand_dummy_function_end ();
2127 }
2128
2129 /* Initialize the compiler back end.  This function is called only once,
2130    when starting the compiler.  */
2131 static void
2132 backend_init (void)
2133 {
2134   init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2135                   || debug_info_level == DINFO_LEVEL_VERBOSE
2136 #ifdef VMS_DEBUGGING_INFO
2137                     /* Enable line number info for traceback.  */
2138                     || debug_info_level > DINFO_LEVEL_NONE
2139 #endif
2140                     || flag_test_coverage);
2141
2142   init_rtlanal ();
2143   init_inline_once ();
2144   init_varasm_once ();
2145   save_register_info ();
2146
2147   /* Initialize the target-specific back end pieces.  */
2148   ira_init_once ();
2149   backend_init_target ();
2150 }
2151
2152 /* Initialize excess precision settings.  */
2153 static void
2154 init_excess_precision (void)
2155 {
2156   /* Adjust excess precision handling based on the target options.  If
2157      the front end cannot handle it, flag_excess_precision_cmdline
2158      will already have been set accordingly in the post_options
2159      hook.  */
2160   gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
2161   flag_excess_precision = flag_excess_precision_cmdline;
2162   if (flag_unsafe_math_optimizations)
2163     flag_excess_precision = EXCESS_PRECISION_FAST;
2164   if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
2165     {
2166       int flt_eval_method = TARGET_FLT_EVAL_METHOD;
2167       switch (flt_eval_method)
2168         {
2169         case -1:
2170         case 0:
2171           /* Either the target acts unpredictably (-1) or has all the
2172              operations required not to have excess precision (0).  */
2173           flag_excess_precision = EXCESS_PRECISION_FAST;
2174           break;
2175         case 1:
2176         case 2:
2177           /* In these cases, predictable excess precision makes
2178              sense.  */
2179           break;
2180         default:
2181           /* Any other implementation-defined FLT_EVAL_METHOD values
2182              require the compiler to handle the associated excess
2183              precision rules in excess_precision_type.  */
2184           gcc_unreachable ();
2185         }
2186     }
2187 }
2188
2189 /* Initialize things that are both lang-dependent and target-dependent.
2190    This function can be called more than once if target parameters change.  */
2191 static void
2192 lang_dependent_init_target (void)
2193 {
2194   /* This determines excess precision settings.  */
2195   init_excess_precision ();
2196
2197   /* This creates various _DECL nodes, so needs to be called after the
2198      front end is initialized.  It also depends on the HAVE_xxx macros
2199      generated from the target machine description.  */
2200   init_optabs ();
2201
2202   /* The following initialization functions need to generate rtl, so
2203      provide a dummy function context for them.  */
2204   init_dummy_function_start ();
2205
2206   /* Do the target-specific parts of expr initialization.  */
2207   init_expr_target ();
2208
2209   /* Although the actions of these functions are language-independent,
2210      they use optabs, so we cannot call them from backend_init.  */
2211   init_set_costs ();
2212   ira_init ();
2213
2214   expand_dummy_function_end ();
2215 }
2216
2217 /* Language-dependent initialization.  Returns nonzero on success.  */
2218 static int
2219 lang_dependent_init (const char *name)
2220 {
2221   location_t save_loc = input_location;
2222   if (dump_base_name == 0)
2223     dump_base_name = name && name[0] ? name : "gccdump";
2224
2225   /* Other front-end initialization.  */
2226   input_location = BUILTINS_LOCATION;
2227   if (lang_hooks.init () == 0)
2228     return 0;
2229   input_location = save_loc;
2230
2231   init_asm_output (name);
2232
2233   /* This creates various _DECL nodes, so needs to be called after the
2234      front end is initialized.  */
2235   init_eh ();
2236
2237   /* Do the target-specific parts of the initialization.  */
2238   lang_dependent_init_target ();
2239
2240   /* If dbx symbol table desired, initialize writing it and output the
2241      predefined types.  */
2242   timevar_push (TV_SYMOUT);
2243
2244 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2245   if (dwarf2out_do_frame ())
2246     dwarf2out_frame_init ();
2247 #endif
2248
2249   /* Now we have the correct original filename, we can initialize
2250      debug output.  */
2251   (*debug_hooks->init) (name);
2252
2253   timevar_pop (TV_SYMOUT);
2254
2255   return 1;
2256 }
2257
2258
2259 /* Reinitialize everything when target parameters, such as register usage,
2260    have changed.  */
2261 void
2262 target_reinit (void)
2263 {
2264   /* Reinitialize RTL backend.  */
2265   backend_init_target ();
2266
2267   /* Reinitialize lang-dependent parts.  */
2268   lang_dependent_init_target ();
2269 }
2270
2271 void
2272 dump_memory_report (bool final)
2273 {
2274   ggc_print_statistics ();
2275   stringpool_statistics ();
2276   dump_tree_statistics ();
2277   dump_gimple_statistics ();
2278   dump_rtx_statistics ();
2279   dump_varray_statistics ();
2280   dump_alloc_pool_statistics ();
2281   dump_bitmap_statistics ();
2282   dump_vec_loc_statistics ();
2283   dump_ggc_loc_statistics (final);
2284   dump_alias_stats (stderr);
2285   dump_pta_stats (stderr);
2286 }
2287
2288 /* Clean up: close opened files, etc.  */
2289
2290 static void
2291 finalize (void)
2292 {
2293   /* Close the dump files.  */
2294   if (flag_gen_aux_info)
2295     {
2296       fclose (aux_info_file);
2297       if (errorcount)
2298         unlink (aux_info_file_name);
2299     }
2300
2301   /* Close non-debugging input and output files.  Take special care to note
2302      whether fclose returns an error, since the pages might still be on the
2303      buffer chain while the file is open.  */
2304
2305   if (asm_out_file)
2306     {
2307       if (ferror (asm_out_file) != 0)
2308         fatal_error ("error writing to %s: %m", asm_file_name);
2309       if (fclose (asm_out_file) != 0)
2310         fatal_error ("error closing %s: %m", asm_file_name);
2311     }
2312
2313   statistics_fini ();
2314   finish_optimization_passes ();
2315
2316   ira_finish_once ();
2317
2318   if (mem_report)
2319     dump_memory_report (true);
2320
2321   /* Language-specific end of compilation actions.  */
2322   lang_hooks.finish ();
2323 }
2324
2325 /* Initialize the compiler, and compile the input file.  */
2326 static void
2327 do_compile (void)
2328 {
2329   /* Initialize timing first.  The C front ends read the main file in
2330      the post_options hook, and C++ does file timings.  */
2331   if (time_report || !quiet_flag  || flag_detailed_statistics)
2332     timevar_init ();
2333   timevar_start (TV_TOTAL);
2334
2335   process_options ();
2336
2337   /* Don't do any more if an error has already occurred.  */
2338   if (!errorcount)
2339     {
2340       /* This must be run always, because it is needed to compute the FP
2341          predefined macros, such as __LDBL_MAX__, for targets using non
2342          default FP formats.  */
2343       init_adjust_machine_modes ();
2344
2345       /* Set up the back-end if requested.  */
2346       if (!no_backend)
2347         backend_init ();
2348
2349       /* Language-dependent initialization.  Returns true on success.  */
2350       if (lang_dependent_init (main_input_filename))
2351         compile_file ();
2352
2353       finalize ();
2354     }
2355
2356   /* Stop timing and print the times.  */
2357   timevar_stop (TV_TOTAL);
2358   timevar_print (stderr);
2359 }
2360
2361 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2362    Exit code is FATAL_EXIT_CODE if can't open files or if there were
2363    any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2364
2365    It is not safe to call this function more than once.  */
2366
2367 int
2368 toplev_main (int argc, char **argv)
2369 {
2370   expandargv (&argc, &argv);
2371
2372   save_argv = CONST_CAST2 (const char **, char **, argv);
2373
2374   /* Initialization of GCC's environment, and diagnostics.  */
2375   general_init (argv[0]);
2376
2377   /* Parse the options and do minimal processing; basically just
2378      enough to default flags appropriately.  */
2379   decode_options (argc, CONST_CAST2 (const char **, char **, argv));
2380
2381   init_local_tick ();
2382
2383   initialize_plugins ();
2384
2385   if (version_flag)
2386     print_version (stderr, "");
2387
2388   if (help_flag)
2389     print_plugins_help (stderr, "");
2390
2391   /* Exit early if we can (e.g. -help).  */
2392   if (!exit_after_options)
2393     do_compile ();
2394
2395   if (warningcount || errorcount) 
2396     print_ignored_options ();
2397
2398   /* Invoke registered plugin callbacks if any.  */
2399   invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2400
2401   finalize_plugins ();
2402   if (errorcount || sorrycount)
2403     return (FATAL_EXIT_CODE);
2404
2405   return (SUCCESS_EXIT_CODE);
2406 }