OSDN Git Service

1dbe25dc5ca45ccd985e988347357d2c845b6518
[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 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
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 "dwarf2asm.h"
70 #include "integrate.h"
71 #include "real.h"
72 #include "debug.h"
73 #include "target.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
76 #include "cfgloop.h"
77 #include "hosthooks.h"
78 #include "cgraph.h"
79 #include "opts.h"
80 #include "coverage.h"
81 #include "value-prof.h"
82 #include "alloc-pool.h"
83
84 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
85 #include "dwarf2out.h"
86 #endif
87
88 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
89 #include "dbxout.h"
90 #endif
91
92 #ifdef SDB_DEBUGGING_INFO
93 #include "sdbout.h"
94 #endif
95
96 #ifdef XCOFF_DEBUGGING_INFO
97 #include "xcoffout.h"           /* Needed for external data
98                                    declarations for e.g. AIX 4.x.  */
99 #endif
100
101 static void general_init (const char *);
102 static void do_compile (void);
103 static void process_options (void);
104 static void backend_init (void);
105 static int lang_dependent_init (const char *);
106 static void init_asm_output (const char *);
107 static void finalize (void);
108
109 static void crash_signal (int) ATTRIBUTE_NORETURN;
110 static void setup_core_dumping (void);
111 static void compile_file (void);
112
113 static int print_single_switch (FILE *, int, int, const char *,
114                                 const char *, const char *,
115                                 const char *, const char *);
116 static void print_switch_values (FILE *, int, int, const char *,
117                                  const char *, const char *);
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 #ifndef USE_MAPPED_LOCATION
142 location_t unknown_location = { NULL, 0 };
143 #endif
144
145 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
146    to optimize and default_debug_hooks in process_options ().  */
147 #define AUTODETECT_FLAG_VAR_TRACKING 2
148
149 /* Current position in real source file.  */
150
151 location_t input_location;
152
153 struct line_maps line_table;
154
155 /* Nonzero if it is unsafe to create any new pseudo registers.  */
156 int no_new_pseudos;
157
158 /* Stack of currently pending input files.  */
159
160 struct file_stack *input_file_stack;
161
162 /* Incremented on each change to input_file_stack.  */
163 int input_file_stack_tick;
164
165 /* Name to use as base of names for dump output files.  */
166
167 const char *dump_base_name;
168
169 /* Name to use as a base for auxiliary output files.  */
170
171 const char *aux_base_name;
172
173 /* Bit flags that specify the machine subtype we are compiling for.
174    Bits are tested using macros TARGET_... defined in the tm.h file
175    and set by `-m...' switches.  Must be defined in rtlanal.c.  */
176
177 extern int target_flags;
178
179 /* A mask of target_flags that includes bit X if X was set or cleared
180    on the command line.  */
181
182 int target_flags_explicit;
183
184 /* Debug hooks - dependent upon command line options.  */
185
186 const struct gcc_debug_hooks *debug_hooks;
187
188 /* Debug hooks - target default.  */
189
190 static const struct gcc_debug_hooks *default_debug_hooks;
191
192 /* Other flags saying which kinds of debugging dump have been requested.  */
193
194 int rtl_dump_and_exit;
195 int flag_print_asm_name;
196 enum graph_dump_types graph_dump_format;
197
198 /* Name for output file of assembly code, specified with -o.  */
199
200 const char *asm_file_name;
201
202 /* Nonzero means do optimizations.  -O.
203    Particular numeric values stand for particular amounts of optimization;
204    thus, -O2 stores 2 here.  However, the optimizations beyond the basic
205    ones are not controlled directly by this variable.  Instead, they are
206    controlled by individual `flag_...' variables that are defaulted
207    based on this variable.  */
208
209 int optimize = 0;
210
211 /* Nonzero means optimize for size.  -Os.
212    The only valid values are zero and nonzero. When optimize_size is
213    nonzero, optimize defaults to 2, but certain individual code
214    bloating optimizations are disabled.  */
215
216 int optimize_size = 0;
217
218 /* The FUNCTION_DECL for the function currently being compiled,
219    or 0 if between functions.  */
220 tree current_function_decl;
221
222 /* Set to the FUNC_BEGIN label of the current function, or NULL
223    if none.  */
224 const char * current_function_func_begin_label;
225
226 /* Temporarily suppress certain warnings.
227    This is set while reading code from a system header file.  */
228
229 int in_system_header = 0;
230
231 /* Nonzero means to collect statistics which might be expensive
232    and to print them when we are done.  */
233 int flag_detailed_statistics = 0;
234
235 /* A random sequence of characters, unless overridden by user.  */
236 const char *flag_random_seed;
237
238 /* A local time stamp derived from the time of compilation. It will be
239    zero if the system cannot provide a time.  It will be -1u, if the
240    user has specified a particular random seed.  */
241 unsigned local_tick;
242
243 /* -f flags.  */
244
245 /* Nonzero means `char' should be signed.  */
246
247 int flag_signed_char;
248
249 /* Nonzero means give an enum type only as many bytes as it needs.  A value
250    of 2 means it has not yet been initialized.  */
251
252 int flag_short_enums;
253
254 /* Nonzero if structures and unions should be returned in memory.
255
256    This should only be defined if compatibility with another compiler or
257    with an ABI is needed, because it results in slower code.  */
258
259 #ifndef DEFAULT_PCC_STRUCT_RETURN
260 #define DEFAULT_PCC_STRUCT_RETURN 1
261 #endif
262
263 /* Nonzero for -fpcc-struct-return: return values the same way PCC does.  */
264
265 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
266
267 /* 0 means straightforward implementation of complex divide acceptable.
268    1 means wide ranges of inputs must work for complex divide.
269    2 means C99-like requirements for complex divide (not yet implemented).  */
270
271 int flag_complex_divide_method = 0;
272
273 /* Nonzero means performs web construction pass.  When flag_web ==
274    AUTODETECT_FLAG_VAR_TRACKING it will be set according to optimize
275    and default_debug_hooks in process_options ().  */
276
277 int flag_web = AUTODETECT_FLAG_VAR_TRACKING;
278
279 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
280    not just because the tree inliner turned us off.  */
281
282 int flag_really_no_inline = 2;
283
284 /* Nonzero means we should be saving declaration info into a .X file.  */
285
286 int flag_gen_aux_info = 0;
287
288 /* Specified name of aux-info file.  */
289
290 const char *aux_info_file_name;
291
292 /* Nonzero if we are compiling code for a shared library, zero for
293    executable.  */
294
295 int flag_shlib;
296
297 /* Set to the default thread-local storage (tls) model to use.  */
298
299 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
300
301 /* Nonzero means change certain warnings into errors.
302    Usually these are warnings about failure to conform to some standard.  */
303
304 int flag_pedantic_errors = 0;
305
306 /* -dA causes debug commentary information to be produced in
307    the generated assembly code (to make it more readable).  This option
308    is generally only of use to those who actually need to read the
309    generated assembly code (perhaps while debugging the compiler itself).
310    Currently, this switch is only used by dwarfout.c; however, it is intended
311    to be a catchall for printing debug information in the assembler file.  */
312
313 int flag_debug_asm = 0;
314
315 /* -dP causes the rtl to be emitted as a comment in assembly.  */
316
317 int flag_dump_rtl_in_asm = 0;
318
319 /* When non-NULL, indicates that whenever space is allocated on the
320    stack, the resulting stack pointer must not pass this
321    address---that is, for stacks that grow downward, the stack pointer
322    must always be greater than or equal to this address; for stacks
323    that grow upward, the stack pointer must be less than this address.
324    At present, the rtx may be either a REG or a SYMBOL_REF, although
325    the support provided depends on the backend.  */
326 rtx stack_limit_rtx;
327
328 /* If one, renumber instruction UIDs to reduce the number of
329    unused UIDs if there are a lot of instructions.  If greater than
330    one, unconditionally renumber instruction UIDs.  */
331 int flag_renumber_insns = 1;
332
333 /* Nonzero if we should track variables.  When
334    flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING it will be set according
335    to optimize, debug_info_level and debug_hooks in process_options ().  */
336 int flag_var_tracking = AUTODETECT_FLAG_VAR_TRACKING;
337
338 /* True if the user has tagged the function with the 'section'
339    attribute.  */
340
341 bool user_defined_section_attribute = false;
342
343 /* Values of the -falign-* flags: how much to align labels in code.
344    0 means `use default', 1 means `don't align'.
345    For each variable, there is an _log variant which is the power
346    of two not less than the variable, for .align output.  */
347
348 int align_loops_log;
349 int align_loops_max_skip;
350 int align_jumps_log;
351 int align_jumps_max_skip;
352 int align_labels_log;
353 int align_labels_max_skip;
354 int align_functions_log;
355
356 /* Like align_functions_log above, but used by front-ends to force the
357    minimum function alignment.  Zero means no alignment is forced.  */
358 int force_align_functions_log;
359
360 typedef struct
361 {
362   const char *const string;
363   int *const variable;
364   const int on_value;
365 }
366 lang_independent_options;
367
368 /* Nonzero if subexpressions must be evaluated from left-to-right.  */
369 int flag_evaluation_order = 0;
370
371 /* The user symbol prefix after having resolved same.  */
372 const char *user_label_prefix;
373
374 static const param_info lang_independent_params[] = {
375 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
376   { OPTION, DEFAULT, HELP },
377 #include "params.def"
378 #undef DEFPARAM
379   { NULL, 0, NULL }
380 };
381
382 /* Here is a table, controlled by the tm.h file, listing each -m switch
383    and which bits in `target_switches' it should set or clear.
384    If VALUE is positive, it is bits to set.
385    If VALUE is negative, -VALUE is bits to clear.
386    (The sign bit is not used so there is no confusion.)  */
387
388 static const struct
389 {
390   const char *const name;
391   const int value;
392   const char *const description;
393 }
394 target_switches[] = TARGET_SWITCHES;
395
396 /* This table is similar, but allows the switch to have a value.  */
397
398 #ifdef TARGET_OPTIONS
399 static const struct
400 {
401   const char *const prefix;
402   const char **const variable;
403   const char *const description;
404   const char *const value;
405 }
406 target_options[] = TARGET_OPTIONS;
407 #endif
408
409 /* Nonzero means warn about function definitions that default the return type
410    or that use a null return and have a return-type other than void.  */
411
412 int warn_return_type;
413
414 /* Output files for assembler code (real compiler output)
415    and debugging dumps.  */
416
417 FILE *asm_out_file;
418 FILE *aux_info_file;
419 FILE *dump_file = NULL;
420 char *dump_file_name;
421
422 /* The current working directory of a translation.  It's generally the
423    directory from which compilation was initiated, but a preprocessed
424    file may specify the original directory in which it was
425    created.  */
426
427 static const char *src_pwd;
428
429 /* Initialize src_pwd with the given string, and return true.  If it
430    was already initialized, return false.  As a special case, it may
431    be called with a NULL argument to test whether src_pwd has NOT been
432    initialized yet.  */
433
434 bool
435 set_src_pwd (const char *pwd)
436 {
437   if (src_pwd)
438     {
439       if (strcmp (src_pwd, pwd) == 0)
440         return true;
441       else
442         return false;
443     }
444
445   src_pwd = xstrdup (pwd);
446   return true;
447 }
448
449 /* Return the directory from which the translation unit was initiated,
450    in case set_src_pwd() was not called before to assign it a
451    different value.  */
452
453 const char *
454 get_src_pwd (void)
455 {
456   if (! src_pwd)
457     src_pwd = getpwd ();
458
459    return src_pwd;
460 }
461
462 /* Called when the start of a function definition is parsed,
463    this function prints on stderr the name of the function.  */
464 void
465 announce_function (tree decl)
466 {
467   if (!quiet_flag)
468     {
469       if (rtl_dump_and_exit)
470         verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
471       else
472         verbatim (" %s", lang_hooks.decl_printable_name (decl, 2));
473       fflush (stderr);
474       pp_needs_newline (global_dc->printer) = true;
475       diagnostic_set_last_function (global_dc);
476     }
477 }
478
479 /* Set up a default flag_random_seed and local_tick, unless the user
480    already specified one.  */
481
482 static void
483 randomize (void)
484 {
485   if (!flag_random_seed)
486     {
487       unsigned HOST_WIDE_INT value;
488       static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
489
490       /* Get some more or less random data.  */
491 #ifdef HAVE_GETTIMEOFDAY
492       {
493         struct timeval tv;
494
495         gettimeofday (&tv, NULL);
496         local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
497       }
498 #else
499       {
500         time_t now = time (NULL);
501
502         if (now != (time_t)-1)
503           local_tick = (unsigned) now;
504       }
505 #endif
506       value = local_tick ^ getpid ();
507
508       sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
509       flag_random_seed = random_seed;
510     }
511   else if (!local_tick)
512     local_tick = -1;
513 }
514
515
516 /* Decode the string P as an integral parameter.
517    If the string is indeed an integer return its numeric value else
518    issue an Invalid Option error for the option PNAME and return DEFVAL.
519    If PNAME is zero just return DEFVAL, do not call error.  */
520
521 int
522 read_integral_parameter (const char *p, const char *pname, const int  defval)
523 {
524   const char *endp = p;
525
526   while (*endp)
527     {
528       if (ISDIGIT (*endp))
529         endp++;
530       else
531         break;
532     }
533
534   if (*endp != 0)
535     {
536       if (pname != 0)
537         error ("invalid option argument `%s'", pname);
538       return defval;
539     }
540
541   return atoi (p);
542 }
543
544 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
545    If X is 0, return -1.
546
547    This should be used via the floor_log2 macro.  */
548
549 int
550 floor_log2_wide (unsigned HOST_WIDE_INT x)
551 {
552   int t=0;
553   if (x == 0)
554     return -1;
555   if (sizeof (HOST_WIDE_INT) * 8 > 64)
556     if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
557       t += 64;
558   if (sizeof (HOST_WIDE_INT) * 8 > 32)
559     if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
560       t += 32;
561   if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
562     t += 16;
563   if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
564     t += 8;
565   if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
566     t += 4;
567   if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
568     t += 2;
569   if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
570     t += 1;
571   return t;
572 }
573
574 /* Return the logarithm of X, base 2, considering X unsigned,
575    if X is a power of 2.  Otherwise, returns -1.
576
577    This should be used via the `exact_log2' macro.  */
578
579 int
580 exact_log2_wide (unsigned HOST_WIDE_INT x)
581 {
582   /* Test for 0 or a power of 2.  */
583   if (x == 0 || x != (x & -x))
584     return -1;
585   return floor_log2_wide (x);
586 }
587
588 /* Handler for fatal signals, such as SIGSEGV.  These are transformed
589    into ICE messages, which is much more user friendly.  In case the
590    error printer crashes, reset the signal to prevent infinite recursion.  */
591
592 static void
593 crash_signal (int signo)
594 {
595   signal (signo, SIG_DFL);
596
597   /* If we crashed while processing an ASM statement, then be a little more
598      graceful.  It's most likely the user's fault.  */
599   if (this_is_asm_operands)
600     {
601       output_operand_lossage ("unrecoverable error");
602       exit (FATAL_EXIT_CODE);
603     }
604
605   internal_error ("%s", strsignal (signo));
606 }
607
608 /* Arrange to dump core on error.  (The regular error message is still
609    printed first, except in the case of abort().)  */
610
611 static void
612 setup_core_dumping (void)
613 {
614 #ifdef SIGABRT
615   signal (SIGABRT, SIG_DFL);
616 #endif
617 #if defined(HAVE_SETRLIMIT)
618   {
619     struct rlimit rlim;
620     if (getrlimit (RLIMIT_CORE, &rlim) != 0)
621       fatal_error ("getting core file size maximum limit: %m");
622     rlim.rlim_cur = rlim.rlim_max;
623     if (setrlimit (RLIMIT_CORE, &rlim) != 0)
624       fatal_error ("setting core file size limit to maximum: %m");
625   }
626 #endif
627   diagnostic_abort_on_error (global_dc);
628 }
629
630
631 /* Strip off a legitimate source ending from the input string NAME of
632    length LEN.  Rather than having to know the names used by all of
633    our front ends, we strip off an ending of a period followed by
634    up to five characters.  (Java uses ".class".)  */
635
636 void
637 strip_off_ending (char *name, int len)
638 {
639   int i;
640   for (i = 2; i < 6 && len > i; i++)
641     {
642       if (name[len - i] == '.')
643         {
644           name[len - i] = '\0';
645           break;
646         }
647     }
648 }
649
650 /* Output a quoted string.  */
651
652 void
653 output_quoted_string (FILE *asm_file, const char *string)
654 {
655 #ifdef OUTPUT_QUOTED_STRING
656   OUTPUT_QUOTED_STRING (asm_file, string);
657 #else
658   char c;
659
660   putc ('\"', asm_file);
661   while ((c = *string++) != 0)
662     {
663       if (ISPRINT (c))
664         {
665           if (c == '\"' || c == '\\')
666             putc ('\\', asm_file);
667           putc (c, asm_file);
668         }
669       else
670         fprintf (asm_file, "\\%03o", (unsigned char) c);
671     }
672   putc ('\"', asm_file);
673 #endif
674 }
675
676 /* Output a file name in the form wanted by System V.  */
677
678 void
679 output_file_directive (FILE *asm_file, const char *input_name)
680 {
681   int len;
682   const char *na;
683
684   if (input_name == NULL)
685     input_name = "<stdin>";
686
687   len = strlen (input_name);
688   na = input_name + len;
689
690   /* NA gets INPUT_NAME sans directory names.  */
691   while (na > input_name)
692     {
693       if (IS_DIR_SEPARATOR (na[-1]))
694         break;
695       na--;
696     }
697
698 #ifdef ASM_OUTPUT_SOURCE_FILENAME
699   ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
700 #else
701   fprintf (asm_file, "\t.file\t");
702   output_quoted_string (asm_file, na);
703   fputc ('\n', asm_file);
704 #endif
705 }
706
707 /* Do any final processing required for the declarations in VEC, of
708    which there are LEN.  We write out inline functions and variables
709    that have been deferred until this point, but which are required.
710    Returns nonzero if anything was put out.  */
711
712 int
713 wrapup_global_declarations (tree *vec, int len)
714 {
715   tree decl;
716   int i;
717   int reconsider;
718   int output_something = 0;
719
720   for (i = 0; i < len; i++)
721     {
722       decl = vec[i];
723
724       /* We're not deferring this any longer.  Assignment is
725          conditional to avoid needlessly dirtying PCH pages.  */
726       if (DECL_DEFER_OUTPUT (decl) != 0)
727         DECL_DEFER_OUTPUT (decl) = 0;
728
729       if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
730         lang_hooks.finish_incomplete_decl (decl);
731     }
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 = 0;
739       for (i = 0; i < len; i++)
740         {
741           decl = vec[i];
742
743           if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
744             continue;
745
746           /* Don't write out static consts, unless we still need them.
747
748              We also keep static consts if not optimizing (for debugging),
749              unless the user specified -fno-keep-static-consts.
750              ??? They might be better written into the debug information.
751              This is possible when using DWARF.
752
753              A language processor that wants static constants to be always
754              written out (even if it is not used) is responsible for
755              calling rest_of_decl_compilation itself.  E.g. the C front-end
756              calls rest_of_decl_compilation from finish_decl.
757              One motivation for this is that is conventional in some
758              environments to write things like:
759              static const char rcsid[] = "... version string ...";
760              intending to force the string to be in the executable.
761
762              A language processor that would prefer to have unneeded
763              static constants "optimized away" would just defer writing
764              them out until here.  E.g. C++ does this, because static
765              constants are often defined in header files.
766
767              ??? A tempting alternative (for both C and C++) would be
768              to force a constant to be written if and only if it is
769              defined in a main file, as opposed to an include file.  */
770
771           if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
772             {
773               struct cgraph_varpool_node *node;
774               bool needed = 1;
775               node = cgraph_varpool_node (decl);
776
777               if (flag_unit_at_a_time && node->finalized)
778                 needed = 0;
779               else if ((flag_unit_at_a_time && !cgraph_global_info_ready)
780                        && (TREE_USED (decl)
781                            || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
782                 /* needed */;
783               else if (node->needed)
784                 /* needed */;
785               else if (DECL_COMDAT (decl))
786                 needed = 0;
787               else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
788                        && (optimize || !flag_keep_static_consts
789                            || DECL_ARTIFICIAL (decl)))
790                 needed = 0;
791
792               if (needed)
793                 {
794                   reconsider = 1;
795                   rest_of_decl_compilation (decl, 1, 1);
796                 }
797             }
798         }
799
800       if (reconsider)
801         output_something = 1;
802     }
803   while (reconsider);
804
805   return output_something;
806 }
807
808 /* Issue appropriate warnings for the global declarations in VEC (of
809    which there are LEN).  Output debugging information for them.  */
810
811 void
812 check_global_declarations (tree *vec, int len)
813 {
814   tree decl;
815   int i;
816
817   for (i = 0; i < len; i++)
818     {
819       decl = vec[i];
820
821       if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
822           && ! TREE_ASM_WRITTEN (decl))
823         /* Cancel the RTL for this decl so that, if debugging info
824            output for global variables is still to come,
825            this one will be omitted.  */
826         SET_DECL_RTL (decl, NULL_RTX);
827
828       /* Warn about any function
829          declared static but not defined.
830          We don't warn about variables,
831          because many programs have static variables
832          that exist only to get some text into the object file.  */
833       if (TREE_CODE (decl) == FUNCTION_DECL
834           && DECL_INITIAL (decl) == 0
835           && DECL_EXTERNAL (decl)
836           && ! DECL_ARTIFICIAL (decl)
837           && ! TREE_NO_WARNING (decl)
838           && ! TREE_PUBLIC (decl)
839           && (warn_unused_function
840               || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
841         {
842           if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
843             pedwarn ("%J'%F' used but never defined", decl, decl);
844           else
845             warning ("%J'%F' declared `static' but never defined", decl, decl);
846           /* This symbol is effectively an "extern" declaration now.  */
847           TREE_PUBLIC (decl) = 1;
848           assemble_external (decl);
849         }
850
851       /* Warn about static fns or vars defined but not used.  */
852       if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
853            /* We don't warn about "static const" variables because the
854               "rcs_id" idiom uses that construction.  */
855            || (warn_unused_variable
856                && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
857           && ! DECL_IN_SYSTEM_HEADER (decl)
858           && ! TREE_USED (decl)
859           /* The TREE_USED bit for file-scope decls is kept in the identifier,
860              to handle multiple external decls in different scopes.  */
861           && ! TREE_USED (DECL_NAME (decl))
862           && ! DECL_EXTERNAL (decl)
863           && ! TREE_PUBLIC (decl)
864           /* A volatile variable might be used in some non-obvious way.  */
865           && ! TREE_THIS_VOLATILE (decl)
866           /* Global register variables must be declared to reserve them.  */
867           && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
868           /* Otherwise, ask the language.  */
869           && lang_hooks.decls.warn_unused_global (decl))
870         warning ("%J'%D' defined but not used", decl, decl);
871
872       /* Avoid confusing the debug information machinery when there are
873          errors.  */
874       if (errorcount == 0 && sorrycount == 0)
875         {
876           timevar_push (TV_SYMOUT);
877           (*debug_hooks->global_decl) (decl);
878           timevar_pop (TV_SYMOUT);
879         }
880     }
881 }
882
883 /* Warn about a use of an identifier which was marked deprecated.  */
884 void
885 warn_deprecated_use (tree node)
886 {
887   if (node == 0 || !warn_deprecated_decl)
888     return;
889
890   if (DECL_P (node))
891     {
892       expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
893       warning ("`%s' is deprecated (declared at %s:%d)",
894                IDENTIFIER_POINTER (DECL_NAME (node)),
895                xloc.file, xloc.line);
896     }
897   else if (TYPE_P (node))
898     {
899       const char *what = NULL;
900       tree decl = TYPE_STUB_DECL (node);
901
902       if (TYPE_NAME (node))
903         {
904           if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
905             what = IDENTIFIER_POINTER (TYPE_NAME (node));
906           else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
907                    && DECL_NAME (TYPE_NAME (node)))
908             what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
909         }
910
911       if (decl)
912         {
913           expanded_location xloc
914             = expand_location (DECL_SOURCE_LOCATION (decl));
915           if (what)
916             warning ("`%s' is deprecated (declared at %s:%d)", what,
917                        xloc.file, xloc.line);
918           else
919             warning ("type is deprecated (declared at %s:%d)",
920                      xloc.file, xloc.line);
921         }
922       else
923         {
924           if (what)
925             warning ("`%s' is deprecated", what);
926           else
927             warning ("type is deprecated");
928         }
929     }
930 }
931
932 /* Save the current INPUT_LOCATION on the top entry in the
933    INPUT_FILE_STACK.  Push a new entry for FILE and LINE, and set the
934    INPUT_LOCATION accordingly.  */
935
936 void
937 #ifdef USE_MAPPED_LOCATION
938 push_srcloc (location_t fline)
939 #else
940 push_srcloc (const char *file, int line)
941 #endif
942 {
943   struct file_stack *fs;
944
945   fs = xmalloc (sizeof (struct file_stack));
946   fs->location = input_location;
947   fs->next = input_file_stack;
948 #ifdef USE_MAPPED_LOCATION
949   input_location = fline;
950 #else
951   input_filename = file;
952   input_line = line;
953 #endif
954   input_file_stack = fs;
955   input_file_stack_tick++;
956 }
957
958 /* Pop the top entry off the stack of presently open source files.
959    Restore the INPUT_LOCATION from the new topmost entry on the
960    stack.  */
961
962 void
963 pop_srcloc (void)
964 {
965   struct file_stack *fs;
966
967   fs = input_file_stack;
968   input_location = fs->location;
969   input_file_stack = fs->next;
970   free (fs);
971   input_file_stack_tick++;
972 }
973
974 /* Compile an entire translation unit.  Write a file of assembly
975    output and various debugging dumps.  */
976
977 static void
978 compile_file (void)
979 {
980   /* Initialize yet another pass.  */
981
982   init_cgraph ();
983   init_final (main_input_filename);
984   coverage_init (aux_base_name);
985
986   timevar_push (TV_PARSE);
987
988   /* Call the parser, which parses the entire file (calling
989      rest_of_compilation for each function).  */
990   lang_hooks.parse_file (set_yydebug);
991
992   /* In case there were missing block closers,
993      get us back to the global binding level.  */
994   lang_hooks.clear_binding_stack ();
995
996   /* Compilation is now finished except for writing
997      what's left of the symbol table output.  */
998   timevar_pop (TV_PARSE);
999
1000   if (flag_syntax_only)
1001     return;
1002
1003   lang_hooks.decls.final_write_globals ();
1004
1005   cgraph_varpool_assemble_pending_decls ();
1006
1007   /* This must occur after the loop to output deferred functions.
1008      Else the coverage initializer would not be emitted if all the
1009      functions in this compilation unit were deferred.  */
1010   coverage_finish ();
1011
1012   /* Write out any pending weak symbol declarations.  */
1013
1014   weak_finish ();
1015
1016   /* Do dbx symbols.  */
1017   timevar_push (TV_SYMOUT);
1018
1019 #ifdef DWARF2_UNWIND_INFO
1020   if (dwarf2out_do_frame ())
1021     dwarf2out_frame_finish ();
1022 #endif
1023
1024   (*debug_hooks->finish) (main_input_filename);
1025   timevar_pop (TV_SYMOUT);
1026
1027   /* Output some stuff at end of file if nec.  */
1028
1029   dw2_output_indirect_constants ();
1030
1031   /* Attach a special .ident directive to the end of the file to identify
1032      the version of GCC which compiled this code.  The format of the .ident
1033      string is patterned after the ones produced by native SVR4 compilers.  */
1034 #ifdef IDENT_ASM_OP
1035   if (!flag_no_ident)
1036     fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1037              IDENT_ASM_OP, version_string);
1038 #endif
1039
1040   /* This must be at the end.  Some target ports emit end of file directives
1041      into the assembly file here, and hence we can not output anything to the
1042      assembly file after this point.  */
1043   targetm.asm_out.file_end ();
1044 }
1045
1046 /* Display help for target options.  */
1047 void
1048 display_target_options (void)
1049 {
1050   int undoc, i;
1051   static bool displayed = false;
1052
1053   /* Avoid double printing for --help --target-help.  */
1054   if (displayed)
1055     return;
1056
1057   displayed = true;
1058
1059   if (ARRAY_SIZE (target_switches) > 1
1060 #ifdef TARGET_OPTIONS
1061       || ARRAY_SIZE (target_options) > 1
1062 #endif
1063       )
1064     {
1065       int doc = 0;
1066
1067       undoc = 0;
1068
1069       printf (_("\nTarget specific options:\n"));
1070
1071       for (i = ARRAY_SIZE (target_switches); i--;)
1072         {
1073           const char *option      = target_switches[i].name;
1074           const char *description = target_switches[i].description;
1075
1076           if (option == NULL || *option == 0)
1077             continue;
1078           else if (description == NULL)
1079             {
1080               undoc = 1;
1081
1082               if (extra_warnings)
1083                 printf (_("  -m%-23s [undocumented]\n"), option);
1084             }
1085           else if (*description != 0)
1086             doc += printf ("  -m%-23s %s\n", option, _(description));
1087         }
1088
1089 #ifdef TARGET_OPTIONS
1090       for (i = ARRAY_SIZE (target_options); i--;)
1091         {
1092           const char *option      = target_options[i].prefix;
1093           const char *description = target_options[i].description;
1094
1095           if (option == NULL || *option == 0)
1096             continue;
1097           else if (description == NULL)
1098             {
1099               undoc = 1;
1100
1101               if (extra_warnings)
1102                 printf (_("  -m%-23s [undocumented]\n"), option);
1103             }
1104           else if (*description != 0)
1105             doc += printf ("  -m%-23s %s\n", option, _(description));
1106         }
1107 #endif
1108       if (undoc)
1109         {
1110           if (doc)
1111             printf (_("\nThere are undocumented target specific options as well.\n"));
1112           else
1113             printf (_("  They exist, but they are not documented.\n"));
1114         }
1115     }
1116 }
1117
1118 /* Parse a -d... command line switch.  */
1119
1120 void
1121 decode_d_option (const char *arg)
1122 {
1123   int c;
1124
1125   while (*arg)
1126     switch (c = *arg++)
1127       {
1128       case 'A':
1129         flag_debug_asm = 1;
1130         break;
1131       case 'p':
1132         flag_print_asm_name = 1;
1133         break;
1134       case 'P':
1135         flag_dump_rtl_in_asm = 1;
1136         flag_print_asm_name = 1;
1137         break;
1138       case 'v':
1139         graph_dump_format = vcg;
1140         break;
1141       case 'x':
1142         rtl_dump_and_exit = 1;
1143         break;
1144       case 'y':
1145         set_yydebug = 1;
1146         break;
1147       case 'D': /* These are handled by the preprocessor.  */
1148       case 'I':
1149         break;
1150       case 'H':
1151         setup_core_dumping();
1152         break;
1153
1154       case 'a':
1155       default:
1156         if (!enable_rtl_dump_file (c))
1157           warning ("unrecognized gcc debugging option: %c", c);
1158         break;
1159       }
1160 }
1161
1162 /* Indexed by enum debug_info_type.  */
1163 const char *const debug_type_names[] =
1164 {
1165   "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
1166 };
1167
1168 /* Decode -m switches.  */
1169 /* Decode the switch -mNAME.  */
1170
1171 void
1172 set_target_switch (const char *name)
1173 {
1174   size_t j;
1175   int valid_target_option = 0;
1176
1177   for (j = 0; j < ARRAY_SIZE (target_switches); j++)
1178     if (!strcmp (target_switches[j].name, name))
1179       {
1180         if (target_switches[j].value < 0)
1181           target_flags &= ~-target_switches[j].value;
1182         else
1183           target_flags |= target_switches[j].value;
1184         if (name[0] != 0)
1185           {
1186             if (target_switches[j].value < 0)
1187               target_flags_explicit |= -target_switches[j].value;
1188             else
1189               target_flags_explicit |= target_switches[j].value;
1190           }
1191         valid_target_option = 1;
1192       }
1193
1194 #ifdef TARGET_OPTIONS
1195   if (!valid_target_option)
1196     for (j = 0; j < ARRAY_SIZE (target_options); j++)
1197       {
1198         int len = strlen (target_options[j].prefix);
1199         if (target_options[j].value)
1200           {
1201             if (!strcmp (target_options[j].prefix, name))
1202               {
1203                 *target_options[j].variable = target_options[j].value;
1204                 valid_target_option = 1;
1205               }
1206           }
1207         else
1208           {
1209             if (!strncmp (target_options[j].prefix, name, len))
1210               {
1211                 *target_options[j].variable = name + len;
1212                 valid_target_option = 1;
1213               }
1214           }
1215       }
1216 #endif
1217
1218   if (!valid_target_option)
1219     error ("invalid option `%s'", name);
1220 }
1221
1222 /* Print version information to FILE.
1223    Each line begins with INDENT (for the case where FILE is the
1224    assembler output file).  */
1225
1226 void
1227 print_version (FILE *file, const char *indent)
1228 {
1229 #ifndef __VERSION__
1230 #define __VERSION__ "[?]"
1231 #endif
1232   fnotice (file,
1233 #ifdef __GNUC__
1234            "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
1235 #else
1236            "%s%s%s version %s (%s) compiled by CC.\n"
1237 #endif
1238            , indent, *indent != 0 ? " " : "",
1239            lang_hooks.name, version_string, TARGET_NAME,
1240            indent, __VERSION__);
1241   fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
1242            indent, *indent != 0 ? " " : "",
1243            PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1244 }
1245
1246 /* Print an option value and return the adjusted position in the line.
1247    ??? We don't handle error returns from fprintf (disk full); presumably
1248    other code will catch a disk full though.  */
1249
1250 static int
1251 print_single_switch (FILE *file, int pos, int max,
1252                      const char *indent, const char *sep, const char *term,
1253                      const char *type, const char *name)
1254 {
1255   /* The ultrix fprintf returns 0 on success, so compute the result we want
1256      here since we need it for the following test.  */
1257   int len = strlen (sep) + strlen (type) + strlen (name);
1258
1259   if (pos != 0
1260       && pos + len > max)
1261     {
1262       fprintf (file, "%s", term);
1263       pos = 0;
1264     }
1265   if (pos == 0)
1266     {
1267       fprintf (file, "%s", indent);
1268       pos = strlen (indent);
1269     }
1270   fprintf (file, "%s%s%s", sep, type, name);
1271   pos += len;
1272   return pos;
1273 }
1274
1275 /* Print active target switches to FILE.
1276    POS is the current cursor position and MAX is the size of a "line".
1277    Each line begins with INDENT and ends with TERM.
1278    Each switch is separated from the next by SEP.  */
1279
1280 static void
1281 print_switch_values (FILE *file, int pos, int max,
1282                      const char *indent, const char *sep, const char *term)
1283 {
1284   size_t j;
1285   const char **p;
1286
1287   /* Fill in the -frandom-seed option, if the user didn't pass it, so
1288      that it can be printed below.  This helps reproducibility.  */
1289   randomize ();
1290
1291   /* Print the options as passed.  */
1292   pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
1293                              _("options passed: "), "");
1294
1295   for (p = &save_argv[1]; *p != NULL; p++)
1296     if (**p == '-')
1297       {
1298         /* Ignore these.  */
1299         if (strcmp (*p, "-o") == 0)
1300           {
1301             if (p[1] != NULL)
1302               p++;
1303             continue;
1304           }
1305         if (strcmp (*p, "-quiet") == 0)
1306           continue;
1307         if (strcmp (*p, "-version") == 0)
1308           continue;
1309         if ((*p)[1] == 'd')
1310           continue;
1311
1312         pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
1313       }
1314   if (pos > 0)
1315     fprintf (file, "%s", term);
1316
1317   /* Print the -f and -m options that have been enabled.
1318      We don't handle language specific options but printing argv
1319      should suffice.  */
1320
1321   pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
1322                              _("options enabled: "), "");
1323
1324   for (j = 0; j < cl_options_count; j++)
1325     {
1326       if (!cl_options[j].flag_var
1327           || !(cl_options[j].flags & CL_REPORT))
1328         continue;
1329
1330       if (cl_options[j].has_set_value)
1331         {
1332           if (*cl_options[j].flag_var != cl_options[j].set_value)
1333             continue;
1334         }
1335       else
1336         {
1337           if (!*cl_options[j].flag_var)
1338             continue;
1339         }
1340       
1341       pos = print_single_switch (file, pos, max, indent, sep, term,
1342                                  "", cl_options[j].opt_text);
1343     }
1344
1345   /* Print target specific options.  */
1346
1347   for (j = 0; j < ARRAY_SIZE (target_switches); j++)
1348     if (target_switches[j].name[0] != '\0'
1349         && target_switches[j].value > 0
1350         && ((target_switches[j].value & target_flags)
1351             == target_switches[j].value))
1352       {
1353         pos = print_single_switch (file, pos, max, indent, sep, term,
1354                                    "-m", target_switches[j].name);
1355       }
1356
1357 #ifdef TARGET_OPTIONS
1358   for (j = 0; j < ARRAY_SIZE (target_options); j++)
1359     if (*target_options[j].variable != NULL)
1360       {
1361         char prefix[256];
1362         sprintf (prefix, "-m%s", target_options[j].prefix);
1363         pos = print_single_switch (file, pos, max, indent, sep, term,
1364                                    prefix, *target_options[j].variable);
1365       }
1366 #endif
1367
1368   fprintf (file, "%s", term);
1369 }
1370
1371 /* Open assembly code output file.  Do this even if -fsyntax-only is
1372    on, because then the driver will have provided the name of a
1373    temporary file or bit bucket for us.  NAME is the file specified on
1374    the command line, possibly NULL.  */
1375 static void
1376 init_asm_output (const char *name)
1377 {
1378   if (name == NULL && asm_file_name == 0)
1379     asm_out_file = stdout;
1380   else
1381     {
1382       if (asm_file_name == 0)
1383         {
1384           int len = strlen (dump_base_name);
1385           char *dumpname = xmalloc (len + 6);
1386           memcpy (dumpname, dump_base_name, len + 1);
1387           strip_off_ending (dumpname, len);
1388           strcat (dumpname, ".s");
1389           asm_file_name = dumpname;
1390         }
1391       if (!strcmp (asm_file_name, "-"))
1392         asm_out_file = stdout;
1393       else
1394         asm_out_file = fopen (asm_file_name, "w+b");
1395       if (asm_out_file == 0)
1396         fatal_error ("can't open %s for writing: %m", asm_file_name);
1397     }
1398
1399 #ifdef IO_BUFFER_SIZE
1400   setvbuf (asm_out_file, xmalloc (IO_BUFFER_SIZE),
1401            _IOFBF, IO_BUFFER_SIZE);
1402 #endif
1403
1404   if (!flag_syntax_only)
1405     {
1406       targetm.asm_out.file_start ();
1407
1408 #ifdef ASM_COMMENT_START
1409       if (flag_verbose_asm)
1410         {
1411           /* Print the list of options in effect.  */
1412           print_version (asm_out_file, ASM_COMMENT_START);
1413           print_switch_values (asm_out_file, 0, MAX_LINE,
1414                                ASM_COMMENT_START, " ", "\n");
1415           /* Add a blank line here so it appears in assembler output but not
1416              screen output.  */
1417           fprintf (asm_out_file, "\n");
1418         }
1419 #endif
1420     }
1421 }
1422
1423 /* Default version of get_pch_validity.
1424    By default, every flag difference is fatal; that will be mostly right for
1425    most targets, but completely right for very few.  */
1426
1427 void *
1428 default_get_pch_validity (size_t *len)
1429 {
1430 #ifdef TARGET_OPTIONS
1431   size_t i;
1432 #endif
1433   char *result, *r;
1434
1435   *len = sizeof (target_flags) + 2;
1436 #ifdef TARGET_OPTIONS
1437   for (i = 0; i < ARRAY_SIZE (target_options); i++)
1438     {
1439       *len += 1;
1440       if (*target_options[i].variable)
1441         *len += strlen (*target_options[i].variable);
1442     }
1443 #endif
1444
1445   result = r = xmalloc (*len);
1446   r[0] = flag_pic;
1447   r[1] = flag_pie;
1448   r += 2;
1449   memcpy (r, &target_flags, sizeof (target_flags));
1450   r += sizeof (target_flags);
1451
1452 #ifdef TARGET_OPTIONS
1453   for (i = 0; i < ARRAY_SIZE (target_options); i++)
1454     {
1455       const char *str = *target_options[i].variable;
1456       size_t l;
1457       if (! str)
1458         str = "";
1459       l = strlen (str) + 1;
1460       memcpy (r, str, l);
1461       r += l;
1462     }
1463 #endif
1464
1465   return result;
1466 }
1467
1468 /* Default version of pch_valid_p.  */
1469
1470 const char *
1471 default_pch_valid_p (const void *data_p, size_t len)
1472 {
1473   const char *data = (const char *)data_p;
1474   const char *flag_that_differs = NULL;
1475   size_t i;
1476
1477   /* -fpic and -fpie also usually make a PCH invalid.  */
1478   if (data[0] != flag_pic)
1479     return _("created and used with different settings of -fpic");
1480   if (data[1] != flag_pie)
1481     return _("created and used with different settings of -fpie");
1482   data += 2;
1483
1484   /* Check target_flags.  */
1485   if (memcmp (data, &target_flags, sizeof (target_flags)) != 0)
1486     {
1487       for (i = 0; i < ARRAY_SIZE (target_switches); i++)
1488         {
1489           int bits;
1490           int tf;
1491
1492           memcpy (&tf, data, sizeof (target_flags));
1493
1494           bits = target_switches[i].value;
1495           if (bits < 0)
1496             bits = -bits;
1497           if ((target_flags & bits) != (tf & bits))
1498             {
1499               flag_that_differs = target_switches[i].name;
1500               goto make_message;
1501             }
1502         }
1503       gcc_unreachable ();
1504     }
1505   data += sizeof (target_flags);
1506   len -= sizeof (target_flags);
1507
1508   /* Check string options.  */
1509 #ifdef TARGET_OPTIONS
1510   for (i = 0; i < ARRAY_SIZE (target_options); i++)
1511     {
1512       const char *str = *target_options[i].variable;
1513       size_t l;
1514       if (! str)
1515         str = "";
1516       l = strlen (str) + 1;
1517       if (len < l || memcmp (data, str, l) != 0)
1518         {
1519           flag_that_differs = target_options[i].prefix;
1520           goto make_message;
1521         }
1522       data += l;
1523       len -= l;
1524     }
1525 #endif
1526
1527   return NULL;
1528
1529  make_message:
1530   {
1531     char *r;
1532     asprintf (&r, _("created and used with differing settings of `-m%s'"),
1533                   flag_that_differs);
1534     if (r == NULL)
1535       return _("out of memory");
1536     return r;
1537   }
1538 }
1539
1540 /* Default tree printer.   Handles declarations only.  */
1541 static bool
1542 default_tree_printer (pretty_printer * pp, text_info *text)
1543 {
1544   switch (*text->format_spec)
1545     {
1546     case 'D':
1547     case 'F':
1548     case 'T':
1549       {
1550         tree t = va_arg (*text->args_ptr, tree);
1551         const char *n = DECL_NAME (t)
1552           ? lang_hooks.decl_printable_name (t, 2)
1553           : "<anonymous>";
1554         pp_string (pp, n);
1555       }
1556       return true;
1557
1558     default:
1559       return false;
1560     }
1561 }
1562
1563 /* Initialization of the front end environment, before command line
1564    options are parsed.  Signal handlers, internationalization etc.
1565    ARGV0 is main's argv[0].  */
1566 static void
1567 general_init (const char *argv0)
1568 {
1569   const char *p;
1570
1571   p = argv0 + strlen (argv0);
1572   while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1573     --p;
1574   progname = p;
1575
1576   xmalloc_set_program_name (progname);
1577
1578   hex_init ();
1579
1580   gcc_init_libintl ();
1581
1582   /* Initialize the diagnostics reporting machinery, so option parsing
1583      can give warnings and errors.  */
1584   diagnostic_initialize (global_dc);
1585   /* Set a default printer.  Language specific initializations will
1586      override it later.  */
1587   pp_format_decoder (global_dc->printer) = &default_tree_printer;
1588
1589   /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages.  */
1590 #ifdef SIGSEGV
1591   signal (SIGSEGV, crash_signal);
1592 #endif
1593 #ifdef SIGILL
1594   signal (SIGILL, crash_signal);
1595 #endif
1596 #ifdef SIGBUS
1597   signal (SIGBUS, crash_signal);
1598 #endif
1599 #ifdef SIGABRT
1600   signal (SIGABRT, crash_signal);
1601 #endif
1602 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1603   signal (SIGIOT, crash_signal);
1604 #endif
1605 #ifdef SIGFPE
1606   signal (SIGFPE, crash_signal);
1607 #endif
1608
1609   /* Other host-specific signal setup.  */
1610   (*host_hooks.extra_signals)();
1611
1612   /* Initialize the garbage-collector, string pools and tree type hash
1613      table.  */
1614   init_ggc ();
1615   init_stringpool ();
1616   linemap_init (&line_table);
1617   init_ttree ();
1618
1619   /* Initialize register usage now so switches may override.  */
1620   init_reg_sets ();
1621
1622   /* Register the language-independent parameters.  */
1623   add_params (lang_independent_params, LAST_PARAM);
1624
1625   /* This must be done after add_params but before argument processing.  */
1626   init_ggc_heuristics();
1627   init_tree_optimization_passes ();
1628 }
1629
1630 /* Process the options that have been parsed.  */
1631 static void
1632 process_options (void)
1633 {
1634   /* Allow the front end to perform consistency checks and do further
1635      initialization based on the command line options.  This hook also
1636      sets the original filename if appropriate (e.g. foo.i -> foo.c)
1637      so we can correctly initialize debug output.  */
1638   no_backend = lang_hooks.post_options (&main_input_filename);
1639 #ifndef USE_MAPPED_LOCATION
1640   input_filename = main_input_filename;
1641 #endif
1642
1643 #ifdef OVERRIDE_OPTIONS
1644   /* Some machines may reject certain combinations of options.  */
1645   OVERRIDE_OPTIONS;
1646 #endif
1647
1648   if (flag_short_enums == 2)
1649     flag_short_enums = targetm.default_short_enums ();
1650
1651   /* Set aux_base_name if not already set.  */
1652   if (aux_base_name)
1653     ;
1654   else if (main_input_filename)
1655     {
1656       char *name = xstrdup (lbasename (main_input_filename));
1657
1658       strip_off_ending (name, strlen (name));
1659       aux_base_name = name;
1660     }
1661   else
1662     aux_base_name = "gccaux";
1663
1664   /* Set up the align_*_log variables, defaulting them to 1 if they
1665      were still unset.  */
1666   if (align_loops <= 0) align_loops = 1;
1667   if (align_loops_max_skip > align_loops || !align_loops)
1668     align_loops_max_skip = align_loops - 1;
1669   align_loops_log = floor_log2 (align_loops * 2 - 1);
1670   if (align_jumps <= 0) align_jumps = 1;
1671   if (align_jumps_max_skip > align_jumps || !align_jumps)
1672     align_jumps_max_skip = align_jumps - 1;
1673   align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1674   if (align_labels <= 0) align_labels = 1;
1675   align_labels_log = floor_log2 (align_labels * 2 - 1);
1676   if (align_labels_max_skip > align_labels || !align_labels)
1677     align_labels_max_skip = align_labels - 1;
1678   if (align_functions <= 0) align_functions = 1;
1679   align_functions_log = floor_log2 (align_functions * 2 - 1);
1680
1681   /* Unrolling all loops implies that standard loop unrolling must also
1682      be done.  */
1683   if (flag_unroll_all_loops)
1684     flag_unroll_loops = 1;
1685
1686   /* The loop unrolling code assumes that cse will be run after loop.  */
1687   if (flag_unroll_loops || flag_peel_loops)
1688     flag_rerun_cse_after_loop = 1;
1689
1690   /* If explicitly asked to run new loop optimizer, switch off the old
1691      one.  */
1692   if (flag_loop_optimize2)
1693     flag_loop_optimize = 0;
1694
1695   /* Enable new loop optimizer pass if any of its optimizations is called.  */
1696   if (flag_move_loop_invariants
1697       || flag_unswitch_loops
1698       || flag_peel_loops
1699       || flag_unroll_loops
1700       || flag_branch_on_count_reg)
1701     flag_loop_optimize2 = 1;
1702
1703   if (flag_non_call_exceptions)
1704     flag_asynchronous_unwind_tables = 1;
1705   if (flag_asynchronous_unwind_tables)
1706     flag_unwind_tables = 1;
1707
1708   /* Disable unit-at-a-time mode for frontends not supporting callgraph
1709      interface.  */
1710   if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
1711     flag_unit_at_a_time = 0;
1712
1713   if (flag_value_profile_transformations)
1714     flag_profile_values = 1;
1715
1716   /* Speculative prefetching implies the value profiling.  We also switch off
1717      the prefetching in the loop optimizer, so that we do not emit double
1718      prefetches.  TODO -- we should teach these two to cooperate; the loop
1719      based prefetching may sometimes do a better job, especially in connection
1720      with reuse analysis.  */
1721   if (flag_speculative_prefetching)
1722     {
1723       flag_profile_values = 1;
1724       flag_prefetch_loop_arrays = 0;
1725     }
1726
1727   /* Warn about options that are not supported on this machine.  */
1728 #ifndef INSN_SCHEDULING
1729   if (flag_schedule_insns || flag_schedule_insns_after_reload)
1730     warning ("instruction scheduling not supported on this target machine");
1731 #endif
1732 #ifndef DELAY_SLOTS
1733   if (flag_delayed_branch)
1734     warning ("this target machine does not have delayed branches");
1735 #endif
1736
1737   if (flag_tree_based_profiling && flag_profile_values)
1738     sorry ("value-based profiling not yet implemented in trees.");
1739
1740   user_label_prefix = USER_LABEL_PREFIX;
1741   if (flag_leading_underscore != -1)
1742     {
1743       /* If the default prefix is more complicated than "" or "_",
1744          issue a warning and ignore this option.  */
1745       if (user_label_prefix[0] == 0 ||
1746           (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1747         {
1748           user_label_prefix = flag_leading_underscore ? "_" : "";
1749         }
1750       else
1751         warning ("-f%sleading-underscore not supported on this target machine",
1752                  flag_leading_underscore ? "" : "no-");
1753     }
1754
1755   /* If we are in verbose mode, write out the version and maybe all the
1756      option flags in use.  */
1757   if (version_flag)
1758     {
1759       print_version (stderr, "");
1760       if (! quiet_flag)
1761         print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
1762     }
1763
1764   if (flag_syntax_only)
1765     {
1766       write_symbols = NO_DEBUG;
1767       profile_flag = 0;
1768     }
1769
1770   /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1771      level is 0.  */
1772   if (debug_info_level == DINFO_LEVEL_NONE)
1773     write_symbols = NO_DEBUG;
1774
1775   /* Now we know write_symbols, set up the debug hooks based on it.
1776      By default we do nothing for debug output.  */
1777   if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG)
1778     default_debug_hooks = &do_nothing_debug_hooks;
1779 #if defined(DBX_DEBUGGING_INFO)
1780   else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG)
1781     default_debug_hooks = &dbx_debug_hooks;
1782 #endif
1783 #if defined(XCOFF_DEBUGGING_INFO)
1784   else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG)
1785     default_debug_hooks = &xcoff_debug_hooks;
1786 #endif
1787 #ifdef SDB_DEBUGGING_INFO
1788   else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG)
1789     default_debug_hooks = &sdb_debug_hooks;
1790 #endif
1791 #ifdef DWARF2_DEBUGGING_INFO
1792   else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG)
1793     default_debug_hooks = &dwarf2_debug_hooks;
1794 #endif
1795 #ifdef VMS_DEBUGGING_INFO
1796   else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG
1797            || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG)
1798     default_debug_hooks = &vmsdbg_debug_hooks;
1799 #endif
1800
1801   debug_hooks = &do_nothing_debug_hooks;
1802   if (write_symbols == NO_DEBUG)
1803     ;
1804 #if defined(DBX_DEBUGGING_INFO)
1805   else if (write_symbols == DBX_DEBUG)
1806     debug_hooks = &dbx_debug_hooks;
1807 #endif
1808 #if defined(XCOFF_DEBUGGING_INFO)
1809   else if (write_symbols == XCOFF_DEBUG)
1810     debug_hooks = &xcoff_debug_hooks;
1811 #endif
1812 #ifdef SDB_DEBUGGING_INFO
1813   else if (write_symbols == SDB_DEBUG)
1814     debug_hooks = &sdb_debug_hooks;
1815 #endif
1816 #ifdef DWARF2_DEBUGGING_INFO
1817   else if (write_symbols == DWARF2_DEBUG)
1818     debug_hooks = &dwarf2_debug_hooks;
1819 #endif
1820 #ifdef VMS_DEBUGGING_INFO
1821   else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1822     debug_hooks = &vmsdbg_debug_hooks;
1823 #endif
1824   else
1825     error ("target system does not support the \"%s\" debug format",
1826            debug_type_names[write_symbols]);
1827
1828   /* Now we know which debug output will be used so we can set
1829      flag_var_tracking, flag_rename_registers and flag_web if the user has
1830      not specified them.  */
1831   if (debug_info_level < DINFO_LEVEL_NORMAL
1832       || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1833     {
1834       if (flag_var_tracking == 1)
1835         {
1836           if (debug_info_level < DINFO_LEVEL_NORMAL)
1837             warning ("variable tracking requested, but useless unless "
1838                      "producing debug info");
1839           else
1840             warning ("variable tracking requested, but not supported "
1841                      "by this debug format");
1842         }
1843       flag_var_tracking = 0;
1844     }
1845
1846   if (flag_rename_registers == AUTODETECT_FLAG_VAR_TRACKING)
1847     flag_rename_registers = default_debug_hooks->var_location
1848                             != do_nothing_debug_hooks.var_location;
1849
1850   if (flag_web == AUTODETECT_FLAG_VAR_TRACKING)
1851     flag_web = optimize >= 2 && (default_debug_hooks->var_location
1852                                  != do_nothing_debug_hooks.var_location);
1853
1854   if (flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING)
1855     flag_var_tracking = optimize >= 1;
1856
1857   /* If auxiliary info generation is desired, open the output file.
1858      This goes in the same directory as the source file--unlike
1859      all the other output files.  */
1860   if (flag_gen_aux_info)
1861     {
1862       aux_info_file = fopen (aux_info_file_name, "w");
1863       if (aux_info_file == 0)
1864         fatal_error ("can't open %s: %m", aux_info_file_name);
1865     }
1866
1867   if (! targetm.have_named_sections)
1868     {
1869       if (flag_function_sections)
1870         {
1871           warning ("-ffunction-sections not supported for this target");
1872           flag_function_sections = 0;
1873         }
1874       if (flag_data_sections)
1875         {
1876           warning ("-fdata-sections not supported for this target");
1877           flag_data_sections = 0;
1878         }
1879     }
1880
1881   if (flag_function_sections && profile_flag)
1882     {
1883       warning ("-ffunction-sections disabled; it makes profiling impossible");
1884       flag_function_sections = 0;
1885     }
1886
1887 #ifndef HAVE_prefetch
1888   if (flag_prefetch_loop_arrays)
1889     {
1890       warning ("-fprefetch-loop-arrays not supported for this target");
1891       flag_prefetch_loop_arrays = 0;
1892     }
1893   if (flag_speculative_prefetching)
1894     {
1895       if (flag_speculative_prefetching_set)
1896         warning ("-fspeculative-prefetching not supported for this target");
1897       flag_speculative_prefetching = 0;
1898     }
1899 #else
1900   if (flag_prefetch_loop_arrays && !HAVE_prefetch)
1901     {
1902       warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
1903       flag_prefetch_loop_arrays = 0;
1904     }
1905   if (flag_speculative_prefetching && !HAVE_prefetch)
1906     {
1907       if (flag_speculative_prefetching_set)
1908         warning ("-fspeculative-prefetching not supported for this target (try -march switches)");
1909       flag_speculative_prefetching = 0;
1910     }
1911 #endif
1912
1913   /* This combination of options isn't handled for i386 targets and doesn't
1914      make much sense anyway, so don't allow it.  */
1915   if (flag_prefetch_loop_arrays && optimize_size)
1916     {
1917       warning ("-fprefetch-loop-arrays is not supported with -Os");
1918       flag_prefetch_loop_arrays = 0;
1919     }
1920
1921 #ifndef OBJECT_FORMAT_ELF
1922   if (flag_function_sections && write_symbols != NO_DEBUG)
1923     warning ("-ffunction-sections may affect debugging on some targets");
1924 #endif
1925
1926   /* The presence of IEEE signaling NaNs, implies all math can trap.  */
1927   if (flag_signaling_nans)
1928     flag_trapping_math = 1;
1929 }
1930
1931 /* Initialize the compiler back end.  */
1932 static void
1933 backend_init (void)
1934 {
1935   init_adjust_machine_modes ();
1936
1937   init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
1938                   || debug_info_level == DINFO_LEVEL_VERBOSE
1939 #ifdef VMS_DEBUGGING_INFO
1940                     /* Enable line number info for traceback.  */
1941                     || debug_info_level > DINFO_LEVEL_NONE
1942 #endif
1943                     || flag_test_coverage);
1944
1945   init_regs ();
1946   init_fake_stack_mems ();
1947   init_alias_once ();
1948   init_loop ();
1949   init_reload ();
1950   init_function_once ();
1951   init_varasm_once ();
1952
1953   /* The following initialization functions need to generate rtl, so
1954      provide a dummy function context for them.  */
1955   init_dummy_function_start ();
1956   init_expmed ();
1957   if (flag_caller_saves)
1958     init_caller_save ();
1959   expand_dummy_function_end ();
1960 }
1961
1962 /* Language-dependent initialization.  Returns nonzero on success.  */
1963 static int
1964 lang_dependent_init (const char *name)
1965 {
1966   location_t save_loc = input_location;
1967   if (dump_base_name == 0)
1968     dump_base_name = name && name[0] ? name : "gccdump";
1969
1970   /* Other front-end initialization.  */
1971 #ifdef USE_MAPPED_LOCATION
1972   input_location = BUILTINS_LOCATION;
1973 #else
1974   input_filename = "<built-in>";
1975   input_line = 0;
1976 #endif
1977   if (lang_hooks.init () == 0)
1978     return 0;
1979   input_location = save_loc;
1980
1981   init_asm_output (name);
1982
1983   /* These create various _DECL nodes, so need to be called after the
1984      front end is initialized.  */
1985   init_eh ();
1986   init_optabs ();
1987
1988   /* The following initialization functions need to generate rtl, so
1989      provide a dummy function context for them.  */
1990   init_dummy_function_start ();
1991   init_expr_once ();
1992   expand_dummy_function_end ();
1993
1994   /* If dbx symbol table desired, initialize writing it and output the
1995      predefined types.  */
1996   timevar_push (TV_SYMOUT);
1997
1998 #ifdef DWARF2_UNWIND_INFO
1999   if (dwarf2out_do_frame ())
2000     dwarf2out_frame_init ();
2001 #endif
2002
2003   /* Now we have the correct original filename, we can initialize
2004      debug output.  */
2005   (*debug_hooks->init) (name);
2006
2007   timevar_pop (TV_SYMOUT);
2008
2009   return 1;
2010 }
2011
2012 /* Clean up: close opened files, etc.  */
2013
2014 static void
2015 finalize (void)
2016 {
2017   /* Close the dump files.  */
2018   if (flag_gen_aux_info)
2019     {
2020       fclose (aux_info_file);
2021       if (errorcount)
2022         unlink (aux_info_file_name);
2023     }
2024
2025   /* Close non-debugging input and output files.  Take special care to note
2026      whether fclose returns an error, since the pages might still be on the
2027      buffer chain while the file is open.  */
2028
2029   if (asm_out_file)
2030     {
2031       if (ferror (asm_out_file) != 0)
2032         fatal_error ("error writing to %s: %m", asm_file_name);
2033       if (fclose (asm_out_file) != 0)
2034         fatal_error ("error closing %s: %m", asm_file_name);
2035     }
2036
2037   finish_optimization_passes ();
2038
2039   if (mem_report)
2040     {
2041       ggc_print_statistics ();
2042       stringpool_statistics ();
2043       dump_tree_statistics ();
2044       dump_rtx_statistics ();
2045       dump_varray_statistics ();
2046       dump_alloc_pool_statistics ();
2047       dump_ggc_loc_statistics ();
2048     }
2049
2050   /* Free up memory for the benefit of leak detectors.  */
2051   free_reg_info ();
2052
2053   /* Language-specific end of compilation actions.  */
2054   lang_hooks.finish ();
2055 }
2056
2057 /* Initialize the compiler, and compile the input file.  */
2058 static void
2059 do_compile (void)
2060 {
2061   /* Initialize timing first.  The C front ends read the main file in
2062      the post_options hook, and C++ does file timings.  */
2063   if (time_report || !quiet_flag  || flag_detailed_statistics)
2064     timevar_init ();
2065   timevar_start (TV_TOTAL);
2066
2067   process_options ();
2068
2069   /* Don't do any more if an error has already occurred.  */
2070   if (!errorcount)
2071     {
2072       /* Set up the back-end if requested.  */
2073       if (!no_backend)
2074         backend_init ();
2075
2076       /* Language-dependent initialization.  Returns true on success.  */
2077       if (lang_dependent_init (main_input_filename))
2078         compile_file ();
2079
2080       finalize ();
2081     }
2082
2083   /* Stop timing and print the times.  */
2084   timevar_stop (TV_TOTAL);
2085   timevar_print (stderr);
2086 }
2087
2088 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2089    Exit code is FATAL_EXIT_CODE if can't open files or if there were
2090    any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2091
2092    It is not safe to call this function more than once.  */
2093
2094 int
2095 toplev_main (unsigned int argc, const char **argv)
2096 {
2097   save_argv = argv;
2098
2099   /* Initialization of GCC's environment, and diagnostics.  */
2100   general_init (argv[0]);
2101
2102   /* Parse the options and do minimal processing; basically just
2103      enough to default flags appropriately.  */
2104   decode_options (argc, argv);
2105
2106   randomize ();
2107
2108   /* Exit early if we can (e.g. -help).  */
2109   if (!exit_after_options)
2110     do_compile ();
2111
2112   if (errorcount || sorrycount)
2113     return (FATAL_EXIT_CODE);
2114
2115   return (SUCCESS_EXIT_CODE);
2116 }