OSDN Git Service

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