PR c/21536
[official-gcc.git] / gcc / toplev.c
blobb26d767a19412b9232391b914be19d63ef6b80c6
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 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
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. */
27 #include "config.h"
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include <signal.h>
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
37 #endif
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
41 #endif
43 #include "line-map.h"
44 #include "input.h"
45 #include "tree.h"
46 #include "version.h"
47 #include "rtl.h"
48 #include "tm_p.h"
49 #include "flags.h"
50 #include "insn-attr.h"
51 #include "insn-config.h"
52 #include "insn-flags.h"
53 #include "hard-reg-set.h"
54 #include "recog.h"
55 #include "output.h"
56 #include "except.h"
57 #include "function.h"
58 #include "toplev.h"
59 #include "expr.h"
60 #include "basic-block.h"
61 #include "intl.h"
62 #include "ggc.h"
63 #include "graph.h"
64 #include "regs.h"
65 #include "timevar.h"
66 #include "diagnostic.h"
67 #include "params.h"
68 #include "reload.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
71 #include "real.h"
72 #include "debug.h"
73 #include "target.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
76 #include "cfgloop.h"
77 #include "hosthooks.h"
78 #include "cgraph.h"
79 #include "opts.h"
80 #include "coverage.h"
81 #include "value-prof.h"
82 #include "alloc-pool.h"
83 #include "tree-mudflap.h"
85 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
86 #include "dwarf2out.h"
87 #endif
89 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
90 #include "dbxout.h"
91 #endif
93 #ifdef SDB_DEBUGGING_INFO
94 #include "sdbout.h"
95 #endif
97 #ifdef XCOFF_DEBUGGING_INFO
98 #include "xcoffout.h" /* Needed for external data
99 declarations for e.g. AIX 4.x. */
100 #endif
102 static void general_init (const char *);
103 static void do_compile (void);
104 static void process_options (void);
105 static void backend_init (void);
106 static int lang_dependent_init (const char *);
107 static void init_asm_output (const char *);
108 static void finalize (void);
110 static void crash_signal (int) ATTRIBUTE_NORETURN;
111 static void setup_core_dumping (void);
112 static void compile_file (void);
114 static int print_single_switch (FILE *, int, int, const char *,
115 const char *, const char *,
116 const char *, const char *);
117 static void print_switch_values (FILE *, int, int, const char *,
118 const char *, const char *);
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. */
127 #define MAX_LINE 75
129 /* Name of program invoked, sans directories. */
131 const char *progname;
133 /* Copy of argument vector to toplev_main. */
134 static const char **save_argv;
136 /* Name of top-level original source file (what was input to cpp).
137 This comes from the #-command at the beginning of the actual input.
138 If there isn't any there, then this is the cc1 input file name. */
140 const char *main_input_filename;
142 #ifndef USE_MAPPED_LOCATION
143 location_t unknown_location = { NULL, 0 };
144 #endif
146 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
147 to optimize and default_debug_hooks in process_options (). */
148 #define AUTODETECT_FLAG_VAR_TRACKING 2
150 /* Current position in real source file. */
152 location_t input_location;
154 struct line_maps line_table;
156 /* Nonzero if it is unsafe to create any new pseudo registers. */
157 int no_new_pseudos;
159 /* Stack of currently pending input files. */
161 struct file_stack *input_file_stack;
163 /* Incremented on each change to input_file_stack. */
164 int input_file_stack_tick;
166 /* Name to use as base of names for dump output files. */
168 const char *dump_base_name;
170 /* Name to use as a base for auxiliary output files. */
172 const char *aux_base_name;
174 /* Bit flags that specify the machine subtype we are compiling for.
175 Bits are tested using macros TARGET_... defined in the tm.h file
176 and set by `-m...' switches. Must be defined in rtlanal.c. */
178 extern int target_flags;
180 /* A mask of target_flags that includes bit X if X was set or cleared
181 on the command line. */
183 int target_flags_explicit;
185 /* Debug hooks - dependent upon command line options. */
187 const struct gcc_debug_hooks *debug_hooks;
189 /* Debug hooks - target default. */
191 static const struct gcc_debug_hooks *default_debug_hooks;
193 /* Other flags saying which kinds of debugging dump have been requested. */
195 int rtl_dump_and_exit;
196 int flag_print_asm_name;
197 enum graph_dump_types graph_dump_format;
199 /* Name for output file of assembly code, specified with -o. */
201 const char *asm_file_name;
203 /* Nonzero means do optimizations. -O.
204 Particular numeric values stand for particular amounts of optimization;
205 thus, -O2 stores 2 here. However, the optimizations beyond the basic
206 ones are not controlled directly by this variable. Instead, they are
207 controlled by individual `flag_...' variables that are defaulted
208 based on this variable. */
210 int optimize = 0;
212 /* Nonzero means optimize for size. -Os.
213 The only valid values are zero and nonzero. When optimize_size is
214 nonzero, optimize defaults to 2, but certain individual code
215 bloating optimizations are disabled. */
217 int optimize_size = 0;
219 /* The FUNCTION_DECL for the function currently being compiled,
220 or 0 if between functions. */
221 tree current_function_decl;
223 /* Set to the FUNC_BEGIN label of the current function, or NULL
224 if none. */
225 const char * current_function_func_begin_label;
227 /* Temporarily suppress certain warnings.
228 This is set while reading code from a system header file. */
230 int in_system_header = 0;
232 /* Nonzero means to collect statistics which might be expensive
233 and to print them when we are done. */
234 int flag_detailed_statistics = 0;
236 /* A random sequence of characters, unless overridden by user. */
237 const char *flag_random_seed;
239 /* A local time stamp derived from the time of compilation. It will be
240 zero if the system cannot provide a time. It will be -1u, if the
241 user has specified a particular random seed. */
242 unsigned local_tick;
244 /* -f flags. */
246 /* Nonzero means `char' should be signed. */
248 int flag_signed_char;
250 /* Nonzero means give an enum type only as many bytes as it needs. A value
251 of 2 means it has not yet been initialized. */
253 int flag_short_enums;
255 /* Nonzero if structures and unions should be returned in memory.
257 This should only be defined if compatibility with another compiler or
258 with an ABI is needed, because it results in slower code. */
260 #ifndef DEFAULT_PCC_STRUCT_RETURN
261 #define DEFAULT_PCC_STRUCT_RETURN 1
262 #endif
264 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
266 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
268 /* 0 means straightforward implementation of complex divide acceptable.
269 1 means wide ranges of inputs must work for complex divide.
270 2 means C99-like requirements for complex multiply and divide. */
272 int flag_complex_method = 1;
274 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
275 not just because the tree inliner turned us off. */
277 int flag_really_no_inline = 2;
279 /* Nonzero means we should be saving declaration info into a .X file. */
281 int flag_gen_aux_info = 0;
283 /* Specified name of aux-info file. */
285 const char *aux_info_file_name;
287 /* Nonzero if we are compiling code for a shared library, zero for
288 executable. */
290 int flag_shlib;
292 /* Set to the default thread-local storage (tls) model to use. */
294 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
296 /* Nonzero means change certain warnings into errors.
297 Usually these are warnings about failure to conform to some standard. */
299 int flag_pedantic_errors = 0;
301 /* -dA causes debug commentary information to be produced in
302 the generated assembly code (to make it more readable). This option
303 is generally only of use to those who actually need to read the
304 generated assembly code (perhaps while debugging the compiler itself).
305 Currently, this switch is only used by dwarfout.c; however, it is intended
306 to be a catchall for printing debug information in the assembler file. */
308 int flag_debug_asm = 0;
310 /* -dP causes the rtl to be emitted as a comment in assembly. */
312 int flag_dump_rtl_in_asm = 0;
314 /* When non-NULL, indicates that whenever space is allocated on the
315 stack, the resulting stack pointer must not pass this
316 address---that is, for stacks that grow downward, the stack pointer
317 must always be greater than or equal to this address; for stacks
318 that grow upward, the stack pointer must be less than this address.
319 At present, the rtx may be either a REG or a SYMBOL_REF, although
320 the support provided depends on the backend. */
321 rtx stack_limit_rtx;
323 /* If one, renumber instruction UIDs to reduce the number of
324 unused UIDs if there are a lot of instructions. If greater than
325 one, unconditionally renumber instruction UIDs. */
326 int flag_renumber_insns = 1;
328 /* Nonzero if we should track variables. When
329 flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING it will be set according
330 to optimize, debug_info_level and debug_hooks in process_options (). */
331 int flag_var_tracking = AUTODETECT_FLAG_VAR_TRACKING;
333 /* True if the user has tagged the function with the 'section'
334 attribute. */
336 bool user_defined_section_attribute = false;
338 /* Values of the -falign-* flags: how much to align labels in code.
339 0 means `use default', 1 means `don't align'.
340 For each variable, there is an _log variant which is the power
341 of two not less than the variable, for .align output. */
343 int align_loops_log;
344 int align_loops_max_skip;
345 int align_jumps_log;
346 int align_jumps_max_skip;
347 int align_labels_log;
348 int align_labels_max_skip;
349 int align_functions_log;
351 /* Like align_functions_log above, but used by front-ends to force the
352 minimum function alignment. Zero means no alignment is forced. */
353 int force_align_functions_log;
355 typedef struct
357 const char *const string;
358 int *const variable;
359 const int on_value;
361 lang_independent_options;
363 /* Nonzero if subexpressions must be evaluated from left-to-right. */
364 int flag_evaluation_order = 0;
366 /* The user symbol prefix after having resolved same. */
367 const char *user_label_prefix;
369 static const param_info lang_independent_params[] = {
370 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
371 { OPTION, DEFAULT, MIN, MAX, HELP },
372 #include "params.def"
373 #undef DEFPARAM
374 { NULL, 0, 0, 0, NULL }
377 /* Output files for assembler code (real compiler output)
378 and debugging dumps. */
380 FILE *asm_out_file;
381 FILE *aux_info_file;
382 FILE *dump_file = NULL;
383 const char *dump_file_name;
385 /* The current working directory of a translation. It's generally the
386 directory from which compilation was initiated, but a preprocessed
387 file may specify the original directory in which it was
388 created. */
390 static const char *src_pwd;
392 /* Initialize src_pwd with the given string, and return true. If it
393 was already initialized, return false. As a special case, it may
394 be called with a NULL argument to test whether src_pwd has NOT been
395 initialized yet. */
397 bool
398 set_src_pwd (const char *pwd)
400 if (src_pwd)
402 if (strcmp (src_pwd, pwd) == 0)
403 return true;
404 else
405 return false;
408 src_pwd = xstrdup (pwd);
409 return true;
412 /* Return the directory from which the translation unit was initiated,
413 in case set_src_pwd() was not called before to assign it a
414 different value. */
416 const char *
417 get_src_pwd (void)
419 if (! src_pwd)
421 src_pwd = getpwd ();
422 if (!src_pwd)
423 src_pwd = ".";
426 return src_pwd;
429 /* Called when the start of a function definition is parsed,
430 this function prints on stderr the name of the function. */
431 void
432 announce_function (tree decl)
434 if (!quiet_flag)
436 if (rtl_dump_and_exit)
437 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
438 else
439 verbatim (" %s", lang_hooks.decl_printable_name (decl, 2));
440 fflush (stderr);
441 pp_needs_newline (global_dc->printer) = true;
442 diagnostic_set_last_function (global_dc);
446 /* Set up a default flag_random_seed and local_tick, unless the user
447 already specified one. */
449 static void
450 randomize (void)
452 if (!flag_random_seed)
454 unsigned HOST_WIDE_INT value;
455 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
457 /* Get some more or less random data. */
458 #ifdef HAVE_GETTIMEOFDAY
460 struct timeval tv;
462 gettimeofday (&tv, NULL);
463 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
465 #else
467 time_t now = time (NULL);
469 if (now != (time_t)-1)
470 local_tick = (unsigned) now;
472 #endif
473 value = local_tick ^ getpid ();
475 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
476 flag_random_seed = random_seed;
478 else if (!local_tick)
479 local_tick = -1;
483 /* Decode the string P as an integral parameter.
484 If the string is indeed an integer return its numeric value else
485 issue an Invalid Option error for the option PNAME and return DEFVAL.
486 If PNAME is zero just return DEFVAL, do not call error. */
489 read_integral_parameter (const char *p, const char *pname, const int defval)
491 const char *endp = p;
493 while (*endp)
495 if (ISDIGIT (*endp))
496 endp++;
497 else
498 break;
501 if (*endp != 0)
503 if (pname != 0)
504 error ("invalid option argument %qs", pname);
505 return defval;
508 return atoi (p);
511 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
512 If X is 0, return -1. */
515 floor_log2 (unsigned HOST_WIDE_INT x)
517 int t = 0;
519 if (x == 0)
520 return -1;
522 #ifdef CLZ_HWI
523 t = HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x);
524 #else
525 if (HOST_BITS_PER_WIDE_INT > 64)
526 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
527 t += 64;
528 if (HOST_BITS_PER_WIDE_INT > 32)
529 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
530 t += 32;
531 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
532 t += 16;
533 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
534 t += 8;
535 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
536 t += 4;
537 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
538 t += 2;
539 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
540 t += 1;
541 #endif
543 return t;
546 /* Return the logarithm of X, base 2, considering X unsigned,
547 if X is a power of 2. Otherwise, returns -1. */
550 exact_log2 (unsigned HOST_WIDE_INT x)
552 if (x != (x & -x))
553 return -1;
554 #ifdef CTZ_HWI
555 return x ? CTZ_HWI (x) : -1;
556 #else
557 return floor_log2 (x);
558 #endif
561 /* Handler for fatal signals, such as SIGSEGV. These are transformed
562 into ICE messages, which is much more user friendly. In case the
563 error printer crashes, reset the signal to prevent infinite recursion. */
565 static void
566 crash_signal (int signo)
568 signal (signo, SIG_DFL);
570 /* If we crashed while processing an ASM statement, then be a little more
571 graceful. It's most likely the user's fault. */
572 if (this_is_asm_operands)
574 output_operand_lossage ("unrecoverable error");
575 exit (FATAL_EXIT_CODE);
578 internal_error ("%s", strsignal (signo));
581 /* Arrange to dump core on error. (The regular error message is still
582 printed first, except in the case of abort().) */
584 static void
585 setup_core_dumping (void)
587 #ifdef SIGABRT
588 signal (SIGABRT, SIG_DFL);
589 #endif
590 #if defined(HAVE_SETRLIMIT)
592 struct rlimit rlim;
593 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
594 fatal_error ("getting core file size maximum limit: %m");
595 rlim.rlim_cur = rlim.rlim_max;
596 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
597 fatal_error ("setting core file size limit to maximum: %m");
599 #endif
600 diagnostic_abort_on_error (global_dc);
604 /* Strip off a legitimate source ending from the input string NAME of
605 length LEN. Rather than having to know the names used by all of
606 our front ends, we strip off an ending of a period followed by
607 up to five characters. (Java uses ".class".) */
609 void
610 strip_off_ending (char *name, int len)
612 int i;
613 for (i = 2; i < 6 && len > i; i++)
615 if (name[len - i] == '.')
617 name[len - i] = '\0';
618 break;
623 /* Output a quoted string. */
625 void
626 output_quoted_string (FILE *asm_file, const char *string)
628 #ifdef OUTPUT_QUOTED_STRING
629 OUTPUT_QUOTED_STRING (asm_file, string);
630 #else
631 char c;
633 putc ('\"', asm_file);
634 while ((c = *string++) != 0)
636 if (ISPRINT (c))
638 if (c == '\"' || c == '\\')
639 putc ('\\', asm_file);
640 putc (c, asm_file);
642 else
643 fprintf (asm_file, "\\%03o", (unsigned char) c);
645 putc ('\"', asm_file);
646 #endif
649 /* Output a file name in the form wanted by System V. */
651 void
652 output_file_directive (FILE *asm_file, const char *input_name)
654 int len;
655 const char *na;
657 if (input_name == NULL)
658 input_name = "<stdin>";
660 len = strlen (input_name);
661 na = input_name + len;
663 /* NA gets INPUT_NAME sans directory names. */
664 while (na > input_name)
666 if (IS_DIR_SEPARATOR (na[-1]))
667 break;
668 na--;
671 #ifdef ASM_OUTPUT_SOURCE_FILENAME
672 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
673 #else
674 fprintf (asm_file, "\t.file\t");
675 output_quoted_string (asm_file, na);
676 fputc ('\n', asm_file);
677 #endif
680 /* Do any final processing required for the declarations in VEC, of
681 which there are LEN. We write out inline functions and variables
682 that have been deferred until this point, but which are required.
683 Returns nonzero if anything was put out. */
686 wrapup_global_declarations (tree *vec, int len)
688 tree decl;
689 int i;
690 int reconsider;
691 int output_something = 0;
693 for (i = 0; i < len; i++)
695 decl = vec[i];
697 /* We're not deferring this any longer. Assignment is
698 conditional to avoid needlessly dirtying PCH pages. */
699 if (DECL_DEFER_OUTPUT (decl) != 0)
700 DECL_DEFER_OUTPUT (decl) = 0;
702 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
703 lang_hooks.finish_incomplete_decl (decl);
706 /* Now emit any global variables or functions that we have been
707 putting off. We need to loop in case one of the things emitted
708 here references another one which comes earlier in the list. */
711 reconsider = 0;
712 for (i = 0; i < len; i++)
714 decl = vec[i];
716 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
717 continue;
719 /* Don't write out static consts, unless we still need them.
721 We also keep static consts if not optimizing (for debugging),
722 unless the user specified -fno-keep-static-consts.
723 ??? They might be better written into the debug information.
724 This is possible when using DWARF.
726 A language processor that wants static constants to be always
727 written out (even if it is not used) is responsible for
728 calling rest_of_decl_compilation itself. E.g. the C front-end
729 calls rest_of_decl_compilation from finish_decl.
730 One motivation for this is that is conventional in some
731 environments to write things like:
732 static const char rcsid[] = "... version string ...";
733 intending to force the string to be in the executable.
735 A language processor that would prefer to have unneeded
736 static constants "optimized away" would just defer writing
737 them out until here. E.g. C++ does this, because static
738 constants are often defined in header files.
740 ??? A tempting alternative (for both C and C++) would be
741 to force a constant to be written if and only if it is
742 defined in a main file, as opposed to an include file. */
744 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
746 struct cgraph_varpool_node *node;
747 bool needed = 1;
748 node = cgraph_varpool_node (decl);
750 if (node->finalized)
751 needed = 0;
752 else if (node->alias)
753 needed = 0;
754 else if (!cgraph_global_info_ready
755 && (TREE_USED (decl)
756 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
757 /* needed */;
758 else if (node->needed)
759 /* needed */;
760 else if (DECL_COMDAT (decl))
761 needed = 0;
762 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
763 && (optimize || !flag_keep_static_consts
764 || DECL_ARTIFICIAL (decl)))
765 needed = 0;
767 if (needed)
769 reconsider = 1;
770 rest_of_decl_compilation (decl, 1, 1);
775 if (reconsider)
776 output_something = 1;
778 while (reconsider);
780 return output_something;
783 /* Issue appropriate warnings for the global declarations in VEC (of
784 which there are LEN). Output debugging information for them. */
786 void
787 check_global_declarations (tree *vec, int len)
789 tree decl;
790 int i;
792 for (i = 0; i < len; i++)
794 decl = vec[i];
796 /* Do not emit debug information about variables that are in
797 static storage, but not defined. */
798 if (TREE_CODE (decl) == VAR_DECL
799 && TREE_STATIC (decl)
800 && !TREE_ASM_WRITTEN (decl))
801 DECL_IGNORED_P (decl) = 1;
803 /* Warn about any function
804 declared static but not defined.
805 We don't warn about variables,
806 because many programs have static variables
807 that exist only to get some text into the object file. */
808 if (TREE_CODE (decl) == FUNCTION_DECL
809 && DECL_INITIAL (decl) == 0
810 && DECL_EXTERNAL (decl)
811 && ! DECL_ARTIFICIAL (decl)
812 && ! TREE_NO_WARNING (decl)
813 && ! TREE_PUBLIC (decl)
814 && (warn_unused_function
815 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
817 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
818 pedwarn ("%J%qF used but never defined", decl, decl);
819 else
820 warning (0, "%J%qF declared %<static%> but never defined",
821 decl, decl);
822 /* This symbol is effectively an "extern" declaration now. */
823 TREE_PUBLIC (decl) = 1;
824 assemble_external (decl);
827 /* Warn about static fns or vars defined but not used. */
828 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
829 /* We don't warn about "static const" variables because the
830 "rcs_id" idiom uses that construction. */
831 || (warn_unused_variable
832 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
833 && ! DECL_IN_SYSTEM_HEADER (decl)
834 && ! TREE_USED (decl)
835 /* The TREE_USED bit for file-scope decls is kept in the identifier,
836 to handle multiple external decls in different scopes. */
837 && ! TREE_USED (DECL_NAME (decl))
838 && ! DECL_EXTERNAL (decl)
839 && ! TREE_PUBLIC (decl)
840 /* A volatile variable might be used in some non-obvious way. */
841 && ! TREE_THIS_VOLATILE (decl)
842 /* Global register variables must be declared to reserve them. */
843 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
844 /* Otherwise, ask the language. */
845 && lang_hooks.decls.warn_unused_global (decl))
846 warning (0, "%J%qD defined but not used", decl, decl);
848 /* Avoid confusing the debug information machinery when there are
849 errors. */
850 if (errorcount == 0 && sorrycount == 0)
852 timevar_push (TV_SYMOUT);
853 (*debug_hooks->global_decl) (decl);
854 timevar_pop (TV_SYMOUT);
859 /* Warn about a use of an identifier which was marked deprecated. */
860 void
861 warn_deprecated_use (tree node)
863 if (node == 0 || !warn_deprecated_decl)
864 return;
866 if (DECL_P (node))
868 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
869 warning (0, "%qs is deprecated (declared at %s:%d)",
870 IDENTIFIER_POINTER (DECL_NAME (node)),
871 xloc.file, xloc.line);
873 else if (TYPE_P (node))
875 const char *what = NULL;
876 tree decl = TYPE_STUB_DECL (node);
878 if (TYPE_NAME (node))
880 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
881 what = IDENTIFIER_POINTER (TYPE_NAME (node));
882 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
883 && DECL_NAME (TYPE_NAME (node)))
884 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
887 if (decl)
889 expanded_location xloc
890 = expand_location (DECL_SOURCE_LOCATION (decl));
891 if (what)
892 warning (0, "%qs is deprecated (declared at %s:%d)", what,
893 xloc.file, xloc.line);
894 else
895 warning (0, "type is deprecated (declared at %s:%d)",
896 xloc.file, xloc.line);
898 else
900 if (what)
901 warning (0, "%qs is deprecated", what);
902 else
903 warning (0, "type is deprecated");
908 /* Save the current INPUT_LOCATION on the top entry in the
909 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
910 INPUT_LOCATION accordingly. */
912 void
913 #ifdef USE_MAPPED_LOCATION
914 push_srcloc (location_t fline)
915 #else
916 push_srcloc (const char *file, int line)
917 #endif
919 struct file_stack *fs;
921 fs = xmalloc (sizeof (struct file_stack));
922 fs->location = input_location;
923 fs->next = input_file_stack;
924 #ifdef USE_MAPPED_LOCATION
925 input_location = fline;
926 #else
927 input_filename = file;
928 input_line = line;
929 #endif
930 input_file_stack = fs;
931 input_file_stack_tick++;
934 /* Pop the top entry off the stack of presently open source files.
935 Restore the INPUT_LOCATION from the new topmost entry on the
936 stack. */
938 void
939 pop_srcloc (void)
941 struct file_stack *fs;
943 fs = input_file_stack;
944 input_location = fs->location;
945 input_file_stack = fs->next;
946 free (fs);
947 input_file_stack_tick++;
950 /* Compile an entire translation unit. Write a file of assembly
951 output and various debugging dumps. */
953 static void
954 compile_file (void)
956 /* Initialize yet another pass. */
958 init_cgraph ();
959 init_final (main_input_filename);
960 coverage_init (aux_base_name);
962 timevar_push (TV_PARSE);
964 /* Call the parser, which parses the entire file (calling
965 rest_of_compilation for each function). */
966 lang_hooks.parse_file (set_yydebug);
968 /* In case there were missing block closers,
969 get us back to the global binding level. */
970 lang_hooks.clear_binding_stack ();
972 /* Compilation is now finished except for writing
973 what's left of the symbol table output. */
974 timevar_pop (TV_PARSE);
976 if (flag_syntax_only)
977 return;
979 lang_hooks.decls.final_write_globals ();
980 cgraph_varpool_assemble_pending_decls ();
981 finish_aliases_2 ();
983 /* This must occur after the loop to output deferred functions.
984 Else the coverage initializer would not be emitted if all the
985 functions in this compilation unit were deferred. */
986 coverage_finish ();
988 /* Likewise for mudflap static object registrations. */
989 if (flag_mudflap)
990 mudflap_finish_file ();
992 /* Write out any pending weak symbol declarations. */
994 weak_finish ();
996 /* Do dbx symbols. */
997 timevar_push (TV_SYMOUT);
999 #ifdef DWARF2_UNWIND_INFO
1000 if (dwarf2out_do_frame ())
1001 dwarf2out_frame_finish ();
1002 #endif
1004 (*debug_hooks->finish) (main_input_filename);
1005 timevar_pop (TV_SYMOUT);
1007 /* Output some stuff at end of file if nec. */
1009 dw2_output_indirect_constants ();
1011 /* Flush any pending external directives. cgraph did this for
1012 assemble_external calls from the front end, but the RTL
1013 expander can also generate them. */
1014 process_pending_assemble_externals ();
1016 /* Attach a special .ident directive to the end of the file to identify
1017 the version of GCC which compiled this code. The format of the .ident
1018 string is patterned after the ones produced by native SVR4 compilers. */
1019 #ifdef IDENT_ASM_OP
1020 if (!flag_no_ident)
1021 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1022 IDENT_ASM_OP, version_string);
1023 #endif
1025 /* This must be at the end. Some target ports emit end of file directives
1026 into the assembly file here, and hence we can not output anything to the
1027 assembly file after this point. */
1028 targetm.asm_out.file_end ();
1031 /* Parse a -d... command line switch. */
1033 void
1034 decode_d_option (const char *arg)
1036 int c;
1038 while (*arg)
1039 switch (c = *arg++)
1041 case 'A':
1042 flag_debug_asm = 1;
1043 break;
1044 case 'p':
1045 flag_print_asm_name = 1;
1046 break;
1047 case 'P':
1048 flag_dump_rtl_in_asm = 1;
1049 flag_print_asm_name = 1;
1050 break;
1051 case 'v':
1052 graph_dump_format = vcg;
1053 break;
1054 case 'x':
1055 rtl_dump_and_exit = 1;
1056 break;
1057 case 'y':
1058 set_yydebug = 1;
1059 break;
1060 case 'D': /* These are handled by the preprocessor. */
1061 case 'I':
1062 break;
1063 case 'H':
1064 setup_core_dumping();
1065 break;
1067 case 'a':
1068 default:
1069 if (!enable_rtl_dump_file (c))
1070 warning (0, "unrecognized gcc debugging option: %c", c);
1071 break;
1075 /* Indexed by enum debug_info_type. */
1076 const char *const debug_type_names[] =
1078 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1081 /* Print version information to FILE.
1082 Each line begins with INDENT (for the case where FILE is the
1083 assembler output file). */
1085 void
1086 print_version (FILE *file, const char *indent)
1088 #ifndef __VERSION__
1089 #define __VERSION__ "[?]"
1090 #endif
1091 fnotice (file,
1092 #ifdef __GNUC__
1093 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
1094 #else
1095 "%s%s%s version %s (%s) compiled by CC.\n"
1096 #endif
1097 , indent, *indent != 0 ? " " : "",
1098 lang_hooks.name, version_string, TARGET_NAME,
1099 indent, __VERSION__);
1100 fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
1101 indent, *indent != 0 ? " " : "",
1102 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1105 /* Print an option value and return the adjusted position in the line.
1106 ??? We don't handle error returns from fprintf (disk full); presumably
1107 other code will catch a disk full though. */
1109 static int
1110 print_single_switch (FILE *file, int pos, int max,
1111 const char *indent, const char *sep, const char *term,
1112 const char *type, const char *name)
1114 /* The ultrix fprintf returns 0 on success, so compute the result we want
1115 here since we need it for the following test. */
1116 int len = strlen (sep) + strlen (type) + strlen (name);
1118 if (pos != 0
1119 && pos + len > max)
1121 fprintf (file, "%s", term);
1122 pos = 0;
1124 if (pos == 0)
1126 fprintf (file, "%s", indent);
1127 pos = strlen (indent);
1129 fprintf (file, "%s%s%s", sep, type, name);
1130 pos += len;
1131 return pos;
1134 /* Print active target switches to FILE.
1135 POS is the current cursor position and MAX is the size of a "line".
1136 Each line begins with INDENT and ends with TERM.
1137 Each switch is separated from the next by SEP. */
1139 static void
1140 print_switch_values (FILE *file, int pos, int max,
1141 const char *indent, const char *sep, const char *term)
1143 size_t j;
1144 const char **p;
1146 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1147 that it can be printed below. This helps reproducibility. */
1148 randomize ();
1150 /* Print the options as passed. */
1151 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
1152 _("options passed: "), "");
1154 for (p = &save_argv[1]; *p != NULL; p++)
1155 if (**p == '-')
1157 /* Ignore these. */
1158 if (strcmp (*p, "-o") == 0)
1160 if (p[1] != NULL)
1161 p++;
1162 continue;
1164 if (strcmp (*p, "-quiet") == 0)
1165 continue;
1166 if (strcmp (*p, "-version") == 0)
1167 continue;
1168 if ((*p)[1] == 'd')
1169 continue;
1171 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
1173 if (pos > 0)
1174 fprintf (file, "%s", term);
1176 /* Print the -f and -m options that have been enabled.
1177 We don't handle language specific options but printing argv
1178 should suffice. */
1180 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
1181 _("options enabled: "), "");
1183 for (j = 0; j < cl_options_count; j++)
1184 if ((cl_options[j].flags & CL_REPORT)
1185 && option_enabled (j) > 0)
1186 pos = print_single_switch (file, pos, max, indent, sep, term,
1187 "", cl_options[j].opt_text);
1189 fprintf (file, "%s", term);
1192 /* Open assembly code output file. Do this even if -fsyntax-only is
1193 on, because then the driver will have provided the name of a
1194 temporary file or bit bucket for us. NAME is the file specified on
1195 the command line, possibly NULL. */
1196 static void
1197 init_asm_output (const char *name)
1199 if (name == NULL && asm_file_name == 0)
1200 asm_out_file = stdout;
1201 else
1203 if (asm_file_name == 0)
1205 int len = strlen (dump_base_name);
1206 char *dumpname = xmalloc (len + 6);
1207 memcpy (dumpname, dump_base_name, len + 1);
1208 strip_off_ending (dumpname, len);
1209 strcat (dumpname, ".s");
1210 asm_file_name = dumpname;
1212 if (!strcmp (asm_file_name, "-"))
1213 asm_out_file = stdout;
1214 else
1215 asm_out_file = fopen (asm_file_name, "w+b");
1216 if (asm_out_file == 0)
1217 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1220 if (!flag_syntax_only)
1222 targetm.asm_out.file_start ();
1224 #ifdef ASM_COMMENT_START
1225 if (flag_verbose_asm)
1227 /* Print the list of options in effect. */
1228 print_version (asm_out_file, ASM_COMMENT_START);
1229 print_switch_values (asm_out_file, 0, MAX_LINE,
1230 ASM_COMMENT_START, " ", "\n");
1231 /* Add a blank line here so it appears in assembler output but not
1232 screen output. */
1233 fprintf (asm_out_file, "\n");
1235 #endif
1239 /* Return true if the state of option OPTION should be stored in PCH files
1240 and checked by default_pch_valid_p. Store the option's current state
1241 in STATE if so. */
1243 static inline bool
1244 option_affects_pch_p (int option, struct cl_option_state *state)
1246 if ((cl_options[option].flags & CL_TARGET) == 0)
1247 return false;
1248 if (cl_options[option].flag_var == &target_flags)
1249 if (targetm.check_pch_target_flags)
1250 return false;
1251 return get_option_state (option, state);
1254 /* Default version of get_pch_validity.
1255 By default, every flag difference is fatal; that will be mostly right for
1256 most targets, but completely right for very few. */
1258 void *
1259 default_get_pch_validity (size_t *len)
1261 struct cl_option_state state;
1262 size_t i;
1263 char *result, *r;
1265 *len = 2;
1266 if (targetm.check_pch_target_flags)
1267 *len += sizeof (target_flags);
1268 for (i = 0; i < cl_options_count; i++)
1269 if (option_affects_pch_p (i, &state))
1270 *len += state.size;
1272 result = r = xmalloc (*len);
1273 r[0] = flag_pic;
1274 r[1] = flag_pie;
1275 r += 2;
1276 if (targetm.check_pch_target_flags)
1278 memcpy (r, &target_flags, sizeof (target_flags));
1279 r += sizeof (target_flags);
1282 for (i = 0; i < cl_options_count; i++)
1283 if (option_affects_pch_p (i, &state))
1285 memcpy (r, state.data, state.size);
1286 r += state.size;
1289 return result;
1292 /* Return a message which says that a PCH file was created with a different
1293 setting of OPTION. */
1295 static const char *
1296 pch_option_mismatch (const char *option)
1298 char *r;
1300 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1301 if (r == NULL)
1302 return _("out of memory");
1303 return r;
1306 /* Default version of pch_valid_p. */
1308 const char *
1309 default_pch_valid_p (const void *data_p, size_t len)
1311 struct cl_option_state state;
1312 const char *data = (const char *)data_p;
1313 size_t i;
1315 /* -fpic and -fpie also usually make a PCH invalid. */
1316 if (data[0] != flag_pic)
1317 return _("created and used with different settings of -fpic");
1318 if (data[1] != flag_pie)
1319 return _("created and used with different settings of -fpie");
1320 data += 2;
1322 /* Check target_flags. */
1323 if (targetm.check_pch_target_flags)
1325 int tf;
1326 const char *r;
1328 memcpy (&tf, data, sizeof (target_flags));
1329 data += sizeof (target_flags);
1330 len -= sizeof (target_flags);
1331 r = targetm.check_pch_target_flags (tf);
1332 if (r != NULL)
1333 return r;
1336 for (i = 0; i < cl_options_count; i++)
1337 if (option_affects_pch_p (i, &state))
1339 if (memcmp (data, state.data, state.size) != 0)
1340 return pch_option_mismatch (cl_options[i].opt_text);
1341 data += state.size;
1342 len -= state.size;
1345 return NULL;
1348 /* Default tree printer. Handles declarations only. */
1349 static bool
1350 default_tree_printer (pretty_printer * pp, text_info *text)
1352 tree t;
1354 switch (*text->format_spec)
1356 case 'D':
1357 t = va_arg (*text->args_ptr, tree);
1358 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1359 t = DECL_DEBUG_EXPR (t);
1360 break;
1362 case 'F':
1363 case 'T':
1364 t = va_arg (*text->args_ptr, tree);
1365 break;
1367 default:
1368 return false;
1371 if (DECL_P (t))
1373 const char *n = DECL_NAME (t)
1374 ? lang_hooks.decl_printable_name (t, 2)
1375 : "<anonymous>";
1376 pp_string (pp, n);
1378 else
1379 dump_generic_node (pp, t, 0, 0, 0);
1381 return true;
1384 /* Initialization of the front end environment, before command line
1385 options are parsed. Signal handlers, internationalization etc.
1386 ARGV0 is main's argv[0]. */
1387 static void
1388 general_init (const char *argv0)
1390 const char *p;
1392 p = argv0 + strlen (argv0);
1393 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1394 --p;
1395 progname = p;
1397 xmalloc_set_program_name (progname);
1399 hex_init ();
1401 /* Unlock the stdio streams. */
1402 unlock_std_streams ();
1404 gcc_init_libintl ();
1406 /* Initialize the diagnostics reporting machinery, so option parsing
1407 can give warnings and errors. */
1408 diagnostic_initialize (global_dc);
1409 /* Set a default printer. Language specific initializations will
1410 override it later. */
1411 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1413 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1414 #ifdef SIGSEGV
1415 signal (SIGSEGV, crash_signal);
1416 #endif
1417 #ifdef SIGILL
1418 signal (SIGILL, crash_signal);
1419 #endif
1420 #ifdef SIGBUS
1421 signal (SIGBUS, crash_signal);
1422 #endif
1423 #ifdef SIGABRT
1424 signal (SIGABRT, crash_signal);
1425 #endif
1426 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1427 signal (SIGIOT, crash_signal);
1428 #endif
1429 #ifdef SIGFPE
1430 signal (SIGFPE, crash_signal);
1431 #endif
1433 /* Other host-specific signal setup. */
1434 (*host_hooks.extra_signals)();
1436 /* Initialize the garbage-collector, string pools and tree type hash
1437 table. */
1438 init_ggc ();
1439 init_stringpool ();
1440 linemap_init (&line_table);
1441 init_ttree ();
1443 /* Initialize register usage now so switches may override. */
1444 init_reg_sets ();
1446 /* Register the language-independent parameters. */
1447 add_params (lang_independent_params, LAST_PARAM);
1449 /* This must be done after add_params but before argument processing. */
1450 init_ggc_heuristics();
1451 init_tree_optimization_passes ();
1454 /* Process the options that have been parsed. */
1455 static void
1456 process_options (void)
1458 /* Allow the front end to perform consistency checks and do further
1459 initialization based on the command line options. This hook also
1460 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1461 so we can correctly initialize debug output. */
1462 no_backend = lang_hooks.post_options (&main_input_filename);
1463 #ifndef USE_MAPPED_LOCATION
1464 input_filename = main_input_filename;
1465 #endif
1467 #ifdef OVERRIDE_OPTIONS
1468 /* Some machines may reject certain combinations of options. */
1469 OVERRIDE_OPTIONS;
1470 #endif
1472 if (flag_short_enums == 2)
1473 flag_short_enums = targetm.default_short_enums ();
1475 /* Set aux_base_name if not already set. */
1476 if (aux_base_name)
1478 else if (main_input_filename)
1480 char *name = xstrdup (lbasename (main_input_filename));
1482 strip_off_ending (name, strlen (name));
1483 aux_base_name = name;
1485 else
1486 aux_base_name = "gccaux";
1488 /* Set up the align_*_log variables, defaulting them to 1 if they
1489 were still unset. */
1490 if (align_loops <= 0) align_loops = 1;
1491 if (align_loops_max_skip > align_loops || !align_loops)
1492 align_loops_max_skip = align_loops - 1;
1493 align_loops_log = floor_log2 (align_loops * 2 - 1);
1494 if (align_jumps <= 0) align_jumps = 1;
1495 if (align_jumps_max_skip > align_jumps || !align_jumps)
1496 align_jumps_max_skip = align_jumps - 1;
1497 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1498 if (align_labels <= 0) align_labels = 1;
1499 align_labels_log = floor_log2 (align_labels * 2 - 1);
1500 if (align_labels_max_skip > align_labels || !align_labels)
1501 align_labels_max_skip = align_labels - 1;
1502 if (align_functions <= 0) align_functions = 1;
1503 align_functions_log = floor_log2 (align_functions * 2 - 1);
1505 /* Unrolling all loops implies that standard loop unrolling must also
1506 be done. */
1507 if (flag_unroll_all_loops)
1508 flag_unroll_loops = 1;
1510 /* The loop unrolling code assumes that cse will be run after loop. */
1511 if (flag_unroll_loops || flag_peel_loops)
1512 flag_rerun_cse_after_loop = 1;
1514 /* If explicitly asked to run new loop optimizer, switch off the old
1515 one. */
1516 if (flag_loop_optimize2)
1517 flag_loop_optimize = 0;
1519 /* Enable new loop optimizer pass if any of its optimizations is called. */
1520 if (flag_move_loop_invariants
1521 || flag_unswitch_loops
1522 || flag_peel_loops
1523 || flag_unroll_loops
1524 || flag_branch_on_count_reg)
1525 flag_loop_optimize2 = 1;
1527 if (flag_non_call_exceptions)
1528 flag_asynchronous_unwind_tables = 1;
1529 if (flag_asynchronous_unwind_tables)
1530 flag_unwind_tables = 1;
1532 /* Disable unit-at-a-time mode for frontends not supporting callgraph
1533 interface. */
1534 if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
1535 flag_unit_at_a_time = 0;
1537 if (flag_value_profile_transformations)
1538 flag_profile_values = 1;
1540 /* Speculative prefetching implies the value profiling. We also switch off
1541 the prefetching in the loop optimizer, so that we do not emit double
1542 prefetches. TODO -- we should teach these two to cooperate; the loop
1543 based prefetching may sometimes do a better job, especially in connection
1544 with reuse analysis. */
1545 if (flag_speculative_prefetching)
1547 flag_profile_values = 1;
1548 flag_prefetch_loop_arrays = 0;
1551 /* Warn about options that are not supported on this machine. */
1552 #ifndef INSN_SCHEDULING
1553 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1554 warning (0, "instruction scheduling not supported on this target machine");
1555 #endif
1556 #ifndef DELAY_SLOTS
1557 if (flag_delayed_branch)
1558 warning (0, "this target machine does not have delayed branches");
1559 #endif
1561 user_label_prefix = USER_LABEL_PREFIX;
1562 if (flag_leading_underscore != -1)
1564 /* If the default prefix is more complicated than "" or "_",
1565 issue a warning and ignore this option. */
1566 if (user_label_prefix[0] == 0 ||
1567 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1569 user_label_prefix = flag_leading_underscore ? "_" : "";
1571 else
1572 warning (0, "-f%sleading-underscore not supported on this target machine",
1573 flag_leading_underscore ? "" : "no-");
1576 /* If we are in verbose mode, write out the version and maybe all the
1577 option flags in use. */
1578 if (version_flag)
1580 print_version (stderr, "");
1581 if (! quiet_flag)
1582 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
1585 if (flag_syntax_only)
1587 write_symbols = NO_DEBUG;
1588 profile_flag = 0;
1591 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1592 level is 0. */
1593 if (debug_info_level == DINFO_LEVEL_NONE)
1594 write_symbols = NO_DEBUG;
1596 /* Now we know write_symbols, set up the debug hooks based on it.
1597 By default we do nothing for debug output. */
1598 if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG)
1599 default_debug_hooks = &do_nothing_debug_hooks;
1600 #if defined(DBX_DEBUGGING_INFO)
1601 else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG)
1602 default_debug_hooks = &dbx_debug_hooks;
1603 #endif
1604 #if defined(XCOFF_DEBUGGING_INFO)
1605 else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG)
1606 default_debug_hooks = &xcoff_debug_hooks;
1607 #endif
1608 #ifdef SDB_DEBUGGING_INFO
1609 else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG)
1610 default_debug_hooks = &sdb_debug_hooks;
1611 #endif
1612 #ifdef DWARF2_DEBUGGING_INFO
1613 else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG)
1614 default_debug_hooks = &dwarf2_debug_hooks;
1615 #endif
1616 #ifdef VMS_DEBUGGING_INFO
1617 else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG
1618 || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG)
1619 default_debug_hooks = &vmsdbg_debug_hooks;
1620 #endif
1622 debug_hooks = &do_nothing_debug_hooks;
1623 if (write_symbols == NO_DEBUG)
1625 #if defined(DBX_DEBUGGING_INFO)
1626 else if (write_symbols == DBX_DEBUG)
1627 debug_hooks = &dbx_debug_hooks;
1628 #endif
1629 #if defined(XCOFF_DEBUGGING_INFO)
1630 else if (write_symbols == XCOFF_DEBUG)
1631 debug_hooks = &xcoff_debug_hooks;
1632 #endif
1633 #ifdef SDB_DEBUGGING_INFO
1634 else if (write_symbols == SDB_DEBUG)
1635 debug_hooks = &sdb_debug_hooks;
1636 #endif
1637 #ifdef DWARF2_DEBUGGING_INFO
1638 else if (write_symbols == DWARF2_DEBUG)
1639 debug_hooks = &dwarf2_debug_hooks;
1640 #endif
1641 #ifdef VMS_DEBUGGING_INFO
1642 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1643 debug_hooks = &vmsdbg_debug_hooks;
1644 #endif
1645 else
1646 error ("target system does not support the \"%s\" debug format",
1647 debug_type_names[write_symbols]);
1649 /* Now we know which debug output will be used so we can set
1650 flag_var_tracking, flag_rename_registers if the user has
1651 not specified them. */
1652 if (debug_info_level < DINFO_LEVEL_NORMAL
1653 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1655 if (flag_var_tracking == 1)
1657 if (debug_info_level < DINFO_LEVEL_NORMAL)
1658 warning (0, "variable tracking requested, but useless unless "
1659 "producing debug info");
1660 else
1661 warning (0, "variable tracking requested, but not supported "
1662 "by this debug format");
1664 flag_var_tracking = 0;
1667 if (flag_rename_registers == AUTODETECT_FLAG_VAR_TRACKING)
1668 flag_rename_registers = default_debug_hooks->var_location
1669 != do_nothing_debug_hooks.var_location;
1671 if (flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING)
1672 flag_var_tracking = optimize >= 1;
1674 /* If auxiliary info generation is desired, open the output file.
1675 This goes in the same directory as the source file--unlike
1676 all the other output files. */
1677 if (flag_gen_aux_info)
1679 aux_info_file = fopen (aux_info_file_name, "w");
1680 if (aux_info_file == 0)
1681 fatal_error ("can%'t open %s: %m", aux_info_file_name);
1684 if (! targetm.have_named_sections)
1686 if (flag_function_sections)
1688 warning (0, "-ffunction-sections not supported for this target");
1689 flag_function_sections = 0;
1691 if (flag_data_sections)
1693 warning (0, "-fdata-sections not supported for this target");
1694 flag_data_sections = 0;
1698 if (flag_function_sections && profile_flag)
1700 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
1701 flag_function_sections = 0;
1704 #ifndef HAVE_prefetch
1705 if (flag_prefetch_loop_arrays)
1707 warning (0, "-fprefetch-loop-arrays not supported for this target");
1708 flag_prefetch_loop_arrays = 0;
1710 if (flag_speculative_prefetching)
1712 if (flag_speculative_prefetching_set)
1713 warning (0, "-fspeculative-prefetching not supported for this target");
1714 flag_speculative_prefetching = 0;
1716 #else
1717 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
1719 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
1720 flag_prefetch_loop_arrays = 0;
1722 if (flag_speculative_prefetching && !HAVE_prefetch)
1724 if (flag_speculative_prefetching_set)
1725 warning (0, "-fspeculative-prefetching not supported for this target (try -march switches)");
1726 flag_speculative_prefetching = 0;
1728 #endif
1730 /* This combination of options isn't handled for i386 targets and doesn't
1731 make much sense anyway, so don't allow it. */
1732 if (flag_prefetch_loop_arrays && optimize_size)
1734 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
1735 flag_prefetch_loop_arrays = 0;
1738 #ifndef OBJECT_FORMAT_ELF
1739 if (flag_function_sections && write_symbols != NO_DEBUG)
1740 warning (0, "-ffunction-sections may affect debugging on some targets");
1741 #endif
1743 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1744 if (flag_signaling_nans)
1745 flag_trapping_math = 1;
1747 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1748 if (flag_cx_limited_range)
1749 flag_complex_method = 0;
1752 /* Initialize the compiler back end. */
1753 static void
1754 backend_init (void)
1756 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
1757 || debug_info_level == DINFO_LEVEL_VERBOSE
1758 #ifdef VMS_DEBUGGING_INFO
1759 /* Enable line number info for traceback. */
1760 || debug_info_level > DINFO_LEVEL_NONE
1761 #endif
1762 || flag_test_coverage);
1764 init_rtlanal ();
1765 init_regs ();
1766 init_fake_stack_mems ();
1767 init_alias_once ();
1768 init_loop ();
1769 init_reload ();
1770 init_function_once ();
1771 init_varasm_once ();
1773 /* The following initialization functions need to generate rtl, so
1774 provide a dummy function context for them. */
1775 init_dummy_function_start ();
1776 init_expmed ();
1777 if (flag_caller_saves)
1778 init_caller_save ();
1779 expand_dummy_function_end ();
1782 /* Language-dependent initialization. Returns nonzero on success. */
1783 static int
1784 lang_dependent_init (const char *name)
1786 location_t save_loc = input_location;
1787 if (dump_base_name == 0)
1788 dump_base_name = name && name[0] ? name : "gccdump";
1790 /* Other front-end initialization. */
1791 #ifdef USE_MAPPED_LOCATION
1792 input_location = BUILTINS_LOCATION;
1793 #else
1794 input_filename = "<built-in>";
1795 input_line = 0;
1796 #endif
1797 if (lang_hooks.init () == 0)
1798 return 0;
1799 input_location = save_loc;
1801 init_asm_output (name);
1803 /* These create various _DECL nodes, so need to be called after the
1804 front end is initialized. */
1805 init_eh ();
1806 init_optabs ();
1808 /* The following initialization functions need to generate rtl, so
1809 provide a dummy function context for them. */
1810 init_dummy_function_start ();
1811 init_expr_once ();
1812 expand_dummy_function_end ();
1814 /* If dbx symbol table desired, initialize writing it and output the
1815 predefined types. */
1816 timevar_push (TV_SYMOUT);
1818 #ifdef DWARF2_UNWIND_INFO
1819 if (dwarf2out_do_frame ())
1820 dwarf2out_frame_init ();
1821 #endif
1823 /* Now we have the correct original filename, we can initialize
1824 debug output. */
1825 (*debug_hooks->init) (name);
1827 timevar_pop (TV_SYMOUT);
1829 return 1;
1832 /* Clean up: close opened files, etc. */
1834 static void
1835 finalize (void)
1837 /* Close the dump files. */
1838 if (flag_gen_aux_info)
1840 fclose (aux_info_file);
1841 if (errorcount)
1842 unlink (aux_info_file_name);
1845 /* Close non-debugging input and output files. Take special care to note
1846 whether fclose returns an error, since the pages might still be on the
1847 buffer chain while the file is open. */
1849 if (asm_out_file)
1851 if (ferror (asm_out_file) != 0)
1852 fatal_error ("error writing to %s: %m", asm_file_name);
1853 if (fclose (asm_out_file) != 0)
1854 fatal_error ("error closing %s: %m", asm_file_name);
1857 finish_optimization_passes ();
1859 if (mem_report)
1861 ggc_print_statistics ();
1862 stringpool_statistics ();
1863 dump_tree_statistics ();
1864 dump_rtx_statistics ();
1865 dump_varray_statistics ();
1866 dump_alloc_pool_statistics ();
1867 dump_ggc_loc_statistics ();
1870 /* Free up memory for the benefit of leak detectors. */
1871 free_reg_info ();
1873 /* Language-specific end of compilation actions. */
1874 lang_hooks.finish ();
1877 /* Initialize the compiler, and compile the input file. */
1878 static void
1879 do_compile (void)
1881 /* Initialize timing first. The C front ends read the main file in
1882 the post_options hook, and C++ does file timings. */
1883 if (time_report || !quiet_flag || flag_detailed_statistics)
1884 timevar_init ();
1885 timevar_start (TV_TOTAL);
1887 process_options ();
1889 /* Don't do any more if an error has already occurred. */
1890 if (!errorcount)
1892 /* This must be run always, because it is needed to compute the FP
1893 predefined macros, such as __LDBL_MAX__, for targets using non
1894 default FP formats. */
1895 init_adjust_machine_modes ();
1897 /* Set up the back-end if requested. */
1898 if (!no_backend)
1899 backend_init ();
1901 /* Language-dependent initialization. Returns true on success. */
1902 if (lang_dependent_init (main_input_filename))
1903 compile_file ();
1905 finalize ();
1908 /* Stop timing and print the times. */
1909 timevar_stop (TV_TOTAL);
1910 timevar_print (stderr);
1913 /* Entry point of cc1, cc1plus, jc1, f771, etc.
1914 Exit code is FATAL_EXIT_CODE if can't open files or if there were
1915 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
1917 It is not safe to call this function more than once. */
1920 toplev_main (unsigned int argc, const char **argv)
1922 save_argv = argv;
1924 /* Initialization of GCC's environment, and diagnostics. */
1925 general_init (argv[0]);
1927 /* Parse the options and do minimal processing; basically just
1928 enough to default flags appropriately. */
1929 decode_options (argc, argv);
1931 randomize ();
1933 /* Exit early if we can (e.g. -help). */
1934 if (!exit_after_options)
1935 do_compile ();
1937 if (errorcount || sorrycount)
1938 return (FATAL_EXIT_CODE);
1940 return (SUCCESS_EXIT_CODE);