1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
29 #include "coretypes.h"
33 #ifdef HAVE_SYS_RESOURCE_H
34 # include <sys/resource.h>
37 #ifdef HAVE_SYS_TIMES_H
38 # include <sys/times.h>
48 #include "insn-attr.h"
49 #include "insn-config.h"
50 #include "insn-flags.h"
51 #include "hard-reg-set.h"
58 #include "basic-block.h"
64 #include "diagnostic.h"
68 #include "dwarf2asm.h"
69 #include "integrate.h"
72 #include "langhooks.h"
73 #include "cfglayout.h"
75 #include "hosthooks.h"
79 #include "value-prof.h"
80 #include "alloc-pool.h"
81 #include "tree-mudflap.h"
82 #include "tree-pass.h"
84 #include "tree-ssa-alias.h"
87 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
88 #include "dwarf2out.h"
91 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
95 #ifdef SDB_DEBUGGING_INFO
99 #ifdef XCOFF_DEBUGGING_INFO
100 #include "xcoffout.h" /* Needed for external data
101 declarations for e.g. AIX 4.x. */
104 static void general_init (const char *);
105 static void do_compile (void);
106 static void process_options (void);
107 static void backend_init (void);
108 static int lang_dependent_init (const char *);
109 static void init_asm_output (const char *);
110 static void finalize (void);
112 static void crash_signal (int) ATTRIBUTE_NORETURN;
113 static void setup_core_dumping (void);
114 static void compile_file (void);
116 /* Nonzero to dump debug info whilst parsing (-dy option). */
117 static int set_yydebug;
119 /* True if we don't need a backend (e.g. preprocessing only). */
120 static bool no_backend;
122 /* Length of line when printing switch values. */
125 /* Name of program invoked, sans directories. */
127 const char *progname;
129 /* Copy of argument vector to toplev_main. */
130 static const char **save_argv;
132 /* Name of top-level original source file (what was input to cpp).
133 This comes from the #-command at the beginning of the actual input.
134 If there isn't any there, then this is the cc1 input file name. */
136 const char *main_input_filename;
138 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
139 to optimize in process_options (). */
140 #define AUTODETECT_VALUE 2
142 /* Current position in real source file. */
144 location_t input_location;
146 struct line_maps *line_table;
148 /* Name to use as base of names for dump output files. */
150 const char *dump_base_name;
152 /* Directory used for dump output files. */
154 const char *dump_dir_name;
156 /* Name to use as a base for auxiliary output files. */
158 const char *aux_base_name;
160 /* Prefix for profile data files */
161 const char *profile_data_prefix;
163 /* A mask of target_flags that includes bit X if X was set or cleared
164 on the command line. */
166 int target_flags_explicit;
168 /* Debug hooks - dependent upon command line options. */
170 const struct gcc_debug_hooks *debug_hooks;
172 /* Other flags saying which kinds of debugging dump have been requested. */
174 int rtl_dump_and_exit;
175 int flag_print_asm_name;
176 enum graph_dump_types graph_dump_format;
178 /* Name for output file of assembly code, specified with -o. */
180 const char *asm_file_name;
182 /* Nonzero means do optimizations. -O.
183 Particular numeric values stand for particular amounts of optimization;
184 thus, -O2 stores 2 here. However, the optimizations beyond the basic
185 ones are not controlled directly by this variable. Instead, they are
186 controlled by individual `flag_...' variables that are defaulted
187 based on this variable. */
191 /* Nonzero means optimize for size. -Os.
192 The only valid values are zero and nonzero. When optimize_size is
193 nonzero, optimize defaults to 2, but certain individual code
194 bloating optimizations are disabled. */
196 int optimize_size = 0;
198 /* True if this is the lto front end. This is used to disable
199 gimple generation and lowering passes that are normally run on the
200 output of a front end. These passes must be bypassed for lto since
201 they have already been done before the gimple was written. */
203 bool in_lto_p = false;
205 /* Nonzero if we should write GIMPLE bytecode for link-time optimization. */
207 int flag_generate_lto;
209 /* The FUNCTION_DECL for the function currently being compiled,
210 or 0 if between functions. */
211 tree current_function_decl;
213 /* Set to the FUNC_BEGIN label of the current function, or NULL
215 const char * current_function_func_begin_label;
217 /* Nonzero means to collect statistics which might be expensive
218 and to print them when we are done. */
219 int flag_detailed_statistics = 0;
221 /* A random sequence of characters, unless overridden by user. */
222 static const char *flag_random_seed;
224 /* A local time stamp derived from the time of compilation. It will be
225 zero if the system cannot provide a time. It will be -1u, if the
226 user has specified a particular random seed. */
231 /* Nonzero means `char' should be signed. */
233 int flag_signed_char;
235 /* Nonzero means give an enum type only as many bytes as it needs. A value
236 of 2 means it has not yet been initialized. */
238 int flag_short_enums;
240 /* Nonzero if structures and unions should be returned in memory.
242 This should only be defined if compatibility with another compiler or
243 with an ABI is needed, because it results in slower code. */
245 #ifndef DEFAULT_PCC_STRUCT_RETURN
246 #define DEFAULT_PCC_STRUCT_RETURN 1
249 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
251 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
253 /* 0 means straightforward implementation of complex divide acceptable.
254 1 means wide ranges of inputs must work for complex divide.
255 2 means C99-like requirements for complex multiply and divide. */
257 int flag_complex_method = 1;
259 /* Nonzero means we should be saving declaration info into a .X file. */
261 int flag_gen_aux_info = 0;
263 /* Specified name of aux-info file. */
265 const char *aux_info_file_name;
267 /* Nonzero if we are compiling code for a shared library, zero for
272 /* Generate code for GNU or NeXT Objective-C runtime environment. */
274 #ifdef NEXT_OBJC_RUNTIME
275 int flag_next_runtime = 1;
277 int flag_next_runtime = 0;
280 /* Set to the default thread-local storage (tls) model to use. */
282 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
284 /* Set the default region and algorithm for the integrated register
287 enum ira_algorithm flag_ira_algorithm = IRA_ALGORITHM_CB;
288 enum ira_region flag_ira_region = IRA_REGION_MIXED;
290 /* Set the default value for -fira-verbose. */
292 unsigned int flag_ira_verbose = 5;
294 /* Set the default for excess precision. */
296 enum excess_precision flag_excess_precision_cmdline = EXCESS_PRECISION_DEFAULT;
297 enum excess_precision flag_excess_precision = EXCESS_PRECISION_DEFAULT;
299 /* Nonzero means change certain warnings into errors.
300 Usually these are warnings about failure to conform to some standard. */
302 int flag_pedantic_errors = 0;
304 /* Nonzero means make permerror produce warnings instead of errors. */
306 int flag_permissive = 0;
308 /* -dA causes debug commentary information to be produced in
309 the generated assembly code (to make it more readable). This option
310 is generally only of use to those who actually need to read the
311 generated assembly code (perhaps while debugging the compiler itself).
312 Currently, this switch is only used by dwarfout.c; however, it is intended
313 to be a catchall for printing debug information in the assembler file. */
315 int flag_debug_asm = 0;
317 /* -dP causes the rtl to be emitted as a comment in assembly. */
319 int flag_dump_rtl_in_asm = 0;
321 /* When non-NULL, indicates that whenever space is allocated on the
322 stack, the resulting stack pointer must not pass this
323 address---that is, for stacks that grow downward, the stack pointer
324 must always be greater than or equal to this address; for stacks
325 that grow upward, the stack pointer must be less than this address.
326 At present, the rtx may be either a REG or a SYMBOL_REF, although
327 the support provided depends on the backend. */
330 /* Positive if we should track variables, negative if we should run
331 the var-tracking pass only to discard debug annotations, zero if
332 we're not to run it. When flag_var_tracking == AUTODETECT_VALUE it
333 will be set according to optimize, debug_info_level and debug_hooks
334 in process_options (). */
335 int flag_var_tracking = AUTODETECT_VALUE;
337 /* Positive if we should track variables at assignments, negative if
338 we should run the var-tracking pass only to discard debug
339 annotations. When flag_var_tracking_assignments ==
340 AUTODETECT_VALUE it will be set according to flag_var_tracking. */
341 int flag_var_tracking_assignments = AUTODETECT_VALUE;
343 /* Nonzero if we should toggle flag_var_tracking_assignments after
344 processing options and computing its default. */
345 int flag_var_tracking_assignments_toggle = 0;
347 /* Type of stack check. */
348 enum stack_check_type flag_stack_check = NO_STACK_CHECK;
350 /* True if the user has tagged the function with the 'section'
353 bool user_defined_section_attribute = false;
355 /* Values of the -falign-* flags: how much to align labels in code.
356 0 means `use default', 1 means `don't align'.
357 For each variable, there is an _log variant which is the power
358 of two not less than the variable, for .align output. */
361 int align_loops_max_skip;
363 int align_jumps_max_skip;
364 int align_labels_log;
365 int align_labels_max_skip;
366 int align_functions_log;
370 const char *const string;
374 lang_independent_options;
376 /* Nonzero if subexpressions must be evaluated from left-to-right. */
377 int flag_evaluation_order = 0;
379 /* The user symbol prefix after having resolved same. */
380 const char *user_label_prefix;
382 static const param_info lang_independent_params[] = {
383 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
384 { OPTION, DEFAULT, false, MIN, MAX, HELP },
385 #include "params.def"
387 { NULL, 0, false, 0, 0, NULL }
390 /* Output files for assembler code (real compiler output)
391 and debugging dumps. */
395 FILE *dump_file = NULL;
396 const char *dump_file_name;
398 /* The current working directory of a translation. It's generally the
399 directory from which compilation was initiated, but a preprocessed
400 file may specify the original directory in which it was
403 static const char *src_pwd;
405 /* Initialize src_pwd with the given string, and return true. If it
406 was already initialized, return false. As a special case, it may
407 be called with a NULL argument to test whether src_pwd has NOT been
411 set_src_pwd (const char *pwd)
415 if (strcmp (src_pwd, pwd) == 0)
421 src_pwd = xstrdup (pwd);
425 /* Return the directory from which the translation unit was initiated,
426 in case set_src_pwd() was not called before to assign it a
442 /* Called when the start of a function definition is parsed,
443 this function prints on stderr the name of the function. */
445 announce_function (tree decl)
449 if (rtl_dump_and_exit)
450 fprintf (stderr, "%s ",
451 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
453 fprintf (stderr, " %s",
454 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
456 pp_needs_newline (global_dc->printer) = true;
457 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
461 /* Initialize local_tick with the time of day, or -1 if
462 flag_random_seed is set. */
465 init_local_tick (void)
467 if (!flag_random_seed)
469 /* Get some more or less random data. */
470 #ifdef HAVE_GETTIMEOFDAY
474 gettimeofday (&tv, NULL);
475 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
479 time_t now = time (NULL);
481 if (now != (time_t)-1)
482 local_tick = (unsigned) now;
490 /* Set up a default flag_random_seed and local_tick, unless the user
491 already specified one. Must be called after init_local_tick. */
494 init_random_seed (void)
496 unsigned HOST_WIDE_INT value;
497 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
499 value = local_tick ^ getpid ();
501 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
502 flag_random_seed = random_seed;
505 /* Obtain the random_seed string. Unless NOINIT, initialize it if
506 it's not provided in the command line. */
509 get_random_seed (bool noinit)
511 if (!flag_random_seed && !noinit)
513 return flag_random_seed;
516 /* Modify the random_seed string to VAL. Return its previous
520 set_random_seed (const char *val)
522 const char *old = flag_random_seed;
523 flag_random_seed = val;
527 /* Decode the string P as an integral parameter.
528 If the string is indeed an integer return its numeric value else
529 issue an Invalid Option error for the option PNAME and return DEFVAL.
530 If PNAME is zero just return DEFVAL, do not call error. */
533 read_integral_parameter (const char *p, const char *pname, const int defval)
535 const char *endp = p;
548 error ("invalid option argument %qs", pname);
555 #if GCC_VERSION < 3004
557 /* The functions floor_log2 and exact_log2 are defined as inline
558 functions in toplev.h if GCC_VERSION >= 3004. The definitions here
559 are used for older versions of gcc. */
561 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
562 If X is 0, return -1. */
565 floor_log2 (unsigned HOST_WIDE_INT x)
572 if (HOST_BITS_PER_WIDE_INT > 64)
573 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
575 if (HOST_BITS_PER_WIDE_INT > 32)
576 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
578 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
580 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
582 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
584 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
586 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
592 /* Return the logarithm of X, base 2, considering X unsigned,
593 if X is a power of 2. Otherwise, returns -1. */
596 exact_log2 (unsigned HOST_WIDE_INT x)
600 return floor_log2 (x);
603 #endif /* GCC_VERSION < 3004 */
605 /* Handler for fatal signals, such as SIGSEGV. These are transformed
606 into ICE messages, which is much more user friendly. In case the
607 error printer crashes, reset the signal to prevent infinite recursion. */
610 crash_signal (int signo)
612 signal (signo, SIG_DFL);
614 /* If we crashed while processing an ASM statement, then be a little more
615 graceful. It's most likely the user's fault. */
616 if (this_is_asm_operands)
618 output_operand_lossage ("unrecoverable error");
619 exit (FATAL_EXIT_CODE);
622 internal_error ("%s", strsignal (signo));
625 /* Arrange to dump core on error. (The regular error message is still
626 printed first, except in the case of abort().) */
629 setup_core_dumping (void)
632 signal (SIGABRT, SIG_DFL);
634 #if defined(HAVE_SETRLIMIT)
637 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
638 fatal_error ("getting core file size maximum limit: %m");
639 rlim.rlim_cur = rlim.rlim_max;
640 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
641 fatal_error ("setting core file size limit to maximum: %m");
644 diagnostic_abort_on_error (global_dc);
648 /* Strip off a legitimate source ending from the input string NAME of
649 length LEN. Rather than having to know the names used by all of
650 our front ends, we strip off an ending of a period followed by
651 up to five characters. (Java uses ".class".) */
654 strip_off_ending (char *name, int len)
657 for (i = 2; i < 6 && len > i; i++)
659 if (name[len - i] == '.')
661 name[len - i] = '\0';
667 /* Output a quoted string. */
670 output_quoted_string (FILE *asm_file, const char *string)
672 #ifdef OUTPUT_QUOTED_STRING
673 OUTPUT_QUOTED_STRING (asm_file, string);
677 putc ('\"', asm_file);
678 while ((c = *string++) != 0)
682 if (c == '\"' || c == '\\')
683 putc ('\\', asm_file);
687 fprintf (asm_file, "\\%03o", (unsigned char) c);
689 putc ('\"', asm_file);
693 /* Output a file name in the form wanted by System V. */
696 output_file_directive (FILE *asm_file, const char *input_name)
701 if (input_name == NULL)
702 input_name = "<stdin>";
704 input_name = remap_debug_filename (input_name);
706 len = strlen (input_name);
707 na = input_name + len;
709 /* NA gets INPUT_NAME sans directory names. */
710 while (na > input_name)
712 if (IS_DIR_SEPARATOR (na[-1]))
717 #ifdef ASM_OUTPUT_SOURCE_FILENAME
718 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
720 fprintf (asm_file, "\t.file\t");
721 output_quoted_string (asm_file, na);
722 putc ('\n', asm_file);
726 /* A subroutine of wrapup_global_declarations. We've come to the end of
727 the compilation unit. All deferred variables should be undeferred,
728 and all incomplete decls should be finalized. */
731 wrapup_global_declaration_1 (tree decl)
733 /* We're not deferring this any longer. Assignment is conditional to
734 avoid needlessly dirtying PCH pages. */
735 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
736 && DECL_DEFER_OUTPUT (decl) != 0)
737 DECL_DEFER_OUTPUT (decl) = 0;
739 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
740 lang_hooks.finish_incomplete_decl (decl);
743 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
744 needs to be output. Return true if it is output. */
747 wrapup_global_declaration_2 (tree decl)
749 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
752 /* Don't write out static consts, unless we still need them.
754 We also keep static consts if not optimizing (for debugging),
755 unless the user specified -fno-keep-static-consts.
756 ??? They might be better written into the debug information.
757 This is possible when using DWARF.
759 A language processor that wants static constants to be always
760 written out (even if it is not used) is responsible for
761 calling rest_of_decl_compilation itself. E.g. the C front-end
762 calls rest_of_decl_compilation from finish_decl.
763 One motivation for this is that is conventional in some
764 environments to write things like:
765 static const char rcsid[] = "... version string ...";
766 intending to force the string to be in the executable.
768 A language processor that would prefer to have unneeded
769 static constants "optimized away" would just defer writing
770 them out until here. E.g. C++ does this, because static
771 constants are often defined in header files.
773 ??? A tempting alternative (for both C and C++) would be
774 to force a constant to be written if and only if it is
775 defined in a main file, as opposed to an include file. */
777 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
779 struct varpool_node *node;
781 node = varpool_node (decl);
785 else if (node->alias)
787 else if (!cgraph_global_info_ready
789 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
791 else if (node->needed)
793 else if (DECL_COMDAT (decl))
795 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
796 && (optimize || !flag_keep_static_consts
797 || DECL_ARTIFICIAL (decl)))
802 rest_of_decl_compilation (decl, 1, 1);
810 /* Do any final processing required for the declarations in VEC, of
811 which there are LEN. We write out inline functions and variables
812 that have been deferred until this point, but which are required.
813 Returns nonzero if anything was put out. */
816 wrapup_global_declarations (tree *vec, int len)
818 bool reconsider, output_something = false;
821 for (i = 0; i < len; i++)
822 wrapup_global_declaration_1 (vec[i]);
824 /* Now emit any global variables or functions that we have been
825 putting off. We need to loop in case one of the things emitted
826 here references another one which comes earlier in the list. */
830 for (i = 0; i < len; i++)
831 reconsider |= wrapup_global_declaration_2 (vec[i]);
833 output_something = true;
837 return output_something;
840 /* A subroutine of check_global_declarations. Issue appropriate warnings
841 for the global declaration DECL. */
844 check_global_declaration_1 (tree decl)
846 /* Warn about any function declared static but not defined. We don't
847 warn about variables, because many programs have static variables
848 that exist only to get some text into the object file. */
849 if (TREE_CODE (decl) == FUNCTION_DECL
850 && DECL_INITIAL (decl) == 0
851 && DECL_EXTERNAL (decl)
852 && ! DECL_ARTIFICIAL (decl)
853 && ! TREE_NO_WARNING (decl)
854 && ! TREE_PUBLIC (decl)
855 && (warn_unused_function
856 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
858 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
859 pedwarn (input_location, 0, "%q+F used but never defined", decl);
861 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
862 /* This symbol is effectively an "extern" declaration now. */
863 TREE_PUBLIC (decl) = 1;
864 assemble_external (decl);
867 /* Warn about static fns or vars defined but not used. */
868 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
869 /* We don't warn about "static const" variables because the
870 "rcs_id" idiom uses that construction. */
871 || (warn_unused_variable
872 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
873 && ! DECL_IN_SYSTEM_HEADER (decl)
874 && ! TREE_USED (decl)
875 /* The TREE_USED bit for file-scope decls is kept in the identifier,
876 to handle multiple external decls in different scopes. */
877 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
878 && ! DECL_EXTERNAL (decl)
879 && ! TREE_PUBLIC (decl)
880 /* A volatile variable might be used in some non-obvious way. */
881 && ! TREE_THIS_VOLATILE (decl)
882 /* Global register variables must be declared to reserve them. */
883 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
884 /* Otherwise, ask the language. */
885 && lang_hooks.decls.warn_unused_global (decl))
886 warning ((TREE_CODE (decl) == FUNCTION_DECL)
887 ? OPT_Wunused_function
888 : OPT_Wunused_variable,
889 "%q+D defined but not used", decl);
892 /* Issue appropriate warnings for the global declarations in VEC (of
893 which there are LEN). */
896 check_global_declarations (tree *vec, int len)
900 for (i = 0; i < len; i++)
901 check_global_declaration_1 (vec[i]);
904 /* Emit debugging information for all global declarations in VEC. */
907 emit_debug_global_declarations (tree *vec, int len)
911 /* Avoid confusing the debug information machinery when there are errors. */
912 if (errorcount != 0 || sorrycount != 0)
915 timevar_push (TV_SYMOUT);
916 for (i = 0; i < len; i++)
917 debug_hooks->global_decl (vec[i]);
918 timevar_pop (TV_SYMOUT);
921 /* Warn about a use of an identifier which was marked deprecated. */
923 warn_deprecated_use (tree node, tree attr)
927 if (node == 0 || !warn_deprecated_decl)
933 attr = DECL_ATTRIBUTES (node);
934 else if (TYPE_P (node))
936 tree decl = TYPE_STUB_DECL (node);
938 attr = lookup_attribute ("deprecated",
939 TYPE_ATTRIBUTES (TREE_TYPE (decl)));
944 attr = lookup_attribute ("deprecated", attr);
947 msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
953 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
955 warning (OPT_Wdeprecated_declarations,
956 "%qD is deprecated (declared at %s:%d): %s",
957 node, xloc.file, xloc.line, msg);
959 warning (OPT_Wdeprecated_declarations,
960 "%qD is deprecated (declared at %s:%d)",
961 node, xloc.file, xloc.line);
963 else if (TYPE_P (node))
965 tree what = NULL_TREE;
966 tree decl = TYPE_STUB_DECL (node);
968 if (TYPE_NAME (node))
970 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
971 what = TYPE_NAME (node);
972 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
973 && DECL_NAME (TYPE_NAME (node)))
974 what = DECL_NAME (TYPE_NAME (node));
979 expanded_location xloc
980 = expand_location (DECL_SOURCE_LOCATION (decl));
984 warning (OPT_Wdeprecated_declarations,
985 "%qE is deprecated (declared at %s:%d): %s",
986 what, xloc.file, xloc.line, msg);
988 warning (OPT_Wdeprecated_declarations,
989 "%qE is deprecated (declared at %s:%d)", what,
990 xloc.file, xloc.line);
995 warning (OPT_Wdeprecated_declarations,
996 "type is deprecated (declared at %s:%d): %s",
997 xloc.file, xloc.line, msg);
999 warning (OPT_Wdeprecated_declarations,
1000 "type is deprecated (declared at %s:%d)",
1001 xloc.file, xloc.line);
1009 warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s",
1012 warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what);
1017 warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
1020 warning (OPT_Wdeprecated_declarations, "type is deprecated");
1026 /* Compile an entire translation unit. Write a file of assembly
1027 output and various debugging dumps. */
1032 /* Initialize yet another pass. */
1034 ggc_protect_identifiers = true;
1037 init_final (main_input_filename);
1038 coverage_init (aux_base_name);
1040 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
1042 timevar_push (TV_PARSE);
1044 /* Call the parser, which parses the entire file (calling
1045 rest_of_compilation for each function). */
1046 lang_hooks.parse_file (set_yydebug);
1048 /* Compilation is now finished except for writing
1049 what's left of the symbol table output. */
1050 timevar_pop (TV_PARSE);
1052 if (flag_syntax_only || flag_wpa)
1055 ggc_protect_identifiers = false;
1057 /* This must also call cgraph_finalize_compilation_unit. */
1058 lang_hooks.decls.final_write_globals ();
1060 if (errorcount || sorrycount)
1063 varpool_assemble_pending_decls ();
1064 finish_aliases_2 ();
1066 /* Likewise for mudflap static object registrations. */
1068 mudflap_finish_file ();
1070 /* Likewise for emulated thread-local storage. */
1071 if (!targetm.have_tls)
1074 output_shared_constant_pool ();
1075 output_object_blocks ();
1077 /* Write out any pending weak symbol declarations. */
1080 /* This must be at the end before unwind and debug info.
1081 Some target ports emit PIC setup thunks here. */
1082 targetm.asm_out.code_end ();
1084 /* Do dbx symbols. */
1085 timevar_push (TV_SYMOUT);
1087 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
1088 if (dwarf2out_do_frame ())
1089 dwarf2out_frame_finish ();
1092 (*debug_hooks->finish) (main_input_filename);
1093 timevar_pop (TV_SYMOUT);
1095 /* Output some stuff at end of file if nec. */
1097 dw2_output_indirect_constants ();
1099 /* Flush any pending external directives. */
1100 process_pending_assemble_externals ();
1102 /* Emit LTO marker if LTO info has been previously emitted. This is
1103 used by collect2 to determine whether an object file contains IL.
1104 We used to emit an undefined reference here, but this produces
1105 link errors if an object file with IL is stored into a shared
1106 library without invoking lto1. */
1107 if (flag_generate_lto)
1109 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1110 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
1112 (unsigned HOST_WIDE_INT) 1, 8);
1113 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1114 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1",
1115 (unsigned HOST_WIDE_INT) 1, 8);
1117 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1",
1118 (unsigned HOST_WIDE_INT) 1,
1119 (unsigned HOST_WIDE_INT) 1);
1123 /* Attach a special .ident directive to the end of the file to identify
1124 the version of GCC which compiled this code. The format of the .ident
1125 string is patterned after the ones produced by native SVR4 compilers. */
1129 const char *pkg_version = "(GNU) ";
1131 if (strcmp ("(GCC) ", pkgversion_string))
1132 pkg_version = pkgversion_string;
1133 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
1134 IDENT_ASM_OP, pkg_version, version_string);
1138 /* Invoke registered plugin callbacks. */
1139 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
1141 /* This must be at the end. Some target ports emit end of file directives
1142 into the assembly file here, and hence we can not output anything to the
1143 assembly file after this point. */
1144 targetm.asm_out.file_end ();
1147 /* Parse a -d... command line switch. */
1150 decode_d_option (const char *arg)
1161 flag_print_asm_name = 1;
1164 flag_dump_rtl_in_asm = 1;
1165 flag_print_asm_name = 1;
1168 graph_dump_format = vcg;
1171 rtl_dump_and_exit = 1;
1176 case 'D': /* These are handled by the preprocessor. */
1183 setup_core_dumping();
1186 enable_rtl_dump_file ();
1190 warning (0, "unrecognized gcc debugging option: %c", c);
1195 /* Indexed by enum debug_info_type. */
1196 const char *const debug_type_names[] =
1198 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1201 /* Print version information to FILE.
1202 Each line begins with INDENT (for the case where FILE is the
1203 assembler output file). */
1206 print_version (FILE *file, const char *indent)
1208 static const char fmt1[] =
1210 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1212 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1215 static const char fmt2[] =
1216 N_("GMP version %s, MPFR version %s, MPC version %s\n");
1217 static const char fmt3[] =
1218 N_("%s%swarning: %s header version %s differs from library version %s.\n");
1219 static const char fmt4[] =
1220 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1222 #define __VERSION__ "[?]"
1225 file == stderr ? _(fmt1) : fmt1,
1226 indent, *indent != 0 ? " " : "",
1227 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
1228 indent, __VERSION__);
1230 /* We need to stringify the GMP macro values. Ugh, gmp_version has
1231 two string formats, "i.j.k" and "i.j" when k is zero. As of
1232 gmp-4.3.0, GMP always uses the 3 number format. */
1233 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1234 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1235 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
1236 #define GCC_GMP_VERSION \
1237 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
1238 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
1239 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1240 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1242 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1243 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1244 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1247 file == stderr ? _(fmt2) : fmt2,
1248 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING);
1249 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
1251 file == stderr ? _(fmt3) : fmt3,
1252 indent, *indent != 0 ? " " : "",
1253 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
1254 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
1256 file == stderr ? _(fmt3) : fmt3,
1257 indent, *indent != 0 ? " " : "",
1258 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
1259 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
1261 file == stderr ? _(fmt3) : fmt3,
1262 indent, *indent != 0 ? " " : "",
1263 "MPC", MPC_VERSION_STRING, mpc_get_version ());
1265 file == stderr ? _(fmt4) : fmt4,
1266 indent, *indent != 0 ? " " : "",
1267 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1269 print_plugins_versions (file, indent);
1272 #ifdef ASM_COMMENT_START
1274 print_to_asm_out_file (print_switch_type type, const char * text)
1276 bool prepend_sep = true;
1280 case SWITCH_TYPE_LINE_END:
1281 putc ('\n', asm_out_file);
1284 case SWITCH_TYPE_LINE_START:
1285 fputs (ASM_COMMENT_START, asm_out_file);
1286 return strlen (ASM_COMMENT_START);
1288 case SWITCH_TYPE_DESCRIPTIVE:
1289 if (ASM_COMMENT_START[0] == 0)
1290 prepend_sep = false;
1292 case SWITCH_TYPE_PASSED:
1293 case SWITCH_TYPE_ENABLED:
1295 fputc (' ', asm_out_file);
1296 fputs (text, asm_out_file);
1297 /* No need to return the length here as
1298 print_single_switch has already done it. */
1308 print_to_stderr (print_switch_type type, const char * text)
1312 case SWITCH_TYPE_LINE_END:
1313 putc ('\n', stderr);
1316 case SWITCH_TYPE_LINE_START:
1319 case SWITCH_TYPE_PASSED:
1320 case SWITCH_TYPE_ENABLED:
1321 fputc (' ', stderr);
1324 case SWITCH_TYPE_DESCRIPTIVE:
1325 fputs (text, stderr);
1326 /* No need to return the length here as
1327 print_single_switch has already done it. */
1335 /* Print an option value and return the adjusted position in the line.
1336 ??? print_fn doesn't handle errors, eg disk full; presumably other
1337 code will catch a disk full though. */
1340 print_single_switch (print_switch_fn_type print_fn,
1342 print_switch_type type,
1345 /* The ultrix fprintf returns 0 on success, so compute the result
1346 we want here since we need it for the following test. The +1
1347 is for the separator character that will probably be emitted. */
1348 int len = strlen (text) + 1;
1351 && pos + len > MAX_LINE)
1353 print_fn (SWITCH_TYPE_LINE_END, NULL);
1358 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1360 print_fn (type, text);
1364 /* Print active target switches using PRINT_FN.
1365 POS is the current cursor position and MAX is the size of a "line".
1366 Each line begins with INDENT and ends with TERM.
1367 Each switch is separated from the next by SEP. */
1370 print_switch_values (print_switch_fn_type print_fn)
1376 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1377 that it can be printed below. This helps reproducibility. */
1378 if (!flag_random_seed)
1379 init_random_seed ();
1381 /* Print the options as passed. */
1382 pos = print_single_switch (print_fn, pos,
1383 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1385 for (p = &save_argv[1]; *p != NULL; p++)
1390 if (strcmp (*p, "-o") == 0
1391 || strcmp (*p, "-dumpbase") == 0
1392 || strcmp (*p, "-dumpdir") == 0
1393 || strcmp (*p, "-auxbase") == 0)
1400 if (strcmp (*p, "-quiet") == 0
1401 || strcmp (*p, "-version") == 0)
1408 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED, *p);
1412 print_fn (SWITCH_TYPE_LINE_END, NULL);
1414 /* Print the -f and -m options that have been enabled.
1415 We don't handle language specific options but printing argv
1417 pos = print_single_switch (print_fn, 0,
1418 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1420 for (j = 0; j < cl_options_count; j++)
1421 if ((cl_options[j].flags & CL_REPORT)
1422 && option_enabled (j) > 0)
1423 pos = print_single_switch (print_fn, pos,
1424 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1426 print_fn (SWITCH_TYPE_LINE_END, NULL);
1429 /* Open assembly code output file. Do this even if -fsyntax-only is
1430 on, because then the driver will have provided the name of a
1431 temporary file or bit bucket for us. NAME is the file specified on
1432 the command line, possibly NULL. */
1434 init_asm_output (const char *name)
1436 if (name == NULL && asm_file_name == 0)
1437 asm_out_file = stdout;
1440 if (asm_file_name == 0)
1442 int len = strlen (dump_base_name);
1443 char *dumpname = XNEWVEC (char, len + 6);
1445 memcpy (dumpname, dump_base_name, len + 1);
1446 strip_off_ending (dumpname, len);
1447 strcat (dumpname, ".s");
1448 asm_file_name = dumpname;
1450 if (!strcmp (asm_file_name, "-"))
1451 asm_out_file = stdout;
1453 asm_out_file = fopen (asm_file_name, "w+b");
1454 if (asm_out_file == 0)
1455 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1458 if (!flag_syntax_only)
1460 targetm.asm_out.file_start ();
1462 if (flag_record_gcc_switches)
1464 if (targetm.asm_out.record_gcc_switches)
1466 /* Let the target know that we are about to start recording. */
1467 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1469 /* Now record the switches. */
1470 print_switch_values (targetm.asm_out.record_gcc_switches);
1471 /* Let the target know that the recording is over. */
1472 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1476 inform (input_location, "-frecord-gcc-switches is not supported by the current target");
1479 #ifdef ASM_COMMENT_START
1480 if (flag_verbose_asm)
1482 /* Print the list of switches in effect
1483 into the assembler file as comments. */
1484 print_version (asm_out_file, ASM_COMMENT_START);
1485 print_switch_values (print_to_asm_out_file);
1486 putc ('\n', asm_out_file);
1492 /* Return true if the state of option OPTION should be stored in PCH files
1493 and checked by default_pch_valid_p. Store the option's current state
1497 option_affects_pch_p (int option, struct cl_option_state *state)
1499 if ((cl_options[option].flags & CL_TARGET) == 0)
1501 if (cl_options[option].flag_var == &target_flags)
1502 if (targetm.check_pch_target_flags)
1504 return get_option_state (option, state);
1507 /* Default version of get_pch_validity.
1508 By default, every flag difference is fatal; that will be mostly right for
1509 most targets, but completely right for very few. */
1512 default_get_pch_validity (size_t *sz)
1514 struct cl_option_state state;
1519 if (targetm.check_pch_target_flags)
1520 *sz += sizeof (target_flags);
1521 for (i = 0; i < cl_options_count; i++)
1522 if (option_affects_pch_p (i, &state))
1525 result = r = XNEWVEC (char, *sz);
1529 if (targetm.check_pch_target_flags)
1531 memcpy (r, &target_flags, sizeof (target_flags));
1532 r += sizeof (target_flags);
1535 for (i = 0; i < cl_options_count; i++)
1536 if (option_affects_pch_p (i, &state))
1538 memcpy (r, state.data, state.size);
1545 /* Return a message which says that a PCH file was created with a different
1546 setting of OPTION. */
1549 pch_option_mismatch (const char *option)
1553 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1555 return _("out of memory");
1559 /* Default version of pch_valid_p. */
1562 default_pch_valid_p (const void *data_p, size_t len)
1564 struct cl_option_state state;
1565 const char *data = (const char *)data_p;
1568 /* -fpic and -fpie also usually make a PCH invalid. */
1569 if (data[0] != flag_pic)
1570 return _("created and used with different settings of -fpic");
1571 if (data[1] != flag_pie)
1572 return _("created and used with different settings of -fpie");
1575 /* Check target_flags. */
1576 if (targetm.check_pch_target_flags)
1581 memcpy (&tf, data, sizeof (target_flags));
1582 data += sizeof (target_flags);
1583 len -= sizeof (target_flags);
1584 r = targetm.check_pch_target_flags (tf);
1589 for (i = 0; i < cl_options_count; i++)
1590 if (option_affects_pch_p (i, &state))
1592 if (memcmp (data, state.data, state.size) != 0)
1593 return pch_option_mismatch (cl_options[i].opt_text);
1601 /* Default tree printer. Handles declarations only. */
1603 default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
1604 int precision, bool wide, bool set_locus, bool hash)
1608 /* FUTURE: %+x should set the locus. */
1609 if (precision != 0 || wide || hash)
1615 t = va_arg (*text->args_ptr, tree);
1616 if (TREE_CODE (t) == IDENTIFIER_NODE)
1618 pp_identifier (pp, IDENTIFIER_POINTER (t));
1624 t = va_arg (*text->args_ptr, tree);
1625 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1626 t = DECL_DEBUG_EXPR (t);
1631 t = va_arg (*text->args_ptr, tree);
1638 if (set_locus && text->locus)
1639 *text->locus = DECL_SOURCE_LOCATION (t);
1643 const char *n = DECL_NAME (t)
1644 ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2))
1649 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1654 /* A helper function; used as the reallocator function for cpp's line
1657 realloc_for_line_map (void *ptr, size_t len)
1659 return ggc_realloc (ptr, len);
1662 /* Initialization of the front end environment, before command line
1663 options are parsed. Signal handlers, internationalization etc.
1664 ARGV0 is main's argv[0]. */
1666 general_init (const char *argv0)
1670 p = argv0 + strlen (argv0);
1671 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1675 xmalloc_set_program_name (progname);
1679 /* Unlock the stdio streams. */
1680 unlock_std_streams ();
1682 gcc_init_libintl ();
1684 /* Initialize the diagnostics reporting machinery, so option parsing
1685 can give warnings and errors. */
1686 diagnostic_initialize (global_dc);
1687 /* Set a default printer. Language specific initializations will
1688 override it later. */
1689 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1690 global_dc->show_option_requested = flag_diagnostics_show_option;
1692 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1694 signal (SIGSEGV, crash_signal);
1697 signal (SIGILL, crash_signal);
1700 signal (SIGBUS, crash_signal);
1703 signal (SIGABRT, crash_signal);
1705 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1706 signal (SIGIOT, crash_signal);
1709 signal (SIGFPE, crash_signal);
1712 /* Other host-specific signal setup. */
1713 (*host_hooks.extra_signals)();
1715 /* Initialize the garbage-collector, string pools and tree type hash
1719 line_table = GGC_NEW (struct line_maps);
1720 linemap_init (line_table);
1721 line_table->reallocator = realloc_for_line_map;
1724 /* Initialize register usage now so switches may override. */
1727 /* Register the language-independent parameters. */
1728 add_params (lang_independent_params, LAST_PARAM);
1730 /* This must be done after add_params but before argument processing. */
1731 init_ggc_heuristics();
1732 init_optimization_passes ();
1733 statistics_early_init ();
1736 /* Return true if the current target supports -fsection-anchors. */
1739 target_supports_section_anchors_p (void)
1741 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1744 if (targetm.asm_out.output_anchor == NULL)
1750 /* Default the align_* variables to 1 if they're still unset, and
1751 set up the align_*_log variables. */
1753 init_alignments (void)
1755 if (align_loops <= 0)
1757 if (align_loops_max_skip > align_loops)
1758 align_loops_max_skip = align_loops - 1;
1759 align_loops_log = floor_log2 (align_loops * 2 - 1);
1760 if (align_jumps <= 0)
1762 if (align_jumps_max_skip > align_jumps)
1763 align_jumps_max_skip = align_jumps - 1;
1764 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1765 if (align_labels <= 0)
1767 align_labels_log = floor_log2 (align_labels * 2 - 1);
1768 if (align_labels_max_skip > align_labels)
1769 align_labels_max_skip = align_labels - 1;
1770 if (align_functions <= 0)
1771 align_functions = 1;
1772 align_functions_log = floor_log2 (align_functions * 2 - 1);
1775 /* Process the options that have been parsed. */
1777 process_options (void)
1779 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1780 This can happen with incorrect pre-processed input. */
1781 debug_hooks = &do_nothing_debug_hooks;
1783 /* This replaces set_Wunused. */
1784 if (warn_unused_function == -1)
1785 warn_unused_function = warn_unused;
1786 if (warn_unused_label == -1)
1787 warn_unused_label = warn_unused;
1788 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */
1789 if (warn_unused_parameter == -1)
1790 warn_unused_parameter = (warn_unused && extra_warnings);
1791 if (warn_unused_variable == -1)
1792 warn_unused_variable = warn_unused;
1793 /* Wunused-but-set-parameter is enabled if both -Wunused -Wextra are
1795 if (warn_unused_but_set_parameter == -1)
1796 warn_unused_but_set_parameter = (warn_unused && extra_warnings);
1797 if (warn_unused_but_set_variable == -1)
1798 warn_unused_but_set_variable = warn_unused;
1799 if (warn_unused_value == -1)
1800 warn_unused_value = warn_unused;
1802 /* This replaces set_Wextra. */
1803 if (warn_uninitialized == -1)
1804 warn_uninitialized = extra_warnings;
1806 /* Allow the front end to perform consistency checks and do further
1807 initialization based on the command line options. This hook also
1808 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1809 so we can correctly initialize debug output. */
1810 no_backend = lang_hooks.post_options (&main_input_filename);
1812 #ifdef OVERRIDE_OPTIONS
1813 /* Some machines may reject certain combinations of options. */
1817 /* Avoid any informative notes in the second run of -fcompare-debug. */
1818 if (flag_compare_debug)
1819 diagnostic_inhibit_notes (global_dc);
1821 if (flag_section_anchors && !target_supports_section_anchors_p ())
1823 warning (OPT_fsection_anchors,
1824 "this target does not support %qs", "-fsection-anchors");
1825 flag_section_anchors = 0;
1828 if (flag_short_enums == 2)
1829 flag_short_enums = targetm.default_short_enums ();
1831 /* Set aux_base_name if not already set. */
1834 else if (main_input_filename)
1836 char *name = xstrdup (lbasename (main_input_filename));
1838 strip_off_ending (name, strlen (name));
1839 aux_base_name = name;
1842 aux_base_name = "gccaux";
1847 || flag_loop_interchange
1848 || flag_loop_strip_mine
1849 || flag_graphite_identity
1850 || flag_loop_parallelize_all)
1851 sorry ("Graphite loop optimizations cannot be used");
1854 /* Unrolling all loops implies that standard loop unrolling must also
1856 if (flag_unroll_all_loops)
1857 flag_unroll_loops = 1;
1859 /* The loop unrolling code assumes that cse will be run after loop.
1860 web and rename-registers also help when run after loop unrolling. */
1861 if (flag_rerun_cse_after_loop == AUTODETECT_VALUE)
1862 flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops;
1864 if (flag_web == AUTODETECT_VALUE)
1865 flag_web = flag_unroll_loops || flag_peel_loops;
1867 if (flag_rename_registers == AUTODETECT_VALUE)
1868 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1870 if (flag_non_call_exceptions)
1871 flag_asynchronous_unwind_tables = 1;
1872 if (flag_asynchronous_unwind_tables)
1873 flag_unwind_tables = 1;
1875 if (flag_value_profile_transformations)
1876 flag_profile_values = 1;
1878 /* Warn about options that are not supported on this machine. */
1879 #ifndef INSN_SCHEDULING
1880 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1881 warning (0, "instruction scheduling not supported on this target machine");
1884 if (flag_delayed_branch)
1885 warning (0, "this target machine does not have delayed branches");
1888 user_label_prefix = USER_LABEL_PREFIX;
1889 if (flag_leading_underscore != -1)
1891 /* If the default prefix is more complicated than "" or "_",
1892 issue a warning and ignore this option. */
1893 if (user_label_prefix[0] == 0 ||
1894 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1896 user_label_prefix = flag_leading_underscore ? "_" : "";
1899 warning (0, "-f%sleading-underscore not supported on this target machine",
1900 flag_leading_underscore ? "" : "no-");
1903 /* If we are in verbose mode, write out the version and maybe all the
1904 option flags in use. */
1907 print_version (stderr, "");
1909 print_switch_values (print_to_stderr);
1912 if (flag_syntax_only)
1914 write_symbols = NO_DEBUG;
1920 if (debug_info_level == DINFO_LEVEL_NONE)
1922 debug_info_level = DINFO_LEVEL_NORMAL;
1924 if (write_symbols == NO_DEBUG)
1925 write_symbols = PREFERRED_DEBUGGING_TYPE;
1928 debug_info_level = DINFO_LEVEL_NONE;
1931 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1933 FILE *final_output = fopen (flag_dump_final_insns, "w");
1936 error ("could not open final insn dump file %qs: %s",
1937 flag_dump_final_insns, strerror (errno));
1938 flag_dump_final_insns = NULL;
1940 else if (fclose (final_output))
1942 error ("could not close zeroed insn dump file %qs: %s",
1943 flag_dump_final_insns, strerror (errno));
1944 flag_dump_final_insns = NULL;
1948 /* Unless over-ridden for the target, assume that all DWARF levels
1949 may be emitted, if DWARF2_DEBUG is selected. */
1950 if (dwarf_strict < 0)
1953 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1955 if (debug_info_level == DINFO_LEVEL_NONE)
1956 write_symbols = NO_DEBUG;
1958 if (write_symbols == NO_DEBUG)
1960 #if defined(DBX_DEBUGGING_INFO)
1961 else if (write_symbols == DBX_DEBUG)
1962 debug_hooks = &dbx_debug_hooks;
1964 #if defined(XCOFF_DEBUGGING_INFO)
1965 else if (write_symbols == XCOFF_DEBUG)
1966 debug_hooks = &xcoff_debug_hooks;
1968 #ifdef SDB_DEBUGGING_INFO
1969 else if (write_symbols == SDB_DEBUG)
1970 debug_hooks = &sdb_debug_hooks;
1972 #ifdef DWARF2_DEBUGGING_INFO
1973 else if (write_symbols == DWARF2_DEBUG)
1974 debug_hooks = &dwarf2_debug_hooks;
1976 #ifdef VMS_DEBUGGING_INFO
1977 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1978 debug_hooks = &vmsdbg_debug_hooks;
1981 error ("target system does not support the \"%s\" debug format",
1982 debug_type_names[write_symbols]);
1984 /* We know which debug output will be used so we can set flag_var_tracking
1985 and flag_var_tracking_uninit if the user has not specified them. */
1986 if (debug_info_level < DINFO_LEVEL_NORMAL
1987 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1989 if (flag_var_tracking == 1
1990 || flag_var_tracking_uninit == 1)
1992 if (debug_info_level < DINFO_LEVEL_NORMAL)
1993 warning (0, "variable tracking requested, but useless unless "
1994 "producing debug info");
1996 warning (0, "variable tracking requested, but not supported "
1997 "by this debug format");
1999 flag_var_tracking = 0;
2000 flag_var_tracking_uninit = 0;
2003 /* If the user specifically requested variable tracking with tagging
2004 uninitialized variables, we need to turn on variable tracking.
2005 (We already determined above that variable tracking is feasible.) */
2006 if (flag_var_tracking_uninit)
2007 flag_var_tracking = 1;
2009 if (flag_var_tracking == AUTODETECT_VALUE)
2010 flag_var_tracking = optimize >= 1;
2012 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
2013 flag_var_tracking_assignments = flag_var_tracking
2014 && !(flag_selective_scheduling || flag_selective_scheduling2);
2016 if (flag_var_tracking_assignments_toggle)
2017 flag_var_tracking_assignments = !flag_var_tracking_assignments;
2019 if (flag_var_tracking_assignments && !flag_var_tracking)
2020 flag_var_tracking = flag_var_tracking_assignments = -1;
2022 if (flag_var_tracking_assignments
2023 && (flag_selective_scheduling || flag_selective_scheduling2))
2024 warning (0, "var-tracking-assignments changes selective scheduling");
2026 if (flag_tree_cselim == AUTODETECT_VALUE)
2027 #ifdef HAVE_conditional_move
2028 flag_tree_cselim = 1;
2030 flag_tree_cselim = 0;
2033 /* If auxiliary info generation is desired, open the output file.
2034 This goes in the same directory as the source file--unlike
2035 all the other output files. */
2036 if (flag_gen_aux_info)
2038 aux_info_file = fopen (aux_info_file_name, "w");
2039 if (aux_info_file == 0)
2040 fatal_error ("can%'t open %s: %m", aux_info_file_name);
2043 if (! targetm.have_named_sections)
2045 if (flag_function_sections)
2047 warning (0, "-ffunction-sections not supported for this target");
2048 flag_function_sections = 0;
2050 if (flag_data_sections)
2052 warning (0, "-fdata-sections not supported for this target");
2053 flag_data_sections = 0;
2057 if (flag_function_sections && profile_flag)
2059 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
2060 flag_function_sections = 0;
2063 #ifndef HAVE_prefetch
2064 if (flag_prefetch_loop_arrays)
2066 warning (0, "-fprefetch-loop-arrays not supported for this target");
2067 flag_prefetch_loop_arrays = 0;
2070 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
2072 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
2073 flag_prefetch_loop_arrays = 0;
2077 /* This combination of options isn't handled for i386 targets and doesn't
2078 make much sense anyway, so don't allow it. */
2079 if (flag_prefetch_loop_arrays && optimize_size)
2081 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
2082 flag_prefetch_loop_arrays = 0;
2085 /* The presence of IEEE signaling NaNs, implies all math can trap. */
2086 if (flag_signaling_nans)
2087 flag_trapping_math = 1;
2089 /* We cannot reassociate if we want traps or signed zeros. */
2090 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
2092 warning (0, "-fassociative-math disabled; other options take precedence");
2093 flag_associative_math = 0;
2096 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
2097 if (flag_cx_limited_range)
2098 flag_complex_method = 0;
2100 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
2101 if (flag_cx_fortran_rules)
2102 flag_complex_method = 1;
2104 /* Targets must be able to place spill slots at lower addresses. If the
2105 target already uses a soft frame pointer, the transition is trivial. */
2106 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
2108 warning (0, "-fstack-protector not supported for this target");
2109 flag_stack_protect = 0;
2111 if (!flag_stack_protect)
2112 warn_stack_protect = 0;
2114 /* ??? Unwind info is not correct around the CFG unless either a frame
2115 pointer is present or A_O_A is set. Fixing this requires rewriting
2116 unwind info generation to be aware of the CFG and propagating states
2118 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
2119 && flag_omit_frame_pointer)
2121 warning (0, "unwind tables currently require a frame pointer "
2123 flag_omit_frame_pointer = 0;
2126 /* Save the current optimization options. */
2127 optimization_default_node = build_optimization_node ();
2128 optimization_current_node = optimization_default_node;
2131 /* This function can be called multiple times to reinitialize the compiler
2132 back end when register classes or instruction sets have changed,
2133 before each function. */
2135 backend_init_target (void)
2137 /* Initialize alignment variables. */
2140 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
2141 to initialize reg_raw_mode[]. */
2144 /* This invokes target hooks to set fixed_reg[] etc, which is
2148 /* This depends on stack_pointer_rtx. */
2149 init_fake_stack_mems ();
2151 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
2153 init_alias_target ();
2155 /* Depends on HARD_FRAME_POINTER_REGNUM. */
2158 /* The following initialization functions need to generate rtl, so
2159 provide a dummy function context for them. */
2160 init_dummy_function_start ();
2162 /* rtx_cost is mode-dependent, so cached values need to be recomputed
2163 on a mode change. */
2166 /* We may need to recompute regno_save_code[] and regno_restore_code[]
2167 after a mode change as well. */
2168 caller_save_initialized_p = false;
2170 expand_dummy_function_end ();
2173 /* Initialize the compiler back end. This function is called only once,
2174 when starting the compiler. */
2181 init_inline_once ();
2182 init_varasm_once ();
2183 save_register_info ();
2185 /* Initialize the target-specific back end pieces. */
2187 backend_init_target ();
2190 /* Initialize excess precision settings. */
2192 init_excess_precision (void)
2194 /* Adjust excess precision handling based on the target options. If
2195 the front end cannot handle it, flag_excess_precision_cmdline
2196 will already have been set accordingly in the post_options
2198 gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
2199 flag_excess_precision = flag_excess_precision_cmdline;
2200 if (flag_unsafe_math_optimizations)
2201 flag_excess_precision = EXCESS_PRECISION_FAST;
2202 if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
2204 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
2205 switch (flt_eval_method)
2209 /* Either the target acts unpredictably (-1) or has all the
2210 operations required not to have excess precision (0). */
2211 flag_excess_precision = EXCESS_PRECISION_FAST;
2215 /* In these cases, predictable excess precision makes
2219 /* Any other implementation-defined FLT_EVAL_METHOD values
2220 require the compiler to handle the associated excess
2221 precision rules in excess_precision_type. */
2227 /* Initialize things that are both lang-dependent and target-dependent.
2228 This function can be called more than once if target parameters change. */
2230 lang_dependent_init_target (void)
2232 /* This determines excess precision settings. */
2233 init_excess_precision ();
2235 /* This creates various _DECL nodes, so needs to be called after the
2236 front end is initialized. It also depends on the HAVE_xxx macros
2237 generated from the target machine description. */
2240 /* The following initialization functions need to generate rtl, so
2241 provide a dummy function context for them. */
2242 init_dummy_function_start ();
2244 /* Do the target-specific parts of expr initialization. */
2245 init_expr_target ();
2247 /* Although the actions of these functions are language-independent,
2248 they use optabs, so we cannot call them from backend_init. */
2252 expand_dummy_function_end ();
2255 /* Language-dependent initialization. Returns nonzero on success. */
2257 lang_dependent_init (const char *name)
2259 location_t save_loc = input_location;
2260 if (dump_base_name == 0)
2261 dump_base_name = name && name[0] ? name : "gccdump";
2263 /* Other front-end initialization. */
2264 input_location = BUILTINS_LOCATION;
2265 if (lang_hooks.init () == 0)
2267 input_location = save_loc;
2269 init_asm_output (name);
2271 /* This creates various _DECL nodes, so needs to be called after the
2272 front end is initialized. */
2275 /* Do the target-specific parts of the initialization. */
2276 lang_dependent_init_target ();
2278 /* If dbx symbol table desired, initialize writing it and output the
2279 predefined types. */
2280 timevar_push (TV_SYMOUT);
2282 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2283 if (dwarf2out_do_frame ())
2284 dwarf2out_frame_init ();
2287 /* Now we have the correct original filename, we can initialize
2289 (*debug_hooks->init) (name);
2291 timevar_pop (TV_SYMOUT);
2297 /* Reinitialize everything when target parameters, such as register usage,
2300 target_reinit (void)
2302 /* Reinitialize RTL backend. */
2303 backend_init_target ();
2305 /* Reinitialize lang-dependent parts. */
2306 lang_dependent_init_target ();
2310 dump_memory_report (bool final)
2312 ggc_print_statistics ();
2313 stringpool_statistics ();
2314 dump_tree_statistics ();
2315 dump_gimple_statistics ();
2316 dump_rtx_statistics ();
2317 dump_alloc_pool_statistics ();
2318 dump_bitmap_statistics ();
2319 dump_vec_loc_statistics ();
2320 dump_ggc_loc_statistics (final);
2321 dump_alias_stats (stderr);
2322 dump_pta_stats (stderr);
2325 /* Clean up: close opened files, etc. */
2330 /* Close the dump files. */
2331 if (flag_gen_aux_info)
2333 fclose (aux_info_file);
2335 unlink (aux_info_file_name);
2338 /* Close non-debugging input and output files. Take special care to note
2339 whether fclose returns an error, since the pages might still be on the
2340 buffer chain while the file is open. */
2344 if (ferror (asm_out_file) != 0)
2345 fatal_error ("error writing to %s: %m", asm_file_name);
2346 if (fclose (asm_out_file) != 0)
2347 fatal_error ("error closing %s: %m", asm_file_name);
2349 unlink_if_ordinary (asm_file_name);
2353 finish_optimization_passes ();
2358 dump_memory_report (true);
2360 /* Language-specific end of compilation actions. */
2361 lang_hooks.finish ();
2364 /* Initialize the compiler, and compile the input file. */
2368 /* Initialize timing first. The C front ends read the main file in
2369 the post_options hook, and C++ does file timings. */
2370 if (time_report || !quiet_flag || flag_detailed_statistics)
2372 timevar_start (TV_TOTAL);
2376 /* Don't do any more if an error has already occurred. */
2379 /* This must be run always, because it is needed to compute the FP
2380 predefined macros, such as __LDBL_MAX__, for targets using non
2381 default FP formats. */
2382 init_adjust_machine_modes ();
2384 /* Set up the back-end if requested. */
2388 /* Language-dependent initialization. Returns true on success. */
2389 if (lang_dependent_init (main_input_filename))
2395 /* Stop timing and print the times. */
2396 timevar_stop (TV_TOTAL);
2397 timevar_print (stderr);
2400 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2401 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2402 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2404 It is not safe to call this function more than once. */
2407 toplev_main (int argc, char **argv)
2409 expandargv (&argc, &argv);
2411 save_argv = CONST_CAST2 (const char **, char **, argv);
2413 /* Initialization of GCC's environment, and diagnostics. */
2414 general_init (argv[0]);
2416 /* Parse the options and do minimal processing; basically just
2417 enough to default flags appropriately. */
2418 decode_options (argc, CONST_CAST2 (const char **, char **, argv));
2422 initialize_plugins ();
2425 print_version (stderr, "");
2428 print_plugins_help (stderr, "");
2430 /* Exit early if we can (e.g. -help). */
2431 if (!exit_after_options)
2434 if (warningcount || errorcount)
2435 print_ignored_options ();
2436 diagnostic_finish (global_dc);
2438 /* Invoke registered plugin callbacks if any. */
2439 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2441 finalize_plugins ();
2442 if (errorcount || sorrycount)
2443 return (FATAL_EXIT_CODE);
2445 return (SUCCESS_EXIT_CODE);