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>
44 #include "realmpfr.h" /* For GMP/MPFR/MPC versions, in print_version. */
49 #include "insn-attr.h"
50 #include "insn-config.h"
51 #include "insn-flags.h"
52 #include "hard-reg-set.h"
59 #include "basic-block.h"
65 #include "diagnostic.h"
66 #include "tree-diagnostic.h"
67 #include "tree-pretty-print.h"
71 #include "dwarf2asm.h"
72 #include "integrate.h"
75 #include "langhooks.h"
76 #include "cfglayout.h"
78 #include "hosthooks.h"
81 #include "opts-diagnostic.h"
83 #include "value-prof.h"
84 #include "alloc-pool.h"
85 #include "tree-mudflap.h"
86 #include "tree-pass.h"
88 #include "tree-ssa-alias.h"
91 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
92 #include "dwarf2out.h"
95 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
99 #ifdef SDB_DEBUGGING_INFO
103 #ifdef XCOFF_DEBUGGING_INFO
104 #include "xcoffout.h" /* Needed for external data
105 declarations for e.g. AIX 4.x. */
108 static void general_init (const char *);
109 static void do_compile (void);
110 static void process_options (void);
111 static void backend_init (void);
112 static int lang_dependent_init (const char *);
113 static void init_asm_output (const char *);
114 static void finalize (void);
116 static void crash_signal (int) ATTRIBUTE_NORETURN
;
117 static void setup_core_dumping (void);
118 static void compile_file (void);
120 /* Nonzero to dump debug info whilst parsing (-dy option). */
121 static int set_yydebug
;
123 /* True if we don't need a backend (e.g. preprocessing only). */
124 static bool no_backend
;
126 /* Length of line when printing switch values. */
129 /* Decoded options, and number of such options. */
130 static struct cl_decoded_option
*save_decoded_options
;
131 static unsigned int save_decoded_options_count
;
133 /* Name of top-level original source file (what was input to cpp).
134 This comes from the #-command at the beginning of the actual input.
135 If there isn't any there, then this is the cc1 input file name. */
137 const char *main_input_filename
;
139 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
140 to optimize in process_options (). */
141 #define AUTODETECT_VALUE 2
143 /* Name to use as base of names for dump output files. */
145 const char *dump_base_name
;
147 /* Directory used for dump output files. */
149 const char *dump_dir_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 /* Other flags saying which kinds of debugging dump have been requested. */
169 int rtl_dump_and_exit
;
170 int flag_print_asm_name
;
171 enum graph_dump_types graph_dump_format
;
173 /* Name for output file of assembly code, specified with -o. */
175 const char *asm_file_name
;
177 /* Nonzero means do optimizations. -O.
178 Particular numeric values stand for particular amounts of optimization;
179 thus, -O2 stores 2 here. However, the optimizations beyond the basic
180 ones are not controlled directly by this variable. Instead, they are
181 controlled by individual `flag_...' variables that are defaulted
182 based on this variable. */
186 /* Nonzero means optimize for size. -Os.
187 The only valid values are zero and nonzero. When optimize_size is
188 nonzero, optimize defaults to 2, but certain individual code
189 bloating optimizations are disabled. */
191 int optimize_size
= 0;
193 /* True if this is the lto front end. This is used to disable
194 gimple generation and lowering passes that are normally run on the
195 output of a front end. These passes must be bypassed for lto since
196 they have already been done before the gimple was written. */
198 bool in_lto_p
= false;
200 /* Nonzero if we should write GIMPLE bytecode for link-time optimization. */
202 int flag_generate_lto
;
204 /* The FUNCTION_DECL for the function currently being compiled,
205 or 0 if between functions. */
206 tree current_function_decl
;
208 /* Set to the FUNC_BEGIN label of the current function, or NULL
210 const char * current_function_func_begin_label
;
212 /* A random sequence of characters, unless overridden by user. */
213 static const char *flag_random_seed
;
215 /* A local time stamp derived from the time of compilation. It will be
216 zero if the system cannot provide a time. It will be -1u, if the
217 user has specified a particular random seed. */
222 /* 0 means straightforward implementation of complex divide acceptable.
223 1 means wide ranges of inputs must work for complex divide.
224 2 means C99-like requirements for complex multiply and divide. */
226 int flag_complex_method
= 1;
228 /* Nonzero means we should be saving declaration info into a .X file. */
230 int flag_gen_aux_info
= 0;
232 /* Specified name of aux-info file. */
234 const char *aux_info_file_name
;
236 /* Nonzero if we are compiling code for a shared library, zero for
241 /* Generate code for GNU or NeXT Objective-C runtime environment. */
243 #ifdef NEXT_OBJC_RUNTIME
244 int flag_next_runtime
= 1;
246 int flag_next_runtime
= 0;
249 /* Set to the default thread-local storage (tls) model to use. */
251 enum tls_model flag_tls_default
= TLS_MODEL_GLOBAL_DYNAMIC
;
253 /* Set the default region and algorithm for the integrated register
256 enum ira_algorithm flag_ira_algorithm
= IRA_ALGORITHM_CB
;
257 enum ira_region flag_ira_region
= IRA_REGION_MIXED
;
259 /* Set the default for excess precision. */
261 enum excess_precision flag_excess_precision_cmdline
= EXCESS_PRECISION_DEFAULT
;
262 enum excess_precision flag_excess_precision
= EXCESS_PRECISION_DEFAULT
;
264 /* Nonzero means change certain warnings into errors.
265 Usually these are warnings about failure to conform to some standard. */
267 int flag_pedantic_errors
= 0;
269 /* Nonzero means make permerror produce warnings instead of errors. */
271 int flag_permissive
= 0;
273 /* -dA causes debug commentary information to be produced in
274 the generated assembly code (to make it more readable). This option
275 is generally only of use to those who actually need to read the
276 generated assembly code (perhaps while debugging the compiler itself).
277 Currently, this switch is only used by dwarfout.c; however, it is intended
278 to be a catchall for printing debug information in the assembler file. */
280 int flag_debug_asm
= 0;
282 /* -dP causes the rtl to be emitted as a comment in assembly. */
284 int flag_dump_rtl_in_asm
= 0;
286 /* When non-NULL, indicates that whenever space is allocated on the
287 stack, the resulting stack pointer must not pass this
288 address---that is, for stacks that grow downward, the stack pointer
289 must always be greater than or equal to this address; for stacks
290 that grow upward, the stack pointer must be less than this address.
291 At present, the rtx may be either a REG or a SYMBOL_REF, although
292 the support provided depends on the backend. */
295 /* Positive if we should track variables, negative if we should run
296 the var-tracking pass only to discard debug annotations, zero if
297 we're not to run it. When flag_var_tracking == AUTODETECT_VALUE it
298 will be set according to optimize, debug_info_level and debug_hooks
299 in process_options (). */
300 int flag_var_tracking
= AUTODETECT_VALUE
;
302 /* Positive if we should track variables at assignments, negative if
303 we should run the var-tracking pass only to discard debug
304 annotations. When flag_var_tracking_assignments ==
305 AUTODETECT_VALUE it will be set according to flag_var_tracking. */
306 int flag_var_tracking_assignments
= AUTODETECT_VALUE
;
308 /* Nonzero if we should toggle flag_var_tracking_assignments after
309 processing options and computing its default. */
310 int flag_var_tracking_assignments_toggle
= 0;
312 /* Type of stack check. */
313 enum stack_check_type flag_stack_check
= NO_STACK_CHECK
;
315 /* True if the user has tagged the function with the 'section'
318 bool user_defined_section_attribute
= false;
320 struct target_flag_state default_target_flag_state
;
321 #if SWITCHABLE_TARGET
322 struct target_flag_state
*this_target_flag_state
= &default_target_flag_state
;
324 #define this_target_flag_state (&default_target_flag_state)
329 const char *const string
;
333 lang_independent_options
;
335 /* Nonzero if subexpressions must be evaluated from left-to-right. */
336 int flag_evaluation_order
= 0;
338 /* The user symbol prefix after having resolved same. */
339 const char *user_label_prefix
;
341 static const param_info lang_independent_params
[] = {
342 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
343 { OPTION, DEFAULT, false, MIN, MAX, HELP },
344 #include "params.def"
346 { NULL
, 0, false, 0, 0, NULL
}
349 /* Output files for assembler code (real compiler output)
350 and debugging dumps. */
354 FILE *dump_file
= NULL
;
355 const char *dump_file_name
;
357 /* The current working directory of a translation. It's generally the
358 directory from which compilation was initiated, but a preprocessed
359 file may specify the original directory in which it was
362 static const char *src_pwd
;
364 /* Initialize src_pwd with the given string, and return true. If it
365 was already initialized, return false. As a special case, it may
366 be called with a NULL argument to test whether src_pwd has NOT been
370 set_src_pwd (const char *pwd
)
374 if (strcmp (src_pwd
, pwd
) == 0)
380 src_pwd
= xstrdup (pwd
);
384 /* Return the directory from which the translation unit was initiated,
385 in case set_src_pwd() was not called before to assign it a
401 /* Called when the start of a function definition is parsed,
402 this function prints on stderr the name of the function. */
404 announce_function (tree decl
)
408 if (rtl_dump_and_exit
)
409 fprintf (stderr
, "%s ",
410 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl
))));
412 fprintf (stderr
, " %s",
413 identifier_to_locale (lang_hooks
.decl_printable_name (decl
, 2)));
415 pp_needs_newline (global_dc
->printer
) = true;
416 diagnostic_set_last_function (global_dc
, (diagnostic_info
*) NULL
);
420 /* Initialize local_tick with the time of day, or -1 if
421 flag_random_seed is set. */
424 init_local_tick (void)
426 if (!flag_random_seed
)
428 /* Get some more or less random data. */
429 #ifdef HAVE_GETTIMEOFDAY
433 gettimeofday (&tv
, NULL
);
434 local_tick
= tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000;
438 time_t now
= time (NULL
);
440 if (now
!= (time_t)-1)
441 local_tick
= (unsigned) now
;
449 /* Set up a default flag_random_seed and local_tick, unless the user
450 already specified one. Must be called after init_local_tick. */
453 init_random_seed (void)
455 unsigned HOST_WIDE_INT value
;
456 static char random_seed
[HOST_BITS_PER_WIDE_INT
/ 4 + 3];
458 value
= local_tick
^ getpid ();
460 sprintf (random_seed
, HOST_WIDE_INT_PRINT_HEX
, value
);
461 flag_random_seed
= random_seed
;
464 /* Obtain the random_seed string. Unless NOINIT, initialize it if
465 it's not provided in the command line. */
468 get_random_seed (bool noinit
)
470 if (!flag_random_seed
&& !noinit
)
472 return flag_random_seed
;
475 /* Modify the random_seed string to VAL. Return its previous
479 set_random_seed (const char *val
)
481 const char *old
= flag_random_seed
;
482 flag_random_seed
= val
;
486 #if GCC_VERSION < 3004
488 /* The functions floor_log2 and exact_log2 are defined as inline
489 functions in toplev.h if GCC_VERSION >= 3004. The definitions here
490 are used for older versions of gcc. */
492 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
493 If X is 0, return -1. */
496 floor_log2 (unsigned HOST_WIDE_INT x
)
503 if (HOST_BITS_PER_WIDE_INT
> 64)
504 if (x
>= (unsigned HOST_WIDE_INT
) 1 << (t
+ 64))
506 if (HOST_BITS_PER_WIDE_INT
> 32)
507 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 32))
509 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 16))
511 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 8))
513 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 4))
515 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 2))
517 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 1))
523 /* Return the logarithm of X, base 2, considering X unsigned,
524 if X is a power of 2. Otherwise, returns -1. */
527 exact_log2 (unsigned HOST_WIDE_INT x
)
531 return floor_log2 (x
);
534 #endif /* GCC_VERSION < 3004 */
536 /* Handler for fatal signals, such as SIGSEGV. These are transformed
537 into ICE messages, which is much more user friendly. In case the
538 error printer crashes, reset the signal to prevent infinite recursion. */
541 crash_signal (int signo
)
543 signal (signo
, SIG_DFL
);
545 /* If we crashed while processing an ASM statement, then be a little more
546 graceful. It's most likely the user's fault. */
547 if (this_is_asm_operands
)
549 output_operand_lossage ("unrecoverable error");
550 exit (FATAL_EXIT_CODE
);
553 internal_error ("%s", strsignal (signo
));
556 /* Arrange to dump core on error. (The regular error message is still
557 printed first, except in the case of abort().) */
560 setup_core_dumping (void)
563 signal (SIGABRT
, SIG_DFL
);
565 #if defined(HAVE_SETRLIMIT)
568 if (getrlimit (RLIMIT_CORE
, &rlim
) != 0)
569 fatal_error ("getting core file size maximum limit: %m");
570 rlim
.rlim_cur
= rlim
.rlim_max
;
571 if (setrlimit (RLIMIT_CORE
, &rlim
) != 0)
572 fatal_error ("setting core file size limit to maximum: %m");
575 diagnostic_abort_on_error (global_dc
);
579 /* Strip off a legitimate source ending from the input string NAME of
580 length LEN. Rather than having to know the names used by all of
581 our front ends, we strip off an ending of a period followed by
582 up to five characters. (Java uses ".class".) */
585 strip_off_ending (char *name
, int len
)
588 for (i
= 2; i
< 6 && len
> i
; i
++)
590 if (name
[len
- i
] == '.')
592 name
[len
- i
] = '\0';
598 /* Output a quoted string. */
601 output_quoted_string (FILE *asm_file
, const char *string
)
603 #ifdef OUTPUT_QUOTED_STRING
604 OUTPUT_QUOTED_STRING (asm_file
, string
);
608 putc ('\"', asm_file
);
609 while ((c
= *string
++) != 0)
613 if (c
== '\"' || c
== '\\')
614 putc ('\\', asm_file
);
618 fprintf (asm_file
, "\\%03o", (unsigned char) c
);
620 putc ('\"', asm_file
);
624 /* Output a file name in the form wanted by System V. */
627 output_file_directive (FILE *asm_file
, const char *input_name
)
632 if (input_name
== NULL
)
633 input_name
= "<stdin>";
635 input_name
= remap_debug_filename (input_name
);
637 len
= strlen (input_name
);
638 na
= input_name
+ len
;
640 /* NA gets INPUT_NAME sans directory names. */
641 while (na
> input_name
)
643 if (IS_DIR_SEPARATOR (na
[-1]))
648 #ifdef ASM_OUTPUT_SOURCE_FILENAME
649 ASM_OUTPUT_SOURCE_FILENAME (asm_file
, na
);
651 fprintf (asm_file
, "\t.file\t");
652 output_quoted_string (asm_file
, na
);
653 putc ('\n', asm_file
);
657 /* A subroutine of wrapup_global_declarations. We've come to the end of
658 the compilation unit. All deferred variables should be undeferred,
659 and all incomplete decls should be finalized. */
662 wrapup_global_declaration_1 (tree decl
)
664 /* We're not deferring this any longer. Assignment is conditional to
665 avoid needlessly dirtying PCH pages. */
666 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_WITH_VIS
)
667 && DECL_DEFER_OUTPUT (decl
) != 0)
668 DECL_DEFER_OUTPUT (decl
) = 0;
670 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_SIZE (decl
) == 0)
671 lang_hooks
.finish_incomplete_decl (decl
);
674 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
675 needs to be output. Return true if it is output. */
678 wrapup_global_declaration_2 (tree decl
)
680 if (TREE_ASM_WRITTEN (decl
) || DECL_EXTERNAL (decl
))
683 /* Don't write out static consts, unless we still need them.
685 We also keep static consts if not optimizing (for debugging),
686 unless the user specified -fno-keep-static-consts.
687 ??? They might be better written into the debug information.
688 This is possible when using DWARF.
690 A language processor that wants static constants to be always
691 written out (even if it is not used) is responsible for
692 calling rest_of_decl_compilation itself. E.g. the C front-end
693 calls rest_of_decl_compilation from finish_decl.
694 One motivation for this is that is conventional in some
695 environments to write things like:
696 static const char rcsid[] = "... version string ...";
697 intending to force the string to be in the executable.
699 A language processor that would prefer to have unneeded
700 static constants "optimized away" would just defer writing
701 them out until here. E.g. C++ does this, because static
702 constants are often defined in header files.
704 ??? A tempting alternative (for both C and C++) would be
705 to force a constant to be written if and only if it is
706 defined in a main file, as opposed to an include file. */
708 if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
710 struct varpool_node
*node
;
712 node
= varpool_get_node (decl
);
714 if (!node
&& flag_ltrans
)
716 else if (node
&& node
->finalized
)
718 else if (node
&& node
->alias
)
720 else if (!cgraph_global_info_ready
722 || TREE_USED (DECL_ASSEMBLER_NAME (decl
))))
724 else if (node
&& node
->needed
)
726 else if (DECL_COMDAT (decl
))
728 else if (TREE_READONLY (decl
) && !TREE_PUBLIC (decl
)
729 && (optimize
|| !flag_keep_static_consts
730 || DECL_ARTIFICIAL (decl
)))
735 rest_of_decl_compilation (decl
, 1, 1);
743 /* Do any final processing required for the declarations in VEC, of
744 which there are LEN. We write out inline functions and variables
745 that have been deferred until this point, but which are required.
746 Returns nonzero if anything was put out. */
749 wrapup_global_declarations (tree
*vec
, int len
)
751 bool reconsider
, output_something
= false;
754 for (i
= 0; i
< len
; i
++)
755 wrapup_global_declaration_1 (vec
[i
]);
757 /* Now emit any global variables or functions that we have been
758 putting off. We need to loop in case one of the things emitted
759 here references another one which comes earlier in the list. */
763 for (i
= 0; i
< len
; i
++)
764 reconsider
|= wrapup_global_declaration_2 (vec
[i
]);
766 output_something
= true;
770 return output_something
;
773 /* A subroutine of check_global_declarations. Issue appropriate warnings
774 for the global declaration DECL. */
777 check_global_declaration_1 (tree decl
)
779 /* Warn about any function declared static but not defined. We don't
780 warn about variables, because many programs have static variables
781 that exist only to get some text into the object file. */
782 if (TREE_CODE (decl
) == FUNCTION_DECL
783 && DECL_INITIAL (decl
) == 0
784 && DECL_EXTERNAL (decl
)
785 && ! DECL_ARTIFICIAL (decl
)
786 && ! TREE_NO_WARNING (decl
)
787 && ! TREE_PUBLIC (decl
)
788 && (warn_unused_function
789 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))))
791 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
)))
792 pedwarn (input_location
, 0, "%q+F used but never defined", decl
);
794 warning (OPT_Wunused_function
, "%q+F declared %<static%> but never defined", decl
);
795 /* This symbol is effectively an "extern" declaration now. */
796 TREE_PUBLIC (decl
) = 1;
797 assemble_external (decl
);
800 /* Warn about static fns or vars defined but not used. */
801 if (((warn_unused_function
&& TREE_CODE (decl
) == FUNCTION_DECL
)
802 /* We don't warn about "static const" variables because the
803 "rcs_id" idiom uses that construction. */
804 || (warn_unused_variable
805 && TREE_CODE (decl
) == VAR_DECL
&& ! TREE_READONLY (decl
)))
806 && ! DECL_IN_SYSTEM_HEADER (decl
)
807 && ! TREE_USED (decl
)
808 /* The TREE_USED bit for file-scope decls is kept in the identifier,
809 to handle multiple external decls in different scopes. */
810 && ! (DECL_NAME (decl
) && TREE_USED (DECL_NAME (decl
)))
811 && ! DECL_EXTERNAL (decl
)
812 && ! TREE_PUBLIC (decl
)
813 /* A volatile variable might be used in some non-obvious way. */
814 && ! TREE_THIS_VOLATILE (decl
)
815 /* Global register variables must be declared to reserve them. */
816 && ! (TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
817 /* Otherwise, ask the language. */
818 && lang_hooks
.decls
.warn_unused_global (decl
))
819 warning ((TREE_CODE (decl
) == FUNCTION_DECL
)
820 ? OPT_Wunused_function
821 : OPT_Wunused_variable
,
822 "%q+D defined but not used", decl
);
825 /* Issue appropriate warnings for the global declarations in VEC (of
826 which there are LEN). */
829 check_global_declarations (tree
*vec
, int len
)
833 for (i
= 0; i
< len
; i
++)
834 check_global_declaration_1 (vec
[i
]);
837 /* Emit debugging information for all global declarations in VEC. */
840 emit_debug_global_declarations (tree
*vec
, int len
)
844 /* Avoid confusing the debug information machinery when there are errors. */
848 timevar_push (TV_SYMOUT
);
849 for (i
= 0; i
< len
; i
++)
850 debug_hooks
->global_decl (vec
[i
]);
851 timevar_pop (TV_SYMOUT
);
854 /* Warn about a use of an identifier which was marked deprecated. */
856 warn_deprecated_use (tree node
, tree attr
)
860 if (node
== 0 || !warn_deprecated_decl
)
866 attr
= DECL_ATTRIBUTES (node
);
867 else if (TYPE_P (node
))
869 tree decl
= TYPE_STUB_DECL (node
);
871 attr
= lookup_attribute ("deprecated",
872 TYPE_ATTRIBUTES (TREE_TYPE (decl
)));
877 attr
= lookup_attribute ("deprecated", attr
);
880 msg
= TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
)));
886 expanded_location xloc
= expand_location (DECL_SOURCE_LOCATION (node
));
888 warning (OPT_Wdeprecated_declarations
,
889 "%qD is deprecated (declared at %s:%d): %s",
890 node
, xloc
.file
, xloc
.line
, msg
);
892 warning (OPT_Wdeprecated_declarations
,
893 "%qD is deprecated (declared at %s:%d)",
894 node
, xloc
.file
, xloc
.line
);
896 else if (TYPE_P (node
))
898 tree what
= NULL_TREE
;
899 tree decl
= TYPE_STUB_DECL (node
);
901 if (TYPE_NAME (node
))
903 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
904 what
= TYPE_NAME (node
);
905 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
906 && DECL_NAME (TYPE_NAME (node
)))
907 what
= DECL_NAME (TYPE_NAME (node
));
912 expanded_location xloc
913 = expand_location (DECL_SOURCE_LOCATION (decl
));
917 warning (OPT_Wdeprecated_declarations
,
918 "%qE is deprecated (declared at %s:%d): %s",
919 what
, xloc
.file
, xloc
.line
, msg
);
921 warning (OPT_Wdeprecated_declarations
,
922 "%qE is deprecated (declared at %s:%d)", what
,
923 xloc
.file
, xloc
.line
);
928 warning (OPT_Wdeprecated_declarations
,
929 "type is deprecated (declared at %s:%d): %s",
930 xloc
.file
, xloc
.line
, msg
);
932 warning (OPT_Wdeprecated_declarations
,
933 "type is deprecated (declared at %s:%d)",
934 xloc
.file
, xloc
.line
);
942 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated: %s",
945 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated", what
);
950 warning (OPT_Wdeprecated_declarations
, "type is deprecated: %s",
953 warning (OPT_Wdeprecated_declarations
, "type is deprecated");
959 /* Compile an entire translation unit. Write a file of assembly
960 output and various debugging dumps. */
965 /* Initialize yet another pass. */
967 ggc_protect_identifiers
= true;
970 init_final (main_input_filename
);
971 coverage_init (aux_base_name
);
973 invoke_plugin_callbacks (PLUGIN_START_UNIT
, NULL
);
975 timevar_push (TV_PARSE
);
977 /* Call the parser, which parses the entire file (calling
978 rest_of_compilation for each function). */
979 lang_hooks
.parse_file (set_yydebug
);
981 /* Compilation is now finished except for writing
982 what's left of the symbol table output. */
983 timevar_pop (TV_PARSE
);
985 if (flag_syntax_only
|| flag_wpa
)
988 ggc_protect_identifiers
= false;
990 /* This must also call cgraph_finalize_compilation_unit. */
991 lang_hooks
.decls
.final_write_globals ();
996 /* Ensure that emulated TLS control vars are finalized and build
997 a static constructor for them, when it is required. */
998 if (!targetm
.have_tls
)
1001 varpool_assemble_pending_decls ();
1002 finish_aliases_2 ();
1004 /* Likewise for mudflap static object registrations. */
1006 mudflap_finish_file ();
1008 output_shared_constant_pool ();
1009 output_object_blocks ();
1011 /* Write out any pending weak symbol declarations. */
1014 /* This must be at the end before unwind and debug info.
1015 Some target ports emit PIC setup thunks here. */
1016 targetm
.asm_out
.code_end ();
1018 /* Do dbx symbols. */
1019 timevar_push (TV_SYMOUT
);
1021 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
1022 if (dwarf2out_do_frame ())
1023 dwarf2out_frame_finish ();
1026 (*debug_hooks
->finish
) (main_input_filename
);
1027 timevar_pop (TV_SYMOUT
);
1029 /* Output some stuff at end of file if nec. */
1031 dw2_output_indirect_constants ();
1033 /* Flush any pending external directives. */
1034 process_pending_assemble_externals ();
1036 /* Emit LTO marker if LTO info has been previously emitted. This is
1037 used by collect2 to determine whether an object file contains IL.
1038 We used to emit an undefined reference here, but this produces
1039 link errors if an object file with IL is stored into a shared
1040 library without invoking lto1. */
1041 if (flag_generate_lto
)
1043 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1044 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, NULL_TREE
,
1046 (unsigned HOST_WIDE_INT
) 1, 8);
1047 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1048 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, "__gnu_lto_v1",
1049 (unsigned HOST_WIDE_INT
) 1, 8);
1051 ASM_OUTPUT_COMMON (asm_out_file
, "__gnu_lto_v1",
1052 (unsigned HOST_WIDE_INT
) 1,
1053 (unsigned HOST_WIDE_INT
) 1);
1057 /* Attach a special .ident directive to the end of the file to identify
1058 the version of GCC which compiled this code. The format of the .ident
1059 string is patterned after the ones produced by native SVR4 compilers. */
1063 const char *pkg_version
= "(GNU) ";
1065 if (strcmp ("(GCC) ", pkgversion_string
))
1066 pkg_version
= pkgversion_string
;
1067 fprintf (asm_out_file
, "%s\"GCC: %s%s\"\n",
1068 IDENT_ASM_OP
, pkg_version
, version_string
);
1072 /* Invoke registered plugin callbacks. */
1073 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT
, NULL
);
1075 /* This must be at the end. Some target ports emit end of file directives
1076 into the assembly file here, and hence we can not output anything to the
1077 assembly file after this point. */
1078 targetm
.asm_out
.file_end ();
1081 /* Parse a -d... command line switch. */
1084 decode_d_option (const char *arg
)
1095 flag_print_asm_name
= 1;
1098 flag_dump_rtl_in_asm
= 1;
1099 flag_print_asm_name
= 1;
1102 graph_dump_format
= vcg
;
1105 rtl_dump_and_exit
= 1;
1110 case 'D': /* These are handled by the preprocessor. */
1117 setup_core_dumping();
1120 enable_rtl_dump_file ();
1124 warning (0, "unrecognized gcc debugging option: %c", c
);
1129 /* Indexed by enum debug_info_type. */
1130 const char *const debug_type_names
[] =
1132 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1135 /* Print version information to FILE.
1136 Each line begins with INDENT (for the case where FILE is the
1137 assembler output file). */
1140 print_version (FILE *file
, const char *indent
)
1142 static const char fmt1
[] =
1144 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1146 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1149 static const char fmt2
[] =
1150 N_("GMP version %s, MPFR version %s, MPC version %s\n");
1151 static const char fmt3
[] =
1152 N_("%s%swarning: %s header version %s differs from library version %s.\n");
1153 static const char fmt4
[] =
1154 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1156 #define __VERSION__ "[?]"
1159 file
== stderr
? _(fmt1
) : fmt1
,
1160 indent
, *indent
!= 0 ? " " : "",
1161 lang_hooks
.name
, pkgversion_string
, version_string
, TARGET_NAME
,
1162 indent
, __VERSION__
);
1164 /* We need to stringify the GMP macro values. Ugh, gmp_version has
1165 two string formats, "i.j.k" and "i.j" when k is zero. As of
1166 gmp-4.3.0, GMP always uses the 3 number format. */
1167 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1168 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1169 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
1170 #define GCC_GMP_VERSION \
1171 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
1172 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
1173 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1174 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1176 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1177 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1178 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1181 file
== stderr
? _(fmt2
) : fmt2
,
1182 GCC_GMP_STRINGIFY_VERSION
, MPFR_VERSION_STRING
, MPC_VERSION_STRING
);
1183 if (strcmp (GCC_GMP_STRINGIFY_VERSION
, gmp_version
))
1185 file
== stderr
? _(fmt3
) : fmt3
,
1186 indent
, *indent
!= 0 ? " " : "",
1187 "GMP", GCC_GMP_STRINGIFY_VERSION
, gmp_version
);
1188 if (strcmp (MPFR_VERSION_STRING
, mpfr_get_version ()))
1190 file
== stderr
? _(fmt3
) : fmt3
,
1191 indent
, *indent
!= 0 ? " " : "",
1192 "MPFR", MPFR_VERSION_STRING
, mpfr_get_version ());
1193 if (strcmp (MPC_VERSION_STRING
, mpc_get_version ()))
1195 file
== stderr
? _(fmt3
) : fmt3
,
1196 indent
, *indent
!= 0 ? " " : "",
1197 "MPC", MPC_VERSION_STRING
, mpc_get_version ());
1199 file
== stderr
? _(fmt4
) : fmt4
,
1200 indent
, *indent
!= 0 ? " " : "",
1201 PARAM_VALUE (GGC_MIN_EXPAND
), PARAM_VALUE (GGC_MIN_HEAPSIZE
));
1203 print_plugins_versions (file
, indent
);
1206 #ifdef ASM_COMMENT_START
1208 print_to_asm_out_file (print_switch_type type
, const char * text
)
1210 bool prepend_sep
= true;
1214 case SWITCH_TYPE_LINE_END
:
1215 putc ('\n', asm_out_file
);
1218 case SWITCH_TYPE_LINE_START
:
1219 fputs (ASM_COMMENT_START
, asm_out_file
);
1220 return strlen (ASM_COMMENT_START
);
1222 case SWITCH_TYPE_DESCRIPTIVE
:
1223 if (ASM_COMMENT_START
[0] == 0)
1224 prepend_sep
= false;
1226 case SWITCH_TYPE_PASSED
:
1227 case SWITCH_TYPE_ENABLED
:
1229 fputc (' ', asm_out_file
);
1230 fputs (text
, asm_out_file
);
1231 /* No need to return the length here as
1232 print_single_switch has already done it. */
1242 print_to_stderr (print_switch_type type
, const char * text
)
1246 case SWITCH_TYPE_LINE_END
:
1247 putc ('\n', stderr
);
1250 case SWITCH_TYPE_LINE_START
:
1253 case SWITCH_TYPE_PASSED
:
1254 case SWITCH_TYPE_ENABLED
:
1255 fputc (' ', stderr
);
1258 case SWITCH_TYPE_DESCRIPTIVE
:
1259 fputs (text
, stderr
);
1260 /* No need to return the length here as
1261 print_single_switch has already done it. */
1269 /* Print an option value and return the adjusted position in the line.
1270 ??? print_fn doesn't handle errors, eg disk full; presumably other
1271 code will catch a disk full though. */
1274 print_single_switch (print_switch_fn_type print_fn
,
1276 print_switch_type type
,
1279 /* The ultrix fprintf returns 0 on success, so compute the result
1280 we want here since we need it for the following test. The +1
1281 is for the separator character that will probably be emitted. */
1282 int len
= strlen (text
) + 1;
1285 && pos
+ len
> MAX_LINE
)
1287 print_fn (SWITCH_TYPE_LINE_END
, NULL
);
1292 pos
+= print_fn (SWITCH_TYPE_LINE_START
, NULL
);
1294 print_fn (type
, text
);
1298 /* Print active target switches using PRINT_FN.
1299 POS is the current cursor position and MAX is the size of a "line".
1300 Each line begins with INDENT and ends with TERM.
1301 Each switch is separated from the next by SEP. */
1304 print_switch_values (print_switch_fn_type print_fn
)
1309 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1310 that it can be printed below. This helps reproducibility. */
1311 if (!flag_random_seed
)
1312 init_random_seed ();
1314 /* Print the options as passed. */
1315 pos
= print_single_switch (print_fn
, pos
,
1316 SWITCH_TYPE_DESCRIPTIVE
, _("options passed: "));
1318 for (j
= 1; j
< save_decoded_options_count
; j
++)
1320 switch (save_decoded_options
[j
].opt_index
)
1333 pos
= print_single_switch (print_fn
, pos
, SWITCH_TYPE_PASSED
,
1334 save_decoded_options
[j
].orig_option_with_args_text
);
1338 print_fn (SWITCH_TYPE_LINE_END
, NULL
);
1340 /* Print the -f and -m options that have been enabled.
1341 We don't handle language specific options but printing argv
1343 pos
= print_single_switch (print_fn
, 0,
1344 SWITCH_TYPE_DESCRIPTIVE
, _("options enabled: "));
1346 for (j
= 0; j
< cl_options_count
; j
++)
1347 if ((cl_options
[j
].flags
& CL_REPORT
)
1348 && option_enabled (j
) > 0)
1349 pos
= print_single_switch (print_fn
, pos
,
1350 SWITCH_TYPE_ENABLED
, cl_options
[j
].opt_text
);
1352 print_fn (SWITCH_TYPE_LINE_END
, NULL
);
1355 /* Open assembly code output file. Do this even if -fsyntax-only is
1356 on, because then the driver will have provided the name of a
1357 temporary file or bit bucket for us. NAME is the file specified on
1358 the command line, possibly NULL. */
1360 init_asm_output (const char *name
)
1362 if (name
== NULL
&& asm_file_name
== 0)
1363 asm_out_file
= stdout
;
1366 if (asm_file_name
== 0)
1368 int len
= strlen (dump_base_name
);
1369 char *dumpname
= XNEWVEC (char, len
+ 6);
1371 memcpy (dumpname
, dump_base_name
, len
+ 1);
1372 strip_off_ending (dumpname
, len
);
1373 strcat (dumpname
, ".s");
1374 asm_file_name
= dumpname
;
1376 if (!strcmp (asm_file_name
, "-"))
1377 asm_out_file
= stdout
;
1379 asm_out_file
= fopen (asm_file_name
, "w+b");
1380 if (asm_out_file
== 0)
1381 fatal_error ("can%'t open %s for writing: %m", asm_file_name
);
1384 if (!flag_syntax_only
)
1386 targetm
.asm_out
.file_start ();
1388 if (flag_record_gcc_switches
)
1390 if (targetm
.asm_out
.record_gcc_switches
)
1392 /* Let the target know that we are about to start recording. */
1393 targetm
.asm_out
.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE
,
1395 /* Now record the switches. */
1396 print_switch_values (targetm
.asm_out
.record_gcc_switches
);
1397 /* Let the target know that the recording is over. */
1398 targetm
.asm_out
.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE
,
1402 inform (input_location
, "-frecord-gcc-switches is not supported by the current target");
1405 #ifdef ASM_COMMENT_START
1406 if (flag_verbose_asm
)
1408 /* Print the list of switches in effect
1409 into the assembler file as comments. */
1410 print_version (asm_out_file
, ASM_COMMENT_START
);
1411 print_switch_values (print_to_asm_out_file
);
1412 putc ('\n', asm_out_file
);
1418 /* Return true if the state of option OPTION should be stored in PCH files
1419 and checked by default_pch_valid_p. Store the option's current state
1423 option_affects_pch_p (int option
, struct cl_option_state
*state
)
1425 if ((cl_options
[option
].flags
& CL_TARGET
) == 0)
1427 if (cl_options
[option
].flag_var
== &target_flags
)
1428 if (targetm
.check_pch_target_flags
)
1430 return get_option_state (option
, state
);
1433 /* Default version of get_pch_validity.
1434 By default, every flag difference is fatal; that will be mostly right for
1435 most targets, but completely right for very few. */
1438 default_get_pch_validity (size_t *sz
)
1440 struct cl_option_state state
;
1445 if (targetm
.check_pch_target_flags
)
1446 *sz
+= sizeof (target_flags
);
1447 for (i
= 0; i
< cl_options_count
; i
++)
1448 if (option_affects_pch_p (i
, &state
))
1451 result
= r
= XNEWVEC (char, *sz
);
1455 if (targetm
.check_pch_target_flags
)
1457 memcpy (r
, &target_flags
, sizeof (target_flags
));
1458 r
+= sizeof (target_flags
);
1461 for (i
= 0; i
< cl_options_count
; i
++)
1462 if (option_affects_pch_p (i
, &state
))
1464 memcpy (r
, state
.data
, state
.size
);
1471 /* Return a message which says that a PCH file was created with a different
1472 setting of OPTION. */
1475 pch_option_mismatch (const char *option
)
1479 asprintf (&r
, _("created and used with differing settings of '%s'"), option
);
1481 return _("out of memory");
1485 /* Default version of pch_valid_p. */
1488 default_pch_valid_p (const void *data_p
, size_t len
)
1490 struct cl_option_state state
;
1491 const char *data
= (const char *)data_p
;
1494 /* -fpic and -fpie also usually make a PCH invalid. */
1495 if (data
[0] != flag_pic
)
1496 return _("created and used with different settings of -fpic");
1497 if (data
[1] != flag_pie
)
1498 return _("created and used with different settings of -fpie");
1501 /* Check target_flags. */
1502 if (targetm
.check_pch_target_flags
)
1507 memcpy (&tf
, data
, sizeof (target_flags
));
1508 data
+= sizeof (target_flags
);
1509 len
-= sizeof (target_flags
);
1510 r
= targetm
.check_pch_target_flags (tf
);
1515 for (i
= 0; i
< cl_options_count
; i
++)
1516 if (option_affects_pch_p (i
, &state
))
1518 if (memcmp (data
, state
.data
, state
.size
) != 0)
1519 return pch_option_mismatch (cl_options
[i
].opt_text
);
1527 /* Default tree printer. Handles declarations only. */
1529 default_tree_printer (pretty_printer
*pp
, text_info
*text
, const char *spec
,
1530 int precision
, bool wide
, bool set_locus
, bool hash
)
1534 /* FUTURE: %+x should set the locus. */
1535 if (precision
!= 0 || wide
|| hash
)
1541 t
= va_arg (*text
->args_ptr
, tree
);
1542 if (TREE_CODE (t
) == IDENTIFIER_NODE
)
1544 pp_identifier (pp
, IDENTIFIER_POINTER (t
));
1550 t
= va_arg (*text
->args_ptr
, tree
);
1551 if (DECL_DEBUG_EXPR_IS_FROM (t
) && DECL_DEBUG_EXPR (t
))
1552 t
= DECL_DEBUG_EXPR (t
);
1557 t
= va_arg (*text
->args_ptr
, tree
);
1561 percent_K_format (text
);
1568 if (set_locus
&& text
->locus
)
1569 *text
->locus
= DECL_SOURCE_LOCATION (t
);
1573 const char *n
= DECL_NAME (t
)
1574 ? identifier_to_locale (lang_hooks
.decl_printable_name (t
, 2))
1579 dump_generic_node (pp
, t
, 0, TDF_DIAGNOSTIC
, 0);
1584 /* A helper function; used as the reallocator function for cpp's line
1587 realloc_for_line_map (void *ptr
, size_t len
)
1589 return GGC_RESIZEVAR (void, ptr
, len
);
1592 /* A helper function: used as the allocator function for
1593 identifier_to_locale. */
1595 alloc_for_identifier_to_locale (size_t len
)
1597 return ggc_alloc_atomic (len
);
1600 /* Initialization of the front end environment, before command line
1601 options are parsed. Signal handlers, internationalization etc.
1602 ARGV0 is main's argv[0]. */
1604 general_init (const char *argv0
)
1608 p
= argv0
+ strlen (argv0
);
1609 while (p
!= argv0
&& !IS_DIR_SEPARATOR (p
[-1]))
1613 xmalloc_set_program_name (progname
);
1617 /* Unlock the stdio streams. */
1618 unlock_std_streams ();
1620 gcc_init_libintl ();
1622 identifier_to_locale_alloc
= alloc_for_identifier_to_locale
;
1623 identifier_to_locale_free
= ggc_free
;
1625 /* Initialize the diagnostics reporting machinery, so option parsing
1626 can give warnings and errors. */
1627 diagnostic_initialize (global_dc
, N_OPTS
);
1628 diagnostic_starter (global_dc
) = default_tree_diagnostic_starter
;
1629 /* Set a default printer. Language specific initializations will
1630 override it later. */
1631 pp_format_decoder (global_dc
->printer
) = &default_tree_printer
;
1632 global_dc
->show_option_requested
= flag_diagnostics_show_option
;
1633 global_dc
->show_column
= flag_show_column
;
1634 global_dc
->internal_error
= plugins_internal_error_function
;
1635 global_dc
->option_enabled
= option_enabled
;
1636 global_dc
->option_name
= option_name
;
1638 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1640 signal (SIGSEGV
, crash_signal
);
1643 signal (SIGILL
, crash_signal
);
1646 signal (SIGBUS
, crash_signal
);
1649 signal (SIGABRT
, crash_signal
);
1651 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1652 signal (SIGIOT
, crash_signal
);
1655 signal (SIGFPE
, crash_signal
);
1658 /* Other host-specific signal setup. */
1659 (*host_hooks
.extra_signals
)();
1661 /* Initialize the garbage-collector, string pools and tree type hash
1665 line_table
= ggc_alloc_line_maps ();
1666 linemap_init (line_table
);
1667 line_table
->reallocator
= realloc_for_line_map
;
1670 /* Initialize register usage now so switches may override. */
1673 /* Register the language-independent parameters. */
1674 add_params (lang_independent_params
, LAST_PARAM
);
1676 /* This must be done after add_params but before argument processing. */
1677 init_ggc_heuristics();
1678 init_optimization_passes ();
1679 statistics_early_init ();
1682 /* Return true if the current target supports -fsection-anchors. */
1685 target_supports_section_anchors_p (void)
1687 if (targetm
.min_anchor_offset
== 0 && targetm
.max_anchor_offset
== 0)
1690 if (targetm
.asm_out
.output_anchor
== NULL
)
1696 /* Default the align_* variables to 1 if they're still unset, and
1697 set up the align_*_log variables. */
1699 init_alignments (void)
1701 if (align_loops
<= 0)
1703 if (align_loops_max_skip
> align_loops
)
1704 align_loops_max_skip
= align_loops
- 1;
1705 align_loops_log
= floor_log2 (align_loops
* 2 - 1);
1706 if (align_jumps
<= 0)
1708 if (align_jumps_max_skip
> align_jumps
)
1709 align_jumps_max_skip
= align_jumps
- 1;
1710 align_jumps_log
= floor_log2 (align_jumps
* 2 - 1);
1711 if (align_labels
<= 0)
1713 align_labels_log
= floor_log2 (align_labels
* 2 - 1);
1714 if (align_labels_max_skip
> align_labels
)
1715 align_labels_max_skip
= align_labels
- 1;
1716 if (align_functions
<= 0)
1717 align_functions
= 1;
1718 align_functions_log
= floor_log2 (align_functions
* 2 - 1);
1721 /* Process the options that have been parsed. */
1723 process_options (void)
1725 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1726 This can happen with incorrect pre-processed input. */
1727 debug_hooks
= &do_nothing_debug_hooks
;
1729 /* This replaces set_Wunused. */
1730 if (warn_unused_function
== -1)
1731 warn_unused_function
= warn_unused
;
1732 if (warn_unused_label
== -1)
1733 warn_unused_label
= warn_unused
;
1734 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */
1735 if (warn_unused_parameter
== -1)
1736 warn_unused_parameter
= (warn_unused
&& extra_warnings
);
1737 if (warn_unused_variable
== -1)
1738 warn_unused_variable
= warn_unused
;
1739 /* Wunused-but-set-parameter is enabled if both -Wunused -Wextra are
1741 if (warn_unused_but_set_parameter
== -1)
1742 warn_unused_but_set_parameter
= (warn_unused
&& extra_warnings
);
1743 if (warn_unused_but_set_variable
== -1)
1744 warn_unused_but_set_variable
= warn_unused
;
1745 if (warn_unused_value
== -1)
1746 warn_unused_value
= warn_unused
;
1748 /* This replaces set_Wextra. */
1749 if (warn_uninitialized
== -1)
1750 warn_uninitialized
= extra_warnings
;
1752 /* Allow the front end to perform consistency checks and do further
1753 initialization based on the command line options. This hook also
1754 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1755 so we can correctly initialize debug output. */
1756 no_backend
= lang_hooks
.post_options (&main_input_filename
);
1758 /* Some machines may reject certain combinations of options. */
1759 targetm
.target_option
.override ();
1761 /* Avoid any informative notes in the second run of -fcompare-debug. */
1762 if (flag_compare_debug
)
1763 diagnostic_inhibit_notes (global_dc
);
1765 if (flag_section_anchors
&& !target_supports_section_anchors_p ())
1767 warning (OPT_fsection_anchors
,
1768 "this target does not support %qs", "-fsection-anchors");
1769 flag_section_anchors
= 0;
1772 if (flag_short_enums
== 2)
1773 flag_short_enums
= targetm
.default_short_enums ();
1775 /* Set aux_base_name if not already set. */
1778 else if (main_input_filename
)
1780 char *name
= xstrdup (lbasename (main_input_filename
));
1782 strip_off_ending (name
, strlen (name
));
1783 aux_base_name
= name
;
1786 aux_base_name
= "gccaux";
1791 || flag_loop_interchange
1792 || flag_loop_strip_mine
1793 || flag_graphite_identity
1794 || flag_loop_parallelize_all
)
1795 sorry ("Graphite loop optimizations cannot be used");
1798 /* Unrolling all loops implies that standard loop unrolling must also
1800 if (flag_unroll_all_loops
)
1801 flag_unroll_loops
= 1;
1803 /* The loop unrolling code assumes that cse will be run after loop.
1804 web and rename-registers also help when run after loop unrolling. */
1805 if (flag_rerun_cse_after_loop
== AUTODETECT_VALUE
)
1806 flag_rerun_cse_after_loop
= flag_unroll_loops
|| flag_peel_loops
;
1808 if (flag_web
== AUTODETECT_VALUE
)
1809 flag_web
= flag_unroll_loops
|| flag_peel_loops
;
1811 if (flag_rename_registers
== AUTODETECT_VALUE
)
1812 flag_rename_registers
= flag_unroll_loops
|| flag_peel_loops
;
1814 if (flag_non_call_exceptions
)
1815 flag_asynchronous_unwind_tables
= 1;
1816 if (flag_asynchronous_unwind_tables
)
1817 flag_unwind_tables
= 1;
1819 if (flag_value_profile_transformations
)
1820 flag_profile_values
= 1;
1822 /* Warn about options that are not supported on this machine. */
1823 #ifndef INSN_SCHEDULING
1824 if (flag_schedule_insns
|| flag_schedule_insns_after_reload
)
1825 warning (0, "instruction scheduling not supported on this target machine");
1828 if (flag_delayed_branch
)
1829 warning (0, "this target machine does not have delayed branches");
1832 user_label_prefix
= USER_LABEL_PREFIX
;
1833 if (flag_leading_underscore
!= -1)
1835 /* If the default prefix is more complicated than "" or "_",
1836 issue a warning and ignore this option. */
1837 if (user_label_prefix
[0] == 0 ||
1838 (user_label_prefix
[0] == '_' && user_label_prefix
[1] == 0))
1840 user_label_prefix
= flag_leading_underscore
? "_" : "";
1843 warning (0, "-f%sleading-underscore not supported on this target machine",
1844 flag_leading_underscore
? "" : "no-");
1847 /* If we are in verbose mode, write out the version and maybe all the
1848 option flags in use. */
1851 print_version (stderr
, "");
1853 print_switch_values (print_to_stderr
);
1856 if (flag_syntax_only
)
1858 write_symbols
= NO_DEBUG
;
1864 if (debug_info_level
== DINFO_LEVEL_NONE
)
1866 debug_info_level
= DINFO_LEVEL_NORMAL
;
1868 if (write_symbols
== NO_DEBUG
)
1869 write_symbols
= PREFERRED_DEBUGGING_TYPE
;
1872 debug_info_level
= DINFO_LEVEL_NONE
;
1875 if (flag_dump_final_insns
&& !flag_syntax_only
&& !no_backend
)
1877 FILE *final_output
= fopen (flag_dump_final_insns
, "w");
1880 error ("could not open final insn dump file %qs: %m",
1881 flag_dump_final_insns
);
1882 flag_dump_final_insns
= NULL
;
1884 else if (fclose (final_output
))
1886 error ("could not close zeroed insn dump file %qs: %m",
1887 flag_dump_final_insns
);
1888 flag_dump_final_insns
= NULL
;
1892 /* Unless over-ridden for the target, assume that all DWARF levels
1893 may be emitted, if DWARF2_DEBUG is selected. */
1894 if (dwarf_strict
< 0)
1897 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1899 if (debug_info_level
== DINFO_LEVEL_NONE
)
1900 write_symbols
= NO_DEBUG
;
1902 if (write_symbols
== NO_DEBUG
)
1904 #if defined(DBX_DEBUGGING_INFO)
1905 else if (write_symbols
== DBX_DEBUG
)
1906 debug_hooks
= &dbx_debug_hooks
;
1908 #if defined(XCOFF_DEBUGGING_INFO)
1909 else if (write_symbols
== XCOFF_DEBUG
)
1910 debug_hooks
= &xcoff_debug_hooks
;
1912 #ifdef SDB_DEBUGGING_INFO
1913 else if (write_symbols
== SDB_DEBUG
)
1914 debug_hooks
= &sdb_debug_hooks
;
1916 #ifdef DWARF2_DEBUGGING_INFO
1917 else if (write_symbols
== DWARF2_DEBUG
)
1918 debug_hooks
= &dwarf2_debug_hooks
;
1920 #ifdef VMS_DEBUGGING_INFO
1921 else if (write_symbols
== VMS_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
1922 debug_hooks
= &vmsdbg_debug_hooks
;
1925 error ("target system does not support the \"%s\" debug format",
1926 debug_type_names
[write_symbols
]);
1928 /* We know which debug output will be used so we can set flag_var_tracking
1929 and flag_var_tracking_uninit if the user has not specified them. */
1930 if (debug_info_level
< DINFO_LEVEL_NORMAL
1931 || debug_hooks
->var_location
== do_nothing_debug_hooks
.var_location
)
1933 if (flag_var_tracking
== 1
1934 || flag_var_tracking_uninit
== 1)
1936 if (debug_info_level
< DINFO_LEVEL_NORMAL
)
1937 warning (0, "variable tracking requested, but useless unless "
1938 "producing debug info");
1940 warning (0, "variable tracking requested, but not supported "
1941 "by this debug format");
1943 flag_var_tracking
= 0;
1944 flag_var_tracking_uninit
= 0;
1947 /* If the user specifically requested variable tracking with tagging
1948 uninitialized variables, we need to turn on variable tracking.
1949 (We already determined above that variable tracking is feasible.) */
1950 if (flag_var_tracking_uninit
)
1951 flag_var_tracking
= 1;
1953 if (flag_var_tracking
== AUTODETECT_VALUE
)
1954 flag_var_tracking
= optimize
>= 1;
1956 if (flag_var_tracking_assignments
== AUTODETECT_VALUE
)
1957 flag_var_tracking_assignments
= flag_var_tracking
1958 && !(flag_selective_scheduling
|| flag_selective_scheduling2
);
1960 if (flag_var_tracking_assignments_toggle
)
1961 flag_var_tracking_assignments
= !flag_var_tracking_assignments
;
1963 if (flag_var_tracking_assignments
&& !flag_var_tracking
)
1964 flag_var_tracking
= flag_var_tracking_assignments
= -1;
1966 if (flag_var_tracking_assignments
1967 && (flag_selective_scheduling
|| flag_selective_scheduling2
))
1968 warning (0, "var-tracking-assignments changes selective scheduling");
1970 if (flag_tree_cselim
== AUTODETECT_VALUE
)
1971 #ifdef HAVE_conditional_move
1972 flag_tree_cselim
= 1;
1974 flag_tree_cselim
= 0;
1977 /* If auxiliary info generation is desired, open the output file.
1978 This goes in the same directory as the source file--unlike
1979 all the other output files. */
1980 if (flag_gen_aux_info
)
1982 aux_info_file
= fopen (aux_info_file_name
, "w");
1983 if (aux_info_file
== 0)
1984 fatal_error ("can%'t open %s: %m", aux_info_file_name
);
1987 if (! targetm
.have_named_sections
)
1989 if (flag_function_sections
)
1991 warning (0, "-ffunction-sections not supported for this target");
1992 flag_function_sections
= 0;
1994 if (flag_data_sections
)
1996 warning (0, "-fdata-sections not supported for this target");
1997 flag_data_sections
= 0;
2001 if (flag_function_sections
&& profile_flag
)
2003 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
2004 flag_function_sections
= 0;
2007 #ifndef HAVE_prefetch
2008 if (flag_prefetch_loop_arrays
> 0)
2010 warning (0, "-fprefetch-loop-arrays not supported for this target");
2011 flag_prefetch_loop_arrays
= 0;
2014 if (flag_prefetch_loop_arrays
> 0 && !HAVE_prefetch
)
2016 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
2017 flag_prefetch_loop_arrays
= 0;
2021 /* This combination of options isn't handled for i386 targets and doesn't
2022 make much sense anyway, so don't allow it. */
2023 if (flag_prefetch_loop_arrays
> 0 && optimize_size
)
2025 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
2026 flag_prefetch_loop_arrays
= 0;
2029 /* The presence of IEEE signaling NaNs, implies all math can trap. */
2030 if (flag_signaling_nans
)
2031 flag_trapping_math
= 1;
2033 /* We cannot reassociate if we want traps or signed zeros. */
2034 if (flag_associative_math
&& (flag_trapping_math
|| flag_signed_zeros
))
2036 warning (0, "-fassociative-math disabled; other options take precedence");
2037 flag_associative_math
= 0;
2040 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
2041 if (flag_cx_limited_range
)
2042 flag_complex_method
= 0;
2044 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
2045 if (flag_cx_fortran_rules
)
2046 flag_complex_method
= 1;
2048 /* Targets must be able to place spill slots at lower addresses. If the
2049 target already uses a soft frame pointer, the transition is trivial. */
2050 if (!FRAME_GROWS_DOWNWARD
&& flag_stack_protect
)
2052 warning (0, "-fstack-protector not supported for this target");
2053 flag_stack_protect
= 0;
2055 if (!flag_stack_protect
)
2056 warn_stack_protect
= 0;
2058 /* ??? Unwind info is not correct around the CFG unless either a frame
2059 pointer is present or A_O_A is set. Fixing this requires rewriting
2060 unwind info generation to be aware of the CFG and propagating states
2062 if (flag_unwind_tables
&& !ACCUMULATE_OUTGOING_ARGS
2063 && flag_omit_frame_pointer
)
2065 warning (0, "unwind tables currently require a frame pointer "
2067 flag_omit_frame_pointer
= 0;
2070 /* Save the current optimization options. */
2071 optimization_default_node
= build_optimization_node ();
2072 optimization_current_node
= optimization_default_node
;
2075 /* This function can be called multiple times to reinitialize the compiler
2076 back end when register classes or instruction sets have changed,
2077 before each function. */
2079 backend_init_target (void)
2081 /* Initialize alignment variables. */
2084 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
2085 to initialize reg_raw_mode[]. */
2088 /* This invokes target hooks to set fixed_reg[] etc, which is
2092 /* This depends on stack_pointer_rtx. */
2093 init_fake_stack_mems ();
2095 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
2097 init_alias_target ();
2099 /* Depends on HARD_FRAME_POINTER_REGNUM. */
2102 /* The following initialization functions need to generate rtl, so
2103 provide a dummy function context for them. */
2104 init_dummy_function_start ();
2106 /* rtx_cost is mode-dependent, so cached values need to be recomputed
2107 on a mode change. */
2110 /* We may need to recompute regno_save_code[] and regno_restore_code[]
2111 after a mode change as well. */
2112 caller_save_initialized_p
= false;
2114 expand_dummy_function_end ();
2117 /* Initialize the compiler back end. This function is called only once,
2118 when starting the compiler. */
2125 init_inline_once ();
2126 init_varasm_once ();
2127 save_register_info ();
2129 /* Initialize the target-specific back end pieces. */
2131 backend_init_target ();
2134 /* Initialize excess precision settings. */
2136 init_excess_precision (void)
2138 /* Adjust excess precision handling based on the target options. If
2139 the front end cannot handle it, flag_excess_precision_cmdline
2140 will already have been set accordingly in the post_options
2142 gcc_assert (flag_excess_precision_cmdline
!= EXCESS_PRECISION_DEFAULT
);
2143 flag_excess_precision
= flag_excess_precision_cmdline
;
2144 if (flag_unsafe_math_optimizations
)
2145 flag_excess_precision
= EXCESS_PRECISION_FAST
;
2146 if (flag_excess_precision
== EXCESS_PRECISION_STANDARD
)
2148 int flt_eval_method
= TARGET_FLT_EVAL_METHOD
;
2149 switch (flt_eval_method
)
2153 /* Either the target acts unpredictably (-1) or has all the
2154 operations required not to have excess precision (0). */
2155 flag_excess_precision
= EXCESS_PRECISION_FAST
;
2159 /* In these cases, predictable excess precision makes
2163 /* Any other implementation-defined FLT_EVAL_METHOD values
2164 require the compiler to handle the associated excess
2165 precision rules in excess_precision_type. */
2171 /* Initialize things that are both lang-dependent and target-dependent.
2172 This function can be called more than once if target parameters change. */
2174 lang_dependent_init_target (void)
2176 /* This determines excess precision settings. */
2177 init_excess_precision ();
2179 /* This creates various _DECL nodes, so needs to be called after the
2180 front end is initialized. It also depends on the HAVE_xxx macros
2181 generated from the target machine description. */
2184 /* The following initialization functions need to generate rtl, so
2185 provide a dummy function context for them. */
2186 init_dummy_function_start ();
2188 /* Do the target-specific parts of expr initialization. */
2189 init_expr_target ();
2191 /* Although the actions of these functions are language-independent,
2192 they use optabs, so we cannot call them from backend_init. */
2196 expand_dummy_function_end ();
2199 /* Language-dependent initialization. Returns nonzero on success. */
2201 lang_dependent_init (const char *name
)
2203 location_t save_loc
= input_location
;
2204 if (dump_base_name
== 0)
2205 dump_base_name
= name
&& name
[0] ? name
: "gccdump";
2207 /* Other front-end initialization. */
2208 input_location
= BUILTINS_LOCATION
;
2209 if (lang_hooks
.init () == 0)
2211 input_location
= save_loc
;
2213 init_asm_output (name
);
2215 /* This creates various _DECL nodes, so needs to be called after the
2216 front end is initialized. */
2219 /* Do the target-specific parts of the initialization. */
2220 lang_dependent_init_target ();
2222 /* If dbx symbol table desired, initialize writing it and output the
2223 predefined types. */
2224 timevar_push (TV_SYMOUT
);
2226 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2227 if (dwarf2out_do_frame ())
2228 dwarf2out_frame_init ();
2231 /* Now we have the correct original filename, we can initialize
2233 (*debug_hooks
->init
) (name
);
2235 timevar_pop (TV_SYMOUT
);
2241 /* Reinitialize everything when target parameters, such as register usage,
2244 target_reinit (void)
2246 /* Reinitialize RTL backend. */
2247 backend_init_target ();
2249 /* Reinitialize lang-dependent parts. */
2250 lang_dependent_init_target ();
2254 dump_memory_report (bool final
)
2256 ggc_print_statistics ();
2257 stringpool_statistics ();
2258 dump_tree_statistics ();
2259 dump_gimple_statistics ();
2260 dump_rtx_statistics ();
2261 dump_alloc_pool_statistics ();
2262 dump_bitmap_statistics ();
2263 dump_vec_loc_statistics ();
2264 dump_ggc_loc_statistics (final
);
2265 dump_alias_stats (stderr
);
2266 dump_pta_stats (stderr
);
2269 /* Clean up: close opened files, etc. */
2274 /* Close the dump files. */
2275 if (flag_gen_aux_info
)
2277 fclose (aux_info_file
);
2279 unlink (aux_info_file_name
);
2282 /* Close non-debugging input and output files. Take special care to note
2283 whether fclose returns an error, since the pages might still be on the
2284 buffer chain while the file is open. */
2288 if (ferror (asm_out_file
) != 0)
2289 fatal_error ("error writing to %s: %m", asm_file_name
);
2290 if (fclose (asm_out_file
) != 0)
2291 fatal_error ("error closing %s: %m", asm_file_name
);
2293 unlink_if_ordinary (asm_file_name
);
2297 finish_optimization_passes ();
2302 dump_memory_report (true);
2304 /* Language-specific end of compilation actions. */
2305 lang_hooks
.finish ();
2308 /* Initialize the compiler, and compile the input file. */
2312 /* Initialize timing first. The C front ends read the main file in
2313 the post_options hook, and C++ does file timings. */
2314 if (time_report
|| !quiet_flag
|| flag_detailed_statistics
)
2316 timevar_start (TV_TOTAL
);
2320 /* Don't do any more if an error has already occurred. */
2323 /* This must be run always, because it is needed to compute the FP
2324 predefined macros, such as __LDBL_MAX__, for targets using non
2325 default FP formats. */
2326 init_adjust_machine_modes ();
2328 /* Set up the back-end if requested. */
2332 /* Language-dependent initialization. Returns true on success. */
2333 if (lang_dependent_init (main_input_filename
))
2339 /* Stop timing and print the times. */
2340 timevar_stop (TV_TOTAL
);
2341 timevar_print (stderr
);
2344 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2345 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2346 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2348 It is not safe to call this function more than once. */
2351 toplev_main (int argc
, char **argv
)
2353 expandargv (&argc
, &argv
);
2355 /* Initialization of GCC's environment, and diagnostics. */
2356 general_init (argv
[0]);
2358 /* Parse the options and do minimal processing; basically just
2359 enough to default flags appropriately. */
2360 decode_options (argc
, CONST_CAST2 (const char **, char **, argv
),
2361 &save_decoded_options
, &save_decoded_options_count
);
2365 initialize_plugins ();
2368 print_version (stderr
, "");
2371 print_plugins_help (stderr
, "");
2373 /* Exit early if we can (e.g. -help). */
2374 if (!exit_after_options
)
2377 if (warningcount
|| errorcount
)
2378 print_ignored_options ();
2379 diagnostic_finish (global_dc
);
2381 /* Invoke registered plugin callbacks if any. */
2382 invoke_plugin_callbacks (PLUGIN_FINISH
, NULL
);
2384 finalize_plugins ();
2386 return (FATAL_EXIT_CODE
);
2388 return (SUCCESS_EXIT_CODE
);