OSDN Git Service

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