OSDN Git Service

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