OSDN Git Service

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