]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/toplev.c
gcc/
[thirdparty/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, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include <signal.h>
32
33 #ifdef HAVE_SYS_RESOURCE_H
34 # include <sys/resource.h>
35 #endif
36
37 #ifdef HAVE_SYS_TIMES_H
38 # include <sys/times.h>
39 #endif
40
41 #include "line-map.h"
42 #include "input.h"
43 #include "tree.h"
44 #include "realmpfr.h" /* For GMP/MPFR/MPC versions, in print_version. */
45 #include "version.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 "regs.h"
64 #include "timevar.h"
65 #include "diagnostic.h"
66 #include "tree-diagnostic.h"
67 #include "tree-pretty-print.h"
68 #include "params.h"
69 #include "reload.h"
70 #include "ira.h"
71 #include "dwarf2asm.h"
72 #include "integrate.h"
73 #include "debug.h"
74 #include "target.h"
75 #include "langhooks.h"
76 #include "cfglayout.h"
77 #include "cfgloop.h"
78 #include "hosthooks.h"
79 #include "cgraph.h"
80 #include "opts.h"
81 #include "opts-diagnostic.h"
82 #include "coverage.h"
83 #include "value-prof.h"
84 #include "alloc-pool.h"
85 #include "tree-mudflap.h"
86 #include "tree-pass.h"
87 #include "gimple.h"
88 #include "tree-ssa-alias.h"
89 #include "plugin.h"
90
91 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
92 #include "dwarf2out.h"
93 #endif
94
95 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
96 #include "dbxout.h"
97 #endif
98
99 #ifdef SDB_DEBUGGING_INFO
100 #include "sdbout.h"
101 #endif
102
103 #ifdef XCOFF_DEBUGGING_INFO
104 #include "xcoffout.h" /* Needed for external data
105 declarations for e.g. AIX 4.x. */
106 #endif
107
108 static void general_init (const char *);
109 static void do_compile (void);
110 static void process_options (void);
111 static void backend_init (void);
112 static int lang_dependent_init (const char *);
113 static void init_asm_output (const char *);
114 static void finalize (void);
115
116 static void crash_signal (int) ATTRIBUTE_NORETURN;
117 static void setup_core_dumping (void);
118 static void compile_file (void);
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 /* Decoded options, and number of such options. */
130 static struct cl_decoded_option *save_decoded_options;
131 static unsigned int save_decoded_options_count;
132
133 /* Name of top-level original source file (what was input to cpp).
134 This comes from the #-command at the beginning of the actual input.
135 If there isn't any there, then this is the cc1 input file name. */
136
137 const char *main_input_filename;
138
139 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
140 to optimize in process_options (). */
141 #define AUTODETECT_VALUE 2
142
143 /* Name to use as base of names for dump output files. */
144
145 const char *dump_base_name;
146
147 /* Directory used for dump output files. */
148
149 const char *dump_dir_name;
150
151 /* Name to use as a base for auxiliary output files. */
152
153 const char *aux_base_name;
154
155 /* Prefix for profile data files */
156 const char *profile_data_prefix;
157
158 /* A mask of target_flags that includes bit X if X was set or cleared
159 on the command line. */
160
161 int target_flags_explicit;
162
163 /* Debug hooks - dependent upon command line options. */
164
165 const struct gcc_debug_hooks *debug_hooks;
166
167 /* Other flags saying which kinds of debugging dump have been requested. */
168
169 int rtl_dump_and_exit;
170 int flag_print_asm_name;
171 enum graph_dump_types graph_dump_format;
172
173 /* Name for output file of assembly code, specified with -o. */
174
175 const char *asm_file_name;
176
177 /* Nonzero means do optimizations. -O.
178 Particular numeric values stand for particular amounts of optimization;
179 thus, -O2 stores 2 here. However, the optimizations beyond the basic
180 ones are not controlled directly by this variable. Instead, they are
181 controlled by individual `flag_...' variables that are defaulted
182 based on this variable. */
183
184 int optimize = 0;
185
186 /* Nonzero means optimize for size. -Os.
187 The only valid values are zero and nonzero. When optimize_size is
188 nonzero, optimize defaults to 2, but certain individual code
189 bloating optimizations are disabled. */
190
191 int optimize_size = 0;
192
193 /* True if this is the lto front end. This is used to disable
194 gimple generation and lowering passes that are normally run on the
195 output of a front end. These passes must be bypassed for lto since
196 they have already been done before the gimple was written. */
197
198 bool in_lto_p = false;
199
200 /* Nonzero if we should write GIMPLE bytecode for link-time optimization. */
201
202 int flag_generate_lto;
203
204 /* The FUNCTION_DECL for the function currently being compiled,
205 or 0 if between functions. */
206 tree current_function_decl;
207
208 /* Set to the FUNC_BEGIN label of the current function, or NULL
209 if none. */
210 const char * current_function_func_begin_label;
211
212 /* A random sequence of characters, unless overridden by user. */
213 static const char *flag_random_seed;
214
215 /* A local time stamp derived from the time of compilation. It will be
216 zero if the system cannot provide a time. It will be -1u, if the
217 user has specified a particular random seed. */
218 unsigned local_tick;
219
220 /* -f flags. */
221
222 /* 0 means straightforward implementation of complex divide acceptable.
223 1 means wide ranges of inputs must work for complex divide.
224 2 means C99-like requirements for complex multiply and divide. */
225
226 int flag_complex_method = 1;
227
228 /* Nonzero means we should be saving declaration info into a .X file. */
229
230 int flag_gen_aux_info = 0;
231
232 /* Specified name of aux-info file. */
233
234 const char *aux_info_file_name;
235
236 /* Nonzero if we are compiling code for a shared library, zero for
237 executable. */
238
239 int flag_shlib;
240
241 /* Generate code for GNU or NeXT Objective-C runtime environment. */
242
243 #ifdef NEXT_OBJC_RUNTIME
244 int flag_next_runtime = 1;
245 #else
246 int flag_next_runtime = 0;
247 #endif
248
249 /* Set to the default thread-local storage (tls) model to use. */
250
251 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
252
253 /* Set the default region and algorithm for the integrated register
254 allocator. */
255
256 enum ira_algorithm flag_ira_algorithm = IRA_ALGORITHM_CB;
257 enum ira_region flag_ira_region = IRA_REGION_MIXED;
258
259 /* Set the default for excess precision. */
260
261 enum excess_precision flag_excess_precision_cmdline = EXCESS_PRECISION_DEFAULT;
262 enum excess_precision flag_excess_precision = EXCESS_PRECISION_DEFAULT;
263
264 /* Nonzero means change certain warnings into errors.
265 Usually these are warnings about failure to conform to some standard. */
266
267 int flag_pedantic_errors = 0;
268
269 /* Nonzero means make permerror produce warnings instead of errors. */
270
271 int flag_permissive = 0;
272
273 /* -dA causes debug commentary information to be produced in
274 the generated assembly code (to make it more readable). This option
275 is generally only of use to those who actually need to read the
276 generated assembly code (perhaps while debugging the compiler itself).
277 Currently, this switch is only used by dwarfout.c; however, it is intended
278 to be a catchall for printing debug information in the assembler file. */
279
280 int flag_debug_asm = 0;
281
282 /* -dP causes the rtl to be emitted as a comment in assembly. */
283
284 int flag_dump_rtl_in_asm = 0;
285
286 /* When non-NULL, indicates that whenever space is allocated on the
287 stack, the resulting stack pointer must not pass this
288 address---that is, for stacks that grow downward, the stack pointer
289 must always be greater than or equal to this address; for stacks
290 that grow upward, the stack pointer must be less than this address.
291 At present, the rtx may be either a REG or a SYMBOL_REF, although
292 the support provided depends on the backend. */
293 rtx stack_limit_rtx;
294
295 /* Positive if we should track variables, negative if we should run
296 the var-tracking pass only to discard debug annotations, zero if
297 we're not to run it. When flag_var_tracking == AUTODETECT_VALUE it
298 will be set according to optimize, debug_info_level and debug_hooks
299 in process_options (). */
300 int flag_var_tracking = AUTODETECT_VALUE;
301
302 /* Positive if we should track variables at assignments, negative if
303 we should run the var-tracking pass only to discard debug
304 annotations. When flag_var_tracking_assignments ==
305 AUTODETECT_VALUE it will be set according to flag_var_tracking. */
306 int flag_var_tracking_assignments = AUTODETECT_VALUE;
307
308 /* Nonzero if we should toggle flag_var_tracking_assignments after
309 processing options and computing its default. */
310 int flag_var_tracking_assignments_toggle = 0;
311
312 /* Type of stack check. */
313 enum stack_check_type flag_stack_check = NO_STACK_CHECK;
314
315 /* True if the user has tagged the function with the 'section'
316 attribute. */
317
318 bool user_defined_section_attribute = false;
319
320 struct target_flag_state default_target_flag_state;
321 #if SWITCHABLE_TARGET
322 struct target_flag_state *this_target_flag_state = &default_target_flag_state;
323 #else
324 #define this_target_flag_state (&default_target_flag_state)
325 #endif
326
327 typedef struct
328 {
329 const char *const string;
330 int *const variable;
331 const int on_value;
332 }
333 lang_independent_options;
334
335 /* Nonzero if subexpressions must be evaluated from left-to-right. */
336 int flag_evaluation_order = 0;
337
338 /* The user symbol prefix after having resolved same. */
339 const char *user_label_prefix;
340
341 static const param_info lang_independent_params[] = {
342 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
343 { OPTION, DEFAULT, false, MIN, MAX, HELP },
344 #include "params.def"
345 #undef DEFPARAM
346 { NULL, 0, false, 0, 0, NULL }
347 };
348
349 /* Output files for assembler code (real compiler output)
350 and debugging dumps. */
351
352 FILE *asm_out_file;
353 FILE *aux_info_file;
354 FILE *dump_file = NULL;
355 const char *dump_file_name;
356
357 /* The current working directory of a translation. It's generally the
358 directory from which compilation was initiated, but a preprocessed
359 file may specify the original directory in which it was
360 created. */
361
362 static const char *src_pwd;
363
364 /* Initialize src_pwd with the given string, and return true. If it
365 was already initialized, return false. As a special case, it may
366 be called with a NULL argument to test whether src_pwd has NOT been
367 initialized yet. */
368
369 bool
370 set_src_pwd (const char *pwd)
371 {
372 if (src_pwd)
373 {
374 if (strcmp (src_pwd, pwd) == 0)
375 return true;
376 else
377 return false;
378 }
379
380 src_pwd = xstrdup (pwd);
381 return true;
382 }
383
384 /* Return the directory from which the translation unit was initiated,
385 in case set_src_pwd() was not called before to assign it a
386 different value. */
387
388 const char *
389 get_src_pwd (void)
390 {
391 if (! src_pwd)
392 {
393 src_pwd = getpwd ();
394 if (!src_pwd)
395 src_pwd = ".";
396 }
397
398 return src_pwd;
399 }
400
401 /* Called when the start of a function definition is parsed,
402 this function prints on stderr the name of the function. */
403 void
404 announce_function (tree decl)
405 {
406 if (!quiet_flag)
407 {
408 if (rtl_dump_and_exit)
409 fprintf (stderr, "%s ",
410 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
411 else
412 fprintf (stderr, " %s",
413 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
414 fflush (stderr);
415 pp_needs_newline (global_dc->printer) = true;
416 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
417 }
418 }
419
420 /* Initialize local_tick with the time of day, or -1 if
421 flag_random_seed is set. */
422
423 static void
424 init_local_tick (void)
425 {
426 if (!flag_random_seed)
427 {
428 /* Get some more or less random data. */
429 #ifdef HAVE_GETTIMEOFDAY
430 {
431 struct timeval tv;
432
433 gettimeofday (&tv, NULL);
434 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
435 }
436 #else
437 {
438 time_t now = time (NULL);
439
440 if (now != (time_t)-1)
441 local_tick = (unsigned) now;
442 }
443 #endif
444 }
445 else
446 local_tick = -1;
447 }
448
449 /* Set up a default flag_random_seed and local_tick, unless the user
450 already specified one. Must be called after init_local_tick. */
451
452 static void
453 init_random_seed (void)
454 {
455 unsigned HOST_WIDE_INT value;
456 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
457
458 value = local_tick ^ getpid ();
459
460 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
461 flag_random_seed = random_seed;
462 }
463
464 /* Obtain the random_seed string. Unless NOINIT, initialize it if
465 it's not provided in the command line. */
466
467 const char *
468 get_random_seed (bool noinit)
469 {
470 if (!flag_random_seed && !noinit)
471 init_random_seed ();
472 return flag_random_seed;
473 }
474
475 /* Modify the random_seed string to VAL. Return its previous
476 value. */
477
478 const char *
479 set_random_seed (const char *val)
480 {
481 const char *old = flag_random_seed;
482 flag_random_seed = val;
483 return old;
484 }
485
486 #if GCC_VERSION < 3004
487
488 /* The functions floor_log2 and exact_log2 are defined as inline
489 functions in toplev.h if GCC_VERSION >= 3004. The definitions here
490 are used for older versions of gcc. */
491
492 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
493 If X is 0, return -1. */
494
495 int
496 floor_log2 (unsigned HOST_WIDE_INT x)
497 {
498 int t = 0;
499
500 if (x == 0)
501 return -1;
502
503 if (HOST_BITS_PER_WIDE_INT > 64)
504 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
505 t += 64;
506 if (HOST_BITS_PER_WIDE_INT > 32)
507 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
508 t += 32;
509 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
510 t += 16;
511 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
512 t += 8;
513 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
514 t += 4;
515 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
516 t += 2;
517 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
518 t += 1;
519
520 return t;
521 }
522
523 /* Return the logarithm of X, base 2, considering X unsigned,
524 if X is a power of 2. Otherwise, returns -1. */
525
526 int
527 exact_log2 (unsigned HOST_WIDE_INT x)
528 {
529 if (x != (x & -x))
530 return -1;
531 return floor_log2 (x);
532 }
533
534 #endif /* GCC_VERSION < 3004 */
535
536 /* Handler for fatal signals, such as SIGSEGV. These are transformed
537 into ICE messages, which is much more user friendly. In case the
538 error printer crashes, reset the signal to prevent infinite recursion. */
539
540 static void
541 crash_signal (int signo)
542 {
543 signal (signo, SIG_DFL);
544
545 /* If we crashed while processing an ASM statement, then be a little more
546 graceful. It's most likely the user's fault. */
547 if (this_is_asm_operands)
548 {
549 output_operand_lossage ("unrecoverable error");
550 exit (FATAL_EXIT_CODE);
551 }
552
553 internal_error ("%s", strsignal (signo));
554 }
555
556 /* Arrange to dump core on error. (The regular error message is still
557 printed first, except in the case of abort().) */
558
559 static void
560 setup_core_dumping (void)
561 {
562 #ifdef SIGABRT
563 signal (SIGABRT, SIG_DFL);
564 #endif
565 #if defined(HAVE_SETRLIMIT)
566 {
567 struct rlimit rlim;
568 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
569 fatal_error ("getting core file size maximum limit: %m");
570 rlim.rlim_cur = rlim.rlim_max;
571 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
572 fatal_error ("setting core file size limit to maximum: %m");
573 }
574 #endif
575 diagnostic_abort_on_error (global_dc);
576 }
577
578
579 /* Strip off a legitimate source ending from the input string NAME of
580 length LEN. Rather than having to know the names used by all of
581 our front ends, we strip off an ending of a period followed by
582 up to five characters. (Java uses ".class".) */
583
584 void
585 strip_off_ending (char *name, int len)
586 {
587 int i;
588 for (i = 2; i < 6 && len > i; i++)
589 {
590 if (name[len - i] == '.')
591 {
592 name[len - i] = '\0';
593 break;
594 }
595 }
596 }
597
598 /* Output a quoted string. */
599
600 void
601 output_quoted_string (FILE *asm_file, const char *string)
602 {
603 #ifdef OUTPUT_QUOTED_STRING
604 OUTPUT_QUOTED_STRING (asm_file, string);
605 #else
606 char c;
607
608 putc ('\"', asm_file);
609 while ((c = *string++) != 0)
610 {
611 if (ISPRINT (c))
612 {
613 if (c == '\"' || c == '\\')
614 putc ('\\', asm_file);
615 putc (c, asm_file);
616 }
617 else
618 fprintf (asm_file, "\\%03o", (unsigned char) c);
619 }
620 putc ('\"', asm_file);
621 #endif
622 }
623
624 /* Output a file name in the form wanted by System V. */
625
626 void
627 output_file_directive (FILE *asm_file, const char *input_name)
628 {
629 int len;
630 const char *na;
631
632 if (input_name == NULL)
633 input_name = "<stdin>";
634 else
635 input_name = remap_debug_filename (input_name);
636
637 len = strlen (input_name);
638 na = input_name + len;
639
640 /* NA gets INPUT_NAME sans directory names. */
641 while (na > input_name)
642 {
643 if (IS_DIR_SEPARATOR (na[-1]))
644 break;
645 na--;
646 }
647
648 #ifdef ASM_OUTPUT_SOURCE_FILENAME
649 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
650 #else
651 fprintf (asm_file, "\t.file\t");
652 output_quoted_string (asm_file, na);
653 putc ('\n', asm_file);
654 #endif
655 }
656
657 /* A subroutine of wrapup_global_declarations. We've come to the end of
658 the compilation unit. All deferred variables should be undeferred,
659 and all incomplete decls should be finalized. */
660
661 void
662 wrapup_global_declaration_1 (tree decl)
663 {
664 /* We're not deferring this any longer. Assignment is conditional to
665 avoid needlessly dirtying PCH pages. */
666 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
667 && DECL_DEFER_OUTPUT (decl) != 0)
668 DECL_DEFER_OUTPUT (decl) = 0;
669
670 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
671 lang_hooks.finish_incomplete_decl (decl);
672 }
673
674 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
675 needs to be output. Return true if it is output. */
676
677 bool
678 wrapup_global_declaration_2 (tree decl)
679 {
680 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
681 return false;
682
683 /* Don't write out static consts, unless we still need them.
684
685 We also keep static consts if not optimizing (for debugging),
686 unless the user specified -fno-keep-static-consts.
687 ??? They might be better written into the debug information.
688 This is possible when using DWARF.
689
690 A language processor that wants static constants to be always
691 written out (even if it is not used) is responsible for
692 calling rest_of_decl_compilation itself. E.g. the C front-end
693 calls rest_of_decl_compilation from finish_decl.
694 One motivation for this is that is conventional in some
695 environments to write things like:
696 static const char rcsid[] = "... version string ...";
697 intending to force the string to be in the executable.
698
699 A language processor that would prefer to have unneeded
700 static constants "optimized away" would just defer writing
701 them out until here. E.g. C++ does this, because static
702 constants are often defined in header files.
703
704 ??? A tempting alternative (for both C and C++) would be
705 to force a constant to be written if and only if it is
706 defined in a main file, as opposed to an include file. */
707
708 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
709 {
710 struct varpool_node *node;
711 bool needed = true;
712 node = varpool_get_node (decl);
713
714 if (!node && flag_ltrans)
715 needed = false;
716 else if (node && node->finalized)
717 needed = false;
718 else if (node && node->alias)
719 needed = false;
720 else if (!cgraph_global_info_ready
721 && (TREE_USED (decl)
722 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
723 /* needed */;
724 else if (node && node->needed)
725 /* needed */;
726 else if (DECL_COMDAT (decl))
727 needed = false;
728 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
729 && (optimize || !flag_keep_static_consts
730 || DECL_ARTIFICIAL (decl)))
731 needed = false;
732
733 if (needed)
734 {
735 rest_of_decl_compilation (decl, 1, 1);
736 return true;
737 }
738 }
739
740 return false;
741 }
742
743 /* Do any final processing required for the declarations in VEC, of
744 which there are LEN. We write out inline functions and variables
745 that have been deferred until this point, but which are required.
746 Returns nonzero if anything was put out. */
747
748 bool
749 wrapup_global_declarations (tree *vec, int len)
750 {
751 bool reconsider, output_something = false;
752 int i;
753
754 for (i = 0; i < len; i++)
755 wrapup_global_declaration_1 (vec[i]);
756
757 /* Now emit any global variables or functions that we have been
758 putting off. We need to loop in case one of the things emitted
759 here references another one which comes earlier in the list. */
760 do
761 {
762 reconsider = false;
763 for (i = 0; i < len; i++)
764 reconsider |= wrapup_global_declaration_2 (vec[i]);
765 if (reconsider)
766 output_something = true;
767 }
768 while (reconsider);
769
770 return output_something;
771 }
772
773 /* A subroutine of check_global_declarations. Issue appropriate warnings
774 for the global declaration DECL. */
775
776 void
777 check_global_declaration_1 (tree decl)
778 {
779 /* Warn about any function declared static but not defined. We don't
780 warn about variables, because many programs have static variables
781 that exist only to get some text into the object file. */
782 if (TREE_CODE (decl) == FUNCTION_DECL
783 && DECL_INITIAL (decl) == 0
784 && DECL_EXTERNAL (decl)
785 && ! DECL_ARTIFICIAL (decl)
786 && ! TREE_NO_WARNING (decl)
787 && ! TREE_PUBLIC (decl)
788 && (warn_unused_function
789 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
790 {
791 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
792 pedwarn (input_location, 0, "%q+F used but never defined", decl);
793 else
794 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
795 /* This symbol is effectively an "extern" declaration now. */
796 TREE_PUBLIC (decl) = 1;
797 assemble_external (decl);
798 }
799
800 /* Warn about static fns or vars defined but not used. */
801 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
802 /* We don't warn about "static const" variables because the
803 "rcs_id" idiom uses that construction. */
804 || (warn_unused_variable
805 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
806 && ! DECL_IN_SYSTEM_HEADER (decl)
807 && ! TREE_USED (decl)
808 /* The TREE_USED bit for file-scope decls is kept in the identifier,
809 to handle multiple external decls in different scopes. */
810 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
811 && ! DECL_EXTERNAL (decl)
812 && ! TREE_PUBLIC (decl)
813 /* A volatile variable might be used in some non-obvious way. */
814 && ! TREE_THIS_VOLATILE (decl)
815 /* Global register variables must be declared to reserve them. */
816 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
817 /* Otherwise, ask the language. */
818 && lang_hooks.decls.warn_unused_global (decl))
819 warning ((TREE_CODE (decl) == FUNCTION_DECL)
820 ? OPT_Wunused_function
821 : OPT_Wunused_variable,
822 "%q+D defined but not used", decl);
823 }
824
825 /* Issue appropriate warnings for the global declarations in VEC (of
826 which there are LEN). */
827
828 void
829 check_global_declarations (tree *vec, int len)
830 {
831 int i;
832
833 for (i = 0; i < len; i++)
834 check_global_declaration_1 (vec[i]);
835 }
836
837 /* Emit debugging information for all global declarations in VEC. */
838
839 void
840 emit_debug_global_declarations (tree *vec, int len)
841 {
842 int i;
843
844 /* Avoid confusing the debug information machinery when there are errors. */
845 if (seen_error ())
846 return;
847
848 timevar_push (TV_SYMOUT);
849 for (i = 0; i < len; i++)
850 debug_hooks->global_decl (vec[i]);
851 timevar_pop (TV_SYMOUT);
852 }
853
854 /* Warn about a use of an identifier which was marked deprecated. */
855 void
856 warn_deprecated_use (tree node, tree attr)
857 {
858 const char *msg;
859
860 if (node == 0 || !warn_deprecated_decl)
861 return;
862
863 if (!attr)
864 {
865 if (DECL_P (node))
866 attr = DECL_ATTRIBUTES (node);
867 else if (TYPE_P (node))
868 {
869 tree decl = TYPE_STUB_DECL (node);
870 if (decl)
871 attr = lookup_attribute ("deprecated",
872 TYPE_ATTRIBUTES (TREE_TYPE (decl)));
873 }
874 }
875
876 if (attr)
877 attr = lookup_attribute ("deprecated", attr);
878
879 if (attr)
880 msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
881 else
882 msg = NULL;
883
884 if (DECL_P (node))
885 {
886 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
887 if (msg)
888 warning (OPT_Wdeprecated_declarations,
889 "%qD is deprecated (declared at %s:%d): %s",
890 node, xloc.file, xloc.line, msg);
891 else
892 warning (OPT_Wdeprecated_declarations,
893 "%qD is deprecated (declared at %s:%d)",
894 node, xloc.file, xloc.line);
895 }
896 else if (TYPE_P (node))
897 {
898 tree what = NULL_TREE;
899 tree decl = TYPE_STUB_DECL (node);
900
901 if (TYPE_NAME (node))
902 {
903 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
904 what = TYPE_NAME (node);
905 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
906 && DECL_NAME (TYPE_NAME (node)))
907 what = DECL_NAME (TYPE_NAME (node));
908 }
909
910 if (decl)
911 {
912 expanded_location xloc
913 = expand_location (DECL_SOURCE_LOCATION (decl));
914 if (what)
915 {
916 if (msg)
917 warning (OPT_Wdeprecated_declarations,
918 "%qE is deprecated (declared at %s:%d): %s",
919 what, xloc.file, xloc.line, msg);
920 else
921 warning (OPT_Wdeprecated_declarations,
922 "%qE is deprecated (declared at %s:%d)", what,
923 xloc.file, xloc.line);
924 }
925 else
926 {
927 if (msg)
928 warning (OPT_Wdeprecated_declarations,
929 "type is deprecated (declared at %s:%d): %s",
930 xloc.file, xloc.line, msg);
931 else
932 warning (OPT_Wdeprecated_declarations,
933 "type is deprecated (declared at %s:%d)",
934 xloc.file, xloc.line);
935 }
936 }
937 else
938 {
939 if (what)
940 {
941 if (msg)
942 warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s",
943 what, msg);
944 else
945 warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what);
946 }
947 else
948 {
949 if (msg)
950 warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
951 msg);
952 else
953 warning (OPT_Wdeprecated_declarations, "type is deprecated");
954 }
955 }
956 }
957 }
958
959 /* Compile an entire translation unit. Write a file of assembly
960 output and various debugging dumps. */
961
962 static void
963 compile_file (void)
964 {
965 /* Initialize yet another pass. */
966
967 ggc_protect_identifiers = true;
968
969 init_cgraph ();
970 init_final (main_input_filename);
971 coverage_init (aux_base_name);
972 statistics_init ();
973 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
974
975 timevar_push (TV_PARSE);
976
977 /* Call the parser, which parses the entire file (calling
978 rest_of_compilation for each function). */
979 lang_hooks.parse_file (set_yydebug);
980
981 /* Compilation is now finished except for writing
982 what's left of the symbol table output. */
983 timevar_pop (TV_PARSE);
984
985 if (flag_syntax_only || flag_wpa)
986 return;
987
988 ggc_protect_identifiers = false;
989
990 /* This must also call cgraph_finalize_compilation_unit. */
991 lang_hooks.decls.final_write_globals ();
992
993 if (seen_error ())
994 return;
995
996 /* Ensure that emulated TLS control vars are finalized and build
997 a static constructor for them, when it is required. */
998 if (!targetm.have_tls)
999 emutls_finish ();
1000
1001 varpool_assemble_pending_decls ();
1002 finish_aliases_2 ();
1003
1004 /* Likewise for mudflap static object registrations. */
1005 if (flag_mudflap)
1006 mudflap_finish_file ();
1007
1008 output_shared_constant_pool ();
1009 output_object_blocks ();
1010
1011 /* Write out any pending weak symbol declarations. */
1012 weak_finish ();
1013
1014 /* This must be at the end before unwind and debug info.
1015 Some target ports emit PIC setup thunks here. */
1016 targetm.asm_out.code_end ();
1017
1018 /* Do dbx symbols. */
1019 timevar_push (TV_SYMOUT);
1020
1021 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
1022 if (dwarf2out_do_frame ())
1023 dwarf2out_frame_finish ();
1024 #endif
1025
1026 (*debug_hooks->finish) (main_input_filename);
1027 timevar_pop (TV_SYMOUT);
1028
1029 /* Output some stuff at end of file if nec. */
1030
1031 dw2_output_indirect_constants ();
1032
1033 /* Flush any pending external directives. */
1034 process_pending_assemble_externals ();
1035
1036 /* Emit LTO marker if LTO info has been previously emitted. This is
1037 used by collect2 to determine whether an object file contains IL.
1038 We used to emit an undefined reference here, but this produces
1039 link errors if an object file with IL is stored into a shared
1040 library without invoking lto1. */
1041 if (flag_generate_lto)
1042 {
1043 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1044 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
1045 "__gnu_lto_v1",
1046 (unsigned HOST_WIDE_INT) 1, 8);
1047 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1048 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1",
1049 (unsigned HOST_WIDE_INT) 1, 8);
1050 #else
1051 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1",
1052 (unsigned HOST_WIDE_INT) 1,
1053 (unsigned HOST_WIDE_INT) 1);
1054 #endif
1055 }
1056
1057 /* Attach a special .ident directive to the end of the file to identify
1058 the version of GCC which compiled this code. The format of the .ident
1059 string is patterned after the ones produced by native SVR4 compilers. */
1060 #ifdef IDENT_ASM_OP
1061 if (!flag_no_ident)
1062 {
1063 const char *pkg_version = "(GNU) ";
1064
1065 if (strcmp ("(GCC) ", pkgversion_string))
1066 pkg_version = pkgversion_string;
1067 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
1068 IDENT_ASM_OP, pkg_version, version_string);
1069 }
1070 #endif
1071
1072 /* Invoke registered plugin callbacks. */
1073 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
1074
1075 /* This must be at the end. Some target ports emit end of file directives
1076 into the assembly file here, and hence we can not output anything to the
1077 assembly file after this point. */
1078 targetm.asm_out.file_end ();
1079 }
1080
1081 /* Parse a -d... command line switch. */
1082
1083 void
1084 decode_d_option (const char *arg)
1085 {
1086 int c;
1087
1088 while (*arg)
1089 switch (c = *arg++)
1090 {
1091 case 'A':
1092 flag_debug_asm = 1;
1093 break;
1094 case 'p':
1095 flag_print_asm_name = 1;
1096 break;
1097 case 'P':
1098 flag_dump_rtl_in_asm = 1;
1099 flag_print_asm_name = 1;
1100 break;
1101 case 'v':
1102 graph_dump_format = vcg;
1103 break;
1104 case 'x':
1105 rtl_dump_and_exit = 1;
1106 break;
1107 case 'y':
1108 set_yydebug = 1;
1109 break;
1110 case 'D': /* These are handled by the preprocessor. */
1111 case 'I':
1112 case 'M':
1113 case 'N':
1114 case 'U':
1115 break;
1116 case 'H':
1117 setup_core_dumping();
1118 break;
1119 case 'a':
1120 enable_rtl_dump_file ();
1121 break;
1122
1123 default:
1124 warning (0, "unrecognized gcc debugging option: %c", c);
1125 break;
1126 }
1127 }
1128
1129 /* Indexed by enum debug_info_type. */
1130 const char *const debug_type_names[] =
1131 {
1132 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1133 };
1134
1135 /* Print version information to FILE.
1136 Each line begins with INDENT (for the case where FILE is the
1137 assembler output file). */
1138
1139 void
1140 print_version (FILE *file, const char *indent)
1141 {
1142 static const char fmt1[] =
1143 #ifdef __GNUC__
1144 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1145 #else
1146 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1147 #endif
1148 ;
1149 static const char fmt2[] =
1150 N_("GMP version %s, MPFR version %s, MPC version %s\n");
1151 static const char fmt3[] =
1152 N_("%s%swarning: %s header version %s differs from library version %s.\n");
1153 static const char fmt4[] =
1154 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1155 #ifndef __VERSION__
1156 #define __VERSION__ "[?]"
1157 #endif
1158 fprintf (file,
1159 file == stderr ? _(fmt1) : fmt1,
1160 indent, *indent != 0 ? " " : "",
1161 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
1162 indent, __VERSION__);
1163
1164 /* We need to stringify the GMP macro values. Ugh, gmp_version has
1165 two string formats, "i.j.k" and "i.j" when k is zero. As of
1166 gmp-4.3.0, GMP always uses the 3 number format. */
1167 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1168 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1169 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
1170 #define GCC_GMP_VERSION \
1171 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
1172 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
1173 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1174 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1175 #else
1176 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1177 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1178 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1179 #endif
1180 fprintf (file,
1181 file == stderr ? _(fmt2) : fmt2,
1182 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING);
1183 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
1184 fprintf (file,
1185 file == stderr ? _(fmt3) : fmt3,
1186 indent, *indent != 0 ? " " : "",
1187 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
1188 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
1189 fprintf (file,
1190 file == stderr ? _(fmt3) : fmt3,
1191 indent, *indent != 0 ? " " : "",
1192 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
1193 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
1194 fprintf (file,
1195 file == stderr ? _(fmt3) : fmt3,
1196 indent, *indent != 0 ? " " : "",
1197 "MPC", MPC_VERSION_STRING, mpc_get_version ());
1198 fprintf (file,
1199 file == stderr ? _(fmt4) : fmt4,
1200 indent, *indent != 0 ? " " : "",
1201 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1202
1203 print_plugins_versions (file, indent);
1204 }
1205
1206 #ifdef ASM_COMMENT_START
1207 static int
1208 print_to_asm_out_file (print_switch_type type, const char * text)
1209 {
1210 bool prepend_sep = true;
1211
1212 switch (type)
1213 {
1214 case SWITCH_TYPE_LINE_END:
1215 putc ('\n', asm_out_file);
1216 return 1;
1217
1218 case SWITCH_TYPE_LINE_START:
1219 fputs (ASM_COMMENT_START, asm_out_file);
1220 return strlen (ASM_COMMENT_START);
1221
1222 case SWITCH_TYPE_DESCRIPTIVE:
1223 if (ASM_COMMENT_START[0] == 0)
1224 prepend_sep = false;
1225 /* Drop through. */
1226 case SWITCH_TYPE_PASSED:
1227 case SWITCH_TYPE_ENABLED:
1228 if (prepend_sep)
1229 fputc (' ', asm_out_file);
1230 fputs (text, asm_out_file);
1231 /* No need to return the length here as
1232 print_single_switch has already done it. */
1233 return 0;
1234
1235 default:
1236 return -1;
1237 }
1238 }
1239 #endif
1240
1241 static int
1242 print_to_stderr (print_switch_type type, const char * text)
1243 {
1244 switch (type)
1245 {
1246 case SWITCH_TYPE_LINE_END:
1247 putc ('\n', stderr);
1248 return 1;
1249
1250 case SWITCH_TYPE_LINE_START:
1251 return 0;
1252
1253 case SWITCH_TYPE_PASSED:
1254 case SWITCH_TYPE_ENABLED:
1255 fputc (' ', stderr);
1256 /* Drop through. */
1257
1258 case SWITCH_TYPE_DESCRIPTIVE:
1259 fputs (text, stderr);
1260 /* No need to return the length here as
1261 print_single_switch has already done it. */
1262 return 0;
1263
1264 default:
1265 return -1;
1266 }
1267 }
1268
1269 /* Print an option value and return the adjusted position in the line.
1270 ??? print_fn doesn't handle errors, eg disk full; presumably other
1271 code will catch a disk full though. */
1272
1273 static int
1274 print_single_switch (print_switch_fn_type print_fn,
1275 int pos,
1276 print_switch_type type,
1277 const char * text)
1278 {
1279 /* The ultrix fprintf returns 0 on success, so compute the result
1280 we want here since we need it for the following test. The +1
1281 is for the separator character that will probably be emitted. */
1282 int len = strlen (text) + 1;
1283
1284 if (pos != 0
1285 && pos + len > MAX_LINE)
1286 {
1287 print_fn (SWITCH_TYPE_LINE_END, NULL);
1288 pos = 0;
1289 }
1290
1291 if (pos == 0)
1292 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1293
1294 print_fn (type, text);
1295 return pos + len;
1296 }
1297
1298 /* Print active target switches using PRINT_FN.
1299 POS is the current cursor position and MAX is the size of a "line".
1300 Each line begins with INDENT and ends with TERM.
1301 Each switch is separated from the next by SEP. */
1302
1303 static void
1304 print_switch_values (print_switch_fn_type print_fn)
1305 {
1306 int pos = 0;
1307 size_t j;
1308
1309 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1310 that it can be printed below. This helps reproducibility. */
1311 if (!flag_random_seed)
1312 init_random_seed ();
1313
1314 /* Print the options as passed. */
1315 pos = print_single_switch (print_fn, pos,
1316 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1317
1318 for (j = 1; j < save_decoded_options_count; j++)
1319 {
1320 switch (save_decoded_options[j].opt_index)
1321 {
1322 case OPT_o:
1323 case OPT_d:
1324 case OPT_dumpbase:
1325 case OPT_dumpdir:
1326 case OPT_auxbase:
1327 case OPT_quiet:
1328 case OPT_version:
1329 /* Ignore these. */
1330 continue;
1331 }
1332
1333 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED,
1334 save_decoded_options[j].orig_option_with_args_text);
1335 }
1336
1337 if (pos > 0)
1338 print_fn (SWITCH_TYPE_LINE_END, NULL);
1339
1340 /* Print the -f and -m options that have been enabled.
1341 We don't handle language specific options but printing argv
1342 should suffice. */
1343 pos = print_single_switch (print_fn, 0,
1344 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1345
1346 for (j = 0; j < cl_options_count; j++)
1347 if ((cl_options[j].flags & CL_REPORT)
1348 && option_enabled (j) > 0)
1349 pos = print_single_switch (print_fn, pos,
1350 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1351
1352 print_fn (SWITCH_TYPE_LINE_END, NULL);
1353 }
1354
1355 /* Open assembly code output file. Do this even if -fsyntax-only is
1356 on, because then the driver will have provided the name of a
1357 temporary file or bit bucket for us. NAME is the file specified on
1358 the command line, possibly NULL. */
1359 static void
1360 init_asm_output (const char *name)
1361 {
1362 if (name == NULL && asm_file_name == 0)
1363 asm_out_file = stdout;
1364 else
1365 {
1366 if (asm_file_name == 0)
1367 {
1368 int len = strlen (dump_base_name);
1369 char *dumpname = XNEWVEC (char, len + 6);
1370
1371 memcpy (dumpname, dump_base_name, len + 1);
1372 strip_off_ending (dumpname, len);
1373 strcat (dumpname, ".s");
1374 asm_file_name = dumpname;
1375 }
1376 if (!strcmp (asm_file_name, "-"))
1377 asm_out_file = stdout;
1378 else
1379 asm_out_file = fopen (asm_file_name, "w+b");
1380 if (asm_out_file == 0)
1381 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1382 }
1383
1384 if (!flag_syntax_only)
1385 {
1386 targetm.asm_out.file_start ();
1387
1388 if (flag_record_gcc_switches)
1389 {
1390 if (targetm.asm_out.record_gcc_switches)
1391 {
1392 /* Let the target know that we are about to start recording. */
1393 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1394 NULL);
1395 /* Now record the switches. */
1396 print_switch_values (targetm.asm_out.record_gcc_switches);
1397 /* Let the target know that the recording is over. */
1398 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1399 NULL);
1400 }
1401 else
1402 inform (input_location, "-frecord-gcc-switches is not supported by the current target");
1403 }
1404
1405 #ifdef ASM_COMMENT_START
1406 if (flag_verbose_asm)
1407 {
1408 /* Print the list of switches in effect
1409 into the assembler file as comments. */
1410 print_version (asm_out_file, ASM_COMMENT_START);
1411 print_switch_values (print_to_asm_out_file);
1412 putc ('\n', asm_out_file);
1413 }
1414 #endif
1415 }
1416 }
1417
1418 /* Return true if the state of option OPTION should be stored in PCH files
1419 and checked by default_pch_valid_p. Store the option's current state
1420 in STATE if so. */
1421
1422 static inline bool
1423 option_affects_pch_p (int option, struct cl_option_state *state)
1424 {
1425 if ((cl_options[option].flags & CL_TARGET) == 0)
1426 return false;
1427 if (cl_options[option].flag_var == &target_flags)
1428 if (targetm.check_pch_target_flags)
1429 return false;
1430 return get_option_state (option, state);
1431 }
1432
1433 /* Default version of get_pch_validity.
1434 By default, every flag difference is fatal; that will be mostly right for
1435 most targets, but completely right for very few. */
1436
1437 void *
1438 default_get_pch_validity (size_t *sz)
1439 {
1440 struct cl_option_state state;
1441 size_t i;
1442 char *result, *r;
1443
1444 *sz = 2;
1445 if (targetm.check_pch_target_flags)
1446 *sz += sizeof (target_flags);
1447 for (i = 0; i < cl_options_count; i++)
1448 if (option_affects_pch_p (i, &state))
1449 *sz += state.size;
1450
1451 result = r = XNEWVEC (char, *sz);
1452 r[0] = flag_pic;
1453 r[1] = flag_pie;
1454 r += 2;
1455 if (targetm.check_pch_target_flags)
1456 {
1457 memcpy (r, &target_flags, sizeof (target_flags));
1458 r += sizeof (target_flags);
1459 }
1460
1461 for (i = 0; i < cl_options_count; i++)
1462 if (option_affects_pch_p (i, &state))
1463 {
1464 memcpy (r, state.data, state.size);
1465 r += state.size;
1466 }
1467
1468 return result;
1469 }
1470
1471 /* Return a message which says that a PCH file was created with a different
1472 setting of OPTION. */
1473
1474 static const char *
1475 pch_option_mismatch (const char *option)
1476 {
1477 char *r;
1478
1479 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1480 if (r == NULL)
1481 return _("out of memory");
1482 return r;
1483 }
1484
1485 /* Default version of pch_valid_p. */
1486
1487 const char *
1488 default_pch_valid_p (const void *data_p, size_t len)
1489 {
1490 struct cl_option_state state;
1491 const char *data = (const char *)data_p;
1492 size_t i;
1493
1494 /* -fpic and -fpie also usually make a PCH invalid. */
1495 if (data[0] != flag_pic)
1496 return _("created and used with different settings of -fpic");
1497 if (data[1] != flag_pie)
1498 return _("created and used with different settings of -fpie");
1499 data += 2;
1500
1501 /* Check target_flags. */
1502 if (targetm.check_pch_target_flags)
1503 {
1504 int tf;
1505 const char *r;
1506
1507 memcpy (&tf, data, sizeof (target_flags));
1508 data += sizeof (target_flags);
1509 len -= sizeof (target_flags);
1510 r = targetm.check_pch_target_flags (tf);
1511 if (r != NULL)
1512 return r;
1513 }
1514
1515 for (i = 0; i < cl_options_count; i++)
1516 if (option_affects_pch_p (i, &state))
1517 {
1518 if (memcmp (data, state.data, state.size) != 0)
1519 return pch_option_mismatch (cl_options[i].opt_text);
1520 data += state.size;
1521 len -= state.size;
1522 }
1523
1524 return NULL;
1525 }
1526
1527 /* Default tree printer. Handles declarations only. */
1528 bool
1529 default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
1530 int precision, bool wide, bool set_locus, bool hash)
1531 {
1532 tree t;
1533
1534 /* FUTURE: %+x should set the locus. */
1535 if (precision != 0 || wide || hash)
1536 return false;
1537
1538 switch (*spec)
1539 {
1540 case 'E':
1541 t = va_arg (*text->args_ptr, tree);
1542 if (TREE_CODE (t) == IDENTIFIER_NODE)
1543 {
1544 pp_identifier (pp, IDENTIFIER_POINTER (t));
1545 return true;
1546 }
1547 break;
1548
1549 case 'D':
1550 t = va_arg (*text->args_ptr, tree);
1551 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1552 t = DECL_DEBUG_EXPR (t);
1553 break;
1554
1555 case 'F':
1556 case 'T':
1557 t = va_arg (*text->args_ptr, tree);
1558 break;
1559
1560 case 'K':
1561 percent_K_format (text);
1562 return true;
1563
1564 default:
1565 return false;
1566 }
1567
1568 if (set_locus && text->locus)
1569 *text->locus = DECL_SOURCE_LOCATION (t);
1570
1571 if (DECL_P (t))
1572 {
1573 const char *n = DECL_NAME (t)
1574 ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2))
1575 : _("<anonymous>");
1576 pp_string (pp, n);
1577 }
1578 else
1579 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1580
1581 return true;
1582 }
1583
1584 /* A helper function; used as the reallocator function for cpp's line
1585 table. */
1586 static void *
1587 realloc_for_line_map (void *ptr, size_t len)
1588 {
1589 return GGC_RESIZEVAR (void, ptr, len);
1590 }
1591
1592 /* A helper function: used as the allocator function for
1593 identifier_to_locale. */
1594 static void *
1595 alloc_for_identifier_to_locale (size_t len)
1596 {
1597 return ggc_alloc_atomic (len);
1598 }
1599
1600 /* Initialization of the front end environment, before command line
1601 options are parsed. Signal handlers, internationalization etc.
1602 ARGV0 is main's argv[0]. */
1603 static void
1604 general_init (const char *argv0)
1605 {
1606 const char *p;
1607
1608 p = argv0 + strlen (argv0);
1609 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1610 --p;
1611 progname = p;
1612
1613 xmalloc_set_program_name (progname);
1614
1615 hex_init ();
1616
1617 /* Unlock the stdio streams. */
1618 unlock_std_streams ();
1619
1620 gcc_init_libintl ();
1621
1622 identifier_to_locale_alloc = alloc_for_identifier_to_locale;
1623 identifier_to_locale_free = ggc_free;
1624
1625 /* Initialize the diagnostics reporting machinery, so option parsing
1626 can give warnings and errors. */
1627 diagnostic_initialize (global_dc, N_OPTS);
1628 diagnostic_starter (global_dc) = default_tree_diagnostic_starter;
1629 /* Set a default printer. Language specific initializations will
1630 override it later. */
1631 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1632 global_dc->show_option_requested = flag_diagnostics_show_option;
1633 global_dc->show_column = flag_show_column;
1634 global_dc->internal_error = plugins_internal_error_function;
1635 global_dc->option_enabled = option_enabled;
1636 global_dc->option_name = option_name;
1637
1638 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1639 #ifdef SIGSEGV
1640 signal (SIGSEGV, crash_signal);
1641 #endif
1642 #ifdef SIGILL
1643 signal (SIGILL, crash_signal);
1644 #endif
1645 #ifdef SIGBUS
1646 signal (SIGBUS, crash_signal);
1647 #endif
1648 #ifdef SIGABRT
1649 signal (SIGABRT, crash_signal);
1650 #endif
1651 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1652 signal (SIGIOT, crash_signal);
1653 #endif
1654 #ifdef SIGFPE
1655 signal (SIGFPE, crash_signal);
1656 #endif
1657
1658 /* Other host-specific signal setup. */
1659 (*host_hooks.extra_signals)();
1660
1661 /* Initialize the garbage-collector, string pools and tree type hash
1662 table. */
1663 init_ggc ();
1664 init_stringpool ();
1665 line_table = ggc_alloc_line_maps ();
1666 linemap_init (line_table);
1667 line_table->reallocator = realloc_for_line_map;
1668 init_ttree ();
1669
1670 /* Initialize register usage now so switches may override. */
1671 init_reg_sets ();
1672
1673 /* Register the language-independent parameters. */
1674 add_params (lang_independent_params, LAST_PARAM);
1675
1676 /* This must be done after add_params but before argument processing. */
1677 init_ggc_heuristics();
1678 init_optimization_passes ();
1679 statistics_early_init ();
1680 }
1681
1682 /* Return true if the current target supports -fsection-anchors. */
1683
1684 static bool
1685 target_supports_section_anchors_p (void)
1686 {
1687 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1688 return false;
1689
1690 if (targetm.asm_out.output_anchor == NULL)
1691 return false;
1692
1693 return true;
1694 }
1695
1696 /* Default the align_* variables to 1 if they're still unset, and
1697 set up the align_*_log variables. */
1698 static void
1699 init_alignments (void)
1700 {
1701 if (align_loops <= 0)
1702 align_loops = 1;
1703 if (align_loops_max_skip > align_loops)
1704 align_loops_max_skip = align_loops - 1;
1705 align_loops_log = floor_log2 (align_loops * 2 - 1);
1706 if (align_jumps <= 0)
1707 align_jumps = 1;
1708 if (align_jumps_max_skip > align_jumps)
1709 align_jumps_max_skip = align_jumps - 1;
1710 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1711 if (align_labels <= 0)
1712 align_labels = 1;
1713 align_labels_log = floor_log2 (align_labels * 2 - 1);
1714 if (align_labels_max_skip > align_labels)
1715 align_labels_max_skip = align_labels - 1;
1716 if (align_functions <= 0)
1717 align_functions = 1;
1718 align_functions_log = floor_log2 (align_functions * 2 - 1);
1719 }
1720
1721 /* Process the options that have been parsed. */
1722 static void
1723 process_options (void)
1724 {
1725 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1726 This can happen with incorrect pre-processed input. */
1727 debug_hooks = &do_nothing_debug_hooks;
1728
1729 /* This replaces set_Wunused. */
1730 if (warn_unused_function == -1)
1731 warn_unused_function = warn_unused;
1732 if (warn_unused_label == -1)
1733 warn_unused_label = warn_unused;
1734 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */
1735 if (warn_unused_parameter == -1)
1736 warn_unused_parameter = (warn_unused && extra_warnings);
1737 if (warn_unused_variable == -1)
1738 warn_unused_variable = warn_unused;
1739 /* Wunused-but-set-parameter is enabled if both -Wunused -Wextra are
1740 enabled. */
1741 if (warn_unused_but_set_parameter == -1)
1742 warn_unused_but_set_parameter = (warn_unused && extra_warnings);
1743 if (warn_unused_but_set_variable == -1)
1744 warn_unused_but_set_variable = warn_unused;
1745 if (warn_unused_value == -1)
1746 warn_unused_value = warn_unused;
1747
1748 /* This replaces set_Wextra. */
1749 if (warn_uninitialized == -1)
1750 warn_uninitialized = extra_warnings;
1751
1752 /* Allow the front end to perform consistency checks and do further
1753 initialization based on the command line options. This hook also
1754 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1755 so we can correctly initialize debug output. */
1756 no_backend = lang_hooks.post_options (&main_input_filename);
1757
1758 /* Some machines may reject certain combinations of options. */
1759 targetm.target_option.override ();
1760
1761 /* Avoid any informative notes in the second run of -fcompare-debug. */
1762 if (flag_compare_debug)
1763 diagnostic_inhibit_notes (global_dc);
1764
1765 if (flag_section_anchors && !target_supports_section_anchors_p ())
1766 {
1767 warning (OPT_fsection_anchors,
1768 "this target does not support %qs", "-fsection-anchors");
1769 flag_section_anchors = 0;
1770 }
1771
1772 if (flag_short_enums == 2)
1773 flag_short_enums = targetm.default_short_enums ();
1774
1775 /* Set aux_base_name if not already set. */
1776 if (aux_base_name)
1777 ;
1778 else if (main_input_filename)
1779 {
1780 char *name = xstrdup (lbasename (main_input_filename));
1781
1782 strip_off_ending (name, strlen (name));
1783 aux_base_name = name;
1784 }
1785 else
1786 aux_base_name = "gccaux";
1787
1788 #ifndef HAVE_cloog
1789 if (flag_graphite
1790 || flag_loop_block
1791 || flag_loop_interchange
1792 || flag_loop_strip_mine
1793 || flag_graphite_identity
1794 || flag_loop_parallelize_all)
1795 sorry ("Graphite loop optimizations cannot be used");
1796 #endif
1797
1798 /* Unrolling all loops implies that standard loop unrolling must also
1799 be done. */
1800 if (flag_unroll_all_loops)
1801 flag_unroll_loops = 1;
1802
1803 /* The loop unrolling code assumes that cse will be run after loop.
1804 web and rename-registers also help when run after loop unrolling. */
1805 if (flag_rerun_cse_after_loop == AUTODETECT_VALUE)
1806 flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops;
1807
1808 if (flag_web == AUTODETECT_VALUE)
1809 flag_web = flag_unroll_loops || flag_peel_loops;
1810
1811 if (flag_rename_registers == AUTODETECT_VALUE)
1812 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1813
1814 if (flag_non_call_exceptions)
1815 flag_asynchronous_unwind_tables = 1;
1816 if (flag_asynchronous_unwind_tables)
1817 flag_unwind_tables = 1;
1818
1819 if (flag_value_profile_transformations)
1820 flag_profile_values = 1;
1821
1822 /* Warn about options that are not supported on this machine. */
1823 #ifndef INSN_SCHEDULING
1824 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1825 warning (0, "instruction scheduling not supported on this target machine");
1826 #endif
1827 #ifndef DELAY_SLOTS
1828 if (flag_delayed_branch)
1829 warning (0, "this target machine does not have delayed branches");
1830 #endif
1831
1832 user_label_prefix = USER_LABEL_PREFIX;
1833 if (flag_leading_underscore != -1)
1834 {
1835 /* If the default prefix is more complicated than "" or "_",
1836 issue a warning and ignore this option. */
1837 if (user_label_prefix[0] == 0 ||
1838 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1839 {
1840 user_label_prefix = flag_leading_underscore ? "_" : "";
1841 }
1842 else
1843 warning (0, "-f%sleading-underscore not supported on this target machine",
1844 flag_leading_underscore ? "" : "no-");
1845 }
1846
1847 /* If we are in verbose mode, write out the version and maybe all the
1848 option flags in use. */
1849 if (version_flag)
1850 {
1851 print_version (stderr, "");
1852 if (! quiet_flag)
1853 print_switch_values (print_to_stderr);
1854 }
1855
1856 if (flag_syntax_only)
1857 {
1858 write_symbols = NO_DEBUG;
1859 profile_flag = 0;
1860 }
1861
1862 if (flag_gtoggle)
1863 {
1864 if (debug_info_level == DINFO_LEVEL_NONE)
1865 {
1866 debug_info_level = DINFO_LEVEL_NORMAL;
1867
1868 if (write_symbols == NO_DEBUG)
1869 write_symbols = PREFERRED_DEBUGGING_TYPE;
1870 }
1871 else
1872 debug_info_level = DINFO_LEVEL_NONE;
1873 }
1874
1875 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1876 {
1877 FILE *final_output = fopen (flag_dump_final_insns, "w");
1878 if (!final_output)
1879 {
1880 error ("could not open final insn dump file %qs: %m",
1881 flag_dump_final_insns);
1882 flag_dump_final_insns = NULL;
1883 }
1884 else if (fclose (final_output))
1885 {
1886 error ("could not close zeroed insn dump file %qs: %m",
1887 flag_dump_final_insns);
1888 flag_dump_final_insns = NULL;
1889 }
1890 }
1891
1892 /* Unless over-ridden for the target, assume that all DWARF levels
1893 may be emitted, if DWARF2_DEBUG is selected. */
1894 if (dwarf_strict < 0)
1895 dwarf_strict = 0;
1896
1897 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1898 level is 0. */
1899 if (debug_info_level == DINFO_LEVEL_NONE)
1900 write_symbols = NO_DEBUG;
1901
1902 if (write_symbols == NO_DEBUG)
1903 ;
1904 #if defined(DBX_DEBUGGING_INFO)
1905 else if (write_symbols == DBX_DEBUG)
1906 debug_hooks = &dbx_debug_hooks;
1907 #endif
1908 #if defined(XCOFF_DEBUGGING_INFO)
1909 else if (write_symbols == XCOFF_DEBUG)
1910 debug_hooks = &xcoff_debug_hooks;
1911 #endif
1912 #ifdef SDB_DEBUGGING_INFO
1913 else if (write_symbols == SDB_DEBUG)
1914 debug_hooks = &sdb_debug_hooks;
1915 #endif
1916 #ifdef DWARF2_DEBUGGING_INFO
1917 else if (write_symbols == DWARF2_DEBUG)
1918 debug_hooks = &dwarf2_debug_hooks;
1919 #endif
1920 #ifdef VMS_DEBUGGING_INFO
1921 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1922 debug_hooks = &vmsdbg_debug_hooks;
1923 #endif
1924 else
1925 error ("target system does not support the \"%s\" debug format",
1926 debug_type_names[write_symbols]);
1927
1928 /* We know which debug output will be used so we can set flag_var_tracking
1929 and flag_var_tracking_uninit if the user has not specified them. */
1930 if (debug_info_level < DINFO_LEVEL_NORMAL
1931 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1932 {
1933 if (flag_var_tracking == 1
1934 || flag_var_tracking_uninit == 1)
1935 {
1936 if (debug_info_level < DINFO_LEVEL_NORMAL)
1937 warning (0, "variable tracking requested, but useless unless "
1938 "producing debug info");
1939 else
1940 warning (0, "variable tracking requested, but not supported "
1941 "by this debug format");
1942 }
1943 flag_var_tracking = 0;
1944 flag_var_tracking_uninit = 0;
1945 }
1946
1947 /* If the user specifically requested variable tracking with tagging
1948 uninitialized variables, we need to turn on variable tracking.
1949 (We already determined above that variable tracking is feasible.) */
1950 if (flag_var_tracking_uninit)
1951 flag_var_tracking = 1;
1952
1953 if (flag_var_tracking == AUTODETECT_VALUE)
1954 flag_var_tracking = optimize >= 1;
1955
1956 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
1957 flag_var_tracking_assignments = flag_var_tracking
1958 && !(flag_selective_scheduling || flag_selective_scheduling2);
1959
1960 if (flag_var_tracking_assignments_toggle)
1961 flag_var_tracking_assignments = !flag_var_tracking_assignments;
1962
1963 if (flag_var_tracking_assignments && !flag_var_tracking)
1964 flag_var_tracking = flag_var_tracking_assignments = -1;
1965
1966 if (flag_var_tracking_assignments
1967 && (flag_selective_scheduling || flag_selective_scheduling2))
1968 warning (0, "var-tracking-assignments changes selective scheduling");
1969
1970 if (flag_tree_cselim == AUTODETECT_VALUE)
1971 #ifdef HAVE_conditional_move
1972 flag_tree_cselim = 1;
1973 #else
1974 flag_tree_cselim = 0;
1975 #endif
1976
1977 /* If auxiliary info generation is desired, open the output file.
1978 This goes in the same directory as the source file--unlike
1979 all the other output files. */
1980 if (flag_gen_aux_info)
1981 {
1982 aux_info_file = fopen (aux_info_file_name, "w");
1983 if (aux_info_file == 0)
1984 fatal_error ("can%'t open %s: %m", aux_info_file_name);
1985 }
1986
1987 if (! targetm.have_named_sections)
1988 {
1989 if (flag_function_sections)
1990 {
1991 warning (0, "-ffunction-sections not supported for this target");
1992 flag_function_sections = 0;
1993 }
1994 if (flag_data_sections)
1995 {
1996 warning (0, "-fdata-sections not supported for this target");
1997 flag_data_sections = 0;
1998 }
1999 }
2000
2001 if (flag_function_sections && profile_flag)
2002 {
2003 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
2004 flag_function_sections = 0;
2005 }
2006
2007 #ifndef HAVE_prefetch
2008 if (flag_prefetch_loop_arrays > 0)
2009 {
2010 warning (0, "-fprefetch-loop-arrays not supported for this target");
2011 flag_prefetch_loop_arrays = 0;
2012 }
2013 #else
2014 if (flag_prefetch_loop_arrays > 0 && !HAVE_prefetch)
2015 {
2016 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
2017 flag_prefetch_loop_arrays = 0;
2018 }
2019 #endif
2020
2021 /* This combination of options isn't handled for i386 targets and doesn't
2022 make much sense anyway, so don't allow it. */
2023 if (flag_prefetch_loop_arrays > 0 && optimize_size)
2024 {
2025 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
2026 flag_prefetch_loop_arrays = 0;
2027 }
2028
2029 /* The presence of IEEE signaling NaNs, implies all math can trap. */
2030 if (flag_signaling_nans)
2031 flag_trapping_math = 1;
2032
2033 /* We cannot reassociate if we want traps or signed zeros. */
2034 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
2035 {
2036 warning (0, "-fassociative-math disabled; other options take precedence");
2037 flag_associative_math = 0;
2038 }
2039
2040 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
2041 if (flag_cx_limited_range)
2042 flag_complex_method = 0;
2043
2044 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
2045 if (flag_cx_fortran_rules)
2046 flag_complex_method = 1;
2047
2048 /* Targets must be able to place spill slots at lower addresses. If the
2049 target already uses a soft frame pointer, the transition is trivial. */
2050 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
2051 {
2052 warning (0, "-fstack-protector not supported for this target");
2053 flag_stack_protect = 0;
2054 }
2055 if (!flag_stack_protect)
2056 warn_stack_protect = 0;
2057
2058 /* ??? Unwind info is not correct around the CFG unless either a frame
2059 pointer is present or A_O_A is set. Fixing this requires rewriting
2060 unwind info generation to be aware of the CFG and propagating states
2061 around edges. */
2062 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
2063 && flag_omit_frame_pointer)
2064 {
2065 warning (0, "unwind tables currently require a frame pointer "
2066 "for correctness");
2067 flag_omit_frame_pointer = 0;
2068 }
2069
2070 /* Save the current optimization options. */
2071 optimization_default_node = build_optimization_node ();
2072 optimization_current_node = optimization_default_node;
2073 }
2074
2075 /* This function can be called multiple times to reinitialize the compiler
2076 back end when register classes or instruction sets have changed,
2077 before each function. */
2078 static void
2079 backend_init_target (void)
2080 {
2081 /* Initialize alignment variables. */
2082 init_alignments ();
2083
2084 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
2085 to initialize reg_raw_mode[]. */
2086 init_emit_regs ();
2087
2088 /* This invokes target hooks to set fixed_reg[] etc, which is
2089 mode-dependent. */
2090 init_regs ();
2091
2092 /* This depends on stack_pointer_rtx. */
2093 init_fake_stack_mems ();
2094
2095 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
2096 mode-dependent. */
2097 init_alias_target ();
2098
2099 /* Depends on HARD_FRAME_POINTER_REGNUM. */
2100 init_reload ();
2101
2102 /* The following initialization functions need to generate rtl, so
2103 provide a dummy function context for them. */
2104 init_dummy_function_start ();
2105
2106 /* rtx_cost is mode-dependent, so cached values need to be recomputed
2107 on a mode change. */
2108 init_expmed ();
2109
2110 /* We may need to recompute regno_save_code[] and regno_restore_code[]
2111 after a mode change as well. */
2112 caller_save_initialized_p = false;
2113
2114 expand_dummy_function_end ();
2115 }
2116
2117 /* Initialize the compiler back end. This function is called only once,
2118 when starting the compiler. */
2119 static void
2120 backend_init (void)
2121 {
2122 init_emit_once ();
2123
2124 init_rtlanal ();
2125 init_inline_once ();
2126 init_varasm_once ();
2127 save_register_info ();
2128
2129 /* Initialize the target-specific back end pieces. */
2130 ira_init_once ();
2131 backend_init_target ();
2132 }
2133
2134 /* Initialize excess precision settings. */
2135 static void
2136 init_excess_precision (void)
2137 {
2138 /* Adjust excess precision handling based on the target options. If
2139 the front end cannot handle it, flag_excess_precision_cmdline
2140 will already have been set accordingly in the post_options
2141 hook. */
2142 gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
2143 flag_excess_precision = flag_excess_precision_cmdline;
2144 if (flag_unsafe_math_optimizations)
2145 flag_excess_precision = EXCESS_PRECISION_FAST;
2146 if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
2147 {
2148 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
2149 switch (flt_eval_method)
2150 {
2151 case -1:
2152 case 0:
2153 /* Either the target acts unpredictably (-1) or has all the
2154 operations required not to have excess precision (0). */
2155 flag_excess_precision = EXCESS_PRECISION_FAST;
2156 break;
2157 case 1:
2158 case 2:
2159 /* In these cases, predictable excess precision makes
2160 sense. */
2161 break;
2162 default:
2163 /* Any other implementation-defined FLT_EVAL_METHOD values
2164 require the compiler to handle the associated excess
2165 precision rules in excess_precision_type. */
2166 gcc_unreachable ();
2167 }
2168 }
2169 }
2170
2171 /* Initialize things that are both lang-dependent and target-dependent.
2172 This function can be called more than once if target parameters change. */
2173 static void
2174 lang_dependent_init_target (void)
2175 {
2176 /* This determines excess precision settings. */
2177 init_excess_precision ();
2178
2179 /* This creates various _DECL nodes, so needs to be called after the
2180 front end is initialized. It also depends on the HAVE_xxx macros
2181 generated from the target machine description. */
2182 init_optabs ();
2183
2184 /* The following initialization functions need to generate rtl, so
2185 provide a dummy function context for them. */
2186 init_dummy_function_start ();
2187
2188 /* Do the target-specific parts of expr initialization. */
2189 init_expr_target ();
2190
2191 /* Although the actions of these functions are language-independent,
2192 they use optabs, so we cannot call them from backend_init. */
2193 init_set_costs ();
2194 ira_init ();
2195
2196 expand_dummy_function_end ();
2197 }
2198
2199 /* Language-dependent initialization. Returns nonzero on success. */
2200 static int
2201 lang_dependent_init (const char *name)
2202 {
2203 location_t save_loc = input_location;
2204 if (dump_base_name == 0)
2205 dump_base_name = name && name[0] ? name : "gccdump";
2206
2207 /* Other front-end initialization. */
2208 input_location = BUILTINS_LOCATION;
2209 if (lang_hooks.init () == 0)
2210 return 0;
2211 input_location = save_loc;
2212
2213 init_asm_output (name);
2214
2215 /* This creates various _DECL nodes, so needs to be called after the
2216 front end is initialized. */
2217 init_eh ();
2218
2219 /* Do the target-specific parts of the initialization. */
2220 lang_dependent_init_target ();
2221
2222 /* If dbx symbol table desired, initialize writing it and output the
2223 predefined types. */
2224 timevar_push (TV_SYMOUT);
2225
2226 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2227 if (dwarf2out_do_frame ())
2228 dwarf2out_frame_init ();
2229 #endif
2230
2231 /* Now we have the correct original filename, we can initialize
2232 debug output. */
2233 (*debug_hooks->init) (name);
2234
2235 timevar_pop (TV_SYMOUT);
2236
2237 return 1;
2238 }
2239
2240
2241 /* Reinitialize everything when target parameters, such as register usage,
2242 have changed. */
2243 void
2244 target_reinit (void)
2245 {
2246 /* Reinitialize RTL backend. */
2247 backend_init_target ();
2248
2249 /* Reinitialize lang-dependent parts. */
2250 lang_dependent_init_target ();
2251 }
2252
2253 void
2254 dump_memory_report (bool final)
2255 {
2256 ggc_print_statistics ();
2257 stringpool_statistics ();
2258 dump_tree_statistics ();
2259 dump_gimple_statistics ();
2260 dump_rtx_statistics ();
2261 dump_alloc_pool_statistics ();
2262 dump_bitmap_statistics ();
2263 dump_vec_loc_statistics ();
2264 dump_ggc_loc_statistics (final);
2265 dump_alias_stats (stderr);
2266 dump_pta_stats (stderr);
2267 }
2268
2269 /* Clean up: close opened files, etc. */
2270
2271 static void
2272 finalize (void)
2273 {
2274 /* Close the dump files. */
2275 if (flag_gen_aux_info)
2276 {
2277 fclose (aux_info_file);
2278 if (seen_error ())
2279 unlink (aux_info_file_name);
2280 }
2281
2282 /* Close non-debugging input and output files. Take special care to note
2283 whether fclose returns an error, since the pages might still be on the
2284 buffer chain while the file is open. */
2285
2286 if (asm_out_file)
2287 {
2288 if (ferror (asm_out_file) != 0)
2289 fatal_error ("error writing to %s: %m", asm_file_name);
2290 if (fclose (asm_out_file) != 0)
2291 fatal_error ("error closing %s: %m", asm_file_name);
2292 if (flag_wpa)
2293 unlink_if_ordinary (asm_file_name);
2294 }
2295
2296 statistics_fini ();
2297 finish_optimization_passes ();
2298
2299 ira_finish_once ();
2300
2301 if (mem_report)
2302 dump_memory_report (true);
2303
2304 /* Language-specific end of compilation actions. */
2305 lang_hooks.finish ();
2306 }
2307
2308 /* Initialize the compiler, and compile the input file. */
2309 static void
2310 do_compile (void)
2311 {
2312 /* Initialize timing first. The C front ends read the main file in
2313 the post_options hook, and C++ does file timings. */
2314 if (time_report || !quiet_flag || flag_detailed_statistics)
2315 timevar_init ();
2316 timevar_start (TV_TOTAL);
2317
2318 process_options ();
2319
2320 /* Don't do any more if an error has already occurred. */
2321 if (!seen_error ())
2322 {
2323 /* This must be run always, because it is needed to compute the FP
2324 predefined macros, such as __LDBL_MAX__, for targets using non
2325 default FP formats. */
2326 init_adjust_machine_modes ();
2327
2328 /* Set up the back-end if requested. */
2329 if (!no_backend)
2330 backend_init ();
2331
2332 /* Language-dependent initialization. Returns true on success. */
2333 if (lang_dependent_init (main_input_filename))
2334 compile_file ();
2335
2336 finalize ();
2337 }
2338
2339 /* Stop timing and print the times. */
2340 timevar_stop (TV_TOTAL);
2341 timevar_print (stderr);
2342 }
2343
2344 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2345 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2346 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2347
2348 It is not safe to call this function more than once. */
2349
2350 int
2351 toplev_main (int argc, char **argv)
2352 {
2353 expandargv (&argc, &argv);
2354
2355 /* Initialization of GCC's environment, and diagnostics. */
2356 general_init (argv[0]);
2357
2358 /* Parse the options and do minimal processing; basically just
2359 enough to default flags appropriately. */
2360 decode_options (argc, CONST_CAST2 (const char **, char **, argv),
2361 &save_decoded_options, &save_decoded_options_count);
2362
2363 init_local_tick ();
2364
2365 initialize_plugins ();
2366
2367 if (version_flag)
2368 print_version (stderr, "");
2369
2370 if (help_flag)
2371 print_plugins_help (stderr, "");
2372
2373 /* Exit early if we can (e.g. -help). */
2374 if (!exit_after_options)
2375 do_compile ();
2376
2377 if (warningcount || errorcount)
2378 print_ignored_options ();
2379 diagnostic_finish (global_dc);
2380
2381 /* Invoke registered plugin callbacks if any. */
2382 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2383
2384 finalize_plugins ();
2385 if (seen_error ())
2386 return (FATAL_EXIT_CODE);
2387
2388 return (SUCCESS_EXIT_CODE);
2389 }