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 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 /* 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 /* True if this is the lto front end. This is used to disable
178 gimple generation and lowering passes that are normally run on the
179 output of a front end. These passes must be bypassed for lto since
180 they have already been done before the gimple was written. */
182 bool in_lto_p = false;
184 /* Nonzero if we should write GIMPLE bytecode for link-time optimization. */
186 int flag_generate_lto;
188 /* The FUNCTION_DECL for the function currently being compiled,
189 or 0 if between functions. */
190 tree current_function_decl;
192 /* Set to the FUNC_BEGIN label of the current function, or NULL
194 const char * current_function_func_begin_label;
196 /* A random sequence of characters, unless overridden by user. */
197 static const char *flag_random_seed;
199 /* A local time stamp derived from the time of compilation. It will be
200 zero if the system cannot provide a time. It will be -1u, if the
201 user has specified a particular random seed. */
206 /* 0 means straightforward implementation of complex divide acceptable.
207 1 means wide ranges of inputs must work for complex divide.
208 2 means C99-like requirements for complex multiply and divide. */
210 int flag_complex_method = 1;
212 /* Nonzero means we should be saving declaration info into a .X file. */
214 int flag_gen_aux_info = 0;
216 /* Specified name of aux-info file. */
218 const char *aux_info_file_name;
220 /* Nonzero if we are compiling code for a shared library, zero for
225 /* Generate code for GNU or NeXT Objective-C runtime environment. */
227 #ifdef NEXT_OBJC_RUNTIME
228 int flag_next_runtime = 1;
230 int flag_next_runtime = 0;
233 /* Set to the default thread-local storage (tls) model to use. */
235 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
237 /* Set the default region and algorithm for the integrated register
240 enum ira_algorithm flag_ira_algorithm = IRA_ALGORITHM_CB;
241 enum ira_region flag_ira_region = IRA_REGION_MIXED;
243 /* Set the default for excess precision. */
245 enum excess_precision flag_excess_precision_cmdline = EXCESS_PRECISION_DEFAULT;
247 /* Nonzero means change certain warnings into errors.
248 Usually these are warnings about failure to conform to some standard. */
250 int flag_pedantic_errors = 0;
252 /* Nonzero means make permerror produce warnings instead of errors. */
254 int flag_permissive = 0;
256 /* -dA causes debug commentary information to be produced in
257 the generated assembly code (to make it more readable). This option
258 is generally only of use to those who actually need to read the
259 generated assembly code (perhaps while debugging the compiler itself).
260 Currently, this switch is only used by dwarfout.c; however, it is intended
261 to be a catchall for printing debug information in the assembler file. */
263 int flag_debug_asm = 0;
265 /* -dP causes the rtl to be emitted as a comment in assembly. */
267 int flag_dump_rtl_in_asm = 0;
269 /* When non-NULL, indicates that whenever space is allocated on the
270 stack, the resulting stack pointer must not pass this
271 address---that is, for stacks that grow downward, the stack pointer
272 must always be greater than or equal to this address; for stacks
273 that grow upward, the stack pointer must be less than this address.
274 At present, the rtx may be either a REG or a SYMBOL_REF, although
275 the support provided depends on the backend. */
278 /* Type of stack check. */
279 enum stack_check_type flag_stack_check = NO_STACK_CHECK;
281 /* True if the user has tagged the function with the 'section'
284 bool user_defined_section_attribute = false;
286 struct target_flag_state default_target_flag_state;
287 #if SWITCHABLE_TARGET
288 struct target_flag_state *this_target_flag_state = &default_target_flag_state;
290 #define this_target_flag_state (&default_target_flag_state)
295 const char *const string;
299 lang_independent_options;
301 /* Nonzero if subexpressions must be evaluated from left-to-right. */
302 int flag_evaluation_order = 0;
304 /* The user symbol prefix after having resolved same. */
305 const char *user_label_prefix;
307 static const param_info lang_independent_params[] = {
308 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
309 { OPTION, DEFAULT, false, MIN, MAX, HELP },
310 #include "params.def"
312 { NULL, 0, false, 0, 0, NULL }
315 /* Output files for assembler code (real compiler output)
316 and debugging dumps. */
320 FILE *stack_usage_file = NULL;
321 FILE *dump_file = NULL;
322 const char *dump_file_name;
324 /* The current working directory of a translation. It's generally the
325 directory from which compilation was initiated, but a preprocessed
326 file may specify the original directory in which it was
329 static const char *src_pwd;
331 /* Initialize src_pwd with the given string, and return true. If it
332 was already initialized, return false. As a special case, it may
333 be called with a NULL argument to test whether src_pwd has NOT been
337 set_src_pwd (const char *pwd)
341 if (strcmp (src_pwd, pwd) == 0)
347 src_pwd = xstrdup (pwd);
351 /* Return the directory from which the translation unit was initiated,
352 in case set_src_pwd() was not called before to assign it a
368 /* Called when the start of a function definition is parsed,
369 this function prints on stderr the name of the function. */
371 announce_function (tree decl)
375 if (rtl_dump_and_exit)
376 fprintf (stderr, "%s ",
377 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
379 fprintf (stderr, " %s",
380 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
382 pp_needs_newline (global_dc->printer) = true;
383 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
387 /* Initialize local_tick with the time of day, or -1 if
388 flag_random_seed is set. */
391 init_local_tick (void)
393 if (!flag_random_seed)
395 /* Get some more or less random data. */
396 #ifdef HAVE_GETTIMEOFDAY
400 gettimeofday (&tv, NULL);
401 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
405 time_t now = time (NULL);
407 if (now != (time_t)-1)
408 local_tick = (unsigned) now;
416 /* Set up a default flag_random_seed and local_tick, unless the user
417 already specified one. Must be called after init_local_tick. */
420 init_random_seed (void)
422 unsigned HOST_WIDE_INT value;
423 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
425 value = local_tick ^ getpid ();
427 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
428 flag_random_seed = random_seed;
431 /* Obtain the random_seed string. Unless NOINIT, initialize it if
432 it's not provided in the command line. */
435 get_random_seed (bool noinit)
437 if (!flag_random_seed && !noinit)
439 return flag_random_seed;
442 /* Modify the random_seed string to VAL. Return its previous
446 set_random_seed (const char *val)
448 const char *old = flag_random_seed;
449 flag_random_seed = val;
453 #if GCC_VERSION < 3004
455 /* The functions clz_hwi, ctz_hwi, ffs_hwi, floor_log2 and exact_log2
456 are defined as inline functions in toplev.h if GCC_VERSION >= 3004.
457 The definitions here are used for older versions of gcc. */
459 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
460 If X is 0, return -1. */
463 floor_log2 (unsigned HOST_WIDE_INT x)
470 if (HOST_BITS_PER_WIDE_INT > 64)
471 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
473 if (HOST_BITS_PER_WIDE_INT > 32)
474 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
476 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
478 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
480 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
482 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
484 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
490 /* Return the logarithm of X, base 2, considering X unsigned,
491 if X is a power of 2. Otherwise, returns -1. */
494 exact_log2 (unsigned HOST_WIDE_INT x)
498 return floor_log2 (x);
501 /* Given X, an unsigned number, return the number of least significant bits
502 that are zero. When X == 0, the result is the word size. */
505 ctz_hwi (unsigned HOST_WIDE_INT x)
507 return x ? floor_log2 (x & -x) : HOST_BITS_PER_WIDE_INT;
510 /* Similarly for most significant bits. */
513 clz_hwi (unsigned HOST_WIDE_INT x)
515 return HOST_BITS_PER_WIDE_INT - 1 - floor_log2(x);
518 /* Similar to ctz_hwi, except that the least significant bit is numbered
519 starting from 1, and X == 0 yields 0. */
522 ffs_hwi (unsigned HOST_WIDE_INT x)
524 return 1 + floor_log2 (x & -x);
527 #endif /* GCC_VERSION < 3004 */
529 /* Handler for fatal signals, such as SIGSEGV. These are transformed
530 into ICE messages, which is much more user friendly. In case the
531 error printer crashes, reset the signal to prevent infinite recursion. */
534 crash_signal (int signo)
536 signal (signo, SIG_DFL);
538 /* If we crashed while processing an ASM statement, then be a little more
539 graceful. It's most likely the user's fault. */
540 if (this_is_asm_operands)
542 output_operand_lossage ("unrecoverable error");
543 exit (FATAL_EXIT_CODE);
546 internal_error ("%s", strsignal (signo));
549 /* Arrange to dump core on error. (The regular error message is still
550 printed first, except in the case of abort().) */
553 setup_core_dumping (void)
556 signal (SIGABRT, SIG_DFL);
558 #if defined(HAVE_SETRLIMIT)
561 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
562 fatal_error ("getting core file size maximum limit: %m");
563 rlim.rlim_cur = rlim.rlim_max;
564 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
565 fatal_error ("setting core file size limit to maximum: %m");
568 diagnostic_abort_on_error (global_dc);
572 /* Strip off a legitimate source ending from the input string NAME of
573 length LEN. Rather than having to know the names used by all of
574 our front ends, we strip off an ending of a period followed by
575 up to five characters. (Java uses ".class".) */
578 strip_off_ending (char *name, int len)
581 for (i = 2; i < 6 && len > i; i++)
583 if (name[len - i] == '.')
585 name[len - i] = '\0';
591 /* Output a quoted string. */
594 output_quoted_string (FILE *asm_file, const char *string)
596 #ifdef OUTPUT_QUOTED_STRING
597 OUTPUT_QUOTED_STRING (asm_file, string);
601 putc ('\"', asm_file);
602 while ((c = *string++) != 0)
606 if (c == '\"' || c == '\\')
607 putc ('\\', asm_file);
611 fprintf (asm_file, "\\%03o", (unsigned char) c);
613 putc ('\"', asm_file);
617 /* A subroutine of wrapup_global_declarations. We've come to the end of
618 the compilation unit. All deferred variables should be undeferred,
619 and all incomplete decls should be finalized. */
622 wrapup_global_declaration_1 (tree decl)
624 /* We're not deferring this any longer. Assignment is conditional to
625 avoid needlessly dirtying PCH pages. */
626 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
627 && DECL_DEFER_OUTPUT (decl) != 0)
628 DECL_DEFER_OUTPUT (decl) = 0;
630 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
631 lang_hooks.finish_incomplete_decl (decl);
634 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
635 needs to be output. Return true if it is output. */
638 wrapup_global_declaration_2 (tree decl)
640 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
643 /* Don't write out static consts, unless we still need them.
645 We also keep static consts if not optimizing (for debugging),
646 unless the user specified -fno-keep-static-consts.
647 ??? They might be better written into the debug information.
648 This is possible when using DWARF.
650 A language processor that wants static constants to be always
651 written out (even if it is not used) is responsible for
652 calling rest_of_decl_compilation itself. E.g. the C front-end
653 calls rest_of_decl_compilation from finish_decl.
654 One motivation for this is that is conventional in some
655 environments to write things like:
656 static const char rcsid[] = "... version string ...";
657 intending to force the string to be in the executable.
659 A language processor that would prefer to have unneeded
660 static constants "optimized away" would just defer writing
661 them out until here. E.g. C++ does this, because static
662 constants are often defined in header files.
664 ??? A tempting alternative (for both C and C++) would be
665 to force a constant to be written if and only if it is
666 defined in a main file, as opposed to an include file. */
668 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
670 struct varpool_node *node;
672 node = varpool_get_node (decl);
674 if (!node && flag_ltrans)
676 else if (node && node->finalized)
678 else if (node && node->alias)
680 else if (!cgraph_global_info_ready
682 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
684 else if (node && node->needed)
686 else if (DECL_COMDAT (decl))
688 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
689 && (optimize || !flag_keep_static_consts
690 || DECL_ARTIFICIAL (decl)))
695 rest_of_decl_compilation (decl, 1, 1);
703 /* Do any final processing required for the declarations in VEC, of
704 which there are LEN. We write out inline functions and variables
705 that have been deferred until this point, but which are required.
706 Returns nonzero if anything was put out. */
709 wrapup_global_declarations (tree *vec, int len)
711 bool reconsider, output_something = false;
714 for (i = 0; i < len; i++)
715 wrapup_global_declaration_1 (vec[i]);
717 /* Now emit any global variables or functions that we have been
718 putting off. We need to loop in case one of the things emitted
719 here references another one which comes earlier in the list. */
723 for (i = 0; i < len; i++)
724 reconsider |= wrapup_global_declaration_2 (vec[i]);
726 output_something = true;
730 return output_something;
733 /* A subroutine of check_global_declarations. Issue appropriate warnings
734 for the global declaration DECL. */
737 check_global_declaration_1 (tree decl)
739 /* Warn about any function declared static but not defined. We don't
740 warn about variables, because many programs have static variables
741 that exist only to get some text into the object file. */
742 if (TREE_CODE (decl) == FUNCTION_DECL
743 && DECL_INITIAL (decl) == 0
744 && DECL_EXTERNAL (decl)
745 && ! DECL_ARTIFICIAL (decl)
746 && ! TREE_NO_WARNING (decl)
747 && ! TREE_PUBLIC (decl)
748 && (warn_unused_function
749 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
751 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
752 pedwarn (input_location, 0, "%q+F used but never defined", decl);
754 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
755 /* This symbol is effectively an "extern" declaration now. */
756 TREE_PUBLIC (decl) = 1;
757 assemble_external (decl);
760 /* Warn about static fns or vars defined but not used. */
761 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
762 /* We don't warn about "static const" variables because the
763 "rcs_id" idiom uses that construction. */
764 || (warn_unused_variable
765 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
766 && ! DECL_IN_SYSTEM_HEADER (decl)
767 && ! TREE_USED (decl)
768 /* The TREE_USED bit for file-scope decls is kept in the identifier,
769 to handle multiple external decls in different scopes. */
770 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
771 && ! DECL_EXTERNAL (decl)
772 && ! TREE_PUBLIC (decl)
773 /* A volatile variable might be used in some non-obvious way. */
774 && ! TREE_THIS_VOLATILE (decl)
775 /* Global register variables must be declared to reserve them. */
776 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
777 /* Otherwise, ask the language. */
778 && lang_hooks.decls.warn_unused_global (decl))
779 warning ((TREE_CODE (decl) == FUNCTION_DECL)
780 ? OPT_Wunused_function
781 : OPT_Wunused_variable,
782 "%q+D defined but not used", decl);
785 /* Issue appropriate warnings for the global declarations in VEC (of
786 which there are LEN). */
789 check_global_declarations (tree *vec, int len)
793 for (i = 0; i < len; i++)
794 check_global_declaration_1 (vec[i]);
797 /* Emit debugging information for all global declarations in VEC. */
800 emit_debug_global_declarations (tree *vec, int len)
804 /* Avoid confusing the debug information machinery when there are errors. */
808 timevar_push (TV_SYMOUT);
809 for (i = 0; i < len; i++)
810 debug_hooks->global_decl (vec[i]);
811 timevar_pop (TV_SYMOUT);
814 /* Warn about a use of an identifier which was marked deprecated. */
816 warn_deprecated_use (tree node, tree attr)
820 if (node == 0 || !warn_deprecated_decl)
826 attr = DECL_ATTRIBUTES (node);
827 else if (TYPE_P (node))
829 tree decl = TYPE_STUB_DECL (node);
831 attr = lookup_attribute ("deprecated",
832 TYPE_ATTRIBUTES (TREE_TYPE (decl)));
837 attr = lookup_attribute ("deprecated", attr);
840 msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
846 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
848 warning (OPT_Wdeprecated_declarations,
849 "%qD is deprecated (declared at %s:%d): %s",
850 node, xloc.file, xloc.line, msg);
852 warning (OPT_Wdeprecated_declarations,
853 "%qD is deprecated (declared at %s:%d)",
854 node, xloc.file, xloc.line);
856 else if (TYPE_P (node))
858 tree what = NULL_TREE;
859 tree decl = TYPE_STUB_DECL (node);
861 if (TYPE_NAME (node))
863 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
864 what = TYPE_NAME (node);
865 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
866 && DECL_NAME (TYPE_NAME (node)))
867 what = DECL_NAME (TYPE_NAME (node));
872 expanded_location xloc
873 = expand_location (DECL_SOURCE_LOCATION (decl));
877 warning (OPT_Wdeprecated_declarations,
878 "%qE is deprecated (declared at %s:%d): %s",
879 what, xloc.file, xloc.line, msg);
881 warning (OPT_Wdeprecated_declarations,
882 "%qE is deprecated (declared at %s:%d)", what,
883 xloc.file, xloc.line);
888 warning (OPT_Wdeprecated_declarations,
889 "type is deprecated (declared at %s:%d): %s",
890 xloc.file, xloc.line, msg);
892 warning (OPT_Wdeprecated_declarations,
893 "type is deprecated (declared at %s:%d)",
894 xloc.file, xloc.line);
902 warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s",
905 warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what);
910 warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
913 warning (OPT_Wdeprecated_declarations, "type is deprecated");
919 /* Compile an entire translation unit. Write a file of assembly
920 output and various debugging dumps. */
925 /* Initialize yet another pass. */
927 ggc_protect_identifiers = true;
930 init_final (main_input_filename);
931 coverage_init (aux_base_name);
933 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
935 timevar_push (TV_PARSE);
937 /* Call the parser, which parses the entire file (calling
938 rest_of_compilation for each function). */
939 lang_hooks.parse_file (set_yydebug);
941 /* Compilation is now finished except for writing
942 what's left of the symbol table output. */
943 timevar_pop (TV_PARSE);
945 if (flag_syntax_only || flag_wpa)
948 ggc_protect_identifiers = false;
950 /* This must also call cgraph_finalize_compilation_unit. */
951 lang_hooks.decls.final_write_globals ();
956 varpool_assemble_pending_decls ();
959 /* Likewise for mudflap static object registrations. */
961 mudflap_finish_file ();
963 output_shared_constant_pool ();
964 output_object_blocks ();
966 /* Write out any pending weak symbol declarations. */
969 /* This must be at the end before unwind and debug info.
970 Some target ports emit PIC setup thunks here. */
971 targetm.asm_out.code_end ();
973 /* Do dbx symbols. */
974 timevar_push (TV_SYMOUT);
976 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
977 if (dwarf2out_do_frame ())
978 dwarf2out_frame_finish ();
981 (*debug_hooks->finish) (main_input_filename);
982 timevar_pop (TV_SYMOUT);
984 /* Output some stuff at end of file if nec. */
986 dw2_output_indirect_constants ();
988 /* Flush any pending external directives. */
989 process_pending_assemble_externals ();
991 /* Emit LTO marker if LTO info has been previously emitted. This is
992 used by collect2 to determine whether an object file contains IL.
993 We used to emit an undefined reference here, but this produces
994 link errors if an object file with IL is stored into a shared
995 library without invoking lto1. */
996 if (flag_generate_lto)
998 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
999 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
1001 (unsigned HOST_WIDE_INT) 1, 8);
1002 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1003 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1",
1004 (unsigned HOST_WIDE_INT) 1, 8);
1006 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1",
1007 (unsigned HOST_WIDE_INT) 1,
1008 (unsigned HOST_WIDE_INT) 1);
1012 /* Attach a special .ident directive to the end of the file to identify
1013 the version of GCC which compiled this code. The format of the .ident
1014 string is patterned after the ones produced by native SVR4 compilers. */
1018 const char *pkg_version = "(GNU) ";
1020 if (strcmp ("(GCC) ", pkgversion_string))
1021 pkg_version = pkgversion_string;
1022 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
1023 IDENT_ASM_OP, pkg_version, version_string);
1027 /* Invoke registered plugin callbacks. */
1028 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
1030 /* This must be at the end. Some target ports emit end of file directives
1031 into the assembly file here, and hence we can not output anything to the
1032 assembly file after this point. */
1033 targetm.asm_out.file_end ();
1036 /* Parse a -d... command line switch. */
1039 decode_d_option (const char *arg)
1050 flag_print_asm_name = 1;
1053 flag_dump_rtl_in_asm = 1;
1054 flag_print_asm_name = 1;
1057 graph_dump_format = vcg;
1060 rtl_dump_and_exit = 1;
1065 case 'D': /* These are handled by the preprocessor. */
1072 setup_core_dumping();
1075 enable_rtl_dump_file ();
1079 warning (0, "unrecognized gcc debugging option: %c", c);
1084 /* Indexed by enum debug_info_type. */
1085 const char *const debug_type_names[] =
1087 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1090 /* Print version information to FILE.
1091 Each line begins with INDENT (for the case where FILE is the
1092 assembler output file). */
1095 print_version (FILE *file, const char *indent)
1097 static const char fmt1[] =
1099 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1101 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1104 static const char fmt2[] =
1105 N_("GMP version %s, MPFR version %s, MPC version %s\n");
1106 static const char fmt3[] =
1107 N_("%s%swarning: %s header version %s differs from library version %s.\n");
1108 static const char fmt4[] =
1109 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1111 #define __VERSION__ "[?]"
1114 file == stderr ? _(fmt1) : fmt1,
1115 indent, *indent != 0 ? " " : "",
1116 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
1117 indent, __VERSION__);
1119 /* We need to stringify the GMP macro values. Ugh, gmp_version has
1120 two string formats, "i.j.k" and "i.j" when k is zero. As of
1121 gmp-4.3.0, GMP always uses the 3 number format. */
1122 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1123 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1124 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
1125 #define GCC_GMP_VERSION \
1126 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
1127 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
1128 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1129 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1131 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1132 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1133 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1136 file == stderr ? _(fmt2) : fmt2,
1137 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING);
1138 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
1140 file == stderr ? _(fmt3) : fmt3,
1141 indent, *indent != 0 ? " " : "",
1142 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
1143 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
1145 file == stderr ? _(fmt3) : fmt3,
1146 indent, *indent != 0 ? " " : "",
1147 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
1148 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
1150 file == stderr ? _(fmt3) : fmt3,
1151 indent, *indent != 0 ? " " : "",
1152 "MPC", MPC_VERSION_STRING, mpc_get_version ());
1154 file == stderr ? _(fmt4) : fmt4,
1155 indent, *indent != 0 ? " " : "",
1156 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1158 print_plugins_versions (file, indent);
1161 #ifdef ASM_COMMENT_START
1163 print_to_asm_out_file (print_switch_type type, const char * text)
1165 bool prepend_sep = true;
1169 case SWITCH_TYPE_LINE_END:
1170 putc ('\n', asm_out_file);
1173 case SWITCH_TYPE_LINE_START:
1174 fputs (ASM_COMMENT_START, asm_out_file);
1175 return strlen (ASM_COMMENT_START);
1177 case SWITCH_TYPE_DESCRIPTIVE:
1178 if (ASM_COMMENT_START[0] == 0)
1179 prepend_sep = false;
1181 case SWITCH_TYPE_PASSED:
1182 case SWITCH_TYPE_ENABLED:
1184 fputc (' ', asm_out_file);
1185 fputs (text, asm_out_file);
1186 /* No need to return the length here as
1187 print_single_switch has already done it. */
1197 print_to_stderr (print_switch_type type, const char * text)
1201 case SWITCH_TYPE_LINE_END:
1202 putc ('\n', stderr);
1205 case SWITCH_TYPE_LINE_START:
1208 case SWITCH_TYPE_PASSED:
1209 case SWITCH_TYPE_ENABLED:
1210 fputc (' ', stderr);
1213 case SWITCH_TYPE_DESCRIPTIVE:
1214 fputs (text, stderr);
1215 /* No need to return the length here as
1216 print_single_switch has already done it. */
1224 /* Print an option value and return the adjusted position in the line.
1225 ??? print_fn doesn't handle errors, eg disk full; presumably other
1226 code will catch a disk full though. */
1229 print_single_switch (print_switch_fn_type print_fn,
1231 print_switch_type type,
1234 /* The ultrix fprintf returns 0 on success, so compute the result
1235 we want here since we need it for the following test. The +1
1236 is for the separator character that will probably be emitted. */
1237 int len = strlen (text) + 1;
1240 && pos + len > MAX_LINE)
1242 print_fn (SWITCH_TYPE_LINE_END, NULL);
1247 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1249 print_fn (type, text);
1253 /* Print active target switches using PRINT_FN.
1254 POS is the current cursor position and MAX is the size of a "line".
1255 Each line begins with INDENT and ends with TERM.
1256 Each switch is separated from the next by SEP. */
1259 print_switch_values (print_switch_fn_type print_fn)
1264 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1265 that it can be printed below. This helps reproducibility. */
1266 if (!flag_random_seed)
1267 init_random_seed ();
1269 /* Print the options as passed. */
1270 pos = print_single_switch (print_fn, pos,
1271 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1273 for (j = 1; j < save_decoded_options_count; j++)
1275 switch (save_decoded_options[j].opt_index)
1288 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED,
1289 save_decoded_options[j].orig_option_with_args_text);
1293 print_fn (SWITCH_TYPE_LINE_END, NULL);
1295 /* Print the -f and -m options that have been enabled.
1296 We don't handle language specific options but printing argv
1298 pos = print_single_switch (print_fn, 0,
1299 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1301 for (j = 0; j < cl_options_count; j++)
1302 if ((cl_options[j].flags & CL_REPORT)
1303 && option_enabled (j, &global_options) > 0)
1304 pos = print_single_switch (print_fn, pos,
1305 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1307 print_fn (SWITCH_TYPE_LINE_END, NULL);
1310 /* Open assembly code output file. Do this even if -fsyntax-only is
1311 on, because then the driver will have provided the name of a
1312 temporary file or bit bucket for us. NAME is the file specified on
1313 the command line, possibly NULL. */
1315 init_asm_output (const char *name)
1317 if (name == NULL && asm_file_name == 0)
1318 asm_out_file = stdout;
1321 if (asm_file_name == 0)
1323 int len = strlen (dump_base_name);
1324 char *dumpname = XNEWVEC (char, len + 6);
1326 memcpy (dumpname, dump_base_name, len + 1);
1327 strip_off_ending (dumpname, len);
1328 strcat (dumpname, ".s");
1329 asm_file_name = dumpname;
1331 if (!strcmp (asm_file_name, "-"))
1332 asm_out_file = stdout;
1334 asm_out_file = fopen (asm_file_name, "w+b");
1335 if (asm_out_file == 0)
1336 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1339 if (!flag_syntax_only)
1341 targetm.asm_out.file_start ();
1343 if (flag_record_gcc_switches)
1345 if (targetm.asm_out.record_gcc_switches)
1347 /* Let the target know that we are about to start recording. */
1348 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1350 /* Now record the switches. */
1351 print_switch_values (targetm.asm_out.record_gcc_switches);
1352 /* Let the target know that the recording is over. */
1353 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1357 inform (input_location, "-frecord-gcc-switches is not supported by the current target");
1360 #ifdef ASM_COMMENT_START
1361 if (flag_verbose_asm)
1363 /* Print the list of switches in effect
1364 into the assembler file as comments. */
1365 print_version (asm_out_file, ASM_COMMENT_START);
1366 print_switch_values (print_to_asm_out_file);
1367 putc ('\n', asm_out_file);
1373 /* Return true if the state of option OPTION should be stored in PCH files
1374 and checked by default_pch_valid_p. Store the option's current state
1378 option_affects_pch_p (int option, struct cl_option_state *state)
1380 if ((cl_options[option].flags & CL_TARGET) == 0)
1382 if (option_flag_var (option, &global_options) == &target_flags)
1383 if (targetm.check_pch_target_flags)
1385 return get_option_state (&global_options, option, state);
1388 /* Default version of get_pch_validity.
1389 By default, every flag difference is fatal; that will be mostly right for
1390 most targets, but completely right for very few. */
1393 default_get_pch_validity (size_t *sz)
1395 struct cl_option_state state;
1400 if (targetm.check_pch_target_flags)
1401 *sz += sizeof (target_flags);
1402 for (i = 0; i < cl_options_count; i++)
1403 if (option_affects_pch_p (i, &state))
1406 result = r = XNEWVEC (char, *sz);
1410 if (targetm.check_pch_target_flags)
1412 memcpy (r, &target_flags, sizeof (target_flags));
1413 r += sizeof (target_flags);
1416 for (i = 0; i < cl_options_count; i++)
1417 if (option_affects_pch_p (i, &state))
1419 memcpy (r, state.data, state.size);
1426 /* Return a message which says that a PCH file was created with a different
1427 setting of OPTION. */
1430 pch_option_mismatch (const char *option)
1434 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1436 return _("out of memory");
1440 /* Default version of pch_valid_p. */
1443 default_pch_valid_p (const void *data_p, size_t len)
1445 struct cl_option_state state;
1446 const char *data = (const char *)data_p;
1449 /* -fpic and -fpie also usually make a PCH invalid. */
1450 if (data[0] != flag_pic)
1451 return _("created and used with different settings of -fpic");
1452 if (data[1] != flag_pie)
1453 return _("created and used with different settings of -fpie");
1456 /* Check target_flags. */
1457 if (targetm.check_pch_target_flags)
1462 memcpy (&tf, data, sizeof (target_flags));
1463 data += sizeof (target_flags);
1464 len -= sizeof (target_flags);
1465 r = targetm.check_pch_target_flags (tf);
1470 for (i = 0; i < cl_options_count; i++)
1471 if (option_affects_pch_p (i, &state))
1473 if (memcmp (data, state.data, state.size) != 0)
1474 return pch_option_mismatch (cl_options[i].opt_text);
1482 /* Default tree printer. Handles declarations only. */
1484 default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
1485 int precision, bool wide, bool set_locus, bool hash)
1489 /* FUTURE: %+x should set the locus. */
1490 if (precision != 0 || wide || hash)
1496 t = va_arg (*text->args_ptr, tree);
1497 if (TREE_CODE (t) == IDENTIFIER_NODE)
1499 pp_identifier (pp, IDENTIFIER_POINTER (t));
1505 t = va_arg (*text->args_ptr, tree);
1506 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1507 t = DECL_DEBUG_EXPR (t);
1512 t = va_arg (*text->args_ptr, tree);
1516 percent_K_format (text);
1523 if (set_locus && text->locus)
1524 *text->locus = DECL_SOURCE_LOCATION (t);
1528 const char *n = DECL_NAME (t)
1529 ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2))
1534 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1539 /* A helper function; used as the reallocator function for cpp's line
1542 realloc_for_line_map (void *ptr, size_t len)
1544 return GGC_RESIZEVAR (void, ptr, len);
1547 /* A helper function: used as the allocator function for
1548 identifier_to_locale. */
1550 alloc_for_identifier_to_locale (size_t len)
1552 return ggc_alloc_atomic (len);
1555 /* Output stack usage information. */
1557 output_stack_usage (void)
1559 static bool warning_issued = false;
1560 enum stack_usage_kind_type { STATIC = 0, DYNAMIC, DYNAMIC_BOUNDED };
1561 const char *stack_usage_kind_str[] = {
1566 HOST_WIDE_INT stack_usage = current_function_static_stack_size;
1567 enum stack_usage_kind_type stack_usage_kind;
1568 expanded_location loc;
1569 const char *raw_id, *id;
1571 if (stack_usage < 0)
1573 if (!warning_issued)
1575 warning (0, "-fstack-usage not supported for this target");
1576 warning_issued = true;
1581 stack_usage_kind = STATIC;
1583 /* Add the maximum amount of space pushed onto the stack. */
1584 if (current_function_pushed_stack_size > 0)
1586 stack_usage += current_function_pushed_stack_size;
1587 stack_usage_kind = DYNAMIC_BOUNDED;
1590 /* Now on to the tricky part: dynamic stack allocation. */
1591 if (current_function_allocates_dynamic_stack_space)
1593 if (current_function_has_unbounded_dynamic_stack_size)
1594 stack_usage_kind = DYNAMIC;
1596 stack_usage_kind = DYNAMIC_BOUNDED;
1598 /* Add the size even in the unbounded case, this can't hurt. */
1599 stack_usage += current_function_dynamic_stack_size;
1602 loc = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
1604 /* Strip the scope prefix if any. */
1605 raw_id = lang_hooks.decl_printable_name (current_function_decl, 2);
1606 id = strrchr (raw_id, '.');
1612 fprintf (stack_usage_file,
1613 "%s:%d:%d:%s\t"HOST_WIDE_INT_PRINT_DEC"\t%s\n",
1614 lbasename (loc.file),
1619 stack_usage_kind_str[stack_usage_kind]);
1622 /* Open an auxiliary output file. */
1624 open_auxiliary_file (const char *ext)
1629 filename = concat (aux_base_name, ".", ext, NULL);
1630 file = fopen (filename, "w");
1632 fatal_error ("can't open %s for writing: %m", filename);
1637 /* Initialization of the front end environment, before command line
1638 options are parsed. Signal handlers, internationalization etc.
1639 ARGV0 is main's argv[0]. */
1641 general_init (const char *argv0)
1645 p = argv0 + strlen (argv0);
1646 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1650 xmalloc_set_program_name (progname);
1654 /* Unlock the stdio streams. */
1655 unlock_std_streams ();
1657 gcc_init_libintl ();
1659 identifier_to_locale_alloc = alloc_for_identifier_to_locale;
1660 identifier_to_locale_free = ggc_free;
1662 /* Initialize the diagnostics reporting machinery, so option parsing
1663 can give warnings and errors. */
1664 diagnostic_initialize (global_dc, N_OPTS);
1665 diagnostic_starter (global_dc) = default_tree_diagnostic_starter;
1666 /* Set a default printer. Language specific initializations will
1667 override it later. */
1668 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1669 global_dc->show_option_requested = flag_diagnostics_show_option;
1670 global_dc->show_column = flag_show_column;
1671 global_dc->internal_error = plugins_internal_error_function;
1672 global_dc->option_enabled = option_enabled;
1673 global_dc->option_state = &global_options;
1674 global_dc->option_name = option_name;
1676 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1678 signal (SIGSEGV, crash_signal);
1681 signal (SIGILL, crash_signal);
1684 signal (SIGBUS, crash_signal);
1687 signal (SIGABRT, crash_signal);
1689 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1690 signal (SIGIOT, crash_signal);
1693 signal (SIGFPE, crash_signal);
1696 /* Other host-specific signal setup. */
1697 (*host_hooks.extra_signals)();
1699 /* Initialize the garbage-collector, string pools and tree type hash
1703 line_table = ggc_alloc_line_maps ();
1704 linemap_init (line_table);
1705 line_table->reallocator = realloc_for_line_map;
1708 /* Initialize register usage now so switches may override. */
1711 /* Register the language-independent parameters. */
1712 add_params (lang_independent_params, LAST_PARAM);
1714 /* This must be done after add_params but before argument processing. */
1715 init_ggc_heuristics();
1716 init_optimization_passes ();
1717 statistics_early_init ();
1720 /* Return true if the current target supports -fsection-anchors. */
1723 target_supports_section_anchors_p (void)
1725 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1728 if (targetm.asm_out.output_anchor == NULL)
1734 /* Default the align_* variables to 1 if they're still unset, and
1735 set up the align_*_log variables. */
1737 init_alignments (void)
1739 if (align_loops <= 0)
1741 if (align_loops_max_skip > align_loops)
1742 align_loops_max_skip = align_loops - 1;
1743 align_loops_log = floor_log2 (align_loops * 2 - 1);
1744 if (align_jumps <= 0)
1746 if (align_jumps_max_skip > align_jumps)
1747 align_jumps_max_skip = align_jumps - 1;
1748 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1749 if (align_labels <= 0)
1751 align_labels_log = floor_log2 (align_labels * 2 - 1);
1752 if (align_labels_max_skip > align_labels)
1753 align_labels_max_skip = align_labels - 1;
1754 if (align_functions <= 0)
1755 align_functions = 1;
1756 align_functions_log = floor_log2 (align_functions * 2 - 1);
1759 /* Process the options that have been parsed. */
1761 process_options (void)
1763 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1764 This can happen with incorrect pre-processed input. */
1765 debug_hooks = &do_nothing_debug_hooks;
1767 /* This replaces set_Wunused. */
1768 if (warn_unused_function == -1)
1769 warn_unused_function = warn_unused;
1770 if (warn_unused_label == -1)
1771 warn_unused_label = warn_unused;
1772 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */
1773 if (warn_unused_parameter == -1)
1774 warn_unused_parameter = (warn_unused && extra_warnings);
1775 if (warn_unused_variable == -1)
1776 warn_unused_variable = warn_unused;
1777 /* Wunused-but-set-parameter is enabled if both -Wunused -Wextra are
1779 if (warn_unused_but_set_parameter == -1)
1780 warn_unused_but_set_parameter = (warn_unused && extra_warnings);
1781 if (warn_unused_but_set_variable == -1)
1782 warn_unused_but_set_variable = warn_unused;
1783 if (warn_unused_value == -1)
1784 warn_unused_value = warn_unused;
1786 /* This replaces set_Wextra. */
1787 if (warn_uninitialized == -1)
1788 warn_uninitialized = extra_warnings;
1790 /* Allow the front end to perform consistency checks and do further
1791 initialization based on the command line options. This hook also
1792 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1793 so we can correctly initialize debug output. */
1794 no_backend = lang_hooks.post_options (&main_input_filename);
1796 /* Some machines may reject certain combinations of options. */
1797 targetm.target_option.override ();
1799 /* Avoid any informative notes in the second run of -fcompare-debug. */
1800 if (flag_compare_debug)
1801 diagnostic_inhibit_notes (global_dc);
1803 if (flag_section_anchors && !target_supports_section_anchors_p ())
1805 warning (OPT_fsection_anchors,
1806 "this target does not support %qs", "-fsection-anchors");
1807 flag_section_anchors = 0;
1810 if (flag_short_enums == 2)
1811 flag_short_enums = targetm.default_short_enums ();
1813 /* Set aux_base_name if not already set. */
1816 else if (main_input_filename)
1818 char *name = xstrdup (lbasename (main_input_filename));
1820 strip_off_ending (name, strlen (name));
1821 aux_base_name = name;
1824 aux_base_name = "gccaux";
1829 || flag_loop_interchange
1830 || flag_loop_strip_mine
1831 || flag_graphite_identity
1832 || flag_loop_parallelize_all)
1833 sorry ("Graphite loop optimizations cannot be used");
1836 /* Unrolling all loops implies that standard loop unrolling must also
1838 if (flag_unroll_all_loops)
1839 flag_unroll_loops = 1;
1841 /* The loop unrolling code assumes that cse will be run after loop.
1842 web and rename-registers also help when run after loop unrolling. */
1843 if (flag_rerun_cse_after_loop == AUTODETECT_VALUE)
1844 flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops;
1846 if (flag_web == AUTODETECT_VALUE)
1847 flag_web = flag_unroll_loops || flag_peel_loops;
1849 if (flag_rename_registers == AUTODETECT_VALUE)
1850 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1852 if (flag_non_call_exceptions)
1853 flag_asynchronous_unwind_tables = 1;
1854 if (flag_asynchronous_unwind_tables)
1855 flag_unwind_tables = 1;
1857 if (flag_value_profile_transformations)
1858 flag_profile_values = 1;
1860 /* Warn about options that are not supported on this machine. */
1861 #ifndef INSN_SCHEDULING
1862 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1863 warning (0, "instruction scheduling not supported on this target machine");
1866 if (flag_delayed_branch)
1867 warning (0, "this target machine does not have delayed branches");
1870 user_label_prefix = USER_LABEL_PREFIX;
1871 if (flag_leading_underscore != -1)
1873 /* If the default prefix is more complicated than "" or "_",
1874 issue a warning and ignore this option. */
1875 if (user_label_prefix[0] == 0 ||
1876 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1878 user_label_prefix = flag_leading_underscore ? "_" : "";
1881 warning (0, "-f%sleading-underscore not supported on this target machine",
1882 flag_leading_underscore ? "" : "no-");
1885 /* If we are in verbose mode, write out the version and maybe all the
1886 option flags in use. */
1889 print_version (stderr, "");
1891 print_switch_values (print_to_stderr);
1894 if (flag_syntax_only)
1896 write_symbols = NO_DEBUG;
1902 if (debug_info_level == DINFO_LEVEL_NONE)
1904 debug_info_level = DINFO_LEVEL_NORMAL;
1906 if (write_symbols == NO_DEBUG)
1907 write_symbols = PREFERRED_DEBUGGING_TYPE;
1910 debug_info_level = DINFO_LEVEL_NONE;
1913 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1915 FILE *final_output = fopen (flag_dump_final_insns, "w");
1918 error ("could not open final insn dump file %qs: %m",
1919 flag_dump_final_insns);
1920 flag_dump_final_insns = NULL;
1922 else if (fclose (final_output))
1924 error ("could not close zeroed insn dump file %qs: %m",
1925 flag_dump_final_insns);
1926 flag_dump_final_insns = NULL;
1930 /* Unless over-ridden for the target, assume that all DWARF levels
1931 may be emitted, if DWARF2_DEBUG is selected. */
1932 if (dwarf_strict < 0)
1935 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1937 if (debug_info_level == DINFO_LEVEL_NONE)
1938 write_symbols = NO_DEBUG;
1940 if (write_symbols == NO_DEBUG)
1942 #if defined(DBX_DEBUGGING_INFO)
1943 else if (write_symbols == DBX_DEBUG)
1944 debug_hooks = &dbx_debug_hooks;
1946 #if defined(XCOFF_DEBUGGING_INFO)
1947 else if (write_symbols == XCOFF_DEBUG)
1948 debug_hooks = &xcoff_debug_hooks;
1950 #ifdef SDB_DEBUGGING_INFO
1951 else if (write_symbols == SDB_DEBUG)
1952 debug_hooks = &sdb_debug_hooks;
1954 #ifdef DWARF2_DEBUGGING_INFO
1955 else if (write_symbols == DWARF2_DEBUG)
1956 debug_hooks = &dwarf2_debug_hooks;
1958 #ifdef VMS_DEBUGGING_INFO
1959 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1960 debug_hooks = &vmsdbg_debug_hooks;
1963 error ("target system does not support the \"%s\" debug format",
1964 debug_type_names[write_symbols]);
1966 /* We know which debug output will be used so we can set flag_var_tracking
1967 and flag_var_tracking_uninit if the user has not specified them. */
1968 if (debug_info_level < DINFO_LEVEL_NORMAL
1969 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1971 if (flag_var_tracking == 1
1972 || flag_var_tracking_uninit == 1)
1974 if (debug_info_level < DINFO_LEVEL_NORMAL)
1975 warning (0, "variable tracking requested, but useless unless "
1976 "producing debug info");
1978 warning (0, "variable tracking requested, but not supported "
1979 "by this debug format");
1981 flag_var_tracking = 0;
1982 flag_var_tracking_uninit = 0;
1985 /* If the user specifically requested variable tracking with tagging
1986 uninitialized variables, we need to turn on variable tracking.
1987 (We already determined above that variable tracking is feasible.) */
1988 if (flag_var_tracking_uninit)
1989 flag_var_tracking = 1;
1991 if (flag_var_tracking == AUTODETECT_VALUE)
1992 flag_var_tracking = optimize >= 1;
1994 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
1995 flag_var_tracking_assignments = flag_var_tracking
1996 && !(flag_selective_scheduling || flag_selective_scheduling2);
1998 if (flag_var_tracking_assignments_toggle)
1999 flag_var_tracking_assignments = !flag_var_tracking_assignments;
2001 if (flag_var_tracking_assignments && !flag_var_tracking)
2002 flag_var_tracking = flag_var_tracking_assignments = -1;
2004 if (flag_var_tracking_assignments
2005 && (flag_selective_scheduling || flag_selective_scheduling2))
2006 warning (0, "var-tracking-assignments changes selective scheduling");
2008 if (flag_tree_cselim == AUTODETECT_VALUE)
2009 #ifdef HAVE_conditional_move
2010 flag_tree_cselim = 1;
2012 flag_tree_cselim = 0;
2015 /* If auxiliary info generation is desired, open the output file.
2016 This goes in the same directory as the source file--unlike
2017 all the other output files. */
2018 if (flag_gen_aux_info)
2020 aux_info_file = fopen (aux_info_file_name, "w");
2021 if (aux_info_file == 0)
2022 fatal_error ("can%'t open %s: %m", aux_info_file_name);
2025 if (! targetm.have_named_sections)
2027 if (flag_function_sections)
2029 warning (0, "-ffunction-sections not supported for this target");
2030 flag_function_sections = 0;
2032 if (flag_data_sections)
2034 warning (0, "-fdata-sections not supported for this target");
2035 flag_data_sections = 0;
2039 if (flag_function_sections && profile_flag)
2041 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
2042 flag_function_sections = 0;
2045 #ifndef HAVE_prefetch
2046 if (flag_prefetch_loop_arrays > 0)
2048 warning (0, "-fprefetch-loop-arrays not supported for this target");
2049 flag_prefetch_loop_arrays = 0;
2052 if (flag_prefetch_loop_arrays > 0 && !HAVE_prefetch)
2054 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
2055 flag_prefetch_loop_arrays = 0;
2059 /* This combination of options isn't handled for i386 targets and doesn't
2060 make much sense anyway, so don't allow it. */
2061 if (flag_prefetch_loop_arrays > 0 && optimize_size)
2063 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
2064 flag_prefetch_loop_arrays = 0;
2067 /* The presence of IEEE signaling NaNs, implies all math can trap. */
2068 if (flag_signaling_nans)
2069 flag_trapping_math = 1;
2071 /* We cannot reassociate if we want traps or signed zeros. */
2072 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
2074 warning (0, "-fassociative-math disabled; other options take precedence");
2075 flag_associative_math = 0;
2078 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
2079 if (flag_cx_limited_range)
2080 flag_complex_method = 0;
2082 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
2083 if (flag_cx_fortran_rules)
2084 flag_complex_method = 1;
2086 /* Targets must be able to place spill slots at lower addresses. If the
2087 target already uses a soft frame pointer, the transition is trivial. */
2088 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
2090 warning (0, "-fstack-protector not supported for this target");
2091 flag_stack_protect = 0;
2093 if (!flag_stack_protect)
2094 warn_stack_protect = 0;
2096 /* ??? Unwind info is not correct around the CFG unless either a frame
2097 pointer is present or A_O_A is set. Fixing this requires rewriting
2098 unwind info generation to be aware of the CFG and propagating states
2100 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
2101 && flag_omit_frame_pointer)
2103 warning (0, "unwind tables currently require a frame pointer "
2105 flag_omit_frame_pointer = 0;
2108 /* Save the current optimization options. */
2109 optimization_default_node = build_optimization_node ();
2110 optimization_current_node = optimization_default_node;
2113 /* This function can be called multiple times to reinitialize the compiler
2114 back end when register classes or instruction sets have changed,
2115 before each function. */
2117 backend_init_target (void)
2119 /* Initialize alignment variables. */
2122 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
2123 to initialize reg_raw_mode[]. */
2126 /* This invokes target hooks to set fixed_reg[] etc, which is
2130 /* This depends on stack_pointer_rtx. */
2131 init_fake_stack_mems ();
2133 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
2135 init_alias_target ();
2137 /* Depends on HARD_FRAME_POINTER_REGNUM. */
2140 /* The following initialization functions need to generate rtl, so
2141 provide a dummy function context for them. */
2142 init_dummy_function_start ();
2144 /* rtx_cost is mode-dependent, so cached values need to be recomputed
2145 on a mode change. */
2148 /* We may need to recompute regno_save_code[] and regno_restore_code[]
2149 after a mode change as well. */
2150 caller_save_initialized_p = false;
2152 expand_dummy_function_end ();
2155 /* Initialize the compiler back end. This function is called only once,
2156 when starting the compiler. */
2163 init_inline_once ();
2164 init_varasm_once ();
2165 save_register_info ();
2167 /* Initialize the target-specific back end pieces. */
2169 backend_init_target ();
2172 /* Initialize excess precision settings. */
2174 init_excess_precision (void)
2176 /* Adjust excess precision handling based on the target options. If
2177 the front end cannot handle it, flag_excess_precision_cmdline
2178 will already have been set accordingly in the post_options
2180 gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
2181 flag_excess_precision = flag_excess_precision_cmdline;
2182 if (flag_unsafe_math_optimizations)
2183 flag_excess_precision = EXCESS_PRECISION_FAST;
2184 if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
2186 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
2187 switch (flt_eval_method)
2191 /* Either the target acts unpredictably (-1) or has all the
2192 operations required not to have excess precision (0). */
2193 flag_excess_precision = EXCESS_PRECISION_FAST;
2197 /* In these cases, predictable excess precision makes
2201 /* Any other implementation-defined FLT_EVAL_METHOD values
2202 require the compiler to handle the associated excess
2203 precision rules in excess_precision_type. */
2209 /* Initialize things that are both lang-dependent and target-dependent.
2210 This function can be called more than once if target parameters change. */
2212 lang_dependent_init_target (void)
2214 /* This determines excess precision settings. */
2215 init_excess_precision ();
2217 /* This creates various _DECL nodes, so needs to be called after the
2218 front end is initialized. It also depends on the HAVE_xxx macros
2219 generated from the target machine description. */
2222 /* The following initialization functions need to generate rtl, so
2223 provide a dummy function context for them. */
2224 init_dummy_function_start ();
2226 /* Do the target-specific parts of expr initialization. */
2227 init_expr_target ();
2229 /* Although the actions of these functions are language-independent,
2230 they use optabs, so we cannot call them from backend_init. */
2234 expand_dummy_function_end ();
2237 /* Language-dependent initialization. Returns nonzero on success. */
2239 lang_dependent_init (const char *name)
2241 location_t save_loc = input_location;
2242 if (dump_base_name == 0)
2243 dump_base_name = name && name[0] ? name : "gccdump";
2245 /* Other front-end initialization. */
2246 input_location = BUILTINS_LOCATION;
2247 if (lang_hooks.init () == 0)
2249 input_location = save_loc;
2251 init_asm_output (name);
2253 /* If stack usage information is desired, open the output file. */
2254 if (flag_stack_usage)
2255 stack_usage_file = open_auxiliary_file ("su");
2257 /* This creates various _DECL nodes, so needs to be called after the
2258 front end is initialized. */
2261 /* Do the target-specific parts of the initialization. */
2262 lang_dependent_init_target ();
2264 /* If dbx symbol table desired, initialize writing it and output the
2265 predefined types. */
2266 timevar_push (TV_SYMOUT);
2268 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2269 if (dwarf2out_do_frame ())
2270 dwarf2out_frame_init ();
2273 /* Now we have the correct original filename, we can initialize
2275 (*debug_hooks->init) (name);
2277 timevar_pop (TV_SYMOUT);
2283 /* Reinitialize everything when target parameters, such as register usage,
2286 target_reinit (void)
2288 /* Reinitialize RTL backend. */
2289 backend_init_target ();
2291 /* Reinitialize lang-dependent parts. */
2292 lang_dependent_init_target ();
2296 dump_memory_report (bool final)
2298 ggc_print_statistics ();
2299 stringpool_statistics ();
2300 dump_tree_statistics ();
2301 dump_gimple_statistics ();
2302 dump_rtx_statistics ();
2303 dump_alloc_pool_statistics ();
2304 dump_bitmap_statistics ();
2305 dump_vec_loc_statistics ();
2306 dump_ggc_loc_statistics (final);
2307 dump_alias_stats (stderr);
2308 dump_pta_stats (stderr);
2311 /* Clean up: close opened files, etc. */
2316 /* Close the dump files. */
2317 if (flag_gen_aux_info)
2319 fclose (aux_info_file);
2321 unlink (aux_info_file_name);
2324 /* Close non-debugging input and output files. Take special care to note
2325 whether fclose returns an error, since the pages might still be on the
2326 buffer chain while the file is open. */
2330 if (ferror (asm_out_file) != 0)
2331 fatal_error ("error writing to %s: %m", asm_file_name);
2332 if (fclose (asm_out_file) != 0)
2333 fatal_error ("error closing %s: %m", asm_file_name);
2335 unlink_if_ordinary (asm_file_name);
2338 if (stack_usage_file)
2339 fclose (stack_usage_file);
2342 finish_optimization_passes ();
2347 dump_memory_report (true);
2349 /* Language-specific end of compilation actions. */
2350 lang_hooks.finish ();
2353 /* Initialize the compiler, and compile the input file. */
2357 /* Initialize timing first. The C front ends read the main file in
2358 the post_options hook, and C++ does file timings. */
2359 if (time_report || !quiet_flag || flag_detailed_statistics)
2361 timevar_start (TV_TOTAL);
2365 /* Don't do any more if an error has already occurred. */
2368 /* This must be run always, because it is needed to compute the FP
2369 predefined macros, such as __LDBL_MAX__, for targets using non
2370 default FP formats. */
2371 init_adjust_machine_modes ();
2373 /* Set up the back-end if requested. */
2377 /* Language-dependent initialization. Returns true on success. */
2378 if (lang_dependent_init (main_input_filename))
2384 /* Stop timing and print the times. */
2385 timevar_stop (TV_TOTAL);
2386 timevar_print (stderr);
2389 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2390 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2391 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2393 It is not safe to call this function more than once. */
2396 toplev_main (int argc, char **argv)
2398 expandargv (&argc, &argv);
2400 /* Initialization of GCC's environment, and diagnostics. */
2401 general_init (argv[0]);
2403 /* Parse the options and do minimal processing; basically just
2404 enough to default flags appropriately. */
2405 decode_options (argc, CONST_CAST2 (const char **, char **, argv),
2406 &save_decoded_options, &save_decoded_options_count);
2410 initialize_plugins ();
2413 print_version (stderr, "");
2416 print_plugins_help (stderr, "");
2418 /* Exit early if we can (e.g. -help). */
2419 if (!exit_after_options)
2422 if (warningcount || errorcount)
2423 print_ignored_options ();
2424 diagnostic_finish (global_dc);
2426 /* Invoke registered plugin callbacks if any. */
2427 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2429 finalize_plugins ();
2431 return (FATAL_EXIT_CODE);
2433 return (SUCCESS_EXIT_CODE);