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 /* Prefix for profile data files */
156 const char *profile_data_prefix;
158 /* A mask of target_flags that includes bit X if X was set or cleared
159 on the command line. */
161 int target_flags_explicit;
163 /* Debug hooks - dependent upon command line options. */
165 const struct gcc_debug_hooks *debug_hooks;
167 /* Debug hooks - target default. */
169 static const struct gcc_debug_hooks *default_debug_hooks;
171 /* Other flags saying which kinds of debugging dump have been requested. */
173 int rtl_dump_and_exit;
174 int flag_print_asm_name;
175 enum graph_dump_types graph_dump_format;
177 /* Name for output file of assembly code, specified with -o. */
179 const char *asm_file_name;
181 /* Nonzero means do optimizations. -O.
182 Particular numeric values stand for particular amounts of optimization;
183 thus, -O2 stores 2 here. However, the optimizations beyond the basic
184 ones are not controlled directly by this variable. Instead, they are
185 controlled by individual `flag_...' variables that are defaulted
186 based on this variable. */
190 /* Nonzero means optimize for size. -Os.
191 The only valid values are zero and nonzero. When optimize_size is
192 nonzero, optimize defaults to 2, but certain individual code
193 bloating optimizations are disabled. */
195 int optimize_size = 0;
197 /* The FUNCTION_DECL for the function currently being compiled,
198 or 0 if between functions. */
199 tree current_function_decl;
201 /* Set to the FUNC_BEGIN label of the current function, or NULL
203 const char * current_function_func_begin_label;
205 /* Temporarily suppress certain warnings.
206 This is set while reading code from a system header file. */
208 int in_system_header = 0;
210 /* Nonzero means to collect statistics which might be expensive
211 and to print them when we are done. */
212 int flag_detailed_statistics = 0;
214 /* A random sequence of characters, unless overridden by user. */
215 static const char *flag_random_seed;
217 /* A local time stamp derived from the time of compilation. It will be
218 zero if the system cannot provide a time. It will be -1u, if the
219 user has specified a particular random seed. */
224 /* Nonzero means `char' should be signed. */
226 int flag_signed_char;
228 /* Nonzero means give an enum type only as many bytes as it needs. A value
229 of 2 means it has not yet been initialized. */
231 int flag_short_enums;
233 /* Nonzero if structures and unions should be returned in memory.
235 This should only be defined if compatibility with another compiler or
236 with an ABI is needed, because it results in slower code. */
238 #ifndef DEFAULT_PCC_STRUCT_RETURN
239 #define DEFAULT_PCC_STRUCT_RETURN 1
242 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
244 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
246 /* 0 means straightforward implementation of complex divide acceptable.
247 1 means wide ranges of inputs must work for complex divide.
248 2 means C99-like requirements for complex multiply and divide. */
250 int flag_complex_method = 1;
252 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
253 not just because the tree inliner turned us off. */
255 int flag_really_no_inline = 2;
257 /* Nonzero means we should be saving declaration info into a .X file. */
259 int flag_gen_aux_info = 0;
261 /* Specified name of aux-info file. */
263 const char *aux_info_file_name;
265 /* Nonzero if we are compiling code for a shared library, zero for
270 /* Generate code for GNU or NeXT Objective-C runtime environment. */
272 #ifdef NEXT_OBJC_RUNTIME
273 int flag_next_runtime = 1;
275 int flag_next_runtime = 0;
278 /* Set to the default thread-local storage (tls) model to use. */
280 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
282 /* Nonzero means change certain warnings into errors.
283 Usually these are warnings about failure to conform to some standard. */
285 int flag_pedantic_errors = 0;
287 /* Nonzero means make permerror produce warnings instead of errors. */
289 int flag_permissive = 0;
291 /* -dA causes debug commentary information to be produced in
292 the generated assembly code (to make it more readable). This option
293 is generally only of use to those who actually need to read the
294 generated assembly code (perhaps while debugging the compiler itself).
295 Currently, this switch is only used by dwarfout.c; however, it is intended
296 to be a catchall for printing debug information in the assembler file. */
298 int flag_debug_asm = 0;
300 /* -dP causes the rtl to be emitted as a comment in assembly. */
302 int flag_dump_rtl_in_asm = 0;
304 /* When non-NULL, indicates that whenever space is allocated on the
305 stack, the resulting stack pointer must not pass this
306 address---that is, for stacks that grow downward, the stack pointer
307 must always be greater than or equal to this address; for stacks
308 that grow upward, the stack pointer must be less than this address.
309 At present, the rtx may be either a REG or a SYMBOL_REF, although
310 the support provided depends on the backend. */
313 /* Nonzero if we should track variables. When
314 flag_var_tracking == AUTODETECT_VALUE it will be set according
315 to optimize, debug_info_level and debug_hooks in process_options (). */
316 int flag_var_tracking = AUTODETECT_VALUE;
318 /* True if the user has tagged the function with the 'section'
321 bool user_defined_section_attribute = false;
323 /* Values of the -falign-* flags: how much to align labels in code.
324 0 means `use default', 1 means `don't align'.
325 For each variable, there is an _log variant which is the power
326 of two not less than the variable, for .align output. */
329 int align_loops_max_skip;
331 int align_jumps_max_skip;
332 int align_labels_log;
333 int align_labels_max_skip;
334 int align_functions_log;
338 const char *const string;
342 lang_independent_options;
344 /* Nonzero if subexpressions must be evaluated from left-to-right. */
345 int flag_evaluation_order = 0;
347 /* The user symbol prefix after having resolved same. */
348 const char *user_label_prefix;
350 static const param_info lang_independent_params[] = {
351 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
352 { OPTION, DEFAULT, false, MIN, MAX, HELP },
353 #include "params.def"
355 { NULL, 0, false, 0, 0, NULL }
358 /* Output files for assembler code (real compiler output)
359 and debugging dumps. */
363 FILE *dump_file = NULL;
364 const char *dump_file_name;
366 /* The current working directory of a translation. It's generally the
367 directory from which compilation was initiated, but a preprocessed
368 file may specify the original directory in which it was
371 static const char *src_pwd;
373 /* Initialize src_pwd with the given string, and return true. If it
374 was already initialized, return false. As a special case, it may
375 be called with a NULL argument to test whether src_pwd has NOT been
379 set_src_pwd (const char *pwd)
383 if (strcmp (src_pwd, pwd) == 0)
389 src_pwd = xstrdup (pwd);
393 /* Return the directory from which the translation unit was initiated,
394 in case set_src_pwd() was not called before to assign it a
410 /* Called when the start of a function definition is parsed,
411 this function prints on stderr the name of the function. */
413 announce_function (tree decl)
417 if (rtl_dump_and_exit)
418 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
420 fprintf (stderr, " %s", lang_hooks.decl_printable_name (decl, 2));
422 pp_needs_newline (global_dc->printer) = true;
423 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
427 /* Initialize local_tick with the time of day, or -1 if
428 flag_random_seed is set. */
431 init_local_tick (void)
433 if (!flag_random_seed)
435 /* Get some more or less random data. */
436 #ifdef HAVE_GETTIMEOFDAY
440 gettimeofday (&tv, NULL);
441 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
445 time_t now = time (NULL);
447 if (now != (time_t)-1)
448 local_tick = (unsigned) now;
456 /* Set up a default flag_random_seed and local_tick, unless the user
457 already specified one. Must be called after init_local_tick. */
460 init_random_seed (void)
462 unsigned HOST_WIDE_INT value;
463 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
465 value = local_tick ^ getpid ();
467 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
468 flag_random_seed = random_seed;
471 /* Obtain the random_seed string. Unless NOINIT, initialize it if
472 it's not provided in the command line. */
475 get_random_seed (bool noinit)
477 if (!flag_random_seed && !noinit)
479 return flag_random_seed;
482 /* Modify the random_seed string to VAL. Return its previous
486 set_random_seed (const char *val)
488 const char *old = flag_random_seed;
489 flag_random_seed = val;
493 /* Decode the string P as an integral parameter.
494 If the string is indeed an integer return its numeric value else
495 issue an Invalid Option error for the option PNAME and return DEFVAL.
496 If PNAME is zero just return DEFVAL, do not call error. */
499 read_integral_parameter (const char *p, const char *pname, const int defval)
501 const char *endp = p;
514 error ("invalid option argument %qs", pname);
521 /* When compiling with a recent enough GCC, we use the GNU C "extern inline"
522 for floor_log2 and exact_log2; see toplev.h. That construct, however,
523 conflicts with the ISO C++ One Definition Rule. */
525 #if GCC_VERSION < 3004 || !defined (__cplusplus)
527 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
528 If X is 0, return -1. */
531 floor_log2 (unsigned HOST_WIDE_INT x)
539 t = HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x);
541 if (HOST_BITS_PER_WIDE_INT > 64)
542 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
544 if (HOST_BITS_PER_WIDE_INT > 32)
545 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
547 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
549 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
551 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
553 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
555 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
562 /* Return the logarithm of X, base 2, considering X unsigned,
563 if X is a power of 2. Otherwise, returns -1. */
566 exact_log2 (unsigned HOST_WIDE_INT x)
571 return x ? CTZ_HWI (x) : -1;
573 return floor_log2 (x);
577 #endif /* GCC_VERSION < 3004 || !defined (__cplusplus) */
579 /* Handler for fatal signals, such as SIGSEGV. These are transformed
580 into ICE messages, which is much more user friendly. In case the
581 error printer crashes, reset the signal to prevent infinite recursion. */
584 crash_signal (int signo)
586 signal (signo, SIG_DFL);
588 /* If we crashed while processing an ASM statement, then be a little more
589 graceful. It's most likely the user's fault. */
590 if (this_is_asm_operands)
592 output_operand_lossage ("unrecoverable error");
593 exit (FATAL_EXIT_CODE);
596 internal_error ("%s", strsignal (signo));
599 /* Arrange to dump core on error. (The regular error message is still
600 printed first, except in the case of abort().) */
603 setup_core_dumping (void)
606 signal (SIGABRT, SIG_DFL);
608 #if defined(HAVE_SETRLIMIT)
611 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
612 fatal_error ("getting core file size maximum limit: %m");
613 rlim.rlim_cur = rlim.rlim_max;
614 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
615 fatal_error ("setting core file size limit to maximum: %m");
618 diagnostic_abort_on_error (global_dc);
622 /* Strip off a legitimate source ending from the input string NAME of
623 length LEN. Rather than having to know the names used by all of
624 our front ends, we strip off an ending of a period followed by
625 up to five characters. (Java uses ".class".) */
628 strip_off_ending (char *name, int len)
631 for (i = 2; i < 6 && len > i; i++)
633 if (name[len - i] == '.')
635 name[len - i] = '\0';
641 /* Output a quoted string. */
644 output_quoted_string (FILE *asm_file, const char *string)
646 #ifdef OUTPUT_QUOTED_STRING
647 OUTPUT_QUOTED_STRING (asm_file, string);
651 putc ('\"', asm_file);
652 while ((c = *string++) != 0)
656 if (c == '\"' || c == '\\')
657 putc ('\\', asm_file);
661 fprintf (asm_file, "\\%03o", (unsigned char) c);
663 putc ('\"', asm_file);
667 /* Output a file name in the form wanted by System V. */
670 output_file_directive (FILE *asm_file, const char *input_name)
675 if (input_name == NULL)
676 input_name = "<stdin>";
678 input_name = remap_debug_filename (input_name);
680 len = strlen (input_name);
681 na = input_name + len;
683 /* NA gets INPUT_NAME sans directory names. */
684 while (na > input_name)
686 if (IS_DIR_SEPARATOR (na[-1]))
691 #ifdef ASM_OUTPUT_SOURCE_FILENAME
692 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
694 fprintf (asm_file, "\t.file\t");
695 output_quoted_string (asm_file, na);
696 fputc ('\n', asm_file);
700 /* A subroutine of wrapup_global_declarations. We've come to the end of
701 the compilation unit. All deferred variables should be undeferred,
702 and all incomplete decls should be finalized. */
705 wrapup_global_declaration_1 (tree decl)
707 /* We're not deferring this any longer. Assignment is conditional to
708 avoid needlessly dirtying PCH pages. */
709 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
710 && DECL_DEFER_OUTPUT (decl) != 0)
711 DECL_DEFER_OUTPUT (decl) = 0;
713 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
714 lang_hooks.finish_incomplete_decl (decl);
717 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
718 needs to be output. Return true if it is output. */
721 wrapup_global_declaration_2 (tree decl)
723 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
726 /* Don't write out static consts, unless we still need them.
728 We also keep static consts if not optimizing (for debugging),
729 unless the user specified -fno-keep-static-consts.
730 ??? They might be better written into the debug information.
731 This is possible when using DWARF.
733 A language processor that wants static constants to be always
734 written out (even if it is not used) is responsible for
735 calling rest_of_decl_compilation itself. E.g. the C front-end
736 calls rest_of_decl_compilation from finish_decl.
737 One motivation for this is that is conventional in some
738 environments to write things like:
739 static const char rcsid[] = "... version string ...";
740 intending to force the string to be in the executable.
742 A language processor that would prefer to have unneeded
743 static constants "optimized away" would just defer writing
744 them out until here. E.g. C++ does this, because static
745 constants are often defined in header files.
747 ??? A tempting alternative (for both C and C++) would be
748 to force a constant to be written if and only if it is
749 defined in a main file, as opposed to an include file. */
751 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
753 struct varpool_node *node;
755 node = varpool_node (decl);
759 else if (node->alias)
761 else if (!cgraph_global_info_ready
763 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
765 else if (node->needed)
767 else if (DECL_COMDAT (decl))
769 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
770 && (optimize || !flag_keep_static_consts
771 || DECL_ARTIFICIAL (decl)))
776 rest_of_decl_compilation (decl, 1, 1);
784 /* Do any final processing required for the declarations in VEC, of
785 which there are LEN. We write out inline functions and variables
786 that have been deferred until this point, but which are required.
787 Returns nonzero if anything was put out. */
790 wrapup_global_declarations (tree *vec, int len)
792 bool reconsider, output_something = false;
795 for (i = 0; i < len; i++)
796 wrapup_global_declaration_1 (vec[i]);
798 /* Now emit any global variables or functions that we have been
799 putting off. We need to loop in case one of the things emitted
800 here references another one which comes earlier in the list. */
804 for (i = 0; i < len; i++)
805 reconsider |= wrapup_global_declaration_2 (vec[i]);
807 output_something = true;
811 return output_something;
814 /* A subroutine of check_global_declarations. Issue appropriate warnings
815 for the global declaration DECL. */
818 check_global_declaration_1 (tree decl)
820 /* Warn about any function declared static but not defined. We don't
821 warn about variables, because many programs have static variables
822 that exist only to get some text into the object file. */
823 if (TREE_CODE (decl) == FUNCTION_DECL
824 && DECL_INITIAL (decl) == 0
825 && DECL_EXTERNAL (decl)
826 && ! DECL_ARTIFICIAL (decl)
827 && ! TREE_NO_WARNING (decl)
828 && ! TREE_PUBLIC (decl)
829 && (warn_unused_function
830 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
832 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
833 pedwarn ("%q+F used but never defined", decl);
835 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
836 /* This symbol is effectively an "extern" declaration now. */
837 TREE_PUBLIC (decl) = 1;
838 assemble_external (decl);
841 /* Warn about static fns or vars defined but not used. */
842 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
843 /* We don't warn about "static const" variables because the
844 "rcs_id" idiom uses that construction. */
845 || (warn_unused_variable
846 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
847 && ! DECL_IN_SYSTEM_HEADER (decl)
848 && ! TREE_USED (decl)
849 /* The TREE_USED bit for file-scope decls is kept in the identifier,
850 to handle multiple external decls in different scopes. */
851 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
852 && ! DECL_EXTERNAL (decl)
853 && ! TREE_PUBLIC (decl)
854 /* A volatile variable might be used in some non-obvious way. */
855 && ! TREE_THIS_VOLATILE (decl)
856 /* Global register variables must be declared to reserve them. */
857 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
858 /* Otherwise, ask the language. */
859 && lang_hooks.decls.warn_unused_global (decl))
860 warning ((TREE_CODE (decl) == FUNCTION_DECL)
861 ? OPT_Wunused_function
862 : OPT_Wunused_variable,
863 "%q+D defined but not used", decl);
866 /* Issue appropriate warnings for the global declarations in VEC (of
867 which there are LEN). */
870 check_global_declarations (tree *vec, int len)
874 for (i = 0; i < len; i++)
875 check_global_declaration_1 (vec[i]);
878 /* Emit debugging information for all global declarations in VEC. */
881 emit_debug_global_declarations (tree *vec, int len)
885 /* Avoid confusing the debug information machinery when there are errors. */
886 if (errorcount != 0 || sorrycount != 0)
889 timevar_push (TV_SYMOUT);
890 for (i = 0; i < len; i++)
891 debug_hooks->global_decl (vec[i]);
892 timevar_pop (TV_SYMOUT);
895 /* Warn about a use of an identifier which was marked deprecated. */
897 warn_deprecated_use (tree node)
899 if (node == 0 || !warn_deprecated_decl)
904 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
905 warning (OPT_Wdeprecated_declarations,
906 "%qD is deprecated (declared at %s:%d)",
907 node, xloc.file, xloc.line);
909 else if (TYPE_P (node))
911 const char *what = NULL;
912 tree decl = TYPE_STUB_DECL (node);
914 if (TYPE_NAME (node))
916 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
917 what = IDENTIFIER_POINTER (TYPE_NAME (node));
918 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
919 && DECL_NAME (TYPE_NAME (node)))
920 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
925 expanded_location xloc
926 = expand_location (DECL_SOURCE_LOCATION (decl));
928 warning (OPT_Wdeprecated_declarations,
929 "%qs is deprecated (declared at %s:%d)", what,
930 xloc.file, xloc.line);
932 warning (OPT_Wdeprecated_declarations,
933 "type is deprecated (declared at %s:%d)",
934 xloc.file, xloc.line);
939 warning (OPT_Wdeprecated_declarations, "%qs is deprecated", what);
941 warning (OPT_Wdeprecated_declarations, "type is deprecated");
946 /* Compile an entire translation unit. Write a file of assembly
947 output and various debugging dumps. */
952 /* Initialize yet another pass. */
955 init_final (main_input_filename);
956 coverage_init (aux_base_name);
959 timevar_push (TV_PARSE);
961 /* Call the parser, which parses the entire file (calling
962 rest_of_compilation for each function). */
963 lang_hooks.parse_file (set_yydebug);
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. */
1074 setup_core_dumping();
1077 enable_rtl_dump_file ();
1081 warning (0, "unrecognized gcc debugging option: %c", c);
1086 /* Indexed by enum debug_info_type. */
1087 const char *const debug_type_names[] =
1089 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1092 /* Print version information to FILE.
1093 Each line begins with INDENT (for the case where FILE is the
1094 assembler output file). */
1097 print_version (FILE *file, const char *indent)
1099 static const char fmt1[] =
1101 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1103 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1106 static const char fmt2[] =
1107 N_("GMP version %s, MPFR version %s.\n");
1108 static const char fmt3[] =
1109 N_("%s%swarning: %s header version %s differs from library version %s.\n");
1110 static const char fmt4[] =
1111 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1113 #define __VERSION__ "[?]"
1116 file == stderr ? _(fmt1) : fmt1,
1117 indent, *indent != 0 ? " " : "",
1118 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
1119 indent, __VERSION__);
1121 /* We need to stringify the GMP macro values. Ugh, gmp_version has
1122 two string formats, "i.j.k" and "i.j" when k is zero. */
1123 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1124 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1125 #if __GNU_MP_VERSION_PATCHLEVEL == 0
1126 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1127 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1129 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1130 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1131 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1134 file == stderr ? _(fmt2) : fmt2,
1135 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING);
1136 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
1138 file == stderr ? _(fmt3) : fmt3,
1139 indent, *indent != 0 ? " " : "",
1140 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
1141 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
1143 file == stderr ? _(fmt3) : fmt3,
1144 indent, *indent != 0 ? " " : "",
1145 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
1147 file == stderr ? _(fmt4) : fmt4,
1148 indent, *indent != 0 ? " " : "",
1149 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1152 #ifdef ASM_COMMENT_START
1154 print_to_asm_out_file (print_switch_type type, const char * text)
1156 bool prepend_sep = true;
1160 case SWITCH_TYPE_LINE_END:
1161 putc ('\n', asm_out_file);
1164 case SWITCH_TYPE_LINE_START:
1165 fputs (ASM_COMMENT_START, asm_out_file);
1166 return strlen (ASM_COMMENT_START);
1168 case SWITCH_TYPE_DESCRIPTIVE:
1169 if (ASM_COMMENT_START[0] == 0)
1170 prepend_sep = false;
1172 case SWITCH_TYPE_PASSED:
1173 case SWITCH_TYPE_ENABLED:
1175 fputc (' ', asm_out_file);
1176 fprintf (asm_out_file, text);
1177 /* No need to return the length here as
1178 print_single_switch has already done it. */
1188 print_to_stderr (print_switch_type type, const char * text)
1192 case SWITCH_TYPE_LINE_END:
1193 putc ('\n', stderr);
1196 case SWITCH_TYPE_LINE_START:
1199 case SWITCH_TYPE_PASSED:
1200 case SWITCH_TYPE_ENABLED:
1201 fputc (' ', stderr);
1204 case SWITCH_TYPE_DESCRIPTIVE:
1205 fprintf (stderr, text);
1206 /* No need to return the length here as
1207 print_single_switch has already done it. */
1215 /* Print an option value and return the adjusted position in the line.
1216 ??? print_fn doesn't handle errors, eg disk full; presumably other
1217 code will catch a disk full though. */
1220 print_single_switch (print_switch_fn_type print_fn,
1222 print_switch_type type,
1225 /* The ultrix fprintf returns 0 on success, so compute the result
1226 we want here since we need it for the following test. The +1
1227 is for the separator character that will probably be emitted. */
1228 int len = strlen (text) + 1;
1231 && pos + len > MAX_LINE)
1233 print_fn (SWITCH_TYPE_LINE_END, NULL);
1238 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1240 print_fn (type, text);
1244 /* Print active target switches using PRINT_FN.
1245 POS is the current cursor position and MAX is the size of a "line".
1246 Each line begins with INDENT and ends with TERM.
1247 Each switch is separated from the next by SEP. */
1250 print_switch_values (print_switch_fn_type print_fn)
1256 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1257 that it can be printed below. This helps reproducibility. */
1258 if (!flag_random_seed)
1259 init_random_seed ();
1261 /* Print the options as passed. */
1262 pos = print_single_switch (print_fn, pos,
1263 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1265 for (p = &save_argv[1]; *p != NULL; p++)
1270 if (strcmp (*p, "-o") == 0
1271 || strcmp (*p, "-dumpbase") == 0
1272 || strcmp (*p, "-auxbase") == 0)
1279 if (strcmp (*p, "-quiet") == 0
1280 || strcmp (*p, "-version") == 0)
1287 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED, *p);
1291 print_fn (SWITCH_TYPE_LINE_END, NULL);
1293 /* Print the -f and -m options that have been enabled.
1294 We don't handle language specific options but printing argv
1296 pos = print_single_switch (print_fn, 0,
1297 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1299 for (j = 0; j < cl_options_count; j++)
1300 if ((cl_options[j].flags & CL_REPORT)
1301 && option_enabled (j) > 0)
1302 pos = print_single_switch (print_fn, pos,
1303 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1305 print_fn (SWITCH_TYPE_LINE_END, NULL);
1308 /* Open assembly code output file. Do this even if -fsyntax-only is
1309 on, because then the driver will have provided the name of a
1310 temporary file or bit bucket for us. NAME is the file specified on
1311 the command line, possibly NULL. */
1313 init_asm_output (const char *name)
1315 if (name == NULL && asm_file_name == 0)
1316 asm_out_file = stdout;
1319 if (asm_file_name == 0)
1321 int len = strlen (dump_base_name);
1322 char *dumpname = XNEWVEC (char, len + 6);
1324 memcpy (dumpname, dump_base_name, len + 1);
1325 strip_off_ending (dumpname, len);
1326 strcat (dumpname, ".s");
1327 asm_file_name = dumpname;
1329 if (!strcmp (asm_file_name, "-"))
1330 asm_out_file = stdout;
1332 asm_out_file = fopen (asm_file_name, "w+b");
1333 if (asm_out_file == 0)
1334 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1337 if (!flag_syntax_only)
1339 targetm.asm_out.file_start ();
1341 if (flag_record_gcc_switches)
1343 if (targetm.asm_out.record_gcc_switches)
1345 /* Let the target know that we are about to start recording. */
1346 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1348 /* Now record the switches. */
1349 print_switch_values (targetm.asm_out.record_gcc_switches);
1350 /* Let the target know that the recording is over. */
1351 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1355 inform ("-frecord-gcc-switches is not supported by the current target");
1358 #ifdef ASM_COMMENT_START
1359 if (flag_verbose_asm)
1361 /* Print the list of switches in effect
1362 into the assembler file as comments. */
1363 print_version (asm_out_file, ASM_COMMENT_START);
1364 print_switch_values (print_to_asm_out_file);
1365 fprintf (asm_out_file, "\n");
1371 /* Return true if the state of option OPTION should be stored in PCH files
1372 and checked by default_pch_valid_p. Store the option's current state
1376 option_affects_pch_p (int option, struct cl_option_state *state)
1378 if ((cl_options[option].flags & CL_TARGET) == 0)
1380 if (cl_options[option].flag_var == &target_flags)
1381 if (targetm.check_pch_target_flags)
1383 return get_option_state (option, state);
1386 /* Default version of get_pch_validity.
1387 By default, every flag difference is fatal; that will be mostly right for
1388 most targets, but completely right for very few. */
1391 default_get_pch_validity (size_t *len)
1393 struct cl_option_state state;
1398 if (targetm.check_pch_target_flags)
1399 *len += sizeof (target_flags);
1400 for (i = 0; i < cl_options_count; i++)
1401 if (option_affects_pch_p (i, &state))
1404 result = r = XNEWVEC (char, *len);
1408 if (targetm.check_pch_target_flags)
1410 memcpy (r, &target_flags, sizeof (target_flags));
1411 r += sizeof (target_flags);
1414 for (i = 0; i < cl_options_count; i++)
1415 if (option_affects_pch_p (i, &state))
1417 memcpy (r, state.data, state.size);
1424 /* Return a message which says that a PCH file was created with a different
1425 setting of OPTION. */
1428 pch_option_mismatch (const char *option)
1432 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1434 return _("out of memory");
1438 /* Default version of pch_valid_p. */
1441 default_pch_valid_p (const void *data_p, size_t len)
1443 struct cl_option_state state;
1444 const char *data = (const char *)data_p;
1447 /* -fpic and -fpie also usually make a PCH invalid. */
1448 if (data[0] != flag_pic)
1449 return _("created and used with different settings of -fpic");
1450 if (data[1] != flag_pie)
1451 return _("created and used with different settings of -fpie");
1454 /* Check target_flags. */
1455 if (targetm.check_pch_target_flags)
1460 memcpy (&tf, data, sizeof (target_flags));
1461 data += sizeof (target_flags);
1462 len -= sizeof (target_flags);
1463 r = targetm.check_pch_target_flags (tf);
1468 for (i = 0; i < cl_options_count; i++)
1469 if (option_affects_pch_p (i, &state))
1471 if (memcmp (data, state.data, state.size) != 0)
1472 return pch_option_mismatch (cl_options[i].opt_text);
1480 /* Default tree printer. Handles declarations only. */
1482 default_tree_printer (pretty_printer * pp, text_info *text, const char *spec,
1483 int precision, bool wide, bool set_locus, bool hash)
1487 /* FUTURE: %+x should set the locus. */
1488 if (precision != 0 || wide || hash)
1494 t = va_arg (*text->args_ptr, tree);
1495 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1496 t = DECL_DEBUG_EXPR (t);
1501 t = va_arg (*text->args_ptr, tree);
1508 if (set_locus && text->locus)
1509 *text->locus = DECL_SOURCE_LOCATION (t);
1513 const char *n = DECL_NAME (t)
1514 ? lang_hooks.decl_printable_name (t, 2)
1519 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1524 /* A helper function; used as the reallocator function for cpp's line
1527 realloc_for_line_map (void *ptr, size_t len)
1529 return ggc_realloc (ptr, len);
1532 /* Initialization of the front end environment, before command line
1533 options are parsed. Signal handlers, internationalization etc.
1534 ARGV0 is main's argv[0]. */
1536 general_init (const char *argv0)
1540 p = argv0 + strlen (argv0);
1541 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1545 xmalloc_set_program_name (progname);
1549 /* Unlock the stdio streams. */
1550 unlock_std_streams ();
1552 gcc_init_libintl ();
1554 /* Initialize the diagnostics reporting machinery, so option parsing
1555 can give warnings and errors. */
1556 diagnostic_initialize (global_dc);
1557 /* Set a default printer. Language specific initializations will
1558 override it later. */
1559 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1561 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1563 signal (SIGSEGV, crash_signal);
1566 signal (SIGILL, crash_signal);
1569 signal (SIGBUS, crash_signal);
1572 signal (SIGABRT, crash_signal);
1574 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1575 signal (SIGIOT, crash_signal);
1578 signal (SIGFPE, crash_signal);
1581 /* Other host-specific signal setup. */
1582 (*host_hooks.extra_signals)();
1584 /* Initialize the garbage-collector, string pools and tree type hash
1588 line_table = GGC_NEW (struct line_maps);
1589 linemap_init (line_table);
1590 line_table->reallocator = realloc_for_line_map;
1593 /* Initialize register usage now so switches may override. */
1596 /* Register the language-independent parameters. */
1597 add_params (lang_independent_params, LAST_PARAM);
1599 /* This must be done after add_params but before argument processing. */
1600 init_ggc_heuristics();
1601 init_optimization_passes ();
1602 statistics_early_init ();
1605 /* Return true if the current target supports -fsection-anchors. */
1608 target_supports_section_anchors_p (void)
1610 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1613 if (targetm.asm_out.output_anchor == NULL)
1619 /* Default the align_* variables to 1 if they're still unset, and
1620 set up the align_*_log variables. */
1622 init_alignments (void)
1624 if (align_loops <= 0)
1626 if (align_loops_max_skip > align_loops)
1627 align_loops_max_skip = align_loops - 1;
1628 align_loops_log = floor_log2 (align_loops * 2 - 1);
1629 if (align_jumps <= 0)
1631 if (align_jumps_max_skip > align_jumps)
1632 align_jumps_max_skip = align_jumps - 1;
1633 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1634 if (align_labels <= 0)
1636 align_labels_log = floor_log2 (align_labels * 2 - 1);
1637 if (align_labels_max_skip > align_labels)
1638 align_labels_max_skip = align_labels - 1;
1639 if (align_functions <= 0)
1640 align_functions = 1;
1641 align_functions_log = floor_log2 (align_functions * 2 - 1);
1644 /* Process the options that have been parsed. */
1646 process_options (void)
1648 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1649 This can happen with incorrect pre-processed input. */
1650 debug_hooks = &do_nothing_debug_hooks;
1652 /* Allow the front end to perform consistency checks and do further
1653 initialization based on the command line options. This hook also
1654 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1655 so we can correctly initialize debug output. */
1656 no_backend = lang_hooks.post_options (&main_input_filename);
1658 #ifdef OVERRIDE_OPTIONS
1659 /* Some machines may reject certain combinations of options. */
1663 if (flag_section_anchors && !target_supports_section_anchors_p ())
1665 warning (OPT_fsection_anchors,
1666 "this target does not support %qs", "-fsection-anchors");
1667 flag_section_anchors = 0;
1670 if (flag_short_enums == 2)
1671 flag_short_enums = targetm.default_short_enums ();
1673 /* Set aux_base_name if not already set. */
1676 else if (main_input_filename)
1678 char *name = xstrdup (lbasename (main_input_filename));
1680 strip_off_ending (name, strlen (name));
1681 aux_base_name = name;
1684 aux_base_name = "gccaux";
1686 /* Unrolling all loops implies that standard loop unrolling must also
1688 if (flag_unroll_all_loops)
1689 flag_unroll_loops = 1;
1691 /* The loop unrolling code assumes that cse will be run after loop.
1692 web and rename-registers also help when run after loop unrolling. */
1694 if (flag_rerun_cse_after_loop == AUTODETECT_VALUE)
1695 flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops;
1696 if (flag_web == AUTODETECT_VALUE)
1697 flag_web = flag_unroll_loops || flag_peel_loops;
1698 if (flag_rename_registers == AUTODETECT_VALUE)
1699 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1701 if (flag_non_call_exceptions)
1702 flag_asynchronous_unwind_tables = 1;
1703 if (flag_asynchronous_unwind_tables)
1704 flag_unwind_tables = 1;
1706 if (!flag_unit_at_a_time)
1707 flag_section_anchors = 0;
1709 if (flag_value_profile_transformations)
1710 flag_profile_values = 1;
1712 /* Warn about options that are not supported on this machine. */
1713 #ifndef INSN_SCHEDULING
1714 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1715 warning (0, "instruction scheduling not supported on this target machine");
1718 if (flag_delayed_branch)
1719 warning (0, "this target machine does not have delayed branches");
1722 user_label_prefix = USER_LABEL_PREFIX;
1723 if (flag_leading_underscore != -1)
1725 /* If the default prefix is more complicated than "" or "_",
1726 issue a warning and ignore this option. */
1727 if (user_label_prefix[0] == 0 ||
1728 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1730 user_label_prefix = flag_leading_underscore ? "_" : "";
1733 warning (0, "-f%sleading-underscore not supported on this target machine",
1734 flag_leading_underscore ? "" : "no-");
1737 /* If we are in verbose mode, write out the version and maybe all the
1738 option flags in use. */
1741 print_version (stderr, "");
1743 print_switch_values (print_to_stderr);
1746 if (flag_syntax_only)
1748 write_symbols = NO_DEBUG;
1752 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1754 if (debug_info_level == DINFO_LEVEL_NONE)
1755 write_symbols = NO_DEBUG;
1757 /* Now we know write_symbols, set up the debug hooks based on it.
1758 By default we do nothing for debug output. */
1759 if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG)
1760 default_debug_hooks = &do_nothing_debug_hooks;
1761 #if defined(DBX_DEBUGGING_INFO)
1762 else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG)
1763 default_debug_hooks = &dbx_debug_hooks;
1765 #if defined(XCOFF_DEBUGGING_INFO)
1766 else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG)
1767 default_debug_hooks = &xcoff_debug_hooks;
1769 #ifdef SDB_DEBUGGING_INFO
1770 else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG)
1771 default_debug_hooks = &sdb_debug_hooks;
1773 #ifdef DWARF2_DEBUGGING_INFO
1774 else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG)
1775 default_debug_hooks = &dwarf2_debug_hooks;
1777 #ifdef VMS_DEBUGGING_INFO
1778 else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG
1779 || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG)
1780 default_debug_hooks = &vmsdbg_debug_hooks;
1783 if (write_symbols == NO_DEBUG)
1785 #if defined(DBX_DEBUGGING_INFO)
1786 else if (write_symbols == DBX_DEBUG)
1787 debug_hooks = &dbx_debug_hooks;
1789 #if defined(XCOFF_DEBUGGING_INFO)
1790 else if (write_symbols == XCOFF_DEBUG)
1791 debug_hooks = &xcoff_debug_hooks;
1793 #ifdef SDB_DEBUGGING_INFO
1794 else if (write_symbols == SDB_DEBUG)
1795 debug_hooks = &sdb_debug_hooks;
1797 #ifdef DWARF2_DEBUGGING_INFO
1798 else if (write_symbols == DWARF2_DEBUG)
1799 debug_hooks = &dwarf2_debug_hooks;
1801 #ifdef VMS_DEBUGGING_INFO
1802 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1803 debug_hooks = &vmsdbg_debug_hooks;
1806 error ("target system does not support the \"%s\" debug format",
1807 debug_type_names[write_symbols]);
1809 /* Now we know which debug output will be used so we can set
1810 flag_var_tracking, flag_rename_registers if the user has
1811 not specified them. */
1812 if (debug_info_level < DINFO_LEVEL_NORMAL
1813 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1815 if (flag_var_tracking == 1
1816 || flag_var_tracking_uninit == 1)
1818 if (debug_info_level < DINFO_LEVEL_NORMAL)
1819 warning (0, "variable tracking requested, but useless unless "
1820 "producing debug info");
1822 warning (0, "variable tracking requested, but not supported "
1823 "by this debug format");
1825 flag_var_tracking = 0;
1826 flag_var_tracking_uninit = 0;
1829 if (flag_rename_registers == AUTODETECT_VALUE)
1830 flag_rename_registers = default_debug_hooks->var_location
1831 != do_nothing_debug_hooks.var_location;
1833 if (flag_var_tracking == AUTODETECT_VALUE)
1834 flag_var_tracking = optimize >= 1;
1836 if (flag_tree_cselim == AUTODETECT_VALUE)
1837 #ifdef HAVE_conditional_move
1838 flag_tree_cselim = 1;
1840 flag_tree_cselim = 0;
1843 /* If the user specifically requested variable tracking with tagging
1844 uninitialized variables, we need to turn on variable tracking.
1845 (We already determined above that variable tracking is feasible.) */
1846 if (flag_var_tracking_uninit)
1847 flag_var_tracking = 1;
1849 /* If auxiliary info generation is desired, open the output file.
1850 This goes in the same directory as the source file--unlike
1851 all the other output files. */
1852 if (flag_gen_aux_info)
1854 aux_info_file = fopen (aux_info_file_name, "w");
1855 if (aux_info_file == 0)
1856 fatal_error ("can%'t open %s: %m", aux_info_file_name);
1859 if (! targetm.have_named_sections)
1861 if (flag_function_sections)
1863 warning (0, "-ffunction-sections not supported for this target");
1864 flag_function_sections = 0;
1866 if (flag_data_sections)
1868 warning (0, "-fdata-sections not supported for this target");
1869 flag_data_sections = 0;
1873 if (flag_function_sections && profile_flag)
1875 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
1876 flag_function_sections = 0;
1879 #ifndef HAVE_prefetch
1880 if (flag_prefetch_loop_arrays)
1882 warning (0, "-fprefetch-loop-arrays not supported for this target");
1883 flag_prefetch_loop_arrays = 0;
1886 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
1888 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
1889 flag_prefetch_loop_arrays = 0;
1893 /* This combination of options isn't handled for i386 targets and doesn't
1894 make much sense anyway, so don't allow it. */
1895 if (flag_prefetch_loop_arrays && optimize_size)
1897 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
1898 flag_prefetch_loop_arrays = 0;
1901 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1902 if (flag_signaling_nans)
1903 flag_trapping_math = 1;
1905 /* We cannot reassociate if we want traps or signed zeros. Â */
1906 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1908 warning (0, "-fassociative-math disabled; other options take precedence");
1909 flag_associative_math = 0;
1912 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1913 if (flag_cx_limited_range)
1914 flag_complex_method = 0;
1916 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1917 if (flag_cx_fortran_rules)
1918 flag_complex_method = 1;
1920 /* Targets must be able to place spill slots at lower addresses. If the
1921 target already uses a soft frame pointer, the transition is trivial. */
1922 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1924 warning (0, "-fstack-protector not supported for this target");
1925 flag_stack_protect = 0;
1927 if (!flag_stack_protect)
1928 warn_stack_protect = 0;
1930 /* ??? Unwind info is not correct around the CFG unless either a frame
1931 pointer is present or A_O_A is set. Fixing this requires rewriting
1932 unwind info generation to be aware of the CFG and propagating states
1934 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
1935 && flag_omit_frame_pointer)
1937 warning (0, "unwind tables currently require a frame pointer "
1939 flag_omit_frame_pointer = 0;
1943 /* This function can be called multiple times to reinitialize the compiler
1944 back end when register classes or instruction sets have changed,
1945 before each function. */
1947 backend_init_target (void)
1949 /* Initialize alignment variables. */
1952 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
1953 to initialize reg_raw_mode[]. */
1956 /* This invokes target hooks to set fixed_reg[] etc, which is
1960 /* This depends on stack_pointer_rtx. */
1961 init_fake_stack_mems ();
1963 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1965 init_alias_target ();
1967 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1970 /* The following initialization functions need to generate rtl, so
1971 provide a dummy function context for them. */
1972 init_dummy_function_start ();
1974 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1975 on a mode change. */
1978 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1979 after a mode change as well. */
1980 if (flag_caller_saves)
1981 init_caller_save ();
1982 expand_dummy_function_end ();
1985 /* Initialize the compiler back end. This function is called only once,
1986 when starting the compiler. */
1990 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
1991 || debug_info_level == DINFO_LEVEL_VERBOSE
1992 #ifdef VMS_DEBUGGING_INFO
1993 /* Enable line number info for traceback. */
1994 || debug_info_level > DINFO_LEVEL_NONE
1996 || flag_test_coverage);
1999 init_inline_once ();
2000 init_varasm_once ();
2001 save_register_info ();
2003 /* Initialize the target-specific back end pieces. */
2004 backend_init_target ();
2007 /* Initialize things that are both lang-dependent and target-dependent.
2008 This function can be called more than once if target parameters change. */
2010 lang_dependent_init_target (void)
2012 /* This creates various _DECL nodes, so needs to be called after the
2013 front end is initialized. It also depends on the HAVE_xxx macros
2014 generated from the target machine description. */
2017 /* The following initialization functions need to generate rtl, so
2018 provide a dummy function context for them. */
2019 init_dummy_function_start ();
2021 /* Do the target-specific parts of expr initialization. */
2022 init_expr_target ();
2024 /* Although the actions of init_set_costs are language-independent,
2025 it uses optabs, so we cannot call it from backend_init. */
2028 expand_dummy_function_end ();
2031 /* Language-dependent initialization. Returns nonzero on success. */
2033 lang_dependent_init (const char *name)
2035 location_t save_loc = input_location;
2036 if (dump_base_name == 0)
2037 dump_base_name = name && name[0] ? name : "gccdump";
2039 /* Other front-end initialization. */
2040 input_location = BUILTINS_LOCATION;
2041 if (lang_hooks.init () == 0)
2043 input_location = save_loc;
2045 init_asm_output (name);
2047 /* This creates various _DECL nodes, so needs to be called after the
2048 front end is initialized. */
2051 /* Do the target-specific parts of the initialization. */
2052 lang_dependent_init_target ();
2054 /* If dbx symbol table desired, initialize writing it and output the
2055 predefined types. */
2056 timevar_push (TV_SYMOUT);
2058 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2059 if (dwarf2out_do_frame ())
2060 dwarf2out_frame_init ();
2063 /* Now we have the correct original filename, we can initialize
2065 (*debug_hooks->init) (name);
2067 timevar_pop (TV_SYMOUT);
2073 /* Reinitialize everything when target parameters, such as register usage,
2076 target_reinit (void)
2078 /* Reinitialize RTL backend. */
2079 backend_init_target ();
2081 /* Reinitialize lang-dependent parts. */
2082 lang_dependent_init_target ();
2086 dump_memory_report (bool final)
2088 ggc_print_statistics ();
2089 stringpool_statistics ();
2090 dump_tree_statistics ();
2091 dump_rtx_statistics ();
2092 dump_varray_statistics ();
2093 dump_alloc_pool_statistics ();
2094 dump_bitmap_statistics ();
2095 dump_ggc_loc_statistics (final);
2098 /* Clean up: close opened files, etc. */
2103 /* Close the dump files. */
2104 if (flag_gen_aux_info)
2106 fclose (aux_info_file);
2108 unlink (aux_info_file_name);
2111 /* Close non-debugging input and output files. Take special care to note
2112 whether fclose returns an error, since the pages might still be on the
2113 buffer chain while the file is open. */
2117 if (ferror (asm_out_file) != 0)
2118 fatal_error ("error writing to %s: %m", asm_file_name);
2119 if (fclose (asm_out_file) != 0)
2120 fatal_error ("error closing %s: %m", asm_file_name);
2124 finish_optimization_passes ();
2127 dump_memory_report (true);
2129 /* Language-specific end of compilation actions. */
2130 lang_hooks.finish ();
2133 /* Initialize the compiler, and compile the input file. */
2137 /* Initialize timing first. The C front ends read the main file in
2138 the post_options hook, and C++ does file timings. */
2139 if (time_report || !quiet_flag || flag_detailed_statistics)
2141 timevar_start (TV_TOTAL);
2145 /* Don't do any more if an error has already occurred. */
2148 /* This must be run always, because it is needed to compute the FP
2149 predefined macros, such as __LDBL_MAX__, for targets using non
2150 default FP formats. */
2151 init_adjust_machine_modes ();
2153 /* Set up the back-end if requested. */
2157 /* Language-dependent initialization. Returns true on success. */
2158 if (lang_dependent_init (main_input_filename))
2164 /* Stop timing and print the times. */
2165 timevar_stop (TV_TOTAL);
2166 timevar_print (stderr);
2169 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2170 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2171 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2173 It is not safe to call this function more than once. */
2176 toplev_main (unsigned int argc, const char **argv)
2180 /* Initialization of GCC's environment, and diagnostics. */
2181 general_init (argv[0]);
2183 /* Parse the options and do minimal processing; basically just
2184 enough to default flags appropriately. */
2185 decode_options (argc, argv);
2189 /* Exit early if we can (e.g. -help). */
2190 if (!exit_after_options)
2193 if (warningcount || errorcount)
2194 print_ignored_options ();
2196 if (errorcount || sorrycount)
2197 return (FATAL_EXIT_CODE);
2199 return (SUCCESS_EXIT_CODE);