OSDN Git Service

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