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 struct cl_decoded_option
*save_decoded_options
;
131 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 /* Debug hooks - dependent upon command line options. */
160 const struct gcc_debug_hooks
*debug_hooks
;
162 /* Other flags saying which kinds of debugging dump have been requested. */
164 int rtl_dump_and_exit
;
165 int flag_print_asm_name
;
166 enum graph_dump_types graph_dump_format
;
168 /* Name for output file of assembly code, specified with -o. */
170 const char *asm_file_name
;
172 /* True if this is the lto front end. This is used to disable
173 gimple generation and lowering passes that are normally run on the
174 output of a front end. These passes must be bypassed for lto since
175 they have already been done before the gimple was written. */
177 bool in_lto_p
= false;
179 /* Nonzero if we should write GIMPLE bytecode for link-time optimization. */
181 int flag_generate_lto
;
183 /* The FUNCTION_DECL for the function currently being compiled,
184 or 0 if between functions. */
185 tree current_function_decl
;
187 /* Set to the FUNC_BEGIN label of the current function, or NULL
189 const char * current_function_func_begin_label
;
191 /* A random sequence of characters, unless overridden by user. */
192 static const char *flag_random_seed
;
194 /* A local time stamp derived from the time of compilation. It will be
195 zero if the system cannot provide a time. It will be -1u, if the
196 user has specified a particular random seed. */
201 /* Nonzero means we should be saving declaration info into a .X file. */
203 int flag_gen_aux_info
= 0;
205 /* Specified name of aux-info file. */
207 const char *aux_info_file_name
;
209 /* Nonzero if we are compiling code for a shared library, zero for
214 /* Generate code for GNU or NeXT Objective-C runtime environment. */
216 #ifdef NEXT_OBJC_RUNTIME
217 int flag_next_runtime
= 1;
219 int flag_next_runtime
= 0;
222 /* Set to the default thread-local storage (tls) model to use. */
224 enum tls_model flag_tls_default
= TLS_MODEL_GLOBAL_DYNAMIC
;
226 /* Set the default for excess precision. */
228 enum excess_precision flag_excess_precision_cmdline
= EXCESS_PRECISION_DEFAULT
;
230 /* Nonzero means change certain warnings into errors.
231 Usually these are warnings about failure to conform to some standard. */
233 int flag_pedantic_errors
= 0;
235 /* Nonzero means make permerror produce warnings instead of errors. */
237 int flag_permissive
= 0;
239 /* -dA causes debug commentary information to be produced in
240 the generated assembly code (to make it more readable). This option
241 is generally only of use to those who actually need to read the
242 generated assembly code (perhaps while debugging the compiler itself).
243 Currently, this switch is only used by dwarfout.c; however, it is intended
244 to be a catchall for printing debug information in the assembler file. */
246 int flag_debug_asm
= 0;
248 /* -dP causes the rtl to be emitted as a comment in assembly. */
250 int flag_dump_rtl_in_asm
= 0;
252 /* When non-NULL, indicates that whenever space is allocated on the
253 stack, the resulting stack pointer must not pass this
254 address---that is, for stacks that grow downward, the stack pointer
255 must always be greater than or equal to this address; for stacks
256 that grow upward, the stack pointer must be less than this address.
257 At present, the rtx may be either a REG or a SYMBOL_REF, although
258 the support provided depends on the backend. */
261 /* Type of stack check. */
262 enum stack_check_type flag_stack_check
= NO_STACK_CHECK
;
264 /* True if the user has tagged the function with the 'section'
267 bool user_defined_section_attribute
= false;
269 struct target_flag_state default_target_flag_state
;
270 #if SWITCHABLE_TARGET
271 struct target_flag_state
*this_target_flag_state
= &default_target_flag_state
;
273 #define this_target_flag_state (&default_target_flag_state)
278 const char *const string
;
282 lang_independent_options
;
284 /* The user symbol prefix after having resolved same. */
285 const char *user_label_prefix
;
287 static const param_info lang_independent_params
[] = {
288 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
289 { OPTION, DEFAULT, false, MIN, MAX, HELP },
290 #include "params.def"
292 { NULL
, 0, false, 0, 0, NULL
}
295 /* Output files for assembler code (real compiler output)
296 and debugging dumps. */
300 FILE *stack_usage_file
= NULL
;
301 FILE *dump_file
= NULL
;
302 const char *dump_file_name
;
304 /* The current working directory of a translation. It's generally the
305 directory from which compilation was initiated, but a preprocessed
306 file may specify the original directory in which it was
309 static const char *src_pwd
;
311 /* Initialize src_pwd with the given string, and return true. If it
312 was already initialized, return false. As a special case, it may
313 be called with a NULL argument to test whether src_pwd has NOT been
317 set_src_pwd (const char *pwd
)
321 if (strcmp (src_pwd
, pwd
) == 0)
327 src_pwd
= xstrdup (pwd
);
331 /* Return the directory from which the translation unit was initiated,
332 in case set_src_pwd() was not called before to assign it a
348 /* Called when the start of a function definition is parsed,
349 this function prints on stderr the name of the function. */
351 announce_function (tree decl
)
355 if (rtl_dump_and_exit
)
356 fprintf (stderr
, "%s ",
357 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl
))));
359 fprintf (stderr
, " %s",
360 identifier_to_locale (lang_hooks
.decl_printable_name (decl
, 2)));
362 pp_needs_newline (global_dc
->printer
) = true;
363 diagnostic_set_last_function (global_dc
, (diagnostic_info
*) NULL
);
367 /* Initialize local_tick with the time of day, or -1 if
368 flag_random_seed is set. */
371 init_local_tick (void)
373 if (!flag_random_seed
)
375 /* Get some more or less random data. */
376 #ifdef HAVE_GETTIMEOFDAY
380 gettimeofday (&tv
, NULL
);
381 local_tick
= tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000;
385 time_t now
= time (NULL
);
387 if (now
!= (time_t)-1)
388 local_tick
= (unsigned) now
;
396 /* Set up a default flag_random_seed and local_tick, unless the user
397 already specified one. Must be called after init_local_tick. */
400 init_random_seed (void)
402 unsigned HOST_WIDE_INT value
;
403 static char random_seed
[HOST_BITS_PER_WIDE_INT
/ 4 + 3];
405 value
= local_tick
^ getpid ();
407 sprintf (random_seed
, HOST_WIDE_INT_PRINT_HEX
, value
);
408 flag_random_seed
= random_seed
;
411 /* Obtain the random_seed string. Unless NOINIT, initialize it if
412 it's not provided in the command line. */
415 get_random_seed (bool noinit
)
417 if (!flag_random_seed
&& !noinit
)
419 return flag_random_seed
;
422 /* Modify the random_seed string to VAL. Return its previous
426 set_random_seed (const char *val
)
428 const char *old
= flag_random_seed
;
429 flag_random_seed
= val
;
433 #if GCC_VERSION < 3004
435 /* The functions clz_hwi, ctz_hwi, ffs_hwi, floor_log2 and exact_log2
436 are defined as inline functions in toplev.h if GCC_VERSION >= 3004.
437 The definitions here are used for older versions of gcc. */
439 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
440 If X is 0, return -1. */
443 floor_log2 (unsigned HOST_WIDE_INT x
)
450 if (HOST_BITS_PER_WIDE_INT
> 64)
451 if (x
>= (unsigned HOST_WIDE_INT
) 1 << (t
+ 64))
453 if (HOST_BITS_PER_WIDE_INT
> 32)
454 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 32))
456 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 16))
458 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 8))
460 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 4))
462 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 2))
464 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 1))
470 /* Return the logarithm of X, base 2, considering X unsigned,
471 if X is a power of 2. Otherwise, returns -1. */
474 exact_log2 (unsigned HOST_WIDE_INT x
)
478 return floor_log2 (x
);
481 /* Given X, an unsigned number, return the number of least significant bits
482 that are zero. When X == 0, the result is the word size. */
485 ctz_hwi (unsigned HOST_WIDE_INT x
)
487 return x
? floor_log2 (x
& -x
) : HOST_BITS_PER_WIDE_INT
;
490 /* Similarly for most significant bits. */
493 clz_hwi (unsigned HOST_WIDE_INT x
)
495 return HOST_BITS_PER_WIDE_INT
- 1 - floor_log2(x
);
498 /* Similar to ctz_hwi, except that the least significant bit is numbered
499 starting from 1, and X == 0 yields 0. */
502 ffs_hwi (unsigned HOST_WIDE_INT x
)
504 return 1 + floor_log2 (x
& -x
);
507 #endif /* GCC_VERSION < 3004 */
509 /* Handler for fatal signals, such as SIGSEGV. These are transformed
510 into ICE messages, which is much more user friendly. In case the
511 error printer crashes, reset the signal to prevent infinite recursion. */
514 crash_signal (int signo
)
516 signal (signo
, SIG_DFL
);
518 /* If we crashed while processing an ASM statement, then be a little more
519 graceful. It's most likely the user's fault. */
520 if (this_is_asm_operands
)
522 output_operand_lossage ("unrecoverable error");
523 exit (FATAL_EXIT_CODE
);
526 internal_error ("%s", strsignal (signo
));
529 /* Arrange to dump core on error. (The regular error message is still
530 printed first, except in the case of abort().) */
533 setup_core_dumping (void)
536 signal (SIGABRT
, SIG_DFL
);
538 #if defined(HAVE_SETRLIMIT)
541 if (getrlimit (RLIMIT_CORE
, &rlim
) != 0)
542 fatal_error ("getting core file size maximum limit: %m");
543 rlim
.rlim_cur
= rlim
.rlim_max
;
544 if (setrlimit (RLIMIT_CORE
, &rlim
) != 0)
545 fatal_error ("setting core file size limit to maximum: %m");
548 diagnostic_abort_on_error (global_dc
);
552 /* Strip off a legitimate source ending from the input string NAME of
553 length LEN. Rather than having to know the names used by all of
554 our front ends, we strip off an ending of a period followed by
555 up to five characters. (Java uses ".class".) */
558 strip_off_ending (char *name
, int len
)
561 for (i
= 2; i
< 6 && len
> i
; i
++)
563 if (name
[len
- i
] == '.')
565 name
[len
- i
] = '\0';
571 /* Output a quoted string. */
574 output_quoted_string (FILE *asm_file
, const char *string
)
576 #ifdef OUTPUT_QUOTED_STRING
577 OUTPUT_QUOTED_STRING (asm_file
, string
);
581 putc ('\"', asm_file
);
582 while ((c
= *string
++) != 0)
586 if (c
== '\"' || c
== '\\')
587 putc ('\\', asm_file
);
591 fprintf (asm_file
, "\\%03o", (unsigned char) c
);
593 putc ('\"', asm_file
);
597 /* A subroutine of wrapup_global_declarations. We've come to the end of
598 the compilation unit. All deferred variables should be undeferred,
599 and all incomplete decls should be finalized. */
602 wrapup_global_declaration_1 (tree decl
)
604 /* We're not deferring this any longer. Assignment is conditional to
605 avoid needlessly dirtying PCH pages. */
606 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_WITH_VIS
)
607 && DECL_DEFER_OUTPUT (decl
) != 0)
608 DECL_DEFER_OUTPUT (decl
) = 0;
610 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_SIZE (decl
) == 0)
611 lang_hooks
.finish_incomplete_decl (decl
);
614 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
615 needs to be output. Return true if it is output. */
618 wrapup_global_declaration_2 (tree decl
)
620 if (TREE_ASM_WRITTEN (decl
) || DECL_EXTERNAL (decl
))
623 /* Don't write out static consts, unless we still need them.
625 We also keep static consts if not optimizing (for debugging),
626 unless the user specified -fno-keep-static-consts.
627 ??? They might be better written into the debug information.
628 This is possible when using DWARF.
630 A language processor that wants static constants to be always
631 written out (even if it is not used) is responsible for
632 calling rest_of_decl_compilation itself. E.g. the C front-end
633 calls rest_of_decl_compilation from finish_decl.
634 One motivation for this is that is conventional in some
635 environments to write things like:
636 static const char rcsid[] = "... version string ...";
637 intending to force the string to be in the executable.
639 A language processor that would prefer to have unneeded
640 static constants "optimized away" would just defer writing
641 them out until here. E.g. C++ does this, because static
642 constants are often defined in header files.
644 ??? A tempting alternative (for both C and C++) would be
645 to force a constant to be written if and only if it is
646 defined in a main file, as opposed to an include file. */
648 if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
650 struct varpool_node
*node
;
652 node
= varpool_get_node (decl
);
654 if (!node
&& flag_ltrans
)
656 else if (node
&& node
->finalized
)
658 else if (node
&& node
->alias
)
660 else if (!cgraph_global_info_ready
662 || TREE_USED (DECL_ASSEMBLER_NAME (decl
))))
664 else if (node
&& node
->needed
)
666 else if (DECL_COMDAT (decl
))
668 else if (TREE_READONLY (decl
) && !TREE_PUBLIC (decl
)
669 && (optimize
|| !flag_keep_static_consts
670 || DECL_ARTIFICIAL (decl
)))
675 rest_of_decl_compilation (decl
, 1, 1);
683 /* Do any final processing required for the declarations in VEC, of
684 which there are LEN. We write out inline functions and variables
685 that have been deferred until this point, but which are required.
686 Returns nonzero if anything was put out. */
689 wrapup_global_declarations (tree
*vec
, int len
)
691 bool reconsider
, output_something
= false;
694 for (i
= 0; i
< len
; i
++)
695 wrapup_global_declaration_1 (vec
[i
]);
697 /* Now emit any global variables or functions that we have been
698 putting off. We need to loop in case one of the things emitted
699 here references another one which comes earlier in the list. */
703 for (i
= 0; i
< len
; i
++)
704 reconsider
|= wrapup_global_declaration_2 (vec
[i
]);
706 output_something
= true;
710 return output_something
;
713 /* A subroutine of check_global_declarations. Issue appropriate warnings
714 for the global declaration DECL. */
717 check_global_declaration_1 (tree decl
)
719 /* Warn about any function declared static but not defined. We don't
720 warn about variables, because many programs have static variables
721 that exist only to get some text into the object file. */
722 if (TREE_CODE (decl
) == FUNCTION_DECL
723 && DECL_INITIAL (decl
) == 0
724 && DECL_EXTERNAL (decl
)
725 && ! DECL_ARTIFICIAL (decl
)
726 && ! TREE_NO_WARNING (decl
)
727 && ! TREE_PUBLIC (decl
)
728 && (warn_unused_function
729 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))))
731 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
)))
732 pedwarn (input_location
, 0, "%q+F used but never defined", decl
);
734 warning (OPT_Wunused_function
, "%q+F declared %<static%> but never defined", decl
);
735 /* This symbol is effectively an "extern" declaration now. */
736 TREE_PUBLIC (decl
) = 1;
737 assemble_external (decl
);
740 /* Warn about static fns or vars defined but not used. */
741 if (((warn_unused_function
&& TREE_CODE (decl
) == FUNCTION_DECL
)
742 /* We don't warn about "static const" variables because the
743 "rcs_id" idiom uses that construction. */
744 || (warn_unused_variable
745 && TREE_CODE (decl
) == VAR_DECL
&& ! TREE_READONLY (decl
)))
746 && ! DECL_IN_SYSTEM_HEADER (decl
)
747 && ! TREE_USED (decl
)
748 /* The TREE_USED bit for file-scope decls is kept in the identifier,
749 to handle multiple external decls in different scopes. */
750 && ! (DECL_NAME (decl
) && TREE_USED (DECL_NAME (decl
)))
751 && ! DECL_EXTERNAL (decl
)
752 && ! TREE_PUBLIC (decl
)
753 /* A volatile variable might be used in some non-obvious way. */
754 && ! TREE_THIS_VOLATILE (decl
)
755 /* Global register variables must be declared to reserve them. */
756 && ! (TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
757 /* Otherwise, ask the language. */
758 && lang_hooks
.decls
.warn_unused_global (decl
))
759 warning ((TREE_CODE (decl
) == FUNCTION_DECL
)
760 ? OPT_Wunused_function
761 : OPT_Wunused_variable
,
762 "%q+D defined but not used", decl
);
765 /* Issue appropriate warnings for the global declarations in VEC (of
766 which there are LEN). */
769 check_global_declarations (tree
*vec
, int len
)
773 for (i
= 0; i
< len
; i
++)
774 check_global_declaration_1 (vec
[i
]);
777 /* Emit debugging information for all global declarations in VEC. */
780 emit_debug_global_declarations (tree
*vec
, int len
)
784 /* Avoid confusing the debug information machinery when there are errors. */
788 timevar_push (TV_SYMOUT
);
789 for (i
= 0; i
< len
; i
++)
790 debug_hooks
->global_decl (vec
[i
]);
791 timevar_pop (TV_SYMOUT
);
794 /* Warn about a use of an identifier which was marked deprecated. */
796 warn_deprecated_use (tree node
, tree attr
)
800 if (node
== 0 || !warn_deprecated_decl
)
806 attr
= DECL_ATTRIBUTES (node
);
807 else if (TYPE_P (node
))
809 tree decl
= TYPE_STUB_DECL (node
);
811 attr
= lookup_attribute ("deprecated",
812 TYPE_ATTRIBUTES (TREE_TYPE (decl
)));
817 attr
= lookup_attribute ("deprecated", attr
);
820 msg
= TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
)));
826 expanded_location xloc
= expand_location (DECL_SOURCE_LOCATION (node
));
828 warning (OPT_Wdeprecated_declarations
,
829 "%qD is deprecated (declared at %s:%d): %s",
830 node
, xloc
.file
, xloc
.line
, msg
);
832 warning (OPT_Wdeprecated_declarations
,
833 "%qD is deprecated (declared at %s:%d)",
834 node
, xloc
.file
, xloc
.line
);
836 else if (TYPE_P (node
))
838 tree what
= NULL_TREE
;
839 tree decl
= TYPE_STUB_DECL (node
);
841 if (TYPE_NAME (node
))
843 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
844 what
= TYPE_NAME (node
);
845 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
846 && DECL_NAME (TYPE_NAME (node
)))
847 what
= DECL_NAME (TYPE_NAME (node
));
852 expanded_location xloc
853 = expand_location (DECL_SOURCE_LOCATION (decl
));
857 warning (OPT_Wdeprecated_declarations
,
858 "%qE is deprecated (declared at %s:%d): %s",
859 what
, xloc
.file
, xloc
.line
, msg
);
861 warning (OPT_Wdeprecated_declarations
,
862 "%qE is deprecated (declared at %s:%d)", what
,
863 xloc
.file
, xloc
.line
);
868 warning (OPT_Wdeprecated_declarations
,
869 "type is deprecated (declared at %s:%d): %s",
870 xloc
.file
, xloc
.line
, msg
);
872 warning (OPT_Wdeprecated_declarations
,
873 "type is deprecated (declared at %s:%d)",
874 xloc
.file
, xloc
.line
);
882 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated: %s",
885 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated", what
);
890 warning (OPT_Wdeprecated_declarations
, "type is deprecated: %s",
893 warning (OPT_Wdeprecated_declarations
, "type is deprecated");
899 /* Compile an entire translation unit. Write a file of assembly
900 output and various debugging dumps. */
905 /* Initialize yet another pass. */
907 ggc_protect_identifiers
= true;
910 init_final (main_input_filename
);
911 coverage_init (aux_base_name
);
913 invoke_plugin_callbacks (PLUGIN_START_UNIT
, NULL
);
915 timevar_push (TV_PARSE
);
917 /* Call the parser, which parses the entire file (calling
918 rest_of_compilation for each function). */
919 lang_hooks
.parse_file (set_yydebug
);
921 /* Compilation is now finished except for writing
922 what's left of the symbol table output. */
923 timevar_pop (TV_PARSE
);
925 if (flag_syntax_only
|| flag_wpa
)
928 ggc_protect_identifiers
= false;
930 /* This must also call cgraph_finalize_compilation_unit. */
931 lang_hooks
.decls
.final_write_globals ();
936 varpool_assemble_pending_decls ();
939 /* Likewise for mudflap static object registrations. */
941 mudflap_finish_file ();
943 output_shared_constant_pool ();
944 output_object_blocks ();
946 /* Write out any pending weak symbol declarations. */
949 /* This must be at the end before unwind and debug info.
950 Some target ports emit PIC setup thunks here. */
951 targetm
.asm_out
.code_end ();
953 /* Do dbx symbols. */
954 timevar_push (TV_SYMOUT
);
956 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
957 if (dwarf2out_do_frame ())
958 dwarf2out_frame_finish ();
961 (*debug_hooks
->finish
) (main_input_filename
);
962 timevar_pop (TV_SYMOUT
);
964 /* Output some stuff at end of file if nec. */
966 dw2_output_indirect_constants ();
968 /* Flush any pending external directives. */
969 process_pending_assemble_externals ();
971 /* Emit LTO marker if LTO info has been previously emitted. This is
972 used by collect2 to determine whether an object file contains IL.
973 We used to emit an undefined reference here, but this produces
974 link errors if an object file with IL is stored into a shared
975 library without invoking lto1. */
976 if (flag_generate_lto
)
978 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
979 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, NULL_TREE
,
981 (unsigned HOST_WIDE_INT
) 1, 8);
982 #elif defined ASM_OUTPUT_ALIGNED_COMMON
983 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, "__gnu_lto_v1",
984 (unsigned HOST_WIDE_INT
) 1, 8);
986 ASM_OUTPUT_COMMON (asm_out_file
, "__gnu_lto_v1",
987 (unsigned HOST_WIDE_INT
) 1,
988 (unsigned HOST_WIDE_INT
) 1);
992 /* Attach a special .ident directive to the end of the file to identify
993 the version of GCC which compiled this code. The format of the .ident
994 string is patterned after the ones produced by native SVR4 compilers. */
998 const char *pkg_version
= "(GNU) ";
1000 if (strcmp ("(GCC) ", pkgversion_string
))
1001 pkg_version
= pkgversion_string
;
1002 fprintf (asm_out_file
, "%s\"GCC: %s%s\"\n",
1003 IDENT_ASM_OP
, pkg_version
, version_string
);
1007 /* Invoke registered plugin callbacks. */
1008 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT
, NULL
);
1010 /* This must be at the end. Some target ports emit end of file directives
1011 into the assembly file here, and hence we can not output anything to the
1012 assembly file after this point. */
1013 targetm
.asm_out
.file_end ();
1016 /* Parse a -d... command line switch. */
1019 decode_d_option (const char *arg
)
1030 flag_print_asm_name
= 1;
1033 flag_dump_rtl_in_asm
= 1;
1034 flag_print_asm_name
= 1;
1037 graph_dump_format
= vcg
;
1040 rtl_dump_and_exit
= 1;
1045 case 'D': /* These are handled by the preprocessor. */
1052 setup_core_dumping();
1055 enable_rtl_dump_file ();
1059 warning (0, "unrecognized gcc debugging option: %c", c
);
1064 /* Indexed by enum debug_info_type. */
1065 const char *const debug_type_names
[] =
1067 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1070 /* Print version information to FILE.
1071 Each line begins with INDENT (for the case where FILE is the
1072 assembler output file). */
1075 print_version (FILE *file
, const char *indent
)
1077 static const char fmt1
[] =
1079 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1081 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1084 static const char fmt2
[] =
1085 N_("GMP version %s, MPFR version %s, MPC version %s\n");
1086 static const char fmt3
[] =
1087 N_("%s%swarning: %s header version %s differs from library version %s.\n");
1088 static const char fmt4
[] =
1089 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1091 #define __VERSION__ "[?]"
1094 file
== stderr
? _(fmt1
) : fmt1
,
1095 indent
, *indent
!= 0 ? " " : "",
1096 lang_hooks
.name
, pkgversion_string
, version_string
, TARGET_NAME
,
1097 indent
, __VERSION__
);
1099 /* We need to stringify the GMP macro values. Ugh, gmp_version has
1100 two string formats, "i.j.k" and "i.j" when k is zero. As of
1101 gmp-4.3.0, GMP always uses the 3 number format. */
1102 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1103 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1104 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
1105 #define GCC_GMP_VERSION \
1106 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
1107 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
1108 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1109 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1111 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1112 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1113 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1116 file
== stderr
? _(fmt2
) : fmt2
,
1117 GCC_GMP_STRINGIFY_VERSION
, MPFR_VERSION_STRING
, MPC_VERSION_STRING
);
1118 if (strcmp (GCC_GMP_STRINGIFY_VERSION
, gmp_version
))
1120 file
== stderr
? _(fmt3
) : fmt3
,
1121 indent
, *indent
!= 0 ? " " : "",
1122 "GMP", GCC_GMP_STRINGIFY_VERSION
, gmp_version
);
1123 if (strcmp (MPFR_VERSION_STRING
, mpfr_get_version ()))
1125 file
== stderr
? _(fmt3
) : fmt3
,
1126 indent
, *indent
!= 0 ? " " : "",
1127 "MPFR", MPFR_VERSION_STRING
, mpfr_get_version ());
1128 if (strcmp (MPC_VERSION_STRING
, mpc_get_version ()))
1130 file
== stderr
? _(fmt3
) : fmt3
,
1131 indent
, *indent
!= 0 ? " " : "",
1132 "MPC", MPC_VERSION_STRING
, mpc_get_version ());
1134 file
== stderr
? _(fmt4
) : fmt4
,
1135 indent
, *indent
!= 0 ? " " : "",
1136 PARAM_VALUE (GGC_MIN_EXPAND
), PARAM_VALUE (GGC_MIN_HEAPSIZE
));
1138 print_plugins_versions (file
, indent
);
1141 #ifdef ASM_COMMENT_START
1143 print_to_asm_out_file (print_switch_type type
, const char * text
)
1145 bool prepend_sep
= true;
1149 case SWITCH_TYPE_LINE_END
:
1150 putc ('\n', asm_out_file
);
1153 case SWITCH_TYPE_LINE_START
:
1154 fputs (ASM_COMMENT_START
, asm_out_file
);
1155 return strlen (ASM_COMMENT_START
);
1157 case SWITCH_TYPE_DESCRIPTIVE
:
1158 if (ASM_COMMENT_START
[0] == 0)
1159 prepend_sep
= false;
1161 case SWITCH_TYPE_PASSED
:
1162 case SWITCH_TYPE_ENABLED
:
1164 fputc (' ', asm_out_file
);
1165 fputs (text
, asm_out_file
);
1166 /* No need to return the length here as
1167 print_single_switch has already done it. */
1177 print_to_stderr (print_switch_type type
, const char * text
)
1181 case SWITCH_TYPE_LINE_END
:
1182 putc ('\n', stderr
);
1185 case SWITCH_TYPE_LINE_START
:
1188 case SWITCH_TYPE_PASSED
:
1189 case SWITCH_TYPE_ENABLED
:
1190 fputc (' ', stderr
);
1193 case SWITCH_TYPE_DESCRIPTIVE
:
1194 fputs (text
, stderr
);
1195 /* No need to return the length here as
1196 print_single_switch has already done it. */
1204 /* Print an option value and return the adjusted position in the line.
1205 ??? print_fn doesn't handle errors, eg disk full; presumably other
1206 code will catch a disk full though. */
1209 print_single_switch (print_switch_fn_type print_fn
,
1211 print_switch_type type
,
1214 /* The ultrix fprintf returns 0 on success, so compute the result
1215 we want here since we need it for the following test. The +1
1216 is for the separator character that will probably be emitted. */
1217 int len
= strlen (text
) + 1;
1220 && pos
+ len
> MAX_LINE
)
1222 print_fn (SWITCH_TYPE_LINE_END
, NULL
);
1227 pos
+= print_fn (SWITCH_TYPE_LINE_START
, NULL
);
1229 print_fn (type
, text
);
1233 /* Print active target switches using PRINT_FN.
1234 POS is the current cursor position and MAX is the size of a "line".
1235 Each line begins with INDENT and ends with TERM.
1236 Each switch is separated from the next by SEP. */
1239 print_switch_values (print_switch_fn_type print_fn
)
1244 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1245 that it can be printed below. This helps reproducibility. */
1246 if (!flag_random_seed
)
1247 init_random_seed ();
1249 /* Print the options as passed. */
1250 pos
= print_single_switch (print_fn
, pos
,
1251 SWITCH_TYPE_DESCRIPTIVE
, _("options passed: "));
1253 for (j
= 1; j
< save_decoded_options_count
; j
++)
1255 switch (save_decoded_options
[j
].opt_index
)
1268 pos
= print_single_switch (print_fn
, pos
, SWITCH_TYPE_PASSED
,
1269 save_decoded_options
[j
].orig_option_with_args_text
);
1273 print_fn (SWITCH_TYPE_LINE_END
, NULL
);
1275 /* Print the -f and -m options that have been enabled.
1276 We don't handle language specific options but printing argv
1278 pos
= print_single_switch (print_fn
, 0,
1279 SWITCH_TYPE_DESCRIPTIVE
, _("options enabled: "));
1281 for (j
= 0; j
< cl_options_count
; j
++)
1282 if ((cl_options
[j
].flags
& CL_REPORT
)
1283 && option_enabled (j
, &global_options
) > 0)
1284 pos
= print_single_switch (print_fn
, pos
,
1285 SWITCH_TYPE_ENABLED
, cl_options
[j
].opt_text
);
1287 print_fn (SWITCH_TYPE_LINE_END
, NULL
);
1290 /* Open assembly code output file. Do this even if -fsyntax-only is
1291 on, because then the driver will have provided the name of a
1292 temporary file or bit bucket for us. NAME is the file specified on
1293 the command line, possibly NULL. */
1295 init_asm_output (const char *name
)
1297 if (name
== NULL
&& asm_file_name
== 0)
1298 asm_out_file
= stdout
;
1301 if (asm_file_name
== 0)
1303 int len
= strlen (dump_base_name
);
1304 char *dumpname
= XNEWVEC (char, len
+ 6);
1306 memcpy (dumpname
, dump_base_name
, len
+ 1);
1307 strip_off_ending (dumpname
, len
);
1308 strcat (dumpname
, ".s");
1309 asm_file_name
= dumpname
;
1311 if (!strcmp (asm_file_name
, "-"))
1312 asm_out_file
= stdout
;
1314 asm_out_file
= fopen (asm_file_name
, "w+b");
1315 if (asm_out_file
== 0)
1316 fatal_error ("can%'t open %s for writing: %m", asm_file_name
);
1319 if (!flag_syntax_only
)
1321 targetm
.asm_out
.file_start ();
1323 if (flag_record_gcc_switches
)
1325 if (targetm
.asm_out
.record_gcc_switches
)
1327 /* Let the target know that we are about to start recording. */
1328 targetm
.asm_out
.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE
,
1330 /* Now record the switches. */
1331 print_switch_values (targetm
.asm_out
.record_gcc_switches
);
1332 /* Let the target know that the recording is over. */
1333 targetm
.asm_out
.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE
,
1337 inform (input_location
, "-frecord-gcc-switches is not supported by the current target");
1340 #ifdef ASM_COMMENT_START
1341 if (flag_verbose_asm
)
1343 /* Print the list of switches in effect
1344 into the assembler file as comments. */
1345 print_version (asm_out_file
, ASM_COMMENT_START
);
1346 print_switch_values (print_to_asm_out_file
);
1347 putc ('\n', asm_out_file
);
1353 /* Return true if the state of option OPTION should be stored in PCH files
1354 and checked by default_pch_valid_p. Store the option's current state
1358 option_affects_pch_p (int option
, struct cl_option_state
*state
)
1360 if ((cl_options
[option
].flags
& CL_TARGET
) == 0)
1362 if (option_flag_var (option
, &global_options
) == &target_flags
)
1363 if (targetm
.check_pch_target_flags
)
1365 return get_option_state (&global_options
, option
, state
);
1368 /* Default version of get_pch_validity.
1369 By default, every flag difference is fatal; that will be mostly right for
1370 most targets, but completely right for very few. */
1373 default_get_pch_validity (size_t *sz
)
1375 struct cl_option_state state
;
1380 if (targetm
.check_pch_target_flags
)
1381 *sz
+= sizeof (target_flags
);
1382 for (i
= 0; i
< cl_options_count
; i
++)
1383 if (option_affects_pch_p (i
, &state
))
1386 result
= r
= XNEWVEC (char, *sz
);
1390 if (targetm
.check_pch_target_flags
)
1392 memcpy (r
, &target_flags
, sizeof (target_flags
));
1393 r
+= sizeof (target_flags
);
1396 for (i
= 0; i
< cl_options_count
; i
++)
1397 if (option_affects_pch_p (i
, &state
))
1399 memcpy (r
, state
.data
, state
.size
);
1406 /* Return a message which says that a PCH file was created with a different
1407 setting of OPTION. */
1410 pch_option_mismatch (const char *option
)
1414 asprintf (&r
, _("created and used with differing settings of '%s'"), option
);
1416 return _("out of memory");
1420 /* Default version of pch_valid_p. */
1423 default_pch_valid_p (const void *data_p
, size_t len
)
1425 struct cl_option_state state
;
1426 const char *data
= (const char *)data_p
;
1429 /* -fpic and -fpie also usually make a PCH invalid. */
1430 if (data
[0] != flag_pic
)
1431 return _("created and used with different settings of -fpic");
1432 if (data
[1] != flag_pie
)
1433 return _("created and used with different settings of -fpie");
1436 /* Check target_flags. */
1437 if (targetm
.check_pch_target_flags
)
1442 memcpy (&tf
, data
, sizeof (target_flags
));
1443 data
+= sizeof (target_flags
);
1444 len
-= sizeof (target_flags
);
1445 r
= targetm
.check_pch_target_flags (tf
);
1450 for (i
= 0; i
< cl_options_count
; i
++)
1451 if (option_affects_pch_p (i
, &state
))
1453 if (memcmp (data
, state
.data
, state
.size
) != 0)
1454 return pch_option_mismatch (cl_options
[i
].opt_text
);
1462 /* Default tree printer. Handles declarations only. */
1464 default_tree_printer (pretty_printer
*pp
, text_info
*text
, const char *spec
,
1465 int precision
, bool wide
, bool set_locus
, bool hash
)
1469 /* FUTURE: %+x should set the locus. */
1470 if (precision
!= 0 || wide
|| hash
)
1476 t
= va_arg (*text
->args_ptr
, tree
);
1477 if (TREE_CODE (t
) == IDENTIFIER_NODE
)
1479 pp_identifier (pp
, IDENTIFIER_POINTER (t
));
1485 t
= va_arg (*text
->args_ptr
, tree
);
1486 if (DECL_DEBUG_EXPR_IS_FROM (t
) && DECL_DEBUG_EXPR (t
))
1487 t
= DECL_DEBUG_EXPR (t
);
1492 t
= va_arg (*text
->args_ptr
, tree
);
1496 percent_K_format (text
);
1503 if (set_locus
&& text
->locus
)
1504 *text
->locus
= DECL_SOURCE_LOCATION (t
);
1508 const char *n
= DECL_NAME (t
)
1509 ? identifier_to_locale (lang_hooks
.decl_printable_name (t
, 2))
1514 dump_generic_node (pp
, t
, 0, TDF_DIAGNOSTIC
, 0);
1519 /* A helper function; used as the reallocator function for cpp's line
1522 realloc_for_line_map (void *ptr
, size_t len
)
1524 return GGC_RESIZEVAR (void, ptr
, len
);
1527 /* A helper function: used as the allocator function for
1528 identifier_to_locale. */
1530 alloc_for_identifier_to_locale (size_t len
)
1532 return ggc_alloc_atomic (len
);
1535 /* Output stack usage information. */
1537 output_stack_usage (void)
1539 static bool warning_issued
= false;
1540 enum stack_usage_kind_type
{ STATIC
= 0, DYNAMIC
, DYNAMIC_BOUNDED
};
1541 const char *stack_usage_kind_str
[] = {
1546 HOST_WIDE_INT stack_usage
= current_function_static_stack_size
;
1547 enum stack_usage_kind_type stack_usage_kind
;
1548 expanded_location loc
;
1549 const char *raw_id
, *id
;
1551 if (stack_usage
< 0)
1553 if (!warning_issued
)
1555 warning (0, "-fstack-usage not supported for this target");
1556 warning_issued
= true;
1561 stack_usage_kind
= STATIC
;
1563 /* Add the maximum amount of space pushed onto the stack. */
1564 if (current_function_pushed_stack_size
> 0)
1566 stack_usage
+= current_function_pushed_stack_size
;
1567 stack_usage_kind
= DYNAMIC_BOUNDED
;
1570 /* Now on to the tricky part: dynamic stack allocation. */
1571 if (current_function_allocates_dynamic_stack_space
)
1573 if (current_function_has_unbounded_dynamic_stack_size
)
1574 stack_usage_kind
= DYNAMIC
;
1576 stack_usage_kind
= DYNAMIC_BOUNDED
;
1578 /* Add the size even in the unbounded case, this can't hurt. */
1579 stack_usage
+= current_function_dynamic_stack_size
;
1582 loc
= expand_location (DECL_SOURCE_LOCATION (current_function_decl
));
1584 /* Strip the scope prefix if any. */
1585 raw_id
= lang_hooks
.decl_printable_name (current_function_decl
, 2);
1586 id
= strrchr (raw_id
, '.');
1592 fprintf (stack_usage_file
,
1593 "%s:%d:%d:%s\t"HOST_WIDE_INT_PRINT_DEC
"\t%s\n",
1594 lbasename (loc
.file
),
1599 stack_usage_kind_str
[stack_usage_kind
]);
1602 /* Open an auxiliary output file. */
1604 open_auxiliary_file (const char *ext
)
1609 filename
= concat (aux_base_name
, ".", ext
, NULL
);
1610 file
= fopen (filename
, "w");
1612 fatal_error ("can't open %s for writing: %m", filename
);
1617 /* Initialization of the front end environment, before command line
1618 options are parsed. Signal handlers, internationalization etc.
1619 ARGV0 is main's argv[0]. */
1621 general_init (const char *argv0
)
1625 p
= argv0
+ strlen (argv0
);
1626 while (p
!= argv0
&& !IS_DIR_SEPARATOR (p
[-1]))
1630 xmalloc_set_program_name (progname
);
1634 /* Unlock the stdio streams. */
1635 unlock_std_streams ();
1637 gcc_init_libintl ();
1639 identifier_to_locale_alloc
= alloc_for_identifier_to_locale
;
1640 identifier_to_locale_free
= ggc_free
;
1642 /* Initialize the diagnostics reporting machinery, so option parsing
1643 can give warnings and errors. */
1644 diagnostic_initialize (global_dc
, N_OPTS
);
1645 diagnostic_starter (global_dc
) = default_tree_diagnostic_starter
;
1646 /* Set a default printer. Language specific initializations will
1647 override it later. */
1648 pp_format_decoder (global_dc
->printer
) = &default_tree_printer
;
1649 global_dc
->show_option_requested
1650 = global_options_init
.x_flag_diagnostics_show_option
;
1651 global_dc
->show_column
1652 = global_options_init
.x_flag_show_column
;
1653 global_dc
->internal_error
= plugins_internal_error_function
;
1654 global_dc
->option_enabled
= option_enabled
;
1655 global_dc
->option_state
= &global_options
;
1656 global_dc
->option_name
= option_name
;
1658 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1660 signal (SIGSEGV
, crash_signal
);
1663 signal (SIGILL
, crash_signal
);
1666 signal (SIGBUS
, crash_signal
);
1669 signal (SIGABRT
, crash_signal
);
1671 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1672 signal (SIGIOT
, crash_signal
);
1675 signal (SIGFPE
, crash_signal
);
1678 /* Other host-specific signal setup. */
1679 (*host_hooks
.extra_signals
)();
1681 /* Initialize the garbage-collector, string pools and tree type hash
1685 line_table
= ggc_alloc_line_maps ();
1686 linemap_init (line_table
);
1687 line_table
->reallocator
= realloc_for_line_map
;
1690 /* Initialize register usage now so switches may override. */
1693 /* Register the language-independent parameters. */
1694 add_params (lang_independent_params
, LAST_PARAM
);
1696 /* This must be done after add_params but before argument processing. */
1697 init_ggc_heuristics();
1698 init_optimization_passes ();
1699 statistics_early_init ();
1702 /* Return true if the current target supports -fsection-anchors. */
1705 target_supports_section_anchors_p (void)
1707 if (targetm
.min_anchor_offset
== 0 && targetm
.max_anchor_offset
== 0)
1710 if (targetm
.asm_out
.output_anchor
== NULL
)
1716 /* Default the align_* variables to 1 if they're still unset, and
1717 set up the align_*_log variables. */
1719 init_alignments (void)
1721 if (align_loops
<= 0)
1723 if (align_loops_max_skip
> align_loops
)
1724 align_loops_max_skip
= align_loops
- 1;
1725 align_loops_log
= floor_log2 (align_loops
* 2 - 1);
1726 if (align_jumps
<= 0)
1728 if (align_jumps_max_skip
> align_jumps
)
1729 align_jumps_max_skip
= align_jumps
- 1;
1730 align_jumps_log
= floor_log2 (align_jumps
* 2 - 1);
1731 if (align_labels
<= 0)
1733 align_labels_log
= floor_log2 (align_labels
* 2 - 1);
1734 if (align_labels_max_skip
> align_labels
)
1735 align_labels_max_skip
= align_labels
- 1;
1736 if (align_functions
<= 0)
1737 align_functions
= 1;
1738 align_functions_log
= floor_log2 (align_functions
* 2 - 1);
1741 /* Process the options that have been parsed. */
1743 process_options (void)
1745 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1746 This can happen with incorrect pre-processed input. */
1747 debug_hooks
= &do_nothing_debug_hooks
;
1749 /* This replaces set_Wunused. */
1750 if (warn_unused_function
== -1)
1751 warn_unused_function
= warn_unused
;
1752 if (warn_unused_label
== -1)
1753 warn_unused_label
= warn_unused
;
1754 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */
1755 if (warn_unused_parameter
== -1)
1756 warn_unused_parameter
= (warn_unused
&& extra_warnings
);
1757 if (warn_unused_variable
== -1)
1758 warn_unused_variable
= warn_unused
;
1759 /* Wunused-but-set-parameter is enabled if both -Wunused -Wextra are
1761 if (warn_unused_but_set_parameter
== -1)
1762 warn_unused_but_set_parameter
= (warn_unused
&& extra_warnings
);
1763 if (warn_unused_but_set_variable
== -1)
1764 warn_unused_but_set_variable
= warn_unused
;
1765 if (warn_unused_value
== -1)
1766 warn_unused_value
= warn_unused
;
1768 /* This replaces set_Wextra. */
1769 if (warn_uninitialized
== -1)
1770 warn_uninitialized
= extra_warnings
;
1772 /* Allow the front end to perform consistency checks and do further
1773 initialization based on the command line options. This hook also
1774 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1775 so we can correctly initialize debug output. */
1776 no_backend
= lang_hooks
.post_options (&main_input_filename
);
1778 /* Some machines may reject certain combinations of options. */
1779 targetm
.target_option
.override ();
1781 /* Avoid any informative notes in the second run of -fcompare-debug. */
1782 if (flag_compare_debug
)
1783 diagnostic_inhibit_notes (global_dc
);
1785 if (flag_section_anchors
&& !target_supports_section_anchors_p ())
1787 warning (OPT_fsection_anchors
,
1788 "this target does not support %qs", "-fsection-anchors");
1789 flag_section_anchors
= 0;
1792 if (flag_short_enums
== 2)
1793 flag_short_enums
= targetm
.default_short_enums ();
1795 /* Set aux_base_name if not already set. */
1798 else if (main_input_filename
)
1800 char *name
= xstrdup (lbasename (main_input_filename
));
1802 strip_off_ending (name
, strlen (name
));
1803 aux_base_name
= name
;
1806 aux_base_name
= "gccaux";
1811 || flag_loop_interchange
1812 || flag_loop_strip_mine
1813 || flag_graphite_identity
1814 || flag_loop_parallelize_all
)
1815 sorry ("Graphite loop optimizations cannot be used");
1818 /* Unrolling all loops implies that standard loop unrolling must also
1820 if (flag_unroll_all_loops
)
1821 flag_unroll_loops
= 1;
1823 /* The loop unrolling code assumes that cse will be run after loop.
1824 web and rename-registers also help when run after loop unrolling. */
1825 if (flag_rerun_cse_after_loop
== AUTODETECT_VALUE
)
1826 flag_rerun_cse_after_loop
= flag_unroll_loops
|| flag_peel_loops
;
1828 if (flag_web
== AUTODETECT_VALUE
)
1829 flag_web
= flag_unroll_loops
|| flag_peel_loops
;
1831 if (flag_rename_registers
== AUTODETECT_VALUE
)
1832 flag_rename_registers
= flag_unroll_loops
|| flag_peel_loops
;
1834 if (flag_non_call_exceptions
)
1835 flag_asynchronous_unwind_tables
= 1;
1836 if (flag_asynchronous_unwind_tables
)
1837 flag_unwind_tables
= 1;
1839 if (flag_value_profile_transformations
)
1840 flag_profile_values
= 1;
1842 /* Warn about options that are not supported on this machine. */
1843 #ifndef INSN_SCHEDULING
1844 if (flag_schedule_insns
|| flag_schedule_insns_after_reload
)
1845 warning (0, "instruction scheduling not supported on this target machine");
1848 if (flag_delayed_branch
)
1849 warning (0, "this target machine does not have delayed branches");
1852 user_label_prefix
= USER_LABEL_PREFIX
;
1853 if (flag_leading_underscore
!= -1)
1855 /* If the default prefix is more complicated than "" or "_",
1856 issue a warning and ignore this option. */
1857 if (user_label_prefix
[0] == 0 ||
1858 (user_label_prefix
[0] == '_' && user_label_prefix
[1] == 0))
1860 user_label_prefix
= flag_leading_underscore
? "_" : "";
1863 warning (0, "-f%sleading-underscore not supported on this target machine",
1864 flag_leading_underscore
? "" : "no-");
1867 /* If we are in verbose mode, write out the version and maybe all the
1868 option flags in use. */
1871 print_version (stderr
, "");
1873 print_switch_values (print_to_stderr
);
1876 if (flag_syntax_only
)
1878 write_symbols
= NO_DEBUG
;
1884 if (debug_info_level
== DINFO_LEVEL_NONE
)
1886 debug_info_level
= DINFO_LEVEL_NORMAL
;
1888 if (write_symbols
== NO_DEBUG
)
1889 write_symbols
= PREFERRED_DEBUGGING_TYPE
;
1892 debug_info_level
= DINFO_LEVEL_NONE
;
1895 if (flag_dump_final_insns
&& !flag_syntax_only
&& !no_backend
)
1897 FILE *final_output
= fopen (flag_dump_final_insns
, "w");
1900 error ("could not open final insn dump file %qs: %m",
1901 flag_dump_final_insns
);
1902 flag_dump_final_insns
= NULL
;
1904 else if (fclose (final_output
))
1906 error ("could not close zeroed insn dump file %qs: %m",
1907 flag_dump_final_insns
);
1908 flag_dump_final_insns
= NULL
;
1912 /* Unless over-ridden for the target, assume that all DWARF levels
1913 may be emitted, if DWARF2_DEBUG is selected. */
1914 if (dwarf_strict
< 0)
1917 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1919 if (debug_info_level
== DINFO_LEVEL_NONE
)
1920 write_symbols
= NO_DEBUG
;
1922 if (write_symbols
== NO_DEBUG
)
1924 #if defined(DBX_DEBUGGING_INFO)
1925 else if (write_symbols
== DBX_DEBUG
)
1926 debug_hooks
= &dbx_debug_hooks
;
1928 #if defined(XCOFF_DEBUGGING_INFO)
1929 else if (write_symbols
== XCOFF_DEBUG
)
1930 debug_hooks
= &xcoff_debug_hooks
;
1932 #ifdef SDB_DEBUGGING_INFO
1933 else if (write_symbols
== SDB_DEBUG
)
1934 debug_hooks
= &sdb_debug_hooks
;
1936 #ifdef DWARF2_DEBUGGING_INFO
1937 else if (write_symbols
== DWARF2_DEBUG
)
1938 debug_hooks
= &dwarf2_debug_hooks
;
1940 #ifdef VMS_DEBUGGING_INFO
1941 else if (write_symbols
== VMS_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
1942 debug_hooks
= &vmsdbg_debug_hooks
;
1945 error ("target system does not support the \"%s\" debug format",
1946 debug_type_names
[write_symbols
]);
1948 /* We know which debug output will be used so we can set flag_var_tracking
1949 and flag_var_tracking_uninit if the user has not specified them. */
1950 if (debug_info_level
< DINFO_LEVEL_NORMAL
1951 || debug_hooks
->var_location
== do_nothing_debug_hooks
.var_location
)
1953 if (flag_var_tracking
== 1
1954 || flag_var_tracking_uninit
== 1)
1956 if (debug_info_level
< DINFO_LEVEL_NORMAL
)
1957 warning (0, "variable tracking requested, but useless unless "
1958 "producing debug info");
1960 warning (0, "variable tracking requested, but not supported "
1961 "by this debug format");
1963 flag_var_tracking
= 0;
1964 flag_var_tracking_uninit
= 0;
1967 /* If the user specifically requested variable tracking with tagging
1968 uninitialized variables, we need to turn on variable tracking.
1969 (We already determined above that variable tracking is feasible.) */
1970 if (flag_var_tracking_uninit
)
1971 flag_var_tracking
= 1;
1973 if (flag_var_tracking
== AUTODETECT_VALUE
)
1974 flag_var_tracking
= optimize
>= 1;
1976 if (flag_var_tracking_assignments
== AUTODETECT_VALUE
)
1977 flag_var_tracking_assignments
= flag_var_tracking
1978 && !(flag_selective_scheduling
|| flag_selective_scheduling2
);
1980 if (flag_var_tracking_assignments_toggle
)
1981 flag_var_tracking_assignments
= !flag_var_tracking_assignments
;
1983 if (flag_var_tracking_assignments
&& !flag_var_tracking
)
1984 flag_var_tracking
= flag_var_tracking_assignments
= -1;
1986 if (flag_var_tracking_assignments
1987 && (flag_selective_scheduling
|| flag_selective_scheduling2
))
1988 warning (0, "var-tracking-assignments changes selective scheduling");
1990 if (flag_tree_cselim
== AUTODETECT_VALUE
)
1991 #ifdef HAVE_conditional_move
1992 flag_tree_cselim
= 1;
1994 flag_tree_cselim
= 0;
1997 /* If auxiliary info generation is desired, open the output file.
1998 This goes in the same directory as the source file--unlike
1999 all the other output files. */
2000 if (flag_gen_aux_info
)
2002 aux_info_file
= fopen (aux_info_file_name
, "w");
2003 if (aux_info_file
== 0)
2004 fatal_error ("can%'t open %s: %m", aux_info_file_name
);
2007 if (! targetm
.have_named_sections
)
2009 if (flag_function_sections
)
2011 warning (0, "-ffunction-sections not supported for this target");
2012 flag_function_sections
= 0;
2014 if (flag_data_sections
)
2016 warning (0, "-fdata-sections not supported for this target");
2017 flag_data_sections
= 0;
2021 if (flag_function_sections
&& profile_flag
)
2023 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
2024 flag_function_sections
= 0;
2027 #ifndef HAVE_prefetch
2028 if (flag_prefetch_loop_arrays
> 0)
2030 warning (0, "-fprefetch-loop-arrays not supported for this target");
2031 flag_prefetch_loop_arrays
= 0;
2034 if (flag_prefetch_loop_arrays
> 0 && !HAVE_prefetch
)
2036 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
2037 flag_prefetch_loop_arrays
= 0;
2041 /* This combination of options isn't handled for i386 targets and doesn't
2042 make much sense anyway, so don't allow it. */
2043 if (flag_prefetch_loop_arrays
> 0 && optimize_size
)
2045 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
2046 flag_prefetch_loop_arrays
= 0;
2049 /* The presence of IEEE signaling NaNs, implies all math can trap. */
2050 if (flag_signaling_nans
)
2051 flag_trapping_math
= 1;
2053 /* We cannot reassociate if we want traps or signed zeros. */
2054 if (flag_associative_math
&& (flag_trapping_math
|| flag_signed_zeros
))
2056 warning (0, "-fassociative-math disabled; other options take precedence");
2057 flag_associative_math
= 0;
2060 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
2061 if (flag_cx_limited_range
)
2062 flag_complex_method
= 0;
2064 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
2065 if (flag_cx_fortran_rules
)
2066 flag_complex_method
= 1;
2068 /* Targets must be able to place spill slots at lower addresses. If the
2069 target already uses a soft frame pointer, the transition is trivial. */
2070 if (!FRAME_GROWS_DOWNWARD
&& flag_stack_protect
)
2072 warning (0, "-fstack-protector not supported for this target");
2073 flag_stack_protect
= 0;
2075 if (!flag_stack_protect
)
2076 warn_stack_protect
= 0;
2078 /* ??? Unwind info is not correct around the CFG unless either a frame
2079 pointer is present or A_O_A is set. Fixing this requires rewriting
2080 unwind info generation to be aware of the CFG and propagating states
2082 if (flag_unwind_tables
&& !ACCUMULATE_OUTGOING_ARGS
2083 && flag_omit_frame_pointer
)
2085 warning (0, "unwind tables currently require a frame pointer "
2087 flag_omit_frame_pointer
= 0;
2090 /* Save the current optimization options. */
2091 optimization_default_node
= build_optimization_node ();
2092 optimization_current_node
= optimization_default_node
;
2095 /* This function can be called multiple times to reinitialize the compiler
2096 back end when register classes or instruction sets have changed,
2097 before each function. */
2099 backend_init_target (void)
2101 /* Initialize alignment variables. */
2104 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
2105 to initialize reg_raw_mode[]. */
2108 /* This invokes target hooks to set fixed_reg[] etc, which is
2112 /* This depends on stack_pointer_rtx. */
2113 init_fake_stack_mems ();
2115 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
2117 init_alias_target ();
2119 /* Depends on HARD_FRAME_POINTER_REGNUM. */
2122 /* The following initialization functions need to generate rtl, so
2123 provide a dummy function context for them. */
2124 init_dummy_function_start ();
2126 /* rtx_cost is mode-dependent, so cached values need to be recomputed
2127 on a mode change. */
2130 /* We may need to recompute regno_save_code[] and regno_restore_code[]
2131 after a mode change as well. */
2132 caller_save_initialized_p
= false;
2134 expand_dummy_function_end ();
2137 /* Initialize the compiler back end. This function is called only once,
2138 when starting the compiler. */
2145 init_inline_once ();
2146 init_varasm_once ();
2147 save_register_info ();
2149 /* Initialize the target-specific back end pieces. */
2151 backend_init_target ();
2154 /* Initialize excess precision settings. */
2156 init_excess_precision (void)
2158 /* Adjust excess precision handling based on the target options. If
2159 the front end cannot handle it, flag_excess_precision_cmdline
2160 will already have been set accordingly in the post_options
2162 gcc_assert (flag_excess_precision_cmdline
!= EXCESS_PRECISION_DEFAULT
);
2163 flag_excess_precision
= flag_excess_precision_cmdline
;
2164 if (flag_unsafe_math_optimizations
)
2165 flag_excess_precision
= EXCESS_PRECISION_FAST
;
2166 if (flag_excess_precision
== EXCESS_PRECISION_STANDARD
)
2168 int flt_eval_method
= TARGET_FLT_EVAL_METHOD
;
2169 switch (flt_eval_method
)
2173 /* Either the target acts unpredictably (-1) or has all the
2174 operations required not to have excess precision (0). */
2175 flag_excess_precision
= EXCESS_PRECISION_FAST
;
2179 /* In these cases, predictable excess precision makes
2183 /* Any other implementation-defined FLT_EVAL_METHOD values
2184 require the compiler to handle the associated excess
2185 precision rules in excess_precision_type. */
2191 /* Initialize things that are both lang-dependent and target-dependent.
2192 This function can be called more than once if target parameters change. */
2194 lang_dependent_init_target (void)
2196 /* This determines excess precision settings. */
2197 init_excess_precision ();
2199 /* This creates various _DECL nodes, so needs to be called after the
2200 front end is initialized. It also depends on the HAVE_xxx macros
2201 generated from the target machine description. */
2204 /* The following initialization functions need to generate rtl, so
2205 provide a dummy function context for them. */
2206 init_dummy_function_start ();
2208 /* Do the target-specific parts of expr initialization. */
2209 init_expr_target ();
2211 /* Although the actions of these functions are language-independent,
2212 they use optabs, so we cannot call them from backend_init. */
2216 expand_dummy_function_end ();
2219 /* Language-dependent initialization. Returns nonzero on success. */
2221 lang_dependent_init (const char *name
)
2223 location_t save_loc
= input_location
;
2224 if (dump_base_name
== 0)
2225 dump_base_name
= name
&& name
[0] ? name
: "gccdump";
2227 /* Other front-end initialization. */
2228 input_location
= BUILTINS_LOCATION
;
2229 if (lang_hooks
.init () == 0)
2231 input_location
= save_loc
;
2233 init_asm_output (name
);
2235 /* If stack usage information is desired, open the output file. */
2236 if (flag_stack_usage
)
2237 stack_usage_file
= open_auxiliary_file ("su");
2239 /* This creates various _DECL nodes, so needs to be called after the
2240 front end is initialized. */
2243 /* Do the target-specific parts of the initialization. */
2244 lang_dependent_init_target ();
2246 /* If dbx symbol table desired, initialize writing it and output the
2247 predefined types. */
2248 timevar_push (TV_SYMOUT
);
2250 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2251 if (dwarf2out_do_frame ())
2252 dwarf2out_frame_init ();
2255 /* Now we have the correct original filename, we can initialize
2257 (*debug_hooks
->init
) (name
);
2259 timevar_pop (TV_SYMOUT
);
2265 /* Reinitialize everything when target parameters, such as register usage,
2268 target_reinit (void)
2270 /* Reinitialize RTL backend. */
2271 backend_init_target ();
2273 /* Reinitialize lang-dependent parts. */
2274 lang_dependent_init_target ();
2278 dump_memory_report (bool final
)
2280 ggc_print_statistics ();
2281 stringpool_statistics ();
2282 dump_tree_statistics ();
2283 dump_gimple_statistics ();
2284 dump_rtx_statistics ();
2285 dump_alloc_pool_statistics ();
2286 dump_bitmap_statistics ();
2287 dump_vec_loc_statistics ();
2288 dump_ggc_loc_statistics (final
);
2289 dump_alias_stats (stderr
);
2290 dump_pta_stats (stderr
);
2293 /* Clean up: close opened files, etc. */
2298 /* Close the dump files. */
2299 if (flag_gen_aux_info
)
2301 fclose (aux_info_file
);
2303 unlink (aux_info_file_name
);
2306 /* Close non-debugging input and output files. Take special care to note
2307 whether fclose returns an error, since the pages might still be on the
2308 buffer chain while the file is open. */
2312 if (ferror (asm_out_file
) != 0)
2313 fatal_error ("error writing to %s: %m", asm_file_name
);
2314 if (fclose (asm_out_file
) != 0)
2315 fatal_error ("error closing %s: %m", asm_file_name
);
2317 unlink_if_ordinary (asm_file_name
);
2320 if (stack_usage_file
)
2321 fclose (stack_usage_file
);
2324 finish_optimization_passes ();
2329 dump_memory_report (true);
2331 /* Language-specific end of compilation actions. */
2332 lang_hooks
.finish ();
2335 /* Initialize the compiler, and compile the input file. */
2339 /* Initialize timing first. The C front ends read the main file in
2340 the post_options hook, and C++ does file timings. */
2341 if (time_report
|| !quiet_flag
|| flag_detailed_statistics
)
2343 timevar_start (TV_TOTAL
);
2347 /* Don't do any more if an error has already occurred. */
2350 /* This must be run always, because it is needed to compute the FP
2351 predefined macros, such as __LDBL_MAX__, for targets using non
2352 default FP formats. */
2353 init_adjust_machine_modes ();
2355 /* Set up the back-end if requested. */
2359 /* Language-dependent initialization. Returns true on success. */
2360 if (lang_dependent_init (main_input_filename
))
2366 /* Stop timing and print the times. */
2367 timevar_stop (TV_TOTAL
);
2368 timevar_print (stderr
);
2371 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2372 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2373 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2375 It is not safe to call this function more than once. */
2378 toplev_main (int argc
, char **argv
)
2380 expandargv (&argc
, &argv
);
2382 /* Initialization of GCC's environment, and diagnostics. */
2383 general_init (argv
[0]);
2385 /* One-off initialization of options that does not need to be
2386 repeated when options are added for particular functions. */
2387 init_options_once ();
2389 /* Initialize global options structures; this must be repeated for
2390 each structure used for parsing options. */
2391 init_options_struct (&global_options
, &global_options_set
);
2392 lang_hooks
.init_options_struct (&global_options
);
2394 /* Convert the options to an array. */
2395 decode_cmdline_options_to_array_default_mask (argc
,
2396 CONST_CAST2 (const char **,
2398 &save_decoded_options
,
2399 &save_decoded_options_count
);
2401 /* Perform language-specific options initialization. */
2402 lang_hooks
.init_options (save_decoded_options_count
, save_decoded_options
);
2404 /* Parse the options and do minimal processing; basically just
2405 enough to default flags appropriately. */
2406 decode_options (&global_options
, &global_options_set
,
2407 save_decoded_options
, save_decoded_options_count
);
2411 initialize_plugins ();
2414 print_version (stderr
, "");
2417 print_plugins_help (stderr
, "");
2419 /* Exit early if we can (e.g. -help). */
2420 if (!exit_after_options
)
2423 if (warningcount
|| errorcount
)
2424 print_ignored_options ();
2425 diagnostic_finish (global_dc
);
2427 /* Invoke registered plugin callbacks if any. */
2428 invoke_plugin_callbacks (PLUGIN_FINISH
, NULL
);
2430 finalize_plugins ();
2432 return (FATAL_EXIT_CODE
);
2434 return (SUCCESS_EXIT_CODE
);