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
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
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. */
29 #include "coretypes.h"
33 #ifdef HAVE_SYS_RESOURCE_H
34 # include <sys/resource.h>
37 #ifdef HAVE_SYS_TIMES_H
38 # include <sys/times.h>
44 #include "realmpfr.h" /* For GMP/MPFR/MPC versions, in print_version. */
49 #include "insn-attr.h"
50 #include "insn-config.h"
51 #include "insn-flags.h"
52 #include "hard-reg-set.h"
59 #include "basic-block.h"
65 #include "diagnostic.h"
66 #include "tree-diagnostic.h"
67 #include "tree-pretty-print.h"
71 #include "dwarf2asm.h"
72 #include "integrate.h"
75 #include "langhooks.h"
76 #include "cfglayout.h"
78 #include "hosthooks.h"
81 #include "opts-diagnostic.h"
83 #include "value-prof.h"
84 #include "alloc-pool.h"
85 #include "tree-mudflap.h"
86 #include "tree-pass.h"
88 #include "tree-ssa-alias.h"
91 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
92 #include "dwarf2out.h"
95 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
99 #ifdef SDB_DEBUGGING_INFO
103 #ifdef XCOFF_DEBUGGING_INFO
104 #include "xcoffout.h" /* Needed for external data
105 declarations for e.g. AIX 4.x. */
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. */
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;
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 /* A mask of target_flags that includes bit X if X was set or cleared
159 on the command line. */
161 int target_flags_explicit;
163 /* Debug hooks - dependent upon command line options. */
165 const struct gcc_debug_hooks *debug_hooks;
167 /* Other flags saying which kinds of debugging dump have been requested. */
169 int rtl_dump_and_exit;
170 int flag_print_asm_name;
171 enum graph_dump_types graph_dump_format;
173 /* Name for output file of assembly code, specified with -o. */
175 const char *asm_file_name;
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. */
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. */
191 int optimize_size = 0;
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. */
198 bool in_lto_p = false;
200 /* Nonzero if we should write GIMPLE bytecode for link-time optimization. */
202 int flag_generate_lto;
204 /* The FUNCTION_DECL for the function currently being compiled,
205 or 0 if between functions. */
206 tree current_function_decl;
208 /* Set to the FUNC_BEGIN label of the current function, or NULL
210 const char * current_function_func_begin_label;
212 /* A random sequence of characters, unless overridden by user. */
213 static const char *flag_random_seed;
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. */
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. */
226 int flag_complex_method = 1;
228 /* Nonzero means we should be saving declaration info into a .X file. */
230 int flag_gen_aux_info = 0;
232 /* Specified name of aux-info file. */
234 const char *aux_info_file_name;
236 /* Nonzero if we are compiling code for a shared library, zero for
241 /* Generate code for GNU or NeXT Objective-C runtime environment. */
243 #ifdef NEXT_OBJC_RUNTIME
244 int flag_next_runtime = 1;
246 int flag_next_runtime = 0;
249 /* Set to the default thread-local storage (tls) model to use. */
251 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
253 /* Set the default region and algorithm for the integrated register
256 enum ira_algorithm flag_ira_algorithm = IRA_ALGORITHM_CB;
257 enum ira_region flag_ira_region = IRA_REGION_MIXED;
259 /* Set the default for excess precision. */
261 enum excess_precision flag_excess_precision_cmdline = EXCESS_PRECISION_DEFAULT;
263 /* Nonzero means change certain warnings into errors.
264 Usually these are warnings about failure to conform to some standard. */
266 int flag_pedantic_errors = 0;
268 /* Nonzero means make permerror produce warnings instead of errors. */
270 int flag_permissive = 0;
272 /* -dA causes debug commentary information to be produced in
273 the generated assembly code (to make it more readable). This option
274 is generally only of use to those who actually need to read the
275 generated assembly code (perhaps while debugging the compiler itself).
276 Currently, this switch is only used by dwarfout.c; however, it is intended
277 to be a catchall for printing debug information in the assembler file. */
279 int flag_debug_asm = 0;
281 /* -dP causes the rtl to be emitted as a comment in assembly. */
283 int flag_dump_rtl_in_asm = 0;
285 /* When non-NULL, indicates that whenever space is allocated on the
286 stack, the resulting stack pointer must not pass this
287 address---that is, for stacks that grow downward, the stack pointer
288 must always be greater than or equal to this address; for stacks
289 that grow upward, the stack pointer must be less than this address.
290 At present, the rtx may be either a REG or a SYMBOL_REF, although
291 the support provided depends on the backend. */
294 /* Positive if we should track variables, negative if we should run
295 the var-tracking pass only to discard debug annotations, zero if
296 we're not to run it. When flag_var_tracking == AUTODETECT_VALUE it
297 will be set according to optimize, debug_info_level and debug_hooks
298 in process_options (). */
299 int flag_var_tracking = AUTODETECT_VALUE;
301 /* Positive if we should track variables at assignments, negative if
302 we should run the var-tracking pass only to discard debug
303 annotations. When flag_var_tracking_assignments ==
304 AUTODETECT_VALUE it will be set according to flag_var_tracking. */
305 int flag_var_tracking_assignments = AUTODETECT_VALUE;
307 /* Nonzero if we should toggle flag_var_tracking_assignments after
308 processing options and computing its default. */
309 int flag_var_tracking_assignments_toggle = 0;
311 /* Type of stack check. */
312 enum stack_check_type flag_stack_check = NO_STACK_CHECK;
314 /* True if the user has tagged the function with the 'section'
317 bool user_defined_section_attribute = false;
319 struct target_flag_state default_target_flag_state;
320 #if SWITCHABLE_TARGET
321 struct target_flag_state *this_target_flag_state = &default_target_flag_state;
323 #define this_target_flag_state (&default_target_flag_state)
328 const char *const string;
332 lang_independent_options;
334 /* Nonzero if subexpressions must be evaluated from left-to-right. */
335 int flag_evaluation_order = 0;
337 /* The user symbol prefix after having resolved same. */
338 const char *user_label_prefix;
340 static const param_info lang_independent_params[] = {
341 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
342 { OPTION, DEFAULT, false, MIN, MAX, HELP },
343 #include "params.def"
345 { NULL, 0, false, 0, 0, NULL }
348 /* Output files for assembler code (real compiler output)
349 and debugging dumps. */
353 FILE *dump_file = NULL;
354 const char *dump_file_name;
356 /* The current working directory of a translation. It's generally the
357 directory from which compilation was initiated, but a preprocessed
358 file may specify the original directory in which it was
361 static const char *src_pwd;
363 /* Initialize src_pwd with the given string, and return true. If it
364 was already initialized, return false. As a special case, it may
365 be called with a NULL argument to test whether src_pwd has NOT been
369 set_src_pwd (const char *pwd)
373 if (strcmp (src_pwd, pwd) == 0)
379 src_pwd = xstrdup (pwd);
383 /* Return the directory from which the translation unit was initiated,
384 in case set_src_pwd() was not called before to assign it a
400 /* Called when the start of a function definition is parsed,
401 this function prints on stderr the name of the function. */
403 announce_function (tree decl)
407 if (rtl_dump_and_exit)
408 fprintf (stderr, "%s ",
409 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
411 fprintf (stderr, " %s",
412 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
414 pp_needs_newline (global_dc->printer) = true;
415 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
419 /* Initialize local_tick with the time of day, or -1 if
420 flag_random_seed is set. */
423 init_local_tick (void)
425 if (!flag_random_seed)
427 /* Get some more or less random data. */
428 #ifdef HAVE_GETTIMEOFDAY
432 gettimeofday (&tv, NULL);
433 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
437 time_t now = time (NULL);
439 if (now != (time_t)-1)
440 local_tick = (unsigned) now;
448 /* Set up a default flag_random_seed and local_tick, unless the user
449 already specified one. Must be called after init_local_tick. */
452 init_random_seed (void)
454 unsigned HOST_WIDE_INT value;
455 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
457 value = local_tick ^ getpid ();
459 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
460 flag_random_seed = random_seed;
463 /* Obtain the random_seed string. Unless NOINIT, initialize it if
464 it's not provided in the command line. */
467 get_random_seed (bool noinit)
469 if (!flag_random_seed && !noinit)
471 return flag_random_seed;
474 /* Modify the random_seed string to VAL. Return its previous
478 set_random_seed (const char *val)
480 const char *old = flag_random_seed;
481 flag_random_seed = val;
485 #if GCC_VERSION < 3004
487 /* The functions clz_hwi, ctz_hwi, ffs_hwi, floor_log2 and exact_log2
488 are defined as inline functions in toplev.h if GCC_VERSION >= 3004.
489 The definitions here are used for older versions of gcc. */
491 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
492 If X is 0, return -1. */
495 floor_log2 (unsigned HOST_WIDE_INT x)
502 if (HOST_BITS_PER_WIDE_INT > 64)
503 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
505 if (HOST_BITS_PER_WIDE_INT > 32)
506 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
508 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
510 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
512 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
514 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
516 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
522 /* Return the logarithm of X, base 2, considering X unsigned,
523 if X is a power of 2. Otherwise, returns -1. */
526 exact_log2 (unsigned HOST_WIDE_INT x)
530 return floor_log2 (x);
533 /* Given X, an unsigned number, return the number of least significant bits
534 that are zero. When X == 0, the result is the word size. */
537 ctz_hwi (unsigned HOST_WIDE_INT x)
539 return x ? floor_log2 (x & -x) : HOST_BITS_PER_WIDE_INT;
542 /* Similarly for most significant bits. */
545 clz_hwi (unsigned HOST_WIDE_INT x)
547 return HOST_BITS_PER_WIDE_INT - 1 - floor_log2(x);
550 /* Similar to ctz_hwi, except that the least significant bit is numbered
551 starting from 1, and X == 0 yields 0. */
554 ffs_hwi (unsigned HOST_WIDE_INT x)
556 return 1 + floor_log2 (x & -x);
559 #endif /* GCC_VERSION < 3004 */
561 /* Handler for fatal signals, such as SIGSEGV. These are transformed
562 into ICE messages, which is much more user friendly. In case the
563 error printer crashes, reset the signal to prevent infinite recursion. */
566 crash_signal (int signo)
568 signal (signo, SIG_DFL);
570 /* If we crashed while processing an ASM statement, then be a little more
571 graceful. It's most likely the user's fault. */
572 if (this_is_asm_operands)
574 output_operand_lossage ("unrecoverable error");
575 exit (FATAL_EXIT_CODE);
578 internal_error ("%s", strsignal (signo));
581 /* Arrange to dump core on error. (The regular error message is still
582 printed first, except in the case of abort().) */
585 setup_core_dumping (void)
588 signal (SIGABRT, SIG_DFL);
590 #if defined(HAVE_SETRLIMIT)
593 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
594 fatal_error ("getting core file size maximum limit: %m");
595 rlim.rlim_cur = rlim.rlim_max;
596 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
597 fatal_error ("setting core file size limit to maximum: %m");
600 diagnostic_abort_on_error (global_dc);
604 /* Strip off a legitimate source ending from the input string NAME of
605 length LEN. Rather than having to know the names used by all of
606 our front ends, we strip off an ending of a period followed by
607 up to five characters. (Java uses ".class".) */
610 strip_off_ending (char *name, int len)
613 for (i = 2; i < 6 && len > i; i++)
615 if (name[len - i] == '.')
617 name[len - i] = '\0';
623 /* Output a quoted string. */
626 output_quoted_string (FILE *asm_file, const char *string)
628 #ifdef OUTPUT_QUOTED_STRING
629 OUTPUT_QUOTED_STRING (asm_file, string);
633 putc ('\"', asm_file);
634 while ((c = *string++) != 0)
638 if (c == '\"' || c == '\\')
639 putc ('\\', asm_file);
643 fprintf (asm_file, "\\%03o", (unsigned char) c);
645 putc ('\"', asm_file);
649 /* A subroutine of wrapup_global_declarations. We've come to the end of
650 the compilation unit. All deferred variables should be undeferred,
651 and all incomplete decls should be finalized. */
654 wrapup_global_declaration_1 (tree decl)
656 /* We're not deferring this any longer. Assignment is conditional to
657 avoid needlessly dirtying PCH pages. */
658 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
659 && DECL_DEFER_OUTPUT (decl) != 0)
660 DECL_DEFER_OUTPUT (decl) = 0;
662 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
663 lang_hooks.finish_incomplete_decl (decl);
666 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
667 needs to be output. Return true if it is output. */
670 wrapup_global_declaration_2 (tree decl)
672 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
675 /* Don't write out static consts, unless we still need them.
677 We also keep static consts if not optimizing (for debugging),
678 unless the user specified -fno-keep-static-consts.
679 ??? They might be better written into the debug information.
680 This is possible when using DWARF.
682 A language processor that wants static constants to be always
683 written out (even if it is not used) is responsible for
684 calling rest_of_decl_compilation itself. E.g. the C front-end
685 calls rest_of_decl_compilation from finish_decl.
686 One motivation for this is that is conventional in some
687 environments to write things like:
688 static const char rcsid[] = "... version string ...";
689 intending to force the string to be in the executable.
691 A language processor that would prefer to have unneeded
692 static constants "optimized away" would just defer writing
693 them out until here. E.g. C++ does this, because static
694 constants are often defined in header files.
696 ??? A tempting alternative (for both C and C++) would be
697 to force a constant to be written if and only if it is
698 defined in a main file, as opposed to an include file. */
700 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
702 struct varpool_node *node;
704 node = varpool_get_node (decl);
706 if (!node && flag_ltrans)
708 else if (node && node->finalized)
710 else if (node && node->alias)
712 else if (!cgraph_global_info_ready
714 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
716 else if (node && node->needed)
718 else if (DECL_COMDAT (decl))
720 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
721 && (optimize || !flag_keep_static_consts
722 || DECL_ARTIFICIAL (decl)))
727 rest_of_decl_compilation (decl, 1, 1);
735 /* Do any final processing required for the declarations in VEC, of
736 which there are LEN. We write out inline functions and variables
737 that have been deferred until this point, but which are required.
738 Returns nonzero if anything was put out. */
741 wrapup_global_declarations (tree *vec, int len)
743 bool reconsider, output_something = false;
746 for (i = 0; i < len; i++)
747 wrapup_global_declaration_1 (vec[i]);
749 /* Now emit any global variables or functions that we have been
750 putting off. We need to loop in case one of the things emitted
751 here references another one which comes earlier in the list. */
755 for (i = 0; i < len; i++)
756 reconsider |= wrapup_global_declaration_2 (vec[i]);
758 output_something = true;
762 return output_something;
765 /* A subroutine of check_global_declarations. Issue appropriate warnings
766 for the global declaration DECL. */
769 check_global_declaration_1 (tree decl)
771 /* Warn about any function declared static but not defined. We don't
772 warn about variables, because many programs have static variables
773 that exist only to get some text into the object file. */
774 if (TREE_CODE (decl) == FUNCTION_DECL
775 && DECL_INITIAL (decl) == 0
776 && DECL_EXTERNAL (decl)
777 && ! DECL_ARTIFICIAL (decl)
778 && ! TREE_NO_WARNING (decl)
779 && ! TREE_PUBLIC (decl)
780 && (warn_unused_function
781 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
783 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
784 pedwarn (input_location, 0, "%q+F used but never defined", decl);
786 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
787 /* This symbol is effectively an "extern" declaration now. */
788 TREE_PUBLIC (decl) = 1;
789 assemble_external (decl);
792 /* Warn about static fns or vars defined but not used. */
793 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
794 /* We don't warn about "static const" variables because the
795 "rcs_id" idiom uses that construction. */
796 || (warn_unused_variable
797 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
798 && ! DECL_IN_SYSTEM_HEADER (decl)
799 && ! TREE_USED (decl)
800 /* The TREE_USED bit for file-scope decls is kept in the identifier,
801 to handle multiple external decls in different scopes. */
802 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
803 && ! DECL_EXTERNAL (decl)
804 && ! TREE_PUBLIC (decl)
805 /* A volatile variable might be used in some non-obvious way. */
806 && ! TREE_THIS_VOLATILE (decl)
807 /* Global register variables must be declared to reserve them. */
808 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
809 /* Otherwise, ask the language. */
810 && lang_hooks.decls.warn_unused_global (decl))
811 warning ((TREE_CODE (decl) == FUNCTION_DECL)
812 ? OPT_Wunused_function
813 : OPT_Wunused_variable,
814 "%q+D defined but not used", decl);
817 /* Issue appropriate warnings for the global declarations in VEC (of
818 which there are LEN). */
821 check_global_declarations (tree *vec, int len)
825 for (i = 0; i < len; i++)
826 check_global_declaration_1 (vec[i]);
829 /* Emit debugging information for all global declarations in VEC. */
832 emit_debug_global_declarations (tree *vec, int len)
836 /* Avoid confusing the debug information machinery when there are errors. */
840 timevar_push (TV_SYMOUT);
841 for (i = 0; i < len; i++)
842 debug_hooks->global_decl (vec[i]);
843 timevar_pop (TV_SYMOUT);
846 /* Warn about a use of an identifier which was marked deprecated. */
848 warn_deprecated_use (tree node, tree attr)
852 if (node == 0 || !warn_deprecated_decl)
858 attr = DECL_ATTRIBUTES (node);
859 else if (TYPE_P (node))
861 tree decl = TYPE_STUB_DECL (node);
863 attr = lookup_attribute ("deprecated",
864 TYPE_ATTRIBUTES (TREE_TYPE (decl)));
869 attr = lookup_attribute ("deprecated", attr);
872 msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
878 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
880 warning (OPT_Wdeprecated_declarations,
881 "%qD is deprecated (declared at %s:%d): %s",
882 node, xloc.file, xloc.line, msg);
884 warning (OPT_Wdeprecated_declarations,
885 "%qD is deprecated (declared at %s:%d)",
886 node, xloc.file, xloc.line);
888 else if (TYPE_P (node))
890 tree what = NULL_TREE;
891 tree decl = TYPE_STUB_DECL (node);
893 if (TYPE_NAME (node))
895 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
896 what = TYPE_NAME (node);
897 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
898 && DECL_NAME (TYPE_NAME (node)))
899 what = DECL_NAME (TYPE_NAME (node));
904 expanded_location xloc
905 = expand_location (DECL_SOURCE_LOCATION (decl));
909 warning (OPT_Wdeprecated_declarations,
910 "%qE is deprecated (declared at %s:%d): %s",
911 what, xloc.file, xloc.line, msg);
913 warning (OPT_Wdeprecated_declarations,
914 "%qE is deprecated (declared at %s:%d)", what,
915 xloc.file, xloc.line);
920 warning (OPT_Wdeprecated_declarations,
921 "type is deprecated (declared at %s:%d): %s",
922 xloc.file, xloc.line, msg);
924 warning (OPT_Wdeprecated_declarations,
925 "type is deprecated (declared at %s:%d)",
926 xloc.file, xloc.line);
934 warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s",
937 warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what);
942 warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
945 warning (OPT_Wdeprecated_declarations, "type is deprecated");
951 /* Compile an entire translation unit. Write a file of assembly
952 output and various debugging dumps. */
957 /* Initialize yet another pass. */
959 ggc_protect_identifiers = true;
962 init_final (main_input_filename);
963 coverage_init (aux_base_name);
965 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
967 timevar_push (TV_PARSE);
969 /* Call the parser, which parses the entire file (calling
970 rest_of_compilation for each function). */
971 lang_hooks.parse_file (set_yydebug);
973 /* Compilation is now finished except for writing
974 what's left of the symbol table output. */
975 timevar_pop (TV_PARSE);
977 if (flag_syntax_only || flag_wpa)
980 ggc_protect_identifiers = false;
982 /* This must also call cgraph_finalize_compilation_unit. */
983 lang_hooks.decls.final_write_globals ();
988 varpool_assemble_pending_decls ();
991 /* Likewise for mudflap static object registrations. */
993 mudflap_finish_file ();
995 output_shared_constant_pool ();
996 output_object_blocks ();
998 /* Write out any pending weak symbol declarations. */
1001 /* This must be at the end before unwind and debug info.
1002 Some target ports emit PIC setup thunks here. */
1003 targetm.asm_out.code_end ();
1005 /* Do dbx symbols. */
1006 timevar_push (TV_SYMOUT);
1008 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
1009 if (dwarf2out_do_frame ())
1010 dwarf2out_frame_finish ();
1013 (*debug_hooks->finish) (main_input_filename);
1014 timevar_pop (TV_SYMOUT);
1016 /* Output some stuff at end of file if nec. */
1018 dw2_output_indirect_constants ();
1020 /* Flush any pending external directives. */
1021 process_pending_assemble_externals ();
1023 /* Emit LTO marker if LTO info has been previously emitted. This is
1024 used by collect2 to determine whether an object file contains IL.
1025 We used to emit an undefined reference here, but this produces
1026 link errors if an object file with IL is stored into a shared
1027 library without invoking lto1. */
1028 if (flag_generate_lto)
1030 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1031 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
1033 (unsigned HOST_WIDE_INT) 1, 8);
1034 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1035 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1",
1036 (unsigned HOST_WIDE_INT) 1, 8);
1038 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1",
1039 (unsigned HOST_WIDE_INT) 1,
1040 (unsigned HOST_WIDE_INT) 1);
1044 /* Attach a special .ident directive to the end of the file to identify
1045 the version of GCC which compiled this code. The format of the .ident
1046 string is patterned after the ones produced by native SVR4 compilers. */
1050 const char *pkg_version = "(GNU) ";
1052 if (strcmp ("(GCC) ", pkgversion_string))
1053 pkg_version = pkgversion_string;
1054 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
1055 IDENT_ASM_OP, pkg_version, version_string);
1059 /* Invoke registered plugin callbacks. */
1060 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
1062 /* This must be at the end. Some target ports emit end of file directives
1063 into the assembly file here, and hence we can not output anything to the
1064 assembly file after this point. */
1065 targetm.asm_out.file_end ();
1068 /* Parse a -d... command line switch. */
1071 decode_d_option (const char *arg)
1082 flag_print_asm_name = 1;
1085 flag_dump_rtl_in_asm = 1;
1086 flag_print_asm_name = 1;
1089 graph_dump_format = vcg;
1092 rtl_dump_and_exit = 1;
1097 case 'D': /* These are handled by the preprocessor. */
1104 setup_core_dumping();
1107 enable_rtl_dump_file ();
1111 warning (0, "unrecognized gcc debugging option: %c", c);
1116 /* Indexed by enum debug_info_type. */
1117 const char *const debug_type_names[] =
1119 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1122 /* Print version information to FILE.
1123 Each line begins with INDENT (for the case where FILE is the
1124 assembler output file). */
1127 print_version (FILE *file, const char *indent)
1129 static const char fmt1[] =
1131 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1133 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1136 static const char fmt2[] =
1137 N_("GMP version %s, MPFR version %s, MPC version %s\n");
1138 static const char fmt3[] =
1139 N_("%s%swarning: %s header version %s differs from library version %s.\n");
1140 static const char fmt4[] =
1141 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1143 #define __VERSION__ "[?]"
1146 file == stderr ? _(fmt1) : fmt1,
1147 indent, *indent != 0 ? " " : "",
1148 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
1149 indent, __VERSION__);
1151 /* We need to stringify the GMP macro values. Ugh, gmp_version has
1152 two string formats, "i.j.k" and "i.j" when k is zero. As of
1153 gmp-4.3.0, GMP always uses the 3 number format. */
1154 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1155 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1156 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
1157 #define GCC_GMP_VERSION \
1158 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
1159 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
1160 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1161 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1163 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1164 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1165 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1168 file == stderr ? _(fmt2) : fmt2,
1169 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING);
1170 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
1172 file == stderr ? _(fmt3) : fmt3,
1173 indent, *indent != 0 ? " " : "",
1174 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
1175 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
1177 file == stderr ? _(fmt3) : fmt3,
1178 indent, *indent != 0 ? " " : "",
1179 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
1180 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
1182 file == stderr ? _(fmt3) : fmt3,
1183 indent, *indent != 0 ? " " : "",
1184 "MPC", MPC_VERSION_STRING, mpc_get_version ());
1186 file == stderr ? _(fmt4) : fmt4,
1187 indent, *indent != 0 ? " " : "",
1188 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1190 print_plugins_versions (file, indent);
1193 #ifdef ASM_COMMENT_START
1195 print_to_asm_out_file (print_switch_type type, const char * text)
1197 bool prepend_sep = true;
1201 case SWITCH_TYPE_LINE_END:
1202 putc ('\n', asm_out_file);
1205 case SWITCH_TYPE_LINE_START:
1206 fputs (ASM_COMMENT_START, asm_out_file);
1207 return strlen (ASM_COMMENT_START);
1209 case SWITCH_TYPE_DESCRIPTIVE:
1210 if (ASM_COMMENT_START[0] == 0)
1211 prepend_sep = false;
1213 case SWITCH_TYPE_PASSED:
1214 case SWITCH_TYPE_ENABLED:
1216 fputc (' ', asm_out_file);
1217 fputs (text, asm_out_file);
1218 /* No need to return the length here as
1219 print_single_switch has already done it. */
1229 print_to_stderr (print_switch_type type, const char * text)
1233 case SWITCH_TYPE_LINE_END:
1234 putc ('\n', stderr);
1237 case SWITCH_TYPE_LINE_START:
1240 case SWITCH_TYPE_PASSED:
1241 case SWITCH_TYPE_ENABLED:
1242 fputc (' ', stderr);
1245 case SWITCH_TYPE_DESCRIPTIVE:
1246 fputs (text, stderr);
1247 /* No need to return the length here as
1248 print_single_switch has already done it. */
1256 /* Print an option value and return the adjusted position in the line.
1257 ??? print_fn doesn't handle errors, eg disk full; presumably other
1258 code will catch a disk full though. */
1261 print_single_switch (print_switch_fn_type print_fn,
1263 print_switch_type type,
1266 /* The ultrix fprintf returns 0 on success, so compute the result
1267 we want here since we need it for the following test. The +1
1268 is for the separator character that will probably be emitted. */
1269 int len = strlen (text) + 1;
1272 && pos + len > MAX_LINE)
1274 print_fn (SWITCH_TYPE_LINE_END, NULL);
1279 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1281 print_fn (type, text);
1285 /* Print active target switches using PRINT_FN.
1286 POS is the current cursor position and MAX is the size of a "line".
1287 Each line begins with INDENT and ends with TERM.
1288 Each switch is separated from the next by SEP. */
1291 print_switch_values (print_switch_fn_type print_fn)
1296 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1297 that it can be printed below. This helps reproducibility. */
1298 if (!flag_random_seed)
1299 init_random_seed ();
1301 /* Print the options as passed. */
1302 pos = print_single_switch (print_fn, pos,
1303 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1305 for (j = 1; j < save_decoded_options_count; j++)
1307 switch (save_decoded_options[j].opt_index)
1320 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED,
1321 save_decoded_options[j].orig_option_with_args_text);
1325 print_fn (SWITCH_TYPE_LINE_END, NULL);
1327 /* Print the -f and -m options that have been enabled.
1328 We don't handle language specific options but printing argv
1330 pos = print_single_switch (print_fn, 0,
1331 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1333 for (j = 0; j < cl_options_count; j++)
1334 if ((cl_options[j].flags & CL_REPORT)
1335 && option_enabled (j) > 0)
1336 pos = print_single_switch (print_fn, pos,
1337 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1339 print_fn (SWITCH_TYPE_LINE_END, NULL);
1342 /* Open assembly code output file. Do this even if -fsyntax-only is
1343 on, because then the driver will have provided the name of a
1344 temporary file or bit bucket for us. NAME is the file specified on
1345 the command line, possibly NULL. */
1347 init_asm_output (const char *name)
1349 if (name == NULL && asm_file_name == 0)
1350 asm_out_file = stdout;
1353 if (asm_file_name == 0)
1355 int len = strlen (dump_base_name);
1356 char *dumpname = XNEWVEC (char, len + 6);
1358 memcpy (dumpname, dump_base_name, len + 1);
1359 strip_off_ending (dumpname, len);
1360 strcat (dumpname, ".s");
1361 asm_file_name = dumpname;
1363 if (!strcmp (asm_file_name, "-"))
1364 asm_out_file = stdout;
1366 asm_out_file = fopen (asm_file_name, "w+b");
1367 if (asm_out_file == 0)
1368 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1371 if (!flag_syntax_only)
1373 targetm.asm_out.file_start ();
1375 if (flag_record_gcc_switches)
1377 if (targetm.asm_out.record_gcc_switches)
1379 /* Let the target know that we are about to start recording. */
1380 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1382 /* Now record the switches. */
1383 print_switch_values (targetm.asm_out.record_gcc_switches);
1384 /* Let the target know that the recording is over. */
1385 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1389 inform (input_location, "-frecord-gcc-switches is not supported by the current target");
1392 #ifdef ASM_COMMENT_START
1393 if (flag_verbose_asm)
1395 /* Print the list of switches in effect
1396 into the assembler file as comments. */
1397 print_version (asm_out_file, ASM_COMMENT_START);
1398 print_switch_values (print_to_asm_out_file);
1399 putc ('\n', asm_out_file);
1405 /* Return true if the state of option OPTION should be stored in PCH files
1406 and checked by default_pch_valid_p. Store the option's current state
1410 option_affects_pch_p (int option, struct cl_option_state *state)
1412 if ((cl_options[option].flags & CL_TARGET) == 0)
1414 if (cl_options[option].flag_var == &target_flags)
1415 if (targetm.check_pch_target_flags)
1417 return get_option_state (option, state);
1420 /* Default version of get_pch_validity.
1421 By default, every flag difference is fatal; that will be mostly right for
1422 most targets, but completely right for very few. */
1425 default_get_pch_validity (size_t *sz)
1427 struct cl_option_state state;
1432 if (targetm.check_pch_target_flags)
1433 *sz += sizeof (target_flags);
1434 for (i = 0; i < cl_options_count; i++)
1435 if (option_affects_pch_p (i, &state))
1438 result = r = XNEWVEC (char, *sz);
1442 if (targetm.check_pch_target_flags)
1444 memcpy (r, &target_flags, sizeof (target_flags));
1445 r += sizeof (target_flags);
1448 for (i = 0; i < cl_options_count; i++)
1449 if (option_affects_pch_p (i, &state))
1451 memcpy (r, state.data, state.size);
1458 /* Return a message which says that a PCH file was created with a different
1459 setting of OPTION. */
1462 pch_option_mismatch (const char *option)
1466 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1468 return _("out of memory");
1472 /* Default version of pch_valid_p. */
1475 default_pch_valid_p (const void *data_p, size_t len)
1477 struct cl_option_state state;
1478 const char *data = (const char *)data_p;
1481 /* -fpic and -fpie also usually make a PCH invalid. */
1482 if (data[0] != flag_pic)
1483 return _("created and used with different settings of -fpic");
1484 if (data[1] != flag_pie)
1485 return _("created and used with different settings of -fpie");
1488 /* Check target_flags. */
1489 if (targetm.check_pch_target_flags)
1494 memcpy (&tf, data, sizeof (target_flags));
1495 data += sizeof (target_flags);
1496 len -= sizeof (target_flags);
1497 r = targetm.check_pch_target_flags (tf);
1502 for (i = 0; i < cl_options_count; i++)
1503 if (option_affects_pch_p (i, &state))
1505 if (memcmp (data, state.data, state.size) != 0)
1506 return pch_option_mismatch (cl_options[i].opt_text);
1514 /* Default tree printer. Handles declarations only. */
1516 default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
1517 int precision, bool wide, bool set_locus, bool hash)
1521 /* FUTURE: %+x should set the locus. */
1522 if (precision != 0 || wide || hash)
1528 t = va_arg (*text->args_ptr, tree);
1529 if (TREE_CODE (t) == IDENTIFIER_NODE)
1531 pp_identifier (pp, IDENTIFIER_POINTER (t));
1537 t = va_arg (*text->args_ptr, tree);
1538 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1539 t = DECL_DEBUG_EXPR (t);
1544 t = va_arg (*text->args_ptr, tree);
1548 percent_K_format (text);
1555 if (set_locus && text->locus)
1556 *text->locus = DECL_SOURCE_LOCATION (t);
1560 const char *n = DECL_NAME (t)
1561 ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2))
1566 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1571 /* A helper function; used as the reallocator function for cpp's line
1574 realloc_for_line_map (void *ptr, size_t len)
1576 return GGC_RESIZEVAR (void, ptr, len);
1579 /* A helper function: used as the allocator function for
1580 identifier_to_locale. */
1582 alloc_for_identifier_to_locale (size_t len)
1584 return ggc_alloc_atomic (len);
1587 /* Initialization of the front end environment, before command line
1588 options are parsed. Signal handlers, internationalization etc.
1589 ARGV0 is main's argv[0]. */
1591 general_init (const char *argv0)
1595 p = argv0 + strlen (argv0);
1596 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1600 xmalloc_set_program_name (progname);
1604 /* Unlock the stdio streams. */
1605 unlock_std_streams ();
1607 gcc_init_libintl ();
1609 identifier_to_locale_alloc = alloc_for_identifier_to_locale;
1610 identifier_to_locale_free = ggc_free;
1612 /* Initialize the diagnostics reporting machinery, so option parsing
1613 can give warnings and errors. */
1614 diagnostic_initialize (global_dc, N_OPTS);
1615 diagnostic_starter (global_dc) = default_tree_diagnostic_starter;
1616 /* Set a default printer. Language specific initializations will
1617 override it later. */
1618 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1619 global_dc->show_option_requested = flag_diagnostics_show_option;
1620 global_dc->show_column = flag_show_column;
1621 global_dc->internal_error = plugins_internal_error_function;
1622 global_dc->option_enabled = option_enabled;
1623 global_dc->option_name = option_name;
1625 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1627 signal (SIGSEGV, crash_signal);
1630 signal (SIGILL, crash_signal);
1633 signal (SIGBUS, crash_signal);
1636 signal (SIGABRT, crash_signal);
1638 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1639 signal (SIGIOT, crash_signal);
1642 signal (SIGFPE, crash_signal);
1645 /* Other host-specific signal setup. */
1646 (*host_hooks.extra_signals)();
1648 /* Initialize the garbage-collector, string pools and tree type hash
1652 line_table = ggc_alloc_line_maps ();
1653 linemap_init (line_table);
1654 line_table->reallocator = realloc_for_line_map;
1657 /* Initialize register usage now so switches may override. */
1660 /* Register the language-independent parameters. */
1661 add_params (lang_independent_params, LAST_PARAM);
1663 /* This must be done after add_params but before argument processing. */
1664 init_ggc_heuristics();
1665 init_optimization_passes ();
1666 statistics_early_init ();
1669 /* Return true if the current target supports -fsection-anchors. */
1672 target_supports_section_anchors_p (void)
1674 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1677 if (targetm.asm_out.output_anchor == NULL)
1683 /* Default the align_* variables to 1 if they're still unset, and
1684 set up the align_*_log variables. */
1686 init_alignments (void)
1688 if (align_loops <= 0)
1690 if (align_loops_max_skip > align_loops)
1691 align_loops_max_skip = align_loops - 1;
1692 align_loops_log = floor_log2 (align_loops * 2 - 1);
1693 if (align_jumps <= 0)
1695 if (align_jumps_max_skip > align_jumps)
1696 align_jumps_max_skip = align_jumps - 1;
1697 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1698 if (align_labels <= 0)
1700 align_labels_log = floor_log2 (align_labels * 2 - 1);
1701 if (align_labels_max_skip > align_labels)
1702 align_labels_max_skip = align_labels - 1;
1703 if (align_functions <= 0)
1704 align_functions = 1;
1705 align_functions_log = floor_log2 (align_functions * 2 - 1);
1708 /* Process the options that have been parsed. */
1710 process_options (void)
1712 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1713 This can happen with incorrect pre-processed input. */
1714 debug_hooks = &do_nothing_debug_hooks;
1716 /* This replaces set_Wunused. */
1717 if (warn_unused_function == -1)
1718 warn_unused_function = warn_unused;
1719 if (warn_unused_label == -1)
1720 warn_unused_label = warn_unused;
1721 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */
1722 if (warn_unused_parameter == -1)
1723 warn_unused_parameter = (warn_unused && extra_warnings);
1724 if (warn_unused_variable == -1)
1725 warn_unused_variable = warn_unused;
1726 /* Wunused-but-set-parameter is enabled if both -Wunused -Wextra are
1728 if (warn_unused_but_set_parameter == -1)
1729 warn_unused_but_set_parameter = (warn_unused && extra_warnings);
1730 if (warn_unused_but_set_variable == -1)
1731 warn_unused_but_set_variable = warn_unused;
1732 if (warn_unused_value == -1)
1733 warn_unused_value = warn_unused;
1735 /* This replaces set_Wextra. */
1736 if (warn_uninitialized == -1)
1737 warn_uninitialized = extra_warnings;
1739 /* Allow the front end to perform consistency checks and do further
1740 initialization based on the command line options. This hook also
1741 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1742 so we can correctly initialize debug output. */
1743 no_backend = lang_hooks.post_options (&main_input_filename);
1745 /* Some machines may reject certain combinations of options. */
1746 targetm.target_option.override ();
1748 /* Avoid any informative notes in the second run of -fcompare-debug. */
1749 if (flag_compare_debug)
1750 diagnostic_inhibit_notes (global_dc);
1752 if (flag_section_anchors && !target_supports_section_anchors_p ())
1754 warning (OPT_fsection_anchors,
1755 "this target does not support %qs", "-fsection-anchors");
1756 flag_section_anchors = 0;
1759 if (flag_short_enums == 2)
1760 flag_short_enums = targetm.default_short_enums ();
1762 /* Set aux_base_name if not already set. */
1765 else if (main_input_filename)
1767 char *name = xstrdup (lbasename (main_input_filename));
1769 strip_off_ending (name, strlen (name));
1770 aux_base_name = name;
1773 aux_base_name = "gccaux";
1778 || flag_loop_interchange
1779 || flag_loop_strip_mine
1780 || flag_graphite_identity
1781 || flag_loop_parallelize_all)
1782 sorry ("Graphite loop optimizations cannot be used");
1785 /* Unrolling all loops implies that standard loop unrolling must also
1787 if (flag_unroll_all_loops)
1788 flag_unroll_loops = 1;
1790 /* The loop unrolling code assumes that cse will be run after loop.
1791 web and rename-registers also help when run after loop unrolling. */
1792 if (flag_rerun_cse_after_loop == AUTODETECT_VALUE)
1793 flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops;
1795 if (flag_web == AUTODETECT_VALUE)
1796 flag_web = flag_unroll_loops || flag_peel_loops;
1798 if (flag_rename_registers == AUTODETECT_VALUE)
1799 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1801 if (flag_non_call_exceptions)
1802 flag_asynchronous_unwind_tables = 1;
1803 if (flag_asynchronous_unwind_tables)
1804 flag_unwind_tables = 1;
1806 if (flag_value_profile_transformations)
1807 flag_profile_values = 1;
1809 /* Warn about options that are not supported on this machine. */
1810 #ifndef INSN_SCHEDULING
1811 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1812 warning (0, "instruction scheduling not supported on this target machine");
1815 if (flag_delayed_branch)
1816 warning (0, "this target machine does not have delayed branches");
1819 user_label_prefix = USER_LABEL_PREFIX;
1820 if (flag_leading_underscore != -1)
1822 /* If the default prefix is more complicated than "" or "_",
1823 issue a warning and ignore this option. */
1824 if (user_label_prefix[0] == 0 ||
1825 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1827 user_label_prefix = flag_leading_underscore ? "_" : "";
1830 warning (0, "-f%sleading-underscore not supported on this target machine",
1831 flag_leading_underscore ? "" : "no-");
1834 /* If we are in verbose mode, write out the version and maybe all the
1835 option flags in use. */
1838 print_version (stderr, "");
1840 print_switch_values (print_to_stderr);
1843 if (flag_syntax_only)
1845 write_symbols = NO_DEBUG;
1851 if (debug_info_level == DINFO_LEVEL_NONE)
1853 debug_info_level = DINFO_LEVEL_NORMAL;
1855 if (write_symbols == NO_DEBUG)
1856 write_symbols = PREFERRED_DEBUGGING_TYPE;
1859 debug_info_level = DINFO_LEVEL_NONE;
1862 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1864 FILE *final_output = fopen (flag_dump_final_insns, "w");
1867 error ("could not open final insn dump file %qs: %m",
1868 flag_dump_final_insns);
1869 flag_dump_final_insns = NULL;
1871 else if (fclose (final_output))
1873 error ("could not close zeroed insn dump file %qs: %m",
1874 flag_dump_final_insns);
1875 flag_dump_final_insns = NULL;
1879 /* Unless over-ridden for the target, assume that all DWARF levels
1880 may be emitted, if DWARF2_DEBUG is selected. */
1881 if (dwarf_strict < 0)
1884 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1886 if (debug_info_level == DINFO_LEVEL_NONE)
1887 write_symbols = NO_DEBUG;
1889 if (write_symbols == NO_DEBUG)
1891 #if defined(DBX_DEBUGGING_INFO)
1892 else if (write_symbols == DBX_DEBUG)
1893 debug_hooks = &dbx_debug_hooks;
1895 #if defined(XCOFF_DEBUGGING_INFO)
1896 else if (write_symbols == XCOFF_DEBUG)
1897 debug_hooks = &xcoff_debug_hooks;
1899 #ifdef SDB_DEBUGGING_INFO
1900 else if (write_symbols == SDB_DEBUG)
1901 debug_hooks = &sdb_debug_hooks;
1903 #ifdef DWARF2_DEBUGGING_INFO
1904 else if (write_symbols == DWARF2_DEBUG)
1905 debug_hooks = &dwarf2_debug_hooks;
1907 #ifdef VMS_DEBUGGING_INFO
1908 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1909 debug_hooks = &vmsdbg_debug_hooks;
1912 error ("target system does not support the \"%s\" debug format",
1913 debug_type_names[write_symbols]);
1915 /* We know which debug output will be used so we can set flag_var_tracking
1916 and flag_var_tracking_uninit if the user has not specified them. */
1917 if (debug_info_level < DINFO_LEVEL_NORMAL
1918 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1920 if (flag_var_tracking == 1
1921 || flag_var_tracking_uninit == 1)
1923 if (debug_info_level < DINFO_LEVEL_NORMAL)
1924 warning (0, "variable tracking requested, but useless unless "
1925 "producing debug info");
1927 warning (0, "variable tracking requested, but not supported "
1928 "by this debug format");
1930 flag_var_tracking = 0;
1931 flag_var_tracking_uninit = 0;
1934 /* If the user specifically requested variable tracking with tagging
1935 uninitialized variables, we need to turn on variable tracking.
1936 (We already determined above that variable tracking is feasible.) */
1937 if (flag_var_tracking_uninit)
1938 flag_var_tracking = 1;
1940 if (flag_var_tracking == AUTODETECT_VALUE)
1941 flag_var_tracking = optimize >= 1;
1943 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
1944 flag_var_tracking_assignments = flag_var_tracking
1945 && !(flag_selective_scheduling || flag_selective_scheduling2);
1947 if (flag_var_tracking_assignments_toggle)
1948 flag_var_tracking_assignments = !flag_var_tracking_assignments;
1950 if (flag_var_tracking_assignments && !flag_var_tracking)
1951 flag_var_tracking = flag_var_tracking_assignments = -1;
1953 if (flag_var_tracking_assignments
1954 && (flag_selective_scheduling || flag_selective_scheduling2))
1955 warning (0, "var-tracking-assignments changes selective scheduling");
1957 if (flag_tree_cselim == AUTODETECT_VALUE)
1958 #ifdef HAVE_conditional_move
1959 flag_tree_cselim = 1;
1961 flag_tree_cselim = 0;
1964 /* If auxiliary info generation is desired, open the output file.
1965 This goes in the same directory as the source file--unlike
1966 all the other output files. */
1967 if (flag_gen_aux_info)
1969 aux_info_file = fopen (aux_info_file_name, "w");
1970 if (aux_info_file == 0)
1971 fatal_error ("can%'t open %s: %m", aux_info_file_name);
1974 if (! targetm.have_named_sections)
1976 if (flag_function_sections)
1978 warning (0, "-ffunction-sections not supported for this target");
1979 flag_function_sections = 0;
1981 if (flag_data_sections)
1983 warning (0, "-fdata-sections not supported for this target");
1984 flag_data_sections = 0;
1988 if (flag_function_sections && profile_flag)
1990 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
1991 flag_function_sections = 0;
1994 #ifndef HAVE_prefetch
1995 if (flag_prefetch_loop_arrays > 0)
1997 warning (0, "-fprefetch-loop-arrays not supported for this target");
1998 flag_prefetch_loop_arrays = 0;
2001 if (flag_prefetch_loop_arrays > 0 && !HAVE_prefetch)
2003 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
2004 flag_prefetch_loop_arrays = 0;
2008 /* This combination of options isn't handled for i386 targets and doesn't
2009 make much sense anyway, so don't allow it. */
2010 if (flag_prefetch_loop_arrays > 0 && optimize_size)
2012 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
2013 flag_prefetch_loop_arrays = 0;
2016 /* The presence of IEEE signaling NaNs, implies all math can trap. */
2017 if (flag_signaling_nans)
2018 flag_trapping_math = 1;
2020 /* We cannot reassociate if we want traps or signed zeros. */
2021 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
2023 warning (0, "-fassociative-math disabled; other options take precedence");
2024 flag_associative_math = 0;
2027 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
2028 if (flag_cx_limited_range)
2029 flag_complex_method = 0;
2031 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
2032 if (flag_cx_fortran_rules)
2033 flag_complex_method = 1;
2035 /* Targets must be able to place spill slots at lower addresses. If the
2036 target already uses a soft frame pointer, the transition is trivial. */
2037 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
2039 warning (0, "-fstack-protector not supported for this target");
2040 flag_stack_protect = 0;
2042 if (!flag_stack_protect)
2043 warn_stack_protect = 0;
2045 /* ??? Unwind info is not correct around the CFG unless either a frame
2046 pointer is present or A_O_A is set. Fixing this requires rewriting
2047 unwind info generation to be aware of the CFG and propagating states
2049 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
2050 && flag_omit_frame_pointer)
2052 warning (0, "unwind tables currently require a frame pointer "
2054 flag_omit_frame_pointer = 0;
2057 /* Save the current optimization options. */
2058 optimization_default_node = build_optimization_node ();
2059 optimization_current_node = optimization_default_node;
2062 /* This function can be called multiple times to reinitialize the compiler
2063 back end when register classes or instruction sets have changed,
2064 before each function. */
2066 backend_init_target (void)
2068 /* Initialize alignment variables. */
2071 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
2072 to initialize reg_raw_mode[]. */
2075 /* This invokes target hooks to set fixed_reg[] etc, which is
2079 /* This depends on stack_pointer_rtx. */
2080 init_fake_stack_mems ();
2082 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
2084 init_alias_target ();
2086 /* Depends on HARD_FRAME_POINTER_REGNUM. */
2089 /* The following initialization functions need to generate rtl, so
2090 provide a dummy function context for them. */
2091 init_dummy_function_start ();
2093 /* rtx_cost is mode-dependent, so cached values need to be recomputed
2094 on a mode change. */
2097 /* We may need to recompute regno_save_code[] and regno_restore_code[]
2098 after a mode change as well. */
2099 caller_save_initialized_p = false;
2101 expand_dummy_function_end ();
2104 /* Initialize the compiler back end. This function is called only once,
2105 when starting the compiler. */
2112 init_inline_once ();
2113 init_varasm_once ();
2114 save_register_info ();
2116 /* Initialize the target-specific back end pieces. */
2118 backend_init_target ();
2121 /* Initialize excess precision settings. */
2123 init_excess_precision (void)
2125 /* Adjust excess precision handling based on the target options. If
2126 the front end cannot handle it, flag_excess_precision_cmdline
2127 will already have been set accordingly in the post_options
2129 gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
2130 flag_excess_precision = flag_excess_precision_cmdline;
2131 if (flag_unsafe_math_optimizations)
2132 flag_excess_precision = EXCESS_PRECISION_FAST;
2133 if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
2135 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
2136 switch (flt_eval_method)
2140 /* Either the target acts unpredictably (-1) or has all the
2141 operations required not to have excess precision (0). */
2142 flag_excess_precision = EXCESS_PRECISION_FAST;
2146 /* In these cases, predictable excess precision makes
2150 /* Any other implementation-defined FLT_EVAL_METHOD values
2151 require the compiler to handle the associated excess
2152 precision rules in excess_precision_type. */
2158 /* Initialize things that are both lang-dependent and target-dependent.
2159 This function can be called more than once if target parameters change. */
2161 lang_dependent_init_target (void)
2163 /* This determines excess precision settings. */
2164 init_excess_precision ();
2166 /* This creates various _DECL nodes, so needs to be called after the
2167 front end is initialized. It also depends on the HAVE_xxx macros
2168 generated from the target machine description. */
2171 /* The following initialization functions need to generate rtl, so
2172 provide a dummy function context for them. */
2173 init_dummy_function_start ();
2175 /* Do the target-specific parts of expr initialization. */
2176 init_expr_target ();
2178 /* Although the actions of these functions are language-independent,
2179 they use optabs, so we cannot call them from backend_init. */
2183 expand_dummy_function_end ();
2186 /* Language-dependent initialization. Returns nonzero on success. */
2188 lang_dependent_init (const char *name)
2190 location_t save_loc = input_location;
2191 if (dump_base_name == 0)
2192 dump_base_name = name && name[0] ? name : "gccdump";
2194 /* Other front-end initialization. */
2195 input_location = BUILTINS_LOCATION;
2196 if (lang_hooks.init () == 0)
2198 input_location = save_loc;
2200 init_asm_output (name);
2202 /* This creates various _DECL nodes, so needs to be called after the
2203 front end is initialized. */
2206 /* Do the target-specific parts of the initialization. */
2207 lang_dependent_init_target ();
2209 /* If dbx symbol table desired, initialize writing it and output the
2210 predefined types. */
2211 timevar_push (TV_SYMOUT);
2213 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2214 if (dwarf2out_do_frame ())
2215 dwarf2out_frame_init ();
2218 /* Now we have the correct original filename, we can initialize
2220 (*debug_hooks->init) (name);
2222 timevar_pop (TV_SYMOUT);
2228 /* Reinitialize everything when target parameters, such as register usage,
2231 target_reinit (void)
2233 /* Reinitialize RTL backend. */
2234 backend_init_target ();
2236 /* Reinitialize lang-dependent parts. */
2237 lang_dependent_init_target ();
2241 dump_memory_report (bool final)
2243 ggc_print_statistics ();
2244 stringpool_statistics ();
2245 dump_tree_statistics ();
2246 dump_gimple_statistics ();
2247 dump_rtx_statistics ();
2248 dump_alloc_pool_statistics ();
2249 dump_bitmap_statistics ();
2250 dump_vec_loc_statistics ();
2251 dump_ggc_loc_statistics (final);
2252 dump_alias_stats (stderr);
2253 dump_pta_stats (stderr);
2256 /* Clean up: close opened files, etc. */
2261 /* Close the dump files. */
2262 if (flag_gen_aux_info)
2264 fclose (aux_info_file);
2266 unlink (aux_info_file_name);
2269 /* Close non-debugging input and output files. Take special care to note
2270 whether fclose returns an error, since the pages might still be on the
2271 buffer chain while the file is open. */
2275 if (ferror (asm_out_file) != 0)
2276 fatal_error ("error writing to %s: %m", asm_file_name);
2277 if (fclose (asm_out_file) != 0)
2278 fatal_error ("error closing %s: %m", asm_file_name);
2280 unlink_if_ordinary (asm_file_name);
2284 finish_optimization_passes ();
2289 dump_memory_report (true);
2291 /* Language-specific end of compilation actions. */
2292 lang_hooks.finish ();
2295 /* Initialize the compiler, and compile the input file. */
2299 /* Initialize timing first. The C front ends read the main file in
2300 the post_options hook, and C++ does file timings. */
2301 if (time_report || !quiet_flag || flag_detailed_statistics)
2303 timevar_start (TV_TOTAL);
2307 /* Don't do any more if an error has already occurred. */
2310 /* This must be run always, because it is needed to compute the FP
2311 predefined macros, such as __LDBL_MAX__, for targets using non
2312 default FP formats. */
2313 init_adjust_machine_modes ();
2315 /* Set up the back-end if requested. */
2319 /* Language-dependent initialization. Returns true on success. */
2320 if (lang_dependent_init (main_input_filename))
2326 /* Stop timing and print the times. */
2327 timevar_stop (TV_TOTAL);
2328 timevar_print (stderr);
2331 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2332 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2333 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2335 It is not safe to call this function more than once. */
2338 toplev_main (int argc, char **argv)
2340 expandargv (&argc, &argv);
2342 /* Initialization of GCC's environment, and diagnostics. */
2343 general_init (argv[0]);
2345 /* Parse the options and do minimal processing; basically just
2346 enough to default flags appropriately. */
2347 decode_options (argc, CONST_CAST2 (const char **, char **, argv),
2348 &save_decoded_options, &save_decoded_options_count);
2352 initialize_plugins ();
2355 print_version (stderr, "");
2358 print_plugins_help (stderr, "");
2360 /* Exit early if we can (e.g. -help). */
2361 if (!exit_after_options)
2364 if (warningcount || errorcount)
2365 print_ignored_options ();
2366 diagnostic_finish (global_dc);
2368 /* Invoke registered plugin callbacks if any. */
2369 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2371 finalize_plugins ();
2373 return (FATAL_EXIT_CODE);
2375 return (SUCCESS_EXIT_CODE);