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 /* Nonzero means make permerror produce warnings instead of errors. */
286 int flag_permissive = 0;
288 /* -dA causes debug commentary information to be produced in
289 the generated assembly code (to make it more readable). This option
290 is generally only of use to those who actually need to read the
291 generated assembly code (perhaps while debugging the compiler itself).
292 Currently, this switch is only used by dwarfout.c; however, it is intended
293 to be a catchall for printing debug information in the assembler file. */
295 int flag_debug_asm = 0;
297 /* -dP causes the rtl to be emitted as a comment in assembly. */
299 int flag_dump_rtl_in_asm = 0;
301 /* When non-NULL, indicates that whenever space is allocated on the
302 stack, the resulting stack pointer must not pass this
303 address---that is, for stacks that grow downward, the stack pointer
304 must always be greater than or equal to this address; for stacks
305 that grow upward, the stack pointer must be less than this address.
306 At present, the rtx may be either a REG or a SYMBOL_REF, although
307 the support provided depends on the backend. */
310 /* Nonzero if we should track variables. When
311 flag_var_tracking == AUTODETECT_VALUE it will be set according
312 to optimize, debug_info_level and debug_hooks in process_options (). */
313 int flag_var_tracking = AUTODETECT_VALUE;
315 /* True if the user has tagged the function with the 'section'
318 bool user_defined_section_attribute = false;
320 /* Values of the -falign-* flags: how much to align labels in code.
321 0 means `use default', 1 means `don't align'.
322 For each variable, there is an _log variant which is the power
323 of two not less than the variable, for .align output. */
326 int align_loops_max_skip;
328 int align_jumps_max_skip;
329 int align_labels_log;
330 int align_labels_max_skip;
331 int align_functions_log;
335 const char *const string;
339 lang_independent_options;
341 /* Nonzero if subexpressions must be evaluated from left-to-right. */
342 int flag_evaluation_order = 0;
344 /* The user symbol prefix after having resolved same. */
345 const char *user_label_prefix;
347 static const param_info lang_independent_params[] = {
348 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
349 { OPTION, DEFAULT, false, MIN, MAX, HELP },
350 #include "params.def"
352 { NULL, 0, false, 0, 0, NULL }
355 /* Output files for assembler code (real compiler output)
356 and debugging dumps. */
360 FILE *dump_file = NULL;
361 const char *dump_file_name;
363 /* The current working directory of a translation. It's generally the
364 directory from which compilation was initiated, but a preprocessed
365 file may specify the original directory in which it was
368 static const char *src_pwd;
370 /* Initialize src_pwd with the given string, and return true. If it
371 was already initialized, return false. As a special case, it may
372 be called with a NULL argument to test whether src_pwd has NOT been
376 set_src_pwd (const char *pwd)
380 if (strcmp (src_pwd, pwd) == 0)
386 src_pwd = xstrdup (pwd);
390 /* Return the directory from which the translation unit was initiated,
391 in case set_src_pwd() was not called before to assign it a
407 /* Called when the start of a function definition is parsed,
408 this function prints on stderr the name of the function. */
410 announce_function (tree decl)
414 if (rtl_dump_and_exit)
415 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
417 fprintf (stderr, " %s", lang_hooks.decl_printable_name (decl, 2));
419 pp_needs_newline (global_dc->printer) = true;
420 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
424 /* Initialize local_tick with the time of day, or -1 if
425 flag_random_seed is set. */
428 init_local_tick (void)
430 if (!flag_random_seed)
432 /* Get some more or less random data. */
433 #ifdef HAVE_GETTIMEOFDAY
437 gettimeofday (&tv, NULL);
438 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
442 time_t now = time (NULL);
444 if (now != (time_t)-1)
445 local_tick = (unsigned) now;
453 /* Set up a default flag_random_seed and local_tick, unless the user
454 already specified one. Must be called after init_local_tick. */
457 init_random_seed (void)
459 unsigned HOST_WIDE_INT value;
460 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
462 value = local_tick ^ getpid ();
464 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
465 flag_random_seed = random_seed;
468 /* Obtain the random_seed string. Unless NOINIT, initialize it if
469 it's not provided in the command line. */
472 get_random_seed (bool noinit)
474 if (!flag_random_seed && !noinit)
476 return flag_random_seed;
479 /* Modify the random_seed string to VAL. Return its previous
483 set_random_seed (const char *val)
485 const char *old = flag_random_seed;
486 flag_random_seed = val;
490 /* Decode the string P as an integral parameter.
491 If the string is indeed an integer return its numeric value else
492 issue an Invalid Option error for the option PNAME and return DEFVAL.
493 If PNAME is zero just return DEFVAL, do not call error. */
496 read_integral_parameter (const char *p, const char *pname, const int defval)
498 const char *endp = p;
511 error ("invalid option argument %qs", pname);
518 /* When compiling with a recent enough GCC, we use the GNU C "extern inline"
519 for floor_log2 and exact_log2; see toplev.h. That construct, however,
520 conflicts with the ISO C++ One Definition Rule. */
522 #if GCC_VERSION < 3004 || !defined (__cplusplus)
524 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
525 If X is 0, return -1. */
528 floor_log2 (unsigned HOST_WIDE_INT x)
536 t = HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x);
538 if (HOST_BITS_PER_WIDE_INT > 64)
539 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
541 if (HOST_BITS_PER_WIDE_INT > 32)
542 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
544 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
546 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
548 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
550 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
552 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
559 /* Return the logarithm of X, base 2, considering X unsigned,
560 if X is a power of 2. Otherwise, returns -1. */
563 exact_log2 (unsigned HOST_WIDE_INT x)
568 return x ? CTZ_HWI (x) : -1;
570 return floor_log2 (x);
574 #endif /* GCC_VERSION < 3004 || !defined (__cplusplus) */
576 /* Handler for fatal signals, such as SIGSEGV. These are transformed
577 into ICE messages, which is much more user friendly. In case the
578 error printer crashes, reset the signal to prevent infinite recursion. */
581 crash_signal (int signo)
583 signal (signo, SIG_DFL);
585 /* If we crashed while processing an ASM statement, then be a little more
586 graceful. It's most likely the user's fault. */
587 if (this_is_asm_operands)
589 output_operand_lossage ("unrecoverable error");
590 exit (FATAL_EXIT_CODE);
593 internal_error ("%s", strsignal (signo));
596 /* Arrange to dump core on error. (The regular error message is still
597 printed first, except in the case of abort().) */
600 setup_core_dumping (void)
603 signal (SIGABRT, SIG_DFL);
605 #if defined(HAVE_SETRLIMIT)
608 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
609 fatal_error ("getting core file size maximum limit: %m");
610 rlim.rlim_cur = rlim.rlim_max;
611 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
612 fatal_error ("setting core file size limit to maximum: %m");
615 diagnostic_abort_on_error (global_dc);
619 /* Strip off a legitimate source ending from the input string NAME of
620 length LEN. Rather than having to know the names used by all of
621 our front ends, we strip off an ending of a period followed by
622 up to five characters. (Java uses ".class".) */
625 strip_off_ending (char *name, int len)
628 for (i = 2; i < 6 && len > i; i++)
630 if (name[len - i] == '.')
632 name[len - i] = '\0';
638 /* Output a quoted string. */
641 output_quoted_string (FILE *asm_file, const char *string)
643 #ifdef OUTPUT_QUOTED_STRING
644 OUTPUT_QUOTED_STRING (asm_file, string);
648 putc ('\"', asm_file);
649 while ((c = *string++) != 0)
653 if (c == '\"' || c == '\\')
654 putc ('\\', asm_file);
658 fprintf (asm_file, "\\%03o", (unsigned char) c);
660 putc ('\"', asm_file);
664 /* Output a file name in the form wanted by System V. */
667 output_file_directive (FILE *asm_file, const char *input_name)
672 if (input_name == NULL)
673 input_name = "<stdin>";
675 input_name = remap_debug_filename (input_name);
677 len = strlen (input_name);
678 na = input_name + len;
680 /* NA gets INPUT_NAME sans directory names. */
681 while (na > input_name)
683 if (IS_DIR_SEPARATOR (na[-1]))
688 #ifdef ASM_OUTPUT_SOURCE_FILENAME
689 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
691 fprintf (asm_file, "\t.file\t");
692 output_quoted_string (asm_file, na);
693 fputc ('\n', asm_file);
697 /* A subroutine of wrapup_global_declarations. We've come to the end of
698 the compilation unit. All deferred variables should be undeferred,
699 and all incomplete decls should be finalized. */
702 wrapup_global_declaration_1 (tree decl)
704 /* We're not deferring this any longer. Assignment is conditional to
705 avoid needlessly dirtying PCH pages. */
706 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
707 && DECL_DEFER_OUTPUT (decl) != 0)
708 DECL_DEFER_OUTPUT (decl) = 0;
710 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
711 lang_hooks.finish_incomplete_decl (decl);
714 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
715 needs to be output. Return true if it is output. */
718 wrapup_global_declaration_2 (tree decl)
720 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
723 /* Don't write out static consts, unless we still need them.
725 We also keep static consts if not optimizing (for debugging),
726 unless the user specified -fno-keep-static-consts.
727 ??? They might be better written into the debug information.
728 This is possible when using DWARF.
730 A language processor that wants static constants to be always
731 written out (even if it is not used) is responsible for
732 calling rest_of_decl_compilation itself. E.g. the C front-end
733 calls rest_of_decl_compilation from finish_decl.
734 One motivation for this is that is conventional in some
735 environments to write things like:
736 static const char rcsid[] = "... version string ...";
737 intending to force the string to be in the executable.
739 A language processor that would prefer to have unneeded
740 static constants "optimized away" would just defer writing
741 them out until here. E.g. C++ does this, because static
742 constants are often defined in header files.
744 ??? A tempting alternative (for both C and C++) would be
745 to force a constant to be written if and only if it is
746 defined in a main file, as opposed to an include file. */
748 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
750 struct varpool_node *node;
752 node = varpool_node (decl);
756 else if (node->alias)
758 else if (!cgraph_global_info_ready
760 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
762 else if (node->needed)
764 else if (DECL_COMDAT (decl))
766 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
767 && (optimize || !flag_keep_static_consts
768 || DECL_ARTIFICIAL (decl)))
773 rest_of_decl_compilation (decl, 1, 1);
781 /* Do any final processing required for the declarations in VEC, of
782 which there are LEN. We write out inline functions and variables
783 that have been deferred until this point, but which are required.
784 Returns nonzero if anything was put out. */
787 wrapup_global_declarations (tree *vec, int len)
789 bool reconsider, output_something = false;
792 for (i = 0; i < len; i++)
793 wrapup_global_declaration_1 (vec[i]);
795 /* Now emit any global variables or functions that we have been
796 putting off. We need to loop in case one of the things emitted
797 here references another one which comes earlier in the list. */
801 for (i = 0; i < len; i++)
802 reconsider |= wrapup_global_declaration_2 (vec[i]);
804 output_something = true;
808 return output_something;
811 /* A subroutine of check_global_declarations. Issue appropriate warnings
812 for the global declaration DECL. */
815 check_global_declaration_1 (tree decl)
817 /* Warn about any function declared static but not defined. We don't
818 warn about variables, because many programs have static variables
819 that exist only to get some text into the object file. */
820 if (TREE_CODE (decl) == FUNCTION_DECL
821 && DECL_INITIAL (decl) == 0
822 && DECL_EXTERNAL (decl)
823 && ! DECL_ARTIFICIAL (decl)
824 && ! TREE_NO_WARNING (decl)
825 && ! TREE_PUBLIC (decl)
826 && (warn_unused_function
827 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
829 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
830 pedwarn ("%q+F used but never defined", decl);
832 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
833 /* This symbol is effectively an "extern" declaration now. */
834 TREE_PUBLIC (decl) = 1;
835 assemble_external (decl);
838 /* Warn about static fns or vars defined but not used. */
839 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
840 /* We don't warn about "static const" variables because the
841 "rcs_id" idiom uses that construction. */
842 || (warn_unused_variable
843 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
844 && ! DECL_IN_SYSTEM_HEADER (decl)
845 && ! TREE_USED (decl)
846 /* The TREE_USED bit for file-scope decls is kept in the identifier,
847 to handle multiple external decls in different scopes. */
848 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
849 && ! DECL_EXTERNAL (decl)
850 && ! TREE_PUBLIC (decl)
851 /* A volatile variable might be used in some non-obvious way. */
852 && ! TREE_THIS_VOLATILE (decl)
853 /* Global register variables must be declared to reserve them. */
854 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
855 /* Otherwise, ask the language. */
856 && lang_hooks.decls.warn_unused_global (decl))
857 warning ((TREE_CODE (decl) == FUNCTION_DECL)
858 ? OPT_Wunused_function
859 : OPT_Wunused_variable,
860 "%q+D defined but not used", decl);
863 /* Issue appropriate warnings for the global declarations in VEC (of
864 which there are LEN). */
867 check_global_declarations (tree *vec, int len)
871 for (i = 0; i < len; i++)
872 check_global_declaration_1 (vec[i]);
875 /* Emit debugging information for all global declarations in VEC. */
878 emit_debug_global_declarations (tree *vec, int len)
882 /* Avoid confusing the debug information machinery when there are errors. */
883 if (errorcount != 0 || sorrycount != 0)
886 timevar_push (TV_SYMOUT);
887 for (i = 0; i < len; i++)
888 debug_hooks->global_decl (vec[i]);
889 timevar_pop (TV_SYMOUT);
892 /* Warn about a use of an identifier which was marked deprecated. */
894 warn_deprecated_use (tree node)
896 if (node == 0 || !warn_deprecated_decl)
901 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
902 warning (OPT_Wdeprecated_declarations,
903 "%qD is deprecated (declared at %s:%d)",
904 node, xloc.file, xloc.line);
906 else if (TYPE_P (node))
908 const char *what = NULL;
909 tree decl = TYPE_STUB_DECL (node);
911 if (TYPE_NAME (node))
913 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
914 what = IDENTIFIER_POINTER (TYPE_NAME (node));
915 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
916 && DECL_NAME (TYPE_NAME (node)))
917 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
922 expanded_location xloc
923 = expand_location (DECL_SOURCE_LOCATION (decl));
925 warning (OPT_Wdeprecated_declarations,
926 "%qs is deprecated (declared at %s:%d)", what,
927 xloc.file, xloc.line);
929 warning (OPT_Wdeprecated_declarations,
930 "type is deprecated (declared at %s:%d)",
931 xloc.file, xloc.line);
936 warning (OPT_Wdeprecated_declarations, "%qs is deprecated", what);
938 warning (OPT_Wdeprecated_declarations, "type is deprecated");
943 /* Compile an entire translation unit. Write a file of assembly
944 output and various debugging dumps. */
949 /* Initialize yet another pass. */
952 init_final (main_input_filename);
953 coverage_init (aux_base_name);
955 timevar_push (TV_PARSE);
957 /* Call the parser, which parses the entire file (calling
958 rest_of_compilation for each function). */
959 lang_hooks.parse_file (set_yydebug);
961 /* In case there were missing block closers,
962 get us back to the global binding level. */
963 lang_hooks.clear_binding_stack ();
965 /* Compilation is now finished except for writing
966 what's left of the symbol table output. */
967 timevar_pop (TV_PARSE);
969 if (flag_syntax_only)
972 lang_hooks.decls.final_write_globals ();
974 if (errorcount || sorrycount)
977 varpool_assemble_pending_decls ();
980 /* This must occur after the loop to output deferred functions.
981 Else the coverage initializer would not be emitted if all the
982 functions in this compilation unit were deferred. */
985 /* Likewise for mudflap static object registrations. */
987 mudflap_finish_file ();
989 /* Likewise for emulated thread-local storage. */
990 if (!targetm.have_tls)
993 output_shared_constant_pool ();
994 output_object_blocks ();
996 /* Write out any pending weak symbol declarations. */
999 /* Do dbx symbols. */
1000 timevar_push (TV_SYMOUT);
1002 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
1003 if (dwarf2out_do_frame ())
1004 dwarf2out_frame_finish ();
1007 (*debug_hooks->finish) (main_input_filename);
1008 timevar_pop (TV_SYMOUT);
1010 /* Output some stuff at end of file if nec. */
1012 dw2_output_indirect_constants ();
1014 /* Flush any pending external directives. */
1015 process_pending_assemble_externals ();
1017 /* Attach a special .ident directive to the end of the file to identify
1018 the version of GCC which compiled this code. The format of the .ident
1019 string is patterned after the ones produced by native SVR4 compilers. */
1023 const char *pkg_version = "(GNU) ";
1025 if (strcmp ("(GCC) ", pkgversion_string))
1026 pkg_version = pkgversion_string;
1027 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
1028 IDENT_ASM_OP, pkg_version, version_string);
1032 /* This must be at the end. Some target ports emit end of file directives
1033 into the assembly file here, and hence we can not output anything to the
1034 assembly file after this point. */
1035 targetm.asm_out.file_end ();
1038 /* Parse a -d... command line switch. */
1041 decode_d_option (const char *arg)
1052 flag_print_asm_name = 1;
1055 flag_dump_rtl_in_asm = 1;
1056 flag_print_asm_name = 1;
1059 graph_dump_format = vcg;
1062 rtl_dump_and_exit = 1;
1067 case 'D': /* These are handled by the preprocessor. */
1071 setup_core_dumping();
1076 if (!enable_rtl_dump_file (c))
1077 warning (0, "unrecognized gcc debugging option: %c", c);
1082 /* Indexed by enum debug_info_type. */
1083 const char *const debug_type_names[] =
1085 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1088 /* Print version information to FILE.
1089 Each line begins with INDENT (for the case where FILE is the
1090 assembler output file). */
1093 print_version (FILE *file, const char *indent)
1095 static const char fmt1[] =
1097 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1099 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1102 static const char fmt2[] =
1103 N_("GMP version %s, MPFR version %s.\n");
1104 static const char fmt3[] =
1105 N_("%s%swarning: %s header version %s differs from library version %s.\n");
1106 static const char fmt4[] =
1107 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1109 #define __VERSION__ "[?]"
1112 file == stderr ? _(fmt1) : fmt1,
1113 indent, *indent != 0 ? " " : "",
1114 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
1115 indent, __VERSION__);
1117 /* We need to stringify the GMP macro values. Ugh, gmp_version has
1118 two string formats, "i.j.k" and "i.j" when k is zero. */
1119 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1120 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1121 #if __GNU_MP_VERSION_PATCHLEVEL == 0
1122 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1123 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1125 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1126 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1127 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1130 file == stderr ? _(fmt2) : fmt2,
1131 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING);
1132 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
1134 file == stderr ? _(fmt3) : fmt3,
1135 indent, *indent != 0 ? " " : "",
1136 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
1137 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
1139 file == stderr ? _(fmt3) : fmt3,
1140 indent, *indent != 0 ? " " : "",
1141 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
1143 file == stderr ? _(fmt4) : fmt4,
1144 indent, *indent != 0 ? " " : "",
1145 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1148 #ifdef ASM_COMMENT_START
1150 print_to_asm_out_file (print_switch_type type, const char * text)
1152 bool prepend_sep = true;
1156 case SWITCH_TYPE_LINE_END:
1157 putc ('\n', asm_out_file);
1160 case SWITCH_TYPE_LINE_START:
1161 fputs (ASM_COMMENT_START, asm_out_file);
1162 return strlen (ASM_COMMENT_START);
1164 case SWITCH_TYPE_DESCRIPTIVE:
1165 if (ASM_COMMENT_START[0] == 0)
1166 prepend_sep = false;
1168 case SWITCH_TYPE_PASSED:
1169 case SWITCH_TYPE_ENABLED:
1171 fputc (' ', asm_out_file);
1172 fprintf (asm_out_file, text);
1173 /* No need to return the length here as
1174 print_single_switch has already done it. */
1184 print_to_stderr (print_switch_type type, const char * text)
1188 case SWITCH_TYPE_LINE_END:
1189 putc ('\n', stderr);
1192 case SWITCH_TYPE_LINE_START:
1195 case SWITCH_TYPE_PASSED:
1196 case SWITCH_TYPE_ENABLED:
1197 fputc (' ', stderr);
1200 case SWITCH_TYPE_DESCRIPTIVE:
1201 fprintf (stderr, text);
1202 /* No need to return the length here as
1203 print_single_switch has already done it. */
1211 /* Print an option value and return the adjusted position in the line.
1212 ??? print_fn doesn't handle errors, eg disk full; presumably other
1213 code will catch a disk full though. */
1216 print_single_switch (print_switch_fn_type print_fn,
1218 print_switch_type type,
1221 /* The ultrix fprintf returns 0 on success, so compute the result
1222 we want here since we need it for the following test. The +1
1223 is for the separator character that will probably be emitted. */
1224 int len = strlen (text) + 1;
1227 && pos + len > MAX_LINE)
1229 print_fn (SWITCH_TYPE_LINE_END, NULL);
1234 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1236 print_fn (type, text);
1240 /* Print active target switches using PRINT_FN.
1241 POS is the current cursor position and MAX is the size of a "line".
1242 Each line begins with INDENT and ends with TERM.
1243 Each switch is separated from the next by SEP. */
1246 print_switch_values (print_switch_fn_type print_fn)
1252 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1253 that it can be printed below. This helps reproducibility. */
1254 if (!flag_random_seed)
1255 init_random_seed ();
1257 /* Print the options as passed. */
1258 pos = print_single_switch (print_fn, pos,
1259 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1261 for (p = &save_argv[1]; *p != NULL; p++)
1266 if (strcmp (*p, "-o") == 0
1267 || strcmp (*p, "-dumpbase") == 0
1268 || strcmp (*p, "-auxbase") == 0)
1275 if (strcmp (*p, "-quiet") == 0
1276 || strcmp (*p, "-version") == 0)
1283 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED, *p);
1287 print_fn (SWITCH_TYPE_LINE_END, NULL);
1289 /* Print the -f and -m options that have been enabled.
1290 We don't handle language specific options but printing argv
1292 pos = print_single_switch (print_fn, 0,
1293 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1295 for (j = 0; j < cl_options_count; j++)
1296 if ((cl_options[j].flags & CL_REPORT)
1297 && option_enabled (j) > 0)
1298 pos = print_single_switch (print_fn, pos,
1299 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1301 print_fn (SWITCH_TYPE_LINE_END, NULL);
1304 /* Open assembly code output file. Do this even if -fsyntax-only is
1305 on, because then the driver will have provided the name of a
1306 temporary file or bit bucket for us. NAME is the file specified on
1307 the command line, possibly NULL. */
1309 init_asm_output (const char *name)
1311 if (name == NULL && asm_file_name == 0)
1312 asm_out_file = stdout;
1315 if (asm_file_name == 0)
1317 int len = strlen (dump_base_name);
1318 char *dumpname = XNEWVEC (char, len + 6);
1320 memcpy (dumpname, dump_base_name, len + 1);
1321 strip_off_ending (dumpname, len);
1322 strcat (dumpname, ".s");
1323 asm_file_name = dumpname;
1325 if (!strcmp (asm_file_name, "-"))
1326 asm_out_file = stdout;
1328 asm_out_file = fopen (asm_file_name, "w+b");
1329 if (asm_out_file == 0)
1330 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1333 if (!flag_syntax_only)
1335 targetm.asm_out.file_start ();
1337 if (flag_record_gcc_switches)
1339 if (targetm.asm_out.record_gcc_switches)
1341 /* Let the target know that we are about to start recording. */
1342 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1344 /* Now record the switches. */
1345 print_switch_values (targetm.asm_out.record_gcc_switches);
1346 /* Let the target know that the recording is over. */
1347 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1351 inform ("-frecord-gcc-switches is not supported by the current target");
1354 #ifdef ASM_COMMENT_START
1355 if (flag_verbose_asm)
1357 /* Print the list of switches in effect
1358 into the assembler file as comments. */
1359 print_version (asm_out_file, ASM_COMMENT_START);
1360 print_switch_values (print_to_asm_out_file);
1361 fprintf (asm_out_file, "\n");
1367 /* Return true if the state of option OPTION should be stored in PCH files
1368 and checked by default_pch_valid_p. Store the option's current state
1372 option_affects_pch_p (int option, struct cl_option_state *state)
1374 if ((cl_options[option].flags & CL_TARGET) == 0)
1376 if (cl_options[option].flag_var == &target_flags)
1377 if (targetm.check_pch_target_flags)
1379 return get_option_state (option, state);
1382 /* Default version of get_pch_validity.
1383 By default, every flag difference is fatal; that will be mostly right for
1384 most targets, but completely right for very few. */
1387 default_get_pch_validity (size_t *len)
1389 struct cl_option_state state;
1394 if (targetm.check_pch_target_flags)
1395 *len += sizeof (target_flags);
1396 for (i = 0; i < cl_options_count; i++)
1397 if (option_affects_pch_p (i, &state))
1400 result = r = XNEWVEC (char, *len);
1404 if (targetm.check_pch_target_flags)
1406 memcpy (r, &target_flags, sizeof (target_flags));
1407 r += sizeof (target_flags);
1410 for (i = 0; i < cl_options_count; i++)
1411 if (option_affects_pch_p (i, &state))
1413 memcpy (r, state.data, state.size);
1420 /* Return a message which says that a PCH file was created with a different
1421 setting of OPTION. */
1424 pch_option_mismatch (const char *option)
1428 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1430 return _("out of memory");
1434 /* Default version of pch_valid_p. */
1437 default_pch_valid_p (const void *data_p, size_t len)
1439 struct cl_option_state state;
1440 const char *data = (const char *)data_p;
1443 /* -fpic and -fpie also usually make a PCH invalid. */
1444 if (data[0] != flag_pic)
1445 return _("created and used with different settings of -fpic");
1446 if (data[1] != flag_pie)
1447 return _("created and used with different settings of -fpie");
1450 /* Check target_flags. */
1451 if (targetm.check_pch_target_flags)
1456 memcpy (&tf, data, sizeof (target_flags));
1457 data += sizeof (target_flags);
1458 len -= sizeof (target_flags);
1459 r = targetm.check_pch_target_flags (tf);
1464 for (i = 0; i < cl_options_count; i++)
1465 if (option_affects_pch_p (i, &state))
1467 if (memcmp (data, state.data, state.size) != 0)
1468 return pch_option_mismatch (cl_options[i].opt_text);
1476 /* Default tree printer. Handles declarations only. */
1478 default_tree_printer (pretty_printer * pp, text_info *text, const char *spec,
1479 int precision, bool wide, bool set_locus, bool hash)
1483 /* FUTURE: %+x should set the locus. */
1484 if (precision != 0 || wide || hash)
1490 t = va_arg (*text->args_ptr, tree);
1491 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1492 t = DECL_DEBUG_EXPR (t);
1497 t = va_arg (*text->args_ptr, tree);
1504 if (set_locus && text->locus)
1505 *text->locus = DECL_SOURCE_LOCATION (t);
1509 const char *n = DECL_NAME (t)
1510 ? lang_hooks.decl_printable_name (t, 2)
1515 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1520 /* A helper function; used as the reallocator function for cpp's line
1523 realloc_for_line_map (void *ptr, size_t len)
1525 return ggc_realloc (ptr, len);
1528 /* Initialization of the front end environment, before command line
1529 options are parsed. Signal handlers, internationalization etc.
1530 ARGV0 is main's argv[0]. */
1532 general_init (const char *argv0)
1536 p = argv0 + strlen (argv0);
1537 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1541 xmalloc_set_program_name (progname);
1545 /* Unlock the stdio streams. */
1546 unlock_std_streams ();
1548 gcc_init_libintl ();
1550 /* Initialize the diagnostics reporting machinery, so option parsing
1551 can give warnings and errors. */
1552 diagnostic_initialize (global_dc);
1553 /* Set a default printer. Language specific initializations will
1554 override it later. */
1555 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1557 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1559 signal (SIGSEGV, crash_signal);
1562 signal (SIGILL, crash_signal);
1565 signal (SIGBUS, crash_signal);
1568 signal (SIGABRT, crash_signal);
1570 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1571 signal (SIGIOT, crash_signal);
1574 signal (SIGFPE, crash_signal);
1577 /* Other host-specific signal setup. */
1578 (*host_hooks.extra_signals)();
1580 /* Initialize the garbage-collector, string pools and tree type hash
1584 line_table = GGC_NEW (struct line_maps);
1585 linemap_init (line_table);
1586 line_table->reallocator = realloc_for_line_map;
1589 /* Initialize register usage now so switches may override. */
1592 /* Register the language-independent parameters. */
1593 add_params (lang_independent_params, LAST_PARAM);
1595 /* This must be done after add_params but before argument processing. */
1596 init_ggc_heuristics();
1597 init_optimization_passes ();
1600 /* Return true if the current target supports -fsection-anchors. */
1603 target_supports_section_anchors_p (void)
1605 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1608 if (targetm.asm_out.output_anchor == NULL)
1614 /* Default the align_* variables to 1 if they're still unset, and
1615 set up the align_*_log variables. */
1617 init_alignments (void)
1619 if (align_loops <= 0)
1621 if (align_loops_max_skip > align_loops)
1622 align_loops_max_skip = align_loops - 1;
1623 align_loops_log = floor_log2 (align_loops * 2 - 1);
1624 if (align_jumps <= 0)
1626 if (align_jumps_max_skip > align_jumps)
1627 align_jumps_max_skip = align_jumps - 1;
1628 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1629 if (align_labels <= 0)
1631 align_labels_log = floor_log2 (align_labels * 2 - 1);
1632 if (align_labels_max_skip > align_labels)
1633 align_labels_max_skip = align_labels - 1;
1634 if (align_functions <= 0)
1635 align_functions = 1;
1636 align_functions_log = floor_log2 (align_functions * 2 - 1);
1639 /* Process the options that have been parsed. */
1641 process_options (void)
1643 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1644 This can happen with incorrect pre-processed input. */
1645 debug_hooks = &do_nothing_debug_hooks;
1647 /* Allow the front end to perform consistency checks and do further
1648 initialization based on the command line options. This hook also
1649 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1650 so we can correctly initialize debug output. */
1651 no_backend = lang_hooks.post_options (&main_input_filename);
1653 #ifdef OVERRIDE_OPTIONS
1654 /* Some machines may reject certain combinations of options. */
1658 if (flag_section_anchors && !target_supports_section_anchors_p ())
1660 warning (OPT_fsection_anchors,
1661 "this target does not support %qs", "-fsection-anchors");
1662 flag_section_anchors = 0;
1665 if (flag_short_enums == 2)
1666 flag_short_enums = targetm.default_short_enums ();
1668 /* Set aux_base_name if not already set. */
1671 else if (main_input_filename)
1673 char *name = xstrdup (lbasename (main_input_filename));
1675 strip_off_ending (name, strlen (name));
1676 aux_base_name = name;
1679 aux_base_name = "gccaux";
1681 /* Unrolling all loops implies that standard loop unrolling must also
1683 if (flag_unroll_all_loops)
1684 flag_unroll_loops = 1;
1686 /* The loop unrolling code assumes that cse will be run after loop.
1687 web and rename-registers also help when run after loop unrolling. */
1689 if (flag_rerun_cse_after_loop == AUTODETECT_VALUE)
1690 flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops;
1691 if (flag_web == AUTODETECT_VALUE)
1692 flag_web = flag_unroll_loops || flag_peel_loops;
1693 if (flag_rename_registers == AUTODETECT_VALUE)
1694 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1696 if (flag_non_call_exceptions)
1697 flag_asynchronous_unwind_tables = 1;
1698 if (flag_asynchronous_unwind_tables)
1699 flag_unwind_tables = 1;
1701 if (!flag_unit_at_a_time)
1702 flag_section_anchors = 0;
1704 if (flag_value_profile_transformations)
1705 flag_profile_values = 1;
1707 /* Warn about options that are not supported on this machine. */
1708 #ifndef INSN_SCHEDULING
1709 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1710 warning (0, "instruction scheduling not supported on this target machine");
1713 if (flag_delayed_branch)
1714 warning (0, "this target machine does not have delayed branches");
1717 user_label_prefix = USER_LABEL_PREFIX;
1718 if (flag_leading_underscore != -1)
1720 /* If the default prefix is more complicated than "" or "_",
1721 issue a warning and ignore this option. */
1722 if (user_label_prefix[0] == 0 ||
1723 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1725 user_label_prefix = flag_leading_underscore ? "_" : "";
1728 warning (0, "-f%sleading-underscore not supported on this target machine",
1729 flag_leading_underscore ? "" : "no-");
1732 /* If we are in verbose mode, write out the version and maybe all the
1733 option flags in use. */
1736 print_version (stderr, "");
1738 print_switch_values (print_to_stderr);
1741 if (flag_syntax_only)
1743 write_symbols = NO_DEBUG;
1747 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1749 if (debug_info_level == DINFO_LEVEL_NONE)
1750 write_symbols = NO_DEBUG;
1752 /* Now we know write_symbols, set up the debug hooks based on it.
1753 By default we do nothing for debug output. */
1754 if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG)
1755 default_debug_hooks = &do_nothing_debug_hooks;
1756 #if defined(DBX_DEBUGGING_INFO)
1757 else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG)
1758 default_debug_hooks = &dbx_debug_hooks;
1760 #if defined(XCOFF_DEBUGGING_INFO)
1761 else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG)
1762 default_debug_hooks = &xcoff_debug_hooks;
1764 #ifdef SDB_DEBUGGING_INFO
1765 else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG)
1766 default_debug_hooks = &sdb_debug_hooks;
1768 #ifdef DWARF2_DEBUGGING_INFO
1769 else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG)
1770 default_debug_hooks = &dwarf2_debug_hooks;
1772 #ifdef VMS_DEBUGGING_INFO
1773 else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG
1774 || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG)
1775 default_debug_hooks = &vmsdbg_debug_hooks;
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 /* Now we know which debug output will be used so we can set
1805 flag_var_tracking, flag_rename_registers if the user has
1806 not specified them. */
1807 if (debug_info_level < DINFO_LEVEL_NORMAL
1808 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1810 if (flag_var_tracking == 1
1811 || flag_var_tracking_uninit == 1)
1813 if (debug_info_level < DINFO_LEVEL_NORMAL)
1814 warning (0, "variable tracking requested, but useless unless "
1815 "producing debug info");
1817 warning (0, "variable tracking requested, but not supported "
1818 "by this debug format");
1820 flag_var_tracking = 0;
1821 flag_var_tracking_uninit = 0;
1824 if (flag_rename_registers == AUTODETECT_VALUE)
1825 flag_rename_registers = default_debug_hooks->var_location
1826 != do_nothing_debug_hooks.var_location;
1828 if (flag_var_tracking == AUTODETECT_VALUE)
1829 flag_var_tracking = optimize >= 1;
1831 if (flag_tree_cselim == AUTODETECT_VALUE)
1832 #ifdef HAVE_conditional_move
1833 flag_tree_cselim = 1;
1835 flag_tree_cselim = 0;
1838 /* If the user specifically requested variable tracking with tagging
1839 uninitialized variables, we need to turn on variable tracking.
1840 (We already determined above that variable tracking is feasible.) */
1841 if (flag_var_tracking_uninit)
1842 flag_var_tracking = 1;
1844 /* If auxiliary info generation is desired, open the output file.
1845 This goes in the same directory as the source file--unlike
1846 all the other output files. */
1847 if (flag_gen_aux_info)
1849 aux_info_file = fopen (aux_info_file_name, "w");
1850 if (aux_info_file == 0)
1851 fatal_error ("can%'t open %s: %m", aux_info_file_name);
1854 if (! targetm.have_named_sections)
1856 if (flag_function_sections)
1858 warning (0, "-ffunction-sections not supported for this target");
1859 flag_function_sections = 0;
1861 if (flag_data_sections)
1863 warning (0, "-fdata-sections not supported for this target");
1864 flag_data_sections = 0;
1868 if (flag_function_sections && profile_flag)
1870 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
1871 flag_function_sections = 0;
1874 #ifndef HAVE_prefetch
1875 if (flag_prefetch_loop_arrays)
1877 warning (0, "-fprefetch-loop-arrays not supported for this target");
1878 flag_prefetch_loop_arrays = 0;
1881 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
1883 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
1884 flag_prefetch_loop_arrays = 0;
1888 /* This combination of options isn't handled for i386 targets and doesn't
1889 make much sense anyway, so don't allow it. */
1890 if (flag_prefetch_loop_arrays && optimize_size)
1892 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
1893 flag_prefetch_loop_arrays = 0;
1896 #ifndef OBJECT_FORMAT_ELF
1897 #ifndef OBJECT_FORMAT_MACHO
1898 if (flag_function_sections && write_symbols != NO_DEBUG)
1899 warning (0, "-ffunction-sections may affect debugging on some targets");
1903 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1904 if (flag_signaling_nans)
1905 flag_trapping_math = 1;
1907 /* We cannot reassociate if we want traps or signed zeros. Â */
1908 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1910 warning (0, "-fassociative-math disabled; other options take precedence");
1911 flag_associative_math = 0;
1914 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1915 if (flag_cx_limited_range)
1916 flag_complex_method = 0;
1918 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1919 if (flag_cx_fortran_rules)
1920 flag_complex_method = 1;
1922 /* Targets must be able to place spill slots at lower addresses. If the
1923 target already uses a soft frame pointer, the transition is trivial. */
1924 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1926 warning (0, "-fstack-protector not supported for this target");
1927 flag_stack_protect = 0;
1929 if (!flag_stack_protect)
1930 warn_stack_protect = 0;
1932 /* ??? Unwind info is not correct around the CFG unless either a frame
1933 pointer is present or A_O_A is set. Fixing this requires rewriting
1934 unwind info generation to be aware of the CFG and propagating states
1936 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
1937 && flag_omit_frame_pointer)
1939 warning (0, "unwind tables currently require a frame pointer "
1941 flag_omit_frame_pointer = 0;
1945 /* This function can be called multiple times to reinitialize the compiler
1946 back end when register classes or instruction sets have changed,
1947 before each function. */
1949 backend_init_target (void)
1951 /* Initialize alignment variables. */
1954 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
1955 to initialize reg_raw_mode[]. */
1958 /* This invokes target hooks to set fixed_reg[] etc, which is
1962 /* This depends on stack_pointer_rtx. */
1963 init_fake_stack_mems ();
1965 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1967 init_alias_target ();
1969 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1972 /* The following initialization functions need to generate rtl, so
1973 provide a dummy function context for them. */
1974 init_dummy_function_start ();
1976 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1977 on a mode change. */
1980 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1981 after a mode change as well. */
1982 if (flag_caller_saves)
1983 init_caller_save ();
1984 expand_dummy_function_end ();
1987 /* Initialize the compiler back end. This function is called only once,
1988 when starting the compiler. */
1992 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
1993 || debug_info_level == DINFO_LEVEL_VERBOSE
1994 #ifdef VMS_DEBUGGING_INFO
1995 /* Enable line number info for traceback. */
1996 || debug_info_level > DINFO_LEVEL_NONE
1998 || flag_test_coverage);
2001 init_inline_once ();
2002 init_varasm_once ();
2003 save_register_info ();
2005 /* Initialize the target-specific back end pieces. */
2006 backend_init_target ();
2009 /* Initialize things that are both lang-dependent and target-dependent.
2010 This function can be called more than once if target parameters change. */
2012 lang_dependent_init_target (void)
2014 /* This creates various _DECL nodes, so needs to be called after the
2015 front end is initialized. It also depends on the HAVE_xxx macros
2016 generated from the target machine description. */
2019 /* The following initialization functions need to generate rtl, so
2020 provide a dummy function context for them. */
2021 init_dummy_function_start ();
2023 /* Do the target-specific parts of expr initialization. */
2024 init_expr_target ();
2026 /* Although the actions of init_set_costs are language-independent,
2027 it uses optabs, so we cannot call it from backend_init. */
2030 expand_dummy_function_end ();
2033 /* Language-dependent initialization. Returns nonzero on success. */
2035 lang_dependent_init (const char *name)
2037 location_t save_loc = input_location;
2038 if (dump_base_name == 0)
2039 dump_base_name = name && name[0] ? name : "gccdump";
2041 /* Other front-end initialization. */
2042 input_location = BUILTINS_LOCATION;
2043 if (lang_hooks.init () == 0)
2045 input_location = save_loc;
2047 init_asm_output (name);
2049 /* This creates various _DECL nodes, so needs to be called after the
2050 front end is initialized. */
2053 /* Do the target-specific parts of the initialization. */
2054 lang_dependent_init_target ();
2056 /* If dbx symbol table desired, initialize writing it and output the
2057 predefined types. */
2058 timevar_push (TV_SYMOUT);
2060 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2061 if (dwarf2out_do_frame ())
2062 dwarf2out_frame_init ();
2065 /* Now we have the correct original filename, we can initialize
2067 (*debug_hooks->init) (name);
2069 timevar_pop (TV_SYMOUT);
2075 /* Reinitialize everything when target parameters, such as register usage,
2078 target_reinit (void)
2080 /* Reinitialize RTL backend. */
2081 backend_init_target ();
2083 /* Reinitialize lang-dependent parts. */
2084 lang_dependent_init_target ();
2088 dump_memory_report (bool final)
2090 ggc_print_statistics ();
2091 stringpool_statistics ();
2092 dump_tree_statistics ();
2093 dump_rtx_statistics ();
2094 dump_varray_statistics ();
2095 dump_alloc_pool_statistics ();
2096 dump_bitmap_statistics ();
2097 dump_ggc_loc_statistics (final);
2100 /* Clean up: close opened files, etc. */
2105 /* Close the dump files. */
2106 if (flag_gen_aux_info)
2108 fclose (aux_info_file);
2110 unlink (aux_info_file_name);
2113 /* Close non-debugging input and output files. Take special care to note
2114 whether fclose returns an error, since the pages might still be on the
2115 buffer chain while the file is open. */
2119 if (ferror (asm_out_file) != 0)
2120 fatal_error ("error writing to %s: %m", asm_file_name);
2121 if (fclose (asm_out_file) != 0)
2122 fatal_error ("error closing %s: %m", asm_file_name);
2125 finish_optimization_passes ();
2128 dump_memory_report (true);
2130 /* Language-specific end of compilation actions. */
2131 lang_hooks.finish ();
2134 /* Initialize the compiler, and compile the input file. */
2138 /* Initialize timing first. The C front ends read the main file in
2139 the post_options hook, and C++ does file timings. */
2140 if (time_report || !quiet_flag || flag_detailed_statistics)
2142 timevar_start (TV_TOTAL);
2146 /* Don't do any more if an error has already occurred. */
2149 /* This must be run always, because it is needed to compute the FP
2150 predefined macros, such as __LDBL_MAX__, for targets using non
2151 default FP formats. */
2152 init_adjust_machine_modes ();
2154 /* Set up the back-end if requested. */
2158 /* Language-dependent initialization. Returns true on success. */
2159 if (lang_dependent_init (main_input_filename))
2165 /* Stop timing and print the times. */
2166 timevar_stop (TV_TOTAL);
2167 timevar_print (stderr);
2170 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2171 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2172 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2174 It is not safe to call this function more than once. */
2177 toplev_main (unsigned int argc, const char **argv)
2181 /* Initialization of GCC's environment, and diagnostics. */
2182 general_init (argv[0]);
2184 /* Parse the options and do minimal processing; basically just
2185 enough to default flags appropriately. */
2186 decode_options (argc, argv);
2190 /* Exit early if we can (e.g. -help). */
2191 if (!exit_after_options)
2194 if (warningcount || errorcount)
2195 print_ignored_options ();
2197 if (errorcount || sorrycount)
2198 return (FATAL_EXIT_CODE);
2200 return (SUCCESS_EXIT_CODE);