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
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. */
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
31 #include "coretypes.h"
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
50 #include "insn-attr.h"
51 #include "insn-config.h"
52 #include "insn-flags.h"
53 #include "hard-reg-set.h"
60 #include "basic-block.h"
66 #include "diagnostic.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
77 #include "hosthooks.h"
81 #include "value-prof.h"
82 #include "alloc-pool.h"
83 #include "tree-mudflap.h"
84 #include "tree-pass.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 setup_core_dumping (void);
113 static void compile_file (void);
115 /* Nonzero to dump debug info whilst parsing (-dy option). */
116 static int set_yydebug;
118 /* True if we don't need a backend (e.g. preprocessing only). */
119 static bool no_backend;
121 /* Length of line when printing switch values. */
124 /* Name of program invoked, sans directories. */
126 const char *progname;
128 /* Copy of argument vector to toplev_main. */
129 static const char **save_argv;
131 /* Name of top-level original source file (what was input to cpp).
132 This comes from the #-command at the beginning of the actual input.
133 If there isn't any there, then this is the cc1 input file name. */
135 const char *main_input_filename;
137 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
138 to optimize and default_debug_hooks in process_options (). */
139 #define AUTODETECT_VALUE 2
141 /* Current position in real source file. */
143 location_t input_location;
145 struct line_maps *line_table;
147 /* Name to use as base of names for dump output files. */
149 const char *dump_base_name;
151 /* Name to use as a base for auxiliary output files. */
153 const char *aux_base_name;
155 /* A mask of target_flags that includes bit X if X was set or cleared
156 on the command line. */
158 int target_flags_explicit;
160 /* Debug hooks - dependent upon command line options. */
162 const struct gcc_debug_hooks *debug_hooks;
164 /* Debug hooks - target default. */
166 static const struct gcc_debug_hooks *default_debug_hooks;
168 /* Other flags saying which kinds of debugging dump have been requested. */
170 int rtl_dump_and_exit;
171 int flag_print_asm_name;
172 enum graph_dump_types graph_dump_format;
174 /* Name for output file of assembly code, specified with -o. */
176 const char *asm_file_name;
178 /* Nonzero means do optimizations. -O.
179 Particular numeric values stand for particular amounts of optimization;
180 thus, -O2 stores 2 here. However, the optimizations beyond the basic
181 ones are not controlled directly by this variable. Instead, they are
182 controlled by individual `flag_...' variables that are defaulted
183 based on this variable. */
187 /* Nonzero means optimize for size. -Os.
188 The only valid values are zero and nonzero. When optimize_size is
189 nonzero, optimize defaults to 2, but certain individual code
190 bloating optimizations are disabled. */
192 int optimize_size = 0;
194 /* The FUNCTION_DECL for the function currently being compiled,
195 or 0 if between functions. */
196 tree current_function_decl;
198 /* Set to the FUNC_BEGIN label of the current function, or NULL
200 const char * current_function_func_begin_label;
202 /* Temporarily suppress certain warnings.
203 This is set while reading code from a system header file. */
205 int in_system_header = 0;
207 /* Nonzero means to collect statistics which might be expensive
208 and to print them when we are done. */
209 int flag_detailed_statistics = 0;
211 /* A random sequence of characters, unless overridden by user. */
212 static const char *flag_random_seed;
214 /* A local time stamp derived from the time of compilation. It will be
215 zero if the system cannot provide a time. It will be -1u, if the
216 user has specified a particular random seed. */
221 /* Nonzero means `char' should be signed. */
223 int flag_signed_char;
225 /* Nonzero means give an enum type only as many bytes as it needs. A value
226 of 2 means it has not yet been initialized. */
228 int flag_short_enums;
230 /* Nonzero if structures and unions should be returned in memory.
232 This should only be defined if compatibility with another compiler or
233 with an ABI is needed, because it results in slower code. */
235 #ifndef DEFAULT_PCC_STRUCT_RETURN
236 #define DEFAULT_PCC_STRUCT_RETURN 1
239 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
241 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
243 /* 0 means straightforward implementation of complex divide acceptable.
244 1 means wide ranges of inputs must work for complex divide.
245 2 means C99-like requirements for complex multiply and divide. */
247 int flag_complex_method = 1;
249 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
250 not just because the tree inliner turned us off. */
252 int flag_really_no_inline = 2;
254 /* Nonzero means we should be saving declaration info into a .X file. */
256 int flag_gen_aux_info = 0;
258 /* Specified name of aux-info file. */
260 const char *aux_info_file_name;
262 /* Nonzero if we are compiling code for a shared library, zero for
267 /* Generate code for GNU or NeXT Objective-C runtime environment. */
269 #ifdef NEXT_OBJC_RUNTIME
270 int flag_next_runtime = 1;
272 int flag_next_runtime = 0;
275 /* Set to the default thread-local storage (tls) model to use. */
277 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
279 /* Nonzero means change certain warnings into errors.
280 Usually these are warnings about failure to conform to some standard. */
282 int flag_pedantic_errors = 0;
284 /* -dA causes debug commentary information to be produced in
285 the generated assembly code (to make it more readable). This option
286 is generally only of use to those who actually need to read the
287 generated assembly code (perhaps while debugging the compiler itself).
288 Currently, this switch is only used by dwarfout.c; however, it is intended
289 to be a catchall for printing debug information in the assembler file. */
291 int flag_debug_asm = 0;
293 /* -dP causes the rtl to be emitted as a comment in assembly. */
295 int flag_dump_rtl_in_asm = 0;
297 /* When non-NULL, indicates that whenever space is allocated on the
298 stack, the resulting stack pointer must not pass this
299 address---that is, for stacks that grow downward, the stack pointer
300 must always be greater than or equal to this address; for stacks
301 that grow upward, the stack pointer must be less than this address.
302 At present, the rtx may be either a REG or a SYMBOL_REF, although
303 the support provided depends on the backend. */
306 /* Nonzero if we should track variables. When
307 flag_var_tracking == AUTODETECT_VALUE it will be set according
308 to optimize, debug_info_level and debug_hooks in process_options (). */
309 int flag_var_tracking = AUTODETECT_VALUE;
311 /* True if the user has tagged the function with the 'section'
314 bool user_defined_section_attribute = false;
316 /* Values of the -falign-* flags: how much to align labels in code.
317 0 means `use default', 1 means `don't align'.
318 For each variable, there is an _log variant which is the power
319 of two not less than the variable, for .align output. */
322 int align_loops_max_skip;
324 int align_jumps_max_skip;
325 int align_labels_log;
326 int align_labels_max_skip;
327 int align_functions_log;
331 const char *const string;
335 lang_independent_options;
337 /* Nonzero if subexpressions must be evaluated from left-to-right. */
338 int flag_evaluation_order = 0;
340 /* The user symbol prefix after having resolved same. */
341 const char *user_label_prefix;
343 static const param_info lang_independent_params[] = {
344 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
345 { OPTION, DEFAULT, false, MIN, MAX, HELP },
346 #include "params.def"
348 { NULL, 0, false, 0, 0, NULL }
351 /* Output files for assembler code (real compiler output)
352 and debugging dumps. */
356 FILE *dump_file = NULL;
357 const char *dump_file_name;
359 /* The current working directory of a translation. It's generally the
360 directory from which compilation was initiated, but a preprocessed
361 file may specify the original directory in which it was
364 static const char *src_pwd;
366 /* Initialize src_pwd with the given string, and return true. If it
367 was already initialized, return false. As a special case, it may
368 be called with a NULL argument to test whether src_pwd has NOT been
372 set_src_pwd (const char *pwd)
376 if (strcmp (src_pwd, pwd) == 0)
382 src_pwd = xstrdup (pwd);
386 /* Return the directory from which the translation unit was initiated,
387 in case set_src_pwd() was not called before to assign it a
403 /* Called when the start of a function definition is parsed,
404 this function prints on stderr the name of the function. */
406 announce_function (tree decl)
410 if (rtl_dump_and_exit)
411 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
413 fprintf (stderr, " %s", lang_hooks.decl_printable_name (decl, 2));
415 pp_needs_newline (global_dc->printer) = true;
416 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
420 /* Initialize local_tick with the time of day, or -1 if
421 flag_random_seed is set. */
424 init_local_tick (void)
426 if (!flag_random_seed)
428 /* Get some more or less random data. */
429 #ifdef HAVE_GETTIMEOFDAY
433 gettimeofday (&tv, NULL);
434 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
438 time_t now = time (NULL);
440 if (now != (time_t)-1)
441 local_tick = (unsigned) now;
449 /* Set up a default flag_random_seed and local_tick, unless the user
450 already specified one. Must be called after init_local_tick. */
453 init_random_seed (void)
455 unsigned HOST_WIDE_INT value;
456 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
458 value = local_tick ^ getpid ();
460 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
461 flag_random_seed = random_seed;
464 /* Obtain the random_seed string. Unless NOINIT, initialize it if
465 it's not provided in the command line. */
468 get_random_seed (bool noinit)
470 if (!flag_random_seed && !noinit)
472 return flag_random_seed;
475 /* Modify the random_seed string to VAL. Return its previous
479 set_random_seed (const char *val)
481 const char *old = flag_random_seed;
482 flag_random_seed = val;
486 /* Decode the string P as an integral parameter.
487 If the string is indeed an integer return its numeric value else
488 issue an Invalid Option error for the option PNAME and return DEFVAL.
489 If PNAME is zero just return DEFVAL, do not call error. */
492 read_integral_parameter (const char *p, const char *pname, const int defval)
494 const char *endp = p;
507 error ("invalid option argument %qs", pname);
514 /* When compiling with a recent enough GCC, we use the GNU C "extern inline"
515 for floor_log2 and exact_log2; see toplev.h. That construct, however,
516 conflicts with the ISO C++ One Definition Rule. */
518 #if GCC_VERSION < 3004 || !defined (__cplusplus)
520 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
521 If X is 0, return -1. */
524 floor_log2 (unsigned HOST_WIDE_INT x)
532 t = HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x);
534 if (HOST_BITS_PER_WIDE_INT > 64)
535 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
537 if (HOST_BITS_PER_WIDE_INT > 32)
538 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
540 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
542 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
544 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
546 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
548 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
555 /* Return the logarithm of X, base 2, considering X unsigned,
556 if X is a power of 2. Otherwise, returns -1. */
559 exact_log2 (unsigned HOST_WIDE_INT x)
564 return x ? CTZ_HWI (x) : -1;
566 return floor_log2 (x);
570 #endif /* GCC_VERSION < 3004 || !defined (__cplusplus) */
572 /* Handler for fatal signals, such as SIGSEGV. These are transformed
573 into ICE messages, which is much more user friendly. In case the
574 error printer crashes, reset the signal to prevent infinite recursion. */
577 crash_signal (int signo)
579 signal (signo, SIG_DFL);
581 /* If we crashed while processing an ASM statement, then be a little more
582 graceful. It's most likely the user's fault. */
583 if (this_is_asm_operands)
585 output_operand_lossage ("unrecoverable error");
586 exit (FATAL_EXIT_CODE);
589 internal_error ("%s", strsignal (signo));
592 /* Arrange to dump core on error. (The regular error message is still
593 printed first, except in the case of abort().) */
596 setup_core_dumping (void)
599 signal (SIGABRT, SIG_DFL);
601 #if defined(HAVE_SETRLIMIT)
604 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
605 fatal_error ("getting core file size maximum limit: %m");
606 rlim.rlim_cur = rlim.rlim_max;
607 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
608 fatal_error ("setting core file size limit to maximum: %m");
611 diagnostic_abort_on_error (global_dc);
615 /* Strip off a legitimate source ending from the input string NAME of
616 length LEN. Rather than having to know the names used by all of
617 our front ends, we strip off an ending of a period followed by
618 up to five characters. (Java uses ".class".) */
621 strip_off_ending (char *name, int len)
624 for (i = 2; i < 6 && len > i; i++)
626 if (name[len - i] == '.')
628 name[len - i] = '\0';
634 /* Output a quoted string. */
637 output_quoted_string (FILE *asm_file, const char *string)
639 #ifdef OUTPUT_QUOTED_STRING
640 OUTPUT_QUOTED_STRING (asm_file, string);
644 putc ('\"', asm_file);
645 while ((c = *string++) != 0)
649 if (c == '\"' || c == '\\')
650 putc ('\\', asm_file);
654 fprintf (asm_file, "\\%03o", (unsigned char) c);
656 putc ('\"', asm_file);
660 /* Output a file name in the form wanted by System V. */
663 output_file_directive (FILE *asm_file, const char *input_name)
668 if (input_name == NULL)
669 input_name = "<stdin>";
671 input_name = remap_debug_filename (input_name);
673 len = strlen (input_name);
674 na = input_name + len;
676 /* NA gets INPUT_NAME sans directory names. */
677 while (na > input_name)
679 if (IS_DIR_SEPARATOR (na[-1]))
684 #ifdef ASM_OUTPUT_SOURCE_FILENAME
685 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
687 fprintf (asm_file, "\t.file\t");
688 output_quoted_string (asm_file, na);
689 fputc ('\n', asm_file);
693 /* A subroutine of wrapup_global_declarations. We've come to the end of
694 the compilation unit. All deferred variables should be undeferred,
695 and all incomplete decls should be finalized. */
698 wrapup_global_declaration_1 (tree decl)
700 /* We're not deferring this any longer. Assignment is conditional to
701 avoid needlessly dirtying PCH pages. */
702 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
703 && DECL_DEFER_OUTPUT (decl) != 0)
704 DECL_DEFER_OUTPUT (decl) = 0;
706 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
707 lang_hooks.finish_incomplete_decl (decl);
710 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
711 needs to be output. Return true if it is output. */
714 wrapup_global_declaration_2 (tree decl)
716 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
719 /* Don't write out static consts, unless we still need them.
721 We also keep static consts if not optimizing (for debugging),
722 unless the user specified -fno-keep-static-consts.
723 ??? They might be better written into the debug information.
724 This is possible when using DWARF.
726 A language processor that wants static constants to be always
727 written out (even if it is not used) is responsible for
728 calling rest_of_decl_compilation itself. E.g. the C front-end
729 calls rest_of_decl_compilation from finish_decl.
730 One motivation for this is that is conventional in some
731 environments to write things like:
732 static const char rcsid[] = "... version string ...";
733 intending to force the string to be in the executable.
735 A language processor that would prefer to have unneeded
736 static constants "optimized away" would just defer writing
737 them out until here. E.g. C++ does this, because static
738 constants are often defined in header files.
740 ??? A tempting alternative (for both C and C++) would be
741 to force a constant to be written if and only if it is
742 defined in a main file, as opposed to an include file. */
744 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
746 struct varpool_node *node;
748 node = varpool_node (decl);
752 else if (node->alias)
754 else if (!cgraph_global_info_ready
756 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
758 else if (node->needed)
760 else if (DECL_COMDAT (decl))
762 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
763 && (optimize || !flag_keep_static_consts
764 || DECL_ARTIFICIAL (decl)))
769 rest_of_decl_compilation (decl, 1, 1);
777 /* Do any final processing required for the declarations in VEC, of
778 which there are LEN. We write out inline functions and variables
779 that have been deferred until this point, but which are required.
780 Returns nonzero if anything was put out. */
783 wrapup_global_declarations (tree *vec, int len)
785 bool reconsider, output_something = false;
788 for (i = 0; i < len; i++)
789 wrapup_global_declaration_1 (vec[i]);
791 /* Now emit any global variables or functions that we have been
792 putting off. We need to loop in case one of the things emitted
793 here references another one which comes earlier in the list. */
797 for (i = 0; i < len; i++)
798 reconsider |= wrapup_global_declaration_2 (vec[i]);
800 output_something = true;
804 return output_something;
807 /* A subroutine of check_global_declarations. Issue appropriate warnings
808 for the global declaration DECL. */
811 check_global_declaration_1 (tree decl)
813 /* Warn about any function declared static but not defined. We don't
814 warn about variables, because many programs have static variables
815 that exist only to get some text into the object file. */
816 if (TREE_CODE (decl) == FUNCTION_DECL
817 && DECL_INITIAL (decl) == 0
818 && DECL_EXTERNAL (decl)
819 && ! DECL_ARTIFICIAL (decl)
820 && ! TREE_NO_WARNING (decl)
821 && ! TREE_PUBLIC (decl)
822 && (warn_unused_function
823 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
825 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
826 pedwarn ("%q+F used but never defined", decl);
828 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
829 /* This symbol is effectively an "extern" declaration now. */
830 TREE_PUBLIC (decl) = 1;
831 assemble_external (decl);
834 /* Warn about static fns or vars defined but not used. */
835 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
836 /* We don't warn about "static const" variables because the
837 "rcs_id" idiom uses that construction. */
838 || (warn_unused_variable
839 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
840 && ! DECL_IN_SYSTEM_HEADER (decl)
841 && ! TREE_USED (decl)
842 /* The TREE_USED bit for file-scope decls is kept in the identifier,
843 to handle multiple external decls in different scopes. */
844 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
845 && ! DECL_EXTERNAL (decl)
846 && ! TREE_PUBLIC (decl)
847 /* A volatile variable might be used in some non-obvious way. */
848 && ! TREE_THIS_VOLATILE (decl)
849 /* Global register variables must be declared to reserve them. */
850 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
851 /* Otherwise, ask the language. */
852 && lang_hooks.decls.warn_unused_global (decl))
853 warning ((TREE_CODE (decl) == FUNCTION_DECL)
854 ? OPT_Wunused_function
855 : OPT_Wunused_variable,
856 "%q+D defined but not used", decl);
859 /* Issue appropriate warnings for the global declarations in VEC (of
860 which there are LEN). */
863 check_global_declarations (tree *vec, int len)
867 for (i = 0; i < len; i++)
868 check_global_declaration_1 (vec[i]);
871 /* Emit debugging information for all global declarations in VEC. */
874 emit_debug_global_declarations (tree *vec, int len)
878 /* Avoid confusing the debug information machinery when there are errors. */
879 if (errorcount != 0 || sorrycount != 0)
882 timevar_push (TV_SYMOUT);
883 for (i = 0; i < len; i++)
884 debug_hooks->global_decl (vec[i]);
885 timevar_pop (TV_SYMOUT);
888 /* Warn about a use of an identifier which was marked deprecated. */
890 warn_deprecated_use (tree node)
892 if (node == 0 || !warn_deprecated_decl)
897 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
898 warning (OPT_Wdeprecated_declarations,
899 "%qD is deprecated (declared at %s:%d)",
900 node, xloc.file, xloc.line);
902 else if (TYPE_P (node))
904 const char *what = NULL;
905 tree decl = TYPE_STUB_DECL (node);
907 if (TYPE_NAME (node))
909 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
910 what = IDENTIFIER_POINTER (TYPE_NAME (node));
911 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
912 && DECL_NAME (TYPE_NAME (node)))
913 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
918 expanded_location xloc
919 = expand_location (DECL_SOURCE_LOCATION (decl));
921 warning (OPT_Wdeprecated_declarations,
922 "%qs is deprecated (declared at %s:%d)", what,
923 xloc.file, xloc.line);
925 warning (OPT_Wdeprecated_declarations,
926 "type is deprecated (declared at %s:%d)",
927 xloc.file, xloc.line);
932 warning (OPT_Wdeprecated_declarations, "%qs is deprecated", what);
934 warning (OPT_Wdeprecated_declarations, "type is deprecated");
939 /* Compile an entire translation unit. Write a file of assembly
940 output and various debugging dumps. */
945 /* Initialize yet another pass. */
948 init_final (main_input_filename);
949 coverage_init (aux_base_name);
951 timevar_push (TV_PARSE);
953 /* Call the parser, which parses the entire file (calling
954 rest_of_compilation for each function). */
955 lang_hooks.parse_file (set_yydebug);
957 /* In case there were missing block closers,
958 get us back to the global binding level. */
959 lang_hooks.clear_binding_stack ();
961 /* Compilation is now finished except for writing
962 what's left of the symbol table output. */
963 timevar_pop (TV_PARSE);
965 if (flag_syntax_only)
968 lang_hooks.decls.final_write_globals ();
970 if (errorcount || sorrycount)
973 varpool_assemble_pending_decls ();
976 /* This must occur after the loop to output deferred functions.
977 Else the coverage initializer would not be emitted if all the
978 functions in this compilation unit were deferred. */
981 /* Likewise for mudflap static object registrations. */
983 mudflap_finish_file ();
985 /* Likewise for emulated thread-local storage. */
986 if (!targetm.have_tls)
989 output_shared_constant_pool ();
990 output_object_blocks ();
992 /* Write out any pending weak symbol declarations. */
995 /* Do dbx symbols. */
996 timevar_push (TV_SYMOUT);
998 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
999 if (dwarf2out_do_frame ())
1000 dwarf2out_frame_finish ();
1003 (*debug_hooks->finish) (main_input_filename);
1004 timevar_pop (TV_SYMOUT);
1006 /* Output some stuff at end of file if nec. */
1008 dw2_output_indirect_constants ();
1010 /* Flush any pending external directives. */
1011 process_pending_assemble_externals ();
1013 /* Attach a special .ident directive to the end of the file to identify
1014 the version of GCC which compiled this code. The format of the .ident
1015 string is patterned after the ones produced by native SVR4 compilers. */
1019 const char *pkg_version = "(GNU) ";
1021 if (strcmp ("(GCC) ", pkgversion_string))
1022 pkg_version = pkgversion_string;
1023 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
1024 IDENT_ASM_OP, pkg_version, version_string);
1028 /* This must be at the end. Some target ports emit end of file directives
1029 into the assembly file here, and hence we can not output anything to the
1030 assembly file after this point. */
1031 targetm.asm_out.file_end ();
1034 /* Parse a -d... command line switch. */
1037 decode_d_option (const char *arg)
1048 flag_print_asm_name = 1;
1051 flag_dump_rtl_in_asm = 1;
1052 flag_print_asm_name = 1;
1055 graph_dump_format = vcg;
1058 rtl_dump_and_exit = 1;
1063 case 'D': /* These are handled by the preprocessor. */
1067 setup_core_dumping();
1072 if (!enable_rtl_dump_file (c))
1073 warning (0, "unrecognized gcc debugging option: %c", c);
1078 /* Indexed by enum debug_info_type. */
1079 const char *const debug_type_names[] =
1081 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1084 /* Print version information to FILE.
1085 Each line begins with INDENT (for the case where FILE is the
1086 assembler output file). */
1089 print_version (FILE *file, const char *indent)
1091 static const char fmt1[] =
1093 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1095 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1098 static const char fmt2[] =
1099 N_("GMP version %s, MPFR version %s.\n");
1100 static const char fmt3[] =
1101 N_("%s%swarning: %s header version %s differs from library version %s.\n");
1102 static const char fmt4[] =
1103 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1105 #define __VERSION__ "[?]"
1108 file == stderr ? _(fmt1) : fmt1,
1109 indent, *indent != 0 ? " " : "",
1110 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
1111 indent, __VERSION__);
1113 /* We need to stringify the GMP macro values. Ugh, gmp_version has
1114 two string formats, "i.j.k" and "i.j" when k is zero. */
1115 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1116 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1117 #if __GNU_MP_VERSION_PATCHLEVEL == 0
1118 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1119 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1121 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1122 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1123 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1126 file == stderr ? _(fmt2) : fmt2,
1127 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING);
1128 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
1130 file == stderr ? _(fmt3) : fmt3,
1131 indent, *indent != 0 ? " " : "",
1132 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
1133 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
1135 file == stderr ? _(fmt3) : fmt3,
1136 indent, *indent != 0 ? " " : "",
1137 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
1139 file == stderr ? _(fmt4) : fmt4,
1140 indent, *indent != 0 ? " " : "",
1141 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1144 #ifdef ASM_COMMENT_START
1146 print_to_asm_out_file (print_switch_type type, const char * text)
1148 bool prepend_sep = true;
1152 case SWITCH_TYPE_LINE_END:
1153 putc ('\n', asm_out_file);
1156 case SWITCH_TYPE_LINE_START:
1157 fputs (ASM_COMMENT_START, asm_out_file);
1158 return strlen (ASM_COMMENT_START);
1160 case SWITCH_TYPE_DESCRIPTIVE:
1161 if (ASM_COMMENT_START[0] == 0)
1162 prepend_sep = false;
1164 case SWITCH_TYPE_PASSED:
1165 case SWITCH_TYPE_ENABLED:
1167 fputc (' ', asm_out_file);
1168 fprintf (asm_out_file, text);
1169 /* No need to return the length here as
1170 print_single_switch has already done it. */
1180 print_to_stderr (print_switch_type type, const char * text)
1184 case SWITCH_TYPE_LINE_END:
1185 putc ('\n', stderr);
1188 case SWITCH_TYPE_LINE_START:
1191 case SWITCH_TYPE_PASSED:
1192 case SWITCH_TYPE_ENABLED:
1193 fputc (' ', stderr);
1196 case SWITCH_TYPE_DESCRIPTIVE:
1197 fprintf (stderr, text);
1198 /* No need to return the length here as
1199 print_single_switch has already done it. */
1207 /* Print an option value and return the adjusted position in the line.
1208 ??? print_fn doesn't handle errors, eg disk full; presumably other
1209 code will catch a disk full though. */
1212 print_single_switch (print_switch_fn_type print_fn,
1214 print_switch_type type,
1217 /* The ultrix fprintf returns 0 on success, so compute the result
1218 we want here since we need it for the following test. The +1
1219 is for the separator character that will probably be emitted. */
1220 int len = strlen (text) + 1;
1223 && pos + len > MAX_LINE)
1225 print_fn (SWITCH_TYPE_LINE_END, NULL);
1230 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1232 print_fn (type, text);
1236 /* Print active target switches using PRINT_FN.
1237 POS is the current cursor position and MAX is the size of a "line".
1238 Each line begins with INDENT and ends with TERM.
1239 Each switch is separated from the next by SEP. */
1242 print_switch_values (print_switch_fn_type print_fn)
1248 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1249 that it can be printed below. This helps reproducibility. */
1250 if (!flag_random_seed)
1251 init_random_seed ();
1253 /* Print the options as passed. */
1254 pos = print_single_switch (print_fn, pos,
1255 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1257 for (p = &save_argv[1]; *p != NULL; p++)
1262 if (strcmp (*p, "-o") == 0
1263 || strcmp (*p, "-dumpbase") == 0
1264 || strcmp (*p, "-auxbase") == 0)
1271 if (strcmp (*p, "-quiet") == 0
1272 || strcmp (*p, "-version") == 0)
1279 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED, *p);
1283 print_fn (SWITCH_TYPE_LINE_END, NULL);
1285 /* Print the -f and -m options that have been enabled.
1286 We don't handle language specific options but printing argv
1288 pos = print_single_switch (print_fn, 0,
1289 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1291 for (j = 0; j < cl_options_count; j++)
1292 if ((cl_options[j].flags & CL_REPORT)
1293 && option_enabled (j) > 0)
1294 pos = print_single_switch (print_fn, pos,
1295 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1297 print_fn (SWITCH_TYPE_LINE_END, NULL);
1300 /* Open assembly code output file. Do this even if -fsyntax-only is
1301 on, because then the driver will have provided the name of a
1302 temporary file or bit bucket for us. NAME is the file specified on
1303 the command line, possibly NULL. */
1305 init_asm_output (const char *name)
1307 if (name == NULL && asm_file_name == 0)
1308 asm_out_file = stdout;
1311 if (asm_file_name == 0)
1313 int len = strlen (dump_base_name);
1314 char *dumpname = XNEWVEC (char, len + 6);
1316 memcpy (dumpname, dump_base_name, len + 1);
1317 strip_off_ending (dumpname, len);
1318 strcat (dumpname, ".s");
1319 asm_file_name = dumpname;
1321 if (!strcmp (asm_file_name, "-"))
1322 asm_out_file = stdout;
1324 asm_out_file = fopen (asm_file_name, "w+b");
1325 if (asm_out_file == 0)
1326 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1329 if (!flag_syntax_only)
1331 targetm.asm_out.file_start ();
1333 if (flag_record_gcc_switches)
1335 if (targetm.asm_out.record_gcc_switches)
1337 /* Let the target know that we are about to start recording. */
1338 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1340 /* Now record the switches. */
1341 print_switch_values (targetm.asm_out.record_gcc_switches);
1342 /* Let the target know that the recording is over. */
1343 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1347 inform ("-frecord-gcc-switches is not supported by the current target");
1350 #ifdef ASM_COMMENT_START
1351 if (flag_verbose_asm)
1353 /* Print the list of switches in effect
1354 into the assembler file as comments. */
1355 print_version (asm_out_file, ASM_COMMENT_START);
1356 print_switch_values (print_to_asm_out_file);
1357 fprintf (asm_out_file, "\n");
1363 /* Return true if the state of option OPTION should be stored in PCH files
1364 and checked by default_pch_valid_p. Store the option's current state
1368 option_affects_pch_p (int option, struct cl_option_state *state)
1370 if ((cl_options[option].flags & CL_TARGET) == 0)
1372 if (cl_options[option].flag_var == &target_flags)
1373 if (targetm.check_pch_target_flags)
1375 return get_option_state (option, state);
1378 /* Default version of get_pch_validity.
1379 By default, every flag difference is fatal; that will be mostly right for
1380 most targets, but completely right for very few. */
1383 default_get_pch_validity (size_t *len)
1385 struct cl_option_state state;
1390 if (targetm.check_pch_target_flags)
1391 *len += sizeof (target_flags);
1392 for (i = 0; i < cl_options_count; i++)
1393 if (option_affects_pch_p (i, &state))
1396 result = r = XNEWVEC (char, *len);
1400 if (targetm.check_pch_target_flags)
1402 memcpy (r, &target_flags, sizeof (target_flags));
1403 r += sizeof (target_flags);
1406 for (i = 0; i < cl_options_count; i++)
1407 if (option_affects_pch_p (i, &state))
1409 memcpy (r, state.data, state.size);
1416 /* Return a message which says that a PCH file was created with a different
1417 setting of OPTION. */
1420 pch_option_mismatch (const char *option)
1424 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1426 return _("out of memory");
1430 /* Default version of pch_valid_p. */
1433 default_pch_valid_p (const void *data_p, size_t len)
1435 struct cl_option_state state;
1436 const char *data = (const char *)data_p;
1439 /* -fpic and -fpie also usually make a PCH invalid. */
1440 if (data[0] != flag_pic)
1441 return _("created and used with different settings of -fpic");
1442 if (data[1] != flag_pie)
1443 return _("created and used with different settings of -fpie");
1446 /* Check target_flags. */
1447 if (targetm.check_pch_target_flags)
1452 memcpy (&tf, data, sizeof (target_flags));
1453 data += sizeof (target_flags);
1454 len -= sizeof (target_flags);
1455 r = targetm.check_pch_target_flags (tf);
1460 for (i = 0; i < cl_options_count; i++)
1461 if (option_affects_pch_p (i, &state))
1463 if (memcmp (data, state.data, state.size) != 0)
1464 return pch_option_mismatch (cl_options[i].opt_text);
1472 /* Default tree printer. Handles declarations only. */
1474 default_tree_printer (pretty_printer * pp, text_info *text, const char *spec,
1475 int precision, bool wide, bool set_locus, bool hash)
1479 /* FUTURE: %+x should set the locus. */
1480 if (precision != 0 || wide || hash)
1486 t = va_arg (*text->args_ptr, tree);
1487 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1488 t = DECL_DEBUG_EXPR (t);
1493 t = va_arg (*text->args_ptr, tree);
1500 if (set_locus && text->locus)
1501 *text->locus = DECL_SOURCE_LOCATION (t);
1505 const char *n = DECL_NAME (t)
1506 ? lang_hooks.decl_printable_name (t, 2)
1511 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1516 /* A helper function; used as the reallocator function for cpp's line
1519 realloc_for_line_map (void *ptr, size_t len)
1521 return ggc_realloc (ptr, len);
1524 /* Initialization of the front end environment, before command line
1525 options are parsed. Signal handlers, internationalization etc.
1526 ARGV0 is main's argv[0]. */
1528 general_init (const char *argv0)
1532 p = argv0 + strlen (argv0);
1533 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1537 xmalloc_set_program_name (progname);
1541 /* Unlock the stdio streams. */
1542 unlock_std_streams ();
1544 gcc_init_libintl ();
1546 /* Initialize the diagnostics reporting machinery, so option parsing
1547 can give warnings and errors. */
1548 diagnostic_initialize (global_dc);
1549 /* Set a default printer. Language specific initializations will
1550 override it later. */
1551 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1553 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1555 signal (SIGSEGV, crash_signal);
1558 signal (SIGILL, crash_signal);
1561 signal (SIGBUS, crash_signal);
1564 signal (SIGABRT, crash_signal);
1566 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1567 signal (SIGIOT, crash_signal);
1570 signal (SIGFPE, crash_signal);
1573 /* Other host-specific signal setup. */
1574 (*host_hooks.extra_signals)();
1576 /* Initialize the garbage-collector, string pools and tree type hash
1580 line_table = GGC_NEW (struct line_maps);
1581 linemap_init (line_table);
1582 line_table->reallocator = realloc_for_line_map;
1585 /* Initialize register usage now so switches may override. */
1588 /* Register the language-independent parameters. */
1589 add_params (lang_independent_params, LAST_PARAM);
1591 /* This must be done after add_params but before argument processing. */
1592 init_ggc_heuristics();
1593 init_optimization_passes ();
1596 /* Return true if the current target supports -fsection-anchors. */
1599 target_supports_section_anchors_p (void)
1601 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1604 if (targetm.asm_out.output_anchor == NULL)
1610 /* Default the align_* variables to 1 if they're still unset, and
1611 set up the align_*_log variables. */
1613 init_alignments (void)
1615 if (align_loops <= 0)
1617 if (align_loops_max_skip > align_loops)
1618 align_loops_max_skip = align_loops - 1;
1619 align_loops_log = floor_log2 (align_loops * 2 - 1);
1620 if (align_jumps <= 0)
1622 if (align_jumps_max_skip > align_jumps)
1623 align_jumps_max_skip = align_jumps - 1;
1624 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1625 if (align_labels <= 0)
1627 align_labels_log = floor_log2 (align_labels * 2 - 1);
1628 if (align_labels_max_skip > align_labels)
1629 align_labels_max_skip = align_labels - 1;
1630 if (align_functions <= 0)
1631 align_functions = 1;
1632 align_functions_log = floor_log2 (align_functions * 2 - 1);
1635 /* Process the options that have been parsed. */
1637 process_options (void)
1639 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1640 This can happen with incorrect pre-processed input. */
1641 debug_hooks = &do_nothing_debug_hooks;
1643 /* Allow the front end to perform consistency checks and do further
1644 initialization based on the command line options. This hook also
1645 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1646 so we can correctly initialize debug output. */
1647 no_backend = lang_hooks.post_options (&main_input_filename);
1649 #ifdef OVERRIDE_OPTIONS
1650 /* Some machines may reject certain combinations of options. */
1654 if (flag_section_anchors && !target_supports_section_anchors_p ())
1656 warning (OPT_fsection_anchors,
1657 "this target does not support %qs", "-fsection-anchors");
1658 flag_section_anchors = 0;
1661 if (flag_short_enums == 2)
1662 flag_short_enums = targetm.default_short_enums ();
1664 /* Set aux_base_name if not already set. */
1667 else if (main_input_filename)
1669 char *name = xstrdup (lbasename (main_input_filename));
1671 strip_off_ending (name, strlen (name));
1672 aux_base_name = name;
1675 aux_base_name = "gccaux";
1677 /* Unrolling all loops implies that standard loop unrolling must also
1679 if (flag_unroll_all_loops)
1680 flag_unroll_loops = 1;
1682 /* The loop unrolling code assumes that cse will be run after loop.
1683 web and rename-registers also help when run after loop unrolling. */
1685 if (flag_rerun_cse_after_loop == AUTODETECT_VALUE)
1686 flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops;
1687 if (flag_web == AUTODETECT_VALUE)
1688 flag_web = flag_unroll_loops || flag_peel_loops;
1689 if (flag_rename_registers == AUTODETECT_VALUE)
1690 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1692 if (flag_non_call_exceptions)
1693 flag_asynchronous_unwind_tables = 1;
1694 if (flag_asynchronous_unwind_tables)
1695 flag_unwind_tables = 1;
1697 if (!flag_unit_at_a_time)
1698 flag_section_anchors = 0;
1700 if (flag_value_profile_transformations)
1701 flag_profile_values = 1;
1703 /* Warn about options that are not supported on this machine. */
1704 #ifndef INSN_SCHEDULING
1705 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1706 warning (0, "instruction scheduling not supported on this target machine");
1709 if (flag_delayed_branch)
1710 warning (0, "this target machine does not have delayed branches");
1713 user_label_prefix = USER_LABEL_PREFIX;
1714 if (flag_leading_underscore != -1)
1716 /* If the default prefix is more complicated than "" or "_",
1717 issue a warning and ignore this option. */
1718 if (user_label_prefix[0] == 0 ||
1719 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1721 user_label_prefix = flag_leading_underscore ? "_" : "";
1724 warning (0, "-f%sleading-underscore not supported on this target machine",
1725 flag_leading_underscore ? "" : "no-");
1728 /* If we are in verbose mode, write out the version and maybe all the
1729 option flags in use. */
1732 print_version (stderr, "");
1734 print_switch_values (print_to_stderr);
1737 if (flag_syntax_only)
1739 write_symbols = NO_DEBUG;
1743 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1745 if (debug_info_level == DINFO_LEVEL_NONE)
1746 write_symbols = NO_DEBUG;
1748 /* Now we know write_symbols, set up the debug hooks based on it.
1749 By default we do nothing for debug output. */
1750 if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG)
1751 default_debug_hooks = &do_nothing_debug_hooks;
1752 #if defined(DBX_DEBUGGING_INFO)
1753 else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG)
1754 default_debug_hooks = &dbx_debug_hooks;
1756 #if defined(XCOFF_DEBUGGING_INFO)
1757 else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG)
1758 default_debug_hooks = &xcoff_debug_hooks;
1760 #ifdef SDB_DEBUGGING_INFO
1761 else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG)
1762 default_debug_hooks = &sdb_debug_hooks;
1764 #ifdef DWARF2_DEBUGGING_INFO
1765 else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG)
1766 default_debug_hooks = &dwarf2_debug_hooks;
1768 #ifdef VMS_DEBUGGING_INFO
1769 else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG
1770 || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG)
1771 default_debug_hooks = &vmsdbg_debug_hooks;
1774 if (write_symbols == NO_DEBUG)
1776 #if defined(DBX_DEBUGGING_INFO)
1777 else if (write_symbols == DBX_DEBUG)
1778 debug_hooks = &dbx_debug_hooks;
1780 #if defined(XCOFF_DEBUGGING_INFO)
1781 else if (write_symbols == XCOFF_DEBUG)
1782 debug_hooks = &xcoff_debug_hooks;
1784 #ifdef SDB_DEBUGGING_INFO
1785 else if (write_symbols == SDB_DEBUG)
1786 debug_hooks = &sdb_debug_hooks;
1788 #ifdef DWARF2_DEBUGGING_INFO
1789 else if (write_symbols == DWARF2_DEBUG)
1790 debug_hooks = &dwarf2_debug_hooks;
1792 #ifdef VMS_DEBUGGING_INFO
1793 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1794 debug_hooks = &vmsdbg_debug_hooks;
1797 error ("target system does not support the \"%s\" debug format",
1798 debug_type_names[write_symbols]);
1800 /* Now we know which debug output will be used so we can set
1801 flag_var_tracking, flag_rename_registers if the user has
1802 not specified them. */
1803 if (debug_info_level < DINFO_LEVEL_NORMAL
1804 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1806 if (flag_var_tracking == 1
1807 || flag_var_tracking_uninit == 1)
1809 if (debug_info_level < DINFO_LEVEL_NORMAL)
1810 warning (0, "variable tracking requested, but useless unless "
1811 "producing debug info");
1813 warning (0, "variable tracking requested, but not supported "
1814 "by this debug format");
1816 flag_var_tracking = 0;
1817 flag_var_tracking_uninit = 0;
1820 if (flag_rename_registers == AUTODETECT_VALUE)
1821 flag_rename_registers = default_debug_hooks->var_location
1822 != do_nothing_debug_hooks.var_location;
1824 if (flag_var_tracking == AUTODETECT_VALUE)
1825 flag_var_tracking = optimize >= 1;
1827 if (flag_tree_cselim == AUTODETECT_VALUE)
1828 #ifdef HAVE_conditional_move
1829 flag_tree_cselim = 1;
1831 flag_tree_cselim = 0;
1834 /* If the user specifically requested variable tracking with tagging
1835 uninitialized variables, we need to turn on variable tracking.
1836 (We already determined above that variable tracking is feasible.) */
1837 if (flag_var_tracking_uninit)
1838 flag_var_tracking = 1;
1840 /* If auxiliary info generation is desired, open the output file.
1841 This goes in the same directory as the source file--unlike
1842 all the other output files. */
1843 if (flag_gen_aux_info)
1845 aux_info_file = fopen (aux_info_file_name, "w");
1846 if (aux_info_file == 0)
1847 fatal_error ("can%'t open %s: %m", aux_info_file_name);
1850 if (! targetm.have_named_sections)
1852 if (flag_function_sections)
1854 warning (0, "-ffunction-sections not supported for this target");
1855 flag_function_sections = 0;
1857 if (flag_data_sections)
1859 warning (0, "-fdata-sections not supported for this target");
1860 flag_data_sections = 0;
1864 if (flag_function_sections && profile_flag)
1866 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
1867 flag_function_sections = 0;
1870 #ifndef HAVE_prefetch
1871 if (flag_prefetch_loop_arrays)
1873 warning (0, "-fprefetch-loop-arrays not supported for this target");
1874 flag_prefetch_loop_arrays = 0;
1877 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
1879 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
1880 flag_prefetch_loop_arrays = 0;
1884 /* This combination of options isn't handled for i386 targets and doesn't
1885 make much sense anyway, so don't allow it. */
1886 if (flag_prefetch_loop_arrays && optimize_size)
1888 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
1889 flag_prefetch_loop_arrays = 0;
1892 #ifndef OBJECT_FORMAT_ELF
1893 #ifndef OBJECT_FORMAT_MACHO
1894 if (flag_function_sections && write_symbols != NO_DEBUG)
1895 warning (0, "-ffunction-sections may affect debugging on some targets");
1899 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1900 if (flag_signaling_nans)
1901 flag_trapping_math = 1;
1903 /* We cannot reassociate if we want traps or signed zeros. Â */
1904 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1906 warning (0, "-fassociative-math disabled; other options take precedence");
1907 flag_associative_math = 0;
1910 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1911 if (flag_cx_limited_range)
1912 flag_complex_method = 0;
1914 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1915 if (flag_cx_fortran_rules)
1916 flag_complex_method = 1;
1918 /* Targets must be able to place spill slots at lower addresses. If the
1919 target already uses a soft frame pointer, the transition is trivial. */
1920 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1922 warning (0, "-fstack-protector not supported for this target");
1923 flag_stack_protect = 0;
1925 if (!flag_stack_protect)
1926 warn_stack_protect = 0;
1928 /* ??? Unwind info is not correct around the CFG unless either a frame
1929 pointer is present or A_O_A is set. Fixing this requires rewriting
1930 unwind info generation to be aware of the CFG and propagating states
1932 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
1933 && flag_omit_frame_pointer)
1935 warning (0, "unwind tables currently require a frame pointer "
1937 flag_omit_frame_pointer = 0;
1941 /* This function can be called multiple times to reinitialize the compiler
1942 back end when register classes or instruction sets have changed,
1943 before each function. */
1945 backend_init_target (void)
1947 /* Initialize alignment variables. */
1950 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
1951 to initialize reg_raw_mode[]. */
1954 /* This invokes target hooks to set fixed_reg[] etc, which is
1958 /* This depends on stack_pointer_rtx. */
1959 init_fake_stack_mems ();
1961 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1963 init_alias_target ();
1965 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1968 /* The following initialization functions need to generate rtl, so
1969 provide a dummy function context for them. */
1970 init_dummy_function_start ();
1972 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1973 on a mode change. */
1976 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1977 after a mode change as well. */
1978 if (flag_caller_saves)
1979 init_caller_save ();
1980 expand_dummy_function_end ();
1983 /* Initialize the compiler back end. This function is called only once,
1984 when starting the compiler. */
1988 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
1989 || debug_info_level == DINFO_LEVEL_VERBOSE
1990 #ifdef VMS_DEBUGGING_INFO
1991 /* Enable line number info for traceback. */
1992 || debug_info_level > DINFO_LEVEL_NONE
1994 || flag_test_coverage);
1997 init_inline_once ();
1998 init_varasm_once ();
1999 save_register_info ();
2001 /* Initialize the target-specific back end pieces. */
2002 backend_init_target ();
2005 /* Initialize things that are both lang-dependent and target-dependent.
2006 This function can be called more than once if target parameters change. */
2008 lang_dependent_init_target (void)
2010 /* This creates various _DECL nodes, so needs to be called after the
2011 front end is initialized. It also depends on the HAVE_xxx macros
2012 generated from the target machine description. */
2015 /* The following initialization functions need to generate rtl, so
2016 provide a dummy function context for them. */
2017 init_dummy_function_start ();
2019 /* Do the target-specific parts of expr initialization. */
2020 init_expr_target ();
2022 /* Although the actions of init_set_costs are language-independent,
2023 it uses optabs, so we cannot call it from backend_init. */
2026 expand_dummy_function_end ();
2029 /* Language-dependent initialization. Returns nonzero on success. */
2031 lang_dependent_init (const char *name)
2033 location_t save_loc = input_location;
2034 if (dump_base_name == 0)
2035 dump_base_name = name && name[0] ? name : "gccdump";
2037 /* Other front-end initialization. */
2038 input_location = BUILTINS_LOCATION;
2039 if (lang_hooks.init () == 0)
2041 input_location = save_loc;
2043 init_asm_output (name);
2045 /* This creates various _DECL nodes, so needs to be called after the
2046 front end is initialized. */
2049 /* Do the target-specific parts of the initialization. */
2050 lang_dependent_init_target ();
2052 /* If dbx symbol table desired, initialize writing it and output the
2053 predefined types. */
2054 timevar_push (TV_SYMOUT);
2056 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2057 if (dwarf2out_do_frame ())
2058 dwarf2out_frame_init ();
2061 /* Now we have the correct original filename, we can initialize
2063 (*debug_hooks->init) (name);
2065 timevar_pop (TV_SYMOUT);
2071 /* Reinitialize everything when target parameters, such as register usage,
2074 target_reinit (void)
2076 /* Reinitialize RTL backend. */
2077 backend_init_target ();
2079 /* Reinitialize lang-dependent parts. */
2080 lang_dependent_init_target ();
2084 dump_memory_report (bool final)
2086 ggc_print_statistics ();
2087 stringpool_statistics ();
2088 dump_tree_statistics ();
2089 dump_rtx_statistics ();
2090 dump_varray_statistics ();
2091 dump_alloc_pool_statistics ();
2092 dump_bitmap_statistics ();
2093 dump_ggc_loc_statistics (final);
2096 /* Clean up: close opened files, etc. */
2101 /* Close the dump files. */
2102 if (flag_gen_aux_info)
2104 fclose (aux_info_file);
2106 unlink (aux_info_file_name);
2109 /* Close non-debugging input and output files. Take special care to note
2110 whether fclose returns an error, since the pages might still be on the
2111 buffer chain while the file is open. */
2115 if (ferror (asm_out_file) != 0)
2116 fatal_error ("error writing to %s: %m", asm_file_name);
2117 if (fclose (asm_out_file) != 0)
2118 fatal_error ("error closing %s: %m", asm_file_name);
2121 finish_optimization_passes ();
2124 dump_memory_report (true);
2126 /* Language-specific end of compilation actions. */
2127 lang_hooks.finish ();
2130 /* Initialize the compiler, and compile the input file. */
2134 /* Initialize timing first. The C front ends read the main file in
2135 the post_options hook, and C++ does file timings. */
2136 if (time_report || !quiet_flag || flag_detailed_statistics)
2138 timevar_start (TV_TOTAL);
2142 /* Don't do any more if an error has already occurred. */
2145 /* This must be run always, because it is needed to compute the FP
2146 predefined macros, such as __LDBL_MAX__, for targets using non
2147 default FP formats. */
2148 init_adjust_machine_modes ();
2150 /* Set up the back-end if requested. */
2154 /* Language-dependent initialization. Returns true on success. */
2155 if (lang_dependent_init (main_input_filename))
2161 /* Stop timing and print the times. */
2162 timevar_stop (TV_TOTAL);
2163 timevar_print (stderr);
2166 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2167 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2168 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2170 It is not safe to call this function more than once. */
2173 toplev_main (unsigned int argc, const char **argv)
2177 /* Initialization of GCC's environment, and diagnostics. */
2178 general_init (argv[0]);
2180 /* Parse the options and do minimal processing; basically just
2181 enough to default flags appropriately. */
2182 decode_options (argc, argv);
2186 /* Exit early if we can (e.g. -help). */
2187 if (!exit_after_options)
2190 if (warningcount || errorcount)
2191 print_ignored_options ();
2193 if (errorcount || sorrycount)
2194 return (FATAL_EXIT_CODE);
2196 return (SUCCESS_EXIT_CODE);