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 /* Other flags saying which kinds of debugging dump have been requested. */
146 int rtl_dump_and_exit;
147 int flag_print_asm_name;
148 enum graph_dump_types graph_dump_format;
150 /* True if this is the lto front end. This is used to disable
151 gimple generation and lowering passes that are normally run on the
152 output of a front end. These passes must be bypassed for lto since
153 they have already been done before the gimple was written. */
155 bool in_lto_p = false;
157 /* The FUNCTION_DECL for the function currently being compiled,
158 or 0 if between functions. */
159 tree current_function_decl;
161 /* Set to the FUNC_BEGIN label of the current function, or NULL
163 const char * current_function_func_begin_label;
165 /* A random sequence of characters, unless overridden by user. */
166 static const char *flag_random_seed;
168 /* A local time stamp derived from the time of compilation. It will be
169 zero if the system cannot provide a time. It will be -1u, if the
170 user has specified a particular random seed. */
175 /* Generate code for GNU or NeXT Objective-C runtime environment. */
177 #ifdef NEXT_OBJC_RUNTIME
178 int flag_next_runtime = 1;
180 int flag_next_runtime = 0;
183 /* Nonzero means make permerror produce warnings instead of errors. */
185 int flag_permissive = 0;
187 /* -dA causes debug commentary information to be produced in
188 the generated assembly code (to make it more readable). This option
189 is generally only of use to those who actually need to read the
190 generated assembly code (perhaps while debugging the compiler itself).
191 Currently, this switch is only used by dwarfout.c; however, it is intended
192 to be a catchall for printing debug information in the assembler file. */
194 int flag_debug_asm = 0;
196 /* -dP causes the rtl to be emitted as a comment in assembly. */
198 int flag_dump_rtl_in_asm = 0;
200 /* When non-NULL, indicates that whenever space is allocated on the
201 stack, the resulting stack pointer must not pass this
202 address---that is, for stacks that grow downward, the stack pointer
203 must always be greater than or equal to this address; for stacks
204 that grow upward, the stack pointer must be less than this address.
205 At present, the rtx may be either a REG or a SYMBOL_REF, although
206 the support provided depends on the backend. */
209 /* Type of stack check. */
210 enum stack_check_type flag_stack_check = NO_STACK_CHECK;
212 /* True if the user has tagged the function with the 'section'
215 bool user_defined_section_attribute = false;
217 struct target_flag_state default_target_flag_state;
218 #if SWITCHABLE_TARGET
219 struct target_flag_state *this_target_flag_state = &default_target_flag_state;
221 #define this_target_flag_state (&default_target_flag_state)
226 const char *const string;
230 lang_independent_options;
232 /* The user symbol prefix after having resolved same. */
233 const char *user_label_prefix;
235 static const param_info lang_independent_params[] = {
236 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
237 { OPTION, DEFAULT, MIN, MAX, HELP },
238 #include "params.def"
240 { NULL, 0, 0, 0, NULL }
243 /* Output files for assembler code (real compiler output)
244 and debugging dumps. */
248 FILE *stack_usage_file = NULL;
249 FILE *dump_file = NULL;
250 const char *dump_file_name;
252 /* The current working directory of a translation. It's generally the
253 directory from which compilation was initiated, but a preprocessed
254 file may specify the original directory in which it was
257 static const char *src_pwd;
259 /* Initialize src_pwd with the given string, and return true. If it
260 was already initialized, return false. As a special case, it may
261 be called with a NULL argument to test whether src_pwd has NOT been
265 set_src_pwd (const char *pwd)
269 if (strcmp (src_pwd, pwd) == 0)
275 src_pwd = xstrdup (pwd);
279 /* Return the directory from which the translation unit was initiated,
280 in case set_src_pwd() was not called before to assign it a
296 /* Called when the start of a function definition is parsed,
297 this function prints on stderr the name of the function. */
299 announce_function (tree decl)
303 if (rtl_dump_and_exit)
304 fprintf (stderr, "%s ",
305 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
307 fprintf (stderr, " %s",
308 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
310 pp_needs_newline (global_dc->printer) = true;
311 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
315 /* Initialize local_tick with the time of day, or -1 if
316 flag_random_seed is set. */
319 init_local_tick (void)
321 if (!flag_random_seed)
323 /* Get some more or less random data. */
324 #ifdef HAVE_GETTIMEOFDAY
328 gettimeofday (&tv, NULL);
329 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
333 time_t now = time (NULL);
335 if (now != (time_t)-1)
336 local_tick = (unsigned) now;
344 /* Set up a default flag_random_seed and local_tick, unless the user
345 already specified one. Must be called after init_local_tick. */
348 init_random_seed (void)
350 unsigned HOST_WIDE_INT value;
351 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
353 value = local_tick ^ getpid ();
355 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
356 flag_random_seed = random_seed;
359 /* Obtain the random_seed string. Unless NOINIT, initialize it if
360 it's not provided in the command line. */
363 get_random_seed (bool noinit)
365 if (!flag_random_seed && !noinit)
367 return flag_random_seed;
370 /* Modify the random_seed string to VAL. Return its previous
374 set_random_seed (const char *val)
376 const char *old = flag_random_seed;
377 flag_random_seed = val;
381 #if GCC_VERSION < 3004
383 /* The functions clz_hwi, ctz_hwi, ffs_hwi, floor_log2 and exact_log2
384 are defined as inline functions in toplev.h if GCC_VERSION >= 3004.
385 The definitions here are used for older versions of gcc. */
387 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
388 If X is 0, return -1. */
391 floor_log2 (unsigned HOST_WIDE_INT x)
398 if (HOST_BITS_PER_WIDE_INT > 64)
399 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
401 if (HOST_BITS_PER_WIDE_INT > 32)
402 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
404 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
406 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
408 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
410 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
412 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
418 /* Return the logarithm of X, base 2, considering X unsigned,
419 if X is a power of 2. Otherwise, returns -1. */
422 exact_log2 (unsigned HOST_WIDE_INT x)
426 return floor_log2 (x);
429 /* Given X, an unsigned number, return the number of least significant bits
430 that are zero. When X == 0, the result is the word size. */
433 ctz_hwi (unsigned HOST_WIDE_INT x)
435 return x ? floor_log2 (x & -x) : HOST_BITS_PER_WIDE_INT;
438 /* Similarly for most significant bits. */
441 clz_hwi (unsigned HOST_WIDE_INT x)
443 return HOST_BITS_PER_WIDE_INT - 1 - floor_log2(x);
446 /* Similar to ctz_hwi, except that the least significant bit is numbered
447 starting from 1, and X == 0 yields 0. */
450 ffs_hwi (unsigned HOST_WIDE_INT x)
452 return 1 + floor_log2 (x & -x);
455 #endif /* GCC_VERSION < 3004 */
457 /* Handler for fatal signals, such as SIGSEGV. These are transformed
458 into ICE messages, which is much more user friendly. In case the
459 error printer crashes, reset the signal to prevent infinite recursion. */
462 crash_signal (int signo)
464 signal (signo, SIG_DFL);
466 /* If we crashed while processing an ASM statement, then be a little more
467 graceful. It's most likely the user's fault. */
468 if (this_is_asm_operands)
470 output_operand_lossage ("unrecoverable error");
471 exit (FATAL_EXIT_CODE);
474 internal_error ("%s", strsignal (signo));
477 /* Output a quoted string. */
480 output_quoted_string (FILE *asm_file, const char *string)
482 #ifdef OUTPUT_QUOTED_STRING
483 OUTPUT_QUOTED_STRING (asm_file, string);
487 putc ('\"', asm_file);
488 while ((c = *string++) != 0)
492 if (c == '\"' || c == '\\')
493 putc ('\\', asm_file);
497 fprintf (asm_file, "\\%03o", (unsigned char) c);
499 putc ('\"', asm_file);
503 /* A subroutine of wrapup_global_declarations. We've come to the end of
504 the compilation unit. All deferred variables should be undeferred,
505 and all incomplete decls should be finalized. */
508 wrapup_global_declaration_1 (tree decl)
510 /* We're not deferring this any longer. Assignment is conditional to
511 avoid needlessly dirtying PCH pages. */
512 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
513 && DECL_DEFER_OUTPUT (decl) != 0)
514 DECL_DEFER_OUTPUT (decl) = 0;
516 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
517 lang_hooks.finish_incomplete_decl (decl);
520 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
521 needs to be output. Return true if it is output. */
524 wrapup_global_declaration_2 (tree decl)
526 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
529 /* Don't write out static consts, unless we still need them.
531 We also keep static consts if not optimizing (for debugging),
532 unless the user specified -fno-keep-static-consts.
533 ??? They might be better written into the debug information.
534 This is possible when using DWARF.
536 A language processor that wants static constants to be always
537 written out (even if it is not used) is responsible for
538 calling rest_of_decl_compilation itself. E.g. the C front-end
539 calls rest_of_decl_compilation from finish_decl.
540 One motivation for this is that is conventional in some
541 environments to write things like:
542 static const char rcsid[] = "... version string ...";
543 intending to force the string to be in the executable.
545 A language processor that would prefer to have unneeded
546 static constants "optimized away" would just defer writing
547 them out until here. E.g. C++ does this, because static
548 constants are often defined in header files.
550 ??? A tempting alternative (for both C and C++) would be
551 to force a constant to be written if and only if it is
552 defined in a main file, as opposed to an include file. */
554 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
556 struct varpool_node *node;
558 node = varpool_get_node (decl);
560 if (!node && flag_ltrans)
562 else if (node && node->finalized)
564 else if (node && node->alias)
566 else if (!cgraph_global_info_ready
568 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
570 else if (node && node->needed)
572 else if (DECL_COMDAT (decl))
574 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
575 && (optimize || !flag_keep_static_consts
576 || DECL_ARTIFICIAL (decl)))
581 rest_of_decl_compilation (decl, 1, 1);
589 /* Do any final processing required for the declarations in VEC, of
590 which there are LEN. We write out inline functions and variables
591 that have been deferred until this point, but which are required.
592 Returns nonzero if anything was put out. */
595 wrapup_global_declarations (tree *vec, int len)
597 bool reconsider, output_something = false;
600 for (i = 0; i < len; i++)
601 wrapup_global_declaration_1 (vec[i]);
603 /* Now emit any global variables or functions that we have been
604 putting off. We need to loop in case one of the things emitted
605 here references another one which comes earlier in the list. */
609 for (i = 0; i < len; i++)
610 reconsider |= wrapup_global_declaration_2 (vec[i]);
612 output_something = true;
616 return output_something;
619 /* A subroutine of check_global_declarations. Issue appropriate warnings
620 for the global declaration DECL. */
623 check_global_declaration_1 (tree decl)
625 /* Warn about any function declared static but not defined. We don't
626 warn about variables, because many programs have static variables
627 that exist only to get some text into the object file. */
628 if (TREE_CODE (decl) == FUNCTION_DECL
629 && DECL_INITIAL (decl) == 0
630 && DECL_EXTERNAL (decl)
631 && ! DECL_ARTIFICIAL (decl)
632 && ! TREE_NO_WARNING (decl)
633 && ! TREE_PUBLIC (decl)
634 && (warn_unused_function
635 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
637 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
638 pedwarn (input_location, 0, "%q+F used but never defined", decl);
640 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
641 /* This symbol is effectively an "extern" declaration now. */
642 TREE_PUBLIC (decl) = 1;
643 assemble_external (decl);
646 /* Warn about static fns or vars defined but not used. */
647 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
648 /* We don't warn about "static const" variables because the
649 "rcs_id" idiom uses that construction. */
650 || (warn_unused_variable
651 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
652 && ! DECL_IN_SYSTEM_HEADER (decl)
653 && ! TREE_USED (decl)
654 /* The TREE_USED bit for file-scope decls is kept in the identifier,
655 to handle multiple external decls in different scopes. */
656 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
657 && ! DECL_EXTERNAL (decl)
658 && ! TREE_PUBLIC (decl)
659 /* A volatile variable might be used in some non-obvious way. */
660 && ! TREE_THIS_VOLATILE (decl)
661 /* Global register variables must be declared to reserve them. */
662 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
663 /* Otherwise, ask the language. */
664 && lang_hooks.decls.warn_unused_global (decl))
665 warning ((TREE_CODE (decl) == FUNCTION_DECL)
666 ? OPT_Wunused_function
667 : OPT_Wunused_variable,
668 "%q+D defined but not used", decl);
671 /* Issue appropriate warnings for the global declarations in VEC (of
672 which there are LEN). */
675 check_global_declarations (tree *vec, int len)
679 for (i = 0; i < len; i++)
680 check_global_declaration_1 (vec[i]);
683 /* Emit debugging information for all global declarations in VEC. */
686 emit_debug_global_declarations (tree *vec, int len)
690 /* Avoid confusing the debug information machinery when there are errors. */
694 timevar_push (TV_SYMOUT);
695 for (i = 0; i < len; i++)
696 debug_hooks->global_decl (vec[i]);
697 timevar_pop (TV_SYMOUT);
700 /* Warn about a use of an identifier which was marked deprecated. */
702 warn_deprecated_use (tree node, tree attr)
706 if (node == 0 || !warn_deprecated_decl)
712 attr = DECL_ATTRIBUTES (node);
713 else if (TYPE_P (node))
715 tree decl = TYPE_STUB_DECL (node);
717 attr = lookup_attribute ("deprecated",
718 TYPE_ATTRIBUTES (TREE_TYPE (decl)));
723 attr = lookup_attribute ("deprecated", attr);
726 msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
732 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
734 warning (OPT_Wdeprecated_declarations,
735 "%qD is deprecated (declared at %s:%d): %s",
736 node, xloc.file, xloc.line, msg);
738 warning (OPT_Wdeprecated_declarations,
739 "%qD is deprecated (declared at %s:%d)",
740 node, xloc.file, xloc.line);
742 else if (TYPE_P (node))
744 tree what = NULL_TREE;
745 tree decl = TYPE_STUB_DECL (node);
747 if (TYPE_NAME (node))
749 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
750 what = TYPE_NAME (node);
751 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
752 && DECL_NAME (TYPE_NAME (node)))
753 what = DECL_NAME (TYPE_NAME (node));
758 expanded_location xloc
759 = expand_location (DECL_SOURCE_LOCATION (decl));
763 warning (OPT_Wdeprecated_declarations,
764 "%qE is deprecated (declared at %s:%d): %s",
765 what, xloc.file, xloc.line, msg);
767 warning (OPT_Wdeprecated_declarations,
768 "%qE is deprecated (declared at %s:%d)", what,
769 xloc.file, xloc.line);
774 warning (OPT_Wdeprecated_declarations,
775 "type is deprecated (declared at %s:%d): %s",
776 xloc.file, xloc.line, msg);
778 warning (OPT_Wdeprecated_declarations,
779 "type is deprecated (declared at %s:%d)",
780 xloc.file, xloc.line);
788 warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s",
791 warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what);
796 warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
799 warning (OPT_Wdeprecated_declarations, "type is deprecated");
805 /* Compile an entire translation unit. Write a file of assembly
806 output and various debugging dumps. */
811 /* Initialize yet another pass. */
813 ggc_protect_identifiers = true;
816 init_final (main_input_filename);
817 coverage_init (aux_base_name);
819 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
821 timevar_push (TV_PARSE);
823 /* Call the parser, which parses the entire file (calling
824 rest_of_compilation for each function). */
825 lang_hooks.parse_file ();
827 /* Compilation is now finished except for writing
828 what's left of the symbol table output. */
829 timevar_pop (TV_PARSE);
831 if (flag_syntax_only || flag_wpa)
834 ggc_protect_identifiers = false;
836 /* This must also call cgraph_finalize_compilation_unit. */
837 lang_hooks.decls.final_write_globals ();
842 varpool_assemble_pending_decls ();
845 /* Likewise for mudflap static object registrations. */
847 mudflap_finish_file ();
849 output_shared_constant_pool ();
850 output_object_blocks ();
852 /* Write out any pending weak symbol declarations. */
855 /* This must be at the end before unwind and debug info.
856 Some target ports emit PIC setup thunks here. */
857 targetm.asm_out.code_end ();
859 /* Do dbx symbols. */
860 timevar_push (TV_SYMOUT);
862 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
863 if (dwarf2out_do_frame ())
864 dwarf2out_frame_finish ();
867 (*debug_hooks->finish) (main_input_filename);
868 timevar_pop (TV_SYMOUT);
870 /* Output some stuff at end of file if nec. */
872 dw2_output_indirect_constants ();
874 /* Flush any pending external directives. */
875 process_pending_assemble_externals ();
877 /* Emit LTO marker if LTO info has been previously emitted. This is
878 used by collect2 to determine whether an object file contains IL.
879 We used to emit an undefined reference here, but this produces
880 link errors if an object file with IL is stored into a shared
881 library without invoking lto1. */
882 if (flag_generate_lto)
884 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
885 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
887 (unsigned HOST_WIDE_INT) 1, 8);
888 #elif defined ASM_OUTPUT_ALIGNED_COMMON
889 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1",
890 (unsigned HOST_WIDE_INT) 1, 8);
892 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1",
893 (unsigned HOST_WIDE_INT) 1,
894 (unsigned HOST_WIDE_INT) 1);
898 /* Attach a special .ident directive to the end of the file to identify
899 the version of GCC which compiled this code. The format of the .ident
900 string is patterned after the ones produced by native SVR4 compilers. */
904 const char *pkg_version = "(GNU) ";
906 if (strcmp ("(GCC) ", pkgversion_string))
907 pkg_version = pkgversion_string;
908 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
909 IDENT_ASM_OP, pkg_version, version_string);
913 /* Invoke registered plugin callbacks. */
914 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
916 /* This must be at the end. Some target ports emit end of file directives
917 into the assembly file here, and hence we can not output anything to the
918 assembly file after this point. */
919 targetm.asm_out.file_end ();
922 /* Indexed by enum debug_info_type. */
923 const char *const debug_type_names[] =
925 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
928 /* Print version information to FILE.
929 Each line begins with INDENT (for the case where FILE is the
930 assembler output file). */
933 print_version (FILE *file, const char *indent)
935 static const char fmt1[] =
937 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
939 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
942 static const char fmt2[] =
943 N_("GMP version %s, MPFR version %s, MPC version %s\n");
944 static const char fmt3[] =
945 N_("%s%swarning: %s header version %s differs from library version %s.\n");
946 static const char fmt4[] =
947 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
949 #define __VERSION__ "[?]"
952 file == stderr ? _(fmt1) : fmt1,
953 indent, *indent != 0 ? " " : "",
954 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
955 indent, __VERSION__);
957 /* We need to stringify the GMP macro values. Ugh, gmp_version has
958 two string formats, "i.j.k" and "i.j" when k is zero. As of
959 gmp-4.3.0, GMP always uses the 3 number format. */
960 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
961 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
962 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
963 #define GCC_GMP_VERSION \
964 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
965 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
966 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
967 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
969 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
970 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
971 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
974 file == stderr ? _(fmt2) : fmt2,
975 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING);
976 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
978 file == stderr ? _(fmt3) : fmt3,
979 indent, *indent != 0 ? " " : "",
980 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
981 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
983 file == stderr ? _(fmt3) : fmt3,
984 indent, *indent != 0 ? " " : "",
985 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
986 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
988 file == stderr ? _(fmt3) : fmt3,
989 indent, *indent != 0 ? " " : "",
990 "MPC", MPC_VERSION_STRING, mpc_get_version ());
992 file == stderr ? _(fmt4) : fmt4,
993 indent, *indent != 0 ? " " : "",
994 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
996 print_plugins_versions (file, indent);
999 #ifdef ASM_COMMENT_START
1001 print_to_asm_out_file (print_switch_type type, const char * text)
1003 bool prepend_sep = true;
1007 case SWITCH_TYPE_LINE_END:
1008 putc ('\n', asm_out_file);
1011 case SWITCH_TYPE_LINE_START:
1012 fputs (ASM_COMMENT_START, asm_out_file);
1013 return strlen (ASM_COMMENT_START);
1015 case SWITCH_TYPE_DESCRIPTIVE:
1016 if (ASM_COMMENT_START[0] == 0)
1017 prepend_sep = false;
1019 case SWITCH_TYPE_PASSED:
1020 case SWITCH_TYPE_ENABLED:
1022 fputc (' ', asm_out_file);
1023 fputs (text, asm_out_file);
1024 /* No need to return the length here as
1025 print_single_switch has already done it. */
1035 print_to_stderr (print_switch_type type, const char * text)
1039 case SWITCH_TYPE_LINE_END:
1040 putc ('\n', stderr);
1043 case SWITCH_TYPE_LINE_START:
1046 case SWITCH_TYPE_PASSED:
1047 case SWITCH_TYPE_ENABLED:
1048 fputc (' ', stderr);
1051 case SWITCH_TYPE_DESCRIPTIVE:
1052 fputs (text, stderr);
1053 /* No need to return the length here as
1054 print_single_switch has already done it. */
1062 /* Print an option value and return the adjusted position in the line.
1063 ??? print_fn doesn't handle errors, eg disk full; presumably other
1064 code will catch a disk full though. */
1067 print_single_switch (print_switch_fn_type print_fn,
1069 print_switch_type type,
1072 /* The ultrix fprintf returns 0 on success, so compute the result
1073 we want here since we need it for the following test. The +1
1074 is for the separator character that will probably be emitted. */
1075 int len = strlen (text) + 1;
1078 && pos + len > MAX_LINE)
1080 print_fn (SWITCH_TYPE_LINE_END, NULL);
1085 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1087 print_fn (type, text);
1091 /* Print active target switches using PRINT_FN.
1092 POS is the current cursor position and MAX is the size of a "line".
1093 Each line begins with INDENT and ends with TERM.
1094 Each switch is separated from the next by SEP. */
1097 print_switch_values (print_switch_fn_type print_fn)
1102 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1103 that it can be printed below. This helps reproducibility. */
1104 if (!flag_random_seed)
1105 init_random_seed ();
1107 /* Print the options as passed. */
1108 pos = print_single_switch (print_fn, pos,
1109 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1111 for (j = 1; j < save_decoded_options_count; j++)
1113 switch (save_decoded_options[j].opt_index)
1126 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED,
1127 save_decoded_options[j].orig_option_with_args_text);
1131 print_fn (SWITCH_TYPE_LINE_END, NULL);
1133 /* Print the -f and -m options that have been enabled.
1134 We don't handle language specific options but printing argv
1136 pos = print_single_switch (print_fn, 0,
1137 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1139 for (j = 0; j < cl_options_count; j++)
1140 if ((cl_options[j].flags & CL_REPORT)
1141 && option_enabled (j, &global_options) > 0)
1142 pos = print_single_switch (print_fn, pos,
1143 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1145 print_fn (SWITCH_TYPE_LINE_END, NULL);
1148 /* Open assembly code output file. Do this even if -fsyntax-only is
1149 on, because then the driver will have provided the name of a
1150 temporary file or bit bucket for us. NAME is the file specified on
1151 the command line, possibly NULL. */
1153 init_asm_output (const char *name)
1155 if (name == NULL && asm_file_name == 0)
1156 asm_out_file = stdout;
1159 if (asm_file_name == 0)
1161 int len = strlen (dump_base_name);
1162 char *dumpname = XNEWVEC (char, len + 6);
1164 memcpy (dumpname, dump_base_name, len + 1);
1165 strip_off_ending (dumpname, len);
1166 strcat (dumpname, ".s");
1167 asm_file_name = dumpname;
1169 if (!strcmp (asm_file_name, "-"))
1170 asm_out_file = stdout;
1172 asm_out_file = fopen (asm_file_name, "w+b");
1173 if (asm_out_file == 0)
1174 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1177 if (!flag_syntax_only)
1179 targetm.asm_out.file_start ();
1181 if (flag_record_gcc_switches)
1183 if (targetm.asm_out.record_gcc_switches)
1185 /* Let the target know that we are about to start recording. */
1186 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1188 /* Now record the switches. */
1189 print_switch_values (targetm.asm_out.record_gcc_switches);
1190 /* Let the target know that the recording is over. */
1191 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1195 inform (input_location, "-frecord-gcc-switches is not supported by the current target");
1198 #ifdef ASM_COMMENT_START
1199 if (flag_verbose_asm)
1201 /* Print the list of switches in effect
1202 into the assembler file as comments. */
1203 print_version (asm_out_file, ASM_COMMENT_START);
1204 print_switch_values (print_to_asm_out_file);
1205 putc ('\n', asm_out_file);
1211 /* Return true if the state of option OPTION should be stored in PCH files
1212 and checked by default_pch_valid_p. Store the option's current state
1216 option_affects_pch_p (int option, struct cl_option_state *state)
1218 if ((cl_options[option].flags & CL_TARGET) == 0)
1220 if (option_flag_var (option, &global_options) == &target_flags)
1221 if (targetm.check_pch_target_flags)
1223 return get_option_state (&global_options, option, state);
1226 /* Default version of get_pch_validity.
1227 By default, every flag difference is fatal; that will be mostly right for
1228 most targets, but completely right for very few. */
1231 default_get_pch_validity (size_t *sz)
1233 struct cl_option_state state;
1238 if (targetm.check_pch_target_flags)
1239 *sz += sizeof (target_flags);
1240 for (i = 0; i < cl_options_count; i++)
1241 if (option_affects_pch_p (i, &state))
1244 result = r = XNEWVEC (char, *sz);
1248 if (targetm.check_pch_target_flags)
1250 memcpy (r, &target_flags, sizeof (target_flags));
1251 r += sizeof (target_flags);
1254 for (i = 0; i < cl_options_count; i++)
1255 if (option_affects_pch_p (i, &state))
1257 memcpy (r, state.data, state.size);
1264 /* Return a message which says that a PCH file was created with a different
1265 setting of OPTION. */
1268 pch_option_mismatch (const char *option)
1272 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1274 return _("out of memory");
1278 /* Default version of pch_valid_p. */
1281 default_pch_valid_p (const void *data_p, size_t len)
1283 struct cl_option_state state;
1284 const char *data = (const char *)data_p;
1287 /* -fpic and -fpie also usually make a PCH invalid. */
1288 if (data[0] != flag_pic)
1289 return _("created and used with different settings of -fpic");
1290 if (data[1] != flag_pie)
1291 return _("created and used with different settings of -fpie");
1294 /* Check target_flags. */
1295 if (targetm.check_pch_target_flags)
1300 memcpy (&tf, data, sizeof (target_flags));
1301 data += sizeof (target_flags);
1302 len -= sizeof (target_flags);
1303 r = targetm.check_pch_target_flags (tf);
1308 for (i = 0; i < cl_options_count; i++)
1309 if (option_affects_pch_p (i, &state))
1311 if (memcmp (data, state.data, state.size) != 0)
1312 return pch_option_mismatch (cl_options[i].opt_text);
1320 /* Default tree printer. Handles declarations only. */
1322 default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
1323 int precision, bool wide, bool set_locus, bool hash)
1327 /* FUTURE: %+x should set the locus. */
1328 if (precision != 0 || wide || hash)
1334 t = va_arg (*text->args_ptr, tree);
1335 if (TREE_CODE (t) == IDENTIFIER_NODE)
1337 pp_identifier (pp, IDENTIFIER_POINTER (t));
1343 t = va_arg (*text->args_ptr, tree);
1344 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1345 t = DECL_DEBUG_EXPR (t);
1350 t = va_arg (*text->args_ptr, tree);
1354 percent_K_format (text);
1361 if (set_locus && text->locus)
1362 *text->locus = DECL_SOURCE_LOCATION (t);
1366 const char *n = DECL_NAME (t)
1367 ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2))
1372 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1377 /* A helper function; used as the reallocator function for cpp's line
1380 realloc_for_line_map (void *ptr, size_t len)
1382 return GGC_RESIZEVAR (void, ptr, len);
1385 /* A helper function: used as the allocator function for
1386 identifier_to_locale. */
1388 alloc_for_identifier_to_locale (size_t len)
1390 return ggc_alloc_atomic (len);
1393 /* Output stack usage information. */
1395 output_stack_usage (void)
1397 static bool warning_issued = false;
1398 enum stack_usage_kind_type { STATIC = 0, DYNAMIC, DYNAMIC_BOUNDED };
1399 const char *stack_usage_kind_str[] = {
1404 HOST_WIDE_INT stack_usage = current_function_static_stack_size;
1405 enum stack_usage_kind_type stack_usage_kind;
1406 expanded_location loc;
1407 const char *raw_id, *id;
1409 if (stack_usage < 0)
1411 if (!warning_issued)
1413 warning (0, "-fstack-usage not supported for this target");
1414 warning_issued = true;
1419 stack_usage_kind = STATIC;
1421 /* Add the maximum amount of space pushed onto the stack. */
1422 if (current_function_pushed_stack_size > 0)
1424 stack_usage += current_function_pushed_stack_size;
1425 stack_usage_kind = DYNAMIC_BOUNDED;
1428 /* Now on to the tricky part: dynamic stack allocation. */
1429 if (current_function_allocates_dynamic_stack_space)
1431 if (current_function_has_unbounded_dynamic_stack_size)
1432 stack_usage_kind = DYNAMIC;
1434 stack_usage_kind = DYNAMIC_BOUNDED;
1436 /* Add the size even in the unbounded case, this can't hurt. */
1437 stack_usage += current_function_dynamic_stack_size;
1440 loc = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
1442 /* Strip the scope prefix if any. */
1443 raw_id = lang_hooks.decl_printable_name (current_function_decl, 2);
1444 id = strrchr (raw_id, '.');
1450 fprintf (stack_usage_file,
1451 "%s:%d:%d:%s\t"HOST_WIDE_INT_PRINT_DEC"\t%s\n",
1452 lbasename (loc.file),
1457 stack_usage_kind_str[stack_usage_kind]);
1460 /* Open an auxiliary output file. */
1462 open_auxiliary_file (const char *ext)
1467 filename = concat (aux_base_name, ".", ext, NULL);
1468 file = fopen (filename, "w");
1470 fatal_error ("can%'t open %s for writing: %m", filename);
1475 /* Initialization of the front end environment, before command line
1476 options are parsed. Signal handlers, internationalization etc.
1477 ARGV0 is main's argv[0]. */
1479 general_init (const char *argv0)
1483 p = argv0 + strlen (argv0);
1484 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1488 xmalloc_set_program_name (progname);
1492 /* Unlock the stdio streams. */
1493 unlock_std_streams ();
1495 gcc_init_libintl ();
1497 identifier_to_locale_alloc = alloc_for_identifier_to_locale;
1498 identifier_to_locale_free = ggc_free;
1500 /* Initialize the diagnostics reporting machinery, so option parsing
1501 can give warnings and errors. */
1502 diagnostic_initialize (global_dc, N_OPTS);
1503 diagnostic_starter (global_dc) = default_tree_diagnostic_starter;
1504 /* Set a default printer. Language specific initializations will
1505 override it later. */
1506 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1507 global_dc->show_option_requested
1508 = global_options_init.x_flag_diagnostics_show_option;
1509 global_dc->show_column
1510 = global_options_init.x_flag_show_column;
1511 global_dc->internal_error = plugins_internal_error_function;
1512 global_dc->option_enabled = option_enabled;
1513 global_dc->option_state = &global_options;
1514 global_dc->option_name = option_name;
1516 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1518 signal (SIGSEGV, crash_signal);
1521 signal (SIGILL, crash_signal);
1524 signal (SIGBUS, crash_signal);
1527 signal (SIGABRT, crash_signal);
1529 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1530 signal (SIGIOT, crash_signal);
1533 signal (SIGFPE, crash_signal);
1536 /* Other host-specific signal setup. */
1537 (*host_hooks.extra_signals)();
1539 /* Initialize the garbage-collector, string pools and tree type hash
1543 line_table = ggc_alloc_line_maps ();
1544 linemap_init (line_table);
1545 line_table->reallocator = realloc_for_line_map;
1548 /* Initialize register usage now so switches may override. */
1551 /* Register the language-independent parameters. */
1552 add_params (lang_independent_params, LAST_PARAM);
1553 targetm.target_option.default_params ();
1555 /* This must be done after add_params but before argument processing. */
1556 init_ggc_heuristics();
1557 init_optimization_passes ();
1558 statistics_early_init ();
1562 /* Return true if the current target supports -fsection-anchors. */
1565 target_supports_section_anchors_p (void)
1567 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1570 if (targetm.asm_out.output_anchor == NULL)
1576 /* Default the align_* variables to 1 if they're still unset, and
1577 set up the align_*_log variables. */
1579 init_alignments (void)
1581 if (align_loops <= 0)
1583 if (align_loops_max_skip > align_loops)
1584 align_loops_max_skip = align_loops - 1;
1585 align_loops_log = floor_log2 (align_loops * 2 - 1);
1586 if (align_jumps <= 0)
1588 if (align_jumps_max_skip > align_jumps)
1589 align_jumps_max_skip = align_jumps - 1;
1590 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1591 if (align_labels <= 0)
1593 align_labels_log = floor_log2 (align_labels * 2 - 1);
1594 if (align_labels_max_skip > align_labels)
1595 align_labels_max_skip = align_labels - 1;
1596 if (align_functions <= 0)
1597 align_functions = 1;
1598 align_functions_log = floor_log2 (align_functions * 2 - 1);
1601 /* Process the options that have been parsed. */
1603 process_options (void)
1605 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1606 This can happen with incorrect pre-processed input. */
1607 debug_hooks = &do_nothing_debug_hooks;
1609 /* This replaces set_Wunused. */
1610 if (warn_unused_function == -1)
1611 warn_unused_function = warn_unused;
1612 if (warn_unused_label == -1)
1613 warn_unused_label = warn_unused;
1614 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */
1615 if (warn_unused_parameter == -1)
1616 warn_unused_parameter = (warn_unused && extra_warnings);
1617 if (warn_unused_variable == -1)
1618 warn_unused_variable = warn_unused;
1619 /* Wunused-but-set-parameter is enabled if both -Wunused -Wextra are
1621 if (warn_unused_but_set_parameter == -1)
1622 warn_unused_but_set_parameter = (warn_unused && extra_warnings);
1623 if (warn_unused_but_set_variable == -1)
1624 warn_unused_but_set_variable = warn_unused;
1625 if (warn_unused_value == -1)
1626 warn_unused_value = warn_unused;
1628 /* This replaces set_Wextra. */
1629 if (warn_uninitialized == -1)
1630 warn_uninitialized = extra_warnings;
1632 /* Allow the front end to perform consistency checks and do further
1633 initialization based on the command line options. This hook also
1634 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1635 so we can correctly initialize debug output. */
1636 no_backend = lang_hooks.post_options (&main_input_filename);
1638 /* Some machines may reject certain combinations of options. */
1639 targetm.target_option.override ();
1641 /* Avoid any informative notes in the second run of -fcompare-debug. */
1642 if (flag_compare_debug)
1643 diagnostic_inhibit_notes (global_dc);
1645 if (flag_section_anchors && !target_supports_section_anchors_p ())
1647 warning (OPT_fsection_anchors,
1648 "this target does not support %qs", "-fsection-anchors");
1649 flag_section_anchors = 0;
1652 if (flag_short_enums == 2)
1653 flag_short_enums = targetm.default_short_enums ();
1655 /* Set aux_base_name if not already set. */
1658 else if (main_input_filename)
1660 char *name = xstrdup (lbasename (main_input_filename));
1662 strip_off_ending (name, strlen (name));
1663 aux_base_name = name;
1666 aux_base_name = "gccaux";
1671 || flag_loop_interchange
1672 || flag_loop_strip_mine
1673 || flag_graphite_identity
1674 || flag_loop_parallelize_all)
1675 sorry ("Graphite loop optimizations cannot be used");
1678 /* Unrolling all loops implies that standard loop unrolling must also
1680 if (flag_unroll_all_loops)
1681 flag_unroll_loops = 1;
1683 /* web and rename-registers help when run after loop unrolling. */
1684 if (flag_web == AUTODETECT_VALUE)
1685 flag_web = flag_unroll_loops || flag_peel_loops;
1687 if (flag_rename_registers == AUTODETECT_VALUE)
1688 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1690 if (flag_non_call_exceptions)
1691 flag_asynchronous_unwind_tables = 1;
1692 if (flag_asynchronous_unwind_tables)
1693 flag_unwind_tables = 1;
1695 if (flag_value_profile_transformations)
1696 flag_profile_values = 1;
1698 /* Warn about options that are not supported on this machine. */
1699 #ifndef INSN_SCHEDULING
1700 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1701 warning (0, "instruction scheduling not supported on this target machine");
1704 if (flag_delayed_branch)
1705 warning (0, "this target machine does not have delayed branches");
1708 user_label_prefix = USER_LABEL_PREFIX;
1709 if (flag_leading_underscore != -1)
1711 /* If the default prefix is more complicated than "" or "_",
1712 issue a warning and ignore this option. */
1713 if (user_label_prefix[0] == 0 ||
1714 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1716 user_label_prefix = flag_leading_underscore ? "_" : "";
1719 warning (0, "-f%sleading-underscore not supported on this target machine",
1720 flag_leading_underscore ? "" : "no-");
1723 /* If we are in verbose mode, write out the version and maybe all the
1724 option flags in use. */
1727 print_version (stderr, "");
1729 print_switch_values (print_to_stderr);
1732 if (flag_syntax_only)
1734 write_symbols = NO_DEBUG;
1740 if (debug_info_level == DINFO_LEVEL_NONE)
1742 debug_info_level = DINFO_LEVEL_NORMAL;
1744 if (write_symbols == NO_DEBUG)
1745 write_symbols = PREFERRED_DEBUGGING_TYPE;
1748 debug_info_level = DINFO_LEVEL_NONE;
1751 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1753 FILE *final_output = fopen (flag_dump_final_insns, "w");
1756 error ("could not open final insn dump file %qs: %m",
1757 flag_dump_final_insns);
1758 flag_dump_final_insns = NULL;
1760 else if (fclose (final_output))
1762 error ("could not close zeroed insn dump file %qs: %m",
1763 flag_dump_final_insns);
1764 flag_dump_final_insns = NULL;
1768 /* Unless over-ridden for the target, assume that all DWARF levels
1769 may be emitted, if DWARF2_DEBUG is selected. */
1770 if (dwarf_strict < 0)
1773 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1775 if (debug_info_level == DINFO_LEVEL_NONE)
1776 write_symbols = NO_DEBUG;
1778 if (write_symbols == NO_DEBUG)
1780 #if defined(DBX_DEBUGGING_INFO)
1781 else if (write_symbols == DBX_DEBUG)
1782 debug_hooks = &dbx_debug_hooks;
1784 #if defined(XCOFF_DEBUGGING_INFO)
1785 else if (write_symbols == XCOFF_DEBUG)
1786 debug_hooks = &xcoff_debug_hooks;
1788 #ifdef SDB_DEBUGGING_INFO
1789 else if (write_symbols == SDB_DEBUG)
1790 debug_hooks = &sdb_debug_hooks;
1792 #ifdef DWARF2_DEBUGGING_INFO
1793 else if (write_symbols == DWARF2_DEBUG)
1794 debug_hooks = &dwarf2_debug_hooks;
1796 #ifdef VMS_DEBUGGING_INFO
1797 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1798 debug_hooks = &vmsdbg_debug_hooks;
1801 error ("target system does not support the \"%s\" debug format",
1802 debug_type_names[write_symbols]);
1804 /* We know which debug output will be used so we can set flag_var_tracking
1805 and flag_var_tracking_uninit if the user has not specified them. */
1806 if (debug_info_level < DINFO_LEVEL_NORMAL
1807 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1809 if (flag_var_tracking == 1
1810 || flag_var_tracking_uninit == 1)
1812 if (debug_info_level < DINFO_LEVEL_NORMAL)
1813 warning (0, "variable tracking requested, but useless unless "
1814 "producing debug info");
1816 warning (0, "variable tracking requested, but not supported "
1817 "by this debug format");
1819 flag_var_tracking = 0;
1820 flag_var_tracking_uninit = 0;
1823 /* The debug hooks are used to implement -fdump-go-spec because it
1824 gives a simple and stable API for all the information we need to
1826 if (flag_dump_go_spec != NULL)
1827 debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
1829 /* If the user specifically requested variable tracking with tagging
1830 uninitialized variables, we need to turn on variable tracking.
1831 (We already determined above that variable tracking is feasible.) */
1832 if (flag_var_tracking_uninit)
1833 flag_var_tracking = 1;
1835 if (flag_var_tracking == AUTODETECT_VALUE)
1836 flag_var_tracking = optimize >= 1;
1838 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
1839 flag_var_tracking_assignments = flag_var_tracking
1840 && !(flag_selective_scheduling || flag_selective_scheduling2);
1842 if (flag_var_tracking_assignments_toggle)
1843 flag_var_tracking_assignments = !flag_var_tracking_assignments;
1845 if (flag_var_tracking_assignments && !flag_var_tracking)
1846 flag_var_tracking = flag_var_tracking_assignments = -1;
1848 if (flag_var_tracking_assignments
1849 && (flag_selective_scheduling || flag_selective_scheduling2))
1850 warning (0, "var-tracking-assignments changes selective scheduling");
1852 if (flag_tree_cselim == AUTODETECT_VALUE)
1853 #ifdef HAVE_conditional_move
1854 flag_tree_cselim = 1;
1856 flag_tree_cselim = 0;
1859 /* If auxiliary info generation is desired, open the output file.
1860 This goes in the same directory as the source file--unlike
1861 all the other output files. */
1862 if (flag_gen_aux_info)
1864 aux_info_file = fopen (aux_info_file_name, "w");
1865 if (aux_info_file == 0)
1866 fatal_error ("can%'t open %s: %m", aux_info_file_name);
1869 if (! targetm.have_named_sections)
1871 if (flag_function_sections)
1873 warning (0, "-ffunction-sections not supported for this target");
1874 flag_function_sections = 0;
1876 if (flag_data_sections)
1878 warning (0, "-fdata-sections not supported for this target");
1879 flag_data_sections = 0;
1883 if (flag_function_sections && profile_flag)
1885 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
1886 flag_function_sections = 0;
1889 #ifndef HAVE_prefetch
1890 if (flag_prefetch_loop_arrays > 0)
1892 warning (0, "-fprefetch-loop-arrays not supported for this target");
1893 flag_prefetch_loop_arrays = 0;
1896 if (flag_prefetch_loop_arrays > 0 && !HAVE_prefetch)
1898 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
1899 flag_prefetch_loop_arrays = 0;
1903 /* This combination of options isn't handled for i386 targets and doesn't
1904 make much sense anyway, so don't allow it. */
1905 if (flag_prefetch_loop_arrays > 0 && optimize_size)
1907 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
1908 flag_prefetch_loop_arrays = 0;
1911 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1912 if (flag_signaling_nans)
1913 flag_trapping_math = 1;
1915 /* We cannot reassociate if we want traps or signed zeros. */
1916 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1918 warning (0, "-fassociative-math disabled; other options take precedence");
1919 flag_associative_math = 0;
1922 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1923 if (flag_cx_limited_range)
1924 flag_complex_method = 0;
1926 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1927 if (flag_cx_fortran_rules)
1928 flag_complex_method = 1;
1930 /* Targets must be able to place spill slots at lower addresses. If the
1931 target already uses a soft frame pointer, the transition is trivial. */
1932 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1934 warning (0, "-fstack-protector not supported for this target");
1935 flag_stack_protect = 0;
1937 if (!flag_stack_protect)
1938 warn_stack_protect = 0;
1940 /* ??? Unwind info is not correct around the CFG unless either a frame
1941 pointer is present or A_O_A is set. Fixing this requires rewriting
1942 unwind info generation to be aware of the CFG and propagating states
1944 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
1945 && flag_omit_frame_pointer)
1947 warning (0, "unwind tables currently require a frame pointer "
1949 flag_omit_frame_pointer = 0;
1952 /* Save the current optimization options. */
1953 optimization_default_node = build_optimization_node ();
1954 optimization_current_node = optimization_default_node;
1957 /* This function can be called multiple times to reinitialize the compiler
1958 back end when register classes or instruction sets have changed,
1959 before each function. */
1961 backend_init_target (void)
1963 /* Initialize alignment variables. */
1966 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
1967 to initialize reg_raw_mode[]. */
1970 /* This invokes target hooks to set fixed_reg[] etc, which is
1974 /* This depends on stack_pointer_rtx. */
1975 init_fake_stack_mems ();
1977 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1979 init_alias_target ();
1981 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1984 /* The following initialization functions need to generate rtl, so
1985 provide a dummy function context for them. */
1986 init_dummy_function_start ();
1988 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1989 on a mode change. */
1992 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1993 after a mode change as well. */
1994 caller_save_initialized_p = false;
1996 expand_dummy_function_end ();
1999 /* Initialize the compiler back end. This function is called only once,
2000 when starting the compiler. */
2007 init_inline_once ();
2008 init_varasm_once ();
2009 save_register_info ();
2011 /* Initialize the target-specific back end pieces. */
2013 backend_init_target ();
2016 /* Initialize excess precision settings. */
2018 init_excess_precision (void)
2020 /* Adjust excess precision handling based on the target options. If
2021 the front end cannot handle it, flag_excess_precision_cmdline
2022 will already have been set accordingly in the post_options
2024 gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
2025 flag_excess_precision = flag_excess_precision_cmdline;
2026 if (flag_unsafe_math_optimizations)
2027 flag_excess_precision = EXCESS_PRECISION_FAST;
2028 if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
2030 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
2031 switch (flt_eval_method)
2035 /* Either the target acts unpredictably (-1) or has all the
2036 operations required not to have excess precision (0). */
2037 flag_excess_precision = EXCESS_PRECISION_FAST;
2041 /* In these cases, predictable excess precision makes
2045 /* Any other implementation-defined FLT_EVAL_METHOD values
2046 require the compiler to handle the associated excess
2047 precision rules in excess_precision_type. */
2053 /* Initialize things that are both lang-dependent and target-dependent.
2054 This function can be called more than once if target parameters change. */
2056 lang_dependent_init_target (void)
2058 /* This determines excess precision settings. */
2059 init_excess_precision ();
2061 /* This creates various _DECL nodes, so needs to be called after the
2062 front end is initialized. It also depends on the HAVE_xxx macros
2063 generated from the target machine description. */
2066 /* The following initialization functions need to generate rtl, so
2067 provide a dummy function context for them. */
2068 init_dummy_function_start ();
2070 /* Do the target-specific parts of expr initialization. */
2071 init_expr_target ();
2073 /* Although the actions of these functions are language-independent,
2074 they use optabs, so we cannot call them from backend_init. */
2078 expand_dummy_function_end ();
2081 /* Language-dependent initialization. Returns nonzero on success. */
2083 lang_dependent_init (const char *name)
2085 location_t save_loc = input_location;
2086 if (dump_base_name == 0)
2087 dump_base_name = name && name[0] ? name : "gccdump";
2089 /* Other front-end initialization. */
2090 input_location = BUILTINS_LOCATION;
2091 if (lang_hooks.init () == 0)
2093 input_location = save_loc;
2095 init_asm_output (name);
2097 /* If stack usage information is desired, open the output file. */
2098 if (flag_stack_usage)
2099 stack_usage_file = open_auxiliary_file ("su");
2101 /* This creates various _DECL nodes, so needs to be called after the
2102 front end is initialized. */
2105 /* Do the target-specific parts of the initialization. */
2106 lang_dependent_init_target ();
2108 /* If dbx symbol table desired, initialize writing it and output the
2109 predefined types. */
2110 timevar_push (TV_SYMOUT);
2112 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2113 if (dwarf2out_do_frame ())
2114 dwarf2out_frame_init ();
2117 /* Now we have the correct original filename, we can initialize
2119 (*debug_hooks->init) (name);
2121 timevar_pop (TV_SYMOUT);
2127 /* Reinitialize everything when target parameters, such as register usage,
2130 target_reinit (void)
2132 /* Reinitialize RTL backend. */
2133 backend_init_target ();
2135 /* Reinitialize lang-dependent parts. */
2136 lang_dependent_init_target ();
2140 dump_memory_report (bool final)
2142 ggc_print_statistics ();
2143 stringpool_statistics ();
2144 dump_tree_statistics ();
2145 dump_gimple_statistics ();
2146 dump_rtx_statistics ();
2147 dump_alloc_pool_statistics ();
2148 dump_bitmap_statistics ();
2149 dump_vec_loc_statistics ();
2150 dump_ggc_loc_statistics (final);
2151 dump_alias_stats (stderr);
2152 dump_pta_stats (stderr);
2155 /* Clean up: close opened files, etc. */
2160 /* Close the dump files. */
2161 if (flag_gen_aux_info)
2163 fclose (aux_info_file);
2165 unlink (aux_info_file_name);
2168 /* Close non-debugging input and output files. Take special care to note
2169 whether fclose returns an error, since the pages might still be on the
2170 buffer chain while the file is open. */
2174 if (ferror (asm_out_file) != 0)
2175 fatal_error ("error writing to %s: %m", asm_file_name);
2176 if (fclose (asm_out_file) != 0)
2177 fatal_error ("error closing %s: %m", asm_file_name);
2179 unlink_if_ordinary (asm_file_name);
2182 if (stack_usage_file)
2183 fclose (stack_usage_file);
2186 finish_optimization_passes ();
2191 dump_memory_report (true);
2193 /* Language-specific end of compilation actions. */
2194 lang_hooks.finish ();
2197 /* Initialize the compiler, and compile the input file. */
2201 /* Initialize timing first. The C front ends read the main file in
2202 the post_options hook, and C++ does file timings. */
2203 if (time_report || !quiet_flag || flag_detailed_statistics)
2205 timevar_start (TV_TOTAL);
2209 /* Don't do any more if an error has already occurred. */
2212 /* This must be run always, because it is needed to compute the FP
2213 predefined macros, such as __LDBL_MAX__, for targets using non
2214 default FP formats. */
2215 init_adjust_machine_modes ();
2217 /* Set up the back-end if requested. */
2221 /* Language-dependent initialization. Returns true on success. */
2222 if (lang_dependent_init (main_input_filename))
2228 /* Stop timing and print the times. */
2229 timevar_stop (TV_TOTAL);
2230 timevar_print (stderr);
2233 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2234 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2235 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2237 It is not safe to call this function more than once. */
2240 toplev_main (int argc, char **argv)
2242 expandargv (&argc, &argv);
2244 /* Initialization of GCC's environment, and diagnostics. */
2245 general_init (argv[0]);
2247 /* One-off initialization of options that does not need to be
2248 repeated when options are added for particular functions. */
2249 init_options_once ();
2251 /* Initialize global options structures; this must be repeated for
2252 each structure used for parsing options. */
2253 init_options_struct (&global_options, &global_options_set);
2254 lang_hooks.init_options_struct (&global_options);
2256 /* Convert the options to an array. */
2257 decode_cmdline_options_to_array_default_mask (argc,
2258 CONST_CAST2 (const char **,
2260 &save_decoded_options,
2261 &save_decoded_options_count);
2263 /* Perform language-specific options initialization. */
2264 lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
2266 /* Parse the options and do minimal processing; basically just
2267 enough to default flags appropriately. */
2268 decode_options (&global_options, &global_options_set,
2269 save_decoded_options, save_decoded_options_count,
2270 UNKNOWN_LOCATION, global_dc);
2272 handle_common_deferred_options ();
2276 initialize_plugins ();
2279 print_version (stderr, "");
2282 print_plugins_help (stderr, "");
2284 /* Exit early if we can (e.g. -help). */
2285 if (!exit_after_options)
2288 if (warningcount || errorcount)
2289 print_ignored_options ();
2290 diagnostic_finish (global_dc);
2292 /* Invoke registered plugin callbacks if any. */
2293 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2295 finalize_plugins ();
2297 return (FATAL_EXIT_CODE);
2299 return (SUCCESS_EXIT_CODE);