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"
32 #ifdef HAVE_SYS_TIMES_H
33 # include <sys/times.h>
39 #include "realmpfr.h" /* For GMP/MPFR/MPC versions, in print_version. */
44 #include "insn-attr.h"
45 #include "insn-config.h"
46 #include "insn-flags.h"
47 #include "hard-reg-set.h"
54 #include "basic-block.h"
60 #include "diagnostic.h"
61 #include "tree-diagnostic.h"
62 #include "tree-pretty-print.h"
66 #include "dwarf2asm.h"
67 #include "integrate.h"
70 #include "langhooks.h"
71 #include "cfglayout.h"
73 #include "hosthooks.h"
76 #include "opts-diagnostic.h"
78 #include "value-prof.h"
79 #include "alloc-pool.h"
80 #include "tree-mudflap.h"
81 #include "tree-pass.h"
83 #include "tree-ssa-alias.h"
86 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
87 #include "dwarf2out.h"
90 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
94 #ifdef SDB_DEBUGGING_INFO
98 #ifdef XCOFF_DEBUGGING_INFO
99 #include "xcoffout.h" /* Needed for external data
100 declarations for e.g. AIX 4.x. */
103 static void general_init (const char *);
104 static void do_compile (void);
105 static void process_options (void);
106 static void backend_init (void);
107 static int lang_dependent_init (const char *);
108 static void init_asm_output (const char *);
109 static void finalize (void);
111 static void crash_signal (int) ATTRIBUTE_NORETURN;
112 static void compile_file (void);
114 /* True if we don't need a backend (e.g. preprocessing only). */
115 static bool no_backend;
117 /* Length of line when printing switch values. */
120 /* Decoded options, and number of such options. */
121 struct cl_decoded_option *save_decoded_options;
122 unsigned int save_decoded_options_count;
124 /* Name of top-level original source file (what was input to cpp).
125 This comes from the #-command at the beginning of the actual input.
126 If there isn't any there, then this is the cc1 input file name. */
128 const char *main_input_filename;
130 /* Pointer to base name in main_input_filename, with directories and a
131 single final extension removed, and the length of this base
133 const char *main_input_basename;
134 int main_input_baselength;
136 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
137 to optimize in process_options (). */
138 #define AUTODETECT_VALUE 2
140 /* Debug hooks - dependent upon command line options. */
142 const struct gcc_debug_hooks *debug_hooks;
144 /* True if this is the lto front end. This is used to disable
145 gimple generation and lowering passes that are normally run on the
146 output of a front end. These passes must be bypassed for lto since
147 they have already been done before the gimple was written. */
149 bool in_lto_p = false;
151 /* The FUNCTION_DECL for the function currently being compiled,
152 or 0 if between functions. */
153 tree current_function_decl;
155 /* Set to the FUNC_BEGIN label of the current function, or NULL
157 const char * current_function_func_begin_label;
159 /* A random sequence of characters, unless overridden by user. */
160 static const char *flag_random_seed;
162 /* A local time stamp derived from the time of compilation. It will be
163 zero if the system cannot provide a time. It will be -1u, if the
164 user has specified a particular random seed. */
169 /* Generate code for GNU or NeXT Objective-C runtime environment. */
171 #ifdef NEXT_OBJC_RUNTIME
172 int flag_next_runtime = 1;
174 int flag_next_runtime = 0;
177 /* Nonzero means make permerror produce warnings instead of errors. */
179 int flag_permissive = 0;
181 /* When non-NULL, indicates that whenever space is allocated on the
182 stack, the resulting stack pointer must not pass this
183 address---that is, for stacks that grow downward, the stack pointer
184 must always be greater than or equal to this address; for stacks
185 that grow upward, the stack pointer must be less than this address.
186 At present, the rtx may be either a REG or a SYMBOL_REF, although
187 the support provided depends on the backend. */
190 /* Type of stack check. */
191 enum stack_check_type flag_stack_check = NO_STACK_CHECK;
193 /* True if the user has tagged the function with the 'section'
196 bool user_defined_section_attribute = false;
198 struct target_flag_state default_target_flag_state;
199 #if SWITCHABLE_TARGET
200 struct target_flag_state *this_target_flag_state = &default_target_flag_state;
202 #define this_target_flag_state (&default_target_flag_state)
207 const char *const string;
211 lang_independent_options;
213 /* The user symbol prefix after having resolved same. */
214 const char *user_label_prefix;
216 static const param_info lang_independent_params[] = {
217 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
218 { OPTION, DEFAULT, MIN, MAX, HELP },
219 #include "params.def"
221 { NULL, 0, 0, 0, NULL }
224 /* Output files for assembler code (real compiler output)
225 and debugging dumps. */
229 FILE *stack_usage_file = NULL;
230 FILE *dump_file = NULL;
231 const char *dump_file_name;
233 /* The current working directory of a translation. It's generally the
234 directory from which compilation was initiated, but a preprocessed
235 file may specify the original directory in which it was
238 static const char *src_pwd;
240 /* Initialize src_pwd with the given string, and return true. If it
241 was already initialized, return false. As a special case, it may
242 be called with a NULL argument to test whether src_pwd has NOT been
246 set_src_pwd (const char *pwd)
250 if (strcmp (src_pwd, pwd) == 0)
256 src_pwd = xstrdup (pwd);
260 /* Return the directory from which the translation unit was initiated,
261 in case set_src_pwd() was not called before to assign it a
277 /* Called when the start of a function definition is parsed,
278 this function prints on stderr the name of the function. */
280 announce_function (tree decl)
284 if (rtl_dump_and_exit)
285 fprintf (stderr, "%s ",
286 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
288 fprintf (stderr, " %s",
289 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
291 pp_needs_newline (global_dc->printer) = true;
292 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
296 /* Initialize local_tick with the time of day, or -1 if
297 flag_random_seed is set. */
300 init_local_tick (void)
302 if (!flag_random_seed)
304 /* Get some more or less random data. */
305 #ifdef HAVE_GETTIMEOFDAY
309 gettimeofday (&tv, NULL);
310 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
314 time_t now = time (NULL);
316 if (now != (time_t)-1)
317 local_tick = (unsigned) now;
325 /* Set up a default flag_random_seed and local_tick, unless the user
326 already specified one. Must be called after init_local_tick. */
329 init_random_seed (void)
331 unsigned HOST_WIDE_INT value;
332 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
334 value = local_tick ^ getpid ();
336 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
337 flag_random_seed = random_seed;
340 /* Obtain the random_seed string. Unless NOINIT, initialize it if
341 it's not provided in the command line. */
344 get_random_seed (bool noinit)
346 if (!flag_random_seed && !noinit)
348 return flag_random_seed;
351 /* Modify the random_seed string to VAL. Return its previous
355 set_random_seed (const char *val)
357 const char *old = flag_random_seed;
358 flag_random_seed = val;
362 #if GCC_VERSION < 3004
364 /* The functions clz_hwi, ctz_hwi, ffs_hwi, floor_log2 and exact_log2
365 are defined as inline functions in toplev.h if GCC_VERSION >= 3004.
366 The definitions here are used for older versions of gcc. */
368 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
369 If X is 0, return -1. */
372 floor_log2 (unsigned HOST_WIDE_INT x)
379 if (HOST_BITS_PER_WIDE_INT > 64)
380 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
382 if (HOST_BITS_PER_WIDE_INT > 32)
383 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
385 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
387 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
389 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
391 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
393 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
399 /* Return the logarithm of X, base 2, considering X unsigned,
400 if X is a power of 2. Otherwise, returns -1. */
403 exact_log2 (unsigned HOST_WIDE_INT x)
407 return floor_log2 (x);
410 /* Given X, an unsigned number, return the number of least significant bits
411 that are zero. When X == 0, the result is the word size. */
414 ctz_hwi (unsigned HOST_WIDE_INT x)
416 return x ? floor_log2 (x & -x) : HOST_BITS_PER_WIDE_INT;
419 /* Similarly for most significant bits. */
422 clz_hwi (unsigned HOST_WIDE_INT x)
424 return HOST_BITS_PER_WIDE_INT - 1 - floor_log2(x);
427 /* Similar to ctz_hwi, except that the least significant bit is numbered
428 starting from 1, and X == 0 yields 0. */
431 ffs_hwi (unsigned HOST_WIDE_INT x)
433 return 1 + floor_log2 (x & -x);
436 #endif /* GCC_VERSION < 3004 */
438 /* Handler for fatal signals, such as SIGSEGV. These are transformed
439 into ICE messages, which is much more user friendly. In case the
440 error printer crashes, reset the signal to prevent infinite recursion. */
443 crash_signal (int signo)
445 signal (signo, SIG_DFL);
447 /* If we crashed while processing an ASM statement, then be a little more
448 graceful. It's most likely the user's fault. */
449 if (this_is_asm_operands)
451 output_operand_lossage ("unrecoverable error");
452 exit (FATAL_EXIT_CODE);
455 internal_error ("%s", strsignal (signo));
458 /* Output a quoted string. */
461 output_quoted_string (FILE *asm_file, const char *string)
463 #ifdef OUTPUT_QUOTED_STRING
464 OUTPUT_QUOTED_STRING (asm_file, string);
468 putc ('\"', asm_file);
469 while ((c = *string++) != 0)
473 if (c == '\"' || c == '\\')
474 putc ('\\', asm_file);
478 fprintf (asm_file, "\\%03o", (unsigned char) c);
480 putc ('\"', asm_file);
484 /* A subroutine of wrapup_global_declarations. We've come to the end of
485 the compilation unit. All deferred variables should be undeferred,
486 and all incomplete decls should be finalized. */
489 wrapup_global_declaration_1 (tree decl)
491 /* We're not deferring this any longer. Assignment is conditional to
492 avoid needlessly dirtying PCH pages. */
493 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
494 && DECL_DEFER_OUTPUT (decl) != 0)
495 DECL_DEFER_OUTPUT (decl) = 0;
497 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
498 lang_hooks.finish_incomplete_decl (decl);
501 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
502 needs to be output. Return true if it is output. */
505 wrapup_global_declaration_2 (tree decl)
507 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
510 /* Don't write out static consts, unless we still need them.
512 We also keep static consts if not optimizing (for debugging),
513 unless the user specified -fno-keep-static-consts.
514 ??? They might be better written into the debug information.
515 This is possible when using DWARF.
517 A language processor that wants static constants to be always
518 written out (even if it is not used) is responsible for
519 calling rest_of_decl_compilation itself. E.g. the C front-end
520 calls rest_of_decl_compilation from finish_decl.
521 One motivation for this is that is conventional in some
522 environments to write things like:
523 static const char rcsid[] = "... version string ...";
524 intending to force the string to be in the executable.
526 A language processor that would prefer to have unneeded
527 static constants "optimized away" would just defer writing
528 them out until here. E.g. C++ does this, because static
529 constants are often defined in header files.
531 ??? A tempting alternative (for both C and C++) would be
532 to force a constant to be written if and only if it is
533 defined in a main file, as opposed to an include file. */
535 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
537 struct varpool_node *node;
539 node = varpool_get_node (decl);
541 if (!node && flag_ltrans)
543 else if (node && node->finalized)
545 else if (node && node->alias)
547 else if (!cgraph_global_info_ready
549 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
551 else if (node && node->needed)
553 else if (DECL_COMDAT (decl))
555 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
556 && (optimize || !flag_keep_static_consts
557 || DECL_ARTIFICIAL (decl)))
562 rest_of_decl_compilation (decl, 1, 1);
570 /* Do any final processing required for the declarations in VEC, of
571 which there are LEN. We write out inline functions and variables
572 that have been deferred until this point, but which are required.
573 Returns nonzero if anything was put out. */
576 wrapup_global_declarations (tree *vec, int len)
578 bool reconsider, output_something = false;
581 for (i = 0; i < len; i++)
582 wrapup_global_declaration_1 (vec[i]);
584 /* Now emit any global variables or functions that we have been
585 putting off. We need to loop in case one of the things emitted
586 here references another one which comes earlier in the list. */
590 for (i = 0; i < len; i++)
591 reconsider |= wrapup_global_declaration_2 (vec[i]);
593 output_something = true;
597 return output_something;
600 /* A subroutine of check_global_declarations. Issue appropriate warnings
601 for the global declaration DECL. */
604 check_global_declaration_1 (tree decl)
606 /* Warn about any function declared static but not defined. We don't
607 warn about variables, because many programs have static variables
608 that exist only to get some text into the object file. */
609 if (TREE_CODE (decl) == FUNCTION_DECL
610 && DECL_INITIAL (decl) == 0
611 && DECL_EXTERNAL (decl)
612 && ! DECL_ARTIFICIAL (decl)
613 && ! TREE_NO_WARNING (decl)
614 && ! TREE_PUBLIC (decl)
615 && (warn_unused_function
616 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
618 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
619 pedwarn (input_location, 0, "%q+F used but never defined", decl);
621 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
622 /* This symbol is effectively an "extern" declaration now. */
623 TREE_PUBLIC (decl) = 1;
624 assemble_external (decl);
627 /* Warn about static fns or vars defined but not used. */
628 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
629 /* We don't warn about "static const" variables because the
630 "rcs_id" idiom uses that construction. */
631 || (warn_unused_variable
632 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
633 && ! DECL_IN_SYSTEM_HEADER (decl)
634 && ! TREE_USED (decl)
635 /* The TREE_USED bit for file-scope decls is kept in the identifier,
636 to handle multiple external decls in different scopes. */
637 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
638 && ! DECL_EXTERNAL (decl)
639 && ! TREE_PUBLIC (decl)
640 /* A volatile variable might be used in some non-obvious way. */
641 && ! TREE_THIS_VOLATILE (decl)
642 /* Global register variables must be declared to reserve them. */
643 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
644 /* Otherwise, ask the language. */
645 && lang_hooks.decls.warn_unused_global (decl))
646 warning ((TREE_CODE (decl) == FUNCTION_DECL)
647 ? OPT_Wunused_function
648 : OPT_Wunused_variable,
649 "%q+D defined but not used", decl);
652 /* Issue appropriate warnings for the global declarations in VEC (of
653 which there are LEN). */
656 check_global_declarations (tree *vec, int len)
660 for (i = 0; i < len; i++)
661 check_global_declaration_1 (vec[i]);
664 /* Emit debugging information for all global declarations in VEC. */
667 emit_debug_global_declarations (tree *vec, int len)
671 /* Avoid confusing the debug information machinery when there are errors. */
675 timevar_push (TV_SYMOUT);
676 for (i = 0; i < len; i++)
677 debug_hooks->global_decl (vec[i]);
678 timevar_pop (TV_SYMOUT);
681 /* Warn about a use of an identifier which was marked deprecated. */
683 warn_deprecated_use (tree node, tree attr)
687 if (node == 0 || !warn_deprecated_decl)
693 attr = DECL_ATTRIBUTES (node);
694 else if (TYPE_P (node))
696 tree decl = TYPE_STUB_DECL (node);
698 attr = lookup_attribute ("deprecated",
699 TYPE_ATTRIBUTES (TREE_TYPE (decl)));
704 attr = lookup_attribute ("deprecated", attr);
707 msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
713 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
715 warning (OPT_Wdeprecated_declarations,
716 "%qD is deprecated (declared at %s:%d): %s",
717 node, xloc.file, xloc.line, msg);
719 warning (OPT_Wdeprecated_declarations,
720 "%qD is deprecated (declared at %s:%d)",
721 node, xloc.file, xloc.line);
723 else if (TYPE_P (node))
725 tree what = NULL_TREE;
726 tree decl = TYPE_STUB_DECL (node);
728 if (TYPE_NAME (node))
730 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
731 what = TYPE_NAME (node);
732 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
733 && DECL_NAME (TYPE_NAME (node)))
734 what = DECL_NAME (TYPE_NAME (node));
739 expanded_location xloc
740 = expand_location (DECL_SOURCE_LOCATION (decl));
744 warning (OPT_Wdeprecated_declarations,
745 "%qE is deprecated (declared at %s:%d): %s",
746 what, xloc.file, xloc.line, msg);
748 warning (OPT_Wdeprecated_declarations,
749 "%qE is deprecated (declared at %s:%d)", what,
750 xloc.file, xloc.line);
755 warning (OPT_Wdeprecated_declarations,
756 "type is deprecated (declared at %s:%d): %s",
757 xloc.file, xloc.line, msg);
759 warning (OPT_Wdeprecated_declarations,
760 "type is deprecated (declared at %s:%d)",
761 xloc.file, xloc.line);
769 warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s",
772 warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what);
777 warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
780 warning (OPT_Wdeprecated_declarations, "type is deprecated");
786 /* Compile an entire translation unit. Write a file of assembly
787 output and various debugging dumps. */
792 /* Initialize yet another pass. */
794 ggc_protect_identifiers = true;
797 init_final (main_input_filename);
798 coverage_init (aux_base_name);
800 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
802 timevar_push (TV_PARSE);
804 /* Call the parser, which parses the entire file (calling
805 rest_of_compilation for each function). */
806 lang_hooks.parse_file ();
808 /* Compilation is now finished except for writing
809 what's left of the symbol table output. */
810 timevar_pop (TV_PARSE);
812 if (flag_syntax_only || flag_wpa)
815 ggc_protect_identifiers = false;
817 /* This must also call cgraph_finalize_compilation_unit. */
818 lang_hooks.decls.final_write_globals ();
823 varpool_assemble_pending_decls ();
826 /* Likewise for mudflap static object registrations. */
828 mudflap_finish_file ();
830 output_shared_constant_pool ();
831 output_object_blocks ();
833 /* Write out any pending weak symbol declarations. */
836 /* This must be at the end before unwind and debug info.
837 Some target ports emit PIC setup thunks here. */
838 targetm.asm_out.code_end ();
840 /* Do dbx symbols. */
841 timevar_push (TV_SYMOUT);
843 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
844 if (dwarf2out_do_frame ())
845 dwarf2out_frame_finish ();
848 (*debug_hooks->finish) (main_input_filename);
849 timevar_pop (TV_SYMOUT);
851 /* Output some stuff at end of file if nec. */
853 dw2_output_indirect_constants ();
855 /* Flush any pending external directives. */
856 process_pending_assemble_externals ();
858 /* Emit LTO marker if LTO info has been previously emitted. This is
859 used by collect2 to determine whether an object file contains IL.
860 We used to emit an undefined reference here, but this produces
861 link errors if an object file with IL is stored into a shared
862 library without invoking lto1. */
863 if (flag_generate_lto)
865 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
866 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
868 (unsigned HOST_WIDE_INT) 1, 8);
869 #elif defined ASM_OUTPUT_ALIGNED_COMMON
870 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1",
871 (unsigned HOST_WIDE_INT) 1, 8);
873 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1",
874 (unsigned HOST_WIDE_INT) 1,
875 (unsigned HOST_WIDE_INT) 1);
879 /* Attach a special .ident directive to the end of the file to identify
880 the version of GCC which compiled this code. The format of the .ident
881 string is patterned after the ones produced by native SVR4 compilers. */
885 const char *pkg_version = "(GNU) ";
887 if (strcmp ("(GCC) ", pkgversion_string))
888 pkg_version = pkgversion_string;
889 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
890 IDENT_ASM_OP, pkg_version, version_string);
894 /* Invoke registered plugin callbacks. */
895 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
897 /* This must be at the end. Some target ports emit end of file directives
898 into the assembly file here, and hence we can not output anything to the
899 assembly file after this point. */
900 targetm.asm_out.file_end ();
903 /* Indexed by enum debug_info_type. */
904 const char *const debug_type_names[] =
906 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
909 /* Print version information to FILE.
910 Each line begins with INDENT (for the case where FILE is the
911 assembler output file). */
914 print_version (FILE *file, const char *indent)
916 static const char fmt1[] =
918 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
920 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
923 static const char fmt2[] =
924 N_("GMP version %s, MPFR version %s, MPC version %s\n");
925 static const char fmt3[] =
926 N_("%s%swarning: %s header version %s differs from library version %s.\n");
927 static const char fmt4[] =
928 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
930 #define __VERSION__ "[?]"
933 file == stderr ? _(fmt1) : fmt1,
934 indent, *indent != 0 ? " " : "",
935 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
936 indent, __VERSION__);
938 /* We need to stringify the GMP macro values. Ugh, gmp_version has
939 two string formats, "i.j.k" and "i.j" when k is zero. As of
940 gmp-4.3.0, GMP always uses the 3 number format. */
941 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
942 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
943 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
944 #define GCC_GMP_VERSION \
945 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
946 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
947 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
948 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
950 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
951 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
952 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
955 file == stderr ? _(fmt2) : fmt2,
956 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING);
957 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
959 file == stderr ? _(fmt3) : fmt3,
960 indent, *indent != 0 ? " " : "",
961 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
962 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
964 file == stderr ? _(fmt3) : fmt3,
965 indent, *indent != 0 ? " " : "",
966 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
967 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
969 file == stderr ? _(fmt3) : fmt3,
970 indent, *indent != 0 ? " " : "",
971 "MPC", MPC_VERSION_STRING, mpc_get_version ());
973 file == stderr ? _(fmt4) : fmt4,
974 indent, *indent != 0 ? " " : "",
975 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
977 print_plugins_versions (file, indent);
980 #ifdef ASM_COMMENT_START
982 print_to_asm_out_file (print_switch_type type, const char * text)
984 bool prepend_sep = true;
988 case SWITCH_TYPE_LINE_END:
989 putc ('\n', asm_out_file);
992 case SWITCH_TYPE_LINE_START:
993 fputs (ASM_COMMENT_START, asm_out_file);
994 return strlen (ASM_COMMENT_START);
996 case SWITCH_TYPE_DESCRIPTIVE:
997 if (ASM_COMMENT_START[0] == 0)
1000 case SWITCH_TYPE_PASSED:
1001 case SWITCH_TYPE_ENABLED:
1003 fputc (' ', asm_out_file);
1004 fputs (text, asm_out_file);
1005 /* No need to return the length here as
1006 print_single_switch has already done it. */
1016 print_to_stderr (print_switch_type type, const char * text)
1020 case SWITCH_TYPE_LINE_END:
1021 putc ('\n', stderr);
1024 case SWITCH_TYPE_LINE_START:
1027 case SWITCH_TYPE_PASSED:
1028 case SWITCH_TYPE_ENABLED:
1029 fputc (' ', stderr);
1032 case SWITCH_TYPE_DESCRIPTIVE:
1033 fputs (text, stderr);
1034 /* No need to return the length here as
1035 print_single_switch has already done it. */
1043 /* Print an option value and return the adjusted position in the line.
1044 ??? print_fn doesn't handle errors, eg disk full; presumably other
1045 code will catch a disk full though. */
1048 print_single_switch (print_switch_fn_type print_fn,
1050 print_switch_type type,
1053 /* The ultrix fprintf returns 0 on success, so compute the result
1054 we want here since we need it for the following test. The +1
1055 is for the separator character that will probably be emitted. */
1056 int len = strlen (text) + 1;
1059 && pos + len > MAX_LINE)
1061 print_fn (SWITCH_TYPE_LINE_END, NULL);
1066 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1068 print_fn (type, text);
1072 /* Print active target switches using PRINT_FN.
1073 POS is the current cursor position and MAX is the size of a "line".
1074 Each line begins with INDENT and ends with TERM.
1075 Each switch is separated from the next by SEP. */
1078 print_switch_values (print_switch_fn_type print_fn)
1083 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1084 that it can be printed below. This helps reproducibility. */
1085 if (!flag_random_seed)
1086 init_random_seed ();
1088 /* Print the options as passed. */
1089 pos = print_single_switch (print_fn, pos,
1090 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1092 for (j = 1; j < save_decoded_options_count; j++)
1094 switch (save_decoded_options[j].opt_index)
1107 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED,
1108 save_decoded_options[j].orig_option_with_args_text);
1112 print_fn (SWITCH_TYPE_LINE_END, NULL);
1114 /* Print the -f and -m options that have been enabled.
1115 We don't handle language specific options but printing argv
1117 pos = print_single_switch (print_fn, 0,
1118 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1120 for (j = 0; j < cl_options_count; j++)
1121 if ((cl_options[j].flags & CL_REPORT)
1122 && option_enabled (j, &global_options) > 0)
1123 pos = print_single_switch (print_fn, pos,
1124 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1126 print_fn (SWITCH_TYPE_LINE_END, NULL);
1129 /* Open assembly code output file. Do this even if -fsyntax-only is
1130 on, because then the driver will have provided the name of a
1131 temporary file or bit bucket for us. NAME is the file specified on
1132 the command line, possibly NULL. */
1134 init_asm_output (const char *name)
1136 if (name == NULL && asm_file_name == 0)
1137 asm_out_file = stdout;
1140 if (asm_file_name == 0)
1142 int len = strlen (dump_base_name);
1143 char *dumpname = XNEWVEC (char, len + 6);
1145 memcpy (dumpname, dump_base_name, len + 1);
1146 strip_off_ending (dumpname, len);
1147 strcat (dumpname, ".s");
1148 asm_file_name = dumpname;
1150 if (!strcmp (asm_file_name, "-"))
1151 asm_out_file = stdout;
1153 asm_out_file = fopen (asm_file_name, "w+b");
1154 if (asm_out_file == 0)
1155 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1158 if (!flag_syntax_only)
1160 targetm.asm_out.file_start ();
1162 if (flag_record_gcc_switches)
1164 if (targetm.asm_out.record_gcc_switches)
1166 /* Let the target know that we are about to start recording. */
1167 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1169 /* Now record the switches. */
1170 print_switch_values (targetm.asm_out.record_gcc_switches);
1171 /* Let the target know that the recording is over. */
1172 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1176 inform (input_location, "-frecord-gcc-switches is not supported by the current target");
1179 #ifdef ASM_COMMENT_START
1180 if (flag_verbose_asm)
1182 /* Print the list of switches in effect
1183 into the assembler file as comments. */
1184 print_version (asm_out_file, ASM_COMMENT_START);
1185 print_switch_values (print_to_asm_out_file);
1186 putc ('\n', asm_out_file);
1192 /* Return true if the state of option OPTION should be stored in PCH files
1193 and checked by default_pch_valid_p. Store the option's current state
1197 option_affects_pch_p (int option, struct cl_option_state *state)
1199 if ((cl_options[option].flags & CL_TARGET) == 0)
1201 if (option_flag_var (option, &global_options) == &target_flags)
1202 if (targetm.check_pch_target_flags)
1204 return get_option_state (&global_options, option, state);
1207 /* Default version of get_pch_validity.
1208 By default, every flag difference is fatal; that will be mostly right for
1209 most targets, but completely right for very few. */
1212 default_get_pch_validity (size_t *sz)
1214 struct cl_option_state state;
1219 if (targetm.check_pch_target_flags)
1220 *sz += sizeof (target_flags);
1221 for (i = 0; i < cl_options_count; i++)
1222 if (option_affects_pch_p (i, &state))
1225 result = r = XNEWVEC (char, *sz);
1229 if (targetm.check_pch_target_flags)
1231 memcpy (r, &target_flags, sizeof (target_flags));
1232 r += sizeof (target_flags);
1235 for (i = 0; i < cl_options_count; i++)
1236 if (option_affects_pch_p (i, &state))
1238 memcpy (r, state.data, state.size);
1245 /* Return a message which says that a PCH file was created with a different
1246 setting of OPTION. */
1249 pch_option_mismatch (const char *option)
1253 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1255 return _("out of memory");
1259 /* Default version of pch_valid_p. */
1262 default_pch_valid_p (const void *data_p, size_t len)
1264 struct cl_option_state state;
1265 const char *data = (const char *)data_p;
1268 /* -fpic and -fpie also usually make a PCH invalid. */
1269 if (data[0] != flag_pic)
1270 return _("created and used with different settings of -fpic");
1271 if (data[1] != flag_pie)
1272 return _("created and used with different settings of -fpie");
1275 /* Check target_flags. */
1276 if (targetm.check_pch_target_flags)
1281 memcpy (&tf, data, sizeof (target_flags));
1282 data += sizeof (target_flags);
1283 len -= sizeof (target_flags);
1284 r = targetm.check_pch_target_flags (tf);
1289 for (i = 0; i < cl_options_count; i++)
1290 if (option_affects_pch_p (i, &state))
1292 if (memcmp (data, state.data, state.size) != 0)
1293 return pch_option_mismatch (cl_options[i].opt_text);
1301 /* Default tree printer. Handles declarations only. */
1303 default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
1304 int precision, bool wide, bool set_locus, bool hash)
1308 /* FUTURE: %+x should set the locus. */
1309 if (precision != 0 || wide || hash)
1315 t = va_arg (*text->args_ptr, tree);
1316 if (TREE_CODE (t) == IDENTIFIER_NODE)
1318 pp_identifier (pp, IDENTIFIER_POINTER (t));
1324 t = va_arg (*text->args_ptr, tree);
1325 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1326 t = DECL_DEBUG_EXPR (t);
1331 t = va_arg (*text->args_ptr, tree);
1335 percent_K_format (text);
1342 if (set_locus && text->locus)
1343 *text->locus = DECL_SOURCE_LOCATION (t);
1347 const char *n = DECL_NAME (t)
1348 ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2))
1353 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1358 /* A helper function; used as the reallocator function for cpp's line
1361 realloc_for_line_map (void *ptr, size_t len)
1363 return GGC_RESIZEVAR (void, ptr, len);
1366 /* A helper function: used as the allocator function for
1367 identifier_to_locale. */
1369 alloc_for_identifier_to_locale (size_t len)
1371 return ggc_alloc_atomic (len);
1374 /* Output stack usage information. */
1376 output_stack_usage (void)
1378 static bool warning_issued = false;
1379 enum stack_usage_kind_type { STATIC = 0, DYNAMIC, DYNAMIC_BOUNDED };
1380 const char *stack_usage_kind_str[] = {
1385 HOST_WIDE_INT stack_usage = current_function_static_stack_size;
1386 enum stack_usage_kind_type stack_usage_kind;
1387 expanded_location loc;
1388 const char *raw_id, *id;
1390 if (stack_usage < 0)
1392 if (!warning_issued)
1394 warning (0, "-fstack-usage not supported for this target");
1395 warning_issued = true;
1400 stack_usage_kind = STATIC;
1402 /* Add the maximum amount of space pushed onto the stack. */
1403 if (current_function_pushed_stack_size > 0)
1405 stack_usage += current_function_pushed_stack_size;
1406 stack_usage_kind = DYNAMIC_BOUNDED;
1409 /* Now on to the tricky part: dynamic stack allocation. */
1410 if (current_function_allocates_dynamic_stack_space)
1412 if (current_function_has_unbounded_dynamic_stack_size)
1413 stack_usage_kind = DYNAMIC;
1415 stack_usage_kind = DYNAMIC_BOUNDED;
1417 /* Add the size even in the unbounded case, this can't hurt. */
1418 stack_usage += current_function_dynamic_stack_size;
1421 loc = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
1423 /* Strip the scope prefix if any. */
1424 raw_id = lang_hooks.decl_printable_name (current_function_decl, 2);
1425 id = strrchr (raw_id, '.');
1431 fprintf (stack_usage_file,
1432 "%s:%d:%d:%s\t"HOST_WIDE_INT_PRINT_DEC"\t%s\n",
1433 lbasename (loc.file),
1438 stack_usage_kind_str[stack_usage_kind]);
1441 /* Open an auxiliary output file. */
1443 open_auxiliary_file (const char *ext)
1448 filename = concat (aux_base_name, ".", ext, NULL);
1449 file = fopen (filename, "w");
1451 fatal_error ("can%'t open %s for writing: %m", filename);
1456 /* Initialization of the front end environment, before command line
1457 options are parsed. Signal handlers, internationalization etc.
1458 ARGV0 is main's argv[0]. */
1460 general_init (const char *argv0)
1464 p = argv0 + strlen (argv0);
1465 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1469 xmalloc_set_program_name (progname);
1473 /* Unlock the stdio streams. */
1474 unlock_std_streams ();
1476 gcc_init_libintl ();
1478 identifier_to_locale_alloc = alloc_for_identifier_to_locale;
1479 identifier_to_locale_free = ggc_free;
1481 /* Initialize the diagnostics reporting machinery, so option parsing
1482 can give warnings and errors. */
1483 diagnostic_initialize (global_dc, N_OPTS);
1484 diagnostic_starter (global_dc) = default_tree_diagnostic_starter;
1485 /* Set a default printer. Language specific initializations will
1486 override it later. */
1487 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1488 global_dc->show_option_requested
1489 = global_options_init.x_flag_diagnostics_show_option;
1490 global_dc->show_column
1491 = global_options_init.x_flag_show_column;
1492 global_dc->internal_error = plugins_internal_error_function;
1493 global_dc->option_enabled = option_enabled;
1494 global_dc->option_state = &global_options;
1495 global_dc->option_name = option_name;
1497 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1499 signal (SIGSEGV, crash_signal);
1502 signal (SIGILL, crash_signal);
1505 signal (SIGBUS, crash_signal);
1508 signal (SIGABRT, crash_signal);
1510 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1511 signal (SIGIOT, crash_signal);
1514 signal (SIGFPE, crash_signal);
1517 /* Other host-specific signal setup. */
1518 (*host_hooks.extra_signals)();
1520 /* Initialize the garbage-collector, string pools and tree type hash
1524 line_table = ggc_alloc_line_maps ();
1525 linemap_init (line_table);
1526 line_table->reallocator = realloc_for_line_map;
1529 /* Initialize register usage now so switches may override. */
1532 /* Register the language-independent parameters. */
1533 add_params (lang_independent_params, LAST_PARAM);
1534 targetm.target_option.default_params ();
1536 /* This must be done after add_params but before argument processing. */
1537 init_ggc_heuristics();
1538 init_optimization_passes ();
1539 statistics_early_init ();
1543 /* Return true if the current target supports -fsection-anchors. */
1546 target_supports_section_anchors_p (void)
1548 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1551 if (targetm.asm_out.output_anchor == NULL)
1557 /* Default the align_* variables to 1 if they're still unset, and
1558 set up the align_*_log variables. */
1560 init_alignments (void)
1562 if (align_loops <= 0)
1564 if (align_loops_max_skip > align_loops)
1565 align_loops_max_skip = align_loops - 1;
1566 align_loops_log = floor_log2 (align_loops * 2 - 1);
1567 if (align_jumps <= 0)
1569 if (align_jumps_max_skip > align_jumps)
1570 align_jumps_max_skip = align_jumps - 1;
1571 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1572 if (align_labels <= 0)
1574 align_labels_log = floor_log2 (align_labels * 2 - 1);
1575 if (align_labels_max_skip > align_labels)
1576 align_labels_max_skip = align_labels - 1;
1577 if (align_functions <= 0)
1578 align_functions = 1;
1579 align_functions_log = floor_log2 (align_functions * 2 - 1);
1582 /* Process the options that have been parsed. */
1584 process_options (void)
1586 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1587 This can happen with incorrect pre-processed input. */
1588 debug_hooks = &do_nothing_debug_hooks;
1590 maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
1592 /* This replaces set_Wunused. */
1593 if (warn_unused_function == -1)
1594 warn_unused_function = warn_unused;
1595 if (warn_unused_label == -1)
1596 warn_unused_label = warn_unused;
1597 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */
1598 if (warn_unused_parameter == -1)
1599 warn_unused_parameter = (warn_unused && extra_warnings);
1600 if (warn_unused_variable == -1)
1601 warn_unused_variable = warn_unused;
1602 /* Wunused-but-set-parameter is enabled if both -Wunused -Wextra are
1604 if (warn_unused_but_set_parameter == -1)
1605 warn_unused_but_set_parameter = (warn_unused && extra_warnings);
1606 if (warn_unused_but_set_variable == -1)
1607 warn_unused_but_set_variable = warn_unused;
1608 if (warn_unused_value == -1)
1609 warn_unused_value = warn_unused;
1611 /* This replaces set_Wextra. */
1612 if (warn_uninitialized == -1)
1613 warn_uninitialized = extra_warnings;
1615 /* Allow the front end to perform consistency checks and do further
1616 initialization based on the command line options. This hook also
1617 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1618 so we can correctly initialize debug output. */
1619 no_backend = lang_hooks.post_options (&main_input_filename);
1621 /* Some machines may reject certain combinations of options. */
1622 targetm.target_option.override ();
1624 /* Avoid any informative notes in the second run of -fcompare-debug. */
1625 if (flag_compare_debug)
1626 diagnostic_inhibit_notes (global_dc);
1628 if (flag_section_anchors && !target_supports_section_anchors_p ())
1630 warning (OPT_fsection_anchors,
1631 "this target does not support %qs", "-fsection-anchors");
1632 flag_section_anchors = 0;
1635 if (flag_short_enums == 2)
1636 flag_short_enums = targetm.default_short_enums ();
1638 /* Set aux_base_name if not already set. */
1641 else if (main_input_filename)
1643 char *name = xstrdup (lbasename (main_input_filename));
1645 strip_off_ending (name, strlen (name));
1646 aux_base_name = name;
1649 aux_base_name = "gccaux";
1654 || flag_loop_interchange
1655 || flag_loop_strip_mine
1656 || flag_graphite_identity
1657 || flag_loop_parallelize_all)
1658 sorry ("Graphite loop optimizations cannot be used");
1661 /* Unrolling all loops implies that standard loop unrolling must also
1663 if (flag_unroll_all_loops)
1664 flag_unroll_loops = 1;
1666 /* web and rename-registers help when run after loop unrolling. */
1667 if (flag_web == AUTODETECT_VALUE)
1668 flag_web = flag_unroll_loops || flag_peel_loops;
1670 if (flag_rename_registers == AUTODETECT_VALUE)
1671 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1673 if (flag_non_call_exceptions)
1674 flag_asynchronous_unwind_tables = 1;
1675 if (flag_asynchronous_unwind_tables)
1676 flag_unwind_tables = 1;
1678 if (flag_value_profile_transformations)
1679 flag_profile_values = 1;
1681 /* Warn about options that are not supported on this machine. */
1682 #ifndef INSN_SCHEDULING
1683 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1684 warning (0, "instruction scheduling not supported on this target machine");
1687 if (flag_delayed_branch)
1688 warning (0, "this target machine does not have delayed branches");
1691 user_label_prefix = USER_LABEL_PREFIX;
1692 if (flag_leading_underscore != -1)
1694 /* If the default prefix is more complicated than "" or "_",
1695 issue a warning and ignore this option. */
1696 if (user_label_prefix[0] == 0 ||
1697 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1699 user_label_prefix = flag_leading_underscore ? "_" : "";
1702 warning (0, "-f%sleading-underscore not supported on this target machine",
1703 flag_leading_underscore ? "" : "no-");
1706 /* If we are in verbose mode, write out the version and maybe all the
1707 option flags in use. */
1710 print_version (stderr, "");
1712 print_switch_values (print_to_stderr);
1715 if (flag_syntax_only)
1717 write_symbols = NO_DEBUG;
1723 if (debug_info_level == DINFO_LEVEL_NONE)
1725 debug_info_level = DINFO_LEVEL_NORMAL;
1727 if (write_symbols == NO_DEBUG)
1728 write_symbols = PREFERRED_DEBUGGING_TYPE;
1731 debug_info_level = DINFO_LEVEL_NONE;
1734 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1736 FILE *final_output = fopen (flag_dump_final_insns, "w");
1739 error ("could not open final insn dump file %qs: %m",
1740 flag_dump_final_insns);
1741 flag_dump_final_insns = NULL;
1743 else if (fclose (final_output))
1745 error ("could not close zeroed insn dump file %qs: %m",
1746 flag_dump_final_insns);
1747 flag_dump_final_insns = NULL;
1751 /* Unless over-ridden for the target, assume that all DWARF levels
1752 may be emitted, if DWARF2_DEBUG is selected. */
1753 if (dwarf_strict < 0)
1756 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1758 if (debug_info_level == DINFO_LEVEL_NONE)
1759 write_symbols = NO_DEBUG;
1761 if (write_symbols == NO_DEBUG)
1763 #if defined(DBX_DEBUGGING_INFO)
1764 else if (write_symbols == DBX_DEBUG)
1765 debug_hooks = &dbx_debug_hooks;
1767 #if defined(XCOFF_DEBUGGING_INFO)
1768 else if (write_symbols == XCOFF_DEBUG)
1769 debug_hooks = &xcoff_debug_hooks;
1771 #ifdef SDB_DEBUGGING_INFO
1772 else if (write_symbols == SDB_DEBUG)
1773 debug_hooks = &sdb_debug_hooks;
1775 #ifdef DWARF2_DEBUGGING_INFO
1776 else if (write_symbols == DWARF2_DEBUG)
1777 debug_hooks = &dwarf2_debug_hooks;
1779 #ifdef VMS_DEBUGGING_INFO
1780 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1781 debug_hooks = &vmsdbg_debug_hooks;
1784 error ("target system does not support the \"%s\" debug format",
1785 debug_type_names[write_symbols]);
1787 /* We know which debug output will be used so we can set flag_var_tracking
1788 and flag_var_tracking_uninit if the user has not specified them. */
1789 if (debug_info_level < DINFO_LEVEL_NORMAL
1790 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1792 if (flag_var_tracking == 1
1793 || flag_var_tracking_uninit == 1)
1795 if (debug_info_level < DINFO_LEVEL_NORMAL)
1796 warning (0, "variable tracking requested, but useless unless "
1797 "producing debug info");
1799 warning (0, "variable tracking requested, but not supported "
1800 "by this debug format");
1802 flag_var_tracking = 0;
1803 flag_var_tracking_uninit = 0;
1806 /* The debug hooks are used to implement -fdump-go-spec because it
1807 gives a simple and stable API for all the information we need to
1809 if (flag_dump_go_spec != NULL)
1810 debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
1812 /* If the user specifically requested variable tracking with tagging
1813 uninitialized variables, we need to turn on variable tracking.
1814 (We already determined above that variable tracking is feasible.) */
1815 if (flag_var_tracking_uninit)
1816 flag_var_tracking = 1;
1818 if (flag_var_tracking == AUTODETECT_VALUE)
1819 flag_var_tracking = optimize >= 1;
1821 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
1822 flag_var_tracking_assignments = flag_var_tracking
1823 && !(flag_selective_scheduling || flag_selective_scheduling2);
1825 if (flag_var_tracking_assignments_toggle)
1826 flag_var_tracking_assignments = !flag_var_tracking_assignments;
1828 if (flag_var_tracking_assignments && !flag_var_tracking)
1829 flag_var_tracking = flag_var_tracking_assignments = -1;
1831 if (flag_var_tracking_assignments
1832 && (flag_selective_scheduling || flag_selective_scheduling2))
1833 warning (0, "var-tracking-assignments changes selective scheduling");
1835 if (flag_tree_cselim == AUTODETECT_VALUE)
1836 #ifdef HAVE_conditional_move
1837 flag_tree_cselim = 1;
1839 flag_tree_cselim = 0;
1842 /* If auxiliary info generation is desired, open the output file.
1843 This goes in the same directory as the source file--unlike
1844 all the other output files. */
1845 if (flag_gen_aux_info)
1847 aux_info_file = fopen (aux_info_file_name, "w");
1848 if (aux_info_file == 0)
1849 fatal_error ("can%'t open %s: %m", aux_info_file_name);
1852 if (! targetm.have_named_sections)
1854 if (flag_function_sections)
1856 warning (0, "-ffunction-sections not supported for this target");
1857 flag_function_sections = 0;
1859 if (flag_data_sections)
1861 warning (0, "-fdata-sections not supported for this target");
1862 flag_data_sections = 0;
1866 if (flag_function_sections && profile_flag)
1868 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
1869 flag_function_sections = 0;
1872 #ifndef HAVE_prefetch
1873 if (flag_prefetch_loop_arrays > 0)
1875 warning (0, "-fprefetch-loop-arrays not supported for this target");
1876 flag_prefetch_loop_arrays = 0;
1879 if (flag_prefetch_loop_arrays > 0 && !HAVE_prefetch)
1881 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
1882 flag_prefetch_loop_arrays = 0;
1886 /* This combination of options isn't handled for i386 targets and doesn't
1887 make much sense anyway, so don't allow it. */
1888 if (flag_prefetch_loop_arrays > 0 && optimize_size)
1890 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
1891 flag_prefetch_loop_arrays = 0;
1894 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1895 if (flag_signaling_nans)
1896 flag_trapping_math = 1;
1898 /* We cannot reassociate if we want traps or signed zeros. */
1899 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1901 warning (0, "-fassociative-math disabled; other options take precedence");
1902 flag_associative_math = 0;
1905 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1906 if (flag_cx_limited_range)
1907 flag_complex_method = 0;
1909 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1910 if (flag_cx_fortran_rules)
1911 flag_complex_method = 1;
1913 /* Targets must be able to place spill slots at lower addresses. If the
1914 target already uses a soft frame pointer, the transition is trivial. */
1915 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1917 warning (0, "-fstack-protector not supported for this target");
1918 flag_stack_protect = 0;
1920 if (!flag_stack_protect)
1921 warn_stack_protect = 0;
1923 /* ??? Unwind info is not correct around the CFG unless either a frame
1924 pointer is present or A_O_A is set. Fixing this requires rewriting
1925 unwind info generation to be aware of the CFG and propagating states
1927 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
1928 && flag_omit_frame_pointer)
1930 warning (0, "unwind tables currently require a frame pointer "
1932 flag_omit_frame_pointer = 0;
1935 /* Save the current optimization options. */
1936 optimization_default_node = build_optimization_node ();
1937 optimization_current_node = optimization_default_node;
1940 /* This function can be called multiple times to reinitialize the compiler
1941 back end when register classes or instruction sets have changed,
1942 before each function. */
1944 backend_init_target (void)
1946 /* Initialize alignment variables. */
1949 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
1950 to initialize reg_raw_mode[]. */
1953 /* This invokes target hooks to set fixed_reg[] etc, which is
1957 /* This depends on stack_pointer_rtx. */
1958 init_fake_stack_mems ();
1960 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1962 init_alias_target ();
1964 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1967 /* The following initialization functions need to generate rtl, so
1968 provide a dummy function context for them. */
1969 init_dummy_function_start ();
1971 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1972 on a mode change. */
1975 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1976 after a mode change as well. */
1977 caller_save_initialized_p = false;
1979 expand_dummy_function_end ();
1982 /* Initialize the compiler back end. This function is called only once,
1983 when starting the compiler. */
1990 init_inline_once ();
1991 init_varasm_once ();
1992 save_register_info ();
1994 /* Initialize the target-specific back end pieces. */
1996 backend_init_target ();
1999 /* Initialize excess precision settings. */
2001 init_excess_precision (void)
2003 /* Adjust excess precision handling based on the target options. If
2004 the front end cannot handle it, flag_excess_precision_cmdline
2005 will already have been set accordingly in the post_options
2007 gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
2008 flag_excess_precision = flag_excess_precision_cmdline;
2009 if (flag_unsafe_math_optimizations)
2010 flag_excess_precision = EXCESS_PRECISION_FAST;
2011 if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
2013 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
2014 switch (flt_eval_method)
2018 /* Either the target acts unpredictably (-1) or has all the
2019 operations required not to have excess precision (0). */
2020 flag_excess_precision = EXCESS_PRECISION_FAST;
2024 /* In these cases, predictable excess precision makes
2028 /* Any other implementation-defined FLT_EVAL_METHOD values
2029 require the compiler to handle the associated excess
2030 precision rules in excess_precision_type. */
2036 /* Initialize things that are both lang-dependent and target-dependent.
2037 This function can be called more than once if target parameters change. */
2039 lang_dependent_init_target (void)
2041 /* This determines excess precision settings. */
2042 init_excess_precision ();
2044 /* This creates various _DECL nodes, so needs to be called after the
2045 front end is initialized. It also depends on the HAVE_xxx macros
2046 generated from the target machine description. */
2049 /* The following initialization functions need to generate rtl, so
2050 provide a dummy function context for them. */
2051 init_dummy_function_start ();
2053 /* Do the target-specific parts of expr initialization. */
2054 init_expr_target ();
2056 /* Although the actions of these functions are language-independent,
2057 they use optabs, so we cannot call them from backend_init. */
2061 expand_dummy_function_end ();
2064 /* Language-dependent initialization. Returns nonzero on success. */
2066 lang_dependent_init (const char *name)
2068 location_t save_loc = input_location;
2069 if (dump_base_name == 0)
2070 dump_base_name = name && name[0] ? name : "gccdump";
2072 /* Other front-end initialization. */
2073 input_location = BUILTINS_LOCATION;
2074 if (lang_hooks.init () == 0)
2076 input_location = save_loc;
2078 init_asm_output (name);
2080 /* If stack usage information is desired, open the output file. */
2081 if (flag_stack_usage)
2082 stack_usage_file = open_auxiliary_file ("su");
2084 /* This creates various _DECL nodes, so needs to be called after the
2085 front end is initialized. */
2088 /* Do the target-specific parts of the initialization. */
2089 lang_dependent_init_target ();
2091 /* If dbx symbol table desired, initialize writing it and output the
2092 predefined types. */
2093 timevar_push (TV_SYMOUT);
2095 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2096 if (dwarf2out_do_frame ())
2097 dwarf2out_frame_init ();
2100 /* Now we have the correct original filename, we can initialize
2102 (*debug_hooks->init) (name);
2104 timevar_pop (TV_SYMOUT);
2110 /* Reinitialize everything when target parameters, such as register usage,
2113 target_reinit (void)
2115 /* Reinitialize RTL backend. */
2116 backend_init_target ();
2118 /* Reinitialize lang-dependent parts. */
2119 lang_dependent_init_target ();
2123 dump_memory_report (bool final)
2125 ggc_print_statistics ();
2126 stringpool_statistics ();
2127 dump_tree_statistics ();
2128 dump_gimple_statistics ();
2129 dump_rtx_statistics ();
2130 dump_alloc_pool_statistics ();
2131 dump_bitmap_statistics ();
2132 dump_vec_loc_statistics ();
2133 dump_ggc_loc_statistics (final);
2134 dump_alias_stats (stderr);
2135 dump_pta_stats (stderr);
2138 /* Clean up: close opened files, etc. */
2143 /* Close the dump files. */
2144 if (flag_gen_aux_info)
2146 fclose (aux_info_file);
2148 unlink (aux_info_file_name);
2151 /* Close non-debugging input and output files. Take special care to note
2152 whether fclose returns an error, since the pages might still be on the
2153 buffer chain while the file is open. */
2157 if (ferror (asm_out_file) != 0)
2158 fatal_error ("error writing to %s: %m", asm_file_name);
2159 if (fclose (asm_out_file) != 0)
2160 fatal_error ("error closing %s: %m", asm_file_name);
2162 unlink_if_ordinary (asm_file_name);
2165 if (stack_usage_file)
2166 fclose (stack_usage_file);
2169 finish_optimization_passes ();
2174 dump_memory_report (true);
2176 /* Language-specific end of compilation actions. */
2177 lang_hooks.finish ();
2180 /* Initialize the compiler, and compile the input file. */
2184 /* Initialize timing first. The C front ends read the main file in
2185 the post_options hook, and C++ does file timings. */
2186 if (time_report || !quiet_flag || flag_detailed_statistics)
2188 timevar_start (TV_TOTAL);
2192 /* Don't do any more if an error has already occurred. */
2195 /* This must be run always, because it is needed to compute the FP
2196 predefined macros, such as __LDBL_MAX__, for targets using non
2197 default FP formats. */
2198 init_adjust_machine_modes ();
2200 /* Set up the back-end if requested. */
2204 /* Language-dependent initialization. Returns true on success. */
2205 if (lang_dependent_init (main_input_filename))
2211 /* Stop timing and print the times. */
2212 timevar_stop (TV_TOTAL);
2213 timevar_print (stderr);
2216 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2217 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2218 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2220 It is not safe to call this function more than once. */
2223 toplev_main (int argc, char **argv)
2225 expandargv (&argc, &argv);
2227 /* Initialization of GCC's environment, and diagnostics. */
2228 general_init (argv[0]);
2230 /* One-off initialization of options that does not need to be
2231 repeated when options are added for particular functions. */
2232 init_options_once ();
2234 /* Initialize global options structures; this must be repeated for
2235 each structure used for parsing options. */
2236 init_options_struct (&global_options, &global_options_set);
2237 lang_hooks.init_options_struct (&global_options);
2239 /* Convert the options to an array. */
2240 decode_cmdline_options_to_array_default_mask (argc,
2241 CONST_CAST2 (const char **,
2243 &save_decoded_options,
2244 &save_decoded_options_count);
2246 /* Perform language-specific options initialization. */
2247 lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
2249 /* Parse the options and do minimal processing; basically just
2250 enough to default flags appropriately. */
2251 decode_options (&global_options, &global_options_set,
2252 save_decoded_options, save_decoded_options_count,
2253 UNKNOWN_LOCATION, global_dc);
2255 handle_common_deferred_options ();
2259 initialize_plugins ();
2262 print_version (stderr, "");
2265 print_plugins_help (stderr, "");
2267 /* Exit early if we can (e.g. -help). */
2268 if (!exit_after_options)
2271 if (warningcount || errorcount)
2272 print_ignored_options ();
2273 diagnostic_finish (global_dc);
2275 /* Invoke registered plugin callbacks if any. */
2276 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2278 finalize_plugins ();
2280 return (FATAL_EXIT_CODE);
2282 return (SUCCESS_EXIT_CODE);