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