1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
31 #include "coretypes.h"
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
50 #include "insn-attr.h"
51 #include "insn-config.h"
52 #include "insn-flags.h"
53 #include "hard-reg-set.h"
60 #include "basic-block.h"
66 #include "diagnostic.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
77 #include "hosthooks.h"
81 #include "value-prof.h"
82 #include "alloc-pool.h"
83 #include "tree-mudflap.h"
84 #include "tree-pass.h"
86 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
87 #include "dwarf2out.h"
90 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
94 #ifdef SDB_DEBUGGING_INFO
98 #ifdef XCOFF_DEBUGGING_INFO
99 #include "xcoffout.h" /* Needed for external data
100 declarations for e.g. AIX 4.x. */
103 static void general_init (const char *);
104 static void do_compile (void);
105 static void process_options (void);
106 static void backend_init (void);
107 static int lang_dependent_init (const char *);
108 static void init_asm_output (const char *);
109 static void finalize (void);
111 static void crash_signal (int) ATTRIBUTE_NORETURN
;
112 static void setup_core_dumping (void);
113 static void compile_file (void);
115 /* Nonzero to dump debug info whilst parsing (-dy option). */
116 static int set_yydebug
;
118 /* True if we don't need a backend (e.g. preprocessing only). */
119 static bool no_backend
;
121 /* Length of line when printing switch values. */
124 /* Name of program invoked, sans directories. */
126 const char *progname
;
128 /* Copy of argument vector to toplev_main. */
129 static const char **save_argv
;
131 /* Name of top-level original source file (what was input to cpp).
132 This comes from the #-command at the beginning of the actual input.
133 If there isn't any there, then this is the cc1 input file name. */
135 const char *main_input_filename
;
137 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
138 to optimize and default_debug_hooks in process_options (). */
139 #define AUTODETECT_VALUE 2
141 /* Current position in real source file. */
143 location_t input_location
;
145 struct line_maps
*line_table
;
147 /* Name to use as base of names for dump output files. */
149 const char *dump_base_name
;
151 /* Name to use as a base for auxiliary output files. */
153 const char *aux_base_name
;
155 /* A mask of target_flags that includes bit X if X was set or cleared
156 on the command line. */
158 int target_flags_explicit
;
160 /* Debug hooks - dependent upon command line options. */
162 const struct gcc_debug_hooks
*debug_hooks
;
164 /* Debug hooks - target default. */
166 static const struct gcc_debug_hooks
*default_debug_hooks
;
168 /* Other flags saying which kinds of debugging dump have been requested. */
170 int rtl_dump_and_exit
;
171 int flag_print_asm_name
;
172 enum graph_dump_types graph_dump_format
;
174 /* Name for output file of assembly code, specified with -o. */
176 const char *asm_file_name
;
178 /* Nonzero means do optimizations. -O.
179 Particular numeric values stand for particular amounts of optimization;
180 thus, -O2 stores 2 here. However, the optimizations beyond the basic
181 ones are not controlled directly by this variable. Instead, they are
182 controlled by individual `flag_...' variables that are defaulted
183 based on this variable. */
187 /* Nonzero means optimize for size. -Os.
188 The only valid values are zero and nonzero. When optimize_size is
189 nonzero, optimize defaults to 2, but certain individual code
190 bloating optimizations are disabled. */
192 int optimize_size
= 0;
194 /* The FUNCTION_DECL for the function currently being compiled,
195 or 0 if between functions. */
196 tree current_function_decl
;
198 /* Set to the FUNC_BEGIN label of the current function, or NULL
200 const char * current_function_func_begin_label
;
202 /* Temporarily suppress certain warnings.
203 This is set while reading code from a system header file. */
205 int in_system_header
= 0;
207 /* Nonzero means to collect statistics which might be expensive
208 and to print them when we are done. */
209 int flag_detailed_statistics
= 0;
211 /* A random sequence of characters, unless overridden by user. */
212 static const char *flag_random_seed
;
214 /* A local time stamp derived from the time of compilation. It will be
215 zero if the system cannot provide a time. It will be -1u, if the
216 user has specified a particular random seed. */
221 /* Nonzero means `char' should be signed. */
223 int flag_signed_char
;
225 /* Nonzero means give an enum type only as many bytes as it needs. A value
226 of 2 means it has not yet been initialized. */
228 int flag_short_enums
;
230 /* Nonzero if structures and unions should be returned in memory.
232 This should only be defined if compatibility with another compiler or
233 with an ABI is needed, because it results in slower code. */
235 #ifndef DEFAULT_PCC_STRUCT_RETURN
236 #define DEFAULT_PCC_STRUCT_RETURN 1
239 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
241 int flag_pcc_struct_return
= DEFAULT_PCC_STRUCT_RETURN
;
243 /* 0 means straightforward implementation of complex divide acceptable.
244 1 means wide ranges of inputs must work for complex divide.
245 2 means C99-like requirements for complex multiply and divide. */
247 int flag_complex_method
= 1;
249 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
250 not just because the tree inliner turned us off. */
252 int flag_really_no_inline
= 2;
254 /* Nonzero means we should be saving declaration info into a .X file. */
256 int flag_gen_aux_info
= 0;
258 /* Specified name of aux-info file. */
260 const char *aux_info_file_name
;
262 /* Nonzero if we are compiling code for a shared library, zero for
267 /* Generate code for GNU or NeXT Objective-C runtime environment. */
269 #ifdef NEXT_OBJC_RUNTIME
270 int flag_next_runtime
= 1;
272 int flag_next_runtime
= 0;
275 /* Set to the default thread-local storage (tls) model to use. */
277 enum tls_model flag_tls_default
= TLS_MODEL_GLOBAL_DYNAMIC
;
279 /* Nonzero means change certain warnings into errors.
280 Usually these are warnings about failure to conform to some standard. */
282 int flag_pedantic_errors
= 0;
284 /* Nonzero means make permerror produce warnings instead of errors. */
286 int flag_permissive
= 0;
288 /* -dA causes debug commentary information to be produced in
289 the generated assembly code (to make it more readable). This option
290 is generally only of use to those who actually need to read the
291 generated assembly code (perhaps while debugging the compiler itself).
292 Currently, this switch is only used by dwarfout.c; however, it is intended
293 to be a catchall for printing debug information in the assembler file. */
295 int flag_debug_asm
= 0;
297 /* -dP causes the rtl to be emitted as a comment in assembly. */
299 int flag_dump_rtl_in_asm
= 0;
301 /* When non-NULL, indicates that whenever space is allocated on the
302 stack, the resulting stack pointer must not pass this
303 address---that is, for stacks that grow downward, the stack pointer
304 must always be greater than or equal to this address; for stacks
305 that grow upward, the stack pointer must be less than this address.
306 At present, the rtx may be either a REG or a SYMBOL_REF, although
307 the support provided depends on the backend. */
310 /* Nonzero if we should track variables. When
311 flag_var_tracking == AUTODETECT_VALUE it will be set according
312 to optimize, debug_info_level and debug_hooks in process_options (). */
313 int flag_var_tracking
= AUTODETECT_VALUE
;
315 /* True if the user has tagged the function with the 'section'
318 bool user_defined_section_attribute
= false;
320 /* Values of the -falign-* flags: how much to align labels in code.
321 0 means `use default', 1 means `don't align'.
322 For each variable, there is an _log variant which is the power
323 of two not less than the variable, for .align output. */
326 int align_loops_max_skip
;
328 int align_jumps_max_skip
;
329 int align_labels_log
;
330 int align_labels_max_skip
;
331 int align_functions_log
;
335 const char *const string
;
339 lang_independent_options
;
341 /* Nonzero if subexpressions must be evaluated from left-to-right. */
342 int flag_evaluation_order
= 0;
344 /* The user symbol prefix after having resolved same. */
345 const char *user_label_prefix
;
347 static const param_info lang_independent_params
[] = {
348 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
349 { OPTION, DEFAULT, false, MIN, MAX, HELP },
350 #include "params.def"
352 { NULL
, 0, false, 0, 0, NULL
}
355 /* Output files for assembler code (real compiler output)
356 and debugging dumps. */
360 FILE *dump_file
= NULL
;
361 const char *dump_file_name
;
363 /* The current working directory of a translation. It's generally the
364 directory from which compilation was initiated, but a preprocessed
365 file may specify the original directory in which it was
368 static const char *src_pwd
;
370 /* Initialize src_pwd with the given string, and return true. If it
371 was already initialized, return false. As a special case, it may
372 be called with a NULL argument to test whether src_pwd has NOT been
376 set_src_pwd (const char *pwd
)
380 if (strcmp (src_pwd
, pwd
) == 0)
386 src_pwd
= xstrdup (pwd
);
390 /* Return the directory from which the translation unit was initiated,
391 in case set_src_pwd() was not called before to assign it a
407 /* Called when the start of a function definition is parsed,
408 this function prints on stderr the name of the function. */
410 announce_function (tree decl
)
414 if (rtl_dump_and_exit
)
415 fprintf (stderr
, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl
)));
417 fprintf (stderr
, " %s", lang_hooks
.decl_printable_name (decl
, 2));
419 pp_needs_newline (global_dc
->printer
) = true;
420 diagnostic_set_last_function (global_dc
, (diagnostic_info
*) NULL
);
424 /* Initialize local_tick with the time of day, or -1 if
425 flag_random_seed is set. */
428 init_local_tick (void)
430 if (!flag_random_seed
)
432 /* Get some more or less random data. */
433 #ifdef HAVE_GETTIMEOFDAY
437 gettimeofday (&tv
, NULL
);
438 local_tick
= tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000;
442 time_t now
= time (NULL
);
444 if (now
!= (time_t)-1)
445 local_tick
= (unsigned) now
;
453 /* Set up a default flag_random_seed and local_tick, unless the user
454 already specified one. Must be called after init_local_tick. */
457 init_random_seed (void)
459 unsigned HOST_WIDE_INT value
;
460 static char random_seed
[HOST_BITS_PER_WIDE_INT
/ 4 + 3];
462 value
= local_tick
^ getpid ();
464 sprintf (random_seed
, HOST_WIDE_INT_PRINT_HEX
, value
);
465 flag_random_seed
= random_seed
;
468 /* Obtain the random_seed string. Unless NOINIT, initialize it if
469 it's not provided in the command line. */
472 get_random_seed (bool noinit
)
474 if (!flag_random_seed
&& !noinit
)
476 return flag_random_seed
;
479 /* Modify the random_seed string to VAL. Return its previous
483 set_random_seed (const char *val
)
485 const char *old
= flag_random_seed
;
486 flag_random_seed
= val
;
490 /* Decode the string P as an integral parameter.
491 If the string is indeed an integer return its numeric value else
492 issue an Invalid Option error for the option PNAME and return DEFVAL.
493 If PNAME is zero just return DEFVAL, do not call error. */
496 read_integral_parameter (const char *p
, const char *pname
, const int defval
)
498 const char *endp
= p
;
511 error ("invalid option argument %qs", pname
);
518 /* When compiling with a recent enough GCC, we use the GNU C "extern inline"
519 for floor_log2 and exact_log2; see toplev.h. That construct, however,
520 conflicts with the ISO C++ One Definition Rule. */
522 #if GCC_VERSION < 3004 || !defined (__cplusplus)
524 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
525 If X is 0, return -1. */
528 floor_log2 (unsigned HOST_WIDE_INT x
)
536 t
= HOST_BITS_PER_WIDE_INT
- 1 - (int) CLZ_HWI (x
);
538 if (HOST_BITS_PER_WIDE_INT
> 64)
539 if (x
>= (unsigned HOST_WIDE_INT
) 1 << (t
+ 64))
541 if (HOST_BITS_PER_WIDE_INT
> 32)
542 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 32))
544 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 16))
546 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 8))
548 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 4))
550 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 2))
552 if (x
>= ((unsigned HOST_WIDE_INT
) 1) << (t
+ 1))
559 /* Return the logarithm of X, base 2, considering X unsigned,
560 if X is a power of 2. Otherwise, returns -1. */
563 exact_log2 (unsigned HOST_WIDE_INT x
)
568 return x
? CTZ_HWI (x
) : -1;
570 return floor_log2 (x
);
574 #endif /* GCC_VERSION < 3004 || !defined (__cplusplus) */
576 /* Handler for fatal signals, such as SIGSEGV. These are transformed
577 into ICE messages, which is much more user friendly. In case the
578 error printer crashes, reset the signal to prevent infinite recursion. */
581 crash_signal (int signo
)
583 signal (signo
, SIG_DFL
);
585 /* If we crashed while processing an ASM statement, then be a little more
586 graceful. It's most likely the user's fault. */
587 if (this_is_asm_operands
)
589 output_operand_lossage ("unrecoverable error");
590 exit (FATAL_EXIT_CODE
);
593 internal_error ("%s", strsignal (signo
));
596 /* Arrange to dump core on error. (The regular error message is still
597 printed first, except in the case of abort().) */
600 setup_core_dumping (void)
603 signal (SIGABRT
, SIG_DFL
);
605 #if defined(HAVE_SETRLIMIT)
608 if (getrlimit (RLIMIT_CORE
, &rlim
) != 0)
609 fatal_error ("getting core file size maximum limit: %m");
610 rlim
.rlim_cur
= rlim
.rlim_max
;
611 if (setrlimit (RLIMIT_CORE
, &rlim
) != 0)
612 fatal_error ("setting core file size limit to maximum: %m");
615 diagnostic_abort_on_error (global_dc
);
619 /* Strip off a legitimate source ending from the input string NAME of
620 length LEN. Rather than having to know the names used by all of
621 our front ends, we strip off an ending of a period followed by
622 up to five characters. (Java uses ".class".) */
625 strip_off_ending (char *name
, int len
)
628 for (i
= 2; i
< 6 && len
> i
; i
++)
630 if (name
[len
- i
] == '.')
632 name
[len
- i
] = '\0';
638 /* Output a quoted string. */
641 output_quoted_string (FILE *asm_file
, const char *string
)
643 #ifdef OUTPUT_QUOTED_STRING
644 OUTPUT_QUOTED_STRING (asm_file
, string
);
648 putc ('\"', asm_file
);
649 while ((c
= *string
++) != 0)
653 if (c
== '\"' || c
== '\\')
654 putc ('\\', asm_file
);
658 fprintf (asm_file
, "\\%03o", (unsigned char) c
);
660 putc ('\"', asm_file
);
664 /* Output a file name in the form wanted by System V. */
667 output_file_directive (FILE *asm_file
, const char *input_name
)
672 if (input_name
== NULL
)
673 input_name
= "<stdin>";
675 input_name
= remap_debug_filename (input_name
);
677 len
= strlen (input_name
);
678 na
= input_name
+ len
;
680 /* NA gets INPUT_NAME sans directory names. */
681 while (na
> input_name
)
683 if (IS_DIR_SEPARATOR (na
[-1]))
688 #ifdef ASM_OUTPUT_SOURCE_FILENAME
689 ASM_OUTPUT_SOURCE_FILENAME (asm_file
, na
);
691 fprintf (asm_file
, "\t.file\t");
692 output_quoted_string (asm_file
, na
);
693 fputc ('\n', asm_file
);
697 /* A subroutine of wrapup_global_declarations. We've come to the end of
698 the compilation unit. All deferred variables should be undeferred,
699 and all incomplete decls should be finalized. */
702 wrapup_global_declaration_1 (tree decl
)
704 /* We're not deferring this any longer. Assignment is conditional to
705 avoid needlessly dirtying PCH pages. */
706 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_WITH_VIS
)
707 && DECL_DEFER_OUTPUT (decl
) != 0)
708 DECL_DEFER_OUTPUT (decl
) = 0;
710 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_SIZE (decl
) == 0)
711 lang_hooks
.finish_incomplete_decl (decl
);
714 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
715 needs to be output. Return true if it is output. */
718 wrapup_global_declaration_2 (tree decl
)
720 if (TREE_ASM_WRITTEN (decl
) || DECL_EXTERNAL (decl
))
723 /* Don't write out static consts, unless we still need them.
725 We also keep static consts if not optimizing (for debugging),
726 unless the user specified -fno-keep-static-consts.
727 ??? They might be better written into the debug information.
728 This is possible when using DWARF.
730 A language processor that wants static constants to be always
731 written out (even if it is not used) is responsible for
732 calling rest_of_decl_compilation itself. E.g. the C front-end
733 calls rest_of_decl_compilation from finish_decl.
734 One motivation for this is that is conventional in some
735 environments to write things like:
736 static const char rcsid[] = "... version string ...";
737 intending to force the string to be in the executable.
739 A language processor that would prefer to have unneeded
740 static constants "optimized away" would just defer writing
741 them out until here. E.g. C++ does this, because static
742 constants are often defined in header files.
744 ??? A tempting alternative (for both C and C++) would be
745 to force a constant to be written if and only if it is
746 defined in a main file, as opposed to an include file. */
748 if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
750 struct varpool_node
*node
;
752 node
= varpool_node (decl
);
756 else if (node
->alias
)
758 else if (!cgraph_global_info_ready
760 || TREE_USED (DECL_ASSEMBLER_NAME (decl
))))
762 else if (node
->needed
)
764 else if (DECL_COMDAT (decl
))
766 else if (TREE_READONLY (decl
) && !TREE_PUBLIC (decl
)
767 && (optimize
|| !flag_keep_static_consts
768 || DECL_ARTIFICIAL (decl
)))
773 rest_of_decl_compilation (decl
, 1, 1);
781 /* Do any final processing required for the declarations in VEC, of
782 which there are LEN. We write out inline functions and variables
783 that have been deferred until this point, but which are required.
784 Returns nonzero if anything was put out. */
787 wrapup_global_declarations (tree
*vec
, int len
)
789 bool reconsider
, output_something
= false;
792 for (i
= 0; i
< len
; i
++)
793 wrapup_global_declaration_1 (vec
[i
]);
795 /* Now emit any global variables or functions that we have been
796 putting off. We need to loop in case one of the things emitted
797 here references another one which comes earlier in the list. */
801 for (i
= 0; i
< len
; i
++)
802 reconsider
|= wrapup_global_declaration_2 (vec
[i
]);
804 output_something
= true;
808 return output_something
;
811 /* A subroutine of check_global_declarations. Issue appropriate warnings
812 for the global declaration DECL. */
815 check_global_declaration_1 (tree decl
)
817 /* Warn about any function declared static but not defined. We don't
818 warn about variables, because many programs have static variables
819 that exist only to get some text into the object file. */
820 if (TREE_CODE (decl
) == FUNCTION_DECL
821 && DECL_INITIAL (decl
) == 0
822 && DECL_EXTERNAL (decl
)
823 && ! DECL_ARTIFICIAL (decl
)
824 && ! TREE_NO_WARNING (decl
)
825 && ! TREE_PUBLIC (decl
)
826 && (warn_unused_function
827 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))))
829 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
)))
830 pedwarn ("%q+F used but never defined", decl
);
832 warning (OPT_Wunused_function
, "%q+F declared %<static%> but never defined", decl
);
833 /* This symbol is effectively an "extern" declaration now. */
834 TREE_PUBLIC (decl
) = 1;
835 assemble_external (decl
);
838 /* Warn about static fns or vars defined but not used. */
839 if (((warn_unused_function
&& TREE_CODE (decl
) == FUNCTION_DECL
)
840 /* We don't warn about "static const" variables because the
841 "rcs_id" idiom uses that construction. */
842 || (warn_unused_variable
843 && TREE_CODE (decl
) == VAR_DECL
&& ! TREE_READONLY (decl
)))
844 && ! DECL_IN_SYSTEM_HEADER (decl
)
845 && ! TREE_USED (decl
)
846 /* The TREE_USED bit for file-scope decls is kept in the identifier,
847 to handle multiple external decls in different scopes. */
848 && ! (DECL_NAME (decl
) && TREE_USED (DECL_NAME (decl
)))
849 && ! DECL_EXTERNAL (decl
)
850 && ! TREE_PUBLIC (decl
)
851 /* A volatile variable might be used in some non-obvious way. */
852 && ! TREE_THIS_VOLATILE (decl
)
853 /* Global register variables must be declared to reserve them. */
854 && ! (TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
855 /* Otherwise, ask the language. */
856 && lang_hooks
.decls
.warn_unused_global (decl
))
857 warning ((TREE_CODE (decl
) == FUNCTION_DECL
)
858 ? OPT_Wunused_function
859 : OPT_Wunused_variable
,
860 "%q+D defined but not used", decl
);
863 /* Issue appropriate warnings for the global declarations in VEC (of
864 which there are LEN). */
867 check_global_declarations (tree
*vec
, int len
)
871 for (i
= 0; i
< len
; i
++)
872 check_global_declaration_1 (vec
[i
]);
875 /* Emit debugging information for all global declarations in VEC. */
878 emit_debug_global_declarations (tree
*vec
, int len
)
882 /* Avoid confusing the debug information machinery when there are errors. */
883 if (errorcount
!= 0 || sorrycount
!= 0)
886 timevar_push (TV_SYMOUT
);
887 for (i
= 0; i
< len
; i
++)
888 debug_hooks
->global_decl (vec
[i
]);
889 timevar_pop (TV_SYMOUT
);
892 /* Warn about a use of an identifier which was marked deprecated. */
894 warn_deprecated_use (tree node
)
896 if (node
== 0 || !warn_deprecated_decl
)
901 expanded_location xloc
= expand_location (DECL_SOURCE_LOCATION (node
));
902 warning (OPT_Wdeprecated_declarations
,
903 "%qD is deprecated (declared at %s:%d)",
904 node
, xloc
.file
, xloc
.line
);
906 else if (TYPE_P (node
))
908 const char *what
= NULL
;
909 tree decl
= TYPE_STUB_DECL (node
);
911 if (TYPE_NAME (node
))
913 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
914 what
= IDENTIFIER_POINTER (TYPE_NAME (node
));
915 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
916 && DECL_NAME (TYPE_NAME (node
)))
917 what
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node
)));
922 expanded_location xloc
923 = expand_location (DECL_SOURCE_LOCATION (decl
));
925 warning (OPT_Wdeprecated_declarations
,
926 "%qs is deprecated (declared at %s:%d)", what
,
927 xloc
.file
, xloc
.line
);
929 warning (OPT_Wdeprecated_declarations
,
930 "type is deprecated (declared at %s:%d)",
931 xloc
.file
, xloc
.line
);
936 warning (OPT_Wdeprecated_declarations
, "%qs is deprecated", what
);
938 warning (OPT_Wdeprecated_declarations
, "type is deprecated");
943 /* Compile an entire translation unit. Write a file of assembly
944 output and various debugging dumps. */
949 /* Initialize yet another pass. */
952 init_final (main_input_filename
);
953 coverage_init (aux_base_name
);
955 timevar_push (TV_PARSE
);
957 /* Call the parser, which parses the entire file (calling
958 rest_of_compilation for each function). */
959 lang_hooks
.parse_file (set_yydebug
);
961 /* Compilation is now finished except for writing
962 what's left of the symbol table output. */
963 timevar_pop (TV_PARSE
);
965 if (flag_syntax_only
)
968 lang_hooks
.decls
.final_write_globals ();
970 if (errorcount
|| sorrycount
)
973 varpool_assemble_pending_decls ();
976 /* This must occur after the loop to output deferred functions.
977 Else the coverage initializer would not be emitted if all the
978 functions in this compilation unit were deferred. */
981 /* Likewise for mudflap static object registrations. */
983 mudflap_finish_file ();
985 /* Likewise for emulated thread-local storage. */
986 if (!targetm
.have_tls
)
989 output_shared_constant_pool ();
990 output_object_blocks ();
992 /* Write out any pending weak symbol declarations. */
995 /* Do dbx symbols. */
996 timevar_push (TV_SYMOUT
);
998 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
999 if (dwarf2out_do_frame ())
1000 dwarf2out_frame_finish ();
1003 (*debug_hooks
->finish
) (main_input_filename
);
1004 timevar_pop (TV_SYMOUT
);
1006 /* Output some stuff at end of file if nec. */
1008 dw2_output_indirect_constants ();
1010 /* Flush any pending external directives. */
1011 process_pending_assemble_externals ();
1013 /* Attach a special .ident directive to the end of the file to identify
1014 the version of GCC which compiled this code. The format of the .ident
1015 string is patterned after the ones produced by native SVR4 compilers. */
1019 const char *pkg_version
= "(GNU) ";
1021 if (strcmp ("(GCC) ", pkgversion_string
))
1022 pkg_version
= pkgversion_string
;
1023 fprintf (asm_out_file
, "%s\"GCC: %s%s\"\n",
1024 IDENT_ASM_OP
, pkg_version
, version_string
);
1028 /* This must be at the end. Some target ports emit end of file directives
1029 into the assembly file here, and hence we can not output anything to the
1030 assembly file after this point. */
1031 targetm
.asm_out
.file_end ();
1034 /* Parse a -d... command line switch. */
1037 decode_d_option (const char *arg
)
1048 flag_print_asm_name
= 1;
1051 flag_dump_rtl_in_asm
= 1;
1052 flag_print_asm_name
= 1;
1055 graph_dump_format
= vcg
;
1058 rtl_dump_and_exit
= 1;
1063 case 'D': /* These are handled by the preprocessor. */
1069 setup_core_dumping();
1074 if (!enable_rtl_dump_file (c
))
1075 warning (0, "unrecognized gcc debugging option: %c", c
);
1080 /* Indexed by enum debug_info_type. */
1081 const char *const debug_type_names
[] =
1083 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1086 /* Print version information to FILE.
1087 Each line begins with INDENT (for the case where FILE is the
1088 assembler output file). */
1091 print_version (FILE *file
, const char *indent
)
1093 static const char fmt1
[] =
1095 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1097 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1100 static const char fmt2
[] =
1101 N_("GMP version %s, MPFR version %s.\n");
1102 static const char fmt3
[] =
1103 N_("%s%swarning: %s header version %s differs from library version %s.\n");
1104 static const char fmt4
[] =
1105 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1107 #define __VERSION__ "[?]"
1110 file
== stderr
? _(fmt1
) : fmt1
,
1111 indent
, *indent
!= 0 ? " " : "",
1112 lang_hooks
.name
, pkgversion_string
, version_string
, TARGET_NAME
,
1113 indent
, __VERSION__
);
1115 /* We need to stringify the GMP macro values. Ugh, gmp_version has
1116 two string formats, "i.j.k" and "i.j" when k is zero. */
1117 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1118 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1119 #if __GNU_MP_VERSION_PATCHLEVEL == 0
1120 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1121 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1123 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1124 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1125 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1128 file
== stderr
? _(fmt2
) : fmt2
,
1129 GCC_GMP_STRINGIFY_VERSION
, MPFR_VERSION_STRING
);
1130 if (strcmp (GCC_GMP_STRINGIFY_VERSION
, gmp_version
))
1132 file
== stderr
? _(fmt3
) : fmt3
,
1133 indent
, *indent
!= 0 ? " " : "",
1134 "GMP", GCC_GMP_STRINGIFY_VERSION
, gmp_version
);
1135 if (strcmp (MPFR_VERSION_STRING
, mpfr_get_version ()))
1137 file
== stderr
? _(fmt3
) : fmt3
,
1138 indent
, *indent
!= 0 ? " " : "",
1139 "MPFR", MPFR_VERSION_STRING
, mpfr_get_version ());
1141 file
== stderr
? _(fmt4
) : fmt4
,
1142 indent
, *indent
!= 0 ? " " : "",
1143 PARAM_VALUE (GGC_MIN_EXPAND
), PARAM_VALUE (GGC_MIN_HEAPSIZE
));
1146 #ifdef ASM_COMMENT_START
1148 print_to_asm_out_file (print_switch_type type
, const char * text
)
1150 bool prepend_sep
= true;
1154 case SWITCH_TYPE_LINE_END
:
1155 putc ('\n', asm_out_file
);
1158 case SWITCH_TYPE_LINE_START
:
1159 fputs (ASM_COMMENT_START
, asm_out_file
);
1160 return strlen (ASM_COMMENT_START
);
1162 case SWITCH_TYPE_DESCRIPTIVE
:
1163 if (ASM_COMMENT_START
[0] == 0)
1164 prepend_sep
= false;
1166 case SWITCH_TYPE_PASSED
:
1167 case SWITCH_TYPE_ENABLED
:
1169 fputc (' ', asm_out_file
);
1170 fprintf (asm_out_file
, text
);
1171 /* No need to return the length here as
1172 print_single_switch has already done it. */
1182 print_to_stderr (print_switch_type type
, const char * text
)
1186 case SWITCH_TYPE_LINE_END
:
1187 putc ('\n', stderr
);
1190 case SWITCH_TYPE_LINE_START
:
1193 case SWITCH_TYPE_PASSED
:
1194 case SWITCH_TYPE_ENABLED
:
1195 fputc (' ', stderr
);
1198 case SWITCH_TYPE_DESCRIPTIVE
:
1199 fprintf (stderr
, text
);
1200 /* No need to return the length here as
1201 print_single_switch has already done it. */
1209 /* Print an option value and return the adjusted position in the line.
1210 ??? print_fn doesn't handle errors, eg disk full; presumably other
1211 code will catch a disk full though. */
1214 print_single_switch (print_switch_fn_type print_fn
,
1216 print_switch_type type
,
1219 /* The ultrix fprintf returns 0 on success, so compute the result
1220 we want here since we need it for the following test. The +1
1221 is for the separator character that will probably be emitted. */
1222 int len
= strlen (text
) + 1;
1225 && pos
+ len
> MAX_LINE
)
1227 print_fn (SWITCH_TYPE_LINE_END
, NULL
);
1232 pos
+= print_fn (SWITCH_TYPE_LINE_START
, NULL
);
1234 print_fn (type
, text
);
1238 /* Print active target switches using PRINT_FN.
1239 POS is the current cursor position and MAX is the size of a "line".
1240 Each line begins with INDENT and ends with TERM.
1241 Each switch is separated from the next by SEP. */
1244 print_switch_values (print_switch_fn_type print_fn
)
1250 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1251 that it can be printed below. This helps reproducibility. */
1252 if (!flag_random_seed
)
1253 init_random_seed ();
1255 /* Print the options as passed. */
1256 pos
= print_single_switch (print_fn
, pos
,
1257 SWITCH_TYPE_DESCRIPTIVE
, _("options passed: "));
1259 for (p
= &save_argv
[1]; *p
!= NULL
; p
++)
1264 if (strcmp (*p
, "-o") == 0
1265 || strcmp (*p
, "-dumpbase") == 0
1266 || strcmp (*p
, "-auxbase") == 0)
1273 if (strcmp (*p
, "-quiet") == 0
1274 || strcmp (*p
, "-version") == 0)
1281 pos
= print_single_switch (print_fn
, pos
, SWITCH_TYPE_PASSED
, *p
);
1285 print_fn (SWITCH_TYPE_LINE_END
, NULL
);
1287 /* Print the -f and -m options that have been enabled.
1288 We don't handle language specific options but printing argv
1290 pos
= print_single_switch (print_fn
, 0,
1291 SWITCH_TYPE_DESCRIPTIVE
, _("options enabled: "));
1293 for (j
= 0; j
< cl_options_count
; j
++)
1294 if ((cl_options
[j
].flags
& CL_REPORT
)
1295 && option_enabled (j
) > 0)
1296 pos
= print_single_switch (print_fn
, pos
,
1297 SWITCH_TYPE_ENABLED
, cl_options
[j
].opt_text
);
1299 print_fn (SWITCH_TYPE_LINE_END
, NULL
);
1302 /* Open assembly code output file. Do this even if -fsyntax-only is
1303 on, because then the driver will have provided the name of a
1304 temporary file or bit bucket for us. NAME is the file specified on
1305 the command line, possibly NULL. */
1307 init_asm_output (const char *name
)
1309 if (name
== NULL
&& asm_file_name
== 0)
1310 asm_out_file
= stdout
;
1313 if (asm_file_name
== 0)
1315 int len
= strlen (dump_base_name
);
1316 char *dumpname
= XNEWVEC (char, len
+ 6);
1318 memcpy (dumpname
, dump_base_name
, len
+ 1);
1319 strip_off_ending (dumpname
, len
);
1320 strcat (dumpname
, ".s");
1321 asm_file_name
= dumpname
;
1323 if (!strcmp (asm_file_name
, "-"))
1324 asm_out_file
= stdout
;
1326 asm_out_file
= fopen (asm_file_name
, "w+b");
1327 if (asm_out_file
== 0)
1328 fatal_error ("can%'t open %s for writing: %m", asm_file_name
);
1331 if (!flag_syntax_only
)
1333 targetm
.asm_out
.file_start ();
1335 if (flag_record_gcc_switches
)
1337 if (targetm
.asm_out
.record_gcc_switches
)
1339 /* Let the target know that we are about to start recording. */
1340 targetm
.asm_out
.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE
,
1342 /* Now record the switches. */
1343 print_switch_values (targetm
.asm_out
.record_gcc_switches
);
1344 /* Let the target know that the recording is over. */
1345 targetm
.asm_out
.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE
,
1349 inform ("-frecord-gcc-switches is not supported by the current target");
1352 #ifdef ASM_COMMENT_START
1353 if (flag_verbose_asm
)
1355 /* Print the list of switches in effect
1356 into the assembler file as comments. */
1357 print_version (asm_out_file
, ASM_COMMENT_START
);
1358 print_switch_values (print_to_asm_out_file
);
1359 fprintf (asm_out_file
, "\n");
1365 /* Return true if the state of option OPTION should be stored in PCH files
1366 and checked by default_pch_valid_p. Store the option's current state
1370 option_affects_pch_p (int option
, struct cl_option_state
*state
)
1372 if ((cl_options
[option
].flags
& CL_TARGET
) == 0)
1374 if (cl_options
[option
].flag_var
== &target_flags
)
1375 if (targetm
.check_pch_target_flags
)
1377 return get_option_state (option
, state
);
1380 /* Default version of get_pch_validity.
1381 By default, every flag difference is fatal; that will be mostly right for
1382 most targets, but completely right for very few. */
1385 default_get_pch_validity (size_t *len
)
1387 struct cl_option_state state
;
1392 if (targetm
.check_pch_target_flags
)
1393 *len
+= sizeof (target_flags
);
1394 for (i
= 0; i
< cl_options_count
; i
++)
1395 if (option_affects_pch_p (i
, &state
))
1398 result
= r
= XNEWVEC (char, *len
);
1402 if (targetm
.check_pch_target_flags
)
1404 memcpy (r
, &target_flags
, sizeof (target_flags
));
1405 r
+= sizeof (target_flags
);
1408 for (i
= 0; i
< cl_options_count
; i
++)
1409 if (option_affects_pch_p (i
, &state
))
1411 memcpy (r
, state
.data
, state
.size
);
1418 /* Return a message which says that a PCH file was created with a different
1419 setting of OPTION. */
1422 pch_option_mismatch (const char *option
)
1426 asprintf (&r
, _("created and used with differing settings of '%s'"), option
);
1428 return _("out of memory");
1432 /* Default version of pch_valid_p. */
1435 default_pch_valid_p (const void *data_p
, size_t len
)
1437 struct cl_option_state state
;
1438 const char *data
= (const char *)data_p
;
1441 /* -fpic and -fpie also usually make a PCH invalid. */
1442 if (data
[0] != flag_pic
)
1443 return _("created and used with different settings of -fpic");
1444 if (data
[1] != flag_pie
)
1445 return _("created and used with different settings of -fpie");
1448 /* Check target_flags. */
1449 if (targetm
.check_pch_target_flags
)
1454 memcpy (&tf
, data
, sizeof (target_flags
));
1455 data
+= sizeof (target_flags
);
1456 len
-= sizeof (target_flags
);
1457 r
= targetm
.check_pch_target_flags (tf
);
1462 for (i
= 0; i
< cl_options_count
; i
++)
1463 if (option_affects_pch_p (i
, &state
))
1465 if (memcmp (data
, state
.data
, state
.size
) != 0)
1466 return pch_option_mismatch (cl_options
[i
].opt_text
);
1474 /* Default tree printer. Handles declarations only. */
1476 default_tree_printer (pretty_printer
* pp
, text_info
*text
, const char *spec
,
1477 int precision
, bool wide
, bool set_locus
, bool hash
)
1481 /* FUTURE: %+x should set the locus. */
1482 if (precision
!= 0 || wide
|| hash
)
1488 t
= va_arg (*text
->args_ptr
, tree
);
1489 if (DECL_DEBUG_EXPR_IS_FROM (t
) && DECL_DEBUG_EXPR (t
))
1490 t
= DECL_DEBUG_EXPR (t
);
1495 t
= va_arg (*text
->args_ptr
, tree
);
1502 if (set_locus
&& text
->locus
)
1503 *text
->locus
= DECL_SOURCE_LOCATION (t
);
1507 const char *n
= DECL_NAME (t
)
1508 ? lang_hooks
.decl_printable_name (t
, 2)
1513 dump_generic_node (pp
, t
, 0, TDF_DIAGNOSTIC
, 0);
1518 /* A helper function; used as the reallocator function for cpp's line
1521 realloc_for_line_map (void *ptr
, size_t len
)
1523 return ggc_realloc (ptr
, len
);
1526 /* Initialization of the front end environment, before command line
1527 options are parsed. Signal handlers, internationalization etc.
1528 ARGV0 is main's argv[0]. */
1530 general_init (const char *argv0
)
1534 p
= argv0
+ strlen (argv0
);
1535 while (p
!= argv0
&& !IS_DIR_SEPARATOR (p
[-1]))
1539 xmalloc_set_program_name (progname
);
1543 /* Unlock the stdio streams. */
1544 unlock_std_streams ();
1546 gcc_init_libintl ();
1548 /* Initialize the diagnostics reporting machinery, so option parsing
1549 can give warnings and errors. */
1550 diagnostic_initialize (global_dc
);
1551 /* Set a default printer. Language specific initializations will
1552 override it later. */
1553 pp_format_decoder (global_dc
->printer
) = &default_tree_printer
;
1555 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1557 signal (SIGSEGV
, crash_signal
);
1560 signal (SIGILL
, crash_signal
);
1563 signal (SIGBUS
, crash_signal
);
1566 signal (SIGABRT
, crash_signal
);
1568 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1569 signal (SIGIOT
, crash_signal
);
1572 signal (SIGFPE
, crash_signal
);
1575 /* Other host-specific signal setup. */
1576 (*host_hooks
.extra_signals
)();
1578 /* Initialize the garbage-collector, string pools and tree type hash
1582 line_table
= GGC_NEW (struct line_maps
);
1583 linemap_init (line_table
);
1584 line_table
->reallocator
= realloc_for_line_map
;
1587 /* Initialize register usage now so switches may override. */
1590 /* Register the language-independent parameters. */
1591 add_params (lang_independent_params
, LAST_PARAM
);
1593 /* This must be done after add_params but before argument processing. */
1594 init_ggc_heuristics();
1595 init_optimization_passes ();
1598 /* Return true if the current target supports -fsection-anchors. */
1601 target_supports_section_anchors_p (void)
1603 if (targetm
.min_anchor_offset
== 0 && targetm
.max_anchor_offset
== 0)
1606 if (targetm
.asm_out
.output_anchor
== NULL
)
1612 /* Default the align_* variables to 1 if they're still unset, and
1613 set up the align_*_log variables. */
1615 init_alignments (void)
1617 if (align_loops
<= 0)
1619 if (align_loops_max_skip
> align_loops
)
1620 align_loops_max_skip
= align_loops
- 1;
1621 align_loops_log
= floor_log2 (align_loops
* 2 - 1);
1622 if (align_jumps
<= 0)
1624 if (align_jumps_max_skip
> align_jumps
)
1625 align_jumps_max_skip
= align_jumps
- 1;
1626 align_jumps_log
= floor_log2 (align_jumps
* 2 - 1);
1627 if (align_labels
<= 0)
1629 align_labels_log
= floor_log2 (align_labels
* 2 - 1);
1630 if (align_labels_max_skip
> align_labels
)
1631 align_labels_max_skip
= align_labels
- 1;
1632 if (align_functions
<= 0)
1633 align_functions
= 1;
1634 align_functions_log
= floor_log2 (align_functions
* 2 - 1);
1637 /* Process the options that have been parsed. */
1639 process_options (void)
1641 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1642 This can happen with incorrect pre-processed input. */
1643 debug_hooks
= &do_nothing_debug_hooks
;
1645 /* Allow the front end to perform consistency checks and do further
1646 initialization based on the command line options. This hook also
1647 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1648 so we can correctly initialize debug output. */
1649 no_backend
= lang_hooks
.post_options (&main_input_filename
);
1651 #ifdef OVERRIDE_OPTIONS
1652 /* Some machines may reject certain combinations of options. */
1656 if (flag_section_anchors
&& !target_supports_section_anchors_p ())
1658 warning (OPT_fsection_anchors
,
1659 "this target does not support %qs", "-fsection-anchors");
1660 flag_section_anchors
= 0;
1663 if (flag_short_enums
== 2)
1664 flag_short_enums
= targetm
.default_short_enums ();
1666 /* Set aux_base_name if not already set. */
1669 else if (main_input_filename
)
1671 char *name
= xstrdup (lbasename (main_input_filename
));
1673 strip_off_ending (name
, strlen (name
));
1674 aux_base_name
= name
;
1677 aux_base_name
= "gccaux";
1679 /* Unrolling all loops implies that standard loop unrolling must also
1681 if (flag_unroll_all_loops
)
1682 flag_unroll_loops
= 1;
1684 /* The loop unrolling code assumes that cse will be run after loop.
1685 web and rename-registers also help when run after loop unrolling. */
1687 if (flag_rerun_cse_after_loop
== AUTODETECT_VALUE
)
1688 flag_rerun_cse_after_loop
= flag_unroll_loops
|| flag_peel_loops
;
1689 if (flag_web
== AUTODETECT_VALUE
)
1690 flag_web
= flag_unroll_loops
|| flag_peel_loops
;
1691 if (flag_rename_registers
== AUTODETECT_VALUE
)
1692 flag_rename_registers
= flag_unroll_loops
|| flag_peel_loops
;
1694 if (flag_non_call_exceptions
)
1695 flag_asynchronous_unwind_tables
= 1;
1696 if (flag_asynchronous_unwind_tables
)
1697 flag_unwind_tables
= 1;
1699 if (!flag_unit_at_a_time
)
1700 flag_section_anchors
= 0;
1702 if (flag_value_profile_transformations
)
1703 flag_profile_values
= 1;
1705 /* Warn about options that are not supported on this machine. */
1706 #ifndef INSN_SCHEDULING
1707 if (flag_schedule_insns
|| flag_schedule_insns_after_reload
)
1708 warning (0, "instruction scheduling not supported on this target machine");
1711 if (flag_delayed_branch
)
1712 warning (0, "this target machine does not have delayed branches");
1715 user_label_prefix
= USER_LABEL_PREFIX
;
1716 if (flag_leading_underscore
!= -1)
1718 /* If the default prefix is more complicated than "" or "_",
1719 issue a warning and ignore this option. */
1720 if (user_label_prefix
[0] == 0 ||
1721 (user_label_prefix
[0] == '_' && user_label_prefix
[1] == 0))
1723 user_label_prefix
= flag_leading_underscore
? "_" : "";
1726 warning (0, "-f%sleading-underscore not supported on this target machine",
1727 flag_leading_underscore
? "" : "no-");
1730 /* If we are in verbose mode, write out the version and maybe all the
1731 option flags in use. */
1734 print_version (stderr
, "");
1736 print_switch_values (print_to_stderr
);
1739 if (flag_syntax_only
)
1741 write_symbols
= NO_DEBUG
;
1745 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1747 if (debug_info_level
== DINFO_LEVEL_NONE
)
1748 write_symbols
= NO_DEBUG
;
1750 /* Now we know write_symbols, set up the debug hooks based on it.
1751 By default we do nothing for debug output. */
1752 if (PREFERRED_DEBUGGING_TYPE
== NO_DEBUG
)
1753 default_debug_hooks
= &do_nothing_debug_hooks
;
1754 #if defined(DBX_DEBUGGING_INFO)
1755 else if (PREFERRED_DEBUGGING_TYPE
== DBX_DEBUG
)
1756 default_debug_hooks
= &dbx_debug_hooks
;
1758 #if defined(XCOFF_DEBUGGING_INFO)
1759 else if (PREFERRED_DEBUGGING_TYPE
== XCOFF_DEBUG
)
1760 default_debug_hooks
= &xcoff_debug_hooks
;
1762 #ifdef SDB_DEBUGGING_INFO
1763 else if (PREFERRED_DEBUGGING_TYPE
== SDB_DEBUG
)
1764 default_debug_hooks
= &sdb_debug_hooks
;
1766 #ifdef DWARF2_DEBUGGING_INFO
1767 else if (PREFERRED_DEBUGGING_TYPE
== DWARF2_DEBUG
)
1768 default_debug_hooks
= &dwarf2_debug_hooks
;
1770 #ifdef VMS_DEBUGGING_INFO
1771 else if (PREFERRED_DEBUGGING_TYPE
== VMS_DEBUG
1772 || PREFERRED_DEBUGGING_TYPE
== VMS_AND_DWARF2_DEBUG
)
1773 default_debug_hooks
= &vmsdbg_debug_hooks
;
1776 if (write_symbols
== NO_DEBUG
)
1778 #if defined(DBX_DEBUGGING_INFO)
1779 else if (write_symbols
== DBX_DEBUG
)
1780 debug_hooks
= &dbx_debug_hooks
;
1782 #if defined(XCOFF_DEBUGGING_INFO)
1783 else if (write_symbols
== XCOFF_DEBUG
)
1784 debug_hooks
= &xcoff_debug_hooks
;
1786 #ifdef SDB_DEBUGGING_INFO
1787 else if (write_symbols
== SDB_DEBUG
)
1788 debug_hooks
= &sdb_debug_hooks
;
1790 #ifdef DWARF2_DEBUGGING_INFO
1791 else if (write_symbols
== DWARF2_DEBUG
)
1792 debug_hooks
= &dwarf2_debug_hooks
;
1794 #ifdef VMS_DEBUGGING_INFO
1795 else if (write_symbols
== VMS_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
1796 debug_hooks
= &vmsdbg_debug_hooks
;
1799 error ("target system does not support the \"%s\" debug format",
1800 debug_type_names
[write_symbols
]);
1802 /* Now we know which debug output will be used so we can set
1803 flag_var_tracking, flag_rename_registers if the user has
1804 not specified them. */
1805 if (debug_info_level
< DINFO_LEVEL_NORMAL
1806 || debug_hooks
->var_location
== do_nothing_debug_hooks
.var_location
)
1808 if (flag_var_tracking
== 1
1809 || flag_var_tracking_uninit
== 1)
1811 if (debug_info_level
< DINFO_LEVEL_NORMAL
)
1812 warning (0, "variable tracking requested, but useless unless "
1813 "producing debug info");
1815 warning (0, "variable tracking requested, but not supported "
1816 "by this debug format");
1818 flag_var_tracking
= 0;
1819 flag_var_tracking_uninit
= 0;
1822 if (flag_rename_registers
== AUTODETECT_VALUE
)
1823 flag_rename_registers
= default_debug_hooks
->var_location
1824 != do_nothing_debug_hooks
.var_location
;
1826 if (flag_var_tracking
== AUTODETECT_VALUE
)
1827 flag_var_tracking
= optimize
>= 1;
1829 if (flag_tree_cselim
== AUTODETECT_VALUE
)
1830 #ifdef HAVE_conditional_move
1831 flag_tree_cselim
= 1;
1833 flag_tree_cselim
= 0;
1836 /* If the user specifically requested variable tracking with tagging
1837 uninitialized variables, we need to turn on variable tracking.
1838 (We already determined above that variable tracking is feasible.) */
1839 if (flag_var_tracking_uninit
)
1840 flag_var_tracking
= 1;
1842 /* If auxiliary info generation is desired, open the output file.
1843 This goes in the same directory as the source file--unlike
1844 all the other output files. */
1845 if (flag_gen_aux_info
)
1847 aux_info_file
= fopen (aux_info_file_name
, "w");
1848 if (aux_info_file
== 0)
1849 fatal_error ("can%'t open %s: %m", aux_info_file_name
);
1852 if (! targetm
.have_named_sections
)
1854 if (flag_function_sections
)
1856 warning (0, "-ffunction-sections not supported for this target");
1857 flag_function_sections
= 0;
1859 if (flag_data_sections
)
1861 warning (0, "-fdata-sections not supported for this target");
1862 flag_data_sections
= 0;
1866 if (flag_function_sections
&& profile_flag
)
1868 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
1869 flag_function_sections
= 0;
1872 #ifndef HAVE_prefetch
1873 if (flag_prefetch_loop_arrays
)
1875 warning (0, "-fprefetch-loop-arrays not supported for this target");
1876 flag_prefetch_loop_arrays
= 0;
1879 if (flag_prefetch_loop_arrays
&& !HAVE_prefetch
)
1881 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
1882 flag_prefetch_loop_arrays
= 0;
1886 /* This combination of options isn't handled for i386 targets and doesn't
1887 make much sense anyway, so don't allow it. */
1888 if (flag_prefetch_loop_arrays
&& optimize_size
)
1890 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
1891 flag_prefetch_loop_arrays
= 0;
1894 #ifndef OBJECT_FORMAT_ELF
1895 #ifndef OBJECT_FORMAT_MACHO
1896 if (flag_function_sections
&& write_symbols
!= NO_DEBUG
)
1897 warning (0, "-ffunction-sections may affect debugging on some targets");
1901 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1902 if (flag_signaling_nans
)
1903 flag_trapping_math
= 1;
1905 /* We cannot reassociate if we want traps or signed zeros. Â */
1906 if (flag_associative_math
&& (flag_trapping_math
|| flag_signed_zeros
))
1908 warning (0, "-fassociative-math disabled; other options take precedence");
1909 flag_associative_math
= 0;
1912 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1913 if (flag_cx_limited_range
)
1914 flag_complex_method
= 0;
1916 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1917 if (flag_cx_fortran_rules
)
1918 flag_complex_method
= 1;
1920 /* Targets must be able to place spill slots at lower addresses. If the
1921 target already uses a soft frame pointer, the transition is trivial. */
1922 if (!FRAME_GROWS_DOWNWARD
&& flag_stack_protect
)
1924 warning (0, "-fstack-protector not supported for this target");
1925 flag_stack_protect
= 0;
1927 if (!flag_stack_protect
)
1928 warn_stack_protect
= 0;
1930 /* ??? Unwind info is not correct around the CFG unless either a frame
1931 pointer is present or A_O_A is set. Fixing this requires rewriting
1932 unwind info generation to be aware of the CFG and propagating states
1934 if (flag_unwind_tables
&& !ACCUMULATE_OUTGOING_ARGS
1935 && flag_omit_frame_pointer
)
1937 warning (0, "unwind tables currently require a frame pointer "
1939 flag_omit_frame_pointer
= 0;
1943 /* This function can be called multiple times to reinitialize the compiler
1944 back end when register classes or instruction sets have changed,
1945 before each function. */
1947 backend_init_target (void)
1949 /* Initialize alignment variables. */
1952 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
1953 to initialize reg_raw_mode[]. */
1956 /* This invokes target hooks to set fixed_reg[] etc, which is
1960 /* This depends on stack_pointer_rtx. */
1961 init_fake_stack_mems ();
1963 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1965 init_alias_target ();
1967 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1970 /* The following initialization functions need to generate rtl, so
1971 provide a dummy function context for them. */
1972 init_dummy_function_start ();
1974 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1975 on a mode change. */
1978 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1979 after a mode change as well. */
1980 if (flag_caller_saves
)
1981 init_caller_save ();
1982 expand_dummy_function_end ();
1985 /* Initialize the compiler back end. This function is called only once,
1986 when starting the compiler. */
1990 init_emit_once (debug_info_level
== DINFO_LEVEL_NORMAL
1991 || debug_info_level
== DINFO_LEVEL_VERBOSE
1992 #ifdef VMS_DEBUGGING_INFO
1993 /* Enable line number info for traceback. */
1994 || debug_info_level
> DINFO_LEVEL_NONE
1996 || flag_test_coverage
);
1999 init_inline_once ();
2000 init_varasm_once ();
2001 save_register_info ();
2003 /* Initialize the target-specific back end pieces. */
2004 backend_init_target ();
2007 /* Initialize things that are both lang-dependent and target-dependent.
2008 This function can be called more than once if target parameters change. */
2010 lang_dependent_init_target (void)
2012 /* This creates various _DECL nodes, so needs to be called after the
2013 front end is initialized. It also depends on the HAVE_xxx macros
2014 generated from the target machine description. */
2017 /* The following initialization functions need to generate rtl, so
2018 provide a dummy function context for them. */
2019 init_dummy_function_start ();
2021 /* Do the target-specific parts of expr initialization. */
2022 init_expr_target ();
2024 /* Although the actions of init_set_costs are language-independent,
2025 it uses optabs, so we cannot call it from backend_init. */
2028 expand_dummy_function_end ();
2031 /* Language-dependent initialization. Returns nonzero on success. */
2033 lang_dependent_init (const char *name
)
2035 location_t save_loc
= input_location
;
2036 if (dump_base_name
== 0)
2037 dump_base_name
= name
&& name
[0] ? name
: "gccdump";
2039 /* Other front-end initialization. */
2040 input_location
= BUILTINS_LOCATION
;
2041 if (lang_hooks
.init () == 0)
2043 input_location
= save_loc
;
2045 init_asm_output (name
);
2047 /* This creates various _DECL nodes, so needs to be called after the
2048 front end is initialized. */
2051 /* Do the target-specific parts of the initialization. */
2052 lang_dependent_init_target ();
2054 /* If dbx symbol table desired, initialize writing it and output the
2055 predefined types. */
2056 timevar_push (TV_SYMOUT
);
2058 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2059 if (dwarf2out_do_frame ())
2060 dwarf2out_frame_init ();
2063 /* Now we have the correct original filename, we can initialize
2065 (*debug_hooks
->init
) (name
);
2067 timevar_pop (TV_SYMOUT
);
2073 /* Reinitialize everything when target parameters, such as register usage,
2076 target_reinit (void)
2078 /* Reinitialize RTL backend. */
2079 backend_init_target ();
2081 /* Reinitialize lang-dependent parts. */
2082 lang_dependent_init_target ();
2086 dump_memory_report (bool final
)
2088 ggc_print_statistics ();
2089 stringpool_statistics ();
2090 dump_tree_statistics ();
2091 dump_rtx_statistics ();
2092 dump_varray_statistics ();
2093 dump_alloc_pool_statistics ();
2094 dump_bitmap_statistics ();
2095 dump_ggc_loc_statistics (final
);
2098 /* Clean up: close opened files, etc. */
2103 /* Close the dump files. */
2104 if (flag_gen_aux_info
)
2106 fclose (aux_info_file
);
2108 unlink (aux_info_file_name
);
2111 /* Close non-debugging input and output files. Take special care to note
2112 whether fclose returns an error, since the pages might still be on the
2113 buffer chain while the file is open. */
2117 if (ferror (asm_out_file
) != 0)
2118 fatal_error ("error writing to %s: %m", asm_file_name
);
2119 if (fclose (asm_out_file
) != 0)
2120 fatal_error ("error closing %s: %m", asm_file_name
);
2123 finish_optimization_passes ();
2126 dump_memory_report (true);
2128 /* Language-specific end of compilation actions. */
2129 lang_hooks
.finish ();
2132 /* Initialize the compiler, and compile the input file. */
2136 /* Initialize timing first. The C front ends read the main file in
2137 the post_options hook, and C++ does file timings. */
2138 if (time_report
|| !quiet_flag
|| flag_detailed_statistics
)
2140 timevar_start (TV_TOTAL
);
2144 /* Don't do any more if an error has already occurred. */
2147 /* This must be run always, because it is needed to compute the FP
2148 predefined macros, such as __LDBL_MAX__, for targets using non
2149 default FP formats. */
2150 init_adjust_machine_modes ();
2152 /* Set up the back-end if requested. */
2156 /* Language-dependent initialization. Returns true on success. */
2157 if (lang_dependent_init (main_input_filename
))
2163 /* Stop timing and print the times. */
2164 timevar_stop (TV_TOTAL
);
2165 timevar_print (stderr
);
2168 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2169 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2170 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2172 It is not safe to call this function more than once. */
2175 toplev_main (unsigned int argc
, const char **argv
)
2179 /* Initialization of GCC's environment, and diagnostics. */
2180 general_init (argv
[0]);
2182 /* Parse the options and do minimal processing; basically just
2183 enough to default flags appropriately. */
2184 decode_options (argc
, argv
);
2188 /* Exit early if we can (e.g. -help). */
2189 if (!exit_after_options
)
2192 if (warningcount
|| errorcount
)
2193 print_ignored_options ();
2195 if (errorcount
|| sorrycount
)
2196 return (FATAL_EXIT_CODE
);
2198 return (SUCCESS_EXIT_CODE
);