OSDN Git Service

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