Fix PR/46316
[official-gcc.git] / gcc / toplev.c
blob596fb89832e3ee53aa8685394ad6acae255b8cbd
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.
6 This file is part of GCC.
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.
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.
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/>. */
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. */
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include <signal.h>
33 #ifdef HAVE_SYS_RESOURCE_H
34 # include <sys/resource.h>
35 #endif
37 #ifdef HAVE_SYS_TIMES_H
38 # include <sys/times.h>
39 #endif
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"
91 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
92 #include "dwarf2out.h"
93 #endif
95 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
96 #include "dbxout.h"
97 #endif
99 #ifdef SDB_DEBUGGING_INFO
100 #include "sdbout.h"
101 #endif
103 #ifdef XCOFF_DEBUGGING_INFO
104 #include "xcoffout.h" /* Needed for external data
105 declarations for e.g. AIX 4.x. */
106 #endif
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);
116 static void crash_signal (int) ATTRIBUTE_NORETURN;
117 static void setup_core_dumping (void);
118 static void compile_file (void);
120 /* Nonzero to dump debug info whilst parsing (-dy option). */
121 static int set_yydebug;
123 /* True if we don't need a backend (e.g. preprocessing only). */
124 static bool no_backend;
126 /* Length of line when printing switch values. */
127 #define MAX_LINE 75
129 /* Decoded options, and number of such options. */
130 struct cl_decoded_option *save_decoded_options;
131 unsigned int save_decoded_options_count;
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. */
137 const char *main_input_filename;
139 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
140 to optimize in process_options (). */
141 #define AUTODETECT_VALUE 2
143 /* Name to use as base of names for dump output files. */
145 const char *dump_base_name;
147 /* Directory used for dump output files. */
149 const char *dump_dir_name;
151 /* Name to use as a base for auxiliary output files. */
153 const char *aux_base_name;
155 /* Prefix for profile data files */
156 const char *profile_data_prefix;
158 /* Debug hooks - dependent upon command line options. */
160 const struct gcc_debug_hooks *debug_hooks;
162 /* Other flags saying which kinds of debugging dump have been requested. */
164 int rtl_dump_and_exit;
165 int flag_print_asm_name;
166 enum graph_dump_types graph_dump_format;
168 /* Name for output file of assembly code, specified with -o. */
170 const char *asm_file_name;
172 /* True if this is the lto front end. This is used to disable
173 gimple generation and lowering passes that are normally run on the
174 output of a front end. These passes must be bypassed for lto since
175 they have already been done before the gimple was written. */
177 bool in_lto_p = false;
179 /* Nonzero if we should write GIMPLE bytecode for link-time optimization. */
181 int flag_generate_lto;
183 /* The FUNCTION_DECL for the function currently being compiled,
184 or 0 if between functions. */
185 tree current_function_decl;
187 /* Set to the FUNC_BEGIN label of the current function, or NULL
188 if none. */
189 const char * current_function_func_begin_label;
191 /* A random sequence of characters, unless overridden by user. */
192 static const char *flag_random_seed;
194 /* A local time stamp derived from the time of compilation. It will be
195 zero if the system cannot provide a time. It will be -1u, if the
196 user has specified a particular random seed. */
197 unsigned local_tick;
199 /* -f flags. */
201 /* Nonzero means we should be saving declaration info into a .X file. */
203 int flag_gen_aux_info = 0;
205 /* Specified name of aux-info file. */
207 const char *aux_info_file_name;
209 /* Nonzero if we are compiling code for a shared library, zero for
210 executable. */
212 int flag_shlib;
214 /* Generate code for GNU or NeXT Objective-C runtime environment. */
216 #ifdef NEXT_OBJC_RUNTIME
217 int flag_next_runtime = 1;
218 #else
219 int flag_next_runtime = 0;
220 #endif
222 /* Set to the default thread-local storage (tls) model to use. */
224 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
226 /* Set the default for excess precision. */
228 enum excess_precision flag_excess_precision_cmdline = EXCESS_PRECISION_DEFAULT;
230 /* Nonzero means change certain warnings into errors.
231 Usually these are warnings about failure to conform to some standard. */
233 int flag_pedantic_errors = 0;
235 /* Nonzero means make permerror produce warnings instead of errors. */
237 int flag_permissive = 0;
239 /* -dA causes debug commentary information to be produced in
240 the generated assembly code (to make it more readable). This option
241 is generally only of use to those who actually need to read the
242 generated assembly code (perhaps while debugging the compiler itself).
243 Currently, this switch is only used by dwarfout.c; however, it is intended
244 to be a catchall for printing debug information in the assembler file. */
246 int flag_debug_asm = 0;
248 /* -dP causes the rtl to be emitted as a comment in assembly. */
250 int flag_dump_rtl_in_asm = 0;
252 /* When non-NULL, indicates that whenever space is allocated on the
253 stack, the resulting stack pointer must not pass this
254 address---that is, for stacks that grow downward, the stack pointer
255 must always be greater than or equal to this address; for stacks
256 that grow upward, the stack pointer must be less than this address.
257 At present, the rtx may be either a REG or a SYMBOL_REF, although
258 the support provided depends on the backend. */
259 rtx stack_limit_rtx;
261 /* Type of stack check. */
262 enum stack_check_type flag_stack_check = NO_STACK_CHECK;
264 /* True if the user has tagged the function with the 'section'
265 attribute. */
267 bool user_defined_section_attribute = false;
269 struct target_flag_state default_target_flag_state;
270 #if SWITCHABLE_TARGET
271 struct target_flag_state *this_target_flag_state = &default_target_flag_state;
272 #else
273 #define this_target_flag_state (&default_target_flag_state)
274 #endif
276 typedef struct
278 const char *const string;
279 int *const variable;
280 const int on_value;
282 lang_independent_options;
284 /* The user symbol prefix after having resolved same. */
285 const char *user_label_prefix;
287 static const param_info lang_independent_params[] = {
288 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
289 { OPTION, DEFAULT, MIN, MAX, HELP },
290 #include "params.def"
291 #undef DEFPARAM
292 { NULL, 0, 0, 0, NULL }
295 /* Output files for assembler code (real compiler output)
296 and debugging dumps. */
298 FILE *asm_out_file;
299 FILE *aux_info_file;
300 FILE *stack_usage_file = NULL;
301 FILE *dump_file = NULL;
302 const char *dump_file_name;
304 /* The current working directory of a translation. It's generally the
305 directory from which compilation was initiated, but a preprocessed
306 file may specify the original directory in which it was
307 created. */
309 static const char *src_pwd;
311 /* Initialize src_pwd with the given string, and return true. If it
312 was already initialized, return false. As a special case, it may
313 be called with a NULL argument to test whether src_pwd has NOT been
314 initialized yet. */
316 bool
317 set_src_pwd (const char *pwd)
319 if (src_pwd)
321 if (strcmp (src_pwd, pwd) == 0)
322 return true;
323 else
324 return false;
327 src_pwd = xstrdup (pwd);
328 return true;
331 /* Return the directory from which the translation unit was initiated,
332 in case set_src_pwd() was not called before to assign it a
333 different value. */
335 const char *
336 get_src_pwd (void)
338 if (! src_pwd)
340 src_pwd = getpwd ();
341 if (!src_pwd)
342 src_pwd = ".";
345 return src_pwd;
348 /* Called when the start of a function definition is parsed,
349 this function prints on stderr the name of the function. */
350 void
351 announce_function (tree decl)
353 if (!quiet_flag)
355 if (rtl_dump_and_exit)
356 fprintf (stderr, "%s ",
357 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
358 else
359 fprintf (stderr, " %s",
360 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
361 fflush (stderr);
362 pp_needs_newline (global_dc->printer) = true;
363 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
367 /* Initialize local_tick with the time of day, or -1 if
368 flag_random_seed is set. */
370 static void
371 init_local_tick (void)
373 if (!flag_random_seed)
375 /* Get some more or less random data. */
376 #ifdef HAVE_GETTIMEOFDAY
378 struct timeval tv;
380 gettimeofday (&tv, NULL);
381 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
383 #else
385 time_t now = time (NULL);
387 if (now != (time_t)-1)
388 local_tick = (unsigned) now;
390 #endif
392 else
393 local_tick = -1;
396 /* Set up a default flag_random_seed and local_tick, unless the user
397 already specified one. Must be called after init_local_tick. */
399 static void
400 init_random_seed (void)
402 unsigned HOST_WIDE_INT value;
403 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
405 value = local_tick ^ getpid ();
407 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
408 flag_random_seed = random_seed;
411 /* Obtain the random_seed string. Unless NOINIT, initialize it if
412 it's not provided in the command line. */
414 const char *
415 get_random_seed (bool noinit)
417 if (!flag_random_seed && !noinit)
418 init_random_seed ();
419 return flag_random_seed;
422 /* Modify the random_seed string to VAL. Return its previous
423 value. */
425 const char *
426 set_random_seed (const char *val)
428 const char *old = flag_random_seed;
429 flag_random_seed = val;
430 return old;
433 #if GCC_VERSION < 3004
435 /* The functions clz_hwi, ctz_hwi, ffs_hwi, floor_log2 and exact_log2
436 are defined as inline functions in toplev.h if GCC_VERSION >= 3004.
437 The definitions here are used for older versions of gcc. */
439 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
440 If X is 0, return -1. */
443 floor_log2 (unsigned HOST_WIDE_INT x)
445 int t = 0;
447 if (x == 0)
448 return -1;
450 if (HOST_BITS_PER_WIDE_INT > 64)
451 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
452 t += 64;
453 if (HOST_BITS_PER_WIDE_INT > 32)
454 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
455 t += 32;
456 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
457 t += 16;
458 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
459 t += 8;
460 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
461 t += 4;
462 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
463 t += 2;
464 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
465 t += 1;
467 return t;
470 /* Return the logarithm of X, base 2, considering X unsigned,
471 if X is a power of 2. Otherwise, returns -1. */
474 exact_log2 (unsigned HOST_WIDE_INT x)
476 if (x != (x & -x))
477 return -1;
478 return floor_log2 (x);
481 /* Given X, an unsigned number, return the number of least significant bits
482 that are zero. When X == 0, the result is the word size. */
485 ctz_hwi (unsigned HOST_WIDE_INT x)
487 return x ? floor_log2 (x & -x) : HOST_BITS_PER_WIDE_INT;
490 /* Similarly for most significant bits. */
493 clz_hwi (unsigned HOST_WIDE_INT x)
495 return HOST_BITS_PER_WIDE_INT - 1 - floor_log2(x);
498 /* Similar to ctz_hwi, except that the least significant bit is numbered
499 starting from 1, and X == 0 yields 0. */
502 ffs_hwi (unsigned HOST_WIDE_INT x)
504 return 1 + floor_log2 (x & -x);
507 #endif /* GCC_VERSION < 3004 */
509 /* Handler for fatal signals, such as SIGSEGV. These are transformed
510 into ICE messages, which is much more user friendly. In case the
511 error printer crashes, reset the signal to prevent infinite recursion. */
513 static void
514 crash_signal (int signo)
516 signal (signo, SIG_DFL);
518 /* If we crashed while processing an ASM statement, then be a little more
519 graceful. It's most likely the user's fault. */
520 if (this_is_asm_operands)
522 output_operand_lossage ("unrecoverable error");
523 exit (FATAL_EXIT_CODE);
526 internal_error ("%s", strsignal (signo));
529 /* Arrange to dump core on error. (The regular error message is still
530 printed first, except in the case of abort().) */
532 static void
533 setup_core_dumping (void)
535 #ifdef SIGABRT
536 signal (SIGABRT, SIG_DFL);
537 #endif
538 #if defined(HAVE_SETRLIMIT)
540 struct rlimit rlim;
541 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
542 fatal_error ("getting core file size maximum limit: %m");
543 rlim.rlim_cur = rlim.rlim_max;
544 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
545 fatal_error ("setting core file size limit to maximum: %m");
547 #endif
548 diagnostic_abort_on_error (global_dc);
552 /* Strip off a legitimate source ending from the input string NAME of
553 length LEN. Rather than having to know the names used by all of
554 our front ends, we strip off an ending of a period followed by
555 up to five characters. (Java uses ".class".) */
557 void
558 strip_off_ending (char *name, int len)
560 int i;
561 for (i = 2; i < 6 && len > i; i++)
563 if (name[len - i] == '.')
565 name[len - i] = '\0';
566 break;
571 /* Output a quoted string. */
573 void
574 output_quoted_string (FILE *asm_file, const char *string)
576 #ifdef OUTPUT_QUOTED_STRING
577 OUTPUT_QUOTED_STRING (asm_file, string);
578 #else
579 char c;
581 putc ('\"', asm_file);
582 while ((c = *string++) != 0)
584 if (ISPRINT (c))
586 if (c == '\"' || c == '\\')
587 putc ('\\', asm_file);
588 putc (c, asm_file);
590 else
591 fprintf (asm_file, "\\%03o", (unsigned char) c);
593 putc ('\"', asm_file);
594 #endif
597 /* A subroutine of wrapup_global_declarations. We've come to the end of
598 the compilation unit. All deferred variables should be undeferred,
599 and all incomplete decls should be finalized. */
601 void
602 wrapup_global_declaration_1 (tree decl)
604 /* We're not deferring this any longer. Assignment is conditional to
605 avoid needlessly dirtying PCH pages. */
606 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
607 && DECL_DEFER_OUTPUT (decl) != 0)
608 DECL_DEFER_OUTPUT (decl) = 0;
610 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
611 lang_hooks.finish_incomplete_decl (decl);
614 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
615 needs to be output. Return true if it is output. */
617 bool
618 wrapup_global_declaration_2 (tree decl)
620 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
621 return false;
623 /* Don't write out static consts, unless we still need them.
625 We also keep static consts if not optimizing (for debugging),
626 unless the user specified -fno-keep-static-consts.
627 ??? They might be better written into the debug information.
628 This is possible when using DWARF.
630 A language processor that wants static constants to be always
631 written out (even if it is not used) is responsible for
632 calling rest_of_decl_compilation itself. E.g. the C front-end
633 calls rest_of_decl_compilation from finish_decl.
634 One motivation for this is that is conventional in some
635 environments to write things like:
636 static const char rcsid[] = "... version string ...";
637 intending to force the string to be in the executable.
639 A language processor that would prefer to have unneeded
640 static constants "optimized away" would just defer writing
641 them out until here. E.g. C++ does this, because static
642 constants are often defined in header files.
644 ??? A tempting alternative (for both C and C++) would be
645 to force a constant to be written if and only if it is
646 defined in a main file, as opposed to an include file. */
648 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
650 struct varpool_node *node;
651 bool needed = true;
652 node = varpool_get_node (decl);
654 if (!node && flag_ltrans)
655 needed = false;
656 else if (node && node->finalized)
657 needed = false;
658 else if (node && node->alias)
659 needed = false;
660 else if (!cgraph_global_info_ready
661 && (TREE_USED (decl)
662 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
663 /* needed */;
664 else if (node && node->needed)
665 /* needed */;
666 else if (DECL_COMDAT (decl))
667 needed = false;
668 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
669 && (optimize || !flag_keep_static_consts
670 || DECL_ARTIFICIAL (decl)))
671 needed = false;
673 if (needed)
675 rest_of_decl_compilation (decl, 1, 1);
676 return true;
680 return false;
683 /* Do any final processing required for the declarations in VEC, of
684 which there are LEN. We write out inline functions and variables
685 that have been deferred until this point, but which are required.
686 Returns nonzero if anything was put out. */
688 bool
689 wrapup_global_declarations (tree *vec, int len)
691 bool reconsider, output_something = false;
692 int i;
694 for (i = 0; i < len; i++)
695 wrapup_global_declaration_1 (vec[i]);
697 /* Now emit any global variables or functions that we have been
698 putting off. We need to loop in case one of the things emitted
699 here references another one which comes earlier in the list. */
702 reconsider = false;
703 for (i = 0; i < len; i++)
704 reconsider |= wrapup_global_declaration_2 (vec[i]);
705 if (reconsider)
706 output_something = true;
708 while (reconsider);
710 return output_something;
713 /* A subroutine of check_global_declarations. Issue appropriate warnings
714 for the global declaration DECL. */
716 void
717 check_global_declaration_1 (tree decl)
719 /* Warn about any function declared static but not defined. We don't
720 warn about variables, because many programs have static variables
721 that exist only to get some text into the object file. */
722 if (TREE_CODE (decl) == FUNCTION_DECL
723 && DECL_INITIAL (decl) == 0
724 && DECL_EXTERNAL (decl)
725 && ! DECL_ARTIFICIAL (decl)
726 && ! TREE_NO_WARNING (decl)
727 && ! TREE_PUBLIC (decl)
728 && (warn_unused_function
729 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
731 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
732 pedwarn (input_location, 0, "%q+F used but never defined", decl);
733 else
734 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
735 /* This symbol is effectively an "extern" declaration now. */
736 TREE_PUBLIC (decl) = 1;
737 assemble_external (decl);
740 /* Warn about static fns or vars defined but not used. */
741 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
742 /* We don't warn about "static const" variables because the
743 "rcs_id" idiom uses that construction. */
744 || (warn_unused_variable
745 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
746 && ! DECL_IN_SYSTEM_HEADER (decl)
747 && ! TREE_USED (decl)
748 /* The TREE_USED bit for file-scope decls is kept in the identifier,
749 to handle multiple external decls in different scopes. */
750 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
751 && ! DECL_EXTERNAL (decl)
752 && ! TREE_PUBLIC (decl)
753 /* A volatile variable might be used in some non-obvious way. */
754 && ! TREE_THIS_VOLATILE (decl)
755 /* Global register variables must be declared to reserve them. */
756 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
757 /* Otherwise, ask the language. */
758 && lang_hooks.decls.warn_unused_global (decl))
759 warning ((TREE_CODE (decl) == FUNCTION_DECL)
760 ? OPT_Wunused_function
761 : OPT_Wunused_variable,
762 "%q+D defined but not used", decl);
765 /* Issue appropriate warnings for the global declarations in VEC (of
766 which there are LEN). */
768 void
769 check_global_declarations (tree *vec, int len)
771 int i;
773 for (i = 0; i < len; i++)
774 check_global_declaration_1 (vec[i]);
777 /* Emit debugging information for all global declarations in VEC. */
779 void
780 emit_debug_global_declarations (tree *vec, int len)
782 int i;
784 /* Avoid confusing the debug information machinery when there are errors. */
785 if (seen_error ())
786 return;
788 timevar_push (TV_SYMOUT);
789 for (i = 0; i < len; i++)
790 debug_hooks->global_decl (vec[i]);
791 timevar_pop (TV_SYMOUT);
794 /* Warn about a use of an identifier which was marked deprecated. */
795 void
796 warn_deprecated_use (tree node, tree attr)
798 const char *msg;
800 if (node == 0 || !warn_deprecated_decl)
801 return;
803 if (!attr)
805 if (DECL_P (node))
806 attr = DECL_ATTRIBUTES (node);
807 else if (TYPE_P (node))
809 tree decl = TYPE_STUB_DECL (node);
810 if (decl)
811 attr = lookup_attribute ("deprecated",
812 TYPE_ATTRIBUTES (TREE_TYPE (decl)));
816 if (attr)
817 attr = lookup_attribute ("deprecated", attr);
819 if (attr)
820 msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
821 else
822 msg = NULL;
824 if (DECL_P (node))
826 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
827 if (msg)
828 warning (OPT_Wdeprecated_declarations,
829 "%qD is deprecated (declared at %s:%d): %s",
830 node, xloc.file, xloc.line, msg);
831 else
832 warning (OPT_Wdeprecated_declarations,
833 "%qD is deprecated (declared at %s:%d)",
834 node, xloc.file, xloc.line);
836 else if (TYPE_P (node))
838 tree what = NULL_TREE;
839 tree decl = TYPE_STUB_DECL (node);
841 if (TYPE_NAME (node))
843 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
844 what = TYPE_NAME (node);
845 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
846 && DECL_NAME (TYPE_NAME (node)))
847 what = DECL_NAME (TYPE_NAME (node));
850 if (decl)
852 expanded_location xloc
853 = expand_location (DECL_SOURCE_LOCATION (decl));
854 if (what)
856 if (msg)
857 warning (OPT_Wdeprecated_declarations,
858 "%qE is deprecated (declared at %s:%d): %s",
859 what, xloc.file, xloc.line, msg);
860 else
861 warning (OPT_Wdeprecated_declarations,
862 "%qE is deprecated (declared at %s:%d)", what,
863 xloc.file, xloc.line);
865 else
867 if (msg)
868 warning (OPT_Wdeprecated_declarations,
869 "type is deprecated (declared at %s:%d): %s",
870 xloc.file, xloc.line, msg);
871 else
872 warning (OPT_Wdeprecated_declarations,
873 "type is deprecated (declared at %s:%d)",
874 xloc.file, xloc.line);
877 else
879 if (what)
881 if (msg)
882 warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s",
883 what, msg);
884 else
885 warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what);
887 else
889 if (msg)
890 warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
891 msg);
892 else
893 warning (OPT_Wdeprecated_declarations, "type is deprecated");
899 /* Compile an entire translation unit. Write a file of assembly
900 output and various debugging dumps. */
902 static void
903 compile_file (void)
905 /* Initialize yet another pass. */
907 ggc_protect_identifiers = true;
909 init_cgraph ();
910 init_final (main_input_filename);
911 coverage_init (aux_base_name);
912 statistics_init ();
913 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
915 timevar_push (TV_PARSE);
917 /* Call the parser, which parses the entire file (calling
918 rest_of_compilation for each function). */
919 lang_hooks.parse_file (set_yydebug);
921 /* Compilation is now finished except for writing
922 what's left of the symbol table output. */
923 timevar_pop (TV_PARSE);
925 if (flag_syntax_only || flag_wpa)
926 return;
928 ggc_protect_identifiers = false;
930 /* This must also call cgraph_finalize_compilation_unit. */
931 lang_hooks.decls.final_write_globals ();
933 if (seen_error ())
934 return;
936 varpool_assemble_pending_decls ();
937 finish_aliases_2 ();
939 /* Likewise for mudflap static object registrations. */
940 if (flag_mudflap)
941 mudflap_finish_file ();
943 output_shared_constant_pool ();
944 output_object_blocks ();
946 /* Write out any pending weak symbol declarations. */
947 weak_finish ();
949 /* This must be at the end before unwind and debug info.
950 Some target ports emit PIC setup thunks here. */
951 targetm.asm_out.code_end ();
953 /* Do dbx symbols. */
954 timevar_push (TV_SYMOUT);
956 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
957 if (dwarf2out_do_frame ())
958 dwarf2out_frame_finish ();
959 #endif
961 (*debug_hooks->finish) (main_input_filename);
962 timevar_pop (TV_SYMOUT);
964 /* Output some stuff at end of file if nec. */
966 dw2_output_indirect_constants ();
968 /* Flush any pending external directives. */
969 process_pending_assemble_externals ();
971 /* Emit LTO marker if LTO info has been previously emitted. This is
972 used by collect2 to determine whether an object file contains IL.
973 We used to emit an undefined reference here, but this produces
974 link errors if an object file with IL is stored into a shared
975 library without invoking lto1. */
976 if (flag_generate_lto)
978 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
979 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
980 "__gnu_lto_v1",
981 (unsigned HOST_WIDE_INT) 1, 8);
982 #elif defined ASM_OUTPUT_ALIGNED_COMMON
983 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1",
984 (unsigned HOST_WIDE_INT) 1, 8);
985 #else
986 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1",
987 (unsigned HOST_WIDE_INT) 1,
988 (unsigned HOST_WIDE_INT) 1);
989 #endif
992 /* Attach a special .ident directive to the end of the file to identify
993 the version of GCC which compiled this code. The format of the .ident
994 string is patterned after the ones produced by native SVR4 compilers. */
995 #ifdef IDENT_ASM_OP
996 if (!flag_no_ident)
998 const char *pkg_version = "(GNU) ";
1000 if (strcmp ("(GCC) ", pkgversion_string))
1001 pkg_version = pkgversion_string;
1002 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
1003 IDENT_ASM_OP, pkg_version, version_string);
1005 #endif
1007 /* Invoke registered plugin callbacks. */
1008 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
1010 /* This must be at the end. Some target ports emit end of file directives
1011 into the assembly file here, and hence we can not output anything to the
1012 assembly file after this point. */
1013 targetm.asm_out.file_end ();
1016 /* Parse a -d... command line switch. */
1018 void
1019 decode_d_option (const char *arg)
1021 int c;
1023 while (*arg)
1024 switch (c = *arg++)
1026 case 'A':
1027 flag_debug_asm = 1;
1028 break;
1029 case 'p':
1030 flag_print_asm_name = 1;
1031 break;
1032 case 'P':
1033 flag_dump_rtl_in_asm = 1;
1034 flag_print_asm_name = 1;
1035 break;
1036 case 'v':
1037 graph_dump_format = vcg;
1038 break;
1039 case 'x':
1040 rtl_dump_and_exit = 1;
1041 break;
1042 case 'y':
1043 set_yydebug = 1;
1044 break;
1045 case 'D': /* These are handled by the preprocessor. */
1046 case 'I':
1047 case 'M':
1048 case 'N':
1049 case 'U':
1050 break;
1051 case 'H':
1052 setup_core_dumping();
1053 break;
1054 case 'a':
1055 enable_rtl_dump_file ();
1056 break;
1058 default:
1059 warning (0, "unrecognized gcc debugging option: %c", c);
1060 break;
1064 /* Indexed by enum debug_info_type. */
1065 const char *const debug_type_names[] =
1067 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1070 /* Print version information to FILE.
1071 Each line begins with INDENT (for the case where FILE is the
1072 assembler output file). */
1074 void
1075 print_version (FILE *file, const char *indent)
1077 static const char fmt1[] =
1078 #ifdef __GNUC__
1079 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1080 #else
1081 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1082 #endif
1084 static const char fmt2[] =
1085 N_("GMP version %s, MPFR version %s, MPC version %s\n");
1086 static const char fmt3[] =
1087 N_("%s%swarning: %s header version %s differs from library version %s.\n");
1088 static const char fmt4[] =
1089 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1090 #ifndef __VERSION__
1091 #define __VERSION__ "[?]"
1092 #endif
1093 fprintf (file,
1094 file == stderr ? _(fmt1) : fmt1,
1095 indent, *indent != 0 ? " " : "",
1096 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
1097 indent, __VERSION__);
1099 /* We need to stringify the GMP macro values. Ugh, gmp_version has
1100 two string formats, "i.j.k" and "i.j" when k is zero. As of
1101 gmp-4.3.0, GMP always uses the 3 number format. */
1102 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1103 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1104 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
1105 #define GCC_GMP_VERSION \
1106 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
1107 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
1108 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1109 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1110 #else
1111 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1112 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1113 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1114 #endif
1115 fprintf (file,
1116 file == stderr ? _(fmt2) : fmt2,
1117 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING);
1118 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
1119 fprintf (file,
1120 file == stderr ? _(fmt3) : fmt3,
1121 indent, *indent != 0 ? " " : "",
1122 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
1123 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
1124 fprintf (file,
1125 file == stderr ? _(fmt3) : fmt3,
1126 indent, *indent != 0 ? " " : "",
1127 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
1128 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
1129 fprintf (file,
1130 file == stderr ? _(fmt3) : fmt3,
1131 indent, *indent != 0 ? " " : "",
1132 "MPC", MPC_VERSION_STRING, mpc_get_version ());
1133 fprintf (file,
1134 file == stderr ? _(fmt4) : fmt4,
1135 indent, *indent != 0 ? " " : "",
1136 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1138 print_plugins_versions (file, indent);
1141 #ifdef ASM_COMMENT_START
1142 static int
1143 print_to_asm_out_file (print_switch_type type, const char * text)
1145 bool prepend_sep = true;
1147 switch (type)
1149 case SWITCH_TYPE_LINE_END:
1150 putc ('\n', asm_out_file);
1151 return 1;
1153 case SWITCH_TYPE_LINE_START:
1154 fputs (ASM_COMMENT_START, asm_out_file);
1155 return strlen (ASM_COMMENT_START);
1157 case SWITCH_TYPE_DESCRIPTIVE:
1158 if (ASM_COMMENT_START[0] == 0)
1159 prepend_sep = false;
1160 /* Drop through. */
1161 case SWITCH_TYPE_PASSED:
1162 case SWITCH_TYPE_ENABLED:
1163 if (prepend_sep)
1164 fputc (' ', asm_out_file);
1165 fputs (text, asm_out_file);
1166 /* No need to return the length here as
1167 print_single_switch has already done it. */
1168 return 0;
1170 default:
1171 return -1;
1174 #endif
1176 static int
1177 print_to_stderr (print_switch_type type, const char * text)
1179 switch (type)
1181 case SWITCH_TYPE_LINE_END:
1182 putc ('\n', stderr);
1183 return 1;
1185 case SWITCH_TYPE_LINE_START:
1186 return 0;
1188 case SWITCH_TYPE_PASSED:
1189 case SWITCH_TYPE_ENABLED:
1190 fputc (' ', stderr);
1191 /* Drop through. */
1193 case SWITCH_TYPE_DESCRIPTIVE:
1194 fputs (text, stderr);
1195 /* No need to return the length here as
1196 print_single_switch has already done it. */
1197 return 0;
1199 default:
1200 return -1;
1204 /* Print an option value and return the adjusted position in the line.
1205 ??? print_fn doesn't handle errors, eg disk full; presumably other
1206 code will catch a disk full though. */
1208 static int
1209 print_single_switch (print_switch_fn_type print_fn,
1210 int pos,
1211 print_switch_type type,
1212 const char * text)
1214 /* The ultrix fprintf returns 0 on success, so compute the result
1215 we want here since we need it for the following test. The +1
1216 is for the separator character that will probably be emitted. */
1217 int len = strlen (text) + 1;
1219 if (pos != 0
1220 && pos + len > MAX_LINE)
1222 print_fn (SWITCH_TYPE_LINE_END, NULL);
1223 pos = 0;
1226 if (pos == 0)
1227 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1229 print_fn (type, text);
1230 return pos + len;
1233 /* Print active target switches using PRINT_FN.
1234 POS is the current cursor position and MAX is the size of a "line".
1235 Each line begins with INDENT and ends with TERM.
1236 Each switch is separated from the next by SEP. */
1238 static void
1239 print_switch_values (print_switch_fn_type print_fn)
1241 int pos = 0;
1242 size_t j;
1244 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1245 that it can be printed below. This helps reproducibility. */
1246 if (!flag_random_seed)
1247 init_random_seed ();
1249 /* Print the options as passed. */
1250 pos = print_single_switch (print_fn, pos,
1251 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1253 for (j = 1; j < save_decoded_options_count; j++)
1255 switch (save_decoded_options[j].opt_index)
1257 case OPT_o:
1258 case OPT_d:
1259 case OPT_dumpbase:
1260 case OPT_dumpdir:
1261 case OPT_auxbase:
1262 case OPT_quiet:
1263 case OPT_version:
1264 /* Ignore these. */
1265 continue;
1268 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED,
1269 save_decoded_options[j].orig_option_with_args_text);
1272 if (pos > 0)
1273 print_fn (SWITCH_TYPE_LINE_END, NULL);
1275 /* Print the -f and -m options that have been enabled.
1276 We don't handle language specific options but printing argv
1277 should suffice. */
1278 pos = print_single_switch (print_fn, 0,
1279 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1281 for (j = 0; j < cl_options_count; j++)
1282 if ((cl_options[j].flags & CL_REPORT)
1283 && option_enabled (j, &global_options) > 0)
1284 pos = print_single_switch (print_fn, pos,
1285 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1287 print_fn (SWITCH_TYPE_LINE_END, NULL);
1290 /* Open assembly code output file. Do this even if -fsyntax-only is
1291 on, because then the driver will have provided the name of a
1292 temporary file or bit bucket for us. NAME is the file specified on
1293 the command line, possibly NULL. */
1294 static void
1295 init_asm_output (const char *name)
1297 if (name == NULL && asm_file_name == 0)
1298 asm_out_file = stdout;
1299 else
1301 if (asm_file_name == 0)
1303 int len = strlen (dump_base_name);
1304 char *dumpname = XNEWVEC (char, len + 6);
1306 memcpy (dumpname, dump_base_name, len + 1);
1307 strip_off_ending (dumpname, len);
1308 strcat (dumpname, ".s");
1309 asm_file_name = dumpname;
1311 if (!strcmp (asm_file_name, "-"))
1312 asm_out_file = stdout;
1313 else
1314 asm_out_file = fopen (asm_file_name, "w+b");
1315 if (asm_out_file == 0)
1316 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1319 if (!flag_syntax_only)
1321 targetm.asm_out.file_start ();
1323 if (flag_record_gcc_switches)
1325 if (targetm.asm_out.record_gcc_switches)
1327 /* Let the target know that we are about to start recording. */
1328 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1329 NULL);
1330 /* Now record the switches. */
1331 print_switch_values (targetm.asm_out.record_gcc_switches);
1332 /* Let the target know that the recording is over. */
1333 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1334 NULL);
1336 else
1337 inform (input_location, "-frecord-gcc-switches is not supported by the current target");
1340 #ifdef ASM_COMMENT_START
1341 if (flag_verbose_asm)
1343 /* Print the list of switches in effect
1344 into the assembler file as comments. */
1345 print_version (asm_out_file, ASM_COMMENT_START);
1346 print_switch_values (print_to_asm_out_file);
1347 putc ('\n', asm_out_file);
1349 #endif
1353 /* Return true if the state of option OPTION should be stored in PCH files
1354 and checked by default_pch_valid_p. Store the option's current state
1355 in STATE if so. */
1357 static inline bool
1358 option_affects_pch_p (int option, struct cl_option_state *state)
1360 if ((cl_options[option].flags & CL_TARGET) == 0)
1361 return false;
1362 if (option_flag_var (option, &global_options) == &target_flags)
1363 if (targetm.check_pch_target_flags)
1364 return false;
1365 return get_option_state (&global_options, option, state);
1368 /* Default version of get_pch_validity.
1369 By default, every flag difference is fatal; that will be mostly right for
1370 most targets, but completely right for very few. */
1372 void *
1373 default_get_pch_validity (size_t *sz)
1375 struct cl_option_state state;
1376 size_t i;
1377 char *result, *r;
1379 *sz = 2;
1380 if (targetm.check_pch_target_flags)
1381 *sz += sizeof (target_flags);
1382 for (i = 0; i < cl_options_count; i++)
1383 if (option_affects_pch_p (i, &state))
1384 *sz += state.size;
1386 result = r = XNEWVEC (char, *sz);
1387 r[0] = flag_pic;
1388 r[1] = flag_pie;
1389 r += 2;
1390 if (targetm.check_pch_target_flags)
1392 memcpy (r, &target_flags, sizeof (target_flags));
1393 r += sizeof (target_flags);
1396 for (i = 0; i < cl_options_count; i++)
1397 if (option_affects_pch_p (i, &state))
1399 memcpy (r, state.data, state.size);
1400 r += state.size;
1403 return result;
1406 /* Return a message which says that a PCH file was created with a different
1407 setting of OPTION. */
1409 static const char *
1410 pch_option_mismatch (const char *option)
1412 char *r;
1414 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1415 if (r == NULL)
1416 return _("out of memory");
1417 return r;
1420 /* Default version of pch_valid_p. */
1422 const char *
1423 default_pch_valid_p (const void *data_p, size_t len)
1425 struct cl_option_state state;
1426 const char *data = (const char *)data_p;
1427 size_t i;
1429 /* -fpic and -fpie also usually make a PCH invalid. */
1430 if (data[0] != flag_pic)
1431 return _("created and used with different settings of -fpic");
1432 if (data[1] != flag_pie)
1433 return _("created and used with different settings of -fpie");
1434 data += 2;
1436 /* Check target_flags. */
1437 if (targetm.check_pch_target_flags)
1439 int tf;
1440 const char *r;
1442 memcpy (&tf, data, sizeof (target_flags));
1443 data += sizeof (target_flags);
1444 len -= sizeof (target_flags);
1445 r = targetm.check_pch_target_flags (tf);
1446 if (r != NULL)
1447 return r;
1450 for (i = 0; i < cl_options_count; i++)
1451 if (option_affects_pch_p (i, &state))
1453 if (memcmp (data, state.data, state.size) != 0)
1454 return pch_option_mismatch (cl_options[i].opt_text);
1455 data += state.size;
1456 len -= state.size;
1459 return NULL;
1462 /* Default tree printer. Handles declarations only. */
1463 bool
1464 default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
1465 int precision, bool wide, bool set_locus, bool hash)
1467 tree t;
1469 /* FUTURE: %+x should set the locus. */
1470 if (precision != 0 || wide || hash)
1471 return false;
1473 switch (*spec)
1475 case 'E':
1476 t = va_arg (*text->args_ptr, tree);
1477 if (TREE_CODE (t) == IDENTIFIER_NODE)
1479 pp_identifier (pp, IDENTIFIER_POINTER (t));
1480 return true;
1482 break;
1484 case 'D':
1485 t = va_arg (*text->args_ptr, tree);
1486 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1487 t = DECL_DEBUG_EXPR (t);
1488 break;
1490 case 'F':
1491 case 'T':
1492 t = va_arg (*text->args_ptr, tree);
1493 break;
1495 case 'K':
1496 percent_K_format (text);
1497 return true;
1499 default:
1500 return false;
1503 if (set_locus && text->locus)
1504 *text->locus = DECL_SOURCE_LOCATION (t);
1506 if (DECL_P (t))
1508 const char *n = DECL_NAME (t)
1509 ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2))
1510 : _("<anonymous>");
1511 pp_string (pp, n);
1513 else
1514 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1516 return true;
1519 /* A helper function; used as the reallocator function for cpp's line
1520 table. */
1521 static void *
1522 realloc_for_line_map (void *ptr, size_t len)
1524 return GGC_RESIZEVAR (void, ptr, len);
1527 /* A helper function: used as the allocator function for
1528 identifier_to_locale. */
1529 static void *
1530 alloc_for_identifier_to_locale (size_t len)
1532 return ggc_alloc_atomic (len);
1535 /* Output stack usage information. */
1536 void
1537 output_stack_usage (void)
1539 static bool warning_issued = false;
1540 enum stack_usage_kind_type { STATIC = 0, DYNAMIC, DYNAMIC_BOUNDED };
1541 const char *stack_usage_kind_str[] = {
1542 "static",
1543 "dynamic",
1544 "dynamic,bounded"
1546 HOST_WIDE_INT stack_usage = current_function_static_stack_size;
1547 enum stack_usage_kind_type stack_usage_kind;
1548 expanded_location loc;
1549 const char *raw_id, *id;
1551 if (stack_usage < 0)
1553 if (!warning_issued)
1555 warning (0, "-fstack-usage not supported for this target");
1556 warning_issued = true;
1558 return;
1561 stack_usage_kind = STATIC;
1563 /* Add the maximum amount of space pushed onto the stack. */
1564 if (current_function_pushed_stack_size > 0)
1566 stack_usage += current_function_pushed_stack_size;
1567 stack_usage_kind = DYNAMIC_BOUNDED;
1570 /* Now on to the tricky part: dynamic stack allocation. */
1571 if (current_function_allocates_dynamic_stack_space)
1573 if (current_function_has_unbounded_dynamic_stack_size)
1574 stack_usage_kind = DYNAMIC;
1575 else
1576 stack_usage_kind = DYNAMIC_BOUNDED;
1578 /* Add the size even in the unbounded case, this can't hurt. */
1579 stack_usage += current_function_dynamic_stack_size;
1582 loc = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
1584 /* Strip the scope prefix if any. */
1585 raw_id = lang_hooks.decl_printable_name (current_function_decl, 2);
1586 id = strrchr (raw_id, '.');
1587 if (id)
1588 id++;
1589 else
1590 id = raw_id;
1592 fprintf (stack_usage_file,
1593 "%s:%d:%d:%s\t"HOST_WIDE_INT_PRINT_DEC"\t%s\n",
1594 lbasename (loc.file),
1595 loc.line,
1596 loc.column,
1598 stack_usage,
1599 stack_usage_kind_str[stack_usage_kind]);
1602 /* Open an auxiliary output file. */
1603 static FILE *
1604 open_auxiliary_file (const char *ext)
1606 char *filename;
1607 FILE *file;
1609 filename = concat (aux_base_name, ".", ext, NULL);
1610 file = fopen (filename, "w");
1611 if (!file)
1612 fatal_error ("can't open %s for writing: %m", filename);
1613 free (filename);
1614 return file;
1617 /* Initialization of the front end environment, before command line
1618 options are parsed. Signal handlers, internationalization etc.
1619 ARGV0 is main's argv[0]. */
1620 static void
1621 general_init (const char *argv0)
1623 const char *p;
1625 p = argv0 + strlen (argv0);
1626 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1627 --p;
1628 progname = p;
1630 xmalloc_set_program_name (progname);
1632 hex_init ();
1634 /* Unlock the stdio streams. */
1635 unlock_std_streams ();
1637 gcc_init_libintl ();
1639 identifier_to_locale_alloc = alloc_for_identifier_to_locale;
1640 identifier_to_locale_free = ggc_free;
1642 /* Initialize the diagnostics reporting machinery, so option parsing
1643 can give warnings and errors. */
1644 diagnostic_initialize (global_dc, N_OPTS);
1645 diagnostic_starter (global_dc) = default_tree_diagnostic_starter;
1646 /* Set a default printer. Language specific initializations will
1647 override it later. */
1648 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1649 global_dc->show_option_requested
1650 = global_options_init.x_flag_diagnostics_show_option;
1651 global_dc->show_column
1652 = global_options_init.x_flag_show_column;
1653 global_dc->internal_error = plugins_internal_error_function;
1654 global_dc->option_enabled = option_enabled;
1655 global_dc->option_state = &global_options;
1656 global_dc->option_name = option_name;
1658 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1659 #ifdef SIGSEGV
1660 signal (SIGSEGV, crash_signal);
1661 #endif
1662 #ifdef SIGILL
1663 signal (SIGILL, crash_signal);
1664 #endif
1665 #ifdef SIGBUS
1666 signal (SIGBUS, crash_signal);
1667 #endif
1668 #ifdef SIGABRT
1669 signal (SIGABRT, crash_signal);
1670 #endif
1671 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1672 signal (SIGIOT, crash_signal);
1673 #endif
1674 #ifdef SIGFPE
1675 signal (SIGFPE, crash_signal);
1676 #endif
1678 /* Other host-specific signal setup. */
1679 (*host_hooks.extra_signals)();
1681 /* Initialize the garbage-collector, string pools and tree type hash
1682 table. */
1683 init_ggc ();
1684 init_stringpool ();
1685 line_table = ggc_alloc_line_maps ();
1686 linemap_init (line_table);
1687 line_table->reallocator = realloc_for_line_map;
1688 init_ttree ();
1690 /* Initialize register usage now so switches may override. */
1691 init_reg_sets ();
1693 /* Register the language-independent parameters. */
1694 add_params (lang_independent_params, LAST_PARAM);
1695 targetm.target_option.default_params ();
1697 /* This must be done after add_params but before argument processing. */
1698 init_ggc_heuristics();
1699 init_optimization_passes ();
1700 statistics_early_init ();
1701 finish_params ();
1704 /* Return true if the current target supports -fsection-anchors. */
1706 static bool
1707 target_supports_section_anchors_p (void)
1709 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1710 return false;
1712 if (targetm.asm_out.output_anchor == NULL)
1713 return false;
1715 return true;
1718 /* Default the align_* variables to 1 if they're still unset, and
1719 set up the align_*_log variables. */
1720 static void
1721 init_alignments (void)
1723 if (align_loops <= 0)
1724 align_loops = 1;
1725 if (align_loops_max_skip > align_loops)
1726 align_loops_max_skip = align_loops - 1;
1727 align_loops_log = floor_log2 (align_loops * 2 - 1);
1728 if (align_jumps <= 0)
1729 align_jumps = 1;
1730 if (align_jumps_max_skip > align_jumps)
1731 align_jumps_max_skip = align_jumps - 1;
1732 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1733 if (align_labels <= 0)
1734 align_labels = 1;
1735 align_labels_log = floor_log2 (align_labels * 2 - 1);
1736 if (align_labels_max_skip > align_labels)
1737 align_labels_max_skip = align_labels - 1;
1738 if (align_functions <= 0)
1739 align_functions = 1;
1740 align_functions_log = floor_log2 (align_functions * 2 - 1);
1743 /* Process the options that have been parsed. */
1744 static void
1745 process_options (void)
1747 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1748 This can happen with incorrect pre-processed input. */
1749 debug_hooks = &do_nothing_debug_hooks;
1751 /* This replaces set_Wunused. */
1752 if (warn_unused_function == -1)
1753 warn_unused_function = warn_unused;
1754 if (warn_unused_label == -1)
1755 warn_unused_label = warn_unused;
1756 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */
1757 if (warn_unused_parameter == -1)
1758 warn_unused_parameter = (warn_unused && extra_warnings);
1759 if (warn_unused_variable == -1)
1760 warn_unused_variable = warn_unused;
1761 /* Wunused-but-set-parameter is enabled if both -Wunused -Wextra are
1762 enabled. */
1763 if (warn_unused_but_set_parameter == -1)
1764 warn_unused_but_set_parameter = (warn_unused && extra_warnings);
1765 if (warn_unused_but_set_variable == -1)
1766 warn_unused_but_set_variable = warn_unused;
1767 if (warn_unused_value == -1)
1768 warn_unused_value = warn_unused;
1770 /* This replaces set_Wextra. */
1771 if (warn_uninitialized == -1)
1772 warn_uninitialized = extra_warnings;
1774 /* Allow the front end to perform consistency checks and do further
1775 initialization based on the command line options. This hook also
1776 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1777 so we can correctly initialize debug output. */
1778 no_backend = lang_hooks.post_options (&main_input_filename);
1780 /* Some machines may reject certain combinations of options. */
1781 targetm.target_option.override ();
1783 /* Avoid any informative notes in the second run of -fcompare-debug. */
1784 if (flag_compare_debug)
1785 diagnostic_inhibit_notes (global_dc);
1787 if (flag_section_anchors && !target_supports_section_anchors_p ())
1789 warning (OPT_fsection_anchors,
1790 "this target does not support %qs", "-fsection-anchors");
1791 flag_section_anchors = 0;
1794 if (flag_short_enums == 2)
1795 flag_short_enums = targetm.default_short_enums ();
1797 /* Set aux_base_name if not already set. */
1798 if (aux_base_name)
1800 else if (main_input_filename)
1802 char *name = xstrdup (lbasename (main_input_filename));
1804 strip_off_ending (name, strlen (name));
1805 aux_base_name = name;
1807 else
1808 aux_base_name = "gccaux";
1810 #ifndef HAVE_cloog
1811 if (flag_graphite
1812 || flag_loop_block
1813 || flag_loop_interchange
1814 || flag_loop_strip_mine
1815 || flag_graphite_identity
1816 || flag_loop_parallelize_all)
1817 sorry ("Graphite loop optimizations cannot be used");
1818 #endif
1820 /* Unrolling all loops implies that standard loop unrolling must also
1821 be done. */
1822 if (flag_unroll_all_loops)
1823 flag_unroll_loops = 1;
1825 /* web and rename-registers help when run after loop unrolling. */
1826 if (flag_web == AUTODETECT_VALUE)
1827 flag_web = flag_unroll_loops || flag_peel_loops;
1829 if (flag_rename_registers == AUTODETECT_VALUE)
1830 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1832 if (flag_non_call_exceptions)
1833 flag_asynchronous_unwind_tables = 1;
1834 if (flag_asynchronous_unwind_tables)
1835 flag_unwind_tables = 1;
1837 if (flag_value_profile_transformations)
1838 flag_profile_values = 1;
1840 /* Warn about options that are not supported on this machine. */
1841 #ifndef INSN_SCHEDULING
1842 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1843 warning (0, "instruction scheduling not supported on this target machine");
1844 #endif
1845 #ifndef DELAY_SLOTS
1846 if (flag_delayed_branch)
1847 warning (0, "this target machine does not have delayed branches");
1848 #endif
1850 user_label_prefix = USER_LABEL_PREFIX;
1851 if (flag_leading_underscore != -1)
1853 /* If the default prefix is more complicated than "" or "_",
1854 issue a warning and ignore this option. */
1855 if (user_label_prefix[0] == 0 ||
1856 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1858 user_label_prefix = flag_leading_underscore ? "_" : "";
1860 else
1861 warning (0, "-f%sleading-underscore not supported on this target machine",
1862 flag_leading_underscore ? "" : "no-");
1865 /* If we are in verbose mode, write out the version and maybe all the
1866 option flags in use. */
1867 if (version_flag)
1869 print_version (stderr, "");
1870 if (! quiet_flag)
1871 print_switch_values (print_to_stderr);
1874 if (flag_syntax_only)
1876 write_symbols = NO_DEBUG;
1877 profile_flag = 0;
1880 if (flag_gtoggle)
1882 if (debug_info_level == DINFO_LEVEL_NONE)
1884 debug_info_level = DINFO_LEVEL_NORMAL;
1886 if (write_symbols == NO_DEBUG)
1887 write_symbols = PREFERRED_DEBUGGING_TYPE;
1889 else
1890 debug_info_level = DINFO_LEVEL_NONE;
1893 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1895 FILE *final_output = fopen (flag_dump_final_insns, "w");
1896 if (!final_output)
1898 error ("could not open final insn dump file %qs: %m",
1899 flag_dump_final_insns);
1900 flag_dump_final_insns = NULL;
1902 else if (fclose (final_output))
1904 error ("could not close zeroed insn dump file %qs: %m",
1905 flag_dump_final_insns);
1906 flag_dump_final_insns = NULL;
1910 /* Unless over-ridden for the target, assume that all DWARF levels
1911 may be emitted, if DWARF2_DEBUG is selected. */
1912 if (dwarf_strict < 0)
1913 dwarf_strict = 0;
1915 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1916 level is 0. */
1917 if (debug_info_level == DINFO_LEVEL_NONE)
1918 write_symbols = NO_DEBUG;
1920 if (write_symbols == NO_DEBUG)
1922 #if defined(DBX_DEBUGGING_INFO)
1923 else if (write_symbols == DBX_DEBUG)
1924 debug_hooks = &dbx_debug_hooks;
1925 #endif
1926 #if defined(XCOFF_DEBUGGING_INFO)
1927 else if (write_symbols == XCOFF_DEBUG)
1928 debug_hooks = &xcoff_debug_hooks;
1929 #endif
1930 #ifdef SDB_DEBUGGING_INFO
1931 else if (write_symbols == SDB_DEBUG)
1932 debug_hooks = &sdb_debug_hooks;
1933 #endif
1934 #ifdef DWARF2_DEBUGGING_INFO
1935 else if (write_symbols == DWARF2_DEBUG)
1936 debug_hooks = &dwarf2_debug_hooks;
1937 #endif
1938 #ifdef VMS_DEBUGGING_INFO
1939 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1940 debug_hooks = &vmsdbg_debug_hooks;
1941 #endif
1942 else
1943 error ("target system does not support the \"%s\" debug format",
1944 debug_type_names[write_symbols]);
1946 /* We know which debug output will be used so we can set flag_var_tracking
1947 and flag_var_tracking_uninit if the user has not specified them. */
1948 if (debug_info_level < DINFO_LEVEL_NORMAL
1949 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1951 if (flag_var_tracking == 1
1952 || flag_var_tracking_uninit == 1)
1954 if (debug_info_level < DINFO_LEVEL_NORMAL)
1955 warning (0, "variable tracking requested, but useless unless "
1956 "producing debug info");
1957 else
1958 warning (0, "variable tracking requested, but not supported "
1959 "by this debug format");
1961 flag_var_tracking = 0;
1962 flag_var_tracking_uninit = 0;
1965 /* If the user specifically requested variable tracking with tagging
1966 uninitialized variables, we need to turn on variable tracking.
1967 (We already determined above that variable tracking is feasible.) */
1968 if (flag_var_tracking_uninit)
1969 flag_var_tracking = 1;
1971 if (flag_var_tracking == AUTODETECT_VALUE)
1972 flag_var_tracking = optimize >= 1;
1974 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
1975 flag_var_tracking_assignments = flag_var_tracking
1976 && !(flag_selective_scheduling || flag_selective_scheduling2);
1978 if (flag_var_tracking_assignments_toggle)
1979 flag_var_tracking_assignments = !flag_var_tracking_assignments;
1981 if (flag_var_tracking_assignments && !flag_var_tracking)
1982 flag_var_tracking = flag_var_tracking_assignments = -1;
1984 if (flag_var_tracking_assignments
1985 && (flag_selective_scheduling || flag_selective_scheduling2))
1986 warning (0, "var-tracking-assignments changes selective scheduling");
1988 if (flag_tree_cselim == AUTODETECT_VALUE)
1989 #ifdef HAVE_conditional_move
1990 flag_tree_cselim = 1;
1991 #else
1992 flag_tree_cselim = 0;
1993 #endif
1995 /* If auxiliary info generation is desired, open the output file.
1996 This goes in the same directory as the source file--unlike
1997 all the other output files. */
1998 if (flag_gen_aux_info)
2000 aux_info_file = fopen (aux_info_file_name, "w");
2001 if (aux_info_file == 0)
2002 fatal_error ("can%'t open %s: %m", aux_info_file_name);
2005 if (! targetm.have_named_sections)
2007 if (flag_function_sections)
2009 warning (0, "-ffunction-sections not supported for this target");
2010 flag_function_sections = 0;
2012 if (flag_data_sections)
2014 warning (0, "-fdata-sections not supported for this target");
2015 flag_data_sections = 0;
2019 if (flag_function_sections && profile_flag)
2021 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
2022 flag_function_sections = 0;
2025 #ifndef HAVE_prefetch
2026 if (flag_prefetch_loop_arrays > 0)
2028 warning (0, "-fprefetch-loop-arrays not supported for this target");
2029 flag_prefetch_loop_arrays = 0;
2031 #else
2032 if (flag_prefetch_loop_arrays > 0 && !HAVE_prefetch)
2034 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
2035 flag_prefetch_loop_arrays = 0;
2037 #endif
2039 /* This combination of options isn't handled for i386 targets and doesn't
2040 make much sense anyway, so don't allow it. */
2041 if (flag_prefetch_loop_arrays > 0 && optimize_size)
2043 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
2044 flag_prefetch_loop_arrays = 0;
2047 /* The presence of IEEE signaling NaNs, implies all math can trap. */
2048 if (flag_signaling_nans)
2049 flag_trapping_math = 1;
2051 /* We cannot reassociate if we want traps or signed zeros. */
2052 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
2054 warning (0, "-fassociative-math disabled; other options take precedence");
2055 flag_associative_math = 0;
2058 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
2059 if (flag_cx_limited_range)
2060 flag_complex_method = 0;
2062 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
2063 if (flag_cx_fortran_rules)
2064 flag_complex_method = 1;
2066 /* Targets must be able to place spill slots at lower addresses. If the
2067 target already uses a soft frame pointer, the transition is trivial. */
2068 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
2070 warning (0, "-fstack-protector not supported for this target");
2071 flag_stack_protect = 0;
2073 if (!flag_stack_protect)
2074 warn_stack_protect = 0;
2076 /* ??? Unwind info is not correct around the CFG unless either a frame
2077 pointer is present or A_O_A is set. Fixing this requires rewriting
2078 unwind info generation to be aware of the CFG and propagating states
2079 around edges. */
2080 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
2081 && flag_omit_frame_pointer)
2083 warning (0, "unwind tables currently require a frame pointer "
2084 "for correctness");
2085 flag_omit_frame_pointer = 0;
2088 /* Save the current optimization options. */
2089 optimization_default_node = build_optimization_node ();
2090 optimization_current_node = optimization_default_node;
2093 /* This function can be called multiple times to reinitialize the compiler
2094 back end when register classes or instruction sets have changed,
2095 before each function. */
2096 static void
2097 backend_init_target (void)
2099 /* Initialize alignment variables. */
2100 init_alignments ();
2102 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
2103 to initialize reg_raw_mode[]. */
2104 init_emit_regs ();
2106 /* This invokes target hooks to set fixed_reg[] etc, which is
2107 mode-dependent. */
2108 init_regs ();
2110 /* This depends on stack_pointer_rtx. */
2111 init_fake_stack_mems ();
2113 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
2114 mode-dependent. */
2115 init_alias_target ();
2117 /* Depends on HARD_FRAME_POINTER_REGNUM. */
2118 init_reload ();
2120 /* The following initialization functions need to generate rtl, so
2121 provide a dummy function context for them. */
2122 init_dummy_function_start ();
2124 /* rtx_cost is mode-dependent, so cached values need to be recomputed
2125 on a mode change. */
2126 init_expmed ();
2128 /* We may need to recompute regno_save_code[] and regno_restore_code[]
2129 after a mode change as well. */
2130 caller_save_initialized_p = false;
2132 expand_dummy_function_end ();
2135 /* Initialize the compiler back end. This function is called only once,
2136 when starting the compiler. */
2137 static void
2138 backend_init (void)
2140 init_emit_once ();
2142 init_rtlanal ();
2143 init_inline_once ();
2144 init_varasm_once ();
2145 save_register_info ();
2147 /* Initialize the target-specific back end pieces. */
2148 ira_init_once ();
2149 backend_init_target ();
2152 /* Initialize excess precision settings. */
2153 static void
2154 init_excess_precision (void)
2156 /* Adjust excess precision handling based on the target options. If
2157 the front end cannot handle it, flag_excess_precision_cmdline
2158 will already have been set accordingly in the post_options
2159 hook. */
2160 gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
2161 flag_excess_precision = flag_excess_precision_cmdline;
2162 if (flag_unsafe_math_optimizations)
2163 flag_excess_precision = EXCESS_PRECISION_FAST;
2164 if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
2166 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
2167 switch (flt_eval_method)
2169 case -1:
2170 case 0:
2171 /* Either the target acts unpredictably (-1) or has all the
2172 operations required not to have excess precision (0). */
2173 flag_excess_precision = EXCESS_PRECISION_FAST;
2174 break;
2175 case 1:
2176 case 2:
2177 /* In these cases, predictable excess precision makes
2178 sense. */
2179 break;
2180 default:
2181 /* Any other implementation-defined FLT_EVAL_METHOD values
2182 require the compiler to handle the associated excess
2183 precision rules in excess_precision_type. */
2184 gcc_unreachable ();
2189 /* Initialize things that are both lang-dependent and target-dependent.
2190 This function can be called more than once if target parameters change. */
2191 static void
2192 lang_dependent_init_target (void)
2194 /* This determines excess precision settings. */
2195 init_excess_precision ();
2197 /* This creates various _DECL nodes, so needs to be called after the
2198 front end is initialized. It also depends on the HAVE_xxx macros
2199 generated from the target machine description. */
2200 init_optabs ();
2202 /* The following initialization functions need to generate rtl, so
2203 provide a dummy function context for them. */
2204 init_dummy_function_start ();
2206 /* Do the target-specific parts of expr initialization. */
2207 init_expr_target ();
2209 /* Although the actions of these functions are language-independent,
2210 they use optabs, so we cannot call them from backend_init. */
2211 init_set_costs ();
2212 ira_init ();
2214 expand_dummy_function_end ();
2217 /* Language-dependent initialization. Returns nonzero on success. */
2218 static int
2219 lang_dependent_init (const char *name)
2221 location_t save_loc = input_location;
2222 if (dump_base_name == 0)
2223 dump_base_name = name && name[0] ? name : "gccdump";
2225 /* Other front-end initialization. */
2226 input_location = BUILTINS_LOCATION;
2227 if (lang_hooks.init () == 0)
2228 return 0;
2229 input_location = save_loc;
2231 init_asm_output (name);
2233 /* If stack usage information is desired, open the output file. */
2234 if (flag_stack_usage)
2235 stack_usage_file = open_auxiliary_file ("su");
2237 /* This creates various _DECL nodes, so needs to be called after the
2238 front end is initialized. */
2239 init_eh ();
2241 /* Do the target-specific parts of the initialization. */
2242 lang_dependent_init_target ();
2244 /* If dbx symbol table desired, initialize writing it and output the
2245 predefined types. */
2246 timevar_push (TV_SYMOUT);
2248 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2249 if (dwarf2out_do_frame ())
2250 dwarf2out_frame_init ();
2251 #endif
2253 /* Now we have the correct original filename, we can initialize
2254 debug output. */
2255 (*debug_hooks->init) (name);
2257 timevar_pop (TV_SYMOUT);
2259 return 1;
2263 /* Reinitialize everything when target parameters, such as register usage,
2264 have changed. */
2265 void
2266 target_reinit (void)
2268 /* Reinitialize RTL backend. */
2269 backend_init_target ();
2271 /* Reinitialize lang-dependent parts. */
2272 lang_dependent_init_target ();
2275 void
2276 dump_memory_report (bool final)
2278 ggc_print_statistics ();
2279 stringpool_statistics ();
2280 dump_tree_statistics ();
2281 dump_gimple_statistics ();
2282 dump_rtx_statistics ();
2283 dump_alloc_pool_statistics ();
2284 dump_bitmap_statistics ();
2285 dump_vec_loc_statistics ();
2286 dump_ggc_loc_statistics (final);
2287 dump_alias_stats (stderr);
2288 dump_pta_stats (stderr);
2291 /* Clean up: close opened files, etc. */
2293 static void
2294 finalize (void)
2296 /* Close the dump files. */
2297 if (flag_gen_aux_info)
2299 fclose (aux_info_file);
2300 if (seen_error ())
2301 unlink (aux_info_file_name);
2304 /* Close non-debugging input and output files. Take special care to note
2305 whether fclose returns an error, since the pages might still be on the
2306 buffer chain while the file is open. */
2308 if (asm_out_file)
2310 if (ferror (asm_out_file) != 0)
2311 fatal_error ("error writing to %s: %m", asm_file_name);
2312 if (fclose (asm_out_file) != 0)
2313 fatal_error ("error closing %s: %m", asm_file_name);
2314 if (flag_wpa)
2315 unlink_if_ordinary (asm_file_name);
2318 if (stack_usage_file)
2319 fclose (stack_usage_file);
2321 statistics_fini ();
2322 finish_optimization_passes ();
2324 ira_finish_once ();
2326 if (mem_report)
2327 dump_memory_report (true);
2329 /* Language-specific end of compilation actions. */
2330 lang_hooks.finish ();
2333 /* Initialize the compiler, and compile the input file. */
2334 static void
2335 do_compile (void)
2337 /* Initialize timing first. The C front ends read the main file in
2338 the post_options hook, and C++ does file timings. */
2339 if (time_report || !quiet_flag || flag_detailed_statistics)
2340 timevar_init ();
2341 timevar_start (TV_TOTAL);
2343 process_options ();
2345 /* Don't do any more if an error has already occurred. */
2346 if (!seen_error ())
2348 /* This must be run always, because it is needed to compute the FP
2349 predefined macros, such as __LDBL_MAX__, for targets using non
2350 default FP formats. */
2351 init_adjust_machine_modes ();
2353 /* Set up the back-end if requested. */
2354 if (!no_backend)
2355 backend_init ();
2357 /* Language-dependent initialization. Returns true on success. */
2358 if (lang_dependent_init (main_input_filename))
2359 compile_file ();
2361 finalize ();
2364 /* Stop timing and print the times. */
2365 timevar_stop (TV_TOTAL);
2366 timevar_print (stderr);
2369 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2370 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2371 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2373 It is not safe to call this function more than once. */
2376 toplev_main (int argc, char **argv)
2378 expandargv (&argc, &argv);
2380 /* Initialization of GCC's environment, and diagnostics. */
2381 general_init (argv[0]);
2383 /* One-off initialization of options that does not need to be
2384 repeated when options are added for particular functions. */
2385 init_options_once ();
2387 /* Initialize global options structures; this must be repeated for
2388 each structure used for parsing options. */
2389 init_options_struct (&global_options, &global_options_set);
2390 lang_hooks.init_options_struct (&global_options);
2392 /* Convert the options to an array. */
2393 decode_cmdline_options_to_array_default_mask (argc,
2394 CONST_CAST2 (const char **,
2395 char **, argv),
2396 &save_decoded_options,
2397 &save_decoded_options_count);
2399 /* Perform language-specific options initialization. */
2400 lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
2402 /* Parse the options and do minimal processing; basically just
2403 enough to default flags appropriately. */
2404 decode_options (&global_options, &global_options_set,
2405 save_decoded_options, save_decoded_options_count);
2407 init_local_tick ();
2409 initialize_plugins ();
2411 if (version_flag)
2412 print_version (stderr, "");
2414 if (help_flag)
2415 print_plugins_help (stderr, "");
2417 /* Exit early if we can (e.g. -help). */
2418 if (!exit_after_options)
2419 do_compile ();
2421 if (warningcount || errorcount)
2422 print_ignored_options ();
2423 diagnostic_finish (global_dc);
2425 /* Invoke registered plugin callbacks if any. */
2426 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2428 finalize_plugins ();
2429 if (seen_error ())
2430 return (FATAL_EXIT_CODE);
2432 return (SUCCESS_EXIT_CODE);