OSDN Git Service

2004-04-05 Caroline Tice <ctice@apple.com>
[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 "rtl.h"
47 #include "tm_p.h"
48 #include "flags.h"
49 #include "insn-attr.h"
50 #include "insn-config.h"
51 #include "insn-flags.h"
52 #include "hard-reg-set.h"
53 #include "recog.h"
54 #include "output.h"
55 #include "except.h"
56 #include "function.h"
57 #include "toplev.h"
58 #include "expr.h"
59 #include "basic-block.h"
60 #include "intl.h"
61 #include "ggc.h"
62 #include "graph.h"
63 #include "loop.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 /* Current position in real source file.  */
142
143 location_t input_location;
144
145 struct line_maps line_table;
146
147 /* Nonzero if it is unsafe to create any new pseudo registers.  */
148 int no_new_pseudos;
149
150 /* Stack of currently pending input files.  */
151
152 struct file_stack *input_file_stack;
153
154 /* Incremented on each change to input_file_stack.  */
155 int input_file_stack_tick;
156
157 /* Name to use as base of names for dump output files.  */
158
159 const char *dump_base_name;
160
161 /* Name to use as a base for auxiliary output files.  */
162
163 const char *aux_base_name;
164
165 /* Bit flags that specify the machine subtype we are compiling for.
166    Bits are tested using macros TARGET_... defined in the tm.h file
167    and set by `-m...' switches.  Must be defined in rtlanal.c.  */
168
169 extern int target_flags;
170
171 /* A mask of target_flags that includes bit X if X was set or cleared
172    on the command line.  */
173
174 int target_flags_explicit;
175
176 /* Debug hooks - dependent upon command line options.  */
177
178 const struct gcc_debug_hooks *debug_hooks;
179
180 /* Other flags saying which kinds of debugging dump have been requested.  */
181
182 int rtl_dump_and_exit;
183 int flag_print_asm_name;
184 enum graph_dump_types graph_dump_format;
185
186 /* Name for output file of assembly code, specified with -o.  */
187
188 const char *asm_file_name;
189
190 /* Nonzero means do optimizations.  -O.
191    Particular numeric values stand for particular amounts of optimization;
192    thus, -O2 stores 2 here.  However, the optimizations beyond the basic
193    ones are not controlled directly by this variable.  Instead, they are
194    controlled by individual `flag_...' variables that are defaulted
195    based on this variable.  */
196
197 int optimize = 0;
198
199 /* Nonzero means optimize for size.  -Os.
200    The only valid values are zero and nonzero. When optimize_size is
201    nonzero, optimize defaults to 2, but certain individual code
202    bloating optimizations are disabled.  */
203
204 int optimize_size = 0;
205
206 /* The FUNCTION_DECL for the function currently being compiled,
207    or 0 if between functions.  */
208 tree current_function_decl;
209
210 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
211    if none.  */
212 tree current_function_func_begin_label;
213
214 /* Nonzero if doing dwarf2 duplicate elimination.  */
215
216 int flag_eliminate_dwarf2_dups = 0;
217
218 /* Nonzero if doing unused type elimination.  */
219
220 int flag_eliminate_unused_debug_types = 1;
221
222 /* Nonzero means emit debugging information only for symbols which are used.  */
223 int flag_debug_only_used_symbols = 0;
224
225 /* Nonzero if generating code to do profiling.  */
226
227 int profile_flag = 0;
228
229 /* Nonzero if generating code to profile program flow graph arcs.  */
230
231 int profile_arc_flag = 0;
232
233 /* Nonzero if value histograms should be measured.  */
234
235 int flag_profile_values = 0;
236
237 /* Nonzero if value histograms should be used to optimize code.  */
238 int flag_value_profile_transformations = 0;
239
240 /* Nonzero if generating info for gcov to calculate line test coverage.  */
241
242 int flag_test_coverage = 0;
243
244 /* Nonzero indicates that branch taken probabilities should be calculated.  */
245
246 int flag_branch_probabilities = 0;
247
248 /* Nonzero if basic blocks should be reordered.  */
249
250 int flag_reorder_blocks = 0;
251
252 /* Nonzero if functions should be reordered.  */
253
254 int flag_reorder_functions = 0;
255
256 /* Nonzero if registers should be renamed.  */
257
258 int flag_rename_registers = 0;
259 int flag_cprop_registers = 0;
260
261 /* Nonzero for -pedantic switch: warn about anything
262    that standard spec forbids.  */
263
264 int pedantic = 0;
265
266 /* Temporarily suppress certain warnings.
267    This is set while reading code from a system header file.  */
268
269 int in_system_header = 0;
270
271 /* Don't print functions as they are compiled.  -quiet.  */
272
273 int quiet_flag = 0;
274
275 /* Print times taken by the various passes.  -ftime-report.  */
276
277 int time_report = 0;
278
279 /* Print memory still in use at end of compilation (which may have little
280    to do with peak memory consumption).  -fmem-report.  */
281
282 int mem_report = 0;
283
284 /* Nonzero means to collect statistics which might be expensive
285    and to print them when we are done.  */
286 int flag_detailed_statistics = 0;
287
288 /* A random sequence of characters, unless overridden by user.  */
289 const char *flag_random_seed;
290
291 /* A local time stamp derived from the time of compilation. It will be
292    zero if the system cannot provide a time.  It will be -1u, if the
293    user has specified a particular random seed.  */
294 unsigned local_tick;
295
296 /* -f flags.  */
297
298 /* Nonzero means `char' should be signed.  */
299
300 int flag_signed_char;
301
302 /* Nonzero means give an enum type only as many bytes as it needs.  */
303
304 int flag_short_enums;
305
306 /* Nonzero for -fcaller-saves: allocate values in regs that need to
307    be saved across function calls, if that produces overall better code.
308    Optional now, so people can test it.  */
309
310 int flag_caller_saves = 0;
311
312 /* Nonzero if structures and unions should be returned in memory.
313
314    This should only be defined if compatibility with another compiler or
315    with an ABI is needed, because it results in slower code.  */
316
317 #ifndef DEFAULT_PCC_STRUCT_RETURN
318 #define DEFAULT_PCC_STRUCT_RETURN 1
319 #endif
320
321 /* Nonzero for -fpcc-struct-return: return values the same way PCC does.  */
322
323 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
324
325 /* Nonzero for -fforce-mem: load memory value into a register
326    before arithmetic on it.  This makes better cse but slower compilation.  */
327
328 int flag_force_mem = 0;
329
330 /* Nonzero for -fforce-addr: load memory address into a register before
331    reference to memory.  This makes better cse but slower compilation.  */
332
333 int flag_force_addr = 0;
334
335 /* Nonzero for -fdefer-pop: don't pop args after each function call;
336    instead save them up to pop many calls' args with one insns.  */
337
338 int flag_defer_pop = 0;
339
340 /* Nonzero for -ffloat-store: don't allocate floats and doubles
341    in extended-precision registers.  */
342
343 int flag_float_store = 0;
344
345 /* Nonzero for -fcse-follow-jumps:
346    have cse follow jumps to do a more extensive job.  */
347
348 int flag_cse_follow_jumps;
349
350 /* Nonzero for -fcse-skip-blocks:
351    have cse follow a branch around a block.  */
352 int flag_cse_skip_blocks;
353
354 /* Nonzero for -fexpensive-optimizations:
355    perform miscellaneous relatively-expensive optimizations.  */
356 int flag_expensive_optimizations;
357
358 /* Nonzero for -fthread-jumps:
359    have jump optimize output of loop.  */
360
361 int flag_thread_jumps;
362
363 /* Nonzero enables strength-reduction in loop.c.  */
364
365 int flag_strength_reduce = 0;
366
367 /* Nonzero enables loop unrolling in unroll.c.  Only loops for which the
368    number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
369    UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
370    unrolled.  */
371
372 int flag_old_unroll_loops;
373
374 /* Nonzero enables loop unrolling in unroll.c.  All loops are unrolled.
375    This is generally not a win.  */
376
377 int flag_old_unroll_all_loops;
378
379 /* Enables unrolling of simple loops in loop-unroll.c.  */
380 int flag_unroll_loops;
381
382 /* Enables unrolling of all loops in loop-unroll.c.  */
383 int flag_unroll_all_loops;
384
385 /* Nonzero enables loop peeling.  */
386 int flag_peel_loops;
387
388 /* Nonzero enables loop unswitching.  */
389 int flag_unswitch_loops;
390
391 /* Nonzero enables prefetch optimizations for arrays in loops.  */
392
393 int flag_prefetch_loop_arrays;
394
395 /* Nonzero forces all invariant computations in loops to be moved
396    outside the loop.  */
397
398 int flag_move_all_movables = 0;
399
400 /* Nonzero forces all general induction variables in loops to be
401    strength reduced.  */
402
403 int flag_reduce_all_givs = 0;
404
405 /* Nonzero to perform full register move optimization passes.  This is the
406    default for -O2.  */
407
408 int flag_regmove = 0;
409
410 /* Nonzero means don't put addresses of constant functions in registers.
411    Used for compiling the Unix kernel, where strange substitutions are
412    done on the assembly output.  */
413
414 int flag_no_function_cse = 0;
415
416 /* Nonzero for -fomit-frame-pointer:
417    don't make a frame pointer in simple functions that don't require one.  */
418
419 int flag_omit_frame_pointer = 0;
420
421 /* Nonzero means place each function into its own section on those platforms
422    which support arbitrary section names and unlimited numbers of sections.  */
423
424 int flag_function_sections = 0;
425
426 /* ... and similar for data.  */
427
428 int flag_data_sections = 0;
429
430 /* Nonzero to inhibit use of define_optimization peephole opts.  */
431
432 int flag_no_peephole = 0;
433
434 /* Nonzero allows GCC to optimize sibling and tail recursive calls.  */
435
436 int flag_optimize_sibling_calls = 0;
437
438 /* Nonzero means the front end generally wants `errno' maintained by math
439    operations, like built-in SQRT.  */
440
441 int flag_errno_math = 1;
442
443 /* Nonzero means that unsafe floating-point math optimizations are allowed
444    for the sake of speed.  IEEE compliance is not guaranteed, and operations
445    are allowed to assume that their arguments and results are "normal"
446    (e.g., nonnegative for SQRT).  */
447
448 int flag_unsafe_math_optimizations = 0;
449
450 /* Nonzero means that no NaNs or +-Infs are expected.  */
451
452 int flag_finite_math_only = 0;
453
454 /* Zero means that floating-point math operations cannot generate a
455    (user-visible) trap.  This is the case, for example, in nonstop
456    IEEE 754 arithmetic.  Trapping conditions include division by zero,
457    overflow, underflow, invalid and inexact, but does not include
458    operations on signaling NaNs (see below).  */
459
460 int flag_trapping_math = 1;
461
462 /* Nonzero means disable transformations that assume default floating
463    point rounding behavior.  */
464
465 int flag_rounding_math = 0;
466
467 /* Nonzero means disable transformations observable by signaling NaNs.
468    This option implies that any operation on an IEEE signaling NaN can
469    generate a (user-visible) trap.  */
470
471 int flag_signaling_nans = 0;
472
473 /* 0 means straightforward implementation of complex divide acceptable.
474    1 means wide ranges of inputs must work for complex divide.
475    2 means C99-like requirements for complex divide (not yet implemented).  */
476
477 int flag_complex_divide_method = 0;
478
479 /* Nonzero means just do syntax checking; don't output anything.  */
480
481 int flag_syntax_only = 0;
482
483 /* Nonzero means performs web construction pass.  */
484
485 int flag_web;
486
487 /* Nonzero means perform loop optimizer.  */
488
489 int flag_loop_optimize;
490
491 /* Nonzero means perform crossjumping.  */
492
493 int flag_crossjumping;
494
495 /* Nonzero means perform if conversion.  */
496
497 int flag_if_conversion;
498
499 /* Nonzero means perform if conversion after reload.  */
500
501 int flag_if_conversion2;
502
503 /* Nonzero means to use global dataflow analysis to eliminate
504    useless null pointer tests.  */
505
506 int flag_delete_null_pointer_checks;
507
508 /* Nonzero means perform global CSE.  */
509
510 int flag_gcse = 0;
511
512 /* Nonzero means to do the enhanced load motion during gcse, which trys
513    to hoist loads by not killing them when a store to the same location
514    is seen.  */
515
516 int flag_gcse_lm = 1;
517
518 /* Nonzero means to perform store motion after gcse, which will try to
519    move stores closer to the exit block.  Its not very effective without
520    flag_gcse_lm.  */
521
522 int flag_gcse_sm = 1;
523
524 /* Nonzero if we want to perform redundant load after store elimination
525    in gcse.  */
526
527 int flag_gcse_las = 1;
528
529 /* Nonzero means perform global cse after register allocation.  */
530 int flag_gcse_after_reload = 0;
531
532 /* Perform target register optimization before prologue / epilogue
533    threading.  */
534
535 int flag_branch_target_load_optimize = 0;
536
537 /* Perform target register optimization after prologue / epilogue
538    threading and jump2.  */
539
540 int flag_branch_target_load_optimize2 = 0;
541
542 /* For the bt-load pass, nonzero means don't re-use branch target registers
543    in any basic block.  */
544
545 int flag_btr_bb_exclusive;
546
547 /* Nonzero means to rerun cse after loop optimization.  This increases
548    compilation time about 20% and picks up a few more common expressions.  */
549
550 int flag_rerun_cse_after_loop;
551
552 /* Nonzero means to run loop optimizations twice.  */
553
554 int flag_rerun_loop_opt;
555
556 /* Nonzero for -finline-functions: ok to inline functions that look like
557    good inline candidates.  */
558
559 int flag_inline_functions;
560
561 /* Nonzero for -fkeep-inline-functions: even if we make a function
562    go inline everywhere, keep its definition around for debugging
563    purposes.  */
564
565 int flag_keep_inline_functions;
566
567 /* Nonzero means that functions will not be inlined.  */
568
569 int flag_no_inline = 2;
570
571 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
572    not just because the tree inliner turned us off.  */
573
574 int flag_really_no_inline = 2;
575
576 /* Nonzero means that we should emit static const variables
577    regardless of whether or not optimization is turned on.  */
578
579 int flag_keep_static_consts = 1;
580
581 /* Nonzero means we should be saving declaration info into a .X file.  */
582
583 int flag_gen_aux_info = 0;
584
585 /* Specified name of aux-info file.  */
586
587 const char *aux_info_file_name;
588
589 /* Nonzero means make the text shared if supported.  */
590
591 int flag_shared_data;
592
593 /* Nonzero means schedule into delayed branch slots if supported.  */
594
595 int flag_delayed_branch;
596
597 /* Nonzero if we are compiling pure (sharable) code.
598    Value is 1 if we are doing "small" pic; value is 2 if we're doing
599    "large" pic.  */
600
601 int flag_pic;
602
603 /* Nonzero if we are compiling position independent code for executable.
604    The value is 1 if we are doing "small" pic; value is 2 if we're doing
605    "large" pic.  */
606
607 int flag_pie;
608
609 /* Nonzero if we are compiling code for a shared library, zero for
610    executable.  */
611
612 int flag_shlib;
613
614 /* Set to the default thread-local storage (tls) model to use.  */
615
616 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
617
618 /* Nonzero means generate extra code for exception handling and enable
619    exception handling.  */
620
621 int flag_exceptions;
622
623 /* Nonzero means generate frame unwind info table when supported.  */
624
625 int flag_unwind_tables = 0;
626
627 /* Nonzero means generate frame unwind info table exact at each insn
628    boundary.  */
629
630 int flag_asynchronous_unwind_tables = 0;
631
632 /* Nonzero means don't place uninitialized global data in common storage
633    by default.  */
634
635 int flag_no_common;
636
637 /* Nonzero means change certain warnings into errors.
638    Usually these are warnings about failure to conform to some standard.  */
639
640 int flag_pedantic_errors = 0;
641
642 /* flag_schedule_insns means schedule insns within basic blocks (before
643    local_alloc).
644    flag_schedule_insns_after_reload means schedule insns after
645    global_alloc.  */
646
647 int flag_schedule_insns = 0;
648 int flag_schedule_insns_after_reload = 0;
649
650 /* When flag_schedule_insns_after_reload is set, use EBB scheduler.  */
651 int flag_sched2_use_superblocks = 0;
652
653 /* When flag_schedule_insns_after_reload is set, construct traces and EBB
654    scheduler.  */
655 int flag_sched2_use_traces = 0;
656
657 /* The following flags have effect only for scheduling before register
658    allocation:
659
660    flag_schedule_interblock means schedule insns across basic blocks.
661    flag_schedule_speculative means allow speculative motion of non-load insns.
662    flag_schedule_speculative_load means allow speculative motion of some
663    load insns.
664    flag_schedule_speculative_load_dangerous allows speculative motion of more
665    load insns.  */
666
667 int flag_schedule_interblock = 1;
668 int flag_schedule_speculative = 1;
669 int flag_schedule_speculative_load = 0;
670 int flag_schedule_speculative_load_dangerous = 0;
671
672 /* The following flags have an effect during scheduling after register
673    allocation:
674
675    flag_sched_stalled_insns means that insns can be moved prematurely from the queue
676    of stalled insns into the ready list.
677
678    flag_sched_stalled_insns_dep controls how many insn groups will be examined
679    for a dependency on a stalled insn that is candidate for premature removal
680    from the queue of stalled insns into the ready list (has an effect only if
681    the flag 'sched_stalled_insns' is set).  */
682
683 int flag_sched_stalled_insns = 0;
684 int flag_sched_stalled_insns_dep = 1;
685
686 int flag_single_precision_constant;
687
688 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
689    by a cheaper branch on a count register.  */
690 int flag_branch_on_count_reg = 1;
691
692 /* -finhibit-size-directive inhibits output of .size for ELF.
693    This is used only for compiling crtstuff.c,
694    and it may be extended to other effects
695    needed for crtstuff.c on other systems.  */
696 int flag_inhibit_size_directive = 0;
697
698 /* -fverbose-asm causes extra commentary information to be produced in
699    the generated assembly code (to make it more readable).  This option
700    is generally only of use to those who actually need to read the
701    generated assembly code (perhaps while debugging the compiler itself).
702    -fno-verbose-asm, the default, causes the extra information
703    to be omitted and is useful when comparing two assembler files.  */
704
705 int flag_verbose_asm = 0;
706
707 /* -dA causes debug commentary information to be produced in
708    the generated assembly code (to make it more readable).  This option
709    is generally only of use to those who actually need to read the
710    generated assembly code (perhaps while debugging the compiler itself).
711    Currently, this switch is only used by dwarfout.c; however, it is intended
712    to be a catchall for printing debug information in the assembler file.  */
713
714 int flag_debug_asm = 0;
715
716 /* -dP causes the rtl to be emitted as a comment in assembly.  */
717
718 int flag_dump_rtl_in_asm = 0;
719
720 /* Nonzero means put zero initialized data in the bss section.  */
721 int flag_zero_initialized_in_bss = 1;
722
723 /* Tag all structures with __attribute__(packed).  */
724 int flag_pack_struct = 0;
725
726 /* Emit code to check for stack overflow; also may cause large objects
727    to be allocated dynamically.  */
728 int flag_stack_check;
729
730 /* When non-NULL, indicates that whenever space is allocated on the
731    stack, the resulting stack pointer must not pass this
732    address---that is, for stacks that grow downward, the stack pointer
733    must always be greater than or equal to this address; for stacks
734    that grow upward, the stack pointer must be less than this address.
735    At present, the rtx may be either a REG or a SYMBOL_REF, although
736    the support provided depends on the backend.  */
737 rtx stack_limit_rtx;
738
739 /* 0 if pointer arguments may alias each other.  True in C.
740    1 if pointer arguments may not alias each other but may alias
741    global variables.
742    2 if pointer arguments may not alias each other and may not
743    alias global variables.  True in Fortran.
744    This defaults to 0 for C.  */
745 int flag_argument_noalias = 0;
746
747 /* Nonzero if we should do (language-dependent) alias analysis.
748    Typically, this analysis will assume that expressions of certain
749    types do not alias expressions of certain other types.  Only used
750    if alias analysis (in general) is enabled.  */
751 int flag_strict_aliasing = 0;
752
753 /* Instrument functions with calls at entry and exit, for profiling.  */
754 int flag_instrument_function_entry_exit = 0;
755
756 /* Nonzero means ignore `#ident' directives.  0 means handle them.
757    On SVR4 targets, it also controls whether or not to emit a
758    string identifying the compiler.  */
759
760 int flag_no_ident = 0;
761
762 /* This will perform a peephole pass before sched2.  */
763 int flag_peephole2 = 0;
764
765 /* This will try to guess branch probabilities.  */
766 int flag_guess_branch_prob = 0;
767
768 /* -fcheck-bounds causes gcc to generate array bounds checks.
769    For C, C++, ObjC: defaults to off.
770    For Java: defaults to on.
771    For Fortran: defaults to off.  */
772 int flag_bounds_check = 0;
773
774 /* This will attempt to merge constant section constants, if 1 only
775    string constants and constants from constant pool, if 2 also constant
776    variables.  */
777 int flag_merge_constants = 1;
778
779 /* If one, renumber instruction UIDs to reduce the number of
780    unused UIDs if there are a lot of instructions.  If greater than
781    one, unconditionally renumber instruction UIDs.  */
782 int flag_renumber_insns = 1;
783
784 /* If nonzero, use the graph coloring register allocator.  */
785 int flag_new_regalloc = 0;
786
787 /* Nonzero if we perform superblock formation.  */
788
789 int flag_tracer = 0;
790
791 /* Nonzero if we perform whole unit at a time compilation.  */
792
793 int flag_unit_at_a_time = 0;
794
795 /* Nonzero if we should track variables.  When
796    flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING it will be set according
797    to optimize, debug_info_level and debug_hooks in process_options ().  */
798  
799 #define AUTODETECT_FLAG_VAR_TRACKING 2
800 int flag_var_tracking = AUTODETECT_FLAG_VAR_TRACKING;
801
802 /* Values of the -falign-* flags: how much to align labels in code.
803    0 means `use default', 1 means `don't align'.
804    For each variable, there is an _log variant which is the power
805    of two not less than the variable, for .align output.  */
806
807 int align_loops;
808 int align_loops_log;
809 int align_loops_max_skip;
810 int align_jumps;
811 int align_jumps_log;
812 int align_jumps_max_skip;
813 int align_labels;
814 int align_labels_log;
815 int align_labels_max_skip;
816 int align_functions;
817 int align_functions_log;
818
819 /* Like align_functions_log above, but used by front-ends to force the
820    minimum function alignment.  Zero means no alignment is forced.  */
821 int force_align_functions_log;
822
823 typedef struct
824 {
825   const char *const string;
826   int *const variable;
827   const int on_value;
828 }
829 lang_independent_options;
830
831 /* Nonzero if signed arithmetic overflow should trap.  */
832 int flag_trapv = 0;
833
834 /* Nonzero if signed arithmetic overflow should wrap around.  */
835 int flag_wrapv = 0;
836
837 /* Nonzero if subexpressions must be evaluated from left-to-right.  */
838 int flag_evaluation_order = 0;
839
840 /* Add or remove a leading underscore from user symbols.  */
841 int flag_leading_underscore = -1;
842
843 /*  The version of the C++ ABI in use.  The following values are
844     allowed:
845
846     0: The version of the ABI believed most conformant with the
847        C++ ABI specification.  This ABI may change as bugs are
848        discovered and fixed.  Therefore, 0 will not necessarily
849        indicate the same ABI in different versions of G++.
850
851     1: The version of the ABI first used in G++ 3.2.
852
853     2: The version of the ABI first used in G++ 3.4.
854
855     Additional positive integers will be assigned as new versions of
856     the ABI become the default version of the ABI.  */
857
858 int flag_abi_version = 2;
859
860 /* The user symbol prefix after having resolved same.  */
861 const char *user_label_prefix;
862
863 static const param_info lang_independent_params[] = {
864 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
865   { OPTION, DEFAULT, HELP },
866 #include "params.def"
867 #undef DEFPARAM
868   { NULL, 0, NULL }
869 };
870
871 /* Table of language-independent -f options.
872    STRING is the option name.  VARIABLE is the address of the variable.
873    ON_VALUE is the value to store in VARIABLE
874     if `-fSTRING' is seen as an option.
875    (If `-fno-STRING' is seen as an option, the opposite value is stored.)  */
876
877 static const lang_independent_options f_options[] =
878 {
879   {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1 },
880   {"eliminate-unused-debug-symbols", &flag_debug_only_used_symbols, 1 },
881   {"eliminate-unused-debug-types", &flag_eliminate_unused_debug_types, 1 },
882   {"float-store", &flag_float_store, 1 },
883   {"defer-pop", &flag_defer_pop, 1 },
884   {"omit-frame-pointer", &flag_omit_frame_pointer, 1 },
885   {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1 },
886   {"tracer", &flag_tracer, 1 },
887   {"unit-at-a-time", &flag_unit_at_a_time, 1 },
888   {"cse-follow-jumps", &flag_cse_follow_jumps, 1 },
889   {"cse-skip-blocks", &flag_cse_skip_blocks, 1 },
890   {"expensive-optimizations", &flag_expensive_optimizations, 1 },
891   {"thread-jumps", &flag_thread_jumps, 1 },
892   {"strength-reduce", &flag_strength_reduce, 1 },
893   {"unroll-loops", &flag_unroll_loops, 1 },
894   {"unroll-all-loops", &flag_unroll_all_loops, 1 },
895   {"old-unroll-loops", &flag_old_unroll_loops, 1 },
896   {"old-unroll-all-loops", &flag_old_unroll_all_loops, 1 },
897   {"peel-loops", &flag_peel_loops, 1 },
898   {"unswitch-loops", &flag_unswitch_loops, 1 },
899   {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1 },
900   {"move-all-movables", &flag_move_all_movables, 1 },
901   {"reduce-all-givs", &flag_reduce_all_givs, 1 },
902   {"peephole", &flag_no_peephole, 0 },
903   {"force-mem", &flag_force_mem, 1 },
904   {"force-addr", &flag_force_addr, 1 },
905   {"function-cse", &flag_no_function_cse, 0 },
906   {"inline-functions", &flag_inline_functions, 1 },
907   {"keep-inline-functions", &flag_keep_inline_functions, 1 },
908   {"inline", &flag_no_inline, 0 },
909   {"keep-static-consts", &flag_keep_static_consts, 1 },
910   {"syntax-only", &flag_syntax_only, 1 },
911   {"shared-data", &flag_shared_data, 1 },
912   {"caller-saves", &flag_caller_saves, 1 },
913   {"pcc-struct-return", &flag_pcc_struct_return, 1 },
914   {"reg-struct-return", &flag_pcc_struct_return, 0 },
915   {"delayed-branch", &flag_delayed_branch, 1 },
916   {"web", &flag_web, 1},
917   {"gcse", &flag_gcse, 1 },
918   {"gcse-lm", &flag_gcse_lm, 1 },
919   {"gcse-sm", &flag_gcse_sm, 1 },
920   {"gcse-las", &flag_gcse_las, 1 },
921   {"gcse-after-reload", &flag_gcse_after_reload, 1},
922   {"branch-target-load-optimize", &flag_branch_target_load_optimize, 1 },
923   {"branch-target-load-optimize2", &flag_branch_target_load_optimize2, 1 },
924   {"btr-bb-exclusive", &flag_btr_bb_exclusive, 1 },
925   {"loop-optimize", &flag_loop_optimize, 1 },
926   {"crossjumping", &flag_crossjumping, 1 },
927   {"if-conversion", &flag_if_conversion, 1 },
928   {"if-conversion2", &flag_if_conversion2, 1 },
929   {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1 },
930   {"rerun-loop-opt", &flag_rerun_loop_opt, 1 },
931   {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1 },
932   {"schedule-insns", &flag_schedule_insns, 1 },
933   {"schedule-insns2", &flag_schedule_insns_after_reload, 1 },
934   {"sched-interblock",&flag_schedule_interblock, 1 },
935   {"sched-spec",&flag_schedule_speculative, 1 },
936   {"sched-spec-load",&flag_schedule_speculative_load, 1 },
937   {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1 },
938   {"sched-stalled-insns", &flag_sched_stalled_insns, 0 },
939   {"sched-stalled-insns-dep", &flag_sched_stalled_insns_dep, 1 },
940   {"sched2-use-superblocks", &flag_sched2_use_superblocks, 1 },
941   {"sched2-use-traces", &flag_sched2_use_traces, 1 },
942   {"branch-count-reg",&flag_branch_on_count_reg, 1 },
943   {"pic", &flag_pic, 1 },
944   {"PIC", &flag_pic, 2 },
945   {"pie", &flag_pie, 1 },
946   {"PIE", &flag_pie, 2 },
947   {"exceptions", &flag_exceptions, 1 },
948   {"unwind-tables", &flag_unwind_tables, 1 },
949   {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1 },
950   {"non-call-exceptions", &flag_non_call_exceptions, 1 },
951   {"profile-arcs", &profile_arc_flag, 1 },
952   {"profile-values", &flag_profile_values, 1 },
953   {"vpt", &flag_value_profile_transformations, 1 },
954   {"test-coverage", &flag_test_coverage, 1 },
955   {"branch-probabilities", &flag_branch_probabilities, 1 },
956   {"profile", &profile_flag, 1 },
957   {"reorder-blocks", &flag_reorder_blocks, 1 },
958   {"reorder-functions", &flag_reorder_functions, 1 },
959   {"rename-registers", &flag_rename_registers, 1 },
960   {"cprop-registers", &flag_cprop_registers, 1 },
961   {"common", &flag_no_common, 0 },
962   {"inhibit-size-directive", &flag_inhibit_size_directive, 1 },
963   {"function-sections", &flag_function_sections, 1 },
964   {"data-sections", &flag_data_sections, 1 },
965   {"verbose-asm", &flag_verbose_asm, 1 },
966   {"regmove", &flag_regmove, 1 },
967   {"optimize-register-move", &flag_regmove, 1 },
968   {"pack-struct", &flag_pack_struct, 1 },
969   {"stack-check", &flag_stack_check, 1 },
970   {"argument-alias", &flag_argument_noalias, 0 },
971   {"argument-noalias", &flag_argument_noalias, 1 },
972   {"argument-noalias-global", &flag_argument_noalias, 2 },
973   {"strict-aliasing", &flag_strict_aliasing, 1 },
974   {"align-loops", &align_loops, 0 },
975   {"align-jumps", &align_jumps, 0 },
976   {"align-labels", &align_labels, 0 },
977   {"align-functions", &align_functions, 0 },
978   {"merge-constants", &flag_merge_constants, 1 },
979   {"merge-all-constants", &flag_merge_constants, 2 },
980   {"dump-unnumbered", &flag_dump_unnumbered, 1 },
981   {"instrument-functions", &flag_instrument_function_entry_exit, 1 },
982   {"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1 },
983   {"leading-underscore", &flag_leading_underscore, 1 },
984   {"ident", &flag_no_ident, 0 },
985   { "peephole2", &flag_peephole2, 1 },
986   {"finite-math-only", &flag_finite_math_only, 1 },
987   { "guess-branch-probability", &flag_guess_branch_prob, 1 },
988   {"math-errno", &flag_errno_math, 1 },
989   {"trapping-math", &flag_trapping_math, 1 },
990   {"rounding-math", &flag_rounding_math, 1 },
991   {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1 },
992   {"signaling-nans", &flag_signaling_nans, 1 },
993   {"bounds-check", &flag_bounds_check, 1 },
994   {"single-precision-constant", &flag_single_precision_constant, 1 },
995   {"time-report", &time_report, 1 },
996   {"mem-report", &mem_report, 1 },
997   { "trapv", &flag_trapv, 1 },
998   { "wrapv", &flag_wrapv, 1 },
999   { "new-ra", &flag_new_regalloc, 1 },
1000   { "var-tracking", &flag_var_tracking, 1}
1001 };
1002
1003 /* Here is a table, controlled by the tm.h file, listing each -m switch
1004    and which bits in `target_switches' it should set or clear.
1005    If VALUE is positive, it is bits to set.
1006    If VALUE is negative, -VALUE is bits to clear.
1007    (The sign bit is not used so there is no confusion.)  */
1008
1009 static const struct
1010 {
1011   const char *const name;
1012   const int value;
1013   const char *const description;
1014 }
1015 target_switches[] = TARGET_SWITCHES;
1016
1017 /* This table is similar, but allows the switch to have a value.  */
1018
1019 #ifdef TARGET_OPTIONS
1020 static const struct
1021 {
1022   const char *const prefix;
1023   const char **const variable;
1024   const char *const description;
1025   const char *const value;
1026 }
1027 target_options[] = TARGET_OPTIONS;
1028 #endif
1029
1030 /* Nonzero means warn about function definitions that default the return type
1031    or that use a null return and have a return-type other than void.  */
1032
1033 int warn_return_type;
1034
1035 /* Output files for assembler code (real compiler output)
1036    and debugging dumps.  */
1037
1038 FILE *asm_out_file;
1039 FILE *aux_info_file;
1040 FILE *dump_file = NULL;
1041 FILE *cgraph_dump_file = NULL;
1042
1043 /* The current working directory of a translation.  It's generally the
1044    directory from which compilation was initiated, but a preprocessed
1045    file may specify the original directory in which it was
1046    created.  */
1047
1048 static const char *src_pwd;
1049
1050 /* Initialize src_pwd with the given string, and return true.  If it
1051    was already initialized, return false.  As a special case, it may
1052    be called with a NULL argument to test whether src_pwd has NOT been
1053    initialized yet.  */
1054
1055 bool
1056 set_src_pwd (const char *pwd)
1057 {
1058   if (src_pwd)
1059     {
1060       if (strcmp (src_pwd, pwd) == 0)
1061         return true;
1062       else
1063         return false;
1064     }
1065
1066   src_pwd = xstrdup (pwd);
1067   return true;
1068 }
1069
1070 /* Return the directory from which the translation unit was initiated,
1071    in case set_src_pwd() was not called before to assign it a
1072    different value.  */
1073
1074 const char *
1075 get_src_pwd (void)
1076 {
1077   if (! src_pwd)
1078     src_pwd = getpwd ();
1079
1080    return src_pwd;
1081 }
1082
1083 /* Called when the start of a function definition is parsed,
1084    this function prints on stderr the name of the function.  */
1085 void
1086 announce_function (tree decl)
1087 {
1088   if (!quiet_flag)
1089     {
1090       if (rtl_dump_and_exit)
1091         verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1092       else
1093         verbatim (" %s", lang_hooks.decl_printable_name (decl, 2));
1094       fflush (stderr);
1095       pp_needs_newline (global_dc->printer) = true;
1096       diagnostic_set_last_function (global_dc);
1097     }
1098 }
1099
1100 /* Set up a default flag_random_seed and local_tick, unless the user
1101    already specified one.  */
1102
1103 static void
1104 randomize (void)
1105 {
1106   if (!flag_random_seed)
1107     {
1108       unsigned HOST_WIDE_INT value;
1109       static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
1110
1111       /* Get some more or less random data.  */
1112 #ifdef HAVE_GETTIMEOFDAY
1113       {
1114         struct timeval tv;
1115
1116         gettimeofday (&tv, NULL);
1117         local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
1118       }
1119 #else
1120       {
1121         time_t now = time (NULL);
1122
1123         if (now != (time_t)-1)
1124           local_tick = (unsigned) now;
1125       }
1126 #endif
1127       value = local_tick ^ getpid ();
1128
1129       sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
1130       flag_random_seed = random_seed;
1131     }
1132   else if (!local_tick)
1133     local_tick = -1;
1134 }
1135
1136
1137 /* Decode the string P as an integral parameter.
1138    If the string is indeed an integer return its numeric value else
1139    issue an Invalid Option error for the option PNAME and return DEFVAL.
1140    If PNAME is zero just return DEFVAL, do not call error.  */
1141
1142 int
1143 read_integral_parameter (const char *p, const char *pname, const int  defval)
1144 {
1145   const char *endp = p;
1146
1147   while (*endp)
1148     {
1149       if (ISDIGIT (*endp))
1150         endp++;
1151       else
1152         break;
1153     }
1154
1155   if (*endp != 0)
1156     {
1157       if (pname != 0)
1158         error ("invalid option argument `%s'", pname);
1159       return defval;
1160     }
1161
1162   return atoi (p);
1163 }
1164
1165 /* Return the logarithm of X, base 2, considering X unsigned,
1166    if X is a power of 2.  Otherwise, returns -1.
1167
1168    This should be used via the `exact_log2' macro.  */
1169
1170 int
1171 exact_log2_wide (unsigned HOST_WIDE_INT x)
1172 {
1173   int log = 0;
1174   /* Test for 0 or a power of 2.  */
1175   if (x == 0 || x != (x & -x))
1176     return -1;
1177   while ((x >>= 1) != 0)
1178     log++;
1179   return log;
1180 }
1181
1182 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1183    If X is 0, return -1.
1184
1185    This should be used via the floor_log2 macro.  */
1186
1187 int
1188 floor_log2_wide (unsigned HOST_WIDE_INT x)
1189 {
1190   int log = -1;
1191   while (x != 0)
1192     log++,
1193     x >>= 1;
1194   return log;
1195 }
1196
1197 /* Handler for fatal signals, such as SIGSEGV.  These are transformed
1198    into ICE messages, which is much more user friendly.  In case the
1199    error printer crashes, reset the signal to prevent infinite recursion.  */
1200
1201 static void
1202 crash_signal (int signo)
1203 {
1204   signal (signo, SIG_DFL);
1205   internal_error ("%s", strsignal (signo));
1206 }
1207
1208 /* Arrange to dump core on error.  (The regular error message is still
1209    printed first, except in the case of abort().)  */
1210
1211 static void
1212 setup_core_dumping (void)
1213 {
1214 #ifdef SIGABRT
1215   signal (SIGABRT, SIG_DFL);
1216 #endif
1217 #if defined(HAVE_SETRLIMIT)
1218   {
1219     struct rlimit rlim;
1220     if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1221       fatal_error ("getting core file size maximum limit: %m");
1222     rlim.rlim_cur = rlim.rlim_max;
1223     if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1224       fatal_error ("setting core file size limit to maximum: %m");
1225   }
1226 #endif
1227   diagnostic_abort_on_error (global_dc);
1228 }
1229
1230
1231 /* Strip off a legitimate source ending from the input string NAME of
1232    length LEN.  Rather than having to know the names used by all of
1233    our front ends, we strip off an ending of a period followed by
1234    up to five characters.  (Java uses ".class".)  */
1235
1236 void
1237 strip_off_ending (char *name, int len)
1238 {
1239   int i;
1240   for (i = 2; i < 6 && len > i; i++)
1241     {
1242       if (name[len - i] == '.')
1243         {
1244           name[len - i] = '\0';
1245           break;
1246         }
1247     }
1248 }
1249
1250 /* Output a quoted string.  */
1251
1252 void
1253 output_quoted_string (FILE *asm_file, const char *string)
1254 {
1255 #ifdef OUTPUT_QUOTED_STRING
1256   OUTPUT_QUOTED_STRING (asm_file, string);
1257 #else
1258   char c;
1259
1260   putc ('\"', asm_file);
1261   while ((c = *string++) != 0)
1262     {
1263       if (ISPRINT (c))
1264         {
1265           if (c == '\"' || c == '\\')
1266             putc ('\\', asm_file);
1267           putc (c, asm_file);
1268         }
1269       else
1270         fprintf (asm_file, "\\%03o", (unsigned char) c);
1271     }
1272   putc ('\"', asm_file);
1273 #endif
1274 }
1275
1276 /* Output a file name in the form wanted by System V.  */
1277
1278 void
1279 output_file_directive (FILE *asm_file, const char *input_name)
1280 {
1281   int len;
1282   const char *na;
1283
1284   if (input_name == NULL)
1285     input_name = "<stdin>";
1286
1287   len = strlen (input_name);
1288   na = input_name + len;
1289
1290   /* NA gets INPUT_NAME sans directory names.  */
1291   while (na > input_name)
1292     {
1293       if (IS_DIR_SEPARATOR (na[-1]))
1294         break;
1295       na--;
1296     }
1297
1298 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1299   ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1300 #else
1301   fprintf (asm_file, "\t.file\t");
1302   output_quoted_string (asm_file, na);
1303   fputc ('\n', asm_file);
1304 #endif
1305 }
1306
1307 /* Do any final processing required for the declarations in VEC, of
1308    which there are LEN.  We write out inline functions and variables
1309    that have been deferred until this point, but which are required.
1310    Returns nonzero if anything was put out.  */
1311
1312 int
1313 wrapup_global_declarations (tree *vec, int len)
1314 {
1315   tree decl;
1316   int i;
1317   int reconsider;
1318   int output_something = 0;
1319
1320   for (i = 0; i < len; i++)
1321     {
1322       decl = vec[i];
1323
1324       /* We're not deferring this any longer.  Assignment is
1325          conditional to avoid needlessly dirtying PCH pages.  */
1326       if (DECL_DEFER_OUTPUT (decl) != 0)
1327         DECL_DEFER_OUTPUT (decl) = 0;
1328
1329       if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
1330         lang_hooks.finish_incomplete_decl (decl);
1331     }
1332
1333   /* Now emit any global variables or functions that we have been
1334      putting off.  We need to loop in case one of the things emitted
1335      here references another one which comes earlier in the list.  */
1336   do
1337     {
1338       reconsider = 0;
1339       for (i = 0; i < len; i++)
1340         {
1341           decl = vec[i];
1342
1343           if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1344             continue;
1345
1346           /* Don't write out static consts, unless we still need them.
1347
1348              We also keep static consts if not optimizing (for debugging),
1349              unless the user specified -fno-keep-static-consts.
1350              ??? They might be better written into the debug information.
1351              This is possible when using DWARF.
1352
1353              A language processor that wants static constants to be always
1354              written out (even if it is not used) is responsible for
1355              calling rest_of_decl_compilation itself.  E.g. the C front-end
1356              calls rest_of_decl_compilation from finish_decl.
1357              One motivation for this is that is conventional in some
1358              environments to write things like:
1359              static const char rcsid[] = "... version string ...";
1360              intending to force the string to be in the executable.
1361
1362              A language processor that would prefer to have unneeded
1363              static constants "optimized away" would just defer writing
1364              them out until here.  E.g. C++ does this, because static
1365              constants are often defined in header files.
1366
1367              ??? A tempting alternative (for both C and C++) would be
1368              to force a constant to be written if and only if it is
1369              defined in a main file, as opposed to an include file.  */
1370
1371           if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
1372             {
1373               bool needed = 1;
1374
1375               if (flag_unit_at_a_time
1376                   && cgraph_varpool_node (decl)->finalized)
1377                 needed = 0;
1378               else if ((flag_unit_at_a_time && !cgraph_global_info_ready)
1379                        && (TREE_USED (decl)
1380                            || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
1381                 /* needed */;
1382               else if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1383                 /* needed */;
1384               else if (DECL_COMDAT (decl))
1385                 needed = 0;
1386               else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
1387                        && (optimize || !flag_keep_static_consts
1388                            || DECL_ARTIFICIAL (decl)))
1389                 needed = 0;
1390
1391               if (needed)
1392                 {
1393                   reconsider = 1;
1394                   rest_of_decl_compilation (decl, NULL, 1, 1);
1395                 }
1396             }
1397
1398           if (TREE_CODE (decl) == FUNCTION_DECL
1399               && DECL_INITIAL (decl) != 0
1400               && DECL_STRUCT_FUNCTION (decl) != 0
1401               && DECL_STRUCT_FUNCTION (decl)->saved_for_inline
1402               && (flag_keep_inline_functions
1403                   || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
1404                   || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1405             {
1406               reconsider = 1;
1407               output_inline_function (decl);
1408             }
1409         }
1410
1411       if (reconsider)
1412         output_something = 1;
1413     }
1414   while (reconsider);
1415
1416   return output_something;
1417 }
1418
1419 /* Issue appropriate warnings for the global declarations in VEC (of
1420    which there are LEN).  Output debugging information for them.  */
1421
1422 void
1423 check_global_declarations (tree *vec, int len)
1424 {
1425   tree decl;
1426   int i;
1427
1428   for (i = 0; i < len; i++)
1429     {
1430       decl = vec[i];
1431
1432       if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1433           && ! TREE_ASM_WRITTEN (decl))
1434         /* Cancel the RTL for this decl so that, if debugging info
1435            output for global variables is still to come,
1436            this one will be omitted.  */
1437         SET_DECL_RTL (decl, NULL_RTX);
1438
1439       /* Warn about any function
1440          declared static but not defined.
1441          We don't warn about variables,
1442          because many programs have static variables
1443          that exist only to get some text into the object file.  */
1444       if (TREE_CODE (decl) == FUNCTION_DECL
1445           && (warn_unused_function
1446               || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1447           && DECL_INITIAL (decl) == 0
1448           && DECL_EXTERNAL (decl)
1449           && ! DECL_ARTIFICIAL (decl)
1450           && ! TREE_PUBLIC (decl))
1451         {
1452           if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1453             pedwarn ("%J'%F' used but never defined", decl, decl);
1454           else
1455             warning ("%J'%F' declared `static' but never defined", decl, decl);
1456           /* This symbol is effectively an "extern" declaration now.  */
1457           TREE_PUBLIC (decl) = 1;
1458           assemble_external (decl);
1459         }
1460
1461       /* Warn about static fns or vars defined but not used.  */
1462       if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
1463            /* We don't warn about "static const" variables because the
1464               "rcs_id" idiom uses that construction.  */
1465            || (warn_unused_variable
1466                && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
1467           && ! DECL_IN_SYSTEM_HEADER (decl)
1468           && ! TREE_USED (decl)
1469           /* The TREE_USED bit for file-scope decls is kept in the identifier,
1470              to handle multiple external decls in different scopes.  */
1471           && ! TREE_USED (DECL_NAME (decl))
1472           && ! DECL_EXTERNAL (decl)
1473           && ! TREE_PUBLIC (decl)
1474           /* A volatile variable might be used in some non-obvious way.  */
1475           && ! TREE_THIS_VOLATILE (decl)
1476           /* Global register variables must be declared to reserve them.  */
1477           && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
1478           /* Otherwise, ask the language.  */
1479           && lang_hooks.decls.warn_unused_global (decl))
1480         warning ("%J'%D' defined but not used", decl, decl);
1481
1482       /* Avoid confusing the debug information machinery when there are
1483          errors.  */
1484       if (errorcount == 0 && sorrycount == 0)
1485         {
1486           timevar_push (TV_SYMOUT);
1487           (*debug_hooks->global_decl) (decl);
1488           timevar_pop (TV_SYMOUT);
1489         }
1490     }
1491 }
1492
1493 /* Warn about a use of an identifier which was marked deprecated.  */
1494 void
1495 warn_deprecated_use (tree node)
1496 {
1497   if (node == 0 || !warn_deprecated_decl)
1498     return;
1499
1500   if (DECL_P (node))
1501     warning ("`%s' is deprecated (declared at %s:%d)",
1502              IDENTIFIER_POINTER (DECL_NAME (node)),
1503              DECL_SOURCE_FILE (node), DECL_SOURCE_LINE (node));
1504   else if (TYPE_P (node))
1505     {
1506       const char *what = NULL;
1507       tree decl = TYPE_STUB_DECL (node);
1508
1509       if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
1510         what = IDENTIFIER_POINTER (TYPE_NAME (node));
1511       else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
1512                && DECL_NAME (TYPE_NAME (node)))
1513         what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
1514
1515       if (what)
1516         {
1517           if (decl)
1518             warning ("`%s' is deprecated (declared at %s:%d)", what,
1519                      DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1520           else
1521             warning ("`%s' is deprecated", what);
1522         }
1523       else if (decl)
1524         warning ("type is deprecated (declared at %s:%d)",
1525                  DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1526       else
1527         warning ("type is deprecated");
1528     }
1529 }
1530
1531 /* Save the current INPUT_LOCATION on the top entry in the
1532    INPUT_FILE_STACK.  Push a new entry for FILE and LINE, and set the
1533    INPUT_LOCATION accordingly.  */
1534
1535 void
1536 push_srcloc (const char *file, int line)
1537 {
1538   struct file_stack *fs;
1539
1540   fs = xmalloc (sizeof (struct file_stack));
1541   fs->location = input_location;
1542   fs->next = input_file_stack;
1543   input_filename = file;
1544   input_line = line;
1545   input_file_stack = fs;
1546   input_file_stack_tick++;
1547 }
1548
1549 /* Pop the top entry off the stack of presently open source files.
1550    Restore the INPUT_LOCATION from the new topmost entry on the
1551    stack.  */
1552
1553 void
1554 pop_srcloc (void)
1555 {
1556   struct file_stack *fs;
1557
1558   fs = input_file_stack;
1559   input_location = fs->location;
1560   input_file_stack = fs->next;
1561   free (fs);
1562   input_file_stack_tick++;
1563 }
1564
1565 /* Compile an entire translation unit.  Write a file of assembly
1566    output and various debugging dumps.  */
1567
1568 static void
1569 compile_file (void)
1570 {
1571   /* Initialize yet another pass.  */
1572
1573   init_final (main_input_filename);
1574   coverage_init (aux_base_name);
1575
1576   timevar_push (TV_PARSE);
1577
1578   /* Call the parser, which parses the entire file (calling
1579      rest_of_compilation for each function).  */
1580   lang_hooks.parse_file (set_yydebug);
1581
1582   /* In case there were missing block closers,
1583      get us back to the global binding level.  */
1584   lang_hooks.clear_binding_stack ();
1585
1586   /* Compilation is now finished except for writing
1587      what's left of the symbol table output.  */
1588   timevar_pop (TV_PARSE);
1589
1590   if (flag_syntax_only)
1591     return;
1592
1593   lang_hooks.decls.final_write_globals ();
1594
1595   cgraph_varpool_assemble_pending_decls ();
1596
1597   /* This must occur after the loop to output deferred functions.
1598      Else the coverage initializer would not be emitted if all the
1599      functions in this compilation unit were deferred.  */
1600   coverage_finish ();
1601
1602   /* Write out any pending weak symbol declarations.  */
1603
1604   weak_finish ();
1605
1606   /* Do dbx symbols.  */
1607   timevar_push (TV_SYMOUT);
1608
1609 #ifdef DWARF2_UNWIND_INFO
1610   if (dwarf2out_do_frame ())
1611     dwarf2out_frame_finish ();
1612 #endif
1613
1614   (*debug_hooks->finish) (main_input_filename);
1615   timevar_pop (TV_SYMOUT);
1616
1617   /* Output some stuff at end of file if nec.  */
1618
1619   dw2_output_indirect_constants ();
1620
1621   targetm.asm_out.file_end ();
1622
1623   /* Attach a special .ident directive to the end of the file to identify
1624      the version of GCC which compiled this code.  The format of the .ident
1625      string is patterned after the ones produced by native SVR4 compilers.  */
1626 #ifdef IDENT_ASM_OP
1627   if (!flag_no_ident)
1628     fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1629              IDENT_ASM_OP, version_string);
1630 #endif
1631 }
1632
1633 /* Display help for target options.  */
1634 void
1635 display_target_options (void)
1636 {
1637   int undoc, i;
1638   static bool displayed = false;
1639
1640   /* Avoid double printing for --help --target-help.  */
1641   if (displayed)
1642     return;
1643
1644   displayed = true;
1645
1646   if (ARRAY_SIZE (target_switches) > 1
1647 #ifdef TARGET_OPTIONS
1648       || ARRAY_SIZE (target_options) > 1
1649 #endif
1650       )
1651     {
1652       int doc = 0;
1653
1654       undoc = 0;
1655
1656       printf (_("\nTarget specific options:\n"));
1657
1658       for (i = ARRAY_SIZE (target_switches); i--;)
1659         {
1660           const char *option      = target_switches[i].name;
1661           const char *description = target_switches[i].description;
1662
1663           if (option == NULL || *option == 0)
1664             continue;
1665           else if (description == NULL)
1666             {
1667               undoc = 1;
1668
1669               if (extra_warnings)
1670                 printf (_("  -m%-23s [undocumented]\n"), option);
1671             }
1672           else if (*description != 0)
1673             doc += printf ("  -m%-23s %s\n", option, _(description));
1674         }
1675
1676 #ifdef TARGET_OPTIONS
1677       for (i = ARRAY_SIZE (target_options); i--;)
1678         {
1679           const char *option      = target_options[i].prefix;
1680           const char *description = target_options[i].description;
1681
1682           if (option == NULL || *option == 0)
1683             continue;
1684           else if (description == NULL)
1685             {
1686               undoc = 1;
1687
1688               if (extra_warnings)
1689                 printf (_("  -m%-23s [undocumented]\n"), option);
1690             }
1691           else if (*description != 0)
1692             doc += printf ("  -m%-23s %s\n", option, _(description));
1693         }
1694 #endif
1695       if (undoc)
1696         {
1697           if (doc)
1698             printf (_("\nThere are undocumented target specific options as well.\n"));
1699           else
1700             printf (_("  They exist, but they are not documented.\n"));
1701         }
1702     }
1703 }
1704
1705 /* Parse a -d... command line switch.  */
1706
1707 void
1708 decode_d_option (const char *arg)
1709 {
1710   int c;
1711
1712   while (*arg)
1713     switch (c = *arg++)
1714       {
1715       case 'A':
1716         flag_debug_asm = 1;
1717         break;
1718       case 'p':
1719         flag_print_asm_name = 1;
1720         break;
1721       case 'P':
1722         flag_dump_rtl_in_asm = 1;
1723         flag_print_asm_name = 1;
1724         break;
1725       case 'v':
1726         graph_dump_format = vcg;
1727         break;
1728       case 'x':
1729         rtl_dump_and_exit = 1;
1730         break;
1731       case 'y':
1732         set_yydebug = 1;
1733         break;
1734       case 'D': /* These are handled by the preprocessor.  */
1735       case 'I':
1736         break;
1737       case 'H':
1738         setup_core_dumping();
1739         break;
1740
1741       case 'a':
1742       default:
1743         if (!enable_rtl_dump_file (c))
1744           warning ("unrecognized gcc debugging option: %c", c);
1745         break;
1746       }
1747 }
1748
1749 /* Indexed by enum debug_info_type.  */
1750 const char *const debug_type_names[] =
1751 {
1752   "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
1753 };
1754
1755 /* Decode -m switches.  */
1756 /* Decode the switch -mNAME.  */
1757
1758 void
1759 set_target_switch (const char *name)
1760 {
1761   size_t j;
1762   int valid_target_option = 0;
1763
1764   for (j = 0; j < ARRAY_SIZE (target_switches); j++)
1765     if (!strcmp (target_switches[j].name, name))
1766       {
1767         if (target_switches[j].value < 0)
1768           target_flags &= ~-target_switches[j].value;
1769         else
1770           target_flags |= target_switches[j].value;
1771         if (name[0] != 0)
1772           {
1773             if (target_switches[j].value < 0)
1774               target_flags_explicit |= -target_switches[j].value;
1775             else
1776               target_flags_explicit |= target_switches[j].value;
1777           }
1778         valid_target_option = 1;
1779       }
1780
1781 #ifdef TARGET_OPTIONS
1782   if (!valid_target_option)
1783     for (j = 0; j < ARRAY_SIZE (target_options); j++)
1784       {
1785         int len = strlen (target_options[j].prefix);
1786         if (target_options[j].value)
1787           {
1788             if (!strcmp (target_options[j].prefix, name))
1789               {
1790                 *target_options[j].variable = target_options[j].value;
1791                 valid_target_option = 1;
1792               }
1793           }
1794         else
1795           {
1796             if (!strncmp (target_options[j].prefix, name, len))
1797               {
1798                 *target_options[j].variable = name + len;
1799                 valid_target_option = 1;
1800               }
1801           }
1802       }
1803 #endif
1804
1805   if (!valid_target_option)
1806     error ("invalid option `%s'", name);
1807 }
1808
1809 /* Print version information to FILE.
1810    Each line begins with INDENT (for the case where FILE is the
1811    assembler output file).  */
1812
1813 void
1814 print_version (FILE *file, const char *indent)
1815 {
1816 #ifndef __VERSION__
1817 #define __VERSION__ "[?]"
1818 #endif
1819   fnotice (file,
1820 #ifdef __GNUC__
1821            "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
1822 #else
1823            "%s%s%s version %s (%s) compiled by CC.\n"
1824 #endif
1825            , indent, *indent != 0 ? " " : "",
1826            lang_hooks.name, version_string, TARGET_NAME,
1827            indent, __VERSION__);
1828   fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
1829            indent, *indent != 0 ? " " : "",
1830            PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1831 }
1832
1833 /* Print an option value and return the adjusted position in the line.
1834    ??? We don't handle error returns from fprintf (disk full); presumably
1835    other code will catch a disk full though.  */
1836
1837 static int
1838 print_single_switch (FILE *file, int pos, int max,
1839                      const char *indent, const char *sep, const char *term,
1840                      const char *type, const char *name)
1841 {
1842   /* The ultrix fprintf returns 0 on success, so compute the result we want
1843      here since we need it for the following test.  */
1844   int len = strlen (sep) + strlen (type) + strlen (name);
1845
1846   if (pos != 0
1847       && pos + len > max)
1848     {
1849       fprintf (file, "%s", term);
1850       pos = 0;
1851     }
1852   if (pos == 0)
1853     {
1854       fprintf (file, "%s", indent);
1855       pos = strlen (indent);
1856     }
1857   fprintf (file, "%s%s%s", sep, type, name);
1858   pos += len;
1859   return pos;
1860 }
1861
1862 /* Print active target switches to FILE.
1863    POS is the current cursor position and MAX is the size of a "line".
1864    Each line begins with INDENT and ends with TERM.
1865    Each switch is separated from the next by SEP.  */
1866
1867 static void
1868 print_switch_values (FILE *file, int pos, int max,
1869                      const char *indent, const char *sep, const char *term)
1870 {
1871   size_t j;
1872   const char **p;
1873
1874   /* Fill in the -frandom-seed option, if the user didn't pass it, so
1875      that it can be printed below.  This helps reproducibility.  */
1876   randomize ();
1877
1878   /* Print the options as passed.  */
1879   pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
1880                              _("options passed: "), "");
1881
1882   for (p = &save_argv[1]; *p != NULL; p++)
1883     if (**p == '-')
1884       {
1885         /* Ignore these.  */
1886         if (strcmp (*p, "-o") == 0)
1887           {
1888             if (p[1] != NULL)
1889               p++;
1890             continue;
1891           }
1892         if (strcmp (*p, "-quiet") == 0)
1893           continue;
1894         if (strcmp (*p, "-version") == 0)
1895           continue;
1896         if ((*p)[1] == 'd')
1897           continue;
1898
1899         pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
1900       }
1901   if (pos > 0)
1902     fprintf (file, "%s", term);
1903
1904   /* Print the -f and -m options that have been enabled.
1905      We don't handle language specific options but printing argv
1906      should suffice.  */
1907
1908   pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
1909                              _("options enabled: "), "");
1910
1911   for (j = 0; j < ARRAY_SIZE (f_options); j++)
1912     if (*f_options[j].variable == f_options[j].on_value)
1913       pos = print_single_switch (file, pos, max, indent, sep, term,
1914                                  "-f", f_options[j].string);
1915
1916   /* Print target specific options.  */
1917
1918   for (j = 0; j < ARRAY_SIZE (target_switches); j++)
1919     if (target_switches[j].name[0] != '\0'
1920         && target_switches[j].value > 0
1921         && ((target_switches[j].value & target_flags)
1922             == target_switches[j].value))
1923       {
1924         pos = print_single_switch (file, pos, max, indent, sep, term,
1925                                    "-m", target_switches[j].name);
1926       }
1927
1928 #ifdef TARGET_OPTIONS
1929   for (j = 0; j < ARRAY_SIZE (target_options); j++)
1930     if (*target_options[j].variable != NULL)
1931       {
1932         char prefix[256];
1933         sprintf (prefix, "-m%s", target_options[j].prefix);
1934         pos = print_single_switch (file, pos, max, indent, sep, term,
1935                                    prefix, *target_options[j].variable);
1936       }
1937 #endif
1938
1939   fprintf (file, "%s", term);
1940 }
1941
1942 /* Open assembly code output file.  Do this even if -fsyntax-only is
1943    on, because then the driver will have provided the name of a
1944    temporary file or bit bucket for us.  NAME is the file specified on
1945    the command line, possibly NULL.  */
1946 static void
1947 init_asm_output (const char *name)
1948 {
1949   if (name == NULL && asm_file_name == 0)
1950     asm_out_file = stdout;
1951   else
1952     {
1953       if (asm_file_name == 0)
1954         {
1955           int len = strlen (dump_base_name);
1956           char *dumpname = xmalloc (len + 6);
1957           memcpy (dumpname, dump_base_name, len + 1);
1958           strip_off_ending (dumpname, len);
1959           strcat (dumpname, ".s");
1960           asm_file_name = dumpname;
1961         }
1962       if (!strcmp (asm_file_name, "-"))
1963         asm_out_file = stdout;
1964       else
1965         asm_out_file = fopen (asm_file_name, "w+");
1966       if (asm_out_file == 0)
1967         fatal_error ("can't open %s for writing: %m", asm_file_name);
1968     }
1969
1970 #ifdef IO_BUFFER_SIZE
1971   setvbuf (asm_out_file, xmalloc (IO_BUFFER_SIZE),
1972            _IOFBF, IO_BUFFER_SIZE);
1973 #endif
1974
1975   if (!flag_syntax_only)
1976     {
1977       targetm.asm_out.file_start ();
1978
1979 #ifdef ASM_COMMENT_START
1980       if (flag_verbose_asm)
1981         {
1982           /* Print the list of options in effect.  */
1983           print_version (asm_out_file, ASM_COMMENT_START);
1984           print_switch_values (asm_out_file, 0, MAX_LINE,
1985                                ASM_COMMENT_START, " ", "\n");
1986           /* Add a blank line here so it appears in assembler output but not
1987              screen output.  */
1988           fprintf (asm_out_file, "\n");
1989         }
1990 #endif
1991     }
1992 }
1993
1994 /* Default version of get_pch_validity.
1995    By default, every flag difference is fatal; that will be mostly right for
1996    most targets, but completely right for very few.  */
1997
1998 void *
1999 default_get_pch_validity (size_t *len)
2000 {
2001 #ifdef TARGET_OPTIONS
2002   size_t i;
2003 #endif
2004   char *result, *r;
2005
2006   *len = sizeof (target_flags) + 2;
2007 #ifdef TARGET_OPTIONS
2008   for (i = 0; i < ARRAY_SIZE (target_options); i++)
2009     {
2010       *len += 1;
2011       if (*target_options[i].variable)
2012         *len += strlen (*target_options[i].variable);
2013     }
2014 #endif
2015
2016   result = r = xmalloc (*len);
2017   r[0] = flag_pic;
2018   r[1] = flag_pie;
2019   r += 2;
2020   memcpy (r, &target_flags, sizeof (target_flags));
2021   r += sizeof (target_flags);
2022
2023 #ifdef TARGET_OPTIONS
2024   for (i = 0; i < ARRAY_SIZE (target_options); i++)
2025     {
2026       const char *str = *target_options[i].variable;
2027       size_t l;
2028       if (! str)
2029         str = "";
2030       l = strlen (str) + 1;
2031       memcpy (r, str, l);
2032       r += l;
2033     }
2034 #endif
2035
2036   return result;
2037 }
2038
2039 /* Default version of pch_valid_p.  */
2040
2041 const char *
2042 default_pch_valid_p (const void *data_p, size_t len)
2043 {
2044   const char *data = (const char *)data_p;
2045   const char *flag_that_differs = NULL;
2046   size_t i;
2047
2048   /* -fpic and -fpie also usually make a PCH invalid.  */
2049   if (data[0] != flag_pic)
2050     return _("created and used with different settings of -fpic");
2051   if (data[1] != flag_pie)
2052     return _("created and used with different settings of -fpie");
2053   data += 2;
2054
2055   /* Check target_flags.  */
2056   if (memcmp (data, &target_flags, sizeof (target_flags)) != 0)
2057     {
2058       for (i = 0; i < ARRAY_SIZE (target_switches); i++)
2059         {
2060           int bits;
2061           int tf;
2062
2063           memcpy (&tf, data, sizeof (target_flags));
2064
2065           bits = target_switches[i].value;
2066           if (bits < 0)
2067             bits = -bits;
2068           if ((target_flags & bits) != (tf & bits))
2069             {
2070               flag_that_differs = target_switches[i].name;
2071               goto make_message;
2072             }
2073         }
2074       abort ();
2075     }
2076   data += sizeof (target_flags);
2077   len -= sizeof (target_flags);
2078
2079   /* Check string options.  */
2080 #ifdef TARGET_OPTIONS
2081   for (i = 0; i < ARRAY_SIZE (target_options); i++)
2082     {
2083       const char *str = *target_options[i].variable;
2084       size_t l;
2085       if (! str)
2086         str = "";
2087       l = strlen (str) + 1;
2088       if (len < l || memcmp (data, str, l) != 0)
2089         {
2090           flag_that_differs = target_options[i].prefix;
2091           goto make_message;
2092         }
2093       data += l;
2094       len -= l;
2095     }
2096 #endif
2097
2098   return NULL;
2099
2100  make_message:
2101   {
2102     char *r;
2103     asprintf (&r, _("created and used with differing settings of `-m%s'"),
2104                   flag_that_differs);
2105     if (r == NULL)
2106       return _("out of memory");
2107     return r;
2108   }
2109 }
2110
2111 /* Default tree printer.   Handles declarations only.  */
2112 static bool
2113 default_tree_printer (pretty_printer * pp, text_info *text)
2114 {
2115   switch (*text->format_spec)
2116     {
2117     case 'D':
2118     case 'F':
2119     case 'T':
2120       {
2121         tree t = va_arg (*text->args_ptr, tree);
2122         const char *n = DECL_NAME (t)
2123           ? lang_hooks.decl_printable_name (t, 2)
2124           : "<anonymous>";
2125         pp_string (pp, n);
2126       }
2127       return true;
2128
2129     default:
2130       return false;
2131     }
2132 }
2133
2134 /* Initialization of the front end environment, before command line
2135    options are parsed.  Signal handlers, internationalization etc.
2136    ARGV0 is main's argv[0].  */
2137 static void
2138 general_init (const char *argv0)
2139 {
2140   const char *p;
2141
2142   p = argv0 + strlen (argv0);
2143   while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
2144     --p;
2145   progname = p;
2146
2147   xmalloc_set_program_name (progname);
2148
2149   hex_init ();
2150
2151   gcc_init_libintl ();
2152
2153   /* Initialize the diagnostics reporting machinery, so option parsing
2154      can give warnings and errors.  */
2155   diagnostic_initialize (global_dc);
2156   /* Set a default printer.  Language specific initializations will
2157      override it later.  */
2158   pp_format_decoder (global_dc->printer) = &default_tree_printer;
2159
2160   /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages.  */
2161 #ifdef SIGSEGV
2162   signal (SIGSEGV, crash_signal);
2163 #endif
2164 #ifdef SIGILL
2165   signal (SIGILL, crash_signal);
2166 #endif
2167 #ifdef SIGBUS
2168   signal (SIGBUS, crash_signal);
2169 #endif
2170 #ifdef SIGABRT
2171   signal (SIGABRT, crash_signal);
2172 #endif
2173 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
2174   signal (SIGIOT, crash_signal);
2175 #endif
2176 #ifdef SIGFPE
2177   signal (SIGFPE, crash_signal);
2178 #endif
2179
2180   /* Other host-specific signal setup.  */
2181   (*host_hooks.extra_signals)();
2182
2183   /* Initialize the garbage-collector, string pools and tree type hash
2184      table.  */
2185   init_ggc ();
2186   init_stringpool ();
2187   linemap_init (&line_table);
2188   init_ttree ();
2189
2190   /* Initialize register usage now so switches may override.  */
2191   init_reg_sets ();
2192
2193   /* Register the language-independent parameters.  */
2194   add_params (lang_independent_params, LAST_PARAM);
2195
2196   /* This must be done after add_params but before argument processing.  */
2197   init_ggc_heuristics();
2198 }
2199
2200 /* Process the options that have been parsed.  */
2201 static void
2202 process_options (void)
2203 {
2204   /* Allow the front end to perform consistency checks and do further
2205      initialization based on the command line options.  This hook also
2206      sets the original filename if appropriate (e.g. foo.i -> foo.c)
2207      so we can correctly initialize debug output.  */
2208   no_backend = lang_hooks.post_options (&main_input_filename);
2209   input_filename = main_input_filename;
2210
2211 #ifdef OVERRIDE_OPTIONS
2212   /* Some machines may reject certain combinations of options.  */
2213   OVERRIDE_OPTIONS;
2214 #endif
2215
2216   /* Set aux_base_name if not already set.  */
2217   if (aux_base_name)
2218     ;
2219   else if (main_input_filename)
2220     {
2221       char *name = xstrdup (lbasename (main_input_filename));
2222
2223       strip_off_ending (name, strlen (name));
2224       aux_base_name = name;
2225     }
2226   else
2227     aux_base_name = "gccaux";
2228
2229   /* Set up the align_*_log variables, defaulting them to 1 if they
2230      were still unset.  */
2231   if (align_loops <= 0) align_loops = 1;
2232   if (align_loops_max_skip > align_loops || !align_loops)
2233     align_loops_max_skip = align_loops - 1;
2234   align_loops_log = floor_log2 (align_loops * 2 - 1);
2235   if (align_jumps <= 0) align_jumps = 1;
2236   if (align_jumps_max_skip > align_jumps || !align_jumps)
2237     align_jumps_max_skip = align_jumps - 1;
2238   align_jumps_log = floor_log2 (align_jumps * 2 - 1);
2239   if (align_labels <= 0) align_labels = 1;
2240   align_labels_log = floor_log2 (align_labels * 2 - 1);
2241   if (align_labels_max_skip > align_labels || !align_labels)
2242     align_labels_max_skip = align_labels - 1;
2243   if (align_functions <= 0) align_functions = 1;
2244   align_functions_log = floor_log2 (align_functions * 2 - 1);
2245
2246   /* Unrolling all loops implies that standard loop unrolling must also
2247      be done.  */
2248   if (flag_unroll_all_loops)
2249     flag_unroll_loops = 1;
2250
2251   if (flag_unroll_loops)
2252     {
2253       flag_old_unroll_loops = 0;
2254       flag_old_unroll_all_loops = 0;
2255     }
2256
2257   if (flag_old_unroll_all_loops)
2258     flag_old_unroll_loops = 1;
2259
2260   /* Old loop unrolling requires that strength_reduction be on also.  Silently
2261      turn on strength reduction here if it isn't already on.  Also, the loop
2262      unrolling code assumes that cse will be run after loop, so that must
2263      be turned on also.  */
2264   if (flag_old_unroll_loops)
2265     {
2266       flag_strength_reduce = 1;
2267       flag_rerun_cse_after_loop = 1;
2268     }
2269   if (flag_unroll_loops || flag_peel_loops)
2270     flag_rerun_cse_after_loop = 1;
2271
2272   if (flag_non_call_exceptions)
2273     flag_asynchronous_unwind_tables = 1;
2274   if (flag_asynchronous_unwind_tables)
2275     flag_unwind_tables = 1;
2276
2277   /* Disable unit-at-a-time mode for frontends not supporting callgraph
2278      interface.  */
2279   if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
2280     flag_unit_at_a_time = 0;
2281
2282   if (flag_value_profile_transformations)
2283     flag_profile_values = 1;
2284
2285   /* Warn about options that are not supported on this machine.  */
2286 #ifndef INSN_SCHEDULING
2287   if (flag_schedule_insns || flag_schedule_insns_after_reload)
2288     warning ("instruction scheduling not supported on this target machine");
2289 #endif
2290 #ifndef DELAY_SLOTS
2291   if (flag_delayed_branch)
2292     warning ("this target machine does not have delayed branches");
2293 #endif
2294
2295   user_label_prefix = USER_LABEL_PREFIX;
2296   if (flag_leading_underscore != -1)
2297     {
2298       /* If the default prefix is more complicated than "" or "_",
2299          issue a warning and ignore this option.  */
2300       if (user_label_prefix[0] == 0 ||
2301           (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
2302         {
2303           user_label_prefix = flag_leading_underscore ? "_" : "";
2304         }
2305       else
2306         warning ("-f%sleading-underscore not supported on this target machine",
2307                  flag_leading_underscore ? "" : "no-");
2308     }
2309
2310   /* If we are in verbose mode, write out the version and maybe all the
2311      option flags in use.  */
2312   if (version_flag)
2313     {
2314       print_version (stderr, "");
2315       if (! quiet_flag)
2316         print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
2317     }
2318
2319   if (flag_syntax_only)
2320     {
2321       write_symbols = NO_DEBUG;
2322       profile_flag = 0;
2323     }
2324
2325   /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
2326      level is 0.  */
2327   if (debug_info_level == DINFO_LEVEL_NONE)
2328     write_symbols = NO_DEBUG;
2329
2330   /* Now we know write_symbols, set up the debug hooks based on it.
2331      By default we do nothing for debug output.  */
2332   if (write_symbols == NO_DEBUG)
2333     debug_hooks = &do_nothing_debug_hooks;
2334 #if defined(DBX_DEBUGGING_INFO)
2335   else if (write_symbols == DBX_DEBUG)
2336     debug_hooks = &dbx_debug_hooks;
2337 #endif
2338 #if defined(XCOFF_DEBUGGING_INFO)
2339   else if (write_symbols == XCOFF_DEBUG)
2340     debug_hooks = &xcoff_debug_hooks;
2341 #endif
2342 #ifdef SDB_DEBUGGING_INFO
2343   else if (write_symbols == SDB_DEBUG)
2344     debug_hooks = &sdb_debug_hooks;
2345 #endif
2346 #ifdef DWARF2_DEBUGGING_INFO
2347   else if (write_symbols == DWARF2_DEBUG)
2348     debug_hooks = &dwarf2_debug_hooks;
2349 #endif
2350 #ifdef VMS_DEBUGGING_INFO
2351   else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2352     debug_hooks = &vmsdbg_debug_hooks;
2353 #endif
2354   else
2355     error ("target system does not support the \"%s\" debug format",
2356            debug_type_names[write_symbols]);
2357
2358   /* Now we know which debug output will be used so we can set
2359      flag_var_tracking if user has not specified it.  */
2360   if (flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING)
2361     {
2362       /* User has not specified -f(no-)var-tracking so autodetect it.  */
2363       flag_var_tracking
2364         = (optimize >= 1 && debug_info_level >= DINFO_LEVEL_NORMAL
2365            && debug_hooks->var_location != do_nothing_debug_hooks.var_location);
2366     }
2367
2368   /* If auxiliary info generation is desired, open the output file.
2369      This goes in the same directory as the source file--unlike
2370      all the other output files.  */
2371   if (flag_gen_aux_info)
2372     {
2373       aux_info_file = fopen (aux_info_file_name, "w");
2374       if (aux_info_file == 0)
2375         fatal_error ("can't open %s: %m", aux_info_file_name);
2376     }
2377
2378   if (! targetm.have_named_sections)
2379     {
2380       if (flag_function_sections)
2381         {
2382           warning ("-ffunction-sections not supported for this target");
2383           flag_function_sections = 0;
2384         }
2385       if (flag_data_sections)
2386         {
2387           warning ("-fdata-sections not supported for this target");
2388           flag_data_sections = 0;
2389         }
2390     }
2391
2392   if (flag_function_sections && profile_flag)
2393     {
2394       warning ("-ffunction-sections disabled; it makes profiling impossible");
2395       flag_function_sections = 0;
2396     }
2397
2398 #ifndef HAVE_prefetch
2399   if (flag_prefetch_loop_arrays)
2400     {
2401       warning ("-fprefetch-loop-arrays not supported for this target");
2402       flag_prefetch_loop_arrays = 0;
2403     }
2404 #else
2405   if (flag_prefetch_loop_arrays && !HAVE_prefetch)
2406     {
2407       warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
2408       flag_prefetch_loop_arrays = 0;
2409     }
2410 #endif
2411
2412   /* This combination of options isn't handled for i386 targets and doesn't
2413      make much sense anyway, so don't allow it.  */
2414   if (flag_prefetch_loop_arrays && optimize_size)
2415     {
2416       warning ("-fprefetch-loop-arrays is not supported with -Os");
2417       flag_prefetch_loop_arrays = 0;
2418     }
2419
2420 #ifndef OBJECT_FORMAT_ELF
2421   if (flag_function_sections && write_symbols != NO_DEBUG)
2422     warning ("-ffunction-sections may affect debugging on some targets");
2423 #endif
2424
2425     /* The presence of IEEE signaling NaNs, implies all math can trap.  */
2426     if (flag_signaling_nans)
2427       flag_trapping_math = 1;
2428 }
2429
2430 /* Initialize the compiler back end.  */
2431 static void
2432 backend_init (void)
2433 {
2434   init_adjust_machine_modes ();
2435
2436   init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2437                   || debug_info_level == DINFO_LEVEL_VERBOSE
2438 #ifdef VMS_DEBUGGING_INFO
2439                     /* Enable line number info for traceback.  */
2440                     || debug_info_level > DINFO_LEVEL_NONE
2441 #endif
2442                     || flag_test_coverage
2443                     || warn_notreached);
2444
2445   init_regs ();
2446   init_fake_stack_mems ();
2447   init_alias_once ();
2448   init_loop ();
2449   init_reload ();
2450   init_function_once ();
2451   init_varasm_once ();
2452
2453   /* The following initialization functions need to generate rtl, so
2454      provide a dummy function context for them.  */
2455   init_dummy_function_start ();
2456   init_expmed ();
2457   if (flag_caller_saves)
2458     init_caller_save ();
2459   expand_dummy_function_end ();
2460 }
2461
2462 /* Language-dependent initialization.  Returns nonzero on success.  */
2463 static int
2464 lang_dependent_init (const char *name)
2465 {
2466   if (dump_base_name == 0)
2467     dump_base_name = name ? name : "gccdump";
2468
2469   /* Other front-end initialization.  */
2470   if (lang_hooks.init () == 0)
2471     return 0;
2472
2473   init_asm_output (name);
2474
2475   /* These create various _DECL nodes, so need to be called after the
2476      front end is initialized.  */
2477   init_eh ();
2478   init_optabs ();
2479   init_optimization_passes ();
2480
2481   /* The following initialization functions need to generate rtl, so
2482      provide a dummy function context for them.  */
2483   init_dummy_function_start ();
2484   init_expr_once ();
2485   expand_dummy_function_end ();
2486
2487   /* If dbx symbol table desired, initialize writing it and output the
2488      predefined types.  */
2489   timevar_push (TV_SYMOUT);
2490
2491 #ifdef DWARF2_UNWIND_INFO
2492   if (dwarf2out_do_frame ())
2493     dwarf2out_frame_init ();
2494 #endif
2495
2496   /* Now we have the correct original filename, we can initialize
2497      debug output.  */
2498   (*debug_hooks->init) (name);
2499
2500   timevar_pop (TV_SYMOUT);
2501
2502   return 1;
2503 }
2504
2505 /* Clean up: close opened files, etc.  */
2506
2507 static void
2508 finalize (void)
2509 {
2510   /* Close the dump files.  */
2511   if (flag_gen_aux_info)
2512     {
2513       fclose (aux_info_file);
2514       if (errorcount)
2515         unlink (aux_info_file_name);
2516     }
2517
2518   /* Close non-debugging input and output files.  Take special care to note
2519      whether fclose returns an error, since the pages might still be on the
2520      buffer chain while the file is open.  */
2521
2522   if (asm_out_file)
2523     {
2524       if (ferror (asm_out_file) != 0)
2525         fatal_error ("error writing to %s: %m", asm_file_name);
2526       if (fclose (asm_out_file) != 0)
2527         fatal_error ("error closing %s: %m", asm_file_name);
2528     }
2529
2530   finish_optimization_passes ();
2531
2532   if (mem_report)
2533     {
2534       ggc_print_statistics ();
2535       stringpool_statistics ();
2536       dump_tree_statistics ();
2537       dump_rtx_statistics ();
2538       dump_varray_statistics ();
2539       dump_alloc_pool_statistics ();
2540       dump_ggc_loc_statistics ();
2541     }
2542
2543   /* Free up memory for the benefit of leak detectors.  */
2544   free_reg_info ();
2545
2546   /* Language-specific end of compilation actions.  */
2547   lang_hooks.finish ();
2548 }
2549
2550 /* Initialize the compiler, and compile the input file.  */
2551 static void
2552 do_compile (void)
2553 {
2554   /* Initialize timing first.  The C front ends read the main file in
2555      the post_options hook, and C++ does file timings.  */
2556   if (time_report || !quiet_flag  || flag_detailed_statistics)
2557     timevar_init ();
2558   timevar_start (TV_TOTAL);
2559
2560   process_options ();
2561
2562   /* Don't do any more if an error has already occurred.  */
2563   if (!errorcount)
2564     {
2565       /* Set up the back-end if requested.  */
2566       if (!no_backend)
2567         backend_init ();
2568
2569       /* Language-dependent initialization.  Returns true on success.  */
2570       if (lang_dependent_init (main_input_filename))
2571         compile_file ();
2572
2573       finalize ();
2574     }
2575
2576   /* Stop timing and print the times.  */
2577   timevar_stop (TV_TOTAL);
2578   timevar_print (stderr);
2579 }
2580
2581 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2582    Exit code is FATAL_EXIT_CODE if can't open files or if there were
2583    any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2584
2585    It is not safe to call this function more than once.  */
2586
2587 int
2588 toplev_main (unsigned int argc, const char **argv)
2589 {
2590   save_argv = argv;
2591
2592   /* Initialization of GCC's environment, and diagnostics.  */
2593   general_init (argv[0]);
2594
2595   /* Parse the options and do minimal processing; basically just
2596      enough to default flags appropriately.  */
2597   decode_options (argc, argv);
2598
2599   randomize ();
2600
2601   /* Exit early if we can (e.g. -help).  */
2602   if (!exit_after_options)
2603     do_compile ();
2604
2605   if (errorcount || sorrycount)
2606     return (FATAL_EXIT_CODE);
2607
2608   return (SUCCESS_EXIT_CODE);
2609 }