OSDN Git Service

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